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

index 68ac068..1136315 100644 (file)
@@ -108,6 +108,8 @@ struct bond {
      * where we can't otherwise provide revalidation feedback to the client.
      * That's only unixctl commands now; I hope no other cases will arise. */
     struct tag_set unixctl_tags;
+
+    int ref_cnt;
 };
 
 static struct hmap all_bonds = HMAP_INITIALIZER(&all_bonds);
@@ -179,6 +181,7 @@ bond_create(const struct bond_settings *s)
     hmap_init(&bond->slaves);
     bond->no_slaves_tag = tag_create_random();
     bond->next_fake_iface_update = LLONG_MAX;
+    bond->ref_cnt = 1;
 
     bond_reconfigure(bond, s);
 
@@ -187,9 +190,19 @@ bond_create(const struct bond_settings *s)
     return bond;
 }
 
+struct bond *
+bond_ref(const struct bond *bond_)
+{
+    struct bond *bond = CONST_CAST(struct bond *, bond_);
+
+    ovs_assert(bond->ref_cnt > 0);
+    bond->ref_cnt++;
+    return bond;
+}
+
 /* Frees 'bond'. */
 void
-bond_destroy(struct bond *bond)
+bond_unref(struct bond *bond)
 {
     struct bond_slave *slave, *next_slave;
 
@@ -197,6 +210,11 @@ bond_destroy(struct bond *bond)
         return;
     }
 
+    ovs_assert(bond->ref_cnt > 0);
+    if (--bond->ref_cnt) {
+        return;
+    }
+
     hmap_remove(&all_bonds, &bond->hmap_node);
 
     HMAP_FOR_EACH_SAFE (slave, next_slave, hmap_node, &bond->slaves) {
index 306cf42..7190935 100644 (file)
@@ -61,7 +61,8 @@ void bond_init(void);
 
 /* Basics. */
 struct bond *bond_create(const struct bond_settings *);
-void bond_destroy(struct bond *);
+void bond_unref(struct bond *);
+struct bond *bond_ref(const struct bond *);
 
 bool bond_reconfigure(struct bond *, const struct bond_settings *);
 void bond_slave_register(struct bond *, void *slave_, struct netdev *);
index a48da13..87b44f2 100644 (file)
@@ -2246,7 +2246,7 @@ bundle_destroy(struct ofbundle *bundle)
     free(bundle->name);
     free(bundle->trunks);
     lacp_unref(bundle->lacp);
-    bond_destroy(bundle->bond);
+    bond_unref(bundle->bond);
     free(bundle);
 }
 
@@ -2420,7 +2420,7 @@ bundle_set(struct ofproto *ofproto_, void *aux,
             bond_slave_register(bundle->bond, port, port->up.netdev);
         }
     } else {
-        bond_destroy(bundle->bond);
+        bond_unref(bundle->bond);
         bundle->bond = NULL;
     }
 
@@ -2444,7 +2444,7 @@ bundle_remove(struct ofport *port_)
         if (list_is_empty(&bundle->ports)) {
             bundle_destroy(bundle);
         } else if (list_is_short(&bundle->ports)) {
-            bond_destroy(bundle->bond);
+            bond_unref(bundle->bond);
             bundle->bond = NULL;
         }
     }