[PATCH v2 13/14] libxl: implement lifecycle actions from domain config

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

 



Instead of hardcoded actions for poweroff, reboot and crash.
Known limitations:
1. Crash actions not fully implemented (namely no coredump done).
2. VIR_DOMAIN_LIFECYCLE_PRESERVE emit VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN
event but do not mark domain object as stopped. So effectively use of
'preserve' can cause Weird Effects (tm).

Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
 src/libxl/libxl_driver.c | 54 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 10 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 448db73..04142bb 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -721,7 +721,8 @@ libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
     libxl_shutdown_reason xl_reason = event->u.domain_shutdown.shutdown_reason;
 
     if (event->type == LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) {
-        virDomainShutoffReason reason;
+        virDomainShutoffReason reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
+        int action = VIR_DOMAIN_LIFECYCLE_DESTROY;
 
         /*
          * Similar to the xl implementation, ignore SUSPEND.  Any actions needed
@@ -739,27 +740,60 @@ libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
 
         switch (xl_reason) {
             case LIBXL_SHUTDOWN_REASON_POWEROFF:
+                reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
+                action = vm->def->onPoweroff;
+                break;
             case LIBXL_SHUTDOWN_REASON_CRASH:
-                if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
-                    dom_event = virDomainEventNewFromObj(vm,
-                                              VIR_DOMAIN_EVENT_STOPPED,
-                                              VIR_DOMAIN_EVENT_STOPPED_CRASHED);
-                    reason = VIR_DOMAIN_SHUTOFF_CRASHED;
-                } else {
-                    reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
+                dom_event = virDomainEventNewFromObj(vm,
+                        VIR_DOMAIN_EVENT_STOPPED,
+                        VIR_DOMAIN_EVENT_STOPPED_CRASHED);
+                reason = VIR_DOMAIN_SHUTOFF_CRASHED;
+                switch (vm->def->onCrash) {
+                    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
+                        /* TODO: coredump here */
+                        VIR_ERROR("Coredump on crash not supported yet");
+                        action = VIR_DOMAIN_LIFECYCLE_DESTROY;
+                        break;
+                    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART:
+                        /* TODO: coredump here */
+                        VIR_ERROR("Coredump on crash not supported yet");
+                        action = VIR_DOMAIN_LIFECYCLE_RESTART;
+                        break;
+                    default:
+                        action = vm->def->onCrash;
+                        break;
                 }
+                break;
+            case LIBXL_SHUTDOWN_REASON_REBOOT:
+                reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
+                action = vm->def->onReboot;
+                break;
+            default:
+                VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
+                break;
+        }
+        switch (action) {
+            case VIR_DOMAIN_LIFECYCLE_DESTROY:
                 libxlVmReap(driver, vm, reason);
                 if (!vm->persistent) {
                     virDomainObjListRemove(driver->domains, vm);
                     vm = NULL;
                 }
                 break;
-            case LIBXL_SHUTDOWN_REASON_REBOOT:
+            case VIR_DOMAIN_LIFECYCLE_RESTART:
+            case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
                 libxlVmReap(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
                 libxlVmStart(driver, vm, 0, -1);
                 break;
+            case VIR_DOMAIN_LIFECYCLE_PRESERVE:
+                if (xl_reason != LIBXL_SHUTDOWN_REASON_CRASH) {
+                    dom_event = virDomainEventNewFromObj(vm,
+                            VIR_DOMAIN_EVENT_STOPPED,
+                            VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
+                }
+                break;
             default:
-                VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
+                VIR_INFO("Unsupported shutdown action: %d", action);
                 break;
         }
     }
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[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]