From 0726878297c75da15052df3b16d76c7abfd76013 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Thu, 25 Jun 2015 12:02:32 -0400 Subject: [PATCH] qemu: reorganize loop in qemuDomainAssignPCIAddresses This loop occurs just after we've assured that all devices that require a PCI device have been assigned and all necessary PCI controllers have been added. It is the perfect place to add other potentially auto-generated PCI controller attributes that are dependent on the controller's PCI address (upcoming patch). There is a convenient loop through all controllers at the end of the function, but the patch to add new functionality will be cleaner if we first rearrange that loop a bit. Note that the loop originally was accessing info.addr.pci.bus prior to determining that the pci part of the object was valid. This isn't dangerous in any way, but seemed a bit ugly, so I fixed it. --- src/qemu/qemu_command.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 42906a898b..09f30c40e7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2248,20 +2248,24 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, goto cleanup; for (i = 0; i < def->ncontrollers; i++) { + virDomainControllerDefPtr cont = def->controllers[i]; + int idx = cont->idx; + virDevicePCIAddressPtr addr; + + if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_PCI) + continue; + + addr = &cont->info.addr.pci; /* check if every PCI bridge controller's ID is greater than * the bus it is placed onto */ - virDomainControllerDefPtr cont = def->controllers[i]; - int idx = cont->idx; - int bus = cont->info.addr.pci.bus; - if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI && - cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE && - idx <= bus) { + if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE && + idx <= addr->bus) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("failed to create PCI bridge " "on bus %d: too many devices with fixed " "addresses"), - bus); + addr->bus); goto cleanup; } } -- GitLab