Blob Blame History Raw
From 6403a3028222b103d7ef8ecf89aabe92242667da Mon Sep 17 00:00:00 2001
Message-Id: <6403a3028222b103d7ef8ecf89aabe92242667da@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:08:15 +0200
Subject: [PATCH] util: vircgroup: pass parent cgroup into
 virCgroupDetectControllersCB
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In cgroups v2 we don't have to detect available controllers every single
time if we are creating a new cgroup based on parent cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 7bca1c9bdc85247446129f856e27c80a32819e17)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <f31650dee05403189825c50e55daf3456c7de1cc.1561993100.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      | 17 +++++++++++------
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 736b5043a8..4f71a1d197 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -388,7 +388,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 a825dc4be7..05af118ec1 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -96,7 +96,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 7098dc5644..784a963b79 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 04638c4e50..60598712c8 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -284,16 +284,21 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
 
 static int
 virCgroupV2DetectControllers(virCgroupPtr group,
-                             int controllers)
+                             int controllers,
+                             virCgroupPtr parent)
 {
     size_t i;
 
-    if (virCgroupV2ParseControllersFile(group) < 0)
-        return -1;
+    if (parent) {
+        group->unified.controllers = parent->unified.controllers;
+    } else {
+        if (virCgroupV2ParseControllersFile(group) < 0)
+            return -1;
 
-    /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always
-     * exists with usage stats. */
-    group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
+        /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always
+         * exists with usage stats. */
+        group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
+    }
 
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++)
         VIR_DEBUG("Controller '%s' present=%s",
-- 
2.22.0