Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@xxxxxxxxxx> --- src/include/liburing.h | 12 ++++++++++++ src/include/liburing/io_uring.h | 10 ++++++++-- src/register.c | 27 ++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/include/liburing.h b/src/include/liburing.h index ebfc424..9648f8c 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -114,6 +114,9 @@ extern int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs, unsigned nr_iovecs); extern int io_uring_unregister_buffers(struct io_uring *ring); +extern int io_uring_register_buffers_update(struct io_uring *ring, unsigned off, + struct iovec *iovecs, + unsigned nr_iovecs); extern int io_uring_register_files(struct io_uring *ring, const int *files, unsigned nr_files); extern int io_uring_unregister_files(struct io_uring *ring); @@ -373,6 +376,15 @@ static inline void io_uring_prep_files_update(struct io_uring_sqe *sqe, io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, fds, nr_fds, offset); } +static inline void io_uring_prep_buffers_update(struct io_uring_sqe *sqe, + struct iovec *iovs, + unsigned nr_iovs, + int offset) +{ + io_uring_prep_rw(IORING_OP_BUFFERS_UPDATE, sqe, -1, iovs, nr_iovs, + offset); +} + static inline void io_uring_prep_fallocate(struct io_uring_sqe *sqe, int fd, int mode, off_t offset, off_t len) { diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 0bb55b0..4e61817 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -141,6 +141,7 @@ enum { IORING_OP_SHUTDOWN, IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, + IORING_OP_BUFFERS_UPDATE, /* this goes last, obviously */ IORING_OP_LAST, @@ -284,15 +285,20 @@ enum { IORING_UNREGISTER_PERSONALITY = 10, IORING_REGISTER_RESTRICTIONS = 11, IORING_REGISTER_ENABLE_RINGS = 12, + IORING_REGISTER_BUFFERS_UPDATE = 13, /* this goes last */ IORING_REGISTER_LAST }; -struct io_uring_files_update { +struct io_uring_rsrc_update { __u32 offset; __u32 resv; - __aligned_u64 /* __s32 * */ fds; + union { + __aligned_u64 /* __s32 * */ fds; + __aligned_u64 /* __s32 * */ iovs; + __aligned_u64 /* __s32 * */ rsrc; + }; }; #define IO_URING_OP_SUPPORTED (1U << 0) diff --git a/src/register.c b/src/register.c index 994aaff..80292d9 100644 --- a/src/register.c +++ b/src/register.c @@ -14,6 +14,31 @@ #include "syscall.h" +/* + * Register an update for an existing buffer set. The updates will start at + * 'off' in the original array, and 'nr_iovecs' is the number of buffers we'll + * update. + * + * Returns number of files updated on success, -ERROR on failure. + */ +int io_uring_register_buffers_update(struct io_uring *ring, unsigned off, + struct iovec *iovecs, unsigned nr_iovecs) +{ + struct io_uring_rsrc_update up = { + .offset = off, + .iovs = (unsigned long) iovecs, + }; + int ret; + + ret = __sys_io_uring_register(ring->ring_fd, + IORING_REGISTER_BUFFERS_UPDATE, &up, + nr_iovecs); + if (ret < 0) + return -errno; + + return ret; +} + int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs, unsigned nr_iovecs) { @@ -49,7 +74,7 @@ int io_uring_unregister_buffers(struct io_uring *ring) int io_uring_register_files_update(struct io_uring *ring, unsigned off, int *files, unsigned nr_files) { - struct io_uring_files_update up = { + struct io_uring_rsrc_update up = { .offset = off, .fds = (unsigned long) files, }; -- 1.8.3.1