[ovs-dev] [PATCH] netdev-dpdk / arbitrary port naming for vhost ports

maryam.tahhan maryam.tahhan at intel.com
Fri Jun 20 15:23:48 UTC 2014


From: "maryam.tahhan" <maryam.tahhan at intel.com>

This patch enables arbitrary port naming for vhost patches, so
they no longer need to be called dpdkvhost<n>.

Signed-off-by: maryam.tahhan <maryam.tahhan at intel.com>
---
 INSTALL.DPDK      |  6 +++---
 lib/netdev-dpdk.c | 30 ++++++++++++++++--------------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/INSTALL.DPDK b/INSTALL.DPDK
index ad60d25..e428937 100644
--- a/INSTALL.DPDK
+++ b/INSTALL.DPDK
@@ -210,15 +210,15 @@ Pre-requisits: Fuse (packages: fuse and fuse-devel) & Cuse
     both. Please refer to the Guest setup section for more information on how to
     setup the guest in both cases.
 
- - Now you can add dpdkvhost devices. OVS expects DPDK vhost device name to start
-   with dpdkvhost and end with a portid:
+ - Now you can add dpdkvhost devices.
 
    e.g.
    ovs-vsctl add-port br0 dpdkvhost0 -- set Interface dpdkvhost0 type=dpdkvhost
 
  - Finally setup a guest with a virtio-net device attached to the vhost port.
 
- **Note: tested with Qemu versions 1.4.2 and 1.6.2**
+ **Note 1: tested with Qemu versions 1.4.2 and 1.6.2**
+   Note 2: ports don't have to be called dpdkvhost<n>.
 
 Guest Setup Requirements:
 -------------------------
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index d01d123..b8e6777 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -170,6 +170,7 @@ struct dpdk_mp {
 struct netdev_dpdk {
     struct netdev up;
     int type; /*DPDK or VHOST*/
+    char *name;
     int port_id;
     int max_packet_len;
 
@@ -454,9 +455,9 @@ static int
 netdev_dpdk_vhost_construct(struct netdev *netdev_)
 {
     struct netdev_dpdk *netdev = netdev_dpdk_cast(netdev_);
-    unsigned int port_no;
+    struct netdev_dpdk *tmp_netdev;
+    unsigned int port_no = 0;
     struct ether_addr eth_addr;
-    char *cport;
     int err = 0;
     int i;
     struct rte_pktmbuf_pool_private *mbp_priv;
@@ -465,14 +466,6 @@ netdev_dpdk_vhost_construct(struct netdev *netdev_)
         return rte_eal_init_ret;
     }
     ovs_mutex_lock(&dpdk_mutex);
-    cport = netdev_->name + 9; /* Names always start with "dpdkvhost". */
-
-    if (strncmp(netdev_->name, "dpdkvhost", 9)) {
-        err = ENODEV;
-        goto unlock_dpdk_vhost;
-    }
-
-    port_no = strtol(cport, 0, 0); /* string must be null terminated. */
 
     for (i = 0; i < NR_QUEUE; i++) {
         rte_spinlock_init(&netdev->tx_q[i].queue_lock);
@@ -485,10 +478,18 @@ netdev_dpdk_vhost_construct(struct netdev *netdev_)
     netdev->flags = NETDEV_UP | NETDEV_PROMISC;
     netdev->dev = NULL;
     netdev->type = VHOST;
+    netdev->name = netdev_->name;
 
     netdev->mtu = ETHER_MTU;
     netdev->max_packet_len = MTU_TO_MAX_LEN(netdev->mtu);
 
+    if(!list_is_empty(&dpdk_list)){
+        LIST_FOR_EACH (tmp_netdev, list_node, &dpdk_list) {
+            if(tmp_netdev->type== VHOST)
+                port_no++;
+        }
+    }
+
     /* TODO: need to discover device node at run time. */
     netdev->socket_id = SOCKET0;
     netdev->port_id = port_no;
@@ -505,7 +506,7 @@ netdev_dpdk_vhost_construct(struct netdev *netdev_)
     }
 
     memset(&eth_addr, 0x0, sizeof(eth_addr));
-    if(netdev->port_id)
+
     if(netdev->port_id < 0xff)
         eth_addr.addr_bytes[5] = netdev->port_id;
     else
@@ -519,12 +520,13 @@ netdev_dpdk_vhost_construct(struct netdev *netdev_)
     netdev->buf_size =
             mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
 
+    VLOG_INFO("%s  is associated with VHOST port #%d\n", netdev->name,
+            netdev->port_id);
 
     list_push_back(&dpdk_list, &netdev->list_node);
 
 unlock_dev:
     ovs_mutex_unlock(&netdev->mutex);
-unlock_dpdk_vhost:
     ovs_mutex_unlock(&dpdk_mutex);
 
     return err;
@@ -1748,8 +1750,8 @@ new_device (struct virtio_net *dev)
         return -1;
     }
 
-    VLOG_INFO("(%ld)  VHOST Device has been added to dpdkvhost%d \n",
-        dev->device_fh, netdev->port_id);
+    VLOG_INFO("(%ld)  VHOST Device has been added to vhost port %s \n",
+        dev->device_fh, netdev->name);
 
     return 0;
 }
-- 
1.9.0

--------------------------------------------------------------
Intel Shannon Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263
Business address: Dromore House, East Park, Shannon, Co. Clare

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.





More information about the dev mailing list