Add scsi_mpath_{start,end}_request() to handle updating private multipath
request data, like nvme_mpath_{start,end}_request().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_multipath.h | 9 +++++++ 4 files changed, 71 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 43154f521198a..46ed669c41dc9 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -645,6 +645,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; @@ -1893,6 +1896,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 80f32b940339f..a2a21793db895 100644 --- a/drivers/scsi/scsi_multipath.c +++ b/drivers/scsi/scsi_multipath.c @@ -564,6 +564,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_multipath.h b/include/scsi/scsi_multipath.h index d0e1cda836865..fdbdb0e5d02e0 100644 --- a/include/scsi/scsi_multipath.h +++ b/include/scsi/scsi_multipath.h @@ -53,6 +53,9 @@ 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 *); void scsi_mpath_put_head(struct 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 { @@ -89,6 +92,12 @@ static inline int scsi_mpath_get_head(struct scsi_mpath_head *) static inline void scsi_mpath_put_head(struct scsi_mpath_head *) { } +static inline void scsi_mpath_start_request(struct request *) +{ +} +static inline void scsi_mpath_end_request(struct request *) +{ +} static inline void scsi_mpath_add_sysfs_link(struct scsi_device *sdev) { } -- 2.43.5

