[LTP] [PATCH] fanotify21: fix test failure when running iterations
Jan Kara
jack@suse.cz
Sat May 30 13:21:35 CEST 2026
On Thu 28-05-26 17:19:38, Amir Goldstein wrote:
> 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.
>
> Reported-by: pvorel@suse.cz
> Link: https://lore.kernel.org/linux-fsdevel/20260527072312.GA231966@pevik/
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Ah, nice trick. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
>
> 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(-)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index c95895c93..fd18d7e29 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -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 = {
> --
> 2.54.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
More information about the ltp
mailing list