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