From: Peter Krempa Date: Wed, 22 Jan 2020 09:06:53 +0000 (+0100) Subject: qemu: domain: Validate that machine type is supported by qemu X-Git-Tag: v6.1.0-rc1~410 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b9d1a80732750d17f9cc3a1eaf646f153291c28;p=thirdparty%2Flibvirt.git qemu: domain: Validate that machine type is supported by qemu 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 Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ca4d4c1a40..073001607e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2701,7 +2701,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, } -static bool +bool virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps, virDomainVirtType virtType, const char *canonical_machine) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index ca7612ebfc..56af9e9a0e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -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); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 50b116445a..3005790225 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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."));