[CRIU] [PATCH 1/2] cgroups: Add ability to reuse existing cgroup yard directory
Cyrill Gorcunov
gorcunov at openvz.org
Wed May 27 06:53:02 PDT 2015
Currently we always create temporary directory where we restore
cgroups, but this won't work in case if mounting cgroups is forbidden
from inside of a container for some reason (as in OpenVZ kernel).
So one can pass --cgroup-yard option to specify an existing
directory where cgroups are living. By default we assume it
lays in /sys/fs/cgroup.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Documentation/criu.txt | 3 +++
cgroup.c | 35 ++++++-----------------------------
crtools.c | 6 ++++++
include/cr_options.h | 1 +
4 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index 81783635af89..43958cba4204 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -218,6 +218,9 @@ Restores previously checkpointed processes.
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 /sys/fs/cgroup.
+
*--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 b7fef38dd334..6541c628f9e4 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -935,14 +935,10 @@ int prepare_task_cgroup(struct pstree_item *me)
void fini_cgroup(void)
{
- if (!cg_yard)
- return;
-
- close_service_fd(CGROUP_YARD);
- umount2(cg_yard, MNT_DETACH);
- rmdir(cg_yard);
- xfree(cg_yard);
- cg_yard = NULL;
+ if (cg_yard) {
+ close_service_fd(CGROUP_YARD);
+ cg_yard = NULL;
+ }
}
static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
@@ -1128,27 +1124,8 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
pr_info("Preparing cgroups yard\n");
- 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;
- }
-
- 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;
- }
+ cg_yard = opts.cg_yard;
+ off = strlen(opts.cg_yard);
pr_debug("Opening %s as cg yard\n", cg_yard);
i = open(cg_yard, O_DIRECTORY);
diff --git a/crtools.c b/crtools.c
index 6da7afeed067..25a117757bb5 100644
--- a/crtools.c
+++ b/crtools.c
@@ -56,6 +56,7 @@ void init_opts(void)
INIT_LIST_HEAD(&opts.inherit_fds);
INIT_LIST_HEAD(&opts.new_cgroup_roots);
+ opts.cg_yard = "/sys/fs/cgroup";
opts.cpu_cap = CPU_CAP_DEFAULT;
opts.manage_cgroups = false;
opts.ps_socket = -1;
@@ -207,6 +208,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 },
{ },
};
@@ -434,6 +436,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;
@@ -674,6 +679,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 28bed45b0cd8..ecd3825224c6 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -60,6 +60,7 @@ struct cr_options {
bool force_irmap;
char **exec_cmd;
bool manage_cgroups;
+ char *cg_yard;
char *new_global_cg_root;
struct list_head new_cgroup_roots;
bool autodetect_ext_mounts;
--
2.1.0
More information about the CRIU
mailing list