aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/src
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2023-07-26 17:26:21 +0300
committerthegeorg <thegeorg@yandex-team.com>2023-07-26 17:26:21 +0300
commit3785d5f97965bccf048718d8717904cf50f9f8f9 (patch)
treeb7ce8ae67d7eb7fcf7767c54379f0564c281147f /contrib/libs/liburing/src
parent1f6b57071583f89299bb5abd3863d594f23c5be5 (diff)
downloadydb-3785d5f97965bccf048718d8717904cf50f9f8f9.tar.gz
Update contrib/libs/liburing to 2.4
Diffstat (limited to 'contrib/libs/liburing/src')
-rw-r--r--contrib/libs/liburing/src/arch/aarch64/lib.h2
-rw-r--r--contrib/libs/liburing/src/include/liburing.h407
-rw-r--r--contrib/libs/liburing/src/include/liburing/compat.h2
-rw-r--r--contrib/libs/liburing/src/include/liburing/io_uring.h70
-rw-r--r--contrib/libs/liburing/src/include/liburing/io_uring_version.h8
-rw-r--r--contrib/libs/liburing/src/int_flags.h1
-rw-r--r--contrib/libs/liburing/src/lib.h21
-rw-r--r--contrib/libs/liburing/src/nolibc.c56
-rw-r--r--contrib/libs/liburing/src/queue.c4
-rw-r--r--contrib/libs/liburing/src/register.c161
-rw-r--r--contrib/libs/liburing/src/setup.c114
-rw-r--r--contrib/libs/liburing/src/version.c22
12 files changed, 568 insertions, 300 deletions
diff --git a/contrib/libs/liburing/src/arch/aarch64/lib.h b/contrib/libs/liburing/src/arch/aarch64/lib.h
index 5a75c1a6723..3b701b1fb77 100644
--- a/contrib/libs/liburing/src/arch/aarch64/lib.h
+++ b/contrib/libs/liburing/src/arch/aarch64/lib.h
@@ -21,7 +21,7 @@ static inline long __get_page_size(void)
ssize_t x;
x = __sys_read(fd, buf, sizeof(buf));
- if (x < sizeof(buf))
+ if (x < (long) sizeof(buf))
break;
if (buf[0] == AT_PAGESZ) {
diff --git a/contrib/libs/liburing/src/include/liburing.h b/contrib/libs/liburing/src/include/liburing.h
index 12a703fdd2e..e6dc9a792f0 100644
--- a/contrib/libs/liburing/src/include/liburing.h
+++ b/contrib/libs/liburing/src/include/liburing.h
@@ -23,6 +23,7 @@
#include <linux/swab.h>
#include "liburing/compat.h"
#include "liburing/io_uring.h"
+#include "liburing/io_uring_version.h"
#include "liburing/barrier.h"
#ifndef uring_unlikely
@@ -33,6 +34,10 @@
#define uring_likely(cond) __builtin_expect(!!(cond), 1)
#endif
+#ifndef IOURINGINLINE
+#define IOURINGINLINE static inline
+#endif
+
#ifdef __alpha__
/*
* alpha and mips are the exceptions, all other architectures have
@@ -151,7 +156,7 @@ struct io_uring_probe *io_uring_get_probe(void);
*/
void io_uring_free_probe(struct io_uring_probe *probe);
-static inline int io_uring_opcode_supported(const struct io_uring_probe *p,
+IOURINGINLINE int io_uring_opcode_supported(const struct io_uring_probe *p,
int op)
{
if (op > p->last_op)
@@ -226,6 +231,7 @@ 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);
+int io_uring_close_ring_fd(struct io_uring *ring);
int io_uring_register_buf_ring(struct io_uring *ring,
struct io_uring_buf_reg *reg, unsigned int flags);
int io_uring_unregister_buf_ring(struct io_uring *ring, int bgid);
@@ -251,6 +257,16 @@ int io_uring_register(unsigned int fd, unsigned int opcode, const void *arg,
unsigned int nr_args);
/*
+ * Mapped buffer ring alloc/register + unregister/free helpers
+ */
+struct io_uring_buf_ring *io_uring_setup_buf_ring(struct io_uring *ring,
+ unsigned int nentries,
+ int bgid, unsigned int flags,
+ int *ret);
+int io_uring_free_buf_ring(struct io_uring *ring, struct io_uring_buf_ring *br,
+ unsigned int nentries, int bgid);
+
+/*
* Helper for the peek/wait single cqe functions. Exported because of that,
* but probably shouldn't be used directly in an application.
*/
@@ -283,8 +299,7 @@ int __io_uring_get_cqe(struct io_uring *ring,
/*
* Must be called after io_uring_for_each_cqe()
*/
-static inline void io_uring_cq_advance(struct io_uring *ring,
- unsigned nr)
+IOURINGINLINE void io_uring_cq_advance(struct io_uring *ring, unsigned nr)
{
if (nr) {
struct io_uring_cq *cq = &ring->cq;
@@ -301,7 +316,7 @@ static inline void io_uring_cq_advance(struct io_uring *ring,
* Must be called after io_uring_{peek,wait}_cqe() after the cqe has
* been processed by the application.
*/
-static inline void io_uring_cqe_seen(struct io_uring *ring,
+IOURINGINLINE void io_uring_cqe_seen(struct io_uring *ring,
struct io_uring_cqe *cqe)
{
if (cqe)
@@ -316,12 +331,12 @@ static inline void io_uring_cqe_seen(struct io_uring *ring,
* Associate pointer @data with the sqe, for later retrieval from the cqe
* at command completion time with io_uring_cqe_get_data().
*/
-static inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data)
+IOURINGINLINE void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data)
{
sqe->user_data = (unsigned long) data;
}
-static inline void *io_uring_cqe_get_data(const struct io_uring_cqe *cqe)
+IOURINGINLINE void *io_uring_cqe_get_data(const struct io_uring_cqe *cqe)
{
return (void *) (uintptr_t) cqe->user_data;
}
@@ -331,13 +346,13 @@ static inline void *io_uring_cqe_get_data(const struct io_uring_cqe *cqe)
* time with io_uring_cqe_get_data64. Just like the non-64 variants, except
* these store a 64-bit type rather than a data pointer.
*/
-static inline void io_uring_sqe_set_data64(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_sqe_set_data64(struct io_uring_sqe *sqe,
__u64 data)
{
sqe->user_data = data;
}
-static inline __u64 io_uring_cqe_get_data64(const struct io_uring_cqe *cqe)
+IOURINGINLINE __u64 io_uring_cqe_get_data64(const struct io_uring_cqe *cqe)
{
return cqe->user_data;
}
@@ -347,20 +362,20 @@ static inline __u64 io_uring_cqe_get_data64(const struct io_uring_cqe *cqe)
*/
#define LIBURING_HAVE_DATA64
-static inline void io_uring_sqe_set_flags(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_sqe_set_flags(struct io_uring_sqe *sqe,
unsigned flags)
{
sqe->flags = (__u8) flags;
}
-static inline void __io_uring_set_target_fixed_file(struct io_uring_sqe *sqe,
+IOURINGINLINE void __io_uring_set_target_fixed_file(struct io_uring_sqe *sqe,
unsigned int file_index)
{
/* 0 means no fixed files, indexes should be encoded as "index + 1" */
sqe->file_index = file_index + 1;
}
-static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd,
const void *addr, unsigned len,
__u64 offset)
{
@@ -379,29 +394,28 @@ static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd,
sqe->__pad2[0] = 0;
}
-/**
- * @pre Either fd_in or fd_out must be a pipe.
- * @param off_in If fd_in refers to a pipe, off_in must be (int64_t) -1;
- * If fd_in does not refer to a pipe and off_in is (int64_t) -1,
- * then bytes are read from fd_in starting from the file offset
- * and it is adjust appropriately;
- * If fd_in does not refer to a pipe and off_in is not
- * (int64_t) -1, then the starting offset of fd_in will be
- * off_in.
- * @param off_out The description of off_in also applied to off_out.
- * @param splice_flags see man splice(2) for description of flags.
+/*
+ * io_uring_prep_splice() - Either @fd_in or @fd_out must be a pipe.
+ *
+ * - If @fd_in refers to a pipe, @off_in is ignored and must be set to -1.
+ *
+ * - If @fd_in does not refer to a pipe and @off_in is -1, then @nbytes are read
+ * from @fd_in starting from the file offset, which is incremented by the
+ * number of bytes read.
+ *
+ * - If @fd_in does not refer to a pipe and @off_in is not -1, then the starting
+ * offset of @fd_in will be @off_in.
*
* This splice operation can be used to implement sendfile by splicing to an
* intermediate pipe first, then splice to the final destination.
* In fact, the implementation of sendfile in kernel uses splice internally.
*
* NOTE that even if fd_in or fd_out refers to a pipe, the splice operation
- * can still failed with EINVAL if one of the fd doesn't explicitly support
- * splice operation, e.g. reading from terminal is unsupported from kernel 5.7
- * to 5.11.
+ * can still fail with EINVAL if one of the fd doesn't explicitly support splice
+ * operation, e.g. reading from terminal is unsupported from kernel 5.7 to 5.11.
* Check issue #291 for more information.
*/
-static inline void io_uring_prep_splice(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_splice(struct io_uring_sqe *sqe,
int fd_in, int64_t off_in,
int fd_out, int64_t off_out,
unsigned int nbytes,
@@ -414,7 +428,7 @@ static inline void io_uring_prep_splice(struct io_uring_sqe *sqe,
sqe->splice_flags = splice_flags;
}
-static inline void io_uring_prep_tee(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_tee(struct io_uring_sqe *sqe,
int fd_in, int fd_out,
unsigned int nbytes,
unsigned int splice_flags)
@@ -425,14 +439,14 @@ static inline void io_uring_prep_tee(struct io_uring_sqe *sqe,
sqe->splice_flags = splice_flags;
}
-static inline void io_uring_prep_readv(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_readv(struct io_uring_sqe *sqe, int fd,
const struct iovec *iovecs,
unsigned nr_vecs, __u64 offset)
{
io_uring_prep_rw(IORING_OP_READV, sqe, fd, iovecs, nr_vecs, offset);
}
-static inline void io_uring_prep_readv2(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_readv2(struct io_uring_sqe *sqe, int fd,
const struct iovec *iovecs,
unsigned nr_vecs, __u64 offset,
int flags)
@@ -441,7 +455,7 @@ static inline void io_uring_prep_readv2(struct io_uring_sqe *sqe, int fd,
sqe->rw_flags = flags;
}
-static inline void io_uring_prep_read_fixed(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_read_fixed(struct io_uring_sqe *sqe, int fd,
void *buf, unsigned nbytes,
__u64 offset, int buf_index)
{
@@ -449,14 +463,14 @@ static inline void io_uring_prep_read_fixed(struct io_uring_sqe *sqe, int fd,
sqe->buf_index = (__u16) buf_index;
}
-static inline void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,
const struct iovec *iovecs,
unsigned nr_vecs, __u64 offset)
{
io_uring_prep_rw(IORING_OP_WRITEV, sqe, fd, iovecs, nr_vecs, offset);
}
-static inline void io_uring_prep_writev2(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_writev2(struct io_uring_sqe *sqe, int fd,
const struct iovec *iovecs,
unsigned nr_vecs, __u64 offset,
int flags)
@@ -465,7 +479,7 @@ static inline void io_uring_prep_writev2(struct io_uring_sqe *sqe, int fd,
sqe->rw_flags = flags;
}
-static inline void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd,
const void *buf, unsigned nbytes,
__u64 offset, int buf_index)
{
@@ -473,21 +487,22 @@ static inline void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd,
sqe->buf_index = (__u16) buf_index;
}
-static inline void io_uring_prep_recvmsg(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_recvmsg(struct io_uring_sqe *sqe, int fd,
struct msghdr *msg, unsigned flags)
{
io_uring_prep_rw(IORING_OP_RECVMSG, sqe, fd, msg, 1, 0);
sqe->msg_flags = flags;
}
-static inline void io_uring_prep_recvmsg_multishot(struct io_uring_sqe *sqe, int fd,
- struct msghdr *msg, unsigned flags)
+IOURINGINLINE void io_uring_prep_recvmsg_multishot(struct io_uring_sqe *sqe,
+ int fd, struct msghdr *msg,
+ unsigned flags)
{
io_uring_prep_recvmsg(sqe, fd, msg, flags);
sqe->ioprio |= IORING_RECV_MULTISHOT;
}
-static inline void io_uring_prep_sendmsg(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_sendmsg(struct io_uring_sqe *sqe, int fd,
const struct msghdr *msg,
unsigned flags)
{
@@ -495,7 +510,7 @@ static inline void io_uring_prep_sendmsg(struct io_uring_sqe *sqe, int fd,
sqe->msg_flags = flags;
}
-static inline unsigned __io_uring_prep_poll_mask(unsigned poll_mask)
+IOURINGINLINE unsigned __io_uring_prep_poll_mask(unsigned poll_mask)
{
#if __BYTE_ORDER == __BIG_ENDIAN
poll_mask = __swahw32(poll_mask);
@@ -503,28 +518,28 @@ static inline unsigned __io_uring_prep_poll_mask(unsigned poll_mask)
return poll_mask;
}
-static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
unsigned poll_mask)
{
io_uring_prep_rw(IORING_OP_POLL_ADD, sqe, fd, NULL, 0, 0);
sqe->poll32_events = __io_uring_prep_poll_mask(poll_mask);
}
-static inline void io_uring_prep_poll_multishot(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_poll_multishot(struct io_uring_sqe *sqe,
int fd, unsigned poll_mask)
{
io_uring_prep_poll_add(sqe, fd, poll_mask);
sqe->len = IORING_POLL_ADD_MULTI;
}
-static inline void io_uring_prep_poll_remove(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_poll_remove(struct io_uring_sqe *sqe,
__u64 user_data)
{
io_uring_prep_rw(IORING_OP_POLL_REMOVE, sqe, -1, NULL, 0, 0);
sqe->addr = user_data;
}
-static inline void io_uring_prep_poll_update(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_poll_update(struct io_uring_sqe *sqe,
__u64 old_user_data,
__u64 new_user_data,
unsigned poll_mask, unsigned flags)
@@ -535,19 +550,19 @@ static inline void io_uring_prep_poll_update(struct io_uring_sqe *sqe,
sqe->poll32_events = __io_uring_prep_poll_mask(poll_mask);
}
-static inline void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
unsigned fsync_flags)
{
io_uring_prep_rw(IORING_OP_FSYNC, sqe, fd, NULL, 0, 0);
sqe->fsync_flags = fsync_flags;
}
-static inline void io_uring_prep_nop(struct io_uring_sqe *sqe)
+IOURINGINLINE void io_uring_prep_nop(struct io_uring_sqe *sqe)
{
io_uring_prep_rw(IORING_OP_NOP, sqe, -1, NULL, 0, 0);
}
-static inline void io_uring_prep_timeout(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_timeout(struct io_uring_sqe *sqe,
struct __kernel_timespec *ts,
unsigned count, unsigned flags)
{
@@ -555,7 +570,7 @@ static inline void io_uring_prep_timeout(struct io_uring_sqe *sqe,
sqe->timeout_flags = flags;
}
-static inline void io_uring_prep_timeout_remove(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_timeout_remove(struct io_uring_sqe *sqe,
__u64 user_data, unsigned flags)
{
io_uring_prep_rw(IORING_OP_TIMEOUT_REMOVE, sqe, -1, NULL, 0, 0);
@@ -563,7 +578,7 @@ static inline void io_uring_prep_timeout_remove(struct io_uring_sqe *sqe,
sqe->timeout_flags = flags;
}
-static inline void io_uring_prep_timeout_update(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_timeout_update(struct io_uring_sqe *sqe,
struct __kernel_timespec *ts,
__u64 user_data, unsigned flags)
{
@@ -573,7 +588,7 @@ static inline void io_uring_prep_timeout_update(struct io_uring_sqe *sqe,
sqe->timeout_flags = flags | IORING_TIMEOUT_UPDATE;
}
-static inline void io_uring_prep_accept(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_accept(struct io_uring_sqe *sqe, int fd,
struct sockaddr *addr,
socklen_t *addrlen, int flags)
{
@@ -583,16 +598,19 @@ static inline void io_uring_prep_accept(struct io_uring_sqe *sqe, int fd,
}
/* accept directly into the fixed file table */
-static inline void io_uring_prep_accept_direct(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_accept_direct(struct io_uring_sqe *sqe, int fd,
struct sockaddr *addr,
socklen_t *addrlen, int flags,
unsigned int file_index)
{
io_uring_prep_accept(sqe, fd, addr, addrlen, flags);
+ /* offset by 1 for allocation */
+ if (file_index == IORING_FILE_INDEX_ALLOC)
+ file_index--;
__io_uring_set_target_fixed_file(sqe, file_index);
}
-static inline void io_uring_prep_multishot_accept(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_multishot_accept(struct io_uring_sqe *sqe,
int fd, struct sockaddr *addr,
socklen_t *addrlen, int flags)
{
@@ -601,7 +619,7 @@ static inline void io_uring_prep_multishot_accept(struct io_uring_sqe *sqe,
}
/* multishot accept directly into the fixed file table */
-static inline void io_uring_prep_multishot_accept_direct(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_multishot_accept_direct(struct io_uring_sqe *sqe,
int fd,
struct sockaddr *addr,
socklen_t *addrlen,
@@ -611,7 +629,7 @@ static inline void io_uring_prep_multishot_accept_direct(struct io_uring_sqe *sq
__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC - 1);
}
-static inline void io_uring_prep_cancel64(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_cancel64(struct io_uring_sqe *sqe,
__u64 user_data, int flags)
{
io_uring_prep_rw(IORING_OP_ASYNC_CANCEL, sqe, -1, NULL, 0, 0);
@@ -619,20 +637,20 @@ static inline void io_uring_prep_cancel64(struct io_uring_sqe *sqe,
sqe->cancel_flags = (__u32) flags;
}
-static inline void io_uring_prep_cancel(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_cancel(struct io_uring_sqe *sqe,
void *user_data, int flags)
{
io_uring_prep_cancel64(sqe, (__u64) (uintptr_t) user_data, flags);
}
-static inline void io_uring_prep_cancel_fd(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_cancel_fd(struct io_uring_sqe *sqe, int fd,
unsigned int flags)
{
io_uring_prep_rw(IORING_OP_ASYNC_CANCEL, sqe, fd, NULL, 0, 0);
sqe->cancel_flags = (__u32) flags | IORING_ASYNC_CANCEL_FD;
}
-static inline void io_uring_prep_link_timeout(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_link_timeout(struct io_uring_sqe *sqe,
struct __kernel_timespec *ts,
unsigned flags)
{
@@ -640,14 +658,14 @@ static inline void io_uring_prep_link_timeout(struct io_uring_sqe *sqe,
sqe->timeout_flags = flags;
}
-static inline void io_uring_prep_connect(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_connect(struct io_uring_sqe *sqe, int fd,
const struct sockaddr *addr,
socklen_t addrlen)
{
io_uring_prep_rw(IORING_OP_CONNECT, sqe, fd, addr, 0, addrlen);
}
-static inline void io_uring_prep_files_update(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_files_update(struct io_uring_sqe *sqe,
int *fds, unsigned nr_fds,
int offset)
{
@@ -655,15 +673,15 @@ static inline void io_uring_prep_files_update(struct io_uring_sqe *sqe,
(__u64) offset);
}
-static inline void io_uring_prep_fallocate(struct io_uring_sqe *sqe, int fd,
- int mode, off_t offset, off_t len)
+IOURINGINLINE void io_uring_prep_fallocate(struct io_uring_sqe *sqe, int fd,
+ int mode, __u64 offset, __u64 len)
{
io_uring_prep_rw(IORING_OP_FALLOCATE, sqe, fd,
0, (unsigned int) mode, (__u64) offset);
sqe->addr = (__u64) len;
}
-static inline void io_uring_prep_openat(struct io_uring_sqe *sqe, int dfd,
+IOURINGINLINE void io_uring_prep_openat(struct io_uring_sqe *sqe, int dfd,
const char *path, int flags,
mode_t mode)
{
@@ -672,34 +690,37 @@ static inline void io_uring_prep_openat(struct io_uring_sqe *sqe, int dfd,
}
/* open directly into the fixed file table */
-static inline void io_uring_prep_openat_direct(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_openat_direct(struct io_uring_sqe *sqe,
int dfd, const char *path,
int flags, mode_t mode,
unsigned file_index)
{
io_uring_prep_openat(sqe, dfd, path, flags, mode);
+ /* offset by 1 for allocation */
+ if (file_index == IORING_FILE_INDEX_ALLOC)
+ file_index--;
__io_uring_set_target_fixed_file(sqe, file_index);
}
-static inline void io_uring_prep_close(struct io_uring_sqe *sqe, int fd)
+IOURINGINLINE void io_uring_prep_close(struct io_uring_sqe *sqe, int fd)
{
io_uring_prep_rw(IORING_OP_CLOSE, sqe, fd, NULL, 0, 0);
}
-static inline void io_uring_prep_close_direct(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_close_direct(struct io_uring_sqe *sqe,
unsigned file_index)
{
io_uring_prep_close(sqe, 0);
__io_uring_set_target_fixed_file(sqe, file_index);
}
-static inline void io_uring_prep_read(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_read(struct io_uring_sqe *sqe, int fd,
void *buf, unsigned nbytes, __u64 offset)
{
io_uring_prep_rw(IORING_OP_READ, sqe, fd, buf, nbytes, offset);
}
-static inline void io_uring_prep_write(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_write(struct io_uring_sqe *sqe, int fd,
const void *buf, unsigned nbytes,
__u64 offset)
{
@@ -707,37 +728,54 @@ static inline void io_uring_prep_write(struct io_uring_sqe *sqe, int fd,
}
struct statx;
-static inline void io_uring_prep_statx(struct io_uring_sqe *sqe, int dfd,
- const char *path, int flags, unsigned mask,
- struct statx *statxbuf)
+IOURINGINLINE void io_uring_prep_statx(struct io_uring_sqe *sqe, int dfd,
+ const char *path, int flags,
+ unsigned mask, struct statx *statxbuf)
{
io_uring_prep_rw(IORING_OP_STATX, sqe, dfd, path, mask,
(__u64) (unsigned long) statxbuf);
sqe->statx_flags = (__u32) flags;
}
-static inline void io_uring_prep_fadvise(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_fadvise(struct io_uring_sqe *sqe, int fd,
__u64 offset, off_t len, int advice)
{
io_uring_prep_rw(IORING_OP_FADVISE, sqe, fd, NULL, (__u32) len, offset);
sqe->fadvise_advice = (__u32) advice;
}
-static inline void io_uring_prep_madvise(struct io_uring_sqe *sqe, void *addr,
+IOURINGINLINE void io_uring_prep_madvise(struct io_uring_sqe *sqe, void *addr,
off_t length, int advice)
{
io_uring_prep_rw(IORING_OP_MADVISE, sqe, -1, addr, (__u32) length, 0);
sqe->fadvise_advice = (__u32) advice;
}
-static inline void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd,
+IOURINGINLINE void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd,
const void *buf, size_t len, int flags)
{
io_uring_prep_rw(IORING_OP_SEND, sqe, sockfd, buf, (__u32) len, 0);
sqe->msg_flags = (__u32) flags;
}
-static inline void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd,
+IOURINGINLINE void io_uring_prep_send_set_addr(struct io_uring_sqe *sqe,
+ const struct sockaddr *dest_addr,
+ __u16 addr_len)
+{
+ sqe->addr2 = (unsigned long)(const void *)dest_addr;
+ sqe->addr_len = addr_len;
+}
+
+IOURINGINLINE void io_uring_prep_sendto(struct io_uring_sqe *sqe, int sockfd,
+ const void *buf, size_t len, int flags,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ io_uring_prep_send(sqe, sockfd, buf, len, flags);
+ io_uring_prep_send_set_addr(sqe, addr, addrlen);
+}
+
+IOURINGINLINE void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd,
const void *buf, size_t len, int flags,
unsigned zc_flags)
{
@@ -746,7 +784,7 @@ static inline void io_uring_prep_send_zc(struct io_uring_sqe *sqe, int sockfd,
sqe->ioprio = zc_flags;
}
-static inline void io_uring_prep_send_zc_fixed(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_send_zc_fixed(struct io_uring_sqe *sqe,
int sockfd, const void *buf,
size_t len, int flags,
unsigned zc_flags,
@@ -757,7 +795,7 @@ static inline void io_uring_prep_send_zc_fixed(struct io_uring_sqe *sqe,
sqe->buf_index = buf_index;
}
-static inline void io_uring_prep_sendmsg_zc(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_sendmsg_zc(struct io_uring_sqe *sqe, int fd,
const struct msghdr *msg,
unsigned flags)
{
@@ -765,22 +803,14 @@ static inline void io_uring_prep_sendmsg_zc(struct io_uring_sqe *sqe, int fd,
sqe->opcode = IORING_OP_SENDMSG_ZC;
}
-static inline void io_uring_prep_send_set_addr(struct io_uring_sqe *sqe,
- const struct sockaddr *dest_addr,
- __u16 addr_len)
-{
- sqe->addr2 = (unsigned long)(const void *)dest_addr;
- sqe->addr_len = addr_len;
-}
-
-static inline void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,
+IOURINGINLINE void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,
void *buf, size_t len, int flags)
{
io_uring_prep_rw(IORING_OP_RECV, sqe, sockfd, buf, (__u32) len, 0);
sqe->msg_flags = (__u32) flags;
}
-static inline void io_uring_prep_recv_multishot(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_recv_multishot(struct io_uring_sqe *sqe,
int sockfd, void *buf,
size_t len, int flags)
{
@@ -788,7 +818,7 @@ static inline void io_uring_prep_recv_multishot(struct io_uring_sqe *sqe,
sqe->ioprio |= IORING_RECV_MULTISHOT;
}
-static inline struct io_uring_recvmsg_out *
+IOURINGINLINE struct io_uring_recvmsg_out *
io_uring_recvmsg_validate(void *buf, int buf_len, struct msghdr *msgh)
{
unsigned long header = msgh->msg_controllen + msgh->msg_namelen +
@@ -798,12 +828,12 @@ io_uring_recvmsg_validate(void *buf, int buf_len, struct msghdr *msgh)
return (struct io_uring_recvmsg_out *)buf;
}
-static inline void *io_uring_recvmsg_name(struct io_uring_recvmsg_out *o)
+IOURINGINLINE void *io_uring_recvmsg_name(struct io_uring_recvmsg_out *o)
{
return (void *) &o[1];
}
-static inline struct cmsghdr *
+IOURINGINLINE struct cmsghdr *
io_uring_recvmsg_cmsg_firsthdr(struct io_uring_recvmsg_out *o,
struct msghdr *msgh)
{
@@ -814,7 +844,7 @@ io_uring_recvmsg_cmsg_firsthdr(struct io_uring_recvmsg_out *o,
msgh->msg_namelen);
}
-static inline struct cmsghdr *
+IOURINGINLINE struct cmsghdr *
io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *msgh,
struct cmsghdr *cmsg)
{
@@ -835,14 +865,14 @@ io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *msg
return cmsg;
}
-static inline void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o,
+IOURINGINLINE void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o,
struct msghdr *msgh)
{
return (void *)((unsigned char *)io_uring_recvmsg_name(o) +
msgh->msg_namelen + msgh->msg_controllen);
}
-static inline unsigned int
+IOURINGINLINE unsigned int
io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o,
int buf_len, struct msghdr *msgh)
{
@@ -853,7 +883,7 @@ io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o,
return (unsigned int) (payload_end - payload_start);
}
-static inline void io_uring_prep_openat2(struct io_uring_sqe *sqe, int dfd,
+IOURINGINLINE void io_uring_prep_openat2(struct io_uring_sqe *sqe, int dfd,
const char *path, struct open_how *how)
{
io_uring_prep_rw(IORING_OP_OPENAT2, sqe, dfd, path, sizeof(*how),
@@ -861,17 +891,20 @@ static inline void io_uring_prep_openat2(struct io_uring_sqe *sqe, int dfd,
}
/* open directly into the fixed file table */
-static inline void io_uring_prep_openat2_direct(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_openat2_direct(struct io_uring_sqe *sqe,
int dfd, const char *path,
struct open_how *how,
unsigned file_index)
{
io_uring_prep_openat2(sqe, dfd, path, how);
+ /* offset by 1 for allocation */
+ if (file_index == IORING_FILE_INDEX_ALLOC)
+ file_index--;
__io_uring_set_target_fixed_file(sqe, file_index);
}
struct epoll_event;
-static inline void io_uring_prep_epoll_ctl(struct io_uring_sqe *sqe, int epfd,
+IOURINGINLINE void io_uring_prep_epoll_ctl(struct io_uring_sqe *sqe, int epfd,
int fd, int op,
struct epoll_event *ev)
{
@@ -879,7 +912,7 @@ static inline void io_uring_prep_epoll_ctl(struct io_uring_sqe *sqe, int epfd,
(__u32) op, (__u32) fd);
}
-static inline void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe,
void *addr, int len, int nr,
int bgid, int bid)
{
@@ -888,33 +921,33 @@ static inline void io_uring_prep_provide_buffers(struct io_uring_sqe *sqe,
sqe->buf_group = (__u16) bgid;
}
-static inline void io_uring_prep_remove_buffers(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_remove_buffers(struct io_uring_sqe *sqe,
int nr, int bgid)
{
io_uring_prep_rw(IORING_OP_REMOVE_BUFFERS, sqe, nr, NULL, 0, 0);
sqe->buf_group = (__u16) bgid;
}
-static inline void io_uring_prep_shutdown(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_shutdown(struct io_uring_sqe *sqe, int fd,
int how)
{
io_uring_prep_rw(IORING_OP_SHUTDOWN, sqe, fd, NULL, (__u32) how, 0);
}
-static inline void io_uring_prep_unlinkat(struct io_uring_sqe *sqe, int dfd,
+IOURINGINLINE void io_uring_prep_unlinkat(struct io_uring_sqe *sqe, int dfd,
const char *path, int flags)
{
io_uring_prep_rw(IORING_OP_UNLINKAT, sqe, dfd, path, 0, 0);
sqe->unlink_flags = (__u32) flags;
}
-static inline void io_uring_prep_unlink(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_unlink(struct io_uring_sqe *sqe,
const char *path, int flags)
{
io_uring_prep_unlinkat(sqe, AT_FDCWD, path, flags);
}
-static inline void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd,
+IOURINGINLINE void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd,
const char *oldpath, int newdfd,
const char *newpath, unsigned int flags)
{
@@ -924,13 +957,14 @@ static inline void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd,
sqe->rename_flags = (__u32) flags;
}
-static inline void io_uring_prep_rename(struct io_uring_sqe *sqe,
- const char *oldpath, const char *newpath)
+IOURINGINLINE void io_uring_prep_rename(struct io_uring_sqe *sqe,
+ const char *oldpath,
+ const char *newpath)
{
io_uring_prep_renameat(sqe, AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
}
-static inline void io_uring_prep_sync_file_range(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_sync_file_range(struct io_uring_sqe *sqe,
int fd, unsigned len,
__u64 offset, int flags)
{
@@ -938,19 +972,19 @@ static inline void io_uring_prep_sync_file_range(struct io_uring_sqe *sqe,
sqe->sync_range_flags = (__u32) flags;
}
-static inline void io_uring_prep_mkdirat(struct io_uring_sqe *sqe, int dfd,
+IOURINGINLINE void io_uring_prep_mkdirat(struct io_uring_sqe *sqe, int dfd,
const char *path, mode_t mode)
{
io_uring_prep_rw(IORING_OP_MKDIRAT, sqe, dfd, path, mode, 0);
}
-static inline void io_uring_prep_mkdir(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_mkdir(struct io_uring_sqe *sqe,
const char *path, mode_t mode)
{
io_uring_prep_mkdirat(sqe, AT_FDCWD, path, mode);
}
-static inline void io_uring_prep_symlinkat(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_symlinkat(struct io_uring_sqe *sqe,
const char *target, int newdirfd,
const char *linkpath)
{
@@ -958,13 +992,14 @@ static inline void io_uring_prep_symlinkat(struct io_uring_sqe *sqe,
(uint64_t) (uintptr_t) linkpath);
}
-static inline void io_uring_prep_symlink(struct io_uring_sqe *sqe,
- const char *target, const char *linkpath)
+IOURINGINLINE void io_uring_prep_symlink(struct io_uring_sqe *sqe,
+ const char *target,
+ const char *linkpath)
{
io_uring_prep_symlinkat(sqe, target, AT_FDCWD, linkpath);
}
-static inline void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd,
+IOURINGINLINE void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd,
const char *oldpath, int newdfd,
const char *newpath, int flags)
{
@@ -973,25 +1008,55 @@ static inline void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd,
sqe->hardlink_flags = (__u32) flags;
}
-static inline void io_uring_prep_link(struct io_uring_sqe *sqe,
- const char *oldpath, const char *newpath, int flags)
+IOURINGINLINE void io_uring_prep_link(struct io_uring_sqe *sqe,
+ const char *oldpath, const char *newpath,
+ int flags)
{
io_uring_prep_linkat(sqe, AT_FDCWD, oldpath, AT_FDCWD, newpath, flags);
}
-static inline void io_uring_prep_msg_ring(struct io_uring_sqe *sqe, int fd,
+IOURINGINLINE void io_uring_prep_msg_ring_cqe_flags(struct io_uring_sqe *sqe,
+ int fd, unsigned int len, __u64 data,
+ unsigned int flags, unsigned int cqe_flags)
+{
+ io_uring_prep_rw(IORING_OP_MSG_RING, sqe, fd, NULL, len, data);
+ sqe->msg_ring_flags = IORING_MSG_RING_FLAGS_PASS | flags;
+ sqe->file_index = cqe_flags;
+}
+
+IOURINGINLINE void io_uring_prep_msg_ring(struct io_uring_sqe *sqe, int fd,
unsigned int len, __u64 data,
unsigned int flags)
{
io_uring_prep_rw(IORING_OP_MSG_RING, sqe, fd, NULL, len, data);
- sqe->rw_flags = flags;
+ sqe->msg_ring_flags = flags;
}
-static inline void io_uring_prep_getxattr(struct io_uring_sqe *sqe,
- const char *name,
- char *value,
- const char *path,
- unsigned int len)
+IOURINGINLINE void io_uring_prep_msg_ring_fd(struct io_uring_sqe *sqe, int fd,
+ int source_fd, int target_fd,
+ __u64 data, unsigned int flags)
+{
+ io_uring_prep_rw(IORING_OP_MSG_RING, sqe, fd,
+ (void *) (uintptr_t) IORING_MSG_SEND_FD, 0, data);
+ sqe->addr3 = source_fd;
+ /* offset by 1 for allocation */
+ if ((unsigned int) target_fd == IORING_FILE_INDEX_ALLOC)
+ target_fd--;
+ __io_uring_set_target_fixed_file(sqe, target_fd);
+ sqe->msg_ring_flags = flags;
+}
+
+IOURINGINLINE void io_uring_prep_msg_ring_fd_alloc(struct io_uring_sqe *sqe,
+ int fd, int source_fd,
+ __u64 data, unsigned int flags)
+{
+ io_uring_prep_msg_ring_fd(sqe, fd, source_fd, IORING_FILE_INDEX_ALLOC,
+ data, flags);
+}
+
+IOURINGINLINE void io_uring_prep_getxattr(struct io_uring_sqe *sqe,
+ const char *name, char *value,
+ const char *path, unsigned int len)
{
io_uring_prep_rw(IORING_OP_GETXATTR, sqe, 0, name, len,
(__u64) (uintptr_t) value);
@@ -999,11 +1064,9 @@ static inline void io_uring_prep_getxattr(struct io_uring_sqe *sqe,
sqe->xattr_flags = 0;
}
-static inline void io_uring_prep_setxattr(struct io_uring_sqe *sqe,
- const char *name,
- const char *value,
- const char *path,
- int flags,
+IOURINGINLINE void io_uring_prep_setxattr(struct io_uring_sqe *sqe,
+ const char *name, const char *value,
+ const char *path, int flags,
unsigned int len)
{
io_uring_prep_rw(IORING_OP_SETXATTR, sqe, 0, name, len,
@@ -1012,30 +1075,25 @@ static inline void io_uring_prep_setxattr(struct io_uring_sqe *sqe,
sqe->xattr_flags = flags;
}
-static inline void io_uring_prep_fgetxattr(struct io_uring_sqe *sqe,
- int fd,
- const char *name,
- char *value,
- unsigned int len)
+IOURINGINLINE void io_uring_prep_fgetxattr(struct io_uring_sqe *sqe,
+ int fd, const char *name,
+ char *value, unsigned int len)
{
io_uring_prep_rw(IORING_OP_FGETXATTR, sqe, fd, name, len,
(__u64) (uintptr_t) value);
sqe->xattr_flags = 0;
}
-static inline void io_uring_prep_fsetxattr(struct io_uring_sqe *sqe,
- int fd,
- const char *name,
- const char *value,
- int flags,
- unsigned int len)
+IOURINGINLINE void io_uring_prep_fsetxattr(struct io_uring_sqe *sqe, int fd,
+ const char *name, const char *value,
+ int flags, unsigned int len)
{
io_uring_prep_rw(IORING_OP_FSETXATTR, sqe, fd, name, len,
(__u64) (uintptr_t) value);
sqe->xattr_flags = flags;
}
-static inline void io_uring_prep_socket(struct io_uring_sqe *sqe, int domain,
+IOURINGINLINE void io_uring_prep_socket(struct io_uring_sqe *sqe, int domain,
int type, int protocol,
unsigned int flags)
{
@@ -1043,7 +1101,7 @@ static inline void io_uring_prep_socket(struct io_uring_sqe *sqe, int domain,
sqe->rw_flags = flags;
}
-static inline void io_uring_prep_socket_direct(struct io_uring_sqe *sqe,
+IOURINGINLINE void io_uring_prep_socket_direct(struct io_uring_sqe *sqe,
int domain, int type,
int protocol,
unsigned file_index,
@@ -1051,12 +1109,16 @@ static inline void io_uring_prep_socket_direct(struct io_uring_sqe *sqe,
{
io_uring_prep_rw(IORING_OP_SOCKET, sqe, domain, NULL, protocol, type);
sqe->rw_flags = flags;
+ /* offset by 1 for allocation */
+ if (file_index == IORING_FILE_INDEX_ALLOC)
+ file_index--;
__io_uring_set_target_fixed_file(sqe, file_index);
}
-static inline void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe,
- int domain, int type, int protocol,
- unsigned int flags)
+IOURINGINLINE void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe,
+ int domain, int type,
+ int protocol,
+ unsigned int flags)
{
io_uring_prep_rw(IORING_OP_SOCKET, sqe, domain, NULL, protocol, type);
sqe->rw_flags = flags;
@@ -1067,7 +1129,7 @@ static inline void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe,
* Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in
* the SQ ring
*/
-static inline unsigned io_uring_sq_ready(const struct io_uring *ring)
+IOURINGINLINE unsigned io_uring_sq_ready(const struct io_uring *ring)
{
unsigned khead = *ring->sq.khead;
@@ -1086,7 +1148,7 @@ static inline unsigned io_uring_sq_ready(const struct io_uring *ring)
/*
* Returns how much space is left in the SQ ring.
*/
-static inline unsigned io_uring_sq_space_left(const struct io_uring *ring)
+IOURINGINLINE unsigned io_uring_sq_space_left(const struct io_uring *ring)
{
return ring->sq.ring_entries - io_uring_sq_ready(ring);
}
@@ -1098,7 +1160,7 @@ static inline unsigned io_uring_sq_space_left(const struct io_uring *ring)
* action is taken. Note: may return -EINVAL if the kernel doesn't support
* this feature.
*/
-static inline int io_uring_sqring_wait(struct io_uring *ring)
+IOURINGINLINE int io_uring_sqring_wait(struct io_uring *ring)
{
if (!(ring->flags & IORING_SETUP_SQPOLL))
return 0;
@@ -1111,7 +1173,7 @@ static inline int io_uring_sqring_wait(struct io_uring *ring)
/*
* Returns how many unconsumed entries are ready in the CQ ring
*/
-static inline unsigned io_uring_cq_ready(const struct io_uring *ring)
+IOURINGINLINE unsigned io_uring_cq_ready(const struct io_uring *ring)
{
return io_uring_smp_load_acquire(ring->cq.ktail) - *ring->cq.khead;
}
@@ -1120,7 +1182,7 @@ static inline unsigned io_uring_cq_ready(const struct io_uring *ring)
* Returns true if there are overflow entries waiting to be flushed onto
* the CQ ring
*/
-static inline bool io_uring_cq_has_overflow(const struct io_uring *ring)
+IOURINGINLINE bool io_uring_cq_has_overflow(const struct io_uring *ring)
{
return IO_URING_READ_ONCE(*ring->sq.kflags) & IORING_SQ_CQ_OVERFLOW;
}
@@ -1128,7 +1190,7 @@ static inline bool io_uring_cq_has_overflow(const struct io_uring *ring)
/*
* Returns true if the eventfd notification is currently enabled
*/
-static inline bool io_uring_cq_eventfd_enabled(const struct io_uring *ring)
+IOURINGINLINE bool io_uring_cq_eventfd_enabled(const struct io_uring *ring)
{
if (!ring->cq.kflags)
return true;
@@ -1140,7 +1202,7 @@ static inline bool io_uring_cq_eventfd_enabled(const struct io_uring *ring)
* Toggle eventfd notification on or off, if an eventfd is registered with
* the ring.
*/
-static inline int io_uring_cq_eventfd_toggle(struct io_uring *ring,
+IOURINGINLINE int io_uring_cq_eventfd_toggle(struct io_uring *ring,
bool enabled)
{
uint32_t flags;
@@ -1168,7 +1230,7 @@ static inline int io_uring_cq_eventfd_toggle(struct io_uring *ring,
* readily available. Returns 0 with cqe_ptr filled in on success, -errno on
* failure.
*/
-static inline int io_uring_wait_cqe_nr(struct io_uring *ring,
+IOURINGINLINE int io_uring_wait_cqe_nr(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr,
unsigned wait_nr)
{
@@ -1180,7 +1242,7 @@ static inline int io_uring_wait_cqe_nr(struct io_uring *ring,
* "official" versions of this, io_uring_peek_cqe(), io_uring_wait_cqe(),
* or io_uring_wait_cqes*().
*/
-static inline int __io_uring_peek_cqe(struct io_uring *ring,
+IOURINGINLINE int __io_uring_peek_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr,
unsigned *nr_available)
{
@@ -1226,7 +1288,7 @@ static inline int __io_uring_peek_cqe(struct io_uring *ring,
* Return an IO completion, if one is readily available. Returns 0 with
* cqe_ptr filled in on success, -errno on failure.
*/
-static inline int io_uring_peek_cqe(struct io_uring *ring,
+IOURINGINLINE int io_uring_peek_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr)
{
if (!__io_uring_peek_cqe(ring, cqe_ptr, NULL) && *cqe_ptr)
@@ -1239,7 +1301,7 @@ static inline int io_uring_peek_cqe(struct io_uring *ring,
* Return an IO completion, waiting for it if necessary. Returns 0 with
* cqe_ptr filled in on success, -errno on failure.
*/
-static inline int io_uring_wait_cqe(struct io_uring *ring,
+IOURINGINLINE int io_uring_wait_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr)
{
if (!__io_uring_peek_cqe(ring, cqe_ptr, NULL) && *cqe_ptr)
@@ -1255,7 +1317,7 @@ static inline int io_uring_wait_cqe(struct io_uring *ring,
*
* Returns a vacant sqe, or NULL if we're full.
*/
-static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
+IOURINGINLINE struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
{
struct io_uring_sq *sq = &ring->sq;
unsigned int head, next = sq->sqe_tail + 1;
@@ -1282,12 +1344,12 @@ static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
/*
* Return the appropriate mask for a buffer ring of size 'ring_entries'
*/
-static inline int io_uring_buf_ring_mask(__u32 ring_entries)
+IOURINGINLINE int io_uring_buf_ring_mask(__u32 ring_entries)
{
return ring_entries - 1;
}
-static inline void io_uring_buf_ring_init(struct io_uring_buf_ring *br)
+IOURINGINLINE void io_uring_buf_ring_init(struct io_uring_buf_ring *br)
{
br->tail = 0;
}
@@ -1295,7 +1357,7 @@ static inline void io_uring_buf_ring_init(struct io_uring_buf_ring *br)
/*
* Assign 'buf' with the addr/len/buffer ID supplied
*/
-static inline void io_uring_buf_ring_add(struct io_uring_buf_ring *br,
+IOURINGINLINE void io_uring_buf_ring_add(struct io_uring_buf_ring *br,
void *addr, unsigned int len,
unsigned short bid, int mask,
int buf_offset)
@@ -1312,7 +1374,7 @@ static inline void io_uring_buf_ring_add(struct io_uring_buf_ring *br,
* io_uring_buf_ring_add() has been called 'count' times to fill in new
* buffers.
*/
-static inline void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
+IOURINGINLINE void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
int count)
{
unsigned short new_tail = br->tail + count;
@@ -1320,6 +1382,14 @@ static inline void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
io_uring_smp_store_release(&br->tail, new_tail);
}
+IOURINGINLINE void __io_uring_buf_ring_cq_advance(struct io_uring *ring,
+ struct io_uring_buf_ring *br,
+ int cq_count, int buf_count)
+{
+ br->tail += buf_count;
+ io_uring_cq_advance(ring, cq_count);
+}
+
/*
* Make 'count' new buffers visible to the kernel while at the same time
* advancing the CQ ring seen entries. This can be used when the application
@@ -1327,16 +1397,15 @@ static inline void io_uring_buf_ring_advance(struct io_uring_buf_ring *br,
* avoiding an extra atomic when needing to increment both the CQ ring and
* the ring buffer index at the same time.
*/
-static inline void io_uring_buf_ring_cq_advance(struct io_uring *ring,
+IOURINGINLINE void io_uring_buf_ring_cq_advance(struct io_uring *ring,
struct io_uring_buf_ring *br,
int count)
{
- br->tail += count;
- io_uring_cq_advance(ring, count);
+ __io_uring_buf_ring_cq_advance(ring, br, count, count);
}
#ifndef LIBURING_INTERNAL
-static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
+IOURINGINLINE struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
{
return _io_uring_get_sqe(ring);
}
@@ -1347,8 +1416,30 @@ struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
ssize_t io_uring_mlock_size(unsigned entries, unsigned flags);
ssize_t io_uring_mlock_size_params(unsigned entries, struct io_uring_params *p);
+/*
+ * Versioning information for liburing.
+ *
+ * Use IO_URING_CHECK_VERSION() for compile time checks including from
+ * preprocessor directives.
+ *
+ * Use io_uring_check_version() for runtime checks of the version of
+ * liburing that was loaded by the dynamic linker.
+ */
+int io_uring_major_version(void);
+int io_uring_minor_version(void);
+bool io_uring_check_version(int major, int minor);
+
+#define IO_URING_CHECK_VERSION(major,minor) \
+ (major > IO_URING_VERSION_MAJOR || \
+ (major == IO_URING_VERSION_MAJOR && \
+ minor >= IO_URING_VERSION_MINOR))
+
#ifdef __cplusplus
}
#endif
+#ifdef IOURINGINLINE
+#undef IOURINGINLINE
+#endif
+
#endif
diff --git a/contrib/libs/liburing/src/include/liburing/compat.h b/contrib/libs/liburing/src/include/liburing/compat.h
index e5794395781..717f81cb7fa 100644
--- a/contrib/libs/liburing/src/include/liburing/compat.h
+++ b/contrib/libs/liburing/src/include/liburing/compat.h
@@ -3,6 +3,8 @@
#define LIBURING_COMPAT_H
#include <linux/time_types.h>
+/* <linux/time_types.h> is included above and not needed again */
+#define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H 1
#include <linux/openat2.h>
diff --git a/contrib/libs/liburing/src/include/liburing/io_uring.h b/contrib/libs/liburing/src/include/liburing/io_uring.h
index a3e09208df7..84c33b5e841 100644
--- a/contrib/libs/liburing/src/include/liburing/io_uring.h
+++ b/contrib/libs/liburing/src/include/liburing/io_uring.h
@@ -12,12 +12,11 @@
#include <linux/types.h>
/*
* this file is shared with liburing and that has to autodetect
- * if linux/time_types.h is available
+ * if linux/time_types.h is available or not, it can
+ * define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
+ * if linux/time_types.h is not available
*/
-#ifdef __KERNEL__
-#define HAVE_LINUX_TIME_TYPES_H 1
-#endif
-#ifdef HAVE_LINUX_TIME_TYPES_H
+#ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
#include <linux/time_types.h>
#endif
@@ -231,7 +230,7 @@ enum io_uring_op {
/*
* sqe->uring_cmd_flags
- * IORING_URING_CMD_FIXED use registered buffer; pass thig flag
+ * IORING_URING_CMD_FIXED use registered buffer; pass this flag
* along with setting sqe->buf_index.
*/
#define IORING_URING_CMD_FIXED (1U << 0)
@@ -251,6 +250,7 @@ enum io_uring_op {
#define IORING_TIMEOUT_REALTIME (1U << 3)
#define IORING_LINK_TIMEOUT_UPDATE (1U << 4)
#define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5)
+#define IORING_TIMEOUT_MULTISHOT (1U << 6)
#define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
#define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
/*
@@ -305,10 +305,28 @@ enum io_uring_op {
*
* IORING_RECVSEND_FIXED_BUF Use registered buffers, the index is stored in
* the buf_index field.
+ *
+ * IORING_SEND_ZC_REPORT_USAGE
+ * If set, SEND[MSG]_ZC should report
+ * the zerocopy usage in cqe.res
+ * for the IORING_CQE_F_NOTIF cqe.
+ * 0 is reported if zerocopy was actually possible.
+ * IORING_NOTIF_USAGE_ZC_COPIED if data was copied
+ * (at least partially).
*/
#define IORING_RECVSEND_POLL_FIRST (1U << 0)
#define IORING_RECV_MULTISHOT (1U << 1)
#define IORING_RECVSEND_FIXED_BUF (1U << 2)
+#define IORING_SEND_ZC_REPORT_USAGE (1U << 3)
+
+/*
+ * cqe.res for IORING_CQE_F_NOTIF if
+ * IORING_SEND_ZC_REPORT_USAGE was requested
+ *
+ * It should be treated as a flag, all other
+ * bits of cqe.res should be treated as reserved!
+ */
+#define IORING_NOTIF_USAGE_ZC_COPIED (1U << 31)
/*
* accept flags stored in sqe->ioprio
@@ -330,6 +348,8 @@ enum {
* applicable for IORING_MSG_DATA, obviously.
*/
#define IORING_MSG_RING_CQE_SKIP (1U << 0)
+/* Pass through the flags from sqe->file_index to cqe->flags */
+#define IORING_MSG_RING_FLAGS_PASS (1U << 1)
/*
* IO completion data structure (Completion Queue Entry)
@@ -370,6 +390,9 @@ enum {
#define IORING_OFF_SQ_RING 0ULL
#define IORING_OFF_CQ_RING 0x8000000ULL
#define IORING_OFF_SQES 0x10000000ULL
+#define IORING_OFF_PBUF_RING 0x80000000ULL
+#define IORING_OFF_PBUF_SHIFT 16
+#define IORING_OFF_MMAP_MASK 0xf8000000ULL
/*
* Filled with the offset for mmap(2)
@@ -453,6 +476,7 @@ struct io_uring_params {
#define IORING_FEAT_RSRC_TAGS (1U << 10)
#define IORING_FEAT_CQE_SKIP (1U << 11)
#define IORING_FEAT_LINKED_FILE (1U << 12)
+#define IORING_FEAT_REG_REG_RING (1U << 13)
/*
* io_uring_register(2) opcodes and arguments
@@ -500,7 +524,10 @@ enum {
IORING_REGISTER_FILE_ALLOC_RANGE = 25,
/* this goes last */
- IORING_REGISTER_LAST
+ IORING_REGISTER_LAST,
+
+ /* flag added to the opcode to use a registered ring fd */
+ IORING_REGISTER_USE_REGISTERED_RING = 1U << 31
};
/* io-wq worker categories */
@@ -545,19 +572,6 @@ struct io_uring_rsrc_update2 {
__u32 resv2;
};
-struct io_uring_notification_slot {
- __u64 tag;
- __u64 resv[3];
-};
-
-struct io_uring_notification_register {
- __u32 nr_slots;
- __u32 resv;
- __u64 resv2;
- __u64 data;
- __u64 resv3;
-};
-
/* Skip updating fd indexes set to this value in the fd table */
#define IORING_REGISTER_FILES_SKIP (-2)
@@ -612,12 +626,26 @@ struct io_uring_buf_ring {
};
};
+/*
+ * Flags for IORING_REGISTER_PBUF_RING.
+ *
+ * IOU_PBUF_RING_MMAP: If set, kernel will allocate the memory for the ring.
+ * The application must not set a ring_addr in struct
+ * io_uring_buf_reg, instead it must subsequently call
+ * mmap(2) with the offset set as:
+ * IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT)
+ * to get a virtual mapping for the ring.
+ */
+enum {
+ IOU_PBUF_RING_MMAP = 1,
+};
+
/* argument for IORING_(UN)REGISTER_PBUF_RING */
struct io_uring_buf_reg {
__u64 ring_addr;
__u32 ring_entries;
__u16 bgid;
- __u16 pad;
+ __u16 flags;
__u64 resv[3];
};
diff --git a/contrib/libs/liburing/src/include/liburing/io_uring_version.h b/contrib/libs/liburing/src/include/liburing/io_uring_version.h
new file mode 100644
index 00000000000..8029e041f9d
--- /dev/null
+++ b/contrib/libs/liburing/src/include/liburing/io_uring_version.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef LIBURING_VERSION_H
+#define LIBURING_VERSION_H
+
+#define IO_URING_VERSION_MAJOR 2
+#define IO_URING_VERSION_MINOR 4
+
+#endif
diff --git a/contrib/libs/liburing/src/int_flags.h b/contrib/libs/liburing/src/int_flags.h
index 90505ec340b..71774fbca53 100644
--- a/contrib/libs/liburing/src/int_flags.h
+++ b/contrib/libs/liburing/src/int_flags.h
@@ -4,6 +4,7 @@
enum {
INT_FLAG_REG_RING = 1,
+ INT_FLAG_REG_REG_RING = 2,
};
#endif
diff --git a/contrib/libs/liburing/src/lib.h b/contrib/libs/liburing/src/lib.h
index 82c0ab10d3f..635a30ece51 100644
--- a/contrib/libs/liburing/src/lib.h
+++ b/contrib/libs/liburing/src/lib.h
@@ -37,25 +37,14 @@
#define __hot __attribute__((__hot__))
#define __cold __attribute__((__cold__))
+#ifdef CONFIG_NOLIBC
+void *__uring_memset(void *s, int c, size_t n);
void *__uring_malloc(size_t len);
void __uring_free(void *p);
-static inline void *uring_malloc(size_t len)
-{
-#ifdef CONFIG_NOLIBC
- return __uring_malloc(len);
-#else
- return malloc(len);
-#endif
-}
-
-static inline void uring_free(void *ptr)
-{
-#ifdef CONFIG_NOLIBC
- __uring_free(ptr);
-#else
- free(ptr);
+#define malloc(LEN) __uring_malloc(LEN)
+#define free(PTR) __uring_free(PTR)
+#define memset(PTR, C, LEN) __uring_memset(PTR, C, LEN)
#endif
-}
#endif /* #ifndef LIBURING_LIB_H */
diff --git a/contrib/libs/liburing/src/nolibc.c b/contrib/libs/liburing/src/nolibc.c
new file mode 100644
index 00000000000..22d23ec50df
--- /dev/null
+++ b/contrib/libs/liburing/src/nolibc.c
@@ -0,0 +1,56 @@
+#include "../config-host.h"
+/* SPDX-License-Identifier: MIT */
+
+#ifndef CONFIG_NOLIBC
+#error "This file should only be compiled for no libc build"
+#endif
+
+#include "lib.h"
+#include "syscall.h"
+
+void *__uring_memset(void *s, int c, size_t n)
+{
+ size_t i;
+ unsigned char *p = s;
+
+ for (i = 0; i < n; i++) {
+ p[i] = (unsigned char) c;
+
+ /*
+ * An empty inline ASM to avoid auto-vectorization
+ * because it's too bloated for liburing.
+ */
+ __asm__ volatile ("");
+ }
+
+ return s;
+}
+
+struct uring_heap {
+ size_t len;
+ char user_p[] __attribute__((__aligned__));
+};
+
+void *__uring_malloc(size_t len)
+{
+ struct uring_heap *heap;
+
+ heap = __sys_mmap(NULL, sizeof(*heap) + len, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (IS_ERR(heap))
+ return NULL;
+
+ heap->len = sizeof(*heap) + len;
+ return heap->user_p;
+}
+
+void __uring_free(void *p)
+{
+ struct uring_heap *heap;
+
+ if (uring_unlikely(!p))
+ return;
+
+ heap = container_of(p, struct uring_heap, user_p);
+ __sys_munmap(heap, heap->len);
+}
diff --git a/contrib/libs/liburing/src/queue.c b/contrib/libs/liburing/src/queue.c
index 4b4220782d6..9fca31fe349 100644
--- a/contrib/libs/liburing/src/queue.c
+++ b/contrib/libs/liburing/src/queue.c
@@ -82,7 +82,7 @@ static int _io_uring_get_cqe(struct io_uring *ring,
}
if (!cqe && !data->wait_nr && !data->submit) {
/*
- * If we already looped once, we already entererd
+ * If we already looped once, we already entered
* the kernel. Since there's nothing to submit or
* wait for, don't keep retrying.
*/
@@ -202,7 +202,7 @@ again:
* Sync internal state with kernel ring state on the SQ side. Returns the
* number of pending items in the SQ ring, for the shared ring.
*/
-unsigned __io_uring_flush_sq(struct io_uring *ring)
+static unsigned __io_uring_flush_sq(struct io_uring *ring)
{
struct io_uring_sq *sq = &ring->sq;
unsigned tail = sq->sqe_tail;
diff --git a/contrib/libs/liburing/src/register.c b/contrib/libs/liburing/src/register.c
index 13e80a5811e..5563db2c4ac 100644
--- a/contrib/libs/liburing/src/register.c
+++ b/contrib/libs/liburing/src/register.c
@@ -9,6 +9,15 @@
#include "liburing/compat.h"
#include "liburing/io_uring.h"
+static inline int do_register(struct io_uring *ring, unsigned int opcode,
+ const void *arg, unsigned int nr_args)
+{
+ if (ring->int_flags & INT_FLAG_REG_REG_RING)
+ opcode |= IORING_REGISTER_USE_REGISTERED_RING;
+
+ return __sys_io_uring_register(ring->enter_ring_fd, opcode, arg, nr_args);
+}
+
int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
const struct iovec *iovecs,
const __u64 *tags,
@@ -21,8 +30,7 @@ int io_uring_register_buffers_update_tag(struct io_uring *ring, unsigned off,
.nr = nr,
};
- return __sys_io_uring_register(ring->ring_fd,IORING_REGISTER_BUFFERS_UPDATE, &up,
- sizeof(up));
+ return do_register(ring, IORING_REGISTER_BUFFERS_UPDATE, &up, sizeof(up));
}
int io_uring_register_buffers_tags(struct io_uring *ring,
@@ -36,9 +44,7 @@ int io_uring_register_buffers_tags(struct io_uring *ring,
.tags = (unsigned long)tags,
};
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_BUFFERS2, &reg,
- sizeof(reg));
+ return do_register(ring, IORING_REGISTER_BUFFERS2, &reg, sizeof(reg));
}
int io_uring_register_buffers_sparse(struct io_uring *ring, unsigned nr)
@@ -48,27 +54,18 @@ int io_uring_register_buffers_sparse(struct io_uring *ring, unsigned nr)
.nr = nr,
};
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS2,
- &reg, sizeof(reg));
+ return do_register(ring, IORING_REGISTER_BUFFERS2, &reg, sizeof(reg));
}
int io_uring_register_buffers(struct io_uring *ring, const struct iovec *iovecs,
unsigned nr_iovecs)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_BUFFERS,
- iovecs, nr_iovecs);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_REGISTER_BUFFERS, iovecs, nr_iovecs);
}
int io_uring_unregister_buffers(struct io_uring *ring)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_BUFFERS,
- NULL, 0);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_UNREGISTER_BUFFERS, NULL, 0);
}
int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
@@ -82,9 +79,7 @@ int io_uring_register_files_update_tag(struct io_uring *ring, unsigned off,
.nr = nr_files,
};
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILES_UPDATE2, &up,
- sizeof(up));
+ return do_register(ring, IORING_REGISTER_FILES_UPDATE2, &up, sizeof(up));
}
/*
@@ -102,9 +97,7 @@ int io_uring_register_files_update(struct io_uring *ring, unsigned off,
.fds = (unsigned long) files,
};
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILES_UPDATE, &up,
- nr_files);
+ return do_register(ring, IORING_REGISTER_FILES_UPDATE, &up, nr_files);
}
static int increase_rlimit_nofile(unsigned nr)
@@ -133,9 +126,7 @@ int io_uring_register_files_sparse(struct io_uring *ring, unsigned nr)
int ret, did_increase = 0;
do {
- ret = __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILES2, &reg,
- sizeof(reg));
+ ret = do_register(ring, IORING_REGISTER_FILES2, &reg, sizeof(reg));
if (ret >= 0)
break;
if (ret == -EMFILE && !did_increase) {
@@ -160,9 +151,7 @@ int io_uring_register_files_tags(struct io_uring *ring, const int *files,
int ret, did_increase = 0;
do {
- ret = __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILES2, &reg,
- sizeof(reg));
+ ret = do_register(ring, IORING_REGISTER_FILES2, &reg, sizeof(reg));
if (ret >= 0)
break;
if (ret == -EMFILE && !did_increase) {
@@ -182,9 +171,7 @@ int io_uring_register_files(struct io_uring *ring, const int *files,
int ret, did_increase = 0;
do {
- ret = __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILES, files,
- nr_files);
+ ret = do_register(ring, IORING_REGISTER_FILES, files, nr_files);
if (ret >= 0)
break;
if (ret == -EMFILE && !did_increase) {
@@ -200,79 +187,50 @@ int io_uring_register_files(struct io_uring *ring, const int *files,
int io_uring_unregister_files(struct io_uring *ring)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES,
- NULL, 0);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_UNREGISTER_FILES, NULL, 0);
}
int io_uring_register_eventfd(struct io_uring *ring, int event_fd)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_EVENTFD,
- &event_fd, 1);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_REGISTER_EVENTFD, &event_fd, 1);
}
int io_uring_unregister_eventfd(struct io_uring *ring)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_EVENTFD,
- NULL, 0);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_UNREGISTER_EVENTFD, NULL, 0);
}
int io_uring_register_eventfd_async(struct io_uring *ring, int event_fd)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_EVENTFD_ASYNC, &event_fd,
- 1);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_REGISTER_EVENTFD_ASYNC, &event_fd, 1);
}
int io_uring_register_probe(struct io_uring *ring, struct io_uring_probe *p,
unsigned int nr_ops)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_PROBE, p,
- nr_ops);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_REGISTER_PROBE, p, nr_ops);
}
int io_uring_register_personality(struct io_uring *ring)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_PERSONALITY, NULL, 0);
+ return do_register(ring, IORING_REGISTER_PERSONALITY, NULL, 0);
}
int io_uring_unregister_personality(struct io_uring *ring, int id)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_UNREGISTER_PERSONALITY, NULL, id);
+ return do_register(ring, IORING_UNREGISTER_PERSONALITY, NULL, id);
}
int io_uring_register_restrictions(struct io_uring *ring,
struct io_uring_restriction *res,
unsigned int nr_res)
{
- int ret;
-
- ret = __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_RESTRICTIONS, res,
- nr_res);
- return (ret < 0) ? ret : 0;
+ return do_register(ring, IORING_REGISTER_RESTRICTIONS, res, nr_res);
}
int io_uring_enable_rings(struct io_uring *ring)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_ENABLE_RINGS, NULL, 0);
+ return do_register(ring, IORING_REGISTER_ENABLE_RINGS, NULL, 0);
}
int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz,
@@ -281,21 +239,17 @@ int io_uring_register_iowq_aff(struct io_uring *ring, size_t cpusz,
if (cpusz >= (1U << 31))
return -EINVAL;
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_IOWQ_AFF,
- mask, (int) cpusz);
+ return do_register(ring, IORING_REGISTER_IOWQ_AFF, mask, (int) cpusz);
}
int io_uring_unregister_iowq_aff(struct io_uring *ring)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_UNREGISTER_IOWQ_AFF, NULL, 0);
+ return do_register(ring, IORING_UNREGISTER_IOWQ_AFF, NULL, 0);
}
int io_uring_register_iowq_max_workers(struct io_uring *ring, unsigned int *val)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_IOWQ_MAX_WORKERS, val,
- 2);
+ return do_register(ring, IORING_REGISTER_IOWQ_MAX_WORKERS, val, 2);
}
int io_uring_register_ring_fd(struct io_uring *ring)
@@ -306,11 +260,16 @@ int io_uring_register_ring_fd(struct io_uring *ring)
};
int ret;
- ret = __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_RING_FDS,
- &up, 1);
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ return -EEXIST;
+
+ ret = do_register(ring, IORING_REGISTER_RING_FDS, &up, 1);
if (ret == 1) {
ring->enter_ring_fd = up.offset;
ring->int_flags |= INT_FLAG_REG_RING;
+ if (ring->features & IORING_FEAT_REG_REG_RING) {
+ ring->int_flags |= INT_FLAG_REG_REG_RING;
+ }
}
return ret;
}
@@ -323,48 +282,58 @@ int io_uring_unregister_ring_fd(struct io_uring *ring)
};
int ret;
- ret = __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_RING_FDS,
- &up, 1);
+ if (!(ring->int_flags & INT_FLAG_REG_RING))
+ return -EINVAL;
+
+ ret = do_register(ring, IORING_UNREGISTER_RING_FDS, &up, 1);
if (ret == 1) {
ring->enter_ring_fd = ring->ring_fd;
- ring->int_flags &= ~INT_FLAG_REG_RING;
+ ring->int_flags &= ~(INT_FLAG_REG_RING | INT_FLAG_REG_REG_RING);
}
return ret;
}
+int io_uring_close_ring_fd(struct io_uring *ring)
+{
+ if (!(ring->features & IORING_FEAT_REG_REG_RING))
+ return -EOPNOTSUPP;
+ if (!(ring->int_flags & INT_FLAG_REG_RING))
+ return -EINVAL;
+ if (ring->ring_fd == -1)
+ return -EBADF;
+
+ __sys_close(ring->ring_fd);
+ ring->ring_fd = -1;
+ return 1;
+}
+
int io_uring_register_buf_ring(struct io_uring *ring,
struct io_uring_buf_reg *reg,
unsigned int __maybe_unused flags)
{
- return __sys_io_uring_register(ring->ring_fd, IORING_REGISTER_PBUF_RING,
- reg, 1);
+ return do_register(ring, IORING_REGISTER_PBUF_RING, reg, 1);
}
int io_uring_unregister_buf_ring(struct io_uring *ring, int bgid)
{
struct io_uring_buf_reg reg = { .bgid = bgid };
- return __sys_io_uring_register(ring->ring_fd,
- IORING_UNREGISTER_PBUF_RING, &reg, 1);
+ return do_register(ring, IORING_UNREGISTER_PBUF_RING, &reg, 1);
}
int io_uring_register_sync_cancel(struct io_uring *ring,
struct io_uring_sync_cancel_reg *reg)
{
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_SYNC_CANCEL, reg, 1);
+ return do_register(ring, IORING_REGISTER_SYNC_CANCEL, reg, 1);
}
int io_uring_register_file_alloc_range(struct io_uring *ring,
unsigned off, unsigned len)
{
- struct io_uring_file_index_range range;
-
- memset(&range, 0, sizeof(range));
- range.off = off;
- range.len = len;
+ struct io_uring_file_index_range range = {
+ .off = off,
+ .len = len
+ };
- return __sys_io_uring_register(ring->ring_fd,
- IORING_REGISTER_FILE_ALLOC_RANGE, &range,
- 0);
+ return do_register(ring, IORING_REGISTER_FILE_ALLOC_RANGE, &range, 0);
}
diff --git a/contrib/libs/liburing/src/setup.c b/contrib/libs/liburing/src/setup.c
index 0c15e75c1c4..db2f3dfe15e 100644
--- a/contrib/libs/liburing/src/setup.c
+++ b/contrib/libs/liburing/src/setup.c
@@ -106,6 +106,7 @@ __cold int io_uring_queue_mmap(int fd, struct io_uring_params *p,
ring->flags = p->flags;
ring->ring_fd = ring->enter_ring_fd = fd;
ring->int_flags = 0;
+ return 0;
}
return ret;
}
@@ -206,7 +207,8 @@ __cold void io_uring_queue_exit(struct io_uring *ring)
*/
if (ring->int_flags & INT_FLAG_REG_RING)
io_uring_unregister_ring_fd(ring);
- __sys_close(ring->ring_fd);
+ if (ring->ring_fd != -1)
+ __sys_close(ring->ring_fd);
}
__cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
@@ -216,7 +218,7 @@ __cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
int r;
len = sizeof(*probe) + 256 * sizeof(struct io_uring_probe_op);
- probe = uring_malloc(len);
+ probe = malloc(len);
if (!probe)
return NULL;
memset(probe, 0, len);
@@ -225,7 +227,7 @@ __cold struct io_uring_probe *io_uring_get_probe_ring(struct io_uring *ring)
if (r >= 0)
return probe;
- uring_free(probe);
+ free(probe);
return NULL;
}
@@ -246,7 +248,7 @@ __cold struct io_uring_probe *io_uring_get_probe(void)
__cold void io_uring_free_probe(struct io_uring_probe *probe)
{
- uring_free(probe);
+ free(probe);
}
static inline int __fls(unsigned long x)
@@ -305,12 +307,14 @@ static size_t rings_size(struct io_uring_params *p, unsigned entries,
__cold ssize_t io_uring_mlock_size_params(unsigned entries,
struct io_uring_params *p)
{
- struct io_uring_params lp = { };
+ struct io_uring_params lp;
struct io_uring ring;
unsigned cq_entries;
long page_size;
ssize_t ret;
+ memset(&lp, 0, sizeof(lp));
+
/*
* We only really use this inited ring to see if the kernel is newer
* or not. Newer kernels don't require memlocked memory. If we fail,
@@ -364,7 +368,105 @@ __cold ssize_t io_uring_mlock_size_params(unsigned entries,
*/
__cold ssize_t io_uring_mlock_size(unsigned entries, unsigned flags)
{
- struct io_uring_params p = { .flags = flags, };
+ struct io_uring_params p;
+ memset(&p, 0, sizeof(p));
+ p.flags = flags;
return io_uring_mlock_size_params(entries, &p);
}
+
+#if defined(__hppa__)
+static struct io_uring_buf_ring *br_setup(struct io_uring *ring,
+ unsigned int nentries, int bgid,
+ unsigned int flags, int *ret)
+{
+ struct io_uring_buf_ring *br;
+ struct io_uring_buf_reg reg;
+ size_t ring_size;
+ off_t off;
+ int lret;
+
+ memset(&reg, 0, sizeof(reg));
+ reg.ring_entries = nentries;
+ reg.bgid = bgid;
+ reg.flags = IOU_PBUF_RING_MMAP;
+
+ *ret = 0;
+ lret = io_uring_register_buf_ring(ring, &reg, flags);
+ if (lret) {
+ *ret = lret;
+ return NULL;
+ }
+
+ off = IORING_OFF_PBUF_RING | (unsigned long long) bgid << IORING_OFF_PBUF_SHIFT;
+ ring_size = nentries * sizeof(struct io_uring_buf);
+ br = __sys_mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_POPULATE, ring->ring_fd, off);
+ if (IS_ERR(br)) {
+ *ret = PTR_ERR(br);
+ return NULL;
+ }
+
+ return br;
+}
+#else
+static struct io_uring_buf_ring *br_setup(struct io_uring *ring,
+ unsigned int nentries, int bgid,
+ unsigned int flags, int *ret)
+{
+ struct io_uring_buf_ring *br;
+ struct io_uring_buf_reg reg;
+ size_t ring_size;
+ int lret;
+
+ memset(&reg, 0, sizeof(reg));
+ ring_size = nentries * sizeof(struct io_uring_buf);
+ br = __sys_mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (IS_ERR(br)) {
+ *ret = PTR_ERR(br);
+ return NULL;
+ }
+
+ reg.ring_addr = (unsigned long) (uintptr_t) br;
+ reg.ring_entries = nentries;
+ reg.bgid = bgid;
+
+ *ret = 0;
+ lret = io_uring_register_buf_ring(ring, &reg, flags);
+ if (lret) {
+ __sys_munmap(br, ring_size);
+ *ret = lret;
+ br = NULL;
+ }
+
+ return br;
+}
+#endif
+
+struct io_uring_buf_ring *io_uring_setup_buf_ring(struct io_uring *ring,
+ unsigned int nentries,
+ int bgid, unsigned int flags,
+ int *ret)
+{
+ struct io_uring_buf_ring *br;
+
+ br = br_setup(ring, nentries, bgid, flags, ret);
+ if (br)
+ io_uring_buf_ring_init(br);
+
+ return br;
+}
+
+int io_uring_free_buf_ring(struct io_uring *ring, struct io_uring_buf_ring *br,
+ unsigned int nentries, int bgid)
+{
+ int ret;
+
+ ret = io_uring_unregister_buf_ring(ring, bgid);
+ if (ret)
+ return ret;
+
+ __sys_munmap(br, nentries * sizeof(struct io_uring_buf));
+ return 0;
+}
diff --git a/contrib/libs/liburing/src/version.c b/contrib/libs/liburing/src/version.c
new file mode 100644
index 00000000000..e1a01229be5
--- /dev/null
+++ b/contrib/libs/liburing/src/version.c
@@ -0,0 +1,22 @@
+#include "../config-host.h"
+/* SPDX-License-Identifier: MIT */
+
+#include "liburing.h"
+#include "liburing/io_uring_version.h"
+
+int io_uring_major_version(void)
+{
+ return IO_URING_VERSION_MAJOR;
+}
+
+int io_uring_minor_version(void)
+{
+ return IO_URING_VERSION_MINOR;
+}
+
+bool io_uring_check_version(int major, int minor)
+{
+ return major > io_uring_major_version() ||
+ (major == io_uring_major_version() &&
+ minor >= io_uring_minor_version());
+}