Whamcloud - gitweb
adjust krb5 related scripts, add krb5 support in replay-ost-single,
[fs/lustre-release.git] / lustre / tests / sanity-fid.sh
1 #!/bin/bash
2 set -e
3
4 ONLY=${ONLY:-"$*"}
5 # bug number for skipped test: 
6 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
7 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
8
9 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
10
11 SRCDIR=`dirname $0`
12 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
13 export SECURITY=${SECURITY:-"null"}
14
15 TMP=${TMP:-/tmp}
16 FSTYPE=${FSTYPE:-ext3}
17
18 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
19 CREATETEST=${CREATETEST:-createtest}
20 LFS=${LFS:-lfs}
21 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
22 LFIND=${LFIND:-"$LFS find"}
23 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
24 LCTL=${LCTL:-lctl}
25 MCREATE=${MCREATE:-mcreate}
26 OPENFILE=${OPENFILE:-openfile}
27 OPENUNLINK=${OPENUNLINK:-openunlink}
28 TOEXCL=${TOEXCL:-toexcl}
29 TRUNCATE=${TRUNCATE:-truncate}
30 MUNLINK=${MUNLINK:-munlink}
31 SOCKETSERVER=${SOCKETSERVER:-socketserver}
32 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
33 IOPENTEST1=${IOPENTEST1:-iopentest1}
34 IOPENTEST2=${IOPENTEST2:-iopentest2}
35 PTLDEBUG=${PTLDEBUG:-0}
36 MODE=${MODE:mds}
37
38 . krb5_env.sh
39
40 export NAME=${NAME:-local}
41
42 SAVE_PWD=$PWD
43
44 clean() {
45         echo -n "cln.."
46         sh llmountcleanup.sh > /dev/null || exit 20
47         I_MOUNTED=no
48 }
49 CLEAN=${CLEAN:-clean}
50
51 start() {
52         echo -n "mnt.."
53         sh llrmount.sh > /dev/null || exit 10
54         I_MOUNTED=yes
55         echo "done"
56 }
57 START=${START:-start}
58
59 log() {
60         echo "$*"
61         lctl mark "$*" 2> /dev/null || true
62 }
63
64 trace() {
65         log "STARTING: $*"
66         strace -o $TMP/$1.strace -ttt $*
67         RC=$?
68         log "FINISHED: $*: rc $RC"
69         return 1
70 }
71 TRACE=${TRACE:-""}
72
73 check_kernel_version() {
74         VERSION_FILE=/proc/fs/lustre/kernel_version
75         WANT_VER=$1
76         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
77         GOT_VER=`cat $VERSION_FILE`
78         [ $GOT_VER -ge $WANT_VER ] && return 0
79         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
80         return 1
81 }
82
83 run_one() {
84         if ! cat /proc/mounts | grep -q $DIR; then
85                 $START
86         fi
87         echo $PTLDEBUG >/proc/sys/portals/debug 
88         log "== test $1: $2"
89         export TESTNAME=test_$1
90         test_$1 || error "test_$1: exit with rc=$?"
91         unset TESTNAME
92         pass
93         cd $SAVE_PWD
94         $CLEAN
95 }
96
97 build_test_filter() {
98         for O in $ONLY; do
99             eval ONLY_${O}=true
100         done
101         for E in $EXCEPT $ALWAYS_EXCEPT; do
102             eval EXCEPT_${E}=true
103         done
104 }
105
106 _basetest() {
107     echo $*
108 }
109
110 basetest() {
111     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
112 }
113
114 run_test() {
115          base=`basetest $1`
116          if [ "$ONLY" ]; then
117                  testname=ONLY_$1
118                  if [ ${!testname}x != x ]; then
119                         run_one $1 "$2"
120                         return $?
121                  fi
122                  testname=ONLY_$base
123                  if [ ${!testname}x != x ]; then
124                          run_one $1 "$2"
125                          return $?
126                  fi
127                  echo -n "."
128                  return 0
129         fi
130         testname=EXCEPT_$1
131         if [ ${!testname}x != x ]; then
132                  echo "skipping excluded test $1"
133                  return 0
134         fi
135         testname=EXCEPT_$base
136         if [ ${!testname}x != x ]; then
137                  echo "skipping excluded test $1 (base $base)"
138                  return 0
139         fi
140         run_one $1 "$2"
141         return $?
142 }
143
144 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
145
146 error() { 
147         log "FAIL: $@"
148         if [ "$SANITYLOG" ]; then
149                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
150         else
151                 exit 1
152         fi
153 }
154
155 pass() { 
156         echo PASS
157 }
158
159 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
160 if [ -z "$MOUNT" ]; then
161         sh llmount.sh
162         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
163         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
164         I_MOUNTED=yes
165 fi
166
167 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
168
169 DIR=${DIR:-$MOUNT}
170 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
171
172 rm -rf $DIR/[Rdfs][1-9]*
173
174 build_test_filter
175
176 echo preparing for tests involving mounts
177 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
178 touch $EXT2_DEV
179 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
180
181 test_1a() {
182         rm -fr $DIR/1a0 > /dev/null
183         MDS=`find /proc/fs/lustre/mds/* -type d | head -n1 | sed 's/.*\///'`
184         [ -z "$MDS" ] && {
185             echo "no MDS available, skipping test"
186             return 0
187         }
188         count=`find /proc/fs/lustre/mds/* -type d | wc -l`
189         [ $count -gt 1 ] && {
190             echo "more than 1 MDS is found, skipping test"
191             return 0
192         }
193
194         mkdir $DIR/1a0 || error
195         old_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
196         createmany -o $DIR/1a0/f 5000
197         new_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
198         
199         diff=$(($new_last_fid-$old_last_fid))
200         [ $diff -ne 5000 ] && {
201             echo "invalid fid management on $MDS: \
202                 old $old_last_fid, new $new_last_fid"
203             error
204         }
205         rm -fr $DIR/1a0 || error
206 }
207 run_test 1a " fid correctness (create) ============="
208
209 test_1b() {
210         rm -fr $DIR/1b0 > /dev/null
211         MDS=`find /proc/fs/lustre/mds/* -type d | head -n1 | sed 's/.*\///'`
212         [ -z "$MDS" ] && {
213             echo "no MDS available, skipping test"
214             return 0
215         }
216         count=`find /proc/fs/lustre/mds/* -type d | wc -l`
217         [ $count -gt 1 ] && {
218             echo "more than 1 MDS is found, skipping test"
219             return 0
220         }
221
222         mkdir $DIR/1b0 || error
223         createmany -o $DIR/1b0/f 5000
224         old_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
225         rm -fr $DIR/1b0/f
226         new_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
227         
228         [ $new_last_fid -ne $old_last_fid ] && {
229             echo "invalid fid management on $MDS: \
230                 old $old_last_fid, new $new_last_fid"
231             error
232         }
233         rm -fr $DIR/1b0 || error
234 }
235 run_test 1b " fid correctness (remove) ============="
236
237 TMPDIR=$OLDTMPDIR
238 TMP=$OLDTMP
239 HOME=$OLDHOME
240
241 log "cleanup: ========================================================"
242 if [ "`mount | grep ^$NAME`" ]; then
243         rm -rf $DIR/[Rdfs][1-9]*
244         if [ "$I_MOUNTED" = "yes" ]; then
245                 sh llmountcleanup.sh || error
246         fi
247 fi
248
249 echo "=========================== finished ============================"
250 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true