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

[libvirt] [PATCH V3 23/24] src/xenxs:Refactor code formating emulated devices config



From: Kiarie Kahurani <davidkiarie4 gmail com>

introduce function
  xenFormatXMEmulatedHardware(virConfPtr conf,....);
which  formats emulated hardware config instead

signed-off-by: David Kiarie<davidkiarie4 gmail com>
---
 src/xenxs/xen_xm.c                         | 150 +++++++++++++++++------------
 tests/xmconfigdata/test-escape-paths.cfg   |   2 +-
 tests/xmconfigdata/test-fullvirt-sound.cfg |   2 +-
 3 files changed, 92 insertions(+), 62 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index bf5a23a..071802d 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -2206,6 +2206,93 @@ xenFormatXMVfb(virConfPtr conf, virDomainDefPtr def,
 
     return 0;
 }
+
+
+static int
+xenFormatXMVif(virConfPtr conf, virConnectPtr conn,
+               virDomainDefPtr def, int xendConfigVersion)
+{
+   virConfValuePtr netVal = NULL;
+   size_t i;
+   int hvm = STREQ(def->os.type, "hvm");
+
+   if (VIR_ALLOC(netVal) < 0)
+        goto cleanup;
+    netVal->type = VIR_CONF_LIST;
+    netVal->list = NULL;
+
+    for (i = 0; i < def->nnets; i++) {
+        if (xenFormatXMNet(conn, netVal, def->nets[i],
+                           hvm, xendConfigVersion) < 0)
+           goto cleanup;
+    }
+
+    if (netVal->list != NULL) {
+        int ret = virConfSetValue(conf, "vif", netVal);
+        netVal = NULL;
+        if (ret < 0)
+            goto cleanup;
+    }
+
+    VIR_FREE(netVal);
+    return 0;
+
+ cleanup:
+    virConfFreeValue(netVal);
+    return -1;
+}
+
+
+static int
+xenFormatXMEmulatedHardware(virConfPtr conf, virDomainDefPtr def)
+{
+    size_t i;
+
+    if (STREQ(def->os.type, "hvm")) {
+        if (def->sounds) {
+            virBuffer buf = VIR_BUFFER_INITIALIZER;
+            char *str = NULL;
+            int ret = xenFormatSxprSound(def, &buf);
+            str = virBufferContentAndReset(&buf);
+            if (ret == 0)
+                ret = xenXMConfigSetString(conf, "soundhw", str);
+
+            VIR_FREE(str);
+            if (ret < 0)
+                return -1;
+        }
+
+        for (i = 0; i < def->ninputs; i++) {
+            if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
+                if (xenXMConfigSetInt(conf, "usb", 1) < 0)
+                    return -1;
+
+                switch (def->inputs[i]->type) {
+                    case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+                        if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0)
+                            return -1;
+
+                        break;
+                    case VIR_DOMAIN_INPUT_TYPE_TABLET:
+                        if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0)
+                            return -1;
+
+                        break;
+                    case VIR_DOMAIN_INPUT_TYPE_KBD:
+                        if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0)
+                            return -1;
+
+                        break;
+                }
+                break;
+            }
+        }
+    }
+
+    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);
@@ -2216,9 +2303,6 @@ xenFormatXM(virConnectPtr conn,
             int xendConfigVersion)
 {
     virConfPtr conf = NULL;
-    int hvm = 0;
-    size_t i;
-    virConfValuePtr netVal = NULL;
 
     if (!(conf = virConfNew()))
         goto cleanup;
@@ -2232,8 +2316,6 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0)
         goto cleanup;
 
-    hvm = STREQ(def->os.type, "hvm");
-
     if (xenFormatXMOS(conf, def, xendConfigVersion) < 0)
         goto cleanup;
 
@@ -2243,29 +2325,8 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMEventActions(conf, def) < 0)
         goto cleanup;
 
-    if (hvm) {
-        for (i = 0; i < def->ninputs; i++) {
-            if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
-                if (xenXMConfigSetInt(conf, "usb", 1) < 0)
-                    goto cleanup;
-                switch (def->inputs[i]->type) {
-                    case VIR_DOMAIN_INPUT_TYPE_MOUSE:
-                        if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0)
-                            goto cleanup;
-                        break;
-                    case VIR_DOMAIN_INPUT_TYPE_TABLET:
-                        if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0)
-                            goto cleanup;
-                        break;
-                    case VIR_DOMAIN_INPUT_TYPE_KBD:
-                        if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0)
-                            goto cleanup;
-                        break;
-                }
-                break;
-            }
-        }
-    }
+    if (xenFormatXMEmulatedHardware(conf, def) < 0)
+        goto cleanup;
 
     if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0)
         goto cleanup;
@@ -2273,23 +2334,8 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(netVal) < 0)
+    if (xenFormatXMVif(conf, conn, def, xendConfigVersion) < 0)
         goto cleanup;
-    netVal->type = VIR_CONF_LIST;
-    netVal->list = NULL;
-
-    for (i = 0; i < def->nnets; i++) {
-        if (xenFormatXMNet(conn, netVal, def->nets[i],
-                           hvm, xendConfigVersion) < 0)
-            goto cleanup;
-    }
-    if (netVal->list != NULL) {
-        int ret = virConfSetValue(conf, "vif", netVal);
-        netVal = NULL;
-        if (ret < 0)
-            goto cleanup;
-    }
-    VIR_FREE(netVal);
 
     if (xenFormatXMPCI(conf, def) < 0)
         goto cleanup;
@@ -2297,25 +2343,9 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMCharDev(conf, def) < 0)
         goto cleanup;
 
-    if (hvm) {
-        if (def->sounds) {
-            virBuffer buf = VIR_BUFFER_INITIALIZER;
-            char *str = NULL;
-            int ret = xenFormatSxprSound(def, &buf);
-            str = virBufferContentAndReset(&buf);
-            if (ret == 0)
-                ret = xenXMConfigSetString(conf, "soundhw", str);
-
-            VIR_FREE(str);
-            if (ret < 0)
-                goto cleanup;
-        }
-    }
-
     return conf;
 
  cleanup:
-    virConfFreeValue(netVal);
     if (conf)
         virConfFree(conf);
     return NULL;
diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg
index 68984da..1336ece 100644
--- a/tests/xmconfigdata/test-escape-paths.cfg
+++ b/tests/xmconfigdata/test-escape-paths.cfg
@@ -14,6 +14,7 @@ localtime = 0
 on_poweroff = "destroy"
 on_reboot = "restart"
 on_crash = "restart"
+soundhw = "sb16,es1370"
 sdl = 0
 vnc = 1
 vncunused = 1
@@ -23,4 +24,3 @@ disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", """phy:/dev/HostVG/XenGuest'",hdb,w"
 vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
 parallel = "none"
 serial = "none"
-soundhw = "sb16,es1370"
diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg
index a12a30c..67dd8e0 100644
--- a/tests/xmconfigdata/test-fullvirt-sound.cfg
+++ b/tests/xmconfigdata/test-fullvirt-sound.cfg
@@ -14,6 +14,7 @@ localtime = 0
 on_poweroff = "destroy"
 on_reboot = "restart"
 on_crash = "restart"
+soundhw = "sb16,es1370"
 sdl = 0
 vnc = 1
 vncunused = 1
@@ -23,4 +24,3 @@ disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ]
 vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
 parallel = "none"
 serial = "none"
-soundhw = "sb16,es1370"
-- 
1.8.4.5


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