Whamcloud - gitweb
LU-1866 osd: ancillary work for initial OI scrub
[fs/lustre-release.git] / lustre / tests / sanity-gss.sh
1 #!/bin/bash
2 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test:
12 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"$SANITY_GSS_EXCEPT"}
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # Tests that fail on uml
16 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
17 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT"
18
19 SRCDIR=`dirname $0`
20 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
21 export NAME=${NAME:-local}
22 SAVE_PWD=$PWD
23
24 export MULTIOP=${MULTIOP:-multiop}
25
26 CLEANUP=${CLEANUP:-""}
27 SETUP=${SETUP:-""}
28
29 LUSTRE=${LUSTRE:-`dirname $0`/..}
30 . $LUSTRE/tests/test-framework.sh
31 init_test_env $@
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 init_logging
34
35 require_dsh_mds || exit 0
36
37 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
38
39 # $RUNAS_ID may get set incorrectly somewhere else
40 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
41
42 # remove $SEC, we'd like to control everything by ourselves
43 unset SEC
44
45 #
46 # global variables of this sanity
47 #
48 KRB5_CCACHE_DIR=/tmp
49 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
50 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
51 DBENCH_PID=0
52
53 # set manually
54 GSS=true
55 GSS_KRB5=true
56
57 prepare_krb5_creds() {
58     echo prepare krb5 cred
59     rm -f $KRB5_CRED_SAVE
60     echo RUNAS=$RUNAS
61     $RUNAS krb5_login.sh || exit 1
62     [ -f $KRB5_CRED ] || exit 2
63     echo CRED=$KRB5_CRED
64     cp $KRB5_CRED $KRB5_CRED_SAVE
65 }
66
67 prepare_krb5_creds
68
69 # we want double mount
70 MOUNT_2=${MOUNT_2:-"yes"}
71 check_and_setup_lustre
72
73 rm -rf $DIR/[df][0-9]*
74
75 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
76
77 build_test_filter
78
79 start_dbench()
80 {
81     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
82     [ $NPROC -gt 2 ] && NPROC=2
83     sh rundbench $NPROC 1>/dev/null &
84     DBENCH_PID=$!
85     sleep 2
86
87     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
88     if [ $num -ne 1 ]; then
89         error "failed to start dbench $NPROC"
90     else
91         echo "started dbench with $NPROC processes at background"
92     fi
93
94     return 0
95 }
96
97 check_dbench()
98 {
99     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
100     if [ $num -eq 0 ]; then
101         echo "dbench $DBENCH_PID already finished"
102         wait $DBENCH_PID || error "dbench $PID exit with error"
103         start_dbench
104     elif [ $num -ne 1 ]; then
105         killall -9 dbench
106         error "found $num instance of pid $DBENCH_PID ???"
107     fi
108
109     return 0
110 }
111
112 stop_dbench()
113 {
114     for ((;;)); do
115         killall dbench 2>/dev/null
116         num=`ps --no-headers -p $DBENCH_PID | wc -l`
117         if [ $num -eq 0 ]; then
118             echo "dbench finished"
119             break
120         fi
121         echo "dbench $DBENCH_PID is still running, waiting 2s..."
122         sleep 2
123     done
124
125     wait $DBENCH_PID || true
126     sync || true
127 }
128
129 restore_krb5_cred() {
130     cp $KRB5_CRED_SAVE $KRB5_CRED
131     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
132     chmod 0600 $KRB5_CRED
133 }
134
135 check_multiple_gss_daemons() {
136     local facet=$1
137     local gssd=$2
138     local gssd_name=`basename $gssd`
139
140     for ((i=0;i<10;i++)); do
141         do_facet $facet "$gssd -v &"
142     done
143
144     # wait daemons entering "stable" status
145     sleep 5
146
147     num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
148     echo "$num instance(s) of $gssd_name are running"
149
150     if [ $num -ne 1 ]; then
151         error "$gssd_name not unique"
152     fi
153 }
154
155 calc_connection_cnt
156 umask 077
157
158 test_0() {
159     local my_facet=mds
160
161     echo "bring up gss daemons..."
162     start_gss_daemons
163
164     echo "check with someone already running..."
165     check_multiple_gss_daemons $my_facet $LSVCGSSD
166     if $GSS_PIPEFS; then
167         check_multiple_gss_daemons $my_facet $LGSSD
168     fi
169
170     echo "check with someone run & finished..."
171     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
172     sleep 5 # wait fully exit
173     check_multiple_gss_daemons $my_facet $LSVCGSSD
174     if $GSS_PIPEFS; then
175         check_multiple_gss_daemons $my_facet $LGSSD
176     fi
177
178     echo "check refresh..."
179     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
180     sleep 5 # wait fully exit
181     do_facet $my_facet ipcrm -S 0x3b92d473
182     check_multiple_gss_daemons $my_facet $LSVCGSSD
183     if $GSS_PIPEFS; then
184         do_facet $my_facet ipcrm -S 0x3a92d473
185         check_multiple_gss_daemons $my_facet $LGSSD
186     fi
187 }
188 run_test 0 "start multiple gss daemons"
189
190 set_flavor_all krb5p
191
192 test_1() {
193     local file=$DIR/$tfile
194
195     chmod 0777 $DIR || error "chmod $DIR failed"
196     $RUNAS touch $DIR
197     # access w/o cred
198     $RUNAS kdestroy
199     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
200     $RUNAS touch $file && error "unexpected success"
201
202     # access w/ cred
203     restore_krb5_cred
204     $RUNAS touch $file || error "should not fail"
205     [ -f $file ] || error "$file not found"
206 }
207 run_test 1 "access with or without krb5 credential"
208
209 test_2() {
210     local file1=$DIR/$tfile-1
211     local file2=$DIR/$tfile-2
212
213     chmod 0777 $DIR || error "chmod $DIR failed"
214     # current access should be ok
215     $RUNAS touch $file1 || error "can't touch $file1"
216     [ -f $file1 ] || error "$file1 not found"
217
218     # cleanup all cred/ctx and touch
219     $RUNAS kdestroy
220     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
221     $RUNAS touch $file2 && error "unexpected success"
222
223     # restore and touch
224     restore_krb5_cred
225     $RUNAS touch $file2 || error "should not fail"
226     [ -f $file2 ] || error "$file2 not found"
227 }
228 run_test 2 "lfs flushctx"
229
230 test_3() {
231     local file=$DIR/$tfile
232
233     # create file
234     echo "aaaaaaaaaaaaaaaaa" > $file
235     chmod 0666 $file
236     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
237     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
238     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
239
240     # start multiop
241     $RUNAS $MULTIOP $file o_r &
242     OPPID=$!
243     # wait multiop finish its open()
244     sleep 1
245
246     # cleanup all cred/ctx and check
247     # metadata check should fail, but file data check should success
248     # because we always use root credential to OSTs
249     $RUNAS kdestroy
250     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
251     echo "destroied credentials/contexs for $RUNAS_ID"
252     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
253     kill -s 10 $OPPID
254     wait $OPPID || error "read file data failed"
255     echo "read file data OK"
256
257     # restore and check again
258     restore_krb5_cred
259     echo "restored credentials for $RUNAS_ID"
260     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
261     echo "$RUNAS_ID checkstat OK"
262     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
263     echo "$UID checkstat OK"
264     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
265     echo "$RUNAS_ID read file data OK"
266 }
267 run_test 3 "local cache under DLM lock"
268
269 test_4() {
270     local file1=$DIR/$tfile-1
271     local file2=$DIR/$tfile-2
272
273     ! $GSS_PIPEFS && skip "pipefs not used" && return
274
275     chmod 0777 $DIR || error "chmod $DIR failed"
276     # current access should be ok
277     $RUNAS touch $file1 || error "can't touch $file1"
278     [ -f $file1 ] || error "$file1 not found"
279
280     # stop lgssd
281     send_sigint client lgssd
282     sleep 5
283     check_gss_daemon_facet client lgssd && error "lgssd still running"
284
285     # flush context, and touch
286     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
287     $RUNAS touch $file2 &
288     TOUCHPID=$!
289     echo "waiting touch pid $TOUCHPID"
290     wait $TOUCHPID && error "touch should fail"
291
292     # restart lgssd
293     do_facet client "$LGSSD -v"
294     sleep 5
295     check_gss_daemon_facet client lgssd
296
297     # touch new should succeed
298     $RUNAS touch $file2 || error "can't touch $file2"
299     [ -f $file2 ] || error "$file2 not found"
300 }
301 run_test 4 "lgssd dead, operations should wait timeout and fail"
302
303 test_5() {
304     local file1=$DIR/$tfile-1
305     local file2=$DIR/$tfile-2
306     local wait_time=$((TIMEOUT + TIMEOUT / 2))
307
308     chmod 0777 $DIR || error "chmod $DIR failed"
309     # current access should be ok
310     $RUNAS touch $file1 || error "can't touch $file1"
311     [ -f $file1 ] || error "$file1 not found"
312
313     # stop lsvcgssd
314     send_sigint $(comma_list $(mdts_nodes)) lsvcgssd
315     sleep 5
316     check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd && error "lsvcgssd still running"
317
318     # flush context, and touch
319     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
320     $RUNAS touch $file2 &
321     TOUCHPID=$!
322
323     # wait certain time
324     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
325     sleep $wait_time
326     num=`ps --no-headers -p $TOUCHPID | wc -l`
327     [ $num -eq 1 ] || error "touch already ended ($num)"
328     echo "process $TOUCHPID still hanging there... OK"
329
330     # restart lsvcgssd, expect touch suceed
331     echo "restart lsvcgssd and recovering"
332     start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -v"
333     sleep 5
334     check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd
335     wait $TOUCHPID || error "touch fail"
336     [ -f $file2 ] || error "$file2 not found"
337 }
338 run_test 5 "lsvcgssd dead, operations lead to recovery"
339
340 test_6() {
341     local nfile=10
342
343     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
344     for ((i=0; i<$nfile; i++)); do
345         dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
346     done
347     ls -l $DIR/d6/* > /dev/null || error "ls failed"
348     rm -rf $DIR2/d6/* || error "rm failed"
349     rmdir $DIR2/d6/ || error "rmdir failed"
350 }
351 run_test 6 "test basic DLM callback works"
352
353 test_7() {
354     local tdir=$DIR/d7
355     local num_osts
356
357     #
358     # for open(), client only reserve space for default stripe count lovea,
359     # and server may return larger lovea in reply (because of larger stripe
360     # count), client need call enlarge_reqbuf() and save the replied lovea
361     # in request for future possible replay.
362     #
363     # Note: current script does NOT guarantee enlarge_reqbuf() will be in
364     # the path, however it does work in local test which has 2 OSTs and
365     # default stripe count is 1.
366     #
367     num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
368     echo "found $num_osts active OSTs"
369     [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
370
371     mkdir $tdir || error
372     $LFS setstripe -c $num_osts $tdir || error
373
374     echo "creating..."
375     for ((i=0;i<20;i++)); do
376         dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
377     done
378     echo "reading..."
379     for ((i=0;i<20;i++)); do
380         dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
381     done
382     rm -rf $tdir
383 }
384 run_test 7 "exercise enlarge_reqbuf()"
385
386 test_8()
387 {
388     local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
389     local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
390     local REQ_DELAY
391     do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
392
393     mkdir -p $DIR/d8
394     chmod a+w $DIR/d8
395
396     $LCTL dk > /dev/null
397     debugsave
398     sysctl -w lnet.debug="+other"
399
400     # wait for the at estimation come down, this is faster
401     while [ true ]; do
402         REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
403                    awk '/portal 12/ {print $5}' | tail -1`
404         [ $REQ_DELAY -le 5 ] && break
405         echo "current AT estimation is $REQ_DELAY, wait a little bit"
406         sleep 8
407     done
408     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
409
410     # sleep sometime in ctx handle
411     do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
412 #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
413     do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
414
415     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
416
417     $RUNAS touch $DIR/d8/f &
418     TOUCHPID=$!
419     echo "waiting for touch (pid $TOUCHPID) to finish..."
420     sleep 2 # give it a chance to really trigger context init rpc
421     do_facet $SINGLEMDS $LCTL set_param fail_loc=0
422     wait $TOUCHPID || error "touch should have succeeded"
423
424     $LCTL dk | grep "Early reply #" || error "No early reply"
425
426     debugrestore
427     do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
428 }
429 run_test 8 "Early reply sent for slow gss context negotiation"
430
431 #
432 # following tests will manipulate flavors and may end with any flavor set,
433 # so each test should not assume any start flavor.
434 #
435
436 test_90() {
437     if [ "$SLOW" = "no" ]; then
438         total=10
439     else
440         total=60
441     fi
442
443     restore_to_default_flavor
444     set_rule $FSNAME any any krb5p
445     wait_flavor all2all krb5p
446
447     start_dbench
448
449     for ((n=0;n<$total;n++)); do
450         sleep 2
451         check_dbench
452         echo "flush ctx ($n/$total) ..."
453         $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
454     done
455     check_dbench
456     #sleep to let ctxs be re-established
457     sleep 10
458     stop_dbench
459 }
460 run_test 90 "recoverable from losing contexts under load"
461
462 test_99() {
463     local nrule_old=0
464     local nrule_new=0
465     local max=64
466
467     #
468     # general rules
469     #
470     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
471                | grep "$FSNAME.srpc.flavor." | wc -l`
472     echo "original general rules: $nrule_old"
473
474     for ((i = $nrule_old; i < $max; i++)); do
475         set_rule $FSNAME elan$i any krb5n || error "set rule $i"
476     done
477     for ((i = $nrule_old; i < $max; i++)); do
478         set_rule $FSNAME elan$i any || error "remove rule $i"
479     done
480
481     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
482                | grep "$FSNAME.srpc.flavor." | wc -l`
483     if [ $nrule_new != $nrule_old ]; then
484         error "general rule: $nrule_new != $nrule_old"
485     fi
486
487     #
488     # target-specific rules
489     #
490     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
491                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
492     echo "original target rules: $nrule_old"
493
494     for ((i = $nrule_old; i < $max; i++)); do
495         set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
496     done
497     for ((i = $nrule_old; i < $max; i++)); do
498         set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
499     done
500
501     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
502                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
503     if [ $nrule_new != $nrule_old ]; then
504         error "general rule: $nrule_new != $nrule_old"
505     fi
506 }
507 run_test 99 "set large number of sptlrpc rules"
508
509 error_dbench()
510 {
511     local err_str=$1
512
513     killall -9 dbench
514     sleep 1
515
516     error $err_str
517 }
518
519 test_100() {
520     # started from default flavors
521     restore_to_default_flavor
522
523     # running dbench background
524     start_dbench
525
526     #
527     # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
528     #
529     set_rule $FSNAME any any krb5n
530     wait_flavor all2all krb5n || error_dbench "1"
531     check_dbench
532
533     set_rule $FSNAME any any krb5a
534     wait_flavor all2all krb5a || error_dbench "2"
535     check_dbench
536
537     set_rule $FSNAME any any krb5i
538     wait_flavor all2all krb5i || error_dbench "3"
539     check_dbench
540
541     set_rule $FSNAME any any krb5p
542     wait_flavor all2all krb5p || error_dbench "4"
543     check_dbench
544
545     set_rule $FSNAME any any plain
546     wait_flavor all2all plain || error_dbench "5"
547     check_dbench
548
549     #
550     # M - M: krb5a
551     # C - M: krb5i
552     # M - O: krb5p
553     # C - O: krb5n
554     #
555     set_rule $FSNAME any mdt2mdt krb5a
556     wait_flavor mdt2mdt krb5a || error_dbench "6"
557     check_dbench
558
559     set_rule $FSNAME any cli2mdt krb5i
560     wait_flavor cli2mdt krb5i || error_dbench "7"
561     check_dbench
562
563     set_rule $FSNAME any mdt2ost krb5p
564     wait_flavor mdt2ost krb5p || error_dbench "8"
565     check_dbench
566
567     set_rule $FSNAME any cli2ost krb5n
568     wait_flavor cli2ost krb5n || error_dbench "9"
569     check_dbench
570
571     #
572     # * - MDT0: krb5p
573     # * - OST0: krb5i
574     #
575     # nothing should be changed because they are override by above dir rules
576     #
577     set_rule $FSNAME-MDT0000 any any krb5p
578     set_rule $FSNAME-OST0000 any any krb5i
579     wait_flavor mdt2mdt krb5a || error_dbench "10"
580     wait_flavor cli2mdt krb5i || error_dbench "11"
581     check_dbench
582     wait_flavor mdt2ost krb5p || error_dbench "12"
583     wait_flavor cli2ost krb5n || error_dbench "13"
584
585     #
586     # delete all dir-specific rules
587     #
588     set_rule $FSNAME any mdt2mdt
589     set_rule $FSNAME any cli2mdt
590     set_rule $FSNAME any mdt2ost
591     set_rule $FSNAME any cli2ost
592     wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
593     wait_flavor cli2mdt krb5p $(get_clients_mount_count) || error_dbench "15"
594     check_dbench
595     wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
596     wait_flavor cli2ost krb5i $(get_clients_mount_count) || error_dbench "17"
597     check_dbench
598
599     #
600     # remove:
601     #  * - MDT0: krb5p
602     #  * - OST0: krb5i
603     #
604     set_rule $FSNAME-MDT0000 any any
605     set_rule $FSNAME-OST0000 any any || error_dbench "18"
606     wait_flavor all2all plain || error_dbench "19"
607     check_dbench
608
609     stop_dbench
610 }
611 run_test 100 "change security flavor on the fly under load"
612
613 switch_sec_test()
614 {
615     local flavor0=$1
616     local flavor1=$2
617     local filename=$DIR/$tfile
618     local multiop_pid
619     local num
620
621     #
622     # after set to flavor0, start multop which use flavor0 rpc, and let
623     # server drop the reply; then switch to flavor1, the resend should be
624     # completed using flavor1. To exercise the code of switching ctx/sec
625     # for a resend request.
626     #
627     log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
628
629     set_rule $FSNAME any cli2mdt $flavor0
630     wait_flavor cli2mdt $flavor0
631     rm -f $filename || error "remove old $filename failed"
632
633 #MDS_REINT = 36
634 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
635     do_facet $SINGLEMDS lctl set_param fail_val=36
636     do_facet $SINGLEMDS lctl set_param fail_loc=0x513
637     log "starting multiop"
638     $MULTIOP $filename m &
639     multiop_pid=$!
640     echo "multiop pid=$multiop_pid"
641     sleep 1
642
643     set_rule $FSNAME any cli2mdt $flavor1
644     wait_flavor cli2mdt $flavor1
645
646     num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
647     [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
648     echo "process $multiop_pid is still hanging there... OK"
649
650     do_facet $SINGLEMDS lctl set_param fail_loc=0
651     log "waiting for multiop ($multiop_pid) to finish"
652     wait $multiop_pid || error "multiop returned error"
653 }
654
655 test_101()
656 {
657     # started from default flavors
658     restore_to_default_flavor
659
660     switch_sec_test null  plain
661     switch_sec_test plain krb5n
662     switch_sec_test krb5n krb5a
663     switch_sec_test krb5a krb5i
664     switch_sec_test krb5i krb5p
665     switch_sec_test krb5p null
666     switch_sec_test null  krb5p
667     switch_sec_test krb5p krb5i
668     switch_sec_test krb5i plain
669     switch_sec_test plain krb5p
670 }
671 run_test 101 "switch ctx/sec for resending request"
672
673 error_102()
674 {
675     local err_str=$1
676
677     killall -9 dbench
678     sleep 1
679
680     error $err_str
681 }
682
683 test_102() {
684     # started from default flavors
685     restore_to_default_flavor
686
687     # run dbench background
688     start_dbench
689
690     echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
691     set_rule $FSNAME any any krb5n
692     set_rule $FSNAME any any krb5a
693     set_rule $FSNAME any any krb5i
694     set_rule $FSNAME any any krb5p
695     set_rule $FSNAME any any plain
696     set_rule $FSNAME any any null
697
698     check_dbench
699     wait_flavor all2all null || error_dbench "1"
700     check_dbench
701
702     echo "waiting for 15s and check again"
703     sleep 15
704     check_dbench
705
706     echo "Testing null->krb5i->null->krb5i->null..."
707     for ((i=0; i<10; i++)); do
708         set_rule $FSNAME any any krb5i
709         set_rule $FSNAME any any null
710     done
711     set_rule $FSNAME any any krb5i
712
713     check_dbench
714     wait_flavor all2all krb5i || error_dbench "2"
715     check_dbench
716
717     echo "waiting for 15s and check again"
718     sleep 15
719     check_dbench
720
721     stop_dbench
722 }
723 run_test 102 "survive from insanely fast flavor switch"
724
725 test_150() {
726     local save_opts
727     local count
728     local clients=$CLIENTS
729
730     [ -z $clients ] && clients=$HOSTNAME
731
732     # started from default flavors
733     restore_to_default_flavor
734
735     # at this time no rules has been set on mgs; mgc use null
736     # flavor connect to mgs.
737     count=`flvr_cnt_mgc2mgs null`
738     [ $count -eq 1 ] || error "$count mgc connection use null flavor"
739
740     zconf_umount_clients $clients $MOUNT || return 1
741
742     # mount client with conflict flavor - should fail
743     save_opts=$MOUNTOPT
744     MOUNTOPT="$MOUNTOPT,mgssec=krb5p"
745     zconf_mount_clients $clients $MOUNT && \
746         error "mount with conflict flavor should have failed"
747     MOUNTOPT=$save_opts
748
749     # mount client with same flavor - should succeed
750     save_opts=$MOUNTOPT
751     MOUNTOPT="$MOUNTOPT,mgssec=null"
752     zconf_mount_clients $clients $MOUNT || \
753         error "mount with same flavor should have succeeded"
754     MOUNTOPT=$save_opts
755     zconf_umount_clients $clients $MOUNT || return 2
756
757     # mount client with default flavor - should succeed
758     zconf_mount_clients $clients $MOUNT || \
759         error "mount with default flavor should have succeeded"
760 }
761 run_test 150 "secure mgs connection: client flavor setting"
762
763 test_151() {
764     local save_opts
765
766     # set mgs only accept krb5p
767     set_rule _mgs any any krb5p
768
769     # umount everything, modules still loaded
770     stopall
771
772     # mount mgs with default flavor, in current framework it means mgs+mdt1.
773     # the connection of mgc of mdt1 to mgs is expected fail.
774     DEVNAME=$(mdsdevname 1)
775     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
776
777     # mount with unauthorized flavor should fail
778     save_opts=$MDS_MOUNT_OPTS
779     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
780     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
781     MDS_MOUNT_OPTS=$save_opts
782
783     # mount with designated flavor should succeed
784     save_opts=$MDS_MOUNT_OPTS
785     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=krb5p"
786     start mds1 $DEVNAME $MDS_MOUNT_OPTS || error "mount with designated flavor should have succeeded"
787     MDS_MOUNT_OPTS=$save_opts
788
789     stop mds1 -f
790 }
791 run_test 151 "secure mgs connection: server flavor control"
792
793 complete $SECONDS
794 check_and_cleanup_lustre
795 exit_status