xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 501
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 501
6 #
7 # Stress test creating a lot of unlinked O_TMPFILE files and recovering them
8 # after a crash, checking that we don't blow up the filesystem.  This is sort
9 # of a performance test for the xfs unlinked inode backref patchset.
10 #
11 # Here we force the use of the slow iunlink bucket walk code in a single
12 # threaded situation.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick unlink
16 testfile=$TEST_DIR/$seq.txt
17
18 delay_knob="/sys/fs/xfs/debug/log_recovery_delay"
19
20 # Override the default cleanup function.
21 _cleanup()
22 {
23         cd /
24         test -e "$delay_knob" && echo 0 > "$delay_knob"
25         rm -f $tmp.*
26 }
27
28 # Import common functions.
29 . ./common/inject
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_xfs_io_error_injection "iunlink_fallback"
34 _require_xfs_sysfs debug/log_recovery_delay
35 _require_scratch
36 _require_test_program "t_open_tmpfiles"
37
38 _scratch_mkfs >> $seqres.full 2>&1
39 _scratch_mount
40
41 # Set ULIMIT_NOFILE to min(file-max / 2, 30000 files per LOAD_FACTOR)
42 # so that this test doesn't take forever or OOM the box
43 max_files=$((30000 * LOAD_FACTOR))
44 max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / 2 ))
45 test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
46         max_files=$max_allowable_files
47 ulimit -n $max_files
48
49 # Open a lot of unlinked files
50 echo create >> $seqres.full
51 $here/src/t_open_tmpfiles $SCRATCH_MNT $(_scratch_shutdown_handle) >> $seqres.full
52
53 # Unmount to prove that we can clean it all
54 echo umount >> $seqres.full
55 before=$(date +%s)
56 _scratch_unmount
57 after=$(date +%s)
58 echo "Unmount took $((after - before))s." >> $seqres.full
59
60 # Force xfs to use the iunlinked fallback 50% of the time
61 injector() {
62         # Slow down log recovery by 5s to give us enough time to set up
63         # error injection.
64         echo 5 > "$delay_knob"
65
66         # Try for 10s to set our knob.
67         knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" iunlink_fallback)"
68         nr=0
69         while [ ! -e "$knob" ] && [ "$nr" -lt 20 ]; do
70                 sleep 0.5
71                 nr=$((nr+1))
72         done
73         if [ -e "$knob" ]; then
74                 echo 2 > "$knob"
75         else
76                 echo "unable to set iunlink_fallback?"
77         fi
78 }
79
80 # Mount so that we can run the usual checks
81 echo silence is golden
82 injector &
83 _scratch_mount
84 status=0
85 exit