Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/domain_conf.c | 146 ++++++++++-------------------------------
1 file changed, 33 insertions(+), 113 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3289c9fa12..dfa8b98aae 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18236,6 +18236,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
for (i = 0; i < n; i++) {
g_autofree char *tmp = NULL;
+ virTristateSwitch triSwitch = VIR_TRISTATE_SWITCH_ABSENT;
int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18245,16 +18246,8 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
switch ((virDomainFeature) val) {
case VIR_DOMAIN_FEATURE_APIC:
- if ((tmp = virXPathString("string(./features/apic/@eoi)", ctxt)))
{
- int eoi;
- if ((eoi = virTristateSwitchTypeFromString(tmp)) <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown value for attribute eoi:
'%s'"),
- tmp);
- return -1;
- }
- def->apic_eoi = eoi;
- }
+ if (virXMLPropTristateSwitch(nodes[i], "eoi", false,
&def->apic_eoi) < 0)
+ return -1;
G_GNUC_FALLTHROUGH;
case VIR_DOMAIN_FEATURE_ACPI:
case VIR_DOMAIN_FEATURE_PAE:
@@ -18286,16 +18279,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
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 {
+ if (virXMLPropTristateSwitch(nodes[i], "state", false,
&triSwitch) < 0)
+ return -1;
+ if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT)
def->features[val] = VIR_TRISTATE_SWITCH_ON;
- }
break;
case VIR_DOMAIN_FEATURE_GIC:
@@ -18403,18 +18390,9 @@ virDomainFeaturesDefParse(virDomainDefPtr 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));
+ if (virXMLPropTristateSwitch(nodes[i], "state", true,
&triSwitch) < 0)
return -1;
- }
+ def->features[val] = triSwitch;
break;
/* coverity[dead_error_begin] */
@@ -18426,13 +18404,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT;
xmlNodePtr node = ctxt->node;
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,
@@ -18443,23 +18420,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
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", true, &state)
< 0)
return -1;
- }
- def->hyperv_features[feature] = value;
+ def->hyperv_features[feature] = state;
switch ((virDomainHyperv) feature) {
case VIR_DOMAIN_HYPERV_RELAXED:
@@ -18477,7 +18441,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
break;
case VIR_DOMAIN_HYPERV_SPINLOCKS:
- if (value != VIR_TRISTATE_SWITCH_ON)
+ if (state != VIR_TRISTATE_SWITCH_ON)
break;
if (virXPathUInt("string(./@retries)", ctxt,
@@ -18496,7 +18460,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
break;
case VIR_DOMAIN_HYPERV_VENDOR_ID:
- if (value != VIR_TRISTATE_SWITCH_ON)
+ if (state != VIR_TRISTATE_SWITCH_ON)
break;
if (!(def->hyperv_vendor_id = virXMLPropString(nodes[i],
@@ -18533,13 +18497,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
}
if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] == VIR_TRISTATE_SWITCH_ON) {
- int value;
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT;
+
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"),
@@ -18547,33 +18510,21 @@ virDomainFeaturesDefParse(virDomainDefPtr 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", true, &state)
< 0)
return -1;
- }
-
- def->hyperv_stimer_direct = value;
+ def->hyperv_stimer_direct = state;
}
VIR_FREE(nodes);
}
if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
+
if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) <
0)
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT;
feature = virDomainKVMTypeFromString((const char *)nodes[i]->name);
if (feature < 0) {
@@ -18587,23 +18538,9 @@ virDomainFeaturesDefParse(virDomainDefPtr 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", true,
&state) < 0)
return -1;
- }
-
- def->kvm_features[feature] = value;
+ def->kvm_features[feature] = state;
break;
/* coverity[dead_error_begin] */
@@ -18616,14 +18553,13 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
if (def->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) {
int feature;
- int value;
g_autofree char *ptval = NULL;
- g_autofree char *tmp = NULL;
if ((n = virXPathNodeSet("./features/xen/*", ctxt, &nodes)) <
0)
return -1;
for (i = 0; i < n; i++) {
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT;
feature = virDomainXenTypeFromString((const char *)nodes[i]->name);
if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18632,30 +18568,17 @@ virDomainFeaturesDefParse(virDomainDefPtr 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", true, &state)
< 0)
return -1;
- }
- def->xen_features[feature] = value;
+ def->xen_features[feature] = state;
switch ((virDomainXen) feature) {
case VIR_DOMAIN_XEN_E820_HOST:
break;
case VIR_DOMAIN_XEN_PASSTHROUGH:
- if (value != VIR_TRISTATE_SWITCH_ON)
+ if (state != VIR_TRISTATE_SWITCH_ON)
break;
if ((ptval = virXMLPropString(nodes[i], "mode"))) {
@@ -18725,7 +18648,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
return -1;
for (i = 0; i < n; i++) {
- g_autofree char *tmp = NULL;
+ virTristateSwitch state = VIR_TRISTATE_SWITCH_ABSENT;
int val = virDomainProcessCapsFeatureTypeFromString((const char
*)nodes[i]->name);
if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18733,16 +18656,13 @@ virDomainFeaturesDefParse(virDomainDefPtr 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", false, &state) <
0)
+ return -1;
+
+ if (state == VIR_TRISTATE_SWITCH_ABSENT)
+ state = VIR_TRISTATE_SWITCH_ON;
+
+ def->caps_features[val] = state;
}
VIR_FREE(nodes);
return 0;
--
2.26.2