From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Damien Le Moal <dlemoal@kernel.org>, io-uring@vger.kernel.org
Subject: [PATCH 5/5] test: add zone_reset_all command test
Date: Mon, 17 Aug 2026 10:28:32 +0200 [thread overview]
Message-ID: <20260817082837.762276-6-hch@lst.de> (raw)
In-Reply-To: <20260817082837.762276-1-hch@lst.de>
Basic sanity checking for the zone_reset_all command, mostly taken from
the discard test.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
test/Makefile | 1 +
test/cmd-zone-reset-all.c | 164 ++++++++++++++++++++++++++++++++++++++
2 files changed, 165 insertions(+)
create mode 100644 test/cmd-zone-reset-all.c
diff --git a/test/Makefile b/test/Makefile
index d88a428774cc..8b276817d33c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -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 \
diff --git a/test/cmd-zone-reset-all.c b/test/cmd-zone-reset-all.c
new file mode 100644
index 000000000000..5d8fe4d5f380
--- /dev/null
+++ b/test/cmd-zone-reset-all.c
@@ -0,0 +1,164 @@
+/* SPDX-License-Identifier: MIT */
+
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#include "liburing.h"
+#include "helpers.h"
+
+static const char *filename;
+
+static int queue_zone_reset_all(struct io_uring *ring, int bdev_fd)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ int err;
+
+ sqe = io_uring_get_sqe(ring);
+ assert(sqe != NULL);
+ io_uring_prep_cmd_zone_reset_all(sqe, bdev_fd);
+
+ err = io_uring_submit_and_wait(ring, 1);
+ if (err != 1) {
+ fprintf(stderr, "io_uring_submit_and_wait failed %d\n", err);
+ exit(1);
+ }
+
+ err = io_uring_wait_cqe(ring, &cqe);
+ if (err) {
+ fprintf(stderr, "io_uring_wait_cqe failed %d\n", err);
+ exit(1);
+ }
+
+ err = cqe->res;
+ io_uring_cqe_seen(ring, cqe);
+ return err;
+}
+
+
+static int basic_cmd_test(struct io_uring *ring)
+{
+ int ret, fd;
+
+ fd = open(filename, O_DIRECT | O_RDWR | O_EXCL);
+ if (fd < 0) {
+ if (errno == EINVAL || errno == EBUSY)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "open failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+
+ ret = queue_zone_reset_all(ring, fd);
+ if (ret) {
+ if (ret == -EINVAL || ret == -EOPNOTSUPP) {
+ printf("cmd not supported, skip\n");
+ ret = T_EXIT_SKIP;
+ } else {
+ fprintf(stderr, "cmd_issue_verify fail ret %i\n", ret);
+ fprintf(stderr, "cmd fail\n");
+ ret = T_EXIT_FAIL;
+ }
+ }
+
+ close(fd);
+ return ret;
+}
+
+static int test_rdonly(struct io_uring *ring)
+{
+ int ret, fd;
+ int ro;
+
+ fd = open(filename, O_DIRECT | O_RDONLY | O_EXCL);
+ if (fd < 0) {
+ if (errno == EINVAL || errno == EBUSY)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "open failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+
+ ret = queue_zone_reset_all(ring, fd);
+ if (ret >= 0) {
+ fprintf(stderr, "discarded with O_RDONLY %i\n", ret);
+ return 1;
+ }
+ close(fd);
+
+ fd = open(filename, O_DIRECT | O_RDWR | O_EXCL);
+ if (fd < 0) {
+ if (errno == EINVAL || errno == EBUSY)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "open failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+
+ ro = 1;
+ ret = ioctl(fd, BLKROSET, &ro);
+ if (ret) {
+ fprintf(stderr, "BLKROSET 1 failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+
+ ret = queue_zone_reset_all(ring, fd);
+ if (ret >= 0) {
+ fprintf(stderr, "discarded with O_RDONLY %i\n", ret);
+ return 1;
+ }
+
+ ro = 0;
+ ret = ioctl(fd, BLKROSET, &ro);
+ if (ret) {
+ fprintf(stderr, "BLKROSET 0 failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+ close(fd);
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int fd, ret;
+
+ if (argc != 2)
+ return T_EXIT_SKIP;
+ filename = argv[1];
+
+ fd = open(filename, O_DIRECT | O_RDONLY | O_EXCL);
+ if (fd < 0) {
+ if (errno == EINVAL || errno == EBUSY)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "open failed %i\n", errno);
+ return T_EXIT_FAIL;
+ }
+ close(fd);
+
+ ret = io_uring_queue_init(16, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "queue init failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ ret = basic_cmd_test(&ring);
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "basic_cmd_test() failed\n");
+ return T_EXIT_FAIL;
+ }
+
+ ret = test_rdonly(&ring);
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "test_rdonly() failed\n");
+ return T_EXIT_FAIL;
+ }
+
+ if (ret != T_EXIT_SKIP)
+ ret = T_EXIT_PASS;
+
+ io_uring_queue_exit(&ring);
+ return ret;
+}
--
2.53.0
next prev parent reply other threads:[~2026-08-17 8:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 8:28 support ZONE_RESET_ALL in liburing v3 Christoph Hellwig
2026-08-17 8:28 ` [PATCH 1/5] configure: shorten the message for the discard command Christoph Hellwig
2026-08-17 18:22 ` Jens Axboe
2026-08-17 8:28 ` [PATCH 2/5] man: fixups for io_uring_prep_cmd_discard.3 Christoph Hellwig
2026-08-17 8:28 ` [PATCH 3/5] liburing: add io_uring_prep_cmd_zone_reset Christoph Hellwig
2026-08-17 8:28 ` [PATCH 4/5] man: add io_uring_prep_cmd_zone_reset_all.3 man page Christoph Hellwig
2026-08-17 8:28 ` Christoph Hellwig [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-08-12 13:12 support ZONE_RESET_ALL in liburing v2 Christoph Hellwig
2026-08-12 13:12 ` [PATCH 5/5] test: add zone_reset_all command test Christoph Hellwig
2026-07-15 6:39 support ZONE_RESET_ALL in liburing Christoph Hellwig
2026-07-15 6:39 ` [PATCH 5/5] test: add zone_reset_all command test Christoph Hellwig
2026-07-15 8:35 ` Damien Le Moal
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=20260817082837.762276-6-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=io-uring@vger.kernel.org \
/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