]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Deal with PHB naming conventions
authorAndrea Bolognani <abologna@redhat.com>
Wed, 1 Mar 2017 14:49:31 +0000 (15:49 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Sat, 15 Jul 2017 12:50:42 +0000 (14:50 +0200)
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 <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
src/qemu/qemu_command.c

index 3c84246d212747a94f429ce401b988d241145632..37cacffcdb7158159a3fa6350a20acf9458b6fb0 100644 (file)
@@ -303,6 +303,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;
@@ -315,6 +317,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 "
@@ -350,7 +354,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");