diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3f4548b532..032f78ac8e 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -353,22 +353,40 @@ virCgroupV2PathOfController(virCgroupPtr group, } +/** + * virCgroupV2EnableController: + * + * Returns: -1 on fatal error + * -2 if we failed to write into cgroup.subtree_control + * 0 on success + */ static int virCgroupV2EnableController(virCgroupPtr parent, - int controller) + int controller, + bool report) { VIR_AUTOFREE(char *) val = NULL; + VIR_AUTOFREE(char *) path = NULL; if (virAsprintf(&val, "+%s", virCgroupV2ControllerTypeToString(controller)) < 0) { return -1; } - if (virCgroupSetValueStr(parent, controller, - "cgroup.subtree_control", val) < 0) { + if (virCgroupPathOfController(parent, controller, + "cgroup.subtree_control", &path) < 0) { return -1; } + if (virFileWriteStr(path, val, 0) < 0) { + if (report) { + virReportSystemError(errno, + _("Failed to enable controller '%s' for '%s'"), + val, path); + } + return -2; + } + return 0; } @@ -406,13 +424,15 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNUSED, if (virCgroupV2HasController(parent, VIR_CGROUP_CONTROLLER_CPU) && virCgroupV2EnableController(parent, - VIR_CGROUP_CONTROLLER_CPU) < 0) { + VIR_CGROUP_CONTROLLER_CPU, + true) < 0) { return -1; } if (virCgroupV2HasController(parent, VIR_CGROUP_CONTROLLER_CPUSET) && virCgroupV2EnableController(parent, - VIR_CGROUP_CONTROLLER_CPUSET) < 0) { + VIR_CGROUP_CONTROLLER_CPUSET, + true) < 0) { return -1; } } else { @@ -425,7 +445,7 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNUSED, if (i == VIR_CGROUP_CONTROLLER_CPUACCT) continue; - if (virCgroupV2EnableController(parent, i) < 0) + if (virCgroupV2EnableController(parent, i, true) < 0) return -1; } }