conf: refactor hyperv features parsing

1. All hyperv features are tristate ones. So make tristate parsing code common.
2. Reindent switch statement.
3. Reduce nesting in spinlocks parsing.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Nikolay Shirokovskiy 2016-03-10 15:43:47 +03:00 committed by John Ferlan
parent 5b5f12cffa
commit ae37d9f1d1

View File

@ -15583,68 +15583,52 @@ virDomainDefParseXML(xmlDocPtr xml,
ctxt->node = nodes[i]; ctxt->node = nodes[i];
if (!(tmp = virXPathString("string(./@state)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR,
_("missing 'state' attribute for "
"HyperV Enlightenment feature '%s'"),
nodes[i]->name);
goto error;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid value of state argument "
"for HyperV Enlightenment feature '%s'"),
nodes[i]->name);
goto error;
}
VIR_FREE(tmp);
def->hyperv_features[feature] = value;
switch ((virDomainHyperv) feature) { switch ((virDomainHyperv) feature) {
case VIR_DOMAIN_HYPERV_RELAXED: case VIR_DOMAIN_HYPERV_RELAXED:
case VIR_DOMAIN_HYPERV_VAPIC: case VIR_DOMAIN_HYPERV_VAPIC:
if (!(tmp = virXPathString("string(./@state)", ctxt))) { break;
virReportError(VIR_ERR_XML_ERROR,
_("missing 'state' attribute for "
"HyperV Enlightenment feature '%s'"),
nodes[i]->name);
goto error;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) { case VIR_DOMAIN_HYPERV_SPINLOCKS:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, if (value != VIR_TRISTATE_SWITCH_ON)
_("invalid value of state argument "
"for HyperV Enlightenment feature '%s'"),
nodes[i]->name);
goto error;
}
VIR_FREE(tmp);
def->hyperv_features[feature] = value;
break; break;
case VIR_DOMAIN_HYPERV_SPINLOCKS: if (virXPathUInt("string(./@retries)", ctxt,
if (!(tmp = virXPathString("string(./@state)", ctxt))) { &def->hyperv_spinlocks) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing 'state' attribute for " _("invalid HyperV spinlock retry count"));
"HyperV Enlightenment feature '%s'"), goto error;
nodes[i]->name); }
goto error;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) { if (def->hyperv_spinlocks < 0xFFF) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of state argument " _("HyperV spinlock retry count must be "
"for HyperV Enlightenment feature '%s'"), "at least 4095"));
nodes[i]->name); goto error;
goto error; }
} break;
VIR_FREE(tmp); /* coverity[dead_error_begin] */
if (value == VIR_TRISTATE_SWITCH_ON) { case VIR_DOMAIN_HYPERV_LAST:
if (virXPathUInt("string(./@retries)", ctxt, break;
&def->hyperv_spinlocks) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid HyperV spinlock retry count"));
goto error;
}
if (def->hyperv_spinlocks < 0xFFF) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("HyperV spinlock retry count must be "
"at least 4095"));
goto error;
}
}
def->hyperv_features[feature] = value;
break;
/* coverity[dead_error_begin] */
case VIR_DOMAIN_HYPERV_LAST:
break;
} }
} }
VIR_FREE(nodes); VIR_FREE(nodes);