DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring
@ 2016-05-02 22:25 Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
                   ` (16 more replies)
  0 siblings, 17 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Every time we introduce a new feature to vhost, we are likely
to break ABI. Moreover, some cleanups (such as the one from Ilya
to remove vec_buf from vhost_virtqueue struct) also break ABI.

This patch set is meant to resolve above issue ultimately, by
hiding virtio_net structure (as well as few others) internaly,
and export the virtio_net dev strut to applications by a number,
vid, like the way kernel exposes an fd to user space.

Back to the patch set, the first part of this set makes some
changes to vhost example, vhost-pmd and vhost, bit by bit, to
remove the dependence to "virtio_net" struct. And then do the
final change to make the current APIs to adapt to using "vid".

After that, "vrtio_net_device_ops" is the only left open struct
that an application can acces, thefeore, it's the only place
that might introduce potential ABI breakage in future for
extension. Hence, I made few more (5) space reservation, to
make sure we will not break ABI for a long time, and hopefuly,
forever.

The last bit of this patch set is some cleanups, including the
one from Ilya.

Note that this refactoring breaks the tep_termination example.
Well, it's just another copy of the original messy vhost example,
and I have no interest to cleanup it again. Therefore, I might
consider to remove that example later, and add the vxlan bits
into vhost example.

Few more TODOs: update release note, update lib version, update
version.map

Thanks.

	--yliu

---
Ilya Maximets (1):
  vhost: make buf vector for scatter Rx local

Yuanhan Liu (15):
  vhost: declare backend with int type
  vhost: set/reset dev flags internally
  vhost: declare device_fh as int
  example/vhost: make a copy of virtio device id
  vhost: rename device_fh to vid
  vhost: get device by vid only
  vhost: move vhost_device_ctx to cuse
  vhost: query pmd internal by vid
  vhost: add few more functions
  vhost: export vid as the only interface to applications
  vhost: hide internal structs/macros/functions
  vhost: remove unnecessary fields
  vhost: remove virtio-net.h
  vhost: reserve few more space for future extension
  vhost: per device vhost_hlen

 drivers/net/vhost/rte_eth_vhost.c             |  86 ++++-------
 examples/vhost/main.c                         | 126 ++++++++-------
 examples/vhost/main.h                         |   1 +
 lib/librte_vhost/rte_virtio_net.h             | 197 ++++++------------------
 lib/librte_vhost/vhost-net.h                  | 195 +++++++++++++++++++----
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  |  83 +++++-----
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  30 ++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  12 +-
 lib/librte_vhost/vhost_rxtx.c                 | 133 ++++++++--------
 lib/librte_vhost/vhost_user/vhost-net-user.c  |  53 +++----
 lib/librte_vhost/vhost_user/virtio-net-user.c |  64 ++++----
 lib/librte_vhost/vhost_user/virtio-net-user.h |  18 +--
 lib/librte_vhost/virtio-net.c                 | 213 ++++++++++++++++----------
 lib/librte_vhost/virtio-net.h                 |  43 ------
 14 files changed, 644 insertions(+), 610 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

It's an fd; so define it as "int", which could also save the unncessary
(int) case.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 +-
 lib/librte_vhost/virtio-net.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 600b20b..4d25f79 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -85,7 +85,7 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;			/**< Virtqueue available ring. */
 	struct vring_used	*used;			/**< Virtqueue used ring. */
 	uint32_t		size;			/**< Size of descriptor ring. */
-	uint32_t		backend;		/**< Backend value to determine if device should started/stopped. */
+	int			backend;		/**< Backend value to determine if device should started/stopped. */
 	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
 	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
 	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index d870ad9..f7c7215 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -716,8 +716,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	 * we add the device.
 	 */
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED) &&
-			((int)dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED)) {
+		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
+		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
 			return notify_ops->new_device(dev);
 		}
 	/* Otherwise we remove it. */
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

It does not make sense to ask the application to set/unset the flag
VIRTIO_DEV_RUNNING (that used internal only) at new_device()/
destroy_device() callback.

Instead, it should be set after new_device() succeeds and reset before
destroy_device() is invoked inside vhost lib. This patch fixes it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c             |  2 --
 examples/vhost/main.c                         |  3 ---
 lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++----
 lib/librte_vhost/virtio-net.c                 | 21 ++++++++++++++-------
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 310cbef..63538c1 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)
 	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
 		rte_vhost_enable_guest_notification(dev, i, 0);
 
-	dev->flags |= VIRTIO_DEV_RUNNING;
 	dev->priv = eth_dev;
 	eth_dev->data->dev_link.link_status = ETH_LINK_UP;
 
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev)
 	eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
 
 	dev->priv = NULL;
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
 		vq = eth_dev->data->rx_queues[i];
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index d3da41b..93f9994 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1180,8 +1180,6 @@ destroy_device (volatile struct virtio_net *dev)
 	struct vhost_dev *vdev;
 	int lcore;
 
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
-
 	vdev = (struct vhost_dev *)dev->priv;
 	/*set the remove flag. */
 	vdev->remove = 1;
@@ -1258,7 +1256,6 @@ new_device (struct virtio_net *dev)
 	/* Disable notifications. */
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
-	dev->flags |= VIRTIO_DEV_RUNNING;
 
 	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index f5248bc..e775e45 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		return -1;
 
 	/* Remove from the data plane. */
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	if (dev->mem) {
 		free_mem_region(dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
 	vhost_set_vring_kick(ctx, &file);
 
-	if (virtio_is_ready(dev) &&
-		!(dev->flags & VIRTIO_DEV_RUNNING))
-			notify_ops->new_device(dev);
+	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
+		if (notify_ops->new_device(dev) == 0)
+			dev->flags |= VIRTIO_DEV_RUNNING;
+	}
 }
 
 /*
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index f7c7215..5eea3be 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 1);
 	free_device(dev);
@@ -352,8 +354,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return -1;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 0);
 	reset_device(dev);
@@ -718,12 +722,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			return notify_ops->new_device(dev);
+			if (notify_ops->new_device(dev) < 0)
+				return -1;
+			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
-	/* Otherwise we remove it. */
-	} else
-		if (file->fd == VIRTIO_DEV_STOPPED)
-			notify_ops->destroy_device(dev);
+	} else if (file->fd == VIRTIO_DEV_STOPPED) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
+		notify_ops->destroy_device(dev);
+	}
+
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Firstly, "int" would be big enough: we don't need 64 bit to represent
a virtio-net device id.

Secondly, this could let us avoid the ugly "%" PRIu64 ".." stuff.

And since ctx.fh is derived from device_fh, declare it as int, too.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c                         | 45 ++++++++++++++-------------
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  8 ++---
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 34 ++++++++++----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  7 ++---
 lib/librte_vhost/vhost_rxtx.c                 | 34 +++++++++-----------
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 21 ++++++-------
 8 files changed, 74 insertions(+), 79 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 93f9994..23bfe09 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -717,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
-			"Device (%" PRIu64 ") is using a registered MAC!\n",
+			"(%d) device is using a registered MAC!\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -729,7 +729,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	vdev->vlan_tag = vlan_tags[dev->device_fh];
 
 	/* Print out VMDQ registration info. */
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n",
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
 		dev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -740,8 +741,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
 				(uint32_t)dev->device_fh + vmdq_pool_base);
 	if (ret)
-		RTE_LOG(ERR, VHOST_DATA, "(%"PRIu64") Failed to add device MAC address to VMDQ\n",
-					dev->device_fh);
+		RTE_LOG(ERR, VHOST_DATA,
+			"(%d) failed to add device MAC address to VMDQ\n",
+			dev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -813,7 +815,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	uint64_t fh;
+	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -824,17 +826,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	fh = dst_vdev->dev->device_fh;
 	if (fh == vdev->dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			"Dropping packet.\n", fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
 
 	if (unlikely(dst_vdev->remove)) {
-		RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") "
-			"Device is marked for removal\n", fh);
+		RTE_LOG(DEBUG, VHOST_DATA,
+			"(%d) device is marked for removal\n", fh);
 		return 0;
 	}
 
@@ -859,8 +860,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 
 	if (dst_vdev->dev->device_fh == dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			" Dropping packet.\n", dst_vdev->dev->device_fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			dst_vdev->dev->device_fh);
 		return -1;
 	}
 
@@ -873,8 +874,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: pkt to local VM device id: (%" PRIu64 ") "
-		"vlan tag: %u.\n",
+		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
 		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
 
 	return 0;
@@ -965,8 +965,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 		}
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
-		"MAC address is external\n", dev->device_fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC is external\n", dev->device_fh);
 
 queue2nic:
 
@@ -1207,7 +1207,7 @@ destroy_device (volatile struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num--;
 
 	RTE_LOG(INFO, VHOST_DATA,
-		"(%" PRIu64 ") Device has been removed from data core\n",
+		"(%d) device has been removed from data core\n",
 		dev->device_fh);
 
 	rte_free(vdev);
@@ -1226,7 +1226,8 @@ new_device (struct virtio_net *dev)
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
-		RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Couldn't allocate memory for vhost dev\n",
+		RTE_LOG(INFO, VHOST_DATA,
+			"(%d) Couldn't allocate memory for vhost dev\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -1257,7 +1258,9 @@ new_device (struct virtio_net *dev)
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
 
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) device has been added to data core %d\n",
+		dev->device_fh, vdev->coreid);
 
 	return 0;
 }
@@ -1301,7 +1304,7 @@ print_stats(void)
 			rx         = rte_atomic64_read(&vdev->stats.rx_atomic);
 			rx_dropped = rx_total - rx;
 
-			printf("Statistics for device %" PRIu64 "\n"
+			printf("Statistics for device %d\n"
 				"-----------------------\n"
 				"TX total:              %" PRIu64 "\n"
 				"TX dropped:            %" PRIu64 "\n"
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 4d25f79..da3af5f 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	uint64_t		device_fh;	/**< device identifier. */
+	int			device_fh;	/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index f193a1f..4b9d74d 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -79,8 +79,8 @@
  * Structure used to identify device context.
  */
 struct vhost_device_ctx {
-	pid_t		pid;	/* PID of process calling the IOCTL. */
-	uint64_t	fh;	/* Populated with fi->fh to track the device index. */
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	fh;	/* Populated with fi->fh to track the device index. */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index c613e68..17124fd 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%"PRIu64") Device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", fi->fh);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_KICK\n",
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
 			ctx.fh);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_CALL\n",
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
 			ctx.fh);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.fh);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.fh);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index a68a8bd..69cc292 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 		sizeof(struct virtio_memory_regions) * nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") fd close failed\n",
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
 			dev->device_fh);
 
 	if (ret >= 0) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") TUNGETIFF ioctl failed\n",
+			"(%d) TUNGETIFF ioctl failed\n",
 			dev->device_fh);
 
 	return 0;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 750821a..a66456b 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	if (count == 0)
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") res_start_idx %d| res_end_idx Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
 		dev->device_fh, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	if (unlikely(m == NULL))
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") Current Index %d| End Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->device_fh, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") RX: Num merge buffers %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
 		dev->device_fh, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_rx()\n",
-		dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
-				"(%" PRIu64 ") Failed to get enough desc from vring\n",
+				"(%d) failed to get enough desc from vring\n",
 				dev->device_fh);
 			break;
 		}
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t avail_idx;
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "%s (%"PRIu64")\n", __func__, dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") about to dequeue %u buffers\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
 			dev->device_fh, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index e775e45..10daaa3 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		sizeof(struct orig_region_map) * memory.nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 5eea3be..3dc779f 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.fh);
 	}
 
 	return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev.\n",
-			ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.fh);
 		return -1;
 	}
 
@@ -407,7 +406,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 		vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
-		"(%"PRIu64") Mergeable RX buffers %s, virtio 1 %s\n",
+		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
 		dev->device_fh,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
@@ -548,7 +547,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->desc_user_addr);
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find desc ring address.\n",
+			"(%d) failed to find desc ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -560,7 +559,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->avail_user_addr);
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find avail ring address.\n",
+			"(%d) failed to find avail ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -569,20 +568,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->used_user_addr);
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find used ring address.\n",
+			"(%d) failed to find used ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address desc: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
 			dev->device_fh, vq->desc);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address avail: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
 			dev->device_fh, vq->avail);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address used: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
 			dev->device_fh, vq->used);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") log_guest_addr: %"PRIx64"\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
 			dev->device_fh, vq->log_guest_addr);
 
 	return 0;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (2 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Make a copy of virtio device id (device_fh) from the virtio_net struct,
so that we could have less dependency on the virtio_net struct.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c | 59 ++++++++++++++++++++++++---------------------------
 examples/vhost/main.h |  1 +
 2 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 23bfe09..7273897 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -709,7 +709,6 @@ static int
 link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
-	struct virtio_net *dev = vdev->dev;
 	int i, ret;
 
 	/* Learn MAC address of guest device from packet */
@@ -718,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -726,12 +725,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[dev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->device_fh];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		dev->device_fh,
+		vdev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -739,11 +738,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)dev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->device_fh + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			dev->device_fh);
+			vdev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -815,7 +814,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -823,19 +821,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	fh = dst_vdev->dev->device_fh;
-	if (fh == vdev->dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			fh);
+			vdev->device_fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", fh);
+			"(%d) device is marked for removal\n", dst_vdev->device_fh);
 		return 0;
 	}
 
@@ -848,7 +846,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
  * and get its vlan tag, and offset if it is.
  */
 static inline int __attribute__((always_inline))
-find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	uint32_t *offset, uint16_t *vlan_tag)
 {
 	struct vhost_dev *dst_vdev;
@@ -858,10 +856,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (dst_vdev->dev->device_fh == dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			dst_vdev->dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -871,11 +869,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
+	*vlan_tag = vlan_tags[vdev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
-		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
+		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
+		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
 
 	return 0;
 }
@@ -938,7 +936,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct mbuf_table *tx_q;
 	unsigned offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net *dev = vdev->dev;
 	struct ether_hdr *nh;
 
 
@@ -959,14 +956,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
-		if (unlikely(find_local_dest(dev, m, &offset, &vlan_tag) != 0)) {
+		if (unlikely(find_local_dest(vdev, m, &offset,
+					     &vlan_tag) != 0)) {
 			rte_pktmbuf_free(m);
 			return;
 		}
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC is external\n", dev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->device_fh);
 
 queue2nic:
 
@@ -1096,10 +1094,8 @@ drain_virtio_tx(struct vhost_dev *vdev)
 			free_pkts(pkts, count);
 	}
 
-	for (i = 0; i < count; ++i) {
-		virtio_tx_route(vdev, pkts[i],
-			vlan_tags[(uint16_t)vdev->dev->device_fh]);
-	}
+	for (i = 0; i < count; ++i)
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
 }
 
 /*
@@ -1208,7 +1204,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		dev->device_fh);
+		vdev->device_fh);
 
 	rte_free(vdev);
 }
@@ -1223,20 +1219,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
+	int device_fh = dev->device_fh;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%d) Couldn't allocate memory for vhost dev\n",
-			dev->device_fh);
+			"(%d) couldn't allocate memory for vhost dev\n",
+			device_fh);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
+	vdev->device_fh = device_fh;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
-	vdev->vmdq_rx_q
-		= dev->device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1260,7 +1257,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		dev->device_fh, vdev->coreid);
+		device_fh, vdev->coreid);
 
 	return 0;
 }
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index c4591b4..aca8904 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,6 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
+	int device_fh;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) next;
 } __rte_cache_aligned;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (3 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

I failed to figure out what does "fh" mean here for a long while.
The only guess I could have had is "file handle". So, you get the
point that it's not well named.

I then figured it out that "fh" is derived from the fuse lib, and
my above guess is right. However, device_fh represents a virtio
net device ID. Therefore, here I rename it to vid (Virtio-net device
ID, or Vhost device ID; choose one you prefer) to make it easier for
understanding.

This name (vid) then will be considered to the only interface to
applications. That's another reason to do the rename: it's our
interface, make it more understandable.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c                         | 44 +++++++++++++--------------
 examples/vhost/main.h                         |  2 +-
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  6 ++--
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 36 +++++++++++-----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++--
 lib/librte_vhost/vhost_rxtx.c                 | 22 +++++++-------
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 16 +++++-----
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 30 +++++++++---------
 10 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 7273897..e395e4a 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -717,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -725,12 +725,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[vdev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->vid];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		vdev->device_fh,
+		vdev->vid,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +738,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)vdev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->vid + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			vdev->device_fh);
+			vdev->vid);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -821,19 +821,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return 0;
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
+		"(%d) TX: MAC address is local\n", dst_vdev->vid);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", dst_vdev->device_fh);
+			"(%d) device is marked for removal\n", dst_vdev->vid);
 		return 0;
 	}
 
@@ -856,10 +856,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -869,11 +869,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[vdev->device_fh];
+	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
 		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
-		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
+		vdev->vid, dst_vdev->vid, *vlan_tag);
 
 	return 0;
 }
@@ -964,7 +964,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is external\n", vdev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->vid);
 
 queue2nic:
 
@@ -1095,7 +1095,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	}
 
 	for (i = 0; i < count; ++i)
-		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->vid]);
 }
 
 /*
@@ -1204,7 +1204,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		vdev->device_fh);
+		vdev->vid);
 
 	rte_free(vdev);
 }
@@ -1219,21 +1219,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int device_fh = dev->device_fh;
+	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
 			"(%d) couldn't allocate memory for vhost dev\n",
-			device_fh);
+			vid);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
-	vdev->device_fh = device_fh;
+	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
-	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1257,7 +1257,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		device_fh, vdev->coreid);
+		vid, vdev->coreid);
 
 	return 0;
 }
@@ -1309,7 +1309,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->device_fh,
+				vdev->dev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index aca8904..69382f9 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,7 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
-	int device_fh;
+	int vid;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) next;
 } __rte_cache_aligned;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index da3af5f..bc64e89 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			device_fh;	/**< device identifier. */
+	int			vid;		/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4b9d74d..b63ea6f 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -80,7 +80,7 @@
  */
 struct vhost_device_ctx {
 	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	fh;	/* Populated with fi->fh to track the device index. */
+	int	vid;	/* Virtio-net device ID */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 17124fd..3a9b33d 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
-	ctx.fh = fi->fh;
+	ctx.vid = (int)fi->fh;
 
 	return ctx;
 }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", err);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.vid);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.fh);
+			ctx.vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.fh);
+			ctx.vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 69cc292..b90dabf 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 
 	if (close(fd_tap) < 0)
 		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) TUNGETIFF ioctl failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	return 0;
 }
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index a66456b..8d87508 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
-		dev->device_fh, res_start_idx, res_end_idx);
+		dev->vid, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
 	rte_prefetch0(&vq->avail->ring[res_start_idx & (vq->size - 1)]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
-		dev->device_fh, cur_idx, res_end_idx);
+		dev->vid, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
 		return -1;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
 	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
-		dev->device_fh, virtio_hdr.num_buffers);
+		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
-				dev->device_fh);
+				dev->vid);
 			break;
 		}
 
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
 	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
-			dev->device_fh, count);
+			dev->vid, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
 	for (i = 0; i < count; i++) {
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index df2bd64..1a74953 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);
 
 struct connfd_ctx {
 	struct vhost_server *vserver;
-	uint32_t fh;
+	uint32_t vid;
 };
 
 #define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	struct vhost_server *vserver = (struct vhost_server *)dat;
 	int conn_fd;
 	struct connfd_ctx *ctx;
-	int fh;
+	int vid;
 	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	fh = vhost_new_device(vdev_ctx);
-	if (fh == -1) {
+	vid = vhost_new_device(vdev_ctx);
+	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.fh = fh;
+	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
 	vhost_set_ifname(vdev_ctx, vserver->path,
 		size);
 
-	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
 	ctx->vserver = vserver;
-	ctx->fh = fh;
+	ctx->vid = vid;
 	fdset_add(&g_vhost_server.fdset,
 		conn_fd, vserver_message_handler, NULL, ctx);
 }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 	uint64_t features;
 	int ret;
 
-	ctx.fh = cfd_ctx->fh;
+	ctx.vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 10daaa3..1568c9f 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 	dev->mem->nregions = memory.nregions;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 3dc779f..61b4305 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 struct virtio_net *
 get_device(struct vhost_device_ctx ctx)
 {
-	struct virtio_net *dev = vhost_devices[ctx.fh];
+	struct virtio_net *dev = vhost_devices[ctx.vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.vid);
 	}
 
 	return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)
 
 /*
  * Reset some variables in device structure, while keeping few
- * others untouched, such as device_fh, ifname, virt_qp_nb: they
+ * others untouched, such as vid, ifname, virt_qp_nb: they
  * should be same unless the device is removed.
  */
 static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.vid);
 		return -1;
 	}
 
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	}
 
 	vhost_devices[i] = dev;
-	dev->device_fh   = i;
+	dev->vid = i;
 
 	return i;
 }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.fh] = NULL;
+	vhost_devices[ctx.vid] = NULL;
 }
 
 void
@@ -407,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
-		dev->device_fh,
+		dev->vid,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
@@ -512,7 +512,7 @@ numa_realloc(struct virtio_net *dev, int index)
 out:
 	dev->virtqueue[index] = vq;
 	dev->virtqueue[index + 1] = vq + 1;
-	vhost_devices[dev->device_fh] = dev;
+	vhost_devices[dev->vid] = dev;
 
 	return dev;
 }
@@ -548,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find desc ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -560,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find avail ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -569,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find used ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
-			dev->device_fh, vq->desc);
+			dev->vid, vq->desc);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
-			dev->device_fh, vq->avail);
+			dev->vid, vq->avail);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
-			dev->device_fh, vq->used);
+			dev->vid, vq->used);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
-			dev->device_fh, vq->log_guest_addr);
+			dev->vid, vq->log_guest_addr);
 
 	return 0;
 }
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 06/16] vhost: get device by vid only
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (4 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

get_device() just needs vid, so pass vid as the parameter only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  | 30 ++++++------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 64 ++++++++++++-------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++---
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 43 ++++++++---------
 lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++-------
 lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++---
 lib/librte_vhost/virtio-net.c                 | 68 +++++++++++++--------------
 lib/librte_vhost/virtio-net.h                 |  2 +-
 8 files changed, 132 insertions(+), 147 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index b63ea6f..4de3aa0 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -83,28 +83,26 @@ struct vhost_device_ctx {
 	int	vid;	/* Virtio-net device ID */
 };
 
-int vhost_new_device(struct vhost_device_ctx);
-void vhost_destroy_device(struct vhost_device_ctx);
+int vhost_new_device(void);
+void vhost_destroy_device(int);
 
-void vhost_set_ifname(struct vhost_device_ctx,
-	const char *if_name, unsigned int if_len);
+void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
 
-int vhost_get_features(struct vhost_device_ctx, uint64_t *);
-int vhost_set_features(struct vhost_device_ctx, uint64_t *);
+int vhost_get_features(int, uint64_t *);
+int vhost_set_features(int, uint64_t *);
 
-int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
-int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_get_vring_base(struct vhost_device_ctx,
-	uint32_t, struct vhost_vring_state *);
+int vhost_set_vring_num(int, struct vhost_vring_state *);
+int vhost_set_vring_addr(int, struct vhost_vring_addr *);
+int vhost_set_vring_base(int, struct vhost_vring_state *);
+int vhost_get_vring_base(int, uint32_t, struct vhost_vring_state *);
 
-int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
-int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_kick(int, struct vhost_vring_file *);
+int vhost_set_vring_call(int, struct vhost_vring_file *);
 
-int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_backend(int, struct vhost_vring_file *);
 
-int vhost_set_owner(struct vhost_device_ctx);
-int vhost_reset_owner(struct vhost_device_ctx);
+int vhost_set_owner(int);
+int vhost_reset_owner(int);
 
 /*
  * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 3a9b33d..45a9a91 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -82,19 +82,18 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 static void
 vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
-	int err = 0;
+	int vid = 0;
 
-	err = vhost_new_device(ctx);
-	if (err == -1) {
+	vid = vhost_new_device();
+	if (vid == -1) {
 		fuse_reply_err(req, EPERM);
 		return;
 	}
 
-	fi->fh = err;
+	fi->fh = vid;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", err);
+		"(%d) device configuration started\n", vid);
 	fuse_reply_open(req, fi);
 }
 
@@ -107,17 +106,17 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	int err = 0;
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
-	vhost_destroy_device(ctx);
+	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
 /*
  * Boilerplate code for CUSE IOCTL
- * Implicit arguments: ctx, req, result.
+ * Implicit arguments: vid, req, result.
  */
 #define VHOST_IOCTL(func) do {	\
-	result = (func)(ctx);	\
+	result = (func)(vid);	\
 	fuse_reply_ioctl(req, result, NULL, 0);	\
 } while (0)
 
@@ -134,41 +133,41 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 
 /*
  * Boilerplate code for CUSE Read IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_R(type, var, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type), 0);\
 	} else {	\
 		(var) = *(const type*)in_buf;	\
-		result = func(ctx, &(var));	\
+		result = func(vid, &(var));	\
 		fuse_reply_ioctl(req, result, NULL, 0);\
 	}	\
 } while (0)
 
 /*
  * Boilerplate code for CUSE Write IOCTL
- * Implicit arguments: ctx, req, result, out_bufsz.
+ * Implicit arguments: vid, req, result, out_bufsz.
  */
 #define VHOST_IOCTL_W(type, var, func) do {	\
 	if (!out_bufsz) {	\
 		VHOST_IOCTL_RETRY(0, sizeof(type));\
 	} else {	\
-		result = (func)(ctx, &(var));\
+		result = (func)(vid, &(var));\
 		fuse_reply_ioctl(req, result, &(var), sizeof(type));\
 	} \
 } while (0)
 
 /*
  * Boilerplate code for CUSE Read/Write IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\
 	} else {	\
 		(var1) = *(const type1*) (in_buf);	\
-		result = (func)(ctx, (var1), &(var2));	\
+		result = (func)(vid, (var1), &(var2));	\
 		fuse_reply_ioctl(req, result, &(var2), sizeof(type2));\
 	}	\
 } while (0)
@@ -190,6 +189,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	uint64_t features;
 	uint32_t index;
 	int result = 0;
+	int vid = ctx.vid;
 
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,12 +294,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n", vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n", vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -315,10 +313,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 			}
 			file.fd = fd;
 			if (cmd == VHOST_SET_VRING_KICK) {
-				result = vhost_set_vring_kick(ctx, &file);
+				result = vhost_set_vring_kick(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			} else {
-				result = vhost_set_vring_call(ctx, &file);
+				result = vhost_set_vring_call(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			}
 		}
@@ -326,17 +324,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
+			"(%d) IOCTL: DOESN NOT EXIST\n", vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.vid);
+			"(%d) IOCTL: FAIL\n", vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.vid);
+			"(%d) IOCTL: SUCCESS\n", vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index b90dabf..34ee6c9 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	uint64_t base_address = 0, mapped_address, mapped_size;
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
  * save it in the device structure.
  */
 static int
-get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int pid)
+get_ifname(int vid, int tap_fd, int pid)
 {
 	int fd_tap;
 	struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->vid);
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n", vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
-		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
+		vhost_set_ifname(vid, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) TUNGETIFF ioctl failed\n",
-			dev->vid);
+			"(%d) TUNGETIFF ioctl failed\n", vid);
 
 	return 0;
 }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
 	if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
-		get_ifname(ctx, dev, file->fd, ctx.pid);
+		get_ifname(ctx.vid, file->fd, ctx.pid);
 
-	return vhost_set_backend(ctx, file);
+	return vhost_set_backend(ctx.vid, file);
 }
 
 void
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 1a74953..5a58946 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -286,7 +286,6 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	int conn_fd;
 	struct connfd_ctx *ctx;
 	int vid;
-	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
 	conn_fd = accept(fd, NULL, NULL);
@@ -301,17 +300,15 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	vid = vhost_new_device(vdev_ctx);
+	vid = vhost_new_device();
 	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
-	vhost_set_ifname(vdev_ctx, vserver->path,
-		size);
+	vhost_set_ifname(vid, vserver->path, size);
 
 	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
@@ -325,13 +322,13 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 static void
 vserver_message_handler(int connfd, void *dat, int *remove)
 {
-	struct vhost_device_ctx ctx;
+	int vid;
 	struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat;
 	struct VhostUserMsg msg;
 	uint64_t features;
 	int ret;
 
-	ctx.vid = cfd_ctx->vid;
+	vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
@@ -347,7 +344,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		close(connfd);
 		*remove = 1;
 		free(cfd_ctx);
-		vhost_destroy_device(ctx);
+		vhost_destroy_device(vid);
 
 		return;
 	}
@@ -356,14 +353,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_get_features(ctx, &features);
+		ret = vhost_get_features(vid, &features);
 		msg.payload.u64 = features;
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
 		features = msg.payload.u64;
-		vhost_set_features(ctx, &features);
+		vhost_set_features(vid, &features);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -372,22 +369,22 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_PROTOCOL_FEATURES:
-		user_set_protocol_features(ctx, msg.payload.u64);
+		user_set_protocol_features(vid, msg.payload.u64);
 		break;
 
 	case VHOST_USER_SET_OWNER:
-		vhost_set_owner(ctx);
+		vhost_set_owner(vid);
 		break;
 	case VHOST_USER_RESET_OWNER:
-		vhost_reset_owner(ctx);
+		vhost_reset_owner(vid);
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		user_set_mem_table(ctx, &msg);
+		user_set_mem_table(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-		user_set_log_base(ctx, &msg);
+		user_set_log_base(vid, &msg);
 
 		/* it needs a reply */
 		msg.size = sizeof(msg.payload.u64);
@@ -399,26 +396,26 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_NUM:
-		vhost_set_vring_num(ctx, &msg.payload.state);
+		vhost_set_vring_num(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SET_VRING_ADDR:
-		vhost_set_vring_addr(ctx, &msg.payload.addr);
+		vhost_set_vring_addr(vid, &msg.payload.addr);
 		break;
 	case VHOST_USER_SET_VRING_BASE:
-		vhost_set_vring_base(ctx, &msg.payload.state);
+		vhost_set_vring_base(vid, &msg.payload.state);
 		break;
 
 	case VHOST_USER_GET_VRING_BASE:
-		ret = user_get_vring_base(ctx, &msg.payload.state);
+		ret = user_get_vring_base(vid, &msg.payload.state);
 		msg.size = sizeof(msg.payload.state);
 		send_vhost_message(connfd, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_KICK:
-		user_set_vring_kick(ctx, &msg);
+		user_set_vring_kick(vid, &msg);
 		break;
 	case VHOST_USER_SET_VRING_CALL:
-		user_set_vring_call(ctx, &msg);
+		user_set_vring_call(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_ERR:
@@ -434,10 +431,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_ENABLE:
-		user_set_vring_enable(ctx, &msg.payload.state);
+		user_set_vring_enable(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SEND_RARP:
-		user_send_rarp(ctx, &msg);
+		user_send_rarp(vid, &msg);
 		break;
 
 	default:
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 1568c9f..9385af1 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev)
 }
 
 int
-user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 {
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	uint64_t alignment;
 
 	/* unmap old memory regions one by one*/
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev)
 }
 
 void
-user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring call idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_call(ctx, &file);
+	vhost_set_vring_call(vid, &file);
 }
 
 
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  *  device is ready for packet processing.
  */
 void
-user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_kick(ctx, &file);
+	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (notify_ops->new_device(dev) == 0)
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  * when virtio is stopped, qemu will send us the GET_VRING_BASE message.
  */
 int
-user_get_vring_base(struct vhost_device_ctx ctx,
+user_get_vring_base(int vid,
 	struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return -1;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
 		notify_ops->destroy_device(dev);
 
 	/* Here we are safe to get the last used index */
-	vhost_get_vring_base(ctx, state->index, state);
+	vhost_get_vring_base(vid, state->index, state);
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,
  * enable the virtio queue pair.
  */
 int
-user_set_vring_enable(struct vhost_device_ctx ctx,
+user_set_vring_enable(int vid,
 		      struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 	int enable = (int)state->num;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx,
 }
 
 void
-user_set_protocol_features(struct vhost_device_ctx ctx,
+user_set_protocol_features(int vid,
 			   uint64_t protocol_features)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
 		return;
 
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx,
 }
 
 int
-user_set_log_base(struct vhost_device_ctx ctx,
+user_set_log_base(int vid,
 		 struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,
 	uint64_t size, off;
 	void *addr;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,
  * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it.
  */
 int
-user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *msg)
+user_send_rarp(int vid, struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
 	uint8_t *mac = (uint8_t *)&msg->payload.u64;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h
index cefec16..e1b967b 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.h
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h
@@ -45,20 +45,18 @@
 					 (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
 					 (1ULL << VHOST_USER_PROTOCOL_F_RARP))
 
-int user_set_mem_table(struct vhost_device_ctx, struct VhostUserMsg *);
+int user_set_mem_table(int, struct VhostUserMsg *);
 
-void user_set_vring_call(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_call(int, struct VhostUserMsg *);
 
-void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_kick(int, struct VhostUserMsg *);
 
-void user_set_protocol_features(struct vhost_device_ctx ctx,
-				uint64_t protocol_features);
-int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *);
-int user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *);
+void user_set_protocol_features(int vid, uint64_t protocol_features);
+int user_set_log_base(int vid, struct VhostUserMsg *);
+int user_send_rarp(int vid, struct VhostUserMsg *);
 
-int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int user_get_vring_base(int, struct vhost_vring_state *);
 
-int user_set_vring_enable(struct vhost_device_ctx ctx,
-			  struct vhost_vring_state *state);
+int user_set_vring_enable(int vid, struct vhost_vring_state *state);
 
 #endif
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 61b4305..ea28090 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -108,15 +108,14 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 	return vhost_va;
 }
 
-
 struct virtio_net *
-get_device(struct vhost_device_ctx ctx)
+get_device(int vid)
 {
-	struct virtio_net *dev = vhost_devices[ctx.vid];
+	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.vid);
+			"(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -255,7 +254,7 @@ reset_device(struct virtio_net *dev)
  * list.
  */
 int
-vhost_new_device(struct vhost_device_ctx ctx)
+vhost_new_device(void)
 {
 	struct virtio_net *dev;
 	int i;
@@ -263,7 +262,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.vid);
+			"Failed to allocate memory for new dev.\n");
 		return -1;
 	}
 
@@ -288,9 +287,9 @@ vhost_new_device(struct vhost_device_ctx ctx)
  * cleanup the device and remove it from device configuration linked list.
  */
 void
-vhost_destroy_device(struct vhost_device_ctx ctx)
+vhost_destroy_device(int vid)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return;
@@ -303,17 +302,16 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.vid] = NULL;
+	vhost_devices[vid] = NULL;
 }
 
 void
-vhost_set_ifname(struct vhost_device_ctx ctx,
-	const char *if_name, unsigned int if_len)
+vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)
 {
 	struct virtio_net *dev;
 	unsigned int len;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return;
 
@@ -330,11 +328,11 @@ vhost_set_ifname(struct vhost_device_ctx ctx,
  * the device hasn't been initialised.
  */
 int
-vhost_set_owner(struct vhost_device_ctx ctx)
+vhost_set_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -345,11 +343,11 @@ vhost_set_owner(struct vhost_device_ctx ctx)
  * Called from CUSE IOCTL: VHOST_RESET_OWNER
  */
 int
-vhost_reset_owner(struct vhost_device_ctx ctx)
+vhost_reset_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -368,11 +366,11 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
  * The features that we support are requested.
  */
 int
-vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_get_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -386,13 +384,13 @@ vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * We receive the negotiated features supported by us and the virtio device.
  */
 int
-vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 	uint16_t vhost_hlen;
 	uint16_t i;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 	if (*pu & ~VHOST_FEATURES)
@@ -426,12 +424,11 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * The virtio device sends us the size of the descriptor ring.
  */
 int
-vhost_set_vring_num(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_num(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -530,12 +527,12 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
  * This function then converts these to our address space.
  */
 int
-vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if ((dev == NULL) || (dev->mem == NULL))
 		return -1;
 
@@ -592,12 +589,11 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
  * The virtio device sends us the available ring last used index.
  */
 int
-vhost_set_vring_base(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_base(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -613,12 +609,12 @@ vhost_set_vring_base(struct vhost_device_ctx ctx,
  * We send the virtio device our available ring last used index.
  */
 int
-vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+vhost_get_vring_base(int vid, uint32_t index,
 	struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -636,13 +632,13 @@ vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
  * copied into our process space.
  */
 int
-vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_call(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 	uint32_t cur_qp_idx = file->index / VIRTIO_QNUM;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -673,12 +669,12 @@ vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * This fd gets copied into our process space.
  */
 int
-vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_kick(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -703,11 +699,11 @@ vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * The device will still exist in the device configuration linked list.
  */
 int
-vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_backend(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
index 75fb57e..9812545 100644
--- a/lib/librte_vhost/virtio-net.h
+++ b/lib/librte_vhost/virtio-net.h
@@ -38,6 +38,6 @@
 #include "rte_virtio_net.h"
 
 struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(struct vhost_device_ctx ctx);
+struct virtio_net *get_device(int vid);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (5 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

vhost cuse is now the last reference of the vhost_device_ctx struct;
move it there, and do a rename to "vhost_cuse_device_ctx", to make
it clear that it's "cuse only".

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  |  8 --------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 13 +++++++------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++--
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4de3aa0..4ed5816 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -75,14 +75,6 @@
 #endif
 
 
-/*
- * Structure used to identify device context.
- */
-struct vhost_device_ctx {
-	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	vid;	/* Virtio-net device ID */
-};
-
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 45a9a91..cf6d191 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";
 static struct fuse_session *session;
 
 /*
- * Returns vhost_device_ctx from given fuse_req_t. The index is populated later
- * when the device is added to the device linked list.
+ * Returns vhost_cuse_device_ctx from given fuse_req_t. The
+ * index is populated later when the device is added to the
+ * device linked list.
  */
-static struct vhost_device_ctx
+static struct vhost_cuse_device_ctx
 fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx;
+	struct vhost_cuse_device_ctx ctx;
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void
 vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 {
 	int err = 0;
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		struct fuse_file_info *fi, __rte_unused unsigned flags,
 		const void *in_buf, size_t in_bufsz, size_t out_bufsz)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 	struct vhost_vring_file file;
 	struct vhost_vring_state state;
 	struct vhost_vring_addr addr;
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 34ee6c9..0723a7a 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr,
 }
 
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions)
 {
 	uint64_t size = offsetof(struct vhost_memory, regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)
 	return 0;
 }
 
-int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+cuse_set_backend(struct vhost_cuse_device_ctx ctx,
+		 struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
index eb6b0ba..3f67154 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
@@ -38,11 +38,19 @@
 
 #include "vhost-net.h"
 
+/*
+ * Structure used to identify device context.
+ */
+struct vhost_cuse_device_ctx {
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	vid;	/* Virtio-net device ID */
+};
+
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions);
 
 int
-cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *);
+cuse_set_backend(struct vhost_cuse_device_ctx ctx, struct vhost_vring_file *);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (6 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 09/16] vhost: add few more functions Yuanhan Liu
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Query internal by vid instead of "ifname", to avoid the dependency of
virtio_net struct.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 63538c1..290fd9e 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -86,6 +86,7 @@ struct vhost_queue {
 };
 
 struct pmd_internal {
+	int vid;
 	char *dev_name;
 	char *iface_name;
 	uint16_t max_queues;
@@ -194,20 +195,17 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
 }
 
 static inline struct internal_list *
-find_internal_resource(char *ifname)
+find_internal_resource(int vid)
 {
 	int found = 0;
 	struct internal_list *list;
 	struct pmd_internal *internal;
 
-	if (ifname == NULL)
-		return NULL;
-
 	pthread_mutex_lock(&internal_list_lock);
 
 	TAILQ_FOREACH(list, &internal_list, next) {
 		internal = list->eth_dev->data->dev_private;
-		if (!strcmp(internal->iface_name, ifname)) {
+		if (internal->vid == vid) {
 			found = 1;
 			break;
 		}
@@ -238,14 +236,15 @@ new_device(struct virtio_net *dev)
 		return -1;
 	}
 
-	list = find_internal_resource(dev->ifname);
+	list = find_internal_resource(dev->vid);
 	if (list == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid device name\n");
+		RTE_LOG(INFO, PMD, "Invalid vid %d\n", dev->vid);
 		return -1;
 	}
 
 	eth_dev = list->eth_dev;
 	internal = eth_dev->data->dev_private;
+	internal->vid = dev->vid;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
 	ret  = get_mempolicy(&newnode, NULL, 0, dev,
@@ -371,9 +370,9 @@ vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)
 		return -1;
 	}
 
-	list = find_internal_resource(dev->ifname);
+	list = find_internal_resource(dev->vid);
 	if (list == NULL) {
-		RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", dev->ifname);
+		RTE_LOG(ERR, PMD, "Invalid vid %d\n", dev->vid);
 		return -1;
 	}
 
@@ -884,7 +883,7 @@ rte_pmd_vhost_devuninit(const char *name)
 	if (internal == NULL)
 		return -ENODEV;
 
-	list = find_internal_resource(internal->iface_name);
+	list = find_internal_resource(internal->vid);
 	if (list == NULL)
 		return -ENODEV;
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 09/16] vhost: add few more functions
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (7 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Add few more functions to export few more fields or informations of
virtio_net struct, to applications, as we are gonna make them private.
It includes:

- rte_vhost_avail_entries
  It's actually a rename of "rte_vring_available_entries", with the
  "vring" to "vhost" name change to keep the consistency of other
  functions.

- rte_vhost_get_queue_num
  Exports the "virt_qp_nb" field.

- rte_vhost_get_numa_node
  Exports the numa node from where the virtio net device is allocated.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 18 ++++---------
 examples/vhost/main.c             |  4 +--
 lib/librte_vhost/rte_virtio_net.h | 37 +++++++++++++++++++++++++++
 lib/librte_vhost/virtio-net.c     | 54 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 15 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 290fd9e..9763cd4 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -33,9 +33,6 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <stdbool.h>
-#ifdef RTE_LIBRTE_VHOST_NUMA
-#include <numaif.h>
-#endif
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
@@ -228,7 +225,7 @@ new_device(struct virtio_net *dev)
 	struct vhost_queue *vq;
 	unsigned i;
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	int newnode, ret;
+	int newnode;
 #endif
 
 	if (dev == NULL) {
@@ -247,14 +244,9 @@ new_device(struct virtio_net *dev)
 	internal->vid = dev->vid;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	ret  = get_mempolicy(&newnode, NULL, 0, dev,
-			MPOL_F_NODE | MPOL_F_ADDR);
-	if (ret < 0) {
-		RTE_LOG(ERR, PMD, "Unknown numa node\n");
-		return -1;
-	}
-
-	eth_dev->data->numa_node = newnode;
+	newnode = rte_vhost_get_numa_node(dev->vid);
+	if (newnode > 0)
+		eth_dev->data->numa_node = newnode;
 #endif
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
@@ -274,7 +266,7 @@ new_device(struct virtio_net *dev)
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
+	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;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index e395e4a..145fa6f 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1056,13 +1056,13 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vring_available_entries(dev,
+	    unlikely(rx_count > rte_vhost_avail_entries(vdev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vring_available_entries(dev,
+			if (rx_count <= rte_vhost_avail_entries(vdev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index bc64e89..27f6847 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -245,6 +245,43 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get how many avail entries are left in the queue @queue_id.
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param queue_id
+ *  virtio queue index in mq case
+ *
+ * @return
+ *  num of avail entires left
+ */
+uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
+
+/**
+ * Get the number of queues the device supports.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The number of queues, 0 on failure
+ */
+uint32_t rte_vhost_get_queue_num(int vid);
+
+/**
+ * Get the numa node from which the virtio net device's memory
+ * is allocated.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The numa node, -1 on failure
+ */
+int rte_vhost_get_numa_node(int vid);
+
+
+/**
  * 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 ea28090..6bf4d87 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -753,6 +753,60 @@ int rte_vhost_feature_disable(uint64_t feature_mask)
 	return 0;
 }
 
+uint16_t
+rte_vhost_avail_entries(int vid, uint16_t queue_id)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	vq = dev->virtqueue[queue_id];
+	if (!vq->enabled)
+		return 0;
+
+	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
+}
+
+uint32_t
+rte_vhost_get_queue_num(int vid)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return 0;
+
+	return dev->virt_qp_nb;
+}
+
+int
+rte_vhost_get_numa_node(int vid)
+{
+#ifdef RTE_LIBRTE_VHOST_NUMA
+	struct virtio_net *dev = get_device(vid);
+	int numa_node;
+	int ret;
+
+	if (dev == NULL)
+		return -1;
+
+	ret = get_mempolicy(&numa_node, NULL, 0, dev,
+			MPOL_F_NODE | MPOL_F_ADDR);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%d) failed to query numa node: %d\n", vid, ret);
+		return -1;
+	}
+
+	return numa_node;
+#else
+	RTE_SET_USED(vid);
+	return -1;
+#endif
+}
+
 int rte_vhost_feature_enable(uint64_t feature_mask)
 {
 	if ((feature_mask & VHOST_SUPPORTED_FEATURES) == feature_mask) {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (8 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 09/16] vhost: add few more functions Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-10 16:17   ` Rich Lane
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

