Merge tag 'fbdev-for-6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux-block.git] / include / linux / io_uring.h
CommitLineData
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
9enum io_uring_cmd_flags {
10 IO_URING_F_COMPLETE_DEFER = 1,
11 IO_URING_F_UNLOCKED = 2,
7500194a
PB
12 /* the request is executed from poll, it should not be freed */
13 IO_URING_F_MULTISHOT = 4,
e6aeb272
PB
14 /* executed by io-wq */
15 IO_URING_F_IOWQ = 8,
ee692a21
JA
16 /* int's last bit, sign checks are usually faster than a bit test */
17 IO_URING_F_NONBLOCK = INT_MIN,
18
19 /* ctx state flags, for URING_CMD */
7500194a
PB
20 IO_URING_F_SQE128 = (1 << 8),
21 IO_URING_F_CQE32 = (1 << 9),
22 IO_URING_F_IOPOLL = (1 << 10),
ee692a21
JA
23};
24
25struct io_uring_cmd {
26 struct file *file;
fd9b8547 27 const struct io_uring_sqe *sqe;
5756a3a7
KJ
28 union {
29 /* callback to defer completions to task context */
9d2789ac 30 void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
5756a3a7
KJ
31 /* used for polled completion */
32 void *cookie;
33 };
ee692a21 34 u32 cmd_op;
9cda70f6 35 u32 flags;
ee692a21
JA
36 u8 pdu[32]; /* available inline for free use */
37};
38
293007b0
JA
39static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
40{
41 return sqe->cmd;
42}
43
0f212204 44#if defined(CONFIG_IO_URING)
a9216fac
AG
45int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
46 struct iov_iter *iter, void *ioucmd);
9d2789ac
JA
47void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
48 unsigned issue_flags);
ee692a21 49void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
9d2789ac 50 void (*task_work_cb)(struct io_uring_cmd *, unsigned));
a3ec6005 51struct sock *io_uring_get_socket(struct file *file);
f552a27a 52void __io_uring_cancel(bool cancel_all);
0f212204 53void __io_uring_free(struct task_struct *tsk);
e7a6c00d 54void io_uring_unreg_ringfd(void);
33337d03 55const char *io_uring_get_opcode(u8 opcode);
0f212204 56
f552a27a 57static inline void io_uring_files_cancel(void)
0f212204 58{
e7a6c00d
JA
59 if (current->io_uring) {
60 io_uring_unreg_ringfd();
f552a27a 61 __io_uring_cancel(false);
e7a6c00d 62 }
0f212204 63}
3f48cf18 64static inline void io_uring_task_cancel(void)
0f212204 65{
a4aadd11 66 if (current->io_uring)
f552a27a 67 __io_uring_cancel(true);
0f212204
JA
68}
69static inline void io_uring_free(struct task_struct *tsk)
70{
71 if (tsk->io_uring)
72 __io_uring_free(tsk);
73}
74#else
0e0abad2 75static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
a9216fac
AG
76 struct iov_iter *iter, void *ioucmd)
77{
78 return -EOPNOTSUPP;
79}
ee692a21 80static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
9d2789ac 81 ssize_t ret2, unsigned issue_flags)
ee692a21
JA
82{
83}
84static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
9d2789ac 85 void (*task_work_cb)(struct io_uring_cmd *, unsigned))
ee692a21
JA
86{
87}
a3ec6005
JA
88static inline struct sock *io_uring_get_socket(struct file *file)
89{
90 return NULL;
91}
0f212204
JA
92static inline void io_uring_task_cancel(void)
93{
94}
f552a27a 95static inline void io_uring_files_cancel(void)
0f212204
JA
96{
97}
98static inline void io_uring_free(struct task_struct *tsk)
99{
100}
33337d03
DY
101static inline const char *io_uring_get_opcode(u8 opcode)
102{
103 return "";
104}
0f212204
JA
105#endif
106
107#endif