summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile2
-rw-r--r--src/liburing.h7
-rw-r--r--src/liburing.map4
-rw-r--r--src/register.c60
-rw-r--r--test/ring-leak.c4
5 files changed, 74 insertions, 3 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;
+}
diff --git a/test/ring-leak.c b/test/ring-leak.c
index d2fcba0..99466e4 100644
--- a/test/ring-leak.c
+++ b/test/ring-leak.c
@@ -23,7 +23,7 @@
#include "../src/liburing.h"
-static int io_uring_register_files(int ring_fd, int fd1, int fd2)
+static int __io_uring_register_files(int ring_fd, int fd1, int fd2)
{
__s32 fds[2] = { fd1, fd2 };
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
if (ring_fd < 0)
return 1;
- ret = io_uring_register_files(ring_fd, sp[0], sp[1]);
+ ret = __io_uring_register_files(ring_fd, sp[0], sp[1]);
if (ret < 0) {
perror("register files");
return 1;