From nobody Thu May 2 02:54:18 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 1522859726738322.8356504564829; Wed, 4 Apr 2018 09:35:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDF7980463; Wed, 4 Apr 2018 16:35:24 +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 97D6D16927; Wed, 4 Apr 2018 16:35:24 +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 A95564CA97; Wed, 4 Apr 2018 16:35:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w34GUGnk014654 for ; Wed, 4 Apr 2018 12:30:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFB067A4D2; Wed, 4 Apr 2018 16:30:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7EF27A43E for ; Wed, 4 Apr 2018 16:30:13 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 B772A356C9 for ; Wed, 4 Apr 2018 16:30:11 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id v5-v6so12771564plo.4 for ; Wed, 04 Apr 2018 09:30:11 -0700 (PDT) Received: from hyd1jrana-dt.caveonetworks.com.com ([115.113.156.2]) by smtp.googlemail.com with ESMTPSA id g127sm4059474pgc.6.2018.04.04.09.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Apr 2018 09:30:10 -0700 (PDT) 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=oOciXK1aUcvquGLDYCCgO6hr1y1mXQZbU2PO4CRfmzE=; b=baafWsMleGpCqgFHgeR8AbjCnPcJlXi4RO3fCp3IEOzcX56L3p5Wl4gu9m3KmAOCo9 25qUf8NeqMwkis8M6yD/SQsOkonoGy0U5WYNkLxCOGSpcvkz+EkqQ3A1uj5XOvY6n8kM ZwJ2obXd9N4xn+zO71IB+/T5TB/irU3R3hVZdTdHWGBV0CYnquhL8Ao0Qnr9iiG4C0kS sQk5sNTOHceSUnyCubTAX+pvGz5s4GaDsLBPvF06gNMQNGlrsaCBM26QdJ9e3ov59xOr lMpKFzElZYklxMSlBh3O3b5g/Bty+dHaTw3fbKn9tr2pNytVRKCXYi/l7en1k+SvchEZ XebA== 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=oOciXK1aUcvquGLDYCCgO6hr1y1mXQZbU2PO4CRfmzE=; b=IPRYkMxe+Vd3lKDCqSUGXAMjKoIOJ+OuisZ0I6Lm5xf/fVY7wJbcZeWx1/eqNyOR7t MdDEA+W80Sx20KmNJ/IQ5KhrZXsm/gHkj782yyT6XA3ck4YSElx1MO5JJFU5BNeUgu6N A4sOaMEMWm1u+UNlo7O7GmqjN37OFZrJL5ZcY3hkc5mPUVLqYtgUHoGt+G3uMQ4DeL+Y BcNWpExUc/6AkOc0zAwfKUcN/UlfPzItJhh2vQVA7sPW6BOktSmsROef1zkLZiSkOl8u 2lGnemBdwPevX0F1r52L8RnSYjF5QsUokzqnDfmo9tJBG2OfkO2BLDA6aMXBwZX6dZ6F TZ0A== X-Gm-Message-State: AElRT7EMuzpcWkHRlbbawxNQlg0n/ZZrHgUVmgLTwcRSxwh4j09DSj0O X7yRc0ZK1/ETs3urWvUsS7EMaA== X-Google-Smtp-Source: AIpwx48Zvjwxw1sIgeXPFdiH2dNodkvKI94QA2lZI5JrQ6LOtm8s8X5QZv0ijcgoJFmDJ1vs66Eb6Q== X-Received: by 2002:a17:902:9308:: with SMTP id bc8-v6mr19248984plb.189.1522859410944; Wed, 04 Apr 2018 09:30:10 -0700 (PDT) From: Jai Singh Rana X-Google-Original-From: Jai Singh Rana To: libvir-list@redhat.com Date: Wed, 4 Apr 2018 21:59:26 +0530 Message-Id: <20180404162927.16210-2-JaiSingh.Rana@cavium.com> In-Reply-To: <20180404162927.16210-1-JaiSingh.Rana@cavium.com> References: <20180404162927.16210-1-JaiSingh.Rana@cavium.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Apr 2018 16:30:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Apr 2018 16:30:11 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'jai.rana@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: JaiSingh.Rana@cavium.com Subject: [libvirt] [PATCH v3 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Apr 2018 16:35:25 +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 queried based on Bus:Device:Function information of pci SR-IOV device in Domain's 'hostdev' structure and subsequently verifying the required net sysfs directory and file entries of VF representor according to switchdev model. --- v3 includes changes based on v2's[1] feedback and suggestions. Fixes warnings reported by syntax-check. [1] https://www.redhat.com/archives/libvir-list/2018-February/msg00562.html po/POTFILES.in | 1 + src/libvirt_private.syms | 7 + src/util/Makefile.inc.am | 2 + src/util/virhostdev.c | 2 +- src/util/virhostdev.h | 8 + src/util/virnetdevhostdev.c | 374 ++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdevhostdev.h | 35 +++++ 7 files changed, 428 insertions(+), 1 deletion(-) 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 d84859a4e..8cd6b86e8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -234,6 +234,7 @@ src/util/virmdev.c src/util/virnetdev.c src/util/virnetdevbandwidth.c src/util/virnetdevbridge.c +src/util/virnetdevhostdev.c src/util/virnetdevip.c src/util/virnetdevmacvlan.c src/util/virnetdevmidonet.c diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f6897915c..fad235206 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1923,6 +1923,7 @@ virHostCPUStatsAssign; virHostdevFindUSBDevice; virHostdevIsSCSIDevice; virHostdevManagerGetDefault; +virHostdevNetDevice; virHostdevPCINodeDeviceDetach; virHostdevPCINodeDeviceReAttach; virHostdevPCINodeDeviceReset; @@ -2306,6 +2307,12 @@ virNetDevBridgeSetSTPDelay; virNetDevBridgeSetVlanFiltering; =20 =20 +# util/virnetdevhostdev.h +virNetdevHostdevCheckVFRIfName; +virNetdevHostdevGetVFRIfName; +virNetdevHostdevVFRIfStats; + + # util/virnetdevip.h virNetDevIPAddrAdd; virNetDevIPAddrDel; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index a3c3b711f..31fe11c68 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -104,6 +104,8 @@ UTIL_SOURCES =3D \ util/virnetdevbandwidth.h \ util/virnetdevbridge.c \ util/virnetdevbridge.h \ + util/virnetdevhostdev.c \ + util/virnetdevhostdev.h \ util/virnetdevip.c \ util/virnetdevip.h \ util/virnetdevmacvlan.c \ diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a12224c58..4f7b46a04 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -306,7 +306,7 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr host= dev) } =20 =20 -static int +int virHostdevNetDevice(virDomainHostdevDefPtr hostdev, int pfNetDevIdx, char **linkdev, diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 54e1c66be..735220add 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -60,6 +60,14 @@ struct _virHostdevManager { }; =20 virHostdevManagerPtr virHostdevManagerGetDefault(void); + +int +virHostdevNetDevice(virDomainHostdevDefPtr hostdev, + int pfNetDevIdx, + char **linkdev, + int *vf) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); + int virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c new file mode 100644 index 000000000..19f95bfdd --- /dev/null +++ b/src/util/virnetdevhostdev.c @@ -0,0 +1,374 @@ +/* + * 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 "virnetdev.h" +#include "virnetdevhostdev.h" +#include "viralloc.h" +#include "virstring.h" +#include "virfile.h" +#include "virerror.h" +#include "virlog.h" +#include "c-ctype.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("util.netdevhostdev"); + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +#define IFSWITCHIDSIZ 20 + +#ifdef __linux__ +/** + * virNetdevHostdevNetSysfsPath + * + * @pf_name: netdev name of the physical function (PF) + * @vf: virtual function (VF) number for the device of interest + * @vf_ifname: name of the VF representor interface + * + * Finds the VF representor name of VF# @vf of SRIOV PF @pfname, + * and puts it in @vf_ifname. The caller must free @vf_ifname + * when it's finished with it + * + * Returns 0 on success, -1 on failure + */ +static int +virNetdevHostdevNetSysfsPath(char *pf_name, + int vf, + char **vf_ifname) +{ + size_t i; + 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_rep_ifname =3D NULL; + char *vf_num_str =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; + + /* a failure to read just means the driver doesn't support + * phys_switch_id, so ignoring the error from + * virFileReadAllQuiet(). + */ + 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; + + VIR_FREE(pf_subsystem_device_file); + if (virAsprintf(&pf_subsystem_device_file, "%s/%s/phys_switch_id", + pf_subsystem_dir, dp->d_name) < 0) + goto cleanup; + + /* a failure to read just means the driver doesn't support the entry + * being probed for current device in subsystem dir, so ignoring the + * error in the following calls to virFileReadAllQuiet() and continue + * the loop to find device which supports this and is a match. + */ + VIR_FREE(pf_subsystem_device_switch_id); + if (virFileReadAllQuiet(pf_subsystem_device_file, IFSWITCHIDSIZ, + &pf_subsystem_device_switch_id) > 0) { + if (STRNEQ(pf_switch_id, 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; + + VIR_FREE(vf_rep_ifname); + vf_rep_ifname =3D NULL; + + if (virFileReadAllQuiet + (pf_subsystem_device_port_name_file, IFNAMSIZ, + &vf_rep_ifname) <=3D 0) + continue; + + if (virAsprintf(&vf_num_str, "%d", vf) < 0) + goto cleanup; + + /* phys_port_name may contain just VF number or string in format + * as pf'X'vf'Y' or vf'Y', where X and Y are PF and VF numbers. + * As at this point, we are already with correct PF, just need + * to verify VF number now. + */ + + /* vf_rep_ifname read from file may contain new line,replace with = '\0' + for string comparison below */ + i =3D strlen(vf_rep_ifname); + if (c_isspace(vf_rep_ifname[i-1])) { + vf_rep_ifname[i-1] =3D '\0'; + i -=3D 1; + } + + while (c_isdigit(vf_rep_ifname[i-1])) + i -=3D 1; + + if ((ret =3D STREQ((vf_rep_ifname + i), vf_num_str))) { + if (VIR_STRDUP(*vf_ifname, 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_rep_ifname); + return ret; +} + + +/** + * virNetdevHostdevGetVFRepIFName + * + * @hostdev: host device to check + * + * Returns VF string with VF representor name upon success else NULL + */ +char * +virNetdevHostdevGetVFRIfName(virDomainHostdevDefPtr hostdev) +{ + char *linkdev =3D NULL; + char *ifname =3D NULL; + char *vf_ifname =3D NULL; + int vf =3D -1; + + if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) + goto cleanup; + + if (virNetdevHostdevNetSysfsPath(linkdev, vf, &vf_ifname)) + goto cleanup; + + ignore_value(VIR_STRDUP(ifname, vf_ifname)); + + cleanup: + VIR_FREE(linkdev); + VIR_FREE(vf_ifname); + return ifname; +} + + +/** + * virNetdevHostdevCheckVFRepIFName + * + * @hostdev: host device to check + * @ifname : VF representor name to verify + * + * Returns true on success, false on failure + */ +bool +virNetdevHostdevCheckVFRIfName(virDomainHostdevDefPtr hostdev, + const char *ifname) +{ + char *linkdev =3D NULL; + char *vf_ifname =3D NULL; + int vf =3D -1; + bool ret =3D false; + + if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) + goto cleanup; + + if (virNetdevHostdevNetSysfsPath(linkdev, vf, &vf_ifname)) + goto cleanup; + + if (STREQ(ifname, vf_ifname)) + ret =3D true; + + cleanup: + VIR_FREE(linkdev); + VIR_FREE(vf_ifname); + return ret; +} + + +/*-------------------- interface stats --------------------*/ +/* Copy of virNetDevTapInterfaceStats for linux */ +/** + * virNetdevHostdevVFRepInterfaceStats: + * @ifname: interface + * @stats: where to store statistics + * @swapped: whether to swap RX/TX fields + * + * Fetch RX/TX statistics for given named interface (@ifname) and + * store them at @stats. The returned statistics are always from + * domain POV. Because in some cases this means swapping RX/TX in + * the stats and in others this means no swapping (consider TAP + * vs macvtap) caller might choose if the returned stats should + * be @swapped or not. + * + * Returns 0 on success, -1 otherwise (with error reported). + */ +int +virNetdevHostdevVFRIfStats(const char *ifname, + virDomainInterfaceStatsPtr stats, + bool swapped) +{ + int ifname_len; + FILE *fp; + char line[256], *colon; + + fp =3D fopen("/proc/net/dev", "r"); + if (!fp) { + virReportSystemError(errno, "%s", + _("Could not open /proc/net/dev")); + return -1; + } + + ifname_len =3D strlen(ifname); + + while (fgets(line, sizeof(line), fp)) { + long long dummy; + long long rx_bytes; + long long rx_packets; + long long rx_errs; + long long rx_drop; + long long tx_bytes; + long long tx_packets; + long long tx_errs; + long long tx_drop; + + /* The line looks like: + * " eth0:..." + * Split it at the colon. + */ + colon =3D strchr(line, ':'); + if (!colon) continue; + *colon =3D '\0'; + if (colon-ifname_len >=3D line && + STREQ(colon-ifname_len, ifname)) { + if (sscanf(colon+1, + "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld = %lld %lld %lld %lld %lld %lld", + &rx_bytes, &rx_packets, &rx_errs, &rx_drop, + &dummy, &dummy, &dummy, &dummy, + &tx_bytes, &tx_packets, &tx_errs, &tx_drop, + &dummy, &dummy, &dummy, &dummy) !=3D 16) + continue; + + if (swapped) { + stats->rx_bytes =3D tx_bytes; + stats->rx_packets =3D tx_packets; + stats->rx_errs =3D tx_errs; + stats->rx_drop =3D tx_drop; + stats->tx_bytes =3D rx_bytes; + stats->tx_packets =3D rx_packets; + stats->tx_errs =3D rx_errs; + stats->tx_drop =3D rx_drop; + } else { + stats->rx_bytes =3D rx_bytes; + stats->rx_packets =3D rx_packets; + stats->rx_errs =3D rx_errs; + stats->rx_drop =3D rx_drop; + stats->tx_bytes =3D tx_bytes; + stats->tx_packets =3D tx_packets; + stats->tx_errs =3D tx_errs; + stats->tx_drop =3D tx_drop; + } + + VIR_FORCE_FCLOSE(fp); + return 0; + } + } + VIR_FORCE_FCLOSE(fp); + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("/proc/net/dev: Interface not found")); + return -1; +} +#else +int +virNetdevHostdevVFRIfStats(const char *ifname ATTRIBUTE_UNUSED, + virDomainInterfaceStatsPtr stats ATTRIBUTE_UNUS= ED, + bool swapped ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("interface stats not implemented on this platform")); + return -1; +} + + +static const char *unsupported =3D N_("not supported on non-linux platform= s"); + + +static int +virNetdevHostdevNetSysfsPath(char *pf_name ATTRIBUTE_UNUSED, + int vf ATTRIBUTE_UNUSED, + char **vf_ifname ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); + return -1; +} + + +char * +virNetdevHostdevGetVFRIfName(virDomainHostdevDefPtr hostdev ATTRIBUTE_UNUS= ED, + char **ifname ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); + return NULL; +} + + +static bool +virNetdevHostdevCheckVFRIfName(virDomainHostdevDefPtr hostdev ATTRIBUTE_UN= USED, + const char *ifname ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); + return false; +} +#endif diff --git a/src/util/virnetdevhostdev.h b/src/util/virnetdevhostdev.h new file mode 100644 index 000000000..3ea1804ff --- /dev/null +++ b/src/util/virnetdevhostdev.h @@ -0,0 +1,35 @@ +/* + * 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" + +char * +virNetdevHostdevGetVFRIfName(virDomainHostdevDefPtr hostdev) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +bool +virNetdevHostdevCheckVFRIfName(virDomainHostdevDefPtr hostdev, + const char *ifname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +int virNetdevHostdevVFRIfStats(const char *ifname, + virDomainInterfaceStatsPtr stats, + bool swapped) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +#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 Thu May 2 02:54:18 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 1522859427647459.893864031518; Wed, 4 Apr 2018 09:30:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CAE78046B; Wed, 4 Apr 2018 16:30:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 322C8179E8; Wed, 4 Apr 2018 16:30:26 +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 E344D180BAD5; Wed, 4 Apr 2018 16:30:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w34GUMjX014671 for ; Wed, 4 Apr 2018 12:30:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 581EA81B42; Wed, 4 Apr 2018 16:30:22 +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 5052080F93 for ; Wed, 4 Apr 2018 16:30:18 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 4032AC036778 for ; Wed, 4 Apr 2018 16:30:17 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id v18-v6so12777158ply.12 for ; Wed, 04 Apr 2018 09:30:17 -0700 (PDT) Received: from hyd1jrana-dt.caveonetworks.com.com ([115.113.156.2]) by smtp.googlemail.com with ESMTPSA id g127sm4059474pgc.6.2018.04.04.09.30.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Apr 2018 09:30:15 -0700 (PDT) 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=YPMCA0O/rY/mp2hLQ4c9lB5JGkaQBNqboxESKtxn5bo=; b=R6w4l6gT9G1XkXXw9UdqkXBF1yAImdXqEshhzzOV12QbgQeRpBXKWw4bKsk6AId0N1 ZKqp+nombuLfU1BZ+9eXPbGdjbSlUkdEp9pmOdIqDStToM/U/H3fawj05eiW1d+kUtgD dvrZ58E5Te+7FbMU0vmh8dqgM69H45VIvvug8V2OfDGSfMRofgKAi9GlQxIOzs4jE4E2 a1+GZhG+0VX9BU/xmcyogBsj6zPieBQzDdGWvETwBx44NosTFfCxJHfsD+JtgLkjZPeZ YpNRxXzH7u4wQvo9/noHXQ01Q2MBJqn5L23eNdYDKEVBV/p9syCGNKE0+Zg70AvBOTqw Avwg== 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=YPMCA0O/rY/mp2hLQ4c9lB5JGkaQBNqboxESKtxn5bo=; b=XKjvBrgspy1dll1YXGvL/OTty9+OrjB0SSd5bUuXbC/03MU0eguiparm8Dg2vTyn18 s5eaFUMP8dtU0d7D1LFTj1vNtvXSLUiBZ32JQqsWyjUSqjWasDKvfg1walM2EkkQ32RN q7HmQLskwcuEmv3mrHCn5ArSIw9pOf1HXNDMzt694OrDsGPF7VsptyLZR8+2HgKZVpIo cb4amOFAN4/ACFW/awY1d6pY0pUm4hzzAaRAQ8CuKaJXG0o6Oxyna5+wCNAhpTmgisjG mBRIO1KRZqR8pi1DmvUHF8YKdyPOBqIX8AxRIsiEOYxjig6zGVyfTajODDJcIPWYyX+O UQtA== X-Gm-Message-State: AElRT7G3ki3gjDZnQB1zQOwbst4VXIeyc8eoO+MzDre7Q38qahsEfeYi dnb6ipMdvuUvwCkowGXaB1cAWA== X-Google-Smtp-Source: AIpwx4/OA4JEuHMgjz8Ec9EsK7YiEWNbmPDepQDwVoVg6mA+SlKFKp3LHKMfB+vn18rM30fhe797tA== X-Received: by 2002:a17:902:3001:: with SMTP id u1-v6mr19623171plb.164.1522859416458; Wed, 04 Apr 2018 09:30:16 -0700 (PDT) From: Jai Singh Rana X-Google-Original-From: Jai Singh Rana To: libvir-list@redhat.com Date: Wed, 4 Apr 2018 21:59:27 +0530 Message-Id: <20180404162927.16210-3-JaiSingh.Rana@cavium.com> In-Reply-To: <20180404162927.16210-1-JaiSingh.Rana@cavium.com> References: <20180404162927.16210-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]); Wed, 04 Apr 2018 16:30:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 04 Apr 2018 16:30:17 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'jai.rana@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: JaiSingh.Rana@cavium.com Subject: [libvirt] [PATCH v3 2/2] qemu: conf: Network stats support for VF Representors 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Apr 2018 16:30:26 +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 pci SR-IOV device with interface_type as 'hostdev', return network stats if it has a VF Representor interface on host for pci SR-IOV device according to switchdev model. --- v3 includes changes based on v2's[1] feedback and suggestions. Includes fix for hostdev to net mapping in a given domain. [1] https://www.redhat.com/archives/libvir-list/2018-February/msg00563.html docs/news.xml | 9 +++++++++ src/conf/domain_conf.c | 15 +++++++++++++++ src/qemu/qemu_driver.c | 33 +++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/news.xml b/docs/news.xml index 87f52e83e..04c18495f 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -47,6 +47,15 @@ supported. In fact, kernel has been supporting this since 4.10. + + + qemu: Support interface network stats for VF Representors + + + Interface network stats are supported now for SR-IOV device(host= dev) + if this interface has VF representor on host in switchdev mode. + +
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef16431aa..50813701c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -56,6 +56,7 @@ #include "virsecret.h" #include "virstring.h" #include "virnetdev.h" +#include "virnetdevhostdev.h" #include "virnetdevmacvlan.h" #include "virhostdev.h" #include "virmdev.h" @@ -28264,12 +28265,26 @@ virDomainNetFindByName(virDomainDefPtr def, const char *ifname) { size_t i; + size_t j; =20 for (i =3D 0; i < def->nnets; i++) { if (STREQ_NULLABLE(ifname, def->nets[i]->ifname)) return def->nets[i]; } =20 + /* Give a try to hostdev */ + for (i =3D 0; i < def->nhostdevs; i++) { + if (virNetdevHostdevCheckVFRIfName(def->hostdevs[i], ifname)) { + for (j =3D 0; j < def->nnets; j++) { + if (def->nets[j]->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) + continue; + if (memcmp(def->hostdevs[i], &def->nets[j]->data.hostdev, + sizeof(virDomainHostdevDef)) =3D=3D 0) + return def->nets[j]; + } + } + } + return NULL; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5c31dfdd5..f2f9d290b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -66,6 +66,7 @@ #include "virbuffer.h" #include "virhostcpu.h" #include "virhostmem.h" +#include "virnetdevhostdev.h" #include "virnetdevtap.h" #include "virnetdevopenvswitch.h" #include "capabilities.h" @@ -11156,6 +11157,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 (virNetdevHostdevVFRIfStats(device, stats, + !virDomainNetTypeSharesHostView(net= )) + < 0) + goto cleanup; } else { if (virNetDevTapInterfaceStats(net->ifname, stats, !virDomainNetTypeSharesHostView(net= )) < 0) @@ -19818,6 +19824,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver= ATTRIBUTE_UNUSED, { size_t i; struct _virDomainInterfaceStats tmp; + char *vf_ifname =3D NULL; int ret =3D -1; =20 if (!virDomainObjIsActive(dom)) @@ -19830,21 +19837,39 @@ 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) { + vf_ifname =3D virNetdevHostdevGetVFRIfName(dom->def->hostdevs[= i]); + if (!vf_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_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 (virNetdevHostdevVFRIfStats(vf_ifname, &tmp, + !virDomainNetTypeSharesHostView= (net)) < 0) { + VIR_FREE(vf_ifname); + virResetLastError(); + continue; + } + VIR_FREE(vf_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