From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>,
Chandra Seetharaman <sekharan@us.ibm.com>,
Mike Christie <michaelc@cs.wisc.edu>
Cc: Sean Stewart <Sean.Stewart@netapp.com>,
Bart Van Assche <bvanassche@acm.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] scsi_dh: get module reference outside of device handler
Date: Mon, 20 Oct 2014 08:01:20 +0200 [thread overview]
Message-ID: <5444A530.3080204@suse.de> (raw)
In-Reply-To: <1413734404-1426-2-git-send-email-hch@lst.de>
On 10/19/2014 05:59 PM, Christoph Hellwig wrote:
> We need to grab a reference to the module before calling the attach
> routines to avoid a small race vs module removal. It also cleans up
> the code significantly as a side effect.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/scsi/device_handler/scsi_dh.c | 31 ++++++++++++++++++++---------
> drivers/scsi/device_handler/scsi_dh_alua.c | 4 ----
> drivers/scsi/device_handler/scsi_dh_emc.c | 4 ----
> drivers/scsi/device_handler/scsi_dh_hp_sw.c | 4 ----
> drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ----
> 5 files changed, 22 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
> index 33e422e..1a8dbf3 100644
> --- a/drivers/scsi/device_handler/scsi_dh.c
> +++ b/drivers/scsi/device_handler/scsi_dh.c
> @@ -102,23 +102,36 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
>
> if (sdev->scsi_dh_data) {
> if (sdev->scsi_dh_data->scsi_dh != scsi_dh)
> - err = -EBUSY;
> - else
> - kref_get(&sdev->scsi_dh_data->kref);
> - } else if (scsi_dh->attach) {
> + return -EBUSY;
> +
> + kref_get(&sdev->scsi_dh_data->kref);
> + return 0;
> + }
> +
> + if (scsi_dh->attach) {
> + if (!try_module_get(scsi_dh->module))
> + return -EINVAL;
> +
> err = scsi_dh->attach(sdev);
> - if (!err) {
> - kref_init(&sdev->scsi_dh_data->kref);
> - sdev->scsi_dh_data->sdev = sdev;
> + if (err) {
> + module_put(scsi_dh->module);
> + return err;
> }
> +
> + kref_init(&sdev->scsi_dh_data->kref);
> + sdev->scsi_dh_data->sdev = sdev;
> }
> return err;
> }
>
> static void __detach_handler (struct kref *kref)
> {
> - struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref);
> - scsi_dh_data->scsi_dh->detach(scsi_dh_data->sdev);
> + struct scsi_dh_data *scsi_dh_data =
> + container_of(kref, struct scsi_dh_data, kref);
> + struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh;
> +
> + scsi_dh->detach(scsi_dh_data->sdev);
> + module_put(scsi_dh->module);
> }
>
> /*
Is it guaranteed that you cannot call ->attach() for devices which
already have a device_handler attached?
You've skipped the case
scsi_dh != sdev->scsi_dh_data->scsi_dh
IE someone called 'attach()' on a device which already has a
different device_handler attached to it.
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@suse.de +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
next prev parent reply other threads:[~2014-10-20 6:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-19 15:59 device handler cleanups Christoph Hellwig
2014-10-19 15:59 ` [PATCH 1/6] scsi_dh: get module reference outside of device handler Christoph Hellwig
2014-10-20 6:01 ` Hannes Reinecke [this message]
2014-10-20 6:53 ` Christoph Hellwig
2014-10-20 8:06 ` Hannes Reinecke
2014-10-19 16:00 ` [PATCH 2/6] scsi: use container_of to get at device handler private data Christoph Hellwig
2014-10-20 6:02 ` Hannes Reinecke
2014-10-19 16:00 ` [PATCH 3/6] scsi: remove struct scsi_dh_devlist Christoph Hellwig
2014-10-20 6:03 ` Hannes Reinecke
2014-10-19 16:00 ` [PATCH 4/6] scsi: device handlers must have attach and detach methods Christoph Hellwig
2014-10-20 6:04 ` Hannes Reinecke
2014-10-19 16:00 ` [PATCH 5/6] scsi_dh_hp_sw: fix return value on failed allocation Christoph Hellwig
2014-10-20 6:04 ` Hannes Reinecke
2014-10-19 16:00 ` [PATCH 6/6] scsi: handle more device handler setup/teardown in common code Christoph Hellwig
2014-10-20 6:06 ` Hannes Reinecke
2014-10-28 17:53 ` Mike Christie
2014-10-30 9:00 ` 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=5444A530.3080204@suse.de \
--to=hare@suse.de \
--cc=Sean.Stewart@netapp.com \
--cc=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=sekharan@us.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).