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