From patchwork Tue Feb 18 22:26:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1240405 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org 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 48Mb6n5YCTz9sRN for ; Wed, 19 Feb 2020 09:26:25 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 309AE8574F; Tue, 18 Feb 2020 22:26:24 +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 9f_LU6AE-tLK; Tue, 18 Feb 2020 22:26:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 38EEB851CC; Tue, 18 Feb 2020 22:26:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2AEBFC1D84; Tue, 18 Feb 2020 22:26:23 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 337F8C013E for ; Tue, 18 Feb 2020 22:26:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 30812877B1 for ; Tue, 18 Feb 2020 22:26:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wia8F+0uqb+u for ; Tue, 18 Feb 2020 22:26:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by hemlock.osuosl.org (Postfix) with ESMTPS id A0C7A87482 for ; Tue, 18 Feb 2020 22:26:19 +0000 (UTC) X-Originating-IP: 216.113.160.77 Received: from localhost.localdomain.localdomain (unknown [216.113.160.77]) (Authenticated sender: hzhou@ovn.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 19A30FF807; Tue, 18 Feb 2020 22:26:15 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Tue, 18 Feb 2020 14:26:05 -0800 Message-Id: <1582064765-98657-1-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn] ovn-controller: Avoid creating patch port for non-local datapaths. 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When external-ids:ovn-monitor-all is set to true, patch ports for non-local datapaths may be created, which is unnecessary and confusing. This patch avoids that by checking if a localnet port belongs to local datapaths before creating the patch port. It also moves patch_run() in mainloop after engine_run(), so that local_datapaths already reflects the up-to-date situation when patch_run() is called. Reported-by: Girish Moodalbail Signed-off-by: Han Zhou Acked-by: Dumitru Ceara --- controller/ovn-controller.c | 12 ++++++------ controller/patch.c | 16 +++++++++++++--- controller/patch.h | 3 ++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 4d245ca..d8e2a0e 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -2011,12 +2011,6 @@ main(int argc, char *argv[]) } if (chassis) { - patch_run(ovs_idl_txn, - ovsrec_bridge_table_get(ovs_idl_loop.idl), - ovsrec_open_vswitch_table_get(ovs_idl_loop.idl), - ovsrec_port_table_get(ovs_idl_loop.idl), - sbrec_port_binding_table_get(ovnsb_idl_loop.idl), - br_int, chassis); encaps_run(ovs_idl_txn, bridge_table, br_int, sbrec_chassis_table_get(ovnsb_idl_loop.idl), @@ -2079,6 +2073,12 @@ main(int argc, char *argv[]) } runtime_data = engine_get_data(&en_runtime_data); if (runtime_data) { + patch_run(ovs_idl_txn, + ovsrec_bridge_table_get(ovs_idl_loop.idl), + ovsrec_open_vswitch_table_get(ovs_idl_loop.idl), + ovsrec_port_table_get(ovs_idl_loop.idl), + sbrec_port_binding_table_get(ovnsb_idl_loop.idl), + br_int, chassis, &runtime_data->local_datapaths); pinctrl_run(ovnsb_idl_txn, sbrec_datapath_binding_by_key, sbrec_port_binding_by_datapath, diff --git a/controller/patch.c b/controller/patch.c index f2053de..349faae 100644 --- a/controller/patch.c +++ b/controller/patch.c @@ -181,7 +181,8 @@ add_bridge_mappings(struct ovsdb_idl_txn *ovs_idl_txn, const struct sbrec_port_binding_table *port_binding_table, const struct ovsrec_bridge *br_int, struct shash *existing_ports, - const struct sbrec_chassis *chassis) + const struct sbrec_chassis *chassis, + const struct hmap *local_datapaths) { /* Get ovn-bridge-mappings. */ struct shash bridge_mappings = SHASH_INITIALIZER(&bridge_mappings); @@ -190,6 +191,13 @@ add_bridge_mappings(struct ovsdb_idl_txn *ovs_idl_txn, const struct sbrec_port_binding *binding; SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) { + /* When ovn-monitor-all is true, there can be port-bindings + * on datapaths that are not related to this chassis. Ignore them. */ + if (!get_local_datapath(local_datapaths, + binding->datapath->tunnel_key)) { + continue; + } + const char *patch_port_id; if (!strcmp(binding->type, "localnet")) { patch_port_id = "ovn-localnet-port"; @@ -242,7 +250,8 @@ patch_run(struct ovsdb_idl_txn *ovs_idl_txn, const struct ovsrec_port_table *port_table, const struct sbrec_port_binding_table *port_binding_table, const struct ovsrec_bridge *br_int, - const struct sbrec_chassis *chassis) + const struct sbrec_chassis *chassis, + const struct hmap *local_datapaths) { if (!ovs_idl_txn) { return; @@ -269,7 +278,8 @@ patch_run(struct ovsdb_idl_txn *ovs_idl_txn, * 'existing_ports' any patch ports that do exist in the database and * should be there. */ add_bridge_mappings(ovs_idl_txn, bridge_table, ovs_table, - port_binding_table, br_int, &existing_ports, chassis); + port_binding_table, br_int, &existing_ports, chassis, + local_datapaths); /* Now 'existing_ports' only still contains patch ports that exist in the * database but shouldn't. Delete them from the database. */ diff --git a/controller/patch.h b/controller/patch.h index 49b0b2e..81a43bc 100644 --- a/controller/patch.h +++ b/controller/patch.h @@ -41,6 +41,7 @@ void patch_run(struct ovsdb_idl_txn *ovs_idl_txn, const struct ovsrec_port_table *, const struct sbrec_port_binding_table *, const struct ovsrec_bridge *br_int, - const struct sbrec_chassis *); + const struct sbrec_chassis *, + const struct hmap *local_datapaths); #endif /* controller/patch.h */