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)
26 #define KIOCB_PRIVATE_SIZE (24 * sizeof(long))
31 #define KIF_CANCELLED 2
33 #define kiocbTryLock(iocb) test_and_set_bit(KIF_LOCKED, &(iocb)->ki_flags)
34 #define kiocbTryKick(iocb) test_and_set_bit(KIF_KICKED, &(iocb)->ki_flags)
36 #define kiocbSetLocked(iocb) set_bit(KIF_LOCKED, &(iocb)->ki_flags)
37 #define kiocbSetKicked(iocb) set_bit(KIF_KICKED, &(iocb)->ki_flags)
38 #define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags)
40 #define kiocbClearLocked(iocb) clear_bit(KIF_LOCKED, &(iocb)->ki_flags)
41 #define kiocbClearKicked(iocb) clear_bit(KIF_KICKED, &(iocb)->ki_flags)
42 #define kiocbClearCancelled(iocb) clear_bit(KIF_CANCELLED, &(iocb)->ki_flags)
44 #define kiocbIsLocked(iocb) test_bit(KIF_LOCKED, &(iocb)->ki_flags)
45 #define kiocbIsKicked(iocb) test_bit(KIF_KICKED, &(iocb)->ki_flags)
46 #define kiocbIsCancelled(iocb) test_bit(KIF_CANCELLED, &(iocb)->ki_flags)
49 struct list_head ki_run_list
;
52 unsigned ki_key
; /* id of this request */
55 struct kioctx
*ki_ctx
; /* may be NULL for sync ops */
56 int (*ki_cancel
)(struct kiocb
*, struct io_event
*);
57 long (*ki_retry
)(struct kiocb
*);
59 struct list_head ki_list
; /* the aio core uses this
62 void __user
*ki_user_obj
; /* pointer to userland's iocb */
63 __u64 ki_user_data
; /* user's data for completion */
66 char private[KIOCB_PRIVATE_SIZE
];
69 #define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY)
70 #define init_sync_kiocb(x, filp) \
72 struct task_struct *tsk = current; \
75 (x)->ki_key = KIOCB_SYNC_KEY; \
76 (x)->ki_filp = (filp); \
77 (x)->ki_ctx = &tsk->active_mm->default_kioctx; \
78 (x)->ki_cancel = NULL; \
79 (x)->ki_user_obj = tsk; \
82 #define AIO_RING_MAGIC 0xa10a10a1
83 #define AIO_RING_COMPAT_FEATURES 1
84 #define AIO_RING_INCOMPAT_FEATURES 0
86 unsigned id
; /* kernel internal index number */
87 unsigned nr
; /* number of io_events */
92 unsigned compat_features
;
93 unsigned incompat_features
;
94 unsigned header_length
; /* size of aio_ring */
97 struct io_event io_events
[0];
98 }; /* 128 bytes + ring size */
100 #define aio_ring_avail(info, ring) (((ring)->head + (info)->nr - 1 - (ring)->tail) % (info)->nr)
102 #define AIO_RING_PAGES 8
103 struct aio_ring_info
{
104 unsigned long mmap_base
;
105 unsigned long mmap_size
;
107 struct page
**ring_pages
;
108 spinlock_t ring_lock
;
113 struct page
*internal_pages
[AIO_RING_PAGES
];
119 struct mm_struct
*mm
;
121 /* This needs improving */
122 unsigned long user_id
;
125 wait_queue_head_t wait
;
130 struct list_head active_reqs
; /* used for cancellation */
131 struct list_head run_list
; /* used for kicked reqs */
135 struct aio_ring_info ring_info
;
137 struct work_struct wq
;
141 extern unsigned aio_max_size
;
143 extern ssize_t
FASTCALL(wait_on_sync_kiocb(struct kiocb
*iocb
));
144 extern int FASTCALL(aio_put_req(struct kiocb
*iocb
));
145 extern void FASTCALL(kick_iocb(struct kiocb
*iocb
));
146 extern int FASTCALL(aio_complete(struct kiocb
*iocb
, long res
, long res2
));
147 extern void FASTCALL(__put_ioctx(struct kioctx
*ctx
));
149 extern void FASTCALL(exit_aio(struct mm_struct
*mm
));
150 extern struct kioctx
*lookup_ioctx(unsigned long ctx_id
);
151 extern int FASTCALL(io_submit_one(struct kioctx
*ctx
,
152 struct iocb
*user_iocb
, struct iocb
*iocb
));
154 /* semi private, but used by the 32bit emulations: */
155 struct kioctx
*lookup_ioctx(unsigned long ctx_id
);
156 int FASTCALL(io_submit_one(struct kioctx
*ctx
, struct iocb
*user_iocb
,
159 #define get_ioctx(kioctx) do { if (unlikely(atomic_read(&(kioctx)->users) <= 0)) BUG(); atomic_inc(&(kioctx)->users); } while (0)
160 #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)
162 #include <linux/aio_abi.h>
164 static inline struct kiocb
*list_kiocb(struct list_head
*h
)
166 return list_entry(h
, struct kiocb
, ki_list
);
170 extern atomic_t aio_nr
;
171 extern unsigned aio_max_nr
;
173 #endif /* __LINUX__AIO_H */