aio.h 3.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
#ifndef __LINUX__AIO_H
#define __LINUX__AIO_H

#include <linux/list.h>
#include <linux/workqueue.h>
#include <linux/aio_abi.h>
7
#include <linux/uio.h>
J
Jens Axboe 已提交
8
#include <linux/rcupdate.h>
L
Linus Torvalds 已提交
9

A
Arun Sharma 已提交
10
#include <linux/atomic.h>
L
Linus Torvalds 已提交
11 12

struct kioctx;
13
struct kiocb;
L
Linus Torvalds 已提交
14

K
Kent Overstreet 已提交
15
#define KIOCB_KEY		0
L
Linus Torvalds 已提交
16

17 18 19 20 21 22 23 24 25 26 27 28
/*
 * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either
 * cancelled or completed (this makes a certain amount of sense because
 * successful cancellation - io_cancel() - does deliver the completion to
 * userspace).
 *
 * And since most things don't implement kiocb cancellation and we'd really like
 * kiocb completion to be lockless when possible, we use ki_cancel to
 * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED
 * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel().
 */
#define KIOCB_CANCELLED		((void *) (~0ULL))
L
Linus Torvalds 已提交
29

30
typedef int (kiocb_cancel_fn)(struct kiocb *);
L
Linus Torvalds 已提交
31 32

struct kiocb {
33
	atomic_t		ki_users;
L
Linus Torvalds 已提交
34 35

	struct file		*ki_filp;
K
Kent Overstreet 已提交
36
	struct kioctx		*ki_ctx;	/* NULL for sync ops */
37
	kiocb_cancel_fn		*ki_cancel;
L
Linus Torvalds 已提交
38 39 40 41 42 43
	void			(*ki_dtor)(struct kiocb *);

	union {
		void __user		*user;
		struct task_struct	*tsk;
	} ki_obj;
44

L
Linus Torvalds 已提交
45 46
	__u64			ki_user_data;	/* user's data for completion */
	loff_t			ki_pos;
47 48

	void			*private;
L
Linus Torvalds 已提交
49 50 51 52
	/* State that we remember to be able to restart/retry  */
	unsigned short		ki_opcode;
	size_t			ki_nbytes; 	/* copy of iocb->aio_nbytes */
	char 			__user *ki_buf;	/* remaining iocb->aio_buf */
53
	struct iovec		ki_inline_vec;	/* inline vector */
B
Badari Pulavarty 已提交
54 55
 	struct iovec		*ki_iovec;
 	unsigned long		ki_nr_segs;
L
Linus Torvalds 已提交
56

57 58
	struct list_head	ki_list;	/* the aio core uses this
						 * 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;
L
Linus Torvalds 已提交
65 66
};

67 68
static inline bool is_sync_kiocb(struct kiocb *kiocb)
{
K
Kent Overstreet 已提交
69
	return kiocb->ki_ctx == NULL;
70 71 72 73 74
}

static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
{
	*kiocb = (struct kiocb) {
75
			.ki_users = ATOMIC_INIT(1),
K
Kent Overstreet 已提交
76
			.ki_ctx = NULL,
77 78 79 80
			.ki_filp = filp,
			.ki_obj.tsk = current,
		};
}
L
Linus Torvalds 已提交
81 82

/* prototypes */
T
Thomas Petazzoni 已提交
83
#ifdef CONFIG_AIO
84
extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
85 86
extern void aio_put_req(struct kiocb *iocb);
extern void aio_complete(struct kiocb *iocb, long res, long res2);
L
Linus Torvalds 已提交
87
struct mm_struct;
88
extern void exit_aio(struct mm_struct *mm);
89 90
extern long do_io_submit(aio_context_t ctx_id, long nr,
			 struct iocb __user *__user *iocbpp, bool compat);
91
void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
T
Thomas Petazzoni 已提交
92 93
#else
static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
94 95
static inline void aio_put_req(struct kiocb *iocb) { }
static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
T
Thomas Petazzoni 已提交
96 97
struct mm_struct;
static inline void exit_aio(struct mm_struct *mm) { }
98 99 100
static inline long do_io_submit(aio_context_t ctx_id, long nr,
				struct iocb __user * __user *iocbpp,
				bool compat) { return 0; }
101 102
static inline void kiocb_set_cancel_fn(struct kiocb *req,
				       kiocb_cancel_fn *cancel) { }
T
Thomas Petazzoni 已提交
103
#endif /* CONFIG_AIO */
L
Linus Torvalds 已提交
104 105 106 107 108 109 110

static inline struct kiocb *list_kiocb(struct list_head *h)
{
	return list_entry(h, struct kiocb, ki_list);
}

/* for sysctl: */
111 112
extern unsigned long aio_nr;
extern unsigned long aio_max_nr;
L
Linus Torvalds 已提交
113 114

#endif /* __LINUX__AIO_H */