c1c534
From dbdc7ec536154af91ae897663d82c57d11500d23 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <dbdc7ec536154af91ae897663d82c57d11500d23@dist-git>
c1c534
From: Jiri Denemark <jdenemar@redhat.com>
c1c534
Date: Thu, 7 Dec 2017 11:23:50 +0100
c1c534
Subject: [PATCH] qemu: Make sure host-model uses CPU model supported by QEMU
c1c534
c1c534
When reconnecting to a running domain started by old libvirt, which did
c1c534
not change host-model into a custom CPU definition, we replace the CPU
c1c534
definition with a specific CPU model from host capabilities. However,
c1c534
that CPU model may not be supported by the running qemu process. We need
c1c534
to translate the CPU model to one of the models which libvirt could have
c1c534
used when starting the domain.
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1521202
c1c534
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
(cherry picked from commit ce73de441d35e17a29b83b8741e668a6ddc013ba)
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_process.c | 30 ++++++++++++++++++++++++++++++
c1c534
 1 file changed, 30 insertions(+)
c1c534
c1c534
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c1c534
index 91426ad3c3..701528c42c 100644
c1c534
--- a/src/qemu/qemu_process.c
c1c534
+++ b/src/qemu/qemu_process.c
c1c534
@@ -3850,6 +3850,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static virDomainCapsCPUModelsPtr
c1c534
+qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver,
c1c534
+                               virDomainObjPtr vm,
c1c534
+                               qemuDomainAsyncJob asyncJob)
c1c534
+{
c1c534
+    qemuDomainObjPrivatePtr priv = vm->privateData;
c1c534
+    virDomainCapsCPUModelsPtr models = NULL;
c1c534
+
c1c534
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
c1c534
+        goto error;
c1c534
+
c1c534
+    models = virQEMUCapsFetchCPUDefinitions(priv->mon);
c1c534
+
c1c534
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
c1c534
+        goto error;
c1c534
+
c1c534
+    return models;
c1c534
+
c1c534
+ error:
c1c534
+    virObjectUnref(models);
c1c534
+    return NULL;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuProcessUpdateCPU(virQEMUDriverPtr driver,
c1c534
                      virDomainObjPtr vm,
c1c534
@@ -3857,6 +3881,7 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
c1c534
 {
c1c534
     virCPUDataPtr cpu = NULL;
c1c534
     virCPUDataPtr disabled = NULL;
c1c534
+    virDomainCapsCPUModelsPtr models = NULL;
c1c534
     int ret = -1;
c1c534
 
c1c534
     if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
c1c534
@@ -3865,11 +3890,16 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
c1c534
     if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
+    if (!(models = qemuProcessFetchCPUDefinitions(driver, vm, asyncJob)) ||
c1c534
+        virCPUTranslate(vm->def->os.arch, vm->def->cpu, models) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
     ret = 0;
c1c534
 
c1c534
  cleanup:
c1c534
     virCPUDataFree(cpu);
c1c534
     virCPUDataFree(disabled);
c1c534
+    virObjectUnref(models);
c1c534
     return ret;
c1c534
 }
c1c534
 
c1c534
-- 
c1c534
2.15.1
c1c534