Whamcloud - gitweb
b=3031
[fs/lustre-release.git] / lustre / tests / sanity-gns.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
11 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
12
13 SRCDIR=`dirname $0`
14 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
15 export SECURITY=${SECURITY:-"null"}
16
17 TMP=${TMP:-/tmp}
18 FSTYPE=${FSTYPE:-ext3}
19
20 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
21 CREATETEST=${CREATETEST:-createtest}
22 LFS=${LFS:-lfs}
23 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
24 LFIND=${LFIND:-"$LFS find"}
25 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
26 LCTL=${LCTL:-lctl}
27 MCREATE=${MCREATE:-mcreate}
28 OPENFILE=${OPENFILE:-openfile}
29 OPENUNLINK=${OPENUNLINK:-openunlink}
30 TOEXCL=${TOEXCL:-toexcl}
31 TRUNCATE=${TRUNCATE:-truncate}
32 MUNLINK=${MUNLINK:-munlink}
33 SOCKETSERVER=${SOCKETSERVER:-socketserver}
34 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
35 IOPENTEST1=${IOPENTEST1:-iopentest1}
36 IOPENTEST2=${IOPENTEST2:-iopentest2}
37 PTLDEBUG=${PTLDEBUG:-0}
38
39 . krb5_env.sh
40
41 if [ $UID -ne 0 ]; then
42         RUNAS_ID="$UID"
43         RUNAS=""
44 else
45         RUNAS_ID=${RUNAS_ID:-500}
46         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
47 fi
48
49 if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
50     start_krb5_kdc || exit 1
51     if [ $RUNAS_ID -ne $UID ]; then
52         $RUNAS ./krb5_refresh_cache.sh || exit 2
53     fi
54 fi
55
56 export NAME=${NAME:-local}
57
58 SAVE_PWD=$PWD
59
60 clean() {
61         echo -n "cln.."
62         sh llmountcleanup.sh > /dev/null || exit 20
63         I_MOUNTED=no
64 }
65 CLEAN=${CLEAN:-clean}
66
67 start() {
68         echo -n "mnt.."
69         sh llrmount.sh > /dev/null || exit 10
70         I_MOUNTED=yes
71         echo "done"
72 }
73 START=${START:-start}
74
75 log() {
76         echo "$*"
77         lctl mark "$*" 2> /dev/null || true
78 }
79
80 trace() {
81         log "STARTING: $*"
82         strace -o $TMP/$1.strace -ttt $*
83         RC=$?
84         log "FINISHED: $*: rc $RC"
85         return 1
86 }
87 TRACE=${TRACE:-""}
88
89 check_kernel_version() {
90         VERSION_FILE=/proc/fs/lustre/kernel_version
91         WANT_VER=$1
92         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
93         GOT_VER=`cat $VERSION_FILE`
94         [ $GOT_VER -ge $WANT_VER ] && return 0
95         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
96         return 1
97 }
98
99 run_one() {
100         if ! mount | grep -q $DIR; then
101                 $START
102         fi
103         echo $PTLDEBUG >/proc/sys/portals/debug 
104         log "== test $1: $2"
105         export TESTNAME=test_$1
106         test_$1 || error "test_$1: exit with rc=$?"
107         unset TESTNAME
108         pass
109         cd $SAVE_PWD
110         $CLEAN
111 }
112
113 build_test_filter() {
114         for O in $ONLY; do
115             eval ONLY_${O}=true
116         done
117         for E in $EXCEPT $ALWAYS_EXCEPT; do
118             eval EXCEPT_${E}=true
119         done
120 }
121
122 _basetest() {
123     echo $*
124 }
125
126 basetest() {
127     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
128 }
129
130 run_test() {
131          base=`basetest $1`
132          if [ "$ONLY" ]; then
133                  testname=ONLY_$1
134                  if [ ${!testname}x != x ]; then
135                         run_one $1 "$2"
136                         return $?
137                  fi
138                  testname=ONLY_$base
139                  if [ ${!testname}x != x ]; then
140                          run_one $1 "$2"
141                          return $?
142                  fi
143                  echo -n "."
144                  return 0
145         fi
146         testname=EXCEPT_$1
147         if [ ${!testname}x != x ]; then
148                  echo "skipping excluded test $1"
149                  return 0
150         fi
151         testname=EXCEPT_$base
152         if [ ${!testname}x != x ]; then
153                  echo "skipping excluded test $1 (base $base)"
154                  return 0
155         fi
156         run_one $1 "$2"
157         return $?
158 }
159
160 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
161
162 error() { 
163         log "FAIL: $@"
164         if [ "$SANITYLOG" ]; then
165                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
166         else
167                 exit 1
168         fi
169 }
170
171 pass() { 
172         echo PASS
173 }
174
175 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
176 if [ -z "$MOUNT" ]; then
177         sh llmount.sh
178         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
179         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
180         I_MOUNTED=yes
181 fi
182
183 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
184
185 DIR=${DIR:-$MOUNT}
186 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
187
188 rm -rf $DIR/[Rdfs][1-9]*
189 build_test_filter
190
191 echo preparing for tests involving mounts
192 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
193 touch $EXT2_DEV
194 mke2fs -j -F $EXT2_DEV 8000 >/dev/null 2>&1
195
196 find_free_loop() {
197     local LOOP_DEV=""
198     test -b /dev/loop0 && 
199         base="/dev/loop" || base="/dev/loop/"
200
201     for ((i=0;i<256;i++)); do
202         test -b $base$i || continue
203         
204         losetup $base$i >/dev/null 2>&1 || {
205             LOOP_DEV="$base$i"
206             break
207         }
208     done
209     echo $LOOP_DEV
210 }
211
212 setup_loop() {
213     local LOOP_DEV=$1
214     local LOOP_FILE=$2
215     
216     dd if=/dev/zero of=$LOOP_FILE bs=1M count=10 2>/dev/null || return $?
217
218     losetup $LOOP_DEV $LOOP_FILE || {
219         rc=$?
220         cleanup_loop $LOOP_DEV $LOOP_FILE
221         return $rc
222     }
223     
224     mke2fs -F $LOOP_DEV >/dev/null 2>&1 || {
225         rc=$?
226         cleanup_loop $LOOP_DEV $LOOP_FILE
227         echo "cannot create test ext2 fs on $LOOP_DEV"
228         return $?
229     }
230     return 0
231 }
232
233 cleanup_loop() {
234     local LOOP_DEV=$1
235     local LOOP_FILE=$2
236     
237     losetup -d $LOOP_DEV >/dev/null 2>&1
238     rm -fr $LOOP_FILE >/dev/null 2>&1
239 }
240
241 setup_upcall() {
242     local INJECTION=""
243     local UPCALL=$1
244     local MODE=$2
245     local LOG=$3
246     local BG=$4
247     
248     test "x$BG" = "xBACKGROUND" && 
249         BG="&" || BG=""
250     
251     test "x$MODE" = "xDEADLOCK" &&
252         INJECTION="touch \$MNTPATH/file"
253     
254     cat > $UPCALL <<- EOF
255 #!/bin/sh
256
257 MOUNT=\`which mount 2>/dev/null\`
258 test "x\$MOUNT" = "x" && MOUNT="/bin/mount"
259
260 OPTIONS=\$1
261 MNTPATH=\$2
262
263 test "x\$OPTIONS" = "x" || "x\$MNTPATH" = "x" &&
264 exit 1
265
266 $INJECTION
267 \$MOUNT \$OPTIONS \$MNTPATH > $LOG 2>&1 $BG
268 exit \$?
269 EOF
270     chmod +x $UPCALL
271     return $?
272 }
273
274 cleanup_upcall() {
275     local UPCALL=$1
276     rm -fr $UPCALL
277 }
278
279 show_log() {
280     local LOG=$1
281     
282     test -f $LOG && {
283         echo "======================== upcall log ==========================="
284         cat $LOG
285         echo "==============================================================="
286     }
287 }
288
289 check_mnt()
290 {
291     local OBJECT=$1
292     local mnt=""
293     local p=""
294     
295     mnt="`cat /proc/mounts | grep $OBJECT | awk '{print \$2}'`"
296     test -z "$mnt" && return 1
297     
298     for p in $mnt; do
299         test "x$p" = "x$OBJECT" || return 1
300     done
301     
302     return 0
303 }
304
305 check_gns() {
306     local LOG="/tmp/gns-log"
307     local UPCALL_PATH=""
308     
309     local UPCALL=$1
310     local OBJECT1=$2
311     local OBJECT2=$3
312     local TIMOUT=$4
313     local TICK=$5
314     local MODE=$6
315     local BG=$7
316     
317     rm -fr $LOG >/dev/null 2>&1
318     UPCALL_PATH="/tmp/gns-upcall-$UPCALL.sh"
319     
320     echo "generating upcall $UPCALL_PATH"
321     setup_upcall $UPCALL_PATH $UPCALL $LOG $BG || return $rc
322
323     echo "======================== upcall script ==========================="
324     cat $UPCALL_PATH 2>/dev/null || return $?
325     echo "=================================================================="
326    
327     echo "$UPCALL_PATH" > /proc/fs/lustre/llite/fs0/gns_upcall || return $?
328     echo "upcall:  $(cat /proc/fs/lustre/llite/fs0/gns_upcall)"
329
330     case "$MODE" in
331         GENERIC)
332             echo -n "mount on open $OBJECT1/test_file1 (generic): "
333             echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1 || return $?
334             ;;
335         CONCUR1)
336             local i=1
337             local nr=20
338         
339             echo -n "mount on open $OBJECT1/test_file1 ($nr threads): "
340             for ((;i<=$nr;i++)); do 
341                 echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
342             done
343         
344             wait
345             
346             local RETVAL=$?
347             
348             [ $RETVAL -eq 0 ] || 
349                 return $RETVAL
350             ;;
351         CONCUR2)
352             test "x$OBJECT2" = "x" && {
353                 echo "not defined object2 for concurrent2 testing"
354                 return 1
355             }
356             echo -n "mount on open $OBJECT1/test_file1: "
357             echo -n "mount on open $OBJECT2/test_file1: "
358             echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1 &
359             echo -n "test data" > $OBJECT2/test_file1 >/dev/null 2>&1 &
360             
361             wait
362             
363             local RETVAL=$?
364             
365             [ $RETVAL -eq 0 ] || 
366                 return $RETVAL
367             ;;
368         CONCUR3)
369             echo -n "mount on open $OBJECT1/test_file1: "
370             
371             local i=1
372             local nr=20
373             
374             for ((;i<$nr;i++)); do
375                 touch $OBJECT1/file$i &
376                 echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
377                 mkdir $OBJECT1/dir$i &
378             done
379
380             wait
381             
382             local RETVAL=$?
383             
384             [ $RETVAL -eq 0 ] || 
385                 return $RETVAL
386             ;;
387         *)
388             echo "invalid testing mode $MODE"
389             return 1
390     esac
391     
392     check_mnt $OBJECT1 || {
393         echo "fail"
394         show_log $LOG
395         return 1
396     }
397     
398     if test "x$MODE" = "xCONCUR2"; then
399         check_mnt $OBJECT2 || {
400             echo "fail"
401             show_log $LOG
402             return 1
403         }
404     fi
405     
406     echo "success"
407
408     local sleep_time=$TIMOUT
409     let sleep_time+=$TICK*2
410     echo -n "waiting for umount ${sleep_time}s (timeout + tick*2): "
411     sleep $sleep_time
412     
413     check_mnt $OBJECT1 && {
414         echo "failed"
415         return 2
416     }
417     
418     if test "x$MODE" = "xCONCUR2"; then
419         check_mnt $OBJECT2 && {
420             echo "failed"
421             return 2
422         }
423     fi
424     
425     echo "success"
426     cleanup_upcall $UPCALL_PATH
427     return 0
428 }
429
430 setup_object() {
431     local OBJPATH=$1
432     local OBJECT=$2
433     local CONTENT=$3
434     
435     mkdir -p $OBJPATH || return $?
436     echo -n $CONTENT > $OBJPATH/$OBJECT || return $?
437     
438     echo "======================== mount object ==========================="
439     cat $OBJPATH/$OBJECT
440     echo ""
441     echo "================================================================="
442     
443     chmod u+s $OBJPATH
444     return $?
445 }
446
447 cleanup_object() {
448     local OBJPATH=$1
449
450     chmod u-s $OBJPATH
451     umount $OBJPATH >/dev/null 2>&1
452     rm -fr $OBJPATH >/dev/null 2>&1
453 }
454
455 setup_gns() {
456     local OBJECT=$1
457     local TIMOUT=$2
458     local TICK=$3
459
460     echo "$OBJECT" > /proc/fs/lustre/llite/fs0/gns_object_name || error
461     echo "$TIMOUT" > /proc/fs/lustre/llite/fs0/gns_timeout || error
462     echo "$TICK" > /proc/fs/lustre/llite/fs0/gns_tick || error
463
464     echo ""
465     echo "timeout: $(cat /proc/fs/lustre/llite/fs0/gns_timeout)s"
466     echo "object:  $(cat /proc/fs/lustre/llite/fs0/gns_object_name)"
467     echo "tick:    $(cat /proc/fs/lustre/llite/fs0/gns_tick)s"
468     echo ""
469
470 }
471
472 enable_gns()
473 {
474     echo "1" > /proc/fs/lustre/llite/fs0/gns_enabled || error
475     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x1" || error
476 }
477
478 disable_gns()
479 {
480     echo "0" > /proc/fs/lustre/llite/fs0/gns_enabled || error
481     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x0" || error
482 }
483
484 test_1a() {
485     local LOOP_DEV=$(find_free_loop 2>/dev/null)
486     local LOOP_FILE="/tmp/gns_loop_1a"
487     local OBJECT=".mntinfo"
488     local TIMOUT=5
489     local TICK=1
490
491     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
492         error "can't find free loop device"
493
494     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
495     cleanup_loop $LOOP_DEV $LOOP_FILE
496     setup_loop $LOOP_DEV $LOOP_FILE || error
497
498     echo "setting up GNS timeouts and mount object..."
499     setup_gns $OBJECT $TIMOUT $TICK || error
500     
501     disable_gns
502
503     echo "preparing mount object at $DIR/gns_test_1a/$OBJECT..."
504     setup_object $DIR/gns_test_1a $OBJECT "-t ext2 $LOOP_DEV" || error
505
506     enable_gns
507
508     echo ""
509     echo "testing GNS with GENERIC upcall 3 times on the row"
510     
511     for ((i=0;i<3;i++)); do
512         check_gns GENERIC $DIR/gns_test_1a $DIR/gns_test_1a $TIMOUT $TICK GENERIC || {
513             disable_gns
514             cleanup_object $DIR/gns_test_1a
515             cleanup_loop $LOOP_DEV $LOOP_FILE
516             error
517         }
518     done
519     
520     disable_gns
521
522     cleanup_object $DIR/gns_test_1a
523     cleanup_loop $LOOP_DEV $LOOP_FILE
524 }
525
526 run_test 1a " general GNS test - mount/umount (GENERIC) ================"
527
528 test_1b() {
529     local LOOP_DEV=$(find_free_loop 2>/dev/null)
530     local LOOP_FILE="/tmp/gns_loop_1b"
531     local OBJECT=".mntinfo"
532     local TIMOUT=5
533     local TICK=1
534
535     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
536         error "can't find free loop device"
537
538     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
539     cleanup_loop $LOOP_DEV $LOOP_FILE
540     setup_loop $LOOP_DEV $LOOP_FILE || error
541
542     echo "setting up GNS timeouts and mount object..."
543     setup_gns $OBJECT $TIMOUT $TICK || error
544
545     disable_gns
546     
547     echo "preparing mount object at $DIR/gns_test_1b/$OBJECT..."
548     setup_object $DIR/gns_test_1b $OBJECT "-t ext2 $LOOP_DEV" || error
549     
550     enable_gns
551
552     echo ""
553     echo "testing GNS with DEADLOCK upcall 3 times on the row"
554     
555     for ((i=0;i<3;i++)); do
556         check_gns DEADLOCK $DIR/gns_test_1b $DIR/gns_test_1b $TIMOUT $TICK GENERIC || {
557             disable_gns
558             cleanup_object $DIR/gns_test_1b
559             cleanup_loop $LOOP_DEV $LOOP_FILE
560             error
561         }
562     done
563     
564     disable_gns
565
566     cleanup_object $DIR/gns_test_1b
567     cleanup_loop $LOOP_DEV $LOOP_FILE
568 }
569
570 run_test 1b " general GNS test - mount/umount (DEADLOCK) ==============="
571
572 test_1c() {
573     local LOOP_DEV=$(find_free_loop 2>/dev/null)
574     local LOOP_FILE="/tmp/gns_loop_1c"
575     local OBJECT=".mntinfo"
576     local TIMOUT=5
577     local TICK=1
578
579     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
580         error "can't find free loop device"
581
582     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
583     cleanup_loop $LOOP_DEV $LOOP_FILE
584     setup_loop $LOOP_DEV $LOOP_FILE || error
585
586     echo "setting up GNS timeouts and mount object..."
587     setup_gns $OBJECT $TIMOUT $TICK || error
588
589     disable_gns
590
591     echo "preparing mount object at $DIR/gns_test_1c/$OBJECT..."
592     setup_object $DIR/gns_test_1c $OBJECT "-t ext2 $LOOP_DEV" || error
593
594     enable_gns
595
596     echo ""
597     echo "testing GNS with GENERIC/DEADLOCK upcall 4 times on the row in GENERIC mode"
598     local i=0
599     
600     for ((;i<4;i++)); do
601         local MODE="GENERIC"
602         
603         test $(($i%2)) -eq 1 && MODE="DEADLOCK"
604         
605         check_gns $MODE $DIR/gns_test_1c $DIR/gns_test_1c $TIMOUT $TICK GENERIC || {
606             disable_gns
607             cleanup_object $DIR/gns_test_1c
608             cleanup_loop $LOOP_DEV $LOOP_FILE
609             error
610         }
611     done
612     
613     disable_gns
614
615     cleanup_object $DIR/gns_test_1c
616     cleanup_loop $LOOP_DEV $LOOP_FILE
617 }
618
619 run_test 1c " general GNS test - mount/umount (GENERIC/DEADLOCK) ========"
620
621 test_1d() {
622     local LOOP_DEV=$(find_free_loop 2>/dev/null)
623     local LOOP_FILE="/tmp/gns_loop_1d"
624     local OBJECT=".mntinfo"
625     local TIMOUT=5
626     local TICK=1
627
628     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
629         error "can't find free loop device"
630
631     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
632     cleanup_loop $LOOP_DEV $LOOP_FILE
633     setup_loop $LOOP_DEV $LOOP_FILE || error
634
635     echo "setting up GNS timeouts and mount object..."
636     setup_gns $OBJECT $TIMOUT $TICK || error
637
638     disable_gns
639
640     echo "preparing mount object at $DIR/gns_test_1d/$OBJECT..."
641     setup_object $DIR/gns_test_1d $OBJECT "-t ext2 $LOOP_DEV" || error
642
643     enable_gns
644
645     echo ""
646     echo "testing GNS with GENERIC/DEADLOCK upcall 4 times on the row in CONCUR1 mode"
647     local i=0
648     
649     for ((;i<4;i++)); do
650         local MODE="GENERIC"
651         
652         test $(($i%2)) -eq 1 && MODE="DEADLOCK"
653         
654         check_gns $MODE $DIR/gns_test_1d $DIR/gns_test_1d $TIMOUT $TICK CONCUR1 || {
655             disable_gns
656             cleanup_object $DIR/gns_test_1d
657             cleanup_loop $LOOP_DEV $LOOP_FILE
658             error
659         }
660     done
661     
662     disable_gns
663
664     cleanup_object $DIR/gns_test_1d
665     cleanup_loop $LOOP_DEV $LOOP_FILE
666 }
667
668 run_test 1d " general GNS test - concurrent mount ======================="
669
670 test_1e() {
671     local LOOP_DEV=$(find_free_loop 2>/dev/null)
672     local LOOP_FILE="/tmp/gns_loop_1e"
673     local OBJECT=".mntinfo"
674     local TIMOUT=5
675     local TICK=1
676
677     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
678         error "can't find free loop device"
679
680     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
681     cleanup_loop $LOOP_DEV $LOOP_FILE
682     setup_loop $LOOP_DEV $LOOP_FILE || error
683
684     echo "setting up GNS timeouts and mount object..."
685     setup_gns $OBJECT $TIMOUT $TICK || error
686
687     disable_gns
688
689     echo "preparing mount object at $DIR/gns_test_1e1/$OBJECT..."
690     setup_object $DIR/gns_test_1e1 $OBJECT "-t ext2 $LOOP_DEV" || error
691     
692     echo "preparing mount object at $DIR/gns_test_1e2/$OBJECT..."
693     setup_object $DIR/gns_test_1e2 $OBJECT "-t ext2 $LOOP_DEV" || error
694
695     enable_gns
696
697     echo ""
698     echo "testing GNS with GENERIC upcall in CONCUR2 mode"
699     
700     check_gns GENERIC $DIR/gns_test_1e1 $DIR/gns_test_1e2 $TIMOUT $TICK CONCUR2 || {
701         disable_gns
702         cleanup_object $DIR/gns_test_1e1
703         cleanup_object $DIR/gns_test_1e2
704         cleanup_loop $LOOP_DEV $LOOP_FILE
705         error
706     }
707     
708     disable_gns
709
710     cleanup_object $DIR/gns_test_1e1
711     cleanup_object $DIR/gns_test_1e2
712     cleanup_loop $LOOP_DEV $LOOP_FILE
713 }
714
715 run_test 1e " general GNS test - concurrent mount of 2 GNS mounts ======="
716
717 test_2a() {
718     local OBJECT=".mntinfo"
719     local TIMOUT=5
720     local TICK=1
721
722     echo "setting up GNS timeouts and mount object..."
723     setup_gns $OBJECT $TIMOUT $TICK || error
724
725     disable_gns
726
727     echo "preparing mount object at $DIR/gns_test_2a/$OBJECT..."
728     mkdir -p $DIR/gns_test_2a
729     ln -s $DIR/gns_test_2a $DIR/gns_test_2a/$OBJECT
730     chmod u+s $DIR/gns_test_2a
731     
732     enable_gns
733
734     echo ""
735     echo "testing GNS with GENERIC upcall"
736     
737     check_gns GENERIC $DIR/gns_test_2a $DIR/gns_test_2a $TIMOUT $TICK GENERIC && {
738         disable_gns
739         chmod u-s $DIR/gns_test_2a
740         rm -fr $DIR/gns_test_2a
741         error "symlink as mount object works?"
742     }
743     
744     disable_gns
745     chmod u-s $DIR/gns_test_2a
746     rm -fr $DIR/gns_test_2a
747 }
748
749 run_test 2a " odd conditions (mount object is symlink) ============="
750
751 test_2b() {
752     local OBJECT=".mntinfo"
753     local TIMOUT=5
754     local TICK=1
755
756     echo "setting up GNS timeouts and mount object..."
757     setup_gns $OBJECT $TIMOUT $TICK || error
758
759     disable_gns
760
761     echo "preparing mount object at $DIR/gns_test_2b/$OBJECT..."
762     mkdir -p $DIR/gns_test_2b/$OBJECT
763     chmod u+s $DIR/gns_test_2b
764     
765     enable_gns
766     
767     echo ""
768     echo "testing GNS with GENERIC upcall"
769     
770     check_gns GENERIC $DIR/gns_test_2b $DIR/gns_test_2b $TIMOUT $TICK GENERIC && {
771         disable_gns
772         chmod u-s $DIR/gns_test_2b
773         rm -fr $DIR/gns_test_2b
774         error "dir as mount object works?"
775     }
776     
777     disable_gns
778     chmod u-s $DIR/gns_test_2b
779     rm -fr $DIR/gns_test_2b
780 }
781
782 run_test 2b " odd conditions (mount object is directory) ==========="
783
784 test_2c() {
785     local OBJECT=".mntinfo"
786     local TIMOUT=5
787     local TICK=1
788
789     echo "setting up GNS timeouts and mount object..."
790     setup_gns $OBJECT $TIMOUT $TICK || error
791
792     disable_gns
793
794     echo "preparing mount object at $DIR/gns_test_2c/$OBJECT..."
795     mkdir -p $DIR/gns_test_2c/$OBJECT/$OBJECT/$OBJECT/$OBJECT
796     chmod u+s -R $DIR/gns_test_2c
797     
798     enable_gns
799     
800     echo ""
801     echo "testing GNS with GENERIC upcall"
802     
803     check_gns GENERIC $DIR/gns_test_2c $DIR/gns_test_2c $TIMOUT $TICK GENERIC && {
804         disable_gns
805         chmod u-s -R $DIR/gns_test_2c
806         rm -fr $DIR/gns_test_2c
807         error "recursive mounting of dir as mount object works?"
808     }
809     
810     disable_gns
811     chmod u-s $DIR/gns_test_2c
812     rm -fr $DIR/gns_test_2c
813 }
814
815 run_test 2c " odd conditions (mount object is recursive dir) ======="
816
817 test_2d() {
818     local OBJECT=".mntinfo"
819     local TIMOUT=5
820     local TICK=1
821
822     echo "setting up GNS timeouts and mount object..."
823     setup_gns $OBJECT $TIMOUT $TICK || error
824
825     disable_gns
826
827     echo "preparing mount object at $DIR/gns_test_2d/$OBJECT..."
828     mkdir -p $DIR/gns_test_2d
829     chmod u+s $DIR/gns_test_2d
830     
831     enable_gns
832
833     echo ""
834     echo "testing GNS with GENERIC upcall"
835     
836     check_gns GENERIC $DIR/gns_test_2d $DIR/gns_test_2d $TIMOUT $TICK GENERIC && {
837         disable_gns
838         chmod u-s $DIR/gns_test_2d
839         rm -fr $DIR/gns_test_2d
840         error "mount point with absent mount object works?"
841     }
842     
843     disable_gns
844     chmod u-s $DIR/gns_test_2d
845     rm -fr $DIR/gns_test_2d
846 }
847
848 run_test 2d " odd conditions (mount object is absent) =============="
849
850 test_2e() {
851     local OBJECT=".mntinfo"
852     local TIMOUT=5
853     local TICK=1
854
855     echo "setting up GNS timeouts and mount object..."
856     setup_gns $OBJECT $TIMOUT $TICK || error
857
858     echo "." > /proc/fs/lustre/llite/fs0/gns_object_name
859     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x." && 
860         error "'.' is set as mount object name"
861
862     echo ".." > /proc/fs/lustre/llite/fs0/gns_object_name
863     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.." && 
864         error "'..' is set as mount object name"
865
866     echo ".a" > /proc/fs/lustre/llite/fs0/gns_object_name
867     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.a" || 
868         error "'.a' is not set as mount object name"
869
870     echo "..a" > /proc/fs/lustre/llite/fs0/gns_object_name
871     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x..a" || 
872         error "'..a' is not set as mount object name"
873 }
874
875 run_test 2e " odd conditions ('.' and '..' as mount object) ============="
876
877 test_2f() {
878     local LOOP_DEV=$(find_free_loop 2>/dev/null)
879     local LOOP_FILE="/tmp/gns_loop_2f"
880     local OBJECT=".mntinfo"
881     local TIMOUT=5
882     local TICK=1
883
884     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
885         error "can't find free loop device"
886
887     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
888     cleanup_loop $LOOP_DEV $LOOP_FILE
889     setup_loop $LOOP_DEV $LOOP_FILE || error
890
891     echo "setting up GNS timeouts and mount object..."
892     setup_gns $OBJECT $TIMOUT $TICK || error
893
894     disable_gns
895
896     echo "preparing mount object at $DIR/gns_test_2f/$OBJECT..."
897     setup_object $DIR/gns_test_2f $OBJECT "-t ext2 $LOOP_DEV" || error
898
899     enable_gns
900
901     echo ""
902     echo "testing GNS with DEADLOCK upcall in CONCUR3 mode"
903     
904     local MODE="DEADLOCK"
905         
906     check_gns $MODE $DIR/gns_test_2f $DIR/gns_test_2f $TIMOUT $TICK CONCUR3 || {
907         disable_gns
908         cleanup_object $DIR/gns_test_2f
909         cleanup_loop $LOOP_DEV $LOOP_FILE
910         error
911     }
912     
913     disable_gns
914
915     cleanup_object $DIR/gns_test_2f
916     cleanup_loop $LOOP_DEV $LOOP_FILE
917 }
918
919 run_test 2f " odd conditions (mount point is modifying during mount) ===="
920
921 test_2g() {
922     local LOOP_DEV=$(find_free_loop 2>/dev/null)
923     local LOOP_FILE="/tmp/gns_loop_2g"
924     local OBJECT=".mntinfo"
925     local TIMOUT=5
926     local TICK=1
927
928     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
929         error "can't find free loop device"
930
931     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
932     cleanup_loop $LOOP_DEV $LOOP_FILE
933     setup_loop $LOOP_DEV $LOOP_FILE || error
934
935     echo "setting up GNS timeouts and mount object..."
936     setup_gns $OBJECT $TIMOUT $TICK || error
937
938     disable_gns
939
940     echo "preparing mount object at $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT..."
941     setup_object $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
942 $OBJECT "-t ext2 $LOOP_DEV" || error
943     chmod u+s $DIR/gns_test_2g -R
944
945     enable_gns
946
947     echo ""
948     echo "testing GNS with DEADLOCK upcall in GENERIC mode"
949     
950     local MODE="DEADLOCK"
951         
952     check_gns $MODE $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
953 $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT $TIMOUT $TICK GENERIC || {
954         disable_gns
955         cleanup_object $DIR/gns_test_2g
956         cleanup_loop $LOOP_DEV $LOOP_FILE
957         error "recursive mount point does not work"
958     }
959     
960     disable_gns
961
962     chmod u-s $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT
963
964     enable_gns
965
966     check_gns $MODE $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
967 $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT $TIMOUT $TICK GENERIC && {
968         disable_gns
969         cleanup_object $DIR/gns_test_2g
970         cleanup_loop $LOOP_DEV $LOOP_FILE
971         error "GNS works whereas mount point is not SUID marked dir"
972     }
973
974     disable_gns
975
976     cleanup_object $DIR/gns_test_2g
977     cleanup_loop $LOOP_DEV $LOOP_FILE
978 }
979
980 run_test 2g " odd conditions (mount point is recursive marked SUID dir) ="
981
982 test_2h() {
983     local LOOP_DEV=$(find_free_loop 2>/dev/null)
984     local LOOP_FILE="/tmp/gns_loop_2h"
985     local OBJECT=".mntinfo"
986     local TIMOUT=5
987     local TICK=1
988
989     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
990         error "can't find free loop device"
991
992     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
993     cleanup_loop $LOOP_DEV $LOOP_FILE
994     setup_loop $LOOP_DEV $LOOP_FILE || error
995
996     echo "setting up GNS timeouts and mount object..."
997     setup_gns $OBJECT $TIMOUT $TICK || error
998
999     disable_gns
1000
1001     echo "preparing mount object at $DIR/gns_test_2h/$OBJECT..."
1002     setup_object $DIR/gns_test_2h $OBJECT "-t ext2 $LOOP_DEV" || error
1003
1004     enable_gns
1005
1006     echo ""
1007     echo "testing GNS with GENERIC upcall in GENERIC mode"
1008     
1009     check_gns GENERIC $DIR/gns_test_2h $DIR/gns_test_2h \
1010 $TIMOUT $TICK GENERIC BACKGROUND || {
1011         disable_gns
1012         cleanup_object $DIR/gns_test_2h
1013         cleanup_loop $LOOP_DEV $LOOP_FILE
1014         error
1015     }
1016     
1017     disable_gns
1018
1019     cleanup_object $DIR/gns_test_2h
1020     cleanup_loop $LOOP_DEV $LOOP_FILE
1021 }
1022
1023 run_test 2h " odd conditions (mounting in background) ==================="
1024
1025 TMPDIR=$OLDTMPDIR
1026 TMP=$OLDTMP
1027 HOME=$OLDHOME
1028
1029 log "cleanup: ==========================================================="
1030 if [ "`mount | grep ^$NAME`" ]; then
1031         rm -rf $DIR/[Rdfs][1-9]*
1032         if [ "$I_MOUNTED" = "yes" ]; then
1033                 sh llmountcleanup.sh || error
1034         fi
1035 fi
1036
1037 echo '=========================== finished ==============================='
1038 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true