3 if ! $FRAMEWORK_NEEDS_INIT; then
6 FRAMEWORK_NEEDS_INIT=false
8 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
9 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
13 export REFORMAT=${REFORMAT:-""}
14 export WRITECONF=${WRITECONF:-""}
15 export VERBOSE=${VERBOSE:-false}
16 export GSS=${GSS:-false}
17 export GSS_SK=${GSS_SK:-false}
19 export SHARED_KEY=${SHARED_KEY:-false}
20 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
21 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
22 export SK_MOUNTED=${SK_MOUNTED:-false}
23 export SK_FLAVOR=${SK_FLAVOR:-ski}
24 export SK_NO_KEY=${SK_NO_KEY:-true}
25 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
26 export SK_S2S=${SK_S2S:-false}
27 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
28 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
29 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
30 # whether identity upcall is enabled (true), disabled (false), or default
31 export IDENTITY_UPCALL=${IDENTITY_UPCALL:-default}
33 export FLAKEY=${FLAKEY:-true}
34 # specify environment variable containing batch job name for server statistics
35 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
37 #export PDSH="pdsh -S -Rssh -w"
38 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
39 export UMOUNT=${UMOUNT:-"umount -d"}
41 # A switch to enable kptr less restrictively
42 export KPTR_ON_MOUNT=${KPTR_ON_MOUNT:-true}
44 export LSNAPSHOT_CONF="/etc/ldev.conf"
45 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
47 export DATA_SEQ_MAX_WIDTH=0x1ffffff
49 # sles12 umount has a issue with -d option
50 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
51 export UMOUNT="umount"
54 # function used by scripts run on remote nodes
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 . $LUSTRE/tests/functions.sh
57 . $LUSTRE/tests/yaml.sh
59 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
61 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
63 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
65 if [ -f "$EXCEPT_LIST_FILE" ]; then
66 echo "Reading test skip list from $EXCEPT_LIST_FILE"
71 # check config files for options in decreasing order of preference
72 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
73 MODPROBECONF=/etc/modprobe.d/lustre.conf
74 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
75 MODPROBECONF=/etc/modprobe.d/Lustre
76 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
77 MODPROBECONF=/etc/modprobe.conf
79 sanitize_parameters() {
80 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
84 if [ -d "$path" ]; then
85 eval export $i=$(echo $path | sed -r 's/\/+$//g')
91 [[ $DIR/ = $MOUNT/* ]] ||
92 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
93 [[ $DIR1/ = $MOUNT1/* ]] ||
94 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
95 [[ $DIR2/ = $MOUNT2/* ]] ||
96 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
98 [ -n "$failed" ] && exit 99 || true
102 echo "usage: $0 [-r] [-f cfgfile]"
110 [ -z "$DEFAULT_SUITES" ] && return 0
111 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
113 local form="%-13s %-17s %-9s %s %s\n"
115 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
116 echo "---------------------------------------------------------------"
117 for O in $DEFAULT_SUITES; do
118 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
119 [ "${!O}" = "no" ] && continue || true
120 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
121 local log=${TMP}/${o}.log
123 if is_sanity_benchmark $o; then
124 log=${TMP}/sanity-benchmark.log
129 local status=Unfinished
132 skipped=$(grep excluded $log |
133 awk '{ printf " %s", $3 }' | sed 's/test_//g')
134 slow=$(egrep "^PASS|^FAIL" $log |
135 tr -d "("| sed s/s\)$//g | sort -nr -k 3 |
136 head -n5 | awk '{ print $2":"$3"s" }')
137 total=$(grep duration $log | awk '{ print $2 }')
138 if [ "${!O}" = "done" ]; then
142 local durations=$(egrep "^PASS|^FAIL" $log |
143 tr -d "("| sed s/s\)$//g |
144 awk '{ print $2":"$3"|" }')
145 details=$(printf "%s\n%s %s %s\n" "$details" \
146 "DDETAILS" "$O" "$(echo $durations)")
149 printf "$form" $status "$O" "${total}" "E=$skipped"
150 printf "$form" "-" "-" "-" "S=$(echo $slow)"
153 for O in $DEFAULT_SUITES; do
154 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
155 if [ "${!O}" = "no" ]; then
156 printf "$form" "Skipped" "$O" ""
160 # print the detailed tests durations if DDETAILS=true
174 ! ${do_setup} && return
175 nfs_client_mode && return
178 local MOUNTED=$(mounted_lustre_filesystems)
180 if $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
181 check_config_clients $MOUNT
187 echo "Lustre is not mounted, trying to do setup ... "
188 $reformat && CLEANUP_DM_DEV=true formatall
191 MOUNTED=$(mounted_lustre_filesystems)
192 if ! $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
193 echo "Lustre is not mounted after setup! "
199 cleanup_if_needed() {
200 if $AUSTER_CLEANUP; then
205 find_script_in_path() {
208 for dir in $(tr : " " <<< $path); do
209 if [ -f $dir/$target ]; then
213 if [ -f $dir/$target.sh ]; then
222 log "-----============= acceptance-small: "$*" ============----- `date`"
227 printf "Would have run: %s\n" "$*"
231 printf "Running: %s\n" "$*"
239 local suite_script=$2
247 local start_ts=$(date +%s)
249 doit $script_lang $suite_script
252 local duration=$(($(date +%s) - $start_ts))
255 if [[ $rc -ne 0 || -f $TF_FAIL ]]; then
257 elif [[ -f $TF_SKIP ]]; then
260 log_test_status $duration $status
261 [[ ! -f $TF_SKIP ]] || rm -f $TF_SKIP
263 # got STOP_NOW_RC, return immediately before reset
264 [[ $rc -eq $STOP_NOW_RC ]] &&
265 echo "stop testing on rc $STOP_NOW_RC" &&
274 local suite_name=${1%.sh}
275 local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
277 suite_script=$(find_script_in_path $suite_name $LUSTRE/tests)
279 if [[ -z $suite_script ]]; then
280 echo "Can't find test script for $suite_name"
284 echo "run_suite $suite_name $suite_script"
286 local log_name=${suite_name}.suite_log.$(hostname -s).log
289 run_suite $suite_name $suite_script 2>&1 |tee $LOGDIR/$log_name
291 run_suite $suite_name $suite_script > $LOGDIR/$log_name 2>&1
294 return ${PIPESTATUS[0]}
312 while ((n < repeat_count)); do
314 local logdir=${test_logs_dir}
315 local first_suite=$FIRST_SUITE
317 ((repeat_count > 1)) && logdir="$logdir/$n"
318 reset_logging $logdir
320 while [[ -n $1 ]]; do
321 unset ONLY EXCEPT START_AT STOP_AT
327 while [[ -n $1 ]]; do
331 export ONLY=$(split_commas $1)
333 opts+="ONLY=$ONLY ";;
336 export SUITE=$(split_commas $1)
338 opts+="SUITE=$SUITE ";;
341 export PATTERN=$(split_commas $1)
343 opts+="PATTERN=$PATTERN ";;
346 export EXCEPT=$(split_commas $1)
348 opts+="EXCEPT=$EXCEPT ";;
353 opts+="START_AT=$START_AT ";;
358 opts+="STOP_AT=$STOP_AT ";;
361 export STOP_ON_ERROR=$(split_commas $1)
363 opts+="STOP_ON_ERROR=$STOP_ON_ERROR ";;
373 # If first_suite not set or this is the first suite
374 if [ "x"$first_suite == "x" ] || [ $first_suite == $suite ]; then
375 echo "running: $suite $opts"
376 run_suite_logged $suite || RC=$?
378 echo $suite returned $RC
380 # stop testing immediately if rc is STOP_NOW_RC
381 [[ $RC -eq $STOP_NOW_RC ]] && exit $STOP_NOW_RC
384 if $upload_logs; then
385 $upload_script $LOGDIR
391 # Get information about the Lustre environment. The information collected
392 # will be used in Lustre tests.
393 # usage: get_lustre_env
394 # input: No required or optional arguments
395 # output: No return values, environment variables are exported
399 export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
400 export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
402 export MGS_VERSION=$(lustre_version_code mgs)
403 export MDS1_VERSION=$(lustre_version_code mds1)
404 export OST1_VERSION=$(lustre_version_code ost1)
405 export CLIENT_VERSION=$(lustre_version_code client)
407 # import server-side version information into local variables
408 # so they can be used in tests instead of checked separately
409 # MGS_OS_VERSION_ID, MGS_OS_ID, MGS_OS_ID_LIKE,
410 # MDS1_OS_VERSION_ID, MDS1_OS_ID, MDS1_OS_ID_LIKE,
411 # OST1_OS_VERSION_ID, OST1_OS_ID, OST1_OS_ID_LIKE,
412 # CLIENT_OS_VERSION_ID, CLIENT_OS_ID, CLIENT_OS_ID_LIKE
413 lustre_os_release mgs
414 lustre_os_release mds1
415 lustre_os_release ost1
416 lustre_os_release client
419 # Prefer using "mds1" directly instead of SINGLEMDS.
420 # Keep this for compat until it is removed from scripts.
421 export SINGLEMDS=${SINGLEMDS:-mds1}
425 export LUSTRE=$(absolute_path $LUSTRE)
426 export TESTSUITE=$(basename $0 .sh)
427 export TEST_FAILED=false
428 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
429 export RPC_MODE=${RPC_MODE:-false}
430 export DO_CLEANUP=${DO_CLEANUP:-true}
431 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
432 export CLEANUP_DM_DEV=false
433 export PAGE_SIZE=$(get_page_size client)
434 export NAME=${NAME:-local}
436 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
438 export MKE2FS=$MKE2FS
439 if [ -z "$MKE2FS" ]; then
440 if which mkfs.ldiskfs >/dev/null 2>&1; then
441 export MKE2FS=mkfs.ldiskfs
447 export DEBUGFS=$DEBUGFS
448 if [ -z "$DEBUGFS" ]; then
449 if which debugfs.ldiskfs >/dev/null 2>&1; then
450 export DEBUGFS=debugfs.ldiskfs
452 export DEBUGFS=debugfs
456 export TUNE2FS=$TUNE2FS
457 if [ -z "$TUNE2FS" ]; then
458 if which tunefs.ldiskfs >/dev/null 2>&1; then
459 export TUNE2FS=tunefs.ldiskfs
461 export TUNE2FS=tune2fs
465 export E2LABEL=$E2LABEL
466 if [ -z "$E2LABEL" ]; then
467 if which label.ldiskfs >/dev/null 2>&1; then
468 export E2LABEL=label.ldiskfs
470 export E2LABEL=e2label
474 export DUMPE2FS=$DUMPE2FS
475 if [ -z "$DUMPE2FS" ]; then
476 if which dumpfs.ldiskfs >/dev/null 2>&1; then
477 export DUMPE2FS=dumpfs.ldiskfs
479 export DUMPE2FS=dumpe2fs
483 export E2FSCK=$E2FSCK
484 if [ -z "$E2FSCK" ]; then
485 if which fsck.ldiskfs >/dev/null 2>&1; then
486 export E2FSCK=fsck.ldiskfs
492 export RESIZE2FS=$RESIZE2FS
493 if [ -z "$RESIZE2FS" ]; then
494 if which resizefs.ldiskfs >/dev/null 2>&1; then
495 export RESIZE2FS=resizefs.ldiskfs
497 export RESIZE2FS=resize2fs
501 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
502 export FSCK_MAX_ERR=4 # File system errors left uncorrected
504 export ZFS=${ZFS:-zfs}
505 export ZPOOL=${ZPOOL:-zpool}
506 export ZDB=${ZDB:-zdb}
507 export PARTPROBE=${PARTPROBE:-partprobe}
509 #[ -d /r ] && export ROOT=${ROOT:-/r}
510 export TMP=${TMP:-$ROOT/tmp}
511 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
512 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
513 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
515 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
516 if ! echo $PATH | grep -q $LUSTRE/utils; then
517 export PATH=$LUSTRE/utils:$PATH
519 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
520 export PATH=$LUSTRE/utils/gss:$PATH
522 if ! echo $PATH | grep -q $LUSTRE/tests; then
523 export PATH=$LUSTRE/tests:$PATH
525 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
526 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
528 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
529 [ ! -f "$LST" ] && export LST=$(which lst)
530 export LSTSH=${LSTSH:-"$LUSTRE/../lustre-iokit/lst-survey/lst.sh"}
531 [ ! -f "$LSTSH" ] && export LSTSH=$(which lst.sh)
532 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
533 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
534 export MCREATE=${MCREATE:-mcreate}
535 export MULTIOP=${MULTIOP:-multiop}
536 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
537 export STATX=${STATX:-statx}
538 # Ubuntu, at least, has a truncate command in /usr/bin
539 # so fully path our truncate command.
540 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
541 export FSX=${FSX:-$LUSTRE/tests/fsx}
542 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
543 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
544 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
545 export PATH=$LUSTRE/tests/racer:$PATH:
547 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
548 export PATH=$LUSTRE/tests/mpi:$PATH
551 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
552 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
553 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
554 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
555 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
556 [ ! -f "$LFS" ] && export LFS=$(which lfs)
557 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
558 [ ! -f "$KSOCKLND_CONFIG" ] &&
559 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
560 export LNET_SYSCTL_CONFIG=${LNET_SYSCTL_CONFIG:-"$LUSTRE/scripts/lnet-sysctl-config"}
561 [ ! -f "$LNET_SYSCTL_CONFIG" ] &&
562 export LNET_SYSCTL_CONFIG=$(which lnet-sysctl-config 2> /dev/null)
564 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
566 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
567 if [ ! -x "$L_GETIDENTITY" ]; then
568 if $(which l_getidentity > /dev/null 2>&1); then
569 export L_GETIDENTITY=$(which l_getidentity)
571 export L_GETIDENTITY=NONE
574 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
575 [ ! -f "$LL_DECODE_FILTER_FID" ] &&
576 export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
577 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
578 [ ! -f "$LL_DECODE_LINKEA" ] &&
579 export LL_DECODE_LINKEA="ll_decode_linkea"
580 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
581 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
582 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
583 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
584 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
585 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
586 [ ! -f "$LUSTRE_RMMOD" ] &&
587 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
588 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
589 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
590 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
591 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
592 [ ! -f "$LFS_MIGRATE" ] &&
593 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
594 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
595 [ ! -f "$LR_READER" ] &&
596 export LR_READER=$(which lr_reader 2> /dev/null)
597 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
598 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
599 [ ! -f "$LSOM_SYNC" ] &&
600 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
601 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
602 export L_GETAUTH=${L_GETAUTH:-"$LUSTRE/utils/gss/l_getauth"}
603 [ ! -f "$L_GETAUTH" ] && export L_GETAUTH=$(which l_getauth 2> /dev/null)
604 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
605 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
606 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
608 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
610 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
611 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
613 export DMSETUP=${DMSETUP:-dmsetup}
614 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
615 export LOSETUP=${LOSETUP:-losetup}
617 if [ "$ACCEPTOR_PORT" ]; then
618 export PORT_OPT="--port $ACCEPTOR_PORT"
622 $RPC_MODE || echo "Using GSS shared-key feature"
624 export LGSS_SK=$(which lgss_sk 2> /dev/null)
626 export LGSS_SK="$LUSTRE/utils/gss/lgss_sk"
628 error_exit "built with lgss_sk disabled! SEC=$SEC"
636 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
637 which lgss_keyring > /dev/null 2>&1 ||
638 error_exit "built with gss disabled! SEC=$SEC"
644 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
646 # Paths on remote nodes, if different
647 export RLUSTRE=${RLUSTRE:-$LUSTRE}
648 export RPWD=${RPWD:-$PWD}
649 export I_MOUNTED=${I_MOUNTED:-"no"}
650 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
651 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
652 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
653 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
654 ! -f $LUSTRE/mdt/mdt.ko ]; then
655 export CLIENTMODSONLY=yes
658 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
659 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
663 while getopts "rvwf:" opt $*; do
668 w) WRITECONF=writeconf;;
673 shift $((OPTIND - 1))
676 # print the durations of each test if "true"
677 DDETAILS=${DDETAILS:-false}
678 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
683 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
685 # Constants used in more than one test script
686 export LOV_MAX_STRIPE_COUNT=2000
687 export LMV_MAX_STRIPES_PER_MDT=5
688 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
689 export KEEP_POOLS=${KEEP_POOLS:-false}
690 export PARALLEL=${PARALLEL:-"no"}
692 export BLCKSIZE=${BLCKSIZE:-4096}
693 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
695 # use /dev/urandom when consuming space on ZFS to avoid compression
696 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
697 DD_DEV="/dev/urandom"
701 DD="dd if=$DD_DEV bs=1M"
703 # use localrecov to enable recovery for local clients, LU-12722
704 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
705 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
706 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
709 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
710 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
712 # Force large nid testing, if unset or false then large NIDs will only
713 # be used if they are the only addresses assigned to the LNet
715 export FORCE_LARGE_NID=${FORCE_LARGE_NID:-false}
716 if ${FORCE_LARGE_NID}; then
717 export LNET_CONFIG_INIT_OPT="--all --large"
718 export LNET_CONFIG_OPT="-l"
720 export LNET_CONFIG_INIT_OPT="--all"
721 export LNET_CONFIG_OPT=""
729 ncpts=$(do_facet $facet "lctl get_param -n " \
730 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
732 if [ $ncpts -eq 0 ]; then
739 # Return a numeric version code based on a version string. The version
740 # code is useful for comparison two version strings to see which is newer.
742 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
743 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
745 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
748 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
749 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
751 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
753 # usage: lustre_build_version_node
755 # All Lustre versions support "lctl get_param" to report the version of the
756 # code running in the kernel (what our tests are interested in), but it
757 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
758 # the "version" parameter doesn't include "lustre: " at the beginning.
759 # If that fails, call "lctl lustre_build_version" which prints either (or both)
760 # the userspace and kernel build versions, but until 2.8.55 required root
761 # access to get the Lustre kernel version. If that also fails, fall back to
762 # using "lctl --version", which is easy to parse and works without the kernel
763 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
764 # not the module version, though they are usually the same.
766 # Various commands and their output format for different Lustre versions:
767 # lctl get_param version: 2.9.55
768 # lctl get_param version: lustre: 2.8.53
769 # lctl get_param version: lustre: 2.6.52
770 # kernel: patchless_client
771 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
772 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
773 # lctl lustre_build_version: error: lustre_build_version: Permission denied
774 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
775 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
776 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
777 # lctl --version: lctl 2.6.50
779 # output: prints version string to stdout in (up to 4) dotted-decimal values
780 lustre_build_version_node() {
785 # this is the currently-running version of the kernel modules
786 ver=$(do_node $node "$LCTL get_param -n version 2>/dev/null")
787 # we mostly test 2.10+ systems, only try others if the above fails
788 if [ -z "$ver" ]; then
789 ver=$(do_node $node "$LCTL lustre_build_version 2>/dev/null")
791 if [ -z "$ver" ]; then
792 ver=$(do_node $node "$LCTL --version 2>/dev/null" |
795 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
796 [ -n "$lver" ] && ver="$lver"
798 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
799 tr _ . | cut -d. -f1-4)
804 lustre_build_version() {
805 local facet=${1:-client}
806 local node=$(facet_active_host $facet)
807 local facet_version=${facet}_VERSION
810 # if the global variable is already set, then use that
811 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
813 lver=$(lustre_build_version_node $node)
814 # save in global variable for the future
815 export $facet_version=$lver
820 # Report the Lustre numeric build version code for the supplied facet.
821 lustre_version_code() {
822 version_code $(lustre_build_version $1)
827 local facet_version=${facet}_ZFS_VERSION
829 if [[ -z "${!facet_version}" ]]; then
830 local zfs_ver=$(do_facet $facet "modinfo --field version zfs")
832 export $facet_version=$(version_code ${zfs_ver%-*})
834 echo ${!facet_version}
837 # Extract the server-side /etc/os-release information into local variables
838 # usage: lustre_os_release <facet>
839 # generates $facet_OS_ID, $facet_OS_ID_LIKE, $facet_VERSION_ID
840 # and also $facet_OS_VERSION_CODE=$(version_code $facet_VERSION_ID)
841 lustre_os_release() {
843 local facet_os=$(tr "[:lower:]" "[:upper:]" <<<$facet)_OS_
844 local facet_version=${facet_os}VERSION_
847 echo "$facet: $(do_facet $facet "cat /etc/system-release")"
848 do_facet $facet "test -r /etc/os-release" || {
849 echo "$facet: has no /etc/os-release"
850 do_facet $facet "uname -a; ls -s /etc/*release"
855 # more variables in os-release could be exported, but these
856 # are the ones that looked enough for our needs here
858 VERSION_ID=*|ID=*|ID_LIKE=*) eval export ${facet_os}$line ;;
860 done < <(do_facet $facet "cat /etc/os-release")
862 eval export ${facet_version}CODE=\$\(version_code \$${facet_version}ID\)
863 # add in the "self" ID to ID_LIKE so only one needs to be checked
864 eval export ${facet_os}ID_LIKE+=\" \$${facet_os}ID\"
865 env | grep "${facet_os}"
869 /sbin/lsmod | grep -q "^\<$1\>"
872 check_lfs_df_ret_val() {
873 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
874 # returned by 'lfs df' for valid dentry but not a lustrefs.
876 # 'lfs df' historically always returned success(0) instead of
877 # EOPNOTSUPP. This function for compatibility reason, ignores and
878 # masquerades EOPNOTSUPP as success.
879 [[ $1 -eq 95 ]] && return 0
892 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
895 # parallels can't load modules directly from prlfs, use /tmp instead
896 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
897 local target="$(mktemp)"
899 cp "$module" "$target"
902 [[ $rc == 0 ]] && PRLFS=true
910 # Load a module on the system where this is running.
912 # usage: load_module module_name [module arguments for insmod/modprobe]
914 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
915 # will be used as the arguments. Otherwise arguments will be obtained from
916 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
919 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
922 local base=$(basename $module $ext)
924 local -A module_is_loaded_aa
928 for mod in $(lsmod | awk '{ print $1; }'); do
929 module_is_loaded_aa[${mod//-/_}]=true
933 ${module_is_loaded_aa[${1//-/_}]:-false}
936 if module_is_loaded $base; then
940 if [[ -f $LUSTRE/$module$ext ]]; then
941 path=$LUSTRE/$module$ext
942 elif [[ "$base" == lnet_selftest ]] &&
943 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
944 path=$LUSTRE/../lnet/selftest/$base$ext
949 if [[ -n "$path" ]]; then
950 # Try to load any non-Lustre modules that $module depends on.
951 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
952 if ! module_is_loaded $mod; then
958 # If no module arguments were passed then get them from
959 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
960 if [ $# -eq 0 ]; then
961 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
962 # not in Bash until 4.x, so we resort to eval.
963 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
964 eval set -- \$$optvar
965 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
966 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
968 opt=$(awk -v var="^options $base" '$0 ~ var \
969 {gsub("'"options $base"'",""); print}' \
971 set -- $(echo -n $opt)
973 # Ensure we have accept=all for lnet
974 if [[ "$base" == lnet ]]; then
975 # OK, this is a bit wordy...
976 local arg accept_all_present=false
979 [[ "$arg" == accept=all ]] &&
980 accept_all_present=true
983 $accept_all_present || set -- "$@" accept=all
990 [ $# -gt 0 ] && echo "${module} options: '$*'"
992 # Note that insmod will ignore anything in modprobe.conf, which is why
993 # we're passing options on the command-line. If $path does not exist
994 # then we must be testing a "make install" or"rpm" installation. Also
995 # note that failing to load ptlrpc_gss is not considered fatal.
996 if [[ -n "$path" ]]; then
997 lustre_insmod $path "$@"
998 elif [[ "$base" == ptlrpc_gss ]]; then
999 if ! modprobe $base "$@" 2>/dev/null; then
1000 echo "gss/krb5 is not supported"
1008 $LCTL mark "$LNETCTL $*"
1014 $LCTL mark "$LNETCTL $*"
1020 # For kmemleak-enabled kernels we need clear all past state
1021 # that obviously has nothing to do with this Lustre run
1022 # Disable automatic memory scanning to avoid perf hit.
1023 if [ -f /sys/kernel/debug/kmemleak ] ; then
1024 echo scan=off > /sys/kernel/debug/kmemleak || true
1025 echo scan > /sys/kernel/debug/kmemleak || true
1026 echo clear > /sys/kernel/debug/kmemleak || true
1029 echo Loading modules from $LUSTRE
1033 if [ -f /sys/devices/system/cpu/online ]; then
1034 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
1035 echo "detected $ncpus online CPUs by sysfs"
1037 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1040 if [ $rc -eq 0 ]; then
1041 echo "detected $ncpus online CPUs by getconf"
1043 echo "Can't detect number of CPUs"
1048 # if there is only one CPU core, libcfs can only create one partition
1049 # if there is more than 4 CPU cores, libcfs should create multiple CPU
1050 # partitions. So we just force libcfs to create 2 partitions for
1051 # system with 2 or 4 cores
1052 local saved_opts="$MODOPTS_LIBCFS"
1054 echo "MODOPTS_LIBCFS=$MODOPTS_LIBCFS"
1055 if ! [[ "$MODOPTS_LIBCFS" =~ "cpu_" ]] &&
1056 (( $ncpus <= 4 && $ncpus > 1 )); then
1057 # force to enable multiple CPU partitions
1058 echo "Force libcfs to create 2 CPU partitions"
1059 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
1061 echo "libcfs will create CPU partition based on online CPUs"
1064 load_module ../libcfs/libcfs/libcfs
1065 # Prevent local MODOPTS_LIBCFS being passed as part of environment
1066 # variable to remote nodes
1067 unset MODOPTS_LIBCFS
1069 set_default_debug "neterror net nettrace malloc"
1070 if [[ $1 == config_on_load=1 ]]; then
1071 load_module ../lnet/lnet/lnet
1073 load_module ../lnet/lnet/lnet "$@"
1076 LNDPATH=${LNDPATH:-"../lnet/klnds"}
1077 if [ -z "$LNETLND" ]; then
1079 o2ib*) [[ -f ${LNDPATH}/o2iblnd/ko2iblnd.ko ]] &&
1080 LNETLND="o2iblnd/ko2iblnd" ||
1081 LNETLND="in-kernel-o2iblnd/ko2iblnd";;
1082 tcp*) LNETLND="socklnd/ksocklnd" ;;
1083 kfi*) LNETLND="kfilnd/kkfilnd" ;;
1084 gni*) LNETLND="gnilnd/kgnilnd" ;;
1085 *) local lnd="${NETTYPE%%[0-9]}lnd"
1086 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
1087 LNETLND="$lnd/k$lnd" ||
1088 LNETLND="socklnd/ksocklnd"
1091 load_module ../lnet/klnds/$LNETLND
1093 if [[ $1 == config_on_load=1 ]]; then
1094 if $FORCE_LARGE_NID; then
1095 do_lnetctl lnet configure -a -l ||
1098 do_lnetctl lnet configure -a ||
1104 load_modules_local() {
1105 if [ -n "$MODPROBE" ]; then
1107 echo "Using modprobe to load modules"
1111 # Create special udev test rules on every node
1112 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
1113 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
1115 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
1117 udevadm control --reload-rules
1120 if $FORCE_LARGE_NID; then
1121 load_lnet config_on_load=1
1126 load_module obdclass/obdclass
1127 if ! client_only; then
1128 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
1130 load_module ptlrpc/ptlrpc
1131 load_module ptlrpc/gss/ptlrpc_gss
1139 load_module obdecho/obdecho
1140 if ! client_only; then
1141 load_module lfsck/lfsck
1142 [ "$LQUOTA" != "no" ] &&
1143 load_module quota/lquota $LQUOTAOPTS
1144 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
1145 load_module osd-zfs/osd_zfs
1146 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
1147 load_module ../ldiskfs/ldiskfs
1148 load_module osd-ldiskfs/osd_ldiskfs
1149 elif [[ $(node_fstypes $HOSTNAME) == *wbcfs* ]]; then
1150 load_module osd-wbcfs/osd_wbcfs
1155 # don't fail if ost module doesn't exist
1156 load_module ost/ost 2>/dev/null || true;
1162 load_module llite/lustre
1163 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
1165 rm -f $OGDB/ogdb-$HOSTNAME
1166 $LCTL modules > $OGDB/ogdb-$HOSTNAME
1168 # 'mount' doesn't look in $PATH, just sbin
1169 local mount_lustre=$LUSTRE/utils/mount.lustre
1170 if [ -f $mount_lustre ]; then
1171 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1172 if grep -qw "$sbin_mount" /proc/mounts; then
1173 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
1175 if ! grep -qw "$sbin_mount" /proc/mounts; then
1176 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
1177 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
1178 cat <<- EOF > "$sbin_mount"
1181 echo "This $sbin_mount just a mountpoint." 1>&2
1182 echo "It is never supposed to be run." 1>&2
1183 logger -p emerg -- "using stub $sbin_mount $@"
1186 chmod a+x $sbin_mount
1188 mount --bind $mount_lustre $sbin_mount ||
1189 error "can't bind $mount_lustre to $sbin_mount"
1190 # ignore errors to symlink .libs for read-only /sbin
1191 [[ -e /sbin/.libs ]] ||
1192 ln -sf $LUSTRE/utils/.libs /sbin/.libs || true
1203 # load modules on remote nodes optionally
1204 # lustre-tests have to be installed on these nodes
1205 if $LOAD_MODULES_REMOTE; then
1206 local list=$(comma_list $(remote_nodes_list))
1208 # include failover nodes in case they are not in the list yet
1209 facets=$(get_facets)
1210 for facet in ${facets//,/ }; do
1211 failover=$(facet_failover_host $facet)
1212 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
1213 list="$list,$failover"
1216 if [ -n "$list" ]; then
1217 echo "loading modules on: '$list'"
1218 do_rpc_nodes "$list" load_modules_local
1224 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
1225 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
1227 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
1228 echo "$LEAK_LUSTRE" 1>&2
1229 echo "$LEAK_PORTALS" 1>&2
1230 echo "Memory leaks detected"
1231 if [ $DEBUG -a -z $DEBUG_RMMOD ]; then
1232 debug_file=$TMP/debug-leak.$(date +%s)
1233 mv $TMP/debug $debug_file &&
1234 echo "Save $TMP/debug to $debug_file"
1236 [[ -n "$IGNORE_LEAK" ]] &&
1237 { echo "ignoring leaks" && return 0; } || true
1242 unload_modules_local() {
1243 $LUSTRE_RMMOD ldiskfs || return 2
1245 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
1246 rm /etc/udev/rules.d/99-lustre-test.rules
1247 udevadm control --reload-rules
1250 check_mem_leak || return 254
1258 wait_exit_ST client # bug 12845
1260 unload_modules_local || rc=$?
1262 if $LOAD_MODULES_REMOTE; then
1263 local list=$(comma_list $(remote_nodes_list))
1265 if (( MDS1_VERSION >= $(version_code 2.15.51) )); then
1266 # unload_module_local is only available after 2.15.51
1267 if [ -n "$list" ]; then
1268 echo "unloading modules via unload_modules_local on: '$list'"
1269 do_rpc_nodes "$list" unload_modules_local
1272 if [ -n "$list" ]; then
1273 echo "unloading modules on: '$list'"
1274 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
1275 do_rpc_nodes "$list" check_mem_leak
1276 do_rpc_nodes "$list" "rm -f /etc/udev/rules.d/99-lustre-test.rules"
1277 do_rpc_nodes "$list" "udevadm control --reload-rules"
1278 do_rpc_nodes "$list" "udevadm trigger"
1283 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1284 if grep -qe "$sbin_mount " /proc/mounts; then
1285 umount $sbin_mount || true
1286 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
1290 [ -L /sbin/.libs ] && rm /sbin/.libs
1292 [[ $rc -eq 0 ]] && echo "modules unloaded."
1298 local facet=${1:-ost1}
1300 local mult=$OSTCOUNT
1302 case $(facet_fstype $facet) in
1303 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
1304 # grant_block_size is in bytes, allow at least 2x max blocksize
1305 zfs) size=$(lctl get_param osc.$FSNAME*.import |
1306 awk '/grant_block_size:/ {print $2/512; exit;}')
1310 [[ $facet =~ mds ]] && mult=$MDTCOUNT
1311 echo -n $((size * mult))
1315 local facet=${1:-$SINGLEMDS}
1316 local fstype=$(facet_fstype $facet)
1319 ldiskfs) size=4;; # ~4KB per inode
1320 zfs) size=11;; # 10 to 11KB per inode
1333 echo Running as $user: $cmd $opts
1336 su - $user -c "$cmd $opts"
1339 check_gss_daemon_nodes() {
1341 local dname=$(basename "$2" | awk '{print $1}')
1347 do_nodesv $list "num=0;
1348 for proc in \\\$(pgrep $dname); do
1349 [ \\\$(ps -o ppid= -p \\\$proc) -ne 1 ] || ((num++))
1351 if [ \\\"\\\$num\\\" -ne 1 ]; then
1352 echo \\\$num instance of $dname;
1356 (( $ret == 0 )) || return $ret
1358 for node in ${list//,/ }; do
1360 while (( $loop < $loopmax )); do
1361 do_nodesv $node "$L_GETAUTH -d"
1363 (( $ret == 0 )) && break
1367 (( $loop < $loopmax )) || return 1
1372 check_gss_daemon_facet() {
1374 local dname=$(basename "$2" | awk '{print $1}')
1375 local num=$(do_facet $facet ps -o cmd -C $dname | grep -c $dname)
1377 if (( $num != 1 )); then
1378 echo "$num instance of $dname on $facet"
1388 echo "Stopping "$@" on $list"
1389 do_nodes $list "killall -2 $* 2>/dev/null || true"
1392 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1393 start_gss_daemons() {
1398 if [ "$nodes" ] && [ "$daemon" ] ; then
1399 echo "Starting gss daemon on nodes: $nodes"
1400 do_nodes $nodes "$daemon" "$options" || return 8
1401 check_gss_daemon_nodes $nodes "$daemon" || return 9
1406 echo "Starting gss daemon on mds: $nodes"
1408 # Start all versions, in case of switching
1409 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1412 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 1
1416 echo "Starting gss daemon on ost: $nodes"
1418 # Start all versions, in case of switching
1419 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1422 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 3
1424 # starting on clients
1426 local clients=${CLIENTS:-$HOSTNAME}
1429 # check daemons are running
1431 check_gss_daemon_nodes $(tgts_nodes) "$LSVCGSSD" || return 5
1434 stop_gss_daemons() {
1435 local nodes=$(mdts_nodes)
1437 send_sigint $nodes lsvcgssd lgssd
1440 send_sigint $nodes lsvcgssd
1442 nodes=${CLIENTS:-$HOSTNAME}
1443 send_sigint $nodes lgssd
1447 # Add mount flags for shared key
1450 if grep -q skpath <<< "$mt_opts" ; then
1451 mt_opts=$(echo $mt_opts |
1452 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1454 if [ -z "$mt_opts" ]; then
1455 mt_opts="-o skpath=$SK_PATH"
1457 mt_opts="$mt_opts,skpath=$SK_PATH"
1467 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1476 [ $from_tree = true ]
1480 if $SHARED_KEY; then
1489 if ! module_loaded ptlrpc_gss; then
1490 load_module ptlrpc/gss/ptlrpc_gss
1491 module_loaded ptlrpc_gss ||
1492 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1495 if $GSS_KRB5 || $GSS_SK; then
1496 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1499 if $GSS_SK && ! $SK_NO_KEY; then
1500 echo "Loading basic SSK keys on all servers"
1501 do_nodes $(comma_list $(all_server_nodes)) \
1502 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1503 do_nodes $(comma_list $(all_server_nodes)) \
1504 "keyctl show | grep lustre | cut -c1-11 |
1506 xargs -IX keyctl setperm X 0x3f3f3f3f"
1509 if $GSS_SK && $SK_NO_KEY; then
1510 local numclients=${1:-$CLIENTCOUNT}
1511 local clients=${CLIENTS:-$HOSTNAME}
1513 # security ctx config for keyring
1515 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1517 if from_build_tree; then
1518 mkdir -p $SK_OM_PATH
1519 if grep -q request-key /proc/mounts > /dev/null; then
1520 echo "SSK: Request key already mounted."
1522 mount -o bind $SK_OM_PATH /etc/request-key.d/
1524 local lgssc_conf_line='create lgssc * * '
1525 lgssc_conf_line+=$(which lgss_keyring)
1526 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1527 echo "$lgssc_conf_line" > $lgssc_conf_file
1530 [ -e $lgssc_conf_file ] ||
1531 error_exit "Could not find key options in $lgssc_conf_file"
1532 echo "$lgssc_conf_file content is:"
1533 cat $lgssc_conf_file
1535 if ! local_mode; then
1536 if from_build_tree; then
1537 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1539 do_nodes $(comma_list $(all_nodes)) "mount \
1540 -o bind $SK_OM_PATH \
1541 /etc/request-key.d/"
1542 do_nodes $(comma_list $(all_nodes)) "rsync \
1543 -aqv $HOSTNAME:$lgssc_conf_file \
1544 $lgssc_conf_file >/dev/null 2>&1"
1546 do_nodes $(comma_list $(all_nodes)) \
1547 "echo $lgssc_conf_file: ; \
1548 cat $lgssc_conf_file"
1552 # create shared key on all nodes
1553 mkdir -p $SK_PATH/nodemap
1554 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1555 $SK_PATH/$FSNAME-*.key
1556 # for nodemap testing each client may need own key,
1557 # and S2S now requires keys as well, both for "client"
1560 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1561 -w $SK_PATH/$FSNAME-nmclient.key \
1562 -d /dev/urandom >/dev/null 2>&1
1563 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1564 -w $SK_PATH/$FSNAME-s2s-server.key \
1565 -d /dev/urandom >/dev/null 2>&1
1568 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1569 -d /dev/urandom >/dev/null 2>&1
1571 for i in $(seq 0 $((numclients - 1))); do
1572 $LGSS_SK -t server -f$FSNAME -n c$i \
1573 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1577 if ! local_mode; then
1578 for lnode in $(all_nodes); do
1579 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1582 # Set client keys to client type to generate prime P
1584 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1585 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1587 do_nodes $clients "$LGSS_SK -t client -m \
1588 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1589 do_nodes $clients "find $SK_PATH/nodemap \
1590 -name \*.key | xargs -IX $LGSS_SK -t client \
1591 -m X >/dev/null 2>&1"
1592 # also have a client key available on server side,
1593 # for local client mount
1594 do_nodes $(comma_list $(all_server_nodes)) \
1595 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1596 $LGSS_SK -t client -m \
1597 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1599 # This is required for servers as well, if S2S in use
1601 do_nodes $(tgts_nodes) \
1602 "cp $SK_PATH/$FSNAME-s2s-server.key \
1603 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1604 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1606 do_nodes $clients "$LGSS_SK -t client \
1607 -m $SK_PATH/$FSNAME-nmclient.key \
1612 # mount options for servers and clients
1613 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1614 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1615 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1616 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1618 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1619 LGSS_KEYRING_DEBUG=4
1623 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1624 ( local_mode || from_build_tree ); then
1626 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1627 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1628 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1630 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1633 do_nodesv $(comma_list $(all_server_nodes)) \
1634 "$LCTL set_param sptlrpc.gss.rsi_upcall=$L_GETAUTH"
1640 # maybe cleanup credential cache?
1647 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1648 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1649 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1653 $RPC_MODE || echo "Cleaning up Shared Key.."
1654 do_nodes $(comma_list $(all_nodes)) "rm -f \
1655 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1656 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1657 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1658 if from_build_tree; then
1659 # Remove the mount and clean up the files we added to
1661 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1662 request-key.d /proc/mounts; do umount \
1663 /etc/request-key.d/; done"
1664 do_nodes $(comma_list $(all_nodes)) "rm -f \
1665 $SK_OM_PATH/lgssc.conf"
1666 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1674 local var=${facet}_svc
1682 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1683 tr '[:lower:]' '[:upper:]'
1689 if [ $facet == mgs ] || [ $facet == client ]; then
1693 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1701 if [ -n "${!var}" ]; then
1706 var=$(facet_type $facet)FSTYPE
1707 if [ -n "${!var}" ]; then
1712 if [ -n "$FSTYPE" ]; then
1717 if [[ $facet == mgs ]] && combined_mgs_mds; then
1729 local facets=$(get_facets)
1732 for facet in ${facets//,/ }; do
1733 if [[ $node == $(facet_host $facet) ]] ||
1734 [[ $node == "$(facet_failover_host $facet)" ]]; then
1735 fstype=$(facet_fstype $facet)
1736 if [[ $fstypes != *$fstype* ]]; then
1737 fstypes+="${fstypes:+,}$fstype"
1746 local num=$(facet_number $facet)
1749 if [[ $(facet_type $facet) = OST ]]; then
1750 index=OSTINDEX${num}
1751 if [[ -n "${!index}" ]]; then
1756 index=${OST_INDICES[num - 1]}
1759 [[ -n "$index" ]] || index=$((num - 1))
1767 local fstype=$(facet_fstype $facet)
1771 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1773 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1774 ${dev} 2>/dev/null");;
1776 label="wbcfs-target";;
1778 error "unknown fstype!";;
1785 # Get the device of a facet.
1792 mgs) device=$(mgsdevname) ;;
1793 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1794 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1795 fs2mds) device=$(mdsdevname 1_2) ;;
1796 fs2ost) device=$(ostdevname 1_2) ;;
1797 fs3ost) device=$(ostdevname 2_2) ;;
1805 # Get the virtual device of a facet.
1812 mgs) device=$(mgsvdevname) ;;
1813 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1814 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1815 fs2mds) device=$(mdsvdevname 1_2) ;;
1816 fs2ost) device=$(ostvdevname 1_2) ;;
1817 fs3ost) device=$(ostvdevname 2_2) ;;
1825 local virt=$(virt-what 2> /dev/null)
1827 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1829 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1832 VMware|KVM|VirtualBox|Parallels|Bochs)
1833 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1838 virt=$(dmidecode -s system-manufacturer | awk '{print $1}')
1841 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1847 # Re-read the partition table on failover partner host.
1848 # After a ZFS storage pool is created on a shared device, the partition table
1849 # on the device may change. However, the operating system on the failover
1850 # host may not notice the change automatically. Without the up-to-date partition
1851 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1852 # relative to partition rather than disk beginnings.
1854 # This function performs partprobe on the failover host to make it re-read the
1857 refresh_partition_table() {
1862 host=$(facet_passive_host $facet)
1863 if [[ -n "$host" ]]; then
1864 do_node $host "$PARTPROBE $device"
1869 # Get ZFS storage pool name.
1876 device=$(facet_device $facet)
1877 # poolname is string before "/"
1878 poolname="${device%%/*}"
1885 # Get ZFS local fsname.
1887 zfs_local_fsname() {
1889 local lfsname=$(basename $(facet_device $facet))
1895 # Create ZFS storage pool.
1902 local opts=${@:-"-o cachefile=none"}
1904 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1905 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1906 $ZPOOL create -f $opts $poolname $vdev"
1910 # Create ZFS file system.
1916 local opts=${@:-"-o mountpoint=legacy"}
1918 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1919 $ZFS create $opts $dataset"
1923 # Export ZFS storage pool.
1924 # Before exporting the pool, all datasets within the pool should be unmounted.
1932 poolname=$(zpool_name $facet)
1934 if [[ -n "$poolname" ]]; then
1935 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1936 grep -q ^$poolname/ /proc/mounts ||
1937 $ZPOOL export $opts $poolname"
1942 # Destroy ZFS storage pool.
1943 # Destroy the given pool and free up any devices for other use. This command
1944 # tries to unmount any active datasets before destroying the pool.
1945 # -f Force any active datasets contained within the pool to be unmounted.
1949 local poolname=${2:-$(zpool_name $facet)}
1951 if [[ -n "$poolname" ]]; then
1952 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1953 $ZPOOL destroy -f $poolname"
1958 # Import ZFS storage pool.
1959 # Force importing, even if the pool appears to be potentially active.
1964 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1967 poolname=$(zpool_name $facet)
1969 if [[ -n "$poolname" ]]; then
1970 opts+=" -d $(dirname $(facet_vdevice $facet))"
1971 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1972 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1973 $ZPOOL import -f $opts $poolname"
1978 # Reimport ZFS storage pool with new name
1983 local opts="-o cachefile=none"
1984 local poolname=$(zpool_name $facet)
1986 opts+=" -d $(dirname $(facet_vdevice $facet))"
1987 do_facet $facet "$ZPOOL export $poolname;
1988 $ZPOOL import $opts $poolname $newpool"
1992 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1993 # is not automatically imported on system startup.
1995 # In a failover environment, this will provide resource level fencing which
1996 # will ensure that the same ZFS storage pool will not be imported concurrently
1997 # on different nodes.
1999 disable_zpool_cache() {
2003 poolname=$(zpool_name $facet)
2005 if [[ -n "$poolname" ]]; then
2006 do_facet $facet "$ZPOOL set cachefile=none $poolname"
2011 # This and set_osd_param() shall be used to access OSD parameters
2012 # once existed under "obdfilter":
2017 # writethrough_cache_enable
2021 local device=${2:-$FSNAME-OST*}
2024 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
2029 local device=${2:-$FSNAME-OST*}
2033 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
2036 set_default_debug () {
2037 local debug=${1:-"$PTLDEBUG"}
2038 local subsys=${2:-"$SUBSYSTEM"}
2039 local debug_size=${3:-$DEBUG_SIZE}
2041 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
2043 lctl set_param subsystem_debug="${subsys# }" >/dev/null
2044 [ -n "$debug_size" ] &&
2045 lctl set_param debug_mb="$debug_size" >/dev/null
2050 set_default_debug_nodes () {
2052 local debug="${2:-"$PTLDEBUG"}"
2053 local subsys="${3:-"$SUBSYSTEM"}"
2054 local debug_size="${4:-$DEBUG_SIZE}"
2056 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
2057 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
2061 [[ -z "$nodes" ]] ||
2062 do_rpc_nodes "$nodes" set_default_debug \
2063 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
2066 set_default_debug_facet () {
2068 local debug="${2:-"$PTLDEBUG"}"
2069 local subsys="${3:-"$SUBSYSTEM"}"
2070 local debug_size="${4:-$DEBUG_SIZE}"
2071 local node=$(facet_active_host $facet)
2073 [ -n "$node" ] || error "No host defined for facet $facet"
2075 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
2078 set_params_nodes() {
2079 (( $# >= 2 )) || return 0
2084 [[ -n "$params" ]] || return 0
2086 do_nodes $nodes "$LCTL set_param $params"
2089 set_params_clients() {
2090 local clients=${1:-$CLIENTS}
2092 local params="${@:-$CLIENT_LCTL_SETPARAM_PARAM}"
2094 set_params_nodes $clients $params
2098 local mdts=${1:-$(mdts_nodes)}
2100 local params="${@:-$MDS_LCTL_SETPARAM_PARAM}"
2102 set_params_nodes $mdts $params
2106 local osts=${1:-$(osts_nodes)}
2108 local params="${@:-$OSS_LCTL_SETPARAM_PARAM}"
2110 set_params_nodes $osts $params
2114 local hostid=${1:-$(hostid)}
2116 if [ ! -s /etc/hostid ]; then
2117 printf $(echo -n $hostid |
2118 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
2124 local facets=${1:-$(get_facets)}
2130 for facet in ${facets//,/ }; do
2131 mount_facet $facet &
2135 for ((index=0; index<$total; index++)); do
2136 wait ${mountpids[index]}
2138 [ $RC -eq 0 ] && continue
2140 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
2141 skip_noexit "Restart of $facet failed!." &&
2144 error "Restart of $facet failed!"
2152 # Add argument "arg" (e.g., "loop") to the comma-separated list
2153 # of arguments for option "opt" (e.g., "-o") on command
2154 # line "opts" (e.g., "-o flock").
2160 local opt_pattern="\([[:space:]]\+\|^\)$opt"
2162 if echo "$opts" | grep -q $opt_pattern; then
2163 opts=$(echo "$opts" | sed -e \
2164 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
2166 opts+="${opts:+ }$opt $arg"
2172 # Associate loop device with a given regular file.
2173 # Return the loop device.
2175 setup_loop_device() {
2179 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
2180 if [[ -z \\\$loop_dev ]]; then
2181 loop_dev=\\\$($LOSETUP -f);
2182 $LOSETUP \\\$loop_dev $file || loop_dev=;
2184 echo -n \\\$loop_dev"
2188 # Detach a loop device.
2190 cleanup_loop_device() {
2194 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
2195 $LOSETUP -d $loop_dev"
2199 # Check if a given device is a block device.
2206 [[ -n "$dev" ]] || return 1
2207 do_facet $facet "test -b $dev" || return 1
2208 if [[ -n "$size" ]]; then
2209 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
2210 count=1 skip=$size 2>&1" |
2211 awk '($3 == "in") { print $1 }')
2212 [[ "$in" = "1+0" ]] || return 1
2217 # Check if a given device is a device-mapper device.
2223 [[ -n "$dev" ]] || return 1
2224 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
2228 # Check if a given device is a device-mapper flakey device.
2230 is_dm_flakey_dev() {
2235 [[ -n "$dev" ]] || return 1
2237 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
2239 [[ $type = flakey ]] && return 0 || return 1
2243 # Check if device-mapper flakey device is supported by the kernel
2244 # of $facet node or not.
2246 dm_flakey_supported() {
2250 do_facet $facet "modprobe dm-flakey;
2251 $DMSETUP targets | grep -q flakey" &> /dev/null
2255 # Get the device-mapper flakey device name of a given facet.
2257 dm_facet_devname() {
2259 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2261 echo -n ${facet}_flakey
2265 # Get the device-mapper flakey device of a given facet.
2266 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
2268 dm_facet_devpath() {
2271 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
2275 # Set a device-mapper device with a new table.
2277 # The table has the following format:
2278 # <logical_start_sector> <num_sectors> <target_type> <target_args>
2280 # flakey <target_args> includes:
2281 # <destination_device> <offset> <up_interval> <down_interval> \
2282 # [<num_features> [<feature_arguments>]]
2284 # linear <target_args> includes:
2285 # <destination_device> <start_sector>
2287 dm_set_dev_table() {
2290 local target_type=$3
2296 read tmp num_sectors tmp real_dev tmp \
2297 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
2299 case $target_type in
2301 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
2304 table="0 $num_sectors linear $real_dev 0"
2306 *) error "invalid target type $target_type" ;;
2309 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
2310 error "failed to suspend $dm_dev"
2311 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
2312 error "failed to load $target_type table into $dm_dev"
2313 do_facet $facet "$DMSETUP resume $dm_dev" ||
2314 error "failed to resume $dm_dev"
2318 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
2319 # feature parameter.
2322 # All write I/O is silently ignored.
2323 # Read I/O is handled correctly.
2325 dm_set_dev_readonly() {
2327 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2329 dm_set_dev_table $facet $dm_dev flakey
2333 # Set a device-mapper device to traditional linear mapping mode.
2335 dm_clear_dev_readonly() {
2337 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2339 dm_set_dev_table $facet $dm_dev linear
2343 # Set the device of a given facet as "read-only".
2345 set_dev_readonly() {
2347 local svc=${facet}_svc
2349 if [[ $(facet_fstype $facet) = zfs ]] ||
2350 ! dm_flakey_supported $facet; then
2351 do_facet $facet $LCTL --device ${!svc} readonly
2353 dm_set_dev_readonly $facet
2358 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
2365 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
2366 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
2367 echo -n $num_sectors
2371 # Create a device-mapper device with a given block device or regular file (will
2372 # be associated with loop device).
2373 # Return the full path of the device-mapper device.
2377 local real_dev=$2 # destination device
2378 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
2379 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
2381 # check if the device-mapper device to be created already exists
2382 if is_dm_dev $facet $dm_dev; then
2383 # if the existing device was set to "read-only", then clear it
2384 ! is_dm_flakey_dev $facet $dm_dev ||
2385 dm_clear_dev_readonly $facet $dm_dev
2391 # check if the destination device is a block device, and if not,
2392 # associate it with a loop device
2393 is_blkdev $facet $real_dev ||
2394 real_dev=$(setup_loop_device $facet $real_dev)
2395 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
2397 # now create the device-mapper device
2398 local num_sectors=$(get_num_sectors $facet $real_dev)
2399 local table="0 $num_sectors linear $real_dev 0"
2402 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
2403 { rc=${PIPESTATUS[0]}; dm_dev=; }
2404 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2411 # Map the facet name to its device variable name.
2413 facet_device_alias() {
2415 local dev_alias=$facet
2418 fs2mds) dev_alias=mds1_2 ;;
2419 fs2ost) dev_alias=ost1_2 ;;
2420 fs3ost) dev_alias=ost2_2 ;;
2428 # Save the original value of the facet device and export the new value.
2434 local active_facet=$(facet_active $facet)
2435 local dev_alias=$(facet_device_alias $active_facet)
2436 local dev_name=${dev_alias}_dev
2437 local dev=${!dev_name}
2439 if [[ $active_facet = $facet ]]; then
2440 local failover_dev=${dev_alias}failover_dev
2441 if [[ ${!failover_dev} = $dev ]]; then
2442 eval export ${failover_dev}_saved=$dev
2443 eval export ${failover_dev}=$dm_dev
2446 dev_alias=$(facet_device_alias $facet)
2447 local facet_dev=${dev_alias}_dev
2448 if [[ ${!facet_dev} = $dev ]]; then
2449 eval export ${facet_dev}_saved=$dev
2450 eval export ${facet_dev}=$dm_dev
2454 eval export ${dev_name}_saved=$dev
2455 eval export ${dev_name}=$dm_dev
2459 # Restore the saved value of the facet device.
2464 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2465 local dev_alias=$(facet_device_alias $facet)
2467 local saved_dev=${dev_alias}_dev_saved
2468 [[ -z ${!saved_dev} ]] ||
2469 eval export ${dev_alias}_dev=${!saved_dev}
2471 saved_dev=${dev_alias}failover_dev_saved
2472 [[ -z ${!saved_dev} ]] ||
2473 eval export ${dev_alias}failover_dev=${!saved_dev}
2477 # Remove a device-mapper device.
2478 # If the destination device is a loop device, then also detach it.
2482 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2486 is_dm_dev $facet $dm_dev || return 0
2488 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2489 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2491 do_facet $facet "$DMSETUP remove $dm_dev"
2492 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2494 unexport_dm_dev $facet
2496 # detach a loop device
2497 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2499 # unload dm-flakey module
2500 do_facet $facet "modprobe -r dm-flakey" || true
2506 local active_facet=$(facet_active $facet)
2507 local dev_alias=$(facet_device_alias $active_facet)
2508 local dev=${dev_alias}_dev
2509 local opt=${facet}_opt
2510 local mntpt=$(facet_mntpt $facet)
2511 local opts="${!opt} $@"
2512 local fstype=$(facet_fstype $facet)
2514 local dm_dev=${!dev}
2515 local index=$(facet_index $facet)
2516 local node_type=$(facet_type $facet)
2518 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2519 dev=mds1failover_dev
2521 module_loaded lustre || load_modules
2525 if dm_flakey_supported $facet; then
2526 dm_dev=$(dm_create_dev $facet ${!dev})
2527 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2530 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2532 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2534 # import ZFS storage pool
2535 import_zpool $facet || return ${PIPESTATUS[0]}
2537 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2538 lustre:svname $dm_dev");;
2542 error "unknown fstype!";;
2545 # for testing LU-482 error handling in mount_facets() and test_0a()
2546 if [ -f $TMP/test-lu482-trigger ]; then
2549 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2550 (( $seq_width >= 16384 )) || seq_width=16384
2554 echo "Start ${facet}: $MOUNT_CMD -v lustre-wbcfs $mntpt"
2556 export OSD_WBC_FSNAME="$FSNAME"
2557 export OSD_WBC_INDEX="$index"
2558 export OSD_WBC_MGS_NID="$MGSNID"
2562 export OSD_WBC_TGT_TYPE="OST"
2565 export OSD_WBC_TGT_TYPE="MDT"
2566 if (( $index == 0 )) &&
2567 [[ "$mds_HOST" == "$mgs_HOST" ]]; then
2568 export OSD_WBC_PRIMARY_MDT="1"
2570 export OSD_WBC_PRIMARY_MDT="0"
2574 export OSD_WBC_TGT_TYPE="MGT"
2577 error "Unhandled node_type!"
2580 do_facet ${facet} "mkdir -p $mntpt; \
2581 OSD_WBC_TGT_TYPE=$OSD_WBC_TGT_TYPE \
2582 OSD_WBC_INDEX=$OSD_WBC_INDEX \
2583 OSD_WBC_MGS_NID=$OSD_WBC_MGS_NID \
2584 OSD_WBC_PRIMARY_MDT=$OSD_WBC_PRIMARY_MDT \
2585 OSD_WBC_FSNAME=$OSD_WBC_FSNAME \
2586 $MOUNT_CMD -v lustre-wbcfs $mntpt"
2589 echo "Start ${facet}: $MOUNT_CMD $opts $dm_dev $mntpt"
2591 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2595 if [[ ${facet} =~ ost ]] && [[ ! "$fstype" == "wbcfs" ]]; then
2596 do_facet ${facet} "$LCTL set_param \
2597 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2601 if [ $RC -ne 0 ]; then
2602 echo "Start of $dm_dev on ${facet} failed ${RC}"
2606 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2607 if [[ "$health" != "healthy" ]]; then
2608 error "$facet is in a unhealthy state, got: '$health'"
2611 set_default_debug_facet $facet
2613 if [[ $opts =~ .*nosvc.* ]]; then
2614 echo "Start $dm_dev without service"
2619 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2620 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2621 "" || error "$dm_dev failed to initialize!";;
2623 wait_update_facet ${facet} "$ZFS get -H -o value \
2624 lustre:svname $dm_dev 2>/dev/null | \
2625 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2626 error "$dm_dev failed to initialize!";;
2631 error "unknown fstype!";;
2635 # commit the device label change to disk
2636 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2637 echo "Commit the device label on ${!dev}"
2638 do_facet $facet "sync; sleep 1; sync"
2642 label=$(devicelabel ${facet} $dm_dev)
2643 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2644 eval export ${facet}_svc=${label}
2645 echo Started ${label}
2647 export_dm_dev $facet $dm_dev
2652 # start facet device options
2658 local dev_alias=$(facet_device_alias $facet)
2660 eval export ${dev_alias}_dev=${device}
2661 eval export ${facet}_opt=\"$*\"
2663 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2664 eval export mgs_dev=${device}
2666 local varname=${dev_alias}failover_dev
2667 if [ -n "${!varname}" ] ; then
2668 eval export ${dev_alias}failover_dev=${!varname}
2670 eval export ${dev_alias}failover_dev=$device
2671 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2672 eval export mgsfailover_dev=${device}
2676 local mntpt=$(facet_mntpt $facet)
2677 do_facet ${facet} mkdir -p $mntpt
2678 eval export ${facet}_MOUNT=$mntpt
2679 mount_facet ${facet}
2682 if [[ $RC == 0 && $facet == *ost* && $OSTDEVBASE == */tmp/* ]]; then
2683 varname="${facet}_FSTRIM"
2684 if [[ -z ${!varname} ]]; then
2685 if do_facet ${facet} "fstrim -v $mntpt"; then
2686 eval export $varname="yes"
2688 eval export $varname="no"
2700 local HOST=$(facet_active_host $facet)
2701 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2703 local mntpt=$(facet_mntpt $facet)
2704 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2705 if [ ${running} -ne 0 ]; then
2706 echo "Stopping $mntpt (opts:$*) on $HOST"
2707 do_facet ${facet} $UMOUNT "$@" $mntpt
2710 # umount should block, but we should wait for unrelated obd's
2711 # like the MGS or MGC to also stop.
2712 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2714 if [[ $(facet_fstype $facet) == zfs ]]; then
2715 # export ZFS storage pool
2716 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2717 elif dm_flakey_supported $facet; then
2718 local host=${facet}_HOST
2719 local failover_host=${facet}failover_HOST
2720 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2721 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2722 dm_cleanup_dev $facet
2727 # get mdt quota type
2729 local varsvc=${SINGLEMDS}_svc
2730 do_facet $SINGLEMDS $LCTL get_param -n \
2731 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2734 # get ost quota type
2736 # All OSTs should have same quota type
2737 local varsvc=ost1_svc
2738 do_facet ost1 $LCTL get_param -n \
2739 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2742 # restore old quota type settings
2744 for usr in $QUOTA_USERS; do
2745 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2747 cmd="$LFS setquota -$type $usr -b 0"
2748 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2750 eval $cmd || error "$cmd FAILED!"
2752 # display the quota status
2753 echo "Quota settings for $usr : "
2754 $LFS quota -v -u $usr $MOUNT || true
2756 if [ "$old_MDT_QUOTA_TYPE" ]; then
2757 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2758 do_facet mgs $PERM_CMD \
2759 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2762 do_facet mgs $PERM_CMD \
2763 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2766 if [ "$old_OST_QUOTA_TYPE" ]; then
2767 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2768 do_facet mgs $PERM_CMD \
2769 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2772 do_facet mgs $LCTL conf_param \
2773 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2778 # Handle the case when there is a space in the lfs df
2779 # "filesystem summary" line the same as when there is no space.
2780 # This will allow fixing the "lfs df" summary line in the future.
2782 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2783 check_lfs_df_ret_val ${PIPESTATUS[0]}
2786 # Get free inodes on the MDT specified by mdt index, free indoes on
2787 # the whole filesystem will be returned when index == -1.
2793 if [ $index -eq -1 ]; then
2796 mdt_uuid=$(mdtuuid_from_index $index)
2799 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2804 # Get the OST device status from 'lfs df' with a given OST index.
2808 local mnt_pnt=${2:-$MOUNT}
2812 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2813 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2819 # save old quota type & set new quota type
2820 local mdt_qtype=$(mdt_quota_type)
2821 local ost_qtype=$(ost_quota_type)
2823 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2824 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2826 export old_MDT_QUOTA_TYPE=$mdt_qtype
2827 export old_OST_QUOTA_TYPE=$ost_qtype
2829 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2830 do_facet mgs $PERM_CMD \
2831 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2832 do_facet mgs $PERM_CMD \
2833 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2835 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2836 error "set mdt quota type failed"
2837 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2838 error "set ost quota type failed"
2841 local quota_usrs=$QUOTA_USERS
2843 # get_filesystem_size
2844 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2845 local blk_soft=$((disksz + 1024))
2846 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2848 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2849 local i_soft=$inodes
2850 local i_hard=$((i_soft + i_soft / 20))
2852 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2853 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2854 "inode-hardlimit: $i_hard"
2857 for usr in $quota_usrs; do
2858 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2860 cmd="$LFS setquota -$type $usr -b $blk_soft"
2861 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2863 eval $cmd || error "$cmd FAILED!"
2865 # display the quota status
2866 echo "Quota settings for $usr : "
2867 $LFS quota -v -u $usr $mntpt || true
2874 local opts=${3:-$MOUNT_OPTS}
2875 opts=${opts:+-o $opts}
2876 local flags=${4:-$MOUNT_FLAGS}
2878 local device=$MGSNID:/$FSNAME$FILESET
2879 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2880 echo "Bad mount command: opt=$flags $opts dev=$device " \
2886 # update mount option with skpath
2887 opts=$(add_sk_mntflag $opts)
2890 echo "Starting client: $client: $flags $opts $device $mnt"
2891 do_node $client mkdir -p $mnt
2892 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2893 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2895 #disable FILESET if not supported
2896 do_nodes $client lctl get_param -n \
2897 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2898 device=$MGSNID:/$FSNAME
2899 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2902 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2903 # Mount using nodemap key
2904 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2905 if $SK_UNIQUE_NM; then
2906 mountkey=$SK_PATH/nodemap/c0.key
2908 local prunedopts=$(echo $opts |
2909 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2910 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2913 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2917 set_default_debug_nodes $client
2918 set_params_clients $client
2929 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2931 [ "$3" ] && force=-f
2932 [ $running -eq 0 ] && return 0
2934 echo "Stopping client $client $mnt (opts:$force)"
2935 do_node $client lsof -t $mnt || need_kill=no
2936 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2937 pids=$(do_node $client lsof -t $mnt | sort -u);
2938 if [ -n "$pids" ]; then
2939 do_node $client kill -9 $pids || true
2943 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2945 if [ $busy -ne 0 ] ; then
2946 echo "$mnt is still busy, wait one second" && sleep 1
2947 do_node $client umount $force $mnt
2951 # Mount the file system on the MDS
2952 mount_mds_client() {
2953 local host=$(facet_active_host $SINGLEMDS)
2955 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2956 error "unable to mount $MOUNT2 on $host with ($?)"
2959 # Unmount the file system on the MDS
2960 umount_mds_client() {
2961 local host=$(facet_active_host $SINGLEMDS)
2962 zconf_umount $host $MOUNT2
2963 do_facet $SINGLEMDS "rmdir $MOUNT2"
2966 # nodes is comma list
2967 sanity_mount_check_nodes () {
2973 # FIXME: assume that all cluster nodes run the same os
2974 [ "$(uname)" = Linux ] || return 0
2977 for mnt in $mnts ; do
2978 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2979 mpts=\\\$(mount | grep -c $mnt' ');
2980 if [ \\\$running -ne \\\$mpts ]; then
2981 echo \\\$(hostname) env are INSANE!;
2984 [ $? -eq 0 ] || rc=1
2989 sanity_mount_check_servers () {
2990 [ -n "$CLIENTONLY" ] &&
2991 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2992 echo Checking servers environments
2994 # FIXME: modify get_facets to display all facets wo params
2995 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2999 for facet in ${facets//,/ }; do
3000 node=$(facet_host ${facet})
3001 mntpt=$(facet_mntpt $facet)
3002 sanity_mount_check_nodes $node $mntpt ||
3003 { error "server $node environments are insane!"; return 1; }
3007 sanity_mount_check_clients () {
3008 local clients=${1:-$CLIENTS}
3009 local mntpt=${2:-$MOUNT}
3010 local mntpt2=${3:-$MOUNT2}
3012 [ -z $clients ] && clients=$(hostname)
3013 echo Checking clients $clients environments
3015 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
3016 error "clients environments are insane!"
3019 sanity_mount_check () {
3020 sanity_mount_check_servers || return 1
3021 sanity_mount_check_clients || return 2
3024 # mount clients if not mouted
3025 zconf_mount_clients() {
3028 local opts=${3:-$MOUNT_OPTS}
3029 opts=${opts:+-o $opts}
3030 local flags=${4:-$MOUNT_FLAGS}
3031 local device=$MGSNID:/$FSNAME$FILESET
3032 if [ -z "$mnt" -o -z "$FSNAME" ]; then
3033 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
3038 echo "Starting client $clients: $flags $opts $device $mnt"
3039 do_nodes $clients mkdir -p $mnt
3040 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
3041 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
3042 # Mount with own nodemap key
3044 # Mount all server nodes first with per-NM keys
3045 for nmclient in ${clients//,/ }; do
3046 do_nodes $(comma_list $(all_server_nodes)) \
3047 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
3050 # set perms for per-nodemap keys else permission denied
3051 do_nodes $(comma_list $(all_nodes)) \
3052 "keyctl show | grep lustre | cut -c1-11 |
3054 xargs -IX keyctl setperm X 0x3f3f3f3f"
3055 local mountkey=$SK_PATH/$FSNAME-nmclient.key
3057 for nmclient in ${clients//,/ }; do
3058 if $SK_UNIQUE_NM; then
3059 mountkey=$SK_PATH/nodemap/c$i.key
3061 do_node $nmclient "! grep -q $mnt' ' \
3062 /proc/mounts || umount $mnt"
3063 local prunedopts=$(add_sk_mntflag $opts);
3064 prunedopts=$(echo $prunedopts | sed -e \
3065 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
3067 do_nodes $(comma_list $(all_server_nodes)) \
3070 do_node $nmclient $MOUNT_CMD $flags \
3071 $prunedopts $MGSNID:/$FSNAME $mnt ||
3076 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
3078 do_nodes $clients $MOUNT_CMD $flags $opts \
3079 $MGSNID:/$FSNAME $mnt || return 1
3081 #disable FILESET if not supported
3082 do_nodes $clients lctl get_param -n \
3083 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
3084 device=$MGSNID:/$FSNAME
3085 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
3089 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
3090 # Mount with nodemap key
3092 local mountkey=$SK_PATH/$FSNAME-nmclient.key
3093 for nmclient in ${clients//,/ }; do
3094 if $SK_UNIQUE_NM; then
3095 mountkey=$SK_PATH/nodemap/c$i.key
3097 local prunedopts=$(echo $opts | sed -e \
3098 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
3099 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
3102 running=\\\$(mount | grep -c $mnt' ');
3104 if [ \\\$running -eq 0 ] ; then
3106 $MOUNT_CMD $flags $prunedopts $device $mnt;
3109 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
3110 grep 'type lustre' | wc -l);
3111 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
3112 echo zconf_mount_clients FAILED: \
3113 mount count \\\$running, not matching \
3114 with mount count of 'type lustre' \
3115 \\\$lustre_mnt_count;
3119 exit \\\$rc" || return ${PIPESTATUS[0]}
3126 if $SHARED_KEY; then
3127 tmpopts=$(add_sk_mntflag $opts)
3130 running=\\\$(mount | grep -c $mnt' ');
3132 if [ \\\$running -eq 0 ] ; then
3134 $MOUNT_CMD $flags $tmpopts $device $mnt;
3137 exit \\\$rc" || return ${PIPESTATUS[0]}
3140 echo "Started clients $clients: "
3141 do_nodes $clients "mount | grep $mnt' '"
3143 set_default_debug_nodes $clients
3144 set_params_clients $clients
3149 zconf_umount_clients() {
3154 [ "$3" ] && force=-f
3156 echo "Stopping clients: $clients $mnt (opts:$force)"
3157 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
3158 if [ \\\$running -ne 0 ] ; then
3159 echo Stopping client \\\$(hostname) $mnt opts:$force;
3160 lsof $mnt || need_kill=no;
3161 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
3162 pids=\\\$(lsof -t $mnt | sort -u);
3163 if [ -n \\\"\\\$pids\\\" ]; then
3167 while umount $force $mnt 2>&1 | grep -q "busy"; do
3168 echo "$mnt is still busy, wait one second" && sleep 1;
3176 echo + $POWER_DOWN $node
3180 shutdown_node_hard () {
3182 local attempts=$SHUTDOWN_ATTEMPTS
3184 for i in $(seq $attempts) ; do
3187 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
3189 echo "waiting for $host to fail attempts=$attempts"
3190 [ $i -lt $attempts ] ||
3191 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
3197 local mnt=${2:-$MOUNT}
3200 if [ "$FAILURE_MODE" = HARD ]; then
3201 shutdown_node_hard $client
3203 zconf_umount_clients $client $mnt -f
3210 local facets="$(get_facets OST),$(get_facets MDS)"
3212 combined_mgs_mds || facets="$facets,mgs"
3214 for facet in ${facets//,/ }; do
3215 if [ $(facet_active_host $facet) == $host ]; then
3216 affected="$affected $facet"
3220 echo $(comma_list $affected)
3225 local host=${2:-$(facet_host $facet)}
3227 local label=$(convert_facet2label $facet)
3228 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
3231 facets_up_on_host () {
3234 local facets=$(facets_on_host $host)
3236 for facet in ${facets//,/ }; do
3237 if $(facet_up $facet $host); then
3238 affected_up="$affected_up $facet"
3242 echo $(comma_list $affected_up)
3247 local affected_facet
3248 local affected_facets
3250 if [[ "$FAILURE_MODE" = HARD ]]; then
3251 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
3252 dm_flakey_supported $facet; then
3253 affected_facets=$(affected_facets $facet)
3254 for affected_facet in ${affected_facets//,/ }; do
3255 unexport_dm_dev $affected_facet
3259 shutdown_node_hard $(facet_active_host $facet)
3268 echo + $POWER_UP $node
3281 local node=$(facet_active_host $facet)
3282 local sleep_time=${2:-10}
3284 if [ "$FAILURE_MODE" = HARD ]; then
3294 if [ "$FAILURE_MODE" = HARD ]; then
3297 if $LOAD_MODULES_REMOTE; then
3298 echo "loading modules on $node: $facet"
3299 do_rpc_nodes $node load_modules_local
3308 for facet in ${facets//,/ }; do
3309 hosts=$(expand_list $hosts $(facet_host $facet) )
3315 _check_progs_installed () {
3319 for prog in $progs; do
3320 if ! [ "$(which $prog)" -o "${!prog}" ]; then
3321 echo $prog missing on $(hostname)
3328 check_progs_installed () {
3332 do_rpc_nodes "$nodes" _check_progs_installed "$@"
3335 # recovery-scale functions
3337 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
3340 start_client_load() {
3343 local var=$(node_var_name $client)_load
3344 eval export ${var}=$load
3346 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
3347 END_RUN_FILE=$END_RUN_FILE \
3348 LOAD_PID_FILE=$LOAD_PID_FILE \
3349 TESTLOG_PREFIX=$TESTLOG_PREFIX \
3350 TESTNAME=$TESTNAME \
3351 DBENCH_LIB=$DBENCH_LIB \
3352 DBENCH_SRC=$DBENCH_SRC \
3353 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
3354 RECOVERY_SCALE_ENABLE_REMOTE_DIRS=$RECOVERY_SCALE_ENABLE_REMOTE_DIRS \
3355 RECOVERY_SCALE_ENABLE_STRIPED_DIRS=$RECOVERY_SCALE_ENABLE_STRIPED_DIRS \
3359 MPI_USER=$MPI_USER \
3361 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
3362 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
3363 num_clients=$(get_node_count ${CLIENTS//,/ }) \
3364 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
3365 ior_blockSize=$ior_blockSize \
3366 ior_blockUnit=$ior_blockUnit \
3367 ior_xferSize=$ior_xferSize ior_type=$ior_type \
3368 ior_DURATION=$ior_DURATION \
3369 ior_stripe_params=\\\"$ior_stripe_params\\\" \
3370 ior_custom_params=\\\"$ior_custom_param\\\" \
3371 mpi_ior_custom_threads=$mpi_ior_custom_threads \
3374 log "Started client load: ${load} on $client"
3376 # get the children process IDs
3377 local pids=$(ps --ppid $ppid -o pid= | xargs)
3378 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
3382 start_client_loads () {
3383 local -a clients=(${1//,/ })
3384 local numloads=${#CLIENT_LOADS[@]}
3386 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
3387 local load=$((nodenum % numloads))
3388 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
3390 # bug 22169: wait the background threads to start
3394 # only for remote client
3395 check_client_load () {
3397 local var=$(node_var_name $client)_load
3398 local testload=run_${!var}.sh
3400 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
3402 # bug 18914: try to connect several times not only when
3403 # check ps, but while check_node_health also
3407 while [ $RC = 254 -a $tries -gt 0 ]; do
3411 if ! check_node_health $client; then
3413 if [ $RC -eq 254 ]; then
3414 # FIXME: not sure how long we shuold sleep here
3418 echo "check node health failed: RC=$RC "
3422 # We can continue try to connect if RC=254
3423 # Just print the warning about this
3424 if [ $RC = 254 ]; then
3425 echo "got a return status of $RC from do_node while checking " \
3426 "node health on $client"
3429 # see if the load is still on the client
3432 while [ $RC = 254 -a $tries -gt 0 ]; do
3436 if ! do_node $client \
3437 "ps auxwww | grep -v grep | grep -q $testload"; then
3442 if [ $RC = 254 ]; then
3443 echo "got a return status of $RC from do_node while checking " \
3444 "(node health and 'ps') the client load on $client"
3445 # see if we can diagnose a bit why this is
3450 check_client_loads () {
3451 local clients=${1//,/ }
3455 for client in $clients; do
3456 check_client_load $client
3458 if [ "$rc" != 0 ]; then
3459 log "Client load failed on node $client, rc=$rc"
3465 restart_client_loads () {
3466 local clients=${1//,/ }
3467 local expectedfail=${2:-""}
3471 for client in $clients; do
3472 check_client_load $client
3474 if [ "$rc" != 0 -a "$expectedfail" ]; then
3475 local var=$(node_var_name $client)_load
3477 start_client_load $client ${!var}
3478 echo "Restarted client load ${!var}: on $client. Checking ..."
3479 check_client_load $client
3481 if [ "$rc" != 0 ]; then
3482 log "Client load failed to restart on node $client, rc=$rc"
3483 # failure one client load means test fail
3484 # we do not need to check other
3493 # Start vmstat and save its process ID in a file.
3498 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3501 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3502 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3505 # Display the nodes on which client loads failed.
3506 print_end_run_file() {
3510 [ -s $file ] || return 0
3512 echo "Found the END_RUN_FILE file: $file"
3515 # A client load will stop if it finds the END_RUN_FILE file.
3516 # That does not mean the client load actually failed though.
3517 # The first node in END_RUN_FILE is the one we are interested in.
3520 if [ -n "$node" ]; then
3521 local var=$(node_var_name $node)_load
3523 local prefix=$TESTLOG_PREFIX
3524 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3525 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3526 local debug_log=$(echo $stdout_log |
3527 sed 's/\(.*\)stdout/\1debug/')
3529 echo "Client load ${!var} failed on node $node:"
3535 # Stop the process which had its PID saved in a file.
3540 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3542 do_nodes $nodes "test -f $pid_file &&
3543 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3546 # Stop all client loads.
3547 stop_client_loads() {
3548 local nodes=${1:-$CLIENTS}
3551 # stop the client loads
3552 stop_process $nodes $pid_file
3554 # clean up the processes that started them
3555 [ -n "$CLIENT_LOAD_PIDS" ] &&
3556 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3558 # End recovery-scale functions
3561 # wait for a command to return the expected result
3563 # This will run @check on @node repeatedly until the output matches @expect
3564 # based on the supplied condition, or until @max_wait seconds have elapsed,
3565 # whichever comes first. @cond may be one of the normal bash operators,
3566 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3567 # in the caller to avoid unintentional evaluation by the shell in the caller.
3569 # If @max_wait is not specified, the condition will be checked for up to 90s.
3571 # If --verbose is passed as the first argument, the result is printed on each
3572 # value change, otherwise it is only printed after every 10s interval.
3574 # If --quiet is passed as the first/second argument, the do_node() command
3575 # will not print the remote command before executing it each time.
3577 # Using wait_update_cond() or related helper function is preferable to adding
3578 # a "long enough" wait for some state to change in the background, since
3579 # "long enough" may be too short due to tunables, system config, or running in
3580 # a VM, and must by necessity wait too long for most cases or risk failure.
3582 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3583 wait_update_cond() {
3587 [[ "$1" == "--verbose" ]] && verbose="$1" && shift || true
3588 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift || true
3594 local max_wait=${5:-90}
3598 local begin=$SECONDS
3602 while (( $waited <= $max_wait )); do
3603 result=$(do_node $quiet $node "$check")
3605 if eval [[ "'$result'" $cond "'$expect'" ]]; then
3606 [[ -z "$quiet" ]] || return 0
3607 [[ -z "$result" || $waited -le $sleep ]] ||
3608 echo "Updated after ${waited}s: want '$expect' got '$result'"
3611 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3612 [[ -n "$quiet" || -z "$prev_result" ]] ||
3613 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3614 prev_result="$result"
3616 (( $waited % $print != 0 )) || {
3617 [[ -z "$quiet" ]] &&
3618 echo "Waiting $((max_wait - waited))s for '$expect'"
3622 waited=$((SECONDS - begin))
3625 [[ -n "$quiet" ]] ||
3626 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3631 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3636 [[ "$1" == "--verbose" ]] && verbose="$1" && shift || true
3637 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift || true
3644 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3647 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3648 wait_update_facet_cond() {
3652 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3653 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3655 local node=$(facet_active_host $1)
3661 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3664 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3665 wait_update_facet() {
3669 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3670 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3672 local node=$(facet_active_host $1)
3677 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3680 sync_all_data_mdts() {
3681 do_nodes $(mdts_nodes) "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3684 sync_all_data_osts() {
3685 do_nodes $(osts_nodes) "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3686 grep -v 'Found no match'
3695 local zfs_wait=${2:-5}
3697 # the occupied disk space will be released
3698 # only after TXGs are committed
3699 if [[ $(facet_fstype $1) == zfs ]]; then
3700 echo "sleep $zfs_wait for ZFS $(facet_type $1)"
3708 local lwm=$3 #low watermark
3709 local size_mb #how many MB should we write to pass watermark
3710 local ost_name=$(ostname_from_index $ost_idx)
3712 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3714 if (( $free_kb / 1024 > lwm )); then
3715 size_mb=$((free_kb / 1024 - lwm))
3717 #If 10% of free space cross low watermark use it
3718 if (( $free_kb / 10240 > size_mb )); then
3719 size_mb=$((free_kb / 10240))
3721 #At least we need to store 1.1 of difference between
3722 #free space and low watermark
3723 size_mb=$((size_mb + size_mb / 10))
3725 if (( lwm <= $free_kb / 1024 )) ||
3726 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3727 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3728 $DD of=$DIR/${filename}.fill_ost$ost_idx \
3729 count=$size_mb oflag=append conv=notrunc
3734 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3735 echo "OST still has $((free_kb / 1024)) MB free"
3738 # This checks only the primary MDS
3739 ost_watermarks_get() {
3741 local ost_name=$(ostname_from_index $ost_idx)
3742 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3744 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3745 osp.$mdtosc_proc.reserved_mb_high)
3746 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3747 osp.$mdtosc_proc.reserved_mb_low)
3752 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3753 ost_watermarks_set() {
3757 local ost_name=$(ostname_from_index $ost_idx)
3758 local facets=$(get_facets MDS)
3760 do_nodes $(mdts_nodes) $LCTL set_param -n \
3761 osp.*$ost_name*.reserved_mb_low=$lwm \
3762 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3764 # sleep to ensure we see the change
3768 ost_watermarks_set_low_space() {
3770 local wms=$(ost_watermarks_get $ost_idx)
3771 local ost_name=$(ostname_from_index $ost_idx)
3773 local old_lwm=$(echo $wms | awk '{ print $1 }')
3774 local old_hwm=$(echo $wms | awk '{ print $2 }')
3776 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3777 # minimal extension size is 64M
3779 if (( $blocks / 1024 > 50 )); then
3780 new_lwm=$((blocks / 1024 - 50))
3782 local new_hwm=$((new_lwm + 5))
3784 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3785 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3788 # Set watermarks to ~current available space & then write data to fill it
3789 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3790 # internal statfs used by the stripe allocator
3792 # first parameter is the filename-prefix, which must get under t-f cleanup
3793 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3794 ost_watermarks_set_enospc() {
3798 local ost_name=$(ostname_from_index $ost_idx)
3799 local facets=$(get_facets MDS)
3803 for MDS in ${facets//,/ }; do
3804 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3806 do_facet $MDS $LCTL get_param -n \
3807 osp.$mdtosc_proc.reserved_mb_high ||
3808 skip "remote MDS does not support reserved_mb_high"
3811 wms=$(ost_watermarks_set_low_space $ost_idx)
3812 local new_lwm=$(echo $wms | awk '{ print $4 }')
3813 fill_ost $filename $ost_idx $new_lwm
3814 #First enospc could execute orphan deletion so repeat
3815 fill_ost $filename $ost_idx $new_lwm
3819 ost_watermarks_enospc_delete_files() {
3823 rm -f $DIR/${filename}.fill_ost$ost_idx
3825 wait_delete_completed
3829 # clean up from "ost_watermarks_set_enospc"
3830 ost_watermarks_clear_enospc() {
3836 ost_watermarks_enospc_delete_files $filename $ost_idx
3837 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3838 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3841 wait_delete_completed_mds() {
3842 local max_wait=${1:-60}
3844 local stime=$(date +%s)
3848 local mdts=$(mdts_nodes)
3850 # find MDS with pending deletions
3851 for node in ${mdts//,/ }; do
3852 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3853 2>/dev/null | calc_sum)
3854 if [[ $changes -eq 0 ]]; then
3857 mds2sync="$mds2sync $node"
3859 if [ -z "$mds2sync" ]; then
3860 wait_zfs_commit $SINGLEMDS
3863 mds2sync=$(comma_list $mds2sync)
3865 # sync MDS transactions
3866 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3868 # wait till all changes are sent and commmitted by OSTs
3869 # for ldiskfs space is released upon execution, but DMU
3870 # do this upon commit
3873 while [[ $WAIT -ne $max_wait ]]; do
3874 changes=$(do_nodes $mds2sync \
3875 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3876 #echo "$node: $changes changes on all"
3877 if [[ $changes -eq 0 ]]; then
3878 wait_zfs_commit $SINGLEMDS
3880 # the occupied disk space will be released
3881 # only after TXGs are committed
3882 wait_zfs_commit ost1
3890 echo "Delete is not completed in $((etime - stime)) seconds"
3891 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3898 # we can use "for" here because we are waiting the slowest
3899 for host in ${hostlist//,/ }; do
3900 check_network "$host" 900
3902 while ! do_nodes $hostlist hostname; do sleep 5; done
3909 for facet in ${facetlist//,/ }; do
3910 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3912 wait_for_host $hostlist
3915 _wait_recovery_complete () {
3918 # Use default policy if $2 is not passed by caller.
3919 local MAX=${2:-$(max_recovery_time)}
3924 while [ $WAIT -lt $MAX ]; do
3925 STATUS=$(lctl get_param -n $param | grep status)
3927 [[ $STATUS == "status: COMPLETE" ||
3928 $STATUS == "status: INACTIVE" ]] && return 0
3931 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3933 echo "$param recovery not done in $MAX sec. $STATUS"
3937 wait_recovery_complete () {
3940 # with an assumption that at_max is the same on all nodes
3941 local MAX=${2:-$(max_recovery_time)}
3944 if [ "$FAILURE_MODE" = HARD ]; then
3945 facets=$(facets_on_host $(facet_active_host $facet))
3947 echo affected facets: $facets
3949 facets=${facets//,/ }
3950 # We can use "for" here because we are waiting the slowest.
3951 # The mgs not having the recovery_status proc entry, exclude it
3952 # from the facet list.
3953 for facet in ${facets//mgs/ }; do
3954 local var_svc=${facet}_svc
3955 local param="*.${!var_svc}.recovery_status"
3957 local host=$(facet_active_host $facet)
3958 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3962 wait_mds_ost_sync () {
3963 # just because recovery is done doesn't mean we've finished
3964 # orphan cleanup. Wait for llogs to get synchronized.
3965 echo "Waiting for orphan cleanup..."
3966 # MAX value includes time needed for MDS-OST reconnection
3967 local MAX=$(( TIMEOUT * 2 ))
3968 local WAIT_TIMEOUT=${1:-$MAX}
3971 local list=$(mdts_nodes)
3972 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3973 if ! do_facet $SINGLEMDS \
3974 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3976 # old way, use mds_sync
3979 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3982 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3983 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3984 local -a sync=($(do_nodes $list "$cmd"))
3987 for ((i=0; i<${#sync[@]}; i++)); do
3989 [ ${sync[$i]} -eq 1 ] && continue
3991 [ ${sync[$i]} -eq 0 ] && continue
3993 # there is a not finished MDS-OST synchronization
3997 sleep 2 # increase waiting time and cover statfs cache
3998 [ ${con} -eq 1 ] && return 0
3999 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
4003 # show which nodes are not finished.
4004 cmd=$(echo $cmd | sed 's/-n//')
4005 do_nodes $list "$cmd"
4006 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
4010 # Wait OSTs to be active on both client and MDT side.
4012 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
4013 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
4014 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
4015 error "wait_update OSTs up on client failed"
4017 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
4018 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
4019 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
4020 error "wait_update OSTs up on MDT0000 failed"
4023 wait_destroy_complete () {
4024 echo "Waiting for MDT destroys to complete"
4025 # MAX value shouldn't be big as this mean server responsiveness
4026 # never increase this just to make test pass but investigate
4027 # why it takes so long time
4030 local mdts=$(mdts_nodes)
4031 while [ $WAIT -lt $MAX ]; do
4032 local -a RPCs=($(do_nodes $mdts $LCTL get_param -n osp.*.destroys_in_flight))
4036 for ((i=0; i<${#RPCs[@]}; i++)); do
4037 [ ${RPCs[$i]} -eq 0 ] && continue
4038 # there are still some destroy RPCs in flight
4042 [ ${con} -eq 1 ] && return 0 # done waiting
4044 echo "Waiting ${WAIT}s for local destroys to complete"
4047 echo "MDT destroys weren't done in $MAX sec."
4051 fstrim_inram_devs() {
4056 [[ "$(facet_fstype ost1)" = "ldiskfs" ]] || return 0
4057 [[ $OSTDEVBASE == */tmp/* ]] || return 0
4059 for (( i=1; i <= $OSTCOUNT; i++)); do
4061 [[ ${!v} != "yes" ]] && continue
4062 do_facet ost$i "fstrim $(facet_mntpt ost$i)" &
4065 [[ -n $pids ]] && wait $pids
4070 wait_delete_completed() {
4071 wait_delete_completed_mds $1 || return $?
4072 wait_destroy_complete || return $?
4082 # conf-sanity 31 takes a long time cleanup
4083 while [ $WAIT -lt 300 ]; do
4084 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
4085 lctl dl | grep ' ST ' || true")
4086 [ -z "${running}" ] && return 0
4087 echo "waited $WAIT for${running}"
4088 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
4090 WAIT=$((WAIT + INTERVAL))
4092 echo "service didn't stop after $WAIT seconds. Still running:"
4097 wait_remote_prog () {
4103 [ "$PDSH" = "no_dsh" ] && return 0
4105 while [ $WAIT -lt $2 ]; do
4106 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
4107 grep -v grep) || true
4108 [ -z "${running}" ] && return 0 || true
4109 echo "waited $WAIT for: "
4111 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
4113 WAIT=$((WAIT + INTERVAL))
4115 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
4116 grep -v grep | awk '{print $2}')
4117 [ -z "$pids" ] && return 0
4118 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
4119 # FIXME: not portable
4120 for pid in $pids; do
4121 cat /proc/${pid}/status || true
4122 cat /proc/${pid}/wchan || true
4124 kill -9 $pid || true
4133 local clients=${1:-$CLIENTS}
4136 if [[ -z "$clients" ]]; then
4137 $LFS df $MOUNT > /dev/null || rc=$?
4139 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
4146 local clients=${1:-$CLIENTS}
4149 _lfs_df_check "$clients" || rc=$?
4151 check_lfs_df_ret_val $rc
4155 # not every config has many clients
4161 (( MDSCOUNT == 1 )) && return
4163 # wait so that statfs data on MDT expire
4164 local delay=$(do_facet mds1 $LCTL \
4165 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
4167 [ -n "$delay" ] || error "fail to get maxage"
4169 local mdts=$(mdts_nodes)
4171 # initiate statfs RPC, all to all MDTs
4172 do_nodes $mdts $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
4173 do_nodes $mdts $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
4177 # usually checked on particular client or locally
4182 # usage: client_evicted client [evictor, mds1 by default]
4183 # return true if \a client was evicted by \a evictor in current test
4185 local testid=$(echo $TESTNAME | tr '_' ' ')
4187 local facet=${2:-mds1}
4188 local dev=$(facet_svc $facet)
4191 $PDSH $client "dmesg | tac | sed \"/$testid/,$ d\"" |
4192 grep -q "client was evicted by ${dev}"
4195 client_reconnect_try() {
4196 local f=$MOUNT/recon
4199 if [ -z "$CLIENTS" ]; then
4200 $LFS df $MOUNT; uname -n >> $f
4202 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
4204 echo "Connected clients: $(cat $f)"
4205 ls -l $f > /dev/null
4209 client_reconnect() {
4210 # one client_reconnect_try call does not always do the job...
4212 client_reconnect_try && break
4217 affected_facets () {
4220 local host=$(facet_active_host $facet)
4221 local affected=$facet
4223 if [ "$FAILURE_MODE" = HARD ]; then
4224 affected=$(facets_up_on_host $host)
4230 local E2FSCK_ON_MDT0=false
4231 if [ "$1" == "--fsck" ]; then
4233 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4245 #Because it will only get up facets, we need get affected
4246 #facets before shutdown
4247 #For HARD Failure mode, it needs make sure facets on the same
4248 #HOST will only be shutdown and reboot once
4249 for facet in ${facets//,/ }; do
4250 local affected_facet
4252 #check whether facet has been included in other affected facets
4253 for ((index=0; index<$total; index++)); do
4254 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
4257 if [ $skip -eq 0 ]; then
4258 affecteds[$total]=$(affected_facets $facet)
4263 for ((index=0; index<$total; index++)); do
4264 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
4265 local host=$(facet_active_host $facet)
4266 echo "Failing ${affecteds[index]} on $host"
4267 shutdown_facet $facet
4270 echo "$(date +'%H:%M:%S (%s)') shut down"
4275 for facet in ${facets//,/ }; do
4276 local host=$(facet_active_host $facet)
4278 hostlist=$(expand_list $hostlist $host)
4279 local fhost=$(facet_host $facet)
4280 local ffhost=$(facet_failover_host $facet)
4281 echo "facet: $facet facet_host: $fhost facet_failover_host: $ffhost"
4282 if [ $(facet_host $facet) = \
4283 $(facet_failover_host $facet) ]; then
4284 waithostlist=$(expand_list $waithostlist $host)
4288 if [ "$FAILURE_MODE" = HARD ]; then
4289 for host in ${hostlist//,/ }; do
4292 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted; waithostlist: $waithostlist"
4293 # We need to wait the rebooted hosts in case if
4294 # facet_HOST == facetfailover_HOST
4295 if ! [ -z "$waithostlist" ]; then
4296 wait_for_host $waithostlist
4297 if $LOAD_MODULES_REMOTE; then
4298 echo "loading modules on $waithostlist"
4299 do_rpc_nodes $waithostlist load_modules_local
4306 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
4307 change_active $SINGLEMDS
4310 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
4311 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
4315 for ((index=0; index<$total; index++)); do
4316 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
4317 change_active ${affecteds[index]}
4321 init_facets_vars_simple
4323 # start mgs first if it is affected
4324 if ! combined_mgs_mds &&
4325 list_member ${affecteds[index]} mgs; then
4326 mount_facet mgs || error "Restart of mgs failed"
4327 affecteds[index]=$(exclude_items_from_list \
4328 ${affecteds[index]} mgs)
4330 if [ -n "${affecteds[index]}" ]; then
4331 echo mount facets: ${affecteds[index]}
4332 mount_facets ${affecteds[index]} &
4336 for ((index=0; index<$total; index++)); do
4337 if [ -n "${affecteds[index]}" ]; then
4338 wait ${mountpids[index]}
4342 do_nodes $(comma_list $(all_nodes)) \
4343 "keyctl show | grep lustre | cut -c1-11 |
4345 xargs -IX keyctl setperm X 0x3f3f3f3f"
4348 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
4350 if [ "$FAILURE_MODE" = HARD ]; then
4351 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
4352 if ! [ -z "$hostlist" ]; then
4353 wait_for_host $hostlist
4354 if $LOAD_MODULES_REMOTE; then
4355 echo "loading modules on $hostlist"
4356 do_rpc_nodes $hostlist load_modules_local
4361 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
4366 do_facet $facet "sync; sync; sync"
4369 # make sure there will be no seq change
4370 local clients=${CLIENTS:-$HOSTNAME}
4371 local f=fsa-\\\$\(hostname\)
4372 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
4373 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
4375 local svc=${facet}_svc
4376 do_facet $facet $LCTL --device ${!svc} notransno
4378 # If a ZFS OSD is made read-only here, its pool is "freezed". This
4379 # in-memory state has to be cleared by either rebooting the host or
4380 # exporting and reimporting the pool.
4382 # Although the uberblocks are not updated when a pool is freezed,
4383 # transactions are still written to the disks. Modified blocks may be
4384 # cached in memory when tests try reading them back. The
4385 # export-and-reimport process also evicts any cached pool data from
4386 # memory to provide the correct "data loss" semantics.
4388 # In the test framework, the exporting and importing operations are
4389 # handled by stop() and mount_facet() separately, which are used
4390 # inside fail() and fail_abort().
4392 set_dev_readonly $facet
4393 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4394 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4397 replay_barrier_nodf() {
4398 local facet=$1 echo running=${running}
4399 do_facet $facet "sync; sync; sync"
4400 local svc=${facet}_svc
4401 echo Replay barrier on ${!svc}
4402 do_facet $facet $LCTL --device ${!svc} notransno
4403 set_dev_readonly $facet
4404 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4405 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4408 replay_barrier_nosync() {
4409 local facet=$1 echo running=${running}
4410 local svc=${facet}_svc
4411 echo Replay barrier on ${!svc}
4412 do_facet $facet $LCTL --device ${!svc} notransno
4413 set_dev_readonly $facet
4414 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4415 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4419 # Get Lustre client uuid for a given Lustre mount point.
4422 local mntpnt=${1:-$MOUNT}
4424 echo -n $($LFS getname -u $mntpnt)
4427 mds_evict_client() {
4428 local mntpnt=${1:-$MOUNT}
4429 local uuid=$(get_client_uuid $mntpnt)
4431 do_facet $SINGLEMDS \
4432 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
4435 ost_evict_client() {
4436 local mntpnt=${1:-$MOUNT}
4437 local uuid=$(get_client_uuid $mntpnt)
4440 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
4445 local clients=${CLIENTS:-$HOSTNAME}
4447 SK_NO_KEY_save=$SK_NO_KEY
4449 export SK_NO_KEY=false
4451 facet_failover $* || error "failover: $?"
4452 export SK_NO_KEY=$SK_NO_KEY_save
4453 # to initiate all OSC idling connections
4455 wait_clients_import_ready "$clients" "$facets"
4456 clients_up || error "post-failover stat: $?"
4462 facet_failover $facet
4467 local abort_type=${2:-"abort_recovery"}
4470 change_active $facet
4471 wait_for_facet $facet
4472 mount_facet $facet -o $abort_type
4473 clients_up || echo "first stat failed: $?"
4474 clients_up || error "post-failover stat: $?"
4478 # LU-16159: abort recovery will cancel update logs, which may leave broken
4479 # directories in the system, remove name entry if necessary
4480 fail_abort_cleanup() {
4482 find $DIR/$tdir -depth | while read D; do
4483 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
4487 host_nids_address() {
4491 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
4495 local ipv4_re='^([0-9]{1,3}\.){3,3}[0-9]{1,3}$'
4497 if ! [[ $1 =~ $ipv4_re ]]; then
4501 local quads=(${1//\./ })
4503 (( ${#quads[@]} == 4)) || return 1
4505 (( quads[0] < 256 && quads[1] < 256 &&
4506 quads[2] < 256 && quads[3] < 256 )) || return 1
4512 local ipv6_re='^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$'
4514 if ! [[ $1 =~ $ipv6_re ]]; then
4519 for segment in ${1//:/ }; do
4520 ((0x$segment <= 0xFFFF)) || return 1
4527 if [[ "$1" == '*' ]]; then
4529 elif ip_is_v4 "$1" || ip_is_v6 "$1" ; then
4532 local addr nidlist large_nidlist
4533 local iplist=$(do_node $1 hostname -I | sed "s/$1://")
4535 for addr in ${iplist}; do
4538 nidlist="${nidlist:+$nidlist,}${nid}" ||
4539 large_nidlist="${large_nidlist:+$large_nidlist,}${nid}"
4541 if [[ -n $nidlist ]] && [[ -n $large_nidlist ]]; then
4542 if ${FORCE_LARGE_NID}; then
4543 echo "$large_nidlist"
4547 elif [[ -n $nidlist ]]; then
4549 elif [[ -n $large_nidlist ]]; then
4550 echo "$large_nidlist"
4558 if [[ -n "$NETTYPE" ]]; then
4559 h2name_or_ip "$1" "$NETTYPE"
4561 h2name_or_ip "$1" "$2"
4564 declare -fx h2nettype
4566 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4567 # expressions format. As a bonus we can then just pass in those variables
4568 # to pdsh. What this function does is take a HOSTLIST type string and
4569 # expand it into a space deliminated list for us.
4577 [ -z "$hostlist" ] && return
4579 # Translate the case of [..],..,[..] to [..] .. [..]
4580 list="${hostlist/],/] }"
4582 [[ "$front" == *,* ]] && {
4585 list=${list/${old}/${new}}
4588 for item in $list; do
4589 # Test if we have any []'s at all
4590 if [ "$item" != "${item/\[/}" ]; then {
4591 # Expand the [*] into list
4595 if [ "$name" != "$item" ]; then
4596 group=${item#$name[*}
4599 for range in ${group//,/ }; do
4605 # Number of leading zeros
4608 end=$(echo $end | sed 's/0*//')
4609 [[ -z "$end" ]] && end=0
4610 [[ $padlen2 -gt $padlen ]] && {
4611 [[ $padlen2 -eq ${#end} ]] &&
4615 begin=$(echo $begin | sed 's/0*//')
4616 [ -z $begin ] && begin=0
4618 if [ ! -z "${begin##[!0-9]*}" ]; then
4619 order=$(seq -f "%0${padlen}g" $begin $end)
4621 order=$(eval echo {$begin..$end});
4624 for num in $order; do
4625 value="${name#*,}${num}${back}"
4627 [ "$value" != "${value/\[/}" ] && {
4628 value=$(hostlist_expand "$value")
4630 myList="$myList $value"
4635 myList="$myList $item"
4638 myList=${myList//,/ }
4639 myList=${myList:1} # Remove first character which is a space
4641 # Filter any duplicates without sorting
4643 myList="${list%% *}"
4645 while [[ "$list" != ${myList##* } ]]; do
4646 local tlist=" $list"
4648 list=${tlist// ${list%% *} / }
4650 myList="$myList ${list%% *}"
4652 myList="${myList%* }";
4654 # We can select an object at an offset in the list
4657 for item in $myList; do
4659 [ $cnt -eq $offset ] && {
4663 [ $(get_node_count $myList) -ne 1 ] && myList=""
4672 [ "$facet" == client ] && echo -n $HOSTNAME && return
4673 varname=${facet}_HOST
4674 if [ -z "${!varname}" ]; then
4675 if [ "${facet:0:3}" == "ost" ]; then
4676 local fh=${facet%failover}_HOST
4677 eval export ${facet}_HOST=${!fh}
4678 if [ -z "${!varname}" ]; then
4679 eval export ${facet}_HOST=${ost_HOST}
4681 elif [ "${facet:0:3}" == "mdt" -o \
4682 "${facet:0:3}" == "mds" -o \
4683 "${facet:0:3}" == "mgs" ]; then
4685 if [ "${facet}" == "mgsfailover" ] &&
4686 [ -n "$mds1failover_HOST" ]; then
4687 temp=$mds1failover_HOST
4691 eval export ${facet}_HOST=$temp
4697 facet_failover_host() {
4701 var=${facet}failover_HOST
4702 if [ -n "${!var}" ]; then
4707 if combined_mgs_mds && [ $facet == "mgs" ] &&
4708 [ -n "$mds1failover_HOST" ]; then
4709 echo $mds1failover_HOST
4713 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4714 "${facet:0:3}" == "mgs" ]; then
4716 eval export ${facet}failover_host=${mds_HOST}
4721 if [[ $facet == ost* ]]; then
4722 eval export ${facet}failover_host=${ost_HOST}
4730 local activevar=${facet}active
4732 if [ -f $TMP/${facet}active ] ; then
4733 source $TMP/${facet}active
4736 active=${!activevar}
4737 if [ -z "$active" ] ; then
4744 facet_active_host() {
4745 facet_host $(facet_active $1)
4748 # Get the passive failover partner host of facet.
4749 facet_passive_host() {
4751 [[ $facet = client ]] && return
4753 local host=${facet}_HOST
4754 local failover_host=${facet}failover_HOST
4755 local active_host=$(facet_active_host $facet)
4757 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4759 if [[ $active_host = ${!host} ]]; then
4760 echo -n ${!failover_host}
4770 for facet in ${facetlist//,/ }; do
4771 local failover=${facet}failover
4772 local host=`facet_host $failover`
4774 [ -z "$host" ] && return
4776 local curactive=`facet_active $facet`
4778 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4779 eval export ${facet}active=$facet
4781 eval export ${facet}active=$failover
4783 # save the active host for this facet
4784 local activevar=${facet}active
4786 echo "$activevar=${!activevar}" > $TMP/$activevar
4787 [[ $facet = mds1 ]] && combined_mgs_mds && \
4788 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4789 local TO=`facet_active_host $facet`
4790 echo "Failover $facet to $TO"
4798 # do not strip off hostname if verbose, b=19215
4799 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4800 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4806 if [ "$HOST" = "$HOSTNAME" ]; then
4808 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4809 echo "cannot run remote command on $HOST with $myPDSH"
4812 if $VERBOSE && [[ -z "$quiet" ]]; then
4813 echo "CMD: $HOST $*" >&2
4814 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4817 if [[ "$myPDSH" == "rsh" ]] ||
4818 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4819 # we need this because rsh and pdsh do not return
4820 # exit code of an executed command
4821 local command_status="$TMP/cs"
4822 eval $myPDSH $HOST ":> $command_status"
4823 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4824 PATH=\$PATH:/sbin:/usr/sbin;
4826 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4827 echo command failed >$command_status"
4828 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4832 if [[ -n "$verbose" ]]; then
4833 # print HOSTNAME for myPDSH="no_dsh"
4834 if [[ $myPDSH = no_dsh ]]; then
4836 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4837 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4838 sed -e "s/^/${HOSTNAME}: /"
4841 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4842 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4846 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4847 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4848 sed "s/^${HOST}: //"
4850 return ${PIPESTATUS[0]}
4854 # Execute exact command line on host
4856 # The \a host may be on a local or remote node, which is determined at
4857 # the time the command is run. Does careful argument quotation to
4858 # ensure that the exact command line is executed without any globbing,
4859 # substitution, or shell interpretation on the remote side. Does not
4860 # support --verbose or --quiet. Does not include "$host: " prefixes on
4861 # output. See also do_facet_vp().
4863 # usage: do_node_vp "$host" "$command" "$arg"...
4868 if [[ "$host" == "$HOSTNAME" ]]; then
4869 bash -c "$(printf -- ' %q' "$@")"
4873 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4874 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4878 # -N Disable hostname: prefix on lines of output.
4880 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4883 single_local_node () {
4884 [ "$1" = "$HOSTNAME" ]
4887 # Outputs environment variable assignments that should be passed to remote nodes
4891 local facets=$(get_facets)
4894 for var in ${!MODOPTS_*}; do
4895 value=${!var//\"/\\\"}
4896 echo -n " ${var}=\"$value\""
4899 for facet in ${facets//,/ }; do
4901 if [ -n "${!var}" ]; then
4902 echo -n " $var=${!var}"
4906 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4907 if [ -n "${!var}" ]; then
4908 echo -n " $var=${!var}"
4912 for var in VERBOSE; do
4913 if [ -n "${!var}" ]; then
4914 echo -n " $var=${!var}"
4918 if [ -n "$FSTYPE" ]; then
4919 echo -n " FSTYPE=$FSTYPE"
4922 for var in LNETLND NETTYPE; do
4923 if [ -n "${!var}" ]; then
4924 echo -n " $var=${!var}"
4933 # do not strip off hostname if verbose, b=19215
4934 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4935 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4940 if single_local_node $rnodes; then
4941 do_node $verbose $quiet $rnodes "$@"
4945 # This is part from do_node
4948 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4949 echo "cannot run remote command on $rnodes with $myPDSH" &&
4952 export FANOUT=$(get_node_count "${rnodes//,/ }")
4953 if $VERBOSE && [[ -z "$quiet" ]]; then
4954 echo "CMD: $rnodes $*" >&2
4955 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4958 # do not replace anything from pdsh output if -N is used
4959 # -N Disable hostname: prefix on lines of output.
4960 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4961 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4963 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4965 return ${PIPESTATUS[0]}
4969 # Execute commands on a single service's host
4971 # The \a facet (service) may be on a local or remote node, which is
4972 # determined at the time the command is run.
4974 # usage: do_facet $facet command [arg ...]
4979 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4980 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4984 local host=$(facet_active_host $facet)
4986 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4987 do_node $verbose $quiet $host "$@"
4991 # Execute exact command line on the host of a facet
4993 # The \a facet (service) may be on a local or remote node, which is
4994 # determined at the time the command is run. Does careful argument
4995 # quotation to ensure that the exact command line is executed without
4996 # any globbing, substitution, or shell interpretation on the remote
4997 # side. Does not support --verbose or --quiet. Does not include
4998 # "$host: " prefixes on output.
5000 # usage: do_facet_vp "$facet" "$command" "$arg"...
5003 local host=$(facet_active_host "$facet")
5006 if [[ -z "$host" ]]; then
5007 echo "no host defined for facet ${facet}" >&2
5011 do_node_vp "$host" "$@"
5014 # Function: do_facet_random_file $FACET $FILE $SIZE
5015 # Creates FILE with random content on the given FACET of given SIZE
5017 do_facet_random_file() {
5021 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
5022 do_facet $facet "$cmd 2>/dev/null"
5025 do_facet_create_file() {
5029 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
5030 do_facet $facet "$cmd 2>/dev/null"
5034 do_nodes --verbose "$@"
5040 # make sure its not already running
5042 rm -f $TMP/${facet}active
5043 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
5045 # make sure in-tree ldiskfs is loaded before mkfs
5046 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
5047 load_module ../ldiskfs/ldiskfs
5050 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
5052 if [[ $(facet_fstype $facet) == zfs ]]; then
5054 # After formatting a ZFS target, "cachefile=none" property will
5055 # be set on the ZFS storage pool so that the pool is not
5056 # automatically imported on system startup. And then the pool
5057 # will be exported so as to leave the importing and exporting
5058 # operations handled by mount_facet() and stop() separately.
5060 refresh_partition_table $facet $(facet_vdevice $facet)
5061 disable_zpool_cache $facet
5066 # Device formatted as ost
5069 local DEVNAME=OSTDEV$num
5071 local fstype=$(facet_fstype ost$num)
5075 local dev=ost${num}_dev
5076 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
5077 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
5078 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
5080 #try $OSTZFSDEVn - independent of vdev
5081 DEVNAME=OSTZFSDEV$num
5082 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
5086 error "unknown fstype!";;
5092 # Physical device location of data
5098 local fstype=$(facet_fstype ost$num)
5102 # vdevs are not supported by ldiskfs
5105 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
5106 # Device formatted by zfs
5108 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
5112 error "unknown fstype!";;
5118 # Logical device formatted for lustre
5121 local DEVNAME=MDSDEV$num
5123 local fstype=$(facet_fstype mds$num)
5127 local dev=mds${num}_dev
5128 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
5129 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
5130 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
5132 # try $MDSZFSDEVn - independent of vdev
5133 DEVNAME=MDSZFSDEV$num
5134 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
5138 error "unknown fstype!";;
5144 # Physical location of data
5148 local fstype=$(facet_fstype mds$num)
5152 # vdevs are not supported by ldiskfs
5155 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
5156 # Device formatted by ZFS
5157 local DEVNAME=MDSDEV$num
5158 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
5162 error "unknown fstype!";;
5170 local fstype=$(facet_fstype mgs)
5174 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
5175 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
5176 DEVPTR=$(mdsdevname 1)
5178 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
5182 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
5183 ( [ -z "$MGSZFSDEV" ] &&
5184 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
5185 DEVPTR=$(mdsdevname 1)
5187 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
5192 error "unknown fstype!";;
5201 local fstype=$(facet_fstype mgs)
5205 # vdevs are not supported by ldiskfs
5208 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
5209 ( [ -z "$MGSDEV" ] &&
5210 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
5211 VDEVPTR=$(mdsvdevname 1)
5212 elif [ -n "$MGSDEV" ]; then
5218 error "unknown fstype!";;
5226 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
5228 local var=${facet}_MOUNT
5229 eval mntpt=${!var:-${MOUNT}-$facet}
5236 local dev=$(facet_device $facet)
5237 local mnt=${2:-$(facet_mntpt $facet)}
5241 if dm_flakey_supported $facet; then
5242 dm_dev=$(dm_create_dev $facet $dev)
5243 [[ -n "$dm_dev" ]] || dm_dev=$dev
5245 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
5246 export_dm_dev $facet $dm_dev
5248 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
5253 local dev=$(facet_device $facet)
5254 local mnt=${2:-$(facet_mntpt $facet)}
5256 do_facet $facet $UMOUNT $mnt
5260 echo -n "$1" | tr -c '[:alnum:]\n' '_'
5265 local ds=$(facet_device $facet)
5266 local mnt=${2:-$(facet_mntpt $facet)}
5271 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
5272 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
5273 do_facet $facet $ZFS set canmount=noauto $ds
5275 # The "legacy" mount method is used here because "zfs unmount $mnt"
5276 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
5277 # targets are not available at the time, the stat(2) on $MOUNT will
5280 do_facet $facet $ZFS set mountpoint=legacy $ds
5281 do_facet $facet mount -t zfs $ds $mnt
5282 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
5283 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
5288 local ds=$(facet_device $facet)
5289 local mnt=${2:-$(facet_mntpt $facet)}
5290 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
5291 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
5292 local mntpt=${!var_mntpt}
5293 local canmnt=${!var_canmnt}
5297 do_facet $facet umount $mnt
5298 do_facet $facet $ZFS set mountpoint=$mntpt $ds
5299 do_facet $facet $ZFS set canmount=$canmnt $ds
5306 local fstype=$(facet_fstype $facet)
5308 mount_$fstype $facet $mnt
5314 local fstype=$(facet_fstype $facet)
5316 unmount_$fstype $facet $mnt
5323 # make sure we are using the primary server, so test-framework will
5324 # be able to clean up properly.
5325 activemds=`facet_active mds1`
5326 if [ $activemds != "mds1" ]; then
5330 local clients=$CLIENTS
5331 [ -z $clients ] && clients=$(hostname)
5333 zconf_umount_clients $clients $MOUNT "$*" || true
5334 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
5336 [ -n "$CLIENTONLY" ] && return
5338 # The add fn does rm ${facet}active file, this would be enough
5339 # if we use do_facet <facet> only after the facet added, but
5340 # currently we use do_facet mds in local.sh
5342 for num in `seq $MDSCOUNT`; do
5344 rm -f ${TMP}/mds${num}active
5346 combined_mgs_mds && rm -f $TMP/mgsactive
5348 for num in `seq $OSTCOUNT`; do
5350 rm -f $TMP/ost${num}active
5353 if ! combined_mgs_mds ; then
5357 if $SHARED_KEY; then
5358 export SK_MOUNTED=false
5364 cleanup_echo_devs () {
5367 local devs=$($LCTL dl | grep echo | awk '{print $4}')
5369 for dev in $devs; do
5370 $LCTL --device $dev cleanup
5371 $LCTL --device $dev detach
5375 # Allow %pK to print raw pointers and save the initial value
5376 kptr_enable_and_save() {
5377 # do not overwrite whatever was initially saved:
5378 [[ -f $TMP/kptr-$PPID-env ]] && return
5381 for node in $(all_nodes); do
5382 kptr[$node]=$(do_node $node "sysctl --values kernel/kptr_restrict")
5383 do_node $node "sysctl -wq kernel/kptr_restrict=1"
5385 declare -p kptr > $TMP/kptr-$PPID-env
5388 # Restore the initial %pK settings
5390 [[ ! -f $TMP/kptr-$PPID-env ]] && return
5392 source $TMP/kptr-$PPID-env
5395 for node in $(all_nodes); do
5396 [[ -z ${kptr[$node]} ]] && continue
5397 param="kernel/kptr_restrict=${kptr[$node]}"
5398 do_node $node "sysctl -wq ${param} || true"
5403 nfs_client_mode && return
5404 cifs_client_mode && return
5407 CLEANUP_DM_DEV=true stopall $*
5409 [[ $KPTR_ON_MOUNT ]] && kptr_restore
5416 combined_mgs_mds () {
5417 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
5418 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
5422 echo -n "$1" | tr '[:upper:]' '[:lower:]'
5426 echo -n "$1" | tr '[:lower:]' '[:upper:]'
5438 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
5439 for i in $(echo "$var"); do
5440 if [ "$i" == "-O" ]; then
5442 first_o=$(($first_o + 1))
5445 if [ "$i" == "-E" ]; then
5447 first_e=$(($first_e + 1 ))
5452 [ $first_o -gt 1 ] && opt_o+=",";
5456 [ $first_e -gt 1 ] && opt_e+=",";
5467 [ -n "$opt_o" ] && echo " -O $opt_o"
5468 [ -n "$opt_e" ] && echo " -E $opt_e"
5474 local fsname=${3:-"$FSNAME"}
5475 local type=$(facet_type $facet)
5476 local index=$(facet_index $facet)
5477 local fstype=$(facet_fstype $facet)
5478 local host=$(facet_host $facet)
5482 local varbs=${facet}_BLOCKSIZE
5484 if [ $type == MGS ] || ( [ $type == MDS ] &&
5485 [ "$dev" == $(mgsdevname) ] &&
5486 [ "$host" == "$(facet_host mgs)" ] ); then
5489 opts="--mgsnode=$MGSNID"
5492 if [ $type != MGS ]; then
5493 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
5497 var=${facet}failover_HOST
5498 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
5499 opts+=" --failnode=$(h2nettype ${!var})"
5502 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
5503 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
5505 if [ $type == MDS ]; then
5506 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
5507 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
5508 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
5510 if [ $fstype == ldiskfs ]; then
5512 if [ -n "${!var}" ]; then
5513 fs_mkfs_opts+=" -J device=${!var}"
5515 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
5517 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
5521 if [ $type == OST ]; then
5522 if [ $fstype == ldiskfs ]; then
5524 if [ -n "${!var}" ]; then
5525 fs_mkfs_opts+=" -J device=${!var}"
5527 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
5532 opts+=" --backfstype=$fstype"
5535 if [ -n "${!var}" ]; then
5536 opts+=" --device-size=${!var}"
5539 var=$(upper $fstype)_MKFS_OPTS
5540 fs_mkfs_opts+=${!var:+" ${!var}"}
5542 var=${type}_FS_MKFS_OPTS
5543 fs_mkfs_opts+=${!var:+" ${!var}"}
5545 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
5547 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
5548 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
5550 if [ -n "${fs_mkfs_opts## }" ]; then
5551 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
5555 opts+=${!var:+" ${!var}"}
5562 local type=$(facet_type $facet)
5563 local var=${type}_MOUNT_FS_OPTS
5565 if [ -n "${!var}" ]; then
5566 opts+=" --mountfsoptions=${!var}"
5571 check_ost_indices() {
5572 local index_count=${#OST_INDICES[@]}
5573 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
5575 # OST count is greater than the index count in $OST_INDEX_LIST.
5576 # We need check whether there are duplicate indices.
5580 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
5581 index=$(facet_index ost$i)
5582 for j in $(seq 0 $((index_count - 1))); do
5583 [[ $index -ne ${OST_INDICES[j]} ]] ||
5584 error "ost$i has the same index $index as ost$((j+1))"
5591 local facet_type=$1 # mgs || mds || ost
5593 local facet=${1}${2}
5596 case "$(facet_fstype $facet)" in
5598 device=$(${facet_type}devname $facet_num)
5601 device=$(${facet_type}vdevname $facet_num)
5604 error "Unhandled filesystem type"
5608 do_facet $facet "[ -e \"$device\" ]" && return
5610 # Note: the following check only works with absolute paths
5611 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5612 error "$facet: device '$device' does not exist"
5614 # zpool create doesn't like empty files
5615 [[ $(facet_fstype $facet) == zfs ]] && return 0
5617 do_facet $facet "touch \"${device}\""
5622 local fstype=$(facet_fstype mgs)
5624 [[ "$fstype" == "wbcfs" ]] && return
5629 echo "Format mgs: $(mgsdevname)"
5630 reformat_external_journal mgs
5632 # touch "device" in case it is a loopback file for testing and needs to
5633 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5634 # to non-existent files in /dev if the admin made a typo during setup
5637 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5638 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5644 local fstype=$(facet_fstype mdt$num)
5646 [[ "$fstype" == "wbcfs" ]] && return
5651 echo "Format mds$num: $(mdsdevname $num)"
5652 reformat_external_journal mds$num
5654 __touch_device mds $num
5656 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5657 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5658 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5663 local fstype=$(facet_fstype ost$num)
5665 [[ "$fstype" == "wbcfs" ]] && return
5670 echo "Format ost$num: $(ostdevname $num)"
5671 reformat_external_journal ost$num
5673 __touch_device ost $num
5675 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5676 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5677 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5682 # Set hostid for ZFS/SPL zpool import protection
5683 # (Assumes MDS version is also OSS version)
5684 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5686 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5689 # We need ldiskfs here, may as well load them all
5691 [ -n "$CLIENTONLY" ] && return
5692 echo Formatting mgs, mds, osts
5693 if ! combined_mgs_mds ; then
5697 for num in $(seq $MDSCOUNT); do
5701 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5703 for num in $(seq $OSTCOUNT); do
5709 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5713 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5716 # usage: switch_identity MDSNUM ENABLE_UPCALL
5719 # 0: success, the identity upcall was previously enabled already.
5720 # 1: success, the identity upcall was previously disabled.
5726 local MDT="$(mdtname_from_index $((num - 1)) $MOUNT)"
5727 local upcall="$L_GETIDENTITY"
5729 [[ -n "$MDT" ]] || return 2
5731 local param="mdt.$MDT.identity_upcall"
5732 local old="$(do_facet $facet "lctl get_param -n $param")"
5734 [[ "$enable" == "true" ]] || upcall="NONE"
5736 do_facet $facet "lctl set_param -n $param='$upcall'" || return 2
5737 do_facet $facet "lctl set_param -n mdt.$MDT.identity_flush=-1"
5739 [[ "$old" != "NONE" ]] # implicit "&& return 0 || return 1"
5744 zconf_umount $HOSTNAME $1 || error "umount failed"
5745 zconf_mount $HOSTNAME $1 || error "mount failed with ($?)"
5753 rm -f $TMP/${facet}active
5754 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5759 local mdt_count=${1:-$MDSCOUNT}
5760 local ost_count=${2:-$OSTCOUNT}
5763 for num in $(seq $mdt_count); do
5764 DEVNAME=$(mdsdevname $num)
5765 writeconf_facet mds$num $DEVNAME || rc=$?
5768 for num in $(seq $ost_count); do
5769 DEVNAME=$(ostdevname $num)
5770 writeconf_facet ost$num $DEVNAME || rc=$?
5776 if ! combined_mgs_mds ; then
5777 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5778 do_facet mgs "$LCTL set_param -P debug_raw_pointers=Y"
5787 for num in $(seq $MDSCOUNT); do
5788 devname=$(mdsdevname $num)
5789 start mds$num $devname $MDS_MOUNT_OPTS
5791 # We started mds$num, now we should set mds${num}_HOST
5792 # and mds${num}failover_HOST variables properly if they
5794 host=$(facet_host mds$num)
5795 for varname in mds${num}_HOST mds${num}failover_HOST; do
5796 if [[ -z "${!varname}" ]]; then
5800 if [[ "$IDENTITY_UPCALL" != "default" ]]; then
5801 switch_identity $num $IDENTITY_UPCALL
5804 if combined_mgs_mds ; then
5805 do_facet mgs "$LCTL set_param -P debug_raw_pointers=Y"
5812 for num in $(seq $OSTCOUNT); do
5814 rm -f $TMP/ost${num}active
5823 for num in $(seq $OSTCOUNT); do
5824 devname=$(ostdevname $num)
5825 start ost$num $devname $OST_MOUNT_OPTS
5827 # We started ost$num, now we should set ost${num}_HOST
5828 # and ost${num}failover_HOST variables properly if they
5830 host=$(facet_host ost$num)
5831 for varname in ost${num}_HOST ost${num}failover_HOST; do
5832 if [[ -z "${!varname}" ]]; then
5840 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5841 if [ ! -z $arg1 ]; then
5842 [ "$arg1" = "server_only" ] && return
5845 if [ -n "$CLIENTS" ]; then
5846 zconf_mount_clients $CLIENTS $MOUNT
5850 if [ "$MOUNT_2" ]; then
5851 mount_client $MOUNT2
5852 if [ -n "$CLIENTS" ]; then
5853 zconf_mount_clients $CLIENTS $MOUNT2
5858 sk_nodemap_setup() {
5859 local sk_map_name=${1:-$SK_S2SNM}
5860 local sk_map_nodes=${2:-$HOSTNAME}
5861 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5862 for servernode in $sk_map_nodes; do
5863 local nids=$(do_nodes $servernode "$LCTL list_nids")
5864 for nid in $nids; do
5865 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5866 $sk_map_name --range $nid"
5874 nfs_client_mode && return
5875 cifs_client_mode && return
5877 sanity_mount_check || error "environments are insane!"
5883 if [ -z "$CLIENTONLY" ]; then
5884 echo Setup mgs, mdt, osts
5885 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5887 if $SK_MOUNTED; then
5888 echo "Shared Key file system already mounted"
5893 if $SHARED_KEY; then
5894 export SK_MOUNTED=true
5898 echo "GSS_SK: setting kernel keyring perms"
5899 do_nodes $(comma_list $(all_nodes)) \
5900 "keyctl show | grep lustre | cut -c1-11 |
5902 xargs -IX keyctl setperm X 0x3f3f3f3f"
5905 # Need to start one nodemap for servers,
5906 # and one for clients.
5907 sk_nodemap_setup $SK_S2SNM \
5908 $(comma_list $(all_server_nodes))
5910 sk_nodemap_setup $SK_S2SNMCLI \
5911 ${CLIENTS:-$HOSTNAME}
5912 echo "Nodemap set up for SK S2S, remounting."
5921 # wait a while to allow sptlrpc configuration be propogated to targets,
5922 # only needed when mounting new target devices.
5930 [[ $KPTR_ON_MOUNT ]] && kptr_enable_and_save
5932 # by remounting mdt before ost, initial connect from mdt to ost might
5933 # timeout because ost is not ready yet. wait some time to its fully
5934 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5935 # preceeded by a context negotiation rpc with $TIMEOUT.
5936 # FIXME better by monitoring import status.
5939 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5940 set_rule $FSNAME any cli2ost $SK_FLAVOR
5941 if $SK_SKIPFIRST; then
5942 export SK_SKIPFIRST=false
5946 "lctl set_param osc.*.idle_connect=1"
5949 wait_flavor cli2mdt $SK_FLAVOR
5950 wait_flavor cli2ost $SK_FLAVOR
5955 sleep $((TIMEOUT + 5))
5961 mounted_lustre_filesystems() {
5962 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5965 init_facet_vars () {
5966 [ -n "$CLIENTONLY" ] && return 0
5973 eval export ${facet}_dev=${device}
5974 eval export ${facet}_opt=\"$*\"
5976 local dev=${facet}_dev
5978 # We need to loop for the label
5979 # in case its not initialized yet.
5980 for wait_time in {0,1,3,5,10}; do
5982 if [ $wait_time -gt 0 ]; then
5983 echo "${!dev} not yet initialized,"\
5984 "waiting ${wait_time} seconds."
5988 local label=$(devicelabel ${facet} ${!dev})
5990 # Check to make sure the label does
5991 # not include ffff at the end of the label.
5992 # This indicates it has not been initialized yet.
5994 if [[ $label =~ [f|F]{4}$ ]]; then
5995 # label is not initialized, unset the result
5996 # and either try again or fail
6003 [ -z "$label" ] && echo no label for ${!dev} && exit 1
6005 eval export ${facet}_svc=${label}
6007 local varname=${facet}failover_HOST
6008 if [ -z "${!varname}" ]; then
6010 if combined_mgs_mds && [ $facet == "mgs" ] &&
6011 [ -n "$mds1failover_HOST" ]; then
6012 temp=$mds1failover_HOST
6014 temp=$(facet_host $facet)
6016 eval export $varname=$temp
6019 varname=${facet}_HOST
6020 if [ -z "${!varname}" ]; then
6021 eval export $varname=$(facet_host $facet)
6024 # ${facet}failover_dev is set in cfg file
6025 varname=${facet}failover_dev
6026 if [ -n "${!varname}" ] ; then
6027 eval export ${facet}failover_dev=${!varname}
6029 eval export ${facet}failover_dev=$device
6032 # get mount point of already mounted device
6033 # is facet_dev is already mounted then use the real
6034 # mount point of this facet; otherwise use $(facet_mntpt $facet)
6035 # i.e. ${facet}_MOUNT if specified by user or default
6036 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
6037 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
6038 if [ -z $mntpt ]; then
6039 mntpt=$(facet_mntpt $facet)
6041 eval export ${facet}_MOUNT=$mntpt
6044 init_facets_vars () {
6047 if ! remote_mds_nodsh; then
6048 for num in $(seq $MDSCOUNT); do
6049 DEVNAME=$(mdsdevname $num)
6050 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
6054 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
6056 if ! remote_ost_nodsh; then
6057 for num in $(seq $OSTCOUNT); do
6058 DEVNAME=$(ostdevname $num)
6059 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
6064 init_facets_vars_simple () {
6067 if ! remote_mds_nodsh; then
6068 for num in $(seq $MDSCOUNT); do
6069 devname=$(mdsdevname $num)
6070 eval export mds${num}_dev=${devname}
6071 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
6075 if ! combined_mgs_mds ; then
6076 eval export mgs_dev=$(mgsdevname)
6077 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
6080 if ! remote_ost_nodsh; then
6081 for num in $(seq $OSTCOUNT); do
6082 devname=$(ostdevname $num)
6083 eval export ost${num}_dev=${devname}
6084 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
6089 osc_ensure_active () {
6094 while [ $period -lt $timeout ]; do
6095 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
6096 if [ $count -eq 0 ]; then
6100 echo "$count OST inactive, wait $period seconds, and try again"
6102 period=$((period+3))
6105 [ $period -lt $timeout ] ||
6106 log "$count OST are inactive after $timeout seconds, give up"
6109 set_conf_param_and_check() {
6113 local ORIG=$(do_facet $myfacet "$TEST")
6114 if [ $# -gt 3 ]; then
6120 echo "Setting $PARAM from $ORIG to $FINAL"
6121 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
6122 error "conf_param $PARAM failed"
6124 wait_update_facet $myfacet "$TEST" "$FINAL" ||
6125 error "check $PARAM failed!"
6128 set_persistent_param() {
6132 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
6134 if [ $# -gt 3 ]; then
6141 if [[ $PERM_CMD == *"set_param -P"* ]]; then
6142 echo "Setting $test_param from $orig to $final"
6143 do_facet mgs "$PERM_CMD $test_param='$final'" ||
6144 error "$PERM_CMD $test_param failed"
6146 echo "Setting $param from $orig to $final"
6147 do_facet mgs "$PERM_CMD $param='$final'" ||
6148 error "$PERM_CMD $param failed"
6152 set_persistent_param_and_check() {
6156 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
6158 if [ $# -gt 3 ]; then
6165 set_persistent_param $myfacet $test_param $param "$final"
6167 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
6168 error "check $param failed!"
6171 init_param_vars () {
6172 TIMEOUT=$(lctl get_param -n timeout)
6173 TIMEOUT=${TIMEOUT:-20}
6175 if [ -n "$arg1" ]; then
6176 [ "$arg1" = "server_only" ] && return
6179 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
6181 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
6182 log "Using TIMEOUT=$TIMEOUT"
6184 # tune down to speed up testing on (usually) small setups
6185 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
6186 do_nodes $(comma_list $(nodes_list)) \
6187 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
6189 osc_ensure_active $SINGLEMDS $TIMEOUT
6190 osc_ensure_active client $TIMEOUT
6191 $LCTL set_param osc.*.idle_timeout=debug
6193 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
6194 local current_jobid_var=$($LCTL get_param -n jobid_var)
6196 if [ $JOBID_VAR = "existing" ]; then
6197 echo "keeping jobstats as $current_jobid_var"
6198 elif [ $current_jobid_var != $JOBID_VAR ]; then
6199 echo "setting jobstats to $JOBID_VAR"
6201 set_persistent_param_and_check client \
6202 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
6205 echo "jobstats not supported by server"
6208 if [ $QUOTA_AUTO -ne 0 ]; then
6209 if [ "$ENABLE_QUOTA" ]; then
6210 echo "enable quota as required"
6211 setup_quota $MOUNT || return 2
6213 echo "disable quota as required"
6214 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
6218 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
6219 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
6223 nfs_client_mode () {
6224 if [ "$NFSCLIENT" ]; then
6225 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
6226 local clients=$CLIENTS
6228 [ -z $clients ] && clients=$(hostname)
6230 # FIXME: remove hostname when 19215 fixed
6231 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
6232 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
6233 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
6234 if [[ ${#nfsexport[@]} -eq 0 ]]; then
6235 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
6237 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
6243 cifs_client_mode () {
6244 [ x$CIFSCLIENT = xyes ] &&
6245 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
6248 check_config_client () {
6250 local mounted=$(mount | grep " $mntpt ")
6252 if [ -n "$CLIENTONLY" ]; then
6254 # CLIENTONLY should not depend on *_HOST settings
6255 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
6256 # in theory someone could create a new,
6257 # client-only config file that assumed lustre was already
6258 # configured and didn't set the MGSNID. If MGSNID is not set,
6259 # then we should use the mgs nid currently being used
6260 # as the default value. bug 18021
6261 [[ x$MGSNID = x ]] &&
6264 if [[ x$mgc != xMGC$MGSNID ]]; then
6265 if [ "$mgs_HOST" ]; then
6266 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
6267 grep PING | awk '{print $3}' |
6268 sed -e "s/(//g" -e "s/)//g")
6270 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
6271 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
6277 echo Checking config lustre mounted on $mntpt
6278 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
6279 mgshost=$(echo $mgshost | awk -F: '{print $1}')
6283 check_config_clients () {
6284 local clients=${CLIENTS:-$HOSTNAME}
6287 nfs_client_mode && return
6288 cifs_client_mode && return
6290 do_rpc_nodes "$clients" check_config_client $mntpt
6292 sanity_mount_check || error "environments are insane!"
6296 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
6297 local cltimeout=$(lctl get_param -n timeout)
6298 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
6299 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
6306 [ -z $mntpt ] && return 1
6307 local mounted=$(mounted_lustre_filesystems)
6309 echo $mounted' ' | grep -w -q $mntpt' '
6314 local ostsn=${2:-$OSTCOUNT}
6315 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
6318 echo ostsn=$ostsn npools=$npools
6319 if [[ $ostsn -gt $OSTCOUNT ]]; then
6320 echo "request to use $ostsn OSTs in the pool, \
6321 using max available OSTCOUNT=$OSTCOUNT"
6324 for (( n=0; n < $npools; n++ )); do
6326 if ! $DELETE_OLD_POOLS; then
6327 log "request to not delete old pools: $FSNAME.$p exist?"
6328 if ! check_pool_not_exist $FSNAME.$p; then
6329 echo "Using existing $FSNAME.$p"
6330 $LCTL pool_list $FSNAME.$p
6334 create_pool $FSNAME.$p $KEEP_POOLS ||
6335 error "create_pool $FSNAME.$p failed"
6337 local first=$(( (n * ostsn) % OSTCOUNT ))
6338 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
6339 if [[ $first -le $last ]]; then
6340 pool_add_targets $p $first $last ||
6341 error "pool_add_targets $p $first $last failed"
6343 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
6344 error "pool_add_targets $p $first \
6345 $(( OSTCOUNT - 1 )) failed"
6346 pool_add_targets $p 0 $last ||
6347 error "pool_add_targets $p 0 $last failed"
6352 set_pools_quota () {
6359 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
6360 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
6362 # POOLS_QUOTA_USERS_SET=
6363 # "quota15_1:20M -- for all of the found pools
6364 # quota15_2:1G:gpool0
6365 # quota15_3 -- for global limit only
6366 # quota15_4:200M:gpool0
6367 # quota15_4:200M:gpool1"
6369 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
6371 declare -A pq_limits
6373 for ((i=0; i<${#pq_userset[@]}; i++)); do
6374 u=${pq_userset[i]%%:*}
6376 # user gets no pool limits if
6377 # POOLS_QUOTA_USERS_SET does not specify it
6378 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
6379 pq_limits[$u]+=" $o"
6381 pq_users=(${!pq_limits[@]})
6386 for ((i=0; i<${#pq_users[@]}; i++)); do
6388 # set to max limit (_u64)
6389 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
6390 opts=(${pq_limits[$u]})
6391 for ((j=0; j<${#opts[@]}; j++)); do
6394 # Set limit for all existing pools if
6396 if [ $p == $o ]; then
6397 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
6398 echo "No pool specified for $u,
6399 set limit $o for all existing pools"
6402 $LFS setquota -u $u -B $o --pool $pool $DIR ||
6403 error "setquota -u $u -B $o \
6404 --pool $pool failed"
6407 $LFS quota -uv $u --pool $DIR
6411 do_check_and_setup_lustre() {
6412 # If auster does not want us to setup, then don't.
6413 ! ${do_setup} && return
6415 log "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
6418 nfs_client_mode && return
6419 cifs_client_mode && return
6421 local MOUNTED=$(mounted_lustre_filesystems)
6425 # both MOUNT and MOUNT2 are not mounted
6426 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6427 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
6428 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
6430 is_mounted $MOUNT || error "NAME=$NAME not mounted"
6431 export I_MOUNTED=yes
6435 elif is_mounted $MOUNT2; then
6437 # MOUNT2 is mounted, while MOUNT_2 is not set
6438 if ! [ "$MOUNT_2" ]; then
6439 cleanup_mount $MOUNT2
6440 export I_UMOUNTED2=yes
6443 # MOUNT2 is mounted, MOUNT_2 is set
6445 # FIXME: what to do if check_config failed?
6447 # 1) remote client has mounted other Lustre fs ?
6448 # 2) it has insane env ?
6449 # try to umount MOUNT2 on all clients and mount again:
6450 if ! check_config_clients $MOUNT2; then
6451 cleanup_mount $MOUNT2
6452 restore_mount $MOUNT2
6453 export I_MOUNTED2=yes
6457 # MOUNT is mounted MOUNT2 is not mounted
6458 elif [ "$MOUNT_2" ]; then
6459 restore_mount $MOUNT2
6460 export I_MOUNTED2=yes
6464 # FIXME: what to do if check_config failed?
6466 # 1) remote client has mounted other Lustre fs?
6467 # 2) lustre is mounted on remote_clients atall ?
6468 check_config_clients $MOUNT
6472 set_default_debug_nodes $(comma_list $(nodes_list))
6476 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
6478 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
6479 facets="$(get_facets OST)"
6480 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
6481 facets="$facets,$(get_facets MDS)"
6482 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
6483 facets="$facets,mgs"
6484 local nodes="$(facets_hosts ${facets})"
6485 if [ -n "$nodes" ] ; then
6486 do_nodes $nodes "$LCTL set_param \
6487 osd-ldiskfs.track_declares_assert=1 || true"
6491 if [ -n "$fs_STRIPEPARAMS" ]; then
6492 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
6501 if $DELETE_OLD_POOLS; then
6505 if [[ -n "$FS_POOL" ]]; then
6506 create_pools $FS_POOL $FS_POOL_NOSTS
6509 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
6513 # set tunable parameters passed to test environment
6518 TESTNAME="start setup" check_dmesg_for_errors ||
6519 TESTNAME="test_setup" error "Error in dmesg detected"
6521 log "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
6523 if [[ "$ONLY" == "setup" ]]; then
6528 check_and_setup_lustre() {
6529 local start_stamp=$(date +%s)
6530 local saved_umask=$(umask)
6531 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
6540 log_sub_test_begin test_setup
6542 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
6543 error=$(tail -1 $log)
6548 stop_stamp=$(date +%s)
6549 duration=$((stop_stamp - start_stamp))
6551 log_sub_test_end "$status" "$duration" "$rc" "$error"
6559 local clients=${CLIENTS:-$HOSTNAME}
6562 zconf_mount_clients $clients $mntpt
6566 local clients=${CLIENTS:-$HOSTNAME}
6569 zconf_umount_clients $clients $mntpt
6572 cleanup_and_setup_lustre() {
6573 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
6574 lctl set_param debug=0 || true
6577 if [[ "$ONLY" == "cleanup" ]]; then
6582 do_check_and_setup_lustre
6585 # Run e2fsck on MDT or OST device.
6590 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
6591 local log=$TMP/e2fsck.log
6594 # turn on pfsck if it is supported
6595 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
6597 do_node $node $cmd 2>&1 | tee $log
6599 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
6601 if [ $MDSCOUNT -gt 1 ]; then
6602 skip_noexit "DNE mode isn't supported!"
6606 error "It's not DNE mode."
6611 [ $rc -le $FSCK_MAX_ERR ] ||
6612 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6618 # Run resize2fs on MDT or OST device.
6627 do_facet $facet "$RESIZE2FS $opts $device $size"
6630 # verify a directory is shared among nodes.
6631 check_shared_dir() {
6633 local list=${2:-$(comma_list $(nodes_list))}
6635 [ -z "$dir" ] && return 1
6636 do_rpc_nodes "$list" check_logdir $dir
6637 check_write_access $dir "$list" || return 1
6642 do_nodes $(tgts_nodes) $LCTL set_param printk=+lfsck
6643 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6645 for k in $(seq $MDSCOUNT); do
6646 # wait up to 10+1 minutes for LFSCK to complete
6647 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6648 mdd.$(facet_svc mds${k}).lfsck_layout |
6649 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6650 error "MDS${k} layout isn't the expected 'completed'"
6651 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6652 mdd.$(facet_svc mds${k}).lfsck_namespace |
6653 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6654 error "MDS${k} namespace isn't the expected 'completed'"
6656 local repaired=$(do_nodes $(tgts_nodes) \
6657 "$LCTL get_param -n *.$FSNAME-*.lfsck_*" |
6658 awk '/repaired/ { print $2 }' | calc_sum)
6659 (( repaired == 0 )) ||
6660 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6663 dump_file_contents() {
6669 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6670 error_noexit false \
6671 "Invalid parameters for dump_file_contents()"
6674 for node in ${nodes//,/ }; do
6675 do_node $node "for i in \\\$(find $dir -type f); do
6676 echo ====\\\${i}=======================;
6678 done" >> ${logname}.${node}.log
6682 dump_command_output() {
6688 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6689 error_noexit false \
6690 "Invalid parameters for dump_command_output()"
6694 for node in ${nodes//,/ }; do
6695 do_node $node "echo ====${cmd}=======================;
6696 $cmd" >> ${logname}.${node}.log
6703 # dump file contents from /proc/spl in case of zfs test
6704 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6705 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6706 dump_command_output \
6707 "$(osts_nodes)" "zpool events -v" "${logname}"
6710 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6711 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6712 dump_command_output \
6713 "$(mdts_nodes)" "zpool events -v" "${logname}"
6717 do_check_and_cleanup_lustre() {
6718 log "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6720 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6721 "$TESTSUITE" != "sanity-scrub" ]]; then
6725 # FIXME: The cleanup takes too long, times out...
6726 if [[ "$FSTYPE" == "wbcfs" ]]; then
6730 if is_mounted $MOUNT; then
6731 if $DO_CLEANUP; then
6732 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6733 error "remove sub-test dirs failed"
6737 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6740 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6741 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6744 if [[ "$I_MOUNTED2" == "yes" ]]; then
6745 cleanup_mount $MOUNT2
6748 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6749 cleanupall -f || error "cleanup failed"
6753 TESTNAME="start cleanup" check_dmesg_for_errors ||
6754 TESTNAME="test_cleanup" error "Error in dmesg detected"
6756 log "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6759 check_and_cleanup_lustre() {
6760 local start_stamp=$(date +%s)
6761 local saved_umask=$(umask)
6762 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6771 log_sub_test_begin test_cleanup
6773 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6774 error=$(tail -1 $log)
6779 stop_stamp=$(date +%s)
6780 duration=$((stop_stamp - start_stamp))
6782 log_sub_test_end "$status" "$duration" "$rc" "$error"
6792 wait_for_function () {
6795 # suppress fn both stderr and stdout
6796 if [ "$1" = "--quiet" ]; then
6798 quiet=" > /dev/null 2>&1"
6809 eval $fn $quiet && return 0
6811 [ $wait -lt $max ] || return 1
6812 echo waiting $fn, $((max - wait)) secs left ...
6813 wait=$((wait + sleep))
6814 [ $wait -gt $max ] && ((sleep -= wait - max))
6824 [ "$host" = "$HOSTNAME" ] && return 0
6826 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6827 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6837 # Convert a space-delimited list to a comma-delimited list. If the input is
6838 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6840 # echo is used to convert newlines to spaces, since it doesn't
6841 # introduce a trailing space as using "tr '\n' ' '" does
6842 echo $(tr -s ", " "\n" <<< $* | sort -b -u) | tr ' ' ','
6849 echo $list | grep -qw $item
6852 # list, excluded are the comma separated lists
6853 exclude_items_from_list () {
6859 for item in ${excluded//,/ }; do
6860 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6862 echo $(comma_list $list)
6865 # list, expand are the comma separated lists
6867 local list=${1//,/ }
6868 local expand=${2//,/ }
6871 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6872 echo $(comma_list $expanded)
6875 testslist_filter () {
6876 local script=$LUSTRE/tests/${TESTSUITE}.sh
6878 [ -f $script ] || return 0
6880 local start_at=$START_AT
6881 local stop_at=$STOP_AT
6883 local var=${TESTSUITE//-/_}_START_AT
6884 [ x"${!var}" != x ] && start_at=${!var}
6885 var=${TESTSUITE//-/_}_STOP_AT
6886 [ x"${!var}" != x ] && stop_at=${!var}
6888 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6889 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6890 /^'${start_at}'$/ {flag = 0}
6891 {if (flag == 1) print $0}
6892 /^'${stop_at}'$/ { flag = 1 }'
6896 (cd `dirname $1`; echo $PWD/`basename $1`)
6900 local types=${*:-"OST MDS MGS"}
6904 for entry in $types; do
6905 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6906 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6909 MGS ) list="$list $name";;
6910 MDS|OST|AGT ) local count=${type}COUNT
6911 for ((i=1; i<=${!count}; i++)) do
6912 list="$list ${name}$i"
6914 * ) error "Invalid facet type"
6918 echo $(comma_list $list)
6921 ##################################
6922 # Adaptive Timeouts funcs
6925 # only check mds, we assume at_max is the same on all nodes
6926 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6928 if [ $at_max -eq 0 ]; then
6939 # suppose that all ost-s have the same $at value set
6940 [ $facet != "ost" ] || facet=ost1
6942 do_facet $facet "lctl get_param -n $at"
6956 for facet in "$@"; do
6957 if [ $facet == "ost" ]; then
6958 facet=$(get_facets OST)
6959 elif [ $facet == "mds" ]; then
6960 facet=$(get_facets MDS)
6962 hosts=$(expand_list $hosts $(facets_hosts $facet))
6965 do_nodes $hosts lctl set_param at_max=$at_max
6979 for facet in "$@"; do
6980 if [ $facet == "ost" ]; then
6981 facet=$(get_facets OST)
6982 elif [ $facet == "mds" ]; then
6983 facet=$(get_facets MDS)
6985 hosts=$(expand_list $hosts $(facets_hosts $facet))
6988 do_nodes $hosts lctl set_param at_min=$at_min
6991 ##################################
6995 # OBD_FAIL_MDS_ALL_REQUEST_NET
6997 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6998 do_facet client "$1" || RC=$?
6999 do_facet $SINGLEMDS lctl set_param fail_loc=0
7004 # OBD_FAIL_MDS_ALL_REPLY_NET
7006 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
7008 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
7012 drop_reint_reply() {
7013 # OBD_FAIL_MDS_REINT_NET_REP
7015 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
7017 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
7021 drop_update_reply() {
7026 # OBD_FAIL_OUT_UPDATE_NET_REP 0x1701
7027 do_facet mds${index} $LCTL set_param fail_loc=0x1701
7028 do_facet client "$@" || rc=$?
7029 do_facet mds${index} $LCTL set_param fail_loc=0
7036 local timeout=${2:-0}
7039 # default is (obd_timeout / 4) if unspecified
7040 echo "timeout is $timeout"
7041 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
7042 do_facet ost1 $LCTL set_param fail_val=$timeout fail_loc=0x80000214
7043 do_facet client "$cmd" || rc=$?
7044 do_facet client "sync"
7045 do_facet ost1 $LCTL set_param fail_loc=0
7050 drop_ldlm_cancel() {
7051 local tgts=$(tgts_nodes)
7054 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
7055 do_nodes $tgts $LCTL set_param fail_loc=0x304
7056 do_facet client "$@" || rc=$?
7057 do_nodes $tgts $LCTL set_param fail_loc=0
7062 drop_bl_callback_once() {
7064 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
7065 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
7066 do_facet client lctl set_param fail_loc=0x80000305
7067 do_facet client "$@" || rc=$?
7068 do_facet client lctl set_param fail_loc=0
7069 do_facet client lctl set_param fail_val=0
7070 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
7074 drop_bl_callback() {
7076 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
7077 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
7078 do_facet client lctl set_param fail_loc=0x305
7079 do_facet client "$@" || rc=$?
7080 do_facet client lctl set_param fail_loc=0
7081 do_facet client lctl set_param fail_val=0
7082 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
7086 drop_mdt_ldlm_reply() {
7087 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
7089 local mdts=$(mdts_nodes)
7091 do_nodes $mdts lctl set_param fail_loc=0x157
7093 do_facet client "$@" || RC=$?
7095 do_nodes $mdts lctl set_param fail_loc=0
7099 drop_mdt_ldlm_reply_once() {
7100 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
7102 local mdts=$(mdts_nodes)
7104 do_nodes $mdts lctl set_param fail_loc=0x80000157
7106 do_facet client "$@" || RC=$?
7108 do_nodes $mdts lctl set_param fail_loc=0
7117 echo "clearing fail_loc on $facet"
7118 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
7121 set_nodes_failloc () {
7123 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
7126 # Print the total of the lock_unused_count across all namespaces containing the
7127 # given wildcard. If the namespace wildcard is omitted, all namespaces will be
7129 # Usage: total_unused_locks [namespace_wildcard]
7130 total_unused_locks() {
7131 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_unused_count" | calc_sum
7134 # Print the total of the lock_count across all namespaces containing the given
7135 # wildcard. If the namespace wilcard is omitted, all namespaces will be matched.
7136 # Usage: total_used_locks [namespace_wildcard]
7137 total_used_locks() {
7138 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_count" | calc_sum
7141 # Cancel lru locks across all namespaces containing the given wildcard. If the
7142 # wilcard is omitted, lru locks will be canceled across all namespaces.
7143 # Usage: cancel_lru_locks [namespace_wildcard]
7144 cancel_lru_locks() {
7145 #$LCTL mark "cancel_lru_locks $1 start"
7146 $LCTL set_param -t4 -n "ldlm.namespaces.*$1*.lru_size=clear"
7147 $LCTL get_param "ldlm.namespaces.*$1*.lock_unused_count" | grep -v '=0'
7148 #$LCTL mark "cancel_lru_locks $1 stop"
7153 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
7155 echo $((100 * nr_cpu))
7160 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=0
7163 lru_resize_disable()
7166 local lru_size=${2:-$(default_lru_size)}
7167 local size_param="ldlm.namespaces.*$dev*.lru_size"
7168 local age_param="ldlm.namespaces.*$dev*.lru_max_age"
7169 local old_age=($($LCTL get_param -n $age_param))
7170 # can't save/restore lru_size since it reports the *current* lru count
7172 echo "$size_param=0->$lru_size"
7173 echo "$age_param=$old_age->3900s"
7175 # increase lru_max_age also, to prevent lock cancel due to age
7176 $LCTL set_param -n $size_param=$lru_size
7177 $LCTL set_param -n $age_param=3900s
7178 stack_trap "cancel_lru_locks $dev || true"
7179 stack_trap "lru_resize_enable $dev || true"
7180 stack_trap "$LCTL set_param -n $age_param=$old_age || true"
7185 local mountpath=${1:-$MOUNT}
7188 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
7195 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
7196 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
7197 echo there is still data in page cache $FILE ?
7198 lctl get_param -n $FILE
7206 DEBUGSAVE="$(lctl get_param -n debug)"
7207 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
7211 [ -n "$DEBUGSAVE" ] &&
7212 do_nodes $CLIENTS $LCTL set_param -n debug=${DEBUGSAVE// /+} ||
7216 [ -n "$DEBUGSAVE_SERVER" ] &&
7217 do_nodes $(comma_list $(all_server_nodes)) \
7218 $LCTL set_param -n debug=${DEBUGSAVE_SERVER// /+} ||
7224 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
7227 debug_size_restore() {
7228 [ -n "$DEBUG_SIZE_SAVED" ] &&
7229 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
7233 start_full_debug_logging() {
7238 local debug_size=150
7239 local nodes=$(comma_list $(nodes_list))
7241 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
7244 stop_full_debug_logging() {
7249 # prints bash call stack
7250 print_stack_trace() {
7253 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
7254 local src=${BASH_SOURCE[$i]}
7255 local lineno=${BASH_LINENO[$i-1]}
7256 local funcname=${FUNCNAME[$i]}
7257 echo " = $src:$lineno:$funcname()"
7262 local TYPE=${TYPE:-"FAIL"}
7265 # do not dump logs if $1=false
7266 if [ "x$1" = "xfalse" ]; then
7271 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
7272 (print_stack_trace 2) >&2
7274 # We need to dump the logs on all nodes
7276 gather_logs $(comma_list $(nodes_list))
7280 [ "$TESTSUITELOG" ] &&
7281 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
7282 if [ -z "$*" ]; then
7283 echo "error() without useful message, please fix" > $LOGDIR/err
7285 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
7286 echo "$@" > $LOGDIR/ignore
7288 echo "$@" > $LOGDIR/err
7292 # cleanup the env for failed tests
7296 ##################################
7298 ##################################
7300 # usage: stack_trap arg sigspec
7302 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
7303 # command "arg" on top of previously defined commands for "sigspec" instead
7304 # of overwriting them.
7305 # stacked traps are executed in reverse order of their registration
7307 # arg and sigspec have the same meaning as in man (1) trap
7311 local sigspec="${2:-EXIT}"
7313 # Use "trap -p" to get the quoting right
7314 local old_trap="$(trap -p "$sigspec")"
7315 # Append ";" and remove the leading "trap -- '" added by "trap -p"
7316 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
7318 # Once again, use "trap -p" to get the quoting right
7319 local new_trap="$(trap -- "$arg" "$sigspec"
7321 trap -- '' "$sigspec")"
7323 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
7325 # The resulting string should be safe to "eval" as it is (supposedly
7326 # correctly) quoted by "trap -p"
7327 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
7336 local logs="$TESTSUITELOG $1"
7338 for log in $logs; do
7339 if [ -f "$log" ]; then
7340 grep -qw FAIL $log && status=1
7357 # use only if we are ignoring failures for this test, bugno required.
7358 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
7359 # e.g. error_ignore bz5494 "your message" or
7360 # error_ignore LU-5494 "your message"
7362 local TYPE="IGNORE ($1)"
7364 report_error false "$@"
7367 error_and_remount() {
7369 remount_client $MOUNT
7373 # Throw an error if it's not running in vm - usually for performance
7376 local virt=$(running_in_vm)
7377 if [[ -n "$virt" ]]; then
7378 echo "running in VM '$virt', ignore error"
7379 error_ignore env=$virt "$@"
7386 # Function: skip_env()
7387 # Purpose: to skip a test during developer testing because some tool
7388 # is missing, but fail the test in release testing because the test
7389 # environment is not configured properly".
7392 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
7397 log " SKIP: $TESTSUITE $TESTNAME $*"
7399 if [[ -n "$ALWAYS_SKIPPED" ]]; then
7400 skip_logged $TESTNAME "$@"
7403 echo "$@" > $LOGDIR/skip
7406 [[ -n "$TESTSUITELOG" ]] &&
7407 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
7417 # For interop testing treate EOPNOTSUPP as success
7423 echo $retstr | awk -F'|' '{print $1}' |
7424 grep -E unsupported\|"(Operation not supported)"
7425 (( $? == 0 )) || error "$retstr"
7429 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
7430 # Usage: always_except LU-4815 23 42q ...
7434 local issue="${1:-}" # single jira style issue ("LU-4815")
7439 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
7440 error "always_except: invalid issue '$issue' for tests '$*'"
7443 for test_num in "$@"; do
7444 ALWAYS_EXCEPT+=" $test_num"
7448 build_test_filter() {
7449 EXCEPT="$EXCEPT $(testslist_filter)"
7451 # allow test numbers separated by '+', or ',', in addition to ' '
7452 # to avoid issues with multiple arguments handling by shell/autotest
7453 for O in ${ONLY//[+,]/ }; do
7454 if [[ $O =~ [0-9]*-[0-9]* ]]; then
7455 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
7463 local nodes=$(comma_list $(facets_nodes mds1,ost1))
7464 local exceptions="$LUSTRE/tests/except/$TESTSUITE.*ex"
7466 do_nodes --verbose $nodes "ls $exceptions || true"
7467 while read facet op need_ver jira subs; do
7468 local have_ver_code=${facet^^*}_VERSION
7471 [[ "$facet" =~ "#" ]] && continue
7472 [[ "$need_ver" =~ _VERSION ]] && need_ver_code=$need_ver ||
7473 need_ver_code=$(version_code $need_ver)
7475 (( ${!have_ver_code} $op $need_ver_code )) &&
7476 echo "- see $facet $op $need_ver for $jira, go $subs" ||
7478 log "- need $facet $op $need_ver for $jira, skip $subs"
7480 eval EXCEPT_${E}=true
7483 done < <(do_nodes $nodes "cat $exceptions 2>/dev/null ||true" | sort -u)
7485 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
7486 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
7487 [[ -z "$EXCEPT_SLOW" ]] ||
7488 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
7489 for E in ${EXCEPT//[+,]/ }; do
7490 eval EXCEPT_${E}=true
7492 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
7493 eval EXCEPT_ALWAYS_${E}=true
7495 for E in ${EXCEPT_SLOW//[+,]/ }; do
7496 eval EXCEPT_SLOW_${E}=true
7498 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
7499 eval GCHECK_ONLY_${G}=true
7501 # similar to $EXCEPT, STOP_ON_ERROR is a list of test numbers,
7502 # e.g. [30d, 34a]. Now set variable STOP_ON_ERROR_30d, etc.
7503 for T in $STOP_ON_ERROR; do
7504 eval STOP_ON_ERROR_${T}=true
7509 if [[ $1 = [a-z]* ]]; then
7512 echo ${1%%[a-zA-Z]*}
7516 # print a newline if the last test was skipped
7517 export LAST_SKIPPED=
7518 export ALWAYS_SKIPPED=
7520 # Main entry into test-framework. This is called with the number and
7521 # description of a test. The number is used to find the function to run
7522 # the test using "test_$name".
7524 # This supports a variety of methods of specifying specific test to
7526 # - ONLY= env variable with space-separated list of test numbers to run
7527 # - EXCEPT= env variable with space-separated list of test numbers to exclude
7533 export base=$(basetest $testnum)
7534 export TESTNAME=test_$testnum
7538 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
7539 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
7540 local isexcept=EXCEPT_$testnum
7541 local isexcept_base=EXCEPT_$base
7542 if [ ${!isexcept}x != x ]; then
7544 skip_message="skipping excluded test $testnum"
7545 elif [ ${!isexcept_base}x != x ]; then
7547 skip_message="skipping excluded test $testnum (base $base)"
7550 isexcept=EXCEPT_ALWAYS_$testnum
7551 isexcept_base=EXCEPT_ALWAYS_$base
7552 if [ ${!isexcept}x != x ]; then
7554 skip_message="skipping ALWAYS excluded test $testnum"
7555 elif [ ${!isexcept_base}x != x ]; then
7557 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
7560 isexcept=EXCEPT_SLOW_$testnum
7561 isexcept_base=EXCEPT_SLOW_$base
7562 if [ ${!isexcept}x != x ]; then
7564 skip_message="skipping SLOW test $testnum"
7565 elif [ ${!isexcept_base}x != x ]; then
7567 skip_message="skipping SLOW test $testnum (base $base)"
7570 # If there are tests on the ONLY list, check if the current test
7571 # is on that list and, if so, check if the test is to be skipped
7572 # and if we are supposed to honor the skip lists.
7573 if [ -n "$ONLY" ]; then
7574 local isonly=ONLY_$testnum
7575 local isonly_base=ONLY_$base
7576 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
7578 if [[ -n "$ALWAYS_SKIPPED" &&
7579 -n "$HONOR_EXCEPT" ]]; then
7581 skip_noexit "$skip_message"
7584 [ -n "$LAST_SKIPPED" ] &&
7585 echo "" && LAST_SKIPPED=
7587 run_one_logged $testnum "$testmsg"
7597 if [ -n "$ALWAYS_SKIPPED" ]; then
7599 skip_noexit "$skip_message"
7602 run_one_logged $testnum "$testmsg"
7603 # TODO: Avoid running out of space!?
7604 if [[ "$FSTYPE" == "wbcfs" ]]; then
7613 load_module ../libcfs/libcfs/libcfs
7626 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
7631 strace -o $TMP/$1.strace -ttt $*
7633 log "FINISHED: $*: rc $RC"
7640 banner "test complete, duration $duration sec"
7641 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
7642 echo "duration $duration" >>$TESTSUITELOG
7646 # Set TEST_STATUS here. It will be used for logging the result.
7649 if [[ -f $LOGDIR/err ]]; then
7651 elif [[ -f $LOGDIR/skip ]]; then
7654 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
7658 local FFREE=$(do_node $SINGLEMDS \
7659 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
7660 local FTOTAL=$(do_node $SINGLEMDS \
7661 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
7663 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
7668 #echo -n "Resetting fail_loc on all nodes..."
7669 do_nodes --quiet $(comma_list $(nodes_list)) \
7670 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
7676 # Log a message (on all nodes) padded with "=" before and after.
7677 # Also appends a timestamp and prepends the testsuite name.
7680 # ======================================================== 15:06:12 (1624050372)
7681 EQUALS="========================================================"
7683 msg="== ${TESTSUITE} $*"
7685 [[ $last != "=" && $last != " " ]] && msg="$msg "
7686 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
7687 # always include at least == after the message
7688 log "$msg== $(date +"%H:%M:%S (%s)")"
7691 check_dmesg_for_errors() {
7694 local testid=$(tr '_' ' ' <<< $TESTNAME)
7696 errors="VFS: Busy inodes after unmount of"
7697 errors+="\|ldiskfs_check_descriptors: Checksum for group 0 failed"
7698 errors+="\|group descriptors corrupted"
7699 errors+="\|UBSAN\|KASAN"
7701 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" |
7702 tac | sed "/$testid/,$ d" | grep "$errors")
7703 [[ -n "$res" ]] || return 0
7704 echo "Kernel error detected: $res"
7709 # Run a single test function and cleanup after it.
7711 # This function should be run in a subshell so the test func can
7712 # exit() without stopping the whole script.
7717 local SAVE_UMASK=`umask`
7720 if ! grep -q $DIR /proc/mounts; then
7724 banner "test $testnum: $testmsg"
7725 test_${testnum} || error "test_$testnum failed with $?"
7728 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7730 check_dmesg_for_errors || error "Error in dmesg detected"
7731 if [ "$PARALLEL" != "yes" ]; then
7732 ps auxww | grep -v grep | grep -q "multiop " &&
7733 error "multiop still running"
7741 # Wrapper around run_one to ensure:
7742 # - test runs in subshell
7743 # - output of test is saved to separate log file for error reporting
7744 # - test result is saved to data file
7747 local before=$SECONDS
7750 export tfile=f${testnum}.${TESTSUITE}
7751 export tdir=d${testnum}.${TESTSUITE}
7752 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7753 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7754 local SAVE_UMASK=$(umask)
7759 [[ $KPTR_ON_MOUNT ]] || kptr_enable_and_save
7761 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7764 # process ONLY options:
7765 # - $ONLY_REPEAT will run the subtest $ONLY_REPEAT times
7766 # - $ONLY_MINUTES will run the subtest for $ONLY_MINUTES
7767 # - $ONLY_REPEAT and $ONLY_MINUTES can be set to run the subtest for
7768 # $ONLY_REPEAT times but not to exceed $ONLY_MINUTES
7769 # - if $ONLY_REPEAT and ONLY_MINUTES are unset, subtest will run once
7770 local repeat=${ONLY:+$ONLY_REPEAT}
7771 if [[ -n "$ONLY" && "$ONLY_MINUTES" ]]; then
7772 local repeat_end_sec=$((SECONDS + ONLY_MINUTES * 60))
7775 export ONLY_REPEAT_ITER=1
7777 local before_sub=$SECONDS
7780 log_sub_test_begin $TESTNAME
7781 # remove temp files between repetitions to avoid test failures
7782 if [[ -n "$append" ]]; then
7783 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7784 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7785 iter=" (repeat $ONLY_REPEAT_ITER/$repeat iter, $(((SECONDS-before)/60))/$ONLY_MINUTES min)"
7787 # loop around subshell so stack_trap EXIT triggers each time
7788 (run_one $testnum "$testmsg$iter") 2>&1 | tee -i $append $test_log
7791 local duration_sub=$((SECONDS - before_sub))
7794 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7795 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7797 if [[ -f $LOGDIR/err ]]; then
7798 test_error=$(cat $LOGDIR/err)
7800 elif [[ -f $LOGDIR/ignore ]]; then
7801 test_error=$(cat $LOGDIR/ignore)
7802 elif [[ -f $LOGDIR/skip ]]; then
7803 test_error=$(cat $LOGDIR/skip)
7809 pass "$testnum" "(${duration_sub}s)"
7810 if [ -n "${DUMP_OK}" ]; then
7811 gather_logs $(comma_list $(nodes_list))
7814 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7816 # exit test suite if the failed test is in STOP_ON_ERROR list
7817 [[ $TEST_STATUS == "FAIL" ]] &&
7818 [[ -v STOP_ON_ERROR_$testnum ]] &&
7821 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7823 # no repeat options were set, break after the first iteration
7824 [[ -z "$repeat" && -z "$repeat_end_sec" ]] && break
7825 # break if any repeat options were set and have been met
7826 [[ -n "$repeat" ]] && (( ONLY_REPEAT_ITER >= repeat )) && break
7827 [[ -n "$repeat_end_sec" ]] &&
7828 (( $SECONDS >= $repeat_end_sec )) && break
7829 ((ONLY_REPEAT_ITER++))
7832 [[ $KPTR_ON_MOUNT ]] || kptr_restore
7834 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7838 if [ -f $LOGDIR/err ]; then
7839 log_zfs_info "$zfs_debug_log"
7840 $FAIL_ON_ERROR && exit $rc
7853 # Print information of skipped tests to result.yml
7856 log_sub_test_begin $1
7858 log_sub_test_end "SKIP" "0" "0" "$@"
7861 grant_from_clients() {
7865 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7869 grant_from_servers() {
7873 # which is tot_granted less grant_precreate
7874 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7875 " obdfilter.${FSNAME}-OST*.tot_pending" \
7876 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7877 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7878 /tot_pending/{ total -= $2 };
7879 /grant_precreate/{ total -= $2 };
7880 END { printf("%0.0f", total) }'
7884 export base=$(basetest $1)
7885 [ "$CHECK_GRANT" == "no" ] && return 0
7887 local isonly_base=GCHECK_ONLY_${base}
7888 local isonly=GCHECK_ONLY_$1
7889 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7891 echo -n "checking grant......"
7893 local osts=$(osts_nodes)
7894 local clients=$CLIENTS
7895 [ -z "$clients" ] && clients=$(hostname)
7897 # sync all the data and make sure no pending data on server
7898 do_nodes $clients sync
7899 do_nodes $clients $LFS df # initiate all idling connections
7902 cli_grant=$(grant_from_clients $clients)
7905 # which is tot_granted less grant_precreate
7906 srv_grant=$(grant_from_servers $osts)
7909 # check whether client grant == server grant
7910 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7911 echo "wait for client:$cli_grant == server:$srv_grant"
7913 cli_grant=$(grant_from_clients $clients)
7914 srv_grant=$(grant_from_servers $osts)
7916 if [[ $cli_grant -ne $srv_grant ]]; then
7917 do_nodes $osts "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7918 "obdfilter.${FSNAME}-OST*.grant_*"
7919 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7920 error "failed grant check: client:$cli_grant server:$srv_grant"
7922 echo "pass grant check: client:$cli_grant server:$srv_grant"
7926 ########################
7935 ostuuid_from_index() {
7936 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7937 local uuid=($($LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7942 ostname_from_index() {
7943 local uuid=$(ostuuid_from_index $1 $2)
7948 mdtuuid_from_index() {
7949 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7950 local uuid=($($LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7955 mdtname_from_index() {
7956 local uuid=$(mdtuuid_from_index $1 $2)
7961 mdssize_from_index() {
7962 local mdt=$(mdtname_from_index $2)
7964 $LFS df $1 | awk "/$mdt/ { print \$2 }"
7967 index_from_ostuuid()
7969 # only print the first index, if 'lfs osts' shows multiple mountpoints
7970 local ostidx=($($LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"))
7976 # Return unique identifier for given hostname
7979 echo $host_name | md5sum | cut -d' ' -f1
7983 # Returns list of ip addresses for each interface
7985 ip -o a s | awk '{print $4}' | awk -F/ '{print $1}'
7989 # Returns list of interfaces configured for LNet
7991 local nids=( $($LCTL list_nids | xargs echo) )
7993 [[ -z ${nids[@]} ]] &&
7996 if [[ ${NETTYPE} =~ kfi* ]]; then
7997 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7998 sort -u | xargs echo
8002 declare -a INTERFACES
8004 for ((i = 0; i < ${#nids[@]}; i++)); do
8005 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
8006 INTERFACES[i]=$(ip -o a s |
8007 awk '$4 ~ /^'$ip'\//{print $2}')
8008 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
8009 if [[ -z ${INTERFACES[i]} ]]; then
8010 error "Can't determine interface name for NID ${nids[i]}"
8011 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
8012 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
8016 echo "${INTERFACES[@]}"
8021 # return 1 if addr is remote
8022 # return 0 if addr is local
8025 # Cache address list to avoid mutiple execution of local_addr_list
8026 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
8028 for i in $LOCAL_ADDR_LIST ; do
8029 [[ "$i" == "$addr" ]] && return 0
8034 # return true(0) if host_name is local
8035 # return false(1) if host_name is remote
8038 local is_local="IS_LOCAL_$(host_id $host_name)"
8040 if [ -z "${!is_local-}" ] ; then
8041 eval $is_local=false
8042 local ip4=$(getent ahostsv4 $host_name |
8043 awk 'NR == 1 { print $1 }')
8044 local ip6=$(getent ahostsv6 $host_name |
8045 awk 'NR == 1 { print $1 }')
8046 if is_local_addr $ip4 || is_local_addr $ip6 ; then
8059 # return true if any MDT is on a remote node
8062 local mdts=$(mdts_nodes)
8065 for node in ${mdts//,/ }; do
8066 remote_node $node && return 0
8072 # return true if any MDT is on a remote node and no remote shell is configured
8075 [ -n "$CLIENTONLY" ] && return 0 || true
8076 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
8081 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
8082 MSKIPPED=1 && return 1
8086 # return true if any OST is on a remote node
8089 local osts=$(osts_nodes)
8092 for node in ${osts//,/ }; do
8093 remote_node $node && return 0
8099 # return true if any OST is on a remote node and no remote shell is configured
8102 [ -n "$CLIENTONLY" ] && return 0 || true
8103 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
8108 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
8109 OSKIPPED=1 && return 1
8115 [ -n "$CLIENTONLY" ] && return 0 || true
8117 MGS=$(facet_host mgs)
8118 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
8123 remote_mds_nodsh || remote_ost_nodsh ||
8124 $(single_local_node $(comma_list $(nodes_list)))
8128 remote_ost && remote_mds
8131 # Get the active nodes for facets.
8139 for facet in ${facets//,/ }; do
8140 nodes="$nodes $(facet_active_host $facet)"
8143 nodes_sort=$(for i in ${nodes//,/ }; do echo $i; done | sort -u)
8147 # Get name of the active MGS node.
8149 echo -n $(facets_nodes $(get_facets MGS))
8152 # Get all of the active MDS nodes.
8154 comma_list $(facets_nodes $(get_facets MDS))
8157 # Get all of the active OSS nodes in a comma-separated list.
8159 comma_list $(facets_nodes $(get_facets OST))
8162 # Get all of the active server nodes in a comma-separated list.
8164 comma_list $(facets_nodes $(get_facets MDS OST))
8167 # Get all of the client nodes and active server nodes.
8169 local nodes=$HOSTNAME
8173 # CLIENTS (if specified) contains the local client
8174 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
8176 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
8177 nodes="$nodes $(facets_nodes $(get_facets))"
8180 nodes_sort=$(for i in ${nodes//,/ }; do echo $i; done | sort -u)
8184 # Get all of the remote client nodes and remote active server nodes.
8185 remote_nodes_list () {
8186 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
8189 # Get all of the MDS nodes, including active and passive nodes.
8196 for ((i=1; i <= $MDSCOUNT; i++)); do
8198 failover_host=mds${i}failover_HOST
8199 nodes="$nodes ${!host} ${!failover_host}"
8205 # Get all of the OSS nodes, including active and passive nodes.
8212 for ((i = 1; i <= $OSTCOUNT; i++)); do
8214 failover_host=ost${i}failover_HOST
8215 nodes="$nodes ${!host} ${!failover_host}"
8221 # Get all of the server nodes, including active and passive nodes.
8222 all_server_nodes () {
8227 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
8229 nodes_sort=$(for i in ${nodes//,/ }; do echo $i; done | sort -u)
8233 # Get all of the client and server nodes, including active and passive nodes.
8235 local nodes=$HOSTNAME
8239 # CLIENTS (if specified) contains the local client
8240 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
8242 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
8243 nodes="$nodes $(all_server_nodes)"
8246 nodes_sort=$(for i in ${nodes//,/ }; do echo $i; done | sort -u)
8250 init_clients_lists () {
8251 # Sanity check: exclude the local client from RCLIENTS
8252 local clients=$(hostlist_expand "$RCLIENTS")
8253 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
8255 # Sanity check: exclude the dup entries
8256 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
8258 export CLIENT1=${CLIENT1:-$HOSTNAME}
8259 export SINGLECLIENT=$CLIENT1
8261 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
8263 # Sanity check: exclude the dup entries from CLIENTS
8264 # for those configs which has SINGLCLIENT set to local client
8265 clients=$(for i in $clients; do echo $i; done | sort -u)
8267 export CLIENTS=$(comma_list $clients)
8268 local -a remoteclients=($RCLIENTS)
8269 for ((i=0; $i<${#remoteclients[@]}; i++)); do
8270 varname=CLIENT$((i + 2))
8272 eval export $varname=${remoteclients[i]}
8275 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
8278 get_random_entry () {
8281 rnodes=${rnodes//,/ }
8283 local -a nodes=($rnodes)
8284 local num=${#nodes[@]}
8285 local i=$((RANDOM * num * 2 / 65536))
8291 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
8295 # this should already have been called, but just in case
8296 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
8299 echo "client=$CLIENT_VERSION MDS=$MDS1_VERSION OSS=$OST1_VERSION"
8301 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
8302 error "unable to determine node versions"
8304 (( "$CLIENT_VERSION" == "$MDS1_VERSION" &&
8305 "$CLIENT_VERSION" == "$OST1_VERSION"))
8311 echo ${nodes//,/ } | wc -w || true
8315 local nodes=$(mdts_nodes)
8316 local mdtcount=$(get_node_count "$nodes")
8318 [ ! "$MDSCOUNT" = "$mdtcount" ]
8321 generate_machine_file() {
8322 local nodes=${1//,/ }
8323 local machinefile=$2
8326 for node in $nodes; do
8327 echo $node >>$machinefile ||
8328 { echo "can not generate machinefile $machinefile" &&
8334 local file=$1/stripe
8337 $LFS getstripe -v $file || error "getstripe $file failed"
8341 # Check and add a test group.
8347 local gid=$(getent group $group_name | cut -d: -f3)
8348 if [[ -n "$gid" ]]; then
8349 [[ "$gid" -eq "$group_id" ]] || {
8350 error_noexit "inconsistent group ID:" \
8351 "new: $group_id, old: $gid"
8355 echo "adding group $group_name:$group_id"
8356 getent group $group_name || true
8357 getent group $group_id || true
8358 groupadd -g $group_id $group_name
8365 # Check and add a test user.
8378 local uid=$(getent passwd $user_name | cut -d: -f3)
8379 if [[ -n "$uid" ]]; then
8380 if [[ "$uid" -eq "$user_id" ]]; then
8381 local dir=$(getent passwd $user_name | cut -d: -f6)
8382 if [[ "$dir" != "$home" ]]; then
8384 usermod -d $home $user_name
8388 error_noexit "inconsistent user ID:" \
8389 "new: $user_id, old: $uid"
8394 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
8401 check_runas_id_ret() {
8403 local myRUNAS_UID=$1
8404 local myRUNAS_GID=$2
8408 if [ -z "$myRUNAS" ]; then
8409 error_exit "check_runas_id_ret requires myRUNAS argument"
8413 error "Unable to execute $myRUNAS"
8415 id $myRUNAS_UID > /dev/null ||
8416 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
8417 "some UID which exists on MDS and client or add user " \
8418 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
8421 $myRUNAS krb5_login.sh ||
8422 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
8424 mkdir $DIR/d0_runas_test
8426 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
8427 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
8428 rm -rf $DIR/d0_runas_test
8433 local myRUNAS_UID=$1
8434 local myRUNAS_GID=$2
8438 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
8439 error "unable to write to $DIR/d0_runas_test as " \
8443 # obtain the UID/GID for MPI_USER
8447 if [[ -z "$MPI_USER_UID" ]]; then
8448 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user |
8449 cut -d: -f3; exit \\\${PIPESTATUS[0]}") ||
8450 skip_env "failed to get the UID for $mpi_user"
8451 echo "mpi_user=$1 MPI_USER_UID=$MPI_USER_UID"
8454 if [[ -z "$MPI_USER_GID" ]]; then
8455 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user |
8456 cut -d: -f4; exit \\\${PIPESTATUS[0]}") ||
8457 skip_env "failed to get the GID for $mpi_user"
8458 echo "mpi_user=$1 MPI_USER_GID=$MPI_USER_GID"
8462 # obtain and cache Kerberos ticket-granting ticket
8463 refresh_krb5_tgt() {
8464 local myRUNAS_UID=$1
8465 local myRUNAS_GID=$2
8468 if [ -z "$myRUNAS" ]; then
8469 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
8472 CLIENTS=${CLIENTS:-$HOSTNAME}
8473 do_nodes $CLIENTS "set -x
8474 if ! $myRUNAS krb5_login.sh; then
8475 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
8480 # Run multiop in the background, but wait for it to print
8481 # "PAUSING" to its stdout before returning from this function.
8482 multiop_bg_pause() {
8483 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
8487 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
8490 echo "$MULTIOP_PROG $FILE v$ARGS"
8491 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
8494 echo "TMPPIPE=${TMPPIPE}"
8495 read -t 60 multiop_output < $TMPPIPE
8496 if [ $? -ne 0 ]; then
8501 if [ "$multiop_output" != "PAUSING" ]; then
8502 echo "Incorrect multiop output: $multiop_output"
8517 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
8519 echo $((SECONDS - start))
8523 inodes_available () {
8524 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
8525 sort -un | head -n1) || return 1
8530 mdsrate_inodes_available () {
8531 local min_inodes=$(inodes_available)
8533 echo $((min_inodes * 99 / 100))
8536 bytes_available () {
8537 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
8540 mdsrate_bytes_available () {
8541 local bytes=$(bytes_available)
8543 echo $((bytes * 99 / 100))
8546 # reset stat counters
8548 local paramfile="$1"
8550 lctl set_param -n $paramfile=0
8555 local paramfile="$1"
8558 lctl get_param -n $paramfile |
8559 awk '/^'$stat' / { sum += $2 } END { printf("%0.0f", sum) }'
8563 local paramfile="$1"
8566 lctl get_param -n $paramfile |
8567 awk '/^'$stat' / { sum += $7 } END { printf("%0.0f", sum) }'
8571 awk '{sum += $1} END { printf("%0.0f", sum) }'
8574 calc_osc_kbytes () {
8575 $LFS df $MOUNT > /dev/null
8576 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
8580 wait_delete_completed
8581 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8582 echo "OST kbytes available: ${AVAIL[*]}"
8587 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8588 #echo OST $i: ${AVAIL[i]}kb
8589 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8593 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8598 echo "Min free space: OST $MINI: $MINV"
8599 echo "Max free space: OST $MAXI: $MAXV"
8602 # save_lustre_params(comma separated facet list, parameter_mask)
8603 # generate a stream of formatted strings (<facet> <param name>=<param value>)
8604 save_lustre_params() {
8609 for facet in ${facets//,/ }; do
8610 facet_svc=$(facet_svc $facet)
8612 "params=\\\$($LCTL get_param $2);
8613 [[ -z \\\"$facet_svc\\\" ]] && param= ||
8614 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
8615 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
8616 while read s; do echo $facet \\\$s;
8617 done <<< \\\"\\\$param\\\""
8621 # restore lustre parameters from input stream, produces by save_lustre_params
8622 restore_lustre_params() {
8627 while IFS=" =" read facet name val; do
8628 do_facet $facet "$LCTL set_param -n $name=$val"
8632 check_node_health() {
8633 local nodes=${1:-$(comma_list $(nodes_list))}
8634 local health=$TMP/node_health.$$
8636 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
8637 grep "catastrophe=1" && error "LBUG/LASSERT detected"
8638 # Only check/report network health if get_param isn't reported, since
8639 # *clearly* the network is working if get_param returned something.
8640 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
8641 for node in ${nodes//,/ }; do
8642 check_network $node 60
8648 mdsrate_cleanup () {
8650 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
8651 --nfiles $3 --dir $4 --filefmt $5 $6
8657 local test_type="$1"
8670 local mdtest_basedir
8671 local mdtest_actions
8672 local mdtest_options
8673 local stripe_options
8676 case "$test_type" in
8678 stripe_options=(-c 1 -i 0)
8679 mdtest_actions=(-F -R)
8684 mdtest_actions=(-F -R)
8688 stripe_options=(-c 1)
8689 mdtest_actions=(-C -D -E -k -r)
8694 stripe_options=(-c 1)
8695 mdtest_actions=(-C -D -E -k -r)
8700 stripe_options=(-c -1)
8706 if [[ -n "$MDTEST_DEBUG" ]]; then
8707 mdtest_options+=(-v -v -v)
8710 num_dirs=${NUM_DIRS:-$num_dirs}
8711 num_files=${NUM_FILES:-$num_files}
8712 file_size=${FILE_SIZE:-$file_size}
8713 free_space=$(mdsrate_bytes_available)
8715 if (( file_size * num_files > free_space )); then
8716 file_size=$((free_space / num_files))
8717 log "change file size to $file_size due to" \
8718 "number of files $num_files and" \
8719 "free space limit in $free_space"
8722 if (( file_size > 0 )); then
8723 log "set file size to $file_size"
8724 mdtest_options+=(-w=$file_size)
8727 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
8728 mdtest_basedir=$MOUNT/mdtest
8729 mdtest_options+=(-d=$mdtest_basedir)
8732 num_hosts=$(get_node_count ${CLIENTS//,/ })
8733 num_procs=$((num_cores * num_hosts))
8734 num_inodes=$(mdsrate_inodes_available)
8736 if (( num_inodes < num_files )); then
8737 log "change the number of files $num_files to the" \
8738 "number of available inodes $num_inodes"
8739 num_files=$num_inodes
8742 if (( num_dirs > 1 )); then
8743 num_entries=$((num_files / num_dirs))
8744 # md_validate_tests requires items must be a multiple of
8745 # items per directory
8746 num_files=$((num_entries * num_dirs))
8747 log "split $num_files files to $num_dirs" \
8748 "with $num_entries files each"
8749 mdtest_options+=(-I=$num_entries)
8752 generate_machine_file $CLIENTS $MACHINEFILE ||
8753 error "can not generate machinefile"
8755 install -v -d -m 0777 $mdtest_basedir
8757 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
8759 save_lustre_params $(get_facets MDS) \
8760 mdt.*.enable_remote_dir_gid > $params_file
8762 do_nodes $(mdts_nodes) $LCTL set_param mdt.*.enable_remote_dir_gid=-1
8764 stack_trap "restore_lustre_params < $params_file" EXIT
8766 for np in 1 $num_procs; do
8767 num_entries=$((num_files / np ))
8769 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8770 -np $np -npernode $num_cores $MDTEST \
8771 ${mdtest_options[@]} -n=$num_entries \
8772 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
8776 if (( rc != 0 )); then
8777 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8778 -np $np -npernode $num_cores $MDTEST \
8779 ${mdtest_options[@]} -n=$num_entries \
8780 -r 2>&1 | tee -a "$LOG"
8785 rmdir -v $mdtest_basedir
8786 rm -v $state $MACHINEFILE
8791 ########################
8793 convert_facet2label() {
8796 if [ x$facet = xost ]; then
8798 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8802 local varsvc=${facet}_svc
8804 if [ -n "${!varsvc}" ]; then
8807 # FIXME: Cannot find label correctly for some reason.
8808 # Just assume wbcfs OSD and continue...
8809 if [[ "$FSTYPE" == "wbcfs" ]]; then
8812 error "No label for $facet!"
8817 get_clientosc_proc_path() {
8818 echo "${1}-osc-[-0-9a-f]*"
8821 get_mdtosc_proc_path() {
8823 local ost_label=${2:-"*OST*"}
8825 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8826 local mdt_label=$(convert_facet2label $mds_facet)
8827 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8829 if [[ $ost_label = *OST* ]]; then
8830 echo "${ost_label}-osc-${mdt_index}"
8832 echo "${ost_label}-osp-${mdt_index}"
8836 get_osc_import_name() {
8839 local label=$(convert_facet2label $ost)
8841 if [ "${facet:0:3}" = "mds" ]; then
8842 get_mdtosc_proc_path $facet $label
8846 get_clientosc_proc_path $label
8850 _wait_import_state () {
8852 local CONN_PROC="$2"
8853 local maxtime=${3:-$(max_recovery_time)}
8854 local err_on_fail=${4:-1}
8858 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8859 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8860 if [[ "${expected}" == "DISCONN" ]]; then
8861 # for disconn we can check after proc entry is removed
8862 [[ -z "${CONN_STATE}" ]] && return 0
8863 # with AT, we can have connect request timeout near
8864 # reconnect timeout and test can't see real disconnect
8865 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8867 if (( $i >= $maxtime )); then
8868 (( $err_on_fail != 0 )) &&
8869 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8873 # Add uniq for multi-mount case
8874 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8879 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8883 wait_import_state() {
8886 local maxtime=${3:-$(max_recovery_time)}
8887 local err_on_fail=${4:-1}
8890 for param in ${params//,/ }; do
8891 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8896 wait_import_state_mount() {
8897 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8901 wait_import_state "$@"
8904 # One client request could be timed out because server was not ready
8905 # when request was sent by client.
8906 # The request timeout calculation details :
8908 # /* We give the server rq_timeout secs to process the req, and
8909 # add the network latency for our local timeout. */
8910 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8911 # ptlrpc_at_get_net_latency(request) ;
8913 # ptlrpc_connect_import ()
8914 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8917 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8918 # ptlrpc_at_get_net_latency(request) ->
8919 # at_get (max (iat_net_latency=0, at_min)) = at_min
8922 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8923 # INITIAL_CONNECT_TIMEOUT + at_min
8925 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8926 # because we can not get this value in runtime,
8927 # the value depends on configure options, and it is not stored in /proc.
8929 # #define CONNECTION_SWITCH_MIN 5U
8930 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8932 request_timeout () {
8935 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8936 local init_connect_timeout=$TIMEOUT
8937 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8939 local at_min=$(at_get $facet at_min)
8941 echo $(( init_connect_timeout + at_min ))
8944 _wait_osc_import_state() {
8948 local target=$(get_osc_import_name $facet $ost_facet)
8949 local param="os[cp].${target}.ost_server_uuid"
8953 # 1. wait the deadline of client 1st request (it could be skipped)
8954 # 2. wait the deadline of client 2nd request
8955 local maxtime=$(( 2 * $(request_timeout $facet)))
8957 if [[ $facet == client* ]]; then
8958 # During setup time, the osc might not be setup, it need wait
8959 # until list_param can return valid value.
8960 params=$($LCTL list_param $param 2>/dev/null | head -1)
8961 while [ -z "$params" ]; do
8962 if [ $i -ge $maxtime ]; then
8963 echo "can't get $param in $maxtime secs"
8968 params=$($LCTL list_param $param 2>/dev/null | head -1)
8972 if [[ $ost_facet = mds* ]]; then
8973 # no OSP connection to itself
8974 if [[ $facet = $ost_facet ]]; then
8977 param="osp.${target}.mdt_server_uuid"
8981 local plist=$(comma_list $params)
8982 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8983 wait_import_state $expected $plist $maxtime; then
8984 error "$facet: import is not in $expected state after $maxtime"
8991 wait_osc_import_state() {
8997 if [[ $facet = mds ]]; then
8998 for num in $(seq $MDSCOUNT); do
8999 _wait_osc_import_state mds$num "$ost_facet" "$expected"
9002 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
9006 wait_osc_import_ready() {
9007 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
9010 _wait_mgc_import_state() {
9013 local error_on_failure=${3:-1}
9014 local param="mgc.*.mgs_server_uuid"
9018 # 1. wait the deadline of client 1st request (it could be skipped)
9019 # 2. wait the deadline of client 2nd request
9020 local maxtime=$(( 2 * $(request_timeout $facet)))
9022 if [[ $facet == client* ]]; then
9023 # During setup time, the osc might not be setup, it need wait
9024 # until list_param can return valid value. And also if there
9025 # are mulitple osc entries we should list all of them before
9027 params=$($LCTL list_param $param 2>/dev/null || true)
9028 while [ -z "$params" ]; do
9029 if [ $i -ge $maxtime ]; then
9030 echo "can't get $param in $maxtime secs"
9035 params=$($LCTL list_param $param 2>/dev/null || true)
9038 local plist=$(comma_list $params)
9039 if ! do_rpc_nodes "$(facet_active_host $facet)" \
9040 wait_import_state $expected $plist $maxtime \
9041 $error_on_failure; then
9042 if [ $error_on_failure -ne 0 ]; then
9043 error "import is not in ${expected} state"
9051 wait_mgc_import_state() {
9054 local error_on_failure=${3:-1}
9057 if [[ $facet = mds ]]; then
9058 for num in $(seq $MDSCOUNT); do
9059 _wait_mgc_import_state mds$num "$expected" \
9060 $error_on_failure || return
9063 _wait_mgc_import_state "$facet" "$expected" \
9064 $error_on_failure || return
9070 local remtgt=$(facet_svc $2)
9072 local loctgt=$(facet_svc $facet)
9073 local param="osp.$remtgt-os[pc]-${loctgt#*-}.*_server_uuid"
9075 do_rpc_nodes "$(facet_active_host $facet)" \
9076 wait_import_state $expected $param ||
9077 error "$param: import is not in expected state"
9080 wait_dne_interconnect() {
9083 if [ $MDSCOUNT -gt 1 ]; then
9084 for num in $(seq $MDSCOUNT); do
9085 wait_osc_import_ready mds mds$num
9090 get_clientmdc_proc_path() {
9094 get_clientmgc_proc_path() {
9101 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
9106 [ -z "$list" ] && return 0
9108 # Add paths to lustre tests for 32 and 64 bit systems.
9109 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
9110 local TESTPATH="$RLUSTRE/tests:"
9111 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
9112 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
9113 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
9114 CONFIG=${CONFIG} bash rpc.sh $* "
9117 wait_clients_import_state () {
9121 local facets="$facet"
9123 if [ "$FAILURE_MODE" = HARD ]; then
9124 facets=$(for f in ${facet//,/ }; do
9125 facets_on_host $(facet_active_host $f) | tr "," "\n"
9126 done | sort -u | paste -sd , )
9129 for facet in ${facets//,/ }; do
9130 local label=$(convert_facet2label $facet)
9133 ost* ) proc_path="osc.$(get_clientosc_proc_path \
9134 $label).ost_server_uuid" ;;
9135 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
9136 $label).mds_server_uuid" ;;
9137 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
9138 $label).mgs_server_uuid" ;;
9139 *) error "unknown facet!" ;;
9142 local params=$(expand_list $params $proc_path)
9145 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
9147 error "import is not in ${expected} state"
9152 wait_clients_import_ready() {
9153 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
9160 $LCTL get_param osc.$tgt.import | awk "/$param/ { print \$2 }"
9172 # wait until all MDTs are in the expected state
9173 for ((num = 1; num <= $MDSCOUNT; num++)); do
9174 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
9177 if [ $facet = "mds" ]; then
9178 mproc="osp.$mdtosp.active"
9179 [ $num -eq $((tgt_idx + 1)) ] && continue
9181 mproc="osc.$mdtosp.active"
9187 val=$(do_facet mds${num} "$LCTL get_param -n $mproc")
9189 if (( rc != 0 )); then
9190 echo "Can't read $mproc (rc = $rc)"
9191 elif [[ "$val" == "$expected" ]]; then
9192 echo "$mproc updated after $wait sec (got $val)"
9197 error "$tgt_name: wanted $expected got $val"
9199 echo "Waiting $((max - wait)) secs for $mproc"
9211 local osts=$(osts_nodes)
9213 availa=($(do_nodes $osts "$LCTL get_param obdfilter.*.kbytesavail"))
9214 granta=($(do_nodes $osts "$LCTL get_param -n obdfilter.*.tot_granted"))
9215 totala=($(do_nodes $osts "$LCTL get_param -n obdfilter.*.kbytestotal"))
9216 for ((i=0; i<${#availa[@]}; i++)); do
9217 local -a avail1=(${availa[$i]//=/ })
9218 local -a total=(${totala[$i]//=/ })
9219 local grant=$((${granta[$i]}/1024))
9220 # allow 1% of total space in bavail because of delayed
9221 # allocation with ZFS which might release some free space after
9222 # txg commit. For small devices, we set a mininum of 8MB
9223 local limit=$((total / 100 + 8000))
9225 echo -n $(echo ${avail1[0]} | cut -d"." -f2) avl=${avail1[1]} \
9226 grnt=$grant diff=$((avail1[1] - grant)) limit=${limit}
9227 [ $((avail1[1] - grant)) -lt $limit ] && oscfull=0 &&
9228 echo " FULL" || echo
9235 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
9238 check_pool_not_exist() {
9239 local fsname=${1%%.*}
9240 local poolname=${1##$fsname.}
9241 [[ $# -ne 1 ]] && return 0
9242 [[ x$poolname = x ]] && return 0
9243 list_pool $fsname | grep -w $1 && return 1
9248 local fsname=${1%%.*}
9249 local poolname=${1##$fsname.}
9250 local keep_pools=${2:-false}
9251 local mdscount=${3:-$MDSCOUNT}
9252 # can't pass an empty argument to destroy_test_pools
9253 local dtp_fsname=${fsname:-$FSNAME}
9255 stack_trap "destroy_test_pools $dtp_fsname $mdscount" EXIT
9256 do_facet mgs lctl pool_new $1
9258 # get param should return err unless pool is created
9259 [[ $RC -ne 0 ]] && return $RC
9261 for ((mds_id = 1; mds_id < $mdscount; mds_id++)); do
9262 local mdt_id=$((mds_id-1))
9263 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
9264 wait_update_facet mds$mds_id \
9265 "lctl get_param -n lod.$lodname.pools.$poolname \
9266 2>/dev/null || echo foo" "" ||
9267 error "mds$mds_id: pool_new failed $1"
9269 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
9270 2>/dev/null || echo foo" "" || error "pool_new failed $1"
9272 $keep_pools || add_pool_to_list $1
9276 add_pool_to_list () {
9277 local fsname=${1%%.*}
9278 local poolname=${1##$fsname.}
9280 local listvar=${fsname}_CREATED_POOLS
9281 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
9285 remove_pool_from_list () {
9286 local fsname=${1%%.*}
9287 local poolname=${1##$fsname.}
9289 local listvar=${fsname}_CREATED_POOLS
9290 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
9294 # cleanup all pools exist on $FSNAME
9295 destroy_all_pools () {
9297 for i in $(list_pool $FSNAME); do
9302 destroy_pool_int() {
9304 local OSTS=$(list_pool $1)
9305 for ost in $OSTS; do
9306 do_facet mgs lctl pool_remove $1 $ost
9308 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
9309 error "MDS: pool_list $1 failed"
9310 do_facet mgs lctl pool_destroy $1
9313 # <fsname>.<poolname> or <poolname>
9315 local fsname=${1%%.*}
9316 local poolname=${1##$fsname.}
9317 local mdscount=${2:-$MDSCOUNT}
9319 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
9323 check_pool_not_exist $fsname.$poolname && return 0 || true
9325 destroy_pool_int $fsname.$poolname
9327 [[ $RC -ne 0 ]] && return $RC
9328 for ((mds_id = 1; mds_id < $mdscount; mds_id++)); do
9329 local mdt_id=$((mds_id-1))
9330 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
9331 wait_update_facet mds$mds_id \
9332 "lctl get_param -n lod.$lodname.pools.$poolname \
9333 2>/dev/null || echo foo" "foo" ||
9334 error "mds$mds_id: destroy pool failed $1"
9336 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
9337 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
9339 remove_pool_from_list $fsname.$poolname
9345 local fsname=${1:-$FSNAME}
9346 local mdscount=${2:-$MDSCOUNT}
9348 local listvar=${fsname}_CREATED_POOLS
9350 [ x${!listvar} = x ] && return 0
9352 echo "Destroy the created pools: ${!listvar}"
9353 for poolname in ${!listvar//,/ }; do
9354 destroy_pool $fsname.$poolname $mdscount
9358 destroy_test_pools () {
9359 local fsname=${1:-$FSNAME}
9360 local mdscount=${2:-$MDSCOUNT}
9362 destroy_pools $fsname $mdscount || true
9368 local ts=$(date +%s)
9371 if [[ ! -f "$YAML_LOG" ]]; then
9372 # init_logging is not performed before gather_logs,
9373 # so the $LOGDIR needs to be checked here
9374 check_shared_dir $LOGDIR && touch $LOGDIR/shared
9377 [ -f $LOGDIR/shared ] && docp=false
9379 # dump lustre logs, dmesg, and journal if GSS_SK=true
9381 prefix="$TESTLOG_PREFIX.$TESTNAME"
9383 echo "Dumping lctl log to ${prefix}.*.${suffix}"
9385 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
9386 echo "Dumping logs only on local client."
9387 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
9388 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
9389 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
9390 $LGSS_SK -r {} \; &> \
9391 ${prefix}.ssk_keys.$(hostname -s).${suffix}
9392 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
9393 ${prefix}.nodemaps.$(hostname -s).${suffix}
9394 [ "$GSS" = true ] && keyctl show > \
9395 ${prefix}.keyring.$(hostname -s).${suffix}
9396 [ "$GSS" = true ] && journalctl -a > \
9397 ${prefix}.journal.$(hostname -s).${suffix}
9402 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
9403 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
9404 if [ "$SHARED_KEY" = true ]; then
9405 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
9406 $LGSS_SK -r {} \; &> \
9407 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
9408 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
9409 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
9411 if [ "$GSS" = true ]; then
9412 do_nodesv $list "keyctl show > \
9413 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
9414 do_nodesv $list "journalctl -a > \
9415 ${prefix}.journal.\\\$(hostname -s).${suffix}"
9418 if [ ! -f $LOGDIR/shared ]; then
9419 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
9421 for node in ${remote_nodes//,/ }; do
9422 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
9436 for i in $(seq 0 $num_mntpts); do
9437 cmd="ls -laf ${mntpt_root}$i/$dir"
9443 for pid in $pids; do
9450 # check_and_start_recovery_timer()
9451 # service_time = at_est2timeout(service_time);
9452 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
9453 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
9455 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
9456 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
9457 #define CONNECTION_SWITCH_MIN 5
9458 #define CONNECTION_SWITCH_INC 5
9459 max_recovery_time() {
9460 local init_connect_timeout=$((TIMEOUT / 20))
9461 ((init_connect_timeout >= 5)) || init_connect_timeout=5
9463 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
9464 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
9466 echo -n $service_time
9469 recovery_time_min() {
9470 local connection_switch_min=5
9471 local connection_switch_inc=5
9472 local connection_switch_max
9473 local reconnect_delay_max
9474 local initial_connect_timeout
9478 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
9479 (($connection_switch_min > $TIMEOUT)) &&
9480 max=$connection_switch_min || max=$TIMEOUT
9481 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
9483 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
9484 timeout_20=$((TIMEOUT/20))
9485 (($connection_switch_min > $timeout_20)) &&
9486 initial_connect_timeout=$connection_switch_min ||
9487 initial_connect_timeout=$timeout_20
9489 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
9490 initial_connect_timeout))
9491 echo $((2 * reconnect_delay_max))
9494 get_clients_mount_count () {
9495 local clients=${CLIENTS:-$HOSTNAME}
9497 # we need to take into account the clients mounts and
9498 # exclude mds/ost mounts if any;
9499 do_nodes $clients cat /proc/mounts | grep lustre |
9500 grep -w $MOUNT | wc -l
9504 PROC_CLI="srpc_info"
9505 PROC_CON="srpc_contexts"
9513 if [ $M -lt $N ]; then
9517 while [ $N -lt $M ]; do
9527 calc_connection_cnt() {
9530 # MDT->MDT = 2 * C(M, 2)
9534 comb_m2=$(combination $MDSCOUNT 2)
9536 local num_clients=$(get_clients_mount_count)
9538 local cnt_mdt2mdt=$((comb_m2 * 2))
9539 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
9540 local cnt_cli2ost=$((num_clients * OSTCOUNT))
9541 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
9542 if is_mounted $MOUNT2; then
9543 cnt_cli2mdt=$((cnt_cli2mdt * 2))
9544 cnt_cli2ost=$((cnt_cli2ost * 2))
9552 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
9553 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
9554 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
9555 + cnt_cli2ost + cnt_cli2mdt))
9569 local cmd="$tgt.srpc.flavor"
9571 if [ $net == "any" ]; then
9576 if [ $dir != "any" ]; then
9581 log "Setting sptlrpc rule: $cmd"
9582 do_facet mgs "$LCTL conf_param $cmd"
9588 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
9598 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
9599 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
9601 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
9603 if [ "x$bulkspec" != "x" ]; then
9604 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
9606 if [ "x$algs" != "x" ]; then
9607 bulk_count=`echo "$output" | grep "bulk flavor" |
9610 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
9612 if [ $bulk == "bulkn" ]; then
9613 bulk_count=`echo "$output" |
9614 grep "bulk flavor" | grep "null/null" |
9616 elif [ $bulk == "bulki" ]; then
9617 bulk_count=`echo "$output" |
9618 grep "bulk flavor" | grep "/null" |
9619 grep -v "null/" | wc -l`
9621 bulk_count=`echo "$output" |
9622 grep "bulk flavor" | grep -v "/null" |
9623 grep -v "null/" | wc -l`
9626 [ $bulk_count -lt $count ] && count=$bulk_count
9637 local clients=${CLIENTS:-$HOSTNAME}
9639 for c in ${clients//,/ }; do
9640 local output=$(do_node $c lctl get_param -n \
9641 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
9642 local tmpcnt=$(count_flvr "$output" $flavor)
9644 if $GSS_SK && [ $flavor != "null" ]; then
9645 # tmpcnt=min(contexts,flavors) to ensure SK context is
9647 output=$(do_node $c lctl get_param -n \
9648 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
9649 local outcon=$(count_contexts "$output")
9651 if [ "$outcon" -lt "$tmpcnt" ]; then
9655 cnt=$((cnt + tmpcnt))
9662 local clients=${CLIENTS:-$HOSTNAME}
9664 for c in ${clients//,/ }; do
9665 do_node $c lctl get_param \
9666 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null
9669 do_node $c lctl get_param \
9670 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null
9680 local clients=${CLIENTS:-$HOSTNAME}
9682 for c in ${clients//,/ }; do
9684 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
9685 local output=$(do_node $c lctl get_param -n \
9686 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
9687 local tmpcnt=$(count_flvr "$output" $flavor)
9689 if $GSS_SK && [ $flavor != "null" ]; then
9690 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9691 output=$(do_node $c lctl get_param -n \
9692 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
9693 local outcon=$(count_contexts "$output")
9695 if [ "$outcon" -lt "$tmpcnt" ]; then
9699 cnt=$((cnt + tmpcnt))
9706 local clients=${CLIENTS:-$HOSTNAME}
9708 for c in ${clients//,/ }; do
9709 do_node $c lctl get_param \
9710 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null
9713 do_node $c lctl get_param \
9714 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null
9724 if [ $MDSCOUNT -le 1 ]; then
9729 for num in `seq $MDSCOUNT`; do
9730 local output=$(do_facet mds$num lctl get_param -n \
9731 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
9732 local tmpcnt=$(count_flvr "$output" $flavor)
9734 if $GSS_SK && [ $flavor != "null" ]; then
9735 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9736 output=$(do_facet mds$num lctl get_param -n \
9737 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
9738 local outcon=$(count_contexts "$output")
9740 if [ "$outcon" -lt "$tmpcnt" ]; then
9744 cnt=$((cnt + tmpcnt))
9751 for num in `seq $MDSCOUNT`; do
9752 do_facet mds$num lctl get_param \
9753 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null
9756 do_facet mds$num lctl get_param \
9757 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null
9768 for num in `seq $MDSCOUNT`; do
9769 mdtosc=$(get_mdtosc_proc_path mds$num)
9770 mdtosc=${mdtosc/-MDT*/-MDT\*}
9771 local output=$(do_facet mds$num lctl get_param -n \
9772 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
9773 # Ensure SK context is on
9774 local tmpcnt=$(count_flvr "$output" $flavor)
9776 if $GSS_SK && [ $flavor != "null" ]; then
9777 output=$(do_facet mds$num lctl get_param -n \
9778 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
9779 local outcon=$(count_contexts "$output")
9781 if [ "$outcon" -lt "$tmpcnt" ]; then
9785 cnt=$((cnt + tmpcnt))
9792 for num in `seq $MDSCOUNT`; do
9793 mdtosc=$(get_mdtosc_proc_path mds$num)
9794 mdtosc=${mdtosc/-MDT*/-MDT\*}
9795 do_facet mds$num lctl get_param \
9796 os[cp].$mdtosc.$PROC_CLI 2>/dev/null
9799 do_facet mds$num lctl get_param \
9800 os[cp].$mdtosc.$PROC_CON 2>/dev/null
9809 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
9811 count_flvr "$output" $flavor
9816 local dir=$1 # from to
9817 local flavor=$2 # flavor expected
9820 if [ $dir == "cli2mdt" ]; then
9821 res=`flvr_cnt_cli2mdt $flavor`
9822 elif [ $dir == "cli2ost" ]; then
9823 res=`flvr_cnt_cli2ost $flavor`
9824 elif [ $dir == "mdt2mdt" ]; then
9825 res=`flvr_cnt_mdt2mdt $flavor`
9826 elif [ $dir == "mdt2ost" ]; then
9827 res=`flvr_cnt_mdt2ost $flavor`
9828 elif [ $dir == "all2ost" ]; then
9829 res1=`flvr_cnt_mdt2ost $flavor`
9830 res2=`flvr_cnt_cli2ost $flavor`
9831 res=$((res1 + res2))
9832 elif [ $dir == "all2mdt" ]; then
9833 res1=`flvr_cnt_mdt2mdt $flavor`
9834 res2=`flvr_cnt_cli2mdt $flavor`
9835 res=$((res1 + res2))
9836 elif [ $dir == "all2all" ]; then
9837 res1=`flvr_cnt_mdt2ost $flavor`
9838 res2=`flvr_cnt_cli2ost $flavor`
9839 res3=`flvr_cnt_mdt2mdt $flavor`
9840 res4=`flvr_cnt_cli2mdt $flavor`
9841 res=$((res1 + res2 + res3 + res4))
9849 local clients=${CLIENTS:-$HOSTNAME}
9852 for c in ${clients//,/ }; do
9853 [ "$type" == "osc" ] &&
9854 do_node $c lctl get_param osc.*.idle_timeout
9855 do_node $c lctl get_param $type.*.import |
9856 grep -E "name:|state:"
9862 local dir=$1 # from to
9864 if [ $dir == "cli2mdt" ]; then
9865 do_dump_imp_state mdc
9867 elif [ $dir == "cli2ost" ]; then
9868 do_dump_imp_state osc
9870 elif [ $dir == "mdt2mdt" ]; then
9872 elif [ $dir == "mdt2ost" ]; then
9874 elif [ $dir == "all2ost" ]; then
9876 do_dump_imp_state osc
9878 elif [ $dir == "all2mdt" ]; then
9880 do_dump_imp_state mdc
9882 elif [ $dir == "all2all" ]; then
9884 do_dump_imp_state osc
9887 do_dump_imp_state mdc
9894 local dir=$1 # from to
9895 local flavor=$2 # flavor expected
9896 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
9897 local WAITFLAVOR_MAX=20 # how many retries before abort?
9900 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
9901 echo -n "checking $dir..."
9902 res=$(do_check_flavor $dir $flavor)
9903 echo "found $res/$expect $flavor connections"
9904 [ $res -ge $expect ] && return 0
9908 echo "Error checking $flavor of $dir: expect $expect, actual $res"
9909 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
9912 gather_logs $(comma_list $(nodes_list))
9917 restore_to_default_flavor()
9919 local proc="mgs.MGS.live.$FSNAME"
9921 echo "restoring to default flavor..."
9923 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9924 grep ".srpc.flavor" | wc -l)
9926 # remove all existing rules if any
9927 if [ $nrule -ne 0 ]; then
9928 echo "$nrule existing rules"
9929 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9930 grep ".srpc.flavor."); do
9931 echo "remove rule: $rule"
9932 spec=`echo $rule | awk -F = '{print $1}'`
9933 do_facet mgs "$LCTL conf_param -d $spec"
9937 # verify no rules left
9938 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9939 grep ".srpc.flavor." | wc -l)
9940 [ $nrule -ne 0 ] && error "still $nrule rules left"
9942 # wait for default flavor to be applied
9945 set_rule $FSNAME any any $SK_FLAVOR
9946 wait_flavor all2all $SK_FLAVOR
9948 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9949 set_rule $FSNAME any cli2ost $SK_FLAVOR
9950 wait_flavor cli2mdt $SK_FLAVOR
9951 wait_flavor cli2ost $SK_FLAVOR
9953 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9955 wait_flavor all2all null
9961 local flavor=${1:-null}
9962 local maxtime=$(( 2 * $(request_timeout client)))
9963 local clients=${CLIENTS:-$HOSTNAME}
9965 echo "setting all flavor to $flavor"
9967 # make sure all oscs are connected
9968 for c in ${clients//,/ }; do
9969 do_node $c lfs df -h
9970 do_rpc_nodes $c wait_import_state "FULL" \
9971 "osc.*.ost_server_uuid" $maxtime ||
9972 error "OSCs not in FULL state for client $c"
9975 # FIXME need parameter to this fn
9976 # and remove global vars
9977 local cnt_all2all=$(calc_connection_cnt all2all)
9979 local res=$(do_check_flavor all2all $flavor)
9980 if [ $res -eq $cnt_all2all ]; then
9981 echo "already have total $res $flavor connections"
9985 echo "found $res $flavor out of total $cnt_all2all connections"
9986 restore_to_default_flavor
9988 [[ $flavor = null ]] && return 0
9990 if $GSS_SK && [ $flavor != "null" ]; then
9992 set_rule $FSNAME any any $flavor
9993 wait_flavor all2all $flavor
9995 set_rule $FSNAME any cli2mdt $flavor
9996 set_rule $FSNAME any cli2ost $flavor
9997 set_rule $FSNAME any mdt2ost null
9998 set_rule $FSNAME any mdt2mdt null
9999 wait_flavor cli2mdt $flavor
10000 wait_flavor cli2ost $flavor
10002 echo "GSS_SK now at flavor: $flavor"
10004 set_rule $FSNAME any cli2mdt $flavor
10005 set_rule $FSNAME any cli2ost $flavor
10006 set_rule $FSNAME any mdt2ost null
10007 set_rule $FSNAME any mdt2mdt null
10008 wait_flavor cli2mdt $flavor
10009 wait_flavor cli2ost $flavor
10016 # Checking for shared logdir
10017 if [ ! -d $dir ]; then
10018 # Not found. Create local logdir
10021 touch $dir/check_file.$(hostname -s)
10026 check_write_access() {
10028 local list=${2:-$(comma_list $(nodes_list))}
10032 for node in ${list//,/ }; do
10033 file=$dir/check_file.$(short_nodename $node)
10034 if [[ ! -f "$file" ]]; then
10035 # Logdir not accessible/writable from this node.
10038 rm -f $file || return 1
10044 [[ -n $YAML_LOG ]] && return
10045 local save_umask=$(umask)
10048 export YAML_LOG=${LOGDIR}/results.yml
10052 # If the yaml log already exists then we will just append to it
10053 if [ ! -f $YAML_LOG ]; then
10054 if check_shared_dir $LOGDIR; then
10055 touch $LOGDIR/shared
10056 echo "Logging to shared log directory: $LOGDIR"
10058 echo "Logging to local directory: $LOGDIR"
10061 yml_nodes_file $LOGDIR >> $YAML_LOG
10062 yml_results_file >> $YAML_LOG
10067 # log actual client and server versions if needed for debugging
10068 log "Client: $(lustre_build_version client)"
10069 log "MDS: $(lustre_build_version mds1)"
10070 log "OSS: $(lustre_build_version ost1)"
10074 yml_log_test $1 >> $YAML_LOG
10077 log_test_status() {
10078 yml_log_test_status "$@" >> $YAML_LOG
10081 log_sub_test_begin() {
10082 yml_log_sub_test_begin "$@" >> $YAML_LOG
10085 log_sub_test_end() {
10086 yml_log_sub_test_end "$@" >> $YAML_LOG
10091 local dev=$1; shift
10092 local llverdev_opts="$*"
10093 local devname=$(basename $dev)
10094 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
10095 # loop devices aren't in /proc/partitions
10096 [[ -z "$size" ]] && size=$(stat -c %s $dev)
10098 local size_gb=$((size / 1024 / 1024)) # Gb
10100 local partial_arg=""
10101 # Run in partial (fast) mode if the size of a partition > 1 GB
10102 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
10104 llverdev --force $partial_arg $llverdev_opts $dev
10110 local llverfs_opts=$2
10111 local use_partial_arg=$3
10112 local partial_arg=""
10113 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
10115 # Run in partial (fast) mode if the size of a partition > 1 GB
10116 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
10118 llverfs $partial_arg $llverfs_opts $dir
10122 local devs=${1//,/ }
10125 local rslt=$TMP/sgpdd_survey
10127 # sgpdd-survey cleanups ${rslt}.* files
10129 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
10135 # returns the canonical name for an ldiskfs device
10140 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
10141 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
10142 echo dm-\\\${foo##*:};
10144 name=\\\$(basename \\\$dv);
10145 if [[ \\\$name = *flakey* ]]; then
10146 name=\\\$(lsblk -o NAME,KNAME |
10147 awk /\\\$name/'{print \\\$NF}');
10153 is_sanity_benchmark() {
10154 local benchmarks="dbench bonnie iozone fsx"
10157 for b in $benchmarks; do
10158 if [ "$b" == "$suite" ]; then
10166 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
10170 # Get the available size (KB) of a given obd target.
10177 [[ $facet != client ]] || return 0
10179 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
10184 # Get the page size (bytes) on a given facet node.
10185 # The local client page_size is directly available in PAGE_SIZE.
10189 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
10191 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
10192 page_size=$(do_facet $facet getconf PAGE_SIZE)
10193 echo -n ${page_size:-4096}
10197 # Get the block count of the filesystem.
10199 get_block_count() {
10204 [ -z "$CLIENTONLY" ] &&
10205 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
10206 awk '/^Block count:/ {print $3}')
10207 echo -n ${count:-0}
10210 # Check whether the "ea_inode" feature is enabled or not, to allow
10211 # ldiskfs xattrs over one block in size. Allow both the historical
10212 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
10213 large_xattr_enabled() {
10214 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
10216 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
10218 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
10219 grep -E -q '(ea_inode|large_xattr)'"
10220 return ${PIPESTATUS[0]}
10223 # Get the maximum xattr size supported by the filesystem.
10225 $LCTL get_param -n llite.*.max_easize
10228 # Dump the value of the named xattr from a file.
10229 get_xattr_value() {
10230 local xattr_name=$1
10233 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
10236 # Generate a string with size of $size bytes.
10237 generate_string() {
10238 local size=${1:-1024} # in bytes
10240 echo "$(head -c $size < /dev/zero | tr '\0' y)"
10243 reformat_external_journal() {
10248 local varbs=${facet}_BLOCKSIZE
10249 if [ -n "${!var}" ]; then
10250 local rcmd="do_facet $facet"
10251 local bs=${!varbs:-$BLCKSIZE}
10254 echo "reformat external journal on $facet:${!var}"
10255 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
10259 # MDT file-level backup/restore
10260 mds_backup_restore() {
10263 local devname=$(mdsdevname $(facet_number $facet))
10264 local mntpt=$(facet_mntpt brpt)
10265 local rcmd="do_facet $facet"
10266 local metadata=${TMP}/backup_restore.tgz
10267 local opts=${MDS_MOUNT_FS_OPTS}
10268 local svc=${facet}_svc
10270 if ! ${rcmd} test -b ${devname}; then
10271 opts=$(csa_add "$opts" -o loop)
10274 echo "file-level backup/restore on $facet:${devname}"
10276 # step 1: build mount point
10277 ${rcmd} mkdir -p $mntpt
10278 # step 2: cleanup old backup
10279 ${rcmd} rm -f $metadata
10280 # step 3: mount dev
10281 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
10282 if [ ! -z $igif ]; then
10283 # step 3.5: rm .lustre
10284 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
10286 # step 4: backup metadata
10288 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
10289 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
10291 ${rcmd} $UMOUNT $mntpt || return 5
10292 # step 6: reformat dev
10293 echo "reformat new device"
10294 format_mdt $(facet_number $facet)
10295 # step 7: mount dev
10296 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
10297 # step 8: restore metadata
10298 echo "restore data"
10299 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
10300 --sparse -C $mntpt > /dev/null 2>&1 || return 8
10301 # step 9: remove recovery logs
10302 echo "remove recovery logs"
10303 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
10304 # step 10: umount dev
10305 ${rcmd} $UMOUNT $mntpt || return 10
10306 # step 11: cleanup tmp backup
10307 ${rcmd} rm -f $metaea $metadata
10308 # step 12: reset device label - it's not virgin on
10309 ${rcmd} e2label $devname ${!svc}
10316 local devname=$(mdsdevname $(facet_number $facet))
10317 local mntpt=$(facet_mntpt brpt)
10318 local rcmd="do_facet $facet"
10319 local opts=${MDS_MOUNT_FS_OPTS}
10321 if ! ${rcmd} test -b ${devname}; then
10322 opts=$(csa_add "$opts" -o loop)
10325 echo "removing OI files on $facet: idx=${idx}"
10327 # step 1: build mount point
10328 ${rcmd} mkdir -p $mntpt
10329 # step 2: mount dev
10330 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
10331 if [ -z $idx ]; then
10332 # step 3: remove all OI files
10333 ${rcmd} rm -fv $mntpt/oi.16*
10334 elif [ $idx -lt 2 ]; then
10335 ${rcmd} rm -fv $mntpt/oi.16.${idx}
10339 # others, rm oi.16.[idx, idx * idx, idx ** ...]
10340 for ((i=${idx}; i<64; i=$((i * idx)))); do
10341 ${rcmd} rm -fv $mntpt/oi.16.${i}
10345 ${rcmd} $UMOUNT $mntpt || return 2
10346 # OI files will be recreated when mounted as lustre next time.
10349 # generate maloo upload-able log file name
10350 # \param logname specify unique part of file name
10351 generate_logname() {
10352 local logname=${1:-"default_logname"}
10354 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
10357 # make directory on different MDTs
10362 local hash_name=("all_char" "fnv_1a_64" "crush")
10363 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
10364 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
10366 local overstripe_count
10367 local stripe_command="-c"
10369 (( $MDS1_VERSION > $(version_code v2_15_50-185-g1ac4b9598a) )) &&
10370 hash_name+=("crush2")
10372 while getopts "c:C:H:i:p" opt; do
10374 c) dirstripe_count=$OPTARG;;
10375 C) overstripe_count=$OPTARG;;
10376 H) hash_type=$OPTARG;;
10377 i) dirstripe_index=$OPTARG;;
10379 \?) error "only support -c -H -i -p";;
10383 shift $((OPTIND - 1))
10384 [ $# -eq 1 ] || error "Only creating single directory is supported"
10387 local parent=$(dirname $path)
10388 if [ "$p_option" == "-p" ]; then
10389 [ -d $path ] && return 0
10390 if [ ! -d ${parent} ]; then
10391 mkdir -p ${parent} ||
10392 error "mkdir parent '$parent' failed"
10396 if [[ -n "$overstripe_count" ]]; then
10397 stripe_command="-C"
10398 dirstripe_count=$overstripe_count
10401 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
10402 mkdir $path || error "mkdir '$path' failed"
10406 if [ $dirstripe_index -eq -1 ]; then
10407 mdt_index=$((base % MDSCOUNT))
10409 mdt_index=$dirstripe_index
10412 # randomly choose hash type
10413 [ -z "$hash_type" ] &&
10414 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
10416 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
10417 if [ $dirstripe_count -eq -1 ]; then
10418 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
10424 echo "striped dir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path"
10425 $LFS mkdir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path ||
10426 error "mkdir -i $mdt_index $stripe_command$dirstripe_count -H $hash_type $path failed"
10430 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
10432 # If called many times, passing @last_fd will avoid repeated searching
10433 # already-open FDs repeatedly if we know they are still in use.
10435 # usage: free_fd [last_fd]
10438 local max_fd=$(ulimit -n)
10439 local fd=$((${1:-2} + 1))
10441 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
10444 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
10448 check_mount_and_prep()
10450 is_mounted $MOUNT || setupall
10452 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
10453 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
10454 for idx in $(seq $MDSCOUNT); do
10455 local name="MDT$(printf '%04x' $((idx - 1)))"
10456 rm -rf $MOUNT/.lustre/lost+found/$name/*
10460 # calcule how many ost-objects to be created.
10461 precreated_ost_obj_count()
10465 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
10466 local ost_name="OST$(printf '%04x' $ost_idx)"
10467 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
10468 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10469 osp.$proc_path.prealloc_last_id)
10470 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10471 osp.$proc_path.prealloc_next_id)
10472 local ost_obj_count=$((last_id - next_id + 1))
10474 echo " - precreated_ost_obj_count $proc_path" \
10475 "prealloc_last_id: $last_id" \
10476 "prealloc_next_id: $next_id" \
10477 "count: $ost_obj_count" 1>&2
10479 echo $ost_obj_count
10482 check_file_in_pool()
10487 local res=$($LFS getstripe $file | grep 0x | cut -f2)
10490 for t in $tlist ; do
10491 [ "$i" -eq "$t" ] && continue 2
10494 echo "pool list: $tlist"
10495 echo "striping: $res"
10496 error_noexit "$file not allocated in $pool"
10504 local mdscount=${2:-$MDSCOUNT}
10506 echo "Creating new pool $pool"
10507 create_pool $FSNAME.$pool false $mdscount ||
10508 { error_noexit "No pool created, result code $?"; return 1; }
10509 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
10510 { error_noexit "$pool not in lfs pool_list"; return 2; }
10513 pool_add_targets() {
10514 echo "Adding targets to pool"
10517 local last=${3:-$first}
10519 local mdscount=${5:-$MDSCOUNT}
10521 local list=$(seq $first $step $last)
10523 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10524 local tg=$(for i in $list;
10525 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
10526 local firstx=$(printf "%04x" $first)
10527 local lastx=$(printf "%04x" $last)
10529 do_facet mgs $LCTL pool_add \
10530 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
10531 # ignore EEXIST(17)
10532 if (( $? != 0 && $? != 17 )); then
10533 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
10537 # wait for OSTs to be added to the pool
10538 for ((mds_id = 1; mds_id < $mdscount; mds_id++)); do
10539 local mdt_id=$((mds_id-1))
10540 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10541 wait_update_facet mds$mds_id \
10542 "lctl get_param -n lod.$lodname.pools.$pool |
10543 grep $tg | sort -u | tr '\n' ' '" "$t" || {
10544 error_noexit "mds$mds_id: Add to pool failed"
10548 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
10549 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
10550 error_noexit "Add to pool failed"
10558 echo "Setting pool on directory $tdir"
10560 $LFS setstripe -c 2 -p $pool $tdir && return 0
10562 error_noexit "Cannot set pool $pool to $tdir"
10569 echo "Checking pool on directory $tdir"
10571 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
10572 [ "$res" = "$pool" ] && return 0
10574 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10578 pool_dir_rel_path() {
10579 echo "Testing relative path works well"
10584 mkdir -p $root/$tdir/$tdir
10586 pool_set_dir $pool $tdir || return 1
10587 pool_set_dir $pool ./$tdir || return 2
10588 pool_set_dir $pool ../$tdir || return 3
10589 pool_set_dir $pool ../$tdir/$tdir || return 4
10590 rm -rf $tdir; cd - > /dev/null
10593 pool_alloc_files() {
10594 echo "Checking files allocation from directory pool"
10601 for i in $(seq -w 1 $count)
10603 local file=$tdir/file-$i
10605 check_file_in_pool $file $pool "$tlist" || \
10606 failed=$((failed + 1))
10608 [ "$failed" = 0 ] && return 0
10610 error_noexit "$failed files not allocated in $pool"
10614 pool_create_files() {
10615 echo "Creating files in pool"
10623 for i in $(seq -w 1 $count)
10625 local file=$tdir/spoo-$i
10626 $LFS setstripe -p $pool $file
10627 check_file_in_pool $file $pool "$tlist" || \
10628 failed=$((failed + 1))
10630 [ "$failed" = 0 ] && return 0
10632 error_noexit "$failed files not allocated in $pool"
10637 echo "Checking 'lfs df' output"
10640 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10642 local res=$($LFS df --pool $FSNAME.$pool |
10644 grep "$FSNAME-OST" |
10646 [ "$res" = "$t" ] && return 0
10648 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10652 pool_file_rel_path() {
10653 echo "Creating files in a pool with relative pathname"
10658 { error_noexit "unable to create $tdir"; return 1 ; }
10659 local file="/..$tdir/$tfile-1"
10660 $LFS setstripe -p $pool $file ||
10661 { error_noexit "unable to create $file" ; return 2 ; }
10664 $LFS setstripe -p $pool $tfile-2 || {
10665 error_noexit "unable to create $tfile-2 in $tdir"
10670 pool_remove_first_target() {
10671 echo "Removing first target from a pool"
10672 pool_remove_target $1 -1
10675 pool_remove_target() {
10679 local pname="lov.$FSNAME-*.pools.$pool"
10680 if [ $index -eq -1 ]; then
10681 local t=$($LCTL get_param -n $pname | head -1)
10683 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
10686 echo "Removing $t from $pool"
10687 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10688 for mds_id in $(seq $MDSCOUNT); do
10689 local mdt_id=$((mds_id-1))
10690 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10691 wait_update_facet mds$mds_id \
10692 "lctl get_param -n lod.$lodname.pools.$pool |
10694 error_noexit "mds$mds_id: $t not removed from" \
10699 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10700 error_noexit "$t not removed from $FSNAME.$pool"
10705 pool_remove_all_targets() {
10706 echo "Removing all targets from pool"
10709 local pname="lov.$FSNAME-*.pools.$pool"
10710 for t in $($LCTL get_param -n $pname | sort -u)
10712 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10714 for mds_id in $(seq $MDSCOUNT); do
10715 local mdt_id=$((mds_id-1))
10716 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10717 wait_update_facet mds$mds_id "lctl get_param -n \
10718 lod.$lodname.pools.$pool" "" || {
10719 error_noexit "mds$mds_id: Pool $pool not drained"
10723 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10724 error_noexit "Pool $FSNAME.$pool cannot be drained"
10727 # striping on an empty/nonexistant pool should fall back
10728 # to "pool of everything"
10730 error_noexit "failed to use fallback striping for empty pool"
10733 # setstripe on an empty pool should fail
10734 $LFS setstripe -p $pool $file 2>/dev/null && {
10735 error_noexit "expected failure when creating file" \
10743 echo "Destroying pool"
10747 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10750 # striping on an empty/nonexistant pool should fall back
10751 # to "pool of everything"
10753 error_noexit "failed to use fallback striping for missing pool"
10756 # setstripe on an empty pool should fail
10757 $LFS setstripe -p $pool $file 2>/dev/null && {
10758 error_noexit "expected failure when creating file" \
10759 "with missing pool"
10763 # get param should return err once pool is gone
10764 if wait_update $HOSTNAME "lctl get_param -n \
10765 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10767 remove_pool_from_list $FSNAME.$pool
10770 error_noexit "Pool $FSNAME.$pool is not destroyed"
10774 # Get and check the actual stripe count of one file.
10775 # Usage: check_stripe_count <file> <expected_stripe_count>
10776 check_stripe_count() {
10781 [[ -z "$file" || -z "$expected" ]] &&
10782 error "check_stripe_count: invalid argument"
10784 local cmd="$LFS getstripe -c $file"
10785 actual=$($cmd) || error "$cmd failed"
10786 actual=${actual%% *}
10788 if [[ $actual -ne $expected ]]; then
10789 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
10790 error "$cmd not expected ($expected): found $actual"; }
10791 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
10792 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
10796 # Get and check the actual list of OST indices on one file.
10797 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
10803 [[ -z "$file" || -z "$expected" ]] &&
10804 error "check_obdidx: invalid argument!"
10806 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
10807 grep -v obdidx | awk '{print $1}' | xargs))
10809 [[ $obdidx = $expected ]] ||
10810 error "list of OST indices on $file is $obdidx," \
10811 "should be $expected"
10814 # Get and check the actual OST index of the first stripe on one file.
10815 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
10816 check_start_ost_idx() {
10819 local start_ost_idx
10821 [[ -z "$file" || -z "$expected" ]] &&
10822 error "check_start_ost_idx: invalid argument!"
10824 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
10825 grep -v obdidx | awk '{print $1}')
10827 [[ $start_ost_idx = $expected ]] ||
10828 error "OST index of the first stripe on $file is" \
10829 "$start_ost_idx, should be $expected"
10832 killall_process () {
10833 local clients=${1:-$(hostname)}
10838 do_nodes $clients "killall $signal $name"
10845 if (( $MDS1_VERSION >= $(version_code 2.16.50) )); then
10846 do_facet mgs "$LCTL snapshot $cmd -F $FSNAME $*"
10848 do_facet mgs "$LCTL snapshot_$cmd -F $FSNAME $*"
10854 lsnapshot create $*
10857 lsnapshot_destroy()
10859 lsnapshot destroy $*
10864 lsnapshot modify $*
10879 lsnapshot umount $*
10886 do_facet mgs "cat $LSNAPSHOT_LOG"
10892 echo "Cleaning test environment ..."
10894 # Every lsnapshot command takes exclusive lock with others,
10895 # so can NOT destroy the snapshot during list with 'xargs'.
10897 local ssname=$(lsnapshot_list | grep snapshot_name |
10898 grep lss_ | awk '{ print $2 }' | head -n 1)
10899 [ -z "$ssname" ] && break
10901 lsnapshot_destroy -n $ssname -f ||
10902 lss_err "Fail to destroy $ssname by force"
10912 local host=$(facet_active_host $facet)
10913 local dir=$(dirname $(facet_vdevice $facet))
10914 local pool=$(zpool_name $facet)
10915 local lfsname=$(zfs_local_fsname $facet)
10916 local label=${FSNAME}-${role}$(printf '%04x' $idx)
10919 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
10925 do_facet mgs "rm -f $LSNAPSHOT_CONF"
10926 echo "Generating $LSNAPSHOT_CONF on MGS ..."
10928 if ! combined_mgs_mds ; then
10929 [ $(facet_fstype mgs) != zfs ] &&
10930 skip "Lustre snapshot 1 only works for ZFS backend"
10932 local host=$(facet_active_host mgs)
10933 local dir=$(dirname $(facet_vdevice mgs))
10934 local pool=$(zpool_name mgs)
10935 local lfsname=$(zfs_local_fsname mgs)
10938 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
10939 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
10942 for num in `seq $MDSCOUNT`; do
10943 [ $(facet_fstype mds$num) != zfs ] &&
10944 skip "Lustre snapshot 1 only works for ZFS backend"
10946 lss_gen_conf_one mds$num MDT $((num - 1)) ||
10947 lss_err "generate lss conf (mds$num)"
10950 for num in `seq $OSTCOUNT`; do
10951 [ $(facet_fstype ost$num) != zfs ] &&
10952 skip "Lustre snapshot 1 only works for ZFS backend"
10954 lss_gen_conf_one ost$num OST $((num - 1)) ||
10955 lss_err "generate lss conf (ost$num)"
10958 do_facet mgs "cat $LSNAPSHOT_CONF"
10961 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
10962 parse_plain_dir_param()
10964 local invalues=($1)
10967 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
10968 (( ${invalues[1]} == $OSTCOUNT - 1 )) &&
10969 param="-c $OSTCOUNT" || param="-c ${invalues[1]}"
10971 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
10972 param="$param -S ${invalues[3]}"
10974 if [[ ${invalues[4]} =~ "pattern:" ]]; then
10975 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
10976 param="$param -i ${invalues[6]}"
10978 param="$param -L ${invalues[5]} -i ${invalues[7]}"
10980 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
10981 param="$param -i ${invalues[5]}"
10986 parse_plain_param()
10989 local val=$(awk '{print $2}' <<< $line)
10991 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
10992 (( $val == $OSTCOUNT - 1 )) &&
10993 param="-c $OSTCOUNT" || param="-c $val"
10995 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
10997 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
10999 elif [[ $line =~ ^"lmm_pattern:" ]]; then
11007 local val=$(awk '{print $2}' <<< $line)
11009 if [[ $line =~ ^"lmv_stripe_count:" ]]; then
11011 elif [[ $line =~ ^"lmv_stripe_offset:" ]]; then
11013 elif [[ $line =~ ^"lmv_hash_type:" ]]; then
11015 elif [[ $line =~ ^"lmv_max_inherit:" ]]; then
11020 parse_layout_param()
11026 while read line; do
11027 if [[ ! -z $line ]]; then
11028 if [[ -z $mode ]]; then
11029 if [[ $line =~ ^"stripe_count:" ]]; then
11031 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
11033 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
11035 elif [[ $line =~ ^"lmv_stripe_count" ]]; then
11040 if [[ $mode = "plain_dir" ]]; then
11041 param=$(parse_plain_dir_param "$line")
11042 elif [[ $mode = "plain_file" ]]; then
11043 val=$(parse_plain_param "$line")
11044 [[ ! -z $val ]] && param="$param $val"
11045 elif [[ $mode = "pfl" ]]; then
11046 val=$(echo $line | awk '{print $2}')
11047 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
11048 if [[ $val = "EOF" ]]; then
11049 param="$param -E -1"
11051 param="$param -E $val"
11053 elif [[ $line =~ ^"stripe_count:" ]]; then
11055 val=$(parse_plain_dir_param "$line")
11056 param="$param $val"
11059 val=$(parse_plain_param "$line")
11060 [[ ! -z $val ]] && param="$param $val"
11062 elif [[ $mode = "dne" ]]; then
11063 val=$(parse_dir_param "$line")
11064 [[ ! -z $val ]] && param="$param $val"
11073 local param=$($LFS getstripe -dy $1 | parse_layout_param)
11077 get_dir_layout_param()
11079 local param=$($LFS getdirstripe -y $1 | parse_layout_param)
11083 lfsck_verify_pfid()
11088 # Cancel locks before setting lfsck_verify_pfid so that errors are more
11090 cancel_lru_locks mdc
11091 cancel_lru_locks osc
11093 # make sure PFID is set correctly for files
11094 do_nodes $(osts_nodes) \
11095 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
11098 cat $f &> /dev/nullA ||
11099 { rc=$?; echo "verify $f failed"; break; }
11102 do_nodes $(osts_nodes) \
11103 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
11107 # check that clients "oscs" was evicted after "before"
11108 check_clients_evicted() {
11115 for osc in $oscs; do
11116 echo "Check state for $osc"
11117 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
11118 tail -n 5 | awk -F"[ ,]" \
11119 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
11120 if (($? == 0)) && (($evicted > $before)); then
11121 echo "$osc is evicted at $evicted"
11124 echo "$osc was not evicted after $before:"
11125 do_facet client $LCTL get_param osc.$osc.state |
11130 [ $rc -eq 0 ] || error "client not evicted from OST"
11133 # check that clients OSCS current_state is FULL
11134 check_clients_full() {
11139 for osc in $oscs; do
11140 wait_update_facet client \
11141 "lctl get_param -n osc.$osc.state |
11142 grep 'current_state: FULL'" \
11143 "current_state: FULL" $timeout
11144 [ $? -eq 0 ] || error "$osc state is not FULL"
11149 __changelog_deregister() {
11151 local mdt="$(facet_svc $facet)"
11155 if (( $MDS1_VERSION >= $(version_code 2.16.50) )); then
11156 changelog_deregister="changelog deregister"
11158 changelog_deregister="changelog_deregister"
11160 # skip cleanup if no user registered for this MDT
11161 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
11162 # user is no longer registered, skip cleanup
11163 changelog_users "$facet" | grep -q "$cl_user" ||
11164 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
11166 # From this point, if any operation fails, it is an error
11167 __changelog_clear $facet $cl_user 0 ||
11168 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
11169 do_facet $facet $LCTL --device $mdt $changelog_deregister $cl_user ||
11170 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
11173 declare -Ax CL_USERS
11174 changelog_register() {
11175 if (( $MDS1_VERSION >= $(version_code 2.16.50) )); then
11176 changelog_register="changelog register"
11178 changelog_register="changelog_register"
11180 for M in $(seq $MDSCOUNT); do
11182 local mdt="$(facet_svc $facet)"
11185 cl_mask=$(do_facet $facet $LCTL get_param \
11186 mdd.${mdt}.changelog_mask -n)
11187 stack_trap "do_facet $facet $LCTL \
11188 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
11189 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
11190 error "$mdt: changelog_mask=+hsm failed: $?"
11193 cl_user=$(do_facet $facet $LCTL --device $mdt \
11194 $changelog_register -n "$@") ||
11195 error "$mdt: register changelog user failed: $?"
11196 stack_trap "__changelog_deregister $facet $cl_user" EXIT
11198 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
11199 # Bash does not support nested arrays, but the format of a
11200 # cl_user is constrained enough to use whitespaces as separators
11201 CL_USERS[$facet]+="$cl_user "
11203 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[*]% }'"
11206 changelog_deregister() {
11208 # bash assoc arrays do not guarantee to list keys in created order
11209 # so reorder to get same order than in changelog_register()
11210 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
11213 for facet in $cl_facets; do
11214 for cl_user in ${CL_USERS[$facet]}; do
11215 __changelog_deregister $facet $cl_user || return $?
11217 unset CL_USERS[$facet]
11221 changelog_users() {
11223 local service=$(facet_svc $facet)
11225 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
11228 changelog_user_rec() {
11231 local service=$(facet_svc $facet)
11233 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
11236 changelog_chmask() {
11239 do_nodes $(mdts_nodes) $LCTL set_param mdd.*.changelog_mask="$mask"
11242 # usage: __changelog_clear FACET CL_USER [+]INDEX
11243 __changelog_clear()
11246 local mdt="$(facet_svc $facet)"
11252 # Remove the leading '+'
11254 rec+=$(changelog_user_rec $facet $cl_user)
11261 if [ $rec -eq 0 ]; then
11262 echo "$mdt: clear the changelog for $cl_user of all records"
11264 echo "$mdt: clear the changelog for $cl_user to record #$rec"
11266 $LFS changelog_clear $mdt $cl_user $rec
11269 # usage: changelog_clear [+]INDEX [facet]...
11271 # If INDEX is prefixed with '+', increment every changelog user's record index
11272 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
11274 changelog_clear() {
11278 local cl_facets="$@"
11279 # bash assoc arrays do not guarantee to list keys in created order
11280 # so reorder to get same order than in changelog_register()
11281 [[ -n "$cl_facets" ]] ||
11282 cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
11286 for facet in $cl_facets; do
11287 for cl_user in ${CL_USERS[$facet]}; do
11288 __changelog_clear $facet $cl_user $idx || rc=${rc:-$?}
11298 for M in $(seq $MDSCOUNT); do
11300 local mdt="$(facet_svc $facet)"
11304 output=$($LFS changelog $mdt)
11306 if [ $ret -ne 0 ]; then
11308 elif [ -n "$output" ]; then
11309 echo "$output" | sed -e 's/^/'$mdt'./'
11316 changelog_extract_field() {
11319 local identifier=$3
11321 changelog_dump | gawk "/$cltype.*$file$/ {
11322 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11326 # Prints a changelog record produced by "lfs changelog" as an associative array
11329 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
11330 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
11331 # nid=0@lo p=[0x200000007:0x1:0x0] blob
11332 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
11333 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
11334 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
11335 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
11337 # Note that the changelog record is not quoted
11338 # Also note that the line breaks in the output were only added for readability
11340 # Typically, you want to eval the output of the command to fill an actual
11341 # associative array, like this:
11342 # $> eval declare -A changelog=$(changelog2array $entry)
11344 # It can then be accessed like any bash associative array:
11345 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
11347 # $> echo "${changelog[uid]}":"${changelog[gid]}"
11355 # A changelog, as printed by "lfs changelog" typically looks like this:
11356 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
11358 # Parse the positional part of the changelog
11360 # changelog_dump() prefixes records with their mdt's name
11361 local index="${1##*.}"
11363 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
11364 "$index" "${2:2}" "$3" "$4" "$5"
11366 # Parse the key/value part of the changelog
11367 for arg in "${@:5}"; do
11368 # Check it matches a key=value syntax
11369 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
11371 local key="${arg%%=*}"
11372 local value="${arg#*=}"
11376 # u is actually for uid AND gid: u=UID:GID
11377 printf " [uid]='%s'" "${value%:*}"
11379 value="${value#*:}"
11412 printf " ['%s']='%s'" "$key" "$value"
11419 # Format and print a changelog record
11421 # Interpreted sequences are:
11423 # %f the "flags" attribute of a changelog record
11424 __changelog_printf()
11429 for ((i = 0; i < ${#format}; i++)); do
11430 local char="${format:$i:1}"
11431 if [ "$char" != % ]; then
11432 printf '%c' "$char"
11437 char="${format:$i:1}"
11440 printf '%s' "${changelog[flags]}"
11450 # Filter changelog records
11454 local action='print'
11457 while [ $# -gt 0 ]; do
11468 filter[${1#-}]="$2"
11477 changelog_dump | { while read -r record; do
11478 eval local -A changelog=$(changelog2array $record)
11479 for key in "${!filter[@]}"; do
11482 [ "${changelog[$key]}" == "${filter[$key]}" ]
11489 case "${action:-print}" in
11491 printf '%s\n' "$record"
11494 __changelog_printf "$format"
11504 [ ! -d "$dir" ] && return
11506 [ -z "$layout" ] && {
11507 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
11511 setfattr -n trusted.lov -v $layout $dir ||
11512 error "error restoring layout '$layout' to '$dir'"
11515 # save the layout of a directory, the returned string will be used by
11516 # restore_layout() to restore the layout
11519 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
11520 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
11524 # save layout of a directory and restore it at exit
11525 save_layout_restore_at_exit() {
11527 local layout=$(save_layout $dir)
11529 stack_trap "restore_layout $dir $layout" EXIT
11532 init_stripe_dir_params() {
11534 local varstriped=$2
11536 if ((MDSCOUNT > 1 &&
11538 $(version_code 2.8.0))); then
11539 eval $varremote=${!varremote:-true}
11540 eval $varstriped=${!varstriped:-true}
11541 elif ((MDSCOUNT > 1 &&
11543 $(version_code 2.5.0))); then
11544 eval $varremote=${!varremote:-true}
11545 eval $varstriped=${!varstriped:-false}
11548 eval $varremote=${!varremote:-false}
11549 eval $varstriped=${!varstriped:-false}
11552 verify_yaml_layout() {
11556 local msg_prefix=$4
11558 echo "$msg_prefix: getstripe --yaml $src"
11559 $LFS getstripe --yaml $src > $temp ||
11560 error "$msg_prefix: getstripe $src failed"
11561 echo "$msg_prefix: setstripe --yaml=$temp $dst"
11562 $LFS setstripe --yaml=$temp $dst || {
11565 sed -e "s/^/$msg_prefix-yaml: /" $temp
11566 getfattr -d -m - -e hex $src
11567 getfattr -d -m - -e hex $dst
11568 error "$msg_prefix: setstripe '$dst' failed"
11571 echo "$msg_prefix: compare"
11572 local layout_src=$(get_layout_param $src)
11573 local layout_dst=$(get_layout_param $dst)
11574 # compare their layout info
11575 [ "$layout_src" == "$layout_dst" ] || {
11576 sed -e "s/^/$msg_prefix-src: /" <<< $layout_src
11577 sed -e "s/^/$msg_prefix-dst: /" <<< $layout_dst
11578 error "$msg_prefix: $src/$dst layouts are not equal"
11582 is_project_quota_supported() {
11583 $ENABLE_PROJECT_QUOTAS || return 1
11584 [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
11585 local save_project_supported=1
11587 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
11588 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
11589 do_facet mds1 lfs --list-commands |& grep -q project &&
11590 save_project_supported=0
11592 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
11593 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
11594 do_facet mds1 $ZPOOL get all | grep -q project_quota &&
11595 save_project_supported=0
11597 # cache state of project quotas once instead of re-checking each time
11598 export SAVE_PROJECT_SUPPORTED=$save_project_supported
11599 echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
11601 return $save_project_supported
11604 # ZFS project quota enable/disable:
11605 # This feature will become active as soon as it is enabled and will never
11606 # return to being disabled. Each filesystem will be upgraded automatically
11607 # when remounted or when [a] new file is created under that filesystem. The
11608 # upgrade can also be triggered on filesystems via `zfs set version=current
11609 # <pool/fs>`. The upgrade process runs in the background and may take a
11610 # while to complete for the filesystems containing a large number of files.
11611 enable_project_quota() {
11612 is_project_quota_supported || return 0
11613 local zkeeper=${KEEP_ZPOOL}
11614 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
11616 stopall || error "failed to stopall (1)"
11618 local zfeat_en="feature@project_quota=enabled"
11619 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
11620 local facet_fstype=${facet:0:3}1_FSTYPE
11623 if [ "${!facet_fstype}" = "zfs" ]; then
11624 devname=$(zpool_name ${facet})
11625 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
11626 error "$ZPOOL set $zfeat_en $devname"
11628 [ ${facet:0:3} == "mds" ] &&
11629 devname=$(mdsdevname ${facet:3}) ||
11630 devname=$(ostdevname ${facet:3})
11631 do_facet ${facet} $TUNE2FS -O project $devname ||
11632 error "tune2fs $devname failed"
11636 KEEP_ZPOOL="${zkeeper}"
11641 disable_project_quota() {
11642 is_project_quota_supported || return 0
11643 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
11644 stopall || error "failed to stopall (1)"
11646 for num in $(seq $MDSCOUNT); do
11647 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
11648 error "tune2fs $(mdsdevname $num) failed"
11651 for num in $(seq $OSTCOUNT); do
11652 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
11653 error "tune2fs $(ostdevname $num) failed"
11661 echo "$LFS project $*"
11662 $LFS project $* || error "$LFS project $* failed"
11665 # get quota for a user or a group
11666 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
11667 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
11677 sync_all_data > /dev/null 2>&1 || true
11679 [[ "$#" != 4 && "$#" != 5 ]] &&
11680 error "getquota: wrong number of arguments: $#"
11681 [[ "$type" != "-u" && "$type" != "-g" && "$type" != "-p" ]] &&
11682 error "getquota: wrong u/g/p specifier $1 passed"
11684 [[ "$spec" =~ "curspace" ]] && spec="space"
11685 [[ "$spec" =~ "curinode" ]] && spec="inodes"
11686 [[ ! -z "$pool" ]] && pool_arg="--pool $pool "
11687 [[ "$3" =~ "OST" ]] && uuid="--ost $(echo "$3" | tail -c 4) "
11688 [[ "$3" =~ "MDT" ]] && uuid="--mdt $(echo "$3" | tail -c 4) "
11690 echo -n "$type $id $uuid $spec:" 1>&2
11691 $LFS quota -q $uuid --$spec "$type" "$id" $pool_arg$DIR | tr -d "*" 1>&2
11692 $LFS quota -q $uuid --$spec "$type" "$id" $pool_arg$DIR | tr -d "*"
11695 # set mdt quota type
11696 # usage: set_mdt_qtype ugp|u|g|p|none
11700 local mdts=$(get_facets MDS)
11702 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
11703 qtype=$(tr -d 'p' <<<$qtype)
11705 if [[ $PERM_CMD == *"set_param -P"* ]]; then
11706 do_facet mgs $PERM_CMD \
11707 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
11709 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
11711 # we have to make sure each MDT received config changes
11712 for mdt in ${mdts//,/ }; do
11714 cmd="$LCTL get_param -n "
11715 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
11716 cmd=${cmd}.quota_slave.enabled
11718 if $(facet_up $mdt); then
11719 wait_update_facet $mdt "$cmd" "$qtype" || return 1
11725 # set ost quota type
11726 # usage: set_ost_qtype ugp|u|g|p|none
11730 local osts=$(get_facets OST)
11732 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
11733 qtype=$(tr -d 'p' <<<$qtype)
11735 if [[ $PERM_CMD == *"set_param -P"* ]]; then
11736 do_facet mgs $PERM_CMD \
11737 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
11739 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
11741 # we have to make sure each OST received config changes
11742 for ost in ${osts//,/ }; do
11744 cmd="$LCTL get_param -n "
11745 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
11746 cmd=${cmd}.quota_slave.enabled
11748 if $(facet_up $ost); then
11749 wait_update_facet $ost "$cmd" "$qtype" || return 1
11756 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
11757 # the following associated variables are added:
11759 # AGTCOUNT: number of agents
11760 # AGTDEV{N}: target HSM mount point (root path of the backend)
11761 # agt{N}_HOST: hostname of the agent agt{N}
11762 # SINGLEAGT: facet of the single agent
11764 # The number of agents is initialized as the number of remote client nodes.
11765 # By default, only single copytool is started on a remote client/agent. If there
11766 # was no remote client, then the copytool will be started on the local client.
11772 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
11773 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
11775 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
11776 if [[ $CLIENTCOUNT -gt 1 ]] &&
11777 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
11778 skip_env "SHARED_DIRECTORY should be accessible"\
11779 "on all client nodes"
11783 # We used to put the HSM archive in $SHARED_DIRECTORY but that
11784 # meant NFS issues could hose sanity-hsm sessions. So now we
11785 # use $TMP instead.
11786 for n in $(seq $AGTCOUNT); do
11787 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
11788 agent=CLIENT$((n + 1))
11789 if [[ -z "${!agent}" ]]; then
11790 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
11793 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
11794 local var=agt${n}_HOST
11795 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
11798 export SINGLEAGT=${SINGLEAGT:-agt1}
11800 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
11801 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
11802 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
11803 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
11804 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
11805 export HSMTOOL_TESTDIR
11806 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
11808 if ! [[ $HSMTOOL =~ hsmtool ]]; then
11809 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
11812 HSM_ARCHIVE_NUMBER=2
11814 # The test only support up to 10 MDTs
11815 MDT_PREFIX="mdt.$FSNAME-MDT000"
11816 HSM_PARAM="${MDT_PREFIX}0.hsm"
11818 # archive is purged at copytool setup
11819 HSM_ARCHIVE_PURGE=true
11821 # Don't allow copytool error upon start/setup
11822 HSMTOOL_NOERROR=false
11825 # Get the backend root path for the given agent facet.
11826 copytool_device() {
11828 local dev=AGTDEV$(facet_number $facet)
11833 get_mdt_devices() {
11835 # get MDT device for each mdc
11836 for mdtno in $(seq 1 $MDSCOUNT); do
11837 local idx=$(($mdtno - 1))
11838 MDT[$idx]=$($LCTL get_param -n \
11839 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
11840 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
11844 pkill_copytools() {
11848 do_nodes "$hosts" \
11849 "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
11852 copytool_continue() {
11853 local agents=${1:-$(facet_active_host $SINGLEAGT)}
11855 pkill_copytools "$agents" CONT || return 0
11856 echo "Copytool is continued on $agents"
11860 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
11862 echo "Killing existing copytools on $hosts"
11863 pkill_copytools "$hosts" TERM || return 0
11864 copytool_continue "$hosts"
11867 copytool_monitor_cleanup() {
11868 local facet=${1:-$SINGLEAGT}
11869 local agent=$(facet_active_host $facet)
11871 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
11872 # Should die when the copytool dies, but just in case.
11873 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
11874 cmd+=" 2>/dev/null || true"
11875 do_node $agent "$cmd"
11876 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
11877 export HSMTOOL_MONITOR_DIR=
11880 # The pdsh should die on its own when the monitor dies. Just
11881 # in case, though, try to clean up to avoid any cruft.
11882 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
11883 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
11884 export HSMTOOL_MONITOR_PDSH=
11890 local host="$(facet_host "$1")"
11891 local prefix=$TESTLOG_PREFIX
11892 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
11894 printf "${prefix}.copytool${archive_id}_log.${host}.log"
11897 __lhsmtool_rebind()
11899 do_facet $facet $HSMTOOL \
11900 "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
11903 __lhsmtool_import()
11905 mkdir -p "$(dirname "$2")" ||
11906 error "cannot create directory '$(dirname "$2")'"
11907 do_facet $facet $HSMTOOL \
11908 "${hsmtool_options[@]}" --import "$@" "$mountpoint"
11913 local host="$(facet_host "$facet")"
11914 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
11916 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
11917 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
11918 # [ ${#misc_options[@]} -gt 0 ] &&
11919 # cmd+=" $(IFS=" " echo "$@")"
11920 cmd+=" $@ \"$mountpoint\""
11922 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
11923 stack_trap "pkill_copytools $host TERM || true" EXIT
11924 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
11928 local facet="${1:-$SINGLEAGT}"
11930 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
11933 # Main entry point to perform copytool related operations
11937 # setup setup a copytool to run in the background, that copytool will be
11939 # import import a file from an HSM backend
11940 # rebind rebind an archived file to a new fid
11942 # Although the semantics might suggest otherwise, one does not need to 'setup'
11943 # a copytool before a call to 'copytool import' or 'copytool rebind'.
11950 # Use default values
11951 local facet=$SINGLEAGT
11952 local mountpoint="${MOUNT2:-$MOUNT}"
11955 local fail_on_error=true
11956 local -a hsmtool_options=()
11957 local -a action_options=()
11959 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
11960 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
11963 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
11964 hsmtool_options+=("$HSMTOOL_VERBOSE")
11967 while [ $# -gt 0 ]; do
11979 local archive_id="$1"
11983 local hsm_root="$1"
11987 local bandwidth="$1" # in MB/s
11990 local fail_on_error=false
11993 # Uncommon(/copytool dependent) option
11994 action_options+=("$1")
12000 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
12001 hsmtool_options+=("--hsm-root=$hsm_root")
12003 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
12004 do_facet $facet mkdir -p "$hsm_root" ||
12005 error "mkdir '$hsm_root' failed"
12009 local copytool=lhsmtool
12013 __${copytool}_${action} "${action_options[@]}"
12014 if [ $? -ne 0 ]; then
12019 local host="$(facet_host $facet)"
12020 error_msg="Failed to start copytool $facet on '$host'"
12023 local src="${action_options[0]}"
12024 local dest="${action_options[1]}"
12025 error_msg="Failed to import '$src' to '$dest'"
12028 error_msg="could not rebind file"
12032 $fail_on_error && error "$error_msg" || echo "$error_msg"
12037 local client_count=$1
12038 if [[ $CLIENTCOUNT -lt $client_count ]]; then
12039 skip "Need $client_count or more clients, have $CLIENTCOUNT"
12046 $LFS path2fid $1 | tr -d '[]'
12047 return ${PIPESTATUS[0]}
12055 if [[ $u == "user" ]]; then
12056 st=$($RUNAS $LFS hsm_state $f)
12059 st=$($LFS hsm_state $f)
12062 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
12064 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
12068 check_hsm_flags() {
12072 local st=$(get_hsm_flags $f)
12073 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
12082 if [[ "$value" != "" ]]; then
12085 for mdtno in $(seq 1 $MDSCOUNT); do
12086 local idx=$(($mdtno - 1))
12087 local facet=mds${mdtno}
12088 # if $arg include -P option, run 1 set_param per MDT on the MGS
12089 # else, run set_param on each MDT
12090 [[ $arg = *"-P"* ]] && facet=mgs
12091 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value ||
12097 mdts_check_param() {
12103 for mdtno in $(seq 1 $MDSCOUNT); do
12104 local idx=$(($mdtno - 1))
12105 wait_update_facet --verbose mds${mdtno} \
12106 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
12108 error "$key state is not '$target' on mds${mdtno}"
12112 cdt_set_mount_state() {
12113 mdts_set_param "-P" hsm_control "$1"
12114 # set_param -P is asynchronous operation and could race with set_param.
12115 # In such case configs could be retrieved and applied at mgc after
12116 # set_param -P completion. Sleep here to avoid race with set_param.
12117 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
12118 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
12119 # and 10 seconds to retrieve config from server.
12123 cdt_check_state() {
12124 mdts_check_param hsm_control "$1" 20
12127 cdt_set_sanity_policy() {
12128 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
12131 mdts_set_param "" hsm.policy "+NRA"
12132 mdts_set_param "" hsm.policy "-NBR"
12133 CDT_POLICY_HAD_CHANGED=
12141 mdts_set_param "$opt -n" "hsm.$param" "$value"
12145 wait_request_state() {
12149 # 4th arg (mdt index) is optional
12150 local mdtidx=${4:-0}
12151 local mds=mds$(($mdtidx + 1))
12153 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
12154 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
12156 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
12157 error "request on $fid is not $state on $mds"
12165 local WAIT_MAX=${4:-60}
12168 # We need to run do_node in bg, because pdsh does not exit
12169 # if child process of run script exists.
12170 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
12171 # because of multiop_bg_pause -> $MULTIOP_PROG &
12172 # By the same reason we need sleep a bit after do_nodes starts
12173 # to let runmultiop_bg_pause start muliop and
12174 # update /tmp/multiop_bg.pid ;
12175 # The rm /tmp/multiop_bg.pid guarantees here that
12176 # we have the updated by runmultiop_bg_pause
12177 # /tmp/multiop_bg.pid file
12179 local pid_file=$TMP/multiop_bg.pid.$$
12181 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
12182 runmultiop_bg_pause $file $cmds" &
12186 while [[ $wait_time -lt $WAIT_MAX ]]; do
12188 wait_time=$((wait_time + 3))
12189 multiop_pid=$(do_node $client cat $pid_file)
12190 if [ -n "$multiop_pid" ]; then
12195 [ -n "$multiop_pid" ] ||
12196 error "$client : Can not get multiop_pid from $pid_file "
12198 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
12199 eval export $(node_var_name $client)_do_node_pid=$pid
12200 local var=$(node_var_name $client)_multiop_pid
12201 echo client $client multiop_bg started multiop_pid=${!var}
12207 local multiop_pid=$(node_var_name $client)_multiop_pid
12208 local do_node_pid=$(node_var_name $client)_do_node_pid
12210 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
12211 do_node $client kill -USR1 ${!multiop_pid}
12213 wait ${!do_node_pid}
12217 local delay=$(do_facet mds1 lctl get_param -n lod.*.qos_maxage |
12218 awk '{ print $1 + 5; exit; }')
12222 sleep_maxage_lmv() {
12223 local delay=$(lctl get_param -n lmv.*.qos_maxage |
12224 awk '{ print $1 + 5; exit; }')
12228 check_component_count() {
12229 local comp_cnt=$($LFS getstripe --component-count $1)
12230 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
12233 # Verify there are no init components with "extension" flag
12234 verify_no_init_extension() {
12235 local flg_opts="--component-flags init,extension"
12236 local found=$($LFS find $flg_opts $1 | wc -l)
12237 [ $found -eq 0 ] || error "$1 has component with initialized extension"
12240 # Verify there is at least one component starting at 0
12241 verify_comp_at_zero() {
12242 flg_opts="--component-flags init"
12243 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
12244 [ $found -eq 1 ] ||
12245 error "No component starting at zero(!)"
12248 # version after which Self-Extending Layouts are available
12251 sel_layout_sanity() {
12255 verify_no_init_extension $file
12256 verify_comp_at_zero $file
12257 check_component_count $file $comp_cnt
12260 statx_supported() {
12261 $STATX --quiet --version
12265 # lfs rm_entry is disabled on native client
12266 is_rmentry_supported() {
12267 $LFS rm_entry $DIR/dir/not/exists > /dev/null
12268 # is return code ENOENT?
12273 # wrappers for createmany and unlinkmany
12274 # to set debug=0 if number of creates is high enough
12275 # this is to speedup testing
12277 function createmany() {
12281 if (( count > 100 )); then
12283 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=ha
12285 $LUSTRE/tests/createmany $*
12287 debugrestore > /dev/null
12292 function unlinkmany() {
12296 if (( count > 100 )); then
12298 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
12300 $LUSTRE/tests/unlinkmany $*
12302 debugrestore > /dev/null
12307 # Check if fallocate on facet is working. Returns fallocate mode if enabled.
12308 # Takes optional facet name as argument, to allow separate MDS/OSS checks.
12309 function check_fallocate_supported()
12311 local facet=${1:-ost1}
12312 local supported="FALLOCATE_SUPPORTED_$facet"
12313 local fstype="${facet}_FSTYPE"
12315 if [[ -n "${!supported}" ]]; then
12316 echo "${!supported}"
12319 if [[ -z "${!fstype}" ]]; then
12320 eval export $fstype=$(facet_fstype $facet)
12322 if [[ "${!fstype}" != "ldiskfs" ]]; then
12323 echo "fallocate on ${!fstype} doesn't consume space" 1>&2
12327 local fa_mode="osd-ldiskfs.$(facet_svc $facet).fallocate_zero_blocks"
12328 local mode=$(do_facet $facet $LCTL get_param -n $fa_mode 2>/dev/null |
12330 ! [[ "$facet" =~ "mds" ]] || # older MDS doesn't support fallocate
12331 (( MDS1_VERSION >= $(version_code v2_14_53-10-g163870abfb) )) ||
12334 if [[ -z "$mode" ]]; then
12335 echo "fallocate not supported on $facet" 1>&2
12338 eval export $supported="$mode"
12344 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable.
12345 # Takes optional facet name as argument.
12346 function check_fallocate_or_skip()
12350 check_fallocate_supported $1 || skip "fallocate not supported"
12353 # Check if fallocate supported on OSTs, enable if unset, default mode=0
12354 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
12355 function check_set_fallocate()
12357 local new_mode="$1"
12358 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
12359 local old_mode="$(check_fallocate_supported)"
12361 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
12362 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
12363 { echo "keep default fallocate mode: $old_mode"; return 0; }
12364 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
12365 { echo "keep current fallocate mode: $old_mode"; return 0; }
12366 local osts=$(osts_nodes)
12368 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
12369 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
12370 error "set $fa_mode=$new_mode"
12373 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
12374 function check_set_fallocate_or_skip()
12376 check_set_fallocate || skip "need >= 2.13.57 and ldiskfs for fallocate"
12379 function disable_opencache()
12381 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" |
12384 test -z "${saved_OPENCACHE_value}" &&
12385 export saved_OPENCACHE_value="$state"
12387 [[ "$state" = "off" ]] && return
12389 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
12392 function set_opencache()
12394 local newvalue="$1"
12395 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
12397 [[ -n "$newvalue" ]] || return
12399 [[ -n "${saved_OPENCACHE_value}" ]] ||
12400 export saved_OPENCACHE_value="$state"
12402 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
12407 function restore_opencache()
12409 [[ -z "${saved_OPENCACHE_value}" ]] ||
12410 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
12413 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
12414 # created on MDT0, use this function to create directory on specific MDT
12415 # explicitly, and set default LMV to create subdirs on the same MDT too.
12420 while getopts "i:" opt $*; do
12426 shift $((OPTIND - 1))
12428 $LFS mkdir -i $mdt -c 1 $*
12432 mkdir_on_mdt -i0 $*
12435 # Wait for nodemap synchronization
12437 local nodemap_name=$1
12442 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
12443 local max_retries=20
12447 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
12450 if [ "$nodemap_name" == "active" ]; then
12451 proc_param="active"
12452 elif [ -z "$key" ]; then
12453 proc_param=${nodemap_name}
12455 proc_param="${nodemap_name}.${key}"
12457 if [ "$opt" == "inactive" ]; then
12458 # check nm sync even if nodemap is not activated
12462 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
12464 if [ -z "$value" ]; then
12465 out1=$(do_facet mgs $LCTL get_param $opt \
12466 nodemap.${proc_param} 2>/dev/null)
12467 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
12472 # if servers run on the same node, it is impossible to tell if they get
12473 # synced with the mgs, so just wait an arbitrary 10 seconds
12474 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
12475 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
12476 echo "waiting 10 secs for sync"
12481 # wait up to 10 seconds for other servers to sync with mgs
12482 for i in $(seq 1 10); do
12483 for node in $(all_server_nodes); do
12484 local node_ip=$(host_nids_address $node $NETTYPE |
12488 if [ -z "$value" ]; then
12489 [ $node_ip == $mgs_ip ] && continue
12492 out2=$(do_node $node $LCTL get_param $opt \
12493 nodemap.$proc_param 2>/dev/null)
12494 echo "On $node ${node_ip}, ${proc_param} = $out2"
12495 [ "$out1" != "$out2" ] && is_sync=false && break
12500 if ! $is_sync; then
12503 echo OTHER - IP: $node_ip
12505 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
12507 echo "waited $((i - 1)) seconds for sync"
12510 consume_precreations() {
12514 local extra=${4:-2}
12515 local OST=$(ostname_from_index $OSTIDX $dir)
12517 mkdir_on_mdt -i $(facet_index $mfacet) $dir/${OST}
12518 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
12521 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
12522 local last_id=$(do_facet $mfacet $LCTL get_param -n \
12523 osp.$mdtosc_proc.prealloc_last_id)
12524 local next_id=$(do_facet $mfacet $LCTL get_param -n \
12525 osp.$mdtosc_proc.prealloc_next_id)
12526 echo "Creating to objid $last_id on ost $OST..."
12527 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
12530 __exhaust_precreations() {
12533 local FAILIDX=${3:-$OSTIDX}
12534 local ofacet=ost$((OSTIDX + 1))
12536 mkdir_on_mdt0 $DIR/$tdir
12537 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
12538 local mfacet=mds$((mdtidx + 1))
12539 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
12541 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
12542 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
12544 #define OBD_FAIL_OST_ENOSPC 0x215
12545 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
12547 consume_precreations $DIR/$tdir $mfacet $OSTIDX
12549 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
12550 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
12553 exhaust_precreations() {
12554 __exhaust_precreations $1 $2 $3
12558 exhaust_all_precreations() {
12560 for (( i=0; i < OSTCOUNT; i++ )) ; do
12561 __exhaust_precreations $i $1 -1
12566 force_new_seq_ost() {
12570 local OST=$(ostname_from_index $OSTIDX)
12571 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
12573 do_facet $mfacet $LCTL set_param \
12574 osp.$mdtosc_proc.prealloc_force_new_seq=1
12575 # consume preallocated objects, to wake up precreate thread
12576 consume_precreations $dir $mfacet $OSTIDX
12577 do_facet $mfacet $LCTL set_param \
12578 osp.$mdtosc_proc.prealloc_force_new_seq=0
12583 local MDTIDX=$(facet_index $mfacet)
12584 local MDT=$(mdtname_from_index $MDTIDX $DIR)
12587 mkdir_on_mdt -i $MDTIDX $DIR/${MDT}
12588 for (( i=0; i < OSTCOUNT; i++ )) ; do
12589 force_new_seq_ost $DIR/${MDT} $mfacet $i &
12595 force_new_seq_all() {
12598 for (( i=0; i < MDSCOUNT; i++ )) ; do
12599 force_new_seq mds$((i + 1)) &
12605 ost_set_temp_seq_width_all() {
12606 local osts=$(osts_nodes)
12607 local width=$(do_facet ost1 $LCTL get_param -n seq.*OST0000-super.width)
12609 (( $width != $1 )) || return 0
12611 do_nodes $osts $LCTL set_param seq.*OST*-super.width=$1
12612 stack_trap "do_nodes $osts $LCTL set_param seq.*OST*-super.width=$width"
12615 verify_yaml_available() {
12616 python3 -c "import yaml; yaml.safe_load('''a: b''')"
12620 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"
12623 verify_compare_yaml() {
12624 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)"
12627 zfs_or_rotational() {
12629 local ost_name=$(ostname_from_index $ost_idx $MOUNT)
12630 local param="get_param -n osd-*.${ost_name}.nonrotational"
12631 local nonrotat=$(do_facet ost1 $LCTL $param)
12633 if [[ -z "$nonrotat" ]]; then
12634 # At this point there is no point moving ahead.
12635 # Will stop here and dump all the info
12637 local ost_name=$(ostname_from_index $ost_idx)
12639 error "$LCTL $input_str"
12642 if [[ "$ost1_FSTYPE" == "zfs" ]] || (( "$nonrotat" == 0 )); then
12649 ost_fid2_objpath() {
12653 fid=$(echo $fid | tr -d '[]')
12655 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
12656 oidhex=$(echo $fid | awk -F ':' '{ print $2 }')
12658 if [ $seq == 0 ] || [ $(facet_fstype $facet) == zfs ]; then
12659 oid=$((16#${oidhex#0x}))
12664 echo "O/$seq/d$((oidhex%32))/$oid"
12669 log "check file $1"
12671 lmm_count=$($LFS getstripe -c $1)
12672 lmm_seq=$($LFS getstripe -v $1 | awk '/lmm_seq/ { print $2 }')
12673 lmm_oid=$($LFS getstripe -v $1 | awk '/lmm_object_id/ { print $2 }')
12675 local old_ifs="$IFS"
12677 fid=($($LFS path2fid $1))
12680 log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
12681 log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
12683 # compare lmm_seq and lu_fid->f_seq
12684 [ $lmm_seq = ${fid[1]} ] || error "SEQ mismatch"
12685 # compare lmm_object_id and lu_fid->oid
12686 [ $lmm_oid = ${fid[2]} ] || error "OID mismatch"
12688 # check the trusted.fid attribute of the OST objects of the file
12689 local have_obdidx=false
12691 $LFS getstripe $1 | while read obdidx oid hex seq; do
12692 # skip lines up to and including "obdidx"
12693 [ -z "$obdidx" ] && break
12694 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
12695 $have_obdidx || continue
12697 local ost=$((obdidx + 1))
12698 local dev=$(ostdevname $ost)
12700 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
12702 local obj_file=$(ost_fid2_objpath ost$ost "$seq:$hex:0")
12706 # Don't unmount/remount the OSTs if we don't need to do that.
12707 # LU-2577 changes filter_fid to be smaller, so debugfs needs
12708 # update too, until that use mount/ll_decode_filter_fid/mount.
12709 # Re-enable when debugfs will understand new filter_fid.
12711 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
12712 ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
12713 $dev 2>/dev/null" | grep "parent=")
12715 if [ -z "$ff" ]; then
12717 mount_fstype ost$ost
12718 ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
12719 $(facet_mntpt ost$ost)/$obj_file)
12720 unmount_fstype ost$ost
12721 start ost$ost $dev $OST_MOUNT_OPTS
12725 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
12727 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
12729 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
12730 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
12732 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
12733 # stripe_size=1048576 component_id=1 component_start=0 \
12734 # component_end=33554432
12735 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
12736 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
12737 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
12739 if grep -q 'stripe=' <<<$ff; then
12740 ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
12742 # $LL_DECODE_FILTER_FID does not print "stripe="; look
12743 # into f_ver in this case. See comment on ff_parent.
12744 ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
12747 # compare lmm_seq and filter_fid->ff_parent.f_seq
12748 [ $ff_pseq = $lmm_seq ] ||
12749 error "FF parent SEQ $ff_pseq != $lmm_seq"
12750 # compare lmm_object_id and filter_fid->ff_parent.f_oid
12751 [ $ff_poid = $lmm_oid ] ||
12752 error "FF parent OID $ff_poid != $lmm_oid"
12753 (($ff_pstripe == $stripe_nr)) ||
12754 error "FF stripe $ff_pstripe != $stripe_nr"
12756 stripe_nr=$((stripe_nr + 1))
12757 [ $CLIENT_VERSION -lt $(version_code 2.9.55) ] &&
12759 if grep -q 'stripe_count=' <<<$ff; then
12760 local ff_scnt=$(sed -e 's/.*stripe_count=//' \
12761 -e 's/ .*//' <<<$ff)
12762 [ $lmm_count = $ff_scnt ] ||
12763 error "FF stripe count $lmm_count != $ff_scnt"