exposing the sdev_target in sysfs
RFC 1/1 exposing the sdev_target in sysfs
The aim of this patch is to give us somewhere to hang the per target timer that emulex needs.
However, it will break the current sysfs layout. devices will now appear something like this:
lrwxrwxrwx 1 root root 0 Sep 3 18:31 /sys/class/scsi_device/0:0:5:0/device -> ../../../devices/parisc8/parisc8:0/pci0000:00/0000:00:13.0/host0/target0:0:5/0:0:5:0
(note the extra target0:0:5 in there).
which may break some of the user land tools (although you're all using the scsi class interface to access your devices, aren't you? in which case you won't notice any problems).
Comments welcome.
James
===== drivers/scsi/scsi_lib.c 1.131 vs edited =====
drivers/scsi/scsi_lib.c +5 -5
@@ -365,7 +365,7 @@unsigned long flags;spin_lock_irqsave (shost->host_lock, flags); - current_sdev->sdev_target->starget_sdev_user =NULL ; +scsi_target (current_sdev)->starget_sdev_user =NULL ;spin_unlock_irqrestore (shost->host_lock, flags);/*
@@ -377,7 +377,7 @@blk_run_queue (current_sdev->request_queue);spin_lock_irqsave (shost->host_lock, flags); -if (current_sdev->sdev_target->starget_sdev_user) +if (scsi_target (current_sdev)->starget_sdev_user) goto out;list_for_each_entry_safe (sdev, tmp, ¤t_sdev->same_target_siblings, same_target_siblings) {
@@ -1247,10 +1247,10 @@if (!scsi_host_queue_ready (q, shost, sdev)) goto not_ready;if (sdev->single_lun) { -if (sdev->sdev_target->starget_sdev_user && - sdev->sdev_target->starget_sdev_user != sdev) +if (scsi_target (sdev)->starget_sdev_user && +scsi_target (sdev)->starget_sdev_user != sdev) goto not_ready; - sdev->sdev_target->starget_sdev_user = sdev; +scsi_target (sdev)->starget_sdev_user = sdev; } shost->host_busy++;
===== drivers/scsi/scsi_priv.h 1.33 vs edited =====
drivers/scsi/scsi_priv.h +9 -1
@@ -65,9 +65,15 @@*/ struct scsi_target {struct scsi_device *starget_sdev_user; -unsigned int starget_refcnt; +struct device dev; }; +#define to_scsi_target (d) container_of(d, struct scsi_target, dev) +static inline struct scsi_target *scsi_target (struct scsi_device *sdev) +{ +return to_scsi_target (sdev->sdev_gendev.parent); +} +/* hosts.c */ extern int scsi_init_hosts (void );extern void scsi_exit_hosts (void );
@@ -156,6 +162,8 @@extern int scsi_sysfs_add_host (struct Scsi_Host *);extern int scsi_sysfs_register (void );extern void scsi_sysfs_unregister (void ); +extern int scsi_sysfs_device_initialize (struct scsi_device *); +extern int scsi_sysfs_target_initialize (struct scsi_device *);extern struct scsi_transport_template blank_transport_template;extern struct class sdev_class;
===== drivers/scsi/scsi_scan.c 1.128 vs edited =====
drivers/scsi/scsi_scan.c +7 -61
87 lines not on this page · raw message
===== drivers/scsi/scsi_sysfs.c 1.52 vs edited =====
drivers/scsi/scsi_sysfs.c +89 -3
125 lines not on this page · raw message
Quoted 12 lines · James Bottomley
The aim of this patch is to give us somewhere to hang the per target timer that emulex needs.
However, it will break the current sysfs layout. devices will now appear something like this:
lrwxrwxrwx 1 root root 0 Sep 3 18:31 /sys/class/scsi_device/0:0:5:0/device -> ../../../devices/parisc8/parisc8:0/pci0000:00/0000:00:13.0/host0/target0:0:5/0:0:5:0
(note the extra target0:0:5 in there).
Quoted 7 lines
which may break some of the user land tools (although you're all using the scsi class interface to access your devices, aren't you? in which case you won't notice any problems).
Comments welcome.
James
Hi James,
One tiny problem below.
Quoted 27 lines
drivers/scsi/scsi_sysfs.c +27
-0+int scsi_sysfs_target_initialize (struct scsi_device *sdev) +{ +struct scsi_target *starget =NULL ; +struct scsi_device *sdev_sibling; +unsigned long flags; + +spin_lock_irqsave (sdev->host->host_lock, flags); +/* +* Search for an existing target for this sdev. +*/ +list_for_each_entry (sdev_sibling, &sdev->same_target_siblings, + same_target_siblings) { +if (sdev_sibling->sdev_gendev.parent !=NULL ) { + starget =scsi_target (sdev_sibling); +break ; + } + } +if (!starget) { +struct device *dev; +int error; + + starget =kmalloc (sizeof (*starget),GFP_ATOMIC ); +if (!starget) { +printk (KERN_ERR "%s: allocation failure\n" , __FUNCTION__); +spin_unlock_irqrestore (sdev->host->host_lock, + flags); +return -ENOMEM ;
drivers/scsi/scsi_sysfs.c line 706
Quoted 10 lines
drivers/scsi/scsi_sysfs.c +10
-0+ } +memset (starget,0 ,sizeof (*starget)); + dev = &starget->dev; +device_initialize (dev); + dev->parent = &sdev->host->shost_gendev; + dev->bus = &scsi_bus_type; + dev->release = scsi_target_dev_release; +sprintf (dev->bus_id,"target%d:%d:%d" , + sdev->host->host_no, sdev->channel, sdev->id); +if ((error =device_add (dev))) {
device_add calls kobject_add which can sleep.
Quoted 12 lines
drivers/scsi/scsi_sysfs.c +8
-0+spin_unlock_irqrestore (sdev->host->host_lock, flags); +printk (KERN_ERR "Target device_add failed\n" ); +return error; + } + } +get_device (&starget->dev); + sdev->sdev_gendev.parent = &starget->dev; +spin_unlock_irqrestore (sdev->host->host_lock, flags);return 0 ; }
Quoted 1 line · Mike Christie
device_addcallskobject_addwhich can sleep.
Yes, I'll move it outside the lock.
I suppose I should add a comment somewhere about our critical dependence on sequential LUN scanning as well just in case someone tries to parallelise it.
James
Quoted 8 lines · James Bottomley
Quoted 1 line · Mike Christie
device_addcallskobject_addwhich can sleep.Yes, I'll move it outside the lock.
I suppose I should add a comment somewhere about our critical dependence on sequential LUN scanning as well just in case someone tries to parallelise it.
sequential on a given bus, rather than globally, right? There's no problem with scanning different busses simultanously, is there?
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 2 lines · Matthew Wilcox
sequential on a given bus, rather than globally, right? There's no problem with scanning different busses simultanously, is there?
Actually, no, sequential within a given target. Ensuring this sequentiality is entirely the province of the scsi subsystem, so as long as we do the right thing it doesn't matter how parallel we make the bus scans.
James
Quoted 10 lines · James Bottomley
The aim of this patch is to give us somewhere to hang the per target timer that emulex needs.
However, it will break the current sysfs layout. devices will now appear something like this:
lrwxrwxrwx 1 root root 0 Sep 3 18:31 /sys/class/scsi_device/0:0:5:0/device -> ../../../devices/parisc8/parisc8:0/pci0000:00/0000:00:13.0/host0/target0:0:5/0:0:5:0
Quoted 5 lines
(note the extra target0:0:5 in there).
which may break some of the user land tools (although you're all using the scsi class interface to access your devices, aren't you? in which case you won't notice any problems).
I do something like this to get to the controller. cd /sys/block/sda/device
cd pwd -P
cd ../..
But if target* will be a stable interface, its easy to change.
Signature · 7 lines
USB is for mice, FireWire is for men! sUse lINUX ag, nÜRNBERG - 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