[ovs-dev] [PATCH v21 3/8] Change tracking structures to use struct uuids

Ryan Moats rmoats at us.ibm.com
Sun Jul 3 15:35:28 UTC 2016


In encaps.c, binding.c, and lport.c incremental processing
is aided by tracking entries by their ovsdb row uuids.
The original patch sets used pointers, which might lead
to errors if the ovsdb row uuid memory is released.  So,
use actual structures to hold the values instead.

Signed-off-by: Ryan Moats <rmoats at us.ibm.com>
---
 ovn/controller/binding.c        | 10 +++++-----
 ovn/controller/encaps.c         | 21 ++++++++++++---------
 ovn/controller/lport.c          | 12 ++++++------
 ovn/controller/ovn-controller.h |  2 +-
 4 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
index 8b439a6..e10c1f0 100644
--- a/ovn/controller/binding.c
+++ b/ovn/controller/binding.c
@@ -118,7 +118,7 @@ local_datapath_lookup_by_uuid(struct hmap *hmap_p, const struct uuid *uuid)
 {
     struct local_datapath *ld;
     HMAP_FOR_EACH_WITH_HASH(ld, uuid_hmap_node, uuid_hash(uuid), hmap_p) {
-        if (uuid_equals(ld->uuid, uuid)) {
+        if (uuid_equals(&ld->uuid, uuid)) {
             return ld;
         }
     }
@@ -169,7 +169,7 @@ add_local_datapath(struct hmap *local_datapaths,
 
     struct local_datapath *ld = xzalloc(sizeof *ld);
     ld->logical_port = xstrdup(binding_rec->logical_port);
-    ld->uuid = &binding_rec->header_.uuid;
+    memcpy(&ld->uuid, &binding_rec->header_.uuid, sizeof ld->uuid);
     hmap_insert(local_datapaths, &ld->hmap_node,
                 binding_rec->datapath->tunnel_key);
     hmap_insert(&local_datapaths_by_uuid, &ld->uuid_hmap_node,
@@ -285,14 +285,14 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
             consider_local_datapath(ctx, &lports, chassis_rec, binding_rec,
                                     local_datapaths);
             struct local_datapath *ld = xzalloc(sizeof *ld);
-            ld->uuid = &binding_rec->header_.uuid;
+            memcpy(&ld->uuid, &binding_rec->header_.uuid, sizeof ld->uuid);
             hmap_insert(&keep_local_datapath_by_uuid, &ld->uuid_hmap_node,
-                        uuid_hash(ld->uuid));
+                        uuid_hash(&ld->uuid));
         }
         struct local_datapath *old_ld, *next;
         HMAP_FOR_EACH_SAFE (old_ld, next, hmap_node, local_datapaths) {
             if (!local_datapath_lookup_by_uuid(&keep_local_datapath_by_uuid,
-                                               old_ld->uuid)) {
+                                               &old_ld->uuid)) {
                 remove_local_datapath(local_datapaths, old_ld);
             }
         }
diff --git a/ovn/controller/encaps.c b/ovn/controller/encaps.c
index 18268a6..6cf60ff 100644
--- a/ovn/controller/encaps.c
+++ b/ovn/controller/encaps.c
@@ -74,7 +74,7 @@ static bool process_full_encaps = false;
 struct port_hash_node {
     struct hmap_node node;
     struct hmap_node uuid_node;
-    const struct uuid *uuid;
+    struct uuid uuid;
     const struct ovsrec_port *port;
     const struct ovsrec_bridge *bridge;
 };
@@ -131,7 +131,7 @@ port_lookup_by_uuid(struct hmap *hmap_p, const struct uuid *uuid)
     struct port_hash_node *answer;
     HMAP_FOR_EACH_WITH_HASH (answer, uuid_node, uuid_hash(uuid),
                              hmap_p) {
-        if (uuid_equals(uuid, answer->uuid)) {
+        if (uuid_equals(uuid, &answer->uuid)) {
             return answer;
         }
     }
@@ -186,11 +186,12 @@ tunnel_add(const struct sbrec_chassis *chassis_rec,
             && !strcmp(encap->type, iface->type)
             && !strcmp(encap->ip, ip)) {
 
-            hash_node->uuid = &chassis_rec->header_.uuid;
+            memcpy(&hash_node->uuid, &chassis_rec->header_.uuid,
+                   sizeof hash_node->uuid);
             if (!port_lookup_by_uuid(&tc.tunnel_hmap_by_uuid,
-                                     hash_node->uuid)) {
+                                     &hash_node->uuid)) {
                 hmap_insert(&tc.tunnel_hmap_by_uuid, &hash_node->uuid_node,
-                            uuid_hash(hash_node->uuid));
+                            uuid_hash(&hash_node->uuid));
             }
             return;
         }
