2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc. All Rights Reserved.
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.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
37 # remove previous $seqres.full before test
40 # real QA test starts here
42 # Modify as appropriate.
46 _require_test_program "punch-alternating"
47 _require_xfs_io_command "falloc"
48 _require_xfs_io_command "fpunch"
49 _require_xfs_io_command "swapext"
51 _scratch_mkfs | _filter_mkfs >> $seqres.full 2> $tmp.mkfs
57 file1=$SCRATCH_MNT/file1
58 file2=$SCRATCH_MNT/file2
60 # The goal is run an extent swap where one of the associated files has the
61 # minimum number of extents to remain in btree format. First, create a couple
62 # files with large enough extent counts (200 or so should be plenty) to ensure
63 # btree format on the largest possible inode size filesystems.
64 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file1
65 $here/src/punch-alternating $file1
66 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file2
67 $here/src/punch-alternating $file2
69 # Now run an extent swap at every possible extent count down to 0. Depending on
70 # inode size, one of these swaps will cover the boundary case between extent and
72 for i in $(seq 1 2 399); do
73 # punch one extent from the tmpfile and swap
74 $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
75 $XFS_IO_PROG -c "swapext $file2" $file1
77 # punch the same extent from the old fork (now in file2) to resync the
78 # extent counts and repeat
79 $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
82 # sanity check that no extents are left over
83 $XFS_IO_PROG -c "fiemap" $file1 | _filter_fiemap
84 $XFS_IO_PROG -c "fiemap" $file2 | _filter_fiemap
86 # failure results in fs corruption and possible assert failure
87 echo Silence is golden