Skip to content

Commit deb1e49

Browse files
Ming Leiaxboe
authored andcommitted
io_uring: support to inject result for NOP
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>
1 parent 3d8f874 commit deb1e49

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

include/uapi/linux/io_uring.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct io_uring_sqe {
7272
__u32 waitid_flags;
7373
__u32 futex_flags;
7474
__u32 install_fd_flags;
75+
__u32 nop_flags;
7576
};
7677
__u64 user_data; /* data to be passed back at completion time */
7778
/* pack this to avoid bogus arm OABI complaints */
@@ -407,6 +408,13 @@ enum io_uring_msg_ring_flags {
407408
*/
408409
#define IORING_FIXED_FD_NO_CLOEXEC (1U << 0)
409410

411+
/*
412+
* IORING_OP_NOP flags (sqe->nop_flags)
413+
*
414+
* IORING_NOP_INJECT_RESULT Inject result from sqe->result
415+
*/
416+
#define IORING_NOP_INJECT_RESULT (1U << 0)
417+
410418
/*
411419
* IO completion data structure (Completion Queue Entry)
412420
*/

io_uring/nop.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,34 @@
1010
#include "io_uring.h"
1111
#include "nop.h"
1212

13+
struct io_nop {
14+
/* NOTE: kiocb has the file as the first member, so don't do it here */
15+
struct file *file;
16+
int result;
17+
};
18+
1319
int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1420
{
15-
if (READ_ONCE(sqe->rw_flags))
21+
unsigned int flags;
22+
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
23+
24+
flags = READ_ONCE(sqe->nop_flags);
25+
if (flags & ~IORING_NOP_INJECT_RESULT)
1626
return -EINVAL;
27+
28+
if (flags & IORING_NOP_INJECT_RESULT)
29+
nop->result = READ_ONCE(sqe->len);
30+
else
31+
nop->result = 0;
1732
return 0;
1833
}
1934

20-
/*
21-
* IORING_OP_NOP just posts a completion event, nothing else.
22-
*/
2335
int io_nop(struct io_kiocb *req, unsigned int issue_flags)
2436
{
25-
io_req_set_res(req, 0, 0);
37+
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
38+
39+
if (nop->result < 0)
40+
req_set_fail(req);
41+
io_req_set_res(req, nop->result, 0);
2642
return IOU_OK;
2743
}

0 commit comments

Comments
 (0)