From: Ethan Jackson Date: Tue, 18 Jun 2013 23:31:43 +0000 (-0700) Subject: cfm: Reference count 'struct cfm'. X-Git-Tag: sliver-openvswitch-1.10.90-3~6^2~37 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=8e9a73fa94560a175a211264c07c3519615edaf7 cfm: Reference count 'struct cfm'. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- diff --git a/lib/cfm.c b/lib/cfm.c index 1c98ed8b5..06415fca5 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 15a015486..8002f3e06 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 85e537633..4a6852b1a 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -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; }