提交 4acb01e4 编写于 作者: D Daniel P. Berrange

lxc: delay setup of cgroup until we have the init pid

Don't create the cgroups ahead of launching the container since
there is no need for the limits to apply during initial bootstrap.
Create the cgroup after the container PID is known and tell
systemd the initpid is the leader, instead of the controller
pid.
上级 0a8addc1
...@@ -462,7 +462,8 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def, ...@@ -462,7 +462,8 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
} }
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def) virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
pid_t initpid)
{ {
virCgroupPtr cgroup = NULL; virCgroupPtr cgroup = NULL;
...@@ -473,18 +474,12 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def) ...@@ -473,18 +474,12 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
goto cleanup; goto cleanup;
} }
/*
* XXX
* We should pass the PID of the LXC init process
* not ourselves, but this requires some more
* refactoring. We should also pass the root dir
*/
if (virCgroupNewMachine(def->name, if (virCgroupNewMachine(def->name,
"lxc", "lxc",
true, true,
def->uuid, def->uuid,
NULL, NULL,
getpid(), initpid,
true, true,
0, NULL, 0, NULL,
def->resource->partition, def->resource->partition,
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
# include "lxc_fuse.h" # include "lxc_fuse.h"
# include "virusb.h" # include "virusb.h"
virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def); virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
pid_t initpid);
virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def); virCgroupPtr virLXCCgroupJoin(virDomainDefPtr def);
int virLXCCgroupSetup(virDomainDefPtr def, int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup, virCgroupPtr cgroup,
......
...@@ -680,8 +680,9 @@ static int virLXCControllerGetNumadAdvice(virLXCControllerPtr ctrl, ...@@ -680,8 +680,9 @@ static int virLXCControllerGetNumadAdvice(virLXCControllerPtr ctrl,
* virLXCControllerSetupResourceLimits * virLXCControllerSetupResourceLimits
* @ctrl: the controller state * @ctrl: the controller state
* *
* Creates a cgroup for the container, moves the task inside, * Sets up the non-cgroup based resource limits that need
* and sets resource limits * to be inherited by the child process across clone()/exec().
* The cgroup limits are setup later
* *
* Returns 0 on success or -1 in case of error * Returns 0 on success or -1 in case of error
*/ */
...@@ -704,6 +705,37 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl) ...@@ -704,6 +705,37 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl)
if (virLXCControllerSetupCpuAffinity(ctrl) < 0) if (virLXCControllerSetupCpuAffinity(ctrl) < 0)
goto cleanup; goto cleanup;
ret = 0;
cleanup:
virBitmapFree(auto_nodeset);
return ret;
}
/*
* Creates the cgroup and sets up the various limits associated
* with it
*/
static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl)
{
virBitmapPtr auto_nodeset = NULL;
int ret = -1;
virBitmapPtr nodeset = NULL;
VIR_DEBUG("Setting up cgroup resource limits");
if (virLXCControllerGetNumadAdvice(ctrl, &auto_nodeset) < 0)
goto cleanup;
nodeset = virDomainNumatuneGetNodeset(ctrl->def->numatune, auto_nodeset, -1);
if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
ctrl->initpid)))
goto cleanup;
if (virCgroupAddTask(ctrl->cgroup, getpid()) < 0)
goto cleanup;
if (virLXCCgroupSetup(ctrl->def, ctrl->cgroup, nodeset) < 0) if (virLXCCgroupSetup(ctrl->def, ctrl->cgroup, nodeset) < 0)
goto cleanup; goto cleanup;
...@@ -2224,6 +2256,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl) ...@@ -2224,6 +2256,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
for (i = 0; i < ctrl->npassFDs; i++) for (i = 0; i < ctrl->npassFDs; i++)
VIR_FORCE_CLOSE(ctrl->passFDs[i]); VIR_FORCE_CLOSE(ctrl->passFDs[i]);
if (virLXCControllerSetupCgroupLimits(ctrl) < 0)
goto cleanup;
if (virLXCControllerSetupUserns(ctrl) < 0) if (virLXCControllerSetupUserns(ctrl) < 0)
goto cleanup; goto cleanup;
...@@ -2454,9 +2489,6 @@ int main(int argc, char *argv[]) ...@@ -2454,9 +2489,6 @@ int main(int argc, char *argv[])
if (virLXCControllerValidateConsoles(ctrl) < 0) if (virLXCControllerValidateConsoles(ctrl) < 0)
goto cleanup; goto cleanup;
if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def)))
goto cleanup;
if (virLXCControllerSetupServer(ctrl) < 0) if (virLXCControllerSetupServer(ctrl) < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册