9b79a710642251af208ed44302455efa64c47e59
[xfstests-dev.git] / tests / generic / 273
1 #! /bin/bash
2 # FS QA Test No. 273
3 #
4 # reservation test with heavy cp workload
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 #creator
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=0        # success is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -rf $tmp.*
41         _scratch_unmount
42 }
43
44 . ./common/rc
45 . ./common/filter
46
47 threads=50
48 count=2
49
50 _threads_set()
51 {
52         _cpu_num=`cat /proc/cpuinfo | grep "processor" | wc -l`
53         threads=$(($_cpu_num * 50))
54         if [ $threads -gt 200 ]
55         then
56                 threads=200
57         fi
58 }
59
60 _file_create()
61 {
62         _i=0
63
64         if ! mkdir $SCRATCH_MNT/origin
65         then
66                 echo "mkdir origin err"
67                 status=1
68                 exit
69         fi
70
71         cd $SCRATCH_MNT/origin
72
73         _disksize=`df --block-size=1 $SCRATCH_DEV | awk -v sd=$SCRATCH_DEV 'BEGIN{c=0}{for(i=1;i<=NF;++i){a[c]=$i;++c}}END{for(entry in a){if(a[entry] ~ sd){print a[entry + 3]; break}}}'`
74         _disksize=$(($_disksize / 3))
75         _num=$(($_disksize / $count / $threads / 4096))
76         _count=$count
77         while [ $_i -lt $_num ]
78         do
79                 dd if=/dev/zero of=file_$_i bs=4096 count=$_count >/dev/null 2>&1
80                 _i=$(($_i + 1))
81         done
82
83         cd $here
84 }
85
86 _porter()
87 {
88         _suffix=$1
89
90         if ! mkdir $SCRATCH_MNT/sub_$_suffix
91         then
92                 echo "mkdir sub_xxx err"
93                 status=1
94                 exit
95         fi
96
97         cp -r $SCRATCH_MNT/origin $SCRATCH_MNT/sub_$_suffix >>$seqres.full 2>&1
98         if [ $? -ne 0 ]
99         then
100                 echo "_porter $_suffix not complete"
101         fi
102         
103         sync
104 }
105
106 _do_workload()
107 {
108         _pids=""
109         _pid=1
110         
111         _threads_set
112         _file_create
113
114         _threads=$threads
115
116         while [ $_pid -lt $_threads ]
117         do
118                 _porter $_pid &
119                 _pids="$_pids $!"
120                 _pid=$(($_pid + 1))
121         done
122
123         wait $_pids
124 }
125
126 # real QA test starts here
127 _supported_fs generic
128 _supported_os IRIX Linux
129 _require_scratch
130
131 echo "------------------------------"
132 echo "start the workload"
133 echo "------------------------------"
134
135 rm -f $seqres.full
136
137 _scratch_unmount 2>/dev/null
138 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
139 _scratch_mount
140
141 _do_workload
142
143 _check_scratch_fs
144 status=$?
145 exit