]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
cpu: Optionally forbid fallback CPU models
authorJiri Denemark <jdenemar@redhat.com>
Wed, 21 Dec 2011 13:27:16 +0000 (14:27 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 17 Jan 2012 10:39:19 +0000 (11:39 +0100)
In case a hypervisor doesn't support the exact CPU model requested by a
domain XML, we automatically fallback to a closest CPU model the
hypervisor supports (and make sure we add/remove any additional features
if needed). This patch adds 'fallback' attribute to model element, which
can be used to disable this automatic fallback.

36 files changed:
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/cpu/cpu_x86.c
src/qemu/qemu_command.c
tests/cputest.c
tests/cputestdata/x86-baseline-1-result.xml
tests/cputestdata/x86-baseline-2-result.xml
tests/cputestdata/x86-baseline-no-vendor-result.xml
tests/cputestdata/x86-baseline-some-vendors-result.xml
tests/cputestdata/x86-guest-nofallback.xml [new file with mode: 0644]
tests/cputestdata/x86-host+guest,model486-result.xml
tests/cputestdata/x86-host+guest,models,Penryn-result.xml
tests/cputestdata/x86-host+guest,models,qemu64-result.xml
tests/cputestdata/x86-host+guest,models-result.xml
tests/cputestdata/x86-host+guest-result.xml
tests/cputestdata/x86-host+guest.xml
tests/cputestdata/x86-host+min.xml
tests/cputestdata/x86-host+nehalem-force-result.xml
tests/cputestdata/x86-host+pentium3.xml
tests/cputestdata/x86-host+strict-force-extra-result.xml
tests/cputestdata/x86-host-better+pentium3,core2duo-result.xml
tests/cputestdata/x86-host-better+pentium3,pentium3-result.xml
tests/cputestdata/x86-host-better+pentium3-result.xml
tests/cputestdata/x86-host-worse+guest-result.xml
tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml
tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c
tests/testutilsqemu.c

index 6b067230956ea28864f34b1d687e0051810f80c4..cb7532e2bd85f1cd8aafaa5bbd94daf44172793a 100644 (file)
 <pre>
   ...
   &lt;cpu match='exact'&gt;
-    &lt;model&gt;core2duo&lt;/model&gt;
+    &lt;model fallback='allow'&gt;core2duo&lt;/model&gt;
     &lt;vendor&gt;Intel&lt;/vendor&gt;
     &lt;topology sockets='1' cores='2' threads='1'/&gt;
     &lt;feature policy='disable' name='lahf_lm'/&gt;
       <dd>The content of the <code>model</code> element specifies CPU model
         requested by the guest. The list of available CPU models and their
         definition can be found in <code>cpu_map.xml</code> file installed
-        in libvirt's data directory.</dd>
+        in libvirt's data directory. If a hypervisor is not able to use the
+        exact CPU model, libvirt automatically falls back to a closest model
+        supported by the hypervisor while maintaining the list of CPU
+        features. <span class="since">Since 0.9.10</span>, an optional
+        <code>fallback</code> attribute can be used to forbid this behavior,
+        in which case an attempt to start a domain requesting an unsupported
+        CPU model will fail. Supported values for <code>fallback</code>
+        attribute are: <code>allow</code> (this is the default), and
+        <code>forbid</code>.</dd>
 
       <dt><code>vendor</code></dt>
       <dd><span class="since">Since 0.8.3</span> the content of the
index b54fd68ac7eb80fc01819f5e831ceba7c57780d0..133b7f7a826d71c33f324eb863c74ae74d57bdf9 100644 (file)
 
   <define name="cpuModel">
     <element name="model">
+      <optional>
+        <attribute name="fallback">
+          <choice>
+            <value>allow</value>
+            <value>forbid</value>
+          </choice>
+        </attribute>
+      </optional>
       <text/>
     </element>
   </define>
index 348299b5fcd30e7a48e7a8480f70d7131aa8bfee..c8e29e4cd8dc0e798683092c57399e8412c62652 100644 (file)
@@ -44,6 +44,10 @@ VIR_ENUM_IMPL(virCPUMatch, VIR_CPU_MATCH_LAST,
               "exact",
               "strict")
 
+VIR_ENUM_IMPL(virCPUFallback, VIR_CPU_FALLBACK_LAST,
+              "allow",
+              "forbid")
+
 VIR_ENUM_IMPL(virCPUFeaturePolicy, VIR_CPU_FEATURE_LAST,
               "force",
               "require",
@@ -97,6 +101,7 @@ virCPUDefCopy(const virCPUDefPtr cpu)
 
     copy->type = cpu->type;
     copy->match = cpu->match;
+    copy->fallback = cpu->fallback;
     copy->sockets = cpu->sockets;
     copy->cores = cpu->cores;
     copy->threads = cpu->threads;
@@ -209,6 +214,21 @@ virCPUDefParseXML(const xmlNodePtr node,
         goto error;
     }
 
+    if (def->model && def->type == VIR_CPU_TYPE_GUEST) {
+        const char *fallback;
+
+        fallback = virXPathString("string(./model[1]/@fallback)", ctxt);
+        if (fallback) {
+            def->fallback = virCPUFallbackTypeFromString(fallback);
+            VIR_FREE(fallback);
+            if (def->fallback < 0) {
+                virCPUReportError(VIR_ERR_XML_ERROR, "%s",
+                                  _("Invalid fallback attribute"));
+                goto error;
+            }
+        }
+    }
+
     def->vendor = virXPathString("string(./vendor[1])", ctxt);
     if (def->vendor && !def->model) {
         virCPUReportError(VIR_ERR_INTERNAL_ERROR,
@@ -455,8 +475,22 @@ virCPUDefFormatBuf(virBufferPtr buf,
         return -1;
     }
 
-    if (def->model)
-        virBufferAsprintf(buf, "<model>%s</model>\n", def->model);
+    if (def->model) {
+        virBufferAddLit(buf, "<model");
+        if (def->type == VIR_CPU_TYPE_GUEST) {
+            const char *fallback;
+
+            fallback = virCPUFallbackTypeToString(def->fallback);
+            if (!fallback) {
+                virCPUReportError(VIR_ERR_INTERNAL_ERROR,
+                                  _("Unexpected CPU fallback value: %d"),
+                                  def->fallback);
+                return -1;
+            }
+            virBufferAsprintf(buf, " fallback='%s'", fallback);
+        }
+        virBufferAsprintf(buf, ">%s</model>\n", def->model);
+    }
 
     if (def->vendor) {
         virBufferAsprintf(buf, "<vendor>%s</vendor>\n", def->vendor);
index efff47378a648a4c05a22b190eff5e02195166c0..0c50f90b156791fae3ec850849094892cbe8ef16 100644 (file)
@@ -48,6 +48,15 @@ enum virCPUMatch {
 
 VIR_ENUM_DECL(virCPUMatch)
 
+enum virCPUFallback {
+    VIR_CPU_FALLBACK_ALLOW,
+    VIR_CPU_FALLBACK_FORBID,
+
+    VIR_CPU_FALLBACK_LAST
+};
+
+VIR_ENUM_DECL(virCPUFallback)
+
 enum virCPUFeaturePolicy {
     VIR_CPU_FEATURE_FORCE,
     VIR_CPU_FEATURE_REQUIRE,
@@ -83,6 +92,7 @@ struct _virCPUDef {
     int match;          /* enum virCPUMatch */
     char *arch;
     char *model;
+    int fallback;       /* enum virCPUFallback */
     char *vendor;
     unsigned int sockets;
     unsigned int cores;
index 4a4272e83960fb649c2b1b183d29473e55a65b07..ad2d5cda45fedb9088e6872922f9afb9113b5f6e 100644 (file)
@@ -1294,8 +1294,21 @@ x86Decode(virCPUDefPtr cpu,
         }
 
         if (!allowed) {
-            VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring",
-                      candidate->name);
+            if (preferred && STREQ(candidate->name, preferred)) {
+                if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
+                    virCPUReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            _("CPU model %s is not supported by hypervisor"),
+                            preferred);
+                    goto out;
+                } else {
+                    VIR_WARN("Preferred CPU model %s not allowed by"
+                             " hypervisor; closest supported model will be"
+                             " used", preferred);
+                }
+            } else {
+                VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring",
+                          candidate->name);
+            }
             goto next;
         }
 
index 98824ac95abb279d07aae53c147e067a8f4c3073..d2789263c843e24f2e071dcbdc4a93e9951187ca 100644 (file)
@@ -3511,6 +3511,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
             preferred = def->cpu->model;
 
         guest->type = VIR_CPU_TYPE_GUEST;
+        guest->fallback = def->cpu->fallback;
         if (cpuDecode(guest, data, cpus, ncpus, preferred) < 0)
             goto cleanup;
 
index 5b7b951ccc6fd226c8476d1f9228c9757090017f..2dd89f28bed4c5c67770f27046571d2a93d65d80 100644 (file)
@@ -287,6 +287,7 @@ cpuTestGuestData(const void *arg)
 
     guest->type = VIR_CPU_TYPE_GUEST;
     guest->match = VIR_CPU_MATCH_EXACT;
+    guest->fallback = cpu->fallback;
     if (cpuDecode(guest, guestData, data->models,
                   data->nmodels, data->preferred) < 0) {
         if (data->result < 0) {
@@ -620,6 +621,7 @@ mymain(void)
     DO_TEST_GUESTDATA("x86", "host", "guest", models, "Penryn", 0);
     DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0);
     DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1);
+    DO_TEST_GUESTDATA("x86", "host", "guest-nofallback", models, "Penryn", -1);
 
     free(map);
     return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
index e376f7442f125569c8c74be8dfe64c98c83c2a2a..99e43d018ff9d894a76ce524ed92099fd91f6bab 100644 (file)
@@ -1,5 +1,5 @@
 <cpu match='exact'>
-  <model>Conroe</model>
+  <model fallback='allow'>Conroe</model>
   <vendor>Intel</vendor>
   <feature policy='disable' name='lahf_lm'/>
 </cpu>
index 3fd0551ba8c022e281edd1a0c029cc56a31f7943..76c13aa505bace44c25f1857360b7be5b0c06274 100644 (file)
@@ -1,4 +1,4 @@
 <cpu match='exact'>
-  <model>core2duo</model>
+  <model fallback='allow'>core2duo</model>
   <feature policy='disable' name='nx'/>
 </cpu>
index 0fc089256f7bd8c2ae4ad048ba76dc3d56bcab14..8b97d2c130924c203db26bcee24cad4eec9a921f 100644 (file)
@@ -1,5 +1,5 @@
 <cpu match='exact'>
-  <model>Opteron_G2</model>
+  <model fallback='allow'>Opteron_G2</model>
   <feature policy='disable' name='svm'/>
   <feature policy='disable' name='rdtscp'/>
 </cpu>
index 2ddfcc5807c303efd2d92b73d2036fa8f42700f0..bac0e5d38f2fcf4250291bedc1f4716a8c7280a0 100644 (file)
@@ -1,3 +1,3 @@
 <cpu match='exact'>
-  <model>Opteron_G1</model>
+  <model fallback='allow'>Opteron_G1</model>
 </cpu>
diff --git a/tests/cputestdata/x86-guest-nofallback.xml b/tests/cputestdata/x86-guest-nofallback.xml
new file mode 100644 (file)
index 0000000..babe47d
--- /dev/null
@@ -0,0 +1,18 @@
+<cpu match='exact'>
+  <model fallback='forbid'>Penryn</model>
+  <topology sockets='2' cores='4' threads='1'/>
+  <!--feature name='sse4.1' policy='optional'/-->
+  <feature name='dca' policy='optional'/>
+  <feature name='xtpr' policy='optional'/>
+  <feature name='sse4.2' policy='optional'/>
+  <feature name='3dnow' policy='optional'/>
+  <feature name='ssse3' policy='optional'/>
+  <feature name='vmx' policy='disable'/>
+  <feature name='ds_cpl' policy='disable'/>
+  <feature name='sse' policy='disable'/>
+  <feature name='monitor' policy='force'/>
+  <feature name='pbe' policy='force'/>
+  <feature name='3dnowext' policy='force'/>
+  <feature name='svm' policy='force'/>
+  <feature name='popcnt' policy='forbid'/>
+</cpu>
index fb1bb4b950d8660dd4263d243411392fcd16ce5a..9fd67eb1a74350d538010e76dd7827060cb157b8 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>486</model>
+  <model fallback='allow'>486</model>
   <feature policy='require' name='svm'/>
   <feature policy='require' name='lahf_lm'/>
   <feature policy='require' name='3dnowext'/>
index 955946537c4605825f8c4da4a136dd6a1f7e5c6f..9ae11c95006fcdd7668a8e6e69900f0f19ebf6ca 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Nehalem</model>
+  <model fallback='allow'>Nehalem</model>
   <feature policy='require' name='svm'/>
   <feature policy='require' name='3dnowext'/>
   <feature policy='require' name='dca'/>
index b41863eb594038ac2306d872b515e164f8df1ac8..7582ddc8c5ab97dad7588018416ae452f382b123 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>qemu64</model>
+  <model fallback='allow'>qemu64</model>
   <feature policy='require' name='lahf_lm'/>
   <feature policy='require' name='3dnowext'/>
   <feature policy='require' name='sse4.1'/>
index 955946537c4605825f8c4da4a136dd6a1f7e5c6f..9ae11c95006fcdd7668a8e6e69900f0f19ebf6ca 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Nehalem</model>
+  <model fallback='allow'>Nehalem</model>
   <feature policy='require' name='svm'/>
   <feature policy='require' name='3dnowext'/>
   <feature policy='require' name='dca'/>
index 544a388f7678c03e69d01f79ae409e6ed2256431..e596c4320992543f25f967437e6deb72a536a42f 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Penryn</model>
+  <model fallback='allow'>Penryn</model>
   <feature policy='require' name='svm'/>
   <feature policy='require' name='3dnowext'/>
   <feature policy='require' name='dca'/>
index c3fca8775426968aef3048744f1edf48c887b4e8..2a786fd3aa335cf484425d921b25772c14e7d422 100644 (file)
@@ -1,5 +1,5 @@
 <cpu match='exact'>
-  <model>Penryn</model>
+  <model fallback='allow'>Penryn</model>
   <topology sockets='2' cores='4' threads='1'/>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
index d22c7b6c1c77b570b382d0a4f5b93ca93d744813..fe55058992e8516e0b75df3a01151731b3aa70f6 100644 (file)
@@ -1,5 +1,5 @@
 <cpu match='exact'>
-  <model>Penryn</model>
+  <model fallback='allow'>Penryn</model>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
   <feature policy='require' name='tm2'/>
index 162685f02269272dcd50b2036e78c44757fe48c6..41e7356796dbb119c68929ea673196e4633d2e5d 100644 (file)
@@ -1,4 +1,4 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Nehalem</model>
+  <model fallback='allow'>Nehalem</model>
 </cpu>
index d141d9e333d038b0412a313126c8acd55ff465c8..e122ba53d6e6ddee87f6d810b9ecf832000dd0f4 100644 (file)
@@ -1,5 +1,5 @@
 <cpu match='exact'>
-  <model>pentium3</model>
+  <model fallback='allow'>pentium3</model>
   <feature policy='require' name='lahf_lm'/>
   <feature policy='require' name='lm'/>
   <feature policy='require' name='nx'/>
index e47933cc3298803d7865d99e9428c25ae130397e..f3d52a14b3cc3d84e7b7d915544df9fbb25ab6d2 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Penryn</model>
+  <model fallback='allow'>Penryn</model>
   <feature policy='require' name='3dnow'/>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
index c2d8ddd636a80207ca2aac5480b14b642f9c5093..5d4528bd6d1aaf1669f3219c7ed6df70fe997aa2 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>core2duo</model>
+  <model fallback='allow'>core2duo</model>
   <feature policy='require' name='lahf_lm'/>
   <feature policy='require' name='popcnt'/>
   <feature policy='require' name='sse4.2'/>
index 6e246a80323d0eee7862306dbe791f21e3cd9504..1530a07e0ac351e292281593f518d3a8c5bd2cc8 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>pentium3</model>
+  <model fallback='allow'>pentium3</model>
   <feature policy='require' name='lahf_lm'/>
   <feature policy='require' name='lm'/>
   <feature policy='require' name='nx'/>
index b918363e6977555ea84c932f045cb3e773ac874e..917d63f06992754f2b5b14e00dcd8b6417e87144 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Nehalem</model>
+  <model fallback='allow'>Nehalem</model>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
   <feature policy='require' name='tm2'/>
index 036177a58fafcda7f5a0af836289f7d342c4f59a..78e170adbc7b2d0ee4f19eae73b11e313c7ea55d 100644 (file)
@@ -1,6 +1,6 @@
 <cpu match='exact'>
   <arch>x86_64</arch>
-  <model>Penryn</model>
+  <model fallback='allow'>Penryn</model>
   <feature policy='require' name='svm'/>
   <feature policy='require' name='3dnowext'/>
   <feature policy='require' name='monitor'/>
index d6db442ad94be0a6eb569df4dfa9a289c4c7f00b..b5fd49c5f7a7ff2e7909626396cbb0cd41167c65 100644 (file)
@@ -9,7 +9,7 @@
     <boot dev='network'/>
   </os>
   <cpu match='exact'>
-    <model>qemu64</model>
+    <model fallback='allow'>qemu64</model>
     <feature policy='disable' name='svm'/>
     <feature policy='disable' name='lm'/>
     <feature policy='disable' name='nx'/>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args
new file mode 100644 (file)
index 0000000..198d0d8
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+-cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+ds_cpl,+tm,+ht,+ds,-nx -m 214 -smp 6 \
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
+none -serial none -parallel none -usb
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml
new file mode 100644 (file)
index 0000000..11de634
--- /dev/null
@@ -0,0 +1,35 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu match='exact'>
+    <model fallback='forbid'>core2duo</model>
+    <feature name='lahf_lm' policy='require'/>
+    <feature name='xtpr' policy='require'/>
+    <feature name='cx16' policy='disable'/>
+    <feature name='tm2' policy='disable'/>
+    <feature name='ds_cpl' policy='require'/>
+    <feature name='pbe' policy='disable'/>
+    <feature name='tm' policy='optional'/>
+    <feature name='ht' policy='require'/>
+    <feature name='ss' policy='disable'/>
+    <feature name='ds' policy='require'/>
+    <feature name='nx' policy='disable'/>
+    <feature name='3dnowext' policy='force'/>
+    <feature name='sse4a' policy='optional'/>
+    <feature name='wdt' policy='forbid'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/./qemu.sh</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args
new file mode 100644 (file)
index 0000000..658f141
--- /dev/null
@@ -0,0 +1,19 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+./qemu.sh \
+-S \
+-M pc \
+-cpu Penryn,-sse4.1 \
+-m 214 \
+-smp 6 \
+-nographic \
+-monitor unix:/tmp/test-monitor,server,nowait \
+-no-acpi \
+-boot n \
+-net none \
+-serial none \
+-parallel none \
+-usb
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml
new file mode 100644 (file)
index 0000000..7bd28a8
--- /dev/null
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu match='exact'>
+    <model>Westmere</model>
+    <feature policy='disable' name='sse4.1'/>
+    <feature policy='disable' name='sse4.2'/>
+    <feature policy='disable' name='popcnt'/>
+    <feature policy='disable' name='aes'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/./qemu.sh</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml
new file mode 100644 (file)
index 0000000..7f1f09a
--- /dev/null
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219100</memory>
+  <currentMemory>219100</currentMemory>
+  <vcpu>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu match='exact'>
+    <model fallback='forbid'>Westmere</model>
+    <feature policy='disable' name='sse4.1'/>
+    <feature policy='disable' name='sse4.2'/>
+    <feature policy='disable' name='popcnt'/>
+    <feature policy='disable' name='aes'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/./qemu.sh</emulator>
+  </devices>
+</domain>
index fd3c9bbd533ee1d99f0eb4baf9548c00ae5b6904..e5161938dabe5c1b07aa82456008c050d1cea600 100644 (file)
@@ -84,7 +84,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
                                      const char *migrateFrom,
                                      int migrateFd,
                                      bool json,
-                                     bool expectError)
+                                     bool expectError,
+                                     bool expectFailure)
 {
     char *expectargv = NULL;
     int len;
@@ -98,19 +99,13 @@ static int testCompareXMLToArgvFiles(const char *xml,
     virCommandPtr cmd = NULL;
 
     if (!(conn = virGetConnect()))
-        goto fail;
+        goto out;
     conn->secretDriver = &fakeSecretDriver;
 
-    len = virtTestLoadFile(cmdline, &expectargv);
-    if (len < 0)
-        goto fail;
-    if (len && expectargv[len - 1] == '\n')
-        expectargv[len - 1] = '\0';
-
     if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
                                         QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
-        goto fail;
+        goto out;
 
     /*
      * For test purposes, we may want to fake emulator's output by providing
@@ -124,12 +119,12 @@ static int testCompareXMLToArgvFiles(const char *xml,
      */
     if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
         if (!(emulator = strdup(vmdef->emulator + 1)))
-            goto fail;
+            goto out;
         free(vmdef->emulator);
         vmdef->emulator = NULL;
         if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
                         abs_srcdir, emulator) < 0)
-            goto fail;
+            goto out;
     }
 
     if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID))
