[CRIU] [PATCH 01/11] mount: rework perparation for pivot_root

Andrey Vagin avagin at openvz.org
Wed Aug 13 00:51:28 PDT 2014


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

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/mount.c b/mount.c
index e0e88ea..e25337b 100644
--- a/mount.c
+++ b/mount.c
@@ -1942,27 +1942,16 @@ 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);
+		if (mount("none", opts.root, "none", MS_SLAVE, NULL)) {
+			pr_perror("Can't remount the parent of the new root with MS_SLAVE");
 			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");
-			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