Commit | Line | Data |
---|---|---|
771b53d0 JA |
1 | #ifndef INTERNAL_IO_WQ_H |
2 | #define INTERNAL_IO_WQ_H | |
3 | ||
98447d65 JA |
4 | #include <linux/io_uring.h> |
5 | ||
771b53d0 JA |
6 | struct io_wq; |
7 | ||
8 | enum { | |
9 | IO_WQ_WORK_CANCEL = 1, | |
e883a79d PB |
10 | IO_WQ_WORK_HASHED = 2, |
11 | IO_WQ_WORK_UNBOUND = 4, | |
e883a79d | 12 | IO_WQ_WORK_CONCURRENT = 16, |
771b53d0 | 13 | |
0f203765 JA |
14 | IO_WQ_WORK_FILES = 32, |
15 | IO_WQ_WORK_FS = 64, | |
16 | IO_WQ_WORK_MM = 128, | |
17 | IO_WQ_WORK_CREDS = 256, | |
18 | IO_WQ_WORK_BLKCG = 512, | |
69228338 | 19 | IO_WQ_WORK_FSIZE = 1024, |
0f203765 | 20 | |
771b53d0 JA |
21 | IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */ |
22 | }; | |
23 | ||
24 | enum io_wq_cancel { | |
25 | IO_WQ_CANCEL_OK, /* cancelled before started */ | |
26 | IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */ | |
27 | IO_WQ_CANCEL_NOTFOUND, /* work not found */ | |
28 | }; | |
29 | ||
86f3cd1b PB |
30 | static inline void wq_list_add_after(struct io_wq_work_node *node, |
31 | struct io_wq_work_node *pos, | |
32 | struct io_wq_work_list *list) | |
33 | { | |
34 | struct io_wq_work_node *next = pos->next; | |
35 | ||
36 | pos->next = node; | |
37 | node->next = next; | |
38 | if (!next) | |
39 | list->last = node; | |
40 | } | |
41 | ||
6206f0e1 JA |
42 | static inline void wq_list_add_tail(struct io_wq_work_node *node, |
43 | struct io_wq_work_list *list) | |
44 | { | |
45 | if (!list->first) { | |
e995d512 JA |
46 | list->last = node; |
47 | WRITE_ONCE(list->first, node); | |
6206f0e1 JA |
48 | } else { |
49 | list->last->next = node; | |
50 | list->last = node; | |
51 | } | |
0020ef04 | 52 | node->next = NULL; |
6206f0e1 JA |
53 | } |
54 | ||
86f3cd1b PB |
55 | static inline void wq_list_cut(struct io_wq_work_list *list, |
56 | struct io_wq_work_node *last, | |
6206f0e1 JA |
57 | struct io_wq_work_node *prev) |
58 | { | |
86f3cd1b PB |
59 | /* first in the list, if prev==NULL */ |
60 | if (!prev) | |
61 | WRITE_ONCE(list->first, last->next); | |
62 | else | |
63 | prev->next = last->next; | |
64 | ||
65 | if (last == list->last) | |
6206f0e1 | 66 | list->last = prev; |
86f3cd1b PB |
67 | last->next = NULL; |
68 | } | |
69 | ||
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) | |
73 | { | |
74 | wq_list_cut(list, node, prev); | |
6206f0e1 JA |
75 | } |
76 | ||
77 | #define wq_list_for_each(pos, prv, head) \ | |
78 | for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next) | |
79 | ||
e995d512 | 80 | #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL) |
6206f0e1 JA |
81 | #define INIT_WQ_LIST(list) do { \ |
82 | (list)->first = NULL; \ | |
83 | (list)->last = NULL; \ | |
84 | } while (0) | |
85 | ||
771b53d0 | 86 | struct io_wq_work { |
18a542ff | 87 | struct io_wq_work_node list; |
98447d65 | 88 | struct io_identity *identity; |
6206f0e1 | 89 | unsigned flags; |
771b53d0 JA |
90 | }; |
91 | ||
86f3cd1b PB |
92 | static inline struct io_wq_work *wq_next_work(struct io_wq_work *work) |
93 | { | |
94 | if (!work->list.next) | |
95 | return NULL; | |
96 | ||
97 | return container_of(work->list.next, struct io_wq_work, list); | |
98 | } | |
99 | ||
5280f7e5 PB |
100 | typedef struct io_wq_work *(free_work_fn)(struct io_wq_work *); |
101 | typedef void (io_wq_work_fn)(struct io_wq_work *); | |
7d723065 | 102 | |
576a347b | 103 | struct io_wq_data { |
576a347b JA |
104 | struct user_struct *user; |
105 | ||
f5fa38c5 | 106 | io_wq_work_fn *do_work; |
e9fd9396 | 107 | free_work_fn *free_work; |
576a347b JA |
108 | }; |
109 | ||
110 | struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data); | |
eba6f5a3 | 111 | bool io_wq_get(struct io_wq *wq, struct io_wq_data *data); |
771b53d0 JA |
112 | void io_wq_destroy(struct io_wq *wq); |
113 | ||
114 | void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work); | |
8766dd51 PB |
115 | void io_wq_hash_work(struct io_wq_work *work, void *val); |
116 | ||
117 | static inline bool io_wq_is_hashed(struct io_wq_work *work) | |
118 | { | |
119 | return work->flags & IO_WQ_WORK_HASHED; | |
120 | } | |
771b53d0 | 121 | |
62755e35 JA |
122 | typedef bool (work_cancel_fn)(struct io_wq_work *, void *); |
123 | ||
124 | enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel, | |
4f26bda1 | 125 | void *data, bool cancel_all); |
62755e35 | 126 | |
aa96bf8a JA |
127 | struct task_struct *io_wq_get_task(struct io_wq *wq); |
128 | ||
771b53d0 JA |
129 | #if defined(CONFIG_IO_WQ) |
130 | extern void io_wq_worker_sleeping(struct task_struct *); | |
131 | extern void io_wq_worker_running(struct task_struct *); | |
132 | #else | |
133 | static inline void io_wq_worker_sleeping(struct task_struct *tsk) | |
134 | { | |
135 | } | |
136 | static inline void io_wq_worker_running(struct task_struct *tsk) | |
137 | { | |
138 | } | |
525b305d | 139 | #endif |
771b53d0 | 140 | |
525b305d JA |
141 | static inline bool io_wq_current_is_worker(void) |
142 | { | |
143 | return in_task() && (current->flags & PF_IO_WORKER); | |
144 | } | |
145 | #endif |