xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 502
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. 502
6 #
7 # Stress test creating a lot of unlinked O_TMPFILE files and closing them
8 # all at once, 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, using every
12 # CPU possible.
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 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/inject
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_xfs_io_error_injection "iunlink_fallback"
35 _require_scratch
36 _require_test_program "t_open_tmpfiles"
37
38 rm -f $seqres.full
39 _scratch_mkfs >> $seqres.full 2>&1
40 _scratch_mount
41
42 # Load up all the CPUs, two threads per CPU.
43 nr_cpus=$(( $(getconf _NPROCESSORS_ONLN) * 2 ))
44
45 # Set ULIMIT_NOFILE to min(file-max / $nr_cpus / 2, 30000 files per cpu per LOAD_FACTOR)
46 # so that this test doesn't take forever or OOM the box
47 max_files=$((30000 * LOAD_FACTOR))
48 max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / $nr_cpus / 2 ))
49 test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
50         max_files=$max_allowable_files
51 ulimit -n $max_files
52
53 # Force xfs to use the iunlinked fallback 50% of the time
54 _scratch_inject_error "iunlink_fallback" "2"
55
56 # Open a lot of unlinked files
57 echo create >> $seqres.full
58 for i in $(seq 1 $nr_cpus); do
59         mkdir $SCRATCH_MNT/$i
60         $here/src/t_open_tmpfiles $SCRATCH_MNT/$i >> $seqres.full &
61 done
62 wait
63
64 # Unmount to prove that we can clean it all
65 echo umount >> $seqres.full
66 before=$(date +%s)
67 _scratch_unmount
68 after=$(date +%s)
69 echo "Unmount took $((after - before))s." >> $seqres.full
70
71 # Mount so that we can run the usual checks
72 echo silence is golden
73 _scratch_mount
74 status=0
75 exit