With all the previous prepare works, we are just one step away from
the final ABI refactoring. That is, to change current API to let them
stick to vid instead of the old virtio_net dev.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c             | 61 ++++++++++-----------------
 examples/vhost/main.c                         | 41 ++++++++++++------
 lib/librte_vhost/rte_virtio_net.h             | 30 +++++--------
 lib/librte_vhost/vhost_rxtx.c                 | 15 ++++++-
 lib/librte_vhost/vhost_user/virtio-net-user.c | 14 +++---
 lib/librte_vhost/virtio-net.c                 | 17 +++++---
 6 files changed, 91 insertions(+), 87 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 9763cd4..a9dada5 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -68,9 +68,9 @@ static struct ether_addr base_eth_addr = {
 };
 
 struct vhost_queue {
+	int vid;
 	rte_atomic32_t allow_queuing;
 	rte_atomic32_t while_queuing;
-	struct virtio_net *device;
 	struct pmd_internal *internal;
 	struct rte_mempool *mb_pool;
 	uint8_t port;
@@ -137,7 +137,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Dequeue packets from guest TX queue */
-	nb_rx = rte_vhost_dequeue_burst(r->device,
+	nb_rx = rte_vhost_dequeue_burst(r->vid,
 			r->virtqueue_id, r->mb_pool, bufs, nb_bufs);
 
 	r->rx_pkts += nb_rx;
@@ -168,7 +168,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Enqueue packets to guest RX queue */
-	nb_tx = rte_vhost_enqueue_burst(r->device,
+	nb_tx = rte_vhost_enqueue_burst(r->vid,
 			r->virtqueue_id, bufs, nb_bufs);
 
 	r->tx_pkts += nb_tx;
@@ -217,7 +217,7 @@ find_internal_resource(int vid)
 }
 
 static int
-new_device(struct virtio_net *dev)
+new_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct internal_list *list;
@@ -228,23 +228,17 @@ new_device(struct virtio_net *dev)
 	int newnode;
 #endif
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return -1;
-	}
-
-	list = find_internal_resource(dev->vid);
+	list = find_internal_resource(vid);
 	if (list == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid vid %d\n", dev->vid);
+		RTE_LOG(INFO, PMD, "Invalid vid %d\n", vid);
 		return -1;
 	}
 
 	eth_dev = list->eth_dev;
 	internal = eth_dev->data->dev_private;
-	internal->vid = dev->vid;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	newnode = rte_vhost_get_numa_node(dev->vid);
+	newnode = rte_vhost_get_numa_node(vid);
 	if (newnode > 0)
 		eth_dev->data->numa_node = newnode;
 #endif
@@ -253,7 +247,7 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
@@ -261,15 +255,14 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < rte_vhost_get_queue_num(dev->vid) * VIRTIO_QNUM; i++)
-		rte_vhost_enable_guest_notification(dev, i, 0);
+	for (i = 0; i < rte_vhost_get_queue_num(vid) * VIRTIO_QNUM; i++)
+		rte_vhost_enable_guest_notification(vid, 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++) {
@@ -293,22 +286,19 @@ new_device(struct virtio_net *dev)
 }
 
 static void
-destroy_device(volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
+	struct internal_list *list;
 	struct rte_eth_dev *eth_dev;
 	struct vhost_queue *vq;
 	unsigned i;
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return;
-	}
-
-	eth_dev = (struct rte_eth_dev *)dev->priv;
-	if (eth_dev == NULL) {
-		RTE_LOG(INFO, PMD, "Failed to find a ethdev\n");
+	list = find_internal_resource(vid);
+	if (list == NULL) {
+		RTE_LOG(INFO, PMD, "Invalid vid %d\n", vid);
 		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++) {
@@ -330,19 +320,17 @@ 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)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 	for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 
 	RTE_LOG(INFO, PMD, "Connection closed\n");
@@ -351,20 +339,15 @@ destroy_device(volatile struct virtio_net *dev)
 }
 
 static int
-vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)
+vring_state_changed(int vid, uint16_t vring, int enable)
 {
 	struct rte_vhost_vring_state *state;
 	struct rte_eth_dev *eth_dev;
 	struct internal_list *list;
 
-	if (dev == NULL) {
-		RTE_LOG(ERR, PMD, "Invalid argument\n");
-		return -1;
-	}
-
-	list = find_internal_resource(dev->vid);
+	list = find_internal_resource(vid);
 	if (list == NULL) {
-		RTE_LOG(ERR, PMD, "Invalid vid %d\n", dev->vid);
+		RTE_LOG(ERR, PMD, "Invalid vid %d\n", vid);
 		return -1;
 	}
 
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 145fa6f..bbf0d28 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -701,6 +701,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.
@@ -796,7 +809,7 @@ virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev,
 {
 	uint16_t ret;
 
-	ret = rte_vhost_enqueue_burst(dst_vdev->dev, VIRTIO_RXQ, &m, 1);
+	ret = rte_vhost_enqueue_burst(dst_vdev->vid, VIRTIO_RXQ, &m, 1);
 	if (enable_stats) {
 		rte_atomic64_inc(&dst_vdev->stats.rx_total_atomic);
 		rte_atomic64_add(&dst_vdev->stats.rx_atomic, ret);
@@ -1042,7 +1055,6 @@ static inline void __attribute__((always_inline))
 drain_eth_rx(struct vhost_dev *vdev)
 {
 	uint16_t rx_count, enqueue_count;
-	struct virtio_net *dev = vdev->dev;
 	struct rte_mbuf *pkts[MAX_PKT_BURST];
 
 	rx_count = rte_eth_rx_burst(ports[0], vdev->vmdq_rx_q,
@@ -1068,7 +1080,7 @@ drain_eth_rx(struct vhost_dev *vdev)
 		}
 	}
 
-	enqueue_count = rte_vhost_enqueue_burst(dev, VIRTIO_RXQ,
+	enqueue_count = rte_vhost_enqueue_burst(vdev->vid, VIRTIO_RXQ,
 						pkts, rx_count);
 	if (enable_stats) {
 		rte_atomic64_add(&vdev->stats.rx_total_atomic, rx_count);
@@ -1085,7 +1097,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	uint16_t count;
 	uint16_t i;
 
-	count = rte_vhost_dequeue_burst(vdev->dev, VIRTIO_TXQ, mbuf_pool,
+	count = rte_vhost_dequeue_burst(vdev->vid, VIRTIO_TXQ, mbuf_pool,
 					pkts, MAX_PKT_BURST);
 
 	/* setup VMDq for the first packet */
@@ -1171,13 +1183,17 @@ switch_worker(void *arg __rte_unused)
  * of dev->remove=1 which can cause an infinite loop in the rte_pause loop.
  */
 static void
-destroy_device (volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct vhost_dev *vdev;
 	int lcore;
 
-	vdev = (struct vhost_dev *)dev->priv;
-	/*set the remove flag. */
+	vdev = find_vhost_dev_by_vid(vid);
+	if (!vdev) {
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to find device\n", vid);
+		return;
+	}
+
 	vdev->remove = 1;
 	while(vdev->ready != DEVICE_SAFE_REMOVE) {
 		rte_pause();
@@ -1214,12 +1230,11 @@ destroy_device (volatile struct virtio_net *dev)
  * and the allocated to a specific data core.
  */
 static int
-new_device (struct virtio_net *dev)
+new_device(int vid)
 {
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
@@ -1228,8 +1243,6 @@ new_device (struct virtio_net *dev)
 			vid);
 		return -1;
 	}
-	vdev->dev = dev;
-	dev->priv = vdev;
 	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
@@ -1252,8 +1265,8 @@ new_device (struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num++;
 
 	/* Disable notifications. */
-	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
-	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_RXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_TXQ, 0);
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
@@ -1309,7 +1322,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->vid,
+				vdev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 27f6847..0a26df9 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -178,23 +178,12 @@ struct virtio_memory {
  *
  */
 struct virtio_net_device_ops {
-	int (*new_device)(struct virtio_net *);	/**< Add device. */
-	void (*destroy_device)(volatile struct virtio_net *);	/**< Remove device. */
+	int (*new_device)(int vid);		/**< Add device. */
+	void (*destroy_device)(int vid);	/**< Remove device. */
 
-	int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 };
 
-static inline uint16_t __attribute__((always_inline))
-rte_vring_available_entries(struct virtio_net *dev, uint16_t queue_id)
-{
-	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
-
-	if (!vq->enabled)
-		return 0;
-
-	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
-}
-
 /**
  * Function to convert guest physical addresses to vhost virtual addresses.
  * This is used to convert guest virtio buffer addresses.
@@ -231,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);
 /* Returns currently supported vhost features */
 uint64_t rte_vhost_feature_get(void);
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t queue_id, int enable);
+int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
 
 /* Register vhost driver. dev_name could be different for multiple instance support. */
 int rte_vhost_driver_register(const char *dev_name);
@@ -286,8 +275,8 @@ int rte_vhost_get_numa_node(int vid);
  * 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
  * added to the RX queue.
- * @param dev
- *  virtio-net device
+ * @param vid
+ *  virtio-net device ID
  * @param queue_id
  *  virtio queue index in mq case
  * @param pkts
@@ -297,14 +286,14 @@ int rte_vhost_get_numa_node(int vid);
  * @return
  *  num of packets enqueued
  */
-uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count);
 
 /**
  * This function gets guest buffers from the virtio device TX virtqueue,
  * construct host mbufs, copies guest buffer content to host mbufs and
  * store them in pkts to be processed.
- * @param dev
+ * @param vid
  *  virtio-net device
  * @param queue_id
  *  virtio queue index in mq case
@@ -317,7 +306,8 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
  * @return
  *  num of packets dequeued
  */
-uint16_t rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
 
+
 #endif /* _VIRTIO_NET_H_ */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 8d87508..08cab08 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,6 +46,7 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
+#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 }
 
 uint16_t
-rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return 0;
+
 	if (dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF))
 		return virtio_dev_merge_rx(dev, queue_id, pkts, count);
 	else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 }
 
 uint16_t
-rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev;
 	struct rte_mbuf *rarp_mbuf = NULL;
 	struct vhost_virtqueue *vq;
 	uint32_t desc_indexes[MAX_PKT_BURST];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t free_entries;
 	uint16_t avail_idx;
 
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 9385af1..7fa69a7 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 	/* Remove from the data plane. */
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
 
+	if (!dev)
+		return;
+
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
 		file.fd = VIRTIO_INVALID_EVENTFD;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (notify_ops->new_device(dev) == 0)
+		if (notify_ops->new_device(vid) == 0)
 			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,
 		return -1;
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 
 	/* Here we are safe to get the last used index */
 	vhost_get_vring_base(vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,
 		"set queue enable: %d to qp idx: %d\n",
 		enable, state->index);
 
-	if (notify_ops->vring_state_changed) {
-		notify_ops->vring_state_changed(dev, state->index, enable);
-	}
+	if (notify_ops->vring_state_changed)
+		notify_ops->vring_state_changed(vid, state->index, enable);
 
 	dev->virtqueue[state->index]->enabled = enable;
 
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 6bf4d87..9fd80a8 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 1);
@@ -353,7 +353,7 @@ vhost_reset_owner(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 0);
@@ -717,21 +717,26 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			if (notify_ops->new_device(dev) < 0)
+			if (notify_ops->new_device(vid) < 0)
 				return -1;
 			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
 	} else if (file->fd == VIRTIO_DEV_STOPPED) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	return 0;
 }
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev,
-	uint16_t queue_id, int enable)
+int
+rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return -1;
+
 	if (enable) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"guest notification isn't supported.\n");
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (9 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

We are now safe to move all those internal structs/macros/functions to
vhost-net.h, to hide them from external access.

This patch also breaks long lines and removes some redundant comments.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h | 128 ----------------------------------
 lib/librte_vhost/vhost-net.h      | 142 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 128 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 0a26df9..388621e 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -65,111 +65,6 @@ struct rte_mbuf;
 /* Enum for virtqueue management. */
 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
 
-#define BUF_VECTOR_MAX 256
-
-/**
- * Structure contains buffer address, length and descriptor index
- * from vring to do scatter RX.
- */
-struct buf_vector {
-	uint64_t buf_addr;
-	uint32_t buf_len;
-	uint32_t desc_idx;
-};
-
-/**
- * Structure contains variables relevant to RX/TX virtqueues.
- */
-struct vhost_virtqueue {
-	struct vring_desc	*desc;			/**< Virtqueue descriptor ring. */
-	struct vring_avail	*avail;			/**< Virtqueue available ring. */
-	struct vring_used	*used;			/**< Virtqueue used ring. */
-	uint32_t		size;			/**< Size of descriptor ring. */
-	int			backend;		/**< Backend value to determine if device should started/stopped. */
-	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
-	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
-	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
-#define VIRTIO_INVALID_EVENTFD		(-1)
-#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
-	int			callfd;			/**< Used to notify the guest (trigger interrupt). */
-	int			kickfd;			/**< Currently unused as polling mode is enabled. */
-	int			enabled;
-	uint64_t		log_guest_addr;		/**< Physical address of used ring, for logging */
-	uint64_t		reserved[15];		/**< Reserve some spaces for future extension. */
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];	/**< for scatter RX. */
-} __rte_cache_aligned;
-
-/* Old kernels have no such macro defined */
-#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
- #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
-#endif
-
-
-/*
- * Make an extra wrapper for VIRTIO_NET_F_MQ and
- * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
- * introduced since kernel v3.8. This makes our
- * code buildable for older kernel.
- */
-#ifdef VIRTIO_NET_F_MQ
- #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
- #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
-#else
- #define VHOST_MAX_QUEUE_PAIRS	1
- #define VHOST_SUPPORTS_MQ	0
-#endif
-
-/*
- * Define virtio 1.0 for older kernels
- */
-#ifndef VIRTIO_F_VERSION_1
- #define VIRTIO_F_VERSION_1 32
-#endif
-
-/**
- * Device structure contains all configuration information relating to the device.
- */
-struct virtio_net {
-	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
-	uint64_t		features;	/**< Negotiated feature set. */
-	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			vid;		/**< device identifier. */
-	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
-#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
-	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
-	uint32_t		virt_qp_nb;	/**< number of queue pair we have allocated */
-	void			*priv;		/**< private context */
-	uint64_t		log_size;	/**< Size of log area */
-	uint64_t		log_base;	/**< Where dirty pages are logged */
-	struct ether_addr	mac;		/**< MAC address */
-	rte_atomic16_t		broadcast_rarp;	/**< A flag to tell if we need broadcast rarp packet */
-	uint64_t		reserved[61];	/**< Reserve some spaces for future extension. */
-	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];	/**< Contains all virtqueue information. */
-} __rte_cache_aligned;
-
-/**
- * Information relating to memory regions including offsets to addresses in QEMUs memory file.
- */
-struct virtio_memory_regions {
-	uint64_t	guest_phys_address;	/**< Base guest physical address of region. */
-	uint64_t	guest_phys_address_end;	/**< End guest physical address of region. */
-	uint64_t	memory_size;		/**< Size of region. */
-	uint64_t	userspace_address;	/**< Base userspace address of region. */
-	uint64_t	address_offset;		/**< Offset of region for address translation. */
-};
-
-
-/**
- * Memory structure includes region and mapping information.
- */
-struct virtio_memory {
-	uint64_t	base_address;	/**< Base QEMU userspace address of the memory file. */
-	uint64_t	mapped_address;	/**< Mapped address of memory file base in our applications memory space. */
-	uint64_t	mapped_size;	/**< Total size of memory file. */
-	uint32_t	nregions;	/**< Number of memory regions. */
-	struct virtio_memory_regions      regions[0]; /**< Memory region information. */
-};
-
 /**
  * Device and vring operations.
  *
@@ -185,29 +80,6 @@ struct virtio_net_device_ops {
 };
 
 /**
- * Function to convert guest physical addresses to vhost virtual addresses.
- * This is used to convert guest virtio buffer addresses.
- */
-static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
-{
-	struct virtio_memory_regions *region;
-	uint32_t regionidx;
-	uint64_t vhost_va = 0;
-
-	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
-		region = &dev->mem->regions[regionidx];
-		if ((guest_pa >= region->guest_phys_address) &&
-			(guest_pa <= region->guest_phys_address_end)) {
-			vhost_va = region->address_offset + guest_pa;
-			break;
-		}
-	}
-	return vhost_va;
-}
-
-
-/**
  *  Disable features in feature_mask. Returns 0 on success.
  */
 int rte_vhost_feature_disable(uint64_t feature_mask);
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4ed5816..dad0280 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,6 +43,127 @@
 
 #include "rte_virtio_net.h"
 
