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

Re: [libvirt] [PATCH] Add actions to virDomainLifecycle enum



Jim Fehlig wrote:
> Eric Blake wrote:
>   
>> Hmm.  These two new values are only valid for on_crash, but I don't see
>> any code that rejects them for on_reboot or on_poweroff.  Do we need a
>> separate enum here, or do we just need to add better checking to the
>> remaining clients to detect enum values they can't support?
>>   
>>     
>
> Good point.  I moved these new options into a new enum and adjusted the
> code accordingly.
>
> V2 attached.
>   

Any comments on V2 of this patch?

Regards,
Jim

>From b0e7400d3a32c71e4eb82294f1d9bf712d94af8a Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig novell com>
Date: Thu, 12 Aug 2010 10:25:56 -0600
Subject: [PATCH] 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.

V2:
  - Create new enum to hold valid on_crash options
  - Reject coredump-{destory,restart} for on_{reboot,poweroff}
---
 docs/formatdomain.html.in |   14 ++++++++++++++
 docs/schemas/domain.rng   |   25 ++++++++++++++++++++++++-
 src/conf/domain_conf.c    |   37 +++++++++++++++++++++++++++----------
 src/conf/domain_conf.h    |   15 +++++++++++++++
 src/xen/xend_internal.c   |    4 ++--
 src/xen/xm_internal.c     |    4 ++--
 src/xenapi/xenapi_utils.c |   30 +++++++++++++++++++-----------
 src/xenapi/xenapi_utils.h |    4 ++--
 8 files changed, 105 insertions(+), 28 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 5269cc5..0d532e2 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -366,6 +366,20 @@
         a new name</dd>
     </dl>
 
+    <p>
+      on_crash supports these additional actions.
+    </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>
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 1e42827..ccb8cf3 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -1177,7 +1177,7 @@
       </optional>
       <optional>
         <element name="on_crash">
-          <ref name="offOptions"/>
+          <ref name="crashOptions"/>
         </element>
       </optional>
     </interleave>
@@ -1199,6 +1199,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.
     -->
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c6534b8..ee99cd1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -83,6 +83,14 @@ VIR_ENUM_IMPL(virDomainLifecycle, VIR_DOMAIN_LIFECYCLE_LAST,
               "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",
@@ -3763,13 +3771,14 @@ error:
 static int virDomainLifecycleParseXML(xmlXPathContextPtr ctxt,
                                       const char *xpath,
                                       int *val,
-                                      int defaultVal)
+                                      int defaultVal,
+                                      virLifecycleFromStringFunc convFunc)
 {
     char *tmp = virXPathString(xpath, ctxt);
     if (tmp == NULL) {
         *val = defaultVal;
     } else {
-        *val = virDomainLifecycleTypeFromString(tmp);
+        *val = convFunc(tmp);
         if (*val < 0) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                                  _("unknown lifecycle action %s"), tmp);
@@ -4253,15 +4262,19 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
 
     if (virDomainLifecycleParseXML(ctxt, "string(./on_reboot[1])",
-                                   &def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART) < 0)
+                                   &def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART,
+                                   virDomainLifecycleTypeFromString) < 0)
         goto error;
 
     if (virDomainLifecycleParseXML(ctxt, "string(./on_poweroff[1])",
-                                   &def->onPoweroff, VIR_DOMAIN_LIFECYCLE_DESTROY) < 0)
+                                   &def->onPoweroff, VIR_DOMAIN_LIFECYCLE_DESTROY,
+                                   virDomainLifecycleTypeFromString) < 0)
         goto error;
 
     if (virDomainLifecycleParseXML(ctxt, "string(./on_crash[1])",
-                                   &def->onCrash, VIR_DOMAIN_LIFECYCLE_DESTROY) < 0)
+                                        &def->onCrash,
+                                   VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY,
+                                   virDomainLifecycleCrashTypeFromString) < 0)
         goto error;
 
     tmp = virXPathString("string(./clock/@offset)", ctxt);
@@ -5396,9 +5409,10 @@ virDomainCpuSetParse(const char **str, char sep,
 static int
 virDomainLifecycleDefFormat(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(VIR_ERR_INTERNAL_ERROR,
                              _("unexpected lifecycle type %d"), type);
@@ -6483,13 +6497,16 @@ char *virDomainDefFormat(virDomainDefPtr def,
     }
 
     if (virDomainLifecycleDefFormat(&buf, def->onPoweroff,
-                                    "on_poweroff") < 0)
+                                    "on_poweroff",
+                                    virDomainLifecycleTypeToString) < 0)
         goto cleanup;
     if (virDomainLifecycleDefFormat(&buf, def->onReboot,
-                                    "on_reboot") < 0)
+                                    "on_reboot",
+                                    virDomainLifecycleTypeToString) < 0)
         goto cleanup;
     if (virDomainLifecycleDefFormat(&buf, def->onCrash,
-                                    "on_crash") < 0)
+                                    "on_crash",
+                                    virDomainLifecycleCrashTypeToString) < 0)
         goto cleanup;
 
     virBufferAddLit(&buf, "  <devices>\n");
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 4361d5b..92f98bc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -663,6 +663,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;
@@ -1135,10 +1146,14 @@ int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
                                 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)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 311775a..d47c625 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2206,7 +2206,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(VIR_ERR_INTERNAL_ERROR,
                          _("unknown lifecycle type %s"), tmp);
             goto error;
@@ -5693,7 +5693,7 @@ xenDaemonFormatSxpr(virConnectPtr conn,
     }
     virBufferVSprintf(&buf, "(on_reboot '%s')", tmp);
 
