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"
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_GSS_EXCEPT"
18 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
22 require_dsh_mds || exit 0
24 # $RUNAS_ID may get set incorrectly somewhere else
25 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
26 error "RUNAS_ID set to 0, but UID is also 0!"
28 # remove $SEC, we'd like to control everything by ourselves
32 # global variables of this sanity
40 prepare_krb5_creds() {
41 echo prepare krb5 cred
43 $RUNAS krb5_login.sh || exit 1
48 # we want double mount
49 MOUNT_2=${MOUNT_2:-"yes"}
50 check_and_setup_lustre
52 rm -rf $DIR/[df][0-9]*
54 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
58 local NPROC=$(grep -c ^processor /proc/cpuinfo)
59 [ $NPROC -gt 2 ] && NPROC=2
60 bash rundbench -D $DIR/$tdir $NPROC 1>/dev/null &
64 num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
65 if [ $num -ne 1 ]; then
66 error "failed to start dbench $NPROC"
68 echo "started dbench with $NPROC processes at background"
76 num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
77 if [ $num -eq 0 ]; then
78 echo "dbench $DBENCH_PID already finished"
79 wait $DBENCH_PID || error "dbench $PID exit with error"
81 elif [ $num -ne 1 ]; then
83 error "found $num instance of pid $DBENCH_PID ???"
92 killall dbench 2>/dev/null
93 local num=$(ps --no-headers -p $DBENCH_PID | wc -l)
94 if [ $num -eq 0 ]; then
95 echo "dbench finished"
98 echo "dbench $DBENCH_PID is still running, waiting 2s..."
102 wait $DBENCH_PID || true
116 restore_krb5_cred() {
117 local keys=$(keyctl show | awk '$6 ~ "^lgssc:" {print $1}')
123 $RUNAS krb5_login.sh || exit 1
126 check_multiple_gss_daemons() {
129 local gssd_name=$(basename $gssd)
131 for ((i = 0; i < 10; i++)); do
132 do_facet $facet "$gssd -vvv"
135 # wait daemons entering "stable" status
138 local num=$(do_facet $facet ps -o cmd -C $gssd_name |
140 echo "$num instance(s) of $gssd_name are running"
142 if [ $num -ne 1 ]; then
143 error "$gssd_name not unique"
153 echo "bring up gss daemons..."
156 echo "check with someone already running..."
157 check_multiple_gss_daemons $my_facet $LSVCGSSD
159 echo "check with someone run & finished..."
160 do_facet $my_facet killall -q -2 lgssd $LSVCGSSD || true
161 sleep 5 # wait fully exit
162 check_multiple_gss_daemons $my_facet $LSVCGSSD
164 echo "check refresh..."
165 do_facet $my_facet killall -q -2 lgssd $LSVCGSSD || true
166 sleep 5 # wait fully exit
167 do_facet $my_facet ipcrm -S 0x3b92d473
168 check_multiple_gss_daemons $my_facet $LSVCGSSD
170 run_test 0 "start multiple gss daemons"
175 local file=$DIR/$tdir/$tfile
177 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
178 chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
179 $RUNAS ls -ld $DIR/$tdir
182 $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
183 $RUNAS touch $file && error "unexpected success"
187 $RUNAS touch $file || error "should not fail"
188 [ -f $file ] || error "$file not found"
190 run_test 1 "access with or without krb5 credential"
193 local file1=$DIR/$tdir/$tfile-1
194 local file2=$DIR/$tdir/$tfile-2
196 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
197 chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
199 # current access should be ok
200 $RUNAS touch $file1 || error "can't touch $file1"
201 [ -f $file1 ] || error "$file1 not found"
203 # cleanup all cred/ctx and touch
204 $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
205 $RUNAS touch $file2 && error "unexpected success"
209 $RUNAS touch $file2 || error "should not fail"
210 [ -f $file2 ] || error "$file2 not found"
212 run_test 2 "lfs flushctx"
215 local file=$DIR/$tdir/$tfile
217 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
218 chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
221 echo "aaaaaaaaaaaaaaaaa" > $file
223 $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
224 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
225 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
228 $RUNAS $MULTIOP $file o_r &
230 # wait multiop finish its open()
233 # cleanup all cred/ctx and check
234 # metadata check should fail, but file data check should succeed
235 # because we always use root credential to OSTs
236 $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
237 echo "destroyed credentials/contexs for $RUNAS_ID"
238 $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
240 wait $OPPID || error "read file data failed"
241 echo "read file data OK"
243 # restore and check again
245 echo "restored credentials for $RUNAS_ID"
246 $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
247 echo "$RUNAS_ID checkstat OK"
248 $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
249 echo "$UID checkstat OK"
250 $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
251 echo "$RUNAS_ID read file data OK"
253 run_test 3 "local cache under DLM lock"
256 local file1=$DIR/$tdir/$tfile-1
257 local file2=$DIR/$tdir/$tfile-2
258 local wait_time=$((TIMEOUT + TIMEOUT / 2))
260 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
261 chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
263 # current access should be ok
264 $RUNAS touch $file1 || error "can't touch $file1"
265 [ -f $file1 ] || error "$file1 not found"
268 send_sigint $(comma_list $(mdts_nodes)) $LSVCGSSD
270 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) $LSVCGSSD &&
271 error "$LSVCGSSD still running"
273 # flush context, and touch
274 $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context (1)"
276 $RUNAS touch $file2 && error "should fail without $LSVCGSSD"
278 # restart lsvcgssd, expect touch succeed
279 echo "restart $LSVCGSSD and recovering"
280 start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -vvv"
282 check_gss_daemon_nodes $(comma_list $(mdts_nodes)) $LSVCGSSD
283 $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context (2)"
285 $RUNAS touch $file2 || error "should not fail now"
286 [ -f $file2 ] || error "$file2 not found"
288 run_test 5 "lsvcgssd dead, operations fail"
293 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
294 for ((i=0; i<$nfile; i++)); do
295 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=8k count=1 ||
296 error "dd $tfile-$i failed"
298 ls -l $DIR/$tdir/* > /dev/null || error "ls failed"
299 rm -rf $DIR2/$tdir/* || error "rm failed"
300 rmdir $DIR2/$tdir || error "rmdir failed"
302 run_test 6 "test basic DLM callback works"
307 # for open(), client only reserve space for default stripe count lovea,
308 # and server may return larger lovea in reply (because of larger stripe
309 # count), client need call enlarge_reqbuf() and save the replied lovea
310 # in request for future possible replay.
312 # Note: current script does NOT guarantee enlarge_reqbuf() will be in
313 # the path, however it does work in local test which has 2 OSTs and
314 # default stripe count is 1.
315 [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
317 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
318 $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe -c $OSTCOUNT"
321 for ((i = 0; i < 20; i++)); do
322 dd if=/dev/zero of=$DIR/$tdir/f$i bs=4k count=16 2>/dev/null
325 for ((i = 0; i < 20; i++)); do
326 dd if=$DIR/$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
329 run_test 7 "exercise enlarge_reqbuf()"
333 local atoldbase=$(do_facet $SINGLEMDS "$LCTL get_param -n at_history")
336 do_facet $SINGLEMDS "$LCTL set_param at_history=8" || true
338 "do_facet $SINGLEMDS $LCTL set_param at_history=$atoldbase" EXIT
345 stack_trap debugrestore EXIT
346 $LCTL set_param debug=+other
348 # wait for the at estimation come down, this is faster
350 req_delay=$($LCTL get_param -n \
351 mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
352 awk '/portal 12/ {print $5}' | tail -1)
353 [ $req_delay -le 5 ] && break
354 echo "current AT estimation is $req_delay, wait a little bit"
357 req_delay=$((${req_delay} + ${req_delay} / 4 + 5))
359 # sleep sometime in ctx handle
360 do_facet $SINGLEMDS $LCTL set_param fail_val=$req_delay
361 #define OBD_FAIL_SEC_CTX_HDL_PAUSE 0x1204
362 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1204
364 $RUNAS $LFS flushctx -k -r $MOUNT ||
365 error "can't flush context on $MOUNT"
368 $RUNAS touch $DIR/$tdir/$tfile &
370 echo "waiting for touch (pid $TOUCHPID) to finish..."
371 sleep 2 # give it a chance to really trigger context init rpc
372 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
373 wait $TOUCHPID || error "touch should have succeeded"
375 $LCTL dk | grep -i "Early reply #" || error "No early reply"
377 run_test 8 "Early reply sent for slow gss context negotiation"
380 # following tests will manipulate flavors and may end with any flavor set,
381 # so each test should not assume any start flavor.
385 if [ "$SLOW" = "no" ]; then
393 restore_to_default_flavor
398 for ((n = 1; n <= $total; n++)); do
401 echo "flush ctx ($n/$total) ..."
402 $LFS flushctx -k -r $MOUNT ||
403 error "can't flush context on $MOUNT"
406 #sleep to let ctxs be re-established
410 run_test 90 "recoverable from losing contexts under load"
420 nrule_old=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
421 2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
422 echo "original general rules: $nrule_old"
424 for ((i = $nrule_old; i < $max; i++)); do
425 set_rule $FSNAME ${NETTYPE}$i cli2mdt krb5n ||
426 error "set rule $i (1)"
427 set_rule $FSNAME ${NETTYPE}$i cli2ost krb5n ||
428 error "set rule $i (2)"
429 set_rule $FSNAME ${NETTYPE}$i mdt2ost null ||
430 error "set rule $i (3)"
431 set_rule $FSNAME ${NETTYPE}$i mdt2mdt null ||
432 error "set rule $i (4)"
434 for ((i = $nrule_old; i < $max; i++)); do
435 set_rule $FSNAME ${NETTYPE}$i cli2mdt ||
436 error "remove rule $i (1)"
437 set_rule $FSNAME ${NETTYPE}$i cli2ost ||
438 error "remove rule $i (2)"
439 set_rule $FSNAME ${NETTYPE}$i mdt2ost ||
440 error "remove rule $i (3)"
441 set_rule $FSNAME ${NETTYPE}$i mdt2mdt ||
442 error "remove rule $i (4)"
446 nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
447 2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
448 if [ $nrule_new != $nrule_old ]; then
449 error "general rule: $nrule_new != $nrule_old"
453 # target-specific rules
455 nrule_old=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
456 2>/dev/null | grep -c "$FSNAME-MDT0000.srpc.flavor.")
457 echo "original target rules: $nrule_old"
459 for ((i = $nrule_old; i < $max; i++)); do
460 set_rule $FSNAME-MDT0000 ${NETTYPE}$i cli2mdt krb5i ||
461 error "set new rule $i (1)"
462 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2ost null ||
463 error "set new rule $i (2)"
464 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2mdt null ||
465 error "set new rule $i (3)"
467 for ((i = $nrule_old; i < $max; i++)); do
468 set_rule $FSNAME-MDT0000 ${NETTYPE}$i cli2mdt ||
469 error "remove new rule $i (1)"
470 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2ost ||
471 error "remove new rule $i (2)"
472 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2mdt ||
473 error "remove new rule $i (3)"
476 nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
477 2>/dev/null \ | grep -c "$FSNAME-MDT0000.srpc.flavor.")
478 if [ $nrule_new != $nrule_old ]; then
479 error "general rule: $nrule_new != $nrule_old"
482 run_test 99 "set large number of sptlrpc rules"
485 # started from default flavors
486 restore_to_default_flavor
490 # running dbench in background
494 # all: null -> krb5n -> krb5a -> krb5i -> krb5p
512 # nothing should be changed because they are overridden by above rules
514 set_rule $FSNAME-MDT0000 any cli2mdt krb5a
515 set_rule $FSNAME-OST0000 any cli2ost krb5i
516 wait_flavor cli2mdt krb5p || error_dbench "1"
518 wait_flavor cli2ost krb5p || error_dbench "2"
525 set_rule $FSNAME-MDT0000 any cli2mdt
526 set_rule $FSNAME-OST0000 any cli2ost
532 set_rule $FSNAME any mdt2mdt
533 set_rule $FSNAME any cli2mdt
534 set_rule $FSNAME any mdt2ost
535 set_rule $FSNAME any cli2ost
536 restore_to_default_flavor
541 run_test 100 "change security flavor on the fly under load"
547 local filename=$DIR/$tfile
552 # after setting flavor0, start multiop which uses flavor0 rpc, and let
553 # server drop the reply; then switch to flavor1, the resend should be
554 # completed using flavor1. To exercise the code of switching ctx/sec
555 # for a resend request.
557 log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
559 set_rule $FSNAME any cli2mdt $flavor0
560 wait_flavor cli2mdt $flavor0
561 rm -f $filename || error "remove old $filename failed"
564 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
565 do_facet $SINGLEMDS lctl set_param fail_val=36
566 do_facet $SINGLEMDS lctl set_param fail_loc=0x513
567 log "starting multiop"
568 $MULTIOP $filename m &
570 echo "multiop pid=$multiop_pid"
573 set_rule $FSNAME any cli2mdt $flavor1
574 wait_flavor cli2mdt $flavor1
576 num=$(ps --no-headers -p $multiop_pid 2>/dev/null | wc -l)
577 [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
578 echo "process $multiop_pid is still hanging there... OK"
580 do_facet $SINGLEMDS lctl set_param fail_loc=0
581 log "waiting for multiop ($multiop_pid) to finish"
582 wait $multiop_pid || error "multiop returned error"
587 # started from default flavors
588 restore_to_default_flavor
590 switch_sec_test null krb5n
591 switch_sec_test krb5n krb5a
592 switch_sec_test krb5a krb5i
593 switch_sec_test krb5i krb5p
594 switch_sec_test krb5p null
596 run_test 101 "switch ctx/sec for resending request"
609 # started from default flavors
610 restore_to_default_flavor
614 # run dbench background
617 echo "Testing null->krb5n->krb5a->krb5i->krb5p->null"
626 echo "waiting for 15s and check again"
630 echo "Testing null->krb5i->null->krb5i->null..."
631 for ((idx = 0; idx < 5; idx++)); do
639 echo "waiting for 15s and check again"
645 run_test 102 "survive from fast flavor switch"
650 local clients=$CLIENTS
652 [ -z $clients ] && clients=$HOSTNAME
654 # started from default flavors
655 restore_to_default_flavor
657 # at this time no rules has been set on mgs; mgc use null
658 # flavor to connect to mgs
659 count=$(flvr_cnt_mgc2mgs null)
660 [ $count -eq 1 ] || error "$count mgc connections use null flavor"
662 zconf_umount_clients $clients $MOUNT || error "umount failed (1)"
664 # mount client with conflict flavor - should fail
665 mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=krb5p"
666 zconf_mount_clients $clients $MOUNT $mount_opts &&
667 error "mount with conflict flavor should have failed"
669 # mount client with same flavor - should succeed
670 mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=null"
671 zconf_mount_clients $clients $MOUNT $mount_opts ||
672 error "mount with same flavor should have succeeded"
673 zconf_umount_clients $clients $MOUNT || error "umount failed (2)"
675 # mount client with default flavor - should succeed
676 zconf_mount_clients $clients $MOUNT ||
677 error "mount with default flavor should have succeeded"
679 run_test 150 "secure mgs connection: client flavor setting"
683 set_rule _mgs any any
685 # umount everything, then remount
693 stack_trap exit_151 EXIT
695 # set mgs rule to only accept krb5p
696 set_rule _mgs any any krb5p
698 # umount everything, modules still loaded
701 # start gss daemon on mgs node
702 combined_mgs_mds || start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv"
705 start mgs $(mgsdevname 1) $MDS_MOUNT_OPTS
707 # mount with default flavor, expected to fail
708 start ost1 "$(ostdevname 1)" $OST_MOUNT_OPTS
709 wait_mgc_import_state ost1 FULL 0 &&
710 error "mount with default flavor should have failed"
713 # mount with unauthorized flavor should fail
714 if [ -z "$OST_MOUNT_OPTS" ]; then
715 new_opts="-o mgssec=null"
717 new_opts="$OST_MOUNT_OPTS,mgssec=null"
719 start ost1 "$(ostdevname 1)" $new_opts
720 wait_mgc_import_state ost1 FULL 0 &&
721 error "mount with unauthorized flavor should have failed"
724 # mount with designated flavor should succeed
725 if [ -z "$OST_MOUNT_OPTS" ]; then
726 new_opts="-o mgssec=krb5p"
728 new_opts="$OST_MOUNT_OPTS,mgssec=krb5p"
730 start ost1 "$(ostdevname 1)" $new_opts
731 wait_mgc_import_state ost1 FULL 0 ||
732 error "mount with designated flavor should have succeeded"
736 run_test 151 "secure mgs connection: server flavor control"
741 check_and_cleanup_lustre