diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 0346471ea4..d3a2f6f23e 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -493,6 +493,12 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr addrs, int ret = -1; char *addrStr = NULL; + /* if flags is 0, the particular model of this device on this + * machinetype doesn't need a PCI address, so we're done. + */ + if (!flags) + return 0; + if (!(addrStr = virDomainPCIAddressAsString(&dev->addr.pci))) goto cleanup; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 4cdff7a57d..4c688b1898 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -467,8 +467,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2: /* xen only */ case VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE: case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_CONTROLLER_TYPE_IDE: @@ -497,8 +496,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, */ if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV || STREQ(net->model, "usb-net")) { - /* should be 0 */ - return pciFlags; + return 0; } return pciFlags; } @@ -515,8 +513,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_SOUND_MODEL_PCSPK: case VIR_DOMAIN_SOUND_MODEL_USB: case VIR_DOMAIN_SOUND_MODEL_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_DISK: @@ -533,8 +530,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_DISK_BUS_SATA: case VIR_DOMAIN_DISK_BUS_SD: case VIR_DOMAIN_DISK_BUS_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_HOSTDEV: @@ -548,8 +544,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_MEMBALLOON_MODEL_XEN: case VIR_DOMAIN_MEMBALLOON_MODEL_NONE: case VIR_DOMAIN_MEMBALLOON_MODEL_LAST: - /* should be 0 (not PCI) */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_RNG: @@ -558,8 +553,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, return pciFlags; case VIR_DOMAIN_RNG_MODEL_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_WATCHDOG: @@ -571,8 +565,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_WATCHDOG_MODEL_IB700: case VIR_DOMAIN_WATCHDOG_MODEL_DIAG288: case VIR_DOMAIN_WATCHDOG_MODEL_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_VIDEO: @@ -588,8 +581,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, return pciFlags; case VIR_DOMAIN_VIDEO_TYPE_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_SHMEM: @@ -605,8 +597,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_INPUT_BUS_XEN: case VIR_DOMAIN_INPUT_BUS_PARALLELS: case VIR_DOMAIN_INPUT_BUS_LAST: - /* should be 0 */ - return pciFlags; + return 0; } case VIR_DOMAIN_DEVICE_CHR: @@ -617,8 +608,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: - /* should be 0 */ - return pciFlags; + return 0; } /* These devices don't ever connect with PCI */ @@ -635,8 +625,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: - /* should be 0 */ - return pciFlags; + return 0; } /* We can never get here, because all cases are covered in the @@ -816,6 +805,28 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED, return 0; } + /* If we get to here, the device has a PCI address assigned in the + * config and we should mark it as in-use. But if the + * pciConnectFlags are 0, then this device shouldn't have a PCI + * address associated with it. *BUT* since there are cases in the + * past where we've apparently allowed that, we need to pretend + * for now that it's okay, otherwise an existing domain could + * "disappear" from the list of domains due to a parse failure. We + * can fix this by just forcing the pciConnectFlags to be + * PCI_DEVICE (and then relying on validation functions to report + * inappropriate address types. + */ + if (!info->pciConnectFlags) { + char *addrStr = virDomainPCIAddressAsString(&info->addr.pci); + + VIR_WARN("qemuDomainDeviceCalculatePCIConnectFlags() thinks that the " + "device with PCI address %s should not have a PCI address", + addrStr ? addrStr : "(unknown)"); + VIR_FREE(addrStr); + + info->pciConnectFlags = VIR_PCI_CONNECT_TYPE_PCI_DEVICE; + } + /* Ignore implicit controllers on slot 0:0:1.0: * implicit IDE controller on 0:0:1.1 (no qemu command line) * implicit USB controller on 0:0:1.2 (-usb)