提交 29a94a3f 编写于 作者: P Pavel Hrdina

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: NPavel Hrdina <phrdina@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 f9d1c085
......@@ -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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册