[PATCH 06/22] qemu: driver: Validate lifecycle actions in 'qemuDomainSetLifecycleAction'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 39347f84c7..0472f54a37 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"
@@ -19577,6 +19578,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,
@@ -19635,6 +19666,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",
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux