Add helpers for notification registration and preparing zerocopy send requests. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- src/include/liburing.h | 41 +++++++++++++++++++++++++++++++++++++++++ src/liburing.map | 2 ++ src/register.c | 20 ++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/include/liburing.h b/src/include/liburing.h index fc7613d..f3c5887 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -189,6 +189,10 @@ int io_uring_register_sync_cancel(struct io_uring *ring, int io_uring_register_file_alloc_range(struct io_uring *ring, unsigned off, unsigned len); +int io_uring_register_notifications(struct io_uring *ring, unsigned nr, + struct io_uring_notification_slot *slots); +int io_uring_unregister_notifications(struct io_uring *ring); + /* * Helper for the peek/wait single cqe functions. Exported because of that, * but probably shouldn't be used directly in an application. @@ -677,6 +681,43 @@ static inline void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd, sqe->msg_flags = (__u32) flags; } +static inline void io_uring_prep_sendzc(struct io_uring_sqe *sqe, int sockfd, + const void *buf, size_t len, int flags, + unsigned slot_idx, unsigned zc_flags) +{ + io_uring_prep_rw(IORING_OP_SENDZC_NOTIF, sqe, sockfd, buf, (__u32) len, 0); + sqe->msg_flags = (__u32) flags; + sqe->notification_idx = slot_idx; + sqe->ioprio = zc_flags; +} + +static inline void io_uring_prep_sendzc_fixed(struct io_uring_sqe *sqe, int sockfd, + const void *buf, size_t len, + int flags, unsigned slot_idx, + unsigned zc_flags, unsigned buf_idx) +{ + io_uring_prep_sendzc(sqe, sockfd, buf, len, flags, slot_idx, zc_flags); + sqe->ioprio |= IORING_RECVSEND_FIXED_BUF; + sqe->buf_index = buf_idx; +} + +static inline void io_uring_prep_sendzc_set_addr(struct io_uring_sqe *sqe, + const struct sockaddr *dest_addr, + __u16 addr_len) +{ + sqe->addr2 = (unsigned long)(void *)dest_addr; + sqe->addr_len = addr_len; +} + +static inline void io_uring_prep_notif_update(struct io_uring_sqe *sqe, + __u64 new_tag, /* 0 to ignore */ + unsigned offset, unsigned nr) +{ + io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr, + (__u64)offset); + sqe->ioprio = IORING_RSRC_UPDATE_NOTIF; +} + static inline void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd, void *buf, size_t len, int flags) { diff --git a/src/liburing.map b/src/liburing.map index 318d3d7..7d8f143 100644 --- a/src/liburing.map +++ b/src/liburing.map @@ -60,4 +60,6 @@ LIBURING_2.3 { global: io_uring_register_sync_cancel; io_uring_register_file_alloc_range; + io_uring_register_notifications; + io_uring_unregister_notifications; } LIBURING_2.2; diff --git a/src/register.c b/src/register.c index 2b37e5f..7482112 100644 --- a/src/register.c +++ b/src/register.c @@ -364,3 +364,23 @@ int io_uring_register_file_alloc_range(struct io_uring *ring, IORING_REGISTER_FILE_ALLOC_RANGE, &range, 0); } + +int io_uring_register_notifications(struct io_uring *ring, unsigned nr, + struct io_uring_notification_slot *slots) +{ + struct io_uring_notification_register r = { + .nr_slots = nr, + .data = (unsigned long)slots, + }; + + return __sys_io_uring_register(ring->ring_fd, + IORING_REGISTER_NOTIFIERS, + &r, sizeof(r)); +} + +int io_uring_unregister_notifications(struct io_uring *ring) +{ + return __sys_io_uring_register(ring->ring_fd, + IORING_UNREGISTER_NOTIFIERS, + NULL, 0); +} -- 2.37.0