Add support in core code for delayed disk removal support. In this, the callback calls into the scsi_driver to do the necessary removal work.
The scsi_disk driver (sd) must ensure that the scsi_mpath_device does not go away while the delayed removal work is active, i.e. it must keep a reference. No reference to the scsi_disk multipath structures are kept outside that driver, so that driver needs to provide a scsi_driver.mpath_remove_head callback to do the necessary work. Signed-off-by: John Garry <[email protected]> --- drivers/scsi/scsi_multipath.c | 18 ++++++++++++++++++ include/scsi/scsi_driver.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c index e0670d353e59f..2806477e1137b 100644 --- a/drivers/scsi/scsi_multipath.c +++ b/drivers/scsi/scsi_multipath.c @@ -372,7 +372,25 @@ static int scsi_mpath_get_nr_active(struct mpath_device *mpath_device) return atomic_read(&shost->mpath_nr_active); } +static int scsi_mpath_remove_head_drv(struct device_driver *drv, void *data) +{ + struct scsi_mpath_head *scsi_mpath_head = data; + struct scsi_driver *scsi_driver = to_scsi_driver(drv); + + if (scsi_driver->mpath_remove_head) + scsi_driver->mpath_remove_head(scsi_mpath_head); + + return 0; +} + +static void scsi_mpath_remove_head_work(struct mpath_head *mpath_head) +{ + bus_for_each_drv(&scsi_bus_type, NULL, mpath_head->drvdata, + scsi_mpath_remove_head_drv); +} + struct mpath_head_template smpdt = { + .remove_head = scsi_mpath_remove_head_work, .is_disabled = scsi_mpath_is_disabled, .is_optimized = scsi_mpath_is_optimized, .available_path = scsi_mpath_available_path, diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h index 249cea724abd1..d92b63d357f2a 100644 --- a/include/scsi/scsi_driver.h +++ b/include/scsi/scsi_driver.h @@ -8,6 +8,7 @@ struct module; struct request; +struct scsi_mpath_head; struct scsi_driver { struct device_driver gendrv; @@ -22,6 +23,9 @@ struct scsi_driver { int (*done)(struct scsi_cmnd *); int (*eh_action)(struct scsi_cmnd *, int); void (*eh_reset)(struct scsi_cmnd *); + #ifdef CONFIG_SCSI_MULTIPATH + void (*mpath_remove_head)(struct scsi_mpath_head *); + #endif }; #define to_scsi_driver(drv) \ container_of((drv), struct scsi_driver, gendrv) -- 2.43.5

