Commit 0989d3fd authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

mounts: allow to customize root path for cr_pivot_root (v2)

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

v2: don't call chdir in a second time, because a path may be relative
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d738cf3e
...@@ -1281,11 +1281,18 @@ static int clean_mnt_ns(void) ...@@ -1281,11 +1281,18 @@ static int clean_mnt_ns(void)
return mnt_tree_for_each_reverse(mntinfo_tree, do_umount_one); return mnt_tree_for_each_reverse(mntinfo_tree, do_umount_one);
} }
static int cr_pivot_root(void) static int cr_pivot_root(char *root)
{ {
char put_root[] = "crtools-put-root.XXXXXX"; 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 (root) {
if (chdir(root)) {
pr_perror("chdir(%s) failed", root);
return -1;
}
}
if (mkdtemp(put_root) == NULL) { if (mkdtemp(put_root) == NULL) {
pr_perror("Can't create a temporary directory"); pr_perror("Can't create a temporary directory");
...@@ -1304,6 +1311,11 @@ static int cr_pivot_root(void) ...@@ -1304,6 +1311,11 @@ static int cr_pivot_root(void)
return -1; 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)) { if (umount2(put_root, MNT_DETACH)) {
pr_perror("Can't umount %s", put_root); pr_perror("Can't umount %s", put_root);
return -1; return -1;
...@@ -1523,7 +1535,7 @@ int prepare_mnt_ns(int ns_pid) ...@@ -1523,7 +1535,7 @@ int prepare_mnt_ns(int ns_pid)
goto out; goto out;
if (opts.root) if (opts.root)
ret = cr_pivot_root(); ret = cr_pivot_root(NULL);
out: out:
return ret; return ret;
} }
......
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