4 #include <linux/list.h>
5 #include <linux/workqueue.h>
6 #include <linux/aio_abi.h>
8 #include <linux/rcupdate.h>
10 #include <linux/atomic.h>
18 * opcode values not exposed to user space
21 IOCB_CMD_READ_ITER = 0x10000,
22 IOCB_CMD_WRITE_ITER = 0x10001,
26 * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either
27 * cancelled or completed (this makes a certain amount of sense because
28 * successful cancellation - io_cancel() - does deliver the completion to
31 * And since most things don't implement kiocb cancellation and we'd really like
32 * kiocb completion to be lockless when possible, we use ki_cancel to
33 * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED
34 * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel().
36 #define KIOCB_CANCELLED ((void *) (~0ULL))
38 typedef int (kiocb_cancel_fn)(struct kiocb *);
42 struct kioctx *ki_ctx; /* NULL for sync ops,
43 * -1 for kernel caller */
44 kiocb_cancel_fn *ki_cancel;
49 struct task_struct *tsk;
50 void (*complete)(u64 user_data, long res);
53 __u64 ki_user_data; /* user's data for completion */
55 size_t ki_nbytes; /* copy of iocb->aio_nbytes */
57 struct list_head ki_list; /* the aio core uses this
61 * If the aio_resfd field of the userspace iocb is not zero,
62 * this is the underlying eventfd context to deliver events to.
64 struct eventfd_ctx *ki_eventfd;
67 static inline bool is_sync_kiocb(struct kiocb *kiocb)
69 return kiocb->ki_ctx == NULL;
72 static inline bool is_kernel_kiocb(struct kiocb *kiocb)
74 return kiocb->ki_ctx == (void *)-1;
77 static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
79 *kiocb = (struct kiocb) {
82 .ki_obj.tsk = current,
88 extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
89 extern void aio_complete(struct kiocb *iocb, long res, long res2);
91 extern void exit_aio(struct mm_struct *mm);
92 extern long do_io_submit(aio_context_t ctx_id, long nr,
93 struct iocb __user *__user *iocbpp, bool compat);
94 void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
95 struct kiocb *aio_kernel_alloc(gfp_t gfp);
96 void aio_kernel_free(struct kiocb *iocb);
97 void aio_kernel_init_rw(struct kiocb *iocb, struct file *filp, size_t nr,
99 void aio_kernel_init_callback(struct kiocb *iocb,
100 void (*complete)(u64 user_data, long res),
102 int aio_kernel_submit(struct kiocb *iocb, unsigned op, void *ptr);
104 static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
105 static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
107 static inline void exit_aio(struct mm_struct *mm) { }
108 static inline long do_io_submit(aio_context_t ctx_id, long nr,
109 struct iocb __user * __user *iocbpp,
110 bool compat) { return 0; }
111 static inline void kiocb_set_cancel_fn(struct kiocb *req,
112 kiocb_cancel_fn *cancel) { }
113 #endif /* CONFIG_AIO */
115 static inline struct kiocb *list_kiocb(struct list_head *h)
117 return list_entry(h, struct kiocb, ki_list);
121 extern unsigned long aio_nr;
122 extern unsigned long aio_max_nr;
124 #endif /* __LINUX__AIO_H */