[CRIU] [PATCH v2 1/3] plugin: add POST_DUMP and POST_RESTORE hooks to c/r custom properties

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Thu Feb 25 07:55:41 PST 2016


Put them just before post-dump and post restore scripts respectively.

Those are alternatives to post-dump/restore script hooks, and can be
used in case one needs to c/r some custom for instance non-mainstream
container property which can't be restored by criu directly.

The difference from scripts is that plugins can reuse criu's protobuf
images managment subsystem to easily save it's data alongside other
criu's images, and one doesn't need to invent a bike.

General naming convention is good here to explain that hooks can be
reused, they are not only for VZCT plugin.

https://bugs.openvz.org/browse/OVZ-6696
https://jira.sw.ru/browse/PSBM-44145

v2: add bug links, switch to more general hook names and explain why

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/cr-dump.c             | 12 +++++++++++-
 criu/cr-restore.c          | 10 ++++++++++
 criu/include/criu-plugin.h |  5 +++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 27cc1d6..6749cb2 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -1519,9 +1519,18 @@ static int cr_dump_finish(int ret)
 	if (bfd_flush_images())
 		ret = -1;
 
+	post_dump_ret = run_plugins(POST_DUMP);
+	if (post_dump_ret != 0) {
+		if (post_dump_ret == -ENOTSUP)
+			post_dump_ret = 0;
+		else
+			pr_err("Post dump plugin failed with %d\n",
+			       post_dump_ret);
+	}
+
 	cr_plugin_fini(CR_PLUGIN_STAGE__DUMP, ret);
 
-	if (!ret) {
+	if (!ret && !post_dump_ret) {
 		/*
 		 * It might be a migration case, where we're asked
 		 * to dump everything, then some script transfer
@@ -1608,6 +1617,7 @@ int cr_dump_tasks(pid_t pid)
 		pr_err("Pre dump script failed with %d!\n", pre_dump_ret);
 		goto err;
 	}
+
 	if (init_stats(DUMP_STATS))
 		goto err;
 
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 67032a3..b96b5cd 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2039,6 +2039,16 @@ static int restore_root_task(struct pstree_item *init)
 	if (ret < 0)
 		goto out_kill;
 
+	ret = run_plugins(POST_RESTORE);
+	if (ret != 0) {
+		if (ret != -ENOTSUP) {
+			pr_err("Aborting restore due to post-restore plugin ret code %d\n", ret);
+			timing_stop(TIME_RESTORE);
+			write_stats(RESTORE_STATS);
+			goto out_kill;
+		}
+	}
+
 	ret = run_scripts(ACT_POST_RESTORE);
 	if (ret != 0) {
 		pr_err("Aborting restore due to post-restore script ret code %d\n", ret);
diff --git a/criu/include/criu-plugin.h b/criu/include/criu-plugin.h
index b76f5f8..02438d9 100644
--- a/criu/include/criu-plugin.h
+++ b/criu/include/criu-plugin.h
@@ -50,6 +50,9 @@ enum {
 
 	CR_PLUGIN_HOOK__DUMP_EXT_LINK		= 6,
 
+	CR_PLUGIN_HOOK__POST_DUMP		= 7,
+	CR_PLUGIN_HOOK__POST_RESTORE		= 8,
+
 	CR_PLUGIN_HOOK__MAX
 };
 
@@ -63,6 +66,8 @@ DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__RESTORE_EXT_FILE, int id);
 DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__DUMP_EXT_MOUNT, char *mountpoint, int id);
 DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__RESTORE_EXT_MOUNT, int id, char *mountpoint, char *old_root, int *is_file);
 DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__DUMP_EXT_LINK, int index, int type, char *kind);
+DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__POST_DUMP);
+DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__POST_RESTORE);
 
 enum {
 	CR_PLUGIN_STAGE__DUMP,
-- 
1.9.3



More information about the CRIU mailing list