io_uring: use percpu counters to track inflight requests
[linux-2.6-microblaze.git] / include / linux / io_uring.h
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         refcount_t                      count;
19 };
20
21 struct io_uring_task {
22         /* submission side */
23         struct xarray           xa;
24         struct wait_queue_head  wait;
25         struct file             *last;
26         struct percpu_counter   inflight;
27         struct io_identity      __identity;
28         struct io_identity      *identity;
29         bool                    in_idle;
30 };
31
32 #if defined(CONFIG_IO_URING)
33 struct sock *io_uring_get_socket(struct file *file);
34 void __io_uring_task_cancel(void);
35 void __io_uring_files_cancel(struct files_struct *files);
36 void __io_uring_free(struct task_struct *tsk);
37
38 static inline void io_uring_task_cancel(void)
39 {
40         if (current->io_uring && !xa_empty(&current->io_uring->xa))
41                 __io_uring_task_cancel();
42 }
43 static inline void io_uring_files_cancel(struct files_struct *files)
44 {
45         if (current->io_uring && !xa_empty(&current->io_uring->xa))
46                 __io_uring_files_cancel(files);
47 }
48 static inline void io_uring_free(struct task_struct *tsk)
49 {
50         if (tsk->io_uring)
51                 __io_uring_free(tsk);
52 }
53 #else
54 static inline struct sock *io_uring_get_socket(struct file *file)
55 {
56         return NULL;
57 }
58 static inline void io_uring_task_cancel(void)
59 {
60 }
61 static inline void io_uring_files_cancel(struct files_struct *files)
62 {
63 }
64 static inline void io_uring_free(struct task_struct *tsk)
65 {
66 }
67 #endif
68
69 #endif