+#define BUF_VECTOR_MAX 256
+
+/**
+ * Structure contains buffer address, length and descriptor index
+ * from vring to do scatter RX.
+ */
+struct buf_vector {
+	uint64_t buf_addr;
+	uint32_t buf_len;
+	uint32_t desc_idx;
+};
+
+/**
+ * Structure contains variables relevant to RX/TX virtqueues.
+ */
+struct vhost_virtqueue {
+	struct vring_desc	*desc;
+	struct vring_avail	*avail;
+	struct vring_used	*used;
+	uint32_t		size;
+	uint16_t		vhost_hlen;
+
+	/* Last index used on the available ring */
+	volatile uint16_t	last_used_idx;
+	/* Used for multiple devices reserving buffers */
+	volatile uint16_t	last_used_idx_res;
+#define VIRTIO_INVALID_EVENTFD		(-1)
+#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
+
+	/* Backend value to determine if device should started/stopped */
+	int			backend;
+	/* Used to notify the guest (trigger interrupt) */
+	int			callfd;
+	/* Currently unused as polling mode is enabled */
+	int			kickfd;
+	int			enabled;
+
+	/* Physical address of used ring, for logging */
+	uint64_t		log_guest_addr;
+	uint64_t		reserved[15];
+	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
+} __rte_cache_aligned;
+
+/* Old kernels have no such macro defined */
+#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
+ #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
+#endif
+
+
+/*
+ * Make an extra wrapper for VIRTIO_NET_F_MQ and
+ * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
+ * introduced since kernel v3.8. This makes our
+ * code buildable for older kernel.
+ */
+#ifdef VIRTIO_NET_F_MQ
+ #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
+ #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
+#else
+ #define VHOST_MAX_QUEUE_PAIRS	1
+ #define VHOST_SUPPORTS_MQ	0
+#endif
+
+/*
+ * Define virtio 1.0 for older kernels
+ */
+#ifndef VIRTIO_F_VERSION_1
+ #define VIRTIO_F_VERSION_1 32
+#endif
+
+/**
+ * Device structure contains all configuration information relating
+ * to the device.
+ */
+struct virtio_net {
+	/* Frontend (QEMU) memory and memory region information */
+	struct virtio_memory	*mem;
+	uint64_t		features;
+	uint64_t		protocol_features;
+	int			vid;
+	uint32_t		flags;
+#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
+	char			ifname[IF_NAME_SZ];
+	uint32_t		virt_qp_nb;
+	void			*priv;
+	uint64_t		log_size;
+	uint64_t		log_base;
+	struct ether_addr	mac;
+
+	/* to tell if we need broadcast rarp packet */
+	rte_atomic16_t		broadcast_rarp;
+	uint64_t		reserved[61];
+	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
+} __rte_cache_aligned;
+
+/**
+ * Information relating to memory regions including offsets to
+ * addresses in QEMUs memory file.
+ */
+struct virtio_memory_regions {
+	uint64_t guest_phys_address;
+	uint64_t guest_phys_address_end;
+	uint64_t memory_size;
+	uint64_t userspace_address;
+	uint64_t address_offset;
+};
+
+
+/**
+ * Memory structure includes region and mapping information.
+ */
+struct virtio_memory {
+	/* Base QEMU userspace address of the memory file. */
+	uint64_t base_address;
+	uint64_t mapped_address;
+	uint64_t mapped_size;
+	uint32_t nregions;
+	struct virtio_memory_regions regions[0];
+};
+
+
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
@@ -74,6 +195,27 @@
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
+/**
+ * Function to convert guest physical addresses to vhost virtual addresses.
+ * This is used to convert guest virtio buffer addresses.
+ */
+static inline uint64_t __attribute__((always_inline))
+gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
+{
+	struct virtio_memory_regions *region;
+	uint32_t regionidx;
+	uint64_t vhost_va = 0;
+
+	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
+		region = &dev->mem->regions[regionidx];
+		if ((guest_pa >= region->guest_phys_address) &&
+			(guest_pa <= region->guest_phys_address_end)) {
+			vhost_va = region->address_offset + guest_pa;
+			break;
+		}
+	}
+	return vhost_va;
+}
 
 int vhost_new_device(void);
 void vhost_destroy_device(int);
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (10 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

The "reserved" field in virtio_net and vhost_virtqueue struct is not
necessary any more. We now expose virtio_net device with a number "vid".

This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access
it is to expose it by a function, but I doubt that's needed or worthwhile.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index dad0280..2e4c95d 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -82,7 +82,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	uint64_t		reserved[15];
 	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
@@ -127,14 +126,12 @@ struct virtio_net {
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
-	void			*priv;
 	uint64_t		log_size;
 	uint64_t		log_base;
 	struct ether_addr	mac;
 
 	/* to tell if we need broadcast rarp packet */
 	rte_atomic16_t		broadcast_rarp;
-	uint64_t		reserved[61];
 	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
 } __rte_cache_aligned;
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (11 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

It barely has anything useful there, just 2 functions prototype. Here
move them to vhost-net.h, and delete it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  |  3 ++
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  1 -
 lib/librte_vhost/vhost_rxtx.c                 |  1 -
 lib/librte_vhost/vhost_user/virtio-net-user.c |  1 -
 lib/librte_vhost/virtio-net.c                 |  1 -
 lib/librte_vhost/virtio-net.h                 | 43 ---------------------------
 6 files changed, 3 insertions(+), 47 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 2e4c95d..9710009 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -214,6 +214,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
 	return vhost_va;
 }
 
+struct virtio_net_device_ops const *notify_ops;
+struct virtio_net *get_device(int vid);
+
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 0723a7a..552be7d 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -54,7 +54,6 @@
 #include "rte_virtio_net.h"
 #include "vhost-net.h"
 #include "virtio-net-cdev.h"
-#include "virtio-net.h"
 #include "eventfd_copy.h"
 
 /* Line size for reading maps file. */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 08cab08..65278bb 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,7 +46,6 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 7fa69a7..6463bdd 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -43,7 +43,6 @@
 #include <rte_common.h>
 #include <rte_log.h>
 
-#include "virtio-net.h"
 #include "virtio-net-user.h"
 #include "vhost-net-user.h"
 #include "vhost-net.h"
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 9fd80a8..6577fe0 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -53,7 +53,6 @@
 #include <rte_virtio_net.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_VHOST_DEVICE	1024
 static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
deleted file mode 100644
index 9812545..0000000
--- a/lib/librte_vhost/virtio-net.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _VIRTIO_NET_H
-#define _VIRTIO_NET_H
-
-#include "vhost-net.h"
-#include "rte_virtio_net.h"
-
-struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(int vid);
-
-#endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (12 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

"virtio_net_device_ops" is the only left open struct that an application
can access, therefore, it's the only place that might introduce potential
ABI break in future for extension.

So, do some reservation for it. 5 should be pretty enough, considering
that we have barely touched it for a long while. Another reason to
choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit
machine.

With this, it's confidence to say that we might be able to be free from
the ABI violation forever.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 388621e..4e50425 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -77,6 +77,8 @@ struct virtio_net_device_ops {
 	void (*destroy_device)(int vid);	/**< Remove device. */
 
 	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+
+	void *reserved[5]; /**< Reserved for future extension */
 };
 
 /**
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (13 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Yuanhan Liu

Virtio net header length is set per device, but not per queue. So, there
is no reason to store it in vhost_virtqueue struct, instead, we should
store it in virtio_net struct, to make one copy only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h  |  2 +-
 lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++--------------------
 lib/librte_vhost/virtio-net.c | 13 ++-----------
 3 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 9710009..9dec83c 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -63,7 +63,6 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;
 	struct vring_used	*used;
 	uint32_t		size;
-	uint16_t		vhost_hlen;
 
 	/* Last index used on the available ring */
 	volatile uint16_t	last_used_idx;
@@ -123,6 +122,7 @@ struct virtio_net {
 	uint64_t		protocol_features;
 	int			vid;
 	uint32_t		flags;
+	uint16_t		vhost_hlen;
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 65278bb..c9cd1c5 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 }
 
 static inline void
-copy_virtio_net_hdr(struct vhost_virtqueue *vq, uint64_t desc_addr,
+copy_virtio_net_hdr(struct virtio_net *dev, uint64_t desc_addr,
 		    struct virtio_net_hdr_mrg_rxbuf hdr)
 {
-	if (vq->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
+	if (dev->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
 		*(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr = hdr;
 	else
 		*(struct virtio_net_hdr *)(uintptr_t)desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, desc->addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, desc->addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_offset = vq->vhost_hlen;
-	desc_avail  = desc->len - vq->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
 
 	*copied = rte_pktmbuf_pkt_len(m);
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 		vq->used->ring[used_idx].id = desc_idx;
 		if (unlikely(err))
-			vq->used->ring[used_idx].len = vq->vhost_hlen;
+			vq->used->ring[used_idx].len = dev->vhost_hlen;
 		else
-			vq->used->ring[used_idx].len = copied + vq->vhost_hlen;
+			vq->used->ring[used_idx].len = copied + dev->vhost_hlen;
 		vhost_log_used_vring(dev, vq,
 			offsetof(struct vring_used, ring[used_idx]),
 			sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
+	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
 	mbuf_offset = 0;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
-		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen;
+		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	uint32_t nr_desc = 1;
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	/* Retrieve virtio net header */
 	hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
-	desc_avail  = desc->len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_offset = 0;
 	mbuf_avail  = m->buf_len - RTE_PKTMBUF_HEADROOM;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 6577fe0..c88aaa3 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -386,8 +386,6 @@ int
 vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
-	uint16_t vhost_hlen;
-	uint16_t i;
 
 	dev = get_device(vid);
 	if (dev == NULL)
@@ -398,9 +396,9 @@ vhost_set_features(int vid, uint64_t *pu)
 	dev->features = *pu;
 	if (dev->features &
 		((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {
-		vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
 	} else {
-		vhost_hlen = sizeof(struct virtio_net_hdr);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -408,13 +406,6 @@ vhost_set_features(int vid, uint64_t *pu)
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
-	for (i = 0; i < dev->virt_qp_nb; i++) {
-		uint16_t base_idx = i * VIRTIO_QNUM;
-
-		dev->virtqueue[base_idx + VIRTIO_RXQ]->vhost_hlen = vhost_hlen;
-		dev->virtqueue[base_idx + VIRTIO_TXQ]->vhost_hlen = vhost_hlen;
-	}
-
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (14 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
@ 2016-05-02 22:25 ` Yuanhan Liu
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
  16 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-02 22:25 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Ilya Maximets, Yuanhan Liu

From: Ilya Maximets <i.maximets@samsung.com>

Array of buf_vector's is just an array for temporary storing information
about available descriptors. It used only locally in virtio_dev_merge_rx()
and there is no reason for that array to be shared.

Fix that by allocating local buf_vec inside virtio_dev_merge_rx().

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h  |  1 -
 lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++-------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 9dec83c..e697d96 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -81,7 +81,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
 /* Old kernels have no such macro defined */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index c9cd1c5..96720db 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -335,7 +335,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 static inline int
 fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
-	     uint32_t *allocated, uint32_t *vec_idx)
+	     uint32_t *allocated, uint32_t *vec_idx,
+	     struct buf_vector *buf_vec)
 {
 	uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
 	uint32_t vec_id = *vec_idx;
@@ -346,9 +347,9 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
 			return -1;
 
 		len += vq->desc[idx].len;
-		vq->buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
-		vq->buf_vec[vec_id].buf_len  = vq->desc[idx].len;
-		vq->buf_vec[vec_id].desc_idx = idx;
+		buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
+		buf_vec[vec_id].buf_len  = vq->desc[idx].len;
+		buf_vec[vec_id].desc_idx = idx;
 		vec_id++;
 
 		if ((vq->desc[idx].flags & VRING_DESC_F_NEXT) == 0)
@@ -371,7 +372,8 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
  */
 static inline int
 reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
-			    uint16_t *start, uint16_t *end)
+			    uint16_t *start, uint16_t *end,
+			    struct buf_vector *buf_vec)
 {
 	uint16_t res_start_idx;
 	uint16_t res_cur_idx;
@@ -393,7 +395,7 @@ again:
 			return -1;
 
 		if (unlikely(fill_vec_buf(vq, res_cur_idx, &allocated,
-					  &vec_idx) < 0))
+					  &vec_idx, buf_vec) < 0))
 			return -1;
 
 		res_cur_idx++;
@@ -427,7 +429,7 @@ again:
 static inline uint32_t __attribute__((always_inline))
 copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			    uint16_t res_start_idx, uint16_t res_end_idx,
-			    struct rte_mbuf *m)
+			    struct rte_mbuf *m, struct buf_vector *buf_vec)
 {
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 	uint32_t vec_idx = 0;
@@ -444,10 +446,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
+	if (buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
-	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+	desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
@@ -456,10 +458,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	vhost_log_write(dev, buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
 	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_avail  = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
 	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -467,7 +469,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	while (mbuf_avail != 0 || m->next != NULL) {
 		/* done with current desc buf, get the next one */
 		if (desc_avail == 0) {
-			desc_idx = vq->buf_vec[vec_idx].desc_idx;
+			desc_idx = buf_vec[vec_idx].desc_idx;
 
 			if (!(vq->desc[desc_idx].flags & VRING_DESC_F_NEXT)) {
 				/* Update used ring with desc information */
@@ -481,12 +483,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			}
 
 			vec_idx++;
-			desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+			desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 
 			/* Prefetch buffer address. */
 			rte_prefetch0((void *)(uintptr_t)desc_addr);
 			desc_offset = 0;
-			desc_avail  = vq->buf_vec[vec_idx].buf_len;
+			desc_avail  = buf_vec[vec_idx].buf_len;
 		}
 
 		/* done with current mbuf, get the next one */
@@ -501,7 +503,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		rte_memcpy((void *)((uintptr_t)(desc_addr + desc_offset)),
 			rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
 			cpy_len);
-		vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr + desc_offset,
+		vhost_log_write(dev, buf_vec[vec_idx].buf_addr + desc_offset,
 			cpy_len);
 		PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset),
 			cpy_len, 0);
@@ -513,7 +515,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	}
 
 	used_idx = cur_idx & (vq->size - 1);
-	vq->used->ring[used_idx].id = vq->buf_vec[vec_idx].desc_idx;
+	vq->used->ring[used_idx].id = buf_vec[vec_idx].desc_idx;
 	vq->used->ring[used_idx].len = desc_offset;
 	vhost_log_used_vring(dev, vq,
 		offsetof(struct vring_used, ring[used_idx]),
@@ -529,6 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	struct vhost_virtqueue *vq;
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
+	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 
 	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
@@ -548,8 +551,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
 		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
-		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
-							 &start, &end) < 0)) {
+		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len, &start,
+							 &end, buf_vec) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
 				dev->vid);
@@ -557,7 +560,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		nr_used = copy_mbuf_to_desc_mergeable(dev, vq, start, end,
-						      pkts[pkt_idx]);
+						      pkts[pkt_idx], buf_vec);
 		rte_smp_wmb();
 
 		/*
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
@ 2016-05-10 16:17   ` Rich Lane
  2016-05-10 16:39     ` Yuanhan Liu
  0 siblings, 1 reply; 76+ messages in thread
From: Rich Lane @ 2016-05-10 16:17 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen,
	Tetsuya Mukawa, Traynor Kevin

On Mon, May 2, 2016 at 3:25 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
wrote:

> With all the previous prepare works, we are just one step away from
> the final ABI refactoring. That is, to change current API to let them
> stick to vid instead of the old virtio_net dev.
>

This patch removes the only assignment to internal->vid in the PMD. It's
initialized to zero, so only the first vhost connection will work.

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-10 16:17   ` Rich Lane
@ 2016-05-10 16:39     ` Yuanhan Liu
  2016-05-10 17:13       ` Rich Lane
  0 siblings, 1 reply; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-10 16:39 UTC (permalink / raw)
  To: Rich Lane
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen,
	Tetsuya Mukawa, Traynor Kevin

On Tue, May 10, 2016 at 09:17:23AM -0700, Rich Lane wrote:
> On Mon, May 2, 2016 at 3:25 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
> wrote:
> 
>     With all the previous prepare works, we are just one step away from
>     the final ABI refactoring. That is, to change current API to let them
>     stick to vid instead of the old virtio_net dev.
> 
> 
> This patch removes the only assignment to internal->vid in the PMD. It's
> initialized to zero, so only the first vhost connection will work.

I assume you meant to following diff:

-       if (dev == NULL) {
-               RTE_LOG(INFO, PMD, "Invalid argument\n");
-               return -1;
-       }
-
-       list = find_internal_resource(dev->vid);
+       list = find_internal_resource(vid);
        if (list == NULL) {
-               RTE_LOG(INFO, PMD, "Invalid vid %d\n", dev->vid);
+               RTE_LOG(INFO, PMD, "Invalid vid %d\n", vid);
                return -1;
        }

        eth_dev = list->eth_dev;
        internal = eth_dev->data->dev_private;
-       internal->vid = dev->vid;

Then yes, I have no idea why I did that; it's a careless and
hard-to-catch issue. So, thanks a lot for catching it!

Rich, would you help try by adding following line there and
do a test? It would be great if this patch has your Tested-by :)

    internal->vid = vid;

Thanks.

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-10 16:39     ` Yuanhan Liu
@ 2016-05-10 17:13       ` Rich Lane
  2016-05-10 17:29         ` Yuanhan Liu
  0 siblings, 1 reply; 76+ messages in thread
From: Rich Lane @ 2016-05-10 17:13 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen,
	Tetsuya Mukawa, Traynor Kevin

On Tue, May 10, 2016 at 9:39 AM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
wrote:
>
> Rich, would you help try by adding following line there and
> do a test? It would be great if this patch has your Tested-by :)
>
>     internal->vid = vid;
>

The problem is new_device has already returned before that point because
find_internal_resource failed.

I suggest adding a cookie parameter to rte_vhost_driver_register and
passing the cookie to each of the vhost_ops. The PMD can use pmd_internals
for the cookie and the whole internal_list can go away.

ps. Could you push git branches somewhere for these larger vhost patch
series? That would make it a lot easier to test than getting patches
individually from patchwork.

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-10 17:13       ` Rich Lane
@ 2016-05-10 17:29         ` Yuanhan Liu
  2016-05-10 19:22           ` Thomas Monjalon
  0 siblings, 1 reply; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-10 17:29 UTC (permalink / raw)
  To: Rich Lane, Thomas Monjalon
  Cc: dev, huawei.xie, Panu Matilainen, Tetsuya Mukawa, Traynor Kevin

On Tue, May 10, 2016 at 10:13:18AM -0700, Rich Lane wrote:
> On Tue, May 10, 2016 at 9:39 AM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
> wrote:
> 
>     Rich, would you help try by adding following line there and
>     do a test? It would be great if this patch has your Tested-by :)
> 
>         internal->vid = vid;
> 
>  
> The problem is new_device has already returned before that point because
> find_internal_resource failed.

Oh. right.

> I suggest adding a cookie parameter to rte_vhost_driver_register and passing
> the cookie to each of the vhost_ops. The PMD can use pmd_internals for the
> cookie and the whole internal_list can go away.

TBH, I don't quite like messing rte_vhost_driver_register here.

Maybe I could switch back to the old way to find_internal_resource by
ifname. In such case, I need introduce an API to expose that field
from vhost lib.

> ps. Could you push git branches somewhere for these larger vhost patch series?
> That would make it a lot easier to test than getting patches individually from
> patchwork.

Yes, indeeded. And I have a tree on dpdk.org, but that is mainly for
holding patches for the mainline. I'm thinking I may could add a new
branch there, say staging, just for testing. Thomas, will it work for
you? Or, should I push it to github?

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications
  2016-05-10 17:29         ` Yuanhan Liu
@ 2016-05-10 19:22           ` Thomas Monjalon
  0 siblings, 0 replies; 76+ messages in thread
From: Thomas Monjalon @ 2016-05-10 19:22 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: dev, Rich Lane, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin

2016-05-10 10:29, Yuanhan Liu:
> On Tue, May 10, 2016 at 10:13:18AM -0700, Rich Lane wrote:
> > ps. Could you push git branches somewhere for these larger vhost patch series?
> > That would make it a lot easier to test than getting patches individually from
> > patchwork.
> 
> Yes, indeeded. And I have a tree on dpdk.org, but that is mainly for
> holding patches for the mainline. I'm thinking I may could add a new
> branch there, say staging, just for testing. Thomas, will it work for
> you? Or, should I push it to github?

You are free to create the branches you like on dpdk.org.

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring
  2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
                   ` (15 preceding siblings ...)
  2016-05-02 22:25 ` [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
@ 2016-05-13  5:24 ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
                     ` (20 more replies)
  16 siblings, 21 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

v2: - exported ifname as well to fix a vhost-pmd issue reported
      by Rich
    - separated the big patch that introduces several new APIs
      into some small patches.
    - updated release note
    - updated version.map

NOTE: I created a branch at dpdk.org [0] for more conveinient
testing:

[0]: git://dpdk.org/next/dpdk-next-virtio for-testing


Every time we introduce a new feature to vhost, we are likely
to break ABI. Moreover, some cleanups (such as the one from Ilya
to remove vec_buf from vhost_virtqueue struct) also break ABI.

This patch set is meant to resolve above issue ultimately, by
hiding virtio_net structure (as well as few others) internaly,
and export the virtio_net dev strut to applications by a number,
vid, like the way kernel exposes an fd to user space.

Back to the patch set, the first part of this set makes some
changes to vhost example, vhost-pmd and vhost, bit by bit, to
remove the dependence to "virtio_net" struct. And then do the
final change to make the current APIs to adapt to using "vid".

After that, "vrtio_net_device_ops" is the only left open struct
that an application can acces, therefore, it's the only place
that might introduce potential ABI breakage in future for
extension. Hence, I made few more (5) space reservation, to
make sure we will not break ABI for a long time, and hopefuly,
forever.

The last bit of this patch set is some cleanups, including the
one from Ilya.

Note that this refactoring breaks the tep_termination example.
Well, it's just another copy of the original messy vhost example,
and I have no interest to cleanup it again. Therefore, I might
consider to remove that example later, and add the vxlan bits
into vhost example.

Thanks.

	--yliu

---
Ilya Maximets (1):
  vhost: make buf vector for scatter Rx local

Yuanhan Liu (18):
  vhost: declare backend with int type
  vhost: set/reset dev flags internally
  vhost: declare device fh as int
  examples/vhost: make a copy of virtio device id
  vhost: rename device fh to vid
  vhost: get device by vid only
  vhost: move vhost device ctx to cuse
  vhost: introduce new API to export numa node
  vhost: introduce new API to export number of queues
  vhost: introduce new API to export ifname
  vhost: introduce new API to export queue free entries
  vhost: remove dependency on priv field
  vhost: export vid as the only interface to applications
  vhost: hide internal structs/macros/functions
  vhost: remove unnecessary fields
  vhost: remove virtio-net.h
  vhost: reserve few more space for future extension
  vhost: per device virtio net header len

 doc/guides/rel_notes/release_16_07.rst        |   9 +
 drivers/net/vhost/rte_eth_vhost.c             |  79 ++++-----
 examples/vhost/main.c                         | 124 +++++++-------
 examples/vhost/main.h                         |   1 +
 lib/librte_vhost/rte_vhost_version.map        |  10 ++
 lib/librte_vhost/rte_virtio_net.h             | 223 +++++++------------------
 lib/librte_vhost/vhost-net.h                  | 201 ++++++++++++++++++----
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  |  83 +++++-----
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  30 ++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  12 +-
 lib/librte_vhost/vhost_rxtx.c                 | 133 ++++++++-------
 lib/librte_vhost/vhost_user/vhost-net-user.c  |  53 +++---
 lib/librte_vhost/vhost_user/vhost-net-user.h  |   2 +
 lib/librte_vhost/vhost_user/virtio-net-user.c |  64 +++----
 lib/librte_vhost/vhost_user/virtio-net-user.h |  18 +-
 lib/librte_vhost/virtio-net.c                 | 229 +++++++++++++++++---------
 lib/librte_vhost/virtio-net.h                 |  43 -----
 17 files changed, 702 insertions(+), 612 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
                     ` (19 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

It's an fd; so define it as "int", which could also save the unncessary
(int) case.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 +-
 lib/librte_vhost/virtio-net.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 600b20b..4d25f79 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -85,7 +85,7 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;			/**< Virtqueue available ring. */
 	struct vring_used	*used;			/**< Virtqueue used ring. */
 	uint32_t		size;			/**< Size of descriptor ring. */
-	uint32_t		backend;		/**< Backend value to determine if device should started/stopped. */
+	int			backend;		/**< Backend value to determine if device should started/stopped. */
 	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
 	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
 	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index f4695af..1a6259b 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -717,8 +717,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	 * we add the device.
 	 */
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED) &&
-			((int)dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED)) {
+		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
+		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
 			return notify_ops->new_device(dev);
 		}
 	/* Otherwise we remove it. */
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
                     ` (18 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

It does not make sense to ask the application to set/unset the flag
VIRTIO_DEV_RUNNING (that used internal only) at new_device()/
destroy_device() callback.

Instead, it should be set after new_device() succeeds and reset before
destroy_device() is invoked inside vhost lib. This patch fixes it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c             |  2 --
 examples/vhost/main.c                         |  3 ---
 lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++----
 lib/librte_vhost/virtio-net.c                 | 21 ++++++++++++++-------
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 310cbef..63538c1 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)
 	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
 		rte_vhost_enable_guest_notification(dev, i, 0);
 
-	dev->flags |= VIRTIO_DEV_RUNNING;
 	dev->priv = eth_dev;
 	eth_dev->data->dev_link.link_status = ETH_LINK_UP;
 
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev)
 	eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
 
 	dev->priv = NULL;
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
 		vq = eth_dev->data->rx_queues[i];
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 32a79be..ffc7209 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1179,8 +1179,6 @@ destroy_device (volatile struct virtio_net *dev)
 	struct vhost_dev *vdev;
 	int lcore;
 
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
-
 	vdev = (struct vhost_dev *)dev->priv;
 	/*set the remove flag. */
 	vdev->remove = 1;
@@ -1257,7 +1255,6 @@ new_device (struct virtio_net *dev)
 	/* Disable notifications. */
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
-	dev->flags |= VIRTIO_DEV_RUNNING;
 
 	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index f5248bc..e775e45 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		return -1;
 
 	/* Remove from the data plane. */
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	if (dev->mem) {
 		free_mem_region(dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
 	vhost_set_vring_kick(ctx, &file);
 
-	if (virtio_is_ready(dev) &&
-		!(dev->flags & VIRTIO_DEV_RUNNING))
-			notify_ops->new_device(dev);
+	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
+		if (notify_ops->new_device(dev) == 0)
+			dev->flags |= VIRTIO_DEV_RUNNING;
+	}
 }
 
 /*
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 1a6259b..c45ed1c 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 1);
 	free_device(dev);
@@ -353,8 +355,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return -1;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 0);
 	reset_device(dev);
@@ -719,12 +723,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			return notify_ops->new_device(dev);
+			if (notify_ops->new_device(dev) < 0)
+				return -1;
+			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
-	/* Otherwise we remove it. */
-	} else
-		if (file->fd == VIRTIO_DEV_STOPPED)
-			notify_ops->destroy_device(dev);
+	} else if (file->fd == VIRTIO_DEV_STOPPED) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
+		notify_ops->destroy_device(dev);
+	}
+
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
                     ` (17 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Firstly, "int" would be big enough: we don't need 64 bit to represent
a virtio-net device id. Secondly, this could let us avoid the ugly
"%" PRIu64 ".." stuff.

And since ctx.fh is derived from device_fh, declare it as int, too.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c                         | 45 ++++++++++++++-------------
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  8 ++---
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 34 ++++++++++----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  7 ++---
 lib/librte_vhost/vhost_rxtx.c                 | 34 +++++++++-----------
 lib/librte_vhost/vhost_user/vhost-net-user.c  |  2 +-
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 21 ++++++-------
 9 files changed, 75 insertions(+), 80 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ffc7209..6c7541a 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
-			"Device (%" PRIu64 ") is using a registered MAC!\n",
+			"(%d) device is using a registered MAC!\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -728,7 +728,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	vdev->vlan_tag = vlan_tags[dev->device_fh];
 
 	/* Print out VMDQ registration info. */
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n",
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
 		dev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -739,8 +740,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
 				(uint32_t)dev->device_fh + vmdq_pool_base);
 	if (ret)
-		RTE_LOG(ERR, VHOST_DATA, "(%"PRIu64") Failed to add device MAC address to VMDQ\n",
-					dev->device_fh);
+		RTE_LOG(ERR, VHOST_DATA,
+			"(%d) failed to add device MAC address to VMDQ\n",
+			dev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -812,7 +814,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	uint64_t fh;
+	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -823,17 +825,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	fh = dst_vdev->dev->device_fh;
 	if (fh == vdev->dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			"Dropping packet.\n", fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
 
 	if (unlikely(dst_vdev->remove)) {
-		RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") "
-			"Device is marked for removal\n", fh);
+		RTE_LOG(DEBUG, VHOST_DATA,
+			"(%d) device is marked for removal\n", fh);
 		return 0;
 	}
 
@@ -858,8 +859,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 
 	if (dst_vdev->dev->device_fh == dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			" Dropping packet.\n", dst_vdev->dev->device_fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			dst_vdev->dev->device_fh);
 		return -1;
 	}
 
@@ -872,8 +873,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: pkt to local VM device id: (%" PRIu64 ") "
-		"vlan tag: %u.\n",
+		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
 		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
 
 	return 0;
@@ -964,8 +964,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 		}
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
-		"MAC address is external\n", dev->device_fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC is external\n", dev->device_fh);
 
 queue2nic:
 
@@ -1206,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num--;
 
 	RTE_LOG(INFO, VHOST_DATA,
-		"(%" PRIu64 ") Device has been removed from data core\n",
+		"(%d) device has been removed from data core\n",
 		dev->device_fh);
 
 	rte_free(vdev);
@@ -1225,7 +1225,8 @@ new_device (struct virtio_net *dev)
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
-		RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Couldn't allocate memory for vhost dev\n",
+		RTE_LOG(INFO, VHOST_DATA,
+			"(%d) Couldn't allocate memory for vhost dev\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -1256,7 +1257,9 @@ new_device (struct virtio_net *dev)
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
 
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) device has been added to data core %d\n",
+		dev->device_fh, vdev->coreid);
 
 	return 0;
 }
@@ -1300,7 +1303,7 @@ print_stats(void)
 			rx         = rte_atomic64_read(&vdev->stats.rx_atomic);
 			rx_dropped = rx_total - rx;
 
-			printf("Statistics for device %" PRIu64 "\n"
+			printf("Statistics for device %d\n"
 				"-----------------------\n"
 				"TX total:              %" PRIu64 "\n"
 				"TX dropped:            %" PRIu64 "\n"
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 4d25f79..da3af5f 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	uint64_t		device_fh;	/**< device identifier. */
+	int			device_fh;	/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index f193a1f..4b9d74d 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -79,8 +79,8 @@
  * Structure used to identify device context.
  */
 struct vhost_device_ctx {
-	pid_t		pid;	/* PID of process calling the IOCTL. */
-	uint64_t	fh;	/* Populated with fi->fh to track the device index. */
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	fh;	/* Populated with fi->fh to track the device index. */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index c613e68..17124fd 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%"PRIu64") Device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", fi->fh);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_KICK\n",
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
 			ctx.fh);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_CALL\n",
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
 			ctx.fh);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.fh);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.fh);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index a68a8bd..69cc292 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 		sizeof(struct virtio_memory_regions) * nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") fd close failed\n",
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
 			dev->device_fh);
 
 	if (ret >= 0) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") TUNGETIFF ioctl failed\n",
+			"(%d) TUNGETIFF ioctl failed\n",
 			dev->device_fh);
 
 	return 0;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 750821a..a66456b 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	if (count == 0)
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") res_start_idx %d| res_end_idx Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
 		dev->device_fh, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	if (unlikely(m == NULL))
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") Current Index %d| End Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->device_fh, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") RX: Num merge buffers %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
 		dev->device_fh, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_rx()\n",
-		dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
-				"(%" PRIu64 ") Failed to get enough desc from vring\n",
+				"(%d) failed to get enough desc from vring\n",
 				dev->device_fh);
 			break;
 		}
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t avail_idx;
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "%s (%"PRIu64")\n", __func__, dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") about to dequeue %u buffers\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
 			dev->device_fh, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index df2bd64..facbfa1 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);
 
 struct connfd_ctx {
 	struct vhost_server *vserver;
-	uint32_t fh;
+	int fh;
 };
 
 #define MAX_VHOST_SERVER 1024
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index e775e45..10daaa3 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		sizeof(struct orig_region_map) * memory.nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index c45ed1c..202e196 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.fh);
 	}
 
 	return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev.\n",
-			ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.fh);
 		return -1;
 	}
 
@@ -408,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 		vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
-		"(%"PRIu64") Mergeable RX buffers %s, virtio 1 %s\n",
+		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
 		dev->device_fh,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
@@ -549,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->desc_user_addr);
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find desc ring address.\n",
+			"(%d) failed to find desc ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -561,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->avail_user_addr);
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find avail ring address.\n",
+			"(%d) failed to find avail ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -570,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->used_user_addr);
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find used ring address.\n",
+			"(%d) failed to find used ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address desc: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
 			dev->device_fh, vq->desc);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address avail: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
 			dev->device_fh, vq->avail);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address used: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
 			dev->device_fh, vq->used);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") log_guest_addr: %"PRIx64"\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
 			dev->device_fh, vq->log_guest_addr);
 
 	return 0;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (2 preceding siblings ...)
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
                     ` (16 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Make a copy of virtio device id (device_fh) from the virtio_net struct,
so that we could have less dependency on the virtio_net struct.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c | 59 ++++++++++++++++++++++++---------------------------
 examples/vhost/main.h |  1 +
 2 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 6c7541a..beb56eb 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -708,7 +708,6 @@ static int
 link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
-	struct virtio_net *dev = vdev->dev;
 	int i, ret;
 
 	/* Learn MAC address of guest device from packet */
@@ -717,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -725,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[dev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->device_fh];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		dev->device_fh,
+		vdev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)dev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->device_fh + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			dev->device_fh);
+			vdev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -814,7 +813,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -822,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	fh = dst_vdev->dev->device_fh;
-	if (fh == vdev->dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			fh);
+			vdev->device_fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", fh);
+			"(%d) device is marked for removal\n", dst_vdev->device_fh);
 		return 0;
 	}
 
@@ -847,7 +845,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
  * and get its vlan tag, and offset if it is.
  */
 static inline int __attribute__((always_inline))
-find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	uint32_t *offset, uint16_t *vlan_tag)
 {
 	struct vhost_dev *dst_vdev;
@@ -857,10 +855,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (dst_vdev->dev->device_fh == dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			dst_vdev->dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -870,11 +868,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
+	*vlan_tag = vlan_tags[vdev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
-		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
+		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
+		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
 
 	return 0;
 }
@@ -937,7 +935,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct mbuf_table *tx_q;
 	unsigned offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net *dev = vdev->dev;
 	struct ether_hdr *nh;
 
 
@@ -958,14 +955,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
-		if (unlikely(find_local_dest(dev, m, &offset, &vlan_tag) != 0)) {
+		if (unlikely(find_local_dest(vdev, m, &offset,
+					     &vlan_tag) != 0)) {
 			rte_pktmbuf_free(m);
 			return;
 		}
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC is external\n", dev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->device_fh);
 
 queue2nic:
 
@@ -1095,10 +1093,8 @@ drain_virtio_tx(struct vhost_dev *vdev)
 			free_pkts(pkts, count);
 	}
 
-	for (i = 0; i < count; ++i) {
-		virtio_tx_route(vdev, pkts[i],
-			vlan_tags[(uint16_t)vdev->dev->device_fh]);
-	}
+	for (i = 0; i < count; ++i)
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
 }
 
 /*
@@ -1207,7 +1203,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		dev->device_fh);
+		vdev->device_fh);
 
 	rte_free(vdev);
 }
@@ -1222,20 +1218,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
+	int device_fh = dev->device_fh;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%d) Couldn't allocate memory for vhost dev\n",
-			dev->device_fh);
+			"(%d) couldn't allocate memory for vhost dev\n",
+			device_fh);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
+	vdev->device_fh = device_fh;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
-	vdev->vmdq_rx_q
-		= dev->device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1259,7 +1256,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		dev->device_fh, vdev->coreid);
+		device_fh, vdev->coreid);
 
 	return 0;
 }
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index c4591b4..aca8904 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,6 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
+	int device_fh;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) next;
 } __rte_cache_aligned;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (3 preceding siblings ...)
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
                     ` (15 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

I failed to figure out what does "fh" mean here for a long while.
The only guess I could have had is "file handle". So, you get the
point that it's not well named.

I then figured it out that "fh" is derived from the fuse lib, and
my above guess is right. However, device_fh represents a virtio
net device ID. Therefore, here I rename it to vid (Virtio-net device
ID, or Vhost device ID; choose one you prefer) to make it easier for
understanding.

This name (vid) then will be considered to the only interface to
applications. That's another reason to do the rename: it's our
interface, make it more understandable.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c                         | 44 +++++++++++++--------------
 examples/vhost/main.h                         |  2 +-
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  6 ++--
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 36 +++++++++++-----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++--
 lib/librte_vhost/vhost_rxtx.c                 | 22 +++++++-------
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 16 +++++-----
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 30 +++++++++---------
 10 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index beb56eb..cb04585 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -724,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[vdev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->vid];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		vdev->device_fh,
+		vdev->vid,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -737,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)vdev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->vid + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			vdev->device_fh);
+			vdev->vid);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -820,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return 0;
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
+		"(%d) TX: MAC address is local\n", dst_vdev->vid);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", dst_vdev->device_fh);
+			"(%d) device is marked for removal\n", dst_vdev->vid);
 		return 0;
 	}
 
@@ -855,10 +855,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -868,11 +868,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[vdev->device_fh];
+	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
 		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
-		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
+		vdev->vid, dst_vdev->vid, *vlan_tag);
 
 	return 0;
 }
@@ -963,7 +963,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is external\n", vdev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->vid);
 
 queue2nic:
 
@@ -1094,7 +1094,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	}
 
 	for (i = 0; i < count; ++i)
-		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->vid]);
 }
 
 /*
@@ -1203,7 +1203,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		vdev->device_fh);
+		vdev->vid);
 
 	rte_free(vdev);
 }
@@ -1218,21 +1218,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int device_fh = dev->device_fh;
+	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
 			"(%d) couldn't allocate memory for vhost dev\n",
-			device_fh);
+			vid);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
-	vdev->device_fh = device_fh;
+	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
-	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1256,7 +1256,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		device_fh, vdev->coreid);
+		vid, vdev->coreid);
 
 	return 0;
 }
@@ -1308,7 +1308,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->device_fh,
+				vdev->dev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index aca8904..69382f9 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,7 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
-	int device_fh;
+	int vid;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) next;
 } __rte_cache_aligned;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index da3af5f..bc64e89 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			device_fh;	/**< device identifier. */
+	int			vid;		/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4b9d74d..b63ea6f 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -80,7 +80,7 @@
  */
 struct vhost_device_ctx {
 	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	fh;	/* Populated with fi->fh to track the device index. */
+	int	vid;	/* Virtio-net device ID */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 17124fd..3a9b33d 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
-	ctx.fh = fi->fh;
+	ctx.vid = (int)fi->fh;
 
 	return ctx;
 }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", err);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.vid);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.fh);
+			ctx.vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.fh);
+			ctx.vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 69cc292..b90dabf 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 
 	if (close(fd_tap) < 0)
 		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) TUNGETIFF ioctl failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	return 0;
 }
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index a66456b..8d87508 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
-		dev->device_fh, res_start_idx, res_end_idx);
+		dev->vid, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
 	rte_prefetch0(&vq->avail->ring[res_start_idx & (vq->size - 1)]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
-		dev->device_fh, cur_idx, res_end_idx);
+		dev->vid, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
 		return -1;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
 	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
-		dev->device_fh, virtio_hdr.num_buffers);
+		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
-				dev->device_fh);
+				dev->vid);
 			break;
 		}
 
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
 	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
-			dev->device_fh, count);
+			dev->vid, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
 	for (i = 0; i < count; i++) {
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index facbfa1..3498796 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);
 
 struct connfd_ctx {
 	struct vhost_server *vserver;
-	int fh;
+	int vid;
 };
 
 #define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	struct vhost_server *vserver = (struct vhost_server *)dat;
 	int conn_fd;
 	struct connfd_ctx *ctx;
-	int fh;
+	int vid;
 	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	fh = vhost_new_device(vdev_ctx);
-	if (fh == -1) {
+	vid = vhost_new_device(vdev_ctx);
+	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.fh = fh;
+	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
 	vhost_set_ifname(vdev_ctx, vserver->path,
 		size);
 
-	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
 	ctx->vserver = vserver;
-	ctx->fh = fh;
+	ctx->vid = vid;
 	fdset_add(&g_vhost_server.fdset,
 		conn_fd, vserver_message_handler, NULL, ctx);
 }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 	uint64_t features;
 	int ret;
 
-	ctx.fh = cfd_ctx->fh;
+	ctx.vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 10daaa3..1568c9f 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 	dev->mem->nregions = memory.nregions;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 202e196..0a13150 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 struct virtio_net *
 get_device(struct vhost_device_ctx ctx)
 {
-	struct virtio_net *dev = vhost_devices[ctx.fh];
+	struct virtio_net *dev = vhost_devices[ctx.vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.vid);
 	}
 
 	return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)
 
 /*
  * Reset some variables in device structure, while keeping few
- * others untouched, such as device_fh, ifname, virt_qp_nb: they
+ * others untouched, such as vid, ifname, virt_qp_nb: they
  * should be same unless the device is removed.
  */
 static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.vid);
 		return -1;
 	}
 
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	}
 
 	vhost_devices[i] = dev;
-	dev->device_fh   = i;
+	dev->vid = i;
 
 	return i;
 }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.fh] = NULL;
+	vhost_devices[ctx.vid] = NULL;
 }
 
 void
@@ -408,7 +408,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
-		dev->device_fh,
+		dev->vid,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
@@ -513,7 +513,7 @@ numa_realloc(struct virtio_net *dev, int index)
 out:
 	dev->virtqueue[index] = vq;
 	dev->virtqueue[index + 1] = vq + 1;
-	vhost_devices[dev->device_fh] = dev;
+	vhost_devices[dev->vid] = dev;
 
 	return dev;
 }
@@ -549,7 +549,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find desc ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -561,7 +561,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find avail ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -570,20 +570,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find used ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
-			dev->device_fh, vq->desc);
+			dev->vid, vq->desc);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
-			dev->device_fh, vq->avail);
+			dev->vid, vq->avail);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
-			dev->device_fh, vq->used);
+			dev->vid, vq->used);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
-			dev->device_fh, vq->log_guest_addr);
+			dev->vid, vq->log_guest_addr);
 
 	return 0;
 }
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (4 preceding siblings ...)
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
                     ` (14 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

get_device() just needs vid, so pass vid as the parameter only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  | 30 ++++++------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 64 ++++++++++++-------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++---
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 43 ++++++++---------
 lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++-------
 lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++---
 lib/librte_vhost/virtio-net.c                 | 68 +++++++++++++--------------
 lib/librte_vhost/virtio-net.h                 |  2 +-
 8 files changed, 132 insertions(+), 147 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index b63ea6f..4de3aa0 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -83,28 +83,26 @@ struct vhost_device_ctx {
 	int	vid;	/* Virtio-net device ID */
 };
 
-int vhost_new_device(struct vhost_device_ctx);
-void vhost_destroy_device(struct vhost_device_ctx);
+int vhost_new_device(void);
+void vhost_destroy_device(int);
 
-void vhost_set_ifname(struct vhost_device_ctx,
-	const char *if_name, unsigned int if_len);
+void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
 
-int vhost_get_features(struct vhost_device_ctx, uint64_t *);
-int vhost_set_features(struct vhost_device_ctx, uint64_t *);
+int vhost_get_features(int, uint64_t *);
+int vhost_set_features(int, uint64_t *);
 
-int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
-int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_get_vring_base(struct vhost_device_ctx,
-	uint32_t, struct vhost_vring_state *);
+int vhost_set_vring_num(int, struct vhost_vring_state *);
+int vhost_set_vring_addr(int, struct vhost_vring_addr *);
+int vhost_set_vring_base(int, struct vhost_vring_state *);
+int vhost_get_vring_base(int, uint32_t, struct vhost_vring_state *);
 
-int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
-int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_kick(int, struct vhost_vring_file *);
+int vhost_set_vring_call(int, struct vhost_vring_file *);
 
-int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_backend(int, struct vhost_vring_file *);
 
-int vhost_set_owner(struct vhost_device_ctx);
-int vhost_reset_owner(struct vhost_device_ctx);
+int vhost_set_owner(int);
+int vhost_reset_owner(int);
 
 /*
  * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 3a9b33d..45a9a91 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -82,19 +82,18 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 static void
 vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
-	int err = 0;
+	int vid = 0;
 
-	err = vhost_new_device(ctx);
-	if (err == -1) {
+	vid = vhost_new_device();
+	if (vid == -1) {
 		fuse_reply_err(req, EPERM);
 		return;
 	}
 
-	fi->fh = err;
+	fi->fh = vid;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", err);
+		"(%d) device configuration started\n", vid);
 	fuse_reply_open(req, fi);
 }
 
@@ -107,17 +106,17 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	int err = 0;
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
-	vhost_destroy_device(ctx);
+	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
 /*
  * Boilerplate code for CUSE IOCTL
- * Implicit arguments: ctx, req, result.
+ * Implicit arguments: vid, req, result.
  */
 #define VHOST_IOCTL(func) do {	\
-	result = (func)(ctx);	\
+	result = (func)(vid);	\
 	fuse_reply_ioctl(req, result, NULL, 0);	\
 } while (0)
 
@@ -134,41 +133,41 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 
 /*
  * Boilerplate code for CUSE Read IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_R(type, var, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type), 0);\
 	} else {	\
 		(var) = *(const type*)in_buf;	\
-		result = func(ctx, &(var));	\
+		result = func(vid, &(var));	\
 		fuse_reply_ioctl(req, result, NULL, 0);\
 	}	\
 } while (0)
 
 /*
  * Boilerplate code for CUSE Write IOCTL
- * Implicit arguments: ctx, req, result, out_bufsz.
+ * Implicit arguments: vid, req, result, out_bufsz.
  */
 #define VHOST_IOCTL_W(type, var, func) do {	\
 	if (!out_bufsz) {	\
 		VHOST_IOCTL_RETRY(0, sizeof(type));\
 	} else {	\
-		result = (func)(ctx, &(var));\
+		result = (func)(vid, &(var));\
 		fuse_reply_ioctl(req, result, &(var), sizeof(type));\
 	} \
 } while (0)
 
 /*
  * Boilerplate code for CUSE Read/Write IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\
 	} else {	\
 		(var1) = *(const type1*) (in_buf);	\
-		result = (func)(ctx, (var1), &(var2));	\
+		result = (func)(vid, (var1), &(var2));	\
 		fuse_reply_ioctl(req, result, &(var2), sizeof(type2));\
 	}	\
 } while (0)
@@ -190,6 +189,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	uint64_t features;
 	uint32_t index;
 	int result = 0;
+	int vid = ctx.vid;
 
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,12 +294,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n", vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n", vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -315,10 +313,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 			}
 			file.fd = fd;
 			if (cmd == VHOST_SET_VRING_KICK) {
-				result = vhost_set_vring_kick(ctx, &file);
+				result = vhost_set_vring_kick(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			} else {
-				result = vhost_set_vring_call(ctx, &file);
+				result = vhost_set_vring_call(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			}
 		}
@@ -326,17 +324,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
+			"(%d) IOCTL: DOESN NOT EXIST\n", vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.vid);
+			"(%d) IOCTL: FAIL\n", vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.vid);
+			"(%d) IOCTL: SUCCESS\n", vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index b90dabf..34ee6c9 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	uint64_t base_address = 0, mapped_address, mapped_size;
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
  * save it in the device structure.
  */
 static int
-get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int pid)
+get_ifname(int vid, int tap_fd, int pid)
 {
 	int fd_tap;
 	struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->vid);
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n", vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
-		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
+		vhost_set_ifname(vid, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) TUNGETIFF ioctl failed\n",
-			dev->vid);
+			"(%d) TUNGETIFF ioctl failed\n", vid);
 
 	return 0;
 }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
 	if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
-		get_ifname(ctx, dev, file->fd, ctx.pid);
+		get_ifname(ctx.vid, file->fd, ctx.pid);
 
-	return vhost_set_backend(ctx, file);
+	return vhost_set_backend(ctx.vid, file);
 }
 
 void
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 3498796..68fc9b9 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -286,7 +286,6 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	int conn_fd;
 	struct connfd_ctx *ctx;
 	int vid;
-	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
 	conn_fd = accept(fd, NULL, NULL);
@@ -301,17 +300,15 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	vid = vhost_new_device(vdev_ctx);
+	vid = vhost_new_device();
 	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
-	vhost_set_ifname(vdev_ctx, vserver->path,
-		size);
+	vhost_set_ifname(vid, vserver->path, size);
 
 	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
@@ -325,13 +322,13 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 static void
 vserver_message_handler(int connfd, void *dat, int *remove)
 {
-	struct vhost_device_ctx ctx;
+	int vid;
 	struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat;
 	struct VhostUserMsg msg;
 	uint64_t features;
 	int ret;
 
-	ctx.vid = cfd_ctx->vid;
+	vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
@@ -347,7 +344,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		close(connfd);
 		*remove = 1;
 		free(cfd_ctx);
-		vhost_destroy_device(ctx);
+		vhost_destroy_device(vid);
 
 		return;
 	}
@@ -356,14 +353,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_get_features(ctx, &features);
+		ret = vhost_get_features(vid, &features);
 		msg.payload.u64 = features;
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
 		features = msg.payload.u64;
-		vhost_set_features(ctx, &features);
+		vhost_set_features(vid, &features);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -372,22 +369,22 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_PROTOCOL_FEATURES:
-		user_set_protocol_features(ctx, msg.payload.u64);
+		user_set_protocol_features(vid, msg.payload.u64);
 		break;
 
 	case VHOST_USER_SET_OWNER:
-		vhost_set_owner(ctx);
+		vhost_set_owner(vid);
 		break;
 	case VHOST_USER_RESET_OWNER:
-		vhost_reset_owner(ctx);
+		vhost_reset_owner(vid);
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		user_set_mem_table(ctx, &msg);
+		user_set_mem_table(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-		user_set_log_base(ctx, &msg);
+		user_set_log_base(vid, &msg);
 
 		/* it needs a reply */
 		msg.size = sizeof(msg.payload.u64);
@@ -399,26 +396,26 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_NUM:
-		vhost_set_vring_num(ctx, &msg.payload.state);
+		vhost_set_vring_num(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SET_VRING_ADDR:
-		vhost_set_vring_addr(ctx, &msg.payload.addr);
+		vhost_set_vring_addr(vid, &msg.payload.addr);
 		break;
 	case VHOST_USER_SET_VRING_BASE:
-		vhost_set_vring_base(ctx, &msg.payload.state);
+		vhost_set_vring_base(vid, &msg.payload.state);
 		break;
 
 	case VHOST_USER_GET_VRING_BASE:
-		ret = user_get_vring_base(ctx, &msg.payload.state);
+		ret = user_get_vring_base(vid, &msg.payload.state);
 		msg.size = sizeof(msg.payload.state);
 		send_vhost_message(connfd, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_KICK:
-		user_set_vring_kick(ctx, &msg);
+		user_set_vring_kick(vid, &msg);
 		break;
 	case VHOST_USER_SET_VRING_CALL:
-		user_set_vring_call(ctx, &msg);
+		user_set_vring_call(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_ERR:
@@ -434,10 +431,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_ENABLE:
-		user_set_vring_enable(ctx, &msg.payload.state);
+		user_set_vring_enable(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SEND_RARP:
-		user_send_rarp(ctx, &msg);
+		user_send_rarp(vid, &msg);
 		break;
 
 	default:
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 1568c9f..9385af1 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev)
 }
 
 int
-user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 {
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	uint64_t alignment;
 
 	/* unmap old memory regions one by one*/
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev)
 }
 
 void
-user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring call idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_call(ctx, &file);
+	vhost_set_vring_call(vid, &file);
 }
 
 
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  *  device is ready for packet processing.
  */
 void
-user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_kick(ctx, &file);
+	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (notify_ops->new_device(dev) == 0)
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  * when virtio is stopped, qemu will send us the GET_VRING_BASE message.
  */
 int
-user_get_vring_base(struct vhost_device_ctx ctx,
+user_get_vring_base(int vid,
 	struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return -1;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
 		notify_ops->destroy_device(dev);
 
 	/* Here we are safe to get the last used index */
-	vhost_get_vring_base(ctx, state->index, state);
+	vhost_get_vring_base(vid, state->index, state);
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,
  * enable the virtio queue pair.
  */
 int
-user_set_vring_enable(struct vhost_device_ctx ctx,
+user_set_vring_enable(int vid,
 		      struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 	int enable = (int)state->num;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx,
 }
 
 void
-user_set_protocol_features(struct vhost_device_ctx ctx,
+user_set_protocol_features(int vid,
 			   uint64_t protocol_features)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
 		return;
 
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx,
 }
 
 int
-user_set_log_base(struct vhost_device_ctx ctx,
+user_set_log_base(int vid,
 		 struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,
 	uint64_t size, off;
 	void *addr;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,
  * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it.
  */
 int
-user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *msg)
+user_send_rarp(int vid, struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
 	uint8_t *mac = (uint8_t *)&msg->payload.u64;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h
index cefec16..e1b967b 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.h
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h
@@ -45,20 +45,18 @@
 					 (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
 					 (1ULL << VHOST_USER_PROTOCOL_F_RARP))
 
-int user_set_mem_table(struct vhost_device_ctx, struct VhostUserMsg *);
+int user_set_mem_table(int, struct VhostUserMsg *);
 
-void user_set_vring_call(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_call(int, struct VhostUserMsg *);
 
-void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_kick(int, struct VhostUserMsg *);
 
-void user_set_protocol_features(struct vhost_device_ctx ctx,
-				uint64_t protocol_features);
-int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *);
-int user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *);
+void user_set_protocol_features(int vid, uint64_t protocol_features);
+int user_set_log_base(int vid, struct VhostUserMsg *);
+int user_send_rarp(int vid, struct VhostUserMsg *);
 
-int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int user_get_vring_base(int, struct vhost_vring_state *);
 
-int user_set_vring_enable(struct vhost_device_ctx ctx,
-			  struct vhost_vring_state *state);
+int user_set_vring_enable(int vid, struct vhost_vring_state *state);
 
 #endif
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 0a13150..c6d3829 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -108,15 +108,14 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 	return vhost_va;
 }
 
-
 struct virtio_net *
-get_device(struct vhost_device_ctx ctx)
+get_device(int vid)
 {
-	struct virtio_net *dev = vhost_devices[ctx.vid];
+	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.vid);
+			"(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -255,7 +254,7 @@ reset_device(struct virtio_net *dev)
  * list.
  */
 int
-vhost_new_device(struct vhost_device_ctx ctx)
+vhost_new_device(void)
 {
 	struct virtio_net *dev;
 	int i;
@@ -263,7 +262,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.vid);
+			"Failed to allocate memory for new dev.\n");
 		return -1;
 	}
 
@@ -288,9 +287,9 @@ vhost_new_device(struct vhost_device_ctx ctx)
  * cleanup the device and remove it from device configuration linked list.
  */
 void
-vhost_destroy_device(struct vhost_device_ctx ctx)
+vhost_destroy_device(int vid)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return;
@@ -303,17 +302,16 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.vid] = NULL;
+	vhost_devices[vid] = NULL;
 }
 
 void
-vhost_set_ifname(struct vhost_device_ctx ctx,
-	const char *if_name, unsigned int if_len)
+vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)
 {
 	struct virtio_net *dev;
 	unsigned int len;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return;
 
@@ -331,11 +329,11 @@ vhost_set_ifname(struct vhost_device_ctx ctx,
  * the device hasn't been initialised.
  */
 int
-vhost_set_owner(struct vhost_device_ctx ctx)
+vhost_set_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -346,11 +344,11 @@ vhost_set_owner(struct vhost_device_ctx ctx)
  * Called from CUSE IOCTL: VHOST_RESET_OWNER
  */
 int
-vhost_reset_owner(struct vhost_device_ctx ctx)
+vhost_reset_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -369,11 +367,11 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
  * The features that we support are requested.
  */
 int
-vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_get_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -387,13 +385,13 @@ vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * We receive the negotiated features supported by us and the virtio device.
  */
 int
-vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 	uint16_t vhost_hlen;
 	uint16_t i;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 	if (*pu & ~VHOST_FEATURES)
@@ -427,12 +425,11 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * The virtio device sends us the size of the descriptor ring.
  */
 int
-vhost_set_vring_num(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_num(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -531,12 +528,12 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
  * This function then converts these to our address space.
  */
 int
-vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if ((dev == NULL) || (dev->mem == NULL))
 		return -1;
 
@@ -593,12 +590,11 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
  * The virtio device sends us the available ring last used index.
  */
 int
-vhost_set_vring_base(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_base(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -614,12 +610,12 @@ vhost_set_vring_base(struct vhost_device_ctx ctx,
  * We send the virtio device our available ring last used index.
  */
 int
-vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+vhost_get_vring_base(int vid, uint32_t index,
 	struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -637,13 +633,13 @@ vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
  * copied into our process space.
  */
 int
-vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_call(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 	uint32_t cur_qp_idx = file->index / VIRTIO_QNUM;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -674,12 +670,12 @@ vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * This fd gets copied into our process space.
  */
 int
-vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_kick(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -704,11 +700,11 @@ vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * The device will still exist in the device configuration linked list.
  */
 int
-vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_backend(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
index 75fb57e..9812545 100644
--- a/lib/librte_vhost/virtio-net.h
+++ b/lib/librte_vhost/virtio-net.h
@@ -38,6 +38,6 @@
 #include "rte_virtio_net.h"
 
 struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(struct vhost_device_ctx ctx);
+struct virtio_net *get_device(int vid);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (5 preceding siblings ...)
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
@ 2016-05-13  5:24   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
                     ` (13 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:24 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

vhost cuse is now the last reference of the vhost_device_ctx struct;
move it there, and do a rename to "vhost_cuse_device_ctx", to make
it clear that it's "cuse only".

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  |  8 --------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 13 +++++++------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++--
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4de3aa0..4ed5816 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -75,14 +75,6 @@
 #endif
 
 
-/*
- * Structure used to identify device context.
- */
-struct vhost_device_ctx {
-	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	vid;	/* Virtio-net device ID */
-};
-
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 45a9a91..cf6d191 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";
 static struct fuse_session *session;
 
 /*
- * Returns vhost_device_ctx from given fuse_req_t. The index is populated later
- * when the device is added to the device linked list.
+ * Returns vhost_cuse_device_ctx from given fuse_req_t. The
+ * index is populated later when the device is added to the
+ * device linked list.
  */
-static struct vhost_device_ctx
+static struct vhost_cuse_device_ctx
 fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx;
+	struct vhost_cuse_device_ctx ctx;
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void
 vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 {
 	int err = 0;
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		struct fuse_file_info *fi, __rte_unused unsigned flags,
 		const void *in_buf, size_t in_bufsz, size_t out_bufsz)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 	struct vhost_vring_file file;
 	struct vhost_vring_state state;
 	struct vhost_vring_addr addr;
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 34ee6c9..0723a7a 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr,
 }
 
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions)
 {
 	uint64_t size = offsetof(struct vhost_memory, regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)
 	return 0;
 }
 
