[2/5] files: Add file_remap_init

Submitted by Cyrill Gorcunov on Feb. 22, 2019, 4:02 p.m.

Details

Message ID 20190222160257.27697-3-gorcunov@gmail.com
State New
Series "Fix order problem in ghost files cleanup"
Headers show

Commit Message

Cyrill Gorcunov Feb. 22, 2019, 4:02 p.m.
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@gmail.com>
---
 criu/files-reg.c         | 5 ++---
 criu/include/files-reg.h | 9 +++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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;