From: Wenchao Hao <haowenchao2@huawei.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
Douglas Gilbert <dgilbert@interlog.com>
Cc: "James E . J . Bottomley" <jejb@linux.ibm.com>,
<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<louhongxiang@huawei.com>, Wenchao Hao <haowenchao2@huawei.com>
Subject: [PATCH v6 09/10] scsi: scsi_debug: Add debugfs interface to fail target reset
Date: Tue, 10 Oct 2023 17:20:50 +0800 [thread overview]
Message-ID: <20231010092051.608007-10-haowenchao2@huawei.com> (raw)
In-Reply-To: <20231010092051.608007-1-haowenchao2@huawei.com>
The interface is found at
/sys/kernel/debug/scsi_debug/target<h:c:t>/fail_reset where <h:c:t>
identifies the target to inject errors on. It's a simple bool type
interface which would make this target's reset fail if set to 'Y'.
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
---
drivers/scsi/scsi_debug.c | 114 +++++++++++++++++++++++++++++++++++++-
1 file changed, 113 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index e54ba0bfa0d6..2743eb36c58e 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -42,6 +42,7 @@
#include <linux/xarray.h>
#include <linux/prefetch.h>
#include <linux/debugfs.h>
+#include <linux/async.h>
#include <net/checksum.h>
@@ -357,6 +358,11 @@ struct sdebug_dev_info {
struct list_head inject_err_list;
};
+struct sdebug_target_info {
+ bool reset_fail;
+ struct dentry *debugfs_entry;
+};
+
struct sdebug_host_info {
struct list_head host_list;
int si_idx; /* sdeb_store_info (per host) xarray index */
@@ -1082,6 +1088,91 @@ static const struct file_operations sdebug_error_fops = {
.release = single_release,
};
+static int sdebug_target_reset_fail_show(struct seq_file *m, void *p)
+{
+ struct scsi_target *starget = (struct scsi_target *)m->private;
+ struct sdebug_target_info *targetip =
+ (struct sdebug_target_info *)starget->hostdata;
+
+ if (targetip)
+ seq_printf(m, "%c\n", targetip->reset_fail ? 'Y' : 'N');
+
+ return 0;
+}
+
+static int sdebug_target_reset_fail_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, sdebug_target_reset_fail_show, inode->i_private);
+}
+
+static ssize_t sdebug_target_reset_fail_write(struct file *file,
+ const char __user *ubuf, size_t count, loff_t *ppos)
+{
+ int ret;
+ struct scsi_target *starget =
+ (struct scsi_target *)file->f_inode->i_private;
+ struct sdebug_target_info *targetip =
+ (struct sdebug_target_info *)starget->hostdata;
+
+ if (targetip) {
+ ret = kstrtobool_from_user(ubuf, count, &targetip->reset_fail);
+ return ret < 0 ? ret : count;
+ }
+ return -ENODEV;
+}
+
+static const struct file_operations sdebug_target_reset_fail_fops = {
+ .open = sdebug_target_reset_fail_open,
+ .read = seq_read,
+ .write = sdebug_target_reset_fail_write,
+ .release = single_release,
+};
+
+static int sdebug_target_alloc(struct scsi_target *starget)
+{
+ struct sdebug_target_info *targetip;
+ struct dentry *dentry;
+
+ targetip = kzalloc(sizeof(struct sdebug_target_info), GFP_KERNEL);
+ if (!targetip)
+ return -ENOMEM;
+
+ targetip->debugfs_entry = debugfs_create_dir(dev_name(&starget->dev),
+ sdebug_debugfs_root);
+ if (IS_ERR_OR_NULL(targetip->debugfs_entry))
+ pr_info("%s: failed to create debugfs directory for target %s\n",
+ __func__, dev_name(&starget->dev));
+
+ debugfs_create_file("fail_reset", 0600, targetip->debugfs_entry, starget,
+ &sdebug_target_reset_fail_fops);
+ if (IS_ERR_OR_NULL(dentry))
+ pr_info("%s: failed to create fail_reset file for target %s\n",
+ __func__, dev_name(&starget->dev));
+
+ starget->hostdata = targetip;
+
+ return 0;
+}
+
+static void sdebug_tartget_cleanup_async(void *data, async_cookie_t cookie)
+{
+ struct sdebug_target_info *targetip = data;
+
+ debugfs_remove(targetip->debugfs_entry);
+ kfree(targetip);
+}
+
+static void sdebug_target_destroy(struct scsi_target *starget)
+{
+ struct sdebug_target_info *targetip;
+
+ targetip = (struct sdebug_target_info *)starget->hostdata;
+ if (targetip) {
+ starget->hostdata = NULL;
+ async_schedule(sdebug_tartget_cleanup_async, targetip);
+ }
+}
+
/* Only do the extra work involved in logical block provisioning if one or
* more of the lbpu, lbpws or lbpws10 parameters are given and we are doing
* real reads and writes (i.e. not skipping them for speed).
@@ -5642,11 +5733,25 @@ static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
return SUCCESS;
}
+static int sdebug_fail_target_reset(struct scsi_cmnd *cmnd)
+{
+ struct scsi_target *starget = scsi_target(cmnd->device);
+ struct sdebug_target_info *targetip =
+ (struct sdebug_target_info *)starget->hostdata;
+
+ if (targetip)
+ return targetip->reset_fail;
+
+ return 0;
+}
+
static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
{
struct scsi_device *sdp = SCpnt->device;
struct sdebug_host_info *sdbg_host = shost_to_sdebug_host(sdp->host);
struct sdebug_dev_info *devip;
+ u8 *cmd = SCpnt->cmnd;
+ u8 opcode = cmd[0];
int k = 0;
++num_target_resets;
@@ -5664,6 +5769,12 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
sdev_printk(KERN_INFO, sdp,
"%s: %d device(s) found in target\n", __func__, k);
+ if (sdebug_fail_target_reset(SCpnt)) {
+ scmd_printk(KERN_INFO, SCpnt, "fail target reset 0x%x\n",
+ opcode);
+ return FAILED;
+ }
+
return SUCCESS;
}
@@ -8119,7 +8230,6 @@ static int sdebug_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
return 0;
}
-
static struct scsi_host_template sdebug_driver_template = {
.show_info = scsi_debug_show_info,
.write_info = scsi_debug_write_info,
@@ -8149,6 +8259,8 @@ static struct scsi_host_template sdebug_driver_template = {
.track_queue_depth = 1,
.cmd_size = sizeof(struct sdebug_scsi_cmd),
.init_cmd_priv = sdebug_init_cmd_priv,
+ .target_alloc = sdebug_target_alloc,
+ .target_destroy = sdebug_target_destroy,
};
static int sdebug_driver_probe(struct device *dev)
--
2.32.0
next prev parent reply other threads:[~2023-10-10 9:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 9:20 [PATCH v6 00/10] scsi:scsi_debug: Add error injection for single device Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 01/10] scsi: scsi_debug: create scsi_debug directory in the debugfs filesystem Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 02/10] scsi: scsi_debug: Add interface to manage single device's error inject Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 03/10] scsi: scsi_debug: Define grammar to remove added error injection Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 04/10] scsi: scsi_debug: timeout command if the error is injected Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 05/10] scsi: scsi_debug: Return failed value " Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 06/10] scsi: scsi_debug: set command's result and sense data " Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 07/10] scsi: scsi_debug: Add new error injection abort failed Wenchao Hao
2023-10-10 9:20 ` [PATCH v6 08/10] scsi: scsi_debug: Add new error injection reset lun failed Wenchao Hao
2023-10-10 9:20 ` Wenchao Hao [this message]
2023-10-10 9:20 ` [PATCH v6 10/10] scsi: scsi_debug: Add param to control sdev's allow_restart Wenchao Hao
2023-10-16 2:09 ` [PATCH v6 00/10] scsi:scsi_debug: Add error injection for single device Wenchao Hao
2023-10-17 0:53 ` Martin K. Petersen
2023-10-25 2:19 ` Martin K. Petersen
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=20231010092051.608007-10-haowenchao2@huawei.com \
--to=haowenchao2@huawei.com \
--cc=dgilbert@interlog.com \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=louhongxiang@huawei.com \
--cc=martin.petersen@oracle.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
all inboxes | Powered by JetHome®