[nvme-cli PATCH] nvme: add [--mpath|-M] option to io-passthru

Minwoo Im minwoo.im.dev at gmail.com
Sun Feb 14 06:01:26 EST 2021


`io-passthru` command is to submit a I/O command to controller with a
namespace specified.  Kernel driver does not allow userspace to I/O
passthrough in case that controller has multiple namespaces attached.
NVME_IOCTL_IO_CMD will return -EINVAL error from the kernel driver.

This patch added an option `--mpath|-M` option to the `io-passthru`
command to support specifying device namespace id to I/O.  This option
will make `--namespace-id` option to be used to find out the namespae
instance to the kernel side even it's a hidden blkdev (e.g.,
/dev/nvmeXcYnZ).

This feature can be used to debug or test the broken path for ANA case
by specifying the target namespace of a controller to I/O.

  nvme io-passthru /dev/nvme0 --namespace-id=123 --opcode=0x2 --data-len=512 --read --mpath

Signed-off-by: Minwoo Im <minwoo.im.dev at gmail.com>
---
 linux/nvme_ioctl.h |  1 +
 nvme.c             | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/linux/nvme_ioctl.h b/linux/nvme_ioctl.h
index d569414211d1..578faaee62b6 100644
--- a/linux/nvme_ioctl.h
+++ b/linux/nvme_ioctl.h
@@ -87,5 +87,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 */
diff --git a/nvme.c b/nvme.c
index c79edbda17ed..9dea66edcabe 100644
--- a/nvme.c
+++ b/nvme.c
@@ -5109,6 +5109,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		int   read;
 		int   write;
 		__u8  prefill;
+		bool  mpath;
 	};
 
 	struct config cfg = {
@@ -5129,6 +5130,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		.cdw15        = 0,
 		.input_file   = "",
 		.prefill      = 0,
+		.mpath        = false,
 	};
 
 	const char *opcode = "opcode (required)";
@@ -5153,6 +5155,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	const char *re = "set dataflow direction to receive";
 	const char *wr = "set dataflow direction to send";
 	const char *prefill = "prefill buffers with known byte-value, default 0";
+	const char *mpath = "multipath I/O (valid only if io-passthru)";
 
 	OPT_ARGS(opts) = {
 		OPT_BYTE("opcode",       'o', &cfg.opcode,       opcode),
@@ -5177,6 +5180,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		OPT_FLAG("dry-run",      'd', &cfg.dry_run,      dry),
 		OPT_FLAG("read",         'r', &cfg.read,         re),
 		OPT_FLAG("write",        'w', &cfg.write,        wr),
+		OPT_FLAG("mpath",        'M', &cfg.mpath,        mpath),
 		OPT_END()
 	};
 
@@ -5184,6 +5188,22 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 	if (fd < 0)
 		goto ret;
 
+	if (cfg.mpath) {
+		if (!cfg.namespace_id) {
+			fprintf(stderr, "mpath should be with --namespace-id\n");
+			err = -EINVAL;
+			goto close_fd;
+		}
+
+		if (!is_chardev()) {
+			fprintf(stderr, "mpath should be with chardev (e.g., /dev/nvme0)\n");
+			err = -EINVAL;
+			goto close_fd;
+		}
+
+		ioctl_cmd = NVME_IOCTL_MPATH_IO;
+	}
+
 	if (strlen(cfg.input_file)){
 		wfd = open(cfg.input_file, O_RDONLY,
 			   S_IRUSR | S_IRGRP | S_IROTH);
-- 
2.17.1




More information about the Linux-nvme mailing list