[PATCH V5 05/12] src/xenxs: Refactor code formating event actions config

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

 



introduce function
   xenFormatXMEventActions(virConfPtr conf,.........);
which formats event actions instead

Signed-off-by: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>
---
 src/xenxs/xen_xm.c | 63 +++++++++++++++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index b17574d..677735d 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1784,6 +1784,41 @@ xenFormatXMTimeOffset(virConfPtr conf, virDomainDefPtr def,
 
     return 0;
 }
+
+
+static int
+xenFormatXMEventActions(virConfPtr conf, virDomainDefPtr def)
+{
+    const char *lifecycle = NULL;
+
+    if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected lifecycle action %d"), def->onPoweroff);
+        return -1;
+    }
+    if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0)
+        return -1;
+
+
+    if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected lifecycle action %d"), def->onReboot);
+        return -1;
+    }
+    if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0)
+        return -1;
+
+
+    if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected lifecycle action %d"), def->onCrash);
+        return -1;
+    }
+    if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0)
+        return -1;
+
+    return 0;
+}
 /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
    either 32, or 64 on a platform where long is big enough.  */
 verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
@@ -1797,7 +1832,6 @@ xenFormatXM(virConnectPtr conn,
     int hvm = 0;
     size_t i;
     char *cpus = NULL;
-    const char *lifecycle;
     virConfValuePtr diskVal = NULL;
     virConfValuePtr netVal = NULL;
 
@@ -1936,33 +1970,8 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0)
         goto cleanup;
 
-    if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected lifecycle action %d"), def->onPoweroff);
-        goto cleanup;
-    }
-    if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0)
-        goto cleanup;
-
-
-    if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected lifecycle action %d"), def->onReboot);
+    if (xenFormatXMEventActions(conf, def) < 0)
         goto cleanup;
-    }
-    if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0)
-        goto cleanup;
-
-
-    if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected lifecycle action %d"), def->onCrash);
-        goto cleanup;
-    }
-    if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0)
-        goto cleanup;
-
-
 
     if (hvm) {
         if (def->emulator &&
-- 
1.8.4.5

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