[CRIU] [PATCH 13/16] files: open ghost file relative to the proper root

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


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 files-reg.c     | 10 ++++++++--
 include/mount.h |  1 +
 mount.c         | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/files-reg.c b/files-reg.c
index 81736d5..fcf178d 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -73,6 +73,7 @@ static int open_remap_ghost(struct reg_file_info *rfi,
 	struct ghost_file *gf;
 	GhostFileEntry *gfe = NULL;
 	int gfd, ifd, ghost_flags;
+	char *root, path[PATH_MAX];
 
 	rfe->remap_id &= ~REMAP_GHOST;
 	list_for_each_entry(gf, &ghost_files, list)
@@ -87,6 +88,10 @@ static int open_remap_ghost(struct reg_file_info *rfi,
 
 	pr_info("Opening ghost file %#x for %s\n", rfe->remap_id, rfi->path);
 
+	root = rst_get_mnt_root(rfi->rfe->mnt_id);
+	if (root == NULL)
+		return -1;
+
 	gf = shmalloc(sizeof(*gf));
 	if (!gf)
 		return -1;
@@ -120,9 +125,10 @@ static int open_remap_ghost(struct reg_file_info *rfi,
 	} else
 		ghost_flags = O_WRONLY | O_CREAT | O_EXCL;
 
-	gfd = open(gf->remap.path, ghost_flags, gfe->mode);
+	snprintf(path, sizeof(path), "%s/%s", root, gf->remap.path);
+	gfd = open(path, ghost_flags, gfe->mode);
 	if (gfd < 0) {
-		pr_perror("Can't open ghost file %s", gf->remap.path);
+		pr_perror("Can't open ghost file %s", path);
 		goto close_ifd;
 	}
 
diff --git a/include/mount.h b/include/mount.h
index 67c506e..9bdc090 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -31,5 +31,6 @@ 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);
+char *rst_get_mnt_root(int mnt_id);
 
 #endif /* __CR_MOUNT_H__ */
diff --git a/mount.c b/mount.c
index 57f9d5f..a6819f3 100644
--- a/mount.c
+++ b/mount.c
@@ -1557,6 +1557,27 @@ err:
 	return NULL;
 }
 
+char *rst_get_mnt_root(int mnt_id)
+{
+	struct mount_info *m;
+	static char path[PATH_MAX] = "/";
+
+	if (!(root_ns_mask & CLONE_NEWNS))
+		return path;
+
+	m = lookup_mnt_id(mnt_id);
+	if (m == NULL)
+		return NULL;
+
+	if (m->nsid->pid == getpid())
+		return path;
+
+	snprintf(path, sizeof(path), "%s/%d/",
+			get_mnt_roots(false), m->nsid->id);
+
+	return path;
+}
+
 int restore_task_mnt_ns(struct ns_id *nsid, pid_t pid)
 {
 	char path[PATH_MAX];
-- 
1.8.5.3



More information about the CRIU mailing list