Commit | Line | Data |
---|---|---|
0f212204 JA |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | #ifndef _LINUX_IO_URING_H | |
3 | #define _LINUX_IO_URING_H | |
4 | ||
5 | #include <linux/sched.h> | |
6 | #include <linux/xarray.h> | |
a9216fac | 7 | #include <uapi/linux/io_uring.h> |
98447d65 | 8 | |
ee692a21 JA |
9 | enum io_uring_cmd_flags { |
10 | IO_URING_F_COMPLETE_DEFER = 1, | |
11 | IO_URING_F_UNLOCKED = 2, | |
12 | /* int's last bit, sign checks are usually faster than a bit test */ | |
13 | IO_URING_F_NONBLOCK = INT_MIN, | |
14 | ||
15 | /* ctx state flags, for URING_CMD */ | |
16 | IO_URING_F_SQE128 = 4, | |
17 | IO_URING_F_CQE32 = 8, | |
18 | IO_URING_F_IOPOLL = 16, | |
19 | }; | |
20 | ||
21 | struct io_uring_cmd { | |
22 | struct file *file; | |
23 | const void *cmd; | |
5756a3a7 KJ |
24 | union { |
25 | /* callback to defer completions to task context */ | |
26 | void (*task_work_cb)(struct io_uring_cmd *cmd); | |
27 | /* used for polled completion */ | |
28 | void *cookie; | |
29 | }; | |
ee692a21 | 30 | u32 cmd_op; |
9cda70f6 | 31 | u32 flags; |
ee692a21 JA |
32 | u8 pdu[32]; /* available inline for free use */ |
33 | }; | |
34 | ||
0f212204 | 35 | #if defined(CONFIG_IO_URING) |
a9216fac AG |
36 | int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, |
37 | struct iov_iter *iter, void *ioucmd); | |
ee692a21 JA |
38 | void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2); |
39 | void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, | |
40 | void (*task_work_cb)(struct io_uring_cmd *)); | |
a3ec6005 | 41 | struct sock *io_uring_get_socket(struct file *file); |
f552a27a | 42 | void __io_uring_cancel(bool cancel_all); |
0f212204 | 43 | void __io_uring_free(struct task_struct *tsk); |
e7a6c00d | 44 | void io_uring_unreg_ringfd(void); |
33337d03 | 45 | const char *io_uring_get_opcode(u8 opcode); |
0f212204 | 46 | |
f552a27a | 47 | static inline void io_uring_files_cancel(void) |
0f212204 | 48 | { |
e7a6c00d JA |
49 | if (current->io_uring) { |
50 | io_uring_unreg_ringfd(); | |
f552a27a | 51 | __io_uring_cancel(false); |
e7a6c00d | 52 | } |
0f212204 | 53 | } |
3f48cf18 | 54 | static inline void io_uring_task_cancel(void) |
0f212204 | 55 | { |
a4aadd11 | 56 | if (current->io_uring) |
f552a27a | 57 | __io_uring_cancel(true); |
0f212204 JA |
58 | } |
59 | static inline void io_uring_free(struct task_struct *tsk) | |
60 | { | |
61 | if (tsk->io_uring) | |
62 | __io_uring_free(tsk); | |
63 | } | |
64 | #else | |
a9216fac AG |
65 | static int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, |
66 | struct iov_iter *iter, void *ioucmd) | |
67 | { | |
68 | return -EOPNOTSUPP; | |
69 | } | |
ee692a21 JA |
70 | static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, |
71 | ssize_t ret2) | |
72 | { | |
73 | } | |
74 | static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, | |
75 | void (*task_work_cb)(struct io_uring_cmd *)) | |
76 | { | |
77 | } | |
a3ec6005 JA |
78 | static inline struct sock *io_uring_get_socket(struct file *file) |
79 | { | |
80 | return NULL; | |
81 | } | |
0f212204 JA |
82 | static inline void io_uring_task_cancel(void) |
83 | { | |
84 | } | |
f552a27a | 85 | static inline void io_uring_files_cancel(void) |
0f212204 JA |
86 | { |
87 | } | |
88 | static inline void io_uring_free(struct task_struct *tsk) | |
89 | { | |
90 | } | |
33337d03 DY |
91 | static inline const char *io_uring_get_opcode(u8 opcode) |
92 | { | |
93 | return ""; | |
94 | } | |
0f212204 JA |
95 | #endif |
96 | ||
97 | #endif |