[PATCH v2 1/3] conf: refactor hyperv features parsing

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

 



1. All hyperv features are tristate ones. So make tristate parsing code common.
2. Reindent switch statement.
3. Reduce nesting in spinlocks parsing.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/conf/domain_conf.c | 96 +++++++++++++++++++++-----------------------------
 1 file changed, 40 insertions(+), 56 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 314a584..1040217 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15584,68 +15584,52 @@ virDomainDefParseXML(xmlDocPtr xml,
 
             ctxt->node = nodes[i];
 
-            switch ((virDomainHyperv) feature) {
-                case VIR_DOMAIN_HYPERV_RELAXED:
-                case VIR_DOMAIN_HYPERV_VAPIC:
-                    if (!(tmp = virXPathString("string(./@state)", ctxt))) {
-                        virReportError(VIR_ERR_XML_ERROR,
-                                       _("missing 'state' attribute for "
-                                         "HyperV Enlightenment feature '%s'"),
-                                       nodes[i]->name);
-                        goto error;
-                    }
-
-                    if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
-                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                       _("invalid value of state argument "
-                                         "for HyperV Enlightenment feature '%s'"),
-                                       nodes[i]->name);
-                        goto error;
-                    }
+            if (!(tmp = virXPathString("string(./@state)", ctxt))) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("missing 'state' attribute for "
+                                 "HyperV Enlightenment feature '%s'"),
+                               nodes[i]->name);
+                goto error;
+            }
 
-                    VIR_FREE(tmp);
-                    def->hyperv_features[feature] = value;
-                    break;
+            if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("invalid value of state argument "
+                                 "for HyperV Enlightenment feature '%s'"),
+                               nodes[i]->name);
+                goto error;
+            }
 
-                case VIR_DOMAIN_HYPERV_SPINLOCKS:
-                    if (!(tmp = virXPathString("string(./@state)", ctxt))) {
-                        virReportError(VIR_ERR_XML_ERROR,
-                                       _("missing 'state' attribute for "
-                                         "HyperV Enlightenment feature '%s'"),
-                                       nodes[i]->name);
-                        goto error;
-                    }
+            VIR_FREE(tmp);
+            def->hyperv_features[feature] = value;
 
-                    if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
-                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                       _("invalid value of state argument "
-                                         "for HyperV Enlightenment feature '%s'"),
-                                       nodes[i]->name);
-                        goto error;
-                    }
+            switch ((virDomainHyperv) feature) {
+            case VIR_DOMAIN_HYPERV_RELAXED:
+            case VIR_DOMAIN_HYPERV_VAPIC:
+                break;
 
-                    VIR_FREE(tmp);
-                    if (value == VIR_TRISTATE_SWITCH_ON) {
-                        if (virXPathUInt("string(./@retries)", ctxt,
-                                     &def->hyperv_spinlocks) < 0) {
-                            virReportError(VIR_ERR_XML_ERROR, "%s",
-                                           _("invalid HyperV spinlock retry count"));
-                            goto error;
-                        }
-
-                        if (def->hyperv_spinlocks < 0xFFF) {
-                            virReportError(VIR_ERR_XML_ERROR, "%s",
-                                           _("HyperV spinlock retry count must be "
-                                             "at least 4095"));
-                            goto error;
-                        }
-                    }
-                    def->hyperv_features[feature] = value;
+            case VIR_DOMAIN_HYPERV_SPINLOCKS:
+                if (value != VIR_TRISTATE_SWITCH_ON)
                     break;
 
-                /* coverity[dead_error_begin] */
-                case VIR_DOMAIN_HYPERV_LAST:
-                    break;
+                if (virXPathUInt("string(./@retries)", ctxt,
+                             &def->hyperv_spinlocks) < 0) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                                   _("invalid HyperV spinlock retry count"));
+                    goto error;
+                }
+
+                if (def->hyperv_spinlocks < 0xFFF) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                                   _("HyperV spinlock retry count must be "
+                                     "at least 4095"));
+                    goto error;
+                }
+                break;
+
+            /* coverity[dead_error_begin] */
+            case VIR_DOMAIN_HYPERV_LAST:
+                break;
             }
         }
         VIR_FREE(nodes);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]