Skip to contentSkip to conversation

io_uring.h: add IORING_SETUP_SQE128 and IORING_SETUP_CQE32

PATCH Superseded Ankit Kumar 5 participants 26 messages May 26, 2022 – May 30, 2022 1 message not in the archive Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20220526145343epcas5p362cd1b702fc0d11d21bca2880d6e288c@epcas5p3.samsung.com

#1 lore raw

v2 cover Add support for uring passthrough commands

This patchset adds a new I/O engine (io_uring_cmd), which enables support for io_uring passthrough commands. This work is based on upcoming 5.19 kernel.
https://git.kernel.dk/cgit/linux-block/log/?h=for-next

This engine will use most of the existing helpers from io_uring. The I/O preparation, completion, file open, file close and post init paths are going to differ and hence io_uring_cmd will have its own helpers for them.

The supported io_uring_cmd options are:
* registerfiles
* sqthread_poll
* sqthread_poll_cpu
* nonvectored
* force_async
* cmd_type (new)

The current uring passthrough support is present only with nvme-ns character device (/dev/ngXnY). This includes both conventional as well as ZNS devices. cmd_type provides the flexibility to support different types of passthrough commands in future.

To enable support for nvme passthrough commands, we are adding nvme.c and nvme.h files. These will have the necessary NVMe specification data strcutures, opcodes and helper functions for sending admin and I/O passthrough commands.

O_DIRECT flag support is not present with nvme-ns charatcer devices, hence zbd will check for them only if fio filetype is a block device. The t/zbd/test-zbd-support test case #1 is now updated to run only for block device.

Changes since v1:
- Removed libnvme dependency.
- Addressed review comments from Jens, no longer messy CONFIG flags for the new engine.
- Addressed review comment from Shinichiro.

Ankit Kumar (5):
configure: check nvme uring command support
nvme: add nvme opcodes, structures and helper functions
docs: document options for io_uring_cmd I/O engine
zbd: Check for direct flag only if its block device engines/io_uring: Enable zone device support for io_uring_cmd I/O
engine

Anuj Gupta (3):
io_uring.h: add IORING_SETUP_SQE128 and IORING_SETUP_CQE32 engines/io_uring: add new I/O engine for uring passthrough support
examples: add 2 example job file for io_uring_cmd engine

 HOWTO.rst                    |  39 +++-
 Makefile                     |   4 +-
 configure                    |  21 +++
 engines/io_uring.c           | 336 +++++++++++++++++++++++++++++++++-
 engines/nvme.c               | 338 +++++++++++++++++++++++++++++++++++
 engines/nvme.h               | 204 +++++++++++++++++++++
 examples/uring-cmd-ng.fio    |  35 ++++
 examples/uring-cmd-zoned.fio |  40 +++++
 file.h                       |  12 +-
 fio.1                        |  28 ++-
 os/linux/io_uring.h          |  45 ++++-
 t/zbd/test-zbd-support       |   3 +-
 zbd.c                        |   4 +-
 13 files changed, 1080 insertions(+), 29 deletions(-)
 create mode 100644 engines/nvme.c
 create mode 100644 engines/nvme.h
 create mode 100644 examples/uring-cmd-ng.fio
 create mode 100644 examples/uring-cmd-zoned.fio

base-commit: 6f1a24593c227a4f392f454698aca20e95f0006c

Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/8 io_uring.h: add IORING_SETUP_SQE128 and IORING_SETUP_CQE32

From: Anuj Gupta <[email protected]>

This asks the kernel to setup a ring with 128-byte SQE and 32-byte CQE entries. It may fail with -EINVAL if the kernel doesn't support this feature. If the kernel does support this feature, then the ring will support big-sqe/big-cqe entries which some commands may require.

---
 os/linux/io_uring.h | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
os/linux/io_uring.h +35 -1
index 42b2fe84..2fa66135 100644
@@ -60,7 +60,17 @@ struct io_uring_sqe {
 		__s32	splice_fd_in;
 		__u32	file_index;
 	};
