Commit 16d3fdef authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

cgroup: fix --cgroup-root and cgns interaction

Basically, instead of --cgroup-root replacing the actual root, when a cgns
is present, it just replaces the namespace prefix. See patch comments for
details.
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent a24e37d6
...@@ -1491,26 +1491,63 @@ err: ...@@ -1491,26 +1491,63 @@ err:
} }
static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers, static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers,
char *from, char *to) char **from, char *to)
{ {
int i, j; int i, j;
bool set_from = false;
for (i = 0; i < cge->n_sets; i++) { for (i = 0; i < cge->n_sets; i++) {
CgSetEntry *set = cge->sets[i]; CgSetEntry *set = cge->sets[i];
for (j = 0; j < set->n_ctls; j++) { for (j = 0; j < set->n_ctls; j++) {
CgMemberEntry *cg = set->ctls[j]; CgMemberEntry *cg = set->ctls[j];
if (cgroup_contains(controllers, n_controllers, cg->name) && char *tmp = cg->path, *tmp2 = NULL;
/* +1 to get rid of leading / */
strstartswith(cg->path + 1, from)) {
char *tmp = cg->path; if (!(cgroup_contains(controllers, n_controllers, cg->name) &&
/* +1 to get rid of leading / */
strstartswith(cg->path + 1, *from)))
continue;
/* If this cgset has a cgns prefix, let's use
* that as the start of the root replacement.
*/
if (cg->has_cgns_prefix && cg->cgns_prefix) {
/* Rewrite the group dir to match the
* prefix. We can do this exactly once
* since we know all the tasks are in
* the same cgroup ns (and thus have
* the same per-controller prefix path)
* since we don't support nesting.
*/
if (!set_from) {
set_from = true;
/* -2 because cgns_prefix includes leading and trailing /'s */
*from = xsprintf("%s%s", to, (*from) + cg->cgns_prefix - 2);
}
/* +1 to get rid of leading /, again */
cg->path = xsprintf("%s%s", to, cg->path + cg->path = xsprintf("%s%s", to, cg->path +
strlen(from) + 1); cg->cgns_prefix - 1);
if (!cg->path) cg->cgns_prefix = strlen(to);
} else {
/* otherwise, use the old rewriting strategy */
cg->path = xsprintf("%s%s", to, cg->path +
strlen(*from) + 1);
if (!set_from) {
set_from = true;
*from = xstrdup(to);
}
}
if (tmp2) {
if (!*from)
return -1; return -1;
free(tmp);
xfree(tmp2);
} }
if (!cg->path)
return -1;
free(tmp);
} }
} }
...@@ -1538,18 +1575,10 @@ static int rewrite_cgroup_roots(CgroupEntry *cge) ...@@ -1538,18 +1575,10 @@ static int rewrite_cgroup_roots(CgroupEntry *cge)
if (newroot) { if (newroot) {
for (j = 0; j < ctrl->n_dirs; j++) { for (j = 0; j < ctrl->n_dirs; j++) {
CgroupDirEntry *cgde = ctrl->dirs[j]; CgroupDirEntry *cgde = ctrl->dirs[j];
char *m;
pr_info("rewriting %s to %s\n", cgde->dir_name, newroot); pr_info("rewriting %s to %s\n", cgde->dir_name, newroot);
if (rewrite_cgsets(cge, ctrl->cnames, ctrl->n_cnames, cgde->dir_name, newroot)) if (rewrite_cgsets(cge, ctrl->cnames, ctrl->n_cnames, &cgde->dir_name, newroot))
return -1;
m = xstrdup(newroot);
if (!m)
return -1; return -1;
free(cgde->dir_name);
cgde->dir_name = m;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment