]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: vircgroup: improve controller detection
authorPavel Hrdina <phrdina@redhat.com>
Thu, 20 Jun 2019 11:02:57 +0000 (13:02 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 26 Jun 2019 11:34:01 +0000 (13:34 +0200)
This affects only cgroups v2 where enabled controllers are not based on
available mount points but on the list provided in cgroup.controllers
file.  However, moving it will fill in placement as well, so it needs
to be freed together with mount point if we don't need that controller.

Before this patch we were assuming that all controllers available in
root cgroup where available in all other sub-cgroups which was wrong.

In order to fix it we need to move the cgroup controllers detection
after cgroup placement was prepared in order to build correct path for
cgroup.controllers file.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/vircgroup.c
src/util/vircgroupv1.c
src/util/vircgroupv2.c

index b7e5f0352147059ff2013e7f9019b7e8cacfd7f0..da506fc0b0ad3bee3009f9a3be89fc07f17ad9d5 100644 (file)
@@ -381,22 +381,6 @@ virCgroupDetect(virCgroupPtr group,
             return -1;
     }
 
-    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
-        if (group->backends[i]) {
-            int rc = group->backends[i]->detectControllers(group, controllers, parent);
-            if (rc < 0)
-                return -1;
-            controllersAvailable |= rc;
-        }
-    }
-
-    /* Check that at least 1 controller is available */
-    if (controllersAvailable == 0) {
-        virReportSystemError(ENXIO, "%s",
-                             _("At least one cgroup controller is required"));
-        return -1;
-    }
-
     /* In some cases we can copy part of the placement info
      * based on the parent cgroup...
      */
@@ -421,6 +405,22 @@ virCgroupDetect(virCgroupPtr group,
         }
     }
 
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
+        if (group->backends[i]) {
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
+            if (rc < 0)
+                return -1;
+            controllersAvailable |= rc;
+        }
+    }
+
+    /* Check that at least 1 controller is available */
+    if (controllersAvailable == 0) {
+        virReportSystemError(ENXIO, "%s",
+                             _("At least one cgroup controller is required"));
+        return -1;
+    }
+
     return 0;
 }
 
index fb3e0b2d478b48151e87a0e40a25d13fcbdaf127..4231d8d6faa303240ad82255e306cd4a57554c5c 100644 (file)
@@ -464,6 +464,7 @@ virCgroupV1DetectControllers(virCgroupPtr group,
                     }
                 }
                 VIR_FREE(group->legacy[i].mountPoint);
+                VIR_FREE(group->legacy[i].placement);
             }
         }
     } else {
index 2d09d77a2998e451dc3e9845fc08be70f32e02b1..29b5806a01e0dfd50c1629c08acb7d99d25fa271 100644 (file)
@@ -250,8 +250,9 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
     char **contList = NULL;
     char **tmp;
 
-    if (virAsprintf(&contFile, "%s/cgroup.controllers",
-                    group->unified.mountPoint) < 0)
+    if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
+                    group->unified.mountPoint,
+                    NULLSTR_EMPTY(group->unified.placement)) < 0)
         return -1;
 
     rc = virFileReadAll(contFile, 1024 * 1024, &contStr);