Skip to contentSkip to conversation

support ZONE_RESET_ALL in liburing v2

PATCH In review Christoph Hellwig 2 participants 8 messages Aug 12 io_uring

lore
Share & tools
lore
#0 lore raw

Hi Jens,

this is the liburing support for the just submitted ZONE_RESET_ALL uring cmd support. Also a few fixup for the discard support that stood model.

Changes since v1:
- misc spelling fixes

#1 lore raw

PATCH 1/5 configure: shorten the message for the discard command

The current message is pretty long, drop the redundant io_uring. This aligns it with the soon to be added zone_reset_all message.

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
index 39c377c9bf8b..b953eddd6ddc 100755
@@ -467,7 +467,7 @@ EOF
 if compile_prog "" "" "discard command"; then
   discard_cmd="yes"
 fi
-print_config "io_uring discard command support" "$discard_cmd"
+print_config "discard command support" "$discard_cmd"
 
 ##########################################
 # Check idtype_t support
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/5 man: fixups for io_uring_prep_cmd_discard.3

In reply to Christoph Hellwig

Mention the ioctl this is modelled after instead of the io_uring cmd used to implement io_uring_prep_cmd_discard.3, and drop an incorrect plural for page cache.

---
 man/io_uring_prep_cmd_discard.3 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
man/io_uring_prep_cmd_discard.3 +4 -4
index 97786726f03b..349df86ff9c9 100644
@@ -26,14 +26,14 @@ to start discarding
 at the specified
 .IR offset .
 
-The command is an asynchronous equivalent of
-.B BLOCK_URING_CMD_DISCARD
+The command is an asynchronous equivalent of the
+.B BLKDISCARD
 ioctl with a few differences. It allows multiple parallel discards, and it does
 not exclude concurrent writes and reads. As a result, it may lead to races for
 the data on the disk, if the application has IO inflight for the same ranges
 that the discard operates on. It's the user's responsibility to account for that.
-Furthermore, only best efforts are done to invalidate page caches. The user has
-to make sure that no other inflight requests are modifying or reading the
+Furthermore, only best efforts are done to invalidate the page cache. The user
+has to make sure that no other inflight requests are modifying or reading the
 range(s). If that is the case, it might result in stale page cache and data
 inconsistencies.
 
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/5 liburing: add io_uring_prep_cmd_zone_reset

In reply to Christoph Hellwig

Add a helper for io_uring zone_reset_all commands.

---
 configure              | 31 +++++++++++++++++++++++++++++++
 src/include/liburing.h |  7 +++++++
 src/liburing-ffi.map   |  5 +++++
 3 files changed, 43 insertions(+)
configure +31 -0
index b953eddd6ddc..8c5ca801f487 100755
@@ -469,6 +469,21 @@ if compile_prog "" "" "discard command"; then
 fi
 print_config "discard command support" "$discard_cmd"
 
+##########################################
+# Check block zone_reset_all cmd support
+zone_reset_all_cmd="no"
+cat > $TMPC << EOF
+#include <linux/blkdev.h>
+int main(void)
+{
+  return BLOCK_URING_CMD_ZONE_RESET_ALL;
+}
+EOF
+if compile_prog "" "" "zone_reset_all command"; then
+  zone_reset_all_cmd="yes"
+fi
+print_config "zone_reset_all command support" "$zone_reset_all_cmd"
+
 ##########################################
 # Check idtype_t support
 has_idtype_t="no"
@@ -797,6 +812,22 @@ else cat >> $compat_h << EOF
 EOF
 fi
 
+if test "$zone_reset_all_cmd" != "yes"; then
+cat >> $compat_h << EOF
+
+#include <linux/ioctl.h>
+
+#ifndef BLOCK_URING_CMD_ZONE_RESET_ALL
+#define BLOCK_URING_CMD_ZONE_RESET_ALL			_IO(0x12, 1)
+#endif
+
+EOF
+else cat >> $compat_h << EOF
+#include <linux/blkdev.h>
+
+EOF
+fi
+
 cat >> $compat_h << EOF
 #endif
 EOF
src/include/liburing.h +7 -0
index 0188937b0de4..214c7778d6a7 100644
@@ -1685,6 +1685,13 @@ IOURINGINLINE void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe,
 	sqe->addr3 = nbytes;
 }
 
+IOURINGINLINE void io_uring_prep_cmd_zone_reset_all(struct io_uring_sqe *sqe,
+						    int fd)
+	LIBURING_NOEXCEPT
+{
+	io_uring_prep_uring_cmd(sqe, BLOCK_URING_CMD_ZONE_RESET_ALL, fd);
+}
+
 IOURINGINLINE void io_uring_prep_pipe(struct io_uring_sqe *sqe, int *fds,
 				      int pipe_flags)
 {
src/liburing-ffi.map +5 -0
index bd7bc64416d3..fc9701b63907 100644
@@ -275,3 +275,8 @@ LIBURING_2.15 {
 		io_uring_register_zcrx_ctrl;
 		io_uring_register_query;
 } LIBURING_2.14;
+
+LIBURING_2.16 {
+	global:
+		io_uring_prep_cmd_zone_reset_all;
+} LIBURING_2.14;
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH 3/5] liburing: add io_uring_prep_cmd_zone_reset

