Skip to contentSkip to conversation

Fanotify tests for v5.9

PATCH New Amir Goldstein 3 participants 17 messages Sep 9, 2020 – Sep 10, 2020

lore
Share & tools
lore
#0 lore raw

cover Fanotify tests for v5.9

Hi Petr,

Following are the tests that were used to develop the upcoming fanotify features in v5.9.

The inotify/dnotify tests and fanotify09 test case are regression tests for a mid series bug that has been fixed before the merge.

fanotify10 gets another set of test cases to catch yet another ignored mask logic bug. The fix commit will be too hard to backport IMO, so perhaps these test cases should go into a new test with .min_kver = "5.9".

Thanks,
Amir.

Amir Goldstein (10):
syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME syscalls/fanotify16: Test more event types with name syscalls/fanotify16: Add test cases more init flag combinations syscalls/fanotify16: Verify child fid info syscalls/fcntl: New test for F_NOTIFY (dnotify) syscalls/inotify: New test for watches on both parent and child syscalls/fanotify09: Add test case with parent and subdir marks syscalls/fanotify10: Test with group flag FAN_REPORT_NAME syscalls/fanotify10: Add test cases for merge with ignored mask on
directory

 runtest/syscalls                              |   3 +
 testcases/kernel/syscalls/fanotify/fanotify.h |  29 +-
 .../kernel/syscalls/fanotify/fanotify09.c     |  57 ++--
 .../kernel/syscalls/fanotify/fanotify10.c     | 181 ++++++++---
 .../kernel/syscalls/fanotify/fanotify14.c     |  10 +-
 .../kernel/syscalls/fanotify/fanotify16.c     | 306 ++++++++++++++----
 testcases/kernel/syscalls/fcntl/fcntl38.c     |  96 ++++++
 testcases/kernel/syscalls/inotify/.gitignore  |   1 +
 testcases/kernel/syscalls/inotify/inotify10.c | 149 +++++++++
 9 files changed, 712 insertions(+), 120 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl38.c
 create mode 100644 testcases/kernel/syscalls/inotify/inotify10.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/10 syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME

Check invalid combinations for the new flags.

---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 10 ++++++++++
 testcases/kernel/syscalls/fanotify/fanotify14.c | 10 +++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fanotify/fanotify.h +10 -0
index d271578e9..4a7959989 100644
@@ -44,6 +44,13 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #ifndef FAN_REPORT_FID
 #define FAN_REPORT_FID		0x00000200
 #endif
+#ifndef FAN_REPORT_DIR_FID
+#define FAN_REPORT_DIR_FID	0x00000400
+#endif
+#ifndef FAN_REPORT_NAME
+#define FAN_REPORT_NAME		0x00000800
+#define FAN_REPORT_DFID_NAME     (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
+#endif
 
 #ifndef FAN_MARK_INODE
 #define FAN_MARK_INODE		0
