rework shost/sdev attribute handling
PATCH 1/1 rework shost/sdev attribute handling
Hi James,
I've finally found some time to look over the per-driver sdev/shost attribute handling and I'm not so happy with it. First it adds new writeable variables to the host templates which is otherwise almost readonly, the other thing is that it needs per-template procedure calls in the drivers wheras we have moved away from that. Also it looks a bit coplicated :)
I've attached a patch below that makes the attributes handling a lot simpler. Details:
- the shost_attrs and sdev_attrs in the host template are now used to store the attributes overriden or added by the LLDD.
- the midlayer creates those first and then the generic attributes that haven't been overridded and the other way around.
- an attribute now must be completly overriden instead of just partially. This change in fact is independand of the other changes, but it makes the code much easier to understand
- the host attributes are properly unregistered now and don't leak anymore.
drivers/scsi/53c700.c +15 -20
@@ -172,7 +172,7 @@ STATIC int NCR_700_slave_configure(Scsi_Device *SDpnt); STATIC void NCR_700_slave_destroy(Scsi_Device *SDpnt); -static struct device_attribute **NCR_700_dev_attrs =NULL ; +STATIC struct device_attribute *NCR_700_dev_attrs[];static char *NCR_700_phase[] = {"" ,
@@ -1990,6 +1990,13 @@ }static ssize_t +NCR_700_show_queue_depth (struct device *dev,char *buf) +{ +struct scsi_device *SDp =to_scsi_device (dev); +return snprintf (buf,20 ,"%d\n" , SDp->queue_depth); +} + +static ssize_t NCR_700_store_queue_depth (struct device *dev,const char *buf,size_t count) {int depth;
@@ -2014,9 +2021,10 @@static struct device_attribute NCR_700_queue_depth_attr = { .attr = { .name ="queue_depth" , - .mode =S_IWUSR , + .mode =S_IRUGO |S_IWUSR , }, .store = NCR_700_store_queue_depth, + .show = NCR_700_show_queue_depth, };static struct device_attribute NCR_700_active_tags_attr = {
@@ -2027,25 +2035,12 @@ .show = NCR_700_show_active_tags, }; -STATIC int __init -NCR_700_init (void ) -{ -scsi_sysfs_modify_sdev_attribute (&NCR_700_dev_attrs, - &NCR_700_queue_depth_attr); -scsi_sysfs_modify_sdev_attribute (&NCR_700_dev_attrs, - &NCR_700_active_tags_attr); -return 0 ; -} - -/* NULL exit routine to keep modutils happy */ -STATIC void __exit -NCR_700_exit (void ) -{ -} +STATIC struct device_attribute *NCR_700_dev_attrs[] = { + &NCR_700_queue_depth_attr, + &NCR_700_active_tags_attr, +NULL , +};EXPORT_SYMBOL (NCR_700_detect);EXPORT_SYMBOL (NCR_700_release);EXPORT_SYMBOL (NCR_700_intr); - -module_init (NCR_700_init); -module_exit (NCR_700_exit);
drivers/scsi/NCR_D700.c +0 -1
@@ -387,7 +387,6 @@ static void __exit NCR_D700_exit(void) {mca_unregister_driver (&NCR_D700_driver); -scsi_sysfs_release_attributes (&NCR_D700_driver_template); }module_init (NCR_D700_init);
drivers/scsi/hosts.c +0 -6
@@ -151,12 +151,6 @@dump_stack (); } -/* if its not set in the template, use the default */ -if (!sht->shost_attrs) - sht->shost_attrs = scsi_sysfs_shost_attrs; -if (!sht->sdev_attrs) - sht->sdev_attrs = scsi_sysfs_sdev_attrs; - shost =kmalloc (sizeof (struct Scsi_Host ) + privsize, gfp_mask);if (!shost)return NULL ;
drivers/scsi/lasi700.c +0 -1
@@ -165,7 +165,6 @@lasi700_exit (void) {unregister_parisc_driver (&lasi700_driver); -scsi_sysfs_release_attributes (&lasi700_template); }module_init (lasi700_init);
drivers/scsi/scsi_priv.h +0 -5
@@ -117,11 +117,6 @@extern int scsi_sysfs_register (void );extern void scsi_sysfs_unregister (void ); -/* definitions for the linker default sections covering the host -* class and device attributes */ -extern struct class_device_attribute *scsi_sysfs_shost_attrs[]; -extern struct device_attribute *scsi_sysfs_sdev_attrs[]; -extern struct class shost_class;extern struct bus_type scsi_bus_type;
drivers/scsi/scsi_sysfs.c +96 -140
293 lines not on this page · raw message
include/scsi/scsi_host.h +2 -4
@@ -329,12 +329,12 @@#define SCSI_DEFAULT_HOST_BLOCKED 7/* -* Pointer to the sysfs class properties for this host +* Pointer to the sysfs class properties for this host, NULL terminated. */ struct class_device_attribute **shost_attrs;/* -* Pointer to the SCSI device properties for this host +* Pointer to the SCSI device properties for this host, NULL terminated. */ struct device_attribute **sdev_attrs;
@@ -498,8 +498,6 @@ {return shost->shost_gendev.parent; } - -extern void scsi_sysfs_release_attributes (struct scsi_host_template *);extern void scsi_unblock_requests (struct Scsi_Host *);extern void scsi_block_requests (struct Scsi_Host *);
Quoted 14 lines · Christoph Hellwig [[email protected]] wrote:
drivers/scsi/scsi_sysfs.c +8
-2@@ -282,8 +308,21 @@ {int i; -for (i =0 ; sdev->host->hostt->sdev_attrs[i] !=NULL ; i++) -device_remove_file (&sdev->sdev_gendev, sdev->host->hostt->sdev_attrs[i]); +for (i =0 ; scsi_sysfs_sdev_attrs[i]; i++) { +if (!attr_overridden (sdev->host->hostt->sdev_attrs, + scsi_sysfs_sdev_attrs[i])) { +device_remove_file (&sdev->sdev_gendev, + scsi_sysfs_sdev_attrs[i]); + } + } +
drivers/scsi/scsi_sysfs.c line 328
Quoted 10 lines
drivers/scsi/scsi_sysfs.c +7
-0+if (sdev->host->hostt->sdev_attrs) { +for (i =0 ; sdev->host->hostt->sdev_attrs[i]; i++) { +device_remove_file (&sdev->sdev_gendev, + sdev->host->hostt->sdev_attrs[i]); + } + } +class_device_unregister (&sdev->sdev_classdev);device_unregister (&sdev->sdev_gendev); }
Just a minor comment.
We are inconsistent in our cleanup, but...
I was told that you do not need to do individual removal of files if you are in the process of unregistering. You only need to do this if you just want to remove the attribute, but are still going to stay around. The files are cleaned up in the sysfs_remove_dir function call.
The comment on sysfs_remove_dir indicates this also.
I might have incorrect info.
-andmike
--
Michael Anderson
[email protected]
Quoted 7 lines · Mike Anderson
I was told that you do not need to do individual removal of files if you are in the process of unregistering. You only need to do this if you just want to remove the attribute, but are still going to stay around. The files are cleaned up in the
sysfs_remove_dirfunction call.The comment on
sysfs_remove_dirindicates this also.
You're right - I looked for {,class_}device_remove_file calls but didn't notice it's handled at a much lower level.
Here's an updated patch which also removes the superflous device_remove_file calls for the sdev attributes.
drivers/scsi/53c700.c +15 -20
@@ -172,7 +172,7 @@ STATIC int NCR_700_slave_configure(Scsi_Device *SDpnt); STATIC void NCR_700_slave_destroy(Scsi_Device *SDpnt); -static struct device_attribute **NCR_700_dev_attrs =NULL ; +STATIC struct device_attribute *NCR_700_dev_attrs[];static char *NCR_700_phase[] = {"" ,
@@ -1990,6 +1990,13 @@ }static ssize_t +NCR_700_show_queue_depth (struct device *dev,char *buf) +{ +struct scsi_device *SDp =to_scsi_device (dev); +return snprintf (buf,20 ,"%d\n" , SDp->queue_depth); +} + +static ssize_t NCR_700_store_queue_depth (struct device *dev,const char *buf,size_t count) {int depth;
@@ -2014,9 +2021,10 @@static struct device_attribute NCR_700_queue_depth_attr = { .attr = { .name ="queue_depth" , - .mode =S_IWUSR , + .mode =S_IRUGO |S_IWUSR , }, .store = NCR_700_store_queue_depth, + .show = NCR_700_show_queue_depth, };static struct device_attribute NCR_700_active_tags_attr = {
@@ -2027,25 +2035,12 @@ .show = NCR_700_show_active_tags, }; -STATIC int __init -NCR_700_init (void ) -{ -scsi_sysfs_modify_sdev_attribute (&NCR_700_dev_attrs, - &NCR_700_queue_depth_attr); -scsi_sysfs_modify_sdev_attribute (&NCR_700_dev_attrs, - &NCR_700_active_tags_attr); -return 0 ; -} - -/* NULL exit routine to keep modutils happy */ -STATIC void __exit -NCR_700_exit (void ) -{ -} +STATIC struct device_attribute *NCR_700_dev_attrs[] = { + &NCR_700_queue_depth_attr, + &NCR_700_active_tags_attr, +NULL , +};EXPORT_SYMBOL (NCR_700_detect);EXPORT_SYMBOL (NCR_700_release);EXPORT_SYMBOL (NCR_700_intr); - -module_init (NCR_700_init); -module_exit (NCR_700_exit);
drivers/scsi/NCR_D700.c +0 -1
@@ -387,7 +387,6 @@ static void __exit NCR_D700_exit(void) {mca_unregister_driver (&NCR_D700_driver); -scsi_sysfs_release_attributes (&NCR_D700_driver_template); }module_init (NCR_D700_init);
drivers/scsi/hosts.c +0 -6
@@ -151,12 +151,6 @@dump_stack (); } -/* if its not set in the template, use the default */ -if (!sht->shost_attrs) - sht->shost_attrs = scsi_sysfs_shost_attrs; -if (!sht->sdev_attrs) - sht->sdev_attrs = scsi_sysfs_sdev_attrs; - shost =kmalloc (sizeof (struct Scsi_Host ) + privsize, gfp_mask);if (!shost)return NULL ;
drivers/scsi/lasi700.c +0 -1
@@ -165,7 +165,6 @@lasi700_exit (void) {unregister_parisc_driver (&lasi700_driver); -scsi_sysfs_release_attributes (&lasi700_template); }module_init (lasi700_init);
drivers/scsi/scsi_priv.h +0 -5
@@ -117,11 +117,6 @@extern int scsi_sysfs_register (void );extern void scsi_sysfs_unregister (void ); -/* definitions for the linker default sections covering the host -* class and device attributes */ -extern struct class_device_attribute *scsi_sysfs_shost_attrs[]; -extern struct device_attribute *scsi_sysfs_sdev_attrs[]; -extern struct class shost_class;extern struct bus_type scsi_bus_type;
drivers/scsi/scsi_sysfs.c +67 -145
263 lines not on this page · raw message
include/scsi/scsi_host.h +2 -4
@@ -329,12 +329,12 @@#define SCSI_DEFAULT_HOST_BLOCKED 7/* -* Pointer to the sysfs class properties for this host +* Pointer to the sysfs class properties for this host, NULL terminated. */ struct class_device_attribute **shost_attrs;/* -* Pointer to the SCSI device properties for this host +* Pointer to the SCSI device properties for this host, NULL terminated. */ struct device_attribute **sdev_attrs;
@@ -498,8 +498,6 @@ {return shost->shost_gendev.parent; } - -extern void scsi_sysfs_release_attributes (struct scsi_host_template *);extern void scsi_unblock_requests (struct Scsi_Host *);extern void scsi_block_requests (struct Scsi_Host *);