]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Split up virCPUDataParse
authorTim Wiederhake <twiederh@redhat.com>
Wed, 13 Oct 2021 10:56:51 +0000 (12:56 +0200)
committerTim Wiederhake <twiederh@redhat.com>
Fri, 5 Nov 2021 16:12:25 +0000 (17:12 +0100)
This makes it possible to call virCPUDataParse with a xmlNodePtr,
which will be required by a later patch.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/cpu/cpu.c
src/cpu/cpu.h
src/libvirt_private.syms

index 7823c7cd3d54b7c623b109d24e71a64149ef930f..b97d06c7d8069dd8dd9ef2bc06bb5415b369d6db 100644 (file)
@@ -803,11 +803,8 @@ virCPUDataFormat(const virCPUData *data)
 virCPUData *
 virCPUDataParse(const char *xmlStr)
 {
-    struct cpuArchDriver *driver;
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
-    virCPUData *data = NULL;
-    g_autofree char *arch = NULL;
 
     VIR_DEBUG("xmlStr=%s", xmlStr);
 
@@ -817,7 +814,25 @@ virCPUDataParse(const char *xmlStr)
         return NULL;
     }
 
-    if (!(arch = virXPathString("string(/cpudata/@arch)", ctxt))) {
+    return virCPUDataParseNode(ctxt->node);
+}
+
+
+/**
+ * virCPUDataParseNode:
+ *
+ * @node: XML node as produced by virCPUDataFormat
+ *
+ * Parses XML representation of virCPUData structure.
+ *
+ * Returns internal CPU data structure parsed from the XML or NULL on error.
+ */
+virCPUData *virCPUDataParseNode(xmlNodePtr node)
+{
+    g_autofree char *arch = NULL;
+    struct cpuArchDriver *driver;
+
+    if (!(arch = virXMLPropString(node, "arch"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing CPU data architecture"));
         return NULL;
@@ -827,13 +842,11 @@ virCPUDataParse(const char *xmlStr)
         return NULL;
 
     if (!driver->dataParse) {
-        virReportError(VIR_ERR_NO_SUPPORT,
-                       _("cannot parse %s CPU data"), arch);
+        virReportError(VIR_ERR_NO_SUPPORT, _("cannot parse %s CPU data"), arch);
         return NULL;
     }
 
-    data = driver->dataParse(ctxt->node);
-    return data;
+    return driver->dataParse(node);
 }
 
 
index c4897a33f5083aed71e4be2495c2db57a1959df9..a67af617578fba3913406834cebd041cbfdf3e15 100644 (file)
@@ -285,3 +285,5 @@ char *virCPUDataFormat(const virCPUData *data)
     ATTRIBUTE_NONNULL(1);
 virCPUData *virCPUDataParse(const char *xmlStr)
     ATTRIBUTE_NONNULL(1);
+virCPUData *virCPUDataParseNode(xmlNodePtr node)
+    ATTRIBUTE_NONNULL(1);
index 69ff1ca4303ae64946002bbf1a7d4b84c292b208..42060caae8af479bc38f90166163ead14ddfba8d 100644 (file)
@@ -1464,6 +1464,7 @@ virCPUDataFormat;
 virCPUDataFree;
 virCPUDataNew;
 virCPUDataParse;
+virCPUDataParseNode;
 virCPUExpandFeatures;
 virCPUGetHost;
 virCPUGetHostIsSupported;