populate: add _require_populate_commands to check for tools
[xfstests-dev.git] / tests / xfs / 314
1 #! /bin/bash
2 # FS QA Test No. 314
3 #
4 # Reflink a file with a few dozen extents, CoW a few blocks, and rm.
5 # Inject an error during rmap updates to test log recovery.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1    # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         cd /
36         _scratch_unmount > /dev/null 2>&1
37         rm -rf $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/reflink
44 . ./common/inject
45
46 # real QA test starts here
47 _supported_os Linux
48 _supported_fs xfs
49 _require_cp_reflink
50 _require_scratch_reflink
51 _require_xfs_scratch_rmapbt
52 _require_error_injection
53 _require_xfs_io_error_injection "rmap_finish_one"
54
55 rm -f $seqres.full
56
57 blksz=65536
58 blks=64
59 sz=$((blksz * blks))
60 echo "Format filesystem"
61 _scratch_mkfs >/dev/null 2>&1
62 _scratch_mount >> $seqres.full
63
64 echo "Create files"
65 _pwrite_byte 0x66 0 $sz $SCRATCH_MNT/file1 >> $seqres.full
66 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file2
67 _cp_reflink $SCRATCH_MNT/file1 $SCRATCH_MNT/file3
68
69 # Punch holes in file3
70 seq 1 2 $blks | while read off; do
71         $XFS_IO_PROG -c "fpunch $((off * blksz)) $blksz" $SCRATCH_MNT/file3 >> $seqres.full
72 done
73 sync
74
75 echo "Check files"
76 md5sum $SCRATCH_MNT/file1 | _filter_scratch
77 md5sum $SCRATCH_MNT/file2 | _filter_scratch
78 md5sum $SCRATCH_MNT/file3 | _filter_scratch
79
80 echo "Inject error"
81 _scratch_inject_error "rmap_finish_one"
82
83 echo "CoW a few blocks"
84 $XFS_IO_PROG -c "pwrite -W -S 0x67 -b $sz $((10 * blksz)) $((10 * blksz))" $SCRATCH_MNT/file2 >> $seqres.full
85
86 echo "FS should be shut down, touch will fail"
87 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
88
89 echo "Remount to replay log"
90 _scratch_inject_logprint >> $seqres.full
91
92 echo "FS should be online, touch should succeed"
93 touch $SCRATCH_MNT/goodfs
94
95 echo "Check files again"
96 md5sum $SCRATCH_MNT/file1 | _filter_scratch
97 md5sum $SCRATCH_MNT/file2 | _filter_scratch
98 md5sum $SCRATCH_MNT/file3 | _filter_scratch
99
100 echo "Done"
101
102 # success, all done
103 status=0
104 exit