[CRIU] [PATCH 01/10] mount: link dependent mounts (v3)

Andrey Vagin avagin at openvz.org
Thu Aug 29 10:55:38 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.
v3: handle errors of collect_shared

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/proc_parse.h |  5 ++++
 mount.c              | 85 ++++++++++++++++++++++++++++++----------------------
 2 files changed, 55 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 c950992..446a03e 100644
--- a/mount.c
+++ b/mount.c
@@ -194,6 +194,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) {
+			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;
@@ -208,6 +253,8 @@ static struct mount_info *mnt_build_tree(struct mount_info *list)
 		return NULL;
 
 	mnt_resort_siblings(tree);
+	if (collect_shared(list))
+		return NULL;
 	pr_info("Done:\n");
 	mnt_tree_show(tree, 0);
 	return tree;
@@ -457,36 +504,6 @@ static struct fstype *decode_fstype(u32 fst)
 	return &fstypes[fst];
 }
 
-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;
@@ -533,11 +550,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_MNTS);
@@ -747,6 +759,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