From nobody Fri May 3 02:42:39 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1505494403825476.8706551205703; Fri, 15 Sep 2017 09:53:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E821CC070E2B; Fri, 15 Sep 2017 16:53:19 +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 3A0736BF61; Fri, 15 Sep 2017 16:53:19 +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 2ED8F410B7; Fri, 15 Sep 2017 16:53:18 +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 v8FFnEPh026793 for ; Fri, 15 Sep 2017 11:49:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D4DD6942B; Fri, 15 Sep 2017 15:49:14 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-231.phx2.redhat.com [10.3.116.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B31562462 for ; Fri, 15 Sep 2017 15:49:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E821CC070E2B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E821CC070E2B From: Laine Stump To: libvir-list@redhat.com Date: Fri, 15 Sep 2017 11:49:00 -0400 Message-Id: <20170915154900.10321-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: virPCIGetNetName(): use first netdev name when phys_port_id isn't matched 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 15 Sep 2017 16:53:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The mlx4 (Mellanox) netdev driver implements the sysfs phys_port_id file for both VFs and PFs, so you can find the VF netdev plugged into the same physical port as any given PF netdev by comparing the contents of phys_port_id of the respective netdevs. That's what libvirt does when attempting to find the PF netdev for a given VF netdev (or vice versa). Most other netdevs drivers don't implement phys_port_id, so the file shows up in sysfs, but attempts to read it result in ENOTSUPP. In these cases, libvirt is unable to read phys_port_id, so it just returns the first entry in the PF/VF's list of netdevs. But we've found that the i40e driver is in between these two situations - it implements phys_port_id for PF netdevs, but doesn't implement it for VF netdevs. So libvirt would successfully read the phys_port_id of the PF netdev, then try to find a VF netdev with matching phys_port_id, but would fail because it is NULL for all VFs. This would result in a message like the following: Could not find network device with phys_port_id '3cfdfe9edc39' under PCI device at /sys/class/net/ens4f1/device/virtfn0 To solve this problem in a way that won't break functionality for anyone else, this patch saves the first netdev name we find for the device, and returns that if we fail to find a netdev with the desired phys_port_id. --- src/util/virpci.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 5ded77087..402602678 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2876,6 +2876,7 @@ virPCIGetNetName(const char *device_link_sysfs_path, int ret =3D -1; DIR *dir =3D NULL; struct dirent *entry =3D NULL; + char *firstEntryName =3D NULL; char *thisPhysPortID =3D NULL; size_t i =3D 0; =20 @@ -2902,6 +2903,15 @@ virPCIGetNetName(const char *device_link_sysfs_path, /* if this one doesn't match, keep looking */ if (STRNEQ_NULLABLE(physPortID, thisPhysPortID)) { VIR_FREE(thisPhysPortID); + /* save the first entry we find to use as a failsafe + * in case we don't match the phys_port_id. This is + * needed because some NIC drivers (e.g. i40e) + * implement phys_port_id for PFs, but not for VFs + */ + if (!firstEntryName && + VIR_STRDUP(firstEntryName, entry->d_name) < 0) + goto cleanup; + continue; } } else { @@ -2918,10 +2928,21 @@ virPCIGetNetName(const char *device_link_sysfs_path, =20 if (ret < 0) { if (physPortID) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find network device with " - "phys_port_id '%s' under PCI device at %s"), - physPortID, device_link_sysfs_path); + if (firstEntryName) { + /* we didn't match the provided phys_port_id, but this + * is probably because phys_port_id isn't implemented + * for this NIC driver, so just return the first + * (probably only) netname we found. + */ + *netname =3D firstEntryName; + firstEntryName =3D NULL; + ret =3D 0; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find network device with " + "phys_port_id '%s' under PCI device at %s= "), + physPortID, device_link_sysfs_path); + } } else { ret =3D 0; /* no netdev at the given index is *not* an error */ } @@ -2930,6 +2951,7 @@ virPCIGetNetName(const char *device_link_sysfs_path, VIR_DIR_CLOSE(dir); VIR_FREE(pcidev_sysfs_net_path); VIR_FREE(thisPhysPortID); + VIR_FREE(firstEntryName); return ret; } =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list