2 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
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!
15 # Tests that fail on uml
16 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
17 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT"
20 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
21 export NAME=${NAME:-local}
24 export MULTIOP=${MULTIOP:-multiop}
26 CLEANUP=${CLEANUP:-""}
29 LUSTRE=${LUSTRE:-`dirname $0`/..}
30 . $LUSTRE/tests/test-framework.sh
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 require_dsh_mds || exit 0
37 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
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!"
42 # remove $SEC, we'd like to control everything by ourselves
46 # global variables of this sanity
49 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
50 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
57 prepare_krb5_creds() {
58 echo prepare krb5 cred
61 $RUNAS krb5_login.sh || exit 1
62 [ -f $KRB5_CRED ] || exit 2
64 cp $KRB5_CRED $KRB5_CRED_SAVE
69 # we want double mount
70 MOUNT_2=${MOUNT_2:-"yes"}
71 check_and_setup_lustre
73 rm -rf $DIR/[df][0-9]*
75 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
81 NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
82 [ $NPROC -gt 2 ] && NPROC=2
83 sh rundbench $NPROC 1>/dev/null &
87 num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
88 if [ $num -ne 1 ]; then
89 error "failed to start dbench $NPROC"
91 echo "started dbench with $NPROC processes at background"
99 num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
100 if [ $num -eq 0 ]; then
101 echo "dbench $DBENCH_PID already finished"
102 wait $DBENCH_PID || error "dbench $PID exit with error"
104 elif [ $num -ne 1 ]; then
106 error "found $num instance of pid $DBENCH_PID ???"
115 killall dbench 2>/dev/null
116 num=`ps --no-headers -p $DBENCH_PID | wc -l`
117 if [ $num -eq 0 ]; then
118 echo "dbench finished"
121 echo "dbench $DBENCH_PID is still running, waiting 2s..."
125 wait $DBENCH_PID || true
129 restore_krb5_cred() {
130 cp $KRB5_CRED_SAVE $KRB5_CRED
131 chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
132 chmod 0600 $KRB5_CRED
135 check_multiple_gss_daemons() {
138 local gssd_name=`basename $gssd`
140 for ((i=0;i<10;i++)); do
141 do_facet $facet "$gssd -v &"
144 # wait daemons entering "stable" status
147 num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
148 echo "$num instance(s) of $gssd_name are running"
150 if [ $num -ne 1 ]; then
151 error "$gssd_name not unique"
161 echo "bring up gss daemons..."
164 echo "check with someone already running..."
165 check_multiple_gss_daemons $my_facet $LSVCGSSD
167 check_multiple_gss_daemons $my_facet $LGSSD
170 echo "check with someone run & finished..."
171 do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
172 sleep 5 # wait fully exit
173 check_multiple_gss_daemons $my_facet $LSVCGSSD
175 check_multiple_gss_daemons $my_facet $LGSSD
178 echo "check refresh..."
179 do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
180 sleep 5 # wait fully exit
181 do_facet $my_facet ipcrm -S 0x3b92d473
182 check_multiple_gss_daemons $my_facet $LSVCGSSD
184 do_facet $my_facet ipcrm -S 0x3a92d473
185 check_multiple_gss_daemons $my_facet $LGSSD
188 run_test 0 "start multiple gss daemons"
193 local file=$DIR/$tfile
195 chmod 0777 $DIR || error "chmod $DIR failed"
199 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
200 $RUNAS touch $file && error "unexpected success"
204 $RUNAS touch $file || error "should not fail"
205 [ -f $file ] || error "$file not found"
207 run_test 1 "access with or without krb5 credential"
210 local file1=$DIR/$tfile-1
211 local file2=$DIR/$tfile-2
213 chmod 0777 $DIR || error "chmod $DIR failed"
214 # current access should be ok
215 $RUNAS touch $file1 || error "can't touch $file1"
216 [ -f $file1 ] || error "$file1 not found"
218 # cleanup all cred/ctx and touch
220 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
221 $RUNAS touch $file2 && error "unexpected success"
225 $RUNAS touch $file2 || error "should not fail"
226 [ -f $file2 ] || error "$file2 not found"
228 run_test 2 "lfs flushctx"
231 local file=$DIR/$tfile
234 echo "aaaaaaaaaaaaaaaaa" > $file
236 $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
237 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
238 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
241 $RUNAS $MULTIOP $file o_r &
243 # wait multiop finish its open()
246 # cleanup all cred/ctx and check
247 # metadata check should fail, but file data check should success
248 # because we always use root credential to OSTs
250 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
251 echo "destroied credentials/contexs for $RUNAS_ID"
252 $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
254 wait $OPPID || error "read file data failed"
255 echo "read file data OK"
257 # restore and check again
259 echo "restored credentials for $RUNAS_ID"
260 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
261 echo "$RUNAS_ID checkstat OK"
262 $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
263 echo "$UID checkstat OK"
264 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
265 echo "$RUNAS_ID read file data OK"
267 run_test 3 "local cache under DLM lock"
270 local file1=$DIR/$tfile-1
271 local file2=$DIR/$tfile-2
273 ! $GSS_PIPEFS && skip "pipefs not used" && return
275 chmod 0777 $DIR || error "chmod $DIR failed"
276 # current access should be ok
277 $RUNAS touch $file1 || error "can't touch $file1"
278 [ -f $file1 ] || error "$file1 not found"
281 send_sigint client lgssd
283 check_gss_daemon_facet client lgssd && error "lgssd still running"
285 # flush context, and touch
286 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
287 $RUNAS touch $file2 &
289 echo "waiting touch pid $TOUCHPID"
290 wait $TOUCHPID && error "touch should fail"
293 do_facet client "$LGSSD -v"
295 check_gss_daemon_facet client lgssd
297 # touch new should succeed
298 $RUNAS touch $file2 || error "can't touch $file2"
299 [ -f $file2 ] || error "$file2 not found"
301 run_test 4 "lgssd dead, operations should wait timeout and fail"
304 local file1=$DIR/$tfile-1
305 local file2=$DIR/$tfile-2
306 local wait_time=$((TIMEOUT + TIMEOUT / 2))
308 chmod 0777 $DIR || error "chmod $DIR failed"
309 # current access should be ok
310 $RUNAS touch $file1 || error "can't touch $file1"
311 [ -f $file1 ] || error "$file1 not found"
314 send_sigint $(comma_list $(mdts_nodes)) lsvcgssd
316 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd && error "lsvcgssd still running"
318 # flush context, and touch
319 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
320 $RUNAS touch $file2 &
324 echo "waiting $wait_time seconds for touch pid $TOUCHPID"
326 num=`ps --no-headers -p $TOUCHPID | wc -l`
327 [ $num -eq 1 ] || error "touch already ended ($num)"
328 echo "process $TOUCHPID still hanging there... OK"
330 # restart lsvcgssd, expect touch suceed
331 echo "restart lsvcgssd and recovering"
332 start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -v"
334 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd
335 wait $TOUCHPID || error "touch fail"
336 [ -f $file2 ] || error "$file2 not found"
338 run_test 5 "lsvcgssd dead, operations lead to recovery"
343 mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
344 for ((i=0; i<$nfile; i++)); do
345 dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
347 ls -l $DIR/d6/* > /dev/null || error "ls failed"
348 rm -rf $DIR2/d6/* || error "rm failed"
349 rmdir $DIR2/d6/ || error "rmdir failed"
351 run_test 6 "test basic DLM callback works"
358 # for open(), client only reserve space for default stripe count lovea,
359 # and server may return larger lovea in reply (because of larger stripe
360 # count), client need call enlarge_reqbuf() and save the replied lovea
361 # in request for future possible replay.
363 # Note: current script does NOT guarantee enlarge_reqbuf() will be in
364 # the path, however it does work in local test which has 2 OSTs and
365 # default stripe count is 1.
367 num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
368 echo "found $num_osts active OSTs"
369 [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
372 $LFS setstripe -c $num_osts $tdir || error
375 for ((i=0;i<20;i++)); do
376 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
379 for ((i=0;i<20;i++)); do
380 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
384 run_test 7 "exercise enlarge_reqbuf()"
388 local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
389 local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
391 do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
398 sysctl -w lnet.debug="+other"
400 # wait for the at estimation come down, this is faster
402 REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
403 awk '/portal 12/ {print $5}' | tail -1`
404 [ $REQ_DELAY -le 5 ] && break
405 echo "current AT estimation is $REQ_DELAY, wait a little bit"
408 REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
410 # sleep sometime in ctx handle
411 do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
412 #define OBD_FAIL_SEC_CTX_HDL_PAUSE 0x1204
413 do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
415 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
417 $RUNAS touch $DIR/d8/f &
419 echo "waiting for touch (pid $TOUCHPID) to finish..."
420 sleep 2 # give it a chance to really trigger context init rpc
421 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
422 wait $TOUCHPID || error "touch should have succeeded"
424 $LCTL dk | grep "Early reply #" || error "No early reply"
427 do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
429 run_test 8 "Early reply sent for slow gss context negotiation"
432 # following tests will manipulate flavors and may end with any flavor set,
433 # so each test should not assume any start flavor.
437 if [ "$SLOW" = "no" ]; then
443 restore_to_default_flavor
444 set_rule $FSNAME any any krb5p
445 wait_flavor all2all krb5p
449 for ((n=0;n<$total;n++)); do
452 echo "flush ctx ($n/$total) ..."
453 $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
456 #sleep to let ctxs be re-established
460 run_test 90 "recoverable from losing contexts under load"
470 nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
471 | grep "$FSNAME.srpc.flavor." | wc -l`
472 echo "original general rules: $nrule_old"
474 for ((i = $nrule_old; i < $max; i++)); do
475 set_rule $FSNAME elan$i any krb5n || error "set rule $i"
477 for ((i = $nrule_old; i < $max; i++)); do
478 set_rule $FSNAME elan$i any || error "remove rule $i"
481 nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
482 | grep "$FSNAME.srpc.flavor." | wc -l`
483 if [ $nrule_new != $nrule_old ]; then
484 error "general rule: $nrule_new != $nrule_old"
488 # target-specific rules
490 nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
491 | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
492 echo "original target rules: $nrule_old"
494 for ((i = $nrule_old; i < $max; i++)); do
495 set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
497 for ((i = $nrule_old; i < $max; i++)); do
498 set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
501 nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
502 | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
503 if [ $nrule_new != $nrule_old ]; then
504 error "general rule: $nrule_new != $nrule_old"
507 run_test 99 "set large number of sptlrpc rules"
520 # started from default flavors
521 restore_to_default_flavor
523 # running dbench background
527 # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
529 set_rule $FSNAME any any krb5n
530 wait_flavor all2all krb5n || error_dbench "1"
533 set_rule $FSNAME any any krb5a
534 wait_flavor all2all krb5a || error_dbench "2"
537 set_rule $FSNAME any any krb5i
538 wait_flavor all2all krb5i || error_dbench "3"
541 set_rule $FSNAME any any krb5p
542 wait_flavor all2all krb5p || error_dbench "4"
545 set_rule $FSNAME any any plain
546 wait_flavor all2all plain || error_dbench "5"
555 set_rule $FSNAME any mdt2mdt krb5a
556 wait_flavor mdt2mdt krb5a || error_dbench "6"
559 set_rule $FSNAME any cli2mdt krb5i
560 wait_flavor cli2mdt krb5i || error_dbench "7"
563 set_rule $FSNAME any mdt2ost krb5p
564 wait_flavor mdt2ost krb5p || error_dbench "8"
567 set_rule $FSNAME any cli2ost krb5n
568 wait_flavor cli2ost krb5n || error_dbench "9"
575 # nothing should be changed because they are override by above dir rules
577 set_rule $FSNAME-MDT0000 any any krb5p
578 set_rule $FSNAME-OST0000 any any krb5i
579 wait_flavor mdt2mdt krb5a || error_dbench "10"
580 wait_flavor cli2mdt krb5i || error_dbench "11"
582 wait_flavor mdt2ost krb5p || error_dbench "12"
583 wait_flavor cli2ost krb5n || error_dbench "13"
586 # delete all dir-specific rules
588 set_rule $FSNAME any mdt2mdt
589 set_rule $FSNAME any cli2mdt
590 set_rule $FSNAME any mdt2ost
591 set_rule $FSNAME any cli2ost
592 wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
593 wait_flavor cli2mdt krb5p $(get_clients_mount_count) || error_dbench "15"
595 wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
596 wait_flavor cli2ost krb5i $(get_clients_mount_count) || error_dbench "17"
604 set_rule $FSNAME-MDT0000 any any
605 set_rule $FSNAME-OST0000 any any || error_dbench "18"
606 wait_flavor all2all plain || error_dbench "19"
611 run_test 100 "change security flavor on the fly under load"
617 local filename=$DIR/$tfile
622 # after set to flavor0, start multop which use flavor0 rpc, and let
623 # server drop the reply; then switch to flavor1, the resend should be
624 # completed using flavor1. To exercise the code of switching ctx/sec
625 # for a resend request.
627 log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
629 set_rule $FSNAME any cli2mdt $flavor0
630 wait_flavor cli2mdt $flavor0
631 rm -f $filename || error "remove old $filename failed"
634 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
635 do_facet $SINGLEMDS lctl set_param fail_val=36
636 do_facet $SINGLEMDS lctl set_param fail_loc=0x513
637 log "starting multiop"
638 $MULTIOP $filename m &
640 echo "multiop pid=$multiop_pid"
643 set_rule $FSNAME any cli2mdt $flavor1
644 wait_flavor cli2mdt $flavor1
646 num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
647 [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
648 echo "process $multiop_pid is still hanging there... OK"
650 do_facet $SINGLEMDS lctl set_param fail_loc=0
651 log "waiting for multiop ($multiop_pid) to finish"
652 wait $multiop_pid || error "multiop returned error"
657 # started from default flavors
658 restore_to_default_flavor
660 switch_sec_test null plain
661 switch_sec_test plain krb5n
662 switch_sec_test krb5n krb5a
663 switch_sec_test krb5a krb5i
664 switch_sec_test krb5i krb5p
665 switch_sec_test krb5p null
666 switch_sec_test null krb5p
667 switch_sec_test krb5p krb5i
668 switch_sec_test krb5i plain
669 switch_sec_test plain krb5p
671 run_test 101 "switch ctx/sec for resending request"
684 # started from default flavors
685 restore_to_default_flavor
687 # run dbench background
690 echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
691 set_rule $FSNAME any any krb5n
692 set_rule $FSNAME any any krb5a
693 set_rule $FSNAME any any krb5i
694 set_rule $FSNAME any any krb5p
695 set_rule $FSNAME any any plain
696 set_rule $FSNAME any any null
699 wait_flavor all2all null || error_dbench "1"
702 echo "waiting for 15s and check again"
706 echo "Testing null->krb5i->null->krb5i->null..."
707 for ((i=0; i<10; i++)); do
708 set_rule $FSNAME any any krb5i
709 set_rule $FSNAME any any null
711 set_rule $FSNAME any any krb5i
714 wait_flavor all2all krb5i || error_dbench "2"
717 echo "waiting for 15s and check again"
723 run_test 102 "survive from insanely fast flavor switch"
728 local clients=$CLIENTS
730 [ -z $clients ] && clients=$HOSTNAME
732 # started from default flavors
733 restore_to_default_flavor
735 # at this time no rules has been set on mgs; mgc use null
736 # flavor connect to mgs.
737 count=`flvr_cnt_mgc2mgs null`
738 [ $count -eq 1 ] || error "$count mgc connection use null flavor"
740 zconf_umount_clients $clients $MOUNT || return 1
742 # mount client with conflict flavor - should fail
744 MOUNTOPT="$MOUNTOPT,mgssec=krb5p"
745 zconf_mount_clients $clients $MOUNT && \
746 error "mount with conflict flavor should have failed"
749 # mount client with same flavor - should succeed
751 MOUNTOPT="$MOUNTOPT,mgssec=null"
752 zconf_mount_clients $clients $MOUNT || \
753 error "mount with same flavor should have succeeded"
755 zconf_umount_clients $clients $MOUNT || return 2
757 # mount client with default flavor - should succeed
758 zconf_mount_clients $clients $MOUNT || \
759 error "mount with default flavor should have succeeded"
761 run_test 150 "secure mgs connection: client flavor setting"
766 # set mgs only accept krb5p
767 set_rule _mgs any any krb5p
769 # umount everything, modules still loaded
772 # mount mgs with default flavor, in current framework it means mgs+mdt1.
773 # the connection of mgc of mdt1 to mgs is expected fail.
774 DEVNAME=$(mdsdevname 1)
775 start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
777 # mount with unauthorized flavor should fail
778 save_opts=$MDS_MOUNT_OPTS
779 MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
780 start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
781 MDS_MOUNT_OPTS=$save_opts
783 # mount with designated flavor should succeed
784 save_opts=$MDS_MOUNT_OPTS
785 MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=krb5p"
786 start mds1 $DEVNAME $MDS_MOUNT_OPTS || error "mount with designated flavor should have succeeded"
787 MDS_MOUNT_OPTS=$save_opts
791 run_test 151 "secure mgs connection: server flavor control"
794 check_and_cleanup_lustre