David Kiarie wrote:
From: Kiarie Kahurani <davidkiarie4(a)gmail.com>
refactor code parsing uuid, memory and name options
signed-off-by:David Kiarie<davidkiarie4(a)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)
Similar comment here as in 1/17 regarding the name xenFormatXMGeneral.
I'd suggest something like xenFormatXMGeneralMeta.
+{
+ 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;
+}
You split the general and mem functions in separate patches on the parse
side. I think that is a good approach on the format side too.
Regards,
Jim
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)