public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Patrick Mansfield <patmans@us.ibm.com>
To: James Bottomley <James.Bottomley@steeleye.com>,
	linux-scsi@vger.kernel.org, Greg KH <greg@kroah.com>,
	Kay Sievers <kay.sievers@vrfy.org>
Subject: [PATCH] 2/2 Use bus dev_attrs to create scsi_device attributes
Date: Wed, 2 Mar 2005 11:46:47 -0800	[thread overview]
Message-ID: <20050302194647.GB9776@us.ibm.com> (raw)
In-Reply-To: <20050302194553.GA9776@us.ibm.com>

Use bus dev_attrs to create the default scsi_device attributes.

Note sdev_default_attrs is not a pointer to an array (like
scsi_sysfs_sdev_attrs), and so DEVICE_ATTR's can be removed, and __ATTR
used instaed.

Signed-off-by: Patrick Mansfield <patmans@us.ibm.com>

--- sattrs-linux-2.6.11/drivers/scsi/s1-scsi_sysfs.c	2005-03-02 09:58:21.000000000 -0800
+++ sattrs-linux-2.6.11/drivers/scsi/scsi_sysfs.c	2005-03-02 10:22:25.000000000 -0800
@@ -193,40 +193,6 @@
 	.release	= scsi_device_cls_release,
 };
 
-/* all probing is done in the individual ->probe routines */
-static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
-{
-	struct scsi_device *sdp = to_scsi_device(dev);
-	if (sdp->no_uld_attach)
-		return 0;
-	return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
-}
-
-struct bus_type scsi_bus_type = {
-        .name		= "scsi",
-        .match		= scsi_bus_match,
-};
-
-int scsi_sysfs_register(void)
-{
-	int error;
-
-	error = bus_register(&scsi_bus_type);
-	if (!error) {
-		error = class_register(&sdev_class);
-		if (error)
-			bus_unregister(&scsi_bus_type);
-	}
-
-	return error;
-}
-
-void scsi_sysfs_unregister(void)
-{
-	class_unregister(&sdev_class);
-	bus_unregister(&scsi_bus_type);
-}
-
 /*
  * sdev_show_function: macro to create an attr function that can be used to
  * show a non-bit field.
@@ -245,8 +211,7 @@
  * read only field.
  */
 #define sdev_rd_attr(field, format_string)				\
-	sdev_show_function(field, format_string)			\
-static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
+	sdev_show_function(field, format_string)
 
 
 /*
@@ -263,8 +228,7 @@
 	sdev = to_scsi_device(dev);					\
 	snscanf (buf, 20, format_string, &sdev->field);			\
 	return count;							\
-}									\
-static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
+}
 
 /* Currently we don't export bit fields, but we might in future,
  * so leave this code in */
@@ -288,8 +252,7 @@
 		ret = count;						\
 	}								\
 	return ret;							\
