render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 6403a3028222b103d7ef8ecf89aabe92242667da Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <6403a3028222b103d7ef8ecf89aabe92242667da@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:08:15 +0200
c480ed
Subject: [PATCH] util: vircgroup: pass parent cgroup into
c480ed
 virCgroupDetectControllersCB
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
In cgroups v2 we don't have to detect available controllers every single
c480ed
time if we are creating a new cgroup based on parent cgroup.
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit 7bca1c9bdc85247446129f856e27c80a32819e17)
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: <f31650dee05403189825c50e55daf3456c7de1cc.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        |  2 +-
c480ed
 src/util/vircgroupbackend.h |  3 ++-
c480ed
 src/util/vircgroupv1.c      |  3 ++-
c480ed
 src/util/vircgroupv2.c      | 17 +++++++++++------
c480ed
 4 files changed, 16 insertions(+), 9 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 736b5043a8..4f71a1d197 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -388,7 +388,7 @@ virCgroupDetect(virCgroupPtr group,
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);
c480ed
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
c480ed
             if (rc < 0)
c480ed
                 return -1;
c480ed
             controllersAvailable |= rc;
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index a825dc4be7..05af118ec1 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -96,7 +96,8 @@ typedef char *
c480ed
 
c480ed
 typedef int
c480ed
 (*virCgroupDetectControllersCB)(virCgroupPtr group,
c480ed
-                                int controllers);
c480ed
+                                int controllers,
c480ed
+                                virCgroupPtr parent);
c480ed
 
c480ed
 typedef bool
c480ed
 (*virCgroupHasControllerCB)(virCgroupPtr cgroup,
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 7098dc5644..784a963b79 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -419,7 +419,8 @@ virCgroupV1StealPlacement(virCgroupPtr group)
c480ed
 
c480ed
 static int
c480ed
 virCgroupV1DetectControllers(virCgroupPtr group,
c480ed
-                             int controllers)
c480ed
+                             int controllers,
c480ed
+                             virCgroupPtr parent ATTRIBUTE_UNUSED)
c480ed
 {
c480ed
     size_t i;
c480ed
     size_t j;
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 04638c4e50..60598712c8 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -284,16 +284,21 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
c480ed
 
c480ed
 static int
c480ed
 virCgroupV2DetectControllers(virCgroupPtr group,
c480ed
-                             int controllers)
c480ed
+                             int controllers,
c480ed
+                             virCgroupPtr parent)
c480ed
 {
c480ed
     size_t i;
c480ed
 
c480ed
-    if (virCgroupV2ParseControllersFile(group) < 0)
c480ed
-        return -1;
c480ed
+    if (parent) {
c480ed
+        group->unified.controllers = parent->unified.controllers;
c480ed
+    } else {
c480ed
+        if (virCgroupV2ParseControllersFile(group) < 0)
c480ed
+            return -1;
c480ed
 
c480ed
-    /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always
c480ed
-     * exists with usage stats. */
c480ed
-    group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
c480ed
+        /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always
c480ed
+         * exists with usage stats. */
c480ed
+        group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
c480ed
+    }
c480ed
 
c480ed
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++)
c480ed
         VIR_DEBUG("Controller '%s' present=%s",
c480ed
-- 
c480ed
2.22.0
c480ed