[CRIU] [PATCH 4/5] mount: migrate bindmounts of external mounts

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Wed Mar 1 05:17:44 PST 2017


If container has external bindmount given to criu through
--ext-mount-map option by admin, container user can bindmount
subdirs of these external bindmount to somewhere else inside
container creating secondary external binmouns. Criu we will
fail to restore them as having unreachable sharing. But we can
restore secondary external bindmounts bindmounting them from
primary external bindmount.

https://jira.sw.ru/browse/PSBM-46753
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/mount.c | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index bd2497b..22a9c13 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -640,6 +640,35 @@ static bool does_mnt_overmount(struct mount_info *m)
 	return false;
 }
 
+/*
+ * Say we are external_bind if we are external or we
+ * will be bind from external, we set bind in propagate_mount
+ * and propagate_siblings
+ */
+
+static struct mount_info *external_bind(struct mount_info *m) {
+	struct mount_info *t;
+
+	if (m->external)
+		return m;
+
+	if (!list_empty(&m->mnt_share))
+		list_for_each_entry(t, &m->mnt_share, mnt_share)
+			if (t->external)
+				return t;
+
+	if (m->mnt_master)
+		return external_bind(m->mnt_master);
+
+	if (m->master_id > 0)
+		return NULL;
+	if (!list_empty(&m->mnt_bind))
+		list_for_each_entry(t, &m->mnt_bind, mnt_bind)
+			if (issubpath(m->root, t->root) && t->external)
+				return t;
+	return NULL;
+}
+
 static int validate_mounts(struct mount_info *info, bool for_dump)
 {
 	struct mount_info *m, *t;
@@ -652,7 +681,7 @@ static int validate_mounts(struct mount_info *info, bool for_dump)
 		if (m->shared_id && validate_shared(m))
 			return -1;
 
-		if (m->external)
+		if (external_bind(m))
 			goto skip_fstype;
 
 		/*
@@ -908,9 +937,9 @@ static int resolve_shared_mounts(struct mount_info *info, int root_master_id)
 
 		/*
 		 * If we haven't already determined this mount is external,
-		 * then we don't know where it came from.
+		 * or bind of external, then we don't know where it came from.
 		 */
-		if (need_master && m->parent && !m->external) {
+		if (need_master && m->parent && !external_bind(m)) {
 			pr_err("Mount %d %s (master_id: %d shared_id: %d) "
 			       "has unreachable sharing. Try --enable-external-masters.\n", m->mnt_id,
 				m->mountpoint, m->master_id, m->shared_id);
@@ -1222,7 +1251,7 @@ static int dump_one_fs(struct mount_info *mi)
 	struct mount_info *t;
 	bool first = true;
 
-	if (mi->is_ns_root || mi->need_plugin || mi->external || !mi->fstype->dump)
+	if (mi->is_ns_root || mi->need_plugin || external_bind(mi) || !mi->fstype->dump)
 		return 0;
 
 	/* mnt_bind is a cycled list, so list_for_each can't be used here. */
@@ -1634,7 +1663,7 @@ static int propagate_mount(struct mount_info *mi)
 	 * FIXME Currently non-root mounts can be restored
 	 * only if a proper root mount exists
 	 */
-	if (fsroot_mounted(mi) || mi->parent == root_yard_mp) {
+	if (fsroot_mounted(mi) || mi->parent == root_yard_mp || mi->external) {
 		list_for_each_entry(t, &mi->mnt_bind, mnt_bind) {
 			if (t->mounted)
 				continue;
@@ -1642,6 +1671,8 @@ static int propagate_mount(struct mount_info *mi)
 				continue;
 			if (t->master_id > 0)
 				continue;
+			if (!issubpath(t->root, mi->root))
+				continue;
 			t->bind = mi;
 			t->s_dev_rt = mi->s_dev_rt;
 		}
-- 
2.9.3



More information about the CRIU mailing list