From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 2D7C9CF9 for ; Sun, 25 Jan 2015 09:34:46 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 25 Jan 2015 00:31:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,463,1418112000"; d="scan'208";a="667171305" Received: from pgsmsx103.gar.corp.intel.com ([10.221.44.82]) by fmsmga002.fm.intel.com with ESMTP; 25 Jan 2015 00:34:38 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by PGSMSX103.gar.corp.intel.com (10.221.44.82) with Microsoft SMTP Server (TLS) id 14.3.195.1; Sun, 25 Jan 2015 16:34:37 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.64]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.173]) with mapi id 14.03.0195.001; Sun, 25 Jan 2015 16:34:35 +0800 From: "Xie, Huawei" To: Linhaifeng , "Loftus, Ciara" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2] vhost: add interface name to virtio-net struct Thread-Index: AQHQOFlZi7oy2Ztsn0+N0B+DLWCExJzQgezA Date: Sun, 25 Jan 2015 08:34:35 +0000 Message-ID: References: <1418926027-19794-1-git-send-email-ciara.loftus@intel.com> <54C47415.9020407@huawei.com> In-Reply-To: <54C47415.9020407@huawei.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: Anthony Fee Subject: Re: [dpdk-dev] [PATCH v2] 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: , X-List-Received-Date: Sun, 25 Jan 2015 08:34:47 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Linhaifeng > Sent: Sunday, January 25, 2015 12:42 PM > To: Loftus, Ciara; dev@dpdk.org > Cc: Anthony Fee > Subject: Re: [dpdk-dev] [PATCH v2] vhost: add interface name to virtio-ne= t struct >=20 >=20 >=20 > On 2014/12/19 2:07, ciara.loftus@intel.com wrote: > > 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 >=20 > Who create the tap device?When using vhost-user QEMU will not create it. >=20 > > for the vSwitch to be able to direct packets to the correct device. >=20 > Why not use unix domain socket path? In this patch, for vhost-cuse, the ifname comes from the name of the tap de= vice. For vhost-user, ifname is the name of the socket path. >=20 > > 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 | 3 ++ > > lib/librte_vhost/virtio-net.c | 48 > ++++++++++++++++++++++++++++++++++++- > > 2 files changed, 50 insertions(+), 1 deletions(-) > > > > diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_v= irtio_net.h > > index 00b1328..0bf07c7 100644 > > --- a/lib/librte_vhost/rte_virtio_net.h > > +++ b/lib/librte_vhost/rte_virtio_net.h > > @@ -43,6 +43,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > #include > > #include > > @@ -96,6 +98,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[IFNAMSIZ]; /**< 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-ne= t.c > > index 852b6d1..7eae5ee 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,46 @@ set_vring_kick(struct vhost_device_ctx ctx, stru= ct > vhost_vring_file *file) > > } > > > > /* > > + * Function to get the tap device name from the provided file descript= or 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, ifr_size; > > + int ret; > > + > > + fd_tap.source_fd =3D eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); > > + fd_tap.target_fd =3D tap_fd; > > + fd_tap.target_pid =3D pid; > > + > > + if (eventfd_copy(dev, &fd_tap)) > > + return -1; > > + > > + ret =3D 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); > > + > > + if (ret >=3D 0) { > > + ifr_size =3D strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)); > > + size =3D ifr_size > sizeof(dev->ifname)? > > + sizeof(dev->ifname): ifr_size; > > + > > + strncpy(dev->ifname, ifr.ifr_name, size); > > + } else > > + RTE_LOG(ERR, VHOST_CONFIG, > > + "(%"PRIu64") TUNGETIFF ioctl failed\n", > > + dev->device_fh); > > + > > + 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 +1070,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 !=3D > VIRTIO_DEV_STOPPED) && > > - ((int)dev->virtqueue[VIRTIO_RXQ]->backend !=3D > VIRTIO_DEV_STOPPED)) > > + ((int)dev->virtqueue[VIRTIO_RXQ]->backend !=3D > VIRTIO_DEV_STOPPED)) { > > + get_ifname(dev, file->fd, ctx.pid); > > return notify_ops->new_device(dev); > > + } > > /* Otherwise we remove it. */ > > } else > > if (file->fd =3D=3D VIRTIO_DEV_STOPPED) > > >=20 > -- > Regards, > Haifeng