[CRIU] [PATCH 01/11] mount: link dependent mounts (v2)

Andrey Vagin avagin at openvz.org
Tue Jul 30 12:25:26 EDT 2013


All shared mounts from one group are connected to circular list.
All slave are added into the proper master list.

v2: change variable name and fix a bug about adding shared mounts in a
circular list.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/proc_parse.h |  5 ++++
 mount.c              | 84 ++++++++++++++++++++++++++++++----------------------
 2 files changed, 54 insertions(+), 35 deletions(-)

diff --git a/include/proc_parse.h b/include/proc_parse.h
index 8c2c36e..99255c4 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -116,6 +116,11 @@ struct mount_info {
 	struct mount_info *parent;
 	struct list_head children;
 	struct list_head siblings;
+
+	struct list_head mnt_share;	/* circular list of shared mounts */
+	struct list_head mnt_slave_list;/* list of slave mounts */
+	struct list_head mnt_slave;	/* slave list entry */
+	struct mount_info *mnt_master;	/* slave is on master->mnt_slave_list */
 };
 
 struct proc_posix_timer {
diff --git a/mount.c b/mount.c
index 58ecf21..81cafe1 100644
--- a/mount.c
+++ b/mount.c
@@ -178,6 +178,51 @@ static void mnt_tree_show(struct mount_info *tree, int off)
 	pr_info("%*s<--\n", off, "");
 }
 
+static int collect_shared(struct mount_info *info)
+{
+	struct mount_info *m, *t;
+
+	/*
+	 * If we have a shared mounts, both master
+	 * slave targets are to be present in mount
+	 * list, otherwise we can't be sure if we can
+	 * recreate the scheme later on restore.
+	 */
+	for (m = info; m; m = m->next) {
+		bool need_share, need_master;
+
+		need_share = m->shared_id && list_empty(&m->mnt_share);
+		need_master = m->master_id;
+
+		for (t = info; t && (need_share || need_master); t = t->next) {
+			if (t == m)
+				continue;
+			if (need_master && t->shared_id == m->master_id) {
+				pr_debug("The mount %d is slave for %d\n", m->mnt_id, t->mnt_id);
+				list_add(&m->mnt_slave, &t->mnt_slave_list);
+				m->mnt_master = t;
+				need_master = false;
+			}
+
+			/* Collect all mounts from this group */
+			if (need_share && t->shared_id == m->shared_id) {
+				pr_debug("Mount %d is shared with %d group %d\n",
+						m->mnt_id, t->mnt_id, m->shared_id);
+				list_add(&t->mnt_share, &m->mnt_share);
+			}
+		}
+		if (!need_master)
+			continue;
+
+		pr_err("Mount %d (master_id: %d shared_id: %d) "
+		       "has unreachable sharing\n", m->mnt_id,
+			m->master_id, m->shared_id);
+		return -1;
+	}
+
+	return 0;
+}
+
 static struct mount_info *mnt_build_tree(struct mount_info *list)
 {
 	struct mount_info *tree;
@@ -192,6 +237,7 @@ static struct mount_info *mnt_build_tree(struct mount_info *list)
 		return NULL;
 
 	mnt_resort_siblings(tree);
+	collect_shared(list);
 	pr_info("Done:\n");
 	mnt_tree_show(tree, 0);
 	return tree;
@@ -486,36 +532,6 @@ static inline int is_root_mount(struct mount_info *mi)
 	return is_root(mi->mountpoint);
 }
 
-static int validate_shared(struct mount_info *info)
-{
-	struct mount_info *m, *t;
-
-	/*
-	 * If we have a shared mounts, both master
-	 * slave targets are to be present in mount
-	 * list, otherwise we can't be sure if we can
-	 * recreate the scheme later on restore.
-	 */
-	for (m = info; m; m = m->next) {
-		if (!m->master_id)
-			continue;
-
-		for (t = info; t; t = t->next) {
-			if (t->shared_id == m->master_id)
-				break;
-		}
-		if (t)
-			continue;
-
-		pr_err("Mount %d (master_id: %d shared_id: %d) "
-		       "has unreachable sharing\n", m->mnt_id,
-			m->master_id, m->shared_id);
-		return -1;
-	}
-
-	return 0;
-}
-
 static int dump_one_mountpoint(struct mount_info *pm, int fd)
 {
 	MntEntry me = MNT_ENTRY__INIT;
@@ -562,11 +578,6 @@ int dump_mnt_ns(int ns_pid, struct cr_fdset *fdset)
 	if (mnt_build_tree(pm) == NULL)
 		return -1;
 
-	if (validate_shared(mntinfo)) {
-		pr_err("Can't proceed %d's mountinfo\n", ns_pid);
-		return -1;
-	}
-
 	pr_info("Dumping mountpoints\n");
 
 	img_fd = fdset_fd(fdset, CR_FD_MOUNTPOINTS);
@@ -775,6 +786,9 @@ struct mount_info *mnt_entry_alloc()
 	if (new) {
 		INIT_LIST_HEAD(&new->children);
 		INIT_LIST_HEAD(&new->siblings);
+		INIT_LIST_HEAD(&new->mnt_slave_list);
+		INIT_LIST_HEAD(&new->mnt_share);
+		new->mnt_master = NULL;
 	}
 	return new;
 }
-- 
1.8.3.1



More information about the CRIU mailing list