render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 8c784cd15bbac88334271f95d14a9770c1b2d864 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <8c784cd15bbac88334271f95d14a9770c1b2d864@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:08:17 +0200
c480ed
Subject: [PATCH] util: vircgroup: improve controller detection
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
This affects only cgroups v2 where enabled controllers are not based on
c480ed
available mount points but on the list provided in cgroup.controllers
c480ed
file.  However, moving it will fill in placement as well, so it needs
c480ed
to be freed together with mount point if we don't need that controller.
c480ed
c480ed
Before this patch we were assuming that all controllers available in
c480ed
root cgroup where available in all other sub-cgroups which was wrong.
c480ed
c480ed
In order to fix it we need to move the cgroup controllers detection
c480ed
after cgroup placement was prepared in order to build correct path for
c480ed
cgroup.controllers file.
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
c480ed
(cherry picked from commit d3007c844d8aa0caa0328ab18275be375f597704)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <cec99e4c53912c3ee6f45012fc4fd760f6e8445b.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c   | 32 ++++++++++++++++----------------
c480ed
 src/util/vircgroupv1.c |  1 +
c480ed
 src/util/vircgroupv2.c |  5 +++--
c480ed
 3 files changed, 20 insertions(+), 18 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 4f71a1d197..ff2a0b75b5 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -386,22 +386,6 @@ virCgroupDetect(virCgroupPtr group,
c480ed
             return -1;
c480ed
     }
c480ed
 
c480ed
-    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c480ed
-        if (group->backends[i]) {
c480ed
-            int rc = group->backends[i]->detectControllers(group, controllers, parent);
c480ed
-            if (rc < 0)
c480ed
-                return -1;
c480ed
-            controllersAvailable |= rc;
c480ed
-        }
c480ed
-    }
c480ed
-
c480ed
-    /* Check that at least 1 controller is available */
c480ed
-    if (controllersAvailable == 0) {
c480ed
-        virReportSystemError(ENXIO, "%s",
c480ed
-                             _("At least one cgroup controller is required"));
c480ed
-        return -1;
c480ed
-    }
c480ed
-
c480ed
     /* In some cases we can copy part of the placement info
c480ed
      * based on the parent cgroup...
c480ed
      */
c480ed
@@ -426,6 +410,22 @@ virCgroupDetect(virCgroupPtr group,
c480ed
         }
c480ed
     }
c480ed
 
c480ed
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c480ed
+        if (group->backends[i]) {
c480ed
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
c480ed
+            if (rc < 0)
c480ed
+                return -1;
c480ed
+            controllersAvailable |= rc;
c480ed
+        }
c480ed
+    }
c480ed
+
c480ed
+    /* Check that at least 1 controller is available */
c480ed
+    if (controllersAvailable == 0) {
c480ed
+        virReportSystemError(ENXIO, "%s",
c480ed
+                             _("At least one cgroup controller is required"));
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
     return 0;
c480ed
 }
c480ed
 
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 784a963b79..5b218c7f78 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -463,6 +463,7 @@ virCgroupV1DetectControllers(virCgroupPtr group,
c480ed
                     }
c480ed
                 }
c480ed
                 VIR_FREE(group->legacy[i].mountPoint);
c480ed
+                VIR_FREE(group->legacy[i].placement);
c480ed
             }
c480ed
         }
c480ed
     } else {
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 60598712c8..10f8a9bbdf 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -249,8 +249,9 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
c480ed
     char **contList = NULL;
c480ed
     char **tmp;
c480ed
 
c480ed
-    if (virAsprintf(&contFile, "%s/cgroup.controllers",
c480ed
-                    group->unified.mountPoint) < 0)
c480ed
+    if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
c480ed
+                    group->unified.mountPoint,
c480ed
+                    NULLSTR_EMPTY(group->unified.placement)) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
c480ed
-- 
c480ed
2.22.0
c480ed