diff mbox series

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

Message ID 20200120150830.16262-22-elibr@mellanox.com
State Under Review
Delegated to: Ilya Maximets
Headers show
Series netdev datapath vxlan offload | expand

Commit Message

Eli Britstein Jan. 20, 2020, 3:08 p.m. UTC
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@mellanox.com>
Reviewed-by: Roni Bar Yanai <roniba@mellanox.com>
---
 lib/netdev-dpdk.c | 23 +++++++++++++++++++++++
 lib/netdev-dpdk.h |  2 ++
 2 files changed, 25 insertions(+)
diff mbox series

Patch

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