Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 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, |
Jens Axboe | fcb323c | 2019-10-24 12:39:47 -0600 | [diff] [blame] | 11 | IO_WQ_WORK_NEEDS_FILES = 16, |
Jens Axboe | c5def4a | 2019-11-07 11:41:16 -0700 | [diff] [blame] | 12 | IO_WQ_WORK_UNBOUND = 32, |
Jens Axboe | 7d72306 | 2019-11-12 22:31:31 -0700 | [diff] [blame] | 13 | IO_WQ_WORK_INTERNAL = 64, |
Jens Axboe | b76da70 | 2019-11-20 13:05:32 -0700 | [diff] [blame] | 14 | IO_WQ_WORK_CB = 128, |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 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 { |
Jens Axboe | b76da70 | 2019-11-20 13:05:32 -0700 | [diff] [blame] | 26 | union { |
| 27 | struct list_head list; |
| 28 | void *data; |
| 29 | }; |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 30 | void (*func)(struct io_wq_work **); |
| 31 | unsigned flags; |
Jens Axboe | fcb323c | 2019-10-24 12:39:47 -0600 | [diff] [blame] | 32 | struct files_struct *files; |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | #define INIT_IO_WORK(work, _func) \ |
| 36 | do { \ |
| 37 | (work)->func = _func; \ |
| 38 | (work)->flags = 0; \ |
Jens Axboe | fcb323c | 2019-10-24 12:39:47 -0600 | [diff] [blame] | 39 | (work)->files = NULL; \ |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 40 | } while (0) \ |
| 41 | |
Jens Axboe | 7d72306 | 2019-11-12 22:31:31 -0700 | [diff] [blame] | 42 | typedef void (get_work_fn)(struct io_wq_work *); |
| 43 | typedef void (put_work_fn)(struct io_wq_work *); |
| 44 | |
Jens Axboe | 576a347 | 2019-11-25 08:49:20 -0700 | [diff] [blame^] | 45 | struct io_wq_data { |
| 46 | struct mm_struct *mm; |
| 47 | struct user_struct *user; |
| 48 | |
| 49 | get_work_fn *get_work; |
| 50 | put_work_fn *put_work; |
| 51 | }; |
| 52 | |
| 53 | struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data); |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 54 | void io_wq_destroy(struct io_wq *wq); |
| 55 | |
| 56 | void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work); |
| 57 | void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val); |
| 58 | void io_wq_flush(struct io_wq *wq); |
| 59 | |
| 60 | void io_wq_cancel_all(struct io_wq *wq); |
| 61 | enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork); |
| 62 | |
Jens Axboe | 62755e3 | 2019-10-28 21:49:21 -0600 | [diff] [blame] | 63 | typedef bool (work_cancel_fn)(struct io_wq_work *, void *); |
| 64 | |
| 65 | enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel, |
| 66 | void *data); |
| 67 | |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 68 | #if defined(CONFIG_IO_WQ) |
| 69 | extern void io_wq_worker_sleeping(struct task_struct *); |
| 70 | extern void io_wq_worker_running(struct task_struct *); |
| 71 | #else |
| 72 | static inline void io_wq_worker_sleeping(struct task_struct *tsk) |
| 73 | { |
| 74 | } |
| 75 | static inline void io_wq_worker_running(struct task_struct *tsk) |
| 76 | { |
| 77 | } |
| 78 | #endif |
| 79 | |
Jens Axboe | 960e432 | 2019-11-12 07:56:39 -0700 | [diff] [blame] | 80 | static inline bool io_wq_current_is_worker(void) |
| 81 | { |
| 82 | return in_task() && (current->flags & PF_IO_WORKER); |
| 83 | } |
Jens Axboe | 771b53d0 | 2019-10-22 10:25:58 -0600 | [diff] [blame] | 84 | #endif |