From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 55F3195CD for ; Fri, 13 May 2016 07:20:25 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 12 May 2016 22:20:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,612,1455004800"; d="scan'208";a="805315037" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga003.jf.intel.com with ESMTP; 12 May 2016 22:20:23 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: Thomas Monjalon , huawei.xie@intel.com, Panu Matilainen , Tetsuya Mukawa , Traynor Kevin , Rich Lane , Yuanhan Liu Date: Thu, 12 May 2016 22:25:04 -0700 Message-Id: <1463117111-27050-13-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1462227927-22853-1-git-send-email-yuanhan.liu@linux.intel.com> <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field 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: Fri, 13 May 2016 05:20:25 -0000 This change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring. Signed-off-by: Yuanhan Liu --- drivers/net/vhost/rte_eth_vhost.c | 13 +++++++------ examples/vhost/main.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 6fa9f6b..de0f25e 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -275,7 +275,6 @@ new_device(struct virtio_net *dev) for (i = 0; i < rte_vhost_get_queue_num(dev->vid) * VIRTIO_QNUM; i++) rte_vhost_enable_guest_notification(dev, i, 0); - dev->priv = eth_dev; eth_dev->data->dev_link.link_status = ETH_LINK_UP; for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { @@ -303,6 +302,8 @@ destroy_device(volatile struct virtio_net *dev) { struct rte_eth_dev *eth_dev; struct vhost_queue *vq; + struct internal_list *list; + char ifname[PATH_MAX]; unsigned i; if (dev == NULL) { @@ -310,11 +311,13 @@ destroy_device(volatile struct virtio_net *dev) return; } - eth_dev = (struct rte_eth_dev *)dev->priv; - if (eth_dev == NULL) { - RTE_LOG(INFO, PMD, "Failed to find a ethdev\n"); + 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", ifname); return; } + eth_dev = list->eth_dev; /* Wait until rx/tx_pkt_burst stops accessing vhost device */ for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { @@ -336,8 +339,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status = ETH_LINK_DOWN; - dev->priv = NULL; - for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i]; if (vq == NULL) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 67ef0ad..c408577 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -700,6 +700,19 @@ find_vhost_dev(struct ether_addr *mac) return NULL; } +static inline struct vhost_dev *__attribute__((always_inline)) +find_vhost_dev_by_vid(int vid) +{ + struct vhost_dev *vdev; + + TAILQ_FOREACH(vdev, &vhost_dev_list, next) { + if (vdev->ready == DEVICE_RX && vdev->vid == vid) + return vdev; + } + + return NULL; +} + /* * This function learns the MAC address of the device and registers this along with a * vlan tag to a VMDQ. @@ -1175,7 +1188,9 @@ destroy_device (volatile struct virtio_net *dev) struct vhost_dev *vdev; int lcore; - vdev = (struct vhost_dev *)dev->priv; + vdev = find_vhost_dev_by_vid(dev->vid); + if (!vdev) + return; /*set the remove flag. */ vdev->remove = 1; while(vdev->ready != DEVICE_SAFE_REMOVE) { @@ -1228,7 +1243,6 @@ new_device (struct virtio_net *dev) return -1; } vdev->dev = dev; - dev->priv = vdev; vdev->vid = vid; TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next); -- 1.9.0