From: Lee Duncan <lduncan@suse.com>
To: linux-scsi@vger.kernel.org
Cc: "James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Hannes Reinecke <hare@suse.com>, Lee Duncan <lduncan@suse.com>
Subject: [PATCH] scsi: ioctl reset should wait for IOs to complete
Date: Tue, 26 Sep 2017 10:22:35 -0700 [thread overview]
Message-ID: <20170926172235.29530-1-lduncan@suse.com> (raw)
The SCSI ioctl reset path is smart enough to set the
flag tmf_in_progress when a user-requested reset is
processed, but it does not wait for IO that is in
flight. This can result in lost IOs and hung
processes. We should wait for a reasonable amount
of time for either the IOs to complete or to fail
the request.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/scsi_error.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 38942050b265..b964152611c3 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -57,6 +57,14 @@
#define BUS_RESET_SETTLE_TIME (10)
#define HOST_RESET_SETTLE_TIME (10)
+/*
+ * Time to wait for outstanding IOs when about to send
+ * a device reset, e.g. sg_reset. The msecs to wait must
+ * be an multiple of the msecs to wait per try.
+ */
+#define MSECS_PER_TRY_FOR_IO_ON_RESET 500
+#define MSECS_TO_WAIT_FOR_IO_ON_RESET (MSECS_PER_TRY_FOR_IO_ON_RESET * 10)
+
static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
static int scsi_try_to_abort_cmd(struct scsi_host_template *,
struct scsi_cmnd *);
@@ -2269,6 +2277,7 @@ void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
struct request *rq;
unsigned long flags;
int error = 0, rtn, val;
+ unsigned int msecs_to_wait = MSECS_TO_WAIT_FOR_IO_ON_RESET;
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
return -EACCES;
@@ -2301,6 +2310,22 @@ void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
spin_lock_irqsave(shost->host_lock, flags);
shost->tmf_in_progress = 1;
+
+ /* if any IOs in progress wait for them a while */
+ while ((atomic_read(&shost->host_busy) > 0) && (msecs_to_wait > 0)) {
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ msleep(MSECS_PER_TRY_FOR_IO_ON_RESET);
+ msecs_to_wait -= MSECS_PER_TRY_FOR_IO_ON_RESET;
+ spin_lock_irqsave(shost->host_lock, flags);
+ }
+ if (atomic_read(&shost->host_busy)) {
+ shost->tmf_in_progress = 0;
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ SCSI_LOG_ERROR_RECOVERY(3,
+ printk("%s: device reset failed: outstanding IO\n", __func__));
+ goto out_put_scmd_and_free;
+ }
+
spin_unlock_irqrestore(shost->host_lock, flags);
switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
@@ -2349,6 +2374,7 @@ void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
wake_up(&shost->host_wait);
scsi_run_host_queues(shost);
+out_put_scmd_and_free:
scsi_put_command(scmd);
kfree(rq);
--
1.8.5.6
next reply other threads:[~2017-09-26 17:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-26 17:22 Lee Duncan [this message]
2017-09-26 18:24 ` [PATCH] scsi: ioctl reset should wait for IOs to complete Bart Van Assche
2017-09-27 6:58 ` Hannes Reinecke
2017-09-27 16:00 ` Lee Duncan
2017-09-26 18:33 ` James Bottomley
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=20170926172235.29530-1-lduncan@suse.com \
--to=lduncan@suse.com \
--cc=hare@suse.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--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