Quoted 83 lines · Christoph Hellwig

Add a helper for io_uring zone_reset_all commands.

---
 configure              | 31 +++++++++++++++++++++++++++++++
 src/include/liburing.h |  7 +++++++
 src/liburing-ffi.map   |  5 +++++
 3 files changed, 43 insertions(+)
configure +31 -0
index b953eddd6ddc..8c5ca801f487 100755
@@ -469,6 +469,21 @@ if compile_prog "" "" "discard command"; then
 fi
 print_config "discard command support" "$discard_cmd"
 
+##########################################
+# Check block zone_reset_all cmd support
+zone_reset_all_cmd="no"
+cat > $TMPC << EOF
+#include <linux/blkdev.h>
+int main(void)
+{
+  return BLOCK_URING_CMD_ZONE_RESET_ALL;
+}
+EOF
+if compile_prog "" "" "zone_reset_all command"; then
+  zone_reset_all_cmd="yes"
+fi
+print_config "zone_reset_all command support" "$zone_reset_all_cmd"
+
 ##########################################
 # Check idtype_t support
 has_idtype_t="no"
@@ -797,6 +812,22 @@ else cat >> $compat_h << EOF
 EOF
 fi
 
+if test "$zone_reset_all_cmd" != "yes"; then
+cat >> $compat_h << EOF
+
+#include <linux/ioctl.h>
+
+#ifndef BLOCK_URING_CMD_ZONE_RESET_ALL
+#define BLOCK_URING_CMD_ZONE_RESET_ALL                 _IO(0x12, 1)
+#endif
+
+EOF
+else cat >> $compat_h << EOF
+#include <linux/blkdev.h>
+
+EOF
+fi
+
 cat >> $compat_h << EOF
 #endif
 EOF
src/include/liburing.h +7 -0
index 0188937b0de4..214c7778d6a7 100644
@@ -1685,6 +1685,13 @@ IOURINGINLINE void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe,
        sqe->addr3 = nbytes;
 }
 
