summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-06-04 20:35:44 -0600
committerJens Axboe <axboe@kernel.dk>2019-06-04 20:35:44 -0600
commit9f44fb0e64e68c304d71c1cc21ddb1de7772c1c4 (patch)
treed77e6e9ec070f76b26d2766e6e8c6ff2e7ae82ac /src
parentb4b3d8c97b2de68e2bbac5f5a37988677c44302a (diff)
downloadliburing-9f44fb0e64e68c304d71c1cc21ddb1de7772c1c4.tar.gz
liburing-9f44fb0e64e68c304d71c1cc21ddb1de7772c1c4.tar.bz2
Add basic helpers for file/buffer registration
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/liburing.h7
-rw-r--r--src/liburing.map4
-rw-r--r--src/register.c60
4 files changed, 72 insertions, 1 deletions
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 <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#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;
+}