]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - fs/io-wq.h
Merge tag 'armsoc-defconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[mirror_ubuntu-hirsute-kernel.git] / fs / io-wq.h
1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
3
4 #include <linux/io_uring.h>
5
6 struct io_wq;
7
8 enum {
9 IO_WQ_WORK_CANCEL = 1,
10 IO_WQ_WORK_HASHED = 2,
11 IO_WQ_WORK_UNBOUND = 4,
12 IO_WQ_WORK_NO_CANCEL = 8,
13 IO_WQ_WORK_CONCURRENT = 16,
14
15 IO_WQ_WORK_FILES = 32,
16 IO_WQ_WORK_FS = 64,
17 IO_WQ_WORK_MM = 128,
18 IO_WQ_WORK_CREDS = 256,
19 IO_WQ_WORK_BLKCG = 512,
20
21 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
22 };
23
24 enum io_wq_cancel {
25 IO_WQ_CANCEL_OK, /* cancelled before started */
26 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
27 IO_WQ_CANCEL_NOTFOUND, /* work not found */
28 };
29
30 struct io_wq_work_node {
31 struct io_wq_work_node *next;
32 };
33
34 struct io_wq_work_list {
35 struct io_wq_work_node *first;
36 struct io_wq_work_node *last;
37 };
38
39 static inline void wq_list_add_after(struct io_wq_work_node *node,
40 struct io_wq_work_node *pos,
41 struct io_wq_work_list *list)
42 {
43 struct io_wq_work_node *next = pos->next;
44
45 pos->next = node;
46 node->next = next;
47 if (!next)
48 list->last = node;
49 }
50
51 static inline void wq_list_add_tail(struct io_wq_work_node *node,
52 struct io_wq_work_list *list)
53 {
54 if (!list->first) {
55 list->last = node;
56 WRITE_ONCE(list->first, node);
57 } else {
58 list->last->next = node;
59 list->last = node;
60 }
61 }
62
63 static inline void wq_list_cut(struct io_wq_work_list *list,
64 struct io_wq_work_node *last,
65 struct io_wq_work_node *prev)
66 {
67 /* first in the list, if prev==NULL */
68 if (!prev)
69 WRITE_ONCE(list->first, last->next);
70 else
71 prev->next = last->next;
72
73 if (last == list->last)
74 list->last = prev;
75 last->next = NULL;
76 }
77
78 static inline void wq_list_del(struct io_wq_work_list *list,
79 struct io_wq_work_node *node,
80 struct io_wq_work_node *prev)
81 {
82 wq_list_cut(list, node, prev);
83 }
84
85 #define wq_list_for_each(pos, prv, head) \
86 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
87
88 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
89 #define INIT_WQ_LIST(list) do { \
90 (list)->first = NULL; \
91 (list)->last = NULL; \
92 } while (0)
93
94 struct io_wq_work {
95 struct io_wq_work_node list;
96 struct io_identity *identity;
97 unsigned flags;
98 };
99
100 static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
101 {
102 if (!work->list.next)
103 return NULL;
104
105 return container_of(work->list.next, struct io_wq_work, list);
106 }
107
108 typedef void (free_work_fn)(struct io_wq_work *);
109 typedef struct io_wq_work *(io_wq_work_fn)(struct io_wq_work *);
110
111 struct io_wq_data {
112 struct user_struct *user;
113
114 io_wq_work_fn *do_work;
115 free_work_fn *free_work;
116 };
117
118 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
119 bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
120 void io_wq_destroy(struct io_wq *wq);
121
122 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
123 void io_wq_hash_work(struct io_wq_work *work, void *val);
124
125 static inline bool io_wq_is_hashed(struct io_wq_work *work)
126 {
127 return work->flags & IO_WQ_WORK_HASHED;
128 }
129
130 void io_wq_cancel_all(struct io_wq *wq);
131 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
132
133 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
134
135 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
136 void *data, bool cancel_all);
137
138 struct task_struct *io_wq_get_task(struct io_wq *wq);
139
140 #if defined(CONFIG_IO_WQ)
141 extern void io_wq_worker_sleeping(struct task_struct *);
142 extern void io_wq_worker_running(struct task_struct *);
143 #else
144 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
145 {
146 }
147 static inline void io_wq_worker_running(struct task_struct *tsk)
148 {
149 }
150 #endif
151
152 static inline bool io_wq_current_is_worker(void)
153 {
154 return in_task() && (current->flags & PF_IO_WORKER);
155 }
156 #endif