[CRIU] [PATCH] zdtm: check how criu can dump file systems if some mount points are overmounted

Andrey Vagin avagin at openvz.org
Fri May 13 16:05:28 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

Test-for: c59759345e6e ("mount: dump a file system only if a mount point isn't overmounted")
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile                  |   1 +
 test/zdtm/static/tempfs_overmounted01.c    | 118 +++++++++++++++++++++++++++++
 test/zdtm/static/tempfs_overmounted01.desc |   1 +
 3 files changed, 120 insertions(+)
 create mode 100644 test/zdtm/static/tempfs_overmounted01.c
 create mode 100644 test/zdtm/static/tempfs_overmounted01.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index afad959..b0be980 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -206,6 +206,7 @@ TST_DIR		=				\
 		overmount_sock			\
 		tempfs				\
 		tempfs_overmounted		\
+		tempfs_overmounted01		\
 		tempfs_ro			\
 		tempfs_subns			\
 		mnt_ro_bind			\
diff --git a/test/zdtm/static/tempfs_overmounted01.c b/test/zdtm/static/tempfs_overmounted01.c
new file mode 100644
index 0000000..e868b18
--- /dev/null
+++ b/test/zdtm/static/tempfs_overmounted01.c
@@ -0,0 +1,118 @@
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <linux/limits.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check how file systems are dumped if some mount points are overmounted";
+const char *test_author	= "Andrei Vagin <avagin at gmail.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	task_waiter_t lock;
+	int pid, status = -1;
+
+	test_init(argc, argv);
+
+	task_waiter_init(&lock);
+
+	mkdir(dirname, 0700);
+
+	pid = fork();
+	if (pid < 0) {
+		pr_perror("fork");
+		return 1;
+	}
+	if (pid == 0) {
+		if (mount("zdtm", dirname, "tmpfs", 0, "") < 0) {
+			pr_err("Can't mount tmpfs");
+			return 1;
+		}
+		if (chdir(dirname)) {
+			pr_err("chdir");
+			return 1;
+		}
+
+		/*
+		 * We don't know a direction in which criu enumerates mount,
+		 * so lets create two chains of mounts.
+		 */
+
+		/* Create a chain when a parent mount is overmounted */
+		mkdir("a", 0700);
+		mkdir("b", 0700);
+		if (mount("zdtm1", "a", "tmpfs", 0, "") ||
+		    mount("a", "b", NULL, MS_BIND, "")) {
+			pr_perror("Can't mount tmpfs");
+			return 1;
+		}
+
+		mkdir("a/b", 0700);
+		mkdir("a/b/c", 0700);
+		if (mount("a/b", "a", NULL, MS_BIND, "")) {
+			pr_perror("mount");
+			return 1;
+		}
+
+		if (mount("b", "a/c", NULL, MS_MOVE, "")) {
+			pr_perror("Can't mount tmpfs");
+			return 1;
+		}
+
+		/* create a second chain where a child mount is overmounted*/
+		if (mount("zdtm2", "b", "tmpfs", 0, "")) {
+			pr_perror("can't mount tmpfs");
+			return 1;
+		}
+		mkdir("b/b", 0700);
+		mkdir("b/b/z", 0700);
+		if (mount("b", "b/b", NULL, MS_BIND, NULL) ||
+		    mount("b/b/b", "b/b", NULL, MS_BIND, NULL)) {
+			pr_perror("can't mount tmpfs");
+			return 1;
+		}
+
+		task_waiter_complete(&lock, 1);
+
+		test_waitsig();
+		if (umount2("a", MNT_DETACH)) {
+			pr_perror("umount");
+			return 1;
+		}
+		if (umount2("b/b", MNT_DETACH) ||
+		    umount2("b/b", MNT_DETACH)) {
+			pr_perror("umount");
+			return 1;
+		}
+
+		if (access("a/b/c", R_OK) || access("b/b/z", R_OK)) {
+			pr_perror("access");
+			return 1;
+		}
+		return 0;
+	}
+
+	task_waiter_wait4(&lock, 1);
+
+	test_daemon();
+	test_waitsig();
+
+	kill(pid, SIGTERM);
+	wait(&status);
+	if (status) {
+		fail();
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/static/tempfs_overmounted01.desc b/test/zdtm/static/tempfs_overmounted01.desc
new file mode 100644
index 0000000..7657ba4
--- /dev/null
+++ b/test/zdtm/static/tempfs_overmounted01.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list