-int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+cuse_set_backend(struct vhost_cuse_device_ctx ctx,
+		 struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
index eb6b0ba..3f67154 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
@@ -38,11 +38,19 @@
 
 #include "vhost-net.h"
 
+/*
+ * Structure used to identify device context.
+ */
+struct vhost_cuse_device_ctx {
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	vid;	/* Virtio-net device ID */
+};
+
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions);
 
 int
-cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *);
+cuse_set_backend(struct vhost_cuse_device_ctx ctx, struct vhost_vring_file *);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (6 preceding siblings ...)
  2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
                     ` (12 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Introduce a new API rte_vhost_get_numa_node() to get the numa node
from which the virtio_net struct is allocated.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c      | 13 ++++---------
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/rte_virtio_net.h      | 12 ++++++++++++
 lib/librte_vhost/virtio-net.c          | 26 ++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 63538c1..204abff 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -230,7 +230,7 @@ new_device(struct virtio_net *dev)
 	struct vhost_queue *vq;
 	unsigned i;
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	int newnode, ret;
+	int newnode;
 #endif
 
 	if (dev == NULL) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
 	internal = eth_dev->data->dev_private;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	ret  = get_mempolicy(&newnode, NULL, 0, dev,
-			MPOL_F_NODE | MPOL_F_ADDR);
-	if (ret < 0) {
-		RTE_LOG(ERR, PMD, "Unknown numa node\n");
-		return -1;
-	}
-
-	eth_dev->data->numa_node = newnode;
+	newnode = rte_vhost_get_numa_node(dev->vid);
+	if (newnode > 0)
+		eth_dev->data->numa_node = newnode;
 #endif
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 3d8709e..bf7b000 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -20,3 +20,10 @@ DPDK_2.1 {
 	rte_vhost_driver_unregister;
 
 } DPDK_2.0;
+
+DPDK_16.07 {
+	global:
+
+	rte_vhost_get_numa_node;
+
+} DPDK_16.04;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index bc64e89..b8e9b02 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get the numa node from which the virtio net device's memory
+ * is allocated.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The numa node, -1 on failure
+ */
+int rte_vhost_get_numa_node(int vid);
+
+/**
  * 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 c6d3829..25b6515 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	return 0;
 }
 
+int
+rte_vhost_get_numa_node(int vid)
+{
+#ifdef RTE_LIBRTE_VHOST_NUMA
+	struct virtio_net *dev = get_device(vid);
+	int numa_node;
+	int ret;
+
+	if (dev == NULL)
+		return -1;
+
+	ret = get_mempolicy(&numa_node, NULL, 0, dev,
+			    MPOL_F_NODE | MPOL_F_ADDR);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%d) failed to query numa node: %d\n", vid, ret);
+		return -1;
+	}
+
+	return numa_node;
+#else
+	RTE_SET_USED(vid);
+	return -1;
+#endif
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (7 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
                     ` (11 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Introduce a new API rte_vhost_get_queue_num() to export the number of
queues.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c      |  2 +-
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/rte_virtio_net.h      | 11 +++++++++++
 lib/librte_vhost/virtio-net.c          | 11 +++++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 204abff..fe0ce90 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -270,7 +270,7 @@ new_device(struct virtio_net *dev)
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
+	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;
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index bf7b000..a65fa21 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -25,5 +25,6 @@ DPDK_16.07 {
 	global:
 
 	rte_vhost_get_numa_node;
+	rte_vhost_get_queue_num;
 
 } DPDK_16.04;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index b8e9b02..de56b1b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -257,6 +257,17 @@ int rte_vhost_driver_session_start(void);
 int rte_vhost_get_numa_node(int vid);
 
 /**
+ * Get the number of queues the device supports.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The number of queues, 0 on failure
+ */
+uint32_t rte_vhost_get_queue_num(int vid);
+
+/**
  * 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 25b6515..a03ff30 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -756,6 +756,17 @@ rte_vhost_get_numa_node(int vid)
 #endif
 }
 
+uint32_t
+rte_vhost_get_queue_num(int vid)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return 0;
+
+	return dev->virt_qp_nb;
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (8 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
                     ` (10 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Introduce a new API rte_vhost_get_ifname() to export the ifname to
application.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 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

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (9 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
                     ` (9 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

The new API rte_vhost_avail_entries() is actually a rename of
rte_vring_available_entries(), with the "vring" to "vhost" name
change to keep the consistency of other vhost exported APIs.

This change could let us avoid the dependency of "virtio_net"
struct, to prepare for the ABI refactoring.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 doc/guides/rel_notes/release_16_07.rst |  2 ++
 examples/vhost/main.c                  |  4 ++--
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/rte_virtio_net.h      | 24 +++++++++++++-----------
 lib/librte_vhost/virtio-net.c          | 17 +++++++++++++++++
 5 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst
index f6d543c..d293eda 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -97,6 +97,8 @@ This section should contain API changes. Sample format:
   ibadcrc, ibadlen, imcasts, fdirmatch, fdirmiss,
   tx_pause_xon, rx_pause_xon, tx_pause_xoff, rx_pause_xoff.
 
+* ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``.
+
 
 ABI Changes
 -----------
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index cb04585..67ef0ad 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1055,13 +1055,13 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vring_available_entries(dev,
+	    unlikely(rx_count > rte_vhost_avail_entries(dev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vring_available_entries(dev,
+			if (rx_count <= rte_vhost_avail_entries(dev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 4608e3b..93f1188 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_avail_entries;
 	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 0898e8b..0427461 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -184,17 +184,6 @@ struct virtio_net_device_ops {
 	int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 };
 
-static inline uint16_t __attribute__((always_inline))
-rte_vring_available_entries(struct virtio_net *dev, uint16_t queue_id)
-{
-	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
-
-	if (!vq->enabled)
-		return 0;
-
-	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
-}
-
 /**
  * Function to convert guest physical addresses to vhost virtual addresses.
  * This is used to convert guest virtio buffer addresses.
@@ -285,6 +274,19 @@ uint32_t rte_vhost_get_queue_num(int vid);
 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
 
 /**
+ * Get how many avail entries are left in the queue
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param queue_id
+ *  virtio queue index
+ *
+ * @return
+ *  num of avail entires left
+ */
+uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
+
+/**
  * 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 375c9d4..115eba4 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -783,6 +783,23 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len)
 	return 0;
 }
 
+uint16_t
+rte_vhost_avail_entries(int vid, uint16_t queue_id)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	vq = dev->virtqueue[queue_id];
+	if (!vq->enabled)
+		return 0;
+
+	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (10 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
                     ` (8 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

This change could let us avoid the dependency of "virtio_net"
struct, to prepare for the ABI refactoring.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 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

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (11 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
                     ` (7 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

With all the previous prepare works, we are just one step away from
the final ABI refactoring. That is, to change current API to let them
stick to vid instead of the old virtio_net dev.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---

v2: update release note
---
 doc/guides/rel_notes/release_16_07.rst        |  7 ++++
 drivers/net/vhost/rte_eth_vhost.c             | 47 +++++++++------------------
 examples/vhost/main.c                         | 25 +++++++-------
 lib/librte_vhost/rte_virtio_net.h             | 18 +++++-----
 lib/librte_vhost/vhost_rxtx.c                 | 15 +++++++--
 lib/librte_vhost/vhost_user/virtio-net-user.c | 14 ++++----
 lib/librte_vhost/virtio-net.c                 | 17 ++++++----
 7 files changed, 75 insertions(+), 68 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst
index d293eda..ebc507b 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -99,6 +99,10 @@ This section should contain API changes. Sample format:
 
 * ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``.
 
+* All existing vhost APIs and callbacks with ``virtio_net`` struct pointer
+  as the parameter have been changed due to the ABI refactoring mentioned
+  below: it's replaced by "int vid".
+
 
 ABI Changes
 -----------
@@ -110,6 +114,9 @@ ABI Changes
 * The ``rte_port_source_params`` structure has new fields to support PCAP file.
   It was already in release 16.04 with ``RTE_NEXT_ABI`` flag.
 
+* vhost ABI refactoring has been made: ``virtio_net`` structure is never
+  exported to application any more. Instead, a handle, ``vid``, has been
+  used to represent this structure internally.
 
 Shared Library Versions
 -----------------------
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index de0f25e..56c1c36 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -71,9 +71,9 @@ static struct ether_addr base_eth_addr = {
 };
 
 struct vhost_queue {
+	int vid;
 	rte_atomic32_t allow_queuing;
 	rte_atomic32_t while_queuing;
-	struct virtio_net *device;
 	struct pmd_internal *internal;
 	struct rte_mempool *mb_pool;
 	uint8_t port;
@@ -139,7 +139,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Dequeue packets from guest TX queue */
-	nb_rx = rte_vhost_dequeue_burst(r->device,
+	nb_rx = rte_vhost_dequeue_burst(r->vid,
 			r->virtqueue_id, r->mb_pool, bufs, nb_bufs);
 
 	r->rx_pkts += nb_rx;
@@ -170,7 +170,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Enqueue packets to guest RX queue */
-	nb_tx = rte_vhost_enqueue_burst(r->device,
+	nb_tx = rte_vhost_enqueue_burst(r->vid,
 			r->virtqueue_id, bufs, nb_bufs);
 
 	r->tx_pkts += nb_tx;
@@ -222,7 +222,7 @@ find_internal_resource(char *ifname)
 }
 
 static int
-new_device(struct virtio_net *dev)
+new_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct internal_list *list;
@@ -234,12 +234,7 @@ new_device(struct virtio_net *dev)
 	int newnode;
 #endif
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return -1;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(INFO, PMD, "Invalid device name: %s\n", ifname);
@@ -250,7 +245,7 @@ new_device(struct virtio_net *dev)
 	internal = eth_dev->data->dev_private;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	newnode = rte_vhost_get_numa_node(dev->vid);
+	newnode = rte_vhost_get_numa_node(vid);
 	if (newnode > 0)
 		eth_dev->data->numa_node = newnode;
 #endif
@@ -259,7 +254,7 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
@@ -267,13 +262,13 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < rte_vhost_get_queue_num(dev->vid) * VIRTIO_QNUM; i++)
-		rte_vhost_enable_guest_notification(dev, i, 0);
+	for (i = 0; i < rte_vhost_get_queue_num(vid) * VIRTIO_QNUM; i++)
+		rte_vhost_enable_guest_notification(vid, i, 0);
 
 	eth_dev->data->dev_link.link_status = ETH_LINK_UP;
 
@@ -298,7 +293,7 @@ new_device(struct virtio_net *dev)
 }
 
 static void
-destroy_device(volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct vhost_queue *vq;
@@ -306,12 +301,7 @@ destroy_device(volatile struct virtio_net *dev)
 	char ifname[PATH_MAX];
 	unsigned i;
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", ifname);
@@ -343,13 +333,13 @@ destroy_device(volatile struct virtio_net *dev)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 	for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 
 	RTE_LOG(INFO, PMD, "Connection closed\n");
@@ -358,19 +348,14 @@ destroy_device(volatile struct virtio_net *dev)
 }
 
 static int
-vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)
+vring_state_changed(int vid, 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;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", ifname);
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index c408577..f3a6277 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -808,7 +808,7 @@ virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev,
 {
 	uint16_t ret;
 
-	ret = rte_vhost_enqueue_burst(dst_vdev->dev, VIRTIO_RXQ, &m, 1);
+	ret = rte_vhost_enqueue_burst(dst_vdev->vid, VIRTIO_RXQ, &m, 1);
 	if (enable_stats) {
 		rte_atomic64_inc(&dst_vdev->stats.rx_total_atomic);
 		rte_atomic64_add(&dst_vdev->stats.rx_atomic, ret);
@@ -1054,7 +1054,6 @@ static inline void __attribute__((always_inline))
 drain_eth_rx(struct vhost_dev *vdev)
 {
 	uint16_t rx_count, enqueue_count;
-	struct virtio_net *dev = vdev->dev;
 	struct rte_mbuf *pkts[MAX_PKT_BURST];
 
 	rx_count = rte_eth_rx_burst(ports[0], vdev->vmdq_rx_q,
@@ -1068,19 +1067,19 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vhost_avail_entries(dev->vid,
+	    unlikely(rx_count > rte_vhost_avail_entries(vdev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vhost_avail_entries(dev->vid,
+			if (rx_count <= rte_vhost_avail_entries(vdev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
 	}
 
-	enqueue_count = rte_vhost_enqueue_burst(dev, VIRTIO_RXQ,
+	enqueue_count = rte_vhost_enqueue_burst(vdev->vid, VIRTIO_RXQ,
 						pkts, rx_count);
 	if (enable_stats) {
 		rte_atomic64_add(&vdev->stats.rx_total_atomic, rx_count);
@@ -1097,7 +1096,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	uint16_t count;
 	uint16_t i;
 
-	count = rte_vhost_dequeue_burst(vdev->dev, VIRTIO_TXQ, mbuf_pool,
+	count = rte_vhost_dequeue_burst(vdev->vid, VIRTIO_TXQ, mbuf_pool,
 					pkts, MAX_PKT_BURST);
 
 	/* setup VMDq for the first packet */
@@ -1183,12 +1182,12 @@ switch_worker(void *arg __rte_unused)
  * of dev->remove=1 which can cause an infinite loop in the rte_pause loop.
  */
 static void
-destroy_device (volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct vhost_dev *vdev;
 	int lcore;
 
-	vdev = find_vhost_dev_by_vid(dev->vid);
+	vdev = find_vhost_dev_by_vid(vid);
 	if (!vdev)
 		return;
 	/*set the remove flag. */
@@ -1228,12 +1227,11 @@ destroy_device (volatile struct virtio_net *dev)
  * and the allocated to a specific data core.
  */
 static int
-new_device (struct virtio_net *dev)
+new_device(int vid)
 {
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
@@ -1242,7 +1240,6 @@ new_device (struct virtio_net *dev)
 			vid);
 		return -1;
 	}
-	vdev->dev = dev;
 	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, next);
@@ -1265,8 +1262,8 @@ new_device (struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num++;
 
 	/* Disable notifications. */
-	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
-	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_RXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_TXQ, 0);
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
@@ -1322,7 +1319,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->vid,
+				vdev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 0427461..370345e 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -178,10 +178,10 @@ struct virtio_memory {
  *
  */
 struct virtio_net_device_ops {
-	int (*new_device)(struct virtio_net *);	/**< Add device. */
-	void (*destroy_device)(volatile struct virtio_net *);	/**< Remove device. */
+	int (*new_device)(int vid);		/**< Add device. */
+	void (*destroy_device)(int vid);	/**< Remove device. */
 
-	int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 };
 
 /**
@@ -220,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);
 /* Returns currently supported vhost features */
 uint64_t rte_vhost_feature_get(void);
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t queue_id, int enable);
+int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
 
 /* Register vhost driver. dev_name could be different for multiple instance support. */
 int rte_vhost_driver_register(const char *dev_name);
@@ -291,8 +291,8 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
  * 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
  * added to the RX queue.
- * @param dev
- *  virtio-net device
+ * @param vid
+ *  virtio-net device ID
  * @param queue_id
  *  virtio queue index in mq case
  * @param pkts
@@ -302,14 +302,14 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
  * @return
  *  num of packets enqueued
  */
-uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count);
 
 /**
  * This function gets guest buffers from the virtio device TX virtqueue,
  * construct host mbufs, copies guest buffer content to host mbufs and
  * store them in pkts to be processed.
- * @param dev
+ * @param vid
  *  virtio-net device
  * @param queue_id
  *  virtio queue index in mq case
@@ -322,7 +322,7 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
  * @return
  *  num of packets dequeued
  */
-uint16_t rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
 
 #endif /* _VIRTIO_NET_H_ */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 8d87508..08cab08 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,6 +46,7 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
+#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 }
 
 uint16_t
-rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return 0;
+
 	if (dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF))
 		return virtio_dev_merge_rx(dev, queue_id, pkts, count);
 	else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 }
 
 uint16_t
-rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev;
 	struct rte_mbuf *rarp_mbuf = NULL;
 	struct vhost_virtqueue *vq;
 	uint32_t desc_indexes[MAX_PKT_BURST];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t free_entries;
 	uint16_t avail_idx;
 
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 9385af1..7fa69a7 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 	/* Remove from the data plane. */
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
 
+	if (!dev)
+		return;
+
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
 		file.fd = VIRTIO_INVALID_EVENTFD;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (notify_ops->new_device(dev) == 0)
+		if (notify_ops->new_device(vid) == 0)
 			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,
 		return -1;
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 
 	/* Here we are safe to get the last used index */
 	vhost_get_vring_base(vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,
 		"set queue enable: %d to qp idx: %d\n",
 		enable, state->index);
 
-	if (notify_ops->vring_state_changed) {
-		notify_ops->vring_state_changed(dev, state->index, enable);
-	}
+	if (notify_ops->vring_state_changed)
+		notify_ops->vring_state_changed(vid, state->index, enable);
 
 	dev->virtqueue[state->index]->enabled = enable;
 
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 115eba4..ea216c0 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 1);
@@ -354,7 +354,7 @@ vhost_reset_owner(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 0);
@@ -718,13 +718,13 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			if (notify_ops->new_device(dev) < 0)
+			if (notify_ops->new_device(vid) < 0)
 				return -1;
 			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
 	} else if (file->fd == VIRTIO_DEV_STOPPED) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	return 0;
@@ -800,9 +800,14 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)
 	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
 }
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev,
-	uint16_t queue_id, int enable)
+int
+rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return -1;
+
 	if (enable) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"guest notification isn't supported.\n");
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (12 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
                     ` (6 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

We are now safe to move all those internal structs/macros/functions to
vhost-net.h, to hide them from external access.

This patch also breaks long lines and removes some redundant comments.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h            | 139 -------------------------
 lib/librte_vhost/vhost-net.h                 | 148 +++++++++++++++++++++++++++
 lib/librte_vhost/vhost_user/vhost-net-user.h |   2 +
 3 files changed, 150 insertions(+), 139 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 370345e..fc1d799 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -51,125 +51,9 @@
 #include <rte_mempool.h>
 #include <rte_ether.h>
 
-struct rte_mbuf;
-
-#define VHOST_MEMORY_MAX_NREGIONS 8
-
-/* Used to indicate that the device is running on a data core */
-#define VIRTIO_DEV_RUNNING 1
-
-/* Backend value set by guest. */
-#define VIRTIO_DEV_STOPPED -1
-
-
 /* Enum for virtqueue management. */
 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
 
-#define BUF_VECTOR_MAX 256
-
-/**
- * Structure contains buffer address, length and descriptor index
- * from vring to do scatter RX.
- */
-struct buf_vector {
-	uint64_t buf_addr;
-	uint32_t buf_len;
-	uint32_t desc_idx;
-};
-
-/**
- * Structure contains variables relevant to RX/TX virtqueues.
- */
-struct vhost_virtqueue {
-	struct vring_desc	*desc;			/**< Virtqueue descriptor ring. */
-	struct vring_avail	*avail;			/**< Virtqueue available ring. */
-	struct vring_used	*used;			/**< Virtqueue used ring. */
-	uint32_t		size;			/**< Size of descriptor ring. */
-	int			backend;		/**< Backend value to determine if device should started/stopped. */
-	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
-	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
-	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
-#define VIRTIO_INVALID_EVENTFD		(-1)
-#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
-	int			callfd;			/**< Used to notify the guest (trigger interrupt). */
-	int			kickfd;			/**< Currently unused as polling mode is enabled. */
-	int			enabled;
-	uint64_t		log_guest_addr;		/**< Physical address of used ring, for logging */
-	uint64_t		reserved[15];		/**< Reserve some spaces for future extension. */
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];	/**< for scatter RX. */
-} __rte_cache_aligned;
-
-/* Old kernels have no such macro defined */
-#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
- #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
-#endif
-
-
-/*
- * Make an extra wrapper for VIRTIO_NET_F_MQ and
- * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
- * introduced since kernel v3.8. This makes our
- * code buildable for older kernel.
- */
-#ifdef VIRTIO_NET_F_MQ
- #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
- #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
-#else
- #define VHOST_MAX_QUEUE_PAIRS	1
- #define VHOST_SUPPORTS_MQ	0
-#endif
-
-/*
- * Define virtio 1.0 for older kernels
- */
-#ifndef VIRTIO_F_VERSION_1
- #define VIRTIO_F_VERSION_1 32
-#endif
-
-/**
- * Device structure contains all configuration information relating to the device.
- */
-struct virtio_net {
-	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
-	uint64_t		features;	/**< Negotiated feature set. */
-	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			vid;		/**< device identifier. */
-	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
-#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
-	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
-	uint32_t		virt_qp_nb;	/**< number of queue pair we have allocated */
-	void			*priv;		/**< private context */
-	uint64_t		log_size;	/**< Size of log area */
-	uint64_t		log_base;	/**< Where dirty pages are logged */
-	struct ether_addr	mac;		/**< MAC address */
-	rte_atomic16_t		broadcast_rarp;	/**< A flag to tell if we need broadcast rarp packet */
-	uint64_t		reserved[61];	/**< Reserve some spaces for future extension. */
-	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];	/**< Contains all virtqueue information. */
-} __rte_cache_aligned;
-
-/**
- * Information relating to memory regions including offsets to addresses in QEMUs memory file.
- */
-struct virtio_memory_regions {
-	uint64_t	guest_phys_address;	/**< Base guest physical address of region. */
-	uint64_t	guest_phys_address_end;	/**< End guest physical address of region. */
-	uint64_t	memory_size;		/**< Size of region. */
-	uint64_t	userspace_address;	/**< Base userspace address of region. */
-	uint64_t	address_offset;		/**< Offset of region for address translation. */
-};
-
-
-/**
- * Memory structure includes region and mapping information.
- */
-struct virtio_memory {
-	uint64_t	base_address;	/**< Base QEMU userspace address of the memory file. */
-	uint64_t	mapped_address;	/**< Mapped address of memory file base in our applications memory space. */
-	uint64_t	mapped_size;	/**< Total size of memory file. */
-	uint32_t	nregions;	/**< Number of memory regions. */
-	struct virtio_memory_regions      regions[0]; /**< Memory region information. */
-};
-
 /**
  * Device and vring operations.
  *
@@ -185,29 +69,6 @@ struct virtio_net_device_ops {
 };
 
 /**
- * Function to convert guest physical addresses to vhost virtual addresses.
- * This is used to convert guest virtio buffer addresses.
- */
-static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
-{
-	struct virtio_memory_regions *region;
-	uint32_t regionidx;
-	uint64_t vhost_va = 0;
-
-	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
-		region = &dev->mem->regions[regionidx];
-		if ((guest_pa >= region->guest_phys_address) &&
-			(guest_pa <= region->guest_phys_address_end)) {
-			vhost_va = region->address_offset + guest_pa;
-			break;
-		}
-	}
-	return vhost_va;
-}
-
-
-/**
  *  Disable features in feature_mask. Returns 0 on success.
  */
 int rte_vhost_feature_disable(uint64_t feature_mask);
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4ed5816..3edeb92 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,6 +43,133 @@
 
 #include "rte_virtio_net.h"
 
+/* Used to indicate that the device is running on a data core */
+#define VIRTIO_DEV_RUNNING 1
+
+/* Backend value set by guest. */
+#define VIRTIO_DEV_STOPPED -1
+
+#define BUF_VECTOR_MAX 256
+
+/**
+ * Structure contains buffer address, length and descriptor index
+ * from vring to do scatter RX.
+ */
+struct buf_vector {
+	uint64_t buf_addr;
+	uint32_t buf_len;
+	uint32_t desc_idx;
+};
+
+/**
+ * Structure contains variables relevant to RX/TX virtqueues.
+ */
+struct vhost_virtqueue {
+	struct vring_desc	*desc;
+	struct vring_avail	*avail;
+	struct vring_used	*used;
+	uint32_t		size;
+	uint16_t		vhost_hlen;
+
+	/* Last index used on the available ring */
+	volatile uint16_t	last_used_idx;
+	/* Used for multiple devices reserving buffers */
+	volatile uint16_t	last_used_idx_res;
+#define VIRTIO_INVALID_EVENTFD		(-1)
+#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
+
+	/* Backend value to determine if device should started/stopped */
+	int			backend;
+	/* Used to notify the guest (trigger interrupt) */
+	int			callfd;
+	/* Currently unused as polling mode is enabled */
+	int			kickfd;
+	int			enabled;
+
+	/* Physical address of used ring, for logging */
+	uint64_t		log_guest_addr;
+	uint64_t		reserved[15];
+	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
+} __rte_cache_aligned;
+
+/* Old kernels have no such macro defined */
+#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
+ #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
+#endif
+
+
+/*
+ * Make an extra wrapper for VIRTIO_NET_F_MQ and
+ * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
+ * introduced since kernel v3.8. This makes our
+ * code buildable for older kernel.
+ */
+#ifdef VIRTIO_NET_F_MQ
+ #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
+ #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
+#else
+ #define VHOST_MAX_QUEUE_PAIRS	1
+ #define VHOST_SUPPORTS_MQ	0
+#endif
+
+/*
+ * Define virtio 1.0 for older kernels
+ */
+#ifndef VIRTIO_F_VERSION_1
+ #define VIRTIO_F_VERSION_1 32
+#endif
+
+/**
+ * Device structure contains all configuration information relating
+ * to the device.
+ */
+struct virtio_net {
+	/* Frontend (QEMU) memory and memory region information */
+	struct virtio_memory	*mem;
+	uint64_t		features;
+	uint64_t		protocol_features;
+	int			vid;
+	uint32_t		flags;
+#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
+	char			ifname[IF_NAME_SZ];
+	uint32_t		virt_qp_nb;
+	void			*priv;
+	uint64_t		log_size;
+	uint64_t		log_base;
+	struct ether_addr	mac;
+
+	/* to tell if we need broadcast rarp packet */
+	rte_atomic16_t		broadcast_rarp;
+	uint64_t		reserved[61];
+	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
+} __rte_cache_aligned;
+
+/**
+ * Information relating to memory regions including offsets to
+ * addresses in QEMUs memory file.
+ */
+struct virtio_memory_regions {
+	uint64_t guest_phys_address;
+	uint64_t guest_phys_address_end;
+	uint64_t memory_size;
+	uint64_t userspace_address;
+	uint64_t address_offset;
+};
+
+
+/**
+ * Memory structure includes region and mapping information.
+ */
+struct virtio_memory {
+	/* Base QEMU userspace address of the memory file. */
+	uint64_t base_address;
+	uint64_t mapped_address;
+	uint64_t mapped_size;
+	uint32_t nregions;
+	struct virtio_memory_regions regions[0];
+};
+
+
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
@@ -74,6 +201,27 @@
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
+/**
+ * Function to convert guest physical addresses to vhost virtual addresses.
+ * This is used to convert guest virtio buffer addresses.
+ */
+static inline uint64_t __attribute__((always_inline))
+gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
+{
+	struct virtio_memory_regions *region;
+	uint32_t regionidx;
+	uint64_t vhost_va = 0;
+
+	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
+		region = &dev->mem->regions[regionidx];
+		if ((guest_pa >= region->guest_phys_address) &&
+			(guest_pa <= region->guest_phys_address_end)) {
+			vhost_va = region->address_offset + guest_pa;
+			break;
+		}
+	}
+	return vhost_va;
+}
 
 int vhost_new_device(void);
 void vhost_destroy_device(int);
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h
index e3bb413..ec68b96 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.h
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
@@ -47,6 +47,8 @@ struct vhost_server {
 
 /* refer to hw/virtio/vhost-user.c */
 
+#define VHOST_MEMORY_MAX_NREGIONS 8
+
 typedef enum VhostUserRequest {
 	VHOST_USER_NONE = 0,
 	VHOST_USER_GET_FEATURES = 1,
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (13 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
                     ` (5 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

The "reserved" field in virtio_net and vhost_virtqueue struct is not
necessary any more. We now expose virtio_net device with a number "vid".

This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access
it is to expose it by a function, but I doubt that's needed or worthwhile.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 3edeb92..c133ea8 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -88,7 +88,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	uint64_t		reserved[15];
 	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
@@ -133,14 +132,12 @@ struct virtio_net {
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
-	void			*priv;
 	uint64_t		log_size;
 	uint64_t		log_base;
 	struct ether_addr	mac;
 
 	/* to tell if we need broadcast rarp packet */
 	rte_atomic16_t		broadcast_rarp;
-	uint64_t		reserved[61];
 	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
 } __rte_cache_aligned;
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (14 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
                     ` (4 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

It barely has anything useful there, just 2 functions prototype. Here
move them to vhost-net.h, and delete it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h                  |  3 ++
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  1 -
 lib/librte_vhost/vhost_rxtx.c                 |  1 -
 lib/librte_vhost/vhost_user/virtio-net-user.c |  1 -
 lib/librte_vhost/virtio-net.c                 |  1 -
 lib/librte_vhost/virtio-net.h                 | 43 ---------------------------
 6 files changed, 3 insertions(+), 47 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index c133ea8..dbd2d62 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -220,6 +220,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
 	return vhost_va;
 }
 
+struct virtio_net_device_ops const *notify_ops;
+struct virtio_net *get_device(int vid);
+
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 0723a7a..552be7d 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -54,7 +54,6 @@
 #include "rte_virtio_net.h"
 #include "vhost-net.h"
 #include "virtio-net-cdev.h"
-#include "virtio-net.h"
 #include "eventfd_copy.h"
 
 /* Line size for reading maps file. */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 08cab08..65278bb 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,7 +46,6 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 7fa69a7..6463bdd 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -43,7 +43,6 @@
 #include <rte_common.h>
 #include <rte_log.h>
 
-#include "virtio-net.h"
 #include "virtio-net-user.h"
 #include "vhost-net-user.h"
 #include "vhost-net.h"
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index ea216c0..13dc021 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -53,7 +53,6 @@
 #include <rte_virtio_net.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_VHOST_DEVICE	1024
 static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
deleted file mode 100644
index 9812545..0000000
--- a/lib/librte_vhost/virtio-net.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _VIRTIO_NET_H
-#define _VIRTIO_NET_H
-
-#include "vhost-net.h"
-#include "rte_virtio_net.h"
-
-struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(int vid);
-
-#endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (15 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
                     ` (3 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

"virtio_net_device_ops" is the only left open struct that an application
can access, therefore, it's the only place that might introduce potential
ABI break in future for extension.

So, do some reservation for it. 5 should be pretty enough, considering
that we have barely touched it for a long while. Another reason to
choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit
machine.

With this, it's confidence to say that we might be able to be free from
the ABI violation forever.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index fc1d799..bc2b74b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -66,6 +66,8 @@ struct virtio_net_device_ops {
 	void (*destroy_device)(int vid);	/**< Remove device. */
 
 	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+
+	void *reserved[5]; /**< Reserved for future extension */
 };
 
 /**
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (16 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
                     ` (2 subsequent siblings)
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Yuanhan Liu

Virtio net header length is set per device, but not per queue. So, there
is no reason to store it in vhost_virtqueue struct, instead, we should
store it in virtio_net struct, to make one copy only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h  |  2 +-
 lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++--------------------
 lib/librte_vhost/virtio-net.c | 13 ++-----------
 3 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index dbd2d62..590a039 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -69,7 +69,6 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;
 	struct vring_used	*used;
 	uint32_t		size;
-	uint16_t		vhost_hlen;
 
 	/* Last index used on the available ring */
 	volatile uint16_t	last_used_idx;
@@ -129,6 +128,7 @@ struct virtio_net {
 	uint64_t		protocol_features;
 	int			vid;
 	uint32_t		flags;
+	uint16_t		vhost_hlen;
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 65278bb..c9cd1c5 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 }
 
 static inline void
-copy_virtio_net_hdr(struct vhost_virtqueue *vq, uint64_t desc_addr,
+copy_virtio_net_hdr(struct virtio_net *dev, uint64_t desc_addr,
 		    struct virtio_net_hdr_mrg_rxbuf hdr)
 {
-	if (vq->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
+	if (dev->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
 		*(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr = hdr;
 	else
 		*(struct virtio_net_hdr *)(uintptr_t)desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, desc->addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, desc->addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_offset = vq->vhost_hlen;
-	desc_avail  = desc->len - vq->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
 
 	*copied = rte_pktmbuf_pkt_len(m);
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 		vq->used->ring[used_idx].id = desc_idx;
 		if (unlikely(err))
-			vq->used->ring[used_idx].len = vq->vhost_hlen;
+			vq->used->ring[used_idx].len = dev->vhost_hlen;
 		else
-			vq->used->ring[used_idx].len = copied + vq->vhost_hlen;
+			vq->used->ring[used_idx].len = copied + dev->vhost_hlen;
 		vhost_log_used_vring(dev, vq,
 			offsetof(struct vring_used, ring[used_idx]),
 			sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
+	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
 	mbuf_offset = 0;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
-		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen;
+		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	uint32_t nr_desc = 1;
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	/* Retrieve virtio net header */
 	hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
-	desc_avail  = desc->len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_offset = 0;
 	mbuf_avail  = m->buf_len - RTE_PKTMBUF_HEADROOM;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 13dc021..835ab3a 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -387,8 +387,6 @@ int
 vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
-	uint16_t vhost_hlen;
-	uint16_t i;
 
 	dev = get_device(vid);
 	if (dev == NULL)
@@ -399,9 +397,9 @@ vhost_set_features(int vid, uint64_t *pu)
 	dev->features = *pu;
 	if (dev->features &
 		((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {
-		vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
 	} else {
-		vhost_hlen = sizeof(struct virtio_net_hdr);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -409,13 +407,6 @@ vhost_set_features(int vid, uint64_t *pu)
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
-	for (i = 0; i < dev->virt_qp_nb; i++) {
-		uint16_t base_idx = i * VIRTIO_QNUM;
-
-		dev->virtqueue[base_idx + VIRTIO_RXQ]->vhost_hlen = vhost_hlen;
-		dev->virtqueue[base_idx + VIRTIO_TXQ]->vhost_hlen = vhost_hlen;
-	}
-
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (17 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
@ 2016-05-13  5:25   ` Yuanhan Liu
  2016-05-26 17:04   ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
  20 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-13  5:25 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, huawei.xie, Panu Matilainen, Tetsuya Mukawa,
	Traynor Kevin, Rich Lane, Ilya Maximets, Yuanhan Liu

From: Ilya Maximets <i.maximets@samsung.com>

Array of buf_vector's is just an array for temporary storing information
about available descriptors. It used only locally in virtio_dev_merge_rx()
and there is no reason for that array to be shared.

Fix that by allocating local buf_vec inside virtio_dev_merge_rx().

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost-net.h  |  1 -
 lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++-------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 590a039..162ad04 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -87,7 +87,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
 /* Old kernels have no such macro defined */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index c9cd1c5..96720db 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -335,7 +335,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 static inline int
 fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
-	     uint32_t *allocated, uint32_t *vec_idx)
+	     uint32_t *allocated, uint32_t *vec_idx,
+	     struct buf_vector *buf_vec)
 {
 	uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
 	uint32_t vec_id = *vec_idx;
@@ -346,9 +347,9 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
 			return -1;
 
 		len += vq->desc[idx].len;
-		vq->buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
-		vq->buf_vec[vec_id].buf_len  = vq->desc[idx].len;
-		vq->buf_vec[vec_id].desc_idx = idx;
+		buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
+		buf_vec[vec_id].buf_len  = vq->desc[idx].len;
+		buf_vec[vec_id].desc_idx = idx;
 		vec_id++;
 
 		if ((vq->desc[idx].flags & VRING_DESC_F_NEXT) == 0)
@@ -371,7 +372,8 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
  */
 static inline int
 reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
-			    uint16_t *start, uint16_t *end)
+			    uint16_t *start, uint16_t *end,
+			    struct buf_vector *buf_vec)
 {
 	uint16_t res_start_idx;
 	uint16_t res_cur_idx;
@@ -393,7 +395,7 @@ again:
 			return -1;
 
 		if (unlikely(fill_vec_buf(vq, res_cur_idx, &allocated,
-					  &vec_idx) < 0))
+					  &vec_idx, buf_vec) < 0))
 			return -1;
 
 		res_cur_idx++;
@@ -427,7 +429,7 @@ again:
 static inline uint32_t __attribute__((always_inline))
 copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			    uint16_t res_start_idx, uint16_t res_end_idx,
-			    struct rte_mbuf *m)
+			    struct rte_mbuf *m, struct buf_vector *buf_vec)
 {
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 	uint32_t vec_idx = 0;
@@ -444,10 +446,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
+	if (buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
-	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+	desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
@@ -456,10 +458,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	vhost_log_write(dev, buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
 	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_avail  = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
 	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -467,7 +469,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	while (mbuf_avail != 0 || m->next != NULL) {
 		/* done with current desc buf, get the next one */
 		if (desc_avail == 0) {
-			desc_idx = vq->buf_vec[vec_idx].desc_idx;
+			desc_idx = buf_vec[vec_idx].desc_idx;
 
 			if (!(vq->desc[desc_idx].flags & VRING_DESC_F_NEXT)) {
 				/* Update used ring with desc information */
@@ -481,12 +483,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			}
 
 			vec_idx++;
-			desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+			desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 
 			/* Prefetch buffer address. */
 			rte_prefetch0((void *)(uintptr_t)desc_addr);
 			desc_offset = 0;
-			desc_avail  = vq->buf_vec[vec_idx].buf_len;
+			desc_avail  = buf_vec[vec_idx].buf_len;
 		}
 
 		/* done with current mbuf, get the next one */
@@ -501,7 +503,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		rte_memcpy((void *)((uintptr_t)(desc_addr + desc_offset)),
 			rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
 			cpy_len);
-		vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr + desc_offset,
+		vhost_log_write(dev, buf_vec[vec_idx].buf_addr + desc_offset,
 			cpy_len);
 		PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset),
 			cpy_len, 0);
@@ -513,7 +515,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	}
 
 	used_idx = cur_idx & (vq->size - 1);
-	vq->used->ring[used_idx].id = vq->buf_vec[vec_idx].desc_idx;
+	vq->used->ring[used_idx].id = buf_vec[vec_idx].desc_idx;
 	vq->used->ring[used_idx].len = desc_offset;
 	vhost_log_used_vring(dev, vq,
 		offsetof(struct vring_used, ring[used_idx]),
@@ -529,6 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	struct vhost_virtqueue *vq;
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
+	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 
 	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
@@ -548,8 +551,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
 		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
-		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
-							 &start, &end) < 0)) {
+		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len, &start,
+							 &end, buf_vec) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
 				dev->vid);
@@ -557,7 +560,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		nr_used = copy_mbuf_to_desc_mergeable(dev, vq, start, end,
-						      pkts[pkt_idx]);
+						      pkts[pkt_idx], buf_vec);
 		rte_smp_wmb();
 
 		/*
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (18 preceding siblings ...)
  2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
@ 2016-05-26 17:04   ` Rich Lane
  2016-05-27  1:36     ` Yuanhan Liu
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
  20 siblings, 1 reply; 76+ messages in thread
From: Rich Lane @ 2016-05-26 17:04 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: dev, Thomas Monjalon, huawei.xie, Panu Matilainen,
	Tetsuya Mukawa, Traynor Kevin

On Thu, May 12, 2016 at 10:24 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
wrote:

> v2: - exported ifname as well to fix a vhost-pmd issue reported
>       by Rich
>     - separated the big patch that introduces several new APIs
>       into some small patches.
>     - updated release note
>     - updated version.map
>

Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring
  2016-05-26 17:04   ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
@ 2016-05-27  1:36     ` Yuanhan Liu
  0 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-05-27  1:36 UTC (permalink / raw)
  To: Rich Lane
  Cc: dev, Thomas Monjalon, huawei.xie, Panu Matilainen,
	Tetsuya Mukawa, Traynor Kevin

On Thu, May 26, 2016 at 10:04:23AM -0700, Rich Lane wrote:
> On Thu, May 12, 2016 at 10:24 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
> wrote:
> 
>     v2: - exported ifname as well to fix a vhost-pmd issue reported
>           by Rich
>         - separated the big patch that introduces several new APIs
>           into some small patches.
>         - updated release note
>         - updated version.map
> 
> 
> Tested-by: Rich Lane <rich.lane@bigswitch.com>
> Acked-by: Rich Lane <rich.lane@bigswitch.com>

Rich, appreciate your time for reviewing and testing!

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
                     ` (19 preceding siblings ...)
  2016-05-26 17:04   ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
@ 2016-06-07  3:51   ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
                       ` (21 more replies)
  20 siblings, 22 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

v3: - adapted the new vhost ABI/API changes to tep_term example, to make
      sure not break build at least.
    - bumped the ABI version to 3

NOTE: I created a branch at dpdk.org [0] for more conveinient testing:

    [0]: git://dpdk.org/next/dpdk-next-virtio for-testing


Every time we introduce a new feature to vhost, we are likely to break
ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf
from vhost_virtqueue struct) also break ABI.

This patch set is meant to resolve above issue ultimately, by hiding
virtio_net structure (as well as few others) internaly, and export the
virtio_net dev strut to applications by a number, vid, like the way
kernel exposes an fd to user space.

Back to the patch set, the first part of this set makes some changes to
vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence
to "virtio_net" struct. And then do the final change to make the current
APIs to adapt to using "vid".

After that, "vrtio_net_device_ops" is the only left open struct that an
application can acces, therefore, it's the only place that might introduce
potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time,
and hopefuly, forever.

The last bit of this patch set is some cleanups, including the one from
Ilya.

v2: - exported ifname as well to fix a vhost-pmd issue reported by Rich
    - separated the big patch that introduces several new APIs into some
      small patches.
    - updated release note
    - updated version.map

Thanks.

	--yliu

---
Ilya Maximets (1):
  vhost: make buf vector for scatter Rx local

Yuanhan Liu (19):
  vhost: declare backend with int type
  vhost: set/reset dev flags internally
  vhost: declare device fh as int
  examples/vhost: make a copy of virtio device id
  vhost: rename device fh to vid
  vhost: get device by vid only
  vhost: move vhost device ctx to cuse
  vhost: introduce new API to export numa node
  vhost: introduce new API to export number of queues
  vhost: introduce new API to export ifname
  vhost: introduce new API to export queue free entries
  vhost: remove dependency on priv field
  vhost: export vid as the only interface to applications
  vhost: hide internal structs/macros/functions
  vhost: remove unnecessary fields
  vhost: remove virtio-net.h
  vhost: reserve few more space for future extension
  examples/tep_term: adapt to new vhost ABI/API changes
  vhost: per device virtio net header len

 doc/guides/rel_notes/release_16_07.rst        |  11 +-
 drivers/net/vhost/rte_eth_vhost.c             |  79 ++++-----
 examples/tep_termination/main.c               |  83 +++++-----
 examples/tep_termination/main.h               |   5 +-
 examples/tep_termination/vxlan_setup.c        |  20 +--
 examples/tep_termination/vxlan_setup.h        |   6 +-
 examples/vhost/main.c                         | 116 +++++++------
 examples/vhost/main.h                         |   3 +-
 lib/librte_vhost/Makefile                     |   2 +-
 lib/librte_vhost/rte_vhost_version.map        |  10 ++
 lib/librte_vhost/rte_virtio_net.h             | 223 +++++++------------------
 lib/librte_vhost/vhost-net.h                  | 201 ++++++++++++++++++----
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  |  83 +++++-----
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  30 ++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  12 +-
 lib/librte_vhost/vhost_rxtx.c                 | 133 ++++++++-------
 lib/librte_vhost/vhost_user/vhost-net-user.c  |  53 +++---
 lib/librte_vhost/vhost_user/vhost-net-user.h  |   2 +
 lib/librte_vhost/vhost_user/virtio-net-user.c |  64 +++----
 lib/librte_vhost/vhost_user/virtio-net-user.h |  18 +-
 lib/librte_vhost/virtio-net.c                 | 229 +++++++++++++++++---------
 lib/librte_vhost/virtio-net.h                 |  43 -----
 22 files changed, 752 insertions(+), 674 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
                       ` (20 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

It's an fd; so define it as "int", which could also save the unncessary
(int) case.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 +-
 lib/librte_vhost/virtio-net.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 600b20b..4d25f79 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -85,7 +85,7 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;			/**< Virtqueue available ring. */
 	struct vring_used	*used;			/**< Virtqueue used ring. */
 	uint32_t		size;			/**< Size of descriptor ring. */
-	uint32_t		backend;		/**< Backend value to determine if device should started/stopped. */
+	int			backend;		/**< Backend value to determine if device should started/stopped. */
 	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
 	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
 	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index f4695af..1a6259b 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -717,8 +717,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	 * we add the device.
 	 */
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED) &&
-			((int)dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED)) {
+		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
+		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
 			return notify_ops->new_device(dev);
 		}
 	/* Otherwise we remove it. */
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
                       ` (19 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

It does not make sense to ask the application to set/unset the flag
VIRTIO_DEV_RUNNING (that used internal only) at new_device()/
destroy_device() callback.

Instead, it should be set after new_device() succeeds and reset before
destroy_device() is invoked inside vhost lib. This patch fixes it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 drivers/net/vhost/rte_eth_vhost.c             |  2 --
 examples/vhost/main.c                         |  3 ---
 lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++----
 lib/librte_vhost/virtio-net.c                 | 21 ++++++++++++++-------
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 310cbef..63538c1 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)
 	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
 		rte_vhost_enable_guest_notification(dev, i, 0);
 
-	dev->flags |= VIRTIO_DEV_RUNNING;
 	dev->priv = eth_dev;
 	eth_dev->data->dev_link.link_status = ETH_LINK_UP;
 
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev)
 	eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
 
 	dev->priv = NULL;
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
 		vq = eth_dev->data->rx_queues[i];
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 48060df..f2e03d9 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1180,8 +1180,6 @@ destroy_device (volatile struct virtio_net *dev)
 	struct vhost_dev *vdev;
 	int lcore;
 
-	dev->flags &= ~VIRTIO_DEV_RUNNING;
-
 	vdev = (struct vhost_dev *)dev->priv;
 	/*set the remove flag. */
 	vdev->remove = 1;
@@ -1261,7 +1259,6 @@ new_device (struct virtio_net *dev)
 	/* Disable notifications. */
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
-	dev->flags |= VIRTIO_DEV_RUNNING;
 
 	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index f5248bc..e775e45 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		return -1;
 
 	/* Remove from the data plane. */
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	if (dev->mem) {
 		free_mem_region(dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
 	vhost_set_vring_kick(ctx, &file);
 
-	if (virtio_is_ready(dev) &&
-		!(dev->flags & VIRTIO_DEV_RUNNING))
-			notify_ops->new_device(dev);
+	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
+		if (notify_ops->new_device(dev) == 0)
+			dev->flags |= VIRTIO_DEV_RUNNING;
+	}
 }
 
 /*
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 1a6259b..c45ed1c 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 1);
 	free_device(dev);
@@ -353,8 +355,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
 	if (dev == NULL)
 		return -1;
 
-	if (dev->flags & VIRTIO_DEV_RUNNING)
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
 		notify_ops->destroy_device(dev);
+	}
 
 	cleanup_device(dev, 0);
 	reset_device(dev);
@@ -719,12 +723,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			return notify_ops->new_device(dev);
+			if (notify_ops->new_device(dev) < 0)
+				return -1;
+			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
-	/* Otherwise we remove it. */
-	} else
-		if (file->fd == VIRTIO_DEV_STOPPED)
-			notify_ops->destroy_device(dev);
+	} else if (file->fd == VIRTIO_DEV_STOPPED) {
+		dev->flags &= ~VIRTIO_DEV_RUNNING;
+		notify_ops->destroy_device(dev);
+	}
+
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id Yuanhan Liu
                       ` (18 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Firstly, "int" would be big enough: we don't need 64 bit to represent
a virtio-net device id. Secondly, this could let us avoid the ugly
"%" PRIu64 ".." stuff.

And since ctx.fh is derived from device_fh, declare it as int, too.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 examples/vhost/main.c                         | 45 ++++++++++++++-------------
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  8 ++---
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 34 ++++++++++----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  7 ++---
 lib/librte_vhost/vhost_rxtx.c                 | 34 +++++++++-----------
 lib/librte_vhost/vhost_user/vhost-net-user.c  |  2 +-
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 21 ++++++-------
 9 files changed, 75 insertions(+), 80 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index f2e03d9..564e3f9 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
-			"Device (%" PRIu64 ") is using a registered MAC!\n",
+			"(%d) device is using a registered MAC!\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -728,7 +728,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	vdev->vlan_tag = vlan_tags[dev->device_fh];
 
 	/* Print out VMDQ registration info. */
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n",
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
 		dev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -739,8 +740,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
 				(uint32_t)dev->device_fh + vmdq_pool_base);
 	if (ret)
-		RTE_LOG(ERR, VHOST_DATA, "(%"PRIu64") Failed to add device MAC address to VMDQ\n",
-					dev->device_fh);
+		RTE_LOG(ERR, VHOST_DATA,
+			"(%d) failed to add device MAC address to VMDQ\n",
+			dev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -812,7 +814,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	uint64_t fh;
+	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -823,17 +825,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	fh = dst_vdev->dev->device_fh;
 	if (fh == vdev->dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			"Dropping packet.\n", fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
 
 	if (unlikely(dst_vdev->remove)) {
-		RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") "
-			"Device is marked for removal\n", fh);
+		RTE_LOG(DEBUG, VHOST_DATA,
+			"(%d) device is marked for removal\n", fh);
 		return 0;
 	}
 
@@ -858,8 +859,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 
 	if (dst_vdev->dev->device_fh == dev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%" PRIu64 ") TX: src and dst MAC is same. "
-			" Dropping packet.\n", dst_vdev->dev->device_fh);
+			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
+			dst_vdev->dev->device_fh);
 		return -1;
 	}
 
@@ -872,8 +873,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%" PRIu64 ") TX: pkt to local VM device id: (%" PRIu64 ") "
-		"vlan tag: %u.\n",
+		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
 		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
 
 	return 0;
@@ -964,8 +964,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 		}
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
-		"MAC address is external\n", dev->device_fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC is external\n", dev->device_fh);
 
 queue2nic:
 
@@ -1209,7 +1209,7 @@ destroy_device (volatile struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num--;
 
 	RTE_LOG(INFO, VHOST_DATA,
-		"(%" PRIu64 ") Device has been removed from data core\n",
+		"(%d) device has been removed from data core\n",
 		dev->device_fh);
 
 	rte_free(vdev);
@@ -1228,7 +1228,8 @@ new_device (struct virtio_net *dev)
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
-		RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Couldn't allocate memory for vhost dev\n",
+		RTE_LOG(INFO, VHOST_DATA,
+			"(%d) Couldn't allocate memory for vhost dev\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -1260,7 +1261,9 @@ new_device (struct virtio_net *dev)
 	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
 	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
 
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid);
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) device has been added to data core %d\n",
+		dev->device_fh, vdev->coreid);
 
 	return 0;
 }
@@ -1304,7 +1307,7 @@ print_stats(void)
 			rx         = rte_atomic64_read(&vdev->stats.rx_atomic);
 			rx_dropped = rx_total - rx;
 
-			printf("Statistics for device %" PRIu64 "\n"
+			printf("Statistics for device %d\n"
 				"-----------------------\n"
 				"TX total:              %" PRIu64 "\n"
 				"TX dropped:            %" PRIu64 "\n"
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 4d25f79..da3af5f 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	uint64_t		device_fh;	/**< device identifier. */
+	int			device_fh;	/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index f193a1f..4b9d74d 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%" PRIu64 ") Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -79,8 +79,8 @@
  * Structure used to identify device context.
  */
 struct vhost_device_ctx {
-	pid_t		pid;	/* PID of process calling the IOCTL. */
-	uint64_t	fh;	/* Populated with fi->fh to track the device index. */
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	fh;	/* Populated with fi->fh to track the device index. */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index c613e68..17124fd 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%"PRIu64") Device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", fi->fh);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_KICK\n",
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
 			ctx.fh);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%"PRIu64") IOCTL: VHOST_SET_VRING_CALL\n",
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
 			ctx.fh);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.fh);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%"PRIu64") IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.fh);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index a68a8bd..69cc292 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 		sizeof(struct virtio_memory_regions) * nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") fd close failed\n",
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
 			dev->device_fh);
 
 	if (ret >= 0) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") TUNGETIFF ioctl failed\n",
+			"(%d) TUNGETIFF ioctl failed\n",
 			dev->device_fh);
 
 	return 0;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 750821a..a66456b 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	if (count == 0)
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") res_start_idx %d| res_end_idx Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
 		dev->device_fh, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	if (unlikely(m == NULL))
 		return 0;
 
-	LOG_DEBUG(VHOST_DATA,
-		"(%"PRIu64") Current Index %d| End Index %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->device_fh, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") RX: Num merge buffers %d\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
 		dev->device_fh, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_rx()\n",
-		dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
-				"(%" PRIu64 ") Failed to get enough desc from vring\n",
+				"(%d) failed to get enough desc from vring\n",
 				dev->device_fh);
 			break;
 		}
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t avail_idx;
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"%s (%"PRIu64"): virtqueue idx:%d invalid.\n",
-			__func__, dev->device_fh, queue_id);
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->device_fh, __func__, queue_id);
 		return 0;
 	}
 
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "%s (%"PRIu64")\n", __func__, dev->device_fh);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
-	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") about to dequeue %u buffers\n",
+	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
 			dev->device_fh, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index df2bd64..facbfa1 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);
 
 struct connfd_ctx {
 	struct vhost_server *vserver;
-	uint32_t fh;
+	int fh;
 };
 
 #define MAX_VHOST_SERVER 1024
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index e775e45..10daaa3 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		sizeof(struct orig_region_map) * memory.nregions);
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev->mem\n",
+			"(%d) failed to allocate memory for dev->mem\n",
 			dev->device_fh);
 		return -1;
 	}
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index c45ed1c..202e196 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.fh);
 	}
 
 	return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to allocate memory for dev.\n",
-			ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.fh);
 		return -1;
 	}
 
@@ -408,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 		vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
-		"(%"PRIu64") Mergeable RX buffers %s, virtio 1 %s\n",
+		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
 		dev->device_fh,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
@@ -549,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->desc_user_addr);
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find desc ring address.\n",
+			"(%d) failed to find desc ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -561,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->avail_user_addr);
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find avail ring address.\n",
+			"(%d) failed to find avail ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
@@ -570,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 			addr->used_user_addr);
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find used ring address.\n",
+			"(%d) failed to find used ring address.\n",
 			dev->device_fh);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address desc: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
 			dev->device_fh, vq->desc);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address avail: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
 			dev->device_fh, vq->avail);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") mapped address used: %p\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
 			dev->device_fh, vq->used);
-	LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") log_guest_addr: %"PRIx64"\n",
+	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
 			dev->device_fh, vq->log_guest_addr);
 
 	return 0;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (2 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
                       ` (17 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Make a copy of virtio device id (device_fh) from the virtio_net struct,
so that we could have less dependency on the virtio_net struct.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 examples/vhost/main.c | 59 ++++++++++++++++++++++++---------------------------
 examples/vhost/main.h |  1 +
 2 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 564e3f9..04a7f52 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -708,7 +708,6 @@ static int
 link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
-	struct virtio_net *dev = vdev->dev;
 	int i, ret;
 
 	/* Learn MAC address of guest device from packet */
@@ -717,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -725,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[dev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->device_fh];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		dev->device_fh,
+		vdev->device_fh,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)dev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->device_fh + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			dev->device_fh);
+			vdev->device_fh);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -814,7 +813,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
 	struct vhost_dev *dst_vdev;
-	int fh;
 
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
@@ -822,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	fh = dst_vdev->dev->device_fh;
-	if (fh == vdev->dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			fh);
+			vdev->device_fh);
 		return 0;
 	}
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
+	RTE_LOG(DEBUG, VHOST_DATA,
+		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", fh);
+			"(%d) device is marked for removal\n", dst_vdev->device_fh);
 		return 0;
 	}
 
@@ -847,7 +845,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
  * and get its vlan tag, and offset if it is.
  */
 static inline int __attribute__((always_inline))
-find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	uint32_t *offset, uint16_t *vlan_tag)
 {
 	struct vhost_dev *dst_vdev;
@@ -857,10 +855,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (dst_vdev->dev->device_fh == dev->device_fh) {
+	if (vdev->device_fh == dst_vdev->device_fh) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			dst_vdev->dev->device_fh);
+			vdev->device_fh);
 		return -1;
 	}
 
@@ -870,11 +868,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
+	*vlan_tag = vlan_tags[vdev->device_fh];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
-		dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
+		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
+		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
 
 	return 0;
 }
@@ -937,7 +935,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct mbuf_table *tx_q;
 	unsigned offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net *dev = vdev->dev;
 	struct ether_hdr *nh;
 
 
@@ -958,14 +955,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
-		if (unlikely(find_local_dest(dev, m, &offset, &vlan_tag) != 0)) {
+		if (unlikely(find_local_dest(vdev, m, &offset,
+					     &vlan_tag) != 0)) {
 			rte_pktmbuf_free(m);
 			return;
 		}
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC is external\n", dev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->device_fh);
 
 queue2nic:
 
@@ -1095,10 +1093,8 @@ drain_virtio_tx(struct vhost_dev *vdev)
 			free_pkts(pkts, count);
 	}
 
-	for (i = 0; i < count; ++i) {
-		virtio_tx_route(vdev, pkts[i],
-			vlan_tags[(uint16_t)vdev->dev->device_fh]);
-	}
+	for (i = 0; i < count; ++i)
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
 }
 
 /*
@@ -1210,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		dev->device_fh);
+		vdev->device_fh);
 
 	rte_free(vdev);
 }
@@ -1225,20 +1221,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
+	int device_fh = dev->device_fh;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%d) Couldn't allocate memory for vhost dev\n",
-			dev->device_fh);
+			"(%d) couldn't allocate memory for vhost dev\n",
+			device_fh);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
+	vdev->device_fh = device_fh;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, global_vdev_entry);
-	vdev->vmdq_rx_q
-		= dev->device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1263,7 +1260,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		dev->device_fh, vdev->coreid);
+		device_fh, vdev->coreid);
 
 	return 0;
 }
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index bd7f1a3..11d121b 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,6 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
+	int device_fh;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) global_vdev_entry;
 	TAILQ_ENTRY(vhost_dev) lcore_vdev_entry;
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (3 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
                       ` (16 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

I failed to figure out what does "fh" mean here for a long while.
The only guess I could have had is "file handle". So, you get the
point that it's not well named.

I then figured it out that "fh" is derived from the fuse lib, and
my above guess is right. However, device_fh represents a virtio
net device ID. Therefore, here I rename it to vid (Virtio-net device
ID, or Vhost device ID; choose one you prefer) to make it easier for
understanding.

This name (vid) then will be considered to the only interface to
applications. That's another reason to do the rename: it's our
interface, make it more understandable.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 examples/vhost/main.c                         | 44 +++++++++++++--------------
 examples/vhost/main.h                         |  2 +-
 lib/librte_vhost/rte_virtio_net.h             |  2 +-
 lib/librte_vhost/vhost-net.h                  |  6 ++--
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 36 +++++++++++-----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++--
 lib/librte_vhost/vhost_rxtx.c                 | 22 +++++++-------
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 16 +++++-----
 lib/librte_vhost/vhost_user/virtio-net-user.c |  2 +-
 lib/librte_vhost/virtio-net.c                 | 30 +++++++++---------
 10 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 04a7f52..d04f779 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (find_vhost_dev(&pkt_hdr->s_addr)) {
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) device is using a registered MAC!\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -724,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
 
 	/* vlan_tag currently uses the device_id. */
-	vdev->vlan_tag = vlan_tags[vdev->device_fh];
+	vdev->vlan_tag = vlan_tags[vdev->vid];
 
 	/* Print out VMDQ registration info. */
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
-		vdev->device_fh,
+		vdev->vid,
 		vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
 		vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
 		vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -737,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
 
 	/* Register the MAC address. */
 	ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
-				(uint32_t)vdev->device_fh + vmdq_pool_base);
+				(uint32_t)vdev->vid + vmdq_pool_base);
 	if (ret)
 		RTE_LOG(ERR, VHOST_DATA,
 			"(%d) failed to add device MAC address to VMDQ\n",
-			vdev->device_fh);
+			vdev->vid);
 
 	/* Enable stripping of the vlan tag as we handle routing. */
 	if (vlan_strip)
@@ -820,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 	if (!dst_vdev)
 		return -1;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return 0;
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is local\n", dst_vdev->device_fh);
+		"(%d) TX: MAC address is local\n", dst_vdev->vid);
 
 	if (unlikely(dst_vdev->remove)) {
 		RTE_LOG(DEBUG, VHOST_DATA,
-			"(%d) device is marked for removal\n", dst_vdev->device_fh);
+			"(%d) device is marked for removal\n", dst_vdev->vid);
 		return 0;
 	}
 
@@ -855,10 +855,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	if (!dst_vdev)
 		return 0;
 
-	if (vdev->device_fh == dst_vdev->device_fh) {
+	if (vdev->vid == dst_vdev->vid) {
 		RTE_LOG(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
-			vdev->device_fh);
+			vdev->vid);
 		return -1;
 	}
 
@@ -868,11 +868,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
 	 * the packet length by plus it.
 	 */
 	*offset  = VLAN_HLEN;
-	*vlan_tag = vlan_tags[vdev->device_fh];
+	*vlan_tag = vlan_tags[vdev->vid];
 
 	RTE_LOG(DEBUG, VHOST_DATA,
 		"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
-		vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
+		vdev->vid, dst_vdev->vid, *vlan_tag);
 
 	return 0;
 }
@@ -963,7 +963,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	RTE_LOG(DEBUG, VHOST_DATA,
-		"(%d) TX: MAC address is external\n", vdev->device_fh);
+		"(%d) TX: MAC address is external\n", vdev->vid);
 
 queue2nic:
 
@@ -1094,7 +1094,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	}
 
 	for (i = 0; i < count; ++i)
-		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
+		virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->vid]);
 }
 
 /*
@@ -1206,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been removed from data core\n",
-		vdev->device_fh);
+		vdev->vid);
 
 	rte_free(vdev);
 }
@@ -1221,21 +1221,21 @@ new_device (struct virtio_net *dev)
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int device_fh = dev->device_fh;
+	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
 			"(%d) couldn't allocate memory for vhost dev\n",
-			device_fh);
+			vid);
 		return -1;
 	}
 	vdev->dev = dev;
 	dev->priv = vdev;
-	vdev->device_fh = device_fh;
+	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, global_vdev_entry);
-	vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
+	vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
 
 	/*reset ready flag*/
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1260,7 +1260,7 @@ new_device (struct virtio_net *dev)
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
-		device_fh, vdev->coreid);
+		vid, vdev->coreid);
 
 	return 0;
 }
@@ -1312,7 +1312,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->device_fh,
+				vdev->dev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index 11d121b..e99c436 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,7 +66,7 @@ struct vhost_dev {
 	/**< Device is marked for removal from the data core. */
 	volatile uint8_t remove;
 
-	int device_fh;
+	int vid;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) global_vdev_entry;
 	TAILQ_ENTRY(vhost_dev) lcore_vdev_entry;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index da3af5f..bc64e89 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -133,7 +133,7 @@ struct virtio_net {
 	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
 	uint64_t		features;	/**< Negotiated feature set. */
 	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			device_fh;	/**< device identifier. */
+	int			vid;		/**< device identifier. */
 	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4b9d74d..b63ea6f 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -57,9 +57,9 @@
 	char packet[VHOST_MAX_PRINT_BUFF]; \
 	\
 	if ((header)) \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
 	else \
-		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->device_fh), (size)); \
+		snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
 	for (index = 0; index < (size); index++) { \
 		snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
 			"%02hhx ", pkt_addr[index]); \
@@ -80,7 +80,7 @@
  */
 struct vhost_device_ctx {
 	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	fh;	/* Populated with fi->fh to track the device index. */
+	int	vid;	/* Virtio-net device ID */
 };
 
 int vhost_new_device(struct vhost_device_ctx);
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 17124fd..3a9b33d 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
-	ctx.fh = fi->fh;
+	ctx.vid = (int)fi->fh;
 
 	return ctx;
 }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 	fi->fh = err;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", fi->fh);
+		"(%d) device configuration started\n", err);
 	fuse_reply_open(req, fi);
 }
 
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx);
-	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh);
+			"(%d) IOCTL: VHOST_NET_SET_BACKEND\n", ctx.vid);
 		if (!in_buf) {
 			VHOST_IOCTL_RETRY(sizeof(file), 0);
 			break;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.fh);
+			ctx.vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
 				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.fh);
+			ctx.vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.fh);
+			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.fh);
+			"(%d) IOCTL: FAIL\n", ctx.vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.fh);
+			"(%d) IOCTL: SUCCESS\n", ctx.vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 69cc292..b90dabf 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 
 	if (close(fd_tap) < 0)
 		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) TUNGETIFF ioctl failed\n",
-			dev->device_fh);
+			dev->vid);
 
 	return 0;
 }
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index a66456b..8d87508 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t desc_indexes[MAX_PKT_BURST];
 	uint32_t i;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) res_start_idx %d | res_end_idx Index %d\n",
-		dev->device_fh, res_start_idx, res_end_idx);
+		dev->vid, res_start_idx, res_end_idx);
 
 	/* Retrieve all of the desc indexes first to avoid caching issues. */
 	rte_prefetch0(&vq->avail->ring[res_start_idx & (vq->size - 1)]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		return 0;
 
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
-		dev->device_fh, cur_idx, res_end_idx);
+		dev->vid, cur_idx, res_end_idx);
 
 	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
 		return -1;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
 	LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
-		dev->device_fh, virtio_hdr.num_buffers);
+		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 							 &start, &end) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
-				dev->device_fh);
+				dev->vid);
 			break;
 		}
 
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->device_fh, __func__, queue_id);
+			dev->vid, __func__, queue_id);
 		return 0;
 	}
 
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	if (free_entries == 0)
 		goto out;
 
-	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->device_fh, __func__);
+	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 
 	/* Prefetch available ring to retrieve head indexes. */
 	used_idx = vq->last_used_idx & (vq->size - 1);
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
 	LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
-			dev->device_fh, count);
+			dev->vid, count);
 
 	/* Retrieve all of the head indexes first to avoid caching issues. */
 	for (i = 0; i < count; i++) {
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index facbfa1..3498796 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);
 
 struct connfd_ctx {
 	struct vhost_server *vserver;
-	int fh;
+	int vid;
 };
 
 #define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	struct vhost_server *vserver = (struct vhost_server *)dat;
 	int conn_fd;
 	struct connfd_ctx *ctx;
-	int fh;
+	int vid;
 	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	fh = vhost_new_device(vdev_ctx);
-	if (fh == -1) {
+	vid = vhost_new_device(vdev_ctx);
+	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.fh = fh;
+	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
 	vhost_set_ifname(vdev_ctx, vserver->path,
 		size);
 
-	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
+	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
 	ctx->vserver = vserver;
-	ctx->fh = fh;
+	ctx->vid = vid;
 	fdset_add(&g_vhost_server.fdset,
 		conn_fd, vserver_message_handler, NULL, ctx);
 }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 	uint64_t features;
 	int ret;
 
-	ctx.fh = cfd_ctx->fh;
+	ctx.vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 10daaa3..1568c9f 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	if (dev->mem == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to allocate memory for dev->mem\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 	dev->mem->nregions = memory.nregions;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 202e196..0a13150 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 struct virtio_net *
 get_device(struct vhost_device_ctx ctx)
 {
-	struct virtio_net *dev = vhost_devices[ctx.fh];
+	struct virtio_net *dev = vhost_devices[ctx.vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.fh);
+			"(%d) device not found.\n", ctx.vid);
 	}
 
 	return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)
 
 /*
  * Reset some variables in device structure, while keeping few
- * others untouched, such as device_fh, ifname, virt_qp_nb: they
+ * others untouched, such as vid, ifname, virt_qp_nb: they
  * should be same unless the device is removed.
  */
 static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.fh);
