[CRIU] [PATCH] mount: rework perparation for pivot_root (v2)

Andrey Vagin avagin at openvz.org
Fri Sep 12 06:17:03 PDT 2014


We can't bind-mount the required root into itself instead of
resolving a parent mount.

This patch is required to support userns, because if we want to make
pivot_root, the parent mount can't be locked. When we create userns
and mntns, all inherited mounts are marked as locked.

v2: don't change properties of the given root

Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/mount.c b/mount.c
index 8565856..d45a67d 100644
--- a/mount.c
+++ b/mount.c
@@ -1935,27 +1935,24 @@ int prepare_mnt_ns(void)
 		if (clean_mnt_ns(ns.mnt.mntinfo_tree))
 			return -1;
 	} else {
-		struct mount_info *mi;
-
-		/* moving a mount residing under a shared mount is invalid. */
-		mi = mount_resolve_path(ns.mnt.mntinfo_tree, opts.root);
-		if (mi == NULL) {
-			pr_err("Unable to find mount point for %s\n", opts.root);
+		char buf[] = "/proc/self/fd/XXXXXXXXXX";
+		int fd;
+		fd = open(opts.root, O_DIRECTORY | O_PATH);
+		if (fd < 0) {
+			pr_perror("Unable to open %s", opts.root);
 			return -1;
 		}
-		if (mi->parent == NULL) {
-			pr_err("New root and old root are the same\n");
+		if (mount(opts.root, opts.root, NULL, MS_BIND, NULL)) {
+			pr_perror("Unable to bind-mount %s", opts.root);
 			return -1;
 		}
-
-		/* Our root is mounted over the parent (in the same directory) */
-		if (!strcmp(mi->parent->mountpoint, mi->mountpoint)) {
-			pr_err("The parent of the new root is unreachable\n");
+		snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
+		if (mount("none", buf, "none", MS_SLAVE, NULL)) {
+			pr_perror("Can't remount the parent of the new root with MS_SLAVE");
 			return -1;
 		}
-
-		if (mount("none", mi->parent->mountpoint + 1, "none", MS_SLAVE, NULL)) {
-			pr_perror("Can't remount the parent of the new root with MS_SLAVE");
+		if (chdir(opts.root)) {
+			pr_perror("chdir(%s) failed", opts.root);
 			return -1;
 		}
 	}
-- 
1.9.3



More information about the CRIU mailing list