]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: vircgroupv2: stop enabling missing controllers with systemd
authorPavel Hrdina <phrdina@redhat.com>
Thu, 27 Jun 2019 12:54:54 +0000 (14:54 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 28 Jun 2019 13:17:37 +0000 (15:17 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgroupv2.c

index e4675a0977760d8fb20a3fb4bfbf356ddbf2f1c4..268e4013e390c3878586bc98c6c6dd982944b189 100644 (file)
@@ -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;
         }
index e58e327c68724c49e0d178e0cd1af744a6f48f26..a91719f89df055e94c3ad6257ec56060dd85dc1b 100644 (file)
@@ -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 {
index b3297dbb1329229be50e17852696b7e7cbadd9ea..9d8a38925ad08999eaa0e28ddb539e30155adf8c 100644 (file)
@@ -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);