vhost: export interface name

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>
This commit is contained in:
Yuanhan Liu 2016-05-11 06:38:44 +08:00
parent 4b4af666b9
commit f6d1bd5365
4 changed files with 42 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -267,6 +267,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

View File

@ -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)
{