2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc. All Rights Reserved.
7 # When an attribute leaf block count is 0, xfs_repair should junk
8 # that leaf directly (as xfsprogs commit f714016).
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
30 # remove previous $seqres.full before test
33 # Modify as appropriate.
39 # Due to xfs_db's write -d option is still not stable, and there's no
40 # plan to support attr3. So only run this case on V4 XFS.
41 # Please update this if xfs_db get enough improvement in one day.
42 if [ -z "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
45 # get block size ($dbsize) from the mkfs output
46 _scratch_mkfs_xfs $mkfs_opts 2>/dev/null | _filter_mkfs 2>$tmp.mkfs >/dev/null
51 touch $SCRATCH_MNT/$seq.attrfile
52 inum=$(stat -c '%i' $SCRATCH_MNT/$seq.attrfile)
54 # To get an attr block leaf, we need to extend attr format to extent
55 # or btree format at least, and the max inode size is half of filesystem
56 # block size, so write half of block size attr to make sure attr
57 # out of local format.
58 maxisize=$((dbsize/2))
59 $SETFATTR_PROG -n "user.testattr${seq}" \
60 -v "$(perl -e "print 'v' x ${maxisize};")" \
61 $SCRATCH_MNT/$seq.attrfile
64 # manually corrupt the XFS, by set the header count of attr to 0
65 _scratch_xfs_db -x -c "inode $inum" \
67 -c "write hdr.count 0" >> $seqres.full
69 # make sure xfs_repair can find above corruption. If it can't, that
70 # means we need to fix this bug on current xfs_repair
71 _scratch_xfs_repair -n >> $seqres.full 2>&1
73 _fail "xfs_repair can't find the corruption"
75 # If xfs_repair can find this corruption, then this repair
76 # should junk above leaf attribute and fix this XFS.
77 _scratch_xfs_repair >> $seqres.full 2>&1
79 # Old xfs_repair maybe find and fix this corruption by
80 # reset the first used heap value and the usedbytes cnt
81 # in ablock 0. That's not what we want. So check if
82 # xfs_repair has junked the whole ablock 0 by xfs_db.
83 _scratch_xfs_db -x -c "inode $inum" -c "ablock 0" | \
84 grep -q "no attribute data"
86 _fail "xfs_repair didn't junk the empty attr leaf"
90 echo "Silence is golden"