xfs/130,235: deal with an unreplayable dirty log
[xfstests-dev.git] / tests / xfs / 235
1 #! /bin/bash
2 # FS QA Test No. 235
3 #
4 # Create and populate an XFS filesystem, corrupt the rmap btree,
5 # then see how the kernel and xfs_repair deal with it.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Oracle, Inc.  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-7031  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     cd /
37     rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/attr
44
45 # real QA test starts here
46 _supported_os Linux
47 _supported_fs xfs
48 _require_xfs_scratch_rmapbt
49 test -n ${FORCE_FUZZ} || _require_scratch_xfs_crc
50
51 rm -f $seqres.full
52
53 echo "+ create scratch fs"
54 _scratch_mkfs_xfs > /dev/null
55
56 echo "+ mount fs image"
57 _scratch_mount
58 blksz=$(stat -f -c '%s' ${SCRATCH_MNT})
59 agcount=$(xfs_info ${SCRATCH_MNT} | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')
60
61 echo "+ make some files"
62 _pwrite_byte 0x62 0 $((blksz * 64)) ${SCRATCH_MNT}/file0 >> $seqres.full
63 _pwrite_byte 0x61 0 $((blksz * 64)) ${SCRATCH_MNT}/file1 >> $seqres.full
64 cp -p ${SCRATCH_MNT}/file0 ${SCRATCH_MNT}/file2
65 cp -p ${SCRATCH_MNT}/file1 ${SCRATCH_MNT}/file3
66 umount ${SCRATCH_MNT}
67
68 echo "+ check fs"
69 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
70         _fail "xfs_repair should not fail"
71
72 echo "+ corrupt image"
73 seq 0 $((agcount - 1)) | while read ag; do
74         $XFS_DB_PROG -x -c "agf ${ag}" -c "agf ${ag}" -c "addr rmaproot" \
75                 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
76                 ${SCRATCH_DEV} >> $seqres.full 2>&1
77 done
78
79 echo "+ mount image"
80 _scratch_mount
81
82 echo "+ copy more"
83 $XFS_IO_PROG -f -c "pwrite -S 0x63 0 $((blksz * 64))" -c "fsync" ${SCRATCH_MNT}/file4 >> $seqres.full 2>&1
84 test -s ${SCRATCH_MNT}/file4 && _fail "should not be able to copy with busted rmap btree"
85 umount ${SCRATCH_MNT}
86
87 echo "+ repair fs"
88 _disable_dmesg_check
89 _repair_scratch_fs >> "$seqres.full" 2>&1
90 _scratch_xfs_repair >> $seqres.full 2>&1
91
92 echo "+ mount image (2)"
93 _scratch_mount
94
95 echo "+ chattr -R -i"
96 $CHATTR_PROG -R -f -i ${SCRATCH_MNT}/
97
98 echo "+ copy more (2)"
99 cp -p ${SCRATCH_MNT}/file1 ${SCRATCH_MNT}/file5 || \
100         _fail "modified rmap tree"
101 umount ${SCRATCH_MNT}
102
103 echo "+ check fs (2)"
104 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
105         _fail "xfs_repair should not fail"
106
107 status=0
108 exit