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

Cyrill Gorcunov gorcunov at openvz.org
Thu May 21 12:33:56 PDT 2015


Currently we always create temporary directory where we restore
cgroups, but this won't work for case where we need to reuse
bindmount cgroups. 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 c307abf7605f..2e3a071f014c 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -230,6 +230,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 d0d693f50605..391aa17173d9 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.cgroup_yard) {
+		umount2(cg_yard, MNT_DETACH);
+		rmdir(cg_yard);
+		xfree(cg_yard);
+	}
 	cg_yard = NULL;
 }
 
@@ -1171,26 +1173,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.cgroup_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.cgroup_yard;
+		off = strlen(opts.cgroup_yard);
 	}
 
 	pr_debug("Opening %s as cg yard\n", cg_yard);
diff --git a/crtools.c b/crtools.c
index d8993be28cd0..3bdec63f5cff 100644
--- a/crtools.c
+++ b/crtools.c
@@ -238,6 +238,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 },
 		{ },
 	};
 
@@ -466,6 +467,9 @@ int main(int argc, char *argv[], char *envp[])
 		case 1067:
 			opts.enable_external_masters = true;
 			break;
+		case 1068:
+			opts.cgroup_yard = optarg;
+			break;
 		case 'M':
 			{
 				char *aux;
@@ -707,6 +711,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 0843187d34b2..03674963e8f1 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -69,6 +69,7 @@ struct cr_options {
 	bool			force_irmap;
 	char			**exec_cmd;
 	unsigned int		manage_cgroups;
+	char			*cgroup_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