reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 042
1 #! /bin/bash
2 # FS QA Test No. 042
3 #
4 # Test stale data exposure via writeback using various file allocation
5 # modification commands. The presumption is that such commands result in partial
6 # writeback and can convert a delayed allocation extent, that might be larger
7 # than the ranged affected by fallocate, to a normal extent. If the fs happens
8 # to crash sometime between when the extent modification is logged and writeback
9 # occurs for dirty pages within the extent but outside of the fallocated range,
10 # stale data exposure can occur.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/punch
49
50 # real QA test starts here
51 rm -f $seqres.full
52
53 _crashtest()
54 {
55         cmd=$1
56         img=$SCRATCH_MNT/$seq.img
57         mnt=$SCRATCH_MNT/$seq.mnt
58         file=$mnt/file
59
60         # Create an fs on a small, initialized image. The pattern is written to
61         # the image to detect stale data exposure.
62         $XFS_IO_PROG -f -c "truncate 0" -c "pwrite 0 25M" $img \
63                 >> $seqres.full 2>&1
64         _mkfs_dev $img >> $seqres.full 2>&1
65
66         mkdir -p $mnt
67         _mount $img $mnt
68
69         echo $cmd
70
71         # write, run the test command and shutdown the fs
72         $XFS_IO_PROG -f -c "pwrite -S 1 0 64k" -c "$cmd 60k 4k" $file | \
73                 _filter_xfs_io
74         ./src/godown -f $mnt
75
76         $UMOUNT_PROG $mnt
77         _mount $img $mnt
78
79         # we generally expect a zero-sized file (this should be silent)
80         hexdump $file
81
82         $UMOUNT_PROG $mnt
83 }
84
85 # Modify as appropriate.
86 _supported_fs generic
87 _supported_os Linux
88 _require_scratch
89 _require_scratch_shutdown
90 _require_xfs_io_command "falloc"
91 _require_xfs_io_command "fpunch"
92 _require_xfs_io_command "fzero"
93
94 _scratch_mkfs >/dev/null 2>&1
95 _scratch_mount
96
97 _crashtest "falloc -k"
98 _crashtest "fpunch"
99 _crashtest "fzero -k"
100
101 status=0
102 exit