]> asedeno.scripts.mit.edu Git - linux.git/blob - fs/io-wq.h
Merge tag 'wireless-drivers-2019-12-17' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / fs / io-wq.h
1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
3
4 struct io_wq;
5
6 enum {
7         IO_WQ_WORK_CANCEL       = 1,
8         IO_WQ_WORK_HAS_MM       = 2,
9         IO_WQ_WORK_HASHED       = 4,
10         IO_WQ_WORK_NEEDS_USER   = 8,
11         IO_WQ_WORK_NEEDS_FILES  = 16,
12         IO_WQ_WORK_UNBOUND      = 32,
13         IO_WQ_WORK_INTERNAL     = 64,
14         IO_WQ_WORK_CB           = 128,
15
16         IO_WQ_HASH_SHIFT        = 24,   /* upper 8 bits are used for hash key */
17 };
18
19 enum io_wq_cancel {
20         IO_WQ_CANCEL_OK,        /* cancelled before started */
21         IO_WQ_CANCEL_RUNNING,   /* found, running, and attempted cancelled */
22         IO_WQ_CANCEL_NOTFOUND,  /* work not found */
23 };
24
25 struct io_wq_work_node {
26         struct io_wq_work_node *next;
27 };
28
29 struct io_wq_work_list {
30         struct io_wq_work_node *first;
31         struct io_wq_work_node *last;
32 };
33
34 static inline void wq_list_add_tail(struct io_wq_work_node *node,
35                                     struct io_wq_work_list *list)
36 {
37         if (!list->first) {
38                 list->first = list->last = node;
39         } else {
40                 list->last->next = node;
41                 list->last = node;
42         }
43 }
44
45 static inline void wq_node_del(struct io_wq_work_list *list,
46                                struct io_wq_work_node *node,
47                                struct io_wq_work_node *prev)
48 {
49         if (node == list->first)
50                 list->first = node->next;
51         if (node == list->last)
52                 list->last = prev;
53         if (prev)
54                 prev->next = node->next;
55         node->next = NULL;
56 }
57
58 #define wq_list_for_each(pos, prv, head)                        \
59         for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
60
61 #define wq_list_empty(list)     ((list)->first == NULL)
62 #define INIT_WQ_LIST(list)      do {                            \
63         (list)->first = NULL;                                   \
64         (list)->last = NULL;                                    \
65 } while (0)
66
67 struct io_wq_work {
68         union {
69                 struct io_wq_work_node list;
70                 void *data;
71         };
72         void (*func)(struct io_wq_work **);
73         struct files_struct *files;
74         unsigned flags;
75 };
76
77 #define INIT_IO_WORK(work, _func)                       \
78         do {                                            \
79                 (work)->list.next = NULL;               \
80                 (work)->func = _func;                   \
81                 (work)->flags = 0;                      \
82                 (work)->files = NULL;                   \
83         } while (0)                                     \
84
85 typedef void (get_work_fn)(struct io_wq_work *);
86 typedef void (put_work_fn)(struct io_wq_work *);
87
88 struct io_wq_data {
89         struct mm_struct *mm;
90         struct user_struct *user;
91         const struct cred *creds;
92
93         get_work_fn *get_work;
94         put_work_fn *put_work;
95 };
96
97 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
98 void io_wq_destroy(struct io_wq *wq);
99
100 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
101 void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
102 void io_wq_flush(struct io_wq *wq);
103
104 void io_wq_cancel_all(struct io_wq *wq);
105 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
106
107 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
108
109 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
110                                         void *data);
111
112 #if defined(CONFIG_IO_WQ)
113 extern void io_wq_worker_sleeping(struct task_struct *);
114 extern void io_wq_worker_running(struct task_struct *);
115 #else
116 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
117 {
118 }
119 static inline void io_wq_worker_running(struct task_struct *tsk)
120 {
121 }
122 #endif /* CONFIG_IO_WQ */
123
124 #endif /* INTERNAL_IO_WQ_H */