render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 992af2f6564b899142a2be5f342e0cdbdd13eadc Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <992af2f6564b899142a2be5f342e0cdbdd13eadc@dist-git>
c480ed
From: Jiri Denemark <jdenemar@redhat.com>
c480ed
Date: Fri, 21 Jun 2019 09:25:59 +0200
c480ed
Subject: [PATCH] cpu: Introduce virCPUDataAddFeature
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
This is a generic replacement for the former virCPUx86DataAddFeature,
c480ed
which worked on the generic virCPUDataPtr anyway.
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit df73078c612a70e48aa76e889a7026e2daa47b16)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c480ed
c480ed
Conflicts:
c480ed
	src/cpu/cpu_x86.h
c480ed
            - downstream did not switch to #pragma once
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Message-Id: <4e946f702092fe5eb4c8235dbb98402b30876a5f.1561068591.git.jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/cpu/cpu.c                | 33 +++++++++++++++++++++++++++++++++
c480ed
 src/cpu/cpu.h                |  9 +++++++++
c480ed
 src/cpu/cpu_x86.c            |  3 ++-
c480ed
 src/cpu/cpu_x86.h            |  3 ---
c480ed
 src/libvirt_private.syms     |  2 +-
c480ed
 src/qemu/qemu_capabilities.c |  2 +-
c480ed
 6 files changed, 46 insertions(+), 6 deletions(-)
c480ed
c480ed
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
c480ed
index cc93c49418..a2d143c94a 100644
c480ed
--- a/src/cpu/cpu.c
c480ed
+++ b/src/cpu/cpu.c
c480ed
@@ -1078,3 +1078,36 @@ virCPUValidateFeatures(virArch arch,
c480ed
     else
c480ed
         return 0;
c480ed
 }
