2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc. All Rights Reserved.
7 # Test that XFS reserves reasonable indirect blocks for delalloc and
8 # speculative allocation, and doesn't cause any fdblocks corruption.
10 # This was inspired by an XFS but that too large 'indlen' was returned by
11 # xfs_bmap_worst_indlen() which can't fit in a 17 bits value (STARTBLOCKVALBITS
12 # is defined as 17), then leaked 1 << 17 blocks in sb_fdblocks.
14 # This was only seen on XFS with rmapbt feature enabled, but nothing prevents
15 # the test from being a generic test.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 testfile=$SCRATCH_MNT/1G_file.$seq
25 file_size=$((1024 * 1024 * 1024))
26 trap "_cleanup; exit \$status" 0 1 2 3 15
28 saved_dirty_background_ratio=0
33 saved_dirty_background_ratio=`cat /proc/sys/vm/dirty_background_ratio`
34 saved_dirty_ratio=`cat /proc/sys/vm/dirty_ratio`
39 echo 100 > /proc/sys/vm/dirty_background_ratio
40 echo 100 > /proc/sys/vm/dirty_ratio
45 if [ $saved_dirty_background_ratio -ne 0 ]; then
46 echo $saved_dirty_background_ratio > /proc/sys/vm/dirty_background_ratio
48 if [ $saved_dirty_ratio -ne 0 ]; then
49 echo $saved_dirty_ratio > /proc/sys/vm/dirty_ratio
60 # get standard environment, filters and checks
64 # remove previous $seqres.full before test
67 # real QA test starts here
70 # test with scratch device, because test is known to corrupt fs, we don't want
71 # the corruption affect subsequent tests
74 _scratch_mkfs >>$seqres.full 2>&1
77 # need at least 1G free space
78 _require_fs_space $SCRATCH_MNT $((1024 * 1024))
80 # To reproduce the bug, we need to keep enough dirty data in memory (1G at
81 # least), so that a large enough delay allocated extent is kept in memory, then
82 # speculative preallocation could allocate large number of blocks based on the
83 # existing extent size.
84 # So we set dirty_background_ratio and dirty_ratio to 100% uncontitionally,
85 # even if the total memory is less than 1G, there's no harm to run a test on a
90 # buffer write a 1G file, which is enough to trigger the bug,
91 # _check_filesystems will complain about fs corruption after test
92 $XFS_IO_PROG -fc "pwrite -b 1m 0 $file_size" $testfile >/dev/null 2>&1
94 echo "Silence is golden"