]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainNumaDefNodeCacheParseXML: Refactor parsing of cache XML
authorPeter Krempa <pkrempa@redhat.com>
Tue, 16 May 2023 08:19:42 +0000 (10:19 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 17 May 2023 08:07:18 +0000 (10:07 +0200)
Use virXMLProp* helpers to simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/numa_conf.c

index b21671f5879fa20fbfd0c42a83fbb9002163c990..c2e3045280fc0a85ed6bed1b6748d86379b5245e 100644 (file)
@@ -815,68 +815,36 @@ virDomainNumaDefNodeCacheParseXML(virDomainNuma *def,
     for (i = 0; i < n; i++) {
         VIR_XPATH_NODE_AUTORESTORE(ctxt)
         virNumaCache *cache = &def->mem_nodes[cur_cell].caches[i];
-        g_autofree char *tmp = NULL;
-        unsigned int level;
-        int associativity;
-        int policy;
-        unsigned long long size;
         unsigned long long line;
 
-        if (!(tmp = virXMLPropString(nodes[i], "level"))) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Missing 'level' attribute in cache element for NUMA node %1$d"),
-                           cur_cell);
-            return -1;
-        }
-
-        if (virStrToLong_uip(tmp, NULL, 10, &level) < 0 ||
-            level == 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid 'level' attribute in cache element for NUMA node %1$d"),
-                           cur_cell);
-            return -1;
-        }
-        VIR_FREE(tmp);
-
-        if (!(tmp = virXMLPropString(nodes[i], "associativity"))) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Missing 'associativity' attribute in cache element for NUMA node %1$d"),
-                           cur_cell);
+        if (virXMLPropUInt(nodes[i], "level", 10,
+                           VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                           &cache->level) < 0)
             return -1;
-        }
 
-        if ((associativity = virNumaCacheAssociativityTypeFromString(tmp)) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid cache associativity '%1$s'"),
-                           tmp);
+        if (virXMLPropEnum(nodes[i], "associativity",
+                           virNumaCacheAssociativityTypeFromString,
+                           VIR_XML_PROP_REQUIRED,
+                           &cache->associativity) < 0)
             return -1;
-        }
-        VIR_FREE(tmp);
-
-        if (!(tmp = virXMLPropString(nodes[i], "policy"))) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Missing 'policy' attribute in cache element for NUMA node %1$d"),
-                           cur_cell);
-        }
 
-        if ((policy = virNumaCachePolicyTypeFromString(tmp)) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid cache policy '%1$s'"),
-                           tmp);
+        if (virXMLPropEnum(nodes[i], "policy",
+                           virNumaCachePolicyTypeFromString,
+                           VIR_XML_PROP_REQUIRED,
+                           &cache->policy) < 0)
             return -1;
-        }
-        VIR_FREE(tmp);
 
         ctxt->node = nodes[i];
         if (virDomainParseMemory("./size/@value", "./size/unit",
-                                 ctxt, &size, true, false) < 0)
+                                 ctxt, &cache->size, true, false) < 0)
             return -1;
 
         if (virParseScaledValue("./line/@value", "./line/unit",
                                 ctxt, &line, 1, ULLONG_MAX, true) < 0)
             return -1;
 
-        *cache = (virNumaCache){level, size, line, associativity, policy};
+        cache->line = line;
+
         def->mem_nodes[cur_cell].ncaches++;
     }