[CRIU] [PATCH 11/16] restore: use a new scheme for restoring of file private mappings
Andrey Vagin
avagin at openvz.org
Wed Nov 14 12:19:20 EST 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 | 22 ++++++++++++++++++----
include/restorer.h | 4 +++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index df77d88..64b1057 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, *paddr = NULL;
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;
@@ -229,6 +241,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;
}
@@ -307,7 +322,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;
@@ -351,8 +366,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 if (vma_entry_is(&vma->vma, VMA_AREA_SOCKET))
ret = get_socket_fd(pid, &vma->vma);
diff --git a/include/restorer.h b/include/restorer.h
index 4ef007f..6f7dc36 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -275,6 +275,8 @@ find_shmem(struct shmems *shmems, unsigned long shmid)
/* the restorer_blob_offset__ prefix is added by gen_offsets.sh */
#define restorer_sym(rblob, name) ((void *)(rblob) + restorer_blob_offset__##name)
-#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