[libvirt] [PATCH 2/2] util: vircgroupv2: stop enabling missing controllers with systemd

Pavel Hrdina phrdina at redhat.com
Thu Jun 27 14:18:47 UTC 2019


Because of a systemd delegation policy [1] we should not write to any
cgroups files owned by systemd which in case of cgroups v2 includes
'cgroups.subtree_control'.

systemd will enable controllers automatically for us to have them
available for VM cgroups.

[1] <https://github.com/systemd/systemd/blob/master/docs/CGROUP_DELEGATION.md>

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroup.c        | 2 +-
 src/util/vircgroupbackend.h | 3 +++
 src/util/vircgroupv2.c      | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index e4675a0977..268e4013e3 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1082,7 +1082,7 @@ virCgroupEnableMissingControllers(char *path,
                          &tmp) < 0)
             goto cleanup;
 
-        if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_NONE) < 0) {
+        if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) {
             virCgroupFree(&tmp);
             goto cleanup;
         }
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index e58e327c68..a91719f89d 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -34,6 +34,9 @@ typedef enum {
                                        * attaching tasks
                                        */
     VIR_CGROUP_THREAD = 1 << 1, /* cgroup v2 handles threads differently */
+    VIR_CGROUP_SYSTEMD = 1 << 2, /* with systemd and cgroups v2 we cannot
+                                  * manually enable controllers that systemd
+                                  * doesn't know how to delegate */
 } virCgroupBackendFlags;
 
 typedef enum {
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index b3297dbb13..9d8a38925a 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -395,6 +395,11 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNUSED,
     VIR_AUTOFREE(char *) path = NULL;
     int controller;
 
+    if (flags & VIR_CGROUP_SYSTEMD) {
+        VIR_DEBUG("Running with systemd so we should not create cgroups ourselves.");
+        return 0;
+    }
+
     VIR_DEBUG("Make group %s", group->path);
 
     controller = virCgroupV2GetAnyController(group);
-- 
2.21.0




More information about the libvir-list mailing list