After previous cleanups, the virDomainDefParseBootXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 61 +++++++++++++++++------------------------ src/conf/domain_conf.h | 4 +-- src/libxl/libxl_conf.c | 2 ++ src/libxl/xen_xl.c | 2 ++ src/libxl/xen_xm.c | 2 ++ src/qemu/qemu_process.c | 2 +- src/vz/vz_sdk.c | 4 ++- 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 281879b915..30f0a13e2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16905,7 +16905,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, xmlNodePtr node; size_t i; int n; - g_autofree char *tmp = NULL; g_autofree xmlNodePtr *nodes = NULL; /* analysis of the boot devices */ @@ -16913,20 +16912,13 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, return -1; for (i = 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) { - int val; - g_autofree char *dev = virXMLPropString(nodes[i], "dev"); - if (!dev) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing boot device")); + if (virXMLPropEnum(nodes[i], "dev", + virDomainBootTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->os.bootDevs[def->os.nBootDevs]) < 0) return -1; - } - if ((val = virDomainBootTypeFromString(dev)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown boot device '%s'"), - dev); - return -1; - } - def->os.bootDevs[def->os.nBootDevs++] = val; + + def->os.nBootDevs++; } if ((node = virXPathNode("./os/bootmenu[1]", ctxt))) { @@ -16940,36 +16932,33 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, def->os.bootmenu = VIR_TRISTATE_BOOL_NO; } - tmp = virXMLPropString(node, "timeout"); - if (tmp && def->os.bootmenu == VIR_TRISTATE_BOOL_YES) { - if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid value for boot menu timeout")); + if (def->os.bootmenu == VIR_TRISTATE_BOOL_YES) { + int rv; + + if ((rv = virXMLPropUInt(node, "timeout", 10, + VIR_XML_PROP_NONE, + &def->os.bm_timeout)) < 0) { return -1; + } else if (rv > 0) { + def->os.bm_timeout_set = true; } - def->os.bm_timeout_set = true; } - VIR_FREE(tmp); } if ((node = virXPathNode("./os/bios[1]", ctxt))) { - tmp = virXMLPropString(node, "useserial"); - if (tmp) { - bool state = false; - ignore_value(virStringParseYesNo(tmp, &state)); - def->os.bios.useserial = virTristateBoolFromBool(state); - VIR_FREE(tmp); + int rv; + + if (virXMLPropTristateBool(node, "useserial", + VIR_XML_PROP_NONE, + &def->os.bios.useserial) < 0) { + def->os.bios.useserial = VIR_TRISTATE_BOOL_NO; } - tmp = virXMLPropString(node, "rebootTimeout"); - if (tmp) { - /* that was really just for the check if it is there */ - - if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid value for rebootTimeout")); - return -1; - } + if ((rv = virXMLPropInt(node, "rebootTimeout", 10, + VIR_XML_PROP_NONE, + &def->os.bios.rt_delay, 0)) < 0) { + return -1; + } else if (rv > 0) { def->os.bios.rt_set = true; } } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c2c263dfab..584e15b6c7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2195,7 +2195,7 @@ typedef enum { VIR_ENUM_DECL(virDomainLockFailure); struct _virDomainBIOSDef { - int useserial; /* enum virTristateBool */ + virTristateBool useserial; /* reboot-timeout parameters */ bool rt_set; int rt_delay; @@ -2324,7 +2324,7 @@ struct _virDomainOSDef { virArch arch; char *machine; size_t nBootDevs; - int bootDevs[VIR_DOMAIN_BOOT_LAST]; + virDomainBootOrder bootDevs[VIR_DOMAIN_BOOT_LAST]; virTristateBool bootmenu; unsigned int bm_timeout; bool bm_timeout_set; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 1ac6253ad7..561171126c 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -609,6 +609,8 @@ libxlMakeDomBuildInfo(virDomainDef *def, case VIR_DOMAIN_BOOT_NET: bootorder[i] = 'n'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } if (def->os.nBootDevs == 0) { diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 799fe05cbd..87194ccbd1 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1153,6 +1153,8 @@ xenFormatXLOS(virConf *conf, virDomainDef *def) default: boot[i] = 'c'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 2e636d874e..a962da9cad 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -457,6 +457,8 @@ xenFormatXMOS(virConf *conf, virDomainDef *def) default: boot[i] = 'c'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7ff4dc1835..336f0bab2e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6183,7 +6183,7 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def) return; for (i = 0; i < def->os.nBootDevs; i++) { - switch ((virDomainBootOrder) def->os.bootDevs[i]) { + switch (def->os.bootDevs[i]) { case VIR_DOMAIN_BOOT_CDROM: bootCD = i + 1; break; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 94c6cd5c7a..ccfd3e9d55 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -3799,7 +3799,7 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDef *def) for (i = 0; i < def->os.nBootDevs; ++i) { virType = def->os.bootDevs[i]; - switch ((int)virType) { + switch (virType) { case VIR_DOMAIN_BOOT_CDROM: sdkType = PDE_OPTICAL_DISK; break; @@ -3809,6 +3809,8 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDef *def) case VIR_DOMAIN_BOOT_NET: sdkType = PDE_GENERIC_NETWORK_ADAPTER; break; + case VIR_DOMAIN_BOOT_FLOPPY: + case VIR_DOMAIN_BOOT_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported boot device type: '%s'"), -- 2.34.1