Skip to contentSkip to conversation

fanotify06: create a mount for test

PATCH New Jan Stancek 3 participants 5 messages Jun 29, 2016 – Jul 1, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fanotify06: create a mount for test

This testcase can rarely fail, when there is a background process modifying files on same mountpoint as is LTP's tmpdir:

fanotify06    1  TFAIL  :  fanotify06.c:212: group 0 got more than one event (48 > 24)
fanotify06    2  TFAIL  :  fanotify06.c:212: group 1 got more than one event (48 > 24)
fanotify06    3  TFAIL  :  fanotify06.c:212: group 2 got more than one event (48 > 24)
fanotify06    4  TFAIL  :  fanotify06.c:222: group 3 got event
fanotify06    5  TFAIL  :  fanotify06.c:222: group 4 got event
fanotify06    6  TPASS  :  group 5 got no event
fanotify06    7  TPASS  :  group 6 got no event
fanotify06    8  TPASS  :  group 7 got no event
fanotify06    9  TPASS  :  group 8 got no event

This patch creates a mount, which should be only used by this test to limit interference from rest of OS. It also adds missing tst_require_root().

---
 testcases/kernel/syscalls/fanotify/fanotify06.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify06.c +18 -0
index 93c960268b57..cdbc7a16c0d7 100644
@@ -42,6 +42,7 @@
 #include <sys/fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <sys/mount.h>
 #include <sys/syscall.h>
 #include "test.h"
 #include "linux_syscall_numbers.h"
@@ -80,6 +81,9 @@ static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
+#define MOUNT_NAME "mntpoint"
+static int mount_created;
+
 static void create_fanotify_groups(void)
 {
 	unsigned int p, i;
@@ -245,8 +249,15 @@ static void setup(void)
 
 	TEST_PAUSE;
 
+	tst_require_root();
 	tst_tmpdir();
 
+	SAFE_MKDIR(cleanup, MOUNT_NAME, 0755);
+	if (mount(MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL) < 0)
+		tst_brkm(TBROK | TERRNO, cleanup, "bind mount failed");
+	mount_created = 1;
+	SAFE_CHDIR(cleanup, MOUNT_NAME);
+
 	sprintf(fname, "tfile_%d", getpid());
 	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 	SAFE_WRITE(cleanup, 1, fd, fname, 1);
@@ -258,6 +269,13 @@ static void setup(void)
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
+
+	if (chdir(tst_get_tmpdir()) < 0)
+		tst_brkm(TBROK, NULL, "chdir(tmpdir) failed");
+
+	if (mount_created && tst_umount(MOUNT_NAME) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "umount failed");
+
 	tst_rmdir();
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 fanotify06: create a mount for test

Quoted 45 lines · Jan Stancek

This testcase can rarely fail, when there is a background process modifying files on same mountpoint as is LTP's tmpdir:

fanotify06    1  TFAIL  :  fanotify06.c:212: group 0 got more than one event (48 > 24)
fanotify06    2  TFAIL  :  fanotify06.c:212: group 1 got more than one event (48 > 24)
fanotify06    3  TFAIL  :  fanotify06.c:212: group 2 got more than one event (48 > 24)
fanotify06    4  TFAIL  :  fanotify06.c:222: group 3 got event
fanotify06    5  TFAIL  :  fanotify06.c:222: group 4 got event
fanotify06    6  TPASS  :  group 5 got no event
fanotify06    7  TPASS  :  group 6 got no event
fanotify06    8  TPASS  :  group 7 got no event
fanotify06    9  TPASS  :  group 8 got no event

This patch creates a mount, which should be only used by this test to limit interference from rest of OS. It also adds missing tst_require_root().

---
 testcases/kernel/syscalls/fanotify/fanotify06.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify06.c +4 -0
index 93c960268b57..cdbc7a16c0d7 100644
@@ -42,6 +42,7 @@
 #include <sys/fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <sys/mount.h>
 #include <sys/syscall.h>
 #include "test.h"
 #include "linux_syscall_numbers.h"
@@ -80,6 +81,9 @@ static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
+#define MOUNT_NAME "mntpoint"
+static int mount_created;
+
 static void create_fanotify_groups(void)
 {
 	unsigned int p, i;

testcases/kernel/syscalls/fanotify/fanotify06.c static void setup(void) · line 256

Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify06.c +3 -0
@@ -245,8 +249,15 @@ static void setup(void)
 
 	TEST_PAUSE;
 
+	tst_require_root();
 	tst_tmpdir();
 
+	SAFE_MKDIR(cleanup, MOUNT_NAME, 0755);
+	if (mount(MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL) < 0)

why not SAFE_MOUNT() here?

	SAFE_MOUNT(cleanup, MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL);
Quoted 27 lines
testcases/kernel/syscalls/fanotify/fanotify06.c +11 -0
+		tst_brkm(TBROK | TERRNO, cleanup, "bind mount failed");
+	mount_created = 1;
+	SAFE_CHDIR(cleanup, MOUNT_NAME);
+
 	sprintf(fname, "tfile_%d", getpid());
 	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 	SAFE_WRITE(cleanup, 1, fd, fname, 1);
@@ -258,6 +269,13 @@ static void setup(void)
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
+
+	if (chdir(tst_get_tmpdir()) < 0)
+		tst_brkm(TBROK, NULL, "chdir(tmpdir) failed");
+
+	if (mount_created && tst_umount(MOUNT_NAME) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "umount failed");
+
 	tst_rmdir();
 }
 
Signature · 5 lines
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH 1/1 fanotify06: create a mount for test

----- Original Message -----

Quoted 60 lines

From: "Li Wang" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected], [email protected]
Sent: Wednesday, 29 June, 2016 12:14:17 PM
Subject: Re: [LTP] [PATCH] fanotify06: create a mount for test

Quoted 53 lines · Jan Stancek

This testcase can rarely fail, when there is a background process modifying files on same mountpoint as is LTP's tmpdir:

fanotify06 1 TFAIL : fanotify06.c:212: group 0 got more than one
event (48 > 24)
fanotify06 2 TFAIL : fanotify06.c:212: group 1 got more than one
event (48 > 24)
fanotify06 3 TFAIL : fanotify06.c:212: group 2 got more than one
event (48 > 24)

fanotify06    4  TFAIL  :  fanotify06.c:222: group 3 got event
fanotify06    5  TFAIL  :  fanotify06.c:222: group 4 got event
fanotify06    6  TPASS  :  group 5 got no event
fanotify06    7  TPASS  :  group 6 got no event
fanotify06    8  TPASS  :  group 7 got no event
fanotify06    9  TPASS  :  group 8 got no event

This patch creates a mount, which should be only used by this test to limit interference from rest of OS. It also adds missing tst_require_root().

---
 testcases/kernel/syscalls/fanotify/fanotify06.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify06.c +4 -0
index 93c960268b57..cdbc7a16c0d7 100644
@@ -42,6 +42,7 @@
 #include <sys/fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <sys/mount.h>
 #include <sys/syscall.h>
 #include "test.h"
 #include "linux_syscall_numbers.h"
@@ -80,6 +81,9 @@ static int
 fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
