[CRIU] [PATCH 2/5] files: Add file_remap_init

Cyrill Gorcunov gorcunov at gmail.com
Tue Feb 26 12:13:32 MSK 2019


Which allows to put this structure into known state
instead of opencoded values. Another reason is that
I think we will have to rework remap engine to address
duplicated ghost directories on image load time instead
of as it will be in next patches.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/files-reg.c         | 5 ++---
 criu/include/files-reg.h | 9 +++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/criu/files-reg.c b/criu/files-reg.c
index e9dcf5efad52..9d5e1d743117 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -449,6 +449,7 @@ static int collect_remap_ghost(struct reg_file_info *rfi,
 	gf = shmalloc(sizeof(*gf));
 	if (!gf)
 		return -1;
+	file_remap_init(&gf->remap);
 
 	/*
 	 * The rpath is shmalloc-ed because we create the ghost
@@ -537,14 +538,12 @@ static int collect_remap_linked(struct reg_file_info *rfi,
 	rm = xmalloc(sizeof(*rm));
 	if (!rm)
 		return -1;
+	file_remap_init(rm);
 
 	rrfi = container_of(rdesc, struct reg_file_info, d);
 	pr_info("Remapped %s -> %s\n", rfi->path, rrfi->path);
 
 	rm->rpath = rrfi->path;
-	rm->is_dir = false;
-	rm->uid = -1;
-	rm->gid = -1;
 	rm->rmnt_id = rfi->rfe->mnt_id;
 	rfi->remap = rm;
 	return 0;
diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h
index 7a22d4d82947..ec142db8c882 100644
--- a/criu/include/files-reg.h
+++ b/criu/include/files-reg.h
@@ -17,6 +17,15 @@ struct file_remap {
 	gid_t gid;
 };
 
+static inline void file_remap_init(struct file_remap *remap)
+{
+	remap->rpath	= NULL;
+	remap->is_dir	= false;
+	remap->uid	= -1;
+	remap->gid	= -1;
+	remap->rmnt_id	= -1;
+}
+
 struct reg_file_info {
 	struct file_desc	d;
 	RegFileEntry		*rfe;
-- 
2.20.1



More information about the CRIU mailing list