Commit f830e0ff authored by Andrei Vagin's avatar Andrei Vagin

mount: clone a mount namespace to open a detached mount

If we can't create a temporary directory for a detached mount,
we can clone a whole mount namespace, open a mount and release
the created namespace. The result will be the same.

https://jira.sw.ru/browse/PSBM-57135
https://github.com/opencontainers/runc/issues/1202
travis-ci: success for A few fixes to c/r a docker container with a console (rev3)
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 3cedb618
...@@ -1091,9 +1091,22 @@ int open_mountpoint(struct mount_info *pm) ...@@ -1091,9 +1091,22 @@ int open_mountpoint(struct mount_info *pm)
goto out; goto out;
mnt_path = get_clean_mnt(pm, mnt_path_tmp, mnt_path_root); mnt_path = get_clean_mnt(pm, mnt_path_tmp, mnt_path_root);
if (mnt_path == NULL) if (mnt_path == NULL) {
/*
* We probably can't create a temporary direcotry,
* so we can try to clone the mount namespace, open
* the required mount and destroy this mount namespace
* by calling restore_ns() below in this function.
*/
if (unshare(CLONE_NEWNS)) {
pr_perror("Unable to clone a mount namespace");
goto out; goto out;
}
fd = open(pm->mountpoint, O_RDONLY | O_DIRECTORY, 0);
if (fd < 0)
pr_perror("Can't open directory %s: %d", pm->mountpoint, fd);
} else
fd = open_detach_mount(mnt_path); fd = open_detach_mount(mnt_path);
if (fd < 0) if (fd < 0)
goto out; goto out;
......
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