[CRIU] [PATCH] cg: rpc -- Add bindings for custom cgroup props engine

Cyrill Gorcunov gorcunov at openvz.org
Mon May 30 08:45:09 PDT 2016


For handling  --cgroup-props, --cgroup-props-file and
--cgroup-dump-controller from RPC interface.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/cr-service.c | 12 ++++++++++++
 images/rpc.proto  |  4 ++++
 lib/c/criu.c      | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/c/criu.h      |  3 +++
 4 files changed, 65 insertions(+)

diff --git a/criu/cr-service.c b/criu/cr-service.c
index 93d146fa061e..bc196eda4dc9 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -28,6 +28,7 @@
 #include "net.h"
 #include "mount.h"
 #include "cgroup.h"
+#include "cgroup-props.h"
 #include "action-scripts.h"
 #include "sockets.h"
 #include "irmap.h"
@@ -453,6 +454,17 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 		opts.manage_cgroups = mode;
 	}
 
+	if (req->cgroup_props)
+		opts.cgroup_props = req->cgroup_props;
+
+	if (req->cgroup_props_file)
+		opts.cgroup_props_file = req->cgroup_props_file;
+
+	for (i = 0; i < req->n_cgroup_dump_controller; i++) {
+		if (!cgp_add_dump_controller(req->cgroup_dump_controller[i]))
+			goto err;
+	}
+
 	if (req->has_auto_ext_mnt)
 		opts.autodetect_ext_mounts = req->auto_ext_mnt;
 
diff --git a/images/rpc.proto b/images/rpc.proto
index 0bd4ef70f8ed..9c9ae4891619 100644
--- a/images/rpc.proto
+++ b/images/rpc.proto
@@ -98,6 +98,10 @@ message criu_opts {
 	optional uint32			empty_ns	= 38;
 	repeated join_namespace		join_ns		= 39;
 	optional uint32			unshare		= 40;
+
+	optional string			cgroup_props		= 41;
+	optional string			cgroup_props_file	= 42;
+	repeated string			cgroup_dump_controller	= 43;
 }
 
 message criu_dump_resp {
diff --git a/lib/c/criu.c b/lib/c/criu.c
index 52d1b61d6371..7211a476b4d8 100644
--- a/lib/c/criu.c
+++ b/lib/c/criu.c
@@ -700,6 +700,52 @@ err:
 	return -ENOMEM;
 }
 
+int criu_local_add_cg_props(criu_opts *opts, char *stream)
+{
+	char *new;
+
+	new = strdup(stream);
+	if (!new)
+		return -ENOMEM;
+
+	free(opts->rpc->cgroup_props);
+	opts->rpc->cgroup_props = new;
+	return 0;
+}
+
+int criu_local_add_cg_props_file(criu_opts *opts, char *path)
+{
+	char *new;
+
+	new = strdup(path);
+	if (!new)
+		return -ENOMEM;
+
+	free(opts->rpc->cgroup_props_file);
+	opts->rpc->cgroup_props_file = new;
+	return 0;
+}
+
+int criu_local_add_cg_dump_controller(criu_opts *opts, char *name)
+{
+	char **new;
+	size_t nr;
+
+	nr = opts->n_cgroup_dump_controller + 1;
+	new = realloc(opts->cgroup_dump_controller, nr * sizeof(char *));
+	if (!new)
+		return -ENOMEM;
+
+	new[opts->n_cgroup_dump_controller] = strdup(name);
+	if (new[opts->n_cgroup_dump_controller])
+		return -ENOMEM;
+
+	opts->n_cgroup_dump_controller = nr;
+	opts->cgroup_dump_controller = new;
+
+	return 0;
+}
+
 int criu_add_skip_mnt(char *mnt)
 {
 	return criu_local_add_skip_mnt(global_opts, mnt);
diff --git a/lib/c/criu.h b/lib/c/criu.h
index 0898be024f63..1085cd3decd4 100644
--- a/lib/c/criu.h
+++ b/lib/c/criu.h
@@ -191,6 +191,9 @@ int criu_local_add_enable_fs(criu_opts *opts, char *fs);
 int criu_local_add_skip_mnt(criu_opts *opts, char *mnt);
 void criu_local_set_ghost_limit(criu_opts *opts, unsigned int limit);
 int criu_local_add_irmap_path(criu_opts *opts, char *path);
+int criu_local_add_cg_props(criu_opts *opts, char *stream);
+int criu_local_add_cg_props_file(criu_opts *opts, char *path);
+int criu_local_add_cg_dump_controller(criu_opts *opts, char *name);
 
 void criu_local_set_notify_cb(criu_opts *opts, int (*cb)(char *action, criu_notify_arg_t na));
 
-- 
2.5.5



More information about the CRIU mailing list