aboutsummaryrefslogtreecommitdiff
path: root/lib/bond.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-06-18 16:48:31 -0700
committerEthan Jackson <ethan@nicira.com>2013-06-27 18:23:40 -0700
commit03366a2d585a6917d7d94c79073e1e615d8d8025 (patch)
tree5d9023448751cf4fb3d5abae7bc829fd7d084540 /lib/bond.c
parent91779071abffe3b6d6243378ff06a179bf39d69a (diff)
bond: Reference count 'struct bond'.
Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/bond.c')
-rw-r--r--lib/bond.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/bond.c b/lib/bond.c
index 68ac0688..11363152 100644
--- a/lib/bond.c
+++ b/lib/bond.c
@@ -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) {