3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export SHARED_KEY=${SHARED_KEY:-false}
15 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
16 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
17 export SK_MOUNTED=${SK_MOUNTED:-false}
18 export SK_FLAVOR=${SK_FLAVOR:-ski}
19 export SK_NO_KEY=${SK_NO_KEY:-true}
20 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
21 export SK_S2S=${SK_S2S:-false}
22 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
23 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
24 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
25 # whether identity upcall is enabled (true), disabled (false), or default
26 export IDENTITY_UPCALL=${IDENTITY_UPCALL:-default}
28 export FLAKEY=${FLAKEY:-true}
29 # specify environment variable containing batch job name for server statistics
30 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
32 #export PDSH="pdsh -S -Rssh -w"
33 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
34 export UMOUNT=${UMOUNT:-"umount -d"}
36 export LSNAPSHOT_CONF="/etc/ldev.conf"
37 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
39 export DATA_SEQ_MAX_WIDTH=0x1ffffff
41 # sles12 umount has a issue with -d option
42 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
43 export UMOUNT="umount"
46 # function used by scripts run on remote nodes
47 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
48 . $LUSTRE/tests/functions.sh
49 . $LUSTRE/tests/yaml.sh
51 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
53 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
55 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
57 if [ -f "$EXCEPT_LIST_FILE" ]; then
58 echo "Reading test skip list from $EXCEPT_LIST_FILE"
63 # check config files for options in decreasing order of preference
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
65 MODPROBECONF=/etc/modprobe.d/lustre.conf
66 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
67 MODPROBECONF=/etc/modprobe.d/Lustre
68 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
69 MODPROBECONF=/etc/modprobe.conf
71 sanitize_parameters() {
72 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
76 if [ -d "$path" ]; then
77 eval export $i=$(echo $path | sed -r 's/\/+$//g')
83 [[ $DIR/ = $MOUNT/* ]] ||
84 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
85 [[ $DIR1/ = $MOUNT1/* ]] ||
86 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
87 [[ $DIR2/ = $MOUNT2/* ]] ||
88 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
90 [ -n "$failed" ] && exit 99 || true
94 echo "usage: $0 [-r] [-f cfgfile]"
102 [ -z "$DEFAULT_SUITES" ] && return 0
103 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
105 local form="%-13s %-17s %-9s %s %s\n"
107 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
108 echo "---------------------------------------------------------------"
109 for O in $DEFAULT_SUITES; do
110 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
111 [ "${!O}" = "no" ] && continue || true
112 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
113 local log=${TMP}/${o}.log
115 if is_sanity_benchmark $o; then
116 log=${TMP}/sanity-benchmark.log
121 local status=Unfinished
124 skipped=$(grep excluded $log |
125 awk '{ printf " %s", $3 }' | sed 's/test_//g')
126 slow=$(egrep "^PASS|^FAIL" $log |
127 tr -d "("| sed s/s\)$//g | sort -nr -k 3 |
128 head -n5 | awk '{ print $2":"$3"s" }')
129 total=$(grep duration $log | awk '{ print $2 }')
130 if [ "${!O}" = "done" ]; then
134 local durations=$(egrep "^PASS|^FAIL" $log |
135 tr -d "("| sed s/s\)$//g |
136 awk '{ print $2":"$3"|" }')
137 details=$(printf "%s\n%s %s %s\n" "$details" \
138 "DDETAILS" "$O" "$(echo $durations)")
141 printf "$form" $status "$O" "${total}" "E=$skipped"
142 printf "$form" "-" "-" "-" "S=$(echo $slow)"
145 for O in $DEFAULT_SUITES; do
146 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
147 if [ "${!O}" = "no" ]; then
148 printf "$form" "Skipped" "$O" ""
152 # print the detailed tests durations if DDETAILS=true
166 ! ${do_setup} && return
167 nfs_client_mode && return
170 local MOUNTED=$(mounted_lustre_filesystems)
172 if $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
173 check_config_clients $MOUNT
179 echo "Lustre is not mounted, trying to do setup ... "
180 $reformat && CLEANUP_DM_DEV=true formatall
183 MOUNTED=$(mounted_lustre_filesystems)
184 if ! $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
185 echo "Lustre is not mounted after setup! "
191 cleanup_if_needed() {
192 if $AUSTER_CLEANUP; then
197 find_script_in_path() {
200 for dir in $(tr : " " <<< $path); do
201 if [ -f $dir/$target ]; then
205 if [ -f $dir/$target.sh ]; then
214 log "-----============= acceptance-small: "$*" ============----- `date`"
219 printf "Would have run: %s\n" "$*"
223 printf "Running: %s\n" "$*"
231 local suite_script=$2
239 local start_ts=$(date +%s)
241 doit $script_lang $suite_script
244 local duration=$(($(date +%s) - $start_ts))
247 if [[ $rc -ne 0 || -f $TF_FAIL ]]; then
249 elif [[ -f $TF_SKIP ]]; then
252 log_test_status $duration $status
253 [[ ! -f $TF_SKIP ]] || rm -f $TF_SKIP
261 local suite_name=${1%.sh}
262 local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
264 suite_script=$(find_script_in_path $suite_name $LUSTRE/tests)
266 if [[ -z $suite_script ]]; then
267 echo "Can't find test script for $suite_name"
271 echo "run_suite $suite_name $suite_script"
273 local log_name=${suite_name}.suite_log.$(hostname -s).log
276 run_suite $suite_name $suite_script 2>&1 |tee $LOGDIR/$log_name
278 run_suite $suite_name $suite_script > $LOGDIR/$log_name 2>&1
281 return ${PIPESTATUS[0]}
299 while ((n < repeat_count)); do
301 local logdir=${test_logs_dir}
302 local first_suite=$FIRST_SUITE
304 ((repeat_count > 1)) && logdir="$logdir/$n"
305 reset_logging $logdir
307 while [[ -n $1 ]]; do
308 unset ONLY EXCEPT START_AT STOP_AT
314 while [[ -n $1 ]]; do
318 export ONLY=$(split_commas $1)
320 opts+="ONLY=$ONLY ";;
323 export SUITE=$(split_commas $1)
325 opts+="SUITE=$SUITE ";;
328 export PATTERN=$(split_commas $1)
330 opts+="PATTERN=$PATTERN ";;
333 export EXCEPT=$(split_commas $1)
335 opts+="EXCEPT=$EXCEPT ";;
340 opts+="START_AT=$START_AT ";;
345 opts+="STOP_AT=$STOP_AT ";;
355 # If first_suite not set or this is the first suite
356 if [ "x"$first_suite == "x" ] || [ $first_suite == $suite ]; then
357 echo "running: $suite $opts"
358 run_suite_logged $suite || RC=$?
360 echo $suite returned $RC
363 if $upload_logs; then
364 $upload_script $LOGDIR
370 # Get information about the Lustre environment. The information collected
371 # will be used in Lustre tests.
372 # usage: get_lustre_env
373 # input: No required or optional arguments
374 # output: No return values, environment variables are exported
378 export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
379 export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
381 export MGS_VERSION=$(lustre_version_code mgs)
382 export MDS1_VERSION=$(lustre_version_code mds1)
383 export OST1_VERSION=$(lustre_version_code ost1)
384 export CLIENT_VERSION=$(lustre_version_code client)
387 # Prefer using "mds1" directly instead of SINGLEMDS.
388 # Keep this for compat until it is removed from scripts.
389 export SINGLEMDS=${SINGLEMDS:-mds1}
393 export LUSTRE=$(absolute_path $LUSTRE)
394 export TESTSUITE=$(basename $0 .sh)
395 export TEST_FAILED=false
396 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
397 export RPC_MODE=${RPC_MODE:-false}
398 export DO_CLEANUP=${DO_CLEANUP:-true}
399 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
400 export CLEANUP_DM_DEV=false
401 export PAGE_SIZE=$(get_page_size client)
402 export NAME=${NAME:-local}
404 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
406 export MKE2FS=$MKE2FS
407 if [ -z "$MKE2FS" ]; then
408 if which mkfs.ldiskfs >/dev/null 2>&1; then
409 export MKE2FS=mkfs.ldiskfs
415 export DEBUGFS=$DEBUGFS
416 if [ -z "$DEBUGFS" ]; then
417 if which debugfs.ldiskfs >/dev/null 2>&1; then
418 export DEBUGFS=debugfs.ldiskfs
420 export DEBUGFS=debugfs
424 export TUNE2FS=$TUNE2FS
425 if [ -z "$TUNE2FS" ]; then
426 if which tunefs.ldiskfs >/dev/null 2>&1; then
427 export TUNE2FS=tunefs.ldiskfs
429 export TUNE2FS=tune2fs
433 export E2LABEL=$E2LABEL
434 if [ -z "$E2LABEL" ]; then
435 if which label.ldiskfs >/dev/null 2>&1; then
436 export E2LABEL=label.ldiskfs
438 export E2LABEL=e2label
442 export DUMPE2FS=$DUMPE2FS
443 if [ -z "$DUMPE2FS" ]; then
444 if which dumpfs.ldiskfs >/dev/null 2>&1; then
445 export DUMPE2FS=dumpfs.ldiskfs
447 export DUMPE2FS=dumpe2fs
451 export E2FSCK=$E2FSCK
452 if [ -z "$E2FSCK" ]; then
453 if which fsck.ldiskfs >/dev/null 2>&1; then
454 export E2FSCK=fsck.ldiskfs
460 export RESIZE2FS=$RESIZE2FS
461 if [ -z "$RESIZE2FS" ]; then
462 if which resizefs.ldiskfs >/dev/null 2>&1; then
463 export RESIZE2FS=resizefs.ldiskfs
465 export RESIZE2FS=resize2fs
469 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
470 export FSCK_MAX_ERR=4 # File system errors left uncorrected
472 export ZFS=${ZFS:-zfs}
473 export ZPOOL=${ZPOOL:-zpool}
474 export ZDB=${ZDB:-zdb}
475 export PARTPROBE=${PARTPROBE:-partprobe}
477 #[ -d /r ] && export ROOT=${ROOT:-/r}
478 export TMP=${TMP:-$ROOT/tmp}
479 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
480 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
481 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
483 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
484 if ! echo $PATH | grep -q $LUSTRE/utils; then
485 export PATH=$LUSTRE/utils:$PATH
487 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
488 export PATH=$LUSTRE/utils/gss:$PATH
490 if ! echo $PATH | grep -q $LUSTRE/tests; then
491 export PATH=$LUSTRE/tests:$PATH
493 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
494 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
496 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
497 [ ! -f "$LST" ] && export LST=$(which lst)
498 export LSTSH=${LSTSH:-"$LUSTRE/../lustre-iokit/lst-survey/lst.sh"}
499 [ ! -f "$LSTSH" ] && export LSTSH=$(which lst.sh)
500 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
501 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
502 export MCREATE=${MCREATE:-mcreate}
503 export MULTIOP=${MULTIOP:-multiop}
504 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
505 export STATX=${STATX:-statx}
506 # Ubuntu, at least, has a truncate command in /usr/bin
507 # so fully path our truncate command.
508 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
509 export FSX=${FSX:-$LUSTRE/tests/fsx}
510 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
511 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
512 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
513 export PATH=$LUSTRE/tests/racer:$PATH:
515 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
516 export PATH=$LUSTRE/tests/mpi:$PATH
519 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
520 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
521 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
522 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
523 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
524 [ ! -f "$LFS" ] && export LFS=$(which lfs)
525 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
526 [ ! -f "$KSOCKLND_CONFIG" ] &&
527 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
529 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
531 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
532 if [ ! -f "$L_GETIDENTITY" ]; then
533 if $(which l_getidentity > /dev/null 2>&1); then
534 export L_GETIDENTITY=$(which l_getidentity)
536 export L_GETIDENTITY=NONE
539 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
540 [ ! -f "$LL_DECODE_FILTER_FID" ] &&
541 export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
542 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
543 [ ! -f "$LL_DECODE_LINKEA" ] &&
544 export LL_DECODE_LINKEA="ll_decode_linkea"
545 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
546 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
547 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
548 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
549 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
550 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
551 [ ! -f "$LUSTRE_RMMOD" ] &&
552 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
553 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
554 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
555 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
556 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
557 [ ! -f "$LFS_MIGRATE" ] &&
558 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
559 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
560 [ ! -f "$LR_READER" ] &&
561 export LR_READER=$(which lr_reader 2> /dev/null)
562 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
563 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
564 [ ! -f "$LSOM_SYNC" ] &&
565 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
566 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
567 export L_GETAUTH=${L_GETAUTH:-"$LUSTRE/utils/gss/l_getauth"}
568 [ ! -f "$L_GETAUTH" ] && export L_GETAUTH=$(which l_getauth 2> /dev/null)
569 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
570 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
571 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
573 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
575 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
576 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
578 export DMSETUP=${DMSETUP:-dmsetup}
579 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
580 export LOSETUP=${LOSETUP:-losetup}
582 if [ "$ACCEPTOR_PORT" ]; then
583 export PORT_OPT="--port $ACCEPTOR_PORT"
587 $RPC_MODE || echo "Using GSS shared-key feature"
589 export LGSS_SK=$(which lgss_sk 2> /dev/null)
591 export LGSS_SK="$LUSTRE/utils/gss/lgss_sk"
593 error_exit "built with lgss_sk disabled! SEC=$SEC"
601 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
602 which lgss_keyring > /dev/null 2>&1 ||
603 error_exit "built with gss disabled! SEC=$SEC"
609 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
611 # Paths on remote nodes, if different
612 export RLUSTRE=${RLUSTRE:-$LUSTRE}
613 export RPWD=${RPWD:-$PWD}
614 export I_MOUNTED=${I_MOUNTED:-"no"}
615 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
616 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
617 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
618 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
619 ! -f $LUSTRE/mdt/mdt.ko ]; then
620 export CLIENTMODSONLY=yes
623 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
624 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
628 while getopts "rvwf:" opt $*; do
633 w) WRITECONF=writeconf;;
638 shift $((OPTIND - 1))
641 # print the durations of each test if "true"
642 DDETAILS=${DDETAILS:-false}
643 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
648 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
650 # Constants used in more than one test script
651 export LOV_MAX_STRIPE_COUNT=2000
652 export LMV_MAX_STRIPES_PER_MDT=5
653 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
654 export KEEP_POOLS=${KEEP_POOLS:-false}
655 export PARALLEL=${PARALLEL:-"no"}
657 export BLCKSIZE=${BLCKSIZE:-4096}
658 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
661 # use localrecov to enable recovery for local clients, LU-12722
662 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
663 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
664 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
667 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
668 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
675 ncpts=$(do_facet $facet "lctl get_param -n " \
676 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
678 if [ $ncpts -eq 0 ]; then
685 # Return a numeric version code based on a version string. The version
686 # code is useful for comparison two version strings to see which is newer.
688 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
689 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
691 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
694 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
695 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
697 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
699 # usage: lustre_build_version
701 # All Lustre versions support "lctl get_param" to report the version of the
702 # code running in the kernel (what our tests are interested in), but it
703 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
704 # the "version" parameter doesn't include "lustre: " at the beginning.
705 # If that fails, call "lctl lustre_build_version" which prints either (or both)
706 # the userspace and kernel build versions, but until 2.8.55 required root
707 # access to get the Lustre kernel version. If that also fails, fall back to
708 # using "lctl --version", which is easy to parse and works without the kernel
709 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
710 # not the module version, though they are usually the same.
712 # Various commands and their output format for different Lustre versions:
713 # lctl get_param version: 2.9.55
714 # lctl get_param version: lustre: 2.8.53
715 # lctl get_param version: lustre: 2.6.52
716 # kernel: patchless_client
717 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
718 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
719 # lctl lustre_build_version: error: lustre_build_version: Permission denied
720 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
721 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
722 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
723 # lctl --version: lctl 2.6.50
725 # output: prints version string to stdout in (up to 4) dotted-decimal values
726 lustre_build_version() {
727 local facet=${1:-client}
728 local facet_version=${facet}_VERSION
730 # if the global variable is already set, then use that
731 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
733 # this is the currently-running version of the kernel modules
734 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
735 # we mostly test 2.10+ systems, only try others if the above fails
736 if [ -z "$ver" ]; then
737 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
739 if [ -z "$ver" ]; then
740 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
743 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
744 [ -n "$lver" ] && ver="$lver"
746 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
747 tr _ . | cut -d. -f1-4)
749 # save in global variable for the future
750 export $facet_version=$lver
755 # Report the Lustre numeric build version code for the supplied facet.
756 lustre_version_code() {
757 version_code $(lustre_build_version $1)
761 /sbin/lsmod | grep -q "^\<$1\>"
764 check_lfs_df_ret_val() {
765 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
766 # returned by 'lfs df' for valid dentry but not a lustrefs.
768 # 'lfs df' historically always returned success(0) instead of
769 # EOPNOTSUPP. This function for compatibility reason, ignores and
770 # masquerades EOPNOTSUPP as success.
771 [[ $1 -eq 95 ]] && return 0
784 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
787 # parallels can't load modules directly from prlfs, use /tmp instead
788 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
789 local target="$(mktemp)"
791 cp "$module" "$target"
794 [[ $rc == 0 ]] && PRLFS=true
802 # Load a module on the system where this is running.
804 # usage: load_module module_name [module arguments for insmod/modprobe]
806 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
807 # will be used as the arguments. Otherwise arguments will be obtained from
808 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
811 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
814 local base=$(basename $module $ext)
816 local -A module_is_loaded_aa
820 for mod in $(lsmod | awk '{ print $1; }'); do
821 module_is_loaded_aa[${mod//-/_}]=true
825 ${module_is_loaded_aa[${1//-/_}]:-false}
828 if module_is_loaded $base; then
832 if [[ -f $LUSTRE/$module$ext ]]; then
833 path=$LUSTRE/$module$ext
834 elif [[ "$base" == lnet_selftest ]] &&
835 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
836 path=$LUSTRE/../lnet/selftest/$base$ext
841 if [[ -n "$path" ]]; then
842 # Try to load any non-Lustre modules that $module depends on.
843 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
844 if ! module_is_loaded $mod; then
850 # If no module arguments were passed then get them from
851 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
852 if [ $# -eq 0 ]; then
853 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
854 # not in Bash until 4.x, so we resort to eval.
855 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
856 eval set -- \$$optvar
857 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
858 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
860 opt=$(awk -v var="^options $base" '$0 ~ var \
861 {gsub("'"options $base"'",""); print}' \
863 set -- $(echo -n $opt)
865 # Ensure we have accept=all for lnet
866 if [[ "$base" == lnet ]]; then
867 # OK, this is a bit wordy...
868 local arg accept_all_present=false
871 [[ "$arg" == accept=all ]] &&
872 accept_all_present=true
875 $accept_all_present || set -- "$@" accept=all
882 [ $# -gt 0 ] && echo "${module} options: '$*'"
884 # Note that insmod will ignore anything in modprobe.conf, which is why
885 # we're passing options on the command-line. If $path does not exist
886 # then we must be testing a "make install" or"rpm" installation. Also
887 # note that failing to load ptlrpc_gss is not considered fatal.
888 if [[ -n "$path" ]]; then
889 lustre_insmod $path "$@"
890 elif [[ "$base" == ptlrpc_gss ]]; then
891 if ! modprobe $base "$@" 2>/dev/null; then
892 echo "gss/krb5 is not supported"
900 $LCTL mark "$LNETCTL $*"
906 # For kmemleak-enabled kernels we need clear all past state
907 # that obviously has nothing to do with this Lustre run
908 # Disable automatic memory scanning to avoid perf hit.
909 if [ -f /sys/kernel/debug/kmemleak ] ; then
910 echo scan=off > /sys/kernel/debug/kmemleak || true
911 echo scan > /sys/kernel/debug/kmemleak || true
912 echo clear > /sys/kernel/debug/kmemleak || true
915 echo Loading modules from $LUSTRE
919 if [ -f /sys/devices/system/cpu/online ]; then
920 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
921 echo "detected $ncpus online CPUs by sysfs"
923 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
926 if [ $rc -eq 0 ]; then
927 echo "detected $ncpus online CPUs by getconf"
929 echo "Can't detect number of CPUs"
934 # if there is only one CPU core, libcfs can only create one partition
935 # if there is more than 4 CPU cores, libcfs should create multiple CPU
936 # partitions. So we just force libcfs to create 2 partitions for
937 # system with 2 or 4 cores
938 local saved_opts="$MODOPTS_LIBCFS"
940 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
941 # force to enable multiple CPU partitions
942 echo "Force libcfs to create 2 CPU partitions"
943 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
945 echo "libcfs will create CPU partition based on online CPUs"
948 load_module ../libcfs/libcfs/libcfs
949 # Prevent local MODOPTS_LIBCFS being passed as part of environment
950 # variable to remote nodes
953 set_default_debug "neterror net nettrace malloc"
954 if [ "$1" = "config_on_load=1" ]; then
955 load_module ../lnet/lnet/lnet
957 load_module ../lnet/lnet/lnet "$@"
960 LNDPATH=${LNDPATH:-"../lnet/klnds"}
961 if [ -z "$LNETLND" ]; then
963 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
964 tcp*) LNETLND="socklnd/ksocklnd" ;;
965 kfi*) LNETLND="kfilnd/kkfilnd" ;;
966 gni*) LNETLND="gnilnd/kgnilnd" ;;
967 *) local lnd="${NETTYPE%%[0-9]}lnd"
968 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
969 LNETLND="$lnd/k$lnd" ||
970 LNETLND="socklnd/ksocklnd"
973 load_module ../lnet/klnds/$LNETLND
975 if [ "$1" = "config_on_load=1" ]; then
976 do_lnetctl lnet configure --all ||
981 load_modules_local() {
982 if [ -n "$MODPROBE" ]; then
984 echo "Using modprobe to load modules"
988 # Create special udev test rules on every node
989 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
990 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
992 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
994 udevadm control --reload-rules
999 load_module obdclass/obdclass
1000 if ! client_only; then
1001 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
1003 load_module ptlrpc/ptlrpc
1004 load_module ptlrpc/gss/ptlrpc_gss
1012 load_module obdecho/obdecho
1013 if ! client_only; then
1014 load_module lfsck/lfsck
1015 [ "$LQUOTA" != "no" ] &&
1016 load_module quota/lquota $LQUOTAOPTS
1017 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
1018 load_module osd-zfs/osd_zfs
1019 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
1020 load_module ../ldiskfs/ldiskfs
1021 load_module osd-ldiskfs/osd_ldiskfs
1026 # don't fail if ost module doesn't exist
1027 load_module ost/ost 2>/dev/null || true;
1033 load_module llite/lustre
1034 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
1036 rm -f $OGDB/ogdb-$HOSTNAME
1037 $LCTL modules > $OGDB/ogdb-$HOSTNAME
1039 # 'mount' doesn't look in $PATH, just sbin
1040 local mount_lustre=$LUSTRE/utils/mount.lustre
1041 if [ -f $mount_lustre ]; then
1042 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1043 if grep -qw "$sbin_mount" /proc/mounts; then
1044 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
1046 if ! grep -qw "$sbin_mount" /proc/mounts; then
1047 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
1048 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
1049 cat <<- EOF > "$sbin_mount"
1052 echo "This $sbin_mount just a mountpoint." 1>&2
1053 echo "It is never supposed to be run." 1>&2
1054 logger -p emerg -- "using stub $sbin_mount $@"
1057 chmod a+x $sbin_mount
1059 mount --bind $mount_lustre $sbin_mount ||
1060 error "can't bind $mount_lustre to $sbin_mount"
1071 # load modules on remote nodes optionally
1072 # lustre-tests have to be installed on these nodes
1073 if $LOAD_MODULES_REMOTE; then
1074 local list=$(comma_list $(remote_nodes_list))
1076 # include failover nodes in case they are not in the list yet
1077 facets=$(get_facets)
1078 for facet in ${facets//,/ }; do
1079 failover=$(facet_failover_host $facet)
1080 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
1081 list="$list,$failover"
1084 if [ -n "$list" ]; then
1085 echo "loading modules on: '$list'"
1086 do_rpc_nodes "$list" load_modules_local
1092 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
1093 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
1095 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
1096 echo "$LEAK_LUSTRE" 1>&2
1097 echo "$LEAK_PORTALS" 1>&2
1098 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
1099 echo "Memory leaks detected"
1100 [ -n "$IGNORE_LEAK" ] &&
1101 { echo "ignoring leaks" && return 0; } || true
1106 unload_modules_local() {
1107 $LUSTRE_RMMOD ldiskfs || return 2
1109 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
1110 rm /etc/udev/rules.d/99-lustre-test.rules
1111 udevadm control --reload-rules
1114 check_mem_leak || return 254
1122 wait_exit_ST client # bug 12845
1124 unload_modules_local || rc=$?
1126 if $LOAD_MODULES_REMOTE; then
1127 local list=$(comma_list $(remote_nodes_list))
1128 if [ -n "$list" ]; then
1129 echo "unloading modules on: '$list'"
1130 do_rpc_nodes "$list" unload_modules_local
1134 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1135 if grep -qe "$sbin_mount " /proc/mounts; then
1136 umount $sbin_mount || true
1137 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
1141 [[ $rc -eq 0 ]] && echo "modules unloaded."
1147 local facet=${1:-ost1}
1149 local mult=$OSTCOUNT
1151 case $(facet_fstype $facet) in
1152 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
1153 # grant_block_size is in bytes, allow at least 2x max blocksize
1154 zfs) size=$(lctl get_param osc.$FSNAME*.import |
1155 awk '/grant_block_size:/ {print $2/512; exit;}')
1159 [[ $facet =~ mds ]] && mult=$MDTCOUNT
1160 echo -n $((size * mult))
1164 local facet=${1:-$SINGLEMDS}
1165 local fstype=$(facet_fstype $facet)
1168 ldiskfs) size=4;; # ~4KB per inode
1169 zfs) size=11;; # 10 to 11KB per inode
1182 echo Running as $user: $cmd $opts
1185 su - $user -c "$cmd $opts"
1188 check_gss_daemon_nodes() {
1196 dname=$(basename "$dname" | awk '{print $1}')
1197 do_nodesv $list "num=0;
1198 for proc in \\\$(pgrep $dname); do
1199 [ \\\$(ps -o ppid= -p \\\$proc) -ne 1 ] || ((num++))
1201 if [ \\\"\\\$num\\\" -ne 1 ]; then
1202 echo \\\$num instance of $dname;
1206 (( $ret == 0 )) || return $ret
1208 for node in ${list//,/ }; do
1210 while (( $loop < $loopmax )); do
1211 do_nodesv $node "$L_GETAUTH -d"
1213 (( $ret == 0 )) && break
1217 (( $loop < $loopmax )) || return 1
1222 check_gss_daemon_facet() {
1226 dname=$(basename "$dname" | awk '{print $1}')
1227 num=$(do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l)
1228 if [ $num -ne 1 ]; then
1229 echo "$num instance of $dname on $facet"
1239 echo "Stopping "$@" on $list"
1240 do_nodes $list "killall -2 $* 2>/dev/null || true"
1243 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1244 start_gss_daemons() {
1249 if [ "$nodes" ] && [ "$daemon" ] ; then
1250 echo "Starting gss daemon on nodes: $nodes"
1251 do_nodes $nodes "$daemon" "$options" || return 8
1252 check_gss_daemon_nodes $nodes "$daemon" || return 9
1256 nodes=$(comma_list $(mdts_nodes))
1257 echo "Starting gss daemon on mds: $nodes"
1259 # Start all versions, in case of switching
1260 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1263 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 1
1266 nodes=$(comma_list $(osts_nodes))
1267 echo "Starting gss daemon on ost: $nodes"
1269 # Start all versions, in case of switching
1270 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1273 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 3
1275 # starting on clients
1277 local clients=${CLIENTS:-$HOSTNAME}
1280 # check daemons are running
1282 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1283 check_gss_daemon_nodes $nodes "$LSVCGSSD" || return 5
1286 stop_gss_daemons() {
1287 local nodes=$(comma_list $(mdts_nodes))
1289 send_sigint $nodes lsvcgssd lgssd
1291 nodes=$(comma_list $(osts_nodes))
1292 send_sigint $nodes lsvcgssd
1294 nodes=${CLIENTS:-$HOSTNAME}
1295 send_sigint $nodes lgssd
1299 # Add mount flags for shared key
1302 if grep -q skpath <<< "$mt_opts" ; then
1303 mt_opts=$(echo $mt_opts |
1304 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1306 if [ -z "$mt_opts" ]; then
1307 mt_opts="-o skpath=$SK_PATH"
1309 mt_opts="$mt_opts,skpath=$SK_PATH"
1319 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1328 [ $from_tree = true ]
1332 if $SHARED_KEY; then
1341 if ! module_loaded ptlrpc_gss; then
1342 load_module ptlrpc/gss/ptlrpc_gss
1343 module_loaded ptlrpc_gss ||
1344 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1347 if $GSS_KRB5 || $GSS_SK; then
1348 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1351 if $GSS_SK && ! $SK_NO_KEY; then
1352 echo "Loading basic SSK keys on all servers"
1353 do_nodes $(comma_list $(all_server_nodes)) \
1354 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1355 do_nodes $(comma_list $(all_server_nodes)) \
1356 "keyctl show | grep lustre | cut -c1-11 |
1358 xargs -IX keyctl setperm X 0x3f3f3f3f"
1361 if $GSS_SK && $SK_NO_KEY; then
1362 local numclients=${1:-$CLIENTCOUNT}
1363 local clients=${CLIENTS:-$HOSTNAME}
1365 # security ctx config for keyring
1367 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1369 if from_build_tree; then
1370 mkdir -p $SK_OM_PATH
1371 if grep -q request-key /proc/mounts > /dev/null; then
1372 echo "SSK: Request key already mounted."
1374 mount -o bind $SK_OM_PATH /etc/request-key.d/
1376 local lgssc_conf_line='create lgssc * * '
1377 lgssc_conf_line+=$(which lgss_keyring)
1378 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1379 echo "$lgssc_conf_line" > $lgssc_conf_file
1382 [ -e $lgssc_conf_file ] ||
1383 error_exit "Could not find key options in $lgssc_conf_file"
1384 echo "$lgssc_conf_file content is:"
1385 cat $lgssc_conf_file
1387 if ! local_mode; then
1388 if from_build_tree; then
1389 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1391 do_nodes $(comma_list $(all_nodes)) "mount \
1392 -o bind $SK_OM_PATH \
1393 /etc/request-key.d/"
1394 do_nodes $(comma_list $(all_nodes)) "rsync \
1395 -aqv $HOSTNAME:$lgssc_conf_file \
1396 $lgssc_conf_file >/dev/null 2>&1"
1398 do_nodes $(comma_list $(all_nodes)) \
1399 "echo $lgssc_conf_file: ; \
1400 cat $lgssc_conf_file"
1404 # create shared key on all nodes
1405 mkdir -p $SK_PATH/nodemap
1406 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1407 $SK_PATH/$FSNAME-*.key
1408 # for nodemap testing each client may need own key,
1409 # and S2S now requires keys as well, both for "client"
1412 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1413 -w $SK_PATH/$FSNAME-nmclient.key \
1414 -d /dev/urandom >/dev/null 2>&1
1415 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1416 -w $SK_PATH/$FSNAME-s2s-server.key \
1417 -d /dev/urandom >/dev/null 2>&1
1420 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1421 -d /dev/urandom >/dev/null 2>&1
1423 for i in $(seq 0 $((numclients - 1))); do
1424 $LGSS_SK -t server -f$FSNAME -n c$i \
1425 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1429 if ! local_mode; then
1430 for lnode in $(all_nodes); do
1431 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1434 # Set client keys to client type to generate prime P
1436 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1437 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1439 do_nodes $clients "$LGSS_SK -t client -m \
1440 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1441 do_nodes $clients "find $SK_PATH/nodemap \
1442 -name \*.key | xargs -IX $LGSS_SK -t client \
1443 -m X >/dev/null 2>&1"
1444 # also have a client key available on server side,
1445 # for local client mount
1446 do_nodes $(comma_list $(all_server_nodes)) \
1447 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1448 $LGSS_SK -t client -m \
1449 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1451 # This is required for servers as well, if S2S in use
1453 do_nodes $(comma_list $(mdts_nodes)) \
1454 "cp $SK_PATH/$FSNAME-s2s-server.key \
1455 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1456 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1458 do_nodes $(comma_list $(osts_nodes)) \
1459 "cp $SK_PATH/$FSNAME-s2s-server.key \
1460 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1461 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1463 do_nodes $clients "$LGSS_SK -t client \
1464 -m $SK_PATH/$FSNAME-nmclient.key \
1469 # mount options for servers and clients
1470 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1471 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1472 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1473 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1475 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1476 LGSS_KEYRING_DEBUG=4
1480 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1481 ( local_mode || from_build_tree ); then
1483 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1484 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1485 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1487 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1490 do_nodesv $(comma_list $(all_server_nodes)) \
1491 "$LCTL set_param sptlrpc.gss.rsi_upcall=$L_GETAUTH"
1497 # maybe cleanup credential cache?
1504 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1505 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1506 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1510 $RPC_MODE || echo "Cleaning up Shared Key.."
1511 do_nodes $(comma_list $(all_nodes)) "rm -f \
1512 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1513 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1514 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1515 if from_build_tree; then
1516 # Remove the mount and clean up the files we added to
1518 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1519 request-key.d /proc/mounts; do umount \
1520 /etc/request-key.d/; done"
1521 do_nodes $(comma_list $(all_nodes)) "rm -f \
1522 $SK_OM_PATH/lgssc.conf"
1523 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1531 local var=${facet}_svc
1539 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1540 tr '[:lower:]' '[:upper:]'
1546 if [ $facet == mgs ] || [ $facet == client ]; then
1550 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1558 if [ -n "${!var}" ]; then
1563 var=$(facet_type $facet)FSTYPE
1564 if [ -n "${!var}" ]; then
1569 if [ -n "$FSTYPE" ]; then
1574 if [[ $facet == mgs ]] && combined_mgs_mds; then
1586 local facets=$(get_facets)
1589 for facet in ${facets//,/ }; do
1590 if [[ $node == $(facet_host $facet) ]] ||
1591 [[ $node == "$(facet_failover_host $facet)" ]]; then
1592 fstype=$(facet_fstype $facet)
1593 if [[ $fstypes != *$fstype* ]]; then
1594 fstypes+="${fstypes:+,}$fstype"
1603 local num=$(facet_number $facet)
1606 if [[ $(facet_type $facet) = OST ]]; then
1607 index=OSTINDEX${num}
1608 if [[ -n "${!index}" ]]; then
1613 index=${OST_INDICES[num - 1]}
1616 [[ -n "$index" ]] || index=$((num - 1))
1624 local fstype=$(facet_fstype $facet)
1628 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1630 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1631 ${dev} 2>/dev/null");;
1633 error "unknown fstype!";;
1640 # Get the device of a facet.
1647 mgs) device=$(mgsdevname) ;;
1648 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1649 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1650 fs2mds) device=$(mdsdevname 1_2) ;;
1651 fs2ost) device=$(ostdevname 1_2) ;;
1652 fs3ost) device=$(ostdevname 2_2) ;;
1660 # Get the virtual device of a facet.
1667 mgs) device=$(mgsvdevname) ;;
1668 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1669 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1670 fs2mds) device=$(mdsvdevname 1_2) ;;
1671 fs2ost) device=$(ostvdevname 1_2) ;;
1672 fs3ost) device=$(ostvdevname 2_2) ;;
1680 local virt=$(virt-what 2> /dev/null)
1682 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1684 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1687 VMware|KVM|VirtualBox|Parallels|Bochs)
1688 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1693 virt=$(dmidecode -s system-manufacturer | awk '{print $1}')
1696 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1702 # Re-read the partition table on failover partner host.
1703 # After a ZFS storage pool is created on a shared device, the partition table
1704 # on the device may change. However, the operating system on the failover
1705 # host may not notice the change automatically. Without the up-to-date partition
1706 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1707 # relative to partition rather than disk beginnings.
1709 # This function performs partprobe on the failover host to make it re-read the
1712 refresh_partition_table() {
1717 host=$(facet_passive_host $facet)
1718 if [[ -n "$host" ]]; then
1719 do_node $host "$PARTPROBE $device"
1724 # Get ZFS storage pool name.
1731 device=$(facet_device $facet)
1732 # poolname is string before "/"
1733 poolname="${device%%/*}"
1740 # Get ZFS local fsname.
1742 zfs_local_fsname() {
1744 local lfsname=$(basename $(facet_device $facet))
1750 # Create ZFS storage pool.
1757 local opts=${@:-"-o cachefile=none"}
1759 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1760 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1761 $ZPOOL create -f $opts $poolname $vdev"
1765 # Create ZFS file system.
1771 local opts=${@:-"-o mountpoint=legacy"}
1773 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1774 $ZFS create $opts $dataset"
1778 # Export ZFS storage pool.
1779 # Before exporting the pool, all datasets within the pool should be unmounted.
1787 poolname=$(zpool_name $facet)
1789 if [[ -n "$poolname" ]]; then
1790 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1791 grep -q ^$poolname/ /proc/mounts ||
1792 $ZPOOL export $opts $poolname"
1797 # Destroy ZFS storage pool.
1798 # Destroy the given pool and free up any devices for other use. This command
1799 # tries to unmount any active datasets before destroying the pool.
1800 # -f Force any active datasets contained within the pool to be unmounted.
1804 local poolname=${2:-$(zpool_name $facet)}
1806 if [[ -n "$poolname" ]]; then
1807 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1808 $ZPOOL destroy -f $poolname"
1813 # Import ZFS storage pool.
1814 # Force importing, even if the pool appears to be potentially active.
1819 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1822 poolname=$(zpool_name $facet)
1824 if [[ -n "$poolname" ]]; then
1825 opts+=" -d $(dirname $(facet_vdevice $facet))"
1826 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1827 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1828 $ZPOOL import -f $opts $poolname"
1833 # Reimport ZFS storage pool with new name
1838 local opts="-o cachefile=none"
1839 local poolname=$(zpool_name $facet)
1841 opts+=" -d $(dirname $(facet_vdevice $facet))"
1842 do_facet $facet "$ZPOOL export $poolname;
1843 $ZPOOL import $opts $poolname $newpool"
1847 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1848 # is not automatically imported on system startup.
1850 # In a failover environment, this will provide resource level fencing which
1851 # will ensure that the same ZFS storage pool will not be imported concurrently
1852 # on different nodes.
1854 disable_zpool_cache() {
1858 poolname=$(zpool_name $facet)
1860 if [[ -n "$poolname" ]]; then
1861 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1866 # This and set_osd_param() shall be used to access OSD parameters
1867 # once existed under "obdfilter":
1872 # writethrough_cache_enable
1876 local device=${2:-$FSNAME-OST*}
1879 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1884 local device=${2:-$FSNAME-OST*}
1888 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1891 set_default_debug () {
1892 local debug=${1:-"$PTLDEBUG"}
1893 local subsys=${2:-"$SUBSYSTEM"}
1894 local debug_size=${3:-$DEBUG_SIZE}
1896 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1898 lctl set_param subsystem_debug="${subsys# }" >/dev/null
1899 [ -n "$debug_size" ] &&
1900 lctl set_param debug_mb="$debug_size" >/dev/null
1905 set_default_debug_nodes () {
1907 local debug="${2:-"$PTLDEBUG"}"
1908 local subsys="${3:-"$SUBSYSTEM"}"
1909 local debug_size="${4:-$DEBUG_SIZE}"
1911 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1912 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1916 [[ -z "$nodes" ]] ||
1917 do_rpc_nodes "$nodes" set_default_debug \
1918 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1921 set_default_debug_facet () {
1923 local debug="${2:-"$PTLDEBUG"}"
1924 local subsys="${3:-"$SUBSYSTEM"}"
1925 local debug_size="${4:-$DEBUG_SIZE}"
1926 local node=$(facet_active_host $facet)
1928 [ -n "$node" ] || error "No host defined for facet $facet"
1930 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1933 set_params_nodes() {
1938 [[ -n "$params" ]] || return 0
1940 do_nodes $nodes "$LCTL set_param $params"
1943 set_params_clients() {
1944 (( $# >= 2 )) || return 0
1945 local clients=${1:-$CLIENTS}
1947 local params="${@:-$CLIENT_LCTL_SETPARAM_PARAM}"
1949 set_params_nodes $clients $params
1953 (( $# >= 2 )) || return 0
1954 local mdts=${1:-$(comma_list $(mdts_nodes))}
1956 local params="${@:-$MDS_LCTL_SETPARAM_PARAM}"
1958 set_params_nodes $mdts $params
1962 (( $# >= 2 )) || return 0
1963 local osts=${1:-$(comma_list $(osts_nodes))}
1965 local params="${@:-$OSS_LCTL_SETPARAM_PARAM}"
1967 set_params_nodes $osts $params
1971 local hostid=${1:-$(hostid)}
1973 if [ ! -s /etc/hostid ]; then
1974 printf $(echo -n $hostid |
1975 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1981 local facets=${1:-$(get_facets)}
1987 for facet in ${facets//,/ }; do
1988 mount_facet $facet &
1992 for ((index=0; index<$total; index++)); do
1993 wait ${mountpids[index]}
1995 [ $RC -eq 0 ] && continue
1997 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1998 skip_noexit "Restart of $facet failed!." &&
2001 error "Restart of $facet failed!"
2009 # Add argument "arg" (e.g., "loop") to the comma-separated list
2010 # of arguments for option "opt" (e.g., "-o") on command
2011 # line "opts" (e.g., "-o flock").
2017 local opt_pattern="\([[:space:]]\+\|^\)$opt"
2019 if echo "$opts" | grep -q $opt_pattern; then
2020 opts=$(echo "$opts" | sed -e \
2021 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
2023 opts+="${opts:+ }$opt $arg"
2029 # Associate loop device with a given regular file.
2030 # Return the loop device.
2032 setup_loop_device() {
2036 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
2037 if [[ -z \\\$loop_dev ]]; then
2038 loop_dev=\\\$($LOSETUP -f);
2039 $LOSETUP \\\$loop_dev $file || loop_dev=;
2041 echo -n \\\$loop_dev"
2045 # Detach a loop device.
2047 cleanup_loop_device() {
2051 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
2052 $LOSETUP -d $loop_dev"
2056 # Check if a given device is a block device.
2063 [[ -n "$dev" ]] || return 1
2064 do_facet $facet "test -b $dev" || return 1
2065 if [[ -n "$size" ]]; then
2066 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
2067 count=1 skip=$size 2>&1" |
2068 awk '($3 == "in") { print $1 }')
2069 [[ "$in" = "1+0" ]] || return 1
2074 # Check if a given device is a device-mapper device.
2080 [[ -n "$dev" ]] || return 1
2081 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
2085 # Check if a given device is a device-mapper flakey device.
2087 is_dm_flakey_dev() {
2092 [[ -n "$dev" ]] || return 1
2094 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
2096 [[ $type = flakey ]] && return 0 || return 1
2100 # Check if device-mapper flakey device is supported by the kernel
2101 # of $facet node or not.
2103 dm_flakey_supported() {
2107 do_facet $facet "modprobe dm-flakey;
2108 $DMSETUP targets | grep -q flakey" &> /dev/null
2112 # Get the device-mapper flakey device name of a given facet.
2114 dm_facet_devname() {
2116 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2118 echo -n ${facet}_flakey
2122 # Get the device-mapper flakey device of a given facet.
2123 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
2125 dm_facet_devpath() {
2128 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
2132 # Set a device-mapper device with a new table.
2134 # The table has the following format:
2135 # <logical_start_sector> <num_sectors> <target_type> <target_args>
2137 # flakey <target_args> includes:
2138 # <destination_device> <offset> <up_interval> <down_interval> \
2139 # [<num_features> [<feature_arguments>]]
2141 # linear <target_args> includes:
2142 # <destination_device> <start_sector>
2144 dm_set_dev_table() {
2147 local target_type=$3
2153 read tmp num_sectors tmp real_dev tmp \
2154 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
2156 case $target_type in
2158 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
2161 table="0 $num_sectors linear $real_dev 0"
2163 *) error "invalid target type $target_type" ;;
2166 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
2167 error "failed to suspend $dm_dev"
2168 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
2169 error "failed to load $target_type table into $dm_dev"
2170 do_facet $facet "$DMSETUP resume $dm_dev" ||
2171 error "failed to resume $dm_dev"
2175 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
2176 # feature parameter.
2179 # All write I/O is silently ignored.
2180 # Read I/O is handled correctly.
2182 dm_set_dev_readonly() {
2184 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2186 dm_set_dev_table $facet $dm_dev flakey
2190 # Set a device-mapper device to traditional linear mapping mode.
2192 dm_clear_dev_readonly() {
2194 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2196 dm_set_dev_table $facet $dm_dev linear
2200 # Set the device of a given facet as "read-only".
2202 set_dev_readonly() {
2204 local svc=${facet}_svc
2206 if [[ $(facet_fstype $facet) = zfs ]] ||
2207 ! dm_flakey_supported $facet; then
2208 do_facet $facet $LCTL --device ${!svc} readonly
2210 dm_set_dev_readonly $facet
2215 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
2222 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
2223 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
2224 echo -n $num_sectors
2228 # Create a device-mapper device with a given block device or regular file (will
2229 # be associated with loop device).
2230 # Return the full path of the device-mapper device.
2234 local real_dev=$2 # destination device
2235 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
2236 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
2238 # check if the device-mapper device to be created already exists
2239 if is_dm_dev $facet $dm_dev; then
2240 # if the existing device was set to "read-only", then clear it
2241 ! is_dm_flakey_dev $facet $dm_dev ||
2242 dm_clear_dev_readonly $facet $dm_dev
2248 # check if the destination device is a block device, and if not,
2249 # associate it with a loop device
2250 is_blkdev $facet $real_dev ||
2251 real_dev=$(setup_loop_device $facet $real_dev)
2252 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
2254 # now create the device-mapper device
2255 local num_sectors=$(get_num_sectors $facet $real_dev)
2256 local table="0 $num_sectors linear $real_dev 0"
2259 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
2260 { rc=${PIPESTATUS[0]}; dm_dev=; }
2261 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2268 # Map the facet name to its device variable name.
2270 facet_device_alias() {
2272 local dev_alias=$facet
2275 fs2mds) dev_alias=mds1_2 ;;
2276 fs2ost) dev_alias=ost1_2 ;;
2277 fs3ost) dev_alias=ost2_2 ;;
2285 # Save the original value of the facet device and export the new value.
2291 local active_facet=$(facet_active $facet)
2292 local dev_alias=$(facet_device_alias $active_facet)
2293 local dev_name=${dev_alias}_dev
2294 local dev=${!dev_name}
2296 if [[ $active_facet = $facet ]]; then
2297 local failover_dev=${dev_alias}failover_dev
2298 if [[ ${!failover_dev} = $dev ]]; then
2299 eval export ${failover_dev}_saved=$dev
2300 eval export ${failover_dev}=$dm_dev
2303 dev_alias=$(facet_device_alias $facet)
2304 local facet_dev=${dev_alias}_dev
2305 if [[ ${!facet_dev} = $dev ]]; then
2306 eval export ${facet_dev}_saved=$dev
2307 eval export ${facet_dev}=$dm_dev
2311 eval export ${dev_name}_saved=$dev
2312 eval export ${dev_name}=$dm_dev
2316 # Restore the saved value of the facet device.
2321 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2322 local dev_alias=$(facet_device_alias $facet)
2324 local saved_dev=${dev_alias}_dev_saved
2325 [[ -z ${!saved_dev} ]] ||
2326 eval export ${dev_alias}_dev=${!saved_dev}
2328 saved_dev=${dev_alias}failover_dev_saved
2329 [[ -z ${!saved_dev} ]] ||
2330 eval export ${dev_alias}failover_dev=${!saved_dev}
2334 # Remove a device-mapper device.
2335 # If the destination device is a loop device, then also detach it.
2339 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2343 is_dm_dev $facet $dm_dev || return 0
2345 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2346 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2348 do_facet $facet "$DMSETUP remove $dm_dev"
2349 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2351 unexport_dm_dev $facet
2353 # detach a loop device
2354 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2356 # unload dm-flakey module
2357 do_facet $facet "modprobe -r dm-flakey" || true
2363 local active_facet=$(facet_active $facet)
2364 local dev_alias=$(facet_device_alias $active_facet)
2365 local dev=${dev_alias}_dev
2366 local opt=${facet}_opt
2367 local mntpt=$(facet_mntpt $facet)
2368 local opts="${!opt} $@"
2369 local fstype=$(facet_fstype $facet)
2371 local dm_dev=${!dev}
2373 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2374 dev=mds1failover_dev
2376 module_loaded lustre || load_modules
2380 if dm_flakey_supported $facet; then
2381 dm_dev=$(dm_create_dev $facet ${!dev})
2382 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2385 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2387 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2389 # import ZFS storage pool
2390 import_zpool $facet || return ${PIPESTATUS[0]}
2392 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2393 lustre:svname $dm_dev");;
2395 error "unknown fstype!";;
2398 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2399 # for testing LU-482 error handling in mount_facets() and test_0a()
2400 if [ -f $TMP/test-lu482-trigger ]; then
2403 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2404 (( $seq_width >= 16384 )) || seq_width=16384
2406 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2408 if [[ ${facet} =~ ost ]]; then
2409 do_facet ${facet} "$LCTL set_param \
2410 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2414 if [ $RC -ne 0 ]; then
2415 echo "Start of $dm_dev on ${facet} failed ${RC}"
2419 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2420 if [[ "$health" != "healthy" ]]; then
2421 error "$facet is in a unhealthy state"
2424 set_default_debug_facet $facet
2426 if [[ $opts =~ .*nosvc.* ]]; then
2427 echo "Start $dm_dev without service"
2432 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2433 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2434 "" || error "$dm_dev failed to initialize!";;
2436 wait_update_facet ${facet} "$ZFS get -H -o value \
2437 lustre:svname $dm_dev 2>/dev/null | \
2438 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2439 error "$dm_dev failed to initialize!";;
2442 error "unknown fstype!";;
2446 # commit the device label change to disk
2447 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2448 echo "Commit the device label on ${!dev}"
2449 do_facet $facet "sync; sleep 1; sync"
2453 label=$(devicelabel ${facet} $dm_dev)
2454 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2455 eval export ${facet}_svc=${label}
2456 echo Started ${label}
2458 export_dm_dev $facet $dm_dev
2463 # start facet device options
2469 local dev_alias=$(facet_device_alias $facet)
2471 eval export ${dev_alias}_dev=${device}
2472 eval export ${facet}_opt=\"$*\"
2474 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2475 eval export mgs_dev=${device}
2477 local varname=${dev_alias}failover_dev
2478 if [ -n "${!varname}" ] ; then
2479 eval export ${dev_alias}failover_dev=${!varname}
2481 eval export ${dev_alias}failover_dev=$device
2482 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2483 eval export mgsfailover_dev=${device}
2487 local mntpt=$(facet_mntpt $facet)
2488 do_facet ${facet} mkdir -p $mntpt
2489 eval export ${facet}_MOUNT=$mntpt
2490 mount_facet ${facet}
2500 local HOST=$(facet_active_host $facet)
2501 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2503 local mntpt=$(facet_mntpt $facet)
2504 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2505 if [ ${running} -ne 0 ]; then
2506 echo "Stopping $mntpt (opts:$*) on $HOST"
2507 do_facet ${facet} $UMOUNT "$@" $mntpt
2510 # umount should block, but we should wait for unrelated obd's
2511 # like the MGS or MGC to also stop.
2512 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2514 if [[ $(facet_fstype $facet) == zfs ]]; then
2515 # export ZFS storage pool
2516 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2517 elif dm_flakey_supported $facet; then
2518 local host=${facet}_HOST
2519 local failover_host=${facet}failover_HOST
2520 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2521 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2522 dm_cleanup_dev $facet
2527 # get mdt quota type
2529 local varsvc=${SINGLEMDS}_svc
2530 do_facet $SINGLEMDS $LCTL get_param -n \
2531 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2534 # get ost quota type
2536 # All OSTs should have same quota type
2537 local varsvc=ost1_svc
2538 do_facet ost1 $LCTL get_param -n \
2539 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2542 # restore old quota type settings
2544 for usr in $QUOTA_USERS; do
2545 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2547 cmd="$LFS setquota -$type $usr -b 0"
2548 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2550 eval $cmd || error "$cmd FAILED!"
2552 # display the quota status
2553 echo "Quota settings for $usr : "
2554 $LFS quota -v -u $usr $MOUNT || true
2556 if [ "$old_MDT_QUOTA_TYPE" ]; then
2557 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2558 do_facet mgs $PERM_CMD \
2559 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2562 do_facet mgs $PERM_CMD \
2563 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2566 if [ "$old_OST_QUOTA_TYPE" ]; then
2567 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2568 do_facet mgs $PERM_CMD \
2569 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2572 do_facet mgs $LCTL conf_param \
2573 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2578 # Handle the case when there is a space in the lfs df
2579 # "filesystem summary" line the same as when there is no space.
2580 # This will allow fixing the "lfs df" summary line in the future.
2582 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2583 check_lfs_df_ret_val ${PIPESTATUS[0]}
2586 # Get free inodes on the MDT specified by mdt index, free indoes on
2587 # the whole filesystem will be returned when index == -1.
2593 if [ $index -eq -1 ]; then
2596 mdt_uuid=$(mdtuuid_from_index $index)
2599 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2604 # Get the OST device status from 'lfs df' with a given OST index.
2608 local mnt_pnt=${2:-$MOUNT}
2612 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2613 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2619 # save old quota type & set new quota type
2620 local mdt_qtype=$(mdt_quota_type)
2621 local ost_qtype=$(ost_quota_type)
2623 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2624 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2626 export old_MDT_QUOTA_TYPE=$mdt_qtype
2627 export old_OST_QUOTA_TYPE=$ost_qtype
2629 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2630 do_facet mgs $PERM_CMD \
2631 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2632 do_facet mgs $PERM_CMD \
2633 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2635 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2636 error "set mdt quota type failed"
2637 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2638 error "set ost quota type failed"
2641 local quota_usrs=$QUOTA_USERS
2643 # get_filesystem_size
2644 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2645 local blk_soft=$((disksz + 1024))
2646 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2648 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2649 local i_soft=$inodes
2650 local i_hard=$((i_soft + i_soft / 20))
2652 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2653 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2654 "inode-hardlimit: $i_hard"
2657 for usr in $quota_usrs; do
2658 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2660 cmd="$LFS setquota -$type $usr -b $blk_soft"
2661 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2663 eval $cmd || error "$cmd FAILED!"
2665 # display the quota status
2666 echo "Quota settings for $usr : "
2667 $LFS quota -v -u $usr $mntpt || true
2674 local opts=${3:-$MOUNT_OPTS}
2675 opts=${opts:+-o $opts}
2676 local flags=${4:-$MOUNT_FLAGS}
2678 local device=$MGSNID:/$FSNAME$FILESET
2679 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2680 echo "Bad mount command: opt=$flags $opts dev=$device " \
2686 # update mount option with skpath
2687 opts=$(add_sk_mntflag $opts)
2690 echo "Starting client: $client: $flags $opts $device $mnt"
2691 do_node $client mkdir -p $mnt
2692 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2693 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2695 #disable FILESET if not supported
2696 do_nodes $client lctl get_param -n \
2697 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2698 device=$MGSNID:/$FSNAME
2699 do_node $client mkdir -p $mnt/$FILESET
2700 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2703 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2704 # Mount using nodemap key
2705 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2706 if $SK_UNIQUE_NM; then
2707 mountkey=$SK_PATH/nodemap/c0.key
2709 local prunedopts=$(echo $opts |
2710 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2711 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2714 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2718 set_default_debug_nodes $client
2719 set_params_clients $client
2730 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2732 [ "$3" ] && force=-f
2733 [ $running -eq 0 ] && return 0
2735 echo "Stopping client $client $mnt (opts:$force)"
2736 do_node $client lsof -t $mnt || need_kill=no
2737 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2738 pids=$(do_node $client lsof -t $mnt | sort -u);
2739 if [ -n "$pids" ]; then
2740 do_node $client kill -9 $pids || true
2744 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2746 if [ $busy -ne 0 ] ; then
2747 echo "$mnt is still busy, wait one second" && sleep 1
2748 do_node $client umount $force $mnt
2752 # Mount the file system on the MDS
2753 mount_mds_client() {
2754 local host=$(facet_active_host $SINGLEMDS)
2756 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2757 error "unable to mount $MOUNT2 on $host"
2760 # Unmount the file system on the MDS
2761 umount_mds_client() {
2762 local host=$(facet_active_host $SINGLEMDS)
2763 zconf_umount $host $MOUNT2
2764 do_facet $SINGLEMDS "rmdir $MOUNT2"
2767 # nodes is comma list
2768 sanity_mount_check_nodes () {
2774 # FIXME: assume that all cluster nodes run the same os
2775 [ "$(uname)" = Linux ] || return 0
2778 for mnt in $mnts ; do
2779 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2780 mpts=\\\$(mount | grep -c $mnt' ');
2781 if [ \\\$running -ne \\\$mpts ]; then
2782 echo \\\$(hostname) env are INSANE!;
2785 [ $? -eq 0 ] || rc=1
2790 sanity_mount_check_servers () {
2791 [ -n "$CLIENTONLY" ] &&
2792 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2793 echo Checking servers environments
2795 # FIXME: modify get_facets to display all facets wo params
2796 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2800 for facet in ${facets//,/ }; do
2801 node=$(facet_host ${facet})
2802 mntpt=$(facet_mntpt $facet)
2803 sanity_mount_check_nodes $node $mntpt ||
2804 { error "server $node environments are insane!"; return 1; }
2808 sanity_mount_check_clients () {
2809 local clients=${1:-$CLIENTS}
2810 local mntpt=${2:-$MOUNT}
2811 local mntpt2=${3:-$MOUNT2}
2813 [ -z $clients ] && clients=$(hostname)
2814 echo Checking clients $clients environments
2816 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2817 error "clients environments are insane!"
2820 sanity_mount_check () {
2821 sanity_mount_check_servers || return 1
2822 sanity_mount_check_clients || return 2
2825 # mount clients if not mouted
2826 zconf_mount_clients() {
2829 local opts=${3:-$MOUNT_OPTS}
2830 opts=${opts:+-o $opts}
2831 local flags=${4:-$MOUNT_FLAGS}
2832 local device=$MGSNID:/$FSNAME$FILESET
2833 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2834 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2839 echo "Starting client $clients: $flags $opts $device $mnt"
2840 do_nodes $clients mkdir -p $mnt
2841 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2842 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2843 # Mount with own nodemap key
2845 # Mount all server nodes first with per-NM keys
2846 for nmclient in ${clients//,/ }; do
2847 do_nodes $(comma_list $(all_server_nodes)) \
2848 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
2851 # set perms for per-nodemap keys else permission denied
2852 do_nodes $(comma_list $(all_nodes)) \
2853 "keyctl show | grep lustre | cut -c1-11 |
2855 xargs -IX keyctl setperm X 0x3f3f3f3f"
2856 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2858 for nmclient in ${clients//,/ }; do
2859 if $SK_UNIQUE_NM; then
2860 mountkey=$SK_PATH/nodemap/c$i.key
2862 do_node $nmclient "! grep -q $mnt' ' \
2863 /proc/mounts || umount $mnt"
2864 local prunedopts=$(add_sk_mntflag $opts);
2865 prunedopts=$(echo $prunedopts | sed -e \
2866 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2868 do_nodes $(comma_list $(all_server_nodes)) \
2871 do_node $nmclient $MOUNT_CMD $flags \
2872 $prunedopts $MGSNID:/$FSNAME $mnt ||
2877 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2879 do_nodes $clients $MOUNT_CMD $flags $opts \
2880 $MGSNID:/$FSNAME $mnt || return 1
2882 #disable FILESET if not supported
2883 do_nodes $clients lctl get_param -n \
2884 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2885 device=$MGSNID:/$FSNAME
2886 do_nodes $clients mkdir -p $mnt/$FILESET
2887 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2891 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2892 # Mount with nodemap key
2894 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2895 for nmclient in ${clients//,/ }; do
2896 if $SK_UNIQUE_NM; then
2897 mountkey=$SK_PATH/nodemap/c$i.key
2899 local prunedopts=$(echo $opts | sed -e \
2900 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2901 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2904 running=\\\$(mount | grep -c $mnt' ');
2906 if [ \\\$running -eq 0 ] ; then
2908 $MOUNT_CMD $flags $prunedopts $device $mnt;
2911 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2912 grep 'type lustre' | wc -l);
2913 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2914 echo zconf_mount_clients FAILED: \
2915 mount count \\\$running, not matching \
2916 with mount count of 'type lustre' \
2917 \\\$lustre_mnt_count;
2921 exit \\\$rc" || return ${PIPESTATUS[0]}
2928 if $SHARED_KEY; then
2929 tmpopts=$(add_sk_mntflag $opts)
2932 running=\\\$(mount | grep -c $mnt' ');
2934 if [ \\\$running -eq 0 ] ; then
2936 $MOUNT_CMD $flags $tmpopts $device $mnt;
2939 exit \\\$rc" || return ${PIPESTATUS[0]}
2942 echo "Started clients $clients: "
2943 do_nodes $clients "mount | grep $mnt' '"
2945 set_default_debug_nodes $clients
2946 set_params_clients $clients
2951 zconf_umount_clients() {
2956 [ "$3" ] && force=-f
2958 echo "Stopping clients: $clients $mnt (opts:$force)"
2959 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2960 if [ \\\$running -ne 0 ] ; then
2961 echo Stopping client \\\$(hostname) $mnt opts:$force;
2962 lsof $mnt || need_kill=no;
2963 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2964 pids=\\\$(lsof -t $mnt | sort -u);
2965 if [ -n \\\"\\\$pids\\\" ]; then
2969 while umount $force $mnt 2>&1 | grep -q "busy"; do
2970 echo "$mnt is still busy, wait one second" && sleep 1;
2978 echo + $POWER_DOWN $node
2982 shutdown_node_hard () {
2984 local attempts=$SHUTDOWN_ATTEMPTS
2986 for i in $(seq $attempts) ; do
2989 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
2991 echo "waiting for $host to fail attempts=$attempts"
2992 [ $i -lt $attempts ] ||
2993 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2999 local mnt=${2:-$MOUNT}
3002 if [ "$FAILURE_MODE" = HARD ]; then
3003 shutdown_node_hard $client
3005 zconf_umount_clients $client $mnt -f
3012 local facets="$(get_facets OST),$(get_facets MDS)"
3014 combined_mgs_mds || facets="$facets,mgs"
3016 for facet in ${facets//,/ }; do
3017 if [ $(facet_active_host $facet) == $host ]; then
3018 affected="$affected $facet"
3022 echo $(comma_list $affected)
3027 local host=${2:-$(facet_host $facet)}
3029 local label=$(convert_facet2label $facet)
3030 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
3033 facets_up_on_host () {
3036 local facets=$(facets_on_host $host)
3038 for facet in ${facets//,/ }; do
3039 if $(facet_up $facet $host); then
3040 affected_up="$affected_up $facet"
3044 echo $(comma_list $affected_up)
3049 local affected_facet
3050 local affected_facets
3052 if [[ "$FAILURE_MODE" = HARD ]]; then
3053 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
3054 dm_flakey_supported $facet; then
3055 affected_facets=$(affected_facets $facet)
3056 for affected_facet in ${affected_facets//,/ }; do
3057 unexport_dm_dev $affected_facet
3061 shutdown_node_hard $(facet_active_host $facet)
3070 echo + $POWER_UP $node
3083 local node=$(facet_active_host $facet)
3084 local sleep_time=${2:-10}
3086 if [ "$FAILURE_MODE" = HARD ]; then
3096 if [ "$FAILURE_MODE" = HARD ]; then
3099 if $LOAD_MODULES_REMOTE; then
3100 echo "loading modules on $node: $facet"
3101 do_rpc_nodes $node load_modules_local
3110 for facet in ${facets//,/ }; do
3111 hosts=$(expand_list $hosts $(facet_host $facet) )
3117 _check_progs_installed () {
3121 for prog in $progs; do
3122 if ! [ "$(which $prog)" -o "${!prog}" ]; then
3123 echo $prog missing on $(hostname)
3130 check_progs_installed () {
3134 do_rpc_nodes "$nodes" _check_progs_installed "$@"
3137 # recovery-scale functions
3139 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
3142 start_client_load() {
3145 local var=$(node_var_name $client)_load
3146 eval export ${var}=$load
3148 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
3149 BREAK_ON_ERROR=$BREAK_ON_ERROR \
3150 END_RUN_FILE=$END_RUN_FILE \
3151 LOAD_PID_FILE=$LOAD_PID_FILE \
3152 TESTLOG_PREFIX=$TESTLOG_PREFIX \
3153 TESTNAME=$TESTNAME \
3154 DBENCH_LIB=$DBENCH_LIB \
3155 DBENCH_SRC=$DBENCH_SRC \
3156 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
3161 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
3162 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
3163 num_clients=$(get_node_count ${CLIENTS//,/ }) \
3164 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
3165 ior_blockSize=$ior_blockSize \
3166 ior_blockUnit=$ior_blockUnit \
3167 ior_xferSize=$ior_xferSize ior_type=$ior_type \
3168 ior_DURATION=$ior_DURATION \
3169 ior_stripe_params=\\\"$ior_stripe_params\\\" \
3170 ior_custom_params=\\\"$ior_custom_param\\\" \
3171 mpi_ior_custom_threads=$mpi_ior_custom_threads \
3174 log "Started client load: ${load} on $client"
3176 # get the children process IDs
3177 local pids=$(ps --ppid $ppid -o pid= | xargs)
3178 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
3182 start_client_loads () {
3183 local -a clients=(${1//,/ })
3184 local numloads=${#CLIENT_LOADS[@]}
3186 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
3187 local load=$((nodenum % numloads))
3188 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
3190 # bug 22169: wait the background threads to start
3194 # only for remote client
3195 check_client_load () {
3197 local var=$(node_var_name $client)_load
3198 local testload=run_${!var}.sh
3200 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
3202 # bug 18914: try to connect several times not only when
3203 # check ps, but while check_node_health also
3207 while [ $RC = 254 -a $tries -gt 0 ]; do
3211 if ! check_node_health $client; then
3213 if [ $RC -eq 254 ]; then
3214 # FIXME: not sure how long we shuold sleep here
3218 echo "check node health failed: RC=$RC "
3222 # We can continue try to connect if RC=254
3223 # Just print the warning about this
3224 if [ $RC = 254 ]; then
3225 echo "got a return status of $RC from do_node while checking " \
3226 "node health on $client"
3229 # see if the load is still on the client
3232 while [ $RC = 254 -a $tries -gt 0 ]; do
3236 if ! do_node $client \
3237 "ps auxwww | grep -v grep | grep -q $testload"; then
3242 if [ $RC = 254 ]; then
3243 echo "got a return status of $RC from do_node while checking " \
3244 "(node health and 'ps') the client load on $client"
3245 # see if we can diagnose a bit why this is
3250 check_client_loads () {
3251 local clients=${1//,/ }
3255 for client in $clients; do
3256 check_client_load $client
3258 if [ "$rc" != 0 ]; then
3259 log "Client load failed on node $client, rc=$rc"
3265 restart_client_loads () {
3266 local clients=${1//,/ }
3267 local expectedfail=${2:-""}
3271 for client in $clients; do
3272 check_client_load $client
3274 if [ "$rc" != 0 -a "$expectedfail" ]; then
3275 local var=$(node_var_name $client)_load
3277 start_client_load $client ${!var}
3278 echo "Restarted client load ${!var}: on $client. Checking ..."
3279 check_client_load $client
3281 if [ "$rc" != 0 ]; then
3282 log "Client load failed to restart on node $client, rc=$rc"
3283 # failure one client load means test fail
3284 # we do not need to check other
3293 # Start vmstat and save its process ID in a file.
3298 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3301 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3302 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3305 # Display the nodes on which client loads failed.
3306 print_end_run_file() {
3310 [ -s $file ] || return 0
3312 echo "Found the END_RUN_FILE file: $file"
3315 # A client load will stop if it finds the END_RUN_FILE file.
3316 # That does not mean the client load actually failed though.
3317 # The first node in END_RUN_FILE is the one we are interested in.
3320 if [ -n "$node" ]; then
3321 local var=$(node_var_name $node)_load
3323 local prefix=$TESTLOG_PREFIX
3324 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3325 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3326 local debug_log=$(echo $stdout_log |
3327 sed 's/\(.*\)stdout/\1debug/')
3329 echo "Client load ${!var} failed on node $node:"
3335 # Stop the process which had its PID saved in a file.
3340 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3342 do_nodes $nodes "test -f $pid_file &&
3343 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3346 # Stop all client loads.
3347 stop_client_loads() {
3348 local nodes=${1:-$CLIENTS}
3351 # stop the client loads
3352 stop_process $nodes $pid_file
3354 # clean up the processes that started them
3355 [ -n "$CLIENT_LOAD_PIDS" ] &&
3356 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3358 # End recovery-scale functions
3361 # wait for a command to return the expected result
3363 # This will run @check on @node repeatedly until the output matches @expect
3364 # based on the supplied condition, or until @max_wait seconds have elapsed,
3365 # whichever comes first. @cond may be one of the normal bash operators,
3366 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3367 # in the caller to avoid unintentional evaluation by the shell in the caller.
3369 # If @max_wait is not specified, the condition will be checked for up to 90s.
3371 # If --verbose is passed as the first argument, the result is printed on each
3372 # value change, otherwise it is only printed after every 10s interval.
3374 # If --quiet is passed as the first/second argument, the do_node() command
3375 # will not print the remote command before executing it each time.
3377 # Using wait_update_cond() or related helper function is preferable to adding
3378 # a "long enough" wait for some state to change in the background, since
3379 # "long enough" may be too short due to tunables, system config, or running in
3380 # a VM, and must by necessity wait too long for most cases or risk failure.
3382 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3383 wait_update_cond() {
3387 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3388 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3394 local max_wait=${5:-90}
3398 local begin=$SECONDS
3402 while (( $waited <= $max_wait )); do
3403 result=$(do_node $quiet $node "$check")
3405 eval [[ "'$result'" $cond "'$expect'" ]]
3406 if [[ $? == 0 ]]; then
3407 [[ -n "$quiet" ]] && return 0
3408 [[ -z "$result" || $waited -le $sleep ]] ||
3409 echo "Updated after ${waited}s: want '$expect' got '$result'"
3412 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3413 [[ -z "$quiet" && -n "$prev_result" ]] &&
3414 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3415 prev_result="$result"
3417 (( $waited % $print == 0 )) && {
3418 [[ -z "$quiet" ]] &&
3419 echo "Waiting $((max_wait - waited))s for '$expect'"
3423 waited=$((SECONDS - begin))
3426 [[ -z "$quiet" ]] &&
3427 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3432 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3437 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3438 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3445 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3448 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3449 wait_update_facet_cond() {
3453 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3454 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3456 local node=$(facet_active_host $1)
3462 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3465 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3466 wait_update_facet() {
3470 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3471 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3473 local node=$(facet_active_host $1)
3478 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3482 do_nodes $(comma_list $(mdts_nodes)) \
3483 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3484 do_nodes $(comma_list $(osts_nodes)) \
3485 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3486 grep -v 'Found no match'
3490 local zfs_wait=${2:-5}
3492 # the occupied disk space will be released
3493 # only after TXGs are committed
3494 if [[ $(facet_fstype $1) == zfs ]]; then
3495 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3503 local lwm=$3 #low watermark
3504 local size_mb #how many MB should we write to pass watermark
3505 local ost_name=$(ostname_from_index $ost_idx)
3507 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3509 if (( $free_kb / 1024 > lwm )); then
3510 size_mb=$((free_kb / 1024 - lwm))
3512 #If 10% of free space cross low watermark use it
3513 if (( $free_kb / 10240 > size_mb )); then
3514 size_mb=$((free_kb / 10240))
3516 #At least we need to store 1.1 of difference between
3517 #free space and low watermark
3518 size_mb=$((size_mb + size_mb / 10))
3520 if (( lwm <= $free_kb / 1024 )) ||
3521 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3522 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3523 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3524 count=$size_mb oflag=append conv=notrunc
3529 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3530 echo "OST still has $((free_kb / 1024)) MB free"
3533 # This checks only the primary MDS
3534 ost_watermarks_get() {
3536 local ost_name=$(ostname_from_index $ost_idx)
3537 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3539 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3540 osp.$mdtosc_proc.reserved_mb_high)
3541 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3542 osp.$mdtosc_proc.reserved_mb_low)
3547 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3548 ost_watermarks_set() {
3552 local ost_name=$(ostname_from_index $ost_idx)
3553 local facets=$(get_facets MDS)
3555 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3556 osp.*$ost_name*.reserved_mb_low=$lwm \
3557 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3559 # sleep to ensure we see the change
3563 ost_watermarks_set_low_space() {
3565 local wms=$(ost_watermarks_get $ost_idx)
3566 local ost_name=$(ostname_from_index $ost_idx)
3568 local old_lwm=$(echo $wms | awk '{ print $1 }')
3569 local old_hwm=$(echo $wms | awk '{ print $2 }')
3571 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3572 # minimal extension size is 64M
3574 if (( $blocks / 1024 > 50 )); then
3575 new_lwm=$((blocks / 1024 - 50))
3577 local new_hwm=$((new_lwm + 5))
3579 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3580 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3583 # Set watermarks to ~current available space & then write data to fill it
3584 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3585 # internal statfs used by the stripe allocator
3587 # first parameter is the filename-prefix, which must get under t-f cleanup
3588 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3589 ost_watermarks_set_enospc() {
3593 local ost_name=$(ostname_from_index $ost_idx)
3594 local facets=$(get_facets MDS)
3598 for MDS in ${facets//,/ }; do
3599 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3601 do_facet $MDS $LCTL get_param -n \
3602 osp.$mdtosc_proc.reserved_mb_high ||
3603 skip "remote MDS does not support reserved_mb_high"
3606 wms=$(ost_watermarks_set_low_space $ost_idx)
3607 local new_lwm=$(echo $wms | awk '{ print $4 }')
3608 fill_ost $filename $ost_idx $new_lwm
3609 #First enospc could execute orphan deletion so repeat
3610 fill_ost $filename $ost_idx $new_lwm
3614 ost_watermarks_enospc_delete_files() {
3618 rm -f $DIR/${filename}.fill_ost$ost_idx
3620 wait_delete_completed
3624 # clean up from "ost_watermarks_set_enospc"
3625 ost_watermarks_clear_enospc() {
3631 ost_watermarks_enospc_delete_files $filename $ost_idx
3632 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3633 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3636 wait_delete_completed_mds() {
3637 local max_wait=${1:-20}
3639 local stime=$(date +%s)
3644 # find MDS with pending deletions
3645 for node in $(mdts_nodes); do
3646 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3647 2>/dev/null | calc_sum)
3648 if [[ $changes -eq 0 ]]; then
3651 mds2sync="$mds2sync $node"
3653 if [ -z "$mds2sync" ]; then
3654 wait_zfs_commit $SINGLEMDS
3657 mds2sync=$(comma_list $mds2sync)
3659 # sync MDS transactions
3660 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3662 # wait till all changes are sent and commmitted by OSTs
3663 # for ldiskfs space is released upon execution, but DMU
3664 # do this upon commit
3667 while [[ $WAIT -ne $max_wait ]]; do
3668 changes=$(do_nodes $mds2sync \
3669 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3670 #echo "$node: $changes changes on all"
3671 if [[ $changes -eq 0 ]]; then
3672 wait_zfs_commit $SINGLEMDS
3674 # the occupied disk space will be released
3675 # only after TXGs are committed
3676 wait_zfs_commit ost1
3684 echo "Delete is not completed in $((etime - stime)) seconds"
3685 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3692 # we can use "for" here because we are waiting the slowest
3693 for host in ${hostlist//,/ }; do
3694 check_network "$host" 900
3696 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3703 for facet in ${facetlist//,/ }; do
3704 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3706 wait_for_host $hostlist
3709 _wait_recovery_complete () {
3712 # Use default policy if $2 is not passed by caller.
3713 local MAX=${2:-$(max_recovery_time)}
3718 while [ $WAIT -lt $MAX ]; do
3719 STATUS=$(lctl get_param -n $param | grep status)
3721 [[ $STATUS == "status: COMPLETE" ||
3722 $STATUS == "status: INACTIVE" ]] && return 0
3725 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3727 echo "$param recovery not done in $MAX sec. $STATUS"
3731 wait_recovery_complete () {
3734 # with an assumption that at_max is the same on all nodes
3735 local MAX=${2:-$(max_recovery_time)}
3738 if [ "$FAILURE_MODE" = HARD ]; then
3739 facets=$(facets_on_host $(facet_active_host $facet))
3741 echo affected facets: $facets
3743 facets=${facets//,/ }
3744 # We can use "for" here because we are waiting the slowest.
3745 # The mgs not having the recovery_status proc entry, exclude it
3746 # from the facet list.
3747 for facet in ${facets//mgs/ }; do
3748 local var_svc=${facet}_svc
3749 local param="*.${!var_svc}.recovery_status"
3751 local host=$(facet_active_host $facet)
3752 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3756 wait_mds_ost_sync () {
3757 # just because recovery is done doesn't mean we've finished
3758 # orphan cleanup. Wait for llogs to get synchronized.
3759 echo "Waiting for orphan cleanup..."
3760 # MAX value includes time needed for MDS-OST reconnection
3761 local MAX=$(( TIMEOUT * 2 ))
3762 local WAIT_TIMEOUT=${1:-$MAX}
3765 local list=$(comma_list $(mdts_nodes))
3766 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3767 if ! do_facet $SINGLEMDS \
3768 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3770 # old way, use mds_sync
3772 list=$(comma_list $(osts_nodes))
3773 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3776 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3777 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3778 local -a sync=($(do_nodes $list "$cmd"))
3781 for ((i=0; i<${#sync[@]}; i++)); do
3783 [ ${sync[$i]} -eq 1 ] && continue
3785 [ ${sync[$i]} -eq 0 ] && continue
3787 # there is a not finished MDS-OST synchronization
3791 sleep 2 # increase waiting time and cover statfs cache
3792 [ ${con} -eq 1 ] && return 0
3793 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3797 # show which nodes are not finished.
3798 cmd=$(echo $cmd | sed 's/-n//')
3799 do_nodes $list "$cmd"
3800 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3804 # Wait OSTs to be active on both client and MDT side.
3806 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3807 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3808 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3809 error "wait_update OSTs up on client failed"
3811 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3812 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3813 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3814 error "wait_update OSTs up on MDT0000 failed"
3817 wait_destroy_complete () {
3818 echo "Waiting for MDT destroys to complete"
3819 # MAX value shouldn't be big as this mean server responsiveness
3820 # never increase this just to make test pass but investigate
3821 # why it takes so long time
3824 local list=$(comma_list $(mdts_nodes))
3825 while [ $WAIT -lt $MAX ]; do
3826 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3830 for ((i=0; i<${#RPCs[@]}; i++)); do
3831 [ ${RPCs[$i]} -eq 0 ] && continue
3832 # there are still some destroy RPCs in flight
3836 [ ${con} -eq 1 ] && return 0 # done waiting
3838 echo "Waiting ${WAIT}s for local destroys to complete"
3841 echo "MDT destroys weren't done in $MAX sec."
3845 wait_delete_completed() {
3846 wait_delete_completed_mds $1 || return $?
3847 wait_destroy_complete || return $?
3856 # conf-sanity 31 takes a long time cleanup
3857 while [ $WAIT -lt 300 ]; do
3858 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3859 lctl dl | grep ' ST ' || true")
3860 [ -z "${running}" ] && return 0
3861 echo "waited $WAIT for${running}"
3862 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3864 WAIT=$((WAIT + INTERVAL))
3866 echo "service didn't stop after $WAIT seconds. Still running:"
3871 wait_remote_prog () {
3877 [ "$PDSH" = "no_dsh" ] && return 0
3879 while [ $WAIT -lt $2 ]; do
3880 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3881 grep -v grep) || true
3882 [ -z "${running}" ] && return 0 || true
3883 echo "waited $WAIT for: "
3885 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3887 WAIT=$((WAIT + INTERVAL))
3889 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3890 grep -v grep | awk '{print $2}')
3891 [ -z "$pids" ] && return 0
3892 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3893 # FIXME: not portable
3894 for pid in $pids; do
3895 cat /proc/${pid}/status || true
3896 cat /proc/${pid}/wchan || true
3898 kill -9 $pid || true
3907 local clients=${1:-$CLIENTS}
3910 if [[ -z "$clients" ]]; then
3911 $LFS df $MOUNT > /dev/null || rc=$?
3913 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3920 local clients=${1:-$CLIENTS}
3923 _lfs_df_check "$clients" || rc=$?
3925 check_lfs_df_ret_val $rc
3929 # not every config has many clients
3935 (( MDSCOUNT == 1 )) && return
3937 # wait so that statfs data on MDT expire
3938 local delay=$(do_facet mds1 $LCTL \
3939 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3941 [ -n "$delay" ] || error "fail to get maxage"
3943 local nodes=$(comma_list $(mdts_nodes))
3944 # initiate statfs RPC, all to all MDTs
3945 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3946 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3950 # usually checked on particular client or locally
3960 client_reconnect_try() {
3961 local f=$MOUNT/recon
3964 if [ -z "$CLIENTS" ]; then
3965 $LFS df $MOUNT; uname -n >> $f
3967 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3969 echo "Connected clients: $(cat $f)"
3970 ls -l $f > /dev/null
3974 client_reconnect() {
3975 # one client_reconnect_try call does not always do the job...
3977 client_reconnect_try && break
3982 affected_facets () {
3985 local host=$(facet_active_host $facet)
3986 local affected=$facet
3988 if [ "$FAILURE_MODE" = HARD ]; then
3989 affected=$(facets_up_on_host $host)
3995 local E2FSCK_ON_MDT0=false
3996 if [ "$1" == "--fsck" ]; then
3998 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4010 #Because it will only get up facets, we need get affected
4011 #facets before shutdown
4012 #For HARD Failure mode, it needs make sure facets on the same
4013 #HOST will only be shutdown and reboot once
4014 for facet in ${facets//,/ }; do
4015 local affected_facet
4017 #check whether facet has been included in other affected facets
4018 for ((index=0; index<$total; index++)); do
4019 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
4022 if [ $skip -eq 0 ]; then
4023 affecteds[$total]=$(affected_facets $facet)
4028 for ((index=0; index<$total; index++)); do
4029 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
4030 local host=$(facet_active_host $facet)
4031 echo "Failing ${affecteds[index]} on $host"
4032 shutdown_facet $facet
4035 echo "$(date +'%H:%M:%S (%s)') shut down"
4040 for facet in ${facets//,/ }; do
4041 local host=$(facet_active_host $facet)
4043 hostlist=$(expand_list $hostlist $host)
4044 if [ $(facet_host $facet) = \
4045 $(facet_failover_host $facet) ]; then
4046 waithostlist=$(expand_list $waithostlist $host)
4050 if [ "$FAILURE_MODE" = HARD ]; then
4051 for host in ${hostlist//,/ }; do
4054 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
4055 # We need to wait the rebooted hosts in case if
4056 # facet_HOST == facetfailover_HOST
4057 if ! [ -z "$waithostlist" ]; then
4058 wait_for_host $waithostlist
4059 if $LOAD_MODULES_REMOTE; then
4060 echo "loading modules on $waithostlist"
4061 do_rpc_nodes $waithostlist load_modules_local
4068 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
4069 change_active $SINGLEMDS
4072 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
4073 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
4077 for ((index=0; index<$total; index++)); do
4078 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
4079 change_active ${affecteds[index]}
4083 init_facets_vars_simple
4085 # start mgs first if it is affected
4086 if ! combined_mgs_mds &&
4087 list_member ${affecteds[index]} mgs; then
4088 mount_facet mgs || error "Restart of mgs failed"
4089 affecteds[index]=$(exclude_items_from_list \
4090 ${affecteds[index]} mgs)
4092 if [ -n "${affecteds[index]}" ]; then
4093 echo mount facets: ${affecteds[index]}
4094 mount_facets ${affecteds[index]} &
4098 for ((index=0; index<$total; index++)); do
4099 if [ -n "${affecteds[index]}" ]; then
4100 wait ${mountpids[index]}
4104 do_nodes $(comma_list $(all_nodes)) \
4105 "keyctl show | grep lustre | cut -c1-11 |
4107 xargs -IX keyctl setperm X 0x3f3f3f3f"
4110 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
4112 if [ "$FAILURE_MODE" = HARD ]; then
4113 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
4114 if ! [ -z "$hostlist" ]; then
4115 wait_for_host $hostlist
4116 if $LOAD_MODULES_REMOTE; then
4117 echo "loading modules on $hostlist"
4118 do_rpc_nodes $hostlist load_modules_local
4123 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
4128 do_facet $facet "sync; sync; sync"
4131 # make sure there will be no seq change
4132 local clients=${CLIENTS:-$HOSTNAME}
4133 local f=fsa-\\\$\(hostname\)
4134 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
4135 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
4137 local svc=${facet}_svc
4138 do_facet $facet $LCTL --device ${!svc} notransno
4140 # If a ZFS OSD is made read-only here, its pool is "freezed". This
4141 # in-memory state has to be cleared by either rebooting the host or
4142 # exporting and reimporting the pool.
4144 # Although the uberblocks are not updated when a pool is freezed,
4145 # transactions are still written to the disks. Modified blocks may be
4146 # cached in memory when tests try reading them back. The
4147 # export-and-reimport process also evicts any cached pool data from
4148 # memory to provide the correct "data loss" semantics.
4150 # In the test framework, the exporting and importing operations are
4151 # handled by stop() and mount_facet() separately, which are used
4152 # inside fail() and fail_abort().
4154 set_dev_readonly $facet
4155 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4156 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4159 replay_barrier_nodf() {
4160 local facet=$1 echo running=${running}
4161 do_facet $facet "sync; sync; sync"
4162 local svc=${facet}_svc
4163 echo Replay barrier on ${!svc}
4164 do_facet $facet $LCTL --device ${!svc} notransno
4165 set_dev_readonly $facet
4166 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4167 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4170 replay_barrier_nosync() {
4171 local facet=$1 echo running=${running}
4172 local svc=${facet}_svc
4173 echo Replay barrier on ${!svc}
4174 do_facet $facet $LCTL --device ${!svc} notransno
4175 set_dev_readonly $facet
4176 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4177 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4181 # Get Lustre client uuid for a given Lustre mount point.
4184 local mntpnt=${1:-$MOUNT}
4186 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
4187 local uuid=$($LCTL get_param -n llite.$name.uuid)
4192 mds_evict_client() {
4193 local mntpnt=${1:-$MOUNT}
4194 local uuid=$(get_client_uuid $mntpnt)
4196 do_facet $SINGLEMDS \
4197 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
4200 ost_evict_client() {
4201 local mntpnt=${1:-$MOUNT}
4202 local uuid=$(get_client_uuid $mntpnt)
4205 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
4210 local clients=${CLIENTS:-$HOSTNAME}
4212 SK_NO_KEY_save=$SK_NO_KEY
4214 export SK_NO_KEY=false
4216 facet_failover $* || error "failover: $?"
4217 export SK_NO_KEY=$SK_NO_KEY_save
4218 # to initiate all OSC idling connections
4220 wait_clients_import_ready "$clients" "$facets"
4221 clients_up || error "post-failover stat: $?"
4227 facet_failover $facet
4232 local abort_type=${2:-"abort_recovery"}
4235 change_active $facet
4236 wait_for_facet $facet
4237 mount_facet $facet -o $abort_type
4238 clients_up || echo "first stat failed: $?"
4239 clients_up || error "post-failover stat: $?"
4243 # LU-16159: abort recovery will cancel update logs, which may leave broken
4244 # directories in the system, remove name entry if necessary
4245 fail_abort_cleanup() {
4247 find $DIR/$tdir -depth | while read D; do
4248 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
4252 host_nids_address() {
4256 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
4260 if [ "$1" = "'*'" ]; then echo \'*\'; else
4266 if [[ -n "$NETTYPE" ]]; then
4267 h2name_or_ip "$1" "$NETTYPE"
4269 h2name_or_ip "$1" "$2"
4272 declare -fx h2nettype
4274 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4275 # expressions format. As a bonus we can then just pass in those variables
4276 # to pdsh. What this function does is take a HOSTLIST type string and
4277 # expand it into a space deliminated list for us.
4285 [ -z "$hostlist" ] && return
4287 # Translate the case of [..],..,[..] to [..] .. [..]
4288 list="${hostlist/],/] }"
4290 [[ "$front" == *,* ]] && {
4293 list=${list/${old}/${new}}
4296 for item in $list; do
4297 # Test if we have any []'s at all
4298 if [ "$item" != "${item/\[/}" ]; then {
4299 # Expand the [*] into list
4303 if [ "$name" != "$item" ]; then
4304 group=${item#$name[*}
4307 for range in ${group//,/ }; do
4313 # Number of leading zeros
4316 end=$(echo $end | sed 's/0*//')
4317 [[ -z "$end" ]] && end=0
4318 [[ $padlen2 -gt $padlen ]] && {
4319 [[ $padlen2 -eq ${#end} ]] &&
4323 begin=$(echo $begin | sed 's/0*//')
4324 [ -z $begin ] && begin=0
4326 if [ ! -z "${begin##[!0-9]*}" ]; then
4327 order=$(seq -f "%0${padlen}g" $begin $end)
4329 order=$(eval echo {$begin..$end});
4332 for num in $order; do
4333 value="${name#*,}${num}${back}"
4335 [ "$value" != "${value/\[/}" ] && {
4336 value=$(hostlist_expand "$value")
4338 myList="$myList $value"
4343 myList="$myList $item"
4346 myList=${myList//,/ }
4347 myList=${myList:1} # Remove first character which is a space
4349 # Filter any duplicates without sorting
4351 myList="${list%% *}"
4353 while [[ "$list" != ${myList##* } ]]; do
4354 local tlist=" $list"
4356 list=${tlist// ${list%% *} / }
4358 myList="$myList ${list%% *}"
4360 myList="${myList%* }";
4362 # We can select an object at an offset in the list
4365 for item in $myList; do
4367 [ $cnt -eq $offset ] && {
4371 [ $(get_node_count $myList) -ne 1 ] && myList=""
4380 [ "$facet" == client ] && echo -n $HOSTNAME && return
4381 varname=${facet}_HOST
4382 if [ -z "${!varname}" ]; then
4383 if [ "${facet:0:3}" == "ost" ]; then
4384 local fh=${facet%failover}_HOST
4385 eval export ${facet}_HOST=${!fh}
4386 if [ -z "${!varname}" ]; then
4387 eval export ${facet}_HOST=${ost_HOST}
4389 elif [ "${facet:0:3}" == "mdt" -o \
4390 "${facet:0:3}" == "mds" -o \
4391 "${facet:0:3}" == "mgs" ]; then
4393 if [ "${facet}" == "mgsfailover" ] &&
4394 [ -n "$mds1failover_HOST" ]; then
4395 temp=$mds1failover_HOST
4399 eval export ${facet}_HOST=$temp
4405 facet_failover_host() {
4409 var=${facet}failover_HOST
4410 if [ -n "${!var}" ]; then
4415 if combined_mgs_mds && [ $facet == "mgs" ] &&
4416 [ -n "$mds1failover_HOST" ]; then
4417 echo $mds1failover_HOST
4421 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4422 "${facet:0:3}" == "mgs" ]; then
4424 eval export ${facet}failover_host=${mds_HOST}
4429 if [[ $facet == ost* ]]; then
4430 eval export ${facet}failover_host=${ost_HOST}
4438 local activevar=${facet}active
4440 if [ -f $TMP/${facet}active ] ; then
4441 source $TMP/${facet}active
4444 active=${!activevar}
4445 if [ -z "$active" ] ; then
4452 facet_active_host() {
4453 facet_host $(facet_active $1)
4456 # Get the passive failover partner host of facet.
4457 facet_passive_host() {
4459 [[ $facet = client ]] && return
4461 local host=${facet}_HOST
4462 local failover_host=${facet}failover_HOST
4463 local active_host=$(facet_active_host $facet)
4465 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4467 if [[ $active_host = ${!host} ]]; then
4468 echo -n ${!failover_host}
4478 for facet in ${facetlist//,/ }; do
4479 local failover=${facet}failover
4480 local host=`facet_host $failover`
4482 [ -z "$host" ] && return
4484 local curactive=`facet_active $facet`
4486 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4487 eval export ${facet}active=$facet
4489 eval export ${facet}active=$failover
4491 # save the active host for this facet
4492 local activevar=${facet}active
4494 echo "$activevar=${!activevar}" > $TMP/$activevar
4495 [[ $facet = mds1 ]] && combined_mgs_mds && \
4496 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4497 local TO=`facet_active_host $facet`
4498 echo "Failover $facet to $TO"
4506 # do not strip off hostname if verbose, b=19215
4507 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4508 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4514 if [ "$HOST" = "$HOSTNAME" ]; then
4516 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4517 echo "cannot run remote command on $HOST with $myPDSH"
4520 if $VERBOSE && [[ -z "$quiet" ]]; then
4521 echo "CMD: $HOST $*" >&2
4522 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4525 if [[ "$myPDSH" == "rsh" ]] ||
4526 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4527 # we need this because rsh and pdsh do not return
4528 # exit code of an executed command
4529 local command_status="$TMP/cs"
4530 eval $myPDSH $HOST ":> $command_status"
4531 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4532 PATH=\$PATH:/sbin:/usr/sbin;
4534 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4535 echo command failed >$command_status"
4536 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4540 if [[ -n "$verbose" ]]; then
4541 # print HOSTNAME for myPDSH="no_dsh"
4542 if [[ $myPDSH = no_dsh ]]; then
4544 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4545 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4546 sed -e "s/^/${HOSTNAME}: /"
4549 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4550 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4554 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4555 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4556 sed "s/^${HOST}: //"
4558 return ${PIPESTATUS[0]}
4562 # Execute exact command line on host
4564 # The \a host may be on a local or remote node, which is determined at
4565 # the time the command is run. Does careful argument quotation to
4566 # ensure that the exact command line is executed without any globbing,
4567 # substitution, or shell interpretation on the remote side. Does not
4568 # support --verbose or --quiet. Does not include "$host: " prefixes on
4569 # output. See also do_facet_vp().
4571 # usage: do_node_vp "$host" "$command" "$arg"...
4576 if [[ "$host" == "$HOSTNAME" ]]; then
4577 bash -c "$(printf -- ' %q' "$@")"
4581 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4582 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4586 # -N Disable hostname: prefix on lines of output.
4588 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4591 single_local_node () {
4592 [ "$1" = "$HOSTNAME" ]
4595 # Outputs environment variable assignments that should be passed to remote nodes
4599 local facets=$(get_facets)
4602 for var in ${!MODOPTS_*}; do
4603 value=${!var//\"/\\\"}
4604 echo -n " ${var}=\"$value\""
4607 for facet in ${facets//,/ }; do
4609 if [ -n "${!var}" ]; then
4610 echo -n " $var=${!var}"
4614 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4615 if [ -n "${!var}" ]; then
4616 echo -n " $var=${!var}"
4620 for var in VERBOSE; do
4621 if [ -n "${!var}" ]; then
4622 echo -n " $var=${!var}"
4626 if [ -n "$FSTYPE" ]; then
4627 echo -n " FSTYPE=$FSTYPE"
4630 for var in LNETLND NETTYPE; do
4631 if [ -n "${!var}" ]; then
4632 echo -n " $var=${!var}"
4641 # do not strip off hostname if verbose, b=19215
4642 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4643 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4648 if single_local_node $rnodes; then
4649 do_node $verbose $quiet $rnodes "$@"
4653 # This is part from do_node
4656 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4657 echo "cannot run remote command on $rnodes with $myPDSH" &&
4660 export FANOUT=$(get_node_count "${rnodes//,/ }")
4661 if $VERBOSE && [[ -z "$quiet" ]]; then
4662 echo "CMD: $rnodes $*" >&2
4663 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4666 # do not replace anything from pdsh output if -N is used
4667 # -N Disable hostname: prefix on lines of output.
4668 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4669 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4671 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4673 return ${PIPESTATUS[0]}
4677 # Execute commands on a single service's host
4679 # The \a facet (service) may be on a local or remote node, which is
4680 # determined at the time the command is run.
4682 # usage: do_facet $facet command [arg ...]
4687 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4688 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4692 local host=$(facet_active_host $facet)
4694 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4695 do_node $verbose $quiet $host "$@"
4699 # Execute exact command line on the host of a facet
4701 # The \a facet (service) may be on a local or remote node, which is
4702 # determined at the time the command is run. Does careful argument
4703 # quotation to ensure that the exact command line is executed without
4704 # any globbing, substitution, or shell interpretation on the remote
4705 # side. Does not support --verbose or --quiet. Does not include
4706 # "$host: " prefixes on output.
4708 # usage: do_facet_vp "$facet" "$command" "$arg"...
4711 local host=$(facet_active_host "$facet")
4714 if [[ -z "$host" ]]; then
4715 echo "no host defined for facet ${facet}" >&2
4719 do_node_vp "$host" "$@"
4722 # Function: do_facet_random_file $FACET $FILE $SIZE
4723 # Creates FILE with random content on the given FACET of given SIZE
4725 do_facet_random_file() {
4729 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4730 do_facet $facet "$cmd 2>/dev/null"
4733 do_facet_create_file() {
4737 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4738 do_facet $facet "$cmd 2>/dev/null"
4742 do_nodes --verbose "$@"
4748 # make sure its not already running
4750 rm -f $TMP/${facet}active
4751 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4753 # make sure in-tree ldiskfs is loaded before mkfs
4754 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4755 load_module ../ldiskfs/ldiskfs
4758 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4760 if [[ $(facet_fstype $facet) == zfs ]]; then
4762 # After formatting a ZFS target, "cachefile=none" property will
4763 # be set on the ZFS storage pool so that the pool is not
4764 # automatically imported on system startup. And then the pool
4765 # will be exported so as to leave the importing and exporting
4766 # operations handled by mount_facet() and stop() separately.
4768 refresh_partition_table $facet $(facet_vdevice $facet)
4769 disable_zpool_cache $facet
4774 # Device formatted as ost
4777 local DEVNAME=OSTDEV$num
4779 local fstype=$(facet_fstype ost$num)
4783 local dev=ost${num}_dev
4784 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4785 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4786 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4788 #try $OSTZFSDEVn - independent of vdev
4789 DEVNAME=OSTZFSDEV$num
4790 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4792 error "unknown fstype!";;
4798 # Physical device location of data
4804 local fstype=$(facet_fstype ost$num)
4808 # vdevs are not supported by ldiskfs
4811 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4812 # Device formatted by zfs
4814 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4816 error "unknown fstype!";;
4822 # Logical device formatted for lustre
4825 local DEVNAME=MDSDEV$num
4827 local fstype=$(facet_fstype mds$num)
4831 local dev=mds${num}_dev
4832 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4833 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4834 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4836 # try $MDSZFSDEVn - independent of vdev
4837 DEVNAME=MDSZFSDEV$num
4838 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4840 error "unknown fstype!";;
4846 # Physical location of data
4850 local fstype=$(facet_fstype mds$num)
4854 # vdevs are not supported by ldiskfs
4857 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4858 # Device formatted by ZFS
4859 local DEVNAME=MDSDEV$num
4860 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4862 error "unknown fstype!";;
4870 local fstype=$(facet_fstype mgs)
4874 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4875 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4876 DEVPTR=$(mdsdevname 1)
4878 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4882 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4883 ( [ -z "$MGSZFSDEV" ] &&
4884 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4885 DEVPTR=$(mdsdevname 1)
4887 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4890 error "unknown fstype!";;
4899 local fstype=$(facet_fstype mgs)
4903 # vdevs are not supported by ldiskfs
4906 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4907 ( [ -z "$MGSDEV" ] &&
4908 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4909 VDEVPTR=$(mdsvdevname 1)
4910 elif [ -n "$MGSDEV" ]; then
4914 error "unknown fstype!";;
4922 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4924 local var=${facet}_MOUNT
4925 eval mntpt=${!var:-${MOUNT}-$facet}
4932 local dev=$(facet_device $facet)
4933 local mnt=${2:-$(facet_mntpt $facet)}
4937 if dm_flakey_supported $facet; then
4938 dm_dev=$(dm_create_dev $facet $dev)
4939 [[ -n "$dm_dev" ]] || dm_dev=$dev
4941 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4942 export_dm_dev $facet $dm_dev
4944 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4949 local dev=$(facet_device $facet)
4950 local mnt=${2:-$(facet_mntpt $facet)}
4952 do_facet $facet $UMOUNT $mnt
4956 echo -n "$1" | tr -c '[:alnum:]\n' '_'
4961 local ds=$(facet_device $facet)
4962 local mnt=${2:-$(facet_mntpt $facet)}
4967 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
4968 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
4969 do_facet $facet $ZFS set canmount=noauto $ds
4971 # The "legacy" mount method is used here because "zfs unmount $mnt"
4972 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
4973 # targets are not available at the time, the stat(2) on $MOUNT will
4976 do_facet $facet $ZFS set mountpoint=legacy $ds
4977 do_facet $facet mount -t zfs $ds $mnt
4978 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
4979 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
4984 local ds=$(facet_device $facet)
4985 local mnt=${2:-$(facet_mntpt $facet)}
4986 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
4987 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
4988 local mntpt=${!var_mntpt}
4989 local canmnt=${!var_canmnt}
4993 do_facet $facet umount $mnt
4994 do_facet $facet $ZFS set mountpoint=$mntpt $ds
4995 do_facet $facet $ZFS set canmount=$canmnt $ds
5002 local fstype=$(facet_fstype $facet)
5004 mount_$fstype $facet $mnt
5010 local fstype=$(facet_fstype $facet)
5012 unmount_$fstype $facet $mnt
5019 # make sure we are using the primary server, so test-framework will
5020 # be able to clean up properly.
5021 activemds=`facet_active mds1`
5022 if [ $activemds != "mds1" ]; then
5026 local clients=$CLIENTS
5027 [ -z $clients ] && clients=$(hostname)
5029 zconf_umount_clients $clients $MOUNT "$*" || true
5030 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
5032 [ -n "$CLIENTONLY" ] && return
5034 # The add fn does rm ${facet}active file, this would be enough
5035 # if we use do_facet <facet> only after the facet added, but
5036 # currently we use do_facet mds in local.sh
5038 for num in `seq $MDSCOUNT`; do
5040 rm -f ${TMP}/mds${num}active
5042 combined_mgs_mds && rm -f $TMP/mgsactive
5044 for num in `seq $OSTCOUNT`; do
5046 rm -f $TMP/ost${num}active
5049 if ! combined_mgs_mds ; then
5053 if $SHARED_KEY; then
5054 export SK_MOUNTED=false
5060 cleanup_echo_devs () {
5063 local devs=$($LCTL dl | grep echo | awk '{print $4}')
5065 for dev in $devs; do
5066 $LCTL --device $dev cleanup
5067 $LCTL --device $dev detach
5072 nfs_client_mode && return
5073 cifs_client_mode && return
5076 CLEANUP_DM_DEV=true stopall $*
5083 combined_mgs_mds () {
5084 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
5085 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
5089 echo -n "$1" | tr '[:upper:]' '[:lower:]'
5093 echo -n "$1" | tr '[:lower:]' '[:upper:]'
5105 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
5106 for i in $(echo "$var"); do
5107 if [ "$i" == "-O" ]; then
5109 first_o=$(($first_o + 1))
5112 if [ "$i" == "-E" ]; then
5114 first_e=$(($first_e + 1 ))
5119 [ $first_o -gt 1 ] && opt_o+=",";
5123 [ $first_e -gt 1 ] && opt_e+=",";
5134 [ -n "$opt_o" ] && echo " -O $opt_o"
5135 [ -n "$opt_e" ] && echo " -E $opt_e"
5141 local fsname=${3:-"$FSNAME"}
5142 local type=$(facet_type $facet)
5143 local index=$(facet_index $facet)
5144 local fstype=$(facet_fstype $facet)
5145 local host=$(facet_host $facet)
5149 local varbs=${facet}_BLOCKSIZE
5151 if [ $type == MGS ] || ( [ $type == MDS ] &&
5152 [ "$dev" == $(mgsdevname) ] &&
5153 [ "$host" == "$(facet_host mgs)" ] ); then
5156 opts="--mgsnode=$MGSNID"
5159 if [ $type != MGS ]; then
5160 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
5164 var=${facet}failover_HOST
5165 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
5166 opts+=" --failnode=$(h2nettype ${!var})"
5169 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
5170 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
5172 if [ $type == MDS ]; then
5173 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
5174 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
5175 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
5177 if [ $fstype == ldiskfs ]; then
5179 if [ -n "${!var}" ]; then
5180 fs_mkfs_opts+=" -J device=${!var}"
5182 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
5184 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
5188 if [ $type == OST ]; then
5189 if [ $fstype == ldiskfs ]; then
5191 if [ -n "${!var}" ]; then
5192 fs_mkfs_opts+=" -J device=${!var}"
5194 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
5199 opts+=" --backfstype=$fstype"
5202 if [ -n "${!var}" ]; then
5203 opts+=" --device-size=${!var}"
5206 var=$(upper $fstype)_MKFS_OPTS
5207 fs_mkfs_opts+=${!var:+" ${!var}"}
5209 var=${type}_FS_MKFS_OPTS
5210 fs_mkfs_opts+=${!var:+" ${!var}"}
5212 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
5214 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
5215 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
5217 if [ -n "${fs_mkfs_opts## }" ]; then
5218 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
5222 opts+=${!var:+" ${!var}"}
5229 local type=$(facet_type $facet)
5230 local var=${type}_MOUNT_FS_OPTS
5232 if [ -n "${!var}" ]; then
5233 opts+=" --mountfsoptions=${!var}"
5238 check_ost_indices() {
5239 local index_count=${#OST_INDICES[@]}
5240 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
5242 # OST count is greater than the index count in $OST_INDEX_LIST.
5243 # We need check whether there are duplicate indices.
5247 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
5248 index=$(facet_index ost$i)
5249 for j in $(seq 0 $((index_count - 1))); do
5250 [[ $index -ne ${OST_INDICES[j]} ]] ||
5251 error "ost$i has the same index $index as ost$((j+1))"
5258 local facet_type=$1 # mgs || mds || ost
5260 local facet=${1}${2}
5263 case "$(facet_fstype $facet)" in
5265 device=$(${facet_type}devname $facet_num)
5268 device=$(${facet_type}vdevname $facet_num)
5271 error "Unhandled filesystem type"
5275 do_facet $facet "[ -e \"$device\" ]" && return
5277 # Note: the following check only works with absolute paths
5278 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5279 error "$facet: device '$device' does not exist"
5281 # zpool create doesn't like empty files
5282 [[ $(facet_fstype $facet) == zfs ]] && return 0
5284 do_facet $facet "touch \"${device}\""
5293 echo "Format mgs: $(mgsdevname)"
5294 reformat_external_journal mgs
5296 # touch "device" in case it is a loopback file for testing and needs to
5297 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5298 # to non-existent files in /dev if the admin made a typo during setup
5301 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5302 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5312 echo "Format mds$num: $(mdsdevname $num)"
5313 reformat_external_journal mds$num
5315 __touch_device mds $num
5317 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5318 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5319 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5328 echo "Format ost$num: $(ostdevname $num)"
5329 reformat_external_journal ost$num
5331 __touch_device ost $num
5333 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5334 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5335 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5340 # Set hostid for ZFS/SPL zpool import protection
5341 # (Assumes MDS version is also OSS version)
5342 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5344 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5347 # We need ldiskfs here, may as well load them all
5349 [ -n "$CLIENTONLY" ] && return
5350 echo Formatting mgs, mds, osts
5351 if ! combined_mgs_mds ; then
5355 for num in $(seq $MDSCOUNT); do
5359 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5361 for num in $(seq $OSTCOUNT); do
5367 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5371 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5374 # usage: switch_identity MDSNUM ENABLE_UPCALL
5377 # 0: success, the identity upcall was previously enabled already.
5378 # 1: success, the identity upcall was previously disabled.
5384 local MDT="$(mdtname_from_index $((num - 1)) $MOUNT)"
5385 local upcall="$L_GETIDENTITY"
5387 [[ -n "$MDT" ]] || return 2
5389 local param="mdt.$MDT.identity_upcall"
5390 local old="$(do_facet $facet "lctl get_param -n $param")"
5392 [[ "$enable" == "true" ]] || upcall="NONE"
5394 do_facet $facet "lctl set_param -n $param='$upcall'" || return 2
5395 do_facet $facet "lctl set_param -n mdt.$MDT.identity_flush=-1"
5397 [[ "$old" != "NONE" ]] # implicit "&& return 0 || return 1"
5402 zconf_umount $HOSTNAME $1 || error "umount failed"
5403 zconf_mount $HOSTNAME $1 || error "mount failed"
5411 rm -f $TMP/${facet}active
5412 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5417 local mdt_count=${1:-$MDSCOUNT}
5418 local ost_count=${2:-$OSTCOUNT}
5421 for num in $(seq $mdt_count); do
5422 DEVNAME=$(mdsdevname $num)
5423 writeconf_facet mds$num $DEVNAME || rc=$?
5426 for num in $(seq $ost_count); do
5427 DEVNAME=$(ostdevname $num)
5428 writeconf_facet ost$num $DEVNAME || rc=$?
5434 if ! combined_mgs_mds ; then
5435 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5444 for num in $(seq $MDSCOUNT); do
5445 devname=$(mdsdevname $num)
5446 start mds$num $devname $MDS_MOUNT_OPTS
5448 # We started mds$num, now we should set mds${num}_HOST
5449 # and mds${num}failover_HOST variables properly if they
5451 host=$(facet_host mds$num)
5452 for varname in mds${num}_HOST mds${num}failover_HOST; do
5453 if [[ -z "${!varname}" ]]; then
5457 if [[ "$IDENTITY_UPCALL" != "default" ]]; then
5458 switch_identity $num $IDENTITY_UPCALL
5466 for num in $(seq $OSTCOUNT); do
5468 rm -f $TMP/ost${num}active
5477 for num in $(seq $OSTCOUNT); do
5478 devname=$(ostdevname $num)
5479 start ost$num $devname $OST_MOUNT_OPTS
5481 # We started ost$num, now we should set ost${num}_HOST
5482 # and ost${num}failover_HOST variables properly if they
5484 host=$(facet_host ost$num)
5485 for varname in ost${num}_HOST ost${num}failover_HOST; do
5486 if [[ -z "${!varname}" ]]; then
5494 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5495 if [ ! -z $arg1 ]; then
5496 [ "$arg1" = "server_only" ] && return
5499 if [ -n "$CLIENTS" ]; then
5500 zconf_mount_clients $CLIENTS $MOUNT
5504 if [ "$MOUNT_2" ]; then
5505 mount_client $MOUNT2
5506 if [ -n "$CLIENTS" ]; then
5507 zconf_mount_clients $CLIENTS $MOUNT2
5512 sk_nodemap_setup() {
5513 local sk_map_name=${1:-$SK_S2SNM}
5514 local sk_map_nodes=${2:-$HOSTNAME}
5515 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5516 for servernode in $sk_map_nodes; do
5517 local nids=$(do_nodes $servernode "$LCTL list_nids")
5518 for nid in $nids; do
5519 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5520 $sk_map_name --range $nid"
5528 nfs_client_mode && return
5529 cifs_client_mode && return
5531 sanity_mount_check || error "environments are insane!"
5537 if [ -z "$CLIENTONLY" ]; then
5538 echo Setup mgs, mdt, osts
5539 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5541 if $SK_MOUNTED; then
5542 echo "Shared Key file system already mounted"
5547 if $SHARED_KEY; then
5548 export SK_MOUNTED=true
5552 echo "GSS_SK: setting kernel keyring perms"
5553 do_nodes $(comma_list $(all_nodes)) \
5554 "keyctl show | grep lustre | cut -c1-11 |
5556 xargs -IX keyctl setperm X 0x3f3f3f3f"
5559 # Need to start one nodemap for servers,
5560 # and one for clients.
5561 sk_nodemap_setup $SK_S2SNM \
5562 $(comma_list $(all_server_nodes))
5564 sk_nodemap_setup $SK_S2SNMCLI \
5565 ${CLIENTS:-$HOSTNAME}
5566 echo "Nodemap set up for SK S2S, remounting."
5575 # wait a while to allow sptlrpc configuration be propogated to targets,
5576 # only needed when mounting new target devices.
5584 # by remounting mdt before ost, initial connect from mdt to ost might
5585 # timeout because ost is not ready yet. wait some time to its fully
5586 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5587 # preceeded by a context negotiation rpc with $TIMEOUT.
5588 # FIXME better by monitoring import status.
5591 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5592 set_rule $FSNAME any cli2ost $SK_FLAVOR
5593 if $SK_SKIPFIRST; then
5594 export SK_SKIPFIRST=false
5598 "lctl set_param osc.*.idle_connect=1"
5601 wait_flavor cli2mdt $SK_FLAVOR
5602 wait_flavor cli2ost $SK_FLAVOR
5607 sleep $((TIMEOUT + 5))
5613 mounted_lustre_filesystems() {
5614 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5617 init_facet_vars () {
5618 [ -n "$CLIENTONLY" ] && return 0
5625 eval export ${facet}_dev=${device}
5626 eval export ${facet}_opt=\"$*\"
5628 local dev=${facet}_dev
5630 # We need to loop for the label
5631 # in case its not initialized yet.
5632 for wait_time in {0,1,3,5,10}; do
5634 if [ $wait_time -gt 0 ]; then
5635 echo "${!dev} not yet initialized,"\
5636 "waiting ${wait_time} seconds."
5640 local label=$(devicelabel ${facet} ${!dev})
5642 # Check to make sure the label does
5643 # not include ffff at the end of the label.
5644 # This indicates it has not been initialized yet.
5646 if [[ $label =~ [f|F]{4}$ ]]; then
5647 # label is not initialized, unset the result
5648 # and either try again or fail
5655 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5657 eval export ${facet}_svc=${label}
5659 local varname=${facet}failover_HOST
5660 if [ -z "${!varname}" ]; then
5662 if combined_mgs_mds && [ $facet == "mgs" ] &&
5663 [ -n "$mds1failover_HOST" ]; then
5664 temp=$mds1failover_HOST
5666 temp=$(facet_host $facet)
5668 eval export $varname=$temp
5671 varname=${facet}_HOST
5672 if [ -z "${!varname}" ]; then
5673 eval export $varname=$(facet_host $facet)
5676 # ${facet}failover_dev is set in cfg file
5677 varname=${facet}failover_dev
5678 if [ -n "${!varname}" ] ; then
5679 eval export ${facet}failover_dev=${!varname}
5681 eval export ${facet}failover_dev=$device
5684 # get mount point of already mounted device
5685 # is facet_dev is already mounted then use the real
5686 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5687 # i.e. ${facet}_MOUNT if specified by user or default
5688 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5689 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5690 if [ -z $mntpt ]; then
5691 mntpt=$(facet_mntpt $facet)
5693 eval export ${facet}_MOUNT=$mntpt
5696 init_facets_vars () {
5699 if ! remote_mds_nodsh; then
5700 for num in $(seq $MDSCOUNT); do
5701 DEVNAME=$(mdsdevname $num)
5702 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5706 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5708 if ! remote_ost_nodsh; then
5709 for num in $(seq $OSTCOUNT); do
5710 DEVNAME=$(ostdevname $num)
5711 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5716 init_facets_vars_simple () {
5719 if ! remote_mds_nodsh; then
5720 for num in $(seq $MDSCOUNT); do
5721 devname=$(mdsdevname $num)
5722 eval export mds${num}_dev=${devname}
5723 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5727 if ! combined_mgs_mds ; then
5728 eval export mgs_dev=$(mgsdevname)
5729 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5732 if ! remote_ost_nodsh; then
5733 for num in $(seq $OSTCOUNT); do
5734 devname=$(ostdevname $num)
5735 eval export ost${num}_dev=${devname}
5736 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5741 osc_ensure_active () {
5746 while [ $period -lt $timeout ]; do
5747 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5748 if [ $count -eq 0 ]; then
5752 echo "$count OST inactive, wait $period seconds, and try again"
5754 period=$((period+3))
5757 [ $period -lt $timeout ] ||
5758 log "$count OST are inactive after $timeout seconds, give up"
5761 set_conf_param_and_check() {
5765 local ORIG=$(do_facet $myfacet "$TEST")
5766 if [ $# -gt 3 ]; then
5772 echo "Setting $PARAM from $ORIG to $FINAL"
5773 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5774 error "conf_param $PARAM failed"
5776 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5777 error "check $PARAM failed!"
5780 set_persistent_param() {
5784 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5786 if [ $# -gt 3 ]; then
5793 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5794 echo "Setting $test_param from $orig to $final"
5795 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5796 error "$PERM_CMD $test_param failed"
5798 echo "Setting $param from $orig to $final"
5799 do_facet mgs "$PERM_CMD $param='$final'" ||
5800 error "$PERM_CMD $param failed"
5804 set_persistent_param_and_check() {
5808 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5810 if [ $# -gt 3 ]; then
5817 set_persistent_param $myfacet $test_param $param "$final"
5819 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5820 error "check $param failed!"
5823 init_param_vars () {
5824 TIMEOUT=$(lctl get_param -n timeout)
5825 TIMEOUT=${TIMEOUT:-20}
5827 if [ -n "$arg1" ]; then
5828 [ "$arg1" = "server_only" ] && return
5831 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5833 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5834 log "Using TIMEOUT=$TIMEOUT"
5836 # tune down to speed up testing on (usually) small setups
5837 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5838 do_nodes $(comma_list $(nodes_list)) \
5839 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5841 osc_ensure_active $SINGLEMDS $TIMEOUT
5842 osc_ensure_active client $TIMEOUT
5843 $LCTL set_param osc.*.idle_timeout=debug
5845 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5846 local current_jobid_var=$($LCTL get_param -n jobid_var)
5848 if [ $JOBID_VAR = "existing" ]; then
5849 echo "keeping jobstats as $current_jobid_var"
5850 elif [ $current_jobid_var != $JOBID_VAR ]; then
5851 echo "setting jobstats to $JOBID_VAR"
5853 set_persistent_param_and_check client \
5854 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5857 echo "jobstats not supported by server"
5860 if [ $QUOTA_AUTO -ne 0 ]; then
5861 if [ "$ENABLE_QUOTA" ]; then
5862 echo "enable quota as required"
5863 setup_quota $MOUNT || return 2
5865 echo "disable quota as required"
5866 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5870 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5871 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5875 nfs_client_mode () {
5876 if [ "$NFSCLIENT" ]; then
5877 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5878 local clients=$CLIENTS
5880 [ -z $clients ] && clients=$(hostname)
5882 # FIXME: remove hostname when 19215 fixed
5883 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5884 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5885 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5886 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5887 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5889 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5895 cifs_client_mode () {
5896 [ x$CIFSCLIENT = xyes ] &&
5897 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5900 check_config_client () {
5902 local mounted=$(mount | grep " $mntpt ")
5904 if [ -n "$CLIENTONLY" ]; then
5906 # CLIENTONLY should not depend on *_HOST settings
5907 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5908 # in theory someone could create a new,
5909 # client-only config file that assumed lustre was already
5910 # configured and didn't set the MGSNID. If MGSNID is not set,
5911 # then we should use the mgs nid currently being used
5912 # as the default value. bug 18021
5913 [[ x$MGSNID = x ]] &&
5916 if [[ x$mgc != xMGC$MGSNID ]]; then
5917 if [ "$mgs_HOST" ]; then
5918 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
5919 grep PING | awk '{print $3}' |
5920 sed -e "s/(//g" -e "s/)//g")
5922 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5923 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5929 echo Checking config lustre mounted on $mntpt
5930 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5931 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5935 check_config_clients () {
5936 local clients=${CLIENTS:-$HOSTNAME}
5939 nfs_client_mode && return
5940 cifs_client_mode && return
5942 do_rpc_nodes "$clients" check_config_client $mntpt
5944 sanity_mount_check || error "environments are insane!"
5948 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5949 local cltimeout=$(lctl get_param -n timeout)
5950 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5951 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
5958 [ -z $mntpt ] && return 1
5959 local mounted=$(mounted_lustre_filesystems)
5961 echo $mounted' ' | grep -w -q $mntpt' '
5966 local ostsn=${2:-$OSTCOUNT}
5967 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
5970 echo ostsn=$ostsn npools=$npools
5971 if [[ $ostsn -gt $OSTCOUNT ]]; then
5972 echo "request to use $ostsn OSTs in the pool, \
5973 using max available OSTCOUNT=$OSTCOUNT"
5976 for (( n=0; n < $npools; n++ )); do
5978 if ! $DELETE_OLD_POOLS; then
5979 log "request to not delete old pools: $FSNAME.$p exist?"
5980 if ! check_pool_not_exist $FSNAME.$p; then
5981 echo "Using existing $FSNAME.$p"
5982 $LCTL pool_list $FSNAME.$p
5986 create_pool $FSNAME.$p $KEEP_POOLS ||
5987 error "create_pool $FSNAME.$p failed"
5989 local first=$(( (n * ostsn) % OSTCOUNT ))
5990 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
5991 if [[ $first -le $last ]]; then
5992 pool_add_targets $p $first $last ||
5993 error "pool_add_targets $p $first $last failed"
5995 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
5996 error "pool_add_targets $p $first \
5997 $(( OSTCOUNT - 1 )) failed"
5998 pool_add_targets $p 0 $last ||
5999 error "pool_add_targets $p 0 $last failed"
6004 set_pools_quota () {
6011 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
6012 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
6014 # POOLS_QUOTA_USERS_SET=
6015 # "quota15_1:20M -- for all of the found pools
6016 # quota15_2:1G:gpool0
6017 # quota15_3 -- for global limit only
6018 # quota15_4:200M:gpool0
6019 # quota15_4:200M:gpool1"
6021 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
6023 declare -A pq_limits
6025 for ((i=0; i<${#pq_userset[@]}; i++)); do
6026 u=${pq_userset[i]%%:*}
6028 # user gets no pool limits if
6029 # POOLS_QUOTA_USERS_SET does not specify it
6030 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
6031 pq_limits[$u]+=" $o"
6033 pq_users=(${!pq_limits[@]})
6038 for ((i=0; i<${#pq_users[@]}; i++)); do
6040 # set to max limit (_u64)
6041 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
6042 opts=(${pq_limits[$u]})
6043 for ((j=0; j<${#opts[@]}; j++)); do
6046 # Set limit for all existing pools if
6048 if [ $p == $o ]; then
6049 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
6050 echo "No pool specified for $u,
6051 set limit $o for all existing pools"
6054 $LFS setquota -u $u -B $o --pool $pool $DIR ||
6055 error "setquota -u $u -B $o \
6056 --pool $pool failed"
6059 $LFS quota -uv $u --pool $DIR
6063 do_check_and_setup_lustre() {
6064 # If auster does not want us to setup, then don't.
6065 ! ${do_setup} && return
6067 echo "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
6070 nfs_client_mode && return
6071 cifs_client_mode && return
6073 local MOUNTED=$(mounted_lustre_filesystems)
6077 # both MOUNT and MOUNT2 are not mounted
6078 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6079 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
6080 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
6082 is_mounted $MOUNT || error "NAME=$NAME not mounted"
6083 export I_MOUNTED=yes
6087 elif is_mounted $MOUNT2; then
6089 # MOUNT2 is mounted, while MOUNT_2 is not set
6090 if ! [ "$MOUNT_2" ]; then
6091 cleanup_mount $MOUNT2
6092 export I_UMOUNTED2=yes
6095 # MOUNT2 is mounted, MOUNT_2 is set
6097 # FIXME: what to do if check_config failed?
6099 # 1) remote client has mounted other Lustre fs ?
6100 # 2) it has insane env ?
6101 # try to umount MOUNT2 on all clients and mount again:
6102 if ! check_config_clients $MOUNT2; then
6103 cleanup_mount $MOUNT2
6104 restore_mount $MOUNT2
6105 export I_MOUNTED2=yes
6109 # MOUNT is mounted MOUNT2 is not mounted
6110 elif [ "$MOUNT_2" ]; then
6111 restore_mount $MOUNT2
6112 export I_MOUNTED2=yes
6116 # FIXME: what to do if check_config failed?
6118 # 1) remote client has mounted other Lustre fs?
6119 # 2) lustre is mounted on remote_clients atall ?
6120 check_config_clients $MOUNT
6124 set_default_debug_nodes $(comma_list $(nodes_list))
6128 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
6130 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
6131 facets="$(get_facets OST)"
6132 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
6133 facets="$facets,$(get_facets MDS)"
6134 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
6135 facets="$facets,mgs"
6136 local nodes="$(facets_hosts ${facets})"
6137 if [ -n "$nodes" ] ; then
6138 do_nodes $nodes "$LCTL set_param \
6139 osd-ldiskfs.track_declares_assert=1 || true"
6143 if [ -n "$fs_STRIPEPARAMS" ]; then
6144 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
6153 if $DELETE_OLD_POOLS; then
6157 if [[ -n "$FS_POOL" ]]; then
6158 create_pools $FS_POOL $FS_POOL_NOSTS
6161 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
6165 # set tunable parameters passed to test environment
6169 echo "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
6171 if [[ "$ONLY" == "setup" ]]; then
6176 check_and_setup_lustre() {
6177 local start_stamp=$(date +%s)
6178 local saved_umask=$(umask)
6179 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
6188 log_sub_test_begin test_setup
6190 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
6191 error=$(tail -1 $log)
6196 stop_stamp=$(date +%s)
6197 duration=$((stop_stamp - start_stamp))
6199 log_sub_test_end "$status" "$duration" "$rc" "$error"
6207 local clients=${CLIENTS:-$HOSTNAME}
6210 zconf_mount_clients $clients $mntpt
6214 local clients=${CLIENTS:-$HOSTNAME}
6217 zconf_umount_clients $clients $mntpt
6220 cleanup_and_setup_lustre() {
6221 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
6222 lctl set_param debug=0 || true
6225 if [[ "$ONLY" == "cleanup" ]]; then
6230 do_check_and_setup_lustre
6233 # Run e2fsck on MDT or OST device.
6238 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
6239 local log=$TMP/e2fsck.log
6242 # turn on pfsck if it is supported
6243 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
6245 do_node $node $cmd 2>&1 | tee $log
6247 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
6249 if [ $MDSCOUNT -gt 1 ]; then
6250 skip_noexit "DNE mode isn't supported!"
6254 error "It's not DNE mode."
6259 [ $rc -le $FSCK_MAX_ERR ] ||
6260 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6266 # Run resize2fs on MDT or OST device.
6275 do_facet $facet "$RESIZE2FS $opts $device $size"
6278 # verify a directory is shared among nodes.
6279 check_shared_dir() {
6281 local list=${2:-$(comma_list $(nodes_list))}
6283 [ -z "$dir" ] && return 1
6284 do_rpc_nodes "$list" check_logdir $dir
6285 check_write_access $dir "$list" || return 1
6290 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
6291 $LCTL set_param printk=+lfsck
6292 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6294 for k in $(seq $MDSCOUNT); do
6295 # wait up to 10+1 minutes for LFSCK to complete
6296 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6297 mdd.$(facet_svc mds${k}).lfsck_layout |
6298 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6299 error "MDS${k} layout isn't the expected 'completed'"
6300 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6301 mdd.$(facet_svc mds${k}).lfsck_namespace |
6302 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6303 error "MDS${k} namespace isn't the expected 'completed'"
6305 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
6306 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
6307 awk '/repaired/ { print $2 }' | calc_sum)
6308 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
6309 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
6310 awk '/repaired/ { print $2 }' | calc_sum)
6311 local repaired=$((rep_mdt + rep_ost))
6312 [ $repaired -eq 0 ] ||
6313 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6316 dump_file_contents() {
6322 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6323 error_noexit false \
6324 "Invalid parameters for dump_file_contents()"
6327 for node in ${nodes}; do
6328 do_node $node "for i in \\\$(find $dir -type f); do
6329 echo ====\\\${i}=======================;
6331 done" >> ${logname}.${node}.log
6335 dump_command_output() {
6341 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6342 error_noexit false \
6343 "Invalid parameters for dump_command_output()"
6347 for node in ${nodes}; do
6348 do_node $node "echo ====${cmd}=======================;
6349 $cmd" >> ${logname}.${node}.log
6356 # dump file contents from /proc/spl in case of zfs test
6357 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6358 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6359 dump_command_output \
6360 "$(osts_nodes)" "zpool events -v" "${logname}"
6363 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6364 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6365 dump_command_output \
6366 "$(mdts_nodes)" "zpool events -v" "${logname}"
6370 do_check_and_cleanup_lustre() {
6371 echo "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6373 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6374 "$TESTSUITE" != "sanity-scrub" ]]; then
6378 if is_mounted $MOUNT; then
6379 if $DO_CLEANUP; then
6380 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6381 error "remove sub-test dirs failed"
6385 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6388 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6389 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6392 if [[ "$I_MOUNTED2" == "yes" ]]; then
6393 cleanup_mount $MOUNT2
6396 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6397 cleanupall -f || error "cleanup failed"
6401 echo "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6404 check_and_cleanup_lustre() {
6405 local start_stamp=$(date +%s)
6406 local saved_umask=$(umask)
6407 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6416 log_sub_test_begin test_cleanup
6418 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6419 error=$(tail -1 $log)
6424 stop_stamp=$(date +%s)
6425 duration=$((stop_stamp - start_stamp))
6427 log_sub_test_end "$status" "$duration" "$rc" "$error"
6437 wait_for_function () {
6440 # suppress fn both stderr and stdout
6441 if [ "$1" = "--quiet" ]; then
6443 quiet=" > /dev/null 2>&1"
6454 eval $fn $quiet && return 0
6456 [ $wait -lt $max ] || return 1
6457 echo waiting $fn, $((max - wait)) secs left ...
6458 wait=$((wait + sleep))
6459 [ $wait -gt $max ] && ((sleep -= wait - max))
6469 [ "$host" = "$HOSTNAME" ] && return 0
6471 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6472 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6482 # Convert a space-delimited list to a comma-delimited list. If the input is
6483 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6485 # echo is used to convert newlines to spaces, since it doesn't
6486 # introduce a trailing space as using "tr '\n' ' '" does
6487 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6493 echo $list | grep -qw $item
6496 # list, excluded are the comma separated lists
6497 exclude_items_from_list () {
6503 for item in ${excluded//,/ }; do
6504 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6506 echo $(comma_list $list)
6509 # list, expand are the comma separated lists
6511 local list=${1//,/ }
6512 local expand=${2//,/ }
6515 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6516 echo $(comma_list $expanded)
6519 testslist_filter () {
6520 local script=$LUSTRE/tests/${TESTSUITE}.sh
6522 [ -f $script ] || return 0
6524 local start_at=$START_AT
6525 local stop_at=$STOP_AT
6527 local var=${TESTSUITE//-/_}_START_AT
6528 [ x"${!var}" != x ] && start_at=${!var}
6529 var=${TESTSUITE//-/_}_STOP_AT
6530 [ x"${!var}" != x ] && stop_at=${!var}
6532 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6533 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6534 /^'${start_at}'$/ {flag = 0}
6535 {if (flag == 1) print $0}
6536 /^'${stop_at}'$/ { flag = 1 }'
6540 (cd `dirname $1`; echo $PWD/`basename $1`)
6544 local types=${1:-"OST MDS MGS"}
6548 for entry in $types; do
6549 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6550 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6553 MGS ) list="$list $name";;
6554 MDS|OST|AGT ) local count=${type}COUNT
6555 for ((i=1; i<=${!count}; i++)) do
6556 list="$list ${name}$i"
6558 * ) error "Invalid facet type"
6562 echo $(comma_list $list)
6565 ##################################
6566 # Adaptive Timeouts funcs
6569 # only check mds, we assume at_max is the same on all nodes
6570 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6572 if [ $at_max -eq 0 ]; then
6583 # suppose that all ost-s have the same $at value set
6584 [ $facet != "ost" ] || facet=ost1
6586 do_facet $facet "lctl get_param -n $at"
6600 for facet in "$@"; do
6601 if [ $facet == "ost" ]; then
6602 facet=$(get_facets OST)
6603 elif [ $facet == "mds" ]; then
6604 facet=$(get_facets MDS)
6606 hosts=$(expand_list $hosts $(facets_hosts $facet))
6609 do_nodes $hosts lctl set_param at_max=$at_max
6623 for facet in "$@"; do
6624 if [ $facet == "ost" ]; then
6625 facet=$(get_facets OST)
6626 elif [ $facet == "mds" ]; then
6627 facet=$(get_facets MDS)
6629 hosts=$(expand_list $hosts $(facets_hosts $facet))
6632 do_nodes $hosts lctl set_param at_min=$at_min
6635 ##################################
6639 # OBD_FAIL_MDS_ALL_REQUEST_NET
6641 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6642 do_facet client "$1" || RC=$?
6643 do_facet $SINGLEMDS lctl set_param fail_loc=0
6648 # OBD_FAIL_MDS_ALL_REPLY_NET
6650 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6652 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6656 drop_reint_reply() {
6657 # OBD_FAIL_MDS_REINT_NET_REP
6659 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6661 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6665 drop_update_reply() {
6666 # OBD_FAIL_OUT_UPDATE_NET_REP
6670 do_facet mds${index} lctl set_param fail_loc=0x1701
6671 do_facet client "$@" || RC=$?
6672 do_facet mds${index} lctl set_param fail_loc=0
6677 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6680 local timeout=${2:-0}
6681 # default is (obd_timeout / 4) if unspecified
6682 echo "timeout is $timeout/$2"
6683 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6684 do_facet client "$1" || RC=$?
6685 do_facet client "sync"
6686 do_facet ost1 lctl set_param fail_loc=0
6690 drop_ldlm_cancel() {
6691 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6693 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6694 do_nodes $list lctl set_param fail_loc=0x304
6696 do_facet client "$@" || RC=$?
6698 do_nodes $list lctl set_param fail_loc=0
6702 drop_bl_callback_once() {
6704 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6705 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6706 do_facet client lctl set_param fail_loc=0x80000305
6707 do_facet client "$@" || rc=$?
6708 do_facet client lctl set_param fail_loc=0
6709 do_facet client lctl set_param fail_val=0
6710 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6714 drop_bl_callback() {
6716 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6717 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6718 do_facet client lctl set_param fail_loc=0x305
6719 do_facet client "$@" || rc=$?
6720 do_facet client lctl set_param fail_loc=0
6721 do_facet client lctl set_param fail_val=0
6722 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6726 drop_mdt_ldlm_reply() {
6727 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6729 local list=$(comma_list $(mdts_nodes))
6731 do_nodes $list lctl set_param fail_loc=0x157
6733 do_facet client "$@" || RC=$?
6735 do_nodes $list lctl set_param fail_loc=0
6739 drop_mdt_ldlm_reply_once() {
6740 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6742 local list=$(comma_list $(mdts_nodes))
6744 do_nodes $list lctl set_param fail_loc=0x80000157
6746 do_facet client "$@" || RC=$?
6748 do_nodes $list lctl set_param fail_loc=0
6756 echo "clearing fail_loc on $facet"
6757 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6760 set_nodes_failloc () {
6762 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6765 # Print the total of the lock_unused_count across all namespaces containing the
6766 # given wildcard. If the namespace wildcard is omitted, all namespaces will be
6768 # Usage: total_unused_locks [namespace_wildcard]
6769 total_unused_locks() {
6770 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_unused_count" | calc_sum
6773 # Print the total of the lock_count across all namespaces containing the given
6774 # wildcard. If the namespace wilcard is omitted, all namespaces will be matched.
6775 # Usage: total_used_locks [namespace_wildcard]
6776 total_used_locks() {
6777 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_count" | calc_sum
6780 # Cancel lru locks across all namespaces containing the given wildcard. If the
6781 # wilcard is omitted, lru locks will be canceled across all namespaces.
6782 # Usage: cancel_lru_locks [namespace_wildcard]
6783 cancel_lru_locks() {
6784 #$LCTL mark "cancel_lru_locks $1 start"
6785 $LCTL set_param -t4 -n "ldlm.namespaces.*$1*.lru_size=clear"
6786 $LCTL get_param "ldlm.namespaces.*$1*.lock_unused_count" | grep -v '=0'
6787 #$LCTL mark "cancel_lru_locks $1 stop"
6792 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6794 echo $((100 * nr_cpu))
6799 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6802 lru_resize_disable()
6805 local lru_size=${2:-$(default_lru_size)}
6807 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6812 local mountpath=${1:-$MOUNT}
6815 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6822 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6823 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6824 echo there is still data in page cache $FILE ?
6825 lctl get_param -n $FILE
6833 DEBUGSAVE="$(lctl get_param -n debug)"
6834 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6838 [ -n "$DEBUGSAVE" ] &&
6839 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6843 [ -n "$DEBUGSAVE_SERVER" ] &&
6844 do_nodes $(comma_list $(all_server_nodes)) \
6845 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6851 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6854 debug_size_restore() {
6855 [ -n "$DEBUG_SIZE_SAVED" ] &&
6856 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6860 start_full_debug_logging() {
6865 local debug_size=150
6866 local nodes=$(comma_list $(nodes_list))
6868 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6871 stop_full_debug_logging() {
6876 # prints bash call stack
6877 print_stack_trace() {
6880 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6881 local src=${BASH_SOURCE[$i]}
6882 local lineno=${BASH_LINENO[$i-1]}
6883 local funcname=${FUNCNAME[$i]}
6884 echo " = $src:$lineno:$funcname()"
6889 local TYPE=${TYPE:-"FAIL"}
6892 # do not dump logs if $1=false
6893 if [ "x$1" = "xfalse" ]; then
6898 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6899 (print_stack_trace 2) >&2
6901 # We need to dump the logs on all nodes
6903 gather_logs $(comma_list $(nodes_list))
6907 [ "$TESTSUITELOG" ] &&
6908 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
6909 if [ -z "$*" ]; then
6910 echo "error() without useful message, please fix" > $LOGDIR/err
6912 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6913 echo "$@" > $LOGDIR/ignore
6915 echo "$@" > $LOGDIR/err
6919 # cleanup the env for failed tests
6923 ##################################
6925 ##################################
6927 # usage: stack_trap arg sigspec
6929 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6930 # command "arg" on top of previously defined commands for "sigspec" instead
6931 # of overwriting them.
6932 # stacked traps are executed in reverse order of their registration
6934 # arg and sigspec have the same meaning as in man (1) trap
6938 local sigspec="${2:-EXIT}"
6940 # Use "trap -p" to get the quoting right
6941 local old_trap="$(trap -p "$sigspec")"
6942 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6943 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6945 # Once again, use "trap -p" to get the quoting right
6946 local new_trap="$(trap -- "$arg" "$sigspec"
6948 trap -- '' "$sigspec")"
6950 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6952 # The resulting string should be safe to "eval" as it is (supposedly
6953 # correctly) quoted by "trap -p"
6954 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
6963 local logs="$TESTSUITELOG $1"
6965 for log in $logs; do
6966 if [ -f "$log" ]; then
6967 grep -qw FAIL $log && status=1
6984 # use only if we are ignoring failures for this test, bugno required.
6985 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
6986 # e.g. error_ignore bz5494 "your message" or
6987 # error_ignore LU-5494 "your message"
6989 local TYPE="IGNORE ($1)"
6994 error_and_remount() {
6996 remount_client $MOUNT
7000 # Throw an error if it's not running in vm - usually for performance
7003 local virt=$(running_in_vm)
7004 if [[ -n "$virt" ]]; then
7005 echo "running in VM '$virt', ignore error"
7006 error_ignore env=$virt "$@"
7013 # Function: skip_env()
7014 # Purpose: to skip a test during developer testing because some tool
7015 # is missing, but fail the test in release testing because the test
7016 # environment is not configured properly".
7019 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
7024 log " SKIP: $TESTSUITE $TESTNAME $*"
7026 if [[ -n "$ALWAYS_SKIPPED" ]]; then
7027 skip_logged $TESTNAME "$@"
7030 echo "$@" > $LOGDIR/skip
7033 [[ -n "$TESTSUITELOG" ]] &&
7034 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
7044 # For interop testing treate EOPNOTSUPP as success
7050 echo $retstr | awk -F'|' '{print $1}' |
7051 grep -E unsupported\|"(Operation not supported)"
7052 (( $? == 0 )) || error "$retstr"
7056 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
7057 # Usage: always_except LU-4815 23 42q ...
7059 function always_except() {
7060 local issue="${1:-}" # single jira style issue ("LU-4815")
7065 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
7066 error "always_except: invalid issue '$issue' for tests '$*'"
7069 for test_num in "$@"; do
7070 ALWAYS_EXCEPT+=" $test_num"
7074 build_test_filter() {
7075 EXCEPT="$EXCEPT $(testslist_filter)"
7077 # allow test numbers separated by '+', or ',', in addition to ' '
7078 # to avoid issues with multiple arguments handling by shell/autotest
7079 for O in ${ONLY//[+,]/ }; do
7080 if [[ $O =~ [0-9]*-[0-9]* ]]; then
7081 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
7089 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
7090 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
7091 [[ -z "$EXCEPT_SLOW" ]] ||
7092 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
7093 for E in ${EXCEPT//[+,]/ }; do
7094 eval EXCEPT_${E}=true
7096 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
7097 eval EXCEPT_ALWAYS_${E}=true
7099 for E in ${EXCEPT_SLOW//[+,]/ }; do
7100 eval EXCEPT_SLOW_${E}=true
7102 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
7103 eval GCHECK_ONLY_${G}=true
7108 if [[ $1 = [a-z]* ]]; then
7111 echo ${1%%[a-zA-Z]*}
7115 # print a newline if the last test was skipped
7116 export LAST_SKIPPED=
7117 export ALWAYS_SKIPPED=
7119 # Main entry into test-framework. This is called with the number and
7120 # description of a test. The number is used to find the function to run
7121 # the test using "test_$name".
7123 # This supports a variety of methods of specifying specific test to
7125 # - ONLY= env variable with space-separated list of test numbers to run
7126 # - EXCEPT= env variable with space-separated list of test numbers to exclude
7132 export base=$(basetest $testnum)
7133 export TESTNAME=test_$testnum
7137 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
7138 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
7139 local isexcept=EXCEPT_$testnum
7140 local isexcept_base=EXCEPT_$base
7141 if [ ${!isexcept}x != x ]; then
7143 skip_message="skipping excluded test $testnum"
7144 elif [ ${!isexcept_base}x != x ]; then
7146 skip_message="skipping excluded test $testnum (base $base)"
7149 isexcept=EXCEPT_ALWAYS_$testnum
7150 isexcept_base=EXCEPT_ALWAYS_$base
7151 if [ ${!isexcept}x != x ]; then
7153 skip_message="skipping ALWAYS excluded test $testnum"
7154 elif [ ${!isexcept_base}x != x ]; then
7156 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
7159 isexcept=EXCEPT_SLOW_$testnum
7160 isexcept_base=EXCEPT_SLOW_$base
7161 if [ ${!isexcept}x != x ]; then
7163 skip_message="skipping SLOW test $testnum"
7164 elif [ ${!isexcept_base}x != x ]; then
7166 skip_message="skipping SLOW test $testnum (base $base)"
7169 # If there are tests on the ONLY list, check if the current test
7170 # is on that list and, if so, check if the test is to be skipped
7171 # and if we are supposed to honor the skip lists.
7172 if [ -n "$ONLY" ]; then
7173 local isonly=ONLY_$testnum
7174 local isonly_base=ONLY_$base
7175 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
7177 if [[ -n "$ALWAYS_SKIPPED" &&
7178 -n "$HONOR_EXCEPT" ]]; then
7180 skip_noexit "$skip_message"
7183 [ -n "$LAST_SKIPPED" ] &&
7184 echo "" && LAST_SKIPPED=
7186 run_one_logged $testnum "$testmsg"
7196 if [ -n "$ALWAYS_SKIPPED" ]; then
7198 skip_noexit "$skip_message"
7201 run_one_logged $testnum "$testmsg"
7208 load_module ../libcfs/libcfs/libcfs
7221 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
7226 strace -o $TMP/$1.strace -ttt $*
7228 log "FINISHED: $*: rc $RC"
7235 banner "test complete, duration $duration sec"
7236 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
7237 echo "duration $duration" >>$TESTSUITELOG
7241 # Set TEST_STATUS here. It will be used for logging the result.
7244 if [[ -f $LOGDIR/err ]]; then
7246 elif [[ -f $LOGDIR/skip ]]; then
7249 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
7253 local FFREE=$(do_node $SINGLEMDS \
7254 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
7255 local FTOTAL=$(do_node $SINGLEMDS \
7256 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
7258 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
7263 #echo -n "Resetting fail_loc on all nodes..."
7264 do_nodes --quiet $(comma_list $(nodes_list)) \
7265 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
7271 # Log a message (on all nodes) padded with "=" before and after.
7272 # Also appends a timestamp and prepends the testsuite name.
7275 # ======================================================== 15:06:12 (1624050372)
7276 EQUALS="========================================================"
7278 msg="== ${TESTSUITE} $*"
7280 [[ $last != "=" && $last != " " ]] && msg="$msg "
7281 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
7282 # always include at least == after the message
7283 log "$msg== $(date +"%H:%M:%S (%s)")"
7286 check_dmesg_for_errors() {
7288 local errors="VFS: Busy inodes after unmount of\|\
7289 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
7290 group descriptors corrupted"
7292 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
7293 [ -z "$res" ] && return 0
7294 echo "Kernel error detected: $res"
7299 # Run a single test function and cleanup after it.
7301 # This function should be run in a subshell so the test func can
7302 # exit() without stopping the whole script.
7307 local SAVE_UMASK=`umask`
7310 if ! grep -q $DIR /proc/mounts; then
7314 banner "test $testnum: $testmsg"
7315 test_${testnum} || error "test_$testnum failed with $?"
7318 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7320 check_dmesg_for_errors || error "Error in dmesg detected"
7321 if [ "$PARALLEL" != "yes" ]; then
7322 ps auxww | grep -v grep | grep -q "multiop " &&
7323 error "multiop still running"
7331 # Wrapper around run_one to ensure:
7332 # - test runs in subshell
7333 # - output of test is saved to separate log file for error reporting
7334 # - test result is saved to data file
7337 local before=$SECONDS
7340 export tfile=f${testnum}.${TESTSUITE}
7341 export tdir=d${testnum}.${TESTSUITE}
7342 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7343 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7344 local SAVE_UMASK=$(umask)
7347 declare -A kptr_restrict
7348 declare -A debug_raw
7351 for node in $(all_nodes); do
7352 kptr_restrict[$node]=$(do_node $node "sysctl --values kernel/kptr_restrict")
7353 do_node $node "sysctl -wq kernel/kptr_restrict=1"
7354 # Enable %p to be unhashed (if supported)
7355 debug_raw[$node]=$(do_node $node "$LCTL get_param -n debug_raw_pointers" || echo 0)
7356 do_node $node "$LCTL set_param debug_raw_pointers=Y || true"
7359 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7361 # if $ONLY is set, repeat subtest $ONLY_REPEAT times, otherwise once
7362 local repeat=${ONLY:+$ONLY_REPEAT}
7364 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
7365 local before_sub=$SECONDS
7367 log_sub_test_begin $TESTNAME
7368 # remove temp files between repetitions to avoid test failures
7369 if [[ -n "$append" ]]; then
7370 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7371 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7372 echo "subtest iteration $testiter/$repeat"
7374 # loop around subshell so stack_trap EXIT triggers each time
7375 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
7378 local duration_sub=$((SECONDS - before_sub))
7381 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7382 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7384 if [[ -f $LOGDIR/err ]]; then
7385 test_error=$(cat $LOGDIR/err)
7387 elif [[ -f $LOGDIR/ignore ]]; then
7388 test_error=$(cat $LOGDIR/ignore)
7389 elif [[ -f $LOGDIR/skip ]]; then
7390 test_error=$(cat $LOGDIR/skip)
7396 pass "$testnum" "(${duration_sub}s)"
7397 if [ -n "${DUMP_OK}" ]; then
7398 gather_logs $(comma_list $(nodes_list))
7401 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7402 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7406 for node in $(all_nodes); do
7407 param="kernel/kptr_restrict=${kptr_restrict[$node]}"
7408 do_node $node "sysctl -wq ${param} || true"
7409 # Restore %p to initial state
7410 param="debug_raw_pointers=${debug_raw[$node]}"
7411 do_node $node "$LCTL set_param ${param} || true"
7414 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7418 if [ -f $LOGDIR/err ]; then
7419 log_zfs_info "$zfs_debug_log"
7420 $FAIL_ON_ERROR && exit $rc
7433 # Print information of skipped tests to result.yml
7436 log_sub_test_begin $1
7438 log_sub_test_end "SKIP" "0" "0" "$@"
7441 grant_from_clients() {
7445 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7449 grant_from_servers() {
7453 # which is tot_granted less grant_precreate
7454 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7455 " obdfilter.${FSNAME}-OST*.tot_pending" \
7456 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7457 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7458 /tot_pending/{ total -= $2 };
7459 /grant_precreate/{ total -= $2 };
7460 END { printf("%0.0f", total) }'
7464 export base=$(basetest $1)
7465 [ "$CHECK_GRANT" == "no" ] && return 0
7467 local isonly_base=GCHECK_ONLY_${base}
7468 local isonly=GCHECK_ONLY_$1
7469 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7471 echo -n "checking grant......"
7473 local osts=$(comma_list $(osts_nodes))
7474 local clients=$CLIENTS
7475 [ -z "$clients" ] && clients=$(hostname)
7477 # sync all the data and make sure no pending data on server
7478 do_nodes $clients sync
7479 do_nodes $clients $LFS df # initiate all idling connections
7482 cli_grant=$(grant_from_clients $clients)
7485 # which is tot_granted less grant_precreate
7486 srv_grant=$(grant_from_servers $osts)
7489 # check whether client grant == server grant
7490 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7491 echo "wait for client:$cli_grant == server:$srv_grant"
7493 cli_grant=$(grant_from_clients $clients)
7494 srv_grant=$(grant_from_servers $osts)
7496 if [[ $cli_grant -ne $srv_grant ]]; then
7497 do_nodes $(comma_list $(osts_nodes)) \
7498 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7499 "obdfilter.${FSNAME}-OST*.grant_*"
7500 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7501 error "failed grant check: client:$cli_grant server:$srv_grant"
7503 echo "pass grant check: client:$cli_grant server:$srv_grant"
7507 ########################
7516 ostuuid_from_index() {
7517 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7518 local uuid=($($LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7523 ostname_from_index() {
7524 local uuid=$(ostuuid_from_index $1 $2)
7529 mdtuuid_from_index() {
7530 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7531 local uuid=($($LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7536 mdtname_from_index() {
7537 local uuid=$(mdtuuid_from_index $1 $2)
7542 mdssize_from_index() {
7543 local mdt=$(mdtname_from_index $2)
7545 $LFS df $1 | awk "/$mdt/ { print \$2 }"
7548 index_from_ostuuid()
7550 # only print the first index, if 'lfs osts' shows multiple mountpoints
7551 local ostidx=($($LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"))
7557 # Return unique identifier for given hostname
7560 echo $host_name | md5sum | cut -d' ' -f1
7564 # Returns list of ip addresses for each interface
7566 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7570 # Returns list of interfaces configured for LNet
7572 local nids=( $($LCTL list_nids | xargs echo) )
7574 [[ -z ${nids[@]} ]] &&
7577 if [[ ${NETTYPE} =~ kfi* ]]; then
7578 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7579 sort -u | xargs echo
7583 declare -a INTERFACES
7585 for ((i = 0; i < ${#nids[@]}; i++)); do
7586 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7587 INTERFACES[i]=$(ip -o a s |
7588 awk '$4 ~ /^'$ip'\//{print $2}')
7589 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7590 if [[ -z ${INTERFACES[i]} ]]; then
7591 error "Can't determine interface name for NID ${nids[i]}"
7592 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7593 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7597 echo "${INTERFACES[@]}"
7602 # return 1 if addr is remote
7603 # return 0 if addr is local
7606 # Cache address list to avoid mutiple execution of local_addr_list
7607 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7609 for i in $LOCAL_ADDR_LIST ; do
7610 [[ "$i" == "$addr" ]] && return 0
7615 # return true(0) if host_name is local
7616 # return false(1) if host_name is remote
7619 local is_local="IS_LOCAL_$(host_id $host_name)"
7621 if [ -z "${!is_local-}" ] ; then
7622 eval $is_local=false
7623 local host_ip=$(getent ahostsv4 $host_name |
7624 awk 'NR == 1 { print $1 }')
7625 is_local_addr "$host_ip" && eval $is_local=true
7639 for node in $(mdts_nodes); do
7640 remote_node $node && return 0
7647 [ -n "$CLIENTONLY" ] && return 0 || true
7648 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7653 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7654 MSKIPPED=1 && return 1
7661 for node in $(osts_nodes) ; do
7662 remote_node $node && return 0
7669 [ -n "$CLIENTONLY" ] && return 0 || true
7670 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7675 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7676 OSKIPPED=1 && return 1
7682 [ -n "$CLIENTONLY" ] && return 0 || true
7684 MGS=$(facet_host mgs)
7685 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7690 remote_mds_nodsh || remote_ost_nodsh ||
7691 $(single_local_node $(comma_list $(nodes_list)))
7695 remote_ost && remote_mds
7698 # Get the active nodes for facets.
7706 for facet in ${facets//,/ }; do
7707 nodes="$nodes $(facet_active_host $facet)"
7710 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7714 # Get name of the active MGS node.
7716 echo -n $(facets_nodes $(get_facets MGS))
7719 # Get all of the active MDS nodes.
7721 echo -n $(facets_nodes $(get_facets MDS))
7724 # Get all of the active OSS nodes.
7726 echo -n $(facets_nodes $(get_facets OST))
7729 # Get all of the client nodes and active server nodes.
7731 local nodes=$HOSTNAME
7735 # CLIENTS (if specified) contains the local client
7736 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7738 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7739 nodes="$nodes $(facets_nodes $(get_facets))"
7742 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7746 # Get all of the remote client nodes and remote active server nodes.
7747 remote_nodes_list () {
7748 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7751 # Get all of the MDS nodes, including active and passive nodes.
7759 for i in $(seq $MDSCOUNT); do
7761 failover_host=mds${i}failover_HOST
7762 nodes="$nodes ${!host} ${!failover_host}"
7765 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7766 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7770 # Get all of the OSS nodes, including active and passive nodes.
7778 for i in $(seq $OSTCOUNT); do
7780 failover_host=ost${i}failover_HOST
7781 nodes="$nodes ${!host} ${!failover_host}"
7784 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7785 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7789 # Get all of the server nodes, including active and passive nodes.
7790 all_server_nodes () {
7795 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7797 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7801 # Get all of the client and server nodes, including active and passive nodes.
7803 local nodes=$HOSTNAME
7807 # CLIENTS (if specified) contains the local client
7808 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7810 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7811 nodes="$nodes $(all_server_nodes)"
7814 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7818 init_clients_lists () {
7819 # Sanity check: exclude the local client from RCLIENTS
7820 local clients=$(hostlist_expand "$RCLIENTS")
7821 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7823 # Sanity check: exclude the dup entries
7824 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7826 export CLIENT1=${CLIENT1:-$HOSTNAME}
7827 export SINGLECLIENT=$CLIENT1
7829 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7831 # Sanity check: exclude the dup entries from CLIENTS
7832 # for those configs which has SINGLCLIENT set to local client
7833 clients=$(for i in $clients; do echo $i; done | sort -u)
7835 export CLIENTS=$(comma_list $clients)
7836 local -a remoteclients=($RCLIENTS)
7837 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7838 varname=CLIENT$((i + 2))
7840 eval export $varname=${remoteclients[i]}
7843 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7846 get_random_entry () {
7849 rnodes=${rnodes//,/ }
7851 local -a nodes=($rnodes)
7852 local num=${#nodes[@]}
7853 local i=$((RANDOM * num * 2 / 65536))
7859 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7863 # this should already have been called, but just in case
7864 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7867 echo "client=$CLIENT_VERSION MDS=$MDS1_VERSION OSS=$OST1_VERSION"
7869 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7870 error "unable to determine node versions"
7872 (( "$CLIENT_VERSION" == "$MDS1_VERSION" &&
7873 "$CLIENT_VERSION" == "$OST1_VERSION"))
7879 echo $nodes | wc -w || true
7883 local nodes=$(mdts_nodes)
7884 local mdtcount=$(get_node_count "$nodes")
7886 [ ! "$MDSCOUNT" = "$mdtcount" ]
7889 generate_machine_file() {
7890 local nodes=${1//,/ }
7891 local machinefile=$2
7894 for node in $nodes; do
7895 echo $node >>$machinefile ||
7896 { echo "can not generate machinefile $machinefile" &&
7902 local file=$1/stripe
7905 $LFS getstripe -v $file || error "getstripe $file failed"
7909 # Check and add a test group.
7915 local gid=$(getent group $group_name | cut -d: -f3)
7916 if [[ -n "$gid" ]]; then
7917 [[ "$gid" -eq "$group_id" ]] || {
7918 error_noexit "inconsistent group ID:" \
7919 "new: $group_id, old: $gid"
7923 echo "adding group $group_name:$group_id"
7924 getent group $group_name || true
7925 getent group $group_id || true
7926 groupadd -g $group_id $group_name
7933 # Check and add a test user.
7946 local uid=$(getent passwd $user_name | cut -d: -f3)
7947 if [[ -n "$uid" ]]; then
7948 if [[ "$uid" -eq "$user_id" ]]; then
7949 local dir=$(getent passwd $user_name | cut -d: -f6)
7950 if [[ "$dir" != "$home" ]]; then
7952 usermod -d $home $user_name
7956 error_noexit "inconsistent user ID:" \
7957 "new: $user_id, old: $uid"
7962 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
7969 check_runas_id_ret() {
7971 local myRUNAS_UID=$1
7972 local myRUNAS_GID=$2
7976 if [ -z "$myRUNAS" ]; then
7977 error_exit "check_runas_id_ret requires myRUNAS argument"
7981 error "Unable to execute $myRUNAS"
7983 id $myRUNAS_UID > /dev/null ||
7984 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
7985 "some UID which exists on MDS and client or add user " \
7986 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
7989 $myRUNAS krb5_login.sh ||
7990 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
7992 mkdir $DIR/d0_runas_test
7994 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
7995 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
7996 rm -rf $DIR/d0_runas_test
8001 local myRUNAS_UID=$1
8002 local myRUNAS_GID=$2
8006 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
8007 error "unable to write to $DIR/d0_runas_test as " \
8011 # obtain the UID/GID for MPI_USER
8015 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
8016 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
8018 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
8019 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
8022 # Run multiop in the background, but wait for it to print
8023 # "PAUSING" to its stdout before returning from this function.
8024 multiop_bg_pause() {
8025 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
8029 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
8032 echo "$MULTIOP_PROG $FILE v$ARGS"
8033 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
8036 echo "TMPPIPE=${TMPPIPE}"
8037 read -t 60 multiop_output < $TMPPIPE
8038 if [ $? -ne 0 ]; then
8043 if [ "$multiop_output" != "PAUSING" ]; then
8044 echo "Incorrect multiop output: $multiop_output"
8059 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
8061 echo $((SECONDS - start))
8065 inodes_available () {
8066 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
8067 sort -un | head -n1) || return 1
8072 mdsrate_inodes_available () {
8073 local min_inodes=$(inodes_available)
8075 echo $((min_inodes * 99 / 100))
8078 bytes_available () {
8079 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
8082 mdsrate_bytes_available () {
8083 local bytes=$(bytes_available)
8085 echo $((bytes * 99 / 100))
8088 # reset stat counters
8090 local paramfile="$1"
8092 lctl set_param -n $paramfile=0
8097 local paramfile="$1"
8100 lctl get_param -n $paramfile |
8101 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
8105 awk '{sum += $1} END { printf("%0.0f", sum) }'
8108 calc_osc_kbytes () {
8109 $LFS df $MOUNT > /dev/null
8110 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
8114 wait_delete_completed
8115 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8116 echo "OST kbytes available: ${AVAIL[*]}"
8121 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8122 #echo OST $i: ${AVAIL[i]}kb
8123 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8127 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8132 echo "Min free space: OST $MINI: $MINV"
8133 echo "Max free space: OST $MAXI: $MAXV"
8136 # save_lustre_params(comma separated facet list, parameter_mask)
8137 # generate a stream of formatted strings (<facet> <param name>=<param value>)
8138 save_lustre_params() {
8143 for facet in ${facets//,/ }; do
8144 facet_svc=$(facet_svc $facet)
8146 "params=\\\$($LCTL get_param $2);
8147 [[ -z \\\"$facet_svc\\\" ]] && param= ||
8148 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
8149 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
8150 while read s; do echo $facet \\\$s;
8151 done <<< \\\"\\\$param\\\""
8155 # restore lustre parameters from input stream, produces by save_lustre_params
8156 restore_lustre_params() {
8161 while IFS=" =" read facet name val; do
8162 do_facet $facet "$LCTL set_param -n $name=$val"
8166 check_node_health() {
8167 local nodes=${1:-$(comma_list $(nodes_list))}
8168 local health=$TMP/node_health.$$
8170 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
8171 grep "catastrophe=1" && error "LBUG/LASSERT detected"
8172 # Only check/report network health if get_param isn't reported, since
8173 # *clearly* the network is working if get_param returned something.
8174 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
8175 for node in ${nodes//,/ }; do
8176 check_network $node 5
8182 mdsrate_cleanup () {
8184 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
8185 --nfiles $3 --dir $4 --filefmt $5 $6
8191 local test_type="$1"
8204 local mdtest_basedir
8205 local mdtest_actions
8206 local mdtest_options
8207 local stripe_options
8210 case "$test_type" in
8212 stripe_options=(-c 1 -i 0)
8213 mdtest_actions=(-F -R)
8218 stripe_options=(-c -1)
8219 mdtest_actions=(-F -R)
8220 file_size=$((1024 * 1024 * 1024))
8224 stripe_options=(-c 1)
8225 mdtest_actions=(-C -D -E -k -r)
8230 stripe_options=(-c 1)
8231 mdtest_actions=(-C -D -E -k -r)
8236 stripe_options=(-c -1)
8242 if [[ -n "$MDTEST_DEBUG" ]]; then
8243 mdtest_options+=(-v -v -v)
8246 num_dirs=${NUM_DIRS:-$num_dirs}
8247 num_files=${NUM_FILES:-$num_files}
8248 file_size=${FILE_SIZE:-$file_size}
8249 free_space=$(mdsrate_bytes_available)
8251 if (( file_size * num_files > free_space )); then
8252 file_size=$((free_space / num_files))
8253 log "change file size to $file_size due to" \
8254 "number of files $num_files and" \
8255 "free space limit in $free_space"
8258 if (( file_size > 0 )); then
8259 log "set file size to $file_size"
8260 mdtest_options+=(-w=$file_size)
8263 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
8264 mdtest_basedir=$MOUNT/mdtest
8265 mdtest_options+=(-d=$mdtest_basedir)
8268 num_hosts=$(get_node_count ${CLIENTS//,/ })
8269 num_procs=$((num_cores * num_hosts))
8270 num_inodes=$(mdsrate_inodes_available)
8272 if (( num_inodes < num_files )); then
8273 log "change the number of files $num_files to the" \
8274 "number of available inodes $num_inodes"
8275 num_files=$num_inodes
8278 if (( num_dirs > 1 )); then
8279 num_entries=$((num_files / num_dirs))
8280 log "split $num_files files to $num_dirs" \
8281 "with $num_entries files each"
8282 mdtest_options+=(-I=$num_entries)
8285 generate_machine_file $CLIENTS $MACHINEFILE ||
8286 error "can not generate machinefile"
8288 install -v -d -m 0777 $mdtest_basedir
8290 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
8292 save_lustre_params $(get_facets MDS) \
8293 mdt.*.enable_remote_dir_gid > $params_file
8295 do_nodes $(comma_list $(mdts_nodes)) \
8296 $LCTL set_param mdt.*.enable_remote_dir_gid=-1
8298 stack_trap "restore_lustre_params < $params_file" EXIT
8300 for np in 1 $num_procs; do
8301 num_entries=$((num_files / np ))
8303 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8304 -np $np -npernode $num_cores $MDTEST \
8305 ${mdtest_options[@]} -n=$num_entries \
8306 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
8310 if (( rc != 0 )); then
8311 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8312 -np $np -npernode $num_cores $MDTEST \
8313 ${mdtest_options[@]} -n=$num_entries \
8314 -r 2>&1 | tee -a "$LOG"
8319 rmdir -v $mdtest_basedir
8320 rm -v $state $MACHINEFILE
8325 ########################
8327 convert_facet2label() {
8330 if [ x$facet = xost ]; then
8332 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8336 local varsvc=${facet}_svc
8338 if [ -n "${!varsvc}" ]; then
8341 error "No label for $facet!"
8345 get_clientosc_proc_path() {
8346 echo "${1}-osc-[-0-9a-f]*"
8349 get_mdtosc_proc_path() {
8351 local ost_label=${2:-"*OST*"}
8353 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8354 local mdt_label=$(convert_facet2label $mds_facet)
8355 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8357 if [[ $ost_label = *OST* ]]; then
8358 echo "${ost_label}-osc-${mdt_index}"
8360 echo "${ost_label}-osp-${mdt_index}"
8364 get_osc_import_name() {
8367 local label=$(convert_facet2label $ost)
8369 if [ "${facet:0:3}" = "mds" ]; then
8370 get_mdtosc_proc_path $facet $label
8374 get_clientosc_proc_path $label
8378 _wait_import_state () {
8380 local CONN_PROC="$2"
8381 local maxtime=${3:-$(max_recovery_time)}
8382 local err_on_fail=${4:-1}
8386 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8387 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8388 if [[ "${expected}" == "DISCONN" ]]; then
8389 # for disconn we can check after proc entry is removed
8390 [[ -z "${CONN_STATE}" ]] && return 0
8391 # with AT, we can have connect request timeout near
8392 # reconnect timeout and test can't see real disconnect
8393 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8395 if (( $i >= $maxtime )); then
8396 (( $err_on_fail != 0 )) &&
8397 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8401 # Add uniq for multi-mount case
8402 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8407 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8411 wait_import_state() {
8414 local maxtime=${3:-$(max_recovery_time)}
8415 local err_on_fail=${4:-1}
8418 for param in ${params//,/ }; do
8419 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8424 wait_import_state_mount() {
8425 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8429 wait_import_state "$@"
8432 # One client request could be timed out because server was not ready
8433 # when request was sent by client.
8434 # The request timeout calculation details :
8436 # /* We give the server rq_timeout secs to process the req, and
8437 # add the network latency for our local timeout. */
8438 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8439 # ptlrpc_at_get_net_latency(request) ;
8441 # ptlrpc_connect_import ()
8442 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8445 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8446 # ptlrpc_at_get_net_latency(request) ->
8447 # at_get (max (iat_net_latency=0, at_min)) = at_min
8450 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8451 # INITIAL_CONNECT_TIMEOUT + at_min
8453 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8454 # because we can not get this value in runtime,
8455 # the value depends on configure options, and it is not stored in /proc.
8457 # #define CONNECTION_SWITCH_MIN 5U
8458 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8460 request_timeout () {
8463 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8464 local init_connect_timeout=$TIMEOUT
8465 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8467 local at_min=$(at_get $facet at_min)
8469 echo $(( init_connect_timeout + at_min ))
8472 _wait_osc_import_state() {
8476 local target=$(get_osc_import_name $facet $ost_facet)
8477 local param="os[cp].${target}.ost_server_uuid"
8481 # 1. wait the deadline of client 1st request (it could be skipped)
8482 # 2. wait the deadline of client 2nd request
8483 local maxtime=$(( 2 * $(request_timeout $facet)))
8485 if [[ $facet == client* ]]; then
8486 # During setup time, the osc might not be setup, it need wait
8487 # until list_param can return valid value.
8488 params=$($LCTL list_param $param 2>/dev/null || true)
8489 while [ -z "$params" ]; do
8490 if [ $i -ge $maxtime ]; then
8491 echo "can't get $param in $maxtime secs"
8496 params=$($LCTL list_param $param 2>/dev/null || true)
8500 if [[ $ost_facet = mds* ]]; then
8501 # no OSP connection to itself
8502 if [[ $facet = $ost_facet ]]; then
8505 param="osp.${target}.mdt_server_uuid"
8509 local plist=$(comma_list $params)
8510 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8511 wait_import_state $expected $plist $maxtime; then
8512 error "$facet: import is not in $expected state after $maxtime"
8519 wait_osc_import_state() {
8525 if [[ $facet = mds ]]; then
8526 for num in $(seq $MDSCOUNT); do
8527 _wait_osc_import_state mds$num "$ost_facet" "$expected"
8530 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
8534 wait_osc_import_ready() {
8535 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
8538 _wait_mgc_import_state() {
8541 local error_on_failure=${3:-1}
8542 local param="mgc.*.mgs_server_uuid"
8546 # 1. wait the deadline of client 1st request (it could be skipped)
8547 # 2. wait the deadline of client 2nd request
8548 local maxtime=$(( 2 * $(request_timeout $facet)))
8550 if [[ $facet == client* ]]; then
8551 # During setup time, the osc might not be setup, it need wait
8552 # until list_param can return valid value. And also if there
8553 # are mulitple osc entries we should list all of them before
8555 params=$($LCTL list_param $param 2>/dev/null || true)
8556 while [ -z "$params" ]; do
8557 if [ $i -ge $maxtime ]; then
8558 echo "can't get $param in $maxtime secs"
8563 params=$($LCTL list_param $param 2>/dev/null || true)
8566 local plist=$(comma_list $params)
8567 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8568 wait_import_state $expected $plist $maxtime \
8569 $error_on_failure; then
8570 if [ $error_on_failure -ne 0 ]; then
8571 error "import is not in ${expected} state"
8579 wait_mgc_import_state() {
8582 local error_on_failure=${3:-1}
8585 if [[ $facet = mds ]]; then
8586 for num in $(seq $MDSCOUNT); do
8587 _wait_mgc_import_state mds$num "$expected" \
8588 $error_on_failure || return
8591 _wait_mgc_import_state "$facet" "$expected" \
8592 $error_on_failure || return
8596 wait_dne_interconnect() {
8599 if [ $MDSCOUNT -gt 1 ]; then
8600 for num in $(seq $MDSCOUNT); do
8601 wait_osc_import_ready mds mds$num
8606 get_clientmdc_proc_path() {
8610 get_clientmgc_proc_path() {
8617 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8622 [ -z "$list" ] && return 0
8624 # Add paths to lustre tests for 32 and 64 bit systems.
8625 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8626 local TESTPATH="$RLUSTRE/tests:"
8627 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8628 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8629 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8633 wait_clients_import_state () {
8637 local facets="$facet"
8639 if [ "$FAILURE_MODE" = HARD ]; then
8640 facets=$(for f in ${facet//,/ }; do
8641 facets_on_host $(facet_active_host $f) | tr "," "\n"
8642 done | sort -u | paste -sd , )
8645 for facet in ${facets//,/ }; do
8646 local label=$(convert_facet2label $facet)
8649 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8650 $label).ost_server_uuid" ;;
8651 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8652 $label).mds_server_uuid" ;;
8653 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8654 $label).mgs_server_uuid" ;;
8655 *) error "unknown facet!" ;;
8658 local params=$(expand_list $params $proc_path)
8661 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8663 error "import is not in ${expected} state"
8668 wait_clients_import_ready() {
8669 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
8679 # wait until all MDTs are in the expected state
8680 for ((num = 1; num <= $MDSCOUNT; num++)); do
8681 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8685 if [ $facet = "mds" ]; then
8686 mproc="osp.$mdtosp.active"
8687 [ $num -eq $((tgt_idx + 1)) ] && continue
8689 mproc="osc.$mdtosp.active"
8695 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8698 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
8699 if [ $result -eq $expected ]; then
8700 echo -n "target updated after "
8701 echo "$wait sec (got $result)"
8705 if [ $wait -eq $max ]; then
8706 error "$tgt_name: wanted $expected got $result"
8708 echo "Waiting $((max - wait)) secs for $tgt_name"
8718 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8719 $LCTL get_param obdfilter.*.kbytesavail))
8720 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8721 $LCTL get_param -n obdfilter.*.tot_granted))
8722 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8723 $LCTL get_param -n obdfilter.*.kbytestotal))
8724 for ((i=0; i<${#AVAILA[@]}; i++)); do
8725 local -a AVAIL1=(${AVAILA[$i]//=/ })
8726 local -a TOTAL=(${TOTALA[$i]//=/ })
8727 GRANT=$((${GRANTA[$i]}/1024))
8728 # allow 1% of total space in bavail because of delayed
8729 # allocation with ZFS which might release some free space after
8730 # txg commit. For small devices, we set a mininum of 8MB
8731 local LIMIT=$((${TOTAL} / 100 + 8000))
8732 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8733 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8734 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8735 echo " FULL" || echo
8741 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8744 check_pool_not_exist() {
8745 local fsname=${1%%.*}
8746 local poolname=${1##$fsname.}
8747 [[ $# -ne 1 ]] && return 0
8748 [[ x$poolname = x ]] && return 0
8749 list_pool $fsname | grep -w $1 && return 1
8754 local fsname=${1%%.*}
8755 local poolname=${1##$fsname.}
8756 local keep_pools=${2:-false}
8758 stack_trap "destroy_test_pools $fsname" EXIT
8759 do_facet mgs lctl pool_new $1
8761 # get param should return err unless pool is created
8762 [[ $RC -ne 0 ]] && return $RC
8764 for mds_id in $(seq $MDSCOUNT); do
8765 local mdt_id=$((mds_id-1))
8766 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8767 wait_update_facet mds$mds_id \
8768 "lctl get_param -n lod.$lodname.pools.$poolname \
8769 2>/dev/null || echo foo" "" ||
8770 error "mds$mds_id: pool_new failed $1"
8772 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8773 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8775 $keep_pools || add_pool_to_list $1
8779 add_pool_to_list () {
8780 local fsname=${1%%.*}
8781 local poolname=${1##$fsname.}
8783 local listvar=${fsname}_CREATED_POOLS
8784 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8788 remove_pool_from_list () {
8789 local fsname=${1%%.*}
8790 local poolname=${1##$fsname.}
8792 local listvar=${fsname}_CREATED_POOLS
8793 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8797 # cleanup all pools exist on $FSNAME
8798 destroy_all_pools () {
8800 for i in $(list_pool $FSNAME); do
8805 destroy_pool_int() {
8807 local OSTS=$(list_pool $1)
8808 for ost in $OSTS; do
8809 do_facet mgs lctl pool_remove $1 $ost
8811 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8812 error "MDS: pool_list $1 failed"
8813 do_facet mgs lctl pool_destroy $1
8816 # <fsname>.<poolname> or <poolname>
8818 local fsname=${1%%.*}
8819 local poolname=${1##$fsname.}
8821 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8825 check_pool_not_exist $fsname.$poolname && return 0 || true
8827 destroy_pool_int $fsname.$poolname
8829 [[ $RC -ne 0 ]] && return $RC
8830 for mds_id in $(seq $MDSCOUNT); do
8831 local mdt_id=$((mds_id-1))
8832 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8833 wait_update_facet mds$mds_id \
8834 "lctl get_param -n lod.$lodname.pools.$poolname \
8835 2>/dev/null || echo foo" "foo" ||
8836 error "mds$mds_id: destroy pool failed $1"
8838 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8839 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8841 remove_pool_from_list $fsname.$poolname
8847 local fsname=${1:-$FSNAME}
8849 local listvar=${fsname}_CREATED_POOLS
8851 [ x${!listvar} = x ] && return 0
8853 echo "Destroy the created pools: ${!listvar}"
8854 for poolname in ${!listvar//,/ }; do
8855 destroy_pool $fsname.$poolname
8859 destroy_test_pools () {
8860 local fsname=${1:-$FSNAME}
8861 destroy_pools $fsname || true
8867 local ts=$(date +%s)
8870 if [[ ! -f "$YAML_LOG" ]]; then
8871 # init_logging is not performed before gather_logs,
8872 # so the $LOGDIR needs to be checked here
8873 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8876 [ -f $LOGDIR/shared ] && docp=false
8878 # dump lustre logs, dmesg, and journal if GSS_SK=true
8880 prefix="$TESTLOG_PREFIX.$TESTNAME"
8882 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8884 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8885 echo "Dumping logs only on local client."
8886 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8887 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8888 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8889 $LGSS_SK -r {} \; &> \
8890 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8891 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8892 ${prefix}.nodemaps.$(hostname -s).${suffix}
8893 [ "$GSS" = true ] && keyctl show > \
8894 ${prefix}.keyring.$(hostname -s).${suffix}
8895 [ "$GSS" = true ] && journalctl -a > \
8896 ${prefix}.journal.$(hostname -s).${suffix}
8901 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8902 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8903 if [ "$SHARED_KEY" = true ]; then
8904 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8905 $LGSS_SK -r {} \; &> \
8906 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8907 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8908 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8910 if [ "$GSS" = true ]; then
8911 do_nodesv $list "keyctl show > \
8912 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8913 do_nodesv $list "journalctl -a > \
8914 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8917 if [ ! -f $LOGDIR/shared ]; then
8918 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8920 for node in ${remote_nodes//,/ }; do
8921 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8935 for i in $(seq 0 $num_mntpts); do
8936 cmd="ls -laf ${mntpt_root}$i/$dir"
8942 for pid in $pids; do
8949 # check_and_start_recovery_timer()
8950 # service_time = at_est2timeout(service_time);
8951 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8952 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8954 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8955 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
8956 #define CONNECTION_SWITCH_MIN 5
8957 #define CONNECTION_SWITCH_INC 5
8958 max_recovery_time() {
8959 local init_connect_timeout=$((TIMEOUT / 20))
8960 ((init_connect_timeout >= 5)) || init_connect_timeout=5
8962 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
8963 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
8965 echo -n $service_time
8968 recovery_time_min() {
8969 local connection_switch_min=5
8970 local connection_switch_inc=5
8971 local connection_switch_max
8972 local reconnect_delay_max
8973 local initial_connect_timeout
8977 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
8978 (($connection_switch_min > $TIMEOUT)) &&
8979 max=$connection_switch_min || max=$TIMEOUT
8980 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
8982 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
8983 timeout_20=$((TIMEOUT/20))
8984 (($connection_switch_min > $timeout_20)) &&
8985 initial_connect_timeout=$connection_switch_min ||
8986 initial_connect_timeout=$timeout_20
8988 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
8989 initial_connect_timeout))
8990 echo $((2 * reconnect_delay_max))
8993 get_clients_mount_count () {
8994 local clients=${CLIENTS:-$HOSTNAME}
8996 # we need to take into account the clients mounts and
8997 # exclude mds/ost mounts if any;
8998 do_nodes $clients cat /proc/mounts | grep lustre |
8999 grep -w $MOUNT | wc -l
9003 PROC_CLI="srpc_info"
9004 PROC_CON="srpc_contexts"
9012 if [ $M -lt $N ]; then
9016 while [ $N -lt $M ]; do
9026 calc_connection_cnt() {
9029 # MDT->MDT = 2 * C(M, 2)
9033 comb_m2=$(combination $MDSCOUNT 2)
9035 local num_clients=$(get_clients_mount_count)
9037 local cnt_mdt2mdt=$((comb_m2 * 2))
9038 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
9039 local cnt_cli2ost=$((num_clients * OSTCOUNT))
9040 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
9041 if is_mounted $MOUNT2; then
9042 cnt_cli2mdt=$((cnt_cli2mdt * 2))
9043 cnt_cli2ost=$((cnt_cli2ost * 2))
9051 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
9052 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
9053 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
9054 + cnt_cli2ost + cnt_cli2mdt))
9068 local cmd="$tgt.srpc.flavor"
9070 if [ $net == "any" ]; then
9075 if [ $dir != "any" ]; then
9080 log "Setting sptlrpc rule: $cmd"
9081 do_facet mgs "$LCTL conf_param $cmd"
9087 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
9097 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
9098 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
9100 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
9102 if [ "x$bulkspec" != "x" ]; then
9103 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
9105 if [ "x$algs" != "x" ]; then
9106 bulk_count=`echo "$output" | grep "bulk flavor" |
9109 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
9111 if [ $bulk == "bulkn" ]; then
9112 bulk_count=`echo "$output" |
9113 grep "bulk flavor" | grep "null/null" |
9115 elif [ $bulk == "bulki" ]; then
9116 bulk_count=`echo "$output" |
9117 grep "bulk flavor" | grep "/null" |
9118 grep -v "null/" | wc -l`
9120 bulk_count=`echo "$output" |
9121 grep "bulk flavor" | grep -v "/null" |
9122 grep -v "null/" | wc -l`
9125 [ $bulk_count -lt $count ] && count=$bulk_count
9136 local clients=${CLIENTS:-$HOSTNAME}
9138 for c in ${clients//,/ }; do
9139 local output=$(do_node $c lctl get_param -n \
9140 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
9141 local tmpcnt=$(count_flvr "$output" $flavor)
9143 if $GSS_SK && [ $flavor != "null" ]; then
9144 # tmpcnt=min(contexts,flavors) to ensure SK context is
9146 output=$(do_node $c lctl get_param -n \
9147 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
9148 local outcon=$(count_contexts "$output")
9150 if [ "$outcon" -lt "$tmpcnt" ]; then
9154 cnt=$((cnt + tmpcnt))
9164 local clients=${CLIENTS:-$HOSTNAME}
9166 for c in ${clients//,/ }; do
9168 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
9169 local output=$(do_node $c lctl get_param -n \
9170 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
9171 local tmpcnt=$(count_flvr "$output" $flavor)
9173 if $GSS_SK && [ $flavor != "null" ]; then
9174 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9175 output=$(do_node $c lctl get_param -n \
9176 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
9177 local outcon=$(count_contexts "$output")
9179 if [ "$outcon" -lt "$tmpcnt" ]; then
9183 cnt=$((cnt + tmpcnt))
9193 if [ $MDSCOUNT -le 1 ]; then
9198 for num in `seq $MDSCOUNT`; do
9199 local output=$(do_facet mds$num lctl get_param -n \
9200 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
9201 local tmpcnt=$(count_flvr "$output" $flavor)
9203 if $GSS_SK && [ $flavor != "null" ]; then
9204 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9205 output=$(do_facet mds$num lctl get_param -n \
9206 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
9207 local outcon=$(count_contexts "$output")
9209 if [ "$outcon" -lt "$tmpcnt" ]; then
9213 cnt=$((cnt + tmpcnt))
9224 for num in `seq $MDSCOUNT`; do
9225 mdtosc=$(get_mdtosc_proc_path mds$num)
9226 mdtosc=${mdtosc/-MDT*/-MDT\*}
9227 local output=$(do_facet mds$num lctl get_param -n \
9228 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
9229 # Ensure SK context is on
9230 local tmpcnt=$(count_flvr "$output" $flavor)
9232 if $GSS_SK && [ $flavor != "null" ]; then
9233 output=$(do_facet mds$num lctl get_param -n \
9234 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
9235 local outcon=$(count_contexts "$output")
9237 if [ "$outcon" -lt "$tmpcnt" ]; then
9241 cnt=$((cnt + tmpcnt))
9250 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
9252 count_flvr "$output" $flavor
9257 local dir=$1 # from to
9258 local flavor=$2 # flavor expected
9261 if [ $dir == "cli2mdt" ]; then
9262 res=`flvr_cnt_cli2mdt $flavor`
9263 elif [ $dir == "cli2ost" ]; then
9264 res=`flvr_cnt_cli2ost $flavor`
9265 elif [ $dir == "mdt2mdt" ]; then
9266 res=`flvr_cnt_mdt2mdt $flavor`
9267 elif [ $dir == "mdt2ost" ]; then
9268 res=`flvr_cnt_mdt2ost $flavor`
9269 elif [ $dir == "all2ost" ]; then
9270 res1=`flvr_cnt_mdt2ost $flavor`
9271 res2=`flvr_cnt_cli2ost $flavor`
9272 res=$((res1 + res2))
9273 elif [ $dir == "all2mdt" ]; then
9274 res1=`flvr_cnt_mdt2mdt $flavor`
9275 res2=`flvr_cnt_cli2mdt $flavor`
9276 res=$((res1 + res2))
9277 elif [ $dir == "all2all" ]; then
9278 res1=`flvr_cnt_mdt2ost $flavor`
9279 res2=`flvr_cnt_cli2ost $flavor`
9280 res3=`flvr_cnt_mdt2mdt $flavor`
9281 res4=`flvr_cnt_cli2mdt $flavor`
9282 res=$((res1 + res2 + res3 + res4))
9290 local dir=$1 # from to
9291 local flavor=$2 # flavor expected
9292 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
9293 local WAITFLAVOR_MAX=20 # how many retries before abort?
9296 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
9297 echo -n "checking $dir..."
9298 res=$(do_check_flavor $dir $flavor)
9299 echo "found $res/$expect $flavor connections"
9300 [ $res -ge $expect ] && return 0
9304 echo "Error checking $flavor of $dir: expect $expect, actual $res"
9305 # echo "Dumping additional logs for SK debug.."
9306 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
9308 gather_logs $(comma_list $(nodes_list))
9313 restore_to_default_flavor()
9315 local proc="mgs.MGS.live.$FSNAME"
9317 echo "restoring to default flavor..."
9319 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9320 grep ".srpc.flavor" | wc -l)
9322 # remove all existing rules if any
9323 if [ $nrule -ne 0 ]; then
9324 echo "$nrule existing rules"
9325 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9326 grep ".srpc.flavor."); do
9327 echo "remove rule: $rule"
9328 spec=`echo $rule | awk -F = '{print $1}'`
9329 do_facet mgs "$LCTL conf_param -d $spec"
9333 # verify no rules left
9334 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9335 grep ".srpc.flavor." | wc -l)
9336 [ $nrule -ne 0 ] && error "still $nrule rules left"
9338 # wait for default flavor to be applied
9341 set_rule $FSNAME any any $SK_FLAVOR
9342 wait_flavor all2all $SK_FLAVOR
9344 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9345 set_rule $FSNAME any cli2ost $SK_FLAVOR
9346 wait_flavor cli2mdt $SK_FLAVOR
9347 wait_flavor cli2ost $SK_FLAVOR
9349 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9351 wait_flavor all2all null
9357 local flavor=${1:-null}
9359 echo "setting all flavor to $flavor"
9361 # FIXME need parameter to this fn
9362 # and remove global vars
9363 local cnt_all2all=$(calc_connection_cnt all2all)
9365 local res=$(do_check_flavor all2all $flavor)
9366 if [ $res -eq $cnt_all2all ]; then
9367 echo "already have total $res $flavor connections"
9371 echo "found $res $flavor out of total $cnt_all2all connections"
9372 restore_to_default_flavor
9374 [[ $flavor = null ]] && return 0
9376 if $GSS_SK && [ $flavor != "null" ]; then
9378 set_rule $FSNAME any any $flavor
9379 wait_flavor all2all $flavor
9381 set_rule $FSNAME any cli2mdt $flavor
9382 set_rule $FSNAME any cli2ost $flavor
9383 set_rule $FSNAME any mdt2ost null
9384 set_rule $FSNAME any mdt2mdt null
9385 wait_flavor cli2mdt $flavor
9386 wait_flavor cli2ost $flavor
9388 echo "GSS_SK now at flavor: $flavor"
9390 set_rule $FSNAME any cli2mdt $flavor
9391 set_rule $FSNAME any cli2ost $flavor
9392 set_rule $FSNAME any mdt2ost null
9393 set_rule $FSNAME any mdt2mdt null
9394 wait_flavor cli2mdt $flavor
9395 wait_flavor cli2ost $flavor
9402 # Checking for shared logdir
9403 if [ ! -d $dir ]; then
9404 # Not found. Create local logdir
9407 touch $dir/check_file.$(hostname -s)
9412 check_write_access() {
9414 local list=${2:-$(comma_list $(nodes_list))}
9418 for node in ${list//,/ }; do
9419 file=$dir/check_file.$(short_nodename $node)
9420 if [[ ! -f "$file" ]]; then
9421 # Logdir not accessible/writable from this node.
9424 rm -f $file || return 1
9430 [[ -n $YAML_LOG ]] && return
9431 local save_umask=$(umask)
9434 export YAML_LOG=${LOGDIR}/results.yml
9438 # If the yaml log already exists then we will just append to it
9439 if [ ! -f $YAML_LOG ]; then
9440 if check_shared_dir $LOGDIR; then
9441 touch $LOGDIR/shared
9442 echo "Logging to shared log directory: $LOGDIR"
9444 echo "Logging to local directory: $LOGDIR"
9447 yml_nodes_file $LOGDIR >> $YAML_LOG
9448 yml_results_file >> $YAML_LOG
9453 # log actual client and server versions if needed for debugging
9454 log "Client: $(lustre_build_version client)"
9455 log "MDS: $(lustre_build_version mds1)"
9456 log "OSS: $(lustre_build_version ost1)"
9460 yml_log_test $1 >> $YAML_LOG
9464 yml_log_test_status "$@" >> $YAML_LOG
9467 log_sub_test_begin() {
9468 yml_log_sub_test_begin "$@" >> $YAML_LOG
9471 log_sub_test_end() {
9472 yml_log_sub_test_end "$@" >> $YAML_LOG
9478 local llverdev_opts="$*"
9479 local devname=$(basename $dev)
9480 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
9481 # loop devices aren't in /proc/partitions
9482 [[ -z "$size" ]] && size=$(stat -c %s $dev)
9484 local size_gb=$((size / 1024 / 1024)) # Gb
9486 local partial_arg=""
9487 # Run in partial (fast) mode if the size of a partition > 1 GB
9488 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
9490 llverdev --force $partial_arg $llverdev_opts $dev
9496 local llverfs_opts=$2
9497 local use_partial_arg=$3
9498 local partial_arg=""
9499 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
9501 # Run in partial (fast) mode if the size of a partition > 1 GB
9502 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
9504 llverfs $partial_arg $llverfs_opts $dir
9508 local devs=${1//,/ }
9511 local rslt=$TMP/sgpdd_survey
9513 # sgpdd-survey cleanups ${rslt}.* files
9515 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
9521 # returns the canonical name for an ldiskfs device
9526 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
9527 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
9528 echo dm-\\\${foo##*:};
9530 name=\\\$(basename \\\$dv);
9531 if [[ \\\$name = *flakey* ]]; then
9532 name=\\\$(lsblk -o NAME,KNAME |
9533 awk /\\\$name/'{print \\\$NF}');
9539 is_sanity_benchmark() {
9540 local benchmarks="dbench bonnie iozone fsx"
9543 for b in $benchmarks; do
9544 if [ "$b" == "$suite" ]; then
9552 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
9556 # Get the available size (KB) of a given obd target.
9563 [[ $facet != client ]] || return 0
9565 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
9570 # Get the page size (bytes) on a given facet node.
9571 # The local client page_size is directly available in PAGE_SIZE.
9575 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
9577 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
9578 page_size=$(do_facet $facet getconf PAGE_SIZE)
9579 echo -n ${page_size:-4096}
9583 # Get the block count of the filesystem.
9590 [ -z "$CLIENTONLY" ] &&
9591 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
9592 awk '/^Block count:/ {print $3}')
9596 # Check whether the "ea_inode" feature is enabled or not, to allow
9597 # ldiskfs xattrs over one block in size. Allow both the historical
9598 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
9599 large_xattr_enabled() {
9600 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
9602 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
9604 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
9605 grep -E -q '(ea_inode|large_xattr)'"
9606 return ${PIPESTATUS[0]}
9609 # Get the maximum xattr size supported by the filesystem.
9611 $LCTL get_param -n llite.*.max_easize
9614 # Dump the value of the named xattr from a file.
9619 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9622 # Generate a string with size of $size bytes.
9624 local size=${1:-1024} # in bytes
9626 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9629 reformat_external_journal() {
9634 local varbs=${facet}_BLOCKSIZE
9635 if [ -n "${!var}" ]; then
9636 local rcmd="do_facet $facet"
9637 local bs=${!varbs:-$BLCKSIZE}
9640 echo "reformat external journal on $facet:${!var}"
9641 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9645 # MDT file-level backup/restore
9646 mds_backup_restore() {
9649 local devname=$(mdsdevname $(facet_number $facet))
9650 local mntpt=$(facet_mntpt brpt)
9651 local rcmd="do_facet $facet"
9652 local metadata=${TMP}/backup_restore.tgz
9653 local opts=${MDS_MOUNT_FS_OPTS}
9654 local svc=${facet}_svc
9656 if ! ${rcmd} test -b ${devname}; then
9657 opts=$(csa_add "$opts" -o loop)
9660 echo "file-level backup/restore on $facet:${devname}"
9662 # step 1: build mount point
9663 ${rcmd} mkdir -p $mntpt
9664 # step 2: cleanup old backup
9665 ${rcmd} rm -f $metadata
9667 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9668 if [ ! -z $igif ]; then
9669 # step 3.5: rm .lustre
9670 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9672 # step 4: backup metadata
9674 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9675 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9677 ${rcmd} $UMOUNT $mntpt || return 5
9678 # step 6: reformat dev
9679 echo "reformat new device"
9680 format_mdt $(facet_number $facet)
9682 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9683 # step 8: restore metadata
9685 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9686 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9687 # step 9: remove recovery logs
9688 echo "remove recovery logs"
9689 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9690 # step 10: umount dev
9691 ${rcmd} $UMOUNT $mntpt || return 10
9692 # step 11: cleanup tmp backup
9693 ${rcmd} rm -f $metaea $metadata
9694 # step 12: reset device label - it's not virgin on
9695 ${rcmd} e2label $devname ${!svc}
9702 local devname=$(mdsdevname $(facet_number $facet))
9703 local mntpt=$(facet_mntpt brpt)
9704 local rcmd="do_facet $facet"
9705 local opts=${MDS_MOUNT_FS_OPTS}
9707 if ! ${rcmd} test -b ${devname}; then
9708 opts=$(csa_add "$opts" -o loop)
9711 echo "removing OI files on $facet: idx=${idx}"
9713 # step 1: build mount point
9714 ${rcmd} mkdir -p $mntpt
9716 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9717 if [ -z $idx ]; then
9718 # step 3: remove all OI files
9719 ${rcmd} rm -fv $mntpt/oi.16*
9720 elif [ $idx -lt 2 ]; then
9721 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9725 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9726 for ((i=${idx}; i<64; i=$((i * idx)))); do
9727 ${rcmd} rm -fv $mntpt/oi.16.${i}
9731 ${rcmd} $UMOUNT $mntpt || return 2
9732 # OI files will be recreated when mounted as lustre next time.
9735 # generate maloo upload-able log file name
9736 # \param logname specify unique part of file name
9737 generate_logname() {
9738 local logname=${1:-"default_logname"}
9740 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9743 # make directory on different MDTs
9748 local hash_name=("all_char" "fnv_1a_64" "crush")
9749 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9750 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9752 local overstripe_count
9753 local stripe_command="-c"
9755 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9756 hash_name+=("crush2")
9758 while getopts "c:C:H:i:p" opt; do
9760 c) dirstripe_count=$OPTARG;;
9761 C) overstripe_count=$OPTARG;;
9762 H) hash_type=$OPTARG;;
9763 i) dirstripe_index=$OPTARG;;
9765 \?) error "only support -c -H -i -p";;
9769 shift $((OPTIND - 1))
9770 [ $# -eq 1 ] || error "Only creating single directory is supported"
9773 local parent=$(dirname $path)
9774 if [ "$p_option" == "-p" ]; then
9775 [ -d $path ] && return 0
9776 if [ ! -d ${parent} ]; then
9777 mkdir -p ${parent} ||
9778 error "mkdir parent '$parent' failed"
9782 if [[ -n "$overstripe_count" ]]; then
9784 dirstripe_count=$overstripe_count
9787 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9788 mkdir $path || error "mkdir '$path' failed"
9792 if [ $dirstripe_index -eq -1 ]; then
9793 mdt_index=$((base % MDSCOUNT))
9795 mdt_index=$dirstripe_index
9798 # randomly choose hash type
9799 [ -z "$hash_type" ] &&
9800 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9802 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9803 if [ $dirstripe_count -eq -1 ]; then
9804 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9810 echo "striped dir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path"
9811 $LFS mkdir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path ||
9812 error "mkdir -i $mdt_index $stripe_command$dirstripe_count -H $hash_type $path failed"
9816 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9818 # If called many times, passing @last_fd will avoid repeated searching
9819 # already-open FDs repeatedly if we know they are still in use.
9821 # usage: free_fd [last_fd]
9824 local max_fd=$(ulimit -n)
9825 local fd=$((${1:-2} + 1))
9827 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9830 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9834 check_mount_and_prep()
9836 is_mounted $MOUNT || setupall
9838 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9839 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9840 for idx in $(seq $MDSCOUNT); do
9841 local name="MDT$(printf '%04x' $((idx - 1)))"
9842 rm -rf $MOUNT/.lustre/lost+found/$name/*
9846 # calcule how many ost-objects to be created.
9847 precreated_ost_obj_count()
9851 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9852 local ost_name="OST$(printf '%04x' $ost_idx)"
9853 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
9854 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9855 osp.$proc_path.prealloc_last_id)
9856 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9857 osp.$proc_path.prealloc_next_id)
9858 echo $((last_id - next_id + 1))
9861 check_file_in_pool()
9866 local res=$($LFS getstripe $file | grep 0x | cut -f2)
9869 for t in $tlist ; do
9870 [ "$i" -eq "$t" ] && continue 2
9873 echo "pool list: $tlist"
9874 echo "striping: $res"
9875 error_noexit "$file not allocated in $pool"
9882 echo "Creating new pool"
9885 create_pool $FSNAME.$pool ||
9886 { error_noexit "No pool created, result code $?"; return 1; }
9887 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
9888 { error_noexit "$pool not in lfs pool_list"; return 2; }
9891 pool_add_targets() {
9892 echo "Adding targets to pool"
9898 if [ -z $last ]; then
9902 local list=$(seq $first $step $last)
9905 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9906 local tg=$(for i in $list;
9907 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
9908 local firstx=$(printf "%04x" $first)
9909 local lastx=$(printf "%04x" $last)
9911 do_facet mgs $LCTL pool_add \
9912 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
9914 if (( $? != 0 && $? != 17 )); then
9915 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
9919 # wait for OSTs to be added to the pool
9920 for mds_id in $(seq $MDSCOUNT); do
9921 local mdt_id=$((mds_id-1))
9922 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9923 wait_update_facet mds$mds_id \
9924 "lctl get_param -n lod.$lodname.pools.$pool |
9925 grep $tg | sort -u | tr '\n' ' '" "$t" || {
9926 error_noexit "mds$mds_id: Add to pool failed"
9930 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
9931 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
9932 error_noexit "Add to pool failed"
9940 echo "Setting pool on directory $tdir"
9942 $LFS setstripe -c 2 -p $pool $tdir && return 0
9944 error_noexit "Cannot set pool $pool to $tdir"
9951 echo "Checking pool on directory $tdir"
9953 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
9954 [ "$res" = "$pool" ] && return 0
9956 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9960 pool_dir_rel_path() {
9961 echo "Testing relative path works well"
9966 mkdir -p $root/$tdir/$tdir
9968 pool_set_dir $pool $tdir || return 1
9969 pool_set_dir $pool ./$tdir || return 2
9970 pool_set_dir $pool ../$tdir || return 3
9971 pool_set_dir $pool ../$tdir/$tdir || return 4
9972 rm -rf $tdir; cd - > /dev/null
9975 pool_alloc_files() {
9976 echo "Checking files allocation from directory pool"
9983 for i in $(seq -w 1 $count)
9985 local file=$tdir/file-$i
9987 check_file_in_pool $file $pool "$tlist" || \
9988 failed=$((failed + 1))
9990 [ "$failed" = 0 ] && return 0
9992 error_noexit "$failed files not allocated in $pool"
9996 pool_create_files() {
9997 echo "Creating files in pool"
10005 for i in $(seq -w 1 $count)
10007 local file=$tdir/spoo-$i
10008 $LFS setstripe -p $pool $file
10009 check_file_in_pool $file $pool "$tlist" || \
10010 failed=$((failed + 1))
10012 [ "$failed" = 0 ] && return 0
10014 error_noexit "$failed files not allocated in $pool"
10019 echo "Checking 'lfs df' output"
10022 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10024 local res=$($LFS df --pool $FSNAME.$pool |
10026 grep "$FSNAME-OST" |
10028 [ "$res" = "$t" ] && return 0
10030 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10034 pool_file_rel_path() {
10035 echo "Creating files in a pool with relative pathname"
10040 { error_noexit "unable to create $tdir"; return 1 ; }
10041 local file="/..$tdir/$tfile-1"
10042 $LFS setstripe -p $pool $file ||
10043 { error_noexit "unable to create $file" ; return 2 ; }
10046 $LFS setstripe -p $pool $tfile-2 || {
10047 error_noexit "unable to create $tfile-2 in $tdir"
10052 pool_remove_first_target() {
10053 echo "Removing first target from a pool"
10054 pool_remove_target $1 -1
10057 pool_remove_target() {
10061 local pname="lov.$FSNAME-*.pools.$pool"
10062 if [ $index -eq -1 ]; then
10063 local t=$($LCTL get_param -n $pname | head -1)
10065 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
10068 echo "Removing $t from $pool"
10069 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10070 for mds_id in $(seq $MDSCOUNT); do
10071 local mdt_id=$((mds_id-1))
10072 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10073 wait_update_facet mds$mds_id \
10074 "lctl get_param -n lod.$lodname.pools.$pool |
10076 error_noexit "mds$mds_id: $t not removed from" \
10081 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10082 error_noexit "$t not removed from $FSNAME.$pool"
10087 pool_remove_all_targets() {
10088 echo "Removing all targets from pool"
10091 local pname="lov.$FSNAME-*.pools.$pool"
10092 for t in $($LCTL get_param -n $pname | sort -u)
10094 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10096 for mds_id in $(seq $MDSCOUNT); do
10097 local mdt_id=$((mds_id-1))
10098 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10099 wait_update_facet mds$mds_id "lctl get_param -n \
10100 lod.$lodname.pools.$pool" "" || {
10101 error_noexit "mds$mds_id: Pool $pool not drained"
10105 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10106 error_noexit "Pool $FSNAME.$pool cannot be drained"
10109 # striping on an empty/nonexistant pool should fall back
10110 # to "pool of everything"
10112 error_noexit "failed to use fallback striping for empty pool"
10115 # setstripe on an empty pool should fail
10116 $LFS setstripe -p $pool $file 2>/dev/null && {
10117 error_noexit "expected failure when creating file" \
10125 echo "Destroying pool"
10129 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10132 # striping on an empty/nonexistant pool should fall back
10133 # to "pool of everything"
10135 error_noexit "failed to use fallback striping for missing pool"
10138 # setstripe on an empty pool should fail
10139 $LFS setstripe -p $pool $file 2>/dev/null && {
10140 error_noexit "expected failure when creating file" \
10141 "with missing pool"
10145 # get param should return err once pool is gone
10146 if wait_update $HOSTNAME "lctl get_param -n \
10147 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10149 remove_pool_from_list $FSNAME.$pool
10152 error_noexit "Pool $FSNAME.$pool is not destroyed"
10156 # Get and check the actual stripe count of one file.
10157 # Usage: check_stripe_count <file> <expected_stripe_count>
10158 check_stripe_count() {
10163 [[ -z "$file" || -z "$expected" ]] &&
10164 error "check_stripe_count: invalid argument"
10166 local cmd="$LFS getstripe -c $file"
10167 actual=$($cmd) || error "$cmd failed"
10168 actual=${actual%% *}
10170 if [[ $actual -ne $expected ]]; then
10171 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
10172 error "$cmd not expected ($expected): found $actual"; }
10173 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
10174 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
10178 # Get and check the actual list of OST indices on one file.
10179 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
10185 [[ -z "$file" || -z "$expected" ]] &&
10186 error "check_obdidx: invalid argument!"
10188 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
10189 grep -v obdidx | awk '{print $1}' | xargs))
10191 [[ $obdidx = $expected ]] ||
10192 error "list of OST indices on $file is $obdidx," \
10193 "should be $expected"
10196 # Get and check the actual OST index of the first stripe on one file.
10197 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
10198 check_start_ost_idx() {
10201 local start_ost_idx
10203 [[ -z "$file" || -z "$expected" ]] &&
10204 error "check_start_ost_idx: invalid argument!"
10206 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
10207 grep -v obdidx | awk '{print $1}')
10209 [[ $start_ost_idx = $expected ]] ||
10210 error "OST index of the first stripe on $file is" \
10211 "$start_ost_idx, should be $expected"
10214 killall_process () {
10215 local clients=${1:-$(hostname)}
10220 do_nodes $clients "killall $signal $name"
10225 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
10228 lsnapshot_destroy()
10230 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
10235 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
10240 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
10245 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
10250 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
10257 do_facet mgs "cat $LSNAPSHOT_LOG"
10263 echo "Cleaning test environment ..."
10265 # Every lsnapshot command takes exclusive lock with others,
10266 # so can NOT destroy the snapshot during list with 'xargs'.
10268 local ssname=$(lsnapshot_list | grep snapshot_name |
10269 grep lss_ | awk '{ print $2 }' | head -n 1)
10270 [ -z "$ssname" ] && break
10272 lsnapshot_destroy -n $ssname -f ||
10273 lss_err "Fail to destroy $ssname by force"
10283 local host=$(facet_active_host $facet)
10284 local dir=$(dirname $(facet_vdevice $facet))
10285 local pool=$(zpool_name $facet)
10286 local lfsname=$(zfs_local_fsname $facet)
10287 local label=${FSNAME}-${role}$(printf '%04x' $idx)
10290 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
10296 do_facet mgs "rm -f $LSNAPSHOT_CONF"
10297 echo "Generating $LSNAPSHOT_CONF on MGS ..."
10299 if ! combined_mgs_mds ; then
10300 [ $(facet_fstype mgs) != zfs ] &&
10301 skip "Lustre snapshot 1 only works for ZFS backend"
10303 local host=$(facet_active_host mgs)
10304 local dir=$(dirname $(facet_vdevice mgs))
10305 local pool=$(zpool_name mgs)
10306 local lfsname=$(zfs_local_fsname mgs)
10309 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
10310 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
10313 for num in `seq $MDSCOUNT`; do
10314 [ $(facet_fstype mds$num) != zfs ] &&
10315 skip "Lustre snapshot 1 only works for ZFS backend"
10317 lss_gen_conf_one mds$num MDT $((num - 1)) ||
10318 lss_err "generate lss conf (mds$num)"
10321 for num in `seq $OSTCOUNT`; do
10322 [ $(facet_fstype ost$num) != zfs ] &&
10323 skip "Lustre snapshot 1 only works for ZFS backend"
10325 lss_gen_conf_one ost$num OST $((num - 1)) ||
10326 lss_err "generate lss conf (ost$num)"
10329 do_facet mgs "cat $LSNAPSHOT_CONF"
10332 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
10333 parse_plain_dir_param()
10335 local invalues=($1)
10338 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
10339 param="-c ${invalues[1]}"
10341 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
10342 param="$param -S ${invalues[3]}"
10344 if [[ ${invalues[4]} =~ "pattern:" ]]; then
10345 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
10346 param="$param -i ${invalues[6]}"
10348 param="$param -L ${invalues[5]} -i ${invalues[7]}"
10350 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
10351 param="$param -i ${invalues[5]}"
10356 parse_plain_param()
10359 local val=$(awk '{print $2}' <<< $line)
10361 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
10363 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
10365 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
10367 elif [[ $line =~ ^"lmm_pattern:" ]]; then
10372 parse_layout_param()
10378 while read line; do
10379 if [[ ! -z $line ]]; then
10380 if [[ -z $mode ]]; then
10381 if [[ $line =~ ^"stripe_count:" ]]; then
10383 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
10385 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
10390 if [[ $mode = "plain_dir" ]]; then
10391 param=$(parse_plain_dir_param "$line")
10392 elif [[ $mode = "plain_file" ]]; then
10393 val=$(parse_plain_param "$line")
10394 [[ ! -z $val ]] && param="$param $val"
10395 elif [[ $mode = "pfl" ]]; then
10396 val=$(echo $line | awk '{print $2}')
10397 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
10398 if [[ $val = "EOF" ]]; then
10399 param="$param -E -1"
10401 param="$param -E $val"
10403 elif [[ $line =~ ^"stripe_count:" ]]; then
10405 val=$(parse_plain_dir_param "$line")
10406 param="$param $val"
10409 val=$(parse_plain_param "$line")
10410 [[ ! -z $val ]] && param="$param $val"
10420 local param=$($LFS getstripe -d $1 | parse_layout_param)
10424 lfsck_verify_pfid()
10429 # Cancel locks before setting lfsck_verify_pfid so that errors are more
10431 cancel_lru_locks mdc
10432 cancel_lru_locks osc
10434 # make sure PFID is set correctly for files
10435 do_nodes $(comma_list $(osts_nodes)) \
10436 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
10439 cat $f &> /dev/nullA ||
10440 { rc=$?; echo "verify $f failed"; break; }
10443 do_nodes $(comma_list $(osts_nodes)) \
10444 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
10448 # check that clients "oscs" was evicted after "before"
10449 check_clients_evicted() {
10456 for osc in $oscs; do
10457 echo "Check state for $osc"
10458 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
10459 tail -n 5 | awk -F"[ ,]" \
10460 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
10461 if (($? == 0)) && (($evicted > $before)); then
10462 echo "$osc is evicted at $evicted"
10465 echo "$osc was not evicted after $before:"
10466 do_facet client $LCTL get_param osc.$osc.state |
10471 [ $rc -eq 0 ] || error "client not evicted from OST"
10474 # check that clients OSCS current_state is FULL
10475 check_clients_full() {
10480 for osc in $oscs; do
10481 wait_update_facet client \
10482 "lctl get_param -n osc.$osc.state |
10483 grep 'current_state: FULL'" \
10484 "current_state: FULL" $timeout
10485 [ $? -eq 0 ] || error "$osc state is not FULL"
10490 __changelog_deregister() {
10492 local mdt="$(facet_svc $facet)"
10496 # skip cleanup if no user registered for this MDT
10497 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
10498 # user is no longer registered, skip cleanup
10499 changelog_users "$facet" | grep -q "$cl_user" ||
10500 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
10502 # From this point, if any operation fails, it is an error
10503 __changelog_clear $facet $cl_user 0 ||
10504 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
10505 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
10506 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
10509 declare -Ax CL_USERS
10510 changelog_register() {
10511 for M in $(seq $MDSCOUNT); do
10513 local mdt="$(facet_svc $facet)"
10516 cl_mask=$(do_facet $facet $LCTL get_param \
10517 mdd.${mdt}.changelog_mask -n)
10518 stack_trap "do_facet $facet $LCTL \
10519 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
10520 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
10521 error "$mdt: changelog_mask=+hsm failed: $?"
10524 cl_user=$(do_facet $facet $LCTL --device $mdt \
10525 changelog_register -n "$@") ||
10526 error "$mdt: register changelog user failed: $?"
10527 stack_trap "__changelog_deregister $facet $cl_user" EXIT
10529 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
10530 # Bash does not support nested arrays, but the format of a
10531 # cl_user is constrained enough to use whitespaces as separators
10532 CL_USERS[$facet]+="$cl_user "
10534 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[*]% }'"
10537 changelog_deregister() {
10539 # bash assoc arrays do not guarantee to list keys in created order
10540 # so reorder to get same order than in changelog_register()
10541 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10544 for facet in $cl_facets; do
10545 for cl_user in ${CL_USERS[$facet]}; do
10546 __changelog_deregister $facet $cl_user || return $?
10548 unset CL_USERS[$facet]
10552 changelog_users() {
10554 local service=$(facet_svc $facet)
10556 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
10559 changelog_user_rec() {
10562 local service=$(facet_svc $facet)
10564 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
10567 changelog_chmask() {
10570 do_nodes $(comma_list $(mdts_nodes)) \
10571 $LCTL set_param mdd.*.changelog_mask="$mask"
10574 # usage: __changelog_clear FACET CL_USER [+]INDEX
10575 __changelog_clear()
10578 local mdt="$(facet_svc $facet)"
10584 # Remove the leading '+'
10586 rec+=$(changelog_user_rec $facet $cl_user)
10593 if [ $rec -eq 0 ]; then
10594 echo "$mdt: clear the changelog for $cl_user of all records"
10596 echo "$mdt: clear the changelog for $cl_user to record #$rec"
10598 $LFS changelog_clear $mdt $cl_user $rec
10601 # usage: changelog_clear [+]INDEX [facet]...
10603 # If INDEX is prefixed with '+', increment every changelog user's record index
10604 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
10606 changelog_clear() {
10610 local cl_facets="$@"
10611 # bash assoc arrays do not guarantee to list keys in created order
10612 # so reorder to get same order than in changelog_register()
10613 [[ -n "$cl_facets" ]] ||
10614 cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10618 for facet in $cl_facets; do
10619 for cl_user in ${CL_USERS[$facet]}; do
10620 __changelog_clear $facet $cl_user $idx || rc=${rc:-$?}
10630 for M in $(seq $MDSCOUNT); do
10632 local mdt="$(facet_svc $facet)"
10636 output=$($LFS changelog $mdt)
10638 if [ $ret -ne 0 ]; then
10640 elif [ -n "$output" ]; then
10641 echo "$output" | sed -e 's/^/'$mdt'./'
10648 changelog_extract_field() {
10651 local identifier=$3
10653 changelog_dump | gawk "/$cltype.*$file$/ {
10654 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10658 # Prints a changelog record produced by "lfs changelog" as an associative array
10661 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
10662 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
10663 # nid=0@lo p=[0x200000007:0x1:0x0] blob
10664 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
10665 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
10666 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
10667 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
10669 # Note that the changelog record is not quoted
10670 # Also note that the line breaks in the output were only added for readability
10672 # Typically, you want to eval the output of the command to fill an actual
10673 # associative array, like this:
10674 # $> eval declare -A changelog=$(changelog2array $entry)
10676 # It can then be accessed like any bash associative array:
10677 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
10679 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10687 # A changelog, as printed by "lfs changelog" typically looks like this:
10688 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10690 # Parse the positional part of the changelog
10692 # changelog_dump() prefixes records with their mdt's name
10693 local index="${1##*.}"
10695 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10696 "$index" "${2:2}" "$3" "$4" "$5"
10698 # Parse the key/value part of the changelog
10699 for arg in "${@:5}"; do
10700 # Check it matches a key=value syntax
10701 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10703 local key="${arg%%=*}"
10704 local value="${arg#*=}"
10708 # u is actually for uid AND gid: u=UID:GID
10709 printf " [uid]='%s'" "${value%:*}"
10711 value="${value#*:}"
10739 printf " ['%s']='%s'" "$key" "$value"
10746 # Format and print a changelog record
10748 # Interpreted sequences are:
10750 # %f the "flags" attribute of a changelog record
10751 __changelog_printf()
10756 for ((i = 0; i < ${#format}; i++)); do
10757 local char="${format:$i:1}"
10758 if [ "$char" != % ]; then
10759 printf '%c' "$char"
10764 char="${format:$i:1}"
10767 printf '%s' "${changelog[flags]}"
10777 # Filter changelog records
10781 local action='print'
10784 while [ $# -gt 0 ]; do
10795 filter[${1#-}]="$2"
10804 changelog_dump | { while read -r record; do
10805 eval local -A changelog=$(changelog2array $record)
10806 for key in "${!filter[@]}"; do
10809 [ "${changelog[$key]}" == "${filter[$key]}" ]
10816 case "${action:-print}" in
10818 printf '%s\n' "$record"
10821 __changelog_printf "$format"
10831 [ ! -d "$dir" ] && return
10833 [ -z "$layout" ] && {
10834 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
10838 setfattr -n trusted.lov -v $layout $dir ||
10839 error "error restoring layout '$layout' to '$dir'"
10842 # save the layout of a directory, the returned string will be used by
10843 # restore_layout() to restore the layout
10846 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
10847 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
10851 # save layout of a directory and restore it at exit
10852 save_layout_restore_at_exit() {
10854 local layout=$(save_layout $dir)
10856 stack_trap "restore_layout $dir $layout" EXIT
10859 verify_yaml_layout() {
10863 local msg_prefix=$4
10865 echo "getstripe --yaml $src"
10866 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
10867 echo "setstripe --yaml=$temp $dst"
10868 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
10871 local layout1=$(get_layout_param $src)
10872 local layout2=$(get_layout_param $dst)
10873 # compare their layout info
10874 [ "$layout1" == "$layout2" ] ||
10875 error "$msg_prefix $src/$dst layouts are not equal"
10878 is_project_quota_supported() {
10879 $ENABLE_PROJECT_QUOTAS || return 1
10880 [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
10881 local save_project_supported=1
10883 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
10884 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
10885 do_facet mds1 lfs --list-commands |& grep -q project &&
10886 save_project_supported=0
10888 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
10889 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
10890 do_facet mds1 $ZPOOL get all | grep -q project_quota &&
10891 save_project_supported=0
10893 # cache state of project quotas once instead of re-checking each time
10894 export SAVE_PROJECT_SUPPORTED=$save_project_supported
10895 echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
10897 return $save_project_supported
10900 # ZFS project quota enable/disable:
10901 # This feature will become active as soon as it is enabled and will never
10902 # return to being disabled. Each filesystem will be upgraded automatically
10903 # when remounted or when [a] new file is created under that filesystem. The
10904 # upgrade can also be triggered on filesystems via `zfs set version=current
10905 # <pool/fs>`. The upgrade process runs in the background and may take a
10906 # while to complete for the filesystems containing a large number of files.
10907 enable_project_quota() {
10908 is_project_quota_supported || return 0
10909 local zkeeper=${KEEP_ZPOOL}
10910 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
10912 stopall || error "failed to stopall (1)"
10914 local zfeat_en="feature@project_quota=enabled"
10915 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
10916 local facet_fstype=${facet:0:3}1_FSTYPE
10919 if [ "${!facet_fstype}" = "zfs" ]; then
10920 devname=$(zpool_name ${facet})
10921 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
10922 error "$ZPOOL set $zfeat_en $devname"
10924 [ ${facet:0:3} == "mds" ] &&
10925 devname=$(mdsdevname ${facet:3}) ||
10926 devname=$(ostdevname ${facet:3})
10927 do_facet ${facet} $TUNE2FS -O project $devname ||
10928 error "tune2fs $devname failed"
10932 KEEP_ZPOOL="${zkeeper}"
10937 disable_project_quota() {
10938 is_project_quota_supported || return 0
10939 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
10940 stopall || error "failed to stopall (1)"
10942 for num in $(seq $MDSCOUNT); do
10943 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
10944 error "tune2fs $(mdsdevname $num) failed"
10947 for num in $(seq $OSTCOUNT); do
10948 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
10949 error "tune2fs $(ostdevname $num) failed"
10957 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
10958 # the following associated variables are added:
10960 # AGTCOUNT: number of agents
10961 # AGTDEV{N}: target HSM mount point (root path of the backend)
10962 # agt{N}_HOST: hostname of the agent agt{N}
10963 # SINGLEAGT: facet of the single agent
10965 # The number of agents is initialized as the number of remote client nodes.
10966 # By default, only single copytool is started on a remote client/agent. If there
10967 # was no remote client, then the copytool will be started on the local client.
10973 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
10974 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
10976 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
10977 if [[ $CLIENTCOUNT -gt 1 ]] &&
10978 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
10979 skip_env "SHARED_DIRECTORY should be accessible"\
10980 "on all client nodes"
10984 # We used to put the HSM archive in $SHARED_DIRECTORY but that
10985 # meant NFS issues could hose sanity-hsm sessions. So now we
10986 # use $TMP instead.
10987 for n in $(seq $AGTCOUNT); do
10988 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
10989 agent=CLIENT$((n + 1))
10990 if [[ -z "${!agent}" ]]; then
10991 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
10994 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
10995 local var=agt${n}_HOST
10996 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
10999 export SINGLEAGT=${SINGLEAGT:-agt1}
11001 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
11002 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
11003 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
11004 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
11005 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
11006 export HSMTOOL_TESTDIR
11007 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
11009 if ! [[ $HSMTOOL =~ hsmtool ]]; then
11010 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
11013 HSM_ARCHIVE_NUMBER=2
11015 # The test only support up to 10 MDTs
11016 MDT_PREFIX="mdt.$FSNAME-MDT000"
11017 HSM_PARAM="${MDT_PREFIX}0.hsm"
11019 # archive is purged at copytool setup
11020 HSM_ARCHIVE_PURGE=true
11022 # Don't allow copytool error upon start/setup
11023 HSMTOOL_NOERROR=false
11026 # Get the backend root path for the given agent facet.
11027 copytool_device() {
11029 local dev=AGTDEV$(facet_number $facet)
11034 get_mdt_devices() {
11036 # get MDT device for each mdc
11037 for mdtno in $(seq 1 $MDSCOUNT); do
11038 local idx=$(($mdtno - 1))
11039 MDT[$idx]=$($LCTL get_param -n \
11040 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
11041 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
11045 pkill_copytools() {
11049 do_nodes "$hosts" \
11050 "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
11053 copytool_continue() {
11054 local agents=${1:-$(facet_active_host $SINGLEAGT)}
11056 pkill_copytools "$agents" CONT || return 0
11057 echo "Copytool is continued on $agents"
11061 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
11063 echo "Killing existing copytools on $hosts"
11064 pkill_copytools "$hosts" TERM || return 0
11065 copytool_continue "$hosts"
11068 copytool_monitor_cleanup() {
11069 local facet=${1:-$SINGLEAGT}
11070 local agent=$(facet_active_host $facet)
11072 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
11073 # Should die when the copytool dies, but just in case.
11074 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
11075 cmd+=" 2>/dev/null || true"
11076 do_node $agent "$cmd"
11077 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
11078 export HSMTOOL_MONITOR_DIR=
11081 # The pdsh should die on its own when the monitor dies. Just
11082 # in case, though, try to clean up to avoid any cruft.
11083 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
11084 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
11085 export HSMTOOL_MONITOR_PDSH=
11091 local host="$(facet_host "$1")"
11092 local prefix=$TESTLOG_PREFIX
11093 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
11095 printf "${prefix}.copytool${archive_id}_log.${host}.log"
11098 __lhsmtool_rebind()
11100 do_facet $facet $HSMTOOL \
11101 "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
11104 __lhsmtool_import()
11106 mkdir -p "$(dirname "$2")" ||
11107 error "cannot create directory '$(dirname "$2")'"
11108 do_facet $facet $HSMTOOL \
11109 "${hsmtool_options[@]}" --import "$@" "$mountpoint"
11114 local host="$(facet_host "$facet")"
11115 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
11117 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
11118 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
11119 # [ ${#misc_options[@]} -gt 0 ] &&
11120 # cmd+=" $(IFS=" " echo "$@")"
11121 cmd+=" $@ \"$mountpoint\""
11123 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
11124 stack_trap "pkill_copytools $host TERM || true" EXIT
11125 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
11129 local facet="${1:-$SINGLEAGT}"
11131 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
11134 # Main entry point to perform copytool related operations
11138 # setup setup a copytool to run in the background, that copytool will be
11140 # import import a file from an HSM backend
11141 # rebind rebind an archived file to a new fid
11143 # Although the semantics might suggest otherwise, one does not need to 'setup'
11144 # a copytool before a call to 'copytool import' or 'copytool rebind'.
11151 # Use default values
11152 local facet=$SINGLEAGT
11153 local mountpoint="${MOUNT2:-$MOUNT}"
11156 local fail_on_error=true
11157 local -a hsmtool_options=()
11158 local -a action_options=()
11160 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
11161 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
11164 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
11165 hsmtool_options+=("$HSMTOOL_VERBOSE")
11168 while [ $# -gt 0 ]; do
11180 local archive_id="$1"
11184 local hsm_root="$1"
11188 local bandwidth="$1" # in MB/s
11191 local fail_on_error=false
11194 # Uncommon(/copytool dependent) option
11195 action_options+=("$1")
11201 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
11202 hsmtool_options+=("--hsm-root=$hsm_root")
11204 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
11205 do_facet $facet mkdir -p "$hsm_root" ||
11206 error "mkdir '$hsm_root' failed"
11210 local copytool=lhsmtool
11214 __${copytool}_${action} "${action_options[@]}"
11215 if [ $? -ne 0 ]; then
11220 local host="$(facet_host $facet)"
11221 error_msg="Failed to start copytool $facet on '$host'"
11224 local src="${action_options[0]}"
11225 local dest="${action_options[1]}"
11226 error_msg="Failed to import '$src' to '$dest'"
11229 error_msg="could not rebind file"
11233 $fail_on_error && error "$error_msg" || echo "$error_msg"
11238 local client_count=$1
11239 if [[ $CLIENTCOUNT -lt $client_count ]]; then
11240 skip "Need $client_count or more clients, have $CLIENTCOUNT"
11247 $LFS path2fid $1 | tr -d '[]'
11248 return ${PIPESTATUS[0]}
11256 if [[ $u == "user" ]]; then
11257 st=$($RUNAS $LFS hsm_state $f)
11260 st=$($LFS hsm_state $f)
11263 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
11265 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
11269 check_hsm_flags() {
11273 local st=$(get_hsm_flags $f)
11274 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
11283 if [[ "$value" != "" ]]; then
11286 for mdtno in $(seq 1 $MDSCOUNT); do
11287 local idx=$(($mdtno - 1))
11288 local facet=mds${mdtno}
11289 # if $arg include -P option, run 1 set_param per MDT on the MGS
11290 # else, run set_param on each MDT
11291 [[ $arg = *"-P"* ]] && facet=mgs
11292 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
11293 [[ $? != 0 ]] && rc=1
11298 mdts_check_param() {
11304 for mdtno in $(seq 1 $MDSCOUNT); do
11305 local idx=$(($mdtno - 1))
11306 wait_update_facet --verbose mds${mdtno} \
11307 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
11309 error "$key state is not '$target' on mds${mdtno}"
11313 cdt_set_mount_state() {
11314 mdts_set_param "-P" hsm_control "$1"
11315 # set_param -P is asynchronous operation and could race with set_param.
11316 # In such case configs could be retrieved and applied at mgc after
11317 # set_param -P completion. Sleep here to avoid race with set_param.
11318 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
11319 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
11320 # and 10 seconds to retrieve config from server.
11324 cdt_check_state() {
11325 mdts_check_param hsm_control "$1" 20
11328 cdt_set_sanity_policy() {
11329 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
11332 mdts_set_param "" hsm.policy "+NRA"
11333 mdts_set_param "" hsm.policy "-NBR"
11334 CDT_POLICY_HAD_CHANGED=
11342 mdts_set_param "$opt -n" "hsm.$param" "$value"
11346 wait_request_state() {
11350 # 4th arg (mdt index) is optional
11351 local mdtidx=${4:-0}
11352 local mds=mds$(($mdtidx + 1))
11354 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
11355 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
11357 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
11358 error "request on $fid is not $state on $mds"
11366 local WAIT_MAX=${4:-60}
11369 # We need to run do_node in bg, because pdsh does not exit
11370 # if child process of run script exists.
11371 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
11372 # because of multiop_bg_pause -> $MULTIOP_PROG &
11373 # By the same reason we need sleep a bit after do_nodes starts
11374 # to let runmultiop_bg_pause start muliop and
11375 # update /tmp/multiop_bg.pid ;
11376 # The rm /tmp/multiop_bg.pid guarantees here that
11377 # we have the updated by runmultiop_bg_pause
11378 # /tmp/multiop_bg.pid file
11380 local pid_file=$TMP/multiop_bg.pid.$$
11382 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
11383 runmultiop_bg_pause $file $cmds" &
11387 while [[ $wait_time -lt $WAIT_MAX ]]; do
11389 wait_time=$((wait_time + 3))
11390 multiop_pid=$(do_node $client cat $pid_file)
11391 if [ -n "$multiop_pid" ]; then
11396 [ -n "$multiop_pid" ] ||
11397 error "$client : Can not get multiop_pid from $pid_file "
11399 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
11400 eval export $(node_var_name $client)_do_node_pid=$pid
11401 local var=$(node_var_name $client)_multiop_pid
11402 echo client $client multiop_bg started multiop_pid=${!var}
11408 local multiop_pid=$(node_var_name $client)_multiop_pid
11409 local do_node_pid=$(node_var_name $client)_do_node_pid
11411 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
11412 do_node $client kill -USR1 ${!multiop_pid}
11414 wait ${!do_node_pid}
11418 local delay=$(do_facet mds1 lctl get_param -n lod.*.qos_maxage |
11419 awk '{ print $1 + 5; exit; }')
11423 sleep_maxage_lmv() {
11424 local delay=$(lctl get_param -n lmv.*.qos_maxage |
11425 awk '{ print $1 + 5; exit; }')
11429 check_component_count() {
11430 local comp_cnt=$($LFS getstripe --component-count $1)
11431 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
11434 # Verify there are no init components with "extension" flag
11435 verify_no_init_extension() {
11436 local flg_opts="--component-flags init,extension"
11437 local found=$($LFS find $flg_opts $1 | wc -l)
11438 [ $found -eq 0 ] || error "$1 has component with initialized extension"
11441 # Verify there is at least one component starting at 0
11442 verify_comp_at_zero() {
11443 flg_opts="--component-flags init"
11444 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
11445 [ $found -eq 1 ] ||
11446 error "No component starting at zero(!)"
11449 # version after which Self-Extending Layouts are available
11452 sel_layout_sanity() {
11456 verify_no_init_extension $file
11457 verify_comp_at_zero $file
11458 check_component_count $file $comp_cnt
11461 statx_supported() {
11462 $STATX --quiet --version
11466 # lfs rm_entry is disabled on native client
11467 is_rmentry_supported() {
11468 $LFS rm_entry $DIR/dir/not/exists > /dev/null
11469 # is return code ENOENT?
11474 # wrappers for createmany and unlinkmany
11475 # to set debug=0 if number of creates is high enough
11476 # this is to speedup testing
11478 function createmany() {
11482 if (( count > 100 )); then
11484 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11486 $LUSTRE/tests/createmany $*
11488 debugrestore > /dev/null
11493 function unlinkmany() {
11497 if (( count > 100 )); then
11499 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11501 $LUSTRE/tests/unlinkmany $*
11503 debugrestore > /dev/null
11508 # Check if fallocate on facet is working. Returns fallocate mode if enabled.
11509 # Takes optional facet name as argument, to allow separate MDS/OSS checks.
11510 function check_fallocate_supported()
11512 local facet=${1:-ost1}
11513 local supported="FALLOCATE_SUPPORTED_$facet"
11514 local fstype="${facet}_FSTYPE"
11516 if [[ -n "${!supported}" ]]; then
11517 echo "${!supported}"
11520 if [[ -z "${!fstype}" ]]; then
11521 eval export $fstype=$(facet_fstype $facet)
11523 if [[ "${!fstype}" != "ldiskfs" ]]; then
11524 echo "fallocate on ${!fstype} doesn't consume space" 1>&2
11528 local fa_mode="osd-ldiskfs.$(facet_svc $facet).fallocate_zero_blocks"
11529 local mode=$(do_facet $facet $LCTL get_param -n $fa_mode 2>/dev/null |
11532 if [[ -z "$mode" ]]; then
11533 echo "fallocate not supported on $facet" 1>&2
11536 eval export $supported="$mode"
11542 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable.
11543 # Takes optional facet name as argument.
11544 function check_fallocate_or_skip()
11548 check_fallocate_supported $1 || skip "fallocate not supported"
11551 # Check if fallocate supported on OSTs, enable if unset, default mode=0
11552 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
11553 function check_set_fallocate()
11555 local new_mode="$1"
11556 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
11557 local old_mode="$(check_fallocate_supported)"
11559 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
11560 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
11561 { echo "keep default fallocate mode: $old_mode"; return 0; }
11562 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
11563 { echo "keep current fallocate mode: $old_mode"; return 0; }
11564 local osts=$(comma_list $(osts_nodes))
11566 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
11567 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
11568 error "set $fa_mode=$new_mode"
11571 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
11572 function check_set_fallocate_or_skip()
11574 check_set_fallocate || skip "need >= 2.13.57 and ldiskfs for fallocate"
11577 function disable_opencache()
11579 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" |
11582 test -z "${saved_OPENCACHE_value}" &&
11583 export saved_OPENCACHE_value="$state"
11585 [[ "$state" = "off" ]] && return
11587 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
11590 function set_opencache()
11592 local newvalue="$1"
11593 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
11595 [[ -n "$newvalue" ]] || return
11597 [[ -n "${saved_OPENCACHE_value}" ]] ||
11598 export saved_OPENCACHE_value="$state"
11600 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
11605 function restore_opencache()
11607 [[ -z "${saved_OPENCACHE_value}" ]] ||
11608 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
11611 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
11612 # created on MDT0, use this function to create directory on specific MDT
11613 # explicitly, and set default LMV to create subdirs on the same MDT too.
11618 while getopts "i:" opt $*; do
11624 shift $((OPTIND - 1))
11626 $LFS mkdir -i $mdt -c 1 $*
11630 mkdir_on_mdt -i0 $*
11633 # Wait for nodemap synchronization
11635 local nodemap_name=$1
11640 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
11641 local max_retries=20
11645 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
11648 if [ "$nodemap_name" == "active" ]; then
11649 proc_param="active"
11650 elif [ -z "$key" ]; then
11651 proc_param=${nodemap_name}
11653 proc_param="${nodemap_name}.${key}"
11655 if [ "$opt" == "inactive" ]; then
11656 # check nm sync even if nodemap is not activated
11660 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
11662 if [ -z "$value" ]; then
11663 out1=$(do_facet mgs $LCTL get_param $opt \
11664 nodemap.${proc_param} 2>/dev/null)
11665 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
11670 # if servers run on the same node, it is impossible to tell if they get
11671 # synced with the mgs, so just wait an arbitrary 10 seconds
11672 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
11673 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
11674 echo "waiting 10 secs for sync"
11679 # wait up to 10 seconds for other servers to sync with mgs
11680 for i in $(seq 1 10); do
11681 for node in $(all_server_nodes); do
11682 local node_ip=$(host_nids_address $node $NETTYPE |
11686 if [ -z "$value" ]; then
11687 [ $node_ip == $mgs_ip ] && continue
11690 out2=$(do_node $node $LCTL get_param $opt \
11691 nodemap.$proc_param 2>/dev/null)
11692 echo "On $node ${node_ip}, ${proc_param} = $out2"
11693 [ "$out1" != "$out2" ] && is_sync=false && break
11698 if ! $is_sync; then
11701 echo OTHER - IP: $node_ip
11703 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
11705 echo "waited $((i - 1)) seconds for sync"
11708 consume_precreations() {
11712 local extra=${4:-2}
11713 local OST=$(ostname_from_index $OSTIDX $dir)
11715 mkdir_on_mdt -i $(facet_index $mfacet) $dir/${OST}
11716 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
11719 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11720 local last_id=$(do_facet $mfacet $LCTL get_param -n \
11721 osp.$mdtosc_proc.prealloc_last_id)
11722 local next_id=$(do_facet $mfacet $LCTL get_param -n \
11723 osp.$mdtosc_proc.prealloc_next_id)
11724 echo "Creating to objid $last_id on ost $OST..."
11725 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
11728 __exhaust_precreations() {
11731 local FAILIDX=${3:-$OSTIDX}
11732 local ofacet=ost$((OSTIDX + 1))
11734 mkdir_on_mdt0 $DIR/$tdir
11735 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
11736 local mfacet=mds$((mdtidx + 1))
11737 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
11739 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
11740 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11742 #define OBD_FAIL_OST_ENOSPC 0x215
11743 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
11745 consume_precreations $DIR/$tdir $mfacet $OSTIDX
11747 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11748 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11751 exhaust_precreations() {
11752 __exhaust_precreations $1 $2 $3
11756 exhaust_all_precreations() {
11758 for (( i=0; i < OSTCOUNT; i++ )) ; do
11759 __exhaust_precreations $i $1 -1
11764 force_new_seq_ost() {
11768 local OST=$(ostname_from_index $OSTIDX)
11769 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11771 do_facet $mfacet $LCTL set_param \
11772 osp.$mdtosc_proc.prealloc_force_new_seq=1
11773 # consume preallocated objects, to wake up precreate thread
11774 consume_precreations $dir $mfacet $OSTIDX
11775 do_facet $mfacet $LCTL set_param \
11776 osp.$mdtosc_proc.prealloc_force_new_seq=0
11781 local MDTIDX=$(facet_index $mfacet)
11782 local MDT=$(mdtname_from_index $MDTIDX $DIR)
11785 mkdir_on_mdt -i $MDTIDX $DIR/${MDT}
11786 for (( i=0; i < OSTCOUNT; i++ )) ; do
11787 force_new_seq_ost $DIR/${MDT} $mfacet $i &
11793 force_new_seq_all() {
11796 for (( i=0; i < MDSCOUNT; i++ )) ; do
11797 force_new_seq mds$((i + 1)) &
11803 ost_set_temp_seq_width_all() {
11804 local osts=$(comma_list $(osts_nodes))
11805 local width=$(do_facet ost1 $LCTL get_param -n seq.*OST0000-super.width)
11807 do_nodes $osts $LCTL set_param seq.*OST*-super.width=$1
11808 stack_trap "do_nodes $osts $LCTL set_param seq.*OST*-super.width=$width"
11811 verify_yaml_available() {
11812 python3 -c "import yaml; yaml.safe_load('''a: b''')"
11816 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"
11819 verify_compare_yaml() {
11820 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)"
11823 zfs_or_rotational() {
11825 local ost_name=$(ostname_from_index $ost_idx $MOUNT)
11826 local param="get_param -n osd-*.${ost_name}.nonrotational"
11827 local nonrotat=$(do_facet ost1 $LCTL $param)
11829 if [[ -z "$nonrotat" ]]; then
11830 # At this point there is no point moving ahead.
11831 # Will stop here and dump all the info
11833 local ost_name=$(ostname_from_index $ost_idx)
11835 error "$LCTL $input_str"
11838 if [[ "$ost1_FSTYPE" == "zfs" ]] || (( "$nonrotat" == 0 )); then