aboutsummaryrefslogtreecommitdiff
path: root/lib/cfm.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-06-18 16:31:43 -0700
committerEthan Jackson <ethan@nicira.com>2013-06-27 18:23:39 -0700
commit8e9a73fa94560a175a211264c07c3519615edaf7 (patch)
tree69a1613a474bf43640589fe506db362fd8aae479 /lib/cfm.c
parent2be0b371712ddf1fc2aaac81672b2196b6df891f (diff)
cfm: Reference count 'struct cfm'.
Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/cfm.c')
-rw-r--r--lib/cfm.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/cfm.c b/lib/cfm.c
index 1c98ed8b..06415fca 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -125,6 +125,8 @@ struct cfm {
int health_interval; /* Number of fault_intervals since health was
recomputed. */
long long int last_tx; /* Last CCM transmission time. */
+
+ int ref_cnt;
};
/* Remote MPs represent foreign network entities that are configured to have
@@ -318,11 +320,12 @@ cfm_create(const struct netdev *netdev)
cfm->fault_override = -1;
cfm->health = -1;
cfm->last_tx = 0;
+ cfm->ref_cnt = 1;
return cfm;
}
void
-cfm_destroy(struct cfm *cfm)
+cfm_unref(struct cfm *cfm)
{
struct remote_mp *rmp, *rmp_next;
@@ -330,6 +333,11 @@ cfm_destroy(struct cfm *cfm)
return;
}
+ ovs_assert(cfm->ref_cnt);
+ if (--cfm->ref_cnt) {
+ return;
+ }
+
HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) {
hmap_remove(&cfm->remote_mps, &rmp->node);
free(rmp);
@@ -342,6 +350,17 @@ cfm_destroy(struct cfm *cfm)
free(cfm);
}
+struct cfm *
+cfm_ref(const struct cfm *cfm_)
+{
+ struct cfm *cfm = CONST_CAST(struct cfm *, cfm_);
+ if (cfm) {
+ ovs_assert(cfm->ref_cnt > 0);
+ cfm->ref_cnt++;
+ }
+ return cfm;
+}
+
/* Should be run periodically to update fault statistics messages. */
void
cfm_run(struct cfm *cfm)