[CRIU] [PATCH 2/4] restore: fill up thread_args a bit earlier

Andrey Vagin avagin at openvz.org
Fri Dec 21 08:19:45 EST 2012


It's preparation for the next patch.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c | 103 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 52 insertions(+), 51 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index ce79f02..6c0f31b 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1894,51 +1894,12 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 
 	strncpy(task_args->comm, core->tc->comm, sizeof(task_args->comm));
 
-	task_args->t.clear_tid_addr	= core->thread_info->clear_tid_addr;
-	task_args->ids			= *core->ids;
-	task_args->t.gpregs		= *core->thread_info->gpregs;
-	task_args->t.blk_sigset		= core->tc->blk_sigset;
-	task_args->t.has_blk_sigset	= true;
-
-	if (core->thread_core) {
-		task_args->t.has_futex		= true;
-		task_args->t.futex_rla		= core->thread_core->futex_rla;
-		task_args->t.futex_rla_len	= core->thread_core->futex_rla_len;
-
-		ret = prep_sched_info(&task_args->t.sp, core->thread_core);
-		if (ret)
-			goto err;
-	}
-
-	/* No longer need it */
-	core_entry__free_unpacked(core, NULL);
-
-	ret = prepare_itimers(pid, task_args);
-	if (ret < 0)
-		goto err;
-
-	ret = prepare_creds(pid, task_args);
-	if (ret < 0)
-		goto err;
-
-	ret = prepare_mm(pid, task_args);
-	if (ret < 0)
-		goto err;
-
-	mutex_init(&task_args->rst_lock);
-
-	/*
-	 * Now prepare run-time data for threads restore.
-	 */
-	task_args->nr_threads		= current->nr_threads;
-	task_args->clone_restore_fn	= (void *)restore_thread_exec_start;
-	task_args->thread_args		= thread_args;
-
 	/*
 	 * Fill up per-thread data.
 	 */
 	for (i = 0; i < current->nr_threads; i++) {
 		int fd_core;
+		CoreEntry *tcore;
 		thread_args[i].pid = current->threads[i].virt;
 
 		/* skip self */
@@ -1960,10 +1921,10 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 			goto err;
 		}
 
-		ret = pb_read_one(fd_core, &core, PB_CORE);
+		ret = pb_read_one(fd_core, &tcore, PB_CORE);
 		close(fd_core);
 
-		if (core->tc || core->ids) {
+		if (tcore->tc || tcore->ids) {
 			pr_err("Thread has optional fields present %d\n",
 			       thread_args[i].pid);
 			ret = -1;
@@ -1976,22 +1937,22 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 		}
 
 		thread_args[i].ta		= task_args;
-		thread_args[i].gpregs		= *core->thread_info->gpregs;
-		thread_args[i].clear_tid_addr	= core->thread_info->clear_tid_addr;
+		thread_args[i].gpregs		= *tcore->thread_info->gpregs;
+		thread_args[i].clear_tid_addr	= tcore->thread_info->clear_tid_addr;
 
-		if (core->thread_core) {
+		if (tcore->thread_core) {
 			thread_args[i].has_futex	= true;
-			thread_args[i].futex_rla	= core->thread_core->futex_rla;
-			thread_args[i].futex_rla_len	= core->thread_core->futex_rla_len;
-			thread_args[i].has_blk_sigset	= core->thread_core->has_blk_sigset;
-			thread_args[i].blk_sigset	= core->thread_core->blk_sigset;
+			thread_args[i].futex_rla	= tcore->thread_core->futex_rla;
+			thread_args[i].futex_rla_len	= tcore->thread_core->futex_rla_len;
+			thread_args[i].has_blk_sigset	= tcore->thread_core->has_blk_sigset;
+			thread_args[i].blk_sigset	= tcore->thread_core->blk_sigset;
 
-			ret = prep_sched_info(&thread_args[i].sp, core->thread_core);
+			ret = prep_sched_info(&thread_args[i].sp, tcore->thread_core);
 			if (ret)
 				goto err;
 		}
 
-		core_entry__free_unpacked(core, NULL);
+		core_entry__free_unpacked(tcore, NULL);
 
 		pr_info("Thread %4d stack %8p heap %8p rt_sigframe %8p\n",
 				i, thread_args[i].mem_zone.stack,
@@ -2000,6 +1961,46 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 
 	}
 
+	task_args->t.clear_tid_addr	= core->thread_info->clear_tid_addr;
+	task_args->ids			= *core->ids;
+	task_args->t.gpregs		= *core->thread_info->gpregs;
+	task_args->t.blk_sigset		= core->tc->blk_sigset;
+	task_args->t.has_blk_sigset	= true;
+
+	if (core->thread_core) {
+		task_args->t.has_futex		= true;
+		task_args->t.futex_rla		= core->thread_core->futex_rla;
+		task_args->t.futex_rla_len	= core->thread_core->futex_rla_len;
+
+		ret = prep_sched_info(&task_args->t.sp, core->thread_core);
+		if (ret)
+			goto err;
+	}
+
+	/* No longer need it */
+	core_entry__free_unpacked(core, NULL);
+
+	ret = prepare_itimers(pid, task_args);
+	if (ret < 0)
+		goto err;
+
+	ret = prepare_creds(pid, task_args);
+	if (ret < 0)
+		goto err;
+
+	ret = prepare_mm(pid, task_args);
+	if (ret < 0)
+		goto err;
+
+	mutex_init(&task_args->rst_lock);
+
+	/*
+	 * Now prepare run-time data for threads restore.
+	 */
+	task_args->nr_threads		= current->nr_threads;
+	task_args->clone_restore_fn	= (void *)restore_thread_exec_start;
+	task_args->thread_args		= thread_args;
+
 	close_image_dir();
 
 	pr_info("task_args: %p\n"
-- 
1.7.11.7



More information about the CRIU mailing list