[CRIU] [PATCH 03/12] mounts: allow to customize root path for cr_pivot_root

Andrey Vagin avagin at openvz.org
Fri Jan 10 05:49:57 PST 2014


We are going to restore nested mount namespaces and we will need to
change root for each of them.

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

diff --git a/mount.c b/mount.c
index e21832c..0a83926 100644
--- a/mount.c
+++ b/mount.c
@@ -1265,14 +1265,14 @@ static int premount_external(struct mount_info *mis, char *old_root)
 	return 0;
 }
 
-static int cr_pivot_root(struct mount_info *mis)
+static int cr_pivot_root(char *root, struct mount_info *mis)
 {
 	char put_root[] = "crtools-put-root.XXXXXX";
 
-	pr_info("Move the root to %s\n", opts.root);
+	pr_info("Move the root to %s\n", root);
 
-	if (chdir(opts.root)) {
-		pr_perror("chdir(%s) failed", opts.root);
+	if (chdir(root)) {
+		pr_perror("chdir(%s) failed", root);
 		return -1;
 	}
 	if (mkdtemp(put_root) == NULL) {
@@ -1280,11 +1280,6 @@ static int cr_pivot_root(struct mount_info *mis)
 		return -1;
 	}
 
-	if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
-		pr_perror("Can't remount root with MS_PRIVATE");
-		return -1;
-	}
-
 	if (pivot_root(".", put_root)) {
 		pr_perror("pivot_root(., %s) failed", put_root);
 		if (rmdir(put_root))
@@ -1300,6 +1295,11 @@ static int cr_pivot_root(struct mount_info *mis)
 	if (premount_external(mis, put_root))
 		return -1;
 
+	if (mount("none", put_root, "none", MS_REC|MS_PRIVATE, NULL)) {
+		pr_perror("Can't remount root with MS_PRIVATE");
+		return -1;
+	}
+
 	if (umount2(put_root, MNT_DETACH)) {
 		pr_perror("Can't umount %s", put_root);
 		return -1;
@@ -1468,9 +1468,14 @@ int prepare_mnt_ns(int ns_pid)
 	 * prior to recreating new ones.
 	 */
 
-	if (opts.root)
-		ret = cr_pivot_root(mis);
-	else
+	if (opts.root) {
+		if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
+			pr_perror("Can't remount root with MS_PRIVATE");
+			return -1;
+		}
+
+		ret = cr_pivot_root(opts.root, mis);
+	} else
 		ret = clean_mnt_ns();
 
 	free_mounts();
-- 
1.8.3.1



More information about the CRIU mailing list