[libvirt PATCH 02/16] virDomainFeaturesHyperVDefParse: Inline hyperv/stimer parsing

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

 



Iterating over all child elements of a node does not require xpath.
By doing away with xpath for this code, the code can be inlined and
simplified. This also removes the re-use of `nodes`, elimininating
two VIR_FREEs.

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

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8cf57db7ba..4ec5557eba 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17303,6 +17303,8 @@ virDomainFeaturesHyperVDefParse(virDomainDef *def,
             return -1;
 
         for (i = 0; i < n; i++) {
+            xmlNodePtr child;
+
             feature = virDomainHypervTypeFromString((const char *)nodes[i]->name);
             if (feature < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -17323,7 +17325,6 @@ virDomainFeaturesHyperVDefParse(virDomainDef *def,
             case VIR_DOMAIN_HYPERV_VPINDEX:
             case VIR_DOMAIN_HYPERV_RUNTIME:
             case VIR_DOMAIN_HYPERV_SYNIC:
-            case VIR_DOMAIN_HYPERV_STIMER:
             case VIR_DOMAIN_HYPERV_RESET:
             case VIR_DOMAIN_HYPERV_FREQUENCIES:
             case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
@@ -17332,6 +17333,28 @@ virDomainFeaturesHyperVDefParse(virDomainDef *def,
             case VIR_DOMAIN_HYPERV_EVMCS:
                 break;
 
+            case VIR_DOMAIN_HYPERV_STIMER:
+                if (value != VIR_TRISTATE_SWITCH_ON)
+                    break;
+
+                child = xmlFirstElementChild(nodes[i]);
+                while (child) {
+                    if (STRNEQ((const char *)child->name, "direct")) {
+                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                       _("unsupported Hyper-V stimer feature: %s"),
+                                       child->name);
+                        return -1;
+                    }
+
+                    if (virXMLPropTristateSwitch(child, "state",
+                                                 VIR_XML_PROP_REQUIRED,
+                                                 &def->hyperv_stimer_direct) < 0)
+                        return -1;
+
+                    child = xmlNextElementSibling(child);
+                }
+                break;
+
             case VIR_DOMAIN_HYPERV_SPINLOCKS:
                 if (value != VIR_TRISTATE_SWITCH_ON)
                     break;
@@ -17381,27 +17404,6 @@ virDomainFeaturesHyperVDefParse(virDomainDef *def,
                 break;
             }
         }
-        VIR_FREE(nodes);
-    }
-
-    if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] == VIR_TRISTATE_SWITCH_ON) {
-        if ((n = virXPathNodeSet("./features/hyperv/stimer/*", ctxt, &nodes)) < 0)
-            return -1;
-
-        for (i = 0; i < n; i++) {
-            if (STRNEQ((const char *)nodes[i]->name, "direct")) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("unsupported Hyper-V stimer feature: %s"),
-                               nodes[i]->name);
-                return -1;
-            }
-
-            if (virXMLPropTristateSwitch(nodes[i], "state",
-                                         VIR_XML_PROP_REQUIRED,
-                                         &def->hyperv_stimer_direct) < 0)
-                return -1;
-        }
-        VIR_FREE(nodes);
     }
 
     return 0;
-- 
2.31.1




[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