cpu: Split up virCPUDataParse

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>
This commit is contained in:
Tim Wiederhake 2021-10-13 12:56:51 +02:00
parent 6c72b352e5
commit 399d6df60e
3 changed files with 24 additions and 8 deletions

View 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);
}

View 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);

View File

@ -1464,6 +1464,7 @@ virCPUDataFormat;
virCPUDataFree;
virCPUDataNew;
virCPUDataParse;
virCPUDataParseNode;
virCPUExpandFeatures;
virCPUGetHost;
virCPUGetHostIsSupported;