2019-01-08 06:51:07 -07:00
|
|
|
#ifndef LIB_URING_H
|
|
|
|
|
#define LIB_URING_H
|
|
|
|
|
|
|
|
|
|
#include <sys/uio.h>
|
2019-01-15 11:14:43 -07:00
|
|
|
#include "compat.h"
|
2019-01-08 06:51:07 -07:00
|
|
|
#include "io_uring.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Library interface to io_uring
|
|
|
|
|
*/
|
|
|
|
|
struct io_uring_sq {
|
|
|
|
|
unsigned *khead;
|
|
|
|
|
unsigned *ktail;
|
|
|
|
|
unsigned *kring_mask;
|
|
|
|
|
unsigned *kring_entries;
|
|
|
|
|
unsigned *kflags;
|
|
|
|
|
unsigned *kdropped;
|
|
|
|
|
unsigned *array;
|
2019-01-09 15:26:20 -07:00
|
|
|
struct io_uring_sqe *sqes;
|
2019-01-08 06:51:07 -07:00
|
|
|
|
2019-01-09 15:26:20 -07:00
|
|
|
unsigned sqe_head;
|
|
|
|
|
unsigned sqe_tail;
|
2019-01-08 06:51:07 -07:00
|
|
|
|
|
|
|
|
size_t ring_sz;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct io_uring_cq {
|
|
|
|
|
unsigned *khead;
|
|
|
|
|
unsigned *ktail;
|
|
|
|
|
unsigned *kring_mask;
|
|
|
|
|
unsigned *kring_entries;
|
|
|
|
|
unsigned *koverflow;
|
2019-01-09 15:26:20 -07:00
|
|
|
struct io_uring_cqe *cqes;
|
2019-01-08 06:51:07 -07:00
|
|
|
|
|
|
|
|
size_t ring_sz;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-08 15:31:35 -07:00
|
|
|
struct io_uring {
|
|
|
|
|
struct io_uring_sq sq;
|
|
|
|
|
struct io_uring_cq cq;
|
2019-01-08 15:59:09 -07:00
|
|
|
int ring_fd;
|
2019-01-08 15:31:35 -07:00
|
|
|
};
|
|
|
|
|
|
2019-01-08 06:51:07 -07:00
|
|
|
/*
|
|
|
|
|
* System calls
|
|
|
|
|
*/
|
2019-01-10 14:28:10 -07:00
|
|
|
extern int io_uring_setup(unsigned entries, struct io_uring_params *p);
|
2019-01-08 06:51:07 -07:00
|
|
|
extern int io_uring_enter(unsigned fd, unsigned to_submit,
|
|
|
|
|
unsigned min_complete, unsigned flags);
|
2019-01-10 14:28:10 -07:00
|
|
|
extern int io_uring_register(int fd, unsigned int opcode, void *arg);
|
2019-01-08 06:51:07 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Library interface
|
|
|
|
|
*/
|
2019-01-10 15:11:07 -07:00
|
|
|
extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
|
|
|
|
|
unsigned flags);
|
2019-01-08 15:59:09 -07:00
|
|
|
extern void io_uring_queue_exit(struct io_uring *ring);
|
|
|
|
|
extern int io_uring_get_completion(struct io_uring *ring,
|
2019-01-09 15:26:20 -07:00
|
|
|
struct io_uring_cqe **cqe_ptr);
|
2019-01-08 15:59:09 -07:00
|
|
|
extern int io_uring_wait_completion(struct io_uring *ring,
|
2019-01-09 15:26:20 -07:00
|
|
|
struct io_uring_cqe **cqe_ptr);
|
2019-01-08 15:59:09 -07:00
|
|
|
extern int io_uring_submit(struct io_uring *ring);
|
2019-01-09 15:26:20 -07:00
|
|
|
extern struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
|
2019-01-08 06:51:07 -07:00
|
|
|
|
2019-01-17 18:12:22 -07:00
|
|
|
/*
|
|
|
|
|
* Command prep helpers
|
|
|
|
|
*/
|
|
|
|
|
static inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data)
|
|
|
|
|
{
|
|
|
|
|
sqe->user_data = (unsigned long) data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void io_uring_prep_readv(struct io_uring_sqe *sqe, int fd,
|
|
|
|
|
struct iovec *iovecs, unsigned nr_vecs,
|
|
|
|
|
off_t offset)
|
|
|
|
|
{
|
|
|
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
|
|
|
sqe->opcode = IORING_OP_READV;
|
|
|
|
|
sqe->fd = fd;
|
|
|
|
|
sqe->off = offset;
|
|
|
|
|
sqe->addr = (unsigned long) iovecs;
|
2019-01-17 21:33:39 -07:00
|
|
|
sqe->len = nr_vecs;
|
2019-01-17 18:12:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,
|
|
|
|
|
struct iovec *iovecs, unsigned nr_vecs,
|
|
|
|
|
off_t offset)
|
|
|
|
|
{
|
|
|
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
|
|
|
sqe->opcode = IORING_OP_WRITEV;
|
|
|
|
|
sqe->fd = fd;
|
|
|
|
|
sqe->off = offset;
|
|
|
|
|
sqe->addr = (unsigned long) iovecs;
|
2019-01-17 21:33:39 -07:00
|
|
|
sqe->len = nr_vecs;
|
2019-01-17 18:12:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void io_uring_prep_poll(struct io_uring_sqe *sqe, int fd,
|
|
|
|
|
short poll_mask)
|
|
|
|
|
{
|
|
|
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
|
|
|
sqe->opcode = IORING_OP_POLL;
|
|
|
|
|
sqe->fd = fd;
|
|
|
|
|
sqe->poll_events = poll_mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void io_uring_prep_poll_cancel(struct io_uring_sqe *sqe,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
|
|
|
sqe->opcode = IORING_OP_POLL_CANCEL;
|
|
|
|
|
sqe->addr = (unsigned long) user_data;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 06:51:07 -07:00
|
|
|
#endif
|