Skip to content

Commit 578454f

Browse files
kaysieversgregkh
authored andcommitted
driver core: add devname module aliases to allow module on-demand auto-loading
This adds: alias: devname:<name> to some common kernel modules, which will allow the on-demand loading of the kernel module when the device node is accessed. Ideally all these modules would be compiled-in, but distros seems too much in love with their modularization that we need to cover the common cases with this new facility. It will allow us to remove a bunch of pretty useless init scripts and modprobes from init scripts. The static device node aliases will be carried in the module itself. The program depmod will extract this information to a file in the module directory: $ cat /lib/modules/2.6.34-00650-g537b60d-dirty/modules.devname # Device nodes to trigger on-demand module loading. microcode cpu/microcode c10:184 fuse fuse c10:229 ppp_generic ppp c108:0 tun net/tun c10:200 dm_mod mapper/control c10:235 Udev will pick up the depmod created file on startup and create all the static device nodes which the kernel modules specify, so that these modules get automatically loaded when the device node is accessed: $ /sbin/udevd --debug ... static_dev_create_from_modules: mknod '/dev/cpu/microcode' c10:184 static_dev_create_from_modules: mknod '/dev/fuse' c10:229 static_dev_create_from_modules: mknod '/dev/ppp' c108:0 static_dev_create_from_modules: mknod '/dev/net/tun' c10:200 static_dev_create_from_modules: mknod '/dev/mapper/control' c10:235 udev_rules_apply_static_dev_perms: chmod '/dev/net/tun' 0666 udev_rules_apply_static_dev_perms: chmod '/dev/fuse' 0666 A few device nodes are switched to statically allocated numbers, to allow the static nodes to work. This might also useful for systems which still run a plain static /dev, which is completely unsafe to use with any dynamic minor numbers. Note: The devname aliases must be limited to the *common* and *single*instance* device nodes, like the misc devices, and never be used for conceptually limited systems like the loop devices, which should rather get fixed properly and get a control node for losetup to talk to, instead of creating a random number of device nodes in advance, regardless if they are ever used. This facility is to hide the mess distros are creating with too modualized kernels, and just to hide that these modules are not compiled-in, and not to paper-over broken concepts. Thanks! :) Cc: Greg Kroah-Hartman <[email protected]> Cc: David S. Miller <[email protected]> Cc: Miklos Szeredi <[email protected]> Cc: Chris Mason <[email protected]> Cc: Alasdair G Kergon <[email protected]> Cc: Tigran Aivazian <[email protected]> Cc: Ian Kent <[email protected]> Signed-Off-By: Kay Sievers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ec96e2f commit 578454f

File tree

8 files changed

+17
-4
lines changed

8 files changed

+17
-4
lines changed

Documentation/devices.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ Your cooperation is appreciated.
443443
231 = /dev/snapshot System memory snapshot device
444444
232 = /dev/kvm Kernel-based virtual machine (hardware virtualization extensions)
445445
233 = /dev/kmview View-OS A process with a view
446+
234 = /dev/btrfs-control Btrfs control device
447+
235 = /dev/autofs Autofs control device
446448
240-254 Reserved for local use
447449
255 Reserved for MISC_DYNAMIC_MINOR
448450

arch/x86/kernel/microcode_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static void microcode_dev_exit(void)
260260
}
261261

262262
MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
263+
MODULE_ALIAS("devname:cpu/microcode");
263264
#else
264265
#define microcode_dev_init() 0
265266
#define microcode_dev_exit() do { } while (0)

drivers/net/ppp_generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,5 +2926,5 @@ EXPORT_SYMBOL(ppp_output_wakeup);
29262926
EXPORT_SYMBOL(ppp_register_compressor);
29272927
EXPORT_SYMBOL(ppp_unregister_compressor);
29282928
MODULE_LICENSE("GPL");
2929-
MODULE_ALIAS_CHARDEV_MAJOR(PPP_MAJOR);
2930-
MODULE_ALIAS("/dev/ppp");
2929+
MODULE_ALIAS_CHARDEV(PPP_MAJOR, 0);
2930+
MODULE_ALIAS("devname:ppp");

drivers/net/tun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,3 +1649,4 @@ MODULE_DESCRIPTION(DRV_DESCRIPTION);
16491649
MODULE_AUTHOR(DRV_COPYRIGHT);
16501650
MODULE_LICENSE("GPL");
16511651
MODULE_ALIAS_MISCDEV(TUN_MINOR);
1652+
MODULE_ALIAS("devname:net/tun");

fs/autofs4/dev-ioctl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,14 @@ static const struct file_operations _dev_ioctl_fops = {
736736
};
737737

738738
static struct miscdevice _autofs_dev_ioctl_misc = {
739-
.minor = MISC_DYNAMIC_MINOR,
739+
.minor = AUTOFS_MINOR,
740740
.name = AUTOFS_DEVICE_NAME,
741741
.fops = &_dev_ioctl_fops
742742
};
743743

744+
MODULE_ALIAS_MISCDEV(AUTOFS_MINOR);
745+
MODULE_ALIAS("devname:autofs");
746+
744747
/* Register/deregister misc character device */
745748
int autofs_dev_ioctl_init(void)
746749
{

fs/btrfs/super.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,14 @@ static const struct file_operations btrfs_ctl_fops = {
832832
};
833833

834834
static struct miscdevice btrfs_misc = {
835-
.minor = MISC_DYNAMIC_MINOR,
835+
.minor = BTRFS_MINOR,
836836
.name = "btrfs-control",
837837
.fops = &btrfs_ctl_fops
838838
};
839839

840+
MODULE_ALIAS_MISCDEV(BTRFS_MINOR);
841+
MODULE_ALIAS("devname:btrfs-control");
842+
840843
static int btrfs_interface_init(void)
841844
{
842845
return misc_register(&btrfs_misc);

fs/fuse/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/slab.h>
1919

2020
MODULE_ALIAS_MISCDEV(FUSE_MINOR);
21+
MODULE_ALIAS("devname:fuse");
2122

2223
static struct kmem_cache *fuse_req_cachep;
2324

include/linux/miscdevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define FUSE_MINOR 229
3232
#define KVM_MINOR 232
3333
#define VHOST_NET_MINOR 233
34+
#define BTRFS_MINOR 234
35+
#define AUTOFS_MINOR 235
3436
#define MISC_DYNAMIC_MINOR 255
3537

3638
struct device;

0 commit comments

Comments
 (0)