4 # This test implements a data corruption scenario on XFS filesystems with
5 # sub-page sized blocks and unwritten extents. Inode lock contention during
6 # writeback of pages to unwritten extents leads to failure to convert those
7 # extents on I/O completion. This causes data corruption as unwritten extents
8 # are always read back as zeroes.
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
40 kill -9 $syncpid > /dev/null 2>&1
45 # get standard environment, filters and checks
49 # real QA test starts here
59 # Modify as appropriate.
63 _require_xfs_io_command "falloc"
64 _require_xfs_io_command "fiemap"
66 _scratch_mkfs >/dev/null 2>&1
69 # run background sync thread
73 for iters in $(seq 1 100)
75 rm -f $SCRATCH_MNT/file
77 # create a delalloc block in each page of the first 64k of the file
78 for pgoff in $(seq 0 0x1000 0xf000); do
79 offset=$((pgoff + 0xc00))
81 -c "pwrite $offset 0x1" \
82 $SCRATCH_MNT/file >> $seqres.full 2>&1
85 # preallocate the first 64k and overwite, writing past 64k to contend
88 -c "falloc 0 0x10000" \
89 -c "pwrite 0 0x100000" \
91 $SCRATCH_MNT/file >> $seqres.full 2>&1
93 # Check for unwritten extents. We should have none since we wrote over
94 # the entire preallocated region and ran fsync.
95 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/file | \
96 tee -a $seqres.full | \
97 _filter_fiemap | grep unwritten
98 [ $? == 0 ] && _fail "Unwritten extents found!"
101 echo $iters iterations
106 # clear page cache and dump the file
108 hexdump $SCRATCH_MNT/file