generic/646: Test page faults during read and write
PATCH 1/1 generic/646: Test page faults during read and write
Here's an update of a test case I'm trying to get merged since May. Please have a look; I'm tired of dragging this along.
Thanks,
Andreas
--
Some filesystems have problems when the buffer passed to read or write is memory-mapped to the file being read from or written to, and the buffer needs to be faulted in during the read or write. That's not common, but filesystems are still required to cope with it, and if they fail this test, then they will also fail more complex scenarios that involve multiple files.
--- src/Makefile | 2 +- src/mmap-rw-fault.c | 176 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/646 | 27 +++++++ tests/generic/646.out | 2 + 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/mmap-rw-fault.c create mode 100755 tests/generic/646 create mode 100644 tests/generic/646.out
src/Makefile +1 -1
@@ -18,7 +18,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ t_ext4_dax_journal_corruption t_ext4_dax_inline_corruption \ t_ofd_locks t_mmap_collision mmap-write-concurrent \ t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \ - t_mmap_writev_overlap checkpoint_journal + t_mmap_writev_overlap checkpoint_journal mmap-rw-fault LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
src/mmap-rw-fault.c new file +176 -0
176 lines not on this page · raw message
tests/generic/646 new file +27 -0
@@ -0,0 +1,27 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test 646 +# +# Trigger mmap page faults in the same file during pread and pwrite +# +. ./common/preamble +_begin_fstest auto quick + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here + +_supported_fs generic +_require_test +_require_test_program mmap-rw-fault + +echo "Silence is golden" + +$here/src/mmap-rw-fault $TEST_DIR/mmap-rw-fault.tmp + +status=$? +exit
tests/generic/646.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 646 +Silence is golden
Signature · 1 line
2.26.3
src/mmap-rw-fault.c
Quoted 44 lines · Andreas Gruenbacher
Here's an update of a test case I'm trying to get merged since May. Please have a look; I'm tired of dragging this along.
Thanks,
Andreas--
Some filesystems have problems when the buffer passed to read or write is memory-mapped to the file being read from or written to, and the buffer needs to be faulted in during the read or write. That's not common, but filesystems are still required to cope with it, and if they fail this test, then they will also fail more complex scenarios that involve multiple files.
Signed-off-by Andreas Gruenbacher <[email protected]>--- src/Makefile | 2 +- src/mmap-rw-fault.c | 176 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/646 | 27 +++++++ tests/generic/646.out | 2 + 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/mmap-rw-fault.c create mode 100755 tests/generic/646 create mode 100644 tests/generic/646.outsrc/Makefile +1
-1@@ -18,7 +18,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ t_ext4_dax_journal_corruption t_ext4_dax_inline_corruption \ t_ofd_locks t_mmap_collision mmap-write-concurrent \ t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \ - t_mmap_writev_overlap checkpoint_journal + t_mmap_writev_overlap checkpoint_journal mmap-rw-fault LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \src/mmap-rw-fault.c new file +0
-0
The generated binary needs a gitignore entry.
src/mmap-rw-fault.c line 1
Quoted 2 lines
src/mmap-rw-fault.c new file +1
-0@@ -0,0 +1,176 @@ +/* Trigger mmap page faults in the same file during pread and pwrite. */
Needs a SPDX header and a copyright statement.
Quoted 5 lines
src/mmap-rw-fault.c new file +5
-0+ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE/* to get definition of O_DIRECT flag. */ +#endif +
src/mmap-rw-fault.c line 16
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <err.h>
<now we skip to main>
Quoted 9 lines
src/mmap-rw-fault.c new file +9
-0+int main (int argc,char *argv[]) +{ +if (argc !=2 ) +errx (1 ,"no test filename argument given" ); + filename = argv[1 ]; + + page_size = ret =sysconf (_SC_PAGE_SIZE); +if (ret ==-1 ) +err (1 ,NULL );
src/mmap-rw-fault.c line 124
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+ + ret =posix_memalign (&page, page_size, page_size); +if (ret) { + errno =ENOMEM ; +err (1 ,NULL ); + } + +/* +* Make sure page faults during pread are handled correctly. +*/
These test reading from page 1 into (mmap) page 0, right?
Quoted 9 lines
src/mmap-rw-fault.c new file +9
-0+init ('a' ,O_RDWR ); + ret =do_read (fd, addr, page_size, page_size); +if (ret != page_size) +err (1 ,"pread %s: %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pread is broken" ); +done (); + +init ('b' ,O_RDWR |O_DIRECT );
src/mmap-rw-fault.c line 143
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+ ret =do_read (fd, addr, page_size, page_size); +if (ret != page_size) +err (1 ,"pread %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pread (D_DIRECT) is broken" ); +done (); + +/* +* Make sure page faults during pwrite are handled correctly. +*/
...and writing from (mmap) page 1 into page 0?
Quoted 9 lines
src/mmap-rw-fault.c new file +9
-0+init ('c' ,O_RDWR ); + ret =do_write (fd, addr + page_size, page_size,0 ); +if (ret != page_size) +err (1 ,"pwrite %s: %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pwrite is broken" ); +done (); + +init ('d' ,O_RDWR |O_DIRECT );
src/mmap-rw-fault.c line 162
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+ ret =do_write (fd, addr + page_size, page_size,0 ); +if (ret != page_size) +err (1 ,"pwrite %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pwrite (O_DIRECT) is broken" ); +done (); + +/* +* Reading from a hole takes a different code path in the kernel. +*/
...and finally we test direct reading from page 0 into (mmap) page 0?
If that's correct, then this looks good to me, modulo the license nit at the top.
Quoted 34 lines
src/mmap-rw-fault.c new file +14
-0+init ('e' ,O_RDWR |O_DIRECT ); + ret =do_read (fd, addr, page_size,0 ); +if (ret != page_size) +err (1 ,"pread %s (O_DIRECT) from hole: %ld != %u" , filename, ret, page_size); +memset (page,0 , page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pread (D_DIRECT) from hole is broken" ); +done (); + +if (unlink (filename)) +err (1 ,"unlink %s" , filename); + +return 0 ; +}tests/generic/646 new file +14
-0@@ -0,0 +1,27 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test 646 +# +# Trigger mmap page faults in the same file during pread and pwrite +# +. ./common/preamble +_begin_fstest auto quick + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter
tests/generic/646 line 24
Quoted 10 lines
tests/generic/646 new file +10
-0+ +# real QA test starts here + +_supported_fs generic +_require_test +_require_test_program mmap-rw-fault + +echo "Silence is golden" + +$here/src/mmap-rw-fault $TEST_DIR/mmap-rw-fault.tmp
_cleanup should clean up the tempfile if the C program crashes, right?
Or use O_TMPFILE and let the kernel clean up the file for you.
--D
Quoted 14 lines
tests/generic/646 new file +3
-0+ +status=$? +exittests/generic/646.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 646 +Silence is goldenSignature · 1 line
2.26.3
Quoted 84 lines · Darrick J. Wong
src/mmap-rw-fault.c
Quoted 44 lines · Andreas Gruenbacher
Here's an update of a test case I'm trying to get merged since May. Please have a look; I'm tired of dragging this along.
Thanks,
Andreas--
Some filesystems have problems when the buffer passed to read or write is memory-mapped to the file being read from or written to, and the buffer needs to be faulted in during the read or write. That's not common, but filesystems are still required to cope with it, and if they fail this test, then they will also fail more complex scenarios that involve multiple files.
Signed-off-by Andreas Gruenbacher <[email protected]>--- src/Makefile | 2 +- src/mmap-rw-fault.c | 176 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/646 | 27 +++++++ tests/generic/646.out | 2 + 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/mmap-rw-fault.c create mode 100755 tests/generic/646 create mode 100644 tests/generic/646.outsrc/Makefile +1
-1@@ -18,7 +18,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ t_ext4_dax_journal_corruption t_ext4_dax_inline_corruption \ t_ofd_locks t_mmap_collision mmap-write-concurrent \ t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \ - t_mmap_writev_overlap checkpoint_journal + t_mmap_writev_overlap checkpoint_journal mmap-rw-fault LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \src/mmap-rw-fault.c new file +0
-0The generated binary needs a gitignore entry.
src/mmap-rw-fault.c line 1
Quoted 2 lines
src/mmap-rw-fault.c new file +1
-0@@ -0,0 +1,176 @@ +/* Trigger mmap page faults in the same file during pread and pwrite. */ Needs a SPDX header and a copyright statement.
Quoted 5 lines
src/mmap-rw-fault.c new file +5
-0+ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE/* to get definition of O_DIRECT flag. */ +#endif +src/mmap-rw-fault.c line 16
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <err.h> <now we skip to main>
Quoted 13 lines
src/mmap-rw-fault.c new file +13
-0+int main (int argc,char *argv[]) +{ +if (argc !=2 ) +errx (1 ,"no test filename argument given" ); + filename = argv[1 ]; + + page_size = ret =sysconf (_SC_PAGE_SIZE); +if (ret ==-1 ) +err (1 ,NULL ); + + ret =posix_memalign (&page, page_size, page_size); +if (ret) { + errno =ENOMEM ;
Quoted 8 lines
src/mmap-rw-fault.c line 124
Quoted 6 lines
src/mmap-rw-fault.c new file +6
-0+err (1 ,NULL ); + } + +/* +* Make sure page faults during pread are handled correctly. +*/ These test reading from page 1 into (mmap) page 0, right?
Yes. I've added more comments.
Quoted 13 lines
Quoted 13 lines
src/mmap-rw-fault.c new file +13
-0+init ('a' ,O_RDWR ); + ret =do_read (fd, addr, page_size, page_size); +if (ret != page_size) +err (1 ,"pread %s: %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pread is broken" ); +done (); + +init ('b' ,O_RDWR |O_DIRECT ); + ret =do_read (fd, addr, page_size, page_size); +if (ret != page_size) +err (1 ,"pread %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size))
Quoted 8 lines
src/mmap-rw-fault.c line 143
Quoted 6 lines
src/mmap-rw-fault.c new file +6
-0+errx (1 ,"pread (D_DIRECT) is broken" ); +done (); + +/* +* Make sure page faults during pwrite are handled correctly. +*/ ...and writing from (mmap) page 1 into page 0?
Yes.
Quoted 22 lines
Quoted 9 lines
src/mmap-rw-fault.c new file +9
-0+init ('c' ,O_RDWR ); + ret =do_write (fd, addr + page_size, page_size,0 ); +if (ret != page_size) +err (1 ,"pwrite %s: %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pwrite is broken" ); +done (); + +init ('d' ,O_RDWR |O_DIRECT );src/mmap-rw-fault.c line 162
Quoted 10 lines
src/mmap-rw-fault.c new file +10
-0+ ret =do_write (fd, addr + page_size, page_size,0 ); +if (ret != page_size) +err (1 ,"pwrite %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pwrite (O_DIRECT) is broken" ); +done (); + +/* +* Reading from a hole takes a different code path in the kernel. +*/ ...and finally we test direct reading from page 0 into (mmap) page 0?
Quoted 2 lines
If that's correct, then this looks good to me, modulo the license nit at the top.
Yes.
Quoted 47 lines
Quoted 34 lines
src/mmap-rw-fault.c new file +14
-0+init ('e' ,O_RDWR |O_DIRECT ); + ret =do_read (fd, addr, page_size,0 ); +if (ret != page_size) +err (1 ,"pread %s (O_DIRECT) from hole: %ld != %u" , filename, ret, page_size); +memset (page,0 , page_size); +if (memcmp (addr, page, page_size)) +errx (1 ,"pread (D_DIRECT) from hole is broken" ); +done (); + +if (unlink (filename)) +err (1 ,"unlink %s" , filename); + +return 0 ; +}tests/generic/646 new file +14
-0@@ -0,0 +1,27 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test 646 +# +# Trigger mmap page faults in the same file during pread and pwrite +# +. ./common/preamble +_begin_fstest auto quick + +# get standard environment, filters and checks +. ./common/rc +. ./common/filtertests/generic/646 line 24
Quoted 10 lines
tests/generic/646 new file +10
-0+ +# real QA test starts here + +_supported_fs generic +_require_test +_require_test_program mmap-rw-fault + +echo "Silence is golden" + +$here/src/mmap-rw-fault $TEST_DIR/mmap-rw-fault.tmp
_cleanupshould clean up the tempfile if the C program crashes, right?
Quoted 1 line
Or use
O_TMPFILEand let the kernel clean up the file for you.
Yep, I'll go for the _cleanup approach.
Thanks,
Andreas