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: Collin Walling <walling(a)linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy(a)linux.ibm.com>
---
include/libvirt/libvirt-host.h | 6 ++++
src/driver-hypervisor.h | 9 ++++++
src/libvirt-host.c | 54 ++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 5 ++++
4 files changed, 74 insertions(+)
diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 3112f2b676..a70a4d9971 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -961,6 +961,12 @@ int virConnectGetCPUModelNames(virConnectPtr conn,
const char *arch,
char ***models,
unsigned int flags);
+char *virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags);
/**
* virConnectBaselineCPUFlags:
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 5219344b72..725c1db752 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -732,6 +732,14 @@ typedef int
char ***models,
unsigned int flags);
+typedef char *
+(*virDrvConnectGetHypervisorCPUModelNames)(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags);
+
typedef int
(*virDrvDomainGetJobInfo)(virDomainPtr domain,
virDomainJobInfoPtr info);
@@ -1701,6 +1709,7 @@ struct _virHypervisorDriver {
virDrvDomainSetLifecycleAction domainSetLifecycleAction;
virDrvConnectCompareHypervisorCPU connectCompareHypervisorCPU;
virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU;
+ virDrvConnectGetHypervisorCPUModelNames connectGetHypervisorCPUModelNames;
virDrvNodeGetSEVInfo nodeGetSEVInfo;
virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo;
virDrvDomainSetLaunchSecurityState domainSetLaunchSecurityState;
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index a2ba347d54..407d19ffa9 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -1379,6 +1379,60 @@ virConnectBaselineHypervisorCPU(virConnectPtr conn,
}
+/**
+ * virConnectGetHypervisorCPUModelNames:
+ *
+ * @conn: pointer to the hypervisor connection
+ * @emulator: path to the emulator binary
+ * @arch: CPU architecture
+ * @machine: machine type
+ * @virttype: virtualization type
+ * @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 NULL on error, or a string of CPU models on success.
+ *
+ * Since: 9.2.0
+ */
+char *
+virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, emulator=%s, arch=%s, machine=%s, virttype=%s",
+ conn, NULLSTR(emulator), NULLSTR(arch),
+ NULLSTR(machine), NULLSTR(virttype));
+
+ virResetLastError();
+ virCheckConnectReturn(conn, NULL);
+
+ if (conn->driver->connectGetHypervisorCPUModelNames) {
+ char *result;
+
+ result = conn->driver->connectGetHypervisorCPUModelNames(conn, emulator,
arch,
+ machine, virttype,
flags);
+ if (!result)
+ goto error;
+
+ return result;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return NULL;
+}
+
+
/**
* virConnectSetKeepAlive:
* @conn: pointer to a hypervisor connection
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 80742f268e..df8d991cce 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -932,4 +932,9 @@ LIBVIRT_9.0.0 {
virDomainFDAssociate;
} LIBVIRT_8.5.0;
+LIBVIRT_9.2.0 {
+ global:
+ virConnectGetHypervisorCPUModelNames;
+} LIBVIRT_9.0.0;
+
# .... define new API here using predicted next version number ....
--
2.39.0