All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <jbottomley@parallels.com>
To: "hch@lst.de" <hch@lst.de>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>
Subject: Re: [PATCH 3/3] scsi: proper state checking and module refcount handling in scsi_device_get
Date: Thu, 29 Jan 2015 14:46:48 +0000	[thread overview]
Message-ID: <1422542848.2091.4.camel@parallels.com> (raw)
In-Reply-To: <1422486056-11591-3-git-send-email-hch@lst.de>

On Thu, 2015-01-29 at 00:00 +0100, Christoph Hellwig wrote:
> This effectively reverts commits 85b6c7 ("[SCSI] sd: fix cache flushing on
> module removal (and individual device removal)" and dc4515ea ("scsi: always
> increment reference count").
> 
> We now never call scsi_device_get from the shutdown path, and the fact
> that we started grabbing reference there in commit 85b6c7 turned out
> turned out to create more problems than it solves, and required
> workarounds for workarounds for workarounds. Move back to properly checking
> the device state and carefully handle module refcounting.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/scsi/scsi.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index 9b38299..95f0293 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -982,15 +982,18 @@ EXPORT_SYMBOL(scsi_report_opcode);
>   */
>  int scsi_device_get(struct scsi_device *sdev)
>  {
> -	if (sdev->sdev_state == SDEV_DEL)
> -		return -ENXIO;
> +	if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL)
> +		goto fail;
>  	if (!get_device(&sdev->sdev_gendev))
> -		return -ENXIO;
> -	/* We can fail try_module_get if we're doing SCSI operations
> -	 * from module exit (like cache flush) */
> -	__module_get(sdev->host->hostt->module);
> -
> +		goto fail;
> +	if (!try_module_get(sdev->host->hostt->module))
> +		goto fail_put_device;
>  	return 0;
> +
> +fail_put_device:
> +	put_device(&sdev->sdev_gendev);
> +fail:
> +	return -ENXIO;
>  }
>  EXPORT_SYMBOL(scsi_device_get);

If we can get away with this, I'm all for this approach.  However, you
need to document in a comment or above the function that it may not be
called in module exit functions and why.

Other than the comment issue, the series looks good,

Thanks,

James


  reply	other threads:[~2015-01-29 14:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28 23:00 [PATCH 1/3] scsi: serialize ->rescan against ->remove Christoph Hellwig
2015-01-28 23:00 ` [PATCH 2/3] sd: don't grab a device references from driver methods Christoph Hellwig
2015-01-28 23:00 ` [PATCH 3/3] scsi: proper state checking and module refcount handling in scsi_device_get Christoph Hellwig
2015-01-29 14:46   ` James Bottomley [this message]
2015-01-29 20:09 ` [PATCH 1/3] scsi: serialize ->rescan against ->remove Alan Stern
2015-01-29 23:11 ` Paolo Bonzini
2015-01-30  1:08   ` Fam Zheng
2015-01-30  9:46     ` Paolo Bonzini
2015-02-02 12:59       ` Christoph Hellwig
2015-02-02 13:14         ` Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2015-02-02 13:01 Christoph Hellwig
2015-02-02 13:01 ` [PATCH 3/3] scsi: proper state checking and module refcount handling in scsi_device_get Christoph Hellwig
2015-03-05 13:36   ` Paolo Bonzini
2015-03-10 16:22   ` Hannes Reinecke
2015-04-29  1:17   ` Akinobu Mita
2015-04-29 13:27     ` Christoph Hellwig

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=1422542848.2091.4.camel@parallels.com \
    --to=jbottomley@parallels.com \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.