From 992af2f6564b899142a2be5f342e0cdbdd13eadc Mon Sep 17 00:00:00 2001 Message-Id: <992af2f6564b899142a2be5f342e0cdbdd13eadc@dist-git> From: Jiri Denemark Date: Fri, 21 Jun 2019 09:25:59 +0200 Subject: [PATCH] cpu: Introduce virCPUDataAddFeature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a generic replacement for the former virCPUx86DataAddFeature, which worked on the generic virCPUDataPtr anyway. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko (cherry picked from commit df73078c612a70e48aa76e889a7026e2daa47b16) https://bugzilla.redhat.com/show_bug.cgi?id=1697627 Conflicts: src/cpu/cpu_x86.h - downstream did not switch to #pragma once Signed-off-by: Jiri Denemark Message-Id: <4e946f702092fe5eb4c8235dbb98402b30876a5f.1561068591.git.jdenemar@redhat.com> Reviewed-by: Ján Tomko --- 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 cc93c49418..a2d143c94a 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1078,3 +1078,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 81119b6aeb..e5fae31e30 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -121,6 +121,10 @@ typedef virCPUDefPtr typedef int (*virCPUArchValidateFeatures)(virCPUDefPtr cpu); +typedef int +(*virCPUArchDataAddFeature)(virCPUDataPtr cpuData, + const char *name); + struct cpuArchDriver { const char *name; const virArch *arch; @@ -143,6 +147,7 @@ struct cpuArchDriver { virCPUArchExpandFeatures expandFeatures; virCPUArchCopyMigratable copyMigratable; virCPUArchValidateFeatures validateFeatures; + virCPUArchDataAddFeature dataAddFeature; }; @@ -260,6 +265,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 3c1bd623db..ead962ae06 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3316,7 +3316,7 @@ virCPUx86DataSetVendor(virCPUDataPtr cpuData, } -int +static int virCPUx86DataAddFeature(virCPUDataPtr cpuData, const char *name) { @@ -3361,4 +3361,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 8b51cef9c1..519024b7c0 100644 --- a/src/cpu/cpu_x86.h +++ b/src/cpu/cpu_x86.h @@ -45,7 +45,4 @@ uint32_t virCPUx86DataGetSignature(virCPUDataPtr cpuData, int virCPUx86DataSetVendor(virCPUDataPtr cpuData, const char *vendor); -int virCPUx86DataAddFeature(virCPUDataPtr cpuData, - const char *name); - #endif /* __VIR_CPU_X86_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 57508de0c1..a20e0593f0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1187,6 +1187,7 @@ virCPUCompare; virCPUCompareXML; virCPUConvertLegacy; virCPUCopyMigratable; +virCPUDataAddFeature; virCPUDataCheckFeature; virCPUDataFormat; virCPUDataFree; @@ -1205,7 +1206,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 78be2d35f4..4be0ec305f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2916,7 +2916,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