[CRIU] [PATCH 08/11] vma: Do not open vmas when inheriting

Pavel Emelyanov xemul at virtuozzo.com
Fri May 5 09:03:31 PDT 2017


Inherited VMAs don't need the descriptor to work with.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/mem.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/criu/mem.c b/criu/mem.c
index a9e6e08..6cefa9d 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -646,16 +646,6 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 	void *addr;
 	unsigned long nr_pages, size;
 
-	if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
-		ret = vma->vm_open(vpid(t), vma);
-		if (ret < 0) {
-			pr_err("Can't fixup VMA's fd\n");
-			return -1;
-		}
-
-		vma->vm_open = NULL; /* prevent from 2nd open in prepare_vmas */
-	}
-
 	nr_pages = vma_entry_len(vma->e) / PAGE_SIZE;
 	vma->page_bitmap = xzalloc(BITS_TO_LONGS(nr_pages) * sizeof(long));
 	if (vma->page_bitmap == NULL)
@@ -682,6 +672,13 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 		 */
 		if (vma_entry_is(vma->e, VMA_AREA_AIORING))
 			flag |= MAP_ANONYMOUS;
+		else if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
+			ret = vma->vm_open(vpid(t), vma);
+			if (ret < 0) {
+				pr_err("Can't fixup VMA's fd\n");
+				return -1;
+			}
+		}
 
 		addr = mmap(*tgt_addr, size,
 				vma->e->prot | PROT_WRITE,
@@ -692,6 +689,9 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 			pr_perror("Unable to map ANON_VMA");
 			return -1;
 		}
+
+		if (vma_area_is(vma, VMA_FILE_PRIVATE))
+			close(vma->e->fd);
 	} else {
 		void *paddr;
 
@@ -725,7 +725,7 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void
 	}
 
 	if (vma_area_is(vma, VMA_FILE_PRIVATE))
-		close(vma->e->fd);
+		vma->vm_open = NULL; /* prevent from 2nd open in prepare_vmas */
 
 	*tgt_addr += size;
 	return 0;
-- 
2.5.5



More information about the CRIU mailing list