generic/530: fix shutdown failure of generic/530 in overlay
[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 _supported_os Linux
38 _require_xfs_io_error_injection "iunlink_fallback"
39 _require_xfs_sysfs debug/log_recovery_delay
40 _require_scratch
41 _require_test_program "t_open_tmpfiles"
42
43 rm -f $seqres.full
44 _scratch_mkfs >> $seqres.full 2>&1
45 _scratch_mount
46
47 # Set ULIMIT_NOFILE to min(file-max / 2, 30000 files per LOAD_FACTOR)
48 # so that this test doesn't take forever or OOM the box
49 max_files=$((30000 * LOAD_FACTOR))
50 max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / 2 ))
51 test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
52         max_files=$max_allowable_files
53 ulimit -n $max_files
54
55 # Open a lot of unlinked files
56 echo create >> $seqres.full
57 $here/src/t_open_tmpfiles $SCRATCH_MNT >> $seqres.full
58 _scratch_shutdown -f
59
60
61 # Unmount to prove that we can clean it all
62 echo umount >> $seqres.full
63 before=$(date +%s)
64 _scratch_unmount
65 after=$(date +%s)
66 echo "Unmount took $((after - before))s." >> $seqres.full
67
68 # Force xfs to use the iunlinked fallback 50% of the time
69 injector() {
70         # Slow down log recovery by 5s to give us enough time to set up
71         # error injection.
72         echo 5 > "$delay_knob"
73
74         # Try for 10s to set our knob.
75         knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" iunlink_fallback)"
76         nr=0
77         while [ ! -e "$knob" ] && [ "$nr" -lt 20 ]; do
78                 sleep 0.5
79                 nr=$((nr+1))
80         done
81         if [ -e "$knob" ]; then
82                 echo 2 > "$knob"
83         else
84                 echo "unable to set iunlink_fallback?"
85         fi
86 }
87
88 # Mount so that we can run the usual checks
89 echo silence is golden
90 injector &
91 _scratch_mount
92 status=0
93 exit