[PATCH] drivers/scsi: add hotplug with MODNAME env var

2005-03-04 Thread Roman Kagan
  Hi,

The patch below adds hotplug callout to scsi_bus_type, and makes it
generate MODNAME environment variable for use with modprobe.  Also it
adds a few matching MODULE_ALIAS() macros to the appropriate modules.

Two caveats:

 1) I'm not particularly certain about the scsi-type- prefix: it may
resemble cases where request_module() is used;  the reason I used
dashes was that MODULE_ALIAS() macros were put manually into the
code, rather that automatically generated from a corresponding
*_dev_id table;

 2) TYPE_* macros in include/scsi/scsi.h are in hex and can't be
conveniently __stringify()-ed, so I've hardcoded the values and
inserted comments next to them referring to those macros.

It handles only sd, sr, st, and osst cases.  I'd like to leave it to
scsi folks to decide whether sg should be scsi-type-* or the explicit
list of types not handled by other modules.

Roman.

Signed-off-by: Roman Kagan [EMAIL PROTECTED]

 drivers/scsi/scsi_sysfs.c |   16 
 drivers/scsi/sd.c |2 ++
 drivers/scsi/sr.c |3 +++
 drivers/scsi/st.c |2 ++
 drivers/scsi/osst.c   |2 ++
 5 files changed, 25 insertions(+)

diff -rup linux-2.6.11/drivers/scsi/scsi_sysfs.c 
linux-2.6.11.modname/drivers/scsi/scsi_sysfs.c
--- linux-2.6.11/drivers/scsi/scsi_sysfs.c  2005-03-02 10:37:49.0 
+0300
+++ linux-2.6.11.modname/drivers/scsi/scsi_sysfs.c  2005-03-04 
13:18:05.0 +0300
@@ -202,9 +202,25 @@ static int scsi_bus_match(struct device 
return (sdp-inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
 }
 
+static int scsi_hotplug(struct device *dev, char **envp,
+   int num_envp, char *buffer, int buffer_size)
+{
+   struct scsi_device *sdev = to_scsi_device(dev);
+   int i = 0;
+   int length = 0;
+
+   if (add_hotplug_env_var(envp, num_envp, i, buffer, buffer_size, 
length,
+   MODNAME=scsi-type-%d, sdev-type))
+   return -ENOMEM;
+
+   envp[i] = NULL;
+   return 0;
+}
+
 struct bus_type scsi_bus_type = {
 .name  = scsi,
 .match = scsi_bus_match,
+   .hotplug= scsi_hotplug,
 };
 
 int scsi_sysfs_register(void)
diff -rup linux-2.6.11/drivers/scsi/sd.c linux-2.6.11.modname/drivers/scsi/sd.c
--- linux-2.6.11/drivers/scsi/sd.c  2005-03-02 10:38:17.0 +0300
+++ linux-2.6.11.modname/drivers/scsi/sd.c  2005-03-04 13:16:22.0 
+0300
@@ -1653,6 +1653,8 @@ static void __exit exit_sd(void)
 MODULE_LICENSE(GPL);
 MODULE_AUTHOR(Eric Youngdale);
 MODULE_DESCRIPTION(SCSI disk (sd) driver);
+MODULE_ALIAS(scsi-type-0);   /*  TYPE_DISK   */
+MODULE_ALIAS(scsi-type-7);   /*  TYPE_MOD*/
 
 module_init(init_sd);
 module_exit(exit_sd);
diff -rup linux-2.6.11/drivers/scsi/sr.c linux-2.6.11.modname/drivers/scsi/sr.c
--- linux-2.6.11/drivers/scsi/sr.c  2005-03-02 10:38:37.0 +0300
+++ linux-2.6.11.modname/drivers/scsi/sr.c  2005-03-04 13:16:22.0 
+0300
@@ -956,6 +956,9 @@ static void __exit exit_sr(void)
unregister_blkdev(SCSI_CDROM_MAJOR, sr);
 }
 
+MODULE_ALIAS(scsi-type-4);   /*  TYPE_WORM   */
+MODULE_ALIAS(scsi-type-5);   /*  TYPE_ROM*/
+
 module_init(init_sr);
 module_exit(exit_sr);
 MODULE_LICENSE(GPL);
diff -rup linux-2.6.11/drivers/scsi/st.c linux-2.6.11.modname/drivers/scsi/st.c
--- linux-2.6.11/drivers/scsi/st.c  2005-03-02 10:38:12.0 +0300
+++ linux-2.6.11.modname/drivers/scsi/st.c  2005-03-04 13:16:22.0 
+0300
@@ -4090,6 +4090,8 @@ static void __exit exit_st(void)
printk(KERN_INFO st: Unloaded.\n);
 }
 
+MODULE_ALIAS(scsi-type-1);   /*  TYPE_TAPE   */
+
 module_init(init_st);
 module_exit(exit_st);
 
diff -rup linux-2.6.11/drivers/scsi/osst.c 
linux-2.6.11.modname/drivers/scsi/osst.c
--- linux-2.6.11/drivers/scsi/osst.c2005-03-02 10:38:08.0 +0300
+++ linux-2.6.11.modname/drivers/scsi/osst.c2005-03-04 13:20:45.0 
+0300
@@ -5888,5 +5888,7 @@ static void __exit exit_osst (void)
printk(KERN_INFO osst :I: Unloaded.\n);
 }
 
+MODULE_ALIAS(scsi-type-1);   /*  TYPE_TAPE   */
+
 module_init(init_osst);
 module_exit(exit_osst);
-
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [ANNOUNCE] hotplug-ng 001 release

2005-02-18 Thread Roman Kagan
On Fri, Feb 18, 2005 at 09:17:37AM -0800, Patrick Mansfield wrote:
 You could also append the sdev-vendor and sdev-model, and use alias wild
 cards.

String values haven't been used in the aliases so far, and I think for a
reason: with all the unpredictable weird characters and string lengths
they would make maintainance harder, not easier.

 That is, add aliases to osst.c like:
 
 MODULE_ALIAS(scsi-type-1-onStream-SC-*);
 MODULE_ALIAS(scsi-type-1-onStream-DI-*);

I used dashes for the only reason of these aliases being static.  If
they are supposed to grow it may make sense to stick to the convention
used everywhere else, i.e. bus:devspec.

 Also, sg loading would want (along with modprobe load all feature):
 
 MODULE_ALIAS(scsi-type-*);

Is it certain that it can live together with s[dtr]?  I thought these
guys now handled all the ioctls sg was supposed to themselves...

Roman.
-
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [ANNOUNCE] hotplug-ng 001 release

2005-02-18 Thread Roman Kagan
On Fri, Feb 18, 2005 at 10:33:50AM -0800, Patrick Mansfield wrote:
 The block SG_IO handles the ioctls, but not devices without a SCSI upper
 level driver (i.e. not tape, disk or cdrom).

Then it might make sense to explicitly list in sg.c the TYPE_* not
matched by s[dtr].

 In my experience, there are always applications that want to use the
 standard device driver (/dev/sda etc.) and others that want to use a
 generic driver.

So these drivers can compete for the same device?  Are there
deterministic rules on which one is supposed to win?  And is there a
userspace interface to unbind one driver and bind another?  Otherwise it
may mean that automatic module loading is inappropriate here at all...

Roman.
-
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html