generic/405: test mkfs against thin provision device
[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 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # success is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -rf $tmp.*
39         _scratch_unmount
40 }
41
42 . ./common/rc
43 . ./common/filter
44
45 threads=50
46 count=2
47
48 _threads_set()
49 {
50         _cpu_num=`$here/src/feature -o`
51         threads=$(($_cpu_num * 50))
52         if [ $threads -gt 200 ]
53         then
54                 threads=200
55         fi
56 }
57
58 _file_create()
59 {
60         block_size=$1
61         _i=0
62
63         if ! mkdir $SCRATCH_MNT/origin
64         then
65                 echo "mkdir origin err"
66                 status=1
67                 exit
68         fi
69
70         cd $SCRATCH_MNT/origin
71
72         _disksize=`$DF_PROG -B 1 $SCRATCH_MNT | tail -1 | $AWK_PROG '{ print $5 }'`
73         _disksize=$(($_disksize / 3))
74         _num=$(($_disksize / $count / $threads / $block_size))
75         _count=$count
76         while [ $_i -lt $_num ]
77         do
78                 dd if=/dev/zero of=file_$_i bs=$block_size count=$_count >/dev/null 2>&1
79                 _i=$(($_i + 1))
80         done
81
82         cd $here
83 }
84
85 _porter()
86 {
87         _suffix=$1
88
89         if ! mkdir $SCRATCH_MNT/sub_$_suffix
90         then
91                 echo "mkdir sub_xxx err"
92                 status=1
93                 exit
94         fi
95
96         cp -r $SCRATCH_MNT/origin $SCRATCH_MNT/sub_$_suffix >>$seqres.full 2>&1
97         if [ $? -ne 0 ]
98         then
99                 echo "_porter $_suffix not complete"
100         fi
101         
102         sync
103 }
104
105 _do_workload()
106 {
107         _pids=""
108         _pid=1
109         block_size=$(_get_block_size $SCRATCH_MNT)
110         
111         _threads_set
112         _file_create $block_size
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 status=0
144 exit