[PATCH 3/3] scsi_dh: Workaround a race condition in module insertion

Chandra Seetharaman
2009-04-27T18:05:49Z

From: Chandra Seetharaman <sekharan@us.ibm.com>

scsi_dh module is getting inserted as soon as the first device is seen.
But, the first device is not seen by the module as we were past the
ADD_DEVICE handling in the module.

Catch the first device by handling BUS_NOTIFY_BOUND_DRIVER event,
and not handle that event for any of the future devices (as they would
have been handled by ADD_DEVICE event).

Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Peter Jones <pjones@redhat.com>

---
drivers/scsi/device_handler/scsi_dh.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

Index: linux-2.6.29/drivers/scsi/device_handler/scsi_dh.c
===================================================================
--- linux-2.6.29.orig/drivers/scsi/device_handler/scsi_dh.c
+++ linux-2.6.29/drivers/scsi/device_handler/scsi_dh.c
@@ -294,7 +294,16 @@ static int scsi_dh_notifier(struct notif

sdev = to_scsi_device(dev);

- if (action == BUS_NOTIFY_ADD_DEVICE) {
+ if ((action == BUS_NOTIFY_ADD_DEVICE) ||
+ (action == BUS_NOTIFY_BOUND_DRIVER)) {
+ /*
+ * This can happen if device was configured already
+ * with BUS_NOTIFY_ADD_DEVICE and we are called
+ * now with BUS_NOTIFY_BOUND_DRIVER
+ */
+ if (sdev->scsi_dh_data)
+ goto out;
+
devinfo = device_handler_match(NULL, sdev);
if (!devinfo)
goto out;