All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	Israel Rukshin <israelr@mellanox.com>,
	Max Gurtovoy <maxg@mellanox.com>,
	Benjamin Block <bblock@linux.vnet.ibm.com>
Subject: [PATCH v2 06/12] Make __scsi_remove_device go straight from BLOCKED to DEL
Date: Thu, 1 Jun 2017 16:27:05 -0700	[thread overview]
Message-ID: <20170601232711.29062-7-bart.vanassche@sandisk.com> (raw)
In-Reply-To: <20170601232711.29062-1-bart.vanassche@sandisk.com>

If a device is blocked, make __scsi_remove_device() cause it to
transition to the DEL state. This means that all the commands
issued in .shutdown() will error in the mid-layer, thus making
the removal proceed without being stopped.

This patch is a slightly modified version of a patch from James
Bottomley. This patch avoids that the following lockup occurs:

Call Trace:
 schedule+0x35/0x80
 schedule_timeout+0x237/0x2d0
 io_schedule_timeout+0xa6/0x110
 wait_for_completion_io+0xa3/0x110
 blk_execute_rq+0xdf/0x120
 scsi_execute+0xce/0x150 [scsi_mod]
 scsi_execute_req_flags+0x8f/0xf0 [scsi_mod]
 sd_sync_cache+0xa9/0x190 [sd_mod]
 sd_shutdown+0x6a/0x100 [sd_mod]
 sd_remove+0x64/0xc0 [sd_mod]
 __device_release_driver+0x8d/0x120
 device_release_driver+0x1e/0x30
 bus_remove_device+0xf9/0x170
 device_del+0x127/0x240
 __scsi_remove_device+0xc1/0xd0 [scsi_mod]
 scsi_forget_host+0x57/0x60 [scsi_mod]
 scsi_remove_host+0x72/0x110 [scsi_mod]
 srp_remove_work+0x8b/0x200 [ib_srp]

Reported-by: Israel Rukshin <israelr@mellanox.com>
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Israel Rukshin <israelr@mellanox.com>
Cc: Max Gurtovoy <maxg@mellanox.com>
Cc: Benjamin Block <bblock@linux.vnet.ibm.com>
---
 drivers/scsi/scsi_lib.c   |  2 +-
 drivers/scsi/scsi_sysfs.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 6a58a124714f..8665eccd2fc8 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2624,7 +2624,6 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
 		case SDEV_QUIESCE:
 		case SDEV_OFFLINE:
 		case SDEV_TRANSPORT_OFFLINE:
-		case SDEV_BLOCK:
 			break;
 		default:
 			goto illegal;
@@ -2638,6 +2637,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
 		case SDEV_OFFLINE:
 		case SDEV_TRANSPORT_OFFLINE:
 		case SDEV_CANCEL:
+		case SDEV_BLOCK:
 		case SDEV_CREATED_BLOCK:
 			break;
 		default:
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index a91537a3abbf..1f243ac16010 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1290,7 +1290,20 @@ void __scsi_remove_device(struct scsi_device *sdev)
 		 * wait until it has finished before changing the device state.
 		 */
 		mutex_lock(&sdev->state_mutex);
+		/*
+		 * If blocked, we go straight to DEL and restart the queue so
+		 * any commands issued during driver shutdown (like sync
+		 * cache) are errored immediately.
+		 */
 		res = scsi_device_set_state(sdev, SDEV_CANCEL);
+		if (res != 0) {
+			res = scsi_device_set_state(sdev, SDEV_DEL);
+			if (res == 0) {
+				scsi_start_queue(sdev);
+				sdev_printk(KERN_DEBUG, sdev,
+				    "Changed state from BLOCKED to DEL\n");
+			}
+		}
 		mutex_unlock(&sdev->state_mutex);
 
 		if (res != 0)
-- 
2.12.2

  parent reply	other threads:[~2017-06-01 23:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 23:26 [PATCH v2 00/12] SCSI patches for kernel v4.13 Bart Van Assche
2017-06-01 23:27 ` [PATCH v2 01/12] Avoid that scsi_exit_rq() triggers a use-after-free Bart Van Assche
2017-06-01 23:27   ` Bart Van Assche
2017-06-02  7:16   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 02/12] Split scsi_internal_device_block() Bart Van Assche
2017-06-02  7:16   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 03/12] Create two versions of scsi_internal_device_unblock() Bart Van Assche
2017-06-02  7:16   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 04/12] Protect SCSI device state changes with a mutex Bart Van Assche
2017-06-02  7:17   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 05/12] Introduce scsi_start_queue() Bart Van Assche
2017-06-02  7:17   ` Christoph Hellwig
2017-06-01 23:27 ` Bart Van Assche [this message]
2017-06-02  7:18   ` [PATCH v2 06/12] Make __scsi_remove_device go straight from BLOCKED to DEL Christoph Hellwig
2017-06-02 20:58     ` Bart Van Assche
2017-06-01 23:27 ` [PATCH v2 07/12] Only add commands to the device command list if required by the LLD Bart Van Assche
2017-06-01 23:27 ` [PATCH v2 08/12] Introduce scsi_mq_sgl_size() Bart Van Assche
2017-06-02  7:18   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 09/12] Make scsi_mq_prep_fn() call scsi_init_command() Bart Van Assche
2017-06-02  7:22   ` Christoph Hellwig
2017-06-02 17:49     ` Bart Van Assche
2017-06-01 23:27 ` [PATCH v2 10/12] snic: Remove code that zeroes driver-private command data Bart Van Assche
2017-06-02  7:22   ` Christoph Hellwig
2017-06-01 23:27 ` [PATCH v2 11/12] virtio: " Bart Van Assche
2017-06-02  7:23   ` Christoph Hellwig
2017-06-02 21:01     ` Bart Van Assche
2017-06-01 23:27 ` [PATCH v2 12/12] xen/scsifront: " Bart Van Assche
2017-06-01 23:27 ` Bart Van Assche
2017-06-02  7:23   ` Christoph Hellwig
2017-06-02  7:23   ` Christoph Hellwig
2017-06-02 21:08 ` [PATCH v2 00/12] SCSI patches for kernel v4.13 Martin K. Petersen
2017-06-02 21:10   ` Bart Van Assche

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=20170601232711.29062-7-bart.vanassche@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=bblock@linux.vnet.ibm.com \
    --cc=hch@lst.de \
    --cc=israelr@mellanox.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=maxg@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.