Prevent test 016 from running if mkfs options create an unworkable log for its purposes.
[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         print;'
56 }
57
58 _filter_dd()
59 {
60         fgrep -v records        # lose records in/out lines
61 }
62
63 # do some controlled corrupting & ensure repair recovers us
64
65 _check_repair()
66 {
67         value=$1
68         structure="$2"
69         _zero_position $value "$structure"
70         _scratch_xfs_repair 2>&1 | _filter_repair
71         # some basic sanity checks...
72         _check_scratch_fs
73         _scratch_mount                                      #mount
74         POSIXLY_CORRECT=yes \
75         dd if=/bin/sh of=$SCRATCH_MNT/sh 2>&1 |_filter_dd   #open,write
76         POSIXLY_CORRECT=yes \
77         dd if=$SCRATCH_MNT/sh of=/dev/null 2>&1 |_filter_dd #read
78         rm -f $SCRATCH_MNT/sh                               #unlink
79         umount $SCRATCH_MNT                                 #umount
80 }
81
82 # make sure this script returns success
83 /bin/true