Whamcloud - gitweb
40390b052ea25af1d7bbceff76c53d38bd840c17
[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 # 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 CLEANUP=${CLEANUP:-""}
30 SETUP=${SETUP:-""}
31
32 LUSTRE=${LUSTRE:-`dirname $0`/..}
33 . $LUSTRE/tests/test-framework.sh
34 init_test_env $@
35 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
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 CLICOUNT=2
52 cnt_mdt2ost=0
53 cnt_mdt2mdt=0
54 cnt_cli2ost=0
55 cnt_cli2mdt=0
56 cnt_all2ost=0
57 cnt_all2mdt=0
58 cnt_all2all=0
59 DBENCH_PID=0
60 PROC_CLI="srpc.info"
61 # Escape "." to use lctl
62 PROC_CLI=${PROC_CLI//\./\*} 
63
64 # set manually
65 GSS=true
66 GSS_KRB5=true
67
68 prepare_krb5_creds() {
69     echo prepare krb5 cred
70     rm -f $KRB5_CRED_SAVE
71     echo RUNAS=$RUNAS
72     $RUNAS krb5_login.sh || exit 1
73     [ -f $KRB5_CRED ] || exit 2
74     echo CRED=$KRB5_CRED
75     cp $KRB5_CRED $KRB5_CRED_SAVE
76 }
77
78 prepare_krb5_creds
79
80 # we want double mount
81 MOUNT_2=${MOUNT_2:-"yes"}
82 cleanup_and_setup_lustre
83
84 rm -rf $DIR/[df][0-9]*
85
86 check_runas_id $RUNAS_ID $RUNAS
87
88 build_test_filter
89
90 combination()
91 {
92     local M=$1
93     local N=$2
94     local R=1
95
96     if [ $M -lt $N ]; then
97         R=0
98     else
99         N=$((N + 1))
100         while [ $N -le $M ]; do
101             R=$((R * N))
102             N=$((N + 1))
103         done
104     fi
105
106     echo $R
107     return 0
108 }
109
110 calc_connection_cnt() {
111     # MDT->MDT = 2 * C(M, 2)
112     # MDT->OST = M * O
113     # CLI->OST = C * O
114     # CLI->MDT = C * M
115     comb_m2=$(combination $MDSCOUNT 2)
116
117     cnt_mdt2mdt=$((comb_m2 * 2))
118     cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
119     cnt_cli2ost=$((CLICOUNT * OSTCOUNT))
120     cnt_cli2mdt=$((CLICOUNT * MDSCOUNT))
121     cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
122     cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
123     cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
124 }
125
126 set_rule()
127 {
128     local tgt=$1
129     local net=$2
130     local dir=$3
131     local flavor=$4
132     local cmd="$tgt.srpc.flavor"
133
134     if [ $net == "any" ]; then
135         net="default"
136     fi
137     cmd="$cmd.$net"
138
139     if [ $dir != "any" ]; then
140         cmd="$cmd.$dir"
141     fi
142
143     cmd="$cmd=$flavor"
144     log "Setting sptlrpc rule: $cmd"
145     do_facet mgs "$LCTL conf_param $cmd"
146 }
147
148 count_flvr()
149 {
150     local output=$1
151     local flavor=$2
152     local count=0
153
154     rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
155     bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
156
157     count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
158
159     if [ "x$bulkspec" != "x" ]; then
160         algs=`echo $bulkspec | awk -F : '{ print $2 }'`
161
162         if [ "x$algs" != "x" ]; then
163             bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
164         else
165             bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
166             if [ $bulk == "bulkn" ]; then
167                 bulk_count=`echo "$output" | grep "bulk flavor" \
168                             | grep "null/null" | wc -l`
169             elif [ $bulk == "bulki" ]; then
170                 bulk_count=`echo "$output" | grep "bulk flavor" \
171                             | grep "/null" | grep -v "null/" | wc -l`
172             else
173                 bulk_count=`echo "$output" | grep "bulk flavor" \
174                             | grep -v "/null" | grep -v "null/" | wc -l`
175             fi
176         fi
177
178         [ $bulk_count -lt $count ] && count=$bulk_count
179     fi
180
181     echo $count
182 }
183
184 flvr_cnt_cli2mdt()
185 {
186     local flavor=$1
187
188     output=`do_facet client lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
189     count_flvr "$output" $flavor
190 }
191
192 flvr_cnt_cli2ost()
193 {
194     local flavor=$1
195
196     output=`do_facet client lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
197     count_flvr "$output" $flavor
198 }
199
200 flvr_cnt_mdt2mdt()
201 {
202     local flavor=$1
203     local cnt=0
204
205     if [ $MDSCOUNT -le 1 ]; then
206         echo 0
207         return
208     fi
209
210     for num in `seq $MDSCOUNT`; do
211         output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
212         tmpcnt=`count_flvr "$output" $flavor`
213         cnt=$((cnt + tmpcnt))
214     done
215     echo $cnt;
216 }
217
218 flvr_cnt_mdt2ost()
219 {
220     local flavor=$1
221     local cnt=0
222
223     for num in `seq $MDSCOUNT`; do
224         output=`do_facet mds$num lctl get_param -n osc.*OST*-osc-MDT*.$PROC_CLI 2>/dev/null`
225         tmpcnt=`count_flvr "$output" $flavor`
226         cnt=$((cnt + tmpcnt))
227     done
228     echo $cnt;
229 }
230
231 do_check_flavor()
232 {
233     local dir=$1        # from to
234     local flavor=$2     # flavor expected
235     local res=0
236
237     if [ $dir == "cli2mdt" ]; then
238         res=`flvr_cnt_cli2mdt $flavor`
239     elif [ $dir == "cli2ost" ]; then
240         res=`flvr_cnt_cli2ost $flavor`
241     elif [ $dir == "mdt2mdt" ]; then
242         res=`flvr_cnt_mdt2mdt $flavor`
243     elif [ $dir == "mdt2ost" ]; then
244         res=`flvr_cnt_mdt2ost $flavor`
245     elif [ $dir == "all2ost" ]; then
246         res1=`flvr_cnt_mdt2ost $flavor`
247         res2=`flvr_cnt_cli2ost $flavor`
248         res=$((res1 + res2))
249     elif [ $dir == "all2mdt" ]; then
250         res1=`flvr_cnt_mdt2mdt $flavor`
251         res2=`flvr_cnt_cli2mdt $flavor`
252         res=$((res1 + res2))
253     elif [ $dir == "all2all" ]; then
254         res1=`flvr_cnt_mdt2ost $flavor`
255         res2=`flvr_cnt_cli2ost $flavor`
256         res3=`flvr_cnt_mdt2mdt $flavor`
257         res4=`flvr_cnt_cli2mdt $flavor`
258         res=$((res1 + res2 + res3 + res4))
259     fi
260
261     echo $res
262 }
263
264 wait_flavor()
265 {
266     local dir=$1        # from to
267     local flavor=$2     # flavor expected
268     local expect=$3     # number expected
269     local res=0
270
271     for ((i=0;i<20;i++)); do
272         echo -n "checking..."
273         res=$(do_check_flavor $dir $flavor)
274         if [ $res -eq $expect ]; then
275             echo "found $res $flavor connections of $dir, OK"
276             return 0
277         else
278             echo "found $res $flavor connections of $dir, not ready ($expect)"
279             sleep 4
280         fi
281     done
282
283     echo "Error checking $flavor of $dir: expect $expect, actual $res"
284     return 1
285 }
286
287 restore_to_default_flavor()
288 {
289     local proc="mgs.MGS.live.$FSNAME"
290
291     echo "restoring to default flavor..."
292
293     nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
294
295     # remove all existing rules if any
296     if [ $nrule -ne 0 ]; then
297         echo "$nrule existing rules"
298         for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
299             echo "remove rule: $rule"
300             spec=`echo $rule | awk -F = '{print $1}'`
301             do_facet mgs "$LCTL conf_param $spec="
302         done
303     fi
304
305     # verify no rules left
306     nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
307     [ $nrule -ne 0 ] && error "still $nrule rules left"
308
309     # wait for default flavor to be applied
310     # currently default flavor for all connections are 'null'
311     wait_flavor all2all null $cnt_all2all
312     echo "now at default flavor settings"
313 }
314
315 set_flavor_all()
316 {
317     local flavor=$1
318
319     echo "setting all flavor to $flavor"
320
321     res=$(do_check_flavor all2all $flavor)
322     if [ $res -eq $cnt_all2all ]; then
323         echo "already have total $res $flavor connections"
324         return
325     fi
326
327     echo "found $res $flavor out of total $cnt_all2all connections"
328     restore_to_default_flavor
329
330     set_rule $FSNAME any any $flavor
331     wait_flavor all2all $flavor $cnt_all2all
332 }
333
334 start_dbench()
335 {
336     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
337     [ $NPROC -gt 2 ] && NPROC=2
338     sh rundbench $NPROC 1>/dev/null &
339     DBENCH_PID=$!
340     sleep 2
341
342     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
343     if [ $num -ne 1 ]; then
344         error "failed to start dbench $NPROC"
345     else
346         echo "started dbench with $NPROC processes at background"
347     fi
348
349     return 0
350 }
351
352 check_dbench()
353 {
354     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
355     if [ $num -eq 0 ]; then
356         echo "dbench $DBENCH_PID already finished"
357         wait $DBENCH_PID || error "dbench $PID exit with error"
358         start_dbench
359     elif [ $num -ne 1 ]; then
360         killall -9 dbench
361         error "found $num instance of pid $DBENCH_PID ???"
362     fi
363
364     return 0
365 }
366
367 stop_dbench()
368 {
369     for ((;;)); do
370         killall dbench 2>/dev/null
371         num=`ps --no-headers -p $DBENCH_PID | wc -l`
372         if [ $num -eq 0 ]; then
373             echo "dbench finished"
374             break
375         fi
376         echo "dbench $DBENCH_PID is still running, waiting 2s..."
377         sleep 2
378     done
379
380     wait $DBENCH_PID || true
381     sync || true
382 }
383
384 restore_krb5_cred() {
385     cp $KRB5_CRED_SAVE $KRB5_CRED
386     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
387     chmod 0600 $KRB5_CRED
388 }
389
390 check_multiple_gss_daemons() {
391     local facet=$1
392     local gssd=$2
393     local gssd_name=`basename $gssd`
394
395     for ((i=0;i<10;i++)); do
396         do_facet $facet "$gssd -v &"
397     done
398
399     # wait daemons entering "stable" status
400     sleep 5
401
402     num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
403     echo "$num instance(s) of $gssd_name are running"
404
405     if [ $num -ne 1 ]; then
406         error "$gssd_name not unique"
407     fi
408 }
409
410 calc_connection_cnt
411 umask 077
412
413 test_0() {
414     local my_facet=mds
415
416     echo "bring up gss daemons..."
417     start_gss_daemons
418
419     echo "check with someone already running..."
420     check_multiple_gss_daemons $my_facet $LSVCGSSD
421     if $GSS_PIPEFS; then
422         check_multiple_gss_daemons $my_facet $LGSSD
423     fi
424
425     echo "check with someone run & finished..."
426     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
427     sleep 5 # wait fully exit
428     check_multiple_gss_daemons $my_facet $LSVCGSSD
429     if $GSS_PIPEFS; then
430         check_multiple_gss_daemons $my_facet $LGSSD
431     fi
432
433     echo "check refresh..."
434     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
435     sleep 5 # wait fully exit
436     do_facet $my_facet ipcrm -S 0x3b92d473
437     check_multiple_gss_daemons $my_facet $LSVCGSSD
438     if $GSS_PIPEFS; then
439         do_facet $my_facet ipcrm -S 0x3a92d473
440         check_multiple_gss_daemons $my_facet $LGSSD
441     fi
442 }
443 run_test 0 "start multiple gss daemons"
444
445 set_flavor_all krb5p
446
447 test_1() {
448     local file=$DIR/$tfile
449
450     chmod 0777 $DIR || error "chmod $DIR failed"
451     # access w/o cred
452     $RUNAS kdestroy
453     $RUNAS touch $file && error "unexpected success"
454
455     # access w/ cred
456     restore_krb5_cred
457     $RUNAS touch $file || error "should not fail"
458     [ -f $file ] || error "$file not found"
459 }
460 run_test 1 "access with or without krb5 credential"
461
462 test_2() {
463     local file1=$DIR/$tfile-1
464     local file2=$DIR/$tfile-2
465
466     chmod 0777 $DIR || error "chmod $DIR failed"
467     # current access should be ok
468     $RUNAS touch $file1 || error "can't touch $file1"
469     [ -f $file1 ] || error "$file1 not found"
470
471     # cleanup all cred/ctx and touch
472     $RUNAS kdestroy
473     $RUNAS $LFS flushctx || error "can't flush ctx"
474     $RUNAS touch $file2 && error "unexpected success"
475
476     # restore and touch
477     restore_krb5_cred
478     $RUNAS touch $file2 || error "should not fail"
479     [ -f $file2 ] || error "$file2 not found"
480 }
481 run_test 2 "lfs flushctx"
482
483 test_3() {
484     local file=$DIR/$tfile
485
486     # create file
487     echo "aaaaaaaaaaaaaaaaa" > $file
488     chmod 0666 $file
489     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
490     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
491     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
492
493     # start multiop
494     $RUNAS multiop $file o_r &
495     OPPID=$!
496     # wait multiop finish its open()
497     sleep 1
498
499     # cleanup all cred/ctx and check
500     # metadata check should fail, but file data check should success
501     # because we always use root credential to OSTs
502     $RUNAS kdestroy
503     $RUNAS $LFS flushctx
504     echo "destroied credentials/contexs for $RUNAS_ID"
505     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
506     kill -s 10 $OPPID
507     wait $OPPID || error "read file data failed"
508     echo "read file data OK"
509
510     # restore and check again
511     restore_krb5_cred
512     echo "restored credentials for $RUNAS_ID"
513     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
514     echo "$RUNAS_ID checkstat OK"
515     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
516     echo "$UID checkstat OK"
517     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
518     echo "$RUNAS_ID read file data OK"
519 }
520 run_test 3 "local cache under DLM lock"
521
522 test_4() {
523     local file1=$DIR/$tfile-1
524     local file2=$DIR/$tfile-2
525
526     ! $GSS_PIPEFS && skip "pipefs not used" && return
527
528     chmod 0777 $DIR || error "chmod $DIR failed"
529     # current access should be ok
530     $RUNAS touch $file1 || error "can't touch $file1"
531     [ -f $file1 ] || error "$file1 not found"
532
533     # stop lgssd
534     send_sigint client lgssd
535     sleep 5
536     check_gss_daemon_facet client lgssd && error "lgssd still running"
537
538     # flush context, and touch
539     $RUNAS $LFS flushctx
540     $RUNAS touch $file2 &
541     TOUCHPID=$!
542     echo "waiting touch pid $TOUCHPID"
543     wait $TOUCHPID && error "touch should fail"
544
545     # restart lgssd
546     do_facet client "$LGSSD -v"
547     sleep 5
548     check_gss_daemon_facet client lgssd
549
550     # touch new should succeed
551     $RUNAS touch $file2 || error "can't touch $file2"
552     [ -f $file2 ] || error "$file2 not found"
553 }
554 run_test 4 "lgssd dead, operations should wait timeout and fail"
555
556 test_5() {
557     local file1=$DIR/$tfile-1
558     local file2=$DIR/$tfile-2
559     local wait_time=$((TIMEOUT + TIMEOUT / 2))
560
561     chmod 0777 $DIR || error "chmod $DIR failed"
562     # current access should be ok
563     $RUNAS touch $file1 || error "can't touch $file1"
564     [ -f $file1 ] || error "$file1 not found"
565
566     # stop lsvcgssd
567     send_sigint mds lsvcgssd
568     sleep 5
569     check_gss_daemon_facet mds lsvcgssd && error "lsvcgssd still running"
570
571     # flush context, and touch
572     $RUNAS $LFS flushctx
573     $RUNAS touch $file2 &
574     TOUCHPID=$!
575
576     # wait certain time
577     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
578     sleep $wait_time
579     num=`ps --no-headers -p $TOUCHPID | wc -l`
580     [ $num -eq 1 ] || error "touch already ended ($num)"
581     echo "process $TOUCHPID still hanging there... OK"
582
583     # restart lsvcgssd, expect touch suceed
584     echo "restart lsvcgssd and recovering"
585     do_facet mds "$LSVCGSSD -v"
586     sleep 5
587     check_gss_daemon_facet mds lsvcgssd
588     wait $TOUCHPID || error "touch fail"
589     [ -f $file2 ] || error "$file2 not found"
590 }
591 run_test 5 "lsvcgssd dead, operations lead to recovery"
592
593 test_6() {
594     local nfile=10
595
596     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
597     for ((i=0; i<$nfile; i++)); do
598         dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
599     done
600     ls -l $DIR/d6/* > /dev/null || error "ls failed"
601     rm -rf $DIR2/d6/* || error "rm failed"
602     rmdir $DIR2/d6/ || error "rmdir failed"
603 }
604 run_test 6 "test basic DLM callback works"
605
606 test_7() {
607     local tdir=$DIR/d7
608     local num_osts
609
610     #
611     # for open(), client only reserve space for default stripe count lovea,
612     # and server may return larger lovea in reply (because of larger stripe
613     # count), client need call enlarge_reqbuf() and save the replied lovea
614     # in request for future possible replay.
615     #
616     # Note: current script does NOT guarantee enlarge_reqbuf() will be in
617     # the path, however it does work in local test which has 2 OSTs and
618     # default stripe count is 1.
619     #
620     num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
621     echo "found $num_osts active OSTs"
622     [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
623
624     mkdir $tdir || error
625     $LFS setstripe $tdir 0 -1 -1 || error
626
627     echo "creating..."
628     for ((i=0;i<20;i++)); do
629         dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
630     done
631     echo "reading..."
632     for ((i=0;i<20;i++)); do
633         dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
634     done
635     rm -rf $tdir
636 }
637 run_test 7 "exercise enlarge_reqbuf()"
638
639 test_8()
640 {
641     debugsave
642     sysctl -w lnet.debug="other"
643     $LCTL dk > /dev/null
644
645     # sleep sometime in ctx handle
646     do_facet mds sysctl -w lustre.fail_val=60
647 #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
648     do_facet mds sysctl -w lustre.fail_loc=0x1204
649
650     $RUNAS $LFS flushctx || error "can't flush ctx"
651
652     $RUNAS df $DIR &
653     DFPID=$!
654     echo "waiting df (pid $TOUCHPID) to finish..."
655     sleep 2 # give df a chance to really trigger context init rpc
656     do_facet mds sysctl -w lustre.fail_loc=0
657     wait $DFPID || error "df should have succeeded"
658
659     $LCTL dk | grep "Early reply #" || error "No early reply"
660     debugrestore
661 }
662 run_test 8 "Early reply sent for slow gss context negotiation"
663
664 #
665 # following tests will manipulate flavors and may end with any flavor set,
666 # so each test should not assume any start flavor.
667 #
668
669 test_50() {
670     local sample=$TMP/sanity-gss-8
671     local tdir=$MOUNT/dir8
672     local iosize="256K"
673     local hash_algs="adler32 crc32 md5 sha1 sha256 sha384 sha512 wp256 wp384 wp512"
674
675     # create sample file with aligned size for direct i/o
676     dd if=/dev/zero of=$sample bs=$iosize count=1 || error
677     dd conv=notrunc if=/etc/termcap of=$sample bs=$iosize count=1 || error
678
679     rm -rf $tdir
680     mkdir $tdir || error "create dir $tdir"
681
682     restore_to_default_flavor
683
684     for alg in $hash_algs; do
685         echo "Testing $alg..."
686         flavor=krb5i-bulki:$alg/null
687         set_rule $FSNAME any cli2ost $flavor
688         wait_flavor cli2ost $flavor $cnt_cli2ost
689
690         dd if=$sample of=$tdir/$alg oflag=direct,dsync bs=$iosize || error "$alg write"
691         diff $sample $tdir/$alg || error "$alg read"
692     done
693
694     rm -rf $tdir
695     rm -f $sample
696 }
697 run_test 50 "verify bulk hash algorithms works"
698
699 test_51() {
700     local s1=$TMP/sanity-gss-9.1
701     local s2=$TMP/sanity-gss-9.2
702     local s3=$TMP/sanity-gss-9.3
703     local s4=$TMP/sanity-gss-9.4
704     local tdir=$MOUNT/dir9
705     local s1_size=4194304   # n * pagesize (4M)
706     local s2_size=512       # n * blksize
707     local s3_size=111       # n * blksize + m
708     local s4_size=5         # m
709     local cipher_algs="arc4 aes128 aes192 aes256 cast128 cast256 twofish128 twofish256"
710
711     # create sample files for each situation
712     rm -f $s1 $s2 $s2 $s4
713     dd if=/dev/urandom of=$s1 bs=1M count=4 || error
714     dd if=/dev/urandom of=$s2 bs=$s2_size count=1 || error
715     dd if=/dev/urandom of=$s3 bs=$s3_size count=1 || error
716     dd if=/dev/urandom of=$s4 bs=$s4_size count=1 || error
717
718     rm -rf $tdir
719     mkdir $tdir || error "create dir $tdir"
720
721     restore_to_default_flavor
722
723     #
724     # different bulk data alignment will lead to different behavior of
725     # the implementation: (n > 0; 0 < m < encryption_block_size)
726     #  - full page i/o
727     #  - partial page, size = n * encryption_block_size
728     #  - partial page, size = n * encryption_block_size + m
729     #  - partial page, size = m
730     #
731     for alg in $cipher_algs; do
732         echo "Testing $alg..."
733         flavor=krb5p-bulkp:sha1/$alg
734         set_rule $FSNAME any cli2ost $flavor
735         wait_flavor cli2ost $flavor $cnt_cli2ost
736
737         # sync write
738         dd if=$s1 of=$tdir/$alg.1 oflag=dsync bs=1M || error "write $alg.1"
739         dd if=$s2 of=$tdir/$alg.2 oflag=dsync || error "write $alg.2"
740         dd if=$s3 of=$tdir/$alg.3 oflag=dsync || error "write $alg.3"
741         dd if=$s4 of=$tdir/$alg.4 oflag=dsync || error "write $alg.4"
742
743         # remount client
744         umount_client $MOUNT
745         umount_client $MOUNT2
746         mount_client $MOUNT
747         mount_client $MOUNT2
748
749         # read & compare
750         diff $tdir/$alg.1 $s1 || error "read $alg.1"
751         diff $tdir/$alg.2 $s2 || error "read $alg.2"
752         diff $tdir/$alg.3 $s3 || error "read $alg.3"
753         diff $tdir/$alg.4 $s4 || error "read $alg.4"
754     done
755
756     rm -rf $tdir
757     rm -f $sample
758 }
759 run_test 51 "bulk data alignment test under encryption mode"
760
761 test_90() {
762     if [ "$SLOW" = "no" ]; then
763         total=10
764     else
765         total=60
766     fi
767
768     restore_to_default_flavor
769     set_rule $FSNAME any any krb5p
770     wait_flavor all2all krb5p $cnt_all2all
771
772     start_dbench
773
774     for ((n=0;n<$total;n++)); do
775         sleep 2
776         check_dbench
777         echo "flush ctx ($n/$total) ..."
778         $LFS flushctx
779     done
780     check_dbench
781     stop_dbench
782 }
783 run_test 90 "recoverable from losing contexts under load"
784
785 test_99() {
786     local nrule_old=0
787     local nrule_new=0
788     local max=32
789
790     #
791     # general rules
792     #
793     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
794                | grep "$FSNAME.srpc.flavor." | wc -l`
795     echo "original general rules: $nrule_old"
796
797     for ((i = $nrule_old; i < $max; i++)); do
798         set_rule $FSNAME elan$i any krb5n || error "set rule $i"
799     done
800     set_rule $FSNAME elan100 any krb5n && error "set $max rule should fail"
801     for ((i = $nrule_old; i < $max; i++)); do
802         set_rule $FSNAME elan$i any || error "remove rule $i"
803     done
804
805     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
806                | grep "$FSNAME.srpc.flavor." | wc -l`
807     if [ $nrule_new != $nrule_old ]; then
808         error "general rule: $nrule_new != $nrule_old"
809     fi
810
811     #
812     # target-specific rules
813     #
814     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
815                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
816     echo "original target rules: $nrule_old"
817
818     for ((i = $nrule_old; i < $max; i++)); do
819         set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
820     done
821     set_rule $FSNAME-MDT0000 elan100 any krb5i && error "set $max rule should fail"
822     for ((i = $nrule_old; i < $max; i++)); do
823         set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
824     done
825
826     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
827                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
828     if [ $nrule_new != $nrule_old ]; then
829         error "general rule: $nrule_new != $nrule_old"
830     fi
831 }
832 run_test 99 "maximum sptlrpc rules limitation"
833
834 error_dbench()
835 {
836     local err_str=$1
837
838     killall -9 dbench
839     sleep 1
840
841     error $err_str
842 }
843
844 test_100() {
845     # started from default flavors
846     restore_to_default_flavor
847
848     # running dbench background
849     start_dbench
850
851     #
852     # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
853     #
854     set_rule $FSNAME any any krb5n
855     wait_flavor all2all krb5n $cnt_all2all || error_dbench "1"
856     check_dbench
857
858     set_rule $FSNAME any any krb5a
859     wait_flavor all2all krb5a $cnt_all2all || error_dbench "2"
860     check_dbench
861
862     set_rule $FSNAME any any krb5i
863     wait_flavor all2all krb5i $cnt_all2all || error_dbench "3"
864     check_dbench
865
866     set_rule $FSNAME any any krb5p
867     wait_flavor all2all krb5p $cnt_all2all || error_dbench "4"
868     check_dbench
869
870     set_rule $FSNAME any any plain
871     wait_flavor all2all plain $cnt_all2all || error_dbench "5"
872     check_dbench
873
874     #
875     # M - M: krb5a
876     # C - M: krb5i
877     # M - O: krb5p
878     # C - O: krb5n
879     #
880     set_rule $FSNAME any mdt2mdt krb5a
881     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "6"
882     check_dbench
883
884     set_rule $FSNAME any cli2mdt krb5i
885     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "7"
886     check_dbench
887
888     set_rule $FSNAME any mdt2ost krb5p
889     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "8"
890     check_dbench
891
892     set_rule $FSNAME any cli2ost krb5n
893     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "9"
894     check_dbench
895
896     #
897     # * - MDT0: krb5p
898     # * - OST0: krb5i
899     #
900     # nothing should be changed because they are override by above dir rules
901     #
902     set_rule $FSNAME-MDT0000 any any krb5p
903     set_rule $FSNAME-OST0000 any any krb5i
904     wait_flavor mdt2mdt krb5a $cnt_mdt2mdt || error_dbench "10"
905     wait_flavor cli2mdt krb5i $cnt_cli2mdt || error_dbench "11"
906     check_dbench
907     wait_flavor mdt2ost krb5p $cnt_mdt2ost || error_dbench "12"
908     wait_flavor cli2ost krb5n $cnt_cli2ost || error_dbench "13"
909
910     #
911     # delete all dir-specific rules
912     #
913     set_rule $FSNAME any mdt2mdt
914     set_rule $FSNAME any cli2mdt
915     set_rule $FSNAME any mdt2ost
916     set_rule $FSNAME any cli2ost
917     wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
918     wait_flavor cli2mdt krb5p $CLICOUNT || error_dbench "15"
919     check_dbench
920     wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
921     wait_flavor cli2ost krb5i $CLICOUNT || error_dbench "17"
922     check_dbench
923
924     #
925     # remove:
926     #  * - MDT0: krb5p
927     #  * - OST0: krb5i
928     #
929     set_rule $FSNAME-MDT0000 any any
930     set_rule $FSNAME-OST0000 any any || error_dbench "18"
931     wait_flavor all2all plain $cnt_all2all || error_dbench "19"
932     check_dbench
933
934     stop_dbench
935 }
936 run_test 100 "change security flavor on the fly under load"
937
938 switch_sec_test()
939 {
940     local count=$1
941     local flavor0=$2
942     local flavor1=$3
943     local flavor2=$4
944     local df_pid=0
945     local wait_time=$((TIMEOUT + TIMEOUT / 4))
946     local num
947
948     #
949     # stop gss daemon, then switch to flavor1 (which should be a gss flavor),
950     # and run a 'df' which should hanging, wait the request timeout and
951     # resend, then switch the flavor to another one. To exercise the code of
952     # switching ctx/sec for a resend request.
953     #
954     echo ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 -> $flavor2..."
955
956     echo "(0) set base flavor $flavor0"
957     set_rule $FSNAME any cli2mdt $flavor0
958     wait_flavor cli2mdt $flavor0 $count
959     df $MOUNT
960     if [ $? -ne 0 ]; then
961         error "initial df failed"
962     fi
963
964     stop_gss_daemons
965     sleep 1
966
967     echo "(1) $flavor0 -> $flavor1"
968     set_rule $FSNAME any cli2mdt $flavor1
969     wait_flavor cli2mdt $flavor1 $count
970     df $MOUNT &
971     df_pid=$!
972     sleep 1
973
974     echo "waiting $wait_time seconds for df ($df_pid)"
975     sleep $wait_time
976     num=`ps --no-headers -p $df_pid 2>/dev/null | wc -l`
977     [ $num -eq 1 ] || error "df already ended ($num)"
978     echo "process $df_pid is still hanging there... OK"
979
980     echo "(2) set end flavor $flavor2"
981     set_rule $FSNAME any cli2mdt $flavor2
982     wait_flavor cli2mdt $flavor2 $count
983     start_gss_daemons
984     wait $df_pid || error "df returned error"
985 }
986
987 test_101()
988 {
989     # started from default flavors
990     restore_to_default_flavor
991
992     switch_sec_test $cnt_cli2mdt null krb5n null
993     switch_sec_test $cnt_cli2mdt null krb5a null
994     switch_sec_test $cnt_cli2mdt null krb5i null
995     switch_sec_test $cnt_cli2mdt null krb5p null
996     switch_sec_test $cnt_cli2mdt null krb5i plain
997     switch_sec_test $cnt_cli2mdt plain krb5p plain
998     switch_sec_test $cnt_cli2mdt plain krb5n krb5a
999     switch_sec_test $cnt_cli2mdt krb5a krb5i krb5p
1000     switch_sec_test $cnt_cli2mdt krb5p krb5a krb5n
1001     switch_sec_test $cnt_cli2mdt krb5n krb5p krb5i
1002 }
1003 run_test 101 "switch ctx as well as sec for resending request"
1004
1005 error_102()
1006 {
1007     local err_str=$1
1008
1009     killall -9 dbench
1010     sleep 1
1011
1012     error $err_str
1013 }
1014
1015 test_102() {
1016     # started from default flavors
1017     restore_to_default_flavor
1018
1019     # run dbench background
1020     start_dbench
1021
1022     echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
1023     set_rule $FSNAME any any krb5n
1024     set_rule $FSNAME any any krb5a
1025     set_rule $FSNAME any any krb5i
1026     set_rule $FSNAME any any krb5p
1027     set_rule $FSNAME any any plain
1028     set_rule $FSNAME any any null
1029
1030     check_dbench
1031     wait_flavor all2all null $cnt_all2all || error_dbench "1"
1032     check_dbench
1033
1034     echo "waiting for 15s and check again"
1035     sleep 15
1036     check_dbench
1037
1038     echo "Testing null->krb5i->null->krb5i->null..."
1039     for ((i=0; i<10; i++)); do
1040         set_rule $FSNAME any any krb5i
1041         set_rule $FSNAME any any null
1042     done
1043     set_rule $FSNAME any any krb5i
1044
1045     check_dbench
1046     wait_flavor all2all krb5i $cnt_all2all || error_dbench "2"
1047     check_dbench
1048
1049     echo "waiting for 15s and check again"
1050     sleep 15
1051     check_dbench
1052
1053     stop_dbench
1054 }
1055 run_test 102 "survive from insanely fast flavor switch"
1056
1057 equals_msg `basename $0`: test complete, cleaning up
1058 check_and_cleanup_lustre
1059 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true