mount: allow to dump and restore nested mount namespaces (v3)

v2: another attempt to write readable code:)
v3: clean up
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrey Vagin 2014-04-21 18:23:21 +04:00 committed by Pavel Emelyanov
parent 3a291e33ff
commit 4067f4bb7e
3 changed files with 18 additions and 9 deletions

View file

@ -59,6 +59,9 @@ struct itimerspec;
#define CLONE_ALLNS (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS)
/* Nested namespaces are supported only for these types */
#define CLONE_SUBNS (CLONE_NEWNS)
#define setns sys_setns
struct rlimit;

View file

@ -182,7 +182,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
BUG_ON(current_ns_mask & nd->cflag);
pr_info("Will take %s namespace in the image\n", nd->str);
current_ns_mask |= nd->cflag;
} else {
} else if (nd->cflag & ~CLONE_SUBNS) {
pr_err("Can't dump nested %s namespace for %d\n",
nd->str, pid);
return 0;

View file

@ -663,16 +663,22 @@ static int prepare_pstree_kobj_ids(void)
set_mask:
item->rst->clone_flags = cflags;
/*
* Workaround for current namespaces model --
* all tasks should be in one namespace. And
* this namespace is either inherited from the
* criu or is created for the init task (only)
*/
cflags &= CLONE_ALLNS;
if (item == root_item) {
pr_info("Will restore in %lx namespaces\n", cflags);
current_ns_mask = cflags & CLONE_ALLNS;
} else if (cflags & CLONE_ALLNS) {
current_ns_mask = cflags;
} else if (cflags & ~(current_ns_mask & CLONE_SUBNS)) {
/*
* Namespaces from CLONE_SUBNS can be nested, but in
* this case nobody can't share external namespaces of
* these types.
*
* Workaround for all other namespaces --
* all tasks should be in one namespace. And
* this namespace is either inherited from the
* criu or is created for the init task (only)
*/
pr_err("Can't restore sub-task in NS\n");
return -1;
}