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