[PATCH 10/17] vhost: export the number of vrings
From: Yuanhan Liu <hidden>
Date: 2017-03-03 09:52:59
Subsystem:
library code, networking drivers, the rest · Maintainers:
Andrew Morton, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
We used to use rte_vhost_get_queue_num() for telling how many vrings. However, the return value is the number of "queue pairs", which is very virtio-net specific. To make it generic, we should return the number of vrings instead, and let the driver do the proper translation. Say, virtio-net driver could turn it to the number of queue pairs by dividing 2. Meanwhile, mark rte_vhost_get_queue_num as deprecated. Signed-off-by: Yuanhan Liu <redacted> --- drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/vhost.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 816a9a0..135fec1 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c@@ -569,7 +569,7 @@ struct vhost_xstats_name_off { vq->port = eth_dev->data->port_id; } - for (i = 0; i < rte_vhost_get_queue_num(vid) * VIRTIO_QNUM; i++) + for (i = 0; i < rte_vhost_get_vring_num(vid); i++) rte_vhost_enable_guest_notification(vid, i, 0); eth_dev->data->dev_link.link_status = ETH_LINK_UP;
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 24f31ee..8e6290d 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map@@ -38,6 +38,7 @@ DPDK_17.05 { rte_vhost_get_negotiated_features rte_vhost_get_vhost_memory; rte_vhost_get_vhost_vring; + rte_vhost_get_vring_num; rte_vhost_gpa_to_vva; } DPDK_16.07;
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index dbdf004..280d9c2 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h@@ -163,17 +163,34 @@ int rte_vhost_driver_callback_register(const char *path, int rte_vhost_get_numa_node(int vid); /** + * @deprecated * Get the number of queues the device supports. * + * Note this function is deprecated, as it returns a queue pair number, + * which is virtio-net specific. Instead, rte_vhost_get_vring_num should + * be used. + * * @param vid * virtio-net device ID * * @return * The number of queues, 0 on failure */ +__rte_deprecated uint32_t rte_vhost_get_queue_num(int vid); /** + * Get the number of vrings the device supports. + * + * @param vid + * vhost device ID + * + * @return + * The number of vrings, 0 on failure + */ +uint16_t rte_vhost_get_vring_num(int vid); + +/** * Get the virtio net device's ifname, which is the vhost-user socket * file path. *
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 82fb2b7..0a27888 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c@@ -296,6 +296,17 @@ struct virtio_net * return dev->nr_vring / 2; } +uint16_t +rte_vhost_get_vring_num(int vid) +{ + struct virtio_net *dev = get_device(vid); + + if (dev == NULL) + return 0; + + return dev->nr_vring; +} + int rte_vhost_get_ifname(int vid, char *buf, size_t len) {
--
1.9.0