bbaaef
From 7a4814d4a50a78a9434df7f55ca0491f4736c658 Mon Sep 17 00:00:00 2001
bbaaef
From: Numan Siddique <numans@ovn.org>
bbaaef
Date: Wed, 22 Jan 2020 19:02:18 +0530
bbaaef
Subject: [PATCH 4/4] ovn-controller: Remove ports from struct local_datapaths.
bbaaef
bbaaef
struct local_datapaths stores the array of port bindings for each datapath.
bbaaef
These ports are used only in the pinctrl module to check if a mac binding
bbaaef
has been learnt for the buffered packets.
bbaaef
bbaaef
MAC bindings are always learnt in the router pipeline and so
bbaaef
logical_port column of MAC_Binding table will always refer to a
bbaaef
logical router port. run_buffered_binding() of pinctrl module can use
bbaaef
the peer ports stored in the struct local_datapaths instead.
bbaaef
This would save many calls to mac_binding_lookup().
bbaaef
bbaaef
This patch doesn't store the array of port bindings for each local
bbaaef
datapath as it is not required at all.
bbaaef
bbaaef
Earlier, the peer ports were stored only for patch port bindings. But we can have
bbaaef
peer ports even for l3gateway port bindings. This patch now considers l3gateway
bbaaef
ports also for storing the peer ports in struct local_datapaths.
bbaaef
bbaaef
Acked-by: Han Zhou <hzhou@ovn.org>
bbaaef
Signed-off-by: Numan Siddique <numans@ovn.org>
bbaaef
bbaaef
(cherry-picked from upstream master commit 6c7d9f1ff6a50f695bfd13be3912f4e82c5045f5)
bbaaef
bbaaef
Change-Id: I30e984df51c1d8f81b74b863aaf37778fffc6b96
bbaaef
---
bbaaef
 ovn/controller/binding.c        | 26 +++++++++++++-------------
bbaaef
 ovn/controller/ovn-controller.c |  2 --
bbaaef
 ovn/controller/ovn-controller.h |  4 ----
bbaaef
 ovn/controller/pinctrl.c        | 11 +++++++++--
bbaaef
 4 files changed, 22 insertions(+), 21 deletions(-)
