util: vircgroupv2: separate return values of virCgroupV2EnableController

In order to skip controllers that we are not able to activate we need
to return different return value so the caller can decide what to do.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Pavel Hrdina 2019-06-21 14:47:47 +02:00
parent f9d1c08557
commit 29a94a3fef

View File

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