[PATCH 26/33] domain_conf.c: reject duplicated pnv-phb3 devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These devices must have unique targetIndex/chip-id pairs.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c                      | 35 +++++++++++++++++++++
 tests/qemuxml2argvdata/powernv8-dupPHBs.err |  1 +
 tests/qemuxml2argvdata/powernv8-dupPHBs.xml | 27 ++++++++++++++++
 tests/qemuxml2argvtest.c                    |  3 ++
 4 files changed, 66 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/powernv8-dupPHBs.err
 create mode 100644 tests/qemuxml2argvdata/powernv8-dupPHBs.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8e44e4b53c..442b3812b7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2481,6 +2481,33 @@ virDomainControllerIsPowerNVRootPort(const virDomainControllerDef *cont)
 }
 
 
+/* Caller must ensure that 'cont' is a PowerNV PHB device */
+static bool
+virDomainControllerDuplicatedPHB(virDomainDef *def,
+                                 virDomainControllerDef *cont)
+{
+    int chipId = cont->opts.pciopts.chipId;
+    int targetIndex = cont->opts.pciopts.targetIndex;
+    size_t i;
+
+    for (i = 0; i < def->ncontrollers; i++) {
+        virDomainControllerDef *cont2 = def->controllers[i];
+
+        if (!virDomainControllerIsPowerNVPHB(cont2))
+            continue;
+
+        if (cont2 == cont)
+            continue;
+
+        if (cont2->opts.pciopts.chipId == chipId &&
+            cont2->opts.pciopts.targetIndex == targetIndex)
+            return true;
+    }
+
+    return false;
+}
+
+
 virDomainFSDef *
 virDomainFSDefNew(virDomainXMLOption *xmlopt)
 {
@@ -4737,6 +4764,14 @@ virDomainDefRejectDuplicateControllers(virDomainDef *def)
                            cont->idx);
             goto cleanup;
         }
+
+        if (virDomainControllerIsPowerNVPHB(cont) &&
+            virDomainControllerDuplicatedPHB(def, cont)) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("Multiple pnv-phb controllers with same chip-id and index"));
+            goto cleanup;
+        }
+
         ignore_value(virBitmapSetBit(bitmaps[cont->type], cont->idx));
     }
 
diff --git a/tests/qemuxml2argvdata/powernv8-dupPHBs.err b/tests/qemuxml2argvdata/powernv8-dupPHBs.err
new file mode 100644
index 0000000000..bc5879640d
--- /dev/null
+++ b/tests/qemuxml2argvdata/powernv8-dupPHBs.err
@@ -0,0 +1 @@
+XML error: Multiple pnv-phb controllers with same chip-id and index
diff --git a/tests/qemuxml2argvdata/powernv8-dupPHBs.xml b/tests/qemuxml2argvdata/powernv8-dupPHBs.xml
new file mode 100644
index 0000000000..43ee3051eb
--- /dev/null
+++ b/tests/qemuxml2argvdata/powernv8-dupPHBs.xml
@@ -0,0 +1,27 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>b20fcfe3-4a0a-4039-8735-9e024256e0f7</uuid>
+  <memory unit='KiB'>2097152</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='powernv8'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+    <controller type='pci' index='0' model='pcie-root'>
+      <model name='pnv-phb3'/>
+      <target index='0' chip-id='0'/>
+    </controller>
+    <controller type='pci' index='1' model='pcie-root'>
+      <model name='pnv-phb3'/>
+      <target index='1' chip-id='0'/>
+    </controller>
+    <controller type='pci' index='2' model='pcie-root'>
+      <model name='pnv-phb3'/>
+      <target index='1' chip-id='0'/>
+    </controller>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a0bc5ed169..ff8698927e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2224,6 +2224,9 @@ mymain(void)
             QEMU_CAPS_DEVICE_ISA_SERIAL,
             QEMU_CAPS_DEVICE_PNV_PHB3,
             QEMU_CAPS_DEVICE_PNV_PHB3_ROOT_PORT);
+    DO_TEST_PARSE_ERROR("powernv8-dupPHBs",
+                        QEMU_CAPS_DEVICE_ISA_SERIAL,
+                        QEMU_CAPS_DEVICE_PNV_PHB3);
 
     DO_TEST("pseries-basic",
             QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux