[CRIU] [PATCHv0 2/3] restore: split finalize_restore into two stages

Eugene Batalov eabatalov89 at gmail.com
Tue Nov 24 05:34:13 PST 2015


From: Evgeniy Akimov <geka666 at gmail.com>

First stage of finalize_restore unmaps the restorer blob, second stage
detaches from processes. After first stage process tree is completely
restored and processes are ready to continue run through sigreturn.
This splitting allows us to execute something between these stages (e.g.
restore freezer cgroup state).

Signed-off-by: Evgeniy Akimov <geka666 at gmail.com>
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 cr-restore.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 482b8e7..dddf4fd 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1714,25 +1714,21 @@ static int clear_breakpoints()
 	return ret;
 }
 
-static void finalize_restore(int status)
+static void finalize_restore(void)
 {
 	struct pstree_item *item;
 
 	for_each_pstree_item(item) {
 		pid_t pid = item->pid.real;
 		struct parasite_ctl *ctl;
-		int i;
 
 		if (!task_alive(item))
 			continue;
 
-		if (status  < 0)
-			goto detach;
-
 		/* Unmap the restorer blob */
 		ctl = parasite_prep_ctl(pid, NULL);
 		if (ctl == NULL)
-			goto detach;
+			continue;
 
 		parasite_unmap(ctl, (unsigned long)rsti(item)->munmap_restorer);
 
@@ -1740,7 +1736,20 @@ static void finalize_restore(int status)
 
 		if (item->state == TASK_STOPPED)
 			kill(item->pid.real, SIGSTOP);
-detach:
+	}
+}
+
+static void finalize_restore_detach(int status)
+{
+	struct pstree_item *item;
+
+	for_each_pstree_item(item) {
+		pid_t pid;
+		int i;
+
+		if (!task_alive(item))
+			continue;
+
 		for (i = 0; i < item->nr_threads; i++) {
 			pid = item->threads[i].real;
 			if (pid < 0) {
@@ -1945,11 +1954,11 @@ static int restore_root_task(struct pstree_item *init)
 	if (clear_breakpoints())
 		pr_err("Unable to flush breakpoints\n");
 
-	/*
-	 * finalize_restore() always detaches from processes and
-	 * they continue run through sigreturn.
-	 */
-	finalize_restore(ret);
+	if (ret == 0)
+		finalize_restore();
+
+	/* Detaches from processes and they continue run through sigreturn. */
+	finalize_restore_detach(ret);
 
 	write_stats(RESTORE_STATS);
 
-- 
1.9.1



More information about the CRIU mailing list