[ovs-dev] [xlate v1 03/18] cfm: Reference count 'struct cfm'.

Ethan Jackson ethan at nicira.com
Tue Jun 25 01:59:17 UTC 2013


Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 lib/cfm.c              |   21 ++++++++++++++++++++-
 lib/cfm.h              |    3 ++-
 ofproto/ofproto-dpif.c |    2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/cfm.c b/lib/cfm.c
index 67c2002..9116cba 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)
diff --git a/lib/cfm.h b/lib/cfm.h
index 15a0154..8002f3e 100644
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -66,7 +66,8 @@ struct cfm_settings {
 
 void cfm_init(void);
 struct cfm *cfm_create(const struct netdev *);
-void cfm_destroy(struct cfm *);
+struct cfm *cfm_ref(const struct cfm *);
+void cfm_unref(struct cfm *);
 void cfm_run(struct cfm *);
 bool cfm_should_send_ccm(struct cfm *);
 void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[6]);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 67738b0..8a588e1 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1669,7 +1669,7 @@ set_cfm(struct ofport *ofport_, const struct cfm_settings *s)
 
         error = EINVAL;
     }
-    cfm_destroy(ofport->cfm);
+    cfm_unref(ofport->cfm);
     ofport->cfm = NULL;
     return error;
 }
-- 
1.7.9.5




More information about the dev mailing list