Hard module dependencies

Tim Gardner tim.gardner at canonical.com
Thu Oct 8 13:50:18 UTC 2009


Andy Whitcroft wrote:
> On Tue, Oct 06, 2009 at 10:12:57AM -0600, Tim Gardner wrote:
>> Andy - How about something like this? I need to test some boundary
>> conditions (like what happens if the target is not a module, etc), and
>> flesh out the commit log, perhaps add some comments to the function.
>> -- 
>> Tim Gardner tim.gardner at canonical.com
> 
>> From 31223d1147dc4d96a70688b5987e9cb63b579f62 Mon Sep 17 00:00:00 2001
>> From: Tim Gardner <tim.gardner at canonical.com>
>> Date: Tue, 6 Oct 2009 08:52:38 -0600
>> Subject: [PATCH 1/2] UBUNTU: [Upstream] Added module_depends()
>>
>> Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
>> ---
>>  include/linux/module.h |   19 +++++++++++++++++++
>>  1 files changed, 19 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/module.h b/include/linux/module.h
>> index 098bdb7..8827da5 100644
>> --- a/include/linux/module.h
>> +++ b/include/linux/module.h
>> @@ -703,6 +703,25 @@ static inline void module_remove_modinfo_attrs(struct module *mod)
>>  
>>  #define __MODULE_STRING(x) __stringify(x)
>>  
>> +static inline void module_depends(const char *mod_name)
>> +{
>> +	struct module *mod;
>> +
>> +	if (mutex_lock_interruptible(&module_mutex) != 0) {
>> +		printk(KERN_ERR "%s Could not get module_mutex\n",__func__);
>> +		return;
>> +	}
>> +	mod = find_module(mod_name);
>> +	if (!mod) {
>> +		mutex_unlock(&module_mutex);
>> +		printk(KERN_ERR "%s Could not find module %s\n",__func__,mod_name);
>> +		return;
>> +	}
>> +	if (use_module(THIS_MODULE,mod) <= 0) {
>> +		printk(KERN_ERR "%s Could not load module %s\n",__func__,mod_name);
>> +	}
>> +	mutex_unlock(&module_mutex);
>> +}
>>  
>>  #ifdef CONFIG_GENERIC_BUG
>>  int  module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
> 
> Looking pretty sensible, how did this fair in testing?
> 
> -apw

I ended up going with a much simpler hack, but still had to touch 2
module source files to get the job done. I think there is a more elegant
way using request_module(). I missed it the first time 'cause I was
looking in modules.h instead of kmod.h for support functions.

http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-karmic.git;a=commit;h=456d96a8165788cfd1e593fb7540f4a58fe2f46b

We're definitely going to do something different for Lucid.

rtg
-- 
Tim Gardner tim.gardner at canonical.com




More information about the kernel-team mailing list