[CRIU] [PATCH 5/5] zdtm: add a test to check a mount tree with overmounts

Andrei Vagin avagin at openvz.org
Wed Dec 7 23:30:10 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile         |   1 +
 test/zdtm/static/mntns_remap.c    | 101 ++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/mntns_remap.desc |   1 +
 3 files changed, 103 insertions(+)
 create mode 100644 test/zdtm/static/mntns_remap.c
 create mode 100644 test/zdtm/static/mntns_remap.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index c932093..42162f5 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -253,6 +253,7 @@ TST_DIR		=				\
 		cgroup04			\
 		cgroup_stray		\
 		unlink_fstat04			\
+		mntns_remap			\
 		mntns_open			\
 		mntns_link_remap		\
 		mntns_ghost			\
diff --git a/test/zdtm/static/mntns_remap.c b/test/zdtm/static/mntns_remap.c
new file mode 100644
index 0000000..f7cdba4
--- /dev/null
+++ b/test/zdtm/static/mntns_remap.c
@@ -0,0 +1,101 @@
+#define _GNU_SOURCE
+#include <sched.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check a case when one mount overmount another one";
+const char *test_author	= "Andrew Vagin <avagin at virtuozzo.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	task_waiter_t t;
+	pid_t pid;
+
+	test_init(argc, argv);
+
+	mkdir(dirname, 0755);
+	if (mount("zdtm", dirname, "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (chdir(dirname)) {
+		pr_perror("chdir");
+		return 1;
+	}
+	mkdir("1", 0755);
+	mkdir("2", 0755);
+	if (mount("1", "1", NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (mount(NULL, "1", NULL, MS_PRIVATE, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (mount("zdtm", "2", "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	mkdir("1/a", 0755);
+	mkdir("2/a", 0755);
+	if (mount("1/a", "1/a", NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (mount(NULL, "1/a", NULL, MS_SHARED, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (mount("1/a", "2/a", NULL, MS_BIND, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	mkdir("1/a/c", 0755);
+	if (mount("zdtm", "1/a/c", "tmpfs", 0, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+	if (mount("2", "1", NULL, MS_MOVE, NULL)) {
+		pr_perror("mount");
+		return 1;
+	}
+
+	task_waiter_init(&t);
+
+	pid = fork();
+	if (pid < 0)
+		return -1;
+
+	if (pid == 0) {
+		if (unshare(CLONE_NEWNS))
+			return 1;
+		task_waiter_complete_current(&t);
+		test_waitsig();
+		return 0;
+	}
+
+	task_waiter_wait4(&t, pid);
+	test_daemon();
+	test_waitsig();
+
+	kill(pid, SIGTERM);
+	wait(NULL);
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/mntns_remap.desc b/test/zdtm/static/mntns_remap.desc
new file mode 100644
index 0000000..3fd8e03
--- /dev/null
+++ b/test/zdtm/static/mntns_remap.desc
@@ -0,0 +1 @@
+{'flavor': 'ns', 'flags': 'suid', 'feature': 'mnt_id'}
-- 
2.7.4



More information about the CRIU mailing list