render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From dbdc7ec536154af91ae897663d82c57d11500d23 Mon Sep 17 00:00:00 2001
Message-Id: <dbdc7ec536154af91ae897663d82c57d11500d23@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Thu, 7 Dec 2017 11:23:50 +0100
Subject: [PATCH] qemu: Make sure host-model uses CPU model supported by QEMU

When reconnecting to a running domain started by old libvirt, which did
not change host-model into a custom CPU definition, we replace the CPU
definition with a specific CPU model from host capabilities. However,
that CPU model may not be supported by the running qemu process. We need
to translate the CPU model to one of the models which libvirt could have
used when starting the domain.

https://bugzilla.redhat.com/show_bug.cgi?id=1521202

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit ce73de441d35e17a29b83b8741e668a6ddc013ba)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_process.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 91426ad3c3..701528c42c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3850,6 +3850,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
 }
 
 
+static virDomainCapsCPUModelsPtr
+qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver,
+                               virDomainObjPtr vm,
+                               qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virDomainCapsCPUModelsPtr models = NULL;
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+        goto error;
+
+    models = virQEMUCapsFetchCPUDefinitions(priv->mon);
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        goto error;
+
+    return models;
+
+ error:
+    virObjectUnref(models);
+    return NULL;
+}
+
+
 static int
 qemuProcessUpdateCPU(virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
@@ -3857,6 +3881,7 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
 {
     virCPUDataPtr cpu = NULL;
     virCPUDataPtr disabled = NULL;
+    virDomainCapsCPUModelsPtr models = NULL;
     int ret = -1;
 
     if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
@@ -3865,11 +3890,16 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
     if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0)
         goto cleanup;
 
+    if (!(models = qemuProcessFetchCPUDefinitions(driver, vm, asyncJob)) ||
+        virCPUTranslate(vm->def->os.arch, vm->def->cpu, models) < 0)
+        goto cleanup;
+
     ret = 0;
 
  cleanup:
     virCPUDataFree(cpu);
     virCPUDataFree(disabled);
+    virObjectUnref(models);
     return ret;
 }
 
-- 
2.15.1