[LTP] [PATCH] syscalls/fanotify0[135]: contain effects of FAN_MARK_MOUNT|FILESYSTEM to test device

Jan Stancek jstancek@redhat.com
Tue Mar 5 10:50:46 CET 2019


FAN_MARK_MOUNT|FILESYSTEM can set up monitoring for entire root /, which
can lead to interference from other background processes.

Use separate device/mount to isolate events from tests.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/fanotify/fanotify01.c |  8 ++++++--
 testcases/kernel/syscalls/fanotify/fanotify03.c | 14 ++++++++++----
 testcases/kernel/syscalls/fanotify/fanotify05.c |  8 ++++++--
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c
index a5585598705b..9b590746ed16 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify01.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify01.c
@@ -32,6 +32,8 @@
 #define BUF_SIZE 256
 #define TST_TOTAL 12
 
+#define MOUNT_PATH "fs_mnt"
+
 static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
@@ -325,7 +327,7 @@ pass:
 
 static void setup(void)
 {
-	sprintf(fname, "tfile_%d", getpid());
+	sprintf(fname, MOUNT_PATH"/tfile_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
 }
 
@@ -341,7 +343,9 @@ static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
-	.needs_root = 1
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_PATH,
 };
 
 #else
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index ae240a0eb505..1ef1c206b64a 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -38,6 +38,8 @@
 #define BUF_SIZE 256
 #define TST_TOTAL 3
 #define TEST_APP "fanotify_child"
+#define MOUNT_PATH "fs_mnt"
+#define FILE_EXEC_PATH MOUNT_PATH"/"TEST_APP
 
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
@@ -127,7 +129,7 @@ static struct tcase {
 static void generate_events(void)
 {
 	int fd;
-	char *const argv[] = {TEST_APP, NULL};
+	char *const argv[] = {FILE_EXEC_PATH, NULL};
 
 	/*
 	 * Generate sequence of events
@@ -144,7 +146,7 @@ static void generate_events(void)
 	if (close(fd) == -1)
 		exit(4);
 
-	if (execve(TEST_APP, argv, environ) != -1)
+	if (execve(FILE_EXEC_PATH, argv, environ) != -1)
 		exit(5);
 }
 
@@ -207,7 +209,7 @@ static int setup_mark(unsigned int n)
 	unsigned int i = 0;
 	struct tcase *tc = &tcases[n];
 	struct fanotify_mark_type *mark = &tc->mark;
-	char *const files[] = {fname, TEST_APP};
+	char *const files[] = {fname, FILE_EXEC_PATH};
 
 	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
@@ -345,8 +347,10 @@ static void test_fanotify(unsigned int n)
 
 static void setup(void)
 {
-	sprintf(fname, "fname_%d", getpid());
+	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
+
+	SAFE_CP(TEST_APP, FILE_EXEC_PATH);
 }
 
 static void cleanup(void)
@@ -367,6 +371,8 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.forks_child = 1,
 	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_PATH,
 	.resource_files = resource_files
 };
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify05.c b/testcases/kernel/syscalls/fanotify/fanotify05.c
index 52bf30ad27ab..de72e346a554 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify05.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify05.c
@@ -26,6 +26,8 @@
 #if defined(HAVE_SYS_FANOTIFY_H)
 #include <sys/fanotify.h>
 
+#define MOUNT_PATH "fs_mnt"
+
 /* Currently this is fixed in kernel... */
 #define MAX_EVENTS 16384
 
@@ -44,7 +46,7 @@ void test01(void)
 	 * generate events
 	 */
 	for (i = 0; i < MAX_EVENTS + 1; i++) {
-		sprintf(fname, "fname_%d", i);
+		sprintf(fname, MOUNT_PATH"/fname_%d", i);
 		fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0644);
 		SAFE_CLOSE(fd);
 	}
@@ -105,7 +107,7 @@ static void setup(void)
 			O_RDONLY);
 
 	if (fanotify_mark(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
-			  AT_FDCWD, ".") < 0) {
+			  AT_FDCWD, MOUNT_PATH) < 0) {
 		tst_brk(TBROK | TERRNO,
 			"fanotify_mark (%d, FAN_MARK_MOUNT | FAN_MARK_ADD, "
 			"FAN_OPEN, AT_FDCWD, \".\") failed",
@@ -125,6 +127,8 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_PATH,
 };
 #else
 	TST_TEST_TCONF("system doesn't have required fanotify support");
-- 
1.8.3.1



More information about the ltp mailing list