Before QEMU introduced migratable CPU property, "-cpu host" included all
features that could be enabled on the host, even those which would block
migration. In other words, the default was equivalent to migratable=off.
When the migratable property was introduced, the default changed to
migratable=on. Let's record the default in domain XML.

Signed-off-by: Jiri Denemark <jdene...@redhat.com>
---
 src/qemu/qemu_domain.c                             | 14 ++++++++++++--
 .../migration-in-params-in.xml                     |  2 +-
 .../migration-out-params-in.xml                    |  2 +-
 .../qemuxml2xmloutdata/cpu-check-default-none.xml  |  2 +-
 tests/qemuxml2xmloutdata/cpu-host-kvmclock.xml     |  2 +-
 .../cpu-host-passthrough-features.xml              |  2 +-
 tests/qemuxml2xmloutdata/kvm-features.xml          |  2 +-
 7 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3239ac1a52..2dad823a86 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4792,7 +4792,8 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
 
 
 static int
-qemuDomainDefCPUPostParse(virDomainDefPtr def)
+qemuDomainDefCPUPostParse(virDomainDefPtr def,
+                          virQEMUCapsPtr qemuCaps)
 {
     virCPUFeatureDefPtr sveFeature = NULL;
     bool sveVectorLengthsProvided = false;
@@ -4888,6 +4889,15 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def)
         }
     }
 
+    if (qemuCaps &&
+        def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH &&
+        !def->cpu->migratable) {
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE))
+            def->cpu->migratable = VIR_TRISTATE_SWITCH_ON;
+        else if (ARCH_IS_X86(def->os.arch))
+            def->cpu->migratable = VIR_TRISTATE_SWITCH_OFF;
+    }
+
     /* Nothing to be done if only CPU topology is specified. */
     if (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
         !def->cpu->model)
@@ -5033,7 +5043,7 @@ qemuDomainDefPostParse(virDomainDefPtr def,
     if (qemuDomainDefVcpusPostParse(def) < 0)
         return -1;
 
-    if (qemuDomainDefCPUPostParse(def) < 0)
+    if (qemuDomainDefCPUPostParse(def, qemuCaps) < 0)
         return -1;
 
     if (qemuDomainDefTsegPostParse(def, qemuCaps) < 0)
diff --git a/tests/qemustatusxml2xmldata/migration-in-params-in.xml 
b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
index fdc2d39173..93450c38d5 100644
--- a/tests/qemustatusxml2xmldata/migration-in-params-in.xml
+++ b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
@@ -277,7 +277,7 @@
       <apic/>
       <vmport state='off'/>
     </features>
-    <cpu mode='host-passthrough' check='none'/>
+    <cpu mode='host-passthrough' check='none' migratable='on'/>
     <clock offset='utc'>
       <timer name='rtc' tickpolicy='catchup'/>
       <timer name='pit' tickpolicy='delay'/>
diff --git a/tests/qemustatusxml2xmldata/migration-out-params-in.xml 
b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
index 1956eac120..c1daab4dee 100644
--- a/tests/qemustatusxml2xmldata/migration-out-params-in.xml
+++ b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
@@ -291,7 +291,7 @@
       <apic/>
       <vmport state='off'/>
     </features>
-    <cpu mode='host-passthrough' check='none'/>
+    <cpu mode='host-passthrough' check='none' migratable='on'/>
     <clock offset='utc'>
       <timer name='rtc' tickpolicy='catchup'/>
       <timer name='pit' tickpolicy='delay'/>
diff --git a/tests/qemuxml2xmloutdata/cpu-check-default-none.xml 
b/tests/qemuxml2xmloutdata/cpu-check-default-none.xml
index ddffb2f15b..9f6b043f2c 100644
--- a/tests/qemuxml2xmloutdata/cpu-check-default-none.xml
+++ b/tests/qemuxml2xmloutdata/cpu-check-default-none.xml
@@ -8,7 +8,7 @@
     <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='network'/>
   </os>
-  <cpu mode='host-passthrough' check='none'/>
+  <cpu mode='host-passthrough' check='none' migratable='off'/>
   <clock offset='utc'/>
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
diff --git a/tests/qemuxml2xmloutdata/cpu-host-kvmclock.xml 
b/tests/qemuxml2xmloutdata/cpu-host-kvmclock.xml
index 6d8fa367c7..9414c41c7a 100644
--- a/tests/qemuxml2xmloutdata/cpu-host-kvmclock.xml
+++ b/tests/qemuxml2xmloutdata/cpu-host-kvmclock.xml
@@ -8,7 +8,7 @@
     <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='network'/>
   </os>
-  <cpu mode='host-passthrough' check='none'/>
+  <cpu mode='host-passthrough' check='none' migratable='off'/>
   <clock offset='utc'>
     <timer name='kvmclock' present='no'/>
   </clock>
diff --git a/tests/qemuxml2xmloutdata/cpu-host-passthrough-features.xml 
b/tests/qemuxml2xmloutdata/cpu-host-passthrough-features.xml
index 9a961eb1a1..bd1e50ef6a 100644
--- a/tests/qemuxml2xmloutdata/cpu-host-passthrough-features.xml
+++ b/tests/qemuxml2xmloutdata/cpu-host-passthrough-features.xml
@@ -13,7 +13,7 @@
     <type arch='i686' machine='pc'>hvm</type>
     <boot dev='hd'/>
   </os>
-  <cpu mode='host-passthrough' check='none'>
+  <cpu mode='host-passthrough' check='none' migratable='off'>
     <feature policy='require' name='abm'/>
     <feature policy='force' name='ds'/>
     <feature policy='disable' name='invtsc'/>
diff --git a/tests/qemuxml2xmloutdata/kvm-features.xml 
b/tests/qemuxml2xmloutdata/kvm-features.xml
index 7c554671b3..9c53eb4630 100644
--- a/tests/qemuxml2xmloutdata/kvm-features.xml
+++ b/tests/qemuxml2xmloutdata/kvm-features.xml
@@ -15,7 +15,7 @@
       <hint-dedicated state='on'/>
     </kvm>
   </features>
-  <cpu mode='host-passthrough' check='none'/>
+  <cpu mode='host-passthrough' check='none' migratable='off'/>
   <clock offset='utc'/>
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
-- 
2.27.0

Reply via email to