On Thu, Aug 14, 2014 at 12:15:32AM -0600, Jim Fehlig wrote:
Kiarie Kahurani wrote:
> introduce function
> xenFormatXMOS(virConfPtr conf,........);
>
I split this into three functions:
- xenFormatXMEmulator
- xenFormatXMCDROM
- xenFormatXMOS
Formating of emulator and cdrom can be different between xm and xl, and
we may want to account for that in the near future.
> which formats OS config instead
>
> Signed-off-by: Kiarie Kahurani <davidkiarie4(a)gmail.com>
> ---
> src/xenxs/xen_xm.c | 95 ++++++++++++----------
> tests/xmconfigdata/test-escape-paths.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-force-hpet.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-force-nohpet.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-localtime.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-net-ioemu.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-net-netfront.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-new-cdrom.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-old-cdrom.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg | 2 +-
> .../test-fullvirt-serial-dev-2-ports.cfg | 2 +-
> .../test-fullvirt-serial-dev-2nd-port.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-file.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-null.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-pipe.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-pty.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-stdio.cfg | 2 +-
> .../test-fullvirt-serial-tcp-telnet.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-tcp.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-udp.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-serial-unix.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-sound.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-usbmouse.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-usbtablet.cfg | 2 +-
> tests/xmconfigdata/test-fullvirt-utc.cfg | 2 +-
> tests/xmconfigdata/test-no-source-cdrom.cfg | 2 +-
> tests/xmconfigdata/test-pci-devs.cfg | 2 +-
>
Avoids changing all the test data files too. Simplified patch below.
BTW, I got interrupted during my earlier review, so "will push shortly"
had changed to "will push tomorrow" :-).
Regards,
Jim
From 76824b192ecac2d9f19406c11446b616ca96e9d4 Mon Sep 17 00:00:00
2001
From: Kiarie Kahurani <davidkiarie4(a)gmail.com>
Date: Tue, 12 Aug 2014 00:21:32 +0300
Subject: [PATCH 08/11] src/xenxs: Refactor code formating OS config
introduce functions
xenFormatXMEmulator(virConfPtr conf,........);
xenFormatXMCDROM(virConfPtr conf, .......);
xenFormatXMOS(virConfPtr conf,........);
which formats OS and associated config instead
Signed-off-by: Kiarie Kahurani <davidkiarie4(a)gmail.com>
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/xenxs/xen_xm.c | 161 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 101 insertions(+), 60 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 432fee2..72ae913 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -2021,42 +2021,57 @@ xenFormatXMCPUFeatures(virConfPtr conf,
}
-/* 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);
+static int
+xenFormatXMEmulator(virConfPtr conf, virDomainDefPtr def)
+{
+ if (def->emulator &&
+ xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
+ return -1;
-virConfPtr
-xenFormatXM(virConnectPtr conn,
- virDomainDefPtr def,
- int xendConfigVersion)
+ return 0;
+}
+
+
+static int
+xenFormatXMCDROM(virConfPtr conf,
+ virDomainDefPtr def,
+ int xendConfigVersion)
{
- virConfPtr conf = NULL;
- int hvm = 0;
size_t i;
- virConfValuePtr netVal = NULL;
-
- if (!(conf = virConfNew()))
- goto cleanup;
- if (xenFormatXMGeneralMeta(conf, def) < 0)
- goto cleanup;
+ if (STREQ(def->os.type, "hvm")) {
+ if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
+ for (i = 0; i < def->ndisks; i++) {
+ if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM
&&
+ def->disks[i]->dst &&
+ STREQ(def->disks[i]->dst, "hdc") &&
+ virDomainDiskGetSource(def->disks[i])) {
+ if (xenXMConfigSetString(conf, "cdrom",
+ virDomainDiskGetSource(def->disks[i]))
< 0)
+ return -1;
+ break;
+ }
+ }
+ }
+ }
- if (xenFormatXMMem(conf, def) < 0)
- goto cleanup;
+ return 0;
+}
- if (xenFormatXMCPUAllocation(conf, def) < 0)
- goto cleanup;
- hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
+static int
+xenFormatXMOS(virConfPtr conf, virDomainDefPtr def)
+{
+ size_t i;
- if (hvm) {
+ if (STREQ(def->os.type, "hvm")) {
char boot[VIR_DOMAIN_BOOT_LAST+1];
if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
- goto cleanup;
+ return -1;
if (def->os.loader &&
xenXMConfigSetString(conf, "kernel", def->os.loader) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < def->os.nBootDevs; i++) {
switch (def->os.bootDevs[i]) {
@@ -2075,6 +2090,7 @@ xenFormatXM(virConnectPtr conn,
break;
}
}
+
if (!def->os.nBootDevs) {
boot[0] = 'c';
boot[1] = '\0';
@@ -2083,43 +2099,69 @@ xenFormatXM(virConnectPtr conn,
}
if (xenXMConfigSetString(conf, "boot", boot) < 0)
- goto cleanup;
-
- if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0)
- goto cleanup;
-
- if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
- for (i = 0; i < def->ndisks; i++) {
- if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM
&&
- def->disks[i]->dst &&
- STREQ(def->disks[i]->dst, "hdc") &&
- virDomainDiskGetSource(def->disks[i])) {
- if (xenXMConfigSetString(conf, "cdrom",
- virDomainDiskGetSource(def->disks[i]))
< 0)
- goto cleanup;
- break;
- }
- }
- }
+ return -1;
/* XXX floppy disks */
} else {
if (def->os.bootloader &&
- xenXMConfigSetString(conf, "bootloader", def->os.bootloader)
< 0)
- goto cleanup;
- if (def->os.bootloaderArgs &&
- xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs)
< 0)
- goto cleanup;
- if (def->os.kernel &&
- xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
- goto cleanup;
- if (def->os.initrd &&
- xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
- goto cleanup;
- if (def->os.cmdline &&
- xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0)
- goto cleanup;
- } /* !hvm */
+ xenXMConfigSetString(conf, "bootloader", def->os.bootloader)
< 0)
+ return -1;
+
+ if (def->os.bootloaderArgs &&
+ xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs)
< 0)
+ return -1;
+
+ if (def->os.kernel &&
+ xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
+ return -1;
+
+ if (def->os.initrd &&
+ xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
+ return -1;
+
+ if (def->os.cmdline &&
+ xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0)
+ return -1;
+ } /* !hvm */
+
+ 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);
+
+virConfPtr
+xenFormatXM(virConnectPtr conn,
+ virDomainDefPtr def,
+ int xendConfigVersion)
+{
+ virConfPtr conf = NULL;
+ int hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
+ size_t i;
+ virConfValuePtr netVal = NULL;
+
+ if (!(conf = virConfNew()))
+ goto cleanup;
+
+ if (xenFormatXMGeneralMeta(conf, def) < 0)
+ goto cleanup;
+
+ if (xenFormatXMMem(conf, def) < 0)
+ goto cleanup;
+
+ if (xenFormatXMCPUAllocation(conf, def) < 0)
+ goto cleanup;
+
+ if (xenFormatXMOS(conf, def) < 0)
+ goto cleanup;
+
+ if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0)
+ goto cleanup;
+
+ if (xenFormatXMCDROM(conf, def, xendConfigVersion) < 0)
+ goto cleanup;
if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0)
goto cleanup;
@@ -2127,11 +2169,10 @@ xenFormatXM(virConnectPtr conn,
if (xenFormatXMEventActions(conf, def) < 0)
goto cleanup;
- if (hvm) {
- if (def->emulator &&
- xenXMConfigSetString(conf, "device_model", def->emulator) <
0)
- goto cleanup;
+ if (xenFormatXMEmulator(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)
--
1.8.4.5
Looks better too.