add sysfs attributes to scan and delete scsi_devices
PATCH 1/1 add sysfs attributes to scan and delete scsi_devices
This patch against recent 2.5 bk adds a sysfs attribute to allow scanning (or rescanning) and deletion of scsi_devices.
It also allows scanning of entire hosts, channels, or targets.
drivers/scsi/scsi_priv.h +2 -0
@@ -107,6 +107,8 @@ extern void scsi_forget_host(struct Scsiextern void scsi_free_sdev (struct scsi_device *);extern void scsi_free_shost (struct Scsi_Host *);extern void scsi_rescan_device (struct device *); +extern int scsi_scan (const char *); +extern int scsi_remove (const char *);/* scsi_sysfs.c */ extern int scsi_device_register (struct scsi_device *);
drivers/scsi/scsi_scan.c +213 -37
346 lines not on this page · raw message
drivers/scsi/scsi_sysfs.c +27 -0
@@ -73,6 +73,27 @@ struct bus_type scsi_bus_type = { .match = scsi_bus_match, }; +static ssize_t store_scan (struct bus_type *bus,const char *buf,size_t count) +{ +int res; + + res =scsi_scan (buf); +if (res ==0 ) + res = count; +return res; +}; +static BUS_ATTR(scan, S_IWUSR, NULL, store_scan); + +static ssize_t store_delete (struct bus_type *bus,const char *buf,size_t count) +{ +int res; + + res =scsi_remove (buf); +if (res ==0 ) + res = count; +return res; +}; +static BUS_ATTR(delete, S_IWUSR, NULL, store_delete);int scsi_sysfs_register (void ) {
@@ -81,6 +102,12 @@ int scsi_sysfs_register(void) error =bus_register (&scsi_bus_type);if (error)return error; + error =bus_create_file (&scsi_bus_type, &bus_attr_scan); +if (error) + goto bus_unregister; + error =bus_create_file (&scsi_bus_type, &bus_attr_delete); +if (error) + goto bus_unregister; error =class_register (&shost_class);if (error) goto bus_unregister;
examples using sysfs attributes to scan and delete scsi_devices
Some sample usage of the delete and scan attributes.
The system has one fastt200 (disk array) with 32 LUNs (4:0:0:*), 10 disk drives (4:0:1-10:0).
[root@elm3b79 root]# ls -l /sysfs/bus/scsi
total 0
--w------- 1 root root 0 Jul 8 13:28 delete drwxr-xr-x 2 root root 0 Jul 8 04:04 devices drwxr-xr-x 5 root root 0 Jul 8 04:04 drivers --w------- 1 root root 0 Jul 8 13:08 scan
[root@elm3b79 root]# ls /sysfs/bus/scsi/devices
0:0:0:0 4:0:0:0 4:0:0:14 4:0:0:2 4:0:0:25 4:0:0:30 4:0:0:8 4:0:4:0 0:0:1:0 4:0:0:1 4:0:0:15 4:0:0:20 4:0:0:26 4:0:0:31 4:0:0:9 4:0:5:0 0:0:2:0 4:0:0:10 4:0:0:16 4:0:0:21 4:0:0:27 4:0:0:4 4:0:1:0 4:0:6:0 0:0:3:0 4:0:0:11 4:0:0:17 4:0:0:22 4:0:0:28 4:0:0:5 4:0:10:0 4:0:7:0 0:0:4:0 4:0:0:12 4:0:0:18 4:0:0:23 4:0:0:29 4:0:0:6 4:0:2:0 4:0:8:0 0:0:5:0 4:0:0:13 4:0:0:19 4:0:0:24 4:0:0:3 4:0:0:7 4:0:3:0 4:0:9:0
# delete a few scsi_devices from the disk array
[root@elm3b79 root]# echo "4 0 0 25" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/delete 0+1 records in
0+1 records out
[root@elm3b79 root]# echo "4 0 0 1" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/delete 0+1 records in
0+1 records out
[root@elm3b79 root]# echo "4 0 0 3" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/delete 0+1 records in
0+1 records out
[root@elm3b79 root]# ls /sysfs/bus/scsi/devices
0:0:0:0 4:0:0:0 4:0:0:15 4:0:0:20 4:0:0:27 4:0:0:5 4:0:10:0 4:0:7:0 0:0:1:0 4:0:0:10 4:0:0:16 4:0:0:21 4:0:0:28 4:0:0:6 4:0:2:0 4:0:8:0 0:0:2:0 4:0:0:11 4:0:0:17 4:0:0:22 4:0:0:29 4:0:0:7 4:0:3:0 4:0:9:0 0:0:3:0 4:0:0:12 4:0:0:18 4:0:0:23 4:0:0:30 4:0:0:8 4:0:4:0 0:0:4:0 4:0:0:13 4:0:0:19 4:0:0:24 4:0:0:31 4:0:0:9 4:0:5:0 0:0:5:0 4:0:0:14 4:0:0:2 4:0:0:26 4:0:0:4 4:0:1:0 4:0:6:0
# Rescan a target, in this particular case a REPORT LUN scan occurs
[root@elm3b79 root]# echo "4 0 0 -" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/scan 0+1 records in
0+1 records out
[root@elm3b79 root]# ls /sysfs/bus/scsi
delete devices drivers scan
[root@elm3b79 root]# ls /sysfs/bus/scsi/devices
0:0:0:0 4:0:0:0 4:0:0:14 4:0:0:2 4:0:0:25 4:0:0:30 4:0:0:8 4:0:4:0 0:0:1:0 4:0:0:1 4:0:0:15 4:0:0:20 4:0:0:26 4:0:0:31 4:0:0:9 4:0:5:0 0:0:2:0 4:0:0:10 4:0:0:16 4:0:0:21 4:0:0:27 4:0:0:4 4:0:1:0 4:0:6:0 0:0:3:0 4:0:0:11 4:0:0:17 4:0:0:22 4:0:0:28 4:0:0:5 4:0:10:0 4:0:7:0 0:0:4:0 4:0:0:12 4:0:0:18 4:0:0:23 4:0:0:29 4:0:0:6 4:0:2:0 4:0:8:0 0:0:5:0 4:0:0:13 4:0:0:19 4:0:0:24 4:0:0:3 4:0:0:7 4:0:3:0 4:0:9:0
# Rescan an entire adapter
[root@elm3b79 root]# echo "4 - - -" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/scan 0+1 records in
0+1 records out
# some failure cases
[root@elm3b79 root]# echo "4 0 0 88" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/delete
dd: writing `/sysfs/bus/scsi/delete': No such device
0+1 records in
0+0 records out
[root@elm3b79 root]# echo "4 0 88" > /root/xx; dd if=/root/xx of=/sysfs/bus/scsi/delete
dd: writing `/sysfs/bus/scsi/delete': Invalid argument
0+1 records in
0+0 records out
-- Patrick Mansfield
Quoted 4 lines · Patrick Mansfield
This patch against recent 2.5 bk adds a sysfs attribute to allow scanning (or rescanning) and deletion of
scsi_devices.It also allows scanning of entire hosts, channels, or targets.
Looks good so far but please keep the string parsing in scsi_sysfs.c instead of scsi_scan.c. Also doesn't want this some code sharing with the old procfs code?
Quoted 4 lines · Patrick Mansfield
This patch against recent 2.5 bk adds a sysfs attribute to allow scanning (or rescanning) and deletion of
scsi_devices.It also allows scanning of entire hosts, channels, or targets.
I'm not convinced we need a bus file for this. What's the reason we can't have a per host file instead?
I'm thinking of the hotplug case where you know the sysfs path to the card just inserted. Translating that to a hostid will be rather hard.
James
Quoted 5 lines · James Bottomley
I'm not convinced we need a bus file for this. What's the reason we can't have a per host file instead?
I'm thinking of the hotplug case where you know the sysfs path to the card just inserted. Translating that to a hostid will be rather hard.
After thinking about this again I tend to agree with you that a per-host file sounds like the better idea.
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · James Bottomley
I'm not convinced we need a bus file for this. What's the reason we can't have a per host file instead?
I'm thinking of the hotplug case where you know the sysfs path to the card just inserted. Translating that to a hostid will be rather hard.
After thinking about this again I tend to agree with you that a per-host file sounds like the better idea.
James/Christoph -
There is not much of a difference either way.
Scanning makes more sense as a host attribute (or as a target attribute, but we don't have a target device today). Deletion of a scsi_device makes more sense as a /sysfs/bus/scsi (or even scsi_device) attribute that takes a bus_id.
But we should be symmetrical for a user space interface. (And it is easier to catch sscanf errors using spaces as a separator.)
I'll go ahead and redo it as per-host, and move string parsing into scsi_sysfs.c.
Thanks for the feedback.
-- Patrick Mansfield
Quoted 3 lines · Christoph Hellwig
Looks good so far but please keep the string parsing in
scsi_sysfs.cinstead ofscsi_scan.c. Also doesn't want this some code sharing with the old procfs code?
I can change procfs to use scsi_scan_host_selected(), it will be externed for use in scsi_sysfs.c.
But is it worth propagating through the call chain whether a new device was found (i.e. scsi_add_device returns -ENODEV)?
-- Patrick Mansfield
PATCH 1/1 take 2 add sysfs attributes to scan and delete scsi_devices
In reply to Patrick MansfieldThis patch against scsi-misc-2.5 adds a sysfs attribute to allow scanning (or rescanning) and deletion of scsi_devices.
It also allows scanning of entire hosts, channels, or targets.
Updated per comments received, mainly create the scan and delete attributes per host.
The scsi_proc.c remove code was not changed, it and this patch still need changes based on Mike A's patches.
drivers/scsi/scsi_priv.h +8 -0
@@ -42,6 +42,12 @@ (((scmd)->sense_buffer[0 ] &0x70 ) ==0x70 )/* +* Special value for scanning to specify scanning or rescanning of all +* possible channels, (target) ids, or luns on a given shost. + */ +#define SCAN_WILD_CARD ~0 + +/* * scsi_target: representation of a scsi target, for now, this is only * used for single_lun devices. If no one has active IO to the target, * starget_sdev_user is NULL, else it points to the active sdev.
@@ -102,6 +108,8 @@ extern void scsi_exit_procfs(void);#endif /* CONFIG_PROC_FS */ /* scsi_scan.c */ +int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int , +unsigned int ,int );extern void scsi_forget_host (struct Scsi_Host *);extern void scsi_free_sdev (struct scsi_device *);extern void scsi_free_shost (struct Scsi_Host *);
drivers/scsi/scsi_proc.c +2 -12
@@ -174,21 +174,11 @@ static int proc_print_scsidevice(structstatic int scsi_add_single_device (uint host,uint channel,uint id,uint lun) {struct Scsi_Host *shost; -struct scsi_device *sdev; -int error = -ENODEV ; - +int error; shost =scsi_host_lookup (host);if (!shost)return -ENODEV ; - -if (!scsi_find_device (shost, channel, id, lun)) { - sdev =scsi_add_device (shost, channel, id, lun); -if (IS_ERR (sdev)) - error =PTR_ERR (sdev); -else - error =0 ; - } - + error =scsi_scan_host_selected (shost, channel, id, lun,1 );scsi_host_put (shost);return error; }
drivers/scsi/scsi_scan.c +89 -38
216 lines not on this page · raw message
drivers/scsi/scsi_sysfs.c +108 -1
133 lines not on this page · raw message
and some example usage of the attributes
Some example uses of the delete and scan attribute.
[root@elm3b79 root]# ls -l /sysfs/class/scsi_host/host2 total 0
-r--r--r-- 1 root root 4096 Jul 9 12:30 cmd_per_lun --w------- 1 root root 0 Jul 9 12:34 delete lrwxrwxrwx 1 root root 46 Jul 9 12:30 device -> ../../../devices/pci0000:01/0000:01:0c.0/host2 -r--r--r-- 1 root root 4096 Jul 9 12:30 host_busy --w------- 1 root root 0 Jul 9 12:36 scan -r--r--r-- 1 root root 4096 Jul 9 12:30 sg_tablesize -r--r--r-- 1 root root 4096 Jul 9 12:30 unchecked_isa_dma -r--r--r-- 1 root root 4096 Jul 9 12:30 unique_id
[root@elm3b79 root]# ls /sysfs/class/scsi_host/host2/device
2:0:0:0 2:0:0:14 2:0:0:2 2:0:0:25 2:0:0:30 2:0:0:8 2:0:4:0 name 2:0:0:1 2:0:0:15 2:0:0:20 2:0:0:26 2:0:0:31 2:0:0:9 2:0:5:0 power 2:0:0:10 2:0:0:16 2:0:0:21 2:0:0:27 2:0:0:4 2:0:1:0 2:0:6:0 2:0:0:11 2:0:0:17 2:0:0:22 2:0:0:28 2:0:0:5 2:0:10:0 2:0:7:0 2:0:0:12 2:0:0:18 2:0:0:23 2:0:0:29 2:0:0:6 2:0:2:0 2:0:8:0 2:0:0:13 2:0:0:19 2:0:0:24 2:0:0:3 2:0:0:7 2:0:3:0 2:0:9:0
# Delete some devices
[root@elm3b79 root]# echo "0 9 0" > /root/xx; dd if=/root/xx of=/sysfs/class/scsi_host/host2/delete 0+1 records in
0+1 records out
[root@elm3b79 root]# echo "0 0 0" > /root/xx; dd if=/root/xx of=/sysfs/class/scsi_host/host2/delete 0+1 records in
0+1 records out
[root@elm3b79 root]# echo "0 0 22" > /root/xx; dd if=/root/xx of=/sysfs/class/scsi_host/host2/delete 0+1 records in
0+1 records out
# Scan a target - for this target REPORT LUN is used
[root@elm3b79 root]# echo "0 0 -" > /root/xx; dd if=/root/xx of=/sysfs/class/scsi_host/host2/scan 0+1 records in
0+1 records out
# Scan the entire host
[root@elm3b79 root]# echo "- - -" > /root/xx; dd if=/root/xx of=/sysfs/class/scsi_host/host2/scan 0+1 records in
0+1 records out
-- Patrick Mansfield
Quoted 2 lines · Patrick Mansfield
Scanning makes more sense as a host attribute (or as a target attribute, but we don't have a target device today).
So we should have a scan host attribute for that.
Quoted 3 lines
Deletion of a
scsi_devicemakes
more sense as a /sysfs/bus/scsi (or evenscsi_device) attribute that takes abus_id.
I don't think it makes sense as a /sysfs/bus/scsi attribute. Having it as a scsi_device attribute makes lots of sense, I just wonder whether the non-symmetric interface would confuse users. Probably not too much as scannaing a bus an deleting a device isn't really a symmetric interface anyway.`