From: Bart Van Assche <bvanassche@acm.org>
To: Mike Christie <michaelc@cs.wisc.edu>
Cc: linux-scsi <linux-scsi@vger.kernel.org>,
Joe Lawrence <jdl1291@gmail.com>, Tejun Heo <tj@kernel.org>,
Chanho Min <chanho.min@lge.com>,
David Milburn <dmilburn@redhat.com>,
James Bottomley <jbottomley@parallels.com>,
Hannes Reinecke <hare@suse.de>
Subject: Re: [PATCH v11 3/9] Avoid calling __scsi_remove_device() twice
Date: Mon, 24 Jun 2013 08:29:52 +0200 [thread overview]
Message-ID: <51C7E760.2010504@acm.org> (raw)
In-Reply-To: <51C76A29.30309@cs.wisc.edu>
On 06/23/13 23:35, Mike Christie wrote:
> On 06/12/2013 07:52 AM, Bart Van Assche wrote:
>> SCSI devices are added to the shost->__devices list from inside
>> scsi_alloc_sdev(). If something goes wrong during LUN scanning,
>> e.g. a transport layer failure occurs, then __scsi_remove_device()
>> can get invoked by the LUN scanning code for a SCSI device in
>> state SDEV_CREATED_BLOCK or SDEV_BLOCKED. If this happens then
>> the SCSI device has not yet been added to sysfs (is_visible == 0).
>> Make sure that if this happens these devices are transitioned
>> into state SDEV_DEL. This avoids that __scsi_remove_device()
>> gets invoked a second time by scsi_forget_host().
>>
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>> Cc: James Bottomley <JBottomley@Parallels.com>
>> Cc: Mike Christie <michaelc@cs.wisc.edu>
>> Cc: Hannes Reinecke <hare@suse.de>
>> Cc: Tejun Heo <tj@kernel.org>
>> ---
>> drivers/scsi/scsi_lib.c | 2 ++
>> drivers/scsi/scsi_sysfs.c | 7 ++++---
>> 2 files changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
>> index 03d4165..d57b5e1 100644
>> --- a/drivers/scsi/scsi_lib.c
>> +++ b/drivers/scsi/scsi_lib.c
>> @@ -2175,6 +2175,8 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
>> case SDEV_OFFLINE:
>> case SDEV_TRANSPORT_OFFLINE:
>> case SDEV_CANCEL:
>> + case SDEV_BLOCK:
>> + case SDEV_CREATED_BLOCK:
>> break;
>> default:
>> goto illegal;
>> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
>> index 34f1b39..f869ef85 100644
>> --- a/drivers/scsi/scsi_sysfs.c
>> +++ b/drivers/scsi/scsi_sysfs.c
>> @@ -956,8 +956,9 @@ void __scsi_remove_device(struct scsi_device *sdev)
>> unsigned long flags;
>>
>> if (sdev->is_visible) {
>> - if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
>> - return;
>> + WARN(scsi_device_set_state(sdev, SDEV_CANCEL) != 0,
>> + "%s: unexpected state %d\n", dev_name(&sdev->sdev_gendev),
>> + sdev->sdev_state);
>>
>> bsg_unregister_queue(sdev->request_queue);
>> device_unregister(&sdev->sdev_dev);
>> @@ -971,7 +972,7 @@ void __scsi_remove_device(struct scsi_device *sdev)
>> * scsi_run_queue() invocations have finished before tearing down the
>> * device.
>> */
>> - scsi_device_set_state(sdev, SDEV_DEL);
>> + WARN_ON_ONCE(scsi_device_set_state(sdev, SDEV_DEL) != 0);
>> blk_cleanup_queue(sdev->request_queue);
>> cancel_work_sync(&sdev->requeue_work);
>
> The Addition to scsi_device_set_state looks ok. I was not sure why we
> need the new WARNs though. Do we still think there are other cases?
Hello Mike,
The new WARN statements helped me while testing and debugging this code.
These statements might also be helpful if anyone would ever add more
SCSI device states. I can leave these out if you want.
Bart.
next prev parent reply other threads:[~2013-06-24 6:29 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-12 12:48 [PATCH v11 0/9] More device removal fixes Bart Van Assche
2013-06-12 12:49 ` [PATCH v11 1/9] Fix race between starved list and device removal Bart Van Assche
2013-06-24 15:38 ` James Bottomley
2013-06-24 16:16 ` Bart Van Assche
2013-06-24 16:23 ` James Bottomley
2013-06-24 17:24 ` Mike Christie
2013-06-24 17:49 ` James Bottomley
2013-06-12 12:51 ` [PATCH v11 2/9] Remove get_device() / put_device() pair from scsi_request_fn() Bart Van Assche
2013-06-24 1:29 ` Mike Christie
2013-06-24 2:36 ` James Bottomley
2013-06-24 7:13 ` Bart Van Assche
2013-06-24 13:34 ` James Bottomley
2013-06-24 15:43 ` Bart Van Assche
2013-06-12 12:52 ` [PATCH v11 3/9] Avoid calling __scsi_remove_device() twice Bart Van Assche
2013-06-23 21:35 ` Mike Christie
2013-06-24 6:29 ` Bart Van Assche [this message]
2013-06-24 17:38 ` James Bottomley
2013-06-25 8:37 ` Bart Van Assche
2013-06-25 13:44 ` James Bottomley
2013-06-25 15:23 ` Bart Van Assche
2013-06-12 12:53 ` [PATCH v11 4/9] Disallow changing the device state via sysfs into "deleted" Bart Van Assche
2013-06-24 1:05 ` Mike Christie
2013-06-24 6:35 ` Bart Van Assche
2013-06-24 17:59 ` James Bottomley
2013-06-25 8:41 ` Bart Van Assche
2013-06-25 13:42 ` James Bottomley
2013-06-12 12:54 ` [PATCH v11 5/9] Avoid saving/restoring interrupt state inside scsi_remove_host() Bart Van Assche
2013-06-24 1:06 ` Mike Christie
2013-06-12 12:55 ` [PATCH v11 6/9] Make scsi_remove_host() wait until error handling finished Bart Van Assche
2013-06-24 1:15 ` Mike Christie
2013-06-24 6:49 ` Bart Van Assche
2013-06-24 19:19 ` James Bottomley
2013-06-24 20:04 ` Mike Christie
2013-06-24 22:27 ` James Bottomley
2013-06-25 2:26 ` Mike Christie
2013-06-25 2:56 ` Michael Christie
2013-06-25 9:01 ` Bart Van Assche
2013-06-25 13:45 ` James Bottomley
2013-06-25 15:31 ` Bart Van Assche
2013-06-25 16:13 ` Michael Christie
2013-06-25 17:40 ` James Bottomley
2013-06-25 17:47 ` Bart Van Assche
2014-01-30 19:46 ` Bart Van Assche
2014-01-31 5:58 ` James Bottomley
2014-01-31 7:52 ` Bart Van Assche
2013-06-25 11:13 ` Bart Van Assche
2013-06-12 12:56 ` PATCH v11 7/9] Avoid that scsi_device_set_state() triggers a race Bart Van Assche
2013-06-12 12:57 ` [PATCH v11 8/9] Save and restore host_scribble during error handling Bart Van Assche
2013-06-24 1:21 ` Mike Christie
2013-06-24 2:08 ` James Bottomley
2013-06-12 12:58 ` [PATCH v11 9/9] Avoid reenabling I/O after the transport became offline Bart Van Assche
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=51C7E760.2010504@acm.org \
--to=bvanassche@acm.org \
--cc=chanho.min@lge.com \
--cc=dmilburn@redhat.com \
--cc=hare@suse.de \
--cc=jbottomley@parallels.com \
--cc=jdl1291@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=tj@kernel.org \
/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).