diff options
Diffstat (limited to 'include/linux/aio.h')
| -rw-r--r-- | include/linux/aio.h | 178 |
1 files changed, 26 insertions, 152 deletions
diff --git a/include/linux/aio.h b/include/linux/aio.h index 31ff6dba4872..1bdf965339f9 100644 --- a/include/linux/aio.h +++ b/include/linux/aio.h | |||
| @@ -9,91 +9,32 @@ | |||
| 9 | 9 | ||
| 10 | #include <linux/atomic.h> | 10 | #include <linux/atomic.h> |
| 11 | 11 | ||
| 12 | #define AIO_MAXSEGS 4 | ||
| 13 | #define AIO_KIOGRP_NR_ATOMIC 8 | ||
| 14 | |||
| 15 | struct kioctx; | 12 | struct kioctx; |
| 13 | struct kiocb; | ||
| 16 | 14 | ||
| 17 | /* Notes on cancelling a kiocb: | 15 | #define KIOCB_KEY 0 |
| 18 | * If a kiocb is cancelled, aio_complete may return 0 to indicate | ||
| 19 | * that cancel has not yet disposed of the kiocb. All cancel | ||
| 20 | * operations *must* call aio_put_req to dispose of the kiocb | ||
| 21 | * to guard against races with the completion code. | ||
| 22 | */ | ||
| 23 | #define KIOCB_C_CANCELLED 0x01 | ||
| 24 | #define KIOCB_C_COMPLETE 0x02 | ||
| 25 | |||
| 26 | #define KIOCB_SYNC_KEY (~0U) | ||
| 27 | 16 | ||
| 28 | /* ki_flags bits */ | ||
| 29 | /* | 17 | /* |
| 30 | * This may be used for cancel/retry serialization in the future, but | 18 | * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either |
| 31 | * for now it's unused and we probably don't want modules to even | 19 | * cancelled or completed (this makes a certain amount of sense because |
| 32 | * think they can use it. | 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(). | ||
| 33 | */ | 27 | */ |
| 34 | /* #define KIF_LOCKED 0 */ | 28 | #define KIOCB_CANCELLED ((void *) (~0ULL)) |
| 35 | #define KIF_KICKED 1 | ||
| 36 | #define KIF_CANCELLED 2 | ||
| 37 | |||
| 38 | #define kiocbTryLock(iocb) test_and_set_bit(KIF_LOCKED, &(iocb)->ki_flags) | ||
| 39 | #define kiocbTryKick(iocb) test_and_set_bit(KIF_KICKED, &(iocb)->ki_flags) | ||
| 40 | 29 | ||
| 41 | #define kiocbSetLocked(iocb) set_bit(KIF_LOCKED, &(iocb)->ki_flags) | 30 | typedef int (kiocb_cancel_fn)(struct kiocb *, struct io_event *); |
| 42 | #define kiocbSetKicked(iocb) set_bit(KIF_KICKED, &(iocb)->ki_flags) | ||
| 43 | #define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags) | ||
| 44 | 31 | ||
| 45 | #define kiocbClearLocked(iocb) clear_bit(KIF_LOCKED, &(iocb)->ki_flags) | ||
| 46 | #define kiocbClearKicked(iocb) clear_bit(KIF_KICKED, &(iocb)->ki_flags) | ||
| 47 | #define kiocbClearCancelled(iocb) clear_bit(KIF_CANCELLED, &(iocb)->ki_flags) | ||
| 48 | |||
| 49 | #define kiocbIsLocked(iocb) test_bit(KIF_LOCKED, &(iocb)->ki_flags) | ||
| 50 | #define kiocbIsKicked(iocb) test_bit(KIF_KICKED, &(iocb)->ki_flags) | ||
| 51 | #define kiocbIsCancelled(iocb) test_bit(KIF_CANCELLED, &(iocb)->ki_flags) | ||
| 52 | |||
| 53 | /* is there a better place to document function pointer methods? */ | ||
| 54 | /** | ||
| 55 | * ki_retry - iocb forward progress callback | ||
| 56 | * @kiocb: The kiocb struct to advance by performing an operation. | ||
| 57 | * | ||
| 58 | * This callback is called when the AIO core wants a given AIO operation | ||
| 59 | * to make forward progress. The kiocb argument describes the operation | ||
| 60 | * that is to be performed. As the operation proceeds, perhaps partially, | ||
| 61 | * ki_retry is expected to update the kiocb with progress made. Typically | ||
| 62 | * ki_retry is set in the AIO core and it itself calls file_operations | ||
| 63 | * helpers. | ||
| 64 | * | ||
| 65 | * ki_retry's return value determines when the AIO operation is completed | ||
| 66 | * and an event is generated in the AIO event ring. Except the special | ||
| 67 | * return values described below, the value that is returned from ki_retry | ||
| 68 | * is transferred directly into the completion ring as the operation's | ||
| 69 | * resulting status. Once this has happened ki_retry *MUST NOT* reference | ||
| 70 | * the kiocb pointer again. | ||
| 71 | * | ||
| 72 | * If ki_retry returns -EIOCBQUEUED it has made a promise that aio_complete() | ||
| 73 | * will be called on the kiocb pointer in the future. The AIO core will | ||
| 74 | * not ask the method again -- ki_retry must ensure forward progress. | ||
| 75 | * aio_complete() must be called once and only once in the future, multiple | ||
| 76 | * calls may result in undefined behaviour. | ||
| 77 | * | ||
| 78 | * If ki_retry returns -EIOCBRETRY it has made a promise that kick_iocb() | ||
| 79 | * will be called on the kiocb pointer in the future. This may happen | ||
| 80 | * through generic helpers that associate kiocb->ki_wait with a wait | ||
| 81 | * queue head that ki_retry uses via current->io_wait. It can also happen | ||
| 82 | * with custom tracking and manual calls to kick_iocb(), though that is | ||
| 83 | * discouraged. In either case, kick_iocb() must be called once and only | ||
| 84 | * once. ki_retry must ensure forward progress, the AIO core will wait | ||
| 85 | * indefinitely for kick_iocb() to be called. | ||
| 86 | */ | ||
| 87 | struct kiocb { | 32 | struct kiocb { |
| 88 | struct list_head ki_run_list; | 33 | atomic_t ki_users; |
| 89 | unsigned long ki_flags; | ||
| 90 | int ki_users; | ||
| 91 | unsigned ki_key; /* id of this request */ | ||
| 92 | 34 | ||
| 93 | struct file *ki_filp; | 35 | struct file *ki_filp; |
| 94 | struct kioctx *ki_ctx; /* may be NULL for sync ops */ | 36 | struct kioctx *ki_ctx; /* NULL for sync ops */ |
| 95 | int (*ki_cancel)(struct kiocb *, struct io_event *); | 37 | kiocb_cancel_fn *ki_cancel; |
| 96 | ssize_t (*ki_retry)(struct kiocb *); | ||
| 97 | void (*ki_dtor)(struct kiocb *); | 38 | void (*ki_dtor)(struct kiocb *); |
| 98 | 39 | ||
| 99 | union { | 40 | union { |
| @@ -117,7 +58,6 @@ struct kiocb { | |||
| 117 | 58 | ||
| 118 | struct list_head ki_list; /* the aio core uses this | 59 | struct list_head ki_list; /* the aio core uses this |
| 119 | * for cancellation */ | 60 | * for cancellation */ |
| 120 | struct list_head ki_batch; /* batch allocation */ | ||
| 121 | 61 | ||
| 122 | /* | 62 | /* |
| 123 | * If the aio_resfd field of the userspace iocb is not zero, | 63 | * If the aio_resfd field of the userspace iocb is not zero, |
| @@ -128,106 +68,40 @@ struct kiocb { | |||
| 128 | 68 | ||
| 129 | static inline bool is_sync_kiocb(struct kiocb *kiocb) | 69 | static inline bool is_sync_kiocb(struct kiocb *kiocb) |
| 130 | { | 70 | { |
| 131 | return kiocb->ki_key == KIOCB_SYNC_KEY; | 71 | return kiocb->ki_ctx == NULL; |
| 132 | } | 72 | } |
| 133 | 73 | ||
| 134 | static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) | 74 | static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) |
| 135 | { | 75 | { |
| 136 | *kiocb = (struct kiocb) { | 76 | *kiocb = (struct kiocb) { |
| 137 | .ki_users = 1, | 77 | .ki_users = ATOMIC_INIT(1), |
| 138 | .ki_key = KIOCB_SYNC_KEY, | 78 | .ki_ctx = NULL, |
| 139 | .ki_filp = filp, | 79 | .ki_filp = filp, |
| 140 | .ki_obj.tsk = current, | 80 | .ki_obj.tsk = current, |
| 141 | }; | 81 | }; |
| 142 | } | 82 | } |
| 143 | 83 | ||
| 144 | #define AIO_RING_MAGIC 0xa10a10a1 | ||
| 145 | #define AIO_RING_COMPAT_FEATURES 1 | ||
| 146 | #define AIO_RING_INCOMPAT_FEATURES 0 | ||
| 147 | struct aio_ring { | ||
| 148 | unsigned id; /* kernel internal index number */ | ||
| 149 | unsigned nr; /* number of io_events */ | ||
| 150 | unsigned head; | ||
| 151 | unsigned tail; | ||
| 152 | |||
| 153 | unsigned magic; | ||
| 154 | unsigned compat_features; | ||
| 155 | unsigned incompat_features; | ||
| 156 | unsigned header_length; /* size of aio_ring */ | ||
| 157 | |||
| 158 | |||
| 159 | struct io_event io_events[0]; | ||
| 160 | }; /* 128 bytes + ring size */ | ||
| 161 | |||
| 162 | #define AIO_RING_PAGES 8 | ||
| 163 | struct aio_ring_info { | ||
| 164 | unsigned long mmap_base; | ||
| 165 | unsigned long mmap_size; | ||
| 166 | |||
| 167 | struct page **ring_pages; | ||
| 168 | spinlock_t ring_lock; | ||
| 169 | long nr_pages; | ||
| 170 | |||
| 171 | unsigned nr, tail; | ||
| 172 | |||
| 173 | struct page *internal_pages[AIO_RING_PAGES]; | ||
| 174 | }; | ||
| 175 | |||
| 176 | static inline unsigned aio_ring_avail(struct aio_ring_info *info, | ||
| 177 | struct aio_ring *ring) | ||
| 178 | { | ||
| 179 | return (ring->head + info->nr - 1 - ring->tail) % info->nr; | ||
| 180 | } | ||
| 181 | |||
| 182 | struct kioctx { | ||
| 183 | atomic_t users; | ||
| 184 | int dead; | ||
| 185 | struct mm_struct *mm; | ||
| 186 | |||
| 187 | /* This needs improving */ | ||
| 188 | unsigned long user_id; | ||
| 189 | struct hlist_node list; | ||
| 190 | |||
| 191 | wait_queue_head_t wait; | ||
| 192 | |||
| 193 | spinlock_t ctx_lock; | ||
| 194 | |||
| 195 | int reqs_active; | ||
| 196 | struct list_head active_reqs; /* used for cancellation */ | ||
| 197 | struct list_head run_list; /* used for kicked reqs */ | ||
| 198 | |||
| 199 | /* sys_io_setup currently limits this to an unsigned int */ | ||
| 200 | unsigned max_reqs; | ||
| 201 | |||
| 202 | struct aio_ring_info ring_info; | ||
| 203 | |||
| 204 | struct delayed_work wq; | ||
| 205 | |||
| 206 | struct rcu_head rcu_head; | ||
| 207 | }; | ||
| 208 | |||
| 209 | /* prototypes */ | 84 | /* prototypes */ |
| 210 | extern unsigned aio_max_size; | ||
| 211 | |||
| 212 | #ifdef CONFIG_AIO | 85 | #ifdef CONFIG_AIO |
| 213 | extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb); | 86 | extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb); |
| 214 | extern int aio_put_req(struct kiocb *iocb); | 87 | extern void aio_put_req(struct kiocb *iocb); |
| 215 | extern void kick_iocb(struct kiocb *iocb); | 88 | extern void aio_complete(struct kiocb *iocb, long res, long res2); |
| 216 | extern int aio_complete(struct kiocb *iocb, long res, long res2); | ||
| 217 | struct mm_struct; | 89 | struct mm_struct; |
| 218 | extern void exit_aio(struct mm_struct *mm); | 90 | extern void exit_aio(struct mm_struct *mm); |
| 219 | extern long do_io_submit(aio_context_t ctx_id, long nr, | 91 | extern long do_io_submit(aio_context_t ctx_id, long nr, |
| 220 | struct iocb __user *__user *iocbpp, bool compat); | 92 | struct iocb __user *__user *iocbpp, bool compat); |
| 93 | void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel); | ||
| 221 | #else | 94 | #else |
| 222 | static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; } | 95 | static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; } |
| 223 | static inline int aio_put_req(struct kiocb *iocb) { return 0; } | 96 | static inline void aio_put_req(struct kiocb *iocb) { } |
| 224 | static inline void kick_iocb(struct kiocb *iocb) { } | 97 | static inline void aio_complete(struct kiocb *iocb, long res, long res2) { } |
| 225 | static inline int aio_complete(struct kiocb *iocb, long res, long res2) { return 0; } | ||
| 226 | struct mm_struct; | 98 | struct mm_struct; |
| 227 | static inline void exit_aio(struct mm_struct *mm) { } | 99 | static inline void exit_aio(struct mm_struct *mm) { } |
| 228 | static inline long do_io_submit(aio_context_t ctx_id, long nr, | 100 | static inline long do_io_submit(aio_context_t ctx_id, long nr, |
| 229 | struct iocb __user * __user *iocbpp, | 101 | struct iocb __user * __user *iocbpp, |
| 230 | bool compat) { return 0; } | 102 | bool compat) { return 0; } |
| 103 | static inline void kiocb_set_cancel_fn(struct kiocb *req, | ||
| 104 | kiocb_cancel_fn *cancel) { } | ||
| 231 | #endif /* CONFIG_AIO */ | 105 | #endif /* CONFIG_AIO */ |
| 232 | 106 | ||
| 233 | static inline struct kiocb *list_kiocb(struct list_head *h) | 107 | static inline struct kiocb *list_kiocb(struct list_head *h) |
