]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virCPUDefParseXML: Prefer virXMLPropUInt over virXPathUInt
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 21 Sep 2021 14:26:48 +0000 (16:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 1 Oct 2021 08:52:35 +0000 (10:52 +0200)
When parsing CPU topology, which is described in <topology/>
attributes we can use virXMLPropUInt() instead of virXPathUInt()
as the former results in shorter code.

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

index d31f28dfe7fea653f2a50e357945fc20f75d5a29..fbceac1657b3f1387e626b6363bbb4368a6003af 100644 (file)
@@ -320,6 +320,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
 {
     g_autoptr(virCPUDef) def = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
+    xmlNodePtr topology = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     int n;
     size_t i;
@@ -525,38 +526,32 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
         return -1;
     }
 
-    if (virXPathNode("./topology[1]", ctxt)) {
-        if (virXPathUInt("string(./topology[1]/@sockets)", ctxt, &def->sockets) < 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("Missing 'sockets' attribute in CPU topology"));
-            return -1;
-        }
+    if ((topology = virXPathNode("./topology[1]", ctxt))) {
+        int rc;
 
-        if (virXPathNode("./topology[1]/@dies", ctxt)) {
-            if (virXPathUInt("string(./topology[1]/@dies)", ctxt, &def->dies) < 0) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("Malformed 'dies' attribute in CPU topology"));
-                return -1;
-            }
-        } else {
-            def->dies = 1;
+        if (virXMLPropUInt(topology, "sockets", 10,
+                           VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                           &def->sockets) < 0) {
+            return -1;
         }
 
-        if (virXPathUInt("string(./topology[1]/@cores)", ctxt, &def->cores) < 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("Missing 'cores' attribute in CPU topology"));
+        if ((rc = virXMLPropUInt(topology, "dies", 10,
+                                 VIR_XML_PROP_NONZERO,
+                                 &def->dies)) < 0) {
             return -1;
+        } else if (rc == 0) {
+            def->dies = 1;
         }
 
-        if (virXPathUInt("string(./topology[1]/@threads)", ctxt, &def->threads) < 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("Missing 'threads' attribute in CPU topology"));
+        if (virXMLPropUInt(topology, "cores", 10,
+                           VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                           &def->cores) < 0) {
             return -1;
         }
 
-        if (!def->sockets || !def->cores || !def->threads || !def->dies) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("Invalid CPU topology"));
+        if (virXMLPropUInt(topology, "threads", 10,
+                           VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                           &def->threads) < 0) {
             return -1;
         }
     }