public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@SteelEye.com>
To: greg@kroah.com, Rusty Russell <rusty@rustcorp.com.au>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>,
	SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: [RFC] put symbolic links between drivers and modules in the sysfs tree
Date: 20 Sep 2004 13:29:44 -0400	[thread overview]
Message-ID: <1095701390.2016.34.camel@mulgrave> (raw)

This functionality is essential for us to work out which drivers are
supplied by which modules.  We use this in turn to work out which
modules are necessary to find the root device (and hence what
initrd/initramfs needs to insert).

If you look at debian at the moment, it uses a huge mapping table on
/proc/scsi/* to do this.  If we implement the sysfs feature, we can
simply go from /sys/block/<device> to the actual device to the driver
and then to the module with no need of any fixed tables.

The code is a first cut and introduces two new module APIs:
module_add_driver() and module_remove_driver().  We need this because
the generic device model driver has no current knowledge of modules.  We
could enhance it to have a struct module * in struct device_driver, but
once we have the sysfs links which this patch provides, there didn't
seem to be a compelling reason to add it to struct device_driver.

Comments?

James

===== drivers/base/bus.c 1.62 vs edited =====
--- 1.62/drivers/base/bus.c	2004-07-07 19:55:49 -05:00
+++ edited/drivers/base/bus.c	2004-09-20 11:09:52 -05:00
@@ -553,6 +553,7 @@
 		pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
 		driver_detach(drv);
 		up_write(&drv->bus->subsys.rwsem);
+		module_remove_driver(drv);
 		kobject_unregister(&drv->kobj);
 		put_bus(drv->bus);
 	}
===== drivers/scsi/hosts.c 1.101 vs edited =====
--- 1.101/drivers/scsi/hosts.c	2004-09-09 16:16:26 -05:00
+++ edited/drivers/scsi/hosts.c	2004-09-20 10:49:08 -05:00
@@ -130,6 +130,11 @@
 		goto out_del_classdev;
 
 	scsi_proc_host_add(shost);
+	if (shost->hostt->module && shost->shost_gendev.parent &&
+	    shost->shost_gendev.parent->driver)
+		module_add_driver(shost->hostt->module, 
+				  shost->shost_gendev.parent->driver);
+		
 	return error;
 
  out_del_classdev:
===== include/linux/module.h 1.79 vs edited =====
--- 1.79/include/linux/module.h	2004-06-27 02:19:28 -05:00
+++ edited/include/linux/module.h	2004-09-20 11:06:13 -05:00
@@ -578,6 +578,9 @@
 
 #define __MODULE_STRING(x) __stringify(x)
 
+/* forward reference for the module_add/remove_driver API */
+struct device_driver;
+
 /* Use symbol_get and symbol_put instead.  You'll thank me. */
 #define HAVE_INTER_MODULE
 extern void inter_module_register(const char *, struct module *, const void *);
@@ -585,5 +588,7 @@
 extern const void *inter_module_get(const char *);
 extern const void *inter_module_get_request(const char *, const char *);
 extern void inter_module_put(const char *);
+extern void module_add_driver(struct module *, struct device_driver *);
+extern void module_remove_driver(struct device_driver *);
 
 #endif /* _LINUX_MODULE_H */
===== kernel/module.c 1.120 vs edited =====
--- 1.120/kernel/module.c	2004-09-08 01:33:04 -05:00
+++ edited/kernel/module.c	2004-09-20 11:10:47 -05:00
@@ -34,6 +34,7 @@
 #include <linux/vermagic.h>
 #include <linux/notifier.h>
 #include <linux/stop_machine.h>
+#include <linux/device.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
@@ -2139,6 +2140,30 @@
 		printk(" %s", mod->name);
 	printk("\n");
 }
+
+void module_add_driver(struct module *mod, struct device_driver *drv)
+{
+	if (!mod || !drv)
+		return;
+	if (!mod->mkobj)
+		return;
+
+	/* Note: Perhaps we should store this link in the
+	 * device_driver structure as well (i.e. have a struct module *
+	 * element). */
+
+	/* Don't check return code; this call is idempotent */
+	sysfs_create_link(&drv->kobj, &mod->mkobj->kobj, "module");
+}
+EXPORT_SYMBOL(module_add_driver);
+
+void module_remove_driver(struct device_driver *drv)
+{
+	if (!drv)
+		return;
+	sysfs_remove_link(&drv->kobj, "module");
+}
+EXPORT_SYMBOL(module_remove_driver);
 
 #ifdef CONFIG_MODVERSIONS
 /* Generate the signature for struct module here, too, for modversions. */




             reply	other threads:[~2004-09-20 17:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-20 17:29 James Bottomley [this message]
2004-09-22 23:04 ` [RFC] put symbolic links between drivers and modules in the sysfs tree Greg KH
2004-09-22 23:06   ` Greg KH
2004-09-22 23:40     ` Greg KH
2004-09-25  7:38 ` viro
2004-09-25  8:05   ` Herbert Xu
2004-09-25  8:21     ` Arjan van de Ven
2004-09-25 13:16       ` James Bottomley
2004-09-25 13:14   ` James Bottomley
2004-09-26 10:37     ` Herbert Xu
2004-09-26 13:09       ` James Bottomley
2004-09-25 16:46   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1095701390.2016.34.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox