[CRIU] [PATCH] cgroups: Add ability to reuse existing cgroup yard directory
Cyrill Gorcunov
gorcunov at openvz.org
Wed Jun 17 00:29:22 PDT 2015
This is update to commit 860df95f859c which makes --cgroup-yard
option to take an argument but by default we make and mount
own cgroup yard.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Documentation/criu.txt | 4 ++++
cgroup.c | 53 ++++++++++++++++++++++++++++----------------------
crtools.c | 5 +++++
include/cr_options.h | 1 +
4 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index 4cf97917b198..cabbc4bc46b7 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -235,6 +235,10 @@ The '<mode>' may be one of below.
Change the root cgroup the controller will be installed into. No controller
means that root is the default for all controllers not specified.
+*--cgroup-yard* '<dir>'::
+ Use directory '<dir>' as cgroups yard instead of creating
+ and mounting own one.
+
*--tcp-established*::
Restore previously dumped established TCP connections. This implies that
the network has been locked between *dump* and *restore* phases so other
diff --git a/cgroup.c b/cgroup.c
index a4e0146e75ad..084433d0aff6 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -939,9 +939,11 @@ void fini_cgroup(void)
return;
close_service_fd(CGROUP_YARD);
- umount2(cg_yard, MNT_DETACH);
- rmdir(cg_yard);
- xfree(cg_yard);
+ if (!opts.cg_yard) {
+ umount2(cg_yard, MNT_DETACH);
+ rmdir(cg_yard);
+ xfree(cg_yard);
+ }
cg_yard = NULL;
}
@@ -1134,32 +1136,37 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
int off, i, ret;
char paux[PATH_MAX];
- if (!opts.manage_cgroups)
- return 0;
-
pr_info("Preparing cgroups yard (cgroups restore mode %#x)\n",
opts.manage_cgroups);
+ if (!opts.manage_cgroups)
+ return 0;
- off = sprintf(paux, ".criu.cgyard.XXXXXX");
- if (mkdtemp(paux) == NULL) {
- pr_perror("Can't make temp cgyard dir");
- return -1;
- }
+ if (opts.cg_yard) {
+ cg_yard = opts.cg_yard;
+ off = strlen(opts.cg_yard);
+ strcpy(paux, opts.cg_yard);
+ } else {
+ off = sprintf(paux, ".criu.cgyard.XXXXXX");
+ if (mkdtemp(paux) == NULL) {
+ pr_perror("Can't make temp cgyard dir");
+ return -1;
+ }
- cg_yard = xstrdup(paux);
- if (!cg_yard) {
- rmdir(paux);
- return -1;
- }
+ cg_yard = xstrdup(paux);
+ if (!cg_yard) {
+ rmdir(paux);
+ return -1;
+ }
- if (mount("none", cg_yard, "tmpfs", 0, NULL)) {
- pr_perror("Can't mount tmpfs in cgyard");
- goto err;
- }
+ if (mount("none", cg_yard, "tmpfs", 0, NULL)) {
+ pr_perror("Can't mount tmpfs in cgyard");
+ goto err;
+ }
- if (mount("none", cg_yard, NULL, MS_PRIVATE, NULL)) {
- pr_perror("Can't make cgyard private");
- goto err;
+ if (mount("none", cg_yard, NULL, MS_PRIVATE, NULL)) {
+ pr_perror("Can't make cgyard private");
+ goto err;
+ }
}
pr_debug("Opening %s as cg yard\n", cg_yard);
diff --git a/crtools.c b/crtools.c
index b085d33d102a..bce37f7f93ec 100644
--- a/crtools.c
+++ b/crtools.c
@@ -234,6 +234,7 @@ int main(int argc, char *argv[], char *envp[])
{ "enable-fs", required_argument, 0, 1065 },
{ "enable-external-sharing", no_argument, 0, 1066 },
{ "enable-external-masters", no_argument, 0, 1067 },
+ { "cgroup-yard", required_argument, 0, 1068 },
{ },
};
@@ -462,6 +463,9 @@ int main(int argc, char *argv[], char *envp[])
case 1067:
opts.enable_external_masters = true;
break;
+ case 1068:
+ opts.cg_yard = optarg;
+ break;
case 'M':
{
char *aux;
@@ -703,6 +707,7 @@ usage:
" change the root cgroup the controller will be\n"
" installed into. No controller means that root is the\n"
" default for all controllers not specified.\n"
+" --cgroup-yard DIR use DIR as premounted cgroups external yard\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/include/cr_options.h b/include/cr_options.h
index 9ab8bbaaef64..d405ad40cb35 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -72,6 +72,7 @@ struct cr_options {
bool force_irmap;
char **exec_cmd;
unsigned int manage_cgroups;
+ char *cg_yard;
char *new_global_cg_root;
struct list_head new_cgroup_roots;
bool autodetect_ext_mounts;
--
2.4.3
More information about the CRIU
mailing list