@@ -114,6 +121,9 @@ typedef struct {
 #ifndef FAN_EVENT_INFO_TYPE_DFID_NAME
 #define FAN_EVENT_INFO_TYPE_DFID_NAME	2
 #endif
+#ifndef FAN_EVENT_INFO_TYPE_DFID
+#define FAN_EVENT_INFO_TYPE_DFID	3
+#endif
 
 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
 struct fanotify_event_info_header {
testcases/kernel/syscalls/fanotify/fanotify14.c +9 -1
index 3ca38d1e7..349177d9a 100644
@@ -52,7 +52,15 @@ static struct test_case_t {
 	},
 	{
 		FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS
-	}
+	},
+	{
+		/* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0
+	},
+	{
+		/* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0
+	},
 };
 
 static void do_test(unsigned int number)
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/10 syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME

In reply to Amir Goldstein

The new FAN_DIR_MODIFY event was removed before final v5.7 release and will be replaced with a new group flag FAN_REPORT_DFID_NAME to report name info for FAN_CREATE, FAN_DELETE and FAN_MOVE events. Adjust the test to use this new API.

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 11 ++-
 .../kernel/syscalls/fanotify/fanotify16.c     | 69 ++++++++++---------
 2 files changed, 44 insertions(+), 36 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +8 -3
index 4a7959989..91535718b 100644
@@ -89,9 +89,6 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #ifndef FAN_OPEN_EXEC_PERM
 #define FAN_OPEN_EXEC_PERM	0x00040000
 #endif
-#ifndef FAN_DIR_MODIFY
-#define FAN_DIR_MODIFY		0x00080000
-#endif
 
 /*
  * FAN_ALL_PERM_EVENTS has been deprecated, so any new permission events
@@ -103,6 +100,11 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #define LTP_ALL_PERM_EVENTS	(FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \
 				 FAN_ACCESS_PERM)
 
+struct fanotify_group_type {
+	unsigned int flag;
+	const char * name;
+};
+
 struct fanotify_mark_type {
 	unsigned int flag;
 	const char * name;
@@ -201,6 +203,9 @@ static inline void fanotify_save_fid(const char *path,
 }
 #endif /* HAVE_NAME_TO_HANDLE_AT */
 
+#define INIT_FANOTIFY_GROUP_TYPE(t) \
+	{ FAN_ ## t, "FAN_" #t }
+
 #define INIT_FANOTIFY_MARK_TYPE(t) \
 	{ FAN_MARK_ ## t, "FAN_MARK_" #t }
 
testcases/kernel/syscalls/fanotify/fanotify16.c +36 -33

170 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/10 syscalls/fanotify16: Test more event types with name

In reply to Amir Goldstein

- Test events "on child" reported with name
- Test events on directory itself reported with name "."
- Test move self event on directory and file

Events open/close are not supported on filesystem mark, so they are set on either a subdir inode mark or mount mark.

Events "on child" may or may not be merged with directory modification events with same file name, depending on group init flags, so relax the exact check to event mask and instead, just expect that all execpted event types will arrive.

---
 .../kernel/syscalls/fanotify/fanotify16.c     | 102 +++++++++++++-----
 1 file changed, 77 insertions(+), 25 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +77 -25
index f3fbd3bc0..76f053fd7 100644
@@ -5,8 +5,8 @@
  * Started by Amir Goldstein <[email protected]>
  *
  * DESCRIPTION
- *     Check fanotify directory entry modification events with group
- *     init flags FAN_REPORT_DFID_NAME (dir fid + name)
+ *     Check fanotify directory entry modification events, events on child and
+ *     on self with group init flags FAN_REPORT_DFID_NAME (dir fid + name)
  */
 #define _GNU_SOURCE
 #include "config.h"
@@ -25,7 +25,7 @@
 #if defined(HAVE_SYS_FANOTIFY_H)
 #include <sys/fanotify.h>
 
-#define EVENT_MAX 10
+#define EVENT_MAX 20
 
 /* Size of the event structure, not including file handle */
 #define EVENT_SIZE (sizeof(struct fanotify_event_metadata) + \
@@ -66,29 +66,29 @@ static struct test_case_t {
 	unsigned long sub_mask;
 } test_cases[] = {
 	{
-		/* Filesystem watch for directory entry modification events */
-		"FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move",
+		"FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move/open/close",
 		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME),
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_CREATE | FAN_DELETE| FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR,
-		{},
-		0,
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+		/* Mount watch for events possible on children */
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
 	},
 	{
-		/* Recursive watches for directory entry modification events */
-		"FAN_REPORT_DFID_NAME monitor directories for create/delete/move",
+		"FAN_REPORT_DFID_NAME monitor directories for create/delete/move/open/close",
 		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME),
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR,
-		/* Watches for directory entry modification events on subdir */
+		/* Watches for self events on subdir and events on subdir's children */
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR,
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
 	},
 };
 
 static void do_test(unsigned int number)
 {
-	int fd, len = 0, i = 0, test_num = 0, tst_count = 0;
+	int fd, dirfd, len = 0, i = 0, test_num = 0, tst_count = 0;
 	struct test_case_t *tc = &test_cases[number];
 	struct fanotify_group_type *group = &tc->group;
 	struct fanotify_mark_type *mark = &tc->mark;
@@ -125,8 +125,10 @@ static void do_test(unsigned int number)
 
 	/*
 	 * Create subdir and watch open events "on children" with name.
+	 * Make it a mount root.
 	 */
 	SAFE_MKDIR(dname1, 0755);
+	SAFE_MOUNT(dname1, dname1, "none", MS_BIND, NULL);
 
 	/* Save the subdir fid */
 	fanotify_save_fid(dname1, &dir_fid);
@@ -153,6 +155,7 @@ static void do_test(unsigned int number)
 
 	SAFE_WRITE(1, fd, "1", 1);
 	SAFE_RENAME(fname1, fname2);
+
 	SAFE_CLOSE(fd);
 
 	/* Generate delete events with fname2 */
@@ -168,6 +171,16 @@ static void do_test(unsigned int number)
 	event_set[tst_count].fid = &dir_fid;
 	strcpy(event_set[tst_count].name, FILE_NAME1);
 	tst_count++;
+	/*
+	 * Event on non-dir child with the same name may be merged with the
+	 * directory entry modification events above, unless FAN_REPORT_FID is
+	 * set and child fid is reported.
+	 */
+	event_set[tst_count].mask = FAN_OPEN;
+	event_set[tst_count].fid = &dir_fid;
+	strcpy(event_set[tst_count].name, FILE_NAME1);
+	tst_count++;
+
 	event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
 	event_set[tst_count].fid = &dir_fid;
 	strcpy(event_set[tst_count].name, FILE_NAME2);
@@ -178,11 +191,37 @@ static void do_test(unsigned int number)
 	 * is set.
 	 */
 	if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) {
-		event_set[tst_count].mask = FAN_DELETE_SELF;
+		event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF;
 		event_set[tst_count].fid = &file_fid;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
 	}
+	event_set[tst_count].mask = FAN_CLOSE_WRITE;
+	event_set[tst_count].fid = &dir_fid;
+	strcpy(event_set[tst_count].name, FILE_NAME2);
+	tst_count++;
+
+	dirfd = SAFE_OPEN(dname1, O_RDONLY | O_DIRECTORY);
+	SAFE_CLOSE(dirfd);
+
+	SAFE_UMOUNT(dname1);
+
+	/*
+	 * Directory watch gets open/close events on itself and on its subdirs.
+	 * Filesystem watch gets open/close event on all directories with name ".".
+	 */
+	event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR;
+	event_set[tst_count].fid = &dir_fid;
+	strcpy(event_set[tst_count].name, ".");
+	tst_count++;
+	/*
+	 * Directory watch gets self event on itself and filesystem watch gets
+	 * self event on all directories with name ".".
+	 */
+	event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR;
+	event_set[tst_count].fid = &dir_fid;
+	strcpy(event_set[tst_count].name, ".");
+	tst_count++;
 
 	SAFE_RENAME(dname1, dname2);
 	SAFE_RMDIR(dname2);
@@ -198,14 +237,8 @@ static void do_test(unsigned int number)
 	event_set[tst_count].fid = &root_fid;
 	strcpy(event_set[tst_count].name, DIR_NAME2);
 	tst_count++;
-	/*
-	 * Directory watch gets self event on itself and filesystem watch gets
-	 * self event on all directories with name ".".
-	 */
-	event_set[tst_count].mask = FAN_DELETE_SELF | FAN_ONDIR;
-	strcpy(event_set[tst_count].name, ".");
-	event_set[tst_count].fid = &dir_fid;
-	tst_count++;
+	/* Expect no more events */
+	event_set[tst_count].mask = 0;
 
 	/*
 	 * Cleanup the marks
@@ -220,7 +253,7 @@ static void do_test(unsigned int number)
 		struct file_handle *file_handle;
 		unsigned int fhlen;
 		const char *filename;
-		int namelen, info_type;
+		int namelen, info_type, mask_match;
 
 		event = (struct fanotify_event_metadata *)&event_buf[i];
 		event_fid = (struct fanotify_event_info_fid *)(event + 1);
@@ -242,6 +275,16 @@ static void do_test(unsigned int number)
 			info_type = FAN_EVENT_INFO_TYPE_DFID;
 		}
 
+		/*
+		 * Event may contain more than the expected mask, but it must
+		 * have all the bits in expected mask.
+		 * Expected event on dir must not get event on non dir and the
+		 * other way around.
+		 */
+		mask_match = ((event->mask & expected->mask) &&
+			      !(expected->mask & ~event->mask) &&
+			      !((event->mask ^ expected->mask) & FAN_ONDIR));
+
 		if (test_num >= tst_count) {
 			tst_res(TFAIL,
 				"got unnecessary event: mask=%llx "
@@ -259,7 +302,7 @@ static void do_test(unsigned int number)
 				(unsigned)event->pid, event->fd,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
-		} else if (event->mask != expected->mask) {
+		} else if (!mask_match) {
 			tst_res(TFAIL,
 				"got event: mask=%llx (expected %llx) "
 				"pid=%u fd=%d name='%s' "
@@ -356,10 +399,19 @@ static void do_test(unsigned int number)
 				event_fid->hdr.len, fhlen);
 		}
 
+		if (test_num < tst_count)
+			test_num++;
+
+		if (mask_match) {
+			/* In case of merged event match next expected mask */
+			event->mask &= ~expected->mask | FAN_ONDIR;
+			if (event->mask & ~FAN_ONDIR)
+				continue;
+		}
+
 		i += event->event_len;
 		if (event->fd > 0)
 			SAFE_CLOSE(event->fd);
-		test_num++;
 	}
 
 	for (; test_num < tst_count; test_num++) {
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/10 syscalls/fanotify16: Add test cases more init flag combinations

In reply to Amir Goldstein

Test more combination of flags FAN_REPORT_DIR_FID, FAN_REPORT_FID and FAN_REPORT_NAME.

Reporting different information per event may result in different event merging. For example, with FAN_REPORT_DFID_NAME, create/open/moved_from of "file1" are merged and moved_to/delete/close of "file2" are merged. With FAN_REPORT_DIR_FID, open/close of the file are merged (dir fid + child fid info are the same) and create/move/delete of file are merged (dir fid info is the same).

---
 testcases/kernel/syscalls/fanotify/fanotify.h |   8 ++
 .../kernel/syscalls/fanotify/fanotify16.c     | 110 ++++++++++++++++--
 2 files changed, 108 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +8 -0
index 91535718b..a9154f993 100644
@@ -52,6 +52,14 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #define FAN_REPORT_DFID_NAME     (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
 #endif
 
+/* Non-uapi convenience macros */
+#ifndef FAN_REPORT_DFID_NAME_FID
+#define FAN_REPORT_DFID_NAME_FID (FAN_REPORT_DFID_NAME | FAN_REPORT_FID)
+#endif
+#ifndef FAN_REPORT_DFID_FID
+#define FAN_REPORT_DFID_FID      (FAN_REPORT_DIR_FID | FAN_REPORT_FID)
+#endif
+
 #ifndef FAN_MARK_INODE
 #define FAN_MARK_INODE		0
 #endif
testcases/kernel/syscalls/fanotify/fanotify16.c +100 -10

148 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/10 syscalls/fanotify16: Verify child fid info

In reply to Amir Goldstein

If event reports both dir and child fid, also verify the expected child fid in the second info record.

---
 .../kernel/syscalls/fanotify/fanotify16.c     | 73 ++++++++++++++++---
 1 file changed, 61 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +61 -12
index c8c7a9ee8..7995a1688 100644
@@ -44,6 +44,7 @@
 struct event_t {
 	unsigned long long mask;
 	struct fanotify_fid_t *fid;
+	struct fanotify_fid_t *child_fid;
 	char name[BUF_SIZE];
 };
 
@@ -205,6 +206,7 @@ static void do_test(unsigned int number)
 
 	event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, DIR_NAME1);
 	tst_count++;
 
@@ -230,6 +232,7 @@ static void do_test(unsigned int number)
 	 */
 	event_set[tst_count].mask = FAN_CREATE | FAN_MOVED_FROM;
 	event_set[tst_count].fid = &dir_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, FILE_NAME1);
 	tst_count++;
 	/*
@@ -242,12 +245,14 @@ static void do_test(unsigned int number)
 	if (group->flag & FAN_REPORT_NAME) {
 		event_set[tst_count].mask = FAN_OPEN;
 		event_set[tst_count].fid = &dir_fid;
+		event_set[tst_count].child_fid = &file_fid;
 		strcpy(event_set[tst_count].name, FILE_NAME1);
 		tst_count++;
 	}
 
 	event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
 	event_set[tst_count].fid = &dir_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, FILE_NAME2);
 	tst_count++;
 	/*
@@ -257,6 +262,7 @@ static void do_test(unsigned int number)
 	if (!(group->flag & FAN_REPORT_NAME)) {
 		event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_WRITE;
 		event_set[tst_count].fid = &dir_fid;
+		event_set[tst_count].child_fid = &file_fid;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
 	}
@@ -268,6 +274,7 @@ static void do_test(unsigned int number)
 	if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) {
 		event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF;
 		event_set[tst_count].fid = &file_fid;
+		event_set[tst_count].child_fid = NULL;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
 	}
@@ -279,6 +286,7 @@ static void do_test(unsigned int number)
 	if (group->flag & FAN_REPORT_NAME) {
 		event_set[tst_count].mask = FAN_CLOSE_WRITE;
 		event_set[tst_count].fid = &dir_fid;
+		event_set[tst_count].child_fid = &file_fid;
 		strcpy(event_set[tst_count].name, FILE_NAME2);
 		tst_count++;
 	}
@@ -294,6 +302,7 @@ static void do_test(unsigned int number)
 	 */
 	event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR;
 	event_set[tst_count].fid = &dir_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, ".");
 	tst_count++;
 	/*
@@ -302,6 +311,7 @@ static void do_test(unsigned int number)
 	 */
 	event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR;
 	event_set[tst_count].fid = &dir_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, ".");
 	tst_count++;
 
