[05/15] restore: Prepare on-restorer aios earlier

Submitted by Pavel Emelianov on May 24, 2016, 11:34 a.m.

Details

Message ID 57443C5B.7000207@virtuozzo.com
State Superseded
Commit 0e6f4cc36aa691ca6d37826304ae55515c354a35
Headers show

Commit Message

Pavel Emelianov May 24, 2016, 11:34 a.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/aio.c         | 30 ++++++++++++++++++++++++++++++
 criu/cr-restore.c  | 26 ++++----------------------
 criu/include/aio.h |  2 ++
 3 files changed, 36 insertions(+), 22 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/aio.c b/criu/aio.c
index 888a640..19257b9 100644
--- a/criu/aio.c
+++ b/criu/aio.c
@@ -3,7 +3,11 @@ 
 #include <stdbool.h>
 #include "vma.h"
 #include "xmalloc.h"
+#include "pstree.h"
+#include "restorer.h"
 #include "aio.h"
+#include "rst_info.h"
+#include "rst-malloc.h"
 #include "parasite.h"
 #include "parasite-syscall.h"
 #include "images/mm.pb-c.h"
@@ -119,3 +123,29 @@  int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas)
 
 	return 0;
 }
+
+int prepare_aios(struct pstree_item *t, struct task_restore_args *ta)
+{
+	int i;
+	MmEntry *mm = rsti(t)->mm;
+	/*
+	 * Put info about AIO rings, they will get remapped
+	 */
+
+	ta->rings = (struct rst_aio_ring *)rst_mem_align_cpos(RM_PRIVATE);
+	ta->rings_n = mm->n_aios;
+
+	for (i = 0; i < mm->n_aios; i++) {
+		struct rst_aio_ring *raio;
+
+		raio = rst_mem_alloc(sizeof(*raio), RM_PRIVATE);
+		if (!raio)
+			return -1;
+
+		raio->addr = mm->aios[i]->id;
+		raio->nr_req = mm->aios[i]->nr_req;
+		raio->len = mm->aios[i]->ring_len;
+	}
+
+	return 0;
+}
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index adc3035..313fefc 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -508,6 +508,9 @@  static int restore_one_alive_task(int pid, CoreEntry *core)
 	if (prepare_vmas(current, ta))
 		return -1;
 
+	if (prepare_aios(current, ta))
+		return -1;
+
 	if (fixup_sysv_shmems())
 		return -1;
 
@@ -2704,10 +2707,6 @@  static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 #ifdef CONFIG_VDSO
 	unsigned long vdso_rt_size = 0;
 #endif
-
-	unsigned long aio_rings;
-	MmEntry *mm = rsti(current)->mm;
-
 	int n_seccomp_filters = 0;
 	unsigned long seccomp_filter_pos = 0;
 
@@ -2726,23 +2725,6 @@  static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 	BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
 
 	/*
-	 * Put info about AIO rings, they will get remapped
-	 */
-
-	aio_rings = rst_mem_align_cpos(RM_PRIVATE);
-	for (i = 0; i < mm->n_aios; i++) {
-		struct rst_aio_ring *raio;
-
-		raio = rst_mem_alloc(sizeof(*raio), RM_PRIVATE);
-		if (!raio)
-			goto err_nv;
-
-		raio->addr = mm->aios[i]->id;
-		raio->nr_req = mm->aios[i]->nr_req;
-		raio->len = mm->aios[i]->ring_len;
-	}
-
-	/*
 	 * Get all the tcp sockets fds into rst memory -- restorer
 	 * will turn repair off before going sigreturn
 	 */
@@ -2883,6 +2865,7 @@  static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 	task_args->task_size = kdat.task_size;
 
 	task_args->vmas = rst_mem_remap_ptr((unsigned long)task_args->vmas, RM_PRIVATE);
+	task_args->rings = rst_mem_remap_ptr((unsigned long)task_args->rings, RM_PRIVATE);
 
 #define remap_array(name, nr, cpos)	do {				\
 		task_args->name##_n = nr;				\
@@ -2893,7 +2876,6 @@  static int sigreturn_restore(pid_t pid, unsigned long ta_cp, CoreEntry *core)
 	remap_array(timerfd,	  rst_timerfd_nr, rst_timerfd_cpos);
 	remap_array(siginfo,	  siginfo_nr, siginfo_cpos);
 	remap_array(tcp_socks,	  rst_tcp_socks_nr, rst_tcp_socks_cpos);
-	remap_array(rings,	  mm->n_aios, aio_rings);
 	remap_array(rlims,	  rlims_nr, rlims_cpos);
 	remap_array(helpers,	  n_helpers, helpers_pos);
 	remap_array(zombies,	  n_zombies, zombies_pos);
diff --git a/criu/include/aio.h b/criu/include/aio.h
index 1e08775..a7572a8 100644
--- a/criu/include/aio.h
+++ b/criu/include/aio.h
@@ -8,6 +8,8 @@  void free_aios(MmEntry *mme);
 struct parasite_ctl;
 int parasite_collect_aios(struct parasite_ctl *, struct vm_area_list *);
 unsigned long aio_rings_args_size(struct vm_area_list *);
+struct task_restore_args;
+int prepare_aios(struct pstree_item *t, struct task_restore_args *ta);
 
 struct aio_ring {
 	unsigned        id;     /* kernel internal index number */