Skip to content

Commit 210588c

Browse files
Johannes Thumshirngregkh
authored andcommitted
scsi: Add intermediate STARGET_REMOVE state to scsi_target_state
commit f05795d3d771f30a7bdc3a138bf714b06d42aa95 upstream. Add intermediate STARGET_REMOVE state to scsi_target_state to avoid running into the BUG_ON() in scsi_target_reap(). The STARGET_REMOVE state is only valid in the path from scsi_remove_target() to scsi_target_destroy() indicating this target is going to be removed. This re-fixes the problem introduced in commits bc3f02a ("[SCSI] scsi_remove_target: fix softlockup regression on hot remove") and 4099819 ("scsi: restart list search after unlock in scsi_remove_target") in a more comprehensive way. [mkp: Included James' fix for scsi_target_destroy()] Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Fixes: 4099819 Reported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Tested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Reviewed-by: Ewan D. Milne <emilne@redhat.com> Reviewed-by: Hannes Reinecke <hare@suse.com> Reviewed-by: James Bottomley <jejb@linux.vnet.ibm.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e92041 commit 210588c

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/scsi/scsi_scan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static void scsi_target_destroy(struct scsi_target *starget)
314314
struct Scsi_Host *shost = dev_to_shost(dev->parent);
315315
unsigned long flags;
316316

317+
BUG_ON(starget->state == STARGET_DEL);
317318
starget->state = STARGET_DEL;
318319
transport_destroy_device(dev);
319320
spin_lock_irqsave(shost->host_lock, flags);

drivers/scsi/scsi_sysfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,11 +1199,13 @@ void scsi_remove_target(struct device *dev)
11991199
spin_lock_irqsave(shost->host_lock, flags);
12001200
list_for_each_entry(starget, &shost->__targets, siblings) {
12011201
if (starget->state == STARGET_DEL ||
1202+
starget->state == STARGET_REMOVE ||
12021203
starget == last_target)
12031204
continue;
12041205
if (starget->dev.parent == dev || &starget->dev == dev) {
12051206
kref_get(&starget->reap_ref);
12061207
last_target = starget;
1208+
starget->state = STARGET_REMOVE;
12071209
spin_unlock_irqrestore(shost->host_lock, flags);
12081210
__scsi_remove_target(starget);
12091211
scsi_target_reap(starget);

include/scsi/scsi_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ scmd_printk(const char *, const struct scsi_cmnd *, const char *, ...);
239239
enum scsi_target_state {
240240
STARGET_CREATED = 1,
241241
STARGET_RUNNING,
242+
STARGET_REMOVE,
242243
STARGET_DEL,
243244
};
244245

0 commit comments

Comments
 (0)