diff mbox series

[liburing,1/1] test: fix parallel send-zerocopy

Message ID a8ab36c6126de3a0595c1b27e610fc203d076461.1674750570.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series [liburing,1/1] test: fix parallel send-zerocopy | expand

Commit Message

Pavel Begunkov Jan. 26, 2023, 4:29 p.m. UTC
Dylan reported that running send-zerocopy in parallel often fails,
seems to trigger regardless whether it's zc or not. The problem here
is using the same port for all programs, let the kernel to select it.

Reported-by: Dylan Yudaken <dylany@meta.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 test/send-zerocopy.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Comments

Jens Axboe Jan. 26, 2023, 5:17 p.m. UTC | #1
On Thu, 26 Jan 2023 16:29:46 +0000, Pavel Begunkov wrote:
> Dylan reported that running send-zerocopy in parallel often fails,
> seems to trigger regardless whether it's zc or not. The problem here
> is using the same port for all programs, let the kernel to select it.
> 
> 

Applied, thanks!

[1/1] test: fix parallel send-zerocopy
      commit: 3832ea016fe119488812205aae758ab720fc4ef5

Best regards,
diff mbox series

Patch

diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index 16830df..ab56397 100644
--- a/test/send-zerocopy.c
+++ b/test/send-zerocopy.c
@@ -40,7 +40,6 @@ 
 
 #define MAX_MSG	128
 
-#define PORT	10200
 #define HOST	"127.0.0.1"
 #define HOSTV6	"::1"
 
@@ -190,7 +189,8 @@  static int create_socketpair_ip(struct sockaddr_storage *addr,
 				bool ipv6, bool client_connect,
 				bool msg_zc, bool tcp)
 {
-	int family, addr_size;
+	int family;
+	socklen_t addr_size;
 	int ret, val;
 	int listen_sock = -1;
 	int sock;
@@ -201,14 +201,14 @@  static int create_socketpair_ip(struct sockaddr_storage *addr,
 
 		family = AF_INET6;
 		saddr->sin6_family = family;
-		saddr->sin6_port = htons(PORT);
+		saddr->sin6_port = htons(0);
 		addr_size = sizeof(*saddr);
 	} else {
 		struct sockaddr_in *saddr = (struct sockaddr_in *)addr;
 
 		family = AF_INET;
 		saddr->sin_family = family;
-		saddr->sin_port = htons(PORT);
+		saddr->sin_port = htons(0);
 		saddr->sin_addr.s_addr = htonl(INADDR_ANY);
 		addr_size = sizeof(*saddr);
 	}
@@ -223,16 +223,19 @@  static int create_socketpair_ip(struct sockaddr_storage *addr,
 		perror("socket");
 		return 1;
 	}
-	val = 1;
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
-	val = 1;
-	setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
 
 	ret = bind(sock, (struct sockaddr *)addr, addr_size);
 	if (ret < 0) {
 		perror("bind");
 		return 1;
 	}
+
+	ret = getsockname(sock, (struct sockaddr *)addr, &addr_size);
+	if (ret < 0) {
+		fprintf(stderr, "getsockname failed %i\n", errno);
+		return 1;
+	}
+
 	if (tcp) {
 		ret = listen(sock, 128);
 		assert(ret != -1);