Whamcloud - gitweb
land b_colibri_devel on HEAD:
[fs/lustre-release.git] / lustre / tests / sanity-gss.sh
1 #!/bin/bash
2 # vim:expandtab: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 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
16
17 # Tests that fail on uml
18 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT"
20
21 case `uname -r` in
22 2.6*) FSTYPE=${FSTYPE:-ldiskfs}; ALWAYS_EXCEPT="$ALWAYS_EXCEPT " ;;
23 *) error "unsupported kernel (gss only works with 2.6.x)" ;;
24 esac
25
26 SRCDIR=`dirname $0`
27 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
28 export NAME=${NAME:-local}
29 SAVE_PWD=$PWD
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
39 if [ $UID -ne 0 ]; then
40     echo "Warning: running as non-root uid $UID"
41     RUNAS_ID="$UID"
42     RUNAS=""
43 else
44     RUNAS_ID=${RUNAS_ID:-500}
45     RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
46
47     # $RUNAS_ID may get set incorrectly somewhere else
48     [ $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
49 fi
50
51 # remove $SEC, we'd like to control everything by ourselves
52 unset SEC
53
54 #
55 # global variables of this sanity
56 #
57 KRB5_CCACHE_DIR=/tmp
58 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
59 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
60 CLICOUNT=2
61 cnt_mdt2ost=0
62 cnt_mdt2mdt=0
63 cnt_cli2ost=0
64 cnt_cli2mdt=0
65 cnt_all2ost=0
66 cnt_all2mdt=0
67 cnt_all2all=0
68 DBENCH_PID=0
69 PROC_CLI="srpc.info"
70
71 # set manually
72 GSS=true
73 GSS_KRB5=true
74
75 # we want double mount
76 MOUNT_2=${MOUNT_2:-"yes"}
77 cleanup_and_setup_lustre
78
79 rm -rf $DIR/${TESTSUITE}/[df][0-9]*
80 rm -rf $DIR/[df][0-9]*
81
82 check_runas_id $RUNAS_ID $RUNAS
83
84 build_test_filter
85
86 prepare_krb5_creds() {
87     rm -f $KRB5_CRED_SAVE
88     $RUNAS krb5_login.sh || exit 1
89     [ -f $KRB5_CRED ] || exit 2
90     cp $KRB5_CRED $KRB5_CRED_SAVE
91 }
92
93 combination()
94 {
95     local M=$1
96     local N=$2
97     local R=1
98
99     if [ $M -lt $N ]; then
100         R=0
101     else
102         N=$((N + 1))
103         while [ $N -le $M ]; do
104             R=$((R * N))
105             N=$((N + 1))
106         done
107     fi
108
109     echo $R
110     return 0
111 }
112
113 calc_connection_cnt() {
114     # MDT->MDT = 2 * C(M, 2)
115     # MDT->OST = M * O
116     # CLI->OST = C * O
117     # CLI->MDT = C * M
118     comb_m2=$(combination $MDSCOUNT 2)
119
120     cnt_mdt2mdt=$((comb_m2 * 2))
121     cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
122     cnt_cli2ost=$((CLICOUNT * OSTCOUNT))
123     cnt_cli2mdt=$((CLICOUNT * MDSCOUNT))
124     cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
125     cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
126     cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
127 }
128
129 set_rule()
130 {
131     local tgt=$1
132     local net=$2
133     local dir=$3
134     local flavor=$4
135     local cmd="$tgt.srpc.flavor"
136
137     if [ $net == "any" ]; then
138         net="default"
139     fi
140     cmd="$cmd.$net"
141
142     if [ $dir != "any" ]; then
143         cmd="$cmd.$dir"
144     fi
145
146     cmd="$cmd=$flavor"
147     log "Setting sptlrpc rule: $cmd"
148     do_facet mgs "$LCTL conf_param $cmd"
149 }
150
151 count_flvr()
152 {
153     output=$1
154     flavor=$2
155
156     echo "$output" | grep rpc | grep $flavor | wc -l
157 }
158
159 flvr_cnt_cli2mdt()
160 {
161     local flavor=$1
162
163     output=`do_facet client cat $LPROC/mdc/*-MDT*-mdc-*/$PROC_CLI 2>/dev/null`
164     count_flvr "$output" $flavor
165 }
166
167 flvr_cnt_cli2ost()
168 {
169     local flavor=$1
170
171     output=`do_facet client cat $LPROC/osc/*OST*-osc-[^M][^D][^T]*/$PROC_CLI 2>/dev/null`
172     count_flvr "$output" $flavor
173 }
174
175 flvr_cnt_mdt2mdt()
176 {
177     local flavor=$1
178     local cnt=0
179
180     if [ $MDSCOUNT -le 1 ]; then
181         echo 0
182         return
183     fi
184
185     for num in `seq $MDSCOUNT`; do
186         output=`do_facet mds$num cat $LPROC/mdc/*-MDT*-mdc[0-9]*/$PROC_CLI 2>/dev/null`
187         tmpcnt=`count_flvr "$output" $flavor`
188         cnt=$((cnt + tmpcnt))
189     done
190     echo $cnt;
191 }
192
193 flvr_cnt_mdt2ost()
194 {
195     local flavor=$1
196     local cnt=0
197
198     for num in `seq $MDSCOUNT`; do
199         output=`do_facet mds$num cat $LPROC/osc/*OST*-osc-MDT*/$PROC_CLI 2>/dev/null`
200         tmpcnt=`count_flvr "$output" $flavor`
201         cnt=$((cnt + tmpcnt))
202     done
203     echo $cnt;
204 }
205
206 do_check_flavor()
207 {
208     local dir=$1        # from to
209     local flavor=$2     # flavor expected
210     local res=0
211
212     if [ $dir == "cli2mdt" ]; then
213         res=`flvr_cnt_cli2mdt $flavor`
214     elif [ $dir == "cli2ost" ]; then
215         res=`flvr_cnt_cli2ost $flavor`
216     elif [ $dir == "mdt2mdt" ]; then
217         res=`flvr_cnt_mdt2mdt $flavor`
218     elif [ $dir == "mdt2ost" ]; then
219         res=`flvr_cnt_mdt2ost $flavor`
220     elif [ $dir == "all2ost" ]; then
221         res1=`flvr_cnt_mdt2ost $flavor`
222         res2=`flvr_cnt_cli2ost $flavor`
223         res=$((res1 + res2))
224     elif [ $dir == "all2mdt" ]; then
225         res1=`flvr_cnt_mdt2mdt $flavor`
226         res2=`flvr_cnt_cli2mdt $flavor`
227         res=$((res1 + res2))
228     elif [ $dir == "all2all" ]; then
229         res1=`flvr_cnt_mdt2ost $flavor`
230         res2=`flvr_cnt_cli2ost $flavor`
231         res3=`flvr_cnt_mdt2mdt $flavor`
232         res4=`flvr_cnt_cli2mdt $flavor`
233         res=$((res1 + res2 + res3 + res4))
234     fi
235
236     echo $res
237 }
238
239 wait_flavor()
240 {
241     local dir=$1        # from to
242     local flavor=$2     # flavor expected
243     local expect=$3     # number expected
244     local res=0
245
246     for ((i=0;i<20;i++)); do
247         echo -n "checking..."
248         res=$(do_check_flavor $dir $flavor)
249         if [ $res -eq $expect ]; then
250             echo "found $res $flavor connections of $dir, OK"
251             return 0
252         else
253             echo "found $res $flavor connections of $dir, not ready ($expect)"
254             sleep 4
255         fi
256     done
257
258     echo "Error checking $flavor of $dir: expect $expect, actual $res"
259     return 1
260 }
261
262 restore_to_default_flavor()
263 {
264     local proc=$LPROC/mgs/MGS/live/$FSNAME
265
266     echo "restoring to default flavor..."
267
268     nrule=`do_facet mgs cat $proc 2>/dev/null | grep "$FSNAME.srpc.flavor." | wc -l`
269
270     # remove all existing rules if any
271     if [ $nrule -ne 0 ]; then
272         echo "remove existing $nrule rules"
273         for rule in `do_facet mgs cat $proc 2>/dev/null | grep "$FSNAME.srpc.flavor."`; do
274             spec=`echo $rule | awk -F = '{print $1}'`
275             do_facet mgs "$LCTL conf_param $spec="
276         done
277     fi
278
279     # verify no rules left
280     nrule=`do_facet mgs cat $proc 2>/dev/null | grep "$FSNAME.srpc.flavor." | wc -l`
281     [ $nrule -ne 0 ] && error "still $nrule rules left"
282
283     # wait for default flavor to be applied
284     # currently default flavor for all connections are 'null'
285     wait_flavor all2all null $cnt_all2all
286     echo "now at default flavor settings"
287 }
288
289 set_flavor_all()
290 {
291     local flavor=$1
292
293     echo "setting all flavor to $flavor"
294
295     res=$(do_check_flavor all2all $flavor)
296     if [ $res -eq $cnt_all2all ]; then
297         echo "already have total $res $flavor connections"
298         return
299     fi
300
301     echo "found $res $flavor out of total $cnt_all2all connections"
302     restore_to_default_flavor
303
304     set_rule $FSNAME any any $flavor
305     wait_flavor all2all $flavor $cnt_all2all
306 }
307
308 start_dbench()
309 {
310     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
311     [ $NPROC -lt 2 ] && NPROC=2
312     sh rundbench $NPROC 1>/dev/null &
313     DBENCH_PID=$!
314     sleep 2
315
316     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
317     if [ $num -ne 1 ]; then
318         error "failed to start dbench $NPROC"
319     else
320         echo "started dbench with $NPROC processes at background"
321     fi
322
323     return 0
324 }
325
326 check_dbench()
327 {
328     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
329     if [ $num -eq 0 ]; then
330         echo "dbench $DBENCH_PID already finished"
331         wait $DBENCH_PID || error "dbench $PID exit with error"
332         start_dbench
333     elif [ $num -ne 1 ]; then
334         killall -9 dbench
335         error "found $num instance of pid $DBENCH_PID ???"
336     fi
337
338     return 0
339 }
340
341 stop_dbench()
342 {
343     for ((;;)); do
344         killall dbench 2>/dev/null
345         num=`ps --no-headers -p $DBENCH_PID | wc -l`
346         if [ $num -eq 0 ]; then
347             echo "dbench finished"
348             break
349         fi
350         echo "dbench $DBENCH_PID is still running, waiting 2s..."
351         sleep 2
352     done
353
354     wait $DBENCH_PID || true
355     sync || true
356 }
357
358 restore_krb5_cred() {
359     cp $KRB5_CRED_SAVE $KRB5_CRED
360     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
361     chmod 0600 $KRB5_CRED
362 }
363
364 check_multiple_gss_daemons() {
365     local facet=$1
366     local gssd=$2
367     local gssd_name=`basename $gssd`
368
369     for ((i=0;i<10;i++)); do
370         do_facet $facet "$gssd -v &"
371     done
372
373     # wait daemons entering "stable" status
374     sleep 5
375
376     num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
377     echo "$num instance(s) of $gssd_name are running"
378
379     if [ $num -ne 1 ]; then
380         error "$gssd_name not unique"
381     fi
382 }
383
384 prepare_krb5_creds
385 calc_connection_cnt
386 umask 077
387
388 test_0() {
389     local my_facet=mds
390
391     echo "bring up gss daemons..."
392     start_gss_daemons
393
394     echo "check with someone already running..."
395     check_multiple_gss_daemons $my_facet $LSVCGSSD
396     if $GSS_PIPEFS; then
397         check_multiple_gss_daemons $my_facet $LGSSD
398     fi
399
400     echo "check with someone run & finished..."
401     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
402     sleep 5 # wait fully exit
403     check_multiple_gss_daemons $my_facet $LSVCGSSD
404     if $GSS_PIPEFS; then
405         check_multiple_gss_daemons $my_facet $LGSSD
406     fi
407
408     echo "check refresh..."
409     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
410     sleep 5 # wait fully exit
411     do_facet $my_facet ipcrm -S 0x3b92d473
412     check_multiple_gss_daemons $my_facet $LSVCGSSD
413     if $GSS_PIPEFS; then
414         do_facet $my_facet ipcrm -S 0x3a92d473
415         check_multiple_gss_daemons $my_facet $LGSSD
416     fi
417 }
418 run_test 0 "start multiple gss daemons"
419
420 set_flavor_all krb5p
421
422 test_1() {
423     local file=$DIR/$tfile
424
425     chmod 0777 $DIR || error "chmod $DIR failed"
426     # access w/o cred
427     $RUNAS kdestroy
428     $RUNAS touch $file && error "unexpected success"
429
430     # access w/ cred
431     restore_krb5_cred
432     $RUNAS touch $file || error "should not fail"
433     [ -f $file ] || error "$file not found"
434 }
435 run_test 1 "access with or without krb5 credential"
436
437 test_2() {
438     local file1=$DIR/$tfile-1
439     local file2=$DIR/$tfile-2
440
441     chmod 0777 $DIR || error "chmod $DIR failed"
442     # current access should be ok
443     $RUNAS touch $file1 || error "can't touch $file1"
444     [ -f $file1 ] || error "$file1 not found"
445
446     # cleanup all cred/ctx and touch
447     $RUNAS kdestroy
448     $RUNAS $LFS flushctx || error "can't flush ctx"
449     $RUNAS touch $file2 && error "unexpected success"
450
451     # restore and touch
452     restore_krb5_cred
453     $RUNAS touch $file2 || error "should not fail"
454     [ -f $file2 ] || error "$file2 not found"
455 }
456 run_test 2 "lfs flushctx"
457
458 test_3() {
459     local file=$DIR/$tfile
460
461     # create file
462     echo "aaaaaaaaaaaaaaaaa" > $file
463     chmod 0666 $file
464     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
465     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
466     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
467
468     # start multiop
469     $RUNAS multiop $file o_r &
470     OPPID=$!
471     # wait multiop finish its open()
472     sleep 1
473
474     # cleanup all cred/ctx and check
475     # metadata check should fail, but file data check should success
476     # because we always use root credential to OSTs
477     $RUNAS kdestroy
478     $RUNAS $LFS flushctx
479     echo "destroied credentials/contexs for $RUNAS_ID"
480     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
481     kill -s 10 $OPPID
482     wait $OPPID || error "read file data failed"
483     echo "read file data OK"
484
485     # restore and check again
486     restore_krb5_cred
487     echo "restored credentials for $RUNAS_ID"
488     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
489     echo "$RUNAS_ID checkstat OK"
490     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
491     echo "$UID checkstat OK"
492     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
493     echo "$RUNAS_ID read file data OK"
494 }
495 run_test 3 "local cache under DLM lock"
496
497 test_4() {
498     local file1=$DIR/$tfile-1
499     local file2=$DIR/$tfile-2
500
501     ! $GSS_PIPEFS && skip "pipefs not used" && return
502
503     chmod 0777 $DIR || error "chmod $DIR failed"
504     # current access should be ok
505     $RUNAS touch $file1 || error "can't touch $file1"
506     [ -f $file1 ] || error "$file1 not found"
507
508     # stop lgssd
509     send_sigint client lgssd
510     sleep 5
511     check_gss_daemon_facet client lgssd && error "lgssd still running"
512
513     # flush context, and touch
514     $RUNAS $LFS flushctx
515     $RUNAS touch $file2 &
516     TOUCHPID=$!
517     echo "waiting touch pid $TOUCHPID"
518     wait $TOUCHPID && error "touch should fail"
519
520     # restart lgssd
521     do_facet client "$LGSSD -v"
522     sleep 5
523     check_gss_daemon_facet client lgssd
524
525     # touch new should succeed
526     $RUNAS touch $file2 || error "can't touch $file2"
527     [ -f $file2 ] || error "$file2 not found"
528 }
529 run_test 4 "lgssd dead, operations should wait timeout and fail"
530
531 test_5() {
532     local file1=$DIR/$tfile-1
533     local file2=$DIR/$tfile-2
534     local wait_time=$((TIMEOUT + TIMEOUT / 2))
535
536     chmod 0777 $DIR || error "chmod $DIR failed"
537     # current access should be ok
538     $RUNAS touch $file1 || error "can't touch $file1"
539     [ -f $file1 ] || error "$file1 not found"
540
541     # stop lsvcgssd
542     send_sigint mds lsvcgssd
543     sleep 5
544     check_gss_daemon_facet mds lsvcgssd && error "lsvcgssd still running"
545
546     # flush context, and touch
547     $RUNAS $LFS flushctx
548     $RUNAS touch $file2 &
549     TOUCHPID=$!
550
551     # wait certain time
552     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
553     sleep $wait_time
554     num=`ps --no-headers -p $TOUCHPID | wc -l`
555     [ $num -eq 1 ] || error "touch already ended ($num)"
556     echo "process $TOUCHPID still hanging there... OK"
557
558     # restart lsvcgssd, expect touch suceed
559     echo "restart lsvcgssd and recovering"
560     do_facet mds "$LSVCGSSD -v"
561     sleep 5
562     check_gss_daemon_facet mds lsvcgssd
563     wait $TOUCHPID || error "touch fail"
564     [ -f $file2 ] || error "$file2 not found"
565 }
566 run_test 5 "lsvcgssd dead, operations lead to recovery"
567
568 test_6() {
569     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
570     cp -a /etc/* $DIR/d6/ || error "cp failed"
571     ls -l $DIR/d6/* > /dev/null || error "ls failed"
572     rm -rf $DIR2/d6/* || error "rm failed"
573 }
574 run_test 6 "test basic DLM callback works"
575
576 test_7() {
577     local tdir=$DIR/d7
578     local num_osts
579
580     #
581     # for open(), client only reserve space for default stripe count lovea,
582     # and server may return larger lovea in reply (because of larger stripe
583     # count), client need call enlarge_reqbuf() and save the replied lovea
584     # in request for future possible replay.
585     #
586     # Note: current script does NOT guarantee enlarge_reqbuf() will be in
587     # the path, however it does work in local test which has 2 OSTs and
588     # default stripe count is 1.
589     #
590     num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
591     echo "found $num_osts active OSTs"
592     [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
593
594     mkdir $tdir || error
595     $LFS setstripe $tdir 0 -1 -1 || error
596
597     echo "creating..."
598     for ((i=0;i<20;i++)); do
599         dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
600     done
601     echo "reading..."
602     for ((i=0;i<20;i++)); do
603         dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
604     done
605     rm -rf $tdir
606 }
607 run_test 7 "exercise enlarge_reqbuf()"
608
609 test_90() {
610     if [ "$SLOW" = "no" ]; then
611         total=10
612     else
613         total=60
614     fi
615
616     start_dbench
617
618     for ((n=0;n<$total;n++)); do
619         sleep 2
620         check_dbench
621         echo "flush ctx ($n/$total) ..."
622         $LFS flushctx
623     done
624     check_dbench
625     stop_dbench
626 }
627 run_test 90 "recoverable from losing contexts under load"
628
629 test_99() {
630     local nrule_old=0
631     local nrule_new=0
632     local max=32
633
634     #
635     # general rules
636     #
637     nrule_old=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
638                | grep "$FSNAME.srpc.flavor." | wc -l`
639     echo "original general rules: $nrule_old"
640
641     for ((i = $nrule_old; i < $max; i++)); do
642         set_rule $FSNAME elan$i any krb5n || error "set rule $i"
643     done
644     set_rule $FSNAME elan100 any krb5n && error "set $max rule should fail"
645     for ((i = $nrule_old; i < $max; i++)); do
646         set_rule $FSNAME elan$i any || error "remove rule $i"
647     done
648
649     nrule_new=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
650                | grep "$FSNAME.srpc.flavor." | wc -l`
651     if [ $nrule_new != $nrule_old ]; then
652         error "general rule: $nrule_new != $nrule_old"
653     fi
654
655     #
656     # target-specific rules
657     #
658     nrule_old=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
659                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
660     echo "original target rules: $nrule_old"
661
662     for ((i = $nrule_old; i < $max; i++)); do
663         set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
664     done
665     set_rule $FSNAME-MDT0000 elan100 any krb5i && error "set $max rule should fail"
666     for ((i = $nrule_old; i < $max; i++)); do
667         set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
668     done
669
670     nrule_new=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
671                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
672     if [ $nrule_new != $nrule_old ]; then
673         error "general rule: $nrule_new != $nrule_old"
674     fi
675 }
676 run_test 99 "maximum sptlrpc rules limitation"
677
678 error_dbench()
679 {
680     local err_str=$1
681
682     killall -9 dbench
683     sleep 1
684
685     error $err_str
686 }
687
688 test_100() {
689     # started from default flavors
690     restore_to_default_flavor
691
692     # running dbench background
693     start_dbench
694
695     #
696     # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
697     #
698     set_rule $FSNAME any any krb5n
699     wait_flavor all2all krb5n $cnt_all2all || error_dbench "1"
700     check_dbench
701
702     set_rule $FSNAME any any krb5a
703     wait_flavor all2all krb5a $cnt_all2all || error_dbench "2"
704     check_dbench
705
706     set_rule $FSNAME any any krb5i
707     wait_flavor all2all krb5i $cnt_all2all || error_dbench "3"
708     check_dbench
709
710     set_rule $FSNAME any any krb5p
711     wait_flavor all2all krb5p $cnt_all2all || error_dbench "4"
712     check_dbench
713
714     set_rule $FSNAME any any plain
715     wait_flavor all2all plain $cnt_all2all || error_dbench "5"
716     check_dbench
717
718     #
719     # M - M: krb5a
720     # C - M: krb5i
721     # M - O: krb5p
722     # C - O: krb5n
723     #
724     set_rule $FSNAME any mdt2mdt krb5a
725     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "6"
726     check_dbench
727
728     set_rule $FSNAME any cli2mdt krb5i
729     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "7"
730     check_dbench
731
732     set_rule $FSNAME any mdt2ost krb5p
733     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "8"
734     check_dbench
735
736     set_rule $FSNAME any cli2ost krb5n
737     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "9"
738     check_dbench
739
740     #
741     # * - MDT0: krb5p
742     # * - OST0: krb5i
743     #
744     # nothing should be changed because they are override by above dir rules
745     #
746     set_rule $FSNAME-MDT0000 any any krb5p
747     set_rule $FSNAME-OST0000 any any krb5i
748     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "10"
749     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "11"
750     check_dbench
751     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "12"
752     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "13"
753
754     #
755     # delete all dir-specific rules
756     #
757     set_rule $FSNAME any mdt2mdt
758     set_rule $FSNAME any cli2mdt
759     set_rule $FSNAME any mdt2ost
760     set_rule $FSNAME any cli2ost
761     wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
762     wait_flavor cli2mdt krb5p $CLICOUNT || error_dbench "15"
763     check_dbench
764     wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
765     wait_flavor cli2ost krb5i $CLICOUNT || error_dbench "17"
766     check_dbench
767
768     #
769     # remove:
770     #  * - MDT0: krb5p
771     #  * - OST0: krb5i
772     #
773     set_rule $FSNAME-MDT0000 any any
774     set_rule $FSNAME-OST0000 any any || error_dbench "18"
775     wait_flavor all2all plain $cnt_all2all || error_dbench "19"
776     check_dbench
777
778     stop_dbench
779 }
780 run_test 100 "change security flavor on the fly under load"
781
782 switch_sec_test()
783 {
784     local count=$1
785     local flavor0=$2
786     local flavor1=$3
787     local flavor2=$4
788     local df_pid=0
789     local wait_time=$((TIMEOUT + TIMEOUT / 4))
790     local num
791
792     #
793     # stop gss daemon, then switch to flavor1 (which should be a gss flavor),
794     # and run a 'df' which should hanging, wait the request timeout and
795     # resend, then switch the flavor to another one. To exercise the code of
796     # switching ctx/sec for a resend request.
797     #
798     echo ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 -> $flavor2..."
799
800     echo "(0) set base flavor $flavor0"
801     set_rule $FSNAME any cli2mdt $flavor0
802     wait_flavor cli2mdt $flavor0 $count
803     df $MOUNT
804     if [ $? -ne 0 ]; then
805         error "initial df failed"
806     fi
807
808     stop_gss_daemons
809     sleep 1
810
811     echo "(1) $flavor0 -> $flavor1"
812     set_rule $FSNAME any cli2mdt $flavor1
813     wait_flavor cli2mdt $flavor1 $count
814     df $MOUNT &
815     df_pid=$!
816     sleep 1
817
818     echo "waiting $wait_time seconds for df ($df_pid)"
819     sleep $wait_time
820     num=`ps --no-headers -p $df_pid 2>/dev/null | wc -l`
821     [ $num -eq 1 ] || error "df already ended ($num)"
822     echo "process $df_pid is still hanging there... OK"
823
824     echo "(2) set end flavor $flavor2"
825     set_rule $FSNAME any cli2mdt $flavor2
826     wait_flavor cli2mdt $flavor2 $count
827     start_gss_daemons
828     wait $df_pid || error "df returned error"
829 }
830
831 test_101()
832 {
833     # started from default flavors
834     restore_to_default_flavor
835
836     switch_sec_test $cnt_cli2mdt null krb5n null
837     switch_sec_test $cnt_cli2mdt null krb5a null
838     switch_sec_test $cnt_cli2mdt null krb5i null
839     switch_sec_test $cnt_cli2mdt null krb5p null
840     switch_sec_test $cnt_cli2mdt null krb5i plain
841     switch_sec_test $cnt_cli2mdt plain krb5p plain
842     switch_sec_test $cnt_cli2mdt plain krb5n krb5a
843     switch_sec_test $cnt_cli2mdt krb5a krb5i krb5p
844     switch_sec_test $cnt_cli2mdt krb5p krb5a krb5n
845     switch_sec_test $cnt_cli2mdt krb5n krb5p krb5i
846 }
847 run_test 101 "switch ctx as well as sec for resending request"
848
849 error_102()
850 {
851     local err_str=$1
852
853     killall -9 dbench
854     sleep 1
855
856     error $err_str
857 }
858
859 test_102() {
860     # started from default flavors
861     restore_to_default_flavor
862
863     # run dbench background
864     start_dbench
865
866     echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
867     set_rule $FSNAME any any krb5n
868     set_rule $FSNAME any any krb5a
869     set_rule $FSNAME any any krb5i
870     set_rule $FSNAME any any krb5p
871     set_rule $FSNAME any any plain
872     set_rule $FSNAME any any null
873
874     check_dbench
875     wait_flavor all2all null $cnt_all2all || error_dbench "1"
876     check_dbench
877
878     echo "waiting for 15s and check again"
879     sleep 15
880     check_dbench
881
882     echo "Testing null->krb5i->null->krb5i->null..."
883     for ((i=0; i<10; i++)); do
884         set_rule $FSNAME any any krb5i
885         set_rule $FSNAME any any null
886     done
887     set_rule $FSNAME any any krb5i
888
889     check_dbench
890     wait_flavor all2all krb5i $cnt_all2all || error_dbench "2"
891     check_dbench
892
893     echo "waiting for 15s and check again"
894     sleep 15
895     check_dbench
896
897     stop_dbench
898 }
899 run_test 102 "survive from insanely fast flavor switch"
900
901 equals_msg `basename $0`: test complete, cleaning up
902 check_and_cleanup_lustre
903 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true