[CRIU] [PATCH 1/3] tests: cgroup02 should use --cgroup-root on dump

Tycho Andersen tycho.andersen at canonical.com
Tue Sep 20 11:08:20 PDT 2016


To mimic the environment that systemd is in when it causes the problem, we
preserve a prefix cgroup path across checkpoint and restore which the tasks
live below, and then we open a fd to this path. Without
--cgroup-root /prefix on dump, this test fails:

(00.030429)     32: Error (criu/files-reg.c:1487): File home/ubuntu/criu/test/zdtm/static/cgroup02.test/zdtmtst/prefix has bad mode 040600 (expect 040777)

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
Note that this will conflict with Pavel's patch:

[PATCH] zdtm/cgroup02: fix test using ropts instead of opts

and this one supercedes that one.
---
 test/zdtm/static/cgroup02.c    | 31 +++++++++++++++++++++++++------
 test/zdtm/static/cgroup02.desc |  2 +-
 test/zdtm/static/cgroup02.hook |  2 +-
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/test/zdtm/static/cgroup02.c b/test/zdtm/static/cgroup02.c
index d892b2f..ac6e9c0 100644
--- a/test/zdtm/static/cgroup02.c
+++ b/test/zdtm/static/cgroup02.c
@@ -17,7 +17,7 @@ static const char *cgname = "zdtmtst";
 static const char *subname = "oldroot";
 static const char *cgname2 = "zdtmtst.defaultroot";
 
-int mount_and_add(const char *controller, const char *path)
+int mount_and_add(const char *controller, const char *prefix, const char *path)
 {
 	char aux[1024], paux[1024], subdir[1024];
 	int cgfd, l;
@@ -39,11 +39,14 @@ int mount_and_add(const char *controller, const char *path)
 		goto err_rd;
 	}
 
-	sprintf(paux, "%s/%s", subdir, path);
+	sprintf(paux, "%s/%s", subdir, prefix);
+	mkdir(paux, 0600);
+
+	sprintf(paux, "%s/%s/%s", subdir, prefix, path);
 	mkdir(paux, 0600);
 
 	l = sprintf(aux, "%d", getpid());
-	sprintf(paux, "%s/%s/tasks", subdir, path);
+	sprintf(paux, "%s/%s/%s/tasks", subdir, prefix, path);
 
 	cgfd = open(paux, O_WRONLY);
 	if (cgfd < 0) {
@@ -93,21 +96,37 @@ int main(int argc, char **argv)
 	bool found_zdtmtstroot = false, found_newroot = false;
 	char paux[1024];
 	int ret = -1;
+	int fd;
 
 	test_init(argc, argv);
 
-	if (mount_and_add(cgname, subname))
+	if (mount_and_add(cgname, "prefix", subname))
 		goto out;
-	if (mount_and_add(cgname2, subname)) {
+	if (mount_and_add(cgname2, "prefix", subname)) {
 		sprintf(paux, "%s/%s", dirname, cgname);
 		umount(paux);
 		rmdir(paux);
 		goto out;
 	}
 
+	sprintf(paux, "%s/%s/prefix", dirname, cgname);
+	fd = open(paux, O_DIRECTORY);
+	if (fd < 0)
+		goto out_umount;
+
+	if (fchmod(fd, 0777) < 0) {
+		fail("fchmod");
+		goto out_umount;
+	}
+
 	test_daemon();
 	test_waitsig();
 
+	if (close(fd) < 0) {
+		fail("fd didn't survive");
+		goto out_umount;
+	}
+
 	cgf = fopen("/proc/self/mountinfo", "r");
 	if (cgf == NULL) {
 		fail("No mountinfo file");
@@ -118,7 +137,7 @@ int main(int argc, char **argv)
 		char *s;
 
 		s = strstr(paux, cgname);
-		if (s && test_exists(paux, "zdtmtstroot")) {
+		if (s && test_exists(paux, "prefix")) {
 			found_zdtmtstroot = true;
 		}
 
diff --git a/test/zdtm/static/cgroup02.desc b/test/zdtm/static/cgroup02.desc
index 4999d91..598cedf 100644
--- a/test/zdtm/static/cgroup02.desc
+++ b/test/zdtm/static/cgroup02.desc
@@ -1 +1 @@
-{'flavor': 'h', 'flags': 'suid', 'opts': '--manage-cgroups --cgroup-root /newroot --cgroup-root name=zdtmtst:/zdtmtstroot'}
+{'flavor': 'h', 'flags': 'suid', 'dopts': '--manage-cgroups --cgroup-root name=zdtmtst:/prefix', 'ropts': '--manage-cgroups --cgroup-root /newroot --cgroup-root name=zdtmtst:/prefix'}
diff --git a/test/zdtm/static/cgroup02.hook b/test/zdtm/static/cgroup02.hook
index 3214552..e4f1ee9 100755
--- a/test/zdtm/static/cgroup02.hook
+++ b/test/zdtm/static/cgroup02.hook
@@ -9,7 +9,7 @@ rmroots() {
 
 	mount -t cgroup none $tname -o "$1"
 
-	for d in "$tname/oldroot" "$tname/newroot" "$tname/zdtmtstroot"; do
+	for d in "$tname/prefix" "$tname/newroot"; do
 		test -d "$d" || continue
 		# sort by line length
 		for i in `find $d -type d | awk '{print length, $0}' | sort -rn | cut -d " " -f2-`; do
-- 
2.7.4



More information about the CRIU mailing list