This is in prep for allwoing NOP to be used in IOPOLL mode. remove_buffers will consistently return ENOENT if asked to remove buffers from a nonexistent group, and so this is a suitable replacement. Other opcodes return -EINVAL in IOPOLL from the prep stage, which has slightly different behaviour. Signed-off-by: Dylan Yudaken <dylany@xxxxxx> --- test/defer.c | 28 ++++++++++++++++++++-------- test/link.c | 6 +++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/defer.c b/test/defer.c index 825b69f..68ee4b4 100644 --- a/test/defer.c +++ b/test/defer.c @@ -12,6 +12,10 @@ #include "liburing.h" #define RING_SIZE 128 +enum { + OP_NOP, + OP_REMOVE_BUFFERS +}; struct test_context { struct io_uring *ring; @@ -27,7 +31,8 @@ static void free_context(struct test_context *ctx) memset(ctx, 0, sizeof(*ctx)); } -static int init_context(struct test_context *ctx, struct io_uring *ring, int nr) +static int init_context(struct test_context *ctx, struct io_uring *ring, int nr, + int op) { struct io_uring_sqe *sqe; int i; @@ -45,7 +50,14 @@ static int init_context(struct test_context *ctx, struct io_uring *ring, int nr) sqe = io_uring_get_sqe(ring); if (!sqe) goto err; - io_uring_prep_nop(sqe); + switch (op) { + case OP_NOP: + io_uring_prep_nop(sqe); + break; + case OP_REMOVE_BUFFERS: + io_uring_prep_remove_buffers(sqe, 10, 1); + break; + }; sqe->user_data = i; ctx->sqes[i] = sqe; } @@ -81,7 +93,7 @@ static int test_cancelled_userdata(struct io_uring *ring) struct test_context ctx; int ret, i, nr = 100; - if (init_context(&ctx, ring, nr)) + if (init_context(&ctx, ring, nr, OP_NOP)) return 1; for (i = 0; i < nr; i++) @@ -115,7 +127,7 @@ static int test_thread_link_cancel(struct io_uring *ring) struct test_context ctx; int ret, i, nr = 100; - if (init_context(&ctx, ring, nr)) + if (init_context(&ctx, ring, nr, OP_REMOVE_BUFFERS)) return 1; for (i = 0; i < nr; i++) @@ -134,12 +146,12 @@ static int test_thread_link_cancel(struct io_uring *ring) bool fail = false; if (i == 0) - fail = (ctx.cqes[i].res != -EINVAL); + fail = (ctx.cqes[i].res != -ENOENT); else fail = (ctx.cqes[i].res != -ECANCELED); if (fail) { - printf("invalid status\n"); + printf("invalid status %d\n", ctx.cqes[i].res); goto err; } } @@ -158,7 +170,7 @@ static int test_drain_with_linked_timeout(struct io_uring *ring) struct test_context ctx; int ret, i; - if (init_context(&ctx, ring, nr * 2)) + if (init_context(&ctx, ring, nr * 2, OP_NOP)) return 1; for (i = 0; i < nr; i++) { @@ -188,7 +200,7 @@ static int run_drained(struct io_uring *ring, int nr) struct test_context ctx; int ret, i; - if (init_context(&ctx, ring, nr)) + if (init_context(&ctx, ring, nr, OP_NOP)) return 1; for (i = 0; i < nr; i++) diff --git a/test/link.c b/test/link.c index c89d6b2..41d3899 100644 --- a/test/link.c +++ b/test/link.c @@ -178,7 +178,7 @@ static int test_single_link_fail(struct io_uring *ring) goto err; } - io_uring_prep_nop(sqe); + io_uring_prep_remove_buffers(sqe, 10, 1); sqe->flags |= IOSQE_IO_LINK; sqe = io_uring_get_sqe(ring); @@ -205,8 +205,8 @@ static int test_single_link_fail(struct io_uring *ring) printf("failed to get cqe\n"); goto err; } - if (i == 0 && cqe->res != -EINVAL) { - printf("sqe0 failed with %d, wanted -EINVAL\n", cqe->res); + if (i == 0 && cqe->res != -ENOENT) { + printf("sqe0 failed with %d, wanted -ENOENT\n", cqe->res); goto err; } if (i == 1 && cqe->res != -ECANCELED) { -- 2.30.2