[CRIU] [PATCH 3/4] cg: Add ability to dump specified controllers only
Cyrill Gorcunov
gorcunov at openvz.org
Fri May 13 13:03:45 PDT 2016
For example in containers case there might be a number
of controllers mounted on the node which we should not
carry inside image when container is migrated. So
add ability to dump predefined controllers only
specified via command line --cgroup-dump-controller
option.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
criu/cgroup-props.c | 39 +++++++++++++++++++++++++++++++++++++--
criu/crtools.c | 8 ++++++++
criu/include/cgroup-props.h | 1 +
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/criu/cgroup-props.c b/criu/cgroup-props.c
index 5328efc22d3e..2bd75aeef4bd 100644
--- a/criu/cgroup-props.c
+++ b/criu/cgroup-props.c
@@ -474,12 +474,41 @@ err:
return ret;
}
+static char **dump_controllers;
+static size_t nr_dump_controllers;
+
+bool cgp_add_dump_controller(const char *name)
+{
+ if (xrealloc_safe(&dump_controllers, (nr_dump_controllers + 1) * sizeof(char *))) {
+ pr_err("Can't add controller \"%s\" to mark\n", name);
+ return false;
+ }
+
+ dump_controllers[nr_dump_controllers] = xstrdup(name);
+ if (!dump_controllers[nr_dump_controllers])
+ return false;
+
+ pr_debug("Mark controller \"%s\" to dump\n", name);
+ nr_dump_controllers++;
+ return true;
+}
+
bool cgp_should_skip_controller(const char *name)
{
+ size_t i;
+
/*
- * FIXME Implement!
+ * Dump all by default.
*/
- return false;
+ if (!nr_dump_controllers)
+ return false;
+
+ for (i = 0; i < nr_dump_controllers; i++) {
+ if (!strcmp(name, dump_controllers[i]))
+ return false;
+ }
+
+ return true;
}
const cgp_t *cgp_get_props(const char *name)
@@ -497,8 +526,14 @@ const cgp_t *cgp_get_props(const char *name)
void cgp_fini(void)
{
cgp_list_entry_t *p, *t;
+ size_t i;
list_for_each_entry_safe(p, t, &cgp_list, list)
cgp_free(p);
INIT_LIST_HEAD(&cgp_list);
+
+ for (i = 0; i < nr_dump_controllers; i++)
+ xfree(dump_controllers[i]);
+ xfree(dump_controllers);
+ nr_dump_controllers = 0;
}
diff --git a/criu/crtools.c b/criu/crtools.c
index 99daee3fe2c0..d87df88d0c14 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -323,6 +323,7 @@ int main(int argc, char *argv[], char *envp[])
{ "all", no_argument, 0, 1079 },
{ "cgroup-props", required_argument, 0, 1080 },
{ "cgroup-props-file", required_argument, 0, 1081 },
+ { "cgroup-dump-controller", required_argument, 0, 1082 },
{ },
};
@@ -631,6 +632,10 @@ int main(int argc, char *argv[], char *envp[])
case 1081:
opts.cgroup_props_file = optarg;
break;
+ case 1082:
+ if (!cgp_add_dump_controller(optarg))
+ return 1;
+ break;
case 'V':
pr_msg("Version: %s\n", CRIU_VERSION);
if (strcmp(CRIU_GITID, "0"))
@@ -884,6 +889,9 @@ usage:
" --cgroup-props-file FILE\n"
" same as --cgroup-props but taking descrition\n"
" from the path specified.\n"
+" --cgroup-dump-controller NAME\n"
+" define cgroup controller to be dumped\n"
+" and skip anything else present in system.\n"
" --skip-mnt PATH ignore this mountpoint when dumping the mount namespace.\n"
" --enable-fs FSNAMES a comma separated list of filesystem names or \"all\".\n"
" force criu to (try to) dump/restore these filesystem's\n"
diff --git a/criu/include/cgroup-props.h b/criu/include/cgroup-props.h
index e6c96bae94f8..0e5201098393 100644
--- a/criu/include/cgroup-props.h
+++ b/criu/include/cgroup-props.h
@@ -12,6 +12,7 @@ typedef struct {
extern cgp_t cgp_global;
extern const cgp_t *cgp_get_props(const char *name);
extern bool cgp_should_skip_controller(const char *name);
+extern bool cgp_add_dump_controller(const char *name);
extern int cgp_init(char *stream, size_t len, char *path);
extern void cgp_fini(void);
--
2.5.5
More information about the CRIU
mailing list