generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 030
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. 030
6 #
7 # exercise xfs_repair repairing broken filesystems
8 #
9 seqfull=$0
10 . ./common/preamble
11 _begin_fstest repair auto quick
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         _scratch_unmount 2>/dev/null
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/repair
24 . ./common/quota
25
26 # nuke the superblock, AGI, AGF, AGFL; then try repair the damage
27 #
28 _check_ag()
29 {
30         for structure in 'sb 0' 'agf 0' 'agi 0' 'agfl 0'
31         do
32                 echo "Corrupting $structure - setting bits to $1"
33                 _check_repair $1 "$structure" | uniq |
34                         sed -e '/^error following ag 0 unlinked list$/d' \
35                             -e '/^bad agbno AGBNO for finobt/d' \
36                             -e '/^bad agbno AGBNO for rmapbt/d' \
37                             -e '/^bad agbno AGBNO for refcntbt/d' \
38                             -e '/^agf has bad CRC/d' \
39                             -e '/^agi has bad CRC/d' \
40                             -e '/^bad inobt block count/d' \
41                             -e '/^bad finobt block count/d' \
42                             -e '/^Missing reverse-mapping record.*/d' \
43                             -e '/^bad levels LEVELS for [a-z]* root.*/d' \
44                             -e '/^unknown block state, ag AGNO, block.*/d'
45         done
46 }
47
48 # real QA test starts here
49 _supported_fs xfs
50
51 _require_scratch
52 _require_no_large_scratch_dev
53
54 DSIZE="-dsize=100m,agcount=6"
55
56 # first we need to ensure there are no bogus secondary
57 # superblocks between the primary and first secondary
58 # superblock (hanging around from earlier tests)...
59 #
60
61 _scratch_mkfs_xfs $DSIZE >/dev/null 2>&1
62 if [ $? -ne 0 ]         # probably don't have a big enough scratch
63 then
64         _notrun "SCRATCH_DEV too small, results would be non-deterministic"
65 else
66         _qmount_option noquota
67         _scratch_mount
68         $here/src/feature -U $SCRATCH_DEV && \
69                 _notrun "UQuota are enabled, test needs controlled sb recovery"
70         $here/src/feature -G $SCRATCH_DEV && \
71                 _notrun "GQuota are enabled, test needs controlled sb recovery"
72         $here/src/feature -P $SCRATCH_DEV && \
73                 _notrun "PQuota are enabled, test needs controlled sb recovery"
74         _scratch_unmount
75 fi
76 clear=""
77 eval `_scratch_xfs_db -r -c "sb 1" -c stack | perl -ne '
78         if (/byte offset (\d+), length (\d+)/) {
79                 print "clear=", $1 / 512, "\n"; exit
80         }'`
81 [ -z "$clear" ] && echo "Cannot calculate length to clear"
82 $here/src/devzero -v -1 -n "$clear" $SCRATCH_DEV >/dev/null
83
84 # now kick off the real repair test...
85 #
86 _scratch_mkfs_xfs $DSIZE | _filter_mkfs 2>$tmp.mkfs
87 . $tmp.mkfs
88 _check_ag 0
89 _check_ag -1
90
91 # success, all done
92 status=0
93 exit