]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/aio.h
Merge tag 'writeback-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/wfg...
[mirror_ubuntu-bionic-kernel.git] / include / linux / aio.h
CommitLineData
1da177e4
LT
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>
027445c3 7#include <linux/uio.h>
abf137dd 8#include <linux/rcupdate.h>
1da177e4 9
60063497 10#include <linux/atomic.h>
1da177e4 11
1da177e4 12struct kioctx;
0460fef2 13struct kiocb;
1da177e4 14
8a660890 15#define KIOCB_KEY 0
1da177e4 16
0460fef2
KO
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))
1da177e4 29
bec68faa 30typedef int (kiocb_cancel_fn)(struct kiocb *);
1da177e4
LT
31
32struct kiocb {
1da177e4 33 struct file *ki_filp;
8a660890 34 struct kioctx *ki_ctx; /* NULL for sync ops */
0460fef2 35 kiocb_cancel_fn *ki_cancel;
8bc92afc 36 void *private;
1da177e4 37
1da177e4
LT
38 union {
39 void __user *user;
40 struct task_struct *tsk;
41 } ki_obj;
59d9136b 42
1da177e4
LT
43 __u64 ki_user_data; /* user's data for completion */
44 loff_t ki_pos;
8bc92afc 45 size_t ki_nbytes; /* copy of iocb->aio_nbytes */
1da177e4 46
59d9136b
BL
47 struct list_head ki_list; /* the aio core uses this
48 * for cancellation */
9c3060be
DL
49
50 /*
51 * If the aio_resfd field of the userspace iocb is not zero,
13389010 52 * this is the underlying eventfd context to deliver events to.
9c3060be 53 */
13389010 54 struct eventfd_ctx *ki_eventfd;
1da177e4
LT
55};
56
f7e1becb
AM
57static inline bool is_sync_kiocb(struct kiocb *kiocb)
58{
8a660890 59 return kiocb->ki_ctx == NULL;
f7e1becb
AM
60}
61
62static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
63{
64 *kiocb = (struct kiocb) {
8a660890 65 .ki_ctx = NULL,
f7e1becb
AM
66 .ki_filp = filp,
67 .ki_obj.tsk = current,
68 };
69}
1da177e4 70
1da177e4 71/* prototypes */
ebf3f09c 72#ifdef CONFIG_AIO
b3c97528 73extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
2d68449e 74extern void aio_complete(struct kiocb *iocb, long res, long res2);
1da177e4 75struct mm_struct;
b3c97528 76extern void exit_aio(struct mm_struct *mm);
9d85cba7
JM
77extern long do_io_submit(aio_context_t ctx_id, long nr,
78 struct iocb __user *__user *iocbpp, bool compat);
0460fef2 79void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
ebf3f09c
TP
80#else
81static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
2d68449e 82static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
ebf3f09c
TP
83struct mm_struct;
84static inline void exit_aio(struct mm_struct *mm) { }
9d85cba7
JM
85static inline long do_io_submit(aio_context_t ctx_id, long nr,
86 struct iocb __user * __user *iocbpp,
87 bool compat) { return 0; }
0460fef2
KO
88static inline void kiocb_set_cancel_fn(struct kiocb *req,
89 kiocb_cancel_fn *cancel) { }
ebf3f09c 90#endif /* CONFIG_AIO */
1da177e4 91
1da177e4
LT
92static inline struct kiocb *list_kiocb(struct list_head *h)
93{
94 return list_entry(h, struct kiocb, ki_list);
95}
96
97/* for sysctl: */
d55b5fda
ZB
98extern unsigned long aio_nr;
99extern unsigned long aio_max_nr;
1da177e4
LT
100
101#endif /* __LINUX__AIO_H */