[CRIU] [PATCH 30/39] mount: use per-ns list of mount-points in clean_mnt_ns and free_mnt_ns

Andrey Vagin avagin at openvz.org
Mon Apr 21 07:23:40 PDT 2014


We are going to dump nested mount namespaces, so we move the mountinfo
list on the namespace structure.

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

diff --git a/mount.c b/mount.c
index d89da7d..de31e11 100644
--- a/mount.c
+++ b/mount.c
@@ -1304,7 +1304,7 @@ static int do_umount_one(struct mount_info *mi)
 	return 0;
 }
 
-static int clean_mnt_ns(void)
+static int clean_mnt_ns(struct mount_info *mntinfo_tree)
 {
 	pr_info("Cleaning mount namespace\n");
 
@@ -1390,16 +1390,14 @@ void mnt_entry_free(struct mount_info *mi)
 	xfree(mi);
 }
 
-static void free_mounts(void)
+static void free_mntinfo(struct mount_info *pms)
 {
-	mntinfo_tree = NULL;
-
-	while (mntinfo) {
+	while (pms) {
 		struct mount_info *pm;
 
-		pm = mntinfo->next;
-		mnt_entry_free(mntinfo);
-		mntinfo = pm;
+		pm = pms->next;
+		mnt_entry_free(pms);
+		pms = pm;
 	}
 }
 
@@ -1721,10 +1719,15 @@ int fini_mnt_ns()
 int prepare_mnt_ns(int ns_pid)
 {
 	int ret = -1;
-	struct mount_info *mis;
+	struct mount_info *mis, *old;
+	struct ns_id ns = { .pid = getpid(), .nd = &mnt_ns_desc };
 
 	pr_info("Restoring mount namespace\n");
 
+	old = collect_mntinfo(&ns);
+	if (old == NULL)
+		return -1;
+
 	close_proc();
 
 	mis = read_mnt_ns_img(ns_pid);
@@ -1742,7 +1745,7 @@ int prepare_mnt_ns(int ns_pid)
 	 * prior to recreating new ones.
 	 */
 	if (!opts.root) {
-		if (clean_mnt_ns())
+		if (clean_mnt_ns(ns.mnt.mntinfo_tree))
 			return -1;
 	} else {
 		struct mount_info *mi;
@@ -1770,7 +1773,7 @@ int prepare_mnt_ns(int ns_pid)
 		}
 	}
 
-	free_mounts();
+	free_mntinfo(old);
 
 	ret = populate_mnt_ns(ns_pid, mis);
 	if (ret)
-- 
1.8.5.3



More information about the CRIU mailing list