Blame SOURCES/libvirt-vircgroupv2-move-task-into-cgroup-before-enabling-controllers.patch

7548c0
From 41a7547b32786b1a84c8ee7bad0c4cf9559ea4b9 Mon Sep 17 00:00:00 2001
7548c0
Message-Id: <41a7547b32786b1a84c8ee7bad0c4cf9559ea4b9@dist-git>
7548c0
From: Pavel Hrdina <phrdina@redhat.com>
7548c0
Date: Fri, 19 Feb 2021 13:33:57 +0100
7548c0
Subject: [PATCH] vircgroupv2: move task into cgroup before enabling
7548c0
 controllers
7548c0
MIME-Version: 1.0
7548c0
Content-Type: text/plain; charset=UTF-8
7548c0
Content-Transfer-Encoding: 8bit
7548c0
7548c0
When we create a new child cgroup and the parent cgroup has any process
7548c0
attached to it enabling controllers for the child cgroup fails with
7548c0
error. We need to move the process into the child cgroup first before
7548c0
enabling any controllers.
7548c0
7548c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7548c0
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
7548c0
(cherry picked from commit 382fa15cde538cba3888a89b301fd3d9a0ce69ea)
7548c0
7548c0
Conflicts:
7548c0
    src/util/vircgroup.c
7548c0
        - missing upstream g_autofree rewrite
7548c0
7548c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
7548c0
7548c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7548c0
Message-Id: <85d34403caacb571cb78539d5c4f56eee9484d57.1613737828.git.phrdina@redhat.com>
7548c0
Reviewed-by: Ján Tomko <jtomko@redhat.com>
7548c0
---
7548c0
 src/util/vircgroup.c        | 13 +++++++------
7548c0
 src/util/vircgroupbackend.h |  1 +
7548c0
 src/util/vircgroupv1.c      |  1 +
7548c0
 src/util/vircgroupv2.c      | 13 +++++++++++++
7548c0
 4 files changed, 22 insertions(+), 6 deletions(-)
7548c0
7548c0
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
7548c0
index 10b934291c..8f5bcd94f4 100644
7548c0
--- a/src/util/vircgroup.c
7548c0
+++ b/src/util/vircgroup.c
7548c0
@@ -622,13 +622,14 @@ static int
7548c0
 virCgroupMakeGroup(virCgroupPtr parent,
7548c0
                    virCgroupPtr group,
7548c0
                    bool create,
7548c0
+                   pid_t pid,
7548c0
                    unsigned int flags)
7548c0
 {
7548c0
     size_t i;
7548c0
 
7548c0
     for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
7548c0
         if (group->backends[i] &&
7548c0
-            group->backends[i]->makeGroup(parent, group, create, flags) < 0) {
7548c0
+            group->backends[i]->makeGroup(parent, group, create, pid, flags) < 0) {
7548c0
             virCgroupRemove(group);
7548c0
             return -1;
7548c0
         }
7548c0
@@ -857,8 +858,8 @@ virCgroupNewPartition(const char *path,
7548c0
         goto cleanup;
7548c0
 
7548c0
     if (parent) {
7548c0
-        if (virCgroupMakeGroup(parent, *group, create, VIR_CGROUP_NONE) < 0)
7548c0
-            goto cleanup;
7548c0
+        if (virCgroupMakeGroup(parent, *group, create, -1, VIR_CGROUP_NONE) < 0)
7548c0
+            return -1;
7548c0
     }
7548c0
 
7548c0
     ret = 0;
7548c0
@@ -924,7 +925,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition,
7548c0
      * a group for driver, is to avoid overhead to track
7548c0
      * cumulative usage that we don't need.
7548c0
      */
7548c0
-    if (virCgroupMakeGroup(partition, *group, create,
7548c0
+    if (virCgroupMakeGroup(partition, *group, create, -1,
7548c0
                            VIR_CGROUP_MEM_HIERACHY) < 0) {
7548c0
         virCgroupFree(group);
7548c0
         return -1;
7548c0
@@ -978,7 +979,7 @@ virCgroupNewThread(virCgroupPtr domain,
7548c0
     if (virCgroupNew(-1, name, domain, controllers, group) < 0)
7548c0
         return -1;
7548c0
 
7548c0
-    if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_THREAD) < 0) {
7548c0
+    if (virCgroupMakeGroup(domain, *group, create, -1, VIR_CGROUP_THREAD) < 0) {
7548c0
         virCgroupFree(group);
7548c0
         return -1;
7548c0
     }
7548c0
@@ -1065,7 +1066,7 @@ virCgroupEnableMissingControllers(char *path,
7548c0
                          &tmp) < 0)
7548c0
             goto cleanup;
7548c0
 
7548c0
-        if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) {
7548c0
+        if (virCgroupMakeGroup(parent, tmp, true, -1, VIR_CGROUP_SYSTEMD) < 0) {
7548c0
             virCgroupFree(&tmp);
7548c0
             goto cleanup;
7548c0
         }
7548c0
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
7548c0
index e12a2e8b9d..ac7b3ae517 100644
7548c0
--- a/src/util/vircgroupbackend.h
7548c0
+++ b/src/util/vircgroupbackend.h
7548c0
@@ -119,6 +119,7 @@ typedef int
7548c0
 (*virCgroupMakeGroupCB)(virCgroupPtr parent,
7548c0
                         virCgroupPtr group,
7548c0
                         bool create,
7548c0
+                        pid_t pid,
7548c0
                         unsigned int flags);
7548c0
 
7548c0
 typedef int
7548c0
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
7548c0
index 09165ece4d..eb2b611cee 100644
7548c0
--- a/src/util/vircgroupv1.c
7548c0
+++ b/src/util/vircgroupv1.c
7548c0
@@ -601,6 +601,7 @@ static int
7548c0
 virCgroupV1MakeGroup(virCgroupPtr parent,
7548c0
                      virCgroupPtr group,
7548c0
                      bool create,
7548c0
+                     pid_t pid G_GNUC_UNUSED,
7548c0
                      unsigned int flags)
7548c0
 {
7548c0
     size_t i;
7548c0
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
7548c0
index 8fe4894a9e..5e19ed8332 100644
7548c0
--- a/src/util/vircgroupv2.c
7548c0
+++ b/src/util/vircgroupv2.c
7548c0
@@ -398,10 +398,17 @@ virCgroupV2EnableController(virCgroupPtr group,
7548c0
 }
7548c0
 
7548c0
 
7548c0
+static int
7548c0
+virCgroupV2AddTask(virCgroupPtr group,
7548c0
+                   pid_t pid,
7548c0
+                   unsigned int flags);
7548c0
+
7548c0
+
7548c0
 static int
7548c0
 virCgroupV2MakeGroup(virCgroupPtr parent,
7548c0
                      virCgroupPtr group,
7548c0
                      bool create,
7548c0
+                     pid_t pid,
7548c0
                      unsigned int flags)
7548c0
 {
7548c0
     g_autofree char *path = NULL;
7548c0
@@ -449,6 +456,12 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
7548c0
             }
7548c0
         } else {
7548c0
             size_t i;
7548c0
+
7548c0
+            if (pid > 0) {
7548c0
+                if (virCgroupV2AddTask(group, pid, VIR_CGROUP_TASK_PROCESS) < 0)
7548c0
+                    return -1;
7548c0
+            }
7548c0
+
7548c0
             for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
7548c0
                 int rc;
7548c0
 
7548c0
-- 
7548c0
2.30.0
7548c0