From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id BE5795A026D for ; Thu, 17 Nov 2022 06:59:22 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NCTkl2QqPz4xcY; Thu, 17 Nov 2022 16:59:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668664751; bh=RtoLQHwQ2bTYpdJ6ojUy4u2mqW90UOOhdEBgvE1RF3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5d7TdHGlqvXmG3VWWP2KCdqPoQEXrPazR/wKSNI0bZuM7TsYVZdNm56T2dH96Cht t60ZOdZ0+ZjlPYhCmDty6TUxJ/VC7wIatx/hShxRouTylHkkD0isBJpGAcZ7bBISYk eB6za0sFA3VuE5TCFH4xx6CiSeML/C0SfoS+9h5s= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 09/32] tcp: Improved helpers to update connections after moving Date: Thu, 17 Nov 2022 16:58:45 +1100 Message-Id: <20221117055908.2782981-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117055908.2782981-1-david@gibson.dropbear.id.au> References: <20221117055908.2782981-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: Z2KLJWUALWZO5XOR4LGN727N3PV3XHXP X-Message-ID-Hash: Z2KLJWUALWZO5XOR4LGN727N3PV3XHXP X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When we compact the connection tables (both spliced and non-spliced) we need to move entries from one slot to another. That requires some updates in the entries themselves. Add helpers to make all the necessary updates for the spliced and non-spliced cases. This will simplify later cleanups. Signed-off-by: David Gibson --- tcp.c | 16 +++++++++------- tcp_splice.c | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tcp.c b/tcp.c index 05eed85..90eb840 100644 --- a/tcp.c +++ b/tcp.c @@ -1291,11 +1291,13 @@ static void tcp_hash_remove(const struct tcp_tap_conn *conn) } /** - * tcp_hash_update() - Update pointer for given connection - * @old: Old connection pointer - * @new: New connection pointer + * tcp_tap_conn_update() - Update tcp_tap_conn when being moved in the table + * @c: Execution context + * @old: Old location of tcp_tap_conn + * @new: New location of tcp_tap_conn */ -static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new) +static void tcp_tap_conn_update(struct ctx *c, struct tcp_tap_conn *old, + struct tcp_tap_conn *new) { struct tcp_tap_conn *entry, *prev = NULL; int b = old->hash_bucket; @@ -1314,6 +1316,8 @@ static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new) debug("TCP: hash table update: old index %li, new index %li, sock %i, " "bucket: %i, old: %p, new: %p", CONN_IDX(old), CONN_IDX(new), new->sock, b, old, new); + + tcp_epoll_ctl(c, new); } /** @@ -1362,9 +1366,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_tap_conn *hole) memcpy(hole, from, sizeof(*hole)); to = hole; - tcp_hash_update(from, to); - - tcp_epoll_ctl(c, to); + tcp_tap_conn_update(c, from, to); debug("TCP: hash table compaction: old index %li, new index %li, " "sock %i, from: %p, to: %p", diff --git a/tcp_splice.c b/tcp_splice.c index d8be91b..7dcd1cb 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -242,6 +242,19 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn, conn_event_do(c, conn, event); \ } while (0) + +/** + * tcp_splice_conn_update() - Update tcp_splice_conn when being moved in the table + * @c: Execution context + * @new: New location of tcp_splice_conn + */ +static void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new) +{ + tcp_splice_epoll_ctl(c, new); + if (tcp_splice_epoll_ctl(c, new)) + conn_flag(c, new, CLOSING); +} + /** * tcp_table_splice_compact - Compact spliced connection table * @c: Execution context @@ -269,9 +282,7 @@ static void tcp_table_splice_compact(struct ctx *c, debug("TCP (spliced): index %li moved to %li", CONN_IDX(move), CONN_IDX(hole)); - tcp_splice_epoll_ctl(c, hole); - if (tcp_splice_epoll_ctl(c, hole)) - conn_flag(c, hole, CLOSING); + tcp_splice_conn_update(c, hole); } /** -- 2.38.1