[CRIU] [PATCH 4/6] unshare: Support mntns

Pavel Emelyanov xemul at parallels.com
Wed Dec 9 04:00:45 PST 2015


When asked for --unshare mnt the result should be as if we restore
into mount namespace from image, but instead of reading mount points
from image, inherit them from parent (criu).

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 crtools.c |  2 +-
 mount.c   | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/crtools.c b/crtools.c
index bca7471..a1a316f 100644
--- a/crtools.c
+++ b/crtools.c
@@ -130,7 +130,7 @@ static int parse_unshare_arg(char *opt)
 	}
 
 	/* Only pid, mnt and user for now */
-	if (opts.unshare_flags) {
+	if (opts.unshare_flags & ~(CLONE_NEWNS)) {
 		pr_err("Unsharing this namespace(s) is not supported yet\n");
 		return -1;
 	}
diff --git a/mount.c b/mount.c
index 7d45765..8ebca94 100644
--- a/mount.c
+++ b/mount.c
@@ -3093,6 +3093,28 @@ int prepare_mnt_ns(void)
 
 	pr_info("Restoring mount namespace\n");
 
+	if (opts.unshare_flags & CLONE_NEWNS) {
+		if (opts.root) {
+			pr_err("The --root option is incompatible with fake new mntns\n");
+			return -1;
+		}
+
+		/*
+		 * Fake newns preparation -- just copy the existing one
+		 * and go on with the rest.
+		 */
+		if (rst_collect_local_mntns(NS_ROOT))
+			return -1;
+
+		ret = chdir("/");
+		if (ret) {
+			pr_perror("chdir to new root failed");
+			return -1;
+		}
+
+		goto ns_created;
+	}
+
 	old = collect_mntinfo(&ns, false);
 	if (old == NULL)
 		return -1;
@@ -3162,6 +3184,7 @@ int prepare_mnt_ns(void)
 	if (!ret && opts.root)
 		ret = cr_pivot_root(NULL);
 
+ns_created:
 	rst = open_proc(PROC_SELF, "ns/mnt");
 	if (rst < 0)
 		return -1;
-- 
1.9.3




More information about the CRIU mailing list