All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] SCSI: fix scsi disk hotpulg/hotunplug race
@ 2010-12-06 13:30 Joe Jin
  0 siblings, 0 replies; only message in thread
From: Joe Jin @ 2010-12-06 13:30 UTC (permalink / raw)
  To: James E.J. Bottomley
  Cc: linux-scsi, linux-kernel, greg.marsden, guru.anbalagane, joe.jin

Hi,

Trigger scsi scan when plug new disk, device also support disk
hotplug and auto scan disk, it may allocate scsi_target for same
target more then one by call scsi_alloc_target(),  this caused by
the race of __scsi_add_device() and scsi_scan_host_selected().

Cc: "James E.J. Bottomley" <James.Bottomley@suse.de>
Signed-off-by: Joe Jin <joe.jin@oracle.com>

---
 scsi_scan.c |    8 +++++---

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 087821f..2429771 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1508,12 +1508,14 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
 	if (strncmp(scsi_scan_type, "none", 4) == 0)
 		return ERR_PTR(-ENODEV);
 
+	mutex_lock(&shost->scan_mutex);
 	starget = scsi_alloc_target(parent, channel, id);
-	if (!starget)
+	if (!starget) {
+		mutex_unlock(&shost->scan_mutex);
 		return ERR_PTR(-ENOMEM);
+	}
 	scsi_autopm_get_target(starget);
 
-	mutex_lock(&shost->scan_mutex);
 	if (!shost->async_scan)
 		scsi_complete_async_scans();
 
@@ -1521,10 +1523,10 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
 		scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
 		scsi_autopm_put_host(shost);
 	}
-	mutex_unlock(&shost->scan_mutex);
 	scsi_autopm_put_target(starget);
 	scsi_target_reap(starget);
 	put_device(&starget->dev);
+	mutex_unlock(&shost->scan_mutex);
 
 	return sdev;
 }

-- 
Oracle <http://www.oracle.com>
Joe Jin | Team Leader, Software Development | +8610.8278.6295
ORACLE | Linux and Virtualization
Incubator Building 2-A ZPark | Beijing China, 100094



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-06 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-06 13:30 [PATCH 1/1] SCSI: fix scsi disk hotpulg/hotunplug race Joe Jin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.