2005-04-17 06:20:36 +08:00
|
|
|
#ifndef __LINUX__AIO_H
|
|
|
|
#define __LINUX__AIO_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/aio_abi.h>
|
2006-10-01 14:28:46 +08:00
|
|
|
#include <linux/uio.h>
|
2008-12-09 15:11:22 +08:00
|
|
|
#include <linux/rcupdate.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct kioctx;
|
2013-05-08 07:18:49 +08:00
|
|
|
struct kiocb;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-08 07:19:10 +08:00
|
|
|
#define KIOCB_KEY 0
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-08 07:18:49 +08:00
|
|
|
/*
|
|
|
|
* 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))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-14 05:45:08 +08:00
|
|
|
typedef int (kiocb_cancel_fn)(struct kiocb *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct kiocb {
|
2013-05-08 07:18:39 +08:00
|
|
|
atomic_t ki_users;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct file *ki_filp;
|
2013-05-08 07:19:10 +08:00
|
|
|
struct kioctx *ki_ctx; /* NULL for sync ops */
|
2013-05-08 07:18:49 +08:00
|
|
|
kiocb_cancel_fn *ki_cancel;
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*ki_dtor)(struct kiocb *);
|
|
|
|
|
|
|
|
union {
|
|
|
|
void __user *user;
|
|
|
|
struct task_struct *tsk;
|
|
|
|
} ki_obj;
|
2006-01-08 17:04:34 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
__u64 ki_user_data; /* user's data for completion */
|
|
|
|
loff_t ki_pos;
|
2006-01-08 17:04:34 +08:00
|
|
|
|
|
|
|
void *private;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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 */
|
2006-10-01 14:28:46 +08:00
|
|
|
struct iovec ki_inline_vec; /* inline vector */
|
2006-10-01 14:28:49 +08:00
|
|
|
struct iovec *ki_iovec;
|
|
|
|
unsigned long ki_nr_segs;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-08 17:04:34 +08:00
|
|
|
struct list_head ki_list; /* the aio core uses this
|
|
|
|
* for cancellation */
|
signal/timer/event: KAIO eventfd support example
This is an example about how to add eventfd support to the current KAIO code,
in order to enable KAIO to post readiness events to a pollable fd (hence
compatible with POSIX select/poll). The KAIO code simply signals the eventfd
fd when events are ready, and this triggers a POLLIN in the fd. This patch
uses a reserved for future use member of the struct iocb to pass an eventfd
file descriptor, that KAIO will use to post events every time a request
completes. At that point, an aio_getevents() will return the completed result
to a struct io_event. I made a quick test program to verify the patch, and it
runs fine here:
http://www.xmailserver.org/eventfd-aio-test.c
The test program uses poll(2), but it'd, of course, work with select and epoll
too.
This can allow to schedule both block I/O and other poll-able devices
requests, and wait for results using select/poll/epoll. In a typical
scenario, an application would submit KAIO request using aio_submit(), and
will also use epoll_ctl() on the whole other class of devices (that with the
addition of signals, timers and user events, now it's pretty much complete),
and then would:
epoll_wait(...);
for_each_event {
if (curr_event_is_kaiofd) {
aio_getevents();
dispatch_aio_events();
} else {
dispatch_epoll_event();
}
}
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 13:23:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the aio_resfd field of the userspace iocb is not zero,
|
2009-07-01 02:41:11 +08:00
|
|
|
* this is the underlying eventfd context to deliver events to.
|
signal/timer/event: KAIO eventfd support example
This is an example about how to add eventfd support to the current KAIO code,
in order to enable KAIO to post readiness events to a pollable fd (hence
compatible with POSIX select/poll). The KAIO code simply signals the eventfd
fd when events are ready, and this triggers a POLLIN in the fd. This patch
uses a reserved for future use member of the struct iocb to pass an eventfd
file descriptor, that KAIO will use to post events every time a request
completes. At that point, an aio_getevents() will return the completed result
to a struct io_event. I made a quick test program to verify the patch, and it
runs fine here:
http://www.xmailserver.org/eventfd-aio-test.c
The test program uses poll(2), but it'd, of course, work with select and epoll
too.
This can allow to schedule both block I/O and other poll-able devices
requests, and wait for results using select/poll/epoll. In a typical
scenario, an application would submit KAIO request using aio_submit(), and
will also use epoll_ctl() on the whole other class of devices (that with the
addition of signals, timers and user events, now it's pretty much complete),
and then would:
epoll_wait(...);
for_each_event {
if (curr_event_is_kaiofd) {
aio_getevents();
dispatch_aio_events();
} else {
dispatch_epoll_event();
}
}
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 13:23:21 +08:00
|
|
|
*/
|
2009-07-01 02:41:11 +08:00
|
|
|
struct eventfd_ctx *ki_eventfd;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2012-07-31 05:42:56 +08:00
|
|
|
static inline bool is_sync_kiocb(struct kiocb *kiocb)
|
|
|
|
{
|
2013-05-08 07:19:10 +08:00
|
|
|
return kiocb->ki_ctx == NULL;
|
2012-07-31 05:42:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
|
|
|
|
{
|
|
|
|
*kiocb = (struct kiocb) {
|
2013-05-08 07:18:39 +08:00
|
|
|
.ki_users = ATOMIC_INIT(1),
|
2013-05-08 07:19:10 +08:00
|
|
|
.ki_ctx = NULL,
|
2012-07-31 05:42:56 +08:00
|
|
|
.ki_filp = filp,
|
|
|
|
.ki_obj.tsk = current,
|
|
|
|
};
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* prototypes */
|
2008-10-16 13:05:12 +08:00
|
|
|
#ifdef CONFIG_AIO
|
2008-02-14 07:03:15 +08:00
|
|
|
extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
|
2013-05-08 07:18:29 +08:00
|
|
|
extern void aio_put_req(struct kiocb *iocb);
|
|
|
|
extern void aio_complete(struct kiocb *iocb, long res, long res2);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mm_struct;
|
2008-02-14 07:03:15 +08:00
|
|
|
extern void exit_aio(struct mm_struct *mm);
|
2010-05-27 05:44:26 +08:00
|
|
|
extern long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user *__user *iocbpp, bool compat);
|
2013-05-08 07:18:49 +08:00
|
|
|
void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
|
2008-10-16 13:05:12 +08:00
|
|
|
#else
|
|
|
|
static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
|
2013-05-08 07:18:29 +08:00
|
|
|
static inline void aio_put_req(struct kiocb *iocb) { }
|
|
|
|
static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
|
2008-10-16 13:05:12 +08:00
|
|
|
struct mm_struct;
|
|
|
|
static inline void exit_aio(struct mm_struct *mm) { }
|
2010-05-27 05:44:26 +08:00
|
|
|
static inline long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user * __user *iocbpp,
|
|
|
|
bool compat) { return 0; }
|
2013-05-08 07:18:49 +08:00
|
|
|
static inline void kiocb_set_cancel_fn(struct kiocb *req,
|
|
|
|
kiocb_cancel_fn *cancel) { }
|
2008-10-16 13:05:12 +08:00
|
|
|
#endif /* CONFIG_AIO */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static inline struct kiocb *list_kiocb(struct list_head *h)
|
|
|
|
{
|
|
|
|
return list_entry(h, struct kiocb, ki_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for sysctl: */
|
2005-11-07 16:59:31 +08:00
|
|
|
extern unsigned long aio_nr;
|
|
|
|
extern unsigned long aio_max_nr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* __LINUX__AIO_H */
|