render / rpms / libvirt

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