X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_vhost%2Fvhost_cuse%2Fvirtio-net-cdev.c;h=ae2c3faf352f1caac5f8b3cc305158107c8e1188;hb=54292e9520e0141b691579868c6e29a7a0628915;hp=adebb5430f5fd78509d252c1cdb0ae494e2e67a2;hpb=9464a441601e8b2447373ce0dfcc31cc4ae409a5;p=dpdk.git diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c index adebb5430f..ae2c3faf35 100644 --- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c @@ -43,6 +43,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -51,6 +55,7 @@ #include "vhost-net.h" #include "virtio-net-cdev.h" #include "virtio-net.h" +#include "eventfd_copy.h" /* Line size for reading maps file. */ static const uint32_t BUFSIZE = PATH_MAX; @@ -368,3 +373,51 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, return 0; } + +/* + * Function to get the tap device name from the provided file descriptor and + * save it in the device structure. + */ +static int +get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int pid) +{ + int fd_tap; + struct ifreq ifr; + uint32_t ifr_size; + int ret; + + fd_tap = eventfd_copy(tap_fd, pid); + if (fd_tap < 0) + return -1; + + ret = ioctl(fd_tap, TUNGETIFF, &ifr); + + if (close(fd_tap) < 0) + RTE_LOG(ERR, VHOST_CONFIG, + "(%"PRIu64") fd close failed\n", + dev->device_fh); + + if (ret >= 0) { + ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)); + ops->set_ifname(ctx, ifr.ifr_name, ifr_size); + } else + RTE_LOG(ERR, VHOST_CONFIG, + "(%"PRIu64") TUNGETIFF ioctl failed\n", + dev->device_fh); + + return 0; +} + +int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) +{ + struct virtio_net *dev; + + dev = get_device(ctx); + if (dev == NULL) + return -1; + + if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED) + get_ifname(ctx, dev, file->fd, ctx.pid); + + return ops->set_backend(ctx, file); +}