diff mbox series

[4/9] syscalls/fanotify10: Avoid undesired event in test

Message ID 20220905154239.2652169-5-amir73il@gmail.com
State Accepted
Headers show
Series Fanotify tests for FAN_MARK_IGNORE | expand

Commit Message

Amir Goldstein Sept. 5, 2022, 3:42 p.m. UTC
Open fd for syncfs before creating groups to avoid the
FAN_OPEN event that this open generates.

This event does not break any of the existing test cases,
but should avoid it to avoid noise in future test cases.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Comments

Petr Vorel Sept. 6, 2022, 4:51 p.m. UTC | #1
Hi,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
Petr Vorel Sept. 6, 2022, 5:09 p.m. UTC | #2
Hi all,

> +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
> @@ -66,6 +66,7 @@ static unsigned int fanotify_class[] = {
>  #define GROUPS_PER_PRIO 3

>  static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
> +static int fd_syncfs;

>  static char event_buf[EVENT_BUF_LEN];
>  static int exec_events_unsupported;
> @@ -342,14 +343,11 @@ static void show_fanotify_marks(int fd)
>  	}
>  }

> -static void drop_caches(const char *path)
Note for myself to add void here before merge
> +static void drop_caches()
>  {

fanotify10.c: In function ‘drop_caches’:
fanotify10.c:352:13: warning: old-style function definition [-Wold-style-definition]
  352 | static void drop_caches()

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 93340255f..b8358b489 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -66,6 +66,7 @@  static unsigned int fanotify_class[] = {
 #define GROUPS_PER_PRIO 3
 
 static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
+static int fd_syncfs;
 
 static char event_buf[EVENT_BUF_LEN];
 static int exec_events_unsupported;
@@ -342,14 +343,11 @@  static void show_fanotify_marks(int fd)
 	}
 }
 
-static void drop_caches(const char *path)
+static void drop_caches()
 {
-	int fd = SAFE_OPEN(path, O_RDONLY);
-
-	if (syncfs(fd) < 0)
+	if (syncfs(fd_syncfs) < 0)
 		tst_brk(TBROK | TERRNO, "Unexpected error when syncing filesystem");
 
-	SAFE_CLOSE(fd);
 	SAFE_FILE_PRINTF(DROP_CACHES_FILE, "3");
 }
 
@@ -364,6 +362,9 @@  static int create_fanotify_groups(unsigned int n)
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
 
+	/* Open fd for syncfs before creating groups to avoid the FAN_OPEN event */
+	fd_syncfs = SAFE_OPEN(MOUNT_PATH, O_RDONLY);
+
 	for (p = 0; p < num_classes; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_class[p] |
@@ -413,7 +414,7 @@  add_mark:
 	 * drop_caches should evict inode from cache and remove evictable marks
 	 */
 	if (evictable_ignored) {
-		drop_caches(tc->mark_path);
+		drop_caches();
 		for (p = 0; p < num_classes; p++) {
 			for (i = 0; i < GROUPS_PER_PRIO; i++) {
 				if (fd_notify[p][i] > 0)
@@ -435,6 +436,8 @@  static void cleanup_fanotify_groups(void)
 				SAFE_CLOSE(fd_notify[p][i]);
 		}
 	}
+	if (fd_syncfs > 0)
+		SAFE_CLOSE(fd_syncfs);
 }
 
 /* Flush out all pending dirty inodes and destructing marks */