From: Eryu Guan Date: Thu, 9 Nov 2017 08:32:42 +0000 (+0800) Subject: generic: test zero page cache beyond new EOF on truncate down X-Git-Tag: v2022.05.01~1773 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=80ec2dd71cebbfea069678f97b9c34e3286e9fb1;p=users%2Fhch%2Fxfstests-dev.git generic: test zero page cache beyond new EOF on truncate down From mmap(2) manpage, "a file is mapped in multiples of the page size. For a file that is not a multiple of the page size, the remaining memory is zeroed when mapped", this test is to test this behavior on truncate down. This is inspired by an XFS bug that truncate down fails to zero page cache beyond new EOF and causes stale data written to disk unexpectedly and a subsequent mmap sees non-zeros post EOF. Patch "xfs: truncate pagecache before writeback in xfs_setattr_size()" fixed the bug on XFS. Reviewed-by: Darrick J. Wong Signed-off-by: Eryu Guan --- diff --git a/tests/generic/469 b/tests/generic/469 new file mode 100755 index 000000000..ab0969a97 --- /dev/null +++ b/tests/generic/469 @@ -0,0 +1,135 @@ +#! /bin/bash +# FS QA Test 469 +# +# Test that mmap read doesn't see non-zero data past EOF on truncate down. +# +# This is inspired by an XFS bug that truncate down fails to zero page cache +# beyond new EOF and causes stale data written to disk unexpectedly and a +# subsequent mmap reads and sees non-zeros post EOF. +# +# Patch "xfs: truncate pagecache before writeback in xfs_setattr_size()" fixed +# the bug on XFS. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Red Hat Inc., All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +file=$TEST_DIR/$seq.fsx +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $file $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_test + +run_fsx() +{ + $here/ltp/fsx $2 --replay-ops $1 $file 2>&1 | tee -a $seqres.full >$tmp.fsx + if [ ${PIPESTATUS[0]} -ne 0 ]; then + cat $tmp.fsx + exit 1 + fi +} + +# run fsx with and without fsync(2) after write to get more coverage +test_fsx() +{ + echo "fsx --replay-ops ${1#*.}" | tee -a $seqres.full + run_fsx $1 + + echo "fsx -y --replay-ops ${1#*.}" | tee -a $seqres.full + run_fsx $1 -y +} + +# simplified fsx operations that work on small & not blocksize-aligned offsets, +# so filesystems with small block size could reproduce too +cat >$tmp.fsxops.0 <$tmp.fsxops.1 <$tmp.fsxops.2 <$tmp.fsxops.3 <