Whamcloud - gitweb
8c0318a0716944879fae39779a876056fdfbb663
[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_gns() {
290     local LOG="/tmp/gns-log"
291     local UPCALL_PATH=""
292     
293     local UPCALL=$1
294     local OBJECT1=$2
295     local OBJECT2=$3
296     local TIMOUT=$4
297     local TICK=$5
298     local MODE=$6
299     local BG=$7
300     
301     rm -fr $LOG >/dev/null 2>&1
302     UPCALL_PATH="/tmp/gns-upcall-$UPCALL.sh"
303     
304     echo "generating upcall $UPCALL_PATH"
305     setup_upcall $UPCALL_PATH $UPCALL $LOG $BG || return $rc
306
307     echo "======================== upcall script ==========================="
308     cat $UPCALL_PATH 2>/dev/null || return $?
309     echo "=================================================================="
310    
311     echo "$UPCALL_PATH" > /proc/fs/lustre/llite/fs0/gns_upcall || return $?
312     echo "upcall:  $(cat /proc/fs/lustre/llite/fs0/gns_upcall)"
313
314     case "$MODE" in
315         GENERIC)
316             echo -n "mount on open $OBJECT1/test_file1 (generic): "
317             echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1 || return $?
318             ;;
319         CONCUR1)
320             local i=1
321             local nr=20
322         
323             echo -n "mount on open $OBJECT1/test_file1 ($nr threads): "
324             for ((;i<=$nr;i++)); do 
325                 echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
326             done
327         
328             wait
329             
330             local RETVAL=$?
331             
332             [ $RETVAL -eq 0 ] || 
333                 return $RETVAL
334             ;;
335         CONCUR2)
336             test "x$OBJECT2" = "x" && {
337                 echo "not defined object2 for concurrent2 testing"
338                 return 1
339             }
340             echo -n "mount on open $OBJECT1/test_file1: "
341             echo -n "mount on open $OBJECT2/test_file1: "
342             echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1 &
343             echo -n "test data" > $OBJECT2/test_file1 >/dev/null 2>&1 &
344             
345             wait
346             
347             local RETVAL=$?
348             
349             [ $RETVAL -eq 0 ] || 
350                 return $RETVAL
351             ;;
352         CONCUR3)
353             echo -n "mount on open $OBJECT1/test_file1: "
354             
355             local i=1
356             local nr=20
357             
358             for ((;i<$nr;i++)); do
359                 touch $OBJECT1/file$i &
360                 echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
361                 mkdir $OBJECT1/dir$i &
362             done
363
364             wait
365             
366             local RETVAL=$?
367             
368             [ $RETVAL -eq 0 ] || 
369                 return $RETVAL
370             ;;
371         *)
372             echo "invalid testing mode $MODE"
373             return 1
374     esac
375     
376     local ENTRY1="`basename $OBJECT1`"
377     local ENTRY2="`basename $OBJECT2`"
378     
379     cat /proc/mounts | grep -q "$ENTRY1" || {
380         echo "fail"
381         show_log $LOG
382         return 1
383     }
384     
385     if test "x$MODE" = "xCONCUR2"; then
386         cat /proc/mounts | grep -q "$ENTRY2" || {
387             echo "fail"
388             show_log $LOG
389             return 1
390         }
391     fi
392     
393     echo "success"
394
395     local sleep_time=$TIMOUT
396     let sleep_time+=$TICK*2
397     echo -n "waiting for umount ${sleep_time}s (timeout + tick*2): "
398     sleep $sleep_time
399
400     cat /proc/mounts | grep -q "$ENTRY1" && {
401         echo "failed"
402         return 2
403     }
404     
405     if test "x$MODE" = "xCONCUR2"; then
406         cat /proc/mounts | grep -q "$ENTRY2" && {
407             echo "failed"
408             return 2
409         }
410     fi
411     
412     echo "success"
413     cleanup_upcall $UPCALL_PATH
414     return 0
415 }
416
417 setup_object() {
418     local OBJPATH=$1
419     local OBJECT=$2
420     local CONTENT=$3
421     local EXTRA_OPT=$4
422     
423     mkdir -p $OBJPATH || return $?
424     echo -n $CONTENT > $OBJPATH/$OBJECT || return $?
425     
426     echo "======================== mount object ==========================="
427     cat $OBJPATH/$OBJECT
428     echo ""
429     echo "================================================================="
430     
431     chmod u+s $OBJPATH $EXTRA_OPT
432     return $?
433 }
434
435 cleanup_object() {
436     local OBJPATH=$1
437     local EXTRA_OPT=$2
438
439     chmod u-s $OBJPATH $EXTRA_OPT
440     umount $OBJPATH >/dev/null 2>&1
441     rm -fr $OBJPATH >/dev/null 2>&1
442 }
443
444 setup_gns() {
445     local OBJECT=$1
446     local TIMOUT=$2
447     local TICK=$3
448
449     echo "$OBJECT" > /proc/fs/lustre/llite/fs0/gns_object_name || error
450     echo "$TIMOUT" > /proc/fs/lustre/llite/fs0/gns_timeout || error
451     echo "$TICK" > /proc/fs/lustre/llite/fs0/gns_tick || error
452
453     echo ""
454     echo "timeout: $(cat /proc/fs/lustre/llite/fs0/gns_timeout)s"
455     echo "object:  $(cat /proc/fs/lustre/llite/fs0/gns_object_name)"
456     echo "tick:    $(cat /proc/fs/lustre/llite/fs0/gns_tick)s"
457     echo ""
458
459 }
460
461 enable_gns()
462 {
463     echo "1" > /proc/fs/lustre/llite/fs0/gns_enabled || error
464     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x1" || error
465 }
466
467 disable_gns()
468 {
469     echo "0" > /proc/fs/lustre/llite/fs0/gns_enabled || error
470     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x0" || error
471 }
472
473 test_1a() {
474     local LOOP_DEV=$(find_free_loop 2>/dev/null)
475     local LOOP_FILE="/tmp/gns_loop_1a"
476     local OBJECT=".mntinfo"
477     local TIMOUT=5
478     local TICK=1
479
480     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
481         error "can't find free loop device"
482
483     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
484     cleanup_loop $LOOP_DEV $LOOP_FILE
485     setup_loop $LOOP_DEV $LOOP_FILE || error
486
487     echo "setting up GNS timeouts and mount object..."
488     setup_gns $OBJECT $TIMOUT $TICK || error
489     
490     disable_gns
491
492     echo "preparing mount object at $DIR/gns_test_1a/$OBJECT..."
493     setup_object $DIR/gns_test_1a $OBJECT "-t ext2 $LOOP_DEV" || error
494
495     enable_gns
496
497     echo ""
498     echo "testing GNS with GENERIC upcall 3 times on the row"
499     for ((i=0;i<3;i++)); do
500         check_gns GENERIC $DIR/gns_test_1a $DIR/gns_test_1a $TIMOUT $TICK GENERIC || {
501             disable_gns
502             cleanup_object $DIR/gns_test_1a
503             cleanup_loop $LOOP_DEV $LOOP_FILE
504             error
505         }
506     done
507     
508     disable_gns
509
510     cleanup_object $DIR/gns_test_1a
511     cleanup_loop $LOOP_DEV $LOOP_FILE
512 }
513
514 run_test 1a " general GNS test - mount/umount (GENERIC) ================"
515
516 test_1b() {
517     local LOOP_DEV=$(find_free_loop 2>/dev/null)
518     local LOOP_FILE="/tmp/gns_loop_1b"
519     local OBJECT=".mntinfo"
520     local TIMOUT=5
521     local TICK=1
522
523     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
524         error "can't find free loop device"
525
526     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
527     cleanup_loop $LOOP_DEV $LOOP_FILE
528     setup_loop $LOOP_DEV $LOOP_FILE || error
529
530     echo "setting up GNS timeouts and mount object..."
531     setup_gns $OBJECT $TIMOUT $TICK || error
532
533     disable_gns
534     
535     echo "preparing mount object at $DIR/gns_test_1b/$OBJECT..."
536     setup_object $DIR/gns_test_1b $OBJECT "-t ext2 $LOOP_DEV" || error
537     
538     enable_gns
539
540     echo ""
541     echo "testing GNS with DEADLOCK upcall 3 times on the row"
542     for ((i=0;i<3;i++)); do
543         check_gns DEADLOCK $DIR/gns_test_1b $DIR/gns_test_1b $TIMOUT $TICK GENERIC || {
544             disable_gns
545             cleanup_object $DIR/gns_test_1b
546             cleanup_loop $LOOP_DEV $LOOP_FILE
547             error
548         }
549     done
550     
551     disable_gns
552
553     cleanup_object $DIR/gns_test_1b
554     cleanup_loop $LOOP_DEV $LOOP_FILE
555 }
556
557 run_test 1b " general GNS test - mount/umount (DEADLOCK) ==============="
558
559 test_1c() {
560     local LOOP_DEV=$(find_free_loop 2>/dev/null)
561     local LOOP_FILE="/tmp/gns_loop_1c"
562     local OBJECT=".mntinfo"
563     local TIMOUT=5
564     local TICK=1
565
566     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
567         error "can't find free loop device"
568
569     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
570     cleanup_loop $LOOP_DEV $LOOP_FILE
571     setup_loop $LOOP_DEV $LOOP_FILE || error
572
573     echo "setting up GNS timeouts and mount object..."
574     setup_gns $OBJECT $TIMOUT $TICK || error
575
576     disable_gns
577
578     echo "preparing mount object at $DIR/gns_test_1c/$OBJECT..."
579     setup_object $DIR/gns_test_1c $OBJECT "-t ext2 $LOOP_DEV" || error
580
581     enable_gns
582
583     echo ""
584     echo "testing GNS with DEADLOCK upcall 4 times on the row"
585     local i=0
586     
587     for ((;i<4;i++)); do
588         local MODE="GENERIC"
589         
590         test $(($i%2)) -eq 1 && MODE="DEADLOCK"
591         
592         check_gns $MODE $DIR/gns_test_1c $DIR/gns_test_1c $TIMOUT $TICK GENERIC || {
593             disable_gns
594             cleanup_object $DIR/gns_test_1c
595             cleanup_loop $LOOP_DEV $LOOP_FILE
596             error
597         }
598     done
599     
600     disable_gns
601
602     cleanup_object $DIR/gns_test_1c
603     cleanup_loop $LOOP_DEV $LOOP_FILE
604 }
605
606 run_test 1c " general GNS test - mount/umount (GENERIC/DEADLOCK) ========"
607
608 test_1d() {
609     local LOOP_DEV=$(find_free_loop 2>/dev/null)
610     local LOOP_FILE="/tmp/gns_loop_1d"
611     local OBJECT=".mntinfo"
612     local TIMOUT=5
613     local TICK=1
614
615     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
616         error "can't find free loop device"
617
618     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
619     cleanup_loop $LOOP_DEV $LOOP_FILE
620     setup_loop $LOOP_DEV $LOOP_FILE || error
621
622     echo "setting up GNS timeouts and mount object..."
623     setup_gns $OBJECT $TIMOUT $TICK || error
624
625     disable_gns
626
627     echo "preparing mount object at $DIR/gns_test_1d/$OBJECT..."
628     setup_object $DIR/gns_test_1d $OBJECT "-t ext2 $LOOP_DEV" || error
629
630     enable_gns
631
632     echo ""
633     echo "testing GNS with GENERIC/DEADLOCK upcall 4 times on the row in CONCUR1 mode"
634     local i=0
635     
636     for ((;i<4;i++)); do
637         local MODE="GENERIC"
638         
639         test $(($i%2)) -eq 1 && MODE="DEADLOCK"
640         
641         check_gns $MODE $DIR/gns_test_1d $DIR/gns_test_1d $TIMOUT $TICK CONCUR1 || {
642             disable_gns
643             cleanup_object $DIR/gns_test_1d
644             cleanup_loop $LOOP_DEV $LOOP_FILE
645             error
646         }
647     done
648     
649     disable_gns
650
651     cleanup_object $DIR/gns_test_1d
652     cleanup_loop $LOOP_DEV $LOOP_FILE
653 }
654
655 run_test 1d " general GNS test - concurrent mount ======================="
656
657 test_1e() {
658     local LOOP_DEV=$(find_free_loop 2>/dev/null)
659     local LOOP_FILE="/tmp/gns_loop_1e"
660     local OBJECT=".mntinfo"
661     local TIMOUT=5
662     local TICK=1
663
664     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
665         error "can't find free loop device"
666
667     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
668     cleanup_loop $LOOP_DEV $LOOP_FILE
669     setup_loop $LOOP_DEV $LOOP_FILE || error
670
671     echo "setting up GNS timeouts and mount object..."
672     setup_gns $OBJECT $TIMOUT $TICK || error
673
674     disable_gns
675
676     echo "preparing mount object at $DIR/gns_test_1e1/$OBJECT..."
677     setup_object $DIR/gns_test_1e1 $OBJECT "-t ext2 $LOOP_DEV" || error
678     
679     echo "preparing mount object at $DIR/gns_test_1e2/$OBJECT..."
680     setup_object $DIR/gns_test_1e2 $OBJECT "-t ext2 $LOOP_DEV" || error
681
682     enable_gns
683
684     echo ""
685     echo "testing GNS with GENERIC upcall in CONCUR2 mode"
686     check_gns GENERIC $DIR/gns_test_1e1 $DIR/gns_test_1e2 $TIMOUT $TICK CONCUR2 || {
687         disable_gns
688         cleanup_object $DIR/gns_test_1e1
689         cleanup_object $DIR/gns_test_1e2
690         cleanup_loop $LOOP_DEV $LOOP_FILE
691         error
692     }
693     
694     disable_gns
695
696     cleanup_object $DIR/gns_test_1e1
697     cleanup_object $DIR/gns_test_1e2
698     cleanup_loop $LOOP_DEV $LOOP_FILE
699 }
700
701 run_test 1e " general GNS test - concurrent mount of 2 GNS mounts ======="
702
703 test_2a() {
704     local OBJECT=".mntinfo"
705     local TIMOUT=5
706     local TICK=1
707
708     echo "setting up GNS timeouts and mount object..."
709     setup_gns $OBJECT $TIMOUT $TICK || error
710
711     disable_gns
712
713     echo "preparing mount object at $DIR/gns_test_2a/$OBJECT..."
714     mkdir -p $DIR/gns_test_2a
715     ln -s $DIR/gns_test_2a $DIR/gns_test_2a/$OBJECT
716     chmod u+s $DIR/gns_test_2a
717     
718     enable_gns
719
720     echo ""
721     echo "testing GNS with GENERIC upcall"
722     check_gns GENERIC $DIR/gns_test_2a $DIR/gns_test_2a $TIMOUT $TICK GENERIC && {
723         disable_gns
724         chmod u-s $DIR/gns_test_2a
725         rm -fr $DIR/gns_test_2a
726         error "symlink as mount object works?"
727     }
728     
729     disable_gns
730     chmod u-s $DIR/gns_test_2a
731     rm -fr $DIR/gns_test_2a
732 }
733
734 run_test 2a " odd conditions (mount object is symlink) ============="
735
736 test_2b() {
737     local OBJECT=".mntinfo"
738     local TIMOUT=5
739     local TICK=1
740
741     echo "setting up GNS timeouts and mount object..."
742     setup_gns $OBJECT $TIMOUT $TICK || error
743
744     disable_gns
745
746     echo "preparing mount object at $DIR/gns_test_2b/$OBJECT..."
747     mkdir -p $DIR/gns_test_2b/$OBJECT
748     chmod u+s $DIR/gns_test_2b
749     
750     enable_gns
751     
752     echo ""
753     echo "testing GNS with GENERIC upcall"
754     check_gns GENERIC $DIR/gns_test_2b $DIR/gns_test_2b $TIMOUT $TICK GENERIC && {
755         disable_gns
756         chmod u-s $DIR/gns_test_2b
757         rm -fr $DIR/gns_test_2b
758         error "dir as mount object works?"
759     }
760     
761     disable_gns
762     chmod u-s $DIR/gns_test_2b
763     rm -fr $DIR/gns_test_2b
764 }
765
766 run_test 2b " odd conditions (mount object is directory) ==========="
767
768 test_2c() {
769     local OBJECT=".mntinfo"
770     local TIMOUT=5
771     local TICK=1
772
773     echo "setting up GNS timeouts and mount object..."
774     setup_gns $OBJECT $TIMOUT $TICK || error
775
776     disable_gns
777
778     echo "preparing mount object at $DIR/gns_test_2c/$OBJECT..."
779     mkdir -p $DIR/gns_test_2c/$OBJECT/$OBJECT/$OBJECT/$OBJECT
780     chmod u+s -R $DIR/gns_test_2c
781     
782     enable_gns
783     
784     echo ""
785     echo "testing GNS with GENERIC upcall"
786     check_gns GENERIC $DIR/gns_test_2c $DIR/gns_test_2c $TIMOUT $TICK GENERIC && {
787         disable_gns
788         chmod u-s -R $DIR/gns_test_2c
789         rm -fr $DIR/gns_test_2c
790         error "recursive mounting of dir as mount object works?"
791     }
792     
793     disable_gns
794     chmod u-s $DIR/gns_test_2c
795     rm -fr $DIR/gns_test_2c
796 }
797
798 run_test 2c " odd conditions (mount object is recursive dir) ======="
799
800 test_2d() {
801     local OBJECT=".mntinfo"
802     local TIMOUT=5
803     local TICK=1
804
805     echo "setting up GNS timeouts and mount object..."
806     setup_gns $OBJECT $TIMOUT $TICK || error
807
808     disable_gns
809
810     echo "preparing mount object at $DIR/gns_test_2d/$OBJECT..."
811     mkdir -p $DIR/gns_test_2d
812     chmod u+s $DIR/gns_test_2d
813     
814     enable_gns
815
816     echo ""
817     echo "testing GNS with GENERIC upcall"
818     check_gns GENERIC $DIR/gns_test_2d $DIR/gns_test_2d $TIMOUT $TICK GENERIC && {
819         disable_gns
820         chmod u-s $DIR/gns_test_2d
821         rm -fr $DIR/gns_test_2d
822         error "mount point with absent mount object works?"
823     }
824     
825     disable_gns
826     chmod u-s $DIR/gns_test_2d
827     rm -fr $DIR/gns_test_2d
828 }
829
830 run_test 2d " odd conditions (mount object is absent) =============="
831
832 test_2e() {
833     local OBJECT=".mntinfo"
834     local TIMOUT=5
835     local TICK=1
836
837     echo "setting up GNS timeouts and mount object..."
838     setup_gns $OBJECT $TIMOUT $TICK || error
839
840     echo "." > /proc/fs/lustre/llite/fs0/gns_object_name
841     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x." && 
842         error "'.' is set as mount object name"
843
844     echo ".." > /proc/fs/lustre/llite/fs0/gns_object_name
845     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.." && 
846         error "'..' is set as mount object name"
847
848     echo ".a" > /proc/fs/lustre/llite/fs0/gns_object_name
849     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.a" || 
850         error "'.a' is not set as mount object name"
851
852     echo "..a" > /proc/fs/lustre/llite/fs0/gns_object_name
853     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x..a" || 
854         error "'..a' is not set as mount object name"
855 }
856
857 run_test 2e " odd conditions ('.' and '..' as mount object) ============="
858
859 test_2f() {
860     local LOOP_DEV=$(find_free_loop 2>/dev/null)
861     local LOOP_FILE="/tmp/gns_loop_2f"
862     local OBJECT=".mntinfo"
863     local TIMOUT=5
864     local TICK=1
865
866     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
867         error "can't find free loop device"
868
869     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
870     cleanup_loop $LOOP_DEV $LOOP_FILE
871     setup_loop $LOOP_DEV $LOOP_FILE || error
872
873     echo "setting up GNS timeouts and mount object..."
874     setup_gns $OBJECT $TIMOUT $TICK || error
875
876     disable_gns
877
878     echo "preparing mount object at $DIR/gns_test_2f/$OBJECT..."
879     setup_object $DIR/gns_test_2f $OBJECT "-t ext2 $LOOP_DEV" || error
880
881     enable_gns
882
883     echo ""
884     echo "testing GNS with DEADLOCK upcall in CONCUR3 mode"
885     
886     local MODE="DEADLOCK"
887         
888     check_gns $MODE $DIR/gns_test_2f $DIR/gns_test_2f $TIMOUT $TICK CONCUR3 || {
889         disable_gns
890         cleanup_object $DIR/gns_test_2f
891         cleanup_loop $LOOP_DEV $LOOP_FILE
892         error
893     }
894     
895     disable_gns
896
897     cleanup_object $DIR/gns_test_2f
898     cleanup_loop $LOOP_DEV $LOOP_FILE
899 }
900
901 run_test 2f " odd conditions (mount point is modifying during mount) ===="
902
903 test_2g() {
904     local LOOP_DEV=$(find_free_loop 2>/dev/null)
905     local LOOP_FILE="/tmp/gns_loop_2g"
906     local OBJECT=".mntinfo"
907     local TIMOUT=5
908     local TICK=1
909
910     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
911         error "can't find free loop device"
912
913     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
914     cleanup_loop $LOOP_DEV $LOOP_FILE
915     setup_loop $LOOP_DEV $LOOP_FILE || error
916
917     echo "setting up GNS timeouts and mount object..."
918     setup_gns $OBJECT $TIMOUT $TICK || error
919
920     disable_gns
921
922     echo "preparing mount object at $DIR/gns_test_2g/$OBJECT..."
923     setup_object $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
924 $OBJECT "-t ext2 $LOOP_DEV" || error
925
926     enable_gns
927
928     echo ""
929     echo "testing GNS with DEADLOCK upcall in GENERIC mode"
930     
931     local MODE="DEADLOCK"
932         
933     check_gns $MODE $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
934 $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT $TIMOUT $TICK GENERIC || {
935         disable_gns
936         cleanup_object $DIR/gns_test_2g
937         cleanup_loop $LOOP_DEV $LOOP_FILE
938         error
939     }
940     
941     disable_gns
942
943     cleanup_object $DIR/gns_test_2g
944     cleanup_loop $LOOP_DEV $LOOP_FILE
945 }
946
947 run_test 2g " odd conditions (mount point is recursive marked SUID dir) ="
948
949 test_2h() {
950     local LOOP_DEV=$(find_free_loop 2>/dev/null)
951     local LOOP_FILE="/tmp/gns_loop_2h"
952     local OBJECT=".mntinfo"
953     local TIMOUT=5
954     local TICK=1
955
956     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
957         error "can't find free loop device"
958
959     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
960     cleanup_loop $LOOP_DEV $LOOP_FILE
961     setup_loop $LOOP_DEV $LOOP_FILE || error
962
963     echo "setting up GNS timeouts and mount object..."
964     setup_gns $OBJECT $TIMOUT $TICK || error
965
966     disable_gns
967
968     echo "preparing mount object at $DIR/gns_test_2h/$OBJECT..."
969     setup_object $DIR/gns_test_2h $OBJECT "-t ext2 $LOOP_DEV" || error
970
971     enable_gns
972
973     echo ""
974     echo "testing GNS with GENERIC upcall in GENERIC mode"
975     
976     check_gns GENERIC $DIR/gns_test_2h $DIR/gns_test_2h \
977 $TIMOUT $TICK GENERIC BACKGROUND || {
978         disable_gns
979         cleanup_object $DIR/gns_test_2h
980         cleanup_loop $LOOP_DEV $LOOP_FILE
981         error
982     }
983     
984     disable_gns
985
986     cleanup_object $DIR/gns_test_2h
987     cleanup_loop $LOOP_DEV $LOOP_FILE
988 }
989
990 run_test 2h " odd conditions (mounting in background) ==================="
991
992 TMPDIR=$OLDTMPDIR
993 TMP=$OLDTMP
994 HOME=$OLDHOME
995
996 log "cleanup: ==========================================================="
997 if [ "`mount | grep ^$NAME`" ]; then
998         rm -rf $DIR/[Rdfs][1-9]*
999         if [ "$I_MOUNTED" = "yes" ]; then
1000                 sh llmountcleanup.sh || error
1001         fi
1002 fi
1003
1004 echo '=========================== finished ==============================='
1005 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true