• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3#
4#
5#   Copyright (c) International Business Machines  Corp., 2001
6#
7#   This program is free software;  you can redistribute it and/or modify
8#   it under the terms of the GNU General Public License as published by
9#   the Free Software Foundation; either version 2 of the License, or
10#   (at your option) any later version.
11#
12#   This program is distributed in the hope that it will be useful,
13#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
14#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15#   the GNU General Public License for more details.
16#
17#   You should have received a copy of the GNU General Public License
18#   along with this program;  if not, write to the Free Software
19#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20#
21#***********************************************************************
22#
23# TEST:
24# 	NAME:		fs_inod
25#	FUNCTIONALITY: 	File system stress - inode allocation/deallocation
26# 	DESCRIPTION:	Rapidly creates and deletes files through
27#			multiple processes running in the background.
28#			The user may specify the number of subdirectories
29#			to create, the number of files to create (per
30#			subdirectory), and the number of times to repeat
31#			the creation/deletion cycle.
32#
33#========================================================================
34#
35# CHANGE HISTORY:
36# 		DATE            AUTHOR                  REASON
37#       	04/18/98        Dara Morgenstein        Project Yeager (AIX)
38#		02/08/01	Jay Inman		Modified to run standalone on Linux
39#		05/24/01	Jay Inman		Added command line args
40#		06/27/01	Jay Inman		Ported from Korn to Bash
41#
42#***********************************************************************
43
44
45#=============================================================================
46# FUNCTION NAME:        err_log
47#
48# FUNCTION DESCRIPTION: Log error
49#
50# PARAMETERS:           None.
51#
52# RETURNS:              None.
53#=============================================================================
54err_log()
55{
56    : $((step_errors += 1))
57}
58
59
60#=============================================================================
61# FUNCTION NAME: 	make_subdirs
62#
63# FUNCTION DESCRIPTION: Creates $numsubdirs subdirectories
64#
65# PARAMETERS: 		None.
66#
67# RETURNS: 		None.
68#=============================================================================
69make_subdirs ()
70{
71    i=0;
72    while [ "$i" -lt "$numsubdirs" ]; do
73        [ -d dir$i ] || { \
74            echo "$0: mkdir dir$i"
75            mkdir -p dir$i || echo "mkdir dir$i FAILED"
76        }
77	: $((i += 1))
78    done;
79}
80
81
82#=============================================================================
83# FUNCTION NAME: 	touch_files
84#
85# FUNCTION DESCRIPTION: Creates $numfiles in each of $numsubdirs directories
86#
87# PARAMETERS: 		None.
88#
89# RETURNS: 		None.
90#=============================================================================
91touch_files()
92{
93    echo "$0: touch files [0-$numsubdirs]/file$numsubdirs[0-$numfiles]"
94    j=0;
95
96    while [ "$j" -lt "$numsubdirs" ]; do
97	cd dir$j
98	k=0;
99
100	while [ "$k" -lt "$numfiles" ]; do
101	    >file$j$k || err_log ">file$j$k FAILED"
102	    : $((k += 1))
103	done
104
105	: $((j += 1))
106	cd ..
107    done
108}
109
110
111#=============================================================================
112# FUNCTION NAME: 	rm_files
113#
114# FUNCTION DESCRIPTION: Removes $numfiles in each $numsubdir directory
115#
116# PARAMETERS: 	None.
117#
118# RETURNS: 	None.
119#=============================================================================
120rm_files()
121{
122    echo "$0: rm files [0-$numsubdirs]/file$numsubdirs[0-$numfiles]"
123    j=0;
124
125    while [ "$j" -lt "$numsubdirs" ]; do
126	cd dir$j
127	k=0;
128
129	while [ "$k" -lt "$numfiles" ]; do
130	    rm -f file$j$k || err_log "rm -f file$j$k FAILED"
131	    : $((k += 1))
132	done
133
134	: $((j += 1))
135	cd ..
136    done
137}
138
139
140#=============================================================================
141# FUNCTION NAME: 	step1
142#
143# FUNCTION DESCRIPTION: multiple processes creating and deleting files
144#
145# PARAMETERS: 		None.
146#
147# RETURNS: 		None.
148#=============================================================================
149step1 ()
150{
151    echo "=============================================="
152    echo "MULTIPLE PROCESSES CREATING AND DELETING FILES"
153    echo "=============================================="
154
155    echo "$0: creating dir2 subdirectories"
156    [ -d dir2 ] || { \
157        mkdir -p dir2 || end_testcase "mkdir dir2 failed"
158    }
159    cd dir2 || err_log "cd dir2 FAILED"
160    make_subdirs || err_log "make_subdirs on dir2 FAILED"
161    cd ..
162
163    echo "$0: creating dir1 subdirectories & files"
164    [ -d dir1 ] || { \
165        mkdir dir1 || abort "mkdir dir1 FAILED"
166    }
167    cd dir1 || err_log "cd dir1 FAILED"
168    make_subdirs || err_log "make_subdirs on dir1 FAILED"
169    touch_files &
170    pid1=$!
171
172    i=1;
173    while [ "$i" -le "$numloops" ]; do
174	echo "Executing loop $i of $numloops..."
175
176#	Added date stamps to track execution time and duration
177
178	echo "$0: cd ../dir1 & creating files"
179	cd ../dir1
180	wait $pid1
181	touch_files &
182	pid1=$!
183
184	echo "$0: cd ../dir1 & removing files"
185	cd ../dir1
186	wait $pid1
187	rm_files &
188	pid2=$!
189
190	echo "$0: cd ../dir2 & creating files"
191	cd ../dir2
192	wait $pid2
193	touch_files &
194	pid2=$!
195
196	echo "$0: cd ../dir2 & removing files"
197	cd ../dir2
198	wait $pid2
199	rm_files &
200	pid1=$!
201
202	: $((i += 1))
203    done
204
205    # wait for all background processes to complete execution
206    wait
207    return $step_errors
208}
209
210
211#=============================================================================
212# MAIN
213#     See the description, purpose, and design of this test under TEST
214#     in this test's prolog.
215#=============================================================================
216    USAGE="Usage: ./fs_inod [volumename] [numsubdirectories] [numfiles] [numloops]"
217
218    if [ $# -ne 4 ]
219    then
220       echo $USAGE
221       exit 2
222    fi
223    ERRORS=0
224
225    testvol=$1
226    numsubdirs=$2
227    numfiles=$3
228    numloops=$4
229
230    cd $testvol || exit 2
231
232    echo "FS_INODE: File system stress - inode allocation/deallocation"
233    echo "Volume under test: $testvol"
234    echo "Number of subdirectories: $numsubdirs"
235    echo "Number of files: $numfiles"
236    echo "Number of loops: $numloops"
237    echo "Execution begins "
238    date
239
240    STEPS="1"
241    for I in $STEPS
242    do
243         step_errors=0
244         step$I
245         if [ $? != 0 ]; then
246            echo "step$I failed - see above errors"
247            : $((ERRORS += step_errors))
248         fi
249    done
250
251# Clean up and timestamp
252    rm -rf $testvol/dir*
253    echo "Execution completed"
254    date
255
256    exit $ERRORS
257