[CRIU] [PATCH 8/9] mounts: handle shared and slave mounts

Andrey Vagin avagin at openvz.org
Wed Jul 24 04:10:22 EDT 2013


The idea is simple. If a mount can't be mounted now, we will try to
mount it later.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/mount.c b/mount.c
index 333b658..8016dcc 100644
--- a/mount.c
+++ b/mount.c
@@ -732,13 +732,33 @@ static int do_new_mount(struct mount_info *mi)
 {
 	char *src;
 	struct fstype *tp = mi->fstype;
+	struct mount_info *t;
 
 	src = resolve_source(mi);
 	if (!src)
 		return -1;
 
+	/*
+	 * Wait while all parent are not mounted
+	 *
+	 * FIXME a child is shared only between parents,
+	 * who was present in a moment of birth
+	 */
+	if (mi->parent->flags & MS_SHARED) {
+		list_for_each_entry(t, &mi->parent->mnt_share, mnt_share)
+			if (!t->mounted) {
+				pr_debug("Postpone %s due to %s\n", mi->mountpoint, t->mountpoint);
+				return 1;
+			}
+		list_for_each_entry(t, &mi->parent->mnt_slave_list, mnt_slave)
+			if (!t->mounted) {
+				pr_debug("Postpone %s\n", mi->mountpoint);
+				return 1;
+			}
+	}
+
 	if (mount(src, mi->mountpoint, tp->name,
-				mi->flags, mi->options) < 0) {
+			mi->flags & (~MS_SHARED), mi->options) < 0) {
 		pr_perror("Can't mount at %s", mi->mountpoint);
 		return -1;
 	}
@@ -746,6 +766,8 @@ static int do_new_mount(struct mount_info *mi)
 	if (restore_shared_options(mi, 0, mi->shared_id, 0))
 		return -1;
 
+	mi->mounted = true;
+
 	if (tp->restore && tp->restore(mi))
 		return -1;
 
@@ -754,8 +776,27 @@ static int do_new_mount(struct mount_info *mi)
 
 static int do_bind_mount(struct mount_info *mi)
 {
-	pr_err("No bind mounts at %s\n", mi->mountpoint);
-	return -1;
+	char rpath[PATH_MAX];
+	bool shared = mi->shared_id && mi->shared_id == mi->bind->shared_id;
+
+	snprintf(rpath, sizeof(rpath), "%s%s", mi->bind->mountpoint, mi->root);
+
+	pr_info("Bind %s to %s\n", rpath, mi->mountpoint);
+
+	if (mount(rpath, mi->mountpoint, NULL,
+				MS_BIND, NULL) < 0) {
+		pr_perror("Can't mount at %s", mi->mountpoint);
+		return -1;
+	}
+
+	if (restore_shared_options(mi, !shared,
+					mi->shared_id && !shared,
+					mi->master_id))
+		return -1;
+
+	mi->mounted = true;
+
+	return 0;
 }
 
 static inline int fsroot_mounted(struct mount_info *mi)
@@ -773,9 +814,14 @@ static int do_mount_one(struct mount_info *mi)
 	if (mi->mounted)
 		return 0;
 
+	if ((mi->master_id || !fsroot_mounted(mi)) && mi->bind == NULL) {
+		pr_debug("Postpone slave %s\n", mi->mountpoint);
+		return 1;
+	}
+
 	pr_debug("\tMounting %s @%s\n", mi->fstype->name, mi->mountpoint);
 
-	if (fsroot_mounted(mi))
+	if (!mi->bind)
 		ret = do_new_mount(mi);
 	else
 		ret = do_bind_mount(mi);
-- 
1.8.3.1



More information about the CRIU mailing list