generic/077: fall back to /usr if /lib/modules doesn't exist
[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         _i=0
61
62         if ! mkdir $SCRATCH_MNT/origin
63         then
64                 echo "mkdir origin err"
65                 status=1
66                 exit
67         fi
68
69         cd $SCRATCH_MNT/origin
70
71         _disksize=`$DF_PROG --block-size=1 $SCRATCH_DEV | tail -1 | awk '{ print $5 }'`
72         _disksize=$(($_disksize / 3))
73         _num=$(($_disksize / $count / $threads / 4096))
74         _count=$count
75         while [ $_i -lt $_num ]
76         do
77                 dd if=/dev/zero of=file_$_i bs=4096 count=$_count >/dev/null 2>&1
78                 _i=$(($_i + 1))
79         done
80
81         cd $here
82 }
83
84 _porter()
85 {
86         _suffix=$1
87
88         if ! mkdir $SCRATCH_MNT/sub_$_suffix
89         then
90                 echo "mkdir sub_xxx err"
91                 status=1
92                 exit
93         fi
94
95         cp -r $SCRATCH_MNT/origin $SCRATCH_MNT/sub_$_suffix >>$seqres.full 2>&1
96         if [ $? -ne 0 ]
97         then
98                 echo "_porter $_suffix not complete"
99         fi
100         
101         sync
102 }
103
104 _do_workload()
105 {
106         _pids=""
107         _pid=1
108         
109         _threads_set
110         _file_create
111
112         _threads=$threads
113
114         while [ $_pid -lt $_threads ]
115         do
116                 _porter $_pid &
117                 _pids="$_pids $!"
118                 _pid=$(($_pid + 1))
119         done
120
121         wait $_pids
122 }
123
124 # real QA test starts here
125 _supported_fs generic
126 _supported_os IRIX Linux
127 _require_scratch
128
129 echo "------------------------------"
130 echo "start the workload"
131 echo "------------------------------"
132
133 rm -f $seqres.full
134
135 _scratch_unmount 2>/dev/null
136 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
137 _scratch_mount
138
139 _do_workload
140
141 status=0
142 exit