[PATCH 03/51] qemu: capabilities: Preserve location of the default machine type when stripping aliases for tests

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

 



Internally the preferred machine which is 'pc' for x86_64 must be kept
in the first place in the array of machines. This was not the case when
stripping the machine aliases for use in tests (so that test output
stays stable) where we've created a new entry for the alias. This means
that the original name (e.g. pc-i440fx-8.1) stayed in the first place.

To fix this we now swap the names around and create a new entry at the
end for the specific type. Additionally the default flag is not
propagated to the copy.

This is also visible now in the output of 'qemuxml2xmltest' as the test
cases which use the default machine type return to 'pc' instead of the
more specific name.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c                  | 21 +++++++++++++++----
 .../default-kvm-host-arch.x86_64-latest.xml   |  2 +-
 .../default-qemu-host-arch.x86_64-latest.xml  |  2 +-
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b52e25a072..972f3e24ee 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -6756,11 +6756,21 @@ virQEMUCapsStripMachineAliasesForVirtType(virQEMUCaps *qemuCaps,

     for (i = 0; i < accel->nmachineTypes; i++) {
         virQEMUCapsMachineType *mach = &accel->machineTypes[i];
-        g_autofree char *name = g_steal_pointer(&mach->alias);

-        if (name) {
-            virQEMUCapsAddMachine(qemuCaps, virtType, name, NULL, mach->defaultCPU,
-                                  mach->maxCpus, mach->hotplugCpus, mach->qemuDefault,
+        if (mach->alias) {
+            g_autofree char *origName = g_steal_pointer(&mach->name);
+
+            /* The preferred machine type, which is generally the default by qemu
+             * in most cases but also generally an alias needs to be kept at the
+             * first entry in the list, because virQEMUCapsGetPreferredMachine
+             * picks the first element. Thus we create a new entry for the
+             * original machine name and replace the existing one by the alias. */
+            mach->name = g_steal_pointer(&mach->alias);
+
+            /* also de-assert the copy's default flag, to ensure we don't have multiple
+             * machines with it */
+            virQEMUCapsAddMachine(qemuCaps, virtType, origName, NULL, mach->defaultCPU,
+                                  mach->maxCpus, mach->hotplugCpus, false,
                                   mach->numaMemSupported, mach->defaultRAMid,
                                   mach->deprecated, mach->acpi);
         }
@@ -6778,6 +6788,9 @@ virQEMUCapsStripMachineAliasesForVirtType(virQEMUCaps *qemuCaps,
  *
  * Remove all aliases so that the tests depending on the latest capabilities
  * file can be stable when new files are added.
+ *
+ * Additionally if a machine type is default, only the copy created for the
+ * alias will be kept as default to eliminate churn in output files.
  */
 void
 virQEMUCapsStripMachineAliases(virQEMUCaps *qemuCaps)
diff --git a/tests/qemuxml2xmloutdata/default-kvm-host-arch.x86_64-latest.xml b/tests/qemuxml2xmloutdata/default-kvm-host-arch.x86_64-latest.xml
index a9de07d41c..c5f03ff2c1 100644
--- a/tests/qemuxml2xmloutdata/default-kvm-host-arch.x86_64-latest.xml
+++ b/tests/qemuxml2xmloutdata/default-kvm-host-arch.x86_64-latest.xml
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>4194304</currentMemory>
   <vcpu placement='static'>4</vcpu>
   <os>
-    <type arch='x86_64' machine='pc-i440fx-8.1'>hvm</type>
+    <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='hd'/>
   </os>
   <cpu mode='custom' match='exact' check='none'>
diff --git a/tests/qemuxml2xmloutdata/default-qemu-host-arch.x86_64-latest.xml b/tests/qemuxml2xmloutdata/default-qemu-host-arch.x86_64-latest.xml
index 37673010f6..36ed26c473 100644
--- a/tests/qemuxml2xmloutdata/default-qemu-host-arch.x86_64-latest.xml
+++ b/tests/qemuxml2xmloutdata/default-qemu-host-arch.x86_64-latest.xml
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>4194304</currentMemory>
   <vcpu placement='static'>4</vcpu>
   <os>
-    <type arch='x86_64' machine='pc-i440fx-8.1'>hvm</type>
+    <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='hd'/>
   </os>
   <cpu mode='custom' match='exact' check='none'>
-- 
2.41.0




[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