From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id C38867DEC for ; Tue, 7 Jun 2016 05:51:38 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 06 Jun 2016 20:51:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,431,1459839600"; d="scan'208";a="992411134" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga002.jf.intel.com with ESMTP; 06 Jun 2016 20:51:36 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: huawei.xie@intel.com, Thomas Monjalon , Panu Matilainen , Traynor Kevin , Rich Lane , Tetsuya Mukawa , Yuanhan Liu Date: Tue, 7 Jun 2016 11:52:00 +0800 Message-Id: <1465271530-27878-11-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 03:51:39 -0000 Introduce a new API rte_vhost_get_ifname() to export the ifname to application. Signed-off-by: Yuanhan Liu Tested-by: Rich Lane Acked-by: Rich Lane --- drivers/net/vhost/rte_eth_vhost.c | 12 ++++++++---- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/virtio-net.c | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index fe0ce90..6fa9f6b 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -229,6 +229,7 @@ new_device(struct virtio_net *dev) struct pmd_internal *internal; struct vhost_queue *vq; unsigned i; + char ifname[PATH_MAX]; #ifdef RTE_LIBRTE_VHOST_NUMA int newnode; #endif @@ -238,9 +239,10 @@ new_device(struct virtio_net *dev) return -1; } - list = find_internal_resource(dev->ifname); + rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname)); + list = find_internal_resource(ifname); if (list == NULL) { - RTE_LOG(INFO, PMD, "Invalid device name\n"); + RTE_LOG(INFO, PMD, "Invalid device name: %s\n", ifname); return -1; } @@ -360,15 +362,17 @@ vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable) struct rte_vhost_vring_state *state; struct rte_eth_dev *eth_dev; struct internal_list *list; + char ifname[PATH_MAX]; if (dev == NULL) { RTE_LOG(ERR, PMD, "Invalid argument\n"); return -1; } - list = find_internal_resource(dev->ifname); + rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname)); + list = find_internal_resource(ifname); if (list == NULL) { - RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", dev->ifname); + RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", ifname); return -1; } diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index a65fa21..4608e3b 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -24,6 +24,7 @@ DPDK_2.1 { DPDK_16.07 { global: + rte_vhost_get_ifname; rte_vhost_get_numa_node; rte_vhost_get_queue_num; diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index de56b1b..0898e8b 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -268,6 +268,23 @@ int rte_vhost_get_numa_node(int vid); uint32_t rte_vhost_get_queue_num(int vid); /** + * Get the virtio net device's ifname. For vhost-cuse, ifname is the + * path of the char device. For vhost-user, ifname is the vhost-user + * socket file path. + * + * @param vid + * virtio-net device ID + * @param buf + * The buffer to stored the queried ifname + * @param len + * The length of buf + * + * @return + * 0 on success, -1 on failure + */ +int rte_vhost_get_ifname(int vid, char *buf, size_t len); + +/** * This function adds buffers to the virtio devices RX virtqueue. Buffers can * be received from the physical port or from another virtual device. A packet * count is returned to indicate the number of packets that were succesfully diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index a03ff30..375c9d4 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -767,6 +767,22 @@ rte_vhost_get_queue_num(int vid) return dev->virt_qp_nb; } +int +rte_vhost_get_ifname(int vid, char *buf, size_t len) +{ + struct virtio_net *dev = get_device(vid); + + if (dev == NULL) + return -1; + + len = RTE_MIN(len, sizeof(dev->ifname)); + + strncpy(buf, dev->ifname, len); + buf[len - 1] = '\0'; + + return 0; +} + int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t queue_id, int enable) { -- 1.9.0