diff mbox

[v4] scsi/sd: release scan_mutex during sync_cache and start_stop

Message ID 20170209010116.362206-1-songliubraving@fb.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Song Liu Feb. 9, 2017, 1:01 a.m. UTC
When a device is deleted through sysfs handle "delete", the code
locks shost->scan_mutex. If multiple devices are deleted at the
same time, these deletes will be handled in series.

On the other hand, sd_shutdown() sometimes issues long latency
commands: sync cache and start_stop. It is not necessary for these
commands to run in series.

To reduce latency of parallel "delete" requests, this patch unlock
shost->scan_mutex before calling sd_shutdown(), relock the mutex
afterwards.

Fixed bug from previous version.

Reported-by: kernel test robot <fengguang.wu@intel.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>
---
 drivers/scsi/sd.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 9e0783b..61ea308 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3211,9 +3211,13 @@  static int sd_probe(struct device *dev)
 static int sd_remove(struct device *dev)
 {
 	struct scsi_disk *sdkp;
+	struct scsi_device *sdev;
+	struct Scsi_Host *shost;
 	dev_t devt;
 
 	sdkp = dev_get_drvdata(dev);
+	sdev = sdkp->device;
+	shost = sdev->host;
 	devt = disk_devt(sdkp->disk);
 	scsi_autopm_get_device(sdkp->device);
 
@@ -3221,7 +3225,9 @@  static int sd_remove(struct device *dev)
 	async_synchronize_full_domain(&scsi_sd_probe_domain);
 	device_del(&sdkp->dev);
 	del_gendisk(sdkp->disk);
+	mutex_unlock(&shost->scan_mutex);
 	sd_shutdown(dev);
+	mutex_lock(&shost->scan_mutex);
 
 	sd_zbc_remove(sdkp);