From f55694fe90cc25e228bd2f779c600d739aec508e Mon Sep 17 00:00:00 2001 Message-Id: From: Andrea Bolognani Date: Mon, 17 Jul 2017 12:09:12 +0200 Subject: [PATCH] qemu: Deal with PHB naming conventions Usually, a controller with alias 'x' will create a bus with the same name; however, the bus created by a PHBs with alias 'x' will be named 'x.0' instead, so we need to account for that. As an exception to the exception, the implicit PHB that's added automatically to every pSeries guest creates the 'pci.0' bus. Signed-off-by: Andrea Bolognani Reviewed-by: Laine Stump (cherry picked from commit 32f23b8d30f13c154fba6673b1b42b164c162f8a) Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1431193 Signed-off-by: Andrea Bolognani Signed-off-by: Jiri Denemark --- src/qemu/qemu_command.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a067aaeb17..0176f0d63f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -301,6 +301,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, int ret = -1; char *devStr = NULL; const char *contAlias = NULL; + bool contIsPHB = false; + int contTargetIndex = 0; if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { size_t i; @@ -313,6 +315,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI && cont->idx == info->addr.pci.bus) { contAlias = cont->info.alias; + contIsPHB = virDomainControllerIsPCIHostBridge(cont); + contTargetIndex = cont->opts.pciopts.targetIndex; if (!contAlias) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Device alias was not set for PCI " @@ -348,7 +352,17 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, } } - virBufferAsprintf(buf, ",bus=%s", contAlias); + if (contIsPHB && contTargetIndex > 0) { + /* The PCI bus created by a spapr-pci-host-bridge device with + * alias 'x' will be called 'x.0' rather than 'x'; however, + * this does not apply to the implicit PHB in a pSeries guest, + * which always has the hardcoded name 'pci.0' */ + virBufferAsprintf(buf, ",bus=%s.0", contAlias); + } else { + /* For all other controllers, the bus name matches the alias + * of the corresponding controller */ + virBufferAsprintf(buf, ",bus=%s", contAlias); + } if (info->addr.pci.multi == VIR_TRISTATE_SWITCH_ON) virBufferAddLit(buf, ",multifunction=on"); -- 2.13.3