-}									\
-static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
+}
 
 /*
  * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
@@ -336,15 +299,13 @@
 	sdev->timeout = timeout * HZ;
 	return count;
 }
-static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
 
 static ssize_t
-store_rescan_field (struct device *dev, const char *buf, size_t count) 
+sdev_store_rescan (struct device *dev, const char *buf, size_t count) 
 {
 	scsi_rescan_device(dev);
 	return count;
 }
-static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
 
 static ssize_t sdev_store_delete(struct device *dev, const char *buf,
 				 size_t count)
@@ -352,10 +313,9 @@
 	scsi_remove_device(to_scsi_device(dev));
 	return count;
 };
-static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
 
 static ssize_t
-store_state_field(struct device *dev, const char *buf, size_t count)
+sdev_store_state(struct device *dev, const char *buf, size_t count)
 {
 	int i;
 	struct scsi_device *sdev = to_scsi_device(dev);
@@ -378,7 +338,7 @@
 }
 
 static ssize_t
-show_state_field(struct device *dev, char *buf)
+sdev_show_state(struct device *dev, char *buf)
 {
 	struct scsi_device *sdev = to_scsi_device(dev);
 	const char *name = scsi_device_state_name(sdev->sdev_state);
@@ -389,8 +349,6 @@
 	return snprintf(buf, 20, "%s\n", name);
 }
 
-static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
-
 sdev_show_function (queue_depth, "%d\n");
 
 static ssize_t sdev_store_queue_depth(struct device *dev, const char *buf,
@@ -420,7 +378,7 @@
 	       sdev_store_queue_depth);
 
 static ssize_t
-show_queue_type_field(struct device *dev, char *buf)
+sdev_show_queue_type(struct device *dev, char *buf)
 {
 	struct scsi_device *sdev = to_scsi_device(dev);
 	const char *name = "none";
@@ -461,25 +419,29 @@
 	return count;
 }
 
-static struct device_attribute dev_attr_queue_type =
-	__ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
-	       sdev_store_queue_type);
+#define SDEV_ATTR_RO(_name) __ATTR(_name, S_IRUGO, sdev_show_##_name, NULL)
+#define SDEV_ATTR_WO(_name) __ATTR(_name, S_IWUSR, NULL, sdev_store_##_name)
+#define SDEV_ATTR_RW(_name) __ATTR(_name, S_IRUGO | S_IWUSR, \
+				   sdev_show_##_name, sdev_store_##_name)
+
+/* Default scsi_device attributes, cannot be overidden */
+static struct device_attribute sdev_default_attrs[] = {
+	SDEV_ATTR_RO(device_blocked),
+	SDEV_ATTR_RW(queue_type),
+	SDEV_ATTR_RO(type),
+	SDEV_ATTR_RO(scsi_level),
+	SDEV_ATTR_RO(vendor),
+	SDEV_ATTR_RO(model),
+	SDEV_ATTR_RO(rev),
+	SDEV_ATTR_WO(rescan),
+	SDEV_ATTR_WO(delete),
+	SDEV_ATTR_RW(state),
+	SDEV_ATTR_RW(timeout),
+	__ATTR_NULL
+};
 
-/* Default template for device attributes.  May NOT be modified */
 static struct device_attribute *scsi_sysfs_sdev_attrs[] = {
-	&dev_attr_device_blocked,
-	&dev_attr_queue_depth,
-	&dev_attr_queue_type,
-	&dev_attr_type,
-	&dev_attr_scsi_level,
-	&dev_attr_vendor,
-	&dev_attr_model,
-	&dev_attr_rev,
-	&dev_attr_rescan,
-	&dev_attr_delete,
-	&dev_attr_state,
-	&dev_attr_timeout,
-	NULL
+	&dev_attr_queue_depth
 };
 
 static struct device_attribute *attr_overridden(
@@ -518,6 +480,41 @@
 	return device_create_file(dev, attr);
 }
 
+/* all probing is done in the individual ->probe routines */
+static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
+{
+	struct scsi_device *sdp = to_scsi_device(dev);
+	if (sdp->no_uld_attach)
+		return 0;
+	return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
+}
+
+struct bus_type scsi_bus_type = {
+        .name		= "scsi",
+        .match		= scsi_bus_match,
+	.dev_attrs	= sdev_default_attrs,
+};
+
+int scsi_sysfs_register(void)
+{
+	int error;
+
+	error = bus_register(&scsi_bus_type);
+	if (!error) {
+		error = class_register(&sdev_class);
+		if (error)
+			bus_unregister(&scsi_bus_type);
+	}
+
+	return error;
+}
+
+void scsi_sysfs_unregister(void)
+{
+	class_unregister(&sdev_class);
+	bus_unregister(&scsi_bus_type);
+}
+
 static void scsi_target_dev_release(struct device *dev)
 {
 	struct scsi_target *starget = to_scsi_target(dev);

  reply	other threads:[~2005-03-02 19:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-02 19:44 [PATCH] 0/2 use sysfs bus dev_attrs for scsi_device attributes Patrick Mansfield
2005-03-02 19:45 ` [PATCH] 1/2 remove attr_changed_internally Patrick Mansfield
2005-03-02 19:46   ` Patrick Mansfield [this message]
2005-03-16 22:45     ` [PATCH] 2/2 Use bus dev_attrs to create scsi_device attributes Patrick Mansfield
2005-03-17 14:53       ` James Bottomley
2005-03-17 17:08         ` Greg KH
2005-03-30  3:15           ` Kay Sievers
2005-03-30  4:20             ` Greg KH
2005-03-30 18:07               ` Kay Sievers
2005-04-06 20:22                 ` Greg KH
2005-03-30 18:32         ` Kay Sievers
2005-03-30 21:44           ` Patrick Mansfield
2005-03-30 22:12             ` Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050302194647.GB9776@us.ibm.com \
    --to=patmans@us.ibm.com \
    --cc=James.Bottomley@steeleye.com \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox