generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
10 _begin_fstest auto quick attr
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/attr
15 . ./common/inject
16 . ./common/populate
17
18 # real QA test starts here
19
20 _supported_fs xfs
21 _require_scratch
22 _require_attrs
23 _require_xfs_debug
24 _require_test_program "punch-alternating"
25 _require_xfs_io_error_injection "reduce_max_iextents"
26 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
27
28 echo "Format and mount fs"
29 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
30 _scratch_mount >> $seqres.full
31
32 # Disable realtime inherit flag (if any) on root directory so that space on data
33 # device gets fragmented rather than realtime device.
34 _xfs_force_bdev data $SCRATCH_MNT
35
36 bsize=$(_get_block_size $SCRATCH_MNT)
37
38 attr_len=255
39
40 testfile=$SCRATCH_MNT/testfile
41
42 echo "Consume free space"
43 fillerdir=$SCRATCH_MNT/fillerdir
44 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
45 nr_free_blks=$((nr_free_blks * 90 / 100))
46
47 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
48
49 echo "Create fragmented filesystem"
50 for dentry in $(ls -1 $fillerdir/); do
51         $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
52 done
53
54 echo "Inject bmap_alloc_minlen_extent error tag"
55 _scratch_inject_error bmap_alloc_minlen_extent 1
56
57 echo "* Set xattrs"
58
59 echo "Create \$testfile"
60 touch $testfile
61
62 echo "Inject reduce_max_iextents error tag"
63 _scratch_inject_error reduce_max_iextents 1
64
65 echo "Create xattrs"
66 nr_attrs=$((bsize * 20 / attr_len))
67 for i in $(seq 1 $nr_attrs); do
68         attr="$(printf "trusted.%0247d" $i)"
69         $SETFATTR_PROG -n "$attr" $testfile >> $seqres.full 2>&1
70         [[ $? != 0 ]] && break
71 done
72
73 echo "Verify \$testfile's naextent count"
74
75 naextents=$(_xfs_get_fsxattr naextents $testfile)
76 if (( $naextents > 10 )); then
77         echo "Extent count overflow check failed: naextents = $naextents"
78         exit 1
79 fi
80
81 echo "Disable reduce_max_iextents error tag"
82 _scratch_inject_error reduce_max_iextents 0
83
84 echo "Remove \$testfile"
85 rm $testfile
86
87 echo "* Remove xattrs"
88
89 echo "Create \$testfile"
90 touch $testfile
91
92 echo "Create initial xattr extents"
93
94 naextents=0
95 last=""
96 start=1
97 nr_attrs=$((bsize / attr_len))
98
99 while (( $naextents < 4 )); do
100         end=$((start + nr_attrs - 1))
101
102         for i in $(seq $start $end); do
103                 attr="$(printf "trusted.%0247d" $i)"
104                 $SETFATTR_PROG -n $attr $testfile
105         done
106
107         start=$((end + 1))
108
109         naextents=$(_xfs_get_fsxattr naextents $testfile)
110 done
111
112 echo "Inject reduce_max_iextents error tag"
113 _scratch_inject_error reduce_max_iextents 1
114
115 echo "Remove xattr to trigger -EFBIG"
116 attr="$(printf "trusted.%0247d" 1)"
117 $SETFATTR_PROG -x "$attr" $testfile >> $seqres.full 2>&1
118 if [[ $? == 0 ]]; then
119         echo "Xattr removal succeeded; Should have failed "
120         exit 1
121 fi
122
123 echo "Disable reduce_max_iextents error tag"
124 _scratch_inject_error reduce_max_iextents 0
125
126 rm $testfile
127
128 # success, all done
129 status=0
130 exit