summaryrefslogtreecommitdiff
path: root/tests/xfs/501
blob: a9acf0af2f4d8a4dd6de075fd516aaa6a61cfdcf (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2019 Oracle, Inc.  All Rights Reserved.
#
# FS QA Test No. 501
#
# Stress test creating a lot of unlinked O_TMPFILE files and recovering them
# after a crash, checking that we don't blow up the filesystem.  This is sort
# of a performance test for the xfs unlinked inode backref patchset.
#
# Here we force the use of the slow iunlink bucket walk code in a single
# threaded situation.
#
. ./common/preamble
_begin_fstest auto quick unlink
testfile=$TEST_DIR/$seq.txt

delay_knob="/sys/fs/xfs/debug/log_recovery_delay"

# Override the default cleanup function.
_cleanup()
{
	cd /
	test -e "$delay_knob" && echo 0 > "$delay_knob"
	rm -f $tmp.*
}

# Import common functions.
. ./common/inject

# real QA test starts here
_supported_fs xfs
_require_xfs_io_error_injection "iunlink_fallback"
_require_xfs_sysfs debug/log_recovery_delay
_require_scratch
_require_test_program "t_open_tmpfiles"

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

# Set ULIMIT_NOFILE to min(file-max / 2, 30000 files per LOAD_FACTOR)
# so that this test doesn't take forever or OOM the box
max_files=$((30000 * LOAD_FACTOR))
max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / 2 ))
test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
	max_files=$max_allowable_files
ulimit -n $max_files

# Open a lot of unlinked files
echo create >> $seqres.full
$here/src/t_open_tmpfiles $SCRATCH_MNT $(_scratch_shutdown_handle) >> $seqres.full

# Unmount to prove that we can clean it all
echo umount >> $seqres.full
before=$(date +%s)
_scratch_unmount
after=$(date +%s)
echo "Unmount took $((after - before))s." >> $seqres.full

# Force xfs to use the iunlinked fallback 50% of the time
injector() {
	# Slow down log recovery by 5s to give us enough time to set up
	# error injection.
	echo 5 > "$delay_knob"

	# Try for 10s to set our knob.
	knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" iunlink_fallback)"
	nr=0
	while [ ! -e "$knob" ] && [ "$nr" -lt 20 ]; do
		sleep 0.5
		nr=$((nr+1))
	done
	if [ -e "$knob" ]; then
		echo 2 > "$knob"
	else
		echo "unable to set iunlink_fallback?"
	fi
}

# Mount so that we can run the usual checks
echo silence is golden
injector &
_scratch_mount
status=0
exit