1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _LINUX_IO_URING_H
3 #define _LINUX_IO_URING_H
5 #include <linux/sched.h>
6 #include <linux/xarray.h>
7 #include <uapi/linux/io_uring.h>
9 enum io_uring_cmd_flags
{
10 IO_URING_F_COMPLETE_DEFER
= 1,
11 IO_URING_F_UNLOCKED
= 2,
12 /* the request is executed from poll, it should not be freed */
13 IO_URING_F_MULTISHOT
= 4,
14 /* executed by io-wq */
16 /* int's last bit, sign checks are usually faster than a bit test */
17 IO_URING_F_NONBLOCK
= INT_MIN
,
19 /* ctx state flags, for URING_CMD */
20 IO_URING_F_SQE128
= (1 << 8),
21 IO_URING_F_CQE32
= (1 << 9),
22 IO_URING_F_IOPOLL
= (1 << 10),
24 /* set when uring wants to cancel a previously issued command */
25 IO_URING_F_CANCEL
= (1 << 11),
28 /* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
29 #define IORING_URING_CMD_CANCELABLE (1U << 30)
30 #define IORING_URING_CMD_POLLED (1U << 31)
34 const struct io_uring_sqe
*sqe
;
36 /* callback to defer completions to task context */
37 void (*task_work_cb
)(struct io_uring_cmd
*cmd
, unsigned);
38 /* used for polled completion */
43 u8 pdu
[32]; /* available inline for free use */
46 static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe
*sqe
)
51 #if defined(CONFIG_IO_URING)
52 int io_uring_cmd_import_fixed(u64 ubuf
, unsigned long len
, int rw
,
53 struct iov_iter
*iter
, void *ioucmd
);
54 void io_uring_cmd_done(struct io_uring_cmd
*cmd
, ssize_t ret
, ssize_t res2
,
55 unsigned issue_flags
);
56 struct sock
*io_uring_get_socket(struct file
*file
);
57 void __io_uring_cancel(bool cancel_all
);
58 void __io_uring_free(struct task_struct
*tsk
);
59 void io_uring_unreg_ringfd(void);
60 const char *io_uring_get_opcode(u8 opcode
);
61 void __io_uring_cmd_do_in_task(struct io_uring_cmd
*ioucmd
,
62 void (*task_work_cb
)(struct io_uring_cmd
*, unsigned),
64 /* users should follow semantics of IOU_F_TWQ_LAZY_WAKE */
65 void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd
*ioucmd
,
66 void (*task_work_cb
)(struct io_uring_cmd
*, unsigned));
68 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd
*ioucmd
,
69 void (*task_work_cb
)(struct io_uring_cmd
*, unsigned))
71 __io_uring_cmd_do_in_task(ioucmd
, task_work_cb
, 0);
74 static inline void io_uring_files_cancel(void)
76 if (current
->io_uring
) {
77 io_uring_unreg_ringfd();
78 __io_uring_cancel(false);
81 static inline void io_uring_task_cancel(void)
83 if (current
->io_uring
)
84 __io_uring_cancel(true);
86 static inline void io_uring_free(struct task_struct
*tsk
)
91 int io_uring_cmd_sock(struct io_uring_cmd
*cmd
, unsigned int issue_flags
);
92 void io_uring_cmd_mark_cancelable(struct io_uring_cmd
*cmd
,
93 unsigned int issue_flags
);
94 struct task_struct
*io_uring_cmd_get_task(struct io_uring_cmd
*cmd
);
96 static inline int io_uring_cmd_import_fixed(u64 ubuf
, unsigned long len
, int rw
,
97 struct iov_iter
*iter
, void *ioucmd
)
101 static inline void io_uring_cmd_done(struct io_uring_cmd
*cmd
, ssize_t ret
,
102 ssize_t ret2
, unsigned issue_flags
)
105 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd
*ioucmd
,
106 void (*task_work_cb
)(struct io_uring_cmd
*, unsigned))
109 static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd
*ioucmd
,
110 void (*task_work_cb
)(struct io_uring_cmd
*, unsigned))
113 static inline struct sock
*io_uring_get_socket(struct file
*file
)
117 static inline void io_uring_task_cancel(void)
120 static inline void io_uring_files_cancel(void)
123 static inline void io_uring_free(struct task_struct
*tsk
)
126 static inline const char *io_uring_get_opcode(u8 opcode
)
130 static inline int io_uring_cmd_sock(struct io_uring_cmd
*cmd
,
131 unsigned int issue_flags
)
135 static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd
*cmd
,
136 unsigned int issue_flags
)
139 static inline struct task_struct
*io_uring_cmd_get_task(struct io_uring_cmd
*cmd
)