[CRIU] [PATCH 16/27] mount: save mount tree for each namespace

Andrey Vagin avagin at openvz.org
Thu Apr 10 04:03:59 PDT 2014


It will be used to check, that a file is reachable.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/mount.h      |  3 ++-
 include/namespaces.h |  6 ++++++
 mount.c              | 10 +++++++---
 namespaces.c         |  2 +-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/mount.h b/include/mount.h
index 2b61811..24e1e26 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -11,7 +11,8 @@ extern int collect_mount_info(pid_t pid);
 extern struct fstype *find_fstype_by_name(char *fst);
 
 struct cr_fdset;
-extern int dump_mnt_ns(int pid, int ns_id);
+struct ns_id;
+extern int dump_mnt_ns(struct ns_id *ns);
 extern int prepare_mnt_ns(int pid);
 
 extern int pivot_root(const char *new_root, const char *put_old);
diff --git a/include/namespaces.h b/include/namespaces.h
index fcbe17c..4b6ba79 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -16,6 +16,12 @@ struct ns_id {
 	struct ns_desc *nd;
 	struct ns_id *next;
 	futex_t created; /* boolean */
+	union {
+		struct {
+			struct mount_info *mntinfo;
+			struct mount_info *mntinfo_tree;
+		} mnt;
+	};
 };
 extern struct ns_id *ns_ids;
 
diff --git a/mount.c b/mount.c
index e111639..0f3bb39 100644
--- a/mount.c
+++ b/mount.c
@@ -844,10 +844,12 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
 	return 0;
 }
 
-int dump_mnt_ns(int ns_pid, int ns_id)
+int dump_mnt_ns(struct ns_id *ns)
 {
 	struct mount_info *pm;
 	int img_fd, ret = -1;
+	int ns_pid = ns->pid;
+	int ns_id = ns->id;
 
 	img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_id);
 	if (img_fd < 0)
@@ -862,7 +864,10 @@ int dump_mnt_ns(int ns_pid, int ns_id)
 		goto err;
 	}
 
-	if (mnt_build_tree(pm) == NULL)
+	ns->mnt.mntinfo = pm;
+
+	ns->mnt.mntinfo_tree = mnt_build_tree(pm);
+	if (ns->mnt.mntinfo_tree == NULL)
 		goto err;
 
 	if (validate_mounts(pm, true))
@@ -876,7 +881,6 @@ int dump_mnt_ns(int ns_pid, int ns_id)
 		if (dump_one_mountpoint(pm, img_fd))
 			goto err;
 
-		xfree(pm);
 		pm = n;
 	} while (pm);
 
diff --git a/namespaces.c b/namespaces.c
index 77920f0..1332a66 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -461,7 +461,7 @@ int dump_mnt_namespaces(void)
 
 		pr_info("Dump MNT namespace (mountpoints) %d via %d\n",
 				ns->id, ns->pid);
-		ret = dump_mnt_ns(ns->pid, ns->id);
+		ret = dump_mnt_ns(ns);
 		if (ret)
 			break;
 	}
-- 
1.8.5.3



More information about the CRIU mailing list