-    if (!(tmp = virDomainLifecycleTypeToString(def->onCrash))) {
+    if (!(tmp = virDomainLifecycleCrashTypeToString(def->onCrash))) {
         virXendError(VIR_ERR_INTERNAL_ERROR,
                      _("unexpected lifecycle value %d"), def->onCrash);
         goto error;
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 153c7a5..fe13e8a 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -803,7 +803,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
 
     if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0)
         goto cleanup;
-    if ((def->onCrash = virDomainLifecycleTypeFromString(str)) < 0) {
+    if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) {
         xenXMError(VIR_ERR_INTERNAL_ERROR,
                    _("unexpected value %s for on_crash"), str);
         goto cleanup;
@@ -2378,7 +2378,7 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,
         goto no_memory;
 
 
-    if (!(lifecycle = virDomainLifecycleTypeToString(def->onCrash))) {
+    if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
         xenXMError(VIR_ERR_INTERNAL_ERROR,
                    _("unexpected lifecycle action %d"), def->onCrash);
         goto cleanup;
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 4eb17fa..4ea9ce5 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -153,17 +153,21 @@ actionShutdownLibvirt2XenapiEnum(enum virDomainLifecycleAction action)
 
 
 enum xen_on_crash_behaviour
-actionCrashLibvirt2XenapiEnum(enum virDomainLifecycleAction action)
+actionCrashLibvirt2XenapiEnum(enum virDomainLifecycleCrashAction action)
 {
     enum xen_on_crash_behaviour num = XEN_ON_CRASH_BEHAVIOUR_RESTART;
-    if (action == VIR_DOMAIN_LIFECYCLE_DESTROY)
+    if (action == VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY)
         num = XEN_ON_CRASH_BEHAVIOUR_DESTROY;
-    else if (action == VIR_DOMAIN_LIFECYCLE_RESTART)
+    else if (action == VIR_DOMAIN_LIFECYCLE_CRASH_RESTART)
         num = XEN_ON_CRASH_BEHAVIOUR_RESTART;
-    else if (action == VIR_DOMAIN_LIFECYCLE_PRESERVE)
+    else if (action == VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE)
         num = XEN_ON_CRASH_BEHAVIOUR_PRESERVE;
-    else if (action == VIR_DOMAIN_LIFECYCLE_RESTART_RENAME)
+    else if (action == VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME)
         num = XEN_ON_CRASH_BEHAVIOUR_RENAME_RESTART;
+    else if (action == VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY)
+        num = XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_DESTROY;
+    else if (action == VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART)
+        num = XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_RESTART;
     return num;
 }
 
@@ -218,18 +222,22 @@ xenapiNormalExitEnum2virDomainLifecycle(enum xen_on_normal_exit action)
 }
 
 
-enum virDomainLifecycleAction
+enum virDomainLifecycleCrashAction
 xenapiCrashExitEnum2virDomainLifecycle(enum xen_on_crash_behaviour action)
 {
-    enum virDomainLifecycleAction num = VIR_DOMAIN_LIFECYCLE_RESTART;
+    enum virDomainLifecycleCrashAction num = VIR_DOMAIN_LIFECYCLE_CRASH__RESTART;
     if (action == XEN_ON_CRASH_BEHAVIOUR_DESTROY)
-        num = VIR_DOMAIN_LIFECYCLE_DESTROY;
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY;
     else if (action == XEN_ON_CRASH_BEHAVIOUR_RESTART)
-        num = VIR_DOMAIN_LIFECYCLE_RESTART;
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_RESTART;
     else if (action == XEN_ON_CRASH_BEHAVIOUR_PRESERVE)
-        num = VIR_DOMAIN_LIFECYCLE_PRESERVE;
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE;
     else if (action == XEN_ON_CRASH_BEHAVIOUR_RENAME_RESTART)
-        num = VIR_DOMAIN_LIFECYCLE_RESTART_RENAME;
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME;
+    else if (action == XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_DESTROY)
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY;
+    else if (action == XEN_ON_CRASH_BEHAVIOUR_COREDUMP_AND_RESTART)
+        num = VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART;
     return num;
 }
 
diff --git a/src/xenapi/xenapi_utils.h b/src/xenapi/xenapi_utils.h
index c062a1e..71b129a 100644
--- a/src/xenapi/xenapi_utils.h
+++ b/src/xenapi/xenapi_utils.h
@@ -46,7 +46,7 @@ enum xen_on_normal_exit
 actionShutdownLibvirt2XenapiEnum(enum virDomainLifecycleAction action);
 
 enum xen_on_crash_behaviour
-actionCrashLibvirt2XenapiEnum(enum virDomainLifecycleAction action);
+actionCrashLibvirt2XenapiEnum(enum virDomainLifecycleCrashAction action);
 
 char *
 createXenAPIBootOrderString(int nboot, int *bootDevs);
@@ -56,7 +56,7 @@ enum virDomainBootOrder map2LibvirtBootOrder(char c);
 enum virDomainLifecycleAction
 xenapiNormalExitEnum2virDomainLifecycle(enum xen_on_normal_exit action);
 
-enum virDomainLifecycleAction
+enum virDomainLifecycleCrashAction
 xenapiCrashExitEnum2virDomainLifecycle(enum xen_on_crash_behaviour action);
 
 void getCpuBitMapfromString(char *mask, unsigned char *cpumap, int maplen);
-- 
1.6.0.2


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