Signed-off-by: Giuseppe Scrivano <gscrivan(a)redhat.com>
---
src/cpu/cpu.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
src/cpu/cpu.h | 3 +++
src/libvirt_private.syms | 1 +
3 files changed, 60 insertions(+)
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 50c2de3..7011b3d 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -27,11 +27,13 @@
#include "viralloc.h"
#include "virxml.h"
#include "cpu.h"
+#include "cpu_map.h"
#include "cpu_x86.h"
#include "cpu_powerpc.h"
#include "cpu_s390.h"
#include "cpu_arm.h"
#include "cpu_generic.h"
+#include "util/virstring.h"
#define NR_DRIVERS ARRAY_CARDINALITY(drivers)
@@ -456,3 +458,57 @@ cpuModelIsAllowed(const char *model,
}
return false;
}
+
+struct cpuGetModelsData
+{
+ char **data;
+ size_t len; /* It includes the last element of DATA, which is NULL. */
+};
+
+static int
+cpuGetArchModelsCb(enum cpuMapElement element,
+ xmlXPathContextPtr ctxt,
+ void *cbdata)
+{
+ char *name;
+ struct cpuGetModelsData *data = cbdata;
+ if (element != CPU_MAP_ELEMENT_MODEL)
+ return 0;
+
+ name = virXPathString("string(@name)", ctxt);
+ if (name == NULL)
+ return -1;
+
+ return VIR_INSERT_ELEMENT(data->data, data->len - 1, data->len, name);
+}
+
+
+static int
+cpuGetArchModels(const char *arch, struct cpuGetModelsData *data)
+{
+ return cpuMapLoad(arch, cpuGetArchModelsCb, data);
+}
+
+
+int
+cpuGetModels(const char *arch, char ***models)
+{
+ struct cpuGetModelsData data;
+
+ *models = data.data = NULL;
+ data.len = 1;
+
+ if (VIR_ALLOC_N(data.data, data.len) < 0)
+ goto error;
+
+ if (cpuGetArchModels(arch, &data) < 0)
+ goto error;
+
+ *models = data.data;
+
+ return data.len - 1;
+
+error:
+ virStringFreeList(data.data);
+ return -1;
+}
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 69f6fae..ebbc7c1 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -175,4 +175,7 @@ cpuModelIsAllowed(const char *model,
const char **models,
unsigned int nmodels);
+extern int
+cpuGetModels(const char *arch, char ***models);
+
#endif /* __VIR_CPU_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 35f0f1b..b456c2d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -719,6 +719,7 @@ cpuCompareXML;
cpuDataFree;
cpuDecode;
cpuEncode;
+cpuGetModels;
cpuGuestData;
cpuHasFeature;
cpuMapOverride;
--
1.8.3.1