subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) International Business Machines Corp., 2008 |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 4 | # |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 18 | # |
| 19 | #******************************************************************************* |
| 20 | # Readme_ROBind has more details on the tests running for ROBIND. |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 21 | # TEST: |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 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's like ext2, ext3, reiserfs, jfs & xfs. |
| 27 | # This test creates an image-file and |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 28 | # a) mounts on dir1, |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 29 | # b) mount --bind dir2 |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 30 | # c) mount -o remount,ro |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 31 | # It verifies the tests on a) and b) works correctly. |
| 32 | # For the c) option it checks that the tests are not able to write into dir. |
| 33 | # Then it executes the tests from flat-file {LTPROOT}/testscripts/fs_ro_tests |
| 34 | # Check the logs /tmp/fs$$/errs.log and /tmp/fs$$/pass.log for pass/failures. |
| 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 | |
| 44 | #trace_logic=${trace_logic:-"set -x"} |
| 45 | $trace_logic |
| 46 | |
| 47 | # The test case ID, the test case count and the total number of test case |
| 48 | TCID=${TCID:-test_robind.sh} |
| 49 | TST_TOTAL=1 |
| 50 | TST_COUNT=1 |
| 51 | export TCID |
| 52 | export TST_COUNT |
| 53 | export TST_TOTAL |
| 54 | |
| 55 | usage() |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 56 | { |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 57 | cat << EOF |
| 58 | usage: $0 [ext3,ext2,jfs,xfs,reiserfs,ramfs] |
| 59 | |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 60 | This script verifies ReadOnly-filesystem, by mounting imagefile and |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 61 | executing the filesystem tests. |
| 62 | |
| 63 | OPTIONS |
| 64 | -h display this message and exit |
| 65 | EOF |
| 66 | } |
| 67 | |
| 68 | DIRS="dir1 dir2-bound dir3-ro" |
| 69 | TMPDIR=/tmp/fs$$ |
| 70 | trap cleanup ERR |
| 71 | trap cleanup INT |
| 72 | |
| 73 | #============================================================================== |
| 74 | # FUNCTION NAME: cleanup |
| 75 | # |
| 76 | # FUNCTION DESCRIPTION: Unmounts dir, Removes dir's, files created by the tests. |
| 77 | # |
| 78 | # PARAMETERS: The $fs_image . |
| 79 | # |
| 80 | # RETURNS: None. |
| 81 | #============================================================================== |
| 82 | function cleanup |
| 83 | { |
| 84 | umount ${TMPDIR}/dir3-ro 2> /dev/null > /dev/null |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 85 | umount ${TMPDIR}/dir2-bound 2> /dev/null 1> /dev/null |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 86 | umount ${TMPDIR}/dir1 2> /dev/null 1> /dev/null |
| 87 | if [ ! -z $1 ]; then { |
| 88 | rm -rf $1 || true |
| 89 | } |
| 90 | fi |
| 91 | } |
| 92 | |
| 93 | #=============================================================================== |
| 94 | # FUNCTION NAME: setup |
| 95 | # |
| 96 | # FUNCTION DESCRIPTION: Does the initailization |
| 97 | # |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 98 | # PARAMETERS: File_systems (if any ) |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 99 | # |
| 100 | # RETURNS: None. |
| 101 | #=============================================================================== |
| 102 | function setup |
| 103 | { |
| 104 | mkdir ${TMPDIR} |
| 105 | FAILLOG="$TMPDIR/errs.log" |
| 106 | PASSLOG="$TMPDIR/pass.log" |
| 107 | |
| 108 | for i in $DIRS; do |
| 109 | rm -rf ${TMPDIR}/$i || true |
| 110 | mkdir -p ${TMPDIR}/$i |
| 111 | done; |
| 112 | |
| 113 | # Populating the default FS as ext3, if FS is not given |
| 114 | if [ -z "$*" ]; then |
| 115 | FSTYPES="ext3" |
| 116 | else |
| 117 | FSTYPES="$*" |
| 118 | fi |
| 119 | |
| 120 | # set the LTPROOT directory |
| 121 | cd `dirname $0` |
| 122 | echo "${PWD}" | grep testscripts > /dev/null 2>&1 |
| 123 | if [ $? -eq 0 ]; then |
| 124 | cd .. |
| 125 | export LTPROOT="${PWD}" |
| 126 | export PATH="${PATH}:${LTPROOT}/testcases/bin" |
| 127 | fi |
| 128 | |
| 129 | FS_Tests="${LTPROOT}/testscripts/fs_ro_tests" |
| 130 | cd ${TMPDIR} |
| 131 | } |
| 132 | |
| 133 | #============================================================================= |
| 134 | # FUNCTION NAME: testdir |
| 135 | # |
| 136 | # FUNCTION DESCRIPTION: The core function where it runs the tests |
| 137 | # |
| 138 | # PARAMETERS: dir_name, file_systems, Read_only flag = [true|false] |
| 139 | # |
| 140 | # RETURNS: None. |
| 141 | #============================================================================= |
| 142 | function testdir |
| 143 | { |
| 144 | dir=$1 |
| 145 | fs=$2 |
| 146 | RO=$3 |
| 147 | pushd $dir |
| 148 | testnums=`wc -l $FS_Tests | cut -f1 -d" "` |
| 149 | status=0 |
| 150 | |
| 151 | echo "---------------------------------------------------" >> $FAILLOG ; |
| 152 | echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $FAILLOG ; |
| 153 | echo "---------------------------------------------------" >> $FAILLOG ; |
| 154 | |
| 155 | echo "---------------------------------------------------" >> $PASSLOG ; |
| 156 | echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $PASSLOG ; |
| 157 | echo "---------------------------------------------------" >> $PASSLOG ; |
| 158 | |
| 159 | export TDIRECTORY=$PWD ; |
| 160 | echo TDIR is $TDIRECTORY; |
| 161 | if [ $RO == false ] ; then # Testing Read-Write dir |
| 162 | for tests in `seq $testnums` ; do |
yaberauneya | 81db12a | 2009-11-19 18:52:32 +0000 | [diff] [blame] | 163 | cmd=`cat $FS_Tests | head -$tests | tail -n 1` |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 164 | # eval $cmd 2>&1 /dev/null |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 165 | eval $cmd 2> /dev/null 1> /dev/null |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 166 | if [ $? -eq 0 ]; then |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 167 | echo "$tests. '$cmd' PASS" >> $PASSLOG |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 168 | else |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 169 | echo "$tests. '$cmd' FAIL " >> $FAILLOG |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 170 | echo "TDIR is $TDIRECTORY" >> $FAILLOG; |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 171 | status=1 |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 172 | fi |
| 173 | done |
| 174 | |
| 175 | else # Testing Read-Only dir |
| 176 | for tests in `seq $testnums` ; do |
yaberauneya | 81db12a | 2009-11-19 18:52:32 +0000 | [diff] [blame] | 177 | cmd=`cat $FS_Tests | head -$tests | tail -n 1` |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 178 | eval $cmd 2> /dev/null 1> /dev/null |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 179 | if [ $? -ne 0 ]; then |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 180 | echo "$tests. '$cmd' PASS " >> $PASSLOG |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 181 | else |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 182 | echo "$tests. '$cmd' FAIL" >> $FAILLOG |
| 183 | status=1 |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 184 | fi |
| 185 | done |
| 186 | fi |
| 187 | if [ $status == 1 ] ; then |
| 188 | echo "RO-FileSystem Tests FAILED for $dir $fs filesystem" >> $FAILLOG |
| 189 | echo >> $FAILLOG |
subrata_modak | 88dc0db | 2008-08-11 11:24:50 +0000 | [diff] [blame] | 190 | retcode=$status |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 191 | else |
| 192 | echo "RO-FileSystem Tests PASSed for $dir $fs filesystem" >> $PASSLOG |
| 193 | echo >> $PASSLOG |
| 194 | fi |
| 195 | # Remove all the temp-files created. |
Jungsoo Son | ce160a7 | 2013-07-16 15:41:26 +0900 | [diff] [blame] | 196 | eval rm -rf ${TMPDIR}/${dir}/* > /dev/null 2>&1 || true |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 197 | unset TDIRECTORY |
| 198 | popd |
| 199 | } |
| 200 | |
| 201 | #============================================================================= |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 202 | # MAIN |
| 203 | # See the description, purpose, and design of this test under TEST |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 204 | # in this test's prolog. |
| 205 | #============================================================================= |
subrata_modak | 88dc0db | 2008-08-11 11:24:50 +0000 | [diff] [blame] | 206 | retcode=0 |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 207 | while getopts h: OPTION; do |
| 208 | case $OPTION in |
| 209 | h) |
| 210 | usage |
| 211 | exit 1 |
| 212 | ;; |
| 213 | ?) |
| 214 | usage |
| 215 | exit 1 |
| 216 | ;; |
| 217 | esac |
| 218 | done |
| 219 | # Does the initial setups |
| 220 | oldpwd=${PWD} |
| 221 | setup $* |
| 222 | |
| 223 | # Executes the tests for differnt FS's |
| 224 | # Creates an image file of 500 MB and mounts it. |
| 225 | for fstype in $FSTYPES; do |
| 226 | image=$fstype.img |
| 227 | dd if=/dev/zero of=$image bs=$((1<<20)) count=500 2> /dev/null 1> /dev/null |
| 228 | if [ $? -ne 0 ] ; then |
| 229 | tst_resm, TFAIL "Unable to create image " |
| 230 | tst_resm, TFAIL "Free Disk space of 512MB is required in /tmp fs" |
| 231 | tst_resm, TFAIL "Please free it and rerun thank you.." |
| 232 | rm -f $image |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 233 | exit -1 |
| 234 | fi |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 235 | |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 236 | OPTS="-F" |
| 237 | if [ "$fstype" == "reiserfs" ]; then |
| 238 | OPTS="-f --journal-size 513 -q" |
| 239 | elif [ "$fstype" == "jfs" ]; then |
| 240 | OPTS="-f" |
| 241 | elif [ "$fstype" == "xfs" ]; then |
| 242 | OPTS="" |
| 243 | fi |
| 244 | |
| 245 | if [ "$fstype" != "ramfs" ] ; then |
| 246 | mkfs.$fstype $OPTS $image 2> /dev/null 1> /dev/null |
| 247 | fi |
| 248 | |
| 249 | mount -t $fstype -o loop $image dir1 |
subrata_modak | 88dc0db | 2008-08-11 11:24:50 +0000 | [diff] [blame] | 250 | mount --bind dir1 dir2-bound || exit -1 |
| 251 | mount --bind dir1 dir3-ro || exit -1 |
| 252 | mount -o remount,ro dir3-ro || exit -1 |
subrata_modak | d5073b9 | 2008-08-11 10:01:12 +0000 | [diff] [blame] | 253 | |
| 254 | testdir dir1 $fstype false |
| 255 | testdir dir2-bound $fstype false |
| 256 | testdir dir3-ro $fstype true |
| 257 | cleanup $image |
| 258 | done |
| 259 | |
| 260 | for i in $DIRS; do |
| 261 | rm -rf ./$i || true |
| 262 | done; |
| 263 | cd $oldpwd || true |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 264 | exit $retcode |
subrata_modak | 88dc0db | 2008-08-11 11:24:50 +0000 | [diff] [blame] | 265 | |