7a3408
From 71ec836090966a629753444b19d3beb6e490a571 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <71ec836090966a629753444b19d3beb6e490a571@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Fri, 21 Aug 2015 16:36:03 -0700
7a3408
Subject: [PATCH] cpu: Move check for NULL CPU model inside the driver
7a3408
7a3408
While the check is appropriate for eg. the x86 and generic drivers,
7a3408
there are some valid ppc64 guest configurations where the CPU
7a3408
model is supposed to be NULL.
7a3408
7a3408
Moving this check from the generic code to the drivers makes it
7a3408
possible to accomodate both use cases.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1251927
7a3408
(cherry picked from commit 5750149fedb2ec7f1aaaad8286650255718c861d)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1251927
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/cpu/cpu.c         | 12 ------------
7a3408
 src/cpu/cpu_generic.c |  6 ++++++
7a3408
 src/cpu/cpu_ppc64.c   |  3 ++-
7a3408
 src/cpu/cpu_x86.c     |  6 ++++++
7a3408
 4 files changed, 14 insertions(+), 13 deletions(-)
7a3408
7a3408
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
7a3408
index 731df26..1952b53 100644
7a3408
--- a/src/cpu/cpu.c
7a3408
+++ b/src/cpu/cpu.c
7a3408
@@ -142,12 +142,6 @@ cpuCompare(virCPUDefPtr host,
7a3408
 
7a3408
     VIR_DEBUG("host=%p, cpu=%p", host, cpu);
7a3408
 
7a3408
-    if (!cpu->model) {
7a3408
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
7a3408
-                       _("no guest CPU model specified"));
7a3408
-        return VIR_CPU_COMPARE_ERROR;
7a3408
-    }
7a3408
-
7a3408
     if ((driver = cpuGetSubDriver(host->arch)) == NULL)
7a3408
         return VIR_CPU_COMPARE_ERROR;
7a3408
 
7a3408
@@ -376,12 +370,6 @@ cpuGuestData(virCPUDefPtr host,
7a3408
 
7a3408
     VIR_DEBUG("host=%p, guest=%p, data=%p, msg=%p", host, guest, data, msg);
7a3408
 
7a3408
-    if (!guest->model) {
7a3408
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
7a3408
-                       _("no guest CPU model specified"));
7a3408
-        return VIR_CPU_COMPARE_ERROR;
7a3408
-    }
7a3408
-
7a3408
     if ((driver = cpuGetSubDriver(host->arch)) == NULL)
7a3408
         return VIR_CPU_COMPARE_ERROR;
7a3408
 
7a3408
diff --git a/src/cpu/cpu_generic.c b/src/cpu/cpu_generic.c
7a3408
index a9cde4c..f26a62d 100644
7a3408
--- a/src/cpu/cpu_generic.c
7a3408
+++ b/src/cpu/cpu_generic.c
7a3408
@@ -65,6 +65,12 @@ genericCompare(virCPUDefPtr host,
7a3408
     size_t i;
7a3408
     unsigned int reqfeatures;
7a3408
 
7a3408
+    if (!cpu->model) {
7a3408
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
7a3408
+                       _("no guest CPU model specified"));
7a3408
+        goto cleanup;
7a3408
+    }
7a3408
+
7a3408
     if ((cpu->arch != VIR_ARCH_NONE &&
7a3408
          host->arch != cpu->arch) ||
7a3408
         STRNEQ(host->model, cpu->model)) {
7a3408
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
7a3408
index a72cc32..364c8ed 100644
7a3408
--- a/src/cpu/cpu_ppc64.c
7a3408
+++ b/src/cpu/cpu_ppc64.c
7a3408
@@ -71,7 +71,8 @@ ppc64ConvertLegacyCPUDef(const virCPUDef *legacy)
7a3408
     if (!(cpu = virCPUDefCopy(legacy)))
7a3408
         goto out;
7a3408
 
7a3408
-    if (!(STREQ(cpu->model, "POWER7_v2.1") ||
7a3408
+    if (!cpu->model ||
7a3408
+        !(STREQ(cpu->model, "POWER7_v2.1") ||
7a3408
           STREQ(cpu->model, "POWER7_v2.3") ||
7a3408
           STREQ(cpu->model, "POWER7+_v2.1") ||
7a3408
           STREQ(cpu->model, "POWER8_v1.0"))) {
7a3408
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
7a3408
index f5f7697..90949f6 100644
7a3408
--- a/src/cpu/cpu_x86.c
7a3408
+++ b/src/cpu/cpu_x86.c
7a3408
@@ -1371,6 +1371,12 @@ x86Compute(virCPUDefPtr host,
7a3408
     virArch arch;
7a3408
     size_t i;
7a3408
 
7a3408
+    if (!cpu->model) {
7a3408
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
7a3408
+                       _("no guest CPU model specified"));
7a3408
+        return VIR_CPU_COMPARE_ERROR;
7a3408
+    }
7a3408
+
7a3408
     if (cpu->arch != VIR_ARCH_NONE) {
7a3408
         bool found = false;
7a3408
 
7a3408
-- 
7a3408
2.5.0
7a3408