mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
lxc: ensure libvirt_lxc and qemu-nbd move into systemd machine slice
Currently when spawning containers with systemd, the container PID 1 will get moved into the systemd machine slice. Libvirt then manually moves the libvirt_lxc and qemu-nbd processes into the cgroups associated with the slice, but skips the systemd controller cgroup. This means that from systemd's POV, libvirt_lxc and qemu-nbd are still part of the libvirtd.service unit. On systemctl daemon-reload, it will notice that libvirt_lxc & qemu-nbd are in the libvirtd.service unit for the systemd controller, but in the machine cgroups for resources. Systemd will thus move them back into the libvirtd.service resource cgroups next time libvirtd is restarted. This causes libvirtd to kill off the container due to incorrect cgroup placement. The solution is to ensure that when moving libvirt_lxc & qemu-nbd, we also move the systemd cgroup controller placement. Normally this is not something we ever want todo, but this is a special case as we are intentionally wanting to move them to a different systemd unit. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
65fb0b79f7
commit
44f79a0bd0
@ -1290,6 +1290,7 @@ virBufferVasprintf;
|
|||||||
|
|
||||||
|
|
||||||
# util/vircgroup.h
|
# util/vircgroup.h
|
||||||
|
virCgroupAddMachineTask;
|
||||||
virCgroupAddTask;
|
virCgroupAddTask;
|
||||||
virCgroupAddTaskController;
|
virCgroupAddTaskController;
|
||||||
virCgroupAllowAllDevices;
|
virCgroupAllowAllDevices;
|
||||||
|
@ -869,12 +869,12 @@ static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl)
|
|||||||
ctrl->nicindexes)))
|
ctrl->nicindexes)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0)
|
if (virCgroupAddMachineTask(ctrl->cgroup, getpid()) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Add all qemu-nbd tasks to the cgroup */
|
/* Add all qemu-nbd tasks to the cgroup */
|
||||||
for (i = 0; i < ctrl->nnbdpids; i++) {
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1184,16 +1184,8 @@ virCgroupNew(pid_t pid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
static int
|
||||||
* virCgroupAddTask:
|
virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -1203,8 +1195,10 @@ virCgroupAddTask(virCgroupPtr group, pid_t pid)
|
|||||||
if (!group->controllers[i].mountPoint)
|
if (!group->controllers[i].mountPoint)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* We must never add tasks in systemd's hierarchy */
|
/* We must never add tasks in systemd's hierarchy
|
||||||
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
|
* unless we're intentionally trying to move a
|
||||||
|
* task into a systemd machine scope */
|
||||||
|
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD && !withSystemd)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (virCgroupAddTaskController(group, pid, i) < 0)
|
if (virCgroupAddTaskController(group, pid, i) < 0)
|
||||||
@ -1216,6 +1210,40 @@ virCgroupAddTask(virCgroupPtr group, pid_t pid)
|
|||||||
return ret;
|
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:
|
* virCgroupAddTaskController:
|
||||||
|
@ -131,6 +131,7 @@ int virCgroupPathOfController(virCgroupPtr group,
|
|||||||
char **path);
|
char **path);
|
||||||
|
|
||||||
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
|
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
|
||||||
|
int virCgroupAddMachineTask(virCgroupPtr group, pid_t pid);
|
||||||
|
|
||||||
int virCgroupAddTaskController(virCgroupPtr group,
|
int virCgroupAddTaskController(virCgroupPtr group,
|
||||||
pid_t pid,
|
pid_t pid,
|
||||||
|
Loading…
Reference in New Issue
Block a user