[PATCH v7 3/9] nvme-multipath: pass I/O type to nvme_find_path()
Nilay Shroff <[email protected]>
| Newsgroups | org.infradead.lists.linux-nvme |
|---|---|
| Message-ID | <[email protected]> |
Currently, nvme_find_path() only accepts an nvme_ns_head argument. However, the upcoming latency-aware I/O policy also needs to know the I/O type (read/write/other) associated with the request in order to make path selection decisions. Update nvme_find_path() to accept an additional argument describing the I/O type. This patch does not introduce any functional change and only prepares the interface for subsequent latency-policy changes. Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Nilay Shroff <[email protected]> --- drivers/nvme/host/ioctl.c | 38 +++++++++++++++++++++++++++++--- drivers/nvme/host/multipath.c | 9 ++++---- drivers/nvme/host/nvme.h | 41 ++++++++++++++++++++++++++++++++++- drivers/nvme/host/pr.c | 6 +++-- drivers/nvme/host/sysfs.c | 2 +- 5 files changed, 85 insertions(+), 11 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 664216eece4a..8a8ed132fab2 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -708,18 +708,29 @@ static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd, int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long arg) { + u8 opcode; struct nvme_ns_head *head = bdev->bd_disk->private_data; bool open_for_write = mode & BLK_OPEN_WRITE; void __user *argp = (void __user *)arg; struct nvme_ns *ns; int srcu_idx, ret = -EWOULDBLOCK; unsigned int flags = 0; + unsigned int op_type = NVME_STAT_OTHER; if (bdev_is_partition(bdev)) flags |= NVME_IOCTL_PARTITION; + if (cmd == NVME_IOCTL_SUBMIT_IO) { + if (get_user(opcode, (u8 *)argp)) + return -EFAULT; + if (opcode == nvme_cmd_write) + op_type = NVME_STAT_WRITE; + else if (opcode == nvme_cmd_read) + op_type = NVME_STAT_READ; + } + srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, op_type); if (!ns) goto out_unlock; @@ -741,6 +752,7 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode, long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { + u8 opcode; bool open_for_write = file->f_mode & FMODE_WRITE; struct cdev *cdev = file_inode(file)->i_cdev; struct nvme_ns_head *head = @@ -748,9 +760,19 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, void __user *argp = (void __user *)arg; struct nvme_ns *ns; int srcu_idx, ret = -EWOULDBLOCK; + unsigned int op_type = NVME_STAT_OTHER; + + if (cmd == NVME_IOCTL_SUBMIT_IO) { + if (get_user(opcode, (u8 *)argp)) + return -EFAULT; + if (opcode == nvme_cmd_write) + op_type = NVME_STAT_WRITE; + else if (opcode == nvme_cmd_read) + op_type = NVME_STAT_READ; + } srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, op_type); if (!ns) goto out_unlock; @@ -770,9 +792,19 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd, struct cdev *cdev = file_inode(ioucmd->file)->i_cdev; struct nvme_ns_head *head = container_of(cdev, struct nvme_ns_head, cdev); int srcu_idx = srcu_read_lock(&head->srcu); - struct nvme_ns *ns = nvme_find_path(head); + struct nvme_ns *ns; int ret = -EINVAL; + const struct nvme_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, + struct nvme_uring_cmd); + unsigned int op_type = NVME_STAT_OTHER; + __u8 opcode = READ_ONCE(cmd->opcode); + + if (opcode == nvme_cmd_write) + op_type = NVME_STAT_WRITE; + else if (opcode == nvme_cmd_read) + op_type = NVME_STAT_READ; + ns = nvme_find_path(head, op_type); if (ns) ret = nvme_ns_uring_cmd(ns, ioucmd, issue_flags); srcu_read_unlock(&head->srcu, srcu_idx); diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 9b9a657fa330..8c20ff516e61 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -460,7 +460,8 @@ static struct nvme_ns *nvme_numa_path(struct nvme_ns_head *head) return ns; } -inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head) +inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head, + unsigned int op_type) { switch (READ_ONCE(head->subsys->iopolicy)) { case NVME_IOPOLICY_QD: @@ -522,7 +523,7 @@ static void nvme_ns_head_submit_bio(struct bio *bio) return; srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, __nvme_data_dir(bio_op(bio))); if (likely(ns)) { bio_set_dev(bio, ns->disk->part0); /* @@ -572,7 +573,7 @@ static int nvme_ns_head_get_unique_id(struct gendisk *disk, u8 id[16], int srcu_idx, ret = -EWOULDBLOCK; srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, NVME_STAT_OTHER); if (ns) ret = nvme_ns_get_unique_id(ns, id, type); srcu_read_unlock(&head->srcu, srcu_idx); @@ -588,7 +589,7 @@ static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector, int srcu_idx, ret = -EWOULDBLOCK; srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, NVME_STAT_OTHER); if (ns) ret = nvme_ns_report_zones(ns, sector, nr_zones, args); srcu_read_unlock(&head->srcu, srcu_idx); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 824651cc898d..8a9ec502912d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -520,6 +520,13 @@ struct nvme_ns_ids { u8 csi; }; +enum nvme_stat_group { + NVME_STAT_READ, + NVME_STAT_WRITE, + NVME_STAT_OTHER, + NVME_NUM_STAT_GROUPS +}; + /* * Anchor structure for namespaces. There is one for each namespace in a * NVMe subsystem that any of our controllers can see, and the namespace @@ -1032,7 +1039,39 @@ extern const struct attribute_group *nvme_dev_attr_groups[]; extern const struct block_device_operations nvme_bdev_ops; void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl); -struct nvme_ns *nvme_find_path(struct nvme_ns_head *head); +struct nvme_ns *nvme_find_path(struct nvme_ns_head *head, unsigned int op_type); + +static inline int __nvme_data_dir(const enum req_op op) +{ + if (op == REQ_OP_READ) + return NVME_STAT_READ; + else if (op == REQ_OP_WRITE) + return NVME_STAT_WRITE; + else + return NVME_STAT_OTHER; +} + +static inline int __nvme_data_dir_passthru(enum nvme_opcode op) +{ + if (op == nvme_cmd_read) + return NVME_STAT_READ; + else if (op == nvme_cmd_write) + return NVME_STAT_WRITE; + else + return NVME_STAT_OTHER; +} + +static inline int nvme_data_dir(struct request *req) +{ + if (blk_rq_is_passthrough(req)) { + struct nvme_request *nr = nvme_req(req); + + return __nvme_data_dir_passthru(nr->cmd->common.opcode); + } + + return __nvme_data_dir(req_op(req)); +} + #ifdef CONFIG_NVME_MULTIPATH static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl) { diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index fe7dbe264815..80e106f151d2 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -53,10 +53,12 @@ static int nvme_send_ns_head_pr_command(struct block_device *bdev, struct nvme_command *c, void *data, unsigned int data_len) { struct nvme_ns_head *head = bdev->bd_disk->private_data; - int srcu_idx = srcu_read_lock(&head->srcu); - struct nvme_ns *ns = nvme_find_path(head); + int srcu_idx; + struct nvme_ns *ns; int ret = -EWOULDBLOCK; + srcu_idx = srcu_read_lock(&head->srcu); + ns = nvme_find_path(head, NVME_STAT_OTHER); if (ns) { c->common.nsid = cpu_to_le32(ns->head->ns_id); ret = nvme_submit_sync_cmd(ns->queue, c, data, data_len); diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index 75b2d69b5957..b2034e033ac3 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -195,7 +195,7 @@ static int ns_head_update_nuse(struct nvme_ns_head *head) return 0; srcu_idx = srcu_read_lock(&head->srcu); - ns = nvme_find_path(head); + ns = nvme_find_path(head, NVME_STAT_OTHER); if (!ns) goto out_unlock; -- 2.53.0