cfm: Reference count 'struct cfm'.
authorEthan Jackson <ethan@nicira.com>
Tue, 18 Jun 2013 23:31:43 +0000 (16:31 -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/cfm.c
lib/cfm.h
ofproto/ofproto-dpif.c

index 1c98ed8..06415fc 100644 (file)
--- 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)
index 15a0154..8002f3e 100644 (file)
--- 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]);
index 85e5376..4a6852b 100644 (file)
@@ -1674,7 +1674,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;
 }