422a2712a3216baf70d26ace9b07d709a8761049
[xfstests-dev.git] / tests / xfs / 031
1 #! /bin/bash
2 # FS QA Test No. 031
3 #
4 # exercise xfs_repair - ensure repeated use doesn't corrupt
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 seq=`basename $0`
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
32 rm -f $seq.full
33
34 # get standard environment, filters and checks
35 . ./common.rc
36 . ./common.repair
37 . ./common.filter
38
39 # link correct .out file
40 _link_out_file $seq.out
41
42 _check_repair()
43 {
44         echo "Repairing, round 0" >> $seq.full
45         _scratch_xfs_repair 2>&1 | _filter_repair | tee -a $seq.full >$tmp.0
46         for i in 1 2 3 4
47         do
48                 echo "Repairing, iteration $i" | tee -a $seq.full
49                 _scratch_xfs_repair 2>&1 | _filter_repair >$tmp.$i
50                 diff $tmp.0 $tmp.$i >> $seq.full
51                 if [ $? -ne 0 ]; then
52                         echo "ERROR: repair round $i differs to round 0 (see $seq.full)" | tee -a $seq.full
53                         break
54                 fi
55                 # echo all interesting stuff...
56                 perl -ne '
57                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
58                         s/internal log/<TYPEOF> log/g;
59                         s/external log on \S+/<TYPEOF> log/g;
60                         /^\S+/ && print;
61                 ' $tmp.$i
62         done
63         echo
64 }
65
66 # prototype file to create various directory forms
67 _create_proto()
68 {
69         total=$1
70         count=0
71
72         # take inode size into account for non-shortform directories...
73         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
74
75         cat >$tmp.proto <<EOF
76 DUMMY1
77 0 0
78 : root directory
79 d--777 3 1
80 lost+found d--755 3 1
81 $
82 EOF
83
84         while [ $count -lt $total ]
85         do
86                 let count=$count+1
87                 cat >>$tmp.proto <<EOF
88 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
89 EOF
90         done
91         echo '$' >>$tmp.proto
92 }
93
94 # real QA test starts here
95 _supported_fs xfs
96 _supported_os IRIX Linux
97
98 _require_scratch
99 _require_no_large_scratch_dev
100
101 # sanity test - default + one root directory entry
102 # Note: must do this proto/mkfs now for later inode size calcs
103 _create_proto 0
104 echo "=== one entry (shortform)"
105 _scratch_mkfs_xfs -p $tmp.proto >$tmp.mkfs0 2>&1
106 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
107 . $tmp.mkfs
108 _check_repair
109
110 # block-form root directory & repeat
111 _create_proto 20
112 echo "=== twenty entries (block form)"
113 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
114 _check_repair
115
116 # leaf-form root directory & repeat
117 _create_proto 1000
118 echo "=== thousand entries (leaf form)"
119 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
120 _check_repair
121
122 # success, all done
123 status=0
124 exit