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