From nobody Sun May 5 02:00:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638744918; cv=none; d=zohomail.com; s=zohoarc; b=mVpmWsHhzVz9EbBSLZLWqBxN3oajbe6OKdKDRX3DtKMF4MM5v8Mwkk+oZN5AoJMlb5Lo2QPzRDN5Z27S6WAmkRsWN3oJqeUECq5zG5HH22bManlPim1xX2RikwPcGTWGlPbNqv0vxcXFGBnvs1uAN4pdFDeHj2K3390vEiV0wk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638744918; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YzCaw5XdEb5fsQb/Mv+P4yK6hSDNF+ZvcZVzPRbqKrc=; b=OYC+DCnxpCazmgltxEIx39At8Qzv5TF1MLDAD5twFHMIzcoLnbQjdye4Y+c8BJPJpO2DUDJRmWE98/YVqVDiLmLM8MmJ4PG50SVv7XBmkbtQZMBOYPrhic5dPqtb+PD0PUwDy3C9RBH1mZXIcD9esyBt9luNnt7QnhDogDS3ee8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638744918524277.71814537320915; Sun, 5 Dec 2021 14:55:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-122-CHG0QsudNzqAeEtT3Dz1Og-1; Sun, 05 Dec 2021 17:55:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF7C01006AA2; Sun, 5 Dec 2021 22:55:11 +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 8323B22DEA; Sun, 5 Dec 2021 22:55:11 +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 51BD31809CBA; Sun, 5 Dec 2021 22:55:11 +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 1B5MsEIu032523 for ; Sun, 5 Dec 2021 17:54:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4299E5DAA5; Sun, 5 Dec 2021 22:54:14 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.16.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F7365DF2B for ; Sun, 5 Dec 2021 22:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638744917; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YzCaw5XdEb5fsQb/Mv+P4yK6hSDNF+ZvcZVzPRbqKrc=; b=TbkF6aDufntcD+JRhIZSOKDfmxyWcURZZWx14Id/vUHoe4VQ1dSutVgDGiiG89liejyYSV JLK8NdoEOwmJDBXqnDBOexWl3lWJJvK0oQw4PbwubsB+gI4auSnpzhi+B7/dyWvUiWZ+xM 7tpPNzyuqxr5AT/W+wVihTNfggTLWWo= X-MC-Unique: CHG0QsudNzqAeEtT3Dz1Og-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] util: fix erroneous requirement for phys_port_id to get ifname of a VF Date: Sun, 5 Dec 2021 17:54:09 -0500 Message-Id: <20211205225410.6822-2-laine@redhat.com> In-Reply-To: <20211205225410.6822-1-laine@redhat.com> References: <20211205225410.6822-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638744918890100001 Content-Type: text/plain; charset="utf-8" Commit 795e9e05c3 (libvirt-7.7.0) refactored the code in virpci.c and virnetdev.c that gathered lists of the Virtual Functions (VF) of an SRIOV Physical Function (PF) to simplify the code. Unfortunately the simplification made the assumption, in the new function virPCIGetVirtualFunctionsFull(), that a VF's netdev interface name should only be retrieved if the PF had a valid phys_port_id. That is an incorrect assumption - only a small handful of (now previous-generation) Mellanox SRIOV cards actually use phys_port_id (this is for an odd design where there are multiple physical network ports on a single PCI address); all other SRIOV cards (including new Mellanox cards) have a file in sysfs called phys_port_id, but it can't be read, and so the pfPhysPortID string is NULL. The result of this logic error is that virtual networks that are a pool of VFs to be used for macvtap connections will be unable to start, giving an errror like this: VF 0 of SRIOV PF enp130s0f0 couldn't be added to the interface pool becaus= e it isn't bound to a network driver - possibly in use elsewhere This error message is misinformed - the caller of virNetDevGetVirtualFunctionsFull() only *thinks* that the VF isn't bound to a network driver because it doesn't see a netdev name for the VF in the list. But that's only because virNetDevGetVirtualFunctionsFull() didn't even try to get the names! We do need a way for virPCIGetVirtualFunctionsFull() to sometimes retrieve the netdev names and sometimes not. One way of doing that would be to send down the netdev name of the PF whenever we also want to know the netdev names of the VFs, but send a NULL when we don't. This can conveniently be done by just *replacing* pfPhysPortID in the arglist with pfNetDevName - pfPhysPortID is determined by simply calling virNetDevGetPhysPortID(pfNetDevName) so we can just make that call down in virPCIGetVirtualFunctionsFull() (when needed). This solves the regression introduced by commit 795e9e05c3, and also nicely sets us up to (in a subsequent commit) move the call to virNetDevGetPhysPortID() down one layer further to virPCIGetNetName(), where it really belongs! Resolves: https://bugzilla.redhat.com/2025432 Fixes: 795e9e05c3b6b9ef3abe6f6078a6373a136ec23b Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virnetdev.c | 6 +----- src/util/virpci.c | 16 ++++++++++------ src/util/virpci.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 58f7360a0f..861b426c58 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1223,15 +1223,11 @@ virNetDevGetVirtualFunctions(const char *pfname, virPCIVirtualFunctionList **vfs) { g_autofree char *pf_sysfs_device_link =3D NULL; - g_autofree char *pfPhysPortID =3D NULL; - - if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - return -1; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) return -1; =20 - if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, vfs, pfPhysPor= tID) < 0) + if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, vfs, pfname) <= 0) return -1; =20 return 0; diff --git a/src/util/virpci.c b/src/util/virpci.c index 2d12e28004..f7afcb6e78 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2340,8 +2340,8 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, * virPCIGetVirtualFunctionsFull: * @sysfs_path: path to physical function sysfs entry * @vfs: filled with the virtual function data - * @pfPhysPortID: Optional physical port id. If provided the network inter= face - * name of the VFs is queried too. + * @pfNetDevName: Optional netdev name of this PF. If provided, the netdev + * names of the VFs are queried too. * * * Returns virtual functions of a physical function. @@ -2349,7 +2349,7 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, int virPCIGetVirtualFunctionsFull(const char *sysfs_path, virPCIVirtualFunctionList **vfs, - const char *pfPhysPortID) + const char *pfNetDevName) { g_autofree char *totalvfs_file =3D NULL; g_autofree char *totalvfs_str =3D NULL; @@ -2390,8 +2390,12 @@ virPCIGetVirtualFunctionsFull(const char *sysfs_path, return -1; } =20 - if (pfPhysPortID) { - if (virPCIGetNetName(device_link, 0, pfPhysPortID, &fnc.ifname= ) < 0) { + if (pfNetDevName) { + g_autofree char *pfPhysPortID =3D NULL; + + if (virNetDevGetPhysPortID(pfNetDevName, &pfPhysPortID) < 0 || + virPCIGetNetName(device_link, 0, pfPhysPortID, &fnc.ifname= ) < 0) { + g_free(fnc.addr); return -1; } @@ -2712,7 +2716,7 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path G= _GNUC_UNUSED, int virPCIGetVirtualFunctionsFull(const char *sysfs_path G_GNUC_UNUSED, virPCIVirtualFunctionList **vfs G_GNUC_UNUSE= D, - const char *pfPhysPortID G_GNUC_UNUSED) + const char *pfNetDevName G_GNUC_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); return -1; diff --git a/src/util/virpci.h b/src/util/virpci.h index 3346321ec9..7f332fc131 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -230,7 +230,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVirtualFunctionList= , virPCIVirtualFunctionLi =20 int virPCIGetVirtualFunctionsFull(const char *sysfs_path, virPCIVirtualFunctionList **vfs, - const char *pfPhysPortID); + const char *pfNetDevName); int virPCIGetVirtualFunctions(const char *sysfs_path, virPCIVirtualFunctionList **vfs); =20 --=20 2.33.1 From nobody Sun May 5 02:00:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638744876; cv=none; d=zohomail.com; s=zohoarc; b=V8dAQU1qilaFQgcOh8t+GeElMJ9G2LQppUnpq+KWpp+S5z/Rr/70KEUW+Rc9hx6TLfTTd36LZLeya7FKl5Ge/XH/Wt727c8GQ4sMSh0vBjG0nBN+RhV5awCquLV0z9NEeoM2dXd3HZRjKl12fk0OuuyiDdKAs7MuiNWY7V8sdf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638744876; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mHON1TYRaoB+XJFW1eLC7Gh+OsXZDjMn3yrC+odBQUk=; b=R+V7jXTmkuMSst4O2N58V/cWKshwjwMSM8HpUDJVXiEj1bwaPnOMO9Tz7FBJrCmBngS+aANQ812+H/9/sgZv2snLcvyXLCp2eU0VkTAdz1iQX7pQfrfNUqDftWTx/qtVa6Ha6/9G+dnbJAvyVSnbc7sCHkgl/HDGi7t9kcWV7D0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638744876388219.74398219093928; Sun, 5 Dec 2021 14:54:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-333-p0_a95O9MgOf5WbA1bvhSQ-1; Sun, 05 Dec 2021 17:54:33 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5E8081CCB4; Sun, 5 Dec 2021 22:54:23 +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 895EE1346F; Sun, 5 Dec 2021 22:54:21 +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 81E081809CB8; Sun, 5 Dec 2021 22:54:16 +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 1B5MsEiV032528 for ; Sun, 5 Dec 2021 17:54:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 93D45ADD5; Sun, 5 Dec 2021 22:54:14 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.16.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 626345DAA5 for ; Sun, 5 Dec 2021 22:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638744875; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mHON1TYRaoB+XJFW1eLC7Gh+OsXZDjMn3yrC+odBQUk=; b=dDt/XJJ2CsPEmkkxekDv5L0IFuwijoz94vsYo0oSD2Ln3LyGnfgC+kjmqBkW15vb/o6UOU 8rs0NSjxZVe9UcJv/hrfP5x2gWbBcG92C4KgDR7ASmLtLuEt3CeZFAmAOQKnFVklNCzV1i osn79pMADfpBWi9um8Im9hs7QfZaS4w= X-MC-Unique: p0_a95O9MgOf5WbA1bvhSQ-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] util: call virNetDevGetPhysPortID() in less places Date: Sun, 5 Dec 2021 17:54:10 -0500 Message-Id: <20211205225410.6822-3-laine@redhat.com> In-Reply-To: <20211205225410.6822-1-laine@redhat.com> References: <20211205225410.6822-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638744877842100001 Content-Type: text/plain; charset="utf-8" Whenever virPCIGetNetName() is called, it is either called with physPortID =3D NULL, or with it set by the caller calling virNetDevGetPhysPortID() soon before virPCIGetNetName(). The physPortID is then used *only* in virPCIGetNetName(). Rather than replicating that same call to virNetDevGetPhysPortID() in all the callers of virPCIGetNetName(), lets just have all those callers send the NetDevName whose physPortID they want down to virPCIGetNetName(), and let virPCIGetNetName() call virNetDevGetPhysPortID(). Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virnetdev.c | 18 ++--------------- src/util/virpci.c | 48 +++++++++++++++++++++++++------------------- src/util/virpci.h | 2 +- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 861b426c58..d93b2c6a83 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1297,18 +1297,12 @@ int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { g_autofree char *physfn_sysfs_path =3D NULL; - g_autofree char *vfPhysPortID =3D NULL; - - if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) - return -1; =20 if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) return -1; =20 - if (virPCIGetNetName(physfn_sysfs_path, 0, - vfPhysPortID, pfname) < 0) { + if (virPCIGetNetName(physfn_sysfs_path, 0, ifname, pfname) < 0) return -1; - } =20 return 0; } @@ -1336,14 +1330,6 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) { g_autofree char *virtfnName =3D NULL; g_autofree char *virtfnSysfsPath =3D NULL; - g_autofree char *pfPhysPortID =3D NULL; - - /* a VF may have multiple "ports", each one having its own netdev, - * and each netdev having a different phys_port_id. Be sure we get - * the VF netdev with a phys_port_id matchine that of pfname - */ - if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - return -1; =20 virtfnName =3D g_strdup_printf("virtfn%d", vf); =20 @@ -1360,7 +1346,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **v= fname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); + return virPCIGetNetName(virtfnSysfsPath, 0, pfname, vfname); } =20 =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index f7afcb6e78..0d476cd8b4 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2390,15 +2390,10 @@ virPCIGetVirtualFunctionsFull(const char *sysfs_pat= h, return -1; } =20 - if (pfNetDevName) { - g_autofree char *pfPhysPortID =3D NULL; - - if (virNetDevGetPhysPortID(pfNetDevName, &pfPhysPortID) < 0 || - virPCIGetNetName(device_link, 0, pfPhysPortID, &fnc.ifname= ) < 0) { - - g_free(fnc.addr); - return -1; - } + if (pfNetDevName && + virPCIGetNetName(device_link, 0, pfNetDevName, &fnc.ifname) < = 0) { + g_free(fnc.addr); + return -1; } =20 VIR_APPEND_ELEMENT(list->functions, list->nfunctions, fnc); @@ -2474,8 +2469,20 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress = *addr, * @device_link_sysfs_path: sysfs path to the PCI device * @idx: used to choose which netdev when there are several * (ignored if physPortID is set or physPortName is available) - * @physPortID: match this string in the netdev's phys_port_id - * (or NULL to ignore and use phys_port_name or idx instead) + + * @physPortNetDevName: if non-null, attempt to learn the phys_port_id + * of the netdev interface named + * @physPortNetDevName, and find a netdev for + * this PCI device that has the same + * phys_port_id. if @physPortNetDevName is NULL, + * or has no phys_port_id, then use + * phys_port_name or idx to determine which + * netdev to return. (NB: as of today, only mlx + * drivers/cards can have multiple phys_ports for + * a single PCI device; on all other devices + * there is only a single choice of netdev, and + * phys_port_id, phys_port_name, and idx are + * unavailable/unused) * @netname: used to return the name of the netdev * (set to NULL (but returns success) if there is no netdev) * @@ -2484,9 +2491,10 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress = *addr, int virPCIGetNetName(const char *device_link_sysfs_path, size_t idx, - const char *physPortID, + const char *physPortNetDevName, char **netname) { + g_autofree char *physPortID =3D NULL; g_autofree char *pcidev_sysfs_net_path =3D NULL; g_autofree char *firstEntryName =3D NULL; g_autoptr(DIR) dir =3D NULL; @@ -2495,6 +2503,11 @@ virPCIGetNetName(const char *device_link_sysfs_path, =20 *netname =3D NULL; =20 + if (physPortNetDevName && + virNetDevGetPhysPortID(physPortNetDevName, &physPortID) < 0) { + return -1; + } + virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path, "net"); =20 if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) { @@ -2585,7 +2598,6 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_dev= ice_path, g_autofree virPCIDeviceAddress *pf_config_address =3D NULL; g_autofree char *pf_sysfs_device_path =3D NULL; g_autofree char *vfname =3D NULL; - g_autofree char *vfPhysPortID =3D NULL; =20 if (virPCIGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address= ) < 0) return -1; @@ -2614,17 +2626,11 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_d= evice_path, if (virPCIGetNetName(vf_sysfs_device_path, 0, NULL, &vfname) < 0) return -1; =20 - if (vfname) { - if (virNetDevGetPhysPortID(vfname, &vfPhysPortID) < 0) - return -1; - } pfNetDevIdx =3D 0; } =20 - if (virPCIGetNetName(pf_sysfs_device_path, - pfNetDevIdx, vfPhysPortID, pfname) < 0) { + if (virPCIGetNetName(pf_sysfs_device_path, pfNetDevIdx, vfname, pfname= ) < 0) return -1; - } =20 if (!*pfname) { /* this shouldn't be possible. A VF can't exist unless its @@ -2751,7 +2757,7 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress *= dev G_GNUC_UNUSED, int virPCIGetNetName(const char *device_link_sysfs_path G_GNUC_UNUSED, size_t idx G_GNUC_UNUSED, - const char *physPortID G_GNUC_UNUSED, + const char *physPortNetDevName G_GNUC_UNUSED, char **netname G_GNUC_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); diff --git a/src/util/virpci.h b/src/util/virpci.h index 7f332fc131..b9b9cd7b34 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -245,7 +245,7 @@ int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress= *addr, =20 int virPCIGetNetName(const char *device_link_sysfs_path, size_t idx, - const char *physPortID, + const char *physPortNetDevName, char **netname); =20 bool virPCIDeviceAddressIsValid(virPCIDeviceAddress *addr, --=20 2.33.1