}
+static struct cpuArchDriver *
+cpuGetSubDriverByName(const char *name)
+{
+ size_t i;
+
+ for (i = 0; i < NR_DRIVERS - 1; i++) {
+ if (STREQ_NULLABLE(name, drivers[i]->name))
+ return drivers[i];
+ }
+
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("CPU driver '%s' does not exist"),
+ name);
+ return NULL;
+}
+
+
/**
* cpuCompareXML:
*
/**
* cpuDataParse:
*
- * @arch: CPU architecture
* @xmlStr: XML string produced by cpuDataFormat
*
* Parses XML representation of virCPUData structure for test purposes.
* Returns internal CPU data structure parsed from the XML or NULL on error.
*/
virCPUDataPtr
-cpuDataParse(virArch arch,
- const char *xmlStr)
+cpuDataParse(const char *xmlStr)
{
struct cpuArchDriver *driver;
+ xmlDocPtr xml = NULL;
+ xmlXPathContextPtr ctxt = NULL;
+ virCPUDataPtr data = NULL;
+ char *arch = NULL;
- VIR_DEBUG("arch=%s, xmlStr=%s", virArchToString(arch), xmlStr);
+ VIR_DEBUG("xmlStr=%s", xmlStr);
- if (!(driver = cpuGetSubDriver(arch)))
- return NULL;
+ if (!(xml = virXMLParseStringCtxt(xmlStr, _("CPU data"), &ctxt))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("cannot parse CPU data"));
+ goto cleanup;
+ }
+
+ if (!(arch = virXPathString("string(/cpudata/@arch)", ctxt))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("missing CPU data architecture"));
+ goto cleanup;
+ }
+
+ if (!(driver = cpuGetSubDriverByName(arch)))
+ goto cleanup;
if (!driver->dataParse) {
virReportError(VIR_ERR_NO_SUPPORT,
- _("cannot parse %s CPU data"),
- virArchToString(arch));
- return NULL;
+ _("cannot parse %s CPU data"), arch);
+ goto cleanup;
}
- return driver->dataParse(xmlStr);
+ data = driver->dataParse(ctxt);
+
+ cleanup:
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(xml);
+ VIR_FREE(arch);
+ return data;
}
bool
(*cpuArchDataFormat)(const virCPUData *data);
typedef virCPUDataPtr
-(*cpuArchDataParse) (const char *xmlStr);
+(*cpuArchDataParse) (xmlXPathContextPtr ctxt);
typedef int
(*cpuArchGetModels) (char ***models);
*/
char *cpuDataFormat(const virCPUData *data)
ATTRIBUTE_NONNULL(1);
-virCPUDataPtr cpuDataParse(virArch arch,
- const char *xmlStr)
- ATTRIBUTE_NONNULL(2);
+virCPUDataPtr cpuDataParse(const char *xmlStr)
+ ATTRIBUTE_NONNULL(1);
#endif /* __VIR_CPU_H__ */
static virCPUDataPtr
-x86CPUDataParse(const char *xmlStr)
+x86CPUDataParse(xmlXPathContextPtr ctxt)
{
- xmlDocPtr xml = NULL;
- xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virCPUDataPtr cpuData = NULL;
virCPUx86Data *data = NULL;
if (VIR_ALLOC(data) < 0)
goto cleanup;
- if (!(xml = virXMLParseStringCtxt(xmlStr, _("CPU data"), &ctxt))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("cannot parse CPU data"));
- goto cleanup;
- }
- ctxt->node = xmlDocGetRootElement(xml);
-
- n = virXPathNodeSet("/cpudata[@arch='x86']/cpuid", ctxt, &nodes);
+ n = virXPathNodeSet("/cpudata/cpuid", ctxt, &nodes);
if (n <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no x86 CPU data found"));
cleanup:
VIR_FREE(nodes);
- xmlXPathFreeContext(ctxt);
- xmlFreeDoc(xml);
virCPUx86DataFree(data);
return cpuData;
}