Commit | Line | Data |
---|---|---|
e28683bd JA |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | #include <linux/kernel.h> | |
3 | #include <linux/errno.h> | |
4 | #include <linux/fs.h> | |
5 | #include <linux/file.h> | |
6 | #include <linux/io_uring.h> | |
7 | ||
8 | #include <uapi/linux/io_uring.h> | |
9 | ||
e28683bd JA |
10 | #include "io_uring.h" |
11 | #include "nop.h" | |
12 | ||
deb1e496 ML |
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 | ||
e28683bd JA |
19 | int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) |
20 | { | |
deb1e496 ML |
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) | |
3d8f874b | 26 | return -EINVAL; |
deb1e496 ML |
27 | |
28 | if (flags & IORING_NOP_INJECT_RESULT) | |
29 | nop->result = READ_ONCE(sqe->len); | |
30 | else | |
31 | nop->result = 0; | |
e28683bd JA |
32 | return 0; |
33 | } | |
34 | ||
e28683bd JA |
35 | int io_nop(struct io_kiocb *req, unsigned int issue_flags) |
36 | { | |
deb1e496 ML |
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); | |
e28683bd JA |
42 | return IOU_OK; |
43 | } |