liburing: Add sendto(2) and recvfrom(2) support
Subsystems (3)
cover liburing: Add sendto(2) and recvfrom(2) support
Hello,
I submitted an RFC patchset to add sendto(2) and recvfrom(2) support for io_uring. This RFC patchset adds the support for the liburing.
There are 5 patches in this series. 4 from me. 1 from Nugra.
For PATCH 1/5, it is just a .gitignore clean up.
## Changes Summary
- Update io_uring.h header (sync with the kernel).
- Add io_uring_prep_{sendto,sendto} functions.
- Add test program for IORING_OP_SENDTO and IORING_OP_RECVFROM.
- Add documentation for io_uring_prep_{sendto,sendto} functions.
## How to test
This patchset is based on branch "xattr-getdents64" commit:
18d71076f6c97e1b25aa0e3b0e12a913ec4717fa ("src/include/liburing.h: style cleanups")
---
Ammar Faizi (4):
.gitignore: Add /test/xattr and /test/getdents io_uring.h: Add IORING_OP_SENDTO and IORING_OP_RECVFROM liburing.h: Add io_uring_prep_{sendto,sendto} helper
test: Add sendto_recvfrom test program
Nugra (1):
man: Add io_uring_prep_{sendto,recvfrom} docs
.gitignore | 3 + man/io_uring_prep_recvfrom.3 | 33 +++ man/io_uring_prep_sendto.3 | 34 +++ src/include/liburing.h | 22 ++ src/include/liburing/io_uring.h | 2 + test/Makefile | 2 + test/sendto_recvfrom.c | 384 ++++++++++++++++++++++++++++++++ 7 files changed, 480 insertions(+) create mode 100644 man/io_uring_prep_recvfrom.3 create mode 100644 man/io_uring_prep_sendto.3 create mode 100644 test/sendto_recvfrom.c
base-commit: 18d71076f6c97e1b25aa0e3b0e12a913ec4717fa
Signature · 1 line
2.32.0
RFC PATCH 1/5 .gitignore: Add `/test/xattr` and `/test/getdents`
When Stefan added these two tests, he forgot to add them to the .gitignore. Add them.
--- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
.gitignore +2 -0
@@ -60,6 +60,7 @@ /test/files-exit-hang-timeout /test/fixed-link /test/fsync +/test/getdents /test/hardlink /test/io-cancel /test/io_uring_enter
@@ -133,6 +134,7 @@ /test/submit-link-fail /test/exec-target /test/skip-cqe +/test/xattr /test/*.dmesg /test/output/
Signature · 1 line
2.32.0
RFC PATCH 2/5 io_uring.h: Add `IORING_OP_SENDTO` and `IORING_OP_RECVFROM`
In reply to Ammar FaiziSync with the kernel to support for sendto(2) and recvfrom(2), this adds those two new opcodes.
--- src/include/liburing/io_uring.h | 2 ++ 1 file changed, 2 insertions(+)
src/include/liburing/io_uring.h +2 -0
@@ -154,6 +154,8 @@ enum {IORING_OP_SETXATTR ,IORING_OP_FGETXATTR ,IORING_OP_GETXATTR , +IORING_OP_SENDTO , +IORING_OP_RECVFROM ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
2.32.0
RFC PATCH 3/5 liburing.h: Add `io_uring_prep_{sendto,sendto}` helper
In reply to Ammar FaiziThis adds IORING_OP_SENDTO and IORING_OP_RECVFROM prep helper.
--- src/include/liburing.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
src/include/liburing.h +22 -0
@@ -750,6 +750,28 @@ static inline void io_uring_prep_fsetxattr(struct io_uring_sqe *sqe, sqe->xattr_flags = flags; } +static inline void io_uring_prep_sendto (struct io_uring_sqe *sqe,int sockfd, +const void *buf,size_t len,int flags, +const struct sockaddr *dest_addr, +socklen_t addrlen) +{ +io_uring_prep_rw (IORING_OP_SENDTO , sqe, sockfd, buf, (__u32 ) len,0 ); + sqe->msg_flags = (__u32 ) flags; + sqe->addr2 = (__u64 ) (uintptr_t ) dest_addr; + sqe->addr3 = (__u64 ) addrlen; +} + +static inline void io_uring_prep_recvfrom (struct io_uring_sqe *sqe,int sockfd, +void *buf,size_t len,int flags, +struct sockaddr *src_addr, +socklen_t *addrlen) +{ +io_uring_prep_rw (IORING_OP_RECVFROM , sqe, sockfd, buf, (__u32 ) len,0 ); + sqe->msg_flags = (__u32 ) flags; + sqe->addr2 = (__u64 ) (uintptr_t ) src_addr; + sqe->addr3 = (__u64 ) (uintptr_t ) addrlen; +} +/* * Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in * the SQ ring
Signature · 1 line
2.32.0
RFC PATCH 4/5 test: Add sendto_recvfrom test program
In reply to Ammar FaiziAdd a test program for IORING_OP_SENDTO and IORING_OP_RECVFROM.
This test is based on send_recv test. Additional thing that needs extra attention here is that sendto and recvfrom can specify explicit destination and source.
Apart from that, it is exactly the same with send and recv, but with 5-th and 6-th argument be zero.
IOW:
recv(sockfd, buf, len, flags) call
is equivalent to:
recvfrom(sockfd, buf, len, flags, NULL, NULL) call.
And
send(sockfd, buf, len, flags) call
is equivalent to:
sendto(sockfd, buf, len, flags, NULL, 0) call.
--- .gitignore | 1 + test/Makefile | 2 + test/sendto_recvfrom.c | 384 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 test/sendto_recvfrom.c
.gitignore +1 -0
@@ -98,6 +98,7 @@ /test/send_recv /test/send_recvmsg /test/sendmsg_fs_cve +/test/sendto_recvfrom /test/shared-wq /test/short-read /test/shutdown
test/Makefile +2 -0
@@ -118,6 +118,7 @@ test_srcs := \ rw_merge_test.c \ self.c \ sendmsg_fs_cve.c \ + sendto_recvfrom.c \ send_recv.c \ send_recvmsg.c \ shared-wq.c \
@@ -219,6 +220,7 @@ thread-exit: override LDFLAGS += -lpthread ring-leak2: override LDFLAGS += -lpthread poll-mshot-update: override LDFLAGS += -lpthread exit-no-cleanup: override LDFLAGS += -lpthread +sendto_recvfrom: override LDFLAGS += -lpthread install: $(test_targets) runtests.sh runtests-loop.sh $(INSTALL) -D -d -m 755 $(datadir)/liburing-test/
test/sendto_recvfrom.c new file +384 -0
384 lines not on this page · raw message
Signature · 1 line
2.32.0
RFC PATCH 5/5 man: Add `io_uring_prep_{sendto,recvfrom}` docs
In reply to Ammar FaiziFrom: Nugra <[email protected]>
--- man/io_uring_prep_recvfrom.3 | 33 +++++++++++++++++++++++++++++++++ man/io_uring_prep_sendto.3 | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 man/io_uring_prep_recvfrom.3 create mode 100644 man/io_uring_prep_sendto.3
man/io_uring_prep_recvfrom.3 new file +33 -0
@@ -0,0 +1,33 @@ +.\" Copyright (C) 2021 Nugra <[email protected]> +.\" +.\" SPDX-License-Identifier: LGPL-2.0-or-later +.\" +.TH io_uring_prep_recvfrom 3 "December 30, 2021" "liburing-2.1" "liburing Manual" +.SH NAME +io_uring_prep_recvfrom - prepare I/O recvfrom request + +.SH SYNOPSIS +.nf +.BR "#include <liburing.h>" +.PP +.BI "void io_uring_prep_recvfrom(struct io_uring_sqe *sqe, int sockfd," +.BI " void *buf, size_t len, int flags, +.BI " struct sockaddr *src_addr," +.BI " socklen_t *addrlen)" +.SH DESCRIPTION +The io_uring_prep_recvfrom() prepares receive messages from a socket. The submission queue entry +.I sqe +is setup to use the file descriptor +.I fd +transmit the request. + +After the submission queue entry +.I sqe +has been prepared as +.I recvfrom +op, it can be submitted with one of the submit functions. + +.SH RETURN VALUE +None +.SH SEE ALSO +.BR io_uring_get_sqe (3), io_uring_submit (3)
man/io_uring_prep_sendto.3 new file +34 -0
@@ -0,0 +1,34 @@ +.\" Copyright (C) 2021 Nugra <[email protected]> +.\" +.\" SPDX-License-Identifier: LGPL-2.0-or-later +.\" +.TH io_uring_prep_sendto 3 "December 30, 2021" "liburing-2.1" "liburing Manual" +.SH NAME +io_uring_prep_sendto - prepare I/O sendto request + +.SH SYNOPSIS +.nf +.BR "#include <liburing.h>" +.PP +.BI "void io_uring_prep_sendto(struct io_uring_sqe *sqe, int sockfd," +.BI " const void *buf, size_t len, int flags," +.BI " const struct sockaddr *dest_addr," +.BI " socklen_t addrlen)" +.PP +.SH DESCRIPTION +The io_uring_prep_sendto() prepares transmit request to another socket. The submission queue entry +.I sqe +is setup to use the file descriptor +.I fd +transmit the request. + +After the submission queue entry +.I sqe +has been prepared as +.I sendto +op, it can be submitted with one of the submit functions. + +.SH RETURN VALUE +None +.SH SEE ALSO +.BR io_uring_get_sqe (3), io_uring_submit (3)
Signature · 1 line
2.32.0