[LTP] [PATCH] fanotify13: fix test failure when running iterations
AnonymeMeow
anonymemeow@gmail.com
Mon Jun 1 01:41:16 CEST 2026
The FAN_DELETE_SELF test case removes test files, causing later
iterations to crash. Recreate the removed files after the test to
restore the expected initial state. And adjust the overlayfs mount
timing to avoid creating files directly in the filesystem underneath
the already mounted overlayfs.
Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
Hi, Amir,
I think we shouldn't unconditionally recreate the files through the
overlayfs. Because files created through overlayfs end up in the upper
dir, but test variant 3 is intended to verify events reported for lower
dir files opened through overlayfs, then starting from the second
iteration variant 3 would test events for upper dir files instead, which
does not match the intended test scenario.
Therefore, I updated my previous patch to unmount the overlayfs mount
and its bind mount before cleaning the upper dir, and mount them back
afterwards. This avoids modifying the underlying fs while the overlayfs
is still mounted.
And since modifying the backing fs of a mounted overlayfs is undefined
behavior, I adjusted the overlayfs setup timing so that the test files
are created before overlayfs is mounted.
With Best Regards,
AnonymeMeow
---
.../kernel/syscalls/fanotify/fanotify13.c | 50 +++++++++++++++----
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c
index 76d40eaf7..c4223c3e9 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify13.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify13.c
@@ -53,6 +53,9 @@
#define FILE_PATH_ONE MOUNT_PATH"/"FILE_ONE
#define FILE_PATH_TWO MOUNT_PATH"/"FILE_TWO
+#define TST_VARIANT_OVL_LOWER (tst_variant & 1)
+#define TST_VARIANT_OVL_WATCH (tst_variant > 2)
+
#if defined(HAVE_NAME_TO_HANDLE_AT)
struct event_t {
unsigned long long expected_mask;
@@ -137,6 +140,22 @@ static void delete_objects(void)
}
}
+static void clean_upper_dir(void)
+{
+ unsigned int i;
+
+ SAFE_UMOUNT(MOUNT_PATH);
+ SAFE_UMOUNT(OVL_MNT);
+
+ SAFE_MOUNT(OVL_UPPER, MOUNT_PATH, "none", MS_BIND, NULL);
+ for (i = 0; i < ARRAY_SIZE(objects); i++)
+ SAFE_UNLINK(objects[i].path);
+ SAFE_UMOUNT(MOUNT_PATH);
+
+ SAFE_MOUNT_OVERLAY();
+ SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL);
+}
+
static void get_object_stats(void)
{
unsigned int i;
@@ -340,6 +359,15 @@ static void do_test(unsigned int number)
"Did not get an expected event (expected: %llx)",
event_set[i].expected_mask);
}
+
+ if (tc->mask & FAN_DELETE_SELF) {
+ if (TST_VARIANT_OVL_LOWER) {
+ clean_upper_dir();
+ } else {
+ create_objects();
+ get_object_stats();
+ }
+ }
out:
SAFE_CLOSE(fanotify_fd);
}
@@ -367,14 +395,11 @@ static void do_setup(void)
*/
if (tst_variant) {
REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(AT_HANDLE_FID);
- ovl_mounted = TST_MOUNT_OVERLAY();
- if (!ovl_mounted)
- return;
-
- mnt = tst_variant & 1 ? OVL_LOWER : OVL_UPPER;
+
+ tst_create_overlay_dirs();
+ mnt = TST_VARIANT_OVL_LOWER ? OVL_LOWER : OVL_UPPER;
} else {
mnt = OVL_BASE_MNTPOINT;
-
}
REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, mnt);
SAFE_MKDIR(MOUNT_PATH, 0755);
@@ -385,8 +410,14 @@ static void do_setup(void)
/* Create file and directory objects for testing on base fs */
create_objects();
+
+ if (tst_variant) {
+ ovl_mounted = TST_MOUNT_OVERLAY();
+ if (!ovl_mounted)
+ return;
+ }
- if (tst_variant > 2) {
+ if (TST_VARIANT_OVL_WATCH) {
/* Setup watches on overlayfs */
SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL);
ovl_bind_mounted = 1;
@@ -416,12 +447,13 @@ static void do_cleanup(void)
SAFE_CLOSE(fanotify_fd);
if (ovl_bind_mounted)
SAFE_UMOUNT(MOUNT_PATH);
+ if (ovl_mounted)
+ SAFE_UMOUNT(OVL_MNT);
if (bind_mounted) {
+ delete_objects();
SAFE_UMOUNT(MOUNT_PATH);
SAFE_RMDIR(MOUNT_PATH);
}
- if (ovl_mounted)
- SAFE_UMOUNT(OVL_MNT);
}
static struct tst_test test = {
--
2.54.0
More information about the ltp
mailing list