test_robind.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/bin/sh
  2. #
  3. # Copyright (c) International Business Machines Corp., 2008
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. # the GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. #*******************************************************************************
  20. # Readme_ROBind has more details on the tests running for ROBIND.
  21. # TEST:
  22. # NAME: test_robind.sh
  23. # FUNCTIONALITY: File system tests for normal mount, bind mount and RO mount
  24. #
  25. # DESCRIPTION: Performs filesystems tests for RO mount.
  26. # For filesystem, like ext2, ext3, reiserfs, jfs & xfs,
  27. # This test needs a big block device(>=500MB is ok), and you can specify
  28. # it by -z option when running runltp.
  29. # a) mounts on dir1,
  30. # b) mount --bind dir2
  31. # c) mount -o remount,ro
  32. # It verifies the tests on a) and b) works correctly.
  33. # For the c) option it checks that the tests are not able to write
  34. # into dir.
  35. #===============================================================================
  36. #
  37. # CHANGE HISTORY:
  38. # DATE AUTHOR REASON
  39. # 09/06/2008 Veerendra Chandrappa For Container, testing of RO-Bind mount
  40. # Dave Hansen
  41. # This script is based on the Dave Hansen script for testing the robind.
  42. #*******************************************************************************
  43. export TCID="test_robind"
  44. export TST_TOTAL=3
  45. DIRS="dir1 dir2-bound dir3-ro"
  46. dir1_mount_flag=0
  47. dir2_bound_mount_flag=0
  48. dir3_ro_mount_flag=0
  49. . test.sh
  50. usage()
  51. {
  52. cat << EOF
  53. usage: $0 -c command [ext3,ext2,jfs,xfs,reiserfs,ramfs]
  54. This script verifies ReadOnly-filesystem, by mounting block device and
  55. executing the filesystem tests.
  56. OPTIONS
  57. -h display this message and exit
  58. -c command to be executed
  59. EOF
  60. exit 1
  61. }
  62. umount_mntpoint()
  63. {
  64. if [ $dir3_ro_mount_flag -eq 1 ];then
  65. umount dir3-ro
  66. if [ $? -ne 0 ];then
  67. tst_resm TWARN "umount dir3-ro failed"
  68. else
  69. dir3_ro_mount_flag=0
  70. fi
  71. fi
  72. if [ $dir2_bound_mount_flag -eq 1 ];then
  73. umount dir2-bound
  74. if [ $? -ne 0 ];then
  75. tst_resm TWARN "umount dir2-bound failed"
  76. else
  77. dir2_bound_mount_flag=0
  78. fi
  79. fi
  80. if [ $dir1_mount_flag -eq 1 ];then
  81. umount dir1
  82. if [ $? -ne 0 ];then
  83. tst_resm TWARN "umount dir1"
  84. else
  85. dir1_mount_flag=0
  86. fi
  87. fi
  88. }
  89. cleanup()
  90. {
  91. umount_mntpoint
  92. tst_rmdir
  93. }
  94. # parameters: file_systems (if any )
  95. setup()
  96. {
  97. tst_require_root
  98. if [ -z "$LTP_BIG_DEV" ];then
  99. tst_brkm TCONF "tests need a big block device(>=500MB)"
  100. else
  101. device=$LTP_BIG_DEV
  102. fi
  103. tst_tmpdir
  104. TST_CLEANUP=cleanup
  105. for dir in $DIRS
  106. do
  107. rm -rf $dir
  108. mkdir -p $dir
  109. done
  110. # populating the default FS as $LTP_BIG_DEV_FS_TYPE
  111. # (or ext3 if it's not set), if FS is not given
  112. if [ -z "$*" ]; then
  113. FSTYPES=${LTP_BIG_DEV_FS_TYPE:-ext3}
  114. else
  115. FSTYPES="$*"
  116. fi
  117. }
  118. # the core function where it runs the tests
  119. # $1 - directory where to run tests
  120. # $2 - file system type
  121. # $3 - read-only flag [true|false]
  122. testdir()
  123. {
  124. local dir=$1
  125. local fs_type=$2
  126. local RO=$3
  127. local tst_result=0
  128. local curdir=$(pwd)
  129. cd $dir
  130. tst_resm TINFO "command: $command"
  131. # we need to export TMPDIR, in case test calls tst_rmdir()
  132. export TMPDIR=$curdir/$dir
  133. eval $command > $curdir/test.log 2>&1
  134. tst_result=$?
  135. # if tst_result isn't 0 and read-only flag is false, the test failed
  136. # or if tst_result is 0 and read-only flag is true, the test failed.
  137. if [ "$RO" = "false" -a $tst_result -ne 0 -o "$RO" = "true" -a \
  138. $tst_result -eq 0 ];then
  139. tst_resm TINFO "error info:"
  140. cat $curdir/test.log
  141. tst_resm TFAIL "RO-FileSystem Tests FAILED for \
  142. $dir $fs_type read-only flag: $RO"
  143. else
  144. tst_resm TPASS "RO-FileSystem Tests PASSED for \
  145. $dir $fs_type read-only flag: $RO"
  146. fi
  147. # remove all the temp files created.
  148. cd ..
  149. rm -f $curdir/test.log
  150. rm -rf $curdir/$dir/*
  151. }
  152. #=============================================================================
  153. # MAIN
  154. # See the description, purpose, and design of this test under TEST
  155. # in this test's prolog.
  156. #=============================================================================
  157. while getopts c:h: OPTION; do
  158. case $OPTION in
  159. c)
  160. command=$OPTARG;;
  161. h)
  162. usage;;
  163. ?)
  164. usage;;
  165. esac
  166. done
  167. shift $((OPTIND-1))
  168. setup $*
  169. # Executes the tests for differnt FS's
  170. for fstype in $FSTYPES; do
  171. if [ "$fstype" = "reiserfs" ]; then
  172. opts="-f --journal-size 513 -q"
  173. elif echo "$fstype" | grep -q "ext"; then
  174. opts="-F"
  175. elif [ "$fstype" = "xfs" ]; then
  176. opts="-f"
  177. elif [ "$fstype" = "btrfs" ]; then
  178. opts="-f"
  179. fi
  180. if [ "$fstype" != "ramfs" ]; then
  181. tst_mkfs $fstype $device $opts
  182. fi
  183. mount -t $fstype $device dir1
  184. if [ $? -ne 0 ];then
  185. tst_brkm TBROK "mount $device to dir1 failed"
  186. else
  187. dir1_mount_flag=1
  188. fi
  189. mount --bind dir1 dir2-bound
  190. if [ $? -ne 0 ];then
  191. tst_brkm TBROK "mount --bind dir1 dir2-bound failed"
  192. else
  193. dir2_bound_mount_flag=1
  194. fi
  195. mount --bind dir1 dir3-ro
  196. if [ $? -ne 0 ];then
  197. tst_brkm TBROK "mount --bind dir1 dir3-ro failed"
  198. else
  199. dir3_ro_mount_flag=1
  200. fi
  201. mount -o remount,ro,bind dir1 dir3-ro
  202. if [ $? -ne 0 ];then
  203. tst_brkm TBROK "mount -o remount,ro,bind dir1 dir3-ro failed"
  204. fi
  205. testdir dir1 $fstype false
  206. testdir dir2-bound $fstype false
  207. testdir dir3-ro $fstype true
  208. umount_mntpoint
  209. done
  210. tst_exit