[libvirt] [PREPOST 11/17] src/xenxs:Refactor code formating general information

David Kiarie davidkiarie4 at gmail.com
Thu Jul 10 13:43:05 UTC 2014


From: Kiarie Kahurani <davidkiarie4 at gmail.com>

refactor code parsing uuid, memory and name options

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

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 657dd1c..a907252 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1609,6 +1609,31 @@ xenFormatXMPCI(virConfPtr conf,
    either 32, or 64 on a platform where long is big enough.  */
 verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
 
+static int xenFormatXMGeneral(virConfPtr conf, virDomainDefPtr def)
+{
+    char uuid[VIR_UUID_STRING_BUFLEN];
+
+    if (xenXMConfigSetString(conf, "name", def->name) < 0)
+        return -1;
+
+    virUUIDFormat(def->uuid, uuid);
+    if (xenXMConfigSetString(conf, "uuid", uuid) < 0)
+        return -1;
+
+    return 0;
+}
+static int xenFormatXMMem(virConfPtr conf, virDomainDefPtr def)
+{
+    if (xenXMConfigSetInt(conf, "maxmem",
+                          VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
+        return -1;
+
+    if (xenXMConfigSetInt(conf, "memory",
+                          VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
+        return -1;
+
+    return 0;
+}
 virConfPtr xenFormatXM(virConnectPtr conn,
                                    virDomainDefPtr def,
                                    int xendConfigVersion)
@@ -1618,27 +1643,16 @@ virConfPtr xenFormatXM(virConnectPtr conn,
     size_t i;
     char *cpus = NULL;
     const char *lifecycle;
-    char uuid[VIR_UUID_STRING_BUFLEN];
     virConfValuePtr diskVal = NULL;
     virConfValuePtr netVal = NULL;
 
     if (!(conf = virConfNew()))
         goto cleanup;
 
-
-    if (xenXMConfigSetString(conf, "name", def->name) < 0)
-        goto cleanup;
-
-    virUUIDFormat(def->uuid, uuid);
-    if (xenXMConfigSetString(conf, "uuid", uuid) < 0)
+    if (xenFormatXMGeneral(conf, def) < 0)
         goto cleanup;
 
-    if (xenXMConfigSetInt(conf, "maxmem",
-                          VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
-        goto cleanup;
-
-    if (xenXMConfigSetInt(conf, "memory",
-                          VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
+    if (xenFormatXMMem(conf, def) < 0)
         goto cleanup;
 
     if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
-- 
1.8.4.5




More information about the libvir-list mailing list