Signed-off-by: Ethan Jackson <et...@nicira.com> --- lib/lacp.c | 23 +++++++++++++++++++++-- lib/lacp.h | 3 ++- ofproto/ofproto-dpif.c | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/lib/lacp.c b/lib/lacp.c index 8bc115d..9daca3b 100644 --- a/lib/lacp.c +++ b/lib/lacp.c @@ -100,6 +100,8 @@ struct lacp { bool fast; /* True if using fast probe interval. */ bool negotiated; /* True if LACP negotiations were successful. */ bool update; /* True if lacp_update() needs to be called. */ + + int ref_cnt; }; struct slave { @@ -197,14 +199,31 @@ lacp_create(void) lacp = xzalloc(sizeof *lacp); hmap_init(&lacp->slaves); list_push_back(&all_lacps, &lacp->node); + lacp->ref_cnt = 1; + return lacp; +} + +struct lacp * +lacp_ref(const struct lacp *lacp_) +{ + struct lacp *lacp = CONST_CAST(struct lacp *, lacp_); + if (lacp) { + ovs_assert(lacp->ref_cnt > 0); + lacp->ref_cnt++; + } return lacp; } /* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */ void -lacp_destroy(struct lacp *lacp) +lacp_unref(struct lacp *lacp) { - if (lacp) { + if (!lacp) { + return; + } + + ovs_assert(lacp->ref_cnt > 0); + if (!--lacp->ref_cnt) { struct slave *slave, *next; HMAP_FOR_EACH_SAFE (slave, next, node, &lacp->slaves) { diff --git a/lib/lacp.h b/lib/lacp.h index 399b39e..89b0e0a 100644 --- a/lib/lacp.h +++ b/lib/lacp.h @@ -39,7 +39,8 @@ struct lacp_settings { void lacp_init(void); struct lacp *lacp_create(void); -void lacp_destroy(struct lacp *); +void lacp_unref(struct lacp *); +struct lacp *lacp_ref(const struct lacp *); void lacp_configure(struct lacp *, const struct lacp_settings *); bool lacp_is_active(const struct lacp *); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 8a588e1..10735b2 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2211,7 +2211,7 @@ bundle_destroy(struct ofbundle *bundle) hmap_remove(&ofproto->bundles, &bundle->hmap_node); free(bundle->name); free(bundle->trunks); - lacp_destroy(bundle->lacp); + lacp_unref(bundle->lacp); bond_destroy(bundle->bond); free(bundle); } @@ -2272,7 +2272,7 @@ bundle_set(struct ofproto *ofproto_, void *aux, } lacp_configure(bundle->lacp, s->lacp); } else { - lacp_destroy(bundle->lacp); + lacp_unref(bundle->lacp); bundle->lacp = NULL; } -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev