3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export SHARED_KEY=${SHARED_KEY:-false}
15 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
16 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
17 export SK_MOUNTED=${SK_MOUNTED:-false}
18 export SK_FLAVOR=${SK_FLAVOR:-ski}
19 export SK_NO_KEY=${SK_NO_KEY:-true}
20 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
21 export SK_S2S=${SK_S2S:-false}
22 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
23 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
24 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
25 # whether identity upcall is enabled (true), disabled (false), or default
26 export IDENTITY_UPCALL=${IDENTITY_UPCALL:-default}
28 export FLAKEY=${FLAKEY:-true}
29 # specify environment variable containing batch job name for server statistics
30 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
32 #export PDSH="pdsh -S -Rssh -w"
33 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
34 export UMOUNT=${UMOUNT:-"umount -d"}
36 # A switch to enable kptr less restrictively
37 export KPTR_ON_MOUNT=${KPTR_ON_MOUNT:-true}
39 export LSNAPSHOT_CONF="/etc/ldev.conf"
40 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
42 export DATA_SEQ_MAX_WIDTH=0x1ffffff
44 # sles12 umount has a issue with -d option
45 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
46 export UMOUNT="umount"
49 # function used by scripts run on remote nodes
50 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
51 . $LUSTRE/tests/functions.sh
52 . $LUSTRE/tests/yaml.sh
54 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
56 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
58 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
60 if [ -f "$EXCEPT_LIST_FILE" ]; then
61 echo "Reading test skip list from $EXCEPT_LIST_FILE"
66 # check config files for options in decreasing order of preference
67 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
68 MODPROBECONF=/etc/modprobe.d/lustre.conf
69 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
70 MODPROBECONF=/etc/modprobe.d/Lustre
71 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
72 MODPROBECONF=/etc/modprobe.conf
74 sanitize_parameters() {
75 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
79 if [ -d "$path" ]; then
80 eval export $i=$(echo $path | sed -r 's/\/+$//g')
86 [[ $DIR/ = $MOUNT/* ]] ||
87 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
88 [[ $DIR1/ = $MOUNT1/* ]] ||
89 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
90 [[ $DIR2/ = $MOUNT2/* ]] ||
91 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
93 [ -n "$failed" ] && exit 99 || true
97 echo "usage: $0 [-r] [-f cfgfile]"
105 [ -z "$DEFAULT_SUITES" ] && return 0
106 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
108 local form="%-13s %-17s %-9s %s %s\n"
110 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
111 echo "---------------------------------------------------------------"
112 for O in $DEFAULT_SUITES; do
113 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
114 [ "${!O}" = "no" ] && continue || true
115 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
116 local log=${TMP}/${o}.log
118 if is_sanity_benchmark $o; then
119 log=${TMP}/sanity-benchmark.log
124 local status=Unfinished
127 skipped=$(grep excluded $log |
128 awk '{ printf " %s", $3 }' | sed 's/test_//g')
129 slow=$(egrep "^PASS|^FAIL" $log |
130 tr -d "("| sed s/s\)$//g | sort -nr -k 3 |
131 head -n5 | awk '{ print $2":"$3"s" }')
132 total=$(grep duration $log | awk '{ print $2 }')
133 if [ "${!O}" = "done" ]; then
137 local durations=$(egrep "^PASS|^FAIL" $log |
138 tr -d "("| sed s/s\)$//g |
139 awk '{ print $2":"$3"|" }')
140 details=$(printf "%s\n%s %s %s\n" "$details" \
141 "DDETAILS" "$O" "$(echo $durations)")
144 printf "$form" $status "$O" "${total}" "E=$skipped"
145 printf "$form" "-" "-" "-" "S=$(echo $slow)"
148 for O in $DEFAULT_SUITES; do
149 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
150 if [ "${!O}" = "no" ]; then
151 printf "$form" "Skipped" "$O" ""
155 # print the detailed tests durations if DDETAILS=true
169 ! ${do_setup} && return
170 nfs_client_mode && return
173 local MOUNTED=$(mounted_lustre_filesystems)
175 if $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
176 check_config_clients $MOUNT
182 echo "Lustre is not mounted, trying to do setup ... "
183 $reformat && CLEANUP_DM_DEV=true formatall
186 MOUNTED=$(mounted_lustre_filesystems)
187 if ! $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
188 echo "Lustre is not mounted after setup! "
194 cleanup_if_needed() {
195 if $AUSTER_CLEANUP; then
200 find_script_in_path() {
203 for dir in $(tr : " " <<< $path); do
204 if [ -f $dir/$target ]; then
208 if [ -f $dir/$target.sh ]; then
217 log "-----============= acceptance-small: "$*" ============----- `date`"
222 printf "Would have run: %s\n" "$*"
226 printf "Running: %s\n" "$*"
234 local suite_script=$2
242 local start_ts=$(date +%s)
244 doit $script_lang $suite_script
247 local duration=$(($(date +%s) - $start_ts))
250 if [[ $rc -ne 0 || -f $TF_FAIL ]]; then
252 elif [[ -f $TF_SKIP ]]; then
255 log_test_status $duration $status
256 [[ ! -f $TF_SKIP ]] || rm -f $TF_SKIP
258 # got STOP_NOW_RC, return immediately before reset
259 [[ $rc -eq $STOP_NOW_RC ]] &&
260 echo "stop testing on rc $STOP_NOW_RC" &&
269 local suite_name=${1%.sh}
270 local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
272 suite_script=$(find_script_in_path $suite_name $LUSTRE/tests)
274 if [[ -z $suite_script ]]; then
275 echo "Can't find test script for $suite_name"
279 echo "run_suite $suite_name $suite_script"
281 local log_name=${suite_name}.suite_log.$(hostname -s).log
284 run_suite $suite_name $suite_script 2>&1 |tee $LOGDIR/$log_name
286 run_suite $suite_name $suite_script > $LOGDIR/$log_name 2>&1
289 return ${PIPESTATUS[0]}
307 while ((n < repeat_count)); do
309 local logdir=${test_logs_dir}
310 local first_suite=$FIRST_SUITE
312 ((repeat_count > 1)) && logdir="$logdir/$n"
313 reset_logging $logdir
315 while [[ -n $1 ]]; do
316 unset ONLY EXCEPT START_AT STOP_AT
322 while [[ -n $1 ]]; do
326 export ONLY=$(split_commas $1)
328 opts+="ONLY=$ONLY ";;
331 export SUITE=$(split_commas $1)
333 opts+="SUITE=$SUITE ";;
336 export PATTERN=$(split_commas $1)
338 opts+="PATTERN=$PATTERN ";;
341 export EXCEPT=$(split_commas $1)
343 opts+="EXCEPT=$EXCEPT ";;
348 opts+="START_AT=$START_AT ";;
353 opts+="STOP_AT=$STOP_AT ";;
356 export STOP_ON_ERROR=$(split_commas $1)
358 opts+="STOP_ON_ERROR=$STOP_ON_ERROR ";;
368 # If first_suite not set or this is the first suite
369 if [ "x"$first_suite == "x" ] || [ $first_suite == $suite ]; then
370 echo "running: $suite $opts"
371 run_suite_logged $suite || RC=$?
373 echo $suite returned $RC
375 # stop testing immediately if rc is STOP_NOW_RC
376 [[ $RC -eq $STOP_NOW_RC ]] && exit $STOP_NOW_RC
379 if $upload_logs; then
380 $upload_script $LOGDIR
386 # Get information about the Lustre environment. The information collected
387 # will be used in Lustre tests.
388 # usage: get_lustre_env
389 # input: No required or optional arguments
390 # output: No return values, environment variables are exported
394 export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
395 export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
397 export MGS_VERSION=$(lustre_version_code mgs)
398 export MDS1_VERSION=$(lustre_version_code mds1)
399 export OST1_VERSION=$(lustre_version_code ost1)
400 export CLIENT_VERSION=$(lustre_version_code client)
402 # import server-side version information into local variables
403 # so they can be used in tests instead of checked separately
404 # MGS_OS_VERSION_ID, MGS_OS_ID, MGS_OS_ID_LIKE,
405 # MDS1_OS_VERSION_ID, MDS1_OS_ID, MDS1_OS_ID_LIKE,
406 # OST1_OS_VERSION_ID, OST1_OS_ID, OST1_OS_ID_LIKE,
407 # CLIENT_OS_VERSION_ID, CLIENT_OS_ID, CLIENT_OS_ID_LIKE
408 lustre_os_release mgs
409 lustre_os_release mds1
410 lustre_os_release ost1
411 lustre_os_release client
414 # Prefer using "mds1" directly instead of SINGLEMDS.
415 # Keep this for compat until it is removed from scripts.
416 export SINGLEMDS=${SINGLEMDS:-mds1}
420 export LUSTRE=$(absolute_path $LUSTRE)
421 export TESTSUITE=$(basename $0 .sh)
422 export TEST_FAILED=false
423 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
424 export RPC_MODE=${RPC_MODE:-false}
425 export DO_CLEANUP=${DO_CLEANUP:-true}
426 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
427 export CLEANUP_DM_DEV=false
428 export PAGE_SIZE=$(get_page_size client)
429 export NAME=${NAME:-local}
431 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
433 export MKE2FS=$MKE2FS
434 if [ -z "$MKE2FS" ]; then
435 if which mkfs.ldiskfs >/dev/null 2>&1; then
436 export MKE2FS=mkfs.ldiskfs
442 export DEBUGFS=$DEBUGFS
443 if [ -z "$DEBUGFS" ]; then
444 if which debugfs.ldiskfs >/dev/null 2>&1; then
445 export DEBUGFS=debugfs.ldiskfs
447 export DEBUGFS=debugfs
451 export TUNE2FS=$TUNE2FS
452 if [ -z "$TUNE2FS" ]; then
453 if which tunefs.ldiskfs >/dev/null 2>&1; then
454 export TUNE2FS=tunefs.ldiskfs
456 export TUNE2FS=tune2fs
460 export E2LABEL=$E2LABEL
461 if [ -z "$E2LABEL" ]; then
462 if which label.ldiskfs >/dev/null 2>&1; then
463 export E2LABEL=label.ldiskfs
465 export E2LABEL=e2label
469 export DUMPE2FS=$DUMPE2FS
470 if [ -z "$DUMPE2FS" ]; then
471 if which dumpfs.ldiskfs >/dev/null 2>&1; then
472 export DUMPE2FS=dumpfs.ldiskfs
474 export DUMPE2FS=dumpe2fs
478 export E2FSCK=$E2FSCK
479 if [ -z "$E2FSCK" ]; then
480 if which fsck.ldiskfs >/dev/null 2>&1; then
481 export E2FSCK=fsck.ldiskfs
487 export RESIZE2FS=$RESIZE2FS
488 if [ -z "$RESIZE2FS" ]; then
489 if which resizefs.ldiskfs >/dev/null 2>&1; then
490 export RESIZE2FS=resizefs.ldiskfs
492 export RESIZE2FS=resize2fs
496 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
497 export FSCK_MAX_ERR=4 # File system errors left uncorrected
499 export ZFS=${ZFS:-zfs}
500 export ZPOOL=${ZPOOL:-zpool}
501 export ZDB=${ZDB:-zdb}
502 export PARTPROBE=${PARTPROBE:-partprobe}
504 #[ -d /r ] && export ROOT=${ROOT:-/r}
505 export TMP=${TMP:-$ROOT/tmp}
506 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
507 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
508 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
510 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
511 if ! echo $PATH | grep -q $LUSTRE/utils; then
512 export PATH=$LUSTRE/utils:$PATH
514 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
515 export PATH=$LUSTRE/utils/gss:$PATH
517 if ! echo $PATH | grep -q $LUSTRE/tests; then
518 export PATH=$LUSTRE/tests:$PATH
520 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
521 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
523 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
524 [ ! -f "$LST" ] && export LST=$(which lst)
525 export LSTSH=${LSTSH:-"$LUSTRE/../lustre-iokit/lst-survey/lst.sh"}
526 [ ! -f "$LSTSH" ] && export LSTSH=$(which lst.sh)
527 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
528 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
529 export MCREATE=${MCREATE:-mcreate}
530 export MULTIOP=${MULTIOP:-multiop}
531 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
532 export STATX=${STATX:-statx}
533 # Ubuntu, at least, has a truncate command in /usr/bin
534 # so fully path our truncate command.
535 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
536 export FSX=${FSX:-$LUSTRE/tests/fsx}
537 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
538 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
539 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
540 export PATH=$LUSTRE/tests/racer:$PATH:
542 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
543 export PATH=$LUSTRE/tests/mpi:$PATH
546 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
547 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
548 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
549 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
550 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
551 [ ! -f "$LFS" ] && export LFS=$(which lfs)
552 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
553 [ ! -f "$KSOCKLND_CONFIG" ] &&
554 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
556 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
558 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
559 if [ ! -f "$L_GETIDENTITY" ]; then
560 if $(which l_getidentity > /dev/null 2>&1); then
561 export L_GETIDENTITY=$(which l_getidentity)
563 export L_GETIDENTITY=NONE
566 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
567 [ ! -f "$LL_DECODE_FILTER_FID" ] &&
568 export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
569 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
570 [ ! -f "$LL_DECODE_LINKEA" ] &&
571 export LL_DECODE_LINKEA="ll_decode_linkea"
572 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
573 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
574 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
575 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
576 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
577 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
578 [ ! -f "$LUSTRE_RMMOD" ] &&
579 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
580 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
581 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
582 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
583 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
584 [ ! -f "$LFS_MIGRATE" ] &&
585 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
586 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
587 [ ! -f "$LR_READER" ] &&
588 export LR_READER=$(which lr_reader 2> /dev/null)
589 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
590 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
591 [ ! -f "$LSOM_SYNC" ] &&
592 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
593 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
594 export L_GETAUTH=${L_GETAUTH:-"$LUSTRE/utils/gss/l_getauth"}
595 [ ! -f "$L_GETAUTH" ] && export L_GETAUTH=$(which l_getauth 2> /dev/null)
596 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
597 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
598 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
600 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
602 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
603 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
605 export DMSETUP=${DMSETUP:-dmsetup}
606 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
607 export LOSETUP=${LOSETUP:-losetup}
609 if [ "$ACCEPTOR_PORT" ]; then
610 export PORT_OPT="--port $ACCEPTOR_PORT"
614 $RPC_MODE || echo "Using GSS shared-key feature"
616 export LGSS_SK=$(which lgss_sk 2> /dev/null)
618 export LGSS_SK="$LUSTRE/utils/gss/lgss_sk"
620 error_exit "built with lgss_sk disabled! SEC=$SEC"
628 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
629 which lgss_keyring > /dev/null 2>&1 ||
630 error_exit "built with gss disabled! SEC=$SEC"
636 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
638 # Paths on remote nodes, if different
639 export RLUSTRE=${RLUSTRE:-$LUSTRE}
640 export RPWD=${RPWD:-$PWD}
641 export I_MOUNTED=${I_MOUNTED:-"no"}
642 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
643 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
644 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
645 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
646 ! -f $LUSTRE/mdt/mdt.ko ]; then
647 export CLIENTMODSONLY=yes
650 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
651 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
655 while getopts "rvwf:" opt $*; do
660 w) WRITECONF=writeconf;;
665 shift $((OPTIND - 1))
668 # print the durations of each test if "true"
669 DDETAILS=${DDETAILS:-false}
670 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
675 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
677 # Constants used in more than one test script
678 export LOV_MAX_STRIPE_COUNT=2000
679 export LMV_MAX_STRIPES_PER_MDT=5
680 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
681 export KEEP_POOLS=${KEEP_POOLS:-false}
682 export PARALLEL=${PARALLEL:-"no"}
684 export BLCKSIZE=${BLCKSIZE:-4096}
685 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
688 # use localrecov to enable recovery for local clients, LU-12722
689 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
690 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
691 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
694 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
695 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
702 ncpts=$(do_facet $facet "lctl get_param -n " \
703 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
705 if [ $ncpts -eq 0 ]; then
712 # Return a numeric version code based on a version string. The version
713 # code is useful for comparison two version strings to see which is newer.
715 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
716 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
718 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
721 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
722 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
724 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
726 # usage: lustre_build_version
728 # All Lustre versions support "lctl get_param" to report the version of the
729 # code running in the kernel (what our tests are interested in), but it
730 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
731 # the "version" parameter doesn't include "lustre: " at the beginning.
732 # If that fails, call "lctl lustre_build_version" which prints either (or both)
733 # the userspace and kernel build versions, but until 2.8.55 required root
734 # access to get the Lustre kernel version. If that also fails, fall back to
735 # using "lctl --version", which is easy to parse and works without the kernel
736 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
737 # not the module version, though they are usually the same.
739 # Various commands and their output format for different Lustre versions:
740 # lctl get_param version: 2.9.55
741 # lctl get_param version: lustre: 2.8.53
742 # lctl get_param version: lustre: 2.6.52
743 # kernel: patchless_client
744 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
745 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
746 # lctl lustre_build_version: error: lustre_build_version: Permission denied
747 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
748 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
749 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
750 # lctl --version: lctl 2.6.50
752 # output: prints version string to stdout in (up to 4) dotted-decimal values
753 lustre_build_version() {
754 local facet=${1:-client}
755 local facet_version=${facet}_VERSION
757 # if the global variable is already set, then use that
758 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
760 # this is the currently-running version of the kernel modules
761 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
762 # we mostly test 2.10+ systems, only try others if the above fails
763 if [ -z "$ver" ]; then
764 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
766 if [ -z "$ver" ]; then
767 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
770 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
771 [ -n "$lver" ] && ver="$lver"
773 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
774 tr _ . | cut -d. -f1-4)
776 # save in global variable for the future
777 export $facet_version=$lver
782 # Report the Lustre numeric build version code for the supplied facet.
783 lustre_version_code() {
784 version_code $(lustre_build_version $1)
787 # Extract the server-side /etc/os-release information into local variables
788 # usage: lustre_os_release <facet>
789 # generates $facet_OS_ID, $facet_OS_ID_LIKE, $facet_VERSION_ID
790 # and also $facet_OS_VERSION_CODE=$(version_code $facet_VERSION_ID)
791 lustre_os_release() {
793 local facet_os=$(tr "[:lower:]" "[:upper:]" <<<$facet)_OS_
794 local facet_version=${facet_os}VERSION_
797 echo "$facet: $(do_facet $facet "cat /etc/system-release")"
798 do_facet $facet "test -r /etc/os-release" || {
799 echo "$facet: has no /etc/os-release"
800 do_facet $facet "uname -a; ls -s /etc/*release"
805 # more variables in os-release could be exported, but these
806 # are the ones that looked enough for our needs here
808 VERSION_ID=*|ID=*|ID_LIKE=*) eval export ${facet_os}$line ;;
810 done < <(do_facet $facet "cat /etc/os-release")
812 eval export ${facet_version}CODE=\$\(version_code \$${facet_version}ID\)
813 # add in the "self" ID to ID_LIKE so only one needs to be checked
814 eval export ${facet_os}ID_LIKE+=\" \$${facet_os}ID\"
815 env | grep "${facet_os}"
819 /sbin/lsmod | grep -q "^\<$1\>"
822 check_lfs_df_ret_val() {
823 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
824 # returned by 'lfs df' for valid dentry but not a lustrefs.
826 # 'lfs df' historically always returned success(0) instead of
827 # EOPNOTSUPP. This function for compatibility reason, ignores and
828 # masquerades EOPNOTSUPP as success.
829 [[ $1 -eq 95 ]] && return 0
842 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
845 # parallels can't load modules directly from prlfs, use /tmp instead
846 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
847 local target="$(mktemp)"
849 cp "$module" "$target"
852 [[ $rc == 0 ]] && PRLFS=true
860 # Load a module on the system where this is running.
862 # usage: load_module module_name [module arguments for insmod/modprobe]
864 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
865 # will be used as the arguments. Otherwise arguments will be obtained from
866 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
869 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
872 local base=$(basename $module $ext)
874 local -A module_is_loaded_aa
878 for mod in $(lsmod | awk '{ print $1; }'); do
879 module_is_loaded_aa[${mod//-/_}]=true
883 ${module_is_loaded_aa[${1//-/_}]:-false}
886 if module_is_loaded $base; then
890 if [[ -f $LUSTRE/$module$ext ]]; then
891 path=$LUSTRE/$module$ext
892 elif [[ "$base" == lnet_selftest ]] &&
893 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
894 path=$LUSTRE/../lnet/selftest/$base$ext
899 if [[ -n "$path" ]]; then
900 # Try to load any non-Lustre modules that $module depends on.
901 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
902 if ! module_is_loaded $mod; then
908 # If no module arguments were passed then get them from
909 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
910 if [ $# -eq 0 ]; then
911 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
912 # not in Bash until 4.x, so we resort to eval.
913 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
914 eval set -- \$$optvar
915 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
916 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
918 opt=$(awk -v var="^options $base" '$0 ~ var \
919 {gsub("'"options $base"'",""); print}' \
921 set -- $(echo -n $opt)
923 # Ensure we have accept=all for lnet
924 if [[ "$base" == lnet ]]; then
925 # OK, this is a bit wordy...
926 local arg accept_all_present=false
929 [[ "$arg" == accept=all ]] &&
930 accept_all_present=true
933 $accept_all_present || set -- "$@" accept=all
940 [ $# -gt 0 ] && echo "${module} options: '$*'"
942 # Note that insmod will ignore anything in modprobe.conf, which is why
943 # we're passing options on the command-line. If $path does not exist
944 # then we must be testing a "make install" or"rpm" installation. Also
945 # note that failing to load ptlrpc_gss is not considered fatal.
946 if [[ -n "$path" ]]; then
947 lustre_insmod $path "$@"
948 elif [[ "$base" == ptlrpc_gss ]]; then
949 if ! modprobe $base "$@" 2>/dev/null; then
950 echo "gss/krb5 is not supported"
958 $LCTL mark "$LNETCTL $*"
964 # For kmemleak-enabled kernels we need clear all past state
965 # that obviously has nothing to do with this Lustre run
966 # Disable automatic memory scanning to avoid perf hit.
967 if [ -f /sys/kernel/debug/kmemleak ] ; then
968 echo scan=off > /sys/kernel/debug/kmemleak || true
969 echo scan > /sys/kernel/debug/kmemleak || true
970 echo clear > /sys/kernel/debug/kmemleak || true
973 echo Loading modules from $LUSTRE
977 if [ -f /sys/devices/system/cpu/online ]; then
978 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
979 echo "detected $ncpus online CPUs by sysfs"
981 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
984 if [ $rc -eq 0 ]; then
985 echo "detected $ncpus online CPUs by getconf"
987 echo "Can't detect number of CPUs"
992 # if there is only one CPU core, libcfs can only create one partition
993 # if there is more than 4 CPU cores, libcfs should create multiple CPU
994 # partitions. So we just force libcfs to create 2 partitions for
995 # system with 2 or 4 cores
996 local saved_opts="$MODOPTS_LIBCFS"
998 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
999 # force to enable multiple CPU partitions
1000 echo "Force libcfs to create 2 CPU partitions"
1001 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
1003 echo "libcfs will create CPU partition based on online CPUs"
1006 load_module ../libcfs/libcfs/libcfs
1007 # Prevent local MODOPTS_LIBCFS being passed as part of environment
1008 # variable to remote nodes
1009 unset MODOPTS_LIBCFS
1011 set_default_debug "neterror net nettrace malloc"
1012 if [ "$1" = "config_on_load=1" ]; then
1013 load_module ../lnet/lnet/lnet
1015 load_module ../lnet/lnet/lnet "$@"
1018 LNDPATH=${LNDPATH:-"../lnet/klnds"}
1019 if [ -z "$LNETLND" ]; then
1021 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
1022 tcp*) LNETLND="socklnd/ksocklnd" ;;
1023 kfi*) LNETLND="kfilnd/kkfilnd" ;;
1024 gni*) LNETLND="gnilnd/kgnilnd" ;;
1025 *) local lnd="${NETTYPE%%[0-9]}lnd"
1026 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
1027 LNETLND="$lnd/k$lnd" ||
1028 LNETLND="socklnd/ksocklnd"
1031 load_module ../lnet/klnds/$LNETLND
1033 if [ "$1" = "config_on_load=1" ]; then
1034 do_lnetctl lnet configure --all ||
1039 load_modules_local() {
1040 if [ -n "$MODPROBE" ]; then
1042 echo "Using modprobe to load modules"
1046 # Create special udev test rules on every node
1047 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
1048 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
1050 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
1052 udevadm control --reload-rules
1057 load_module obdclass/obdclass
1058 if ! client_only; then
1059 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
1061 load_module ptlrpc/ptlrpc
1062 load_module ptlrpc/gss/ptlrpc_gss
1070 load_module obdecho/obdecho
1071 if ! client_only; then
1072 load_module lfsck/lfsck
1073 [ "$LQUOTA" != "no" ] &&
1074 load_module quota/lquota $LQUOTAOPTS
1075 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
1076 load_module osd-zfs/osd_zfs
1077 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
1078 load_module ../ldiskfs/ldiskfs
1079 load_module osd-ldiskfs/osd_ldiskfs
1084 # don't fail if ost module doesn't exist
1085 load_module ost/ost 2>/dev/null || true;
1091 load_module llite/lustre
1092 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
1094 rm -f $OGDB/ogdb-$HOSTNAME
1095 $LCTL modules > $OGDB/ogdb-$HOSTNAME
1097 # 'mount' doesn't look in $PATH, just sbin
1098 local mount_lustre=$LUSTRE/utils/mount.lustre
1099 if [ -f $mount_lustre ]; then
1100 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1101 if grep -qw "$sbin_mount" /proc/mounts; then
1102 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
1104 if ! grep -qw "$sbin_mount" /proc/mounts; then
1105 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
1106 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
1107 cat <<- EOF > "$sbin_mount"
1110 echo "This $sbin_mount just a mountpoint." 1>&2
1111 echo "It is never supposed to be run." 1>&2
1112 logger -p emerg -- "using stub $sbin_mount $@"
1115 chmod a+x $sbin_mount
1117 mount --bind $mount_lustre $sbin_mount ||
1118 error "can't bind $mount_lustre to $sbin_mount"
1129 # load modules on remote nodes optionally
1130 # lustre-tests have to be installed on these nodes
1131 if $LOAD_MODULES_REMOTE; then
1132 local list=$(comma_list $(remote_nodes_list))
1134 # include failover nodes in case they are not in the list yet
1135 facets=$(get_facets)
1136 for facet in ${facets//,/ }; do
1137 failover=$(facet_failover_host $facet)
1138 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
1139 list="$list,$failover"
1142 if [ -n "$list" ]; then
1143 echo "loading modules on: '$list'"
1144 do_rpc_nodes "$list" load_modules_local
1150 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
1151 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
1153 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
1154 echo "$LEAK_LUSTRE" 1>&2
1155 echo "$LEAK_PORTALS" 1>&2
1156 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
1157 echo "Memory leaks detected"
1158 [ -n "$IGNORE_LEAK" ] &&
1159 { echo "ignoring leaks" && return 0; } || true
1164 unload_modules_local() {
1165 $LUSTRE_RMMOD ldiskfs || return 2
1167 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
1168 rm /etc/udev/rules.d/99-lustre-test.rules
1169 udevadm control --reload-rules
1172 check_mem_leak || return 254
1180 wait_exit_ST client # bug 12845
1182 unload_modules_local || rc=$?
1184 if $LOAD_MODULES_REMOTE; then
1185 local list=$(comma_list $(remote_nodes_list))
1186 if [ -n "$list" ]; then
1187 echo "unloading modules on: '$list'"
1188 do_rpc_nodes "$list" unload_modules_local
1192 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1193 if grep -qe "$sbin_mount " /proc/mounts; then
1194 umount $sbin_mount || true
1195 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
1199 [[ $rc -eq 0 ]] && echo "modules unloaded."
1205 local facet=${1:-ost1}
1207 local mult=$OSTCOUNT
1209 case $(facet_fstype $facet) in
1210 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
1211 # grant_block_size is in bytes, allow at least 2x max blocksize
1212 zfs) size=$(lctl get_param osc.$FSNAME*.import |
1213 awk '/grant_block_size:/ {print $2/512; exit;}')
1217 [[ $facet =~ mds ]] && mult=$MDTCOUNT
1218 echo -n $((size * mult))
1222 local facet=${1:-$SINGLEMDS}
1223 local fstype=$(facet_fstype $facet)
1226 ldiskfs) size=4;; # ~4KB per inode
1227 zfs) size=11;; # 10 to 11KB per inode
1240 echo Running as $user: $cmd $opts
1243 su - $user -c "$cmd $opts"
1246 check_gss_daemon_nodes() {
1254 dname=$(basename "$dname" | awk '{print $1}')
1255 do_nodesv $list "num=0;
1256 for proc in \\\$(pgrep $dname); do
1257 [ \\\$(ps -o ppid= -p \\\$proc) -ne 1 ] || ((num++))
1259 if [ \\\"\\\$num\\\" -ne 1 ]; then
1260 echo \\\$num instance of $dname;
1264 (( $ret == 0 )) || return $ret
1266 for node in ${list//,/ }; do
1268 while (( $loop < $loopmax )); do
1269 do_nodesv $node "$L_GETAUTH -d"
1271 (( $ret == 0 )) && break
1275 (( $loop < $loopmax )) || return 1
1280 check_gss_daemon_facet() {
1284 dname=$(basename "$dname" | awk '{print $1}')
1285 num=$(do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l)
1286 if [ $num -ne 1 ]; then
1287 echo "$num instance of $dname on $facet"
1297 echo "Stopping "$@" on $list"
1298 do_nodes $list "killall -2 $* 2>/dev/null || true"
1301 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1302 start_gss_daemons() {
1307 if [ "$nodes" ] && [ "$daemon" ] ; then
1308 echo "Starting gss daemon on nodes: $nodes"
1309 do_nodes $nodes "$daemon" "$options" || return 8
1310 check_gss_daemon_nodes $nodes "$daemon" || return 9
1314 nodes=$(comma_list $(mdts_nodes))
1315 echo "Starting gss daemon on mds: $nodes"
1317 # Start all versions, in case of switching
1318 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1321 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 1
1324 nodes=$(comma_list $(osts_nodes))
1325 echo "Starting gss daemon on ost: $nodes"
1327 # Start all versions, in case of switching
1328 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1331 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 3
1333 # starting on clients
1335 local clients=${CLIENTS:-$HOSTNAME}
1338 # check daemons are running
1340 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1341 check_gss_daemon_nodes $nodes "$LSVCGSSD" || return 5
1344 stop_gss_daemons() {
1345 local nodes=$(comma_list $(mdts_nodes))
1347 send_sigint $nodes lsvcgssd lgssd
1349 nodes=$(comma_list $(osts_nodes))
1350 send_sigint $nodes lsvcgssd
1352 nodes=${CLIENTS:-$HOSTNAME}
1353 send_sigint $nodes lgssd
1357 # Add mount flags for shared key
1360 if grep -q skpath <<< "$mt_opts" ; then
1361 mt_opts=$(echo $mt_opts |
1362 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1364 if [ -z "$mt_opts" ]; then
1365 mt_opts="-o skpath=$SK_PATH"
1367 mt_opts="$mt_opts,skpath=$SK_PATH"
1377 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1386 [ $from_tree = true ]
1390 if $SHARED_KEY; then
1399 if ! module_loaded ptlrpc_gss; then
1400 load_module ptlrpc/gss/ptlrpc_gss
1401 module_loaded ptlrpc_gss ||
1402 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1405 if $GSS_KRB5 || $GSS_SK; then
1406 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1409 if $GSS_SK && ! $SK_NO_KEY; then
1410 echo "Loading basic SSK keys on all servers"
1411 do_nodes $(comma_list $(all_server_nodes)) \
1412 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1413 do_nodes $(comma_list $(all_server_nodes)) \
1414 "keyctl show | grep lustre | cut -c1-11 |
1416 xargs -IX keyctl setperm X 0x3f3f3f3f"
1419 if $GSS_SK && $SK_NO_KEY; then
1420 local numclients=${1:-$CLIENTCOUNT}
1421 local clients=${CLIENTS:-$HOSTNAME}
1423 # security ctx config for keyring
1425 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1427 if from_build_tree; then
1428 mkdir -p $SK_OM_PATH
1429 if grep -q request-key /proc/mounts > /dev/null; then
1430 echo "SSK: Request key already mounted."
1432 mount -o bind $SK_OM_PATH /etc/request-key.d/
1434 local lgssc_conf_line='create lgssc * * '
1435 lgssc_conf_line+=$(which lgss_keyring)
1436 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1437 echo "$lgssc_conf_line" > $lgssc_conf_file
1440 [ -e $lgssc_conf_file ] ||
1441 error_exit "Could not find key options in $lgssc_conf_file"
1442 echo "$lgssc_conf_file content is:"
1443 cat $lgssc_conf_file
1445 if ! local_mode; then
1446 if from_build_tree; then
1447 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1449 do_nodes $(comma_list $(all_nodes)) "mount \
1450 -o bind $SK_OM_PATH \
1451 /etc/request-key.d/"
1452 do_nodes $(comma_list $(all_nodes)) "rsync \
1453 -aqv $HOSTNAME:$lgssc_conf_file \
1454 $lgssc_conf_file >/dev/null 2>&1"
1456 do_nodes $(comma_list $(all_nodes)) \
1457 "echo $lgssc_conf_file: ; \
1458 cat $lgssc_conf_file"
1462 # create shared key on all nodes
1463 mkdir -p $SK_PATH/nodemap
1464 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1465 $SK_PATH/$FSNAME-*.key
1466 # for nodemap testing each client may need own key,
1467 # and S2S now requires keys as well, both for "client"
1470 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1471 -w $SK_PATH/$FSNAME-nmclient.key \
1472 -d /dev/urandom >/dev/null 2>&1
1473 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1474 -w $SK_PATH/$FSNAME-s2s-server.key \
1475 -d /dev/urandom >/dev/null 2>&1
1478 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1479 -d /dev/urandom >/dev/null 2>&1
1481 for i in $(seq 0 $((numclients - 1))); do
1482 $LGSS_SK -t server -f$FSNAME -n c$i \
1483 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1487 if ! local_mode; then
1488 for lnode in $(all_nodes); do
1489 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1492 # Set client keys to client type to generate prime P
1494 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1495 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1497 do_nodes $clients "$LGSS_SK -t client -m \
1498 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1499 do_nodes $clients "find $SK_PATH/nodemap \
1500 -name \*.key | xargs -IX $LGSS_SK -t client \
1501 -m X >/dev/null 2>&1"
1502 # also have a client key available on server side,
1503 # for local client mount
1504 do_nodes $(comma_list $(all_server_nodes)) \
1505 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1506 $LGSS_SK -t client -m \
1507 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1509 # This is required for servers as well, if S2S in use
1511 do_nodes $(comma_list $(mdts_nodes)) \
1512 "cp $SK_PATH/$FSNAME-s2s-server.key \
1513 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1514 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1516 do_nodes $(comma_list $(osts_nodes)) \
1517 "cp $SK_PATH/$FSNAME-s2s-server.key \
1518 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1519 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1521 do_nodes $clients "$LGSS_SK -t client \
1522 -m $SK_PATH/$FSNAME-nmclient.key \
1527 # mount options for servers and clients
1528 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1529 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1530 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1531 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1533 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1534 LGSS_KEYRING_DEBUG=4
1538 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1539 ( local_mode || from_build_tree ); then
1541 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1542 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1543 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1545 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1548 do_nodesv $(comma_list $(all_server_nodes)) \
1549 "$LCTL set_param sptlrpc.gss.rsi_upcall=$L_GETAUTH"
1555 # maybe cleanup credential cache?
1562 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1563 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1564 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1568 $RPC_MODE || echo "Cleaning up Shared Key.."
1569 do_nodes $(comma_list $(all_nodes)) "rm -f \
1570 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1571 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1572 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1573 if from_build_tree; then
1574 # Remove the mount and clean up the files we added to
1576 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1577 request-key.d /proc/mounts; do umount \
1578 /etc/request-key.d/; done"
1579 do_nodes $(comma_list $(all_nodes)) "rm -f \
1580 $SK_OM_PATH/lgssc.conf"
1581 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1589 local var=${facet}_svc
1597 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1598 tr '[:lower:]' '[:upper:]'
1604 if [ $facet == mgs ] || [ $facet == client ]; then
1608 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1616 if [ -n "${!var}" ]; then
1621 var=$(facet_type $facet)FSTYPE
1622 if [ -n "${!var}" ]; then
1627 if [ -n "$FSTYPE" ]; then
1632 if [[ $facet == mgs ]] && combined_mgs_mds; then
1644 local facets=$(get_facets)
1647 for facet in ${facets//,/ }; do
1648 if [[ $node == $(facet_host $facet) ]] ||
1649 [[ $node == "$(facet_failover_host $facet)" ]]; then
1650 fstype=$(facet_fstype $facet)
1651 if [[ $fstypes != *$fstype* ]]; then
1652 fstypes+="${fstypes:+,}$fstype"
1661 local num=$(facet_number $facet)
1664 if [[ $(facet_type $facet) = OST ]]; then
1665 index=OSTINDEX${num}
1666 if [[ -n "${!index}" ]]; then
1671 index=${OST_INDICES[num - 1]}
1674 [[ -n "$index" ]] || index=$((num - 1))
1682 local fstype=$(facet_fstype $facet)
1686 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1688 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1689 ${dev} 2>/dev/null");;
1691 error "unknown fstype!";;
1698 # Get the device of a facet.
1705 mgs) device=$(mgsdevname) ;;
1706 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1707 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1708 fs2mds) device=$(mdsdevname 1_2) ;;
1709 fs2ost) device=$(ostdevname 1_2) ;;
1710 fs3ost) device=$(ostdevname 2_2) ;;
1718 # Get the virtual device of a facet.
1725 mgs) device=$(mgsvdevname) ;;
1726 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1727 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1728 fs2mds) device=$(mdsvdevname 1_2) ;;
1729 fs2ost) device=$(ostvdevname 1_2) ;;
1730 fs3ost) device=$(ostvdevname 2_2) ;;
1738 local virt=$(virt-what 2> /dev/null)
1740 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1742 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1745 VMware|KVM|VirtualBox|Parallels|Bochs)
1746 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1751 virt=$(dmidecode -s system-manufacturer | awk '{print $1}')
1754 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1760 # Re-read the partition table on failover partner host.
1761 # After a ZFS storage pool is created on a shared device, the partition table
1762 # on the device may change. However, the operating system on the failover
1763 # host may not notice the change automatically. Without the up-to-date partition
1764 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1765 # relative to partition rather than disk beginnings.
1767 # This function performs partprobe on the failover host to make it re-read the
1770 refresh_partition_table() {
1775 host=$(facet_passive_host $facet)
1776 if [[ -n "$host" ]]; then
1777 do_node $host "$PARTPROBE $device"
1782 # Get ZFS storage pool name.
1789 device=$(facet_device $facet)
1790 # poolname is string before "/"
1791 poolname="${device%%/*}"
1798 # Get ZFS local fsname.
1800 zfs_local_fsname() {
1802 local lfsname=$(basename $(facet_device $facet))
1808 # Create ZFS storage pool.
1815 local opts=${@:-"-o cachefile=none"}
1817 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1818 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1819 $ZPOOL create -f $opts $poolname $vdev"
1823 # Create ZFS file system.
1829 local opts=${@:-"-o mountpoint=legacy"}
1831 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1832 $ZFS create $opts $dataset"
1836 # Export ZFS storage pool.
1837 # Before exporting the pool, all datasets within the pool should be unmounted.
1845 poolname=$(zpool_name $facet)
1847 if [[ -n "$poolname" ]]; then
1848 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1849 grep -q ^$poolname/ /proc/mounts ||
1850 $ZPOOL export $opts $poolname"
1855 # Destroy ZFS storage pool.
1856 # Destroy the given pool and free up any devices for other use. This command
1857 # tries to unmount any active datasets before destroying the pool.
1858 # -f Force any active datasets contained within the pool to be unmounted.
1862 local poolname=${2:-$(zpool_name $facet)}
1864 if [[ -n "$poolname" ]]; then
1865 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1866 $ZPOOL destroy -f $poolname"
1871 # Import ZFS storage pool.
1872 # Force importing, even if the pool appears to be potentially active.
1877 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1880 poolname=$(zpool_name $facet)
1882 if [[ -n "$poolname" ]]; then
1883 opts+=" -d $(dirname $(facet_vdevice $facet))"
1884 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1885 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1886 $ZPOOL import -f $opts $poolname"
1891 # Reimport ZFS storage pool with new name
1896 local opts="-o cachefile=none"
1897 local poolname=$(zpool_name $facet)
1899 opts+=" -d $(dirname $(facet_vdevice $facet))"
1900 do_facet $facet "$ZPOOL export $poolname;
1901 $ZPOOL import $opts $poolname $newpool"
1905 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1906 # is not automatically imported on system startup.
1908 # In a failover environment, this will provide resource level fencing which
1909 # will ensure that the same ZFS storage pool will not be imported concurrently
1910 # on different nodes.
1912 disable_zpool_cache() {
1916 poolname=$(zpool_name $facet)
1918 if [[ -n "$poolname" ]]; then
1919 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1924 # This and set_osd_param() shall be used to access OSD parameters
1925 # once existed under "obdfilter":
1930 # writethrough_cache_enable
1934 local device=${2:-$FSNAME-OST*}
1937 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1942 local device=${2:-$FSNAME-OST*}
1946 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1949 set_default_debug () {
1950 local debug=${1:-"$PTLDEBUG"}
1951 local subsys=${2:-"$SUBSYSTEM"}
1952 local debug_size=${3:-$DEBUG_SIZE}
1954 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1956 lctl set_param subsystem_debug="${subsys# }" >/dev/null
1957 [ -n "$debug_size" ] &&
1958 lctl set_param debug_mb="$debug_size" >/dev/null
1963 set_default_debug_nodes () {
1965 local debug="${2:-"$PTLDEBUG"}"
1966 local subsys="${3:-"$SUBSYSTEM"}"
1967 local debug_size="${4:-$DEBUG_SIZE}"
1969 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1970 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1974 [[ -z "$nodes" ]] ||
1975 do_rpc_nodes "$nodes" set_default_debug \
1976 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1979 set_default_debug_facet () {
1981 local debug="${2:-"$PTLDEBUG"}"
1982 local subsys="${3:-"$SUBSYSTEM"}"
1983 local debug_size="${4:-$DEBUG_SIZE}"
1984 local node=$(facet_active_host $facet)
1986 [ -n "$node" ] || error "No host defined for facet $facet"
1988 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1991 set_params_nodes() {
1996 [[ -n "$params" ]] || return 0
1998 do_nodes $nodes "$LCTL set_param $params"
2001 set_params_clients() {
2002 (( $# >= 2 )) || return 0
2003 local clients=${1:-$CLIENTS}
2005 local params="${@:-$CLIENT_LCTL_SETPARAM_PARAM}"
2007 set_params_nodes $clients $params
2011 (( $# >= 2 )) || return 0
2012 local mdts=${1:-$(comma_list $(mdts_nodes))}
2014 local params="${@:-$MDS_LCTL_SETPARAM_PARAM}"
2016 set_params_nodes $mdts $params
2020 (( $# >= 2 )) || return 0
2021 local osts=${1:-$(comma_list $(osts_nodes))}
2023 local params="${@:-$OSS_LCTL_SETPARAM_PARAM}"
2025 set_params_nodes $osts $params
2029 local hostid=${1:-$(hostid)}
2031 if [ ! -s /etc/hostid ]; then
2032 printf $(echo -n $hostid |
2033 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
2039 local facets=${1:-$(get_facets)}
2045 for facet in ${facets//,/ }; do
2046 mount_facet $facet &
2050 for ((index=0; index<$total; index++)); do
2051 wait ${mountpids[index]}
2053 [ $RC -eq 0 ] && continue
2055 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
2056 skip_noexit "Restart of $facet failed!." &&
2059 error "Restart of $facet failed!"
2067 # Add argument "arg" (e.g., "loop") to the comma-separated list
2068 # of arguments for option "opt" (e.g., "-o") on command
2069 # line "opts" (e.g., "-o flock").
2075 local opt_pattern="\([[:space:]]\+\|^\)$opt"
2077 if echo "$opts" | grep -q $opt_pattern; then
2078 opts=$(echo "$opts" | sed -e \
2079 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
2081 opts+="${opts:+ }$opt $arg"
2087 # Associate loop device with a given regular file.
2088 # Return the loop device.
2090 setup_loop_device() {
2094 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
2095 if [[ -z \\\$loop_dev ]]; then
2096 loop_dev=\\\$($LOSETUP -f);
2097 $LOSETUP \\\$loop_dev $file || loop_dev=;
2099 echo -n \\\$loop_dev"
2103 # Detach a loop device.
2105 cleanup_loop_device() {
2109 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
2110 $LOSETUP -d $loop_dev"
2114 # Check if a given device is a block device.
2121 [[ -n "$dev" ]] || return 1
2122 do_facet $facet "test -b $dev" || return 1
2123 if [[ -n "$size" ]]; then
2124 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
2125 count=1 skip=$size 2>&1" |
2126 awk '($3 == "in") { print $1 }')
2127 [[ "$in" = "1+0" ]] || return 1
2132 # Check if a given device is a device-mapper device.
2138 [[ -n "$dev" ]] || return 1
2139 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
2143 # Check if a given device is a device-mapper flakey device.
2145 is_dm_flakey_dev() {
2150 [[ -n "$dev" ]] || return 1
2152 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
2154 [[ $type = flakey ]] && return 0 || return 1
2158 # Check if device-mapper flakey device is supported by the kernel
2159 # of $facet node or not.
2161 dm_flakey_supported() {
2165 do_facet $facet "modprobe dm-flakey;
2166 $DMSETUP targets | grep -q flakey" &> /dev/null
2170 # Get the device-mapper flakey device name of a given facet.
2172 dm_facet_devname() {
2174 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2176 echo -n ${facet}_flakey
2180 # Get the device-mapper flakey device of a given facet.
2181 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
2183 dm_facet_devpath() {
2186 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
2190 # Set a device-mapper device with a new table.
2192 # The table has the following format:
2193 # <logical_start_sector> <num_sectors> <target_type> <target_args>
2195 # flakey <target_args> includes:
2196 # <destination_device> <offset> <up_interval> <down_interval> \
2197 # [<num_features> [<feature_arguments>]]
2199 # linear <target_args> includes:
2200 # <destination_device> <start_sector>
2202 dm_set_dev_table() {
2205 local target_type=$3
2211 read tmp num_sectors tmp real_dev tmp \
2212 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
2214 case $target_type in
2216 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
2219 table="0 $num_sectors linear $real_dev 0"
2221 *) error "invalid target type $target_type" ;;
2224 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
2225 error "failed to suspend $dm_dev"
2226 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
2227 error "failed to load $target_type table into $dm_dev"
2228 do_facet $facet "$DMSETUP resume $dm_dev" ||
2229 error "failed to resume $dm_dev"
2233 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
2234 # feature parameter.
2237 # All write I/O is silently ignored.
2238 # Read I/O is handled correctly.
2240 dm_set_dev_readonly() {
2242 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2244 dm_set_dev_table $facet $dm_dev flakey
2248 # Set a device-mapper device to traditional linear mapping mode.
2250 dm_clear_dev_readonly() {
2252 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2254 dm_set_dev_table $facet $dm_dev linear
2258 # Set the device of a given facet as "read-only".
2260 set_dev_readonly() {
2262 local svc=${facet}_svc
2264 if [[ $(facet_fstype $facet) = zfs ]] ||
2265 ! dm_flakey_supported $facet; then
2266 do_facet $facet $LCTL --device ${!svc} readonly
2268 dm_set_dev_readonly $facet
2273 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
2280 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
2281 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
2282 echo -n $num_sectors
2286 # Create a device-mapper device with a given block device or regular file (will
2287 # be associated with loop device).
2288 # Return the full path of the device-mapper device.
2292 local real_dev=$2 # destination device
2293 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
2294 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
2296 # check if the device-mapper device to be created already exists
2297 if is_dm_dev $facet $dm_dev; then
2298 # if the existing device was set to "read-only", then clear it
2299 ! is_dm_flakey_dev $facet $dm_dev ||
2300 dm_clear_dev_readonly $facet $dm_dev
2306 # check if the destination device is a block device, and if not,
2307 # associate it with a loop device
2308 is_blkdev $facet $real_dev ||
2309 real_dev=$(setup_loop_device $facet $real_dev)
2310 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
2312 # now create the device-mapper device
2313 local num_sectors=$(get_num_sectors $facet $real_dev)
2314 local table="0 $num_sectors linear $real_dev 0"
2317 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
2318 { rc=${PIPESTATUS[0]}; dm_dev=; }
2319 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2326 # Map the facet name to its device variable name.
2328 facet_device_alias() {
2330 local dev_alias=$facet
2333 fs2mds) dev_alias=mds1_2 ;;
2334 fs2ost) dev_alias=ost1_2 ;;
2335 fs3ost) dev_alias=ost2_2 ;;
2343 # Save the original value of the facet device and export the new value.
2349 local active_facet=$(facet_active $facet)
2350 local dev_alias=$(facet_device_alias $active_facet)
2351 local dev_name=${dev_alias}_dev
2352 local dev=${!dev_name}
2354 if [[ $active_facet = $facet ]]; then
2355 local failover_dev=${dev_alias}failover_dev
2356 if [[ ${!failover_dev} = $dev ]]; then
2357 eval export ${failover_dev}_saved=$dev
2358 eval export ${failover_dev}=$dm_dev
2361 dev_alias=$(facet_device_alias $facet)
2362 local facet_dev=${dev_alias}_dev
2363 if [[ ${!facet_dev} = $dev ]]; then
2364 eval export ${facet_dev}_saved=$dev
2365 eval export ${facet_dev}=$dm_dev
2369 eval export ${dev_name}_saved=$dev
2370 eval export ${dev_name}=$dm_dev
2374 # Restore the saved value of the facet device.
2379 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2380 local dev_alias=$(facet_device_alias $facet)
2382 local saved_dev=${dev_alias}_dev_saved
2383 [[ -z ${!saved_dev} ]] ||
2384 eval export ${dev_alias}_dev=${!saved_dev}
2386 saved_dev=${dev_alias}failover_dev_saved
2387 [[ -z ${!saved_dev} ]] ||
2388 eval export ${dev_alias}failover_dev=${!saved_dev}
2392 # Remove a device-mapper device.
2393 # If the destination device is a loop device, then also detach it.
2397 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2401 is_dm_dev $facet $dm_dev || return 0
2403 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2404 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2406 do_facet $facet "$DMSETUP remove $dm_dev"
2407 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2409 unexport_dm_dev $facet
2411 # detach a loop device
2412 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2414 # unload dm-flakey module
2415 do_facet $facet "modprobe -r dm-flakey" || true
2421 local active_facet=$(facet_active $facet)
2422 local dev_alias=$(facet_device_alias $active_facet)
2423 local dev=${dev_alias}_dev
2424 local opt=${facet}_opt
2425 local mntpt=$(facet_mntpt $facet)
2426 local opts="${!opt} $@"
2427 local fstype=$(facet_fstype $facet)
2429 local dm_dev=${!dev}
2431 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2432 dev=mds1failover_dev
2434 module_loaded lustre || load_modules
2438 if dm_flakey_supported $facet; then
2439 dm_dev=$(dm_create_dev $facet ${!dev})
2440 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2443 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2445 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2447 # import ZFS storage pool
2448 import_zpool $facet || return ${PIPESTATUS[0]}
2450 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2451 lustre:svname $dm_dev");;
2453 error "unknown fstype!";;
2456 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2457 # for testing LU-482 error handling in mount_facets() and test_0a()
2458 if [ -f $TMP/test-lu482-trigger ]; then
2461 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2462 (( $seq_width >= 16384 )) || seq_width=16384
2464 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2466 if [[ ${facet} =~ ost ]]; then
2467 do_facet ${facet} "$LCTL set_param \
2468 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2472 if [ $RC -ne 0 ]; then
2473 echo "Start of $dm_dev on ${facet} failed ${RC}"
2477 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2478 if [[ "$health" != "healthy" ]]; then
2479 error "$facet is in a unhealthy state"
2482 set_default_debug_facet $facet
2484 if [[ $opts =~ .*nosvc.* ]]; then
2485 echo "Start $dm_dev without service"
2490 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2491 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2492 "" || error "$dm_dev failed to initialize!";;
2494 wait_update_facet ${facet} "$ZFS get -H -o value \
2495 lustre:svname $dm_dev 2>/dev/null | \
2496 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2497 error "$dm_dev failed to initialize!";;
2500 error "unknown fstype!";;
2504 # commit the device label change to disk
2505 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2506 echo "Commit the device label on ${!dev}"
2507 do_facet $facet "sync; sleep 1; sync"
2511 label=$(devicelabel ${facet} $dm_dev)
2512 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2513 eval export ${facet}_svc=${label}
2514 echo Started ${label}
2516 export_dm_dev $facet $dm_dev
2521 # start facet device options
2527 local dev_alias=$(facet_device_alias $facet)
2529 eval export ${dev_alias}_dev=${device}
2530 eval export ${facet}_opt=\"$*\"
2532 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2533 eval export mgs_dev=${device}
2535 local varname=${dev_alias}failover_dev
2536 if [ -n "${!varname}" ] ; then
2537 eval export ${dev_alias}failover_dev=${!varname}
2539 eval export ${dev_alias}failover_dev=$device
2540 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2541 eval export mgsfailover_dev=${device}
2545 local mntpt=$(facet_mntpt $facet)
2546 do_facet ${facet} mkdir -p $mntpt
2547 eval export ${facet}_MOUNT=$mntpt
2548 mount_facet ${facet}
2558 local HOST=$(facet_active_host $facet)
2559 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2561 local mntpt=$(facet_mntpt $facet)
2562 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2563 if [ ${running} -ne 0 ]; then
2564 echo "Stopping $mntpt (opts:$*) on $HOST"
2565 do_facet ${facet} $UMOUNT "$@" $mntpt
2568 # umount should block, but we should wait for unrelated obd's
2569 # like the MGS or MGC to also stop.
2570 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2572 if [[ $(facet_fstype $facet) == zfs ]]; then
2573 # export ZFS storage pool
2574 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2575 elif dm_flakey_supported $facet; then
2576 local host=${facet}_HOST
2577 local failover_host=${facet}failover_HOST
2578 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2579 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2580 dm_cleanup_dev $facet
2585 # get mdt quota type
2587 local varsvc=${SINGLEMDS}_svc
2588 do_facet $SINGLEMDS $LCTL get_param -n \
2589 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2592 # get ost quota type
2594 # All OSTs should have same quota type
2595 local varsvc=ost1_svc
2596 do_facet ost1 $LCTL get_param -n \
2597 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2600 # restore old quota type settings
2602 for usr in $QUOTA_USERS; do
2603 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2605 cmd="$LFS setquota -$type $usr -b 0"
2606 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2608 eval $cmd || error "$cmd FAILED!"
2610 # display the quota status
2611 echo "Quota settings for $usr : "
2612 $LFS quota -v -u $usr $MOUNT || true
2614 if [ "$old_MDT_QUOTA_TYPE" ]; then
2615 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2616 do_facet mgs $PERM_CMD \
2617 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2620 do_facet mgs $PERM_CMD \
2621 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2624 if [ "$old_OST_QUOTA_TYPE" ]; then
2625 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2626 do_facet mgs $PERM_CMD \
2627 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2630 do_facet mgs $LCTL conf_param \
2631 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2636 # Handle the case when there is a space in the lfs df
2637 # "filesystem summary" line the same as when there is no space.
2638 # This will allow fixing the "lfs df" summary line in the future.
2640 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2641 check_lfs_df_ret_val ${PIPESTATUS[0]}
2644 # Get free inodes on the MDT specified by mdt index, free indoes on
2645 # the whole filesystem will be returned when index == -1.
2651 if [ $index -eq -1 ]; then
2654 mdt_uuid=$(mdtuuid_from_index $index)
2657 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2662 # Get the OST device status from 'lfs df' with a given OST index.
2666 local mnt_pnt=${2:-$MOUNT}
2670 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2671 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2677 # save old quota type & set new quota type
2678 local mdt_qtype=$(mdt_quota_type)
2679 local ost_qtype=$(ost_quota_type)
2681 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2682 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2684 export old_MDT_QUOTA_TYPE=$mdt_qtype
2685 export old_OST_QUOTA_TYPE=$ost_qtype
2687 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2688 do_facet mgs $PERM_CMD \
2689 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2690 do_facet mgs $PERM_CMD \
2691 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2693 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2694 error "set mdt quota type failed"
2695 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2696 error "set ost quota type failed"
2699 local quota_usrs=$QUOTA_USERS
2701 # get_filesystem_size
2702 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2703 local blk_soft=$((disksz + 1024))
2704 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2706 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2707 local i_soft=$inodes
2708 local i_hard=$((i_soft + i_soft / 20))
2710 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2711 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2712 "inode-hardlimit: $i_hard"
2715 for usr in $quota_usrs; do
2716 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2718 cmd="$LFS setquota -$type $usr -b $blk_soft"
2719 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2721 eval $cmd || error "$cmd FAILED!"
2723 # display the quota status
2724 echo "Quota settings for $usr : "
2725 $LFS quota -v -u $usr $mntpt || true
2732 local opts=${3:-$MOUNT_OPTS}
2733 opts=${opts:+-o $opts}
2734 local flags=${4:-$MOUNT_FLAGS}
2736 local device=$MGSNID:/$FSNAME$FILESET
2737 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2738 echo "Bad mount command: opt=$flags $opts dev=$device " \
2744 # update mount option with skpath
2745 opts=$(add_sk_mntflag $opts)
2748 echo "Starting client: $client: $flags $opts $device $mnt"
2749 do_node $client mkdir -p $mnt
2750 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2751 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2753 #disable FILESET if not supported
2754 do_nodes $client lctl get_param -n \
2755 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2756 device=$MGSNID:/$FSNAME
2757 do_node $client mkdir -p $mnt/$FILESET
2758 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2761 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2762 # Mount using nodemap key
2763 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2764 if $SK_UNIQUE_NM; then
2765 mountkey=$SK_PATH/nodemap/c0.key
2767 local prunedopts=$(echo $opts |
2768 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2769 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2772 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2776 set_default_debug_nodes $client
2777 set_params_clients $client
2788 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2790 [ "$3" ] && force=-f
2791 [ $running -eq 0 ] && return 0
2793 echo "Stopping client $client $mnt (opts:$force)"
2794 do_node $client lsof -t $mnt || need_kill=no
2795 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2796 pids=$(do_node $client lsof -t $mnt | sort -u);
2797 if [ -n "$pids" ]; then
2798 do_node $client kill -9 $pids || true
2802 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2804 if [ $busy -ne 0 ] ; then
2805 echo "$mnt is still busy, wait one second" && sleep 1
2806 do_node $client umount $force $mnt
2810 # Mount the file system on the MDS
2811 mount_mds_client() {
2812 local host=$(facet_active_host $SINGLEMDS)
2814 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2815 error "unable to mount $MOUNT2 on $host"
2818 # Unmount the file system on the MDS
2819 umount_mds_client() {
2820 local host=$(facet_active_host $SINGLEMDS)
2821 zconf_umount $host $MOUNT2
2822 do_facet $SINGLEMDS "rmdir $MOUNT2"
2825 # nodes is comma list
2826 sanity_mount_check_nodes () {
2832 # FIXME: assume that all cluster nodes run the same os
2833 [ "$(uname)" = Linux ] || return 0
2836 for mnt in $mnts ; do
2837 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2838 mpts=\\\$(mount | grep -c $mnt' ');
2839 if [ \\\$running -ne \\\$mpts ]; then
2840 echo \\\$(hostname) env are INSANE!;
2843 [ $? -eq 0 ] || rc=1
2848 sanity_mount_check_servers () {
2849 [ -n "$CLIENTONLY" ] &&
2850 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2851 echo Checking servers environments
2853 # FIXME: modify get_facets to display all facets wo params
2854 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2858 for facet in ${facets//,/ }; do
2859 node=$(facet_host ${facet})
2860 mntpt=$(facet_mntpt $facet)
2861 sanity_mount_check_nodes $node $mntpt ||
2862 { error "server $node environments are insane!"; return 1; }
2866 sanity_mount_check_clients () {
2867 local clients=${1:-$CLIENTS}
2868 local mntpt=${2:-$MOUNT}
2869 local mntpt2=${3:-$MOUNT2}
2871 [ -z $clients ] && clients=$(hostname)
2872 echo Checking clients $clients environments
2874 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2875 error "clients environments are insane!"
2878 sanity_mount_check () {
2879 sanity_mount_check_servers || return 1
2880 sanity_mount_check_clients || return 2
2883 # mount clients if not mouted
2884 zconf_mount_clients() {
2887 local opts=${3:-$MOUNT_OPTS}
2888 opts=${opts:+-o $opts}
2889 local flags=${4:-$MOUNT_FLAGS}
2890 local device=$MGSNID:/$FSNAME$FILESET
2891 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2892 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2897 echo "Starting client $clients: $flags $opts $device $mnt"
2898 do_nodes $clients mkdir -p $mnt
2899 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2900 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2901 # Mount with own nodemap key
2903 # Mount all server nodes first with per-NM keys
2904 for nmclient in ${clients//,/ }; do
2905 do_nodes $(comma_list $(all_server_nodes)) \
2906 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
2909 # set perms for per-nodemap keys else permission denied
2910 do_nodes $(comma_list $(all_nodes)) \
2911 "keyctl show | grep lustre | cut -c1-11 |
2913 xargs -IX keyctl setperm X 0x3f3f3f3f"
2914 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2916 for nmclient in ${clients//,/ }; do
2917 if $SK_UNIQUE_NM; then
2918 mountkey=$SK_PATH/nodemap/c$i.key
2920 do_node $nmclient "! grep -q $mnt' ' \
2921 /proc/mounts || umount $mnt"
2922 local prunedopts=$(add_sk_mntflag $opts);
2923 prunedopts=$(echo $prunedopts | sed -e \
2924 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2926 do_nodes $(comma_list $(all_server_nodes)) \
2929 do_node $nmclient $MOUNT_CMD $flags \
2930 $prunedopts $MGSNID:/$FSNAME $mnt ||
2935 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2937 do_nodes $clients $MOUNT_CMD $flags $opts \
2938 $MGSNID:/$FSNAME $mnt || return 1
2940 #disable FILESET if not supported
2941 do_nodes $clients lctl get_param -n \
2942 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2943 device=$MGSNID:/$FSNAME
2944 do_nodes $clients mkdir -p $mnt/$FILESET
2945 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2949 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2950 # Mount with nodemap key
2952 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2953 for nmclient in ${clients//,/ }; do
2954 if $SK_UNIQUE_NM; then
2955 mountkey=$SK_PATH/nodemap/c$i.key
2957 local prunedopts=$(echo $opts | sed -e \
2958 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2959 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2962 running=\\\$(mount | grep -c $mnt' ');
2964 if [ \\\$running -eq 0 ] ; then
2966 $MOUNT_CMD $flags $prunedopts $device $mnt;
2969 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2970 grep 'type lustre' | wc -l);
2971 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2972 echo zconf_mount_clients FAILED: \
2973 mount count \\\$running, not matching \
2974 with mount count of 'type lustre' \
2975 \\\$lustre_mnt_count;
2979 exit \\\$rc" || return ${PIPESTATUS[0]}
2986 if $SHARED_KEY; then
2987 tmpopts=$(add_sk_mntflag $opts)
2990 running=\\\$(mount | grep -c $mnt' ');
2992 if [ \\\$running -eq 0 ] ; then
2994 $MOUNT_CMD $flags $tmpopts $device $mnt;
2997 exit \\\$rc" || return ${PIPESTATUS[0]}
3000 echo "Started clients $clients: "
3001 do_nodes $clients "mount | grep $mnt' '"
3003 set_default_debug_nodes $clients
3004 set_params_clients $clients
3009 zconf_umount_clients() {
3014 [ "$3" ] && force=-f
3016 echo "Stopping clients: $clients $mnt (opts:$force)"
3017 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
3018 if [ \\\$running -ne 0 ] ; then
3019 echo Stopping client \\\$(hostname) $mnt opts:$force;
3020 lsof $mnt || need_kill=no;
3021 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
3022 pids=\\\$(lsof -t $mnt | sort -u);
3023 if [ -n \\\"\\\$pids\\\" ]; then
3027 while umount $force $mnt 2>&1 | grep -q "busy"; do
3028 echo "$mnt is still busy, wait one second" && sleep 1;
3036 echo + $POWER_DOWN $node
3040 shutdown_node_hard () {
3042 local attempts=$SHUTDOWN_ATTEMPTS
3044 for i in $(seq $attempts) ; do
3047 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
3049 echo "waiting for $host to fail attempts=$attempts"
3050 [ $i -lt $attempts ] ||
3051 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
3057 local mnt=${2:-$MOUNT}
3060 if [ "$FAILURE_MODE" = HARD ]; then
3061 shutdown_node_hard $client
3063 zconf_umount_clients $client $mnt -f
3070 local facets="$(get_facets OST),$(get_facets MDS)"
3072 combined_mgs_mds || facets="$facets,mgs"
3074 for facet in ${facets//,/ }; do
3075 if [ $(facet_active_host $facet) == $host ]; then
3076 affected="$affected $facet"
3080 echo $(comma_list $affected)
3085 local host=${2:-$(facet_host $facet)}
3087 local label=$(convert_facet2label $facet)
3088 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
3091 facets_up_on_host () {
3094 local facets=$(facets_on_host $host)
3096 for facet in ${facets//,/ }; do
3097 if $(facet_up $facet $host); then
3098 affected_up="$affected_up $facet"
3102 echo $(comma_list $affected_up)
3107 local affected_facet
3108 local affected_facets
3110 if [[ "$FAILURE_MODE" = HARD ]]; then
3111 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
3112 dm_flakey_supported $facet; then
3113 affected_facets=$(affected_facets $facet)
3114 for affected_facet in ${affected_facets//,/ }; do
3115 unexport_dm_dev $affected_facet
3119 shutdown_node_hard $(facet_active_host $facet)
3128 echo + $POWER_UP $node
3141 local node=$(facet_active_host $facet)
3142 local sleep_time=${2:-10}
3144 if [ "$FAILURE_MODE" = HARD ]; then
3154 if [ "$FAILURE_MODE" = HARD ]; then
3157 if $LOAD_MODULES_REMOTE; then
3158 echo "loading modules on $node: $facet"
3159 do_rpc_nodes $node load_modules_local
3168 for facet in ${facets//,/ }; do
3169 hosts=$(expand_list $hosts $(facet_host $facet) )
3175 _check_progs_installed () {
3179 for prog in $progs; do
3180 if ! [ "$(which $prog)" -o "${!prog}" ]; then
3181 echo $prog missing on $(hostname)
3188 check_progs_installed () {
3192 do_rpc_nodes "$nodes" _check_progs_installed "$@"
3195 # recovery-scale functions
3197 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
3200 start_client_load() {
3203 local var=$(node_var_name $client)_load
3204 eval export ${var}=$load
3206 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
3207 BREAK_ON_ERROR=$BREAK_ON_ERROR \
3208 END_RUN_FILE=$END_RUN_FILE \
3209 LOAD_PID_FILE=$LOAD_PID_FILE \
3210 TESTLOG_PREFIX=$TESTLOG_PREFIX \
3211 TESTNAME=$TESTNAME \
3212 DBENCH_LIB=$DBENCH_LIB \
3213 DBENCH_SRC=$DBENCH_SRC \
3214 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
3219 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
3220 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
3221 num_clients=$(get_node_count ${CLIENTS//,/ }) \
3222 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
3223 ior_blockSize=$ior_blockSize \
3224 ior_blockUnit=$ior_blockUnit \
3225 ior_xferSize=$ior_xferSize ior_type=$ior_type \
3226 ior_DURATION=$ior_DURATION \
3227 ior_stripe_params=\\\"$ior_stripe_params\\\" \
3228 ior_custom_params=\\\"$ior_custom_param\\\" \
3229 mpi_ior_custom_threads=$mpi_ior_custom_threads \
3232 log "Started client load: ${load} on $client"
3234 # get the children process IDs
3235 local pids=$(ps --ppid $ppid -o pid= | xargs)
3236 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
3240 start_client_loads () {
3241 local -a clients=(${1//,/ })
3242 local numloads=${#CLIENT_LOADS[@]}
3244 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
3245 local load=$((nodenum % numloads))
3246 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
3248 # bug 22169: wait the background threads to start
3252 # only for remote client
3253 check_client_load () {
3255 local var=$(node_var_name $client)_load
3256 local testload=run_${!var}.sh
3258 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
3260 # bug 18914: try to connect several times not only when
3261 # check ps, but while check_node_health also
3265 while [ $RC = 254 -a $tries -gt 0 ]; do
3269 if ! check_node_health $client; then
3271 if [ $RC -eq 254 ]; then
3272 # FIXME: not sure how long we shuold sleep here
3276 echo "check node health failed: RC=$RC "
3280 # We can continue try to connect if RC=254
3281 # Just print the warning about this
3282 if [ $RC = 254 ]; then
3283 echo "got a return status of $RC from do_node while checking " \
3284 "node health on $client"
3287 # see if the load is still on the client
3290 while [ $RC = 254 -a $tries -gt 0 ]; do
3294 if ! do_node $client \
3295 "ps auxwww | grep -v grep | grep -q $testload"; then
3300 if [ $RC = 254 ]; then
3301 echo "got a return status of $RC from do_node while checking " \
3302 "(node health and 'ps') the client load on $client"
3303 # see if we can diagnose a bit why this is
3308 check_client_loads () {
3309 local clients=${1//,/ }
3313 for client in $clients; do
3314 check_client_load $client
3316 if [ "$rc" != 0 ]; then
3317 log "Client load failed on node $client, rc=$rc"
3323 restart_client_loads () {
3324 local clients=${1//,/ }
3325 local expectedfail=${2:-""}
3329 for client in $clients; do
3330 check_client_load $client
3332 if [ "$rc" != 0 -a "$expectedfail" ]; then
3333 local var=$(node_var_name $client)_load
3335 start_client_load $client ${!var}
3336 echo "Restarted client load ${!var}: on $client. Checking ..."
3337 check_client_load $client
3339 if [ "$rc" != 0 ]; then
3340 log "Client load failed to restart on node $client, rc=$rc"
3341 # failure one client load means test fail
3342 # we do not need to check other
3351 # Start vmstat and save its process ID in a file.
3356 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3359 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3360 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3363 # Display the nodes on which client loads failed.
3364 print_end_run_file() {
3368 [ -s $file ] || return 0
3370 echo "Found the END_RUN_FILE file: $file"
3373 # A client load will stop if it finds the END_RUN_FILE file.
3374 # That does not mean the client load actually failed though.
3375 # The first node in END_RUN_FILE is the one we are interested in.
3378 if [ -n "$node" ]; then
3379 local var=$(node_var_name $node)_load
3381 local prefix=$TESTLOG_PREFIX
3382 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3383 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3384 local debug_log=$(echo $stdout_log |
3385 sed 's/\(.*\)stdout/\1debug/')
3387 echo "Client load ${!var} failed on node $node:"
3393 # Stop the process which had its PID saved in a file.
3398 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3400 do_nodes $nodes "test -f $pid_file &&
3401 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3404 # Stop all client loads.
3405 stop_client_loads() {
3406 local nodes=${1:-$CLIENTS}
3409 # stop the client loads
3410 stop_process $nodes $pid_file
3412 # clean up the processes that started them
3413 [ -n "$CLIENT_LOAD_PIDS" ] &&
3414 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3416 # End recovery-scale functions
3419 # wait for a command to return the expected result
3421 # This will run @check on @node repeatedly until the output matches @expect
3422 # based on the supplied condition, or until @max_wait seconds have elapsed,
3423 # whichever comes first. @cond may be one of the normal bash operators,
3424 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3425 # in the caller to avoid unintentional evaluation by the shell in the caller.
3427 # If @max_wait is not specified, the condition will be checked for up to 90s.
3429 # If --verbose is passed as the first argument, the result is printed on each
3430 # value change, otherwise it is only printed after every 10s interval.
3432 # If --quiet is passed as the first/second argument, the do_node() command
3433 # will not print the remote command before executing it each time.
3435 # Using wait_update_cond() or related helper function is preferable to adding
3436 # a "long enough" wait for some state to change in the background, since
3437 # "long enough" may be too short due to tunables, system config, or running in
3438 # a VM, and must by necessity wait too long for most cases or risk failure.
3440 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3441 wait_update_cond() {
3445 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3446 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3452 local max_wait=${5:-90}
3456 local begin=$SECONDS
3460 while (( $waited <= $max_wait )); do
3461 result=$(do_node $quiet $node "$check")
3463 eval [[ "'$result'" $cond "'$expect'" ]]
3464 if [[ $? == 0 ]]; then
3465 [[ -n "$quiet" ]] && return 0
3466 [[ -z "$result" || $waited -le $sleep ]] ||
3467 echo "Updated after ${waited}s: want '$expect' got '$result'"
3470 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3471 [[ -z "$quiet" && -n "$prev_result" ]] &&
3472 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3473 prev_result="$result"
3475 (( $waited % $print == 0 )) && {
3476 [[ -z "$quiet" ]] &&
3477 echo "Waiting $((max_wait - waited))s for '$expect'"
3481 waited=$((SECONDS - begin))
3484 [[ -z "$quiet" ]] &&
3485 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3490 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3495 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3496 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3503 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3506 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3507 wait_update_facet_cond() {
3511 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3512 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3514 local node=$(facet_active_host $1)
3520 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3523 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3524 wait_update_facet() {
3528 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3529 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3531 local node=$(facet_active_host $1)
3536 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3540 do_nodes $(comma_list $(mdts_nodes)) \
3541 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3542 do_nodes $(comma_list $(osts_nodes)) \
3543 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3544 grep -v 'Found no match'
3548 local zfs_wait=${2:-5}
3550 # the occupied disk space will be released
3551 # only after TXGs are committed
3552 if [[ $(facet_fstype $1) == zfs ]]; then
3553 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3561 local lwm=$3 #low watermark
3562 local size_mb #how many MB should we write to pass watermark
3563 local ost_name=$(ostname_from_index $ost_idx)
3565 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3567 if (( $free_kb / 1024 > lwm )); then
3568 size_mb=$((free_kb / 1024 - lwm))
3570 #If 10% of free space cross low watermark use it
3571 if (( $free_kb / 10240 > size_mb )); then
3572 size_mb=$((free_kb / 10240))
3574 #At least we need to store 1.1 of difference between
3575 #free space and low watermark
3576 size_mb=$((size_mb + size_mb / 10))
3578 if (( lwm <= $free_kb / 1024 )) ||
3579 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3580 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3581 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3582 count=$size_mb oflag=append conv=notrunc
3587 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3588 echo "OST still has $((free_kb / 1024)) MB free"
3591 # This checks only the primary MDS
3592 ost_watermarks_get() {
3594 local ost_name=$(ostname_from_index $ost_idx)
3595 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3597 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3598 osp.$mdtosc_proc.reserved_mb_high)
3599 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3600 osp.$mdtosc_proc.reserved_mb_low)
3605 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3606 ost_watermarks_set() {
3610 local ost_name=$(ostname_from_index $ost_idx)
3611 local facets=$(get_facets MDS)
3613 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3614 osp.*$ost_name*.reserved_mb_low=$lwm \
3615 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3617 # sleep to ensure we see the change
3621 ost_watermarks_set_low_space() {
3623 local wms=$(ost_watermarks_get $ost_idx)
3624 local ost_name=$(ostname_from_index $ost_idx)
3626 local old_lwm=$(echo $wms | awk '{ print $1 }')
3627 local old_hwm=$(echo $wms | awk '{ print $2 }')
3629 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3630 # minimal extension size is 64M
3632 if (( $blocks / 1024 > 50 )); then
3633 new_lwm=$((blocks / 1024 - 50))
3635 local new_hwm=$((new_lwm + 5))
3637 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3638 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3641 # Set watermarks to ~current available space & then write data to fill it
3642 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3643 # internal statfs used by the stripe allocator
3645 # first parameter is the filename-prefix, which must get under t-f cleanup
3646 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3647 ost_watermarks_set_enospc() {
3651 local ost_name=$(ostname_from_index $ost_idx)
3652 local facets=$(get_facets MDS)
3656 for MDS in ${facets//,/ }; do
3657 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3659 do_facet $MDS $LCTL get_param -n \
3660 osp.$mdtosc_proc.reserved_mb_high ||
3661 skip "remote MDS does not support reserved_mb_high"
3664 wms=$(ost_watermarks_set_low_space $ost_idx)
3665 local new_lwm=$(echo $wms | awk '{ print $4 }')
3666 fill_ost $filename $ost_idx $new_lwm
3667 #First enospc could execute orphan deletion so repeat
3668 fill_ost $filename $ost_idx $new_lwm
3672 ost_watermarks_enospc_delete_files() {
3676 rm -f $DIR/${filename}.fill_ost$ost_idx
3678 wait_delete_completed
3682 # clean up from "ost_watermarks_set_enospc"
3683 ost_watermarks_clear_enospc() {
3689 ost_watermarks_enospc_delete_files $filename $ost_idx
3690 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3691 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3694 wait_delete_completed_mds() {
3695 local max_wait=${1:-20}
3697 local stime=$(date +%s)
3702 # find MDS with pending deletions
3703 for node in $(mdts_nodes); do
3704 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3705 2>/dev/null | calc_sum)
3706 if [[ $changes -eq 0 ]]; then
3709 mds2sync="$mds2sync $node"
3711 if [ -z "$mds2sync" ]; then
3712 wait_zfs_commit $SINGLEMDS
3715 mds2sync=$(comma_list $mds2sync)
3717 # sync MDS transactions
3718 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3720 # wait till all changes are sent and commmitted by OSTs
3721 # for ldiskfs space is released upon execution, but DMU
3722 # do this upon commit
3725 while [[ $WAIT -ne $max_wait ]]; do
3726 changes=$(do_nodes $mds2sync \
3727 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3728 #echo "$node: $changes changes on all"
3729 if [[ $changes -eq 0 ]]; then
3730 wait_zfs_commit $SINGLEMDS
3732 # the occupied disk space will be released
3733 # only after TXGs are committed
3734 wait_zfs_commit ost1
3742 echo "Delete is not completed in $((etime - stime)) seconds"
3743 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3750 # we can use "for" here because we are waiting the slowest
3751 for host in ${hostlist//,/ }; do
3752 check_network "$host" 900
3754 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3761 for facet in ${facetlist//,/ }; do
3762 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3764 wait_for_host $hostlist
3767 _wait_recovery_complete () {
3770 # Use default policy if $2 is not passed by caller.
3771 local MAX=${2:-$(max_recovery_time)}
3776 while [ $WAIT -lt $MAX ]; do
3777 STATUS=$(lctl get_param -n $param | grep status)
3779 [[ $STATUS == "status: COMPLETE" ||
3780 $STATUS == "status: INACTIVE" ]] && return 0
3783 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3785 echo "$param recovery not done in $MAX sec. $STATUS"
3789 wait_recovery_complete () {
3792 # with an assumption that at_max is the same on all nodes
3793 local MAX=${2:-$(max_recovery_time)}
3796 if [ "$FAILURE_MODE" = HARD ]; then
3797 facets=$(facets_on_host $(facet_active_host $facet))
3799 echo affected facets: $facets
3801 facets=${facets//,/ }
3802 # We can use "for" here because we are waiting the slowest.
3803 # The mgs not having the recovery_status proc entry, exclude it
3804 # from the facet list.
3805 for facet in ${facets//mgs/ }; do
3806 local var_svc=${facet}_svc
3807 local param="*.${!var_svc}.recovery_status"
3809 local host=$(facet_active_host $facet)
3810 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3814 wait_mds_ost_sync () {
3815 # just because recovery is done doesn't mean we've finished
3816 # orphan cleanup. Wait for llogs to get synchronized.
3817 echo "Waiting for orphan cleanup..."
3818 # MAX value includes time needed for MDS-OST reconnection
3819 local MAX=$(( TIMEOUT * 2 ))
3820 local WAIT_TIMEOUT=${1:-$MAX}
3823 local list=$(comma_list $(mdts_nodes))
3824 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3825 if ! do_facet $SINGLEMDS \
3826 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3828 # old way, use mds_sync
3830 list=$(comma_list $(osts_nodes))
3831 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3834 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3835 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3836 local -a sync=($(do_nodes $list "$cmd"))
3839 for ((i=0; i<${#sync[@]}; i++)); do
3841 [ ${sync[$i]} -eq 1 ] && continue
3843 [ ${sync[$i]} -eq 0 ] && continue
3845 # there is a not finished MDS-OST synchronization
3849 sleep 2 # increase waiting time and cover statfs cache
3850 [ ${con} -eq 1 ] && return 0
3851 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3855 # show which nodes are not finished.
3856 cmd=$(echo $cmd | sed 's/-n//')
3857 do_nodes $list "$cmd"
3858 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3862 # Wait OSTs to be active on both client and MDT side.
3864 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3865 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3866 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3867 error "wait_update OSTs up on client failed"
3869 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3870 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3871 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3872 error "wait_update OSTs up on MDT0000 failed"
3875 wait_destroy_complete () {
3876 echo "Waiting for MDT destroys to complete"
3877 # MAX value shouldn't be big as this mean server responsiveness
3878 # never increase this just to make test pass but investigate
3879 # why it takes so long time
3882 local list=$(comma_list $(mdts_nodes))
3883 while [ $WAIT -lt $MAX ]; do
3884 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3888 for ((i=0; i<${#RPCs[@]}; i++)); do
3889 [ ${RPCs[$i]} -eq 0 ] && continue
3890 # there are still some destroy RPCs in flight
3894 [ ${con} -eq 1 ] && return 0 # done waiting
3896 echo "Waiting ${WAIT}s for local destroys to complete"
3899 echo "MDT destroys weren't done in $MAX sec."
3903 wait_delete_completed() {
3904 wait_delete_completed_mds $1 || return $?
3905 wait_destroy_complete || return $?
3914 # conf-sanity 31 takes a long time cleanup
3915 while [ $WAIT -lt 300 ]; do
3916 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3917 lctl dl | grep ' ST ' || true")
3918 [ -z "${running}" ] && return 0
3919 echo "waited $WAIT for${running}"
3920 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3922 WAIT=$((WAIT + INTERVAL))
3924 echo "service didn't stop after $WAIT seconds. Still running:"
3929 wait_remote_prog () {
3935 [ "$PDSH" = "no_dsh" ] && return 0
3937 while [ $WAIT -lt $2 ]; do
3938 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3939 grep -v grep) || true
3940 [ -z "${running}" ] && return 0 || true
3941 echo "waited $WAIT for: "
3943 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3945 WAIT=$((WAIT + INTERVAL))
3947 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3948 grep -v grep | awk '{print $2}')
3949 [ -z "$pids" ] && return 0
3950 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3951 # FIXME: not portable
3952 for pid in $pids; do
3953 cat /proc/${pid}/status || true
3954 cat /proc/${pid}/wchan || true
3956 kill -9 $pid || true
3965 local clients=${1:-$CLIENTS}
3968 if [[ -z "$clients" ]]; then
3969 $LFS df $MOUNT > /dev/null || rc=$?
3971 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3978 local clients=${1:-$CLIENTS}
3981 _lfs_df_check "$clients" || rc=$?
3983 check_lfs_df_ret_val $rc
3987 # not every config has many clients
3993 (( MDSCOUNT == 1 )) && return
3995 # wait so that statfs data on MDT expire
3996 local delay=$(do_facet mds1 $LCTL \
3997 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3999 [ -n "$delay" ] || error "fail to get maxage"
4001 local nodes=$(comma_list $(mdts_nodes))
4002 # initiate statfs RPC, all to all MDTs
4003 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
4004 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
4008 # usually checked on particular client or locally
4018 client_reconnect_try() {
4019 local f=$MOUNT/recon
4022 if [ -z "$CLIENTS" ]; then
4023 $LFS df $MOUNT; uname -n >> $f
4025 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
4027 echo "Connected clients: $(cat $f)"
4028 ls -l $f > /dev/null
4032 client_reconnect() {
4033 # one client_reconnect_try call does not always do the job...
4035 client_reconnect_try && break
4040 affected_facets () {
4043 local host=$(facet_active_host $facet)
4044 local affected=$facet
4046 if [ "$FAILURE_MODE" = HARD ]; then
4047 affected=$(facets_up_on_host $host)
4053 local E2FSCK_ON_MDT0=false
4054 if [ "$1" == "--fsck" ]; then
4056 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4068 #Because it will only get up facets, we need get affected
4069 #facets before shutdown
4070 #For HARD Failure mode, it needs make sure facets on the same
4071 #HOST will only be shutdown and reboot once
4072 for facet in ${facets//,/ }; do
4073 local affected_facet
4075 #check whether facet has been included in other affected facets
4076 for ((index=0; index<$total; index++)); do
4077 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
4080 if [ $skip -eq 0 ]; then
4081 affecteds[$total]=$(affected_facets $facet)
4086 for ((index=0; index<$total; index++)); do
4087 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
4088 local host=$(facet_active_host $facet)
4089 echo "Failing ${affecteds[index]} on $host"
4090 shutdown_facet $facet
4093 echo "$(date +'%H:%M:%S (%s)') shut down"
4098 for facet in ${facets//,/ }; do
4099 local host=$(facet_active_host $facet)
4101 hostlist=$(expand_list $hostlist $host)
4102 if [ $(facet_host $facet) = \
4103 $(facet_failover_host $facet) ]; then
4104 waithostlist=$(expand_list $waithostlist $host)
4108 if [ "$FAILURE_MODE" = HARD ]; then
4109 for host in ${hostlist//,/ }; do
4112 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
4113 # We need to wait the rebooted hosts in case if
4114 # facet_HOST == facetfailover_HOST
4115 if ! [ -z "$waithostlist" ]; then
4116 wait_for_host $waithostlist
4117 if $LOAD_MODULES_REMOTE; then
4118 echo "loading modules on $waithostlist"
4119 do_rpc_nodes $waithostlist load_modules_local
4126 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
4127 change_active $SINGLEMDS
4130 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
4131 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
4135 for ((index=0; index<$total; index++)); do
4136 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
4137 change_active ${affecteds[index]}
4141 init_facets_vars_simple
4143 # start mgs first if it is affected
4144 if ! combined_mgs_mds &&
4145 list_member ${affecteds[index]} mgs; then
4146 mount_facet mgs || error "Restart of mgs failed"
4147 affecteds[index]=$(exclude_items_from_list \
4148 ${affecteds[index]} mgs)
4150 if [ -n "${affecteds[index]}" ]; then
4151 echo mount facets: ${affecteds[index]}
4152 mount_facets ${affecteds[index]} &
4156 for ((index=0; index<$total; index++)); do
4157 if [ -n "${affecteds[index]}" ]; then
4158 wait ${mountpids[index]}
4162 do_nodes $(comma_list $(all_nodes)) \
4163 "keyctl show | grep lustre | cut -c1-11 |
4165 xargs -IX keyctl setperm X 0x3f3f3f3f"
4168 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
4170 if [ "$FAILURE_MODE" = HARD ]; then
4171 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
4172 if ! [ -z "$hostlist" ]; then
4173 wait_for_host $hostlist
4174 if $LOAD_MODULES_REMOTE; then
4175 echo "loading modules on $hostlist"
4176 do_rpc_nodes $hostlist load_modules_local
4181 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
4186 do_facet $facet "sync; sync; sync"
4189 # make sure there will be no seq change
4190 local clients=${CLIENTS:-$HOSTNAME}
4191 local f=fsa-\\\$\(hostname\)
4192 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
4193 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
4195 local svc=${facet}_svc
4196 do_facet $facet $LCTL --device ${!svc} notransno
4198 # If a ZFS OSD is made read-only here, its pool is "freezed". This
4199 # in-memory state has to be cleared by either rebooting the host or
4200 # exporting and reimporting the pool.
4202 # Although the uberblocks are not updated when a pool is freezed,
4203 # transactions are still written to the disks. Modified blocks may be
4204 # cached in memory when tests try reading them back. The
4205 # export-and-reimport process also evicts any cached pool data from
4206 # memory to provide the correct "data loss" semantics.
4208 # In the test framework, the exporting and importing operations are
4209 # handled by stop() and mount_facet() separately, which are used
4210 # inside fail() and fail_abort().
4212 set_dev_readonly $facet
4213 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4214 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4217 replay_barrier_nodf() {
4218 local facet=$1 echo running=${running}
4219 do_facet $facet "sync; sync; sync"
4220 local svc=${facet}_svc
4221 echo Replay barrier on ${!svc}
4222 do_facet $facet $LCTL --device ${!svc} notransno
4223 set_dev_readonly $facet
4224 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4225 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4228 replay_barrier_nosync() {
4229 local facet=$1 echo running=${running}
4230 local svc=${facet}_svc
4231 echo Replay barrier on ${!svc}
4232 do_facet $facet $LCTL --device ${!svc} notransno
4233 set_dev_readonly $facet
4234 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4235 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4239 # Get Lustre client uuid for a given Lustre mount point.
4242 local mntpnt=${1:-$MOUNT}
4244 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
4245 local uuid=$($LCTL get_param -n llite.$name.uuid)
4250 mds_evict_client() {
4251 local mntpnt=${1:-$MOUNT}
4252 local uuid=$(get_client_uuid $mntpnt)
4254 do_facet $SINGLEMDS \
4255 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
4258 ost_evict_client() {
4259 local mntpnt=${1:-$MOUNT}
4260 local uuid=$(get_client_uuid $mntpnt)
4263 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
4268 local clients=${CLIENTS:-$HOSTNAME}
4270 SK_NO_KEY_save=$SK_NO_KEY
4272 export SK_NO_KEY=false
4274 facet_failover $* || error "failover: $?"
4275 export SK_NO_KEY=$SK_NO_KEY_save
4276 # to initiate all OSC idling connections
4278 wait_clients_import_ready "$clients" "$facets"
4279 clients_up || error "post-failover stat: $?"
4285 facet_failover $facet
4290 local abort_type=${2:-"abort_recovery"}
4293 change_active $facet
4294 wait_for_facet $facet
4295 mount_facet $facet -o $abort_type
4296 clients_up || echo "first stat failed: $?"
4297 clients_up || error "post-failover stat: $?"
4301 # LU-16159: abort recovery will cancel update logs, which may leave broken
4302 # directories in the system, remove name entry if necessary
4303 fail_abort_cleanup() {
4305 find $DIR/$tdir -depth | while read D; do
4306 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
4310 host_nids_address() {
4314 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
4318 if [ "$1" = "'*'" ]; then echo \'*\'; else
4324 if [[ -n "$NETTYPE" ]]; then
4325 h2name_or_ip "$1" "$NETTYPE"
4327 h2name_or_ip "$1" "$2"
4330 declare -fx h2nettype
4332 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4333 # expressions format. As a bonus we can then just pass in those variables
4334 # to pdsh. What this function does is take a HOSTLIST type string and
4335 # expand it into a space deliminated list for us.
4343 [ -z "$hostlist" ] && return
4345 # Translate the case of [..],..,[..] to [..] .. [..]
4346 list="${hostlist/],/] }"
4348 [[ "$front" == *,* ]] && {
4351 list=${list/${old}/${new}}
4354 for item in $list; do
4355 # Test if we have any []'s at all
4356 if [ "$item" != "${item/\[/}" ]; then {
4357 # Expand the [*] into list
4361 if [ "$name" != "$item" ]; then
4362 group=${item#$name[*}
4365 for range in ${group//,/ }; do
4371 # Number of leading zeros
4374 end=$(echo $end | sed 's/0*//')
4375 [[ -z "$end" ]] && end=0
4376 [[ $padlen2 -gt $padlen ]] && {
4377 [[ $padlen2 -eq ${#end} ]] &&
4381 begin=$(echo $begin | sed 's/0*//')
4382 [ -z $begin ] && begin=0
4384 if [ ! -z "${begin##[!0-9]*}" ]; then
4385 order=$(seq -f "%0${padlen}g" $begin $end)
4387 order=$(eval echo {$begin..$end});
4390 for num in $order; do
4391 value="${name#*,}${num}${back}"
4393 [ "$value" != "${value/\[/}" ] && {
4394 value=$(hostlist_expand "$value")
4396 myList="$myList $value"
4401 myList="$myList $item"
4404 myList=${myList//,/ }
4405 myList=${myList:1} # Remove first character which is a space
4407 # Filter any duplicates without sorting
4409 myList="${list%% *}"
4411 while [[ "$list" != ${myList##* } ]]; do
4412 local tlist=" $list"
4414 list=${tlist// ${list%% *} / }
4416 myList="$myList ${list%% *}"
4418 myList="${myList%* }";
4420 # We can select an object at an offset in the list
4423 for item in $myList; do
4425 [ $cnt -eq $offset ] && {
4429 [ $(get_node_count $myList) -ne 1 ] && myList=""
4438 [ "$facet" == client ] && echo -n $HOSTNAME && return
4439 varname=${facet}_HOST
4440 if [ -z "${!varname}" ]; then
4441 if [ "${facet:0:3}" == "ost" ]; then
4442 local fh=${facet%failover}_HOST
4443 eval export ${facet}_HOST=${!fh}
4444 if [ -z "${!varname}" ]; then
4445 eval export ${facet}_HOST=${ost_HOST}
4447 elif [ "${facet:0:3}" == "mdt" -o \
4448 "${facet:0:3}" == "mds" -o \
4449 "${facet:0:3}" == "mgs" ]; then
4451 if [ "${facet}" == "mgsfailover" ] &&
4452 [ -n "$mds1failover_HOST" ]; then
4453 temp=$mds1failover_HOST
4457 eval export ${facet}_HOST=$temp
4463 facet_failover_host() {
4467 var=${facet}failover_HOST
4468 if [ -n "${!var}" ]; then
4473 if combined_mgs_mds && [ $facet == "mgs" ] &&
4474 [ -n "$mds1failover_HOST" ]; then
4475 echo $mds1failover_HOST
4479 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4480 "${facet:0:3}" == "mgs" ]; then
4482 eval export ${facet}failover_host=${mds_HOST}
4487 if [[ $facet == ost* ]]; then
4488 eval export ${facet}failover_host=${ost_HOST}
4496 local activevar=${facet}active
4498 if [ -f $TMP/${facet}active ] ; then
4499 source $TMP/${facet}active
4502 active=${!activevar}
4503 if [ -z "$active" ] ; then
4510 facet_active_host() {
4511 facet_host $(facet_active $1)
4514 # Get the passive failover partner host of facet.
4515 facet_passive_host() {
4517 [[ $facet = client ]] && return
4519 local host=${facet}_HOST
4520 local failover_host=${facet}failover_HOST
4521 local active_host=$(facet_active_host $facet)
4523 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4525 if [[ $active_host = ${!host} ]]; then
4526 echo -n ${!failover_host}
4536 for facet in ${facetlist//,/ }; do
4537 local failover=${facet}failover
4538 local host=`facet_host $failover`
4540 [ -z "$host" ] && return
4542 local curactive=`facet_active $facet`
4544 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4545 eval export ${facet}active=$facet
4547 eval export ${facet}active=$failover
4549 # save the active host for this facet
4550 local activevar=${facet}active
4552 echo "$activevar=${!activevar}" > $TMP/$activevar
4553 [[ $facet = mds1 ]] && combined_mgs_mds && \
4554 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4555 local TO=`facet_active_host $facet`
4556 echo "Failover $facet to $TO"
4564 # do not strip off hostname if verbose, b=19215
4565 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4566 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4572 if [ "$HOST" = "$HOSTNAME" ]; then
4574 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4575 echo "cannot run remote command on $HOST with $myPDSH"
4578 if $VERBOSE && [[ -z "$quiet" ]]; then
4579 echo "CMD: $HOST $*" >&2
4580 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4583 if [[ "$myPDSH" == "rsh" ]] ||
4584 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4585 # we need this because rsh and pdsh do not return
4586 # exit code of an executed command
4587 local command_status="$TMP/cs"
4588 eval $myPDSH $HOST ":> $command_status"
4589 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4590 PATH=\$PATH:/sbin:/usr/sbin;
4592 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4593 echo command failed >$command_status"
4594 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4598 if [[ -n "$verbose" ]]; then
4599 # print HOSTNAME for myPDSH="no_dsh"
4600 if [[ $myPDSH = no_dsh ]]; then
4602 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4603 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4604 sed -e "s/^/${HOSTNAME}: /"
4607 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4608 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4612 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4613 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4614 sed "s/^${HOST}: //"
4616 return ${PIPESTATUS[0]}
4620 # Execute exact command line on host
4622 # The \a host may be on a local or remote node, which is determined at
4623 # the time the command is run. Does careful argument quotation to
4624 # ensure that the exact command line is executed without any globbing,
4625 # substitution, or shell interpretation on the remote side. Does not
4626 # support --verbose or --quiet. Does not include "$host: " prefixes on
4627 # output. See also do_facet_vp().
4629 # usage: do_node_vp "$host" "$command" "$arg"...
4634 if [[ "$host" == "$HOSTNAME" ]]; then
4635 bash -c "$(printf -- ' %q' "$@")"
4639 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4640 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4644 # -N Disable hostname: prefix on lines of output.
4646 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4649 single_local_node () {
4650 [ "$1" = "$HOSTNAME" ]
4653 # Outputs environment variable assignments that should be passed to remote nodes
4657 local facets=$(get_facets)
4660 for var in ${!MODOPTS_*}; do
4661 value=${!var//\"/\\\"}
4662 echo -n " ${var}=\"$value\""
4665 for facet in ${facets//,/ }; do
4667 if [ -n "${!var}" ]; then
4668 echo -n " $var=${!var}"
4672 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4673 if [ -n "${!var}" ]; then
4674 echo -n " $var=${!var}"
4678 for var in VERBOSE; do
4679 if [ -n "${!var}" ]; then
4680 echo -n " $var=${!var}"
4684 if [ -n "$FSTYPE" ]; then
4685 echo -n " FSTYPE=$FSTYPE"
4688 for var in LNETLND NETTYPE; do
4689 if [ -n "${!var}" ]; then
4690 echo -n " $var=${!var}"
4699 # do not strip off hostname if verbose, b=19215
4700 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4701 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4706 if single_local_node $rnodes; then
4707 do_node $verbose $quiet $rnodes "$@"
4711 # This is part from do_node
4714 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4715 echo "cannot run remote command on $rnodes with $myPDSH" &&
4718 export FANOUT=$(get_node_count "${rnodes//,/ }")
4719 if $VERBOSE && [[ -z "$quiet" ]]; then
4720 echo "CMD: $rnodes $*" >&2
4721 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4724 # do not replace anything from pdsh output if -N is used
4725 # -N Disable hostname: prefix on lines of output.
4726 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4727 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4729 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4731 return ${PIPESTATUS[0]}
4735 # Execute commands on a single service's host
4737 # The \a facet (service) may be on a local or remote node, which is
4738 # determined at the time the command is run.
4740 # usage: do_facet $facet command [arg ...]
4745 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4746 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4750 local host=$(facet_active_host $facet)
4752 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4753 do_node $verbose $quiet $host "$@"
4757 # Execute exact command line on the host of a facet
4759 # The \a facet (service) may be on a local or remote node, which is
4760 # determined at the time the command is run. Does careful argument
4761 # quotation to ensure that the exact command line is executed without
4762 # any globbing, substitution, or shell interpretation on the remote
4763 # side. Does not support --verbose or --quiet. Does not include
4764 # "$host: " prefixes on output.
4766 # usage: do_facet_vp "$facet" "$command" "$arg"...
4769 local host=$(facet_active_host "$facet")
4772 if [[ -z "$host" ]]; then
4773 echo "no host defined for facet ${facet}" >&2
4777 do_node_vp "$host" "$@"
4780 # Function: do_facet_random_file $FACET $FILE $SIZE
4781 # Creates FILE with random content on the given FACET of given SIZE
4783 do_facet_random_file() {
4787 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4788 do_facet $facet "$cmd 2>/dev/null"
4791 do_facet_create_file() {
4795 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4796 do_facet $facet "$cmd 2>/dev/null"
4800 do_nodes --verbose "$@"
4806 # make sure its not already running
4808 rm -f $TMP/${facet}active
4809 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4811 # make sure in-tree ldiskfs is loaded before mkfs
4812 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4813 load_module ../ldiskfs/ldiskfs
4816 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4818 if [[ $(facet_fstype $facet) == zfs ]]; then
4820 # After formatting a ZFS target, "cachefile=none" property will
4821 # be set on the ZFS storage pool so that the pool is not
4822 # automatically imported on system startup. And then the pool
4823 # will be exported so as to leave the importing and exporting
4824 # operations handled by mount_facet() and stop() separately.
4826 refresh_partition_table $facet $(facet_vdevice $facet)
4827 disable_zpool_cache $facet
4832 # Device formatted as ost
4835 local DEVNAME=OSTDEV$num
4837 local fstype=$(facet_fstype ost$num)
4841 local dev=ost${num}_dev
4842 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4843 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4844 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4846 #try $OSTZFSDEVn - independent of vdev
4847 DEVNAME=OSTZFSDEV$num
4848 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4850 error "unknown fstype!";;
4856 # Physical device location of data
4862 local fstype=$(facet_fstype ost$num)
4866 # vdevs are not supported by ldiskfs
4869 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4870 # Device formatted by zfs
4872 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4874 error "unknown fstype!";;
4880 # Logical device formatted for lustre
4883 local DEVNAME=MDSDEV$num
4885 local fstype=$(facet_fstype mds$num)
4889 local dev=mds${num}_dev
4890 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4891 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4892 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4894 # try $MDSZFSDEVn - independent of vdev
4895 DEVNAME=MDSZFSDEV$num
4896 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4898 error "unknown fstype!";;
4904 # Physical location of data
4908 local fstype=$(facet_fstype mds$num)
4912 # vdevs are not supported by ldiskfs
4915 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4916 # Device formatted by ZFS
4917 local DEVNAME=MDSDEV$num
4918 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4920 error "unknown fstype!";;
4928 local fstype=$(facet_fstype mgs)
4932 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4933 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4934 DEVPTR=$(mdsdevname 1)
4936 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4940 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4941 ( [ -z "$MGSZFSDEV" ] &&
4942 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4943 DEVPTR=$(mdsdevname 1)
4945 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4948 error "unknown fstype!";;
4957 local fstype=$(facet_fstype mgs)
4961 # vdevs are not supported by ldiskfs
4964 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4965 ( [ -z "$MGSDEV" ] &&
4966 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4967 VDEVPTR=$(mdsvdevname 1)
4968 elif [ -n "$MGSDEV" ]; then
4972 error "unknown fstype!";;
4980 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4982 local var=${facet}_MOUNT
4983 eval mntpt=${!var:-${MOUNT}-$facet}
4990 local dev=$(facet_device $facet)
4991 local mnt=${2:-$(facet_mntpt $facet)}
4995 if dm_flakey_supported $facet; then
4996 dm_dev=$(dm_create_dev $facet $dev)
4997 [[ -n "$dm_dev" ]] || dm_dev=$dev
4999 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
5000 export_dm_dev $facet $dm_dev
5002 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
5007 local dev=$(facet_device $facet)
5008 local mnt=${2:-$(facet_mntpt $facet)}
5010 do_facet $facet $UMOUNT $mnt
5014 echo -n "$1" | tr -c '[:alnum:]\n' '_'
5019 local ds=$(facet_device $facet)
5020 local mnt=${2:-$(facet_mntpt $facet)}
5025 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
5026 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
5027 do_facet $facet $ZFS set canmount=noauto $ds
5029 # The "legacy" mount method is used here because "zfs unmount $mnt"
5030 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
5031 # targets are not available at the time, the stat(2) on $MOUNT will
5034 do_facet $facet $ZFS set mountpoint=legacy $ds
5035 do_facet $facet mount -t zfs $ds $mnt
5036 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
5037 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
5042 local ds=$(facet_device $facet)
5043 local mnt=${2:-$(facet_mntpt $facet)}
5044 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
5045 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
5046 local mntpt=${!var_mntpt}
5047 local canmnt=${!var_canmnt}
5051 do_facet $facet umount $mnt
5052 do_facet $facet $ZFS set mountpoint=$mntpt $ds
5053 do_facet $facet $ZFS set canmount=$canmnt $ds
5060 local fstype=$(facet_fstype $facet)
5062 mount_$fstype $facet $mnt
5068 local fstype=$(facet_fstype $facet)
5070 unmount_$fstype $facet $mnt
5077 # make sure we are using the primary server, so test-framework will
5078 # be able to clean up properly.
5079 activemds=`facet_active mds1`
5080 if [ $activemds != "mds1" ]; then
5084 local clients=$CLIENTS
5085 [ -z $clients ] && clients=$(hostname)
5087 zconf_umount_clients $clients $MOUNT "$*" || true
5088 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
5090 [ -n "$CLIENTONLY" ] && return
5092 # The add fn does rm ${facet}active file, this would be enough
5093 # if we use do_facet <facet> only after the facet added, but
5094 # currently we use do_facet mds in local.sh
5096 for num in `seq $MDSCOUNT`; do
5098 rm -f ${TMP}/mds${num}active
5100 combined_mgs_mds && rm -f $TMP/mgsactive
5102 for num in `seq $OSTCOUNT`; do
5104 rm -f $TMP/ost${num}active
5107 if ! combined_mgs_mds ; then
5111 if $SHARED_KEY; then
5112 export SK_MOUNTED=false
5118 cleanup_echo_devs () {
5121 local devs=$($LCTL dl | grep echo | awk '{print $4}')
5123 for dev in $devs; do
5124 $LCTL --device $dev cleanup
5125 $LCTL --device $dev detach
5129 # Allow %pK to print raw pointers and save the initial value
5130 kptr_enable_and_save() {
5131 # do not overwrite whatever was initially saved:
5132 [[ -f $TMP/kptr-$PPID-env ]] && return
5135 for node in $(all_nodes); do
5136 kptr[$node]=$(do_node $node "sysctl --values kernel/kptr_restrict")
5137 do_node $node "sysctl -wq kernel/kptr_restrict=1"
5139 declare -p kptr > $TMP/kptr-$PPID-env
5142 # Restore the initial %pK settings
5144 [[ ! -f $TMP/kptr-$PPID-env ]] && return
5146 source $TMP/kptr-$PPID-env
5149 for node in $(all_nodes); do
5150 [[ -z ${kptr[$node]} ]] && continue
5151 param="kernel/kptr_restrict=${kptr[$node]}"
5152 do_node $node "sysctl -wq ${param} || true"
5157 nfs_client_mode && return
5158 cifs_client_mode && return
5161 CLEANUP_DM_DEV=true stopall $*
5163 [[ $KPTR_ON_MOUNT ]] && kptr_restore
5170 combined_mgs_mds () {
5171 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
5172 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
5176 echo -n "$1" | tr '[:upper:]' '[:lower:]'
5180 echo -n "$1" | tr '[:lower:]' '[:upper:]'
5192 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
5193 for i in $(echo "$var"); do
5194 if [ "$i" == "-O" ]; then
5196 first_o=$(($first_o + 1))
5199 if [ "$i" == "-E" ]; then
5201 first_e=$(($first_e + 1 ))
5206 [ $first_o -gt 1 ] && opt_o+=",";
5210 [ $first_e -gt 1 ] && opt_e+=",";
5221 [ -n "$opt_o" ] && echo " -O $opt_o"
5222 [ -n "$opt_e" ] && echo " -E $opt_e"
5228 local fsname=${3:-"$FSNAME"}
5229 local type=$(facet_type $facet)
5230 local index=$(facet_index $facet)
5231 local fstype=$(facet_fstype $facet)
5232 local host=$(facet_host $facet)
5236 local varbs=${facet}_BLOCKSIZE
5238 if [ $type == MGS ] || ( [ $type == MDS ] &&
5239 [ "$dev" == $(mgsdevname) ] &&
5240 [ "$host" == "$(facet_host mgs)" ] ); then
5243 opts="--mgsnode=$MGSNID"
5246 if [ $type != MGS ]; then
5247 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
5251 var=${facet}failover_HOST
5252 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
5253 opts+=" --failnode=$(h2nettype ${!var})"
5256 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
5257 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
5259 if [ $type == MDS ]; then
5260 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
5261 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
5262 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
5264 if [ $fstype == ldiskfs ]; then
5266 if [ -n "${!var}" ]; then
5267 fs_mkfs_opts+=" -J device=${!var}"
5269 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
5271 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
5275 if [ $type == OST ]; then
5276 if [ $fstype == ldiskfs ]; then
5278 if [ -n "${!var}" ]; then
5279 fs_mkfs_opts+=" -J device=${!var}"
5281 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
5286 opts+=" --backfstype=$fstype"
5289 if [ -n "${!var}" ]; then
5290 opts+=" --device-size=${!var}"
5293 var=$(upper $fstype)_MKFS_OPTS
5294 fs_mkfs_opts+=${!var:+" ${!var}"}
5296 var=${type}_FS_MKFS_OPTS
5297 fs_mkfs_opts+=${!var:+" ${!var}"}
5299 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
5301 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
5302 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
5304 if [ -n "${fs_mkfs_opts## }" ]; then
5305 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
5309 opts+=${!var:+" ${!var}"}
5316 local type=$(facet_type $facet)
5317 local var=${type}_MOUNT_FS_OPTS
5319 if [ -n "${!var}" ]; then
5320 opts+=" --mountfsoptions=${!var}"
5325 check_ost_indices() {
5326 local index_count=${#OST_INDICES[@]}
5327 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
5329 # OST count is greater than the index count in $OST_INDEX_LIST.
5330 # We need check whether there are duplicate indices.
5334 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
5335 index=$(facet_index ost$i)
5336 for j in $(seq 0 $((index_count - 1))); do
5337 [[ $index -ne ${OST_INDICES[j]} ]] ||
5338 error "ost$i has the same index $index as ost$((j+1))"
5345 local facet_type=$1 # mgs || mds || ost
5347 local facet=${1}${2}
5350 case "$(facet_fstype $facet)" in
5352 device=$(${facet_type}devname $facet_num)
5355 device=$(${facet_type}vdevname $facet_num)
5358 error "Unhandled filesystem type"
5362 do_facet $facet "[ -e \"$device\" ]" && return
5364 # Note: the following check only works with absolute paths
5365 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5366 error "$facet: device '$device' does not exist"
5368 # zpool create doesn't like empty files
5369 [[ $(facet_fstype $facet) == zfs ]] && return 0
5371 do_facet $facet "touch \"${device}\""
5380 echo "Format mgs: $(mgsdevname)"
5381 reformat_external_journal mgs
5383 # touch "device" in case it is a loopback file for testing and needs to
5384 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5385 # to non-existent files in /dev if the admin made a typo during setup
5388 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5389 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5399 echo "Format mds$num: $(mdsdevname $num)"
5400 reformat_external_journal mds$num
5402 __touch_device mds $num
5404 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5405 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5406 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5415 echo "Format ost$num: $(ostdevname $num)"
5416 reformat_external_journal ost$num
5418 __touch_device ost $num
5420 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5421 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5422 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5427 # Set hostid for ZFS/SPL zpool import protection
5428 # (Assumes MDS version is also OSS version)
5429 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5431 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5434 # We need ldiskfs here, may as well load them all
5436 [ -n "$CLIENTONLY" ] && return
5437 echo Formatting mgs, mds, osts
5438 if ! combined_mgs_mds ; then
5442 for num in $(seq $MDSCOUNT); do
5446 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5448 for num in $(seq $OSTCOUNT); do
5454 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5458 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5461 # usage: switch_identity MDSNUM ENABLE_UPCALL
5464 # 0: success, the identity upcall was previously enabled already.
5465 # 1: success, the identity upcall was previously disabled.
5471 local MDT="$(mdtname_from_index $((num - 1)) $MOUNT)"
5472 local upcall="$L_GETIDENTITY"
5474 [[ -n "$MDT" ]] || return 2
5476 local param="mdt.$MDT.identity_upcall"
5477 local old="$(do_facet $facet "lctl get_param -n $param")"
5479 [[ "$enable" == "true" ]] || upcall="NONE"
5481 do_facet $facet "lctl set_param -n $param='$upcall'" || return 2
5482 do_facet $facet "lctl set_param -n mdt.$MDT.identity_flush=-1"
5484 [[ "$old" != "NONE" ]] # implicit "&& return 0 || return 1"
5489 zconf_umount $HOSTNAME $1 || error "umount failed"
5490 zconf_mount $HOSTNAME $1 || error "mount failed"
5498 rm -f $TMP/${facet}active
5499 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5504 local mdt_count=${1:-$MDSCOUNT}
5505 local ost_count=${2:-$OSTCOUNT}
5508 for num in $(seq $mdt_count); do
5509 DEVNAME=$(mdsdevname $num)
5510 writeconf_facet mds$num $DEVNAME || rc=$?
5513 for num in $(seq $ost_count); do
5514 DEVNAME=$(ostdevname $num)
5515 writeconf_facet ost$num $DEVNAME || rc=$?
5521 if ! combined_mgs_mds ; then
5522 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5523 do_facet mgs "$LCTL set_param -P debug_raw_pointers=Y"
5532 for num in $(seq $MDSCOUNT); do
5533 devname=$(mdsdevname $num)
5534 start mds$num $devname $MDS_MOUNT_OPTS
5536 # We started mds$num, now we should set mds${num}_HOST
5537 # and mds${num}failover_HOST variables properly if they
5539 host=$(facet_host mds$num)
5540 for varname in mds${num}_HOST mds${num}failover_HOST; do
5541 if [[ -z "${!varname}" ]]; then
5545 if [[ "$IDENTITY_UPCALL" != "default" ]]; then
5546 switch_identity $num $IDENTITY_UPCALL
5549 if combined_mgs_mds ; then
5550 do_facet mgs "$LCTL set_param -P debug_raw_pointers=Y"
5557 for num in $(seq $OSTCOUNT); do
5559 rm -f $TMP/ost${num}active
5568 for num in $(seq $OSTCOUNT); do
5569 devname=$(ostdevname $num)
5570 start ost$num $devname $OST_MOUNT_OPTS
5572 # We started ost$num, now we should set ost${num}_HOST
5573 # and ost${num}failover_HOST variables properly if they
5575 host=$(facet_host ost$num)
5576 for varname in ost${num}_HOST ost${num}failover_HOST; do
5577 if [[ -z "${!varname}" ]]; then
5585 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5586 if [ ! -z $arg1 ]; then
5587 [ "$arg1" = "server_only" ] && return
5590 if [ -n "$CLIENTS" ]; then
5591 zconf_mount_clients $CLIENTS $MOUNT
5595 if [ "$MOUNT_2" ]; then
5596 mount_client $MOUNT2
5597 if [ -n "$CLIENTS" ]; then
5598 zconf_mount_clients $CLIENTS $MOUNT2
5603 sk_nodemap_setup() {
5604 local sk_map_name=${1:-$SK_S2SNM}
5605 local sk_map_nodes=${2:-$HOSTNAME}
5606 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5607 for servernode in $sk_map_nodes; do
5608 local nids=$(do_nodes $servernode "$LCTL list_nids")
5609 for nid in $nids; do
5610 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5611 $sk_map_name --range $nid"
5619 nfs_client_mode && return
5620 cifs_client_mode && return
5622 sanity_mount_check || error "environments are insane!"
5628 if [ -z "$CLIENTONLY" ]; then
5629 echo Setup mgs, mdt, osts
5630 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5632 if $SK_MOUNTED; then
5633 echo "Shared Key file system already mounted"
5638 if $SHARED_KEY; then
5639 export SK_MOUNTED=true
5643 echo "GSS_SK: setting kernel keyring perms"
5644 do_nodes $(comma_list $(all_nodes)) \
5645 "keyctl show | grep lustre | cut -c1-11 |
5647 xargs -IX keyctl setperm X 0x3f3f3f3f"
5650 # Need to start one nodemap for servers,
5651 # and one for clients.
5652 sk_nodemap_setup $SK_S2SNM \
5653 $(comma_list $(all_server_nodes))
5655 sk_nodemap_setup $SK_S2SNMCLI \
5656 ${CLIENTS:-$HOSTNAME}
5657 echo "Nodemap set up for SK S2S, remounting."
5666 # wait a while to allow sptlrpc configuration be propogated to targets,
5667 # only needed when mounting new target devices.
5675 [[ $KPTR_ON_MOUNT ]] && kptr_enable_and_save
5677 # by remounting mdt before ost, initial connect from mdt to ost might
5678 # timeout because ost is not ready yet. wait some time to its fully
5679 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5680 # preceeded by a context negotiation rpc with $TIMEOUT.
5681 # FIXME better by monitoring import status.
5684 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5685 set_rule $FSNAME any cli2ost $SK_FLAVOR
5686 if $SK_SKIPFIRST; then
5687 export SK_SKIPFIRST=false
5691 "lctl set_param osc.*.idle_connect=1"
5694 wait_flavor cli2mdt $SK_FLAVOR
5695 wait_flavor cli2ost $SK_FLAVOR
5700 sleep $((TIMEOUT + 5))
5706 mounted_lustre_filesystems() {
5707 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5710 init_facet_vars () {
5711 [ -n "$CLIENTONLY" ] && return 0
5718 eval export ${facet}_dev=${device}
5719 eval export ${facet}_opt=\"$*\"
5721 local dev=${facet}_dev
5723 # We need to loop for the label
5724 # in case its not initialized yet.
5725 for wait_time in {0,1,3,5,10}; do
5727 if [ $wait_time -gt 0 ]; then
5728 echo "${!dev} not yet initialized,"\
5729 "waiting ${wait_time} seconds."
5733 local label=$(devicelabel ${facet} ${!dev})
5735 # Check to make sure the label does
5736 # not include ffff at the end of the label.
5737 # This indicates it has not been initialized yet.
5739 if [[ $label =~ [f|F]{4}$ ]]; then
5740 # label is not initialized, unset the result
5741 # and either try again or fail
5748 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5750 eval export ${facet}_svc=${label}
5752 local varname=${facet}failover_HOST
5753 if [ -z "${!varname}" ]; then
5755 if combined_mgs_mds && [ $facet == "mgs" ] &&
5756 [ -n "$mds1failover_HOST" ]; then
5757 temp=$mds1failover_HOST
5759 temp=$(facet_host $facet)
5761 eval export $varname=$temp
5764 varname=${facet}_HOST
5765 if [ -z "${!varname}" ]; then
5766 eval export $varname=$(facet_host $facet)
5769 # ${facet}failover_dev is set in cfg file
5770 varname=${facet}failover_dev
5771 if [ -n "${!varname}" ] ; then
5772 eval export ${facet}failover_dev=${!varname}
5774 eval export ${facet}failover_dev=$device
5777 # get mount point of already mounted device
5778 # is facet_dev is already mounted then use the real
5779 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5780 # i.e. ${facet}_MOUNT if specified by user or default
5781 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5782 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5783 if [ -z $mntpt ]; then
5784 mntpt=$(facet_mntpt $facet)
5786 eval export ${facet}_MOUNT=$mntpt
5789 init_facets_vars () {
5792 if ! remote_mds_nodsh; then
5793 for num in $(seq $MDSCOUNT); do
5794 DEVNAME=$(mdsdevname $num)
5795 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5799 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5801 if ! remote_ost_nodsh; then
5802 for num in $(seq $OSTCOUNT); do
5803 DEVNAME=$(ostdevname $num)
5804 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5809 init_facets_vars_simple () {
5812 if ! remote_mds_nodsh; then
5813 for num in $(seq $MDSCOUNT); do
5814 devname=$(mdsdevname $num)
5815 eval export mds${num}_dev=${devname}
5816 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5820 if ! combined_mgs_mds ; then
5821 eval export mgs_dev=$(mgsdevname)
5822 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5825 if ! remote_ost_nodsh; then
5826 for num in $(seq $OSTCOUNT); do
5827 devname=$(ostdevname $num)
5828 eval export ost${num}_dev=${devname}
5829 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5834 osc_ensure_active () {
5839 while [ $period -lt $timeout ]; do
5840 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5841 if [ $count -eq 0 ]; then
5845 echo "$count OST inactive, wait $period seconds, and try again"
5847 period=$((period+3))
5850 [ $period -lt $timeout ] ||
5851 log "$count OST are inactive after $timeout seconds, give up"
5854 set_conf_param_and_check() {
5858 local ORIG=$(do_facet $myfacet "$TEST")
5859 if [ $# -gt 3 ]; then
5865 echo "Setting $PARAM from $ORIG to $FINAL"
5866 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5867 error "conf_param $PARAM failed"
5869 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5870 error "check $PARAM failed!"
5873 set_persistent_param() {
5877 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5879 if [ $# -gt 3 ]; then
5886 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5887 echo "Setting $test_param from $orig to $final"
5888 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5889 error "$PERM_CMD $test_param failed"
5891 echo "Setting $param from $orig to $final"
5892 do_facet mgs "$PERM_CMD $param='$final'" ||
5893 error "$PERM_CMD $param failed"
5897 set_persistent_param_and_check() {
5901 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5903 if [ $# -gt 3 ]; then
5910 set_persistent_param $myfacet $test_param $param "$final"
5912 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5913 error "check $param failed!"
5916 init_param_vars () {
5917 TIMEOUT=$(lctl get_param -n timeout)
5918 TIMEOUT=${TIMEOUT:-20}
5920 if [ -n "$arg1" ]; then
5921 [ "$arg1" = "server_only" ] && return
5924 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5926 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5927 log "Using TIMEOUT=$TIMEOUT"
5929 # tune down to speed up testing on (usually) small setups
5930 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5931 do_nodes $(comma_list $(nodes_list)) \
5932 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5934 osc_ensure_active $SINGLEMDS $TIMEOUT
5935 osc_ensure_active client $TIMEOUT
5936 $LCTL set_param osc.*.idle_timeout=debug
5938 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5939 local current_jobid_var=$($LCTL get_param -n jobid_var)
5941 if [ $JOBID_VAR = "existing" ]; then
5942 echo "keeping jobstats as $current_jobid_var"
5943 elif [ $current_jobid_var != $JOBID_VAR ]; then
5944 echo "setting jobstats to $JOBID_VAR"
5946 set_persistent_param_and_check client \
5947 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5950 echo "jobstats not supported by server"
5953 if [ $QUOTA_AUTO -ne 0 ]; then
5954 if [ "$ENABLE_QUOTA" ]; then
5955 echo "enable quota as required"
5956 setup_quota $MOUNT || return 2
5958 echo "disable quota as required"
5959 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5963 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5964 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5968 nfs_client_mode () {
5969 if [ "$NFSCLIENT" ]; then
5970 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5971 local clients=$CLIENTS
5973 [ -z $clients ] && clients=$(hostname)
5975 # FIXME: remove hostname when 19215 fixed
5976 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5977 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5978 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5979 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5980 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5982 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5988 cifs_client_mode () {
5989 [ x$CIFSCLIENT = xyes ] &&
5990 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5993 check_config_client () {
5995 local mounted=$(mount | grep " $mntpt ")
5997 if [ -n "$CLIENTONLY" ]; then
5999 # CLIENTONLY should not depend on *_HOST settings
6000 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
6001 # in theory someone could create a new,
6002 # client-only config file that assumed lustre was already
6003 # configured and didn't set the MGSNID. If MGSNID is not set,
6004 # then we should use the mgs nid currently being used
6005 # as the default value. bug 18021
6006 [[ x$MGSNID = x ]] &&
6009 if [[ x$mgc != xMGC$MGSNID ]]; then
6010 if [ "$mgs_HOST" ]; then
6011 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
6012 grep PING | awk '{print $3}' |
6013 sed -e "s/(//g" -e "s/)//g")
6015 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
6016 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
6022 echo Checking config lustre mounted on $mntpt
6023 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
6024 mgshost=$(echo $mgshost | awk -F: '{print $1}')
6028 check_config_clients () {
6029 local clients=${CLIENTS:-$HOSTNAME}
6032 nfs_client_mode && return
6033 cifs_client_mode && return
6035 do_rpc_nodes "$clients" check_config_client $mntpt
6037 sanity_mount_check || error "environments are insane!"
6041 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
6042 local cltimeout=$(lctl get_param -n timeout)
6043 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
6044 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
6051 [ -z $mntpt ] && return 1
6052 local mounted=$(mounted_lustre_filesystems)
6054 echo $mounted' ' | grep -w -q $mntpt' '
6059 local ostsn=${2:-$OSTCOUNT}
6060 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
6063 echo ostsn=$ostsn npools=$npools
6064 if [[ $ostsn -gt $OSTCOUNT ]]; then
6065 echo "request to use $ostsn OSTs in the pool, \
6066 using max available OSTCOUNT=$OSTCOUNT"
6069 for (( n=0; n < $npools; n++ )); do
6071 if ! $DELETE_OLD_POOLS; then
6072 log "request to not delete old pools: $FSNAME.$p exist?"
6073 if ! check_pool_not_exist $FSNAME.$p; then
6074 echo "Using existing $FSNAME.$p"
6075 $LCTL pool_list $FSNAME.$p
6079 create_pool $FSNAME.$p $KEEP_POOLS ||
6080 error "create_pool $FSNAME.$p failed"
6082 local first=$(( (n * ostsn) % OSTCOUNT ))
6083 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
6084 if [[ $first -le $last ]]; then
6085 pool_add_targets $p $first $last ||
6086 error "pool_add_targets $p $first $last failed"
6088 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
6089 error "pool_add_targets $p $first \
6090 $(( OSTCOUNT - 1 )) failed"
6091 pool_add_targets $p 0 $last ||
6092 error "pool_add_targets $p 0 $last failed"
6097 set_pools_quota () {
6104 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
6105 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
6107 # POOLS_QUOTA_USERS_SET=
6108 # "quota15_1:20M -- for all of the found pools
6109 # quota15_2:1G:gpool0
6110 # quota15_3 -- for global limit only
6111 # quota15_4:200M:gpool0
6112 # quota15_4:200M:gpool1"
6114 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
6116 declare -A pq_limits
6118 for ((i=0; i<${#pq_userset[@]}; i++)); do
6119 u=${pq_userset[i]%%:*}
6121 # user gets no pool limits if
6122 # POOLS_QUOTA_USERS_SET does not specify it
6123 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
6124 pq_limits[$u]+=" $o"
6126 pq_users=(${!pq_limits[@]})
6131 for ((i=0; i<${#pq_users[@]}; i++)); do
6133 # set to max limit (_u64)
6134 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
6135 opts=(${pq_limits[$u]})
6136 for ((j=0; j<${#opts[@]}; j++)); do
6139 # Set limit for all existing pools if
6141 if [ $p == $o ]; then
6142 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
6143 echo "No pool specified for $u,
6144 set limit $o for all existing pools"
6147 $LFS setquota -u $u -B $o --pool $pool $DIR ||
6148 error "setquota -u $u -B $o \
6149 --pool $pool failed"
6152 $LFS quota -uv $u --pool $DIR
6156 do_check_and_setup_lustre() {
6157 # If auster does not want us to setup, then don't.
6158 ! ${do_setup} && return
6160 echo "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
6163 nfs_client_mode && return
6164 cifs_client_mode && return
6166 local MOUNTED=$(mounted_lustre_filesystems)
6170 # both MOUNT and MOUNT2 are not mounted
6171 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6172 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
6173 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
6175 is_mounted $MOUNT || error "NAME=$NAME not mounted"
6176 export I_MOUNTED=yes
6180 elif is_mounted $MOUNT2; then
6182 # MOUNT2 is mounted, while MOUNT_2 is not set
6183 if ! [ "$MOUNT_2" ]; then
6184 cleanup_mount $MOUNT2
6185 export I_UMOUNTED2=yes
6188 # MOUNT2 is mounted, MOUNT_2 is set
6190 # FIXME: what to do if check_config failed?
6192 # 1) remote client has mounted other Lustre fs ?
6193 # 2) it has insane env ?
6194 # try to umount MOUNT2 on all clients and mount again:
6195 if ! check_config_clients $MOUNT2; then
6196 cleanup_mount $MOUNT2
6197 restore_mount $MOUNT2
6198 export I_MOUNTED2=yes
6202 # MOUNT is mounted MOUNT2 is not mounted
6203 elif [ "$MOUNT_2" ]; then
6204 restore_mount $MOUNT2
6205 export I_MOUNTED2=yes
6209 # FIXME: what to do if check_config failed?
6211 # 1) remote client has mounted other Lustre fs?
6212 # 2) lustre is mounted on remote_clients atall ?
6213 check_config_clients $MOUNT
6217 set_default_debug_nodes $(comma_list $(nodes_list))
6221 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
6223 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
6224 facets="$(get_facets OST)"
6225 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
6226 facets="$facets,$(get_facets MDS)"
6227 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
6228 facets="$facets,mgs"
6229 local nodes="$(facets_hosts ${facets})"
6230 if [ -n "$nodes" ] ; then
6231 do_nodes $nodes "$LCTL set_param \
6232 osd-ldiskfs.track_declares_assert=1 || true"
6236 if [ -n "$fs_STRIPEPARAMS" ]; then
6237 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
6246 if $DELETE_OLD_POOLS; then
6250 if [[ -n "$FS_POOL" ]]; then
6251 create_pools $FS_POOL $FS_POOL_NOSTS
6254 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
6258 # set tunable parameters passed to test environment
6262 echo "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
6264 if [[ "$ONLY" == "setup" ]]; then
6269 check_and_setup_lustre() {
6270 local start_stamp=$(date +%s)
6271 local saved_umask=$(umask)
6272 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
6281 log_sub_test_begin test_setup
6283 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
6284 error=$(tail -1 $log)
6289 stop_stamp=$(date +%s)
6290 duration=$((stop_stamp - start_stamp))
6292 log_sub_test_end "$status" "$duration" "$rc" "$error"
6300 local clients=${CLIENTS:-$HOSTNAME}
6303 zconf_mount_clients $clients $mntpt
6307 local clients=${CLIENTS:-$HOSTNAME}
6310 zconf_umount_clients $clients $mntpt
6313 cleanup_and_setup_lustre() {
6314 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
6315 lctl set_param debug=0 || true
6318 if [[ "$ONLY" == "cleanup" ]]; then
6323 do_check_and_setup_lustre
6326 # Run e2fsck on MDT or OST device.
6331 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
6332 local log=$TMP/e2fsck.log
6335 # turn on pfsck if it is supported
6336 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
6338 do_node $node $cmd 2>&1 | tee $log
6340 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
6342 if [ $MDSCOUNT -gt 1 ]; then
6343 skip_noexit "DNE mode isn't supported!"
6347 error "It's not DNE mode."
6352 [ $rc -le $FSCK_MAX_ERR ] ||
6353 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6359 # Run resize2fs on MDT or OST device.
6368 do_facet $facet "$RESIZE2FS $opts $device $size"
6371 # verify a directory is shared among nodes.
6372 check_shared_dir() {
6374 local list=${2:-$(comma_list $(nodes_list))}
6376 [ -z "$dir" ] && return 1
6377 do_rpc_nodes "$list" check_logdir $dir
6378 check_write_access $dir "$list" || return 1
6383 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
6384 $LCTL set_param printk=+lfsck
6385 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6387 for k in $(seq $MDSCOUNT); do
6388 # wait up to 10+1 minutes for LFSCK to complete
6389 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6390 mdd.$(facet_svc mds${k}).lfsck_layout |
6391 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6392 error "MDS${k} layout isn't the expected 'completed'"
6393 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6394 mdd.$(facet_svc mds${k}).lfsck_namespace |
6395 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6396 error "MDS${k} namespace isn't the expected 'completed'"
6398 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
6399 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
6400 awk '/repaired/ { print $2 }' | calc_sum)
6401 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
6402 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
6403 awk '/repaired/ { print $2 }' | calc_sum)
6404 local repaired=$((rep_mdt + rep_ost))
6405 [ $repaired -eq 0 ] ||
6406 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6409 dump_file_contents() {
6415 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6416 error_noexit false \
6417 "Invalid parameters for dump_file_contents()"
6420 for node in ${nodes}; do
6421 do_node $node "for i in \\\$(find $dir -type f); do
6422 echo ====\\\${i}=======================;
6424 done" >> ${logname}.${node}.log
6428 dump_command_output() {
6434 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6435 error_noexit false \
6436 "Invalid parameters for dump_command_output()"
6440 for node in ${nodes}; do
6441 do_node $node "echo ====${cmd}=======================;
6442 $cmd" >> ${logname}.${node}.log
6449 # dump file contents from /proc/spl in case of zfs test
6450 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6451 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6452 dump_command_output \
6453 "$(osts_nodes)" "zpool events -v" "${logname}"
6456 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6457 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6458 dump_command_output \
6459 "$(mdts_nodes)" "zpool events -v" "${logname}"
6463 do_check_and_cleanup_lustre() {
6464 echo "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6466 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6467 "$TESTSUITE" != "sanity-scrub" ]]; then
6471 if is_mounted $MOUNT; then
6472 if $DO_CLEANUP; then
6473 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6474 error "remove sub-test dirs failed"
6478 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6481 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6482 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6485 if [[ "$I_MOUNTED2" == "yes" ]]; then
6486 cleanup_mount $MOUNT2
6489 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6490 cleanupall -f || error "cleanup failed"
6494 echo "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6497 check_and_cleanup_lustre() {
6498 local start_stamp=$(date +%s)
6499 local saved_umask=$(umask)
6500 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6509 log_sub_test_begin test_cleanup
6511 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6512 error=$(tail -1 $log)
6517 stop_stamp=$(date +%s)
6518 duration=$((stop_stamp - start_stamp))
6520 log_sub_test_end "$status" "$duration" "$rc" "$error"
6530 wait_for_function () {
6533 # suppress fn both stderr and stdout
6534 if [ "$1" = "--quiet" ]; then
6536 quiet=" > /dev/null 2>&1"
6547 eval $fn $quiet && return 0
6549 [ $wait -lt $max ] || return 1
6550 echo waiting $fn, $((max - wait)) secs left ...
6551 wait=$((wait + sleep))
6552 [ $wait -gt $max ] && ((sleep -= wait - max))
6562 [ "$host" = "$HOSTNAME" ] && return 0
6564 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6565 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6575 # Convert a space-delimited list to a comma-delimited list. If the input is
6576 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6578 # echo is used to convert newlines to spaces, since it doesn't
6579 # introduce a trailing space as using "tr '\n' ' '" does
6580 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6586 echo $list | grep -qw $item
6589 # list, excluded are the comma separated lists
6590 exclude_items_from_list () {
6596 for item in ${excluded//,/ }; do
6597 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6599 echo $(comma_list $list)
6602 # list, expand are the comma separated lists
6604 local list=${1//,/ }
6605 local expand=${2//,/ }
6608 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6609 echo $(comma_list $expanded)
6612 testslist_filter () {
6613 local script=$LUSTRE/tests/${TESTSUITE}.sh
6615 [ -f $script ] || return 0
6617 local start_at=$START_AT
6618 local stop_at=$STOP_AT
6620 local var=${TESTSUITE//-/_}_START_AT
6621 [ x"${!var}" != x ] && start_at=${!var}
6622 var=${TESTSUITE//-/_}_STOP_AT
6623 [ x"${!var}" != x ] && stop_at=${!var}
6625 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6626 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6627 /^'${start_at}'$/ {flag = 0}
6628 {if (flag == 1) print $0}
6629 /^'${stop_at}'$/ { flag = 1 }'
6633 (cd `dirname $1`; echo $PWD/`basename $1`)
6637 local types=${1:-"OST MDS MGS"}
6641 for entry in $types; do
6642 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6643 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6646 MGS ) list="$list $name";;
6647 MDS|OST|AGT ) local count=${type}COUNT
6648 for ((i=1; i<=${!count}; i++)) do
6649 list="$list ${name}$i"
6651 * ) error "Invalid facet type"
6655 echo $(comma_list $list)
6658 ##################################
6659 # Adaptive Timeouts funcs
6662 # only check mds, we assume at_max is the same on all nodes
6663 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6665 if [ $at_max -eq 0 ]; then
6676 # suppose that all ost-s have the same $at value set
6677 [ $facet != "ost" ] || facet=ost1
6679 do_facet $facet "lctl get_param -n $at"
6693 for facet in "$@"; do
6694 if [ $facet == "ost" ]; then
6695 facet=$(get_facets OST)
6696 elif [ $facet == "mds" ]; then
6697 facet=$(get_facets MDS)
6699 hosts=$(expand_list $hosts $(facets_hosts $facet))
6702 do_nodes $hosts lctl set_param at_max=$at_max
6716 for facet in "$@"; do
6717 if [ $facet == "ost" ]; then
6718 facet=$(get_facets OST)
6719 elif [ $facet == "mds" ]; then
6720 facet=$(get_facets MDS)
6722 hosts=$(expand_list $hosts $(facets_hosts $facet))
6725 do_nodes $hosts lctl set_param at_min=$at_min
6728 ##################################
6732 # OBD_FAIL_MDS_ALL_REQUEST_NET
6734 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6735 do_facet client "$1" || RC=$?
6736 do_facet $SINGLEMDS lctl set_param fail_loc=0
6741 # OBD_FAIL_MDS_ALL_REPLY_NET
6743 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6745 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6749 drop_reint_reply() {
6750 # OBD_FAIL_MDS_REINT_NET_REP
6752 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6754 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6758 drop_update_reply() {
6759 # OBD_FAIL_OUT_UPDATE_NET_REP
6763 do_facet mds${index} lctl set_param fail_loc=0x1701
6764 do_facet client "$@" || RC=$?
6765 do_facet mds${index} lctl set_param fail_loc=0
6770 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6773 local timeout=${2:-0}
6774 # default is (obd_timeout / 4) if unspecified
6775 echo "timeout is $timeout/$2"
6776 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6777 do_facet client "$1" || RC=$?
6778 do_facet client "sync"
6779 do_facet ost1 lctl set_param fail_loc=0
6783 drop_ldlm_cancel() {
6784 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6786 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6787 do_nodes $list lctl set_param fail_loc=0x304
6789 do_facet client "$@" || RC=$?
6791 do_nodes $list lctl set_param fail_loc=0
6795 drop_bl_callback_once() {
6797 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6798 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6799 do_facet client lctl set_param fail_loc=0x80000305
6800 do_facet client "$@" || rc=$?
6801 do_facet client lctl set_param fail_loc=0
6802 do_facet client lctl set_param fail_val=0
6803 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6807 drop_bl_callback() {
6809 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6810 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6811 do_facet client lctl set_param fail_loc=0x305
6812 do_facet client "$@" || rc=$?
6813 do_facet client lctl set_param fail_loc=0
6814 do_facet client lctl set_param fail_val=0
6815 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6819 drop_mdt_ldlm_reply() {
6820 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6822 local list=$(comma_list $(mdts_nodes))
6824 do_nodes $list lctl set_param fail_loc=0x157
6826 do_facet client "$@" || RC=$?
6828 do_nodes $list lctl set_param fail_loc=0
6832 drop_mdt_ldlm_reply_once() {
6833 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6835 local list=$(comma_list $(mdts_nodes))
6837 do_nodes $list lctl set_param fail_loc=0x80000157
6839 do_facet client "$@" || RC=$?
6841 do_nodes $list lctl set_param fail_loc=0
6849 echo "clearing fail_loc on $facet"
6850 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6853 set_nodes_failloc () {
6855 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6858 # Print the total of the lock_unused_count across all namespaces containing the
6859 # given wildcard. If the namespace wildcard is omitted, all namespaces will be
6861 # Usage: total_unused_locks [namespace_wildcard]
6862 total_unused_locks() {
6863 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_unused_count" | calc_sum
6866 # Print the total of the lock_count across all namespaces containing the given
6867 # wildcard. If the namespace wilcard is omitted, all namespaces will be matched.
6868 # Usage: total_used_locks [namespace_wildcard]
6869 total_used_locks() {
6870 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_count" | calc_sum
6873 # Cancel lru locks across all namespaces containing the given wildcard. If the
6874 # wilcard is omitted, lru locks will be canceled across all namespaces.
6875 # Usage: cancel_lru_locks [namespace_wildcard]
6876 cancel_lru_locks() {
6877 #$LCTL mark "cancel_lru_locks $1 start"
6878 $LCTL set_param -t4 -n "ldlm.namespaces.*$1*.lru_size=clear"
6879 $LCTL get_param "ldlm.namespaces.*$1*.lock_unused_count" | grep -v '=0'
6880 #$LCTL mark "cancel_lru_locks $1 stop"
6885 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6887 echo $((100 * nr_cpu))
6892 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6895 lru_resize_disable()
6898 local lru_size=${2:-$(default_lru_size)}
6900 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6905 local mountpath=${1:-$MOUNT}
6908 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6915 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6916 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6917 echo there is still data in page cache $FILE ?
6918 lctl get_param -n $FILE
6926 DEBUGSAVE="$(lctl get_param -n debug)"
6927 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6931 [ -n "$DEBUGSAVE" ] &&
6932 do_nodes $CLIENTS $LCTL set_param -n debug=${DEBUGSAVE// /+} ||
6936 [ -n "$DEBUGSAVE_SERVER" ] &&
6937 do_nodes $(comma_list $(all_server_nodes)) \
6938 $LCTL set_param -n debug=${DEBUGSAVE_SERVER// /+} ||
6944 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6947 debug_size_restore() {
6948 [ -n "$DEBUG_SIZE_SAVED" ] &&
6949 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6953 start_full_debug_logging() {
6958 local debug_size=150
6959 local nodes=$(comma_list $(nodes_list))
6961 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6964 stop_full_debug_logging() {
6969 # prints bash call stack
6970 print_stack_trace() {
6973 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6974 local src=${BASH_SOURCE[$i]}
6975 local lineno=${BASH_LINENO[$i-1]}
6976 local funcname=${FUNCNAME[$i]}
6977 echo " = $src:$lineno:$funcname()"
6982 local TYPE=${TYPE:-"FAIL"}
6985 # do not dump logs if $1=false
6986 if [ "x$1" = "xfalse" ]; then
6991 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6992 (print_stack_trace 2) >&2
6994 # We need to dump the logs on all nodes
6996 gather_logs $(comma_list $(nodes_list))
7000 [ "$TESTSUITELOG" ] &&
7001 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
7002 if [ -z "$*" ]; then
7003 echo "error() without useful message, please fix" > $LOGDIR/err
7005 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
7006 echo "$@" > $LOGDIR/ignore
7008 echo "$@" > $LOGDIR/err
7012 # cleanup the env for failed tests
7016 ##################################
7018 ##################################
7020 # usage: stack_trap arg sigspec
7022 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
7023 # command "arg" on top of previously defined commands for "sigspec" instead
7024 # of overwriting them.
7025 # stacked traps are executed in reverse order of their registration
7027 # arg and sigspec have the same meaning as in man (1) trap
7031 local sigspec="${2:-EXIT}"
7033 # Use "trap -p" to get the quoting right
7034 local old_trap="$(trap -p "$sigspec")"
7035 # Append ";" and remove the leading "trap -- '" added by "trap -p"
7036 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
7038 # Once again, use "trap -p" to get the quoting right
7039 local new_trap="$(trap -- "$arg" "$sigspec"
7041 trap -- '' "$sigspec")"
7043 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
7045 # The resulting string should be safe to "eval" as it is (supposedly
7046 # correctly) quoted by "trap -p"
7047 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
7056 local logs="$TESTSUITELOG $1"
7058 for log in $logs; do
7059 if [ -f "$log" ]; then
7060 grep -qw FAIL $log && status=1
7077 # use only if we are ignoring failures for this test, bugno required.
7078 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
7079 # e.g. error_ignore bz5494 "your message" or
7080 # error_ignore LU-5494 "your message"
7082 local TYPE="IGNORE ($1)"
7087 error_and_remount() {
7089 remount_client $MOUNT
7093 # Throw an error if it's not running in vm - usually for performance
7096 local virt=$(running_in_vm)
7097 if [[ -n "$virt" ]]; then
7098 echo "running in VM '$virt', ignore error"
7099 error_ignore env=$virt "$@"
7106 # Function: skip_env()
7107 # Purpose: to skip a test during developer testing because some tool
7108 # is missing, but fail the test in release testing because the test
7109 # environment is not configured properly".
7112 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
7117 log " SKIP: $TESTSUITE $TESTNAME $*"
7119 if [[ -n "$ALWAYS_SKIPPED" ]]; then
7120 skip_logged $TESTNAME "$@"
7123 echo "$@" > $LOGDIR/skip
7126 [[ -n "$TESTSUITELOG" ]] &&
7127 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
7137 # For interop testing treate EOPNOTSUPP as success
7143 echo $retstr | awk -F'|' '{print $1}' |
7144 grep -E unsupported\|"(Operation not supported)"
7145 (( $? == 0 )) || error "$retstr"
7149 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
7150 # Usage: always_except LU-4815 23 42q ...
7152 function always_except() {
7153 local issue="${1:-}" # single jira style issue ("LU-4815")
7158 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
7159 error "always_except: invalid issue '$issue' for tests '$*'"
7162 for test_num in "$@"; do
7163 ALWAYS_EXCEPT+=" $test_num"
7167 build_test_filter() {
7168 EXCEPT="$EXCEPT $(testslist_filter)"
7170 # allow test numbers separated by '+', or ',', in addition to ' '
7171 # to avoid issues with multiple arguments handling by shell/autotest
7172 for O in ${ONLY//[+,]/ }; do
7173 if [[ $O =~ [0-9]*-[0-9]* ]]; then
7174 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
7182 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
7183 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
7184 [[ -z "$EXCEPT_SLOW" ]] ||
7185 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
7186 for E in ${EXCEPT//[+,]/ }; do
7187 eval EXCEPT_${E}=true
7189 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
7190 eval EXCEPT_ALWAYS_${E}=true
7192 for E in ${EXCEPT_SLOW//[+,]/ }; do
7193 eval EXCEPT_SLOW_${E}=true
7195 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
7196 eval GCHECK_ONLY_${G}=true
7198 # similar to $EXCEPT, STOP_ON_ERROR is a list of test numbers,
7199 # e.g. [30d, 34a]. Now set variable STOP_ON_ERROR_30d, etc.
7200 for T in $STOP_ON_ERROR; do
7201 eval STOP_ON_ERROR_${T}=true
7206 if [[ $1 = [a-z]* ]]; then
7209 echo ${1%%[a-zA-Z]*}
7213 # print a newline if the last test was skipped
7214 export LAST_SKIPPED=
7215 export ALWAYS_SKIPPED=
7217 # Main entry into test-framework. This is called with the number and
7218 # description of a test. The number is used to find the function to run
7219 # the test using "test_$name".
7221 # This supports a variety of methods of specifying specific test to
7223 # - ONLY= env variable with space-separated list of test numbers to run
7224 # - EXCEPT= env variable with space-separated list of test numbers to exclude
7230 export base=$(basetest $testnum)
7231 export TESTNAME=test_$testnum
7235 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
7236 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
7237 local isexcept=EXCEPT_$testnum
7238 local isexcept_base=EXCEPT_$base
7239 if [ ${!isexcept}x != x ]; then
7241 skip_message="skipping excluded test $testnum"
7242 elif [ ${!isexcept_base}x != x ]; then
7244 skip_message="skipping excluded test $testnum (base $base)"
7247 isexcept=EXCEPT_ALWAYS_$testnum
7248 isexcept_base=EXCEPT_ALWAYS_$base
7249 if [ ${!isexcept}x != x ]; then
7251 skip_message="skipping ALWAYS excluded test $testnum"
7252 elif [ ${!isexcept_base}x != x ]; then
7254 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
7257 isexcept=EXCEPT_SLOW_$testnum
7258 isexcept_base=EXCEPT_SLOW_$base
7259 if [ ${!isexcept}x != x ]; then
7261 skip_message="skipping SLOW test $testnum"
7262 elif [ ${!isexcept_base}x != x ]; then
7264 skip_message="skipping SLOW test $testnum (base $base)"
7267 # If there are tests on the ONLY list, check if the current test
7268 # is on that list and, if so, check if the test is to be skipped
7269 # and if we are supposed to honor the skip lists.
7270 if [ -n "$ONLY" ]; then
7271 local isonly=ONLY_$testnum
7272 local isonly_base=ONLY_$base
7273 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
7275 if [[ -n "$ALWAYS_SKIPPED" &&
7276 -n "$HONOR_EXCEPT" ]]; then
7278 skip_noexit "$skip_message"
7281 [ -n "$LAST_SKIPPED" ] &&
7282 echo "" && LAST_SKIPPED=
7284 run_one_logged $testnum "$testmsg"
7294 if [ -n "$ALWAYS_SKIPPED" ]; then
7296 skip_noexit "$skip_message"
7299 run_one_logged $testnum "$testmsg"
7306 load_module ../libcfs/libcfs/libcfs
7319 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
7324 strace -o $TMP/$1.strace -ttt $*
7326 log "FINISHED: $*: rc $RC"
7333 banner "test complete, duration $duration sec"
7334 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
7335 echo "duration $duration" >>$TESTSUITELOG
7339 # Set TEST_STATUS here. It will be used for logging the result.
7342 if [[ -f $LOGDIR/err ]]; then
7344 elif [[ -f $LOGDIR/skip ]]; then
7347 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
7351 local FFREE=$(do_node $SINGLEMDS \
7352 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
7353 local FTOTAL=$(do_node $SINGLEMDS \
7354 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
7356 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
7361 #echo -n "Resetting fail_loc on all nodes..."
7362 do_nodes --quiet $(comma_list $(nodes_list)) \
7363 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
7369 # Log a message (on all nodes) padded with "=" before and after.
7370 # Also appends a timestamp and prepends the testsuite name.
7373 # ======================================================== 15:06:12 (1624050372)
7374 EQUALS="========================================================"
7376 msg="== ${TESTSUITE} $*"
7378 [[ $last != "=" && $last != " " ]] && msg="$msg "
7379 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
7380 # always include at least == after the message
7381 log "$msg== $(date +"%H:%M:%S (%s)")"
7384 check_dmesg_for_errors() {
7386 local errors="VFS: Busy inodes after unmount of\|\
7387 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
7388 group descriptors corrupted"
7390 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
7391 [ -z "$res" ] && return 0
7392 echo "Kernel error detected: $res"
7397 # Run a single test function and cleanup after it.
7399 # This function should be run in a subshell so the test func can
7400 # exit() without stopping the whole script.
7405 local SAVE_UMASK=`umask`
7408 if ! grep -q $DIR /proc/mounts; then
7412 banner "test $testnum: $testmsg"
7413 test_${testnum} || error "test_$testnum failed with $?"
7416 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7418 check_dmesg_for_errors || error "Error in dmesg detected"
7419 if [ "$PARALLEL" != "yes" ]; then
7420 ps auxww | grep -v grep | grep -q "multiop " &&
7421 error "multiop still running"
7429 # Wrapper around run_one to ensure:
7430 # - test runs in subshell
7431 # - output of test is saved to separate log file for error reporting
7432 # - test result is saved to data file
7435 local before=$SECONDS
7438 export tfile=f${testnum}.${TESTSUITE}
7439 export tdir=d${testnum}.${TESTSUITE}
7440 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7441 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7442 local SAVE_UMASK=$(umask)
7447 [[ $KPTR_ON_MOUNT ]] || kptr_enable_and_save
7449 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7452 # process ONLY options:
7453 # - $ONLY_REPEAT will run the subtest $ONLY_REPEAT times
7454 # - $ONLY_MINUTES will run the subtest for $ONLY_MINUTES
7455 # - $ONLY_REPEAT and $ONLY_MINUTES can be set to run the subtest for
7456 # $ONLY_REPEAT times but not to exceed $ONLY_MINUTES
7457 # - if $ONLY_REPEAT and ONLY_MINUTES are unset, subtest will run once
7458 local repeat=${ONLY:+$ONLY_REPEAT}
7459 if [[ -n "$ONLY" && "$ONLY_MINUTES" ]]; then
7460 local repeat_end_sec=$((SECONDS + ONLY_MINUTES * 60))
7465 local before_sub=$SECONDS
7467 log_sub_test_begin $TESTNAME
7468 # remove temp files between repetitions to avoid test failures
7469 if [[ -n "$append" ]]; then
7470 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7471 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7472 echo "subtest iteration $testiter/$repeat " \
7473 "($(((SECONDS-before)/60))/$ONLY_MINUTES min)"
7475 # loop around subshell so stack_trap EXIT triggers each time
7476 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
7479 local duration_sub=$((SECONDS - before_sub))
7482 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7483 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7485 if [[ -f $LOGDIR/err ]]; then
7486 test_error=$(cat $LOGDIR/err)
7488 elif [[ -f $LOGDIR/ignore ]]; then
7489 test_error=$(cat $LOGDIR/ignore)
7490 elif [[ -f $LOGDIR/skip ]]; then
7491 test_error=$(cat $LOGDIR/skip)
7497 pass "$testnum" "(${duration_sub}s)"
7498 if [ -n "${DUMP_OK}" ]; then
7499 gather_logs $(comma_list $(nodes_list))
7502 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7504 # exit test suite if the failed test is in STOP_ON_ERROR list
7505 [[ $TEST_STATUS == "FAIL" ]] &&
7506 [[ -v STOP_ON_ERROR_$testnum ]] &&
7509 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7511 # no repeat options were set, break after the first iteration
7512 [[ -z "$repeat" && -z "$repeat_end_sec" ]] && break
7513 # break if any repeat options were set and have been met
7514 [[ -n "$repeat" ]] && (( $testiter >= $repeat )) && break
7515 [[ -n "$repeat_end_sec" ]] &&
7516 (( $SECONDS >= $repeat_end_sec )) && break
7520 [[ $KPTR_ON_MOUNT ]] || kptr_restore
7522 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7526 if [ -f $LOGDIR/err ]; then
7527 log_zfs_info "$zfs_debug_log"
7528 $FAIL_ON_ERROR && exit $rc
7541 # Print information of skipped tests to result.yml
7544 log_sub_test_begin $1
7546 log_sub_test_end "SKIP" "0" "0" "$@"
7549 grant_from_clients() {
7553 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7557 grant_from_servers() {
7561 # which is tot_granted less grant_precreate
7562 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7563 " obdfilter.${FSNAME}-OST*.tot_pending" \
7564 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7565 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7566 /tot_pending/{ total -= $2 };
7567 /grant_precreate/{ total -= $2 };
7568 END { printf("%0.0f", total) }'
7572 export base=$(basetest $1)
7573 [ "$CHECK_GRANT" == "no" ] && return 0
7575 local isonly_base=GCHECK_ONLY_${base}
7576 local isonly=GCHECK_ONLY_$1
7577 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7579 echo -n "checking grant......"
7581 local osts=$(comma_list $(osts_nodes))
7582 local clients=$CLIENTS
7583 [ -z "$clients" ] && clients=$(hostname)
7585 # sync all the data and make sure no pending data on server
7586 do_nodes $clients sync
7587 do_nodes $clients $LFS df # initiate all idling connections
7590 cli_grant=$(grant_from_clients $clients)
7593 # which is tot_granted less grant_precreate
7594 srv_grant=$(grant_from_servers $osts)
7597 # check whether client grant == server grant
7598 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7599 echo "wait for client:$cli_grant == server:$srv_grant"
7601 cli_grant=$(grant_from_clients $clients)
7602 srv_grant=$(grant_from_servers $osts)
7604 if [[ $cli_grant -ne $srv_grant ]]; then
7605 do_nodes $(comma_list $(osts_nodes)) \
7606 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7607 "obdfilter.${FSNAME}-OST*.grant_*"
7608 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7609 error "failed grant check: client:$cli_grant server:$srv_grant"
7611 echo "pass grant check: client:$cli_grant server:$srv_grant"
7615 ########################
7624 ostuuid_from_index() {
7625 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7626 local uuid=($($LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7631 ostname_from_index() {
7632 local uuid=$(ostuuid_from_index $1 $2)
7637 mdtuuid_from_index() {
7638 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7639 local uuid=($($LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7644 mdtname_from_index() {
7645 local uuid=$(mdtuuid_from_index $1 $2)
7650 mdssize_from_index() {
7651 local mdt=$(mdtname_from_index $2)
7653 $LFS df $1 | awk "/$mdt/ { print \$2 }"
7656 index_from_ostuuid()
7658 # only print the first index, if 'lfs osts' shows multiple mountpoints
7659 local ostidx=($($LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"))
7665 # Return unique identifier for given hostname
7668 echo $host_name | md5sum | cut -d' ' -f1
7672 # Returns list of ip addresses for each interface
7674 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7678 # Returns list of interfaces configured for LNet
7680 local nids=( $($LCTL list_nids | xargs echo) )
7682 [[ -z ${nids[@]} ]] &&
7685 if [[ ${NETTYPE} =~ kfi* ]]; then
7686 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7687 sort -u | xargs echo
7691 declare -a INTERFACES
7693 for ((i = 0; i < ${#nids[@]}; i++)); do
7694 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7695 INTERFACES[i]=$(ip -o a s |
7696 awk '$4 ~ /^'$ip'\//{print $2}')
7697 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7698 if [[ -z ${INTERFACES[i]} ]]; then
7699 error "Can't determine interface name for NID ${nids[i]}"
7700 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7701 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7705 echo "${INTERFACES[@]}"
7710 # return 1 if addr is remote
7711 # return 0 if addr is local
7714 # Cache address list to avoid mutiple execution of local_addr_list
7715 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7717 for i in $LOCAL_ADDR_LIST ; do
7718 [[ "$i" == "$addr" ]] && return 0
7723 # return true(0) if host_name is local
7724 # return false(1) if host_name is remote
7727 local is_local="IS_LOCAL_$(host_id $host_name)"
7729 if [ -z "${!is_local-}" ] ; then
7730 eval $is_local=false
7731 local host_ip=$(getent ahostsv4 $host_name |
7732 awk 'NR == 1 { print $1 }')
7733 is_local_addr "$host_ip" && eval $is_local=true
7747 for node in $(mdts_nodes); do
7748 remote_node $node && return 0
7755 [ -n "$CLIENTONLY" ] && return 0 || true
7756 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7761 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7762 MSKIPPED=1 && return 1
7769 for node in $(osts_nodes) ; do
7770 remote_node $node && return 0
7777 [ -n "$CLIENTONLY" ] && return 0 || true
7778 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7783 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7784 OSKIPPED=1 && return 1
7790 [ -n "$CLIENTONLY" ] && return 0 || true
7792 MGS=$(facet_host mgs)
7793 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7798 remote_mds_nodsh || remote_ost_nodsh ||
7799 $(single_local_node $(comma_list $(nodes_list)))
7803 remote_ost && remote_mds
7806 # Get the active nodes for facets.
7814 for facet in ${facets//,/ }; do
7815 nodes="$nodes $(facet_active_host $facet)"
7818 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7822 # Get name of the active MGS node.
7824 echo -n $(facets_nodes $(get_facets MGS))
7827 # Get all of the active MDS nodes.
7829 echo -n $(facets_nodes $(get_facets MDS))
7832 # Get all of the active OSS nodes.
7834 echo -n $(facets_nodes $(get_facets OST))
7837 # Get all of the client nodes and active server nodes.
7839 local nodes=$HOSTNAME
7843 # CLIENTS (if specified) contains the local client
7844 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7846 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7847 nodes="$nodes $(facets_nodes $(get_facets))"
7850 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7854 # Get all of the remote client nodes and remote active server nodes.
7855 remote_nodes_list () {
7856 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7859 # Get all of the MDS nodes, including active and passive nodes.
7867 for i in $(seq $MDSCOUNT); do
7869 failover_host=mds${i}failover_HOST
7870 nodes="$nodes ${!host} ${!failover_host}"
7873 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7874 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7878 # Get all of the OSS nodes, including active and passive nodes.
7886 for i in $(seq $OSTCOUNT); do
7888 failover_host=ost${i}failover_HOST
7889 nodes="$nodes ${!host} ${!failover_host}"
7892 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7893 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7897 # Get all of the server nodes, including active and passive nodes.
7898 all_server_nodes () {
7903 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7905 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7909 # Get all of the client and server nodes, including active and passive nodes.
7911 local nodes=$HOSTNAME
7915 # CLIENTS (if specified) contains the local client
7916 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7918 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7919 nodes="$nodes $(all_server_nodes)"
7922 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7926 init_clients_lists () {
7927 # Sanity check: exclude the local client from RCLIENTS
7928 local clients=$(hostlist_expand "$RCLIENTS")
7929 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7931 # Sanity check: exclude the dup entries
7932 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7934 export CLIENT1=${CLIENT1:-$HOSTNAME}
7935 export SINGLECLIENT=$CLIENT1
7937 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7939 # Sanity check: exclude the dup entries from CLIENTS
7940 # for those configs which has SINGLCLIENT set to local client
7941 clients=$(for i in $clients; do echo $i; done | sort -u)
7943 export CLIENTS=$(comma_list $clients)
7944 local -a remoteclients=($RCLIENTS)
7945 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7946 varname=CLIENT$((i + 2))
7948 eval export $varname=${remoteclients[i]}
7951 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7954 get_random_entry () {
7957 rnodes=${rnodes//,/ }
7959 local -a nodes=($rnodes)
7960 local num=${#nodes[@]}
7961 local i=$((RANDOM * num * 2 / 65536))
7967 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7971 # this should already have been called, but just in case
7972 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7975 echo "client=$CLIENT_VERSION MDS=$MDS1_VERSION OSS=$OST1_VERSION"
7977 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7978 error "unable to determine node versions"
7980 (( "$CLIENT_VERSION" == "$MDS1_VERSION" &&
7981 "$CLIENT_VERSION" == "$OST1_VERSION"))
7987 echo $nodes | wc -w || true
7991 local nodes=$(mdts_nodes)
7992 local mdtcount=$(get_node_count "$nodes")
7994 [ ! "$MDSCOUNT" = "$mdtcount" ]
7997 generate_machine_file() {
7998 local nodes=${1//,/ }
7999 local machinefile=$2
8002 for node in $nodes; do
8003 echo $node >>$machinefile ||
8004 { echo "can not generate machinefile $machinefile" &&
8010 local file=$1/stripe
8013 $LFS getstripe -v $file || error "getstripe $file failed"
8017 # Check and add a test group.
8023 local gid=$(getent group $group_name | cut -d: -f3)
8024 if [[ -n "$gid" ]]; then
8025 [[ "$gid" -eq "$group_id" ]] || {
8026 error_noexit "inconsistent group ID:" \
8027 "new: $group_id, old: $gid"
8031 echo "adding group $group_name:$group_id"
8032 getent group $group_name || true
8033 getent group $group_id || true
8034 groupadd -g $group_id $group_name
8041 # Check and add a test user.
8054 local uid=$(getent passwd $user_name | cut -d: -f3)
8055 if [[ -n "$uid" ]]; then
8056 if [[ "$uid" -eq "$user_id" ]]; then
8057 local dir=$(getent passwd $user_name | cut -d: -f6)
8058 if [[ "$dir" != "$home" ]]; then
8060 usermod -d $home $user_name
8064 error_noexit "inconsistent user ID:" \
8065 "new: $user_id, old: $uid"
8070 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
8077 check_runas_id_ret() {
8079 local myRUNAS_UID=$1
8080 local myRUNAS_GID=$2
8084 if [ -z "$myRUNAS" ]; then
8085 error_exit "check_runas_id_ret requires myRUNAS argument"
8089 error "Unable to execute $myRUNAS"
8091 id $myRUNAS_UID > /dev/null ||
8092 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
8093 "some UID which exists on MDS and client or add user " \
8094 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
8097 $myRUNAS krb5_login.sh ||
8098 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
8100 mkdir $DIR/d0_runas_test
8102 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
8103 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
8104 rm -rf $DIR/d0_runas_test
8109 local myRUNAS_UID=$1
8110 local myRUNAS_GID=$2
8114 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
8115 error "unable to write to $DIR/d0_runas_test as " \
8119 # obtain the UID/GID for MPI_USER
8123 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
8124 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
8126 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
8127 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
8130 # Run multiop in the background, but wait for it to print
8131 # "PAUSING" to its stdout before returning from this function.
8132 multiop_bg_pause() {
8133 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
8137 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
8140 echo "$MULTIOP_PROG $FILE v$ARGS"
8141 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
8144 echo "TMPPIPE=${TMPPIPE}"
8145 read -t 60 multiop_output < $TMPPIPE
8146 if [ $? -ne 0 ]; then
8151 if [ "$multiop_output" != "PAUSING" ]; then
8152 echo "Incorrect multiop output: $multiop_output"
8167 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
8169 echo $((SECONDS - start))
8173 inodes_available () {
8174 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
8175 sort -un | head -n1) || return 1
8180 mdsrate_inodes_available () {
8181 local min_inodes=$(inodes_available)
8183 echo $((min_inodes * 99 / 100))
8186 bytes_available () {
8187 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
8190 mdsrate_bytes_available () {
8191 local bytes=$(bytes_available)
8193 echo $((bytes * 99 / 100))
8196 # reset stat counters
8198 local paramfile="$1"
8200 lctl set_param -n $paramfile=0
8205 local paramfile="$1"
8208 lctl get_param -n $paramfile |
8209 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
8213 awk '{sum += $1} END { printf("%0.0f", sum) }'
8216 calc_osc_kbytes () {
8217 $LFS df $MOUNT > /dev/null
8218 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
8222 wait_delete_completed
8223 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8224 echo "OST kbytes available: ${AVAIL[*]}"
8229 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8230 #echo OST $i: ${AVAIL[i]}kb
8231 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8235 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8240 echo "Min free space: OST $MINI: $MINV"
8241 echo "Max free space: OST $MAXI: $MAXV"
8244 # save_lustre_params(comma separated facet list, parameter_mask)
8245 # generate a stream of formatted strings (<facet> <param name>=<param value>)
8246 save_lustre_params() {
8251 for facet in ${facets//,/ }; do
8252 facet_svc=$(facet_svc $facet)
8254 "params=\\\$($LCTL get_param $2);
8255 [[ -z \\\"$facet_svc\\\" ]] && param= ||
8256 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
8257 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
8258 while read s; do echo $facet \\\$s;
8259 done <<< \\\"\\\$param\\\""
8263 # restore lustre parameters from input stream, produces by save_lustre_params
8264 restore_lustre_params() {
8269 while IFS=" =" read facet name val; do
8270 do_facet $facet "$LCTL set_param -n $name=$val"
8274 check_node_health() {
8275 local nodes=${1:-$(comma_list $(nodes_list))}
8276 local health=$TMP/node_health.$$
8278 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
8279 grep "catastrophe=1" && error "LBUG/LASSERT detected"
8280 # Only check/report network health if get_param isn't reported, since
8281 # *clearly* the network is working if get_param returned something.
8282 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
8283 for node in ${nodes//,/ }; do
8284 check_network $node 5
8290 mdsrate_cleanup () {
8292 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
8293 --nfiles $3 --dir $4 --filefmt $5 $6
8299 local test_type="$1"
8312 local mdtest_basedir
8313 local mdtest_actions
8314 local mdtest_options
8315 local stripe_options
8318 case "$test_type" in
8320 stripe_options=(-c 1 -i 0)
8321 mdtest_actions=(-F -R)
8326 stripe_options=(-c -1)
8327 mdtest_actions=(-F -R)
8328 file_size=$((1024 * 1024 * 1024))
8332 stripe_options=(-c 1)
8333 mdtest_actions=(-C -D -E -k -r)
8338 stripe_options=(-c 1)
8339 mdtest_actions=(-C -D -E -k -r)
8344 stripe_options=(-c -1)
8350 if [[ -n "$MDTEST_DEBUG" ]]; then
8351 mdtest_options+=(-v -v -v)
8354 num_dirs=${NUM_DIRS:-$num_dirs}
8355 num_files=${NUM_FILES:-$num_files}
8356 file_size=${FILE_SIZE:-$file_size}
8357 free_space=$(mdsrate_bytes_available)
8359 if (( file_size * num_files > free_space )); then
8360 file_size=$((free_space / num_files))
8361 log "change file size to $file_size due to" \
8362 "number of files $num_files and" \
8363 "free space limit in $free_space"
8366 if (( file_size > 0 )); then
8367 log "set file size to $file_size"
8368 mdtest_options+=(-w=$file_size)
8371 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
8372 mdtest_basedir=$MOUNT/mdtest
8373 mdtest_options+=(-d=$mdtest_basedir)
8376 num_hosts=$(get_node_count ${CLIENTS//,/ })
8377 num_procs=$((num_cores * num_hosts))
8378 num_inodes=$(mdsrate_inodes_available)
8380 if (( num_inodes < num_files )); then
8381 log "change the number of files $num_files to the" \
8382 "number of available inodes $num_inodes"
8383 num_files=$num_inodes
8386 if (( num_dirs > 1 )); then
8387 num_entries=$((num_files / num_dirs))
8388 log "split $num_files files to $num_dirs" \
8389 "with $num_entries files each"
8390 mdtest_options+=(-I=$num_entries)
8393 generate_machine_file $CLIENTS $MACHINEFILE ||
8394 error "can not generate machinefile"
8396 install -v -d -m 0777 $mdtest_basedir
8398 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
8400 save_lustre_params $(get_facets MDS) \
8401 mdt.*.enable_remote_dir_gid > $params_file
8403 do_nodes $(comma_list $(mdts_nodes)) \
8404 $LCTL set_param mdt.*.enable_remote_dir_gid=-1
8406 stack_trap "restore_lustre_params < $params_file" EXIT
8408 for np in 1 $num_procs; do
8409 num_entries=$((num_files / np ))
8411 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8412 -np $np -npernode $num_cores $MDTEST \
8413 ${mdtest_options[@]} -n=$num_entries \
8414 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
8418 if (( rc != 0 )); then
8419 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8420 -np $np -npernode $num_cores $MDTEST \
8421 ${mdtest_options[@]} -n=$num_entries \
8422 -r 2>&1 | tee -a "$LOG"
8427 rmdir -v $mdtest_basedir
8428 rm -v $state $MACHINEFILE
8433 ########################
8435 convert_facet2label() {
8438 if [ x$facet = xost ]; then
8440 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8444 local varsvc=${facet}_svc
8446 if [ -n "${!varsvc}" ]; then
8449 error "No label for $facet!"
8453 get_clientosc_proc_path() {
8454 echo "${1}-osc-[-0-9a-f]*"
8457 get_mdtosc_proc_path() {
8459 local ost_label=${2:-"*OST*"}
8461 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8462 local mdt_label=$(convert_facet2label $mds_facet)
8463 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8465 if [[ $ost_label = *OST* ]]; then
8466 echo "${ost_label}-osc-${mdt_index}"
8468 echo "${ost_label}-osp-${mdt_index}"
8472 get_osc_import_name() {
8475 local label=$(convert_facet2label $ost)
8477 if [ "${facet:0:3}" = "mds" ]; then
8478 get_mdtosc_proc_path $facet $label
8482 get_clientosc_proc_path $label
8486 _wait_import_state () {
8488 local CONN_PROC="$2"
8489 local maxtime=${3:-$(max_recovery_time)}
8490 local err_on_fail=${4:-1}
8494 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8495 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8496 if [[ "${expected}" == "DISCONN" ]]; then
8497 # for disconn we can check after proc entry is removed
8498 [[ -z "${CONN_STATE}" ]] && return 0
8499 # with AT, we can have connect request timeout near
8500 # reconnect timeout and test can't see real disconnect
8501 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8503 if (( $i >= $maxtime )); then
8504 (( $err_on_fail != 0 )) &&
8505 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8509 # Add uniq for multi-mount case
8510 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8515 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8519 wait_import_state() {
8522 local maxtime=${3:-$(max_recovery_time)}
8523 local err_on_fail=${4:-1}
8526 for param in ${params//,/ }; do
8527 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8532 wait_import_state_mount() {
8533 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8537 wait_import_state "$@"
8540 # One client request could be timed out because server was not ready
8541 # when request was sent by client.
8542 # The request timeout calculation details :
8544 # /* We give the server rq_timeout secs to process the req, and
8545 # add the network latency for our local timeout. */
8546 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8547 # ptlrpc_at_get_net_latency(request) ;
8549 # ptlrpc_connect_import ()
8550 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8553 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8554 # ptlrpc_at_get_net_latency(request) ->
8555 # at_get (max (iat_net_latency=0, at_min)) = at_min
8558 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8559 # INITIAL_CONNECT_TIMEOUT + at_min
8561 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8562 # because we can not get this value in runtime,
8563 # the value depends on configure options, and it is not stored in /proc.
8565 # #define CONNECTION_SWITCH_MIN 5U
8566 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8568 request_timeout () {
8571 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8572 local init_connect_timeout=$TIMEOUT
8573 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8575 local at_min=$(at_get $facet at_min)
8577 echo $(( init_connect_timeout + at_min ))
8580 _wait_osc_import_state() {
8584 local target=$(get_osc_import_name $facet $ost_facet)
8585 local param="os[cp].${target}.ost_server_uuid"
8589 # 1. wait the deadline of client 1st request (it could be skipped)
8590 # 2. wait the deadline of client 2nd request
8591 local maxtime=$(( 2 * $(request_timeout $facet)))
8593 if [[ $facet == client* ]]; then
8594 # During setup time, the osc might not be setup, it need wait
8595 # until list_param can return valid value.
8596 params=$($LCTL list_param $param 2>/dev/null || true)
8597 while [ -z "$params" ]; do
8598 if [ $i -ge $maxtime ]; then
8599 echo "can't get $param in $maxtime secs"
8604 params=$($LCTL list_param $param 2>/dev/null || true)
8608 if [[ $ost_facet = mds* ]]; then
8609 # no OSP connection to itself
8610 if [[ $facet = $ost_facet ]]; then
8613 param="osp.${target}.mdt_server_uuid"
8617 local plist=$(comma_list $params)
8618 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8619 wait_import_state $expected $plist $maxtime; then
8620 error "$facet: import is not in $expected state after $maxtime"
8627 wait_osc_import_state() {
8633 if [[ $facet = mds ]]; then
8634 for num in $(seq $MDSCOUNT); do
8635 _wait_osc_import_state mds$num "$ost_facet" "$expected"
8638 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
8642 wait_osc_import_ready() {
8643 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
8646 _wait_mgc_import_state() {
8649 local error_on_failure=${3:-1}
8650 local param="mgc.*.mgs_server_uuid"
8654 # 1. wait the deadline of client 1st request (it could be skipped)
8655 # 2. wait the deadline of client 2nd request
8656 local maxtime=$(( 2 * $(request_timeout $facet)))
8658 if [[ $facet == client* ]]; then
8659 # During setup time, the osc might not be setup, it need wait
8660 # until list_param can return valid value. And also if there
8661 # are mulitple osc entries we should list all of them before
8663 params=$($LCTL list_param $param 2>/dev/null || true)
8664 while [ -z "$params" ]; do
8665 if [ $i -ge $maxtime ]; then
8666 echo "can't get $param in $maxtime secs"
8671 params=$($LCTL list_param $param 2>/dev/null || true)
8674 local plist=$(comma_list $params)
8675 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8676 wait_import_state $expected $plist $maxtime \
8677 $error_on_failure; then
8678 if [ $error_on_failure -ne 0 ]; then
8679 error "import is not in ${expected} state"
8687 wait_mgc_import_state() {
8690 local error_on_failure=${3:-1}
8693 if [[ $facet = mds ]]; then
8694 for num in $(seq $MDSCOUNT); do
8695 _wait_mgc_import_state mds$num "$expected" \
8696 $error_on_failure || return
8699 _wait_mgc_import_state "$facet" "$expected" \
8700 $error_on_failure || return
8704 wait_dne_interconnect() {
8707 if [ $MDSCOUNT -gt 1 ]; then
8708 for num in $(seq $MDSCOUNT); do
8709 wait_osc_import_ready mds mds$num
8714 get_clientmdc_proc_path() {
8718 get_clientmgc_proc_path() {
8725 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8730 [ -z "$list" ] && return 0
8732 # Add paths to lustre tests for 32 and 64 bit systems.
8733 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8734 local TESTPATH="$RLUSTRE/tests:"
8735 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8736 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8737 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8741 wait_clients_import_state () {
8745 local facets="$facet"
8747 if [ "$FAILURE_MODE" = HARD ]; then
8748 facets=$(for f in ${facet//,/ }; do
8749 facets_on_host $(facet_active_host $f) | tr "," "\n"
8750 done | sort -u | paste -sd , )
8753 for facet in ${facets//,/ }; do
8754 local label=$(convert_facet2label $facet)
8757 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8758 $label).ost_server_uuid" ;;
8759 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8760 $label).mds_server_uuid" ;;
8761 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8762 $label).mgs_server_uuid" ;;
8763 *) error "unknown facet!" ;;
8766 local params=$(expand_list $params $proc_path)
8769 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8771 error "import is not in ${expected} state"
8776 wait_clients_import_ready() {
8777 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
8789 # wait until all MDTs are in the expected state
8790 for ((num = 1; num <= $MDSCOUNT; num++)); do
8791 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8794 if [ $facet = "mds" ]; then
8795 mproc="osp.$mdtosp.active"
8796 [ $num -eq $((tgt_idx + 1)) ] && continue
8798 mproc="osc.$mdtosp.active"
8804 val=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8806 if (( rc != 0 )); then
8807 echo "Can't read $mproc (rc = $rc)"
8808 elif [[ "$val" == "$expected" ]]; then
8809 echo "$mproc updated after $wait sec (got $val)"
8814 error "$tgt_name: wanted $expected got $val"
8816 echo "Waiting $((max - wait)) secs for $mproc"
8828 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8829 $LCTL get_param obdfilter.*.kbytesavail))
8830 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8831 $LCTL get_param -n obdfilter.*.tot_granted))
8832 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8833 $LCTL get_param -n obdfilter.*.kbytestotal))
8834 for ((i=0; i<${#AVAILA[@]}; i++)); do
8835 local -a AVAIL1=(${AVAILA[$i]//=/ })
8836 local -a TOTAL=(${TOTALA[$i]//=/ })
8837 GRANT=$((${GRANTA[$i]}/1024))
8838 # allow 1% of total space in bavail because of delayed
8839 # allocation with ZFS which might release some free space after
8840 # txg commit. For small devices, we set a mininum of 8MB
8841 local LIMIT=$((${TOTAL} / 100 + 8000))
8842 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8843 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8844 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8845 echo " FULL" || echo
8851 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8854 check_pool_not_exist() {
8855 local fsname=${1%%.*}
8856 local poolname=${1##$fsname.}
8857 [[ $# -ne 1 ]] && return 0
8858 [[ x$poolname = x ]] && return 0
8859 list_pool $fsname | grep -w $1 && return 1
8864 local fsname=${1%%.*}
8865 local poolname=${1##$fsname.}
8866 local keep_pools=${2:-false}
8868 stack_trap "destroy_test_pools $fsname" EXIT
8869 do_facet mgs lctl pool_new $1
8871 # get param should return err unless pool is created
8872 [[ $RC -ne 0 ]] && return $RC
8874 for mds_id in $(seq $MDSCOUNT); do
8875 local mdt_id=$((mds_id-1))
8876 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8877 wait_update_facet mds$mds_id \
8878 "lctl get_param -n lod.$lodname.pools.$poolname \
8879 2>/dev/null || echo foo" "" ||
8880 error "mds$mds_id: pool_new failed $1"
8882 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8883 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8885 $keep_pools || add_pool_to_list $1
8889 add_pool_to_list () {
8890 local fsname=${1%%.*}
8891 local poolname=${1##$fsname.}
8893 local listvar=${fsname}_CREATED_POOLS
8894 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8898 remove_pool_from_list () {
8899 local fsname=${1%%.*}
8900 local poolname=${1##$fsname.}
8902 local listvar=${fsname}_CREATED_POOLS
8903 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8907 # cleanup all pools exist on $FSNAME
8908 destroy_all_pools () {
8910 for i in $(list_pool $FSNAME); do
8915 destroy_pool_int() {
8917 local OSTS=$(list_pool $1)
8918 for ost in $OSTS; do
8919 do_facet mgs lctl pool_remove $1 $ost
8921 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8922 error "MDS: pool_list $1 failed"
8923 do_facet mgs lctl pool_destroy $1
8926 # <fsname>.<poolname> or <poolname>
8928 local fsname=${1%%.*}
8929 local poolname=${1##$fsname.}
8931 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8935 check_pool_not_exist $fsname.$poolname && return 0 || true
8937 destroy_pool_int $fsname.$poolname
8939 [[ $RC -ne 0 ]] && return $RC
8940 for mds_id in $(seq $MDSCOUNT); do
8941 local mdt_id=$((mds_id-1))
8942 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8943 wait_update_facet mds$mds_id \
8944 "lctl get_param -n lod.$lodname.pools.$poolname \
8945 2>/dev/null || echo foo" "foo" ||
8946 error "mds$mds_id: destroy pool failed $1"
8948 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8949 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8951 remove_pool_from_list $fsname.$poolname
8957 local fsname=${1:-$FSNAME}
8959 local listvar=${fsname}_CREATED_POOLS
8961 [ x${!listvar} = x ] && return 0
8963 echo "Destroy the created pools: ${!listvar}"
8964 for poolname in ${!listvar//,/ }; do
8965 destroy_pool $fsname.$poolname
8969 destroy_test_pools () {
8970 local fsname=${1:-$FSNAME}
8971 destroy_pools $fsname || true
8977 local ts=$(date +%s)
8980 if [[ ! -f "$YAML_LOG" ]]; then
8981 # init_logging is not performed before gather_logs,
8982 # so the $LOGDIR needs to be checked here
8983 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8986 [ -f $LOGDIR/shared ] && docp=false
8988 # dump lustre logs, dmesg, and journal if GSS_SK=true
8990 prefix="$TESTLOG_PREFIX.$TESTNAME"
8992 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8994 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8995 echo "Dumping logs only on local client."
8996 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8997 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8998 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8999 $LGSS_SK -r {} \; &> \
9000 ${prefix}.ssk_keys.$(hostname -s).${suffix}
9001 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
9002 ${prefix}.nodemaps.$(hostname -s).${suffix}
9003 [ "$GSS" = true ] && keyctl show > \
9004 ${prefix}.keyring.$(hostname -s).${suffix}
9005 [ "$GSS" = true ] && journalctl -a > \
9006 ${prefix}.journal.$(hostname -s).${suffix}
9011 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
9012 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
9013 if [ "$SHARED_KEY" = true ]; then
9014 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
9015 $LGSS_SK -r {} \; &> \
9016 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
9017 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
9018 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
9020 if [ "$GSS" = true ]; then
9021 do_nodesv $list "keyctl show > \
9022 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
9023 do_nodesv $list "journalctl -a > \
9024 ${prefix}.journal.\\\$(hostname -s).${suffix}"
9027 if [ ! -f $LOGDIR/shared ]; then
9028 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
9030 for node in ${remote_nodes//,/ }; do
9031 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
9045 for i in $(seq 0 $num_mntpts); do
9046 cmd="ls -laf ${mntpt_root}$i/$dir"
9052 for pid in $pids; do
9059 # check_and_start_recovery_timer()
9060 # service_time = at_est2timeout(service_time);
9061 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
9062 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
9064 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
9065 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
9066 #define CONNECTION_SWITCH_MIN 5
9067 #define CONNECTION_SWITCH_INC 5
9068 max_recovery_time() {
9069 local init_connect_timeout=$((TIMEOUT / 20))
9070 ((init_connect_timeout >= 5)) || init_connect_timeout=5
9072 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
9073 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
9075 echo -n $service_time
9078 recovery_time_min() {
9079 local connection_switch_min=5
9080 local connection_switch_inc=5
9081 local connection_switch_max
9082 local reconnect_delay_max
9083 local initial_connect_timeout
9087 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
9088 (($connection_switch_min > $TIMEOUT)) &&
9089 max=$connection_switch_min || max=$TIMEOUT
9090 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
9092 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
9093 timeout_20=$((TIMEOUT/20))
9094 (($connection_switch_min > $timeout_20)) &&
9095 initial_connect_timeout=$connection_switch_min ||
9096 initial_connect_timeout=$timeout_20
9098 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
9099 initial_connect_timeout))
9100 echo $((2 * reconnect_delay_max))
9103 get_clients_mount_count () {
9104 local clients=${CLIENTS:-$HOSTNAME}
9106 # we need to take into account the clients mounts and
9107 # exclude mds/ost mounts if any;
9108 do_nodes $clients cat /proc/mounts | grep lustre |
9109 grep -w $MOUNT | wc -l
9113 PROC_CLI="srpc_info"
9114 PROC_CON="srpc_contexts"
9122 if [ $M -lt $N ]; then
9126 while [ $N -lt $M ]; do
9136 calc_connection_cnt() {
9139 # MDT->MDT = 2 * C(M, 2)
9143 comb_m2=$(combination $MDSCOUNT 2)
9145 local num_clients=$(get_clients_mount_count)
9147 local cnt_mdt2mdt=$((comb_m2 * 2))
9148 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
9149 local cnt_cli2ost=$((num_clients * OSTCOUNT))
9150 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
9151 if is_mounted $MOUNT2; then
9152 cnt_cli2mdt=$((cnt_cli2mdt * 2))
9153 cnt_cli2ost=$((cnt_cli2ost * 2))
9161 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
9162 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
9163 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
9164 + cnt_cli2ost + cnt_cli2mdt))
9178 local cmd="$tgt.srpc.flavor"
9180 if [ $net == "any" ]; then
9185 if [ $dir != "any" ]; then
9190 log "Setting sptlrpc rule: $cmd"
9191 do_facet mgs "$LCTL conf_param $cmd"
9197 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
9207 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
9208 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
9210 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
9212 if [ "x$bulkspec" != "x" ]; then
9213 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
9215 if [ "x$algs" != "x" ]; then
9216 bulk_count=`echo "$output" | grep "bulk flavor" |
9219 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
9221 if [ $bulk == "bulkn" ]; then
9222 bulk_count=`echo "$output" |
9223 grep "bulk flavor" | grep "null/null" |
9225 elif [ $bulk == "bulki" ]; then
9226 bulk_count=`echo "$output" |
9227 grep "bulk flavor" | grep "/null" |
9228 grep -v "null/" | wc -l`
9230 bulk_count=`echo "$output" |
9231 grep "bulk flavor" | grep -v "/null" |
9232 grep -v "null/" | wc -l`
9235 [ $bulk_count -lt $count ] && count=$bulk_count
9246 local clients=${CLIENTS:-$HOSTNAME}
9248 for c in ${clients//,/ }; do
9249 local output=$(do_node $c lctl get_param -n \
9250 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
9251 local tmpcnt=$(count_flvr "$output" $flavor)
9253 if $GSS_SK && [ $flavor != "null" ]; then
9254 # tmpcnt=min(contexts,flavors) to ensure SK context is
9256 output=$(do_node $c lctl get_param -n \
9257 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
9258 local outcon=$(count_contexts "$output")
9260 if [ "$outcon" -lt "$tmpcnt" ]; then
9264 cnt=$((cnt + tmpcnt))
9271 local clients=${CLIENTS:-$HOSTNAME}
9273 for c in ${clients//,/ }; do
9274 do_node $c lctl get_param \
9275 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null
9278 do_node $c lctl get_param \
9279 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null
9289 local clients=${CLIENTS:-$HOSTNAME}
9291 for c in ${clients//,/ }; do
9293 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
9294 local output=$(do_node $c lctl get_param -n \
9295 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
9296 local tmpcnt=$(count_flvr "$output" $flavor)
9298 if $GSS_SK && [ $flavor != "null" ]; then
9299 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9300 output=$(do_node $c lctl get_param -n \
9301 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
9302 local outcon=$(count_contexts "$output")
9304 if [ "$outcon" -lt "$tmpcnt" ]; then
9308 cnt=$((cnt + tmpcnt))
9315 local clients=${CLIENTS:-$HOSTNAME}
9317 for c in ${clients//,/ }; do
9318 do_node $c lctl get_param \
9319 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null
9322 do_node $c lctl get_param \
9323 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null
9333 if [ $MDSCOUNT -le 1 ]; then
9338 for num in `seq $MDSCOUNT`; do
9339 local output=$(do_facet mds$num lctl get_param -n \
9340 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
9341 local tmpcnt=$(count_flvr "$output" $flavor)
9343 if $GSS_SK && [ $flavor != "null" ]; then
9344 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9345 output=$(do_facet mds$num lctl get_param -n \
9346 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
9347 local outcon=$(count_contexts "$output")
9349 if [ "$outcon" -lt "$tmpcnt" ]; then
9353 cnt=$((cnt + tmpcnt))
9360 for num in `seq $MDSCOUNT`; do
9361 do_facet mds$num lctl get_param \
9362 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null
9365 do_facet mds$num lctl get_param \
9366 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null
9377 for num in `seq $MDSCOUNT`; do
9378 mdtosc=$(get_mdtosc_proc_path mds$num)
9379 mdtosc=${mdtosc/-MDT*/-MDT\*}
9380 local output=$(do_facet mds$num lctl get_param -n \
9381 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
9382 # Ensure SK context is on
9383 local tmpcnt=$(count_flvr "$output" $flavor)
9385 if $GSS_SK && [ $flavor != "null" ]; then
9386 output=$(do_facet mds$num lctl get_param -n \
9387 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
9388 local outcon=$(count_contexts "$output")
9390 if [ "$outcon" -lt "$tmpcnt" ]; then
9394 cnt=$((cnt + tmpcnt))
9401 for num in `seq $MDSCOUNT`; do
9402 mdtosc=$(get_mdtosc_proc_path mds$num)
9403 mdtosc=${mdtosc/-MDT*/-MDT\*}
9404 do_facet mds$num lctl get_param \
9405 os[cp].$mdtosc.$PROC_CLI 2>/dev/null
9408 do_facet mds$num lctl get_param \
9409 os[cp].$mdtosc.$PROC_CON 2>/dev/null
9418 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
9420 count_flvr "$output" $flavor
9425 local dir=$1 # from to
9426 local flavor=$2 # flavor expected
9429 if [ $dir == "cli2mdt" ]; then
9430 res=`flvr_cnt_cli2mdt $flavor`
9431 elif [ $dir == "cli2ost" ]; then
9432 res=`flvr_cnt_cli2ost $flavor`
9433 elif [ $dir == "mdt2mdt" ]; then
9434 res=`flvr_cnt_mdt2mdt $flavor`
9435 elif [ $dir == "mdt2ost" ]; then
9436 res=`flvr_cnt_mdt2ost $flavor`
9437 elif [ $dir == "all2ost" ]; then
9438 res1=`flvr_cnt_mdt2ost $flavor`
9439 res2=`flvr_cnt_cli2ost $flavor`
9440 res=$((res1 + res2))
9441 elif [ $dir == "all2mdt" ]; then
9442 res1=`flvr_cnt_mdt2mdt $flavor`
9443 res2=`flvr_cnt_cli2mdt $flavor`
9444 res=$((res1 + res2))
9445 elif [ $dir == "all2all" ]; then
9446 res1=`flvr_cnt_mdt2ost $flavor`
9447 res2=`flvr_cnt_cli2ost $flavor`
9448 res3=`flvr_cnt_mdt2mdt $flavor`
9449 res4=`flvr_cnt_cli2mdt $flavor`
9450 res=$((res1 + res2 + res3 + res4))
9458 local clients=${CLIENTS:-$HOSTNAME}
9461 for c in ${clients//,/ }; do
9462 [ "$type" == "osc" ] &&
9463 do_node $c lctl get_param osc.*.idle_timeout
9464 do_node $c lctl get_param $type.*.import |
9465 grep -E "name:|state:"
9471 local dir=$1 # from to
9473 if [ $dir == "cli2mdt" ]; then
9474 do_dump_imp_state mdc
9476 elif [ $dir == "cli2ost" ]; then
9477 do_dump_imp_state osc
9479 elif [ $dir == "mdt2mdt" ]; then
9481 elif [ $dir == "mdt2ost" ]; then
9483 elif [ $dir == "all2ost" ]; then
9485 do_dump_imp_state osc
9487 elif [ $dir == "all2mdt" ]; then
9489 do_dump_imp_state mdc
9491 elif [ $dir == "all2all" ]; then
9493 do_dump_imp_state osc
9496 do_dump_imp_state mdc
9503 local dir=$1 # from to
9504 local flavor=$2 # flavor expected
9505 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
9506 local WAITFLAVOR_MAX=20 # how many retries before abort?
9509 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
9510 echo -n "checking $dir..."
9511 res=$(do_check_flavor $dir $flavor)
9512 echo "found $res/$expect $flavor connections"
9513 [ $res -ge $expect ] && return 0
9517 echo "Error checking $flavor of $dir: expect $expect, actual $res"
9518 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
9521 gather_logs $(comma_list $(nodes_list))
9526 restore_to_default_flavor()
9528 local proc="mgs.MGS.live.$FSNAME"
9530 echo "restoring to default flavor..."
9532 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9533 grep ".srpc.flavor" | wc -l)
9535 # remove all existing rules if any
9536 if [ $nrule -ne 0 ]; then
9537 echo "$nrule existing rules"
9538 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9539 grep ".srpc.flavor."); do
9540 echo "remove rule: $rule"
9541 spec=`echo $rule | awk -F = '{print $1}'`
9542 do_facet mgs "$LCTL conf_param -d $spec"
9546 # verify no rules left
9547 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9548 grep ".srpc.flavor." | wc -l)
9549 [ $nrule -ne 0 ] && error "still $nrule rules left"
9551 # wait for default flavor to be applied
9554 set_rule $FSNAME any any $SK_FLAVOR
9555 wait_flavor all2all $SK_FLAVOR
9557 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9558 set_rule $FSNAME any cli2ost $SK_FLAVOR
9559 wait_flavor cli2mdt $SK_FLAVOR
9560 wait_flavor cli2ost $SK_FLAVOR
9562 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9564 wait_flavor all2all null
9570 local flavor=${1:-null}
9572 echo "setting all flavor to $flavor"
9574 # FIXME need parameter to this fn
9575 # and remove global vars
9576 local cnt_all2all=$(calc_connection_cnt all2all)
9578 local res=$(do_check_flavor all2all $flavor)
9579 if [ $res -eq $cnt_all2all ]; then
9580 echo "already have total $res $flavor connections"
9584 echo "found $res $flavor out of total $cnt_all2all connections"
9585 restore_to_default_flavor
9587 [[ $flavor = null ]] && return 0
9589 if $GSS_SK && [ $flavor != "null" ]; then
9591 set_rule $FSNAME any any $flavor
9592 wait_flavor all2all $flavor
9594 set_rule $FSNAME any cli2mdt $flavor
9595 set_rule $FSNAME any cli2ost $flavor
9596 set_rule $FSNAME any mdt2ost null
9597 set_rule $FSNAME any mdt2mdt null
9598 wait_flavor cli2mdt $flavor
9599 wait_flavor cli2ost $flavor
9601 echo "GSS_SK now at flavor: $flavor"
9603 set_rule $FSNAME any cli2mdt $flavor
9604 set_rule $FSNAME any cli2ost $flavor
9605 set_rule $FSNAME any mdt2ost null
9606 set_rule $FSNAME any mdt2mdt null
9607 wait_flavor cli2mdt $flavor
9608 wait_flavor cli2ost $flavor
9615 # Checking for shared logdir
9616 if [ ! -d $dir ]; then
9617 # Not found. Create local logdir
9620 touch $dir/check_file.$(hostname -s)
9625 check_write_access() {
9627 local list=${2:-$(comma_list $(nodes_list))}
9631 for node in ${list//,/ }; do
9632 file=$dir/check_file.$(short_nodename $node)
9633 if [[ ! -f "$file" ]]; then
9634 # Logdir not accessible/writable from this node.
9637 rm -f $file || return 1
9643 [[ -n $YAML_LOG ]] && return
9644 local save_umask=$(umask)
9647 export YAML_LOG=${LOGDIR}/results.yml
9651 # If the yaml log already exists then we will just append to it
9652 if [ ! -f $YAML_LOG ]; then
9653 if check_shared_dir $LOGDIR; then
9654 touch $LOGDIR/shared
9655 echo "Logging to shared log directory: $LOGDIR"
9657 echo "Logging to local directory: $LOGDIR"
9660 yml_nodes_file $LOGDIR >> $YAML_LOG
9661 yml_results_file >> $YAML_LOG
9666 # log actual client and server versions if needed for debugging
9667 log "Client: $(lustre_build_version client)"
9668 log "MDS: $(lustre_build_version mds1)"
9669 log "OSS: $(lustre_build_version ost1)"
9673 yml_log_test $1 >> $YAML_LOG
9677 yml_log_test_status "$@" >> $YAML_LOG
9680 log_sub_test_begin() {
9681 yml_log_sub_test_begin "$@" >> $YAML_LOG
9684 log_sub_test_end() {
9685 yml_log_sub_test_end "$@" >> $YAML_LOG
9691 local llverdev_opts="$*"
9692 local devname=$(basename $dev)
9693 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
9694 # loop devices aren't in /proc/partitions
9695 [[ -z "$size" ]] && size=$(stat -c %s $dev)
9697 local size_gb=$((size / 1024 / 1024)) # Gb
9699 local partial_arg=""
9700 # Run in partial (fast) mode if the size of a partition > 1 GB
9701 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
9703 llverdev --force $partial_arg $llverdev_opts $dev
9709 local llverfs_opts=$2
9710 local use_partial_arg=$3
9711 local partial_arg=""
9712 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
9714 # Run in partial (fast) mode if the size of a partition > 1 GB
9715 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
9717 llverfs $partial_arg $llverfs_opts $dir
9721 local devs=${1//,/ }
9724 local rslt=$TMP/sgpdd_survey
9726 # sgpdd-survey cleanups ${rslt}.* files
9728 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
9734 # returns the canonical name for an ldiskfs device
9739 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
9740 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
9741 echo dm-\\\${foo##*:};
9743 name=\\\$(basename \\\$dv);
9744 if [[ \\\$name = *flakey* ]]; then
9745 name=\\\$(lsblk -o NAME,KNAME |
9746 awk /\\\$name/'{print \\\$NF}');
9752 is_sanity_benchmark() {
9753 local benchmarks="dbench bonnie iozone fsx"
9756 for b in $benchmarks; do
9757 if [ "$b" == "$suite" ]; then
9765 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
9769 # Get the available size (KB) of a given obd target.
9776 [[ $facet != client ]] || return 0
9778 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
9783 # Get the page size (bytes) on a given facet node.
9784 # The local client page_size is directly available in PAGE_SIZE.
9788 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
9790 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
9791 page_size=$(do_facet $facet getconf PAGE_SIZE)
9792 echo -n ${page_size:-4096}
9796 # Get the block count of the filesystem.
9803 [ -z "$CLIENTONLY" ] &&
9804 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
9805 awk '/^Block count:/ {print $3}')
9809 # Check whether the "ea_inode" feature is enabled or not, to allow
9810 # ldiskfs xattrs over one block in size. Allow both the historical
9811 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
9812 large_xattr_enabled() {
9813 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
9815 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
9817 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
9818 grep -E -q '(ea_inode|large_xattr)'"
9819 return ${PIPESTATUS[0]}
9822 # Get the maximum xattr size supported by the filesystem.
9824 $LCTL get_param -n llite.*.max_easize
9827 # Dump the value of the named xattr from a file.
9832 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9835 # Generate a string with size of $size bytes.
9837 local size=${1:-1024} # in bytes
9839 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9842 reformat_external_journal() {
9847 local varbs=${facet}_BLOCKSIZE
9848 if [ -n "${!var}" ]; then
9849 local rcmd="do_facet $facet"
9850 local bs=${!varbs:-$BLCKSIZE}
9853 echo "reformat external journal on $facet:${!var}"
9854 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9858 # MDT file-level backup/restore
9859 mds_backup_restore() {
9862 local devname=$(mdsdevname $(facet_number $facet))
9863 local mntpt=$(facet_mntpt brpt)
9864 local rcmd="do_facet $facet"
9865 local metadata=${TMP}/backup_restore.tgz
9866 local opts=${MDS_MOUNT_FS_OPTS}
9867 local svc=${facet}_svc
9869 if ! ${rcmd} test -b ${devname}; then
9870 opts=$(csa_add "$opts" -o loop)
9873 echo "file-level backup/restore on $facet:${devname}"
9875 # step 1: build mount point
9876 ${rcmd} mkdir -p $mntpt
9877 # step 2: cleanup old backup
9878 ${rcmd} rm -f $metadata
9880 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9881 if [ ! -z $igif ]; then
9882 # step 3.5: rm .lustre
9883 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9885 # step 4: backup metadata
9887 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9888 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9890 ${rcmd} $UMOUNT $mntpt || return 5
9891 # step 6: reformat dev
9892 echo "reformat new device"
9893 format_mdt $(facet_number $facet)
9895 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9896 # step 8: restore metadata
9898 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9899 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9900 # step 9: remove recovery logs
9901 echo "remove recovery logs"
9902 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9903 # step 10: umount dev
9904 ${rcmd} $UMOUNT $mntpt || return 10
9905 # step 11: cleanup tmp backup
9906 ${rcmd} rm -f $metaea $metadata
9907 # step 12: reset device label - it's not virgin on
9908 ${rcmd} e2label $devname ${!svc}
9915 local devname=$(mdsdevname $(facet_number $facet))
9916 local mntpt=$(facet_mntpt brpt)
9917 local rcmd="do_facet $facet"
9918 local opts=${MDS_MOUNT_FS_OPTS}
9920 if ! ${rcmd} test -b ${devname}; then
9921 opts=$(csa_add "$opts" -o loop)
9924 echo "removing OI files on $facet: idx=${idx}"
9926 # step 1: build mount point
9927 ${rcmd} mkdir -p $mntpt
9929 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9930 if [ -z $idx ]; then
9931 # step 3: remove all OI files
9932 ${rcmd} rm -fv $mntpt/oi.16*
9933 elif [ $idx -lt 2 ]; then
9934 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9938 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9939 for ((i=${idx}; i<64; i=$((i * idx)))); do
9940 ${rcmd} rm -fv $mntpt/oi.16.${i}
9944 ${rcmd} $UMOUNT $mntpt || return 2
9945 # OI files will be recreated when mounted as lustre next time.
9948 # generate maloo upload-able log file name
9949 # \param logname specify unique part of file name
9950 generate_logname() {
9951 local logname=${1:-"default_logname"}
9953 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9956 # make directory on different MDTs
9961 local hash_name=("all_char" "fnv_1a_64" "crush")
9962 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9963 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9965 local overstripe_count
9966 local stripe_command="-c"
9968 (( $MDS1_VERSION > $(version_code v2_15_50-185-g1ac4b9598a) )) &&
9969 hash_name+=("crush2")
9971 while getopts "c:C:H:i:p" opt; do
9973 c) dirstripe_count=$OPTARG;;
9974 C) overstripe_count=$OPTARG;;
9975 H) hash_type=$OPTARG;;
9976 i) dirstripe_index=$OPTARG;;
9978 \?) error "only support -c -H -i -p";;
9982 shift $((OPTIND - 1))
9983 [ $# -eq 1 ] || error "Only creating single directory is supported"
9986 local parent=$(dirname $path)
9987 if [ "$p_option" == "-p" ]; then
9988 [ -d $path ] && return 0
9989 if [ ! -d ${parent} ]; then
9990 mkdir -p ${parent} ||
9991 error "mkdir parent '$parent' failed"
9995 if [[ -n "$overstripe_count" ]]; then
9997 dirstripe_count=$overstripe_count
10000 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
10001 mkdir $path || error "mkdir '$path' failed"
10005 if [ $dirstripe_index -eq -1 ]; then
10006 mdt_index=$((base % MDSCOUNT))
10008 mdt_index=$dirstripe_index
10011 # randomly choose hash type
10012 [ -z "$hash_type" ] &&
10013 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
10015 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
10016 if [ $dirstripe_count -eq -1 ]; then
10017 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
10023 echo "striped dir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path"
10024 $LFS mkdir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path ||
10025 error "mkdir -i $mdt_index $stripe_command$dirstripe_count -H $hash_type $path failed"
10029 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
10031 # If called many times, passing @last_fd will avoid repeated searching
10032 # already-open FDs repeatedly if we know they are still in use.
10034 # usage: free_fd [last_fd]
10037 local max_fd=$(ulimit -n)
10038 local fd=$((${1:-2} + 1))
10040 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
10043 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
10047 check_mount_and_prep()
10049 is_mounted $MOUNT || setupall
10051 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
10052 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
10053 for idx in $(seq $MDSCOUNT); do
10054 local name="MDT$(printf '%04x' $((idx - 1)))"
10055 rm -rf $MOUNT/.lustre/lost+found/$name/*
10059 # calcule how many ost-objects to be created.
10060 precreated_ost_obj_count()
10064 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
10065 local ost_name="OST$(printf '%04x' $ost_idx)"
10066 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
10067 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10068 osp.$proc_path.prealloc_last_id)
10069 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10070 osp.$proc_path.prealloc_next_id)
10071 echo $((last_id - next_id + 1))
10074 check_file_in_pool()
10079 local res=$($LFS getstripe $file | grep 0x | cut -f2)
10082 for t in $tlist ; do
10083 [ "$i" -eq "$t" ] && continue 2
10086 echo "pool list: $tlist"
10087 echo "striping: $res"
10088 error_noexit "$file not allocated in $pool"
10095 echo "Creating new pool"
10098 create_pool $FSNAME.$pool ||
10099 { error_noexit "No pool created, result code $?"; return 1; }
10100 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
10101 { error_noexit "$pool not in lfs pool_list"; return 2; }
10104 pool_add_targets() {
10105 echo "Adding targets to pool"
10108 local last=${3:-$first}
10111 local list=$(seq $first $step $last)
10113 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10114 local tg=$(for i in $list;
10115 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
10116 local firstx=$(printf "%04x" $first)
10117 local lastx=$(printf "%04x" $last)
10119 do_facet mgs $LCTL pool_add \
10120 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
10121 # ignore EEXIST(17)
10122 if (( $? != 0 && $? != 17 )); then
10123 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
10127 # wait for OSTs to be added to the pool
10128 for mds_id in $(seq $MDSCOUNT); do
10129 local mdt_id=$((mds_id-1))
10130 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10131 wait_update_facet mds$mds_id \
10132 "lctl get_param -n lod.$lodname.pools.$pool |
10133 grep $tg | sort -u | tr '\n' ' '" "$t" || {
10134 error_noexit "mds$mds_id: Add to pool failed"
10138 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
10139 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
10140 error_noexit "Add to pool failed"
10148 echo "Setting pool on directory $tdir"
10150 $LFS setstripe -c 2 -p $pool $tdir && return 0
10152 error_noexit "Cannot set pool $pool to $tdir"
10159 echo "Checking pool on directory $tdir"
10161 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
10162 [ "$res" = "$pool" ] && return 0
10164 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10168 pool_dir_rel_path() {
10169 echo "Testing relative path works well"
10174 mkdir -p $root/$tdir/$tdir
10176 pool_set_dir $pool $tdir || return 1
10177 pool_set_dir $pool ./$tdir || return 2
10178 pool_set_dir $pool ../$tdir || return 3
10179 pool_set_dir $pool ../$tdir/$tdir || return 4
10180 rm -rf $tdir; cd - > /dev/null
10183 pool_alloc_files() {
10184 echo "Checking files allocation from directory pool"
10191 for i in $(seq -w 1 $count)
10193 local file=$tdir/file-$i
10195 check_file_in_pool $file $pool "$tlist" || \
10196 failed=$((failed + 1))
10198 [ "$failed" = 0 ] && return 0
10200 error_noexit "$failed files not allocated in $pool"
10204 pool_create_files() {
10205 echo "Creating files in pool"
10213 for i in $(seq -w 1 $count)
10215 local file=$tdir/spoo-$i
10216 $LFS setstripe -p $pool $file
10217 check_file_in_pool $file $pool "$tlist" || \
10218 failed=$((failed + 1))
10220 [ "$failed" = 0 ] && return 0
10222 error_noexit "$failed files not allocated in $pool"
10227 echo "Checking 'lfs df' output"
10230 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10232 local res=$($LFS df --pool $FSNAME.$pool |
10234 grep "$FSNAME-OST" |
10236 [ "$res" = "$t" ] && return 0
10238 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10242 pool_file_rel_path() {
10243 echo "Creating files in a pool with relative pathname"
10248 { error_noexit "unable to create $tdir"; return 1 ; }
10249 local file="/..$tdir/$tfile-1"
10250 $LFS setstripe -p $pool $file ||
10251 { error_noexit "unable to create $file" ; return 2 ; }
10254 $LFS setstripe -p $pool $tfile-2 || {
10255 error_noexit "unable to create $tfile-2 in $tdir"
10260 pool_remove_first_target() {
10261 echo "Removing first target from a pool"
10262 pool_remove_target $1 -1
10265 pool_remove_target() {
10269 local pname="lov.$FSNAME-*.pools.$pool"
10270 if [ $index -eq -1 ]; then
10271 local t=$($LCTL get_param -n $pname | head -1)
10273 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
10276 echo "Removing $t from $pool"
10277 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10278 for mds_id in $(seq $MDSCOUNT); do
10279 local mdt_id=$((mds_id-1))
10280 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10281 wait_update_facet mds$mds_id \
10282 "lctl get_param -n lod.$lodname.pools.$pool |
10284 error_noexit "mds$mds_id: $t not removed from" \
10289 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10290 error_noexit "$t not removed from $FSNAME.$pool"
10295 pool_remove_all_targets() {
10296 echo "Removing all targets from pool"
10299 local pname="lov.$FSNAME-*.pools.$pool"
10300 for t in $($LCTL get_param -n $pname | sort -u)
10302 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10304 for mds_id in $(seq $MDSCOUNT); do
10305 local mdt_id=$((mds_id-1))
10306 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10307 wait_update_facet mds$mds_id "lctl get_param -n \
10308 lod.$lodname.pools.$pool" "" || {
10309 error_noexit "mds$mds_id: Pool $pool not drained"
10313 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10314 error_noexit "Pool $FSNAME.$pool cannot be drained"
10317 # striping on an empty/nonexistant pool should fall back
10318 # to "pool of everything"
10320 error_noexit "failed to use fallback striping for empty pool"
10323 # setstripe on an empty pool should fail
10324 $LFS setstripe -p $pool $file 2>/dev/null && {
10325 error_noexit "expected failure when creating file" \
10333 echo "Destroying pool"
10337 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10340 # striping on an empty/nonexistant pool should fall back
10341 # to "pool of everything"
10343 error_noexit "failed to use fallback striping for missing pool"
10346 # setstripe on an empty pool should fail
10347 $LFS setstripe -p $pool $file 2>/dev/null && {
10348 error_noexit "expected failure when creating file" \
10349 "with missing pool"
10353 # get param should return err once pool is gone
10354 if wait_update $HOSTNAME "lctl get_param -n \
10355 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10357 remove_pool_from_list $FSNAME.$pool
10360 error_noexit "Pool $FSNAME.$pool is not destroyed"
10364 # Get and check the actual stripe count of one file.
10365 # Usage: check_stripe_count <file> <expected_stripe_count>
10366 check_stripe_count() {
10371 [[ -z "$file" || -z "$expected" ]] &&
10372 error "check_stripe_count: invalid argument"
10374 local cmd="$LFS getstripe -c $file"
10375 actual=$($cmd) || error "$cmd failed"
10376 actual=${actual%% *}
10378 if [[ $actual -ne $expected ]]; then
10379 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
10380 error "$cmd not expected ($expected): found $actual"; }
10381 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
10382 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
10386 # Get and check the actual list of OST indices on one file.
10387 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
10393 [[ -z "$file" || -z "$expected" ]] &&
10394 error "check_obdidx: invalid argument!"
10396 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
10397 grep -v obdidx | awk '{print $1}' | xargs))
10399 [[ $obdidx = $expected ]] ||
10400 error "list of OST indices on $file is $obdidx," \
10401 "should be $expected"
10404 # Get and check the actual OST index of the first stripe on one file.
10405 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
10406 check_start_ost_idx() {
10409 local start_ost_idx
10411 [[ -z "$file" || -z "$expected" ]] &&
10412 error "check_start_ost_idx: invalid argument!"
10414 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
10415 grep -v obdidx | awk '{print $1}')
10417 [[ $start_ost_idx = $expected ]] ||
10418 error "OST index of the first stripe on $file is" \
10419 "$start_ost_idx, should be $expected"
10422 killall_process () {
10423 local clients=${1:-$(hostname)}
10428 do_nodes $clients "killall $signal $name"
10433 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
10436 lsnapshot_destroy()
10438 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
10443 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
10448 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
10453 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
10458 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
10465 do_facet mgs "cat $LSNAPSHOT_LOG"
10471 echo "Cleaning test environment ..."
10473 # Every lsnapshot command takes exclusive lock with others,
10474 # so can NOT destroy the snapshot during list with 'xargs'.
10476 local ssname=$(lsnapshot_list | grep snapshot_name |
10477 grep lss_ | awk '{ print $2 }' | head -n 1)
10478 [ -z "$ssname" ] && break
10480 lsnapshot_destroy -n $ssname -f ||
10481 lss_err "Fail to destroy $ssname by force"
10491 local host=$(facet_active_host $facet)
10492 local dir=$(dirname $(facet_vdevice $facet))
10493 local pool=$(zpool_name $facet)
10494 local lfsname=$(zfs_local_fsname $facet)
10495 local label=${FSNAME}-${role}$(printf '%04x' $idx)
10498 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
10504 do_facet mgs "rm -f $LSNAPSHOT_CONF"
10505 echo "Generating $LSNAPSHOT_CONF on MGS ..."
10507 if ! combined_mgs_mds ; then
10508 [ $(facet_fstype mgs) != zfs ] &&
10509 skip "Lustre snapshot 1 only works for ZFS backend"
10511 local host=$(facet_active_host mgs)
10512 local dir=$(dirname $(facet_vdevice mgs))
10513 local pool=$(zpool_name mgs)
10514 local lfsname=$(zfs_local_fsname mgs)
10517 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
10518 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
10521 for num in `seq $MDSCOUNT`; do
10522 [ $(facet_fstype mds$num) != zfs ] &&
10523 skip "Lustre snapshot 1 only works for ZFS backend"
10525 lss_gen_conf_one mds$num MDT $((num - 1)) ||
10526 lss_err "generate lss conf (mds$num)"
10529 for num in `seq $OSTCOUNT`; do
10530 [ $(facet_fstype ost$num) != zfs ] &&
10531 skip "Lustre snapshot 1 only works for ZFS backend"
10533 lss_gen_conf_one ost$num OST $((num - 1)) ||
10534 lss_err "generate lss conf (ost$num)"
10537 do_facet mgs "cat $LSNAPSHOT_CONF"
10540 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
10541 parse_plain_dir_param()
10543 local invalues=($1)
10546 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
10547 param="-c ${invalues[1]}"
10549 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
10550 param="$param -S ${invalues[3]}"
10552 if [[ ${invalues[4]} =~ "pattern:" ]]; then
10553 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
10554 param="$param -i ${invalues[6]}"
10556 param="$param -L ${invalues[5]} -i ${invalues[7]}"
10558 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
10559 param="$param -i ${invalues[5]}"
10564 parse_plain_param()
10567 local val=$(awk '{print $2}' <<< $line)
10569 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
10571 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
10573 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
10575 elif [[ $line =~ ^"lmm_pattern:" ]]; then
10580 parse_layout_param()
10586 while read line; do
10587 if [[ ! -z $line ]]; then
10588 if [[ -z $mode ]]; then
10589 if [[ $line =~ ^"stripe_count:" ]]; then
10591 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
10593 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
10598 if [[ $mode = "plain_dir" ]]; then
10599 param=$(parse_plain_dir_param "$line")
10600 elif [[ $mode = "plain_file" ]]; then
10601 val=$(parse_plain_param "$line")
10602 [[ ! -z $val ]] && param="$param $val"
10603 elif [[ $mode = "pfl" ]]; then
10604 val=$(echo $line | awk '{print $2}')
10605 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
10606 if [[ $val = "EOF" ]]; then
10607 param="$param -E -1"
10609 param="$param -E $val"
10611 elif [[ $line =~ ^"stripe_count:" ]]; then
10613 val=$(parse_plain_dir_param "$line")
10614 param="$param $val"
10617 val=$(parse_plain_param "$line")
10618 [[ ! -z $val ]] && param="$param $val"
10628 local param=$($LFS getstripe -d $1 | parse_layout_param)
10632 lfsck_verify_pfid()
10637 # Cancel locks before setting lfsck_verify_pfid so that errors are more
10639 cancel_lru_locks mdc
10640 cancel_lru_locks osc
10642 # make sure PFID is set correctly for files
10643 do_nodes $(comma_list $(osts_nodes)) \
10644 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
10647 cat $f &> /dev/nullA ||
10648 { rc=$?; echo "verify $f failed"; break; }
10651 do_nodes $(comma_list $(osts_nodes)) \
10652 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
10656 # check that clients "oscs" was evicted after "before"
10657 check_clients_evicted() {
10664 for osc in $oscs; do
10665 echo "Check state for $osc"
10666 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
10667 tail -n 5 | awk -F"[ ,]" \
10668 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
10669 if (($? == 0)) && (($evicted > $before)); then
10670 echo "$osc is evicted at $evicted"
10673 echo "$osc was not evicted after $before:"
10674 do_facet client $LCTL get_param osc.$osc.state |
10679 [ $rc -eq 0 ] || error "client not evicted from OST"
10682 # check that clients OSCS current_state is FULL
10683 check_clients_full() {
10688 for osc in $oscs; do
10689 wait_update_facet client \
10690 "lctl get_param -n osc.$osc.state |
10691 grep 'current_state: FULL'" \
10692 "current_state: FULL" $timeout
10693 [ $? -eq 0 ] || error "$osc state is not FULL"
10698 __changelog_deregister() {
10700 local mdt="$(facet_svc $facet)"
10704 # skip cleanup if no user registered for this MDT
10705 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
10706 # user is no longer registered, skip cleanup
10707 changelog_users "$facet" | grep -q "$cl_user" ||
10708 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
10710 # From this point, if any operation fails, it is an error
10711 __changelog_clear $facet $cl_user 0 ||
10712 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
10713 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
10714 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
10717 declare -Ax CL_USERS
10718 changelog_register() {
10719 for M in $(seq $MDSCOUNT); do
10721 local mdt="$(facet_svc $facet)"
10724 cl_mask=$(do_facet $facet $LCTL get_param \
10725 mdd.${mdt}.changelog_mask -n)
10726 stack_trap "do_facet $facet $LCTL \
10727 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
10728 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
10729 error "$mdt: changelog_mask=+hsm failed: $?"
10732 cl_user=$(do_facet $facet $LCTL --device $mdt \
10733 changelog_register -n "$@") ||
10734 error "$mdt: register changelog user failed: $?"
10735 stack_trap "__changelog_deregister $facet $cl_user" EXIT
10737 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
10738 # Bash does not support nested arrays, but the format of a
10739 # cl_user is constrained enough to use whitespaces as separators
10740 CL_USERS[$facet]+="$cl_user "
10742 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[*]% }'"
10745 changelog_deregister() {
10747 # bash assoc arrays do not guarantee to list keys in created order
10748 # so reorder to get same order than in changelog_register()
10749 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10752 for facet in $cl_facets; do
10753 for cl_user in ${CL_USERS[$facet]}; do
10754 __changelog_deregister $facet $cl_user || return $?
10756 unset CL_USERS[$facet]
10760 changelog_users() {
10762 local service=$(facet_svc $facet)
10764 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
10767 changelog_user_rec() {
10770 local service=$(facet_svc $facet)
10772 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
10775 changelog_chmask() {
10778 do_nodes $(comma_list $(mdts_nodes)) \
10779 $LCTL set_param mdd.*.changelog_mask="$mask"
10782 # usage: __changelog_clear FACET CL_USER [+]INDEX
10783 __changelog_clear()
10786 local mdt="$(facet_svc $facet)"
10792 # Remove the leading '+'
10794 rec+=$(changelog_user_rec $facet $cl_user)
10801 if [ $rec -eq 0 ]; then
10802 echo "$mdt: clear the changelog for $cl_user of all records"
10804 echo "$mdt: clear the changelog for $cl_user to record #$rec"
10806 $LFS changelog_clear $mdt $cl_user $rec
10809 # usage: changelog_clear [+]INDEX [facet]...
10811 # If INDEX is prefixed with '+', increment every changelog user's record index
10812 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
10814 changelog_clear() {
10818 local cl_facets="$@"
10819 # bash assoc arrays do not guarantee to list keys in created order
10820 # so reorder to get same order than in changelog_register()
10821 [[ -n "$cl_facets" ]] ||
10822 cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10826 for facet in $cl_facets; do
10827 for cl_user in ${CL_USERS[$facet]}; do
10828 __changelog_clear $facet $cl_user $idx || rc=${rc:-$?}
10838 for M in $(seq $MDSCOUNT); do
10840 local mdt="$(facet_svc $facet)"
10844 output=$($LFS changelog $mdt)
10846 if [ $ret -ne 0 ]; then
10848 elif [ -n "$output" ]; then
10849 echo "$output" | sed -e 's/^/'$mdt'./'
10856 changelog_extract_field() {
10859 local identifier=$3
10861 changelog_dump | gawk "/$cltype.*$file$/ {
10862 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10866 # Prints a changelog record produced by "lfs changelog" as an associative array
10869 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
10870 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
10871 # nid=0@lo p=[0x200000007:0x1:0x0] blob
10872 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
10873 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
10874 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
10875 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
10877 # Note that the changelog record is not quoted
10878 # Also note that the line breaks in the output were only added for readability
10880 # Typically, you want to eval the output of the command to fill an actual
10881 # associative array, like this:
10882 # $> eval declare -A changelog=$(changelog2array $entry)
10884 # It can then be accessed like any bash associative array:
10885 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
10887 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10895 # A changelog, as printed by "lfs changelog" typically looks like this:
10896 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10898 # Parse the positional part of the changelog
10900 # changelog_dump() prefixes records with their mdt's name
10901 local index="${1##*.}"
10903 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10904 "$index" "${2:2}" "$3" "$4" "$5"
10906 # Parse the key/value part of the changelog
10907 for arg in "${@:5}"; do
10908 # Check it matches a key=value syntax
10909 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10911 local key="${arg%%=*}"
10912 local value="${arg#*=}"
10916 # u is actually for uid AND gid: u=UID:GID
10917 printf " [uid]='%s'" "${value%:*}"
10919 value="${value#*:}"
10947 printf " ['%s']='%s'" "$key" "$value"
10954 # Format and print a changelog record
10956 # Interpreted sequences are:
10958 # %f the "flags" attribute of a changelog record
10959 __changelog_printf()
10964 for ((i = 0; i < ${#format}; i++)); do
10965 local char="${format:$i:1}"
10966 if [ "$char" != % ]; then
10967 printf '%c' "$char"
10972 char="${format:$i:1}"
10975 printf '%s' "${changelog[flags]}"
10985 # Filter changelog records
10989 local action='print'
10992 while [ $# -gt 0 ]; do
11003 filter[${1#-}]="$2"
11012 changelog_dump | { while read -r record; do
11013 eval local -A changelog=$(changelog2array $record)
11014 for key in "${!filter[@]}"; do
11017 [ "${changelog[$key]}" == "${filter[$key]}" ]
11024 case "${action:-print}" in
11026 printf '%s\n' "$record"
11029 __changelog_printf "$format"
11039 [ ! -d "$dir" ] && return
11041 [ -z "$layout" ] && {
11042 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
11046 setfattr -n trusted.lov -v $layout $dir ||
11047 error "error restoring layout '$layout' to '$dir'"
11050 # save the layout of a directory, the returned string will be used by
11051 # restore_layout() to restore the layout
11054 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
11055 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
11059 # save layout of a directory and restore it at exit
11060 save_layout_restore_at_exit() {
11062 local layout=$(save_layout $dir)
11064 stack_trap "restore_layout $dir $layout" EXIT
11067 verify_yaml_layout() {
11071 local msg_prefix=$4
11073 echo "getstripe --yaml $src"
11074 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
11075 echo "setstripe --yaml=$temp $dst"
11076 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
11079 local layout1=$(get_layout_param $src)
11080 local layout2=$(get_layout_param $dst)
11081 # compare their layout info
11082 [ "$layout1" == "$layout2" ] ||
11083 error "$msg_prefix $src/$dst layouts are not equal"
11086 is_project_quota_supported() {
11087 $ENABLE_PROJECT_QUOTAS || return 1
11088 [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
11089 local save_project_supported=1
11091 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
11092 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
11093 do_facet mds1 lfs --list-commands |& grep -q project &&
11094 save_project_supported=0
11096 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
11097 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
11098 do_facet mds1 $ZPOOL get all | grep -q project_quota &&
11099 save_project_supported=0
11101 # cache state of project quotas once instead of re-checking each time
11102 export SAVE_PROJECT_SUPPORTED=$save_project_supported
11103 echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
11105 return $save_project_supported
11108 # ZFS project quota enable/disable:
11109 # This feature will become active as soon as it is enabled and will never
11110 # return to being disabled. Each filesystem will be upgraded automatically
11111 # when remounted or when [a] new file is created under that filesystem. The
11112 # upgrade can also be triggered on filesystems via `zfs set version=current
11113 # <pool/fs>`. The upgrade process runs in the background and may take a
11114 # while to complete for the filesystems containing a large number of files.
11115 enable_project_quota() {
11116 is_project_quota_supported || return 0
11117 local zkeeper=${KEEP_ZPOOL}
11118 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
11120 stopall || error "failed to stopall (1)"
11122 local zfeat_en="feature@project_quota=enabled"
11123 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
11124 local facet_fstype=${facet:0:3}1_FSTYPE
11127 if [ "${!facet_fstype}" = "zfs" ]; then
11128 devname=$(zpool_name ${facet})
11129 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
11130 error "$ZPOOL set $zfeat_en $devname"
11132 [ ${facet:0:3} == "mds" ] &&
11133 devname=$(mdsdevname ${facet:3}) ||
11134 devname=$(ostdevname ${facet:3})
11135 do_facet ${facet} $TUNE2FS -O project $devname ||
11136 error "tune2fs $devname failed"
11140 KEEP_ZPOOL="${zkeeper}"
11145 disable_project_quota() {
11146 is_project_quota_supported || return 0
11147 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
11148 stopall || error "failed to stopall (1)"
11150 for num in $(seq $MDSCOUNT); do
11151 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
11152 error "tune2fs $(mdsdevname $num) failed"
11155 for num in $(seq $OSTCOUNT); do
11156 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
11157 error "tune2fs $(ostdevname $num) failed"
11165 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
11166 # the following associated variables are added:
11168 # AGTCOUNT: number of agents
11169 # AGTDEV{N}: target HSM mount point (root path of the backend)
11170 # agt{N}_HOST: hostname of the agent agt{N}
11171 # SINGLEAGT: facet of the single agent
11173 # The number of agents is initialized as the number of remote client nodes.
11174 # By default, only single copytool is started on a remote client/agent. If there
11175 # was no remote client, then the copytool will be started on the local client.
11181 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
11182 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
11184 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
11185 if [[ $CLIENTCOUNT -gt 1 ]] &&
11186 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
11187 skip_env "SHARED_DIRECTORY should be accessible"\
11188 "on all client nodes"
11192 # We used to put the HSM archive in $SHARED_DIRECTORY but that
11193 # meant NFS issues could hose sanity-hsm sessions. So now we
11194 # use $TMP instead.
11195 for n in $(seq $AGTCOUNT); do
11196 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
11197 agent=CLIENT$((n + 1))
11198 if [[ -z "${!agent}" ]]; then
11199 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
11202 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
11203 local var=agt${n}_HOST
11204 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
11207 export SINGLEAGT=${SINGLEAGT:-agt1}
11209 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
11210 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
11211 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
11212 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
11213 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
11214 export HSMTOOL_TESTDIR
11215 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
11217 if ! [[ $HSMTOOL =~ hsmtool ]]; then
11218 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
11221 HSM_ARCHIVE_NUMBER=2
11223 # The test only support up to 10 MDTs
11224 MDT_PREFIX="mdt.$FSNAME-MDT000"
11225 HSM_PARAM="${MDT_PREFIX}0.hsm"
11227 # archive is purged at copytool setup
11228 HSM_ARCHIVE_PURGE=true
11230 # Don't allow copytool error upon start/setup
11231 HSMTOOL_NOERROR=false
11234 # Get the backend root path for the given agent facet.
11235 copytool_device() {
11237 local dev=AGTDEV$(facet_number $facet)
11242 get_mdt_devices() {
11244 # get MDT device for each mdc
11245 for mdtno in $(seq 1 $MDSCOUNT); do
11246 local idx=$(($mdtno - 1))
11247 MDT[$idx]=$($LCTL get_param -n \
11248 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
11249 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
11253 pkill_copytools() {
11257 do_nodes "$hosts" \
11258 "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
11261 copytool_continue() {
11262 local agents=${1:-$(facet_active_host $SINGLEAGT)}
11264 pkill_copytools "$agents" CONT || return 0
11265 echo "Copytool is continued on $agents"
11269 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
11271 echo "Killing existing copytools on $hosts"
11272 pkill_copytools "$hosts" TERM || return 0
11273 copytool_continue "$hosts"
11276 copytool_monitor_cleanup() {
11277 local facet=${1:-$SINGLEAGT}
11278 local agent=$(facet_active_host $facet)
11280 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
11281 # Should die when the copytool dies, but just in case.
11282 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
11283 cmd+=" 2>/dev/null || true"
11284 do_node $agent "$cmd"
11285 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
11286 export HSMTOOL_MONITOR_DIR=
11289 # The pdsh should die on its own when the monitor dies. Just
11290 # in case, though, try to clean up to avoid any cruft.
11291 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
11292 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
11293 export HSMTOOL_MONITOR_PDSH=
11299 local host="$(facet_host "$1")"
11300 local prefix=$TESTLOG_PREFIX
11301 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
11303 printf "${prefix}.copytool${archive_id}_log.${host}.log"
11306 __lhsmtool_rebind()
11308 do_facet $facet $HSMTOOL \
11309 "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
11312 __lhsmtool_import()
11314 mkdir -p "$(dirname "$2")" ||
11315 error "cannot create directory '$(dirname "$2")'"
11316 do_facet $facet $HSMTOOL \
11317 "${hsmtool_options[@]}" --import "$@" "$mountpoint"
11322 local host="$(facet_host "$facet")"
11323 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
11325 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
11326 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
11327 # [ ${#misc_options[@]} -gt 0 ] &&
11328 # cmd+=" $(IFS=" " echo "$@")"
11329 cmd+=" $@ \"$mountpoint\""
11331 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
11332 stack_trap "pkill_copytools $host TERM || true" EXIT
11333 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
11337 local facet="${1:-$SINGLEAGT}"
11339 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
11342 # Main entry point to perform copytool related operations
11346 # setup setup a copytool to run in the background, that copytool will be
11348 # import import a file from an HSM backend
11349 # rebind rebind an archived file to a new fid
11351 # Although the semantics might suggest otherwise, one does not need to 'setup'
11352 # a copytool before a call to 'copytool import' or 'copytool rebind'.
11359 # Use default values
11360 local facet=$SINGLEAGT
11361 local mountpoint="${MOUNT2:-$MOUNT}"
11364 local fail_on_error=true
11365 local -a hsmtool_options=()
11366 local -a action_options=()
11368 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
11369 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
11372 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
11373 hsmtool_options+=("$HSMTOOL_VERBOSE")
11376 while [ $# -gt 0 ]; do
11388 local archive_id="$1"
11392 local hsm_root="$1"
11396 local bandwidth="$1" # in MB/s
11399 local fail_on_error=false
11402 # Uncommon(/copytool dependent) option
11403 action_options+=("$1")
11409 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
11410 hsmtool_options+=("--hsm-root=$hsm_root")
11412 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
11413 do_facet $facet mkdir -p "$hsm_root" ||
11414 error "mkdir '$hsm_root' failed"
11418 local copytool=lhsmtool
11422 __${copytool}_${action} "${action_options[@]}"
11423 if [ $? -ne 0 ]; then
11428 local host="$(facet_host $facet)"
11429 error_msg="Failed to start copytool $facet on '$host'"
11432 local src="${action_options[0]}"
11433 local dest="${action_options[1]}"
11434 error_msg="Failed to import '$src' to '$dest'"
11437 error_msg="could not rebind file"
11441 $fail_on_error && error "$error_msg" || echo "$error_msg"
11446 local client_count=$1
11447 if [[ $CLIENTCOUNT -lt $client_count ]]; then
11448 skip "Need $client_count or more clients, have $CLIENTCOUNT"
11455 $LFS path2fid $1 | tr -d '[]'
11456 return ${PIPESTATUS[0]}
11464 if [[ $u == "user" ]]; then
11465 st=$($RUNAS $LFS hsm_state $f)
11468 st=$($LFS hsm_state $f)
11471 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
11473 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
11477 check_hsm_flags() {
11481 local st=$(get_hsm_flags $f)
11482 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
11491 if [[ "$value" != "" ]]; then
11494 for mdtno in $(seq 1 $MDSCOUNT); do
11495 local idx=$(($mdtno - 1))
11496 local facet=mds${mdtno}
11497 # if $arg include -P option, run 1 set_param per MDT on the MGS
11498 # else, run set_param on each MDT
11499 [[ $arg = *"-P"* ]] && facet=mgs
11500 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
11501 [[ $? != 0 ]] && rc=1
11506 mdts_check_param() {
11512 for mdtno in $(seq 1 $MDSCOUNT); do
11513 local idx=$(($mdtno - 1))
11514 wait_update_facet --verbose mds${mdtno} \
11515 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
11517 error "$key state is not '$target' on mds${mdtno}"
11521 cdt_set_mount_state() {
11522 mdts_set_param "-P" hsm_control "$1"
11523 # set_param -P is asynchronous operation and could race with set_param.
11524 # In such case configs could be retrieved and applied at mgc after
11525 # set_param -P completion. Sleep here to avoid race with set_param.
11526 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
11527 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
11528 # and 10 seconds to retrieve config from server.
11532 cdt_check_state() {
11533 mdts_check_param hsm_control "$1" 20
11536 cdt_set_sanity_policy() {
11537 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
11540 mdts_set_param "" hsm.policy "+NRA"
11541 mdts_set_param "" hsm.policy "-NBR"
11542 CDT_POLICY_HAD_CHANGED=
11550 mdts_set_param "$opt -n" "hsm.$param" "$value"
11554 wait_request_state() {
11558 # 4th arg (mdt index) is optional
11559 local mdtidx=${4:-0}
11560 local mds=mds$(($mdtidx + 1))
11562 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
11563 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
11565 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
11566 error "request on $fid is not $state on $mds"
11574 local WAIT_MAX=${4:-60}
11577 # We need to run do_node in bg, because pdsh does not exit
11578 # if child process of run script exists.
11579 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
11580 # because of multiop_bg_pause -> $MULTIOP_PROG &
11581 # By the same reason we need sleep a bit after do_nodes starts
11582 # to let runmultiop_bg_pause start muliop and
11583 # update /tmp/multiop_bg.pid ;
11584 # The rm /tmp/multiop_bg.pid guarantees here that
11585 # we have the updated by runmultiop_bg_pause
11586 # /tmp/multiop_bg.pid file
11588 local pid_file=$TMP/multiop_bg.pid.$$
11590 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
11591 runmultiop_bg_pause $file $cmds" &
11595 while [[ $wait_time -lt $WAIT_MAX ]]; do
11597 wait_time=$((wait_time + 3))
11598 multiop_pid=$(do_node $client cat $pid_file)
11599 if [ -n "$multiop_pid" ]; then
11604 [ -n "$multiop_pid" ] ||
11605 error "$client : Can not get multiop_pid from $pid_file "
11607 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
11608 eval export $(node_var_name $client)_do_node_pid=$pid
11609 local var=$(node_var_name $client)_multiop_pid
11610 echo client $client multiop_bg started multiop_pid=${!var}
11616 local multiop_pid=$(node_var_name $client)_multiop_pid
11617 local do_node_pid=$(node_var_name $client)_do_node_pid
11619 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
11620 do_node $client kill -USR1 ${!multiop_pid}
11622 wait ${!do_node_pid}
11626 local delay=$(do_facet mds1 lctl get_param -n lod.*.qos_maxage |
11627 awk '{ print $1 + 5; exit; }')
11631 sleep_maxage_lmv() {
11632 local delay=$(lctl get_param -n lmv.*.qos_maxage |
11633 awk '{ print $1 + 5; exit; }')
11637 check_component_count() {
11638 local comp_cnt=$($LFS getstripe --component-count $1)
11639 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
11642 # Verify there are no init components with "extension" flag
11643 verify_no_init_extension() {
11644 local flg_opts="--component-flags init,extension"
11645 local found=$($LFS find $flg_opts $1 | wc -l)
11646 [ $found -eq 0 ] || error "$1 has component with initialized extension"
11649 # Verify there is at least one component starting at 0
11650 verify_comp_at_zero() {
11651 flg_opts="--component-flags init"
11652 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
11653 [ $found -eq 1 ] ||
11654 error "No component starting at zero(!)"
11657 # version after which Self-Extending Layouts are available
11660 sel_layout_sanity() {
11664 verify_no_init_extension $file
11665 verify_comp_at_zero $file
11666 check_component_count $file $comp_cnt
11669 statx_supported() {
11670 $STATX --quiet --version
11674 # lfs rm_entry is disabled on native client
11675 is_rmentry_supported() {
11676 $LFS rm_entry $DIR/dir/not/exists > /dev/null
11677 # is return code ENOENT?
11682 # wrappers for createmany and unlinkmany
11683 # to set debug=0 if number of creates is high enough
11684 # this is to speedup testing
11686 function createmany() {
11690 if (( count > 100 )); then
11692 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11694 $LUSTRE/tests/createmany $*
11696 debugrestore > /dev/null
11701 function unlinkmany() {
11705 if (( count > 100 )); then
11707 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11709 $LUSTRE/tests/unlinkmany $*
11711 debugrestore > /dev/null
11716 # Check if fallocate on facet is working. Returns fallocate mode if enabled.
11717 # Takes optional facet name as argument, to allow separate MDS/OSS checks.
11718 function check_fallocate_supported()
11720 local facet=${1:-ost1}
11721 local supported="FALLOCATE_SUPPORTED_$facet"
11722 local fstype="${facet}_FSTYPE"
11724 if [[ -n "${!supported}" ]]; then
11725 echo "${!supported}"
11728 if [[ -z "${!fstype}" ]]; then
11729 eval export $fstype=$(facet_fstype $facet)
11731 if [[ "${!fstype}" != "ldiskfs" ]]; then
11732 echo "fallocate on ${!fstype} doesn't consume space" 1>&2
11736 local fa_mode="osd-ldiskfs.$(facet_svc $facet).fallocate_zero_blocks"
11737 local mode=$(do_facet $facet $LCTL get_param -n $fa_mode 2>/dev/null |
11740 if [[ -z "$mode" ]]; then
11741 echo "fallocate not supported on $facet" 1>&2
11744 eval export $supported="$mode"
11750 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable.
11751 # Takes optional facet name as argument.
11752 function check_fallocate_or_skip()
11756 check_fallocate_supported $1 || skip "fallocate not supported"
11759 # Check if fallocate supported on OSTs, enable if unset, default mode=0
11760 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
11761 function check_set_fallocate()
11763 local new_mode="$1"
11764 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
11765 local old_mode="$(check_fallocate_supported)"
11767 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
11768 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
11769 { echo "keep default fallocate mode: $old_mode"; return 0; }
11770 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
11771 { echo "keep current fallocate mode: $old_mode"; return 0; }
11772 local osts=$(comma_list $(osts_nodes))
11774 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
11775 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
11776 error "set $fa_mode=$new_mode"
11779 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
11780 function check_set_fallocate_or_skip()
11782 check_set_fallocate || skip "need >= 2.13.57 and ldiskfs for fallocate"
11785 function disable_opencache()
11787 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" |
11790 test -z "${saved_OPENCACHE_value}" &&
11791 export saved_OPENCACHE_value="$state"
11793 [[ "$state" = "off" ]] && return
11795 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
11798 function set_opencache()
11800 local newvalue="$1"
11801 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
11803 [[ -n "$newvalue" ]] || return
11805 [[ -n "${saved_OPENCACHE_value}" ]] ||
11806 export saved_OPENCACHE_value="$state"
11808 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
11813 function restore_opencache()
11815 [[ -z "${saved_OPENCACHE_value}" ]] ||
11816 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
11819 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
11820 # created on MDT0, use this function to create directory on specific MDT
11821 # explicitly, and set default LMV to create subdirs on the same MDT too.
11826 while getopts "i:" opt $*; do
11832 shift $((OPTIND - 1))
11834 $LFS mkdir -i $mdt -c 1 $*
11838 mkdir_on_mdt -i0 $*
11841 # Wait for nodemap synchronization
11843 local nodemap_name=$1
11848 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
11849 local max_retries=20
11853 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
11856 if [ "$nodemap_name" == "active" ]; then
11857 proc_param="active"
11858 elif [ -z "$key" ]; then
11859 proc_param=${nodemap_name}
11861 proc_param="${nodemap_name}.${key}"
11863 if [ "$opt" == "inactive" ]; then
11864 # check nm sync even if nodemap is not activated
11868 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
11870 if [ -z "$value" ]; then
11871 out1=$(do_facet mgs $LCTL get_param $opt \
11872 nodemap.${proc_param} 2>/dev/null)
11873 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
11878 # if servers run on the same node, it is impossible to tell if they get
11879 # synced with the mgs, so just wait an arbitrary 10 seconds
11880 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
11881 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
11882 echo "waiting 10 secs for sync"
11887 # wait up to 10 seconds for other servers to sync with mgs
11888 for i in $(seq 1 10); do
11889 for node in $(all_server_nodes); do
11890 local node_ip=$(host_nids_address $node $NETTYPE |
11894 if [ -z "$value" ]; then
11895 [ $node_ip == $mgs_ip ] && continue
11898 out2=$(do_node $node $LCTL get_param $opt \
11899 nodemap.$proc_param 2>/dev/null)
11900 echo "On $node ${node_ip}, ${proc_param} = $out2"
11901 [ "$out1" != "$out2" ] && is_sync=false && break
11906 if ! $is_sync; then
11909 echo OTHER - IP: $node_ip
11911 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
11913 echo "waited $((i - 1)) seconds for sync"
11916 consume_precreations() {
11920 local extra=${4:-2}
11921 local OST=$(ostname_from_index $OSTIDX $dir)
11923 mkdir_on_mdt -i $(facet_index $mfacet) $dir/${OST}
11924 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
11927 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11928 local last_id=$(do_facet $mfacet $LCTL get_param -n \
11929 osp.$mdtosc_proc.prealloc_last_id)
11930 local next_id=$(do_facet $mfacet $LCTL get_param -n \
11931 osp.$mdtosc_proc.prealloc_next_id)
11932 echo "Creating to objid $last_id on ost $OST..."
11933 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
11936 __exhaust_precreations() {
11939 local FAILIDX=${3:-$OSTIDX}
11940 local ofacet=ost$((OSTIDX + 1))
11942 mkdir_on_mdt0 $DIR/$tdir
11943 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
11944 local mfacet=mds$((mdtidx + 1))
11945 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
11947 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
11948 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11950 #define OBD_FAIL_OST_ENOSPC 0x215
11951 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
11953 consume_precreations $DIR/$tdir $mfacet $OSTIDX
11955 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11956 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11959 exhaust_precreations() {
11960 __exhaust_precreations $1 $2 $3
11964 exhaust_all_precreations() {
11966 for (( i=0; i < OSTCOUNT; i++ )) ; do
11967 __exhaust_precreations $i $1 -1
11972 force_new_seq_ost() {
11976 local OST=$(ostname_from_index $OSTIDX)
11977 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11979 do_facet $mfacet $LCTL set_param \
11980 osp.$mdtosc_proc.prealloc_force_new_seq=1
11981 # consume preallocated objects, to wake up precreate thread
11982 consume_precreations $dir $mfacet $OSTIDX
11983 do_facet $mfacet $LCTL set_param \
11984 osp.$mdtosc_proc.prealloc_force_new_seq=0
11989 local MDTIDX=$(facet_index $mfacet)
11990 local MDT=$(mdtname_from_index $MDTIDX $DIR)
11993 mkdir_on_mdt -i $MDTIDX $DIR/${MDT}
11994 for (( i=0; i < OSTCOUNT; i++ )) ; do
11995 force_new_seq_ost $DIR/${MDT} $mfacet $i &
12001 force_new_seq_all() {
12004 for (( i=0; i < MDSCOUNT; i++ )) ; do
12005 force_new_seq mds$((i + 1)) &
12011 ost_set_temp_seq_width_all() {
12012 local osts=$(comma_list $(osts_nodes))
12013 local width=$(do_facet ost1 $LCTL get_param -n seq.*OST0000-super.width)
12015 do_nodes $osts $LCTL set_param seq.*OST*-super.width=$1
12016 stack_trap "do_nodes $osts $LCTL set_param seq.*OST*-super.width=$width"
12019 verify_yaml_available() {
12020 python3 -c "import yaml; yaml.safe_load('''a: b''')"
12024 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"
12027 verify_compare_yaml() {
12028 python3 -c "import sys, yaml; f=open(\"$1\", \"r\"); obj1 = yaml.safe_load(f); f=open(\"$2\", \"r\"); obj2 = yaml.safe_load(f); sys.exit(obj1 != obj2)"
12031 zfs_or_rotational() {
12033 local ost_name=$(ostname_from_index $ost_idx $MOUNT)
12034 local param="get_param -n osd-*.${ost_name}.nonrotational"
12035 local nonrotat=$(do_facet ost1 $LCTL $param)
12037 if [[ -z "$nonrotat" ]]; then
12038 # At this point there is no point moving ahead.
12039 # Will stop here and dump all the info
12041 local ost_name=$(ostname_from_index $ost_idx)
12043 error "$LCTL $input_str"
12046 if [[ "$ost1_FSTYPE" == "zfs" ]] || (( "$nonrotat" == 0 )); then