]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: explicitly error for non-x86 default CPU
authorCole Robinson <crobinso@redhat.com>
Thu, 13 Jul 2017 19:15:38 +0000 (15:15 -0400)
committerCole Robinson <crobinso@redhat.com>
Thu, 3 Aug 2017 15:54:42 +0000 (11:54 -0400)
The code only currently handles writing an x86 default -cpu
argument, and doesn't know anything about other architectures.
Let's make this explicit rather than leaving ex. qemu ppc64 to
throw an error about -cpu qemu64

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
src/qemu/qemu_command.c

index 189441377ff068655d2e5a12e4a07abd92ade0ad..604650596324f296dd49775d4965d13e6b71647e 100644 (file)
@@ -6814,17 +6814,11 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
     virArch hostarch = virArchFromHost();
     char *cpu = NULL, *cpu_flags = NULL;
     bool hasHwVirt = false;
-    const char *default_model;
     int ret = -1;
     virBuffer cpu_buf = VIR_BUFFER_INITIALIZER;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    if (def->os.arch == VIR_ARCH_I686)
-        default_model = "qemu32";
-    else
-        default_model = "qemu64";
-
     if (def->cpu &&
         (def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
         if (qemuBuildCpuModelArgStr(driver, def, &cpu_buf, qemuCaps) < 0)
@@ -6866,7 +6860,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
             ((hostarch == VIR_ARCH_X86_64 &&
               strstr(def->emulator, "kvm")) ||
              strstr(def->emulator, "x86_64"))) {
-            virBufferAdd(&cpu_buf, default_model, -1);
+            virBufferAddLit(&cpu_buf, "qemu32");
         }
     }
 
@@ -7013,6 +7007,23 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
     cpu_flags = virBufferContentAndReset(&buf);
 
     if (cpu_flags && !cpu) {
+        const char *default_model;
+
+        switch (def->os.arch) {
+        case VIR_ARCH_I686:
+            default_model = "qemu32";
+            break;
+        case VIR_ARCH_X86_64:
+            default_model = "qemu64";
+            break;
+        default:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("CPU flags requested but can't determine "
+                             "default CPU for arch %s"),
+                           virArchToString(def->os.arch));
+            goto cleanup;
+        }
+
         if (VIR_STRDUP(cpu, default_model) < 0)
             goto cleanup;
     }