[ovs-dev] [PATCH 2/2] dpif: Fix clean up of dpif_ports on dpif_close().

Joe Stringer joe at ovn.org
Tue Jun 27 18:13:10 UTC 2017


Commit 32b77c316d9982("dpif: Save added ports in a port map.")
introduced tracking of all dpif ports by taking a reference on each
available netdev when the dpif is opened, but it failed to clear out and
release references to these netdevs when the dpif is closed.

Balance the referencing of netdevs by introducing netdev_ports_flush()
and clearing these during dpif_close().

Fixes: 32b77c316d9982("dpif: Save added ports in a port map.")
Signed-off-by: Joe Stringer <joe at ovn.org>
---
CC: Paul Blakey <paulb at mellanox.com>
CC: Darrell Ball <dlu998 at gmail.com>
---
 lib/dpif.c   |  1 +
 lib/netdev.c | 15 +++++++++++++++
 lib/netdev.h |  1 +
 3 files changed, 17 insertions(+)

diff --git a/lib/dpif.c b/lib/dpif.c
index 2ed0ba02f2ce..134388b996d5 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -427,6 +427,7 @@ dpif_close(struct dpif *dpif)
         struct registered_dpif_class *rc;
 
         rc = shash_find_data(&dpif_classes, dpif->dpif_class->type);
+        netdev_ports_flush(DPIF_HMAP_KEY(dpif));
         dpif_uninit(dpif, true);
         dp_class_unref(rc);
     }
diff --git a/lib/netdev.c b/lib/netdev.c
index eb7aef7376f1..52c132f3ad22 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -2247,6 +2247,21 @@ netdev_ports_remove(odp_port_t port_no, const void *obj)
     return ret;
 }
 
+void
+netdev_ports_flush(const void *obj)
+{
+    struct port_to_netdev_data *data, *next;
+
+    ovs_mutex_lock(&netdev_hmap_mutex);
+    HMAP_FOR_EACH_SAFE(data, next, node, &port_to_netdev) {
+        if (data->obj == obj) {
+            netdev_port_data_destroy(data);
+        }
+    }
+
+    ovs_mutex_unlock(&netdev_hmap_mutex);
+}
+
 odp_port_t
 netdev_ifindex_to_odp_port(int ifindex)
 {
diff --git a/lib/netdev.h b/lib/netdev.h
index 31846fabf9af..158c16bcb6ca 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -186,6 +186,7 @@ struct dpif_port;
 int netdev_ports_insert(struct netdev *, const void *obj, struct dpif_port *);
 struct netdev *netdev_ports_get(odp_port_t port, const void *obj);
 int netdev_ports_remove(odp_port_t port, const void *obj);
+void netdev_ports_flush(const void *obj);
 odp_port_t netdev_ifindex_to_odp_port(int ifindex);
 struct netdev_flow_dump **netdev_ports_flow_dump_create(const void *obj,
                                                         int *ports);
-- 
2.11.1



More information about the dev mailing list