[CRIU] [PATCH] mount: don't collect mounts when they are not required

Andrei Vagin avagin at openvz.org
Wed Mar 22 22:09:29 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Currently we collect mounts to clean up a mount namespace,
but it isn't required when we are going to call pivot_root.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/mount.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index 02fc71d..e04893b 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2902,7 +2902,6 @@ void cleanup_mnt_ns(void)
 int prepare_mnt_ns(void)
 {
 	int ret = -1, rst = -1;
-	struct mount_info *old;
 	struct ns_id ns = { .type = NS_CRIU, .ns_pid = PROC_SELF, .nd = &mnt_ns_desc };
 	struct ns_id *nsid;
 
@@ -2911,27 +2910,30 @@ int prepare_mnt_ns(void)
 
 	pr_info("Restoring mount namespace\n");
 
-	old = collect_mntinfo(&ns, false);
-	if (old == NULL)
-		return -1;
-
 	if (!opts.root) {
+		struct mount_info *old;
+
 		if (chdir("/")) {
 			pr_perror("chdir(\"/\") failed");
 			return -1;
 		}
 
+		old = collect_mntinfo(&ns, false);
+		if (old == NULL)
+			return -1;
 		/*
 		 * The new mount namespace is filled with the mountpoint
 		 * clones from the original one. We have to umount them
 		 * prior to recreating new ones.
 		 */
 		pr_info("Cleaning mount namespace\n");
-		if (mnt_tree_for_each_reverse(ns.mnt.mntinfo_tree, do_umount_one))
+		if (mnt_tree_for_each_reverse(ns.mnt.mntinfo_tree, do_umount_one)) {
+			free_mntinfo(old);
 			return -1;
-	}
+		}
 
-	free_mntinfo(old);
+		free_mntinfo(old);
+	}
 
 	ret = populate_mnt_ns();
 	if (ret)
-- 
2.7.4



More information about the CRIU mailing list