scsi: core: host template attribute groups
authorStanislav Nijnikov <stanislav.nijnikov@wdc.com>
Thu, 15 Feb 2018 12:14:08 +0000 (14:14 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 15 Feb 2018 23:34:51 +0000 (18:34 -0500)
The patch introduces an additional field in the scsi_host_template
structure - struct attribute_group **sdev_group.  This field allows to
define groups of attributes. It will provide an ability to use binary
attributes as well as device attributes and to group them under
subfolders if necessary.

Signed-off-by: Stanislav Nijnikov <stanislav.nijnikov@wdc.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_sysfs.c
include/scsi/scsi_host.h

index 91b90f672d232f708e3baeaa1871a4ed121fcd48..e56a4ac990c082ebc886d0352a204ee3da931a0f 100644 (file)
@@ -1310,6 +1310,13 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
                }
        }
 
+       if (sdev->host->hostt->sdev_groups) {
+               error = sysfs_create_groups(&sdev->sdev_gendev.kobj,
+                               sdev->host->hostt->sdev_groups);
+               if (error)
+                       return error;
+       }
+
        scsi_autopm_put_device(sdev);
        return error;
 }
@@ -1349,6 +1356,10 @@ void __scsi_remove_device(struct scsi_device *sdev)
                if (res != 0)
                        return;
 
+               if (sdev->host->hostt->sdev_groups)
+                       sysfs_remove_groups(&sdev->sdev_gendev.kobj,
+                                       sdev->host->hostt->sdev_groups);
+
                bsg_unregister_queue(sdev->request_queue);
                device_unregister(&sdev->sdev_dev);
                transport_remove_device(dev);
index 1a1df0d21ee3f9648cc02a6bc067783ae5e5ef03..19317585ae48f30d22a3b7f4c1ddb30d66ce493b 100644 (file)
@@ -476,6 +476,12 @@ struct scsi_host_template {
         */
        struct device_attribute **sdev_attrs;
 
+       /*
+        * Pointer to the SCSI device attribute groups for this host,
+        * NULL terminated.
+        */
+       const struct attribute_group **sdev_groups;
+
        /*
         * List of hosts per template.
         *