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