[v2,4/5] mount: migrate bindmounts of external mounts

Submitted by Pavel Tikhomirov on March 2, 2017, 11:32 a.m.

Details

Message ID 20170302113255.28422-1-ptikhomirov@virtuozzo.com
State New
Series "mount: handle external mount bindmounts"
Headers show

Commit Message

Pavel Tikhomirov March 2, 2017, 11:32 a.m.
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

v2: s/external_bind/mnt_is_external/, make mnt_is_external bool,
do mnt_is_external without recursion

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/mount.c | 42 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index a8716c5..5d98280 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -640,6 +640,36 @@  static bool does_mnt_overmount(struct mount_info *m)
 	return false;
 }
 
+/*
+ * Say mount is external if it was explicitly specified as an
+ * external or it will be bind from such an explicit external
+ * mount, we set bind in propagate_mount and propagate_siblings
+ */
+
+static bool mnt_is_external(struct mount_info *m)
+{
+	struct mount_info *t;
+
+	while (m) {
+		if (m->external)
+			return 1;
+
+		if (!list_empty(&m->mnt_share))
+			list_for_each_entry(t, &m->mnt_share, mnt_share)
+				if (t->external)
+					return 1;
+
+		if (m->master_id <= 0 && !list_empty(&m->mnt_bind))
+			list_for_each_entry(t, &m->mnt_bind, mnt_bind)
+				if (issubpath(m->root, t->root) && t->external)
+					return 1;
+
+		m = m->mnt_master;
+	}
+
+	return 0;
+}
+
 static int validate_mounts(struct mount_info *info, bool for_dump)
 {
 	struct mount_info *m, *t;
@@ -652,7 +682,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 (mnt_is_external(m))
 			goto skip_fstype;
 
 		/*
@@ -908,9 +938,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 && !mnt_is_external(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 +1252,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 || mnt_is_external(mi) || !mi->fstype->dump)
 		return 0;
 
 	/* mnt_bind is a cycled list, so list_for_each can't be used here. */
@@ -1634,7 +1664,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 +1672,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;
 		}