]> xenbits.xensource.com Git - libvirt.git/commitdiff
Revert "cgroup/LXC: Do not condition availability of v2 by controllers"
authorPavel Hrdina <phrdina@redhat.com>
Tue, 25 Oct 2022 09:34:43 +0000 (11:34 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Oct 2022 11:51:45 +0000 (13:51 +0200)
This reverts commit e49313b54ed2a149c71f9073659222742ff3ffb0.
This reverts commit a0f37232b9c4296ca16955cc625f75eb848ace39.

Revert them together to not break build.

This fix of the issue is incorrect and breaks usage of other controllers
in hybrid mode that systemd creates, specifically usage of devices and
cpuacct controllers as they are now assumed to be part of the cgroup v2
topology which is not true.

We need to find different solution to the issue.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/vircgroup.c
src/util/vircgroupv2.c

index 49ebd37dede36782c726b8e6befa2a7712726454..a6a409af3dff6af4b8536abd2a0b6de74f1b2120 100644 (file)
@@ -2921,12 +2921,10 @@ int
 virCgroupBindMount(virCgroup *group, const char *oldroot,
                    const char *mountopts)
 {
-    ssize_t i;
+    size_t i;
     virCgroup *parent = virCgroupGetNested(group);
 
-    /* In hybrid environments, V2 may be mounted over V1.
-     * Mount the backends in reverse order. */
-    for (i = VIR_CGROUP_BACKEND_TYPE_LAST - 1; i >= 0; i--) {
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
         if (parent->backends[i] &&
             parent->backends[i]->bindMount(parent, oldroot, mountopts) < 0) {
             return -1;
index bf6bd11fefa50f6f5be1d39f4df1620adcbad165..4c110940cf104a68898d67717192b246e5b4b29d 100644 (file)
@@ -69,13 +69,28 @@ virCgroupV2Available(void)
         return false;
 
     while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) {
+        g_autofree char *contFile = NULL;
+        g_autofree char *contStr = NULL;
+
         if (STRNEQ(entry.mnt_type, "cgroup2"))
             continue;
 
+        /* Systemd uses cgroup v2 for process tracking but no controller is
+         * available. We should consider this configuration as cgroup v2 is
+         * not available. */
+        contFile = g_strdup_printf("%s/cgroup.controllers", entry.mnt_dir);
+
+        if (virFileReadAll(contFile, 1024 * 1024, &contStr) < 0)
+            goto cleanup;
+
+        if (STREQ(contStr, ""))
+            continue;
+
         ret = true;
         break;
     }
 
+ cleanup:
     VIR_FORCE_FCLOSE(mounts);
     return ret;
 }