[CRIU] [PATCH 08/13] mounts: bind mount one root for all namespaces

Andrey Vagin avagin at openvz.org
Tue Mar 11 08:18:24 PDT 2014


Currently we support nested mount namespaces, only if all of them have
the same root.

crtools doesn't mount root, so it should be bind-mounted for all
namespaces.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/mount.c b/mount.c
index 22df8e9..a1e1748 100644
--- a/mount.c
+++ b/mount.c
@@ -239,6 +239,12 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list)
 					m->mnt_id, m->parent_mnt_id, m->mountpoint,
 					root ? "found" : "not found");
 			if (root && m->is_root) {
+				if (!mounts_equal(root, m, true) ||
+					(strcmp(root->root, m->root))) {
+					pr_err("Nested mount namespaces with different roots are not supported yet");
+					return NULL;
+				}
+
 				/*
 				 * A root of a sub mount namespace is
 				 * mounted in a temporary directory in the
@@ -1011,6 +1017,10 @@ static int propagate_mount(struct mount_info *mi)
 	struct mount_info *t;
 
 	propagate_siblings(mi);
+
+	if (mi->parent == NULL)
+		goto skip;
+
 	umount_from_slaves(mi);
 
 	/* Propagate this mount to everyone from a parent group */
@@ -1028,11 +1038,13 @@ static int propagate_mount(struct mount_info *mi)
 		}
 	}
 
+skip:
 	/*
 	 * FIXME Currently non-root mounts can be restored
-	 * only if a proper root mount exists
+	 * only if a proper root mount exists.
+	 * Here is one exception for sub-roots. Roots of all mntns are the same.
 	 */
-	if (fsroot_mounted(mi))
+	if (mi->parent == NULL || fsroot_mounted(mi))
 		list_for_each_entry(t, &mi->mnt_bind, mnt_bind) {
 			if (t->bind)
 				continue;
@@ -1154,8 +1166,11 @@ static int do_mount_one(struct mount_info *mi)
 {
 	int ret;
 
-	if (!mi->parent)
-		return 0;
+	if (!mi->parent) {
+		mi->mounted = true;
+		ret = restore_shared_options(mi, 0, mi->shared_id, 0);
+		goto propagate;
+	}
 
 	if (mi->mounted)
 		return 0;
@@ -1172,6 +1187,7 @@ static int do_mount_one(struct mount_info *mi)
 	else
 		ret = do_bind_mount(mi);
 
+propagate:
 	if (ret == 0 && propagate_mount(mi))
 		return -1;
 
-- 
1.8.5.3



More information about the CRIU mailing list