net: enetc: Use DT protocol information to set up the ports
[linux-2.6-block.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
86f3cd1b
PB
31static 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)
34{
35 struct io_wq_work_node *next = pos->next;
36
37 pos->next = node;
38 node->next = next;
39 if (!next)
40 list->last = node;
41}
42
6206f0e1
JA
43static inline void wq_list_add_tail(struct io_wq_work_node *node,
44 struct io_wq_work_list *list)
45{
46 if (!list->first) {
e995d512
JA
47 list->last = node;
48 WRITE_ONCE(list->first, node);
6206f0e1
JA
49 } else {
50 list->last->next = node;
51 list->last = node;
52 }
53}
54
86f3cd1b
PB
55static 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
70static 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 86struct io_wq_work {
18a542ff 87 struct io_wq_work_node list;
fcb323cc 88 struct files_struct *files;
cccf0ee8
JA
89 struct mm_struct *mm;
90 const struct cred *creds;
9392a27d 91 struct fs_struct *fs;
6206f0e1 92 unsigned flags;
771b53d0
JA
93};
94
86f3cd1b
PB
95static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
96{
97 if (!work->list.next)
98 return NULL;
99
100 return container_of(work->list.next, struct io_wq_work, list);
101}
102
e9fd9396 103typedef void (free_work_fn)(struct io_wq_work *);
f5fa38c5 104typedef void (io_wq_work_fn)(struct io_wq_work **);
7d723065 105
576a347b 106struct io_wq_data {
576a347b
JA
107 struct user_struct *user;
108
f5fa38c5 109 io_wq_work_fn *do_work;
e9fd9396 110 free_work_fn *free_work;
576a347b
JA
111};
112
113struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
eba6f5a3 114bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
771b53d0
JA
115void io_wq_destroy(struct io_wq *wq);
116
117void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
8766dd51
PB
118void io_wq_hash_work(struct io_wq_work *work, void *val);
119
120static inline bool io_wq_is_hashed(struct io_wq_work *work)
121{
122 return work->flags & IO_WQ_WORK_HASHED;
123}
771b53d0
JA
124
125void io_wq_cancel_all(struct io_wq *wq);
126enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
127
62755e35
JA
128typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
129
130enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
4f26bda1 131 void *data, bool cancel_all);
62755e35 132
aa96bf8a
JA
133struct task_struct *io_wq_get_task(struct io_wq *wq);
134
771b53d0
JA
135#if defined(CONFIG_IO_WQ)
136extern void io_wq_worker_sleeping(struct task_struct *);
137extern void io_wq_worker_running(struct task_struct *);
138#else
139static inline void io_wq_worker_sleeping(struct task_struct *tsk)
140{
141}
142static inline void io_wq_worker_running(struct task_struct *tsk)
143{
144}
525b305d 145#endif
771b53d0 146
525b305d
JA
147static inline bool io_wq_current_is_worker(void)
148{
149 return in_task() && (current->flags & PF_IO_WORKER);
150}
151#endif