From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id B93862A1A for ; Thu, 18 Dec 2014 19:20:22 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 18 Dec 2014 10:11:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,602,1413270000"; d="scan'208";a="626125938" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by orsmga001.jf.intel.com with ESMTP; 18 Dec 2014 10:11:45 -0800 Received: from irsmsx106.ger.corp.intel.com ([169.254.8.18]) by IRSMSX153.ger.corp.intel.com ([163.33.192.75]) with mapi id 14.03.0195.001; Thu, 18 Dec 2014 18:11:45 +0000 From: "Loftus, Ciara" To: "Ananyev, Konstantin" Thread-Topic: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct Thread-Index: AQHQGtLEcjdlFXE5jESNg2FD7ncNQpyVk1MAgAASVTA= Date: Thu, 18 Dec 2014 18:11:43 +0000 Message-ID: <74F120C019F4A64C9B78E802F6AD4CC212579086@IRSMSX106.ger.corp.intel.com> References: <1418914523-24530-1-git-send-email-ciara.loftus@intel.com> <2601191342CEEE43887BDE71AB977258213C1FDC@IRSMSX105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258213C1FDC@IRSMSX105.ger.corp.intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Cc: "dev@dpdk.org" Subject: Re: [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: , X-List-Received-Date: Thu, 18 Dec 2014 18:20:23 -0000 Hi Konstantin, Thank you for the feedback. = As regards the following: "So if sizeof(ifr.ifr_name) > sizeof(dev->ifname) then we can endup with de= v->ifname not being null-termianted?" This should never be the case as now both dev->ifname and ifr.ifr_name are = of size IFNAMSIZ in v2 of the patch. Thanks, Ciara -----Original Message----- From: Ananyev, Konstantin = Sent: Thursday, December 18, 2014 5:03 PM To: Loftus, Ciara; dev@dpdk.org Cc: Anthony Fee Subject: RE: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net str= uct > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of = > ciara.loftus@intel.com > Sent: Thursday, December 18, 2014 2:55 PM > To: dev@dpdk.org > Cc: Anthony Fee > Subject: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net = > struct > = > 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 ru= nning 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 =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; > + > + ioctl(fd_tap.source_fd, TUNGETIFF, &ifr); Shouldn't we check that ioctl() returns with success here, and if it fails,= don't copy stuff over? > + > + if (close(fd_tap.source_fd) < 0) > + RTE_LOG(ERR, VHOST_CONFIG, > + "(%"PRIu64") fd close failed\n", > + dev->device_fh); > + > + size =3D strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) > sizeof(dev->ifna= me)? > + sizeof(dev->ifname): strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)); > + So if sizeof(ifr.ifr_name) > sizeof(dev->ifname) then we can endup with dev= ->ifname not being null-termianted? Another nit: there is no need to call strnlen() twice. Konstantin > + 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 vh= ost_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) > -- > 1.7.4.1 -------------------------------------------------------------- Intel Shannon Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 Business address: Dromore House, East Park, Shannon, Co. Clare This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). Any review or distribution by others = is strictly prohibited. If you are not the intended recipient, please conta= ct the sender and delete all copies.