xfs/419: remove irrelevant swapfile test
[xfstests-dev.git] / tests / xfs / 529
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 529
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # adding a single extent while there's no possibility of splitting an existing
9 # mapping.
10
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/quota
30 . ./common/inject
31 . ./common/populate
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37
38 _supported_fs xfs
39 _require_scratch
40 _require_xfs_quota
41 _require_xfs_debug
42 _require_test_program "punch-alternating"
43 _require_xfs_io_command "falloc"
44 _require_xfs_io_error_injection "reduce_max_iextents"
45 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
46
47 echo "Format and mount fs"
48 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full
49 _scratch_mount -o uquota >> $seqres.full
50
51 bsize=$(_get_file_block_size $SCRATCH_MNT)
52
53 echo "* Delalloc to written extent conversion"
54
55 testfile=$SCRATCH_MNT/testfile
56
57 touch $testfile
58
59 echo "Inject reduce_max_iextents error tag"
60 _scratch_inject_error reduce_max_iextents 1
61
62 nr_blks=$((15 * 2))
63
64 echo "Create fragmented file"
65 for i in $(seq 0 2 $((nr_blks - 1))); do
66         $XFS_IO_PROG -f -s -c "pwrite $((i * bsize)) $bsize" $testfile \
67                >> $seqres.full 2>&1
68         [[ $? != 0 ]] && break
69 done
70
71 echo "Verify \$testfile's extent count"
72
73 nextents=$(_xfs_get_fsxattr nextents $testfile)
74 if (( $nextents > 10 )); then
75         echo "Extent count overflow check failed: nextents = $nextents"
76         exit 1
77 fi
78
79 echo "Disable reduce_max_iextents error tag"
80 _scratch_inject_error reduce_max_iextents 0
81
82 rm $testfile
83
84 echo "* Fallocate unwritten extents"
85
86 touch $testfile
87
88 echo "Inject reduce_max_iextents error tag"
89 _scratch_inject_error reduce_max_iextents 1
90
91 echo "Fallocate fragmented file"
92 for i in $(seq 0 2 $((nr_blks - 1))); do
93         $XFS_IO_PROG -f -c "falloc $((i * bsize)) $bsize" $testfile \
94                >> $seqres.full 2>&1
95         [[ $? != 0 ]] && break
96 done
97
98 echo "Verify \$testfile's extent count"
99
100 nextents=$(_xfs_get_fsxattr nextents $testfile)
101 if (( $nextents > 10 )); then
102         echo "Extent count overflow check failed: nextents = $nextents"
103         exit 1
104 fi
105
106 echo "Disable reduce_max_iextents error tag"
107 _scratch_inject_error reduce_max_iextents 0
108
109 rm $testfile
110
111 echo "* Directio write"
112
113 touch $testfile
114
115 echo "Inject reduce_max_iextents error tag"
116 _scratch_inject_error reduce_max_iextents 1
117
118 echo "Create fragmented file via directio writes"
119 for i in $(seq 0 2 $((nr_blks - 1))); do
120         $XFS_IO_PROG -d -s -f -c "pwrite $((i * bsize)) $bsize" $testfile \
121                >> $seqres.full 2>&1
122         [[ $? != 0 ]] && break
123 done
124
125 echo "Verify \$testfile's extent count"
126
127 nextents=$(_xfs_get_fsxattr nextents $testfile)
128 if (( $nextents > 10 )); then
129         echo "Extent count overflow check failed: nextents = $nextents"
130         exit 1
131 fi
132
133 echo "Disable reduce_max_iextents error tag"
134 _scratch_inject_error reduce_max_iextents 0
135
136 rm $testfile
137
138 # Check if XFS gracefully returns with an error code when we try to increase
139 # extent count of user quota inode beyond the pseudo max extent count limit.
140 echo "* Extend quota inodes"
141
142 echo "Consume free space"
143 fillerdir=$SCRATCH_MNT/fillerdir
144 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
145 nr_free_blks=$((nr_free_blks * 90 / 100))
146
147 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
148
149 echo "Create fragmented filesystem"
150 for dentry in $(ls -1 $fillerdir/); do
151         $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
152 done
153
154 echo "Inject reduce_max_iextents error tag"
155 _scratch_inject_error reduce_max_iextents 1
156
157 echo "Inject bmap_alloc_minlen_extent error tag"
158 _scratch_inject_error bmap_alloc_minlen_extent 1
159
160 nr_blks=20
161
162 # This is a rough calculation; It doesn't take block headers into
163 # consideration.
164 # gdb -batch vmlinux -ex 'print sizeof(struct xfs_dqblk)'
165 # $1 = 136
166 nr_quotas_per_block=$((bsize / 136))
167 nr_quotas=$((nr_quotas_per_block * nr_blks))
168
169 echo "Extend uquota file"
170 for i in $(seq 0 $nr_quotas_per_block $nr_quotas); do
171         chown $i $fillerdir >> $seqres.full 2>&1
172         [[ $? != 0 ]] && break
173 done
174
175 _scratch_unmount >> $seqres.full
176
177 echo "Verify uquota inode's extent count"
178 uquotino=$(_scratch_xfs_get_metadata_field 'uquotino' 'sb 0')
179
180 nextents=$(_scratch_get_iext_count $uquotino data || \
181                    _fail "Unable to obtain inode fork's extent count")
182 if (( $nextents > 10 )); then
183         echo "Extent count overflow check failed: nextents = $nextents"
184         exit 1
185 fi
186
187 # success, all done
188 status=0
189 exit