fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 537
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 537
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # swapping forks between files
9 . ./common/preamble
10 _begin_fstest auto quick
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/inject
15
16 # real QA test starts here
17
18 _supported_fs xfs
19 _require_scratch
20 _require_xfs_debug
21 _require_xfs_scratch_rmapbt
22 _require_xfs_io_command "fcollapse"
23 _require_xfs_io_command "swapext"
24 _require_xfs_io_error_injection "reduce_max_iextents"
25
26 echo "* Swap extent forks"
27
28 echo "Format and mount fs"
29 _scratch_mkfs >> $seqres.full
30 _scratch_mount >> $seqres.full
31
32 bsize=$(_get_block_size $SCRATCH_MNT)
33
34 srcfile=${SCRATCH_MNT}/srcfile
35 donorfile=${SCRATCH_MNT}/donorfile
36
37 echo "Create \$donorfile having an extent of length 67 blocks"
38 $XFS_IO_PROG -f -s -c "pwrite -b $((17 * bsize)) 0 $((17 * bsize))" $donorfile \
39        >> $seqres.full
40
41 # After the for loop the donor file will have the following extent layout
42 # | 0-4 | 5 | 6 | 7 | 8 | 9 | 10 |
43 echo "Fragment \$donorfile"
44 for i in $(seq 5 10); do
45         start_offset=$((i * bsize))
46         $XFS_IO_PROG -f -c "fcollapse $start_offset $bsize" $donorfile >> $seqres.full
47 done
48
49 echo "Create \$srcfile having an extent of length 18 blocks"
50 $XFS_IO_PROG -f -s -c "pwrite -b $((18 * bsize)) 0 $((18 * bsize))" $srcfile \
51        >> $seqres.full
52
53 echo "Fragment \$srcfile"
54 # After the for loop the src file will have the following extent layout
55 # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7-10 |
56 for i in $(seq 1 7); do
57         start_offset=$((i * bsize))
58         $XFS_IO_PROG -f -c "fcollapse $start_offset $bsize" $srcfile >> $seqres.full
59 done
60
61 echo "Collect \$donorfile's extent count"
62 donor_nr_exts=$(_xfs_get_fsxattr nextents $donorfile)
63
64 echo "Collect \$srcfile's extent count"
65 src_nr_exts=$(_xfs_get_fsxattr nextents $srcfile)
66
67 echo "Inject reduce_max_iextents error tag"
68 _scratch_inject_error reduce_max_iextents 1
69
70 echo "Swap \$srcfile's and \$donorfile's extent forks"
71 $XFS_IO_PROG -f -c "swapext $donorfile" $srcfile >> $seqres.full 2>&1
72
73 echo "Check for \$donorfile's extent count overflow"
74 nextents=$(_xfs_get_fsxattr nextents $donorfile)
75
76 if (( $nextents == $src_nr_exts )); then
77         echo "\$donorfile: Extent count overflow check failed"
78 fi
79
80 echo "Check for \$srcfile's extent count overflow"
81 nextents=$(_xfs_get_fsxattr nextents $srcfile)
82
83 if (( $nextents == $donor_nr_exts )); then
84         echo "\$srcfile: Extent count overflow check failed"
85 fi
86
87 # success, all done
88 status=0
89 exit