xfs/007: fix regressions on V4 filesystems
[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 . ./common/preamble
11 _begin_fstest auto quick repair fuzzers
12
13 # Import common functions.
14 . ./common/filter
15 . ./common/attr
16
17 # Modify as appropriate.
18 _supported_fs xfs
19 _require_scratch
20 _require_attrs
21
22 # get block size ($dbsize) from the mkfs output
23 _scratch_mkfs_xfs 2>/dev/null | _filter_mkfs 2>$tmp.mkfs >/dev/null
24 . $tmp.mkfs
25
26 _scratch_mount
27
28 touch $SCRATCH_MNT/$seq.attrfile
29 inum=$(stat -c '%i' $SCRATCH_MNT/$seq.attrfile)
30
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
39
40 _scratch_unmount
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
44
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"
51 fi
52
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
56 if [ $? -eq 0 ];then
57         _fail "xfs_repair can't find the corruption"
58 else
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
62
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"
69         if [ $? -ne 0 ]; then
70                 _fail "xfs_repair didn't junk the empty attr leaf"
71         fi
72 fi
73
74 echo "Silence is golden"
75
76 # success, all done
77 status=0
78 exit