Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef __LINUX__AIO_H |
2 | #define __LINUX__AIO_H | |
3 | ||
4 | #include <linux/list.h> | |
5 | #include <linux/workqueue.h> | |
6 | #include <linux/aio_abi.h> | |
027445c3 | 7 | #include <linux/uio.h> |
abf137dd | 8 | #include <linux/rcupdate.h> |
1da177e4 | 9 | |
60063497 | 10 | #include <linux/atomic.h> |
1da177e4 | 11 | |
1da177e4 | 12 | struct kioctx; |
0460fef2 | 13 | struct kiocb; |
1da177e4 | 14 | |
8a660890 | 15 | #define KIOCB_KEY 0 |
1da177e4 | 16 | |
0460fef2 KO |
17 | /* |
18 | * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either | |
19 | * cancelled or completed (this makes a certain amount of sense because | |
20 | * successful cancellation - io_cancel() - does deliver the completion to | |
21 | * userspace). | |
22 | * | |
23 | * And since most things don't implement kiocb cancellation and we'd really like | |
24 | * kiocb completion to be lockless when possible, we use ki_cancel to | |
25 | * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED | |
26 | * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel(). | |
27 | */ | |
28 | #define KIOCB_CANCELLED ((void *) (~0ULL)) | |
1da177e4 | 29 | |
0460fef2 | 30 | typedef int (kiocb_cancel_fn)(struct kiocb *, struct io_event *); |
1da177e4 LT |
31 | |
32 | struct kiocb { | |
11599eba | 33 | atomic_t ki_users; |
1da177e4 LT |
34 | |
35 | struct file *ki_filp; | |
8a660890 | 36 | struct kioctx *ki_ctx; /* NULL for sync ops */ |
0460fef2 | 37 | kiocb_cancel_fn *ki_cancel; |
1da177e4 LT |
38 | void (*ki_dtor)(struct kiocb *); |
39 | ||
1da177e4 LT |
40 | union { |
41 | void __user *user; | |
42 | struct task_struct *tsk; | |
43 | } ki_obj; | |
59d9136b | 44 | |
1da177e4 LT |
45 | __u64 ki_user_data; /* user's data for completion */ |
46 | loff_t ki_pos; | |
59d9136b BL |
47 | |
48 | void *private; | |
1da177e4 LT |
49 | /* State that we remember to be able to restart/retry */ |
50 | unsigned short ki_opcode; | |
51 | size_t ki_nbytes; /* copy of iocb->aio_nbytes */ | |
52 | char __user *ki_buf; /* remaining iocb->aio_buf */ | |
53 | size_t ki_left; /* remaining bytes */ | |
027445c3 | 54 | struct iovec ki_inline_vec; /* inline vector */ |
eed4e51f BP |
55 | struct iovec *ki_iovec; |
56 | unsigned long ki_nr_segs; | |
57 | unsigned long ki_cur_seg; | |
1da177e4 | 58 | |
59d9136b BL |
59 | struct list_head ki_list; /* the aio core uses this |
60 | * for cancellation */ | |
9c3060be DL |
61 | |
62 | /* | |
63 | * If the aio_resfd field of the userspace iocb is not zero, | |
13389010 | 64 | * this is the underlying eventfd context to deliver events to. |
9c3060be | 65 | */ |
13389010 | 66 | struct eventfd_ctx *ki_eventfd; |
1da177e4 LT |
67 | }; |
68 | ||
f7e1becb AM |
69 | static inline bool is_sync_kiocb(struct kiocb *kiocb) |
70 | { | |
8a660890 | 71 | return kiocb->ki_ctx == NULL; |
f7e1becb AM |
72 | } |
73 | ||
74 | static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) | |
75 | { | |
76 | *kiocb = (struct kiocb) { | |
11599eba | 77 | .ki_users = ATOMIC_INIT(1), |
8a660890 | 78 | .ki_ctx = NULL, |
f7e1becb AM |
79 | .ki_filp = filp, |
80 | .ki_obj.tsk = current, | |
81 | }; | |
82 | } | |
1da177e4 | 83 | |
1da177e4 | 84 | /* prototypes */ |
ebf3f09c | 85 | #ifdef CONFIG_AIO |
b3c97528 | 86 | extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb); |
2d68449e KO |
87 | extern void aio_put_req(struct kiocb *iocb); |
88 | extern void aio_complete(struct kiocb *iocb, long res, long res2); | |
1da177e4 | 89 | struct mm_struct; |
b3c97528 | 90 | extern void exit_aio(struct mm_struct *mm); |
9d85cba7 JM |
91 | extern long do_io_submit(aio_context_t ctx_id, long nr, |
92 | struct iocb __user *__user *iocbpp, bool compat); | |
0460fef2 | 93 | void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel); |
ebf3f09c TP |
94 | #else |
95 | static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; } | |
2d68449e KO |
96 | static inline void aio_put_req(struct kiocb *iocb) { } |
97 | static inline void aio_complete(struct kiocb *iocb, long res, long res2) { } | |
ebf3f09c TP |
98 | struct mm_struct; |
99 | static inline void exit_aio(struct mm_struct *mm) { } | |
9d85cba7 JM |
100 | static inline long do_io_submit(aio_context_t ctx_id, long nr, |
101 | struct iocb __user * __user *iocbpp, | |
102 | bool compat) { return 0; } | |
0460fef2 KO |
103 | static inline void kiocb_set_cancel_fn(struct kiocb *req, |
104 | kiocb_cancel_fn *cancel) { } | |
ebf3f09c | 105 | #endif /* CONFIG_AIO */ |
1da177e4 | 106 | |
1da177e4 LT |
107 | static inline struct kiocb *list_kiocb(struct list_head *h) |
108 | { | |
109 | return list_entry(h, struct kiocb, ki_list); | |
110 | } | |
111 | ||
112 | /* for sysctl: */ | |
d55b5fda ZB |
113 | extern unsigned long aio_nr; |
114 | extern unsigned long aio_max_nr; | |
1da177e4 LT |
115 | |
116 | #endif /* __LINUX__AIO_H */ |