bbaaef
bbaaef
diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
bbaaef
index 1380a3e6e..d94e43893 100644
bbaaef
--- a/ovn/controller/binding.c
bbaaef
+++ b/ovn/controller/binding.c
bbaaef
@@ -146,7 +146,7 @@ add_local_datapath__(struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
bbaaef
     const struct sbrec_port_binding *pb;
bbaaef
     SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, target,
bbaaef
                                        sbrec_port_binding_by_datapath) {
bbaaef
-        if (!strcmp(pb->type, "patch")) {
bbaaef
+        if (!strcmp(pb->type, "patch") || !strcmp(pb->type, "l3gateway")) {
bbaaef
             const char *peer_name = smap_get(&pb->options, "peer");
bbaaef
             if (peer_name) {
bbaaef
                 const struct sbrec_port_binding *peer;
bbaaef
@@ -155,11 +155,18 @@ add_local_datapath__(struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
bbaaef
                                             peer_name);
bbaaef
 
bbaaef
                 if (peer && peer->datapath) {
bbaaef
-                    add_local_datapath__(sbrec_datapath_binding_by_key,
bbaaef
-                                         sbrec_port_binding_by_datapath,
bbaaef
-                                         sbrec_port_binding_by_name,
bbaaef
-                                         peer->datapath, false,
bbaaef
-                                         depth + 1, local_datapaths);
bbaaef
+                    if (!strcmp(pb->type, "patch")) {
bbaaef
+                        /* Add the datapath to local datapath only for patch
bbaaef
+                         * ports. For l3gateway ports, since gateway router
bbaaef
+                         * resides on one chassis, we don't need to add.
bbaaef
+                         * Otherwise, all other chassis might create patch
bbaaef
+                         * ports between br-int and the provider bridge. */
bbaaef
+                        add_local_datapath__(sbrec_datapath_binding_by_key,
bbaaef
+                                             sbrec_port_binding_by_datapath,
bbaaef
+                                             sbrec_port_binding_by_name,
bbaaef
+                                             peer->datapath, false,
bbaaef
+                                             depth + 1, local_datapaths);
bbaaef
+                    }
bbaaef
                     ld->n_peer_ports++;
bbaaef
                     if (ld->n_peer_ports > ld->n_allocated_peer_ports) {
bbaaef
                         ld->peer_ports =
bbaaef
@@ -172,13 +179,6 @@ add_local_datapath__(struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
bbaaef
                 }
bbaaef
             }
bbaaef
         }
bbaaef
-
bbaaef
-        ld->n_ports++;
bbaaef
-        if (ld->n_ports > ld->n_allocated_ports) {
bbaaef
-            ld->ports = x2nrealloc(ld->ports, &ld->n_allocated_ports,
bbaaef
-                                   sizeof *ld->ports);
bbaaef
-        }
bbaaef
-        ld->ports[ld->n_ports - 1] = pb;
bbaaef
     }
bbaaef
     sbrec_port_binding_index_destroy_row(target);
bbaaef
 }
bbaaef
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
bbaaef
index 8d7ea89c4..b80d6c0dc 100644
bbaaef
--- a/ovn/controller/ovn-controller.c
bbaaef
+++ b/ovn/controller/ovn-controller.c
bbaaef
@@ -929,7 +929,6 @@ en_runtime_data_cleanup(void *data)
bbaaef
     HMAP_FOR_EACH_SAFE (cur_node, next_node, hmap_node,
bbaaef
                         &rt_data->local_datapaths) {
bbaaef
         free(cur_node->peer_ports);
bbaaef
-        free(cur_node->ports);
bbaaef
         hmap_remove(&rt_data->local_datapaths, &cur_node->hmap_node);
bbaaef
         free(cur_node);
bbaaef
     }
bbaaef
@@ -953,7 +952,6 @@ en_runtime_data_run(struct engine_node *node, void *data)
bbaaef
         struct local_datapath *cur_node, *next_node;
bbaaef
         HMAP_FOR_EACH_SAFE (cur_node, next_node, hmap_node, local_datapaths) {
bbaaef
             free(cur_node->peer_ports);
bbaaef
-            free(cur_node->ports);
bbaaef
             hmap_remove(local_datapaths, &cur_node->hmap_node);
bbaaef
             free(cur_node);
bbaaef
         }
bbaaef
diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h
bbaaef
index 09ef4b632..8bff57c56 100644
bbaaef
--- a/ovn/controller/ovn-controller.h
bbaaef
+++ b/ovn/controller/ovn-controller.h
bbaaef
@@ -60,10 +60,6 @@ struct local_datapath {
bbaaef
      * hypervisor. */
bbaaef
     bool has_local_l3gateway;
bbaaef
 
bbaaef
-    const struct sbrec_port_binding **ports;
bbaaef
-    size_t n_ports;
bbaaef
-    size_t n_allocated_ports;
bbaaef
-
bbaaef
     struct {
bbaaef
         const struct sbrec_port_binding *local;
bbaaef
         const struct sbrec_port_binding *remote;
bbaaef
diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
bbaaef
index 5636fc1e0..800bde7e7 100644
bbaaef
--- a/ovn/controller/pinctrl.c
bbaaef
+++ b/ovn/controller/pinctrl.c
bbaaef
@@ -2973,10 +2973,17 @@ run_buffered_binding(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip,
bbaaef
     bool notify = false;
bbaaef
 
bbaaef
     HMAP_FOR_EACH (ld, hmap_node, local_datapaths) {
bbaaef
+        /* MAC_Binding.logical_port will always belong to a
bbaaef
+         * a router datapath. Hence we can skip logical switch
bbaaef
+         * datapaths.
bbaaef
+         * */
bbaaef
+        if (datapath_is_switch(ld->datapath)) {
bbaaef
+            continue;
bbaaef
+        }
bbaaef
 
bbaaef
-        for (size_t i = 0; i < ld->n_ports; i++) {
bbaaef
+        for (size_t i = 0; i < ld->n_peer_ports; i++) {
bbaaef
 
bbaaef
-            const struct sbrec_port_binding *pb = ld->ports[i];
bbaaef
+            const struct sbrec_port_binding *pb = ld->peer_ports[i].local;
bbaaef
             struct buffered_packets *cur_qp, *next_qp;
bbaaef
             HMAP_FOR_EACH_SAFE (cur_qp, next_qp, hmap_node,
bbaaef
                                 &buffered_packets_map) {
bbaaef
-- 
bbaaef
2.26.2
bbaaef