mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
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:
parent
f9d1c08557
commit
29a94a3fef
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user