commit b9c10268e14b5f6a8a405813406964ccade67fcb
Author: Jim Fehlig <jfehlig@novell.com>
Date:   Thu Aug 12 11:15:44 2010 -0600

    Add actions to virDomainLifecycle enum
    
    Xen supports on_crash actions coredump-{destroy,restart}.  libvirt
    cannot parse config returned by xend that contains either of these
    actions
    
    xen52 # xm li -l test | grep on_crash
        (on_crash coredump-restart)
    xen52 # virsh dumpxml test
    error: internal error unknown lifecycle type coredump-restart
    
    This patch adds a new virDomainLifecycleCrash enum and appends
    the new options to existing destroy, restart, preserve, and
    rename-restart options.

Index: libvirt-0.7.6/docs/formatdomain.html.in
===================================================================
--- libvirt-0.7.6.orig/docs/formatdomain.html.in
+++ libvirt-0.7.6/docs/formatdomain.html.in
@@ -343,6 +343,21 @@
         a new name</dd>
     </dl>
 
+    <p>
+      on_crash supports these additional
+      actions <span class="since">since 0.8.4</span>.
+    </p>
+
+    <dl>
+      <dt><code>coredump-destroy</code></dt>
+      <dd>The crashed domain's core will be dumped, and then the
+        domain will be terminated completely and all resources
+        released</dd>
+      <dt><code>coredump-restart</code></dt>
+      <dd>The crashed domain's core will be dumped, and then the
+        domain will be restarted with the same configuration</dd>
+    </dl>
+
     <h3><a name="elementsFeatures">Hypervisor features</a></h3>
 
     <p>
Index: libvirt-0.7.6/docs/schemas/domain.rng
===================================================================
--- libvirt-0.7.6.orig/docs/schemas/domain.rng
+++ libvirt-0.7.6/docs/schemas/domain.rng
@@ -953,7 +953,7 @@
       </optional>
       <optional>
         <element name="on_crash">
-          <ref name="offOptions"/>
+          <ref name="crashOptions"/>
         </element>
       </optional>
     </interleave>
@@ -975,6 +975,29 @@
     </choice>
   </define>
   <!--
+      Options when a domain crashes:
+      destroy: The domain is cleaned up
+      restart: A new domain is started in place of the old one
+      preserve: The domain will remain in memory until it is destroyed manually
+      rename-restart: a variant of the previous one but where the old domain is
+                      renamed before being saved to allow a restart
+      coredump-destroy: The crashed domain's core will be dumped, and then the
+                        domain will be terminated completely and all resources
+                        released
+      coredump-restart: The crashed domain's core will be dumped, and then the
+                        domain will be restarted with the same configuration
+    -->
+  <define name="crashOptions">
+    <choice>
+      <value>destroy</value>
+      <value>restart</value>
+      <value>preserve</value>
+      <value>rename-restart</value>
+      <value>coredump-destroy</value>
+      <value>coredump-restart</value>
+    </choice>
+  </define>
+  <!--
       Specific setup for a qemu emulated character device.  Note: this
       definition doesn't fully specify the constraints on this node.
     -->
Index: libvirt-0.7.6/src/conf/domain_conf.c
===================================================================
--- libvirt-0.7.6.orig/src/conf/domain_conf.c
+++ libvirt-0.7.6/src/conf/domain_conf.c
@@ -79,6 +79,14 @@ VIR_ENUM_IMPL(virDomainLifecycle, VIR_DO
               "rename-restart",
               "preserve")
 
+VIR_ENUM_IMPL(virDomainLifecycleCrash, VIR_DOMAIN_LIFECYCLE_CRASH_LAST,
+              "destroy",
+              "restart",
+              "rename-restart",
+              "preserve",
+              "coredump-destroy",
+              "coredump-restart")
+
 VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST,
               "disk",
               "filesystem",
@@ -3042,13 +3050,14 @@ static int virDomainLifecycleParseXML(vi
                                       xmlXPathContextPtr ctxt,
                                       const char *xpath,
                                       int *val,
-                                      int defaultVal)
+                                      int defaultVal,
+                                      virLifecycleFromStringFunc convFunc)
 {
     char *tmp = virXPathString(conn, xpath, ctxt);
     if (tmp == NULL) {
         *val = defaultVal;
     } else {
-        *val = virDomainLifecycleTypeFromString(tmp);
+        *val = convFunc(tmp);
         if (*val < 0) {
             virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                  _("unknown lifecycle action %s"), tmp);
@@ -3466,15 +3475,19 @@ static virDomainDefPtr virDomainDefParse
     }
 
     if (virDomainLifecycleParseXML(conn, ctxt, "string(./on_reboot[1])",
-                                   &def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART) < 0)
+                                   &def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART,
+                                   virDomainLifecycleTypeFromString) < 0)
         goto error;
 
     if (virDomainLifecycleParseXML(conn, ctxt, "string(./on_poweroff[1])",
-                                   &def->onPoweroff, VIR_DOMAIN_LIFECYCLE_DESTROY) < 0)
+                                   &def->onPoweroff, VIR_DOMAIN_LIFECYCLE_DESTROY,
+                                   virDomainLifecycleTypeFromString) < 0)
         goto error;
 
     if (virDomainLifecycleParseXML(conn, ctxt, "string(./on_crash[1])",
-                                   &def->onCrash, VIR_DOMAIN_LIFECYCLE_DESTROY) < 0)
+                                   &def->onCrash,
+                                   VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY,
+                                   virDomainLifecycleCrashTypeFromString) < 0)
         goto error;
 
 
