modalias for scsi devices?
Subsystems (2)
Currently, scsi device modules (sd_mod, sr_mod, st, ch) are the only commonly used modules which requires special handling. For the rest of (commonly used) devices, there's modalias file in sysfs and $MODALIAS env. variable at hotplug time. (Well, there are other cases still, but those are rare and mostly legacy stuff - such as ISA-PnP devices etc - on such systems static configuration in a means of /etc/modules or similar will do the trick just fine). Since not-so-recently already IDE modules - another very commonly used kind - become "modalias-aware", so to say.
I implemented a patch enabling scsi modules autoloading without special handling for 2.6.17 -- modalias contains scsi:type-0x04 for WORMs for example, and sd_mod has scsi:type-0x04* alias string. Very simple patch, I posted it to lkml.
But at that time, someone replied telling me he's implementing this functionality in a more general way.
The problem with my (simplistic?) approach was with st vs osst modules - in "new world" as I did it both will be loading for all tapes, but only one will take care of the given device. It can be worked around later as well, by including, say, vendor information into modalias string, like scsi:type-0:vendor-ADAPTEC or something like that, and after this, os/osst dilemma will be solved. But in any way, I don't see a problem with trying both modules this way.
The original patch as I did for 2.6.17 still applies cleanly against 2.6.18 and current 2.6.19-tobe tree (with some offsets). It's attached to this email for consideration.
Thanks.
/mjt
From: Michael Tokarev <[email protected]>
To: Linux-kernel <[email protected]>
Cc: Linus-SCSI <[email protected]>
Subject: [RFC] MODALIAS support for SCSI devices (try 1)
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="scsi-modalias-1.patch"
The following patch adds support for sysfs/uevent modalias attribute for scsi devices (like disks, tapes, cdroms etc), based on whatever current sd.c, sr.c, st.c and osst.c drivers supports.
The modalias format is like this:
scsi:type-0x04
(for TYPE_WORM, handled by sr.c now).
Several comments.
o This hexadecimal type value is because all TYPE_XXX constants in include/scsi/scsi.h are given in hex, but __stringify() will not convert them to decimal (so it will NOT be scsi:type-4). Since it does not really matter in which format it is, while both modalias in module and modalias attribute match each other, I descided to go for that 0x%02x format (and added a comment in include/scsi/scsi.h to keep them that way), instead of changing them all to decimal.
o There was no .uevent routine for SCSI bus. It might be a good idea to add some more ueven environment variables in there.
o osst.c driver handles tapes too, like st.c, but only SOME tapes. With this setup, hotplug scripts (or whatever is used by the user) will try to load both st and osst modules for all SCSI tapes found, because both modules have scsi:type-0x01 alias). It is not harmful, but one extra module is no good either. It is possible to solve this, by exporting more info in modalias attribute, including vendor and device identification strings, so that modalias becomes something like
scsi:type-0x12:vendor-Adaptec LTD:device-OnStream Tape Drive
and having that, match for all 3 attributes, not only device type. But oh well, vendor and device strings may be large, and they do contain spaces and whatnot.
So I left them for now, awaiting for comments first.
The patch is against 2.6.17, but should apply to more recent versions as well.
And oh, almost forget:
Thanks.
drivers/scsi/osst.c +1 -0
@@ -87,6 +87,7 @@ MODULE_AUTHOR("Willem Riede");MODULE_DESCRIPTION ("OnStream {DI-|FW-|SC-|USB}{30|50} Tape Driver" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_CHARDEV_MAJOR (OSST_MAJOR ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_TAPE );module_param (max_dev, int,0444 );MODULE_PARM_DESC (max_dev,"Maximum number of OnStream Tape Drives to attach (4)" );
drivers/scsi/scsi_sysfs.c +23 -0
@@ -275,6 +275,19 @@ static int scsi_bus_match(struct devicereturn (sdp->inq_periph_qual ==SCSI_INQ_PQ_CON )?1 :0 ; } +static int scsi_bus_uevent (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 ; + +add_uevent_var (envp, num_envp, &i, buffer, buffer_size, &length, +"MODALIAS=" SCSI_DEVICE_MODALIAS_FMT , sdev->type); + envp[i] =NULL ; +return 0 ; +} +static int scsi_bus_suspend (struct device * dev,pm_message_t state) {struct scsi_device *sdev =to_scsi_device (dev);
@@ -307,6 +320,7 @@ static int scsi_bus_resume(struct devicestruct bus_type scsi_bus_type = { .name ="scsi" , .match = scsi_bus_match, + .uevent = scsi_bus_uevent, .suspend = scsi_bus_suspend, .resume = scsi_bus_resume, };
@@ -534,6 +548,14 @@ show_sdev_iostat(iorequest_cnt);show_sdev_iostat (iodone_cnt);show_sdev_iostat (ioerr_cnt); +static ssize_t +sdev_show_modalias (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct scsi_device *sdev; + sdev =to_scsi_device (dev); +return snprintf (buf,20 ,SCSI_DEVICE_MODALIAS_FMT "\n" , sdev->type); +} +static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);/* Default template for device attributes. May NOT be modified */ static struct device_attribute *scsi_sysfs_sdev_attrs[] = {
@@ -553,6 +575,7 @@ static struct device_attribute *scsi_sys &dev_attr_iorequest_cnt, &dev_attr_iodone_cnt, &dev_attr_ioerr_cnt, + &dev_attr_modalias, NULL };
drivers/scsi/sd.c +3 -0
@@ -90,6 +90,9 @@ MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK12_MODULE_ALIAS_BLOCKDEV_MAJOR (SCSI_DISK13_MAJOR );MODULE_ALIAS_BLOCKDEV_MAJOR (SCSI_DISK14_MAJOR );MODULE_ALIAS_BLOCKDEV_MAJOR (SCSI_DISK15_MAJOR ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_DISK ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_MOD ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_RBC );/* * This is limited by the naming scheme enforced in sd_probe,
drivers/scsi/sr.c +2 -0
@@ -63,6 +63,8 @@MODULE_DESCRIPTION ("SCSI cdrom (sr) driver" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_BLOCKDEV_MAJOR (SCSI_CDROM_MAJOR ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_ROM ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_WORM );#define SR_DISKS 256
drivers/scsi/st.c +1 -0
@@ -89,6 +89,7 @@ MODULE_AUTHOR("Kai Makisara");MODULE_DESCRIPTION ("SCSI tape (st) driver" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_CHARDEV_MAJOR (SCSI_TAPE_MAJOR ); +MODULE_ALIAS_SCSI_DEVICE (TYPE_TAPE );/* Set 'perm' (4th argument) to 0 to disable module_param's definition * of sysfs parameters (which module_param doesn't yet support).
include/scsi/scsi_device.h +5 -0
@@ -352,4 +352,9 @@ static inline int scsi_device_qas(structreturn 0 ; return sdev->inquiry[56] & 0x02; } + +#define MODULE_ALIAS_SCSI_DEVICE (type) \ + MODULE_ALIAS("scsi:t-" __stringify(type) "*") +#define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x" +#endif /* _SCSI_SCSI_DEVICE_H */
include/scsi/scsi.h +1 -0
@@ -207,6 +207,7 @@ static inline int scsi_status_is_good(in/* * DEVICE TYPES +* Please keep them in 0x%02x format for $MODALIAS to work */ #define TYPE_DISK 0x00
Michael Tokarev wrote on 2006-10-27:
...
Quoted 2 lines
But at that time, someone replied telling me he's implementing this functionality in a more general way.
Could you point to an archive of this discussion?
...
Quoted 3 lines
The modalias format is like this:
scsi:type-0x04
...
Quoted 11 lines
o
osst.cdriver handles tapes too, likest.c, but only SOME tapes. With this setup, hotplug scripts (or whatever is used by the user) will try to load both st and osst modules for all SCSI tapes found, because both modules have scsi:type-0x01 alias). It is not harmful, but one extra module is no good either. It is possible to solve this, by exporting more info in modalias attribute, including vendor and device identification strings, so that modalias becomes something likescsi:type-0x12:vendor-Adaptec LTD:device-OnStream Tape Driveand having that, match for all 3 attributes, not only device type. But oh well, vendor and device strings may be large,
8 and 16 characters may be somewhat large for modalias strings but I think this is still OK.
Quoted 1 line
and they do contain spaces and whatnot.
...
What about the string format that scsi_scan.c::scsi_add_lun() prints in Linux 2.6.19?
sdev_printk(KERN_NOTICE, sdev, "%s %.8s %.16s %.4s PQ: %d " "ANSI: %d%s\n", scsi_device_type(sdev->type), sdev->vendor, sdev->model, sdev->rev, sdev->inq_periph_qual, inq_result[2] & 0x07, (inq_result[3] & 0x0f) == 1 ? " CCS" : "");
Of course you could use hexadecimal for the type again and use other delimiters. But I think the only sane way to parse vendor and model is to rely on their fixed length, not on some nifty delimiters. I don't know though if existing userspace helpers are prepared for fixed-length string elements.
I can't comment on the general idea to switch to modaliases.
Signature · 3 lines
Stefan Richter -=====-=-==- =-=- ===== http://arcgraph.de/sr/