]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/io-wq.h
io-uring: drop 'free_pfile' in struct io_file_put
[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 {
18a542ff 66 struct io_wq_work_node list;
771b53d0 67 void (*func)(struct io_wq_work **);
fcb323cc 68 struct files_struct *files;
cccf0ee8
JA
69 struct mm_struct *mm;
70 const struct cred *creds;
9392a27d 71 struct fs_struct *fs;
6206f0e1 72 unsigned flags;
36282881 73 pid_t task_pid;
771b53d0
JA
74};
75
2d141dd2
JA
76#define INIT_IO_WORK(work, _func) \
77 do { \
78 *(work) = (struct io_wq_work){ .func = _func }; \
79 } while (0) \
771b53d0 80
e9fd9396 81typedef void (free_work_fn)(struct io_wq_work *);
7d723065 82
576a347b 83struct io_wq_data {
576a347b
JA
84 struct user_struct *user;
85
e9fd9396 86 free_work_fn *free_work;
576a347b
JA
87};
88
89struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
eba6f5a3 90bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
771b53d0
JA
91void io_wq_destroy(struct io_wq *wq);
92
93void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
8766dd51
PB
94void io_wq_hash_work(struct io_wq_work *work, void *val);
95
96static inline bool io_wq_is_hashed(struct io_wq_work *work)
97{
98 return work->flags & IO_WQ_WORK_HASHED;
99}
771b53d0
JA
100
101void io_wq_cancel_all(struct io_wq *wq);
102enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
36282881 103enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
771b53d0 104
62755e35
JA
105typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
106
107enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
108 void *data);
109
771b53d0
JA
110#if defined(CONFIG_IO_WQ)
111extern void io_wq_worker_sleeping(struct task_struct *);
112extern void io_wq_worker_running(struct task_struct *);
113#else
114static inline void io_wq_worker_sleeping(struct task_struct *tsk)
115{
116}
117static inline void io_wq_worker_running(struct task_struct *tsk)
118{
119}
525b305d 120#endif
771b53d0 121
525b305d
JA
122static inline bool io_wq_current_is_worker(void)
123{
124 return in_task() && (current->flags & PF_IO_WORKER);
125}
126#endif