pci: Remove error reporting from PCI VPD parsing

The PCI VPD (Vital Product Data) may be missing or the kernel can report
presence but not actually have the data. Also the data is specified by
the device vendor and thus may be invalid in some cases.

To avoid log spamming, since the only usage in the node device driver is
ignoring errors, remove all error reporting.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/607
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-26 15:06:58 +01:00
parent 34f7ca668f
commit 0e566614ff
4 changed files with 11 additions and 43 deletions

View File

@ -3066,15 +3066,12 @@ virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev *devCapPCIDev)
if (!(pciDev = virPCIDeviceNew(&devAddr)))
return -1;
if (virPCIDeviceHasVPD(pciDev)) {
/* VPD is optional in PCI(e) specs. If it is there, attempt to add it. */
if ((res = virPCIDeviceGetVPD(pciDev))) {
devCapPCIDev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VPD;
devCapPCIDev->vpd = g_steal_pointer(&res);
} else {
virResetLastError();
}
/* VPD is optional in PCI(e) specs. If it is there, attempt to add it. */
if ((res = virPCIDeviceGetVPD(pciDev))) {
devCapPCIDev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VPD;
devCapPCIDev->vpd = g_steal_pointer(&res);
}
return 0;
}

View File

@ -3107,7 +3107,6 @@ virPCIDeviceGetUnbindFromStub;
virPCIDeviceGetUsedBy;
virPCIDeviceGetVPD;
virPCIDeviceHasPCIExpressLink;
virPCIDeviceHasVPD;
virPCIDeviceIsAssignable;
virPCIDeviceIsPCIExpress;
virPCIDeviceListAdd;

View File

@ -3078,24 +3078,14 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
}
bool
virPCIDeviceHasVPD(virPCIDevice *dev)
{
g_autofree char *vpdPath = virPCIFile(dev->name, "vpd");
bool ret = virFileIsRegular(vpdPath);
VIR_DEBUG("path='%s', exists='%d'", vpdPath, ret);
return ret;
}
/**
* virPCIDeviceGetVPD:
* @dev: a PCI device to get a PCI VPD for.
*
* Obtain a PCI device's Vital Product Data (VPD). VPD is optional in
* both PCI Local Bus and PCIe specifications so there is no guarantee it
* will be there for a particular device.
* will be there for a particular device. The VPD data is returned in @vpd if
* it's available or otherwise NULL is set.
*
* Returns: a pointer to virPCIVPDResource which needs to be freed by the caller
* or NULL if getting it failed for some reason (e.g. invalid format, I/O error).
@ -3104,26 +3094,16 @@ virPCIVPDResource *
virPCIDeviceGetVPD(virPCIDevice *dev)
{
g_autofree char *vpdPath = virPCIFile(dev->name, "vpd");
virPCIVPDResource *ret = NULL;
VIR_AUTOCLOSE fd = -1;
if (!virPCIDeviceHasVPD(dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Device %1$s does not have a VPD"),
virPCIDeviceGetName(dev));
return NULL;
}
fd = open(vpdPath, O_RDONLY);
if ((fd = open(vpdPath, O_RDONLY)) < 0) {
virReportSystemError(errno, _("Failed to open a VPD file '%1$s'"), vpdPath);
return NULL;
}
VIR_DEBUG("dev='%s' path='%s' fd='%d'", virPCIDeviceGetName(dev), vpdPath, fd);
if (!(ret = virPCIVPDParse(fd))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to parse device VPD data"));
if (fd < 0)
return NULL;
}
return ret;
return virPCIVPDParse(fd);
}
#else
@ -3200,17 +3180,10 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path G_GNUC_UNUSED,
return -1;
}
bool
virPCIDeviceHasVPD(virPCIDevice *dev G_GNUC_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return NULL;
}
virPCIVPDResource *
virPCIDeviceGetVPD(virPCIDevice *dev G_GNUC_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return NULL;
}
#endif /* __linux__ */

View File

@ -270,7 +270,6 @@ int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
char **pfname,
int *vf_index);
bool virPCIDeviceHasVPD(virPCIDevice *dev);
virPCIVPDResource * virPCIDeviceGetVPD(virPCIDevice *dev);
int virPCIDeviceUnbind(virPCIDevice *dev);