[CRIU] [PATCH] cgroups: Add ability to reuse existing cgroup yard directory

Andrew Vagin avagin at gmail.com
Wed Jul 22 04:23:00 PDT 2015


On Wed, Jun 17, 2015 at 10:29:22AM +0300, Cyrill Gorcunov wrote:
> 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.

Hello Cyrill,

I found a new error which is appeared with this patch.

[root at avagin-fc19-cr criu]# bash test/zdtm.sh  -r static/env00
Execute static/env00
./env00 --pidfile=env00.pid --outfile=env00.out --envname=ENV_00_TEST
Dump 3599
Restore
Test: zdtm/live/static/env00, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/env00, Namespace: 
Dump log   : /root/git/criu/test/dump/static/env00/3599/1/dump.log
--------------------------------- grep Error ---------------------------------
------------------------------------- END -------------------------------------
Restore log: /root/git/criu/test/dump/static/env00/3599/1/restore.log
--------------------------------- grep Error ---------------------------------
(00.009820)   3599: Error (cgroup.c:901): cg: Can't move into cpuset,cpu,cpuacct,blkio///tasks (-1/-1): Bad file descriptor
(00.009888) Error (cr-restore.c:1912): Restoring FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================


Steps to reproduce:

1. Apply this patch
diff --git a/test/zdtm.sh b/test/zdtm.sh
index d8a3a70..245c827 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -565,6 +565,7 @@ start_test()
        (
                # Here is no way to set FD_CLOEXEC on 3
                exec 3>&-
+               echo 0 > /sys/fs/cgroup/freezer/test/tasks
                make -C $tdir $tname.pid
        )
2. mkdir /sys/fs/cgroup/freezer/test
3. bash test/zdtm.sh  -r static/env00

Additional information:
[root at avagin-fc19-cr criu]# cat /proc/self/cgroup 
7:perf_event:/
6:net_cls:/
5:freezer:/
4:devices:/user.slice
3:memory:/
2:cpuset,cpu,cpuacct,blkio:/
1:name=systemd:/user.slice/user-0.slice/session-1.scope
[root at avagin-fc19-cr criu]# cat /proc/self/mountinfo | grep cgroup
23 16 0:20 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:8 - tmpfs tmpfs ro,mode=755
24 23 0:21 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:9 - cgroup cgroup rw,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd
26 23 0:23 / /sys/fs/cgroup/cpu,cpuacct,cpuset,blkio rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,cpuset,cpu,cpuacct,blkio
27 23 0:24 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:11 - cgroup cgroup rw,memory
28 23 0:25 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:12 - cgroup cgroup rw,devices
29 23 0:26 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,freezer
30 23 0:27 / /sys/fs/cgroup/net_cls rw,nosuid,nodev,noexec,relatime shared:14 - cgroup cgroup rw,net_cls
31 23 0:28 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:15 - cgroup cgroup rw,perf_event

> 
> 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
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list