All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.9
Date: Tue, 19 Oct 2004 09:36:21 -0700	[thread overview]
Message-ID: <10982037811163@kroah.com> (raw)
In-Reply-To: <1098203779656@kroah.com>

ChangeSet 1.1939.1.47, 2004/09/22 16:09:41-07:00, greg@kroah.com

[PATCH] Put symbolic links between drivers and modules in the sysfs tree

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.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 drivers/base/bus.c     |    2 ++
 include/linux/device.h |    2 ++
 include/linux/module.h |   14 ++++++++++++++
 kernel/module.c        |   21 +++++++++++++++++++++
 4 files changed, 39 insertions(+)


diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c	2004-10-19 09:22:29 -07:00
+++ b/drivers/base/bus.c	2004-10-19 09:22:29 -07:00
@@ -529,6 +529,7 @@
 		down_write(&bus->subsys.rwsem);
 		driver_attach(drv);
 		up_write(&bus->subsys.rwsem);
+		module_add_driver(drv->owner, drv);
 
 		driver_add_attrs(bus, drv);
 	}
@@ -553,6 +554,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);
 	}
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	2004-10-19 09:22:29 -07:00
+++ b/include/linux/device.h	2004-10-19 09:22:29 -07:00
@@ -106,6 +106,8 @@
 	struct kobject		kobj;
 	struct list_head	devices;
 
+	struct module 		* owner;
+
 	int	(*probe)	(struct device * dev);
 	int 	(*remove)	(struct device * dev);
 	void	(*shutdown)	(struct device * dev);
diff -Nru a/include/linux/module.h b/include/linux/module.h
--- a/include/linux/module.h	2004-10-19 09:22:29 -07:00
+++ b/include/linux/module.h	2004-10-19 09:22:29 -07:00
@@ -445,6 +445,11 @@
 int unregister_module_notifier(struct notifier_block * nb);
 
 extern void print_modules(void);
+
+struct device_driver;
+void module_add_driver(struct module *, struct device_driver *);
+void module_remove_driver(struct device_driver *);
+
 #else /* !CONFIG_MODULES... */
 #define EXPORT_SYMBOL(sym)
 #define EXPORT_SYMBOL_GPL(sym)
@@ -534,6 +539,15 @@
 static inline void print_modules(void)
 {
 }
+
+static inline void module_add_driver(struct module *, struct device_driver *)
+{
+}
+
+static inline void module_remove_driver(struct device_driver *)
+{
+}
+
 #endif /* CONFIG_MODULES */
 
 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
diff -Nru a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c	2004-10-19 09:22:29 -07:00
+++ b/kernel/module.c	2004-10-19 09:22:29 -07: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,26 @@
 		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;
+
+	/* 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-10-19 16:55 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-19 16:34 [BK PATCH] Driver Core patches for 2.6.9 Greg KH
2004-10-19 16:35 ` [PATCH] " Greg KH
2004-10-19 16:35   ` Greg KH
2004-10-19 16:36     ` Greg KH
2004-10-19 16:36       ` Greg KH
2004-10-19 16:36         ` Greg KH
2004-10-19 16:36           ` Greg KH
2004-10-19 16:36             ` Greg KH
2004-10-19 16:36               ` Greg KH
2004-10-19 16:36                 ` Greg KH
2004-10-19 16:36                   ` Greg KH
2004-10-19 16:36                     ` Greg KH
2004-10-19 16:36                       ` Greg KH [this message]
2004-10-19 16:36                         ` Greg KH
2004-10-19 16:36                           ` Greg KH
2004-10-19 16:36                             ` Greg KH
2004-10-19 16:36                               ` Greg KH
2004-10-19 16:36                                 ` Greg KH
2004-10-19 16:36                                   ` Greg KH
2004-10-19 16:36                                     ` Greg KH
2004-10-19 16:36                                       ` Greg KH
2004-10-19 16:36                                         ` Greg KH
2004-10-19 16:36                                           ` Greg KH
2004-10-19 16:36                                             ` Greg KH
2004-10-19 16:36                                               ` Greg KH
2004-10-19 16:36                                                 ` Greg KH
2004-10-19 16:36                                                   ` Greg KH
2004-10-19 16:36                                                     ` Greg KH
2004-10-19 16:36                                                       ` Greg KH
2004-10-19 16:37                                                         ` Greg KH
2004-10-19 16:37                                                           ` Greg KH
2004-10-19 16:37                                                             ` Greg KH
2004-10-19 16:37                                                               ` Greg KH
2004-10-19 16:37                                                                 ` Greg KH
2004-10-19 16:37                                                                   ` Greg KH
2004-10-23 20:20                     ` Kronos
2004-10-23 20:34                       ` Greg KH
2004-10-23 21:46                         ` Kronos

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=10982037811163@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.