cpu_x86: Separate ancestor model parsing from x86ModelParse

The code is separated into a new x86ModelParseAncestor function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2019-02-22 15:22:29 +01:00
parent 87a46f5d8f
commit 2e1e2b910c

View File

@ -1150,6 +1150,42 @@ x86ModelCompare(virCPUx86ModelPtr model1,
} }
static int
x86ModelParseAncestor(virCPUx86ModelPtr model,
xmlXPathContextPtr ctxt,
virCPUx86MapPtr map)
{
VIR_AUTOFREE(char *) name = NULL;
virCPUx86ModelPtr ancestor;
int rc;
if ((rc = virXPathBoolean("boolean(./model)", ctxt)) <= 0)
return rc;
name = virXPathString("string(./model/@name)", ctxt);
if (!name) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing ancestor's name in CPU model %s"),
model->name);
return -1;
}
if (!(ancestor = x86ModelFind(map, name))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Ancestor model %s not found for CPU model %s"),
name, model->name);
return -1;
}
model->vendor = ancestor->vendor;
model->signature = ancestor->signature;
if (x86DataCopy(&model->data, &ancestor->data) < 0)
return -1;
return 0;
}
static int static int
x86ModelParse(xmlXPathContextPtr ctxt, x86ModelParse(xmlXPathContextPtr ctxt,
const char *name, const char *name,
@ -1169,33 +1205,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
if (VIR_STRDUP(model->name, name) < 0) if (VIR_STRDUP(model->name, name) < 0)
goto cleanup; goto cleanup;
if (virXPathNode("./model", ctxt)) { if (x86ModelParseAncestor(model, ctxt, map) < 0)
virCPUx86ModelPtr ancestor; goto cleanup;
char *anname;
anname = virXPathString("string(./model/@name)", ctxt);
if (!anname) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing ancestor's name in CPU model %s"),
model->name);
goto cleanup;
}
if (!(ancestor = x86ModelFind(map, anname))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Ancestor model %s not found for CPU model %s"),
anname, model->name);
VIR_FREE(anname);
goto cleanup;
}
VIR_FREE(anname);
model->vendor = ancestor->vendor;
model->signature = ancestor->signature;
if (x86DataCopy(&model->data, &ancestor->data) < 0)
goto cleanup;
}
if (virXPathBoolean("boolean(./signature)", ctxt)) { if (virXPathBoolean("boolean(./signature)", ctxt)) {
unsigned int sigFamily = 0; unsigned int sigFamily = 0;