]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/aio.h
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / include / linux / aio.h
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>
7 #include <linux/uio.h>
8 #include <linux/rcupdate.h>
9
10 #include <linux/atomic.h>
11
12 struct kioctx;
13 struct kiocb;
14
15 #define KIOCB_KEY               0
16
17 /*
18  * opcode values not exposed to user space
19  */
20 enum {
21         IOCB_CMD_READ_ITER = 0x10000,
22         IOCB_CMD_WRITE_ITER = 0x10001,
23 };
24
25 /*
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
29  * userspace).
30  *
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().
35  */
36 #define KIOCB_CANCELLED         ((void *) (~0ULL))
37
38 typedef int (kiocb_cancel_fn)(struct kiocb *);
39
40 struct kiocb {
41         struct file             *ki_filp;
42         struct kioctx           *ki_ctx;        /* NULL for sync ops,
43                                                  * -1 for kernel caller */
44         kiocb_cancel_fn         *ki_cancel;
45         void                    *private;
46
47         union {
48                 void __user             *user;
49                 struct task_struct      *tsk;
50                 void                    (*complete)(u64 user_data, long res);
51         } ki_obj;
52
53         __u64                   ki_user_data;   /* user's data for completion */
54         loff_t                  ki_pos;
55         size_t                  ki_nbytes;      /* copy of iocb->aio_nbytes */
56
57         struct list_head        ki_list;        /* the aio core uses this
58                                                  * for cancellation */
59
60         /*
61          * If the aio_resfd field of the userspace iocb is not zero,
62          * this is the underlying eventfd context to deliver events to.
63          */
64         struct eventfd_ctx      *ki_eventfd;
65 };
66
67 static inline bool is_sync_kiocb(struct kiocb *kiocb)
68 {
69         return kiocb->ki_ctx == NULL;
70 }
71
72 static inline bool is_kernel_kiocb(struct kiocb *kiocb)
73 {
74         return kiocb->ki_ctx == (void *)-1;
75 }
76
77 static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
78 {
79         *kiocb = (struct kiocb) {
80                         .ki_ctx = NULL,
81                         .ki_filp = filp,
82                         .ki_obj.tsk = current,
83                 };
84 }
85
86 /* prototypes */
87 #ifdef CONFIG_AIO
88 extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
89 extern void aio_complete(struct kiocb *iocb, long res, long res2);
90 struct mm_struct;
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,
98                         loff_t off);
99 void aio_kernel_init_callback(struct kiocb *iocb,
100                               void (*complete)(u64 user_data, long res),
101                               u64 user_data);
102 int aio_kernel_submit(struct kiocb *iocb, unsigned op, void *ptr);
103 #else
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) { }
106 struct mm_struct;
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 */
114
115 static inline struct kiocb *list_kiocb(struct list_head *h)
116 {
117         return list_entry(h, struct kiocb, ki_list);
118 }
119
120 /* for sysctl: */
121 extern unsigned long aio_nr;
122 extern unsigned long aio_max_nr;
123
124 #endif /* __LINUX__AIO_H */