From 5789a6351a2ae69e810fca79b9e9b68797169e17 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 17 Jan 2019 18:12:22 -0700 Subject: Add sqe prep helpers Signed-off-by: Jens Axboe --- src/liburing.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/liburing.h') diff --git a/src/liburing.h b/src/liburing.h index 038dd15..4a8c55f 100644 --- a/src/liburing.h +++ b/src/liburing.h @@ -62,4 +62,53 @@ extern int io_uring_wait_completion(struct io_uring *ring, extern int io_uring_submit(struct io_uring *ring); extern struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring); +/* + * 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; + sqe->len = 1; +} + +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; + sqe->len = 1; +} + +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; +} + #endif -- cgit