-	__u64	__pad2[2];
+	union {
+		struct {
+			__u64	addr3;
+			__u64	__pad2[1];
+		};
+		/*
+		 * If the ring is initialized with IORING_SETUP_SQE128, then
+		 * this field is used for 80 bytes of arbitrary command data
+		 */
+		__u8	cmd[0];
+	};
 };
 
 enum {
@@ -101,6 +111,24 @@ enum {
 #define IORING_SETUP_CLAMP	(1U << 4)	/* clamp SQ/CQ ring sizes */
 #define IORING_SETUP_ATTACH_WQ	(1U << 5)	/* attach to existing wq */
 #define IORING_SETUP_R_DISABLED	(1U << 6)	/* start with ring disabled */
+#define IORING_SETUP_SUBMIT_ALL	(1U << 7)	/* continue submit on error */
+/*
+ * Cooperative task running. When requests complete, they often require
+ * forcing the submitter to transition to the kernel to complete. If this
+ * flag is set, work will be done when the task transitions anyway, rather
+ * than force an inter-processor interrupt reschedule. This avoids interrupting
+ * a task running in userspace, and saves an IPI.
+ */
+#define IORING_SETUP_COOP_TASKRUN	(1U << 8)
+/*
+ * If COOP_TASKRUN is set, get notified if task work is available for
+ * running and a kernel transition would be needed to run it. This sets
+ * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
+ */
+#define IORING_SETUP_TASKRUN_FLAG	(1U << 9)
+
+#define IORING_SETUP_SQE128		(1U << 10) /* SQEs are 128 byte */
+#define IORING_SETUP_CQE32		(1U << 11) /* CQEs are 32 byte */
 
 enum {
 	IORING_OP_NOP,
@@ -192,6 +220,12 @@ struct io_uring_cqe {
 	__u64	user_data;	/* sqe->data submission passed back */
 	__s32	res;		/* result code for this event */
 	__u32	flags;
+
+	/*
+	 * If the ring is initialized with IORING_SETUP_CQE32, then this field
+	 * contains 16-bytes of padding, doubling the size of the CQE.
+	 */
+	__u64 big_cqe[];
 };
 
 /*
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 2/8 configure: check nvme uring command support

In reply to Ankit Kumar

Modify configure to check availability of nvme_uring_cmd, but only when the target OS is Linux. This way in the follow up patch we can define the missing structure to prevent compilation errors.

---
 configure | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
configure +21 -0
index 95b60bb7..7e855e0e 100755
@@ -2587,6 +2587,27 @@ if test "$libzbc" != "no" ; then
 fi
 print_config "libzbc engine" "$libzbc"
 
+if test "$targetos" = "Linux" ; then
+##########################################
+# Check NVME_URING_CMD support
+cat > $TMPC << EOF
+#include <linux/nvme_ioctl.h>
+int main(void)
+{
+  struct nvme_uring_cmd *cmd;
+
+  return sizeof(struct nvme_uring_cmd);
+}
+EOF
+if compile_prog "" "" "nvme uring cmd"; then
+  output_sym "CONFIG_NVME_URING_CMD"
+  nvme_uring_cmd="yes"
+else
+  nvme_uring_cmd="no"
+fi
+print_config "NVMe uring command support" "$nvme_uring_cmd"
+fi
+
 ##########################################
 # Check if we have xnvme
 if test "$xnvme" != "yes" ; then
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 3/8 nvme: add nvme opcodes, structures and helper functions

In reply to Ankit Kumar

Add NVMe specification opcodes, data structures and helper functions to get identify namespace and form nvme uring command.

This will help the follow up patches to get nvme-ns generic charcter device size, lba size.

---
 Makefile       |   4 +-
 engines/nvme.c | 100 +++++++++++++++++++++++++++++++++++++++
 engines/nvme.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 227 insertions(+), 2 deletions(-)
 create mode 100644 engines/nvme.c
 create mode 100644 engines/nvme.h
Makefile +2 -2
index ed66305a..188a74d7 100644
@@ -231,7 +231,7 @@ ifdef CONFIG_LIBXNVME
 endif
 ifeq ($(CONFIG_TARGET_OS), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
-		oslib/linux-dev-lookup.c engines/io_uring.c
+		oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c
   cmdprio_SRCS = engines/cmdprio.c
 ifdef CONFIG_HAS_BLKZONED
   SOURCE += oslib/linux-blkzoned.c
@@ -241,7 +241,7 @@ endif
 endif
 ifeq ($(CONFIG_TARGET_OS), Android)
   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c profiles/tiobench.c \
-		oslib/linux-dev-lookup.c engines/io_uring.c
+		oslib/linux-dev-lookup.c engines/io_uring.c engines/nvme.c
   cmdprio_SRCS = engines/cmdprio.c
 ifdef CONFIG_HAS_BLKZONED
   SOURCE += oslib/linux-blkzoned.c
engines/nvme.c new file +100 -0

100 lines not on this page · raw message

engines/nvme.h new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

engines/nvme.c line 18

Quoted 11 lines · Ankit Kumar
engines/nvme.c new file +11 -0
+void fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
+			     struct iovec *iov)
+{
+	struct nvme_data *data = FILE_ENG_DATA(io_u->file);
+	__u64 slba;
+	__u32 nlb;
+
+	slba = io_u->offset / data->lba_size;
+	nlb = (io_u->xfer_buflen / data->lba_size) - 1;
+
+	memset(cmd, 0, sizeof(struct nvme_uring_cmd));

Is this better or setting remaining fields (which are not populated down) to zero.

engines/nvme.c line 29

Quoted 10 lines
engines/nvme.c new file +10 -0
+	/* cdw10 and cdw11 represent starting lba */
+	cmd->cdw10 = slba & 0xffffffff;
+	cmd->cdw11 = slba >> 32;
+	/* cdw12 represent number of lba's for read/write */
+	cmd->cdw12 = nlb;
+	if (iov) {
+		iov->iov_base = io_u->xfer_buf;
+		iov->iov_len = io_u->xfer_buflen;
+		cmd->addr = (__u64)(uintptr_t)iov;
+		cmd->data_len = 1;

Is this correct? Do we always get 1 vector to deal with.

#6 lore raw

Re: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

Quoted 16 lines · Kanchan Joshi

engines/nvme.c line 18

Quoted 11 lines · Ankit Kumar
engines/nvme.c new file +11 -0
+void fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
+                 struct iovec *iov)
+{
+    struct nvme_data *data = FILE_ENG_DATA(io_u->file);
+    __u64 slba;
+    __u32 nlb;
+
+    slba = io_u->offset / data->lba_size;
+    nlb = (io_u->xfer_buflen / data->lba_size) - 1;
+
+    memset(cmd, 0, sizeof(struct nvme_uring_cmd));

Is this better or setting remaining fields (which are not populated down) to zero.

Since lba_size is a power of 2, it would be a lot more efficient to take this division by non-constant out of the fast path and init a shift value:

data->lba_shift = log2(data->lba_size);

and change these to:

slba = io_u->offset >> data->lba_shift;

and ditto for nlb.

Quoted 11 lines

engines/nvme.c line 29

Quoted 10 lines
engines/nvme.c new file +10 -0
+    /* cdw10 and cdw11 represent starting lba */
+    cmd->cdw10 = slba & 0xffffffff;
+    cmd->cdw11 = slba >> 32;
+    /* cdw12 represent number of lba's for read/write */
+    cmd->cdw12 = nlb;
+    if (iov) {
+        iov->iov_base = io_u->xfer_buf;
+        iov->iov_len = io_u->xfer_buflen;
+        cmd->addr = (__u64)(uintptr_t)iov;
+        cmd->data_len = 1;
Quoted 1 line

Is this correct? Do we always get 1 vector to deal with.

Yes

Signature · 1 line
Jens Axboe
#7 lore raw

Re: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

Quoted 22 lines · Jens Axboe
Quoted 16 lines · Kanchan Joshi

engines/nvme.c line 18

Quoted 11 lines · Ankit Kumar
engines/nvme.c new file +11 -0
+void fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
+                 struct iovec *iov)
+{
+    struct nvme_data *data = FILE_ENG_DATA(io_u->file);
+    __u64 slba;
+    __u32 nlb;
+
+    slba = io_u->offset / data->lba_size;
+    nlb = (io_u->xfer_buflen / data->lba_size) - 1;
+
+    memset(cmd, 0, sizeof(struct nvme_uring_cmd));

Is this better or setting remaining fields (which are not populated down) to zero.

Since lba_size is a power of 2, it would be a lot more efficient to take this division by non-constant out of the fast path and init a shift value:

Quoted 7 lines

data->lba_shift = log2(data->lba_size);

and change these to:

slba = io_u->offset >> data->lba_shift;

and ditto for nlb.

Thanks, will do this in v3

Quoted 20 lines
Quoted 12 lines

engines/nvme.c line 29

Quoted 11 lines
engines/nvme.c new file +10 -0
+    /* cdw10 and cdw11 represent starting lba */
+    cmd->cdw10 = slba & 0xffffffff;
+    cmd->cdw11 = slba >> 32;
+    /* cdw12 represent number of lba's for read/write */
+    cmd->cdw12 = nlb;
+    if (iov) {
+        iov->iov_base = io_u->xfer_buf;
+        iov->iov_len = io_u->xfer_buflen;
+        cmd->addr = (__u64)(uintptr_t)iov;
+        cmd->data_len = 1;
Quoted 1 line

Is this correct? Do we always get 1 vector to deal with.

Yes

Signature · 1 line
Jens Axboe
#8 lore raw

RE: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

In reply to Ankit Kumar

engines/nvme.c line 39

Quoted 8 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]

engines/nvme.c new file +5 -0
+
+	if (io_u->ddir == DDIR_READ)
+		cmd->opcode = nvme_cmd_read;
+	if (io_u->ddir == DDIR_WRITE)
+		cmd->opcode = nvme_cmd_write;

Consider changing this to a switch statement and adding a default: case in case someone tries to send an unsupported command.

Since this is in the fast path a switch statement would also reduce the number of times ddir is checked.

#9 lore raw

Re: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

Quoted 12 lines · Vincent Fu

engines/nvme.c line 39

Quoted 8 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]

engines/nvme.c new file +5 -0
+
+	if (io_u->ddir == DDIR_READ)
+		cmd->opcode = nvme_cmd_read;
+	if (io_u->ddir == DDIR_WRITE)
+		cmd->opcode = nvme_cmd_write;

Consider changing this to a switch statement and adding a default:
case in case someone tries to send an unsupported command.

Quoted 2 lines

Since this is in the fast path a switch statement would also reduce the number of times ddir is checked.

A switch or if/else won't make any difference there, the compiler should generate the same code. But I do agree that it's nicer to use a switch so that unhandled cases are done properly.

Signature · 1 line
Jens Axboe
#10 lore raw

Re: [PATCH v2 3/8] nvme: add nvme opcodes, structures and helper functions

Quoted 13 lines · Jens Axboe
Quoted 12 lines · Vincent Fu

engines/nvme.c line 39

Quoted 8 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]

engines/nvme.c new file +5 -0
+
+	if (io_u->ddir == DDIR_READ)
+		cmd->opcode = nvme_cmd_read;
+	if (io_u->ddir == DDIR_WRITE)
+		cmd->opcode = nvme_cmd_write;

Consider changing this to a switch statement and adding a default:
case in case someone tries to send an unsupported command.

Quoted 6 lines
Quoted 2 lines

Since this is in the fast path a switch statement would also reduce the number of times ddir is checked.

A switch or if/else won't make any difference there, the compiler should generate the same code. But I do agree that it's nicer to use a switch so that unhandled cases are done properly.

How I'd do this:

make the prep handler return an error, and then do:

if (io_u->ddir == DDIR_READ)

	cmd->opcode = nvme_cmd_read;
else if (io_u->ddir == DDIR_WRITE)
	cmd->opcode = nvme_cmd_write;
else
	return appropriate error;

after you do the command memset, before all the other logic. Now make sure that whoever calls the prep handler will check for an error and error the io_u in that case.

Signature · 1 line
Jens Axboe
#11 lore raw

PATCH v2 4/8 engines/io_uring: add new I/O engine for uring passthrough support

In reply to Ankit Kumar

From: Anuj Gupta <[email protected]>

Add a new I/O engine (io_uring_cmd) for sending uring passthrough commands. It will also use most of the existing helpers from the I/O engine io_uring. The I/O preparation, completion, file open, file close and post init paths are going to differ and hence io_uring_cmd will have its own helper for them.

Add a new io_uring_cmd engine specific option to support nvme passthrough commands. Filename name for this specific option must specify nvme-ns generic character device (dev/ngXnY). This provides io_uring_cmd I/O engine a bandwidth to support various passthrough commands in future.

The engine_pos and engine_data fields in struct fio_file are separated now. This will help I/O engine io_uring_cmd to store specific data as well as keep track of register files.

The supported options for io_uring_cmd I/O engine are:
* registerfiles
* sqthread_poll
* sqthread_poll_cpu
* cmd_type
* nonvectored
* force_async

---
 engines/io_uring.c  | 304 +++++++++++++++++++++++++++++++++++++++++++-
 file.h              |  12 +-
 os/linux/io_uring.h |   9 ++
 3 files changed, 314 insertions(+), 11 deletions(-)
engines/io_uring.c +298 -6
index 1e15647e..2088ac47 100644
@@ -24,6 +24,13 @@
 #include "../lib/types.h"
 #include "../os/linux/io_uring.h"
 #include "cmdprio.h"
+#include "nvme.h"
+
+#include <sys/stat.h>
+
+enum uring_cmd_type {
+	FIO_URING_CMD_NVME = 1,
+};
 
 struct io_sq_ring {
 	unsigned *head;
@@ -85,6 +92,7 @@ struct ioring_options {
 	unsigned int uncached;
 	unsigned int nowait;
 	unsigned int force_async;
+	enum uring_cmd_type cmd_type;
 };
 
 static const int ddir_to_op[2][2] = {
@@ -270,6 +278,22 @@ static struct fio_option options[] = {
 		.category = FIO_OPT_C_ENGINE,
 		.group	= FIO_OPT_G_IOURING,
 	},
+	{
+		.name	= "cmd_type",
+		.lname	= "Uring cmd type",
+		.type	= FIO_OPT_STR,
+		.off1	= offsetof(struct ioring_options, cmd_type),
+		.help	= "Specify uring-cmd type",
+		.def	= "nvme",
+		.posval = {
+			  { .ival = "nvme",
+			    .oval = FIO_URING_CMD_NVME,
+			    .help = "Issue nvme-uring-cmd",
+			  },
+		},
+		.category = FIO_OPT_C_ENGINE,
+		.group	= FIO_OPT_G_IOURING,
+	},
 	{
 		.name	= NULL,
 	},
@@ -373,6 +397,45 @@ static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u)
 	return 0;
 }
 
+static int fio_ioring_cmd_prep(struct thread_data *td, struct io_u *io_u)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+	struct fio_file *f = io_u->file;
+	struct io_uring_sqe *sqe;
+
+	/* nvme_uring_cmd case */
+	if (o->cmd_type == FIO_URING_CMD_NVME) {
+		struct nvme_uring_cmd *cmd;
+
+		sqe = &ld->sqes[(io_u->index) << 1];
+
+		if (o->registerfiles) {
+			sqe->fd = f->engine_pos;
+			sqe->flags = IOSQE_FIXED_FILE;
+		} else {
+			sqe->fd = f->fd;
+		}
+		sqe->opcode = IORING_OP_URING_CMD;
+		sqe->user_data = (unsigned long) io_u;
+		if (o->nonvectored)
+			sqe->cmd_op = NVME_URING_CMD_IO;
+		else
+			sqe->cmd_op = NVME_URING_CMD_IO_VEC;
+		if (o->force_async && ++ld->prepped == o->force_async) {
+			ld->prepped = 0;
+			sqe->flags |= IOSQE_ASYNC;
+		}
+
+		cmd = (struct nvme_uring_cmd *)sqe->cmd;
+		fio_nvme_uring_cmd_prep(cmd, io_u,
+				o->nonvectored ? NULL : &ld->iovecs[io_u->index]);
+
+		return 0;
+	}
+	return -EINVAL;
+}
+
 static struct io_u *fio_ioring_event(struct thread_data *td, int event)
 {
 	struct ioring_data *ld = td->io_ops_data;
@@ -396,6 +459,29 @@ static struct io_u *fio_ioring_event(struct thread_data *td, int event)
 	return io_u;
 }
 
+static struct io_u *fio_ioring_cmd_event(struct thread_data *td, int event)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+	struct io_uring_cqe *cqe;
+	struct io_u *io_u;
+	unsigned index;
+
+	index = (event + ld->cq_ring_off) & ld->cq_ring_mask;
+	if (o->cmd_type == FIO_URING_CMD_NVME)
+		index <<= 1;
+
+	cqe = &ld->cq_ring.cqes[index];
+	io_u = (struct io_u *) (uintptr_t) cqe->user_data;
+
+	if (cqe->res != 0)
+		io_u->error = -cqe->res;
+	else
+		io_u->error = 0;
+
+	return io_u;
+}
+
 static int fio_ioring_cqring_reap(struct thread_data *td, unsigned int events,
 				   unsigned int max)
 {
@@ -622,14 +708,22 @@ static int fio_ioring_mmap(struct ioring_data *ld, struct io_uring_params *p)
 	sring->array = ptr + p->sq_off.array;
 	ld->sq_ring_mask = *sring->ring_mask;
 
-	ld->mmap[1].len = p->sq_entries * sizeof(struct io_uring_sqe);
+	if (p->flags & IORING_SETUP_SQE128)
+		ld->mmap[1].len = 2 * p->sq_entries * sizeof(struct io_uring_sqe);
+	else
+		ld->mmap[1].len = p->sq_entries * sizeof(struct io_uring_sqe);
 	ld->sqes = mmap(0, ld->mmap[1].len, PROT_READ | PROT_WRITE,
 				MAP_SHARED | MAP_POPULATE, ld->ring_fd,
 				IORING_OFF_SQES);
 	ld->mmap[1].ptr = ld->sqes;
 
-	ld->mmap[2].len = p->cq_off.cqes +
-				p->cq_entries * sizeof(struct io_uring_cqe);
+	if (p->flags & IORING_SETUP_CQE32) {
+		ld->mmap[2].len = p->cq_off.cqes +
+					2 * p->cq_entries * sizeof(struct io_uring_cqe);
+	} else {
+		ld->mmap[2].len = p->cq_off.cqes +
+					p->cq_entries * sizeof(struct io_uring_cqe);
+	}
 	ptr = mmap(0, ld->mmap[2].len, PROT_READ | PROT_WRITE,
 			MAP_SHARED | MAP_POPULATE, ld->ring_fd,
 			IORING_OFF_CQ_RING);
@@ -728,6 +822,54 @@ retry:
 	return fio_ioring_mmap(ld, &p);
 }
 
+static int fio_ioring_cmd_queue_init(struct thread_data *td)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+	int depth = td->o.iodepth;
+	struct io_uring_params p;
+	int ret;
+
+	memset(&p, 0, sizeof(p));
+
+	if (o->hipri)
+		p.flags |= IORING_SETUP_IOPOLL;
+	if (o->sqpoll_thread) {
+		p.flags |= IORING_SETUP_SQPOLL;
+		if (o->sqpoll_set) {
+			p.flags |= IORING_SETUP_SQ_AFF;
+			p.sq_thread_cpu = o->sqpoll_cpu;
+		}
+	}
+	if (o->cmd_type == FIO_URING_CMD_NVME) {
+		p.flags |= IORING_SETUP_SQE128;
+		p.flags |= IORING_SETUP_CQE32;
+	}
+
+	/*
+	 * Clamp CQ ring size at our SQ ring size, we don't need more entries
+	 * than that.
+	 */
+	p.flags |= IORING_SETUP_CQSIZE;
+	p.cq_entries = depth;
+
+retry:
+	ret = syscall(__NR_io_uring_setup, depth, &p);
+	if (ret < 0) {
+		if (errno == EINVAL && p.flags & IORING_SETUP_CQSIZE) {
+			p.flags &= ~IORING_SETUP_CQSIZE;
+			goto retry;
+		}
+		return ret;
+	}
+
+	ld->ring_fd = ret;
+
+	fio_ioring_probe(td);
+
+	return fio_ioring_mmap(ld, &p);
+}
+
 static int fio_ioring_register_files(struct thread_data *td)
 {
 	struct ioring_data *ld = td->io_ops_data;
@@ -811,6 +953,52 @@ static int fio_ioring_post_init(struct thread_data *td)
 	return 0;
 }
 
