From dcbc9a2cfa0894e2bfc46c2a01659a86518c6e0a Mon Sep 17 00:00:00 2001
From: Tim Wiederhake <twiederh@redhat.com>
Date: Tue, 22 Jun 2021 14:22:47 +0200
Subject: [PATCH] virDomainFeaturesKVMDefParse: Remove ctxt

Iterating over all child elements of a node does not require xpath.
By doing away with xpath for this code, the code can be simplified.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Shaokun Wei <weishaokun@kylinos.cn>
---
 src/conf/domain_conf.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ac2bb8abb4..9073db8541 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20594,38 +20594,34 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
 
 static int
 virDomainFeaturesKVMDefParse(virDomainDef *def,
-                             xmlXPathContext *ctxt)
+                             xmlNodePtr node)
 {
     g_autofree char *tmp = NULL;
-    g_autofree xmlNodePtr *nodes = NULL;
-    size_t i;
-    int n;
 
     def->features[VIR_DOMAIN_FEATURE_KVM] = VIR_TRISTATE_SWITCH_ON;
 
     if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) {
         int feature;
         virTristateSwitch value;
-        if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0)
-            return -1;
 
-        for (i = 0; i < n; i++) {
-            feature = virDomainKVMTypeFromString((const char *)nodes[i]->name);
+        node = xmlFirstElementChild(node);
+        while (node) {
+            feature = virDomainKVMTypeFromString((const char *)node->name);
             if (feature < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("unsupported KVM feature: %s"),
-                               nodes[i]->name);
+                               node->name);
                 return -1;
             }
 
             switch ((virDomainKVM) feature) {
                 case VIR_DOMAIN_KVM_HIDDEN:
                 case VIR_DOMAIN_KVM_DEDICATED:
-                    if (!(tmp = virXMLPropString(nodes[i], "state"))) {
+                    if (!(tmp = virXMLPropString(node, "state"))) {
                         virReportError(VIR_ERR_XML_ERROR,
                                        _("missing 'state' attribute for "
                                          "KVM feature '%s'"),
-                                       nodes[i]->name);
+                                       node->name);
                         return -1;
                     }
 
@@ -20633,7 +20629,7 @@ virDomainFeaturesKVMDefParse(virDomainDef *def,
                         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                        _("invalid value of state argument "
                                          "for KVM feature '%s'"),
-                                       nodes[i]->name);
+                                       node->name);
                         return -1;
                     }
 
@@ -20645,8 +20641,9 @@ virDomainFeaturesKVMDefParse(virDomainDef *def,
                 case VIR_DOMAIN_KVM_LAST:
                     break;
             }
+
+            node = xmlNextElementSibling(node);
         }
-        VIR_FREE(nodes);
     }
 
     return 0;
@@ -21173,7 +21170,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             break;
 
         case VIR_DOMAIN_FEATURE_KVM:
-            if (virDomainFeaturesKVMDefParse(def, ctxt) < 0)
+            if (virDomainFeaturesKVMDefParse(def, nodes[i]) < 0)
                 goto error;
             break;
         case VIR_DOMAIN_FEATURE_CAPABILITIES:
-- 
2.27.0

