a3bc25
From 57a9f46878f57d1602a030cfd8484c8566201c40 Mon Sep 17 00:00:00 2001
a3bc25
Message-Id: <57a9f46878f57d1602a030cfd8484c8566201c40@dist-git>
a3bc25
From: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Date: Tue, 11 Jul 2017 13:18:45 +0200
a3bc25
Subject: [PATCH] qemu: Add qemuProcessFetchGuestCPU
a3bc25
a3bc25
Separated from qemuProcessUpdateLiveGuestCPU. Its purpose is to fetch
a3bc25
guest CPU data from a running QEMU process. The data can later be used
a3bc25
to verify and update the active guest CPU definition.
a3bc25
a3bc25
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a3bc25
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
a3bc25
(cherry picked from commit 40d246a22b46f1691d09cbce5904c79d712d8c16)
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 | 58 +++++++++++++++++++++++++++++++++++++------------
a3bc25
 1 file changed, 44 insertions(+), 14 deletions(-)
a3bc25
a3bc25
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
a3bc25
index 4d7c8d8e40..d3fa8ef41e 100644
a3bc25
--- a/src/qemu/qemu_process.c
a3bc25
+++ b/src/qemu/qemu_process.c
a3bc25
@@ -3905,6 +3905,47 @@ qemuProcessVerifyCPUFeatures(virDomainDefPtr def,
a3bc25
 
a3bc25
 
a3bc25
 static int
a3bc25
+qemuProcessFetchGuestCPU(virQEMUDriverPtr driver,
a3bc25
+                         virDomainObjPtr vm,
a3bc25
+                         qemuDomainAsyncJob asyncJob,
a3bc25
+                         virCPUDataPtr *enabled,
a3bc25
+                         virCPUDataPtr *disabled)
a3bc25
+{
a3bc25
+    qemuDomainObjPrivatePtr priv = vm->privateData;
a3bc25
+    virCPUDataPtr dataEnabled = NULL;
a3bc25
+    virCPUDataPtr dataDisabled = NULL;
a3bc25
+    int rc;
a3bc25
+
a3bc25
+    *enabled = NULL;
a3bc25
+    *disabled = NULL;
a3bc25
+
a3bc25
+    if (!ARCH_IS_X86(vm->def->os.arch))
a3bc25
+        return 0;
a3bc25
+
a3bc25
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
a3bc25
+        goto error;
a3bc25
+
a3bc25
+    rc = qemuMonitorGetGuestCPU(priv->mon, vm->def->os.arch,
a3bc25
+                                &dataEnabled, &dataDisabled);
a3bc25
+
a3bc25
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
a3bc25
+        goto error;
a3bc25
+
a3bc25
+    if (rc == -1)
a3bc25
+        goto error;
a3bc25
+
a3bc25
+    *enabled = dataEnabled;
a3bc25
+    *disabled = dataDisabled;
a3bc25
+    return 0;
a3bc25
+
a3bc25
+ error:
a3bc25
+    virCPUDataFree(dataEnabled);
a3bc25
+    virCPUDataFree(dataDisabled);
a3bc25
+    return -1;
a3bc25
+}
a3bc25
+
a3bc25
+
a3bc25
+static int
a3bc25
 qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
a3bc25
                               virDomainObjPtr vm,
a3bc25
                               qemuDomainAsyncJob asyncJob)
a3bc25
@@ -3917,21 +3958,10 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
a3bc25
     int ret = -1;
a3bc25
     virCPUDefPtr orig = NULL;
a3bc25
 
a3bc25
-    if (ARCH_IS_X86(def->os.arch)) {
a3bc25
-        if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
a3bc25
-            goto cleanup;
a3bc25
-
a3bc25
-        rc = qemuMonitorGetGuestCPU(priv->mon, def->os.arch, &cpu, &disabled);
a3bc25
-
a3bc25
-        if (qemuDomainObjExitMonitor(driver, vm) < 0)
a3bc25
-            goto cleanup;
a3bc25
-
a3bc25
-        if (rc < 0) {
a3bc25
-            if (rc == -2)
a3bc25
-                ret = 0;
a3bc25
-            goto cleanup;
a3bc25
-        }
a3bc25
+    if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
a3bc25
+        goto cleanup;
a3bc25
 
a3bc25
+    if (cpu) {
a3bc25
         if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 ||
a3bc25
             qemuProcessVerifyHypervFeatures(def, cpu) < 0)
a3bc25
             goto cleanup;
a3bc25
-- 
a3bc25
2.13.2
a3bc25