[CRIU] [PATCH cr 03/11] restore: split read_and_open_vmas into parts read_vmas and open_vmas

Andrey Vagin avagin at openvz.org
Mon Oct 15 11:32:16 EDT 2012


read_vmas will be called bedore forking children to restore
copy-on-write memory.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 4fe2969..f74e323 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -170,7 +170,7 @@ err:
 	return ret;
 }
 
-static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
+static int read_vmas(int pid, struct list_head *vmas, int *nr_vmas)
 {
 	int fd, ret = -1;
 
@@ -203,7 +203,22 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
 
 		vma->vma = *e;
 		vma_entry__free_unpacked(e, NULL);
+	}
+
+	close(fd);
+	return ret;
+}
 
+static int open_vmas(int pid, struct list_head *vmas)
+{
+	struct vma_area *vma;
+	int fd, ret = -1;
+
+	fd = open_image_ro(CR_FD_VMAS, pid);
+	if (fd < 0)
+		return fd;
+
+	list_for_each_entry(vma, vmas, list) {
 		if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR)))
 			continue;
 
@@ -229,7 +244,7 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
 	}
 
 	close(fd);
-	return ret;
+	return ret < 0 ? -1 : 0;
 }
 
 static int prepare_and_sigreturn(int pid, CoreEntry *core)
@@ -237,7 +252,11 @@ static int prepare_and_sigreturn(int pid, CoreEntry *core)
 	int err, nr_vmas;
 	LIST_HEAD(vma_list);
 
-	err = read_and_open_vmas(pid, &vma_list, &nr_vmas);
+	err = read_vmas(pid, &vma_list, &nr_vmas);
+	if (err)
+		return err;
+
+	err = open_vmas(pid, &vma_list);
 	if (err)
 		return err;
 
@@ -335,7 +354,7 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
 	 * We should be sure, that children don't use any file
 	 * descriptor while fdtable is being restored.
 	 */
-	list_for_each_entry(child, &current->children, list) {
+	list_for_each_entry(child, &current->children, sibling) {
 		if (!shared_fdtable(child))
 			continue;
 		futex_wait_until(child->rst->fdt_lock, FDT_LOCK_SYNC);
-- 
1.7.1



More information about the CRIU mailing list