@@ -313,10 +323,12 @@ static void do_test(unsigned int number)
 
 	event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, DIR_NAME1);
 	tst_count++;
 	event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
+	event_set[tst_count].child_fid = NULL;
 	strcpy(event_set[tst_count].name, DIR_NAME2);
 	tst_count++;
 	/* Expect no more events */
@@ -332,17 +344,21 @@ static void do_test(unsigned int number)
 		struct event_t *expected = &event_set[test_num];
 		struct fanotify_event_metadata *event;
 		struct fanotify_event_info_fid *event_fid;
+		struct fanotify_event_info_fid *child_fid;
+		struct fanotify_fid_t *expected_fid = expected->fid;
+		struct fanotify_fid_t *expected_child_fid = expected->child_fid;
 		struct file_handle *file_handle;
 		unsigned int fhlen;
 		const char *filename;
-		int namelen, info_type, mask_match;
+		int namelen, info_type, mask_match, info_id = 0;
 
 		event = (struct fanotify_event_metadata *)&event_buf[i];
 		event_fid = (struct fanotify_event_info_fid *)(event + 1);
 		file_handle = (struct file_handle *)event_fid->handle;
 		fhlen = file_handle->handle_bytes;
 		filename = (char *)file_handle->f_handle + fhlen;
-		namelen = ((char *)event_fid + event_fid->hdr.len) - filename;
+		child_fid = (void *)((char *)event_fid + event_fid->hdr.len);
+		namelen = (char *)child_fid - (char *)filename;
 		/* End of event_fid could have name, zero padding, both or none */
 		if (namelen > 0) {
 			namelen = strlen(filename);
@@ -350,6 +366,12 @@ static void do_test(unsigned int number)
 			filename = "";
 			namelen = 0;
 		}
