common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / tests / generic / 531
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. 531
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, but it
10 # applies to most other filesystems.
11 #
12 # Use every CPU possible to stress the filesystem.
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
31 # real QA test starts here
32 _supported_fs generic
33 _require_scratch
34 _require_test_program "t_open_tmpfiles"
35
36 rm -f $seqres.full
37 _scratch_mkfs >> $seqres.full 2>&1
38 _scratch_mount
39
40 # Try to load up all the CPUs, two threads per CPU.
41 nr_cpus=$(( $(getconf _NPROCESSORS_ONLN) * 2 ))
42
43 # Set ULIMIT_NOFILE to min(file-max / $nr_cpus / 2, 50000 files per LOAD_FACTOR)
44 # so that this test doesn't take forever or OOM the box
45 max_files=$((50000 * LOAD_FACTOR))
46 max_allowable_files=$(( $(cat /proc/sys/fs/file-max) / $nr_cpus / 2 ))
47 test $max_allowable_files -gt 0 && test $max_files -gt $max_allowable_files && \
48         max_files=$max_allowable_files
49 ulimit -n $max_files
50
51 # Open a lot of unlinked files
52 echo create >> $seqres.full
53 for i in $(seq 1 $nr_cpus); do
54         mkdir $SCRATCH_MNT/$i
55         $here/src/t_open_tmpfiles $SCRATCH_MNT/$i >> $seqres.full &
56 done
57 wait
58
59 # Unmount to prove that we can clean it all
60 echo umount >> $seqres.full
61 before=$(date +%s)
62 _scratch_unmount
63 after=$(date +%s)
64 echo "Unmount took $((after - before))s." >> $seqres.full
65
66 # Mount so that we can run the usual checks
67 echo silence is golden
68 _scratch_mount
69 status=0
70 exit