mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
cpu_x86: Separate feature list parsing from x86ModelParse
The code is separated into a new x86ModelParseFeatures function. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
232266839c
commit
8d249df9c9
@ -1249,16 +1249,51 @@ x86ModelParseVendor(virCPUx86ModelPtr model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
x86ModelParseFeatures(virCPUx86ModelPtr model,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
virCPUx86MapPtr map)
|
||||||
|
{
|
||||||
|
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
|
||||||
|
size_t i;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) <= 0)
|
||||||
|
return n;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
VIR_AUTOFREE(char *) ftname = NULL;
|
||||||
|
virCPUx86FeaturePtr feature;
|
||||||
|
|
||||||
|
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Missing feature name for CPU model %s"),
|
||||||
|
model->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(feature = x86FeatureFind(map, ftname))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Feature %s required by CPU model %s not found"),
|
||||||
|
ftname, model->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x86DataAdd(&model->data, &feature->data))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x86ModelParse(xmlXPathContextPtr ctxt,
|
x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
virCPUx86MapPtr map = data;
|
virCPUx86MapPtr map = data;
|
||||||
xmlNodePtr *nodes = NULL;
|
|
||||||
virCPUx86ModelPtr model;
|
virCPUx86ModelPtr model;
|
||||||
size_t i;
|
|
||||||
int n;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(model = x86ModelNew()))
|
if (!(model = x86ModelNew()))
|
||||||
@ -1276,33 +1311,9 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
|||||||
if (x86ModelParseVendor(model, ctxt, map) < 0)
|
if (x86ModelParseVendor(model, ctxt, map) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
n = virXPathNodeSet("./feature", ctxt, &nodes);
|
if (x86ModelParseFeatures(model, ctxt, map) < 0)
|
||||||
if (n < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
virCPUx86FeaturePtr feature;
|
|
||||||
char *ftname;
|
|
||||||
|
|
||||||
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Missing feature name for CPU model %s"), model->name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(feature = x86FeatureFind(map, ftname))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Feature %s required by CPU model %s not found"),
|
|
||||||
ftname, model->name);
|
|
||||||
VIR_FREE(ftname);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
VIR_FREE(ftname);
|
|
||||||
|
|
||||||
if (x86DataAdd(&model->data, &feature->data))
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -1310,7 +1321,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
x86ModelFree(model);
|
x86ModelFree(model);
|
||||||
VIR_FREE(nodes);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user