Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / include / linux / aio.h
blob6b2f85a12aabde20216ba8cf1aa3df1f9a022f7f
1 #ifndef __LINUX__AIO_H
2 #define __LINUX__AIO_H
4 #include <linux/list.h>
5 #include <linux/workqueue.h>
6 #include <linux/aio_abi.h>
7 #include <linux/uio.h>
9 #include <asm/atomic.h>
10 #include <linux/uio.h>
12 #define AIO_MAXSEGS 4
13 #define AIO_KIOGRP_NR_ATOMIC 8
15 struct kioctx;
17 /* Notes on cancelling a kiocb:
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.
23 #define KIOCB_C_CANCELLED 0x01
24 #define KIOCB_C_COMPLETE 0x02
26 #define KIOCB_SYNC_KEY (~0U)
28 /* ki_flags bits */
30 * This may be used for cancel/retry serialization in the future, but
31 * for now it's unused and we probably don't want modules to even
32 * think they can use it.
34 /* #define KIF_LOCKED 0 */
35 #define KIF_KICKED 1
36 #define KIF_CANCELLED 2
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)
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)
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)
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)
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.
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.
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.
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.
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.
87 struct kiocb {
88 struct list_head ki_run_list;
89 unsigned long ki_flags;
90 int ki_users;
91 unsigned ki_key; /* id of this request */
93 struct file *ki_filp;
94 struct kioctx *ki_ctx; /* may be NULL for sync ops */
95 int (*ki_cancel)(struct kiocb *, struct io_event *);
96 ssize_t (*ki_retry)(struct kiocb *);
97 void (*ki_dtor)(struct kiocb *);
99 union {
100 void __user *user;
101 struct task_struct *tsk;
102 } ki_obj;
104 __u64 ki_user_data; /* user's data for completion */
105 wait_queue_t ki_wait;
106 loff_t ki_pos;
108 <<<<<<< HEAD:include/linux/aio.h
109 atomic_t ki_bio_count; /* num bio used for this iocb */
110 =======
111 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/linux/aio.h
112 void *private;
113 /* State that we remember to be able to restart/retry */
114 unsigned short ki_opcode;
115 size_t ki_nbytes; /* copy of iocb->aio_nbytes */
116 char __user *ki_buf; /* remaining iocb->aio_buf */
117 size_t ki_left; /* remaining bytes */
118 struct iovec ki_inline_vec; /* inline vector */
119 struct iovec *ki_iovec;
120 unsigned long ki_nr_segs;
121 unsigned long ki_cur_seg;
123 struct list_head ki_list; /* the aio core uses this
124 * for cancellation */
127 * If the aio_resfd field of the userspace iocb is not zero,
128 * this is the underlying file* to deliver event to.
130 struct file *ki_eventfd;
133 #define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY)
134 #define init_sync_kiocb(x, filp) \
135 do { \
136 struct task_struct *tsk = current; \
137 (x)->ki_flags = 0; \
138 (x)->ki_users = 1; \
139 (x)->ki_key = KIOCB_SYNC_KEY; \
140 (x)->ki_filp = (filp); \
141 (x)->ki_ctx = NULL; \
142 (x)->ki_cancel = NULL; \
143 (x)->ki_retry = NULL; \
144 (x)->ki_dtor = NULL; \
145 (x)->ki_obj.tsk = tsk; \
146 (x)->ki_user_data = 0; \
147 init_wait((&(x)->ki_wait)); \
148 } while (0)
150 #define AIO_RING_MAGIC 0xa10a10a1
151 #define AIO_RING_COMPAT_FEATURES 1
152 #define AIO_RING_INCOMPAT_FEATURES 0
153 struct aio_ring {
154 unsigned id; /* kernel internal index number */
155 unsigned nr; /* number of io_events */
156 unsigned head;
157 unsigned tail;
159 unsigned magic;
160 unsigned compat_features;
161 unsigned incompat_features;
162 unsigned header_length; /* size of aio_ring */
165 struct io_event io_events[0];
166 }; /* 128 bytes + ring size */
168 #define aio_ring_avail(info, ring) (((ring)->head + (info)->nr - 1 - (ring)->tail) % (info)->nr)
170 #define AIO_RING_PAGES 8
171 struct aio_ring_info {
172 unsigned long mmap_base;
173 unsigned long mmap_size;
175 struct page **ring_pages;
176 spinlock_t ring_lock;
177 long nr_pages;
179 unsigned nr, tail;
181 struct page *internal_pages[AIO_RING_PAGES];
184 struct kioctx {
185 atomic_t users;
186 int dead;
187 struct mm_struct *mm;
189 /* This needs improving */
190 unsigned long user_id;
191 struct kioctx *next;
193 wait_queue_head_t wait;
195 spinlock_t ctx_lock;
197 int reqs_active;
198 struct list_head active_reqs; /* used for cancellation */
199 struct list_head run_list; /* used for kicked reqs */
201 /* sys_io_setup currently limits this to an unsigned int */
202 unsigned max_reqs;
204 struct aio_ring_info ring_info;
206 struct delayed_work wq;
209 /* prototypes */
210 extern unsigned aio_max_size;
212 extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
213 extern int aio_put_req(struct kiocb *iocb);
214 extern void kick_iocb(struct kiocb *iocb);
215 extern int aio_complete(struct kiocb *iocb, long res, long res2);
216 extern void __put_ioctx(struct kioctx *ctx);
217 struct mm_struct;
218 extern void exit_aio(struct mm_struct *mm);
219 extern struct kioctx *lookup_ioctx(unsigned long ctx_id);
220 extern int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
221 struct iocb *iocb);
223 /* semi private, but used by the 32bit emulations: */
224 struct kioctx *lookup_ioctx(unsigned long ctx_id);
225 int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
226 struct iocb *iocb);
228 #define get_ioctx(kioctx) do { \
229 BUG_ON(atomic_read(&(kioctx)->users) <= 0); \
230 atomic_inc(&(kioctx)->users); \
231 } while (0)
232 #define put_ioctx(kioctx) do { \
233 BUG_ON(atomic_read(&(kioctx)->users) <= 0); \
234 if (unlikely(atomic_dec_and_test(&(kioctx)->users))) \
235 __put_ioctx(kioctx); \
236 } while (0)
238 #define io_wait_to_kiocb(wait) container_of(wait, struct kiocb, ki_wait)
240 #include <linux/aio_abi.h>
242 static inline struct kiocb *list_kiocb(struct list_head *h)
244 return list_entry(h, struct kiocb, ki_list);
247 /* for sysctl: */
248 extern unsigned long aio_nr;
249 extern unsigned long aio_max_nr;
251 #endif /* __LINUX__AIO_H */