fs_inod 6.4 KB

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