#include #include #include #include #include #include #include #include #include "liburing.h" #include "test.h" #define BUF_SIZE 4096 static char buf[BUF_SIZE]; static char buf_tmp[BUF_SIZE]; static void io_uring_prep_my_cmd_lease(struct io_uring_sqe *sqe) { io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, 0, 0, 0); /* TODO */ ... } static void do_submit_wait1(struct io_uring *ring) { struct io_uring_cqe *cqe; int ret; ret = io_uring_submit(ring); assert(ret == 1); ret = io_uring_wait_cqe(ring, &cqe); assert(ret >= 0); printf("cqe data %i res %i\n", (int)cqe->user_data, cqe->res); io_uring_cqe_seen(ring, cqe); } int main(int argc, char *argv[]) { unsigned long buf_offset = 0; unsigned slot = 0; /* reg buffer table index */ struct io_uring_sqe *sqe; int pipe1[2], pipe2[2]; struct io_uring ring; int ret, i; for (i = 0; i < BUF_SIZE; i++) buf[i] = (char)i; ret = pipe(pipe1); assert(ret == 0); ret = pipe(pipe2); assert(ret == 0); ret = io_uring_queue_init(8, &ring, 0); assert(ret == 0); ret = io_uring_register_buffers_sparse(&ring, 16); assert(ret >= 0); ret = write(pipe1[1], buf, BUF_SIZE); assert(ret == BUF_SIZE); sqe = io_uring_get_sqe(&ring); io_uring_prep_my_cmd_lease(sqe, bdev_fd, slot); sqe->user_data = 1; do_submit_wait1(&ring); // read data into the leased buffer sqe = io_uring_get_sqe(&ring); io_uring_prep_read_fixed(sqe, pipe1[0], (void *)buf_offset, BUF_SIZE, 0, slot); sqe->user_data = 2; do_submit_wait1(&ring); // write from the leased buffer into a pipe sqe = io_uring_get_sqe(&ring); io_uring_prep_write_fixed(sqe, pipe2[1], (void *)buf_offset, BUF_SIZE, 0, slot); sqe->user_data = 3; do_submit_wait1(&ring); // check the right data is in the pipe ret = read(pipe2[0], buf_tmp, BUF_SIZE); assert(ret == BUF_SIZE); for (i = 0; i < BUF_SIZE; i++) { assert(buf[i] == buf_tmp[i]); } struct iovec iovec = {}; ret = io_uring_register_buffers_update_tag(&ring, 0, &iovec, NULL, 1); assert(ret >= 0); io_uring_queue_exit(&ring); return 0; }