]> xenbits.xensource.com Git - libvirt.git/commitdiff
src/xenxs: Refactor code parsing event actions
authorKiarie Kahurani <davidkiarie4@gmail.com>
Thu, 7 Aug 2014 18:32:52 +0000 (21:32 +0300)
committerJim Fehlig <jfehlig@suse.com>
Fri, 8 Aug 2014 17:35:37 +0000 (11:35 -0600)
introduce function
  xenParseXMEventActions(virConfPtr conf,........)
which parses events leading to certain actions

Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
src/xenxs/xen_xm.c

index baee7eac139f35ca021ee4d438dcfa63550c145b..6f1339e12f0a441dddafa1df835acac8d9482cac 100644 (file)
@@ -303,6 +303,42 @@ xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def,
 }
 
 
+static int
+xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def)
+{
+    const char *str = NULL;
+
+    if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0)
+        return -1;
+
+    if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected value %s for on_poweroff"), str);
+        return -1;
+    }
+
+    if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0)
+        return -1;
+
+    if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected value %s for on_reboot"), str);
+        return -1;
+    }
+
+    if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0)
+        return -1;
+
+    if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected value %s for on_crash"), str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 #define MAX_VFB 1024
 
 /*
@@ -435,31 +471,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
     if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0))
             goto cleanup;
 
-    if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0)
+    if (xenParseXMEventsActions(conf, def) < 0)
         goto cleanup;
-    if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected value %s for on_poweroff"), str);
-        goto cleanup;
-    }
-
-    if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0)
-        goto cleanup;
-    if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected value %s for on_reboot"), str);
-        goto cleanup;
-    }
-
-    if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0)
-        goto cleanup;
-    if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected value %s for on_crash"), str);
-        goto cleanup;
-    }
-
-
 
     if (hvm) {
         if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0)