[libvirt PATCH 29/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainFeaturesDefParse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 138 ++++++++++++++---------------------------
 1 file changed, 48 insertions(+), 90 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 39f171ba74..4f020714bc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18292,6 +18292,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,
@@ -18301,16 +18302,9 @@ 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 (virXMLPropOnOff(nodes[i], "eoi", &triSwitch) < 0)
+                return -1;
+            def->apic_eoi = triSwitch;
             G_GNUC_FALLTHROUGH;
         case VIR_DOMAIN_FEATURE_ACPI:
         case VIR_DOMAIN_FEATURE_PAE:
@@ -18342,16 +18336,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 (virXMLPropOnOff(nodes[i], "state", &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:
@@ -18459,15 +18447,11 @@ 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));
+            if (virXMLPropOnOff(nodes[i], "state", &triSwitch) < 0)
                 return -1;
-            }
-            if ((def->features[val] = virTristateSwitchTypeFromString(tmp)) < 0) {
+            if ((def->features[val] = triSwitch) == VIR_TRISTATE_SWITCH_ABSENT) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("unknown state attribute '%s' of feature '%s'"),
+                               _("missing state attribute '%s' of feature '%s'"),
                                tmp, virDomainFeatureTypeToString(val));
                 return -1;
             }
@@ -18482,13 +18466,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,
@@ -18499,7 +18482,10 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
 
             ctxt->node = nodes[i];
 
-            if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+            if (virXMLPropOnOff(nodes[i], "state", &state) < 0)
+                return -1;
+
+            if (state == VIR_TRISTATE_SWITCH_ABSENT) {
                 virReportError(VIR_ERR_XML_ERROR,
                                _("missing 'state' attribute for "
                                  "HyperV Enlightenment feature '%s'"),
@@ -18507,15 +18493,7 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                 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:
@@ -18533,7 +18511,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,
@@ -18552,7 +18530,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],
@@ -18589,13 +18567,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"),
@@ -18603,33 +18580,28 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                 return -1;
             }
 
-            if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+            if (virXMLPropOnOff(nodes[i], "state", &state) < 0)
+                return -1;
+            def->hyperv_stimer_direct = state;
+
+            if (state == VIR_TRISTATE_SWITCH_ABSENT) {
                 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");
-                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;
+
         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) {
@@ -18643,7 +18615,11 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                 case VIR_DOMAIN_KVM_HIDDEN:
                 case VIR_DOMAIN_KVM_DEDICATED:
                 case VIR_DOMAIN_KVM_POLLCONTROL:
-                    if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+                    if (virXMLPropOnOff(nodes[i], "state", &state) < 0)
+                        return -1;
+                    def->kvm_features[feature] = state;
+
+                    if (state == VIR_TRISTATE_SWITCH_ABSENT) {
                         virReportError(VIR_ERR_XML_ERROR,
                                        _("missing 'state' attribute for "
                                          "KVM feature '%s'"),
@@ -18651,15 +18627,6 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                         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;
                     break;
 
                 /* coverity[dead_error_begin] */
@@ -18672,14 +18639,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,
@@ -18688,7 +18654,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                 return -1;
             }
 
-            if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+            if (virXMLPropOnOff(nodes[i], "state", &state) < 0)
+                return -1;
+
+            def->xen_features[feature] = state;
+
+            if (state == VIR_TRISTATE_SWITCH_ABSENT) {
                 virReportError(VIR_ERR_XML_ERROR,
                                _("missing 'state' attribute for "
                                  "Xen feature '%s'"),
@@ -18696,22 +18667,12 @@ virDomainFeaturesDefParse(virDomainDefPtr def,
                 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;
-
             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"))) {
@@ -18781,7 +18742,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,
@@ -18789,16 +18750,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 (virXMLPropOnOff(nodes[i], "state", &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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux