All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] inotify: Add test for inotify mark destruction race
@ 2015-08-10 14:04 Jan Kara
  2015-08-11 14:14 ` Cyril Hrubis
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kara @ 2015-08-10 14:04 UTC (permalink / raw)
  To: ltp-list; +Cc: Jan Kara

Kernels prior to 4.2 have a race when inode is being deleted while
inotify group watching that inode is being torn down. When the race is
hit, the kernel crashes or loops. Test for that race.

The problem has been fixed by commit 8f2f3eb59dff "fsnotify: fix oops in
fsnotify_clear_marks_by_group_flags()".

Signed-off-by: Jan Kara <jack@suse.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/inotify/inotify06.c | 121 ++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 testcases/kernel/syscalls/inotify/inotify06.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 70d4945706ea..c532fe307df9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -449,6 +449,7 @@ inotify02 inotify02
 inotify03 inotify03
 inotify04 inotify04
 inotify05 inotify05
+inotify06 inotify06
 
 fanotify01 fanotify01
 fanotify02 fanotify02
diff --git a/testcases/kernel/syscalls/inotify/inotify06.c b/testcases/kernel/syscalls/inotify/inotify06.c
new file mode 100644
index 000000000000..373f5bd19217
--- /dev/null
+++ b/testcases/kernel/syscalls/inotify/inotify06.c
@@ -0,0 +1,121 @@
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <time.h>
+#include <signal.h>
+#include <sys/inotify.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/syscall.h>
+
+#include "test.h"
+#include "linux_syscall_numbers.h"
+#include "inotify.h"
+#include "safe_macros.h"
+
+char *TCID = "inotify06";
+int TST_TOTAL = 1;
+
+#if defined(HAVE_SYS_INOTIFY_H)
+#include <sys/inotify.h>
+
+/* Number of test loops to run the test for */
+#define TEARDOWNS 100000
+
+/* Number of files to test (must be > 1) */
+#define FILES 5
+
+char names[FILES][PATH_MAX];
+
+static void cleanup(void)
+{
+	tst_rmdir();
+}
+
+static void setup(void)
+{
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	for (i = 0; i < FILES; i++)
+		sprintf(names[i], "fname_%d", i);
+}
+
+int main(int ac, char **av)
+{
+	int inotify_fd, fd;
+	pid_t pid;
+	int i, lc;
+	int tests;
+
+	tst_parse_opts(ac, av, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		pid = fork();
+		if (pid == 0) {
+			while (1) {
+				for (i = 0; i < FILES; i++) {
+					fd = SAFE_OPEN(cleanup, names[i],
+						       O_CREAT | O_RDWR, 0600);
+					SAFE_CLOSE(cleanup, fd);
+				}
+				for (i = 0; i < FILES; i++)
+					SAFE_UNLINK(cleanup, names[i]);
+			}
+		} else if (pid == -1)
+			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
+
+		for (tests = 0; tests < TEARDOWNS; tests++) {
+			inotify_fd = syscall(__NR_inotify_init1, O_NONBLOCK);
+			if (inotify_fd < 0) {
+				if (errno == ENOSYS) {
+					tst_brkm(TCONF, cleanup,
+					 	 "inotify is not configured in this "
+						 "kernel.");
+				} else {
+					tst_brkm(TBROK | TERRNO, cleanup,
+						 "inotify_init failed");
+				}
+			}
+			for (i = 0; i < FILES; i++) {
+				/*
+				 * Both failure and success are fine since
+				 * files are being deleted in parallel - this
+				 * is what provokes the race we want to test
+				 * for...
+				 */
+				myinotify_add_watch(inotify_fd, names[i],
+						    IN_MODIFY);
+			}
+			SAFE_CLOSE(cleanup, inotify_fd);
+		}
+		/* We survived for given time - test succeeded */
+		tst_resm(TPASS, "kernel survived inotify beating");
+
+		/* Kill the child creating / deleting files and wait for it */
+		kill(pid, SIGKILL);
+		wait(NULL);
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+#else
+
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "system doesn't have required inotify support");
+}
+
+#endif
-- 
2.1.4


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-04-27  7:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 14:04 [LTP] [PATCH v2] inotify: Add test for inotify mark destruction race Jan Kara
2015-08-11 14:14 ` Cyril Hrubis
     [not found]   ` <20150811142035.GD2659@quack.suse.cz>
2015-08-25  9:29     ` Cyril Hrubis
     [not found]       ` <20150825103803.GA15280@quack.suse.cz>
2015-08-25 11:29         ` Cyril Hrubis
2016-04-14  2:06           ` Xiaoguang Wang
2016-04-14  8:15             ` Jan Kara
2016-04-14  8:14               ` Xiaoguang Wang
2016-04-14  8:46                 ` Jan Kara
2016-04-18  3:37                   ` Xiaoguang Wang
2016-04-19 13:05                     ` Jan Kara
2016-04-26 10:42                       ` Jan Kara
2016-04-27  4:48                         ` Xiaoguang Wang
2016-04-27  7:58                           ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.