public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Anderson <andmike@us.ibm.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: James Bottomley <James.Bottomley@SteelEye.com>,
	SCSI development list <linux-scsi@vger.kernel.org>
Subject: Re: Questions about scsi_target_reap and starget/sdev lifecyle
Date: Thu, 16 Jun 2005 00:31:27 -0700	[thread overview]
Message-ID: <20050616073127.GA20051@us.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0506152205000.5061-100000@netrider.rowland.org>

Alan Stern [stern@rowland.harvard.edu] wrote:
> On Wed, 15 Jun 2005, James Bottomley wrote:
> 
> > On Wed, 2005-06-15 at 17:11 -0400, Alan Stern wrote:
> > > This means that scsi_target_reap can be called and the __targets list 
> > > changed essentially at any time (subject only to the host_lock).  Hence it 
> > > is impossible for scsi_forget_host to iterate through the list of targets 
> > > belonging to the host: While it is working to remove one target, the next 
> > > target on the list (stored in the tmp variable) might be removed by 
> > > another thread.
> > 
> > It's no better nor worse than we already have.  As has been said many
> > times before, we need a proper host state model.
> > 
> > > In fact there doesn't seem to be any safe way to remove all the targets
> > > from a host.  And what's to prevent scsi_target_reap being called twice
> > > for the same target?
> > 
> > The usage, if you look at the code ... it's alloc/reap or inc
> > reap_ref/reap
> 
> Okay, I understand a little better now.
> 
> Would it hurt anything to change scsi_remove_host so that SHOST_DEL gets
> set at the start, before scsi_forget_host is called?  If that were done,
> then we could make every pathway that adds a device acquire the scan_mutex
> and fail if SHOST_DEL is already set.  Thus no devices would ever be added
> after forget_host had removed the existing ones, which can happen as
> things stand.
> 
> Furthermore, forget_host could be changed to loop over the __devices list
> instead of the __targets list.  The net effect would be the same: All the
> devices on the host would be removed and the targets would automatically
> get reaped by scsi_device_dev_release.  There wouldn't be any need to
> iterate over the targets at all.
> 
> As a final change, the new loop-over-devices in forget_host and the one in
> __scsi_remove_target should be made to skip over devices with SDEV_DEL
> already set, and each time they call scsi_remove_device the loops should
> restart from the beginning.  This will eliminate the problem of the tmp
> pointer being pulled out from under the code (even though it has 
> quadratic behavior).
> 
> Do these changes sound okay?
> 

I have something similar that I was testing since you mentioned the
problem the other day. Our build machine went down so I will need to wait
until tomorrow to get access to my patches for a post, if you have already
rolled a patch we can compare notes when I post.

What I did in the patch sequence was:
	1.) Recode the scsi_host state model to align with the device
	state model (i.e. added scsi_host_set_state function and
	associated changes).
	2.) Made shost cancel matched the scsi device state model and set
	this at the top of scsi_remove_host. Previous cancel code was not
	doing anything as the list was normally empty do to
	scsi_forget_host being called first. Also there where possible
	race conditions that you previously mentioned about canceling
	commands in this method.
	3.) Added choke point checks under the scan_mutex to determine if
	scanning is allowed (scsi_host_scan_allowed).
	4.) Added a target state model to match the scsi device state
	model.
	5.) I use the STGT_CANCEL and STGT_DEL states in scsi_forget_host
	to skip over entries in the list as I am no longer using the
	_safe version.
This looks like a good starting point with limited testing. I also need to
more states to the target state model as I only added a few that I needed
for the delete code.

Anyway sorry about the delay.

-andmike
--
Michael Anderson
andmike@us.ibm.com


  reply	other threads:[~2005-06-16  7:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-14 21:27 Questions about scsi_target_reap and starget/sdev lifecyle Alan Stern
2005-06-15  3:28 ` James Bottomley
2005-06-15 20:07   ` Alan Stern
2005-06-15 21:11   ` Alan Stern
2005-06-15 23:03     ` James Bottomley
2005-06-16  2:22       ` Alan Stern
2005-06-16  7:31         ` Mike Anderson [this message]
2005-06-16 13:57           ` James Bottomley
2005-06-17  2:01             ` Alan Stern
2005-06-18 20:14             ` Alan Stern
2005-06-20 15:52               ` Brian King
2005-06-20 16:35                 ` Alan Stern
2005-06-20 17:31                   ` Patrick Mansfield
2005-06-20 19:24                     ` Alan Stern
2005-06-21 17:12               ` Mike Anderson
2005-06-21 17:43                 ` Patrick Mansfield
2005-06-21 19:24                   ` Mike Anderson
2005-06-21 20:04                 ` Alan Stern
2005-06-21 20:10                   ` Christoph Hellwig
2005-06-21 20:33                     ` Alan Stern
2005-06-21 20:58                       ` Mike Anderson
2005-06-21 21:22                         ` Alan Stern
2005-06-22 13:44                         ` Luben Tuikov
2005-06-22 13:36                       ` Luben Tuikov
2005-06-22 15:12                         ` Alan Stern
2005-06-22 15:46                           ` Luben Tuikov
2005-06-22 16:16                             ` Alan Stern
2005-06-22 16:53                               ` Luben Tuikov
2005-06-21 21:08                   ` Mike Anderson
2005-06-21 21:37                     ` Alan Stern

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=20050616073127.GA20051@us.ibm.com \
    --to=andmike@us.ibm.com \
    --cc=James.Bottomley@SteelEye.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox