From nobody Mon Apr 29 04:18:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518185322813759.3121758082121; Fri, 9 Feb 2018 06:08:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F26A9C05E76D; Fri, 9 Feb 2018 14:08:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B36966F989; Fri, 9 Feb 2018 14:08:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7DDA24A46D; Fri, 9 Feb 2018 14:08:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w19E1knG009570 for ; Fri, 9 Feb 2018 09:01:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3D63C67646; Fri, 9 Feb 2018 14:01:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 353A567641 for ; Fri, 9 Feb 2018 14:01:46 +0000 (UTC) Received: from mail-io0-f195.google.com (mail-io0-f195.google.com [209.85.223.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE5666E76B for ; Fri, 9 Feb 2018 14:01:44 +0000 (UTC) Received: by mail-io0-f195.google.com with SMTP id m11so9706889iob.2 for ; Fri, 09 Feb 2018 06:01:44 -0800 (PST) Received: from linux-8bx1.caveonetworks.com ([115.113.156.2]) by smtp.googlemail.com with ESMTPSA id n4sm3900604itg.2.2018.02.09.06.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JEOiFGJMDFc0BPFKd1aWt6fGxhxIJNFz69L2LTf9feE=; b=H0Dp9LHvjirYEWDodbjnPRcfCaCf267xlVtstLyKOYfOjWRJS08EA3TXgassKo18e1 gbbtCGosUiEqSSn0TTXDbTzjFSt7yNByX8pKbx51rDJwnrQxKrZVvcUYn+f2mRfmp0Vg 1d2XGZ9z6PHwlTAFenuvMNdoedd0DX0b3k5l1HGt83nKqgXrUhTj81hjJSmgHXcAWyBs MsakQVnz80i9T9CS/478oe+WHTPCzpYxbtLII1qSXRwm5JpE07JNHovOhLEI/1Wv/8ly yrt/O4xWeSEChu4ZCrK1Gpwaj6LbQ2RapBeU/JFSl0RHkLF7HCqEc28mz5DSO/+tidtE Ui9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JEOiFGJMDFc0BPFKd1aWt6fGxhxIJNFz69L2LTf9feE=; b=q2wVXv9IU2ToQu/F7mMjLwYuitWWggmesG9C44lQtNnoAmk2ChQV5SFwi5ubIogc7Z unNjoGYQiYjs7rTwf6sfsWTT8H9Z0AqvFmqVmmjPZD5dWL3euwX2mXJcQ6GC/ah1tIKX gjxP2KxvqiF8NwBfWxzaYL/0XzBXxw+kUBJo/XYuEgojdAf6Po9JC3LAYZorAyVtZDFL mxL/IoX8X1u4MasCEGasUqinQOFZXAdIOnszL6UEdRF5hfoVETW6ucjUmrqk/tAP3yWq 3kK+QaBxX27KLR2D8AJDBB+7EtBVLaHEHlH9rVxm16+MFzN4A1Eg8lmh++EUNYuLUtcn s8Sw== X-Gm-Message-State: APf1xPCeDEbuOQSM/DD+efZboEnwv5hiMRz+imaa9e9NwHGwS7yjGypY DM98z79DVmXU4NQ3TE1qu1lHZzcb X-Google-Smtp-Source: AH8x225CqBYhdSmdMT6gMtrI8oa20+k4PQReYjYL/l64ArKNEVbPrEoktBYCCgmppM6Yh83aFgYbYw== X-Received: by 10.107.25.137 with SMTP id 131mr3451715ioz.243.1518184902256; Fri, 09 Feb 2018 06:01:42 -0800 (PST) From: Jai Singh Rana X-Google-Original-From: Jai Singh Rana To: libvir-list@redhat.com Date: Fri, 9 Feb 2018 19:30:44 +0530 Message-Id: <20180209140045.25480-2-JaiSingh.Rana@cavium.com> In-Reply-To: <20180209140045.25480-1-JaiSingh.Rana@cavium.com> References: <20180209140045.25480-1-JaiSingh.Rana@cavium.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Feb 2018 14:01:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Feb 2018 14:01:44 +0000 (UTC) for IP:'209.85.223.195' DOMAIN:'mail-io0-f195.google.com' HELO:'mail-io0-f195.google.com' FROM:'jai.rana@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.223.195 mail-io0-f195.google.com 209.85.223.195 mail-io0-f195.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: jai.rana@gmail.com, Jai Singh Rana Subject: [libvirt] [PATCH 1/2] util: Add helper APIs to get/verify VF Representor name X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 09 Feb 2018 14:08:41 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Switchdev VF Representor interface name on host is derived based on BDF of pci SR-IOV device in 'hostdev' and querying required net sysfs entries on host. --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/libvirt_private.syms | 5 + src/util/virhostdev.c | 10 ++ src/util/virhostdev.h | 6 + src/util/virnetdevhostdev.c | 284 ++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdevhostdev.h | 33 +++++ 7 files changed, 340 insertions(+) create mode 100644 src/util/virnetdevhostdev.c create mode 100644 src/util/virnetdevhostdev.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 285955469..73ce73397 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -237,6 +237,7 @@ src/util/virnetdevmacvlan.c src/util/virnetdevmidonet.c src/util/virnetdevopenvswitch.c src/util/virnetdevtap.c +src/util/virnetdevhostdev.c src/util/virnetdevveth.c src/util/virnetdevvportprofile.c src/util/virnetlink.c diff --git a/src/Makefile.am b/src/Makefile.am index db68e01db..0f3c3f1bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -148,6 +148,7 @@ UTIL_SOURCES =3D \ util/virnetdev.h util/virnetdev.c \ util/virnetdevbandwidth.h util/virnetdevbandwidth.c \ util/virnetdevbridge.h util/virnetdevbridge.c \ + util/virnetdevhostdev.h util/virnetdevhostdev.c \ util/virnetdevip.h util/virnetdevip.c \ util/virnetdevmacvlan.c util/virnetdevmacvlan.h \ util/virnetdevmidonet.h util/virnetdevmidonet.c \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3b14d7d15..d9bc8ad72 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2288,6 +2288,11 @@ virNetDevBridgeSetSTPDelay; virNetDevBridgeSetVlanFiltering; =20 =20 +# util/virnetdevhostdev.h +virNetdevHostdevCheckVFRepIFName; +virNetdevHostdevGetVFRepIFName; + + # util/virnetdevip.h virNetDevIPAddrAdd; virNetDevIPAddrDel; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a12224c58..7a90779f0 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -350,6 +350,16 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, return ret; } =20 +/* Non static wrapper for virHostdevNetDevice to use outside filescope */ +int +virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev, + int pfNetDevIdx, + char **linkdev, + int *vf) +{ + return virHostdevNetDevice(hostdev, pfNetDevIdx, linkdev, vf); +} + =20 static bool virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 54e1c66be..7dc860a85 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -202,5 +202,11 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerP= tr mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +int +virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev, + int pfNetDevIdx, + char **linkdev, + int *vf) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); =20 #endif /* __VIR_HOSTDEV_H__ */ diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c new file mode 100644 index 000000000..ecf4b7d8f --- /dev/null +++ b/src/util/virnetdevhostdev.c @@ -0,0 +1,284 @@ +/*=20 + * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include +#include +#include +#include + +#include "virhostdev.h" +#include "virnetdevhostdev.h" +#include "viralloc.h" +#include "virstring.h" +#include "virfile.h" +#include "virerror.h" +#include "virlog.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("util.netdevhostdev"); + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +#define IFSWITCHIDSIZ 20 + +#ifndef SYSFS_NET_DIR +#define SYSFS_NET_DIR "/sys/class/net/" +#endif + +#if 0 +static int +virNetdevHostdevPCISysfsPath(virDomainHostdevDefPtr hostdev, + char **sysfs_path) +{ + virPCIDeviceAddress config_address; + + config_address.domain =3D hostdev->source.subsys.u.pci.addr.domain; + config_address.bus =3D hostdev->source.subsys.u.pci.addr.bus; + config_address.slot =3D hostdev->source.subsys.u.pci.addr.slot; + config_address.function =3D hostdev->source.subsys.u.pci.addr.function; + + return virPCIDeviceAddressGetSysfsFile(&config_address, sysfs_path); +} + + +static int +virNetdevHostdevNetDevice(virDomainHostdevDefPtr hostdev, + int pfNetDevIdx, + char **linkdev, + int *vf) +{ + int ret =3D -1; + char *sysfs_path =3D NULL; + + if (virNetdevHostdevPCISysfsPath(hostdev, &sysfs_path) < 0) + return ret; + + if (virPCIIsVirtualFunction(sysfs_path) =3D=3D 1) { + if (virPCIGetVirtualFunctionInfo(sysfs_path, pfNetDevIdx, + linkdev, vf) < 0) + goto cleanup; + } else { + /* In practice this should never happen, since we currently + * only support assigning SRIOV VFs via , and it is only those devices that should + * end up calling this function. + */ + if (virPCIGetNetName(sysfs_path, 0, NULL, linkdev) < 0) + goto cleanup; + + if (!linkdev) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("The device at %s has no network device name"= ), + sysfs_path); + goto cleanup; + } + + *vf =3D -1; + } + + ret =3D 0; + + cleanup: + VIR_FREE(sysfs_path); + + return ret; +} +#endif + + +/** + * virNetdevHostdevNetSysfsPath + * + * @pf_name: netdev name of the physical function (PF) + * @vf: virtual function (VF) number for the device of interest + * @vf_representor: name of the VF representor interface + * + * Finds the VF representor name of VF# @vf of SRIOV PF @pfname, and + * puts it in @vf_representor. The caller must free @vf_representor + * when it's finished with it + * + * Returns 0 on success, -1 on failure + */ +static int +virNetdevHostdevNetSysfsPath(char *pf_name, int vf, char **vf_representor) +{ + char *pf_switch_id =3D NULL; + char *pf_switch_id_file =3D NULL; + char *pf_subsystem_device_file =3D NULL; + char *pf_subsystem_device_switch_id =3D NULL; + char *pf_subsystem_device_port_name_file =3D NULL; + char *pf_subsystem_dir =3D NULL; + char *vf_representor_name =3D NULL; + char *vf_num_str =3D NULL; + char *vf_suffix =3D NULL; + DIR *dirp =3D NULL; + struct dirent *dp; + int ret =3D -1; + + + if (virAsprintf(&pf_switch_id_file, SYSFS_NET_DIR "%s/phys_switch_id", + pf_name) < 0) + goto cleanup; + + if (virAsprintf(&pf_subsystem_dir, SYSFS_NET_DIR "%s/subsystem", + pf_name) < 0) + goto cleanup; + + if (virFileReadAllQuiet(pf_switch_id_file, IFSWITCHIDSIZ, + &pf_switch_id) <=3D 0) { + goto cleanup; + } + + if (virDirOpen(&dirp, pf_subsystem_dir) < 0) + goto cleanup; + + /* Iterate over the PFs subsystem devices to find entry with matching + * switch_id with that of PF. + */ + while (virDirRead(dirp, &dp, pf_subsystem_dir) > 0) { + if (STREQ(dp->d_name, pf_name)) + continue; + + if (virAsprintf(&pf_subsystem_device_file, "%s/%s/phys_switch_id", + pf_subsystem_dir, dp->d_name) < 0) + goto cleanup; + + if (virFileReadAllQuiet(pf_subsystem_device_file, IFSWITCHIDSIZ, + &pf_subsystem_device_switch_id) > 0) { + if (!STREQ(pf_switch_id, pf_subsystem_device_switch_id)) { + VIR_FREE(pf_subsystem_device_file); + VIR_FREE(pf_subsystem_device_switch_id); + continue; + } + } + + if (virAsprintf(&pf_subsystem_device_port_name_file, + "%s/%s/phys_port_name", pf_subsystem_dir, + dp->d_name) < 0) + goto cleanup; + + if (virFileReadAllQuiet + (pf_subsystem_device_port_name_file, IFNAMSIZ, + &vf_representor_name) <=3D 0) { + VIR_FREE(pf_subsystem_device_file); + VIR_FREE(pf_subsystem_device_switch_id); + VIR_FREE(pf_subsystem_device_port_name_file); + continue; + } + + if (virAsprintf(&vf_num_str, "%d", vf) < 0) + goto cleanup; + + /* phys_port_name may contain just VF number or string with + * 'vf' or 'VF' followed by VF number at the end. + */ + if (!(vf_suffix =3D strcasestr(vf_representor_name, "vf"))) + vf_suffix =3D vf_representor_name; + + if (strstr(vf_suffix, vf_num_str)) { + if (virAsprintf(vf_representor, "%s", dp->d_name) < 0) + goto cleanup; + + ret =3D 0; + break; + } + } + + cleanup: + VIR_DIR_CLOSE(dirp); + VIR_FREE(pf_switch_id); + VIR_FREE(pf_switch_id_file); + VIR_FREE(pf_subsystem_dir); + VIR_FREE(pf_subsystem_device_file); + VIR_FREE(pf_subsystem_device_switch_id); + VIR_FREE(pf_subsystem_device_port_name_file); + VIR_FREE(vf_num_str); + VIR_FREE(vf_representor_name); + return ret; +} + + +/** + * virNetdevHostdevGetVFRepIFName + * + * @hostdev: host device to check + * @ifname : Contains VF representor name upon successful return. + * + * Returns 0 on success, -1 on failure + */ +int +virNetdevHostdevGetVFRepIFName(virDomainHostdevDefPtr hostdev, + char **ifname) +{ + char *linkdev =3D NULL; + char *vf_representor =3D NULL; + int vf =3D -1; + int ret =3D -1; + + if (virHostdevNetDeviceWrapper(hostdev, -1, &linkdev, &vf) < 0) + goto cleanup; + + if (virNetdevHostdevNetSysfsPath(linkdev, vf, &vf_representor)) + goto cleanup; + + if (VIR_STRDUP(*ifname, vf_representor) > 0) + ret =3D 0; + + cleanup: + VIR_FREE(linkdev); + VIR_FREE(vf_representor); + return ret; +} + + +/** + * virNetdevHostdevCheckVFRepIFName + * + * @hostdev: host device to check + * @ifname : VF representor name to verify + * + * Returns 0 on success, -1 on failure + */ +int +virNetdevHostdevCheckVFRepIFName(virDomainHostdevDefPtr hostdev, + const char *ifname) +{ + char *linkdev =3D NULL; + char *vf_representor =3D NULL; + int vf =3D -1; + int ret =3D -1; + + if (virHostdevNetDeviceWrapper(hostdev, -1, &linkdev, &vf) < 0) + goto cleanup; + + if (virNetdevHostdevNetSysfsPath(linkdev, vf, &vf_representor)) + goto cleanup; + + if (STREQ(ifname, vf_representor)) + ret =3D 0; + + cleanup: + VIR_FREE(linkdev); + VIR_FREE(vf_representor); + return ret; +} diff --git a/src/util/virnetdevhostdev.h b/src/util/virnetdevhostdev.h new file mode 100644 index 000000000..9fb5c5069 --- /dev/null +++ b/src/util/virnetdevhostdev.h @@ -0,0 +1,33 @@ +/*=20 + * virnetdevhostdev.h: utilities to get/verify Switchdev VF Representor + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef __VIR_NETDEV_HOSTDEV_H__ +#define __VIR_NETDEV_HOSTDEV_H__ +#include "virnetdevtap.h" + +int +virNetdevHostdevGetVFRepIFName(virDomainHostdevDefPtr hostdev, + char **ifname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +int +virNetdevHostdevCheckVFRepIFName(virDomainHostdevDefPtr hostdev, + const char *ifname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +#define virNetdevHostdevVFRepInterfaceStats virNetDevTapInterfaceStats +#endif /* __VIR_NETDEV_HOSTDEV_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 04:18:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15181853276111014.0382338161536; Fri, 9 Feb 2018 06:08:47 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 460963ADA9; Fri, 9 Feb 2018 14:08:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C5826EE5C; Fri, 9 Feb 2018 14:08:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D5B954A471; Fri, 9 Feb 2018 14:08:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w19E1p8j009807 for ; Fri, 9 Feb 2018 09:01:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id A35505D723; Fri, 9 Feb 2018 14:01:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AA0F5D995 for ; Fri, 9 Feb 2018 14:01:48 +0000 (UTC) Received: from mail-io0-f193.google.com (mail-io0-f193.google.com [209.85.223.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61CBFC05FEF7 for ; Fri, 9 Feb 2018 14:01:47 +0000 (UTC) Received: by mail-io0-f193.google.com with SMTP id f89so9720578ioj.4 for ; Fri, 09 Feb 2018 06:01:47 -0800 (PST) Received: from linux-8bx1.caveonetworks.com ([115.113.156.2]) by smtp.googlemail.com with ESMTPSA id n4sm3900604itg.2.2018.02.09.06.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z6dkQkDw/JGmQwDpsvg1hwVbKIRYPOCDafJkoCx4j+w=; b=WTyeZKM3F1LOfVlmQiG+LlMgjuZa8nY6hDbaE/qT2vMITPh1kjx7KsKWa4SfODZNrC za5xy5SNyVBFBus+qwc8P9+2V/8LFYdza0BOGW3cbga0I2eQWg+Xs/A4B0InXRZF/EJF SlwmRcs5Amumlr/KNPLAOgSoyB9EdnnO4Vo4HoDvPrXPDo8UlePb228rt0z4MT0nqa27 WA4qD2NNykCOZmOOz2vDksC40W8dw1BdRaiJOazT1uQCOl1mtqWZWbBSpOTI7Tn13Sx8 3rpf7hdp2m650kNyydIc3KlKuzWSN579cCGSECh2yEhsualW06q0eWMotm9il4AExKOv LJNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z6dkQkDw/JGmQwDpsvg1hwVbKIRYPOCDafJkoCx4j+w=; b=Bemq8dMtVnxf6/jnC4970FSGrwCxNfRvjpE3CpGsPCrABvbdzE3Wnzd+JMsXmvj9vZ g7146prBjV5u2IOiorO6/sw1P4KFiy6XVoyQVu+mHDnd1rbAQEbjLT2T11P/oBEAPJMH LAsl1PQYH4ZU49z5ggTV3/P1IWkdc8UQX4QJGd7H5Pacx3AkcuV4GqTlDPvkBMDj0zio 39QKcC1+AELIAQk1jr8kFN36itqSnO9Hp8kdSmyWGHtcFDXWHqhyH3MqIDTJXDgtG9we 6gZZahcIDWhcs6Rv4mSZsj+kEnDkgEjMGc5gwz0j9s1Mh1Fd2HHZq7qk91uQuzqnQetB j2Zw== X-Gm-Message-State: APf1xPBjnzFr5Q8/gPcB78EzE/orTBEze4+WCZqOuzVQN1ly/cYaYUHB NGJh1DkMP1EcuN1N1NcJys+gQu1B X-Google-Smtp-Source: AH8x225wfcXiEwlnH7Umg7Zh7EPPtp/A7bac1/v+sKOFWTzi4sUZwpRMoPTGH/+CFOu7NcCbNNcpeg== X-Received: by 10.107.7.69 with SMTP id 66mr3194419ioh.216.1518184906090; Fri, 09 Feb 2018 06:01:46 -0800 (PST) From: Jai Singh Rana X-Google-Original-From: Jai Singh Rana To: libvir-list@redhat.com Date: Fri, 9 Feb 2018 19:30:45 +0530 Message-Id: <20180209140045.25480-3-JaiSingh.Rana@cavium.com> In-Reply-To: <20180209140045.25480-1-JaiSingh.Rana@cavium.com> References: <20180209140045.25480-1-JaiSingh.Rana@cavium.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 09 Feb 2018 14:01:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 09 Feb 2018 14:01:47 +0000 (UTC) for IP:'209.85.223.193' DOMAIN:'mail-io0-f193.google.com' HELO:'mail-io0-f193.google.com' FROM:'jai.rana@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.223.193 mail-io0-f193.google.com 209.85.223.193 mail-io0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: jai.rana@gmail.com, Jai Singh Rana Subject: [libvirt] [PATCH 2/2] qemu: conf: Network stats support for hostdev VF Representor X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 09 Feb 2018 14:08:46 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In case of , return stats if its a Switchdev VF Representor interface of pci SR-IOV device. --- src/conf/domain_conf.c | 7 +++++++ src/qemu/qemu_driver.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fb732a0c2..649fc2eb8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -58,6 +58,7 @@ #include "virnetdev.h" #include "virnetdevmacvlan.h" #include "virhostdev.h" +#include "virnetdevhostdev.h" #include "virmdev.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -28112,6 +28113,12 @@ virDomainNetFind(virDomainDefPtr def, const char *= device) return net; } =20 + /* Give a try to hostdev */ + for (i =3D 0; i < def->nnets; i++) { + if(!virNetdevHostdevCheckVFRepIFName(def->hostdevs[i], device)) + return def->nets[i]; + } + virReportError(VIR_ERR_INVALID_ARG, _("'%s' is not a known interface"), device); return NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 978ecd4e0..3a3a9c986 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -67,6 +67,7 @@ #include "virhostcpu.h" #include "virhostmem.h" #include "virnetdevtap.h" +#include "virnetdevhostdev.h" #include "virnetdevopenvswitch.h" #include "capabilities.h" #include "viralloc.h" @@ -11153,6 +11154,11 @@ qemuDomainInterfaceStats(virDomainPtr dom, if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSE= R) { if (virNetDevOpenvswitchInterfaceStats(net->ifname, stats) < 0) goto cleanup; + } else if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_H= OSTDEV) { + if (virNetdevHostdevVFRepInterfaceStats(device, stats, + !virDomainNetTypeSharesHos= tView + (net)) < 0) + goto cleanup; } else { if (virNetDevTapInterfaceStats(net->ifname, stats, !virDomainNetTypeSharesHostView(net= )) < 0) @@ -19794,6 +19800,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver= ATTRIBUTE_UNUSED, { size_t i; struct _virDomainInterfaceStats tmp; + char *vf_representor_ifname =3D NULL; int ret =3D -1; =20 if (!virDomainObjIsActive(dom)) @@ -19806,21 +19813,40 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driv= er ATTRIBUTE_UNUSED, virDomainNetDefPtr net =3D dom->def->nets[i]; virDomainNetType actualType; =20 - if (!net->ifname) + actualType =3D virDomainNetGetActualType(net); + + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { + if (virNetdevHostdevGetVFRepIFName(dom->def->hostdevs[i], + &vf_representor_ifname)) + continue; + } + else if (!net->ifname) continue; =20 memset(&tmp, 0, sizeof(tmp)); =20 - actualType =3D virDomainNetGetActualType(net); =20 - QEMU_ADD_NAME_PARAM(record, maxparams, - "net", "name", i, net->ifname); + if (actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) + QEMU_ADD_NAME_PARAM(record, maxparams, + "net", "name", i, net->ifname); + else + QEMU_ADD_NAME_PARAM(record, maxparams, + "net", "name", i, vf_representor_ifname); =20 if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { if (virNetDevOpenvswitchInterfaceStats(net->ifname, &tmp) < 0)= { virResetLastError(); continue; } + } else if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { + if (virNetdevHostdevVFRepInterfaceStats + (vf_representor_ifname, &tmp, + !virDomainNetTypeSharesHostView(net)) < 0) { + VIR_FREE(vf_representor_ifname); + virResetLastError(); + continue; + } + VIR_FREE(vf_representor_ifname); } else { if (virNetDevTapInterfaceStats(net->ifname, &tmp, !virDomainNetTypeSharesHostView= (net)) < 0) { --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list