blob: 4b29f922f80cfc2b916374eedf788a8526b93861 [file] [log] [blame]
Jens Axboe771b53d02019-10-22 10:25:58 -06001#ifndef INTERNAL_IO_WQ_H
2#define INTERNAL_IO_WQ_H
3
4struct io_wq;
5
6enum {
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,
Jens Axboefcb323c2019-10-24 12:39:47 -060011 IO_WQ_WORK_NEEDS_FILES = 16,
Jens Axboec5def4a2019-11-07 11:41:16 -070012 IO_WQ_WORK_UNBOUND = 32,
Jens Axboe7d723062019-11-12 22:31:31 -070013 IO_WQ_WORK_INTERNAL = 64,
Jens Axboe771b53d02019-10-22 10:25:58 -060014
15 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
16};
17
18enum io_wq_cancel {
19 IO_WQ_CANCEL_OK, /* cancelled before started */
20 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
21 IO_WQ_CANCEL_NOTFOUND, /* work not found */
22};
23
24struct io_wq_work {
25 struct list_head list;
26 void (*func)(struct io_wq_work **);
27 unsigned flags;
Jens Axboefcb323c2019-10-24 12:39:47 -060028 struct files_struct *files;
Jens Axboe771b53d02019-10-22 10:25:58 -060029};
30
31#define INIT_IO_WORK(work, _func) \
32 do { \
33 (work)->func = _func; \
34 (work)->flags = 0; \
Jens Axboefcb323c2019-10-24 12:39:47 -060035 (work)->files = NULL; \
Jens Axboe771b53d02019-10-22 10:25:58 -060036 } while (0) \
37
Jens Axboe7d723062019-11-12 22:31:31 -070038typedef void (get_work_fn)(struct io_wq_work *);
39typedef void (put_work_fn)(struct io_wq_work *);
40
Jens Axboec5def4a2019-11-07 11:41:16 -070041struct io_wq *io_wq_create(unsigned bounded, struct mm_struct *mm,
Jens Axboe7d723062019-11-12 22:31:31 -070042 struct user_struct *user,
43 get_work_fn *get_work, put_work_fn *put_work);
Jens Axboe771b53d02019-10-22 10:25:58 -060044void io_wq_destroy(struct io_wq *wq);
45
46void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
47void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
48void io_wq_flush(struct io_wq *wq);
49
50void io_wq_cancel_all(struct io_wq *wq);
51enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
52
Jens Axboe62755e32019-10-28 21:49:21 -060053typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
54
55enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
56 void *data);
57
Jens Axboe771b53d02019-10-22 10:25:58 -060058#if defined(CONFIG_IO_WQ)
59extern void io_wq_worker_sleeping(struct task_struct *);
60extern void io_wq_worker_running(struct task_struct *);
61#else
62static inline void io_wq_worker_sleeping(struct task_struct *tsk)
63{
64}
65static inline void io_wq_worker_running(struct task_struct *tsk)
66{
67}
68#endif
69
Jens Axboe960e4322019-11-12 07:56:39 -070070static inline bool io_wq_current_is_worker(void)
71{
72 return in_task() && (current->flags & PF_IO_WORKER);
73}
Jens Axboe771b53d02019-10-22 10:25:58 -060074#endif