io_uring: support to inject result for NOP for-6.10/io_uring for-6.10/io_uring-20240511
authorMing Lei <ming.lei@redhat.com>
Fri, 10 May 2024 03:50:28 +0000 (11:50 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 10 May 2024 12:09:45 +0000 (06:09 -0600)
Support to inject result for NOP so that we can inject failure from
userspace. It is very helpful for covering failure handling code in
io_uring core change.

With nop flags, it becomes possible to add more test features on NOP in
future.

Suggested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20240510035031.78874-3-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/uapi/linux/io_uring.h
io_uring/nop.c

index 6dbac55f86861b6ec0683bd97bb6634fc4fcd077..994bf7af0efe20afbfc4888413ad5a6d261a0e6e 100644 (file)
@@ -72,6 +72,7 @@ struct io_uring_sqe {
                __u32           waitid_flags;
                __u32           futex_flags;
                __u32           install_fd_flags;
+               __u32           nop_flags;
        };
        __u64   user_data;      /* data to be passed back at completion time */
        /* pack this to avoid bogus arm OABI complaints */
@@ -407,6 +408,13 @@ enum io_uring_msg_ring_flags {
  */
 #define IORING_FIXED_FD_NO_CLOEXEC     (1U << 0)
 
+/*
+ * IORING_OP_NOP flags (sqe->nop_flags)
+ *
+ * IORING_NOP_INJECT_RESULT    Inject result from sqe->result
+ */
+#define IORING_NOP_INJECT_RESULT       (1U << 0)
+
 /*
  * IO completion data structure (Completion Queue Entry)
  */
index 1a4e312dfe510af0c54f8d5243ef4a01926dbb53..a5bcf3d6984f7be6e5d4d9ac0adb5f34fdfe8276 100644 (file)
 #include "io_uring.h"
 #include "nop.h"
 
+struct io_nop {
+       /* NOTE: kiocb has the file as the first member, so don't do it here */
+       struct file     *file;
+       int             result;
+};
+
 int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-       if (READ_ONCE(sqe->rw_flags))
+       unsigned int flags;
+       struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
+
+       flags = READ_ONCE(sqe->nop_flags);
+       if (flags & ~IORING_NOP_INJECT_RESULT)
                return -EINVAL;
+
+       if (flags & IORING_NOP_INJECT_RESULT)
+               nop->result = READ_ONCE(sqe->len);
+       else
+               nop->result = 0;
        return 0;
 }
 
-/*
- * IORING_OP_NOP just posts a completion event, nothing else.
- */
 int io_nop(struct io_kiocb *req, unsigned int issue_flags)
 {
-       io_req_set_res(req, 0, 0);
+       struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
+
+       if (nop->result < 0)
+               req_set_fail(req);
+       io_req_set_res(req, nop->result, 0);
        return IOU_OK;
 }