xref: /linux-6.15/include/linux/io_uring.h (revision a93dcaad)
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 struct io_identity {
9 	struct files_struct		*files;
10 	struct mm_struct		*mm;
11 #ifdef CONFIG_BLK_CGROUP
12 	struct cgroup_subsys_state	*blkcg_css;
13 #endif
14 	const struct cred		*creds;
15 	struct nsproxy			*nsproxy;
16 	struct fs_struct		*fs;
17 	unsigned long			fsize;
18 #ifdef CONFIG_AUDIT
19 	kuid_t				loginuid;
20 	unsigned int			sessionid;
21 #endif
22 	refcount_t			count;
23 };
24 
25 struct io_wq_work_node {
26 	struct io_wq_work_node *next;
27 };
28 
29 struct io_wq_work_list {
30 	struct io_wq_work_node *first;
31 	struct io_wq_work_node *last;
32 };
33 
34 struct io_uring_task {
35 	/* submission side */
36 	struct xarray		xa;
37 	struct wait_queue_head	wait;
38 	struct file		*last;
39 	struct percpu_counter	inflight;
40 	struct io_identity	__identity;
41 	struct io_identity	*identity;
42 	atomic_t		in_idle;
43 	bool			sqpoll;
44 
45 	spinlock_t		task_lock;
46 	struct io_wq_work_list	task_list;
47 	unsigned long		task_state;
48 	struct callback_head	task_work;
49 };
50 
51 #if defined(CONFIG_IO_URING)
52 struct sock *io_uring_get_socket(struct file *file);
53 void __io_uring_task_cancel(void);
54 void __io_uring_files_cancel(struct files_struct *files);
55 void __io_uring_free(struct task_struct *tsk);
56 
57 static inline void io_uring_task_cancel(void)
58 {
59 	if (current->io_uring && !xa_empty(&current->io_uring->xa))
60 		__io_uring_task_cancel();
61 }
62 static inline void io_uring_files_cancel(struct files_struct *files)
63 {
64 	if (current->io_uring && !xa_empty(&current->io_uring->xa))
65 		__io_uring_files_cancel(files);
66 }
67 static inline void io_uring_free(struct task_struct *tsk)
68 {
69 	if (tsk->io_uring)
70 		__io_uring_free(tsk);
71 }
72 #else
73 static inline struct sock *io_uring_get_socket(struct file *file)
74 {
75 	return NULL;
76 }
77 static inline void io_uring_task_cancel(void)
78 {
79 }
80 static inline void io_uring_files_cancel(struct files_struct *files)
81 {
82 }
83 static inline void io_uring_free(struct task_struct *tsk)
84 {
85 }
86 #endif
87 
88 #endif
89