From: Luis Chamberlain <mcgrof@kernel.org>
To: patches@lists.linux.dev, fstests@vger.kernel.org
Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org,
ziy@nvidia.com, vbabka@suse.cz, seanjc@google.com,
willy@infradead.org, david@redhat.com, hughd@google.com,
linmiaohe@huawei.com, muchun.song@linux.dev, osalvador@suse.de,
p.raghav@samsung.com, da.gomez@samsung.com, hare@suse.de,
john.g.garry@oracle.com, mcgrof@kernel.org,
"Darrick J . Wong" <djwong@kernel.org>
Subject: [PATCH v2 1/5] common: move mread() to generic helper _mread()
Date: Fri, 14 Jun 2024 17:29:30 -0700 [thread overview]
Message-ID: <20240615002935.1033031-2-mcgrof@kernel.org> (raw)
In-Reply-To: <20240615002935.1033031-1-mcgrof@kernel.org>
We want a shared way to use mmap in a way that we can test
for the SIGBUS, provide a shared routine which other tests can
leverage.
Suggested-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
common/rc | 28 ++++++++++++++++++++++++++++
tests/generic/574 | 36 ++++--------------------------------
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/common/rc b/common/rc
index 163041fea5b9..fa7942809d6c 100644
--- a/common/rc
+++ b/common/rc
@@ -52,6 +52,34 @@ _pwrite_byte() {
$XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
}
+_round_up_to_page_boundary()
+{
+ local n=$1
+ local page_size=$(_get_page_size)
+
+ echo $(( (n + page_size - 1) & ~(page_size - 1) ))
+}
+
+_mread()
+{
+ local file=$1
+ local offset=$2
+ local length=$3
+ local map_len=$(_round_up_to_page_boundary $(_get_filesize $file))
+
+ # Some callers expect xfs_io to crash with SIGBUS due to the mread,
+ # causing the shell to print "Bus error" to stderr. To allow this
+ # message to be redirected, execute xfs_io in a new shell instance.
+ # However, for this to work reliably, we also need to prevent the new
+ # shell instance from optimizing out the fork and directly exec'ing
+ # xfs_io. The easiest way to do that is to append 'true' to the
+ # commands, so that xfs_io is no longer the last command the shell sees.
+ # Don't let it write core files to the filesystem.
+ bash -c "trap '' SIGBUS; ulimit -c 0; $XFS_IO_PROG -r $file \
+ -c 'mmap -r 0 $map_len' \
+ -c 'mread -v $offset $length'; true"
+}
+
# mmap-write a byte into a range of a file
_mwrite_byte() {
local pattern="$1"
diff --git a/tests/generic/574 b/tests/generic/574
index cb42baaa67aa..d44c23e5abc2 100755
--- a/tests/generic/574
+++ b/tests/generic/574
@@ -52,34 +52,6 @@ setup_zeroed_file()
cmp $fsv_orig_file $fsv_file
}
-round_up_to_page_boundary()
-{
- local n=$1
- local page_size=$(_get_page_size)
-
- echo $(( (n + page_size - 1) & ~(page_size - 1) ))
-}
-
-mread()
-{
- local file=$1
- local offset=$2
- local length=$3
- local map_len=$(round_up_to_page_boundary $(_get_filesize $file))
-
- # Some callers expect xfs_io to crash with SIGBUS due to the mread,
- # causing the shell to print "Bus error" to stderr. To allow this
- # message to be redirected, execute xfs_io in a new shell instance.
- # However, for this to work reliably, we also need to prevent the new
- # shell instance from optimizing out the fork and directly exec'ing
- # xfs_io. The easiest way to do that is to append 'true' to the
- # commands, so that xfs_io is no longer the last command the shell sees.
- # Don't let it write core files to the filesystem.
- bash -c "trap '' SIGBUS; ulimit -c 0; $XFS_IO_PROG -r $file \
- -c 'mmap -r 0 $map_len' \
- -c 'mread -v $offset $length'; true"
-}
-
corruption_test()
{
local block_size=$1
@@ -142,7 +114,7 @@ corruption_test()
fi
# Reading the full file via mmap should fail.
- mread $fsv_file 0 $file_len >/dev/null 2>$tmp.err
+ _mread $fsv_file 0 $file_len >/dev/null 2>$tmp.err
if ! grep -q 'Bus error' $tmp.err; then
echo "Didn't see SIGBUS when reading file via mmap"
cat $tmp.err
@@ -150,7 +122,7 @@ corruption_test()
# Reading just the corrupted part via mmap should fail.
if ! $is_merkle_tree; then
- mread $fsv_file $zap_offset $zap_len >/dev/null 2>$tmp.err
+ _mread $fsv_file $zap_offset $zap_len >/dev/null 2>$tmp.err
if ! grep -q 'Bus error' $tmp.err; then
echo "Didn't see SIGBUS when reading corrupted part via mmap"
cat $tmp.err
@@ -174,10 +146,10 @@ corrupt_eof_block_test()
head -c $zap_len /dev/zero | tr '\0' X \
| _fsv_scratch_corrupt_bytes $fsv_file $file_len
- mread $fsv_file $file_len $zap_len >$tmp.out 2>$tmp.err
+ _mread $fsv_file $file_len $zap_len >$tmp.out 2>$tmp.err
head -c $file_len /dev/zero >$tmp.zeroes
- mread $tmp.zeroes $file_len $zap_len >$tmp.zeroes_out
+ _mread $tmp.zeroes $file_len $zap_len >$tmp.zeroes_out
grep -q 'Bus error' $tmp.err || diff $tmp.out $tmp.zeroes_out
}
--
2.43.0
next prev parent reply other threads:[~2024-06-15 0:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-15 0:29 [PATCH v2 0/5] fstests: add some new LBS inspired tests Luis Chamberlain
2024-06-15 0:29 ` Luis Chamberlain [this message]
2024-06-15 0:29 ` [PATCH v2 2/5] fstests: add mmap page boundary tests Luis Chamberlain
2024-06-18 14:07 ` Zorro Lang
2024-06-15 0:29 ` [PATCH v2 3/5] fstests: add fsstress + compaction test Luis Chamberlain
2024-06-15 0:29 ` [PATCH v2 4/5] _require_debugfs(): simplify and fix for debian Luis Chamberlain
2024-06-15 0:29 ` [PATCH v2 5/5] fstests: add stress truncation + writeback test Luis Chamberlain
2024-06-18 14:10 ` Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240615002935.1033031-2-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=da.gomez@samsung.com \
--cc=david@redhat.com \
--cc=djwong@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=hare@suse.de \
--cc=hughd@google.com \
--cc=john.g.garry@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=p.raghav@samsung.com \
--cc=patches@lists.linux.dev \
--cc=seanjc@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).