]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Validate that machine type is supported by qemu
authorPeter Krempa <pkrempa@redhat.com>
Wed, 22 Jan 2020 09:06:53 +0000 (10:06 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Jan 2020 13:55:03 +0000 (14:55 +0100)
Every supported qemu is able to return the list of machine types it
supports so we can start validating it against that list. The advantage
is a better error message, and the change will also prevent having stale
test data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_domain.c

index ca4d4c1a4002ffba60eec1ed7fb64972ed95e9da..073001607e8f1bb70007ebc762951c9cda0ce989 100644 (file)
@@ -2701,7 +2701,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
 }
 
 
-static bool
+bool
 virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
                               virDomainVirtType virtType,
                               const char *canonical_machine)
index ca7612ebfc17de4bbbca1e5cd9733092ce5ae5e0..56af9e9a0ecdaa34c76cd95d33204808323ba1a0 100644 (file)
@@ -631,6 +631,10 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
 const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
                                            virDomainVirtType virtType,
                                            const char *name);
+bool virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
+                                   virDomainVirtType virtType,
+                                   const char *canonical_machine)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
                                  virDomainVirtType virtType,
                                  const char *name);
index 50b116445a6d47b4718ea10c4723e9196214a9f7..30057902254c56cb29e044d726d7da108eefe938 100644 (file)
@@ -5727,6 +5727,14 @@ qemuDomainDefValidate(const virDomainDef *def,
         goto cleanup;
     }
 
+    if (qemuCaps &&
+        !virQEMUCapsIsMachineSupported(qemuCaps, def->virtType, def->os.machine)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Emulator '%s' does not support machine type '%s'"),
+                       def->emulator, def->os.machine);
+        goto cleanup;
+    }
+
     if (def->mem.min_guarantee) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Parameter 'min_guarantee' not supported by QEMU."));