3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
10 # bug number for skipped test:
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"$SANITY_GSS_EXCEPT"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
16 export NAME=${NAME:-local}
19 export MULTIOP=${MULTIOP:-multiop}
21 CLEANUP=${CLEANUP:-""}
24 LUSTRE=${LUSTRE:-`dirname $0`/..}
25 . $LUSTRE/tests/test-framework.sh
27 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 require_dsh_mds || exit 0
32 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
34 # $RUNAS_ID may get set incorrectly somewhere else
35 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
37 # remove $SEC, we'd like to control everything by ourselves
41 # global variables of this sanity
44 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
45 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
52 prepare_krb5_creds() {
53 echo prepare krb5 cred
56 $RUNAS krb5_login.sh || exit 1
57 [ -f $KRB5_CRED ] || exit 2
59 cp $KRB5_CRED $KRB5_CRED_SAVE
64 # we want double mount
65 MOUNT_2=${MOUNT_2:-"yes"}
66 check_and_setup_lustre
68 rm -rf $DIR/[df][0-9]*
70 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
76 NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
77 [ $NPROC -gt 2 ] && NPROC=2
78 sh rundbench $NPROC 1>/dev/null &
82 num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
83 if [ $num -ne 1 ]; then
84 error "failed to start dbench $NPROC"
86 echo "started dbench with $NPROC processes at background"
94 num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
95 if [ $num -eq 0 ]; then
96 echo "dbench $DBENCH_PID already finished"
97 wait $DBENCH_PID || error "dbench $PID exit with error"
99 elif [ $num -ne 1 ]; then
101 error "found $num instance of pid $DBENCH_PID ???"
110 killall dbench 2>/dev/null
111 num=`ps --no-headers -p $DBENCH_PID | wc -l`
112 if [ $num -eq 0 ]; then
113 echo "dbench finished"
116 echo "dbench $DBENCH_PID is still running, waiting 2s..."
120 wait $DBENCH_PID || true
124 restore_krb5_cred() {
125 cp $KRB5_CRED_SAVE $KRB5_CRED
126 chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
127 chmod 0600 $KRB5_CRED
130 check_multiple_gss_daemons() {
133 local gssd_name=`basename $gssd`
135 for ((i=0;i<10;i++)); do
136 do_facet $facet "$gssd -v &"
139 # wait daemons entering "stable" status
142 num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
143 echo "$num instance(s) of $gssd_name are running"
145 if [ $num -ne 1 ]; then
146 error "$gssd_name not unique"
156 echo "bring up gss daemons..."
159 echo "check with someone already running..."
160 check_multiple_gss_daemons $my_facet $LSVCGSSD
162 check_multiple_gss_daemons $my_facet $LGSSD
165 echo "check with someone run & finished..."
166 do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
167 sleep 5 # wait fully exit
168 check_multiple_gss_daemons $my_facet $LSVCGSSD
170 check_multiple_gss_daemons $my_facet $LGSSD
173 echo "check refresh..."
174 do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
175 sleep 5 # wait fully exit
176 do_facet $my_facet ipcrm -S 0x3b92d473
177 check_multiple_gss_daemons $my_facet $LSVCGSSD
179 do_facet $my_facet ipcrm -S 0x3a92d473
180 check_multiple_gss_daemons $my_facet $LGSSD
183 run_test 0 "start multiple gss daemons"
188 local file=$DIR/$tfile
190 chmod 0777 $DIR || error "chmod $DIR failed"
194 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
195 $RUNAS touch $file && error "unexpected success"
199 $RUNAS touch $file || error "should not fail"
200 [ -f $file ] || error "$file not found"
202 run_test 1 "access with or without krb5 credential"
205 local file1=$DIR/$tfile-1
206 local file2=$DIR/$tfile-2
208 chmod 0777 $DIR || error "chmod $DIR failed"
209 # current access should be ok
210 $RUNAS touch $file1 || error "can't touch $file1"
211 [ -f $file1 ] || error "$file1 not found"
213 # cleanup all cred/ctx and touch
215 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
216 $RUNAS touch $file2 && error "unexpected success"
220 $RUNAS touch $file2 || error "should not fail"
221 [ -f $file2 ] || error "$file2 not found"
223 run_test 2 "lfs flushctx"
226 local file=$DIR/$tfile
229 echo "aaaaaaaaaaaaaaaaa" > $file
231 $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
232 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
233 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
236 $RUNAS $MULTIOP $file o_r &
238 # wait multiop finish its open()
241 # cleanup all cred/ctx and check
242 # metadata check should fail, but file data check should success
243 # because we always use root credential to OSTs
245 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
246 echo "destroied credentials/contexs for $RUNAS_ID"
247 $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
249 wait $OPPID || error "read file data failed"
250 echo "read file data OK"
252 # restore and check again
254 echo "restored credentials for $RUNAS_ID"
255 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
256 echo "$RUNAS_ID checkstat OK"
257 $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
258 echo "$UID checkstat OK"
259 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
260 echo "$RUNAS_ID read file data OK"
262 run_test 3 "local cache under DLM lock"
265 local file1=$DIR/$tfile-1
266 local file2=$DIR/$tfile-2
268 ! $GSS_PIPEFS && skip "pipefs not used" && return
270 chmod 0777 $DIR || error "chmod $DIR failed"
271 # current access should be ok
272 $RUNAS touch $file1 || error "can't touch $file1"
273 [ -f $file1 ] || error "$file1 not found"
276 send_sigint client lgssd
278 check_gss_daemon_facet client lgssd && error "lgssd still running"
280 # flush context, and touch
281 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
282 $RUNAS touch $file2 &
284 echo "waiting touch pid $TOUCHPID"
285 wait $TOUCHPID && error "touch should fail"
288 do_facet client "$LGSSD -v"
290 check_gss_daemon_facet client lgssd
292 # touch new should succeed
293 $RUNAS touch $file2 || error "can't touch $file2"
294 [ -f $file2 ] || error "$file2 not found"
296 run_test 4 "lgssd dead, operations should wait timeout and fail"
299 local file1=$DIR/$tfile-1
300 local file2=$DIR/$tfile-2
301 local wait_time=$((TIMEOUT + TIMEOUT / 2))
303 chmod 0777 $DIR || error "chmod $DIR failed"
304 # current access should be ok
305 $RUNAS touch $file1 || error "can't touch $file1"
306 [ -f $file1 ] || error "$file1 not found"
309 send_sigint $(comma_list $(mdts_nodes)) lsvcgssd
311 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd && error "lsvcgssd still running"
313 # flush context, and touch
314 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
315 $RUNAS touch $file2 &
319 echo "waiting $wait_time seconds for touch pid $TOUCHPID"
321 num=`ps --no-headers -p $TOUCHPID | wc -l`
322 [ $num -eq 1 ] || error "touch already ended ($num)"
323 echo "process $TOUCHPID still hanging there... OK"
325 # restart lsvcgssd, expect touch suceed
326 echo "restart lsvcgssd and recovering"
327 start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -v"
329 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd
330 wait $TOUCHPID || error "touch fail"
331 [ -f $file2 ] || error "$file2 not found"
333 run_test 5 "lsvcgssd dead, operations lead to recovery"
338 mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
339 for ((i=0; i<$nfile; i++)); do
340 dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
342 ls -l $DIR/d6/* > /dev/null || error "ls failed"
343 rm -rf $DIR2/d6/* || error "rm failed"
344 rmdir $DIR2/d6/ || error "rmdir failed"
346 run_test 6 "test basic DLM callback works"
352 # for open(), client only reserve space for default stripe count lovea,
353 # and server may return larger lovea in reply (because of larger stripe
354 # count), client need call enlarge_reqbuf() and save the replied lovea
355 # in request for future possible replay.
357 # Note: current script does NOT guarantee enlarge_reqbuf() will be in
358 # the path, however it does work in local test which has 2 OSTs and
359 # default stripe count is 1.
360 num_osts=$($LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l)
361 echo "found $num_osts active OSTs"
362 [ $num_osts -lt 2 ] &&
363 echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
365 mkdir $tdir || error "mkdir $tdir failed"
366 $LFS setstripe -c $num_osts $tdir || error "setstripe -c $num_osts"
369 for ((i = 0; i < 20; i++)); do
370 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
373 for ((i = 0; i < 20; i++)); do
374 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
378 run_test 7 "exercise enlarge_reqbuf()"
382 local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
383 local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
385 do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
392 sysctl -w lnet.debug="+other"
394 # wait for the at estimation come down, this is faster
396 REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
397 awk '/portal 12/ {print $5}' | tail -1`
398 [ $REQ_DELAY -le 5 ] && break
399 echo "current AT estimation is $REQ_DELAY, wait a little bit"
402 REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
404 # sleep sometime in ctx handle
405 do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
406 #define OBD_FAIL_SEC_CTX_HDL_PAUSE 0x1204
407 do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
409 $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
411 $RUNAS touch $DIR/d8/f &
413 echo "waiting for touch (pid $TOUCHPID) to finish..."
414 sleep 2 # give it a chance to really trigger context init rpc
415 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
416 wait $TOUCHPID || error "touch should have succeeded"
418 $LCTL dk | grep "Early reply #" || error "No early reply"
421 do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
423 run_test 8 "Early reply sent for slow gss context negotiation"
426 # following tests will manipulate flavors and may end with any flavor set,
427 # so each test should not assume any start flavor.
431 if [ "$SLOW" = "no" ]; then
437 restore_to_default_flavor
438 set_rule $FSNAME any any krb5p
439 wait_flavor all2all krb5p
443 for ((n=0;n<$total;n++)); do
446 echo "flush ctx ($n/$total) ..."
447 $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
450 #sleep to let ctxs be re-established
454 run_test 90 "recoverable from losing contexts under load"
464 nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
465 | grep "$FSNAME.srpc.flavor." | wc -l`
466 echo "original general rules: $nrule_old"
468 for ((i = $nrule_old; i < $max; i++)); do
469 set_rule $FSNAME elan$i any krb5n || error "set rule $i"
471 for ((i = $nrule_old; i < $max; i++)); do
472 set_rule $FSNAME elan$i any || error "remove rule $i"
475 nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
476 | grep "$FSNAME.srpc.flavor." | wc -l`
477 if [ $nrule_new != $nrule_old ]; then
478 error "general rule: $nrule_new != $nrule_old"
482 # target-specific rules
484 nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
485 | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
486 echo "original target rules: $nrule_old"
488 for ((i = $nrule_old; i < $max; i++)); do
489 set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
491 for ((i = $nrule_old; i < $max; i++)); do
492 set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
495 nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
496 | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
497 if [ $nrule_new != $nrule_old ]; then
498 error "general rule: $nrule_new != $nrule_old"
501 run_test 99 "set large number of sptlrpc rules"
514 # started from default flavors
515 restore_to_default_flavor
517 # running dbench background
521 # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
523 set_rule $FSNAME any any krb5n
524 wait_flavor all2all krb5n || error_dbench "1"
527 set_rule $FSNAME any any krb5a
528 wait_flavor all2all krb5a || error_dbench "2"
531 set_rule $FSNAME any any krb5i
532 wait_flavor all2all krb5i || error_dbench "3"
535 set_rule $FSNAME any any krb5p
536 wait_flavor all2all krb5p || error_dbench "4"
539 set_rule $FSNAME any any plain
540 wait_flavor all2all plain || error_dbench "5"
549 set_rule $FSNAME any mdt2mdt krb5a
550 wait_flavor mdt2mdt krb5a || error_dbench "6"
553 set_rule $FSNAME any cli2mdt krb5i
554 wait_flavor cli2mdt krb5i || error_dbench "7"
557 set_rule $FSNAME any mdt2ost krb5p
558 wait_flavor mdt2ost krb5p || error_dbench "8"
561 set_rule $FSNAME any cli2ost krb5n
562 wait_flavor cli2ost krb5n || error_dbench "9"
569 # nothing should be changed because they are override by above dir rules
571 set_rule $FSNAME-MDT0000 any any krb5p
572 set_rule $FSNAME-OST0000 any any krb5i
573 wait_flavor mdt2mdt krb5a || error_dbench "10"
574 wait_flavor cli2mdt krb5i || error_dbench "11"
576 wait_flavor mdt2ost krb5p || error_dbench "12"
577 wait_flavor cli2ost krb5n || error_dbench "13"
580 # delete all dir-specific rules
582 set_rule $FSNAME any mdt2mdt
583 set_rule $FSNAME any cli2mdt
584 set_rule $FSNAME any mdt2ost
585 set_rule $FSNAME any cli2ost
586 wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
587 wait_flavor cli2mdt krb5p $(get_clients_mount_count) || error_dbench "15"
589 wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
590 wait_flavor cli2ost krb5i $(get_clients_mount_count) || error_dbench "17"
598 set_rule $FSNAME-MDT0000 any any
599 set_rule $FSNAME-OST0000 any any || error_dbench "18"
600 wait_flavor all2all plain || error_dbench "19"
605 run_test 100 "change security flavor on the fly under load"
611 local filename=$DIR/$tfile
616 # after set to flavor0, start multop which use flavor0 rpc, and let
617 # server drop the reply; then switch to flavor1, the resend should be
618 # completed using flavor1. To exercise the code of switching ctx/sec
619 # for a resend request.
621 log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
623 set_rule $FSNAME any cli2mdt $flavor0
624 wait_flavor cli2mdt $flavor0
625 rm -f $filename || error "remove old $filename failed"
628 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
629 do_facet $SINGLEMDS lctl set_param fail_val=36
630 do_facet $SINGLEMDS lctl set_param fail_loc=0x513
631 log "starting multiop"
632 $MULTIOP $filename m &
634 echo "multiop pid=$multiop_pid"
637 set_rule $FSNAME any cli2mdt $flavor1
638 wait_flavor cli2mdt $flavor1
640 num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
641 [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
642 echo "process $multiop_pid is still hanging there... OK"
644 do_facet $SINGLEMDS lctl set_param fail_loc=0
645 log "waiting for multiop ($multiop_pid) to finish"
646 wait $multiop_pid || error "multiop returned error"
651 # started from default flavors
652 restore_to_default_flavor
654 switch_sec_test null plain
655 switch_sec_test plain krb5n
656 switch_sec_test krb5n krb5a
657 switch_sec_test krb5a krb5i
658 switch_sec_test krb5i krb5p
659 switch_sec_test krb5p null
660 switch_sec_test null krb5p
661 switch_sec_test krb5p krb5i
662 switch_sec_test krb5i plain
663 switch_sec_test plain krb5p
665 run_test 101 "switch ctx/sec for resending request"
678 # started from default flavors
679 restore_to_default_flavor
681 # run dbench background
684 echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
685 set_rule $FSNAME any any krb5n
686 set_rule $FSNAME any any krb5a
687 set_rule $FSNAME any any krb5i
688 set_rule $FSNAME any any krb5p
689 set_rule $FSNAME any any plain
690 set_rule $FSNAME any any null
693 wait_flavor all2all null || error_dbench "1"
696 echo "waiting for 15s and check again"
700 echo "Testing null->krb5i->null->krb5i->null..."
701 for ((i=0; i<10; i++)); do
702 set_rule $FSNAME any any krb5i
703 set_rule $FSNAME any any null
705 set_rule $FSNAME any any krb5i
708 wait_flavor all2all krb5i || error_dbench "2"
711 echo "waiting for 15s and check again"
717 run_test 102 "survive from insanely fast flavor switch"
722 local clients=$CLIENTS
724 [ -z $clients ] && clients=$HOSTNAME
726 # started from default flavors
727 restore_to_default_flavor
729 # at this time no rules has been set on mgs; mgc use null
730 # flavor connect to mgs.
731 count=`flvr_cnt_mgc2mgs null`
732 [ $count -eq 1 ] || error "$count mgc connection use null flavor"
734 zconf_umount_clients $clients $MOUNT || return 1
736 # mount client with conflict flavor - should fail
738 MOUNTOPT="$MOUNTOPT,mgssec=krb5p"
739 zconf_mount_clients $clients $MOUNT && \
740 error "mount with conflict flavor should have failed"
743 # mount client with same flavor - should succeed
745 MOUNTOPT="$MOUNTOPT,mgssec=null"
746 zconf_mount_clients $clients $MOUNT || \
747 error "mount with same flavor should have succeeded"
749 zconf_umount_clients $clients $MOUNT || return 2
751 # mount client with default flavor - should succeed
752 zconf_mount_clients $clients $MOUNT || \
753 error "mount with default flavor should have succeeded"
755 run_test 150 "secure mgs connection: client flavor setting"
760 # set mgs only accept krb5p
761 set_rule _mgs any any krb5p
763 # umount everything, modules still loaded
766 # mount mgs with default flavor, in current framework it means mgs+mdt1.
767 # the connection of mgc of mdt1 to mgs is expected fail.
768 DEVNAME=$(mdsdevname 1)
769 start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
771 # mount with unauthorized flavor should fail
772 save_opts=$MDS_MOUNT_OPTS
773 MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
774 start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
775 MDS_MOUNT_OPTS=$save_opts
777 # mount with designated flavor should succeed
778 save_opts=$MDS_MOUNT_OPTS
779 MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=krb5p"
780 start mds1 $DEVNAME $MDS_MOUNT_OPTS || error "mount with designated flavor should have succeeded"
781 MDS_MOUNT_OPTS=$save_opts
785 run_test 151 "secure mgs connection: server flavor control"
788 check_and_cleanup_lustre