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 418e86ebcb..83fc12c41b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18237,6 +18237,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,
@@ -18246,16 +18247,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:
@@ -18287,16 +18280,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:
@@ -18404,18 +18391,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] */
@@ -18427,13 +18405,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,
@@ -18444,23 +18421,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);
+ if (virXMLPropTristateSwitch(nodes[i], "state", true, &state)
< 0)
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);
- return -1;
- }
-
- def->hyperv_features[feature] = value;
+ def->hyperv_features[feature] = state;
switch ((virDomainHyperv) feature) {
case VIR_DOMAIN_HYPERV_RELAXED:
@@ -18478,7 +18442,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,
@@ -18497,7 +18461,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],
@@ -18534,13 +18498,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"),
@@ -18548,33 +18511,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) {
@@ -18588,23 +18539,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);
+ if (virXMLPropTristateSwitch(nodes[i], "state", true,
&state) < 0)
return -1;
- }
-
- if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("invalid value of state argument "
- "for KVM feature '%s'"),
- nodes[i]->name);
- return -1;
- }
-
- def->kvm_features[feature] = value;
+ def->kvm_features[feature] = state;
break;
/* coverity[dead_error_begin] */
@@ -18617,14 +18554,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,
@@ -18633,30 +18569,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"))) {
@@ -18726,7 +18649,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,
@@ -18734,16 +18657,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