File 817206cd-libxl-lifecycle-events.patch of Package libvirt

commit 817206cdc85442a090d01f2d3011847ee02d8565
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Wed Sep 3 14:14:50 2014 -0600

    libxl: fix mapping of libvirt and libxl lifecycle actions
    
    The libxl driver was blindly assigning libvirt's
    virDomainLifecycleAction to libxl's libxl_action_on_shutdown, when
    in fact the various actions take on different values in these enums.
    
    Introduce helpers to properly map the enum values.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>

Index: libvirt-1.2.5/src/libxl/libxl_conf.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_conf.c
+++ libvirt-1.2.5/src/libxl/libxl_conf.c
@@ -102,6 +102,62 @@ libxlDriverConfigDispose(void *obj)
     VIR_FREE(cfg->autoDumpDir);
 }
 
+
+static libxl_action_on_shutdown
+libxlActionFromVirLifecycle(enum virDomainLifecycleAction action)
+{
+    switch (action) {
+    case VIR_DOMAIN_LIFECYCLE_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_RESTART:
+        return  LIBXL_ACTION_ON_SHUTDOWN_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
+        return LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME;
+
+    case VIR_DOMAIN_LIFECYCLE_PRESERVE:
+        return LIBXL_ACTION_ON_SHUTDOWN_PRESERVE;
+
+    case VIR_DOMAIN_LIFECYCLE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
+static libxl_action_on_shutdown
+libxlActionFromVirLifecycleCrash(enum virDomainLifecycleCrashAction action)
+{
+
+    switch (action) {
+    case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART:
+        return  LIBXL_ACTION_ON_SHUTDOWN_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
+        return LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
+        return LIBXL_ACTION_ON_SHUTDOWN_PRESERVE;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART:
+        return LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
 static int
 libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
 {
@@ -1402,9 +1458,9 @@ libxlBuildDomainConfig(libxlDriverPrivat
     if (libxlMakePCIList(def, d_config) < 0)
         return -1;
 
-    d_config->on_reboot = def->onReboot;
-    d_config->on_poweroff = def->onPoweroff;
-    d_config->on_crash = def->onCrash;
+    d_config->on_reboot = libxlActionFromVirLifecycle(def->onReboot);
+    d_config->on_poweroff = libxlActionFromVirLifecycle(def->onPoweroff);
+    d_config->on_crash = libxlActionFromVirLifecycleCrash(def->onCrash);
 
     return 0;
 }