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

[libvirt] [PATCH 3/3] lxc: Implement geting emulator pin info API in lxc driver



From: Yue Wenyuan <yuewenyuan huawei com>

Implement the lxc driver method for virDomainGetEmulatorPinInfo
to get container's cpuset.

Signed-off-by: Wang Rui <moon wangrui huawei com>
Signed-off-by: Yue Wenyuan <yuewenyuan huawei com>
---
 src/lxc/lxc_driver.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 9e3a877..6694cf3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1395,6 +1395,80 @@ lxcDomainPinEmulator(virDomainPtr dom,
     return ret;
 }
 
+static int
+lxcDomainGetEmulatorPinInfo(virDomainPtr dom,
+                             unsigned char *cpumaps,
+                             int maplen,
+                             unsigned int flags)
+{
+    virLXCDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm = NULL;
+    virDomainDefPtr targetDef = NULL;
+    int ret = -1;
+    int maxcpu, hostcpus, pcpu;
+    virBitmapPtr cpumask = NULL;
+    bool pinned;
+    virCapsPtr caps = NULL;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(vm = lxcDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainGetEmulatorPinInfoEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt,
+                                        vm, &flags, &targetDef) < 0)
+        goto cleanup;
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE)
+        targetDef = vm->def;
+
+    sa_assert(targetDef);
+
+    if ((hostcpus = nodeGetCPUCount()) < 0)
+        goto cleanup;
+
+    maxcpu = maplen * 8;
+    if (maxcpu > hostcpus)
+        maxcpu = hostcpus;
+
+    /* initialize cpumaps */
+    memset(cpumaps, 0xff, maplen);
+    if (maxcpu % 8) {
+        cpumaps[maplen - 1] &= (1 << maxcpu % 8) - 1;
+    }
+
+    if (targetDef->cputune.emulatorpin) {
+        cpumask = targetDef->cputune.emulatorpin->cpumask;
+    } else if (targetDef->cpumask) {
+        cpumask = targetDef->cpumask;
+    } else {
+        ret = 0;
+        goto cleanup;
+    }
+
+    for (pcpu = 0; pcpu < maxcpu; pcpu++) {
+        if (virBitmapGetBit(cpumask, pcpu, &pinned) < 0)
+            goto cleanup;
+        if (!pinned)
+            VIR_UNUSE_CPU(cpumaps, pcpu);
+    }
+
+    ret = 1;
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    virObjectUnref(caps);
+    return ret;
+}
+
 static int lxcDomainGetSecurityLabel(virDomainPtr dom, virSecurityLabelPtr seclabel)
 {
     virLXCDriverPtr driver = dom->conn->privateData;
@@ -5831,6 +5905,7 @@ static virDriver lxcDriver = {
     .domainCreateXML = lxcDomainCreateXML, /* 0.4.4 */
     .domainCreateXMLWithFiles = lxcDomainCreateXMLWithFiles, /* 1.1.1 */
     .domainPinEmulator = lxcDomainPinEmulator, /*1.2.9*/
+    .domainGetEmulatorPinInfo = lxcDomainGetEmulatorPinInfo, /*1.2.9*/
     .domainLookupByID = lxcDomainLookupByID, /* 0.4.2 */
     .domainLookupByUUID = lxcDomainLookupByUUID, /* 0.4.2 */
     .domainLookupByName = lxcDomainLookupByName, /* 0.4.2 */
-- 
1.7.12.4



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