+		/* Is there a child fid after first fid record? */
+		if (((char *)child_fid - (char *)event) >= event->event_len)
+			child_fid = NULL;
+
+		if (!(group->flag & FAN_REPORT_FID))
+			expected_child_fid = NULL;
 
 		if (!(group->flag & FAN_REPORT_NAME))
 			expected->name[0] = 0;
@@ -375,6 +397,7 @@ static void do_test(unsigned int number)
 			      !(expected->mask & ~event->mask) &&
 			      !((event->mask ^ expected->mask) & FAN_ONDIR));
 
+check_match:
 		if (test_num >= tst_count) {
 			tst_res(TFAIL,
 				"got unnecessary event: mask=%llx "
@@ -409,7 +432,7 @@ static void do_test(unsigned int number)
 				(unsigned)event->pid, event->fd,
 				event->event_len, event_fid->hdr.info_type,
 				info_type, event_fid->hdr.len, fhlen);
-		} else if (fhlen != expected->fid->handle.handle_bytes) {
+		} else if (fhlen != expected_fid->handle.handle_bytes) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d expected(%d)"
@@ -418,10 +441,10 @@ static void do_test(unsigned int number)
 				(unsigned)event->pid, event->fd, filename,
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
-				expected->fid->handle.handle_bytes,
+				expected_fid->handle.handle_bytes,
 				file_handle->handle_type);
 		} else if (file_handle->handle_type !=
-			   expected->fid->handle.handle_type) {
+			   expected_fid->handle.handle_type) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d "
@@ -431,9 +454,9 @@ static void do_test(unsigned int number)
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
 				file_handle->handle_type,
-				expected->fid->handle.handle_type);
+				expected_fid->handle.handle_type);
 		} else if (memcmp(file_handle->f_handle,
-				  expected->fid->handle.f_handle, fhlen)) {
+				  expected_fid->handle.f_handle, fhlen)) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d "
@@ -444,7 +467,7 @@ static void do_test(unsigned int number)
 				event_fid->hdr.len, fhlen,
 				file_handle->handle_type,
 				*(int *)(file_handle->f_handle));
