common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / tests / generic / 320
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
4 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. generic/320
7 #
8 # heavy rm workload
9 #
10 # Regression test for commit:
11 # 9a3a5da xfs: check for stale inode before acquiring iflock on push
12 #
13 # Based on generic/273
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -rf $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35 _supported_fs generic
36 _require_scratch
37
38 threads=100
39 count=2
40 fs_size=$((2 * 1024 * 1024 * 1024))
41 ORIGIN=$SCRATCH_MNT/origin
42
43 threads_set()
44 {
45         threads=$((LOAD_FACTOR * 100))
46         if [ $threads -gt 200 ]
47         then
48                 threads=200
49         fi
50 }
51
52 file_create()
53 {
54         i=0
55         mkdir $ORIGIN
56
57         disksize=$(($fs_size / 3))
58         num=$(($disksize / $count / $threads / 4096))
59         while [ $i -lt $num ]; do
60                 $XFS_IO_PROG -f -c "pwrite 0 $((4096*count))" \
61                         $ORIGIN/file_$i >>$seqres.full 2>&1
62                 i=$(($i + 1))
63         done
64 }
65
66 worker()
67 {
68         suffix=$1
69
70         mkdir $SCRATCH_MNT/sub_$suffix
71
72         cp -r $ORIGIN/* $SCRATCH_MNT/sub_$suffix >>$seqres.full 2>&1
73         rm -rf $SCRATCH_MNT/sub_$suffix
74 }
75
76 do_workload()
77 {
78         pids=""
79         loop=1
80
81         threads_set
82         file_create
83
84         while [ $loop -lt $threads ]; do
85                 worker $loop &
86                 pids="$pids $!"
87                 loop=$(($loop + 1))
88         done
89
90         wait $pids
91 }
92
93 echo "Silence is golden"
94
95 rm -f $seqres.full
96
97 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
98 _scratch_mount >>$seqres.full 2>&1
99
100 do_workload
101
102 status=0
103 exit