Whamcloud - gitweb
- fixed sys_umount() code path. It did not release intent what caused memory leaks...
[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 ! cat /proc/mounts | 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" = "xBG" && 
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     local OP=$8
317     
318     rm -fr $LOG >/dev/null 2>&1
319     UPCALL_PATH="$TMP/gns-upcall-$UPCALL.sh"
320     
321     echo "generating upcall $UPCALL_PATH"
322     setup_upcall $UPCALL_PATH $UPCALL $LOG $BG || return $rc
323
324     echo "======================== upcall script ==========================="
325     cat $UPCALL_PATH 2>/dev/null || return $?
326     echo "=================================================================="
327    
328     echo "$UPCALL_PATH" > /proc/fs/lustre/llite/fs0/gns_upcall || return $?
329     echo "upcall:  $(cat /proc/fs/lustre/llite/fs0/gns_upcall)"
330
331     echo -n "mount on $OP: "
332
333     local OLD_PWD=$(pwd)
334     
335     case "$MODE" in
336         GENERIC)
337             case "$OP" in
338                 OPEN)
339                     echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1
340                     ;;
341                 CHDIR)
342                     cd $OBJECT1 || return $?
343                     ;;
344                 *)
345                     echo "invalid testing operation $OP"
346                     return 1
347             esac
348             ;;
349         CONCUR1)
350             local i=1
351             local nr=20
352         
353             for ((;i<=$nr;i++)); do 
354                 case "$OP" in
355                     OPEN)
356                         echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
357                         ;;
358                     CHDIR)
359                         cd $OBJECT1 >/dev/null 2>&1 &
360                         ;;
361                     *)
362                         echo "invalid testing operation $OP"
363                         return 1
364                 esac
365             done
366         
367             wait
368             
369             local RETVAL=$?
370             
371             [ $RETVAL -eq 0 ] || 
372                 return $RETVAL
373             ;;
374         CONCUR2)
375             test "x$OBJECT2" = "x" && {
376                 echo "not defined object2 for concurrent2 testing"
377                 return 1
378             }
379             case "$OP" in
380                 OPEN)
381                     echo -n "test data" > $OBJECT1/test_file1 >/dev/null 2>&1 &
382                     echo -n "test data" > $OBJECT2/test_file1 >/dev/null 2>&1 &
383                     ;;
384                 CHDIR)
385                     cd $OBJECT1 >/dev/null 2>&1 &
386                     cd $OBJECT2 >/dev/null 2>&1 &
387                     ;;
388                 *)
389                     echo "invalid testing operation $OP"
390                     return 1
391             esac
392             
393             wait
394             
395             local RETVAL=$?
396             
397             [ $RETVAL -eq 0 ] || 
398                 return $RETVAL
399             ;;
400         CONCUR3)
401             local i=1
402             local nr=20
403             
404             for ((;i<$nr;i++)); do
405                 case "$OP" in
406                     OPEN)
407                         touch $OBJECT1/file$i &
408                         echo -n "test data" > $OBJECT1/test_file$i >/dev/null 2>&1 &
409                         mkdir $OBJECT1/dir$i &
410                         ;;
411                     CHDIR)
412                         touch $OBJECT1/file$i &
413                         cd $OBJECT1 >/dev/null 2>&1 &
414                         mkdir $OBJECT1/dir$i &
415                         ;;
416                     *)
417                         echo "invalid testing operation $OP"
418                         return 1
419                 esac
420             done
421
422             wait
423             
424             local RETVAL=$?
425             
426             [ $RETVAL -eq 0 ] || 
427                 return $RETVAL
428             ;;
429         *)
430             echo "invalid testing mode $MODE"
431             return 1
432     esac
433
434     test "x$OP" = "xCHDIR" && cd $OLD_PWD
435     
436     check_mnt $OBJECT1 || {
437         echo "fail"
438         show_log $LOG
439         return 1
440     }
441     
442     if test "x$MODE" = "xCONCUR2"; then
443         check_mnt $OBJECT2 || {
444             echo "fail"
445             show_log $LOG
446             return 1
447         }
448     fi
449     
450     echo "success"
451
452     local sleep_time=$TIMOUT
453     let sleep_time+=$TICK*2
454     echo -n "waiting for umount ${sleep_time}s (timeout + tick*2): "
455     sleep $sleep_time
456     
457     check_mnt $OBJECT1 && {
458         echo "failed"
459         return 2
460     }
461     
462     if test "x$MODE" = "xCONCUR2"; then
463         check_mnt $OBJECT2 && {
464             echo "failed"
465             return 2
466         }
467     fi
468     
469     echo "success"
470     cleanup_upcall $UPCALL_PATH
471     return 0
472 }
473
474 setup_object() {
475     local OBJPATH=$1
476     local OBJECT=$2
477     local CONTENT=$3
478     
479     mkdir -p $OBJPATH || return $?
480     echo -n $CONTENT > $OBJPATH/$OBJECT || return $?
481     
482     echo "======================== mount object ==========================="
483     cat $OBJPATH/$OBJECT
484     echo ""
485     echo "================================================================="
486     
487     chmod u+s $OBJPATH
488     return $?
489 }
490
491 cleanup_object() {
492     local OBJPATH=$1
493
494     chmod u-s $OBJPATH
495     umount $OBJPATH >/dev/null 2>&1
496     rm -fr $OBJPATH >/dev/null 2>&1
497 }
498
499 setup_gns() {
500     local OBJECT=$1
501     local TIMOUT=$2
502     local TICK=$3
503
504     echo "$OBJECT" > /proc/fs/lustre/llite/fs0/gns_object_name || error
505     echo "$TIMOUT" > /proc/fs/lustre/llite/fs0/gns_timeout || error
506     echo "$TICK" > /proc/fs/lustre/llite/fs0/gns_tick || error
507
508     echo ""
509     echo "timeout: $(cat /proc/fs/lustre/llite/fs0/gns_timeout)s"
510     echo "object:  $(cat /proc/fs/lustre/llite/fs0/gns_object_name)"
511     echo "tick:    $(cat /proc/fs/lustre/llite/fs0/gns_tick)s"
512     echo ""
513
514 }
515
516 enable_gns()
517 {
518     echo "1" > /proc/fs/lustre/llite/fs0/gns_enabled || error
519     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x1" || error
520 }
521
522 disable_gns()
523 {
524     echo "0" > /proc/fs/lustre/llite/fs0/gns_enabled || error
525     test "x$(cat /proc/fs/lustre/llite/fs0/gns_enabled)" = "x0" || error
526 }
527
528 test_1a() {
529     local LOOP_DEV=$(find_free_loop 2>/dev/null)
530     local LOOP_FILE="$TMP/gns_loop_1a"
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_1a/$OBJECT..."
548     setup_object $DIR/gns_test_1a $OBJECT "-t ext2 $LOOP_DEV" || error
549
550     enable_gns
551
552     echo ""
553     echo "testing GNS with GENERIC upcall 3 times on the row"
554     
555     echo ""
556     echo "testing OPEN operation"
557     
558     for ((i=0;i<3;i++)); do
559         check_gns GENERIC $DIR/gns_test_1a $DIR/gns_test_1a $TIMOUT $TICK GENERIC FG OPEN || {
560             disable_gns
561             cleanup_object $DIR/gns_test_1a
562             cleanup_loop $LOOP_DEV $LOOP_FILE
563             error
564         }
565     done
566     
567     echo ""
568     echo "testing CHDIR operation"
569     
570     for ((i=0;i<3;i++)); do
571         check_gns GENERIC $DIR/gns_test_1a $DIR/gns_test_1a $TIMOUT $TICK GENERIC FG CHDIR || {
572             disable_gns
573             cleanup_object $DIR/gns_test_1a
574             cleanup_loop $LOOP_DEV $LOOP_FILE
575             error
576         }
577     done
578     
579     disable_gns
580
581     cleanup_object $DIR/gns_test_1a
582     cleanup_loop $LOOP_DEV $LOOP_FILE
583     return 0
584 }
585
586 run_test 1a " general GNS test - mount/umount (GENERIC) ================"
587
588 test_1b() {
589     local LOOP_DEV=$(find_free_loop 2>/dev/null)
590     local LOOP_FILE="$TMP/gns_loop_1b"
591     local OBJECT=".mntinfo"
592     local TIMOUT=5
593     local TICK=1
594
595     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
596         error "can't find free loop device"
597
598     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
599     cleanup_loop $LOOP_DEV $LOOP_FILE
600     setup_loop $LOOP_DEV $LOOP_FILE || error
601
602     echo "setting up GNS timeouts and mount object..."
603     setup_gns $OBJECT $TIMOUT $TICK || error
604
605     disable_gns
606     
607     echo "preparing mount object at $DIR/gns_test_1b/$OBJECT..."
608     setup_object $DIR/gns_test_1b $OBJECT "-t ext2 $LOOP_DEV" || error
609     
610     enable_gns
611
612     echo ""
613     echo "testing GNS with DEADLOCK upcall 3 times on the row"
614     
615     for ((i=0;i<3;i++)); do
616         check_gns DEADLOCK $DIR/gns_test_1b $DIR/gns_test_1b $TIMOUT $TICK GENERIC FG OPEN
617     done
618     
619     disable_gns
620
621     cleanup_object $DIR/gns_test_1b
622     cleanup_loop $LOOP_DEV $LOOP_FILE
623     return 0
624 }
625
626 run_test 1b " general GNS test - mount/umount (DEADLOCK) ==============="
627
628 test_1c() {
629     local LOOP_DEV=$(find_free_loop 2>/dev/null)
630     local LOOP_FILE="$TMP/gns_loop_1c"
631     local OBJECT=".mntinfo"
632     local TIMOUT=5
633     local TICK=1
634
635     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
636         error "can't find free loop device"
637
638     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
639     cleanup_loop $LOOP_DEV $LOOP_FILE
640     setup_loop $LOOP_DEV $LOOP_FILE || error
641
642     echo "setting up GNS timeouts and mount object..."
643     setup_gns $OBJECT $TIMOUT $TICK || error
644
645     disable_gns
646
647     echo "preparing mount object at $DIR/gns_test_1c/$OBJECT..."
648     setup_object $DIR/gns_test_1c $OBJECT "-t ext2 $LOOP_DEV" || error
649
650     enable_gns
651
652     echo ""
653     echo "testing GNS with GENERIC/DEADLOCK upcall 4 times on the row in GENERIC mode"
654     local i=0
655     
656     for ((;i<4;i++)); do
657         test $(($i%2)) -eq 1 && {
658             check_gns DEADLOCK $DIR/gns_test_1c $DIR/gns_test_1c $TIMOUT $TICK GENERIC FG OPEN
659         } || {
660             check_gns GENERIC $DIR/gns_test_1c $DIR/gns_test_1c $TIMOUT $TICK GENERIC FG OPEN || {
661                 disable_gns
662                 cleanup_object $DIR/gns_test_1c
663                 cleanup_loop $LOOP_DEV $LOOP_FILE
664                 error "generic upcall does not work!"
665             }
666         }
667         
668     done
669     
670     disable_gns
671
672     cleanup_object $DIR/gns_test_1c
673     cleanup_loop $LOOP_DEV $LOOP_FILE
674     return 0
675 }
676
677 run_test 1c " general GNS test - mount/umount (GENERIC/DEADLOCK) ========"
678
679 test_1d() {
680     local LOOP_DEV=$(find_free_loop 2>/dev/null)
681     local LOOP_FILE="$TMP/gns_loop_1d"
682     local OBJECT=".mntinfo"
683     local TIMOUT=5
684     local TICK=1
685
686     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
687         error "can't find free loop device"
688
689     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
690     cleanup_loop $LOOP_DEV $LOOP_FILE
691     setup_loop $LOOP_DEV $LOOP_FILE || error
692
693     echo "setting up GNS timeouts and mount object..."
694     setup_gns $OBJECT $TIMOUT $TICK || error
695
696     disable_gns
697
698     echo "preparing mount object at $DIR/gns_test_1d/$OBJECT..."
699     setup_object $DIR/gns_test_1d $OBJECT "-t ext2 $LOOP_DEV" || error
700
701     enable_gns
702
703     echo ""
704     echo "testing GNS with GENERIC upcall 4 times on the row in CONCUR1 mode"
705     local i=0
706     
707     for ((;i<4;i++)); do
708         check_gns GENERIC $DIR/gns_test_1d $DIR/gns_test_1d $TIMOUT $TICK CONCUR1 FG OPEN || {
709             disable_gns
710             cleanup_object $DIR/gns_test_1d
711             cleanup_loop $LOOP_DEV $LOOP_FILE
712             error
713         }
714     done
715     
716     disable_gns
717
718     cleanup_object $DIR/gns_test_1d
719     cleanup_loop $LOOP_DEV $LOOP_FILE
720     return 0
721 }
722
723 run_test 1d " general GNS test - concurrent mount ======================="
724
725 test_1e() {
726     local LOOP_DEV=$(find_free_loop 2>/dev/null)
727     local LOOP_FILE="$TMP/gns_loop_1e"
728     local OBJECT=".mntinfo"
729     local TIMOUT=5
730     local TICK=1
731
732     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
733         error "can't find free loop device"
734
735     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
736     cleanup_loop $LOOP_DEV $LOOP_FILE
737     setup_loop $LOOP_DEV $LOOP_FILE || error
738
739     echo "setting up GNS timeouts and mount object..."
740     setup_gns $OBJECT $TIMOUT $TICK || error
741
742     disable_gns
743
744     echo "preparing mount object at $DIR/gns_test_1e1/$OBJECT..."
745     setup_object $DIR/gns_test_1e1 $OBJECT "-t ext2 $LOOP_DEV" || error
746     
747     echo "preparing mount object at $DIR/gns_test_1e2/$OBJECT..."
748     setup_object $DIR/gns_test_1e2 $OBJECT "-t ext2 $LOOP_DEV" || error
749
750     enable_gns
751
752     echo ""
753     echo "testing GNS with GENERIC upcall in CONCUR2 mode"
754     
755     check_gns GENERIC $DIR/gns_test_1e1 $DIR/gns_test_1e2 $TIMOUT $TICK CONCUR2 FG OPEN || {
756         disable_gns
757         cleanup_object $DIR/gns_test_1e1
758         cleanup_object $DIR/gns_test_1e2
759         cleanup_loop $LOOP_DEV $LOOP_FILE
760         error
761     }
762     
763     disable_gns
764
765     cleanup_object $DIR/gns_test_1e1
766     cleanup_object $DIR/gns_test_1e2
767     cleanup_loop $LOOP_DEV $LOOP_FILE
768     return 0
769 }
770
771 run_test 1e " general GNS test - concurrent mount of 2 GNS mounts ======="
772
773 test_2a() {
774     local OBJECT=".mntinfo"
775     local TIMOUT=5
776     local TICK=1
777
778     echo "setting up GNS timeouts and mount object..."
779     setup_gns $OBJECT $TIMOUT $TICK || error
780
781     disable_gns
782
783     echo "preparing mount object at $DIR/gns_test_2a/$OBJECT..."
784     mkdir -p $DIR/gns_test_2a
785     ln -s $DIR/gns_test_2a $DIR/gns_test_2a/$OBJECT
786     chmod u+s $DIR/gns_test_2a
787     
788     enable_gns
789
790     echo ""
791     echo "testing GNS with GENERIC upcall"
792     
793     check_gns GENERIC $DIR/gns_test_2a $DIR/gns_test_2a $TIMOUT $TICK GENERIC FG OPEN && {
794         disable_gns
795         chmod u-s $DIR/gns_test_2a
796         rm -fr $DIR/gns_test_2a
797         error "symlink as mount object works?"
798     }
799     
800     disable_gns
801     chmod u-s $DIR/gns_test_2a
802     rm -fr $DIR/gns_test_2a
803     return 0
804 }
805
806 run_test 2a " odd conditions (mount object is symlink) ============="
807
808 test_2b() {
809     local OBJECT=".mntinfo"
810     local TIMOUT=5
811     local TICK=1
812
813     echo "setting up GNS timeouts and mount object..."
814     setup_gns $OBJECT $TIMOUT $TICK || error
815
816     disable_gns
817
818     echo "preparing mount object at $DIR/gns_test_2b/$OBJECT..."
819     mkdir -p $DIR/gns_test_2b/$OBJECT
820     chmod u+s $DIR/gns_test_2b
821     
822     enable_gns
823     
824     echo ""
825     echo "testing GNS with GENERIC upcall"
826     
827     check_gns GENERIC $DIR/gns_test_2b $DIR/gns_test_2b $TIMOUT $TICK GENERIC FG OPEN && {
828         disable_gns
829         chmod u-s $DIR/gns_test_2b
830         rm -fr $DIR/gns_test_2b
831         error "dir as mount object works?"
832     }
833     
834     disable_gns
835     chmod u-s $DIR/gns_test_2b
836     rm -fr $DIR/gns_test_2b
837     return 0
838 }
839
840 run_test 2b " odd conditions (mount object is directory) ==========="
841
842 test_2c() {
843     local OBJECT=".mntinfo"
844     local TIMOUT=5
845     local TICK=1
846
847     echo "setting up GNS timeouts and mount object..."
848     setup_gns $OBJECT $TIMOUT $TICK || error
849
850     disable_gns
851
852     echo "preparing mount object at $DIR/gns_test_2c/$OBJECT..."
853     mkdir -p $DIR/gns_test_2c/$OBJECT/$OBJECT/$OBJECT/$OBJECT
854     chmod u+s -R $DIR/gns_test_2c
855     
856     enable_gns
857     
858     echo ""
859     echo "testing GNS with GENERIC upcall"
860     
861     check_gns GENERIC $DIR/gns_test_2c $DIR/gns_test_2c $TIMOUT $TICK GENERIC FG OPEN && {
862         disable_gns
863         chmod u-s -R $DIR/gns_test_2c
864         rm -fr $DIR/gns_test_2c
865         error "recursive mounting of dir as mount object works?"
866     }
867     
868     disable_gns
869     chmod u-s -R $DIR/gns_test_2c
870     rm -fr $DIR/gns_test_2c
871     return 0
872 }
873
874 run_test 2c " odd conditions (mount object is recursive dir) ======="
875
876 test_2d() {
877     local OBJECT=".mntinfo"
878     local TIMOUT=5
879     local TICK=1
880
881     echo "setting up GNS timeouts and mount object..."
882     setup_gns $OBJECT $TIMOUT $TICK || error
883
884     disable_gns
885
886     echo "preparing mount object at $DIR/gns_test_2d/$OBJECT..."
887     mkdir -p $DIR/gns_test_2d
888     chmod u+s $DIR/gns_test_2d
889     
890     enable_gns
891
892     echo ""
893     echo "testing GNS with GENERIC upcall"
894     
895     check_gns GENERIC $DIR/gns_test_2d $DIR/gns_test_2d $TIMOUT $TICK GENERIC FG OPEN && {
896         disable_gns
897         chmod u-s $DIR/gns_test_2d
898         rm -fr $DIR/gns_test_2d
899         error "mount point with absent mount object works?"
900     }
901     
902     disable_gns
903     chmod u-s $DIR/gns_test_2d
904     rm -fr $DIR/gns_test_2d
905     return 0
906 }
907
908 run_test 2d " odd conditions (mount object is absent) =============="
909
910 test_2e() {
911     local OBJECT=".mntinfo"
912     local TIMOUT=5
913     local TICK=1
914
915     echo "setting up GNS timeouts and mount object..."
916     setup_gns $OBJECT $TIMOUT $TICK || error
917
918     echo "." > /proc/fs/lustre/llite/fs0/gns_object_name
919     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x." && 
920         error "'.' is set as mount object name"
921
922     echo ".." > /proc/fs/lustre/llite/fs0/gns_object_name
923     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.." && 
924         error "'..' is set as mount object name"
925
926     echo ".a" > /proc/fs/lustre/llite/fs0/gns_object_name
927     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x.a" || 
928         error "'.a' is not set as mount object name"
929
930     echo "..a" > /proc/fs/lustre/llite/fs0/gns_object_name
931     test "x$(cat /proc/fs/lustre/llite/fs0/gns_object_name)" = "x..a" || 
932         error "'..a' is not set as mount object name"
933     return 0
934 }
935
936 run_test 2e " odd conditions ('.' and '..' as mount object) ============="
937
938 test_2f() {
939     local LOOP_DEV=$(find_free_loop 2>/dev/null)
940     local LOOP_FILE="$TMP/gns_loop_2f"
941     local OBJECT=".mntinfo"
942     local TIMOUT=5
943     local TICK=1
944
945     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
946         error "can't find free loop device"
947
948     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
949     cleanup_loop $LOOP_DEV $LOOP_FILE
950     setup_loop $LOOP_DEV $LOOP_FILE || error
951
952     echo "setting up GNS timeouts and mount object..."
953     setup_gns $OBJECT $TIMOUT $TICK || error
954
955     disable_gns
956
957     echo "preparing mount object at $DIR/gns_test_2f/$OBJECT..."
958     setup_object $DIR/gns_test_2f $OBJECT "-t ext2 $LOOP_DEV" || error
959
960     enable_gns
961
962     echo ""
963     echo "testing GNS with GENERIC upcall in CONCUR3 mode"
964     
965     check_gns GENERIC $DIR/gns_test_2f $DIR/gns_test_2f $TIMOUT $TICK CONCUR3 FG OPEN || {
966         disable_gns
967         cleanup_object $DIR/gns_test_2f
968         cleanup_loop $LOOP_DEV $LOOP_FILE
969         error "mount during modifying mount point does not work"
970     }
971     
972     disable_gns
973
974     cleanup_object $DIR/gns_test_2f
975     cleanup_loop $LOOP_DEV $LOOP_FILE
976     return 0
977 }
978
979 run_test 2f " odd conditions (mount point is modifying during mount) ===="
980
981 test_2g() {
982     local LOOP_DEV=$(find_free_loop 2>/dev/null)
983     local LOOP_FILE="$TMP/gns_loop_2g"
984     local OBJECT=".mntinfo"
985     local TIMOUT=5
986     local TICK=1
987
988     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
989         error "can't find free loop device"
990
991     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
992     cleanup_loop $LOOP_DEV $LOOP_FILE
993     setup_loop $LOOP_DEV $LOOP_FILE || error
994
995     echo "setting up GNS timeouts and mount object..."
996     setup_gns $OBJECT $TIMOUT $TICK || error
997
998     disable_gns
999
1000     echo "preparing mount object at $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT..."
1001     setup_object $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
1002 $OBJECT "-t ext2 $LOOP_DEV" || error
1003     chmod u+s $DIR/gns_test_2g -R
1004
1005     enable_gns
1006
1007     echo ""
1008     echo "testing GNS with GENERIC upcall in GENERIC mode"
1009     
1010     check_gns GENERIC $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
1011 $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT $TIMOUT $TICK GENERIC FG OPEN || {
1012         disable_gns
1013         cleanup_object $DIR/gns_test_2g
1014         cleanup_loop $LOOP_DEV $LOOP_FILE
1015         error "recursive mount point does not work"
1016     }
1017     
1018     disable_gns
1019
1020     echo ""
1021     echo "turning SUID on $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT off"
1022     chmod u-s $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT
1023
1024     enable_gns
1025
1026     check_gns GENERIC $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT \
1027 $DIR/gns_test_2g/$OBJECT/$OBJECT/$OBJECT $TIMOUT $TICK GENERIC FG OPEN && {
1028         disable_gns
1029         cleanup_object $DIR/gns_test_2g
1030         cleanup_loop $LOOP_DEV $LOOP_FILE
1031         error "GNS works whereas mount point is not SUID marked dir"
1032     }
1033
1034     disable_gns
1035
1036     cleanup_object $DIR/gns_test_2g
1037     cleanup_loop $LOOP_DEV $LOOP_FILE
1038     return 0
1039 }
1040
1041 run_test 2g " odd conditions (mount point is recursive marked SUID dir) ="
1042
1043 test_2h() {
1044     local LOOP_DEV=$(find_free_loop 2>/dev/null)
1045     local LOOP_FILE="$TMP/gns_loop_2h"
1046     local OBJECT=".mntinfo"
1047     local TIMOUT=5
1048     local TICK=1
1049
1050     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
1051         error "can't find free loop device"
1052
1053     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
1054     cleanup_loop $LOOP_DEV $LOOP_FILE
1055     setup_loop $LOOP_DEV $LOOP_FILE || error
1056
1057     echo "setting up GNS timeouts and mount object..."
1058     setup_gns $OBJECT $TIMOUT $TICK || error
1059
1060     disable_gns
1061
1062     echo "preparing mount object at $DIR/gns_test_2h/$OBJECT..."
1063     setup_object $DIR/gns_test_2h $OBJECT "-t ext2 $LOOP_DEV" || error
1064
1065     enable_gns
1066
1067     echo ""
1068     echo "testing GNS with GENERIC upcall in GENERIC mode"
1069     
1070     check_gns GENERIC $DIR/gns_test_2h $DIR/gns_test_2h \
1071 $TIMOUT $TICK GENERIC BG OPEN || {
1072         disable_gns
1073         cleanup_object $DIR/gns_test_2h
1074         cleanup_loop $LOOP_DEV $LOOP_FILE
1075         error
1076     }
1077     
1078     disable_gns
1079
1080     cleanup_object $DIR/gns_test_2h
1081     cleanup_loop $LOOP_DEV $LOOP_FILE
1082     return 0
1083 }
1084
1085 run_test 2h " odd conditions (mounting in background) ==================="
1086
1087 test_3a() {
1088     local LOOP_DEV=$(find_free_loop 2>/dev/null)
1089     local LOOP_FILE="$TMP/gns_loop_3a"
1090     local OBJECT=".mntinfo"
1091     local TIMOUT=5
1092     local TICK=1
1093
1094     test "x$LOOP_DEV" != "x" && test -b $LOOP_DEV ||
1095         error "can't find free loop device"
1096
1097     echo "preparing loop device $LOOP_DEV <-> $LOOP_FILE..."
1098     cleanup_loop $LOOP_DEV $LOOP_FILE
1099     setup_loop $LOOP_DEV $LOOP_FILE || error
1100
1101     echo "setting up GNS timeouts and mount object..."
1102     setup_gns $OBJECT $TIMOUT $TICK || error
1103
1104     disable_gns
1105
1106     echo "preparing mount object at $DIR/gns_test_3a/$OBJECT..."
1107     setup_object $DIR/gns_test_3a $OBJECT "-t ext2 $LOOP_DEV" || error
1108
1109     enable_gns
1110
1111     echo ""
1112     echo "testing GNS with GENERIC upcall in GENERIC mode"
1113     
1114     check_gns GENERIC $DIR/gns_test_3a $DIR/gns_test_3a \
1115 $TIMOUT $TICK GENERIC FG OPEN || {
1116         disable_gns
1117         cleanup_object $DIR/gns_test_3a
1118         cleanup_loop $LOOP_DEV $LOOP_FILE
1119         error
1120     }
1121     
1122     chmod u-s $DIR/gns_test_3a || {
1123         disable_gns
1124         cleanup_object $DIR/gns_test_3a
1125         cleanup_loop $LOOP_DEV $LOOP_FILE
1126         error "can't chmod u-s $DIR/gns_test_3a"
1127     }
1128     
1129     check_mnt $DIR/gns_test_3a && {
1130         disable_gns
1131         cleanup_object $DIR/gns_test_3a
1132         cleanup_loop $LOOP_DEV $LOOP_FILE
1133         error "chmod u-s $DIR/gns_test_3a caused mounting"
1134     }
1135     
1136     disable_gns
1137     cleanup_object $DIR/gns_test_3a
1138     cleanup_loop $LOOP_DEV $LOOP_FILE
1139     return 0
1140 }
1141
1142 run_test 3a " removing mnt by chmod u-s ================================="
1143
1144 TMPDIR=$OLDTMPDIR
1145 TMP=$OLDTMP
1146 HOME=$OLDHOME
1147
1148 log "cleanup: ==========================================================="
1149 if [ "`mount | grep ^$NAME`" ]; then
1150         rm -rf $DIR/[Rdfs][1-9]*
1151         if [ "$I_MOUNTED" = "yes" ]; then
1152                 sh llmountcleanup.sh || error
1153         fi
1154 fi
1155
1156 echo '=========================== finished ==============================='
1157 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true