From 16ae8abe1cb8b545d4ca5cdee0e3db32c6b8b498 Mon Sep 17 00:00:00 2001 From: Yuanhan Liu Date: Wed, 11 May 2016 07:02:58 +0800 Subject: [PATCH] vhost: remove dependency on device private field This change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring. Signed-off-by: Yuanhan Liu Tested-by: Rich Lane Acked-by: Rich Lane --- drivers/net/vhost/rte_eth_vhost.c | 13 +++++++------ examples/tep_termination/main.c | 14 +++++++++++--- examples/tep_termination/main.h | 1 + examples/vhost/main.c | 10 +++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 5c1690d00e..ce5ca8b147 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/tep_termination/main.c b/examples/tep_termination/main.c index fb0c7fce2c..8c627d2299 100644 --- a/examples/tep_termination/main.c +++ b/examples/tep_termination/main.c @@ -919,12 +919,20 @@ destroy_device(volatile struct virtio_net *dev) struct virtio_net_data_ll *ll_main_dev_cur; struct virtio_net_data_ll *ll_lcore_dev_last = NULL; struct virtio_net_data_ll *ll_main_dev_last = NULL; - struct vhost_dev *vdev; + struct vhost_dev *vdev = NULL; int lcore; dev->flags &= ~VIRTIO_DEV_RUNNING; - vdev = (struct vhost_dev *)dev->priv; + ll_main_dev_cur = ll_root_used; + while (ll_main_dev_cur != NULL) { + if (ll_main_dev_cur->vdev->vid == dev->vid) { + vdev = ll_main_dev_cur->vdev; + break; + } + } + if (!vdev) + return; /* set the remove flag. */ vdev->remove = 1; @@ -1019,7 +1027,7 @@ new_device(struct virtio_net *dev) return -1; } vdev->dev = dev; - dev->priv = vdev; + vdev->vid = dev->vid; /* Add device to main ll */ ll_dev = get_data_ll_free_entry(&ll_root_free); if (ll_dev == NULL) { diff --git a/examples/tep_termination/main.h b/examples/tep_termination/main.h index 4b123abad8..f786640a09 100644 --- a/examples/tep_termination/main.h +++ b/examples/tep_termination/main.h @@ -71,6 +71,7 @@ struct device_statistics { * Device linked list structure for data path. */ struct vhost_dev { + int vid; /**< Pointer to device created by vhost lib. */ struct virtio_net *dev; /**< Number of memory regions for gpa to hpa translation. */ diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 4e26a8b0f1..77214a697d 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -1173,10 +1173,15 @@ switch_worker(void *arg __rte_unused) static void destroy_device (volatile struct virtio_net *dev) { - struct vhost_dev *vdev; + struct vhost_dev *vdev = NULL; int lcore; - vdev = (struct vhost_dev *)dev->priv; + TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { + if (vdev->vid == dev->vid) + break; + } + if (!vdev) + return; /*set the remove flag. */ vdev->remove = 1; while(vdev->ready != DEVICE_SAFE_REMOVE) { @@ -1231,7 +1236,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, global_vdev_entry);