[PATCH 2/6] scsi_dh : increment the refcounts while calling activate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hold the refcounts for device and scsi_dh_data while calling handler's activate. This will make sure that devices and scsi_dh_data are not removed while activate is still in progress. Make sure to call put_device and kref_put in the handler after activate is complete.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
--- linux-2.6.35-rc5/drivers/scsi/device_handler/scsi_dh.c.orig	2010-07-23 05:40:11.000000000 -0500
+++ linux-2.6.35-rc5/drivers/scsi/device_handler/scsi_dh.c	2010-07-23 05:48:53.000000000 -0500
@@ -228,7 +228,8 @@ store_dh_state(struct device *dev, struc
 			 * Activate a device handler
 			 */
 			if (scsi_dh->activate)
-				err = scsi_dh->activate(sdev, NULL, NULL);
+				err = scsi_dh_activate(sdev->request_queue,
+							NULL, NULL);
 			else
 				err = 0;
 		}
@@ -431,6 +432,8 @@ EXPORT_SYMBOL_GPL(scsi_unregister_device
  *         do not hold the lock in the caller which may be needed in fn.
  * @data - data passed to the function fn upon completion.
  *
+ * NOTE  - Remember to call put_device and kref_put in the handler after
+ *         calling the callback function. Otherwise things could become messy.
  */
 int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)
 {
@@ -450,9 +453,12 @@ int scsi_dh_activate(struct request_queu
 	if (err)
 		return err;
 
-	if (scsi_dh->activate)
+	if (scsi_dh->activate) {
+		kref_get(&sdev->scsi_dh_data->kref);
 		err = scsi_dh->activate(sdev, fn, data);
-	put_device(&sdev->sdev_gendev);
+	} else
+		put_device(&sdev->sdev_gendev);
+
 	return err;
 }
 EXPORT_SYMBOL_GPL(scsi_dh_activate);



--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux