misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 443
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 443
6 #
7 # Regression test for the XFS rmapbt based extent swap algorithm. The extent
8 # swap algorithm for rmapbt=1 filesystems unmaps/remaps individual extents to
9 # rectify the rmapbt for each extent swapped between inodes. If one of the
10 # inodes happens to straddle the extent <-> btree format boundary (which can
11 # vary depending on inode size), the unmap/remap sequence can bounce the inodes
12 # back and forth between formats many times during the swap. Since extent ->
13 # btree format conversion requires a block allocation, this can consume more
14 # blocks than expected, lead to block reservation overrun and free space
15 # accounting inconsistency.
16 #
17 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35 . ./common/punch
36
37 # remove previous $seqres.full before test
38 rm -f $seqres.full
39
40 # real QA test starts here
41
42 # Modify as appropriate.
43 _supported_fs generic
44 _require_scratch
45 _require_test_program "punch-alternating"
46 _require_xfs_io_command "falloc"
47 _require_xfs_io_command "fpunch"
48 _require_xfs_io_command "swapext"
49
50 _scratch_mkfs | _filter_mkfs >> $seqres.full 2> $tmp.mkfs
51 _scratch_mount
52
53 # get fs block size
54 . $tmp.mkfs
55
56 file1=$SCRATCH_MNT/file1
57 file2=$SCRATCH_MNT/file2
58
59 # The goal is run an extent swap where one of the associated files has the
60 # minimum number of extents to remain in btree format. First, create a couple
61 # files with large enough extent counts (200 or so should be plenty) to ensure
62 # btree format on the largest possible inode size filesystems.
63 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file1
64 $here/src/punch-alternating $file1
65 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file2
66 $here/src/punch-alternating $file2
67
68 # Now run an extent swap at every possible extent count down to 0. Depending on
69 # inode size, one of these swaps will cover the boundary case between extent and
70 # btree format.
71 for i in $(seq 1 2 399); do
72         # punch one extent from the tmpfile and swap
73         $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
74         $XFS_IO_PROG -c "swapext $file2" $file1
75
76         # punch the same extent from the old fork (now in file2) to resync the
77         # extent counts and repeat
78         $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
79 done
80
81 # sanity check that no extents are left over
82 $XFS_IO_PROG -c "fiemap" $file1 | _filter_fiemap
83 $XFS_IO_PROG -c "fiemap" $file2 | _filter_fiemap
84
85 # failure results in fs corruption and possible assert failure
86 echo Silence is golden
87
88 # success, all done
89 status=0
90 exit