[patch] depmod: export static device node information to modules.devname

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kay Sievers <kay.sievers@xxxxxxxx>
Subject: depmod: export static device node information to modules.devname

To be able to let udev support kernel module on-demand loading, the next
kernel will export:
  alias: devname:<name>
for some well-defined common kernel modules. This will let the kernel call
modprobe when the device node is accessed, the subsystem/driver will be
initialized and the open() of the device node will magically succeed.

The static device node aliases will be carried in the module itself. depmod
extracts this information:
  $ 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
---

 depmod.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/depmod.c b/depmod.c
index 697477f..71ecc1c 100644
--- a/depmod.c
+++ b/depmod.c
@@ -978,6 +978,43 @@ static int output_softdeps(struct module *modules, FILE *out, char *dirname)
 	return 1;
 }
 
+static int output_devname(struct module *modules, FILE *out, char *dirname)
+{
+	struct module *m;
+
+	fprintf(out, "# Device nodes to trigger on-demand module loading.\n");
+	for (m = modules; m != NULL; m = m->next) {
+		struct string_table *tbl;
+		int i;
+		char type = '\0';
+		const char *devname = NULL;
+
+		tbl = m->file->ops->load_strings(m->file, ".modinfo", NULL);
+		for (i = 0; tbl && i < tbl->cnt; i++) {
+			const char *p = tbl->str[i];
+			unsigned int maj, min;
+
+			if (sscanf(p, "alias=char-major-%u-%u", &maj, &min) == 2)
+				type = 'c';
+			else if (sscanf(p, "alias=block-major-%u-%u", &maj, &min) == 2)
+				type = 'b';
+			else if (strstarts(p, "alias=devname:"))
+				devname = &p[strlen("alias=devname:")];
+
+			if (type && devname) {
+				char modname[strlen(m->pathname)+1];
+
+				filename2modname(modname, m->pathname);
+				fprintf(out, "%s %s %c%u:%u\n",
+					modname, devname, type, maj, min);
+				break;
+			}
+		}
+		strtbl_free(tbl);
+	}
+	return 1;
+}
+
 struct depfile {
 	char *name;
 	int (*func)(struct module *, FILE *, char *dirname);
@@ -1001,6 +1038,7 @@ static struct depfile depfiles[] = {
 	{ "modules.symbols", output_symbols, 0 },
 	{ "modules.symbols.bin", output_symbols_bin, 0 },
 	{ "modules.builtin.bin", output_builtin_bin, 0 },
+	{ "modules.devname", output_devname, 0 },
 };
 
 /* If we can't figure it out, it's safe to say "true". */


--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux