From 9f44fb0e64e68c304d71c1cc21ddb1de7772c1c4 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 4 Jun 2019 20:35:44 -0600 Subject: Add basic helpers for file/buffer registration Signed-off-by: Jens Axboe --- src/Makefile | 2 +- src/liburing.h | 7 +++++++ src/liburing.map | 4 ++++ src/register.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/register.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 02abc3a..b68b57e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -22,7 +22,7 @@ endif all: $(all_targets) -liburing_srcs := setup.c queue.c syscall.c +liburing_srcs := setup.c queue.c syscall.c register.c liburing_objs := $(patsubst %.c,%.ol,$(liburing_srcs)) liburing_sobjs := $(patsubst %.c,%.os,$(liburing_srcs)) diff --git a/src/liburing.h b/src/liburing.h index db9758d..d7aec73 100644 --- a/src/liburing.h +++ b/src/liburing.h @@ -76,6 +76,13 @@ extern int io_uring_wait_cqe(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); +extern int io_uring_register_buffers(struct io_uring *ring, struct iovec *iovecs, + unsigned nr_iovecs); +extern int io_uring_unregister_buffers(struct io_uring *ring); +extern int io_uring_register_files(struct io_uring *ring, __s32 *files, + unsigned nr_files); +extern int io_uring_unregister_files(struct io_uring *ring); + #define io_uring_for_each_cqe(ring, head, cqe) \ for (head = *(ring)->cq.khead; \ /* See read_barrier() explanation in __io_uring_get_cqe() */ \ diff --git a/src/liburing.map b/src/liburing.map index 39b0ca8..d940da2 100644 --- a/src/liburing.map +++ b/src/liburing.map @@ -11,6 +11,10 @@ LIBURING_0.1 { io_uring_setup; io_uring_enter; io_uring_mmap; + io_uring_register_buffers; + io_uring_unregister_buffers; + io_uring_register_files; + io_uring_unregister_files; local: *; diff --git a/src/register.c b/src/register.c new file mode 100644 index 0000000..e352291 --- /dev/null +++ b/src/register.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +#include "compat.h" +#include "io_uring.h" +#include "liburing.h" + +int io_uring_register_buffers(struct io_uring *ring, struct iovec *iovecs, + unsigned nr_iovecs) +{ + int ret; + + ret = io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS, + iovecs, nr_iovecs); + if (ret < 0) + return -errno; + + return 0; +} + +int io_uring_unregister_buffers(struct io_uring *ring) +{ + int ret; + + ret = io_uring_register(ring->ring_fd, IORING_UNREGISTER_BUFFERS, NULL, + 0); + if (ret < 0) + return -errno; + + return 0; +} + +int io_uring_register_files(struct io_uring *ring, __s32 *files, + unsigned nr_files) +{ + int ret; + + ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES, files, + nr_files); + if (ret < 0) + return -errno; + + return 0; +} + +int io_uring_unregister_files(struct io_uring *ring) +{ + int ret; + + ret = io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES, NULL, + 0); + if (ret < 0) + return -errno; + + return 0; +} -- cgit