public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Mike Anderson <andmike@us.ibm.com>,
	Alberto Bertogli <albertogli@telpin.com.ar>,
	USB development list <linux-usb-devel@lists.sourceforge.net>,
	SCSI development list <linux-scsi@vger.kernel.org>
Subject: Re: [linux-usb-devel] BUG when removing USB flash drive
Date: 14 May 2004 15:04:29 -0500	[thread overview]
Message-ID: <1084565070.1841.373.camel@mulgrave> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0405141514470.20244-100000@ida.rowland.org>

On Fri, 2004-05-14 at 14:33, Alan Stern wrote:
> usb-storage checks the state of its kernel thread after calling
> scsi_remove_host(), while preparing to kill the thread.  This can only
> be done while the thread is idle, not processing any queued commands or
> error handler requests.  The BUG in Alberto's log was triggered because
> the thread was not idle.  Unfortunately the log doesn't say whether it was
> executing a queued command or an error handler request at the time.

The idea behind scsi_remove_host() was that it was going to be called
from the module_exit() routine.  This means that the reference count on
the LLD has already dropped to zero and it's safe for removal.

If you call scsi_remove_host() outside of the module_exit() code then
what it does is remove all hosts from visibility (and makes it
impossible to open or do anything with them), but it cannot revoke
outstanding references (which may continue to use the device).  The
mid-layer takes the devices through CANCEL and then DEL.  When
scsi_remove_host() returns, you are guaranteed (barring any state model
cockups) that the devices on the LLD with outstanding references are all
in the DEL state.  It will also block the device from above (no commands
will be sent down).  Any currently outstanding commands will be errored
from the mid-layer; however, it will do nothing about outstanding
commands in the LLD, you have to deal with them yourself.

The way this is supposed to work is that when you get a disconnection,
you start refusing commands (and you also discard any active ones). 
Then you call scsi_remove_host().  We discard all current commands

So, if the usb storage LLD isn't discarding the commands, then they may
be active.

James



  reply	other threads:[~2004-05-14 20:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040514004132.GA10537@telpin.com.ar>
2004-05-14  3:11 ` [linux-usb-devel] BUG when removing USB flash drive Alan Stern
2004-05-14  5:36   ` Mike Anderson
2004-05-14 15:12     ` Alan Stern
2004-05-14 16:59       ` Mike Anderson
2004-05-14 19:33         ` Alan Stern
2004-05-14 20:04           ` James Bottomley [this message]
2004-05-14 21:13             ` Alan Stern
2004-05-14 21:55               ` Alberto Bertogli
2004-05-15 19:56                 ` 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=1084565070.1841.373.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=albertogli@telpin.com.ar \
    --cc=andmike@us.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --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