3 # Copyright (c) International Business Machines Corp., 2008
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #*******************************************************************************
20 # Readme_ROBind has more details on the tests running for ROBIND.
22 # NAME: test_robind.sh
23 # FUNCTIONALITY: File system tests for normal mount, bind mount and RO mount
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
29 # b) mount --bind dir2
30 # c) mount -o remount,ro
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 #===============================================================================
39 # 09/06/2008 Veerendra Chandrappa For Container, testing of RO-Bind mount
41 # This script is based on the Dave Hansen script for testing the robind.
42 #*******************************************************************************
44 #trace_logic=${trace_logic:-"set -x"}
47 # The test case ID, the test case count and the total number of test case
48 TCID
=${TCID:-test_robind.sh}
58 usage: $0 [ext3,ext2,jfs,xfs,reiserfs,ramfs]
60 This script verifies ReadOnly-filesystem, by mounting imagefile and
61 executing the filesystem tests.
64 -h display this message and exit
68 DIRS
="dir1 dir2-bound dir3-ro"
73 #==============================================================================
74 # FUNCTION NAME: cleanup
76 # FUNCTION DESCRIPTION: Unmounts dir, Removes dir's, files created by the tests.
78 # PARAMETERS: The $fs_image .
81 #==============================================================================
84 umount
${TMPDIR}/dir3-ro
2> /dev
/null
> /dev
/null
85 umount
${TMPDIR}/dir2-bound
2> /dev
/null
1> /dev
/null
86 umount
${TMPDIR}/dir1
2> /dev
/null
1> /dev
/null
87 if [ ! -z $1 ]; then {
93 #===============================================================================
94 # FUNCTION NAME: setup
96 # FUNCTION DESCRIPTION: Does the initailization
98 # PARAMETERS: File_systems (if any )
101 #===============================================================================
105 FAILLOG
="$TMPDIR/errs.log"
106 PASSLOG
="$TMPDIR/pass.log"
109 rm -rf ${TMPDIR}/$i || true
110 mkdir
-p ${TMPDIR}/$i
113 # Populating the default FS as ext3, if FS is not given
120 # set the LTPROOT directory
122 echo "${PWD}" |
grep testscripts
> /dev
/null
2>&1
123 if [ $?
-eq 0 ]; then
125 export LTPROOT
="${PWD}"
126 export PATH
="${PATH}:${LTPROOT}/testcases/bin"
129 FS_Tests
="${LTPROOT}/testscripts/fs_ro_tests"
133 #=============================================================================
134 # FUNCTION NAME: testdir
136 # FUNCTION DESCRIPTION: The core function where it runs the tests
138 # PARAMETERS: dir_name, file_systems, Read_only flag = [true|false]
141 #=============================================================================
148 testnums
=`wc -l $FS_Tests | cut -f1 -d" "`
151 echo "---------------------------------------------------" >> $FAILLOG ;
152 echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $FAILLOG ;
153 echo "---------------------------------------------------" >> $FAILLOG ;
155 echo "---------------------------------------------------" >> $PASSLOG ;
156 echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $PASSLOG ;
157 echo "---------------------------------------------------" >> $PASSLOG ;
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
163 cmd
=`cat $FS_Tests | head -$tests | tail -1`
164 # eval $cmd 2>&1 /dev/null
165 eval $cmd 2> /dev
/null
1> /dev
/null
166 if [ $?
-eq 0 ]; then
167 echo "$tests. '$cmd' PASS" >> $PASSLOG
169 echo "$tests. '$cmd' FAIL " >> $FAILLOG
170 echo "TDIR is $TDIRECTORY" >> $FAILLOG;
175 else # Testing Read-Only dir
176 for tests
in `seq $testnums` ; do
177 cmd
=`cat $FS_Tests | head -$tests | tail -1`
178 eval $cmd 2> /dev
/null
1> /dev
/null
179 if [ $?
-ne 0 ]; then
180 echo "$tests. '$cmd' PASS " >> $PASSLOG
182 echo "$tests. '$cmd' FAIL" >> $FAILLOG
187 if [ $status == 1 ] ; then
188 echo "RO-FileSystem Tests FAILED for $dir $fs filesystem" >> $FAILLOG
192 echo "RO-FileSystem Tests PASSed for $dir $fs filesystem" >> $PASSLOG
195 # Remove all the temp-files created.
196 eval rm -rf ${TMPDIR}/${dir}/* > /dev
/null
2>&1 /dev
/null || true
201 #=============================================================================
203 # See the description, purpose, and design of this test under TEST
204 # in this test's prolog.
205 #=============================================================================
207 while getopts h
: OPTION
; do
219 # Does the initial setups
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
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.."
237 if [ "$fstype" == "reiserfs" ]; then
238 OPTS="-f --journal-size 513 -q"
239 elif [ "$fstype" == "jfs" ]; then
241 elif [ "$fstype" == "xfs" ]; then
245 if [ "$fstype" != "ramfs" ] ; then
246 mkfs.$fstype $OPTS $image 2> /dev/null 1> /dev/null
249 mount -t $fstype -o loop $image dir1
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
254 testdir dir1 $fstype false
255 testdir dir2-bound $fstype false
256 testdir dir3-ro $fstype true