[CRIU] [PATCH 1/2] zdtm: test inotifies in a sub mount namespace

Andrey Vagin avagin at openvz.org
Fri Oct 9 15:49:37 PDT 2015


From: Andrew Vagin <avagin at openvz.org>

Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 test/zdtm.list                    |  3 ++
 test/zdtm.sh                      |  2 ++
 test/zdtm/live/static/Makefile    |  2 ++
 test/zdtm/live/static/inotify00.c | 65 ++++++++++++++++++++++++++++++++++++---
 test/zdtm/live/static/inotify01.c |  1 +
 5 files changed, 68 insertions(+), 5 deletions(-)
 create mode 120000 test/zdtm/live/static/inotify01.c

diff --git a/test/zdtm.list b/test/zdtm.list
index b4e6fd5..6d6ec99 100644
--- a/test/zdtm.list
+++ b/test/zdtm.list
@@ -92,6 +92,9 @@ static/unlink_mmap02:
 static/rmdir_open:
 static/eventfs00:
 static/signalfd00:
+static/inotify01:
+  flags: suid
+  flavor: ns uns
 static/inotify00:
   opts: --link-remap
 static/inotify_irmap:
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 407c106..37dd183 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -229,6 +229,7 @@ generate_test_list()
 		ns/static/mntns_shared_bind02
 		ns/static/mntns_root_bind
 		ns/static/mntns_deleted
+		ns/static/inotify01
 	"
 
 	TEST_AIO="
@@ -365,6 +366,7 @@ seccomp_strict
 different_creds
 ipc_namespace
 utsname
+inotify01
 "
 
 TEST_EXPECTED_FAILURE="
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 16c7299..fb6a22e 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -192,6 +192,7 @@ TST_DIR		=				\
 		mount_paths			\
 		bind-mount			\
 		inotify00			\
+		inotify01			\
 		cgroup00			\
 		rmdir_open			\
 		cgroup01			\
@@ -344,6 +345,7 @@ mntns_link_remap:	override CFLAGS += -DZDTM_LINK_REMAP
 mntns_shared_bind02:		override CFLAGS += -DSHARED_BIND02
 maps02:		get_smaps_bits.o
 mlock_setuid:		get_smaps_bits.o
+inotify01:		override CFLAGS += -DINOTIFY01
 
 $(LIB):	force
 	$(Q) $(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/static/inotify00.c b/test/zdtm/live/static/inotify00.c
index 519afe3..9ca27ba 100644
--- a/test/zdtm/live/static/inotify00.c
+++ b/test/zdtm/live/static/inotify00.c
@@ -13,6 +13,10 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <dirent.h>
+#include <signal.h>
+#include <sched.h>
+#include <sys/mount.h>
+#include <sys/prctl.h>
 
 #include "zdtmtst.h"
 
@@ -114,14 +118,61 @@ int main (int argc, char *argv[])
 
 	test_init(argc, argv);
 
-	fd = inotify_init1(IN_NONBLOCK);
-	if (fd < 0) {
-		err("inotify_init failed");
+	if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+		err("Can't create directory %s", dirname);
 		exit(1);
 	}
 
-	if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
-		err("Can't create directory %s", dirname);
+#ifdef INOTIFY01
+{
+	pid_t pid;
+	task_waiter_t t;
+	task_waiter_init(&t);
+	static char buf[PATH_MAX];
+
+	if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) {
+		err("Unable to remount /");
+		return 1;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		err("Can't fork a test process");
+		exit(1);
+	}
+	if (pid == 0) {
+		int fd;
+
+		prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
+		if (unshare(CLONE_NEWNS)) {
+			err("Unable to unshare mount namespace");
+			exit(1);
+		}
+
+		if (mount("zdtm", dirname, "tmpfs", 0, NULL)) {
+			err("Unable to mount tmpfs");
+			exit(1);
+		}
+		fd = open(dirname, O_RDONLY);
+		if (fd < 0) {
+			err("Unable to open %s", dirname);
+			exit(1);
+		}
+		dup2(fd, 100);
+		task_waiter_complete_current(&t);
+		while (1)
+			sleep(1000);
+		exit(1);
+	}
+	task_waiter_wait4(&t, pid);
+	snprintf(buf, sizeof(buf), "/proc/%d/fd/100", pid);
+	dirname = buf;
+}
+#endif
+
+	fd = inotify_init1(IN_NONBLOCK);
+	if (fd < 0) {
+		err("inotify_init failed");
 		exit(1);
 	}
 
@@ -149,6 +200,7 @@ int main (int argc, char *argv[])
 	 * hardlink are opened.
 	 */
 
+#ifndef INOTIFY01
 	if (unlink(test_file_path)) {
 		err("can't unlink %s\n", test_file_path);
 		exit(1);
@@ -163,6 +215,7 @@ int main (int argc, char *argv[])
 		    emask, emask_bits);
 		exit(1);
 	}
+#endif
 
 	test_daemon();
 	test_waitsig();
@@ -179,6 +232,7 @@ int main (int argc, char *argv[])
 		return 1;
 	}
 
+#ifndef INOTIFY01
 	real_fd = open(test_file_path, O_CREAT | O_TRUNC | O_RDWR, 0644);
 	if (real_fd < 0) {
 		err("Can't create %s", test_file_path);
@@ -195,6 +249,7 @@ int main (int argc, char *argv[])
 		    emask, emask_bits);
 		return 1;
 	}
+#endif
 
 	pass();
 
diff --git a/test/zdtm/live/static/inotify01.c b/test/zdtm/live/static/inotify01.c
new file mode 120000
index 0000000..a7937cf
--- /dev/null
+++ b/test/zdtm/live/static/inotify01.c
@@ -0,0 +1 @@
+inotify00.c
\ No newline at end of file
-- 
2.4.3



More information about the CRIU mailing list