fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 273
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 273
6 #
7 # reservation test with heavy cp workload
8 #
9 #creator
10
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=0        # success is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -rf $tmp.*
24         _scratch_unmount
25 }
26
27 . ./common/rc
28 . ./common/filter
29
30 threads=50
31 count=2
32
33 _threads_set()
34 {
35         _cpu_num=`$here/src/feature -o`
36         threads=$(($_cpu_num * 50))
37         if [ $threads -gt 200 ]
38         then
39                 threads=200
40         fi
41 }
42
43 _file_create()
44 {
45         block_size=$1
46         _i=0
47
48         if ! mkdir $SCRATCH_MNT/origin
49         then
50                 echo "mkdir origin err"
51                 status=1
52                 exit
53         fi
54
55         cd $SCRATCH_MNT/origin
56
57         _disksize=`$DF_PROG -B 1 $SCRATCH_MNT | tail -1 | $AWK_PROG '{ print $5 }'`
58         _disksize=$(($_disksize / 3))
59         _num=$(($_disksize / $count / $threads / $block_size))
60         _count=$count
61         while [ $_i -lt $_num ]
62         do
63                 dd if=/dev/zero of=file_$_i bs=$block_size count=$_count >/dev/null 2>&1
64                 _i=$(($_i + 1))
65         done
66
67         cd $here
68 }
69
70 _porter()
71 {
72         _suffix=$1
73
74         if ! mkdir $SCRATCH_MNT/sub_$_suffix
75         then
76                 echo "mkdir sub_xxx err"
77                 status=1
78                 exit
79         fi
80
81         cp -r $SCRATCH_MNT/origin $SCRATCH_MNT/sub_$_suffix >>$seqres.full 2>&1
82         if [ $? -ne 0 ]
83         then
84                 echo "_porter $_suffix not complete"
85         fi
86         
87         sync
88 }
89
90 _do_workload()
91 {
92         _pids=""
93         _pid=1
94         block_size=$(_get_block_size $SCRATCH_MNT)
95         
96         _threads_set
97         _file_create $block_size
98
99         _threads=$threads
100
101         while [ $_pid -lt $_threads ]
102         do
103                 _porter $_pid &
104                 _pids="$_pids $!"
105                 _pid=$(($_pid + 1))
106         done
107
108         wait $_pids
109 }
110
111 # real QA test starts here
112 _supported_fs generic
113 _supported_os Linux
114 _require_scratch
115
116 echo "------------------------------"
117 echo "start the workload"
118 echo "------------------------------"
119
120 rm -f $seqres.full
121
122 _scratch_unmount 2>/dev/null
123 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
124 _scratch_mount
125
126 _do_workload
127
128 status=0
129 exit