Skip to contentSkip to conversation

fanotify13: fix test failure when running iterations

PATCH Superseded Amir Goldstein 3 participants 6 messages May 28 – May 30

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fanotify13: fix test failure when running iterations

The test case for FAN_SELETE_SELF deletes the objects created in do_setup() so we need to re-create them for the next iteration.

This bring up a problem with ext2 and filesystem that do not support RENAME_EXCHANGE because overlayfs fails to re-create objects over a whiteout.

It is generally not interesting to test overlayfs over such base fs, but for now, let just exclude this type of base fs from the delete self event test case.

---

Petr,

The basic fix is taken from AnonymeMeow's patch.

I applied a skip instead of fix for the issue with test_variant 3 on ext2 base fs.

Thanks,
Amir.

 .../kernel/syscalls/fanotify/fanotify13.c     | 37 +++++++++++++++----
 1 file changed, 29 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify13.c +29 -8
index 32b2b8238..d2e65167f 100644
@@ -109,6 +109,7 @@ static int nofid_fd;
 static int fanotify_fd;
 static int at_handle_fid;
 static int filesystem_mark_unsupported;
+static int rename_exchange_unsupported;
 static char events_buf[BUF_SIZE];
 static struct event_t event_set[EVENT_MAX];
 
@@ -190,6 +191,13 @@ static void do_test(unsigned int number)
 		return;
 	}
 
+	if (tst_variant && (tc->mask & FAN_DELETE_SELF) &&
+	    (!ovl_bind_mounted || rename_exchange_unsupported)) {
+		/* The eviction of base fs inodes is defered due to overlay held reference */
+		tst_res(TCONF, "overlayfs base fs cannot be watched for delete self events");
+		return;
+	}
+
 	if (filesystem_mark_unsupported && mark->flag != FAN_MARK_INODE) {
 		FANOTIFY_MARK_FLAGS_ERR_MSG(mark, filesystem_mark_unsupported);
 		return;
@@ -211,11 +219,6 @@ static void do_test(unsigned int number)
 			tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark");
 			goto out;
 		}
-		if (tc->mask & FAN_DELETE_SELF) {
-			/* The eviction of base fs inodes is defered due to overlay held reference */
-			tst_res(TCONF, "overlayfs base fs cannot be watched for delete self events");
-			goto out;
-		}
 		SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL);
 	}
 
@@ -339,10 +342,18 @@ 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) {
+		create_objects();
+		get_object_stats();
+	}
 out:
 	SAFE_CLOSE(fanotify_fd);
 }
 
