render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a3bc25
From 9c2457dd94cf148dce04ee5fd3997003ca03a642 Mon Sep 17 00:00:00 2001
a3bc25
Message-Id: <9c2457dd94cf148dce04ee5fd3997003ca03a642@dist-git>
a3bc25
From: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Date: Tue, 11 Jul 2017 14:16:40 +0200
a3bc25
Subject: [PATCH] qemu: Update host-model CPUs on reconnect
a3bc25
a3bc25
When libvirt starts a new QEMU domain, it replaces host-model CPUs with
a3bc25
the appropriate custom CPU definition. However, when reconnecting to a
a3bc25
domain started by older libvirt (< 2.3), the domain would still have a
a3bc25
host-model CPU in its active definition.
a3bc25
a3bc25
https://bugzilla.redhat.com/show_bug.cgi?id=1463957
a3bc25
a3bc25
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
a3bc25
(cherry picked from commit 7cf22b4879e819dee42e0a058f7ed149dc9d639a)
a3bc25
a3bc25
https://bugzilla.redhat.com/show_bug.cgi?id=1470582
a3bc25
a3bc25
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
a3bc25
---
a3bc25
 src/qemu/qemu_process.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
a3bc25
 1 file changed, 48 insertions(+)
a3bc25
a3bc25
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
a3bc25
index e6f56dc484..8fe9ef36d7 100644
a3bc25
--- a/src/qemu/qemu_process.c
a3bc25
+++ b/src/qemu/qemu_process.c
a3bc25
@@ -3718,6 +3718,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
a3bc25
 
a3bc25
 
a3bc25
 static int
a3bc25
+qemuProcessUpdateCPU(virQEMUDriverPtr driver,
a3bc25
+                     virDomainObjPtr vm,
a3bc25
+                     qemuDomainAsyncJob asyncJob)
a3bc25
+{
a3bc25
+    virCPUDataPtr cpu = NULL;
a3bc25
+    virCPUDataPtr disabled = NULL;
a3bc25
+    int ret = -1;
a3bc25
+
a3bc25
+    if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
a3bc25
+        goto cleanup;
a3bc25
+
a3bc25
+    if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0)
a3bc25
+        goto cleanup;
a3bc25
+
a3bc25
+    ret = 0;
a3bc25
+
a3bc25
+ cleanup:
a3bc25
+    virCPUDataFree(cpu);
a3bc25
+    virCPUDataFree(disabled);
a3bc25
+    return ret;
a3bc25
+}
a3bc25
+
a3bc25
+
a3bc25
+static int
a3bc25
 qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
a3bc25
                  virDomainObjPtr vm)
a3bc25
 {
a3bc25
@@ -6796,6 +6820,30 @@ qemuProcessReconnect(void *opaque)
a3bc25
     ignore_value(qemuSecurityCheckAllLabel(driver->securityManager,
a3bc25
                                            obj->def));
a3bc25
 
a3bc25
+    /* If the domain with a host-model CPU was started by an old libvirt
a3bc25
+     * (< 2.3) which didn't replace the CPU with a custom one, let's do it now
a3bc25
+     * since the rest of our code does not really expect a host-model CPU in a
a3bc25
+     * running domain.
a3bc25
+     */
a3bc25
+    if (virQEMUCapsGuestIsNative(caps->host.arch, obj->def->os.arch) &&
a3bc25
+        caps->host.cpu &&
a3bc25
+        obj->def->cpu &&
a3bc25
+        obj->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) {
a3bc25
+        virCPUDefPtr host;
a3bc25
+
a3bc25
+        if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
a3bc25
+            goto error;
a3bc25
+
a3bc25
+        if (virCPUUpdate(obj->def->os.arch, obj->def->cpu, host) < 0) {
a3bc25
+            virCPUDefFree(host);
a3bc25
+            goto error;
a3bc25
+        }
a3bc25
+        virCPUDefFree(host);
a3bc25
+
a3bc25
+        if (qemuProcessUpdateCPU(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
a3bc25
+            goto error;
a3bc25
+    }
a3bc25
+
a3bc25
     if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) < 0)
a3bc25
         goto error;
a3bc25
 
a3bc25
-- 
a3bc25
2.13.2
a3bc25