From: David Judkovics <djudkovi@linux.ibm.com>
The new API collects a list of CPU model names supported by the
specified hypervisor. This is a more useful version of
virConnectGetCPUNames, which does not consider any hypervisor
capabilities when querying model names.
Signed-off-by: David Judkovics <djudkovi@linux.ibm.com>
Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
---
include/libvirt/libvirt-host.h | 7 ++++
src/driver-hypervisor.h | 10 ++++++
src/libvirt-host.c | 65 ++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 5 +++
4 files changed, 87 insertions(+)
diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 3112f2b676..67f57cdd16 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -961,6 +961,13 @@ int virConnectGetCPUModelNames(virConnectPtr conn,
const char *arch,
char ***models,
unsigned int flags);
+int virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ char ***models,
+ unsigned int flags);
/**
* virConnectBaselineCPUFlags:
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 4ce8da078d..ed42e3553d 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1453,6 +1453,15 @@ typedef int
unsigned int type,
unsigned int flags);
+typedef int
+(*virDrvConnectGetHypervisorCPUModelNames)(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ char ***models,
+ unsigned int flags);
+
typedef struct _virHypervisorDriver virHypervisorDriver;
/**
@@ -1726,4 +1735,5 @@ struct _virHypervisorDriver {
virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc;
virDrvDomainFDAssociate domainFDAssociate;
virDrvDomainGraphicsReload domainGraphicsReload;
+ virDrvConnectGetHypervisorCPUModelNames connectGetHypervisorCPUModelNames;
};
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index b3a6421a7f..ba845a7126 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -1222,6 +1222,71 @@ virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
}
+/**
+ * virConnectGetHypervisorCPUModelNames:
+ *
+ * @conn: pointer to the hypervisor connection
+ * @emulator: path to the emulator binary
+ * @arch: CPU architecture
+ * @machine: machine type
+ * @virttype: virtualization type
+ * @models: Pointer to a variable to store the NULL-terminated array of the
+ * CPU models supported by the hypervisor. Each element
+ * and the array itself must be freed by the caller with free. Pass
+ * NULL if only the list length is needed.
+ * @flags: extra flags; not used yet, so callers should always pass 0.
+ *
+ * Get the list of CPU models recognized by the hypervisor for a specific
+ * architecture. Note that even if the hypervisor reports a particular CPU
+ * model, hardware limitations may impose restrictions on which CPU models
+ * may be supported on the host (e.g. on s390 the hypervisor may report
+ * model gen15a, but this model will not run on an older machine such as z14).
+ *
+ * Returns -1 on error, number of elements in @models on success.
+ *
+ * Since: 11.1.0
+ */
+int
+virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ char ***models,
+ unsigned int flags)
+{
+
+ VIR_DEBUG("conn=%p, emulator=%s, arch=%s, "
+ "machine=%s, virttype=%s,flags=0x%x",
+ conn, NULLSTR(emulator), NULLSTR(arch),
+ NULLSTR(machine), NULLSTR(virttype), flags);
+
+ virResetLastError();
+ virCheckConnectReturn(conn, -1);
+
+ if (conn->driver->connectGetHypervisorCPUModelNames) {
+ int nmodels;
+ nmodels = conn->driver->connectGetHypervisorCPUModelNames(conn,
+ emulator,
+ arch,
+ machine,
+ virttype,
+ models,
+ flags);
+ if (nmodels < 0) {
+ goto error;
+ }
+
+ return nmodels;
+ }
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return -1;
+}
+
+
/**
* virConnectBaselineCPU:
*
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 7a3492d9d7..88f33427cc 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -948,4 +948,9 @@ LIBVIRT_10.2.0 {
virDomainGraphicsReload;
} LIBVIRT_10.1.0;
+LIBVIRT_11.1.0 {
+ global:
+ virConnectGetHypervisorCPUModelNames;
+} LIBVIRT_10.2.0;
+
# .... define new API here using predicted next version number ....
--
2.47.0
© 2016 - 2025 Red Hat, Inc.