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