On Sat, Jul 23, 2016 at 03:47:12AM +0200, Tomasz Flendrich wrote:
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;
+
There actually is a call that does what we need and it's this one ^ We
just need the number for buses (for some reason), which we can easily
eliminate in that function itself. All the information that the
functions below do is only needed when creating a new domain object as
all the information is saved there. So we don't need to call these,
neither have the calculation for the number of buses outside of that
function.
NACK to this approach, just fix qemuDomainPCIAddressSetCreate() itself
and use that in the later patch.