Whamcloud - gitweb
Branch b1_4_mountconf
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test:  3192 4035
7 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"14b  14c"}
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 [ "$ALWAYS_EXCEPT$EXCEPT$SANITYN_EXCEPT" ] && \
11         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITYN_EXCEPT`"
12
13 SRCDIR=`dirname $0`
14 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
15
16 SIZE=${SIZE:-40960}
17 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
18 CREATETEST=${CREATETEST:-createtest}
19 LFIND=${LFIND:-lfind}
20 LSTRIPE=${LSTRIPE:-lstripe}
21 LCTL=${LCTL:-lctl}
22 MCREATE=${MCREATE:-mcreate}
23 OPENFILE=${OPENFILE:-openfile}
24 OPENUNLINK=${OPENUNLINK:-openunlink}
25 TOEXCL=${TOEXCL:-toexcl}
26 TRUNCATE=${TRUNCATE:-truncate}
27 export TMP=${TMP:-/tmp}
28
29 if [ $UID -ne 0 ]; then
30         RUNAS_ID="$UID"
31         RUNAS=""
32 else
33         RUNAS_ID=${RUNAS_ID:-500}
34         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
35 fi
36
37 SAVE_PWD=$PWD
38
39 clean() {
40         echo -n "cln.."
41         sh llmountcleanup.sh ${FORCE} > /dev/null || exit 20
42 }
43 CLEAN=${CLEAN:-}
44
45 start() {
46         echo -n "mnt.."
47         sh llmount.sh > /dev/null || exit 10
48         echo "done"
49 }
50 START=${START:-}
51
52 log() {
53         echo "$*"
54         lctl mark "$*" 2> /dev/null || true
55 }
56
57 trace() {
58         log "STARTING: $*"
59         strace -o $TMP/$1.strace -ttt $*
60         RC=$?
61         log "FINISHED: $*: rc $RC"
62         return 1
63 }
64 TRACE=${TRACE:-""}
65
66 run_one() {
67         if ! mount | grep -q $DIR1; then
68                 $START
69         fi
70         BEFORE=`date +%s`
71         log "== test $1: $2= `date +%H:%M:%S` ($BEFORE)"
72         export TESTNAME=test_$1
73         export tfile=f${testnum}
74         export tdir=d${base}
75         test_$1 || error "test_$1: exit with rc=$?"
76         unset TESTNAME
77         pass "($((`date +%s` - $BEFORE))s)"
78         cd $SAVE_PWD
79         $CLEAN
80 }
81
82 run_test() {
83         for O in $ONLY; do
84                 if [ "`echo $1 | grep '\<'$O'[a-z]*\>'`" ]; then
85                         echo ""
86                         run_one $1 "$2"
87                         return $?
88                 else
89                         echo -n "."
90                 fi
91         done
92         for X in $EXCEPT $ALWAYS_EXCEPT $SANITYN_EXCEPT; do
93                 if [ "`echo $1 | grep '\<'$X'[a-z]*\>'`" ]; then
94                         echo "skipping excluded test $1"
95                         return 0
96                 fi
97         done
98         if [ -z "$ONLY" ]; then
99                 run_one $1 "$2"
100                 return $?
101         fi
102 }
103
104 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
105
106 error () {
107         log "FAIL: $TESTNAME $@"
108         if [ "$SANITYLOG" ]; then
109                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
110         else
111                 exit 1
112         fi
113 }
114
115 pass() {
116         echo PASS $@
117 }
118
119 export MOUNT1=`mount| awk '/ lustre/ { print $3 }'| head -n 1`
120 export MOUNT2=`mount| awk '/ lustre/ { print $3 }'| tail -n 1`
121 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
122 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
123 [ `mount| awk '/ lustre/ { print $3 }'| wc -l` -ne 2 ] && \
124         error "NAME=$NAME mounted more than twice"
125
126 export DIR1=${DIR1:-$MOUNT1}
127 export DIR2=${DIR2:-$MOUNT2}
128 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
129 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
130
131 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
132
133 test_1a() {
134         touch $DIR1/f1
135         [ -f $DIR2/f1 ] || error
136 }
137 run_test 1a "check create on 2 mtpt's =========================="
138
139 test_1b() {
140         chmod 777 $DIR2/f1
141         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
142         chmod a-x $DIR2/f1
143 }
144 run_test 1b "check attribute updates on 2 mtpt's ==============="
145
146 test_1c() {
147         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
148 }
149 run_test 1c "check after remount attribute updates on 2 mtpt's ="
150
151 test_1d() {
152         rm $DIR2/f1
153         $CHECKSTAT -a $DIR1/f1 || error
154 }
155 run_test 1d "unlink on one mountpoint removes file on other ===="
156
157 test_2a() {
158         touch $DIR1/f2a
159         ls -l $DIR2/f2a
160         chmod 777 $DIR2/f2a
161         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
162 }
163 run_test 2a "check cached attribute updates on 2 mtpt's ========"
164
165 test_2b() {
166         touch $DIR1/f2b
167         ls -l $DIR2/f2b
168         chmod 777 $DIR1/f2b
169         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
170 }
171 run_test 2b "check cached attribute updates on 2 mtpt's ========"
172
173 # NEED TO SAVE ROOT DIR MODE
174 test_2c() {
175         chmod 777 $DIR1
176         $CHECKSTAT -t dir -p 0777 $DIR2 || error
177 }
178 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
179
180 test_2d() {
181         chmod 755 $DIR1
182         $CHECKSTAT -t dir -p 0755 $DIR2 || error
183 }
184 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
185
186 test_3() {
187         ( cd $DIR1 ; ln -s this/is/good lnk )
188         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
189                 error
190 }
191 run_test 3 "symlink on one mtpt, readlink on another ==========="
192
193 test_4() {
194         multifstat $DIR1/f4 $DIR2/f4
195 }
196 run_test 4 "fstat validation on multiple mount points =========="
197
198 test_5() {
199         mcreate $DIR1/f5
200         truncate $DIR2/f5 100
201         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
202         rm $DIR1/f5
203 }
204 run_test 5 "create a file on one mount, truncate it on the other"
205
206 test_6() {
207         openunlink $DIR1/f6 $DIR2/f6 || error
208 }
209 run_test 6 "remove of open file on other node =================="
210
211 test_7() {
212         opendirunlink $DIR1/d7 $DIR2/d7 || error
213 }
214 run_test 7 "remove of open directory on other node ============="
215
216 test_8() {
217         opendevunlink $DIR1/dev8 $DIR2/dev8 || error
218 }
219 run_test 8 "remove of open special file on other node =========="
220
221 test_9() {
222         MTPT=1
223         > $DIR2/f9
224         for C in a b c d e f g h i j k l; do
225                 DIR=`eval echo \\$DIR$MTPT`
226                 echo -n $C >> $DIR/f9
227                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
228         done
229         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
230                 error "`od -a $DIR1/f9` != abcdefghijkl"
231 }
232 run_test 9 "append of file with sub-page size on multiple mounts"
233
234 test_10a() {
235         MTPT=1
236         OFFSET=0
237         > $DIR2/f10
238         for C in a b c d e f g h i j k l; do
239                 DIR=`eval echo \\$DIR$MTPT`
240                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
241                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
242                 OFFSET=`expr $OFFSET + 1`
243         done
244         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
245                 error "`od -a $DIR1/f10` != abcdefghijkl"
246 }
247 run_test 10a "write of file with sub-page size on multiple mounts "
248
249 test_10b() {
250         yes "R" | dd of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
251
252         truncate $DIR1/f10b 4096 || error "truncate 4096"
253
254         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
255
256         # create a test file locally to compare
257         yes "R" | dd of=$TMP/f10b bs=3k count=1 || error "dd random"
258         truncate $TMP/f10b 4096 || error "truncate 4096"
259         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
260         rm $TMP/f10b $TMP/f10b-lustre
261 }
262 run_test 10b "write of file with sub-page size on multiple mounts "
263
264 test_11() {
265         mkdir $DIR1/d11
266         multiop $DIR1/d11/f O_c &
267         MULTIPID=$!
268         usleep 200
269         cp -p /bin/ls $DIR1/d11/f
270         $DIR2/d11/f
271         RC=$?
272         kill -USR1 $MULTIPID
273         wait $MULTIPID || error
274         [ $RC -eq 0 ] && error || true
275 }
276 run_test 11 "execution of file opened for write should return error ===="
277
278 test_12() {
279        sh lockorder.sh
280 }
281 run_test 12 "test lock ordering (link, stat, unlink) ==========="
282
283 test_13() {     # bug 2451 - directory coherency
284        rm -rf $DIR1/d13
285        mkdir $DIR1/d13 || error
286        cd $DIR1/d13 || error
287        ls
288        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
289        ls
290        rm -f $DIR2/d13/f13 || error
291        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
292        # need to run it twice
293        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
294        ls
295        rm -f $DIR2/d13/f13 || error
296        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
297 }
298 run_test 13 "test directory page revocation ===================="
299
300 test_14() {
301         mkdir $DIR1/d14
302         cp -p /bin/ls $DIR1/d14/ls
303         exec 100>> $DIR1/d14/ls
304         $DIR2/d14/ls && error || true
305         exec 100<&-
306 }
307 run_test 14 "execution of file open for write returns -ETXTBSY ="
308
309 test_14a() {
310         mkdir -p $DIR1/d14
311         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
312         $DIR1/d14/multiop $TMP/test14.junk O_c &
313         MULTIPID=$!
314         sleep 1
315         multiop $DIR2/d14/multiop Oc && error "expected error, got success"
316         kill -USR1 $MULTIPID || return 2
317         wait $MULTIPID || return 3
318         rm $TMP/test14.junk
319 }
320 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
321
322 test_14b() { # bug 3192
323         mkdir -p $DIR1/d14
324         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
325         $DIR1/d14/multiop $TMP/test14.junk O_c &
326         MULTIPID=$!
327         sleep 1
328         truncate $DIR2/d14/multiop 0 && error "expected error, got success"
329         kill -USR1 $MULTIPID || return 2
330         wait $MULTIPID || return 3
331         rm $TMP/test14.junk
332 }
333 run_test 14b "truncate of executing file returns -ETXTBSY ======"
334
335 test_14c() { # bug 3430
336         mkdir -p $DIR1/d14
337         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
338         $DIR1/d14/multiop $TMP/test14.junk O_c &
339         MULTIPID=$!
340         sleep 1
341         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
342         kill -USR1 $MULTIPID || return 2
343         wait $MULTIPID || return 3
344         #cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
345         rm $TMP/test14.junk
346 }
347 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
348
349 test_15() {     # bug 974 - ENOSPC
350         echo $PATH
351         sh oos2.sh $MOUNT1 $MOUNT2
352 }
353 run_test 15 "test out-of-space with multiple writers ==========="
354
355 test_16() {
356         fsx -c 50 -p 100 -N 2500 -S 0 $MOUNT1/fsxfile $MOUNT2/fsxfile
357 }
358 run_test 16 "2500 iterations of dual-mount fsx ================="
359
360 cancel_lru_locks() {
361         for d in /proc/fs/lustre/ldlm/namespaces/$1*; do
362                 echo clear > $d/lru_size
363         done
364         grep "[0-9]" /proc/fs/lustre/ldlm/namespaces/$1*/lock_unused_count /dev/null
365 }
366
367 test_17() { # bug 3513, 3667
368         [ ! -d /proc/fs/lustre/ost ] && echo "skipping OST-only test" && return
369
370         cp /etc/termcap $DIR1/f17
371         cancel_lru_locks OSC > /dev/null
372         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
373         echo 0x8000030a > /proc/sys/lustre/fail_loc
374         ls -ls $DIR1/f17 | awk '{ print $1,$6 }' > $DIR1/f17-1 & \
375         ls -ls $DIR2/f17 | awk '{ print $1,$6 }' > $DIR2/f17-2
376         wait
377         diff -u $DIR1/f17-1 $DIR2/f17-2 || error "files are different"
378 }
379 run_test 17 "resource creation/LVB creation race ==============="
380
381 test_18() {
382         ./mmap_sanity -d $MOUNT1 -m $MOUNT2
383         sync; sleep 1; sync
384 }
385 run_test 18 "mmap sanity check ================================="
386
387 test_19() { # bug3811
388         [ -d /proc/fs/lustre/obdfilter ] || return 0
389
390         MAX=`cat /proc/fs/lustre/obdfilter/*/readcache_max_filesize | head -n 1`
391         for O in /proc/fs/lustre/obdfilter/OST*; do
392                 echo 4096 > $O/readcache_max_filesize
393         done
394         dd if=/dev/urandom of=$TMP/f19b bs=512k count=32
395         SUM=`cksum $TMP/f19b | cut -d" " -f 1,2`
396         cp $TMP/f19b $DIR1/f19b
397         for i in `seq 1 20`; do
398                 [ $((i % 5)) -eq 0 ] && log "test_18 loop $i"
399                 cancel_lru_locks OSC > /dev/null
400                 cksum $DIR1/f19b | cut -d" " -f 1,2 > $TMP/sum1 & \
401                 cksum $DIR2/f19b | cut -d" " -f 1,2 > $TMP/sum2
402                 wait
403                 [ "`cat $TMP/sum1`" = "$SUM" ] || \
404                         error "$DIR1/f19b `cat $TMP/sum1` != $SUM"
405                 [ "`cat $TMP/sum2`" = "$SUM" ] || \
406                         error "$DIR2/f19b `cat $TMP/sum2` != $SUM"
407         done
408         for O in /proc/fs/lustre/obdfilter/OST*; do
409                 echo $MAX > $O/readcache_max_filesize
410         done
411         rm $DIR1/f19b
412 }
413 #run_test 19 "test concurrent uncached read races ==============="
414
415 test_20() {
416         mkdir $DIR1/d20
417         cancel_lru_locks OSC
418         CNT=$((`cat /proc/fs/lustre/llite/fs0/dump_page_cache | wc -l`))
419         multiop $DIR1/f20 Ow8190c
420         multiop $DIR2/f20 Oz8194w8190c
421         multiop $DIR1/f20 Oz0r8190c
422         cancel_lru_locks OSC
423         CNTD=$((`cat /proc/fs/lustre/llite/fs0/dump_page_cache | wc -l` - $CNT))
424         [ $CNTD -gt 0 ] && \
425             error $CNTD" page left in cache after lock cancel" || true
426 }
427 run_test 20 "test extra readahead page left in cache ===="
428
429 cleanup_21() {
430         trap 0
431         umount $DIR1/d21
432 }
433
434 test_21() { # Bug 5907
435         mkdir $DIR1/d21
436         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
437         trap cleanup_21 EXIT
438         rmdir -v $DIR1/d21 && error "Removed mounted directory"
439         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
440         test -d $DIR1/d21 || error "Mounted directory disappeared"
441         cleanup_21
442         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
443         true
444 }
445 run_test 21 " Try to remove mountpoint on another dir ===="
446
447 JOIN=${JOIN:-"lfs join"}
448
449 test_22() { # Bug 9926
450         mkdir $DIR1/d21
451         dd if=/dev/urandom of=$DIR1/d21/128k bs=1024 count=128
452         cp -p $DIR1/d21/128k $DIR1/d21/f_head
453         for ((i=0;i<10;i++)); do
454                 cp -p $DIR1/d21/128k $DIR1/d21/f_tail
455                 $JOIN $DIR1/d21/f_head $DIR1/d21/f_tail || error "join error"
456                 $CHECKSTAT -a $DIR1/d21/f_tail || error "tail file exist after join"
457         done
458         echo aaaaaaaaaaa >> $DIR1/d21/no_joined
459
460         mv $DIR2/d21/f_head $DIR2/
461         munlink $DIR2/f_head || error "unlink joined file error"
462         cat $DIR2/d21/no_joined || error "cat error"
463         rm -rf $DIR2/d21/no_joined || error "unlink normal file error"
464 }
465 run_test 22 " After joining in one dir,  open/close unlink file in anther dir" 
466
467 log "cleanup: ======================================================"
468 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
469
470 echo '=========================== finished ==============================='
471 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true