[libvirt] [PATCH] vircgroup: fix partition creation for cgroups v2 without systemd

Pavel Hrdina posted 1 patch 4 years, 8 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/e5a76531fe9e76ec57d8c1e37d14b18512f83de7.1564734617.git.phrdina@redhat.com
src/util/vircgroup.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
[libvirt] [PATCH] vircgroup: fix partition creation for cgroups v2 without systemd
Posted by Pavel Hrdina 4 years, 8 months ago
On hosts without systemd libvirt is responsible for creating cgroups
topology.  With cgroups v2 the logic changed a bit.  If we need to
create new directory the detection of controllers fails because the
directory doesn't exists so there is no cgroup.controllers file.
To fix that issue we need to have a parent cgroup where we can look
into cgroup.subtree_control to get a list of enabled controllers.

To fix the issue reorder the operations to get a parent group fist so
we can use it to create a new partition.

<https://www.redhat.com/archives/libvir-list/2019-July/msg01309.html>

Reported-by: Raghav Gururajan <rvgn@disroot.org>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/vircgroup.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 825f62a97b..0789630b47 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -842,6 +842,7 @@ virCgroupNewPartition(const char *path,
                       virCgroupPtr *group)
 {
     int ret = -1;
+    char *tmp;
     VIR_AUTOFREE(char *) parentPath = NULL;
     VIR_AUTOFREE(char *) newPath = NULL;
     virCgroupPtr parent = NULL;
@@ -858,25 +859,27 @@ virCgroupNewPartition(const char *path,
     if (virCgroupSetPartitionSuffix(path, &newPath) < 0)
         goto cleanup;
 
-    if (virCgroupNew(-1, newPath, NULL, controllers, group) < 0)
+    if (STREQ(newPath, "/")) {
+        ret = 0;
         goto cleanup;
-
-    if (STRNEQ(newPath, "/")) {
-        char *tmp;
-        if (VIR_STRDUP(parentPath, newPath) < 0)
-            goto cleanup;
-
-        tmp = strrchr(parentPath, '/');
-        tmp++;
-        *tmp = '\0';
-
-        if (virCgroupNew(-1, parentPath, NULL, controllers, &parent) < 0)
-            goto cleanup;
-
-        if (virCgroupMakeGroup(parent, *group, create, VIR_CGROUP_NONE) < 0)
-            goto cleanup;
     }
 
+    if (VIR_STRDUP(parentPath, newPath) < 0)
+        goto cleanup;
+
+    tmp = strrchr(parentPath, '/');
+    tmp++;
+    *tmp = '\0';
+
+    if (virCgroupNew(-1, parentPath, NULL, controllers, &parent) < 0)
+        goto cleanup;
+
+    if (virCgroupNew(-1, newPath, parent, controllers, group) < 0)
+        goto cleanup;
+
+    if (virCgroupMakeGroup(parent, *group, create, VIR_CGROUP_NONE) < 0)
+        goto cleanup;
+
     ret = 0;
  cleanup:
     if (ret != 0)
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list