The bus name for the default PHB is always "pci.0".
Fixes: 937f319536723fec57ad472b002a159d0f67a77c
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_command.c | 23 ++++++++++++++++---
.../pseries-phb-user-alias.ppc64-latest.args | 2 +-
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 712feb7b81..f2a4e1088b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -366,9 +366,26 @@ qemuBuildDeviceAddressPCIGetBus(const virDomainDef *domainDef,
if (virDomainDeviceAliasIsUserAlias(contAlias)) {
/* When domain has builtin pci-root controller we don't put it
* onto cmd line. Therefore we can't set its alias. In that
- * case, use the default one. */
- if (!qemuDomainIsPSeries(domainDef) &&
- cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) {
+ * case, use the default one.
+ *
+ * Note that we have to check the value of targetIndex here,
+ * because we need to handle three different cases:
+ *
+ * non-pSeries guest (targetIndex == -1)
+ * => must use default alias
+ *
+ * pSeries guest, default PHB (targetIndex == 0)
+ * => must use default alias
+ *
+ * pSeries guest, non-default PHB (targetIndex > 0)
+ * => can use actual alias
+ *
+ * The last one is due to non-default PHBs beind created
+ * through the spapr-pci-host-bridge device, which supports
+ * custom device IDs and thus custom bus names.
+ * */
+ if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT &&
+ contTargetIndex <= 0) {
if (virQEMUCapsHasPCIMultiBus(domainDef))
contAlias = "pci.0";
else
diff --git a/tests/qemuxml2argvdata/pseries-phb-user-alias.ppc64-latest.args
b/tests/qemuxml2argvdata/pseries-phb-user-alias.ppc64-latest.args
index e64fc9aa11..8a2be8cf0c 100644
--- a/tests/qemuxml2argvdata/pseries-phb-user-alias.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/pseries-phb-user-alias.ppc64-latest.args
@@ -28,7 +28,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-boot strict=on \
-device
'{"driver":"spapr-pci-host-bridge","index":1,"id":"ua-phb1"}'
\
-netdev user,id=hostnet0 \
--device
'{"driver":"virtio-net-pci","netdev":"hostnet0","id":"net0","mac":"52:54:00:a2:44:92","bus":"ua-phb0","addr":"0x1"}'
\
+-device
'{"driver":"virtio-net-pci","netdev":"hostnet0","id":"net0","mac":"52:54:00:a2:44:92","bus":"pci.0","addr":"0x1"}'
\
-netdev user,id=hostnet1 \
-device
'{"driver":"virtio-net-pci","netdev":"hostnet1","id":"net1","mac":"52:54:00:a2:44:93","bus":"ua-phb1.0","addr":"0x1"}'
\
-audiodev
'{"id":"audio1","driver":"none"}' \
--
2.43.0