[PATCH v2 22/25] src/xenxs:Refactor code formating emulated devices config

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

 



From: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>

introduce function
  xenFormatXMEmulatedDevices(virConfPtr conf,...........)
which formats emulated devices config instead

signed-off-by: David Kiarie<davidkiarie4@xxxxxxxxx>
---
 src/xenxs/xen_xm.c                         | 86 +++++++++++++++++-------------
 tests/xmconfigdata/test-escape-paths.cfg   |  2 +-
 tests/xmconfigdata/test-fullvirt-sound.cfg |  2 +-
 3 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 2d975d5..08d8918 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -2067,6 +2067,54 @@ int xenFormatXMDomainDisks(virConfPtr conf, virDomainDefPtr def,
 }
 
 
+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;
+}
 virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
                        int xendConfigVersion)
 {
@@ -2161,30 +2209,10 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
         if (def->emulator &&
             xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
             goto cleanup;
-
-        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;
     if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0)
@@ -2265,20 +2293,6 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
             if (xenXMConfigSetString(conf, "serial", "none") < 0)
                 goto cleanup;
         }
-
-
-        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;
diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg
index 4a18cc1..42223b9 100644
--- a/tests/xmconfigdata/test-escape-paths.cfg
+++ b/tests/xmconfigdata/test-escape-paths.cfg
@@ -14,6 +14,7 @@ on_poweroff = "destroy"
 on_reboot = "restart"
 on_crash = "restart"
 device_model = "/usr/lib/xen/bin/qemu-dm&test"
+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 d315f93..a3bb409 100644
--- a/tests/xmconfigdata/test-fullvirt-sound.cfg
+++ b/tests/xmconfigdata/test-fullvirt-sound.cfg
@@ -14,6 +14,7 @@ on_poweroff = "destroy"
 on_reboot = "restart"
 on_crash = "restart"
 device_model = "/usr/lib/xen/bin/qemu-dm"
+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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]