+static int fio_ioring_cmd_post_init(struct thread_data *td)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+	struct io_u *io_u;
+	int err, i;
+
+	for (i = 0; i < td->o.iodepth; i++) {
+		struct iovec *iov = &ld->iovecs[i];
+
+		io_u = ld->io_u_index[i];
+		iov->iov_base = io_u->buf;
+		iov->iov_len = td_max_bs(td);
+	}
+
+	err = fio_ioring_cmd_queue_init(td);
+	if (err) {
+		int init_err = errno;
+
+		td_verror(td, init_err, "io_queue_init");
+		return 1;
+	}
+
+	for (i = 0; i < td->o.iodepth; i++) {
+		struct io_uring_sqe *sqe;
+
+		if (o->cmd_type == FIO_URING_CMD_NVME) {
+			sqe = &ld->sqes[i << 1];
+			memset(sqe, 0, 2 * sizeof(*sqe));
+		} else {
+			sqe = &ld->sqes[i];
+			memset(sqe, 0, sizeof(*sqe));
+		}
+	}
+
+	if (o->registerfiles) {
+		err = fio_ioring_register_files(td);
+		if (err) {
+			td_verror(td, errno, "ioring_register_files");
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 static int fio_ioring_init(struct thread_data *td)
 {
 	struct ioring_options *o = td->eo;
@@ -868,6 +1056,38 @@ static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f)
 	return 0;
 }
 
+static int fio_ioring_cmd_open_file(struct thread_data *td, struct fio_file *f)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+
+	if (o->cmd_type == FIO_URING_CMD_NVME) {
+		struct nvme_data *data = NULL;
+		unsigned int nsid, lba_size = 0;
+		unsigned long long nlba = 0;
+		int ret;
+
+		/* Store the namespace-id and lba size. */
+		data = FILE_ENG_DATA(f);
+		if (data == NULL) {
+			ret = fio_nvme_get_info(f, &nsid, &lba_size, &nlba);
+			if (ret)
+				return ret;
+
+			data = calloc(1, sizeof(struct nvme_data));
+			data->nsid = nsid;
+			data->lba_size = lba_size;
+
+			FILE_SET_ENG_DATA(f, data);
+		}
+	}
+	if (!ld || !o->registerfiles)
+		return generic_open_file(td, f);
+
+	f->fd = ld->fds[f->engine_pos];
+	return 0;
+}
+
 static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f)
 {
 	struct ioring_data *ld = td->io_ops_data;
@@ -880,7 +1100,57 @@ static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f)
 	return 0;
 }
 