+#define MOUNT_NAME "mntpoint"
+static int mount_created;
+
 static void create_fanotify_groups(void)
 {
testcases/kernel/syscalls/fanotify/fanotify06.c +0 -0
 	unsigned int p, i;
@@ -245,8 +249,15 @@ static void setup(void)
 
 	TEST_PAUSE;
 
Quoted 8 lines

testcases/kernel/syscalls/fanotify/fanotify06.c static void setup(void) · line 256

Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify06.c +3 -0
+	tst_require_root();
 	tst_tmpdir();
 
+	SAFE_MKDIR(cleanup, MOUNT_NAME, 0755);
+	if (mount(MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL) < 0)

why not SAFE_MOUNT() here?

	SAFE_MOUNT(cleanup, MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL);

Good point, I replaced it for SAFE_MOUNT locally
(holding off from sending v2 for now).

Thanks,
Jan

#3 lore raw

PATCH 1/1 fanotify06: create a mount for test

In reply to Jan Stancek
Quoted 13 lines · Jan Stancek

This testcase can rarely fail, when there is a background process modifying files on same mountpoint as is LTP's tmpdir:

fanotify06    1  TFAIL  :  fanotify06.c:212: group 0 got more than one event (48 > 24)
fanotify06    2  TFAIL  :  fanotify06.c:212: group 1 got more than one event (48 > 24)
fanotify06    3  TFAIL  :  fanotify06.c:212: group 2 got more than one event (48 > 24)
fanotify06    4  TFAIL  :  fanotify06.c:222: group 3 got event
fanotify06    5  TFAIL  :  fanotify06.c:222: group 4 got event
fanotify06    6  TPASS  :  group 5 got no event
fanotify06    7  TPASS  :  group 6 got no event
fanotify06    8  TPASS  :  group 7 got no event
fanotify06    9  TPASS  :  group 8 got no event
Quoted 5 lines

This patch creates a mount, which should be only used by this test to limit interference from rest of OS. It also adds missing tst_require_root().

Yeah, that is a good idea. The patch looks good to me so feel free to add:

Honza

Quoted 59 lines
---
 testcases/kernel/syscalls/fanotify/fanotify06.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify06.c +18 -0
index 93c960268b57..cdbc7a16c0d7 100644
@@ -42,6 +42,7 @@
 #include <sys/fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <sys/mount.h>
 #include <sys/syscall.h>
 #include "test.h"
 #include "linux_syscall_numbers.h"
@@ -80,6 +81,9 @@ static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
+#define MOUNT_NAME "mntpoint"
+static int mount_created;
+
 static void create_fanotify_groups(void)
 {
 	unsigned int p, i;
@@ -245,8 +249,15 @@ static void setup(void)
 
 	TEST_PAUSE;
 
+	tst_require_root();
 	tst_tmpdir();
 
+	SAFE_MKDIR(cleanup, MOUNT_NAME, 0755);
+	if (mount(MOUNT_NAME, MOUNT_NAME, NULL, MS_BIND, NULL) < 0)
+		tst_brkm(TBROK | TERRNO, cleanup, "bind mount failed");
+	mount_created = 1;
+	SAFE_CHDIR(cleanup, MOUNT_NAME);
+
 	sprintf(fname, "tfile_%d", getpid());
 	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 	SAFE_WRITE(cleanup, 1, fd, fname, 1);
@@ -258,6 +269,13 @@ static void setup(void)
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
+
+	if (chdir(tst_get_tmpdir()) < 0)
+		tst_brkm(TBROK, NULL, "chdir(tmpdir) failed");
+
+	if (mount_created && tst_umount(MOUNT_NAME) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "umount failed");
+
 	tst_rmdir();
 }
 
Signature · 1 line
1.8.3.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw

PATCH 1/1 fanotify06: create a mount for test

----- Original Message -----

Quoted 27 lines

From: "Jan Kara" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected], [email protected]
Sent: Wednesday, 29 June, 2016 9:50:40 PM
Subject: Re: [PATCH] fanotify06: create a mount for test

Quoted 20 lines · Jan Stancek

This testcase can rarely fail, when there is a background process modifying files on same mountpoint as is LTP's tmpdir:

fanotify06 1 TFAIL : fanotify06.c:212: group 0 got more than one
event (48 > 24)
fanotify06 2 TFAIL : fanotify06.c:212: group 1 got more than one
event (48 > 24)
fanotify06 3 TFAIL : fanotify06.c:212: group 2 got more than one
event (48 > 24)

fanotify06    4  TFAIL  :  fanotify06.c:222: group 3 got event
fanotify06    5  TFAIL  :  fanotify06.c:222: group 4 got event
fanotify06    6  TPASS  :  group 5 got no event
fanotify06    7  TPASS  :  group 6 got no event
fanotify06    8  TPASS  :  group 7 got no event
fanotify06    9  TPASS  :  group 8 got no event

This patch creates a mount, which should be only used by this test to limit interference from rest of OS. It also adds missing tst_require_root().

Quoted 7 lines
Quoted 1 line

Yeah, that is a good idea. The patch looks good to me so feel free to add:

Honza

Pushed.

Regards,
Jan