[CRIU] [PATCH 10/16] restore: look up root for each file

Andrey Vagin avagin at openvz.org
Tue Apr 8 16:35:02 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 files-reg.c          | 16 +++++++++++++++-
 include/proc_parse.h |  1 +
 mount.c              |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/files-reg.c b/files-reg.c
index 750b356..81736d5 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -23,6 +23,7 @@
 #include "fs-magic.h"
 #include "asm/atomic.h"
 #include "namespaces.h"
+#include "proc_parse.h"
 
 #include "protobuf.h"
 #include "protobuf/regfile.pb-c.h"
@@ -608,9 +609,22 @@ int open_path(struct file_desc *d,
 	struct reg_file_info *rfi;
 	int tmp;
 	char *orig_path = NULL;
+	struct mount_info *m;
 
 	rfi = container_of(d, struct reg_file_info, d);
 
+	if (rfi->rfe->mnt_id >= 0) {
+		m = lookup_mnt_id(rfi->rfe->mnt_id);
+		if (m == NULL) {
+			pr_err("Unable to look up the %d mntns: %s\n",
+						rfi->rfe->mnt_id, rfi->path);
+			return -1;
+		}
+
+		if (mntns_collect_root(m->nsid->pid))
+			return -1;
+	}
+
 	if (rfi->remap) {
 		mutex_lock(ghost_file_mutex);
 		if (rfi_remap(rfi) < 0) {
@@ -674,7 +688,7 @@ static int do_open_reg_noseek_flags(struct reg_file_info *rfi, void *arg)
 	u32 flags = *(u32 *)arg;
 	int fd;
 
-	fd = open(rfi->path, flags);
+	fd = openat(mntns_root, rfi->path, flags);
 	if (fd < 0) {
 		pr_perror("Can't open file %s on restore", rfi->path);
 		return fd;
diff --git a/include/proc_parse.h b/include/proc_parse.h
index c42a48c..423b490 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -116,6 +116,7 @@ struct mount_info {
 	int		is_file;
 	bool		is_root;
 	struct mount_info *next;
+	struct ns_id	*nsid;
 
 	/* tree linkage */
 	struct mount_info *parent;
diff --git a/mount.c b/mount.c
index 9b40903..57f9d5f 100644
--- a/mount.c
+++ b/mount.c
@@ -1445,6 +1445,7 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 		if (!pm)
 			goto err;
 
+		pm->nsid = nsid;
 		pm->next = *pms;
 		*pms = pm;
 
-- 
1.8.5.3



More information about the CRIU mailing list