-		} else if (memcmp(&event_fid->fsid, &expected->fid->fsid,
+		} else if (memcmp(&event_fid->fsid, &expected_fid->fsid,
 				  sizeof(event_fid->fsid)) != 0) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u fd=%d name='%s' "
@@ -456,8 +479,8 @@ static void do_test(unsigned int number)
 				event_fid->hdr.len, fhlen,
 				FSID_VAL_MEMBER(event_fid->fsid, 0),
 				FSID_VAL_MEMBER(event_fid->fsid, 1),
-				expected->fid->fsid.val[0],
-				expected->fid->fsid.val[1]);
+				expected_fid->fsid.val[0],
+				expected_fid->fsid.val[1]);
 		} else if (strcmp(expected->name, filename)) {
 			tst_res(TFAIL,
 				"got event: mask=%llx "
@@ -479,13 +502,39 @@ static void do_test(unsigned int number)
 				event->fd, filename,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
+		} else if (!!child_fid != !!expected_child_fid) {
+			tst_res(TFAIL,
+				"got event: mask=%llx "
+				"pid=%u fd=%d name='%s' num_info=%d (expected %d) "
+				"len=%d info_type=%d info_len=%d fh_len=%d",
+				(unsigned long long)event->mask,
+				(unsigned)event->pid, event->fd,
+				filename, 1 + !!child_fid, 1 + !!expected_child_fid,
+				event->event_len, event_fid->hdr.info_type,
+				event_fid->hdr.len, fhlen);
+		} else if (child_fid) {
+			tst_res(TINFO,
+				"got event #%d: info #%d: info_type=%d info_len=%d fh_len=%d",
+				test_num, info_id, event_fid->hdr.info_type,
+				event_fid->hdr.len, fhlen);
+
+			/* Recheck event_fid match with child_fid */
+			event_fid = child_fid;
+			expected_fid = expected->child_fid;
+			info_id = 1;
+			info_type = FAN_EVENT_INFO_TYPE_FID;
+			file_handle = (struct file_handle *)event_fid->handle;
+			fhlen = file_handle->handle_bytes;
+			child_fid = NULL;
+			expected_child_fid = NULL;
+			goto check_match;
 		} else {
 			tst_res(TPASS,
 				"got event #%d: mask=%llx pid=%u fd=%d name='%s' "
-				"len=%d info_type=%d info_len=%d fh_len=%d",
+				"len=%d; info #%d: info_type=%d info_len=%d fh_len=%d",
 				test_num, (unsigned long long)event->mask,
 				(unsigned)event->pid, event->fd, filename,
-				event->event_len, event_fid->hdr.info_type,
+				event->event_len, info_id, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
 		}
 
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/10 syscalls/fcntl: New test for F_NOTIFY (dnotify)

In reply to Amir Goldstein

Check that signal is delivered for both watching parent and watching subdir when subdir metadata changes.

---
 runtest/syscalls                          |  2 +
 testcases/kernel/syscalls/fcntl/fcntl38.c | 96 +++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl38.c
runtest/syscalls +2 -0
index dc0ca5626..376a2bc6b 100644
@@ -316,6 +316,8 @@ fcntl36 fcntl36
 fcntl36_64 fcntl36_64
 fcntl37 fcntl37
 fcntl37_64 fcntl37_64
+fcntl38 fcntl38
+fcntl38_64 fcntl38_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
testcases/kernel/syscalls/fcntl/fcntl38.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/10 syscalls/inotify: New test for watches on both parent and child

In reply to Amir Goldstein

Check that an inotify event is reported to both watching parent and watching child when the child metadata changes.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/inotify/.gitignore  |   1 +
 testcases/kernel/syscalls/inotify/inotify10.c | 149 ++++++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 testcases/kernel/syscalls/inotify/inotify10.c
runtest/syscalls +1 -0
index 376a2bc6b..b556fb85d 100644
@@ -564,6 +564,7 @@ inotify06 inotify06
 inotify07 inotify07
 inotify08 inotify08
 inotify09 inotify09
+inotify10 inotify10
 
 fanotify01 fanotify01
 fanotify02 fanotify02
testcases/kernel/syscalls/inotify/.gitignore +1 -0
index 32ccab5de..da9bfc767 100644
@@ -7,3 +7,4 @@
 /inotify07
 /inotify08
 /inotify09
+/inotify10
testcases/kernel/syscalls/inotify/inotify10.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/10 syscalls/fanotify09: Add test case with parent and subdir marks

In reply to Amir Goldstein

This test checks handling of events with both parent and mount marks. Generalize the test, and add test case of both parent and subdir marks.

Verified that existing test cases still fail on old kernels without the relevant fix commits.

---
 .../kernel/syscalls/fanotify/fanotify09.c     | 57 ++++++++++++-------
 1 file changed, 35 insertions(+), 22 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify09.c +35 -22
index 4336f498f..83210bc1c 100644
@@ -6,17 +6,17 @@
  *
  * DESCRIPTION
  *     Check that fanotify handles events on children correctly when
- *     both inode and mountpoint marks exist.
+ *     both parent and subdir or mountpoint marks exist.
  *
  * This is a regression test for commit 54a307ba8d3c:
  *
  *      fanotify: fix logic of events on child
  *
- * Test case #2 is a regression test for commit b469e7e47c8a:
+ * Test case #1 is a regression test for commit b469e7e47c8a:
  *
  *      fanotify: fix handling of events on child sub-directory
  *
- * Test case #3 is a regression test for commit 55bf882c7f13:
+ * Test case #2 is a regression test for commit 55bf882c7f13:
  *
  *      fanotify: fix merging marks masks with FAN_ONDIR
  */
@@ -60,33 +60,45 @@ static int mount_created;
 
 static struct tcase {
 	const char *tname;
+	struct fanotify_mark_type mark;
 	unsigned int ondir;
 	const char *testdir;
 	int nevents;
 } tcases[] = {
 	{
-		"Events on children with both inode and mount marks",
+		"Events on non-dir child with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
 		DIR_NAME,
 		1,
 	},
 	{
-		"Events on children and subdirs with both inode and mount marks",
+		"Events on non-dir child and subdir with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
 		DIR_NAME,
 		2,
 	},
 	{
-		"Events on files and dirs with both inode and mount marks",
+		"Events on non-dir child and parent with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
 		".",
 		2,
 	},
+	{
+		"Events on non-dir child and subdir with both parent and subdir marks",
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_ONDIR,
+		DIR_NAME,
+		2,
+	},
 };
 
-static void create_fanotify_groups(unsigned int ondir)
+static void create_fanotify_groups(struct tcase *tc)
 {
-	unsigned int i, onchild;
+	struct fanotify_mark_type *mark = &tc->mark;
+	unsigned int i, onchild, ondir = tc->ondir;
 	int ret;
 
 	for (i = 0; i < NUM_GROUPS; i++) {
@@ -94,22 +106,25 @@ static void create_fanotify_groups(unsigned int ondir)
 						  FAN_NONBLOCK,
 						  O_RDONLY);
 
-		/* Add mount mark for each group without MODIFY event */
+		/*
+		 * Add subdir or mount mark for each group with CLOSE event,
+		 * but only the first group requests events on dir.
+		 */
 		onchild = (i == 0) ? FAN_EVENT_ON_CHILD | ondir : 0;
 		ret = fanotify_mark(fd_notify[i],
-				    FAN_MARK_ADD | FAN_MARK_MOUNT,
+				    FAN_MARK_ADD | mark->flag,
 				    FAN_CLOSE_NOWRITE | onchild,
-				    AT_FDCWD, ".");
+				    AT_FDCWD, tc->testdir);
 		if (ret < 0) {
 			tst_brk(TBROK | TERRNO,
-				"fanotify_mark(%d, FAN_MARK_ADD | "
-				"FAN_MARK_MOUNT, FAN_MODIFY%s, AT_FDCWD,"
-				" '.') failed", fd_notify[i],
-				ondir ? " | FAN_ONDIR" : "");
+				"fanotify_mark(%d, FAN_MARK_ADD | %s, "
+				"%x, AT_FDCWD, '%s') failed",
+				fd_notify[i], mark->name,
+				FAN_CLOSE_NOWRITE | ondir, tc->testdir);
 		}
 		/*
-		 * Add inode mark on parent for each group with MODIFY
-		 * event, but only one group requests events on child.
+		 * Add inode mark on parent for each group with MODIFY event,
+		 * but only the first group requests events on child.
 		 * The one mark with FAN_EVENT_ON_CHILD is needed for
 		 * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry
 		 * flag.
@@ -120,10 +135,8 @@ static void create_fanotify_groups(unsigned int ondir)
 		if (ret < 0) {
 			tst_brk(TBROK | TERRNO,
 				"fanotify_mark(%d, FAN_MARK_ADD, "
-				"FAN_MODIFY%s%s, AT_FDCWD, '.') failed",
-				fd_notify[i],
-				ondir ? " | FAN_ONDIR" : "",
-				onchild ? " | FAN_EVENT_ON_CHILD" : "");
+				"%x, AT_FDCWD, '.') failed",
+				fd_notify[i], FAN_MODIFY | ondir | onchild);
 		}
 	}
 }
@@ -179,7 +192,7 @@ static void test_fanotify(unsigned int n)
 
 	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 
-	create_fanotify_groups(tc->ondir);
+	create_fanotify_groups(tc);
 
 	/*
 	 * generate MODIFY event and no FAN_CLOSE_NOWRITE event.
Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/10 syscalls/fanotify10: Test with group flag FAN_REPORT_NAME

In reply to Amir Goldstein

The group flag FAN_REPORT_NAME could change the behavior of merging inode mark mask with sb/mount marks.

Add another group class with flag FAN_REPORT_NAME to see how it affects merging of events on kernels that support FAN_REPORT_NAME.

On old kernels without FAN_REPORT_NAME support, the new group class is not tested.

---
 .../kernel/syscalls/fanotify/fanotify10.c     | 72 +++++++++++--------
 1 file changed, 44 insertions(+), 28 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +44 -28
index 3cdb25a73..9ebb6d68f 100644
@@ -45,16 +45,18 @@
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
-static unsigned int fanotify_prio[] = {
+static unsigned int fanotify_class[] = {
 	FAN_CLASS_PRE_CONTENT,
 	FAN_CLASS_CONTENT,
-	FAN_CLASS_NOTIF
+	FAN_CLASS_NOTIF,
+	/* Reporting dfid+name+fid merges events similar to reporting fd */
+	FAN_REPORT_DFID_NAME_FID,
 };
-#define FANOTIFY_PRIORITIES ARRAY_SIZE(fanotify_prio)
+#define NUM_CLASSES ARRAY_SIZE(fanotify_class)
 
 #define GROUPS_PER_PRIO 3
 
