[Devel,criu] mount: clone a mount namespace to open a detached mount

Submitted by Andrei Vagin on Dec. 12, 2016, 11:17 p.m.

Details

Message ID 1481584663-26338-1-git-send-email-avagin@openvz.org
State New
Series "mount: clone a mount namespace to open a detached mount"
Headers show

Commit Message

Andrei Vagin Dec. 12, 2016, 11:17 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

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
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/mount.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index d889732..50c5b79 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1123,10 +1123,22 @@  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.
+		 */
+		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;