Commit c80a84f8 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

cg: Add ability to dump custom cgroup properties

We have some common predefined properties such as "cpuset.cpus" and etc gathered
in @cgp_predefined set, but there might be situation when only predefined ones
are not enough, so add ability to specify properties via --cgroup-props
and/or --cgroup-props-file options.

For example one may pass file with content

"cpu":
 - "strategy": "merge"
 - "properties": ["cpu.shares", "cpu.cfs_period_us"]

to dump custom properties for cpu controller.

The description is implemented in almost valid yaml, probably we will
need to support the various forms, but oneline is enough for now.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent ee0d1be1
...@@ -5,6 +5,7 @@ obj-y += aio.o ...@@ -5,6 +5,7 @@ obj-y += aio.o
obj-y += bfd.o obj-y += bfd.o
obj-y += bitmap.o obj-y += bitmap.o
obj-y += cgroup.o obj-y += cgroup.o
obj-y += cgroup-props.o
obj-y += cr-check.o obj-y += cr-check.o
obj-y += cr-dedup.o obj-y += cr-dedup.o
obj-y += cr-dump.o obj-y += cr-dump.o
......
This diff is collapsed.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "list.h" #include "list.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "cgroup.h" #include "cgroup.h"
#include "cgroup-props.h"
#include "cr_options.h" #include "cr_options.h"
#include "pstree.h" #include "pstree.h"
#include "proc_parse.h" #include "proc_parse.h"
...@@ -24,73 +25,6 @@ ...@@ -24,73 +25,6 @@
#include "images/core.pb-c.h" #include "images/core.pb-c.h"
#include "images/cgroup.pb-c.h" #include "images/cgroup.pb-c.h"
/*
* These string arrays have the names of all the properties that will be
* restored. To add a property for a cgroup type, add it to the
* corresponding char array above the NULL terminator. If you are adding
* a new cgroup family all together, you must also edit get_known_properties()
* Currently the code only supports properties with 1 value
*/
static const char *cpu_props[] = {
"cpu.shares",
"cpu.cfs_period_us",
"cpu.cfs_quota_us",
"cpu.rt_period_us",
"cpu.rt_runtime_us",
"notify_on_release",
NULL
};
static const char *memory_props[] = {
/* limit_in_bytes and memsw.limit_in_bytes must be set in this order */
"memory.limit_in_bytes",
"memory.memsw.limit_in_bytes",
"memory.use_hierarchy",
"notify_on_release",
NULL
};
static const char *cpuset_props[] = {
/*
* cpuset.cpus and cpuset.mems must be set before the process moves
* into its cgroup; they are "initialized" below to whatever the root
* values are in copy_special_cg_props so as not to cause ENOSPC when
* values are restored via this code.
*/
"cpuset.cpus",
"cpuset.mems",
"cpuset.memory_migrate",
"cpuset.cpu_exclusive",
"cpuset.mem_exclusive",
"cpuset.mem_hardwall",
"cpuset.memory_spread_page",
"cpuset.memory_spread_slab",
"cpuset.sched_load_balance",
"cpuset.sched_relax_domain_level",
"notify_on_release",
NULL
};
static const char *blkio_props[] = {
"blkio.weight",
"notify_on_release",
NULL
};
static const char *freezer_props[] = {
"notify_on_release",
NULL
};
static const char *global_props[] = {
"cgroup.clone_children",
"notify_on_release",
"cgroup.procs",
"tasks",
NULL
};
/* /*
* This structure describes set of controller groups * This structure describes set of controller groups
* a task lives in. The cg_ctl entries are stored in * a task lives in. The cg_ctl entries are stored in
...@@ -421,33 +355,14 @@ static void free_all_cgroup_props(struct cgroup_dir *ncd) ...@@ -421,33 +355,14 @@ static void free_all_cgroup_props(struct cgroup_dir *ncd)
ncd->n_properties = 0; ncd->n_properties = 0;
} }
static const char **get_known_properties(char *controller) static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd, const cgp_t *cgp)
{
const char **prop_arr = NULL;
if (!strcmp(controller, "cpu"))
prop_arr = cpu_props;
else if (!strcmp(controller, "memory"))
prop_arr = memory_props;
else if (!strcmp(controller, "cpuset"))
prop_arr = cpuset_props;
else if (!strcmp(controller, "blkio"))
prop_arr = blkio_props;
else if (!strcmp(controller, "freezer"))
prop_arr = freezer_props;
return prop_arr;
}
static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd,
const char **prop_arr)
{ {
int j; int j;
char buf[PATH_MAX]; char buf[PATH_MAX];
struct cgroup_prop *prop; struct cgroup_prop *prop;
for (j = 0; prop_arr != NULL && prop_arr[j] != NULL; ++j) { for (j = 0; cgp && j < cgp->nr_props; j++) {
if (snprintf(buf, PATH_MAX, "%s/%s", fpath, prop_arr[j]) >= PATH_MAX) { if (snprintf(buf, PATH_MAX, "%s/%s", fpath, cgp->props[j]) >= PATH_MAX) {
pr_err("snprintf output was truncated\n"); pr_err("snprintf output was truncated\n");
return -1; return -1;
} }
...@@ -457,7 +372,7 @@ static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd, ...@@ -457,7 +372,7 @@ static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd,
continue; continue;
} }
prop = create_cgroup_prop(prop_arr[j]); prop = create_cgroup_prop(cgp->props[j]);
if (!prop) { if (!prop) {
free_all_cgroup_props(ncd); free_all_cgroup_props(ncd);
return -1; return -1;
...@@ -483,15 +398,14 @@ static int add_cgroup_properties(const char *fpath, struct cgroup_dir *ncd, ...@@ -483,15 +398,14 @@ static int add_cgroup_properties(const char *fpath, struct cgroup_dir *ncd,
int i; int i;
for (i = 0; i < controller->n_controllers; ++i) { for (i = 0; i < controller->n_controllers; ++i) {
const cgp_t *cgp = cgp_get_props(controller->controllers[i]);
const char **prop_arr = get_known_properties(controller->controllers[i]); if (dump_cg_props_array(fpath, ncd, cgp) < 0) {
if (dump_cg_props_array(fpath, ncd, prop_arr) < 0) {
pr_err("dumping known properties failed"); pr_err("dumping known properties failed");
return -1; return -1;
} }
if (dump_cg_props_array(fpath, ncd, global_props) < 0) { if (dump_cg_props_array(fpath, ncd, &cgp_global) < 0) {
pr_err("dumping global properties failed"); pr_err("dumping global properties failed");
return -1; return -1;
} }
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "cpu.h" #include "cpu.h"
#include "elf.h" #include "elf.h"
#include "cgroup.h" #include "cgroup.h"
#include "cgroup-props.h"
#include "file-lock.h" #include "file-lock.h"
#include "page-xfer.h" #include "page-xfer.h"
#include "kerndat.h" #include "kerndat.h"
...@@ -1538,6 +1539,7 @@ static int cr_dump_finish(int ret) ...@@ -1538,6 +1539,7 @@ static int cr_dump_finish(int ret)
ret = -1; ret = -1;
cr_plugin_fini(CR_PLUGIN_STAGE__DUMP, ret); cr_plugin_fini(CR_PLUGIN_STAGE__DUMP, ret);
cgp_fini();
if (!ret) { if (!ret) {
/* /*
...@@ -1637,6 +1639,12 @@ int cr_dump_tasks(pid_t pid) ...@@ -1637,6 +1639,12 @@ int cr_dump_tasks(pid_t pid)
if (vdso_init()) if (vdso_init())
goto err; goto err;
if (cgp_init(opts.cgroup_props,
opts.cgroup_props ?
strlen(opts.cgroup_props) : 0,
opts.cgroup_props_file))
goto err;
if (parse_cg_info()) if (parse_cg_info())
goto err; goto err;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "mount.h" #include "mount.h"
#include "namespaces.h" #include "namespaces.h"
#include "cgroup.h" #include "cgroup.h"
#include "cgroup-props.h"
#include "cpu.h" #include "cpu.h"
#include "action-scripts.h" #include "action-scripts.h"
#include "irmap.h" #include "irmap.h"
...@@ -275,6 +276,8 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -275,6 +276,8 @@ int main(int argc, char *argv[], char *envp[])
{ "extra", no_argument, 0, 1077 }, { "extra", no_argument, 0, 1077 },
{ "experimental", no_argument, 0, 1078 }, { "experimental", no_argument, 0, 1078 },
{ "all", no_argument, 0, 1079 }, { "all", no_argument, 0, 1079 },
{ "cgroup-props", required_argument, 0, 1080 },
{ "cgroup-props-file", required_argument, 0, 1081 },
{ }, { },
}; };
...@@ -569,6 +572,12 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -569,6 +572,12 @@ int main(int argc, char *argv[], char *envp[])
opts.check_extra_features = true; opts.check_extra_features = true;
opts.check_experimental_features = true; opts.check_experimental_features = true;
break; break;
case 1080:
opts.cgroup_props = optarg;
break;
case 1081:
opts.cgroup_props_file = optarg;
break;
case 'V': case 'V':
pr_msg("Version: %s\n", CRIU_VERSION); pr_msg("Version: %s\n", CRIU_VERSION);
if (strcmp(CRIU_GITID, "0")) if (strcmp(CRIU_GITID, "0"))
...@@ -806,6 +815,13 @@ usage: ...@@ -806,6 +815,13 @@ usage:
" change the root cgroup the controller will be\n" " change the root cgroup the controller will be\n"
" installed into. No controller means that root is the\n" " installed into. No controller means that root is the\n"
" default for all controllers not specified.\n" " default for all controllers not specified.\n"
" --cgroup-props STRING\n"
" define cgroup controllers and properties\n"
" to be checkpointed, which are described\n"
" via STRING using simplified YAML format.\n"
" --cgroup-props-file FILE\n"
" same as --cgroup-props but taking descrition\n"
" from the path specified.\n"
" --skip-mnt PATH ignore this mountpoint when dumping the mount namespace.\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" " --enable-fs FSNAMES a comma separated list of filesystem names or \"all\".\n"
" force criu to (try to) dump/restore these filesystem's\n" " force criu to (try to) dump/restore these filesystem's\n"
......
#ifndef __CR_CGROUP_PROPS_H__
#define __CR_CGROUP_PROPS_H__
#include <stdbool.h>
typedef struct {
const char *name;
size_t nr_props;
const char **props;
} cgp_t;
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 int cgp_init(char *stream, size_t len, char *path);
extern void cgp_fini(void);
#endif /* __CR_CGROUP_PROPS_H__ */
...@@ -95,6 +95,8 @@ struct cr_options { ...@@ -95,6 +95,8 @@ struct cr_options {
char **exec_cmd; char **exec_cmd;
unsigned int manage_cgroups; unsigned int manage_cgroups;
char *new_global_cg_root; char *new_global_cg_root;
char *cgroup_props;
char *cgroup_props_file;
struct list_head new_cgroup_roots; struct list_head new_cgroup_roots;
bool autodetect_ext_mounts; bool autodetect_ext_mounts;
bool enable_external_sharing; bool enable_external_sharing;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "namespaces.h" #include "namespaces.h"
#include "files-reg.h" #include "files-reg.h"
#include "cgroup.h" #include "cgroup.h"
#include "cgroup-props.h"
#include "protobuf.h" #include "protobuf.h"
#include "images/fdinfo.pb-c.h" #include "images/fdinfo.pb-c.h"
...@@ -2232,6 +2233,18 @@ int parse_cgroup_file(FILE *f, struct list_head *retl, unsigned int *n) ...@@ -2232,6 +2233,18 @@ int parse_cgroup_file(FILE *f, struct list_head *retl, unsigned int *n)
if (e) if (e)
*e = '\0'; *e = '\0';
/*
* Controllers and their props might be
* configured the way some of them are
* not taken into the image for migration
* sake or container specifics.
*/
if (cgp_should_skip_controller(name)) {
pr_debug("cg-prop: Skipping controller %s\n", name);
xfree(ncc);
continue;
}
ncc->name = xstrdup(name); ncc->name = xstrdup(name);
ncc->path = xstrdup(path); ncc->path = xstrdup(path);
ncc->cgns_prefix = 0; ncc->cgns_prefix = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment