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

Pavel Emelyanov xemul at parallels.com
Fri May 22 09:48:05 PDT 2015


On 05/22/2015 06:33 PM, Cyrill Gorcunov wrote:
> Currently we always create temporary directory where we restore
> cgroups, but this won't work for case where we need to reuse
> bindmount cgroups.

Why? This yard is just a place where we see the cgroups hierarchy,
what's the problem with it?

> So using --cgroup-yard option one may define which directory to
> reuse instead of creating new one.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  Documentation/criu.txt |  3 +++
>  cgroup.c               | 47 +++++++++++++++++++++++++++--------------------
>  crtools.c              |  5 +++++
>  include/cr_options.h   |  1 +
>  4 files changed, 36 insertions(+), 20 deletions(-)
> 
> diff --git a/Documentation/criu.txt b/Documentation/criu.txt
> index 81783635af89..3d93900855bb 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 creating 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 b7fef38dd334..f8ec213d209b 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;
>  }
>  
> @@ -1128,26 +1130,31 @@ 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;
> -	}
> +	if (!opts.cg_yard) {
> +		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;
> +		}
> +	} else {
> +		cg_yard = opts.cg_yard;
> +		off = strlen(opts.cg_yard);
>  	}
>  
>  	pr_debug("Opening %s as cg yard\n", cg_yard);
> diff --git a/crtools.c b/crtools.c
> index 6da7afeed067..8f22cba71b93 100644
> --- a/crtools.c
> +++ b/crtools.c
> @@ -207,6 +207,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 +435,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 +678,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;
> 



More information about the CRIU mailing list