public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Minwoo Im <minwoo.im.dev@gmail.com>
To: linux-nvme@lists.infradead.org
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@fb.com>,
	Minwoo Im <minwoo.im.dev@gmail.com>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Subject: [PATCH] nvme: introduce passthrough ioctl for multipath
Date: Sun, 14 Feb 2021 20:01:25 +0900	[thread overview]
Message-ID: <20210214110126.24023-2-minwoo.im.dev@gmail.com> (raw)
In-Reply-To: <20210214110126.24023-1-minwoo.im.dev@gmail.com>

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@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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2021-02-14 11:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 11:01 [PATCH 0/2] nvme: support I/O passthrough for multipath Minwoo Im
2021-02-14 11:01 ` Minwoo Im [this message]
2021-02-15 17:02   ` [PATCH] nvme: introduce passthrough ioctl " Keith Busch
2021-02-16  9:51     ` Minwoo Im
2021-02-16 17:57       ` Keith Busch
2021-02-17  2:14         ` Minwoo Im
2021-02-18  8:40           ` Christoph Hellwig
2021-02-18  8:48             ` Javier González
2021-02-19 21:27               ` Minwoo Im
2021-02-19 21:26             ` Minwoo Im
2021-02-14 11:01 ` [nvme-cli PATCH] nvme: add [--mpath|-M] option to io-passthru Minwoo Im

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210214110126.24023-2-minwoo.im.dev@gmail.com \
    --to=minwoo.im.dev@gmail.com \
    --cc=axboe@fb.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox