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>
7#include <linux/uio.h>
8#include <linux/rcupdate.h>
9
10#include <asm/atomic.h>
11
12#define AIO_MAXSEGS 4
13#define AIO_KIOGRP_NR_ATOMIC 8
14
15struct kioctx;
16
17
18
19
20
21
22
23#define KIOCB_C_CANCELLED 0x01
24#define KIOCB_C_COMPLETE 0x02
25
26#define KIOCB_SYNC_KEY (~0U)
27
28
29
30
31
32
33
34
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
41#define kiocbSetLocked(iocb) set_bit(KIF_LOCKED, &(iocb)->ki_flags)
42#define kiocbSetKicked(iocb) set_bit(KIF_KICKED, &(iocb)->ki_flags)
43#define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags)
44
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87struct kiocb {
88 struct list_head ki_run_list;
89 unsigned long ki_flags;
90 int ki_users;
91 unsigned ki_key;
92
93 struct file *ki_filp;
94 struct kioctx *ki_ctx;
95 int (*ki_cancel)(struct kiocb *, struct io_event *);
96 ssize_t (*ki_retry)(struct kiocb *);
97 void (*ki_dtor)(struct kiocb *);
98
99 union {
100 void __user *user;
101 struct task_struct *tsk;
102 } ki_obj;
103
104 __u64 ki_user_data;
105 loff_t ki_pos;
106
107 void *private;
108
109 unsigned short ki_opcode;
110 size_t ki_nbytes;
111 char __user *ki_buf;
112 size_t ki_left;
113 struct iovec ki_inline_vec;
114 struct iovec *ki_iovec;
115 unsigned long ki_nr_segs;
116 unsigned long ki_cur_seg;
117
118 struct list_head ki_list;
119
120
121
122
123
124
125 struct eventfd_ctx *ki_eventfd;
126};
127
128#define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY)
129#define init_sync_kiocb(x, filp) \
130 do { \
131 struct task_struct *tsk = current; \
132 (x)->ki_flags = 0; \
133 (x)->ki_users = 1; \
134 (x)->ki_key = KIOCB_SYNC_KEY; \
135 (x)->ki_filp = (filp); \
136 (x)->ki_ctx = NULL; \
137 (x)->ki_cancel = NULL; \
138 (x)->ki_retry = NULL; \
139 (x)->ki_dtor = NULL; \
140 (x)->ki_obj.tsk = tsk; \
141 (x)->ki_user_data = 0; \
142 } while (0)
143
144#define AIO_RING_MAGIC 0xa10a10a1
145#define AIO_RING_COMPAT_FEATURES 1
146#define AIO_RING_INCOMPAT_FEATURES 0
147struct aio_ring {
148 unsigned id;
149 unsigned nr;
150 unsigned head;
151 unsigned tail;
152
153 unsigned magic;
154 unsigned compat_features;
155 unsigned incompat_features;
156 unsigned header_length;
157
158
159 struct io_event io_events[0];
160};
161
162#define aio_ring_avail(info, ring) (((ring)->head + (info)->nr - 1 - (ring)->tail) % (info)->nr)
163
164#define AIO_RING_PAGES 8
165struct aio_ring_info {
166 unsigned long mmap_base;
167 unsigned long mmap_size;
168
169 struct page **ring_pages;
170 spinlock_t ring_lock;
171 long nr_pages;
172
173 unsigned nr, tail;
174
175 struct page *internal_pages[AIO_RING_PAGES];
176};
177
178struct kioctx {
179 atomic_t users;
180 int dead;
181 struct mm_struct *mm;
182
183
184 unsigned long user_id;
185 struct hlist_node list;
186
187 wait_queue_head_t wait;
188
189 spinlock_t ctx_lock;
190
191 int reqs_active;
192 struct list_head active_reqs;
193 struct list_head run_list;
194
195
196 unsigned max_reqs;
197
198 struct aio_ring_info ring_info;
199
200 struct delayed_work wq;
201
202 struct rcu_head rcu_head;
203};
204
205
206extern unsigned aio_max_size;
207
208#ifdef CONFIG_AIO
209extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
210extern int aio_put_req(struct kiocb *iocb);
211extern void kick_iocb(struct kiocb *iocb);
212extern int aio_complete(struct kiocb *iocb, long res, long res2);
213struct mm_struct;
214extern void exit_aio(struct mm_struct *mm);
215extern long do_io_submit(aio_context_t ctx_id, long nr,
216 struct iocb __user *__user *iocbpp, bool compat);
217#else
218static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
219static inline int aio_put_req(struct kiocb *iocb) { return 0; }
220static inline void kick_iocb(struct kiocb *iocb) { }
221static inline int aio_complete(struct kiocb *iocb, long res, long res2) { return 0; }
222struct mm_struct;
223static inline void exit_aio(struct mm_struct *mm) { }
224static inline long do_io_submit(aio_context_t ctx_id, long nr,
225 struct iocb __user * __user *iocbpp,
226 bool compat) { return 0; }
227#endif
228
229static inline struct kiocb *list_kiocb(struct list_head *h)
230{
231 return list_entry(h, struct kiocb, ki_list);
232}
233
234
235extern unsigned long aio_nr;
236extern unsigned long aio_max_nr;
237
238#endif
239