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 <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-08-24 13:44:00 +02:00
parent 2b81fbb22e
commit 507e608835

View File

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