[CRIU] [PATCH 1/3] zdtm: add a new test to check tmpfs in a non-root mntns (v2)

Andrey Vagin avagin at openvz.org
Fri Nov 13 06:56:45 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

v2: add a file mapping from a test tmpfs mount
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 test/zdtm.sh                            |   2 +
 test/zdtm/live/static/Makefile          |   1 +
 test/zdtm/live/static/tempfs_subns.c    | 119 ++++++++++++++++++++++++++++++++
 test/zdtm/live/static/tempfs_subns.desc |   1 +
 4 files changed, 123 insertions(+)
 create mode 100644 test/zdtm/live/static/tempfs_subns.c
 create mode 100644 test/zdtm/live/static/tempfs_subns.desc

diff --git a/test/zdtm.sh b/test/zdtm.sh
index f2bbd89..c4c4865 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -190,6 +190,7 @@ generate_test_list()
 		ns/static/session01
 		ns/static/tempfs
 		ns/static/tempfs_ro
+		ns/static/tempfs_subns
 		ns/static/mnt_ro_bind
 		ns/static/mount_paths
 		ns/static/bind-mount
@@ -335,6 +336,7 @@ rtc
 maps007
 tempfs
 tempfs_ro
+tempfs_subns
 mnt_ro_bind
 bind-mount
 mountpoints
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 90cd6f5..fd5a4f4 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -186,6 +186,7 @@ TST_DIR		=				\
 		overmount_sock			\
 		tempfs				\
 		tempfs_ro			\
+		tempfs_subns			\
 		mnt_ro_bind			\
 		mount_paths			\
 		bind-mount			\
diff --git a/test/zdtm/live/static/tempfs_subns.c b/test/zdtm/live/static/tempfs_subns.c
new file mode 100644
index 0000000..178400d
--- /dev/null
+++ b/test/zdtm/live/static/tempfs_subns.c
@@ -0,0 +1,119 @@
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <sys/mount.h>
+#include <signal.h>
+#include <sys/prctl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check tmpfs in a non-root mntns";
+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)
+{
+	int fds[2];
+	pid_t pid;
+	int fd, status;
+
+	test_init(argc, argv);
+
+	if (pipe(fds)) {
+		pr_perror("pipe");
+		return 1;
+	}
+
+	if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) {
+		pr_perror("mount");
+	}
+	pid = fork();
+	if (pid < 0) {
+		pr_perror("fork");
+		return 1;
+	}
+	if (pid == 0) {
+		void *addr;
+
+		pid = fork();
+		if (pid == 0) {
+			if (unshare(CLONE_NEWNS)) {
+				pr_perror("unshare");
+				return 1;
+			}
+			prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
+			while (1)
+				sleep(1);
+			return 1;
+		}
+		if (unshare(CLONE_NEWNS)) {
+			pr_perror("unshare");
+			return 1;
+		}
+		mkdir(dirname, 0755);
+		if (mount("zdtm", dirname, "tmpfs", 0, NULL)) {
+			pr_perror("mount");
+			return 1;
+		}
+
+		chdir(dirname);
+		fd = open("test", O_CREAT | O_RDWR | O_APPEND, 0666);
+		if (fd < 0) {
+			pr_perror("open");
+			return 1;
+		}
+		ftruncate(fd, PAGE_SIZE);
+		addr = mmap(NULL, PAGE_SIZE, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_FILE, fd, 0);
+		if (addr == MAP_FAILED) {
+			pr_perror("mmap");
+			return 1;
+		}
+
+		if (write(fds[1], &fd, sizeof(fd)) != sizeof(fd)) {
+			pr_perror("write");
+			return 1;
+		}
+
+		test_waitsig();
+		if (close(fd)) {
+			pr_perror("close");
+			return 1;
+		}
+
+		fd = open("test", O_RDONLY | O_APPEND);
+		if (fd < 0) {
+			pr_perror("open");
+			return 1;
+		}
+		close(fd);
+		return 0;
+	}
+	close(fds[1]);
+
+	if (read(fds[0], &fd, sizeof(fd)) != sizeof(fd)) {
+		pr_perror("read");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	kill(pid, SIGTERM);
+	status = -1;
+	if (waitpid(pid, &status, 0) != pid) {
+		pr_perror("waitpid");
+		return 1;
+	}
+	if (status) {
+		pr_err("Returned non-zero code: 0x%x\n", status);
+		return 1;
+	}
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/live/static/tempfs_subns.desc b/test/zdtm/live/static/tempfs_subns.desc
new file mode 100644
index 0000000..7657ba4
--- /dev/null
+++ b/test/zdtm/live/static/tempfs_subns.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.4.3



More information about the CRIU mailing list