Commit 0661a8a4 authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

mount: don't create a temporary directory if /tmp exists

pivot_root requires a place where 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

v2: don't give a constant string to mkdtemp
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 043fd0ee
...@@ -2702,8 +2702,11 @@ static int do_umount_one(struct mount_info *mi) ...@@ -2702,8 +2702,11 @@ static int do_umount_one(struct mount_info *mi)
static int cr_pivot_root(char *root) static int cr_pivot_root(char *root)
{ {
char put_root[] = "crtools-put-root.XXXXXX"; char tmp_dir_tmpl[] = "crtools-put-root.XXXXXX";
bool tmp_dir = false;
char *put_root = "tmp";
int exit_code = -1; int exit_code = -1;
struct stat st;
pr_info("Move the root to %s\n", root ? : "."); pr_info("Move the root to %s\n", root ? : ".");
...@@ -2714,9 +2717,13 @@ static int cr_pivot_root(char *root) ...@@ -2714,9 +2717,13 @@ static int cr_pivot_root(char *root)
} }
} }
if (mkdtemp(put_root) == NULL) { if (stat(put_root, &st) || !S_ISDIR(st.st_mode)) {
pr_perror("Can't create a temporary directory"); put_root = mkdtemp(tmp_dir_tmpl);
return -1; if (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)) { if (mount(put_root, put_root, NULL, MS_BIND, NULL)) {
...@@ -2753,7 +2760,7 @@ err_tmpfs: ...@@ -2753,7 +2760,7 @@ err_tmpfs:
} }
err_root: err_root:
if (rmdir(put_root)) { if (tmp_dir && rmdir(put_root)) {
pr_perror("Can't remove the directory %s", put_root); pr_perror("Can't remove the directory %s", put_root);
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment