This is a generic replacement for the former virCPUx86DataAddFeature,
which worked on the generic virCPUDataPtr anyway.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/cpu/cpu.c | 33 +++++++++++++++++++++++++++++++++
src/cpu/cpu.h | 9 +++++++++
src/cpu/cpu_x86.c | 3 ++-
src/cpu/cpu_x86.h | 3 ---
src/libvirt_private.syms | 2 +-
src/qemu/qemu_capabilities.c | 2 +-
6 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index a223ff06e8..b89462cc0c 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -1075,3 +1075,36 @@ virCPUValidateFeatures(virArch arch,
else
return 0;
}
+
+
+/**
+ * virCPUDataAddFeature:
+ *
+ * @cpuData: CPU data
+ * @name: feature to be added to @cpuData
+ *
+ * Adds a feature called @name to @cpuData.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int
+virCPUDataAddFeature(virCPUDataPtr cpuData,
+ const char *name)
+{
+ struct cpuArchDriver *driver;
+
+ VIR_DEBUG("arch=%s, cpuData=%p, name=%s",
+ virArchToString(cpuData->arch), cpuData, name);
+
+ if (!(driver = cpuGetSubDriver(cpuData->arch)))
+ return -1;
+
+ if (!driver->dataAddFeature) {
+ virReportError(VIR_ERR_NO_SUPPORT,
+ _("cannot add guest CPU feature for %s architecture"),
+ virArchToString(cpuData->arch));
+ return -1;
+ }
+
+ return driver->dataAddFeature(cpuData, name);
+}
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 7cc9e7d9db..13909bb7a4 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -117,6 +117,10 @@ typedef virCPUDefPtr
typedef int
(*virCPUArchValidateFeatures)(virCPUDefPtr cpu);
+typedef int
+(*virCPUArchDataAddFeature)(virCPUDataPtr cpuData,
+ const char *name);
+
struct cpuArchDriver {
const char *name;
const virArch *arch;
@@ -139,6 +143,7 @@ struct cpuArchDriver {
virCPUArchExpandFeatures expandFeatures;
virCPUArchCopyMigratable copyMigratable;
virCPUArchValidateFeatures validateFeatures;
+ virCPUArchDataAddFeature dataAddFeature;
};
@@ -256,6 +261,10 @@ virCPUValidateFeatures(virArch arch,
virCPUDefPtr cpu)
ATTRIBUTE_NONNULL(2);
+int
+virCPUDataAddFeature(virCPUDataPtr cpuData,
+ const char *name);
+
/* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
* have no real-life usage
*/
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 689b6cdaf5..b6a94d483a 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3326,7 +3326,7 @@ virCPUx86DataSetVendor(virCPUDataPtr cpuData,
}
-int
+static int
virCPUx86DataAddFeature(virCPUDataPtr cpuData,
const char *name)
{
@@ -3371,4 +3371,5 @@ struct cpuArchDriver cpuDriverX86 = {
.expandFeatures = virCPUx86ExpandFeatures,
.copyMigratable = virCPUx86CopyMigratable,
.validateFeatures = virCPUx86ValidateFeatures,
+ .dataAddFeature = virCPUx86DataAddFeature,
};
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 29037d4afa..28ae46647a 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -40,6 +40,3 @@ uint32_t virCPUx86DataGetSignature(virCPUDataPtr cpuData,
int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
const char *vendor);
-
-int virCPUx86DataAddFeature(virCPUDataPtr cpuData,
- const char *name);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 228cd929b4..ab2e4bc6fe 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1245,6 +1245,7 @@ virCPUCompare;
virCPUCompareXML;
virCPUConvertLegacy;
virCPUCopyMigratable;
+virCPUDataAddFeature;
virCPUDataCheckFeature;
virCPUDataFormat;
virCPUDataFree;
@@ -1263,7 +1264,6 @@ virCPUValidateFeatures;
# cpu/cpu_x86.h
virCPUx86DataAdd;
-virCPUx86DataAddFeature;
virCPUx86DataGetSignature;
virCPUx86DataSetSignature;
virCPUx86DataSetVendor;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9ef1eabc95..4134f319ac 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3009,7 +3009,7 @@ virQEMUCapsGetCPUModelX86Data(virQEMUCapsPtr qemuCaps,
(migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
continue;
- if (virCPUx86DataAddFeature(data, name) < 0)
+ if (virCPUDataAddFeature(data, name) < 0)
goto cleanup;
break;
--
2.22.0