With a parameter, we can show whether we want qemuDomainValidateDevicePCISlotsChipsets to assign new addresses or simply verify the existing ones and reserve slots for potential future devices. If the parameter is false and some device is missing an address, a warning will be displayed. The PCI address set will be recalculated instead of being cached, and during recalculation all the addresses should have already been assigned. --- src/qemu/qemu_domain_address.c | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 2e19905..70b6978 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -542,7 +542,8 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED, static int qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virDomainPCIAddressSetPtr addrs) + virDomainPCIAddressSetPtr addrs, + bool assign) { int ret = -1; size_t i; @@ -567,6 +568,10 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, goto cleanup; } } else { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; def->controllers[i]->info.addr.pci.domain = 0; def->controllers[i]->info.addr.pci.bus = 0; @@ -587,6 +592,10 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, goto cleanup; } } else { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; def->controllers[i]->info.addr.pci.domain = 0; def->controllers[i]->info.addr.pci.bus = 0; @@ -615,6 +624,10 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, */ virDomainVideoDefPtr primaryVideo = def->videos[0]; if (virDeviceInfoPCIAddressWanted(&primaryVideo->info)) { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 2; @@ -676,7 +689,8 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, static int qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virDomainPCIAddressSetPtr addrs) + virDomainPCIAddressSetPtr addrs, + bool assign) { int ret = -1; size_t i; @@ -703,6 +717,10 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, goto cleanup; } } else { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; def->controllers[i]->info.addr.pci.domain = 0; def->controllers[i]->info.addr.pci.bus = 0; @@ -726,18 +744,22 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, * get assigned to the same slot as the UHCI1 when * addresses are later assigned to all devices.) */ - bool assign = false; + bool assignUSB = false; memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 0x1D; if (!virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { - assign = true; + assignUSB = true; } else { tmp_addr.slot = 0x1A; if (!virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) - assign = true; + assignUSB = true; } - if (assign) { + if (assignUSB) { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, false, true) < 0) goto cleanup; @@ -763,6 +785,10 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 0x1E; if (!virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, true, false) < 0) goto cleanup; @@ -806,6 +832,10 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, */ virDomainVideoDefPtr primaryVideo = def->videos[0]; if (virDeviceInfoPCIAddressWanted(&primaryVideo->info)) { + if (!assign) { + VIR_WARN("During PCI address set recalculation " + "no new addresses should be assigned."); + } memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 1; @@ -868,15 +898,16 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, static int qemuDomainValidateDevicePCISlotsChipsets(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, - virDomainPCIAddressSetPtr addrs) + virDomainPCIAddressSetPtr addrs, + bool assign) { if (qemuDomainMachineIsI440FX(def) && - qemuDomainValidateDevicePCISlotsPIIX3(def, qemuCaps, addrs) < 0) { + qemuDomainValidateDevicePCISlotsPIIX3(def, qemuCaps, addrs, assign) < 0) { return -1; } if (qemuDomainMachineIsQ35(def) && - qemuDomainValidateDevicePCISlotsQ35(def, qemuCaps, addrs) < 0) { + qemuDomainValidateDevicePCISlotsQ35(def, qemuCaps, addrs, assign) < 0) { return -1; } @@ -888,7 +919,8 @@ static virDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def, unsigned int nbuses, virQEMUCapsPtr qemuCaps, - bool dryRun) + bool dryRun, + bool assign) { virDomainPCIAddressSetPtr addrs; size_t i; @@ -936,7 +968,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, goto error; if (qemuDomainValidateDevicePCISlotsChipsets(def, qemuCaps, - addrs) < 0) + addrs, assign) < 0) goto error; return addrs; @@ -1461,7 +1493,8 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, virDomainDeviceInfo info; /* 1st pass to figure out how many PCI bridges we need */ - if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps, true))) + if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps, + true, true))) goto cleanup; for (i = 0; i < addrs->nbuses; i++) { @@ -1509,7 +1542,8 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, } if (qemuDomainSupportsPCI(def, qemuCaps)) { - if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps, false))) + if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps, + false, true))) goto cleanup; if (qemuDomainAssignDevicePCISlots(def, qemuCaps, addrs) < 0) -- 1.9.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list