Skip to contentSkip to conversation

scsi_set_device_offline lock fix

PATCH New Mike Anderson 1 participant 1 message Feb 26, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_set_device_offline lock fix

Patrick pointed out that I could get into a ABBA issue with holding list_lock while calling scsi_eh_scmd_add which takes host_lock. A call to scsi_prep_fn already holds the queue_lock and then makes a call to scsi_get_command which takes list_lock.

-andmike
--
Michael Anderson
[email protected]

=====
name: 00_scsi_set_device_offline.diff
version: 2003-02-26.15:18:19-0800
against: scsi-misc-2.5

 scsi.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

=====

drivers/scsi/scsi.c +9 -6
@@ -1308,7 +1308,8 @@
 void scsi_set_device_offline(struct scsi_device *sdev)
 {
 	struct scsi_cmnd *scmd;
-	int	cmds_active = 0;
+	LIST_HEAD(active_list);
+	struct list_head *lh, *lh_sf;
 	unsigned long flags;
 
 	sdev->online = FALSE;
@@ -1324,15 +1325,17 @@
 			if (!scsi_delete_timer(scmd)) {
 				continue;
 			}
-
-			++cmds_active;
-
-			scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD);
+			list_add_tail(&scmd->eh_entry, &active_list);
 		}
 	}
 	spin_unlock_irqrestore(&sdev->list_lock, flags);
 
-	if (!cmds_active) {
+	if (!list_empty(&active_list)) {
+		list_for_each_safe(lh, lh_sf, &active_list) {
+			scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
+			scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD);
+		}
+	} else {
 		/* FIXME: Send online state change hotplug event */
 	}
 }