[ovs-dev] [PATCH 21/25] netdev-dpdk: Introduce get netdev by devargs function

Eli Britstein elibr at mellanox.com
Mon Jan 20 15:08:26 UTC 2020


When a vport flow is removed, we need to get the netdev struct from the
devargs we kept in the offload event, in order to remove the rules.
Introduce a function to lookup a netdev by provided devargs.

Signed-off-by: Eli Britstein <elibr at mellanox.com>
Reviewed-by: Roni Bar Yanai <roniba at mellanox.com>
---
 lib/netdev-dpdk.c | 23 +++++++++++++++++++++++
 lib/netdev-dpdk.h |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index c094a33a5..f2e737e30 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -5334,6 +5334,29 @@ out:
     return devargs;
 }
 
+struct netdev *
+netdev_dpdk_get_netdev_by_devargs(const char *devargs)
+{
+    struct netdev *netdev = NULL;
+    struct netdev_dpdk *dev;
+    dpdk_port_t port_id;
+
+    ovs_mutex_lock(&dpdk_mutex);
+    port_id = netdev_dpdk_get_port_by_devargs(devargs);
+    if (!rte_eth_dev_is_valid_port(port_id)) {
+        goto out;
+    }
+    dev = netdev_dpdk_lookup_by_port_id(port_id);
+    ovs_mutex_lock(&dev->mutex);
+    netdev = &dev->up;
+    netdev_ref(netdev);
+    ovs_mutex_unlock(&dev->mutex);
+
+out:
+    ovs_mutex_unlock(&dpdk_mutex);
+    return netdev;
+}
+
 bool
 netdev_dpdk_flow_api_supported(struct netdev *netdev)
 {
diff --git a/lib/netdev-dpdk.h b/lib/netdev-dpdk.h
index 3deadafff..94e08e516 100644
--- a/lib/netdev-dpdk.h
+++ b/lib/netdev-dpdk.h
@@ -59,6 +59,8 @@ bool
 netdev_dpdk_is_uplink_port(struct netdev *netdev);
 const char *
 netdev_dpdk_get_port_devargs(struct netdev *netdev);
+struct netdev *
+netdev_dpdk_get_netdev_by_devargs(const char *devargs);
 
 #else
 
-- 
2.14.5



More information about the dev mailing list