[CRIU] [PATCH] opts: add --manage-cgroups option
Tycho Andersen
tycho.andersen at canonical.com
Wed Aug 6 11:23:01 PDT 2014
On Wed, Aug 06, 2014 at 10:30:30AM +0400, Pavel Emelyanov wrote:
> On 08/05/2014 09:07 AM, Tycho Andersen wrote:
> > 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.
>
> With this the zdtm's cgroup00 and cgroup01 both start to fail since
> cgroups are not managed. You can specify options that should be passed
> to criu dump/restore in per-test manner by putting them into $test.opts
> files. E.g. look at test/zdtm/live/static/unlink_fstat03.opts
Ah, yes, sorry about that.
> And one more thing:
>
>
> > --- a/crtools.c
> > +++ b/crtools.c
> > @@ -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},
>
> Would you also add a line to the the --help message.
I just put it under "Special resources support", let me know if there
is a better place.
Tycho
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 use the previous behavior.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
cgroup.c | 6 ++++--
cr-service.c | 3 +++
crtools.c | 6 ++++++
include/cr_options.h | 1 +
lib/criu.c | 6 ++++++
lib/criu.h | 1 +
protobuf/rpc.proto | 1 +
test/zdtm/live/static/cgroup00.opts | 1 +
test/zdtm/live/static/cgroup01.opts | 1 +
9 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 test/zdtm/live/static/cgroup00.opts
create mode 100644 test/zdtm/live/static/cgroup01.opts
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 9504c14..c00413c 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -304,6 +304,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 28d343e..6caea08 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},
{ },
};
@@ -353,6 +355,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;
@@ -541,6 +546,7 @@ usage:
" --force-irmap force resolving names for inotify/fsnotify watches\n"
" -M|--ext-mount-map KEY:VALUE\n"
" add external mount mapping\n"
+" --manage-cgroups dump or restore cgroups the process is in\n"
"\n"
"* Logging:\n"
" -o|--log-file FILE log file name\n"
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 {
diff --git a/test/zdtm/live/static/cgroup00.opts b/test/zdtm/live/static/cgroup00.opts
new file mode 100644
index 0000000..998cb32
--- /dev/null
+++ b/test/zdtm/live/static/cgroup00.opts
@@ -0,0 +1 @@
+--manage-cgroups
diff --git a/test/zdtm/live/static/cgroup01.opts b/test/zdtm/live/static/cgroup01.opts
new file mode 100644
index 0000000..998cb32
--- /dev/null
+++ b/test/zdtm/live/static/cgroup01.opts
@@ -0,0 +1 @@
+--manage-cgroups
--
1.9.1
More information about the CRIU
mailing list