[libvirt] [PREPOST 09/17] src/xenxs:Refactor OS and Miscellaneous deivices config

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


From: Kiarie Kahurani <davidkiarie4 at gmail.com>

Introduce functions
 xenParseXMOS(.....) and
 xenParseXMMisc(.....) to parse the OS and
Miscellaneous devices configs

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

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 89d5739..312d890 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1020,36 +1020,21 @@ static int xenParseXMVfb(virConfPtr conf, virDomainDefPtr def,
     virDomainGraphicsDefFree(graphics);
     return -1;
 }
-virDomainDefPtr
-xenParseXM(virConfPtr conf, int xendConfigVersion,
-                       virCapsPtr caps)
+static int xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
 {
-    const char *str;
-    int hvm = 0;
-    virConfValuePtr list;
-    virDomainDefPtr def = NULL;
-    virDomainDiskDefPtr disk = NULL;
-    virDomainNetDefPtr net = NULL;
-    virDomainGraphicsDefPtr graphics = NULL;
     size_t i;
-    char *script = NULL;
-    char *listenAddr = NULL;
-
-    if (VIR_ALLOC(def) < 0)
-        return NULL;
 
-    def->virtType = VIR_DOMAIN_VIRT_XEN;
-    def->id = -1;
-    if (xenParseXMGeneral(conf, def, caps) < 0)
-        goto cleanup;
-    hvm = (STREQ(def->os.type, "hvm"));
-    if (hvm) {
+    if (STREQ(def->os.type, "hvm")) {
         const char *boot;
+
+        if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
+            return -1;
+
         if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
-            goto cleanup;
+            return -1;
 
         if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
-            goto cleanup;
+            return -1;
 
         for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
             switch (*boot) {
@@ -1073,55 +1058,52 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
         const char *extra, *root;
 
         if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
-            goto cleanup;
+            return -1;
         if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
-            goto cleanup;
+            return -1;
 
         if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
-            goto cleanup;
+            return -1;
         if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
-            goto cleanup;
+            return -1;
         if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
-            goto cleanup;
+            return -1;
         if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
-            goto cleanup;
+            return -1;
 
         if (root) {
             if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
-                goto cleanup;
+                return -1;
         } else {
             if (VIR_STRDUP(def->os.cmdline, extra) < 0)
-                goto cleanup;
+                return -1;
         }
     }
-    if (xenParseXMMem(conf, def) < 0)
-        goto cleanup;
-    if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
-        goto cleanup;
-   if (xenParseXMVif(conf, def) < 0)
-       goto cleanup;
-
-   if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
-       goto cleanup;
-   if (xenParseXMEventsActions(conf, def) < 0)
-       goto cleanup;
-   if (xenParseXMPCI(conf, def) < 0)
-       goto cleanup;
-   if (xenParseXMCPUFeatures(conf, def) < 0)
-       goto cleanup;
-   if (xenParseXMDisk(conf, def, xendConfigVersion) < 0)
-       goto cleanup;
-
-   if (hvm) {
+
+    return 0;
+}
+static int xenParseXMMisc(virConfPtr conf, virDomainDefPtr def)
+{
+    const char *str;
+
+    if (STREQ(def->os.type, "hvm")) {
+        if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0)
+            return -1;
+
+        if (str &&
+            xenParseSxprSound(def, str) < 0)
+            return -1;
+
         if (xenXMConfigGetString(conf, "usbdevice", &str, NULL) < 0)
-            goto cleanup;
+            return -1;
+
         if (str &&
             (STREQ(str, "tablet") ||
              STREQ(str, "mouse") ||
              STREQ(str, "keyboard"))) {
             virDomainInputDefPtr input;
             if (VIR_ALLOC(input) < 0)
-                goto cleanup;
+                return -1;
             input->bus = VIR_DOMAIN_INPUT_BUS_USB;
             if (STREQ(str, "mouse"))
                 input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
@@ -1131,15 +1113,61 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                 input->type = VIR_DOMAIN_INPUT_TYPE_KBD;
             if (VIR_ALLOC_N(def->inputs, 1) < 0) {
                 virDomainInputDefFree(input);
-                goto cleanup;
+                return -1;
             }
             def->inputs[0] = input;
             def->ninputs = 1;
         }
     }
-    if (xenParseXMVfb(conf, def, xendConfigVersion) < 0)
+
+    return 0;
+}
+virDomainDefPtr
+xenParseXM(virConfPtr conf, int xendConfigVersion,
+                       virCapsPtr caps)
+{
+    const char *str;
+    int hvm = 0;
+    virConfValuePtr list;
+    virDomainDefPtr def = NULL;
+    virDomainDiskDefPtr disk = NULL;
+    virDomainNetDefPtr net = NULL;
+    virDomainGraphicsDefPtr graphics = NULL;
+    char *script = NULL;
+    char *listenAddr = NULL;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    def->virtType = VIR_DOMAIN_VIRT_XEN;
+    def->id = -1;
+    if (xenParseXMGeneral(conf, def, caps) < 0)
         goto cleanup;
 
+    if (xenParseXMOS(conf, def) < 0)
+        goto cleanup;
+
+    hvm = (STREQ(def->os.type, "hvm"));
+    if (xenParseXMMem(conf, def) < 0)
+        goto cleanup;
+    if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
+        goto cleanup;
+    if (xenParseXMVif(conf, def) < 0)
+        goto cleanup;
+    if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
+        goto cleanup;
+    if (xenParseXMEventsActions(conf, def) < 0)
+        goto cleanup;
+    if (xenParseXMPCI(conf, def) < 0)
+        goto cleanup;
+    if (xenParseXMCPUFeatures(conf, def) < 0)
+        goto cleanup;
+    if (xenParseXMDisk(conf, def, xendConfigVersion) < 0)
+        goto cleanup;
+    if (xenParseXMVfb(conf, def, xendConfigVersion) < 0)
+        goto cleanup;
+    if (xenParseXMMisc(conf, def) < 0)
+        goto cleanup;
     if (hvm) {
         virDomainChrDefPtr chr = NULL;
 
@@ -1221,16 +1249,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
         def->consoles[0]->target.port = 0;
         def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
     }
-
-    if (hvm) {
-        if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0)
-            goto cleanup;
-
-        if (str &&
-            xenParseSxprSound(def, str) < 0)
-            goto cleanup;
-    }
-
     VIR_FREE(script);
     return def;
 
-- 
1.8.4.5




More information about the libvir-list mailing list