[CRIU] [PATCH 12/13] mount: allow to dump and restore nested mount namespaces

Andrey Vagin avagin at openvz.org
Tue Mar 11 08:18:28 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 namespaces.c |  2 +-
 pstree.c     | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/namespaces.c b/namespaces.c
index f45e088..b8036a3 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -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_NEWNS) {
 			pr_err("Can't dump nested %s namespace for %d\n",
 					nd->str, pid);
 			return 0;
diff --git a/pstree.c b/pstree.c
index f2f3fc7..aac29c7 100644
--- a/pstree.c
+++ b/pstree.c
@@ -635,19 +635,30 @@ static int prepare_pstree_kobj_ids(void)
 set_mask:
 		item->rst->clone_flags = cflags;
 
+		if (item == root_item) {
+			pr_info("Will restore in %lx namespaces\n", cflags);
+			current_ns_mask = cflags & CLONE_ALLNS;
+			continue;
+		}
+
+		/*
+		 * Nested mount namespaces are supported only
+		 * nobody shares external mntns.
+		 */
+		if (cflags & current_ns_mask & CLONE_NEWNS)
+			cflags &= ~CLONE_NEWNS;
+
 		/*
 		 * 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)
 		 */
-		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");
-			return -1;
-		}
+		if (cflags & CLONE_ALLNS == 0)
+			continue;
+
+		pr_err("Can't restore sub-task in NS\n");
+		return -1;
 	}
 
 	pr_debug("NS mask to use %lx\n", current_ns_mask);
-- 
1.8.5.3



More information about the CRIU mailing list