1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
4 #include <linux/io_uring.h>
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,
15 IO_WQ_WORK_FILES = 32,
18 IO_WQ_WORK_CREDS = 256,
19 IO_WQ_WORK_BLKCG = 512,
20 IO_WQ_WORK_FSIZE = 1024,
22 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
26 IO_WQ_CANCEL_OK, /* cancelled before started */
27 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
28 IO_WQ_CANCEL_NOTFOUND, /* work not found */
31 struct io_wq_work_node {
32 struct io_wq_work_node *next;
35 struct io_wq_work_list {
36 struct io_wq_work_node *first;
37 struct io_wq_work_node *last;
40 static inline void wq_list_add_after(struct io_wq_work_node *node,
41 struct io_wq_work_node *pos,
42 struct io_wq_work_list *list)
44 struct io_wq_work_node *next = pos->next;
52 static inline void wq_list_add_tail(struct io_wq_work_node *node,
53 struct io_wq_work_list *list)
57 WRITE_ONCE(list->first, node);
59 list->last->next = node;
65 static inline void wq_list_cut(struct io_wq_work_list *list,
66 struct io_wq_work_node *last,
67 struct io_wq_work_node *prev)
69 /* first in the list, if prev==NULL */
71 WRITE_ONCE(list->first, last->next);
73 prev->next = last->next;
75 if (last == list->last)
80 static inline void wq_list_del(struct io_wq_work_list *list,
81 struct io_wq_work_node *node,
82 struct io_wq_work_node *prev)
84 wq_list_cut(list, node, prev);
87 #define wq_list_for_each(pos, prv, head) \
88 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
90 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
91 #define INIT_WQ_LIST(list) do { \
92 (list)->first = NULL; \
93 (list)->last = NULL; \
97 struct io_wq_work_node list;
98 struct io_identity *identity;
102 static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
104 if (!work->list.next)
107 return container_of(work->list.next, struct io_wq_work, list);
110 typedef void (free_work_fn)(struct io_wq_work *);
111 typedef struct io_wq_work *(io_wq_work_fn)(struct io_wq_work *);
114 struct user_struct *user;
116 io_wq_work_fn *do_work;
117 free_work_fn *free_work;
120 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
121 bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
122 void io_wq_destroy(struct io_wq *wq);
124 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
125 void io_wq_hash_work(struct io_wq_work *work, void *val);
127 static inline bool io_wq_is_hashed(struct io_wq_work *work)
129 return work->flags & IO_WQ_WORK_HASHED;
132 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
134 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
135 void *data, bool cancel_all);
137 struct task_struct *io_wq_get_task(struct io_wq *wq);
139 #if defined(CONFIG_IO_WQ)
140 extern void io_wq_worker_sleeping(struct task_struct *);
141 extern void io_wq_worker_running(struct task_struct *);
143 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
146 static inline void io_wq_worker_running(struct task_struct *tsk)
151 static inline bool io_wq_current_is_worker(void)
153 return in_task() && (current->flags & PF_IO_WORKER);