[CRIU] [RFC 2/2] plugin: Add protobuf read/write hooks

Cyrill Gorcunov gorcunov at openvz.org
Thu Sep 18 01:14:09 PDT 2014


Sometime we might need to modify protobuf objects which are to
written to image and read from. For this sake introduce two new
plugin entry points:

 - CR_PLUGIN_HOOK__PB_READ_OBJ: run at moment when PB object is
   read from image but not yet passed to criu for further handling,
   so that plugin can modify its data

 - CR_PLUGIN_HOOK__PB_WRITE_OBJ: run at moment when PB object is
   about to be written, plugin can modify its contents before criu
   pack it and write into image

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/criu-plugin.h |  5 +++++
 protobuf.c            | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/criu-plugin.h b/include/criu-plugin.h
index 4be697b0cb15..e419c37f6bc6 100644
--- a/include/criu-plugin.h
+++ b/include/criu-plugin.h
@@ -50,6 +50,9 @@ enum {
 
 	CR_PLUGIN_HOOK__DUMP_EXT_LINK		= 6,
 
+	CR_PLUGIN_HOOK__PB_READ_OBJ		= 7,
+	CR_PLUGIN_HOOK__PB_WRITE_OBJ		= 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__PB_READ_OBJ, int fd, void *obj, int type);
+DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__PB_WRITE_OBJ, int fd, void *obj, int type);
 
 enum {
 	CR_PLUGIN_STAGE__DUMP,
diff --git a/protobuf.c b/protobuf.c
index f73fb285a08e..def271894150 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -17,6 +17,7 @@
 #include "string.h"
 #include "sockets.h"
 #include "cr_options.h"
+#include "plugin.h"
 
 #include "protobuf.h"
 
@@ -568,6 +569,13 @@ int do_pb_read_one(int fd, void **pobj, int type, bool eof)
 		pr_err("Failed unpacking object %p from %s\n",
 		       pobj, image_name(fd));
 		goto err;
+	} else {
+		ret = run_plugins(PB_READ_OBJ, fd, *pobj, type);
+		if (ret < 0 && ret != -ENOTSUP) {
+			pr_err("Plugin failed to handle PB object %p from %s\n",
+			       pobj, image_name(fd));
+			goto err;
+		}
 	}
 
 	ret = 1;
@@ -599,6 +607,14 @@ int pb_write_one(int fd, void *obj, int type)
 		return -1;
 	}
 
+	ret = run_plugins(PB_WRITE_OBJ, fd, obj, type);
+	if (ret < 0 && ret != -ENOTSUP) {
+		pr_err("Plugin failed to handle PB object %p to %s\n",
+		       obj, image_name(fd));
+		goto err;
+	} else
+		ret = -1;
+
 	size = cr_pb_descs[type].getpksize(obj);
 	if (size > (u32)sizeof(local)) {
 		buf = xmalloc(size);
-- 
1.9.3



More information about the CRIU mailing list