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