From nobody Wed Feb 11 10:17:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1489178321822948.8776704417368; Fri, 10 Mar 2017 12:38:41 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AKZNiB039275; Fri, 10 Mar 2017 15:35:23 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2AKZKo7018964 for ; Fri, 10 Mar 2017 15:35:20 -0500 Received: from vhost2.laine.org (ovpn-116-174.phx2.redhat.com [10.3.116.174]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AKZHid012172 for ; Fri, 10 Mar 2017 15:35:20 -0500 From: Laine Stump To: libvir-list@redhat.com Date: Fri, 10 Mar 2017 15:34:59 -0500 Message-Id: <20170310203512.15478-7-laine@laine.org> In-Reply-To: <20170310203512.15478-1-laine@laine.org> References: <20170310203512.15478-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/19] util: change virPCIGetNetName() to not return error if device has no net 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" ...and cleanup the callers to report it when it *is* an error. In many cases It's useful for virPCIGetNetName() to not log an error and simply return a NULL pointer when the given device isn't bound to a net driver (e.g. we're looking at a VF that is permanently bound to vfio-pci). The existing code would silently return an error in this case, which could eventually lead to the dreaded "An error occurred but the cause is unknown" log message. This patch changes virPCIGetNetName() to still return success if the device simply isn't bound to a net driver, and adjusts all the callers that require a non-null netname to check for that condition and log an error when it happens. --- src/util/virhostdev.c | 13 +++++++++++++ src/util/virnetdev.c | 19 +++++++++++++++++-- src/util/virpci.c | 30 ++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a967182..7292cf4 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -317,8 +317,21 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, ch= ar **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, 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; } =20 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 30a4a01..766638d 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1162,6 +1162,9 @@ virNetDevGetVirtualFunctions(const char *pfname, } =20 if (virPCIGetNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) + goto cleanup; + + if (!(*vfname)[i]) VIR_INFO("VF does not have an interface name"); } =20 @@ -1258,10 +1261,22 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) return ret; =20 - ret =3D virPCIGetNetName(physfn_sysfs_path, pfname); + if (virPCIGetNetName(physfn_sysfs_path, pfname) < 0) + goto cleanup; =20 - VIR_FREE(physfn_sysfs_path); + if (!*pfname) { + /* this shouldn't be possible. A VF can't exist unless its + * PF device is bound to a network driver + */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("The PF device for VF %s has no network device na= me"), + ifname); + goto cleanup; + } =20 + ret =3D 0; + cleanup: + VIR_FREE(physfn_sysfs_path); return ret; } =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index 3c1e13b..337afda 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2854,8 +2854,11 @@ virPCIGetNetName(char *device_link_sysfs_path, char = **netname) return -1; } =20 - if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) + if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) { + /* this *isn't* an error - caller needs to check for netname =3D= =3D NULL */ + ret =3D 0; goto out; + } =20 while (virDirRead(dir, &entry, pcidev_sysfs_net_path) > 0) { /* Assume a single directory entry */ @@ -2881,24 +2884,35 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_d= evice_path, int ret =3D -1; =20 if (virPCIGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address= ) < 0) - return ret; + goto cleanup; =20 if (!pf_config_address) - return ret; + goto cleanup; =20 if (virPCIDeviceAddressGetSysfsFile(pf_config_address, &pf_sysfs_device_path) < 0) { + goto cleanup; + } =20 - VIR_FREE(pf_config_address); - return ret; + if (virPCIGetVirtualFunctionIndex(pf_sysfs_device_path, + vf_sysfs_device_path, vf_index) < 0)= { + goto cleanup; } =20 - if (virPCIGetVirtualFunctionIndex(pf_sysfs_device_path, vf_sysfs_devic= e_path, - vf_index) < 0) + if (virPCIGetNetName(pf_sysfs_device_path, pfname) < 0) goto cleanup; =20 - ret =3D virPCIGetNetName(pf_sysfs_device_path, pfname); + if (!*pfname) { + /* this shouldn't be possible. A VF can't exist unless its + * PF device is bound to a network driver + */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("The PF device for VF %s has no network device na= me"), + vf_sysfs_device_path); + goto cleanup; + } =20 + ret =3D 0; cleanup: VIR_FREE(pf_config_address); VIR_FREE(pf_sysfs_device_path); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list