From patchwork Thu Dec 18 14:55:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Loftus, Ciara" X-Patchwork-Id: 2096 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 1FC2B8045; Thu, 18 Dec 2014 15:58:16 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id F20FB803F for ; Thu, 18 Dec 2014 15:58:12 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 18 Dec 2014 06:54:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="500959448" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 18 Dec 2014 06:51:42 -0800 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id sBIEu1ZK001458; Thu, 18 Dec 2014 14:56:01 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id sBIEu1w9024777; Thu, 18 Dec 2014 14:56:01 GMT Received: (from cloftus@localhost) by sivswdev01.ir.intel.com with id sBIEu1tr024773; Thu, 18 Dec 2014 14:56:01 GMT From: ciara.loftus@intel.com To: dev@dpdk.org Date: Thu, 18 Dec 2014 14:55:23 +0000 Message-Id: <1418914523-24530-1-git-send-email-ciara.loftus@intel.com> X-Mailer: git-send-email 1.7.4.1 Cc: Anthony Fee Subject: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ciara Loftus This patch fixes the issue whereby when using userspace vhost ports in the context of vSwitching, the name provided to the hypervisor/QEMU of the vhost tap device needs to be exposed in the library, in order for the vSwitch to be able to direct packets to the correct device. This patch introduces an 'ifname' member to the virtio-net structure which is populated with the tap device name when QEMU is brought up with a vhost device. Signed-off-by: Ciara Loftus Signed-off-by: Anthony Fee Acked-by: Huawei Xie --- lib/librte_vhost/rte_virtio_net.h | 1 + lib/librte_vhost/virtio-net.c | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletions(-) diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 00b1328..aebb4b5 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -96,6 +96,7 @@ struct virtio_net { uint64_t features; /**< Negotiated feature set. */ uint64_t device_fh; /**< device identifier. */ uint32_t flags; /**< Device flags. Only used to check if device is running on data core. */ + char ifname[32]; /** Name of the tap device **/ void *priv; /**< private context */ } __rte_cache_aligned; diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 852b6d1..7f90ecf 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -43,6 +43,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -1000,6 +1004,39 @@ set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file) } /* + * Function to get the tap device name from the provided file descriptor and + * save it in the device structure. + */ +static int +get_ifname(struct virtio_net *dev, int tap_fd, int pid) +{ + struct eventfd_copy fd_tap; + struct ifreq ifr; + uint32_t size; + + fd_tap.source_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + fd_tap.target_fd = tap_fd; + fd_tap.target_pid = pid; + + if (eventfd_copy(dev, &fd_tap)) + return -1; + + ioctl(fd_tap.source_fd, TUNGETIFF, &ifr); + + if (close(fd_tap.source_fd) < 0) + RTE_LOG(ERR, VHOST_CONFIG, + "(%"PRIu64") fd close failed\n", + dev->device_fh); + + size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) > sizeof(dev->ifname)? + sizeof(dev->ifname): strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)); + + strncpy(dev->ifname, ifr.ifr_name, size); + + return 0; +} + +/* * Called from CUSE IOCTL: VHOST_NET_SET_BACKEND * To complete device initialisation when the virtio driver is loaded, * we are provided with a valid fd for a tap device (not used by us). @@ -1026,8 +1063,10 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) */ 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)) + ((int)dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED)) { + get_ifname(dev, file->fd, ctx.pid); return notify_ops->new_device(dev); + } /* Otherwise we remove it. */ } else if (file->fd == VIRTIO_DEV_STOPPED)