xfs/004: don't fail test due to realtime files
[xfstests-dev.git] / tests / xfs / 532
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Chandan Babu R.  All Rights Reserved.
4 #
5 # FS QA Test 532
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # adding/removing xattrs.
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/inject
29 . ./common/populate
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35
36 _supported_fs xfs
37 _require_scratch
38 _require_attrs
39 _require_xfs_debug
40 _require_test_program "punch-alternating"
41 _require_xfs_io_error_injection "reduce_max_iextents"
42 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
43
44 echo "Format and mount fs"
45 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
46 _scratch_mount >> $seqres.full
47
48 # Disable realtime inherit flag (if any) on root directory so that space on data
49 # device gets fragmented rather than realtime device.
50 $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
51
52 bsize=$(_get_block_size $SCRATCH_MNT)
53
54 attr_len=255
55
56 testfile=$SCRATCH_MNT/testfile
57
58 echo "Consume free space"
59 fillerdir=$SCRATCH_MNT/fillerdir
60 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
61 nr_free_blks=$((nr_free_blks * 90 / 100))
62
63 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
64
65 echo "Create fragmented filesystem"
66 for dentry in $(ls -1 $fillerdir/); do
67         $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
68 done
69
70 echo "Inject bmap_alloc_minlen_extent error tag"
71 _scratch_inject_error bmap_alloc_minlen_extent 1
72
73 echo "* Set xattrs"
74
75 echo "Create \$testfile"
76 touch $testfile
77
78 echo "Inject reduce_max_iextents error tag"
79 _scratch_inject_error reduce_max_iextents 1
80
81 echo "Create xattrs"
82 nr_attrs=$((bsize * 20 / attr_len))
83 for i in $(seq 1 $nr_attrs); do
84         attr="$(printf "trusted.%0247d" $i)"
85         $SETFATTR_PROG -n "$attr" $testfile >> $seqres.full 2>&1
86         [[ $? != 0 ]] && break
87 done
88
89 echo "Verify \$testfile's naextent count"
90
91 naextents=$(_xfs_get_fsxattr naextents $testfile)
92 if (( $naextents > 10 )); then
93         echo "Extent count overflow check failed: naextents = $naextents"
94         exit 1
95 fi
96
97 echo "Disable reduce_max_iextents error tag"
98 _scratch_inject_error reduce_max_iextents 0
99
100 echo "Remove \$testfile"
101 rm $testfile
102
103 echo "* Remove xattrs"
104
105 echo "Create \$testfile"
106 touch $testfile
107
108 echo "Create initial xattr extents"
109
110 naextents=0
111 last=""
112 start=1
113 nr_attrs=$((bsize / attr_len))
114
115 while (( $naextents < 4 )); do
116         end=$((start + nr_attrs - 1))
117
118         for i in $(seq $start $end); do
119                 attr="$(printf "trusted.%0247d" $i)"
120                 $SETFATTR_PROG -n $attr $testfile
121         done
122
123         start=$((end + 1))
124
125         naextents=$(_xfs_get_fsxattr naextents $testfile)
126 done
127
128 echo "Inject reduce_max_iextents error tag"
129 _scratch_inject_error reduce_max_iextents 1
130
131 echo "Remove xattr to trigger -EFBIG"
132 attr="$(printf "trusted.%0247d" 1)"
133 $SETFATTR_PROG -x "$attr" $testfile >> $seqres.full 2>&1
134 if [[ $? == 0 ]]; then
135         echo "Xattr removal succeeded; Should have failed "
136         exit 1
137 fi
138
139 echo "Disable reduce_max_iextents error tag"
140 _scratch_inject_error reduce_max_iextents 0
141
142 rm $testfile
143
144 # success, all done
145 status=0
146 exit