Commit a2fd8cd0 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

mntns: simplify a case, when a root should be changed

We don't need to clean_mnt_ns(), if we are goning to do pivot_root().

"""
pivot_root moves the root file system of the current process to the
directory put_old and makes new_root the new root file system.
"""

So I suggest to do pivot_root() and then detach the old root, all
other mount points will be unmounted automatically.

This patch fixes a problem, when a new root is mounted above a non-root
mount point. It's a default configuration for OpenVZ.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e3fbb630
......@@ -540,13 +540,6 @@ static int do_umount_one(struct mount_info *mi)
if (!mi->parent)
return 0;
/*
* Don't umount the future root. It can be a mountpoint only,
* otherwise pivot_root() fails.
*/
if (opts.root && !strcmp(opts.root, mi->mountpoint))
return 0;
if (umount(mi->mountpoint)) {
pr_perror("Can't umount at %s", mi->mountpoint);
return -1;
......@@ -582,17 +575,12 @@ static int clean_mnt_ns(void)
return ret;
}
static int populate_mnt_ns(int ns_pid)
static int cr_pivot_root()
{
MntEntry *me = NULL;
int img, ret;
struct mount_info *pms = NULL;
pr_info("Populating mount namespace\n");
if (opts.root) {
char put_root[PATH_MAX] = "crtools-put-root.XXXXXX";
pr_info("Move the root to %s", opts.root);
if (chdir(opts.root)) {
pr_perror("chdir(%s) failed", opts.root);
return -1;
......@@ -615,7 +603,17 @@ static int populate_mnt_ns(int ns_pid)
pr_perror("Can't remove the directory %s", put_root);
return -1;
}
}
return 0;
}
static int populate_mnt_ns(int ns_pid)
{
MntEntry *me = NULL;
int img, ret;
struct mount_info *pms = NULL;
pr_info("Populating mount namespace\n");
img = open_image_ro(CR_FD_MOUNTPOINTS, ns_pid);
if (img < 0)
......@@ -695,7 +693,11 @@ int prepare_mnt_ns(int ns_pid)
* prior to recreating new ones.
*/
ret = clean_mnt_ns();
if (opts.root)
ret = cr_pivot_root();
else
ret = clean_mnt_ns();
if (!ret)
ret = populate_mnt_ns(ns_pid);
......
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