[CRIU] [PATCH 3/3] mount: Umount forced mounts on restore

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 22 07:19:26 PDT 2016


Umount mountpoints, which was forced mounted at dump.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/mount.h |    1 +
 criu/mount.c         |   23 +++++++++++++++++++++++
 images/mnt.proto     |    1 +
 3 files changed, 25 insertions(+)

diff --git a/criu/include/mount.h b/criu/include/mount.h
index 191f6a3..4554b2d 100644
--- a/criu/include/mount.h
+++ b/criu/include/mount.h
@@ -70,6 +70,7 @@ struct mount_info {
 
 	struct ext_mount	*external;
 	bool			internal_sharing;
+	bool			forced_mounted;
 
 	/* tree linkage */
 	struct mount_info	*parent;
diff --git a/criu/mount.c b/criu/mount.c
index f91654c..c08d217 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1832,9 +1832,19 @@ static struct fstype *decode_fstype(u32 fst)
 static int dump_one_fs(struct mount_info *mi)
 {
 	struct mount_info *pm = mi;
+	struct forced_mount *fm;
 	struct mount_info *t;
 	bool first = true;
 
+	list_for_each_entry(fm, &forced_mounts_list, list) {
+		if (fm->mnt_id == mi->mnt_id &&
+		    fm->ns_id == mi->nsid->kid) {
+			pr_info("Mark forced mount %u in ns %u\n", fm->mnt_id, fm->ns_id);
+			mi->forced_mounted = true;
+			break;
+		}
+	}
+
 	if (mi->is_ns_root || mi->need_plugin || mi->external || !mi->fstype->dump)
 		return 0;
 
@@ -1902,6 +1912,11 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img)
 		me.deleted	= true;
 	}
 
+	if (pm->forced_mounted) {
+		me.forced_mounted	= pm->forced_mounted;
+		me.has_forced_mounted	= true;
+	}
+
 	if (pm->internal_sharing) {
 		me.has_internal_sharing = true;
 		me.internal_sharing = true;
@@ -2684,6 +2699,12 @@ static int do_mount_one(struct mount_info *mi)
 			mi->fstype = find_fstype_by_name("btrfs");
 	}
 
+	if (mi->forced_mounted) {
+		ret = umount(mi->mountpoint);
+		if (ret)
+			pr_perror("Can't umount %s\n", mi->mountpoint);
+	}
+
 	return ret;
 }
 
@@ -2998,6 +3019,8 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 		pm->is_ns_root		= is_root(me->mountpoint);
 		if (me->has_internal_sharing)
 			pm->internal_sharing = me->internal_sharing;
+		if (me->has_forced_mounted)
+			pm->forced_mounted = me->forced_mounted;
 
 		pm->source = xstrdup(me->source);
 		if (!pm->source)
diff --git a/images/mnt.proto b/images/mnt.proto
index 9338ecb..4e56201 100644
--- a/images/mnt.proto
+++ b/images/mnt.proto
@@ -46,4 +46,5 @@ message mnt_entry {
 
 	optional bool		deleted			= 16;
 	optional uint32		sb_flags		= 17 [(criu).hex = true];
+	optional bool		forced_mounted		= 18;
 }



More information about the CRIU mailing list