Skip to content

Commit

Permalink
cfm: Reference count 'struct cfm'.
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Jackson <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
ejj committed Jun 28, 2013
1 parent 2be0b37 commit 8e9a73f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion lib/cfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -318,18 +320,24 @@ 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;

if (!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);
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/cfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion ofproto/ofproto-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8e9a73f

Please sign in to comment.