Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/domain_conf.c | 141 +++++++++++------------------------------
1 file changed, 37 insertions(+), 104 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b1e5115c7e..4c7affe5af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17913,18 +17913,16 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_FEATURE_PMU:
case VIR_DOMAIN_FEATURE_PVSPINLOCK:
case VIR_DOMAIN_FEATURE_VMPORT:
- case VIR_DOMAIN_FEATURE_SMM:
- if ((tmp = virXMLPropString(nodes[i], "state"))) {
- if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) == -1)
{
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown state attribute '%s' of
feature '%s'"),
- tmp, virDomainFeatureTypeToString(val));
- return -1;
- }
- } else {
- def->features[val] = VIR_TRISTATE_SWITCH_ON;
- }
+ case VIR_DOMAIN_FEATURE_SMM: {
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ON;
+
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_NONE, &state) < 0)
+ return -1;
+
+ def->features[val] = state;
break;
+ }
case VIR_DOMAIN_FEATURE_GIC:
if ((tmp = virXMLPropString(nodes[i], "version"))) {
@@ -18030,20 +18028,16 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_FEATURE_HTM:
case VIR_DOMAIN_FEATURE_NESTED_HV:
- case VIR_DOMAIN_FEATURE_CCF_ASSIST:
- if (!(tmp = virXMLPropString(nodes[i], "state"))) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("missing state attribute '%s' of feature
'%s'"),
- tmp, virDomainFeatureTypeToString(val));
- return -1;
- }
- if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown state attribute '%s' of feature
'%s'"),
- tmp, virDomainFeatureTypeToString(val));
+ case VIR_DOMAIN_FEATURE_CCF_ASSIST: {
+ virTristateSwitch state;
+
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_REQUIRED, &state) < 0)
return -1;
- }
+
+ def->features[val] = state;
break;
+ }
/* coverity[dead_error_begin] */
case VIR_DOMAIN_FEATURE_LAST:
@@ -18054,13 +18048,11 @@ virDomainFeaturesDefParse(virDomainDef *def,
if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
- xmlNodePtr node = ctxt->node;
+ virTristateSwitch value;
if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) <
0)
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
feature = virDomainHypervTypeFromString((const char *)nodes[i]->name);
if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18069,23 +18061,9 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1;
}
- ctxt->node = nodes[i];
-
- if (!(tmp = virXMLPropString(nodes[i], "state"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("missing 'state' attribute for "
- "HyperV Enlightenment feature '%s'"),
- nodes[i]->name);
- return -1;
- }
-
- if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("invalid value of state argument "
- "for HyperV Enlightenment feature
'%s'"),
- nodes[i]->name);
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_REQUIRED, &value) < 0)
return -1;
- }
def->hyperv_features[feature] = value;
@@ -18155,17 +18133,13 @@ virDomainFeaturesDefParse(virDomainDef *def,
}
}
VIR_FREE(nodes);
- ctxt->node = node;
}
if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] == VIR_TRISTATE_SWITCH_ON) {
- int value;
if ((n = virXPathNodeSet("./features/hyperv/stimer/*", ctxt,
&nodes)) < 0)
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
-
if (STRNEQ((const char *)nodes[i]->name, "direct")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported Hyper-V stimer feature: %s"),
@@ -18173,34 +18147,21 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1;
}
- if (!(tmp = virXMLPropString(nodes[i], "state"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("missing 'state' attribute for "
- "Hyper-V stimer '%s' feature"),
"direct");
- return -1;
- }
-
- if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("invalid value of state argument "
- "for Hyper-V stimer '%s' feature"),
"direct");
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_REQUIRED,
+ &def->hyperv_stimer_direct) < 0)
return -1;
- }
-
- def->hyperv_stimer_direct = value;
}
VIR_FREE(nodes);
}
if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
+ virTristateSwitch value;
if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) <
0)
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
-
feature = virDomainKVMTypeFromString((const char *)nodes[i]->name);
if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18213,21 +18174,10 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_KVM_HIDDEN:
case VIR_DOMAIN_KVM_DEDICATED:
case VIR_DOMAIN_KVM_POLLCONTROL:
- if (!(tmp = virXMLPropString(nodes[i], "state"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("missing 'state' attribute for
"
- "KVM feature '%s'"),
- nodes[i]->name);
- return -1;
- }
-
- if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("invalid value of state argument "
- "for KVM feature '%s'"),
- nodes[i]->name);
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_REQUIRED,
+ &value) < 0)
return -1;
- }
def->kvm_features[feature] = value;
break;
@@ -18242,14 +18192,13 @@ virDomainFeaturesDefParse(virDomainDef *def,
if (def->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
+ virTristateSwitch value;
g_autofree char *ptval = NULL;
if ((n = virXPathNodeSet("./features/xen/*", ctxt, &nodes)) <
0)
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
feature = virDomainXenTypeFromString((const char *)nodes[i]->name);
if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18258,21 +18207,9 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1;
}
- if (!(tmp = virXMLPropString(nodes[i], "state"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("missing 'state' attribute for "
- "Xen feature '%s'"),
- nodes[i]->name);
- return -1;
- }
-
- if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("invalid value of state argument "
- "for Xen feature '%s'"),
- nodes[i]->name);
+ if (virXMLPropTristateSwitch(nodes[i], "state",
+ VIR_XML_PROP_REQUIRED, &value) < 0)
return -1;
- }
def->xen_features[feature] = value;
@@ -18351,7 +18288,7 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ON;
int val = virDomainProcessCapsFeatureTypeFromString((const char
*)nodes[i]->name);
if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18359,16 +18296,12 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1;
}
- if ((tmp = virXMLPropString(nodes[i], "state"))) {
- if ((def->caps_features[val] = virTristateSwitchTypeFromString(tmp)) ==
-1) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown state attribute '%s' of feature
capability '%s'"),
- tmp, virDomainProcessCapsFeatureTypeToString(val));
- return -1;
- }
- } else {
- def->caps_features[val] = VIR_TRISTATE_SWITCH_ON;
- }
+
+ if (virXMLPropTristateSwitch(nodes[i], "state", VIR_XML_PROP_NONE,
+ &state) < 0)
+ return -1;
+
+ def->caps_features[val] = state;
}
VIR_FREE(nodes);
return 0;
--
2.26.3