summaryrefslogtreecommitdiff
path: root/src/register.c
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/register.c
parentb4b3d8c97b2de68e2bbac5f5a37988677c44302a (diff)
Add basic helpers for file/buffer registration
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src/register.c')
-rw-r--r--src/register.c60
1 files changed, 60 insertions, 0 deletions
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;
+}