[libvirt PATCH 2/9] libvirt: introduce virConnectGetHypervisorCPUModelNames public API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create a function to query the hypervisor for its list of known CPU model
names. This is different from virConnectGetCPUModelNames, as this new
function will determine the list of CPU models (and alias names) at
runtime.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 include/libvirt/libvirt-host.h |  6 ++++
 src/driver-hypervisor.h        |  8 +++++
 src/libvirt-host.c             | 55 ++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms        |  1 +
 4 files changed, 70 insertions(+)

diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 3112f2b676..5aaa001adb 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -962,6 +962,12 @@ int virConnectGetCPUModelNames(virConnectPtr conn,
                                char ***models,
                                unsigned int flags);
 
+int virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+                                         const char *arch,
+                                         char ***names,
+                                         char ***aliases,
+                                         unsigned int flags);
+
 /**
  * virConnectBaselineCPUFlags:
  *
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 016d5cec7c..c81e5d4c75 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -732,6 +732,13 @@ typedef int
                                  char ***models,
                                  unsigned int flags);
 
+typedef int
+(*virDrvConnectGetHypervisorCPUModelNames)(virConnectPtr conn,
+                                           const char *archName,
+                                           char ***names,
+                                           char ***aliases,
+                                           unsigned int flags);
+
 typedef int
 (*virDrvDomainGetJobInfo)(virDomainPtr domain,
                           virDomainJobInfoPtr info);
@@ -1712,4 +1719,5 @@ struct _virHypervisorDriver {
     virDrvDomainAuthorizedSSHKeysSet domainAuthorizedSSHKeysSet;
     virDrvDomainGetMessages domainGetMessages;
     virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc;
+    virDrvConnectGetHypervisorCPUModelNames connectGetHypervisorCPUModelNames;
 };
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index 2ee6370bce..6e734628c1 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -1234,6 +1234,61 @@ virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
 }
 
 
+/**
+ * virConnectGetHypervisorCPUModelNames:
+ *
+ * @conn: virConnect connection
+ * @arch: Architecture
+ * @names: Pointer to a variable to store the NULL-terminated array of the CPU
+ *         models supported by the hypervisor for the specified architecture.
+ *         Each element and the array itself must be freed by the caller.
+ * @aliases: Pointer to a variable to store the NULL-terminated array of alias
+ *           names for CPU model names. Each element and the array itself must
+ *           be freed by the caller.
+ * @flags: extra flags; not used yet, so callers should always pass 0.
+ *
+ * Get the list of CPU models supported by the hypervisor for a specific
+ * architecture.
+ *
+ * If @aliases[x] is not an empty string, @names[x] is an alias for that CPU
+ * model.
+ *
+ * Returns -1 on error, number of elements in @models on success.
+ *
+ * Since: 8.5.0
+ */
+int
+virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+                                     const char *arch,
+                                     char ***names,
+                                     char ***aliases,
+                                     unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, arch=%s, flags=0x%x", conn, NULLSTR(arch), flags);
+    virResetLastError();
+
+    virCheckConnectReturn(conn, -1);
+    virCheckNonNullArgGoto(arch, error);
+
+    if (conn->driver->connectGetHypervisorCPUModelNames) {
+        int ret;
+
+        ret = conn->driver->connectGetHypervisorCPUModelNames(conn, arch, names,
+                                                              aliases, flags);
+        if (ret < 0)
+            goto error;
+
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(conn);
+    return -1;
+}
+
+
 /**
  * virConnectBaselineCPU:
  *
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 297a2c436a..c6a8e898ae 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -924,6 +924,7 @@ LIBVIRT_8.4.0 {
 
 LIBVIRT_8.5.0 {
     global:
+        virConnectGetHypervisorCPUModelNames;
         virDomainAbortJobFlags;
 } LIBVIRT_8.4.0;
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux