public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH v3] scsi/sd: release scan_mutex during sync_cache and start_stop
Date: Wed, 8 Feb 2017 22:56:10 +0000	[thread overview]
Message-ID: <87413FD9-0B96-4902-B458-034AF7AFDB7B@fb.com> (raw)
In-Reply-To: <20170208225353.82334-1-songliubraving@fb.com>

> On Feb 8, 2017, at 2:53 PM, Song Liu <songliubraving@fb.com> wrote:
> 
> 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 long latency commands and relock the mutex
> after the command.
> 
> Fixed bug from previous version.
> 
> Reported-by: kernel test robot <fengguang.wu@intel.com>
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
> drivers/scsi/sd.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 9e0783b..14c5815 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -3304,6 +3304,9 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
> static void sd_shutdown(struct device *dev)
> {
> 	struct scsi_disk *sdkp = dev_get_drvdata(dev);
> +	struct scsi_device *sdev;
> +	struct Scsi_Host *shost;
> +	int try_lock_scan_mutex;
> 
> 	if (!sdkp)
> 		return;         /* this can happen */
> @@ -3311,15 +3314,26 @@ static void sd_shutdown(struct device *dev)
> 	if (pm_runtime_suspended(dev))
> 		return;
> 
> +	sdev = sdkp->device;
> +	shost = sdev->host;
> +	try_lock_scan_mutex = mutex_trylock(&shost->scan_mutex);
> +
> 	if (sdkp->WCE && sdkp->media_present) {
> +		mutex_unlock(&shost->scan_mutex);
> 		sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
> 		sd_sync_cache(sdkp);
> +		mutex_lock(&shost->scan_mutex);
> 	}
> 
> 	if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) {
> +		mutex_unlock(&shost->scan_mutex);
> 		sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
> 		sd_start_stop_device(sdkp, 0);
> +		mutex_lock(&shost->scan_mutex);
> 	}
> +
> +	if (try_lock_scan_mutex)
> +		mutex_unlock(&shost->scan_mutex);
> }
> 
> static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)
> -- 
> 2.9.3
> 

Forgot to CC Christoph

  reply	other threads:[~2017-02-08 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-08 22:53 [PATCH v3] scsi/sd: release scan_mutex during sync_cache and start_stop Song Liu
2017-02-08 22:56 ` Song Liu [this message]
2017-02-08 22:58 ` Bart Van Assche
2017-02-08 23:03   ` Song Liu

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=87413FD9-0B96-4902-B458-034AF7AFDB7B@fb.com \
    --to=songliubraving@fb.com \
    --cc=hch@infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox