generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
18 _begin_fstest auto quick ioctl fsr punch
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/punch
23
24 # real QA test starts here
25
26 # Modify as appropriate.
27 _supported_fs generic
28 _require_scratch
29 _require_test_program "punch-alternating"
30 _require_xfs_io_command "falloc"
31 _require_xfs_io_command "fpunch"
32 _require_xfs_io_command "swapext"
33
34 _scratch_mkfs | _filter_mkfs >> $seqres.full 2> $tmp.mkfs
35 _scratch_mount
36
37 # get fs block size
38 . $tmp.mkfs
39
40 file1=$SCRATCH_MNT/file1
41 file2=$SCRATCH_MNT/file2
42
43 # The goal is run an extent swap where one of the associated files has the
44 # minimum number of extents to remain in btree format. First, create a couple
45 # files with large enough extent counts (200 or so should be plenty) to ensure
46 # btree format on the largest possible inode size filesystems.
47 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file1
48 $here/src/punch-alternating $file1
49 $XFS_IO_PROG -fc "falloc 0 $((400 * dbsize))" $file2
50 $here/src/punch-alternating $file2
51
52 # Now run an extent swap at every possible extent count down to 0. Depending on
53 # inode size, one of these swaps will cover the boundary case between extent and
54 # btree format.
55 for i in $(seq 1 2 399); do
56         # punch one extent from the tmpfile and swap
57         $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
58         $XFS_IO_PROG -c "swapext $file2" $file1
59
60         # punch the same extent from the old fork (now in file2) to resync the
61         # extent counts and repeat
62         $XFS_IO_PROG -c "fpunch $((i * dbsize)) $dbsize" $file2
63 done
64
65 # sanity check that no extents are left over
66 $XFS_IO_PROG -c "fiemap" $file1 | _filter_fiemap
67 $XFS_IO_PROG -c "fiemap" $file2 | _filter_fiemap
68
69 # failure results in fs corruption and possible assert failure
70 echo Silence is golden
71
72 # success, all done
73 status=0
74 exit