Commit fbf7eda6 authored by Rusty Russell's avatar Rusty Russell Committed by Christoph Hellwig

[PATCH] __module_get

Introduces __module_get for places where we know we already hold
a reference and ignoring the fact that the module is being "rmmod --wait"ed
is simpler.
parent 67ac5b86
...@@ -32,17 +32,7 @@ static rwlock_t file_systems_lock = RW_LOCK_UNLOCKED; ...@@ -32,17 +32,7 @@ static rwlock_t file_systems_lock = RW_LOCK_UNLOCKED;
/* WARNING: This can be used only if we _already_ own a reference */ /* WARNING: This can be used only if we _already_ own a reference */
void get_filesystem(struct file_system_type *fs) void get_filesystem(struct file_system_type *fs)
{ {
if (!try_module_get(fs->owner)) { __module_get(fs->owner);
#ifdef CONFIG_MODULE_UNLOAD
unsigned int cpu = get_cpu();
local_inc(&fs->owner->ref[cpu].count);
put_cpu();
#else
/* Getting filesystem while it's starting up? We're
already supposed to have a reference. */
BUG();
#endif
}
} }
void put_filesystem(struct file_system_type *fs) void put_filesystem(struct file_system_type *fs)
......
...@@ -265,6 +265,7 @@ struct module *module_text_address(unsigned long addr); ...@@ -265,6 +265,7 @@ struct module *module_text_address(unsigned long addr);
#ifdef CONFIG_MODULE_UNLOAD #ifdef CONFIG_MODULE_UNLOAD
unsigned int module_refcount(struct module *mod);
void __symbol_put(const char *symbol); void __symbol_put(const char *symbol);
#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
void symbol_put_addr(void *addr); void symbol_put_addr(void *addr);
...@@ -275,6 +276,17 @@ void symbol_put_addr(void *addr); ...@@ -275,6 +276,17 @@ void symbol_put_addr(void *addr);
#define local_dec(x) atomic_dec(x) #define local_dec(x) atomic_dec(x)
#endif #endif
/* Sometimes we know we already have a refcount, and it's easier not
to handle the error case (which only happens with rmmod --wait). */
static inline void __module_get(struct module *module)
{
if (module) {
BUG_ON(module_refcount(module) == 0);
local_inc(&module->ref[get_cpu()].count);
put_cpu();
}
}
static inline int try_module_get(struct module *module) static inline int try_module_get(struct module *module)
{ {
int ret = 1; int ret = 1;
...@@ -310,6 +322,9 @@ static inline int try_module_get(struct module *module) ...@@ -310,6 +322,9 @@ static inline int try_module_get(struct module *module)
static inline void module_put(struct module *module) static inline void module_put(struct module *module)
{ {
} }
static inline void __module_get(struct module *module)
{
}
#define symbol_put(x) do { } while(0) #define symbol_put(x) do { } while(0)
#define symbol_put_addr(p) do { } while(0) #define symbol_put_addr(p) do { } while(0)
...@@ -367,6 +382,10 @@ static inline struct module *module_text_address(unsigned long addr) ...@@ -367,6 +382,10 @@ static inline struct module *module_text_address(unsigned long addr)
#define symbol_put(x) do { } while(0) #define symbol_put(x) do { } while(0)
#define symbol_put_addr(x) do { } while(0) #define symbol_put_addr(x) do { } while(0)
static inline void __module_get(struct module *module)
{
}
static inline int try_module_get(struct module *module) static inline int try_module_get(struct module *module)
{ {
return 1; return 1;
......
...@@ -431,7 +431,7 @@ static inline void restart_refcounts(void) ...@@ -431,7 +431,7 @@ static inline void restart_refcounts(void)
} }
#endif #endif
static unsigned int module_refcount(struct module *mod) unsigned int module_refcount(struct module *mod)
{ {
unsigned int i, total = 0; unsigned int i, total = 0;
...@@ -439,6 +439,7 @@ static unsigned int module_refcount(struct module *mod) ...@@ -439,6 +439,7 @@ static unsigned int module_refcount(struct module *mod)
total += atomic_read(&mod->ref[i].count); total += atomic_read(&mod->ref[i].count);
return total; return total;
} }
EXPORT_SYMBOL(module_refcount);
/* This exists whether we can unload or not */ /* This exists whether we can unload or not */
static void free_module(struct module *mod); static void free_module(struct module *mod);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment