1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
10 IO_WQ_WORK_NEEDS_USER = 8,
11 IO_WQ_WORK_NEEDS_FILES = 16,
12 IO_WQ_WORK_UNBOUND = 32,
13 IO_WQ_WORK_INTERNAL = 64,
16 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
20 IO_WQ_CANCEL_OK, /* cancelled before started */
21 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
22 IO_WQ_CANCEL_NOTFOUND, /* work not found */
25 struct io_wq_work_node {
26 struct io_wq_work_node *next;
29 struct io_wq_work_list {
30 struct io_wq_work_node *first;
31 struct io_wq_work_node *last;
34 static inline void wq_list_add_tail(struct io_wq_work_node *node,
35 struct io_wq_work_list *list)
38 list->first = list->last = node;
40 list->last->next = node;
45 static inline void wq_node_del(struct io_wq_work_list *list,
46 struct io_wq_work_node *node,
47 struct io_wq_work_node *prev)
49 if (node == list->first)
50 list->first = node->next;
51 if (node == list->last)
54 prev->next = node->next;
57 #define wq_list_for_each(pos, prv, head) \
58 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
60 #define wq_list_empty(list) ((list)->first == NULL)
61 #define INIT_WQ_LIST(list) do { \
62 (list)->first = NULL; \
63 (list)->last = NULL; \
68 struct io_wq_work_node list;
71 void (*func)(struct io_wq_work **);
72 struct files_struct *files;
76 #define INIT_IO_WORK(work, _func) \
78 (work)->list.next = NULL; \
79 (work)->func = _func; \
81 (work)->files = NULL; \
84 typedef void (get_work_fn)(struct io_wq_work *);
85 typedef void (put_work_fn)(struct io_wq_work *);
89 struct user_struct *user;
92 get_work_fn *get_work;
93 put_work_fn *put_work;
96 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
97 void io_wq_destroy(struct io_wq *wq);
99 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
100 void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
101 void io_wq_flush(struct io_wq *wq);
103 void io_wq_cancel_all(struct io_wq *wq);
104 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
106 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
108 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
111 #if defined(CONFIG_IO_WQ)
112 extern void io_wq_worker_sleeping(struct task_struct *);
113 extern void io_wq_worker_running(struct task_struct *);
115 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
118 static inline void io_wq_worker_running(struct task_struct *tsk)
123 static inline bool io_wq_current_is_worker(void)
125 return in_task() && (current->flags & PF_IO_WORKER);