Commit 270a6c4c authored by Kay Sievers's avatar Kay Sievers Committed by Greg Kroah-Hartman

/sys/modules/*/holders

  /sys/module/usbcore/
  |-- drivers
  |   |-- usb:hub -> ../../../subsystem/usb/drivers/hub
  |   |-- usb:usb -> ../../../subsystem/usb/drivers/usb
  |   `-- usb:usbfs -> ../../../subsystem/usb/drivers/usbfs
  |-- holders
  |   |-- ehci_hcd -> ../../../module/ehci_hcd
  |   |-- uhci_hcd -> ../../../module/uhci_hcd
  |   |-- usb_storage -> ../../../module/usb_storage
  |   `-- usbhid -> ../../../module/usbhid
  |-- initstate
Signed-off-by: default avatarKay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 80f745fb
...@@ -264,6 +264,7 @@ struct module ...@@ -264,6 +264,7 @@ struct module
struct module_attribute *modinfo_attrs; struct module_attribute *modinfo_attrs;
const char *version; const char *version;
const char *srcversion; const char *srcversion;
struct kobject *holders_dir;
/* Exported symbols */ /* Exported symbols */
const struct kernel_symbol *syms; const struct kernel_symbol *syms;
......
...@@ -537,6 +537,8 @@ static int already_uses(struct module *a, struct module *b) ...@@ -537,6 +537,8 @@ static int already_uses(struct module *a, struct module *b)
static int use_module(struct module *a, struct module *b) static int use_module(struct module *a, struct module *b)
{ {
struct module_use *use; struct module_use *use;
int no_warn;
if (b == NULL || already_uses(a, b)) return 1; if (b == NULL || already_uses(a, b)) return 1;
if (!strong_try_module_get(b)) if (!strong_try_module_get(b))
...@@ -552,6 +554,7 @@ static int use_module(struct module *a, struct module *b) ...@@ -552,6 +554,7 @@ static int use_module(struct module *a, struct module *b)
use->module_which_uses = a; use->module_which_uses = a;
list_add(&use->list, &b->modules_which_use_me); list_add(&use->list, &b->modules_which_use_me);
no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
return 1; return 1;
} }
...@@ -569,6 +572,7 @@ static void module_unload_free(struct module *mod) ...@@ -569,6 +572,7 @@ static void module_unload_free(struct module *mod)
module_put(i); module_put(i);
list_del(&use->list); list_del(&use->list);
kfree(use); kfree(use);
sysfs_remove_link(i->holders_dir, mod->name);
/* There can be at most one match. */ /* There can be at most one match. */
break; break;
} }
...@@ -1106,9 +1110,7 @@ static void module_remove_modinfo_attrs(struct module *mod) ...@@ -1106,9 +1110,7 @@ static void module_remove_modinfo_attrs(struct module *mod)
kfree(mod->modinfo_attrs); kfree(mod->modinfo_attrs);
} }
static int mod_sysfs_setup(struct module *mod, static int mod_sysfs_init(struct module *mod)
struct kernel_param *kparam,
unsigned int num_params)
{ {
int err; int err;
...@@ -1125,15 +1127,30 @@ static int mod_sysfs_setup(struct module *mod, ...@@ -1125,15 +1127,30 @@ static int mod_sysfs_setup(struct module *mod,
kobj_set_kset_s(&mod->mkobj, module_subsys); kobj_set_kset_s(&mod->mkobj, module_subsys);
mod->mkobj.mod = mod; mod->mkobj.mod = mod;
/* delay uevent until full sysfs population */
kobject_init(&mod->mkobj.kobj); kobject_init(&mod->mkobj.kobj);
out:
return err;
}
static int mod_sysfs_setup(struct module *mod,
struct kernel_param *kparam,
unsigned int num_params)
{
int err;
/* delay uevent until full sysfs population */
err = kobject_add(&mod->mkobj.kobj); err = kobject_add(&mod->mkobj.kobj);
if (err) if (err)
goto out; goto out;
mod->holders_dir = kobject_add_dir(&mod->mkobj.kobj, "holders");
if (!mod->holders_dir)
goto out_unreg;
err = module_param_sysfs_setup(mod, kparam, num_params); err = module_param_sysfs_setup(mod, kparam, num_params);
if (err) if (err)
goto out_unreg_drivers; goto out_unreg_holders;
err = module_add_modinfo_attrs(mod); err = module_add_modinfo_attrs(mod);
if (err) if (err)
...@@ -1144,7 +1161,9 @@ static int mod_sysfs_setup(struct module *mod, ...@@ -1144,7 +1161,9 @@ static int mod_sysfs_setup(struct module *mod,
out_unreg_param: out_unreg_param:
module_param_sysfs_remove(mod); module_param_sysfs_remove(mod);
out_unreg_drivers: out_unreg_holders:
kobject_unregister(mod->holders_dir);
out_unreg:
kobject_del(&mod->mkobj.kobj); kobject_del(&mod->mkobj.kobj);
kobject_put(&mod->mkobj.kobj); kobject_put(&mod->mkobj.kobj);
out: out:
...@@ -1157,6 +1176,8 @@ static void mod_kobject_remove(struct module *mod) ...@@ -1157,6 +1176,8 @@ static void mod_kobject_remove(struct module *mod)
module_param_sysfs_remove(mod); module_param_sysfs_remove(mod);
if (mod->mkobj.drivers_dir) if (mod->mkobj.drivers_dir)
kobject_unregister(mod->mkobj.drivers_dir); kobject_unregister(mod->mkobj.drivers_dir);
if (mod->holders_dir)
kobject_unregister(mod->holders_dir);
kobject_unregister(&mod->mkobj.kobj); kobject_unregister(&mod->mkobj.kobj);
} }
...@@ -1761,6 +1782,10 @@ static struct module *load_module(void __user *umod, ...@@ -1761,6 +1782,10 @@ static struct module *load_module(void __user *umod,
/* Now we've moved module, initialize linked lists, etc. */ /* Now we've moved module, initialize linked lists, etc. */
module_unload_init(mod); module_unload_init(mod);
/* Initialize kobject, so we can reference it. */
if (mod_sysfs_init(mod) != 0)
goto cleanup;
/* Set up license info based on the info section */ /* Set up license info based on the info section */
set_license(mod, get_modinfo(sechdrs, infoindex, "license")); set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#define DEBUGP(fmt, a...) #define DEBUGP(fmt, a...)
#endif #endif
static struct kobj_type module_ktype;
static inline char dash2underscore(char c) static inline char dash2underscore(char c)
{ {
if (c == '-') if (c == '-')
...@@ -671,6 +673,19 @@ static struct sysfs_ops module_sysfs_ops = { ...@@ -671,6 +673,19 @@ static struct sysfs_ops module_sysfs_ops = {
.store = module_attr_store, .store = module_attr_store,
}; };
static int uevent_filter(struct kset *kset, struct kobject *kobj)
{
struct kobj_type *ktype = get_ktype(kobj);
if (ktype == &module_ktype)
return 1;
return 0;
}
static struct kset_uevent_ops module_uevent_ops = {
.filter = uevent_filter,
};
#else #else
static struct sysfs_ops module_sysfs_ops = { static struct sysfs_ops module_sysfs_ops = {
.show = NULL, .show = NULL,
...@@ -682,7 +697,7 @@ static struct kobj_type module_ktype = { ...@@ -682,7 +697,7 @@ static struct kobj_type module_ktype = {
.sysfs_ops = &module_sysfs_ops, .sysfs_ops = &module_sysfs_ops,
}; };
decl_subsys(module, &module_ktype, NULL); decl_subsys(module, &module_ktype, &module_uevent_ops);
/* /*
* param_sysfs_init - wrapper for built-in params support * param_sysfs_init - wrapper for built-in params support
......
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