Add scsi_mpath_{start,end}_request() to handle updating private multipath
request data, like nvme_mpath_{start,end}_request().New member Scsi_Host.mpath_nr_active is added. 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_lib.c | 6 +++++ drivers/scsi/scsi_multipath.c | 51 +++++++++++++++++++++++++++++++++++ include/scsi/scsi_cmnd.h | 5 ++++ include/scsi/scsi_host.h | 4 +++ include/scsi/scsi_multipath.h | 8 ++++++ 5 files changed, 74 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index cc34253c467a2..f8b389fda2537 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -669,6 +669,9 @@ static bool scsi_end_request(struct request *req, blk_status_t error, struct scsi_device *sdev = cmd->device; struct request_queue *q = sdev->request_queue; + if (is_mpath_request(req)) + scsi_mpath_end_request(req); + if (blk_update_request(req, error, bytes)) return true; @@ -1917,6 +1920,9 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); cmd->submitter = SUBMITTED_BY_BLOCK_LAYER; + if (is_mpath_request(req)) + scsi_mpath_start_request(req); + blk_mq_start_request(req); if (blk_mq_is_reserved_rq(req)) { reason = shost->hostt->queue_reserved_command(shost, cmd); diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c index d8ea9ffe8942c..61fa2e4cdfdab 100644 --- a/drivers/scsi/scsi_multipath.c +++ b/drivers/scsi/scsi_multipath.c @@ -543,6 +543,57 @@ void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head) } EXPORT_SYMBOL_GPL(scsi_mpath_put_head); +void scsi_mpath_start_request(struct request *req) +{ + struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req); + struct scsi_device *sdev = scmd->device; + struct scsi_mpath_device *scsi_mpath_dev = sdev->scsi_mpath_dev; + struct scsi_mpath_head *scsi_mpath_head = + scsi_mpath_dev->scsi_mpath_head; + struct mpath_head *mpath_head = &scsi_mpath_head->mpath_head; + struct gendisk *disk = mpath_head->disk; + + if (mpath_qd_iopolicy(&scsi_mpath_head->iopolicy) && + !(scmd->flags & SCMD_MPATH_CNT_ACTIVE)) { + struct Scsi_Host *shost = sdev->host; + + atomic_inc(&shost->mpath_nr_active); + scmd->flags |= SCMD_MPATH_CNT_ACTIVE; + } + + if (!blk_queue_io_stat(disk->queue) || blk_rq_is_passthrough(req) || + (scmd->flags & SCMD_MPATH_IO_STATS)) + return; + + scmd->flags |= SCMD_MPATH_IO_STATS; + scmd->start_time = bdev_start_io_acct(disk->part0, req_op(req), + jiffies); +} + +void scsi_mpath_end_request(struct request *req) +{ + struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req); + struct scsi_device *sdev = scmd->device; + struct scsi_mpath_device *scsi_mpath_dev = + sdev->scsi_mpath_dev; + struct scsi_mpath_head *scsi_mpath_head = + scsi_mpath_dev->scsi_mpath_head; + struct mpath_head *mpath_head = &scsi_mpath_head->mpath_head; + struct gendisk *disk = mpath_head->disk; + + if (scmd->flags & SCMD_MPATH_CNT_ACTIVE) { + struct Scsi_Host *shost = sdev->host; + + atomic_dec_if_positive(&shost->mpath_nr_active); + } + + if (!(scmd->flags & SCMD_MPATH_IO_STATS)) + return; + bdev_end_io_acct(disk->part0, req_op(req), + blk_rq_bytes(req) >> SECTOR_SHIFT, + scmd->start_time); +} + int __init scsi_multipath_init(void) { return class_register(&scsi_mpath_device_class); diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 8ecfb94049db5..c6571a36e577b 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -60,6 +60,8 @@ struct scsi_pointer { #define SCMD_FAIL_IF_RECOVERING (1 << 4) /* flags preserved across unprep / reprep */ #define SCMD_PRESERVED_FLAGS (SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING) +#define SCMD_MPATH_IO_STATS (1 << 5) +#define SCMD_MPATH_CNT_ACTIVE (1 << 6) /* for scmd->state */ #define SCMD_STATE_COMPLETE 0 @@ -139,6 +141,9 @@ struct scsi_cmnd { * to release this memory. (The memory * obtained by scsi_malloc is guaranteed * to be at an address < 16Mb). */ + #ifdef CONFIG_SCSI_MULTIPATH + unsigned long start_time; + #endif int result; /* Status code from lower level driver */ }; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 7e2011830ba4b..cf4fff3ea1a8e 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -753,6 +753,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 diff --git a/include/scsi/scsi_multipath.h b/include/scsi/scsi_multipath.h index d8644d6261992..ed5c77d568843 100644 --- a/include/scsi/scsi_multipath.h +++ b/include/scsi/scsi_multipath.h @@ -55,6 +55,8 @@ void scsi_mpath_add_sysfs_link(struct scsi_device *sdev); void scsi_mpath_remove_sysfs_link(struct scsi_device *sdev); int scsi_mpath_get_head(struct scsi_mpath_head *scsi_mpath_head); void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head); +void scsi_mpath_start_request(struct request *req); +void scsi_mpath_end_request(struct request *req); #else /* CONFIG_SCSI_MULTIPATH */ struct scsi_mpath_head { @@ -93,6 +95,12 @@ static inline void scsi_mpath_put_head(struct scsi_mpath_head *scsi_mpath_head) { } +static inline void scsi_mpath_start_request(struct request *req) +{ +} +static inline void scsi_mpath_end_request(struct request *req) +{ +} static inline void scsi_mpath_add_sysfs_link(struct scsi_device *sdev) { } -- 2.43.7