@@ -4656,9 +4669,10 @@ static int
 virDomainLifecycleDefFormat(virConnectPtr conn,
                             virBufferPtr buf,
                             int type,
-                            const char *name)
+                            const char *name,
+                            virLifecycleToStringFunc convFunc)
 {
-    const char *typeStr = virDomainLifecycleTypeToString(type);
+    const char *typeStr = convFunc(type);
     if (!typeStr) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
                              _("unexpected lifecycle type %d"), type);
@@ -5527,13 +5541,16 @@ char *virDomainDefFormat(virConnectPtr c
                       def->localtime ? "localtime" : "utc");
 
     if (virDomainLifecycleDefFormat(conn, &buf, def->onPoweroff,
-                                    "on_poweroff") < 0)
+                                    "on_poweroff",
+                                    virDomainLifecycleTypeToString) < 0)
         goto cleanup;
     if (virDomainLifecycleDefFormat(conn, &buf, def->onReboot,
-                                    "on_reboot") < 0)
+                                    "on_reboot",
+                                    virDomainLifecycleTypeToString) < 0)
         goto cleanup;
     if (virDomainLifecycleDefFormat(conn, &buf, def->onCrash,
-                                    "on_crash") < 0)
+                                    "on_crash",
+                                    virDomainLifecycleCrashTypeToString) < 0)
         goto cleanup;
 
     virBufferAddLit(&buf, "  <devices>\n");
Index: libvirt-0.7.6/src/conf/domain_conf.h
===================================================================
--- libvirt-0.7.6.orig/src/conf/domain_conf.h
+++ libvirt-0.7.6/src/conf/domain_conf.h
@@ -558,6 +558,17 @@ enum virDomainLifecycleAction {
     VIR_DOMAIN_LIFECYCLE_LAST
 };
 
+enum virDomainLifecycleCrashAction {
+    VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY,
+    VIR_DOMAIN_LIFECYCLE_CRASH_RESTART,
+    VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME,
+    VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE,
+    VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY,
+    VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART,
+
+    VIR_DOMAIN_LIFECYCLE_CRASH_LAST
+};
+
 /* Operating system configuration data & machine / arch */
 typedef struct _virDomainOSDef virDomainOSDef;
 typedef virDomainOSDef *virDomainOSDefPtr;
@@ -898,10 +909,14 @@ int virDomainDiskDefForeachPath(virConne
                                 virDomainDiskDefPathIterator iter,
                                 void *opaque);
 
+typedef const char* (*virLifecycleToStringFunc)(int type);
+typedef int (*virLifecycleFromStringFunc)(const char *type);
+
 VIR_ENUM_DECL(virDomainVirt)
 VIR_ENUM_DECL(virDomainBoot)
 VIR_ENUM_DECL(virDomainFeature)
 VIR_ENUM_DECL(virDomainLifecycle)
+VIR_ENUM_DECL(virDomainLifecycleCrash)
 VIR_ENUM_DECL(virDomainDevice)
 VIR_ENUM_DECL(virDomainDeviceAddress)
 VIR_ENUM_DECL(virDomainDeviceAddressMode)
Index: libvirt-0.7.6/src/xen/xend_internal.c
===================================================================
--- libvirt-0.7.6.orig/src/xen/xend_internal.c
+++ libvirt-0.7.6/src/xen/xend_internal.c
@@ -2460,7 +2460,7 @@ xenDaemonParseSxpr(virConnectPtr conn,
 
     tmp = sexpr_node(root, "domain/on_crash");
     if (tmp != NULL) {
-        if ((def->onCrash = virDomainLifecycleTypeFromString(tmp)) < 0) {
+        if ((def->onCrash = virDomainLifecycleCrashTypeFromString(tmp)) < 0) {
             virXendError(conn, VIR_ERR_INTERNAL_ERROR,
                          _("unknown lifecycle type %s"), tmp);
             goto error;
@@ -5858,7 +5858,7 @@ xenDaemonFormatSxpr(virConnectPtr conn,
     }
     virBufferVSprintf(&buf, "(on_reboot '%s')", tmp);
 
-    if (!(tmp = virDomainLifecycleTypeToString(def->onCrash))) {
+    if (!(tmp = virDomainLifecycleCrashTypeToString(def->onCrash))) {
         virXendError(conn, VIR_ERR_INTERNAL_ERROR,
                      _("unexpected lifecycle value %d"), def->onCrash);
         goto error;
Index: libvirt-0.7.6/src/xen/xm_internal.c
===================================================================
--- libvirt-0.7.6.orig/src/xen/xm_internal.c
+++ libvirt-0.7.6/src/xen/xm_internal.c
@@ -808,7 +808,7 @@ xenXMDomainConfigParse(virConnectPtr con
 
     if (xenXMConfigGetString(conn, conf, "on_crash", &str, "restart") < 0)
         goto cleanup;
-    if ((def->onCrash = virDomainLifecycleTypeFromString(str)) < 0) {
+    if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) {
         xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                    _("unexpected value %s for on_crash"), str);
         goto cleanup;
@@ -2380,7 +2380,7 @@ virConfPtr xenXMDomainConfigFormat(virCo
         goto no_memory;
 
 
-    if (!(lifecycle = virDomainLifecycleTypeToString(def->onCrash))) {
+    if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
         xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                    _("unexpected lifecycle action %d"), def->onCrash);
         goto cleanup;
