[ovs-dev] [xlate v1 08/18] ofproto-dpif-sflow: Reference count 'struct dpif_sflow'.

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


Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 ofproto/ofproto-dpif-sflow.c |   22 ++++++++++++++++++++--
 ofproto/ofproto-dpif-sflow.h |    4 +++-
 ofproto/ofproto-dpif.c       |    4 ++--
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c
index ee31f88..102467a 100644
--- a/ofproto/ofproto-dpif-sflow.c
+++ b/ofproto/ofproto-dpif-sflow.c
@@ -57,6 +57,7 @@ struct dpif_sflow {
     size_t n_flood, n_all;
     struct hmap ports;          /* Contains "struct dpif_sflow_port"s. */
     uint32_t probability;
+    int ref_cnt;
 };
 
 static void dpif_sflow_del_port__(struct dpif_sflow *,
@@ -302,10 +303,22 @@ dpif_sflow_create(void)
     hmap_init(&ds->ports);
     ds->probability = 0;
     route_table_register();
+    ds->ref_cnt = 1;
 
     return ds;
 }
 
+struct dpif_sflow *
+dpif_sflow_ref(const struct dpif_sflow *ds_)
+{
+    struct dpif_sflow *ds = CONST_CAST(struct dpif_sflow *, ds_);
+    if (ds) {
+        ovs_assert(ds->ref_cnt > 0);
+        ds->ref_cnt++;
+    }
+    return ds;
+}
+
 /* 32-bit fraction of packets to sample with.  A value of 0 samples no packets,
  * a value of %UINT32_MAX samples all packets and intermediate values sample
  * intermediate fractions of packets. */
@@ -316,9 +329,14 @@ dpif_sflow_get_probability(const struct dpif_sflow *ds)
 }
 
 void
-dpif_sflow_destroy(struct dpif_sflow *ds)
+dpif_sflow_unref(struct dpif_sflow *ds)
 {
-    if (ds) {
+    if (!ds) {
+        return;
+    }
+
+    ovs_assert(ds->ref_cnt > 0);
+    if (!--ds->ref_cnt) {
         struct dpif_sflow_port *dsp, *next;
 
         route_table_unregister();
diff --git a/ofproto/ofproto-dpif-sflow.h b/ofproto/ofproto-dpif-sflow.h
index d0f83bc..d53c95c 100644
--- a/ofproto/ofproto-dpif-sflow.h
+++ b/ofproto/ofproto-dpif-sflow.h
@@ -29,9 +29,11 @@ struct ofproto_sflow_options;
 struct ofport;
 
 struct dpif_sflow *dpif_sflow_create(void);
+struct dpif_sflow *dpif_sflow_ref(const struct dpif_sflow *);
+void dpif_sflow_unref(struct dpif_sflow *);
+
 uint32_t dpif_sflow_get_probability(const struct dpif_sflow *);
 
-void dpif_sflow_destroy(struct dpif_sflow *);
 void dpif_sflow_set_options(struct dpif_sflow *,
                             const struct ofproto_sflow_options *);
 void dpif_sflow_clear(struct dpif_sflow *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 9ac60be..264238c 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1185,7 +1185,7 @@ destruct(struct ofproto *ofproto_)
     mirror_unregister_ofproto(ofproto);
 
     netflow_destroy(ofproto->netflow);
-    dpif_sflow_destroy(ofproto->sflow);
+    dpif_sflow_unref(ofproto->sflow);
     hmap_destroy(&ofproto->bundles);
     mac_learning_unref(ofproto->ml);
 
@@ -1612,7 +1612,7 @@ set_sflow(struct ofproto *ofproto_,
         dpif_sflow_set_options(ds, sflow_options);
     } else {
         if (ds) {
-            dpif_sflow_destroy(ds);
+            dpif_sflow_unref(ds);
             ofproto->backer->need_revalidate = REV_RECONFIGURE;
             ofproto->sflow = NULL;
         }
-- 
1.7.9.5




More information about the dev mailing list