xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / generic / 032
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 032
6 #
7 # This test implements a data corruption scenario on XFS filesystems with
8 # sub-page sized blocks and unwritten extents. Inode lock contention during
9 # writeback of pages to unwritten extents leads to failure to convert those
10 # extents on I/O completion. This causes data corruption as unwritten extents
11 # are always read back as zeroes.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         kill -9 $syncpid > /dev/null 2>&1
26         wait
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/punch
33
34 # real QA test starts here
35 rm -f $seqres.full
36
37 _syncloop()
38 {
39         while [ true ]; do
40                 sync
41         done
42 }
43
44 # Modify as appropriate.
45 _supported_fs generic
46 _require_scratch
47 _require_xfs_io_command "falloc"
48 _require_xfs_io_command "fiemap"
49
50 _scratch_mkfs >/dev/null 2>&1
51 _scratch_mount
52
53 # run background sync thread
54 _syncloop &
55 syncpid=$!
56
57 for iters in $(seq 1 100)
58 do
59         rm -f $SCRATCH_MNT/file
60
61         # create a delalloc block in each page of the first 64k of the file
62         for pgoff in $(seq 0 0x1000 0xf000); do
63                 offset=$((pgoff + 0xc00))
64                 $XFS_IO_PROG -f \
65                         -c "pwrite $offset 0x1" \
66                         $SCRATCH_MNT/file >> $seqres.full 2>&1
67         done
68
69         # preallocate the first 64k and overwite, writing past 64k to contend
70         # with writeback
71         file_len=0x100000
72         $XFS_IO_PROG \
73                 -c "falloc 0 0x10000"   \
74                 -c "pwrite 0 $file_len" \
75                 -c "fsync"              \
76                 $SCRATCH_MNT/file >> $seqres.full 2>&1
77
78         # Check for unwritten extents. We should have none before EOF since we
79         # wrote over the entire preallocated region and ran fsync.
80         eof_sector=$(( file_len / 512 ))
81         $XFS_IO_PROG -c 'fiemap -v' $SCRATCH_MNT/file | \
82                 _filter_fiemap | \
83                 tr '[.]:' '    ' | \
84                 awk "{if (\$2 < $eof_sector) {print \$0}}" | \
85                 grep -q unwritten && _fail "Unwritten extents found!"
86 done
87
88 echo $iters iterations
89
90 kill $syncpid
91 wait
92
93 # clear page cache and dump the file
94 _scratch_cycle_mount
95 hexdump $SCRATCH_MNT/file
96
97 status=0
98 exit