@@ -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);
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(+)