[libvirt PATCH 4/9] qemu: implement virConnectGetHypervisorCPUModelNames API

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3b5c3db67c..538a35d327 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17311,6 +17311,57 @@ qemuConnectGetCPUModelNames(virConnectPtr conn,
     return virCPUGetModels(arch, models);
 }
 
+static int
+qemuConnectGetHypervisorCPUModelNames(virConnectPtr conn,
+                                      const char *archName,
+                                      char ***names,
+                                      char ***aliases,
+                                      unsigned int flags)
+{
+    size_t i;
+    virQEMUDriver *driver = conn->privateData;
+    g_autoptr(qemuMonitorCPUDefs) cpuDefs = NULL;
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    g_autoptr(qemuProcessQMP) proc = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
+
+    virCheckFlags(0, -1);
+    if (virConnectGetHypervisorCPUModelNamesEnsureACL(conn) < 0)
+        return -1;
+
+    qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache, NULL,
+                                             archName, NULL, NULL, NULL,
+                                             NULL, NULL);
+
+    if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps), cfg->libDir,
+                                   cfg->user, cfg->group, false)))
+        return -1;
+
+    if (qemuProcessQMPStart(proc) < 0)
+        return -1;
+
+    if (qemuMonitorGetCPUDefinitions(proc->mon, &cpuDefs) < 0)
+        return -1;
+
+    // plus one to NULL terminate the lists
+    *names = g_new(char*, cpuDefs->ncpus + 1);
+    *aliases = g_new(char*, cpuDefs->ncpus + 1);
+
+    for (i = 0; i < cpuDefs->ncpus; ++i) {
+        if (cpuDefs->cpus[i].name)
+            (*names)[i] = g_strdup(cpuDefs->cpus[i].name);
+        else
+            (*names)[i] = g_strdup("");
+
+        if (cpuDefs->cpus[i].alias)
+            (*aliases)[i] = g_strdup(cpuDefs->cpus[i].alias);
+        else
+            (*aliases)[i] = g_strdup("");
+    }
+
+    return cpuDefs->ncpus;
+}
+
 
 static int
 qemuDomainGetHostnameAgent(virQEMUDriver *driver,
@@ -21324,6 +21375,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
     .domainGetMessages = qemuDomainGetMessages, /* 7.1.0 */
     .domainStartDirtyRateCalc = qemuDomainStartDirtyRateCalc, /* 7.2.0 */
     .domainSetLaunchSecurityState = qemuDomainSetLaunchSecurityState, /* 8.0.0 */
+    .connectGetHypervisorCPUModelNames = qemuConnectGetHypervisorCPUModelNames, /* 8.5.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