Replace metaperf gedents code with a more useful readdir operation; add some auto...
[xfstests-dev.git] / common.repair
1 ##/bin/sh
2
3 #
4 # Functions useful for xfs_repair tests
5
6 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
7
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
11
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like.  Any license provided herein, whether implied or
19 # otherwise, applies only to this software file.  Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
22
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write the Free Software Foundation, Inc., 59
25 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
26
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA  94043, or:
29
30 # http://www.sgi.com 
31
32 # For further information regarding this notice, see: 
33
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #
36
37 _zero_position()
38 {
39         value=$1
40         struct="$2"
41
42         # set values for off/len variables provided by db
43         eval `xfs_db -r -c "$struct" -c stack $SCRATCH_DEV | perl -ne '
44                 if (/byte offset (\d+), length (\d+)/) {
45                         print "offset=$1\nlength=$2\n"; exit
46                 }'`
47         if [ -z "$offset" -o -z "$length" ]; then
48                 echo "cannot calculate offset ($offset) or length ($length)"
49                 exit
50         fi
51         length=`expr $length / 512`
52         src/devzero -v $value -b 1 -n $length -o $offset $SCRATCH_DEV \
53                 | perl -npe 's/\d\.\d\dKb/X.XXKb/g'
54 }
55
56 _filter_repair()
57 {
58         perl -ne '
59 # for sb
60 /- agno = / && next;    # remove each AG line (variable number)
61 s/(pointer to) (\d+)/\1 INO/;
62 s/(sb root inode value) (\d+)( \(NULLFSINO\))?/\1 INO/;
63 s/(realtime bitmap inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
64 s/(realtime summary inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
65 s/(inconsistent with calculated value) (\d+)/\1 INO/;
66 s/\.+(found)/\1/g;      # remove "searching" output
67 # for agf + agi
68 s/(bad length -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
69 s/(bad length # -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
70 s/(bad agbno) (\d+)/\1 AGBNO/g;
71 s/(max =) (\d+)/\1 MAX/g;
72 # for root inos
73 s/(on inode) (\d+)/\1 INO/g;
74 s/(imap claims a free inode) (\d+)/\1 INO/;
75 s/(imap claims in-use inode) (\d+)/\1 INO/;
76 s/(cleared root inode) (\d+)/\1 INO/;
77 s/(resetting inode) (\d+)/\1 INO/;
78 s/(disconnected dir inode) (\d+)/\1 INO/;
79 # for log
80 s/internal log/<TYPEOF> log/g;
81 s/external log on \S+/<TYPEOF> log/g;
82         print;'
83 }
84
85 _filter_dd()
86 {
87         fgrep -v records        # lose records in/out lines
88 }
89
90 # do some controlled corrupting & ensure repair recovers us
91
92 _check_repair()
93 {
94         value=$1
95         structure="$2"
96         _zero_position $value "$structure"
97         _scratch_xfs_repair 2>&1 | _filter_repair
98         # some basic sanity checks...
99         _check_scratch_fs
100         _scratch_mount                                      #mount
101         POSIXLY_CORRECT=yes \
102         dd if=/bin/sh of=$SCRATCH_MNT/sh 2>&1 |_filter_dd   #open,write
103         POSIXLY_CORRECT=yes \
104         dd if=$SCRATCH_MNT/sh of=/dev/null 2>&1 |_filter_dd #read
105         rm -f $SCRATCH_MNT/sh                               #unlink
106         umount $SCRATCH_MNT                                 #umount
107 }
108
109 # make sure this script returns success
110 /bin/true