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; |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #define KIOCB_SYNC_KEY (~0U) |
| 15 | |
| 16 | /* ki_flags bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define KIF_CANCELLED 2 |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags) |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define kiocbClearCancelled(iocb) clear_bit(KIF_CANCELLED, &(iocb)->ki_flags) |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define kiocbIsCancelled(iocb) test_bit(KIF_CANCELLED, &(iocb)->ki_flags) |
| 24 | |
Zach Brown | 897f15f | 2005-09-30 11:58:55 -0700 | [diff] [blame] | 25 | /* is there a better place to document function pointer methods? */ |
| 26 | /** |
| 27 | * ki_retry - iocb forward progress callback |
| 28 | * @kiocb: The kiocb struct to advance by performing an operation. |
| 29 | * |
| 30 | * This callback is called when the AIO core wants a given AIO operation |
| 31 | * to make forward progress. The kiocb argument describes the operation |
| 32 | * that is to be performed. As the operation proceeds, perhaps partially, |
| 33 | * ki_retry is expected to update the kiocb with progress made. Typically |
| 34 | * ki_retry is set in the AIO core and it itself calls file_operations |
| 35 | * helpers. |
| 36 | * |
| 37 | * ki_retry's return value determines when the AIO operation is completed |
| 38 | * and an event is generated in the AIO event ring. Except the special |
| 39 | * return values described below, the value that is returned from ki_retry |
| 40 | * is transferred directly into the completion ring as the operation's |
| 41 | * resulting status. Once this has happened ki_retry *MUST NOT* reference |
| 42 | * the kiocb pointer again. |
| 43 | * |
| 44 | * If ki_retry returns -EIOCBQUEUED it has made a promise that aio_complete() |
| 45 | * will be called on the kiocb pointer in the future. The AIO core will |
| 46 | * not ask the method again -- ki_retry must ensure forward progress. |
| 47 | * aio_complete() must be called once and only once in the future, multiple |
| 48 | * calls may result in undefined behaviour. |
Zach Brown | 897f15f | 2005-09-30 11:58:55 -0700 | [diff] [blame] | 49 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct kiocb { |
David Brownell | 2ba2d00 | 2007-07-19 01:47:55 -0700 | [diff] [blame] | 51 | unsigned long ki_flags; |
Kent Overstreet | 11599eb | 2013-05-07 16:18:39 -0700 | [diff] [blame^] | 52 | atomic_t ki_users; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | unsigned ki_key; /* id of this request */ |
| 54 | |
| 55 | struct file *ki_filp; |
| 56 | struct kioctx *ki_ctx; /* may be NULL for sync ops */ |
| 57 | int (*ki_cancel)(struct kiocb *, struct io_event *); |
| 58 | ssize_t (*ki_retry)(struct kiocb *); |
| 59 | void (*ki_dtor)(struct kiocb *); |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | union { |
| 62 | void __user *user; |
| 63 | struct task_struct *tsk; |
| 64 | } ki_obj; |
Benjamin LaHaise | 59d9136 | 2006-01-08 01:04:34 -0800 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | __u64 ki_user_data; /* user's data for completion */ |
| 67 | loff_t ki_pos; |
Benjamin LaHaise | 59d9136 | 2006-01-08 01:04:34 -0800 | [diff] [blame] | 68 | |
| 69 | void *private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* State that we remember to be able to restart/retry */ |
| 71 | unsigned short ki_opcode; |
| 72 | size_t ki_nbytes; /* copy of iocb->aio_nbytes */ |
| 73 | char __user *ki_buf; /* remaining iocb->aio_buf */ |
| 74 | size_t ki_left; /* remaining bytes */ |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 75 | struct iovec ki_inline_vec; /* inline vector */ |
Badari Pulavarty | eed4e51 | 2006-09-30 23:28:49 -0700 | [diff] [blame] | 76 | struct iovec *ki_iovec; |
| 77 | unsigned long ki_nr_segs; |
| 78 | unsigned long ki_cur_seg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Benjamin LaHaise | 59d9136 | 2006-01-08 01:04:34 -0800 | [diff] [blame] | 80 | struct list_head ki_list; /* the aio core uses this |
| 81 | * for cancellation */ |
Jeff Moyer | 080d676 | 2011-11-02 13:40:10 -0700 | [diff] [blame] | 82 | struct list_head ki_batch; /* batch allocation */ |
Davide Libenzi | 9c3060b | 2007-05-10 22:23:21 -0700 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * If the aio_resfd field of the userspace iocb is not zero, |
Davide Libenzi | 1338901 | 2009-06-30 11:41:11 -0700 | [diff] [blame] | 86 | * this is the underlying eventfd context to deliver events to. |
Davide Libenzi | 9c3060b | 2007-05-10 22:23:21 -0700 | [diff] [blame] | 87 | */ |
Davide Libenzi | 1338901 | 2009-06-30 11:41:11 -0700 | [diff] [blame] | 88 | struct eventfd_ctx *ki_eventfd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Andrew Morton | f7e1bec | 2012-07-30 14:42:56 -0700 | [diff] [blame] | 91 | static inline bool is_sync_kiocb(struct kiocb *kiocb) |
| 92 | { |
| 93 | return kiocb->ki_key == KIOCB_SYNC_KEY; |
| 94 | } |
| 95 | |
| 96 | static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) |
| 97 | { |
| 98 | *kiocb = (struct kiocb) { |
Kent Overstreet | 11599eb | 2013-05-07 16:18:39 -0700 | [diff] [blame^] | 99 | .ki_users = ATOMIC_INIT(1), |
Andrew Morton | f7e1bec | 2012-07-30 14:42:56 -0700 | [diff] [blame] | 100 | .ki_key = KIOCB_SYNC_KEY, |
| 101 | .ki_filp = filp, |
| 102 | .ki_obj.tsk = current, |
| 103 | }; |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* prototypes */ |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 107 | #ifdef CONFIG_AIO |
Harvey Harrison | b3c9752 | 2008-02-13 15:03:15 -0800 | [diff] [blame] | 108 | extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb); |
Kent Overstreet | 2d68449 | 2013-05-07 16:18:29 -0700 | [diff] [blame] | 109 | extern void aio_put_req(struct kiocb *iocb); |
| 110 | extern void aio_complete(struct kiocb *iocb, long res, long res2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | struct mm_struct; |
Harvey Harrison | b3c9752 | 2008-02-13 15:03:15 -0800 | [diff] [blame] | 112 | extern void exit_aio(struct mm_struct *mm); |
Jeff Moyer | 9d85cba | 2010-05-26 14:44:26 -0700 | [diff] [blame] | 113 | extern long do_io_submit(aio_context_t ctx_id, long nr, |
| 114 | struct iocb __user *__user *iocbpp, bool compat); |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 115 | #else |
| 116 | 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] | 117 | static inline void aio_put_req(struct kiocb *iocb) { } |
| 118 | static inline void aio_complete(struct kiocb *iocb, long res, long res2) { } |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 119 | struct mm_struct; |
| 120 | static inline void exit_aio(struct mm_struct *mm) { } |
Jeff Moyer | 9d85cba | 2010-05-26 14:44:26 -0700 | [diff] [blame] | 121 | static inline long do_io_submit(aio_context_t ctx_id, long nr, |
| 122 | struct iocb __user * __user *iocbpp, |
| 123 | bool compat) { return 0; } |
Thomas Petazzoni | ebf3f09 | 2008-10-15 22:05:12 -0700 | [diff] [blame] | 124 | #endif /* CONFIG_AIO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static inline struct kiocb *list_kiocb(struct list_head *h) |
| 127 | { |
| 128 | return list_entry(h, struct kiocb, ki_list); |
| 129 | } |
| 130 | |
| 131 | /* for sysctl: */ |
Zach Brown | d55b5fd | 2005-11-07 00:59:31 -0800 | [diff] [blame] | 132 | extern unsigned long aio_nr; |
| 133 | extern unsigned long aio_max_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | #endif /* __LINUX__AIO_H */ |