1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
9 IO_WQ_WORK_UNBOUND
= 32,
10 IO_WQ_WORK_NO_CANCEL
= 256,
11 IO_WQ_WORK_CONCURRENT
= 512,
13 IO_WQ_HASH_SHIFT
= 24, /* upper 8 bits are used for hash key */
17 IO_WQ_CANCEL_OK
, /* cancelled before started */
18 IO_WQ_CANCEL_RUNNING
, /* found, running, and attempted cancelled */
19 IO_WQ_CANCEL_NOTFOUND
, /* work not found */
22 struct io_wq_work_node
{
23 struct io_wq_work_node
*next
;
26 struct io_wq_work_list
{
27 struct io_wq_work_node
*first
;
28 struct io_wq_work_node
*last
;
31 static inline void wq_list_add_after(struct io_wq_work_node
*node
,
32 struct io_wq_work_node
*pos
,
33 struct io_wq_work_list
*list
)
35 struct io_wq_work_node
*next
= pos
->next
;
43 static inline void wq_list_add_tail(struct io_wq_work_node
*node
,
44 struct io_wq_work_list
*list
)
48 WRITE_ONCE(list
->first
, node
);
50 list
->last
->next
= node
;
55 static inline void wq_list_cut(struct io_wq_work_list
*list
,
56 struct io_wq_work_node
*last
,
57 struct io_wq_work_node
*prev
)
59 /* first in the list, if prev==NULL */
61 WRITE_ONCE(list
->first
, last
->next
);
63 prev
->next
= last
->next
;
65 if (last
== list
->last
)
70 static inline void wq_list_del(struct io_wq_work_list
*list
,
71 struct io_wq_work_node
*node
,
72 struct io_wq_work_node
*prev
)
74 wq_list_cut(list
, node
, prev
);
77 #define wq_list_for_each(pos, prv, head) \
78 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
80 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
81 #define INIT_WQ_LIST(list) do { \
82 (list)->first = NULL; \
83 (list)->last = NULL; \
87 struct io_wq_work_node list
;
88 void (*func
)(struct io_wq_work
**);
89 struct files_struct
*files
;
91 const struct cred
*creds
;
97 #define INIT_IO_WORK(work, _func) \
99 *(work) = (struct io_wq_work){ .func = _func }; \
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
*);
113 struct user_struct
*user
;
115 free_work_fn
*free_work
;
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
);
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
);
125 static inline bool io_wq_is_hashed(struct io_wq_work
*work
)
127 return work
->flags
& IO_WQ_WORK_HASHED
;
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 enum io_wq_cancel
io_wq_cancel_pid(struct io_wq
*wq
, pid_t pid
);
134 typedef bool (work_cancel_fn
)(struct io_wq_work
*, void *);
136 enum io_wq_cancel
io_wq_cancel_cb(struct io_wq
*wq
, work_cancel_fn
*cancel
,
139 struct task_struct
*io_wq_get_task(struct io_wq
*wq
);
141 #if defined(CONFIG_IO_WQ)
142 extern void io_wq_worker_sleeping(struct task_struct
*);
143 extern void io_wq_worker_running(struct task_struct
*);
145 static inline void io_wq_worker_sleeping(struct task_struct
*tsk
)
148 static inline void io_wq_worker_running(struct task_struct
*tsk
)
153 static inline bool io_wq_current_is_worker(void)
155 return in_task() && (current
->flags
& PF_IO_WORKER
);