fstests: move test group info to test files
[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 . ./common/preamble
14 _begin_fstest auto quick rw
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19         cd /
20         kill -9 $syncpid > /dev/null 2>&1
21         wait
22         rm -f $tmp.*
23 }
24
25 # Import common functions.
26 . ./common/punch
27
28 # real QA test starts here
29
30 _syncloop()
31 {
32         while [ true ]; do
33                 sync
34         done
35 }
36
37 # Modify as appropriate.
38 _supported_fs generic
39 _require_scratch
40 _require_xfs_io_command "falloc"
41 _require_xfs_io_command "fiemap"
42
43 _scratch_mkfs >/dev/null 2>&1
44 _scratch_mount
45
46 # run background sync thread
47 _syncloop &
48 syncpid=$!
49
50 for iters in $(seq 1 100)
51 do
52         rm -f $SCRATCH_MNT/file
53
54         # create a delalloc block in each page of the first 64k of the file
55         for pgoff in $(seq 0 0x1000 0xf000); do
56                 offset=$((pgoff + 0xc00))
57                 $XFS_IO_PROG -f \
58                         -c "pwrite $offset 0x1" \
59                         $SCRATCH_MNT/file >> $seqres.full 2>&1
60         done
61
62         # preallocate the first 64k and overwite, writing past 64k to contend
63         # with writeback
64         file_len=0x100000
65         $XFS_IO_PROG \
66                 -c "falloc 0 0x10000"   \
67                 -c "pwrite 0 $file_len" \
68                 -c "fsync"              \
69                 $SCRATCH_MNT/file >> $seqres.full 2>&1
70
71         # Check for unwritten extents. We should have none before EOF since we
72         # wrote over the entire preallocated region and ran fsync.
73         eof_sector=$(( file_len / 512 ))
74         $XFS_IO_PROG -c 'fiemap -v' $SCRATCH_MNT/file | \
75                 _filter_fiemap | \
76                 tr '[.]:' '    ' | \
77                 awk "{if (\$2 < $eof_sector) {print \$0}}" | \
78                 grep -q unwritten && _fail "Unwritten extents found!"
79 done
80
81 echo $iters iterations
82
83 kill $syncpid
84 wait
85
86 # clear page cache and dump the file
87 _scratch_cycle_mount
88 hexdump $SCRATCH_MNT/file
89
90 status=0
91 exit