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