]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: driver: Validate lifecycle actions in 'qemuDomainSetLifecycleAction'
authorPeter Krempa <pkrempa@redhat.com>
Tue, 24 Aug 2021 11:44:00 +0000 (13:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Aug 2021 13:32:44 +0000 (15:32 +0200)
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>
src/qemu/qemu_driver.c

index ac3e9c7dd8e04de4a3ec8a1b0b8786acc95c690f..0473985588213987b5cf137db1ea55db2056b89d 100644 (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",