[PATCH] nvme: introduce passthrough ioctl for multipath
Minwoo Im
minwoo.im.dev at gmail.com
Sun Feb 14 06:01:25 EST 2021
We don't allow NVME_IOCTL_IO_CMD ioctl in case that a controller has
multiple namespaces attached. Also, I/O request to the controller
character device has not been recommended and deprecated because we have
block device to I/O with where the multipath consideration is taken.
Once kernel decided a path to I/O for a namespace based on the I/O
policy of a NVMe subsystem, userspace is not allowed to choose a path to
I/O. If a path is broken(inaccessible state in ANA), then it will not
try to I/O to that path.
This patch introduced NVME_IOCTL_MPATH_IO command for controller
device(e.g., /dev/nvme0) to support multipath I/O passthrough for
userspace. Regardless driver's path decision, userspace can target a
namespace to I/O. In this case, `cmd.nsid` will be used to find out the
namespace instance target which is hidden(e.g., nvmeXcYnZ).
Signed-off-by: Minwoo Im <minwoo.im.dev at gmail.com>
---
drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++
include/uapi/linux/nvme_ioctl.h | 1 +
2 files changed, 32 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index d77f3f26d8d3..fed9fc41b021 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1707,6 +1707,35 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
return status;
}
+#ifdef CONFIG_NVME_MULTIPATH
+static int nvme_dev_mpath_cmd(struct nvme_ctrl *ctrl,
+ struct nvme_passthru_cmd __user *ucmd)
+{
+ struct nvme_passthru_cmd cmd;
+ struct nvme_ns *ns;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+ if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
+ return -EFAULT;
+
+ ns = nvme_find_get_ns(ctrl, cmd.nsid);
+ if (unlikely(!ns))
+ return -EINVAL;
+ if (WARN_ON_ONCE(!(ns->disk->flags & GENHD_FL_HIDDEN)))
+ return -EINVAL;
+
+ return nvme_user_cmd(ctrl, ns, ucmd);
+}
+#else
+static int nvme_dev_mpath_cmd(struct nvme_ctrl *ctrl,
+ struct nvme_passthru_cmd __user *ucmd)
+{
+ dev_warn(ctrl->device, "CONFIG_NVME_MULTIPATH should be enabled\n");
+ return -EINVAL;
+}
+#endif
+
/*
* Issue ioctl requests on the first available path. Note that unlike normal
* block layer requests we will not retry failed request on another controller.
@@ -3329,6 +3358,8 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd,
return nvme_user_cmd64(ctrl, NULL, argp);
case NVME_IOCTL_IO_CMD:
return nvme_dev_user_cmd(ctrl, argp);
+ case NVME_IOCTL_MPATH_IO:
+ return nvme_dev_mpath_cmd(ctrl, argp);
case NVME_IOCTL_RESET:
dev_warn(ctrl->device, "resetting controller\n");
return nvme_reset_ctrl_sync(ctrl);
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index d99b5a772698..38bd330e5416 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -78,5 +78,6 @@ struct nvme_passthru_cmd64 {
#define NVME_IOCTL_RESCAN _IO('N', 0x46)
#define NVME_IOCTL_ADMIN64_CMD _IOWR('N', 0x47, struct nvme_passthru_cmd64)
#define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct nvme_passthru_cmd64)
+#define NVME_IOCTL_MPATH_IO _IOWR('N', 0x49, struct nvme_passthru_cmd)
#endif /* _UAPI_LINUX_NVME_IOCTL_H */
--
2.17.1
More information about the Linux-nvme
mailing list