[CRIU] [PATCH] opts: add --manage-cgroups option

Tycho Andersen tycho.andersen at canonical.com
Mon Aug 4 22:07:24 PDT 2014


criu managed cgroups is now an opt-in thing, so by default criu does not manage
(i.e. dump or restore) cgroups. This allows users to preserve the
previous behavior.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 cgroup.c             | 6 ++++--
 cr-service.c         | 3 +++
 crtools.c            | 5 +++++
 include/cr_options.h | 1 +
 lib/criu.c           | 6 ++++++
 lib/criu.h           | 1 +
 protobuf/rpc.proto   | 1 +
 7 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index 06311e4..66302ea 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -10,6 +10,7 @@
 #include "list.h"
 #include "xmalloc.h"
 #include "cgroup.h"
+#include "cr_options.h"
 #include "pstree.h"
 #include "proc_parse.h"
 #include "util.h"
@@ -390,7 +391,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
 		 * The on-stack ctls is moved into cs inside
 		 * the get_cg_set routine.
 		 */
-		if (cs != criu_cgset && collect_cgroups(&cs->ctls))
+		if (cs != criu_cgset && opts.manage_cgroups && collect_cgroups(&cs->ctls))
 			return -1;
 	}
 
@@ -771,7 +772,8 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
 			goto err;
 		}
 
-		if (prepare_cgroup_dirs(paux, off + name_off, ctrl->dirs, ctrl->n_dirs))
+		if (opts.manage_cgroups &&
+		    prepare_cgroup_dirs(paux, off + name_off, ctrl->dirs, ctrl->n_dirs))
 			goto err;
 
 	}
diff --git a/cr-service.c b/cr-service.c
index 64ce751..8726aa6 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -303,6 +303,9 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 	if (req->has_cpu_cap)
 		opts.cpu_cap = req->cpu_cap;
 
+	if (req->has_manage_cgroups)
+		opts.manage_cgroups = req->manage_cgroups;
+
 	return 0;
 }
 
diff --git a/crtools.c b/crtools.c
index b662fff..a5ebd26 100644
--- a/crtools.c
+++ b/crtools.c
@@ -49,6 +49,7 @@ void init_opts(void)
 	INIT_LIST_HEAD(&opts.ext_mounts);
 
 	opts.cpu_cap = CPU_CAP_ALL;
+	opts.manage_cgroups = false;
 }
 
 static int parse_ns_string(const char *ptr)
@@ -167,6 +168,7 @@ int main(int argc, char *argv[])
 		{ "force-irmap", no_argument, 0, 58},
 		{ "ext-mount-map", required_argument, 0, 'M'},
 		{ "exec-cmd", no_argument, 0, 59},
+		{ "manage-cgroups", no_argument, 0, 60},
 		{ },
 	};
 
@@ -352,6 +354,9 @@ int main(int argc, char *argv[])
 		case 59:
 			has_exec_cmd = true;
 			break;
+		case 60:
+			opts.manage_cgroups = true;
+			break;
 		case 'M':
 			{
 				char *aux;
diff --git a/include/cr_options.h b/include/cr_options.h
index 55ca70b..0d11aa7 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -51,6 +51,7 @@ struct cr_options {
 	unsigned int		cpu_cap;
 	bool			force_irmap;
 	char			**exec_cmd;
+	bool			manage_cgroups;
 };
 
 extern struct cr_options opts;
diff --git a/lib/criu.c b/lib/criu.c
index ca6c6aa..45006e2 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -152,6 +152,12 @@ void criu_set_root(char *root)
 	opts->root = strdup(root);
 }
 
+void criu_set_manage_cgroups(bool manage)
+{
+	opts->has_manage_cgroups = true;
+	opts->manage_cgroups = manage;
+}
+
 void criu_set_log_file(char *log_file)
 {
 	opts->log_file = strdup(log_file);
diff --git a/lib/criu.h b/lib/criu.h
index 18faaef..94c5979 100644
--- a/lib/criu.h
+++ b/lib/criu.h
@@ -47,6 +47,7 @@ void criu_set_log_level(int log_level);
 void criu_set_log_file(char *log_file);
 void criu_set_cpu_cap(unsigned int cap);
 void criu_set_root(char *root);
+void criu_set_manage_cgroups(bool manage);
 int criu_set_exec_cmd(int argc, char *argv[]);
 int criu_add_ext_mount(char *key, char *val);
 int criu_add_veth_pair(char *in, char *out);
diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
index e50d97c..7098111 100644
--- a/protobuf/rpc.proto
+++ b/protobuf/rpc.proto
@@ -45,6 +45,7 @@ message criu_opts {
 	repeated string			exec_cmd	= 22;
 
 	repeated ext_mount_map		ext_mnt		= 23;
+	optional bool			manage_cgroups	= 24;
 }
 
 message criu_dump_resp {
-- 
1.9.1



More information about the CRIU mailing list