提交 5c5cac8c 编写于 作者: K Kiarie Kahurani 提交者: Jim Fehlig

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: NKiarie Kahurani <davidkiarie4@gmail.com>
Signed-off-by: NJim Fehlig <jfehlig@suse.com>
上级 208660e0
...@@ -2021,42 +2021,57 @@ xenFormatXMCPUFeatures(virConfPtr conf, ...@@ -2021,42 +2021,57 @@ xenFormatXMCPUFeatures(virConfPtr conf,
} }
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is static int
either 32, or 64 on a platform where long is big enough. */ xenFormatXMEmulator(virConfPtr conf, virDomainDefPtr def)
verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); {
if (def->emulator &&
xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
return -1;
virConfPtr return 0;
xenFormatXM(virConnectPtr conn, }
virDomainDefPtr def,
int xendConfigVersion)
static int
xenFormatXMCDROM(virConfPtr conf,
virDomainDefPtr def,
int xendConfigVersion)
{ {
virConfPtr conf = NULL;
int hvm = 0;
size_t i; size_t i;
virConfValuePtr netVal = NULL;
if (!(conf = virConfNew()))
goto cleanup;
if (xenFormatXMGeneralMeta(conf, def) < 0) if (STREQ(def->os.type, "hvm")) {
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)
return -1;
break;
}
}
}
}
if (xenFormatXMMem(conf, def) < 0) return 0;
goto cleanup; }
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]; char boot[VIR_DOMAIN_BOOT_LAST+1];
if (xenXMConfigSetString(conf, "builder", "hvm") < 0) if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
goto cleanup; return -1;
if (def->os.loader && if (def->os.loader &&
xenXMConfigSetString(conf, "kernel", def->os.loader) < 0) xenXMConfigSetString(conf, "kernel", def->os.loader) < 0)
goto cleanup; return -1;
for (i = 0; i < def->os.nBootDevs; i++) { for (i = 0; i < def->os.nBootDevs; i++) {
switch (def->os.bootDevs[i]) { switch (def->os.bootDevs[i]) {
...@@ -2075,6 +2090,7 @@ xenFormatXM(virConnectPtr conn, ...@@ -2075,6 +2090,7 @@ xenFormatXM(virConnectPtr conn,
break; break;
} }
} }
if (!def->os.nBootDevs) { if (!def->os.nBootDevs) {
boot[0] = 'c'; boot[0] = 'c';
boot[1] = '\0'; boot[1] = '\0';
...@@ -2083,43 +2099,69 @@ xenFormatXM(virConnectPtr conn, ...@@ -2083,43 +2099,69 @@ xenFormatXM(virConnectPtr conn,
} }
if (xenXMConfigSetString(conf, "boot", boot) < 0) if (xenXMConfigSetString(conf, "boot", boot) < 0)
goto cleanup; return -1;
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;
}
}
}
/* XXX floppy disks */ /* XXX floppy disks */
} else { } else {
if (def->os.bootloader && if (def->os.bootloader &&
xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0) xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0)
goto cleanup; return -1;
if (def->os.bootloaderArgs &&
xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0) if (def->os.bootloaderArgs &&
goto cleanup; xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0)
if (def->os.kernel && return -1;
xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
goto cleanup; if (def->os.kernel &&
if (def->os.initrd && xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0) return -1;
goto cleanup;
if (def->os.cmdline && if (def->os.initrd &&
xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0) xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
goto cleanup; return -1;
} /* !hvm */
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) if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0)
goto cleanup; goto cleanup;
...@@ -2127,11 +2169,10 @@ xenFormatXM(virConnectPtr conn, ...@@ -2127,11 +2169,10 @@ xenFormatXM(virConnectPtr conn,
if (xenFormatXMEventActions(conf, def) < 0) if (xenFormatXMEventActions(conf, def) < 0)
goto cleanup; goto cleanup;
if (hvm) { if (xenFormatXMEmulator(conf, def) < 0)
if (def->emulator && goto cleanup;
xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
goto cleanup;
if (hvm) {
for (i = 0; i < def->ninputs; i++) { for (i = 0; i < def->ninputs; i++) {
if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
if (xenXMConfigSetInt(conf, "usb", 1) < 0) if (xenXMConfigSetInt(conf, "usb", 1) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册