summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-01-17 18:12:22 -0700
committerJens Axboe <axboe@kernel.dk>2019-01-17 18:12:22 -0700
commit5789a6351a2ae69e810fca79b9e9b68797169e17 (patch)
tree7749af6aa692ead29f20a20ef2a9dfef71834ac9 /src
parent980cc0f0256f18eb3a6e53e394251cb18fc7d218 (diff)
Add sqe prep helpers
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src')
-rw-r--r--src/liburing.h49
1 files changed, 49 insertions, 0 deletions
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