diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 6eef5cef0046c64e464853474ec69d0cb01d454a..4624ebaff56ea1607b775228cf520533ca559af0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3362,6 +3362,63 @@ virCPUx86DataAddFeature(virCPUDataPtr cpuData, } +static bool +virCPUx86FeatureIsMSR(const char *name) +{ + virCPUx86FeaturePtr feature; + virCPUx86DataIterator iter; + virCPUx86DataItemPtr item; + virCPUx86MapPtr map; + + if (!(map = virCPUx86GetMap())) + return false; + + if (!(feature = x86FeatureFind(map, name)) && + !(feature = x86FeatureFindInternal(name))) + return false; + + virCPUx86DataIteratorInit(&iter, &feature->data); + while ((item = virCPUx86DataNext(&iter))) { + if (item->type == VIR_CPU_X86_DATA_MSR) + return true; + } + + return false; +} + + +/** + * virCPUx86FeatureFilterSelectMSR: + * + * This is a callback for functions filtering features in virCPUDef. The result + * will contain only MSR features. + * + * Returns true if @name is an MSR feature, false otherwise. + */ +bool +virCPUx86FeatureFilterSelectMSR(const char *name, + void *opaque ATTRIBUTE_UNUSED) +{ + return virCPUx86FeatureIsMSR(name); +} + + +/** + * virCPUx86FeatureFilterDropMSR: + * + * This is a callback for functions filtering features in virCPUDef. The result + * will not contain any MSR feature. + * + * Returns true if @name is not an MSR feature, false otherwise. + */ +bool +virCPUx86FeatureFilterDropMSR(const char *name, + void *opaque ATTRIBUTE_UNUSED) +{ + return !virCPUx86FeatureIsMSR(name); +} + + struct cpuArchDriver cpuDriverX86 = { .name = "x86", .arch = archs, diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h index 28ae46647a0f2d294ba417b85d62f664ad7fa12e..3ea38d170166a9750fa05b62af5da0032faa2cf1 100644 --- a/src/cpu/cpu_x86.h +++ b/src/cpu/cpu_x86.h @@ -40,3 +40,9 @@ uint32_t virCPUx86DataGetSignature(virCPUDataPtr cpuData, int virCPUx86DataSetVendor(virCPUDataPtr cpuData, const char *vendor); + +bool virCPUx86FeatureFilterSelectMSR(const char *name, + void *opaque); + +bool virCPUx86FeatureFilterDropMSR(const char *name, + void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 90a6d10666cf4e8f2d2c77d75f1f1a6d13c79efa..c06fa67d6aae28d252b7d36864634085532a4362 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1268,7 +1268,8 @@ virCPUx86DataAdd; virCPUx86DataGetSignature; virCPUx86DataSetSignature; virCPUx86DataSetVendor; - +virCPUx86FeatureFilterDropMSR; +virCPUx86FeatureFilterSelectMSR; # datatypes.h virConnectClass;