[CRIU] [PATCH 1/2] vma: Move fdflags evaluation into collect_filemap

Pavel Emelyanov xemul at virtuozzo.com
Thu May 18 10:24:49 PDT 2017


In this routine we'll need to compare fdflags, so to
avoid double if-s, let's calculate and set fdflags early.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/files-reg.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/criu/files-reg.c b/criu/files-reg.c
index 9c851f4..44bf528 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1629,14 +1629,8 @@ static int open_filemap(int pid, struct vma_area *vma)
 	 * We open file w/o lseek, as mappings don't care about it
 	 */
 
-	BUG_ON(vma->vmfd == NULL);
-	if (vma->e->has_fdflags)
-		flags = vma->e->fdflags;
-	else if ((vma->e->prot & PROT_WRITE) &&
-			vma_area_is(vma, VMA_FILE_SHARED))
-		flags = O_RDWR;
-	else
-		flags = O_RDONLY;
+	BUG_ON((vma->vmfd == NULL) || !vma->e->has_fdflags);
+	flags = vma->e->fdflags;
 
 	ret = open_path(vma->vmfd, do_open_reg_noseek_flags, &flags);
 	if (ret < 0)
@@ -1650,6 +1644,16 @@ int collect_filemap(struct vma_area *vma)
 {
 	struct file_desc *fd;
 
+	if (!vma->e->has_fdflags) {
+		/* Make a wild guess for the fdflags */
+		vma->e->has_fdflags = true;
+		if ((vma->e->prot & PROT_WRITE) &&
+				vma_area_is(vma, VMA_FILE_SHARED))
+			vma->e->fdflags = O_RDWR;
+		else
+			vma->e->fdflags = O_RDONLY;
+	}
+
 	fd = collect_special_file(vma->e->shmid);
 	if (!fd)
 		return -1;
-- 
2.1.4



More information about the CRIU mailing list