From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=bruNyys8; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E92415A0622 for ; Wed, 19 Feb 2025 03:28:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1739932118; bh=rMn95wyfUh8Yi8+0QsKIRRaGfqPdiQFZk5N7GT1uf/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bruNyys8Mme5Qk9k7Ho54uQ81m9eZzrZ9pu2GqexTQzNS4cLgqBHecwQ56Wfd2LiQ 637yg9aXyUWrjJiNgKaGpRiUdsfDpNYpmtk+lrVUpdgWG/905dspr7cE349QdLiPGb 6jpkBwvRzRyM6wS0oeztmwj9P5G0UQgme8ekBybq2rNns5XRD8LBV+Usgb5s21JLSU HU2JMVxhlr06+o+SzcDecrVC2Ldm7W8LlwbUsFtmjGGCKgT1IR9Gs9iGyZyZdhlHLl kYGszrX0vWRqRyIhBtEIkueCklnqZQd3hfxrl711KdRgU4zORpDNx7/Tfqc12HwP3n TgIBzbRzJ1AXQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4YyL124Bb6z4wj2; Wed, 19 Feb 2025 13:28:38 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/3] flow: Remove unneeded bound parameter from flow traversal macros Date: Wed, 19 Feb 2025 13:28:35 +1100 Message-ID: <20250219022836.3345243-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219022836.3345243-1-david@gibson.dropbear.id.au> References: <20250219022836.3345243-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: MXSBZ3LRJOWLU3YNUBPZ2ATYKNF2YUBG X-Message-ID-Hash: MXSBZ3LRJOWLU3YNUBPZ2ATYKNF2YUBG 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.8 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: The foreach macros used to step through flows each take a 'bound' parameter to only scan part of the flow table. Only one place actually passes a bound different from FLOW_MAX. So we can simplify every other invocation by having that one case manually handle the bound. Signed-off-by: David Gibson --- flow.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/flow.c b/flow.c index 3fcdd9f2..602fea79 100644 --- a/flow.c +++ b/flow.c @@ -53,28 +53,28 @@ const uint8_t flow_proto[] = { static_assert(ARRAY_SIZE(flow_proto) == FLOW_NUM_TYPES, "flow_proto[] doesn't match enum flow_type"); -#define foreach_flow(flow, bound) \ - for ((flow) = flowtab; FLOW_IDX(flow) < (bound); (flow)++) \ +#define foreach_flow(flow) \ + for ((flow) = flowtab; FLOW_IDX(flow) < FLOW_MAX; (flow)++) \ if ((flow)->f.state == FLOW_STATE_FREE) \ (flow) += (flow)->free.n - 1; \ else -#define foreach_active_flow(flow, bound) \ - foreach_flow((flow), (bound)) \ +#define foreach_active_flow(flow) \ + foreach_flow((flow)) \ if ((flow)->f.state != FLOW_STATE_ACTIVE) \ /* NOLINTNEXTLINE(bugprone-branch-clone) */ \ continue; \ else -#define foreach_tcp_flow(flow, bound) \ - foreach_active_flow((flow), (bound)) \ +#define foreach_tcp_flow(flow) \ + foreach_active_flow((flow)) \ if ((flow)->f.type != FLOW_TCP) \ /* NOLINTNEXTLINE(bugprone-branch-clone) */ \ continue; \ else -#define foreach_established_tcp_flow(flow, bound) \ - foreach_tcp_flow((flow), (bound)) \ +#define foreach_established_tcp_flow(flow) \ + foreach_tcp_flow((flow)) \ if (!tcp_flow_is_established(&(flow)->tcp)) \ /* NOLINTNEXTLINE(bugprone-branch-clone) */ \ continue; \ @@ -907,21 +907,23 @@ void flow_defer_handler(const struct ctx *c, const struct timespec *now) /** * flow_migrate_source_rollback() - Disable repair mode, return failure * @c: Execution context - * @max_flow: Maximum index of affected flows + * @bound: No need to roll back flow indices >= @bound * @ret: Negative error code * * Return: @ret */ -static int flow_migrate_source_rollback(struct ctx *c, unsigned max_flow, - int ret) +static int flow_migrate_source_rollback(struct ctx *c, unsigned bound, int ret) { union flow *flow; debug("...roll back migration"); - foreach_established_tcp_flow(flow, max_flow) + foreach_established_tcp_flow(flow) { + if (FLOW_IDX(flow) >= bound) + break; if (tcp_flow_repair_off(c, &flow->tcp)) die("Failed to roll back TCP_REPAIR mode"); + } if (repair_flush(c)) die("Failed to roll back TCP_REPAIR mode"); @@ -941,7 +943,7 @@ static int flow_migrate_repair_all(struct ctx *c, bool enable) union flow *flow; int rc; - foreach_established_tcp_flow(flow, FLOW_MAX) { + foreach_established_tcp_flow(flow) { if (enable) rc = tcp_flow_repair_on(c, &flow->tcp); else @@ -1005,7 +1007,7 @@ int flow_migrate_source(struct ctx *c, const struct migrate_stage *stage, (void)c; (void)stage; - foreach_established_tcp_flow(flow, FLOW_MAX) + foreach_established_tcp_flow(flow) count++; count = htonl(count); @@ -1024,7 +1026,7 @@ int flow_migrate_source(struct ctx *c, const struct migrate_stage *stage, * stream might now be inconsistent, and we might have closed listening * TCP sockets, so just terminate. */ - foreach_established_tcp_flow(flow, FLOW_MAX) { + foreach_established_tcp_flow(flow) { rc = tcp_flow_migrate_source(fd, &flow->tcp); if (rc) { err("Can't send data, flow %u: %s", FLOW_IDX(flow), @@ -1051,7 +1053,7 @@ int flow_migrate_source(struct ctx *c, const struct migrate_stage *stage, * failures but not if the stream might be inconsistent (reported here * as EIO). */ - foreach_established_tcp_flow(flow, FLOW_MAX) { + foreach_established_tcp_flow(flow) { rc = tcp_flow_migrate_source_ext(fd, &flow->tcp); if (rc) { err("Extended data for flow %u: %s", FLOW_IDX(flow), -- 2.48.1