[LTP] [PATCH 1/5] fanotify13: Verify that we did not get an extra event
Amir Goldstein
amir73il@gmail.com
Wed Jan 22 18:24:36 CET 2025
For example, verify that we did not get an event on a directory object
without requesting FAN_ONDIR. Also, report a test failure if no events
received at all instead of blocking on read of fanotify_fd.
With this change, the test fails with overlayfs variants over btrfs,
because the size of fid of overalyfs over btrfs is about 90 bytes and
the events on the three objects do not all fit into a single 256 bytes
buffer read. Increase the size of the events buffer to fix this failure.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify13.c | 22 ++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c
index 5cd857707..16fd99ba1 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify13.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify13.c
@@ -34,7 +34,7 @@
#include "fanotify.h"
#define PATH_LEN 128
-#define BUF_SIZE 256
+#define BUF_SIZE 1024
#define DIR_ONE "dir_one"
#define FILE_ONE "file_one"
#define FILE_TWO "file_two"
@@ -130,10 +130,15 @@ static int setup_marks(unsigned int fd, struct test_case_t *tc)
SAFE_FANOTIFY_MARK(fd, FAN_MARK_ADD | mark->flag, tc->mask,
AT_FDCWD, objects[i].path);
- /* Setup the expected mask for each generated event */
+ /*
+ * Setup the expected mask for each generated event.
+ * No events are expected on directory without FAN_ONDIR.
+ */
event_set[i].expected_mask = tc->mask;
if (!objects[i].is_dir)
event_set[i].expected_mask &= ~FAN_ONDIR;
+ else if (!(event_set[i].expected_mask & FAN_ONDIR))
+ event_set[i].expected_mask = 0;
}
return 0;
}
@@ -163,7 +168,8 @@ static void do_test(unsigned int number)
return;
}
- fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
+ fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID |
+ FAN_NONBLOCK, O_RDONLY);
/*
* Place marks on a set of objects and setup the expected masks
@@ -279,6 +285,16 @@ static void do_test(unsigned int number)
FSID_VAL_MEMBER(event_fid->fsid, 1),
*(unsigned long *) event_file_handle->f_handle);
}
+
+ /*
+ * Verify that we did not get an extra event, for example, that we did
+ * not get an event on directory without FAN_ONDIR.
+ */
+ if (event_set[i].expected_mask) {
+ tst_res(TFAIL,
+ "Did not get an expected event (expected: %llx)",
+ event_set[i].expected_mask);
+ }
out:
SAFE_CLOSE(fanotify_fd);
}
--
2.34.1
More information about the ltp
mailing list