render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From b220fdba77897f65f3e7e963868f22d7ace58724 Mon Sep 17 00:00:00 2001
Message-Id: <b220fdba77897f65f3e7e963868f22d7ace58724@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Thu, 25 Jul 2019 13:37:01 +0200
Subject: [PATCH] vircgroup: fix cgroups v2 controllers detection
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When creating new group for cgroups v2 the we cannot check
cgroups.controllers for that cgroup because the directory is created
later.  In that case we should check cgroups.subtree_control of parent
group to get list of controllers enabled for child cgroups.

In order to achieve that we will prefer the parent group if it exists,
the current group will be used only for root group.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit 7b77f3a11e9ae3e3cf0ccb71bd72d4a865b7c71e)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <ff6427994e0904f5649b70206f8f73129d1b8452.1564054553.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        |  2 +-
 src/util/vircgroupbackend.h |  3 ++-
 src/util/vircgroupv1.c      |  3 ++-
 src/util/vircgroupv2.c      | 23 ++++++++++++++++-------
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 37f6def08d..2c067edc5c 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -412,7 +412,7 @@ virCgroupDetect(virCgroupPtr group,
 
     for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
         if (group->backends[i]) {
-            int rc = group->backends[i]->detectControllers(group, controllers);
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
             if (rc < 0)
                 return -1;
             controllersAvailable |= rc;
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 2b5be21a76..b97f686368 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -99,7 +99,8 @@ typedef char *
 
 typedef int
 (*virCgroupDetectControllersCB)(virCgroupPtr group,
-                                int controllers);
+                                int controllers,
+                                virCgroupPtr parent);
 
 typedef bool
 (*virCgroupHasControllerCB)(virCgroupPtr cgroup,
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index a7d6c92e4c..925e8ee1c1 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -419,7 +419,8 @@ virCgroupV1StealPlacement(virCgroupPtr group)
 
 static int
 virCgroupV1DetectControllers(virCgroupPtr group,
-                             int controllers)
+                             int controllers,
+                             virCgroupPtr parent ATTRIBUTE_UNUSED)
 {
     size_t i;
     size_t j;
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index b4e90ed46d..7b3cd64cc5 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -241,7 +241,8 @@ virCgroupV2StealPlacement(virCgroupPtr group)
 
 
 static int
-virCgroupV2ParseControllersFile(virCgroupPtr group)
+virCgroupV2ParseControllersFile(virCgroupPtr group,
+                                virCgroupPtr parent)
 {
     int rc;
     VIR_AUTOFREE(char *) contStr = NULL;
@@ -249,10 +250,17 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
     char **contList = NULL;
     char **tmp;
 
-    if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
-                    group->unified.mountPoint,
-                    NULLSTR_EMPTY(group->unified.placement)) < 0)
-        return -1;
+    if (parent) {
+        if (virAsprintf(&contFile, "%s%s/cgroup.subtree_control",
+                        parent->unified.mountPoint,
+                        NULLSTR_EMPTY(parent->unified.placement)) < 0)
+            return -1;
+    } else {
+        if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
+                        group->unified.mountPoint,
+                        NULLSTR_EMPTY(group->unified.placement)) < 0)
+            return -1;
+    }
 
     rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
     if (rc < 0) {
@@ -285,11 +293,12 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
 
 static int
 virCgroupV2DetectControllers(virCgroupPtr group,
-                             int controllers)
+                             int controllers,
+                             virCgroupPtr parent)
 {
     size_t i;
 
-    if (virCgroupV2ParseControllersFile(group) < 0)
+    if (virCgroupV2ParseControllersFile(group, parent) < 0)
         return -1;
 
     /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always
-- 
2.22.0