4 #include <linux/list.h>
5 #include <linux/workqueue.h>
6 #include <linux/aio_abi.h>
8 #include <asm/atomic.h>
11 #define AIO_KIOGRP_NR_ATOMIC 8
15 /* Notes on cancelling a kiocb:
16 * If a kiocb is cancelled, aio_complete may return 0 to indicate
17 * that cancel has not yet disposed of the kiocb. All cancel
18 * operations *must* call aio_put_req to dispose of the kiocb
19 * to guard against races with the completion code.
21 #define KIOCB_C_CANCELLED 0x01
22 #define KIOCB_C_COMPLETE 0x02
24 #define KIOCB_SYNC_KEY (~0U)
29 #define KIF_CANCELLED 2
31 #define kiocbTryLock(iocb) test_and_set_bit(KIF_LOCKED, &(iocb)->ki_flags)
32 #define kiocbTryKick(iocb) test_and_set_bit(KIF_KICKED, &(iocb)->ki_flags)
34 #define kiocbSetLocked(iocb) set_bit(KIF_LOCKED, &(iocb)->ki_flags)
35 #define kiocbSetKicked(iocb) set_bit(KIF_KICKED, &(iocb)->ki_flags)
36 #define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags)
38 #define kiocbClearLocked(iocb) clear_bit(KIF_LOCKED, &(iocb)->ki_flags)
39 #define kiocbClearKicked(iocb) clear_bit(KIF_KICKED, &(iocb)->ki_flags)
40 #define kiocbClearCancelled(iocb) clear_bit(KIF_CANCELLED, &(iocb)->ki_flags)
42 #define kiocbIsLocked(iocb) test_bit(KIF_LOCKED, &(iocb)->ki_flags)
43 #define kiocbIsKicked(iocb) test_bit(KIF_KICKED, &(iocb)->ki_flags)
44 #define kiocbIsCancelled(iocb) test_bit(KIF_CANCELLED, &(iocb)->ki_flags)
47 struct list_head ki_run_list
;
50 unsigned ki_key
; /* id of this request */
53 struct kioctx
*ki_ctx
; /* may be NULL for sync ops */
54 int (*ki_cancel
)(struct kiocb
*, struct io_event
*);
55 ssize_t (*ki_retry
)(struct kiocb
*);
56 void (*ki_dtor
)(struct kiocb
*);
58 struct list_head ki_list
; /* the aio core uses this
63 struct task_struct
*tsk
;
65 __u64 ki_user_data
; /* user's data for completion */
67 /* State that we remember to be able to restart/retry */
68 unsigned short ki_opcode
;
69 size_t ki_nbytes
; /* copy of iocb->aio_nbytes */
70 char __user
*ki_buf
; /* remaining iocb->aio_buf */
71 size_t ki_left
; /* remaining bytes */
73 long ki_retried
; /* just for testing */
74 long ki_kicked
; /* just for testing */
75 long ki_queued
; /* just for testing */
80 #define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY)
81 #define init_sync_kiocb(x, filp) \
83 struct task_struct *tsk = current; \
86 (x)->ki_key = KIOCB_SYNC_KEY; \
87 (x)->ki_filp = (filp); \
88 (x)->ki_ctx = &tsk->active_mm->default_kioctx; \
89 (x)->ki_cancel = NULL; \
90 (x)->ki_dtor = NULL; \
91 (x)->ki_obj.tsk = tsk; \
92 (x)->ki_user_data = 0; \
93 init_wait((&(x)->ki_wait)); \
96 #define AIO_RING_MAGIC 0xa10a10a1
97 #define AIO_RING_COMPAT_FEATURES 1
98 #define AIO_RING_INCOMPAT_FEATURES 0
100 unsigned id
; /* kernel internal index number */
101 unsigned nr
; /* number of io_events */
106 unsigned compat_features
;
107 unsigned incompat_features
;
108 unsigned header_length
; /* size of aio_ring */
111 struct io_event io_events
[0];
112 }; /* 128 bytes + ring size */
114 #define aio_ring_avail(info, ring) (((ring)->head + (info)->nr - 1 - (ring)->tail) % (info)->nr)
116 #define AIO_RING_PAGES 8
117 struct aio_ring_info
{
118 unsigned long mmap_base
;
119 unsigned long mmap_size
;
121 struct page
**ring_pages
;
122 spinlock_t ring_lock
;
127 struct page
*internal_pages
[AIO_RING_PAGES
];
133 struct mm_struct
*mm
;
135 /* This needs improving */
136 unsigned long user_id
;
139 wait_queue_head_t wait
;
144 struct list_head active_reqs
; /* used for cancellation */
145 struct list_head run_list
; /* used for kicked reqs */
149 struct aio_ring_info ring_info
;
151 struct work_struct wq
;
155 extern unsigned aio_max_size
;
157 extern ssize_t
FASTCALL(wait_on_sync_kiocb(struct kiocb
*iocb
));
158 extern int FASTCALL(aio_put_req(struct kiocb
*iocb
));
159 extern void FASTCALL(kick_iocb(struct kiocb
*iocb
));
160 extern int FASTCALL(aio_complete(struct kiocb
*iocb
, long res
, long res2
));
161 extern void FASTCALL(__put_ioctx(struct kioctx
*ctx
));
163 extern void FASTCALL(exit_aio(struct mm_struct
*mm
));
164 extern struct kioctx
*lookup_ioctx(unsigned long ctx_id
);
165 extern int FASTCALL(io_submit_one(struct kioctx
*ctx
,
166 struct iocb __user
*user_iocb
, struct iocb
*iocb
));
168 /* semi private, but used by the 32bit emulations: */
169 struct kioctx
*lookup_ioctx(unsigned long ctx_id
);
170 int FASTCALL(io_submit_one(struct kioctx
*ctx
, struct iocb __user
*user_iocb
,
173 #define get_ioctx(kioctx) do { if (unlikely(atomic_read(&(kioctx)->users) <= 0)) BUG(); atomic_inc(&(kioctx)->users); } while (0)
174 #define put_ioctx(kioctx) do { if (unlikely(atomic_dec_and_test(&(kioctx)->users))) __put_ioctx(kioctx); else if (unlikely(atomic_read(&(kioctx)->users) < 0)) BUG(); } while (0)
176 #define in_aio() !is_sync_wait(current->io_wait)
177 /* may be used for debugging */
178 #define warn_if_async() \
181 printk(KERN_ERR "%s(%s:%d) called in async context!\n", \
182 __FUNCTION__, __FILE__, __LINE__); \
187 #define io_wait_to_kiocb(wait) container_of(wait, struct kiocb, ki_wait)
188 #define is_retried_kiocb(iocb) ((iocb)->ki_retried > 1)
190 #include <linux/aio_abi.h>
192 static inline struct kiocb
*list_kiocb(struct list_head
*h
)
194 return list_entry(h
, struct kiocb
, ki_list
);
198 extern atomic_t aio_nr
;
199 extern unsigned aio_max_nr
;
201 #endif /* __LINUX__AIO_H */