Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- new patch
src/cpu/cpu.c | 25 +++++++++++++++++++++++++
src/cpu/cpu.h | 8 ++++++++
src/cpu/cpu_x86.c | 19 +++++++++++++++++++
src/libvirt_private.syms | 1 +
4 files changed, 53 insertions(+)
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 2b0d641e78..ef515744ba 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -1345,6 +1345,31 @@ virCPUGetCheckMode(virArch arch,
}
+/** virCPUGetCanonicalModel:
+ *
+ * @arch: CPU architecture
+ * @model: CPU model to be checked
+ *
+ * Returns @model's canonical name if @model is an alias or NULL otherwise.
+ */
+const char *
+virCPUGetCanonicalModel(virArch arch,
+ const char *model)
+{
+ struct cpuArchDriver *driver;
+
+ VIR_DEBUG("arch=%s model=%s", virArchToString(arch), model);
+
+ if (!(driver = cpuGetSubDriver(arch)))
+ return NULL;
+
+ if (!driver->getCanonicalModel)
+ return NULL;
+
+ return driver->getCanonicalModel(model);
+}
+
+
/**
* virCPUArchIsSupported:
*
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index ff68c5da2d..fc6a812eaa 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -140,6 +140,9 @@ typedef int
(*virCPUArchGetCheckMode)(const char *modelName,
bool *compat);
+typedef const char *
+(*virCPUArchGetCanonicalModel)(const char *model);
+
struct cpuArchDriver {
const char *name;
const virArch *arch;
@@ -168,6 +171,7 @@ struct cpuArchDriver {
virCPUArchDataIsIdentical dataIsIdentical;
virCPUArchDataGetHost dataGetHost;
virCPUArchGetCheckMode getCheckMode;
+ virCPUArchGetCanonicalModel getCanonicalModel;
};
@@ -324,6 +328,10 @@ virCPUGetCheckMode(virArch arch,
const virCPUDef *cpu,
bool *compat);
+const char *
+virCPUGetCanonicalModel(virArch arch,
+ const char *model);
+
bool
virCPUArchIsSupported(virArch arch);
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index ce3506be55..13695802da 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3697,6 +3697,24 @@ virCPUx86GetCheckMode(const char *modelName,
}
+static const char *
+virCPUx86GetCanonicalModel(const char *modelName)
+{
+ virCPUx86Map *map;
+ virCPUx86Model *model;
+
+ if (!(map = virCPUx86GetMap()))
+ return NULL;
+
+ model = x86ModelFind(map, modelName);
+
+ if (!model || !model->canonical)
+ return NULL;
+
+ return model->canonical->name;
+}
+
+
struct cpuArchDriver cpuDriverX86 = {
.name = "x86",
.arch = archs,
@@ -3730,4 +3748,5 @@ struct cpuArchDriver cpuDriverX86 = {
.dataGetHost = virCPUx86DataGetHost,
#endif
.getCheckMode = virCPUx86GetCheckMode,
+ .getCanonicalModel = virCPUx86GetCanonicalModel,
};
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5b9b44ef96..2a9d3230e1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1543,6 +1543,7 @@ virCPUDataNewCopy;
virCPUDataParse;
virCPUDataParseNode;
virCPUExpandFeatures;
+virCPUGetCanonicalModel;
virCPUGetCheckMode;
virCPUGetHost;
virCPUGetHostIsSupported;
--
2.47.0