scsi sysfs cleanups
Subsystems (3)
PATCH 1/1 scsi sysfs cleanups
This is a re-roll of a previous patch for SCSI sysfs cleanups. The update includes changes from comments on previous patch posted and the removal of the extra h file (some name change updates where postponed to avoid clashing with others).
This patch is against bk://linux-scsi.bkbits.net/scsi-for-linus-2.5
Changes:
[base]
- Concentrate scsi sysfs support functions into one file
- Added wrapper functions the reduce init / cleanup issues and mixed object issues (use of container_of with mixed types).
- Moved init_scsi initcall level to subsys_initcall.
- Added scsi-host class support. Future ../class/scsi_host/devices should equal scsi_host_list.
- Removed extra scsi(n) level in tree. Future ../class/scsi_host/devices/(n) children should equal host_queue.
[upper level]
- Minor changes to Scsi_Device_Template init.
[scsi_debug]
- scsi_debug will not compile with this patch. This patch depends on a previous patch posted to linux-scsi for scsi_debug 1.64 or use 1.65
Testing:
2x with ips, aic, qlogicisp.
also tested on bk current.
Note: To get successful insmod / rmmod combinations and clean shutdowns please use the previously posted sysfs core fixups.
-andmike
--
Michael Anderson
[email protected]
Makefile | 3 hosts.c | 9 - hosts.h | 31 +++++- scsi.c | 41 +------- scsi.h | 10 +- scsi_scan.c | 81 ---------------- scsi_syms.c | 8 + scsi_sysfs.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sd.c | 5 - sg.c | 8 + sr.c | 6 - st.c | 10 +- 12 files changed, 359 insertions(+), 142 deletions(-)
------
drivers/scsi/Makefile +2 -1
@@ -123,7 +123,8 @@ obj-$(CONFIG_CHR_DEV_SG) += sg.o scsi_mod-objs := scsi.o hosts.o scsi_ioctl.o constants.o scsicam.o \ - scsi_error.o scsi_lib.o scsi_scan.o scsi_syms.o + scsi_error.o scsi_lib.o scsi_scan.o scsi_syms.o \ + scsi_sysfs.o ifdef CONFIG_PROC_FS scsi_mod-objs += scsi_proc.o
drivers/scsi/hosts.c +1 -8
@@ -280,7 +280,7 @@return 1 ; }devfs_unregister (sdev->de); -device_unregister (&sdev->sdev_driverfs_dev); +scsi_device_unregister (sdev); }/* Next we free up the Scsi_Cmnd structures for this host */
@@ -307,7 +307,6 @@printk (KERN_INFO "scsi%d : %s\n" , shost->host_no, sht->info ? sht->info (shost) : sht->name); -device_register (&shost->host_driverfs_dev);scan_scsis (shost,0 ,0 ,0 ,0 );for (sdev = shost->host_queue; sdev; sdev = sdev->next) {
@@ -348,7 +347,6 @@/* Cleanup proc and driverfs */ scsi_proc_host_rm (shost); -device_unregister (&shost->host_driverfs_dev);kfree (shost); }
@@ -462,11 +460,6 @@spin_unlock (&scsi_host_list_lock);scsi_proc_host_add (shost); - -strncpy (shost->host_driverfs_dev.name, shost_tp->proc_name, -DEVICE_NAME_SIZE -1 ); -sprintf (shost->host_driverfs_dev.bus_id,"scsi%d" , - shost->host_no); shost->eh_notify = &sem;kernel_thread ((int (*)(void *)) scsi_error_handler, (void *) shost,0 );
drivers/scsi/hosts.h +28 -3
@@ -476,7 +476,7 @@/* * Support for driverfs filesystem */ -struct device host_driverfs_dev; +struct device *host_driverfs_dev;/* * We should ensure that this is aligned, both for better performance
@@ -521,7 +521,7 @@ struct pci_dev *pdev) { shost->pci_dev = pdev; - shost->host_driverfs_dev.parent=&pdev->dev; + shost->host_driverfs_dev = &pdev->dev; }
@@ -534,7 +534,6 @@ {struct list_head list;const char * name; -const char * tag;struct module * module;/* Used for loadable modules */ unsigned char scsi_type;int (*attach)(Scsi_Device *);/* Attach devices to arrays */
@@ -602,6 +601,32 @@break ; return sdev; } + + +/* +* sysfs host class +*/ +extern int scsi_host_class_register (struct device *,struct Scsi_Host *); +extern void scsi_host_class_unregister (struct device *); + +extern struct device_class shost_devclass; + +static inline void scsi_host_dev_set (struct Scsi_Host *shost, +struct device *dev) +{ + shost->host_driverfs_dev = dev; +} + +static inline void scsi_class_data_set (struct device *dev, +struct Scsi_Host *host) +{ + dev->class_data = (void *)host; +}; + +static inline struct Scsi_Host *scsi_class_data_get (struct device *dev) +{ +return (struct Scsi_Host *) dev->class_data; +};#endif /*
drivers/scsi/scsi.c +6 -35
83 lines not on this page · raw message
drivers/scsi/scsi.h +8 -2
@@ -411,8 +411,6 @@extern unsigned int scsi_logging_level;/* What do we log? */ -extern struct bus_type scsi_driverfs_bus_type; -/* * These are the error handling functions defined in scsi_error.c
@@ -988,5 +986,13 @@#define SCSI_SENSE_VALID (scmd) ((scmd->sense_buffer[0] & 0x70) == 0x70)int scsi_set_medium_removal (Scsi_Device *dev,char state); + +extern int scsi_device_driver_register (struct Scsi_Device_Template *); +extern void scsi_device_driver_unregister (struct Scsi_Device_Template *); +extern int scsi_device_register (struct scsi_device *); +extern void scsi_device_unregister (struct scsi_device *); + +extern int scsi_sysfs_register (void ); +extern void scsi_sysfs_unregister (void );#endif
drivers/scsi/scsi_scan.c +1 -80
93 lines not on this page · raw message
drivers/scsi/scsi_syms.c +6 -2
@@ -104,6 +104,10 @@EXPORT_SYMBOL (scsi_delete_timer);/* -* driverfs support for determining driver types +* sysfs support */ -EXPORT_SYMBOL (scsi_driverfs_bus_type); +EXPORT_SYMBOL (scsi_device_driver_register); +EXPORT_SYMBOL (scsi_device_driver_unregister); +EXPORT_SYMBOL (scsi_host_class_register); +EXPORT_SYMBOL (scsi_host_class_unregister); +EXPORT_SYMBOL (shost_devclass);
drivers/scsi/scsi_sysfs.c new file +289 -0
289 lines not on this page · raw message
drivers/scsi/sd.c +3 -2
@@ -105,11 +105,13 @@ .module = THIS_MODULE, .list = LIST_HEAD_INIT(sd_template.list), .name = "disk", - .tag = "sd", .scsi_type = TYPE_DISK, .attach = sd_attach, .detach = sd_detach, .init_command = sd_init_command, + .scsi_driverfs_driver = { + .name = "sd", + }, };static struct scsi_disk *sd_find_by_sdev (Scsi_Device *sd)
@@ -1343,7 +1345,6 @@scsi_unregister_device (&sd_template);for (i =0 ; i <SD_MAJORS ; i++)unregister_blkdev (SD_MAJOR (i),"sd" ); -driver_unregister (&sd_template.scsi_driverfs_driver); }/*
drivers/scsi/sg.c +5 -3
@@ -122,10 +122,12 @@ .module = THIS_MODULE, .list = LIST_HEAD_INIT(sg_template.list), .name = "generic", - .tag = "sg", .scsi_type = 0xff, .attach = sg_attach, - .detach = sg_detach + .detach = sg_detach, + .scsi_driverfs_driver = { + .name = "sg", + }, }; typedef struct sg_scatter_hold { /* holding area for scsi scatter gather info */
@@ -1464,7 +1466,7 @@sprintf (sdp->sg_driverfs_dev.name,"%sgeneric" , scsidp->sdev_driverfs_dev.name); sdp->sg_driverfs_dev.parent = &scsidp->sdev_driverfs_dev; - sdp->sg_driverfs_dev.bus = &scsi_driverfs_bus_type; + sdp->sg_driverfs_dev.bus = scsidp->sdev_driverfs_dev.bus; sg_nr_dev++; sg_dev_arr[k] = sdp;
drivers/scsi/sr.c +4 -2
@@ -73,11 +73,13 @@ .module = THIS_MODULE, .list = LIST_HEAD_INIT(sr_template.list), .name = "cdrom", - .tag = "sr", .scsi_type = TYPE_ROM, .attach = sr_attach, .detach = sr_detach, - .init_command = sr_init_command + .init_command = sr_init_command, + .scsi_driverfs_driver = { + .name = "sr", + }, };static int sr_nr_dev;/* XXX(hch) bad hack, we want a bitmap instead */
drivers/scsi/st.c +6 -4
@@ -176,10 +176,12 @@ .module = THIS_MODULE, .list = LIST_HEAD_INIT(st_template.list), .name = "tape", - .tag = "st", .scsi_type = TYPE_TAPE, .attach = st_attach, - .detach = st_detach + .detach = st_detach, + .scsi_driverfs_driver = { + .name = "st", + }, };static int st_compression (Scsi_Tape *,int );
@@ -3838,7 +3840,7 @@sprintf (tpnt->driverfs_dev_r[mode].name,"%s%s" , SDp->sdev_driverfs_dev.name, name); tpnt->driverfs_dev_r[mode].parent = &SDp->sdev_driverfs_dev; - tpnt->driverfs_dev_r[mode].bus = &scsi_driverfs_bus_type; + tpnt->driverfs_dev_r[mode].bus = SDp->sdev_driverfs_dev.bus; tpnt->driverfs_dev_r[mode].driver_data = (void *)(long )__mkdev (MAJOR_NR , dev_num + (mode <<5 ));device_register (&tpnt->driverfs_dev_r[mode]);
@@ -3857,7 +3859,7 @@sprintf (tpnt->driverfs_dev_n[mode].name,"%s%s" , SDp->sdev_driverfs_dev.name, name); tpnt->driverfs_dev_n[mode].parent= &SDp->sdev_driverfs_dev; - tpnt->driverfs_dev_n[mode].bus = &scsi_driverfs_bus_type; + tpnt->driverfs_dev_n[mode].bus = SDp->sdev_driverfs_dev.bus; tpnt->driverfs_dev_n[mode].driver_data = (void *)(long )__mkdev (MAJOR_NR , dev_num + (mode <<5 ) +128 );device_register (&tpnt->driverfs_dev_n[mode]);
drivers/scsi/hosts.h line 629
Quoted 10 lines · Mike Anderson
drivers/scsi/hosts.h +10
-0+static inline void scsi_class_data_set (struct device *dev, +struct Scsi_Host *host) +{ + dev->class_data = (void *)host; +}; + +static inline struct Scsi_Host *scsi_class_data_get (struct device *dev) +{ +return (struct Scsi_Host *) dev->class_data; +};
These casts look rather pointless.
drivers/scsi/scsi.c line 2224
Quoted 3 lines
drivers/scsi/scsi.c +1
-1-module_init (init_scsi); +subsys_initcall (init_scsi);module_exit (exit_scsi);
What's the exact reason for this change?
drivers/scsi/scsi_syms.c line 113
Quoted 10 lines
/*
- * driverfs support for determining driver types
+ * sysfs support
*/drivers/scsi/scsi_syms.c +5
-1-EXPORT_SYMBOL (scsi_driverfs_bus_type); +EXPORT_SYMBOL (scsi_device_driver_register); +EXPORT_SYMBOL (scsi_device_driver_unregister); +EXPORT_SYMBOL (scsi_host_class_register); +EXPORT_SYMBOL (scsi_host_class_unregister); +EXPORT_SYMBOL (shost_devclass);
Why are these exported?
Quoted 32 lines
drivers/scsi/scsi_sysfs.c new file +32
-0+/** +* scsi_host_class_register - register class scsi host +* @dev: class device to register +* @shost: scsi host associtated with class device +* +* Return value: +**/ +int scsi_host_class_register (struct device *dev,struct Scsi_Host *shost) +{ +scsi_class_data_set (dev, shost); +scsi_host_dev_set (shost, dev); + +scsi_add_host (shost); + +return 0 ; +} + +/** +* scsi_host_class_unregister - unregister class scsi host. +* @dev: class device to unregister +**/ +void scsi_host_class_unregister (struct device *dev) +{ +struct Scsi_Host *shost; + + shost =scsi_class_data_get (dev); + +scsi_remove_host (shost); + +scsi_class_data_set (dev,NULL ); + +}
Quoted 1 line
diff -Nru
a/drivers/scsi/sd.cb/drivers/scsi/sd.c
What the point of these? They don't seem to be used at all..
Quoted 14 lines · Christoph Hellwig [[email protected]] wrote:
drivers/scsi/hosts.h line 629
Quoted 10 lines · Mike Anderson
drivers/scsi/hosts.h +10
-0+static inline void scsi_class_data_set (struct device *dev, +struct Scsi_Host *host) +{ + dev->class_data = (void *)host; +}; + +static inline struct Scsi_Host *scsi_class_data_get (struct device *dev) +{ +return (struct Scsi_Host *) dev->class_data; +};These casts look rather pointless.
These interfaces allow LLDD to use the probe / remove device model driver interfaces without having to store a previously registered scsi_host pointer away in there private data. On remove a LLD is passed a struct device pointer and would need to determine the associated scsi_host to call scsi_remove_host.
I was trying to ensure consistency and type checking of class_data used by host of class type scsi-host.
In the device model the struct device contains three void pointers for use by associated member. driver_data is a private data pointer for the device driver. class_data is for use by the class in this case scsi-host class.
Quoted 7 lines
drivers/scsi/scsi.c line 2224
Quoted 3 lines
drivers/scsi/scsi.c +1
-1-module_init (init_scsi); +subsys_initcall (init_scsi);module_exit (exit_scsi);What's the exact reason for this change?
This could be removed. Without this change the scsi_subsystem defaults to device_initcall level the same as upper and lower levels. The original Makefile ordering SCSI has works around this same level issue.
Quoted 4 lines
Quoted 4 lines
/*
- * driverfs support for determining driver types
+ * sysfs support
*/
Quoted 9 lines
drivers/scsi/scsi_syms.c line 113
Quoted 6 lines
drivers/scsi/scsi_syms.c +5
-1-EXPORT_SYMBOL (scsi_driverfs_bus_type); +EXPORT_SYMBOL (scsi_device_driver_register); +EXPORT_SYMBOL (scsi_device_driver_unregister); +EXPORT_SYMBOL (scsi_host_class_register); +EXPORT_SYMBOL (scsi_host_class_unregister); +EXPORT_SYMBOL (shost_devclass);Why are these exported?
The *device_driver* interfaces are possibly not needed any more as I originally had them exported because they where being called directly by the upper layers. Now they are being called by the mid-layer which this *.o is linked. In the future the upper layers could call these directly as the operations in scsi_register_device are handled by the sysfs layer if upper layers fully support the device model probe / remove / release.
The *host_class* are interfaces for the LLDD to call to register and unregister as a scsi host class driver.
These interfaces are used in a scsi_debug patch I have beyond scsi_debug 1.65 that demonstrate the used of these interfaces.
Quoted 27 lines
Quoted 27 lines
drivers/scsi/scsi_sysfs.c new file +27
-0+/** +* scsi_host_class_register - register class scsi host +* @dev: class device to register +* @shost: scsi host associtated with class device +* +* Return value: +**/ +int scsi_host_class_register (struct device *dev,struct Scsi_Host *shost) +{ +scsi_class_data_set (dev, shost); +scsi_host_dev_set (shost, dev); + +scsi_add_host (shost); + +return 0 ; +} + +/** +* scsi_host_class_unregister - unregister class scsi host. +* @dev: class device to unregister +**/ +void scsi_host_class_unregister (struct device *dev) +{ +struct Scsi_Host *shost; + + shost =scsi_class_data_get (dev); +
Quoted 9 lines
Quoted 6 lines
drivers/scsi/scsi_sysfs.c new file +5
-0+scsi_remove_host (shost); + +scsi_class_data_set (dev,NULL ); + +}diff -Nru
a/drivers/scsi/sd.cb/drivers/scsi/sd.cWhat the point of these? They don't seem to be used at all..
See previous comment.
-andmike
--
Michael Anderson
[email protected]
Quoted 7 lines · Mike Anderson
I was trying to ensure consistency and type checking of
class_dataused by host of class type scsi-host.In the device model the struct device contains three void pointers for use by associated member.
driver_datais a private data pointer for the device driver.class_datais for use by the class in this case scsi-host class.
Still the casts make no sense at all. in C you can assign a void pointer to any other pointer and the other way around.
Quoted 7 lines
The *device_driver* interfaces are possibly not needed any more as I originally had them exported because they where being called directly by the upper layers. Now they are being called by the mid-layer which this *.o is linked. In the future the upper layers could call these directly as the operations in
scsi_register_deviceare handled by the sysfs layer if upper layers fully support the device model probe / remove / release.
But they shouldn't. Each additional exported interface makes life harder. Please don't export stuff unless it's really required.
Quoted 5 lines
The *host_class* are interfaces for the LLDD to call to register and unregister as a scsi host class driver.
These interfaces are used in a
scsi_debugpatch I have beyondscsi_debug1.65 that demonstrate the used of these interfaces.
Again, see above. What do these interfaces actually gain us over scsi_add_host/scsi_remove_host? If it helps us in practice (of which I still need to be convienced) remove scsi_add_host/scsi_remove_host when exporting those, but don't keep both.
Quoted 4 lines · Christoph Hellwig [[email protected]] wrote:
Quoted 3 lines · Mike Anderson
I was trying to ensure consistency and type checking of
class_dataused by host of class type scsi-host.
Quoted 8 lines
Quoted 4 lines
In the device model the struct device contains three void pointers for use by associated member.
driver_datais a private data pointer for the device driver.class_datais for use by the class in this case scsi-host class.Still the casts make no sense at all. in C you can assign a void pointer to any other pointer and the other way around.
Ok, I guess I misunderstood (read to fast) what your issue was on this. I removed the casts.
Quoted 11 lines
Quoted 7 lines
The *device_driver* interfaces are possibly not needed any more as I originally had them exported because they where being called directly by the upper layers. Now they are being called by the mid-layer which this *.o is linked. In the future the upper layers could call these directly as the operations in
scsi_register_deviceare handled by the sysfs layer if upper layers fully support the device model probe / remove / release.But they shouldn't. Each additional exported interface makes life harder. Please don't export stuff unless it's really required.
I removed them.
Quoted 11 lines
Quoted 5 lines
The *host_class* are interfaces for the LLDD to call to register and unregister as a scsi host class driver.
These interfaces are used in a
scsi_debugpatch I have beyondscsi_debug1.65 that demonstrate the used of these interfaces.Again, see above. What do these interfaces actually gain us over scsi_add_host/scsi_remove_host? If it helps us in practice (of which I still need to be convienced) remove scsi_add_host/scsi_remove_host when exporting those, but don't keep both.
The only issue with removing the scsi_add_host and scsi_remove_host and replacing them with something like the *host_class* is that the host class interfaces assume the caller has a struct device to pass in. Currently there are callers of scsi_add_host that appear to not support the new device model.
-andmike
--
Michael Anderson
[email protected]