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)
386 # import server-side version information into local variables
387 # so they can be used in tests instead of checked separately
388 # MGS_OS_VERSION_ID, MGS_OS_ID, MGS_OS_ID_LIKE,
389 # MDS1_OS_VERSION_ID, MDS1_OS_ID, MDS1_OS_ID_LIKE,
390 # OST1_OS_VERSION_ID, OST1_OS_ID, OST1_OS_ID_LIKE,
391 # CLIENT_OS_VERSION_ID, CLIENT_OS_ID, CLIENT_OS_ID_LIKE
392 lustre_os_release mgs
393 lustre_os_release mds1
394 lustre_os_release ost1
395 lustre_os_release client
398 # Prefer using "mds1" directly instead of SINGLEMDS.
399 # Keep this for compat until it is removed from scripts.
400 export SINGLEMDS=${SINGLEMDS:-mds1}
404 export LUSTRE=$(absolute_path $LUSTRE)
405 export TESTSUITE=$(basename $0 .sh)
406 export TEST_FAILED=false
407 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
408 export RPC_MODE=${RPC_MODE:-false}
409 export DO_CLEANUP=${DO_CLEANUP:-true}
410 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
411 export CLEANUP_DM_DEV=false
412 export PAGE_SIZE=$(get_page_size client)
413 export NAME=${NAME:-local}
415 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
417 export MKE2FS=$MKE2FS
418 if [ -z "$MKE2FS" ]; then
419 if which mkfs.ldiskfs >/dev/null 2>&1; then
420 export MKE2FS=mkfs.ldiskfs
426 export DEBUGFS=$DEBUGFS
427 if [ -z "$DEBUGFS" ]; then
428 if which debugfs.ldiskfs >/dev/null 2>&1; then
429 export DEBUGFS=debugfs.ldiskfs
431 export DEBUGFS=debugfs
435 export TUNE2FS=$TUNE2FS
436 if [ -z "$TUNE2FS" ]; then
437 if which tunefs.ldiskfs >/dev/null 2>&1; then
438 export TUNE2FS=tunefs.ldiskfs
440 export TUNE2FS=tune2fs
444 export E2LABEL=$E2LABEL
445 if [ -z "$E2LABEL" ]; then
446 if which label.ldiskfs >/dev/null 2>&1; then
447 export E2LABEL=label.ldiskfs
449 export E2LABEL=e2label
453 export DUMPE2FS=$DUMPE2FS
454 if [ -z "$DUMPE2FS" ]; then
455 if which dumpfs.ldiskfs >/dev/null 2>&1; then
456 export DUMPE2FS=dumpfs.ldiskfs
458 export DUMPE2FS=dumpe2fs
462 export E2FSCK=$E2FSCK
463 if [ -z "$E2FSCK" ]; then
464 if which fsck.ldiskfs >/dev/null 2>&1; then
465 export E2FSCK=fsck.ldiskfs
471 export RESIZE2FS=$RESIZE2FS
472 if [ -z "$RESIZE2FS" ]; then
473 if which resizefs.ldiskfs >/dev/null 2>&1; then
474 export RESIZE2FS=resizefs.ldiskfs
476 export RESIZE2FS=resize2fs
480 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
481 export FSCK_MAX_ERR=4 # File system errors left uncorrected
483 export ZFS=${ZFS:-zfs}
484 export ZPOOL=${ZPOOL:-zpool}
485 export ZDB=${ZDB:-zdb}
486 export PARTPROBE=${PARTPROBE:-partprobe}
488 #[ -d /r ] && export ROOT=${ROOT:-/r}
489 export TMP=${TMP:-$ROOT/tmp}
490 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
491 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
492 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
494 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
495 if ! echo $PATH | grep -q $LUSTRE/utils; then
496 export PATH=$LUSTRE/utils:$PATH
498 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
499 export PATH=$LUSTRE/utils/gss:$PATH
501 if ! echo $PATH | grep -q $LUSTRE/tests; then
502 export PATH=$LUSTRE/tests:$PATH
504 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
505 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
507 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
508 [ ! -f "$LST" ] && export LST=$(which lst)
509 export LSTSH=${LSTSH:-"$LUSTRE/../lustre-iokit/lst-survey/lst.sh"}
510 [ ! -f "$LSTSH" ] && export LSTSH=$(which lst.sh)
511 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
512 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
513 export MCREATE=${MCREATE:-mcreate}
514 export MULTIOP=${MULTIOP:-multiop}
515 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
516 export STATX=${STATX:-statx}
517 # Ubuntu, at least, has a truncate command in /usr/bin
518 # so fully path our truncate command.
519 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
520 export FSX=${FSX:-$LUSTRE/tests/fsx}
521 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
522 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
523 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
524 export PATH=$LUSTRE/tests/racer:$PATH:
526 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
527 export PATH=$LUSTRE/tests/mpi:$PATH
530 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
531 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
532 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
533 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
534 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
535 [ ! -f "$LFS" ] && export LFS=$(which lfs)
536 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
537 [ ! -f "$KSOCKLND_CONFIG" ] &&
538 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
540 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
542 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
543 if [ ! -f "$L_GETIDENTITY" ]; then
544 if $(which l_getidentity > /dev/null 2>&1); then
545 export L_GETIDENTITY=$(which l_getidentity)
547 export L_GETIDENTITY=NONE
550 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
551 [ ! -f "$LL_DECODE_FILTER_FID" ] &&
552 export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
553 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
554 [ ! -f "$LL_DECODE_LINKEA" ] &&
555 export LL_DECODE_LINKEA="ll_decode_linkea"
556 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
557 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
558 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
559 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
560 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
561 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
562 [ ! -f "$LUSTRE_RMMOD" ] &&
563 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
564 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
565 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
566 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
567 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
568 [ ! -f "$LFS_MIGRATE" ] &&
569 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
570 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
571 [ ! -f "$LR_READER" ] &&
572 export LR_READER=$(which lr_reader 2> /dev/null)
573 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
574 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
575 [ ! -f "$LSOM_SYNC" ] &&
576 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
577 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
578 export L_GETAUTH=${L_GETAUTH:-"$LUSTRE/utils/gss/l_getauth"}
579 [ ! -f "$L_GETAUTH" ] && export L_GETAUTH=$(which l_getauth 2> /dev/null)
580 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
581 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
582 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
584 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
586 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
587 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
589 export DMSETUP=${DMSETUP:-dmsetup}
590 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
591 export LOSETUP=${LOSETUP:-losetup}
593 if [ "$ACCEPTOR_PORT" ]; then
594 export PORT_OPT="--port $ACCEPTOR_PORT"
598 $RPC_MODE || echo "Using GSS shared-key feature"
600 export LGSS_SK=$(which lgss_sk 2> /dev/null)
602 export LGSS_SK="$LUSTRE/utils/gss/lgss_sk"
604 error_exit "built with lgss_sk disabled! SEC=$SEC"
612 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
613 which lgss_keyring > /dev/null 2>&1 ||
614 error_exit "built with gss disabled! SEC=$SEC"
620 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
622 # Paths on remote nodes, if different
623 export RLUSTRE=${RLUSTRE:-$LUSTRE}
624 export RPWD=${RPWD:-$PWD}
625 export I_MOUNTED=${I_MOUNTED:-"no"}
626 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
627 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
628 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
629 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
630 ! -f $LUSTRE/mdt/mdt.ko ]; then
631 export CLIENTMODSONLY=yes
634 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
635 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
639 while getopts "rvwf:" opt $*; do
644 w) WRITECONF=writeconf;;
649 shift $((OPTIND - 1))
652 # print the durations of each test if "true"
653 DDETAILS=${DDETAILS:-false}
654 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
659 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
661 # Constants used in more than one test script
662 export LOV_MAX_STRIPE_COUNT=2000
663 export LMV_MAX_STRIPES_PER_MDT=5
664 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
665 export KEEP_POOLS=${KEEP_POOLS:-false}
666 export PARALLEL=${PARALLEL:-"no"}
668 export BLCKSIZE=${BLCKSIZE:-4096}
669 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
672 # use localrecov to enable recovery for local clients, LU-12722
673 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
674 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
675 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
678 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
679 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
686 ncpts=$(do_facet $facet "lctl get_param -n " \
687 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
689 if [ $ncpts -eq 0 ]; then
696 # Return a numeric version code based on a version string. The version
697 # code is useful for comparison two version strings to see which is newer.
699 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
700 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
702 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
705 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
706 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
708 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
710 # usage: lustre_build_version
712 # All Lustre versions support "lctl get_param" to report the version of the
713 # code running in the kernel (what our tests are interested in), but it
714 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
715 # the "version" parameter doesn't include "lustre: " at the beginning.
716 # If that fails, call "lctl lustre_build_version" which prints either (or both)
717 # the userspace and kernel build versions, but until 2.8.55 required root
718 # access to get the Lustre kernel version. If that also fails, fall back to
719 # using "lctl --version", which is easy to parse and works without the kernel
720 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
721 # not the module version, though they are usually the same.
723 # Various commands and their output format for different Lustre versions:
724 # lctl get_param version: 2.9.55
725 # lctl get_param version: lustre: 2.8.53
726 # lctl get_param version: lustre: 2.6.52
727 # kernel: patchless_client
728 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
729 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
730 # lctl lustre_build_version: error: lustre_build_version: Permission denied
731 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
732 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
733 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
734 # lctl --version: lctl 2.6.50
736 # output: prints version string to stdout in (up to 4) dotted-decimal values
737 lustre_build_version() {
738 local facet=${1:-client}
739 local facet_version=${facet}_VERSION
741 # if the global variable is already set, then use that
742 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
744 # this is the currently-running version of the kernel modules
745 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
746 # we mostly test 2.10+ systems, only try others if the above fails
747 if [ -z "$ver" ]; then
748 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
750 if [ -z "$ver" ]; then
751 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
754 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
755 [ -n "$lver" ] && ver="$lver"
757 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
758 tr _ . | cut -d. -f1-4)
760 # save in global variable for the future
761 export $facet_version=$lver
766 # Report the Lustre numeric build version code for the supplied facet.
767 lustre_version_code() {
768 version_code $(lustre_build_version $1)
771 # Extract the server-side /etc/os-release information into local variables
772 # usage: lustre_os_release <facet>
773 # generates $facet_OS_ID, $facet_OS_ID_LIKE, $facet_VERSION_ID
774 # and also $facet_OS_VERSION_CODE=$(version_code $facet_VERSION_ID)
775 lustre_os_release() {
777 local facet_os=$(tr "[:lower:]" "[:upper:]" <<<$facet)_OS_
778 local facet_version=${facet_os}VERSION_
781 echo "$facet: $(do_facet $facet "cat /etc/system-release")"
782 do_facet $facet "test -r /etc/os-release" || {
783 echo "$facet: has no /etc/os-release"
784 do_facet $facet "uname -a; ls -s /etc/*release"
789 # more variables in os-release could be exported, but these
790 # are the ones that looked enough for our needs here
792 VERSION_ID=*|ID=*|ID_LIKE=*) eval export ${facet_os}$line ;;
794 done < <(do_facet $facet "cat /etc/os-release")
796 eval export ${facet_version}CODE=\$\(version_code \$${facet_version}ID\)
797 # add in the "self" ID to ID_LIKE so only one needs to be checked
798 eval export ${facet_os}ID_LIKE+=\" \$${facet_os}ID\"
799 env | grep "${facet_os}"
803 /sbin/lsmod | grep -q "^\<$1\>"
806 check_lfs_df_ret_val() {
807 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
808 # returned by 'lfs df' for valid dentry but not a lustrefs.
810 # 'lfs df' historically always returned success(0) instead of
811 # EOPNOTSUPP. This function for compatibility reason, ignores and
812 # masquerades EOPNOTSUPP as success.
813 [[ $1 -eq 95 ]] && return 0
826 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
829 # parallels can't load modules directly from prlfs, use /tmp instead
830 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
831 local target="$(mktemp)"
833 cp "$module" "$target"
836 [[ $rc == 0 ]] && PRLFS=true
844 # Load a module on the system where this is running.
846 # usage: load_module module_name [module arguments for insmod/modprobe]
848 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
849 # will be used as the arguments. Otherwise arguments will be obtained from
850 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
853 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
856 local base=$(basename $module $ext)
858 local -A module_is_loaded_aa
862 for mod in $(lsmod | awk '{ print $1; }'); do
863 module_is_loaded_aa[${mod//-/_}]=true
867 ${module_is_loaded_aa[${1//-/_}]:-false}
870 if module_is_loaded $base; then
874 if [[ -f $LUSTRE/$module$ext ]]; then
875 path=$LUSTRE/$module$ext
876 elif [[ "$base" == lnet_selftest ]] &&
877 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
878 path=$LUSTRE/../lnet/selftest/$base$ext
883 if [[ -n "$path" ]]; then
884 # Try to load any non-Lustre modules that $module depends on.
885 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
886 if ! module_is_loaded $mod; then
892 # If no module arguments were passed then get them from
893 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
894 if [ $# -eq 0 ]; then
895 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
896 # not in Bash until 4.x, so we resort to eval.
897 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
898 eval set -- \$$optvar
899 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
900 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
902 opt=$(awk -v var="^options $base" '$0 ~ var \
903 {gsub("'"options $base"'",""); print}' \
905 set -- $(echo -n $opt)
907 # Ensure we have accept=all for lnet
908 if [[ "$base" == lnet ]]; then
909 # OK, this is a bit wordy...
910 local arg accept_all_present=false
913 [[ "$arg" == accept=all ]] &&
914 accept_all_present=true
917 $accept_all_present || set -- "$@" accept=all
924 [ $# -gt 0 ] && echo "${module} options: '$*'"
926 # Note that insmod will ignore anything in modprobe.conf, which is why
927 # we're passing options on the command-line. If $path does not exist
928 # then we must be testing a "make install" or"rpm" installation. Also
929 # note that failing to load ptlrpc_gss is not considered fatal.
930 if [[ -n "$path" ]]; then
931 lustre_insmod $path "$@"
932 elif [[ "$base" == ptlrpc_gss ]]; then
933 if ! modprobe $base "$@" 2>/dev/null; then
934 echo "gss/krb5 is not supported"
942 $LCTL mark "$LNETCTL $*"
948 # For kmemleak-enabled kernels we need clear all past state
949 # that obviously has nothing to do with this Lustre run
950 # Disable automatic memory scanning to avoid perf hit.
951 if [ -f /sys/kernel/debug/kmemleak ] ; then
952 echo scan=off > /sys/kernel/debug/kmemleak || true
953 echo scan > /sys/kernel/debug/kmemleak || true
954 echo clear > /sys/kernel/debug/kmemleak || true
957 echo Loading modules from $LUSTRE
961 if [ -f /sys/devices/system/cpu/online ]; then
962 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
963 echo "detected $ncpus online CPUs by sysfs"
965 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
968 if [ $rc -eq 0 ]; then
969 echo "detected $ncpus online CPUs by getconf"
971 echo "Can't detect number of CPUs"
976 # if there is only one CPU core, libcfs can only create one partition
977 # if there is more than 4 CPU cores, libcfs should create multiple CPU
978 # partitions. So we just force libcfs to create 2 partitions for
979 # system with 2 or 4 cores
980 local saved_opts="$MODOPTS_LIBCFS"
982 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
983 # force to enable multiple CPU partitions
984 echo "Force libcfs to create 2 CPU partitions"
985 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
987 echo "libcfs will create CPU partition based on online CPUs"
990 load_module ../libcfs/libcfs/libcfs
991 # Prevent local MODOPTS_LIBCFS being passed as part of environment
992 # variable to remote nodes
995 set_default_debug "neterror net nettrace malloc"
996 if [ "$1" = "config_on_load=1" ]; then
997 load_module ../lnet/lnet/lnet
999 load_module ../lnet/lnet/lnet "$@"
1002 LNDPATH=${LNDPATH:-"../lnet/klnds"}
1003 if [ -z "$LNETLND" ]; then
1005 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
1006 tcp*) LNETLND="socklnd/ksocklnd" ;;
1007 kfi*) LNETLND="kfilnd/kkfilnd" ;;
1008 gni*) LNETLND="gnilnd/kgnilnd" ;;
1009 *) local lnd="${NETTYPE%%[0-9]}lnd"
1010 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
1011 LNETLND="$lnd/k$lnd" ||
1012 LNETLND="socklnd/ksocklnd"
1015 load_module ../lnet/klnds/$LNETLND
1017 if [ "$1" = "config_on_load=1" ]; then
1018 do_lnetctl lnet configure --all ||
1023 load_modules_local() {
1024 if [ -n "$MODPROBE" ]; then
1026 echo "Using modprobe to load modules"
1030 # Create special udev test rules on every node
1031 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
1032 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
1034 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
1036 udevadm control --reload-rules
1041 load_module obdclass/obdclass
1042 if ! client_only; then
1043 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
1045 load_module ptlrpc/ptlrpc
1046 load_module ptlrpc/gss/ptlrpc_gss
1054 load_module obdecho/obdecho
1055 if ! client_only; then
1056 load_module lfsck/lfsck
1057 [ "$LQUOTA" != "no" ] &&
1058 load_module quota/lquota $LQUOTAOPTS
1059 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
1060 load_module osd-zfs/osd_zfs
1061 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
1062 load_module ../ldiskfs/ldiskfs
1063 load_module osd-ldiskfs/osd_ldiskfs
1068 # don't fail if ost module doesn't exist
1069 load_module ost/ost 2>/dev/null || true;
1075 load_module llite/lustre
1076 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
1078 rm -f $OGDB/ogdb-$HOSTNAME
1079 $LCTL modules > $OGDB/ogdb-$HOSTNAME
1081 # 'mount' doesn't look in $PATH, just sbin
1082 local mount_lustre=$LUSTRE/utils/mount.lustre
1083 if [ -f $mount_lustre ]; then
1084 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1085 if grep -qw "$sbin_mount" /proc/mounts; then
1086 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
1088 if ! grep -qw "$sbin_mount" /proc/mounts; then
1089 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
1090 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
1091 cat <<- EOF > "$sbin_mount"
1094 echo "This $sbin_mount just a mountpoint." 1>&2
1095 echo "It is never supposed to be run." 1>&2
1096 logger -p emerg -- "using stub $sbin_mount $@"
1099 chmod a+x $sbin_mount
1101 mount --bind $mount_lustre $sbin_mount ||
1102 error "can't bind $mount_lustre to $sbin_mount"
1113 # load modules on remote nodes optionally
1114 # lustre-tests have to be installed on these nodes
1115 if $LOAD_MODULES_REMOTE; then
1116 local list=$(comma_list $(remote_nodes_list))
1118 # include failover nodes in case they are not in the list yet
1119 facets=$(get_facets)
1120 for facet in ${facets//,/ }; do
1121 failover=$(facet_failover_host $facet)
1122 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
1123 list="$list,$failover"
1126 if [ -n "$list" ]; then
1127 echo "loading modules on: '$list'"
1128 do_rpc_nodes "$list" load_modules_local
1134 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
1135 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
1137 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
1138 echo "$LEAK_LUSTRE" 1>&2
1139 echo "$LEAK_PORTALS" 1>&2
1140 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
1141 echo "Memory leaks detected"
1142 [ -n "$IGNORE_LEAK" ] &&
1143 { echo "ignoring leaks" && return 0; } || true
1148 unload_modules_local() {
1149 $LUSTRE_RMMOD ldiskfs || return 2
1151 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
1152 rm /etc/udev/rules.d/99-lustre-test.rules
1153 udevadm control --reload-rules
1156 check_mem_leak || return 254
1164 wait_exit_ST client # bug 12845
1166 unload_modules_local || rc=$?
1168 if $LOAD_MODULES_REMOTE; then
1169 local list=$(comma_list $(remote_nodes_list))
1170 if [ -n "$list" ]; then
1171 echo "unloading modules on: '$list'"
1172 do_rpc_nodes "$list" unload_modules_local
1176 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1177 if grep -qe "$sbin_mount " /proc/mounts; then
1178 umount $sbin_mount || true
1179 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
1183 [[ $rc -eq 0 ]] && echo "modules unloaded."
1189 local facet=${1:-ost1}
1191 local mult=$OSTCOUNT
1193 case $(facet_fstype $facet) in
1194 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
1195 # grant_block_size is in bytes, allow at least 2x max blocksize
1196 zfs) size=$(lctl get_param osc.$FSNAME*.import |
1197 awk '/grant_block_size:/ {print $2/512; exit;}')
1201 [[ $facet =~ mds ]] && mult=$MDTCOUNT
1202 echo -n $((size * mult))
1206 local facet=${1:-$SINGLEMDS}
1207 local fstype=$(facet_fstype $facet)
1210 ldiskfs) size=4;; # ~4KB per inode
1211 zfs) size=11;; # 10 to 11KB per inode
1224 echo Running as $user: $cmd $opts
1227 su - $user -c "$cmd $opts"
1230 check_gss_daemon_nodes() {
1238 dname=$(basename "$dname" | awk '{print $1}')
1239 do_nodesv $list "num=0;
1240 for proc in \\\$(pgrep $dname); do
1241 [ \\\$(ps -o ppid= -p \\\$proc) -ne 1 ] || ((num++))
1243 if [ \\\"\\\$num\\\" -ne 1 ]; then
1244 echo \\\$num instance of $dname;
1248 (( $ret == 0 )) || return $ret
1250 for node in ${list//,/ }; do
1252 while (( $loop < $loopmax )); do
1253 do_nodesv $node "$L_GETAUTH -d"
1255 (( $ret == 0 )) && break
1259 (( $loop < $loopmax )) || return 1
1264 check_gss_daemon_facet() {
1268 dname=$(basename "$dname" | awk '{print $1}')
1269 num=$(do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l)
1270 if [ $num -ne 1 ]; then
1271 echo "$num instance of $dname on $facet"
1281 echo "Stopping "$@" on $list"
1282 do_nodes $list "killall -2 $* 2>/dev/null || true"
1285 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1286 start_gss_daemons() {
1291 if [ "$nodes" ] && [ "$daemon" ] ; then
1292 echo "Starting gss daemon on nodes: $nodes"
1293 do_nodes $nodes "$daemon" "$options" || return 8
1294 check_gss_daemon_nodes $nodes "$daemon" || return 9
1298 nodes=$(comma_list $(mdts_nodes))
1299 echo "Starting gss daemon on mds: $nodes"
1301 # Start all versions, in case of switching
1302 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1305 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 1
1308 nodes=$(comma_list $(osts_nodes))
1309 echo "Starting gss daemon on ost: $nodes"
1311 # Start all versions, in case of switching
1312 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1315 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 3
1317 # starting on clients
1319 local clients=${CLIENTS:-$HOSTNAME}
1322 # check daemons are running
1324 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1325 check_gss_daemon_nodes $nodes "$LSVCGSSD" || return 5
1328 stop_gss_daemons() {
1329 local nodes=$(comma_list $(mdts_nodes))
1331 send_sigint $nodes lsvcgssd lgssd
1333 nodes=$(comma_list $(osts_nodes))
1334 send_sigint $nodes lsvcgssd
1336 nodes=${CLIENTS:-$HOSTNAME}
1337 send_sigint $nodes lgssd
1341 # Add mount flags for shared key
1344 if grep -q skpath <<< "$mt_opts" ; then
1345 mt_opts=$(echo $mt_opts |
1346 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1348 if [ -z "$mt_opts" ]; then
1349 mt_opts="-o skpath=$SK_PATH"
1351 mt_opts="$mt_opts,skpath=$SK_PATH"
1361 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1370 [ $from_tree = true ]
1374 if $SHARED_KEY; then
1383 if ! module_loaded ptlrpc_gss; then
1384 load_module ptlrpc/gss/ptlrpc_gss
1385 module_loaded ptlrpc_gss ||
1386 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1389 if $GSS_KRB5 || $GSS_SK; then
1390 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1393 if $GSS_SK && ! $SK_NO_KEY; then
1394 echo "Loading basic SSK keys on all servers"
1395 do_nodes $(comma_list $(all_server_nodes)) \
1396 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1397 do_nodes $(comma_list $(all_server_nodes)) \
1398 "keyctl show | grep lustre | cut -c1-11 |
1400 xargs -IX keyctl setperm X 0x3f3f3f3f"
1403 if $GSS_SK && $SK_NO_KEY; then
1404 local numclients=${1:-$CLIENTCOUNT}
1405 local clients=${CLIENTS:-$HOSTNAME}
1407 # security ctx config for keyring
1409 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1411 if from_build_tree; then
1412 mkdir -p $SK_OM_PATH
1413 if grep -q request-key /proc/mounts > /dev/null; then
1414 echo "SSK: Request key already mounted."
1416 mount -o bind $SK_OM_PATH /etc/request-key.d/
1418 local lgssc_conf_line='create lgssc * * '
1419 lgssc_conf_line+=$(which lgss_keyring)
1420 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1421 echo "$lgssc_conf_line" > $lgssc_conf_file
1424 [ -e $lgssc_conf_file ] ||
1425 error_exit "Could not find key options in $lgssc_conf_file"
1426 echo "$lgssc_conf_file content is:"
1427 cat $lgssc_conf_file
1429 if ! local_mode; then
1430 if from_build_tree; then
1431 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1433 do_nodes $(comma_list $(all_nodes)) "mount \
1434 -o bind $SK_OM_PATH \
1435 /etc/request-key.d/"
1436 do_nodes $(comma_list $(all_nodes)) "rsync \
1437 -aqv $HOSTNAME:$lgssc_conf_file \
1438 $lgssc_conf_file >/dev/null 2>&1"
1440 do_nodes $(comma_list $(all_nodes)) \
1441 "echo $lgssc_conf_file: ; \
1442 cat $lgssc_conf_file"
1446 # create shared key on all nodes
1447 mkdir -p $SK_PATH/nodemap
1448 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1449 $SK_PATH/$FSNAME-*.key
1450 # for nodemap testing each client may need own key,
1451 # and S2S now requires keys as well, both for "client"
1454 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1455 -w $SK_PATH/$FSNAME-nmclient.key \
1456 -d /dev/urandom >/dev/null 2>&1
1457 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1458 -w $SK_PATH/$FSNAME-s2s-server.key \
1459 -d /dev/urandom >/dev/null 2>&1
1462 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1463 -d /dev/urandom >/dev/null 2>&1
1465 for i in $(seq 0 $((numclients - 1))); do
1466 $LGSS_SK -t server -f$FSNAME -n c$i \
1467 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1471 if ! local_mode; then
1472 for lnode in $(all_nodes); do
1473 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1476 # Set client keys to client type to generate prime P
1478 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1479 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1481 do_nodes $clients "$LGSS_SK -t client -m \
1482 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1483 do_nodes $clients "find $SK_PATH/nodemap \
1484 -name \*.key | xargs -IX $LGSS_SK -t client \
1485 -m X >/dev/null 2>&1"
1486 # also have a client key available on server side,
1487 # for local client mount
1488 do_nodes $(comma_list $(all_server_nodes)) \
1489 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1490 $LGSS_SK -t client -m \
1491 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1493 # This is required for servers as well, if S2S in use
1495 do_nodes $(comma_list $(mdts_nodes)) \
1496 "cp $SK_PATH/$FSNAME-s2s-server.key \
1497 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1498 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1500 do_nodes $(comma_list $(osts_nodes)) \
1501 "cp $SK_PATH/$FSNAME-s2s-server.key \
1502 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1503 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1505 do_nodes $clients "$LGSS_SK -t client \
1506 -m $SK_PATH/$FSNAME-nmclient.key \
1511 # mount options for servers and clients
1512 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1513 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1514 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1515 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1517 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1518 LGSS_KEYRING_DEBUG=4
1522 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1523 ( local_mode || from_build_tree ); then
1525 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1526 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1527 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1529 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1532 do_nodesv $(comma_list $(all_server_nodes)) \
1533 "$LCTL set_param sptlrpc.gss.rsi_upcall=$L_GETAUTH"
1539 # maybe cleanup credential cache?
1546 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1547 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1548 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1552 $RPC_MODE || echo "Cleaning up Shared Key.."
1553 do_nodes $(comma_list $(all_nodes)) "rm -f \
1554 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1555 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1556 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1557 if from_build_tree; then
1558 # Remove the mount and clean up the files we added to
1560 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1561 request-key.d /proc/mounts; do umount \
1562 /etc/request-key.d/; done"
1563 do_nodes $(comma_list $(all_nodes)) "rm -f \
1564 $SK_OM_PATH/lgssc.conf"
1565 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1573 local var=${facet}_svc
1581 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1582 tr '[:lower:]' '[:upper:]'
1588 if [ $facet == mgs ] || [ $facet == client ]; then
1592 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1600 if [ -n "${!var}" ]; then
1605 var=$(facet_type $facet)FSTYPE
1606 if [ -n "${!var}" ]; then
1611 if [ -n "$FSTYPE" ]; then
1616 if [[ $facet == mgs ]] && combined_mgs_mds; then
1628 local facets=$(get_facets)
1631 for facet in ${facets//,/ }; do
1632 if [[ $node == $(facet_host $facet) ]] ||
1633 [[ $node == "$(facet_failover_host $facet)" ]]; then
1634 fstype=$(facet_fstype $facet)
1635 if [[ $fstypes != *$fstype* ]]; then
1636 fstypes+="${fstypes:+,}$fstype"
1645 local num=$(facet_number $facet)
1648 if [[ $(facet_type $facet) = OST ]]; then
1649 index=OSTINDEX${num}
1650 if [[ -n "${!index}" ]]; then
1655 index=${OST_INDICES[num - 1]}
1658 [[ -n "$index" ]] || index=$((num - 1))
1666 local fstype=$(facet_fstype $facet)
1670 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1672 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1673 ${dev} 2>/dev/null");;
1675 error "unknown fstype!";;
1682 # Get the device of a facet.
1689 mgs) device=$(mgsdevname) ;;
1690 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1691 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1692 fs2mds) device=$(mdsdevname 1_2) ;;
1693 fs2ost) device=$(ostdevname 1_2) ;;
1694 fs3ost) device=$(ostdevname 2_2) ;;
1702 # Get the virtual device of a facet.
1709 mgs) device=$(mgsvdevname) ;;
1710 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1711 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1712 fs2mds) device=$(mdsvdevname 1_2) ;;
1713 fs2ost) device=$(ostvdevname 1_2) ;;
1714 fs3ost) device=$(ostvdevname 2_2) ;;
1722 local virt=$(virt-what 2> /dev/null)
1724 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1726 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1729 VMware|KVM|VirtualBox|Parallels|Bochs)
1730 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1735 virt=$(dmidecode -s system-manufacturer | awk '{print $1}')
1738 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1744 # Re-read the partition table on failover partner host.
1745 # After a ZFS storage pool is created on a shared device, the partition table
1746 # on the device may change. However, the operating system on the failover
1747 # host may not notice the change automatically. Without the up-to-date partition
1748 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1749 # relative to partition rather than disk beginnings.
1751 # This function performs partprobe on the failover host to make it re-read the
1754 refresh_partition_table() {
1759 host=$(facet_passive_host $facet)
1760 if [[ -n "$host" ]]; then
1761 do_node $host "$PARTPROBE $device"
1766 # Get ZFS storage pool name.
1773 device=$(facet_device $facet)
1774 # poolname is string before "/"
1775 poolname="${device%%/*}"
1782 # Get ZFS local fsname.
1784 zfs_local_fsname() {
1786 local lfsname=$(basename $(facet_device $facet))
1792 # Create ZFS storage pool.
1799 local opts=${@:-"-o cachefile=none"}
1801 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1802 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1803 $ZPOOL create -f $opts $poolname $vdev"
1807 # Create ZFS file system.
1813 local opts=${@:-"-o mountpoint=legacy"}
1815 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1816 $ZFS create $opts $dataset"
1820 # Export ZFS storage pool.
1821 # Before exporting the pool, all datasets within the pool should be unmounted.
1829 poolname=$(zpool_name $facet)
1831 if [[ -n "$poolname" ]]; then
1832 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1833 grep -q ^$poolname/ /proc/mounts ||
1834 $ZPOOL export $opts $poolname"
1839 # Destroy ZFS storage pool.
1840 # Destroy the given pool and free up any devices for other use. This command
1841 # tries to unmount any active datasets before destroying the pool.
1842 # -f Force any active datasets contained within the pool to be unmounted.
1846 local poolname=${2:-$(zpool_name $facet)}
1848 if [[ -n "$poolname" ]]; then
1849 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1850 $ZPOOL destroy -f $poolname"
1855 # Import ZFS storage pool.
1856 # Force importing, even if the pool appears to be potentially active.
1861 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1864 poolname=$(zpool_name $facet)
1866 if [[ -n "$poolname" ]]; then
1867 opts+=" -d $(dirname $(facet_vdevice $facet))"
1868 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1869 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1870 $ZPOOL import -f $opts $poolname"
1875 # Reimport ZFS storage pool with new name
1880 local opts="-o cachefile=none"
1881 local poolname=$(zpool_name $facet)
1883 opts+=" -d $(dirname $(facet_vdevice $facet))"
1884 do_facet $facet "$ZPOOL export $poolname;
1885 $ZPOOL import $opts $poolname $newpool"
1889 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1890 # is not automatically imported on system startup.
1892 # In a failover environment, this will provide resource level fencing which
1893 # will ensure that the same ZFS storage pool will not be imported concurrently
1894 # on different nodes.
1896 disable_zpool_cache() {
1900 poolname=$(zpool_name $facet)
1902 if [[ -n "$poolname" ]]; then
1903 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1908 # This and set_osd_param() shall be used to access OSD parameters
1909 # once existed under "obdfilter":
1914 # writethrough_cache_enable
1918 local device=${2:-$FSNAME-OST*}
1921 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1926 local device=${2:-$FSNAME-OST*}
1930 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1933 set_default_debug () {
1934 local debug=${1:-"$PTLDEBUG"}
1935 local subsys=${2:-"$SUBSYSTEM"}
1936 local debug_size=${3:-$DEBUG_SIZE}
1938 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1940 lctl set_param subsystem_debug="${subsys# }" >/dev/null
1941 [ -n "$debug_size" ] &&
1942 lctl set_param debug_mb="$debug_size" >/dev/null
1947 set_default_debug_nodes () {
1949 local debug="${2:-"$PTLDEBUG"}"
1950 local subsys="${3:-"$SUBSYSTEM"}"
1951 local debug_size="${4:-$DEBUG_SIZE}"
1953 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1954 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1958 [[ -z "$nodes" ]] ||
1959 do_rpc_nodes "$nodes" set_default_debug \
1960 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1963 set_default_debug_facet () {
1965 local debug="${2:-"$PTLDEBUG"}"
1966 local subsys="${3:-"$SUBSYSTEM"}"
1967 local debug_size="${4:-$DEBUG_SIZE}"
1968 local node=$(facet_active_host $facet)
1970 [ -n "$node" ] || error "No host defined for facet $facet"
1972 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1975 set_params_nodes() {
1980 [[ -n "$params" ]] || return 0
1982 do_nodes $nodes "$LCTL set_param $params"
1985 set_params_clients() {
1986 (( $# >= 2 )) || return 0
1987 local clients=${1:-$CLIENTS}
1989 local params="${@:-$CLIENT_LCTL_SETPARAM_PARAM}"
1991 set_params_nodes $clients $params
1995 (( $# >= 2 )) || return 0
1996 local mdts=${1:-$(comma_list $(mdts_nodes))}
1998 local params="${@:-$MDS_LCTL_SETPARAM_PARAM}"
2000 set_params_nodes $mdts $params
2004 (( $# >= 2 )) || return 0
2005 local osts=${1:-$(comma_list $(osts_nodes))}
2007 local params="${@:-$OSS_LCTL_SETPARAM_PARAM}"
2009 set_params_nodes $osts $params
2013 local hostid=${1:-$(hostid)}
2015 if [ ! -s /etc/hostid ]; then
2016 printf $(echo -n $hostid |
2017 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
2023 local facets=${1:-$(get_facets)}
2029 for facet in ${facets//,/ }; do
2030 mount_facet $facet &
2034 for ((index=0; index<$total; index++)); do
2035 wait ${mountpids[index]}
2037 [ $RC -eq 0 ] && continue
2039 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
2040 skip_noexit "Restart of $facet failed!." &&
2043 error "Restart of $facet failed!"
2051 # Add argument "arg" (e.g., "loop") to the comma-separated list
2052 # of arguments for option "opt" (e.g., "-o") on command
2053 # line "opts" (e.g., "-o flock").
2059 local opt_pattern="\([[:space:]]\+\|^\)$opt"
2061 if echo "$opts" | grep -q $opt_pattern; then
2062 opts=$(echo "$opts" | sed -e \
2063 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
2065 opts+="${opts:+ }$opt $arg"
2071 # Associate loop device with a given regular file.
2072 # Return the loop device.
2074 setup_loop_device() {
2078 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
2079 if [[ -z \\\$loop_dev ]]; then
2080 loop_dev=\\\$($LOSETUP -f);
2081 $LOSETUP \\\$loop_dev $file || loop_dev=;
2083 echo -n \\\$loop_dev"
2087 # Detach a loop device.
2089 cleanup_loop_device() {
2093 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
2094 $LOSETUP -d $loop_dev"
2098 # Check if a given device is a block device.
2105 [[ -n "$dev" ]] || return 1
2106 do_facet $facet "test -b $dev" || return 1
2107 if [[ -n "$size" ]]; then
2108 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
2109 count=1 skip=$size 2>&1" |
2110 awk '($3 == "in") { print $1 }')
2111 [[ "$in" = "1+0" ]] || return 1
2116 # Check if a given device is a device-mapper device.
2122 [[ -n "$dev" ]] || return 1
2123 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
2127 # Check if a given device is a device-mapper flakey device.
2129 is_dm_flakey_dev() {
2134 [[ -n "$dev" ]] || return 1
2136 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
2138 [[ $type = flakey ]] && return 0 || return 1
2142 # Check if device-mapper flakey device is supported by the kernel
2143 # of $facet node or not.
2145 dm_flakey_supported() {
2149 do_facet $facet "modprobe dm-flakey;
2150 $DMSETUP targets | grep -q flakey" &> /dev/null
2154 # Get the device-mapper flakey device name of a given facet.
2156 dm_facet_devname() {
2158 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2160 echo -n ${facet}_flakey
2164 # Get the device-mapper flakey device of a given facet.
2165 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
2167 dm_facet_devpath() {
2170 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
2174 # Set a device-mapper device with a new table.
2176 # The table has the following format:
2177 # <logical_start_sector> <num_sectors> <target_type> <target_args>
2179 # flakey <target_args> includes:
2180 # <destination_device> <offset> <up_interval> <down_interval> \
2181 # [<num_features> [<feature_arguments>]]
2183 # linear <target_args> includes:
2184 # <destination_device> <start_sector>
2186 dm_set_dev_table() {
2189 local target_type=$3
2195 read tmp num_sectors tmp real_dev tmp \
2196 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
2198 case $target_type in
2200 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
2203 table="0 $num_sectors linear $real_dev 0"
2205 *) error "invalid target type $target_type" ;;
2208 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
2209 error "failed to suspend $dm_dev"
2210 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
2211 error "failed to load $target_type table into $dm_dev"
2212 do_facet $facet "$DMSETUP resume $dm_dev" ||
2213 error "failed to resume $dm_dev"
2217 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
2218 # feature parameter.
2221 # All write I/O is silently ignored.
2222 # Read I/O is handled correctly.
2224 dm_set_dev_readonly() {
2226 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2228 dm_set_dev_table $facet $dm_dev flakey
2232 # Set a device-mapper device to traditional linear mapping mode.
2234 dm_clear_dev_readonly() {
2236 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2238 dm_set_dev_table $facet $dm_dev linear
2242 # Set the device of a given facet as "read-only".
2244 set_dev_readonly() {
2246 local svc=${facet}_svc
2248 if [[ $(facet_fstype $facet) = zfs ]] ||
2249 ! dm_flakey_supported $facet; then
2250 do_facet $facet $LCTL --device ${!svc} readonly
2252 dm_set_dev_readonly $facet
2257 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
2264 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
2265 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
2266 echo -n $num_sectors
2270 # Create a device-mapper device with a given block device or regular file (will
2271 # be associated with loop device).
2272 # Return the full path of the device-mapper device.
2276 local real_dev=$2 # destination device
2277 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
2278 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
2280 # check if the device-mapper device to be created already exists
2281 if is_dm_dev $facet $dm_dev; then
2282 # if the existing device was set to "read-only", then clear it
2283 ! is_dm_flakey_dev $facet $dm_dev ||
2284 dm_clear_dev_readonly $facet $dm_dev
2290 # check if the destination device is a block device, and if not,
2291 # associate it with a loop device
2292 is_blkdev $facet $real_dev ||
2293 real_dev=$(setup_loop_device $facet $real_dev)
2294 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
2296 # now create the device-mapper device
2297 local num_sectors=$(get_num_sectors $facet $real_dev)
2298 local table="0 $num_sectors linear $real_dev 0"
2301 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
2302 { rc=${PIPESTATUS[0]}; dm_dev=; }
2303 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2310 # Map the facet name to its device variable name.
2312 facet_device_alias() {
2314 local dev_alias=$facet
2317 fs2mds) dev_alias=mds1_2 ;;
2318 fs2ost) dev_alias=ost1_2 ;;
2319 fs3ost) dev_alias=ost2_2 ;;
2327 # Save the original value of the facet device and export the new value.
2333 local active_facet=$(facet_active $facet)
2334 local dev_alias=$(facet_device_alias $active_facet)
2335 local dev_name=${dev_alias}_dev
2336 local dev=${!dev_name}
2338 if [[ $active_facet = $facet ]]; then
2339 local failover_dev=${dev_alias}failover_dev
2340 if [[ ${!failover_dev} = $dev ]]; then
2341 eval export ${failover_dev}_saved=$dev
2342 eval export ${failover_dev}=$dm_dev
2345 dev_alias=$(facet_device_alias $facet)
2346 local facet_dev=${dev_alias}_dev
2347 if [[ ${!facet_dev} = $dev ]]; then
2348 eval export ${facet_dev}_saved=$dev
2349 eval export ${facet_dev}=$dm_dev
2353 eval export ${dev_name}_saved=$dev
2354 eval export ${dev_name}=$dm_dev
2358 # Restore the saved value of the facet device.
2363 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2364 local dev_alias=$(facet_device_alias $facet)
2366 local saved_dev=${dev_alias}_dev_saved
2367 [[ -z ${!saved_dev} ]] ||
2368 eval export ${dev_alias}_dev=${!saved_dev}
2370 saved_dev=${dev_alias}failover_dev_saved
2371 [[ -z ${!saved_dev} ]] ||
2372 eval export ${dev_alias}failover_dev=${!saved_dev}
2376 # Remove a device-mapper device.
2377 # If the destination device is a loop device, then also detach it.
2381 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2385 is_dm_dev $facet $dm_dev || return 0
2387 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2388 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2390 do_facet $facet "$DMSETUP remove $dm_dev"
2391 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2393 unexport_dm_dev $facet
2395 # detach a loop device
2396 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2398 # unload dm-flakey module
2399 do_facet $facet "modprobe -r dm-flakey" || true
2405 local active_facet=$(facet_active $facet)
2406 local dev_alias=$(facet_device_alias $active_facet)
2407 local dev=${dev_alias}_dev
2408 local opt=${facet}_opt
2409 local mntpt=$(facet_mntpt $facet)
2410 local opts="${!opt} $@"
2411 local fstype=$(facet_fstype $facet)
2413 local dm_dev=${!dev}
2415 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2416 dev=mds1failover_dev
2418 module_loaded lustre || load_modules
2422 if dm_flakey_supported $facet; then
2423 dm_dev=$(dm_create_dev $facet ${!dev})
2424 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2427 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2429 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2431 # import ZFS storage pool
2432 import_zpool $facet || return ${PIPESTATUS[0]}
2434 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2435 lustre:svname $dm_dev");;
2437 error "unknown fstype!";;
2440 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2441 # for testing LU-482 error handling in mount_facets() and test_0a()
2442 if [ -f $TMP/test-lu482-trigger ]; then
2445 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2446 (( $seq_width >= 16384 )) || seq_width=16384
2448 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2450 if [[ ${facet} =~ ost ]]; then
2451 do_facet ${facet} "$LCTL set_param \
2452 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2456 if [ $RC -ne 0 ]; then
2457 echo "Start of $dm_dev on ${facet} failed ${RC}"
2461 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2462 if [[ "$health" != "healthy" ]]; then
2463 error "$facet is in a unhealthy state"
2466 set_default_debug_facet $facet
2468 if [[ $opts =~ .*nosvc.* ]]; then
2469 echo "Start $dm_dev without service"
2474 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2475 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2476 "" || error "$dm_dev failed to initialize!";;
2478 wait_update_facet ${facet} "$ZFS get -H -o value \
2479 lustre:svname $dm_dev 2>/dev/null | \
2480 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2481 error "$dm_dev failed to initialize!";;
2484 error "unknown fstype!";;
2488 # commit the device label change to disk
2489 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2490 echo "Commit the device label on ${!dev}"
2491 do_facet $facet "sync; sleep 1; sync"
2495 label=$(devicelabel ${facet} $dm_dev)
2496 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2497 eval export ${facet}_svc=${label}
2498 echo Started ${label}
2500 export_dm_dev $facet $dm_dev
2505 # start facet device options
2511 local dev_alias=$(facet_device_alias $facet)
2513 eval export ${dev_alias}_dev=${device}
2514 eval export ${facet}_opt=\"$*\"
2516 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2517 eval export mgs_dev=${device}
2519 local varname=${dev_alias}failover_dev
2520 if [ -n "${!varname}" ] ; then
2521 eval export ${dev_alias}failover_dev=${!varname}
2523 eval export ${dev_alias}failover_dev=$device
2524 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2525 eval export mgsfailover_dev=${device}
2529 local mntpt=$(facet_mntpt $facet)
2530 do_facet ${facet} mkdir -p $mntpt
2531 eval export ${facet}_MOUNT=$mntpt
2532 mount_facet ${facet}
2542 local HOST=$(facet_active_host $facet)
2543 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2545 local mntpt=$(facet_mntpt $facet)
2546 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2547 if [ ${running} -ne 0 ]; then
2548 echo "Stopping $mntpt (opts:$*) on $HOST"
2549 do_facet ${facet} $UMOUNT "$@" $mntpt
2552 # umount should block, but we should wait for unrelated obd's
2553 # like the MGS or MGC to also stop.
2554 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2556 if [[ $(facet_fstype $facet) == zfs ]]; then
2557 # export ZFS storage pool
2558 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2559 elif dm_flakey_supported $facet; then
2560 local host=${facet}_HOST
2561 local failover_host=${facet}failover_HOST
2562 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2563 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2564 dm_cleanup_dev $facet
2569 # get mdt quota type
2571 local varsvc=${SINGLEMDS}_svc
2572 do_facet $SINGLEMDS $LCTL get_param -n \
2573 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2576 # get ost quota type
2578 # All OSTs should have same quota type
2579 local varsvc=ost1_svc
2580 do_facet ost1 $LCTL get_param -n \
2581 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2584 # restore old quota type settings
2586 for usr in $QUOTA_USERS; do
2587 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2589 cmd="$LFS setquota -$type $usr -b 0"
2590 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2592 eval $cmd || error "$cmd FAILED!"
2594 # display the quota status
2595 echo "Quota settings for $usr : "
2596 $LFS quota -v -u $usr $MOUNT || true
2598 if [ "$old_MDT_QUOTA_TYPE" ]; then
2599 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2600 do_facet mgs $PERM_CMD \
2601 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2604 do_facet mgs $PERM_CMD \
2605 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2608 if [ "$old_OST_QUOTA_TYPE" ]; then
2609 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2610 do_facet mgs $PERM_CMD \
2611 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2614 do_facet mgs $LCTL conf_param \
2615 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2620 # Handle the case when there is a space in the lfs df
2621 # "filesystem summary" line the same as when there is no space.
2622 # This will allow fixing the "lfs df" summary line in the future.
2624 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2625 check_lfs_df_ret_val ${PIPESTATUS[0]}
2628 # Get free inodes on the MDT specified by mdt index, free indoes on
2629 # the whole filesystem will be returned when index == -1.
2635 if [ $index -eq -1 ]; then
2638 mdt_uuid=$(mdtuuid_from_index $index)
2641 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2646 # Get the OST device status from 'lfs df' with a given OST index.
2650 local mnt_pnt=${2:-$MOUNT}
2654 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2655 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2661 # save old quota type & set new quota type
2662 local mdt_qtype=$(mdt_quota_type)
2663 local ost_qtype=$(ost_quota_type)
2665 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2666 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2668 export old_MDT_QUOTA_TYPE=$mdt_qtype
2669 export old_OST_QUOTA_TYPE=$ost_qtype
2671 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2672 do_facet mgs $PERM_CMD \
2673 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2674 do_facet mgs $PERM_CMD \
2675 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2677 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2678 error "set mdt quota type failed"
2679 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2680 error "set ost quota type failed"
2683 local quota_usrs=$QUOTA_USERS
2685 # get_filesystem_size
2686 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2687 local blk_soft=$((disksz + 1024))
2688 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2690 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2691 local i_soft=$inodes
2692 local i_hard=$((i_soft + i_soft / 20))
2694 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2695 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2696 "inode-hardlimit: $i_hard"
2699 for usr in $quota_usrs; do
2700 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2702 cmd="$LFS setquota -$type $usr -b $blk_soft"
2703 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2705 eval $cmd || error "$cmd FAILED!"
2707 # display the quota status
2708 echo "Quota settings for $usr : "
2709 $LFS quota -v -u $usr $mntpt || true
2716 local opts=${3:-$MOUNT_OPTS}
2717 opts=${opts:+-o $opts}
2718 local flags=${4:-$MOUNT_FLAGS}
2720 local device=$MGSNID:/$FSNAME$FILESET
2721 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2722 echo "Bad mount command: opt=$flags $opts dev=$device " \
2728 # update mount option with skpath
2729 opts=$(add_sk_mntflag $opts)
2732 echo "Starting client: $client: $flags $opts $device $mnt"
2733 do_node $client mkdir -p $mnt
2734 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2735 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2737 #disable FILESET if not supported
2738 do_nodes $client lctl get_param -n \
2739 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2740 device=$MGSNID:/$FSNAME
2741 do_node $client mkdir -p $mnt/$FILESET
2742 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2745 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2746 # Mount using nodemap key
2747 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2748 if $SK_UNIQUE_NM; then
2749 mountkey=$SK_PATH/nodemap/c0.key
2751 local prunedopts=$(echo $opts |
2752 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2753 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2756 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2760 set_default_debug_nodes $client
2761 set_params_clients $client
2772 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2774 [ "$3" ] && force=-f
2775 [ $running -eq 0 ] && return 0
2777 echo "Stopping client $client $mnt (opts:$force)"
2778 do_node $client lsof -t $mnt || need_kill=no
2779 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2780 pids=$(do_node $client lsof -t $mnt | sort -u);
2781 if [ -n "$pids" ]; then
2782 do_node $client kill -9 $pids || true
2786 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2788 if [ $busy -ne 0 ] ; then
2789 echo "$mnt is still busy, wait one second" && sleep 1
2790 do_node $client umount $force $mnt
2794 # Mount the file system on the MDS
2795 mount_mds_client() {
2796 local host=$(facet_active_host $SINGLEMDS)
2798 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2799 error "unable to mount $MOUNT2 on $host"
2802 # Unmount the file system on the MDS
2803 umount_mds_client() {
2804 local host=$(facet_active_host $SINGLEMDS)
2805 zconf_umount $host $MOUNT2
2806 do_facet $SINGLEMDS "rmdir $MOUNT2"
2809 # nodes is comma list
2810 sanity_mount_check_nodes () {
2816 # FIXME: assume that all cluster nodes run the same os
2817 [ "$(uname)" = Linux ] || return 0
2820 for mnt in $mnts ; do
2821 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2822 mpts=\\\$(mount | grep -c $mnt' ');
2823 if [ \\\$running -ne \\\$mpts ]; then
2824 echo \\\$(hostname) env are INSANE!;
2827 [ $? -eq 0 ] || rc=1
2832 sanity_mount_check_servers () {
2833 [ -n "$CLIENTONLY" ] &&
2834 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2835 echo Checking servers environments
2837 # FIXME: modify get_facets to display all facets wo params
2838 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2842 for facet in ${facets//,/ }; do
2843 node=$(facet_host ${facet})
2844 mntpt=$(facet_mntpt $facet)
2845 sanity_mount_check_nodes $node $mntpt ||
2846 { error "server $node environments are insane!"; return 1; }
2850 sanity_mount_check_clients () {
2851 local clients=${1:-$CLIENTS}
2852 local mntpt=${2:-$MOUNT}
2853 local mntpt2=${3:-$MOUNT2}
2855 [ -z $clients ] && clients=$(hostname)
2856 echo Checking clients $clients environments
2858 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2859 error "clients environments are insane!"
2862 sanity_mount_check () {
2863 sanity_mount_check_servers || return 1
2864 sanity_mount_check_clients || return 2
2867 # mount clients if not mouted
2868 zconf_mount_clients() {
2871 local opts=${3:-$MOUNT_OPTS}
2872 opts=${opts:+-o $opts}
2873 local flags=${4:-$MOUNT_FLAGS}
2874 local device=$MGSNID:/$FSNAME$FILESET
2875 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2876 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2881 echo "Starting client $clients: $flags $opts $device $mnt"
2882 do_nodes $clients mkdir -p $mnt
2883 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2884 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2885 # Mount with own nodemap key
2887 # Mount all server nodes first with per-NM keys
2888 for nmclient in ${clients//,/ }; do
2889 do_nodes $(comma_list $(all_server_nodes)) \
2890 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
2893 # set perms for per-nodemap keys else permission denied
2894 do_nodes $(comma_list $(all_nodes)) \
2895 "keyctl show | grep lustre | cut -c1-11 |
2897 xargs -IX keyctl setperm X 0x3f3f3f3f"
2898 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2900 for nmclient in ${clients//,/ }; do
2901 if $SK_UNIQUE_NM; then
2902 mountkey=$SK_PATH/nodemap/c$i.key
2904 do_node $nmclient "! grep -q $mnt' ' \
2905 /proc/mounts || umount $mnt"
2906 local prunedopts=$(add_sk_mntflag $opts);
2907 prunedopts=$(echo $prunedopts | sed -e \
2908 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2910 do_nodes $(comma_list $(all_server_nodes)) \
2913 do_node $nmclient $MOUNT_CMD $flags \
2914 $prunedopts $MGSNID:/$FSNAME $mnt ||
2919 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2921 do_nodes $clients $MOUNT_CMD $flags $opts \
2922 $MGSNID:/$FSNAME $mnt || return 1
2924 #disable FILESET if not supported
2925 do_nodes $clients lctl get_param -n \
2926 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2927 device=$MGSNID:/$FSNAME
2928 do_nodes $clients mkdir -p $mnt/$FILESET
2929 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2933 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2934 # Mount with nodemap key
2936 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2937 for nmclient in ${clients//,/ }; do
2938 if $SK_UNIQUE_NM; then
2939 mountkey=$SK_PATH/nodemap/c$i.key
2941 local prunedopts=$(echo $opts | sed -e \
2942 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2943 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2946 running=\\\$(mount | grep -c $mnt' ');
2948 if [ \\\$running -eq 0 ] ; then
2950 $MOUNT_CMD $flags $prunedopts $device $mnt;
2953 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2954 grep 'type lustre' | wc -l);
2955 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2956 echo zconf_mount_clients FAILED: \
2957 mount count \\\$running, not matching \
2958 with mount count of 'type lustre' \
2959 \\\$lustre_mnt_count;
2963 exit \\\$rc" || return ${PIPESTATUS[0]}
2970 if $SHARED_KEY; then
2971 tmpopts=$(add_sk_mntflag $opts)
2974 running=\\\$(mount | grep -c $mnt' ');
2976 if [ \\\$running -eq 0 ] ; then
2978 $MOUNT_CMD $flags $tmpopts $device $mnt;
2981 exit \\\$rc" || return ${PIPESTATUS[0]}
2984 echo "Started clients $clients: "
2985 do_nodes $clients "mount | grep $mnt' '"
2987 set_default_debug_nodes $clients
2988 set_params_clients $clients
2993 zconf_umount_clients() {
2998 [ "$3" ] && force=-f
3000 echo "Stopping clients: $clients $mnt (opts:$force)"
3001 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
3002 if [ \\\$running -ne 0 ] ; then
3003 echo Stopping client \\\$(hostname) $mnt opts:$force;
3004 lsof $mnt || need_kill=no;
3005 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
3006 pids=\\\$(lsof -t $mnt | sort -u);
3007 if [ -n \\\"\\\$pids\\\" ]; then
3011 while umount $force $mnt 2>&1 | grep -q "busy"; do
3012 echo "$mnt is still busy, wait one second" && sleep 1;
3020 echo + $POWER_DOWN $node
3024 shutdown_node_hard () {
3026 local attempts=$SHUTDOWN_ATTEMPTS
3028 for i in $(seq $attempts) ; do
3031 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
3033 echo "waiting for $host to fail attempts=$attempts"
3034 [ $i -lt $attempts ] ||
3035 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
3041 local mnt=${2:-$MOUNT}
3044 if [ "$FAILURE_MODE" = HARD ]; then
3045 shutdown_node_hard $client
3047 zconf_umount_clients $client $mnt -f
3054 local facets="$(get_facets OST),$(get_facets MDS)"
3056 combined_mgs_mds || facets="$facets,mgs"
3058 for facet in ${facets//,/ }; do
3059 if [ $(facet_active_host $facet) == $host ]; then
3060 affected="$affected $facet"
3064 echo $(comma_list $affected)
3069 local host=${2:-$(facet_host $facet)}
3071 local label=$(convert_facet2label $facet)
3072 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
3075 facets_up_on_host () {
3078 local facets=$(facets_on_host $host)
3080 for facet in ${facets//,/ }; do
3081 if $(facet_up $facet $host); then
3082 affected_up="$affected_up $facet"
3086 echo $(comma_list $affected_up)
3091 local affected_facet
3092 local affected_facets
3094 if [[ "$FAILURE_MODE" = HARD ]]; then
3095 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
3096 dm_flakey_supported $facet; then
3097 affected_facets=$(affected_facets $facet)
3098 for affected_facet in ${affected_facets//,/ }; do
3099 unexport_dm_dev $affected_facet
3103 shutdown_node_hard $(facet_active_host $facet)
3112 echo + $POWER_UP $node
3125 local node=$(facet_active_host $facet)
3126 local sleep_time=${2:-10}
3128 if [ "$FAILURE_MODE" = HARD ]; then
3138 if [ "$FAILURE_MODE" = HARD ]; then
3141 if $LOAD_MODULES_REMOTE; then
3142 echo "loading modules on $node: $facet"
3143 do_rpc_nodes $node load_modules_local
3152 for facet in ${facets//,/ }; do
3153 hosts=$(expand_list $hosts $(facet_host $facet) )
3159 _check_progs_installed () {
3163 for prog in $progs; do
3164 if ! [ "$(which $prog)" -o "${!prog}" ]; then
3165 echo $prog missing on $(hostname)
3172 check_progs_installed () {
3176 do_rpc_nodes "$nodes" _check_progs_installed "$@"
3179 # recovery-scale functions
3181 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
3184 start_client_load() {
3187 local var=$(node_var_name $client)_load
3188 eval export ${var}=$load
3190 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
3191 BREAK_ON_ERROR=$BREAK_ON_ERROR \
3192 END_RUN_FILE=$END_RUN_FILE \
3193 LOAD_PID_FILE=$LOAD_PID_FILE \
3194 TESTLOG_PREFIX=$TESTLOG_PREFIX \
3195 TESTNAME=$TESTNAME \
3196 DBENCH_LIB=$DBENCH_LIB \
3197 DBENCH_SRC=$DBENCH_SRC \
3198 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
3203 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
3204 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
3205 num_clients=$(get_node_count ${CLIENTS//,/ }) \
3206 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
3207 ior_blockSize=$ior_blockSize \
3208 ior_blockUnit=$ior_blockUnit \
3209 ior_xferSize=$ior_xferSize ior_type=$ior_type \
3210 ior_DURATION=$ior_DURATION \
3211 ior_stripe_params=\\\"$ior_stripe_params\\\" \
3212 ior_custom_params=\\\"$ior_custom_param\\\" \
3213 mpi_ior_custom_threads=$mpi_ior_custom_threads \
3216 log "Started client load: ${load} on $client"
3218 # get the children process IDs
3219 local pids=$(ps --ppid $ppid -o pid= | xargs)
3220 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
3224 start_client_loads () {
3225 local -a clients=(${1//,/ })
3226 local numloads=${#CLIENT_LOADS[@]}
3228 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
3229 local load=$((nodenum % numloads))
3230 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
3232 # bug 22169: wait the background threads to start
3236 # only for remote client
3237 check_client_load () {
3239 local var=$(node_var_name $client)_load
3240 local testload=run_${!var}.sh
3242 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
3244 # bug 18914: try to connect several times not only when
3245 # check ps, but while check_node_health also
3249 while [ $RC = 254 -a $tries -gt 0 ]; do
3253 if ! check_node_health $client; then
3255 if [ $RC -eq 254 ]; then
3256 # FIXME: not sure how long we shuold sleep here
3260 echo "check node health failed: RC=$RC "
3264 # We can continue try to connect if RC=254
3265 # Just print the warning about this
3266 if [ $RC = 254 ]; then
3267 echo "got a return status of $RC from do_node while checking " \
3268 "node health on $client"
3271 # see if the load is still on the client
3274 while [ $RC = 254 -a $tries -gt 0 ]; do
3278 if ! do_node $client \
3279 "ps auxwww | grep -v grep | grep -q $testload"; then
3284 if [ $RC = 254 ]; then
3285 echo "got a return status of $RC from do_node while checking " \
3286 "(node health and 'ps') the client load on $client"
3287 # see if we can diagnose a bit why this is
3292 check_client_loads () {
3293 local clients=${1//,/ }
3297 for client in $clients; do
3298 check_client_load $client
3300 if [ "$rc" != 0 ]; then
3301 log "Client load failed on node $client, rc=$rc"
3307 restart_client_loads () {
3308 local clients=${1//,/ }
3309 local expectedfail=${2:-""}
3313 for client in $clients; do
3314 check_client_load $client
3316 if [ "$rc" != 0 -a "$expectedfail" ]; then
3317 local var=$(node_var_name $client)_load
3319 start_client_load $client ${!var}
3320 echo "Restarted client load ${!var}: on $client. Checking ..."
3321 check_client_load $client
3323 if [ "$rc" != 0 ]; then
3324 log "Client load failed to restart on node $client, rc=$rc"
3325 # failure one client load means test fail
3326 # we do not need to check other
3335 # Start vmstat and save its process ID in a file.
3340 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3343 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3344 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3347 # Display the nodes on which client loads failed.
3348 print_end_run_file() {
3352 [ -s $file ] || return 0
3354 echo "Found the END_RUN_FILE file: $file"
3357 # A client load will stop if it finds the END_RUN_FILE file.
3358 # That does not mean the client load actually failed though.
3359 # The first node in END_RUN_FILE is the one we are interested in.
3362 if [ -n "$node" ]; then
3363 local var=$(node_var_name $node)_load
3365 local prefix=$TESTLOG_PREFIX
3366 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3367 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3368 local debug_log=$(echo $stdout_log |
3369 sed 's/\(.*\)stdout/\1debug/')
3371 echo "Client load ${!var} failed on node $node:"
3377 # Stop the process which had its PID saved in a file.
3382 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3384 do_nodes $nodes "test -f $pid_file &&
3385 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3388 # Stop all client loads.
3389 stop_client_loads() {
3390 local nodes=${1:-$CLIENTS}
3393 # stop the client loads
3394 stop_process $nodes $pid_file
3396 # clean up the processes that started them
3397 [ -n "$CLIENT_LOAD_PIDS" ] &&
3398 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3400 # End recovery-scale functions
3403 # wait for a command to return the expected result
3405 # This will run @check on @node repeatedly until the output matches @expect
3406 # based on the supplied condition, or until @max_wait seconds have elapsed,
3407 # whichever comes first. @cond may be one of the normal bash operators,
3408 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3409 # in the caller to avoid unintentional evaluation by the shell in the caller.
3411 # If @max_wait is not specified, the condition will be checked for up to 90s.
3413 # If --verbose is passed as the first argument, the result is printed on each
3414 # value change, otherwise it is only printed after every 10s interval.
3416 # If --quiet is passed as the first/second argument, the do_node() command
3417 # will not print the remote command before executing it each time.
3419 # Using wait_update_cond() or related helper function is preferable to adding
3420 # a "long enough" wait for some state to change in the background, since
3421 # "long enough" may be too short due to tunables, system config, or running in
3422 # a VM, and must by necessity wait too long for most cases or risk failure.
3424 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3425 wait_update_cond() {
3429 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3430 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3436 local max_wait=${5:-90}
3440 local begin=$SECONDS
3444 while (( $waited <= $max_wait )); do
3445 result=$(do_node $quiet $node "$check")
3447 eval [[ "'$result'" $cond "'$expect'" ]]
3448 if [[ $? == 0 ]]; then
3449 [[ -n "$quiet" ]] && return 0
3450 [[ -z "$result" || $waited -le $sleep ]] ||
3451 echo "Updated after ${waited}s: want '$expect' got '$result'"
3454 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3455 [[ -z "$quiet" && -n "$prev_result" ]] &&
3456 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3457 prev_result="$result"
3459 (( $waited % $print == 0 )) && {
3460 [[ -z "$quiet" ]] &&
3461 echo "Waiting $((max_wait - waited))s for '$expect'"
3465 waited=$((SECONDS - begin))
3468 [[ -z "$quiet" ]] &&
3469 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3474 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3479 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3480 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3487 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3490 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3491 wait_update_facet_cond() {
3495 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3496 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3498 local node=$(facet_active_host $1)
3504 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3507 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3508 wait_update_facet() {
3512 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3513 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3515 local node=$(facet_active_host $1)
3520 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3524 do_nodes $(comma_list $(mdts_nodes)) \
3525 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3526 do_nodes $(comma_list $(osts_nodes)) \
3527 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3528 grep -v 'Found no match'
3532 local zfs_wait=${2:-5}
3534 # the occupied disk space will be released
3535 # only after TXGs are committed
3536 if [[ $(facet_fstype $1) == zfs ]]; then
3537 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3545 local lwm=$3 #low watermark
3546 local size_mb #how many MB should we write to pass watermark
3547 local ost_name=$(ostname_from_index $ost_idx)
3549 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3551 if (( $free_kb / 1024 > lwm )); then
3552 size_mb=$((free_kb / 1024 - lwm))
3554 #If 10% of free space cross low watermark use it
3555 if (( $free_kb / 10240 > size_mb )); then
3556 size_mb=$((free_kb / 10240))
3558 #At least we need to store 1.1 of difference between
3559 #free space and low watermark
3560 size_mb=$((size_mb + size_mb / 10))
3562 if (( lwm <= $free_kb / 1024 )) ||
3563 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3564 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3565 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3566 count=$size_mb oflag=append conv=notrunc
3571 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3572 echo "OST still has $((free_kb / 1024)) MB free"
3575 # This checks only the primary MDS
3576 ost_watermarks_get() {
3578 local ost_name=$(ostname_from_index $ost_idx)
3579 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3581 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3582 osp.$mdtosc_proc.reserved_mb_high)
3583 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3584 osp.$mdtosc_proc.reserved_mb_low)
3589 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3590 ost_watermarks_set() {
3594 local ost_name=$(ostname_from_index $ost_idx)
3595 local facets=$(get_facets MDS)
3597 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3598 osp.*$ost_name*.reserved_mb_low=$lwm \
3599 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3601 # sleep to ensure we see the change
3605 ost_watermarks_set_low_space() {
3607 local wms=$(ost_watermarks_get $ost_idx)
3608 local ost_name=$(ostname_from_index $ost_idx)
3610 local old_lwm=$(echo $wms | awk '{ print $1 }')
3611 local old_hwm=$(echo $wms | awk '{ print $2 }')
3613 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3614 # minimal extension size is 64M
3616 if (( $blocks / 1024 > 50 )); then
3617 new_lwm=$((blocks / 1024 - 50))
3619 local new_hwm=$((new_lwm + 5))
3621 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3622 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3625 # Set watermarks to ~current available space & then write data to fill it
3626 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3627 # internal statfs used by the stripe allocator
3629 # first parameter is the filename-prefix, which must get under t-f cleanup
3630 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3631 ost_watermarks_set_enospc() {
3635 local ost_name=$(ostname_from_index $ost_idx)
3636 local facets=$(get_facets MDS)
3640 for MDS in ${facets//,/ }; do
3641 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3643 do_facet $MDS $LCTL get_param -n \
3644 osp.$mdtosc_proc.reserved_mb_high ||
3645 skip "remote MDS does not support reserved_mb_high"
3648 wms=$(ost_watermarks_set_low_space $ost_idx)
3649 local new_lwm=$(echo $wms | awk '{ print $4 }')
3650 fill_ost $filename $ost_idx $new_lwm
3651 #First enospc could execute orphan deletion so repeat
3652 fill_ost $filename $ost_idx $new_lwm
3656 ost_watermarks_enospc_delete_files() {
3660 rm -f $DIR/${filename}.fill_ost$ost_idx
3662 wait_delete_completed
3666 # clean up from "ost_watermarks_set_enospc"
3667 ost_watermarks_clear_enospc() {
3673 ost_watermarks_enospc_delete_files $filename $ost_idx
3674 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3675 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3678 wait_delete_completed_mds() {
3679 local max_wait=${1:-20}
3681 local stime=$(date +%s)
3686 # find MDS with pending deletions
3687 for node in $(mdts_nodes); do
3688 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3689 2>/dev/null | calc_sum)
3690 if [[ $changes -eq 0 ]]; then
3693 mds2sync="$mds2sync $node"
3695 if [ -z "$mds2sync" ]; then
3696 wait_zfs_commit $SINGLEMDS
3699 mds2sync=$(comma_list $mds2sync)
3701 # sync MDS transactions
3702 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3704 # wait till all changes are sent and commmitted by OSTs
3705 # for ldiskfs space is released upon execution, but DMU
3706 # do this upon commit
3709 while [[ $WAIT -ne $max_wait ]]; do
3710 changes=$(do_nodes $mds2sync \
3711 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3712 #echo "$node: $changes changes on all"
3713 if [[ $changes -eq 0 ]]; then
3714 wait_zfs_commit $SINGLEMDS
3716 # the occupied disk space will be released
3717 # only after TXGs are committed
3718 wait_zfs_commit ost1
3726 echo "Delete is not completed in $((etime - stime)) seconds"
3727 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3734 # we can use "for" here because we are waiting the slowest
3735 for host in ${hostlist//,/ }; do
3736 check_network "$host" 900
3738 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3745 for facet in ${facetlist//,/ }; do
3746 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3748 wait_for_host $hostlist
3751 _wait_recovery_complete () {
3754 # Use default policy if $2 is not passed by caller.
3755 local MAX=${2:-$(max_recovery_time)}
3760 while [ $WAIT -lt $MAX ]; do
3761 STATUS=$(lctl get_param -n $param | grep status)
3763 [[ $STATUS == "status: COMPLETE" ||
3764 $STATUS == "status: INACTIVE" ]] && return 0
3767 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3769 echo "$param recovery not done in $MAX sec. $STATUS"
3773 wait_recovery_complete () {
3776 # with an assumption that at_max is the same on all nodes
3777 local MAX=${2:-$(max_recovery_time)}
3780 if [ "$FAILURE_MODE" = HARD ]; then
3781 facets=$(facets_on_host $(facet_active_host $facet))
3783 echo affected facets: $facets
3785 facets=${facets//,/ }
3786 # We can use "for" here because we are waiting the slowest.
3787 # The mgs not having the recovery_status proc entry, exclude it
3788 # from the facet list.
3789 for facet in ${facets//mgs/ }; do
3790 local var_svc=${facet}_svc
3791 local param="*.${!var_svc}.recovery_status"
3793 local host=$(facet_active_host $facet)
3794 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3798 wait_mds_ost_sync () {
3799 # just because recovery is done doesn't mean we've finished
3800 # orphan cleanup. Wait for llogs to get synchronized.
3801 echo "Waiting for orphan cleanup..."
3802 # MAX value includes time needed for MDS-OST reconnection
3803 local MAX=$(( TIMEOUT * 2 ))
3804 local WAIT_TIMEOUT=${1:-$MAX}
3807 local list=$(comma_list $(mdts_nodes))
3808 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3809 if ! do_facet $SINGLEMDS \
3810 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3812 # old way, use mds_sync
3814 list=$(comma_list $(osts_nodes))
3815 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3818 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3819 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3820 local -a sync=($(do_nodes $list "$cmd"))
3823 for ((i=0; i<${#sync[@]}; i++)); do
3825 [ ${sync[$i]} -eq 1 ] && continue
3827 [ ${sync[$i]} -eq 0 ] && continue
3829 # there is a not finished MDS-OST synchronization
3833 sleep 2 # increase waiting time and cover statfs cache
3834 [ ${con} -eq 1 ] && return 0
3835 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3839 # show which nodes are not finished.
3840 cmd=$(echo $cmd | sed 's/-n//')
3841 do_nodes $list "$cmd"
3842 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3846 # Wait OSTs to be active on both client and MDT side.
3848 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3849 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3850 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3851 error "wait_update OSTs up on client failed"
3853 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3854 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3855 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3856 error "wait_update OSTs up on MDT0000 failed"
3859 wait_destroy_complete () {
3860 echo "Waiting for MDT destroys to complete"
3861 # MAX value shouldn't be big as this mean server responsiveness
3862 # never increase this just to make test pass but investigate
3863 # why it takes so long time
3866 local list=$(comma_list $(mdts_nodes))
3867 while [ $WAIT -lt $MAX ]; do
3868 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3872 for ((i=0; i<${#RPCs[@]}; i++)); do
3873 [ ${RPCs[$i]} -eq 0 ] && continue
3874 # there are still some destroy RPCs in flight
3878 [ ${con} -eq 1 ] && return 0 # done waiting
3880 echo "Waiting ${WAIT}s for local destroys to complete"
3883 echo "MDT destroys weren't done in $MAX sec."
3887 wait_delete_completed() {
3888 wait_delete_completed_mds $1 || return $?
3889 wait_destroy_complete || return $?
3898 # conf-sanity 31 takes a long time cleanup
3899 while [ $WAIT -lt 300 ]; do
3900 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3901 lctl dl | grep ' ST ' || true")
3902 [ -z "${running}" ] && return 0
3903 echo "waited $WAIT for${running}"
3904 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3906 WAIT=$((WAIT + INTERVAL))
3908 echo "service didn't stop after $WAIT seconds. Still running:"
3913 wait_remote_prog () {
3919 [ "$PDSH" = "no_dsh" ] && return 0
3921 while [ $WAIT -lt $2 ]; do
3922 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3923 grep -v grep) || true
3924 [ -z "${running}" ] && return 0 || true
3925 echo "waited $WAIT for: "
3927 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3929 WAIT=$((WAIT + INTERVAL))
3931 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3932 grep -v grep | awk '{print $2}')
3933 [ -z "$pids" ] && return 0
3934 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3935 # FIXME: not portable
3936 for pid in $pids; do
3937 cat /proc/${pid}/status || true
3938 cat /proc/${pid}/wchan || true
3940 kill -9 $pid || true
3949 local clients=${1:-$CLIENTS}
3952 if [[ -z "$clients" ]]; then
3953 $LFS df $MOUNT > /dev/null || rc=$?
3955 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3962 local clients=${1:-$CLIENTS}
3965 _lfs_df_check "$clients" || rc=$?
3967 check_lfs_df_ret_val $rc
3971 # not every config has many clients
3977 (( MDSCOUNT == 1 )) && return
3979 # wait so that statfs data on MDT expire
3980 local delay=$(do_facet mds1 $LCTL \
3981 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3983 [ -n "$delay" ] || error "fail to get maxage"
3985 local nodes=$(comma_list $(mdts_nodes))
3986 # initiate statfs RPC, all to all MDTs
3987 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3988 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3992 # usually checked on particular client or locally
4002 client_reconnect_try() {
4003 local f=$MOUNT/recon
4006 if [ -z "$CLIENTS" ]; then
4007 $LFS df $MOUNT; uname -n >> $f
4009 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
4011 echo "Connected clients: $(cat $f)"
4012 ls -l $f > /dev/null
4016 client_reconnect() {
4017 # one client_reconnect_try call does not always do the job...
4019 client_reconnect_try && break
4024 affected_facets () {
4027 local host=$(facet_active_host $facet)
4028 local affected=$facet
4030 if [ "$FAILURE_MODE" = HARD ]; then
4031 affected=$(facets_up_on_host $host)
4037 local E2FSCK_ON_MDT0=false
4038 if [ "$1" == "--fsck" ]; then
4040 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4052 #Because it will only get up facets, we need get affected
4053 #facets before shutdown
4054 #For HARD Failure mode, it needs make sure facets on the same
4055 #HOST will only be shutdown and reboot once
4056 for facet in ${facets//,/ }; do
4057 local affected_facet
4059 #check whether facet has been included in other affected facets
4060 for ((index=0; index<$total; index++)); do
4061 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
4064 if [ $skip -eq 0 ]; then
4065 affecteds[$total]=$(affected_facets $facet)
4070 for ((index=0; index<$total; index++)); do
4071 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
4072 local host=$(facet_active_host $facet)
4073 echo "Failing ${affecteds[index]} on $host"
4074 shutdown_facet $facet
4077 echo "$(date +'%H:%M:%S (%s)') shut down"
4082 for facet in ${facets//,/ }; do
4083 local host=$(facet_active_host $facet)
4085 hostlist=$(expand_list $hostlist $host)
4086 if [ $(facet_host $facet) = \
4087 $(facet_failover_host $facet) ]; then
4088 waithostlist=$(expand_list $waithostlist $host)
4092 if [ "$FAILURE_MODE" = HARD ]; then
4093 for host in ${hostlist//,/ }; do
4096 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
4097 # We need to wait the rebooted hosts in case if
4098 # facet_HOST == facetfailover_HOST
4099 if ! [ -z "$waithostlist" ]; then
4100 wait_for_host $waithostlist
4101 if $LOAD_MODULES_REMOTE; then
4102 echo "loading modules on $waithostlist"
4103 do_rpc_nodes $waithostlist load_modules_local
4110 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
4111 change_active $SINGLEMDS
4114 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
4115 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
4119 for ((index=0; index<$total; index++)); do
4120 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
4121 change_active ${affecteds[index]}
4125 init_facets_vars_simple
4127 # start mgs first if it is affected
4128 if ! combined_mgs_mds &&
4129 list_member ${affecteds[index]} mgs; then
4130 mount_facet mgs || error "Restart of mgs failed"
4131 affecteds[index]=$(exclude_items_from_list \
4132 ${affecteds[index]} mgs)
4134 if [ -n "${affecteds[index]}" ]; then
4135 echo mount facets: ${affecteds[index]}
4136 mount_facets ${affecteds[index]} &
4140 for ((index=0; index<$total; index++)); do
4141 if [ -n "${affecteds[index]}" ]; then
4142 wait ${mountpids[index]}
4146 do_nodes $(comma_list $(all_nodes)) \
4147 "keyctl show | grep lustre | cut -c1-11 |
4149 xargs -IX keyctl setperm X 0x3f3f3f3f"
4152 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
4154 if [ "$FAILURE_MODE" = HARD ]; then
4155 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
4156 if ! [ -z "$hostlist" ]; then
4157 wait_for_host $hostlist
4158 if $LOAD_MODULES_REMOTE; then
4159 echo "loading modules on $hostlist"
4160 do_rpc_nodes $hostlist load_modules_local
4165 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
4170 do_facet $facet "sync; sync; sync"
4173 # make sure there will be no seq change
4174 local clients=${CLIENTS:-$HOSTNAME}
4175 local f=fsa-\\\$\(hostname\)
4176 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
4177 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
4179 local svc=${facet}_svc
4180 do_facet $facet $LCTL --device ${!svc} notransno
4182 # If a ZFS OSD is made read-only here, its pool is "freezed". This
4183 # in-memory state has to be cleared by either rebooting the host or
4184 # exporting and reimporting the pool.
4186 # Although the uberblocks are not updated when a pool is freezed,
4187 # transactions are still written to the disks. Modified blocks may be
4188 # cached in memory when tests try reading them back. The
4189 # export-and-reimport process also evicts any cached pool data from
4190 # memory to provide the correct "data loss" semantics.
4192 # In the test framework, the exporting and importing operations are
4193 # handled by stop() and mount_facet() separately, which are used
4194 # inside fail() and fail_abort().
4196 set_dev_readonly $facet
4197 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4198 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4201 replay_barrier_nodf() {
4202 local facet=$1 echo running=${running}
4203 do_facet $facet "sync; sync; sync"
4204 local svc=${facet}_svc
4205 echo Replay barrier on ${!svc}
4206 do_facet $facet $LCTL --device ${!svc} notransno
4207 set_dev_readonly $facet
4208 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4209 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4212 replay_barrier_nosync() {
4213 local facet=$1 echo running=${running}
4214 local svc=${facet}_svc
4215 echo Replay barrier on ${!svc}
4216 do_facet $facet $LCTL --device ${!svc} notransno
4217 set_dev_readonly $facet
4218 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4219 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4223 # Get Lustre client uuid for a given Lustre mount point.
4226 local mntpnt=${1:-$MOUNT}
4228 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
4229 local uuid=$($LCTL get_param -n llite.$name.uuid)
4234 mds_evict_client() {
4235 local mntpnt=${1:-$MOUNT}
4236 local uuid=$(get_client_uuid $mntpnt)
4238 do_facet $SINGLEMDS \
4239 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
4242 ost_evict_client() {
4243 local mntpnt=${1:-$MOUNT}
4244 local uuid=$(get_client_uuid $mntpnt)
4247 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
4252 local clients=${CLIENTS:-$HOSTNAME}
4254 SK_NO_KEY_save=$SK_NO_KEY
4256 export SK_NO_KEY=false
4258 facet_failover $* || error "failover: $?"
4259 export SK_NO_KEY=$SK_NO_KEY_save
4260 # to initiate all OSC idling connections
4262 wait_clients_import_ready "$clients" "$facets"
4263 clients_up || error "post-failover stat: $?"
4269 facet_failover $facet
4274 local abort_type=${2:-"abort_recovery"}
4277 change_active $facet
4278 wait_for_facet $facet
4279 mount_facet $facet -o $abort_type
4280 clients_up || echo "first stat failed: $?"
4281 clients_up || error "post-failover stat: $?"
4285 # LU-16159: abort recovery will cancel update logs, which may leave broken
4286 # directories in the system, remove name entry if necessary
4287 fail_abort_cleanup() {
4289 find $DIR/$tdir -depth | while read D; do
4290 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
4294 host_nids_address() {
4298 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
4302 if [ "$1" = "'*'" ]; then echo \'*\'; else
4308 if [[ -n "$NETTYPE" ]]; then
4309 h2name_or_ip "$1" "$NETTYPE"
4311 h2name_or_ip "$1" "$2"
4314 declare -fx h2nettype
4316 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4317 # expressions format. As a bonus we can then just pass in those variables
4318 # to pdsh. What this function does is take a HOSTLIST type string and
4319 # expand it into a space deliminated list for us.
4327 [ -z "$hostlist" ] && return
4329 # Translate the case of [..],..,[..] to [..] .. [..]
4330 list="${hostlist/],/] }"
4332 [[ "$front" == *,* ]] && {
4335 list=${list/${old}/${new}}
4338 for item in $list; do
4339 # Test if we have any []'s at all
4340 if [ "$item" != "${item/\[/}" ]; then {
4341 # Expand the [*] into list
4345 if [ "$name" != "$item" ]; then
4346 group=${item#$name[*}
4349 for range in ${group//,/ }; do
4355 # Number of leading zeros
4358 end=$(echo $end | sed 's/0*//')
4359 [[ -z "$end" ]] && end=0
4360 [[ $padlen2 -gt $padlen ]] && {
4361 [[ $padlen2 -eq ${#end} ]] &&
4365 begin=$(echo $begin | sed 's/0*//')
4366 [ -z $begin ] && begin=0
4368 if [ ! -z "${begin##[!0-9]*}" ]; then
4369 order=$(seq -f "%0${padlen}g" $begin $end)
4371 order=$(eval echo {$begin..$end});
4374 for num in $order; do
4375 value="${name#*,}${num}${back}"
4377 [ "$value" != "${value/\[/}" ] && {
4378 value=$(hostlist_expand "$value")
4380 myList="$myList $value"
4385 myList="$myList $item"
4388 myList=${myList//,/ }
4389 myList=${myList:1} # Remove first character which is a space
4391 # Filter any duplicates without sorting
4393 myList="${list%% *}"
4395 while [[ "$list" != ${myList##* } ]]; do
4396 local tlist=" $list"
4398 list=${tlist// ${list%% *} / }
4400 myList="$myList ${list%% *}"
4402 myList="${myList%* }";
4404 # We can select an object at an offset in the list
4407 for item in $myList; do
4409 [ $cnt -eq $offset ] && {
4413 [ $(get_node_count $myList) -ne 1 ] && myList=""
4422 [ "$facet" == client ] && echo -n $HOSTNAME && return
4423 varname=${facet}_HOST
4424 if [ -z "${!varname}" ]; then
4425 if [ "${facet:0:3}" == "ost" ]; then
4426 local fh=${facet%failover}_HOST
4427 eval export ${facet}_HOST=${!fh}
4428 if [ -z "${!varname}" ]; then
4429 eval export ${facet}_HOST=${ost_HOST}
4431 elif [ "${facet:0:3}" == "mdt" -o \
4432 "${facet:0:3}" == "mds" -o \
4433 "${facet:0:3}" == "mgs" ]; then
4435 if [ "${facet}" == "mgsfailover" ] &&
4436 [ -n "$mds1failover_HOST" ]; then
4437 temp=$mds1failover_HOST
4441 eval export ${facet}_HOST=$temp
4447 facet_failover_host() {
4451 var=${facet}failover_HOST
4452 if [ -n "${!var}" ]; then
4457 if combined_mgs_mds && [ $facet == "mgs" ] &&
4458 [ -n "$mds1failover_HOST" ]; then
4459 echo $mds1failover_HOST
4463 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4464 "${facet:0:3}" == "mgs" ]; then
4466 eval export ${facet}failover_host=${mds_HOST}
4471 if [[ $facet == ost* ]]; then
4472 eval export ${facet}failover_host=${ost_HOST}
4480 local activevar=${facet}active
4482 if [ -f $TMP/${facet}active ] ; then
4483 source $TMP/${facet}active
4486 active=${!activevar}
4487 if [ -z "$active" ] ; then
4494 facet_active_host() {
4495 facet_host $(facet_active $1)
4498 # Get the passive failover partner host of facet.
4499 facet_passive_host() {
4501 [[ $facet = client ]] && return
4503 local host=${facet}_HOST
4504 local failover_host=${facet}failover_HOST
4505 local active_host=$(facet_active_host $facet)
4507 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4509 if [[ $active_host = ${!host} ]]; then
4510 echo -n ${!failover_host}
4520 for facet in ${facetlist//,/ }; do
4521 local failover=${facet}failover
4522 local host=`facet_host $failover`
4524 [ -z "$host" ] && return
4526 local curactive=`facet_active $facet`
4528 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4529 eval export ${facet}active=$facet
4531 eval export ${facet}active=$failover
4533 # save the active host for this facet
4534 local activevar=${facet}active
4536 echo "$activevar=${!activevar}" > $TMP/$activevar
4537 [[ $facet = mds1 ]] && combined_mgs_mds && \
4538 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4539 local TO=`facet_active_host $facet`
4540 echo "Failover $facet to $TO"
4548 # do not strip off hostname if verbose, b=19215
4549 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4550 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4556 if [ "$HOST" = "$HOSTNAME" ]; then
4558 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4559 echo "cannot run remote command on $HOST with $myPDSH"
4562 if $VERBOSE && [[ -z "$quiet" ]]; then
4563 echo "CMD: $HOST $*" >&2
4564 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4567 if [[ "$myPDSH" == "rsh" ]] ||
4568 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4569 # we need this because rsh and pdsh do not return
4570 # exit code of an executed command
4571 local command_status="$TMP/cs"
4572 eval $myPDSH $HOST ":> $command_status"
4573 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4574 PATH=\$PATH:/sbin:/usr/sbin;
4576 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4577 echo command failed >$command_status"
4578 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4582 if [[ -n "$verbose" ]]; then
4583 # print HOSTNAME for myPDSH="no_dsh"
4584 if [[ $myPDSH = no_dsh ]]; then
4586 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4587 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4588 sed -e "s/^/${HOSTNAME}: /"
4591 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4592 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4596 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4597 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4598 sed "s/^${HOST}: //"
4600 return ${PIPESTATUS[0]}
4604 # Execute exact command line on host
4606 # The \a host may be on a local or remote node, which is determined at
4607 # the time the command is run. Does careful argument quotation to
4608 # ensure that the exact command line is executed without any globbing,
4609 # substitution, or shell interpretation on the remote side. Does not
4610 # support --verbose or --quiet. Does not include "$host: " prefixes on
4611 # output. See also do_facet_vp().
4613 # usage: do_node_vp "$host" "$command" "$arg"...
4618 if [[ "$host" == "$HOSTNAME" ]]; then
4619 bash -c "$(printf -- ' %q' "$@")"
4623 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4624 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4628 # -N Disable hostname: prefix on lines of output.
4630 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4633 single_local_node () {
4634 [ "$1" = "$HOSTNAME" ]
4637 # Outputs environment variable assignments that should be passed to remote nodes
4641 local facets=$(get_facets)
4644 for var in ${!MODOPTS_*}; do
4645 value=${!var//\"/\\\"}
4646 echo -n " ${var}=\"$value\""
4649 for facet in ${facets//,/ }; do
4651 if [ -n "${!var}" ]; then
4652 echo -n " $var=${!var}"
4656 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4657 if [ -n "${!var}" ]; then
4658 echo -n " $var=${!var}"
4662 for var in VERBOSE; do
4663 if [ -n "${!var}" ]; then
4664 echo -n " $var=${!var}"
4668 if [ -n "$FSTYPE" ]; then
4669 echo -n " FSTYPE=$FSTYPE"
4672 for var in LNETLND NETTYPE; do
4673 if [ -n "${!var}" ]; then
4674 echo -n " $var=${!var}"
4683 # do not strip off hostname if verbose, b=19215
4684 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4685 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4690 if single_local_node $rnodes; then
4691 do_node $verbose $quiet $rnodes "$@"
4695 # This is part from do_node
4698 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4699 echo "cannot run remote command on $rnodes with $myPDSH" &&
4702 export FANOUT=$(get_node_count "${rnodes//,/ }")
4703 if $VERBOSE && [[ -z "$quiet" ]]; then
4704 echo "CMD: $rnodes $*" >&2
4705 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4708 # do not replace anything from pdsh output if -N is used
4709 # -N Disable hostname: prefix on lines of output.
4710 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4711 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4713 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4715 return ${PIPESTATUS[0]}
4719 # Execute commands on a single service's host
4721 # The \a facet (service) may be on a local or remote node, which is
4722 # determined at the time the command is run.
4724 # usage: do_facet $facet command [arg ...]
4729 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4730 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4734 local host=$(facet_active_host $facet)
4736 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4737 do_node $verbose $quiet $host "$@"
4741 # Execute exact command line on the host of a facet
4743 # The \a facet (service) may be on a local or remote node, which is
4744 # determined at the time the command is run. Does careful argument
4745 # quotation to ensure that the exact command line is executed without
4746 # any globbing, substitution, or shell interpretation on the remote
4747 # side. Does not support --verbose or --quiet. Does not include
4748 # "$host: " prefixes on output.
4750 # usage: do_facet_vp "$facet" "$command" "$arg"...
4753 local host=$(facet_active_host "$facet")
4756 if [[ -z "$host" ]]; then
4757 echo "no host defined for facet ${facet}" >&2
4761 do_node_vp "$host" "$@"
4764 # Function: do_facet_random_file $FACET $FILE $SIZE
4765 # Creates FILE with random content on the given FACET of given SIZE
4767 do_facet_random_file() {
4771 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4772 do_facet $facet "$cmd 2>/dev/null"
4775 do_facet_create_file() {
4779 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4780 do_facet $facet "$cmd 2>/dev/null"
4784 do_nodes --verbose "$@"
4790 # make sure its not already running
4792 rm -f $TMP/${facet}active
4793 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4795 # make sure in-tree ldiskfs is loaded before mkfs
4796 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4797 load_module ../ldiskfs/ldiskfs
4800 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4802 if [[ $(facet_fstype $facet) == zfs ]]; then
4804 # After formatting a ZFS target, "cachefile=none" property will
4805 # be set on the ZFS storage pool so that the pool is not
4806 # automatically imported on system startup. And then the pool
4807 # will be exported so as to leave the importing and exporting
4808 # operations handled by mount_facet() and stop() separately.
4810 refresh_partition_table $facet $(facet_vdevice $facet)
4811 disable_zpool_cache $facet
4816 # Device formatted as ost
4819 local DEVNAME=OSTDEV$num
4821 local fstype=$(facet_fstype ost$num)
4825 local dev=ost${num}_dev
4826 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4827 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4828 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4830 #try $OSTZFSDEVn - independent of vdev
4831 DEVNAME=OSTZFSDEV$num
4832 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4834 error "unknown fstype!";;
4840 # Physical device location of data
4846 local fstype=$(facet_fstype ost$num)
4850 # vdevs are not supported by ldiskfs
4853 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4854 # Device formatted by zfs
4856 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4858 error "unknown fstype!";;
4864 # Logical device formatted for lustre
4867 local DEVNAME=MDSDEV$num
4869 local fstype=$(facet_fstype mds$num)
4873 local dev=mds${num}_dev
4874 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4875 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4876 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4878 # try $MDSZFSDEVn - independent of vdev
4879 DEVNAME=MDSZFSDEV$num
4880 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4882 error "unknown fstype!";;
4888 # Physical location of data
4892 local fstype=$(facet_fstype mds$num)
4896 # vdevs are not supported by ldiskfs
4899 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4900 # Device formatted by ZFS
4901 local DEVNAME=MDSDEV$num
4902 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4904 error "unknown fstype!";;
4912 local fstype=$(facet_fstype mgs)
4916 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4917 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4918 DEVPTR=$(mdsdevname 1)
4920 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4924 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4925 ( [ -z "$MGSZFSDEV" ] &&
4926 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4927 DEVPTR=$(mdsdevname 1)
4929 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4932 error "unknown fstype!";;
4941 local fstype=$(facet_fstype mgs)
4945 # vdevs are not supported by ldiskfs
4948 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4949 ( [ -z "$MGSDEV" ] &&
4950 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4951 VDEVPTR=$(mdsvdevname 1)
4952 elif [ -n "$MGSDEV" ]; then
4956 error "unknown fstype!";;
4964 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4966 local var=${facet}_MOUNT
4967 eval mntpt=${!var:-${MOUNT}-$facet}
4974 local dev=$(facet_device $facet)
4975 local mnt=${2:-$(facet_mntpt $facet)}
4979 if dm_flakey_supported $facet; then
4980 dm_dev=$(dm_create_dev $facet $dev)
4981 [[ -n "$dm_dev" ]] || dm_dev=$dev
4983 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4984 export_dm_dev $facet $dm_dev
4986 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4991 local dev=$(facet_device $facet)
4992 local mnt=${2:-$(facet_mntpt $facet)}
4994 do_facet $facet $UMOUNT $mnt
4998 echo -n "$1" | tr -c '[:alnum:]\n' '_'
5003 local ds=$(facet_device $facet)
5004 local mnt=${2:-$(facet_mntpt $facet)}
5009 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
5010 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
5011 do_facet $facet $ZFS set canmount=noauto $ds
5013 # The "legacy" mount method is used here because "zfs unmount $mnt"
5014 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
5015 # targets are not available at the time, the stat(2) on $MOUNT will
5018 do_facet $facet $ZFS set mountpoint=legacy $ds
5019 do_facet $facet mount -t zfs $ds $mnt
5020 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
5021 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
5026 local ds=$(facet_device $facet)
5027 local mnt=${2:-$(facet_mntpt $facet)}
5028 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
5029 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
5030 local mntpt=${!var_mntpt}
5031 local canmnt=${!var_canmnt}
5035 do_facet $facet umount $mnt
5036 do_facet $facet $ZFS set mountpoint=$mntpt $ds
5037 do_facet $facet $ZFS set canmount=$canmnt $ds
5044 local fstype=$(facet_fstype $facet)
5046 mount_$fstype $facet $mnt
5052 local fstype=$(facet_fstype $facet)
5054 unmount_$fstype $facet $mnt
5061 # make sure we are using the primary server, so test-framework will
5062 # be able to clean up properly.
5063 activemds=`facet_active mds1`
5064 if [ $activemds != "mds1" ]; then
5068 local clients=$CLIENTS
5069 [ -z $clients ] && clients=$(hostname)
5071 zconf_umount_clients $clients $MOUNT "$*" || true
5072 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
5074 [ -n "$CLIENTONLY" ] && return
5076 # The add fn does rm ${facet}active file, this would be enough
5077 # if we use do_facet <facet> only after the facet added, but
5078 # currently we use do_facet mds in local.sh
5080 for num in `seq $MDSCOUNT`; do
5082 rm -f ${TMP}/mds${num}active
5084 combined_mgs_mds && rm -f $TMP/mgsactive
5086 for num in `seq $OSTCOUNT`; do
5088 rm -f $TMP/ost${num}active
5091 if ! combined_mgs_mds ; then
5095 if $SHARED_KEY; then
5096 export SK_MOUNTED=false
5102 cleanup_echo_devs () {
5105 local devs=$($LCTL dl | grep echo | awk '{print $4}')
5107 for dev in $devs; do
5108 $LCTL --device $dev cleanup
5109 $LCTL --device $dev detach
5114 nfs_client_mode && return
5115 cifs_client_mode && return
5118 CLEANUP_DM_DEV=true stopall $*
5125 combined_mgs_mds () {
5126 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
5127 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
5131 echo -n "$1" | tr '[:upper:]' '[:lower:]'
5135 echo -n "$1" | tr '[:lower:]' '[:upper:]'
5147 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
5148 for i in $(echo "$var"); do
5149 if [ "$i" == "-O" ]; then
5151 first_o=$(($first_o + 1))
5154 if [ "$i" == "-E" ]; then
5156 first_e=$(($first_e + 1 ))
5161 [ $first_o -gt 1 ] && opt_o+=",";
5165 [ $first_e -gt 1 ] && opt_e+=",";
5176 [ -n "$opt_o" ] && echo " -O $opt_o"
5177 [ -n "$opt_e" ] && echo " -E $opt_e"
5183 local fsname=${3:-"$FSNAME"}
5184 local type=$(facet_type $facet)
5185 local index=$(facet_index $facet)
5186 local fstype=$(facet_fstype $facet)
5187 local host=$(facet_host $facet)
5191 local varbs=${facet}_BLOCKSIZE
5193 if [ $type == MGS ] || ( [ $type == MDS ] &&
5194 [ "$dev" == $(mgsdevname) ] &&
5195 [ "$host" == "$(facet_host mgs)" ] ); then
5198 opts="--mgsnode=$MGSNID"
5201 if [ $type != MGS ]; then
5202 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
5206 var=${facet}failover_HOST
5207 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
5208 opts+=" --failnode=$(h2nettype ${!var})"
5211 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
5212 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
5214 if [ $type == MDS ]; then
5215 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
5216 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
5217 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
5219 if [ $fstype == ldiskfs ]; then
5221 if [ -n "${!var}" ]; then
5222 fs_mkfs_opts+=" -J device=${!var}"
5224 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
5226 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
5230 if [ $type == OST ]; then
5231 if [ $fstype == ldiskfs ]; then
5233 if [ -n "${!var}" ]; then
5234 fs_mkfs_opts+=" -J device=${!var}"
5236 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
5241 opts+=" --backfstype=$fstype"
5244 if [ -n "${!var}" ]; then
5245 opts+=" --device-size=${!var}"
5248 var=$(upper $fstype)_MKFS_OPTS
5249 fs_mkfs_opts+=${!var:+" ${!var}"}
5251 var=${type}_FS_MKFS_OPTS
5252 fs_mkfs_opts+=${!var:+" ${!var}"}
5254 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
5256 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
5257 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
5259 if [ -n "${fs_mkfs_opts## }" ]; then
5260 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
5264 opts+=${!var:+" ${!var}"}
5271 local type=$(facet_type $facet)
5272 local var=${type}_MOUNT_FS_OPTS
5274 if [ -n "${!var}" ]; then
5275 opts+=" --mountfsoptions=${!var}"
5280 check_ost_indices() {
5281 local index_count=${#OST_INDICES[@]}
5282 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
5284 # OST count is greater than the index count in $OST_INDEX_LIST.
5285 # We need check whether there are duplicate indices.
5289 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
5290 index=$(facet_index ost$i)
5291 for j in $(seq 0 $((index_count - 1))); do
5292 [[ $index -ne ${OST_INDICES[j]} ]] ||
5293 error "ost$i has the same index $index as ost$((j+1))"
5300 local facet_type=$1 # mgs || mds || ost
5302 local facet=${1}${2}
5305 case "$(facet_fstype $facet)" in
5307 device=$(${facet_type}devname $facet_num)
5310 device=$(${facet_type}vdevname $facet_num)
5313 error "Unhandled filesystem type"
5317 do_facet $facet "[ -e \"$device\" ]" && return
5319 # Note: the following check only works with absolute paths
5320 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5321 error "$facet: device '$device' does not exist"
5323 # zpool create doesn't like empty files
5324 [[ $(facet_fstype $facet) == zfs ]] && return 0
5326 do_facet $facet "touch \"${device}\""
5335 echo "Format mgs: $(mgsdevname)"
5336 reformat_external_journal mgs
5338 # touch "device" in case it is a loopback file for testing and needs to
5339 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5340 # to non-existent files in /dev if the admin made a typo during setup
5343 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5344 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5354 echo "Format mds$num: $(mdsdevname $num)"
5355 reformat_external_journal mds$num
5357 __touch_device mds $num
5359 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5360 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5361 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5370 echo "Format ost$num: $(ostdevname $num)"
5371 reformat_external_journal ost$num
5373 __touch_device ost $num
5375 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5376 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5377 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5382 # Set hostid for ZFS/SPL zpool import protection
5383 # (Assumes MDS version is also OSS version)
5384 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5386 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5389 # We need ldiskfs here, may as well load them all
5391 [ -n "$CLIENTONLY" ] && return
5392 echo Formatting mgs, mds, osts
5393 if ! combined_mgs_mds ; then
5397 for num in $(seq $MDSCOUNT); do
5401 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5403 for num in $(seq $OSTCOUNT); do
5409 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5413 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5416 # usage: switch_identity MDSNUM ENABLE_UPCALL
5419 # 0: success, the identity upcall was previously enabled already.
5420 # 1: success, the identity upcall was previously disabled.
5426 local MDT="$(mdtname_from_index $((num - 1)) $MOUNT)"
5427 local upcall="$L_GETIDENTITY"
5429 [[ -n "$MDT" ]] || return 2
5431 local param="mdt.$MDT.identity_upcall"
5432 local old="$(do_facet $facet "lctl get_param -n $param")"
5434 [[ "$enable" == "true" ]] || upcall="NONE"
5436 do_facet $facet "lctl set_param -n $param='$upcall'" || return 2
5437 do_facet $facet "lctl set_param -n mdt.$MDT.identity_flush=-1"
5439 [[ "$old" != "NONE" ]] # implicit "&& return 0 || return 1"
5444 zconf_umount $HOSTNAME $1 || error "umount failed"
5445 zconf_mount $HOSTNAME $1 || error "mount failed"
5453 rm -f $TMP/${facet}active
5454 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5459 local mdt_count=${1:-$MDSCOUNT}
5460 local ost_count=${2:-$OSTCOUNT}
5463 for num in $(seq $mdt_count); do
5464 DEVNAME=$(mdsdevname $num)
5465 writeconf_facet mds$num $DEVNAME || rc=$?
5468 for num in $(seq $ost_count); do
5469 DEVNAME=$(ostdevname $num)
5470 writeconf_facet ost$num $DEVNAME || rc=$?
5476 if ! combined_mgs_mds ; then
5477 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5486 for num in $(seq $MDSCOUNT); do
5487 devname=$(mdsdevname $num)
5488 start mds$num $devname $MDS_MOUNT_OPTS
5490 # We started mds$num, now we should set mds${num}_HOST
5491 # and mds${num}failover_HOST variables properly if they
5493 host=$(facet_host mds$num)
5494 for varname in mds${num}_HOST mds${num}failover_HOST; do
5495 if [[ -z "${!varname}" ]]; then
5499 if [[ "$IDENTITY_UPCALL" != "default" ]]; then
5500 switch_identity $num $IDENTITY_UPCALL
5508 for num in $(seq $OSTCOUNT); do
5510 rm -f $TMP/ost${num}active
5519 for num in $(seq $OSTCOUNT); do
5520 devname=$(ostdevname $num)
5521 start ost$num $devname $OST_MOUNT_OPTS
5523 # We started ost$num, now we should set ost${num}_HOST
5524 # and ost${num}failover_HOST variables properly if they
5526 host=$(facet_host ost$num)
5527 for varname in ost${num}_HOST ost${num}failover_HOST; do
5528 if [[ -z "${!varname}" ]]; then
5536 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5537 if [ ! -z $arg1 ]; then
5538 [ "$arg1" = "server_only" ] && return
5541 if [ -n "$CLIENTS" ]; then
5542 zconf_mount_clients $CLIENTS $MOUNT
5546 if [ "$MOUNT_2" ]; then
5547 mount_client $MOUNT2
5548 if [ -n "$CLIENTS" ]; then
5549 zconf_mount_clients $CLIENTS $MOUNT2
5554 sk_nodemap_setup() {
5555 local sk_map_name=${1:-$SK_S2SNM}
5556 local sk_map_nodes=${2:-$HOSTNAME}
5557 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5558 for servernode in $sk_map_nodes; do
5559 local nids=$(do_nodes $servernode "$LCTL list_nids")
5560 for nid in $nids; do
5561 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5562 $sk_map_name --range $nid"
5570 nfs_client_mode && return
5571 cifs_client_mode && return
5573 sanity_mount_check || error "environments are insane!"
5579 if [ -z "$CLIENTONLY" ]; then
5580 echo Setup mgs, mdt, osts
5581 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5583 if $SK_MOUNTED; then
5584 echo "Shared Key file system already mounted"
5589 if $SHARED_KEY; then
5590 export SK_MOUNTED=true
5594 echo "GSS_SK: setting kernel keyring perms"
5595 do_nodes $(comma_list $(all_nodes)) \
5596 "keyctl show | grep lustre | cut -c1-11 |
5598 xargs -IX keyctl setperm X 0x3f3f3f3f"
5601 # Need to start one nodemap for servers,
5602 # and one for clients.
5603 sk_nodemap_setup $SK_S2SNM \
5604 $(comma_list $(all_server_nodes))
5606 sk_nodemap_setup $SK_S2SNMCLI \
5607 ${CLIENTS:-$HOSTNAME}
5608 echo "Nodemap set up for SK S2S, remounting."
5617 # wait a while to allow sptlrpc configuration be propogated to targets,
5618 # only needed when mounting new target devices.
5626 # by remounting mdt before ost, initial connect from mdt to ost might
5627 # timeout because ost is not ready yet. wait some time to its fully
5628 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5629 # preceeded by a context negotiation rpc with $TIMEOUT.
5630 # FIXME better by monitoring import status.
5633 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5634 set_rule $FSNAME any cli2ost $SK_FLAVOR
5635 if $SK_SKIPFIRST; then
5636 export SK_SKIPFIRST=false
5640 "lctl set_param osc.*.idle_connect=1"
5643 wait_flavor cli2mdt $SK_FLAVOR
5644 wait_flavor cli2ost $SK_FLAVOR
5649 sleep $((TIMEOUT + 5))
5655 mounted_lustre_filesystems() {
5656 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5659 init_facet_vars () {
5660 [ -n "$CLIENTONLY" ] && return 0
5667 eval export ${facet}_dev=${device}
5668 eval export ${facet}_opt=\"$*\"
5670 local dev=${facet}_dev
5672 # We need to loop for the label
5673 # in case its not initialized yet.
5674 for wait_time in {0,1,3,5,10}; do
5676 if [ $wait_time -gt 0 ]; then
5677 echo "${!dev} not yet initialized,"\
5678 "waiting ${wait_time} seconds."
5682 local label=$(devicelabel ${facet} ${!dev})
5684 # Check to make sure the label does
5685 # not include ffff at the end of the label.
5686 # This indicates it has not been initialized yet.
5688 if [[ $label =~ [f|F]{4}$ ]]; then
5689 # label is not initialized, unset the result
5690 # and either try again or fail
5697 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5699 eval export ${facet}_svc=${label}
5701 local varname=${facet}failover_HOST
5702 if [ -z "${!varname}" ]; then
5704 if combined_mgs_mds && [ $facet == "mgs" ] &&
5705 [ -n "$mds1failover_HOST" ]; then
5706 temp=$mds1failover_HOST
5708 temp=$(facet_host $facet)
5710 eval export $varname=$temp
5713 varname=${facet}_HOST
5714 if [ -z "${!varname}" ]; then
5715 eval export $varname=$(facet_host $facet)
5718 # ${facet}failover_dev is set in cfg file
5719 varname=${facet}failover_dev
5720 if [ -n "${!varname}" ] ; then
5721 eval export ${facet}failover_dev=${!varname}
5723 eval export ${facet}failover_dev=$device
5726 # get mount point of already mounted device
5727 # is facet_dev is already mounted then use the real
5728 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5729 # i.e. ${facet}_MOUNT if specified by user or default
5730 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5731 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5732 if [ -z $mntpt ]; then
5733 mntpt=$(facet_mntpt $facet)
5735 eval export ${facet}_MOUNT=$mntpt
5738 init_facets_vars () {
5741 if ! remote_mds_nodsh; then
5742 for num in $(seq $MDSCOUNT); do
5743 DEVNAME=$(mdsdevname $num)
5744 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5748 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5750 if ! remote_ost_nodsh; then
5751 for num in $(seq $OSTCOUNT); do
5752 DEVNAME=$(ostdevname $num)
5753 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5758 init_facets_vars_simple () {
5761 if ! remote_mds_nodsh; then
5762 for num in $(seq $MDSCOUNT); do
5763 devname=$(mdsdevname $num)
5764 eval export mds${num}_dev=${devname}
5765 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5769 if ! combined_mgs_mds ; then
5770 eval export mgs_dev=$(mgsdevname)
5771 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5774 if ! remote_ost_nodsh; then
5775 for num in $(seq $OSTCOUNT); do
5776 devname=$(ostdevname $num)
5777 eval export ost${num}_dev=${devname}
5778 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5783 osc_ensure_active () {
5788 while [ $period -lt $timeout ]; do
5789 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5790 if [ $count -eq 0 ]; then
5794 echo "$count OST inactive, wait $period seconds, and try again"
5796 period=$((period+3))
5799 [ $period -lt $timeout ] ||
5800 log "$count OST are inactive after $timeout seconds, give up"
5803 set_conf_param_and_check() {
5807 local ORIG=$(do_facet $myfacet "$TEST")
5808 if [ $# -gt 3 ]; then
5814 echo "Setting $PARAM from $ORIG to $FINAL"
5815 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5816 error "conf_param $PARAM failed"
5818 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5819 error "check $PARAM failed!"
5822 set_persistent_param() {
5826 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5828 if [ $# -gt 3 ]; then
5835 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5836 echo "Setting $test_param from $orig to $final"
5837 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5838 error "$PERM_CMD $test_param failed"
5840 echo "Setting $param from $orig to $final"
5841 do_facet mgs "$PERM_CMD $param='$final'" ||
5842 error "$PERM_CMD $param failed"
5846 set_persistent_param_and_check() {
5850 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5852 if [ $# -gt 3 ]; then
5859 set_persistent_param $myfacet $test_param $param "$final"
5861 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5862 error "check $param failed!"
5865 init_param_vars () {
5866 TIMEOUT=$(lctl get_param -n timeout)
5867 TIMEOUT=${TIMEOUT:-20}
5869 if [ -n "$arg1" ]; then
5870 [ "$arg1" = "server_only" ] && return
5873 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5875 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5876 log "Using TIMEOUT=$TIMEOUT"
5878 # tune down to speed up testing on (usually) small setups
5879 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5880 do_nodes $(comma_list $(nodes_list)) \
5881 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5883 osc_ensure_active $SINGLEMDS $TIMEOUT
5884 osc_ensure_active client $TIMEOUT
5885 $LCTL set_param osc.*.idle_timeout=debug
5887 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5888 local current_jobid_var=$($LCTL get_param -n jobid_var)
5890 if [ $JOBID_VAR = "existing" ]; then
5891 echo "keeping jobstats as $current_jobid_var"
5892 elif [ $current_jobid_var != $JOBID_VAR ]; then
5893 echo "setting jobstats to $JOBID_VAR"
5895 set_persistent_param_and_check client \
5896 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5899 echo "jobstats not supported by server"
5902 if [ $QUOTA_AUTO -ne 0 ]; then
5903 if [ "$ENABLE_QUOTA" ]; then
5904 echo "enable quota as required"
5905 setup_quota $MOUNT || return 2
5907 echo "disable quota as required"
5908 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5912 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5913 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5917 nfs_client_mode () {
5918 if [ "$NFSCLIENT" ]; then
5919 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5920 local clients=$CLIENTS
5922 [ -z $clients ] && clients=$(hostname)
5924 # FIXME: remove hostname when 19215 fixed
5925 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5926 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5927 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5928 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5929 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5931 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5937 cifs_client_mode () {
5938 [ x$CIFSCLIENT = xyes ] &&
5939 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5942 check_config_client () {
5944 local mounted=$(mount | grep " $mntpt ")
5946 if [ -n "$CLIENTONLY" ]; then
5948 # CLIENTONLY should not depend on *_HOST settings
5949 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5950 # in theory someone could create a new,
5951 # client-only config file that assumed lustre was already
5952 # configured and didn't set the MGSNID. If MGSNID is not set,
5953 # then we should use the mgs nid currently being used
5954 # as the default value. bug 18021
5955 [[ x$MGSNID = x ]] &&
5958 if [[ x$mgc != xMGC$MGSNID ]]; then
5959 if [ "$mgs_HOST" ]; then
5960 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
5961 grep PING | awk '{print $3}' |
5962 sed -e "s/(//g" -e "s/)//g")
5964 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5965 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5971 echo Checking config lustre mounted on $mntpt
5972 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5973 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5977 check_config_clients () {
5978 local clients=${CLIENTS:-$HOSTNAME}
5981 nfs_client_mode && return
5982 cifs_client_mode && return
5984 do_rpc_nodes "$clients" check_config_client $mntpt
5986 sanity_mount_check || error "environments are insane!"
5990 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5991 local cltimeout=$(lctl get_param -n timeout)
5992 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5993 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
6000 [ -z $mntpt ] && return 1
6001 local mounted=$(mounted_lustre_filesystems)
6003 echo $mounted' ' | grep -w -q $mntpt' '
6008 local ostsn=${2:-$OSTCOUNT}
6009 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
6012 echo ostsn=$ostsn npools=$npools
6013 if [[ $ostsn -gt $OSTCOUNT ]]; then
6014 echo "request to use $ostsn OSTs in the pool, \
6015 using max available OSTCOUNT=$OSTCOUNT"
6018 for (( n=0; n < $npools; n++ )); do
6020 if ! $DELETE_OLD_POOLS; then
6021 log "request to not delete old pools: $FSNAME.$p exist?"
6022 if ! check_pool_not_exist $FSNAME.$p; then
6023 echo "Using existing $FSNAME.$p"
6024 $LCTL pool_list $FSNAME.$p
6028 create_pool $FSNAME.$p $KEEP_POOLS ||
6029 error "create_pool $FSNAME.$p failed"
6031 local first=$(( (n * ostsn) % OSTCOUNT ))
6032 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
6033 if [[ $first -le $last ]]; then
6034 pool_add_targets $p $first $last ||
6035 error "pool_add_targets $p $first $last failed"
6037 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
6038 error "pool_add_targets $p $first \
6039 $(( OSTCOUNT - 1 )) failed"
6040 pool_add_targets $p 0 $last ||
6041 error "pool_add_targets $p 0 $last failed"
6046 set_pools_quota () {
6053 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
6054 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
6056 # POOLS_QUOTA_USERS_SET=
6057 # "quota15_1:20M -- for all of the found pools
6058 # quota15_2:1G:gpool0
6059 # quota15_3 -- for global limit only
6060 # quota15_4:200M:gpool0
6061 # quota15_4:200M:gpool1"
6063 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
6065 declare -A pq_limits
6067 for ((i=0; i<${#pq_userset[@]}; i++)); do
6068 u=${pq_userset[i]%%:*}
6070 # user gets no pool limits if
6071 # POOLS_QUOTA_USERS_SET does not specify it
6072 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
6073 pq_limits[$u]+=" $o"
6075 pq_users=(${!pq_limits[@]})
6080 for ((i=0; i<${#pq_users[@]}; i++)); do
6082 # set to max limit (_u64)
6083 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
6084 opts=(${pq_limits[$u]})
6085 for ((j=0; j<${#opts[@]}; j++)); do
6088 # Set limit for all existing pools if
6090 if [ $p == $o ]; then
6091 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
6092 echo "No pool specified for $u,
6093 set limit $o for all existing pools"
6096 $LFS setquota -u $u -B $o --pool $pool $DIR ||
6097 error "setquota -u $u -B $o \
6098 --pool $pool failed"
6101 $LFS quota -uv $u --pool $DIR
6105 do_check_and_setup_lustre() {
6106 # If auster does not want us to setup, then don't.
6107 ! ${do_setup} && return
6109 echo "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
6112 nfs_client_mode && return
6113 cifs_client_mode && return
6115 local MOUNTED=$(mounted_lustre_filesystems)
6119 # both MOUNT and MOUNT2 are not mounted
6120 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6121 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
6122 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
6124 is_mounted $MOUNT || error "NAME=$NAME not mounted"
6125 export I_MOUNTED=yes
6129 elif is_mounted $MOUNT2; then
6131 # MOUNT2 is mounted, while MOUNT_2 is not set
6132 if ! [ "$MOUNT_2" ]; then
6133 cleanup_mount $MOUNT2
6134 export I_UMOUNTED2=yes
6137 # MOUNT2 is mounted, MOUNT_2 is set
6139 # FIXME: what to do if check_config failed?
6141 # 1) remote client has mounted other Lustre fs ?
6142 # 2) it has insane env ?
6143 # try to umount MOUNT2 on all clients and mount again:
6144 if ! check_config_clients $MOUNT2; then
6145 cleanup_mount $MOUNT2
6146 restore_mount $MOUNT2
6147 export I_MOUNTED2=yes
6151 # MOUNT is mounted MOUNT2 is not mounted
6152 elif [ "$MOUNT_2" ]; then
6153 restore_mount $MOUNT2
6154 export I_MOUNTED2=yes
6158 # FIXME: what to do if check_config failed?
6160 # 1) remote client has mounted other Lustre fs?
6161 # 2) lustre is mounted on remote_clients atall ?
6162 check_config_clients $MOUNT
6166 set_default_debug_nodes $(comma_list $(nodes_list))
6170 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
6172 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
6173 facets="$(get_facets OST)"
6174 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
6175 facets="$facets,$(get_facets MDS)"
6176 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
6177 facets="$facets,mgs"
6178 local nodes="$(facets_hosts ${facets})"
6179 if [ -n "$nodes" ] ; then
6180 do_nodes $nodes "$LCTL set_param \
6181 osd-ldiskfs.track_declares_assert=1 || true"
6185 if [ -n "$fs_STRIPEPARAMS" ]; then
6186 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
6195 if $DELETE_OLD_POOLS; then
6199 if [[ -n "$FS_POOL" ]]; then
6200 create_pools $FS_POOL $FS_POOL_NOSTS
6203 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
6207 # set tunable parameters passed to test environment
6211 echo "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
6213 if [[ "$ONLY" == "setup" ]]; then
6218 check_and_setup_lustre() {
6219 local start_stamp=$(date +%s)
6220 local saved_umask=$(umask)
6221 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
6230 log_sub_test_begin test_setup
6232 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
6233 error=$(tail -1 $log)
6238 stop_stamp=$(date +%s)
6239 duration=$((stop_stamp - start_stamp))
6241 log_sub_test_end "$status" "$duration" "$rc" "$error"
6249 local clients=${CLIENTS:-$HOSTNAME}
6252 zconf_mount_clients $clients $mntpt
6256 local clients=${CLIENTS:-$HOSTNAME}
6259 zconf_umount_clients $clients $mntpt
6262 cleanup_and_setup_lustre() {
6263 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
6264 lctl set_param debug=0 || true
6267 if [[ "$ONLY" == "cleanup" ]]; then
6272 do_check_and_setup_lustre
6275 # Run e2fsck on MDT or OST device.
6280 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
6281 local log=$TMP/e2fsck.log
6284 # turn on pfsck if it is supported
6285 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
6287 do_node $node $cmd 2>&1 | tee $log
6289 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
6291 if [ $MDSCOUNT -gt 1 ]; then
6292 skip_noexit "DNE mode isn't supported!"
6296 error "It's not DNE mode."
6301 [ $rc -le $FSCK_MAX_ERR ] ||
6302 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6308 # Run resize2fs on MDT or OST device.
6317 do_facet $facet "$RESIZE2FS $opts $device $size"
6320 # verify a directory is shared among nodes.
6321 check_shared_dir() {
6323 local list=${2:-$(comma_list $(nodes_list))}
6325 [ -z "$dir" ] && return 1
6326 do_rpc_nodes "$list" check_logdir $dir
6327 check_write_access $dir "$list" || return 1
6332 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
6333 $LCTL set_param printk=+lfsck
6334 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6336 for k in $(seq $MDSCOUNT); do
6337 # wait up to 10+1 minutes for LFSCK to complete
6338 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6339 mdd.$(facet_svc mds${k}).lfsck_layout |
6340 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6341 error "MDS${k} layout isn't the expected 'completed'"
6342 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6343 mdd.$(facet_svc mds${k}).lfsck_namespace |
6344 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6345 error "MDS${k} namespace isn't the expected 'completed'"
6347 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
6348 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
6349 awk '/repaired/ { print $2 }' | calc_sum)
6350 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
6351 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
6352 awk '/repaired/ { print $2 }' | calc_sum)
6353 local repaired=$((rep_mdt + rep_ost))
6354 [ $repaired -eq 0 ] ||
6355 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6358 dump_file_contents() {
6364 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6365 error_noexit false \
6366 "Invalid parameters for dump_file_contents()"
6369 for node in ${nodes}; do
6370 do_node $node "for i in \\\$(find $dir -type f); do
6371 echo ====\\\${i}=======================;
6373 done" >> ${logname}.${node}.log
6377 dump_command_output() {
6383 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6384 error_noexit false \
6385 "Invalid parameters for dump_command_output()"
6389 for node in ${nodes}; do
6390 do_node $node "echo ====${cmd}=======================;
6391 $cmd" >> ${logname}.${node}.log
6398 # dump file contents from /proc/spl in case of zfs test
6399 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6400 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6401 dump_command_output \
6402 "$(osts_nodes)" "zpool events -v" "${logname}"
6405 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6406 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6407 dump_command_output \
6408 "$(mdts_nodes)" "zpool events -v" "${logname}"
6412 do_check_and_cleanup_lustre() {
6413 echo "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6415 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6416 "$TESTSUITE" != "sanity-scrub" ]]; then
6420 if is_mounted $MOUNT; then
6421 if $DO_CLEANUP; then
6422 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6423 error "remove sub-test dirs failed"
6427 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6430 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6431 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6434 if [[ "$I_MOUNTED2" == "yes" ]]; then
6435 cleanup_mount $MOUNT2
6438 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6439 cleanupall -f || error "cleanup failed"
6443 echo "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6446 check_and_cleanup_lustre() {
6447 local start_stamp=$(date +%s)
6448 local saved_umask=$(umask)
6449 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6458 log_sub_test_begin test_cleanup
6460 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6461 error=$(tail -1 $log)
6466 stop_stamp=$(date +%s)
6467 duration=$((stop_stamp - start_stamp))
6469 log_sub_test_end "$status" "$duration" "$rc" "$error"
6479 wait_for_function () {
6482 # suppress fn both stderr and stdout
6483 if [ "$1" = "--quiet" ]; then
6485 quiet=" > /dev/null 2>&1"
6496 eval $fn $quiet && return 0
6498 [ $wait -lt $max ] || return 1
6499 echo waiting $fn, $((max - wait)) secs left ...
6500 wait=$((wait + sleep))
6501 [ $wait -gt $max ] && ((sleep -= wait - max))
6511 [ "$host" = "$HOSTNAME" ] && return 0
6513 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6514 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6524 # Convert a space-delimited list to a comma-delimited list. If the input is
6525 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6527 # echo is used to convert newlines to spaces, since it doesn't
6528 # introduce a trailing space as using "tr '\n' ' '" does
6529 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6535 echo $list | grep -qw $item
6538 # list, excluded are the comma separated lists
6539 exclude_items_from_list () {
6545 for item in ${excluded//,/ }; do
6546 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6548 echo $(comma_list $list)
6551 # list, expand are the comma separated lists
6553 local list=${1//,/ }
6554 local expand=${2//,/ }
6557 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6558 echo $(comma_list $expanded)
6561 testslist_filter () {
6562 local script=$LUSTRE/tests/${TESTSUITE}.sh
6564 [ -f $script ] || return 0
6566 local start_at=$START_AT
6567 local stop_at=$STOP_AT
6569 local var=${TESTSUITE//-/_}_START_AT
6570 [ x"${!var}" != x ] && start_at=${!var}
6571 var=${TESTSUITE//-/_}_STOP_AT
6572 [ x"${!var}" != x ] && stop_at=${!var}
6574 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6575 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6576 /^'${start_at}'$/ {flag = 0}
6577 {if (flag == 1) print $0}
6578 /^'${stop_at}'$/ { flag = 1 }'
6582 (cd `dirname $1`; echo $PWD/`basename $1`)
6586 local types=${1:-"OST MDS MGS"}
6590 for entry in $types; do
6591 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6592 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6595 MGS ) list="$list $name";;
6596 MDS|OST|AGT ) local count=${type}COUNT
6597 for ((i=1; i<=${!count}; i++)) do
6598 list="$list ${name}$i"
6600 * ) error "Invalid facet type"
6604 echo $(comma_list $list)
6607 ##################################
6608 # Adaptive Timeouts funcs
6611 # only check mds, we assume at_max is the same on all nodes
6612 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6614 if [ $at_max -eq 0 ]; then
6625 # suppose that all ost-s have the same $at value set
6626 [ $facet != "ost" ] || facet=ost1
6628 do_facet $facet "lctl get_param -n $at"
6642 for facet in "$@"; do
6643 if [ $facet == "ost" ]; then
6644 facet=$(get_facets OST)
6645 elif [ $facet == "mds" ]; then
6646 facet=$(get_facets MDS)
6648 hosts=$(expand_list $hosts $(facets_hosts $facet))
6651 do_nodes $hosts lctl set_param at_max=$at_max
6665 for facet in "$@"; do
6666 if [ $facet == "ost" ]; then
6667 facet=$(get_facets OST)
6668 elif [ $facet == "mds" ]; then
6669 facet=$(get_facets MDS)
6671 hosts=$(expand_list $hosts $(facets_hosts $facet))
6674 do_nodes $hosts lctl set_param at_min=$at_min
6677 ##################################
6681 # OBD_FAIL_MDS_ALL_REQUEST_NET
6683 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6684 do_facet client "$1" || RC=$?
6685 do_facet $SINGLEMDS lctl set_param fail_loc=0
6690 # OBD_FAIL_MDS_ALL_REPLY_NET
6692 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6694 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6698 drop_reint_reply() {
6699 # OBD_FAIL_MDS_REINT_NET_REP
6701 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6703 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6707 drop_update_reply() {
6708 # OBD_FAIL_OUT_UPDATE_NET_REP
6712 do_facet mds${index} lctl set_param fail_loc=0x1701
6713 do_facet client "$@" || RC=$?
6714 do_facet mds${index} lctl set_param fail_loc=0
6719 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6722 local timeout=${2:-0}
6723 # default is (obd_timeout / 4) if unspecified
6724 echo "timeout is $timeout/$2"
6725 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6726 do_facet client "$1" || RC=$?
6727 do_facet client "sync"
6728 do_facet ost1 lctl set_param fail_loc=0
6732 drop_ldlm_cancel() {
6733 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6735 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6736 do_nodes $list lctl set_param fail_loc=0x304
6738 do_facet client "$@" || RC=$?
6740 do_nodes $list lctl set_param fail_loc=0
6744 drop_bl_callback_once() {
6746 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6747 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6748 do_facet client lctl set_param fail_loc=0x80000305
6749 do_facet client "$@" || rc=$?
6750 do_facet client lctl set_param fail_loc=0
6751 do_facet client lctl set_param fail_val=0
6752 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6756 drop_bl_callback() {
6758 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6759 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6760 do_facet client lctl set_param fail_loc=0x305
6761 do_facet client "$@" || rc=$?
6762 do_facet client lctl set_param fail_loc=0
6763 do_facet client lctl set_param fail_val=0
6764 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6768 drop_mdt_ldlm_reply() {
6769 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6771 local list=$(comma_list $(mdts_nodes))
6773 do_nodes $list lctl set_param fail_loc=0x157
6775 do_facet client "$@" || RC=$?
6777 do_nodes $list lctl set_param fail_loc=0
6781 drop_mdt_ldlm_reply_once() {
6782 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6784 local list=$(comma_list $(mdts_nodes))
6786 do_nodes $list lctl set_param fail_loc=0x80000157
6788 do_facet client "$@" || RC=$?
6790 do_nodes $list lctl set_param fail_loc=0
6798 echo "clearing fail_loc on $facet"
6799 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6802 set_nodes_failloc () {
6804 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6807 # Print the total of the lock_unused_count across all namespaces containing the
6808 # given wildcard. If the namespace wildcard is omitted, all namespaces will be
6810 # Usage: total_unused_locks [namespace_wildcard]
6811 total_unused_locks() {
6812 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_unused_count" | calc_sum
6815 # Print the total of the lock_count across all namespaces containing the given
6816 # wildcard. If the namespace wilcard is omitted, all namespaces will be matched.
6817 # Usage: total_used_locks [namespace_wildcard]
6818 total_used_locks() {
6819 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_count" | calc_sum
6822 # Cancel lru locks across all namespaces containing the given wildcard. If the
6823 # wilcard is omitted, lru locks will be canceled across all namespaces.
6824 # Usage: cancel_lru_locks [namespace_wildcard]
6825 cancel_lru_locks() {
6826 #$LCTL mark "cancel_lru_locks $1 start"
6827 $LCTL set_param -t4 -n "ldlm.namespaces.*$1*.lru_size=clear"
6828 $LCTL get_param "ldlm.namespaces.*$1*.lock_unused_count" | grep -v '=0'
6829 #$LCTL mark "cancel_lru_locks $1 stop"
6834 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6836 echo $((100 * nr_cpu))
6841 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6844 lru_resize_disable()
6847 local lru_size=${2:-$(default_lru_size)}
6849 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6854 local mountpath=${1:-$MOUNT}
6857 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6864 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6865 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6866 echo there is still data in page cache $FILE ?
6867 lctl get_param -n $FILE
6875 DEBUGSAVE="$(lctl get_param -n debug)"
6876 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6880 [ -n "$DEBUGSAVE" ] &&
6881 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6885 [ -n "$DEBUGSAVE_SERVER" ] &&
6886 do_nodes $(comma_list $(all_server_nodes)) \
6887 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6893 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6896 debug_size_restore() {
6897 [ -n "$DEBUG_SIZE_SAVED" ] &&
6898 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6902 start_full_debug_logging() {
6907 local debug_size=150
6908 local nodes=$(comma_list $(nodes_list))
6910 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6913 stop_full_debug_logging() {
6918 # prints bash call stack
6919 print_stack_trace() {
6922 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6923 local src=${BASH_SOURCE[$i]}
6924 local lineno=${BASH_LINENO[$i-1]}
6925 local funcname=${FUNCNAME[$i]}
6926 echo " = $src:$lineno:$funcname()"
6931 local TYPE=${TYPE:-"FAIL"}
6934 # do not dump logs if $1=false
6935 if [ "x$1" = "xfalse" ]; then
6940 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6941 (print_stack_trace 2) >&2
6943 # We need to dump the logs on all nodes
6945 gather_logs $(comma_list $(nodes_list))
6949 [ "$TESTSUITELOG" ] &&
6950 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
6951 if [ -z "$*" ]; then
6952 echo "error() without useful message, please fix" > $LOGDIR/err
6954 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6955 echo "$@" > $LOGDIR/ignore
6957 echo "$@" > $LOGDIR/err
6961 # cleanup the env for failed tests
6965 ##################################
6967 ##################################
6969 # usage: stack_trap arg sigspec
6971 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6972 # command "arg" on top of previously defined commands for "sigspec" instead
6973 # of overwriting them.
6974 # stacked traps are executed in reverse order of their registration
6976 # arg and sigspec have the same meaning as in man (1) trap
6980 local sigspec="${2:-EXIT}"
6982 # Use "trap -p" to get the quoting right
6983 local old_trap="$(trap -p "$sigspec")"
6984 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6985 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6987 # Once again, use "trap -p" to get the quoting right
6988 local new_trap="$(trap -- "$arg" "$sigspec"
6990 trap -- '' "$sigspec")"
6992 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6994 # The resulting string should be safe to "eval" as it is (supposedly
6995 # correctly) quoted by "trap -p"
6996 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
7005 local logs="$TESTSUITELOG $1"
7007 for log in $logs; do
7008 if [ -f "$log" ]; then
7009 grep -qw FAIL $log && status=1
7026 # use only if we are ignoring failures for this test, bugno required.
7027 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
7028 # e.g. error_ignore bz5494 "your message" or
7029 # error_ignore LU-5494 "your message"
7031 local TYPE="IGNORE ($1)"
7036 error_and_remount() {
7038 remount_client $MOUNT
7042 # Throw an error if it's not running in vm - usually for performance
7045 local virt=$(running_in_vm)
7046 if [[ -n "$virt" ]]; then
7047 echo "running in VM '$virt', ignore error"
7048 error_ignore env=$virt "$@"
7055 # Function: skip_env()
7056 # Purpose: to skip a test during developer testing because some tool
7057 # is missing, but fail the test in release testing because the test
7058 # environment is not configured properly".
7061 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
7066 log " SKIP: $TESTSUITE $TESTNAME $*"
7068 if [[ -n "$ALWAYS_SKIPPED" ]]; then
7069 skip_logged $TESTNAME "$@"
7072 echo "$@" > $LOGDIR/skip
7075 [[ -n "$TESTSUITELOG" ]] &&
7076 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
7086 # For interop testing treate EOPNOTSUPP as success
7092 echo $retstr | awk -F'|' '{print $1}' |
7093 grep -E unsupported\|"(Operation not supported)"
7094 (( $? == 0 )) || error "$retstr"
7098 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
7099 # Usage: always_except LU-4815 23 42q ...
7101 function always_except() {
7102 local issue="${1:-}" # single jira style issue ("LU-4815")
7107 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
7108 error "always_except: invalid issue '$issue' for tests '$*'"
7111 for test_num in "$@"; do
7112 ALWAYS_EXCEPT+=" $test_num"
7116 build_test_filter() {
7117 EXCEPT="$EXCEPT $(testslist_filter)"
7119 # allow test numbers separated by '+', or ',', in addition to ' '
7120 # to avoid issues with multiple arguments handling by shell/autotest
7121 for O in ${ONLY//[+,]/ }; do
7122 if [[ $O =~ [0-9]*-[0-9]* ]]; then
7123 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
7131 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
7132 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
7133 [[ -z "$EXCEPT_SLOW" ]] ||
7134 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
7135 for E in ${EXCEPT//[+,]/ }; do
7136 eval EXCEPT_${E}=true
7138 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
7139 eval EXCEPT_ALWAYS_${E}=true
7141 for E in ${EXCEPT_SLOW//[+,]/ }; do
7142 eval EXCEPT_SLOW_${E}=true
7144 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
7145 eval GCHECK_ONLY_${G}=true
7150 if [[ $1 = [a-z]* ]]; then
7153 echo ${1%%[a-zA-Z]*}
7157 # print a newline if the last test was skipped
7158 export LAST_SKIPPED=
7159 export ALWAYS_SKIPPED=
7161 # Main entry into test-framework. This is called with the number and
7162 # description of a test. The number is used to find the function to run
7163 # the test using "test_$name".
7165 # This supports a variety of methods of specifying specific test to
7167 # - ONLY= env variable with space-separated list of test numbers to run
7168 # - EXCEPT= env variable with space-separated list of test numbers to exclude
7174 export base=$(basetest $testnum)
7175 export TESTNAME=test_$testnum
7179 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
7180 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
7181 local isexcept=EXCEPT_$testnum
7182 local isexcept_base=EXCEPT_$base
7183 if [ ${!isexcept}x != x ]; then
7185 skip_message="skipping excluded test $testnum"
7186 elif [ ${!isexcept_base}x != x ]; then
7188 skip_message="skipping excluded test $testnum (base $base)"
7191 isexcept=EXCEPT_ALWAYS_$testnum
7192 isexcept_base=EXCEPT_ALWAYS_$base
7193 if [ ${!isexcept}x != x ]; then
7195 skip_message="skipping ALWAYS excluded test $testnum"
7196 elif [ ${!isexcept_base}x != x ]; then
7198 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
7201 isexcept=EXCEPT_SLOW_$testnum
7202 isexcept_base=EXCEPT_SLOW_$base
7203 if [ ${!isexcept}x != x ]; then
7205 skip_message="skipping SLOW test $testnum"
7206 elif [ ${!isexcept_base}x != x ]; then
7208 skip_message="skipping SLOW test $testnum (base $base)"
7211 # If there are tests on the ONLY list, check if the current test
7212 # is on that list and, if so, check if the test is to be skipped
7213 # and if we are supposed to honor the skip lists.
7214 if [ -n "$ONLY" ]; then
7215 local isonly=ONLY_$testnum
7216 local isonly_base=ONLY_$base
7217 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
7219 if [[ -n "$ALWAYS_SKIPPED" &&
7220 -n "$HONOR_EXCEPT" ]]; then
7222 skip_noexit "$skip_message"
7225 [ -n "$LAST_SKIPPED" ] &&
7226 echo "" && LAST_SKIPPED=
7228 run_one_logged $testnum "$testmsg"
7238 if [ -n "$ALWAYS_SKIPPED" ]; then
7240 skip_noexit "$skip_message"
7243 run_one_logged $testnum "$testmsg"
7250 load_module ../libcfs/libcfs/libcfs
7263 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
7268 strace -o $TMP/$1.strace -ttt $*
7270 log "FINISHED: $*: rc $RC"
7277 banner "test complete, duration $duration sec"
7278 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
7279 echo "duration $duration" >>$TESTSUITELOG
7283 # Set TEST_STATUS here. It will be used for logging the result.
7286 if [[ -f $LOGDIR/err ]]; then
7288 elif [[ -f $LOGDIR/skip ]]; then
7291 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
7295 local FFREE=$(do_node $SINGLEMDS \
7296 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
7297 local FTOTAL=$(do_node $SINGLEMDS \
7298 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
7300 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
7305 #echo -n "Resetting fail_loc on all nodes..."
7306 do_nodes --quiet $(comma_list $(nodes_list)) \
7307 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
7313 # Log a message (on all nodes) padded with "=" before and after.
7314 # Also appends a timestamp and prepends the testsuite name.
7317 # ======================================================== 15:06:12 (1624050372)
7318 EQUALS="========================================================"
7320 msg="== ${TESTSUITE} $*"
7322 [[ $last != "=" && $last != " " ]] && msg="$msg "
7323 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
7324 # always include at least == after the message
7325 log "$msg== $(date +"%H:%M:%S (%s)")"
7328 check_dmesg_for_errors() {
7330 local errors="VFS: Busy inodes after unmount of\|\
7331 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
7332 group descriptors corrupted"
7334 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
7335 [ -z "$res" ] && return 0
7336 echo "Kernel error detected: $res"
7341 # Run a single test function and cleanup after it.
7343 # This function should be run in a subshell so the test func can
7344 # exit() without stopping the whole script.
7349 local SAVE_UMASK=`umask`
7352 if ! grep -q $DIR /proc/mounts; then
7356 banner "test $testnum: $testmsg"
7357 test_${testnum} || error "test_$testnum failed with $?"
7360 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7362 check_dmesg_for_errors || error "Error in dmesg detected"
7363 if [ "$PARALLEL" != "yes" ]; then
7364 ps auxww | grep -v grep | grep -q "multiop " &&
7365 error "multiop still running"
7373 # Wrapper around run_one to ensure:
7374 # - test runs in subshell
7375 # - output of test is saved to separate log file for error reporting
7376 # - test result is saved to data file
7379 local before=$SECONDS
7382 export tfile=f${testnum}.${TESTSUITE}
7383 export tdir=d${testnum}.${TESTSUITE}
7384 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7385 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7386 local SAVE_UMASK=$(umask)
7389 declare -A kptr_restrict
7390 declare -A debug_raw
7393 for node in $(all_nodes); do
7394 kptr_restrict[$node]=$(do_node $node "sysctl --values kernel/kptr_restrict")
7395 do_node $node "sysctl -wq kernel/kptr_restrict=1"
7396 # Enable %p to be unhashed (if supported)
7397 debug_raw[$node]=$(do_node $node "$LCTL get_param -n debug_raw_pointers" || echo 0)
7398 do_node $node "$LCTL set_param debug_raw_pointers=Y || true"
7401 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7403 # if $ONLY is set, repeat subtest $ONLY_REPEAT times, otherwise once
7404 local repeat=${ONLY:+$ONLY_REPEAT}
7406 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
7407 local before_sub=$SECONDS
7409 log_sub_test_begin $TESTNAME
7410 # remove temp files between repetitions to avoid test failures
7411 if [[ -n "$append" ]]; then
7412 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7413 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7414 echo "subtest iteration $testiter/$repeat"
7416 # loop around subshell so stack_trap EXIT triggers each time
7417 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
7420 local duration_sub=$((SECONDS - before_sub))
7423 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7424 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7426 if [[ -f $LOGDIR/err ]]; then
7427 test_error=$(cat $LOGDIR/err)
7429 elif [[ -f $LOGDIR/ignore ]]; then
7430 test_error=$(cat $LOGDIR/ignore)
7431 elif [[ -f $LOGDIR/skip ]]; then
7432 test_error=$(cat $LOGDIR/skip)
7438 pass "$testnum" "(${duration_sub}s)"
7439 if [ -n "${DUMP_OK}" ]; then
7440 gather_logs $(comma_list $(nodes_list))
7443 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7444 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7448 for node in $(all_nodes); do
7449 param="kernel/kptr_restrict=${kptr_restrict[$node]}"
7450 do_node $node "sysctl -wq ${param} || true"
7451 # Restore %p to initial state
7452 param="debug_raw_pointers=${debug_raw[$node]}"
7453 do_node $node "$LCTL set_param ${param} || true"
7456 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7460 if [ -f $LOGDIR/err ]; then
7461 log_zfs_info "$zfs_debug_log"
7462 $FAIL_ON_ERROR && exit $rc
7475 # Print information of skipped tests to result.yml
7478 log_sub_test_begin $1
7480 log_sub_test_end "SKIP" "0" "0" "$@"
7483 grant_from_clients() {
7487 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7491 grant_from_servers() {
7495 # which is tot_granted less grant_precreate
7496 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7497 " obdfilter.${FSNAME}-OST*.tot_pending" \
7498 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7499 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7500 /tot_pending/{ total -= $2 };
7501 /grant_precreate/{ total -= $2 };
7502 END { printf("%0.0f", total) }'
7506 export base=$(basetest $1)
7507 [ "$CHECK_GRANT" == "no" ] && return 0
7509 local isonly_base=GCHECK_ONLY_${base}
7510 local isonly=GCHECK_ONLY_$1
7511 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7513 echo -n "checking grant......"
7515 local osts=$(comma_list $(osts_nodes))
7516 local clients=$CLIENTS
7517 [ -z "$clients" ] && clients=$(hostname)
7519 # sync all the data and make sure no pending data on server
7520 do_nodes $clients sync
7521 do_nodes $clients $LFS df # initiate all idling connections
7524 cli_grant=$(grant_from_clients $clients)
7527 # which is tot_granted less grant_precreate
7528 srv_grant=$(grant_from_servers $osts)
7531 # check whether client grant == server grant
7532 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7533 echo "wait for client:$cli_grant == server:$srv_grant"
7535 cli_grant=$(grant_from_clients $clients)
7536 srv_grant=$(grant_from_servers $osts)
7538 if [[ $cli_grant -ne $srv_grant ]]; then
7539 do_nodes $(comma_list $(osts_nodes)) \
7540 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7541 "obdfilter.${FSNAME}-OST*.grant_*"
7542 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7543 error "failed grant check: client:$cli_grant server:$srv_grant"
7545 echo "pass grant check: client:$cli_grant server:$srv_grant"
7549 ########################
7558 ostuuid_from_index() {
7559 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7560 local uuid=($($LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7565 ostname_from_index() {
7566 local uuid=$(ostuuid_from_index $1 $2)
7571 mdtuuid_from_index() {
7572 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7573 local uuid=($($LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7578 mdtname_from_index() {
7579 local uuid=$(mdtuuid_from_index $1 $2)
7584 mdssize_from_index() {
7585 local mdt=$(mdtname_from_index $2)
7587 $LFS df $1 | awk "/$mdt/ { print \$2 }"
7590 index_from_ostuuid()
7592 # only print the first index, if 'lfs osts' shows multiple mountpoints
7593 local ostidx=($($LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"))
7599 # Return unique identifier for given hostname
7602 echo $host_name | md5sum | cut -d' ' -f1
7606 # Returns list of ip addresses for each interface
7608 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7612 # Returns list of interfaces configured for LNet
7614 local nids=( $($LCTL list_nids | xargs echo) )
7616 [[ -z ${nids[@]} ]] &&
7619 if [[ ${NETTYPE} =~ kfi* ]]; then
7620 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7621 sort -u | xargs echo
7625 declare -a INTERFACES
7627 for ((i = 0; i < ${#nids[@]}; i++)); do
7628 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7629 INTERFACES[i]=$(ip -o a s |
7630 awk '$4 ~ /^'$ip'\//{print $2}')
7631 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7632 if [[ -z ${INTERFACES[i]} ]]; then
7633 error "Can't determine interface name for NID ${nids[i]}"
7634 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7635 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7639 echo "${INTERFACES[@]}"
7644 # return 1 if addr is remote
7645 # return 0 if addr is local
7648 # Cache address list to avoid mutiple execution of local_addr_list
7649 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7651 for i in $LOCAL_ADDR_LIST ; do
7652 [[ "$i" == "$addr" ]] && return 0
7657 # return true(0) if host_name is local
7658 # return false(1) if host_name is remote
7661 local is_local="IS_LOCAL_$(host_id $host_name)"
7663 if [ -z "${!is_local-}" ] ; then
7664 eval $is_local=false
7665 local host_ip=$(getent ahostsv4 $host_name |
7666 awk 'NR == 1 { print $1 }')
7667 is_local_addr "$host_ip" && eval $is_local=true
7681 for node in $(mdts_nodes); do
7682 remote_node $node && return 0
7689 [ -n "$CLIENTONLY" ] && return 0 || true
7690 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7695 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7696 MSKIPPED=1 && return 1
7703 for node in $(osts_nodes) ; do
7704 remote_node $node && return 0
7711 [ -n "$CLIENTONLY" ] && return 0 || true
7712 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7717 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7718 OSKIPPED=1 && return 1
7724 [ -n "$CLIENTONLY" ] && return 0 || true
7726 MGS=$(facet_host mgs)
7727 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7732 remote_mds_nodsh || remote_ost_nodsh ||
7733 $(single_local_node $(comma_list $(nodes_list)))
7737 remote_ost && remote_mds
7740 # Get the active nodes for facets.
7748 for facet in ${facets//,/ }; do
7749 nodes="$nodes $(facet_active_host $facet)"
7752 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7756 # Get name of the active MGS node.
7758 echo -n $(facets_nodes $(get_facets MGS))
7761 # Get all of the active MDS nodes.
7763 echo -n $(facets_nodes $(get_facets MDS))
7766 # Get all of the active OSS nodes.
7768 echo -n $(facets_nodes $(get_facets OST))
7771 # Get all of the client nodes and active server nodes.
7773 local nodes=$HOSTNAME
7777 # CLIENTS (if specified) contains the local client
7778 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7780 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7781 nodes="$nodes $(facets_nodes $(get_facets))"
7784 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7788 # Get all of the remote client nodes and remote active server nodes.
7789 remote_nodes_list () {
7790 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7793 # Get all of the MDS nodes, including active and passive nodes.
7801 for i in $(seq $MDSCOUNT); do
7803 failover_host=mds${i}failover_HOST
7804 nodes="$nodes ${!host} ${!failover_host}"
7807 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7808 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7812 # Get all of the OSS nodes, including active and passive nodes.
7820 for i in $(seq $OSTCOUNT); do
7822 failover_host=ost${i}failover_HOST
7823 nodes="$nodes ${!host} ${!failover_host}"
7826 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7827 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7831 # Get all of the server nodes, including active and passive nodes.
7832 all_server_nodes () {
7837 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7839 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7843 # Get all of the client and server nodes, including active and passive nodes.
7845 local nodes=$HOSTNAME
7849 # CLIENTS (if specified) contains the local client
7850 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7852 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7853 nodes="$nodes $(all_server_nodes)"
7856 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7860 init_clients_lists () {
7861 # Sanity check: exclude the local client from RCLIENTS
7862 local clients=$(hostlist_expand "$RCLIENTS")
7863 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7865 # Sanity check: exclude the dup entries
7866 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7868 export CLIENT1=${CLIENT1:-$HOSTNAME}
7869 export SINGLECLIENT=$CLIENT1
7871 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7873 # Sanity check: exclude the dup entries from CLIENTS
7874 # for those configs which has SINGLCLIENT set to local client
7875 clients=$(for i in $clients; do echo $i; done | sort -u)
7877 export CLIENTS=$(comma_list $clients)
7878 local -a remoteclients=($RCLIENTS)
7879 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7880 varname=CLIENT$((i + 2))
7882 eval export $varname=${remoteclients[i]}
7885 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7888 get_random_entry () {
7891 rnodes=${rnodes//,/ }
7893 local -a nodes=($rnodes)
7894 local num=${#nodes[@]}
7895 local i=$((RANDOM * num * 2 / 65536))
7901 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7905 # this should already have been called, but just in case
7906 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7909 echo "client=$CLIENT_VERSION MDS=$MDS1_VERSION OSS=$OST1_VERSION"
7911 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7912 error "unable to determine node versions"
7914 (( "$CLIENT_VERSION" == "$MDS1_VERSION" &&
7915 "$CLIENT_VERSION" == "$OST1_VERSION"))
7921 echo $nodes | wc -w || true
7925 local nodes=$(mdts_nodes)
7926 local mdtcount=$(get_node_count "$nodes")
7928 [ ! "$MDSCOUNT" = "$mdtcount" ]
7931 generate_machine_file() {
7932 local nodes=${1//,/ }
7933 local machinefile=$2
7936 for node in $nodes; do
7937 echo $node >>$machinefile ||
7938 { echo "can not generate machinefile $machinefile" &&
7944 local file=$1/stripe
7947 $LFS getstripe -v $file || error "getstripe $file failed"
7951 # Check and add a test group.
7957 local gid=$(getent group $group_name | cut -d: -f3)
7958 if [[ -n "$gid" ]]; then
7959 [[ "$gid" -eq "$group_id" ]] || {
7960 error_noexit "inconsistent group ID:" \
7961 "new: $group_id, old: $gid"
7965 echo "adding group $group_name:$group_id"
7966 getent group $group_name || true
7967 getent group $group_id || true
7968 groupadd -g $group_id $group_name
7975 # Check and add a test user.
7988 local uid=$(getent passwd $user_name | cut -d: -f3)
7989 if [[ -n "$uid" ]]; then
7990 if [[ "$uid" -eq "$user_id" ]]; then
7991 local dir=$(getent passwd $user_name | cut -d: -f6)
7992 if [[ "$dir" != "$home" ]]; then
7994 usermod -d $home $user_name
7998 error_noexit "inconsistent user ID:" \
7999 "new: $user_id, old: $uid"
8004 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
8011 check_runas_id_ret() {
8013 local myRUNAS_UID=$1
8014 local myRUNAS_GID=$2
8018 if [ -z "$myRUNAS" ]; then
8019 error_exit "check_runas_id_ret requires myRUNAS argument"
8023 error "Unable to execute $myRUNAS"
8025 id $myRUNAS_UID > /dev/null ||
8026 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
8027 "some UID which exists on MDS and client or add user " \
8028 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
8031 $myRUNAS krb5_login.sh ||
8032 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
8034 mkdir $DIR/d0_runas_test
8036 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
8037 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
8038 rm -rf $DIR/d0_runas_test
8043 local myRUNAS_UID=$1
8044 local myRUNAS_GID=$2
8048 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
8049 error "unable to write to $DIR/d0_runas_test as " \
8053 # obtain the UID/GID for MPI_USER
8057 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
8058 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
8060 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
8061 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
8064 # Run multiop in the background, but wait for it to print
8065 # "PAUSING" to its stdout before returning from this function.
8066 multiop_bg_pause() {
8067 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
8071 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
8074 echo "$MULTIOP_PROG $FILE v$ARGS"
8075 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
8078 echo "TMPPIPE=${TMPPIPE}"
8079 read -t 60 multiop_output < $TMPPIPE
8080 if [ $? -ne 0 ]; then
8085 if [ "$multiop_output" != "PAUSING" ]; then
8086 echo "Incorrect multiop output: $multiop_output"
8101 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
8103 echo $((SECONDS - start))
8107 inodes_available () {
8108 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
8109 sort -un | head -n1) || return 1
8114 mdsrate_inodes_available () {
8115 local min_inodes=$(inodes_available)
8117 echo $((min_inodes * 99 / 100))
8120 bytes_available () {
8121 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
8124 mdsrate_bytes_available () {
8125 local bytes=$(bytes_available)
8127 echo $((bytes * 99 / 100))
8130 # reset stat counters
8132 local paramfile="$1"
8134 lctl set_param -n $paramfile=0
8139 local paramfile="$1"
8142 lctl get_param -n $paramfile |
8143 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
8147 awk '{sum += $1} END { printf("%0.0f", sum) }'
8150 calc_osc_kbytes () {
8151 $LFS df $MOUNT > /dev/null
8152 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
8156 wait_delete_completed
8157 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8158 echo "OST kbytes available: ${AVAIL[*]}"
8163 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8164 #echo OST $i: ${AVAIL[i]}kb
8165 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8169 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8174 echo "Min free space: OST $MINI: $MINV"
8175 echo "Max free space: OST $MAXI: $MAXV"
8178 # save_lustre_params(comma separated facet list, parameter_mask)
8179 # generate a stream of formatted strings (<facet> <param name>=<param value>)
8180 save_lustre_params() {
8185 for facet in ${facets//,/ }; do
8186 facet_svc=$(facet_svc $facet)
8188 "params=\\\$($LCTL get_param $2);
8189 [[ -z \\\"$facet_svc\\\" ]] && param= ||
8190 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
8191 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
8192 while read s; do echo $facet \\\$s;
8193 done <<< \\\"\\\$param\\\""
8197 # restore lustre parameters from input stream, produces by save_lustre_params
8198 restore_lustre_params() {
8203 while IFS=" =" read facet name val; do
8204 do_facet $facet "$LCTL set_param -n $name=$val"
8208 check_node_health() {
8209 local nodes=${1:-$(comma_list $(nodes_list))}
8210 local health=$TMP/node_health.$$
8212 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
8213 grep "catastrophe=1" && error "LBUG/LASSERT detected"
8214 # Only check/report network health if get_param isn't reported, since
8215 # *clearly* the network is working if get_param returned something.
8216 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
8217 for node in ${nodes//,/ }; do
8218 check_network $node 5
8224 mdsrate_cleanup () {
8226 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
8227 --nfiles $3 --dir $4 --filefmt $5 $6
8233 local test_type="$1"
8246 local mdtest_basedir
8247 local mdtest_actions
8248 local mdtest_options
8249 local stripe_options
8252 case "$test_type" in
8254 stripe_options=(-c 1 -i 0)
8255 mdtest_actions=(-F -R)
8260 stripe_options=(-c -1)
8261 mdtest_actions=(-F -R)
8262 file_size=$((1024 * 1024 * 1024))
8266 stripe_options=(-c 1)
8267 mdtest_actions=(-C -D -E -k -r)
8272 stripe_options=(-c 1)
8273 mdtest_actions=(-C -D -E -k -r)
8278 stripe_options=(-c -1)
8284 if [[ -n "$MDTEST_DEBUG" ]]; then
8285 mdtest_options+=(-v -v -v)
8288 num_dirs=${NUM_DIRS:-$num_dirs}
8289 num_files=${NUM_FILES:-$num_files}
8290 file_size=${FILE_SIZE:-$file_size}
8291 free_space=$(mdsrate_bytes_available)
8293 if (( file_size * num_files > free_space )); then
8294 file_size=$((free_space / num_files))
8295 log "change file size to $file_size due to" \
8296 "number of files $num_files and" \
8297 "free space limit in $free_space"
8300 if (( file_size > 0 )); then
8301 log "set file size to $file_size"
8302 mdtest_options+=(-w=$file_size)
8305 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
8306 mdtest_basedir=$MOUNT/mdtest
8307 mdtest_options+=(-d=$mdtest_basedir)
8310 num_hosts=$(get_node_count ${CLIENTS//,/ })
8311 num_procs=$((num_cores * num_hosts))
8312 num_inodes=$(mdsrate_inodes_available)
8314 if (( num_inodes < num_files )); then
8315 log "change the number of files $num_files to the" \
8316 "number of available inodes $num_inodes"
8317 num_files=$num_inodes
8320 if (( num_dirs > 1 )); then
8321 num_entries=$((num_files / num_dirs))
8322 log "split $num_files files to $num_dirs" \
8323 "with $num_entries files each"
8324 mdtest_options+=(-I=$num_entries)
8327 generate_machine_file $CLIENTS $MACHINEFILE ||
8328 error "can not generate machinefile"
8330 install -v -d -m 0777 $mdtest_basedir
8332 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
8334 save_lustre_params $(get_facets MDS) \
8335 mdt.*.enable_remote_dir_gid > $params_file
8337 do_nodes $(comma_list $(mdts_nodes)) \
8338 $LCTL set_param mdt.*.enable_remote_dir_gid=-1
8340 stack_trap "restore_lustre_params < $params_file" EXIT
8342 for np in 1 $num_procs; do
8343 num_entries=$((num_files / np ))
8345 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8346 -np $np -npernode $num_cores $MDTEST \
8347 ${mdtest_options[@]} -n=$num_entries \
8348 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
8352 if (( rc != 0 )); then
8353 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8354 -np $np -npernode $num_cores $MDTEST \
8355 ${mdtest_options[@]} -n=$num_entries \
8356 -r 2>&1 | tee -a "$LOG"
8361 rmdir -v $mdtest_basedir
8362 rm -v $state $MACHINEFILE
8367 ########################
8369 convert_facet2label() {
8372 if [ x$facet = xost ]; then
8374 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8378 local varsvc=${facet}_svc
8380 if [ -n "${!varsvc}" ]; then
8383 error "No label for $facet!"
8387 get_clientosc_proc_path() {
8388 echo "${1}-osc-[-0-9a-f]*"
8391 get_mdtosc_proc_path() {
8393 local ost_label=${2:-"*OST*"}
8395 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8396 local mdt_label=$(convert_facet2label $mds_facet)
8397 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8399 if [[ $ost_label = *OST* ]]; then
8400 echo "${ost_label}-osc-${mdt_index}"
8402 echo "${ost_label}-osp-${mdt_index}"
8406 get_osc_import_name() {
8409 local label=$(convert_facet2label $ost)
8411 if [ "${facet:0:3}" = "mds" ]; then
8412 get_mdtosc_proc_path $facet $label
8416 get_clientosc_proc_path $label
8420 _wait_import_state () {
8422 local CONN_PROC="$2"
8423 local maxtime=${3:-$(max_recovery_time)}
8424 local err_on_fail=${4:-1}
8428 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8429 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8430 if [[ "${expected}" == "DISCONN" ]]; then
8431 # for disconn we can check after proc entry is removed
8432 [[ -z "${CONN_STATE}" ]] && return 0
8433 # with AT, we can have connect request timeout near
8434 # reconnect timeout and test can't see real disconnect
8435 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8437 if (( $i >= $maxtime )); then
8438 (( $err_on_fail != 0 )) &&
8439 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8443 # Add uniq for multi-mount case
8444 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8449 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8453 wait_import_state() {
8456 local maxtime=${3:-$(max_recovery_time)}
8457 local err_on_fail=${4:-1}
8460 for param in ${params//,/ }; do
8461 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8466 wait_import_state_mount() {
8467 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8471 wait_import_state "$@"
8474 # One client request could be timed out because server was not ready
8475 # when request was sent by client.
8476 # The request timeout calculation details :
8478 # /* We give the server rq_timeout secs to process the req, and
8479 # add the network latency for our local timeout. */
8480 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8481 # ptlrpc_at_get_net_latency(request) ;
8483 # ptlrpc_connect_import ()
8484 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8487 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8488 # ptlrpc_at_get_net_latency(request) ->
8489 # at_get (max (iat_net_latency=0, at_min)) = at_min
8492 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8493 # INITIAL_CONNECT_TIMEOUT + at_min
8495 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8496 # because we can not get this value in runtime,
8497 # the value depends on configure options, and it is not stored in /proc.
8499 # #define CONNECTION_SWITCH_MIN 5U
8500 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8502 request_timeout () {
8505 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8506 local init_connect_timeout=$TIMEOUT
8507 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8509 local at_min=$(at_get $facet at_min)
8511 echo $(( init_connect_timeout + at_min ))
8514 _wait_osc_import_state() {
8518 local target=$(get_osc_import_name $facet $ost_facet)
8519 local param="os[cp].${target}.ost_server_uuid"
8523 # 1. wait the deadline of client 1st request (it could be skipped)
8524 # 2. wait the deadline of client 2nd request
8525 local maxtime=$(( 2 * $(request_timeout $facet)))
8527 if [[ $facet == client* ]]; then
8528 # During setup time, the osc might not be setup, it need wait
8529 # until list_param can return valid value.
8530 params=$($LCTL list_param $param 2>/dev/null || true)
8531 while [ -z "$params" ]; do
8532 if [ $i -ge $maxtime ]; then
8533 echo "can't get $param in $maxtime secs"
8538 params=$($LCTL list_param $param 2>/dev/null || true)
8542 if [[ $ost_facet = mds* ]]; then
8543 # no OSP connection to itself
8544 if [[ $facet = $ost_facet ]]; then
8547 param="osp.${target}.mdt_server_uuid"
8551 local plist=$(comma_list $params)
8552 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8553 wait_import_state $expected $plist $maxtime; then
8554 error "$facet: import is not in $expected state after $maxtime"
8561 wait_osc_import_state() {
8567 if [[ $facet = mds ]]; then
8568 for num in $(seq $MDSCOUNT); do
8569 _wait_osc_import_state mds$num "$ost_facet" "$expected"
8572 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
8576 wait_osc_import_ready() {
8577 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
8580 _wait_mgc_import_state() {
8583 local error_on_failure=${3:-1}
8584 local param="mgc.*.mgs_server_uuid"
8588 # 1. wait the deadline of client 1st request (it could be skipped)
8589 # 2. wait the deadline of client 2nd request
8590 local maxtime=$(( 2 * $(request_timeout $facet)))
8592 if [[ $facet == client* ]]; then
8593 # During setup time, the osc might not be setup, it need wait
8594 # until list_param can return valid value. And also if there
8595 # are mulitple osc entries we should list all of them before
8597 params=$($LCTL list_param $param 2>/dev/null || true)
8598 while [ -z "$params" ]; do
8599 if [ $i -ge $maxtime ]; then
8600 echo "can't get $param in $maxtime secs"
8605 params=$($LCTL list_param $param 2>/dev/null || true)
8608 local plist=$(comma_list $params)
8609 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8610 wait_import_state $expected $plist $maxtime \
8611 $error_on_failure; then
8612 if [ $error_on_failure -ne 0 ]; then
8613 error "import is not in ${expected} state"
8621 wait_mgc_import_state() {
8624 local error_on_failure=${3:-1}
8627 if [[ $facet = mds ]]; then
8628 for num in $(seq $MDSCOUNT); do
8629 _wait_mgc_import_state mds$num "$expected" \
8630 $error_on_failure || return
8633 _wait_mgc_import_state "$facet" "$expected" \
8634 $error_on_failure || return
8638 wait_dne_interconnect() {
8641 if [ $MDSCOUNT -gt 1 ]; then
8642 for num in $(seq $MDSCOUNT); do
8643 wait_osc_import_ready mds mds$num
8648 get_clientmdc_proc_path() {
8652 get_clientmgc_proc_path() {
8659 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8664 [ -z "$list" ] && return 0
8666 # Add paths to lustre tests for 32 and 64 bit systems.
8667 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8668 local TESTPATH="$RLUSTRE/tests:"
8669 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8670 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8671 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8675 wait_clients_import_state () {
8679 local facets="$facet"
8681 if [ "$FAILURE_MODE" = HARD ]; then
8682 facets=$(for f in ${facet//,/ }; do
8683 facets_on_host $(facet_active_host $f) | tr "," "\n"
8684 done | sort -u | paste -sd , )
8687 for facet in ${facets//,/ }; do
8688 local label=$(convert_facet2label $facet)
8691 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8692 $label).ost_server_uuid" ;;
8693 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8694 $label).mds_server_uuid" ;;
8695 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8696 $label).mgs_server_uuid" ;;
8697 *) error "unknown facet!" ;;
8700 local params=$(expand_list $params $proc_path)
8703 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8705 error "import is not in ${expected} state"
8710 wait_clients_import_ready() {
8711 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
8723 # wait until all MDTs are in the expected state
8724 for ((num = 1; num <= $MDSCOUNT; num++)); do
8725 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8728 if [ $facet = "mds" ]; then
8729 mproc="osp.$mdtosp.active"
8730 [ $num -eq $((tgt_idx + 1)) ] && continue
8732 mproc="osc.$mdtosp.active"
8738 val=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8740 if (( rc != 0 )); then
8741 echo "Can't read $mproc (rc = $rc)"
8742 elif [[ "$val" == "$expected" ]]; then
8743 echo "$mproc updated after $wait sec (got $val)"
8748 error "$tgt_name: wanted $expected got $val"
8750 echo "Waiting $((max - wait)) secs for $mproc"
8762 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8763 $LCTL get_param obdfilter.*.kbytesavail))
8764 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8765 $LCTL get_param -n obdfilter.*.tot_granted))
8766 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8767 $LCTL get_param -n obdfilter.*.kbytestotal))
8768 for ((i=0; i<${#AVAILA[@]}; i++)); do
8769 local -a AVAIL1=(${AVAILA[$i]//=/ })
8770 local -a TOTAL=(${TOTALA[$i]//=/ })
8771 GRANT=$((${GRANTA[$i]}/1024))
8772 # allow 1% of total space in bavail because of delayed
8773 # allocation with ZFS which might release some free space after
8774 # txg commit. For small devices, we set a mininum of 8MB
8775 local LIMIT=$((${TOTAL} / 100 + 8000))
8776 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8777 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8778 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8779 echo " FULL" || echo
8785 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8788 check_pool_not_exist() {
8789 local fsname=${1%%.*}
8790 local poolname=${1##$fsname.}
8791 [[ $# -ne 1 ]] && return 0
8792 [[ x$poolname = x ]] && return 0
8793 list_pool $fsname | grep -w $1 && return 1
8798 local fsname=${1%%.*}
8799 local poolname=${1##$fsname.}
8800 local keep_pools=${2:-false}
8802 stack_trap "destroy_test_pools $fsname" EXIT
8803 do_facet mgs lctl pool_new $1
8805 # get param should return err unless pool is created
8806 [[ $RC -ne 0 ]] && return $RC
8808 for mds_id in $(seq $MDSCOUNT); do
8809 local mdt_id=$((mds_id-1))
8810 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8811 wait_update_facet mds$mds_id \
8812 "lctl get_param -n lod.$lodname.pools.$poolname \
8813 2>/dev/null || echo foo" "" ||
8814 error "mds$mds_id: pool_new failed $1"
8816 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8817 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8819 $keep_pools || add_pool_to_list $1
8823 add_pool_to_list () {
8824 local fsname=${1%%.*}
8825 local poolname=${1##$fsname.}
8827 local listvar=${fsname}_CREATED_POOLS
8828 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8832 remove_pool_from_list () {
8833 local fsname=${1%%.*}
8834 local poolname=${1##$fsname.}
8836 local listvar=${fsname}_CREATED_POOLS
8837 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8841 # cleanup all pools exist on $FSNAME
8842 destroy_all_pools () {
8844 for i in $(list_pool $FSNAME); do
8849 destroy_pool_int() {
8851 local OSTS=$(list_pool $1)
8852 for ost in $OSTS; do
8853 do_facet mgs lctl pool_remove $1 $ost
8855 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8856 error "MDS: pool_list $1 failed"
8857 do_facet mgs lctl pool_destroy $1
8860 # <fsname>.<poolname> or <poolname>
8862 local fsname=${1%%.*}
8863 local poolname=${1##$fsname.}
8865 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8869 check_pool_not_exist $fsname.$poolname && return 0 || true
8871 destroy_pool_int $fsname.$poolname
8873 [[ $RC -ne 0 ]] && return $RC
8874 for mds_id in $(seq $MDSCOUNT); do
8875 local mdt_id=$((mds_id-1))
8876 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8877 wait_update_facet mds$mds_id \
8878 "lctl get_param -n lod.$lodname.pools.$poolname \
8879 2>/dev/null || echo foo" "foo" ||
8880 error "mds$mds_id: destroy pool failed $1"
8882 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8883 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8885 remove_pool_from_list $fsname.$poolname
8891 local fsname=${1:-$FSNAME}
8893 local listvar=${fsname}_CREATED_POOLS
8895 [ x${!listvar} = x ] && return 0
8897 echo "Destroy the created pools: ${!listvar}"
8898 for poolname in ${!listvar//,/ }; do
8899 destroy_pool $fsname.$poolname
8903 destroy_test_pools () {
8904 local fsname=${1:-$FSNAME}
8905 destroy_pools $fsname || true
8911 local ts=$(date +%s)
8914 if [[ ! -f "$YAML_LOG" ]]; then
8915 # init_logging is not performed before gather_logs,
8916 # so the $LOGDIR needs to be checked here
8917 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8920 [ -f $LOGDIR/shared ] && docp=false
8922 # dump lustre logs, dmesg, and journal if GSS_SK=true
8924 prefix="$TESTLOG_PREFIX.$TESTNAME"
8926 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8928 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8929 echo "Dumping logs only on local client."
8930 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8931 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8932 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8933 $LGSS_SK -r {} \; &> \
8934 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8935 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8936 ${prefix}.nodemaps.$(hostname -s).${suffix}
8937 [ "$GSS" = true ] && keyctl show > \
8938 ${prefix}.keyring.$(hostname -s).${suffix}
8939 [ "$GSS" = true ] && journalctl -a > \
8940 ${prefix}.journal.$(hostname -s).${suffix}
8945 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8946 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8947 if [ "$SHARED_KEY" = true ]; then
8948 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8949 $LGSS_SK -r {} \; &> \
8950 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8951 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8952 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8954 if [ "$GSS" = true ]; then
8955 do_nodesv $list "keyctl show > \
8956 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8957 do_nodesv $list "journalctl -a > \
8958 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8961 if [ ! -f $LOGDIR/shared ]; then
8962 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8964 for node in ${remote_nodes//,/ }; do
8965 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8979 for i in $(seq 0 $num_mntpts); do
8980 cmd="ls -laf ${mntpt_root}$i/$dir"
8986 for pid in $pids; do
8993 # check_and_start_recovery_timer()
8994 # service_time = at_est2timeout(service_time);
8995 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8996 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8998 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8999 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
9000 #define CONNECTION_SWITCH_MIN 5
9001 #define CONNECTION_SWITCH_INC 5
9002 max_recovery_time() {
9003 local init_connect_timeout=$((TIMEOUT / 20))
9004 ((init_connect_timeout >= 5)) || init_connect_timeout=5
9006 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
9007 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
9009 echo -n $service_time
9012 recovery_time_min() {
9013 local connection_switch_min=5
9014 local connection_switch_inc=5
9015 local connection_switch_max
9016 local reconnect_delay_max
9017 local initial_connect_timeout
9021 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
9022 (($connection_switch_min > $TIMEOUT)) &&
9023 max=$connection_switch_min || max=$TIMEOUT
9024 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
9026 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
9027 timeout_20=$((TIMEOUT/20))
9028 (($connection_switch_min > $timeout_20)) &&
9029 initial_connect_timeout=$connection_switch_min ||
9030 initial_connect_timeout=$timeout_20
9032 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
9033 initial_connect_timeout))
9034 echo $((2 * reconnect_delay_max))
9037 get_clients_mount_count () {
9038 local clients=${CLIENTS:-$HOSTNAME}
9040 # we need to take into account the clients mounts and
9041 # exclude mds/ost mounts if any;
9042 do_nodes $clients cat /proc/mounts | grep lustre |
9043 grep -w $MOUNT | wc -l
9047 PROC_CLI="srpc_info"
9048 PROC_CON="srpc_contexts"
9056 if [ $M -lt $N ]; then
9060 while [ $N -lt $M ]; do
9070 calc_connection_cnt() {
9073 # MDT->MDT = 2 * C(M, 2)
9077 comb_m2=$(combination $MDSCOUNT 2)
9079 local num_clients=$(get_clients_mount_count)
9081 local cnt_mdt2mdt=$((comb_m2 * 2))
9082 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
9083 local cnt_cli2ost=$((num_clients * OSTCOUNT))
9084 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
9085 if is_mounted $MOUNT2; then
9086 cnt_cli2mdt=$((cnt_cli2mdt * 2))
9087 cnt_cli2ost=$((cnt_cli2ost * 2))
9095 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
9096 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
9097 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
9098 + cnt_cli2ost + cnt_cli2mdt))
9112 local cmd="$tgt.srpc.flavor"
9114 if [ $net == "any" ]; then
9119 if [ $dir != "any" ]; then
9124 log "Setting sptlrpc rule: $cmd"
9125 do_facet mgs "$LCTL conf_param $cmd"
9131 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
9141 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
9142 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
9144 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
9146 if [ "x$bulkspec" != "x" ]; then
9147 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
9149 if [ "x$algs" != "x" ]; then
9150 bulk_count=`echo "$output" | grep "bulk flavor" |
9153 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
9155 if [ $bulk == "bulkn" ]; then
9156 bulk_count=`echo "$output" |
9157 grep "bulk flavor" | grep "null/null" |
9159 elif [ $bulk == "bulki" ]; then
9160 bulk_count=`echo "$output" |
9161 grep "bulk flavor" | grep "/null" |
9162 grep -v "null/" | wc -l`
9164 bulk_count=`echo "$output" |
9165 grep "bulk flavor" | grep -v "/null" |
9166 grep -v "null/" | wc -l`
9169 [ $bulk_count -lt $count ] && count=$bulk_count
9180 local clients=${CLIENTS:-$HOSTNAME}
9182 for c in ${clients//,/ }; do
9183 local output=$(do_node $c lctl get_param -n \
9184 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
9185 local tmpcnt=$(count_flvr "$output" $flavor)
9187 if $GSS_SK && [ $flavor != "null" ]; then
9188 # tmpcnt=min(contexts,flavors) to ensure SK context is
9190 output=$(do_node $c lctl get_param -n \
9191 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
9192 local outcon=$(count_contexts "$output")
9194 if [ "$outcon" -lt "$tmpcnt" ]; then
9198 cnt=$((cnt + tmpcnt))
9205 local clients=${CLIENTS:-$HOSTNAME}
9207 for c in ${clients//,/ }; do
9208 do_node $c lctl get_param \
9209 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null
9212 do_node $c lctl get_param \
9213 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null
9223 local clients=${CLIENTS:-$HOSTNAME}
9225 for c in ${clients//,/ }; do
9227 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
9228 local output=$(do_node $c lctl get_param -n \
9229 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
9230 local tmpcnt=$(count_flvr "$output" $flavor)
9232 if $GSS_SK && [ $flavor != "null" ]; then
9233 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9234 output=$(do_node $c lctl get_param -n \
9235 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
9236 local outcon=$(count_contexts "$output")
9238 if [ "$outcon" -lt "$tmpcnt" ]; then
9242 cnt=$((cnt + tmpcnt))
9249 local clients=${CLIENTS:-$HOSTNAME}
9251 for c in ${clients//,/ }; do
9252 do_node $c lctl get_param \
9253 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null
9256 do_node $c lctl get_param \
9257 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null
9267 if [ $MDSCOUNT -le 1 ]; then
9272 for num in `seq $MDSCOUNT`; do
9273 local output=$(do_facet mds$num lctl get_param -n \
9274 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
9275 local tmpcnt=$(count_flvr "$output" $flavor)
9277 if $GSS_SK && [ $flavor != "null" ]; then
9278 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9279 output=$(do_facet mds$num lctl get_param -n \
9280 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
9281 local outcon=$(count_contexts "$output")
9283 if [ "$outcon" -lt "$tmpcnt" ]; then
9287 cnt=$((cnt + tmpcnt))
9294 for num in `seq $MDSCOUNT`; do
9295 do_facet mds$num lctl get_param \
9296 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null
9299 do_facet mds$num lctl get_param \
9300 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null
9311 for num in `seq $MDSCOUNT`; do
9312 mdtosc=$(get_mdtosc_proc_path mds$num)
9313 mdtosc=${mdtosc/-MDT*/-MDT\*}
9314 local output=$(do_facet mds$num lctl get_param -n \
9315 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
9316 # Ensure SK context is on
9317 local tmpcnt=$(count_flvr "$output" $flavor)
9319 if $GSS_SK && [ $flavor != "null" ]; then
9320 output=$(do_facet mds$num lctl get_param -n \
9321 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
9322 local outcon=$(count_contexts "$output")
9324 if [ "$outcon" -lt "$tmpcnt" ]; then
9328 cnt=$((cnt + tmpcnt))
9335 for num in `seq $MDSCOUNT`; do
9336 mdtosc=$(get_mdtosc_proc_path mds$num)
9337 mdtosc=${mdtosc/-MDT*/-MDT\*}
9338 do_facet mds$num lctl get_param \
9339 os[cp].$mdtosc.$PROC_CLI 2>/dev/null
9342 do_facet mds$num lctl get_param \
9343 os[cp].$mdtosc.$PROC_CON 2>/dev/null
9352 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
9354 count_flvr "$output" $flavor
9359 local dir=$1 # from to
9360 local flavor=$2 # flavor expected
9363 if [ $dir == "cli2mdt" ]; then
9364 res=`flvr_cnt_cli2mdt $flavor`
9365 elif [ $dir == "cli2ost" ]; then
9366 res=`flvr_cnt_cli2ost $flavor`
9367 elif [ $dir == "mdt2mdt" ]; then
9368 res=`flvr_cnt_mdt2mdt $flavor`
9369 elif [ $dir == "mdt2ost" ]; then
9370 res=`flvr_cnt_mdt2ost $flavor`
9371 elif [ $dir == "all2ost" ]; then
9372 res1=`flvr_cnt_mdt2ost $flavor`
9373 res2=`flvr_cnt_cli2ost $flavor`
9374 res=$((res1 + res2))
9375 elif [ $dir == "all2mdt" ]; then
9376 res1=`flvr_cnt_mdt2mdt $flavor`
9377 res2=`flvr_cnt_cli2mdt $flavor`
9378 res=$((res1 + res2))
9379 elif [ $dir == "all2all" ]; then
9380 res1=`flvr_cnt_mdt2ost $flavor`
9381 res2=`flvr_cnt_cli2ost $flavor`
9382 res3=`flvr_cnt_mdt2mdt $flavor`
9383 res4=`flvr_cnt_cli2mdt $flavor`
9384 res=$((res1 + res2 + res3 + res4))
9392 local clients=${CLIENTS:-$HOSTNAME}
9395 for c in ${clients//,/ }; do
9396 [ "$type" == "osc" ] &&
9397 do_node $c lctl get_param osc.*.idle_timeout
9398 do_node $c lctl get_param $type.*.import |
9399 grep -E "name:|state:"
9405 local dir=$1 # from to
9407 if [ $dir == "cli2mdt" ]; then
9408 do_dump_imp_state mdc
9410 elif [ $dir == "cli2ost" ]; then
9411 do_dump_imp_state osc
9413 elif [ $dir == "mdt2mdt" ]; then
9415 elif [ $dir == "mdt2ost" ]; then
9417 elif [ $dir == "all2ost" ]; then
9419 do_dump_imp_state osc
9421 elif [ $dir == "all2mdt" ]; then
9423 do_dump_imp_state mdc
9425 elif [ $dir == "all2all" ]; then
9427 do_dump_imp_state osc
9430 do_dump_imp_state mdc
9437 local dir=$1 # from to
9438 local flavor=$2 # flavor expected
9439 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
9440 local WAITFLAVOR_MAX=20 # how many retries before abort?
9443 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
9444 echo -n "checking $dir..."
9445 res=$(do_check_flavor $dir $flavor)
9446 echo "found $res/$expect $flavor connections"
9447 [ $res -ge $expect ] && return 0
9451 echo "Error checking $flavor of $dir: expect $expect, actual $res"
9452 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
9455 gather_logs $(comma_list $(nodes_list))
9460 restore_to_default_flavor()
9462 local proc="mgs.MGS.live.$FSNAME"
9464 echo "restoring to default flavor..."
9466 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9467 grep ".srpc.flavor" | wc -l)
9469 # remove all existing rules if any
9470 if [ $nrule -ne 0 ]; then
9471 echo "$nrule existing rules"
9472 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9473 grep ".srpc.flavor."); do
9474 echo "remove rule: $rule"
9475 spec=`echo $rule | awk -F = '{print $1}'`
9476 do_facet mgs "$LCTL conf_param -d $spec"
9480 # verify no rules left
9481 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9482 grep ".srpc.flavor." | wc -l)
9483 [ $nrule -ne 0 ] && error "still $nrule rules left"
9485 # wait for default flavor to be applied
9488 set_rule $FSNAME any any $SK_FLAVOR
9489 wait_flavor all2all $SK_FLAVOR
9491 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9492 set_rule $FSNAME any cli2ost $SK_FLAVOR
9493 wait_flavor cli2mdt $SK_FLAVOR
9494 wait_flavor cli2ost $SK_FLAVOR
9496 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9498 wait_flavor all2all null
9504 local flavor=${1:-null}
9506 echo "setting all flavor to $flavor"
9508 # FIXME need parameter to this fn
9509 # and remove global vars
9510 local cnt_all2all=$(calc_connection_cnt all2all)
9512 local res=$(do_check_flavor all2all $flavor)
9513 if [ $res -eq $cnt_all2all ]; then
9514 echo "already have total $res $flavor connections"
9518 echo "found $res $flavor out of total $cnt_all2all connections"
9519 restore_to_default_flavor
9521 [[ $flavor = null ]] && return 0
9523 if $GSS_SK && [ $flavor != "null" ]; then
9525 set_rule $FSNAME any any $flavor
9526 wait_flavor all2all $flavor
9528 set_rule $FSNAME any cli2mdt $flavor
9529 set_rule $FSNAME any cli2ost $flavor
9530 set_rule $FSNAME any mdt2ost null
9531 set_rule $FSNAME any mdt2mdt null
9532 wait_flavor cli2mdt $flavor
9533 wait_flavor cli2ost $flavor
9535 echo "GSS_SK now at flavor: $flavor"
9537 set_rule $FSNAME any cli2mdt $flavor
9538 set_rule $FSNAME any cli2ost $flavor
9539 set_rule $FSNAME any mdt2ost null
9540 set_rule $FSNAME any mdt2mdt null
9541 wait_flavor cli2mdt $flavor
9542 wait_flavor cli2ost $flavor
9549 # Checking for shared logdir
9550 if [ ! -d $dir ]; then
9551 # Not found. Create local logdir
9554 touch $dir/check_file.$(hostname -s)
9559 check_write_access() {
9561 local list=${2:-$(comma_list $(nodes_list))}
9565 for node in ${list//,/ }; do
9566 file=$dir/check_file.$(short_nodename $node)
9567 if [[ ! -f "$file" ]]; then
9568 # Logdir not accessible/writable from this node.
9571 rm -f $file || return 1
9577 [[ -n $YAML_LOG ]] && return
9578 local save_umask=$(umask)
9581 export YAML_LOG=${LOGDIR}/results.yml
9585 # If the yaml log already exists then we will just append to it
9586 if [ ! -f $YAML_LOG ]; then
9587 if check_shared_dir $LOGDIR; then
9588 touch $LOGDIR/shared
9589 echo "Logging to shared log directory: $LOGDIR"
9591 echo "Logging to local directory: $LOGDIR"
9594 yml_nodes_file $LOGDIR >> $YAML_LOG
9595 yml_results_file >> $YAML_LOG
9600 # log actual client and server versions if needed for debugging
9601 log "Client: $(lustre_build_version client)"
9602 log "MDS: $(lustre_build_version mds1)"
9603 log "OSS: $(lustre_build_version ost1)"
9607 yml_log_test $1 >> $YAML_LOG
9611 yml_log_test_status "$@" >> $YAML_LOG
9614 log_sub_test_begin() {
9615 yml_log_sub_test_begin "$@" >> $YAML_LOG
9618 log_sub_test_end() {
9619 yml_log_sub_test_end "$@" >> $YAML_LOG
9625 local llverdev_opts="$*"
9626 local devname=$(basename $dev)
9627 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
9628 # loop devices aren't in /proc/partitions
9629 [[ -z "$size" ]] && size=$(stat -c %s $dev)
9631 local size_gb=$((size / 1024 / 1024)) # Gb
9633 local partial_arg=""
9634 # Run in partial (fast) mode if the size of a partition > 1 GB
9635 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
9637 llverdev --force $partial_arg $llverdev_opts $dev
9643 local llverfs_opts=$2
9644 local use_partial_arg=$3
9645 local partial_arg=""
9646 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
9648 # Run in partial (fast) mode if the size of a partition > 1 GB
9649 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
9651 llverfs $partial_arg $llverfs_opts $dir
9655 local devs=${1//,/ }
9658 local rslt=$TMP/sgpdd_survey
9660 # sgpdd-survey cleanups ${rslt}.* files
9662 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
9668 # returns the canonical name for an ldiskfs device
9673 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
9674 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
9675 echo dm-\\\${foo##*:};
9677 name=\\\$(basename \\\$dv);
9678 if [[ \\\$name = *flakey* ]]; then
9679 name=\\\$(lsblk -o NAME,KNAME |
9680 awk /\\\$name/'{print \\\$NF}');
9686 is_sanity_benchmark() {
9687 local benchmarks="dbench bonnie iozone fsx"
9690 for b in $benchmarks; do
9691 if [ "$b" == "$suite" ]; then
9699 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
9703 # Get the available size (KB) of a given obd target.
9710 [[ $facet != client ]] || return 0
9712 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
9717 # Get the page size (bytes) on a given facet node.
9718 # The local client page_size is directly available in PAGE_SIZE.
9722 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
9724 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
9725 page_size=$(do_facet $facet getconf PAGE_SIZE)
9726 echo -n ${page_size:-4096}
9730 # Get the block count of the filesystem.
9737 [ -z "$CLIENTONLY" ] &&
9738 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
9739 awk '/^Block count:/ {print $3}')
9743 # Check whether the "ea_inode" feature is enabled or not, to allow
9744 # ldiskfs xattrs over one block in size. Allow both the historical
9745 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
9746 large_xattr_enabled() {
9747 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
9749 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
9751 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
9752 grep -E -q '(ea_inode|large_xattr)'"
9753 return ${PIPESTATUS[0]}
9756 # Get the maximum xattr size supported by the filesystem.
9758 $LCTL get_param -n llite.*.max_easize
9761 # Dump the value of the named xattr from a file.
9766 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9769 # Generate a string with size of $size bytes.
9771 local size=${1:-1024} # in bytes
9773 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9776 reformat_external_journal() {
9781 local varbs=${facet}_BLOCKSIZE
9782 if [ -n "${!var}" ]; then
9783 local rcmd="do_facet $facet"
9784 local bs=${!varbs:-$BLCKSIZE}
9787 echo "reformat external journal on $facet:${!var}"
9788 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9792 # MDT file-level backup/restore
9793 mds_backup_restore() {
9796 local devname=$(mdsdevname $(facet_number $facet))
9797 local mntpt=$(facet_mntpt brpt)
9798 local rcmd="do_facet $facet"
9799 local metadata=${TMP}/backup_restore.tgz
9800 local opts=${MDS_MOUNT_FS_OPTS}
9801 local svc=${facet}_svc
9803 if ! ${rcmd} test -b ${devname}; then
9804 opts=$(csa_add "$opts" -o loop)
9807 echo "file-level backup/restore on $facet:${devname}"
9809 # step 1: build mount point
9810 ${rcmd} mkdir -p $mntpt
9811 # step 2: cleanup old backup
9812 ${rcmd} rm -f $metadata
9814 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9815 if [ ! -z $igif ]; then
9816 # step 3.5: rm .lustre
9817 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9819 # step 4: backup metadata
9821 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9822 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9824 ${rcmd} $UMOUNT $mntpt || return 5
9825 # step 6: reformat dev
9826 echo "reformat new device"
9827 format_mdt $(facet_number $facet)
9829 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9830 # step 8: restore metadata
9832 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9833 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9834 # step 9: remove recovery logs
9835 echo "remove recovery logs"
9836 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9837 # step 10: umount dev
9838 ${rcmd} $UMOUNT $mntpt || return 10
9839 # step 11: cleanup tmp backup
9840 ${rcmd} rm -f $metaea $metadata
9841 # step 12: reset device label - it's not virgin on
9842 ${rcmd} e2label $devname ${!svc}
9849 local devname=$(mdsdevname $(facet_number $facet))
9850 local mntpt=$(facet_mntpt brpt)
9851 local rcmd="do_facet $facet"
9852 local opts=${MDS_MOUNT_FS_OPTS}
9854 if ! ${rcmd} test -b ${devname}; then
9855 opts=$(csa_add "$opts" -o loop)
9858 echo "removing OI files on $facet: idx=${idx}"
9860 # step 1: build mount point
9861 ${rcmd} mkdir -p $mntpt
9863 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9864 if [ -z $idx ]; then
9865 # step 3: remove all OI files
9866 ${rcmd} rm -fv $mntpt/oi.16*
9867 elif [ $idx -lt 2 ]; then
9868 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9872 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9873 for ((i=${idx}; i<64; i=$((i * idx)))); do
9874 ${rcmd} rm -fv $mntpt/oi.16.${i}
9878 ${rcmd} $UMOUNT $mntpt || return 2
9879 # OI files will be recreated when mounted as lustre next time.
9882 # generate maloo upload-able log file name
9883 # \param logname specify unique part of file name
9884 generate_logname() {
9885 local logname=${1:-"default_logname"}
9887 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9890 # make directory on different MDTs
9895 local hash_name=("all_char" "fnv_1a_64" "crush")
9896 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9897 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9899 local overstripe_count
9900 local stripe_command="-c"
9902 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9903 hash_name+=("crush2")
9905 while getopts "c:C:H:i:p" opt; do
9907 c) dirstripe_count=$OPTARG;;
9908 C) overstripe_count=$OPTARG;;
9909 H) hash_type=$OPTARG;;
9910 i) dirstripe_index=$OPTARG;;
9912 \?) error "only support -c -H -i -p";;
9916 shift $((OPTIND - 1))
9917 [ $# -eq 1 ] || error "Only creating single directory is supported"
9920 local parent=$(dirname $path)
9921 if [ "$p_option" == "-p" ]; then
9922 [ -d $path ] && return 0
9923 if [ ! -d ${parent} ]; then
9924 mkdir -p ${parent} ||
9925 error "mkdir parent '$parent' failed"
9929 if [[ -n "$overstripe_count" ]]; then
9931 dirstripe_count=$overstripe_count
9934 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9935 mkdir $path || error "mkdir '$path' failed"
9939 if [ $dirstripe_index -eq -1 ]; then
9940 mdt_index=$((base % MDSCOUNT))
9942 mdt_index=$dirstripe_index
9945 # randomly choose hash type
9946 [ -z "$hash_type" ] &&
9947 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9949 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9950 if [ $dirstripe_count -eq -1 ]; then
9951 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9957 echo "striped dir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path"
9958 $LFS mkdir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path ||
9959 error "mkdir -i $mdt_index $stripe_command$dirstripe_count -H $hash_type $path failed"
9963 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9965 # If called many times, passing @last_fd will avoid repeated searching
9966 # already-open FDs repeatedly if we know they are still in use.
9968 # usage: free_fd [last_fd]
9971 local max_fd=$(ulimit -n)
9972 local fd=$((${1:-2} + 1))
9974 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9977 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9981 check_mount_and_prep()
9983 is_mounted $MOUNT || setupall
9985 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9986 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9987 for idx in $(seq $MDSCOUNT); do
9988 local name="MDT$(printf '%04x' $((idx - 1)))"
9989 rm -rf $MOUNT/.lustre/lost+found/$name/*
9993 # calcule how many ost-objects to be created.
9994 precreated_ost_obj_count()
9998 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9999 local ost_name="OST$(printf '%04x' $ost_idx)"
10000 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
10001 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10002 osp.$proc_path.prealloc_last_id)
10003 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
10004 osp.$proc_path.prealloc_next_id)
10005 echo $((last_id - next_id + 1))
10008 check_file_in_pool()
10013 local res=$($LFS getstripe $file | grep 0x | cut -f2)
10016 for t in $tlist ; do
10017 [ "$i" -eq "$t" ] && continue 2
10020 echo "pool list: $tlist"
10021 echo "striping: $res"
10022 error_noexit "$file not allocated in $pool"
10029 echo "Creating new pool"
10032 create_pool $FSNAME.$pool ||
10033 { error_noexit "No pool created, result code $?"; return 1; }
10034 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
10035 { error_noexit "$pool not in lfs pool_list"; return 2; }
10038 pool_add_targets() {
10039 echo "Adding targets to pool"
10042 local last=${3:-$first}
10045 local list=$(seq $first $step $last)
10047 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10048 local tg=$(for i in $list;
10049 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
10050 local firstx=$(printf "%04x" $first)
10051 local lastx=$(printf "%04x" $last)
10053 do_facet mgs $LCTL pool_add \
10054 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
10055 # ignore EEXIST(17)
10056 if (( $? != 0 && $? != 17 )); then
10057 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
10061 # wait for OSTs to be added to the pool
10062 for mds_id in $(seq $MDSCOUNT); do
10063 local mdt_id=$((mds_id-1))
10064 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10065 wait_update_facet mds$mds_id \
10066 "lctl get_param -n lod.$lodname.pools.$pool |
10067 grep $tg | sort -u | tr '\n' ' '" "$t" || {
10068 error_noexit "mds$mds_id: Add to pool failed"
10072 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
10073 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
10074 error_noexit "Add to pool failed"
10082 echo "Setting pool on directory $tdir"
10084 $LFS setstripe -c 2 -p $pool $tdir && return 0
10086 error_noexit "Cannot set pool $pool to $tdir"
10093 echo "Checking pool on directory $tdir"
10095 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
10096 [ "$res" = "$pool" ] && return 0
10098 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10102 pool_dir_rel_path() {
10103 echo "Testing relative path works well"
10108 mkdir -p $root/$tdir/$tdir
10110 pool_set_dir $pool $tdir || return 1
10111 pool_set_dir $pool ./$tdir || return 2
10112 pool_set_dir $pool ../$tdir || return 3
10113 pool_set_dir $pool ../$tdir/$tdir || return 4
10114 rm -rf $tdir; cd - > /dev/null
10117 pool_alloc_files() {
10118 echo "Checking files allocation from directory pool"
10125 for i in $(seq -w 1 $count)
10127 local file=$tdir/file-$i
10129 check_file_in_pool $file $pool "$tlist" || \
10130 failed=$((failed + 1))
10132 [ "$failed" = 0 ] && return 0
10134 error_noexit "$failed files not allocated in $pool"
10138 pool_create_files() {
10139 echo "Creating files in pool"
10147 for i in $(seq -w 1 $count)
10149 local file=$tdir/spoo-$i
10150 $LFS setstripe -p $pool $file
10151 check_file_in_pool $file $pool "$tlist" || \
10152 failed=$((failed + 1))
10154 [ "$failed" = 0 ] && return 0
10156 error_noexit "$failed files not allocated in $pool"
10161 echo "Checking 'lfs df' output"
10164 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10166 local res=$($LFS df --pool $FSNAME.$pool |
10168 grep "$FSNAME-OST" |
10170 [ "$res" = "$t" ] && return 0
10172 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10176 pool_file_rel_path() {
10177 echo "Creating files in a pool with relative pathname"
10182 { error_noexit "unable to create $tdir"; return 1 ; }
10183 local file="/..$tdir/$tfile-1"
10184 $LFS setstripe -p $pool $file ||
10185 { error_noexit "unable to create $file" ; return 2 ; }
10188 $LFS setstripe -p $pool $tfile-2 || {
10189 error_noexit "unable to create $tfile-2 in $tdir"
10194 pool_remove_first_target() {
10195 echo "Removing first target from a pool"
10196 pool_remove_target $1 -1
10199 pool_remove_target() {
10203 local pname="lov.$FSNAME-*.pools.$pool"
10204 if [ $index -eq -1 ]; then
10205 local t=$($LCTL get_param -n $pname | head -1)
10207 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
10210 echo "Removing $t from $pool"
10211 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10212 for mds_id in $(seq $MDSCOUNT); do
10213 local mdt_id=$((mds_id-1))
10214 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10215 wait_update_facet mds$mds_id \
10216 "lctl get_param -n lod.$lodname.pools.$pool |
10218 error_noexit "mds$mds_id: $t not removed from" \
10223 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10224 error_noexit "$t not removed from $FSNAME.$pool"
10229 pool_remove_all_targets() {
10230 echo "Removing all targets from pool"
10233 local pname="lov.$FSNAME-*.pools.$pool"
10234 for t in $($LCTL get_param -n $pname | sort -u)
10236 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10238 for mds_id in $(seq $MDSCOUNT); do
10239 local mdt_id=$((mds_id-1))
10240 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
10241 wait_update_facet mds$mds_id "lctl get_param -n \
10242 lod.$lodname.pools.$pool" "" || {
10243 error_noexit "mds$mds_id: Pool $pool not drained"
10247 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10248 error_noexit "Pool $FSNAME.$pool cannot be drained"
10251 # striping on an empty/nonexistant pool should fall back
10252 # to "pool of everything"
10254 error_noexit "failed to use fallback striping for empty pool"
10257 # setstripe on an empty pool should fail
10258 $LFS setstripe -p $pool $file 2>/dev/null && {
10259 error_noexit "expected failure when creating file" \
10267 echo "Destroying pool"
10271 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10274 # striping on an empty/nonexistant pool should fall back
10275 # to "pool of everything"
10277 error_noexit "failed to use fallback striping for missing pool"
10280 # setstripe on an empty pool should fail
10281 $LFS setstripe -p $pool $file 2>/dev/null && {
10282 error_noexit "expected failure when creating file" \
10283 "with missing pool"
10287 # get param should return err once pool is gone
10288 if wait_update $HOSTNAME "lctl get_param -n \
10289 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10291 remove_pool_from_list $FSNAME.$pool
10294 error_noexit "Pool $FSNAME.$pool is not destroyed"
10298 # Get and check the actual stripe count of one file.
10299 # Usage: check_stripe_count <file> <expected_stripe_count>
10300 check_stripe_count() {
10305 [[ -z "$file" || -z "$expected" ]] &&
10306 error "check_stripe_count: invalid argument"
10308 local cmd="$LFS getstripe -c $file"
10309 actual=$($cmd) || error "$cmd failed"
10310 actual=${actual%% *}
10312 if [[ $actual -ne $expected ]]; then
10313 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
10314 error "$cmd not expected ($expected): found $actual"; }
10315 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
10316 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
10320 # Get and check the actual list of OST indices on one file.
10321 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
10327 [[ -z "$file" || -z "$expected" ]] &&
10328 error "check_obdidx: invalid argument!"
10330 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
10331 grep -v obdidx | awk '{print $1}' | xargs))
10333 [[ $obdidx = $expected ]] ||
10334 error "list of OST indices on $file is $obdidx," \
10335 "should be $expected"
10338 # Get and check the actual OST index of the first stripe on one file.
10339 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
10340 check_start_ost_idx() {
10343 local start_ost_idx
10345 [[ -z "$file" || -z "$expected" ]] &&
10346 error "check_start_ost_idx: invalid argument!"
10348 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
10349 grep -v obdidx | awk '{print $1}')
10351 [[ $start_ost_idx = $expected ]] ||
10352 error "OST index of the first stripe on $file is" \
10353 "$start_ost_idx, should be $expected"
10356 killall_process () {
10357 local clients=${1:-$(hostname)}
10362 do_nodes $clients "killall $signal $name"
10367 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
10370 lsnapshot_destroy()
10372 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
10377 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
10382 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
10387 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
10392 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
10399 do_facet mgs "cat $LSNAPSHOT_LOG"
10405 echo "Cleaning test environment ..."
10407 # Every lsnapshot command takes exclusive lock with others,
10408 # so can NOT destroy the snapshot during list with 'xargs'.
10410 local ssname=$(lsnapshot_list | grep snapshot_name |
10411 grep lss_ | awk '{ print $2 }' | head -n 1)
10412 [ -z "$ssname" ] && break
10414 lsnapshot_destroy -n $ssname -f ||
10415 lss_err "Fail to destroy $ssname by force"
10425 local host=$(facet_active_host $facet)
10426 local dir=$(dirname $(facet_vdevice $facet))
10427 local pool=$(zpool_name $facet)
10428 local lfsname=$(zfs_local_fsname $facet)
10429 local label=${FSNAME}-${role}$(printf '%04x' $idx)
10432 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
10438 do_facet mgs "rm -f $LSNAPSHOT_CONF"
10439 echo "Generating $LSNAPSHOT_CONF on MGS ..."
10441 if ! combined_mgs_mds ; then
10442 [ $(facet_fstype mgs) != zfs ] &&
10443 skip "Lustre snapshot 1 only works for ZFS backend"
10445 local host=$(facet_active_host mgs)
10446 local dir=$(dirname $(facet_vdevice mgs))
10447 local pool=$(zpool_name mgs)
10448 local lfsname=$(zfs_local_fsname mgs)
10451 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
10452 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
10455 for num in `seq $MDSCOUNT`; do
10456 [ $(facet_fstype mds$num) != zfs ] &&
10457 skip "Lustre snapshot 1 only works for ZFS backend"
10459 lss_gen_conf_one mds$num MDT $((num - 1)) ||
10460 lss_err "generate lss conf (mds$num)"
10463 for num in `seq $OSTCOUNT`; do
10464 [ $(facet_fstype ost$num) != zfs ] &&
10465 skip "Lustre snapshot 1 only works for ZFS backend"
10467 lss_gen_conf_one ost$num OST $((num - 1)) ||
10468 lss_err "generate lss conf (ost$num)"
10471 do_facet mgs "cat $LSNAPSHOT_CONF"
10474 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
10475 parse_plain_dir_param()
10477 local invalues=($1)
10480 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
10481 param="-c ${invalues[1]}"
10483 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
10484 param="$param -S ${invalues[3]}"
10486 if [[ ${invalues[4]} =~ "pattern:" ]]; then
10487 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
10488 param="$param -i ${invalues[6]}"
10490 param="$param -L ${invalues[5]} -i ${invalues[7]}"
10492 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
10493 param="$param -i ${invalues[5]}"
10498 parse_plain_param()
10501 local val=$(awk '{print $2}' <<< $line)
10503 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
10505 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
10507 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
10509 elif [[ $line =~ ^"lmm_pattern:" ]]; then
10514 parse_layout_param()
10520 while read line; do
10521 if [[ ! -z $line ]]; then
10522 if [[ -z $mode ]]; then
10523 if [[ $line =~ ^"stripe_count:" ]]; then
10525 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
10527 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
10532 if [[ $mode = "plain_dir" ]]; then
10533 param=$(parse_plain_dir_param "$line")
10534 elif [[ $mode = "plain_file" ]]; then
10535 val=$(parse_plain_param "$line")
10536 [[ ! -z $val ]] && param="$param $val"
10537 elif [[ $mode = "pfl" ]]; then
10538 val=$(echo $line | awk '{print $2}')
10539 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
10540 if [[ $val = "EOF" ]]; then
10541 param="$param -E -1"
10543 param="$param -E $val"
10545 elif [[ $line =~ ^"stripe_count:" ]]; then
10547 val=$(parse_plain_dir_param "$line")
10548 param="$param $val"
10551 val=$(parse_plain_param "$line")
10552 [[ ! -z $val ]] && param="$param $val"
10562 local param=$($LFS getstripe -d $1 | parse_layout_param)
10566 lfsck_verify_pfid()
10571 # Cancel locks before setting lfsck_verify_pfid so that errors are more
10573 cancel_lru_locks mdc
10574 cancel_lru_locks osc
10576 # make sure PFID is set correctly for files
10577 do_nodes $(comma_list $(osts_nodes)) \
10578 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
10581 cat $f &> /dev/nullA ||
10582 { rc=$?; echo "verify $f failed"; break; }
10585 do_nodes $(comma_list $(osts_nodes)) \
10586 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
10590 # check that clients "oscs" was evicted after "before"
10591 check_clients_evicted() {
10598 for osc in $oscs; do
10599 echo "Check state for $osc"
10600 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
10601 tail -n 5 | awk -F"[ ,]" \
10602 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
10603 if (($? == 0)) && (($evicted > $before)); then
10604 echo "$osc is evicted at $evicted"
10607 echo "$osc was not evicted after $before:"
10608 do_facet client $LCTL get_param osc.$osc.state |
10613 [ $rc -eq 0 ] || error "client not evicted from OST"
10616 # check that clients OSCS current_state is FULL
10617 check_clients_full() {
10622 for osc in $oscs; do
10623 wait_update_facet client \
10624 "lctl get_param -n osc.$osc.state |
10625 grep 'current_state: FULL'" \
10626 "current_state: FULL" $timeout
10627 [ $? -eq 0 ] || error "$osc state is not FULL"
10632 __changelog_deregister() {
10634 local mdt="$(facet_svc $facet)"
10638 # skip cleanup if no user registered for this MDT
10639 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
10640 # user is no longer registered, skip cleanup
10641 changelog_users "$facet" | grep -q "$cl_user" ||
10642 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
10644 # From this point, if any operation fails, it is an error
10645 __changelog_clear $facet $cl_user 0 ||
10646 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
10647 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
10648 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
10651 declare -Ax CL_USERS
10652 changelog_register() {
10653 for M in $(seq $MDSCOUNT); do
10655 local mdt="$(facet_svc $facet)"
10658 cl_mask=$(do_facet $facet $LCTL get_param \
10659 mdd.${mdt}.changelog_mask -n)
10660 stack_trap "do_facet $facet $LCTL \
10661 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
10662 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
10663 error "$mdt: changelog_mask=+hsm failed: $?"
10666 cl_user=$(do_facet $facet $LCTL --device $mdt \
10667 changelog_register -n "$@") ||
10668 error "$mdt: register changelog user failed: $?"
10669 stack_trap "__changelog_deregister $facet $cl_user" EXIT
10671 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
10672 # Bash does not support nested arrays, but the format of a
10673 # cl_user is constrained enough to use whitespaces as separators
10674 CL_USERS[$facet]+="$cl_user "
10676 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[*]% }'"
10679 changelog_deregister() {
10681 # bash assoc arrays do not guarantee to list keys in created order
10682 # so reorder to get same order than in changelog_register()
10683 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10686 for facet in $cl_facets; do
10687 for cl_user in ${CL_USERS[$facet]}; do
10688 __changelog_deregister $facet $cl_user || return $?
10690 unset CL_USERS[$facet]
10694 changelog_users() {
10696 local service=$(facet_svc $facet)
10698 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
10701 changelog_user_rec() {
10704 local service=$(facet_svc $facet)
10706 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
10709 changelog_chmask() {
10712 do_nodes $(comma_list $(mdts_nodes)) \
10713 $LCTL set_param mdd.*.changelog_mask="$mask"
10716 # usage: __changelog_clear FACET CL_USER [+]INDEX
10717 __changelog_clear()
10720 local mdt="$(facet_svc $facet)"
10726 # Remove the leading '+'
10728 rec+=$(changelog_user_rec $facet $cl_user)
10735 if [ $rec -eq 0 ]; then
10736 echo "$mdt: clear the changelog for $cl_user of all records"
10738 echo "$mdt: clear the changelog for $cl_user to record #$rec"
10740 $LFS changelog_clear $mdt $cl_user $rec
10743 # usage: changelog_clear [+]INDEX [facet]...
10745 # If INDEX is prefixed with '+', increment every changelog user's record index
10746 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
10748 changelog_clear() {
10752 local cl_facets="$@"
10753 # bash assoc arrays do not guarantee to list keys in created order
10754 # so reorder to get same order than in changelog_register()
10755 [[ -n "$cl_facets" ]] ||
10756 cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10760 for facet in $cl_facets; do
10761 for cl_user in ${CL_USERS[$facet]}; do
10762 __changelog_clear $facet $cl_user $idx || rc=${rc:-$?}
10772 for M in $(seq $MDSCOUNT); do
10774 local mdt="$(facet_svc $facet)"
10778 output=$($LFS changelog $mdt)
10780 if [ $ret -ne 0 ]; then
10782 elif [ -n "$output" ]; then
10783 echo "$output" | sed -e 's/^/'$mdt'./'
10790 changelog_extract_field() {
10793 local identifier=$3
10795 changelog_dump | gawk "/$cltype.*$file$/ {
10796 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10800 # Prints a changelog record produced by "lfs changelog" as an associative array
10803 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
10804 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
10805 # nid=0@lo p=[0x200000007:0x1:0x0] blob
10806 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
10807 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
10808 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
10809 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
10811 # Note that the changelog record is not quoted
10812 # Also note that the line breaks in the output were only added for readability
10814 # Typically, you want to eval the output of the command to fill an actual
10815 # associative array, like this:
10816 # $> eval declare -A changelog=$(changelog2array $entry)
10818 # It can then be accessed like any bash associative array:
10819 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
10821 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10829 # A changelog, as printed by "lfs changelog" typically looks like this:
10830 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10832 # Parse the positional part of the changelog
10834 # changelog_dump() prefixes records with their mdt's name
10835 local index="${1##*.}"
10837 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10838 "$index" "${2:2}" "$3" "$4" "$5"
10840 # Parse the key/value part of the changelog
10841 for arg in "${@:5}"; do
10842 # Check it matches a key=value syntax
10843 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10845 local key="${arg%%=*}"
10846 local value="${arg#*=}"
10850 # u is actually for uid AND gid: u=UID:GID
10851 printf " [uid]='%s'" "${value%:*}"
10853 value="${value#*:}"
10881 printf " ['%s']='%s'" "$key" "$value"
10888 # Format and print a changelog record
10890 # Interpreted sequences are:
10892 # %f the "flags" attribute of a changelog record
10893 __changelog_printf()
10898 for ((i = 0; i < ${#format}; i++)); do
10899 local char="${format:$i:1}"
10900 if [ "$char" != % ]; then
10901 printf '%c' "$char"
10906 char="${format:$i:1}"
10909 printf '%s' "${changelog[flags]}"
10919 # Filter changelog records
10923 local action='print'
10926 while [ $# -gt 0 ]; do
10937 filter[${1#-}]="$2"
10946 changelog_dump | { while read -r record; do
10947 eval local -A changelog=$(changelog2array $record)
10948 for key in "${!filter[@]}"; do
10951 [ "${changelog[$key]}" == "${filter[$key]}" ]
10958 case "${action:-print}" in
10960 printf '%s\n' "$record"
10963 __changelog_printf "$format"
10973 [ ! -d "$dir" ] && return
10975 [ -z "$layout" ] && {
10976 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
10980 setfattr -n trusted.lov -v $layout $dir ||
10981 error "error restoring layout '$layout' to '$dir'"
10984 # save the layout of a directory, the returned string will be used by
10985 # restore_layout() to restore the layout
10988 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
10989 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
10993 # save layout of a directory and restore it at exit
10994 save_layout_restore_at_exit() {
10996 local layout=$(save_layout $dir)
10998 stack_trap "restore_layout $dir $layout" EXIT
11001 verify_yaml_layout() {
11005 local msg_prefix=$4
11007 echo "getstripe --yaml $src"
11008 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
11009 echo "setstripe --yaml=$temp $dst"
11010 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
11013 local layout1=$(get_layout_param $src)
11014 local layout2=$(get_layout_param $dst)
11015 # compare their layout info
11016 [ "$layout1" == "$layout2" ] ||
11017 error "$msg_prefix $src/$dst layouts are not equal"
11020 is_project_quota_supported() {
11021 $ENABLE_PROJECT_QUOTAS || return 1
11022 [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
11023 local save_project_supported=1
11025 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
11026 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
11027 do_facet mds1 lfs --list-commands |& grep -q project &&
11028 save_project_supported=0
11030 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
11031 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
11032 do_facet mds1 $ZPOOL get all | grep -q project_quota &&
11033 save_project_supported=0
11035 # cache state of project quotas once instead of re-checking each time
11036 export SAVE_PROJECT_SUPPORTED=$save_project_supported
11037 echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
11039 return $save_project_supported
11042 # ZFS project quota enable/disable:
11043 # This feature will become active as soon as it is enabled and will never
11044 # return to being disabled. Each filesystem will be upgraded automatically
11045 # when remounted or when [a] new file is created under that filesystem. The
11046 # upgrade can also be triggered on filesystems via `zfs set version=current
11047 # <pool/fs>`. The upgrade process runs in the background and may take a
11048 # while to complete for the filesystems containing a large number of files.
11049 enable_project_quota() {
11050 is_project_quota_supported || return 0
11051 local zkeeper=${KEEP_ZPOOL}
11052 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
11054 stopall || error "failed to stopall (1)"
11056 local zfeat_en="feature@project_quota=enabled"
11057 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
11058 local facet_fstype=${facet:0:3}1_FSTYPE
11061 if [ "${!facet_fstype}" = "zfs" ]; then
11062 devname=$(zpool_name ${facet})
11063 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
11064 error "$ZPOOL set $zfeat_en $devname"
11066 [ ${facet:0:3} == "mds" ] &&
11067 devname=$(mdsdevname ${facet:3}) ||
11068 devname=$(ostdevname ${facet:3})
11069 do_facet ${facet} $TUNE2FS -O project $devname ||
11070 error "tune2fs $devname failed"
11074 KEEP_ZPOOL="${zkeeper}"
11079 disable_project_quota() {
11080 is_project_quota_supported || return 0
11081 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
11082 stopall || error "failed to stopall (1)"
11084 for num in $(seq $MDSCOUNT); do
11085 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
11086 error "tune2fs $(mdsdevname $num) failed"
11089 for num in $(seq $OSTCOUNT); do
11090 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
11091 error "tune2fs $(ostdevname $num) failed"
11099 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
11100 # the following associated variables are added:
11102 # AGTCOUNT: number of agents
11103 # AGTDEV{N}: target HSM mount point (root path of the backend)
11104 # agt{N}_HOST: hostname of the agent agt{N}
11105 # SINGLEAGT: facet of the single agent
11107 # The number of agents is initialized as the number of remote client nodes.
11108 # By default, only single copytool is started on a remote client/agent. If there
11109 # was no remote client, then the copytool will be started on the local client.
11115 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
11116 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
11118 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
11119 if [[ $CLIENTCOUNT -gt 1 ]] &&
11120 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
11121 skip_env "SHARED_DIRECTORY should be accessible"\
11122 "on all client nodes"
11126 # We used to put the HSM archive in $SHARED_DIRECTORY but that
11127 # meant NFS issues could hose sanity-hsm sessions. So now we
11128 # use $TMP instead.
11129 for n in $(seq $AGTCOUNT); do
11130 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
11131 agent=CLIENT$((n + 1))
11132 if [[ -z "${!agent}" ]]; then
11133 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
11136 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
11137 local var=agt${n}_HOST
11138 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
11141 export SINGLEAGT=${SINGLEAGT:-agt1}
11143 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
11144 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
11145 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
11146 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
11147 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
11148 export HSMTOOL_TESTDIR
11149 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
11151 if ! [[ $HSMTOOL =~ hsmtool ]]; then
11152 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
11155 HSM_ARCHIVE_NUMBER=2
11157 # The test only support up to 10 MDTs
11158 MDT_PREFIX="mdt.$FSNAME-MDT000"
11159 HSM_PARAM="${MDT_PREFIX}0.hsm"
11161 # archive is purged at copytool setup
11162 HSM_ARCHIVE_PURGE=true
11164 # Don't allow copytool error upon start/setup
11165 HSMTOOL_NOERROR=false
11168 # Get the backend root path for the given agent facet.
11169 copytool_device() {
11171 local dev=AGTDEV$(facet_number $facet)
11176 get_mdt_devices() {
11178 # get MDT device for each mdc
11179 for mdtno in $(seq 1 $MDSCOUNT); do
11180 local idx=$(($mdtno - 1))
11181 MDT[$idx]=$($LCTL get_param -n \
11182 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
11183 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
11187 pkill_copytools() {
11191 do_nodes "$hosts" \
11192 "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
11195 copytool_continue() {
11196 local agents=${1:-$(facet_active_host $SINGLEAGT)}
11198 pkill_copytools "$agents" CONT || return 0
11199 echo "Copytool is continued on $agents"
11203 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
11205 echo "Killing existing copytools on $hosts"
11206 pkill_copytools "$hosts" TERM || return 0
11207 copytool_continue "$hosts"
11210 copytool_monitor_cleanup() {
11211 local facet=${1:-$SINGLEAGT}
11212 local agent=$(facet_active_host $facet)
11214 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
11215 # Should die when the copytool dies, but just in case.
11216 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
11217 cmd+=" 2>/dev/null || true"
11218 do_node $agent "$cmd"
11219 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
11220 export HSMTOOL_MONITOR_DIR=
11223 # The pdsh should die on its own when the monitor dies. Just
11224 # in case, though, try to clean up to avoid any cruft.
11225 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
11226 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
11227 export HSMTOOL_MONITOR_PDSH=
11233 local host="$(facet_host "$1")"
11234 local prefix=$TESTLOG_PREFIX
11235 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
11237 printf "${prefix}.copytool${archive_id}_log.${host}.log"
11240 __lhsmtool_rebind()
11242 do_facet $facet $HSMTOOL \
11243 "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
11246 __lhsmtool_import()
11248 mkdir -p "$(dirname "$2")" ||
11249 error "cannot create directory '$(dirname "$2")'"
11250 do_facet $facet $HSMTOOL \
11251 "${hsmtool_options[@]}" --import "$@" "$mountpoint"
11256 local host="$(facet_host "$facet")"
11257 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
11259 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
11260 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
11261 # [ ${#misc_options[@]} -gt 0 ] &&
11262 # cmd+=" $(IFS=" " echo "$@")"
11263 cmd+=" $@ \"$mountpoint\""
11265 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
11266 stack_trap "pkill_copytools $host TERM || true" EXIT
11267 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
11271 local facet="${1:-$SINGLEAGT}"
11273 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
11276 # Main entry point to perform copytool related operations
11280 # setup setup a copytool to run in the background, that copytool will be
11282 # import import a file from an HSM backend
11283 # rebind rebind an archived file to a new fid
11285 # Although the semantics might suggest otherwise, one does not need to 'setup'
11286 # a copytool before a call to 'copytool import' or 'copytool rebind'.
11293 # Use default values
11294 local facet=$SINGLEAGT
11295 local mountpoint="${MOUNT2:-$MOUNT}"
11298 local fail_on_error=true
11299 local -a hsmtool_options=()
11300 local -a action_options=()
11302 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
11303 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
11306 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
11307 hsmtool_options+=("$HSMTOOL_VERBOSE")
11310 while [ $# -gt 0 ]; do
11322 local archive_id="$1"
11326 local hsm_root="$1"
11330 local bandwidth="$1" # in MB/s
11333 local fail_on_error=false
11336 # Uncommon(/copytool dependent) option
11337 action_options+=("$1")
11343 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
11344 hsmtool_options+=("--hsm-root=$hsm_root")
11346 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
11347 do_facet $facet mkdir -p "$hsm_root" ||
11348 error "mkdir '$hsm_root' failed"
11352 local copytool=lhsmtool
11356 __${copytool}_${action} "${action_options[@]}"
11357 if [ $? -ne 0 ]; then
11362 local host="$(facet_host $facet)"
11363 error_msg="Failed to start copytool $facet on '$host'"
11366 local src="${action_options[0]}"
11367 local dest="${action_options[1]}"
11368 error_msg="Failed to import '$src' to '$dest'"
11371 error_msg="could not rebind file"
11375 $fail_on_error && error "$error_msg" || echo "$error_msg"
11380 local client_count=$1
11381 if [[ $CLIENTCOUNT -lt $client_count ]]; then
11382 skip "Need $client_count or more clients, have $CLIENTCOUNT"
11389 $LFS path2fid $1 | tr -d '[]'
11390 return ${PIPESTATUS[0]}
11398 if [[ $u == "user" ]]; then
11399 st=$($RUNAS $LFS hsm_state $f)
11402 st=$($LFS hsm_state $f)
11405 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
11407 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
11411 check_hsm_flags() {
11415 local st=$(get_hsm_flags $f)
11416 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
11425 if [[ "$value" != "" ]]; then
11428 for mdtno in $(seq 1 $MDSCOUNT); do
11429 local idx=$(($mdtno - 1))
11430 local facet=mds${mdtno}
11431 # if $arg include -P option, run 1 set_param per MDT on the MGS
11432 # else, run set_param on each MDT
11433 [[ $arg = *"-P"* ]] && facet=mgs
11434 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
11435 [[ $? != 0 ]] && rc=1
11440 mdts_check_param() {
11446 for mdtno in $(seq 1 $MDSCOUNT); do
11447 local idx=$(($mdtno - 1))
11448 wait_update_facet --verbose mds${mdtno} \
11449 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
11451 error "$key state is not '$target' on mds${mdtno}"
11455 cdt_set_mount_state() {
11456 mdts_set_param "-P" hsm_control "$1"
11457 # set_param -P is asynchronous operation and could race with set_param.
11458 # In such case configs could be retrieved and applied at mgc after
11459 # set_param -P completion. Sleep here to avoid race with set_param.
11460 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
11461 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
11462 # and 10 seconds to retrieve config from server.
11466 cdt_check_state() {
11467 mdts_check_param hsm_control "$1" 20
11470 cdt_set_sanity_policy() {
11471 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
11474 mdts_set_param "" hsm.policy "+NRA"
11475 mdts_set_param "" hsm.policy "-NBR"
11476 CDT_POLICY_HAD_CHANGED=
11484 mdts_set_param "$opt -n" "hsm.$param" "$value"
11488 wait_request_state() {
11492 # 4th arg (mdt index) is optional
11493 local mdtidx=${4:-0}
11494 local mds=mds$(($mdtidx + 1))
11496 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
11497 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
11499 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
11500 error "request on $fid is not $state on $mds"
11508 local WAIT_MAX=${4:-60}
11511 # We need to run do_node in bg, because pdsh does not exit
11512 # if child process of run script exists.
11513 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
11514 # because of multiop_bg_pause -> $MULTIOP_PROG &
11515 # By the same reason we need sleep a bit after do_nodes starts
11516 # to let runmultiop_bg_pause start muliop and
11517 # update /tmp/multiop_bg.pid ;
11518 # The rm /tmp/multiop_bg.pid guarantees here that
11519 # we have the updated by runmultiop_bg_pause
11520 # /tmp/multiop_bg.pid file
11522 local pid_file=$TMP/multiop_bg.pid.$$
11524 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
11525 runmultiop_bg_pause $file $cmds" &
11529 while [[ $wait_time -lt $WAIT_MAX ]]; do
11531 wait_time=$((wait_time + 3))
11532 multiop_pid=$(do_node $client cat $pid_file)
11533 if [ -n "$multiop_pid" ]; then
11538 [ -n "$multiop_pid" ] ||
11539 error "$client : Can not get multiop_pid from $pid_file "
11541 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
11542 eval export $(node_var_name $client)_do_node_pid=$pid
11543 local var=$(node_var_name $client)_multiop_pid
11544 echo client $client multiop_bg started multiop_pid=${!var}
11550 local multiop_pid=$(node_var_name $client)_multiop_pid
11551 local do_node_pid=$(node_var_name $client)_do_node_pid
11553 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
11554 do_node $client kill -USR1 ${!multiop_pid}
11556 wait ${!do_node_pid}
11560 local delay=$(do_facet mds1 lctl get_param -n lod.*.qos_maxage |
11561 awk '{ print $1 + 5; exit; }')
11565 sleep_maxage_lmv() {
11566 local delay=$(lctl get_param -n lmv.*.qos_maxage |
11567 awk '{ print $1 + 5; exit; }')
11571 check_component_count() {
11572 local comp_cnt=$($LFS getstripe --component-count $1)
11573 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
11576 # Verify there are no init components with "extension" flag
11577 verify_no_init_extension() {
11578 local flg_opts="--component-flags init,extension"
11579 local found=$($LFS find $flg_opts $1 | wc -l)
11580 [ $found -eq 0 ] || error "$1 has component with initialized extension"
11583 # Verify there is at least one component starting at 0
11584 verify_comp_at_zero() {
11585 flg_opts="--component-flags init"
11586 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
11587 [ $found -eq 1 ] ||
11588 error "No component starting at zero(!)"
11591 # version after which Self-Extending Layouts are available
11594 sel_layout_sanity() {
11598 verify_no_init_extension $file
11599 verify_comp_at_zero $file
11600 check_component_count $file $comp_cnt
11603 statx_supported() {
11604 $STATX --quiet --version
11608 # lfs rm_entry is disabled on native client
11609 is_rmentry_supported() {
11610 $LFS rm_entry $DIR/dir/not/exists > /dev/null
11611 # is return code ENOENT?
11616 # wrappers for createmany and unlinkmany
11617 # to set debug=0 if number of creates is high enough
11618 # this is to speedup testing
11620 function createmany() {
11624 if (( count > 100 )); then
11626 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11628 $LUSTRE/tests/createmany $*
11630 debugrestore > /dev/null
11635 function unlinkmany() {
11639 if (( count > 100 )); then
11641 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11643 $LUSTRE/tests/unlinkmany $*
11645 debugrestore > /dev/null
11650 # Check if fallocate on facet is working. Returns fallocate mode if enabled.
11651 # Takes optional facet name as argument, to allow separate MDS/OSS checks.
11652 function check_fallocate_supported()
11654 local facet=${1:-ost1}
11655 local supported="FALLOCATE_SUPPORTED_$facet"
11656 local fstype="${facet}_FSTYPE"
11658 if [[ -n "${!supported}" ]]; then
11659 echo "${!supported}"
11662 if [[ -z "${!fstype}" ]]; then
11663 eval export $fstype=$(facet_fstype $facet)
11665 if [[ "${!fstype}" != "ldiskfs" ]]; then
11666 echo "fallocate on ${!fstype} doesn't consume space" 1>&2
11670 local fa_mode="osd-ldiskfs.$(facet_svc $facet).fallocate_zero_blocks"
11671 local mode=$(do_facet $facet $LCTL get_param -n $fa_mode 2>/dev/null |
11674 if [[ -z "$mode" ]]; then
11675 echo "fallocate not supported on $facet" 1>&2
11678 eval export $supported="$mode"
11684 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable.
11685 # Takes optional facet name as argument.
11686 function check_fallocate_or_skip()
11690 check_fallocate_supported $1 || skip "fallocate not supported"
11693 # Check if fallocate supported on OSTs, enable if unset, default mode=0
11694 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
11695 function check_set_fallocate()
11697 local new_mode="$1"
11698 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
11699 local old_mode="$(check_fallocate_supported)"
11701 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
11702 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
11703 { echo "keep default fallocate mode: $old_mode"; return 0; }
11704 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
11705 { echo "keep current fallocate mode: $old_mode"; return 0; }
11706 local osts=$(comma_list $(osts_nodes))
11708 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
11709 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
11710 error "set $fa_mode=$new_mode"
11713 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
11714 function check_set_fallocate_or_skip()
11716 check_set_fallocate || skip "need >= 2.13.57 and ldiskfs for fallocate"
11719 function disable_opencache()
11721 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" |
11724 test -z "${saved_OPENCACHE_value}" &&
11725 export saved_OPENCACHE_value="$state"
11727 [[ "$state" = "off" ]] && return
11729 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
11732 function set_opencache()
11734 local newvalue="$1"
11735 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
11737 [[ -n "$newvalue" ]] || return
11739 [[ -n "${saved_OPENCACHE_value}" ]] ||
11740 export saved_OPENCACHE_value="$state"
11742 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
11747 function restore_opencache()
11749 [[ -z "${saved_OPENCACHE_value}" ]] ||
11750 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
11753 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
11754 # created on MDT0, use this function to create directory on specific MDT
11755 # explicitly, and set default LMV to create subdirs on the same MDT too.
11760 while getopts "i:" opt $*; do
11766 shift $((OPTIND - 1))
11768 $LFS mkdir -i $mdt -c 1 $*
11772 mkdir_on_mdt -i0 $*
11775 # Wait for nodemap synchronization
11777 local nodemap_name=$1
11782 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
11783 local max_retries=20
11787 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
11790 if [ "$nodemap_name" == "active" ]; then
11791 proc_param="active"
11792 elif [ -z "$key" ]; then
11793 proc_param=${nodemap_name}
11795 proc_param="${nodemap_name}.${key}"
11797 if [ "$opt" == "inactive" ]; then
11798 # check nm sync even if nodemap is not activated
11802 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
11804 if [ -z "$value" ]; then
11805 out1=$(do_facet mgs $LCTL get_param $opt \
11806 nodemap.${proc_param} 2>/dev/null)
11807 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
11812 # if servers run on the same node, it is impossible to tell if they get
11813 # synced with the mgs, so just wait an arbitrary 10 seconds
11814 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
11815 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
11816 echo "waiting 10 secs for sync"
11821 # wait up to 10 seconds for other servers to sync with mgs
11822 for i in $(seq 1 10); do
11823 for node in $(all_server_nodes); do
11824 local node_ip=$(host_nids_address $node $NETTYPE |
11828 if [ -z "$value" ]; then
11829 [ $node_ip == $mgs_ip ] && continue
11832 out2=$(do_node $node $LCTL get_param $opt \
11833 nodemap.$proc_param 2>/dev/null)
11834 echo "On $node ${node_ip}, ${proc_param} = $out2"
11835 [ "$out1" != "$out2" ] && is_sync=false && break
11840 if ! $is_sync; then
11843 echo OTHER - IP: $node_ip
11845 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
11847 echo "waited $((i - 1)) seconds for sync"
11850 consume_precreations() {
11854 local extra=${4:-2}
11855 local OST=$(ostname_from_index $OSTIDX $dir)
11857 mkdir_on_mdt -i $(facet_index $mfacet) $dir/${OST}
11858 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
11861 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11862 local last_id=$(do_facet $mfacet $LCTL get_param -n \
11863 osp.$mdtosc_proc.prealloc_last_id)
11864 local next_id=$(do_facet $mfacet $LCTL get_param -n \
11865 osp.$mdtosc_proc.prealloc_next_id)
11866 echo "Creating to objid $last_id on ost $OST..."
11867 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
11870 __exhaust_precreations() {
11873 local FAILIDX=${3:-$OSTIDX}
11874 local ofacet=ost$((OSTIDX + 1))
11876 mkdir_on_mdt0 $DIR/$tdir
11877 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
11878 local mfacet=mds$((mdtidx + 1))
11879 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
11881 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
11882 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11884 #define OBD_FAIL_OST_ENOSPC 0x215
11885 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
11887 consume_precreations $DIR/$tdir $mfacet $OSTIDX
11889 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11890 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11893 exhaust_precreations() {
11894 __exhaust_precreations $1 $2 $3
11898 exhaust_all_precreations() {
11900 for (( i=0; i < OSTCOUNT; i++ )) ; do
11901 __exhaust_precreations $i $1 -1
11906 force_new_seq_ost() {
11910 local OST=$(ostname_from_index $OSTIDX)
11911 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11913 do_facet $mfacet $LCTL set_param \
11914 osp.$mdtosc_proc.prealloc_force_new_seq=1
11915 # consume preallocated objects, to wake up precreate thread
11916 consume_precreations $dir $mfacet $OSTIDX
11917 do_facet $mfacet $LCTL set_param \
11918 osp.$mdtosc_proc.prealloc_force_new_seq=0
11923 local MDTIDX=$(facet_index $mfacet)
11924 local MDT=$(mdtname_from_index $MDTIDX $DIR)
11927 mkdir_on_mdt -i $MDTIDX $DIR/${MDT}
11928 for (( i=0; i < OSTCOUNT; i++ )) ; do
11929 force_new_seq_ost $DIR/${MDT} $mfacet $i &
11935 force_new_seq_all() {
11938 for (( i=0; i < MDSCOUNT; i++ )) ; do
11939 force_new_seq mds$((i + 1)) &
11945 ost_set_temp_seq_width_all() {
11946 local osts=$(comma_list $(osts_nodes))
11947 local width=$(do_facet ost1 $LCTL get_param -n seq.*OST0000-super.width)
11949 do_nodes $osts $LCTL set_param seq.*OST*-super.width=$1
11950 stack_trap "do_nodes $osts $LCTL set_param seq.*OST*-super.width=$width"
11953 verify_yaml_available() {
11954 python3 -c "import yaml; yaml.safe_load('''a: b''')"
11958 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"
11961 verify_compare_yaml() {
11962 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)"
11965 zfs_or_rotational() {
11967 local ost_name=$(ostname_from_index $ost_idx $MOUNT)
11968 local param="get_param -n osd-*.${ost_name}.nonrotational"
11969 local nonrotat=$(do_facet ost1 $LCTL $param)
11971 if [[ -z "$nonrotat" ]]; then
11972 # At this point there is no point moving ahead.
11973 # Will stop here and dump all the info
11975 local ost_name=$(ostname_from_index $ost_idx)
11977 error "$LCTL $input_str"
11980 if [[ "$ost1_FSTYPE" == "zfs" ]] || (( "$nonrotat" == 0 )); then