mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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@gmail.com> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
208660e046
commit
5c5cac8ced
@ -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 &&
|
||||||
virConfPtr
|
xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
|
||||||
xenFormatXM(virConnectPtr conn,
|
return -1;
|
||||||
virDomainDefPtr def,
|
|
||||||
int xendConfigVersion)
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()))
|
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 (xenFormatXMGeneralMeta(conf, def) < 0)
|
return 0;
|
||||||
goto cleanup;
|
}
|
||||||
|
|
||||||
if (xenFormatXMMem(conf, def) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (xenFormatXMCPUAllocation(conf, def) < 0)
|
static int
|
||||||
goto cleanup;
|
xenFormatXMOS(virConfPtr conf, virDomainDefPtr def)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
|
if (STREQ(def->os.type, "hvm")) {
|
||||||
|
|
||||||
if (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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user