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