Setup LXC cgroups in two phases

Currently the LXC controller creates the cgroup, configures the
resources and adds the task all in one go. This is not sufficiently
flexible for the forthcoming NBD integration. We need to make sure
the NBD process gets into the right cgroup immediately, but we can
not have limits (in particular the device ACL) applied at the point
where we start qemu-nbd. So create a virLXCCgroupCreate method
which creates the cgroup and adds the current task to be called
early, and leave virLXCCgroupSetup to only do resource config.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-03-14 12:47:28 +00:00
parent ebf78be4c2
commit 1760258cc3
3 changed files with 39 additions and 16 deletions

View File

@ -472,7 +472,7 @@ cleanup:
} }
int virLXCCgroupSetup(virDomainDefPtr def) virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
{ {
virCgroupPtr driver = NULL; virCgroupPtr driver = NULL;
virCgroupPtr cgroup = NULL; virCgroupPtr cgroup = NULL;
@ -494,6 +494,32 @@ int virLXCCgroupSetup(virDomainDefPtr def)
goto cleanup; goto cleanup;
} }
rc = virCgroupAddTask(cgroup, getpid());
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to add task %d to cgroup for domain %s"),
getpid(), def->name);
goto cleanup;
}
ret = 0;
cleanup:
virCgroupFree(&driver);
if (ret < 0) {
virCgroupFree(&cgroup);
return NULL;
}
return cgroup;
}
int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup)
{
int ret = -1;
if (virLXCCgroupSetupCpuTune(def, cgroup) < 0) if (virLXCCgroupSetupCpuTune(def, cgroup) < 0)
goto cleanup; goto cleanup;
@ -506,19 +532,8 @@ int virLXCCgroupSetup(virDomainDefPtr def)
if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0) if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0)
goto cleanup; goto cleanup;
rc = virCgroupAddTask(cgroup, getpid());
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to add task %d to cgroup for domain %s"),
getpid(), def->name);
goto cleanup;
}
ret = 0; ret = 0;
cleanup: cleanup:
virCgroupFree(&cgroup);
virCgroupFree(&driver);
return ret; return ret;
} }

View File

@ -26,7 +26,9 @@
# include "lxc_fuse.h" # include "lxc_fuse.h"
# include "virusb.h" # include "virusb.h"
int virLXCCgroupSetup(virDomainDefPtr def); virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def);
int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup);
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo); int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo);
int int

View File

@ -628,7 +628,8 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
* *
* Returns 0 on success or -1 in case of error * Returns 0 on success or -1 in case of error
*/ */
static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl) static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl,
virCgroupPtr cgroup)
{ {
if (virLXCControllerSetupCpuAffinity(ctrl) < 0) if (virLXCControllerSetupCpuAffinity(ctrl) < 0)
@ -637,7 +638,7 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl)
if (virLXCControllerSetupNUMAPolicy(ctrl) < 0) if (virLXCControllerSetupNUMAPolicy(ctrl) < 0)
return -1; return -1;
return virLXCCgroupSetup(ctrl->def); return virLXCCgroupSetup(ctrl->def, cgroup);
} }
@ -1473,6 +1474,7 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
int containerhandshake[2] = { -1, -1 }; int containerhandshake[2] = { -1, -1 };
char **containerTTYPaths = NULL; char **containerTTYPaths = NULL;
size_t i; size_t i;
virCgroupPtr cgroup = NULL;
if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) { if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) {
virReportOOMError(); virReportOOMError();
@ -1494,10 +1496,13 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
if (virLXCControllerSetupPrivateNS() < 0) if (virLXCControllerSetupPrivateNS() < 0)
goto cleanup; goto cleanup;
if (!(cgroup = virLXCCgroupCreate(ctrl->def)))
goto cleanup;
if (virLXCControllerSetupLoopDevices(ctrl) < 0) if (virLXCControllerSetupLoopDevices(ctrl) < 0)
goto cleanup; goto cleanup;
if (virLXCControllerSetupResourceLimits(ctrl) < 0) if (virLXCControllerSetupResourceLimits(ctrl, cgroup) < 0)
goto cleanup; goto cleanup;
if (virLXCControllerSetupDevPTS(ctrl) < 0) if (virLXCControllerSetupDevPTS(ctrl) < 0)
@ -1570,6 +1575,7 @@ cleanup:
VIR_FREE(containerTTYPaths[i]); VIR_FREE(containerTTYPaths[i]);
VIR_FREE(containerTTYPaths); VIR_FREE(containerTTYPaths);
virCgroupFree(&cgroup);
virLXCControllerStopInit(ctrl); virLXCControllerStopInit(ctrl);
return rc; return rc;