4 # Create and populate an XFS filesystem, corrupt the rmap btree,
5 # then see how the kernel and xfs_repair deal with it.
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Oracle, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
45 # real QA test starts here
48 _require_xfs_scratch_rmapbt
49 test -n ${FORCE_FUZZ} || _require_scratch_xfs_crc
53 echo "+ create scratch fs"
54 _scratch_mkfs_xfs > /dev/null
56 echo "+ mount fs image"
58 blksz=$(stat -f -c '%s' ${SCRATCH_MNT})
59 agcount=$(xfs_info ${SCRATCH_MNT} | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')
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
69 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
70 _fail "xfs_repair should not fail"
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
83 $XFS_IO_PROG -f -c "pwrite -S 0x63 0 $((blksz * 64))" -c "fsync" ${SCRATCH_MNT}/file4 >> $seqres.full
84 test -s ${SCRATCH_MNT}/file4 || _fail "should not be able to copy with busted rmap btree"
88 _scratch_xfs_repair >> $seqres.full 2>&1
89 _scratch_xfs_repair >> $seqres.full 2>&1
91 echo "+ mount image (2)"
95 chattr -R -f -i ${SCRATCH_MNT}/
97 echo "+ copy more (2)"
98 cp -p ${SCRATCH_MNT}/file1 ${SCRATCH_MNT}/file5 || \
99 _fail "modified rmap tree"
100 umount ${SCRATCH_MNT}
102 echo "+ check fs (2)"
103 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
104 _fail "xfs_repair should not fail"