15f41edd5b4f042848ab3dc75de7b10ce8f61c67
[xfstests-dev.git] / tests / xfs / 030
1 #! /bin/bash
2 # FS QA Test No. 030
3 #
4 # exercise xfs_repair repairing broken filesystems
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seqfull=$0
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 _cleanup()
35 {
36         cd /
37         _scratch_unmount 2>/dev/null
38         rm -f $tmp.*
39 }
40
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/repair
47
48 # link correct .out file
49 _link_out_file
50
51 # nuke the superblock, AGI, AGF, AGFL; then try repair the damage
52 #
53 _check_ag()
54 {
55         for structure in 'sb 0' 'agf 0' 'agi 0' 'agfl 0'
56         do
57                 echo "Corrupting $structure - setting bits to $1"
58                 _check_repair $1 "$structure" | uniq |
59                         sed -e '/^error following ag 0 unlinked list$/d' \
60                             -e '/^bad agbno AGBNO for finobt/d' \
61                             -e '/^bad agbno AGBNO for rmapbt/d' \
62                             -e '/^bad agbno AGBNO for refcntbt/d' \
63                             -e '/^Missing reverse-mapping record.*/d' \
64                             -e '/^unknown block state, ag 0, block.*/d'
65         done
66 }
67
68 # real QA test starts here
69 _supported_fs xfs
70 _supported_os IRIX Linux
71
72 _require_scratch
73 _require_no_large_scratch_dev
74
75 DSIZE="-dsize=100m,agcount=6"
76
77 # first we need to ensure there are no bogus secondary
78 # superblocks between the primary and first secondary
79 # superblock (hanging around from earlier tests)...
80 #
81
82 _scratch_mkfs_xfs $DSIZE >/dev/null 2>&1
83 if [ $? -ne 0 ]         # probably don't have a big enough scratch
84 then
85         _notrun "SCRATCH_DEV too small, results would be non-deterministic"
86 else
87         _scratch_mount
88         src/feature -U $SCRATCH_DEV && \
89                 _notrun "UQuota are enabled, test needs controlled sb recovery"
90         src/feature -G $SCRATCH_DEV && \
91                 _notrun "GQuota are enabled, test needs controlled sb recovery"
92         src/feature -P $SCRATCH_DEV && \
93                 _notrun "PQuota are enabled, test needs controlled sb recovery"
94         _scratch_unmount
95 fi
96 clear=""
97 eval `xfs_db -r -c "sb 1" -c stack $SCRATCH_DEV | perl -ne '
98         if (/byte offset (\d+), length (\d+)/) {
99                 print "clear=", $1 / 512, "\n"; exit
100         }'`
101 [ -z "$clear" ] && echo "Cannot calculate length to clear"
102 src/devzero -v -1 -n "$clear" $SCRATCH_DEV >/dev/null
103
104 # now kick off the real repair test...
105 #
106 _scratch_mkfs_xfs $DSIZE | _filter_mkfs 2>$tmp.mkfs
107 . $tmp.mkfs
108 _check_ag 0
109 _check_ag -1
110
111 # success, all done
112 status=0
113 exit