The code is separated into a new x86ModelParseAncestor function.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
Notes:
Version 2:
- no change
src/cpu/cpu_x86.c | 65 +++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 27 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index d3a88da21d..8a0ff50afe 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -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
x86ModelParse(xmlXPathContextPtr ctxt,
const char *name,
@@ -1169,33 +1205,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
if (VIR_STRDUP(model->name, name) < 0)
goto cleanup;
- if (virXPathNode("./model", ctxt)) {
- virCPUx86ModelPtr ancestor;
- 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 (x86ModelParseAncestor(model, ctxt, map) < 0)
+ goto cleanup;
if (virXPathBoolean("boolean(./signature)", ctxt)) {
unsigned int sigFamily = 0;
--
2.21.0