From patchwork Fri Sep 2 07:14:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C4FC54EE9 for ; Fri, 2 Sep 2022 07:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235438AbiIBHPg (ORCPT ); Fri, 2 Sep 2022 03:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbiIBHPc (ORCPT ); Fri, 2 Sep 2022 03:15:32 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9200C27CFE for ; Fri, 2 Sep 2022 00:15:31 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 817AB80C57; Fri, 2 Sep 2022 07:15:27 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102931; bh=lZw4entFoarpqtxNEsuI3QpY8fUls6MsgylWRSF/gFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJwKH9iLze8+Cv7ToS8KMYgZvEubbfTc89gFwj8+CvMZG8DhDdXYM4zXBV4T/rbq3 C8VaOWpFEGB+U6Y61iEqEbWJBHZlJUrPFoReMTbFFj1CcPVEV2lt+BpFT8jFA7Zm7f /wY8aqhK4grXqcK8wJvK2DIewMhG1NZx1oBslp2B2emO44US0ADmPKMenhr4erIfuM nCO2uYZkEbwiEcxm6EOSChJp8ZPWjp4+aR6VloHQZRZqs2YzlhusghEQClBnoPALMP dYM69mjs6SdBP/rAOyAe7G2DCurSzjDVw+U1zrBJjxuf4B4+o5pBHm4KnUcvS3+cIu eYfuqd6Aa0KjQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 01/12] test/helpers: Add `t_bind_ephemeral_port()` function Date: Fri, 2 Sep 2022 14:14:54 +0700 Message-Id: <20220902071153.3168814-2-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi This is a prep patch to fix an intermittent issue with the port number. We have many places where we need to bind() a socket to any unused port number. To achieve that, the current approach does one of the following mechanisms: 1) Randomly brute force the port number until the bind() syscall succeeds. 2) Use a static port at compile time (randomly chosen too). This is not reliable and it results in an intermittent issue (test fails when the selected port is in use). Setting @addr->sin_port to zero on a bind() syscall lets the kernel choose a port number that is not in use. The caller then can know the port number to be bound by invoking a getsockname() syscall after bind() succeeds. Wrap this procedure in a new function called t_bind_ephemeral_port(). The selected port will be returned into @addr->sin_port, the caller can use it later to connect() or whatever they need. Link: https://lore.kernel.org/r/918facd1-78ba-2de7-693a-5f8c65ea2fcd@gnuweeb.org Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/helpers.c | 18 ++++++++++++++++++ test/helpers.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/test/helpers.c b/test/helpers.c index 0146533..4d5c402 100644 --- a/test/helpers.c +++ b/test/helpers.c @@ -24,14 +24,32 @@ void *t_malloc(size_t size) { void *ret; ret = malloc(size); assert(ret); return ret; } +/* + * Helper for binding socket to an ephemeral port. + * The port number to be bound is returned in @addr->sin_port. + */ +int t_bind_ephemeral_port(int fd, struct sockaddr_in *addr) +{ + socklen_t addrlen; + + addr->sin_port = 0; + if (bind(fd, (struct sockaddr *)addr, sizeof(*addr))) + return -errno; + + addrlen = sizeof(*addr); + assert(!getsockname(fd, (struct sockaddr *)addr, &addrlen)); + assert(addr->sin_port != 0); + return 0; +} + /* * Helper for allocating size bytes aligned on a boundary. */ void t_posix_memalign(void **memptr, size_t alignment, size_t size) { int ret; ret = posix_memalign(memptr, alignment, size); diff --git a/test/helpers.h b/test/helpers.h index 6d5726c..9ad9947 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -18,14 +18,21 @@ enum t_setup_ret { enum t_test_result { T_EXIT_PASS = 0, T_EXIT_FAIL = 1, T_EXIT_SKIP = 77, }; +/* + * Helper for binding socket to an ephemeral port. + * The port number to be bound is returned in @addr->sin_port. + */ +int t_bind_ephemeral_port(int fd, struct sockaddr_in *addr); + + /* * Helper for allocating memory in tests. */ void *t_malloc(size_t size); /* From patchwork Fri Sep 2 07:14:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 511A0ECAAA1 for ; Fri, 2 Sep 2022 07:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbiIBHPj (ORCPT ); Fri, 2 Sep 2022 03:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235446AbiIBHPi (ORCPT ); Fri, 2 Sep 2022 03:15:38 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AF122BB2A for ; Fri, 2 Sep 2022 00:15:35 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id CB2DD80C38; Fri, 2 Sep 2022 07:15:31 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102935; bh=tWfvU6nGOwRgpO1E4lOI3rFftClQKt3nqBwHF9ncPfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mBoR9nBt+OjwsAh9U+XqX3Dg0nlnHcWGaEscVB6/hGW2VWGdUuT2U0LDrgpHvLOlg d0E08KVyAYw8oZ7R4DUX/whctCnkSFHhR9t4gZyw0sWpb0mKN+Ac18JZNqY4kuKGgb ywL6mNxpvPy+N8WW+Mu6yx1satGQpvWwc4SEfkafnDQlAvXS5jFvaY5DgV75IOVmFr qvRWCAudRnMaYuWbBLT9crMIEQxSgfUPAA1laUW4vrmPyLMbP6ks3WbUodS1+lDuVn IdkFarB75Vaj60E20LsFYaTko6AMX7dPPbZZzUsy8dGoj3EWHNsICZoQCMuTz9hoGE OjE5Lh4xHM5/w== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 02/12] t/poll-link: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:55 +0700 Message-Id: <20220902071153.3168814-3-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. v2: - While in there, fix variable placements (put them at the top). Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/poll-link.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/poll-link.c b/test/poll-link.c index 197ad77..39b48f5 100644 --- a/test/poll-link.c +++ b/test/poll-link.c @@ -9,14 +9,15 @@ #include #include #include #include #include #include +#include "helpers.h" #include "liburing.h" pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static int recv_thread_ready = 0; static int recv_thread_done = 0; @@ -46,36 +47,37 @@ struct data { unsigned short port; unsigned int addr; int stop; }; static void *send_thread(void *arg) { + struct sockaddr_in addr; struct data *data = arg; + int s0; wait_for_var(&recv_thread_ready); - int s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); assert(s0 != -1); - struct sockaddr_in addr; - addr.sin_family = AF_INET; addr.sin_port = data->port; addr.sin_addr.s_addr = data->addr; if (connect(s0, (struct sockaddr*)&addr, sizeof(addr)) != -1) wait_for_var(&recv_thread_done); close(s0); return 0; } void *recv_thread(void *arg) { + struct sockaddr_in addr = { }; struct data *data = arg; struct io_uring_sqe *sqe; struct io_uring ring; int i, ret; ret = io_uring_queue_init(8, &ring, 0); assert(ret == 0); @@ -85,35 +87,25 @@ void *recv_thread(void *arg) int32_t val = 1; ret = setsockopt(s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); - struct sockaddr_in addr; - addr.sin_family = AF_INET; data->addr = inet_addr("127.0.0.1"); addr.sin_addr.s_addr = data->addr; - i = 0; - do { - data->port = htons(1025 + (rand() % 64510)); - addr.sin_port = data->port; - - if (bind(s0, (struct sockaddr*)&addr, sizeof(addr)) != -1) - break; - } while (++i < 100); - - if (i >= 100) { - fprintf(stderr, "Can't find good port, skipped\n"); + if (t_bind_ephemeral_port(s0, &addr)) { + perror("bind"); data->stop = 1; signal_var(&recv_thread_ready); - goto out; + goto err; } + data->port = addr.sin_port; ret = listen(s0, 128); assert(ret != -1); signal_var(&recv_thread_ready); sqe = io_uring_get_sqe(&ring); @@ -154,15 +146,14 @@ void *recv_thread(void *arg) (uint64_t) cqe->user_data, cqe->res, data->expected[idx]); goto err; } io_uring_cqe_seen(&ring, cqe); } -out: signal_var(&recv_thread_done); close(s0); io_uring_queue_exit(&ring); return NULL; err: signal_var(&recv_thread_done); close(s0); From patchwork Fri Sep 2 07:14:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A17C54EE9 for ; Fri, 2 Sep 2022 07:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232001AbiIBHPm (ORCPT ); Fri, 2 Sep 2022 03:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233577AbiIBHPl (ORCPT ); Fri, 2 Sep 2022 03:15:41 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D1233358 for ; Fri, 2 Sep 2022 00:15:40 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 1EC8F80C57; Fri, 2 Sep 2022 07:15:35 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102939; bh=8KdROfXyudkGNGd97z8dQf49Bep8VmZZWdSZ9sU9JZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=If5xjmlQ/tKpAS5LrXKcAVuz8lZKHv7qRE+tQNv6xH4j2uN4dz1zL16xhkZqt8eE+ pDFcsF0eeeUZUTZ9qO0M2yPmii+ZfAHGWGBhEnazzP0q4HIiSrCohMfkH4UMu/PqJf kjyD7K1kL1kFsYfUM6I8d45mPRcgb3H3kXyAYSjOZ95W9AHNTiID6jIiLI/ObL0PMh k3iexUors/Vyi9sQIGuw8MhmhFxUFcSaMBALDpl3HKV4ijjPQQZjlNxFOxw+lu8gW9 oWIJjoCBxNtaJUvipIDfBOq1KVPFQRkX2UytVvgfOMiWBIh9JKACIton80R6FBaKi5 tMKWt6sOF1Nqw== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 03/12] t/socket-rw: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:56 +0700 Message-Id: <20220902071153.3168814-4-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/socket-rw.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/test/socket-rw.c b/test/socket-rw.c index 4fbf032..6211b01 100644 --- a/test/socket-rw.c +++ b/test/socket-rw.c @@ -16,14 +16,15 @@ #include #include #include #include #include #include "liburing.h" +#include "helpers.h" int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val = 1; struct sockaddr_in addr; @@ -39,25 +40,15 @@ int main(int argc, char *argv[]) ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - - do { - addr.sin_port = htons((rand() % 61440) + 4096); - ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - if (!ret) - break; - if (errno != EADDRINUSE) { - perror("bind"); - exit(1); - } - } while (1); + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret = listen(recv_s0, 128); assert(ret != -1); p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); val = 1; From patchwork Fri Sep 2 07:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2902DC54EE9 for ; Fri, 2 Sep 2022 07:15:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233577AbiIBHPp (ORCPT ); Fri, 2 Sep 2022 03:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbiIBHPp (ORCPT ); Fri, 2 Sep 2022 03:15:45 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91CB737197 for ; Fri, 2 Sep 2022 00:15:44 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 76BB680C53; Fri, 2 Sep 2022 07:15:40 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102944; bh=5P/4HVhR5lyT4eld4B/ez4Z99vPsEFIBhMu+N4A6WQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZUarb+Xn9+029YXh0MB9nm9sj63zL5VqRR9RJhJNU2YNv4YLm8alsqciIc5v3zkdE rIuW1jf3ZghTYxJNjlB/uXkPz1Q3rxWmnglc8PKq6MSoPFs9IeKB7x97psH+zykk6x /0/WnBCURtLI0EWw/sSDKbB0MogHJbQeBQNJsiAWYW9xtqv8df1H5WLZFLsx4ZdyUI 6F9IiweilGM+DstxKdu92jjHkS42Zbj+f3IhXDTaaQSDgOgDdE24onG/KeqaLaYu3N +ykiQYYX0/Ji4ziJBxx0Bcaq/uI1BKNNLsxLcTmEK+zw/8+/O6/ztDKW83JZhCjtj8 gIICeOv5Oz0VQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 04/12] t/socket-rw-eagain: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:57 +0700 Message-Id: <20220902071153.3168814-5-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/socket-rw-eagain.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/socket-rw-eagain.c b/test/socket-rw-eagain.c index 2d6a817..a12c70d 100644 --- a/test/socket-rw-eagain.c +++ b/test/socket-rw-eagain.c @@ -14,14 +14,15 @@ #include #include #include #include #include #include "liburing.h" +#include "helpers.h" int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val = 1; struct sockaddr_in addr; @@ -37,26 +38,15 @@ int main(int argc, char *argv[]) ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - - do { - addr.sin_port = htons((rand() % 61440) + 4096); - ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - if (!ret) - break; - if (errno != EADDRINUSE) { - perror("bind"); - exit(1); - } - } while (1); - + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret = listen(recv_s0, 128); assert(ret != -1); p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); val = 1; ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); From patchwork Fri Sep 2 07:14:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C735C54EE9 for ; Fri, 2 Sep 2022 07:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231544AbiIBHPv (ORCPT ); Fri, 2 Sep 2022 03:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiIBHPt (ORCPT ); Fri, 2 Sep 2022 03:15:49 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB67B3DF0D for ; Fri, 2 Sep 2022 00:15:48 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id CE85C80C32; Fri, 2 Sep 2022 07:15:44 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102948; bh=XsgUeSNS8UzObKxwEKptqRvJ/bYG5SFx4pbeZrm0SsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sdJtlp1AajNlP7uNPhM2v5tUVIQ8RxmjYfxoujfKTS3pEa8PudlyLr0z3FOGmypyM kjZKNikEyk2TTDEe+nvun5jKqShAyRGQdWL1p63JVx6dnIYVna163O8ztogpMeGkoe FR9ioxNmdpMvcLub7vK+LZOH91Tjm9DufEBpMjWUfp4b7SONkzp7d6oY+tmZfUdqh3 phd0Zp4wUSy1T+CD2HOL6vCHGbsC6b50Z1iZuhtLRPxTBeq7aoZcZQvIareuZyTF4Z aZxz5Uehns2ikG3R8cOj/MCFgWeQ1rje1wxRm5bMJPGr3S2cI3b2imw1IIVG6BPISy toGSplNzcaLTw== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 05/12] t/socket-rw-offset: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:58 +0700 Message-Id: <20220902071153.3168814-6-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/socket-rw-offset.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/test/socket-rw-offset.c b/test/socket-rw-offset.c index 987b6c9..c422442 100644 --- a/test/socket-rw-offset.c +++ b/test/socket-rw-offset.c @@ -16,14 +16,15 @@ #include #include #include #include #include #include "liburing.h" +#include "helpers.h" int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val = 1; struct sockaddr_in addr; @@ -39,25 +40,15 @@ int main(int argc, char *argv[]) ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - - do { - addr.sin_port = htons((rand() % 61440) + 4096); - ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - if (!ret) - break; - if (errno != EADDRINUSE) { - perror("bind"); - exit(1); - } - } while (1); + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret = listen(recv_s0, 128); assert(ret != -1); p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); val = 1; From patchwork Fri Sep 2 07:14:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 265E9ECAAA1 for ; Fri, 2 Sep 2022 07:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235034AbiIBHPz (ORCPT ); Fri, 2 Sep 2022 03:15:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiIBHPy (ORCPT ); Fri, 2 Sep 2022 03:15:54 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32743402DA for ; Fri, 2 Sep 2022 00:15:53 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 32CBD80C16; Fri, 2 Sep 2022 07:15:48 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102953; bh=R5rG7aU/B7wwAgf7ocUkSsJuoLBhyqFD2BPlWKzh60g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pMfMxVOQKhOrR+7aJ5U6mkxRyEbL5WKp42aj+D6mr7nXWm9aZozB7D2hWaFj/iQE0 im0KWkIpQ0RZQLLMZ7/5FbXa6g9if0yZc7W0V7Y2//XTvYGordTvkj2niHzxro+zUH x7MV9+jaceVWO+lengrWakTQaNIbjauBYzlbtkZe5HkyXgouhQOtol2mb5NUjTHGwH 69ItuPN5a42xaadsrkvDseIaAg4eeNQs4oJ/zSoK9lcQ0WSd1YStif0xGqV4d11+DZ DVeB3Y7EMVNzVmw0bW/x3nj+R84cXnR9H/2aiZSMCYvWFZ7jBX9udGQEubdTHh0scY W0vNLS7zNRcew== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 06/12] t/files-exit-hang-poll: Don't brute force the port number Date: Fri, 2 Sep 2022 14:14:59 +0700 Message-Id: <20220902071153.3168814-7-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't brute force the port number, use `t_bind_ephemeral_port()`, much simpler and reliable for choosing a port number that is not in use. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/files-exit-hang-poll.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/test/files-exit-hang-poll.c b/test/files-exit-hang-poll.c index 0c609f1..04febc8 100644 --- a/test/files-exit-hang-poll.c +++ b/test/files-exit-hang-poll.c @@ -15,16 +15,14 @@ #include #include #include "liburing.h" #include "helpers.h" #define BACKLOG 512 -#define PORT 9100 - static struct io_uring ring; static void add_poll(struct io_uring *ring, int fd) { struct io_uring_sqe *sqe; sqe = io_uring_get_sqe(ring); @@ -60,15 +58,14 @@ static void alarm_sig(int sig) int main(int argc, char *argv[]) { struct sockaddr_in serv_addr; struct io_uring_cqe *cqe; int ret, sock_listen_fd; const int val = 1; - int i; if (argc > 1) return T_EXIT_SKIP; sock_listen_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); if (sock_listen_fd < 0) { perror("socket"); @@ -77,28 +74,17 @@ int main(int argc, char *argv[]) setsockopt(sock_listen_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; - for (i = 0; i < 100; i++) { - serv_addr.sin_port = htons(PORT + i); - - ret = bind(sock_listen_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); - if (!ret) - break; - if (errno != EADDRINUSE) { - fprintf(stderr, "bind: %s\n", strerror(errno)); - return T_EXIT_FAIL; - } - if (i == 99) { - printf("Gave up on finding a port, skipping\n"); - goto skip; - } + if (t_bind_ephemeral_port(sock_listen_fd, &serv_addr)) { + perror("bind"); + return T_EXIT_FAIL; } if (listen(sock_listen_fd, BACKLOG) < 0) { perror("Error listening on socket\n"); return T_EXIT_FAIL; } @@ -121,11 +107,8 @@ int main(int argc, char *argv[]) if (ret) { fprintf(stderr, "wait_cqe=%d\n", ret); return T_EXIT_FAIL; } io_uring_queue_exit(&ring); return T_EXIT_PASS; -skip: - io_uring_queue_exit(&ring); - return T_EXIT_SKIP; } From patchwork Fri Sep 2 07:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAFCCC54EE9 for ; Fri, 2 Sep 2022 07:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234723AbiIBHP7 (ORCPT ); Fri, 2 Sep 2022 03:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235286AbiIBHP6 (ORCPT ); Fri, 2 Sep 2022 03:15:58 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 737DA4D83C for ; Fri, 2 Sep 2022 00:15:57 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 7F64980C52; Fri, 2 Sep 2022 07:15:53 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102957; bh=75xduiH5BRYatK1HW5Otf59KSLOr3on+y2lVgrCwD64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7goCI6SlBrm/d+n5cXS3khvSU/ClX9l8s8UvVrj49Yw1Y/bB9Sg1t7AUHfWeaVen JHhbEAZotzetmUTK0sBHBUZ/TIvoGcDMXi/AJGm1JppuxlgBUgwOhbRa1NxwZcsqQo 6uQdL032ff0QyYBtGc1GGIetG8CQKtY4M9jg9JcegOCYz35KgqTbpJyEO25DkZS71b FnwD2fx7x/eaNXus2FRSR4PBcgqfmNQGHaHynoCPqfWX8L5R3qqxif0e5UmEp329ni 5bgiYMMYWwa0xxECtYRE/3H2llHhfa43fCaNuu4hJPMIDM+KYsP5gz7quZKH3lCh0D fe8FFDIvQ351Q== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 07/12] t/socket: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:00 +0700 Message-Id: <20220902071153.3168814-8-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/socket.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/socket.c b/test/socket.c index 6a3ea09..94c8e9f 100644 --- a/test/socket.c +++ b/test/socket.c @@ -7,53 +7,53 @@ #include #include #include #include #include #include #include +#include #include "liburing.h" #include "helpers.h" static char str[] = "This is a test of send and recv over io_uring!"; #define MAX_MSG 128 -#define PORT 10202 #define HOST "127.0.0.1" static int no_socket; +static __be32 g_port; static int recv_prep(struct io_uring *ring, struct iovec *iov, int *sock, int registerfiles) { struct sockaddr_in saddr; struct io_uring_sqe *sqe; int sockfd, ret, val, use_fd; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); - saddr.sin_port = htons(PORT); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("socket"); return 1; } val = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); - ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret < 0) { + if (t_bind_ephemeral_port(sockfd, &saddr)) { perror("bind"); goto err; } + g_port = saddr.sin_port; if (registerfiles) { ret = io_uring_register_files(ring, &sockfd, 1); if (ret) { fprintf(stderr, "file reg failed\n"); goto err; } @@ -240,17 +240,18 @@ static int do_send(int socket_direct, int alloc) ret = io_uring_register_files(&ring, &fd, 1); if (ret) { fprintf(stderr, "file register %d\n", ret); return 1; } } + assert(g_port != 0); memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; - saddr.sin_port = htons(PORT); + saddr.sin_port = g_port; inet_pton(AF_INET, HOST, &saddr.sin_addr); sqe = io_uring_get_sqe(&ring); if (socket_direct) { unsigned file_index = 0; if (alloc) file_index = IORING_FILE_INDEX_ALLOC - 1; From patchwork Fri Sep 2 07:15:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8730AECAAA1 for ; Fri, 2 Sep 2022 07:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234970AbiIBHQE (ORCPT ); Fri, 2 Sep 2022 03:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233931AbiIBHQD (ORCPT ); Fri, 2 Sep 2022 03:16:03 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C189250725 for ; Fri, 2 Sep 2022 00:16:01 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id BC97180C38; Fri, 2 Sep 2022 07:15:57 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102961; bh=fB/SGSBw+8SZhNANAbgH+HD11RWuT2SAsbQ2ZNOIGLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cSbLiMsWBY5yKtSLcrjP2QWCPHCuaD03SbnWVZGJEDYJNpSaBz85v7U4Wytjul2bA BWj1CBt6hfBHbM3F4ATQh2svj69MkOSMmXE/FxJz2IITHkRCNkOXdKA2h6fL86pQz2 MW8ArP7BpMdVTCC1+g8eLpRctoaetDKqNcocYWkKfSZTXNfadnNsoJR52FSlq5+ptL goCbOqt2AYOgTTepoSOlFggeR9R6mRr0Yu4UX+Lfs/vHLioeJJt1qAui+PgOVg0dWf 8yAwAMvT1gfhyjv7S9Myi1qzd3J2pSh0F881YfWxUfnmUrJCq3e5O/ifbIR4uaJQ58 OrRAwrjY+D4zw== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 08/12] t/connect: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:01 +0700 Message-Id: <20220902071153.3168814-9-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/accept.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/accept.c b/test/accept.c index b35ded4..1821faa 100644 --- a/test/accept.c +++ b/test/accept.c @@ -190,19 +190,16 @@ static int start_accept_listen(struct sockaddr_in *addr, int port_off, struct sockaddr_in laddr; if (!addr) addr = &laddr; addr->sin_family = AF_INET; - addr->sin_port = htons(0x1235 + port_off); addr->sin_addr.s_addr = inet_addr("127.0.0.1"); - - ret = bind(fd, (struct sockaddr*)addr, sizeof(*addr)); - assert(ret != -1); + assert(!t_bind_ephemeral_port(fd, addr)); ret = listen(fd, 128); assert(ret != -1); return fd; } static int set_client_fd(struct sockaddr_in *addr) From patchwork Fri Sep 2 07:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB0C6C6FA81 for ; Fri, 2 Sep 2022 07:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbiIBHQI (ORCPT ); Fri, 2 Sep 2022 03:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233931AbiIBHQH (ORCPT ); Fri, 2 Sep 2022 03:16:07 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0903A52E66 for ; Fri, 2 Sep 2022 00:16:06 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 06D0380C52; Fri, 2 Sep 2022 07:16:01 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102965; bh=8CxoNLdpfZGlVSeMG07m4BkqhkERVBRYGewViV876js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKHIB9nGvMeZb6apL5hbyK7KrXb9vKmkKmbgF2hmXXR+uiTWMzv0SBhlbvYvRi2Eg qg/AhXKCkKNwxVohbuOGw5Dll5M/kuID/mok8qZLTs88EH52cHcwwXnCbj0UTiu+O2 qjo1+yFcHZVr2JqAs6ImkEZIVcExyhzUnn52rxNdUVC9hj9RxWdLYC8EBk9JWKEyXL 9+SMlw9E8N29l+riCEc4t+IAAhrpkes0RNIAweXQD980IVPUJfv8IPmgAEothGpTjv VFyHtRCqrDzqGD2Ksz+rE9jyQ3Bc5vQxSnfyjePM1CUZhNO1fwaVXyFa9I13/5sACl ss4AuIvA6oqOQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 09/12] t/shutdown: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:02 +0700 Message-Id: <20220902071153.3168814-10-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/shutdown.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/shutdown.c b/test/shutdown.c index 14c7407..064ee36 100644 --- a/test/shutdown.c +++ b/test/shutdown.c @@ -15,44 +15,43 @@ #include #include #include #include #include #include "liburing.h" +#include "helpers.h" static void sig_pipe(int sig) { } int main(int argc, char *argv[]) { int p_fd[2], ret; int32_t recv_s0; int32_t val = 1; - struct sockaddr_in addr; + struct sockaddr_in addr = { }; if (argc > 1) return 0; srand(getpid()); recv_s0 = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); assert(ret != -1); ret = setsockopt(recv_s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(ret != -1); addr.sin_family = AF_INET; - addr.sin_port = htons((rand() % 61440) + 4096); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr)); - assert(ret != -1); + assert(!t_bind_ephemeral_port(recv_s0, &addr)); ret = listen(recv_s0, 128); assert(ret != -1); p_fd[1] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); val = 1; ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); From patchwork Fri Sep 2 07:15:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C65C54EE9 for ; Fri, 2 Sep 2022 07:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235369AbiIBHQP (ORCPT ); Fri, 2 Sep 2022 03:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235295AbiIBHQM (ORCPT ); Fri, 2 Sep 2022 03:16:12 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACF7550BB for ; Fri, 2 Sep 2022 00:16:10 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 585AB80C38; Fri, 2 Sep 2022 07:16:06 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102970; bh=2p9uHfWtW3AKFDRIFltihLhNPVLqKFuiwaVh2DT6Y5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RrIeiej1KF92eSZmADJXkEKGyDRjyW8ytRoMswcTlcucwZqHuG4atHc1JNiksrN9r ujifqSb3OrbnukXsn+DHgECASUaHq7/t3CduP3+bAahnPymu/iCgdBjenjhgodpeJI HiBw/8mcrY0JcDdFaKqRee37uWqembyerVe3VfnJssSHJvV5furSxkBE5rTWhcXaaa mu0ieKCTf72HFliiiTiLZXtApNJiTOAYB71fNWkfOTVmciMA4X9iGp+jocoit1xEnv 7Ds+sC8jP+v9+r0R1G+88FH0XdYALnHrAkIpsf/1o+VSLDOxtlsvGe5abhocEMx+rq wmFwO1h+jN5/g== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 10/12] t/recv-msgall: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:03 +0700 Message-Id: <20220902071153.3168814-11-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/recv-msgall.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/recv-msgall.c b/test/recv-msgall.c index a6f7cfc..ae123e4 100644 --- a/test/recv-msgall.c +++ b/test/recv-msgall.c @@ -12,45 +12,43 @@ #include #include #include "liburing.h" #include "helpers.h" #define MAX_MSG 128 - -#define PORT 10201 #define HOST "127.0.0.1" +static __be16 bind_port; static int recv_prep(struct io_uring *ring, struct iovec *iov, int *sock, int use_recvmsg) { struct sockaddr_in saddr; struct io_uring_sqe *sqe; int sockfd, ret, val; struct msghdr msg = { }; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); - saddr.sin_port = htons(PORT); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("socket"); return 1; } val = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); - ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret < 0) { + if (t_bind_ephemeral_port(sockfd, &saddr)) { perror("bind"); goto err; } + bind_port = saddr.sin_port; sqe = io_uring_get_sqe(ring); if (!use_recvmsg) { io_uring_prep_recv(sqe, sockfd, iov->iov_base, iov->iov_len, MSG_WAITALL); } else { msg.msg_namelen = sizeof(struct sockaddr_in); @@ -161,15 +159,15 @@ static int do_send(void) buf = malloc(MAX_MSG * sizeof(int)); for (i = 0; i < MAX_MSG; i++) buf[i] = i; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; - saddr.sin_port = htons(PORT); + saddr.sin_port = bind_port; inet_pton(AF_INET, HOST, &saddr.sin_addr); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("socket"); return 1; } From patchwork Fri Sep 2 07:15:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963724 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC33BECAAA1 for ; Fri, 2 Sep 2022 07:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235295AbiIBHQQ (ORCPT ); Fri, 2 Sep 2022 03:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235371AbiIBHQP (ORCPT ); Fri, 2 Sep 2022 03:16:15 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C2257558 for ; Fri, 2 Sep 2022 00:16:14 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id C570880C32; Fri, 2 Sep 2022 07:16:10 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102974; bh=T126dCp9v3ZoM12a5j/AAdc4YvfYF7qFFa3/xP4/m7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIaZsJ17zV9TcQ9MTYvuBQppOFeD3JAkzQIYiLG/od27uLq4mk3ExJIXqALhOwfP3 tLH9Usz+RJyNVGEOFhYyTt4NBJGi4hCXKi+z78fNYYFChsJBcJIZwc2c8+11YHojWs QzUUsSymKabZoMvPeOplVGdpTTZtALUOjR9eQckoytrnTN2RuuGvMLFH6hCsBTos7u VPs9uFSVPKIwswMkvV0WtE07dB6DpnNr7A/VP1FzqYAUaCQWLpymucCmDRy4Dvqdks RdcRZFJ4eksWktL6lcqotNmfhPW5ROlZ6TLPXCXBeMHvOGD0tIJOyHDiSmlxbckF8q TBDRphZmlOhFg== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 11/12] t/232c93d07b74: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:04 +0700 Message-Id: <20220902071153.3168814-12-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/232c93d07b74.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/232c93d07b74.c b/test/232c93d07b74.c index c99491f..74cc063 100644 --- a/test/232c93d07b74.c +++ b/test/232c93d07b74.c @@ -23,19 +23,18 @@ #include "helpers.h" #include "liburing.h" #define RECV_BUFF_SIZE 2 #define SEND_BUFF_SIZE 3 -#define PORT 0x1234 - struct params { int tcp; int non_blocking; + __be16 bind_port; }; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int rcv_ready = 0; static void set_rcv_ready(void) @@ -73,18 +72,17 @@ static void *rcv(void *arg) assert(res != -1); res = setsockopt(s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(res != -1); struct sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons(PORT); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - res = bind(s0, (struct sockaddr *) &addr, sizeof(addr)); - assert(res != -1); + assert(t_bind_ephemeral_port(s0, &addr) == 0); + p->bind_port = addr.sin_port; } else { s0 = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); assert(s0 != -1); struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); @@ -188,15 +186,15 @@ static void *snd(void *arg) s0 = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); ret = setsockopt(s0, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); assert(ret != -1); struct sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons(PORT); + addr.sin_port = p->bind_port; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); ret = connect(s0, (struct sockaddr*) &addr, sizeof(addr)); assert(ret != -1); } else { s0 = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); assert(s0 != -1); From patchwork Fri Sep 2 07:15:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12963725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB394C54EE9 for ; Fri, 2 Sep 2022 07:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235381AbiIBHQW (ORCPT ); Fri, 2 Sep 2022 03:16:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235371AbiIBHQW (ORCPT ); Fri, 2 Sep 2022 03:16:22 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548335F11D for ; Fri, 2 Sep 2022 00:16:20 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id 355BC80C74; Fri, 2 Sep 2022 07:16:14 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102979; bh=xdxxEiXCVOGbUZCh1DJ5zBAf3MA/1dNBGI/518QX6L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKNzIM7/KbYFgrKmmbO6jUZN0no5sbkEXWWc2LoOsjX6x9LhNrDeum98SHLJvBHyR riOYp8boND1lw6KXvalF0VaKYeCUN7ZFhcnBv5J4E6qQy7NJnDFJwhT7/LHW2QbMM1 p9bxYBGC7PO3zQwep2vCc8CvypqsxVY3kUaEIZJXNHw0WWiiRZwHWBeDGZeQQK6xTr 6PrRyOLWtnTO2UJeP4Pb87LsKGMFllbJ6NqbXdKmhb0ksfWDgSaT5mJ4ypCQKy3L2t 68MnaSWzf56VpzxMYfDYA6n9j4UdUv6wFMUEGO/+rEvyYnGfO4e1P15jknJplul+B+ 61yWeP3K2HprQ== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 12/12] t/recv-msgall-stream: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:05 +0700 Message-Id: <20220902071153.3168814-13-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/recv-msgall-stream.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/recv-msgall-stream.c b/test/recv-msgall-stream.c index a188cc1..65b4d22 100644 --- a/test/recv-msgall-stream.c +++ b/test/recv-msgall-stream.c @@ -1,12 +1,13 @@ /* SPDX-License-Identifier: MIT */ /* * Test MSG_WAITALL for recv/recvmsg and include normal sync versions just * for comparison. */ +#include #include #include #include #include #include #include #include @@ -15,48 +16,45 @@ #include #include "liburing.h" #include "helpers.h" #define MAX_MSG 128 -static int port = 31200; - struct recv_data { pthread_mutex_t mutex; int use_recvmsg; int use_sync; - int port; + __be16 port; }; static int get_conn_sock(struct recv_data *rd, int *sockout) { struct sockaddr_in saddr; int sockfd, ret, val; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); - saddr.sin_port = htons(rd->port); sockfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); if (sockfd < 0) { perror("socket"); goto err; } val = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); - ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret < 0) { + if (t_bind_ephemeral_port(sockfd, &saddr)) { perror("bind"); goto err; } + rd->port = saddr.sin_port; ret = listen(sockfd, 16); if (ret < 0) { perror("listen"); goto err; } @@ -275,26 +273,26 @@ static int do_send(struct recv_data *rd) return 1; } buf = malloc(MAX_MSG * sizeof(int)); for (i = 0; i < MAX_MSG; i++) buf[i] = i; - memset(&saddr, 0, sizeof(saddr)); - saddr.sin_family = AF_INET; - saddr.sin_port = htons(rd->port); - inet_pton(AF_INET, "127.0.0.1", &saddr.sin_addr); - sockfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); if (sockfd < 0) { perror("socket"); return 1; } pthread_mutex_lock(&rd->mutex); + assert(rd->port != 0); + memset(&saddr, 0, sizeof(saddr)); + saddr.sin_family = AF_INET; + saddr.sin_port = rd->port; + inet_pton(AF_INET, "127.0.0.1", &saddr.sin_addr); ret = connect(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { perror("connect"); return 1; } @@ -347,15 +345,15 @@ static int test(int use_recvmsg, int use_sync) pthread_mutexattr_init(&attr); pthread_mutexattr_setpshared(&attr, 1); pthread_mutex_init(&rd.mutex, &attr); pthread_mutex_lock(&rd.mutex); rd.use_recvmsg = use_recvmsg; rd.use_sync = use_sync; - rd.port = port++; + rd.port = 0; ret = pthread_create(&recv_thread, NULL, recv_fn, &rd); if (ret) { fprintf(stderr, "Thread create failed: %d\n", ret); pthread_mutex_unlock(&rd.mutex); return 1; }