The address sets (pci, ccw, virtio serial) are currently cached in qemu private data, but all the information required to recreate these sets is in the domain definition. Therefore I am removing the redundant data and adding a way to recalculate these sets. Add a function that calculates the pci address set from the domain definition. The part of pci address assignment that is not a dryRun is separated from qemuDomainAssignPCIAddresses into a new function: qemuDomainPCIAddrSetCreateFromDomain. The first time this function is run, it can allocate some new addresses. After all the pci addresses are assigned, on subsequent runs to this function, it just recreates the pci address set. --- src/qemu/qemu_domain_address.c | 48 +++++++++++++++++++++++++++++++++++------- src/qemu/qemu_domain_address.h | 5 +++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 66ab70e..add6fb5 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1424,6 +1424,45 @@ qemuDomainAddressFindNewBusNr(virDomainDefPtr def) return lowestBusNr - 2; } +virDomainPCIAddressSetPtr +qemuDomainPCIAddrSetCreateFromDomain(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) +{ + virDomainPCIAddressSetPtr addrs = NULL; + int max_idx = -1; + int nbuses = 0; + virDomainPCIAddressSetPtr ret = NULL; + size_t i; + + for (i = 0; i < def->ncontrollers; i++) { + if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if ((int) def->controllers[i]->idx > max_idx) + max_idx = def->controllers[i]->idx; + } + } + + nbuses = max_idx + 1; + + if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false))) + goto cleanup; + + if (qemuDomainSupportsPCI(def, qemuCaps)) { + if (qemuDomainValidateDevicePCISlotsChipsets(def, qemuCaps, + addrs) < 0) + goto cleanup; + + if (qemuDomainAssignDevicePCISlots(def, qemuCaps, addrs) < 0) + goto cleanup; + } + + ret = addrs; + addrs = NULL; + + cleanup: + virDomainPCIAddressSetFree(addrs); + + return ret; +} static int qemuDomainAssignPCIAddresses(virDomainDefPtr def, @@ -1506,17 +1545,10 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, goto cleanup; } - if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false))) + if (!(addrs = qemuDomainPCIAddrSetCreateFromDomain(def, qemuCaps))) goto cleanup; if (qemuDomainSupportsPCI(def, qemuCaps)) { - if (qemuDomainValidateDevicePCISlotsChipsets(def, qemuCaps, - addrs) < 0) - goto cleanup; - - if (qemuDomainAssignDevicePCISlots(def, qemuCaps, addrs) < 0) - goto cleanup; - for (i = 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont = def->controllers[i]; int idx = cont->idx; diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 11d6e92..546c57f 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -45,6 +45,11 @@ virDomainCCWAddressSetPtr qemuDomainCCWAddrSetCreateFromDomain(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); +virDomainPCIAddressSetPtr +qemuDomainPCIAddrSetCreateFromDomain(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + # define __QEMU_DOMAIN_ADDRESS_H__ #endif /* __QEMU_DOMAIN_ADDRESS_H__ */ -- 2.7.4 (Apple Git-66) -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list