summaryrefslogtreecommitdiff
path: root/tests/generic/460
blob: 68720d3a9f639e8bcf6db98cf2b64882fdd179f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
#
# FS QA Test 460
#
# Test that XFS reserves reasonable indirect blocks for delalloc and
# speculative allocation, and doesn't cause any fdblocks corruption.
#
# This was inspired by an XFS but that too large 'indlen' was returned by
# xfs_bmap_worst_indlen() which can't fit in a 17 bits value (STARTBLOCKVALBITS
# is defined as 17), then leaked 1 << 17 blocks in sb_fdblocks.
#
# This was only seen on XFS with rmapbt feature enabled, but nothing prevents
# the test from being a generic test.
#
. ./common/preamble
_begin_fstest auto quick rw

testfile=$SCRATCH_MNT/1G_file.$seq
file_size=$((1024 * 1024 * 1024))

saved_dirty_background_ratio=0
saved_dirty_ratio=0

save_dirty_ratio()
{
	saved_dirty_background_ratio=`cat /proc/sys/vm/dirty_background_ratio`
	saved_dirty_ratio=`cat /proc/sys/vm/dirty_ratio`
}

set_dirty_ratio()
{
	echo 100 > /proc/sys/vm/dirty_background_ratio
	echo 100 > /proc/sys/vm/dirty_ratio
}

restore_dirty_ratio()
{
	if [ $saved_dirty_background_ratio -ne 0 ]; then
		echo $saved_dirty_background_ratio > /proc/sys/vm/dirty_background_ratio
	fi
	if [ $saved_dirty_ratio -ne 0 ]; then
		echo $saved_dirty_ratio > /proc/sys/vm/dirty_ratio
	fi
}

# Override the default cleanup function.
_cleanup()
{
	cd /
	restore_dirty_ratio
	rm -f $tmp.*
}

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
# test with scratch device, because test is known to corrupt fs, we don't want
# the corruption affect subsequent tests
_require_scratch

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

# need at least 1G free space
_require_fs_space $SCRATCH_MNT $((1024 * 1024))

# To reproduce the bug, we need to keep enough dirty data in memory (1G at
# least), so that a large enough delay allocated extent is kept in memory, then
# speculative preallocation could allocate large number of blocks based on the
# existing extent size.
# So we set dirty_background_ratio and dirty_ratio to 100% uncontitionally,
# even if the total memory is less than 1G, there's no harm to run a test on a
# such host.
save_dirty_ratio
set_dirty_ratio

# buffer write a 1G file, which is enough to trigger the bug,
# _check_filesystems will complain about fs corruption after test
$XFS_IO_PROG -fc "pwrite -b 1m 0 $file_size" $testfile >/dev/null 2>&1

echo "Silence is golden"

# success, all done
status=0
exit