2005-04-16 15:20:36 -07:00
|
|
|
#ifndef __LINUX__AIO_H
|
|
|
|
#define __LINUX__AIO_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/aio_abi.h>
|
2006-09-30 23:28:46 -07:00
|
|
|
#include <linux/uio.h>
|
2008-12-09 08:11:22 +01:00
|
|
|
#include <linux/rcupdate.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2011-07-26 16:09:06 -07:00
|
|
|
#include <linux/atomic.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
struct kioctx;
|
|
|
|
|
|
|
|
#define KIOCB_SYNC_KEY (~0U)
|
|
|
|
|
|
|
|
/* ki_flags bits */
|
|
|
|
#define KIF_CANCELLED 2
|
|
|
|
|
|
|
|
#define kiocbSetCancelled(iocb) set_bit(KIF_CANCELLED, &(iocb)->ki_flags)
|
|
|
|
|
|
|
|
#define kiocbClearCancelled(iocb) clear_bit(KIF_CANCELLED, &(iocb)->ki_flags)
|
|
|
|
|
|
|
|
#define kiocbIsCancelled(iocb) test_bit(KIF_CANCELLED, &(iocb)->ki_flags)
|
|
|
|
|
2005-09-30 11:58:55 -07:00
|
|
|
/* is there a better place to document function pointer methods? */
|
|
|
|
/**
|
|
|
|
* ki_retry - iocb forward progress callback
|
|
|
|
* @kiocb: The kiocb struct to advance by performing an operation.
|
|
|
|
*
|
|
|
|
* This callback is called when the AIO core wants a given AIO operation
|
|
|
|
* to make forward progress. The kiocb argument describes the operation
|
|
|
|
* that is to be performed. As the operation proceeds, perhaps partially,
|
|
|
|
* ki_retry is expected to update the kiocb with progress made. Typically
|
|
|
|
* ki_retry is set in the AIO core and it itself calls file_operations
|
|
|
|
* helpers.
|
|
|
|
*
|
|
|
|
* ki_retry's return value determines when the AIO operation is completed
|
|
|
|
* and an event is generated in the AIO event ring. Except the special
|
|
|
|
* return values described below, the value that is returned from ki_retry
|
|
|
|
* is transferred directly into the completion ring as the operation's
|
|
|
|
* resulting status. Once this has happened ki_retry *MUST NOT* reference
|
|
|
|
* the kiocb pointer again.
|
|
|
|
*
|
|
|
|
* If ki_retry returns -EIOCBQUEUED it has made a promise that aio_complete()
|
|
|
|
* will be called on the kiocb pointer in the future. The AIO core will
|
|
|
|
* not ask the method again -- ki_retry must ensure forward progress.
|
|
|
|
* aio_complete() must be called once and only once in the future, multiple
|
|
|
|
* calls may result in undefined behaviour.
|
|
|
|
*/
|
2005-04-16 15:20:36 -07:00
|
|
|
struct kiocb {
|
2007-07-19 01:47:55 -07:00
|
|
|
unsigned long ki_flags;
|
2005-04-16 15:20:36 -07:00
|
|
|
int ki_users;
|
|
|
|
unsigned ki_key; /* id of this request */
|
|
|
|
|
|
|
|
struct file *ki_filp;
|
|
|
|
struct kioctx *ki_ctx; /* may be NULL for sync ops */
|
|
|
|
int (*ki_cancel)(struct kiocb *, struct io_event *);
|
|
|
|
ssize_t (*ki_retry)(struct kiocb *);
|
|
|
|
void (*ki_dtor)(struct kiocb *);
|
|
|
|
|
|
|
|
union {
|
|
|
|
void __user *user;
|
|
|
|
struct task_struct *tsk;
|
|
|
|
} ki_obj;
|
2006-01-08 01:04:34 -08:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
__u64 ki_user_data; /* user's data for completion */
|
|
|
|
loff_t ki_pos;
|
2006-01-08 01:04:34 -08:00
|
|
|
|
|
|
|
void *private;
|
2005-04-16 15:20:36 -07: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 */
|
|
|
|
size_t ki_left; /* remaining bytes */
|
2006-09-30 23:28:46 -07:00
|
|
|
struct iovec ki_inline_vec; /* inline vector */
|
2006-09-30 23:28:49 -07:00
|
|
|
struct iovec *ki_iovec;
|
|
|
|
unsigned long ki_nr_segs;
|
|
|
|
unsigned long ki_cur_seg;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-01-08 01:04:34 -08:00
|
|
|
struct list_head ki_list; /* the aio core uses this
|
|
|
|
* for cancellation */
|
2011-11-02 13:40:10 -07:00
|
|
|
struct list_head ki_batch; /* batch allocation */
|
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-10 22:23:21 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the aio_resfd field of the userspace iocb is not zero,
|
2009-06-30 11:41:11 -07: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-10 22:23:21 -07:00
|
|
|
*/
|
2009-06-30 11:41:11 -07:00
|
|
|
struct eventfd_ctx *ki_eventfd;
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
2012-07-30 14:42:56 -07:00
|
|
|
static inline bool is_sync_kiocb(struct kiocb *kiocb)
|
|
|
|
{
|
|
|
|
return kiocb->ki_key == KIOCB_SYNC_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
|
|
|
|
{
|
|
|
|
*kiocb = (struct kiocb) {
|
|
|
|
.ki_users = 1,
|
|
|
|
.ki_key = KIOCB_SYNC_KEY,
|
|
|
|
.ki_filp = filp,
|
|
|
|
.ki_obj.tsk = current,
|
|
|
|
};
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* prototypes */
|
2008-10-15 22:05:12 -07:00
|
|
|
#ifdef CONFIG_AIO
|
2008-02-13 15:03:15 -08:00
|
|
|
extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
|
2013-05-07 16:18:29 -07:00
|
|
|
extern void aio_put_req(struct kiocb *iocb);
|
|
|
|
extern void aio_complete(struct kiocb *iocb, long res, long res2);
|
2005-04-16 15:20:36 -07:00
|
|
|
struct mm_struct;
|
2008-02-13 15:03:15 -08:00
|
|
|
extern void exit_aio(struct mm_struct *mm);
|
2010-05-26 14:44:26 -07:00
|
|
|
extern long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user *__user *iocbpp, bool compat);
|
2008-10-15 22:05:12 -07:00
|
|
|
#else
|
|
|
|
static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
|
2013-05-07 16:18:29 -07:00
|
|
|
static inline void aio_put_req(struct kiocb *iocb) { }
|
|
|
|
static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
|
2008-10-15 22:05:12 -07:00
|
|
|
struct mm_struct;
|
|
|
|
static inline void exit_aio(struct mm_struct *mm) { }
|
2010-05-26 14:44:26 -07:00
|
|
|
static inline long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user * __user *iocbpp,
|
|
|
|
bool compat) { return 0; }
|
2008-10-15 22:05:12 -07:00
|
|
|
#endif /* CONFIG_AIO */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
static inline struct kiocb *list_kiocb(struct list_head *h)
|
|
|
|
{
|
|
|
|
return list_entry(h, struct kiocb, ki_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for sysctl: */
|
2005-11-07 00:59:31 -08:00
|
|
|
extern unsigned long aio_nr;
|
|
|
|
extern unsigned long aio_max_nr;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#endif /* __LINUX__AIO_H */
|