public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: SCSI Mailing List <linux-scsi@vger.kernel.org>,
	Patrick Mochel <mochel@osdl.org>, Greg KH <greg@kroah.com>,
	Mike Anderson <andmike@us.ibm.com>
Subject: Re: [RFC] support for sysfs string based properties for SCSI (3/3)
Date: 03 May 2003 14:30:54 -0500	[thread overview]
Message-ID: <1051990255.2308.26.camel@mulgrave> (raw)
In-Reply-To: <1051989937.2308.21.camel@mulgrave>

[-- Attachment #1: Type: text/plain, Size: 488 bytes --]

This illustrates how the new show/store interface may be used for adding
and setting properties.

The attached patch implements a store method in 53c700 which allows the
setting of the queue_depth parameter.

It also adds an "outstanding_tags" attribute which provides all the
information that the 53c700 procfs_info routine now provides.

Hopefully, this interface will be simple and flexible enough to allow us
to migrate all of the SCSI drivers away from proc and on to sysfs.

James


[-- Attachment #2: tmp.diff --]
[-- Type: text/plain, Size: 3831 bytes --]

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1198  -> 1.1199 
#	drivers/scsi/53c700.c	1.29    -> 1.30   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/05/03	jejb@raven.il.steeleye.com	1.1199
# SCSI: implement properties in the 53c700 driver
# 
# Add a store for the queue_depth setting, and a show for a new
# property called outstanding tags (this is the information currently
# shown by the drivers procfs routine).
# --------------------------------------------
#
diff -Nru a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
--- a/drivers/scsi/53c700.c	Sat May  3 14:27:29 2003
+++ b/drivers/scsi/53c700.c	Sat May  3 14:27:29 2003
@@ -172,6 +172,17 @@
 STATIC void NCR_700_chip_reset(struct Scsi_Host *host);
 STATIC int NCR_700_slave_configure(Scsi_Device *SDpnt);
 STATIC void NCR_700_slave_destroy(Scsi_Device *SDpnt);
+STATIC ssize_t NCR_700_device_property_show(struct scsi_device * dev,
+					    char * buf,
+					    struct attribute *attr);
+STATIC ssize_t NCR_700_device_property_store(struct scsi_device * dev,
+					     const char * buf,
+					     size_t count,
+					     struct attribute *attr);
+
+struct device_attribute NCR_700_sdev_attrs[] = {
+	{ .attr = { .name = "outstanding_tags", .mode = S_IRUGO }, },
+};
 
 static char *NCR_700_phase[] = {
 	"",
@@ -278,6 +289,8 @@
 	tpnt->proc_info = NCR_700_proc_directory_info;
 	tpnt->slave_configure = NCR_700_slave_configure;
 	tpnt->slave_destroy = NCR_700_slave_destroy;
+	tpnt->device_property_show = NCR_700_device_property_show;
+	tpnt->device_property_store = NCR_700_device_property_store;
 	tpnt->use_blk_tcq = 1;
 	tpnt->highmem_io = 1;
 	
@@ -2007,6 +2020,8 @@
 STATIC int
 NCR_700_slave_configure(Scsi_Device *SDp)
 {
+	int i;
+
 	/* to do here: allocate memory; build a queue_full list */
 	if(SDp->tagged_supported) {
 		/* do TCQ stuff here */
@@ -2014,14 +2029,63 @@
 		/* initialise to default depth */
 		scsi_adjust_queue_depth(SDp, 0, SDp->host->cmd_per_lun);
 	}
+
+	for (i = 0; i < ARRAY_SIZE(NCR_700_sdev_attrs); i++)
+		device_create_file(&SDp->sdev_driverfs_dev,
+				   &NCR_700_sdev_attrs[i]);
 	return 0;
 }
 
 STATIC void
 NCR_700_slave_destroy(Scsi_Device *SDp)
 {
-	/* to do here: deallocate memory */
+	int i;
+
+	/* FIXME: slave_destroy can be called if no driverfs entry
+	 * has been created.  We really need a slave_unconfigure for
+	 * this type of thing */
+	if(SDp->sdev_driverfs_dev.node.next != NULL)
+		for (i = 0; i < ARRAY_SIZE(NCR_700_sdev_attrs); i++)
+			device_remove_file(&SDp->sdev_driverfs_dev,
+					   &NCR_700_sdev_attrs[i]);
+
+}
+
+STATIC ssize_t
+NCR_700_device_property_show(struct scsi_device * sdev, char * buf,
+			     struct attribute *attr)
+{
+	char *name = attr->name;
+	int ret = 0;
+
+	if (strcmp(name, "outstanding_tags") == 0) {
+		ret = snprintf(buf, 20, "%d\n", NCR_700_get_depth(sdev));
+	}
+	return ret;
 }
+
+STATIC ssize_t
+NCR_700_device_property_store(struct scsi_device * sdev, const char * buf,
+			      size_t count, struct attribute *attr)
+{
+	char *name = attr->name;
+
+	if (strcmp(name, "queue_depth") == 0) {
+		long new_depth = simple_strtol(buf, NULL, 0);
+		if (new_depth > NCR_700_MAX_TAGS) {
+			return -EINVAL;
+		} else if (new_depth < 0) {
+			/* FIXME: turn off tags need to quiesce the
+			 * device to do this */
+			return -EINVAL;
+		} else {
+			scsi_adjust_queue_depth(sdev, 0, new_depth);
+		}
+	}
+	return 0;
+}
+
+
 
 EXPORT_SYMBOL(NCR_700_detect);
 EXPORT_SYMBOL(NCR_700_release);

  reply	other threads:[~2003-05-03 19:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-03 19:11 [RFC] support for sysfs string based properties for SCSI (1/3) James Bottomley
2003-05-03 19:19 ` James Bottomley
2003-05-03 19:25   ` [RFC] support for sysfs string based properties for SCSI (2/3) James Bottomley
2003-05-03 19:30     ` James Bottomley [this message]
2003-05-05 17:02   ` [RFC] support for sysfs string based properties for SCSI (1/3) Greg KH
2003-05-05 17:08     ` James Bottomley
2003-05-05 17:17       ` Greg KH
2003-05-05 20:08         ` Mike Anderson
2003-05-06  0:05         ` James Bottomley
2003-05-13 21:02   ` Patrick Mochel

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=1051990255.2308.26.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=andmike@us.ibm.com \
    --cc=greg@kroah.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mochel@osdl.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