[CRIU] [PATCH 1/9] Revert "mount: don't create a temporary directory for pivot_root()"

Andrey Vagin avagin at openvz.org
Thu Oct 23 06:48:59 PDT 2014


This reverts commit 21d1b2fdb97facf88436d083896311367e4398af.

pivot_root() can move the current root to a non-shared mount. So we are
going to create a temporary private mount in put_old.

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

diff --git a/mount.c b/mount.c
index e915025..89eb160 100644
--- a/mount.c
+++ b/mount.c
@@ -1464,7 +1464,7 @@ static int clean_mnt_ns(struct mount_info *mntinfo_tree)
 
 static int cr_pivot_root(char *root)
 {
-	int old_root;
+	char put_root[] = "crtools-put-root.XXXXXX";
 
 	pr_info("Move the root to %s\n", root ? : ".");
 
@@ -1475,36 +1475,34 @@ static int cr_pivot_root(char *root)
 		}
 	}
 
-	old_root = open("/", O_DIRECTORY | O_RDONLY);
-	if (old_root < 0) {
-		pr_perror("Unable to open /");
+	if (mkdtemp(put_root) == NULL) {
+		pr_perror("Can't create a temporary directory");
 		return -1;
 	}
 
-	if (pivot_root(".", ".")) {
-		close(old_root);
-		pr_perror("pivot_root(., .) failed");
+	if (pivot_root(".", put_root)) {
+		pr_perror("pivot_root(., %s) failed", put_root);
+		if (rmdir(put_root))
+			pr_perror("Can't remove the directory %s", put_root);
 		return -1;
 	}
 
-	if (fchdir(old_root)) {
-		perror("Unable to change working directory");
+	if (mount("none", put_root, "none", MS_REC|MS_PRIVATE, NULL)) {
+		pr_perror("Can't remount root with MS_PRIVATE");
 		return -1;
 	}
-	close(old_root);
 
-	if (mount("none", ".", "none", MS_REC|MS_PRIVATE, NULL)) {
+	if (mount("none", put_root, "none", MS_REC|MS_PRIVATE, NULL)) {
 		pr_perror("Can't remount root with MS_PRIVATE");
 		return -1;
 	}
 
-	if (umount2(".", MNT_DETACH)) {
-		pr_perror("Can't umount the old root");
+	if (umount2(put_root, MNT_DETACH)) {
+		pr_perror("Can't umount %s", put_root);
 		return -1;
 	}
-
-	if (chdir("/")) {
-		perror("Unable to change working directory");
+	if (rmdir(put_root)) {
+		pr_perror("Can't remove the directory %s", put_root);
 		return -1;
 	}
 
-- 
1.9.3



More information about the CRIU mailing list