[PATCH RFC 3/5] libxl: implement virConnectCompareCPU

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

 



Implement support for "virsh cpu-compare" so that we can calculate
common cpu element between a pool of hosts, which had a requirement
of providing host cpu description.

Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
---
 src/libxl/libxl_driver.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 3189f1c..32bf150 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5740,6 +5740,43 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
 }
 
 
+static int
+libxlConnectCompareCPU(virConnectPtr conn,
+                       const char *xmlDesc,
+                       unsigned int flags)
+{
+    libxlDriverPrivatePtr driver = conn->privateData;
+    libxlDriverConfigPtr cfg;
+    int ret = VIR_CPU_COMPARE_ERROR;
+    bool failIncompatible;
+
+    virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+                  VIR_CPU_COMPARE_ERROR);
+
+    if (virConnectCompareCPUEnsureACL(conn) < 0)
+        return ret;
+
+    failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+
+    cfg = libxlDriverConfigGet(driver);
+
+    if (!cfg->caps->host.cpu ||
+        !cfg->caps->host.cpu->model) {
+        if (failIncompatible) {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+                           _("cannot get host CPU capabilities"));
+        } else {
+            VIR_WARN("cannot get host CPU capabilities");
+            ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+        }
+    } else {
+        ret = cpuCompareXML(cfg->caps->host.cpu, xmlDesc, failIncompatible);
+    }
+
+    virObjectUnref(cfg);
+    return ret;
+}
+
 static virHypervisorDriver libxlHypervisorDriver = {
     .name = LIBXL_DRIVER_NAME,
     .connectOpen = libxlConnectOpen, /* 0.9.0 */
@@ -5842,6 +5879,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
     .nodeGetSecurityModel = libxlNodeGetSecurityModel, /* 1.2.16 */
     .domainInterfaceAddresses = libxlDomainInterfaceAddresses, /* 1.3.5 */
     .connectGetDomainCapabilities = libxlConnectGetDomainCapabilities, /* 2.0.0 */
+    .connectCompareCPU = libxlConnectCompareCPU, /* 2.1.0 */
 };
 
 static virConnectDriver libxlConnectDriver = {
-- 
2.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]