c313de
From 2d8d4379690e55d8d9a0b194ddef33d073154c7b Mon Sep 17 00:00:00 2001
c313de
Message-Id: <2d8d4379690e55d8d9a0b194ddef33d073154c7b@dist-git>
c313de
From: Jiri Denemark <jdenemar@redhat.com>
c313de
Date: Fri, 21 Jun 2019 09:25:03 +0200
c313de
Subject: [PATCH] qemu_capabilities: Inroduce virQEMUCapsGetCPUModelX86Data
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
The code for transforming qemuMonitorCPUModelInfo data from QEMU into
c313de
virCPUDefPtr consumable by virCPU* APIs was hidden inside
c313de
virQEMUCapsInitCPUModelX86. This patch moves it into a new function to
c313de
make it usable in tests.
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 30e4faac2f3e72aec29be9963d7a5394153e812f)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1686895
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Message-Id: <e91c6c1e8de59a6cc151154f7c2a9eae79249fa5.1561068591.git.jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/qemu/qemu_capabilities.c | 50 ++++++++++++++++++++++++------------
c313de
 src/qemu/qemu_capspriv.h     |  4 +++
c313de
 2 files changed, 38 insertions(+), 16 deletions(-)
c313de
c313de
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c313de
index 5539d168cd..5a7160d02e 100644
c313de
--- a/src/qemu/qemu_capabilities.c
c313de
+++ b/src/qemu/qemu_capabilities.c
c313de
@@ -2812,28 +2812,17 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
c313de
 }
c313de
 
c313de
 
c313de
-/**
c313de
- * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
c313de
- *          1 when the caller should fall back to using virCapsPtr->host.cpu,
c313de
- *         -1 on error.
c313de
- */
c313de
-static int
c313de
-virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
c313de
-                           virDomainVirtType type,
c313de
-                           qemuMonitorCPUModelInfoPtr model,
c313de
-                           virCPUDefPtr cpu,
c313de
-                           bool migratable)
c313de
+virCPUDataPtr
c313de
+virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
c313de
+                              bool migratable)
c313de
 {
c313de
-    virCPUDataPtr data = NULL;
c313de
     unsigned long long sigFamily = 0;
c313de
     unsigned long long sigModel = 0;
c313de
     unsigned long long sigStepping = 0;
c313de
-    int ret = -1;
c313de
+    virCPUDataPtr data = NULL;
c313de
+    virCPUDataPtr ret = NULL;
c313de
     size_t i;
c313de
 
c313de
-    if (!model)
c313de
-        return 1;
c313de
-
c313de
     if (!(data = virCPUDataNew(VIR_ARCH_X86_64)))
c313de
         goto cleanup;
c313de
 
c313de
@@ -2874,6 +2863,35 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
c313de
     if (virCPUx86DataSetSignature(data, sigFamily, sigModel, sigStepping) < 0)
c313de
         goto cleanup;
c313de
 
c313de
+    VIR_STEAL_PTR(ret, data);
c313de
+
c313de
+ cleanup:
c313de
+    virCPUDataFree(data);
c313de
+    return ret;
c313de
+}
c313de
+
c313de
+
c313de
+/**
c313de
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
c313de
+ *          1 when the caller should fall back to using virCapsPtr->host.cpu,
c313de
+ *         -1 on error.
c313de
+ */
c313de
+static int
c313de
+virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
c313de
+                           virDomainVirtType type,
c313de
+                           qemuMonitorCPUModelInfoPtr model,
c313de
+                           virCPUDefPtr cpu,
c313de
+                           bool migratable)
c313de
+{
c313de
+    virCPUDataPtr data = NULL;
c313de
+    int ret = -1;
c313de
+
c313de
+    if (!model)
c313de
+        return 1;
c313de
+
c313de
+    if (!(data = virQEMUCapsGetCPUModelX86Data(model, migratable)))
c313de
+        goto cleanup;
c313de
+
c313de
     if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0)
c313de
         goto cleanup;
c313de
 
c313de
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
c313de
index cb5e0dd9a9..70cdbbc504 100644
c313de
--- a/src/qemu/qemu_capspriv.h
c313de
+++ b/src/qemu/qemu_capspriv.h
c313de
@@ -80,6 +80,10 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
c313de
                            virDomainVirtType type,
c313de
                            qemuMonitorCPUModelInfoPtr modelInfo);
c313de
 
c313de
+virCPUDataPtr
c313de
+virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
c313de
+                              bool migratable);
c313de
+
c313de
 virCPUDefPtr
c313de
 virQEMUCapsProbeHostCPUForEmulator(virArch hostArch,
c313de
                                    virQEMUCapsPtr qemuCaps,
c313de
-- 
c313de
2.22.0
c313de