blob: 4c01f4eff030437e6ad761c6cec3b86710a3c3f9 [file] [log] [blame]
subrata_modakd5073b92008-08-11 10:01:12 +00001#!/bin/bash
2#
3# Copyright (c) International Business Machines Corp., 2008
Chris Dearman37550cf2012-10-17 19:54:01 -07004#
subrata_modakd5073b92008-08-11 10:01:12 +00005# 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 Gao4548c6c2012-10-19 18:03:36 +080017# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modakd5073b92008-08-11 10:01:12 +000018#
19#*******************************************************************************
20# Readme_ROBind has more details on the tests running for ROBIND.
Chris Dearman37550cf2012-10-17 19:54:01 -070021# TEST:
subrata_modakd5073b92008-08-11 10:01:12 +000022# 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 Dearman37550cf2012-10-17 19:54:01 -070028# a) mounts on dir1,
subrata_modakd5073b92008-08-11 10:01:12 +000029# b) mount --bind dir2
Chris Dearman37550cf2012-10-17 19:54:01 -070030# c) mount -o remount,ro
subrata_modakd5073b92008-08-11 10:01:12 +000031# 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
48TCID=${TCID:-test_robind.sh}
49TST_TOTAL=1
50TST_COUNT=1
51export TCID
52export TST_COUNT
53export TST_TOTAL
54
55usage()
Chris Dearman37550cf2012-10-17 19:54:01 -070056{
subrata_modakd5073b92008-08-11 10:01:12 +000057 cat << EOF
58 usage: $0 [ext3,ext2,jfs,xfs,reiserfs,ramfs]
59
Chris Dearman37550cf2012-10-17 19:54:01 -070060 This script verifies ReadOnly-filesystem, by mounting imagefile and
subrata_modakd5073b92008-08-11 10:01:12 +000061 executing the filesystem tests.
62
63 OPTIONS
64 -h display this message and exit
65EOF
66}
67
68DIRS="dir1 dir2-bound dir3-ro"
69TMPDIR=/tmp/fs$$
70trap cleanup ERR
71trap 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#==============================================================================
82function cleanup
83{
84 umount ${TMPDIR}/dir3-ro 2> /dev/null > /dev/null
Chris Dearman37550cf2012-10-17 19:54:01 -070085 umount ${TMPDIR}/dir2-bound 2> /dev/null 1> /dev/null
subrata_modakd5073b92008-08-11 10:01:12 +000086 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 Dearman37550cf2012-10-17 19:54:01 -070098# PARAMETERS: File_systems (if any )
subrata_modakd5073b92008-08-11 10:01:12 +000099#
100# RETURNS: None.
101#===============================================================================
102function 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#=============================================================================
142function 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
yaberauneya81db12a2009-11-19 18:52:32 +0000163 cmd=`cat $FS_Tests | head -$tests | tail -n 1`
subrata_modakd5073b92008-08-11 10:01:12 +0000164# eval $cmd 2>&1 /dev/null
Chris Dearman37550cf2012-10-17 19:54:01 -0700165 eval $cmd 2> /dev/null 1> /dev/null
subrata_modakd5073b92008-08-11 10:01:12 +0000166 if [ $? -eq 0 ]; then
Chris Dearman37550cf2012-10-17 19:54:01 -0700167 echo "$tests. '$cmd' PASS" >> $PASSLOG
subrata_modakd5073b92008-08-11 10:01:12 +0000168 else
Chris Dearman37550cf2012-10-17 19:54:01 -0700169 echo "$tests. '$cmd' FAIL " >> $FAILLOG
subrata_modakd5073b92008-08-11 10:01:12 +0000170 echo "TDIR is $TDIRECTORY" >> $FAILLOG;
Chris Dearman37550cf2012-10-17 19:54:01 -0700171 status=1
subrata_modakd5073b92008-08-11 10:01:12 +0000172 fi
173 done
174
175 else # Testing Read-Only dir
176 for tests in `seq $testnums` ; do
yaberauneya81db12a2009-11-19 18:52:32 +0000177 cmd=`cat $FS_Tests | head -$tests | tail -n 1`
Chris Dearman37550cf2012-10-17 19:54:01 -0700178 eval $cmd 2> /dev/null 1> /dev/null
subrata_modakd5073b92008-08-11 10:01:12 +0000179 if [ $? -ne 0 ]; then
Chris Dearman37550cf2012-10-17 19:54:01 -0700180 echo "$tests. '$cmd' PASS " >> $PASSLOG
subrata_modakd5073b92008-08-11 10:01:12 +0000181 else
Chris Dearman37550cf2012-10-17 19:54:01 -0700182 echo "$tests. '$cmd' FAIL" >> $FAILLOG
183 status=1
subrata_modakd5073b92008-08-11 10:01:12 +0000184 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_modak88dc0db2008-08-11 11:24:50 +0000190 retcode=$status
subrata_modakd5073b92008-08-11 10:01:12 +0000191 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 Sonce160a72013-07-16 15:41:26 +0900196 eval rm -rf ${TMPDIR}/${dir}/* > /dev/null 2>&1 || true
subrata_modakd5073b92008-08-11 10:01:12 +0000197 unset TDIRECTORY
198 popd
199}
200
201#=============================================================================
Chris Dearman37550cf2012-10-17 19:54:01 -0700202# MAIN
203# See the description, purpose, and design of this test under TEST
subrata_modakd5073b92008-08-11 10:01:12 +0000204# in this test's prolog.
205#=============================================================================
subrata_modak88dc0db2008-08-11 11:24:50 +0000206retcode=0
subrata_modakd5073b92008-08-11 10:01:12 +0000207while 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
218done
219# Does the initial setups
220oldpwd=${PWD}
221setup $*
222
223# Executes the tests for differnt FS's
224# Creates an image file of 500 MB and mounts it.
225for 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_modakd5073b92008-08-11 10:01:12 +0000233 exit -1
234 fi
Chris Dearman37550cf2012-10-17 19:54:01 -0700235
subrata_modakd5073b92008-08-11 10:01:12 +0000236 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_modak88dc0db2008-08-11 11:24:50 +0000250 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_modakd5073b92008-08-11 10:01:12 +0000253
254 testdir dir1 $fstype false
255 testdir dir2-bound $fstype false
256 testdir dir3-ro $fstype true
257 cleanup $image
258done
259
260 for i in $DIRS; do
261 rm -rf ./$i || true
262 done;
263 cd $oldpwd || true
Chris Dearman37550cf2012-10-17 19:54:01 -0700264 exit $retcode
subrata_modak88dc0db2008-08-11 11:24:50 +0000265