From ba8500293ed9ec8421b17e510443d5f7cf58c997 Mon Sep 17 00:00:00 2001 From: nikita Date: Mon, 1 Sep 2008 16:27:02 +0000 Subject: [PATCH] split osc_cl.c into osc_object.c osc_lock.c osc_io.c osc_page.c osc_dev.c --- libcfs/include/libcfs/posix/libcfs.h | 80 +++++++++++++++++++++++------------- libcfs/include/libcfs/user-lock.h | 25 +++++++++-- libcfs/libcfs/linux/linux-prim.c | 1 + libcfs/libcfs/tracefile.c | 34 +++++++-------- libcfs/libcfs/user-lock.c | 19 +++++++++ lnet/utils/wirecheck.c | 2 +- 6 files changed, 112 insertions(+), 49 deletions(-) diff --git a/libcfs/include/libcfs/posix/libcfs.h b/libcfs/include/libcfs/posix/libcfs.h index 8509eb4..b50554f 100644 --- a/libcfs/include/libcfs/posix/libcfs.h +++ b/libcfs/include/libcfs/posix/libcfs.h @@ -221,7 +221,7 @@ static inline void MODULE_AUTHOR(char *name) #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name) #define MODULE_LICENSE(name) MODULE_AUTHOR(name) -#define THIS_MODULE NULL +#define THIS_MODULE (void *)0x11111 #define __init #define __exit @@ -265,7 +265,7 @@ typedef int (*shrinker_t)(int, unsigned int); static inline struct shrinker *set_shrinker(int seeks, shrinker_t shrinkert) { - return NULL; + return (struct shrinker *)0xdeadbea1; // Cannot return NULL here } static inline void remove_shrinker(struct shrinker *shrinker) @@ -283,63 +283,87 @@ static inline void remove_shrinker(struct shrinker *shrinker) ***************************************************************************/ struct radix_tree_root { - struct list_head *rnode; + struct list_head list; + void *rnode; }; +struct radix_tree_node { + struct list_head _node; + unsigned long index; + void *item; +}; + #define RADIX_TREE_INIT(mask) { \ - .rnode = NULL, \ + NOT_IMPLEMENTED \ } #define RADIX_TREE(name, mask) \ struct radix_tree_root name = RADIX_TREE_INIT(mask) -#define INIT_RADIX_TREE(root, mask) \ -do { \ - (root)->rnode = NULL; \ + +#define INIT_RADIX_TREE(root, mask) \ +do { \ + CFS_INIT_LIST_HEAD(&((struct radix_tree_root *)root)->list); \ + ((struct radix_tree_root *)root)->rnode = NULL; \ } while (0) static inline int radix_tree_insert(struct radix_tree_root *root, - unsigned long idx, struct page *page) + unsigned long idx, void *item) { - if (root->rnode == NULL) - root->rnode = &page->_node; - else - list_add_tail(&page->_node, root->rnode); + struct radix_tree_node *node; + node = malloc(sizeof(*node)); + if (!node) + return -ENOMEM; + + CFS_INIT_LIST_HEAD(&node->_node); + node->index = idx; + node->item = item; + list_add_tail(&node->_node, &root->list); + root->rnode = (void *)1001; return 0; } -static inline void *radix_tree_lookup(struct radix_tree_root *root, +static inline struct radix_tree_node *radix_tree_lookup0(struct radix_tree_root *root, unsigned long idx) { - struct page *p; + struct radix_tree_node *node; - if (root->rnode == NULL) + if (list_empty(&root->list)) return NULL; - p = list_entry(root->rnode, struct page, _node); - if (p->index == idx) - return p; - - list_for_each_entry(p, root->rnode, _node) - if (p->index == idx) - return p; + list_for_each_entry(node, &root->list, _node) + if (node->index == idx) + return node; return NULL; } +static inline void *radix_tree_lookup(struct radix_tree_root *root, + unsigned long idx) +{ + struct radix_tree_node *node = radix_tree_lookup0(root, idx); + + if (node) + return node->item; + return node; +} + static inline void *radix_tree_delete(struct radix_tree_root *root, unsigned long idx) { - struct page *p = radix_tree_lookup(root, idx); + struct radix_tree_node *p = radix_tree_lookup0(root, idx); + void *item; if (p == NULL) return NULL; - if (list_empty(root->rnode)) - root->rnode = NULL; - else if (root->rnode == &p->_node) - root->rnode = p->_node.next; + list_del_init(&p->_node); - return p; + item = p->item; + free(p); + if (list_empty(&root->list)) + root->rnode = NULL; + + return item; } static inline unsigned int diff --git a/libcfs/include/libcfs/user-lock.h b/libcfs/include/libcfs/user-lock.h index 6f4e145..2561381 100644 --- a/libcfs/include/libcfs/user-lock.h +++ b/libcfs/include/libcfs/user-lock.h @@ -146,7 +146,8 @@ struct completion { unsigned int done; cfs_waitq_t wait; }; - +typedef int (cfs_wait_handler) (int timeout); +void set_completion_wait_handler(cfs_wait_handler *handler); void init_completion(struct completion *c); void complete(struct completion *c); void wait_for_completion(struct completion *c); @@ -279,6 +280,8 @@ struct mutex { struct semaphore m_sem; }; +#define DEFINE_MUTEX(m) struct mutex m + static inline void mutex_init(struct mutex *mutex) { init_mutex(&mutex->m_sem); @@ -297,13 +300,27 @@ static inline void mutex_unlock(struct mutex *mutex) /** * Try-lock this mutex. * - * \retval 1 try-lock succeeded. * - * \retval 0 try-lock failed. + * \retval 0 try-lock succeeded (lock acquired). + * \retval errno indicates lock contention. + */ +static inline int mutex_down_trylock(struct mutex *mutex) +{ + return 0; +} + +/** + * Try-lock this mutex. + * + * Note, return values are negation of what is expected from down_trylock() or + * pthread_mutex_trylock(). + * + * \retval 1 try-lock succeeded (lock acquired). + * \retval 0 indicates lock contention. */ static inline int mutex_trylock(struct mutex *mutex) { - return 1; + return !mutex_down_trylock(mutex); } static inline void mutex_destroy(struct mutex *lock) diff --git a/libcfs/libcfs/linux/linux-prim.c b/libcfs/libcfs/linux/linux-prim.c index c332ad2..e92aacc 100644 --- a/libcfs/libcfs/linux/linux-prim.c +++ b/libcfs/libcfs/linux/linux-prim.c @@ -323,6 +323,7 @@ libcfs_arch_cleanup(void) EXPORT_SYMBOL(libcfs_arch_init); EXPORT_SYMBOL(libcfs_arch_cleanup); +EXPORT_SYMBOL(cfs_enter_debugger); EXPORT_SYMBOL(cfs_daemonize); EXPORT_SYMBOL(cfs_daemonize_ctxt); EXPORT_SYMBOL(cfs_block_allsigs); diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 5530832..f32ba75 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -150,9 +150,10 @@ static struct trace_page *trace_get_tage_try(struct trace_cpu_data *tcd, } else { tage = tage_alloc(CFS_ALLOC_ATOMIC); if (tage == NULL) { - printk(KERN_WARNING - "failure to allocate a tage (%ld)\n", - tcd->tcd_cur_pages); + if (printk_ratelimit()) + printk(KERN_WARNING + "cannot allocate a tage (%ld)\n", + tcd->tcd_cur_pages); return NULL; } } @@ -189,7 +190,7 @@ static void tcd_shrink(struct trace_cpu_data *tcd) if (printk_ratelimit()) printk(KERN_WARNING "debug daemon buffer overflowed; " - "discarding 10%% of pages (%d of %ld)\n", + "discarding 10%% of pages (%d of %ld)\n", pgcount + 1, tcd->tcd_cur_pages); CFS_INIT_LIST_HEAD(&pc.pc_pages); @@ -238,7 +239,7 @@ static struct trace_page *trace_get_tage(struct trace_cpu_data *tcd, int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask, const char *file, const char *fn, const int line, const char *format1, va_list args, - const char *format2, ...) + const char *format2, ...) { struct trace_cpu_data *tcd = NULL; struct ptldebug_header header; @@ -448,6 +449,7 @@ libcfs_assertion_failed(const char *expr, const char *file, { libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "ASSERTION(%s) failed\n", expr); + cfs_enter_debugger(); lbug_with_loc(file, func, line); } EXPORT_SYMBOL(libcfs_assertion_failed); @@ -729,11 +731,11 @@ int trace_copyin_string(char *knl_buffer, int knl_buffer_nob, const char *usr_buffer, int usr_buffer_nob) { int nob; - + if (usr_buffer_nob > knl_buffer_nob) return -EOVERFLOW; - - if (copy_from_user((void *)knl_buffer, + + if (copy_from_user((void *)knl_buffer, (void *)usr_buffer, usr_buffer_nob)) return -EFAULT; @@ -759,17 +761,17 @@ int trace_copyout_string(char *usr_buffer, int usr_buffer_nob, * copied out string - usually "\n", for /proc entries and "" (i.e. a * terminating zero byte) for sysctl entries */ int nob = strlen(knl_buffer); - + if (nob > usr_buffer_nob) nob = usr_buffer_nob; - + if (copy_to_user(usr_buffer, knl_buffer, nob)) return -EFAULT; - + if (append != NULL && nob < usr_buffer_nob) { if (copy_to_user(usr_buffer + nob, append, 1)) return -EFAULT; - + nob++; } @@ -780,7 +782,7 @@ int trace_allocate_string_buffer(char **str, int nob) { if (nob > 2 * CFS_PAGE_SIZE) /* string must be "sensible" */ return -EINVAL; - + *str = cfs_alloc(nob, CFS_ALLOC_STD | CFS_ALLOC_ZERO); if (*str == NULL) return -ENOMEM; @@ -822,7 +824,7 @@ out: int trace_daemon_command(char *str) { int rc = 0; - + tracefile_write_lock(); if (strcmp(str, "stop") == 0) { @@ -881,7 +883,7 @@ int trace_set_debug_mb(int mb) int pages; int limit = trace_max_debug_mb(); struct trace_cpu_data *tcd; - + if (mb < num_possible_cpus()) return -EINVAL; @@ -922,7 +924,7 @@ int trace_get_debug_mb(void) int j; struct trace_cpu_data *tcd; int total_pages = 0; - + tracefile_read_lock(); tcd_for_each(tcd, i, j) diff --git a/libcfs/libcfs/user-lock.c b/libcfs/libcfs/user-lock.c index 1f392f6..ab4447c 100644 --- a/libcfs/libcfs/user-lock.c +++ b/libcfs/libcfs/user-lock.c @@ -147,6 +147,13 @@ void __up(struct semaphore *s) * - wait_for_completion(c) */ +static cfs_wait_handler *wait_handler; + +void init_completion_module(cfs_wait_handler *handler) +{ + wait_handler = handler; +} + void init_completion(struct completion *c) { LASSERT(c != NULL); @@ -164,11 +171,23 @@ void complete(struct completion *c) void wait_for_completion(struct completion *c) { LASSERT(c != NULL); + do { + if (wait_handler) + wait_handler(1000); + else + break; + } while (c->done == 0); } int wait_for_completion_interruptible(struct completion *c) { LASSERT(c != NULL); + do { + if (wait_handler) + wait_handler(1000); + else + break; + } while (c->done == 0); return 0; } diff --git a/lnet/utils/wirecheck.c b/lnet/utils/wirecheck.c index 6d44ea1..17c57aa 100644 --- a/lnet/utils/wirecheck.c +++ b/lnet/utils/wirecheck.c @@ -193,7 +193,7 @@ system_string (char *cmdline, char *str, int len) WEXITSTATUS(rc) != 0) abort(); - if (strnlen(str, len) == len) + if (strlen(str) == len) str[len - 1] = 0; if (str[strlen(str) - 1] == '\n') -- 1.8.3.1