Update QA tests for new lost+found behaviour
[xfstests-dev.git] / common.repair
1 ##/bin/sh
2 #
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # Functions useful for xfs_repair tests
6 #
7
8 _zero_position()
9 {
10         value=$1
11         struct="$2"
12
13         # set values for off/len variables provided by db
14         eval `xfs_db -r -c "$struct" -c stack $SCRATCH_DEV | perl -ne '
15                 if (/byte offset (\d+), length (\d+)/) {
16                         print "offset=$1\nlength=$2\n"; exit
17                 }'`
18         if [ -z "$offset" -o -z "$length" ]; then
19                 echo "cannot calculate offset ($offset) or length ($length)"
20                 exit
21         fi
22         length=`expr $length / 512`
23         src/devzero -v $value -b 1 -n $length -o $offset $SCRATCH_DEV \
24                 | perl -npe 's/\d\.\d\dKb/X.XXKb/g'
25 }
26
27 _filter_repair()
28 {
29         perl -ne '
30 # for sb
31 /- agno = / && next;    # remove each AG line (variable number)
32 s/(pointer to) (\d+)/\1 INO/;
33 s/(sb root inode value) (\d+)( \(NULLFSINO\))?/\1 INO/;
34 s/(realtime bitmap inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
35 s/(realtime summary inode) (\d+)( \(NULLFSINO\))?/\1 INO/;
36 s/(inconsistent with calculated value) (\d+)/\1 INO/;
37 s/\.+(found)/\1/g;      # remove "searching" output
38 # for agf + agi
39 s/(bad length -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
40 s/(bad length # -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
41 s/(bad agbno) (\d+)/\1 AGBNO/g;
42 s/(max =) (\d+)/\1 MAX/g;
43 # for root inos
44 s/(on inode) (\d+)/\1 INO/g;
45 s/(imap claims a free inode) (\d+)/\1 INO/;
46 s/(imap claims in-use inode) (\d+)/\1 INO/;
47 s/(cleared root inode) (\d+)/\1 INO/;
48 s/(resetting inode) (\d+)/\1 INO/;
49 s/(disconnected dir inode) (\d+)/\1 INO/;
50 # for log
51 s/internal log/<TYPEOF> log/g;
52 s/external log on \S+/<TYPEOF> log/g;
53 # realtime subvol - remove this whole line if it appears
54 s/        - generate realtime summary info and bitmap...\n//g;
55 #
56 # new xfs repair output filters
57 #
58 s/\s+- creating \d+ worker thread\(s\)\n//g;
59 s/\s+- reporting progress in intervals of \d+ minutes\n//g;
60 s/\s+- \d+:\d\d:\d\d:.*\n//g;
61         print;'
62 }
63
64 _filter_dd()
65 {
66         fgrep -v records        # lose records in/out lines
67 }
68
69 # do some controlled corrupting & ensure repair recovers us
70
71 _check_repair()
72 {
73         value=$1
74         structure="$2"
75
76         #ensure the filesystem has been dirtied since last repair
77         _scratch_mount
78         POSIXLY_CORRECT=yes \
79         dd if=/bin/sh of=$SCRATCH_MNT/sh 2>&1 |_filter_dd
80         sync
81         rm -f $SCRATCH_MNT/sh
82         umount $SCRATCH_MNT
83
84         _zero_position $value "$structure"
85         _scratch_xfs_repair 2>&1 | _filter_repair
86
87         # some basic sanity checks...
88         _check_scratch_fs
89         _scratch_mount                                      #mount
90         POSIXLY_CORRECT=yes \
91         dd if=/bin/sh of=$SCRATCH_MNT/sh 2>&1 |_filter_dd   #open,write
92         POSIXLY_CORRECT=yes \
93         dd if=$SCRATCH_MNT/sh of=/dev/null 2>&1 |_filter_dd #read
94         rm -f $SCRATCH_MNT/sh                               #unlink
95         umount $SCRATCH_MNT                                 #umount
96 }
97
98 # make sure this script returns success
99 /bin/true