util: vircgroup: improve controller detection

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>
This commit is contained in:
Pavel Hrdina 2019-06-20 13:02:57 +02:00
parent 7bca1c9bdc
commit d3007c844d
3 changed files with 20 additions and 18 deletions

View 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;
}

View File

@ -464,6 +464,7 @@ virCgroupV1DetectControllers(virCgroupPtr group,
}
}
VIR_FREE(group->legacy[i].mountPoint);
VIR_FREE(group->legacy[i].placement);
}
}
} else {

View 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);