[CRIU] [PATCH 1/2] mount: don't create a temporary directory if /tmp exists

Andrei Vagin avagin at openvz.org
Mon Aug 8 17:23:00 PDT 2016


From: Andrei Vagin <avagin at virtuozzo.com>

pivot_root requires a place to move an old root. Currently
a temporary directory is created for that, but it doesn't
work if the / directory is read-only.

Actually we can use any existing directory. In this patch,
criu tries to use /tmp and only if it doesn't exist,
criu creates a temporary directory.

https://bugs.openvz.org/browse/OVZ-6778
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/mount.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index f90ec69..6f42d32 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2702,8 +2702,10 @@ static int do_umount_one(struct mount_info *mi)
 
 static int cr_pivot_root(char *root)
 {
-	char put_root[] = "crtools-put-root.XXXXXX";
+	char *put_root = "tmp";
 	int exit_code = -1;
+	struct stat st;
+	bool tmp_dir = false;
 
 	pr_info("Move the root to %s\n", root ? : ".");
 
@@ -2714,9 +2716,13 @@ static int cr_pivot_root(char *root)
 		}
 	}
 
-	if (mkdtemp(put_root) == NULL) {
-		pr_perror("Can't create a temporary directory");
-		return -1;
+	if (stat(put_root, &st) || !S_ISDIR(st.st_mode)) {
+		put_root = "crtools-put-root.XXXXXX";
+		if (mkdtemp(put_root) == NULL) {
+			pr_perror("Can't create a temporary directory");
+			return -1;
+		}
+		tmp_dir = true;
 	}
 
 	if (mount(put_root, put_root, NULL, MS_BIND, NULL)) {
@@ -2753,7 +2759,7 @@ err_tmpfs:
 	}
 
 err_root:
-	if (rmdir(put_root)) {
+	if (tmp_dir && rmdir(put_root)) {
 		pr_perror("Can't remove the directory %s", put_root);
 		return -1;
 	}
-- 
2.7.4



More information about the CRIU mailing list