[CRIU] [PATCH] Add pre-dump and pre-restore action scripts

Matthew Krafczyk krafczyk.matthew at gmail.com
Mon Oct 5 15:02:48 PDT 2015


This allows the user to perform actions before dumping or restoration
occurs.

Signed-off-by: Matthew Krafczyk <krafczyk.matthew at gmail.com>
---
 Documentation/criu.txt   |  6 ++++++
 action-scripts.c         |  2 ++
 cr-dump.c                |  6 ++++++
 cr-restore.c             | 10 +++++++++-
 include/action-scripts.h | 12 +++++++-----
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index 84de897..652706e 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -76,9 +76,15 @@ The following levels are available:
     Add an external action script.
     The environment variable *CRTOOLS_SCRIPT_ACTION* contains one of the
     actions:
+        * *pre-dump*
+            run an action prior to beginning a *dump*
+
         * *post-dump*
             run an action upon *dump* completion;
 
+        * *pre-restore*
+            run an action prior to beginning a *restore*
+
         * *post-restore*
             run an action upon *restore* completion;
 
diff --git a/action-scripts.c b/action-scripts.c
index 4c39a25..e37bafd 100644
--- a/action-scripts.c
+++ b/action-scripts.c
@@ -12,7 +12,9 @@
 #include "action-scripts.h"
 
 static const char *action_names[ACT_MAX] = {
+	[ ACT_PRE_DUMP ]	= "pre-dump",
 	[ ACT_POST_DUMP ]	= "post-dump",
+	[ ACT_PRE_RESTORE ]	= "pre-restore",
 	[ ACT_POST_RESTORE ]	= "post-restore",
 	[ ACT_NET_LOCK ]	= "network-lock",
 	[ ACT_NET_UNLOCK ]	= "network-unlock",
diff --git a/cr-dump.c b/cr-dump.c
index 3af077b..16b45b6 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1442,12 +1442,18 @@ int cr_dump_tasks(pid_t pid)
 {
 	struct pstree_item *item;
 	int post_dump_ret = 0;
+	int pre_dump_ret = 0;
 	int ret = -1;
 
 	pr_info("========================================\n");
 	pr_info("Dumping processes (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
+	pre_dump_ret = run_scripts(ACT_PRE_DUMP);
+	if (pre_dump_ret != 0) {
+		pr_err("Pre dump script failed with %d!\n", post_dump_ret);
+		goto err;
+	}
 	if (init_stats(DUMP_STATS))
 		goto err;
 
diff --git a/cr-restore.c b/cr-restore.c
index 33205e4..dc57ad5 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1736,6 +1736,14 @@ static int restore_root_task(struct pstree_item *init)
 	enum trace_flags flag = TRACE_ALL;
 	int ret, fd, mnt_ns_fd = -1;
 
+	ret = run_scripts(ACT_PRE_RESTORE);
+	if (ret != 0) {
+		pr_err("Aborting restore due to pre-restore script ret code %d\n", ret);
+		timing_stop(TIME_RESTORE);
+		write_stats(RESTORE_STATS);
+		goto out_kill;
+	}
+
 	fd = open("/proc", O_DIRECTORY | O_RDONLY);
 	if (fd < 0) {
 		pr_perror("Unable to open /proc");
@@ -1870,7 +1878,7 @@ static int restore_root_task(struct pstree_item *init)
 
 	ret = run_scripts(ACT_POST_RESTORE);
 	if (ret != 0) {
-		pr_err("Aborting restore due to script ret code %d\n", ret);
+		pr_err("Aborting restore due to post-restore script ret code %d\n", ret);
 		timing_stop(TIME_RESTORE);
 		write_stats(RESTORE_STATS);
 		goto out_kill;
diff --git a/include/action-scripts.h b/include/action-scripts.h
index 684221f..52f7531 100644
--- a/include/action-scripts.h
+++ b/include/action-scripts.h
@@ -10,11 +10,13 @@ struct script {
 #define SCRIPT_RPC_NOTIFY	(char *)0x1
 
 enum script_actions {
-	ACT_POST_DUMP		= 0,
-	ACT_POST_RESTORE	= 1,
-	ACT_NET_LOCK		= 2,
-	ACT_NET_UNLOCK		= 3,
-	ACT_SETUP_NS		= 4,
+	ACT_PRE_DUMP		= 0,
+	ACT_POST_DUMP		= 1,
+	ACT_PRE_RESTORE		= 2,
+	ACT_POST_RESTORE	= 3,
+	ACT_NET_LOCK		= 4,
+	ACT_NET_UNLOCK		= 5,
+	ACT_SETUP_NS		= 6,
 
 	ACT_MAX
 };
-- 
2.6.0



More information about the CRIU mailing list