These two loops were updating 'localvif_to_ports' to be the same as
'new_localvif_to_ports' and setting physical_map_changed if there had been
any differences.  This is more work than necessary, so this commit
simplifies it.

Signed-off-by: Ben Pfaff <b...@ovn.org>
---
 ovn/controller/physical.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
index 0f1aa63ab4e7..457fc45414bd 100644
--- a/ovn/controller/physical.c
+++ b/ovn/controller/physical.c
@@ -753,6 +753,17 @@ consider_mc_group(enum mf_field_id mff_ovn_geneve,
     sset_destroy(&remote_chassis);
 }
 
+/* Replaces 'old' by 'new' (destroying 'new').  Returns true if 'old' and 'new'
+ * contained different data, false if they were the same. */
+static bool
+update_ofports(struct simap *old, struct simap *new)
+{
+    bool changed = !simap_equal(old, new);
+    simap_swap(old, new);
+    simap_destroy(new);
+    return changed;
+}
+
 void
 physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve,
              const struct ovsrec_bridge *br_int,
@@ -864,26 +875,8 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id 
mff_ovn_geneve,
     }
 
     /* Capture changed or removed openflow ports. */
-    struct simap_node *vif_name, *vif_name_next;
-    SIMAP_FOR_EACH_SAFE (vif_name, vif_name_next, &localvif_to_ofport) {
-        int newport;
-        if ((newport = simap_get(&new_localvif_to_ofport, vif_name->name))) {
-            if (newport != simap_get(&localvif_to_ofport, vif_name->name)) {
-                simap_put(&localvif_to_ofport, vif_name->name, newport);
-                physical_map_changed = true;
-            }
-        } else {
-            simap_find_and_delete(&localvif_to_ofport, vif_name->name);
-            physical_map_changed = true;
-        }
-    }
-    SIMAP_FOR_EACH (vif_name, &new_localvif_to_ofport) {
-        if (!simap_get(&localvif_to_ofport, vif_name->name)) {
-            simap_put(&localvif_to_ofport, vif_name->name,
-                      simap_get(&new_localvif_to_ofport, vif_name->name));
-            physical_map_changed = true;
-        }
-    }
+    physical_map_changed |= update_ofports(&localvif_to_ofport,
+                                           &new_localvif_to_ofport);
     if (physical_map_changed) {
         /* Reprocess logical flow table immediately. */
         poll_immediate_wake();
@@ -1041,6 +1034,5 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id 
mff_ovn_geneve,
 
     ofpbuf_uninit(&ofpacts);
 
-    simap_destroy(&new_localvif_to_ofport);
     simap_destroy(&new_tunnel_to_ofport);
 }
-- 
2.10.2

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to