[ovs-dev] [PATCH ovn 3/6] binding.c: Create a new function consider_patch_port_for_local_datapaths.

Han Zhou hzhou at ovn.org
Fri Aug 13 22:55:31 UTC 2021


Move the logical of handling patch port changes for updating local_datapaths
to a separate function, which will be reused later. Also split the
switch-case for the 2 cases: LP_PATCH and LP_VTEP, because there are
more differences than common, to avoid the extra if-blocks.

Signed-off-by: Han Zhou <hzhou at ovn.org>
---
 controller/binding.c | 101 ++++++++++++++++++++++---------------------
 1 file changed, 52 insertions(+), 49 deletions(-)

diff --git a/controller/binding.c b/controller/binding.c
index aa032789c..355599dc9 100644
--- a/controller/binding.c
+++ b/controller/binding.c
@@ -2183,6 +2183,51 @@ handle_updated_vif_lport(const struct sbrec_port_binding *pb,
     return true;
 }
 
+static void
+consider_patch_port_for_local_datapaths(const struct sbrec_port_binding *pb,
+                                        struct binding_ctx_in *b_ctx_in,
+                                        struct binding_ctx_out *b_ctx_out)
+{
+    struct local_datapath *ld =
+        get_local_datapath(b_ctx_out->local_datapaths,
+                           pb->datapath->tunnel_key);
+
+    if (!ld) {
+        /* If 'ld' for this lport is not present, then check if
+         * there is a peer for this lport. If peer is present
+         * and peer's datapath is already in the local datapaths,
+         * then add this lport's datapath to the local_datapaths.
+         * */
+        const struct sbrec_port_binding *peer;
+        struct local_datapath *peer_ld = NULL;
+        peer = lport_get_peer(pb, b_ctx_in->sbrec_port_binding_by_name);
+        if (peer) {
+            peer_ld =
+                get_local_datapath(b_ctx_out->local_datapaths,
+                                   peer->datapath->tunnel_key);
+        }
+        if (peer_ld) {
+            add_local_datapath(
+                b_ctx_in->sbrec_datapath_binding_by_key,
+                b_ctx_in->sbrec_port_binding_by_datapath,
+                b_ctx_in->sbrec_port_binding_by_name,
+                pb->datapath,
+                b_ctx_out->local_datapaths,
+                b_ctx_out->tracked_dp_bindings);
+        }
+    } else {
+        /* Add the peer datapath to the local datapaths if it's
+         * not present yet.
+         */
+        add_local_datapath_peer_port(
+            pb, b_ctx_in->sbrec_datapath_binding_by_key,
+            b_ctx_in->sbrec_port_binding_by_datapath,
+            b_ctx_in->sbrec_port_binding_by_name,
+            ld, b_ctx_out->local_datapaths,
+            b_ctx_out->tracked_dp_bindings);
+    }
+}
+
 /* Returns true if the port binding changes resulted in local binding
  * updates, false otherwise.
  */
@@ -2340,10 +2385,6 @@ delete_done:
             }
         }
 
-        struct local_datapath *ld =
-            get_local_datapath(b_ctx_out->local_datapaths,
-                               pb->datapath->tunnel_key);
-
         switch (lport_type) {
         case LP_VIF:
         case LP_CONTAINER:
@@ -2357,53 +2398,15 @@ delete_done:
             break;
 
         case LP_PATCH:
-        case LP_VTEP:
             update_related_lport(pb, b_ctx_out);
-            if (lport_type ==  LP_PATCH) {
-                if (!ld) {
-                    /* If 'ld' for this lport is not present, then check if
-                     * there is a peer for this lport. If peer is present
-                     * and peer's datapath is already in the local datapaths,
-                     * then add this lport's datapath to the local_datapaths.
-                     * */
-                    const struct sbrec_port_binding *peer;
-                    struct local_datapath *peer_ld = NULL;
-                    peer =
-                        lport_get_peer(pb,
-                                       b_ctx_in->sbrec_port_binding_by_name);
-
-                    if (peer) {
-                        peer_ld =
-                            get_local_datapath(b_ctx_out->local_datapaths,
-                                               peer->datapath->tunnel_key);
-                    }
-                    if (peer_ld) {
-                        add_local_datapath(
-                            b_ctx_in->sbrec_datapath_binding_by_key,
-                            b_ctx_in->sbrec_port_binding_by_datapath,
-                            b_ctx_in->sbrec_port_binding_by_name,
-                            pb->datapath,
-                            b_ctx_out->local_datapaths,
-                            b_ctx_out->tracked_dp_bindings);
-                    }
-                } else {
-                    /* Add the peer datapath to the local datapaths if it's
-                     * not present yet.
-                     */
-                    add_local_datapath_peer_port(
-                        pb, b_ctx_in->sbrec_datapath_binding_by_key,
-                        b_ctx_in->sbrec_port_binding_by_datapath,
-                        b_ctx_in->sbrec_port_binding_by_name,
-                        ld, b_ctx_out->local_datapaths,
-                        b_ctx_out->tracked_dp_bindings);
-                }
-            }
+            consider_patch_port_for_local_datapaths(pb, b_ctx_in, b_ctx_out);
+            break;
 
-            if (lport_type == LP_VTEP) {
-                /* VTEP lports are claimed/released by ovn-controller-vteps.
-                 * We are not sure what changed. */
-                b_ctx_out->non_vif_ports_changed = true;
-            }
+        case LP_VTEP:
+            update_related_lport(pb, b_ctx_out);
+            /* VTEP lports are claimed/released by ovn-controller-vteps.
+             * We are not sure what changed. */
+            b_ctx_out->non_vif_ports_changed = true;
             break;
 
         case LP_L2GATEWAY:
-- 
2.30.2



More information about the dev mailing list