6292b5e1b3ed8ee026cc0e72edfb7aac9c9261b5
[xfstests-dev.git] / tests / xfs / 495
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 495
6 #
7 # Test for two related regressions -- first, check that repair doesn't
8 # repeatedly rebuild directories with a single leafn block; and check that
9 # repair also doesn't crash when it hits a corrupt da btree with a zero before
10 # pointer.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 7 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/populate
31 . ./common/fuzzy
32
33 # real QA test starts here
34 _supported_fs xfs
35 _require_scratch_xfs_fuzz_fields
36
37 echo "Format and populate"
38 _scratch_populate_cached nofill > $seqres.full 2>&1
39
40 filter_nbrepair() {
41         grep rebuilding | sed -e 's/directory inode [0-9]*/directory inode XXX/g'
42 }
43
44 run_repair() {
45         _scratch_xfs_repair > $tmp.repair 2>&1
46         cat $tmp.repair >> $seqres.full
47         cat $tmp.repair | filter_nbrepair
48 }
49
50 echo "Check leafn rebuilds"
51 run_repair
52 run_repair
53
54 echo "Fuzz nbtree[0].before to zero"
55 _scratch_mount
56 inum=$(stat -c '%i' $SCRATCH_MNT/S_IFDIR.FMT_NODE)
57 blk_sz=$(_get_block_size $SCRATCH_MNT)
58 _scratch_unmount
59 leaf_offset=$(( (2 ** 35) / blk_sz ))
60 _scratch_xfs_fuzz_metadata_field "nbtree[0].before" "zeroes" "inode ${inum}" \
61                                  "dblock ${leaf_offset}" >> $seqres.full
62
63 echo "Check nbtree[0].before repair"
64 run_repair
65 run_repair
66
67 # success, all done
68 echo Done
69 status=0
70 exit