Message ID | 20170601232711.29062-7-bart.vanassche@sandisk.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Thu, Jun 01, 2017 at 04:27:05PM -0700, Bart Van Assche wrote: > 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: Do we really need the printk for this case? And if we do we should probably rate limit it.
On Fri, 2017-06-02 at 09:18 +0200, Christoph Hellwig wrote: > On Thu, Jun 01, 2017 at 04:27:05PM -0700, Bart Van Assche wrote: > > 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: > > Do we really need the printk for this case? And if we do we should > probably rate limit it. Hello Christoph, The printk statement was useful during debugging to confirm that the code path with the printk was hit. I will remove the printk. Bart.
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)