Skip to content

Commit

Permalink
Change tracking structures to use struct uuids
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
jayhawk87 authored and blp committed Jul 3, 2016
1 parent fa313a8 commit 8e9f1c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
10 changes: 5 additions & 5 deletions ovn/controller/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down
21 changes: 12 additions & 9 deletions ovn/controller/encaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions ovn/controller/lport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
};

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ovn/controller/ovn-controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 8e9f1c1

Please sign in to comment.