block: ublk_drv: mark device as LIVE before adding disk
[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;
27 const void *cmd;
5756a3a7
KJ
28 union {
29 /* callback to defer completions to task context */
30 void (*task_work_cb)(struct io_uring_cmd *cmd);
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
0f212204 39#if defined(CONFIG_IO_URING)
a9216fac
AG
40int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
41 struct iov_iter *iter, void *ioucmd);
ee692a21
JA
42void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
43void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
44 void (*task_work_cb)(struct io_uring_cmd *));
a3ec6005 45struct sock *io_uring_get_socket(struct file *file);
f552a27a 46void __io_uring_cancel(bool cancel_all);
0f212204 47void __io_uring_free(struct task_struct *tsk);
e7a6c00d 48void io_uring_unreg_ringfd(void);
33337d03 49const char *io_uring_get_opcode(u8 opcode);
0f212204 50
f552a27a 51static inline void io_uring_files_cancel(void)
0f212204 52{
e7a6c00d
JA
53 if (current->io_uring) {
54 io_uring_unreg_ringfd();
f552a27a 55 __io_uring_cancel(false);
e7a6c00d 56 }
0f212204 57}
3f48cf18 58static inline void io_uring_task_cancel(void)
0f212204 59{
a4aadd11 60 if (current->io_uring)
f552a27a 61 __io_uring_cancel(true);
0f212204
JA
62}
63static inline void io_uring_free(struct task_struct *tsk)
64{
65 if (tsk->io_uring)
66 __io_uring_free(tsk);
67}
68#else
0e0abad2 69static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
a9216fac
AG
70 struct iov_iter *iter, void *ioucmd)
71{
72 return -EOPNOTSUPP;
73}
ee692a21
JA
74static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
75 ssize_t ret2)
76{
77}
78static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
79 void (*task_work_cb)(struct io_uring_cmd *))
80{
81}
a3ec6005
JA
82static inline struct sock *io_uring_get_socket(struct file *file)
83{
84 return NULL;
85}
0f212204
JA
86static inline void io_uring_task_cancel(void)
87{
88}
f552a27a 89static inline void io_uring_files_cancel(void)
0f212204
JA
90{
91}
92static inline void io_uring_free(struct task_struct *tsk)
93{
94}
33337d03
DY
95static inline const char *io_uring_get_opcode(u8 opcode)
96{
97 return "";
98}
0f212204
JA
99#endif
100
101#endif