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