c480ed
+
c480ed
+
c480ed
+/**
c480ed
+ * virCPUDataAddFeature:
c480ed
+ *
c480ed
+ * @cpuData: CPU data
c480ed
+ * @name: feature to be added to @cpuData
c480ed
+ *
c480ed
+ * Adds a feature called @name to @cpuData.
c480ed
+ *
c480ed
+ * Returns 0 on success, -1 on error.
c480ed
+ */
c480ed
+int
c480ed
+virCPUDataAddFeature(virCPUDataPtr cpuData,
c480ed
+                     const char *name)
c480ed
+{
c480ed
+    struct cpuArchDriver *driver;
c480ed
+
c480ed
+    VIR_DEBUG("arch=%s, cpuData=%p, name=%s",
c480ed
+              virArchToString(cpuData->arch), cpuData, name);
c480ed
+
c480ed
+    if (!(driver = cpuGetSubDriver(cpuData->arch)))
c480ed
+        return -1;
c480ed
+
c480ed
+    if (!driver->dataAddFeature) {
c480ed
+        virReportError(VIR_ERR_NO_SUPPORT,
c480ed
+                       _("cannot add guest CPU feature for %s architecture"),
c480ed
+                       virArchToString(cpuData->arch));
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return driver->dataAddFeature(cpuData, name);
c480ed
+}
c480ed
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
c480ed
index 81119b6aeb..e5fae31e30 100644
c480ed
--- a/src/cpu/cpu.h
c480ed
+++ b/src/cpu/cpu.h
c480ed
@@ -121,6 +121,10 @@ typedef virCPUDefPtr
c480ed
 typedef int
c480ed
 (*virCPUArchValidateFeatures)(virCPUDefPtr cpu);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCPUArchDataAddFeature)(virCPUDataPtr cpuData,
c480ed
+                            const char *name);
c480ed
+
c480ed
 struct cpuArchDriver {
c480ed
     const char *name;
c480ed
     const virArch *arch;
c480ed
@@ -143,6 +147,7 @@ struct cpuArchDriver {
c480ed
     virCPUArchExpandFeatures expandFeatures;
c480ed
     virCPUArchCopyMigratable copyMigratable;
c480ed
     virCPUArchValidateFeatures validateFeatures;
c480ed
+    virCPUArchDataAddFeature dataAddFeature;
c480ed
 };
c480ed
 
c480ed
 
c480ed
@@ -260,6 +265,10 @@ virCPUValidateFeatures(virArch arch,
c480ed
                        virCPUDefPtr cpu)
c480ed
     ATTRIBUTE_NONNULL(2);
c480ed
 
c480ed
+int
c480ed
+virCPUDataAddFeature(virCPUDataPtr cpuData,
c480ed
+                     const char *name);
c480ed
+
c480ed
 /* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
c480ed
  * have no real-life usage
c480ed
  */
c480ed
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
c480ed
index 3c1bd623db..ead962ae06 100644
c480ed
--- a/src/cpu/cpu_x86.c
c480ed
+++ b/src/cpu/cpu_x86.c
c480ed
@@ -3316,7 +3316,7 @@ virCPUx86DataSetVendor(virCPUDataPtr cpuData,
c480ed
 }
c480ed
 
c480ed
 
c480ed
-int
c480ed
+static int
c480ed
 virCPUx86DataAddFeature(virCPUDataPtr cpuData,
c480ed
                         const char *name)
c480ed
 {
c480ed
@@ -3361,4 +3361,5 @@ struct cpuArchDriver cpuDriverX86 = {
c480ed
     .expandFeatures = virCPUx86ExpandFeatures,
c480ed
     .copyMigratable = virCPUx86CopyMigratable,
c480ed
     .validateFeatures = virCPUx86ValidateFeatures,
c480ed
+    .dataAddFeature = virCPUx86DataAddFeature,
c480ed
 };
c480ed
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
c480ed
index 8b51cef9c1..519024b7c0 100644
c480ed
--- a/src/cpu/cpu_x86.h
c480ed
+++ b/src/cpu/cpu_x86.h
c480ed
@@ -45,7 +45,4 @@ uint32_t virCPUx86DataGetSignature(virCPUDataPtr cpuData,
c480ed
 int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
c480ed
                            const char *vendor);
c480ed
 
c480ed
-int virCPUx86DataAddFeature(virCPUDataPtr cpuData,
c480ed
-                            const char *name);
c480ed
-
c480ed
 #endif /* __VIR_CPU_X86_H__ */
c480ed
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c480ed
index 57508de0c1..a20e0593f0 100644
c480ed
--- a/src/libvirt_private.syms
c480ed
+++ b/src/libvirt_private.syms
c480ed
@@ -1187,6 +1187,7 @@ virCPUCompare;
c480ed
 virCPUCompareXML;
c480ed
 virCPUConvertLegacy;
c480ed
 virCPUCopyMigratable;
c480ed
+virCPUDataAddFeature;
c480ed
 virCPUDataCheckFeature;
c480ed
 virCPUDataFormat;
c480ed
 virCPUDataFree;
c480ed
@@ -1205,7 +1206,6 @@ virCPUValidateFeatures;
c480ed
 
c480ed
 # cpu/cpu_x86.h
c480ed
 virCPUx86DataAdd;
c480ed
-virCPUx86DataAddFeature;
c480ed
 virCPUx86DataGetSignature;
c480ed
 virCPUx86DataSetSignature;
c480ed
 virCPUx86DataSetVendor;
c480ed
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c480ed
index 78be2d35f4..4be0ec305f 100644
c480ed
--- a/src/qemu/qemu_capabilities.c
c480ed
+++ b/src/qemu/qemu_capabilities.c
c480ed
@@ -2916,7 +2916,7 @@ virQEMUCapsGetCPUModelX86Data(virQEMUCapsPtr qemuCaps,
c480ed
                 (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
c480ed
                 continue;
c480ed
 
c480ed
-            if (virCPUx86DataAddFeature(data, name) < 0)
c480ed
+            if (virCPUDataAddFeature(data, name) < 0)
c480ed
                 goto cleanup;
c480ed
 
c480ed
             break;
c480ed
-- 
c480ed
2.22.0
c480ed