render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a3bc25
From e5840b68e6376a514c6c5de1897ac87dc57e7a58 Mon Sep 17 00:00:00 2001
a3bc25
Message-Id: <e5840b68e6376a514c6c5de1897ac87dc57e7a58@dist-git>
a3bc25
From: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Date: Tue, 11 Jul 2017 13:51:17 +0200
a3bc25
Subject: [PATCH] qemu: Add qemuProcessUpdateLiveGuestCPU
a3bc25
a3bc25
Separated from qemuProcessUpdateAndVerifyCPU to handle updating of an
a3bc25
active guest CPU definition according to live data from QEMU.
a3bc25
a3bc25
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
a3bc25
(cherry picked from commit eef9f83b691e0713e4fc480b497b85517aba6ca4)
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 | 72 ++++++++++++++++++++++++++++++-------------------
a3bc25
 1 file changed, 44 insertions(+), 28 deletions(-)
a3bc25
a3bc25
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
a3bc25
index 1e7724e784..9df463094e 100644
a3bc25
--- a/src/qemu/qemu_process.c
a3bc25
+++ b/src/qemu/qemu_process.c
a3bc25
@@ -3971,17 +3971,55 @@ qemuProcessVerifyCPU(virDomainObjPtr vm,
a3bc25
 
a3bc25
 
a3bc25
 static int
a3bc25
+qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm,
a3bc25
+                              virCPUDataPtr enabled,
a3bc25
+                              virCPUDataPtr disabled)
a3bc25
+{
a3bc25
+    virDomainDefPtr def = vm->def;
a3bc25
+    qemuDomainObjPrivatePtr priv = vm->privateData;
a3bc25
+    virCPUDefPtr orig = NULL;
a3bc25
+    int rc;
a3bc25
+    int ret = -1;
a3bc25
+
a3bc25
+    if (!enabled)
a3bc25
+        return 0;
a3bc25
+
a3bc25
+    if (!def->cpu ||
a3bc25
+        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
a3bc25
+         !def->cpu->model))
a3bc25
+        return 0;
a3bc25
+
a3bc25
+    if (!(orig = virCPUDefCopy(def->cpu)))
a3bc25
+        goto cleanup;
a3bc25
+
a3bc25
+    if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled)) < 0) {
a3bc25
+        goto cleanup;
a3bc25
+    } else if (rc == 0) {
a3bc25
+        /* Store the original CPU in priv if QEMU changed it and we didn't
a3bc25
+         * get the original CPU via migration, restore, or snapshot revert.
a3bc25
+         */
a3bc25
+        if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false))
a3bc25
+            VIR_STEAL_PTR(priv->origCPU, orig);
a3bc25
+
a3bc25
+        def->cpu->check = VIR_CPU_CHECK_FULL;
a3bc25
+    }
a3bc25
+
a3bc25
+    ret = 0;
a3bc25
+
a3bc25
+ cleanup:
a3bc25
+    virCPUDefFree(orig);
a3bc25
+    return ret;
a3bc25
+}
a3bc25
+
a3bc25
+
a3bc25
+static int
a3bc25
 qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
a3bc25
                               virDomainObjPtr vm,
a3bc25
                               qemuDomainAsyncJob asyncJob)
a3bc25
 {
a3bc25
-    virDomainDefPtr def = vm->def;
a3bc25
     virCPUDataPtr cpu = NULL;
a3bc25
     virCPUDataPtr disabled = NULL;
a3bc25
-    qemuDomainObjPrivatePtr priv = vm->privateData;
a3bc25
-    int rc;
a3bc25
     int ret = -1;
a3bc25
-    virCPUDefPtr orig = NULL;
a3bc25
 
a3bc25
     if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
a3bc25
         goto cleanup;
a3bc25
@@ -3989,36 +4027,14 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
a3bc25
     if (qemuProcessVerifyCPU(vm, cpu) < 0)
a3bc25
         goto cleanup;
a3bc25
 
a3bc25
-    if (cpu) {
a3bc25
-        if (!def->cpu ||
a3bc25
-            (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
a3bc25
-             !def->cpu->model)) {
a3bc25
-            ret = 0;
a3bc25
-            goto cleanup;
a3bc25
-        }
a3bc25
-
a3bc25
-        if (!(orig = virCPUDefCopy(def->cpu)))
a3bc25
-            goto cleanup;
a3bc25
-
a3bc25
-        if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled)) < 0) {
a3bc25
-            goto cleanup;
a3bc25
-        } else if (rc == 0) {
a3bc25
-            /* Store the original CPU in priv if QEMU changed it and we didn't
a3bc25
-             * get the original CPU via migration, restore, or snapshot revert.
a3bc25
-             */
a3bc25
-            if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false))
a3bc25
-                VIR_STEAL_PTR(priv->origCPU, orig);
a3bc25
-
a3bc25
-            def->cpu->check = VIR_CPU_CHECK_FULL;
a3bc25
-        }
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
-    virCPUDefFree(orig);
a3bc25
     return ret;
a3bc25
 }
a3bc25
 
a3bc25
-- 
a3bc25
2.13.2
a3bc25