From patchwork Thu Feb 18 08:50:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1441581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dh7jg2SJSz9sRf for ; Thu, 18 Feb 2021 19:51:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 94E8F8647E; Thu, 18 Feb 2021 08:51:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qthDaDycFAbW; Thu, 18 Feb 2021 08:51:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id BA5E3861FE; Thu, 18 Feb 2021 08:51:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8D131C001B; Thu, 18 Feb 2021 08:51:09 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 11745C000D for ; Thu, 18 Feb 2021 08:51:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id F26BF86D6F for ; Thu, 18 Feb 2021 08:51:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rXLik1RBOyth for ; Thu, 18 Feb 2021 08:51:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from frode-threadripper.home (ti0189a330-0925.bb.online.no [88.88.218.161]) by whitealder.osuosl.org (Postfix) with ESMTP id 4402286D09 for ; Thu, 18 Feb 2021 08:51:02 +0000 (UTC) From: Frode Nordahl To: dev@openvswitch.org Date: Thu, 18 Feb 2021 09:50:44 +0100 Message-Id: <3f96d7ccbda5d47ef4225cce086f0487b053fa23.1613636533.git.frode.nordahl@canonical.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn branch-20.03 08/16] ofctrl.c: Avoid repeatedly linking an installed flow and a desired flow. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Han Zhou In update_installed_flows_by_compare() there are two loops. The first loop iterates the installed flows and find its peer in desired flows to: 1. uninstall flows that are not needed anymore 2. update flows if needed At the same time, it links the desired flow found for the installed flow which also set the desired flow as the current active installed flow. The second loop iterates the desired flows and find its peer in installed flows to install missing flows. At the same time it will detect if there are conflict desired flows matching same installed flow then just link them. However, currently in the second loop, it blindly link the desired flows to the installed flows, without checking if it is already linked in the first loop. Lucky enough, this won't cause any real problem so far, because when there are conflict flows, the one found in the first loop will be set as active in the installed_flow, and in the function link_installed_to_desired() checks if it is already the active desired flow it just does nothing but return. However, the check in the link_installed_to_desired() is confusing because a desired_flow may be linked to the installed_flow already but not the active flow, and the check is insufficient. It should be rather an assertion and let the caller ensure that a pair of desired_flow and installed_flow is never linked twice. For the above reason, this patch does the following changes: 1. Removes the check in link_installed_to_desired() and convert it to an assert. 2. Before calling link_installed_to_desired() in the above mentioned loop, check if the desired flow is already installed. Acked-by: Dumitru Ceara Signed-off-by: Han Zhou (cherry picked from commit 7cab7bd1268ba67429954da4f73de91090acf779) Signed-off-by: Frode Nordahl --- controller/ofctrl.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/controller/ofctrl.c b/controller/ofctrl.c index 41495c41f..70ec3e82b 100644 --- a/controller/ofctrl.c +++ b/controller/ofctrl.c @@ -806,13 +806,18 @@ desired_flow_set_active(struct desired_flow *d) d->installed_flow->desired_flow = d; } +/* Adds the desired flow to the list of desired flows that have same match + * conditions as the installed flow. + * + * If the newly added desired flow is the first one in the list, it is also set + * as the active one. + * + * It is caller's responsibility to make sure the link between the pair didn't + * exist before. */ static void link_installed_to_desired(struct installed_flow *i, struct desired_flow *d) { - if (i->desired_flow == d) { - return; - } - + ovs_assert(i->desired_flow != d); if (ovs_list_is_empty(&i->desired_refs)) { ovs_assert(!i->desired_flow); i->desired_flow = d; @@ -1644,8 +1649,12 @@ update_installed_flows_by_compare(struct ovn_desired_flow_table *flow_table, /* Copy 'd' from 'flow_table' to installed_flows. */ i = installed_flow_dup(d); hmap_insert(&installed_flows, &i->match_hmap_node, i->flow.hash); + link_installed_to_desired(i, d); + } else if (!d->installed_flow) { + /* This is a desired_flow that conflicts with one installed + * previously but not linked yet. */ + link_installed_to_desired(i, d); } - link_installed_to_desired(i, d); } }