From: Peter Krempa Date: Tue, 24 Aug 2021 11:44:00 +0000 (+0200) Subject: qemu: driver: Validate lifecycle actions in 'qemuDomainSetLifecycleAction' X-Git-Tag: v7.7.0-rc1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=507e6088353ed472998f1c6b9ae0713c4f2fa6a0;p=thirdparty%2Flibvirt.git qemu: driver: Validate lifecycle actions in 'qemuDomainSetLifecycleAction' Some actions are not supported by qemu. Use the recently added 'qemuValidateLifecycleAction' helper to ensure that the API does the same validation as we do on startup in the validation callbacks. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ac3e9c7dd8..0473985588 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -53,6 +53,7 @@ #include "qemu_namespace.h" #include "qemu_saveimage.h" #include "qemu_snapshot.h" +#include "qemu_validate.h" #include "virerror.h" #include "virlog.h" @@ -19575,6 +19576,36 @@ qemuDomainSetBlockThreshold(virDomainPtr dom, } +static int +qemuDomainSetLifecycleActionValidate(virDomainDef *def, + virDomainLifecycle type, + virDomainLifecycleAction action) +{ + virDomainLifecycleAction onPoweroff = def->onPoweroff; + virDomainLifecycleAction onReboot = def->onReboot; + virDomainLifecycleAction onCrash = def->onCrash; + + switch (type) { + case VIR_DOMAIN_LIFECYCLE_POWEROFF: + onPoweroff = action; + break; + case VIR_DOMAIN_LIFECYCLE_REBOOT: + onReboot = action; + break; + case VIR_DOMAIN_LIFECYCLE_CRASH: + onCrash = action; + break; + case VIR_DOMAIN_LIFECYCLE_LAST: + break; + } + + if (qemuValidateLifecycleAction(onPoweroff, onReboot, onCrash) < 0) + return -1; + + return 0; +} + + static void qemuDomainModifyLifecycleAction(virDomainDef *def, virDomainLifecycle type, @@ -19633,6 +19664,10 @@ qemuDomainSetLifecycleAction(virDomainPtr dom, if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) goto endjob; + if ((def && qemuDomainSetLifecycleActionValidate(def, type, action) < 0) || + (persistentDef && qemuDomainSetLifecycleActionValidate(persistentDef, type, action) < 0)) + goto endjob; + if (def) { if (priv->allowReboot == VIR_TRISTATE_BOOL_NO) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",