VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.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
8 #include <asm/atomic.h>
9
10 #define AIO_MAXSEGS             4
11 #define AIO_KIOGRP_NR_ATOMIC    8
12
13 struct kioctx;
14
15 /* Notes on cancelling a kiocb:
16  *      If a kiocb is cancelled, aio_complete may return 0 to indicate 
17  *      that cancel has not yet disposed of the kiocb.  All cancel 
18  *      operations *must* call aio_put_req to dispose of the kiocb 
19  *      to guard against races with the completion code.
20  */
21 #define KIOCB_C_CANCELLED       0x01
22 #define KIOCB_C_COMPLETE        0x02
23
24 #define KIOCB_SYNC_KEY          (~0U)
25
26 /* ki_flags bits */
27 #define KIF_LOCKED              0
28 #define KIF_KICKED              1
29 #define KIF_CANCELLED           2
30
31 #define kiocbTryLock(iocb)      test_and_set_bit(KIF_LOCKED, &(iocb)->ki_flags)
32 #define kiocbTryKick(iocb)      test_and_set_bit(KIF_KICKED, &(iocb)->ki_flags)
33
34 #define kiocbSetLocked(iocb)    set_bit(KIF_LOCKED, &(iocb)->ki_flags)
35 #define kiocbSetKicked(iocb)    set_bit(KIF_KICKED, &(iocb)->ki_flags)
36 #define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags)
37
38 #define kiocbClearLocked(iocb)  clear_bit(KIF_LOCKED, &(iocb)->ki_flags)
39 #define kiocbClearKicked(iocb)  clear_bit(KIF_KICKED, &(iocb)->ki_flags)
40 #define kiocbClearCancelled(iocb)       clear_bit(KIF_CANCELLED, &(iocb)->ki_flags)
41
42 #define kiocbIsLocked(iocb)     test_bit(KIF_LOCKED, &(iocb)->ki_flags)
43 #define kiocbIsKicked(iocb)     test_bit(KIF_KICKED, &(iocb)->ki_flags)
44 #define kiocbIsCancelled(iocb)  test_bit(KIF_CANCELLED, &(iocb)->ki_flags)
45
46 struct kiocb {
47         struct list_head        ki_run_list;
48         long                    ki_flags;
49         int                     ki_users;
50         unsigned                ki_key;         /* id of this request */
51
52         struct file             *ki_filp;
53         struct kioctx           *ki_ctx;        /* may be NULL for sync ops */
54         int                     (*ki_cancel)(struct kiocb *, struct io_event *);
55         long                    (*ki_retry)(struct kiocb *);
56         void                    (*ki_dtor)(struct kiocb *);
57
58         struct list_head        ki_list;        /* the aio core uses this
59                                                  * for cancellation */
60
61         union {
62                 void __user             *user;
63                 struct task_struct      *tsk;
64         } ki_obj;
65         __u64                   ki_user_data;   /* user's data for completion */
66         loff_t                  ki_pos;
67         void                    *private;
68 };
69
70 #define is_sync_kiocb(iocb)     ((iocb)->ki_key == KIOCB_SYNC_KEY)
71 #define init_sync_kiocb(x, filp)                        \
72         do {                                            \
73                 struct task_struct *tsk = current;      \
74                 (x)->ki_flags = 0;                      \
75                 (x)->ki_users = 1;                      \
76                 (x)->ki_key = KIOCB_SYNC_KEY;           \
77                 (x)->ki_filp = (filp);                  \
78                 (x)->ki_ctx = &tsk->active_mm->default_kioctx;  \
79                 (x)->ki_cancel = NULL;                  \
80                 (x)->ki_dtor = NULL;                    \
81                 (x)->ki_obj.tsk = tsk;                  \
82         } while (0)
83
84 #define AIO_RING_MAGIC                  0xa10a10a1
85 #define AIO_RING_COMPAT_FEATURES        1
86 #define AIO_RING_INCOMPAT_FEATURES      0
87 struct aio_ring {
88         unsigned        id;     /* kernel internal index number */
89         unsigned        nr;     /* number of io_events */
90         unsigned        head;
91         unsigned        tail;
92
93         unsigned        magic;
94         unsigned        compat_features;
95         unsigned        incompat_features;
96         unsigned        header_length;  /* size of aio_ring */
97
98
99         struct io_event         io_events[0];
100 }; /* 128 bytes + ring size */
101
102 #define aio_ring_avail(info, ring)      (((ring)->head + (info)->nr - 1 - (ring)->tail) % (info)->nr)
103
104 #define AIO_RING_PAGES  8
105 struct aio_ring_info {
106         unsigned long           mmap_base;
107         unsigned long           mmap_size;
108
109         struct page             **ring_pages;
110         spinlock_t              ring_lock;
111         long                    nr_pages;
112
113         unsigned                nr, tail;
114
115         struct page             *internal_pages[AIO_RING_PAGES];
116 };
117
118 struct kioctx {
119         atomic_t                users;
120         int                     dead;
121         struct mm_struct        *mm;
122
123         /* This needs improving */
124         unsigned long           user_id;
125         struct kioctx           *next;
126
127         wait_queue_head_t       wait;
128
129         spinlock_t              ctx_lock;
130
131         int                     reqs_active;
132         struct list_head        active_reqs;    /* used for cancellation */
133         struct list_head        run_list;       /* used for kicked reqs */
134
135         unsigned                max_reqs;
136
137         struct aio_ring_info    ring_info;
138
139         struct work_struct      wq;
140 };
141
142 /* prototypes */
143 extern unsigned aio_max_size;
144
145 extern ssize_t FASTCALL(wait_on_sync_kiocb(struct kiocb *iocb));
146 extern int FASTCALL(aio_put_req(struct kiocb *iocb));
147 extern void FASTCALL(kick_iocb(struct kiocb *iocb));
148 extern int FASTCALL(aio_complete(struct kiocb *iocb, long res, long res2));
149 extern void FASTCALL(__put_ioctx(struct kioctx *ctx));
150 struct mm_struct;
151 extern void FASTCALL(exit_aio(struct mm_struct *mm));
152 extern struct kioctx *lookup_ioctx(unsigned long ctx_id);
153 extern int FASTCALL(io_submit_one(struct kioctx *ctx,
154                         struct iocb __user *user_iocb, struct iocb *iocb));
155
156 /* semi private, but used by the 32bit emulations: */
157 struct kioctx *lookup_ioctx(unsigned long ctx_id);
158 int FASTCALL(io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
159                                   struct iocb *iocb));
160
161 #define get_ioctx(kioctx)       do { if (unlikely(atomic_read(&(kioctx)->users) <= 0)) BUG(); atomic_inc(&(kioctx)->users); } while (0)
162 #define put_ioctx(kioctx)       do { if (unlikely(atomic_dec_and_test(&(kioctx)->users))) __put_ioctx(kioctx); else if (unlikely(atomic_read(&(kioctx)->users) < 0)) BUG(); } while (0)
163
164 #include <linux/aio_abi.h>
165
166 static inline struct kiocb *list_kiocb(struct list_head *h)
167 {
168         return list_entry(h, struct kiocb, ki_list);
169 }
170
171 /* for sysctl: */
172 extern atomic_t aio_nr;
173 extern unsigned aio_max_nr;
174
175 #endif /* __LINUX__AIO_H */