Skip to content

Commit 88bfa32

Browse files
kaysieversrustyrussell
authored andcommitted
module: add /sys/module/<name>/uevent files
Userspace wants to manage module parameters with udev rules. This currently only works for loaded modules, but not for built-in ones. To allow access to the built-in modules we need to re-trigger all module load events that happened before any userspace was running. We already do the same thing for all devices, subsystems(buses) and drivers. This adds the currently missing /sys/module/<name>/uevent files to all module entries. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (split & trivial fix)
1 parent 4befb02 commit 88bfa32

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎include/linux/module.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct module_version_attribute {
7575
extern ssize_t __modver_version_show(struct module_attribute *,
7676
struct module_kobject *, char *);
7777

78+
extern struct module_attribute module_uevent;
7879

7980
/* These are either module local, or the kernel's dummy ones. */
8081
extern int init_module(void);

‎kernel/module.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,27 @@ static struct module_attribute initstate = {
975975
.show = show_initstate,
976976
};
977977

978+
static ssize_t store_uevent(struct module_attribute *mattr,
979+
struct module_kobject *mk,
980+
const char *buffer, size_t count)
981+
{
982+
enum kobject_action action;
983+
984+
if (kobject_action_type(buffer, count, &action) == 0)
985+
kobject_uevent(&mk->kobj, action);
986+
return count;
987+
}
988+
989+
struct module_attribute module_uevent = {
990+
.attr = { .name = "uevent", .mode = 0200 },
991+
.store = store_uevent,
992+
};
993+
978994
static struct module_attribute *modinfo_attrs[] = {
979995
&modinfo_version,
980996
&modinfo_srcversion,
981997
&initstate,
998+
&module_uevent,
982999
#ifdef CONFIG_MODULE_UNLOAD
9831000
&refcnt,
9841001
#endif

‎kernel/params.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ static struct module_kobject * __init locate_module_kobject(const char *name)
730730
mk->kobj.kset = module_kset;
731731
err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL,
732732
"%s", name);
733+
#ifdef CONFIG_MODULES
734+
if (!err)
735+
err = sysfs_create_file(&mk->kobj, &module_uevent.attr);
736+
#endif
733737
if (err) {
734738
kobject_put(&mk->kobj);
735739
printk(KERN_ERR

0 commit comments

Comments
 (0)