@@ -149,7 +144,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
                     QEMU_CAPS_LAST);
 
     if (qemudCanonicalizeMachine(&driver, vmdef) < 0)
-        goto fail;
+        goto out;
 
     if (qemuCapsGet(extraFlags, QEMU_CAPS_DEVICE)) {
         qemuDomainPCIAddressSetPtr pciaddrs;
@@ -157,14 +152,14 @@ static int testCompareXMLToArgvFiles(const char *xml,
         if (qemuDomainAssignSpaprVIOAddresses(vmdef)) {
             if (expectError)
                 goto ok;
-            goto fail;
+            goto out;
         }
 
         if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef)))
-            goto fail;
+            goto out;
 
         if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0)
-            goto fail;
+            goto out;
 
         qemuDomainPCIAddressSetFree(pciaddrs);
     }
@@ -183,35 +178,50 @@ static int testCompareXMLToArgvFiles(const char *xml,
     }
 
     if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0)
-        goto fail;
+        goto out;
 
     if (!(cmd = qemuBuildCommandLine(conn, &driver,
                                      vmdef, &monitor_chr, json, extraFlags,
                                      migrateFrom, migrateFd, NULL,
-                                     VIR_NETDEV_VPORT_PROFILE_OP_NO_OP)))
-        goto fail;
+                                     VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) {
+        if (expectFailure) {
+            ret = 0;
+            virResetLastError();
+        }
+        goto out;
+    } else if (expectFailure) {
+        if (virTestGetDebug())
+            fprintf(stderr, "qemuBuildCommandLine should have failed\n");
+        goto out;
+    }
 
     if (!!virGetLastError() != expectError) {
         if (virTestGetDebug() && (log = virtTestLogContentAndReset()))
             fprintf(stderr, "\n%s", log);
-        goto fail;
+        goto out;
     }
 
     if (!(actualargv = virCommandToString(cmd)))
