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>
7 #include <uapi/linux/io_uring.h>
8
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 /* the request is executed from poll, it should not be freed */
21 IO_URING_F_MULTISHOT = 32,
22 };
23
24 struct io_uring_cmd {
25 struct file *file;
26 const void *cmd;
27 union {
28 /* callback to defer completions to task context */
29 void (*task_work_cb)(struct io_uring_cmd *cmd);
30 /* used for polled completion */
31 void *cookie;
32 };
33 u32 cmd_op;
34 u32 flags;
35 u8 pdu[32]; /* available inline for free use */
36 };
37
38 #if defined(CONFIG_IO_URING)
39 int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
40 struct iov_iter *iter, void *ioucmd);
41 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
42 void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
43 void (*task_work_cb)(struct io_uring_cmd *));
44 struct sock *io_uring_get_socket(struct file *file);
45 void __io_uring_cancel(bool cancel_all);
46 void __io_uring_free(struct task_struct *tsk);
47 void io_uring_unreg_ringfd(void);
48 const char *io_uring_get_opcode(u8 opcode);
49
io_uring_files_cancel(void)50 static inline void io_uring_files_cancel(void)
51 {
52 if (current->io_uring) {
53 io_uring_unreg_ringfd();
54 __io_uring_cancel(false);
55 }
56 }
io_uring_task_cancel(void)57 static inline void io_uring_task_cancel(void)
58 {
59 if (current->io_uring)
60 __io_uring_cancel(true);
61 }
io_uring_free(struct task_struct * tsk)62 static inline void io_uring_free(struct task_struct *tsk)
63 {
64 if (tsk->io_uring)
65 __io_uring_free(tsk);
66 }
67 #else
io_uring_cmd_import_fixed(u64 ubuf,unsigned long len,int rw,struct iov_iter * iter,void * ioucmd)68 static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
69 struct iov_iter *iter, void *ioucmd)
70 {
71 return -EOPNOTSUPP;
72 }
io_uring_cmd_done(struct io_uring_cmd * cmd,ssize_t ret,ssize_t ret2)73 static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
74 ssize_t ret2)
75 {
76 }
io_uring_cmd_complete_in_task(struct io_uring_cmd * ioucmd,void (* task_work_cb)(struct io_uring_cmd *))77 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
78 void (*task_work_cb)(struct io_uring_cmd *))
79 {
80 }
io_uring_get_socket(struct file * file)81 static inline struct sock *io_uring_get_socket(struct file *file)
82 {
83 return NULL;
84 }
io_uring_task_cancel(void)85 static inline void io_uring_task_cancel(void)
86 {
87 }
io_uring_files_cancel(void)88 static inline void io_uring_files_cancel(void)
89 {
90 }
io_uring_free(struct task_struct * tsk)91 static inline void io_uring_free(struct task_struct *tsk)
92 {
93 }
io_uring_get_opcode(u8 opcode)94 static inline const char *io_uring_get_opcode(u8 opcode)
95 {
96 return "";
97 }
98 #endif
99
100 #endif
101