-static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
+static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
@@ -75,6 +77,7 @@ static char event_buf[EVENT_BUF_LEN];
 
 static pid_t child_pid;
 static int bind_mount_created;
+static unsigned int num_classes = NUM_CLASSES;
 
 enum {
 	FANOTIFY_INODE,
@@ -216,11 +219,23 @@ static int create_fanotify_groups(unsigned int n)
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
 
-	for (p = 0; p < FANOTIFY_PRIORITIES; p++) {
+	for (p = 0; p < num_classes; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
-			fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_prio[p] |
-							     FAN_NONBLOCK,
-							     O_RDONLY);
+			fd_notify[p][i] = fanotify_init(fanotify_class[p] |
+							FAN_NONBLOCK, O_RDONLY);
+			if (fd_notify[p][i] == -1) {
+				if (errno == EINVAL &&
+				    fanotify_class[p] & FAN_REPORT_NAME) {
+					tst_res(TCONF,
+						"FAN_REPORT_NAME not supported by kernel?");
+					/* Do not try creating this group again */
+					num_classes--;
+					return -1;
+				}
+
+				tst_brk(TBROK | TERRNO,
+					"fanotify_init(%x, 0) failed", fanotify_class[p]);
+			}
 
 			/*
 			 * Add mark for each group.
@@ -281,7 +296,7 @@ static void cleanup_fanotify_groups(void)
 {
 	unsigned int i, p;
 
-	for (p = 0; p < FANOTIFY_PRIORITIES; p++) {
+	for (p = 0; p < num_classes; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			if (fd_notify[p][i] > 0)
 				SAFE_CLOSE(fd_notify[p][i]);
@@ -289,22 +304,23 @@ static void cleanup_fanotify_groups(void)
 	}
 }
 
-static void verify_event(int group, struct fanotify_event_metadata *event,
+static void verify_event(int p, int group, struct fanotify_event_metadata *event,
 			 unsigned long long expected_mask)
 {
 	if (event->mask != expected_mask) {
-		tst_res(TFAIL, "group %d got event: mask %llx (expected %llx) "
-			"pid=%u fd=%u", group, (unsigned long long)event->mask,
+		tst_res(TFAIL, "group %d (%x) got event: mask %llx (expected %llx) "
+			"pid=%u fd=%u", group, fanotify_class[p],
+			(unsigned long long) event->mask,
 			(unsigned long long) expected_mask,
 			(unsigned)event->pid, event->fd);
 	} else if (event->pid != child_pid) {
-		tst_res(TFAIL, "group %d got event: mask %llx pid=%u "
-			"(expected %u) fd=%u", group,
+		tst_res(TFAIL, "group %d (%x) got event: mask %llx pid=%u "
+			"(expected %u) fd=%u", group, fanotify_class[p],
 			(unsigned long long)event->mask, (unsigned)event->pid,
 			(unsigned)getpid(), event->fd);
 	} else {
-		tst_res(TPASS, "group %d got event: mask %llx pid=%u fd=%u",
-			group, (unsigned long long)event->mask,
+		tst_res(TPASS, "group %d (%x) got event: mask %llx pid=%u fd=%u",
+			group, fanotify_class[p], (unsigned long long)event->mask,
 			(unsigned)event->pid, event->fd);
 	}
 }
@@ -357,7 +373,7 @@ static void test_fanotify(unsigned int n)
 		tst_brk(TBROK, "Child process terminated incorrectly");
 
 	/* First verify all groups without matching ignore mask got the event */
-	for (p = 0; p < FANOTIFY_PRIORITIES; p++) {
+	for (p = 0; p < num_classes; p++) {
 		if (p > 0 && !tc->expected_mask_with_ignore)
 			break;
 
@@ -365,9 +381,10 @@ static void test_fanotify(unsigned int n)
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
 			if (ret < 0) {
 				if (errno == EAGAIN) {
-					tst_res(TFAIL, "group %d (prio %d) "
+					tst_res(TFAIL, "group %d (%x) "
 						"with %s did not get event",
-						i, p, mark->name);
+						i, fanotify_class[p], mark->name);
+					continue;
 				}
 				tst_brk(TBROK | TERRNO,
 					"reading fanotify events failed");
@@ -380,12 +397,12 @@ static void test_fanotify(unsigned int n)
 			}
 			event = (struct fanotify_event_metadata *)event_buf;
 			if (ret > (int)event->event_len) {
-				tst_res(TFAIL, "group %d (prio %d) with %s "
+				tst_res(TFAIL, "group %d (%x) with %s "
 					"got more than one event (%d > %d)",
-					i, p, mark->name, ret,
+					i, fanotify_class[p], mark->name, ret,
 					event->event_len);
 			} else {
-				verify_event(i, event, p == 0 ?
+				verify_event(p, i, event, p == 0 ?
 						tc->expected_mask_without_ignore :
 						tc->expected_mask_with_ignore);
 			}
@@ -394,8 +411,7 @@ static void test_fanotify(unsigned int n)
 		}
 	}
 	/* Then verify all groups with matching ignore mask did got the event */
-	for (p = 1; p < FANOTIFY_PRIORITIES &&
-			!tc->expected_mask_with_ignore; p++) {
+	for (p = 1; p < num_classes && !tc->expected_mask_with_ignore; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
 			if (ret == 0) {
@@ -403,15 +419,15 @@ static void test_fanotify(unsigned int n)
 					"zero length read from fanotify fd");
 			}
 			if (ret > 0) {
-				tst_res(TFAIL, "group %d (prio %d) with %s and "
+				tst_res(TFAIL, "group %d (%x) with %s and "
 					"%s ignore mask got event",
-					i, p, mark->name, ignore_mark->name);
+					i, fanotify_class[p], mark->name, ignore_mark->name);
 				if (event->fd != FAN_NOFD)
 					SAFE_CLOSE(event->fd);
 			} else if (errno == EAGAIN) {
-				tst_res(TPASS, "group %d (prio %d) with %s and "
+				tst_res(TPASS, "group %d (%x) with %s and "
 					"%s ignore mask got no event",
-					i, p, mark->name, ignore_mark->name);
+					i, fanotify_class[p], mark->name, ignore_mark->name);
 			} else {
 				tst_brk(TBROK | TERRNO,
 					"reading fanotify events failed");
Signature · 1 line
2.17.1
#10 lore raw

PATCH 10/10 syscalls/fanotify10: Add test cases for merge with ignored mask on directory

In reply to Amir Goldstein

Pre kernel v5.9, a child mark with ignored mask would not prevent the delivery of events to a watching parent of that child.

This was fixed by kernel commit eca4784cbb18 ("fsnotify: send event to parent and child with single callback").

We add test cases for combination of mark of a directory with ignored mask either watching children or not.

Verified that existing test cases still fail on old kernels without the relevant fix commits.

In current kernel, there is a limitation that requires setting the event also in the parent's mask for ignore mask to be correctly merged with other marks. This is a temporary workaround that could be removed in the future when the correct behavior could be tested.

---
 .../kernel/syscalls/fanotify/fanotify10.c     | 109 ++++++++++++++++--
 1 file changed, 99 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +99 -10
index 9ebb6d68f..17d2f7578 100644
@@ -19,6 +19,10 @@
  * Test case #16 is a regression test for commit:
  *
  *     2f02fd3fa13e fanotify: fix ignore mask logic for events on child...
+ *
+ * Test cases #17-#23 are regression tests for commit:
+ *
+ *     eca4784cbb18 fsnotify: send event to parent and child with single...
  */
 #define _GNU_SOURCE
 #include "config.h"
@@ -97,6 +101,7 @@ static struct tcase {
 	int mark_type;
 	const char *ignore_path;
 	int ignore_mark_type;
+	unsigned int ignored_onchild;
 	const char *event_path;
 	unsigned long long expected_mask_with_ignore;
 	unsigned long long expected_mask_without_ignore;
@@ -105,24 +110,28 @@ static struct tcase {
 		"ignore mount events created on a specific file",
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		FILE_MNT2, FANOTIFY_INODE,
+		0,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"ignore exec mount events created on a specific file",
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		FILE_EXEC_PATH2, FANOTIFY_INODE,
+		0,
 		FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"don't ignore mount events created on another file",
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		FILE_PATH, FANOTIFY_INODE,
+		0,
 		FILE2_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"don't ignore exec mount events created on another file",
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		FILE_EXEC_PATH, FANOTIFY_INODE,
+		0,
 		FILE2_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC,
 		FAN_OPEN | FAN_OPEN_EXEC
 	},
@@ -130,24 +139,28 @@ static struct tcase {
 		"ignore inode events created on a specific mount point",
 		FILE_PATH, FANOTIFY_INODE,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_MNT2, 0, FAN_OPEN
 	},
 	{
 		"ignore exec inode events created on a specific mount point",
 		FILE_EXEC_PATH, FANOTIFY_INODE,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_EXEC_PATH2, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"don't ignore inode events created on another mount point",
 		FILE_MNT2, FANOTIFY_INODE,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"don't ignore exec inode events created on another mount point",
 		FILE_EXEC_PATH2, FANOTIFY_INODE,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC,
 		FAN_OPEN | FAN_OPEN_EXEC
 	},
@@ -155,24 +168,28 @@ static struct tcase {
 		"ignore fs events created on a specific file",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		FILE_PATH, FANOTIFY_INODE,
+		0,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"ignore exec fs events created on a specific file",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		FILE_EXEC_PATH, FANOTIFY_INODE,
+		0,
 		FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"don't ignore mount events created on another file",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		FILE_PATH, FANOTIFY_INODE,
+		0,
 		FILE2_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"don't ignore exec mount events created on another file",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		FILE_EXEC_PATH, FANOTIFY_INODE,
+		0,
 		FILE2_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC,
 		FAN_OPEN | FAN_OPEN_EXEC
 	},
@@ -180,24 +197,28 @@ static struct tcase {
 		"ignore fs events created on a specific mount point",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_MNT2, 0, FAN_OPEN
 	},
 	{
 		"ignore exec fs events created on a specific mount point",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_EXEC_PATH2, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"don't ignore fs events created on another mount point",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"don't ignore exec fs events created on another mount point",
 		MOUNT_PATH, FANOTIFY_FILESYSTEM,
 		MNT2_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC,
 		FAN_OPEN | FAN_OPEN_EXEC
 	},
@@ -205,14 +226,65 @@ static struct tcase {
 		"ignore child exec events created on a specific mount point",
 		MOUNT_PATH, FANOTIFY_INODE,
 		MOUNT_PATH, FANOTIFY_MOUNT,
+		0,
 		FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
+	{
+		"ignore events on children of directory created on a specific file",
+		MNT2_PATH, FANOTIFY_INODE,
+		FILE_PATH, FANOTIFY_INODE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, 0, FAN_OPEN
+	},
+	{
+		"ignore events on file created inside a parent watching children",
+		FILE_PATH, FANOTIFY_INODE,
+		MNT2_PATH, FANOTIFY_INODE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, 0, FAN_OPEN
+	},
+	{
+		"don't ignore events on file created inside a parent not watching children",
+		FILE_PATH, FANOTIFY_INODE,
+		MNT2_PATH, FANOTIFY_INODE,
+		0,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	{
+		"ignore mount events created inside a parent watching children",
+		FILE_PATH, FANOTIFY_MOUNT,
+		MNT2_PATH, FANOTIFY_INODE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, 0, FAN_OPEN
+	},
+	{
+		"don't ignore mount events created inside a parent not watching children",
+		FILE_PATH, FANOTIFY_MOUNT,
+		MNT2_PATH, FANOTIFY_INODE,
+		0,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	{
+		"ignore fs events created inside a parent watching children",
+		FILE_PATH, FANOTIFY_FILESYSTEM,
+		MNT2_PATH, FANOTIFY_INODE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, 0, FAN_OPEN
+	},
+	{
+		"don't ignore fs events created inside a parent not watching children",
+		FILE_PATH, FANOTIFY_FILESYSTEM,
+		MNT2_PATH, FANOTIFY_INODE,
+		0,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
 };
 
 static int create_fanotify_groups(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 	struct fanotify_mark_type *mark, *ignore_mark;
+	unsigned int mark_ignored, mask;
 	unsigned int p, i;
 	int ret;
 
@@ -272,20 +344,36 @@ static int create_fanotify_groups(unsigned int n)
 			/* Add ignore mark for groups with higher priority */
 			if (p == 0)
 				continue;
+
+			mask = FAN_OPEN;
+			mark_ignored = FAN_MARK_IGNORED_MASK |
+					FAN_MARK_IGNORED_SURV_MODIFY;
+add_mark:
 			ret = fanotify_mark(fd_notify[p][i],
-					    FAN_MARK_ADD | ignore_mark->flag |
-					    FAN_MARK_IGNORED_MASK |
-					    FAN_MARK_IGNORED_SURV_MODIFY,
-					    FAN_OPEN, AT_FDCWD,
-					    tc->ignore_path);
+					    FAN_MARK_ADD | ignore_mark->flag | mark_ignored,
+					    mask, AT_FDCWD, tc->ignore_path);
 			if (ret < 0) {
 				tst_brk(TBROK | TERRNO,
-					"fanotify_mark(%d, FAN_MARK_ADD | %s | "
-					"FAN_MARK_IGNORED_MASK | "
-					"FAN_MARK_IGNORED_SURV_MODIFY, "
-					"FAN_OPEN, AT_FDCWD, %s) failed",
+					"fanotify_mark(%d, FAN_MARK_ADD | %s | %s, "
+					"%x, AT_FDCWD, %s) failed",
 					fd_notify[p][i], ignore_mark->name,
-					tc->ignore_path);
+					mark_ignored ? "FAN_MARK_IGNORED_MASK | "
+					"FAN_MARK_IGNORED_SURV_MODIFY" : "",
+					mask, tc->ignore_path);
+			}
+
+			/*
+			 * If ignored mask is on a parent watching children,
+			 * also set the flag FAN_EVENT_ON_CHILD in mark mask.
+			 * This is needed to indicate that parent ignored mask
+			 * should be applied to events on children.
+			 */
+			if (tc->ignored_onchild && mark_ignored) {
+				mask = tc->ignored_onchild;
+				/* XXX: temporary hack may be removed in the future */
+				mask |= FAN_OPEN;
+				mark_ignored = 0;
+				goto add_mark;
 			}
 		}
 	}
@@ -478,6 +566,7 @@ static struct tst_test test = {
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "9bdda4e9cf2d"},
 		{"linux-git", "2f02fd3fa13e"},
+		{"linux-git", "eca4784cbb18"},
 		{}
 	}
 };
Signature · 1 line
2.17.1
#11 lore raw

cover Fanotify tests for v5.9

In reply to Amir Goldstein

Hi Amir,

Quoted 4 lines

Hi Petr,

Following are the tests that were used to develop the upcoming fanotify features in v5.9.

Thanks a lot for perfect update. There is LTP freeze soon (in 2 weeks [1]). I'd like to merge your patches although it'll be probably v5.9 release.

Patches LGTM, but I'd like to give change the others to look into them.

I tested all fanotify tests on 5.9.0-rc3 from openSUSE and on various old kernels from various distros.

Kind regards,
Petr

[1] http://lists.linux.it/pipermail/ltp/2020-September/018860.html

Quoted 9 lines

The inotify/dnotify tests and fanotify09 test case are regression tests for a mid series bug that has been fixed before the merge.

fanotify10 gets another set of test cases to catch yet another ignored mask logic bug. The fix commit will be too hard to backport IMO, so perhaps these test cases should go into a new test with .min_kver = "5.9".

Thanks,
Amir.

#13 lore raw

cover Fanotify tests for v5.9

In reply to Amir Goldstein

Hi Amir,

Quoted 5 lines

Following are the tests that were used to develop the upcoming fanotify features in v5.9.

The inotify/dnotify tests and fanotify09 test case are regression tests for a mid series bug that has been fixed before the merge.

Patchset merged.

Quoted 3 lines

fanotify10 gets another set of test cases to catch yet another ignored mask logic bug. The fix commit will be too hard to backport IMO, so perhaps these test cases should go into a new test with .min_kver = "5.9".

Can we just skip particular test with tst_parse_kver() or tst_kvcmp()? Because other tests are valid, thus why to skip them (which would be when using .min_kver).

Kind regards,
Petr

#14 lore raw

cover Fanotify tests for v5.9

Quoted 8 lines · Petr Vorel

Hi Amir,

Quoted 5 lines

Following are the tests that were used to develop the upcoming fanotify features in v5.9.

The inotify/dnotify tests and fanotify09 test case are regression tests for a mid series bug that has been fixed before the merge.

Quoted 8 lines

Patchset merged.

Quoted 3 lines

fanotify10 gets another set of test cases to catch yet another ignored mask logic bug. The fix commit will be too hard to backport IMO, so perhaps these test cases should go into a new test with .min_kver = "5.9".

Can we just skip particular test with tst_parse_kver() or tst_kvcmp()? Because other tests are valid, thus why to skip them (which would be when using .min_kver).

Sure I did not know about tst_parse_kver() I will send a patch.

BTW, sorry for the wrong commit id in the test. Your fix missed removing the old commit from comment:

* Test cases #17-#23 are regression tests for commit:
*
* 497b0c5a7c06 fsnotify: send event to parent and child with single...
* eca4784cbb18 fsnotify: send event to parent and child with single...
*/

Thanks,
Amir.

#15 lore raw

cover Fanotify tests for v5.9

Quoted 21 lines · Amir Goldstein
Quoted 8 lines · Petr Vorel

Hi Amir,

Quoted 5 lines

Following are the tests that were used to develop the upcoming fanotify features in v5.9.

The inotify/dnotify tests and fanotify09 test case are regression tests for a mid series bug that has been fixed before the merge.

Quoted 8 lines

Patchset merged.

Quoted 3 lines

fanotify10 gets another set of test cases to catch yet another ignored mask logic bug. The fix commit will be too hard to backport IMO, so perhaps these test cases should go into a new test with .min_kver = "5.9".

Can we just skip particular test with tst_parse_kver() or tst_kvcmp()? Because other tests are valid, thus why to skip them (which would be when using .min_kver).

Sure I did not know about tst_parse_kver() I will send a patch.

Quoted 9 lines

BTW, sorry for the wrong commit id in the test. Your fix missed removing the old commit from comment:

* Test cases #17-#23 are regression tests for commit:
*
* 497b0c5a7c06 fsnotify: send event to parent and child with single...
* eca4784cbb18 fsnotify: send event to parent and child with single...
*/

Actually, I don't see any examples of tests that use tst_kvcmp() Do you mind making and testing this change?

All the test cases in fanotify10 with non zero tc->ignored_onchild should be skipped for kver < 5.9

Thanks,
Amir.

#16 lore raw

cover Fanotify tests for v5.9

Hi!

Quoted 5 lines
Quoted 5 lines

Sure I did not know about tst_parse_kver() I will send a patch.

BTW, sorry for the wrong commit id in the test. Your fix missed removing the old commit from comment:

Quoted 8 lines
Quoted 6 lines

* Test cases #17-#23 are regression tests for commit:
*
* 497b0c5a7c06 fsnotify: send event to parent and child with single...
* eca4784cbb18 fsnotify: send event to parent and child with single...
*/

Actually, I don't see any examples of tests that use tst_kvcmp()

It's tst_kvercmp() the tst_kvcmp() is internal library function that shouldn't be used in testcases.

Signature · 2 lines
Cyril Hrubis
[email protected]