From: James Smart <jsmart2021@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: James Smart <jsmart2021@gmail.com>
Subject: [PATCH] scsi: add attribute to set lun queue depth on all luns on shost
Date: Tue, 21 Jan 2020 15:53:02 -0800 [thread overview]
Message-ID: <20200121235302.9955-1-jsmart2021@gmail.com> (raw)
There has been a desire to set the lun queue depth on all luns on
an shost. Today that is done by an external script looping through
discovered sdevs and set an sdev attribute.
This patch addes a shost attribute that will cycle through all
sdevs and set the lun queue depth.
Signed-off-by: James Smart <jsmart2021@gmail.com>
---
drivers/scsi/scsi_sysfs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 677b5c5403d2..debb79be66c0 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -368,6 +368,50 @@ store_shost_eh_deadline(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR(eh_deadline, S_IRUGO | S_IWUSR, show_shost_eh_deadline, store_shost_eh_deadline);
+static int
+sdev_set_queue_depth(struct scsi_device *sdev, int depth)
+{
+ struct scsi_host_template *sht = sdev->host->hostt;
+ int retval;
+
+ retval = sht->change_queue_depth(sdev, depth);
+ if (retval < 0)
+ return retval;
+
+ sdev->max_queue_depth = sdev->queue_depth;
+
+ return 0;
+}
+
+static ssize_t
+store_host_lun_queue_depth(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct Scsi_Host *shost = class_to_shost(dev);
+ struct scsi_host_template *sht = shost->hostt;
+ struct scsi_device *sdev;
+ int depth, retval;
+
+ if (!sht->change_queue_depth)
+ return -EINVAL;
+
+ depth = simple_strtoul(buf, NULL, 0);
+ if (depth < 1 || depth > shost->can_queue)
+ return -EINVAL;
+
+ shost_for_each_device(sdev, shost) {
+ retval = sdev_set_queue_depth(sdev, depth);
+ if (retval != 0)
+ sdev_printk(KERN_INFO, sdev,
+ "failed to set queue depth to %d (err %d)",
+ depth, retval);
+ }
+
+ return count;
+}
+
+static DEVICE_ATTR(lun_queue_depth, S_IWUSR, NULL, store_host_lun_queue_depth);
+
shost_rd_attr(unique_id, "%u\n");
shost_rd_attr(cmd_per_lun, "%hd\n");
shost_rd_attr(can_queue, "%hd\n");
@@ -411,6 +455,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = {
&dev_attr_prot_guard_type.attr,
&dev_attr_host_reset.attr,
&dev_attr_eh_deadline.attr,
+ &dev_attr_lun_queue_depth.attr,
NULL
};
@@ -992,12 +1037,10 @@ sdev_store_queue_depth(struct device *dev, struct device_attribute *attr,
if (depth < 1 || depth > sdev->host->can_queue)
return -EINVAL;
- retval = sht->change_queue_depth(sdev, depth);
+ retval = sdev_set_queue_depth(sdev, depth);
if (retval < 0)
return retval;
- sdev->max_queue_depth = sdev->queue_depth;
-
return count;
}
sdev_show_function(queue_depth, "%d\n");
--
2.13.7
next reply other threads:[~2020-01-21 23:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-21 23:53 James Smart [this message]
2020-01-23 4:44 ` [PATCH] scsi: add attribute to set lun queue depth on all luns on shost Bart Van Assche
2020-01-23 22:24 ` James Smart
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=20200121235302.9955-1-jsmart2021@gmail.com \
--to=jsmart2021@gmail.com \
--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