[CRIU] [PATCH 2/2] mount: fix mounting non-root shared mounts

Andrei Vagin avagin at openvz.org
Mon Nov 21 21:36:15 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

The widest mount of a shared group has to be mounted first and
then other mounts has to be bind-mounted from the first one to
inherite its group.

This patch adds a check in can_mount_now() to mount the widest group
mount first and sets it as a source mount for other members.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/mount.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index d80ae59..7967404 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1564,11 +1564,15 @@ static int propagate_siblings(struct mount_info *mi)
 
 	/*
 	 * Find all mounts, which must be bind-mounted from this one
-	 * to inherite shared group or master id
+	 * to inherite shared group or master id.
+	 *
+	 * This work has to be done only once per group.
 	 */
 	list_for_each_entry(t, &mi->mnt_share, mnt_share) {
-		if (t->mounted || t->bind)
-			continue;
+		if (t->mounted)
+			break;
+		if (t->bind && t->bind->shared_id == mi->shared_id)
+			break;
 		pr_debug("\t\tBind share %s\n", t->mountpoint);
 		t->bind = mi;
 		t->s_dev_rt = mi->s_dev_rt;
@@ -1576,7 +1580,7 @@ static int propagate_siblings(struct mount_info *mi)
 
 	list_for_each_entry(t, &mi->mnt_slave_list, mnt_slave) {
 		if (t->mounted || t->bind)
-			continue;
+			break;
 		pr_debug("\t\tBind slave %s\n", t->mountpoint);
 		t->bind = mi;
 		t->s_dev_rt = mi->s_dev_rt;
@@ -2042,6 +2046,16 @@ static bool can_mount_now(struct mount_info *mi)
 	if (!fsroot_mounted(mi) && (mi->bind == NULL && !mi->need_plugin && !mi->external))
 		return false;
 
+	if (mi->bind && mi->shared_id != mi->bind->shared_id) {
+		struct mount_info *n;
+		int len;
+
+		len = strlen(mi->root);
+		list_for_each_entry(n, &mi->mnt_share, mnt_share)
+			if (len > strlen(n->root))
+				return false;
+	}
+
 shared:
 	if (mi->parent->shared_id) {
 		struct mount_info *p = mi->parent, *n;
-- 
2.7.4



More information about the CRIU mailing list