move over exposing host attributes from sg/procfs to sysfs
Subsystems (2)
PATCH 1/1 move over exposing host attributes from sg/procfs to sysfs
This patch moves over printing of the various struct Scsi_Host attributes from procfs functions in the sg driver to sysfs.
Not only is this the much more logical place for them, but with some more work on the pcmcia drivers this will allow us to make scsi_host_get_next() private to the midlayer for implementing refcounting and cleaning up locking in that area.
drivers/scsi/scsi_sysfs.c +56 -9
@@ -14,6 +14,44 @@#include "scsi.h" #include "hosts.h" + +/* +* shost_show_function: macro to create an attr function that can be used to +* show a non-bit field. +*/ +#define shost_show_function (field, format_string) \ +static ssize_t \ +show_##field (struct device *dev, char *buf) \ +{ \ + struct Scsi_Host *shost = to_scsi_host(dev); \ + return snprintf (buf, 20, format_string, shost->field); \ +} + +/* +* shost_rd_attr: macro to create a function and attribute variable for a +* read only field. +*/ +#define shost_rd_attr (field, format_string) \ + shost_show_function(field, format_string) \ +static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL) + +/* +* Create the actual show/store functions and data structures. +*/ +shost_rd_attr (unique_id,"%u\n" ); +shost_rd_attr (host_busy,"%hu\n" ); +shost_rd_attr (cmd_per_lun,"%hd\n" ); +shost_rd_attr (sg_tablesize,"%hu\n" ); +shost_rd_attr (unchecked_isa_dma,"%d\n" ); + +static struct device_attribute *const shost_attrs[] = { + &dev_attr_unique_id, + &dev_attr_host_busy, + &dev_attr_cmd_per_lun, + &dev_attr_sg_tablesize, + &dev_attr_unchecked_isa_dma, +}; +/** * scsi_host_class_name_show - copy out the SCSI host name * @dev: device to check
@@ -39,12 +77,21 @@static int scsi_host_class_add_dev (struct device * dev) { +int i; +device_create_file (dev, &dev_attr_class_name); +for (i =0 ; i <ARRAY_SIZE (shost_attrs); i++) +device_create_file (dev, shost_attrs[i]); +return 0 ; }static void scsi_host_class_rm_dev (struct device * dev) { +int i; + +for (i =0 ; i <ARRAY_SIZE (shost_attrs); i++) +device_remove_file (dev, shost_attrs[i]);device_remove_file (dev, &dev_attr_class_name); }
@@ -129,10 +176,10 @@/* -* show_function: macro to create an attr function that can be used to +* sdev_show_function: macro to create an attr function that can be used to * show a non-bit field. */ -#define show_function (field, format_string) \ +#define sdev_show_function (field, format_string) \ static ssize_t \ show_##field (struct device *dev, char *buf) \ { \
@@ -146,7 +193,7 @@* read only field. */ #define sdev_rd_attr (field, format_string) \ - show_function(field, format_string) \ + sdev_show_function(field, format_string) \ static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL)
@@ -155,27 +202,27 @@* read/write field. */ #define sdev_rw_attr (field, format_string) \ - show_function(field, format_string) \ + sdev_show_function(field, format_string) \ \ static ssize_t \ -store_##field (struct device *dev, const char *buf, size_t count) \ +sdev_store_##field (struct device *dev, const char *buf, size_t count) \ { \ struct scsi_device *sdev; \ sdev = to_scsi_device(dev); \ snscanf (buf, 20, format_string, &sdev->field); \ return count; \ } \ -static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, show_##field, store_##field) +static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, show_##field, sdev_store_##field)/* * sdev_rd_attr: create a function and attribute variable for a * read/write bit field. */ #define sdev_rw_attr_bit (field) \ - show_function(field, "%d\n") \ + sdev_show_function(field, "%d\n") \ \ static ssize_t \ -store_##field (struct device *dev, const char *buf, size_t count) \ +sdev_store_##field (struct device *dev, const char *buf, size_t count) \ { \ int ret; \ struct scsi_device *sdev; \
@@ -187,7 +234,7 @@ } \return ret; \ } \ -static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, show_##field, store_##field) +static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, show_##field, sdev_store_##field)/* * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
drivers/scsi/sg.c +0 -88
106 lines not on this page · raw message