[CRIU] [PATCH 06/16] files: save mnt_id for reg files

Andrey Vagin avagin at openvz.org
Tue Apr 8 16:34:58 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 85246f2..075a75f 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1655,11 +1655,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 dd9b404..d4c06a5 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