From 8a8a9862071bb9042bb9d58cd9c9bbac20a9c904 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 7 Feb 2017 11:43:30 +0300 Subject: [PATCH] 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 Signed-off-by: Andrei Vagin --- criu/mount.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/criu/mount.c b/criu/mount.c index cbbc15444d..8f66b4e098 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -1091,10 +1091,23 @@ int open_mountpoint(struct mount_info *pm) goto out; mnt_path = get_clean_mnt(pm, mnt_path_tmp, mnt_path_root); - if (mnt_path == NULL) - goto out; + 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; + } - fd = open_detach_mount(mnt_path); + 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); if (fd < 0) goto out;