Whamcloud - gitweb
branch: 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 ".srpc.flavor." | wc -l`
269
270     # remove all existing rules if any
271     if [ $nrule -ne 0 ]; then
272         echo "$nrule existing rules"
273         for rule in `do_facet mgs cat $proc 2>/dev/null | grep ".srpc.flavor."`; do
274             echo "remove rule: $rule"
275             spec=`echo $rule | awk -F = '{print $1}'`
276             do_facet mgs "$LCTL conf_param $spec="
277         done
278     fi
279
280     # verify no rules left
281     nrule=`do_facet mgs cat $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
282     [ $nrule -ne 0 ] && error "still $nrule rules left"
283
284     # wait for default flavor to be applied
285     # currently default flavor for all connections are 'null'
286     wait_flavor all2all null $cnt_all2all
287     echo "now at default flavor settings"
288 }
289
290 set_flavor_all()
291 {
292     local flavor=$1
293
294     echo "setting all flavor to $flavor"
295
296     res=$(do_check_flavor all2all $flavor)
297     if [ $res -eq $cnt_all2all ]; then
298         echo "already have total $res $flavor connections"
299         return
300     fi
301
302     echo "found $res $flavor out of total $cnt_all2all connections"
303     restore_to_default_flavor
304
305     set_rule $FSNAME any any $flavor
306     wait_flavor all2all $flavor $cnt_all2all
307 }
308
309 start_dbench()
310 {
311     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
312     [ $NPROC -lt 2 ] && NPROC=2
313     sh rundbench $NPROC 1>/dev/null &
314     DBENCH_PID=$!
315     sleep 2
316
317     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
318     if [ $num -ne 1 ]; then
319         error "failed to start dbench $NPROC"
320     else
321         echo "started dbench with $NPROC processes at background"
322     fi
323
324     return 0
325 }
326
327 check_dbench()
328 {
329     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
330     if [ $num -eq 0 ]; then
331         echo "dbench $DBENCH_PID already finished"
332         wait $DBENCH_PID || error "dbench $PID exit with error"
333         start_dbench
334     elif [ $num -ne 1 ]; then
335         killall -9 dbench
336         error "found $num instance of pid $DBENCH_PID ???"
337     fi
338
339     return 0
340 }
341
342 stop_dbench()
343 {
344     for ((;;)); do
345         killall dbench 2>/dev/null
346         num=`ps --no-headers -p $DBENCH_PID | wc -l`
347         if [ $num -eq 0 ]; then
348             echo "dbench finished"
349             break
350         fi
351         echo "dbench $DBENCH_PID is still running, waiting 2s..."
352         sleep 2
353     done
354
355     wait $DBENCH_PID || true
356     sync || true
357 }
358
359 restore_krb5_cred() {
360     cp $KRB5_CRED_SAVE $KRB5_CRED
361     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
362     chmod 0600 $KRB5_CRED
363 }
364
365 check_multiple_gss_daemons() {
366     local facet=$1
367     local gssd=$2
368     local gssd_name=`basename $gssd`
369
370     for ((i=0;i<10;i++)); do
371         do_facet $facet "$gssd -v &"
372     done
373
374     # wait daemons entering "stable" status
375     sleep 5
376
377     num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
378     echo "$num instance(s) of $gssd_name are running"
379
380     if [ $num -ne 1 ]; then
381         error "$gssd_name not unique"
382     fi
383 }
384
385 prepare_krb5_creds
386 calc_connection_cnt
387 umask 077
388
389 test_0() {
390     local my_facet=mds
391
392     echo "bring up gss daemons..."
393     start_gss_daemons
394
395     echo "check with someone already running..."
396     check_multiple_gss_daemons $my_facet $LSVCGSSD
397     if $GSS_PIPEFS; then
398         check_multiple_gss_daemons $my_facet $LGSSD
399     fi
400
401     echo "check with someone run & finished..."
402     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
403     sleep 5 # wait fully exit
404     check_multiple_gss_daemons $my_facet $LSVCGSSD
405     if $GSS_PIPEFS; then
406         check_multiple_gss_daemons $my_facet $LGSSD
407     fi
408
409     echo "check refresh..."
410     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
411     sleep 5 # wait fully exit
412     do_facet $my_facet ipcrm -S 0x3b92d473
413     check_multiple_gss_daemons $my_facet $LSVCGSSD
414     if $GSS_PIPEFS; then
415         do_facet $my_facet ipcrm -S 0x3a92d473
416         check_multiple_gss_daemons $my_facet $LGSSD
417     fi
418 }
419 run_test 0 "start multiple gss daemons"
420
421 set_flavor_all krb5p
422
423 test_1() {
424     local file=$DIR/$tfile
425
426     chmod 0777 $DIR || error "chmod $DIR failed"
427     # access w/o cred
428     $RUNAS kdestroy
429     $RUNAS touch $file && error "unexpected success"
430
431     # access w/ cred
432     restore_krb5_cred
433     $RUNAS touch $file || error "should not fail"
434     [ -f $file ] || error "$file not found"
435 }
436 run_test 1 "access with or without krb5 credential"
437
438 test_2() {
439     local file1=$DIR/$tfile-1
440     local file2=$DIR/$tfile-2
441
442     chmod 0777 $DIR || error "chmod $DIR failed"
443     # current access should be ok
444     $RUNAS touch $file1 || error "can't touch $file1"
445     [ -f $file1 ] || error "$file1 not found"
446
447     # cleanup all cred/ctx and touch
448     $RUNAS kdestroy
449     $RUNAS $LFS flushctx || error "can't flush ctx"
450     $RUNAS touch $file2 && error "unexpected success"
451
452     # restore and touch
453     restore_krb5_cred
454     $RUNAS touch $file2 || error "should not fail"
455     [ -f $file2 ] || error "$file2 not found"
456 }
457 run_test 2 "lfs flushctx"
458
459 test_3() {
460     local file=$DIR/$tfile
461
462     # create file
463     echo "aaaaaaaaaaaaaaaaa" > $file
464     chmod 0666 $file
465     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
466     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
467     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
468
469     # start multiop
470     $RUNAS multiop $file o_r &
471     OPPID=$!
472     # wait multiop finish its open()
473     sleep 1
474
475     # cleanup all cred/ctx and check
476     # metadata check should fail, but file data check should success
477     # because we always use root credential to OSTs
478     $RUNAS kdestroy
479     $RUNAS $LFS flushctx
480     echo "destroied credentials/contexs for $RUNAS_ID"
481     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
482     kill -s 10 $OPPID
483     wait $OPPID || error "read file data failed"
484     echo "read file data OK"
485
486     # restore and check again
487     restore_krb5_cred
488     echo "restored credentials for $RUNAS_ID"
489     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
490     echo "$RUNAS_ID checkstat OK"
491     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
492     echo "$UID checkstat OK"
493     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
494     echo "$RUNAS_ID read file data OK"
495 }
496 run_test 3 "local cache under DLM lock"
497
498 test_4() {
499     local file1=$DIR/$tfile-1
500     local file2=$DIR/$tfile-2
501
502     ! $GSS_PIPEFS && skip "pipefs not used" && return
503
504     chmod 0777 $DIR || error "chmod $DIR failed"
505     # current access should be ok
506     $RUNAS touch $file1 || error "can't touch $file1"
507     [ -f $file1 ] || error "$file1 not found"
508
509     # stop lgssd
510     send_sigint client lgssd
511     sleep 5
512     check_gss_daemon_facet client lgssd && error "lgssd still running"
513
514     # flush context, and touch
515     $RUNAS $LFS flushctx
516     $RUNAS touch $file2 &
517     TOUCHPID=$!
518     echo "waiting touch pid $TOUCHPID"
519     wait $TOUCHPID && error "touch should fail"
520
521     # restart lgssd
522     do_facet client "$LGSSD -v"
523     sleep 5
524     check_gss_daemon_facet client lgssd
525
526     # touch new should succeed
527     $RUNAS touch $file2 || error "can't touch $file2"
528     [ -f $file2 ] || error "$file2 not found"
529 }
530 run_test 4 "lgssd dead, operations should wait timeout and fail"
531
532 test_5() {
533     local file1=$DIR/$tfile-1
534     local file2=$DIR/$tfile-2
535     local wait_time=$((TIMEOUT + TIMEOUT / 2))
536
537     chmod 0777 $DIR || error "chmod $DIR failed"
538     # current access should be ok
539     $RUNAS touch $file1 || error "can't touch $file1"
540     [ -f $file1 ] || error "$file1 not found"
541
542     # stop lsvcgssd
543     send_sigint mds lsvcgssd
544     sleep 5
545     check_gss_daemon_facet mds lsvcgssd && error "lsvcgssd still running"
546
547     # flush context, and touch
548     $RUNAS $LFS flushctx
549     $RUNAS touch $file2 &
550     TOUCHPID=$!
551
552     # wait certain time
553     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
554     sleep $wait_time
555     num=`ps --no-headers -p $TOUCHPID | wc -l`
556     [ $num -eq 1 ] || error "touch already ended ($num)"
557     echo "process $TOUCHPID still hanging there... OK"
558
559     # restart lsvcgssd, expect touch suceed
560     echo "restart lsvcgssd and recovering"
561     do_facet mds "$LSVCGSSD -v"
562     sleep 5
563     check_gss_daemon_facet mds lsvcgssd
564     wait $TOUCHPID || error "touch fail"
565     [ -f $file2 ] || error "$file2 not found"
566 }
567 run_test 5 "lsvcgssd dead, operations lead to recovery"
568
569 test_6() {
570     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
571     cp -a /etc/* $DIR/d6/ || error "cp failed"
572     ls -l $DIR/d6/* > /dev/null || error "ls failed"
573     rm -rf $DIR2/d6/* || error "rm failed"
574 }
575 run_test 6 "test basic DLM callback works"
576
577 test_7() {
578     local tdir=$DIR/d7
579     local num_osts
580
581     #
582     # for open(), client only reserve space for default stripe count lovea,
583     # and server may return larger lovea in reply (because of larger stripe
584     # count), client need call enlarge_reqbuf() and save the replied lovea
585     # in request for future possible replay.
586     #
587     # Note: current script does NOT guarantee enlarge_reqbuf() will be in
588     # the path, however it does work in local test which has 2 OSTs and
589     # default stripe count is 1.
590     #
591     num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
592     echo "found $num_osts active OSTs"
593     [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
594
595     mkdir $tdir || error
596     $LFS setstripe $tdir 0 -1 -1 || error
597
598     echo "creating..."
599     for ((i=0;i<20;i++)); do
600         dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
601     done
602     echo "reading..."
603     for ((i=0;i<20;i++)); do
604         dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
605     done
606     rm -rf $tdir
607 }
608 run_test 7 "exercise enlarge_reqbuf()"
609
610 test_90() {
611     if [ "$SLOW" = "no" ]; then
612         total=10
613     else
614         total=60
615     fi
616
617     start_dbench
618
619     for ((n=0;n<$total;n++)); do
620         sleep 2
621         check_dbench
622         echo "flush ctx ($n/$total) ..."
623         $LFS flushctx
624     done
625     check_dbench
626     stop_dbench
627 }
628 run_test 90 "recoverable from losing contexts under load"
629
630 test_99() {
631     local nrule_old=0
632     local nrule_new=0
633     local max=32
634
635     #
636     # general rules
637     #
638     nrule_old=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
639                | grep "$FSNAME.srpc.flavor." | wc -l`
640     echo "original general rules: $nrule_old"
641
642     for ((i = $nrule_old; i < $max; i++)); do
643         set_rule $FSNAME elan$i any krb5n || error "set rule $i"
644     done
645     set_rule $FSNAME elan100 any krb5n && error "set $max rule should fail"
646     for ((i = $nrule_old; i < $max; i++)); do
647         set_rule $FSNAME elan$i any || error "remove rule $i"
648     done
649
650     nrule_new=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
651                | grep "$FSNAME.srpc.flavor." | wc -l`
652     if [ $nrule_new != $nrule_old ]; then
653         error "general rule: $nrule_new != $nrule_old"
654     fi
655
656     #
657     # target-specific rules
658     #
659     nrule_old=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
660                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
661     echo "original target rules: $nrule_old"
662
663     for ((i = $nrule_old; i < $max; i++)); do
664         set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
665     done
666     set_rule $FSNAME-MDT0000 elan100 any krb5i && error "set $max rule should fail"
667     for ((i = $nrule_old; i < $max; i++)); do
668         set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
669     done
670
671     nrule_new=`do_facet mgs cat $LPROC/mgs/MGS/live/$FSNAME 2>/dev/null \
672                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
673     if [ $nrule_new != $nrule_old ]; then
674         error "general rule: $nrule_new != $nrule_old"
675     fi
676 }
677 run_test 99 "maximum sptlrpc rules limitation"
678
679 error_dbench()
680 {
681     local err_str=$1
682
683     killall -9 dbench
684     sleep 1
685
686     error $err_str
687 }
688
689 test_100() {
690     # started from default flavors
691     restore_to_default_flavor
692
693     # running dbench background
694     start_dbench
695
696     #
697     # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
698     #
699     set_rule $FSNAME any any krb5n
700     wait_flavor all2all krb5n $cnt_all2all || error_dbench "1"
701     check_dbench
702
703     set_rule $FSNAME any any krb5a
704     wait_flavor all2all krb5a $cnt_all2all || error_dbench "2"
705     check_dbench
706
707     set_rule $FSNAME any any krb5i
708     wait_flavor all2all krb5i $cnt_all2all || error_dbench "3"
709     check_dbench
710
711     set_rule $FSNAME any any krb5p
712     wait_flavor all2all krb5p $cnt_all2all || error_dbench "4"
713     check_dbench
714
715     set_rule $FSNAME any any plain
716     wait_flavor all2all plain $cnt_all2all || error_dbench "5"
717     check_dbench
718
719     #
720     # M - M: krb5a
721     # C - M: krb5i
722     # M - O: krb5p
723     # C - O: krb5n
724     #
725     set_rule $FSNAME any mdt2mdt krb5a
726     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "6"
727     check_dbench
728
729     set_rule $FSNAME any cli2mdt krb5i
730     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "7"
731     check_dbench
732
733     set_rule $FSNAME any mdt2ost krb5p
734     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "8"
735     check_dbench
736
737     set_rule $FSNAME any cli2ost krb5n
738     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "9"
739     check_dbench
740
741     #
742     # * - MDT0: krb5p
743     # * - OST0: krb5i
744     #
745     # nothing should be changed because they are override by above dir rules
746     #
747     set_rule $FSNAME-MDT0000 any any krb5p
748     set_rule $FSNAME-OST0000 any any krb5i
749     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "10"
750     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "11"
751     check_dbench
752     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "12"
753     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "13"
754
755     #
756     # delete all dir-specific rules
757     #
758     set_rule $FSNAME any mdt2mdt
759     set_rule $FSNAME any cli2mdt
760     set_rule $FSNAME any mdt2ost
761     set_rule $FSNAME any cli2ost
762     wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
763     wait_flavor cli2mdt krb5p $CLICOUNT || error_dbench "15"
764     check_dbench
765     wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
766     wait_flavor cli2ost krb5i $CLICOUNT || error_dbench "17"
767     check_dbench
768
769     #
770     # remove:
771     #  * - MDT0: krb5p
772     #  * - OST0: krb5i
773     #
774     set_rule $FSNAME-MDT0000 any any
775     set_rule $FSNAME-OST0000 any any || error_dbench "18"
776     wait_flavor all2all plain $cnt_all2all || error_dbench "19"
777     check_dbench
778
779     stop_dbench
780 }
781 run_test 100 "change security flavor on the fly under load"
782
783 switch_sec_test()
784 {
785     local count=$1
786     local flavor0=$2
787     local flavor1=$3
788     local flavor2=$4
789     local df_pid=0
790     local wait_time=$((TIMEOUT + TIMEOUT / 4))
791     local num
792
793     #
794     # stop gss daemon, then switch to flavor1 (which should be a gss flavor),
795     # and run a 'df' which should hanging, wait the request timeout and
796     # resend, then switch the flavor to another one. To exercise the code of
797     # switching ctx/sec for a resend request.
798     #
799     echo ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 -> $flavor2..."
800
801     echo "(0) set base flavor $flavor0"
802     set_rule $FSNAME any cli2mdt $flavor0
803     wait_flavor cli2mdt $flavor0 $count
804     df $MOUNT
805     if [ $? -ne 0 ]; then
806         error "initial df failed"
807     fi
808
809     stop_gss_daemons
810     sleep 1
811
812     echo "(1) $flavor0 -> $flavor1"
813     set_rule $FSNAME any cli2mdt $flavor1
814     wait_flavor cli2mdt $flavor1 $count
815     df $MOUNT &
816     df_pid=$!
817     sleep 1
818
819     echo "waiting $wait_time seconds for df ($df_pid)"
820     sleep $wait_time
821     num=`ps --no-headers -p $df_pid 2>/dev/null | wc -l`
822     [ $num -eq 1 ] || error "df already ended ($num)"
823     echo "process $df_pid is still hanging there... OK"
824
825     echo "(2) set end flavor $flavor2"
826     set_rule $FSNAME any cli2mdt $flavor2
827     wait_flavor cli2mdt $flavor2 $count
828     start_gss_daemons
829     wait $df_pid || error "df returned error"
830 }
831
832 test_101()
833 {
834     # started from default flavors
835     restore_to_default_flavor
836
837     switch_sec_test $cnt_cli2mdt null krb5n null
838     switch_sec_test $cnt_cli2mdt null krb5a null
839     switch_sec_test $cnt_cli2mdt null krb5i null
840     switch_sec_test $cnt_cli2mdt null krb5p null
841     switch_sec_test $cnt_cli2mdt null krb5i plain
842     switch_sec_test $cnt_cli2mdt plain krb5p plain
843     switch_sec_test $cnt_cli2mdt plain krb5n krb5a
844     switch_sec_test $cnt_cli2mdt krb5a krb5i krb5p
845     switch_sec_test $cnt_cli2mdt krb5p krb5a krb5n
846     switch_sec_test $cnt_cli2mdt krb5n krb5p krb5i
847 }
848 run_test 101 "switch ctx as well as sec for resending request"
849
850 error_102()
851 {
852     local err_str=$1
853
854     killall -9 dbench
855     sleep 1
856
857     error $err_str
858 }
859
860 test_102() {
861     # started from default flavors
862     restore_to_default_flavor
863
864     # run dbench background
865     start_dbench
866
867     echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
868     set_rule $FSNAME any any krb5n
869     set_rule $FSNAME any any krb5a
870     set_rule $FSNAME any any krb5i
871     set_rule $FSNAME any any krb5p
872     set_rule $FSNAME any any plain
873     set_rule $FSNAME any any null
874
875     check_dbench
876     wait_flavor all2all null $cnt_all2all || error_dbench "1"
877     check_dbench
878
879     echo "waiting for 15s and check again"
880     sleep 15
881     check_dbench
882
883     echo "Testing null->krb5i->null->krb5i->null..."
884     for ((i=0; i<10; i++)); do
885         set_rule $FSNAME any any krb5i
886         set_rule $FSNAME any any null
887     done
888     set_rule $FSNAME any any krb5i
889
890     check_dbench
891     wait_flavor all2all krb5i $cnt_all2all || error_dbench "2"
892     check_dbench
893
894     echo "waiting for 15s and check again"
895     sleep 15
896     check_dbench
897
898     stop_dbench
899 }
900 run_test 102 "survive from insanely fast flavor switch"
901
902 equals_msg `basename $0`: test complete, cleaning up
903 check_and_cleanup_lustre
904 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true