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",