Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 7 | #include <linux/uio.h> |
Jens Axboe | abf137d | 2008-12-09 08:11:22 +0100 | [diff] [blame] | 8 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 10 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | struct kioctx; |
Kent Overstreet | 0460fef | 2013-05-07 16:18:49 -0700 | [diff] [blame] | 13 | struct kiocb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Kent Overstreet | 8a66089 | 2013-05-07 16:19:10 -0700 | [diff] [blame] | 15 | #define KIOCB_KEY 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Kent Overstreet | 0460fef | 2013-05-07 16:18:49 -0700 | [diff] [blame] | 17 | /* |
| 18 | * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either |
| 19 | * cancelled or completed (this makes a certain amount of sense because |
| 20 | * successful cancellation - io_cancel() - does deliver the completion to |
| 21 | * userspace). |
| 22 | * |
| 23 | * And since most things don't implement kiocb cancellation and we'd really like |
| 24 | * kiocb completion to be lockless when possible, we use ki_cancel to |
| 25 | * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED |
| 26 | * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel(). |
| 27 | */ |
| 28 | #define KIOCB_CANCELLED ((void *) (~0ULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Kent Overstreet | bec68faa | 2013-05-13 14:45:08 -0700 | [diff] [blame] | 30 | typedef int (kiocb_cancel_fn)(struct kiocb *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | struct kiocb { |
Kent Overstreet | 11599eb | 2013-05-07 16:18:39 -0700 | [diff] [blame] | 33 | atomic_t ki_users; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | struct file *ki_filp; |
Kent Overstreet | 8a66089 | 2013-05-07 16:19:10 -0700 | [diff] [blame] | 36 | struct kioctx *ki_ctx; /* NULL for sync ops */ |
Kent Overstreet | 0460fef | 2013-05-07 16:18:49 -0700 | [diff] [blame] | 37 | kiocb_cancel_fn *ki_cancel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | void (*ki_dtor)(struct kiocb *); |
Kent Overstreet | 8bc92af | 2013-02-25 16:36:27 -0800 | [diff] [blame^] | 39 | void *private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | union { |
| 42 | void __user *user; |
| 43 | struct task_struct *tsk; |
| 44 | } ki_obj; |
Benjamin LaHaise | 59d9136 | 2006-01-08 01:04:34 -0800 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | __u64 ki_user_data; /* user's data for completion */ |
| 47 | loff_t ki_pos; |
Kent Overstreet | 8bc92af | 2013-02-25 16:36:27 -0800 | [diff] [blame^] | 48 | size_t ki_nbytes; /* copy of iocb->aio_nbytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Benjamin LaHaise | 59d9136 | 2006-01-08 01:04:34 -0800 | [diff] [blame] | 50 | struct list_head ki_list; /* the aio core uses this |
| 51 | * for cancellation */ |
Davide Libenzi | 9c3060b | 2007-05-10 22:23:21 -0700 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * If the aio_resfd field of the userspace iocb is not zero, |
Davide Libenzi | 1338901 | 2009-06-30 11:41:11 -0700 | [diff] [blame] | 55 | * this is the underlying eventfd context to deliver events to. |
Davide Libenzi | 9c3060b | 2007-05-10 22:23:21 -0700 | [diff] [blame] | 56 | */ |
Davide Libenzi | 1338901 | 2009-06-30 11:41:11 -0700 | [diff] [blame] | 57 | struct eventfd_ctx *ki_eventfd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Andrew Morton | f7e1bec | 2012-07-30 14:42:56 -0700 | [diff] [blame] | 60 | static inline bool is_sync_kiocb(struct kiocb *kiocb) |
| 61 | { |
Kent Overstreet | 8a66089 | 2013-05-07 16:19:10 -0700 | [diff] [blame] | 62 | return kiocb->ki_ctx == NULL; |
Andrew Morton | f7e1bec | 2012-07-30 14:42:56 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) |
| 66 | { |
| 67 | *kiocb = (struct kiocb) { |
Kent Overstreet | 11599eb | 2013-05-07 16:18:39 -0700 | [diff] [blame] | 68 | .ki_users = ATOMIC_INIT(1), |
Kent Overstreet | 8a66089 | 2013-05-07 16:19:10 -0700 | [diff] [blame] | 69 | .ki_ctx = NULL, |
Andrew Morton | f7e1bec | 2012-07-30 14:42:56 -0700 | [diff] [blame] | 70 | .ki_filp = filp, |
| 71 | .ki_obj.tsk = current, |
| 72 | }; |
| 73 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* prototypes */ |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 76 | #ifdef CONFIG_AIO |
Harvey Harrison | b3c9752 | 2008-02-13 15:03:15 -0800 | [diff] [blame] | 77 | extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb); |
Kent Overstreet | 2d68449 | 2013-05-07 16:18:29 -0700 | [diff] [blame] | 78 | extern void aio_put_req(struct kiocb *iocb); |
| 79 | extern void aio_complete(struct kiocb *iocb, long res, long res2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | struct mm_struct; |
Harvey Harrison | b3c9752 | 2008-02-13 15:03:15 -0800 | [diff] [blame] | 81 | extern void exit_aio(struct mm_struct *mm); |
Jeff Moyer | 9d85cba | 2010-05-26 14:44:26 -0700 | [diff] [blame] | 82 | extern long do_io_submit(aio_context_t ctx_id, long nr, |
| 83 | struct iocb __user *__user *iocbpp, bool compat); |
Kent Overstreet | 0460fef | 2013-05-07 16:18:49 -0700 | [diff] [blame] | 84 | void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel); |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 85 | #else |
| 86 | static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; } |
Kent Overstreet | 2d68449 | 2013-05-07 16:18:29 -0700 | [diff] [blame] | 87 | static inline void aio_put_req(struct kiocb *iocb) { } |
| 88 | static inline void aio_complete(struct kiocb *iocb, long res, long res2) { } |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 89 | struct mm_struct; |
| 90 | static inline void exit_aio(struct mm_struct *mm) { } |
Jeff Moyer | 9d85cba | 2010-05-26 14:44:26 -0700 | [diff] [blame] | 91 | static inline long do_io_submit(aio_context_t ctx_id, long nr, |
| 92 | struct iocb __user * __user *iocbpp, |
| 93 | bool compat) { return 0; } |
Kent Overstreet | 0460fef | 2013-05-07 16:18:49 -0700 | [diff] [blame] | 94 | static inline void kiocb_set_cancel_fn(struct kiocb *req, |
| 95 | kiocb_cancel_fn *cancel) { } |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 96 | #endif /* CONFIG_AIO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static inline struct kiocb *list_kiocb(struct list_head *h) |
| 99 | { |
| 100 | return list_entry(h, struct kiocb, ki_list); |
| 101 | } |
| 102 | |
| 103 | /* for sysctl: */ |
Zach Brown | d55b5fd | 2005-11-07 00:59:31 -0800 | [diff] [blame] | 104 | extern unsigned long aio_nr; |
| 105 | extern unsigned long aio_max_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | #endif /* __LINUX__AIO_H */ |