[CRIU] [PATCH 18/27] files: save mnt_id for reg files

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


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c              | 10 ++++++----
 files-reg.c            | 12 ++++++++++++
 include/mount.h        |  2 ++
 mount.c                | 26 ++++++++++++++++++++++++++
 protobuf/regfile.proto |  1 +
 5 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index f8209ae..c52ba67 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1652,11 +1652,13 @@ int cr_pre_dump_tasks(pid_t pid)
 	if (gen_predump_ns_mask())
 		goto err;
 
-	if (collect_mount_info(pid))
-		goto err;
+	if (!(root_ns_mask & CLONE_NEWNS)) {
+		if (collect_mount_info(pid))
+			goto err;
 
-	if (mntns_collect_root(root_item->pid.real))
-		goto err;
+		if (mntns_collect_root(root_item->pid.real))
+			goto err;
+	}
 
 	for_each_pstree_item(item)
 		if (pre_dump_one_task(item, &ctls))
diff --git a/files-reg.c b/files-reg.c
index 7c783b5..750b356 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -22,6 +22,7 @@
 #include "util.h"
 #include "fs-magic.h"
 #include "asm/atomic.h"
+#include "namespaces.h"
 
 #include "protobuf.h"
 #include "protobuf/regfile.pb-c.h"
@@ -549,6 +550,17 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 	} else
 		link = p->link;
 
+	if (p->mnt_id >= 0 && (root_ns_mask & CLONE_NEWNS)) {
+		if (set_mntns_by_mnt_id(p->mnt_id)) {
+			pr_err("The %d mount is unreachable\n", p->mnt_id);
+			return -1;
+		}
+
+		rfe.mnt_id = p->mnt_id;
+		rfe.has_mnt_id = true;
+
+	}
+
 	pr_info("Dumping path for %d fd via self %d [%s]\n",
 			p->fd, lfd, &link->name[1]);
 
diff --git a/include/mount.h b/include/mount.h
index 24e1e26..67c506e 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -30,4 +30,6 @@ struct ns_id;
 extern int restore_task_mnt_ns(struct ns_id *nsid, pid_t pid);
 extern int fini_mnt_ns(void);
 
+int set_mntns_by_mnt_id(int mnt_id);
+
 #endif /* __CR_MOUNT_H__ */
diff --git a/mount.c b/mount.c
index 0f3bb39..f807ba9 100644
--- a/mount.c
+++ b/mount.c
@@ -128,6 +128,32 @@ static struct mount_info *__lookup_mnt_id(struct mount_info *list, int id)
 	return NULL;
 }
 
+int set_mntns_by_mnt_id(int mnt_id)
+{
+	struct ns_id *nsid;
+
+	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
+		if (nsid->nd != &mnt_ns_desc)
+			continue;
+
+		if (__lookup_mnt_id(nsid->mnt.mntinfo, mnt_id))
+			break;
+	}
+
+	if (nsid == NULL) {
+		pr_err("The %d mount is unreachable\n", mnt_id);
+		return -1;
+	}
+
+	mntinfo = nsid->mnt.mntinfo;
+	mntinfo_tree = nsid->mnt.mntinfo_tree;
+
+	if (mntns_collect_root(nsid->pid))
+		return -1;
+
+	return 0;
+}
+
 struct mount_info *lookup_mnt_id(unsigned int id)
 {
 	return __lookup_mnt_id(mntinfo, id);
diff --git a/protobuf/regfile.proto b/protobuf/regfile.proto
index d975ab0..e91dc44 100644
--- a/protobuf/regfile.proto
+++ b/protobuf/regfile.proto
@@ -6,4 +6,5 @@ message reg_file_entry {
 	required uint64		pos	= 3;
 	required fown_entry	fown	= 5;
 	required string		name	= 6;
+	optional sint32		mnt_id	= 7 [default = -1];
 }
-- 
1.8.5.3



More information about the CRIU mailing list