The flag was set if virPCIGetPhysicalFunction() did not return
an error; unfortunately, the 'physfn' sysfs file not being
present is not considered an error, which means that the flag
was set pretty much unconditionally.
This, in turn, caused libvirtd to crash in
virNodeDeviceDefFormat(), where the presence of the flag
is considered a reliable indicator of the fact that
pci_dev.physical_function has been filled in.
Change the code to check pci_dev.physical_function before
setting the flag.
---
src/node_device/node_device_linux_sysfs.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/node_device/node_device_linux_sysfs.c
b/src/node_device/node_device_linux_sysfs.c
index 24a6a2e..b337d2d 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -154,19 +154,25 @@ nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath,
data->pci_dev.flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
data->pci_dev.flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
- if (!virPCIGetPhysicalFunction(sysfsPath, &data->pci_dev.physical_function))
+ ret = virPCIGetPhysicalFunction(sysfsPath,
+ &data->pci_dev.physical_function);
+ if (ret < 0)
+ goto out;
+
+ if (data->pci_dev.physical_function)
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
ret = virPCIGetVirtualFunctions(sysfsPath, &data->pci_dev.virtual_functions,
&data->pci_dev.num_virtual_functions,
&data->pci_dev.max_virtual_functions);
if (ret < 0)
- return ret;
+ goto out;
if (data->pci_dev.num_virtual_functions > 0 ||
data->pci_dev.max_virtual_functions > 0)
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
+ out:
return ret;
}
--
2.5.5