diff options
author | Jens Axboe <axboe@kernel.dk> | 2022-03-04 08:03:20 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2022-03-08 06:02:46 -0700 |
commit | bbcc0e06b47a2aab828e57e67cd3d592293097fb (patch) | |
tree | 865baed5f746156e440de03832767d70fb0593ae | |
parent | b02125e164ea2604efbf443224fe5679ef0047c1 (diff) | |
download | liburing-bbcc0e06b47a2aab828e57e67cd3d592293097fb.tar.gz liburing-bbcc0e06b47a2aab828e57e67cd3d592293097fb.tar.bz2 |
Add ring fd registration helpers
These just handle registering the ring itself, while the kernel API
does allow registering multiple ring fds at the same time.Add ring fd registration helpers
These just handle registering the ring itself, while the kernel API
does allow registering multiple ring fds at the same time.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | src/include/liburing.h | 2 | ||||
-rw-r--r-- | src/register.c | 34 | ||||
-rw-r--r-- | src/setup.c | 7 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h index 0799a50..88418dc 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -170,6 +170,8 @@ int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz, int io_uring_unregister_iowq_aff(struct io_uring *ring); int io_uring_register_iowq_max_workers(struct io_uring *ring, unsigned int *values); +int io_uring_register_ring_fd(struct io_uring *ring); +int io_uring_unregister_ring_fd(struct io_uring *ring); /* * Helper for the peek/wait single cqe functions. Exported because of that, diff --git a/src/register.c b/src/register.c index cd73fce..1b96c77 100644 --- a/src/register.c +++ b/src/register.c @@ -4,6 +4,7 @@ #include "lib.h" #include "syscall.h" #include "liburing.h" +#include "int_flags.h" #include "liburing/compat.h" #include "liburing/io_uring.h" @@ -257,3 +258,36 @@ int io_uring_register_iowq_max_workers(struct io_uring *ring, unsigned int *val) IORING_REGISTER_IOWQ_MAX_WORKERS, val, 2); } + +int io_uring_register_ring_fd(struct io_uring *ring) +{ + struct io_uring_rsrc_update up = { + .data = ring->ring_fd, + .offset = -1U, + }; + int ret; + + ret = ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_RING_FDS, + &up, 1); + if (ret == 1) { + ring->enter_ring_fd = up.offset; + ring->int_flags |= INT_FLAG_REG_RING; + } + return ret; +} + +int io_uring_unregister_ring_fd(struct io_uring *ring) +{ + struct io_uring_rsrc_update up = { + .offset = ring->enter_ring_fd, + }; + int ret; + + ret = ____sys_io_uring_register(ring->ring_fd, + IORING_UNREGISTER_RING_FDS, &up, 1); + if (ret == 1) { + ring->enter_ring_fd = ring->ring_fd; + ring->int_flags &= ~INT_FLAG_REG_RING; + } + return ret; +} diff --git a/src/setup.c b/src/setup.c index 12a1cd5..5529784 100644 --- a/src/setup.c +++ b/src/setup.c @@ -4,6 +4,7 @@ #include "lib.h" #include "syscall.h" #include "liburing.h" +#include "int_flags.h" #include "liburing/compat.h" #include "liburing/io_uring.h" @@ -169,6 +170,12 @@ void io_uring_queue_exit(struct io_uring *ring) __sys_munmap(sq->sqes, *sq->kring_entries * sizeof(struct io_uring_sqe)); io_uring_unmap_rings(sq, cq); + /* + * Not strictly required, but frees up the slot we used now rather + * than at process exit time. + */ + if (ring->int_flags & INT_FLAG_REG_RING) + io_uring_unregister_ring_fd(ring); __sys_close(ring->ring_fd); } |