@@ -380,17 +381,19 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
         SBREC_CHASSIS_FOR_EACH (chassis_rec, ctx->ovnsb_idl) {
             check_and_add_tunnel(chassis_rec, chassis_id);
             struct port_hash_node *hash_node = xzalloc(sizeof *hash_node);
-            hash_node->uuid = &chassis_rec->header_.uuid;
+            memcpy(&hash_node->uuid, &chassis_rec->header_.uuid,
+                   sizeof hash_node->uuid);
             hmap_insert(&keep_tunnel_hmap_by_uuid, &hash_node->uuid_node,
-                        uuid_hash(hash_node->uuid));
+                        uuid_hash(&hash_node->uuid));
         }
 
         /* 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)) {
+            if (!uuid_is_zero(&old_hash_node->uuid)
+                && !port_lookup_by_uuid(&keep_tunnel_hmap_by_uuid,
+                                        &old_hash_node->uuid)) {
                 bridge_delete_port(old_hash_node->bridge, old_hash_node->port);
                 sset_find_and_delete(&tc.port_names,
                                      old_hash_node->port->name);
diff --git a/ovn/controller/lport.c b/ovn/controller/lport.c
index a5e9ad3..080b27f 100644
--- a/ovn/controller/lport.c
+++ b/ovn/controller/lport.c
@@ -28,7 +28,7 @@ struct lport {
     struct hmap_node name_node;  /* Index by name. */
     struct hmap_node key_node;   /* Index by (dp_key, port_key). */
     struct hmap_node uuid_node;  /* Index by row uuid. */
-    const struct uuid *uuid;
+    struct uuid uuid;
     const struct sbrec_port_binding *pb;
 };
 
@@ -91,7 +91,7 @@ consider_lport_index(struct lport_index *lports,
                 hash_int(pb->tunnel_key, pb->datapath->tunnel_key));
     hmap_insert(&lports->by_uuid, &p->uuid_node,
                 uuid_hash(&pb->header_.uuid));
-    p->uuid = &pb->header_.uuid;
+    memcpy(&p->uuid, &pb->header_.uuid, sizeof p->uuid);
     p->pb = pb;
 }
 
@@ -148,7 +148,7 @@ lport_lookup_by_uuid(const struct lport_index *lports,
     const struct lport *lport;
     HMAP_FOR_EACH_WITH_HASH (lport, uuid_node, uuid_hash(uuid),
                              &lports->by_uuid) {
-        if (uuid_equals(uuid, lport->uuid)) {
+        if (uuid_equals(uuid, &lport->uuid)) {
             return lport;
         }
     }
@@ -173,7 +173,7 @@ lport_lookup_by_key(const struct lport_index *lports,
 struct mcgroup {
     struct hmap_node dp_name_node; /* Index by (logical datapath, name). */
     struct hmap_node uuid_node;    /* Index by insert uuid. */
-    const struct uuid *uuid;
+    struct uuid uuid;
     const struct sbrec_multicast_group *mg;
 };
 
@@ -229,7 +229,7 @@ consider_mcgroup_index(struct mcgroup_index *mcgroups,
                 hash_string(mg->name, uuid_hash(dp_uuid)));
     hmap_insert(&mcgroups->by_uuid, &m->uuid_node,
                 uuid_hash(&mg->header_.uuid));
-    m->uuid = &mg->header_.uuid;
+    memcpy(&m->uuid, &mg->header_.uuid, sizeof m->uuid);
     m->mg = mg;
 }
 
@@ -269,7 +269,7 @@ mcgroup_lookup_by_uuid(const struct mcgroup_index *mcgroups,
     const struct mcgroup *mcgroup;
     HMAP_FOR_EACH_WITH_HASH (mcgroup, uuid_node, uuid_hash(uuid),
                              &mcgroups->by_uuid) {
-        if (uuid_equals(mcgroup->uuid, uuid)) {
+        if (uuid_equals(&mcgroup->uuid, uuid)) {
             return mcgroup;
         }
     }
diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h
index f0c4e63..6a021a0 100644
--- a/ovn/controller/ovn-controller.h
+++ b/ovn/controller/ovn-controller.h
@@ -39,7 +39,7 @@ struct controller_ctx {
 struct local_datapath {
     struct hmap_node hmap_node;
     struct hmap_node uuid_hmap_node;
-    const struct uuid *uuid;
+    struct uuid uuid;
     char *logical_port;
     const struct sbrec_port_binding *localnet_port;
 };
-- 
2.7.4 (Apple Git-66)




More information about the dev mailing list