+			"(%d) failed to allocate memory for dev.\n", ctx.vid);
 		return -1;
 	}
 
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	}
 
 	vhost_devices[i] = dev;
-	dev->device_fh   = i;
+	dev->vid = i;
 
 	return i;
 }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.fh] = NULL;
+	vhost_devices[ctx.vid] = NULL;
 }
 
 void
@@ -408,7 +408,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
-		dev->device_fh,
+		dev->vid,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
@@ -513,7 +513,7 @@ numa_realloc(struct virtio_net *dev, int index)
 out:
 	dev->virtqueue[index] = vq;
 	dev->virtqueue[index + 1] = vq + 1;
-	vhost_devices[dev->device_fh] = dev;
+	vhost_devices[dev->vid] = dev;
 
 	return dev;
 }
@@ -549,7 +549,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->desc == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find desc ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -561,7 +561,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->avail == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find avail ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
@@ -570,20 +570,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
 	if (vq->used == 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"(%d) failed to find used ring address.\n",
-			dev->device_fh);
+			dev->vid);
 		return -1;
 	}
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
-			dev->device_fh, vq->desc);
+			dev->vid, vq->desc);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
-			dev->device_fh, vq->avail);
+			dev->vid, vq->avail);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
-			dev->device_fh, vq->used);
+			dev->vid, vq->used);
 	LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
-			dev->device_fh, vq->log_guest_addr);
+			dev->vid, vq->log_guest_addr);
 
 	return 0;
 }
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (4 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
                       ` (15 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

get_device() just needs vid, so pass vid as the parameter only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h                  | 30 ++++++------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 64 ++++++++++++-------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++---
 lib/librte_vhost/vhost_user/vhost-net-user.c  | 43 ++++++++---------
 lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++-------
 lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++---
 lib/librte_vhost/virtio-net.c                 | 68 +++++++++++++--------------
 lib/librte_vhost/virtio-net.h                 |  2 +-
 8 files changed, 132 insertions(+), 147 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index b63ea6f..4de3aa0 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -83,28 +83,26 @@ struct vhost_device_ctx {
 	int	vid;	/* Virtio-net device ID */
 };
 
-int vhost_new_device(struct vhost_device_ctx);
-void vhost_destroy_device(struct vhost_device_ctx);
+int vhost_new_device(void);
+void vhost_destroy_device(int);
 
-void vhost_set_ifname(struct vhost_device_ctx,
-	const char *if_name, unsigned int if_len);
+void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
 
-int vhost_get_features(struct vhost_device_ctx, uint64_t *);
-int vhost_set_features(struct vhost_device_ctx, uint64_t *);
+int vhost_get_features(int, uint64_t *);
+int vhost_set_features(int, uint64_t *);
 
-int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
-int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
-int vhost_get_vring_base(struct vhost_device_ctx,
-	uint32_t, struct vhost_vring_state *);
+int vhost_set_vring_num(int, struct vhost_vring_state *);
+int vhost_set_vring_addr(int, struct vhost_vring_addr *);
+int vhost_set_vring_base(int, struct vhost_vring_state *);
+int vhost_get_vring_base(int, uint32_t, struct vhost_vring_state *);
 
-int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
-int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_kick(int, struct vhost_vring_file *);
+int vhost_set_vring_call(int, struct vhost_vring_file *);
 
-int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_backend(int, struct vhost_vring_file *);
 
-int vhost_set_owner(struct vhost_device_ctx);
-int vhost_reset_owner(struct vhost_device_ctx);
+int vhost_set_owner(int);
+int vhost_reset_owner(int);
 
 /*
  * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 3a9b33d..45a9a91 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -82,19 +82,18 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 static void
 vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
-	int err = 0;
+	int vid = 0;
 
-	err = vhost_new_device(ctx);
-	if (err == -1) {
+	vid = vhost_new_device();
+	if (vid == -1) {
 		fuse_reply_err(req, EPERM);
 		return;
 	}
 
-	fi->fh = err;
+	fi->fh = vid;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
-		"(%d) device configuration started\n", err);
+		"(%d) device configuration started\n", vid);
 	fuse_reply_open(req, fi);
 }
 
@@ -107,17 +106,17 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 	int err = 0;
 	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
-	vhost_destroy_device(ctx);
+	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
 	fuse_reply_err(req, err);
 }
 
 /*
  * Boilerplate code for CUSE IOCTL
- * Implicit arguments: ctx, req, result.
+ * Implicit arguments: vid, req, result.
  */
 #define VHOST_IOCTL(func) do {	\
-	result = (func)(ctx);	\
+	result = (func)(vid);	\
 	fuse_reply_ioctl(req, result, NULL, 0);	\
 } while (0)
 
@@ -134,41 +133,41 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 
 /*
  * Boilerplate code for CUSE Read IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_R(type, var, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type), 0);\
 	} else {	\
 		(var) = *(const type*)in_buf;	\
-		result = func(ctx, &(var));	\
+		result = func(vid, &(var));	\
 		fuse_reply_ioctl(req, result, NULL, 0);\
 	}	\
 } while (0)
 
 /*
  * Boilerplate code for CUSE Write IOCTL
- * Implicit arguments: ctx, req, result, out_bufsz.
+ * Implicit arguments: vid, req, result, out_bufsz.
  */
 #define VHOST_IOCTL_W(type, var, func) do {	\
 	if (!out_bufsz) {	\
 		VHOST_IOCTL_RETRY(0, sizeof(type));\
 	} else {	\
-		result = (func)(ctx, &(var));\
+		result = (func)(vid, &(var));\
 		fuse_reply_ioctl(req, result, &(var), sizeof(type));\
 	} \
 } while (0)
 
 /*
  * Boilerplate code for CUSE Read/Write IOCTL
- * Implicit arguments: ctx, req, result, in_bufsz, in_buf.
+ * Implicit arguments: vid, req, result, in_bufsz, in_buf.
  */
 #define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do {	\
 	if (!in_bufsz) {	\
 		VHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\
 	} else {	\
 		(var1) = *(const type1*) (in_buf);	\
-		result = (func)(ctx, (var1), &(var2));	\
+		result = (func)(vid, (var1), &(var2));	\
 		fuse_reply_ioctl(req, result, &(var2), sizeof(type2));\
 	}	\
 } while (0)
@@ -190,6 +189,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	uint64_t features;
 	uint32_t index;
 	int result = 0;
+	int vid = ctx.vid;
 
 	switch (cmd) {
 	case VHOST_NET_SET_BACKEND:
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_GET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_FEATURES\n", vid);
 		VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
 		break;
 
 	case VHOST_SET_FEATURES:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_FEATURES\n", vid);
 		VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
 		break;
 
 	case VHOST_RESET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_RESET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_reset_owner);
 		break;
 
 	case VHOST_SET_OWNER:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_OWNER\n", vid);
 		VHOST_IOCTL(vhost_set_owner);
 		break;
 
 	case VHOST_SET_MEM_TABLE:
 		/*TODO fix race condition.*/
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_MEM_TABLE\n", vid);
 		static struct vhost_memory mem_temp;
 
 		switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	case VHOST_SET_VRING_NUM:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_NUM\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_num);
 		break;
 
 	case VHOST_SET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_BASE\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_state, state,
 			vhost_set_vring_base);
 		break;
 
 	case VHOST_GET_VRING_BASE:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid);
+			"(%d) IOCTL: VHOST_GET_VRING_BASE\n", vid);
 		VHOST_IOCTL_RW(uint32_t, index,
 			struct vhost_vring_state, state, vhost_get_vring_base);
 		break;
 
 	case VHOST_SET_VRING_ADDR:
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid);
+			"(%d) IOCTL: VHOST_SET_VRING_ADDR\n", vid);
 		VHOST_IOCTL_R(struct vhost_vring_addr, addr,
 			vhost_set_vring_addr);
 		break;
@@ -294,12 +294,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 	case VHOST_SET_VRING_CALL:
 		if (cmd == VHOST_SET_VRING_KICK)
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_KICK\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_KICK\n", vid);
 		else
 			LOG_DEBUG(VHOST_CONFIG,
-				"(%d) IOCTL: VHOST_SET_VRING_CALL\n",
-			ctx.vid);
+				"(%d) IOCTL: VHOST_SET_VRING_CALL\n", vid);
 		if (!in_buf)
 			VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0);
 		else {
@@ -315,10 +313,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 			}
 			file.fd = fd;
 			if (cmd == VHOST_SET_VRING_KICK) {
-				result = vhost_set_vring_kick(ctx, &file);
+				result = vhost_set_vring_kick(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			} else {
-				result = vhost_set_vring_call(ctx, &file);
+				result = vhost_set_vring_call(vid, &file);
 				fuse_reply_ioctl(req, result, NULL, 0);
 			}
 		}
@@ -326,17 +324,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 
 	default:
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid);
+			"(%d) IOCTL: DOESN NOT EXIST\n", vid);
 		result = -1;
 		fuse_reply_ioctl(req, result, NULL, 0);
 	}
 
 	if (result < 0)
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: FAIL\n", ctx.vid);
+			"(%d) IOCTL: FAIL\n", vid);
 	else
 		LOG_DEBUG(VHOST_CONFIG,
-			"(%d) IOCTL: SUCCESS\n", ctx.vid);
+			"(%d) IOCTL: SUCCESS\n", vid);
 }
 
 /*
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index b90dabf..34ee6c9 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
 	uint64_t base_address = 0, mapped_address, mapped_size;
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,
  * save it in the device structure.
  */
 static int
-get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int pid)
+get_ifname(int vid, int tap_fd, int pid)
 {
 	int fd_tap;
 	struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
 	ret = ioctl(fd_tap, TUNGETIFF, &ifr);
 
 	if (close(fd_tap) < 0)
-		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n",
-			dev->vid);
+		RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n", vid);
 
 	if (ret >= 0) {
 		ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
-		vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
+		vhost_set_ifname(vid, ifr.ifr_name, ifr_size);
 	} else
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) TUNGETIFF ioctl failed\n",
-			dev->vid);
+			"(%d) TUNGETIFF ioctl failed\n", vid);
 
 	return 0;
 }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(ctx.vid);
 	if (dev == NULL)
 		return -1;
 
 	if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
-		get_ifname(ctx, dev, file->fd, ctx.pid);
+		get_ifname(ctx.vid, file->fd, ctx.pid);
 
-	return vhost_set_backend(ctx, file);
+	return vhost_set_backend(ctx.vid, file);
 }
 
 void
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 3498796..68fc9b9 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -286,7 +286,6 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	int conn_fd;
 	struct connfd_ctx *ctx;
 	int vid;
-	struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 };
 	unsigned int size;
 
 	conn_fd = accept(fd, NULL, NULL);
@@ -301,17 +300,15 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 		return;
 	}
 
-	vid = vhost_new_device(vdev_ctx);
+	vid = vhost_new_device();
 	if (vid == -1) {
 		free(ctx);
 		close(conn_fd);
 		return;
 	}
 
-	vdev_ctx.vid = vid;
 	size = strnlen(vserver->path, PATH_MAX);
-	vhost_set_ifname(vdev_ctx, vserver->path,
-		size);
+	vhost_set_ifname(vid, vserver->path, size);
 
 	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
@@ -325,13 +322,13 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 static void
 vserver_message_handler(int connfd, void *dat, int *remove)
 {
-	struct vhost_device_ctx ctx;
+	int vid;
 	struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat;
 	struct VhostUserMsg msg;
 	uint64_t features;
 	int ret;
 
-	ctx.vid = cfd_ctx->vid;
+	vid = cfd_ctx->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
@@ -347,7 +344,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		close(connfd);
 		*remove = 1;
 		free(cfd_ctx);
-		vhost_destroy_device(ctx);
+		vhost_destroy_device(vid);
 
 		return;
 	}
@@ -356,14 +353,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_get_features(ctx, &features);
+		ret = vhost_get_features(vid, &features);
 		msg.payload.u64 = features;
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
 		features = msg.payload.u64;
-		vhost_set_features(ctx, &features);
+		vhost_set_features(vid, &features);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -372,22 +369,22 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		send_vhost_message(connfd, &msg);
 		break;
 	case VHOST_USER_SET_PROTOCOL_FEATURES:
-		user_set_protocol_features(ctx, msg.payload.u64);
+		user_set_protocol_features(vid, msg.payload.u64);
 		break;
 
 	case VHOST_USER_SET_OWNER:
-		vhost_set_owner(ctx);
+		vhost_set_owner(vid);
 		break;
 	case VHOST_USER_RESET_OWNER:
-		vhost_reset_owner(ctx);
+		vhost_reset_owner(vid);
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		user_set_mem_table(ctx, &msg);
+		user_set_mem_table(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-		user_set_log_base(ctx, &msg);
+		user_set_log_base(vid, &msg);
 
 		/* it needs a reply */
 		msg.size = sizeof(msg.payload.u64);
@@ -399,26 +396,26 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_NUM:
-		vhost_set_vring_num(ctx, &msg.payload.state);
+		vhost_set_vring_num(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SET_VRING_ADDR:
-		vhost_set_vring_addr(ctx, &msg.payload.addr);
+		vhost_set_vring_addr(vid, &msg.payload.addr);
 		break;
 	case VHOST_USER_SET_VRING_BASE:
-		vhost_set_vring_base(ctx, &msg.payload.state);
+		vhost_set_vring_base(vid, &msg.payload.state);
 		break;
 
 	case VHOST_USER_GET_VRING_BASE:
-		ret = user_get_vring_base(ctx, &msg.payload.state);
+		ret = user_get_vring_base(vid, &msg.payload.state);
 		msg.size = sizeof(msg.payload.state);
 		send_vhost_message(connfd, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_KICK:
-		user_set_vring_kick(ctx, &msg);
+		user_set_vring_kick(vid, &msg);
 		break;
 	case VHOST_USER_SET_VRING_CALL:
-		user_set_vring_call(ctx, &msg);
+		user_set_vring_call(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_ERR:
@@ -434,10 +431,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 		break;
 
 	case VHOST_USER_SET_VRING_ENABLE:
-		user_set_vring_enable(ctx, &msg.payload.state);
+		user_set_vring_enable(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SEND_RARP:
-		user_send_rarp(ctx, &msg);
+		user_send_rarp(vid, &msg);
 		break;
 
 	default:
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 1568c9f..9385af1 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev)
 }
 
 int
-user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 {
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 	uint64_t alignment;
 
 	/* unmap old memory regions one by one*/
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev)
 }
 
 void
-user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring call idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_call(ctx, &file);
+	vhost_set_vring_call(vid, &file);
 }
 
 
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  *  device is ready for packet processing.
  */
 void
-user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
+user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_kick(ctx, &file);
+	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (notify_ops->new_device(dev) == 0)
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
  * when virtio is stopped, qemu will send us the GET_VRING_BASE message.
  */
 int
-user_get_vring_base(struct vhost_device_ctx ctx,
+user_get_vring_base(int vid,
 	struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return -1;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
 		notify_ops->destroy_device(dev);
 
 	/* Here we are safe to get the last used index */
-	vhost_get_vring_base(ctx, state->index, state);
+	vhost_get_vring_base(vid, state->index, state);
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,
  * enable the virtio queue pair.
  */
 int
-user_set_vring_enable(struct vhost_device_ctx ctx,
+user_set_vring_enable(int vid,
 		      struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 	int enable = (int)state->num;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx,
 }
 
 void
-user_set_protocol_features(struct vhost_device_ctx ctx,
+user_set_protocol_features(int vid,
 			   uint64_t protocol_features)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
 		return;
 
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx,
 }
 
 int
-user_set_log_base(struct vhost_device_ctx ctx,
+user_set_log_base(int vid,
 		 struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,
 	uint64_t size, off;
 	void *addr;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,
  * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it.
  */
 int
-user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *msg)
+user_send_rarp(int vid, struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
 	uint8_t *mac = (uint8_t *)&msg->payload.u64;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (!dev)
 		return -1;
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h
index cefec16..e1b967b 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.h
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h
@@ -45,20 +45,18 @@
 					 (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
 					 (1ULL << VHOST_USER_PROTOCOL_F_RARP))
 
-int user_set_mem_table(struct vhost_device_ctx, struct VhostUserMsg *);
+int user_set_mem_table(int, struct VhostUserMsg *);
 
-void user_set_vring_call(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_call(int, struct VhostUserMsg *);
 
-void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *);
+void user_set_vring_kick(int, struct VhostUserMsg *);
 
-void user_set_protocol_features(struct vhost_device_ctx ctx,
-				uint64_t protocol_features);
-int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *);
-int user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *);
+void user_set_protocol_features(int vid, uint64_t protocol_features);
+int user_set_log_base(int vid, struct VhostUserMsg *);
+int user_send_rarp(int vid, struct VhostUserMsg *);
 
-int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int user_get_vring_base(int, struct vhost_vring_state *);
 
-int user_set_vring_enable(struct vhost_device_ctx ctx,
-			  struct vhost_vring_state *state);
+int user_set_vring_enable(int vid, struct vhost_vring_state *state);
 
 #endif
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 0a13150..c6d3829 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -108,15 +108,14 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
 	return vhost_va;
 }
 
-
 struct virtio_net *
-get_device(struct vhost_device_ctx ctx)
+get_device(int vid)
 {
-	struct virtio_net *dev = vhost_devices[ctx.vid];
+	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) device not found.\n", ctx.vid);
+			"(%d) device not found.\n", vid);
 	}
 
 	return dev;
@@ -255,7 +254,7 @@ reset_device(struct virtio_net *dev)
  * list.
  */
 int
-vhost_new_device(struct vhost_device_ctx ctx)
+vhost_new_device(void)
 {
 	struct virtio_net *dev;
 	int i;
@@ -263,7 +262,7 @@ vhost_new_device(struct vhost_device_ctx ctx)
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%d) failed to allocate memory for dev.\n", ctx.vid);
+			"Failed to allocate memory for new dev.\n");
 		return -1;
 	}
 
@@ -288,9 +287,9 @@ vhost_new_device(struct vhost_device_ctx ctx)
  * cleanup the device and remove it from device configuration linked list.
  */
 void
-vhost_destroy_device(struct vhost_device_ctx ctx)
+vhost_destroy_device(int vid)
 {
-	struct virtio_net *dev = get_device(ctx);
+	struct virtio_net *dev = get_device(vid);
 
 	if (dev == NULL)
 		return;
@@ -303,17 +302,16 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
 	cleanup_device(dev, 1);
 	free_device(dev);
 
-	vhost_devices[ctx.vid] = NULL;
+	vhost_devices[vid] = NULL;
 }
 
 void
-vhost_set_ifname(struct vhost_device_ctx ctx,
-	const char *if_name, unsigned int if_len)
+vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)
 {
 	struct virtio_net *dev;
 	unsigned int len;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return;
 
@@ -331,11 +329,11 @@ vhost_set_ifname(struct vhost_device_ctx ctx,
  * the device hasn't been initialised.
  */
 int
-vhost_set_owner(struct vhost_device_ctx ctx)
+vhost_set_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -346,11 +344,11 @@ vhost_set_owner(struct vhost_device_ctx ctx)
  * Called from CUSE IOCTL: VHOST_RESET_OWNER
  */
 int
-vhost_reset_owner(struct vhost_device_ctx ctx)
+vhost_reset_owner(int vid)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -369,11 +367,11 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
  * The features that we support are requested.
  */
 int
-vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_get_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -387,13 +385,13 @@ vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * We receive the negotiated features supported by us and the virtio device.
  */
 int
-vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 	uint16_t vhost_hlen;
 	uint16_t i;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 	if (*pu & ~VHOST_FEATURES)
@@ -427,12 +425,11 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
  * The virtio device sends us the size of the descriptor ring.
  */
 int
-vhost_set_vring_num(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_num(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -531,12 +528,12 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
  * This function then converts these to our address space.
  */
 int
-vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if ((dev == NULL) || (dev->mem == NULL))
 		return -1;
 
@@ -593,12 +590,11 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
  * The virtio device sends us the available ring last used index.
  */
 int
-vhost_set_vring_base(struct vhost_device_ctx ctx,
-	struct vhost_vring_state *state)
+vhost_set_vring_base(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -614,12 +610,12 @@ vhost_set_vring_base(struct vhost_device_ctx ctx,
  * We send the virtio device our available ring last used index.
  */
 int
-vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+vhost_get_vring_base(int vid, uint32_t index,
 	struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -637,13 +633,13 @@ vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
  * copied into our process space.
  */
 int
-vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_call(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 	uint32_t cur_qp_idx = file->index / VIRTIO_QNUM;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -674,12 +670,12 @@ vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * This fd gets copied into our process space.
  */
 int
-vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_vring_kick(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
@@ -704,11 +700,11 @@ vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
  * The device will still exist in the device configuration linked list.
  */
 int
-vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+vhost_set_backend(int vid, struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
-	dev = get_device(ctx);
+	dev = get_device(vid);
 	if (dev == NULL)
 		return -1;
 
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
index 75fb57e..9812545 100644
--- a/lib/librte_vhost/virtio-net.h
+++ b/lib/librte_vhost/virtio-net.h
@@ -38,6 +38,6 @@
 #include "rte_virtio_net.h"
 
 struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(struct vhost_device_ctx ctx);
+struct virtio_net *get_device(int vid);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (5 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
                       ` (14 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

vhost cuse is now the last reference of the vhost_device_ctx struct;
move it there, and do a rename to "vhost_cuse_device_ctx", to make
it clear that it's "cuse only".

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h                  |  8 --------
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 13 +++++++------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  6 ++++--
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++--
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4de3aa0..4ed5816 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -75,14 +75,6 @@
 #endif
 
 
-/*
- * Structure used to identify device context.
- */
-struct vhost_device_ctx {
-	pid_t	pid;	/* PID of process calling the IOCTL. */
-	int	vid;	/* Virtio-net device ID */
-};
-
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index 45a9a91..cf6d191 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";
 static struct fuse_session *session;
 
 /*
- * Returns vhost_device_ctx from given fuse_req_t. The index is populated later
- * when the device is added to the device linked list.
+ * Returns vhost_cuse_device_ctx from given fuse_req_t. The
+ * index is populated later when the device is added to the
+ * device linked list.
  */
-static struct vhost_device_ctx
+static struct vhost_cuse_device_ctx
 fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)
 {
-	struct vhost_device_ctx ctx;
+	struct vhost_cuse_device_ctx ctx;
 	struct fuse_ctx const *const req_ctx = fuse_req_ctx(req);
 
 	ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void
 vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
 {
 	int err = 0;
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 
 	vhost_destroy_device(ctx.vid);
 	RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
 		struct fuse_file_info *fi, __rte_unused unsigned flags,
 		const void *in_buf, size_t in_bufsz, size_t out_bufsz)
 {
-	struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
+	struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
 	struct vhost_vring_file file;
 	struct vhost_vring_state state;
 	struct vhost_vring_addr addr;
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 34ee6c9..0723a7a 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr,
 }
 
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions)
 {
 	uint64_t size = offsetof(struct vhost_memory, regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)
 	return 0;
 }
 
-int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+cuse_set_backend(struct vhost_cuse_device_ctx ctx,
+		 struct vhost_vring_file *file)
 {
 	struct virtio_net *dev;
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
index eb6b0ba..3f67154 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
@@ -38,11 +38,19 @@
 
 #include "vhost-net.h"
 
+/*
+ * Structure used to identify device context.
+ */
+struct vhost_cuse_device_ctx {
+	pid_t	pid;	/* PID of process calling the IOCTL. */
+	int	vid;	/* Virtio-net device ID */
+};
+
 int
-cuse_set_mem_table(struct vhost_device_ctx ctx,
+cuse_set_mem_table(struct vhost_cuse_device_ctx ctx,
 	const struct vhost_memory *mem_regions_addr, uint32_t nregions);
 
 int
-cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *);
+cuse_set_backend(struct vhost_cuse_device_ctx ctx, struct vhost_vring_file *);
 
 #endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (6 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07 11:42       ` Panu Matilainen
  2016-06-08 21:51       ` Rich Lane
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
                       ` (13 subsequent siblings)
  21 siblings, 2 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Introduce a new API rte_vhost_get_numa_node() to get the numa node
from which the virtio_net struct is allocated.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 drivers/net/vhost/rte_eth_vhost.c      | 13 ++++---------
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/rte_virtio_net.h      | 12 ++++++++++++
 lib/librte_vhost/virtio-net.c          | 26 ++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 63538c1..204abff 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -230,7 +230,7 @@ new_device(struct virtio_net *dev)
 	struct vhost_queue *vq;
 	unsigned i;
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	int newnode, ret;
+	int newnode;
 #endif
 
 	if (dev == NULL) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
 	internal = eth_dev->data->dev_private;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	ret  = get_mempolicy(&newnode, NULL, 0, dev,
-			MPOL_F_NODE | MPOL_F_ADDR);
-	if (ret < 0) {
-		RTE_LOG(ERR, PMD, "Unknown numa node\n");
-		return -1;
-	}
-
-	eth_dev->data->numa_node = newnode;
+	newnode = rte_vhost_get_numa_node(dev->vid);
+	if (newnode > 0)
+		eth_dev->data->numa_node = newnode;
 #endif
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 3d8709e..bf7b000 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -20,3 +20,10 @@ DPDK_2.1 {
 	rte_vhost_driver_unregister;
 
 } DPDK_2.0;
+
+DPDK_16.07 {
+	global:
+
+	rte_vhost_get_numa_node;
+
+} DPDK_16.04;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index bc64e89..b8e9b02 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get the numa node from which the virtio net device's memory
+ * is allocated.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The numa node, -1 on failure
+ */
+int rte_vhost_get_numa_node(int vid);
+
+/**
  * 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 c6d3829..25b6515 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	return 0;
 }
 
+int
+rte_vhost_get_numa_node(int vid)
+{
+#ifdef RTE_LIBRTE_VHOST_NUMA
+	struct virtio_net *dev = get_device(vid);
+	int numa_node;
+	int ret;
+
+	if (dev == NULL)
+		return -1;
+
+	ret = get_mempolicy(&numa_node, NULL, 0, dev,
+			    MPOL_F_NODE | MPOL_F_ADDR);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%d) failed to query numa node: %d\n", vid, ret);
+		return -1;
+	}
+
+	return numa_node;
+#else
+	RTE_SET_USED(vid);
+	return -1;
+#endif
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (7 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
@ 2016-06-07  3:51     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
                       ` (12 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:51 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Introduce a new API rte_vhost_get_queue_num() to export the number of
queues.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 drivers/net/vhost/rte_eth_vhost.c      |  2 +-
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/rte_virtio_net.h      | 11 +++++++++++
 lib/librte_vhost/virtio-net.c          | 11 +++++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 204abff..fe0ce90 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -270,7 +270,7 @@ new_device(struct virtio_net *dev)
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
+	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;
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index bf7b000..a65fa21 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -25,5 +25,6 @@ DPDK_16.07 {
 	global:
 
 	rte_vhost_get_numa_node;
+	rte_vhost_get_queue_num;
 
 } DPDK_16.04;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index b8e9b02..de56b1b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -257,6 +257,17 @@ int rte_vhost_driver_session_start(void);
 int rte_vhost_get_numa_node(int vid);
 
 /**
+ * Get the number of queues the device supports.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The number of queues, 0 on failure
+ */
+uint32_t rte_vhost_get_queue_num(int vid);
+
+/**
  * 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 25b6515..a03ff30 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -756,6 +756,17 @@ rte_vhost_get_numa_node(int vid)
 #endif
 }
 
+uint32_t
+rte_vhost_get_queue_num(int vid)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return 0;
+
+	return dev->virt_qp_nb;
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (8 preceding siblings ...)
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
                       ` (11 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Introduce a new API rte_vhost_get_ifname() to export the ifname to
application.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 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

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (9 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
                       ` (10 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

The new API rte_vhost_avail_entries() is actually a rename of
rte_vring_available_entries(), with the "vring" to "vhost" name
change to keep the consistency of other vhost exported APIs.

This change could let us avoid the dependency of "virtio_net"
struct, to prepare for the ABI refactoring.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 doc/guides/rel_notes/release_16_07.rst |  2 ++
 examples/vhost/main.c                  |  4 ++--
 lib/librte_vhost/rte_vhost_version.map |  1 +
 lib/librte_vhost/rte_virtio_net.h      | 24 +++++++++++++-----------
 lib/librte_vhost/virtio-net.c          | 17 +++++++++++++++++
 5 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst
index 30e78d4..7b602b7 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -116,6 +116,8 @@ API Changes
   ibadcrc, ibadlen, imcasts, fdirmatch, fdirmiss,
   tx_pause_xon, rx_pause_xon, tx_pause_xoff, rx_pause_xoff.
 
+* ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``.
+
 
 ABI Changes
 -----------
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index d04f779..3ae302f 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1055,13 +1055,13 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vring_available_entries(dev,
+	    unlikely(rx_count > rte_vhost_avail_entries(dev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vring_available_entries(dev,
+			if (rx_count <= rte_vhost_avail_entries(dev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 4608e3b..93f1188 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_avail_entries;
 	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 0898e8b..0427461 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -184,17 +184,6 @@ struct virtio_net_device_ops {
 	int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 };
 
-static inline uint16_t __attribute__((always_inline))
-rte_vring_available_entries(struct virtio_net *dev, uint16_t queue_id)
-{
-	struct vhost_virtqueue *vq = dev->virtqueue[queue_id];
-
-	if (!vq->enabled)
-		return 0;
-
-	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
-}
-
 /**
  * Function to convert guest physical addresses to vhost virtual addresses.
  * This is used to convert guest virtio buffer addresses.
@@ -285,6 +274,19 @@ uint32_t rte_vhost_get_queue_num(int vid);
 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
 
 /**
+ * Get how many avail entries are left in the queue
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param queue_id
+ *  virtio queue index
+ *
+ * @return
+ *  num of avail entires left
+ */
+uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
+
+/**
  * 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 375c9d4..115eba4 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -783,6 +783,23 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len)
 	return 0;
 }
 
+uint16_t
+rte_vhost_avail_entries(int vid, uint16_t queue_id)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	vq = dev->virtqueue[queue_id];
+	if (!vq->enabled)
+		return 0;
+
+	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (10 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
                       ` (9 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

This change could let us avoid the dependency of "virtio_net"
struct, to prepare for the ABI refactoring.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 13 +++++++------
 examples/vhost/main.c             | 10 +++++++---
 2 files changed, 14 insertions(+), 9 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 3ae302f..9b74a16 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);
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (11 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
                       ` (8 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

With all the previous prepare works, we are just one step away from
the final ABI refactoring. That is, to change current API to let them
stick to vid instead of the old virtio_net dev.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---

v2: update release note

v3: - bump the ABI version to 3.
    - remove "struct virtio_net *dev" field in vhost example
---
 doc/guides/rel_notes/release_16_07.rst        |  9 ++++-
 drivers/net/vhost/rte_eth_vhost.c             | 47 +++++++++------------------
 examples/vhost/main.c                         | 25 +++++++-------
 examples/vhost/main.h                         |  2 --
 lib/librte_vhost/Makefile                     |  2 +-
 lib/librte_vhost/rte_virtio_net.h             | 18 +++++-----
 lib/librte_vhost/vhost_rxtx.c                 | 15 +++++++--
 lib/librte_vhost/vhost_user/virtio-net-user.c | 14 ++++----
 lib/librte_vhost/virtio-net.c                 | 17 ++++++----
 9 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst
index 7b602b7..8dbcf8a 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -118,6 +118,10 @@ API Changes
 
 * ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``.
 
+* All existing vhost APIs and callbacks with ``virtio_net`` struct pointer
+  as the parameter have been changed due to the ABI refactoring mentioned
+  below: it's replaced by ``int vid``.
+
 
 ABI Changes
 -----------
@@ -129,6 +133,9 @@ ABI Changes
 * The ``rte_port_source_params`` structure has new fields to support PCAP file.
   It was already in release 16.04 with ``RTE_NEXT_ABI`` flag.
 
+* vhost ABI refactoring has been made: ``virtio_net`` structure is never
+  exported to application any more. Instead, a handle, ``vid``, has been
+  used to represent this structure internally.
 
 Shared Library Versions
 -----------------------
@@ -165,7 +172,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_sched.so.1
      librte_table.so.2
      librte_timer.so.1
-     librte_vhost.so.2
+   + librte_vhost.so.3
 
 
 Tested Platforms
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index de0f25e..56c1c36 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -71,9 +71,9 @@ static struct ether_addr base_eth_addr = {
 };
 
 struct vhost_queue {
+	int vid;
 	rte_atomic32_t allow_queuing;
 	rte_atomic32_t while_queuing;
-	struct virtio_net *device;
 	struct pmd_internal *internal;
 	struct rte_mempool *mb_pool;
 	uint8_t port;
@@ -139,7 +139,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Dequeue packets from guest TX queue */
-	nb_rx = rte_vhost_dequeue_burst(r->device,
+	nb_rx = rte_vhost_dequeue_burst(r->vid,
 			r->virtqueue_id, r->mb_pool, bufs, nb_bufs);
 
 	r->rx_pkts += nb_rx;
@@ -170,7 +170,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		goto out;
 
 	/* Enqueue packets to guest RX queue */
-	nb_tx = rte_vhost_enqueue_burst(r->device,
+	nb_tx = rte_vhost_enqueue_burst(r->vid,
 			r->virtqueue_id, bufs, nb_bufs);
 
 	r->tx_pkts += nb_tx;
@@ -222,7 +222,7 @@ find_internal_resource(char *ifname)
 }
 
 static int
-new_device(struct virtio_net *dev)
+new_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct internal_list *list;
@@ -234,12 +234,7 @@ new_device(struct virtio_net *dev)
 	int newnode;
 #endif
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return -1;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(INFO, PMD, "Invalid device name: %s\n", ifname);
@@ -250,7 +245,7 @@ new_device(struct virtio_net *dev)
 	internal = eth_dev->data->dev_private;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	newnode = rte_vhost_get_numa_node(dev->vid);
+	newnode = rte_vhost_get_numa_node(vid);
 	if (newnode > 0)
 		eth_dev->data->numa_node = newnode;
 #endif
@@ -259,7 +254,7 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
@@ -267,13 +262,13 @@ new_device(struct virtio_net *dev)
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = dev;
+		vq->vid = vid;
 		vq->internal = internal;
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < rte_vhost_get_queue_num(dev->vid) * VIRTIO_QNUM; i++)
-		rte_vhost_enable_guest_notification(dev, i, 0);
+	for (i = 0; i < rte_vhost_get_queue_num(vid) * VIRTIO_QNUM; i++)
+		rte_vhost_enable_guest_notification(vid, i, 0);
 
 	eth_dev->data->dev_link.link_status = ETH_LINK_UP;
 
@@ -298,7 +293,7 @@ new_device(struct virtio_net *dev)
 }
 
 static void
-destroy_device(volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct vhost_queue *vq;
@@ -306,12 +301,7 @@ destroy_device(volatile struct virtio_net *dev)
 	char ifname[PATH_MAX];
 	unsigned i;
 
-	if (dev == NULL) {
-		RTE_LOG(INFO, PMD, "Invalid argument\n");
-		return;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", ifname);
@@ -343,13 +333,13 @@ destroy_device(volatile struct virtio_net *dev)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 	for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		vq->device = NULL;
+		vq->vid = -1;
 	}
 
 	RTE_LOG(INFO, PMD, "Connection closed\n");
@@ -358,19 +348,14 @@ destroy_device(volatile struct virtio_net *dev)
 }
 
 static int
-vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)
+vring_state_changed(int vid, 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;
-	}
-
-	rte_vhost_get_ifname(dev->vid, ifname, sizeof(ifname));
+	rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
 	list = find_internal_resource(ifname);
 	if (list == NULL) {
 		RTE_LOG(ERR, PMD, "Invalid interface name: %s\n", ifname);
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 9b74a16..c854660 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -795,7 +795,7 @@ virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev,
 {
 	uint16_t ret;
 
-	ret = rte_vhost_enqueue_burst(dst_vdev->dev, VIRTIO_RXQ, &m, 1);
+	ret = rte_vhost_enqueue_burst(dst_vdev->vid, VIRTIO_RXQ, &m, 1);
 	if (enable_stats) {
 		rte_atomic64_inc(&dst_vdev->stats.rx_total_atomic);
 		rte_atomic64_add(&dst_vdev->stats.rx_atomic, ret);
@@ -1041,7 +1041,6 @@ static inline void __attribute__((always_inline))
 drain_eth_rx(struct vhost_dev *vdev)
 {
 	uint16_t rx_count, enqueue_count;
-	struct virtio_net *dev = vdev->dev;
 	struct rte_mbuf *pkts[MAX_PKT_BURST];
 
 	rx_count = rte_eth_rx_burst(ports[0], vdev->vmdq_rx_q,
@@ -1055,19 +1054,19 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vhost_avail_entries(dev->vid,
+	    unlikely(rx_count > rte_vhost_avail_entries(vdev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vhost_avail_entries(dev->vid,
+			if (rx_count <= rte_vhost_avail_entries(vdev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
 	}
 
-	enqueue_count = rte_vhost_enqueue_burst(dev, VIRTIO_RXQ,
+	enqueue_count = rte_vhost_enqueue_burst(vdev->vid, VIRTIO_RXQ,
 						pkts, rx_count);
 	if (enable_stats) {
 		rte_atomic64_add(&vdev->stats.rx_total_atomic, rx_count);
@@ -1084,7 +1083,7 @@ drain_virtio_tx(struct vhost_dev *vdev)
 	uint16_t count;
 	uint16_t i;
 
-	count = rte_vhost_dequeue_burst(vdev->dev, VIRTIO_TXQ, mbuf_pool,
+	count = rte_vhost_dequeue_burst(vdev->vid, VIRTIO_TXQ, mbuf_pool,
 					pkts, MAX_PKT_BURST);
 
 	/* setup VMDq for the first packet */
@@ -1171,13 +1170,13 @@ switch_worker(void *arg __rte_unused)
  * of dev->remove=1 which can cause an infinite loop in the rte_pause loop.
  */
 static void
-destroy_device (volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct vhost_dev *vdev = NULL;
 	int lcore;
 
 	TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) {
-		if (vdev->vid == dev->vid)
+		if (vdev->vid == vid)
 			break;
 	}
 	if (!vdev)
@@ -1221,12 +1220,11 @@ destroy_device (volatile struct virtio_net *dev)
  * and the allocated to a specific data core.
  */
 static int
-new_device (struct virtio_net *dev)
+new_device(int vid)
 {
 	int lcore, core_add = 0;
 	uint32_t device_num_min = num_devices;
 	struct vhost_dev *vdev;
-	int vid = dev->vid;
 
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
@@ -1235,7 +1233,6 @@ new_device (struct virtio_net *dev)
 			vid);
 		return -1;
 	}
-	vdev->dev = dev;
 	vdev->vid = vid;
 
 	TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, global_vdev_entry);
@@ -1259,8 +1256,8 @@ new_device (struct virtio_net *dev)
 	lcore_info[vdev->coreid].device_num++;
 
 	/* Disable notifications. */
-	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
-	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_RXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_TXQ, 0);
 
 	RTE_LOG(INFO, VHOST_DATA,
 		"(%d) device has been added to data core %d\n",
@@ -1316,7 +1313,7 @@ print_stats(void)
 				"RX total:              %" PRIu64 "\n"
 				"RX dropped:            %" PRIu64 "\n"
 				"RX successful:         %" PRIu64 "\n",
-				vdev->dev->vid,
+				vdev->vid,
 				tx_total, tx_dropped, tx,
 				rx_total, rx_dropped, rx);
 		}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index e99c436..6bb42e8 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -49,8 +49,6 @@ struct device_statistics {
 };
 
 struct vhost_dev {
-	/**< Pointer to device created by vhost lib. */
-	struct virtio_net      *dev;
 	/**< Number of memory regions for gpa to hpa translation. */
 	uint32_t nregions_hpa;
 	/**< Device MAC address (Obtained on first TX packet). */
diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index e33ff53..7ef8d34 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -36,7 +36,7 @@ LIB = librte_vhost.a
 
 EXPORT_MAP := rte_vhost_version.map
 
-LIBABIVER := 2
+LIBABIVER := 3
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64
 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y)
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 0427461..370345e 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -178,10 +178,10 @@ struct virtio_memory {
  *
  */
 struct virtio_net_device_ops {
-	int (*new_device)(struct virtio_net *);	/**< Add device. */
-	void (*destroy_device)(volatile struct virtio_net *);	/**< Remove device. */
+	int (*new_device)(int vid);		/**< Add device. */
+	void (*destroy_device)(int vid);	/**< Remove device. */
 
-	int (*vring_state_changed)(struct virtio_net *dev, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 };
 
 /**
@@ -220,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);
 /* Returns currently supported vhost features */
 uint64_t rte_vhost_feature_get(void);
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t queue_id, int enable);
+int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
 
 /* Register vhost driver. dev_name could be different for multiple instance support. */
 int rte_vhost_driver_register(const char *dev_name);
@@ -291,8 +291,8 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
  * 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
  * added to the RX queue.
- * @param dev
- *  virtio-net device
+ * @param vid
+ *  virtio-net device ID
  * @param queue_id
  *  virtio queue index in mq case
  * @param pkts
@@ -302,14 +302,14 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
  * @return
  *  num of packets enqueued
  */
-uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count);
 
 /**
  * This function gets guest buffers from the virtio device TX virtqueue,
  * construct host mbufs, copies guest buffer content to host mbufs and
  * store them in pkts to be processed.
- * @param dev
+ * @param vid
  *  virtio-net device
  * @param queue_id
  *  virtio queue index in mq case
@@ -322,7 +322,7 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
  * @return
  *  num of packets dequeued
  */
-uint16_t rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
 
 #endif /* _VIRTIO_NET_H_ */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 8d87508..08cab08 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,6 +46,7 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
+#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 }
 
 uint16_t
-rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return 0;
+
 	if (dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF))
 		return virtio_dev_merge_rx(dev, queue_id, pkts, count);
 	else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 }
 
 uint16_t
-rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
+rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
 {
+	struct virtio_net *dev;
 	struct rte_mbuf *rarp_mbuf = NULL;
 	struct vhost_virtqueue *vq;
 	uint32_t desc_indexes[MAX_PKT_BURST];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	uint16_t free_entries;
 	uint16_t avail_idx;
 
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 9385af1..7fa69a7 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 	/* Remove from the data plane. */
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
 
+	if (!dev)
+		return;
+
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
 		file.fd = VIRTIO_INVALID_EVENTFD;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	vhost_set_vring_kick(vid, &file);
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (notify_ops->new_device(dev) == 0)
+		if (notify_ops->new_device(vid) == 0)
 			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,
 		return -1;
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 
 	/* Here we are safe to get the last used index */
 	vhost_get_vring_base(vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,
 		"set queue enable: %d to qp idx: %d\n",
 		enable, state->index);
 
-	if (notify_ops->vring_state_changed) {
-		notify_ops->vring_state_changed(dev, state->index, enable);
-	}
+	if (notify_ops->vring_state_changed)
+		notify_ops->vring_state_changed(vid, state->index, enable);
 
 	dev->virtqueue[state->index]->enabled = enable;
 
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 115eba4..ea216c0 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 1);
@@ -354,7 +354,7 @@ vhost_reset_owner(int vid)
 
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	cleanup_device(dev, 0);
@@ -718,13 +718,13 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
 		    dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
-			if (notify_ops->new_device(dev) < 0)
+			if (notify_ops->new_device(vid) < 0)
 				return -1;
 			dev->flags |= VIRTIO_DEV_RUNNING;
 		}
 	} else if (file->fd == VIRTIO_DEV_STOPPED) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(dev);
+		notify_ops->destroy_device(vid);
 	}
 
 	return 0;
@@ -800,9 +800,14 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)
 	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
 }
 
-int rte_vhost_enable_guest_notification(struct virtio_net *dev,
-	uint16_t queue_id, int enable)
+int
+rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
 {
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return -1;
+
 	if (enable) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"guest notification isn't supported.\n");
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (12 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
                       ` (7 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

We are now safe to move all those internal structs/macros/functions to
vhost-net.h, to hide them from external access.

This patch also breaks long lines and removes some redundant comments.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/rte_virtio_net.h            | 139 -------------------------
 lib/librte_vhost/vhost-net.h                 | 148 +++++++++++++++++++++++++++
 lib/librte_vhost/vhost_user/vhost-net-user.h |   2 +
 3 files changed, 150 insertions(+), 139 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 370345e..fc1d799 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -51,125 +51,9 @@
 #include <rte_mempool.h>
 #include <rte_ether.h>
 
-struct rte_mbuf;
-
-#define VHOST_MEMORY_MAX_NREGIONS 8
-
-/* Used to indicate that the device is running on a data core */
-#define VIRTIO_DEV_RUNNING 1
-
-/* Backend value set by guest. */
-#define VIRTIO_DEV_STOPPED -1
-
-
 /* Enum for virtqueue management. */
 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
 
-#define BUF_VECTOR_MAX 256
-
-/**
- * Structure contains buffer address, length and descriptor index
- * from vring to do scatter RX.
- */
-struct buf_vector {
-	uint64_t buf_addr;
-	uint32_t buf_len;
-	uint32_t desc_idx;
-};
-
-/**
- * Structure contains variables relevant to RX/TX virtqueues.
- */
-struct vhost_virtqueue {
-	struct vring_desc	*desc;			/**< Virtqueue descriptor ring. */
-	struct vring_avail	*avail;			/**< Virtqueue available ring. */
-	struct vring_used	*used;			/**< Virtqueue used ring. */
-	uint32_t		size;			/**< Size of descriptor ring. */
-	int			backend;		/**< Backend value to determine if device should started/stopped. */
-	uint16_t		vhost_hlen;		/**< Vhost header length (varies depending on RX merge buffers. */
-	volatile uint16_t	last_used_idx;		/**< Last index used on the available ring */
-	volatile uint16_t	last_used_idx_res;	/**< Used for multiple devices reserving buffers. */
-#define VIRTIO_INVALID_EVENTFD		(-1)
-#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
-	int			callfd;			/**< Used to notify the guest (trigger interrupt). */
-	int			kickfd;			/**< Currently unused as polling mode is enabled. */
-	int			enabled;
-	uint64_t		log_guest_addr;		/**< Physical address of used ring, for logging */
-	uint64_t		reserved[15];		/**< Reserve some spaces for future extension. */
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];	/**< for scatter RX. */
-} __rte_cache_aligned;
-
-/* Old kernels have no such macro defined */
-#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
- #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
-#endif
-
-
-/*
- * Make an extra wrapper for VIRTIO_NET_F_MQ and
- * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
- * introduced since kernel v3.8. This makes our
- * code buildable for older kernel.
- */
-#ifdef VIRTIO_NET_F_MQ
- #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
- #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
-#else
- #define VHOST_MAX_QUEUE_PAIRS	1
- #define VHOST_SUPPORTS_MQ	0
-#endif
-
-/*
- * Define virtio 1.0 for older kernels
- */
-#ifndef VIRTIO_F_VERSION_1
- #define VIRTIO_F_VERSION_1 32
-#endif
-
-/**
- * Device structure contains all configuration information relating to the device.
- */
-struct virtio_net {
-	struct virtio_memory	*mem;		/**< QEMU memory and memory region information. */
-	uint64_t		features;	/**< Negotiated feature set. */
-	uint64_t		protocol_features;	/**< Negotiated protocol feature set. */
-	int			vid;		/**< device identifier. */
-	uint32_t		flags;		/**< Device flags. Only used to check if device is running on data core. */
-#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
-	char			ifname[IF_NAME_SZ];	/**< Name of the tap device or socket path. */
-	uint32_t		virt_qp_nb;	/**< number of queue pair we have allocated */
-	void			*priv;		/**< private context */
-	uint64_t		log_size;	/**< Size of log area */
-	uint64_t		log_base;	/**< Where dirty pages are logged */
-	struct ether_addr	mac;		/**< MAC address */
-	rte_atomic16_t		broadcast_rarp;	/**< A flag to tell if we need broadcast rarp packet */
-	uint64_t		reserved[61];	/**< Reserve some spaces for future extension. */
-	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];	/**< Contains all virtqueue information. */
-} __rte_cache_aligned;
-
-/**
- * Information relating to memory regions including offsets to addresses in QEMUs memory file.
- */
-struct virtio_memory_regions {
-	uint64_t	guest_phys_address;	/**< Base guest physical address of region. */
-	uint64_t	guest_phys_address_end;	/**< End guest physical address of region. */
-	uint64_t	memory_size;		/**< Size of region. */
-	uint64_t	userspace_address;	/**< Base userspace address of region. */
-	uint64_t	address_offset;		/**< Offset of region for address translation. */
-};
-
-
-/**
- * Memory structure includes region and mapping information.
- */
-struct virtio_memory {
-	uint64_t	base_address;	/**< Base QEMU userspace address of the memory file. */
-	uint64_t	mapped_address;	/**< Mapped address of memory file base in our applications memory space. */
-	uint64_t	mapped_size;	/**< Total size of memory file. */
-	uint32_t	nregions;	/**< Number of memory regions. */
-	struct virtio_memory_regions      regions[0]; /**< Memory region information. */
-};
-
 /**
  * Device and vring operations.
  *
@@ -185,29 +69,6 @@ struct virtio_net_device_ops {
 };
 
 /**
- * Function to convert guest physical addresses to vhost virtual addresses.
- * This is used to convert guest virtio buffer addresses.
- */
-static inline uint64_t __attribute__((always_inline))
-gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
-{
-	struct virtio_memory_regions *region;
-	uint32_t regionidx;
-	uint64_t vhost_va = 0;
-
-	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
-		region = &dev->mem->regions[regionidx];
-		if ((guest_pa >= region->guest_phys_address) &&
-			(guest_pa <= region->guest_phys_address_end)) {
-			vhost_va = region->address_offset + guest_pa;
-			break;
-		}
-	}
-	return vhost_va;
-}
-
-
-/**
  *  Disable features in feature_mask. Returns 0 on success.
  */
 int rte_vhost_feature_disable(uint64_t feature_mask);
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 4ed5816..3edeb92 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,6 +43,133 @@
 
 #include "rte_virtio_net.h"
 
+/* Used to indicate that the device is running on a data core */
+#define VIRTIO_DEV_RUNNING 1
+
+/* Backend value set by guest. */
+#define VIRTIO_DEV_STOPPED -1
+
+#define BUF_VECTOR_MAX 256
+
+/**
+ * Structure contains buffer address, length and descriptor index
+ * from vring to do scatter RX.
+ */
+struct buf_vector {
+	uint64_t buf_addr;
+	uint32_t buf_len;
+	uint32_t desc_idx;
+};
+
+/**
+ * Structure contains variables relevant to RX/TX virtqueues.
+ */
+struct vhost_virtqueue {
+	struct vring_desc	*desc;
+	struct vring_avail	*avail;
+	struct vring_used	*used;
+	uint32_t		size;
+	uint16_t		vhost_hlen;
+
+	/* Last index used on the available ring */
+	volatile uint16_t	last_used_idx;
+	/* Used for multiple devices reserving buffers */
+	volatile uint16_t	last_used_idx_res;
+#define VIRTIO_INVALID_EVENTFD		(-1)
+#define VIRTIO_UNINITIALIZED_EVENTFD	(-2)
+
+	/* Backend value to determine if device should started/stopped */
+	int			backend;
+	/* Used to notify the guest (trigger interrupt) */
+	int			callfd;
+	/* Currently unused as polling mode is enabled */
+	int			kickfd;
+	int			enabled;
+
+	/* Physical address of used ring, for logging */
+	uint64_t		log_guest_addr;
+	uint64_t		reserved[15];
+	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
+} __rte_cache_aligned;
+
+/* Old kernels have no such macro defined */
+#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
+ #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
+#endif
+
+
+/*
+ * Make an extra wrapper for VIRTIO_NET_F_MQ and
+ * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are
+ * introduced since kernel v3.8. This makes our
+ * code buildable for older kernel.
+ */
+#ifdef VIRTIO_NET_F_MQ
+ #define VHOST_MAX_QUEUE_PAIRS	VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX
+ #define VHOST_SUPPORTS_MQ	(1ULL << VIRTIO_NET_F_MQ)
+#else
+ #define VHOST_MAX_QUEUE_PAIRS	1
+ #define VHOST_SUPPORTS_MQ	0
+#endif
+
+/*
+ * Define virtio 1.0 for older kernels
+ */
+#ifndef VIRTIO_F_VERSION_1
+ #define VIRTIO_F_VERSION_1 32
+#endif
+
+/**
+ * Device structure contains all configuration information relating
+ * to the device.
+ */
+struct virtio_net {
+	/* Frontend (QEMU) memory and memory region information */
+	struct virtio_memory	*mem;
+	uint64_t		features;
+	uint64_t		protocol_features;
+	int			vid;
+	uint32_t		flags;
+#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
+	char			ifname[IF_NAME_SZ];
+	uint32_t		virt_qp_nb;
+	void			*priv;
+	uint64_t		log_size;
+	uint64_t		log_base;
+	struct ether_addr	mac;
+
+	/* to tell if we need broadcast rarp packet */
+	rte_atomic16_t		broadcast_rarp;
+	uint64_t		reserved[61];
+	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
+} __rte_cache_aligned;
+
+/**
+ * Information relating to memory regions including offsets to
+ * addresses in QEMUs memory file.
+ */
+struct virtio_memory_regions {
+	uint64_t guest_phys_address;
+	uint64_t guest_phys_address_end;
+	uint64_t memory_size;
+	uint64_t userspace_address;
+	uint64_t address_offset;
+};
+
+
+/**
+ * Memory structure includes region and mapping information.
+ */
+struct virtio_memory {
+	/* Base QEMU userspace address of the memory file. */
+	uint64_t base_address;
+	uint64_t mapped_address;
+	uint64_t mapped_size;
+	uint32_t nregions;
+	struct virtio_memory_regions regions[0];
+};
+
+
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
@@ -74,6 +201,27 @@
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
+/**
+ * Function to convert guest physical addresses to vhost virtual addresses.
+ * This is used to convert guest virtio buffer addresses.
+ */
+static inline uint64_t __attribute__((always_inline))
+gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
+{
+	struct virtio_memory_regions *region;
+	uint32_t regionidx;
+	uint64_t vhost_va = 0;
+
+	for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) {
+		region = &dev->mem->regions[regionidx];
+		if ((guest_pa >= region->guest_phys_address) &&
+			(guest_pa <= region->guest_phys_address_end)) {
+			vhost_va = region->address_offset + guest_pa;
+			break;
+		}
+	}
+	return vhost_va;
+}
 
 int vhost_new_device(void);
 void vhost_destroy_device(int);
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h
index e3bb413..ec68b96 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.h
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
@@ -47,6 +47,8 @@ struct vhost_server {
 
 /* refer to hw/virtio/vhost-user.c */
 
+#define VHOST_MEMORY_MAX_NREGIONS 8
+
 typedef enum VhostUserRequest {
 	VHOST_USER_NONE = 0,
 	VHOST_USER_GET_FEATURES = 1,
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (13 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
                       ` (6 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

The "reserved" field in virtio_net and vhost_virtqueue struct is not
necessary any more. We now expose virtio_net device with a number "vid".

This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access
it is to expose it by a function, but I doubt that's needed or worthwhile.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 3edeb92..c133ea8 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -88,7 +88,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	uint64_t		reserved[15];
 	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
@@ -133,14 +132,12 @@ struct virtio_net {
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
-	void			*priv;
 	uint64_t		log_size;
 	uint64_t		log_base;
 	struct ether_addr	mac;
 
 	/* to tell if we need broadcast rarp packet */
 	rte_atomic16_t		broadcast_rarp;
-	uint64_t		reserved[61];
 	struct vhost_virtqueue	*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];
 } __rte_cache_aligned;
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (14 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
                       ` (5 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

It barely has anything useful there, just 2 functions prototype. Here
move them to vhost-net.h, and delete it.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h                  |  3 ++
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  1 -
 lib/librte_vhost/vhost_rxtx.c                 |  1 -
 lib/librte_vhost/vhost_user/virtio-net-user.c |  1 -
 lib/librte_vhost/virtio-net.c                 |  1 -
 lib/librte_vhost/virtio-net.h                 | 43 ---------------------------
 6 files changed, 3 insertions(+), 47 deletions(-)
 delete mode 100644 lib/librte_vhost/virtio-net.h

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index c133ea8..dbd2d62 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -220,6 +220,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
 	return vhost_va;
 }
 
+struct virtio_net_device_ops const *notify_ops;
+struct virtio_net *get_device(int vid);
+
 int vhost_new_device(void);
 void vhost_destroy_device(int);
 
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 0723a7a..552be7d 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -54,7 +54,6 @@
 #include "rte_virtio_net.h"
 #include "vhost-net.h"
 #include "virtio-net-cdev.h"
-#include "virtio-net.h"
 #include "eventfd_copy.h"
 
 /* Line size for reading maps file. */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 08cab08..65278bb 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -46,7 +46,6 @@
 #include <rte_arp.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_PKT_BURST 32
 #define VHOST_LOG_PAGE	4096
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 7fa69a7..6463bdd 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -43,7 +43,6 @@
 #include <rte_common.h>
 #include <rte_log.h>
 
-#include "virtio-net.h"
 #include "virtio-net-user.h"
 #include "vhost-net-user.h"
 #include "vhost-net.h"
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index ea216c0..13dc021 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -53,7 +53,6 @@
 #include <rte_virtio_net.h>
 
 #include "vhost-net.h"
-#include "virtio-net.h"
 
 #define MAX_VHOST_DEVICE	1024
 static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
deleted file mode 100644
index 9812545..0000000
--- a/lib/librte_vhost/virtio-net.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _VIRTIO_NET_H
-#define _VIRTIO_NET_H
-
-#include "vhost-net.h"
-#include "rte_virtio_net.h"
-
-struct virtio_net_device_ops const *notify_ops;
-struct virtio_net *get_device(int vid);
-
-#endif
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (15 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
                       ` (4 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

"virtio_net_device_ops" is the only left open struct that an application
can access, therefore, it's the only place that might introduce potential
ABI break in future for extension.

So, do some reservation for it. 5 should be pretty enough, considering
that we have barely touched it for a long while. Another reason to
choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit
machine.

With this, it's confidence to say that we might be able to be free from
the ABI violation forever.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/rte_virtio_net.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index fc1d799..bc2b74b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -66,6 +66,8 @@ struct virtio_net_device_ops {
 	void (*destroy_device)(int vid);	/**< Remove device. */
 
 	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
+
+	void *reserved[5]; /**< Reserved for future extension */
 };
 
 /**
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (16 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
                       ` (3 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Adapt to the new vhost ABI/API refactoring changes, to not break the
build. It's a straightforward change: replace "struct virtio_net *dev"
with "int fd". Simple build test only so far.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---

tep_term is built on top of vhost switch example; they shared a lot of
code (before the vhost example cleanup). Idealy, we might should move
the vxlan part to vhost example, and introduce an option to enable it.

However, I found that would take more effort, including the effort
of making it co-work with VLAN and VMDq stuff as well as the effort
to not break anything, I found it's better to start simple first:
just do a new ABI/API adaption.
---
 examples/tep_termination/main.c        | 83 +++++++++++++++++-----------------
 examples/tep_termination/main.h        |  5 +-
 examples/tep_termination/vxlan_setup.c | 20 ++++----
 examples/tep_termination/vxlan_setup.h |  6 +--
 4 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c
index b8297dd..32eb925 100644
--- a/examples/tep_termination/main.c
+++ b/examples/tep_termination/main.c
@@ -566,10 +566,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m)
 	struct rte_mbuf **m_table;
 	unsigned len, ret = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net *dev = vdev->dev;
+	int vid = vdev->vid;
 
-	RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: MAC address is external\n",
-		dev->device_fh);
+	RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is external\n", vid);
 
 	/* Add packet to the port tx queue */
 	tx_q = &lcore_tx_queue[lcore_id];
@@ -578,8 +577,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m)
 	tx_q->m_table[len] = m;
 	len++;
 	if (enable_stats) {
-		dev_statistics[dev->device_fh].tx_total++;
-		dev_statistics[dev->device_fh].tx++;
+		dev_statistics[vid].tx_total++;
+		dev_statistics[vid].tx++;
 	}
 
 	if (unlikely(len == MAX_PKT_BURST)) {
@@ -614,7 +613,7 @@ static int
 switch_worker(__rte_unused void *arg)
 {
 	struct rte_mempool *mbuf_pool = arg;
-	struct virtio_net *dev = NULL;
+	int vid;
 	struct vhost_dev *vdev = NULL;
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	struct virtio_net_data_ll *dev_ll;
@@ -688,7 +687,7 @@ switch_worker(__rte_unused void *arg)
 
 		while (dev_ll != NULL) {
 			vdev = dev_ll->vdev;
-			dev = vdev->dev;
+			vid = vdev->vid;
 
 			if (unlikely(vdev->remove)) {
 				dev_ll = dev_ll->next;
@@ -709,22 +708,22 @@ switch_worker(__rte_unused void *arg)
 					* must be less than virtio queue size
 					*/
 					if (enable_retry && unlikely(rx_count >
-						rte_vring_available_entries(dev, VIRTIO_RXQ))) {
+						rte_vhost_avail_entries(vid, VIRTIO_RXQ))) {
 						for (retry = 0; retry < burst_rx_retry_num;
 							retry++) {
 							rte_delay_us(burst_rx_delay_time);
-							if (rx_count <= rte_vring_available_entries(dev, VIRTIO_RXQ))
+							if (rx_count <= rte_vhost_avail_entries(vid, VIRTIO_RXQ))
 								break;
 						}
 					}
 
-					ret_count = overlay_options.rx_handle(dev, pkts_burst, rx_count);
+					ret_count = overlay_options.rx_handle(vid, pkts_burst, rx_count);
 					if (enable_stats) {
 						rte_atomic64_add(
-						&dev_statistics[dev->device_fh].rx_total_atomic,
+						&dev_statistics[vid].rx_total_atomic,
 						rx_count);
 						rte_atomic64_add(
-						&dev_statistics[dev->device_fh].rx_atomic, ret_count);
+						&dev_statistics[vid].rx_atomic, ret_count);
 					}
 					while (likely(rx_count)) {
 						rx_count--;
@@ -736,7 +735,7 @@ switch_worker(__rte_unused void *arg)
 
 			if (likely(!vdev->remove)) {
 				/* Handle guest TX*/
-				tx_count = rte_vhost_dequeue_burst(dev,
+				tx_count = rte_vhost_dequeue_burst(vid,
 						VIRTIO_TXQ, mbuf_pool,
 						pkts_burst, MAX_PKT_BURST);
 				/* If this is the first received packet we need to learn the MAC */
@@ -913,18 +912,24 @@ init_data_ll(void)
  * loop in the rte_pause loop.
  */
 static void
-destroy_device(volatile struct virtio_net *dev)
+destroy_device(int vid)
 {
 	struct virtio_net_data_ll *ll_lcore_dev_cur;
 	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 == vid) {
+			vdev = ll_main_dev_cur->vdev;
+			break;
+		}
+	}
+	if (!vdev)
+		return;
 
 	/* set the remove flag. */
 	vdev->remove = 1;
@@ -944,8 +949,7 @@ destroy_device(volatile struct virtio_net *dev)
 
 	if (ll_lcore_dev_cur == NULL) {
 		RTE_LOG(ERR, VHOST_CONFIG,
-			"(%"PRIu64") Failed to find the dev to be destroy.\n",
-			dev->device_fh);
+			"(%d) Failed to find the dev to be destroy.\n", vid);
 		return;
 	}
 
@@ -992,8 +996,8 @@ destroy_device(volatile struct virtio_net *dev)
 	/* Decrement number of device on the lcore. */
 	lcore_info[vdev->coreid].lcore_ll->device_num--;
 
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been removed "
-		"from data core\n", dev->device_fh);
+	RTE_LOG(INFO, VHOST_DATA, "(%d) Device has been removed "
+		"from data core\n", vid);
 
 	rte_free(vdev);
 
@@ -1004,7 +1008,7 @@ destroy_device(volatile struct virtio_net *dev)
  * to the main linked list and the allocated to a specific data core.
  */
 static int
-new_device(struct virtio_net *dev)
+new_device(int vid)
 {
 	struct virtio_net_data_ll *ll_dev;
 	int lcore, core_add = 0;
@@ -1014,18 +1018,16 @@ new_device(struct virtio_net *dev)
 	vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
 	if (vdev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%"PRIu64") Couldn't allocate memory for vhost dev\n",
-			dev->device_fh);
+			"(%d) Couldn't allocate memory for vhost dev\n", vid);
 		return -1;
 	}
-	vdev->dev = dev;
-	dev->priv = vdev;
+	vdev->vid = vid;
 	/* Add device to main ll */
 	ll_dev = get_data_ll_free_entry(&ll_root_free);
 	if (ll_dev == NULL) {
-		RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") No free entry found in"
+		RTE_LOG(INFO, VHOST_DATA, "(%d) No free entry found in"
 			" linked list Device limit of %d devices per core"
-			" has been reached\n", dev->device_fh, nb_devices);
+			" has been reached\n", vid, nb_devices);
 		if (vdev->regions_hpa)
 			rte_free(vdev->regions_hpa);
 		rte_free(vdev);
@@ -1033,7 +1035,7 @@ new_device(struct virtio_net *dev)
 	}
 	ll_dev->vdev = vdev;
 	add_data_ll_entry(&ll_root_used, ll_dev);
-	vdev->rx_q = dev->device_fh;
+	vdev->rx_q = vid;
 
 	/* reset ready flag */
 	vdev->ready = DEVICE_MAC_LEARNING;
@@ -1050,10 +1052,9 @@ new_device(struct virtio_net *dev)
 	ll_dev = get_data_ll_free_entry(&lcore_info[core_add].lcore_ll->ll_root_free);
 	if (ll_dev == NULL) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%"PRIu64") Failed to add device to data core\n",
-			dev->device_fh);
+			"(%d) Failed to add device to data core\n", vid);
 		vdev->ready = DEVICE_SAFE_REMOVE;
