Skip to content
Snippets Groups Projects
Commit ba850029 authored by Nikita Danilov's avatar Nikita Danilov
Browse files

split osc_cl.c into osc_object.c osc_lock.c osc_io.c osc_page.c osc_dev.c

parent 0878538e
No related branches found
No related tags found
No related merge requests found
...@@ -221,7 +221,7 @@ static inline void MODULE_AUTHOR(char *name) ...@@ -221,7 +221,7 @@ static inline void MODULE_AUTHOR(char *name)
#define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name) #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
#define MODULE_LICENSE(name) MODULE_AUTHOR(name) #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
#define THIS_MODULE NULL #define THIS_MODULE (void *)0x11111
#define __init #define __init
#define __exit #define __exit
...@@ -265,7 +265,7 @@ typedef int (*shrinker_t)(int, unsigned int); ...@@ -265,7 +265,7 @@ typedef int (*shrinker_t)(int, unsigned int);
static inline struct shrinker *set_shrinker(int seeks, shrinker_t shrinkert) 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) static inline void remove_shrinker(struct shrinker *shrinker)
...@@ -283,63 +283,87 @@ 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 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) { \ #define RADIX_TREE_INIT(mask) { \
.rnode = NULL, \ NOT_IMPLEMENTED \
} }
#define RADIX_TREE(name, mask) \ #define RADIX_TREE(name, mask) \
struct radix_tree_root name = RADIX_TREE_INIT(mask) struct radix_tree_root name = RADIX_TREE_INIT(mask)
#define INIT_RADIX_TREE(root, mask) \
do { \ #define INIT_RADIX_TREE(root, mask) \
(root)->rnode = NULL; \ do { \
CFS_INIT_LIST_HEAD(&((struct radix_tree_root *)root)->list); \
((struct radix_tree_root *)root)->rnode = NULL; \
} while (0) } while (0)
static inline int radix_tree_insert(struct radix_tree_root *root, 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) struct radix_tree_node *node;
root->rnode = &page->_node; node = malloc(sizeof(*node));
else if (!node)
list_add_tail(&page->_node, root->rnode); 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; 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) unsigned long idx)
{ {
struct page *p; struct radix_tree_node *node;
if (root->rnode == NULL) if (list_empty(&root->list))
return NULL; return NULL;
p = list_entry(root->rnode, struct page, _node); list_for_each_entry(node, &root->list, _node)
if (p->index == idx) if (node->index == idx)
return p; return node;
list_for_each_entry(p, root->rnode, _node)
if (p->index == idx)
return p;
return NULL; 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, static inline void *radix_tree_delete(struct radix_tree_root *root,
unsigned long idx) 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) if (p == NULL)
return 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); 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 static inline unsigned int
......
...@@ -146,7 +146,8 @@ struct completion { ...@@ -146,7 +146,8 @@ struct completion {
unsigned int done; unsigned int done;
cfs_waitq_t wait; 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 init_completion(struct completion *c);
void complete(struct completion *c); void complete(struct completion *c);
void wait_for_completion(struct completion *c); void wait_for_completion(struct completion *c);
...@@ -279,6 +280,8 @@ struct mutex { ...@@ -279,6 +280,8 @@ struct mutex {
struct semaphore m_sem; struct semaphore m_sem;
}; };
#define DEFINE_MUTEX(m) struct mutex m
static inline void mutex_init(struct mutex *mutex) static inline void mutex_init(struct mutex *mutex)
{ {
init_mutex(&mutex->m_sem); init_mutex(&mutex->m_sem);
...@@ -297,13 +300,27 @@ static inline void mutex_unlock(struct mutex *mutex) ...@@ -297,13 +300,27 @@ static inline void mutex_unlock(struct mutex *mutex)
/** /**
* Try-lock this 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) static inline int mutex_trylock(struct mutex *mutex)
{ {
return 1; return !mutex_down_trylock(mutex);
} }
static inline void mutex_destroy(struct mutex *lock) static inline void mutex_destroy(struct mutex *lock)
......
...@@ -323,6 +323,7 @@ libcfs_arch_cleanup(void) ...@@ -323,6 +323,7 @@ libcfs_arch_cleanup(void)
EXPORT_SYMBOL(libcfs_arch_init); EXPORT_SYMBOL(libcfs_arch_init);
EXPORT_SYMBOL(libcfs_arch_cleanup); EXPORT_SYMBOL(libcfs_arch_cleanup);
EXPORT_SYMBOL(cfs_enter_debugger);
EXPORT_SYMBOL(cfs_daemonize); EXPORT_SYMBOL(cfs_daemonize);
EXPORT_SYMBOL(cfs_daemonize_ctxt); EXPORT_SYMBOL(cfs_daemonize_ctxt);
EXPORT_SYMBOL(cfs_block_allsigs); EXPORT_SYMBOL(cfs_block_allsigs);
......
...@@ -150,9 +150,10 @@ static struct trace_page *trace_get_tage_try(struct trace_cpu_data *tcd, ...@@ -150,9 +150,10 @@ static struct trace_page *trace_get_tage_try(struct trace_cpu_data *tcd,
} else { } else {
tage = tage_alloc(CFS_ALLOC_ATOMIC); tage = tage_alloc(CFS_ALLOC_ATOMIC);
if (tage == NULL) { if (tage == NULL) {
printk(KERN_WARNING if (printk_ratelimit())
"failure to allocate a tage (%ld)\n", printk(KERN_WARNING
tcd->tcd_cur_pages); "cannot allocate a tage (%ld)\n",
tcd->tcd_cur_pages);
return NULL; return NULL;
} }
} }
...@@ -189,7 +190,7 @@ static void tcd_shrink(struct trace_cpu_data *tcd) ...@@ -189,7 +190,7 @@ static void tcd_shrink(struct trace_cpu_data *tcd)
if (printk_ratelimit()) if (printk_ratelimit())
printk(KERN_WARNING "debug daemon buffer overflowed; " 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); pgcount + 1, tcd->tcd_cur_pages);
CFS_INIT_LIST_HEAD(&pc.pc_pages); CFS_INIT_LIST_HEAD(&pc.pc_pages);
...@@ -238,7 +239,7 @@ static struct trace_page *trace_get_tage(struct trace_cpu_data *tcd, ...@@ -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, 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 *file, const char *fn, const int line,
const char *format1, va_list args, const char *format1, va_list args,
const char *format2, ...) const char *format2, ...)
{ {
struct trace_cpu_data *tcd = NULL; struct trace_cpu_data *tcd = NULL;
struct ptldebug_header header; struct ptldebug_header header;
...@@ -448,6 +449,7 @@ libcfs_assertion_failed(const char *expr, const char *file, ...@@ -448,6 +449,7 @@ libcfs_assertion_failed(const char *expr, const char *file,
{ {
libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
"ASSERTION(%s) failed\n", expr); "ASSERTION(%s) failed\n", expr);
cfs_enter_debugger();
lbug_with_loc(file, func, line); lbug_with_loc(file, func, line);
} }
EXPORT_SYMBOL(libcfs_assertion_failed); EXPORT_SYMBOL(libcfs_assertion_failed);
...@@ -729,11 +731,11 @@ int trace_copyin_string(char *knl_buffer, int knl_buffer_nob, ...@@ -729,11 +731,11 @@ int trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
const char *usr_buffer, int usr_buffer_nob) const char *usr_buffer, int usr_buffer_nob)
{ {
int nob; int nob;
if (usr_buffer_nob > knl_buffer_nob) if (usr_buffer_nob > knl_buffer_nob)
return -EOVERFLOW; return -EOVERFLOW;
if (copy_from_user((void *)knl_buffer, if (copy_from_user((void *)knl_buffer,
(void *)usr_buffer, usr_buffer_nob)) (void *)usr_buffer, usr_buffer_nob))
return -EFAULT; return -EFAULT;
...@@ -759,17 +761,17 @@ int trace_copyout_string(char *usr_buffer, int usr_buffer_nob, ...@@ -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 * copied out string - usually "\n", for /proc entries and "" (i.e. a
* terminating zero byte) for sysctl entries */ * terminating zero byte) for sysctl entries */
int nob = strlen(knl_buffer); int nob = strlen(knl_buffer);
if (nob > usr_buffer_nob) if (nob > usr_buffer_nob)
nob = usr_buffer_nob; nob = usr_buffer_nob;
if (copy_to_user(usr_buffer, knl_buffer, nob)) if (copy_to_user(usr_buffer, knl_buffer, nob))
return -EFAULT; return -EFAULT;
if (append != NULL && nob < usr_buffer_nob) { if (append != NULL && nob < usr_buffer_nob) {
if (copy_to_user(usr_buffer + nob, append, 1)) if (copy_to_user(usr_buffer + nob, append, 1))
return -EFAULT; return -EFAULT;
nob++; nob++;
} }
...@@ -780,7 +782,7 @@ int trace_allocate_string_buffer(char **str, int nob) ...@@ -780,7 +782,7 @@ int trace_allocate_string_buffer(char **str, int nob)
{ {
if (nob > 2 * CFS_PAGE_SIZE) /* string must be "sensible" */ if (nob > 2 * CFS_PAGE_SIZE) /* string must be "sensible" */
return -EINVAL; return -EINVAL;
*str = cfs_alloc(nob, CFS_ALLOC_STD | CFS_ALLOC_ZERO); *str = cfs_alloc(nob, CFS_ALLOC_STD | CFS_ALLOC_ZERO);
if (*str == NULL) if (*str == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -822,7 +824,7 @@ out: ...@@ -822,7 +824,7 @@ out:
int trace_daemon_command(char *str) int trace_daemon_command(char *str)
{ {
int rc = 0; int rc = 0;
tracefile_write_lock(); tracefile_write_lock();
if (strcmp(str, "stop") == 0) { if (strcmp(str, "stop") == 0) {
...@@ -881,7 +883,7 @@ int trace_set_debug_mb(int mb) ...@@ -881,7 +883,7 @@ int trace_set_debug_mb(int mb)
int pages; int pages;
int limit = trace_max_debug_mb(); int limit = trace_max_debug_mb();
struct trace_cpu_data *tcd; struct trace_cpu_data *tcd;
if (mb < num_possible_cpus()) if (mb < num_possible_cpus())
return -EINVAL; return -EINVAL;
...@@ -922,7 +924,7 @@ int trace_get_debug_mb(void) ...@@ -922,7 +924,7 @@ int trace_get_debug_mb(void)
int j; int j;
struct trace_cpu_data *tcd; struct trace_cpu_data *tcd;
int total_pages = 0; int total_pages = 0;
tracefile_read_lock(); tracefile_read_lock();
tcd_for_each(tcd, i, j) tcd_for_each(tcd, i, j)
......
...@@ -147,6 +147,13 @@ void __up(struct semaphore *s) ...@@ -147,6 +147,13 @@ void __up(struct semaphore *s)
* - wait_for_completion(c) * - 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) void init_completion(struct completion *c)
{ {
LASSERT(c != NULL); LASSERT(c != NULL);
...@@ -164,11 +171,23 @@ void complete(struct completion *c) ...@@ -164,11 +171,23 @@ void complete(struct completion *c)
void wait_for_completion(struct completion *c) void wait_for_completion(struct completion *c)
{ {
LASSERT(c != NULL); LASSERT(c != NULL);
do {
if (wait_handler)
wait_handler(1000);
else
break;
} while (c->done == 0);
} }
int wait_for_completion_interruptible(struct completion *c) int wait_for_completion_interruptible(struct completion *c)
{ {
LASSERT(c != NULL); LASSERT(c != NULL);
do {
if (wait_handler)
wait_handler(1000);
else
break;
} while (c->done == 0);
return 0; return 0;
} }
......
...@@ -193,7 +193,7 @@ system_string (char *cmdline, char *str, int len) ...@@ -193,7 +193,7 @@ system_string (char *cmdline, char *str, int len)
WEXITSTATUS(rc) != 0) WEXITSTATUS(rc) != 0)
abort(); abort();
if (strnlen(str, len) == len) if (strlen(str) == len)
str[len - 1] = 0; str[len - 1] = 0;
if (str[strlen(str) - 1] == '\n') if (str[strlen(str) - 1] == '\n')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment