From 414c6a8f9c63d702f5c248d728693e027802b9af Mon Sep 17 00:00:00 2001 From: Pavel Begunkov Date: Sat, 16 Nov 2024 21:27:47 +0000 Subject: [PATCH] test/reg-wait: add registration helper Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/defbcb4f286b62c04dedaab54a7e7d1de0ad33e7.1731792294.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- test/reg-wait.c | 56 ++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/test/reg-wait.c b/test/reg-wait.c index ffe4c1d00..559228f65 100644 --- a/test/reg-wait.c +++ b/test/reg-wait.c @@ -32,6 +32,37 @@ static int test_wait_reg_offset(struct io_uring *ring, sizeof(struct io_uring_reg_wait)); } +static int __init_ring_with_region(struct io_uring *ring, unsigned ring_flags, + struct io_uring_mem_region_reg *pr, + bool disabled) +{ + int flags = disabled ? IORING_SETUP_R_DISABLED : 0; + int ret; + + ret = io_uring_queue_init(8, ring, flags); + if (ret) { + if (ret != -EINVAL) + fprintf(stderr, "ring setup failed: %d\n", ret); + return ret; + } + + ret = io_uring_register_region(ring, pr); + if (ret) + goto err; + + if (disabled) { + ret = io_uring_enable_rings(ring); + if (ret) { + fprintf(stderr, "io_uring_enable_rings failure %i\n", ret); + goto err; + } + } + return 0; +err: + io_uring_queue_exit(ring); + return ret; +} + static int page_size; static struct io_uring_reg_wait *reg; @@ -222,30 +253,11 @@ static int test_try_register_region(struct io_uring_mem_region_reg *pr, bool disabled) { struct io_uring ring; - int flags = 0; int ret; - if (disabled) - flags = IORING_SETUP_R_DISABLED; - - ret = io_uring_queue_init(8, &ring, flags); - if (ret) { - if (ret != -EINVAL) - fprintf(stderr, "ring setup failed: %d\n", ret); - return ret; - } - - ret = io_uring_register_region(&ring, pr); - if (ret) - goto err; - - if (disabled) { - ret = io_uring_enable_rings(&ring); - if (ret) - fprintf(stderr, "io_uring_enable_rings failure %i\n", ret); - } -err: - io_uring_queue_exit(&ring); + ret = __init_ring_with_region(&ring, 0, pr, disabled); + if (!ret) + io_uring_queue_exit(&ring); return ret; }