From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id A429F8041 for ; Fri, 19 Dec 2014 16:39:32 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 19 Dec 2014 07:39:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="431232359" Received: from irsmsx109.ger.corp.intel.com ([163.33.3.23]) by FMSMGA003.fm.intel.com with ESMTP; 19 Dec 2014 07:28:14 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.144]) by IRSMSX109.ger.corp.intel.com ([169.254.13.244]) with mapi id 14.03.0195.001; Fri, 19 Dec 2014 15:39:29 +0000 From: "Ananyev, Konstantin" To: "Loftus, Ciara" , "dev@dpdk.org" Thread-Topic: [PATCH v2] vhost: add interface name to virtio-net struct Thread-Index: AQHQGu1+MOnmNh8pUE2NrTb8Pd7SCJyXAx/g Date: Fri, 19 Dec 2014 15:39:29 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258213C2436@IRSMSX105.ger.corp.intel.com> References: <1418926027-19794-1-git-send-email-ciara.loftus@intel.com> In-Reply-To: <1418926027-19794-1-git-send-email-ciara.loftus@intel.com> Accept-Language: en-IE, 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" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: Fri, 19 Dec 2014 15:39:33 -0000 Hi Ciara, > -----Original Message----- > From: Loftus, Ciara > Sent: Thursday, December 18, 2014 6:07 PM > To: dev@dpdk.org > Cc: thomas.monjalon@6wind.com; stephen@networkplumber.org; vincent.jardin= @6wind.com; Ananyev, Konstantin; Czesnowicz, > Przemyslaw; Loftus, Ciara; Anthony Fee > Subject: [PATCH v2] vhost: add interface name to virtio-net struct >=20 > From: Ciara Loftus >=20 > 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. >=20 > 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(-) >=20 > diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_vir= tio_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 >=20 > #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 ru= nning on data core. */ > + char ifname[IFNAMSIZ]; /**< Name of the tap device. */ > void *priv; /**< private context */ > } __rte_cache_aligned; >=20 > diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.= 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 >=20 > +#include > +#include > +#include > + > #include > #include > #include > @@ -1000,6 +1004,46 @@ set_vring_kick(struct vhost_device_ctx ctx, struct= vhost_vring_file *file) > } >=20 > /* > + * 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, 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; If you saying that sizeof(ifr.ifr_name) would always be equal to sizeof(de= v->ifname), then why are you doing the comparison above? "ifr_size <=3D sizeof(dev->ifname)" would always be true, right? >>From other side, if if strlen(ifr.ifr_name) < sizeof(dev->ifname), you wo= uldn't copy over terminating 0. I think it needs to be something like: size =3D strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) + 1; size =3D RTE_MIN(size, sizeof(dev->ifname)); strncpy(dev->ifname, ifr.ifr_name, size); dev->ifname[sizeof(dev->ifname) - 1] =3D 0; > + > + strncpy(dev->ifname, ifr.ifr_name, size); > + } else > + RTE_LOG(ERR, VHOST_CONFIG, > + "(%"PRIu64") TUNGETIFF ioctl failed\n", > + dev->device_fh); > + > + return 0; Shouldn't we return a failure if ret is negative (ioclt failed)?=20 Konstantin > +} > + > +/* > * 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 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