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 _begin_fstest auto quick repair fuzzers
13 # Import common functions.
17 # Modify as appropriate.
22 # get block size ($dbsize) from the mkfs output
23 _scratch_mkfs_xfs 2>/dev/null | _filter_mkfs 2>$tmp.mkfs >/dev/null
28 touch $SCRATCH_MNT/$seq.attrfile
29 inum=$(stat -c '%i' $SCRATCH_MNT/$seq.attrfile)
31 # To get an attr block leaf, we need to extend attr format to extent
32 # or btree format at least, and the max inode size is half of filesystem
33 # block size, so write half of block size attr to make sure attr
34 # out of local format.
35 maxisize=$((dbsize/2))
36 $SETFATTR_PROG -n "user.testattr${seq}" \
37 -v "$(perl -e "print 'v' x ${maxisize};")" \
38 $SCRATCH_MNT/$seq.attrfile
41 # manually corrupt the XFS, by set the header count of attr to 0
42 _scratch_xfs_set_metadata_field "hdr.count" "0" \
43 "inode $inum" "ablock 0" >> $seqres.full
45 # verify current xfs_db write command can set hdr.count to 0. Old xfsprogs
46 # can't do that on v5 filesystems.
47 count=$(_scratch_xfs_get_metadata_field "hdr.count" \
48 "inode $inum" "ablock 0" 2> /dev/null)
49 if [ "$count" != "0" ]; then
50 _notrun "xfs_db can't set attr hdr.count to 0"
53 # make sure xfs_repair can find above corruption. If it can't, that
54 # means we need to fix this bug on current xfs_repair
55 _scratch_xfs_repair -n >> $seqres.full 2>&1
57 _fail "xfs_repair can't find the corruption"
59 # If xfs_repair can find this corruption, then this repair
60 # should junk above leaf attribute and fix this XFS.
61 _scratch_xfs_repair >> $seqres.full 2>&1
63 # Old xfs_repair maybe find and fix this corruption by
64 # reset the first used heap value and the usedbytes cnt
65 # in ablock 0. That's not what we want. So check if
66 # xfs_repair has junked the whole ablock 0 by xfs_db.
67 _scratch_xfs_db -x -c "inode $inum" -c "ablock 0" | \
68 grep -q "no attribute data"
70 _fail "xfs_repair didn't junk the empty attr leaf"
74 echo "Silence is golden"