From: Chandra Seetharaman Subject: [PATCH 3/3] scsi_dh: Workaround a race condition in module insertion 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 Signed-off-by: Peter Jones Signed-off-by: Mike Snitzer --- drivers/scsi/device_handler/scsi_dh.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c =================================================================== --- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c +++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c @@ -248,7 +248,18 @@ 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)) { + /* + * Catch a device during BUS_NOTIFY_BOUND_DRIVER + * if it was missed by this module, because it wasn't + * yet loaded, during BUS_NOTIFY_ADD_DEVICE. + * Skip a device that was already configured via + * BUS_NOTIFY_ADD_DEVICE. + */ + if (sdev->scsi_dh_data) + return 0; + err = device_create_file(dev, &scsi_dh_state_attr); /* don't care about err */ devinfo = device_handler_match(NULL, sdev);