]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/aio.h
aio: Kill ki_users
[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  * 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))
29
30 typedef int (kiocb_cancel_fn)(struct kiocb *);
31
32 struct kiocb {
33         struct file             *ki_filp;
34         struct kioctx           *ki_ctx;        /* NULL for sync ops */
35         kiocb_cancel_fn         *ki_cancel;
36         void                    (*ki_dtor)(struct kiocb *);
37         void                    *private;
38
39         union {
40                 void __user             *user;
41                 struct task_struct      *tsk;
42         } ki_obj;
43
44         __u64                   ki_user_data;   /* user's data for completion */
45         loff_t                  ki_pos;
46         size_t                  ki_nbytes;      /* copy of iocb->aio_nbytes */
47
48         struct list_head        ki_list;        /* the aio core uses this
49                                                  * for cancellation */
50
51         /*
52          * If the aio_resfd field of the userspace iocb is not zero,
53          * this is the underlying eventfd context to deliver events to.
54          */
55         struct eventfd_ctx      *ki_eventfd;
56 };
57
58 static inline bool is_sync_kiocb(struct kiocb *kiocb)
59 {
60         return kiocb->ki_ctx == NULL;
61 }
62
63 static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
64 {
65         *kiocb = (struct kiocb) {
66                         .ki_ctx = NULL,
67                         .ki_filp = filp,
68                         .ki_obj.tsk = current,
69                 };
70 }
71
72 /* prototypes */
73 #ifdef CONFIG_AIO
74 extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
75 extern void aio_complete(struct kiocb *iocb, long res, long res2);
76 struct mm_struct;
77 extern void exit_aio(struct mm_struct *mm);
78 extern long do_io_submit(aio_context_t ctx_id, long nr,
79                          struct iocb __user *__user *iocbpp, bool compat);
80 void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
81 #else
82 static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
83 static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
84 struct mm_struct;
85 static inline void exit_aio(struct mm_struct *mm) { }
86 static inline long do_io_submit(aio_context_t ctx_id, long nr,
87                                 struct iocb __user * __user *iocbpp,
88                                 bool compat) { return 0; }
89 static inline void kiocb_set_cancel_fn(struct kiocb *req,
90                                        kiocb_cancel_fn *cancel) { }
91 #endif /* CONFIG_AIO */
92
93 static inline struct kiocb *list_kiocb(struct list_head *h)
94 {
95         return list_entry(h, struct kiocb, ki_list);
96 }
97
98 /* for sysctl: */
99 extern unsigned long aio_nr;
100 extern unsigned long aio_max_nr;
101
102 #endif /* __LINUX__AIO_H */