-        goto fail;
+        goto out;
 
     if (emulator) {
         /* Skip the abs_srcdir portion of replacement emulator.  */
         char *start_skip = strstr(actualargv, abs_srcdir);
         char *end_skip = strstr(actualargv, emulator);
         if (!start_skip || !end_skip)
-            goto fail;
+            goto out;
         memmove(start_skip, end_skip, strlen(end_skip) + 1);
     }
 
+    len = virtTestLoadFile(cmdline, &expectargv);
+    if (len < 0)
+        goto out;
+    if (len && expectargv[len - 1] == '\n')
+        expectargv[len - 1] = '\0';
+
     if (STRNEQ(expectargv, actualargv)) {
         virtTestDifference(stderr, expectargv, actualargv);
-        goto fail;
+        goto out;
     }
 
  ok:
@@ -222,7 +232,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
 
     ret = 0;
 
- fail:
+out:
     free(log);
     free(emulator);
     free(expectargv);
@@ -240,6 +250,7 @@ struct testInfo {
     const char *migrateFrom;
     int migrateFd;
     bool expectError;
+    bool expectFailure;
 };
 
 static int
@@ -260,7 +271,8 @@ testCompareXMLToArgvHelper(const void *data)
                                        info->migrateFrom, info->migrateFd,
                                        qemuCapsGet(info->extraFlags,
                                                    QEMU_CAPS_MONITOR_JSON),
