Commit 860df95f authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

cgroups: Add ability to reuse existing cgroup yard directory

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a65bffe3
...@@ -218,6 +218,9 @@ Restores previously checkpointed processes. ...@@ -218,6 +218,9 @@ Restores previously checkpointed processes.
Change the root cgroup the controller will be installed into. No controller Change the root cgroup the controller will be installed into. No controller
means that root is the default for all controllers not specified. 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*:: *--tcp-established*::
Restore previously dumped established TCP connections. This implies that Restore previously dumped established TCP connections. This implies that
the network has been locked between *dump* and *restore* phases so other the network has been locked between *dump* and *restore* phases so other
......
...@@ -935,14 +935,10 @@ int prepare_task_cgroup(struct pstree_item *me) ...@@ -935,14 +935,10 @@ int prepare_task_cgroup(struct pstree_item *me)
void fini_cgroup(void) void fini_cgroup(void)
{ {
if (!cg_yard) if (cg_yard) {
return; close_service_fd(CGROUP_YARD);
cg_yard = NULL;
close_service_fd(CGROUP_YARD); }
umount2(cg_yard, MNT_DETACH);
rmdir(cg_yard);
xfree(cg_yard);
cg_yard = NULL;
} }
static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p, static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
...@@ -1128,27 +1124,8 @@ static int prepare_cgroup_sfd(CgroupEntry *ce) ...@@ -1128,27 +1124,8 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
pr_info("Preparing cgroups yard\n"); pr_info("Preparing cgroups yard\n");
off = sprintf(paux, ".criu.cgyard.XXXXXX"); cg_yard = opts.cg_yard;
if (mkdtemp(paux) == NULL) { off = strlen(opts.cg_yard);
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;
}
pr_debug("Opening %s as cg yard\n", cg_yard); pr_debug("Opening %s as cg yard\n", cg_yard);
i = open(cg_yard, O_DIRECTORY); i = open(cg_yard, O_DIRECTORY);
......
...@@ -56,6 +56,7 @@ void init_opts(void) ...@@ -56,6 +56,7 @@ void init_opts(void)
INIT_LIST_HEAD(&opts.inherit_fds); INIT_LIST_HEAD(&opts.inherit_fds);
INIT_LIST_HEAD(&opts.new_cgroup_roots); INIT_LIST_HEAD(&opts.new_cgroup_roots);
opts.cg_yard = "/sys/fs/cgroup";
opts.cpu_cap = CPU_CAP_DEFAULT; opts.cpu_cap = CPU_CAP_DEFAULT;
opts.manage_cgroups = false; opts.manage_cgroups = false;
opts.ps_socket = -1; opts.ps_socket = -1;
...@@ -207,6 +208,7 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -207,6 +208,7 @@ int main(int argc, char *argv[], char *envp[])
{ "enable-fs", required_argument, 0, 1065 }, { "enable-fs", required_argument, 0, 1065 },
{ "enable-external-sharing", no_argument, 0, 1066 }, { "enable-external-sharing", no_argument, 0, 1066 },
{ "enable-external-masters", no_argument, 0, 1067 }, { "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[]) ...@@ -434,6 +436,9 @@ int main(int argc, char *argv[], char *envp[])
case 1067: case 1067:
opts.enable_external_masters = true; opts.enable_external_masters = true;
break; break;
case 1068:
opts.cg_yard = optarg;
break;
case 'M': case 'M':
{ {
char *aux; char *aux;
...@@ -674,6 +679,7 @@ usage: ...@@ -674,6 +679,7 @@ 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-yard DIR use DIR as premounted cgroups external yard\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"
......
...@@ -60,6 +60,7 @@ struct cr_options { ...@@ -60,6 +60,7 @@ struct cr_options {
bool force_irmap; bool force_irmap;
char **exec_cmd; char **exec_cmd;
bool manage_cgroups; bool manage_cgroups;
char *cg_yard;
char *new_global_cg_root; char *new_global_cg_root;
struct list_head new_cgroup_roots; struct list_head new_cgroup_roots;
bool autodetect_ext_mounts; bool autodetect_ext_mounts;
......
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