[CRIU] [PATCH cr 04/11] restore: collect vma-s before creating
children
Andrey Vagin
avagin at openvz.org
Mon Oct 15 11:32:17 EDT 2012
A private vma's should be inherited by children for
restoring copy-on-write regions.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
cr-restore.c | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index f74e323..21d6f97 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -64,6 +64,9 @@ static int restore_task_with_children(void *);
static int sigreturn_restore(pid_t pid, CoreEntry *core, struct list_head *vmas, int nr_vmas);
static int prepare_restorer_blob(void);
+static LIST_HEAD(vma_list);
+static int nr_vmas;
+
static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
{
void *ret;
@@ -170,15 +173,18 @@ err:
return ret;
}
-static int read_vmas(int pid, struct list_head *vmas, int *nr_vmas)
+static int read_vmas(int pid)
{
- int fd, ret = -1;
+ int fd, ret = 0;
+
+ INIT_LIST_HEAD(&vma_list);
+ /* Skip errors, because a zombie doesn't have an image of vmas */
fd = open_image_ro(CR_FD_VMAS, pid);
if (fd < 0)
- return fd;
+ return ret;
- *nr_vmas = 0;
+ nr_vmas = 0;
while (1) {
struct vma_area *vma;
VmaEntry *e;
@@ -188,8 +194,8 @@ static int read_vmas(int pid, struct list_head *vmas, int *nr_vmas)
if (!vma)
break;
- (*nr_vmas)++;
- list_add_tail(&vma->list, vmas);
+ nr_vmas++;
+ list_add_tail(&vma->list, &vma_list);
ret = pb_read_one_eof(fd, &e, PB_VMAS);
if (ret <= 0)
break;
@@ -249,12 +255,7 @@ static int open_vmas(int pid, struct list_head *vmas)
static int prepare_and_sigreturn(int pid, CoreEntry *core)
{
- int err, nr_vmas;
- LIST_HEAD(vma_list);
-
- err = read_vmas(pid, &vma_list, &nr_vmas);
- if (err)
- return err;
+ int err;
err = open_vmas(pid, &vma_list);
if (err)
@@ -835,6 +836,9 @@ static int restore_task_with_children(void *_arg)
exit(1);
}
+ if (read_vmas(pid))
+ exit(1);
+
pr_info("Restoring children:\n");
list_for_each_entry(child, ¤t->children, sibling) {
if (!restore_before_setsid(child))
--
1.7.1
More information about the CRIU
mailing list