]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: check os type / virt type / arch in validate callback
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 11 Dec 2019 11:55:23 +0000 (11:55 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 12 Dec 2019 16:30:02 +0000 (16:30 +0000)
Don't check os type / virt type / arch in the post-parse callback
because we can't assume qemuCaps is non-NULL at this point. It
also conceptually belongs to the validation callback.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_domain.c
tests/qemuxml2argvtest.c

index 6870c17834eb7930c2930d207f76acc346346305..40298ab56cce0bd7b4efd5862513a23f22b50aa8 100644 (file)
@@ -4864,27 +4864,6 @@ qemuDomainDefPostParse(virDomainDefPtr def,
         return 1;
     }
 
-    if (def->os.type != VIR_DOMAIN_OSTYPE_HVM) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Emulator '%s' does not support os type '%s'"),
-                       def->emulator, virDomainOSTypeToString(def->os.type));
-        return -1;
-    }
-
-    if (!virQEMUCapsIsArchSupported(qemuCaps, def->os.arch)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Emulator '%s' does not support arch '%s'"),
-                       def->emulator, virArchToString(def->os.arch));
-        return -1;
-    }
-
-    if (!virQEMUCapsIsVirtTypeSupported(qemuCaps, def->virtType)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Emulator '%s' does not support virt type '%s'"),
-                       def->emulator, virDomainVirtTypeToString(def->virtType));
-        return -1;
-    }
-
     if (def->os.bootloader || def->os.bootloaderArgs) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("bootloader is not supported by QEMU"));
@@ -5141,6 +5120,27 @@ qemuDomainDefValidate(const virDomainDef *def,
                                             def->emulator)))
         goto cleanup;
 
+    if (def->os.type != VIR_DOMAIN_OSTYPE_HVM) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Emulator '%s' does not support os type '%s'"),
+                       def->emulator, virDomainOSTypeToString(def->os.type));
+        goto cleanup;
+    }
+
+    if (!virQEMUCapsIsArchSupported(qemuCaps, def->os.arch)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Emulator '%s' does not support arch '%s'"),
+                       def->emulator, virArchToString(def->os.arch));
+        goto cleanup;
+    }
+
+    if (!virQEMUCapsIsVirtTypeSupported(qemuCaps, def->virtType)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Emulator '%s' does not support virt type '%s'"),
+                       def->emulator, virDomainVirtTypeToString(def->virtType));
+        goto cleanup;
+    }
+
     if (def->mem.min_guarantee) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Parameter 'min_guarantee' not supported by QEMU."));
index ba4a92ec0aed8eb7ca5ba0fa02006472a06e371c..8655db609effb3123d7491784d1e12080a5a4aa0 100644 (file)
@@ -2852,10 +2852,13 @@ mymain(void)
             QEMU_CAPS_NEC_USB_XHCI);
 
     /* VM XML has invalid arch/ostype/virttype combo, but the SKIP flag
-     * will avoid the error. Still, we expect qemu driver to complain about
-     * missing machine error, and not crash */
+     * will avoid the error during parse. This will cause us to fill in
+     * the missing machine type using the i386 binary, despite it being
+     * the wrong binary for the arch. We expect to get a failure about
+     * bad arch later when creating the pretend command.
+     */
     DO_TEST_FULL("missing-machine",
-                 ARG_FLAGS, FLAG_EXPECT_PARSE_ERROR | FLAG_EXPECT_FAILURE,
+                 ARG_FLAGS, FLAG_EXPECT_FAILURE,
                  ARG_PARSEFLAGS, VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE,
                  ARG_QEMU_CAPS, NONE);