-static struct ioengine_ops ioengine = {
+static int fio_ioring_cmd_close_file(struct thread_data *td,
+				     struct fio_file *f)
+{
+	struct ioring_data *ld = td->io_ops_data;
+	struct ioring_options *o = td->eo;
+
+	if (o->cmd_type == FIO_URING_CMD_NVME) {
+		struct nvme_data *data = FILE_ENG_DATA(f);
+
+		FILE_SET_ENG_DATA(f, NULL);
+		free(data);
+	}
+	if (!ld || !o->registerfiles)
+		return generic_close_file(td, f);
+
+	f->fd = -1;
+	return 0;
+}
+
+static int fio_ioring_cmd_get_file_size(struct thread_data *td,
+					struct fio_file *f)
+{
+	struct ioring_options *o = td->eo;
+
+	if (fio_file_size_known(f))
+		return 0;
+
+	if (o->cmd_type == FIO_URING_CMD_NVME) {
+		struct nvme_data *data = NULL;
+		unsigned int nsid, lba_size = 0;
+		unsigned long long nlba = 0;
+		int ret;
+
+		ret = fio_nvme_get_info(f, &nsid, &lba_size, &nlba);
+		if (ret)
+			return ret;
+
+		data = calloc(1, sizeof(struct nvme_data));
+		data->nsid = nsid;
+		data->lba_size = lba_size;
+
+		f->real_file_size = lba_size * nlba;
+		fio_file_set_size_known(f);
+
+		FILE_SET_ENG_DATA(f, data);
+		return 0;
+	}
+	return generic_get_file_size(td, f);
+}
+
+static struct ioengine_ops ioengine_uring = {
 	.name			= "io_uring",
 	.version		= FIO_IOOPS_VERSION,
 	.flags			= FIO_ASYNCIO_SYNC_TRIM | FIO_NO_OFFLOAD,
@@ -900,13 +1170,35 @@ static struct ioengine_ops ioengine = {
 	.option_struct_size	= sizeof(struct ioring_options),
 };
 
+static struct ioengine_ops ioengine_uring_cmd = {
+	.name			= "io_uring_cmd",
+	.version		= FIO_IOOPS_VERSION,
+	.flags			= FIO_ASYNCIO_SYNC_TRIM | FIO_NO_OFFLOAD | FIO_MEMALIGN | FIO_RAWIO,
+	.init			= fio_ioring_init,
+	.post_init		= fio_ioring_cmd_post_init,
+	.io_u_init		= fio_ioring_io_u_init,
+	.prep			= fio_ioring_cmd_prep,
+	.queue			= fio_ioring_queue,
+	.commit			= fio_ioring_commit,
+	.getevents		= fio_ioring_getevents,
+	.event			= fio_ioring_cmd_event,
+	.cleanup		= fio_ioring_cleanup,
+	.open_file		= fio_ioring_cmd_open_file,
+	.close_file		= fio_ioring_cmd_close_file,
+	.get_file_size		= fio_ioring_cmd_get_file_size,
+	.options		= options,
+	.option_struct_size	= sizeof(struct ioring_options),
+};
+
 static void fio_init fio_ioring_register(void)
 {
-	register_ioengine(&ioengine);
+	register_ioengine(&ioengine_uring);
+	register_ioengine(&ioengine_uring_cmd);
 }
 
 static void fio_exit fio_ioring_unregister(void)
 {
-	unregister_ioengine(&ioengine);
+	unregister_ioengine(&ioengine_uring);
+	unregister_ioengine(&ioengine_uring_cmd);
 }
 #endif
file.h +7 -5
index faf65a2a..da1b8947 100644
@@ -126,12 +126,14 @@ struct fio_file {
 	unsigned int last_write_idx;
 
 	/*
-	 * For use by the io engine for offset or private data storage
+	 * For use by the io engine to store offset
 	 */
-	union {
-		uint64_t engine_pos;
-		void *engine_data;
-	};
+	uint64_t engine_pos;
+
+	/*
+	 * For use by the io engine for private data storage
+	 */
+	void *engine_data;
 
 	/*
 	 * if io is protected by a semaphore, this is set
os/linux/io_uring.h +9 -0
index 2fa66135..929997f8 100644
@@ -22,6 +22,7 @@ struct io_uring_sqe {
 	union {
 		__u64	off;	/* offset into file */
 		__u64	addr2;
+		__u32	cmd_op;
 	};
 	union {
 		__u64	addr;	/* pointer to buffer or iovecs */
@@ -171,6 +172,14 @@ enum {
 	IORING_OP_MKDIRAT,
 	IORING_OP_SYMLINKAT,
 	IORING_OP_LINKAT,
+	IORING_OP_MSG_RING,
+	IORING_OP_FSETXATTR,
+	IORING_OP_SETXATTR,
+	IORING_OP_FGETXATTR,
+	IORING_OP_GETXATTR,
+	IORING_OP_SOCKET,
+	IORING_OP_URING_CMD,
+
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
Signature · 1 line
2.17.1
#12 lore raw

Re: [PATCH v2 4/8] engines/io_uring: add new I/O engine for uring passthrough support

Quoted 9 lines · Ankit Kumar

From: Anuj Gupta <[email protected]>

Add a new I/O engine (io_uring_cmd) for sending uring passthrough commands. It will also use most of the existing helpers from the I/O engine io_uring. The I/O preparation, completion, file open, file close and post init paths are going to differ and hence io_uring_cmd will have its own helper for them.

Add a new io_uring_cmd engine specific option to support nvme

Is "-cmd_type=nvme" the specific option? Putting it here in the message should help.

Quoted 9 lines

passthrough commands. Filename name for this specific option must specify nvme-ns generic character device (dev/ngXnY). This provides io_uring_cmd I/O engine a bandwidth to support various passthrough commands in future.

The engine_pos and engine_data fields in struct fio_file are separated now. This will help I/O engine io_uring_cmd to store specific data as well as keep track of register files.

Quoted 7 lines

The supported options for io_uring_cmd I/O engine are:
* registerfiles
* sqthread_poll
* sqthread_poll_cpu
* cmd_type
* nonvectored
* force_async

Since this code seems to support passing other options (e.g. fixedbufs, hipri etc.) too, above comment is bit confusing. If it is about listing what kernel supports at the moment, this seems misplaced.

Quoted 2 lines
#13 lore raw

PATCH v2 5/8 docs: document options for io_uring_cmd I/O engine

In reply to Ankit Kumar

Update documentation with io_uring_cmd I/O engine specific options. Add missing io_uring I/O engine entry from fio man page. Update docs with missing io_uring engine specific options.

---
 HOWTO.rst | 39 ++++++++++++++++++++++++++++++---------
 fio.1     | 28 +++++++++++++++++++++++++---
 2 files changed, 55 insertions(+), 12 deletions(-)
HOWTO.rst +30 -9
index 84bea5c5..fb06a788 100644
@@ -1948,6 +1948,10 @@ I/O engine
 			for both direct and buffered IO.
 			This engine defines engine specific options.
 
+		**io_uring_cmd**
+			Fast Linux native asynchronous I/O for pass through commands.
+			This engine defines engine specific options.
+
 		**libaio**
 			Linux native asynchronous I/O. Note that Linux may only support
 			queued behavior with non-buffered I/O (set ``direct=1`` or
@@ -2253,20 +2257,32 @@ with the caveat that when used on the command line, they must come after the
 
 .. option:: fixedbufs : [io_uring]
 
-    If fio is asked to do direct IO, then Linux will map pages for each
-    IO call, and release them when IO is done. If this option is set, the
-    pages are pre-mapped before IO is started. This eliminates the need to
-    map and release for each IO. This is more efficient, and reduces the
-    IO latency as well.
+	If fio is asked to do direct IO, then Linux will map pages for each
+	IO call, and release them when IO is done. If this option is set, the
+	pages are pre-mapped before IO is started. This eliminates the need to
+	map and release for each IO. This is more efficient, and reduces the
+	IO latency as well.
+
+.. option:: nonvectored : [io_uring] [io_uring_cmd]
+
+	With this option, fio will use non-vectored read/write commands, where
+	address must contain the address directly.
 
-.. option:: registerfiles : [io_uring]
+.. option:: force_async=int : [io_uring] [io_uring_cmd]
+
+	Normal operation for io_uring is to try and issue an sqe as
+	non-blocking first, and if that fails, execute it in an async manner.
+	With this option set to N, then every N request fio will ask sqe to
+	be issued in an async manner.
+
+.. option:: registerfiles : [io_uring] [io_uring_cmd]
 
 	With this option, fio registers the set of files being used with the
 	kernel. This avoids the overhead of managing file counts in the kernel,
 	making the submission and completion part more lightweight. Required
 	for the below :option:`sqthread_poll` option.
 
-.. option:: sqthread_poll : [io_uring] [xnvme]
+.. option:: sqthread_poll : [io_uring] [io_uring_cmd] [xnvme]
 
 	Normally fio will submit IO by issuing a system call to notify the
 	kernel of available items in the SQ ring. If this option is set, the
@@ -2274,14 +2290,19 @@ with the caveat that when used on the command line, they must come after the
 	This frees up cycles for fio, at the cost of using more CPU in the
 	system.
 
-.. option:: sqthread_poll_cpu : [io_uring]
+.. option:: sqthread_poll_cpu : [io_uring] [io_uring_cmd]
 
 	When :option:`sqthread_poll` is set, this option provides a way to
 	define which CPU should be used for the polling thread.
 
+.. option:: cmd_type=str : [io_uring_cmd]
+
+	Specifies the type of uring passthrough command to be used. Supported
+	value is nvme.
+
 .. option:: hipri
 
-   [io_uring], [xnvme]
+   [io_uring] [xnvme]
 
         If this option is set, fio will attempt to use polled IO completions.
         Normal IO completions generate interrupts to signal the completion of
fio.1 +25 -3
index ded7bbfc..66d4adbb 100644
@@ -1738,6 +1738,15 @@ Basic \fBpreadv\fR\|(2) or \fBpwritev\fR\|(2) I/O.
 .B pvsync2
 Basic \fBpreadv2\fR\|(2) or \fBpwritev2\fR\|(2) I/O.
 .TP
+.B io_uring
+Fast Linux native asynchronous I/O. Supports async IO
+for both direct and buffered IO.
+This engine defines engine specific options.
+.TP
+.B io_uring_cmd
+Fast Linux native asynchronous I/O for passthrough commands.
+This engine defines engine specific options.
+.TP
 .B libaio
 Linux native asynchronous I/O. Note that Linux may only support
 queued behavior with non-buffered I/O (set `direct=1' or
@@ -2045,6 +2054,15 @@ release them when IO is done. If this option is set, the pages are pre-mapped
 before IO is started. This eliminates the need to map and release for each IO.
 This is more efficient, and reduces the IO latency as well.
 .TP
+.BI (io_uring,io_uring_cmd)nonvectored
+With this option, fio will use non-vectored read/write commands, where address
+must contain the address directly.
+.TP
+.BI (io_uring,io_uring_cmd)force_async
+Normal operation for io_uring is to try and issue an sqe as non-blocking first,
+and if that fails, execute it in an async manner. With this option set to N,
+then every N request fio will ask sqe to be issued in an async manner.
+.TP
 .BI (io_uring,xnvme)hipri
 If this option is set, fio will attempt to use polled IO completions. Normal IO
 completions generate interrupts to signal the completion of IO, polled
@@ -2052,22 +2070,26 @@ completions do not. Hence they are require active reaping by the application.
 The benefits are more efficient IO for high IOPS scenarios, and lower latencies
 for low queue depth IO.
 .TP
-.BI (io_uring)registerfiles
+.BI (io_uring,io_uring_cmd)registerfiles
 With this option, fio registers the set of files being used with the kernel.
 This avoids the overhead of managing file counts in the kernel, making the
 submission and completion part more lightweight. Required for the below
 sqthread_poll option.
 .TP
-.BI (io_uring,xnvme)sqthread_poll
+.BI (io_uring,io_uring_cmd,xnvme)sqthread_poll
 Normally fio will submit IO by issuing a system call to notify the kernel of
 available items in the SQ ring. If this option is set, the act of submitting IO
 will be done by a polling thread in the kernel. This frees up cycles for fio, at
 the cost of using more CPU in the system.
 .TP
-.BI (io_uring)sqthread_poll_cpu
+.BI (io_uring,io_uring_cmd)sqthread_poll_cpu
 When `sqthread_poll` is set, this option provides a way to define which CPU
 should be used for the polling thread.
 .TP
+.BI (io_uring_cmd)cmd_type \fR=\fPstr
+Specifies the type of uring passthrough command to be used. Supported
+value is nvme.
+.TP
 .BI (libaio)userspace_reap
 Normally, with the libaio engine in use, fio will use the
 \fBio_getevents\fR\|(3) system call to reap newly returned events. With
Signature · 1 line
2.17.1
#14 lore raw

Re: [PATCH v2 5/8] docs: document options for io_uring_cmd I/O engine

Quoted 16 lines · Ankit Kumar

.B libaio
Linux native asynchronous I/O. Note that Linux may only support queued behavior with non-buffered I/O (set `direct=1' or

(quoted diff) +0 -0
@@ -2045,6 +2054,15 @@ release them when IO is done. If this option is set, the pages are pre-mapped

before IO is started. This eliminates the need to map and release for each IO. This is more efficient, and reduces the IO latency as well.
.TP
+.BI (io_uring,io_uring_cmd)nonvectored

fio.1 +8 -0
+With this option, fio will use non-vectored read/write commands, where address
+must contain the address directly.
+.TP
+.BI (io_uring,io_uring_cmd)force_async
+Normal operation for io_uring is to try and issue an sqe as non-blocking first,
+and if that fails, execute it in an async manner. With this option set to N,
+then every N request fio will ask sqe to be issued in an async manner.
+.TP
Quoted 1 line

.BI (io_uring,xnvme)hipri

io_uring_cmd should be added here? And same for fixedbufs too.

Quoted 26 lines

If this option is set, fio will attempt to use polled IO completions. Normal IO completions generate interrupts to signal the completion of IO, polled

(quoted diff) +0 -0
@@ -2052,22 +2070,26 @@ completions do not. Hence they are require active reaping by the application.

The benefits are more efficient IO for high IOPS scenarios, and lower latencies for low queue depth IO.
.TP
-.BI (io_uring)registerfiles
+.BI (io_uring,io_uring_cmd)registerfiles
With this option, fio registers the set of files being used with the kernel. This avoids the overhead of managing file counts in the kernel, making the submission and completion part more lightweight. Required for the below sqthread_poll option.
.TP
-.BI (io_uring,xnvme)sqthread_poll
+.BI (io_uring,io_uring_cmd,xnvme)sqthread_poll
Normally fio will submit IO by issuing a system call to notify the kernel of available items in the SQ ring. If this option is set, the act of submitting IO will be done by a polling thread in the kernel. This frees up cycles for fio, at the cost of using more CPU in the system.
.TP
-.BI (io_uring)sqthread_poll_cpu
+.BI (io_uring,io_uring_cmd)sqthread_poll_cpu
When sqthread_poll is set, this option provides a way to define which CPU should be used for the polling thread.
.TP
+.BI (io_uring_cmd)cmd_type \fR=\fPstr

Review

Quoted 2 lines
(quoted diff) +2 -0
+Specifies the type of uring passthrough command to be used. Supported
+value is nvme.

Seems that is default value too. So that part needs to be mentioned here.

#15 lore raw

Re: [PATCH v2 5/8] docs: document options for io_uring_cmd I/O engine

Quoted 12 lines · Kanchan Joshi
Quoted 11 lines · Ankit Kumar

.B libaio
Linux native asynchronous I/O. Note that Linux may only support queued behavior with non-buffered I/O (set `direct=1' or

(quoted diff) +0 -0
@@ -2045,6 +2054,15 @@ release them when IO is done. If this option is set, the pages are pre-mapped

before IO is started. This eliminates the need to map and release for each IO. This is more efficient, and reduces the IO latency as well.
.TP
+.BI (io_uring,io_uring_cmd)nonvectored

fio.1 +3 -0
+With this option, fio will use non-vectored read/write commands, where address
+must contain the address directly.
+.TP
Quoted 9 lines
Quoted 6 lines

+.BI (io_uring,io_uring_cmd)force_async

fio.1 +4 -0
+Normal operation for io_uring is to try and issue an sqe as non-blocking first,
+and if that fails, execute it in an async manner. With this option set to N,
+then every N request fio will ask sqe to be issued in an async manner.
+.TP

.BI (io_uring,xnvme)hipri

io_uring_cmd should be added here? And same for fixedbufs too.

Agreed, will be done in v3

Quoted 23 lines
Quoted 23 lines

If this option is set, fio will attempt to use polled IO completions. Normal IO completions generate interrupts to signal the completion of IO, polled

(quoted diff) +0 -0
@@ -2052,22 +2070,26 @@ completions do not. Hence they are require active reaping by the application.

The benefits are more efficient IO for high IOPS scenarios, and lower latencies for low queue depth IO.
.TP
-.BI (io_uring)registerfiles
+.BI (io_uring,io_uring_cmd)registerfiles
With this option, fio registers the set of files being used with the kernel. This avoids the overhead of managing file counts in the kernel, making the submission and completion part more lightweight. Required for the below sqthread_poll option.
.TP
-.BI (io_uring,xnvme)sqthread_poll
+.BI (io_uring,io_uring_cmd,xnvme)sqthread_poll
Normally fio will submit IO by issuing a system call to notify the kernel of available items in the SQ ring. If this option is set, the act of submitting IO will be done by a polling thread in the kernel. This frees up cycles for fio, at the cost of using more CPU in the system.
.TP
-.BI (io_uring)sqthread_poll_cpu
+.BI (io_uring,io_uring_cmd)sqthread_poll_cpu
When sqthread_poll is set, this option provides a way to define which CPU

Quoted 8 lines

Review

Quoted 5 lines

should be used for the polling thread.
.TP
+.BI (io_uring_cmd)cmd_type \fR=\fPstr

(quoted diff) +2 -0
+Specifies the type of uring passthrough command to be used. Supported
+value is nvme.

Seems that is default value too. So that part needs to be mentioned here.

Yes, will add it in v3

#16 lore raw

RE: [PATCH v2 5/8] docs: document options for io_uring_cmd I/O engine

In reply to Ankit Kumar
Quoted 21 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]
Sent: Thursday, May 26, 2022 10:48 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ankit Kumar <[email protected]>
Subject: [PATCH v2 5/8] docs: document options for io_uring_cmd I/O engine

Update documentation with io_uring_cmd I/O engine specific options. Add missing io_uring I/O engine entry from fio man page. Update docs with missing io_uring engine specific options.

---

+.. option:: nonvectored : [io_uring] [io_uring_cmd]

(quoted diff) +2 -0
+
+	With this option, fio will use non-vectored read/write commands,

where

HOWTO.rst with the caveat that when used on the command line, they must come after the · line 2277

Quoted 10 lines
HOWTO.rst +8 -1
+	address must contain the address directly.
 
-.. option:: registerfiles : [io_uring]
+.. option:: force_async=int : [io_uring] [io_uring_cmd]
+
+	Normal operation for io_uring is to try and issue an sqe as
+	non-blocking first, and if that fails, execute it in an async manner.
+	With this option set to N, then every N request fio will ask sqe to
+	be issued in an async manner.
+

It would be helpful to state the default values for nonvectored and force_async.

#17 lore raw

PATCH v2 6/8 zbd: Check for direct flag only if its block device

In reply to Ankit Kumar

nvme-ns generic character devices currently do not support O_DIRECT flag. Check for fio option for direct flag only if filetype is a block device.

t/zbd skip test case #1 for character devices as don't require direct I/O.

---
 t/zbd/test-zbd-support | 3 ++-
 zbd.c                  | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
t/zbd/test-zbd-support +2 -1
index 7e2fff00..a1ec5684 100755
@@ -251,8 +251,9 @@ require_conv_zones() {
 	return 0
 }
 
-# Check whether buffered writes are refused.
+# Check whether buffered writes are refused for regular block devices.
 test1() {
+    require_regular_block_dev || return $SKIP_TESTCASE
     run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K	\
 	    "$(ioengine "psync")" --size="${zone_size}" --thread=1	\
 	    --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
zbd.c +2 -2
index b1fd6b4b..627fb968 100644
@@ -466,7 +466,7 @@ out:
 	return res;
 }
 
-/* Verify whether direct I/O is used for all host-managed zoned drives. */
+/* Verify whether direct I/O is used for all host-managed zoned block drives. */
 static bool zbd_using_direct_io(void)
 {
 	struct thread_data *td;
@@ -477,7 +477,7 @@ static bool zbd_using_direct_io(void)
 		if (td->o.odirect || !(td->o.td_ddir & TD_DDIR_WRITE))
 			continue;
 		for_each_file(td, f, j) {
-			if (f->zbd_info &&
+			if (f->zbd_info && f->filetype == FIO_TYPE_BLOCK &&
 			    f->zbd_info->model == ZBD_HOST_MANAGED)
 				return false;
 		}
Signature · 1 line
2.17.1
Tested-by on v2 6/8
#18 lore raw

RE: [PATCH v2 6/8] zbd: Check for direct flag only if its block device

Quoted 13 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]
Sent: Thursday, May 26, 2022 10:48 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ankit Kumar <[email protected]>
Subject: [PATCH v2 6/8] zbd: Check for direct flag only if its block device

nvme-ns generic character devices currently do not support O_DIRECT flag.
Check for fio option for direct flag only if filetype is a block device.

Quoted 5 lines

t/zbd skip test case #1 for character devices as don't require direct I/O.

---

I tested this with a zoned scsi_debug device created by:

modprobe scsi_debug zbc=2

I observed that running

t/zbd/test-zbd-support -t 1 -l /dev/sg2

on v1 of this patch series produced a test failure whereas on v2 of this patch series the test case is appropriately skipped.

#19 lore raw

Re: [PATCH v2 6/8] zbd: Check for direct flag only if its block device

In reply to Ankit Kumar
Quoted 17 lines · Ankit Kumar

nvme-ns generic character devices currently do not support O_DIRECT flag. Check for fio option for direct flag only if filetype is a block device.

t/zbd skip test case #1 for character devices as don't require direct I/O.

---
 t/zbd/test-zbd-support | 3 ++-
 zbd.c                  | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
t/zbd/test-zbd-support +0 -0
index 7e2fff00..a1ec5684 100755

t/zbd/test-zbd-support require_conv_zones() { · line 256

Quoted 7 lines
t/zbd/test-zbd-support +2 -1
@@ -251,8 +251,9 @@ require_conv_zones() {
 	return 0
 }
 
-# Check whether buffered writes are refused.
+# Check whether buffered writes are refused for regular block devices.
 test1() {
+    require_regular_block_dev || return $SKIP_TESTCASE

Hmm, this change skips this test case for character devices, but it also skips for zoned block devices. Not good. This test case should not be skipped for block devices for both zoned and non-zoned. The word "regular" in the the helper function require_regular_block_dev() means "non-zoned". So it ensures that the test target device is a *non-zoned* block device.

To skip this test case for character devices and run for block devices, a new helper function require_block_dev() will be needed.

Quoted 28 lines
t/zbd/test-zbd-support +0 -0
     run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K	\
 	    "$(ioengine "psync")" --size="${zone_size}" --thread=1	\
 	    --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
zbd.c +2 -2
index b1fd6b4b..627fb968 100644
@@ -466,7 +466,7 @@ out:
 	return res;
 }
 
-/* Verify whether direct I/O is used for all host-managed zoned drives. */
+/* Verify whether direct I/O is used for all host-managed zoned block drives. */
 static bool zbd_using_direct_io(void)
 {
 	struct thread_data *td;
@@ -477,7 +477,7 @@ static bool zbd_using_direct_io(void)
 		if (td->o.odirect || !(td->o.td_ddir & TD_DDIR_WRITE))
 			continue;
 		for_each_file(td, f, j) {
-			if (f->zbd_info &&
+			if (f->zbd_info && f->filetype == FIO_TYPE_BLOCK &&
 			    f->zbd_info->model == ZBD_HOST_MANAGED)
 				return false;
 		}
Signature · 1 line
2.17.1
Signature · 1 line
Shin'ichiro Kawasaki
#20 lore raw

PATCH v2 7/8 engines/io_uring: Enable zone device support for io_uring_cmd I/O engine

In reply to Ankit Kumar

Add zone device specific ioengine_ops for io_uring_cmd.
* get_zoned_model
* report_zones
* reset_wp
* get_max_open_zones

Add the necessary NVMe ZNS specfication opcodes and strcutures. Add helper functions to submit admin and I/O passthrough commands for these new NVMe ZNS specific commands.

For write workload iodepth must be set to 1 as there is no IO scheduler

---
 engines/io_uring.c |  32 ++++++
 engines/nvme.c     | 238 +++++++++++++++++++++++++++++++++++++++++++++
 engines/nvme.h     |  81 ++++++++++++++-
 3 files changed, 350 insertions(+), 1 deletion(-)
engines/io_uring.c +32 -0
index 2088ac47..2457a7a3 100644
@@ -1150,6 +1150,34 @@ static int fio_ioring_cmd_get_file_size(struct thread_data *td,
 	return generic_get_file_size(td, f);
 }
 
+static int fio_ioring_cmd_get_zoned_model(struct thread_data *td,
+					  struct fio_file *f,
+					  enum zbd_zoned_model *model)
+{
+	return fio_nvme_get_zoned_model(td, f, model);
+}
+
+static int fio_ioring_cmd_report_zones(struct thread_data *td,
+				       struct fio_file *f, uint64_t offset,
+				       struct zbd_zone *zbdz,
+				       unsigned int nr_zones)
+{
+	return fio_nvme_report_zones(td, f, offset, zbdz, nr_zones);
+}
+
+static int fio_ioring_cmd_reset_wp(struct thread_data *td, struct fio_file *f,
+				   uint64_t offset, uint64_t length)
+{
+	return fio_nvme_reset_wp(td, f, offset, length);
+}
+
+static int fio_ioring_cmd_get_max_open_zones(struct thread_data *td,
+					     struct fio_file *f,
+					     unsigned int *max_open_zones)
+{
+	return fio_nvme_get_max_open_zones(td, f, max_open_zones);
+}
+
 static struct ioengine_ops ioengine_uring = {
 	.name			= "io_uring",
 	.version		= FIO_IOOPS_VERSION,
@@ -1186,6 +1214,10 @@ static struct ioengine_ops ioengine_uring_cmd = {
 	.open_file		= fio_ioring_cmd_open_file,
 	.close_file		= fio_ioring_cmd_close_file,
 	.get_file_size		= fio_ioring_cmd_get_file_size,
+	.get_zoned_model	= fio_ioring_cmd_get_zoned_model,
+	.report_zones		= fio_ioring_cmd_report_zones,
+	.reset_wp		= fio_ioring_cmd_reset_wp,
+	.get_max_open_zones	= fio_ioring_cmd_get_max_open_zones,
 	.options		= options,
 	.option_struct_size	= sizeof(struct ioring_options),
 };
engines/nvme.c +238 -0

241 lines not on this page · raw message

engines/nvme.h +80 -1

104 lines not on this page · raw message

Signature · 1 line
2.17.1
Tested-by on v2 7/8
#21 lore raw

RE: [PATCH v2 7/8] engines/io_uring: Enable zone device support for io_uring_cmd I/O engine

Quoted 16 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]
Sent: Thursday, May 26, 2022 10:48 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ankit Kumar <[email protected]>
Subject: [PATCH v2 7/8] engines/io_uring: Enable zone device support for io_uring_cmd I/O engine

Add zone device specific ioengine_ops for io_uring_cmd.
* get_zoned_model
* report_zones
* reset_wp
* get_max_open_zones

Quoted 8 lines

Add the necessary NVMe ZNS specfication opcodes and strcutures. Add helper functions to submit admin and I/O passthrough commands for these
new NVMe ZNS specific commands.

For write workload iodepth must be set to 1 as there is no IO scheduler

I ran the job file below on an emulated ZNS device under QEMU and found no problems.

[global]
filename=/dev/ng0n1
ioengine=io_uring_cmd
cmd_type=nvme
zonemode=zbd
bs=256K
verify=crc32c
stonewall=1

[write-plain]
rw=randwrite

[randwrite-plain]
rw=randwrite

[write-opts]
rw=randwrite
registerfiles=1
sqthread_poll=1
sqthread_poll_cpu=0

[randwrite-opts]
rw=randwrite
registerfiles=1
sqthread_poll=1
sqthread_poll_cpu=0

#22 lore raw

PATCH v2 8/8 examples: add 2 example job file for io_uring_cmd engine

In reply to Ankit Kumar

From: Anuj Gupta <[email protected]>

examples/uring-cmd-ng.fio has usage for conventional nvme-ns char device examples/uring-cmd-zoned.fio has usage for ZNS nvme-ns char device

---
 examples/uring-cmd-ng.fio    | 35 +++++++++++++++++++++++++++++++
 examples/uring-cmd-zoned.fio | 40 ++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 examples/uring-cmd-ng.fio
 create mode 100644 examples/uring-cmd-zoned.fio
examples/uring-cmd-ng.fio new file +35 -0
new file mode 100644
index 00000000..db4292d3
@@ -0,0 +1,35 @@
+; io_uring_cmd I/O engine for nvme-ns generic character device
+;
+; This job-file is intended to be used as:
+;
+; fio examples/uring-cmd-ng.fio \
+;   --section=default \
+;   --ioengine=io_uring_cmd \
+;   --sqthread_poll=1 \
+;   --cmd_type=nvme \
+;   --filename=/dev/ng0n1
+;
+; NOTE: If you want to override the default bs, iodepth, and workload, then
+; invoke it as:
+;
+; FIO_BS="512" FIO_RW="write" FIO_IODEPTH=16 fio examples/uring-cmd-ng.fio \
+;   --section=override --ioengine=io_uring_cmd --cmd_type=nvme \
+;   --filename=/dev/ng0n1
+;
+[global]
+rw=randread
+size=12G
+iodepth=1
+bs=4K
+thread=1
+time_based=1
+runtime=7
+ramp_time=3
+norandommap=1
+
+[default]
+
+[override]
+rw=${FIO_RW}
+iodepth=${FIO_IODEPTH}
+bs=${FIO_BS}
examples/uring-cmd-zoned.fio new file +40 -0
new file mode 100644
index 00000000..2649d2fe
@@ -0,0 +1,40 @@
+; io_uring_cmd I/O engine for nvme-ns generic zoned character device
+;
+; NOTE: with write workload iodepth must be set to 1 as there is no IO
+; scheduler.
+;
+; Writes 1GB at QD1 using 4K BS and verifies it.
+;
+; This job-file is intended to be used as:
+;
+; fio examples/uring-cmd-zoned.fio \
+;   --section=default \
+;   --ioengine=io_uring_cmd \
+;   --sqthread_poll=1 \
+;   --cmd_type=nvme \
+;   --filename=/dev/ng0n1
+;
+; NOTE: If you want to override the default bs, size and workload, then
+; invoke it as:
+;
+; FIO_BS="32k" FIO_RW="randwrite" FIO_SIZE="2G" fio \
+;   examples/uring-cmd-zoned.fio --section=override --ioengine=io_uring_cmd \
+;   --sqthread_poll=1 --cmd_type=nvme --filename=/dev/ng0n1
+;
+[global]
+zonemode=zbd
+rw=write
+size=1G
+iodepth=1
+bs=4K
+thread=1
+ramp_time=1
+norandommap=1
+verify=crc32c
+
+[default]
+
+[override]
+rw=${FIO_RW}
+size=${FIO_SIZE}
+bs=${FIO_BS}
Signature · 1 line
2.17.1
Tested-by on v2 8/8
#23 lore raw

RE: [PATCH v2 8/8] examples: add 2 example job file for io_uring_cmd engine

Quoted 11 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]
Sent: Thursday, May 26, 2022 10:48 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 8/8] examples: add 2 example job file for io_uring_cmd engine

From: Anuj Gupta <[email protected]>

Quoted 7 lines

examples/uring-cmd-ng.fio has usage for conventional nvme-ns char device
examples/uring-cmd-zoned.fio has usage for ZNS nvme-ns char device

---

A minor nit: consider putting ioengine=io_uring_cmd and cmd_type=nvme directly in the job file.

#24 lore raw

Re: [PATCH v2 8/8] examples: add 2 example job file for io_uring_cmd engine

Quoted 15 lines · Vincent Fu
Quoted 15 lines

-----Original Message-----
From: Ankit Kumar [mailto:[email protected]]
Sent: Thursday, May 26, 2022 10:48 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 8/8] examples: add 2 example job file for io_uring_cmd engine

From: Anuj Gupta <[email protected]>

examples/uring-cmd-ng.fio has usage for conventional nvme-ns char device
examples/uring-cmd-zoned.fio has usage for ZNS nvme-ns char device

Quoted 6 lines
Quoted 3 lines

---

A minor nit: consider putting ioengine=io_uring_cmd and cmd_type=nvme directly in the job file.

Seconded - mixed job files generally only make sense for some kind of testing framework, the example job files should be runnable directly without using any args of environment variables.

Signature · 1 line
Jens Axboe
#25 lore raw

Re: [PATCH v2 0/8] Add support for uring passthrough commands

In reply to Ankit Kumar
Quoted 2 lines · Ankit Kumar

* force_async
* cmd_type (new)

when cmd_type is not nvme (and something random is passed), it shows the error message but run continues with default type (i.e. nvme). Something to fix there.

#26 lore raw

Re: [PATCH v2 0/8] Add support for uring passthrough commands

Quoted 7 lines · Kanchan Joshi
Quoted 2 lines · Ankit Kumar

* force_async
* cmd_type (new)

when cmd_type is not nvme (and something random is passed), it shows the error message but run continues with default type (i.e. nvme). Something to fix there.

Thanks, will fix this in v3.