We can as well generate the number of buses inside that function. Fewer
parameters will be useful when recalculating the pci address set on
demand.
---
src/qemu/qemu_domain_address.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 70b6978..27ad54a 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -917,14 +917,24 @@ qemuDomainValidateDevicePCISlotsChipsets(virDomainDefPtr def,
static virDomainPCIAddressSetPtr
qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
- unsigned int nbuses,
virQEMUCapsPtr qemuCaps,
bool dryRun,
bool assign)
{
virDomainPCIAddressSetPtr addrs;
+ int max_idx = -1;
+ int nbuses = 0;
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 = virDomainPCIAddressSetAlloc(nbuses)) == NULL)
return NULL;
@@ -1493,7 +1503,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
virDomainDeviceInfo info;
/* 1st pass to figure out how many PCI bridges we need */
- if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps,
+ if (!(addrs = qemuDomainPCIAddressSetCreate(def, qemuCaps,
true, true)))
goto cleanup;
@@ -1530,7 +1540,6 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
virDomainPCIAddressReserveNextSlot(addrs, &info, flags) < 0)
goto cleanup;
}
- nbuses = addrs->nbuses;
virDomainPCIAddressSetFree(addrs);
addrs = NULL;
@@ -1542,7 +1551,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
}
if (qemuDomainSupportsPCI(def, qemuCaps)) {
- if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, qemuCaps,
+ if (!(addrs = qemuDomainPCIAddressSetCreate(def, qemuCaps,
false, true)))
goto cleanup;
--
1.9.1