-		destroy_device(dev);
+		destroy_device(vid);
 		rte_free(vdev->regions_hpa);
 		rte_free(vdev);
 		return -1;
@@ -1065,17 +1066,17 @@ new_device(struct virtio_net *dev)
 			ll_dev);
 
 	/* Initialize device stats */
-	memset(&dev_statistics[dev->device_fh], 0,
+	memset(&dev_statistics[vid], 0,
 		sizeof(struct device_statistics));
 
 	/* Disable notifications. */
-	rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0);
-	rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_RXQ, 0);
+	rte_vhost_enable_guest_notification(vid, VIRTIO_TXQ, 0);
 	lcore_info[vdev->coreid].lcore_ll->device_num++;
-	dev->flags |= VIRTIO_DEV_RUNNING;
 
-	RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n",
-		dev->device_fh, vdev->coreid);
+	RTE_LOG(INFO, VHOST_DATA,
+		"(%d) Device has been added to data core %d\n",
+		vid, vdev->coreid);
 
 	return 0;
 }
@@ -1113,7 +1114,7 @@ print_stats(void)
 
 		dev_ll = ll_root_used;
 		while (dev_ll != NULL) {
-			device_fh = (uint32_t)dev_ll->vdev->dev->device_fh;
+			device_fh = dev_ll->vdev->vid;
 			tx_total = dev_statistics[device_fh].tx_total;
 			tx = dev_statistics[device_fh].tx;
 			tx_dropped = tx_total - tx;
@@ -1257,7 +1258,7 @@ main(int argc, char *argv[])
 	rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_MRG_RXBUF);
 
 	/* Register CUSE device to handle IOCTLs. */
-	ret = rte_vhost_driver_register((char *)&dev_basename);
+	ret = rte_vhost_driver_register(dev_basename, 0);
 	if (ret != 0)
 		rte_exit(EXIT_FAILURE, "CUSE device setup failure.\n");
 
diff --git a/examples/tep_termination/main.h b/examples/tep_termination/main.h
index 4b123ab..c0ea766 100644
--- a/examples/tep_termination/main.h
+++ b/examples/tep_termination/main.h
@@ -71,8 +71,7 @@ struct device_statistics {
  * Device linked list structure for data path.
  */
 struct vhost_dev {
-	/**< Pointer to device created by vhost lib. */
-	struct virtio_net      *dev;
+	int vid;
 	/**< Number of memory regions for gpa to hpa translation. */
 	uint32_t nregions_hpa;
 	/**< Memory region information for gpa to hpa translation. */
@@ -116,6 +115,6 @@ struct virtio_net_data_ll {
 };
 
 uint32_t
-virtio_dev_rx(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count);
+virtio_dev_rx(int vid, struct rte_mbuf **pkts, uint32_t count);
 
 #endif /* _MAIN_H_ */
diff --git a/examples/tep_termination/vxlan_setup.c b/examples/tep_termination/vxlan_setup.c
index 2a48e14..58bc334 100644
--- a/examples/tep_termination/vxlan_setup.c
+++ b/examples/tep_termination/vxlan_setup.c
@@ -244,17 +244,17 @@ vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	int i, ret;
 	struct ether_hdr *pkt_hdr;
-	struct virtio_net *dev = vdev->dev;
-	uint64_t portid = dev->device_fh;
+	int vid = vdev->vid;
+	uint64_t portid = vid;
 	struct ipv4_hdr *ip;
 
 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
 
 	if (unlikely(portid > VXLAN_N_PORTS)) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%"PRIu64") WARNING: Not configuring device,"
+			"(%d) WARNING: Not configuring device,"
 			"as already have %d ports for VXLAN.",
-			dev->device_fh, VXLAN_N_PORTS);
+			vid, VXLAN_N_PORTS);
 		return -1;
 	}
 
@@ -262,9 +262,9 @@ vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m)
 	pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	if (is_same_ether_addr(&(pkt_hdr->s_addr), &vdev->mac_address)) {
 		RTE_LOG(INFO, VHOST_DATA,
-			"(%"PRIu64") WARNING: This device is using an existing"
+			"(%d) WARNING: This device is using an existing"
 			" MAC address and has not been registered.\n",
-			dev->device_fh);
+			vid);
 		return -1;
 	}
 
@@ -425,7 +425,7 @@ vxlan_tx_pkts(uint8_t port_id, uint16_t queue_id,
 
 /* Check for decapsulation and pass packets directly to VIRTIO device */
 int
-vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts_burst,
+vxlan_rx_pkts(int vid, struct rte_mbuf **pkts_burst,
 		uint32_t rx_count)
 {
 	uint32_t i = 0;
@@ -436,11 +436,11 @@ vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts_burst,
 	for (i = 0; i < rx_count; i++) {
 		if (enable_stats) {
 			rte_atomic64_add(
-				&dev_statistics[dev->device_fh].rx_bad_ip_csum,
+				&dev_statistics[vid].rx_bad_ip_csum,
 				(pkts_burst[i]->ol_flags & PKT_RX_IP_CKSUM_BAD)
 				!= 0);
 			rte_atomic64_add(
-				&dev_statistics[dev->device_fh].rx_bad_ip_csum,
+				&dev_statistics[vid].rx_bad_ip_csum,
 				(pkts_burst[i]->ol_flags & PKT_RX_L4_CKSUM_BAD)
 				!= 0);
 		}
@@ -452,6 +452,6 @@ vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts_burst,
 			count++;
 	}
 
-	ret = rte_vhost_enqueue_burst(dev, VIRTIO_RXQ, pkts_valid, count);
+	ret = rte_vhost_enqueue_burst(vid, VIRTIO_RXQ, pkts_valid, count);
 	return ret;
 }
diff --git a/examples/tep_termination/vxlan_setup.h b/examples/tep_termination/vxlan_setup.h
index 1846540..8d26461 100644
--- a/examples/tep_termination/vxlan_setup.h
+++ b/examples/tep_termination/vxlan_setup.h
@@ -55,10 +55,10 @@ typedef void (*ol_tunnel_destroy_t)(struct vhost_dev *vdev);
 typedef int (*ol_tx_handle_t)(uint8_t port_id, uint16_t queue_id,
 			      struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
 
-typedef int (*ol_rx_handle_t)(struct virtio_net *dev, struct rte_mbuf **pkts,
+typedef int (*ol_rx_handle_t)(int vid, struct rte_mbuf **pkts,
 			      uint32_t count);
 
-typedef int (*ol_param_handle)(struct virtio_net *dev);
+typedef int (*ol_param_handle)(int vid);
 
 struct ol_switch_ops {
 	ol_port_configure_t        port_configure;
@@ -82,6 +82,6 @@ int
 vxlan_tx_pkts(uint8_t port_id, uint16_t queue_id,
 			struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
 int
-vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count);
+vxlan_rx_pkts(int vid, struct rte_mbuf **pkts, uint32_t count);
 
 #endif /* VXLAN_SETUP_H_ */
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (17 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local Yuanhan Liu
                       ` (2 subsequent siblings)
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Yuanhan Liu

Virtio net header length is set per device, but not per queue. So, there
is no reason to store it in vhost_virtqueue struct, instead, we should
store it in virtio_net struct, to make one copy only.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h  |  2 +-
 lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++--------------------
 lib/librte_vhost/virtio-net.c | 13 ++-----------
 3 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index dbd2d62..590a039 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -69,7 +69,6 @@ struct vhost_virtqueue {
 	struct vring_avail	*avail;
 	struct vring_used	*used;
 	uint32_t		size;
-	uint16_t		vhost_hlen;
 
 	/* Last index used on the available ring */
 	volatile uint16_t	last_used_idx;
@@ -129,6 +128,7 @@ struct virtio_net {
 	uint64_t		protocol_features;
 	int			vid;
 	uint32_t		flags;
+	uint16_t		vhost_hlen;
 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
 	char			ifname[IF_NAME_SZ];
 	uint32_t		virt_qp_nb;
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 65278bb..c9cd1c5 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 }
 
 static inline void
-copy_virtio_net_hdr(struct vhost_virtqueue *vq, uint64_t desc_addr,
+copy_virtio_net_hdr(struct virtio_net *dev, uint64_t desc_addr,
 		    struct virtio_net_hdr_mrg_rxbuf hdr)
 {
-	if (vq->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
+	if (dev->vhost_hlen == sizeof(struct virtio_net_hdr_mrg_rxbuf))
 		*(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)desc_addr = hdr;
 	else
 		*(struct virtio_net_hdr *)(uintptr_t)desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, desc->addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, desc->addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_offset = vq->vhost_hlen;
-	desc_avail  = desc->len - vq->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
 
 	*copied = rte_pktmbuf_pkt_len(m);
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 		vq->used->ring[used_idx].id = desc_idx;
 		if (unlikely(err))
-			vq->used->ring[used_idx].len = vq->vhost_hlen;
+			vq->used->ring[used_idx].len = dev->vhost_hlen;
 		else
-			vq->used->ring[used_idx].len = copied + vq->vhost_hlen;
+			vq->used->ring[used_idx].len = copied + dev->vhost_hlen;
 		vhost_log_used_vring(dev, vq,
 			offsetof(struct vring_used, ring[used_idx]),
 			sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
+	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		dev->vid, virtio_hdr.num_buffers);
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
-	copy_virtio_net_hdr(vq, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen);
-	PRINT_PACKET(dev, (uintptr_t)desc_addr, vq->vhost_hlen, 0);
+	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
+	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
 	mbuf_offset = 0;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		return 0;
 
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
-		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen;
+		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
 		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
 							 &start, &end) < 0)) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	uint32_t nr_desc = 1;
 
 	desc = &vq->desc[desc_idx];
-	if (unlikely(desc->len < vq->vhost_hlen))
+	if (unlikely(desc->len < dev->vhost_hlen))
 		return -1;
 
 	desc_addr = gpa_to_vva(dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	/* Retrieve virtio net header */
 	hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
-	desc_avail  = desc->len - vq->vhost_hlen;
-	desc_offset = vq->vhost_hlen;
+	desc_avail  = desc->len - dev->vhost_hlen;
+	desc_offset = dev->vhost_hlen;
 
 	mbuf_offset = 0;
 	mbuf_avail  = m->buf_len - RTE_PKTMBUF_HEADROOM;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 13dc021..835ab3a 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -387,8 +387,6 @@ int
 vhost_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
-	uint16_t vhost_hlen;
-	uint16_t i;
 
 	dev = get_device(vid);
 	if (dev == NULL)
@@ -399,9 +397,9 @@ vhost_set_features(int vid, uint64_t *pu)
 	dev->features = *pu;
 	if (dev->features &
 		((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {
-		vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
 	} else {
-		vhost_hlen = sizeof(struct virtio_net_hdr);
+		dev->vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
 	LOG_DEBUG(VHOST_CONFIG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -409,13 +407,6 @@ vhost_set_features(int vid, uint64_t *pu)
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
 		(dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off");
 
-	for (i = 0; i < dev->virt_qp_nb; i++) {
-		uint16_t base_idx = i * VIRTIO_QNUM;
-
-		dev->virtqueue[base_idx + VIRTIO_RXQ]->vhost_hlen = vhost_hlen;
-		dev->virtqueue[base_idx + VIRTIO_TXQ]->vhost_hlen = vhost_hlen;
-	}
-
 	return 0;
 }
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (18 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
@ 2016-06-07  3:52     ` Yuanhan Liu
  2016-06-14 12:00     ` [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
  2016-06-30  7:39     ` Panu Matilainen
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07  3:52 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa, Ilya Maximets, Yuanhan Liu

From: Ilya Maximets <i.maximets@samsung.com>

Array of buf_vector's is just an array for temporary storing information
about available descriptors. It used only locally in virtio_dev_merge_rx()
and there is no reason for that array to be shared.

Fix that by allocating local buf_vec inside virtio_dev_merge_rx().

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
 lib/librte_vhost/vhost-net.h  |  1 -
 lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++-------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 590a039..162ad04 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -87,7 +87,6 @@ struct vhost_virtqueue {
 
 	/* Physical address of used ring, for logging */
 	uint64_t		log_guest_addr;
-	struct buf_vector	buf_vec[BUF_VECTOR_MAX];
 } __rte_cache_aligned;
 
 /* Old kernels have no such macro defined */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index c9cd1c5..96720db 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -335,7 +335,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 static inline int
 fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
-	     uint32_t *allocated, uint32_t *vec_idx)
+	     uint32_t *allocated, uint32_t *vec_idx,
+	     struct buf_vector *buf_vec)
 {
 	uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
 	uint32_t vec_id = *vec_idx;
@@ -346,9 +347,9 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
 			return -1;
 
 		len += vq->desc[idx].len;
-		vq->buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
-		vq->buf_vec[vec_id].buf_len  = vq->desc[idx].len;
-		vq->buf_vec[vec_id].desc_idx = idx;
+		buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
+		buf_vec[vec_id].buf_len  = vq->desc[idx].len;
+		buf_vec[vec_id].desc_idx = idx;
 		vec_id++;
 
 		if ((vq->desc[idx].flags & VRING_DESC_F_NEXT) == 0)
@@ -371,7 +372,8 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
  */
 static inline int
 reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
-			    uint16_t *start, uint16_t *end)
+			    uint16_t *start, uint16_t *end,
+			    struct buf_vector *buf_vec)
 {
 	uint16_t res_start_idx;
 	uint16_t res_cur_idx;
@@ -393,7 +395,7 @@ again:
 			return -1;
 
 		if (unlikely(fill_vec_buf(vq, res_cur_idx, &allocated,
-					  &vec_idx) < 0))
+					  &vec_idx, buf_vec) < 0))
 			return -1;
 
 		res_cur_idx++;
