fsx/fsstress: round blocksize properly
[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 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 testfile=$TEST_DIR/$seq.txt
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 delay_knob="/sys/fs/xfs/debug/log_recovery_delay"
23
24 _cleanup()
25 {
26         cd /
27         test -e "$delay_knob" && echo 0 > "$delay_knob"
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/inject
34
35 # real QA test starts here
36 _supported_fs xfs
37 _require_xfs_io_error_injection "iunlink_fallback"
38 _require_xfs_sysfs debug/log_recovery_delay
39 _require_scratch
40 _require_test_program "t_open_tmpfiles"
41
42 rm -f $seqres.full
43 _scratch_mkfs >> $seqres.full 2>&1
44 _scratch_mount
45
46 # Set ULIMIT_NOFILE to min(file-max / 2, 30000 files per LOAD_FACTOR)
47 # so that this test doesn't take forever or OOM the box
48 max_files=$((30000 * LOAD_FACTOR))
49 max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / 2 ))
50 test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
51         max_files=$max_allowable_files
52 ulimit -n $max_files
53
54 # Open a lot of unlinked files
55 echo create >> $seqres.full
56 $here/src/t_open_tmpfiles $SCRATCH_MNT $(_scratch_shutdown_handle) >> $seqres.full
57
58 # Unmount to prove that we can clean it all
59 echo umount >> $seqres.full
60 before=$(date +%s)
61 _scratch_unmount
62 after=$(date +%s)
63 echo "Unmount took $((after - before))s." >> $seqres.full
64
65 # Force xfs to use the iunlinked fallback 50% of the time
66 injector() {
67         # Slow down log recovery by 5s to give us enough time to set up
68         # error injection.
69         echo 5 > "$delay_knob"
70
71         # Try for 10s to set our knob.
72         knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" iunlink_fallback)"
73         nr=0
74         while [ ! -e "$knob" ] && [ "$nr" -lt 20 ]; do
75                 sleep 0.5
76                 nr=$((nr+1))
77         done
78         if [ -e "$knob" ]; then
79                 echo 2 > "$knob"
80         else
81                 echo "unable to set iunlink_fallback?"
82         fi
83 }
84
85 # Mount so that we can run the usual checks
86 echo silence is golden
87 injector &
88 _scratch_mount
89 status=0
90 exit