-                                       info->expectError);
+                                       info->expectError,
+                                       info->expectFailure);
 
 cleanup:
     free(xml);
@@ -299,10 +311,12 @@ mymain(void)
         return EXIT_FAILURE;
     }
 
-# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...)   \
+# define DO_TEST_FULL(name, migrateFrom, migrateFd,                     \
+                      expectError, expectFailure, ...)                  \
     do {                                                                \
         struct testInfo info = {                                        \
-            name, NULL, migrateFrom, migrateFd, expectError             \
+            name, NULL, migrateFrom, migrateFd,                         \
+            expectError, expectFailure                                  \
         };                                                              \
         if (!(info.extraFlags = qemuCapsNew()))                         \
             return EXIT_FAILURE;                                        \
@@ -314,7 +328,10 @@ mymain(void)
     } while (0)
 
 # define DO_TEST(name, expectError, ...)                                \
-    DO_TEST_FULL(name, NULL, -1, expectError, __VA_ARGS__)
+    DO_TEST_FULL(name, NULL, -1, expectError, false, __VA_ARGS__)
+
+# define DO_TEST_FAILURE(name, ...)                                     \
+    DO_TEST_FULL(name, NULL, -1, false, true, __VA_ARGS__)
 
 # define NONE QEMU_CAPS_LAST
 
