Export helper function for reuse in getting values
from a virConfPtr object
Signed-off-by: Kiarie Kahurani <davidkiarie4(a)gmail.com>
---
src/xenconfig/xen_common.c | 144 ++++++++++++++++++++++-----------------------
src/xenconfig/xen_common.h | 24 ++++++--
2 files changed, 91 insertions(+), 77 deletions(-)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 9beaf6c..d71dd07 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -43,7 +43,7 @@
/*
* Convenience method to grab a long int from the config file object
*/
-static int
+int
xenConfigGetBool(virConfPtr conf,
const char *name,
int *value,
@@ -73,7 +73,7 @@ xenConfigGetBool(virConfPtr conf,
/*
* Convenience method to grab a int from the config file object
*/
-static int
+int
xenConfigGetULong(virConfPtr conf,
const char *name,
unsigned long *value,
@@ -179,7 +179,7 @@ xenConfigCopyString(virConfPtr conf, const char *name, char **value)
}
-static int
+int
xenConfigCopyStringOpt(virConfPtr conf, const char *name, char **value)
{
return xenConfigCopyStringInternal(conf, name, value, 1);
@@ -262,8 +262,8 @@ xenConfigGetString(virConfPtr conf,
}
-static int
-xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l)
+int
+xenConfigSetInt(virConfPtr conf, const char *setting, long long l)
{
virConfValuePtr value = NULL;
@@ -283,8 +283,8 @@ xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l)
}
-static int
-xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str)
+int
+xenConfigSetString(virConfPtr conf, const char *setting, const char *str)
{
virConfValuePtr value = NULL;
@@ -1387,11 +1387,11 @@ xenFormatGeneralMeta(virConfPtr conf, virDomainDefPtr def)
{
char uuid[VIR_UUID_STRING_BUFLEN];
- if (xenXMConfigSetString(conf, "name", def->name) < 0)
+ if (xenConfigSetString(conf, "name", def->name) < 0)
return -1;
virUUIDFormat(def->uuid, uuid);
- if (xenXMConfigSetString(conf, "uuid", uuid) < 0)
+ if (xenConfigSetString(conf, "uuid", uuid) < 0)
return -1;
return 0;
@@ -1401,12 +1401,12 @@ xenFormatGeneralMeta(virConfPtr conf, virDomainDefPtr def)
static int
xenFormatMem(virConfPtr conf, virDomainDefPtr def)
{
- if (xenXMConfigSetInt(conf, "maxmem",
- VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
+ if (xenConfigSetInt(conf, "maxmem",
+ VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "memory",
- VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
+ if (xenConfigSetInt(conf, "memory",
+ VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
return -1;
return 0;
@@ -1468,7 +1468,7 @@ xenFormatTimeOffset(virConfPtr conf, virDomainDefPtr def, int
xendConfigVersion)
virDomainClockOffsetTypeToString(def->clock.offset));
return -1;
}
- if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) <
0)
+ if (xenConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) <
0)
return -1;
} else {
@@ -1489,7 +1489,7 @@ xenFormatTimeOffset(virConfPtr conf, virDomainDefPtr def, int
xendConfigVersion)
} /* !hvm */
}
- if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0)
+ if (xenConfigSetInt(conf, "localtime", vmlocaltime) < 0)
return -1;
return 0;
@@ -1506,7 +1506,7 @@ xenFormatEventActions(virConfPtr conf, virDomainDefPtr def)
_("unexpected lifecycle action %d"),
def->onPoweroff);
return -1;
}
- if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0)
+ if (xenConfigSetString(conf, "on_poweroff", lifecycle) < 0)
return -1;
@@ -1515,7 +1515,7 @@ xenFormatEventActions(virConfPtr conf, virDomainDefPtr def)
_("unexpected lifecycle action %d"), def->onReboot);
return -1;
}
- if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0)
+ if (xenConfigSetString(conf, "on_reboot", lifecycle) < 0)
return -1;
@@ -1524,7 +1524,7 @@ xenFormatEventActions(virConfPtr conf, virDomainDefPtr def)
_("unexpected lifecycle action %d"), def->onCrash);
return -1;
}
- if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0)
+ if (xenConfigSetString(conf, "on_crash", lifecycle) < 0)
return -1;
return 0;
@@ -1545,12 +1545,12 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def)
ret = xenFormatSxprChr(def->parallels[0], &buf);
str = virBufferContentAndReset(&buf);
if (ret == 0)
- ret = xenXMConfigSetString(conf, "parallel", str);
+ ret = xenConfigSetString(conf, "parallel", str);
VIR_FREE(str);
if (ret < 0)
return -1;
} else {
- if (xenXMConfigSetString(conf, "parallel", "none") <
0)
+ if (xenConfigSetString(conf, "parallel", "none") < 0)
return -1;
}
@@ -1563,7 +1563,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def)
ret = xenFormatSxprChr(def->serials[0], &buf);
str = virBufferContentAndReset(&buf);
if (ret == 0)
- ret = xenXMConfigSetString(conf, "serial", str);
+ ret = xenConfigSetString(conf, "serial", str);
VIR_FREE(str);
if (ret < 0)
return -1;
@@ -1608,7 +1608,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def)
VIR_FREE(serialVal);
}
} else {
- if (xenXMConfigSetString(conf, "serial", "none") < 0)
+ if (xenConfigSetString(conf, "serial", "none") < 0)
return -1;
}
}
@@ -1623,13 +1623,13 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
int ret = -1;
char *cpus = NULL;
- if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
+ if (xenConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
goto cleanup;
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
either 32, or 64 on a platform where long is big enough. */
if (def->vcpus < def->maxvcpus &&
- xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1)
< 0)
+ xenConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1)
< 0)
goto cleanup;
if ((def->cpumask != NULL) &&
@@ -1638,7 +1638,7 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
}
if (cpus &&
- xenXMConfigSetString(conf, "cpus", cpus) < 0)
+ xenConfigSetString(conf, "cpus", cpus) < 0)
goto cleanup;
ret = 0;
@@ -1655,37 +1655,37 @@ xenFormatCPUFeatures(virConfPtr conf, virDomainDefPtr def, int
xendConfigVersion
size_t i;
if (STREQ(def->os.type, "hvm")) {
- if (xenXMConfigSetInt(conf, "pae",
- (def->features[VIR_DOMAIN_FEATURE_PAE] ==
- VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
+ if (xenConfigSetInt(conf, "pae",
+ (def->features[VIR_DOMAIN_FEATURE_PAE] ==
+ VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "acpi",
- (def->features[VIR_DOMAIN_FEATURE_ACPI] ==
- VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
+ if (xenConfigSetInt(conf, "acpi",
+ (def->features[VIR_DOMAIN_FEATURE_ACPI] ==
+ VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "apic",
- (def->features[VIR_DOMAIN_FEATURE_APIC] ==
- VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
+ if (xenConfigSetInt(conf, "apic",
+ (def->features[VIR_DOMAIN_FEATURE_APIC] ==
+ VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
return -1;
if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) {
- if (xenXMConfigSetInt(conf, "hap",
- (def->features[VIR_DOMAIN_FEATURE_HAP] ==
- VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
+ if (xenConfigSetInt(conf, "hap",
+ (def->features[VIR_DOMAIN_FEATURE_HAP] ==
+ VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "viridian",
- (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] ==
- VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
+ if (xenConfigSetInt(conf, "viridian",
+ (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] ==
+ VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
return -1;
}
for (i = 0; i < def->clock.ntimers; i++) {
if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET
&&
def->clock.timers[i]->present != -1 &&
- xenXMConfigSetInt(conf, "hpet",
def->clock.timers[i]->present) < 0)
+ xenConfigSetInt(conf, "hpet",
def->clock.timers[i]->present) < 0)
return -1;
}
}
@@ -1698,7 +1698,7 @@ static int
xenFormatEmulator(virConfPtr conf, virDomainDefPtr def)
{
if (def->emulator &&
- xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
+ xenConfigSetString(conf, "device_model", def->emulator) < 0)
return -1;
return 0;
@@ -1717,7 +1717,7 @@ xenFormatCDROM(virConfPtr conf, virDomainDefPtr def, int
xendConfigVersion)
def->disks[i]->dst &&
STREQ(def->disks[i]->dst, "hdc") &&
virDomainDiskGetSource(def->disks[i])) {
- if (xenXMConfigSetString(conf, "cdrom",
+ if (xenConfigSetString(conf, "cdrom",
virDomainDiskGetSource(def->disks[i]))
< 0)
return -1;
break;
@@ -1737,11 +1737,11 @@ xenFormatOS(virConfPtr conf, virDomainDefPtr def)
if (STREQ(def->os.type, "hvm")) {
char boot[VIR_DOMAIN_BOOT_LAST+1];
- if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
+ if (xenConfigSetString(conf, "builder", "hvm") < 0)
return -1;
if (def->os.loader &&
- xenXMConfigSetString(conf, "kernel", def->os.loader) < 0)
+ xenConfigSetString(conf, "kernel", def->os.loader) < 0)
return -1;
for (i = 0; i < def->os.nBootDevs; i++) {
@@ -1769,29 +1769,29 @@ xenFormatOS(virConfPtr conf, virDomainDefPtr def)
boot[def->os.nBootDevs] = '\0';
}
- if (xenXMConfigSetString(conf, "boot", boot) < 0)
+ if (xenConfigSetString(conf, "boot", boot) < 0)
return -1;
/* XXX floppy disks */
} else {
if (def->os.bootloader &&
- xenXMConfigSetString(conf, "bootloader", def->os.bootloader)
< 0)
+ xenConfigSetString(conf, "bootloader", def->os.bootloader) <
0)
return -1;
if (def->os.bootloaderArgs &&
- xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs)
< 0)
+ xenConfigSetString(conf, "bootargs", def->os.bootloaderArgs)
< 0)
return -1;
if (def->os.kernel &&
- xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
+ xenConfigSetString(conf, "kernel", def->os.kernel) < 0)
return -1;
if (def->os.initrd &&
- xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
+ xenConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
return -1;
if (def->os.cmdline &&
- xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0)
+ xenConfigSetString(conf, "extra", def->os.cmdline) < 0)
return -1;
} /* !hvm */
@@ -1807,52 +1807,52 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def, int
xendConfigVersion)
if (def->ngraphics == 1) {
if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
- if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
+ if (xenConfigSetInt(conf, "sdl", 1) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
+ if (xenConfigSetInt(conf, "vnc", 0) < 0)
return -1;
if (def->graphics[0]->data.sdl.display &&
- xenXMConfigSetString(conf, "display",
- def->graphics[0]->data.sdl.display) < 0)
+ xenConfigSetString(conf, "display",
+ def->graphics[0]->data.sdl.display) < 0)
return -1;
if (def->graphics[0]->data.sdl.xauth &&
- xenXMConfigSetString(conf, "xauthority",
- def->graphics[0]->data.sdl.xauth) < 0)
+ xenConfigSetString(conf, "xauthority",
+ def->graphics[0]->data.sdl.xauth) < 0)
return -1;
} else {
const char *listenAddr;
- if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
+ if (xenConfigSetInt(conf, "sdl", 0) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
+ if (xenConfigSetInt(conf, "vnc", 1) < 0)
return -1;
- if (xenXMConfigSetInt(conf, "vncunused",
+ if (xenConfigSetInt(conf, "vncunused",
def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
return -1;
if (!def->graphics[0]->data.vnc.autoport &&
- xenXMConfigSetInt(conf, "vncdisplay",
- def->graphics[0]->data.vnc.port - 5900) < 0)
+ xenConfigSetInt(conf, "vncdisplay",
+ def->graphics[0]->data.vnc.port - 5900) <
0)
return -1;
listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
if (listenAddr &&
- xenXMConfigSetString(conf, "vnclisten", listenAddr) <
0)
+ xenConfigSetString(conf, "vnclisten", listenAddr) < 0)
return -1;
if (def->graphics[0]->data.vnc.auth.passwd &&
- xenXMConfigSetString(conf, "vncpasswd",
- def->graphics[0]->data.vnc.auth.passwd)
< 0)
+ xenConfigSetString(conf, "vncpasswd",
+ def->graphics[0]->data.vnc.auth.passwd) <
0)
return -1;
if (def->graphics[0]->data.vnc.keymap &&
- xenXMConfigSetString(conf, "keymap",
- def->graphics[0]->data.vnc.keymap) < 0)
+ xenConfigSetString(conf, "keymap",
+ def->graphics[0]->data.vnc.keymap) < 0)
return -1;
}
} else {
@@ -1928,7 +1928,7 @@ xenFormatSound(virConfPtr conf, virDomainDefPtr def)
str = virBufferContentAndReset(&buf);
if (ret == 0)
- ret = xenXMConfigSetString(conf, "soundhw", str);
+ ret = xenConfigSetString(conf, "soundhw", str);
VIR_FREE(str);
if (ret < 0)
@@ -1948,22 +1948,22 @@ xenFormatInputDevs(virConfPtr conf, virDomainDefPtr def)
if (STREQ(def->os.type, "hvm")) {
for (i = 0; i < def->ninputs; i++) {
if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
- if (xenXMConfigSetInt(conf, "usb", 1) < 0)
+ if (xenConfigSetInt(conf, "usb", 1) < 0)
return -1;
switch (def->inputs[i]->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
- if (xenXMConfigSetString(conf, "usbdevice",
"mouse") < 0)
+ if (xenConfigSetString(conf, "usbdevice",
"mouse") < 0)
return -1;
break;
case VIR_DOMAIN_INPUT_TYPE_TABLET:
- if (xenXMConfigSetString(conf, "usbdevice",
"tablet") < 0)
+ if (xenConfigSetString(conf, "usbdevice",
"tablet") < 0)
return -1;
break;
case VIR_DOMAIN_INPUT_TYPE_KBD:
- if (xenXMConfigSetString(conf, "usbdevice",
"keyboard") < 0)
+ if (xenConfigSetString(conf, "usbdevice",
"keyboard") < 0)
return -1;
break;
diff --git a/src/xenconfig/xen_common.h b/src/xenconfig/xen_common.h
index 9f50aef..e993b21 100644
--- a/src/xenconfig/xen_common.h
+++ b/src/xenconfig/xen_common.h
@@ -27,11 +27,25 @@
# include "virconf.h"
# include "domain_conf.h"
-int
-xenConfigGetString(virConfPtr conf,
- const char *name,
- const char **value,
- const char *def);
+int xenConfigGetString(virConfPtr conf,
+ const char *name,
+ const char **value,
+ const char *def);
+
+int xenConfigGetBool(virConfPtr conf, const char *name, int *value, int def);
+
+int xenConfigSetInt(virConfPtr conf, const char *name, long long value);
+
+int xenConfigSetString(virConfPtr conf, const char *setting, const char *value);
+
+int xenConfigGetULong(virConfPtr conf,
+ const char *name,
+ unsigned long *value,
+ unsigned long def);
+
+int xenConfigCopyStringOpt(virConfPtr conf,
+ const char *name,
+ char **value);
int xenParseConfigCommon(virConfPtr conf,
virDomainDefPtr def,
--
1.8.4.5