+#define TST_VARINAT_OVL_LOWER (tst_variant & 1)
+#define TST_VARIANT_OVL_WATCH (tst_variant > 2)
+
 static void do_setup(void)
 {
 	const char *mnt;
@@ -370,10 +381,9 @@ static void do_setup(void)
 		if (!ovl_mounted)
 			return;
 
-		mnt = tst_variant & 1 ? OVL_LOWER : OVL_UPPER;
+		mnt = TST_VARINAT_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,7 +395,18 @@ static void do_setup(void)
 	/* Create file and directory objects for testing on base fs */
 	create_objects();
 
-	if (tst_variant > 2) {
+	/* RENAME_EXCHANGE is required for create over whiteout in overlayfs */
+	if (TST_VARINAT_OVL_LOWER) {
+		rename_exchange_unsupported = renameat2(AT_FDCWD, FILE_PATH_ONE,
+							AT_FDCWD, FILE_PATH_TWO,
+							RENAME_EXCHANGE);
+		if (rename_exchange_unsupported) {
+			tst_res(TCONF, "RENAME_EXCHANGE not supported on %s",
+				tst_device->fs_type);
+		}
+	}
+
+	if (TST_VARIANT_OVL_WATCH) {
 		/* Setup watches on overlayfs */
 		SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL);
 		ovl_bind_mounted = 1;
Signature · 5 lines
2.54.0


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

PATCH 1/1 fanotify21: fix test failure when running iterations

Peter reported that fanotify21 -i2 fails.
Fix this by always remounting ro/rw before every test. Use a bind mount, where remount works regardless of base fs.

---

Petr,

This is a simplified version of AnonymeMeow's patch.

Thanks,
Amir.

 .../kernel/syscalls/fanotify/fanotify21.c      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify21.c +9 -9
index c95895c93..fd18d7e29 100644
@@ -123,6 +123,9 @@ static void do_setup(void)
 	int pidfd;
 	int init_flags = FAN_REPORT_PIDFD;
 
+	/* Bind mount so remount ro/rw always work */
+	SAFE_MOUNT(MOUNT_PATH, MOUNT_PATH, "none", MS_BIND, NULL);
+
 	if (tst_variant) {
 		fanotify_fd = -1;
 		fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
@@ -171,15 +174,9 @@ static void do_test(unsigned int num)
 		return;
 	}
 
-	if (tc->remount_ro) {
-		/* SAFE_MOUNT fails to remount FUSE */
-		if (mount(tst_device->dev, MOUNT_PATH, tst_device->fs_type,
-			  MS_REMOUNT|MS_RDONLY, NULL) != 0) {
-			tst_brk(TFAIL,
-				"filesystem %s failed to remount readonly",
-				tst_device->fs_type);
-		}
-	}
+	/* remount ro/rw the bind mount */
+	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
+		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
 
 	/*
 	 * Generate the event in either self or a child process. Event
@@ -355,6 +352,9 @@ static void do_cleanup(void)
 
 	if (self_pidfd_fdinfo)
 		free(self_pidfd_fdinfo);
+
+	/* Unmount the bind mount */
+	SAFE_UMOUNT(MOUNT_PATH);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.54.0


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

Re: [LTP] fanotify21: fix test failure when running iterations

Hi Amir,

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_setup(void) · line 127

Quoted 4 lines · Amir Goldstein

fanotify21: fix test failure when running iterations

testcases/kernel/syscalls/fanotify/fanotify21.c +2 -0
+/* Bind mount so remount ro/rw always work */
+SAFE_MOUNT(MOUNT_PATH, MOUNT_PATH, "none", MS_BIND, NULL);

The self-bind-mount approach is clean — it decouples the remount ro/rw state from the underlying filesystem type, removing both the FUSE special-case and the need for tst_device->fs_type in the remount call.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 179

Quoted 12 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +3 -9
-if (tc->remount_ro) {
-/* SAFE_MOUNT fails to remount FUSE */
-if (mount(tst_device->dev, MOUNT_PATH, tst_device->fs_type,
-  MS_REMOUNT|MS_RDONLY, NULL) != 0) {
-tst_brk(TFAIL,
-"filesystem %s failed to remount readonly",
-tst_device->fs_type);
-}
-}
+/* remount ro/rw the bind mount */
+SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
+   (tc->remount_ro ? MS_RDONLY : 0), NULL);

Good — always remounting to the correct state (rw or ro) before each test case is exactly what was missing and explains the -i2 failure.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_cleanup(void) · line 357

Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +2 -0
+/* Unmount the bind mount */
+SAFE_UMOUNT(MOUNT_PATH);

Correct. The bind mount is cleaned up before the LTP framework unmounts the underlying device.

Quoted 1 line

+Reported-by: [email protected]

Missing full name. Should be:

[...]

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#3 lore raw

Re: [LTP] [PATCH] fanotify21: fix test failure when running iterations

In reply to Amir Goldstein
Quoted 7 lines · Amir Goldstein

Peter reported that fanotify21 -i2 fails.
Fix this by always remounting ro/rw before every test. Use a bind mount, where remount works regardless of base fs.

Ah, nice trick. Feel free to add:

Honza

Quoted 58 lines

---

Petr,

This is a simplified version of AnonymeMeow's patch.

Thanks,
Amir.

 .../kernel/syscalls/fanotify/fanotify21.c      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify21.c +9 -9
index c95895c93..fd18d7e29 100644
@@ -123,6 +123,9 @@ static void do_setup(void)
 	int pidfd;
 	int init_flags = FAN_REPORT_PIDFD;
 
+	/* Bind mount so remount ro/rw always work */
+	SAFE_MOUNT(MOUNT_PATH, MOUNT_PATH, "none", MS_BIND, NULL);
+
 	if (tst_variant) {
 		fanotify_fd = -1;
 		fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
@@ -171,15 +174,9 @@ static void do_test(unsigned int num)
 		return;
 	}
 
-	if (tc->remount_ro) {
-		/* SAFE_MOUNT fails to remount FUSE */
-		if (mount(tst_device->dev, MOUNT_PATH, tst_device->fs_type,
-			  MS_REMOUNT|MS_RDONLY, NULL) != 0) {
-			tst_brk(TFAIL,
-				"filesystem %s failed to remount readonly",
-				tst_device->fs_type);
-		}
-	}
+	/* remount ro/rw the bind mount */
+	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
+		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
 
 	/*
 	 * Generate the event in either self or a child process. Event
@@ -355,6 +352,9 @@ static void do_cleanup(void)
 
 	if (self_pidfd_fdinfo)
 		free(self_pidfd_fdinfo);
+
+	/* Unmount the bind mount */
+	SAFE_UMOUNT(MOUNT_PATH);
 }
 
 static struct tst_test test = {
Signature · 1 line
2.54.0
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Amir Goldstein

Hi Amir,

Quoted 3 lines · Amir Goldstein

fanotify13: fix test failure when running iterations

The test case for FAN_SELETE_SELF deletes the objects created in

Typo: "FAN_SELETE_SELF" should be "FAN_DELETE_SELF".

Quoted 1 line

+#define TST_VARINAT_OVL_LOWER (tst_variant & 1)

Typo in macro name: "VARINAT" should be "VARIANT" -> TST_VARIANT_OVL_LOWER. It is used consistently with the typo throughout, but it should be fixed.

testcases/kernel/syscalls/fanotify/fanotify13.c static void do_setup(void) · line 407

Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify13.c +9 -0
+	if (TST_VARINAT_OVL_LOWER) {
+		rename_exchange_unsupported = renameat2(AT_FDCWD, FILE_PATH_ONE,
+							AT_FDCWD, FILE_PATH_TWO,
+							RENAME_EXCHANGE);
+		if (rename_exchange_unsupported) {
+			tst_res(TCONF, "RENAME_EXCHANGE not supported on %s",
+				tst_device->fs_type);
+		}
+	}

The return value of renameat2(2) is -1 on any error, not only when RENAME_EXCHANGE is unsupported. Storing the raw return value means any transient failure (EIO, ENOMEM, ...) silently sets rename_exchange_unsupported and causes all FAN_DELETE_SELF variants to TCONF, masking a real problem. Check errno for EOPNOTSUPP/EINVAL before setting the flag:

	rename_exchange_unsupported = (renameat2(...) == -1 &&
				       (errno == EOPNOTSUPP || errno == EINVAL));

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#5 lore raw
In reply to Amir Goldstein
Quoted 14 lines · Amir Goldstein

The test case for FAN_SELETE_SELF deletes the objects created in do_setup() so we need to re-create them for the next iteration.

This bring up a problem with ext2 and filesystem that do not support RENAME_EXCHANGE because overlayfs fails to re-create objects over a whiteout.

It is generally not interesting to test overlayfs over such base fs, but for now, let just exclude this type of base fs from the delete self event test case.

Quoted 8 lines

---

Petr,

The basic fix is taken from AnonymeMeow's patch.

I applied a skip instead of fix for the issue with test_variant 3 on ext2 base fs.

Looks good. Feel free to add:

One typo fix below:

Quoted 1 line

+#define TST_VARINAT_OVL_LOWER (tst_variant & 1)

		^^^^ typo here

testcases/kernel/syscalls/fanotify/fanotify13.c static void do_test(unsigned int number) · line 356

Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify13.c +2 -0
+#define TST_VARIANT_OVL_WATCH (tst_variant > 2)
+

Honza

Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp