[PATCH] dump: Introduce "post-dump" script action

Cyrill Gorcunov gorcunov at openvz.org
Fri Jul 12 15:08:01 EDT 2013


This is usefull if one needs to do some final action before checkpoint
is complete. For example in case of online migration one may provide
a script which would check the restore procedure on remote note
ended without errors, thus the script returns zero code and criu
simply kills running instance of application.

In turn, if migration failed, the script can return nonzero code
and criu won't kill the application but continue its execution
instead.

https://bugzilla.openvz.org/show_bug.cgi?id=2583

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c | 26 +++++++++++++++++++++++---
 util.c    |  2 ++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 863bffd..13ff6d4 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1637,6 +1637,7 @@ err:
 int cr_dump_tasks(pid_t pid)
 {
 	struct pstree_item *item;
+	int post_dump_ret = 0;
 	int ret = -1;
 
 	pr_info("========================================\n");
@@ -1717,15 +1718,34 @@ int cr_dump_tasks(pid_t pid)
 err:
 	close_cr_fdset(&glob_fdset);
 
+	if (!ret) {
+		/*
+		 * It might be a migration case, where we're asked
+		 * to dump everything, then some script transfer
+		 * image on a new node and we're supposed to kill
+		 * dumpee because it continue running somewhere
+		 * else.
+		 *
+		 * Thus ask user via script if we're to break
+		 * checkpoint.
+		 */
+		post_dump_ret = run_scripts("post-dump");
+		if (post_dump_ret) {
+			post_dump_ret = WEXITSTATUS(post_dump_ret);
+			pr_info("Post dump script passed with %d\n", post_dump_ret);
+		}
+	}
+
 	/*
 	 * If we've failed to do anything -- unlock all TCP sockets
 	 * so that the connections can go on. But if we succeeded --
 	 * don't, just close them silently.
 	 */
-	if (ret)
+	if (ret || post_dump_ret)
 		network_unlock();
 	pstree_switch_state(root_item,
-			ret ? TASK_ALIVE : opts.final_state);
+			    (ret || post_dump_ret) ?
+			    TASK_ALIVE : opts.final_state);
 	timing_stop(TIME_FROZEN);
 	free_pstree(root_item);
 	free_file_locks();
@@ -1740,5 +1760,5 @@ err:
 		pr_info("Dumping finished successfully\n");
 	}
 
-	return ret;
+	return post_dump_ret ? : ret;
 }
diff --git a/util.c b/util.c
index 69ecf5d..74c14ac 100644
--- a/util.c
+++ b/util.c
@@ -1,3 +1,5 @@
+#define _XOPEN_SOURCE
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
-- 
1.8.1.4


--HlL+5n6rz5pIUxbD--


More information about the CRIU mailing list