]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/io-wq.h
io-wq: close cancel gap for hashed linked work
[mirror_ubuntu-jammy-kernel.git] / fs / io-wq.h
CommitLineData
771b53d0
JA
1#ifndef INTERNAL_IO_WQ_H
2#define INTERNAL_IO_WQ_H
3
4struct io_wq;
5
6enum {
7 IO_WQ_WORK_CANCEL = 1,
771b53d0 8 IO_WQ_WORK_HASHED = 4,
c5def4ab 9 IO_WQ_WORK_UNBOUND = 32,
0c9d5ccd 10 IO_WQ_WORK_NO_CANCEL = 256,
895e2ca0 11 IO_WQ_WORK_CONCURRENT = 512,
771b53d0
JA
12
13 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
14};
15
16enum io_wq_cancel {
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 */
20};
21
6206f0e1
JA
22struct io_wq_work_node {
23 struct io_wq_work_node *next;
24};
25
26struct io_wq_work_list {
27 struct io_wq_work_node *first;
28 struct io_wq_work_node *last;
29};
30
31static inline void wq_list_add_tail(struct io_wq_work_node *node,
32 struct io_wq_work_list *list)
33{
34 if (!list->first) {
e995d512
JA
35 list->last = node;
36 WRITE_ONCE(list->first, node);
6206f0e1
JA
37 } else {
38 list->last->next = node;
39 list->last = node;
40 }
41}
42
43static inline void wq_node_del(struct io_wq_work_list *list,
44 struct io_wq_work_node *node,
45 struct io_wq_work_node *prev)
46{
47 if (node == list->first)
e995d512 48 WRITE_ONCE(list->first, node->next);
6206f0e1
JA
49 if (node == list->last)
50 list->last = prev;
51 if (prev)
52 prev->next = node->next;
08bdcc35 53 node->next = NULL;
6206f0e1
JA
54}
55
56#define wq_list_for_each(pos, prv, head) \
57 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
58
e995d512 59#define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
6206f0e1
JA
60#define INIT_WQ_LIST(list) do { \
61 (list)->first = NULL; \
62 (list)->last = NULL; \
63} while (0)
64
771b53d0 65struct io_wq_work {
b76da70f 66 union {
6206f0e1 67 struct io_wq_work_node list;
b76da70f
JA
68 void *data;
69 };
771b53d0 70 void (*func)(struct io_wq_work **);
fcb323cc 71 struct files_struct *files;
cccf0ee8
JA
72 struct mm_struct *mm;
73 const struct cred *creds;
9392a27d 74 struct fs_struct *fs;
6206f0e1 75 unsigned flags;
36282881 76 pid_t task_pid;
771b53d0
JA
77};
78
2d141dd2
JA
79#define INIT_IO_WORK(work, _func) \
80 do { \
81 *(work) = (struct io_wq_work){ .func = _func }; \
82 } while (0) \
771b53d0 83
e9fd9396 84typedef void (free_work_fn)(struct io_wq_work *);
7d723065 85
576a347b 86struct io_wq_data {
576a347b
JA
87 struct user_struct *user;
88
e9fd9396 89 free_work_fn *free_work;
576a347b
JA
90};
91
92struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
eba6f5a3 93bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
771b53d0
JA
94void io_wq_destroy(struct io_wq *wq);
95
96void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
8766dd51
PB
97void io_wq_hash_work(struct io_wq_work *work, void *val);
98
99static inline bool io_wq_is_hashed(struct io_wq_work *work)
100{
101 return work->flags & IO_WQ_WORK_HASHED;
102}
771b53d0
JA
103
104void io_wq_cancel_all(struct io_wq *wq);
105enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
36282881 106enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
771b53d0 107
62755e35
JA
108typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
109
110enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
111 void *data);
112
771b53d0
JA
113#if defined(CONFIG_IO_WQ)
114extern void io_wq_worker_sleeping(struct task_struct *);
115extern void io_wq_worker_running(struct task_struct *);
116#else
117static inline void io_wq_worker_sleeping(struct task_struct *tsk)
118{
119}
120static inline void io_wq_worker_running(struct task_struct *tsk)
121{
122}
525b305d 123#endif
771b53d0 124
525b305d
JA
125static inline bool io_wq_current_is_worker(void)
126{
127 return in_task() && (current->flags & PF_IO_WORKER);
128}
129#endif