bccdb6fc35ec55ed8405adf10b30ebdea242c082
[xfstests-dev.git] / tests / xfs / 288
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 288
6 #
7 # When an attribute leaf block count is 0, xfs_repair should junk
8 # that leaf directly (as xfsprogs commit f714016).
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # Modify as appropriate.
34 _supported_fs xfs
35 _supported_os Linux
36 _require_scratch
37 _require_attrs
38
39 # get block size ($dbsize) from the mkfs output
40 _scratch_mkfs_xfs 2>/dev/null | _filter_mkfs 2>$tmp.mkfs >/dev/null
41 . $tmp.mkfs
42
43 _scratch_mount
44
45 touch $SCRATCH_MNT/$seq.attrfile
46 inum=$(stat -c '%i' $SCRATCH_MNT/$seq.attrfile)
47
48 # To get an attr block leaf, we need to extend attr format to extent
49 # or btree format at least, and the max inode size is half of filesystem
50 # block size, so write half of block size attr to make sure attr
51 # out of local format.
52 maxisize=$((dbsize/2))
53 $SETFATTR_PROG -n "user.testattr${seq}" \
54                -v "$(perl -e "print 'v' x ${maxisize};")" \
55                $SCRATCH_MNT/$seq.attrfile
56
57 _scratch_unmount
58 # manually corrupt the XFS, by set the header count of attr to 0
59 _scratch_xfs_db -x -c "inode $inum" \
60                    -c "ablock 0" \
61                    -c "write hdr.count 0" >> $seqres.full
62
63 # make sure xfs_repair can find above corruption. If it can't, that
64 # means we need to fix this bug on current xfs_repair
65 _scratch_xfs_repair -n >> $seqres.full 2>&1
66 if [ $? -eq 0 ];then
67         _fail "xfs_repair can't find the corruption"
68 else
69         # If xfs_repair can find this corruption, then this repair
70         # should junk above leaf attribute and fix this XFS.
71         _scratch_xfs_repair >> $seqres.full 2>&1
72
73         # Old xfs_repair maybe find and fix this corruption by
74         # reset the first used heap value and the usedbytes cnt
75         # in ablock 0. That's not what we want. So check if
76         # xfs_repair has junked the whole ablock 0 by xfs_db.
77         _scratch_xfs_db -x -c "inode $inum" -c "ablock 0" | \
78                 grep -q "no attribute data"
79         if [ $? -ne 0 ]; then
80                 _fail "xfs_repair didn't junk the empty attr leaf"
81         fi
82 fi
83
84 echo "Silence is golden"
85
86 # success, all done
87 status=0
88 exit