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

Andrey Vagin avagin at openvz.org
Tue Oct 23 06:02:22 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       |   17 ++++++++++++++---
 include/restorer.h |    5 +++--
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 4e27c06..4ff552a 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -179,9 +179,21 @@ err:
 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;
@@ -362,7 +374,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)
@@ -379,8 +391,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 de73b3c..ebdfb1d 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -268,7 +268,8 @@ find_shmem(struct shmems *shmems, unsigned long shmid)
 	return NULL;
 }
 
-#define vma_priv(vma) (vma_entry_is(vma, VMA_AREA_REGULAR) &&	\
-			vma_entry_is(vma, 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.1



More information about the CRIU mailing list