diff options
author | Michael Tokarev <mjt@tls.msk.ru> | 2006-10-27 08:02:37 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2007-04-17 18:15:04 -0400 |
commit | d7b8bcb0a0819315a51cae620ff7ae0c1704c069 (patch) | |
tree | 13945e987d1654d58905bbb467b3671388d74746 /drivers/scsi/scsi_sysfs.c | |
parent | 44ec95425c1d9dce6e4638c29e4362cfb44814e7 (diff) |
[SCSI] modalias for scsi devices
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.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/scsi_sysfs.c')
-rw-r--r-- | drivers/scsi/scsi_sysfs.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 96db51c40ef3..5326f5cbeae9 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c | |||
@@ -276,6 +276,19 @@ static int scsi_bus_match(struct device *dev, struct device_driver *gendrv) | |||
276 | return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0; | 276 | return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0; |
277 | } | 277 | } |
278 | 278 | ||
279 | static int scsi_bus_uevent(struct device *dev, char **envp, int num_envp, | ||
280 | char *buffer, int buffer_size) | ||
281 | { | ||
282 | struct scsi_device *sdev = to_scsi_device(dev); | ||
283 | int i = 0; | ||
284 | int length = 0; | ||
285 | |||
286 | add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length, | ||
287 | "MODALIAS=" SCSI_DEVICE_MODALIAS_FMT, sdev->type); | ||
288 | envp[i] = NULL; | ||
289 | return 0; | ||
290 | } | ||
291 | |||
279 | static int scsi_bus_suspend(struct device * dev, pm_message_t state) | 292 | static int scsi_bus_suspend(struct device * dev, pm_message_t state) |
280 | { | 293 | { |
281 | struct device_driver *drv = dev->driver; | 294 | struct device_driver *drv = dev->driver; |
@@ -331,6 +344,7 @@ static int scsi_bus_resume(struct device * dev) | |||
331 | struct bus_type scsi_bus_type = { | 344 | struct bus_type scsi_bus_type = { |
332 | .name = "scsi", | 345 | .name = "scsi", |
333 | .match = scsi_bus_match, | 346 | .match = scsi_bus_match, |
347 | .uevent = scsi_bus_uevent, | ||
334 | .suspend = scsi_bus_suspend, | 348 | .suspend = scsi_bus_suspend, |
335 | .resume = scsi_bus_resume, | 349 | .resume = scsi_bus_resume, |
336 | }; | 350 | }; |
@@ -558,6 +572,14 @@ show_sdev_iostat(iorequest_cnt); | |||
558 | show_sdev_iostat(iodone_cnt); | 572 | show_sdev_iostat(iodone_cnt); |
559 | show_sdev_iostat(ioerr_cnt); | 573 | show_sdev_iostat(ioerr_cnt); |
560 | 574 | ||
575 | static ssize_t | ||
576 | sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf) | ||
577 | { | ||
578 | struct scsi_device *sdev; | ||
579 | sdev = to_scsi_device(dev); | ||
580 | return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type); | ||
581 | } | ||
582 | static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL); | ||
561 | 583 | ||
562 | /* Default template for device attributes. May NOT be modified */ | 584 | /* Default template for device attributes. May NOT be modified */ |
563 | static struct device_attribute *scsi_sysfs_sdev_attrs[] = { | 585 | static struct device_attribute *scsi_sysfs_sdev_attrs[] = { |
@@ -577,6 +599,7 @@ static struct device_attribute *scsi_sysfs_sdev_attrs[] = { | |||
577 | &dev_attr_iorequest_cnt, | 599 | &dev_attr_iorequest_cnt, |
578 | &dev_attr_iodone_cnt, | 600 | &dev_attr_iodone_cnt, |
579 | &dev_attr_ioerr_cnt, | 601 | &dev_attr_ioerr_cnt, |
602 | &dev_attr_modalias, | ||
580 | NULL | 603 | NULL |
581 | }; | 604 | }; |
582 | 605 | ||