From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@lst.de>,
Johannes Thumshirn <jthumshirn@suse.de>,
Dan Williams <dan.j.williams@intel.com>,
Sebastian Herbszt <herbszt@gmx.de>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH] Separate target visibility from reaped state information
Date: Tue, 02 Feb 2016 16:43:21 -0800 [thread overview]
Message-ID: <1454460201.2363.3.camel@HansenPartnership.com> (raw)
In-Reply-To: <56B0F58B.60708@sandisk.com>
On Tue, 2016-02-02 at 10:29 -0800, Bart Van Assche wrote:
> On 02/02/2016 03:46 AM, James Bottomley wrote:
> > diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> > index 4f18a85..00bc721 100644
> > --- a/drivers/scsi/scsi_sysfs.c
> > +++ b/drivers/scsi/scsi_sysfs.c
> > @@ -1272,16 +1272,18 @@ static void __scsi_remove_target(struct
> > scsi_target *starget)
> > void scsi_remove_target(struct device *dev)
> > {
> > struct Scsi_Host *shost = dev_to_shost(dev->parent);
> > - struct scsi_target *starget;
> > + struct scsi_target *starget, *last_target = NULL;
> > unsigned long flags;
> >
> > restart:
> > spin_lock_irqsave(shost->host_lock, flags);
> > list_for_each_entry(starget, &shost->__targets, siblings) {
> > - if (starget->state == STARGET_DEL)
> > + if (starget->state == STARGET_DEL ||
> > + starget == last_target)
> > continue;
> > if (starget->dev.parent == dev || &starget->dev ==
> > dev) {
> > kref_get(&starget->reap_ref);
> > + last_target = starget;
> > spin_unlock_irqrestore(shost->host_lock,
> > flags);
> > __scsi_remove_target(starget);
> > scsi_target_reap(starget);
>
> Hello James,
>
> Do you think it is a robust approach to store the pointer to the last
> removed target in the last_target variable ?
Well, yes, I think it will work, if that's what you mean.
> What if e.g. scsi_target_reap() frees the memory the last_target
> pointer points at and another thread reallocates a scsi_target data
> structure ? Can that last data structure have the same address as the
> contents of the last_target variable ?
Yes, but it doesn't matter, does it? Add/Remove has always (and will
always) be racy. Under current conditions you can still add to the
target after the list_for_each terminates and have scsi_remove_target()
return with attached devices. The only way to close the race is
basically to forbid scanning as we shut down the host and wait for all
in-progress scans before starting the final removals.
James
next prev parent reply other threads:[~2016-02-03 0:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 16:51 [PATCH] Separate target visibility from reaped state information Bart Van Assche
2016-01-18 8:55 ` Johannes Thumshirn
2016-01-20 0:30 ` Martin K. Petersen
2016-01-20 1:03 ` James Bottomley
2016-01-31 17:54 ` Sebastian Herbszt
2016-02-02 1:11 ` Martin K. Petersen
2016-02-02 9:03 ` Johannes Thumshirn
2016-02-03 17:17 ` Christoph Hellwig
2016-02-03 17:54 ` James Bottomley
2016-02-03 21:37 ` *** GMX Spamverdacht *** " Sebastian Herbszt
2016-02-07 22:48 ` Sebastian Herbszt
2016-02-02 3:43 ` Bart Van Assche
2016-02-02 11:46 ` James Bottomley
2016-02-02 18:29 ` Bart Van Assche
2016-02-03 0:43 ` James Bottomley [this message]
2016-02-03 1:17 ` Bart Van Assche
2016-02-03 2:01 ` James Bottomley
2016-02-03 22:38 ` Sebastian Herbszt
2016-02-03 22:55 ` James Bottomley
2016-02-03 23:28 ` Sebastian Herbszt
2016-02-07 22:56 ` Sebastian Herbszt
2016-02-10 14:05 ` Johannes Thumshirn
2016-02-10 15:34 ` James Bottomley
2016-02-10 16:06 ` Johannes Thumshirn
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=1454460201.2363.3.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=bart.vanassche@sandisk.com \
--cc=dan.j.williams@intel.com \
--cc=hch@lst.de \
--cc=herbszt@gmx.de \
--cc=jthumshirn@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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 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.