[CRIU] [PATCH 10/15] restore: use a new scheme for restoring of file private mappings

Andrey Vagin avagin at openvz.org
Fri Nov 2 09:32:02 EDT 2012


With this patch vma->shmid contains file id before mapping a region,
then it contains of a temporary address.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c       | 24 +++++++++++++++++++-----
 include/restorer.h |  4 +++-
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 2204b4c..9f577c2 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -182,12 +182,24 @@ err:
 }
 
 /* Map a private vma, if it is not mapped by a parrent yet */
-static int map_private_vma(struct vma_area *vma, void *tgt_addr,
+static int map_private_vma(pid_t pid, struct vma_area *vma, void *tgt_addr,
 			struct vma_area **pvma, struct list_head *pvma_list)
 {
+	int ret;
 	void *addr;
 	struct vma_area *p = *pvma;
 
+	if (vma_entry_is(&vma->vma, VMA_FILE_PRIVATE)) {
+		ret = get_filemap_fd(pid, &vma->vma);
+		if (ret < 0) {
+			pr_err("Can't fixup fd\n");
+			return -1;
+		}
+		vma->vma.fd = ret;
+		/* shmid will be used for a temporary address */
+		vma->vma.shmid = 0;
+	}
+
 	list_for_each_entry_continue(p, pvma_list, list) {
 		if (p->vma.start > vma->vma.start)
 			 break;
@@ -230,6 +242,9 @@ static int map_private_vma(struct vma_area *vma, void *tgt_addr,
 		vma_premmaped_start(&(vma->vma)) = (unsigned long) addr;
 	}
 
+	if (vma_entry_is(&vma->vma, VMA_FILE_PRIVATE))
+		close(vma->vma.fd);
+
 	return 0;
 }
 
@@ -300,7 +315,7 @@ static int read_vmas(int pid)
 		if (!vma_priv(&vma->vma))
 			continue;
 
-		ret = map_private_vma(vma, addr, &pvma, &old);
+		ret = map_private_vma(pid, vma, addr, &pvma, &old);
 		if (ret < 0)
 			break;
 
@@ -330,7 +345,7 @@ out:
 static int open_vmas(int pid, struct list_head *vmas)
 {
 	struct vma_area *vma;
-	int fd, ret = -1;
+	int fd, ret = 0;
 
 	fd = open_image_ro(CR_FD_VMAS, pid);
 	if (fd < 0)
@@ -347,8 +362,7 @@ static int open_vmas(int pid, struct list_head *vmas)
 			ret = vma->vma.shmid;
 		else if (vma_entry_is(&vma->vma, VMA_ANON_SHARED))
 			ret = get_shmem_fd(pid, &vma->vma);
-		else if (vma_entry_is(&vma->vma, VMA_FILE_PRIVATE) ||
-				vma_entry_is(&vma->vma, VMA_FILE_SHARED))
+		else if (vma_entry_is(&vma->vma, VMA_FILE_SHARED))
 			ret = get_filemap_fd(pid, &vma->vma);
 		else
 			continue;
diff --git a/include/restorer.h b/include/restorer.h
index e64c114..bd9b35d 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -273,6 +273,8 @@ find_shmem(struct shmems *shmems, unsigned long shmid)
 	return NULL;
 }
 
-#define vma_priv(vma) (vma_entry_is(vma, VMA_AREA_REGULAR | VMA_ANON_PRIVATE))
+#define vma_priv(vma) ((vma_entry_is(vma, VMA_AREA_REGULAR)) &&	\
+			(vma_entry_is(vma, VMA_ANON_PRIVATE) || \
+			vma_entry_is(vma, VMA_FILE_PRIVATE)))
 
 #endif /* CR_RESTORER_H__ */
-- 
1.7.11.7



More information about the CRIU mailing list