virDomainFeaturesDefParse: Use virXMLPropTristateSwitch

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-04-27 13:12:55 +02:00 committed by Ján Tomko
parent f45937c9cf
commit 54635ea592

View File

@ -17952,18 +17952,16 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_FEATURE_PMU: case VIR_DOMAIN_FEATURE_PMU:
case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_PVSPINLOCK:
case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_VMPORT:
case VIR_DOMAIN_FEATURE_SMM: case VIR_DOMAIN_FEATURE_SMM: {
if ((tmp = virXMLPropString(nodes[i], "state"))) { virTristateSwitch state = VIR_TRISTATE_SWITCH_ON;
if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) == -1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, if (virXMLPropTristateSwitch(nodes[i], "state",
_("unknown state attribute '%s' of feature '%s'"), VIR_XML_PROP_NONE, &state) < 0)
tmp, virDomainFeatureTypeToString(val)); return -1;
return -1;
} def->features[val] = state;
} else {
def->features[val] = VIR_TRISTATE_SWITCH_ON;
}
break; break;
}
case VIR_DOMAIN_FEATURE_GIC: case VIR_DOMAIN_FEATURE_GIC:
if ((tmp = virXMLPropString(nodes[i], "version"))) { if ((tmp = virXMLPropString(nodes[i], "version"))) {
@ -18069,20 +18067,16 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_HTM:
case VIR_DOMAIN_FEATURE_NESTED_HV: case VIR_DOMAIN_FEATURE_NESTED_HV:
case VIR_DOMAIN_FEATURE_CCF_ASSIST: case VIR_DOMAIN_FEATURE_CCF_ASSIST: {
if (!(tmp = virXMLPropString(nodes[i], "state"))) { virTristateSwitch state;
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("missing state attribute '%s' of feature '%s'"), if (virXMLPropTristateSwitch(nodes[i], "state",
tmp, virDomainFeatureTypeToString(val)); VIR_XML_PROP_REQUIRED, &state) < 0)
return -1; return -1;
}
if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) { def->features[val] = state;
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown state attribute '%s' of feature '%s'"),
tmp, virDomainFeatureTypeToString(val));
return -1;
}
break; break;
}
/* coverity[dead_error_begin] */ /* coverity[dead_error_begin] */
case VIR_DOMAIN_FEATURE_LAST: case VIR_DOMAIN_FEATURE_LAST:
@ -18093,13 +18087,11 @@ virDomainFeaturesDefParse(virDomainDef *def,
if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) {
int feature; int feature;
int value; virTristateSwitch value;
xmlNodePtr node = ctxt->node;
if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) < 0)
return -1; return -1;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
g_autofree char *tmp = NULL;
feature = virDomainHypervTypeFromString((const char *)nodes[i]->name); feature = virDomainHypervTypeFromString((const char *)nodes[i]->name);
if (feature < 0) { if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -18108,23 +18100,9 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1; return -1;
} }
ctxt->node = nodes[i]; if (virXMLPropTristateSwitch(nodes[i], "state",
VIR_XML_PROP_REQUIRED, &value) < 0)
if (!(tmp = virXMLPropString(nodes[i], "state"))) {
virReportError(VIR_ERR_XML_ERROR,
_("missing 'state' attribute for "
"HyperV Enlightenment feature '%s'"),
nodes[i]->name);
return -1; 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] = value;
@ -18194,17 +18172,13 @@ virDomainFeaturesDefParse(virDomainDef *def,
} }
} }
VIR_FREE(nodes); VIR_FREE(nodes);
ctxt->node = node;
} }
if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] == VIR_TRISTATE_SWITCH_ON) { if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] == VIR_TRISTATE_SWITCH_ON) {
int value;
if ((n = virXPathNodeSet("./features/hyperv/stimer/*", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./features/hyperv/stimer/*", ctxt, &nodes)) < 0)
return -1; return -1;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
g_autofree char *tmp = NULL;
if (STRNEQ((const char *)nodes[i]->name, "direct")) { if (STRNEQ((const char *)nodes[i]->name, "direct")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported Hyper-V stimer feature: %s"), _("unsupported Hyper-V stimer feature: %s"),
@ -18212,34 +18186,21 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1; return -1;
} }
if (!(tmp = virXMLPropString(nodes[i], "state"))) { if (virXMLPropTristateSwitch(nodes[i], "state",
virReportError(VIR_ERR_XML_ERROR, VIR_XML_PROP_REQUIRED,
_("missing 'state' attribute for " &def->hyperv_stimer_direct) < 0)
"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");
return -1; return -1;
}
def->hyperv_stimer_direct = value;
} }
VIR_FREE(nodes); VIR_FREE(nodes);
} }
if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) { if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) {
int feature; int feature;
int value; virTristateSwitch value;
if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0)
return -1; return -1;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
g_autofree char *tmp = NULL;
feature = virDomainKVMTypeFromString((const char *)nodes[i]->name); feature = virDomainKVMTypeFromString((const char *)nodes[i]->name);
if (feature < 0) { if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -18252,21 +18213,10 @@ virDomainFeaturesDefParse(virDomainDef *def,
case VIR_DOMAIN_KVM_HIDDEN: case VIR_DOMAIN_KVM_HIDDEN:
case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_DEDICATED:
case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_POLLCONTROL:
if (!(tmp = virXMLPropString(nodes[i], "state"))) { if (virXMLPropTristateSwitch(nodes[i], "state",
virReportError(VIR_ERR_XML_ERROR, VIR_XML_PROP_REQUIRED,
_("missing 'state' attribute for " &value) < 0)
"KVM feature '%s'"),
nodes[i]->name);
return -1; 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] = value;
break; break;
@ -18281,14 +18231,13 @@ virDomainFeaturesDefParse(virDomainDef *def,
if (def->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) { if (def->features[VIR_DOMAIN_FEATURE_XEN] == VIR_TRISTATE_SWITCH_ON) {
int feature; int feature;
int value; virTristateSwitch value;
g_autofree char *ptval = NULL; g_autofree char *ptval = NULL;
if ((n = virXPathNodeSet("./features/xen/*", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./features/xen/*", ctxt, &nodes)) < 0)
return -1; return -1;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
g_autofree char *tmp = NULL;
feature = virDomainXenTypeFromString((const char *)nodes[i]->name); feature = virDomainXenTypeFromString((const char *)nodes[i]->name);
if (feature < 0) { if (feature < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -18297,21 +18246,9 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1; return -1;
} }
if (!(tmp = virXMLPropString(nodes[i], "state"))) { if (virXMLPropTristateSwitch(nodes[i], "state",
virReportError(VIR_ERR_XML_ERROR, VIR_XML_PROP_REQUIRED, &value) < 0)
_("missing 'state' attribute for "
"Xen feature '%s'"),
nodes[i]->name);
return -1; return -1;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid value of state argument "
"for Xen feature '%s'"),
nodes[i]->name);
return -1;
}
def->xen_features[feature] = value; def->xen_features[feature] = value;
@ -18390,7 +18327,7 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1; return -1;
for (i = 0; i < n; i++) { 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); int val = virDomainProcessCapsFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) { if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -18398,16 +18335,12 @@ virDomainFeaturesDefParse(virDomainDef *def,
return -1; return -1;
} }
if ((tmp = virXMLPropString(nodes[i], "state"))) {
if ((def->caps_features[val] = virTristateSwitchTypeFromString(tmp)) == -1) { if (virXMLPropTristateSwitch(nodes[i], "state", VIR_XML_PROP_NONE,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, &state) < 0)
_("unknown state attribute '%s' of feature capability '%s'"), return -1;
tmp, virDomainProcessCapsFeatureTypeToString(val));
return -1; def->caps_features[val] = state;
}
} else {
def->caps_features[val] = VIR_TRISTATE_SWITCH_ON;
}
} }
VIR_FREE(nodes); VIR_FREE(nodes);
return 0; return 0;