generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 533
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 533
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # adding/removing directory entries.
9 . ./common/preamble
10 _begin_fstest auto quick dir hardlink symlink
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/inject
15 . ./common/populate
16
17 # real QA test starts here
18
19 _supported_fs xfs
20 _require_scratch
21 _require_xfs_debug
22 _require_test_program "punch-alternating"
23 _require_xfs_io_error_injection "reduce_max_iextents"
24 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
25
26 _scratch_mkfs_sized $((1024 * 1024 * 1024)) | _filter_mkfs >> $seqres.full 2> $tmp.mkfs
27 . $tmp.mkfs
28
29 # Filesystems with directory block size greater than one FSB will not be tested,
30 # since "7 (i.e. XFS_DA_NODE_MAXDEPTH + 1 data block + 1 free block) * 2 (fsb
31 # count) = 14" is greater than the pseudo max extent count limit of 10.
32 # Extending the pseudo max limit won't help either.  Consider the case where 1
33 # FSB is 1k in size and 1 dir block is 64k in size (i.e. fsb count = 64). In
34 # this case, the pseudo max limit has to be greater than 7 * 64 = 448 extents.
35 if (( $dirbsize > $dbsize )); then
36         _notrun "Directory block size ($dirbsize) is larger than FSB size ($dbsize)"
37 fi
38
39 echo "Format and mount fs"
40 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
41 _scratch_mount >> $seqres.full
42
43 # Disable realtime inherit flag (if any) on root directory so that space on data
44 # device gets fragmented rather than realtime device.
45 _xfs_force_bdev data $SCRATCH_MNT
46
47 echo "Consume free space"
48 fillerdir=$SCRATCH_MNT/fillerdir
49 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
50 nr_free_blks=$((nr_free_blks * 90 / 100))
51
52 _fill_fs $((dbsize * nr_free_blks)) $fillerdir $dbsize 0 >> $seqres.full 2>&1
53
54 echo "Create fragmented filesystem"
55 for dentry in $(ls -1 $fillerdir/); do
56         $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
57 done
58
59 echo "Inject reduce_max_iextents error tag"
60 _scratch_inject_error reduce_max_iextents 1
61
62 echo "Inject bmap_alloc_minlen_extent error tag"
63 _scratch_inject_error bmap_alloc_minlen_extent 1
64
65 dent_len=255
66
67 echo "* Create directory entries"
68
69 testdir=$SCRATCH_MNT/testdir
70 mkdir $testdir
71
72 nr_dents=$((dbsize * 20 / dent_len))
73 for i in $(seq 1 $nr_dents); do
74         dentry="$(printf "%0255d" $i)"
75         touch ${testdir}/$dentry >> $seqres.full 2>&1 || break
76 done
77
78 echo "Verify directory's extent count"
79 nextents=$(_xfs_get_fsxattr nextents $testdir)
80 if (( $nextents > 10 )); then
81         echo "Extent count overflow check failed: nextents = $nextents"
82         exit 1
83 fi
84
85 rm -rf $testdir
86
87 echo "* Rename: Populate destination directory"
88
89 dstdir=$SCRATCH_MNT/dstdir
90 mkdir $dstdir
91
92 nr_dents=$((dirbsize * 20 / dent_len))
93
94 echo "Populate \$dstdir by moving new directory entries"
95 for i in $(seq 1 $nr_dents); do
96         dentry="$(printf "%0255d" $i)"
97         dentry=${SCRATCH_MNT}/${dentry}
98         touch $dentry || break
99         mv $dentry $dstdir >> $seqres.full 2>&1 || break
100 done
101
102 rm $dentry
103
104 echo "Verify \$dstdir's extent count"
105
106 nextents=$(_xfs_get_fsxattr nextents $dstdir)
107 if (( $nextents > 10 )); then
108         echo "Extent count overflow check failed: nextents = $nextents"
109         exit 1
110 fi
111
112 rm -rf $dstdir
113
114 echo "* Create multiple hard links to a single file"
115
116 testdir=$SCRATCH_MNT/testdir
117 mkdir $testdir
118
119 testfile=$SCRATCH_MNT/testfile
120 touch $testfile
121
122 nr_dents=$((dirbsize * 20 / dent_len))
123
124 echo "Create multiple hardlinks"
125 for i in $(seq 1 $nr_dents); do
126         dentry="$(printf "%0255d" $i)"
127         ln $testfile ${testdir}/${dentry} >> $seqres.full 2>&1 || break
128 done
129
130 rm $testfile
131
132 echo "Verify directory's extent count"
133 nextents=$(_xfs_get_fsxattr nextents $testdir)
134 if (( $nextents > 10 )); then
135         echo "Extent count overflow check failed: nextents = $nextents"
136         exit 1
137 fi
138
139 rm -rf $testdir
140
141 echo "* Create multiple symbolic links to a single file"
142
143 testdir=$SCRATCH_MNT/testdir
144 mkdir $testdir
145
146 testfile=$SCRATCH_MNT/testfile
147 touch $testfile
148
149 nr_dents=$((dirbsize * 20 / dent_len))
150
151 echo "Create multiple symbolic links"
152 for i in $(seq 1 $nr_dents); do
153         dentry="$(printf "%0255d" $i)"
154         ln -s $testfile ${testdir}/${dentry} >> $seqres.full 2>&1 || break;
155 done
156
157 rm $testfile
158
159 echo "Verify directory's extent count"
160 nextents=$(_xfs_get_fsxattr nextents $testdir)
161 if (( $nextents > 10 )); then
162         echo "Extent count overflow check failed: nextents = $nextents"
163         exit 1
164 fi
165
166 rm -rf $testdir
167
168 # success, all done
169 status=0
170 exit