public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Ye Bin <yebin@huaweicloud.com>
To: jejb@linux.ibm.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ye Bin <yebin10@huawei.com>
Subject: [PATCH v2 2/3] scsi: introduce 'blocked' sysfs api
Date: Tue, 28 Mar 2023 22:34:41 +0800	[thread overview]
Message-ID: <20230328143442.2684167-3-yebin@huaweicloud.com> (raw)
In-Reply-To: <20230328143442.2684167-1-yebin@huaweicloud.com>

From: Ye Bin <yebin10@huawei.com>

Introduce 'blocked' sysfs api to control scsi host blocking IO.
Use this founction for test. Perhaps we can use this to do some fault
recovery or firmware upgrades, as long as the driver support is good,
it may be insensitive to the upper layer.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 drivers/scsi/scsi_sysfs.c | 32 ++++++++++++++++++++++++++++++++
 include/scsi/scsi_host.h  |  3 +++
 2 files changed, 35 insertions(+)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 903aa9de46e5..cad1981ab528 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -345,6 +345,37 @@ 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 ssize_t
+store_shost_blocked(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	int err;
+	bool blocked;
+	struct Scsi_Host *shost = class_to_shost(dev);
+
+	err = kstrtobool(buf, &blocked);
+	if (err)
+		return err;
+
+	if (shost->host_blockio != blocked) {
+		shost->host_blockio = blocked;
+		if (!blocked)
+			scsi_run_host_queues(shost);
+	}
+
+	return count;
+}
+
+static ssize_t
+show_shost_blocked(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(dev);
+
+	return snprintf(buf, 20, "%d\n", shost->host_blockio);
+}
+static DEVICE_ATTR(blocked, S_IRUGO | S_IWUSR,
+		   show_shost_blocked, store_shost_blocked);
+
 shost_rd_attr(unique_id, "%u\n");
 shost_rd_attr(cmd_per_lun, "%hd\n");
 shost_rd_attr(can_queue, "%d\n");
@@ -397,6 +428,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = {
 	&dev_attr_host_reset.attr,
 	&dev_attr_eh_deadline.attr,
 	&dev_attr_nr_hw_queues.attr,
+	&dev_attr_blocked.attr,
 	NULL
 };
 
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 587cc767bb67..3e916dbac1cb 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -659,6 +659,9 @@ struct Scsi_Host {
 	/* The transport requires the LUN bits NOT to be stored in CDB[1] */
 	unsigned no_scsi2_lun_in_cdb:1;
 
+	/* True host will blocking IO */
+	unsigned host_blockio:1;
+
 	/*
 	 * Optional work queue to be utilized by the transport
 	 */
-- 
2.31.1


  parent reply	other threads:[~2023-03-28 14:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 14:34 [PATCH v2 0/3] limit set the host state by sysfs Ye Bin
2023-03-28 14:34 ` [PATCH v2 1/3] scsi: forbid to set scsi " Ye Bin
2023-03-28 14:34 ` Ye Bin [this message]
2023-03-28 16:06   ` [PATCH v2 2/3] scsi: introduce 'blocked' sysfs api Mike Christie
2023-03-28 14:34 ` [PATCH v2 3/3] scsi: blocking IO when host is set blocked Ye Bin
2023-03-28 15:56   ` Mike Christie

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=20230328143442.2684167-3-yebin@huaweicloud.com \
    --to=yebin@huaweicloud.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yebin10@huawei.com \
    /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