+IOURINGINLINE void io_uring_prep_cmd_zone_reset_all(struct io_uring_sqe *sqe,
+                                                   int fd)
+       LIBURING_NOEXCEPT
+{
+       io_uring_prep_uring_cmd(sqe, BLOCK_URING_CMD_ZONE_RESET_ALL, fd);
+}
+
 IOURINGINLINE void io_uring_prep_pipe(struct io_uring_sqe *sqe, int *fds,
                                      int pipe_flags)
 {
src/liburing-ffi.map +0 -0
index bd7bc64416d3..fc9701b63907 100644

src/liburing-ffi.map LIBURING_2.15 { · line 282

Quoted 8 lines
src/liburing-ffi.map +5 -0
@@ -275,3 +275,8 @@ LIBURING_2.15 {
                io_uring_register_zcrx_ctrl;
                io_uring_register_query;
 } LIBURING_2.14;
+
+LIBURING_2.16 {
+       global:
+               io_uring_prep_cmd_zone_reset_all;
+} LIBURING_2.14;

Mentioned this on v1 too, but I think this should inherit from LIBURING_2.15.

Best,
Caleb

#5 lore raw

Re: [PATCH 3/5] liburing: add io_uring_prep_cmd_zone_reset

Quoted 86 lines · Caleb Sander Mateos
Quoted 85 lines · Christoph Hellwig

Add a helper for io_uring zone_reset_all commands.

---
 configure              | 31 +++++++++++++++++++++++++++++++
 src/include/liburing.h |  7 +++++++
 src/liburing-ffi.map   |  5 +++++
 3 files changed, 43 insertions(+)
configure +31 -0
index b953eddd6ddc..8c5ca801f487 100755
@@ -469,6 +469,21 @@ if compile_prog "" "" "discard command"; then
 fi
 print_config "discard command support" "$discard_cmd"
 
+##########################################
+# Check block zone_reset_all cmd support
+zone_reset_all_cmd="no"
+cat > $TMPC << EOF
+#include <linux/blkdev.h>
+int main(void)
+{
+  return BLOCK_URING_CMD_ZONE_RESET_ALL;
+}
+EOF
+if compile_prog "" "" "zone_reset_all command"; then
+  zone_reset_all_cmd="yes"
+fi
+print_config "zone_reset_all command support" "$zone_reset_all_cmd"
+
 ##########################################
 # Check idtype_t support
 has_idtype_t="no"
@@ -797,6 +812,22 @@ else cat >> $compat_h << EOF
 EOF
 fi
 
+if test "$zone_reset_all_cmd" != "yes"; then
+cat >> $compat_h << EOF
+
+#include <linux/ioctl.h>
+
+#ifndef BLOCK_URING_CMD_ZONE_RESET_ALL
+#define BLOCK_URING_CMD_ZONE_RESET_ALL                 _IO(0x12, 1)
+#endif
+
+EOF
+else cat >> $compat_h << EOF
+#include <linux/blkdev.h>
+
+EOF
+fi
+
 cat >> $compat_h << EOF
 #endif
 EOF
src/include/liburing.h +7 -0
index 0188937b0de4..214c7778d6a7 100644
@@ -1685,6 +1685,13 @@ IOURINGINLINE void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe,
        sqe->addr3 = nbytes;
 }
 
+IOURINGINLINE void io_uring_prep_cmd_zone_reset_all(struct io_uring_sqe *sqe,
+                                                   int fd)
+       LIBURING_NOEXCEPT
+{
+       io_uring_prep_uring_cmd(sqe, BLOCK_URING_CMD_ZONE_RESET_ALL, fd);
+}
+
 IOURINGINLINE void io_uring_prep_pipe(struct io_uring_sqe *sqe, int *fds,
                                      int pipe_flags)
 {
src/liburing-ffi.map +0 -0
index bd7bc64416d3..fc9701b63907 100644
@@ -275,3 +275,8 @@ LIBURING_2.15 {
                io_uring_register_zcrx_ctrl;
                io_uring_register_query;
Quoted 8 lines

src/liburing-ffi.map LIBURING_2.15 { · line 282

Quoted 6 lines
src/liburing-ffi.map +5 -0
 } LIBURING_2.14;
+
+LIBURING_2.16 {
+       global:
+               io_uring_prep_cmd_zone_reset_all;
+} LIBURING_2.14;

Mentioned this on v1 too, but I think this should inherit from LIBURING_2.15.

And I do remember it now that you mention it again, not sure why it splitted through sorry.

#6 lore raw

PATCH 4/5 man: add io_uring_prep_cmd_zone_reset_all.3 man page

In reply to Christoph Hellwig

Add documentation for the new zone reset all io_uring cmd.

---
 man/io_uring_prep_cmd_zone_reset_all.3 | 54 ++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 man/io_uring_prep_cmd_zone_reset_all.3
man/io_uring_prep_cmd_zone_reset_all.3 new file +54 -0
new file mode 100644
index 000000000000..9512fa6bbe73
@@ -0,0 +1,54 @@
+.\" Copyright (C) 2026 Christoph Hellwig <[email protected]>
+.\"
+.\" SPDX-License-Identifier: LGPL-2.0-or-later
+.\"
+.TH io_uring_prep_cmd_zone_reset_all 3 "Aug 11, 2026" "liburing-2.16" "liburing Manual"
+.SH NAME
+io_uring_prep_cmd_zone_reset_all \- prepare a zone_reset_all command
+.SH SYNOPSIS
+.nf
+.B #include <liburing.h>
+.PP
+.BI "void io_uring_prep_cmd_zone_reset_all(struct io_uring_sqe *" sqe ", int " fd ");"
+.fi
+.SH DESCRIPTION
+The
+.BR io_uring_prep_cmd_zone_reset_all (3)
+function prepares a zone_reset_all command request. The submission queue entry
+.I sqe
+is setup to reset all sequential write required zones on the block device
+pointed to by
+.IR fd .
+
+This command does not synchronize against concurrent file operations, including
+but not limited to reads, write, ioctls and other uring_cmds and only performs
+a best effort invalidation of the page cache for the device.  The user has
+to make sure that no other in-flight requests are modifying or reading the
+range(s). If that is the case, it might result in stale page cache and data
+inconsistencies.
+
+Available since Linux 7.TBD.
+
+.SH RETURN VALUE
+None
+.SH ERRORS
+The CQE
+.I res
+field will contain the result of the operation. On success, this field will be
+set to
+.B 0 .
+On error, a negative error value is returned. Note that where synchronous
+system calls will return
+.B -1
+on failure and set
+.I errno
+to the actual error value, io_uring never uses
+.IR errno .
+Instead it returns the negated
+.I errno
+directly in the CQE
+.I res
+field.
+.SH SEE ALSO
+.BR io_uring_get_sqe (3),
+.BR io_uring_submit (3),
Signature · 1 line
2.53.0
#7 lore raw

PATCH 5/5 test: add zone_reset_all command test

In reply to Christoph Hellwig

Basic sanity checking for the zone_reset_all command, mostly taken from the discard test.

---
 test/Makefile             |   1 +
 test/cmd-zone-reset-all.c | 164 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 165 insertions(+)
 create mode 100644 test/cmd-zone-reset-all.c
test/Makefile +1 -0
index d88a428774cc..8b276817d33c 100644
@@ -90,6 +90,7 @@ test_srcs := \
 	connect-rep.c \
 	coredump.c \
 	cmd-discard.c \
+	cmd-zone-reset-all.c \
 	cq-full.c \
 	cq-overflow.c \
 	cq-peek-batch.c \
test/cmd-zone-reset-all.c new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
2.53.0