On Tue, Jun 07, 2016 at 01:52:50PM -0500, Ryan Moats wrote:
> As a side effect, tunnel context is persisted.
> 
> Signed-off-by: Ryan Moats <rmo...@us.ibm.com>

Thanks for the patch.  I folded in the following changes and applied
this to master.  Most of my changes are style or comments, but there is
a memory leak fix; please verify it.  Also, I renamed old_chassis_id to
just chassis_id, because I couldn't see what was "old" about the chassis
ID there.

--8<--------------------------cut here-------------------------->8--

diff --git a/ovn/controller/encaps.c b/ovn/controller/encaps.c
index 632973c..bd5650a 100644
--- a/ovn/controller/encaps.c
+++ b/ovn/controller/encaps.c
@@ -50,6 +50,8 @@ struct tunnel_ctx {
      * generated we remove them.  After generating all the rows, any
      * remaining in 'tunnel_hmap' must be deleted from the database. */
     struct hmap tunnel_hmap;
+
+    /* Only valid within the process_full_encaps case in encaps_run(). */
     struct hmap tunnel_hmap_by_uuid;
 
     /* Names of all ports in the bridge, to allow checking uniqueness when
@@ -275,7 +277,6 @@ check_and_add_tunnel(const struct sbrec_chassis 
*chassis_rec,
                      const char *chassis_id)
 {
     if (strcmp(chassis_rec->name, chassis_id)) {
-        /* Create tunnels to the other chassis. */
         const struct sbrec_encap *encap = preferred_encap(chassis_rec);
         if (!encap) {
             VLOG_INFO("No supported encaps for '%s'", chassis_rec->name);
@@ -288,10 +289,12 @@ check_and_add_tunnel(const struct sbrec_chassis 
*chassis_rec,
 }
 
 static void
-check_and_update_tunnel(const struct sbrec_chassis *chassis_rec) {
+check_and_update_tunnel(const struct sbrec_chassis *chassis_rec)
+{
     struct port_hash_node *port_node;
-    if ((port_node = port_lookup_by_uuid(&tc.tunnel_hmap_by_uuid,
-                                        &chassis_rec->header_.uuid))) {
+    port_node = port_lookup_by_uuid(&tc.tunnel_hmap_by_uuid,
+                                    &chassis_rec->header_.uuid);
+    if (port_node) {
         const struct sbrec_encap *encap = preferred_encap(chassis_rec);
         const struct ovsrec_port *port = port_node->port;
         const struct ovsrec_interface *iface = port->interfaces[0];
@@ -354,23 +357,22 @@ encaps_run(struct controller_ctx *ctx, const struct 
ovsrec_bridge *br_int,
 
             sset_add(&tc.port_names, port->name);
 
-            const char *old_chassis_id = smap_get(&port->external_ids,
-                                                  "ovn-chassis-id");
-            if (old_chassis_id) {
-                if (!port_lookup_by_port(port)) {
-                    struct port_hash_node *hash_node =
-                        xzalloc(sizeof *hash_node);
-                    hash_node->bridge = br;
-                    hash_node->port = port;
-                    hmap_insert(&tc.tunnel_hmap, &hash_node->node,
-                                port_hash_rec(port));
-                    process_full_encaps = true;
-                }
+            const char *chassis_id = smap_get(&port->external_ids,
+                                              "ovn-chassis-id");
+            if (chassis_id && !port_lookup_by_port(port)) {
+                struct port_hash_node *hash_node =
+                    xzalloc(sizeof *hash_node);
+                hash_node->bridge = br;
+                hash_node->port = port;
+                hmap_insert(&tc.tunnel_hmap, &hash_node->node,
+                            port_hash_rec(port));
+                process_full_encaps = true;
             }
         }
     }
 
     if (process_full_encaps) {
+        /* Create tunnels to the other chassis. */
         struct hmap keep_tunnel_hmap_by_uuid =
             HMAP_INITIALIZER(&keep_tunnel_hmap_by_uuid);
         SBREC_CHASSIS_FOR_EACH (chassis_rec, ctx->ovnsb_idl) {
@@ -380,8 +382,11 @@ encaps_run(struct controller_ctx *ctx, const struct 
ovsrec_bridge *br_int,
             hmap_insert(&keep_tunnel_hmap_by_uuid, &hash_node->uuid_node,
                         uuid_hash(hash_node->uuid));
         }
-        struct port_hash_node *old_hash_node;
-        HMAP_FOR_EACH (old_hash_node, node, &tc.tunnel_hmap) {
+
+        /* Delete any tunnels that weren't recreated above. */
+        struct port_hash_node *old_hash_node, *next_hash_node;
+        HMAP_FOR_EACH_SAFE (old_hash_node, next_hash_node,
+                            node, &tc.tunnel_hmap) {
             if (!port_lookup_by_uuid(&keep_tunnel_hmap_by_uuid,
                                      old_hash_node->uuid)) {
                 bridge_delete_port(old_hash_node->bridge, old_hash_node->port);
@@ -390,6 +395,7 @@ encaps_run(struct controller_ctx *ctx, const struct 
ovsrec_bridge *br_int,
                 hmap_remove(&tc.tunnel_hmap, &old_hash_node->node);
                 hmap_remove(&tc.tunnel_hmap_by_uuid,
                             &old_hash_node->uuid_node);
+                free(old_hash_node);
             }
         }
         hmap_destroy(&keep_tunnel_hmap_by_uuid);
@@ -397,9 +403,9 @@ encaps_run(struct controller_ctx *ctx, const struct 
ovsrec_bridge *br_int,
     } else {
         SBREC_CHASSIS_FOR_EACH_TRACKED (chassis_rec, ctx->ovnsb_idl) {
             bool is_deleted = sbrec_chassis_row_get_seqno(chassis_rec,
-                OVSDB_IDL_CHANGE_DELETE) > 0;
+                                                          
OVSDB_IDL_CHANGE_DELETE) > 0;
             bool is_new = sbrec_chassis_row_get_seqno(chassis_rec,
-                OVSDB_IDL_CHANGE_MODIFY) == 0;
+                                                      OVSDB_IDL_CHANGE_MODIFY) 
== 0;
 
             if (is_deleted) {
                 /* Lookup the tunnel by row uuid and remove it. */
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to