0f4c8a
From 24d641eb1f8cf8b90e1276426c5e7889b7324807 Mon Sep 17 00:00:00 2001
0f4c8a
Message-Id: <24d641eb1f8cf8b90e1276426c5e7889b7324807@dist-git>
0f4c8a
From: Jiri Denemark <jdenemar@redhat.com>
0f4c8a
Date: Fri, 6 Oct 2017 12:57:15 +0200
0f4c8a
Subject: [PATCH] qemu: Separate CPU updating code from qemuProcessReconnect
0f4c8a
0f4c8a
The new function is called qemuProcessRefreshCPU.
0f4c8a
0f4c8a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
0f4c8a
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
0f4c8a
(cherry picked from commit 4b87b3675ffd7794542de70da4391f3787ed76a2)
0f4c8a
0f4c8a
https://bugzilla.redhat.com/show_bug.cgi?id=1508549
0f4c8a
0f4c8a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
0f4c8a
---
0f4c8a
 src/qemu/qemu_process.c | 68 ++++++++++++++++++++++++++++++++-----------------
0f4c8a
 1 file changed, 45 insertions(+), 23 deletions(-)
0f4c8a
0f4c8a
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
0f4c8a
index 8fe9ef36d7..4a8c4421a3 100644
0f4c8a
--- a/src/qemu/qemu_process.c
0f4c8a
+++ b/src/qemu/qemu_process.c
0f4c8a
@@ -6662,6 +6662,49 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
0f4c8a
 }
0f4c8a
 
0f4c8a
 
0f4c8a
+static int
0f4c8a
+qemuProcessRefreshCPU(virQEMUDriverPtr driver,
0f4c8a
+                      virDomainObjPtr vm)
0f4c8a
+{
0f4c8a
+    virCapsPtr caps = virQEMUDriverGetCapabilities(driver, false);
0f4c8a
+    virCPUDefPtr host = NULL;
0f4c8a
+    int ret = -1;
0f4c8a
+
0f4c8a
+    if (!caps)
0f4c8a
+        return -1;
0f4c8a
+
0f4c8a
+    if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) ||
0f4c8a
+        !caps->host.cpu ||
0f4c8a
+        !vm->def->cpu) {
0f4c8a
+        ret = 0;
0f4c8a
+        goto cleanup;
0f4c8a
+    }
0f4c8a
+
0f4c8a
+    /* If the domain with a host-model CPU was started by an old libvirt
0f4c8a
+     * (< 2.3) which didn't replace the CPU with a custom one, let's do it now
0f4c8a
+     * since the rest of our code does not really expect a host-model CPU in a
0f4c8a
+     * running domain.
0f4c8a
+     */
0f4c8a
+    if (vm->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) {
0f4c8a
+        if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
0f4c8a
+            goto cleanup;
0f4c8a
+
0f4c8a
+        if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, host) < 0)
0f4c8a
+            goto cleanup;
0f4c8a
+
0f4c8a
+        if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
0f4c8a
+            goto cleanup;
0f4c8a
+    }
0f4c8a
+
0f4c8a
+    ret = 0;
0f4c8a
+
0f4c8a
+ cleanup:
0f4c8a
+    virCPUDefFree(host);
0f4c8a
+    virObjectUnref(caps);
0f4c8a
+    return ret;
0f4c8a
+}
0f4c8a
+
0f4c8a
+
0f4c8a
 struct qemuProcessReconnectData {
0f4c8a
     virConnectPtr conn;
0f4c8a
     virQEMUDriverPtr driver;
0f4c8a
@@ -6820,29 +6863,8 @@ qemuProcessReconnect(void *opaque)
0f4c8a
     ignore_value(qemuSecurityCheckAllLabel(driver->securityManager,
0f4c8a
                                            obj->def));
0f4c8a
 
0f4c8a
-    /* If the domain with a host-model CPU was started by an old libvirt
0f4c8a
-     * (< 2.3) which didn't replace the CPU with a custom one, let's do it now
0f4c8a
-     * since the rest of our code does not really expect a host-model CPU in a
0f4c8a
-     * running domain.
0f4c8a
-     */
0f4c8a
-    if (virQEMUCapsGuestIsNative(caps->host.arch, obj->def->os.arch) &&
0f4c8a
-        caps->host.cpu &&
0f4c8a
-        obj->def->cpu &&
0f4c8a
-        obj->def->cpu->mode == VIR_CPU_MODE_HOST_MODEL) {
0f4c8a
-        virCPUDefPtr host;
0f4c8a
-
0f4c8a
-        if (!(host = virCPUCopyMigratable(caps->host.cpu->arch, caps->host.cpu)))
0f4c8a
-            goto error;
0f4c8a
-
0f4c8a
-        if (virCPUUpdate(obj->def->os.arch, obj->def->cpu, host) < 0) {
0f4c8a
-            virCPUDefFree(host);
0f4c8a
-            goto error;
0f4c8a
-        }
0f4c8a
-        virCPUDefFree(host);
0f4c8a
-
0f4c8a
-        if (qemuProcessUpdateCPU(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
0f4c8a
-            goto error;
0f4c8a
-    }
0f4c8a
+    if (qemuProcessRefreshCPU(driver, obj) < 0)
0f4c8a
+        goto error;
0f4c8a
 
0f4c8a
     if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) < 0)
0f4c8a
         goto error;
0f4c8a
-- 
0f4c8a
2.15.0
0f4c8a