7a3408
From 3f53107a34adf39f8e380a1036eda619b3460a2c Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <3f53107a34adf39f8e380a1036eda619b3460a2c@dist-git>
7a3408
From: Luyao Huang <lhuang@redhat.com>
7a3408
Date: Thu, 6 Aug 2015 13:08:35 +0200
7a3408
Subject: [PATCH] qemu: fix some api cannot work when disable cpuset in conf
7a3408
7a3408
If cpuset is disabled or not available, it libvirt must not use it.
7a3408
Mainly for actions that do not need it and can use sched_setaffinity()
7a3408
or numa_membind() instead, because they will fail without good reason.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1244664
7a3408
7a3408
Signed-off-by: Luyao Huang <lhuang@redhat.com>
7a3408
(cherry picked from commit 1439eb32afc9f97378d1d121c0b5c80d2f84896c)
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_cgroup.c | 16 ++++++++--------
7a3408
 src/qemu/qemu_driver.c | 10 +++++++---
7a3408
 2 files changed, 15 insertions(+), 11 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
7a3408
index ab21e12..e1a2827 100644
7a3408
--- a/src/qemu/qemu_cgroup.c
7a3408
+++ b/src/qemu/qemu_cgroup.c
7a3408
@@ -1025,10 +1025,6 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
7a3408
         if (virCgroupAddTask(cgroup_vcpu, priv->vcpupids[i]) < 0)
7a3408
             goto cleanup;
7a3408
 
7a3408
-        if (mem_mask &&
7a3408
-            virCgroupSetCpusetMems(cgroup_vcpu, mem_mask) < 0)
7a3408
-            goto cleanup;
7a3408
-
7a3408
         if (period || quota) {
7a3408
             if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0)
7a3408
                 goto cleanup;
7a3408
@@ -1038,6 +1034,10 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
7a3408
         if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
7a3408
             virBitmapPtr cpumap = NULL;
7a3408
 
7a3408
+            if (mem_mask &&
7a3408
+                virCgroupSetCpusetMems(cgroup_vcpu, mem_mask) < 0)
7a3408
+                goto cleanup;
7a3408
+
7a3408
             /* try to use the default cpu maps */
7a3408
             if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
7a3408
                 cpumap = priv->autoCpuset;
7a3408
@@ -1202,15 +1202,15 @@ qemuSetupCgroupForIOThreads(virDomainObjPtr vm)
7a3408
                 goto cleanup;
7a3408
         }
7a3408
 
7a3408
-        if (mem_mask &&
7a3408
-            virCgroupSetCpusetMems(cgroup_iothread, mem_mask) < 0)
7a3408
-            goto cleanup;
7a3408
-
7a3408
         /* Set iothreadpin in cgroup if iothreadpin xml is provided */
7a3408
         if (virCgroupHasController(priv->cgroup,
7a3408
                                    VIR_CGROUP_CONTROLLER_CPUSET)) {
7a3408
             virBitmapPtr cpumask = NULL;
7a3408
 
7a3408
+            if (mem_mask &&
7a3408
+                virCgroupSetCpusetMems(cgroup_iothread, mem_mask) < 0)
7a3408
+                goto cleanup;
7a3408
+
7a3408
             if (def->iothreadids[i]->cpumask)
7a3408
                 cpumask = def->iothreadids[i]->cpumask;
7a3408
             else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
7a3408
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
7a3408
index 6b715bf..bb0dc7e 100644
7a3408
--- a/src/qemu/qemu_driver.c
7a3408
+++ b/src/qemu/qemu_driver.c
7a3408
@@ -4613,7 +4613,9 @@ qemuDomainAddCgroupForThread(virCgroupPtr cgroup,
7a3408
     if (virCgroupNewThread(cgroup, nameval, idx, true, &new_cgroup) < 0)
7a3408
         return NULL;
7a3408
 
7a3408
-    if (mem_mask && virCgroupSetCpusetMems(new_cgroup, mem_mask) < 0)
7a3408
+    if (mem_mask &&
7a3408
+        virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET) &&
7a3408
+        virCgroupSetCpusetMems(new_cgroup, mem_mask) < 0)
7a3408
         goto error;
7a3408
 
7a3408
     /* Add pid/thread to the cgroup */
7a3408
@@ -4669,7 +4671,8 @@ qemuDomainHotplugPinThread(virBitmapPtr cpumask,
7a3408
 {
7a3408
     int ret = -1;
7a3408
 
7a3408
-    if (cgroup) {
7a3408
+    if (cgroup &&
7a3408
+        virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
7a3408
         if (qemuSetupCgroupCpusetCpus(cgroup, cpumask) < 0) {
7a3408
             virReportError(VIR_ERR_OPERATION_INVALID,
7a3408
                            _("failed to set cpuset.cpus in cgroup for id %d"),
7a3408
@@ -4912,7 +4915,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
7a3408
     if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
7a3408
         goto endjob;
7a3408
 
7a3408
-    if (def && !(flags & VIR_DOMAIN_VCPU_GUEST) && virNumaIsAvailable()) {
7a3408
+    if (def && !(flags & VIR_DOMAIN_VCPU_GUEST) && virNumaIsAvailable() &&
7a3408
+        virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
7a3408
         if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
7a3408
                                false, &cgroup_temp) < 0)
7a3408
             goto endjob;
7a3408
-- 
7a3408
2.5.0
7a3408