diff mbox series

[ovs-dev,net-next,5/6] netdev-dpdk: Add check whether dpdk-port is used

Message ID 1523537572-2595-6-git-send-email-xiangxia.m.yue@gmail.com
State Rejected
Delegated to: Ian Stokes
Headers show
Series Add dpdk-bond support | expand

Commit Message

Tonghao Zhang April 12, 2018, 12:52 p.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Extend the function, when looking up the dpdk netdev
by port id, if the port id is a slave port id, return
its master device.

The patch changes the function 'netdev_dpdk_lookup_by_port_id'.

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 lib/netdev-dpdk.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index e1285d1..4ef7d9f 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -1363,6 +1363,9 @@  netdev_dpdk_get_config(const struct netdev *netdev, struct smap *args)
     return 0;
 }
 
+static bool
+netdev_dpdk_bond_is_include(struct netdev_dpdk *dev, dpdk_port_t port_id);
+
 static struct netdev_dpdk *
 netdev_dpdk_lookup_by_port_id(dpdk_port_t port_id)
     OVS_REQUIRES(dpdk_mutex)
@@ -1370,7 +1373,8 @@  netdev_dpdk_lookup_by_port_id(dpdk_port_t port_id)
     struct netdev_dpdk *dev;
 
     LIST_FOR_EACH (dev, list_node, &dpdk_list) {
-        if (dev->port_id == port_id) {
+        if (dev->port_id == port_id ||
+                netdev_dpdk_bond_is_include(dev, port_id)) {
             return dev;
         }
     }
@@ -1432,6 +1436,19 @@  netdev_dpdk_bond_uninit(struct netdev_dpdk *dev)
     free(dev->bond);
 }
 
+static bool
+netdev_dpdk_bond_is_include(struct netdev_dpdk *dev,
+                            dpdk_port_t port_id)
+{
+    LIST_EACH_VALID_BOND_SLAVE(dev->bond->slaves) {
+        if (dev->bond->slaves[i] == port_id) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 /* Check the PCIs or device names requested whether
  * it's valid or not. */
 static bool
@@ -1439,6 +1456,7 @@  netdev_dpdk_bond_slave_request(const struct netdev_dpdk *dev OVS_UNUSED,
                                const char *devargs, dpdk_port_t *rs)
 {
     dpdk_port_t port_id = DPDK_ETH_PORT_ID_INVALID;
+    struct netdev_dpdk *dpdk_dev = NULL;
     char *pci = NULL, *save_ptr = NULL;
     char *args = xstrdup(devargs);
     int i;
@@ -1449,7 +1467,9 @@  netdev_dpdk_bond_slave_request(const struct netdev_dpdk *dev OVS_UNUSED,
             pci != NULL; pci = strtok_r(NULL, ",", &save_ptr), i++) {
 
         if (rte_eth_dev_get_port_by_name(pci, &port_id) ||
-                !rte_eth_dev_is_valid_port(port_id)) {
+                !rte_eth_dev_is_valid_port(port_id) ||
+                ((dpdk_dev = netdev_dpdk_lookup_by_port_id(port_id)) &&
+                 dpdk_dev != dev)) {
 
             VLOG_INFO("Could not get the port id from pci address "
                       "or device name: %s, or the device is not attached, "