@@ -643,17 +660,17 @@ mymain(void)
     DO_TEST("hostdev-pci-address-device", false,
             QEMU_CAPS_PCIDEVICE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
 
-    DO_TEST_FULL("restore-v1", "stdio", 7, false,
+    DO_TEST_FULL("restore-v1", "stdio", 7, false, false,
             QEMU_CAPS_MIGRATE_KVM_STDIO);
-    DO_TEST_FULL("restore-v2", "stdio", 7, false,
+    DO_TEST_FULL("restore-v2", "stdio", 7, false, false,
             QEMU_CAPS_MIGRATE_QEMU_EXEC);
-    DO_TEST_FULL("restore-v2", "exec:cat", 7, false,
+    DO_TEST_FULL("restore-v2", "exec:cat", 7, false, false,
             QEMU_CAPS_MIGRATE_QEMU_EXEC);
-    DO_TEST_FULL("restore-v2-fd", "stdio", 7, false,
+    DO_TEST_FULL("restore-v2-fd", "stdio", 7, false, false,
             QEMU_CAPS_MIGRATE_QEMU_FD);
-    DO_TEST_FULL("restore-v2-fd", "fd:7", 7, false,
+    DO_TEST_FULL("restore-v2-fd", "fd:7", 7, false, false,
             QEMU_CAPS_MIGRATE_QEMU_FD);
-    DO_TEST_FULL("migrate", "tcp:10.0.0.1:5000", -1, false,
+    DO_TEST_FULL("migrate", "tcp:10.0.0.1:5000", -1, false, false,
             QEMU_CAPS_MIGRATE_QEMU_TCP);
 
     DO_TEST("qemu-ns", false, NONE);
@@ -667,6 +684,9 @@ mymain(void)
     DO_TEST("cpu-minimum2", false, NONE);
     DO_TEST("cpu-exact1", false, NONE);
     DO_TEST("cpu-exact2", false, NONE);
+    DO_TEST("cpu-exact2-nofallback", false, NONE);
+    DO_TEST("cpu-fallback", false, NONE);
+    DO_TEST_FAILURE("cpu-nofallback", NONE);
     DO_TEST("cpu-strict1", false, NONE);
     DO_TEST("cpu-numa1", false, NONE);
     DO_TEST("cpu-numa2", false, QEMU_CAPS_SMP_TOPOLOGY);
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml
new file mode 100644 (file)
index 0000000..caa5f0a
--- /dev/null
@@ -0,0 +1,86 @@
+<domain type='qemu'>
+  <name>f14</name>
+  <uuid>553effab-b5e1-2d80-dfe3-da4344826c43</uuid>
+  <memory>1048576</memory>
+  <currentMemory>1048576</currentMemory>
+  <vcpu>2</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='cdrom'/>
+    <boot dev='hd'/>
+    <bootmenu enable='yes'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <cpu match='exact'>
+    <model fallback='allow'>core2duo</model>
+    <vendor>Intel</vendor>
+    <topology sockets='1' cores='2' threads='1'/>
+    <feature policy='require' name='lahf_lm'/>
+    <feature policy='require' name='xtpr'/>
+    <feature policy='require' name='cx16'/>
+    <feature policy='require' name='tm2'/>
+    <feature policy='require' name='est'/>
+    <feature policy='require' name='vmx'/>
+    <feature policy='require' name='ds_cpl'/>
+    <feature policy='require' name='pbe'/>
+    <feature policy='require' name='tm'/>
+    <feature policy='require' name='ht'/>
+    <feature policy='require' name='ss'/>
+    <feature policy='require' name='acpi'/>
+    <feature policy='require' name='ds'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/./qemu.sh</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2'/>
+      <source file='/var/lib/libvirt/images/f14.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+      <address type='drive' controller='0' bus='1' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='virtio-serial' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+    </controller>
+    <interface type='ethernet'>
+      <mac address='52:54:00:71:70:89'/>
+      <script path='/etc/qemu-ifup'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+    </interface>
+    <serial type='pty'>
+      <target port='0'/>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='tablet' bus='usb'/>
+    <input type='mouse' bus='ps2'/>
+    <graphics type='spice' port='5900' autoport='no' passwd='sercet' passwdValidTo='2011-05-31T16:11:22' connected='disconnect'/>
+    <sound model='ac97'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </sound>
+    <video>
+      <model type='vga' vram='9216' heads='1'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </video>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
index ad1903bcbc31b52643946d966283dd563112ceab..293c2a7d5f3e9692a1dbd0e39d35ee712618e08e 100644 (file)
@@ -149,7 +149,6 @@ mymain(void)
     DO_TEST("graphics-sdl-fullscreen");
     DO_TEST("graphics-spice");
     DO_TEST("graphics-spice-compression");
-    DO_TEST("graphics-spice-timeout");
     DO_TEST("graphics-spice-qxl-vga");
     DO_TEST("input-usbmouse");
     DO_TEST("input-usbtablet");
@@ -209,6 +208,7 @@ mymain(void)
     DO_TEST_DIFFERENT("console-virtio");
     DO_TEST_DIFFERENT("serial-target-port-auto");
     DO_TEST_DIFFERENT("graphics-listen-network2");
+    DO_TEST_DIFFERENT("graphics-spice-timeout");
 
     virCapabilitiesFree(driver.caps);
 
index fa6422a70608175f70bafe0b70caf8f3e5652e5b..c6adec924c34c5f3f09504342872f8d6316cfcd5 100644 (file)
@@ -115,6 +115,7 @@ virCapsPtr testQemuCapsInit(void) {
         0,                      /* match */
         (char *) "x86_64",      /* arch */
         (char *) "core2duo",    /* model */
+        0,                      /* fallback */
         (char *) "Intel",       /* vendor */
         1,                      /* sockets */
         2,                      /* cores */