[libvirt PATCH v2 05/20] cpu: Split up virCPUDataParse

Tim Wiederhake twiederh at redhat.com
Thu Nov 4 16:27:05 UTC 2021


This makes it possible to call virCPUDataParse with a xmlNodePtr,
which will be required by a later patch.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/cpu/cpu.c            | 29 +++++++++++++++++++++--------
 src/cpu/cpu.h            |  2 ++
 src/libvirt_private.syms |  1 +
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 7823c7cd3d..b97d06c7d8 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -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);
 }
 
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index c4897a33f5..a67af61757 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -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);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 55ae7d5b6f..21a723035d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1462,6 +1462,7 @@ virCPUDataFormat;
 virCPUDataFree;
 virCPUDataNew;
 virCPUDataParse;
+virCPUDataParseNode;
 virCPUExpandFeatures;
 virCPUGetHost;
 virCPUGetHostIsSupported;
-- 
2.31.1




More information about the libvir-list mailing list