Merge branch 'master' of git://oss.sgi.com/xfs/cmds/xfstests
[xfstests-dev.git] / 031
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FS QA Test No. 031
22 #
23 # exercise xfs_repair - ensure repeated use doesn't corrupt
24 #
25 # creator
26 owner=nathans@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
35 rm -f $seq.full
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.repair
40 . ./common.filter
41
42 # link correct .out file
43 _link_out_file $seq.out
44
45 _check_repair()
46 {
47         echo "Repairing, round 0" >> $seq.full
48         _scratch_xfs_repair 2>&1 | _filter_repair | tee -a $seq.full >$tmp.0
49         for i in 1 2 3 4
50         do
51                 echo "Repairing, iteration $i" | tee -a $seq.full
52                 _scratch_xfs_repair 2>&1 | _filter_repair >$tmp.$i
53                 diff $tmp.0 $tmp.$i >> $seq.full
54                 if [ $? -ne 0 ]; then
55                         echo "ERROR: repair round $i differs to round 0 (see $seq.full)" | tee -a $seq.full
56                         break
57                 fi
58                 # echo all interesting stuff...
59                 perl -ne '
60                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
61                         s/internal log/<TYPEOF> log/g;
62                         s/external log on \S+/<TYPEOF> log/g;
63                         /^\S+/ && print;
64                 ' $tmp.$i
65         done
66         echo
67 }
68
69 # prototype file to create various directory forms
70 _create_proto()
71 {
72         total=$1
73         count=0
74
75         # take inode size into account for non-shortform directories...
76         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
77
78         cat >$tmp.proto <<EOF
79 DUMMY1
80 0 0
81 : root directory
82 d--777 3 1
83 lost+found d--755 3 1
84 $
85 EOF
86
87         while [ $count -lt $total ]
88         do
89                 let count=$count+1
90                 cat >>$tmp.proto <<EOF
91 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
92 EOF
93         done
94         echo '$' >>$tmp.proto
95 }
96
97 # real QA test starts here
98 _supported_fs xfs
99 _supported_os IRIX Linux
100
101 _require_nobigloopfs
102 _require_scratch
103
104 # sanity test - default + one root directory entry
105 # Note: must do this proto/mkfs now for later inode size calcs
106 _create_proto 0
107 echo "=== one entry (shortform)"
108 _scratch_mkfs_xfs -p $tmp.proto >$tmp.mkfs0 2>&1
109 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
110 . $tmp.mkfs
111 _check_repair
112
113 # block-form root directory & repeat
114 _create_proto 20
115 echo "=== twenty entries (block form)"
116 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
117 _check_repair
118
119 # leaf-form root directory & repeat
120 _create_proto 1000
121 echo "=== thousand entries (leaf form)"
122 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
123 _check_repair
124
125 # success, all done
126 status=0
127 exit