lacp: Reference count 'struct lacp'.
authorEthan Jackson <ethan@nicira.com>
Tue, 18 Jun 2013 23:44:23 +0000 (16:44 -0700)
committerEthan Jackson <ethan@nicira.com>
Fri, 28 Jun 2013 01:23:39 +0000 (18:23 -0700)
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/lacp.c
lib/lacp.h
ofproto/ofproto-dpif.c

index 8bc115d..9daca3b 100644 (file)
@@ -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) {
index 399b39e..89b0e0a 100644 (file)
@@ -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 *);
index 4a6852b..a48da13 100644 (file)
@@ -2245,7 +2245,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);
 }
@@ -2309,7 +2309,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;
     }