diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c5b9cee45e067a653aedf84a6baa8b4062319e17..f07a219a8237288ad9f0cdf58d597f3a10913949 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1290,6 +1290,7 @@ virBufferVasprintf; # util/vircgroup.h +virCgroupAddMachineTask; virCgroupAddTask; virCgroupAddTaskController; virCgroupAllowAllDevices; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 2170b0ae2f99395459247a5e3098972247555edf..88ba8aaa215ae39edbf8e0f14ae7f5a7c7748ff0 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -869,12 +869,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl) ctrl->nicindexes))) goto cleanup; - if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0) + if (virCgroupAddMachineTask(ctrl->cgroup, getpid()) < 0) goto cleanup; /* Add all qemu-nbd tasks to the cgroup */ for (i = 0; i < ctrl->nnbdpids; i++) { - if (virCgroupAddTask(ctrl->cgroup, ctrl->nbdpids[i]) < 0) + if (virCgroupAddMachineTask(ctrl->cgroup, ctrl->nbdpids[i]) < 0) goto cleanup; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 80ce43c1ff5a7aeeab9acfd030d364ab463feb94..ddf19e9023669d7610148ade97a511e154e1ae1d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1184,16 +1184,8 @@ virCgroupNew(pid_t pid, } -/** - * virCgroupAddTask: - * - * @group: The cgroup to add a task to - * @pid: The pid of the task to add - * - * Returns: 0 on success, -1 on error - */ -int -virCgroupAddTask(virCgroupPtr group, pid_t pid) +static int +virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd) { int ret = -1; size_t i; @@ -1203,8 +1195,10 @@ virCgroupAddTask(virCgroupPtr group, pid_t pid) if (!group->controllers[i].mountPoint) continue; - /* We must never add tasks in systemd's hierarchy */ - if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) + /* We must never add tasks in systemd's hierarchy + * unless we're intentionally trying to move a + * task into a systemd machine scope */ + if (i == VIR_CGROUP_CONTROLLER_SYSTEMD && !withSystemd) continue; if (virCgroupAddTaskController(group, pid, i) < 0) @@ -1216,6 +1210,40 @@ virCgroupAddTask(virCgroupPtr group, pid_t pid) return ret; } +/** + * virCgroupAddTask: + * + * @group: The cgroup to add a task to + * @pid: The pid of the task to add + * + * Will add the task to all controllers, except the + * systemd unit controller. + * + * Returns: 0 on success, -1 on error + */ +int +virCgroupAddTask(virCgroupPtr group, pid_t pid) +{ + return virCgroupAddTaskInternal(group, pid, false); +} + +/** + * virCgroupAddMachineTask: + * + * @group: The cgroup to add a task to + * @pid: The pid of the task to add + * + * Will add the task to all controllers, including the + * systemd unit controller. + * + * Returns: 0 on success, -1 on error + */ +int +virCgroupAddMachineTask(virCgroupPtr group, pid_t pid) +{ + return virCgroupAddTaskInternal(group, pid, true); +} + /** * virCgroupAddTaskController: diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 4b8f3ff86f15da6ac27dd7f69479f14d819334aa..2de1bf2de4ce7bd1798f1ac73094c683945a5610 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -131,6 +131,7 @@ int virCgroupPathOfController(virCgroupPtr group, char **path); int virCgroupAddTask(virCgroupPtr group, pid_t pid); +int virCgroupAddMachineTask(virCgroupPtr group, pid_t pid); int virCgroupAddTaskController(virCgroupPtr group, pid_t pid,