@@ -427,7 +429,7 @@ again:
 static inline uint32_t __attribute__((always_inline))
 copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			    uint16_t res_start_idx, uint16_t res_end_idx,
-			    struct rte_mbuf *m)
+			    struct rte_mbuf *m, struct buf_vector *buf_vec)
 {
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 	uint32_t vec_idx = 0;
@@ -444,10 +446,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
 		dev->vid, cur_idx, res_end_idx);
 
-	if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
+	if (buf_vec[vec_idx].buf_len < dev->vhost_hlen)
 		return -1;
 
-	desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+	desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 	rte_prefetch0((void *)(uintptr_t)desc_addr);
 
 	virtio_hdr.num_buffers = res_end_idx - res_start_idx;
@@ -456,10 +458,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	virtio_enqueue_offload(m, &virtio_hdr.hdr);
 	copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
-	vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+	vhost_log_write(dev, buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
 	PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
 
-	desc_avail  = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+	desc_avail  = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
 	desc_offset = dev->vhost_hlen;
 
 	mbuf_avail  = rte_pktmbuf_data_len(m);
@@ -467,7 +469,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	while (mbuf_avail != 0 || m->next != NULL) {
 		/* done with current desc buf, get the next one */
 		if (desc_avail == 0) {
-			desc_idx = vq->buf_vec[vec_idx].desc_idx;
+			desc_idx = buf_vec[vec_idx].desc_idx;
 
 			if (!(vq->desc[desc_idx].flags & VRING_DESC_F_NEXT)) {
 				/* Update used ring with desc information */
@@ -481,12 +483,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			}
 
 			vec_idx++;
-			desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+			desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
 
 			/* Prefetch buffer address. */
 			rte_prefetch0((void *)(uintptr_t)desc_addr);
 			desc_offset = 0;
-			desc_avail  = vq->buf_vec[vec_idx].buf_len;
+			desc_avail  = buf_vec[vec_idx].buf_len;
 		}
 
 		/* done with current mbuf, get the next one */
@@ -501,7 +503,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		rte_memcpy((void *)((uintptr_t)(desc_addr + desc_offset)),
 			rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
 			cpy_len);
-		vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr + desc_offset,
+		vhost_log_write(dev, buf_vec[vec_idx].buf_addr + desc_offset,
 			cpy_len);
 		PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset),
 			cpy_len, 0);
@@ -513,7 +515,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	}
 
 	used_idx = cur_idx & (vq->size - 1);
-	vq->used->ring[used_idx].id = vq->buf_vec[vec_idx].desc_idx;
+	vq->used->ring[used_idx].id = buf_vec[vec_idx].desc_idx;
 	vq->used->ring[used_idx].len = desc_offset;
 	vhost_log_used_vring(dev, vq,
 		offsetof(struct vring_used, ring[used_idx]),
@@ -529,6 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	struct vhost_virtqueue *vq;
 	uint32_t pkt_idx = 0, nr_used = 0;
 	uint16_t start, end;
+	struct buf_vector buf_vec[BUF_VECTOR_MAX];
 
 	LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
@@ -548,8 +551,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 	for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
 		uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
 
-		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
-							 &start, &end) < 0)) {
+		if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len, &start,
+							 &end, buf_vec) < 0)) {
 			LOG_DEBUG(VHOST_DATA,
 				"(%d) failed to get enough desc from vring\n",
 				dev->vid);
@@ -557,7 +560,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
 		}
 
 		nr_used = copy_mbuf_to_desc_mergeable(dev, vq, start, end,
-						      pkts[pkt_idx]);
+						      pkts[pkt_idx], buf_vec);
 		rte_smp_wmb();
 
 		/*
-- 
1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
@ 2016-06-07 11:42       ` Panu Matilainen
  2016-06-07 12:45         ` Yuanhan Liu
  2016-06-08 21:51       ` Rich Lane
  1 sibling, 1 reply; 76+ messages in thread
From: Panu Matilainen @ 2016-06-07 11:42 UTC (permalink / raw)
  To: Yuanhan Liu, dev
  Cc: huawei.xie, Thomas Monjalon, Traynor Kevin, Rich Lane, Tetsuya Mukawa

On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> Introduce a new API rte_vhost_get_numa_node() to get the numa node
> from which the virtio_net struct is allocated.
>
> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Tested-by: Rich Lane <rich.lane@bigswitch.com>
> Acked-by: Rich Lane <rich.lane@bigswitch.com>
> ---
>  drivers/net/vhost/rte_eth_vhost.c      | 13 ++++---------
>  lib/librte_vhost/rte_vhost_version.map |  7 +++++++
>  lib/librte_vhost/rte_virtio_net.h      | 12 ++++++++++++
>  lib/librte_vhost/virtio-net.c          | 26 ++++++++++++++++++++++++++
>  4 files changed, 49 insertions(+), 9 deletions(-)
>
[...]
> diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
> index 3d8709e..bf7b000 100644
> --- a/lib/librte_vhost/rte_vhost_version.map
> +++ b/lib/librte_vhost/rte_vhost_version.map
> @@ -20,3 +20,10 @@ DPDK_2.1 {
>  	rte_vhost_driver_unregister;
>
>  } DPDK_2.0;
> +
> +DPDK_16.07 {
> +	global:
> +
> +	rte_vhost_get_numa_node;
> +
> +} DPDK_16.04;

This fails to compile in shared library configuration:

LD librte_vhost.so.3.1
/usr/bin/ld: unable to find version dependency `DPDK_16.04'
collect2: error: ld returned 1 exit status

Problem obviously being that DPDK_16.04 does not exist, the most recent 
version symbol for librte_vhost is DPDK_2.1 so you need to inherit from 
that instead.

	- Panu -

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-07 11:42       ` Panu Matilainen
@ 2016-06-07 12:45         ` Yuanhan Liu
  0 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-07 12:45 UTC (permalink / raw)
  To: Panu Matilainen
  Cc: dev, huawei.xie, Thomas Monjalon, Traynor Kevin, Rich Lane,
	Tetsuya Mukawa

On Tue, Jun 07, 2016 at 02:42:58PM +0300, Panu Matilainen wrote:
> On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> >Introduce a new API rte_vhost_get_numa_node() to get the numa node
> >from which the virtio_net struct is allocated.
> >
> >Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> >Tested-by: Rich Lane <rich.lane@bigswitch.com>
> >Acked-by: Rich Lane <rich.lane@bigswitch.com>
> >---
> > drivers/net/vhost/rte_eth_vhost.c      | 13 ++++---------
> > lib/librte_vhost/rte_vhost_version.map |  7 +++++++
> > lib/librte_vhost/rte_virtio_net.h      | 12 ++++++++++++
> > lib/librte_vhost/virtio-net.c          | 26 ++++++++++++++++++++++++++
> > 4 files changed, 49 insertions(+), 9 deletions(-)
> >
> [...]
> >diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
> >index 3d8709e..bf7b000 100644
> >--- a/lib/librte_vhost/rte_vhost_version.map
> >+++ b/lib/librte_vhost/rte_vhost_version.map
> >@@ -20,3 +20,10 @@ DPDK_2.1 {
> > 	rte_vhost_driver_unregister;
> >
> > } DPDK_2.0;
> >+
> >+DPDK_16.07 {
> >+	global:
> >+
> >+	rte_vhost_get_numa_node;
> >+
> >+} DPDK_16.04;
> 
> This fails to compile in shared library configuration:
> 
> LD librte_vhost.so.3.1
> /usr/bin/ld: unable to find version dependency `DPDK_16.04'
> collect2: error: ld returned 1 exit status
> 
> Problem obviously being that DPDK_16.04 does not exist, the most recent
> version symbol for librte_vhost is DPDK_2.1 so you need to inherit from that
> instead.

Panu, thanks for the catching, and will fix it.

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
  2016-06-07 11:42       ` Panu Matilainen
@ 2016-06-08 21:51       ` Rich Lane
  2016-06-09  4:45         ` Yuanhan Liu
  1 sibling, 1 reply; 76+ messages in thread
From: Rich Lane @ 2016-06-08 21:51 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Tetsuya Mukawa

On Mon, Jun 6, 2016 at 8:51 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
wrote:
>
> @@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
>         internal = eth_dev->data->dev_private;
>
>  #ifdef RTE_LIBRTE_VHOST_NUMA
> -       ret  = get_mempolicy(&newnode, NULL, 0, dev,
> -                       MPOL_F_NODE | MPOL_F_ADDR);
> -       if (ret < 0) {
> -               RTE_LOG(ERR, PMD, "Unknown numa node\n");
> -               return -1;
> -       }
> -
> -       eth_dev->data->numa_node = newnode;
> +       newnode = rte_vhost_get_numa_node(dev->vid);
> +       if (newnode > 0)
>

Should be "newnode >= 0".

+               eth_dev->data->numa_node = newnode;
>  #endif
>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-08 21:51       ` Rich Lane
@ 2016-06-09  4:45         ` Yuanhan Liu
  2016-06-13 10:05           ` Yuanhan Liu
  0 siblings, 1 reply; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-09  4:45 UTC (permalink / raw)
  To: Rich Lane
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Tetsuya Mukawa

On Wed, Jun 08, 2016 at 02:51:33PM -0700, Rich Lane wrote:
> On Mon, Jun 6, 2016 at 8:51 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
> wrote:
> 
>     @@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
>             internal = eth_dev->data->dev_private;
> 
>      #ifdef RTE_LIBRTE_VHOST_NUMA
>     -       ret  = get_mempolicy(&newnode, NULL, 0, dev,
>     -                       MPOL_F_NODE | MPOL_F_ADDR);
>     -       if (ret < 0) {
>     -               RTE_LOG(ERR, PMD, "Unknown numa node\n");
>     -               return -1;
>     -       }
>     -
>     -       eth_dev->data->numa_node = newnode;
>     +       newnode = rte_vhost_get_numa_node(dev->vid);
>     +       if (newnode > 0)
> 
> 
> Should be "newnode >= 0". 

Nice catch! Thanks.

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node
  2016-06-09  4:45         ` Yuanhan Liu
@ 2016-06-13 10:05           ` Yuanhan Liu
  0 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-13 10:05 UTC (permalink / raw)
  To: Rich Lane
  Cc: dev, huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Tetsuya Mukawa

On Thu, Jun 09, 2016 at 12:45:00PM +0800, Yuanhan Liu wrote:
> On Wed, Jun 08, 2016 at 02:51:33PM -0700, Rich Lane wrote:
> > On Mon, Jun 6, 2016 at 8:51 PM, Yuanhan Liu <yuanhan.liu@linux.intel.com>
> > wrote:
> > 
> >     @@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
> >             internal = eth_dev->data->dev_private;
> > 
> >      #ifdef RTE_LIBRTE_VHOST_NUMA
> >     -       ret  = get_mempolicy(&newnode, NULL, 0, dev,
> >     -                       MPOL_F_NODE | MPOL_F_ADDR);
> >     -       if (ret < 0) {
> >     -               RTE_LOG(ERR, PMD, "Unknown numa node\n");
> >     -               return -1;
> >     -       }
> >     -
> >     -       eth_dev->data->numa_node = newnode;
> >     +       newnode = rte_vhost_get_numa_node(dev->vid);
> >     +       if (newnode > 0)
> > 
> > 
> > Should be "newnode >= 0". 
> 
> Nice catch! Thanks.

Here is the update patch that includes the fix of two issues reported by
Rich and Panu.

And if there is no objection, I'd like to apply this series plus some
other series on virtio/vhost from mine in one or two days: it's close
to the RC1 deadline now.

	--yliu

---
>From f378af61f6ba7dcfcd20ab180fba166619ea3d88 Mon Sep 17 00:00:00 2001
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Date: Wed, 11 May 2016 06:12:57 +0800
Subject: [PATCH] vhost: introduce new API to export numa node

Introduce a new API rte_vhost_get_numa_node() to get the numa node
from which the virtio_net struct is allocated.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---

v4: - fix build error in shared configuration reported by Panu
    - fix numa node check reported by Rich
---
 drivers/net/vhost/rte_eth_vhost.c      | 13 ++++---------
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/rte_virtio_net.h      | 12 ++++++++++++
 lib/librte_vhost/virtio-net.c          | 26 ++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 63538c1..a00351b 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -230,7 +230,7 @@ new_device(struct virtio_net *dev)
 	struct vhost_queue *vq;
 	unsigned i;
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	int newnode, ret;
+	int newnode;
 #endif
 
 	if (dev == NULL) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev)
 	internal = eth_dev->data->dev_private;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	ret  = get_mempolicy(&newnode, NULL, 0, dev,
-			MPOL_F_NODE | MPOL_F_ADDR);
-	if (ret < 0) {
-		RTE_LOG(ERR, PMD, "Unknown numa node\n");
-		return -1;
-	}
-
-	eth_dev->data->numa_node = newnode;
+	newnode = rte_vhost_get_numa_node(dev->vid);
+	if (newnode >= 0)
+		eth_dev->data->numa_node = newnode;
 #endif
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 3d8709e..a323fa0 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -20,3 +20,10 @@ DPDK_2.1 {
 	rte_vhost_driver_unregister;
 
 } DPDK_2.0;
+
+DPDK_16.07 {
+	global:
+
+	rte_vhost_get_numa_node;
+
+} DPDK_2.1;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index bc64e89..b8e9b02 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get the numa node from which the virtio net device's memory
+ * is allocated.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The numa node, -1 on failure
+ */
+int rte_vhost_get_numa_node(int vid);
+
+/**
  * 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 c6d3829..25b6515 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)
 	return 0;
 }
 
+int
+rte_vhost_get_numa_node(int vid)
+{
+#ifdef RTE_LIBRTE_VHOST_NUMA
+	struct virtio_net *dev = get_device(vid);
+	int numa_node;
+	int ret;
+
+	if (dev == NULL)
+		return -1;
+
+	ret = get_mempolicy(&numa_node, NULL, 0, dev,
+			    MPOL_F_NODE | MPOL_F_ADDR);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%d) failed to query numa node: %d\n", vid, ret);
+		return -1;
+	}
+
+	return numa_node;
+#else
+	RTE_SET_USED(vid);
+	return -1;
+#endif
+}
+
 int rte_vhost_enable_guest_notification(struct virtio_net *dev,
 	uint16_t queue_id, int enable)
 {
-- 
1.9.3

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (19 preceding siblings ...)
  2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local Yuanhan Liu
@ 2016-06-14 12:00     ` Yuanhan Liu
  2016-06-30  7:39     ` Panu Matilainen
  21 siblings, 0 replies; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-14 12:00 UTC (permalink / raw)
  To: dev
  Cc: huawei.xie, Thomas Monjalon, Panu Matilainen, Traynor Kevin,
	Rich Lane, Tetsuya Mukawa

Applied to dpdk-next-virtio.

	--yliu

On Tue, Jun 07, 2016 at 11:51:50AM +0800, Yuanhan Liu wrote:
> v3: - adapted the new vhost ABI/API changes to tep_term example, to make
>       sure not break build at least.
>     - bumped the ABI version to 3
> 
> NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
> 
>     [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
> 
> 
> Every time we introduce a new feature to vhost, we are likely to break
> ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf
> from vhost_virtqueue struct) also break ABI.
> 
> This patch set is meant to resolve above issue ultimately, by hiding
> virtio_net structure (as well as few others) internaly, and export the
> virtio_net dev strut to applications by a number, vid, like the way
> kernel exposes an fd to user space.
> 
> Back to the patch set, the first part of this set makes some changes to
> vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence
> to "virtio_net" struct. And then do the final change to make the current
> APIs to adapt to using "vid".
> 
> After that, "vrtio_net_device_ops" is the only left open struct that an
> application can acces, therefore, it's the only place that might introduce
> potential ABI breakage in future for extension. Hence, I made few more
> (5) space reservation, to make sure we will not break ABI for a long time,
> and hopefuly, forever.
> 
> The last bit of this patch set is some cleanups, including the one from
> Ilya.
> 
> v2: - exported ifname as well to fix a vhost-pmd issue reported by Rich
>     - separated the big patch that introduces several new APIs into some
>       small patches.
>     - updated release note
>     - updated version.map
> 
> Thanks.
> 
> 	--yliu
> 
> ---
> Ilya Maximets (1):
>   vhost: make buf vector for scatter Rx local
> 
> Yuanhan Liu (19):
>   vhost: declare backend with int type
>   vhost: set/reset dev flags internally
>   vhost: declare device fh as int
>   examples/vhost: make a copy of virtio device id
>   vhost: rename device fh to vid
>   vhost: get device by vid only
>   vhost: move vhost device ctx to cuse
>   vhost: introduce new API to export numa node
>   vhost: introduce new API to export number of queues
>   vhost: introduce new API to export ifname
>   vhost: introduce new API to export queue free entries
>   vhost: remove dependency on priv field
>   vhost: export vid as the only interface to applications
>   vhost: hide internal structs/macros/functions
>   vhost: remove unnecessary fields
>   vhost: remove virtio-net.h
>   vhost: reserve few more space for future extension
>   examples/tep_term: adapt to new vhost ABI/API changes
>   vhost: per device virtio net header len
> 
>  doc/guides/rel_notes/release_16_07.rst        |  11 +-
>  drivers/net/vhost/rte_eth_vhost.c             |  79 ++++-----
>  examples/tep_termination/main.c               |  83 +++++-----
>  examples/tep_termination/main.h               |   5 +-
>  examples/tep_termination/vxlan_setup.c        |  20 +--
>  examples/tep_termination/vxlan_setup.h        |   6 +-
>  examples/vhost/main.c                         | 116 +++++++------
>  examples/vhost/main.h                         |   3 +-
>  lib/librte_vhost/Makefile                     |   2 +-
>  lib/librte_vhost/rte_vhost_version.map        |  10 ++
>  lib/librte_vhost/rte_virtio_net.h             | 223 +++++++------------------
>  lib/librte_vhost/vhost-net.h                  | 201 ++++++++++++++++++----
>  lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  |  83 +++++-----
>  lib/librte_vhost/vhost_cuse/virtio-net-cdev.c |  30 ++--
>  lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  12 +-
>  lib/librte_vhost/vhost_rxtx.c                 | 133 ++++++++-------
>  lib/librte_vhost/vhost_user/vhost-net-user.c  |  53 +++---
>  lib/librte_vhost/vhost_user/vhost-net-user.h  |   2 +
>  lib/librte_vhost/vhost_user/virtio-net-user.c |  64 +++----
>  lib/librte_vhost/vhost_user/virtio-net-user.h |  18 +-
>  lib/librte_vhost/virtio-net.c                 | 229 +++++++++++++++++---------
>  lib/librte_vhost/virtio-net.h                 |  43 -----
>  22 files changed, 752 insertions(+), 674 deletions(-)
>  delete mode 100644 lib/librte_vhost/virtio-net.h
> 
> -- 
> 1.9.0

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
                       ` (20 preceding siblings ...)
  2016-06-14 12:00     ` [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
@ 2016-06-30  7:39     ` Panu Matilainen
  2016-06-30  7:57       ` Yuanhan Liu
  21 siblings, 1 reply; 76+ messages in thread
From: Panu Matilainen @ 2016-06-30  7:39 UTC (permalink / raw)
  To: Yuanhan Liu, dev
  Cc: huawei.xie, Thomas Monjalon, Traynor Kevin, Rich Lane, Tetsuya Mukawa

On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> v3: - adapted the new vhost ABI/API changes to tep_term example, to make
>       sure not break build at least.
>     - bumped the ABI version to 3
>
> NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
>
>     [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
>
>
> Every time we introduce a new feature to vhost, we are likely to break
> ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf
> from vhost_virtqueue struct) also break ABI.
>
> This patch set is meant to resolve above issue ultimately, by hiding
> virtio_net structure (as well as few others) internaly, and export the
> virtio_net dev strut to applications by a number, vid, like the way
> kernel exposes an fd to user space.
>
> Back to the patch set, the first part of this set makes some changes to
> vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence
> to "virtio_net" struct. And then do the final change to make the current
> APIs to adapt to using "vid".
>
> After that, "vrtio_net_device_ops" is the only left open struct that an
> application can acces, therefore, it's the only place that might introduce
> potential ABI breakage in future for extension. Hence, I made few more
> (5) space reservation, to make sure we will not break ABI for a long time,
> and hopefuly, forever.

Been intending to say this for a while but seems I never actually got 
around to do so:

This is a really fine example of how to refactor an API against constant 
ABI breakages, thank you Yuanhan! Exported structs are one of the 
biggest obstacles in keeping a stable ABI while adding new features, and 
while its not always possible to hide everything to this extent, the 
damage (erm, exposure) can usually be considerably limited by careful 
API design.

Since the first and the foremost objection against doing this in the 
DPDK context is always "but performance!", I'm curious as to what sort 
of numbers you're getting with the new API vs the old one? I'm really 
hoping other libraries would follow suit after seeing that its possible 
to provide a future-proof API/ABI without sacrificing performance :)

Thanks again,

	- Panu -

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-30  7:39     ` Panu Matilainen
@ 2016-06-30  7:57       ` Yuanhan Liu
  2016-06-30  9:05         ` Panu Matilainen
  0 siblings, 1 reply; 76+ messages in thread
From: Yuanhan Liu @ 2016-06-30  7:57 UTC (permalink / raw)
  To: Panu Matilainen
  Cc: dev, huawei.xie, Thomas Monjalon, Rich Lane, Tetsuya Mukawa

On Thu, Jun 30, 2016 at 10:39:45AM +0300, Panu Matilainen wrote:
> On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> >v3: - adapted the new vhost ABI/API changes to tep_term example, to make
> >      sure not break build at least.
> >    - bumped the ABI version to 3
> >
> >NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
> >
> >    [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
> >
> >
> >Every time we introduce a new feature to vhost, we are likely to break
> >ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf
> >from vhost_virtqueue struct) also break ABI.
> >
> >This patch set is meant to resolve above issue ultimately, by hiding
> >virtio_net structure (as well as few others) internaly, and export the
> >virtio_net dev strut to applications by a number, vid, like the way
> >kernel exposes an fd to user space.
> >
> >Back to the patch set, the first part of this set makes some changes to
> >vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence
> >to "virtio_net" struct. And then do the final change to make the current
> >APIs to adapt to using "vid".
> >
> >After that, "vrtio_net_device_ops" is the only left open struct that an
> >application can acces, therefore, it's the only place that might introduce
> >potential ABI breakage in future for extension. Hence, I made few more
> >(5) space reservation, to make sure we will not break ABI for a long time,
> >and hopefuly, forever.
> 
> Been intending to say this for a while but seems I never actually got around
> to do so:
> 
> This is a really fine example of how to refactor an API against constant ABI
> breakages, thank you Yuanhan!

Panu, thanks!

> Exported structs are one of the biggest
> obstacles in keeping a stable ABI while adding new features, and while its
> not always possible to hide everything to this extent, the damage (erm,
> exposure) can usually be considerably limited by careful API design.

Agreed.

> Since the first and the foremost objection against doing this in the DPDK
> context is always "but performance!", I'm curious as to what sort of numbers
> you're getting with the new API vs the old one? I'm really hoping other
> libraries would follow suit after seeing that its possible to provide a
> future-proof API/ABI without sacrificing performance :)

>From my (limited) test, nope, I see no performance drop at all, not even a
little.

	--yliu

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-30  7:57       ` Yuanhan Liu
@ 2016-06-30  9:05         ` Panu Matilainen
  2016-06-30 11:15           ` Mcnamara, John
  0 siblings, 1 reply; 76+ messages in thread
From: Panu Matilainen @ 2016-06-30  9:05 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, huawei.xie, Thomas Monjalon, Rich Lane, Tetsuya Mukawa

On 06/30/2016 10:57 AM, Yuanhan Liu wrote:
> On Thu, Jun 30, 2016 at 10:39:45AM +0300, Panu Matilainen wrote:
>> On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
>>> v3: - adapted the new vhost ABI/API changes to tep_term example, to make
>>>      sure not break build at least.
>>>    - bumped the ABI version to 3
>>>
>>> NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
>>>
>>>    [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
>>>
>>>
>>> Every time we introduce a new feature to vhost, we are likely to break
>>> ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf
>> >from vhost_virtqueue struct) also break ABI.
>>>
>>> This patch set is meant to resolve above issue ultimately, by hiding
>>> virtio_net structure (as well as few others) internaly, and export the
>>> virtio_net dev strut to applications by a number, vid, like the way
>>> kernel exposes an fd to user space.
>>>
>>> Back to the patch set, the first part of this set makes some changes to
>>> vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence
>>> to "virtio_net" struct. And then do the final change to make the current
>>> APIs to adapt to using "vid".
>>>
>>> After that, "vrtio_net_device_ops" is the only left open struct that an
>>> application can acces, therefore, it's the only place that might introduce
>>> potential ABI breakage in future for extension. Hence, I made few more
>>> (5) space reservation, to make sure we will not break ABI for a long time,
>>> and hopefuly, forever.
>>
>> Been intending to say this for a while but seems I never actually got around
>> to do so:
>>
>> This is a really fine example of how to refactor an API against constant ABI
>> breakages, thank you Yuanhan!
>
> Panu, thanks!
>
>> Exported structs are one of the biggest
>> obstacles in keeping a stable ABI while adding new features, and while its
>> not always possible to hide everything to this extent, the damage (erm,
>> exposure) can usually be considerably limited by careful API design.
>
> Agreed.
>
>> Since the first and the foremost objection against doing this in the DPDK
>> context is always "but performance!", I'm curious as to what sort of numbers
>> you're getting with the new API vs the old one? I'm really hoping other
>> libraries would follow suit after seeing that its possible to provide a
>> future-proof API/ABI without sacrificing performance :)
>
> From my (limited) test, nope, I see no performance drop at all, not even a
> little.

Awesome!

With that, hopefully others will see the light and follow its example. 
If nothing else, they ought to get a bit envious when you can add 
features left and right without ever having to wait for API/ABI break 
periods etc ;)

	- Panu -

>
> 	--yliu
>

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-30  9:05         ` Panu Matilainen
@ 2016-06-30 11:15           ` Mcnamara, John
  2016-06-30 11:40             ` Thomas Monjalon
  0 siblings, 1 reply; 76+ messages in thread
From: Mcnamara, John @ 2016-06-30 11:15 UTC (permalink / raw)
  To: Panu Matilainen, Yuanhan Liu
  Cc: dev, Xie, Huawei, Thomas Monjalon, Rich Lane, Tetsuya Mukawa



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Panu Matilainen
> Sent: Thursday, June 30, 2016 10:05 AM
> To: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Cc: dev@dpdk.org; Xie, Huawei <huawei.xie@intel.com>; Thomas Monjalon
> <thomas.monjalon@6wind.com>; Rich Lane <rich.lane@bigswitch.com>; Tetsuya
> Mukawa <mukawa@igel.co.jp>
> Subject: Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
> 
> On 06/30/2016 10:57 AM, Yuanhan Liu wrote:
> > On Thu, Jun 30, 2016 at 10:39:45AM +0300, Panu Matilainen wrote:
> >> On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> >>> v3: - adapted the new vhost ABI/API changes to tep_term example, to
> make
> >>>      sure not break build at least.
> >>>    - bumped the ABI version to 3
> >>>
> >>> NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
> >>>
> >>>    [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
> >>>
> >>>
> >>> Every time we introduce a new feature to vhost, we are likely to
> >>> break ABI. Moreover, some cleanups (such as the one from Ilya to
> >>> remove vec_buf
> >> >from vhost_virtqueue struct) also break ABI.
> >>>
> >>> This patch set is meant to resolve above issue ultimately, by hiding
> >>> virtio_net structure (as well as few others) internaly, and export
> >>> the virtio_net dev strut to applications by a number, vid, like the
> >>> way kernel exposes an fd to user space.
> >>>
> >>> Back to the patch set, the first part of this set makes some changes
> >>> to vhost example, vhost-pmd and vhost, bit by bit, to remove the
> >>> dependence to "virtio_net" struct. And then do the final change to
> >>> make the current APIs to adapt to using "vid".
> >>>
> >>> After that, "vrtio_net_device_ops" is the only left open struct that
> >>> an application can acces, therefore, it's the only place that might
> >>> introduce potential ABI breakage in future for extension. Hence, I
> >>> made few more
> >>> (5) space reservation, to make sure we will not break ABI for a long
> >>> time, and hopefuly, forever.
> >>
> >> Been intending to say this for a while but seems I never actually got
> >> around to do so:
> >>
> >> This is a really fine example of how to refactor an API against
> >> constant ABI breakages, thank you Yuanhan!
> >
> > Panu, thanks!
> >
> >> Exported structs are one of the biggest obstacles in keeping a stable
> >> ABI while adding new features, and while its not always possible to
> >> hide everything to this extent, the damage (erm,
> >> exposure) can usually be considerably limited by careful API design.
> >
> > Agreed.
> >
> >> Since the first and the foremost objection against doing this in the
> >> DPDK context is always "but performance!", I'm curious as to what
> >> sort of numbers you're getting with the new API vs the old one? I'm
> >> really hoping other libraries would follow suit after seeing that its
> >> possible to provide a future-proof API/ABI without sacrificing
> >> performance :)
> >
> > From my (limited) test, nope, I see no performance drop at all, not
> > even a little.
> 
> Awesome!
> 
> With that, hopefully others will see the light and follow its example.
> If nothing else, they ought to get a bit envious when you can add features
> left and right without ever having to wait for API/ABI break periods etc
> ;)

Agreed. We should be doing more of this type of refactoring work to make the API/ABI less easier to break.

John

^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring
  2016-06-30 11:15           ` Mcnamara, John
@ 2016-06-30 11:40             ` Thomas Monjalon
  0 siblings, 0 replies; 76+ messages in thread
From: Thomas Monjalon @ 2016-06-30 11:40 UTC (permalink / raw)
  To: Mcnamara, John
  Cc: Panu Matilainen, Yuanhan Liu, dev, Xie, Huawei, Rich Lane,
	Tetsuya Mukawa

2016-06-30 11:15, Mcnamara, John:
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Panu Matilainen
> > On 06/30/2016 10:57 AM, Yuanhan Liu wrote:
> > > On Thu, Jun 30, 2016 at 10:39:45AM +0300, Panu Matilainen wrote:
> > >> On 06/07/2016 06:51 AM, Yuanhan Liu wrote:
> > >>> v3: - adapted the new vhost ABI/API changes to tep_term example, to
> > make
> > >>>      sure not break build at least.
> > >>>    - bumped the ABI version to 3
> > >>>
> > >>> NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
> > >>>
> > >>>    [0]: git://dpdk.org/next/dpdk-next-virtio for-testing
> > >>>
> > >>>
> > >>> Every time we introduce a new feature to vhost, we are likely to
> > >>> break ABI. Moreover, some cleanups (such as the one from Ilya to
> > >>> remove vec_buf
> > >> >from vhost_virtqueue struct) also break ABI.
> > >>>
> > >>> This patch set is meant to resolve above issue ultimately, by hiding
> > >>> virtio_net structure (as well as few others) internaly, and export
> > >>> the virtio_net dev strut to applications by a number, vid, like the
> > >>> way kernel exposes an fd to user space.
> > >>>
> > >>> Back to the patch set, the first part of this set makes some changes
> > >>> to vhost example, vhost-pmd and vhost, bit by bit, to remove the
> > >>> dependence to "virtio_net" struct. And then do the final change to
> > >>> make the current APIs to adapt to using "vid".
> > >>>
> > >>> After that, "vrtio_net_device_ops" is the only left open struct that
> > >>> an application can acces, therefore, it's the only place that might
> > >>> introduce potential ABI breakage in future for extension. Hence, I
> > >>> made few more
> > >>> (5) space reservation, to make sure we will not break ABI for a long
> > >>> time, and hopefuly, forever.
> > >>
> > >> Been intending to say this for a while but seems I never actually got
> > >> around to do so:
> > >>
> > >> This is a really fine example of how to refactor an API against
> > >> constant ABI breakages, thank you Yuanhan!
> > >
> > > Panu, thanks!
> > >
> > >> Exported structs are one of the biggest obstacles in keeping a stable
> > >> ABI while adding new features, and while its not always possible to
> > >> hide everything to this extent, the damage (erm,
> > >> exposure) can usually be considerably limited by careful API design.
> > >
> > > Agreed.
> > >
> > >> Since the first and the foremost objection against doing this in the
> > >> DPDK context is always "but performance!", I'm curious as to what
> > >> sort of numbers you're getting with the new API vs the old one? I'm
> > >> really hoping other libraries would follow suit after seeing that its
> > >> possible to provide a future-proof API/ABI without sacrificing
> > >> performance :)
> > >
> > > From my (limited) test, nope, I see no performance drop at all, not
> > > even a little.
> > 
> > Awesome!
> > 
> > With that, hopefully others will see the light and follow its example.
> > If nothing else, they ought to get a bit envious when you can add features
> > left and right without ever having to wait for API/ABI break periods etc
> > ;)
> 
> Agreed. We should be doing more of this type of refactoring work to make the API/ABI less easier to break.

+1
But we must check the possible performance degradation with care :)

^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2016-06-30 11:40 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 09/16] vhost: add few more functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-10 16:17   ` Rich Lane
2016-05-10 16:39     ` Yuanhan Liu
2016-05-10 17:13       ` Rich Lane
2016-05-10 17:29         ` Yuanhan Liu
2016-05-10 19:22           ` Thomas Monjalon
2016-05-02 22:25 ` [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-13  5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
2016-05-13  5:24   ` [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
2016-05-13  5:25   ` [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-26 17:04   ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
2016-05-27  1:36     ` Yuanhan Liu
2016-06-07  3:51   ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
2016-06-07 11:42       ` Panu Matilainen
2016-06-07 12:45         ` Yuanhan Liu
2016-06-08 21:51       ` Rich Lane
2016-06-09  4:45         ` Yuanhan Liu
2016-06-13 10:05           ` Yuanhan Liu
2016-06-07  3:51     ` [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
2016-06-07  3:52     ` [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-06-14 12:00     ` [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
2016-06-30  7:39     ` Panu Matilainen
2016-06-30  7:57       ` Yuanhan Liu
2016-06-30  9:05         ` Panu Matilainen
2016-06-30 11:15           ` Mcnamara, John
2016-06-30 11:40             ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).