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...@intel.com>
Signed-off-by: Song Liu <songliubrav...@fb.com>
Cc: Christoph Hellwig <h...@lst.de>
Cc: Bart Van Assche <bart.vanass...@sandisk.com>
---
 drivers/scsi/sd.c | 6 ++++++
 1 file changed, 6 insertions(+)

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);
 
-- 
2.9.3

Reply via email to