summaryrefslogtreecommitdiff
path: root/ofproto/netflow.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-12-07 14:38:14 -0800
committerEthan Jackson <ethan@nicira.com>2013-12-12 17:14:31 -0800
commit936604c009caf1587df9c1aec6c4c6e3020052b3 (patch)
treed93b3c27b67890bc4c003231bbb22562bb6add2e /ofproto/netflow.c
parent8e407f2744c0fad4fe4785c7be5849eb6ad1f903 (diff)
downloadopenvswitch-936604c009caf1587df9c1aec6c4c6e3020052b3.tar.gz
ofproto: New function netflow_exists().
Useful in future patches. Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'ofproto/netflow.c')
-rw-r--r--ofproto/netflow.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/ofproto/netflow.c b/ofproto/netflow.c
index c91ecf068..7b9e0e6c2 100644
--- a/ofproto/netflow.c
+++ b/ofproto/netflow.c
@@ -79,6 +79,7 @@ struct netflow_flow {
};
static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
+static atomic_uint netflow_count = ATOMIC_VAR_INIT(0);
static struct netflow_flow *netflow_flow_lookup(const struct netflow *,
const struct flow *)
@@ -396,6 +397,8 @@ struct netflow *
netflow_create(void)
{
struct netflow *nf = xzalloc(sizeof *nf);
+ int junk;
+
nf->engine_type = 0;
nf->engine_id = 0;
nf->boot_time = time_msec();
@@ -405,6 +408,7 @@ netflow_create(void)
hmap_init(&nf->flows);
atomic_init(&nf->ref_cnt, 1);
ofpbuf_init(&nf->packet, 1500);
+ atomic_add(&netflow_count, 1, &junk);
return nf;
}
@@ -432,11 +436,22 @@ netflow_unref(struct netflow *nf)
atomic_sub(&nf->ref_cnt, 1, &orig);
ovs_assert(orig > 0);
if (orig == 1) {
- ofpbuf_uninit(&nf->packet);
+ atomic_sub(&netflow_count, 1, &orig);
collectors_destroy(nf->collectors);
+ ofpbuf_uninit(&nf->packet);
free(nf);
}
}
+
+/* Returns true if there exist any netflow objects, false otherwise. */
+bool
+netflow_exists(void)
+{
+ int n;
+
+ atomic_read(&netflow_count, &n);
+ return n > 0;
+}
/* Helpers. */