Commit 4067f4bb authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

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

v2: another attempt to write readable code:)
v3: clean up
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 3a291e33
...@@ -59,6 +59,9 @@ struct itimerspec; ...@@ -59,6 +59,9 @@ struct itimerspec;
#define CLONE_ALLNS (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS) #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 #define setns sys_setns
struct rlimit; struct rlimit;
......
...@@ -182,7 +182,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd ...@@ -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); BUG_ON(current_ns_mask & nd->cflag);
pr_info("Will take %s namespace in the image\n", nd->str); pr_info("Will take %s namespace in the image\n", nd->str);
current_ns_mask |= nd->cflag; current_ns_mask |= nd->cflag;
} else { } else if (nd->cflag & ~CLONE_SUBNS) {
pr_err("Can't dump nested %s namespace for %d\n", pr_err("Can't dump nested %s namespace for %d\n",
nd->str, pid); nd->str, pid);
return 0; return 0;
......
...@@ -663,16 +663,22 @@ static int prepare_pstree_kobj_ids(void) ...@@ -663,16 +663,22 @@ static int prepare_pstree_kobj_ids(void)
set_mask: set_mask:
item->rst->clone_flags = cflags; item->rst->clone_flags = cflags;
cflags &= CLONE_ALLNS;
if (item == root_item) {
pr_info("Will restore in %lx namespaces\n", cflags);
current_ns_mask = cflags;
} else if (cflags & ~(current_ns_mask & CLONE_SUBNS)) {
/* /*
* Workaround for current namespaces model -- * 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 * all tasks should be in one namespace. And
* this namespace is either inherited from the * this namespace is either inherited from the
* criu or is created for the init task (only) * criu or is created for the init task (only)
*/ */
if (item == root_item) {
pr_info("Will restore in %lx namespaces\n", cflags);
current_ns_mask = cflags & CLONE_ALLNS;
} else if (cflags & CLONE_ALLNS) {
pr_err("Can't restore sub-task in NS\n"); pr_err("Can't restore sub-task in NS\n");
return -1; return -1;
} }
......
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