conf: Convert virDomainDefParseBootXML() to virXMLProp*()

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-20 21:57:49 +01:00
parent 0aaf410262
commit 0eb42087c7
7 changed files with 37 additions and 40 deletions

View File

@ -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))) {
@ -16935,36 +16927,33 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
&def->os.bootmenu) < 0)
return -1;
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;
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -1153,6 +1153,8 @@ xenFormatXLOS(virConf *conf, virDomainDef *def)
default:
boot[i] = 'c';
break;
case VIR_DOMAIN_BOOT_LAST:
break;
}
}

View File

@ -457,6 +457,8 @@ xenFormatXMOS(virConf *conf, virDomainDef *def)
default:
boot[i] = 'c';
break;
case VIR_DOMAIN_BOOT_LAST:
break;
}
}

View File

@ -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;

View File

@ -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'"),