2024-09-09 08:52:07 +00:00
|
|
|
#ifndef __LINUX__AIO_H
|
|
|
|
#define __LINUX__AIO_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/aio_abi.h>
|
|
|
|
#include <linux/uio.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
|
|
|
|
#include <linux/atomic.h>
|
|
|
|
|
|
|
|
struct kioctx;
|
2024-09-09 08:57:42 +00:00
|
|
|
struct kiocb;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
#define KIOCB_KEY 0
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
/*
|
2024-09-09 08:57:42 +00: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().
|
2024-09-09 08:52:07 +00:00
|
|
|
*/
|
2024-09-09 08:57:42 +00:00
|
|
|
#define KIOCB_CANCELLED ((void *) (~0ULL))
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
typedef int (kiocb_cancel_fn)(struct kiocb *);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
struct kiocb {
|
|
|
|
struct file *ki_filp;
|
2024-09-09 08:57:42 +00:00
|
|
|
struct kioctx *ki_ctx; /* NULL for sync ops */
|
|
|
|
kiocb_cancel_fn *ki_cancel;
|
|
|
|
void *private;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
void __user *user;
|
|
|
|
struct task_struct *tsk;
|
|
|
|
} ki_obj;
|
|
|
|
|
|
|
|
__u64 ki_user_data; /* user's data for completion */
|
|
|
|
loff_t ki_pos;
|
2024-09-09 08:57:42 +00:00
|
|
|
size_t ki_nbytes; /* copy of iocb->aio_nbytes */
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
struct list_head ki_list; /* the aio core uses this
|
|
|
|
* for cancellation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the aio_resfd field of the userspace iocb is not zero,
|
|
|
|
* this is the underlying eventfd context to deliver events to.
|
|
|
|
*/
|
|
|
|
struct eventfd_ctx *ki_eventfd;
|
|
|
|
};
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline bool is_sync_kiocb(struct kiocb *kiocb)
|
|
|
|
{
|
|
|
|
return kiocb->ki_ctx == NULL;
|
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
|
|
|
|
{
|
|
|
|
*kiocb = (struct kiocb) {
|
|
|
|
.ki_ctx = NULL,
|
|
|
|
.ki_filp = filp,
|
|
|
|
.ki_obj.tsk = current,
|
|
|
|
};
|
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
#ifdef CONFIG_AIO
|
|
|
|
extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
|
2024-09-09 08:57:42 +00:00
|
|
|
extern void aio_complete(struct kiocb *iocb, long res, long res2);
|
2024-09-09 08:52:07 +00:00
|
|
|
struct mm_struct;
|
|
|
|
extern void exit_aio(struct mm_struct *mm);
|
|
|
|
extern long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user *__user *iocbpp, bool compat);
|
2024-09-09 08:57:42 +00:00
|
|
|
void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
|
2024-09-09 08:52:07 +00:00
|
|
|
#else
|
|
|
|
static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
|
2024-09-09 08:52:07 +00:00
|
|
|
struct mm_struct;
|
|
|
|
static inline void exit_aio(struct mm_struct *mm) { }
|
|
|
|
static inline long do_io_submit(aio_context_t ctx_id, long nr,
|
|
|
|
struct iocb __user * __user *iocbpp,
|
|
|
|
bool compat) { return 0; }
|
2024-09-09 08:57:42 +00:00
|
|
|
static inline void kiocb_set_cancel_fn(struct kiocb *req,
|
|
|
|
kiocb_cancel_fn *cancel) { }
|
2024-09-09 08:52:07 +00:00
|
|
|
#endif /* CONFIG_AIO */
|
|
|
|
|
|
|
|
static inline struct kiocb *list_kiocb(struct list_head *h)
|
|
|
|
{
|
|
|
|
return list_entry(h, struct kiocb, ki_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for sysctl: */
|
|
|
|
extern unsigned long aio_nr;
|
|
|
|
extern unsigned long aio_max_nr;
|
|
|
|
|
|
|
|
#endif /* __LINUX__AIO_H */
|