Add scsi_mpath_get_nr_active() for calculating the number of active requests associated with an mpath_device. This is required for queue depth multipath iopolicy.
For NVMe, this count is per controller. The reason is that many NSes may be connected to a controller, so congestion should be judged at controller level. SCSI has no definition of a controller, but SCSI host is a comparable concept. Indeed, many SCSI disks may be connected to the same SCSI host, so it makes sense to count number of active requests at this point. However, for a transport like iSCSI Initiator over TCP/IP, we have a separate SCSI host per SCSI device (so there the count would be same at SCSI device level). Signed-off-by: John Garry <[email protected]> --- drivers/scsi/scsi_multipath.c | 11 +++++++++++ include/scsi/scsi_host.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c index a3bf95e2a18eb..80f32b940339f 100644 --- a/drivers/scsi/scsi_multipath.c +++ b/drivers/scsi/scsi_multipath.c @@ -351,12 +351,23 @@ static bool scsi_mpath_available_path(struct mpath_device *mpath_device) return false; } +static int scsi_mpath_get_nr_active(struct mpath_device *mpath_device) +{ + struct scsi_mpath_device *scsi_mpath_dev = + to_scsi_mpath_device(mpath_device); + struct scsi_device *sdev = scsi_mpath_dev->sdev; + struct Scsi_Host *shost = sdev->host; + + return atomic_read(&shost->mpath_nr_active); +} + struct mpath_head_template smpdt = { .is_disabled = scsi_mpath_is_disabled, .is_optimized = scsi_mpath_is_optimized, .available_path = scsi_mpath_available_path, .get_iopolicy = scsi_mpath_get_iopolicy, .clone_bio = scsi_mpath_clone_bio, + .get_nr_active = scsi_mpath_get_nr_active, }; static struct scsi_mpath_head *scsi_mpath_alloc_head(void) diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index f6e12565a81de..979d1e89f0f13 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -752,6 +752,10 @@ struct Scsi_Host { /* Delay for runtime autosuspend */ int rpm_autosuspend_delay; + #ifdef CONFIG_SCSI_MULTIPATH + atomic_t mpath_nr_active; + #endif + /* * We should ensure that this is aligned, both for better performance * and also because some compilers (m68k) don't automatically force -- 2.43.5

