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

[libvirt] [PATCH V3 11/24] src/xenxs:Refactor code parsing general config



From: Kiarie Kahurani <davidkiarie4 gmail com>

introduce function
   xenParseXMGeneralMeta(virConfPtr conf, .......);
which parses general metadata instead

signed-off-by: David Kiarie<davidkiarie4 gmail com>
---
 src/xenxs/xen_xm.c | 58 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 9eabfa4..32c6d8c 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1131,38 +1131,28 @@ xenParseXMEmulatedDevices(virConfPtr conf, virDomainDefPtr def)
     return 0;
 }
 
-/*
- * Turn a config record into a lump of XML describing the
- * domain, suitable for later feeding for virDomainCreateXML
- */
-virDomainDefPtr
-xenParseXM(virConfPtr conf, int xendConfigVersion,
-           virCapsPtr caps)
+
+static int
+xenParseXMGeneralMeta(virConfPtr conf, virDomainDefPtr def,
+                      virCapsPtr caps)
 {
+
+    const char *defaultMachine;
     const char *str;
     int hvm = 0;
-    virDomainDefPtr def = NULL;
-    size_t i;
-    const char *defaultMachine;
-
-    if (VIR_ALLOC(def) < 0)
-        return NULL;
-
-    def->virtType = VIR_DOMAIN_VIRT_XEN;
-    def->id = -1;
 
     if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
-        goto cleanup;
-    if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
-        goto cleanup;
+        return -1;
 
+    if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
+        return -1;
 
     if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
         STREQ(str, "hvm"))
         hvm = 1;
 
     if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
-        goto cleanup;
+        return -1;
 
     def->os.arch =
         virCapabilitiesDefaultGuestArch(caps,
@@ -1172,7 +1162,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("no supported architecture for os type '%s'"),
                        def->os.type);
-        goto cleanup;
+        return -1;
     }
 
     defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
@@ -1181,10 +1171,32 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                                                         virDomainVirtTypeToString(def->virtType));
     if (defaultMachine != NULL) {
         if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
-            goto cleanup;
+            return -1;
     }
 
-    if (hvm) {
+    return 0;
+}
+/*
+ * Turn a config record into a lump of XML describing the
+ * domain, suitable for later feeding for virDomainCreateXML
+ */
+virDomainDefPtr
+xenParseXM(virConfPtr conf, int xendConfigVersion,
+           virCapsPtr caps)
+{
+    virDomainDefPtr def = NULL;
+    size_t i;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    def->virtType = VIR_DOMAIN_VIRT_XEN;
+    def->id = -1;
+
+    if (xenParseXMGeneralMeta(conf, def, caps) < 0)
+        goto cleanup;
+
+    if (STREQ(def->os.type, "hvm")) {
         const char *boot;
         if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
             goto cleanup;
-- 
1.8.4.5


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