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 "eval export" mgs
393 lustre_os_release "eval export" mds1
394 lustre_os_release "eval export" ost1
395 lustre_os_release "eval export" 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() {
776 local action=${1:-echo}
778 local FACET_OS=$(tr "[:lower:]" "[:upper:]" <<<$facet)_OS_
780 [[ "$action" == "echo" ]] &&
781 echo "$facet: $(do_facet $facet "cat /etc/system-release")"
782 do_facet $facet "[[ -r /etc/os-release ]] || ls -s /etc/*release" 1>&2
786 VERSION_ID=*|ID=*|ID_LIKE=*) $action ${FACET_OS}$LINE ;;
788 done < <(do_facet $facet "cat /etc/os-release")
790 [[ "$action" == "echo" ]] && return 0
792 local facet_version=${FACET_OS}VERSION
793 $action ${facet_version}_CODE=\$\(version_code \$${facet_version}_ID\)
797 /sbin/lsmod | grep -q "^\<$1\>"
800 check_lfs_df_ret_val() {
801 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
802 # returned by 'lfs df' for valid dentry but not a lustrefs.
804 # 'lfs df' historically always returned success(0) instead of
805 # EOPNOTSUPP. This function for compatibility reason, ignores and
806 # masquerades EOPNOTSUPP as success.
807 [[ $1 -eq 95 ]] && return 0
820 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
823 # parallels can't load modules directly from prlfs, use /tmp instead
824 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
825 local target="$(mktemp)"
827 cp "$module" "$target"
830 [[ $rc == 0 ]] && PRLFS=true
838 # Load a module on the system where this is running.
840 # usage: load_module module_name [module arguments for insmod/modprobe]
842 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
843 # will be used as the arguments. Otherwise arguments will be obtained from
844 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
847 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
850 local base=$(basename $module $ext)
852 local -A module_is_loaded_aa
856 for mod in $(lsmod | awk '{ print $1; }'); do
857 module_is_loaded_aa[${mod//-/_}]=true
861 ${module_is_loaded_aa[${1//-/_}]:-false}
864 if module_is_loaded $base; then
868 if [[ -f $LUSTRE/$module$ext ]]; then
869 path=$LUSTRE/$module$ext
870 elif [[ "$base" == lnet_selftest ]] &&
871 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
872 path=$LUSTRE/../lnet/selftest/$base$ext
877 if [[ -n "$path" ]]; then
878 # Try to load any non-Lustre modules that $module depends on.
879 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
880 if ! module_is_loaded $mod; then
886 # If no module arguments were passed then get them from
887 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
888 if [ $# -eq 0 ]; then
889 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
890 # not in Bash until 4.x, so we resort to eval.
891 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
892 eval set -- \$$optvar
893 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
894 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
896 opt=$(awk -v var="^options $base" '$0 ~ var \
897 {gsub("'"options $base"'",""); print}' \
899 set -- $(echo -n $opt)
901 # Ensure we have accept=all for lnet
902 if [[ "$base" == lnet ]]; then
903 # OK, this is a bit wordy...
904 local arg accept_all_present=false
907 [[ "$arg" == accept=all ]] &&
908 accept_all_present=true
911 $accept_all_present || set -- "$@" accept=all
918 [ $# -gt 0 ] && echo "${module} options: '$*'"
920 # Note that insmod will ignore anything in modprobe.conf, which is why
921 # we're passing options on the command-line. If $path does not exist
922 # then we must be testing a "make install" or"rpm" installation. Also
923 # note that failing to load ptlrpc_gss is not considered fatal.
924 if [[ -n "$path" ]]; then
925 lustre_insmod $path "$@"
926 elif [[ "$base" == ptlrpc_gss ]]; then
927 if ! modprobe $base "$@" 2>/dev/null; then
928 echo "gss/krb5 is not supported"
936 $LCTL mark "$LNETCTL $*"
942 # For kmemleak-enabled kernels we need clear all past state
943 # that obviously has nothing to do with this Lustre run
944 # Disable automatic memory scanning to avoid perf hit.
945 if [ -f /sys/kernel/debug/kmemleak ] ; then
946 echo scan=off > /sys/kernel/debug/kmemleak || true
947 echo scan > /sys/kernel/debug/kmemleak || true
948 echo clear > /sys/kernel/debug/kmemleak || true
951 echo Loading modules from $LUSTRE
955 if [ -f /sys/devices/system/cpu/online ]; then
956 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
957 echo "detected $ncpus online CPUs by sysfs"
959 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
962 if [ $rc -eq 0 ]; then
963 echo "detected $ncpus online CPUs by getconf"
965 echo "Can't detect number of CPUs"
970 # if there is only one CPU core, libcfs can only create one partition
971 # if there is more than 4 CPU cores, libcfs should create multiple CPU
972 # partitions. So we just force libcfs to create 2 partitions for
973 # system with 2 or 4 cores
974 local saved_opts="$MODOPTS_LIBCFS"
976 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
977 # force to enable multiple CPU partitions
978 echo "Force libcfs to create 2 CPU partitions"
979 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
981 echo "libcfs will create CPU partition based on online CPUs"
984 load_module ../libcfs/libcfs/libcfs
985 # Prevent local MODOPTS_LIBCFS being passed as part of environment
986 # variable to remote nodes
989 set_default_debug "neterror net nettrace malloc"
990 if [ "$1" = "config_on_load=1" ]; then
991 load_module ../lnet/lnet/lnet
993 load_module ../lnet/lnet/lnet "$@"
996 LNDPATH=${LNDPATH:-"../lnet/klnds"}
997 if [ -z "$LNETLND" ]; then
999 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
1000 tcp*) LNETLND="socklnd/ksocklnd" ;;
1001 kfi*) LNETLND="kfilnd/kkfilnd" ;;
1002 gni*) LNETLND="gnilnd/kgnilnd" ;;
1003 *) local lnd="${NETTYPE%%[0-9]}lnd"
1004 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
1005 LNETLND="$lnd/k$lnd" ||
1006 LNETLND="socklnd/ksocklnd"
1009 load_module ../lnet/klnds/$LNETLND
1011 if [ "$1" = "config_on_load=1" ]; then
1012 do_lnetctl lnet configure --all ||
1017 load_modules_local() {
1018 if [ -n "$MODPROBE" ]; then
1020 echo "Using modprobe to load modules"
1024 # Create special udev test rules on every node
1025 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
1026 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
1028 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
1030 udevadm control --reload-rules
1035 load_module obdclass/obdclass
1036 if ! client_only; then
1037 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
1039 load_module ptlrpc/ptlrpc
1040 load_module ptlrpc/gss/ptlrpc_gss
1048 load_module obdecho/obdecho
1049 if ! client_only; then
1050 load_module lfsck/lfsck
1051 [ "$LQUOTA" != "no" ] &&
1052 load_module quota/lquota $LQUOTAOPTS
1053 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
1054 load_module osd-zfs/osd_zfs
1055 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
1056 load_module ../ldiskfs/ldiskfs
1057 load_module osd-ldiskfs/osd_ldiskfs
1062 # don't fail if ost module doesn't exist
1063 load_module ost/ost 2>/dev/null || true;
1069 load_module llite/lustre
1070 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
1072 rm -f $OGDB/ogdb-$HOSTNAME
1073 $LCTL modules > $OGDB/ogdb-$HOSTNAME
1075 # 'mount' doesn't look in $PATH, just sbin
1076 local mount_lustre=$LUSTRE/utils/mount.lustre
1077 if [ -f $mount_lustre ]; then
1078 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1079 if grep -qw "$sbin_mount" /proc/mounts; then
1080 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
1082 if ! grep -qw "$sbin_mount" /proc/mounts; then
1083 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
1084 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
1085 cat <<- EOF > "$sbin_mount"
1088 echo "This $sbin_mount just a mountpoint." 1>&2
1089 echo "It is never supposed to be run." 1>&2
1090 logger -p emerg -- "using stub $sbin_mount $@"
1093 chmod a+x $sbin_mount
1095 mount --bind $mount_lustre $sbin_mount ||
1096 error "can't bind $mount_lustre to $sbin_mount"
1107 # load modules on remote nodes optionally
1108 # lustre-tests have to be installed on these nodes
1109 if $LOAD_MODULES_REMOTE; then
1110 local list=$(comma_list $(remote_nodes_list))
1112 # include failover nodes in case they are not in the list yet
1113 facets=$(get_facets)
1114 for facet in ${facets//,/ }; do
1115 failover=$(facet_failover_host $facet)
1116 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
1117 list="$list,$failover"
1120 if [ -n "$list" ]; then
1121 echo "loading modules on: '$list'"
1122 do_rpc_nodes "$list" load_modules_local
1128 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
1129 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
1131 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
1132 echo "$LEAK_LUSTRE" 1>&2
1133 echo "$LEAK_PORTALS" 1>&2
1134 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
1135 echo "Memory leaks detected"
1136 [ -n "$IGNORE_LEAK" ] &&
1137 { echo "ignoring leaks" && return 0; } || true
1142 unload_modules_local() {
1143 $LUSTRE_RMMOD ldiskfs || return 2
1145 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
1146 rm /etc/udev/rules.d/99-lustre-test.rules
1147 udevadm control --reload-rules
1150 check_mem_leak || return 254
1158 wait_exit_ST client # bug 12845
1160 unload_modules_local || rc=$?
1162 if $LOAD_MODULES_REMOTE; then
1163 local list=$(comma_list $(remote_nodes_list))
1164 if [ -n "$list" ]; then
1165 echo "unloading modules on: '$list'"
1166 do_rpc_nodes "$list" unload_modules_local
1170 local sbin_mount=$(readlink -f /sbin)/mount.lustre
1171 if grep -qe "$sbin_mount " /proc/mounts; then
1172 umount $sbin_mount || true
1173 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
1177 [[ $rc -eq 0 ]] && echo "modules unloaded."
1183 local facet=${1:-ost1}
1185 local mult=$OSTCOUNT
1187 case $(facet_fstype $facet) in
1188 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
1189 # grant_block_size is in bytes, allow at least 2x max blocksize
1190 zfs) size=$(lctl get_param osc.$FSNAME*.import |
1191 awk '/grant_block_size:/ {print $2/512; exit;}')
1195 [[ $facet =~ mds ]] && mult=$MDTCOUNT
1196 echo -n $((size * mult))
1200 local facet=${1:-$SINGLEMDS}
1201 local fstype=$(facet_fstype $facet)
1204 ldiskfs) size=4;; # ~4KB per inode
1205 zfs) size=11;; # 10 to 11KB per inode
1218 echo Running as $user: $cmd $opts
1221 su - $user -c "$cmd $opts"
1224 check_gss_daemon_nodes() {
1232 dname=$(basename "$dname" | awk '{print $1}')
1233 do_nodesv $list "num=0;
1234 for proc in \\\$(pgrep $dname); do
1235 [ \\\$(ps -o ppid= -p \\\$proc) -ne 1 ] || ((num++))
1237 if [ \\\"\\\$num\\\" -ne 1 ]; then
1238 echo \\\$num instance of $dname;
1242 (( $ret == 0 )) || return $ret
1244 for node in ${list//,/ }; do
1246 while (( $loop < $loopmax )); do
1247 do_nodesv $node "$L_GETAUTH -d"
1249 (( $ret == 0 )) && break
1253 (( $loop < $loopmax )) || return 1
1258 check_gss_daemon_facet() {
1262 dname=$(basename "$dname" | awk '{print $1}')
1263 num=$(do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l)
1264 if [ $num -ne 1 ]; then
1265 echo "$num instance of $dname on $facet"
1275 echo "Stopping "$@" on $list"
1276 do_nodes $list "killall -2 $* 2>/dev/null || true"
1279 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1280 start_gss_daemons() {
1285 if [ "$nodes" ] && [ "$daemon" ] ; then
1286 echo "Starting gss daemon on nodes: $nodes"
1287 do_nodes $nodes "$daemon" "$options" || return 8
1288 check_gss_daemon_nodes $nodes "$daemon" || return 9
1292 nodes=$(comma_list $(mdts_nodes))
1293 echo "Starting gss daemon on mds: $nodes"
1295 # Start all versions, in case of switching
1296 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1299 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 1
1302 nodes=$(comma_list $(osts_nodes))
1303 echo "Starting gss daemon on ost: $nodes"
1305 # Start all versions, in case of switching
1306 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z $options" ||
1309 do_nodes $nodes "$LSVCGSSD -vvv $options" || return 3
1311 # starting on clients
1313 local clients=${CLIENTS:-$HOSTNAME}
1316 # check daemons are running
1318 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1319 check_gss_daemon_nodes $nodes "$LSVCGSSD" || return 5
1322 stop_gss_daemons() {
1323 local nodes=$(comma_list $(mdts_nodes))
1325 send_sigint $nodes lsvcgssd lgssd
1327 nodes=$(comma_list $(osts_nodes))
1328 send_sigint $nodes lsvcgssd
1330 nodes=${CLIENTS:-$HOSTNAME}
1331 send_sigint $nodes lgssd
1335 # Add mount flags for shared key
1338 if grep -q skpath <<< "$mt_opts" ; then
1339 mt_opts=$(echo $mt_opts |
1340 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1342 if [ -z "$mt_opts" ]; then
1343 mt_opts="-o skpath=$SK_PATH"
1345 mt_opts="$mt_opts,skpath=$SK_PATH"
1355 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1364 [ $from_tree = true ]
1368 if $SHARED_KEY; then
1377 if ! module_loaded ptlrpc_gss; then
1378 load_module ptlrpc/gss/ptlrpc_gss
1379 module_loaded ptlrpc_gss ||
1380 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1383 if $GSS_KRB5 || $GSS_SK; then
1384 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1387 if $GSS_SK && ! $SK_NO_KEY; then
1388 echo "Loading basic SSK keys on all servers"
1389 do_nodes $(comma_list $(all_server_nodes)) \
1390 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1391 do_nodes $(comma_list $(all_server_nodes)) \
1392 "keyctl show | grep lustre | cut -c1-11 |
1394 xargs -IX keyctl setperm X 0x3f3f3f3f"
1397 if $GSS_SK && $SK_NO_KEY; then
1398 local numclients=${1:-$CLIENTCOUNT}
1399 local clients=${CLIENTS:-$HOSTNAME}
1401 # security ctx config for keyring
1403 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1405 if from_build_tree; then
1406 mkdir -p $SK_OM_PATH
1407 if grep -q request-key /proc/mounts > /dev/null; then
1408 echo "SSK: Request key already mounted."
1410 mount -o bind $SK_OM_PATH /etc/request-key.d/
1412 local lgssc_conf_line='create lgssc * * '
1413 lgssc_conf_line+=$(which lgss_keyring)
1414 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1415 echo "$lgssc_conf_line" > $lgssc_conf_file
1418 [ -e $lgssc_conf_file ] ||
1419 error_exit "Could not find key options in $lgssc_conf_file"
1420 echo "$lgssc_conf_file content is:"
1421 cat $lgssc_conf_file
1423 if ! local_mode; then
1424 if from_build_tree; then
1425 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1427 do_nodes $(comma_list $(all_nodes)) "mount \
1428 -o bind $SK_OM_PATH \
1429 /etc/request-key.d/"
1430 do_nodes $(comma_list $(all_nodes)) "rsync \
1431 -aqv $HOSTNAME:$lgssc_conf_file \
1432 $lgssc_conf_file >/dev/null 2>&1"
1434 do_nodes $(comma_list $(all_nodes)) \
1435 "echo $lgssc_conf_file: ; \
1436 cat $lgssc_conf_file"
1440 # create shared key on all nodes
1441 mkdir -p $SK_PATH/nodemap
1442 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1443 $SK_PATH/$FSNAME-*.key
1444 # for nodemap testing each client may need own key,
1445 # and S2S now requires keys as well, both for "client"
1448 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1449 -w $SK_PATH/$FSNAME-nmclient.key \
1450 -d /dev/urandom >/dev/null 2>&1
1451 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1452 -w $SK_PATH/$FSNAME-s2s-server.key \
1453 -d /dev/urandom >/dev/null 2>&1
1456 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1457 -d /dev/urandom >/dev/null 2>&1
1459 for i in $(seq 0 $((numclients - 1))); do
1460 $LGSS_SK -t server -f$FSNAME -n c$i \
1461 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1465 if ! local_mode; then
1466 for lnode in $(all_nodes); do
1467 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1470 # Set client keys to client type to generate prime P
1472 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1473 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1475 do_nodes $clients "$LGSS_SK -t client -m \
1476 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1477 do_nodes $clients "find $SK_PATH/nodemap \
1478 -name \*.key | xargs -IX $LGSS_SK -t client \
1479 -m X >/dev/null 2>&1"
1480 # also have a client key available on server side,
1481 # for local client mount
1482 do_nodes $(comma_list $(all_server_nodes)) \
1483 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1484 $LGSS_SK -t client -m \
1485 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1487 # This is required for servers as well, if S2S in use
1489 do_nodes $(comma_list $(mdts_nodes)) \
1490 "cp $SK_PATH/$FSNAME-s2s-server.key \
1491 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1492 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1494 do_nodes $(comma_list $(osts_nodes)) \
1495 "cp $SK_PATH/$FSNAME-s2s-server.key \
1496 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1497 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1499 do_nodes $clients "$LGSS_SK -t client \
1500 -m $SK_PATH/$FSNAME-nmclient.key \
1505 # mount options for servers and clients
1506 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1507 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1508 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1509 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1511 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1512 LGSS_KEYRING_DEBUG=4
1516 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1517 ( local_mode || from_build_tree ); then
1519 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1520 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1521 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1523 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1526 do_nodesv $(comma_list $(all_server_nodes)) \
1527 "$LCTL set_param sptlrpc.gss.rsi_upcall=$L_GETAUTH"
1533 # maybe cleanup credential cache?
1540 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1541 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1542 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1546 $RPC_MODE || echo "Cleaning up Shared Key.."
1547 do_nodes $(comma_list $(all_nodes)) "rm -f \
1548 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1549 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1550 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1551 if from_build_tree; then
1552 # Remove the mount and clean up the files we added to
1554 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1555 request-key.d /proc/mounts; do umount \
1556 /etc/request-key.d/; done"
1557 do_nodes $(comma_list $(all_nodes)) "rm -f \
1558 $SK_OM_PATH/lgssc.conf"
1559 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1567 local var=${facet}_svc
1575 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1576 tr '[:lower:]' '[:upper:]'
1582 if [ $facet == mgs ] || [ $facet == client ]; then
1586 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1594 if [ -n "${!var}" ]; then
1599 var=$(facet_type $facet)FSTYPE
1600 if [ -n "${!var}" ]; then
1605 if [ -n "$FSTYPE" ]; then
1610 if [[ $facet == mgs ]] && combined_mgs_mds; then
1622 local facets=$(get_facets)
1625 for facet in ${facets//,/ }; do
1626 if [[ $node == $(facet_host $facet) ]] ||
1627 [[ $node == "$(facet_failover_host $facet)" ]]; then
1628 fstype=$(facet_fstype $facet)
1629 if [[ $fstypes != *$fstype* ]]; then
1630 fstypes+="${fstypes:+,}$fstype"
1639 local num=$(facet_number $facet)
1642 if [[ $(facet_type $facet) = OST ]]; then
1643 index=OSTINDEX${num}
1644 if [[ -n "${!index}" ]]; then
1649 index=${OST_INDICES[num - 1]}
1652 [[ -n "$index" ]] || index=$((num - 1))
1660 local fstype=$(facet_fstype $facet)
1664 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1666 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1667 ${dev} 2>/dev/null");;
1669 error "unknown fstype!";;
1676 # Get the device of a facet.
1683 mgs) device=$(mgsdevname) ;;
1684 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1685 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1686 fs2mds) device=$(mdsdevname 1_2) ;;
1687 fs2ost) device=$(ostdevname 1_2) ;;
1688 fs3ost) device=$(ostdevname 2_2) ;;
1696 # Get the virtual device of a facet.
1703 mgs) device=$(mgsvdevname) ;;
1704 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1705 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1706 fs2mds) device=$(mdsvdevname 1_2) ;;
1707 fs2ost) device=$(ostvdevname 1_2) ;;
1708 fs3ost) device=$(ostvdevname 2_2) ;;
1716 local virt=$(virt-what 2> /dev/null)
1718 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1720 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1723 VMware|KVM|VirtualBox|Parallels|Bochs)
1724 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1729 virt=$(dmidecode -s system-manufacturer | awk '{print $1}')
1732 echo $virt | tr '[A-Z]' '[a-z]' && return;;
1738 # Re-read the partition table on failover partner host.
1739 # After a ZFS storage pool is created on a shared device, the partition table
1740 # on the device may change. However, the operating system on the failover
1741 # host may not notice the change automatically. Without the up-to-date partition
1742 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1743 # relative to partition rather than disk beginnings.
1745 # This function performs partprobe on the failover host to make it re-read the
1748 refresh_partition_table() {
1753 host=$(facet_passive_host $facet)
1754 if [[ -n "$host" ]]; then
1755 do_node $host "$PARTPROBE $device"
1760 # Get ZFS storage pool name.
1767 device=$(facet_device $facet)
1768 # poolname is string before "/"
1769 poolname="${device%%/*}"
1776 # Get ZFS local fsname.
1778 zfs_local_fsname() {
1780 local lfsname=$(basename $(facet_device $facet))
1786 # Create ZFS storage pool.
1793 local opts=${@:-"-o cachefile=none"}
1795 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1796 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1797 $ZPOOL create -f $opts $poolname $vdev"
1801 # Create ZFS file system.
1807 local opts=${@:-"-o mountpoint=legacy"}
1809 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1810 $ZFS create $opts $dataset"
1814 # Export ZFS storage pool.
1815 # Before exporting the pool, all datasets within the pool should be unmounted.
1823 poolname=$(zpool_name $facet)
1825 if [[ -n "$poolname" ]]; then
1826 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1827 grep -q ^$poolname/ /proc/mounts ||
1828 $ZPOOL export $opts $poolname"
1833 # Destroy ZFS storage pool.
1834 # Destroy the given pool and free up any devices for other use. This command
1835 # tries to unmount any active datasets before destroying the pool.
1836 # -f Force any active datasets contained within the pool to be unmounted.
1840 local poolname=${2:-$(zpool_name $facet)}
1842 if [[ -n "$poolname" ]]; then
1843 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1844 $ZPOOL destroy -f $poolname"
1849 # Import ZFS storage pool.
1850 # Force importing, even if the pool appears to be potentially active.
1855 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1858 poolname=$(zpool_name $facet)
1860 if [[ -n "$poolname" ]]; then
1861 opts+=" -d $(dirname $(facet_vdevice $facet))"
1862 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1863 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1864 $ZPOOL import -f $opts $poolname"
1869 # Reimport ZFS storage pool with new name
1874 local opts="-o cachefile=none"
1875 local poolname=$(zpool_name $facet)
1877 opts+=" -d $(dirname $(facet_vdevice $facet))"
1878 do_facet $facet "$ZPOOL export $poolname;
1879 $ZPOOL import $opts $poolname $newpool"
1883 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1884 # is not automatically imported on system startup.
1886 # In a failover environment, this will provide resource level fencing which
1887 # will ensure that the same ZFS storage pool will not be imported concurrently
1888 # on different nodes.
1890 disable_zpool_cache() {
1894 poolname=$(zpool_name $facet)
1896 if [[ -n "$poolname" ]]; then
1897 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1902 # This and set_osd_param() shall be used to access OSD parameters
1903 # once existed under "obdfilter":
1908 # writethrough_cache_enable
1912 local device=${2:-$FSNAME-OST*}
1915 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1920 local device=${2:-$FSNAME-OST*}
1924 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1927 set_default_debug () {
1928 local debug=${1:-"$PTLDEBUG"}
1929 local subsys=${2:-"$SUBSYSTEM"}
1930 local debug_size=${3:-$DEBUG_SIZE}
1932 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1934 lctl set_param subsystem_debug="${subsys# }" >/dev/null
1935 [ -n "$debug_size" ] &&
1936 lctl set_param debug_mb="$debug_size" >/dev/null
1941 set_default_debug_nodes () {
1943 local debug="${2:-"$PTLDEBUG"}"
1944 local subsys="${3:-"$SUBSYSTEM"}"
1945 local debug_size="${4:-$DEBUG_SIZE}"
1947 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1948 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1952 [[ -z "$nodes" ]] ||
1953 do_rpc_nodes "$nodes" set_default_debug \
1954 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1957 set_default_debug_facet () {
1959 local debug="${2:-"$PTLDEBUG"}"
1960 local subsys="${3:-"$SUBSYSTEM"}"
1961 local debug_size="${4:-$DEBUG_SIZE}"
1962 local node=$(facet_active_host $facet)
1964 [ -n "$node" ] || error "No host defined for facet $facet"
1966 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1969 set_params_nodes() {
1974 [[ -n "$params" ]] || return 0
1976 do_nodes $nodes "$LCTL set_param $params"
1979 set_params_clients() {
1980 (( $# >= 2 )) || return 0
1981 local clients=${1:-$CLIENTS}
1983 local params="${@:-$CLIENT_LCTL_SETPARAM_PARAM}"
1985 set_params_nodes $clients $params
1989 (( $# >= 2 )) || return 0
1990 local mdts=${1:-$(comma_list $(mdts_nodes))}
1992 local params="${@:-$MDS_LCTL_SETPARAM_PARAM}"
1994 set_params_nodes $mdts $params
1998 (( $# >= 2 )) || return 0
1999 local osts=${1:-$(comma_list $(osts_nodes))}
2001 local params="${@:-$OSS_LCTL_SETPARAM_PARAM}"
2003 set_params_nodes $osts $params
2007 local hostid=${1:-$(hostid)}
2009 if [ ! -s /etc/hostid ]; then
2010 printf $(echo -n $hostid |
2011 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
2017 local facets=${1:-$(get_facets)}
2023 for facet in ${facets//,/ }; do
2024 mount_facet $facet &
2028 for ((index=0; index<$total; index++)); do
2029 wait ${mountpids[index]}
2031 [ $RC -eq 0 ] && continue
2033 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
2034 skip_noexit "Restart of $facet failed!." &&
2037 error "Restart of $facet failed!"
2045 # Add argument "arg" (e.g., "loop") to the comma-separated list
2046 # of arguments for option "opt" (e.g., "-o") on command
2047 # line "opts" (e.g., "-o flock").
2053 local opt_pattern="\([[:space:]]\+\|^\)$opt"
2055 if echo "$opts" | grep -q $opt_pattern; then
2056 opts=$(echo "$opts" | sed -e \
2057 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
2059 opts+="${opts:+ }$opt $arg"
2065 # Associate loop device with a given regular file.
2066 # Return the loop device.
2068 setup_loop_device() {
2072 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
2073 if [[ -z \\\$loop_dev ]]; then
2074 loop_dev=\\\$($LOSETUP -f);
2075 $LOSETUP \\\$loop_dev $file || loop_dev=;
2077 echo -n \\\$loop_dev"
2081 # Detach a loop device.
2083 cleanup_loop_device() {
2087 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
2088 $LOSETUP -d $loop_dev"
2092 # Check if a given device is a block device.
2099 [[ -n "$dev" ]] || return 1
2100 do_facet $facet "test -b $dev" || return 1
2101 if [[ -n "$size" ]]; then
2102 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
2103 count=1 skip=$size 2>&1" |
2104 awk '($3 == "in") { print $1 }')
2105 [[ "$in" = "1+0" ]] || return 1
2110 # Check if a given device is a device-mapper device.
2116 [[ -n "$dev" ]] || return 1
2117 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
2121 # Check if a given device is a device-mapper flakey device.
2123 is_dm_flakey_dev() {
2128 [[ -n "$dev" ]] || return 1
2130 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
2132 [[ $type = flakey ]] && return 0 || return 1
2136 # Check if device-mapper flakey device is supported by the kernel
2137 # of $facet node or not.
2139 dm_flakey_supported() {
2143 do_facet $facet "modprobe dm-flakey;
2144 $DMSETUP targets | grep -q flakey" &> /dev/null
2148 # Get the device-mapper flakey device name of a given facet.
2150 dm_facet_devname() {
2152 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2154 echo -n ${facet}_flakey
2158 # Get the device-mapper flakey device of a given facet.
2159 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
2161 dm_facet_devpath() {
2164 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
2168 # Set a device-mapper device with a new table.
2170 # The table has the following format:
2171 # <logical_start_sector> <num_sectors> <target_type> <target_args>
2173 # flakey <target_args> includes:
2174 # <destination_device> <offset> <up_interval> <down_interval> \
2175 # [<num_features> [<feature_arguments>]]
2177 # linear <target_args> includes:
2178 # <destination_device> <start_sector>
2180 dm_set_dev_table() {
2183 local target_type=$3
2189 read tmp num_sectors tmp real_dev tmp \
2190 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
2192 case $target_type in
2194 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
2197 table="0 $num_sectors linear $real_dev 0"
2199 *) error "invalid target type $target_type" ;;
2202 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
2203 error "failed to suspend $dm_dev"
2204 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
2205 error "failed to load $target_type table into $dm_dev"
2206 do_facet $facet "$DMSETUP resume $dm_dev" ||
2207 error "failed to resume $dm_dev"
2211 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
2212 # feature parameter.
2215 # All write I/O is silently ignored.
2216 # Read I/O is handled correctly.
2218 dm_set_dev_readonly() {
2220 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2222 dm_set_dev_table $facet $dm_dev flakey
2226 # Set a device-mapper device to traditional linear mapping mode.
2228 dm_clear_dev_readonly() {
2230 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2232 dm_set_dev_table $facet $dm_dev linear
2236 # Set the device of a given facet as "read-only".
2238 set_dev_readonly() {
2240 local svc=${facet}_svc
2242 if [[ $(facet_fstype $facet) = zfs ]] ||
2243 ! dm_flakey_supported $facet; then
2244 do_facet $facet $LCTL --device ${!svc} readonly
2246 dm_set_dev_readonly $facet
2251 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
2258 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
2259 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
2260 echo -n $num_sectors
2264 # Create a device-mapper device with a given block device or regular file (will
2265 # be associated with loop device).
2266 # Return the full path of the device-mapper device.
2270 local real_dev=$2 # destination device
2271 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
2272 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
2274 # check if the device-mapper device to be created already exists
2275 if is_dm_dev $facet $dm_dev; then
2276 # if the existing device was set to "read-only", then clear it
2277 ! is_dm_flakey_dev $facet $dm_dev ||
2278 dm_clear_dev_readonly $facet $dm_dev
2284 # check if the destination device is a block device, and if not,
2285 # associate it with a loop device
2286 is_blkdev $facet $real_dev ||
2287 real_dev=$(setup_loop_device $facet $real_dev)
2288 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
2290 # now create the device-mapper device
2291 local num_sectors=$(get_num_sectors $facet $real_dev)
2292 local table="0 $num_sectors linear $real_dev 0"
2295 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
2296 { rc=${PIPESTATUS[0]}; dm_dev=; }
2297 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2304 # Map the facet name to its device variable name.
2306 facet_device_alias() {
2308 local dev_alias=$facet
2311 fs2mds) dev_alias=mds1_2 ;;
2312 fs2ost) dev_alias=ost1_2 ;;
2313 fs3ost) dev_alias=ost2_2 ;;
2321 # Save the original value of the facet device and export the new value.
2327 local active_facet=$(facet_active $facet)
2328 local dev_alias=$(facet_device_alias $active_facet)
2329 local dev_name=${dev_alias}_dev
2330 local dev=${!dev_name}
2332 if [[ $active_facet = $facet ]]; then
2333 local failover_dev=${dev_alias}failover_dev
2334 if [[ ${!failover_dev} = $dev ]]; then
2335 eval export ${failover_dev}_saved=$dev
2336 eval export ${failover_dev}=$dm_dev
2339 dev_alias=$(facet_device_alias $facet)
2340 local facet_dev=${dev_alias}_dev
2341 if [[ ${!facet_dev} = $dev ]]; then
2342 eval export ${facet_dev}_saved=$dev
2343 eval export ${facet_dev}=$dm_dev
2347 eval export ${dev_name}_saved=$dev
2348 eval export ${dev_name}=$dm_dev
2352 # Restore the saved value of the facet device.
2357 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2358 local dev_alias=$(facet_device_alias $facet)
2360 local saved_dev=${dev_alias}_dev_saved
2361 [[ -z ${!saved_dev} ]] ||
2362 eval export ${dev_alias}_dev=${!saved_dev}
2364 saved_dev=${dev_alias}failover_dev_saved
2365 [[ -z ${!saved_dev} ]] ||
2366 eval export ${dev_alias}failover_dev=${!saved_dev}
2370 # Remove a device-mapper device.
2371 # If the destination device is a loop device, then also detach it.
2375 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2379 is_dm_dev $facet $dm_dev || return 0
2381 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2382 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2384 do_facet $facet "$DMSETUP remove $dm_dev"
2385 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2387 unexport_dm_dev $facet
2389 # detach a loop device
2390 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2392 # unload dm-flakey module
2393 do_facet $facet "modprobe -r dm-flakey" || true
2399 local active_facet=$(facet_active $facet)
2400 local dev_alias=$(facet_device_alias $active_facet)
2401 local dev=${dev_alias}_dev
2402 local opt=${facet}_opt
2403 local mntpt=$(facet_mntpt $facet)
2404 local opts="${!opt} $@"
2405 local fstype=$(facet_fstype $facet)
2407 local dm_dev=${!dev}
2409 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2410 dev=mds1failover_dev
2412 module_loaded lustre || load_modules
2416 if dm_flakey_supported $facet; then
2417 dm_dev=$(dm_create_dev $facet ${!dev})
2418 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2421 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2423 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2425 # import ZFS storage pool
2426 import_zpool $facet || return ${PIPESTATUS[0]}
2428 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2429 lustre:svname $dm_dev");;
2431 error "unknown fstype!";;
2434 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2435 # for testing LU-482 error handling in mount_facets() and test_0a()
2436 if [ -f $TMP/test-lu482-trigger ]; then
2439 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2440 (( $seq_width >= 16384 )) || seq_width=16384
2442 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2444 if [[ ${facet} =~ ost ]]; then
2445 do_facet ${facet} "$LCTL set_param \
2446 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2450 if [ $RC -ne 0 ]; then
2451 echo "Start of $dm_dev on ${facet} failed ${RC}"
2455 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2456 if [[ "$health" != "healthy" ]]; then
2457 error "$facet is in a unhealthy state"
2460 set_default_debug_facet $facet
2462 if [[ $opts =~ .*nosvc.* ]]; then
2463 echo "Start $dm_dev without service"
2468 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2469 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2470 "" || error "$dm_dev failed to initialize!";;
2472 wait_update_facet ${facet} "$ZFS get -H -o value \
2473 lustre:svname $dm_dev 2>/dev/null | \
2474 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2475 error "$dm_dev failed to initialize!";;
2478 error "unknown fstype!";;
2482 # commit the device label change to disk
2483 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2484 echo "Commit the device label on ${!dev}"
2485 do_facet $facet "sync; sleep 1; sync"
2489 label=$(devicelabel ${facet} $dm_dev)
2490 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2491 eval export ${facet}_svc=${label}
2492 echo Started ${label}
2494 export_dm_dev $facet $dm_dev
2499 # start facet device options
2505 local dev_alias=$(facet_device_alias $facet)
2507 eval export ${dev_alias}_dev=${device}
2508 eval export ${facet}_opt=\"$*\"
2510 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2511 eval export mgs_dev=${device}
2513 local varname=${dev_alias}failover_dev
2514 if [ -n "${!varname}" ] ; then
2515 eval export ${dev_alias}failover_dev=${!varname}
2517 eval export ${dev_alias}failover_dev=$device
2518 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2519 eval export mgsfailover_dev=${device}
2523 local mntpt=$(facet_mntpt $facet)
2524 do_facet ${facet} mkdir -p $mntpt
2525 eval export ${facet}_MOUNT=$mntpt
2526 mount_facet ${facet}
2536 local HOST=$(facet_active_host $facet)
2537 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2539 local mntpt=$(facet_mntpt $facet)
2540 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2541 if [ ${running} -ne 0 ]; then
2542 echo "Stopping $mntpt (opts:$*) on $HOST"
2543 do_facet ${facet} $UMOUNT "$@" $mntpt
2546 # umount should block, but we should wait for unrelated obd's
2547 # like the MGS or MGC to also stop.
2548 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2550 if [[ $(facet_fstype $facet) == zfs ]]; then
2551 # export ZFS storage pool
2552 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2553 elif dm_flakey_supported $facet; then
2554 local host=${facet}_HOST
2555 local failover_host=${facet}failover_HOST
2556 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2557 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2558 dm_cleanup_dev $facet
2563 # get mdt quota type
2565 local varsvc=${SINGLEMDS}_svc
2566 do_facet $SINGLEMDS $LCTL get_param -n \
2567 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2570 # get ost quota type
2572 # All OSTs should have same quota type
2573 local varsvc=ost1_svc
2574 do_facet ost1 $LCTL get_param -n \
2575 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2578 # restore old quota type settings
2580 for usr in $QUOTA_USERS; do
2581 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2583 cmd="$LFS setquota -$type $usr -b 0"
2584 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2586 eval $cmd || error "$cmd FAILED!"
2588 # display the quota status
2589 echo "Quota settings for $usr : "
2590 $LFS quota -v -u $usr $MOUNT || true
2592 if [ "$old_MDT_QUOTA_TYPE" ]; then
2593 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2594 do_facet mgs $PERM_CMD \
2595 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2598 do_facet mgs $PERM_CMD \
2599 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2602 if [ "$old_OST_QUOTA_TYPE" ]; then
2603 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2604 do_facet mgs $PERM_CMD \
2605 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2608 do_facet mgs $LCTL conf_param \
2609 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2614 # Handle the case when there is a space in the lfs df
2615 # "filesystem summary" line the same as when there is no space.
2616 # This will allow fixing the "lfs df" summary line in the future.
2618 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2619 check_lfs_df_ret_val ${PIPESTATUS[0]}
2622 # Get free inodes on the MDT specified by mdt index, free indoes on
2623 # the whole filesystem will be returned when index == -1.
2629 if [ $index -eq -1 ]; then
2632 mdt_uuid=$(mdtuuid_from_index $index)
2635 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2640 # Get the OST device status from 'lfs df' with a given OST index.
2644 local mnt_pnt=${2:-$MOUNT}
2648 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2649 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2655 # save old quota type & set new quota type
2656 local mdt_qtype=$(mdt_quota_type)
2657 local ost_qtype=$(ost_quota_type)
2659 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2660 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2662 export old_MDT_QUOTA_TYPE=$mdt_qtype
2663 export old_OST_QUOTA_TYPE=$ost_qtype
2665 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2666 do_facet mgs $PERM_CMD \
2667 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2668 do_facet mgs $PERM_CMD \
2669 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2671 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2672 error "set mdt quota type failed"
2673 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2674 error "set ost quota type failed"
2677 local quota_usrs=$QUOTA_USERS
2679 # get_filesystem_size
2680 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2681 local blk_soft=$((disksz + 1024))
2682 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2684 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2685 local i_soft=$inodes
2686 local i_hard=$((i_soft + i_soft / 20))
2688 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2689 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2690 "inode-hardlimit: $i_hard"
2693 for usr in $quota_usrs; do
2694 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2696 cmd="$LFS setquota -$type $usr -b $blk_soft"
2697 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2699 eval $cmd || error "$cmd FAILED!"
2701 # display the quota status
2702 echo "Quota settings for $usr : "
2703 $LFS quota -v -u $usr $mntpt || true
2710 local opts=${3:-$MOUNT_OPTS}
2711 opts=${opts:+-o $opts}
2712 local flags=${4:-$MOUNT_FLAGS}
2714 local device=$MGSNID:/$FSNAME$FILESET
2715 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2716 echo "Bad mount command: opt=$flags $opts dev=$device " \
2722 # update mount option with skpath
2723 opts=$(add_sk_mntflag $opts)
2726 echo "Starting client: $client: $flags $opts $device $mnt"
2727 do_node $client mkdir -p $mnt
2728 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2729 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2731 #disable FILESET if not supported
2732 do_nodes $client lctl get_param -n \
2733 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2734 device=$MGSNID:/$FSNAME
2735 do_node $client mkdir -p $mnt/$FILESET
2736 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2739 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2740 # Mount using nodemap key
2741 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2742 if $SK_UNIQUE_NM; then
2743 mountkey=$SK_PATH/nodemap/c0.key
2745 local prunedopts=$(echo $opts |
2746 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2747 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2750 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2754 set_default_debug_nodes $client
2755 set_params_clients $client
2766 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2768 [ "$3" ] && force=-f
2769 [ $running -eq 0 ] && return 0
2771 echo "Stopping client $client $mnt (opts:$force)"
2772 do_node $client lsof -t $mnt || need_kill=no
2773 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2774 pids=$(do_node $client lsof -t $mnt | sort -u);
2775 if [ -n "$pids" ]; then
2776 do_node $client kill -9 $pids || true
2780 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2782 if [ $busy -ne 0 ] ; then
2783 echo "$mnt is still busy, wait one second" && sleep 1
2784 do_node $client umount $force $mnt
2788 # Mount the file system on the MDS
2789 mount_mds_client() {
2790 local host=$(facet_active_host $SINGLEMDS)
2792 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2793 error "unable to mount $MOUNT2 on $host"
2796 # Unmount the file system on the MDS
2797 umount_mds_client() {
2798 local host=$(facet_active_host $SINGLEMDS)
2799 zconf_umount $host $MOUNT2
2800 do_facet $SINGLEMDS "rmdir $MOUNT2"
2803 # nodes is comma list
2804 sanity_mount_check_nodes () {
2810 # FIXME: assume that all cluster nodes run the same os
2811 [ "$(uname)" = Linux ] || return 0
2814 for mnt in $mnts ; do
2815 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2816 mpts=\\\$(mount | grep -c $mnt' ');
2817 if [ \\\$running -ne \\\$mpts ]; then
2818 echo \\\$(hostname) env are INSANE!;
2821 [ $? -eq 0 ] || rc=1
2826 sanity_mount_check_servers () {
2827 [ -n "$CLIENTONLY" ] &&
2828 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2829 echo Checking servers environments
2831 # FIXME: modify get_facets to display all facets wo params
2832 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2836 for facet in ${facets//,/ }; do
2837 node=$(facet_host ${facet})
2838 mntpt=$(facet_mntpt $facet)
2839 sanity_mount_check_nodes $node $mntpt ||
2840 { error "server $node environments are insane!"; return 1; }
2844 sanity_mount_check_clients () {
2845 local clients=${1:-$CLIENTS}
2846 local mntpt=${2:-$MOUNT}
2847 local mntpt2=${3:-$MOUNT2}
2849 [ -z $clients ] && clients=$(hostname)
2850 echo Checking clients $clients environments
2852 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2853 error "clients environments are insane!"
2856 sanity_mount_check () {
2857 sanity_mount_check_servers || return 1
2858 sanity_mount_check_clients || return 2
2861 # mount clients if not mouted
2862 zconf_mount_clients() {
2865 local opts=${3:-$MOUNT_OPTS}
2866 opts=${opts:+-o $opts}
2867 local flags=${4:-$MOUNT_FLAGS}
2868 local device=$MGSNID:/$FSNAME$FILESET
2869 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2870 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2875 echo "Starting client $clients: $flags $opts $device $mnt"
2876 do_nodes $clients mkdir -p $mnt
2877 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2878 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2879 # Mount with own nodemap key
2881 # Mount all server nodes first with per-NM keys
2882 for nmclient in ${clients//,/ }; do
2883 do_nodes $(comma_list $(all_server_nodes)) \
2884 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
2887 # set perms for per-nodemap keys else permission denied
2888 do_nodes $(comma_list $(all_nodes)) \
2889 "keyctl show | grep lustre | cut -c1-11 |
2891 xargs -IX keyctl setperm X 0x3f3f3f3f"
2892 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2894 for nmclient in ${clients//,/ }; do
2895 if $SK_UNIQUE_NM; then
2896 mountkey=$SK_PATH/nodemap/c$i.key
2898 do_node $nmclient "! grep -q $mnt' ' \
2899 /proc/mounts || umount $mnt"
2900 local prunedopts=$(add_sk_mntflag $opts);
2901 prunedopts=$(echo $prunedopts | sed -e \
2902 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2904 do_nodes $(comma_list $(all_server_nodes)) \
2907 do_node $nmclient $MOUNT_CMD $flags \
2908 $prunedopts $MGSNID:/$FSNAME $mnt ||
2913 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2915 do_nodes $clients $MOUNT_CMD $flags $opts \
2916 $MGSNID:/$FSNAME $mnt || return 1
2918 #disable FILESET if not supported
2919 do_nodes $clients lctl get_param -n \
2920 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2921 device=$MGSNID:/$FSNAME
2922 do_nodes $clients mkdir -p $mnt/$FILESET
2923 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2927 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2928 # Mount with nodemap key
2930 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2931 for nmclient in ${clients//,/ }; do
2932 if $SK_UNIQUE_NM; then
2933 mountkey=$SK_PATH/nodemap/c$i.key
2935 local prunedopts=$(echo $opts | sed -e \
2936 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2937 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2940 running=\\\$(mount | grep -c $mnt' ');
2942 if [ \\\$running -eq 0 ] ; then
2944 $MOUNT_CMD $flags $prunedopts $device $mnt;
2947 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2948 grep 'type lustre' | wc -l);
2949 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2950 echo zconf_mount_clients FAILED: \
2951 mount count \\\$running, not matching \
2952 with mount count of 'type lustre' \
2953 \\\$lustre_mnt_count;
2957 exit \\\$rc" || return ${PIPESTATUS[0]}
2964 if $SHARED_KEY; then
2965 tmpopts=$(add_sk_mntflag $opts)
2968 running=\\\$(mount | grep -c $mnt' ');
2970 if [ \\\$running -eq 0 ] ; then
2972 $MOUNT_CMD $flags $tmpopts $device $mnt;
2975 exit \\\$rc" || return ${PIPESTATUS[0]}
2978 echo "Started clients $clients: "
2979 do_nodes $clients "mount | grep $mnt' '"
2981 set_default_debug_nodes $clients
2982 set_params_clients $clients
2987 zconf_umount_clients() {
2992 [ "$3" ] && force=-f
2994 echo "Stopping clients: $clients $mnt (opts:$force)"
2995 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2996 if [ \\\$running -ne 0 ] ; then
2997 echo Stopping client \\\$(hostname) $mnt opts:$force;
2998 lsof $mnt || need_kill=no;
2999 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
3000 pids=\\\$(lsof -t $mnt | sort -u);
3001 if [ -n \\\"\\\$pids\\\" ]; then
3005 while umount $force $mnt 2>&1 | grep -q "busy"; do
3006 echo "$mnt is still busy, wait one second" && sleep 1;
3014 echo + $POWER_DOWN $node
3018 shutdown_node_hard () {
3020 local attempts=$SHUTDOWN_ATTEMPTS
3022 for i in $(seq $attempts) ; do
3025 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
3027 echo "waiting for $host to fail attempts=$attempts"
3028 [ $i -lt $attempts ] ||
3029 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
3035 local mnt=${2:-$MOUNT}
3038 if [ "$FAILURE_MODE" = HARD ]; then
3039 shutdown_node_hard $client
3041 zconf_umount_clients $client $mnt -f
3048 local facets="$(get_facets OST),$(get_facets MDS)"
3050 combined_mgs_mds || facets="$facets,mgs"
3052 for facet in ${facets//,/ }; do
3053 if [ $(facet_active_host $facet) == $host ]; then
3054 affected="$affected $facet"
3058 echo $(comma_list $affected)
3063 local host=${2:-$(facet_host $facet)}
3065 local label=$(convert_facet2label $facet)
3066 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
3069 facets_up_on_host () {
3072 local facets=$(facets_on_host $host)
3074 for facet in ${facets//,/ }; do
3075 if $(facet_up $facet $host); then
3076 affected_up="$affected_up $facet"
3080 echo $(comma_list $affected_up)
3085 local affected_facet
3086 local affected_facets
3088 if [[ "$FAILURE_MODE" = HARD ]]; then
3089 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
3090 dm_flakey_supported $facet; then
3091 affected_facets=$(affected_facets $facet)
3092 for affected_facet in ${affected_facets//,/ }; do
3093 unexport_dm_dev $affected_facet
3097 shutdown_node_hard $(facet_active_host $facet)
3106 echo + $POWER_UP $node
3119 local node=$(facet_active_host $facet)
3120 local sleep_time=${2:-10}
3122 if [ "$FAILURE_MODE" = HARD ]; then
3132 if [ "$FAILURE_MODE" = HARD ]; then
3135 if $LOAD_MODULES_REMOTE; then
3136 echo "loading modules on $node: $facet"
3137 do_rpc_nodes $node load_modules_local
3146 for facet in ${facets//,/ }; do
3147 hosts=$(expand_list $hosts $(facet_host $facet) )
3153 _check_progs_installed () {
3157 for prog in $progs; do
3158 if ! [ "$(which $prog)" -o "${!prog}" ]; then
3159 echo $prog missing on $(hostname)
3166 check_progs_installed () {
3170 do_rpc_nodes "$nodes" _check_progs_installed "$@"
3173 # recovery-scale functions
3175 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
3178 start_client_load() {
3181 local var=$(node_var_name $client)_load
3182 eval export ${var}=$load
3184 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
3185 BREAK_ON_ERROR=$BREAK_ON_ERROR \
3186 END_RUN_FILE=$END_RUN_FILE \
3187 LOAD_PID_FILE=$LOAD_PID_FILE \
3188 TESTLOG_PREFIX=$TESTLOG_PREFIX \
3189 TESTNAME=$TESTNAME \
3190 DBENCH_LIB=$DBENCH_LIB \
3191 DBENCH_SRC=$DBENCH_SRC \
3192 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
3197 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
3198 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
3199 num_clients=$(get_node_count ${CLIENTS//,/ }) \
3200 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
3201 ior_blockSize=$ior_blockSize \
3202 ior_blockUnit=$ior_blockUnit \
3203 ior_xferSize=$ior_xferSize ior_type=$ior_type \
3204 ior_DURATION=$ior_DURATION \
3205 ior_stripe_params=\\\"$ior_stripe_params\\\" \
3206 ior_custom_params=\\\"$ior_custom_param\\\" \
3207 mpi_ior_custom_threads=$mpi_ior_custom_threads \
3210 log "Started client load: ${load} on $client"
3212 # get the children process IDs
3213 local pids=$(ps --ppid $ppid -o pid= | xargs)
3214 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
3218 start_client_loads () {
3219 local -a clients=(${1//,/ })
3220 local numloads=${#CLIENT_LOADS[@]}
3222 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
3223 local load=$((nodenum % numloads))
3224 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
3226 # bug 22169: wait the background threads to start
3230 # only for remote client
3231 check_client_load () {
3233 local var=$(node_var_name $client)_load
3234 local testload=run_${!var}.sh
3236 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
3238 # bug 18914: try to connect several times not only when
3239 # check ps, but while check_node_health also
3243 while [ $RC = 254 -a $tries -gt 0 ]; do
3247 if ! check_node_health $client; then
3249 if [ $RC -eq 254 ]; then
3250 # FIXME: not sure how long we shuold sleep here
3254 echo "check node health failed: RC=$RC "
3258 # We can continue try to connect if RC=254
3259 # Just print the warning about this
3260 if [ $RC = 254 ]; then
3261 echo "got a return status of $RC from do_node while checking " \
3262 "node health on $client"
3265 # see if the load is still on the client
3268 while [ $RC = 254 -a $tries -gt 0 ]; do
3272 if ! do_node $client \
3273 "ps auxwww | grep -v grep | grep -q $testload"; then
3278 if [ $RC = 254 ]; then
3279 echo "got a return status of $RC from do_node while checking " \
3280 "(node health and 'ps') the client load on $client"
3281 # see if we can diagnose a bit why this is
3286 check_client_loads () {
3287 local clients=${1//,/ }
3291 for client in $clients; do
3292 check_client_load $client
3294 if [ "$rc" != 0 ]; then
3295 log "Client load failed on node $client, rc=$rc"
3301 restart_client_loads () {
3302 local clients=${1//,/ }
3303 local expectedfail=${2:-""}
3307 for client in $clients; do
3308 check_client_load $client
3310 if [ "$rc" != 0 -a "$expectedfail" ]; then
3311 local var=$(node_var_name $client)_load
3313 start_client_load $client ${!var}
3314 echo "Restarted client load ${!var}: on $client. Checking ..."
3315 check_client_load $client
3317 if [ "$rc" != 0 ]; then
3318 log "Client load failed to restart on node $client, rc=$rc"
3319 # failure one client load means test fail
3320 # we do not need to check other
3329 # Start vmstat and save its process ID in a file.
3334 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3337 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3338 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3341 # Display the nodes on which client loads failed.
3342 print_end_run_file() {
3346 [ -s $file ] || return 0
3348 echo "Found the END_RUN_FILE file: $file"
3351 # A client load will stop if it finds the END_RUN_FILE file.
3352 # That does not mean the client load actually failed though.
3353 # The first node in END_RUN_FILE is the one we are interested in.
3356 if [ -n "$node" ]; then
3357 local var=$(node_var_name $node)_load
3359 local prefix=$TESTLOG_PREFIX
3360 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3361 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3362 local debug_log=$(echo $stdout_log |
3363 sed 's/\(.*\)stdout/\1debug/')
3365 echo "Client load ${!var} failed on node $node:"
3371 # Stop the process which had its PID saved in a file.
3376 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3378 do_nodes $nodes "test -f $pid_file &&
3379 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3382 # Stop all client loads.
3383 stop_client_loads() {
3384 local nodes=${1:-$CLIENTS}
3387 # stop the client loads
3388 stop_process $nodes $pid_file
3390 # clean up the processes that started them
3391 [ -n "$CLIENT_LOAD_PIDS" ] &&
3392 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3394 # End recovery-scale functions
3397 # wait for a command to return the expected result
3399 # This will run @check on @node repeatedly until the output matches @expect
3400 # based on the supplied condition, or until @max_wait seconds have elapsed,
3401 # whichever comes first. @cond may be one of the normal bash operators,
3402 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3403 # in the caller to avoid unintentional evaluation by the shell in the caller.
3405 # If @max_wait is not specified, the condition will be checked for up to 90s.
3407 # If --verbose is passed as the first argument, the result is printed on each
3408 # value change, otherwise it is only printed after every 10s interval.
3410 # If --quiet is passed as the first/second argument, the do_node() command
3411 # will not print the remote command before executing it each time.
3413 # Using wait_update_cond() or related helper function is preferable to adding
3414 # a "long enough" wait for some state to change in the background, since
3415 # "long enough" may be too short due to tunables, system config, or running in
3416 # a VM, and must by necessity wait too long for most cases or risk failure.
3418 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3419 wait_update_cond() {
3423 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3424 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3430 local max_wait=${5:-90}
3434 local begin=$SECONDS
3438 while (( $waited <= $max_wait )); do
3439 result=$(do_node $quiet $node "$check")
3441 eval [[ "'$result'" $cond "'$expect'" ]]
3442 if [[ $? == 0 ]]; then
3443 [[ -n "$quiet" ]] && return 0
3444 [[ -z "$result" || $waited -le $sleep ]] ||
3445 echo "Updated after ${waited}s: want '$expect' got '$result'"
3448 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3449 [[ -z "$quiet" && -n "$prev_result" ]] &&
3450 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3451 prev_result="$result"
3453 (( $waited % $print == 0 )) && {
3454 [[ -z "$quiet" ]] &&
3455 echo "Waiting $((max_wait - waited))s for '$expect'"
3459 waited=$((SECONDS - begin))
3462 [[ -z "$quiet" ]] &&
3463 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3468 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3473 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3474 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3481 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3484 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3485 wait_update_facet_cond() {
3489 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3490 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3492 local node=$(facet_active_host $1)
3498 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3501 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3502 wait_update_facet() {
3506 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3507 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3509 local node=$(facet_active_host $1)
3514 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3518 do_nodes $(comma_list $(mdts_nodes)) \
3519 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3520 do_nodes $(comma_list $(osts_nodes)) \
3521 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3522 grep -v 'Found no match'
3526 local zfs_wait=${2:-5}
3528 # the occupied disk space will be released
3529 # only after TXGs are committed
3530 if [[ $(facet_fstype $1) == zfs ]]; then
3531 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3539 local lwm=$3 #low watermark
3540 local size_mb #how many MB should we write to pass watermark
3541 local ost_name=$(ostname_from_index $ost_idx)
3543 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3545 if (( $free_kb / 1024 > lwm )); then
3546 size_mb=$((free_kb / 1024 - lwm))
3548 #If 10% of free space cross low watermark use it
3549 if (( $free_kb / 10240 > size_mb )); then
3550 size_mb=$((free_kb / 10240))
3552 #At least we need to store 1.1 of difference between
3553 #free space and low watermark
3554 size_mb=$((size_mb + size_mb / 10))
3556 if (( lwm <= $free_kb / 1024 )) ||
3557 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3558 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3559 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3560 count=$size_mb oflag=append conv=notrunc
3565 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3566 echo "OST still has $((free_kb / 1024)) MB free"
3569 # This checks only the primary MDS
3570 ost_watermarks_get() {
3572 local ost_name=$(ostname_from_index $ost_idx)
3573 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3575 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3576 osp.$mdtosc_proc.reserved_mb_high)
3577 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3578 osp.$mdtosc_proc.reserved_mb_low)
3583 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3584 ost_watermarks_set() {
3588 local ost_name=$(ostname_from_index $ost_idx)
3589 local facets=$(get_facets MDS)
3591 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3592 osp.*$ost_name*.reserved_mb_low=$lwm \
3593 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3595 # sleep to ensure we see the change
3599 ost_watermarks_set_low_space() {
3601 local wms=$(ost_watermarks_get $ost_idx)
3602 local ost_name=$(ostname_from_index $ost_idx)
3604 local old_lwm=$(echo $wms | awk '{ print $1 }')
3605 local old_hwm=$(echo $wms | awk '{ print $2 }')
3607 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3608 # minimal extension size is 64M
3610 if (( $blocks / 1024 > 50 )); then
3611 new_lwm=$((blocks / 1024 - 50))
3613 local new_hwm=$((new_lwm + 5))
3615 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3616 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3619 # Set watermarks to ~current available space & then write data to fill it
3620 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3621 # internal statfs used by the stripe allocator
3623 # first parameter is the filename-prefix, which must get under t-f cleanup
3624 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3625 ost_watermarks_set_enospc() {
3629 local ost_name=$(ostname_from_index $ost_idx)
3630 local facets=$(get_facets MDS)
3634 for MDS in ${facets//,/ }; do
3635 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3637 do_facet $MDS $LCTL get_param -n \
3638 osp.$mdtosc_proc.reserved_mb_high ||
3639 skip "remote MDS does not support reserved_mb_high"
3642 wms=$(ost_watermarks_set_low_space $ost_idx)
3643 local new_lwm=$(echo $wms | awk '{ print $4 }')
3644 fill_ost $filename $ost_idx $new_lwm
3645 #First enospc could execute orphan deletion so repeat
3646 fill_ost $filename $ost_idx $new_lwm
3650 ost_watermarks_enospc_delete_files() {
3654 rm -f $DIR/${filename}.fill_ost$ost_idx
3656 wait_delete_completed
3660 # clean up from "ost_watermarks_set_enospc"
3661 ost_watermarks_clear_enospc() {
3667 ost_watermarks_enospc_delete_files $filename $ost_idx
3668 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3669 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3672 wait_delete_completed_mds() {
3673 local max_wait=${1:-20}
3675 local stime=$(date +%s)
3680 # find MDS with pending deletions
3681 for node in $(mdts_nodes); do
3682 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3683 2>/dev/null | calc_sum)
3684 if [[ $changes -eq 0 ]]; then
3687 mds2sync="$mds2sync $node"
3689 if [ -z "$mds2sync" ]; then
3690 wait_zfs_commit $SINGLEMDS
3693 mds2sync=$(comma_list $mds2sync)
3695 # sync MDS transactions
3696 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3698 # wait till all changes are sent and commmitted by OSTs
3699 # for ldiskfs space is released upon execution, but DMU
3700 # do this upon commit
3703 while [[ $WAIT -ne $max_wait ]]; do
3704 changes=$(do_nodes $mds2sync \
3705 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3706 #echo "$node: $changes changes on all"
3707 if [[ $changes -eq 0 ]]; then
3708 wait_zfs_commit $SINGLEMDS
3710 # the occupied disk space will be released
3711 # only after TXGs are committed
3712 wait_zfs_commit ost1
3720 echo "Delete is not completed in $((etime - stime)) seconds"
3721 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3728 # we can use "for" here because we are waiting the slowest
3729 for host in ${hostlist//,/ }; do
3730 check_network "$host" 900
3732 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3739 for facet in ${facetlist//,/ }; do
3740 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3742 wait_for_host $hostlist
3745 _wait_recovery_complete () {
3748 # Use default policy if $2 is not passed by caller.
3749 local MAX=${2:-$(max_recovery_time)}
3754 while [ $WAIT -lt $MAX ]; do
3755 STATUS=$(lctl get_param -n $param | grep status)
3757 [[ $STATUS == "status: COMPLETE" ||
3758 $STATUS == "status: INACTIVE" ]] && return 0
3761 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3763 echo "$param recovery not done in $MAX sec. $STATUS"
3767 wait_recovery_complete () {
3770 # with an assumption that at_max is the same on all nodes
3771 local MAX=${2:-$(max_recovery_time)}
3774 if [ "$FAILURE_MODE" = HARD ]; then
3775 facets=$(facets_on_host $(facet_active_host $facet))
3777 echo affected facets: $facets
3779 facets=${facets//,/ }
3780 # We can use "for" here because we are waiting the slowest.
3781 # The mgs not having the recovery_status proc entry, exclude it
3782 # from the facet list.
3783 for facet in ${facets//mgs/ }; do
3784 local var_svc=${facet}_svc
3785 local param="*.${!var_svc}.recovery_status"
3787 local host=$(facet_active_host $facet)
3788 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3792 wait_mds_ost_sync () {
3793 # just because recovery is done doesn't mean we've finished
3794 # orphan cleanup. Wait for llogs to get synchronized.
3795 echo "Waiting for orphan cleanup..."
3796 # MAX value includes time needed for MDS-OST reconnection
3797 local MAX=$(( TIMEOUT * 2 ))
3798 local WAIT_TIMEOUT=${1:-$MAX}
3801 local list=$(comma_list $(mdts_nodes))
3802 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3803 if ! do_facet $SINGLEMDS \
3804 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3806 # old way, use mds_sync
3808 list=$(comma_list $(osts_nodes))
3809 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3812 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3813 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3814 local -a sync=($(do_nodes $list "$cmd"))
3817 for ((i=0; i<${#sync[@]}; i++)); do
3819 [ ${sync[$i]} -eq 1 ] && continue
3821 [ ${sync[$i]} -eq 0 ] && continue
3823 # there is a not finished MDS-OST synchronization
3827 sleep 2 # increase waiting time and cover statfs cache
3828 [ ${con} -eq 1 ] && return 0
3829 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3833 # show which nodes are not finished.
3834 cmd=$(echo $cmd | sed 's/-n//')
3835 do_nodes $list "$cmd"
3836 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3840 # Wait OSTs to be active on both client and MDT side.
3842 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3843 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3844 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3845 error "wait_update OSTs up on client failed"
3847 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3848 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3849 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3850 error "wait_update OSTs up on MDT0000 failed"
3853 wait_destroy_complete () {
3854 echo "Waiting for MDT destroys to complete"
3855 # MAX value shouldn't be big as this mean server responsiveness
3856 # never increase this just to make test pass but investigate
3857 # why it takes so long time
3860 local list=$(comma_list $(mdts_nodes))
3861 while [ $WAIT -lt $MAX ]; do
3862 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3866 for ((i=0; i<${#RPCs[@]}; i++)); do
3867 [ ${RPCs[$i]} -eq 0 ] && continue
3868 # there are still some destroy RPCs in flight
3872 [ ${con} -eq 1 ] && return 0 # done waiting
3874 echo "Waiting ${WAIT}s for local destroys to complete"
3877 echo "MDT destroys weren't done in $MAX sec."
3881 wait_delete_completed() {
3882 wait_delete_completed_mds $1 || return $?
3883 wait_destroy_complete || return $?
3892 # conf-sanity 31 takes a long time cleanup
3893 while [ $WAIT -lt 300 ]; do
3894 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3895 lctl dl | grep ' ST ' || true")
3896 [ -z "${running}" ] && return 0
3897 echo "waited $WAIT for${running}"
3898 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3900 WAIT=$((WAIT + INTERVAL))
3902 echo "service didn't stop after $WAIT seconds. Still running:"
3907 wait_remote_prog () {
3913 [ "$PDSH" = "no_dsh" ] && return 0
3915 while [ $WAIT -lt $2 ]; do
3916 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3917 grep -v grep) || true
3918 [ -z "${running}" ] && return 0 || true
3919 echo "waited $WAIT for: "
3921 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3923 WAIT=$((WAIT + INTERVAL))
3925 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3926 grep -v grep | awk '{print $2}')
3927 [ -z "$pids" ] && return 0
3928 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3929 # FIXME: not portable
3930 for pid in $pids; do
3931 cat /proc/${pid}/status || true
3932 cat /proc/${pid}/wchan || true
3934 kill -9 $pid || true
3943 local clients=${1:-$CLIENTS}
3946 if [[ -z "$clients" ]]; then
3947 $LFS df $MOUNT > /dev/null || rc=$?
3949 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3956 local clients=${1:-$CLIENTS}
3959 _lfs_df_check "$clients" || rc=$?
3961 check_lfs_df_ret_val $rc
3965 # not every config has many clients
3971 (( MDSCOUNT == 1 )) && return
3973 # wait so that statfs data on MDT expire
3974 local delay=$(do_facet mds1 $LCTL \
3975 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3977 [ -n "$delay" ] || error "fail to get maxage"
3979 local nodes=$(comma_list $(mdts_nodes))
3980 # initiate statfs RPC, all to all MDTs
3981 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3982 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3986 # usually checked on particular client or locally
3996 client_reconnect_try() {
3997 local f=$MOUNT/recon
4000 if [ -z "$CLIENTS" ]; then
4001 $LFS df $MOUNT; uname -n >> $f
4003 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
4005 echo "Connected clients: $(cat $f)"
4006 ls -l $f > /dev/null
4010 client_reconnect() {
4011 # one client_reconnect_try call does not always do the job...
4013 client_reconnect_try && break
4018 affected_facets () {
4021 local host=$(facet_active_host $facet)
4022 local affected=$facet
4024 if [ "$FAILURE_MODE" = HARD ]; then
4025 affected=$(facets_up_on_host $host)
4031 local E2FSCK_ON_MDT0=false
4032 if [ "$1" == "--fsck" ]; then
4034 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4046 #Because it will only get up facets, we need get affected
4047 #facets before shutdown
4048 #For HARD Failure mode, it needs make sure facets on the same
4049 #HOST will only be shutdown and reboot once
4050 for facet in ${facets//,/ }; do
4051 local affected_facet
4053 #check whether facet has been included in other affected facets
4054 for ((index=0; index<$total; index++)); do
4055 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
4058 if [ $skip -eq 0 ]; then
4059 affecteds[$total]=$(affected_facets $facet)
4064 for ((index=0; index<$total; index++)); do
4065 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
4066 local host=$(facet_active_host $facet)
4067 echo "Failing ${affecteds[index]} on $host"
4068 shutdown_facet $facet
4071 echo "$(date +'%H:%M:%S (%s)') shut down"
4076 for facet in ${facets//,/ }; do
4077 local host=$(facet_active_host $facet)
4079 hostlist=$(expand_list $hostlist $host)
4080 if [ $(facet_host $facet) = \
4081 $(facet_failover_host $facet) ]; then
4082 waithostlist=$(expand_list $waithostlist $host)
4086 if [ "$FAILURE_MODE" = HARD ]; then
4087 for host in ${hostlist//,/ }; do
4090 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
4091 # We need to wait the rebooted hosts in case if
4092 # facet_HOST == facetfailover_HOST
4093 if ! [ -z "$waithostlist" ]; then
4094 wait_for_host $waithostlist
4095 if $LOAD_MODULES_REMOTE; then
4096 echo "loading modules on $waithostlist"
4097 do_rpc_nodes $waithostlist load_modules_local
4104 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
4105 change_active $SINGLEMDS
4108 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
4109 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
4113 for ((index=0; index<$total; index++)); do
4114 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
4115 change_active ${affecteds[index]}
4119 init_facets_vars_simple
4121 # start mgs first if it is affected
4122 if ! combined_mgs_mds &&
4123 list_member ${affecteds[index]} mgs; then
4124 mount_facet mgs || error "Restart of mgs failed"
4125 affecteds[index]=$(exclude_items_from_list \
4126 ${affecteds[index]} mgs)
4128 if [ -n "${affecteds[index]}" ]; then
4129 echo mount facets: ${affecteds[index]}
4130 mount_facets ${affecteds[index]} &
4134 for ((index=0; index<$total; index++)); do
4135 if [ -n "${affecteds[index]}" ]; then
4136 wait ${mountpids[index]}
4140 do_nodes $(comma_list $(all_nodes)) \
4141 "keyctl show | grep lustre | cut -c1-11 |
4143 xargs -IX keyctl setperm X 0x3f3f3f3f"
4146 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
4148 if [ "$FAILURE_MODE" = HARD ]; then
4149 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
4150 if ! [ -z "$hostlist" ]; then
4151 wait_for_host $hostlist
4152 if $LOAD_MODULES_REMOTE; then
4153 echo "loading modules on $hostlist"
4154 do_rpc_nodes $hostlist load_modules_local
4159 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
4164 do_facet $facet "sync; sync; sync"
4167 # make sure there will be no seq change
4168 local clients=${CLIENTS:-$HOSTNAME}
4169 local f=fsa-\\\$\(hostname\)
4170 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
4171 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
4173 local svc=${facet}_svc
4174 do_facet $facet $LCTL --device ${!svc} notransno
4176 # If a ZFS OSD is made read-only here, its pool is "freezed". This
4177 # in-memory state has to be cleared by either rebooting the host or
4178 # exporting and reimporting the pool.
4180 # Although the uberblocks are not updated when a pool is freezed,
4181 # transactions are still written to the disks. Modified blocks may be
4182 # cached in memory when tests try reading them back. The
4183 # export-and-reimport process also evicts any cached pool data from
4184 # memory to provide the correct "data loss" semantics.
4186 # In the test framework, the exporting and importing operations are
4187 # handled by stop() and mount_facet() separately, which are used
4188 # inside fail() and fail_abort().
4190 set_dev_readonly $facet
4191 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4192 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4195 replay_barrier_nodf() {
4196 local facet=$1 echo running=${running}
4197 do_facet $facet "sync; sync; sync"
4198 local svc=${facet}_svc
4199 echo Replay barrier on ${!svc}
4200 do_facet $facet $LCTL --device ${!svc} notransno
4201 set_dev_readonly $facet
4202 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4203 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4206 replay_barrier_nosync() {
4207 local facet=$1 echo running=${running}
4208 local svc=${facet}_svc
4209 echo Replay barrier on ${!svc}
4210 do_facet $facet $LCTL --device ${!svc} notransno
4211 set_dev_readonly $facet
4212 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
4213 $LCTL mark "local REPLAY BARRIER on ${!svc}"
4217 # Get Lustre client uuid for a given Lustre mount point.
4220 local mntpnt=${1:-$MOUNT}
4222 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
4223 local uuid=$($LCTL get_param -n llite.$name.uuid)
4228 mds_evict_client() {
4229 local mntpnt=${1:-$MOUNT}
4230 local uuid=$(get_client_uuid $mntpnt)
4232 do_facet $SINGLEMDS \
4233 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
4236 ost_evict_client() {
4237 local mntpnt=${1:-$MOUNT}
4238 local uuid=$(get_client_uuid $mntpnt)
4241 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
4246 local clients=${CLIENTS:-$HOSTNAME}
4248 SK_NO_KEY_save=$SK_NO_KEY
4250 export SK_NO_KEY=false
4252 facet_failover $* || error "failover: $?"
4253 export SK_NO_KEY=$SK_NO_KEY_save
4254 # to initiate all OSC idling connections
4256 wait_clients_import_ready "$clients" "$facets"
4257 clients_up || error "post-failover stat: $?"
4263 facet_failover $facet
4268 local abort_type=${2:-"abort_recovery"}
4271 change_active $facet
4272 wait_for_facet $facet
4273 mount_facet $facet -o $abort_type
4274 clients_up || echo "first stat failed: $?"
4275 clients_up || error "post-failover stat: $?"
4279 # LU-16159: abort recovery will cancel update logs, which may leave broken
4280 # directories in the system, remove name entry if necessary
4281 fail_abort_cleanup() {
4283 find $DIR/$tdir -depth | while read D; do
4284 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
4288 host_nids_address() {
4292 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
4296 if [ "$1" = "'*'" ]; then echo \'*\'; else
4302 if [[ -n "$NETTYPE" ]]; then
4303 h2name_or_ip "$1" "$NETTYPE"
4305 h2name_or_ip "$1" "$2"
4308 declare -fx h2nettype
4310 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4311 # expressions format. As a bonus we can then just pass in those variables
4312 # to pdsh. What this function does is take a HOSTLIST type string and
4313 # expand it into a space deliminated list for us.
4321 [ -z "$hostlist" ] && return
4323 # Translate the case of [..],..,[..] to [..] .. [..]
4324 list="${hostlist/],/] }"
4326 [[ "$front" == *,* ]] && {
4329 list=${list/${old}/${new}}
4332 for item in $list; do
4333 # Test if we have any []'s at all
4334 if [ "$item" != "${item/\[/}" ]; then {
4335 # Expand the [*] into list
4339 if [ "$name" != "$item" ]; then
4340 group=${item#$name[*}
4343 for range in ${group//,/ }; do
4349 # Number of leading zeros
4352 end=$(echo $end | sed 's/0*//')
4353 [[ -z "$end" ]] && end=0
4354 [[ $padlen2 -gt $padlen ]] && {
4355 [[ $padlen2 -eq ${#end} ]] &&
4359 begin=$(echo $begin | sed 's/0*//')
4360 [ -z $begin ] && begin=0
4362 if [ ! -z "${begin##[!0-9]*}" ]; then
4363 order=$(seq -f "%0${padlen}g" $begin $end)
4365 order=$(eval echo {$begin..$end});
4368 for num in $order; do
4369 value="${name#*,}${num}${back}"
4371 [ "$value" != "${value/\[/}" ] && {
4372 value=$(hostlist_expand "$value")
4374 myList="$myList $value"
4379 myList="$myList $item"
4382 myList=${myList//,/ }
4383 myList=${myList:1} # Remove first character which is a space
4385 # Filter any duplicates without sorting
4387 myList="${list%% *}"
4389 while [[ "$list" != ${myList##* } ]]; do
4390 local tlist=" $list"
4392 list=${tlist// ${list%% *} / }
4394 myList="$myList ${list%% *}"
4396 myList="${myList%* }";
4398 # We can select an object at an offset in the list
4401 for item in $myList; do
4403 [ $cnt -eq $offset ] && {
4407 [ $(get_node_count $myList) -ne 1 ] && myList=""
4416 [ "$facet" == client ] && echo -n $HOSTNAME && return
4417 varname=${facet}_HOST
4418 if [ -z "${!varname}" ]; then
4419 if [ "${facet:0:3}" == "ost" ]; then
4420 local fh=${facet%failover}_HOST
4421 eval export ${facet}_HOST=${!fh}
4422 if [ -z "${!varname}" ]; then
4423 eval export ${facet}_HOST=${ost_HOST}
4425 elif [ "${facet:0:3}" == "mdt" -o \
4426 "${facet:0:3}" == "mds" -o \
4427 "${facet:0:3}" == "mgs" ]; then
4429 if [ "${facet}" == "mgsfailover" ] &&
4430 [ -n "$mds1failover_HOST" ]; then
4431 temp=$mds1failover_HOST
4435 eval export ${facet}_HOST=$temp
4441 facet_failover_host() {
4445 var=${facet}failover_HOST
4446 if [ -n "${!var}" ]; then
4451 if combined_mgs_mds && [ $facet == "mgs" ] &&
4452 [ -n "$mds1failover_HOST" ]; then
4453 echo $mds1failover_HOST
4457 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4458 "${facet:0:3}" == "mgs" ]; then
4460 eval export ${facet}failover_host=${mds_HOST}
4465 if [[ $facet == ost* ]]; then
4466 eval export ${facet}failover_host=${ost_HOST}
4474 local activevar=${facet}active
4476 if [ -f $TMP/${facet}active ] ; then
4477 source $TMP/${facet}active
4480 active=${!activevar}
4481 if [ -z "$active" ] ; then
4488 facet_active_host() {
4489 facet_host $(facet_active $1)
4492 # Get the passive failover partner host of facet.
4493 facet_passive_host() {
4495 [[ $facet = client ]] && return
4497 local host=${facet}_HOST
4498 local failover_host=${facet}failover_HOST
4499 local active_host=$(facet_active_host $facet)
4501 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4503 if [[ $active_host = ${!host} ]]; then
4504 echo -n ${!failover_host}
4514 for facet in ${facetlist//,/ }; do
4515 local failover=${facet}failover
4516 local host=`facet_host $failover`
4518 [ -z "$host" ] && return
4520 local curactive=`facet_active $facet`
4522 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4523 eval export ${facet}active=$facet
4525 eval export ${facet}active=$failover
4527 # save the active host for this facet
4528 local activevar=${facet}active
4530 echo "$activevar=${!activevar}" > $TMP/$activevar
4531 [[ $facet = mds1 ]] && combined_mgs_mds && \
4532 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4533 local TO=`facet_active_host $facet`
4534 echo "Failover $facet to $TO"
4542 # do not strip off hostname if verbose, b=19215
4543 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4544 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4550 if [ "$HOST" = "$HOSTNAME" ]; then
4552 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4553 echo "cannot run remote command on $HOST with $myPDSH"
4556 if $VERBOSE && [[ -z "$quiet" ]]; then
4557 echo "CMD: $HOST $*" >&2
4558 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4561 if [[ "$myPDSH" == "rsh" ]] ||
4562 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4563 # we need this because rsh and pdsh do not return
4564 # exit code of an executed command
4565 local command_status="$TMP/cs"
4566 eval $myPDSH $HOST ":> $command_status"
4567 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4568 PATH=\$PATH:/sbin:/usr/sbin;
4570 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4571 echo command failed >$command_status"
4572 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4576 if [[ -n "$verbose" ]]; then
4577 # print HOSTNAME for myPDSH="no_dsh"
4578 if [[ $myPDSH = no_dsh ]]; then
4580 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4581 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4582 sed -e "s/^/${HOSTNAME}: /"
4585 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4586 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4590 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4591 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4592 sed "s/^${HOST}: //"
4594 return ${PIPESTATUS[0]}
4598 # Execute exact command line on host
4600 # The \a host may be on a local or remote node, which is determined at
4601 # the time the command is run. Does careful argument quotation to
4602 # ensure that the exact command line is executed without any globbing,
4603 # substitution, or shell interpretation on the remote side. Does not
4604 # support --verbose or --quiet. Does not include "$host: " prefixes on
4605 # output. See also do_facet_vp().
4607 # usage: do_node_vp "$host" "$command" "$arg"...
4612 if [[ "$host" == "$HOSTNAME" ]]; then
4613 bash -c "$(printf -- ' %q' "$@")"
4617 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4618 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4622 # -N Disable hostname: prefix on lines of output.
4624 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4627 single_local_node () {
4628 [ "$1" = "$HOSTNAME" ]
4631 # Outputs environment variable assignments that should be passed to remote nodes
4635 local facets=$(get_facets)
4638 for var in ${!MODOPTS_*}; do
4639 value=${!var//\"/\\\"}
4640 echo -n " ${var}=\"$value\""
4643 for facet in ${facets//,/ }; do
4645 if [ -n "${!var}" ]; then
4646 echo -n " $var=${!var}"
4650 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4651 if [ -n "${!var}" ]; then
4652 echo -n " $var=${!var}"
4656 for var in VERBOSE; do
4657 if [ -n "${!var}" ]; then
4658 echo -n " $var=${!var}"
4662 if [ -n "$FSTYPE" ]; then
4663 echo -n " FSTYPE=$FSTYPE"
4666 for var in LNETLND NETTYPE; do
4667 if [ -n "${!var}" ]; then
4668 echo -n " $var=${!var}"
4677 # do not strip off hostname if verbose, b=19215
4678 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4679 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4684 if single_local_node $rnodes; then
4685 do_node $verbose $quiet $rnodes "$@"
4689 # This is part from do_node
4692 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4693 echo "cannot run remote command on $rnodes with $myPDSH" &&
4696 export FANOUT=$(get_node_count "${rnodes//,/ }")
4697 if $VERBOSE && [[ -z "$quiet" ]]; then
4698 echo "CMD: $rnodes $*" >&2
4699 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4702 # do not replace anything from pdsh output if -N is used
4703 # -N Disable hostname: prefix on lines of output.
4704 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4705 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4707 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4709 return ${PIPESTATUS[0]}
4713 # Execute commands on a single service's host
4715 # The \a facet (service) may be on a local or remote node, which is
4716 # determined at the time the command is run.
4718 # usage: do_facet $facet command [arg ...]
4723 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4724 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4728 local host=$(facet_active_host $facet)
4730 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4731 do_node $verbose $quiet $host "$@"
4735 # Execute exact command line on the host of a facet
4737 # The \a facet (service) may be on a local or remote node, which is
4738 # determined at the time the command is run. Does careful argument
4739 # quotation to ensure that the exact command line is executed without
4740 # any globbing, substitution, or shell interpretation on the remote
4741 # side. Does not support --verbose or --quiet. Does not include
4742 # "$host: " prefixes on output.
4744 # usage: do_facet_vp "$facet" "$command" "$arg"...
4747 local host=$(facet_active_host "$facet")
4750 if [[ -z "$host" ]]; then
4751 echo "no host defined for facet ${facet}" >&2
4755 do_node_vp "$host" "$@"
4758 # Function: do_facet_random_file $FACET $FILE $SIZE
4759 # Creates FILE with random content on the given FACET of given SIZE
4761 do_facet_random_file() {
4765 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4766 do_facet $facet "$cmd 2>/dev/null"
4769 do_facet_create_file() {
4773 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4774 do_facet $facet "$cmd 2>/dev/null"
4778 do_nodes --verbose "$@"
4784 # make sure its not already running
4786 rm -f $TMP/${facet}active
4787 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4789 # make sure in-tree ldiskfs is loaded before mkfs
4790 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4791 load_module ../ldiskfs/ldiskfs
4794 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4796 if [[ $(facet_fstype $facet) == zfs ]]; then
4798 # After formatting a ZFS target, "cachefile=none" property will
4799 # be set on the ZFS storage pool so that the pool is not
4800 # automatically imported on system startup. And then the pool
4801 # will be exported so as to leave the importing and exporting
4802 # operations handled by mount_facet() and stop() separately.
4804 refresh_partition_table $facet $(facet_vdevice $facet)
4805 disable_zpool_cache $facet
4810 # Device formatted as ost
4813 local DEVNAME=OSTDEV$num
4815 local fstype=$(facet_fstype ost$num)
4819 local dev=ost${num}_dev
4820 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4821 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4822 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4824 #try $OSTZFSDEVn - independent of vdev
4825 DEVNAME=OSTZFSDEV$num
4826 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4828 error "unknown fstype!";;
4834 # Physical device location of data
4840 local fstype=$(facet_fstype ost$num)
4844 # vdevs are not supported by ldiskfs
4847 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4848 # Device formatted by zfs
4850 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4852 error "unknown fstype!";;
4858 # Logical device formatted for lustre
4861 local DEVNAME=MDSDEV$num
4863 local fstype=$(facet_fstype mds$num)
4867 local dev=mds${num}_dev
4868 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4869 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4870 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4872 # try $MDSZFSDEVn - independent of vdev
4873 DEVNAME=MDSZFSDEV$num
4874 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4876 error "unknown fstype!";;
4882 # Physical location of data
4886 local fstype=$(facet_fstype mds$num)
4890 # vdevs are not supported by ldiskfs
4893 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4894 # Device formatted by ZFS
4895 local DEVNAME=MDSDEV$num
4896 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4898 error "unknown fstype!";;
4906 local fstype=$(facet_fstype mgs)
4910 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4911 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4912 DEVPTR=$(mdsdevname 1)
4914 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4918 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4919 ( [ -z "$MGSZFSDEV" ] &&
4920 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4921 DEVPTR=$(mdsdevname 1)
4923 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4926 error "unknown fstype!";;
4935 local fstype=$(facet_fstype mgs)
4939 # vdevs are not supported by ldiskfs
4942 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4943 ( [ -z "$MGSDEV" ] &&
4944 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4945 VDEVPTR=$(mdsvdevname 1)
4946 elif [ -n "$MGSDEV" ]; then
4950 error "unknown fstype!";;
4958 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4960 local var=${facet}_MOUNT
4961 eval mntpt=${!var:-${MOUNT}-$facet}
4968 local dev=$(facet_device $facet)
4969 local mnt=${2:-$(facet_mntpt $facet)}
4973 if dm_flakey_supported $facet; then
4974 dm_dev=$(dm_create_dev $facet $dev)
4975 [[ -n "$dm_dev" ]] || dm_dev=$dev
4977 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4978 export_dm_dev $facet $dm_dev
4980 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4985 local dev=$(facet_device $facet)
4986 local mnt=${2:-$(facet_mntpt $facet)}
4988 do_facet $facet $UMOUNT $mnt
4992 echo -n "$1" | tr -c '[:alnum:]\n' '_'
4997 local ds=$(facet_device $facet)
4998 local mnt=${2:-$(facet_mntpt $facet)}
5003 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
5004 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
5005 do_facet $facet $ZFS set canmount=noauto $ds
5007 # The "legacy" mount method is used here because "zfs unmount $mnt"
5008 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
5009 # targets are not available at the time, the stat(2) on $MOUNT will
5012 do_facet $facet $ZFS set mountpoint=legacy $ds
5013 do_facet $facet mount -t zfs $ds $mnt
5014 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
5015 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
5020 local ds=$(facet_device $facet)
5021 local mnt=${2:-$(facet_mntpt $facet)}
5022 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
5023 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
5024 local mntpt=${!var_mntpt}
5025 local canmnt=${!var_canmnt}
5029 do_facet $facet umount $mnt
5030 do_facet $facet $ZFS set mountpoint=$mntpt $ds
5031 do_facet $facet $ZFS set canmount=$canmnt $ds
5038 local fstype=$(facet_fstype $facet)
5040 mount_$fstype $facet $mnt
5046 local fstype=$(facet_fstype $facet)
5048 unmount_$fstype $facet $mnt
5055 # make sure we are using the primary server, so test-framework will
5056 # be able to clean up properly.
5057 activemds=`facet_active mds1`
5058 if [ $activemds != "mds1" ]; then
5062 local clients=$CLIENTS
5063 [ -z $clients ] && clients=$(hostname)
5065 zconf_umount_clients $clients $MOUNT "$*" || true
5066 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
5068 [ -n "$CLIENTONLY" ] && return
5070 # The add fn does rm ${facet}active file, this would be enough
5071 # if we use do_facet <facet> only after the facet added, but
5072 # currently we use do_facet mds in local.sh
5074 for num in `seq $MDSCOUNT`; do
5076 rm -f ${TMP}/mds${num}active
5078 combined_mgs_mds && rm -f $TMP/mgsactive
5080 for num in `seq $OSTCOUNT`; do
5082 rm -f $TMP/ost${num}active
5085 if ! combined_mgs_mds ; then
5089 if $SHARED_KEY; then
5090 export SK_MOUNTED=false
5096 cleanup_echo_devs () {
5099 local devs=$($LCTL dl | grep echo | awk '{print $4}')
5101 for dev in $devs; do
5102 $LCTL --device $dev cleanup
5103 $LCTL --device $dev detach
5108 nfs_client_mode && return
5109 cifs_client_mode && return
5112 CLEANUP_DM_DEV=true stopall $*
5119 combined_mgs_mds () {
5120 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
5121 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
5125 echo -n "$1" | tr '[:upper:]' '[:lower:]'
5129 echo -n "$1" | tr '[:lower:]' '[:upper:]'
5141 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
5142 for i in $(echo "$var"); do
5143 if [ "$i" == "-O" ]; then
5145 first_o=$(($first_o + 1))
5148 if [ "$i" == "-E" ]; then
5150 first_e=$(($first_e + 1 ))
5155 [ $first_o -gt 1 ] && opt_o+=",";
5159 [ $first_e -gt 1 ] && opt_e+=",";
5170 [ -n "$opt_o" ] && echo " -O $opt_o"
5171 [ -n "$opt_e" ] && echo " -E $opt_e"
5177 local fsname=${3:-"$FSNAME"}
5178 local type=$(facet_type $facet)
5179 local index=$(facet_index $facet)
5180 local fstype=$(facet_fstype $facet)
5181 local host=$(facet_host $facet)
5185 local varbs=${facet}_BLOCKSIZE
5187 if [ $type == MGS ] || ( [ $type == MDS ] &&
5188 [ "$dev" == $(mgsdevname) ] &&
5189 [ "$host" == "$(facet_host mgs)" ] ); then
5192 opts="--mgsnode=$MGSNID"
5195 if [ $type != MGS ]; then
5196 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
5200 var=${facet}failover_HOST
5201 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
5202 opts+=" --failnode=$(h2nettype ${!var})"
5205 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
5206 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
5208 if [ $type == MDS ]; then
5209 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
5210 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
5211 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
5213 if [ $fstype == ldiskfs ]; then
5215 if [ -n "${!var}" ]; then
5216 fs_mkfs_opts+=" -J device=${!var}"
5218 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
5220 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
5224 if [ $type == OST ]; then
5225 if [ $fstype == ldiskfs ]; then
5227 if [ -n "${!var}" ]; then
5228 fs_mkfs_opts+=" -J device=${!var}"
5230 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
5235 opts+=" --backfstype=$fstype"
5238 if [ -n "${!var}" ]; then
5239 opts+=" --device-size=${!var}"
5242 var=$(upper $fstype)_MKFS_OPTS
5243 fs_mkfs_opts+=${!var:+" ${!var}"}
5245 var=${type}_FS_MKFS_OPTS
5246 fs_mkfs_opts+=${!var:+" ${!var}"}
5248 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
5250 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
5251 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
5253 if [ -n "${fs_mkfs_opts## }" ]; then
5254 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
5258 opts+=${!var:+" ${!var}"}
5265 local type=$(facet_type $facet)
5266 local var=${type}_MOUNT_FS_OPTS
5268 if [ -n "${!var}" ]; then
5269 opts+=" --mountfsoptions=${!var}"
5274 check_ost_indices() {
5275 local index_count=${#OST_INDICES[@]}
5276 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
5278 # OST count is greater than the index count in $OST_INDEX_LIST.
5279 # We need check whether there are duplicate indices.
5283 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
5284 index=$(facet_index ost$i)
5285 for j in $(seq 0 $((index_count - 1))); do
5286 [[ $index -ne ${OST_INDICES[j]} ]] ||
5287 error "ost$i has the same index $index as ost$((j+1))"
5294 local facet_type=$1 # mgs || mds || ost
5296 local facet=${1}${2}
5299 case "$(facet_fstype $facet)" in
5301 device=$(${facet_type}devname $facet_num)
5304 device=$(${facet_type}vdevname $facet_num)
5307 error "Unhandled filesystem type"
5311 do_facet $facet "[ -e \"$device\" ]" && return
5313 # Note: the following check only works with absolute paths
5314 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5315 error "$facet: device '$device' does not exist"
5317 # zpool create doesn't like empty files
5318 [[ $(facet_fstype $facet) == zfs ]] && return 0
5320 do_facet $facet "touch \"${device}\""
5329 echo "Format mgs: $(mgsdevname)"
5330 reformat_external_journal mgs
5332 # touch "device" in case it is a loopback file for testing and needs to
5333 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5334 # to non-existent files in /dev if the admin made a typo during setup
5337 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5338 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5348 echo "Format mds$num: $(mdsdevname $num)"
5349 reformat_external_journal mds$num
5351 __touch_device mds $num
5353 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5354 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5355 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5364 echo "Format ost$num: $(ostdevname $num)"
5365 reformat_external_journal ost$num
5367 __touch_device ost $num
5369 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5370 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5371 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5376 # Set hostid for ZFS/SPL zpool import protection
5377 # (Assumes MDS version is also OSS version)
5378 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5380 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5383 # We need ldiskfs here, may as well load them all
5385 [ -n "$CLIENTONLY" ] && return
5386 echo Formatting mgs, mds, osts
5387 if ! combined_mgs_mds ; then
5391 for num in $(seq $MDSCOUNT); do
5395 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5397 for num in $(seq $OSTCOUNT); do
5403 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5407 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5410 # usage: switch_identity MDSNUM ENABLE_UPCALL
5413 # 0: success, the identity upcall was previously enabled already.
5414 # 1: success, the identity upcall was previously disabled.
5420 local MDT="$(mdtname_from_index $((num - 1)) $MOUNT)"
5421 local upcall="$L_GETIDENTITY"
5423 [[ -n "$MDT" ]] || return 2
5425 local param="mdt.$MDT.identity_upcall"
5426 local old="$(do_facet $facet "lctl get_param -n $param")"
5428 [[ "$enable" == "true" ]] || upcall="NONE"
5430 do_facet $facet "lctl set_param -n $param='$upcall'" || return 2
5431 do_facet $facet "lctl set_param -n mdt.$MDT.identity_flush=-1"
5433 [[ "$old" != "NONE" ]] # implicit "&& return 0 || return 1"
5438 zconf_umount $HOSTNAME $1 || error "umount failed"
5439 zconf_mount $HOSTNAME $1 || error "mount failed"
5447 rm -f $TMP/${facet}active
5448 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5453 local mdt_count=${1:-$MDSCOUNT}
5454 local ost_count=${2:-$OSTCOUNT}
5457 for num in $(seq $mdt_count); do
5458 DEVNAME=$(mdsdevname $num)
5459 writeconf_facet mds$num $DEVNAME || rc=$?
5462 for num in $(seq $ost_count); do
5463 DEVNAME=$(ostdevname $num)
5464 writeconf_facet ost$num $DEVNAME || rc=$?
5470 if ! combined_mgs_mds ; then
5471 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5480 for num in $(seq $MDSCOUNT); do
5481 devname=$(mdsdevname $num)
5482 start mds$num $devname $MDS_MOUNT_OPTS
5484 # We started mds$num, now we should set mds${num}_HOST
5485 # and mds${num}failover_HOST variables properly if they
5487 host=$(facet_host mds$num)
5488 for varname in mds${num}_HOST mds${num}failover_HOST; do
5489 if [[ -z "${!varname}" ]]; then
5493 if [[ "$IDENTITY_UPCALL" != "default" ]]; then
5494 switch_identity $num $IDENTITY_UPCALL
5502 for num in $(seq $OSTCOUNT); do
5504 rm -f $TMP/ost${num}active
5513 for num in $(seq $OSTCOUNT); do
5514 devname=$(ostdevname $num)
5515 start ost$num $devname $OST_MOUNT_OPTS
5517 # We started ost$num, now we should set ost${num}_HOST
5518 # and ost${num}failover_HOST variables properly if they
5520 host=$(facet_host ost$num)
5521 for varname in ost${num}_HOST ost${num}failover_HOST; do
5522 if [[ -z "${!varname}" ]]; then
5530 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5531 if [ ! -z $arg1 ]; then
5532 [ "$arg1" = "server_only" ] && return
5535 if [ -n "$CLIENTS" ]; then
5536 zconf_mount_clients $CLIENTS $MOUNT
5540 if [ "$MOUNT_2" ]; then
5541 mount_client $MOUNT2
5542 if [ -n "$CLIENTS" ]; then
5543 zconf_mount_clients $CLIENTS $MOUNT2
5548 sk_nodemap_setup() {
5549 local sk_map_name=${1:-$SK_S2SNM}
5550 local sk_map_nodes=${2:-$HOSTNAME}
5551 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5552 for servernode in $sk_map_nodes; do
5553 local nids=$(do_nodes $servernode "$LCTL list_nids")
5554 for nid in $nids; do
5555 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5556 $sk_map_name --range $nid"
5564 nfs_client_mode && return
5565 cifs_client_mode && return
5567 sanity_mount_check || error "environments are insane!"
5573 if [ -z "$CLIENTONLY" ]; then
5574 echo Setup mgs, mdt, osts
5575 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5577 if $SK_MOUNTED; then
5578 echo "Shared Key file system already mounted"
5583 if $SHARED_KEY; then
5584 export SK_MOUNTED=true
5588 echo "GSS_SK: setting kernel keyring perms"
5589 do_nodes $(comma_list $(all_nodes)) \
5590 "keyctl show | grep lustre | cut -c1-11 |
5592 xargs -IX keyctl setperm X 0x3f3f3f3f"
5595 # Need to start one nodemap for servers,
5596 # and one for clients.
5597 sk_nodemap_setup $SK_S2SNM \
5598 $(comma_list $(all_server_nodes))
5600 sk_nodemap_setup $SK_S2SNMCLI \
5601 ${CLIENTS:-$HOSTNAME}
5602 echo "Nodemap set up for SK S2S, remounting."
5611 # wait a while to allow sptlrpc configuration be propogated to targets,
5612 # only needed when mounting new target devices.
5620 # by remounting mdt before ost, initial connect from mdt to ost might
5621 # timeout because ost is not ready yet. wait some time to its fully
5622 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5623 # preceeded by a context negotiation rpc with $TIMEOUT.
5624 # FIXME better by monitoring import status.
5627 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5628 set_rule $FSNAME any cli2ost $SK_FLAVOR
5629 if $SK_SKIPFIRST; then
5630 export SK_SKIPFIRST=false
5634 "lctl set_param osc.*.idle_connect=1"
5637 wait_flavor cli2mdt $SK_FLAVOR
5638 wait_flavor cli2ost $SK_FLAVOR
5643 sleep $((TIMEOUT + 5))
5649 mounted_lustre_filesystems() {
5650 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5653 init_facet_vars () {
5654 [ -n "$CLIENTONLY" ] && return 0
5661 eval export ${facet}_dev=${device}
5662 eval export ${facet}_opt=\"$*\"
5664 local dev=${facet}_dev
5666 # We need to loop for the label
5667 # in case its not initialized yet.
5668 for wait_time in {0,1,3,5,10}; do
5670 if [ $wait_time -gt 0 ]; then
5671 echo "${!dev} not yet initialized,"\
5672 "waiting ${wait_time} seconds."
5676 local label=$(devicelabel ${facet} ${!dev})
5678 # Check to make sure the label does
5679 # not include ffff at the end of the label.
5680 # This indicates it has not been initialized yet.
5682 if [[ $label =~ [f|F]{4}$ ]]; then
5683 # label is not initialized, unset the result
5684 # and either try again or fail
5691 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5693 eval export ${facet}_svc=${label}
5695 local varname=${facet}failover_HOST
5696 if [ -z "${!varname}" ]; then
5698 if combined_mgs_mds && [ $facet == "mgs" ] &&
5699 [ -n "$mds1failover_HOST" ]; then
5700 temp=$mds1failover_HOST
5702 temp=$(facet_host $facet)
5704 eval export $varname=$temp
5707 varname=${facet}_HOST
5708 if [ -z "${!varname}" ]; then
5709 eval export $varname=$(facet_host $facet)
5712 # ${facet}failover_dev is set in cfg file
5713 varname=${facet}failover_dev
5714 if [ -n "${!varname}" ] ; then
5715 eval export ${facet}failover_dev=${!varname}
5717 eval export ${facet}failover_dev=$device
5720 # get mount point of already mounted device
5721 # is facet_dev is already mounted then use the real
5722 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5723 # i.e. ${facet}_MOUNT if specified by user or default
5724 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5725 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5726 if [ -z $mntpt ]; then
5727 mntpt=$(facet_mntpt $facet)
5729 eval export ${facet}_MOUNT=$mntpt
5732 init_facets_vars () {
5735 if ! remote_mds_nodsh; then
5736 for num in $(seq $MDSCOUNT); do
5737 DEVNAME=$(mdsdevname $num)
5738 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5742 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5744 if ! remote_ost_nodsh; then
5745 for num in $(seq $OSTCOUNT); do
5746 DEVNAME=$(ostdevname $num)
5747 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5752 init_facets_vars_simple () {
5755 if ! remote_mds_nodsh; then
5756 for num in $(seq $MDSCOUNT); do
5757 devname=$(mdsdevname $num)
5758 eval export mds${num}_dev=${devname}
5759 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5763 if ! combined_mgs_mds ; then
5764 eval export mgs_dev=$(mgsdevname)
5765 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5768 if ! remote_ost_nodsh; then
5769 for num in $(seq $OSTCOUNT); do
5770 devname=$(ostdevname $num)
5771 eval export ost${num}_dev=${devname}
5772 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5777 osc_ensure_active () {
5782 while [ $period -lt $timeout ]; do
5783 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5784 if [ $count -eq 0 ]; then
5788 echo "$count OST inactive, wait $period seconds, and try again"
5790 period=$((period+3))
5793 [ $period -lt $timeout ] ||
5794 log "$count OST are inactive after $timeout seconds, give up"
5797 set_conf_param_and_check() {
5801 local ORIG=$(do_facet $myfacet "$TEST")
5802 if [ $# -gt 3 ]; then
5808 echo "Setting $PARAM from $ORIG to $FINAL"
5809 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5810 error "conf_param $PARAM failed"
5812 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5813 error "check $PARAM failed!"
5816 set_persistent_param() {
5820 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5822 if [ $# -gt 3 ]; then
5829 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5830 echo "Setting $test_param from $orig to $final"
5831 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5832 error "$PERM_CMD $test_param failed"
5834 echo "Setting $param from $orig to $final"
5835 do_facet mgs "$PERM_CMD $param='$final'" ||
5836 error "$PERM_CMD $param failed"
5840 set_persistent_param_and_check() {
5844 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5846 if [ $# -gt 3 ]; then
5853 set_persistent_param $myfacet $test_param $param "$final"
5855 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5856 error "check $param failed!"
5859 init_param_vars () {
5860 TIMEOUT=$(lctl get_param -n timeout)
5861 TIMEOUT=${TIMEOUT:-20}
5863 if [ -n "$arg1" ]; then
5864 [ "$arg1" = "server_only" ] && return
5867 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5869 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5870 log "Using TIMEOUT=$TIMEOUT"
5872 # tune down to speed up testing on (usually) small setups
5873 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5874 do_nodes $(comma_list $(nodes_list)) \
5875 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5877 osc_ensure_active $SINGLEMDS $TIMEOUT
5878 osc_ensure_active client $TIMEOUT
5879 $LCTL set_param osc.*.idle_timeout=debug
5881 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5882 local current_jobid_var=$($LCTL get_param -n jobid_var)
5884 if [ $JOBID_VAR = "existing" ]; then
5885 echo "keeping jobstats as $current_jobid_var"
5886 elif [ $current_jobid_var != $JOBID_VAR ]; then
5887 echo "setting jobstats to $JOBID_VAR"
5889 set_persistent_param_and_check client \
5890 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5893 echo "jobstats not supported by server"
5896 if [ $QUOTA_AUTO -ne 0 ]; then
5897 if [ "$ENABLE_QUOTA" ]; then
5898 echo "enable quota as required"
5899 setup_quota $MOUNT || return 2
5901 echo "disable quota as required"
5902 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5906 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5907 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5911 nfs_client_mode () {
5912 if [ "$NFSCLIENT" ]; then
5913 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5914 local clients=$CLIENTS
5916 [ -z $clients ] && clients=$(hostname)
5918 # FIXME: remove hostname when 19215 fixed
5919 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5920 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5921 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5922 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5923 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5925 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5931 cifs_client_mode () {
5932 [ x$CIFSCLIENT = xyes ] &&
5933 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5936 check_config_client () {
5938 local mounted=$(mount | grep " $mntpt ")
5940 if [ -n "$CLIENTONLY" ]; then
5942 # CLIENTONLY should not depend on *_HOST settings
5943 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5944 # in theory someone could create a new,
5945 # client-only config file that assumed lustre was already
5946 # configured and didn't set the MGSNID. If MGSNID is not set,
5947 # then we should use the mgs nid currently being used
5948 # as the default value. bug 18021
5949 [[ x$MGSNID = x ]] &&
5952 if [[ x$mgc != xMGC$MGSNID ]]; then
5953 if [ "$mgs_HOST" ]; then
5954 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
5955 grep PING | awk '{print $3}' |
5956 sed -e "s/(//g" -e "s/)//g")
5958 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5959 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5965 echo Checking config lustre mounted on $mntpt
5966 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5967 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5971 check_config_clients () {
5972 local clients=${CLIENTS:-$HOSTNAME}
5975 nfs_client_mode && return
5976 cifs_client_mode && return
5978 do_rpc_nodes "$clients" check_config_client $mntpt
5980 sanity_mount_check || error "environments are insane!"
5984 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5985 local cltimeout=$(lctl get_param -n timeout)
5986 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5987 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
5994 [ -z $mntpt ] && return 1
5995 local mounted=$(mounted_lustre_filesystems)
5997 echo $mounted' ' | grep -w -q $mntpt' '
6002 local ostsn=${2:-$OSTCOUNT}
6003 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
6006 echo ostsn=$ostsn npools=$npools
6007 if [[ $ostsn -gt $OSTCOUNT ]]; then
6008 echo "request to use $ostsn OSTs in the pool, \
6009 using max available OSTCOUNT=$OSTCOUNT"
6012 for (( n=0; n < $npools; n++ )); do
6014 if ! $DELETE_OLD_POOLS; then
6015 log "request to not delete old pools: $FSNAME.$p exist?"
6016 if ! check_pool_not_exist $FSNAME.$p; then
6017 echo "Using existing $FSNAME.$p"
6018 $LCTL pool_list $FSNAME.$p
6022 create_pool $FSNAME.$p $KEEP_POOLS ||
6023 error "create_pool $FSNAME.$p failed"
6025 local first=$(( (n * ostsn) % OSTCOUNT ))
6026 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
6027 if [[ $first -le $last ]]; then
6028 pool_add_targets $p $first $last ||
6029 error "pool_add_targets $p $first $last failed"
6031 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
6032 error "pool_add_targets $p $first \
6033 $(( OSTCOUNT - 1 )) failed"
6034 pool_add_targets $p 0 $last ||
6035 error "pool_add_targets $p 0 $last failed"
6040 set_pools_quota () {
6047 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
6048 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
6050 # POOLS_QUOTA_USERS_SET=
6051 # "quota15_1:20M -- for all of the found pools
6052 # quota15_2:1G:gpool0
6053 # quota15_3 -- for global limit only
6054 # quota15_4:200M:gpool0
6055 # quota15_4:200M:gpool1"
6057 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
6059 declare -A pq_limits
6061 for ((i=0; i<${#pq_userset[@]}; i++)); do
6062 u=${pq_userset[i]%%:*}
6064 # user gets no pool limits if
6065 # POOLS_QUOTA_USERS_SET does not specify it
6066 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
6067 pq_limits[$u]+=" $o"
6069 pq_users=(${!pq_limits[@]})
6074 for ((i=0; i<${#pq_users[@]}; i++)); do
6076 # set to max limit (_u64)
6077 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
6078 opts=(${pq_limits[$u]})
6079 for ((j=0; j<${#opts[@]}; j++)); do
6082 # Set limit for all existing pools if
6084 if [ $p == $o ]; then
6085 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
6086 echo "No pool specified for $u,
6087 set limit $o for all existing pools"
6090 $LFS setquota -u $u -B $o --pool $pool $DIR ||
6091 error "setquota -u $u -B $o \
6092 --pool $pool failed"
6095 $LFS quota -uv $u --pool $DIR
6099 do_check_and_setup_lustre() {
6100 # If auster does not want us to setup, then don't.
6101 ! ${do_setup} && return
6103 echo "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
6106 nfs_client_mode && return
6107 cifs_client_mode && return
6109 local MOUNTED=$(mounted_lustre_filesystems)
6113 # both MOUNT and MOUNT2 are not mounted
6114 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6115 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
6116 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
6118 is_mounted $MOUNT || error "NAME=$NAME not mounted"
6119 export I_MOUNTED=yes
6123 elif is_mounted $MOUNT2; then
6125 # MOUNT2 is mounted, while MOUNT_2 is not set
6126 if ! [ "$MOUNT_2" ]; then
6127 cleanup_mount $MOUNT2
6128 export I_UMOUNTED2=yes
6131 # MOUNT2 is mounted, MOUNT_2 is set
6133 # FIXME: what to do if check_config failed?
6135 # 1) remote client has mounted other Lustre fs ?
6136 # 2) it has insane env ?
6137 # try to umount MOUNT2 on all clients and mount again:
6138 if ! check_config_clients $MOUNT2; then
6139 cleanup_mount $MOUNT2
6140 restore_mount $MOUNT2
6141 export I_MOUNTED2=yes
6145 # MOUNT is mounted MOUNT2 is not mounted
6146 elif [ "$MOUNT_2" ]; then
6147 restore_mount $MOUNT2
6148 export I_MOUNTED2=yes
6152 # FIXME: what to do if check_config failed?
6154 # 1) remote client has mounted other Lustre fs?
6155 # 2) lustre is mounted on remote_clients atall ?
6156 check_config_clients $MOUNT
6160 set_default_debug_nodes $(comma_list $(nodes_list))
6164 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
6166 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
6167 facets="$(get_facets OST)"
6168 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
6169 facets="$facets,$(get_facets MDS)"
6170 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
6171 facets="$facets,mgs"
6172 local nodes="$(facets_hosts ${facets})"
6173 if [ -n "$nodes" ] ; then
6174 do_nodes $nodes "$LCTL set_param \
6175 osd-ldiskfs.track_declares_assert=1 || true"
6179 if [ -n "$fs_STRIPEPARAMS" ]; then
6180 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
6189 if $DELETE_OLD_POOLS; then
6193 if [[ -n "$FS_POOL" ]]; then
6194 create_pools $FS_POOL $FS_POOL_NOSTS
6197 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
6201 # set tunable parameters passed to test environment
6205 echo "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
6207 if [[ "$ONLY" == "setup" ]]; then
6212 check_and_setup_lustre() {
6213 local start_stamp=$(date +%s)
6214 local saved_umask=$(umask)
6215 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
6224 log_sub_test_begin test_setup
6226 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
6227 error=$(tail -1 $log)
6232 stop_stamp=$(date +%s)
6233 duration=$((stop_stamp - start_stamp))
6235 log_sub_test_end "$status" "$duration" "$rc" "$error"
6243 local clients=${CLIENTS:-$HOSTNAME}
6246 zconf_mount_clients $clients $mntpt
6250 local clients=${CLIENTS:-$HOSTNAME}
6253 zconf_umount_clients $clients $mntpt
6256 cleanup_and_setup_lustre() {
6257 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
6258 lctl set_param debug=0 || true
6261 if [[ "$ONLY" == "cleanup" ]]; then
6266 do_check_and_setup_lustre
6269 # Run e2fsck on MDT or OST device.
6274 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
6275 local log=$TMP/e2fsck.log
6278 # turn on pfsck if it is supported
6279 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
6281 do_node $node $cmd 2>&1 | tee $log
6283 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
6285 if [ $MDSCOUNT -gt 1 ]; then
6286 skip_noexit "DNE mode isn't supported!"
6290 error "It's not DNE mode."
6295 [ $rc -le $FSCK_MAX_ERR ] ||
6296 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6302 # Run resize2fs on MDT or OST device.
6311 do_facet $facet "$RESIZE2FS $opts $device $size"
6314 # verify a directory is shared among nodes.
6315 check_shared_dir() {
6317 local list=${2:-$(comma_list $(nodes_list))}
6319 [ -z "$dir" ] && return 1
6320 do_rpc_nodes "$list" check_logdir $dir
6321 check_write_access $dir "$list" || return 1
6326 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
6327 $LCTL set_param printk=+lfsck
6328 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6330 for k in $(seq $MDSCOUNT); do
6331 # wait up to 10+1 minutes for LFSCK to complete
6332 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6333 mdd.$(facet_svc mds${k}).lfsck_layout |
6334 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6335 error "MDS${k} layout isn't the expected 'completed'"
6336 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6337 mdd.$(facet_svc mds${k}).lfsck_namespace |
6338 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6339 error "MDS${k} namespace isn't the expected 'completed'"
6341 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
6342 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
6343 awk '/repaired/ { print $2 }' | calc_sum)
6344 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
6345 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
6346 awk '/repaired/ { print $2 }' | calc_sum)
6347 local repaired=$((rep_mdt + rep_ost))
6348 [ $repaired -eq 0 ] ||
6349 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6352 dump_file_contents() {
6358 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6359 error_noexit false \
6360 "Invalid parameters for dump_file_contents()"
6363 for node in ${nodes}; do
6364 do_node $node "for i in \\\$(find $dir -type f); do
6365 echo ====\\\${i}=======================;
6367 done" >> ${logname}.${node}.log
6371 dump_command_output() {
6377 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6378 error_noexit false \
6379 "Invalid parameters for dump_command_output()"
6383 for node in ${nodes}; do
6384 do_node $node "echo ====${cmd}=======================;
6385 $cmd" >> ${logname}.${node}.log
6392 # dump file contents from /proc/spl in case of zfs test
6393 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6394 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6395 dump_command_output \
6396 "$(osts_nodes)" "zpool events -v" "${logname}"
6399 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6400 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6401 dump_command_output \
6402 "$(mdts_nodes)" "zpool events -v" "${logname}"
6406 do_check_and_cleanup_lustre() {
6407 echo "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6409 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6410 "$TESTSUITE" != "sanity-scrub" ]]; then
6414 if is_mounted $MOUNT; then
6415 if $DO_CLEANUP; then
6416 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6417 error "remove sub-test dirs failed"
6421 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6424 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6425 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6428 if [[ "$I_MOUNTED2" == "yes" ]]; then
6429 cleanup_mount $MOUNT2
6432 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6433 cleanupall -f || error "cleanup failed"
6437 echo "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6440 check_and_cleanup_lustre() {
6441 local start_stamp=$(date +%s)
6442 local saved_umask=$(umask)
6443 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6452 log_sub_test_begin test_cleanup
6454 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6455 error=$(tail -1 $log)
6460 stop_stamp=$(date +%s)
6461 duration=$((stop_stamp - start_stamp))
6463 log_sub_test_end "$status" "$duration" "$rc" "$error"
6473 wait_for_function () {
6476 # suppress fn both stderr and stdout
6477 if [ "$1" = "--quiet" ]; then
6479 quiet=" > /dev/null 2>&1"
6490 eval $fn $quiet && return 0
6492 [ $wait -lt $max ] || return 1
6493 echo waiting $fn, $((max - wait)) secs left ...
6494 wait=$((wait + sleep))
6495 [ $wait -gt $max ] && ((sleep -= wait - max))
6505 [ "$host" = "$HOSTNAME" ] && return 0
6507 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6508 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6518 # Convert a space-delimited list to a comma-delimited list. If the input is
6519 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6521 # echo is used to convert newlines to spaces, since it doesn't
6522 # introduce a trailing space as using "tr '\n' ' '" does
6523 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6529 echo $list | grep -qw $item
6532 # list, excluded are the comma separated lists
6533 exclude_items_from_list () {
6539 for item in ${excluded//,/ }; do
6540 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6542 echo $(comma_list $list)
6545 # list, expand are the comma separated lists
6547 local list=${1//,/ }
6548 local expand=${2//,/ }
6551 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6552 echo $(comma_list $expanded)
6555 testslist_filter () {
6556 local script=$LUSTRE/tests/${TESTSUITE}.sh
6558 [ -f $script ] || return 0
6560 local start_at=$START_AT
6561 local stop_at=$STOP_AT
6563 local var=${TESTSUITE//-/_}_START_AT
6564 [ x"${!var}" != x ] && start_at=${!var}
6565 var=${TESTSUITE//-/_}_STOP_AT
6566 [ x"${!var}" != x ] && stop_at=${!var}
6568 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6569 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6570 /^'${start_at}'$/ {flag = 0}
6571 {if (flag == 1) print $0}
6572 /^'${stop_at}'$/ { flag = 1 }'
6576 (cd `dirname $1`; echo $PWD/`basename $1`)
6580 local types=${1:-"OST MDS MGS"}
6584 for entry in $types; do
6585 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6586 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6589 MGS ) list="$list $name";;
6590 MDS|OST|AGT ) local count=${type}COUNT
6591 for ((i=1; i<=${!count}; i++)) do
6592 list="$list ${name}$i"
6594 * ) error "Invalid facet type"
6598 echo $(comma_list $list)
6601 ##################################
6602 # Adaptive Timeouts funcs
6605 # only check mds, we assume at_max is the same on all nodes
6606 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6608 if [ $at_max -eq 0 ]; then
6619 # suppose that all ost-s have the same $at value set
6620 [ $facet != "ost" ] || facet=ost1
6622 do_facet $facet "lctl get_param -n $at"
6636 for facet in "$@"; do
6637 if [ $facet == "ost" ]; then
6638 facet=$(get_facets OST)
6639 elif [ $facet == "mds" ]; then
6640 facet=$(get_facets MDS)
6642 hosts=$(expand_list $hosts $(facets_hosts $facet))
6645 do_nodes $hosts lctl set_param at_max=$at_max
6659 for facet in "$@"; do
6660 if [ $facet == "ost" ]; then
6661 facet=$(get_facets OST)
6662 elif [ $facet == "mds" ]; then
6663 facet=$(get_facets MDS)
6665 hosts=$(expand_list $hosts $(facets_hosts $facet))
6668 do_nodes $hosts lctl set_param at_min=$at_min
6671 ##################################
6675 # OBD_FAIL_MDS_ALL_REQUEST_NET
6677 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6678 do_facet client "$1" || RC=$?
6679 do_facet $SINGLEMDS lctl set_param fail_loc=0
6684 # OBD_FAIL_MDS_ALL_REPLY_NET
6686 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6688 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6692 drop_reint_reply() {
6693 # OBD_FAIL_MDS_REINT_NET_REP
6695 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6697 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6701 drop_update_reply() {
6702 # OBD_FAIL_OUT_UPDATE_NET_REP
6706 do_facet mds${index} lctl set_param fail_loc=0x1701
6707 do_facet client "$@" || RC=$?
6708 do_facet mds${index} lctl set_param fail_loc=0
6713 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6716 local timeout=${2:-0}
6717 # default is (obd_timeout / 4) if unspecified
6718 echo "timeout is $timeout/$2"
6719 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6720 do_facet client "$1" || RC=$?
6721 do_facet client "sync"
6722 do_facet ost1 lctl set_param fail_loc=0
6726 drop_ldlm_cancel() {
6727 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6729 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6730 do_nodes $list lctl set_param fail_loc=0x304
6732 do_facet client "$@" || RC=$?
6734 do_nodes $list lctl set_param fail_loc=0
6738 drop_bl_callback_once() {
6740 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6741 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6742 do_facet client lctl set_param fail_loc=0x80000305
6743 do_facet client "$@" || rc=$?
6744 do_facet client lctl set_param fail_loc=0
6745 do_facet client lctl set_param fail_val=0
6746 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6750 drop_bl_callback() {
6752 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6753 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6754 do_facet client lctl set_param fail_loc=0x305
6755 do_facet client "$@" || rc=$?
6756 do_facet client lctl set_param fail_loc=0
6757 do_facet client lctl set_param fail_val=0
6758 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6762 drop_mdt_ldlm_reply() {
6763 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6765 local list=$(comma_list $(mdts_nodes))
6767 do_nodes $list lctl set_param fail_loc=0x157
6769 do_facet client "$@" || RC=$?
6771 do_nodes $list lctl set_param fail_loc=0
6775 drop_mdt_ldlm_reply_once() {
6776 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6778 local list=$(comma_list $(mdts_nodes))
6780 do_nodes $list lctl set_param fail_loc=0x80000157
6782 do_facet client "$@" || RC=$?
6784 do_nodes $list lctl set_param fail_loc=0
6792 echo "clearing fail_loc on $facet"
6793 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6796 set_nodes_failloc () {
6798 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6801 # Print the total of the lock_unused_count across all namespaces containing the
6802 # given wildcard. If the namespace wildcard is omitted, all namespaces will be
6804 # Usage: total_unused_locks [namespace_wildcard]
6805 total_unused_locks() {
6806 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_unused_count" | calc_sum
6809 # Print the total of the lock_count across all namespaces containing the given
6810 # wildcard. If the namespace wilcard is omitted, all namespaces will be matched.
6811 # Usage: total_used_locks [namespace_wildcard]
6812 total_used_locks() {
6813 $LCTL get_param -n "ldlm.namespaces.*$1*.lock_count" | calc_sum
6816 # Cancel lru locks across all namespaces containing the given wildcard. If the
6817 # wilcard is omitted, lru locks will be canceled across all namespaces.
6818 # Usage: cancel_lru_locks [namespace_wildcard]
6819 cancel_lru_locks() {
6820 #$LCTL mark "cancel_lru_locks $1 start"
6821 $LCTL set_param -t4 -n "ldlm.namespaces.*$1*.lru_size=clear"
6822 $LCTL get_param "ldlm.namespaces.*$1*.lock_unused_count" | grep -v '=0'
6823 #$LCTL mark "cancel_lru_locks $1 stop"
6828 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6830 echo $((100 * nr_cpu))
6835 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6838 lru_resize_disable()
6841 local lru_size=${2:-$(default_lru_size)}
6843 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6848 local mountpath=${1:-$MOUNT}
6851 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6858 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6859 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6860 echo there is still data in page cache $FILE ?
6861 lctl get_param -n $FILE
6869 DEBUGSAVE="$(lctl get_param -n debug)"
6870 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6874 [ -n "$DEBUGSAVE" ] &&
6875 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6879 [ -n "$DEBUGSAVE_SERVER" ] &&
6880 do_nodes $(comma_list $(all_server_nodes)) \
6881 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6887 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6890 debug_size_restore() {
6891 [ -n "$DEBUG_SIZE_SAVED" ] &&
6892 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6896 start_full_debug_logging() {
6901 local debug_size=150
6902 local nodes=$(comma_list $(nodes_list))
6904 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6907 stop_full_debug_logging() {
6912 # prints bash call stack
6913 print_stack_trace() {
6916 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6917 local src=${BASH_SOURCE[$i]}
6918 local lineno=${BASH_LINENO[$i-1]}
6919 local funcname=${FUNCNAME[$i]}
6920 echo " = $src:$lineno:$funcname()"
6925 local TYPE=${TYPE:-"FAIL"}
6928 # do not dump logs if $1=false
6929 if [ "x$1" = "xfalse" ]; then
6934 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6935 (print_stack_trace 2) >&2
6937 # We need to dump the logs on all nodes
6939 gather_logs $(comma_list $(nodes_list))
6943 [ "$TESTSUITELOG" ] &&
6944 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
6945 if [ -z "$*" ]; then
6946 echo "error() without useful message, please fix" > $LOGDIR/err
6948 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6949 echo "$@" > $LOGDIR/ignore
6951 echo "$@" > $LOGDIR/err
6955 # cleanup the env for failed tests
6959 ##################################
6961 ##################################
6963 # usage: stack_trap arg sigspec
6965 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6966 # command "arg" on top of previously defined commands for "sigspec" instead
6967 # of overwriting them.
6968 # stacked traps are executed in reverse order of their registration
6970 # arg and sigspec have the same meaning as in man (1) trap
6974 local sigspec="${2:-EXIT}"
6976 # Use "trap -p" to get the quoting right
6977 local old_trap="$(trap -p "$sigspec")"
6978 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6979 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6981 # Once again, use "trap -p" to get the quoting right
6982 local new_trap="$(trap -- "$arg" "$sigspec"
6984 trap -- '' "$sigspec")"
6986 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6988 # The resulting string should be safe to "eval" as it is (supposedly
6989 # correctly) quoted by "trap -p"
6990 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
6999 local logs="$TESTSUITELOG $1"
7001 for log in $logs; do
7002 if [ -f "$log" ]; then
7003 grep -qw FAIL $log && status=1
7020 # use only if we are ignoring failures for this test, bugno required.
7021 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
7022 # e.g. error_ignore bz5494 "your message" or
7023 # error_ignore LU-5494 "your message"
7025 local TYPE="IGNORE ($1)"
7030 error_and_remount() {
7032 remount_client $MOUNT
7036 # Throw an error if it's not running in vm - usually for performance
7039 local virt=$(running_in_vm)
7040 if [[ -n "$virt" ]]; then
7041 echo "running in VM '$virt', ignore error"
7042 error_ignore env=$virt "$@"
7049 # Function: skip_env()
7050 # Purpose: to skip a test during developer testing because some tool
7051 # is missing, but fail the test in release testing because the test
7052 # environment is not configured properly".
7055 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
7060 log " SKIP: $TESTSUITE $TESTNAME $*"
7062 if [[ -n "$ALWAYS_SKIPPED" ]]; then
7063 skip_logged $TESTNAME "$@"
7066 echo "$@" > $LOGDIR/skip
7069 [[ -n "$TESTSUITELOG" ]] &&
7070 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
7080 # For interop testing treate EOPNOTSUPP as success
7086 echo $retstr | awk -F'|' '{print $1}' |
7087 grep -E unsupported\|"(Operation not supported)"
7088 (( $? == 0 )) || error "$retstr"
7092 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
7093 # Usage: always_except LU-4815 23 42q ...
7095 function always_except() {
7096 local issue="${1:-}" # single jira style issue ("LU-4815")
7101 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
7102 error "always_except: invalid issue '$issue' for tests '$*'"
7105 for test_num in "$@"; do
7106 ALWAYS_EXCEPT+=" $test_num"
7110 build_test_filter() {
7111 EXCEPT="$EXCEPT $(testslist_filter)"
7113 # allow test numbers separated by '+', or ',', in addition to ' '
7114 # to avoid issues with multiple arguments handling by shell/autotest
7115 for O in ${ONLY//[+,]/ }; do
7116 if [[ $O =~ [0-9]*-[0-9]* ]]; then
7117 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
7125 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
7126 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
7127 [[ -z "$EXCEPT_SLOW" ]] ||
7128 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
7129 for E in ${EXCEPT//[+,]/ }; do
7130 eval EXCEPT_${E}=true
7132 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
7133 eval EXCEPT_ALWAYS_${E}=true
7135 for E in ${EXCEPT_SLOW//[+,]/ }; do
7136 eval EXCEPT_SLOW_${E}=true
7138 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
7139 eval GCHECK_ONLY_${G}=true
7144 if [[ $1 = [a-z]* ]]; then
7147 echo ${1%%[a-zA-Z]*}
7151 # print a newline if the last test was skipped
7152 export LAST_SKIPPED=
7153 export ALWAYS_SKIPPED=
7155 # Main entry into test-framework. This is called with the number and
7156 # description of a test. The number is used to find the function to run
7157 # the test using "test_$name".
7159 # This supports a variety of methods of specifying specific test to
7161 # - ONLY= env variable with space-separated list of test numbers to run
7162 # - EXCEPT= env variable with space-separated list of test numbers to exclude
7168 export base=$(basetest $testnum)
7169 export TESTNAME=test_$testnum
7173 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
7174 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
7175 local isexcept=EXCEPT_$testnum
7176 local isexcept_base=EXCEPT_$base
7177 if [ ${!isexcept}x != x ]; then
7179 skip_message="skipping excluded test $testnum"
7180 elif [ ${!isexcept_base}x != x ]; then
7182 skip_message="skipping excluded test $testnum (base $base)"
7185 isexcept=EXCEPT_ALWAYS_$testnum
7186 isexcept_base=EXCEPT_ALWAYS_$base
7187 if [ ${!isexcept}x != x ]; then
7189 skip_message="skipping ALWAYS excluded test $testnum"
7190 elif [ ${!isexcept_base}x != x ]; then
7192 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
7195 isexcept=EXCEPT_SLOW_$testnum
7196 isexcept_base=EXCEPT_SLOW_$base
7197 if [ ${!isexcept}x != x ]; then
7199 skip_message="skipping SLOW test $testnum"
7200 elif [ ${!isexcept_base}x != x ]; then
7202 skip_message="skipping SLOW test $testnum (base $base)"
7205 # If there are tests on the ONLY list, check if the current test
7206 # is on that list and, if so, check if the test is to be skipped
7207 # and if we are supposed to honor the skip lists.
7208 if [ -n "$ONLY" ]; then
7209 local isonly=ONLY_$testnum
7210 local isonly_base=ONLY_$base
7211 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
7213 if [[ -n "$ALWAYS_SKIPPED" &&
7214 -n "$HONOR_EXCEPT" ]]; then
7216 skip_noexit "$skip_message"
7219 [ -n "$LAST_SKIPPED" ] &&
7220 echo "" && LAST_SKIPPED=
7222 run_one_logged $testnum "$testmsg"
7232 if [ -n "$ALWAYS_SKIPPED" ]; then
7234 skip_noexit "$skip_message"
7237 run_one_logged $testnum "$testmsg"
7244 load_module ../libcfs/libcfs/libcfs
7257 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
7262 strace -o $TMP/$1.strace -ttt $*
7264 log "FINISHED: $*: rc $RC"
7271 banner "test complete, duration $duration sec"
7272 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
7273 echo "duration $duration" >>$TESTSUITELOG
7277 # Set TEST_STATUS here. It will be used for logging the result.
7280 if [[ -f $LOGDIR/err ]]; then
7282 elif [[ -f $LOGDIR/skip ]]; then
7285 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
7289 local FFREE=$(do_node $SINGLEMDS \
7290 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
7291 local FTOTAL=$(do_node $SINGLEMDS \
7292 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
7294 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
7299 #echo -n "Resetting fail_loc on all nodes..."
7300 do_nodes --quiet $(comma_list $(nodes_list)) \
7301 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
7307 # Log a message (on all nodes) padded with "=" before and after.
7308 # Also appends a timestamp and prepends the testsuite name.
7311 # ======================================================== 15:06:12 (1624050372)
7312 EQUALS="========================================================"
7314 msg="== ${TESTSUITE} $*"
7316 [[ $last != "=" && $last != " " ]] && msg="$msg "
7317 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
7318 # always include at least == after the message
7319 log "$msg== $(date +"%H:%M:%S (%s)")"
7322 check_dmesg_for_errors() {
7324 local errors="VFS: Busy inodes after unmount of\|\
7325 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
7326 group descriptors corrupted"
7328 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
7329 [ -z "$res" ] && return 0
7330 echo "Kernel error detected: $res"
7335 # Run a single test function and cleanup after it.
7337 # This function should be run in a subshell so the test func can
7338 # exit() without stopping the whole script.
7343 local SAVE_UMASK=`umask`
7346 if ! grep -q $DIR /proc/mounts; then
7350 banner "test $testnum: $testmsg"
7351 test_${testnum} || error "test_$testnum failed with $?"
7354 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7356 check_dmesg_for_errors || error "Error in dmesg detected"
7357 if [ "$PARALLEL" != "yes" ]; then
7358 ps auxww | grep -v grep | grep -q "multiop " &&
7359 error "multiop still running"
7367 # Wrapper around run_one to ensure:
7368 # - test runs in subshell
7369 # - output of test is saved to separate log file for error reporting
7370 # - test result is saved to data file
7373 local before=$SECONDS
7376 export tfile=f${testnum}.${TESTSUITE}
7377 export tdir=d${testnum}.${TESTSUITE}
7378 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7379 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7380 local SAVE_UMASK=$(umask)
7383 declare -A kptr_restrict
7384 declare -A debug_raw
7387 for node in $(all_nodes); do
7388 kptr_restrict[$node]=$(do_node $node "sysctl --values kernel/kptr_restrict")
7389 do_node $node "sysctl -wq kernel/kptr_restrict=1"
7390 # Enable %p to be unhashed (if supported)
7391 debug_raw[$node]=$(do_node $node "$LCTL get_param -n debug_raw_pointers" || echo 0)
7392 do_node $node "$LCTL set_param debug_raw_pointers=Y || true"
7395 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7397 # if $ONLY is set, repeat subtest $ONLY_REPEAT times, otherwise once
7398 local repeat=${ONLY:+$ONLY_REPEAT}
7400 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
7401 local before_sub=$SECONDS
7403 log_sub_test_begin $TESTNAME
7404 # remove temp files between repetitions to avoid test failures
7405 if [[ -n "$append" ]]; then
7406 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7407 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7408 echo "subtest iteration $testiter/$repeat"
7410 # loop around subshell so stack_trap EXIT triggers each time
7411 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
7414 local duration_sub=$((SECONDS - before_sub))
7417 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7418 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7420 if [[ -f $LOGDIR/err ]]; then
7421 test_error=$(cat $LOGDIR/err)
7423 elif [[ -f $LOGDIR/ignore ]]; then
7424 test_error=$(cat $LOGDIR/ignore)
7425 elif [[ -f $LOGDIR/skip ]]; then
7426 test_error=$(cat $LOGDIR/skip)
7432 pass "$testnum" "(${duration_sub}s)"
7433 if [ -n "${DUMP_OK}" ]; then
7434 gather_logs $(comma_list $(nodes_list))
7437 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7438 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7442 for node in $(all_nodes); do
7443 param="kernel/kptr_restrict=${kptr_restrict[$node]}"
7444 do_node $node "sysctl -wq ${param} || true"
7445 # Restore %p to initial state
7446 param="debug_raw_pointers=${debug_raw[$node]}"
7447 do_node $node "$LCTL set_param ${param} || true"
7450 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7454 if [ -f $LOGDIR/err ]; then
7455 log_zfs_info "$zfs_debug_log"
7456 $FAIL_ON_ERROR && exit $rc
7469 # Print information of skipped tests to result.yml
7472 log_sub_test_begin $1
7474 log_sub_test_end "SKIP" "0" "0" "$@"
7477 grant_from_clients() {
7481 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7485 grant_from_servers() {
7489 # which is tot_granted less grant_precreate
7490 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7491 " obdfilter.${FSNAME}-OST*.tot_pending" \
7492 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7493 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7494 /tot_pending/{ total -= $2 };
7495 /grant_precreate/{ total -= $2 };
7496 END { printf("%0.0f", total) }'
7500 export base=$(basetest $1)
7501 [ "$CHECK_GRANT" == "no" ] && return 0
7503 local isonly_base=GCHECK_ONLY_${base}
7504 local isonly=GCHECK_ONLY_$1
7505 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7507 echo -n "checking grant......"
7509 local osts=$(comma_list $(osts_nodes))
7510 local clients=$CLIENTS
7511 [ -z "$clients" ] && clients=$(hostname)
7513 # sync all the data and make sure no pending data on server
7514 do_nodes $clients sync
7515 do_nodes $clients $LFS df # initiate all idling connections
7518 cli_grant=$(grant_from_clients $clients)
7521 # which is tot_granted less grant_precreate
7522 srv_grant=$(grant_from_servers $osts)
7525 # check whether client grant == server grant
7526 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7527 echo "wait for client:$cli_grant == server:$srv_grant"
7529 cli_grant=$(grant_from_clients $clients)
7530 srv_grant=$(grant_from_servers $osts)
7532 if [[ $cli_grant -ne $srv_grant ]]; then
7533 do_nodes $(comma_list $(osts_nodes)) \
7534 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7535 "obdfilter.${FSNAME}-OST*.grant_*"
7536 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7537 error "failed grant check: client:$cli_grant server:$srv_grant"
7539 echo "pass grant check: client:$cli_grant server:$srv_grant"
7543 ########################
7552 ostuuid_from_index() {
7553 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7554 local uuid=($($LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7559 ostname_from_index() {
7560 local uuid=$(ostuuid_from_index $1 $2)
7565 mdtuuid_from_index() {
7566 # only print the first UUID, if 'lfs osts' shows multiple mountpoints
7567 local uuid=($($LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"))
7572 mdtname_from_index() {
7573 local uuid=$(mdtuuid_from_index $1 $2)
7578 mdssize_from_index() {
7579 local mdt=$(mdtname_from_index $2)
7581 $LFS df $1 | awk "/$mdt/ { print \$2 }"
7584 index_from_ostuuid()
7586 # only print the first index, if 'lfs osts' shows multiple mountpoints
7587 local ostidx=($($LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"))
7593 # Return unique identifier for given hostname
7596 echo $host_name | md5sum | cut -d' ' -f1
7600 # Returns list of ip addresses for each interface
7602 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7606 # Returns list of interfaces configured for LNet
7608 local nids=( $($LCTL list_nids | xargs echo) )
7610 [[ -z ${nids[@]} ]] &&
7613 if [[ ${NETTYPE} =~ kfi* ]]; then
7614 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7615 sort -u | xargs echo
7619 declare -a INTERFACES
7621 for ((i = 0; i < ${#nids[@]}; i++)); do
7622 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7623 INTERFACES[i]=$(ip -o a s |
7624 awk '$4 ~ /^'$ip'\//{print $2}')
7625 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7626 if [[ -z ${INTERFACES[i]} ]]; then
7627 error "Can't determine interface name for NID ${nids[i]}"
7628 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7629 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7633 echo "${INTERFACES[@]}"
7638 # return 1 if addr is remote
7639 # return 0 if addr is local
7642 # Cache address list to avoid mutiple execution of local_addr_list
7643 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7645 for i in $LOCAL_ADDR_LIST ; do
7646 [[ "$i" == "$addr" ]] && return 0
7651 # return true(0) if host_name is local
7652 # return false(1) if host_name is remote
7655 local is_local="IS_LOCAL_$(host_id $host_name)"
7657 if [ -z "${!is_local-}" ] ; then
7658 eval $is_local=false
7659 local host_ip=$(getent ahostsv4 $host_name |
7660 awk 'NR == 1 { print $1 }')
7661 is_local_addr "$host_ip" && eval $is_local=true
7675 for node in $(mdts_nodes); do
7676 remote_node $node && return 0
7683 [ -n "$CLIENTONLY" ] && return 0 || true
7684 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7689 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7690 MSKIPPED=1 && return 1
7697 for node in $(osts_nodes) ; do
7698 remote_node $node && return 0
7705 [ -n "$CLIENTONLY" ] && return 0 || true
7706 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7711 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7712 OSKIPPED=1 && return 1
7718 [ -n "$CLIENTONLY" ] && return 0 || true
7720 MGS=$(facet_host mgs)
7721 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7726 remote_mds_nodsh || remote_ost_nodsh ||
7727 $(single_local_node $(comma_list $(nodes_list)))
7731 remote_ost && remote_mds
7734 # Get the active nodes for facets.
7742 for facet in ${facets//,/ }; do
7743 nodes="$nodes $(facet_active_host $facet)"
7746 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7750 # Get name of the active MGS node.
7752 echo -n $(facets_nodes $(get_facets MGS))
7755 # Get all of the active MDS nodes.
7757 echo -n $(facets_nodes $(get_facets MDS))
7760 # Get all of the active OSS nodes.
7762 echo -n $(facets_nodes $(get_facets OST))
7765 # Get all of the client nodes and active server nodes.
7767 local nodes=$HOSTNAME
7771 # CLIENTS (if specified) contains the local client
7772 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7774 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7775 nodes="$nodes $(facets_nodes $(get_facets))"
7778 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7782 # Get all of the remote client nodes and remote active server nodes.
7783 remote_nodes_list () {
7784 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7787 # Get all of the MDS nodes, including active and passive nodes.
7795 for i in $(seq $MDSCOUNT); do
7797 failover_host=mds${i}failover_HOST
7798 nodes="$nodes ${!host} ${!failover_host}"
7801 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7802 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7806 # Get all of the OSS nodes, including active and passive nodes.
7814 for i in $(seq $OSTCOUNT); do
7816 failover_host=ost${i}failover_HOST
7817 nodes="$nodes ${!host} ${!failover_host}"
7820 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7821 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7825 # Get all of the server nodes, including active and passive nodes.
7826 all_server_nodes () {
7831 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7833 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7837 # Get all of the client and server nodes, including active and passive nodes.
7839 local nodes=$HOSTNAME
7843 # CLIENTS (if specified) contains the local client
7844 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7846 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7847 nodes="$nodes $(all_server_nodes)"
7850 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7854 init_clients_lists () {
7855 # Sanity check: exclude the local client from RCLIENTS
7856 local clients=$(hostlist_expand "$RCLIENTS")
7857 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7859 # Sanity check: exclude the dup entries
7860 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7862 export CLIENT1=${CLIENT1:-$HOSTNAME}
7863 export SINGLECLIENT=$CLIENT1
7865 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7867 # Sanity check: exclude the dup entries from CLIENTS
7868 # for those configs which has SINGLCLIENT set to local client
7869 clients=$(for i in $clients; do echo $i; done | sort -u)
7871 export CLIENTS=$(comma_list $clients)
7872 local -a remoteclients=($RCLIENTS)
7873 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7874 varname=CLIENT$((i + 2))
7876 eval export $varname=${remoteclients[i]}
7879 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7882 get_random_entry () {
7885 rnodes=${rnodes//,/ }
7887 local -a nodes=($rnodes)
7888 local num=${#nodes[@]}
7889 local i=$((RANDOM * num * 2 / 65536))
7895 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7899 # this should already have been called, but just in case
7900 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7903 echo "client=$CLIENT_VERSION MDS=$MDS1_VERSION OSS=$OST1_VERSION"
7905 [[ -n "$CLIENT_VERSION" && -n "$MDS1_VERSION" && -n "$OST1_VERSION" ]]||
7906 error "unable to determine node versions"
7908 (( "$CLIENT_VERSION" == "$MDS1_VERSION" &&
7909 "$CLIENT_VERSION" == "$OST1_VERSION"))
7915 echo $nodes | wc -w || true
7919 local nodes=$(mdts_nodes)
7920 local mdtcount=$(get_node_count "$nodes")
7922 [ ! "$MDSCOUNT" = "$mdtcount" ]
7925 generate_machine_file() {
7926 local nodes=${1//,/ }
7927 local machinefile=$2
7930 for node in $nodes; do
7931 echo $node >>$machinefile ||
7932 { echo "can not generate machinefile $machinefile" &&
7938 local file=$1/stripe
7941 $LFS getstripe -v $file || error "getstripe $file failed"
7945 # Check and add a test group.
7951 local gid=$(getent group $group_name | cut -d: -f3)
7952 if [[ -n "$gid" ]]; then
7953 [[ "$gid" -eq "$group_id" ]] || {
7954 error_noexit "inconsistent group ID:" \
7955 "new: $group_id, old: $gid"
7959 echo "adding group $group_name:$group_id"
7960 getent group $group_name || true
7961 getent group $group_id || true
7962 groupadd -g $group_id $group_name
7969 # Check and add a test user.
7982 local uid=$(getent passwd $user_name | cut -d: -f3)
7983 if [[ -n "$uid" ]]; then
7984 if [[ "$uid" -eq "$user_id" ]]; then
7985 local dir=$(getent passwd $user_name | cut -d: -f6)
7986 if [[ "$dir" != "$home" ]]; then
7988 usermod -d $home $user_name
7992 error_noexit "inconsistent user ID:" \
7993 "new: $user_id, old: $uid"
7998 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
8005 check_runas_id_ret() {
8007 local myRUNAS_UID=$1
8008 local myRUNAS_GID=$2
8012 if [ -z "$myRUNAS" ]; then
8013 error_exit "check_runas_id_ret requires myRUNAS argument"
8017 error "Unable to execute $myRUNAS"
8019 id $myRUNAS_UID > /dev/null ||
8020 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
8021 "some UID which exists on MDS and client or add user " \
8022 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
8025 $myRUNAS krb5_login.sh ||
8026 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
8028 mkdir $DIR/d0_runas_test
8030 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
8031 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
8032 rm -rf $DIR/d0_runas_test
8037 local myRUNAS_UID=$1
8038 local myRUNAS_GID=$2
8042 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
8043 error "unable to write to $DIR/d0_runas_test as " \
8047 # obtain the UID/GID for MPI_USER
8051 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
8052 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
8054 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
8055 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
8058 # Run multiop in the background, but wait for it to print
8059 # "PAUSING" to its stdout before returning from this function.
8060 multiop_bg_pause() {
8061 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
8065 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
8068 echo "$MULTIOP_PROG $FILE v$ARGS"
8069 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
8072 echo "TMPPIPE=${TMPPIPE}"
8073 read -t 60 multiop_output < $TMPPIPE
8074 if [ $? -ne 0 ]; then
8079 if [ "$multiop_output" != "PAUSING" ]; then
8080 echo "Incorrect multiop output: $multiop_output"
8095 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
8097 echo $((SECONDS - start))
8101 inodes_available () {
8102 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
8103 sort -un | head -n1) || return 1
8108 mdsrate_inodes_available () {
8109 local min_inodes=$(inodes_available)
8111 echo $((min_inodes * 99 / 100))
8114 bytes_available () {
8115 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
8118 mdsrate_bytes_available () {
8119 local bytes=$(bytes_available)
8121 echo $((bytes * 99 / 100))
8124 # reset stat counters
8126 local paramfile="$1"
8128 lctl set_param -n $paramfile=0
8133 local paramfile="$1"
8136 lctl get_param -n $paramfile |
8137 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
8141 awk '{sum += $1} END { printf("%0.0f", sum) }'
8144 calc_osc_kbytes () {
8145 $LFS df $MOUNT > /dev/null
8146 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
8150 wait_delete_completed
8151 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8152 echo "OST kbytes available: ${AVAIL[*]}"
8157 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8158 #echo OST $i: ${AVAIL[i]}kb
8159 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8163 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8168 echo "Min free space: OST $MINI: $MINV"
8169 echo "Max free space: OST $MAXI: $MAXV"
8172 # save_lustre_params(comma separated facet list, parameter_mask)
8173 # generate a stream of formatted strings (<facet> <param name>=<param value>)
8174 save_lustre_params() {
8179 for facet in ${facets//,/ }; do
8180 facet_svc=$(facet_svc $facet)
8182 "params=\\\$($LCTL get_param $2);
8183 [[ -z \\\"$facet_svc\\\" ]] && param= ||
8184 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
8185 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
8186 while read s; do echo $facet \\\$s;
8187 done <<< \\\"\\\$param\\\""
8191 # restore lustre parameters from input stream, produces by save_lustre_params
8192 restore_lustre_params() {
8197 while IFS=" =" read facet name val; do
8198 do_facet $facet "$LCTL set_param -n $name=$val"
8202 check_node_health() {
8203 local nodes=${1:-$(comma_list $(nodes_list))}
8204 local health=$TMP/node_health.$$
8206 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
8207 grep "catastrophe=1" && error "LBUG/LASSERT detected"
8208 # Only check/report network health if get_param isn't reported, since
8209 # *clearly* the network is working if get_param returned something.
8210 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
8211 for node in ${nodes//,/ }; do
8212 check_network $node 5
8218 mdsrate_cleanup () {
8220 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
8221 --nfiles $3 --dir $4 --filefmt $5 $6
8227 local test_type="$1"
8240 local mdtest_basedir
8241 local mdtest_actions
8242 local mdtest_options
8243 local stripe_options
8246 case "$test_type" in
8248 stripe_options=(-c 1 -i 0)
8249 mdtest_actions=(-F -R)
8254 stripe_options=(-c -1)
8255 mdtest_actions=(-F -R)
8256 file_size=$((1024 * 1024 * 1024))
8260 stripe_options=(-c 1)
8261 mdtest_actions=(-C -D -E -k -r)
8266 stripe_options=(-c 1)
8267 mdtest_actions=(-C -D -E -k -r)
8272 stripe_options=(-c -1)
8278 if [[ -n "$MDTEST_DEBUG" ]]; then
8279 mdtest_options+=(-v -v -v)
8282 num_dirs=${NUM_DIRS:-$num_dirs}
8283 num_files=${NUM_FILES:-$num_files}
8284 file_size=${FILE_SIZE:-$file_size}
8285 free_space=$(mdsrate_bytes_available)
8287 if (( file_size * num_files > free_space )); then
8288 file_size=$((free_space / num_files))
8289 log "change file size to $file_size due to" \
8290 "number of files $num_files and" \
8291 "free space limit in $free_space"
8294 if (( file_size > 0 )); then
8295 log "set file size to $file_size"
8296 mdtest_options+=(-w=$file_size)
8299 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
8300 mdtest_basedir=$MOUNT/mdtest
8301 mdtest_options+=(-d=$mdtest_basedir)
8304 num_hosts=$(get_node_count ${CLIENTS//,/ })
8305 num_procs=$((num_cores * num_hosts))
8306 num_inodes=$(mdsrate_inodes_available)
8308 if (( num_inodes < num_files )); then
8309 log "change the number of files $num_files to the" \
8310 "number of available inodes $num_inodes"
8311 num_files=$num_inodes
8314 if (( num_dirs > 1 )); then
8315 num_entries=$((num_files / num_dirs))
8316 log "split $num_files files to $num_dirs" \
8317 "with $num_entries files each"
8318 mdtest_options+=(-I=$num_entries)
8321 generate_machine_file $CLIENTS $MACHINEFILE ||
8322 error "can not generate machinefile"
8324 install -v -d -m 0777 $mdtest_basedir
8326 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
8328 save_lustre_params $(get_facets MDS) \
8329 mdt.*.enable_remote_dir_gid > $params_file
8331 do_nodes $(comma_list $(mdts_nodes)) \
8332 $LCTL set_param mdt.*.enable_remote_dir_gid=-1
8334 stack_trap "restore_lustre_params < $params_file" EXIT
8336 for np in 1 $num_procs; do
8337 num_entries=$((num_files / np ))
8339 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8340 -np $np -npernode $num_cores $MDTEST \
8341 ${mdtest_options[@]} -n=$num_entries \
8342 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
8346 if (( rc != 0 )); then
8347 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
8348 -np $np -npernode $num_cores $MDTEST \
8349 ${mdtest_options[@]} -n=$num_entries \
8350 -r 2>&1 | tee -a "$LOG"
8355 rmdir -v $mdtest_basedir
8356 rm -v $state $MACHINEFILE
8361 ########################
8363 convert_facet2label() {
8366 if [ x$facet = xost ]; then
8368 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8372 local varsvc=${facet}_svc
8374 if [ -n "${!varsvc}" ]; then
8377 error "No label for $facet!"
8381 get_clientosc_proc_path() {
8382 echo "${1}-osc-[-0-9a-f]*"
8385 get_mdtosc_proc_path() {
8387 local ost_label=${2:-"*OST*"}
8389 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8390 local mdt_label=$(convert_facet2label $mds_facet)
8391 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8393 if [[ $ost_label = *OST* ]]; then
8394 echo "${ost_label}-osc-${mdt_index}"
8396 echo "${ost_label}-osp-${mdt_index}"
8400 get_osc_import_name() {
8403 local label=$(convert_facet2label $ost)
8405 if [ "${facet:0:3}" = "mds" ]; then
8406 get_mdtosc_proc_path $facet $label
8410 get_clientosc_proc_path $label
8414 _wait_import_state () {
8416 local CONN_PROC="$2"
8417 local maxtime=${3:-$(max_recovery_time)}
8418 local err_on_fail=${4:-1}
8422 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8423 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8424 if [[ "${expected}" == "DISCONN" ]]; then
8425 # for disconn we can check after proc entry is removed
8426 [[ -z "${CONN_STATE}" ]] && return 0
8427 # with AT, we can have connect request timeout near
8428 # reconnect timeout and test can't see real disconnect
8429 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8431 if (( $i >= $maxtime )); then
8432 (( $err_on_fail != 0 )) &&
8433 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8437 # Add uniq for multi-mount case
8438 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8443 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8447 wait_import_state() {
8450 local maxtime=${3:-$(max_recovery_time)}
8451 local err_on_fail=${4:-1}
8454 for param in ${params//,/ }; do
8455 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8460 wait_import_state_mount() {
8461 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8465 wait_import_state "$@"
8468 # One client request could be timed out because server was not ready
8469 # when request was sent by client.
8470 # The request timeout calculation details :
8472 # /* We give the server rq_timeout secs to process the req, and
8473 # add the network latency for our local timeout. */
8474 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8475 # ptlrpc_at_get_net_latency(request) ;
8477 # ptlrpc_connect_import ()
8478 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8481 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8482 # ptlrpc_at_get_net_latency(request) ->
8483 # at_get (max (iat_net_latency=0, at_min)) = at_min
8486 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8487 # INITIAL_CONNECT_TIMEOUT + at_min
8489 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8490 # because we can not get this value in runtime,
8491 # the value depends on configure options, and it is not stored in /proc.
8493 # #define CONNECTION_SWITCH_MIN 5U
8494 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8496 request_timeout () {
8499 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8500 local init_connect_timeout=$TIMEOUT
8501 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8503 local at_min=$(at_get $facet at_min)
8505 echo $(( init_connect_timeout + at_min ))
8508 _wait_osc_import_state() {
8512 local target=$(get_osc_import_name $facet $ost_facet)
8513 local param="os[cp].${target}.ost_server_uuid"
8517 # 1. wait the deadline of client 1st request (it could be skipped)
8518 # 2. wait the deadline of client 2nd request
8519 local maxtime=$(( 2 * $(request_timeout $facet)))
8521 if [[ $facet == client* ]]; then
8522 # During setup time, the osc might not be setup, it need wait
8523 # until list_param can return valid value.
8524 params=$($LCTL list_param $param 2>/dev/null || true)
8525 while [ -z "$params" ]; do
8526 if [ $i -ge $maxtime ]; then
8527 echo "can't get $param in $maxtime secs"
8532 params=$($LCTL list_param $param 2>/dev/null || true)
8536 if [[ $ost_facet = mds* ]]; then
8537 # no OSP connection to itself
8538 if [[ $facet = $ost_facet ]]; then
8541 param="osp.${target}.mdt_server_uuid"
8545 local plist=$(comma_list $params)
8546 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8547 wait_import_state $expected $plist $maxtime; then
8548 error "$facet: import is not in $expected state after $maxtime"
8555 wait_osc_import_state() {
8561 if [[ $facet = mds ]]; then
8562 for num in $(seq $MDSCOUNT); do
8563 _wait_osc_import_state mds$num "$ost_facet" "$expected"
8566 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
8570 wait_osc_import_ready() {
8571 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
8574 _wait_mgc_import_state() {
8577 local error_on_failure=${3:-1}
8578 local param="mgc.*.mgs_server_uuid"
8582 # 1. wait the deadline of client 1st request (it could be skipped)
8583 # 2. wait the deadline of client 2nd request
8584 local maxtime=$(( 2 * $(request_timeout $facet)))
8586 if [[ $facet == client* ]]; then
8587 # During setup time, the osc might not be setup, it need wait
8588 # until list_param can return valid value. And also if there
8589 # are mulitple osc entries we should list all of them before
8591 params=$($LCTL list_param $param 2>/dev/null || true)
8592 while [ -z "$params" ]; do
8593 if [ $i -ge $maxtime ]; then
8594 echo "can't get $param in $maxtime secs"
8599 params=$($LCTL list_param $param 2>/dev/null || true)
8602 local plist=$(comma_list $params)
8603 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8604 wait_import_state $expected $plist $maxtime \
8605 $error_on_failure; then
8606 if [ $error_on_failure -ne 0 ]; then
8607 error "import is not in ${expected} state"
8615 wait_mgc_import_state() {
8618 local error_on_failure=${3:-1}
8621 if [[ $facet = mds ]]; then
8622 for num in $(seq $MDSCOUNT); do
8623 _wait_mgc_import_state mds$num "$expected" \
8624 $error_on_failure || return
8627 _wait_mgc_import_state "$facet" "$expected" \
8628 $error_on_failure || return
8632 wait_dne_interconnect() {
8635 if [ $MDSCOUNT -gt 1 ]; then
8636 for num in $(seq $MDSCOUNT); do
8637 wait_osc_import_ready mds mds$num
8642 get_clientmdc_proc_path() {
8646 get_clientmgc_proc_path() {
8653 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8658 [ -z "$list" ] && return 0
8660 # Add paths to lustre tests for 32 and 64 bit systems.
8661 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8662 local TESTPATH="$RLUSTRE/tests:"
8663 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8664 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8665 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8669 wait_clients_import_state () {
8673 local facets="$facet"
8675 if [ "$FAILURE_MODE" = HARD ]; then
8676 facets=$(for f in ${facet//,/ }; do
8677 facets_on_host $(facet_active_host $f) | tr "," "\n"
8678 done | sort -u | paste -sd , )
8681 for facet in ${facets//,/ }; do
8682 local label=$(convert_facet2label $facet)
8685 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8686 $label).ost_server_uuid" ;;
8687 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8688 $label).mds_server_uuid" ;;
8689 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8690 $label).mgs_server_uuid" ;;
8691 *) error "unknown facet!" ;;
8694 local params=$(expand_list $params $proc_path)
8697 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8699 error "import is not in ${expected} state"
8704 wait_clients_import_ready() {
8705 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
8715 # wait until all MDTs are in the expected state
8716 for ((num = 1; num <= $MDSCOUNT; num++)); do
8717 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8721 if [ $facet = "mds" ]; then
8722 mproc="osp.$mdtosp.active"
8723 [ $num -eq $((tgt_idx + 1)) ] && continue
8725 mproc="osc.$mdtosp.active"
8731 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8734 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
8735 if [ $result -eq $expected ]; then
8736 echo -n "target updated after "
8737 echo "$wait sec (got $result)"
8741 if [ $wait -eq $max ]; then
8742 error "$tgt_name: wanted $expected got $result"
8744 echo "Waiting $((max - wait)) secs for $tgt_name"
8754 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8755 $LCTL get_param obdfilter.*.kbytesavail))
8756 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8757 $LCTL get_param -n obdfilter.*.tot_granted))
8758 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8759 $LCTL get_param -n obdfilter.*.kbytestotal))
8760 for ((i=0; i<${#AVAILA[@]}; i++)); do
8761 local -a AVAIL1=(${AVAILA[$i]//=/ })
8762 local -a TOTAL=(${TOTALA[$i]//=/ })
8763 GRANT=$((${GRANTA[$i]}/1024))
8764 # allow 1% of total space in bavail because of delayed
8765 # allocation with ZFS which might release some free space after
8766 # txg commit. For small devices, we set a mininum of 8MB
8767 local LIMIT=$((${TOTAL} / 100 + 8000))
8768 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8769 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8770 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8771 echo " FULL" || echo
8777 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8780 check_pool_not_exist() {
8781 local fsname=${1%%.*}
8782 local poolname=${1##$fsname.}
8783 [[ $# -ne 1 ]] && return 0
8784 [[ x$poolname = x ]] && return 0
8785 list_pool $fsname | grep -w $1 && return 1
8790 local fsname=${1%%.*}
8791 local poolname=${1##$fsname.}
8792 local keep_pools=${2:-false}
8794 stack_trap "destroy_test_pools $fsname" EXIT
8795 do_facet mgs lctl pool_new $1
8797 # get param should return err unless pool is created
8798 [[ $RC -ne 0 ]] && return $RC
8800 for mds_id in $(seq $MDSCOUNT); do
8801 local mdt_id=$((mds_id-1))
8802 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8803 wait_update_facet mds$mds_id \
8804 "lctl get_param -n lod.$lodname.pools.$poolname \
8805 2>/dev/null || echo foo" "" ||
8806 error "mds$mds_id: pool_new failed $1"
8808 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8809 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8811 $keep_pools || add_pool_to_list $1
8815 add_pool_to_list () {
8816 local fsname=${1%%.*}
8817 local poolname=${1##$fsname.}
8819 local listvar=${fsname}_CREATED_POOLS
8820 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8824 remove_pool_from_list () {
8825 local fsname=${1%%.*}
8826 local poolname=${1##$fsname.}
8828 local listvar=${fsname}_CREATED_POOLS
8829 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8833 # cleanup all pools exist on $FSNAME
8834 destroy_all_pools () {
8836 for i in $(list_pool $FSNAME); do
8841 destroy_pool_int() {
8843 local OSTS=$(list_pool $1)
8844 for ost in $OSTS; do
8845 do_facet mgs lctl pool_remove $1 $ost
8847 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8848 error "MDS: pool_list $1 failed"
8849 do_facet mgs lctl pool_destroy $1
8852 # <fsname>.<poolname> or <poolname>
8854 local fsname=${1%%.*}
8855 local poolname=${1##$fsname.}
8857 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8861 check_pool_not_exist $fsname.$poolname && return 0 || true
8863 destroy_pool_int $fsname.$poolname
8865 [[ $RC -ne 0 ]] && return $RC
8866 for mds_id in $(seq $MDSCOUNT); do
8867 local mdt_id=$((mds_id-1))
8868 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8869 wait_update_facet mds$mds_id \
8870 "lctl get_param -n lod.$lodname.pools.$poolname \
8871 2>/dev/null || echo foo" "foo" ||
8872 error "mds$mds_id: destroy pool failed $1"
8874 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8875 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8877 remove_pool_from_list $fsname.$poolname
8883 local fsname=${1:-$FSNAME}
8885 local listvar=${fsname}_CREATED_POOLS
8887 [ x${!listvar} = x ] && return 0
8889 echo "Destroy the created pools: ${!listvar}"
8890 for poolname in ${!listvar//,/ }; do
8891 destroy_pool $fsname.$poolname
8895 destroy_test_pools () {
8896 local fsname=${1:-$FSNAME}
8897 destroy_pools $fsname || true
8903 local ts=$(date +%s)
8906 if [[ ! -f "$YAML_LOG" ]]; then
8907 # init_logging is not performed before gather_logs,
8908 # so the $LOGDIR needs to be checked here
8909 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8912 [ -f $LOGDIR/shared ] && docp=false
8914 # dump lustre logs, dmesg, and journal if GSS_SK=true
8916 prefix="$TESTLOG_PREFIX.$TESTNAME"
8918 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8920 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8921 echo "Dumping logs only on local client."
8922 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8923 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8924 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8925 $LGSS_SK -r {} \; &> \
8926 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8927 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8928 ${prefix}.nodemaps.$(hostname -s).${suffix}
8929 [ "$GSS" = true ] && keyctl show > \
8930 ${prefix}.keyring.$(hostname -s).${suffix}
8931 [ "$GSS" = true ] && journalctl -a > \
8932 ${prefix}.journal.$(hostname -s).${suffix}
8937 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8938 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8939 if [ "$SHARED_KEY" = true ]; then
8940 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8941 $LGSS_SK -r {} \; &> \
8942 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8943 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8944 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8946 if [ "$GSS" = true ]; then
8947 do_nodesv $list "keyctl show > \
8948 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8949 do_nodesv $list "journalctl -a > \
8950 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8953 if [ ! -f $LOGDIR/shared ]; then
8954 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8956 for node in ${remote_nodes//,/ }; do
8957 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8971 for i in $(seq 0 $num_mntpts); do
8972 cmd="ls -laf ${mntpt_root}$i/$dir"
8978 for pid in $pids; do
8985 # check_and_start_recovery_timer()
8986 # service_time = at_est2timeout(service_time);
8987 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8988 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8990 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8991 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
8992 #define CONNECTION_SWITCH_MIN 5
8993 #define CONNECTION_SWITCH_INC 5
8994 max_recovery_time() {
8995 local init_connect_timeout=$((TIMEOUT / 20))
8996 ((init_connect_timeout >= 5)) || init_connect_timeout=5
8998 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
8999 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
9001 echo -n $service_time
9004 recovery_time_min() {
9005 local connection_switch_min=5
9006 local connection_switch_inc=5
9007 local connection_switch_max
9008 local reconnect_delay_max
9009 local initial_connect_timeout
9013 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
9014 (($connection_switch_min > $TIMEOUT)) &&
9015 max=$connection_switch_min || max=$TIMEOUT
9016 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
9018 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
9019 timeout_20=$((TIMEOUT/20))
9020 (($connection_switch_min > $timeout_20)) &&
9021 initial_connect_timeout=$connection_switch_min ||
9022 initial_connect_timeout=$timeout_20
9024 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
9025 initial_connect_timeout))
9026 echo $((2 * reconnect_delay_max))
9029 get_clients_mount_count () {
9030 local clients=${CLIENTS:-$HOSTNAME}
9032 # we need to take into account the clients mounts and
9033 # exclude mds/ost mounts if any;
9034 do_nodes $clients cat /proc/mounts | grep lustre |
9035 grep -w $MOUNT | wc -l
9039 PROC_CLI="srpc_info"
9040 PROC_CON="srpc_contexts"
9048 if [ $M -lt $N ]; then
9052 while [ $N -lt $M ]; do
9062 calc_connection_cnt() {
9065 # MDT->MDT = 2 * C(M, 2)
9069 comb_m2=$(combination $MDSCOUNT 2)
9071 local num_clients=$(get_clients_mount_count)
9073 local cnt_mdt2mdt=$((comb_m2 * 2))
9074 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
9075 local cnt_cli2ost=$((num_clients * OSTCOUNT))
9076 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
9077 if is_mounted $MOUNT2; then
9078 cnt_cli2mdt=$((cnt_cli2mdt * 2))
9079 cnt_cli2ost=$((cnt_cli2ost * 2))
9087 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
9088 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
9089 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
9090 + cnt_cli2ost + cnt_cli2mdt))
9104 local cmd="$tgt.srpc.flavor"
9106 if [ $net == "any" ]; then
9111 if [ $dir != "any" ]; then
9116 log "Setting sptlrpc rule: $cmd"
9117 do_facet mgs "$LCTL conf_param $cmd"
9123 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
9133 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
9134 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
9136 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
9138 if [ "x$bulkspec" != "x" ]; then
9139 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
9141 if [ "x$algs" != "x" ]; then
9142 bulk_count=`echo "$output" | grep "bulk flavor" |
9145 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
9147 if [ $bulk == "bulkn" ]; then
9148 bulk_count=`echo "$output" |
9149 grep "bulk flavor" | grep "null/null" |
9151 elif [ $bulk == "bulki" ]; then
9152 bulk_count=`echo "$output" |
9153 grep "bulk flavor" | grep "/null" |
9154 grep -v "null/" | wc -l`
9156 bulk_count=`echo "$output" |
9157 grep "bulk flavor" | grep -v "/null" |
9158 grep -v "null/" | wc -l`
9161 [ $bulk_count -lt $count ] && count=$bulk_count
9172 local clients=${CLIENTS:-$HOSTNAME}
9174 for c in ${clients//,/ }; do
9175 local output=$(do_node $c lctl get_param -n \
9176 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
9177 local tmpcnt=$(count_flvr "$output" $flavor)
9179 if $GSS_SK && [ $flavor != "null" ]; then
9180 # tmpcnt=min(contexts,flavors) to ensure SK context is
9182 output=$(do_node $c lctl get_param -n \
9183 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
9184 local outcon=$(count_contexts "$output")
9186 if [ "$outcon" -lt "$tmpcnt" ]; then
9190 cnt=$((cnt + tmpcnt))
9197 local clients=${CLIENTS:-$HOSTNAME}
9199 for c in ${clients//,/ }; do
9200 do_node $c lctl get_param \
9201 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null
9204 do_node $c lctl get_param \
9205 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null
9215 local clients=${CLIENTS:-$HOSTNAME}
9217 for c in ${clients//,/ }; do
9219 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
9220 local output=$(do_node $c lctl get_param -n \
9221 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
9222 local tmpcnt=$(count_flvr "$output" $flavor)
9224 if $GSS_SK && [ $flavor != "null" ]; then
9225 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9226 output=$(do_node $c lctl get_param -n \
9227 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
9228 local outcon=$(count_contexts "$output")
9230 if [ "$outcon" -lt "$tmpcnt" ]; then
9234 cnt=$((cnt + tmpcnt))
9241 local clients=${CLIENTS:-$HOSTNAME}
9243 for c in ${clients//,/ }; do
9244 do_node $c lctl get_param \
9245 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null
9248 do_node $c lctl get_param \
9249 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null
9259 if [ $MDSCOUNT -le 1 ]; then
9264 for num in `seq $MDSCOUNT`; do
9265 local output=$(do_facet mds$num lctl get_param -n \
9266 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
9267 local tmpcnt=$(count_flvr "$output" $flavor)
9269 if $GSS_SK && [ $flavor != "null" ]; then
9270 # tmpcnt=min(contexts,flavors) to ensure SK context is on
9271 output=$(do_facet mds$num lctl get_param -n \
9272 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
9273 local outcon=$(count_contexts "$output")
9275 if [ "$outcon" -lt "$tmpcnt" ]; then
9279 cnt=$((cnt + tmpcnt))
9286 for num in `seq $MDSCOUNT`; do
9287 do_facet mds$num lctl get_param \
9288 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null
9291 do_facet mds$num lctl get_param \
9292 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null
9303 for num in `seq $MDSCOUNT`; do
9304 mdtosc=$(get_mdtosc_proc_path mds$num)
9305 mdtosc=${mdtosc/-MDT*/-MDT\*}
9306 local output=$(do_facet mds$num lctl get_param -n \
9307 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
9308 # Ensure SK context is on
9309 local tmpcnt=$(count_flvr "$output" $flavor)
9311 if $GSS_SK && [ $flavor != "null" ]; then
9312 output=$(do_facet mds$num lctl get_param -n \
9313 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
9314 local outcon=$(count_contexts "$output")
9316 if [ "$outcon" -lt "$tmpcnt" ]; then
9320 cnt=$((cnt + tmpcnt))
9327 for num in `seq $MDSCOUNT`; do
9328 mdtosc=$(get_mdtosc_proc_path mds$num)
9329 mdtosc=${mdtosc/-MDT*/-MDT\*}
9330 do_facet mds$num lctl get_param \
9331 os[cp].$mdtosc.$PROC_CLI 2>/dev/null
9334 do_facet mds$num lctl get_param \
9335 os[cp].$mdtosc.$PROC_CON 2>/dev/null
9344 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
9346 count_flvr "$output" $flavor
9351 local dir=$1 # from to
9352 local flavor=$2 # flavor expected
9355 if [ $dir == "cli2mdt" ]; then
9356 res=`flvr_cnt_cli2mdt $flavor`
9357 elif [ $dir == "cli2ost" ]; then
9358 res=`flvr_cnt_cli2ost $flavor`
9359 elif [ $dir == "mdt2mdt" ]; then
9360 res=`flvr_cnt_mdt2mdt $flavor`
9361 elif [ $dir == "mdt2ost" ]; then
9362 res=`flvr_cnt_mdt2ost $flavor`
9363 elif [ $dir == "all2ost" ]; then
9364 res1=`flvr_cnt_mdt2ost $flavor`
9365 res2=`flvr_cnt_cli2ost $flavor`
9366 res=$((res1 + res2))
9367 elif [ $dir == "all2mdt" ]; then
9368 res1=`flvr_cnt_mdt2mdt $flavor`
9369 res2=`flvr_cnt_cli2mdt $flavor`
9370 res=$((res1 + res2))
9371 elif [ $dir == "all2all" ]; then
9372 res1=`flvr_cnt_mdt2ost $flavor`
9373 res2=`flvr_cnt_cli2ost $flavor`
9374 res3=`flvr_cnt_mdt2mdt $flavor`
9375 res4=`flvr_cnt_cli2mdt $flavor`
9376 res=$((res1 + res2 + res3 + res4))
9384 local clients=${CLIENTS:-$HOSTNAME}
9387 for c in ${clients//,/ }; do
9388 [ "$type" == "osc" ] &&
9389 do_node $c lctl get_param osc.*.idle_timeout
9390 do_node $c lctl get_param $type.*.import |
9391 grep -E "name:|state:"
9397 local dir=$1 # from to
9399 if [ $dir == "cli2mdt" ]; then
9400 do_dump_imp_state mdc
9402 elif [ $dir == "cli2ost" ]; then
9403 do_dump_imp_state osc
9405 elif [ $dir == "mdt2mdt" ]; then
9407 elif [ $dir == "mdt2ost" ]; then
9409 elif [ $dir == "all2ost" ]; then
9411 do_dump_imp_state osc
9413 elif [ $dir == "all2mdt" ]; then
9415 do_dump_imp_state mdc
9417 elif [ $dir == "all2all" ]; then
9419 do_dump_imp_state osc
9422 do_dump_imp_state mdc
9429 local dir=$1 # from to
9430 local flavor=$2 # flavor expected
9431 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
9432 local WAITFLAVOR_MAX=20 # how many retries before abort?
9435 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
9436 echo -n "checking $dir..."
9437 res=$(do_check_flavor $dir $flavor)
9438 echo "found $res/$expect $flavor connections"
9439 [ $res -ge $expect ] && return 0
9443 echo "Error checking $flavor of $dir: expect $expect, actual $res"
9444 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
9447 gather_logs $(comma_list $(nodes_list))
9452 restore_to_default_flavor()
9454 local proc="mgs.MGS.live.$FSNAME"
9456 echo "restoring to default flavor..."
9458 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9459 grep ".srpc.flavor" | wc -l)
9461 # remove all existing rules if any
9462 if [ $nrule -ne 0 ]; then
9463 echo "$nrule existing rules"
9464 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9465 grep ".srpc.flavor."); do
9466 echo "remove rule: $rule"
9467 spec=`echo $rule | awk -F = '{print $1}'`
9468 do_facet mgs "$LCTL conf_param -d $spec"
9472 # verify no rules left
9473 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9474 grep ".srpc.flavor." | wc -l)
9475 [ $nrule -ne 0 ] && error "still $nrule rules left"
9477 # wait for default flavor to be applied
9480 set_rule $FSNAME any any $SK_FLAVOR
9481 wait_flavor all2all $SK_FLAVOR
9483 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9484 set_rule $FSNAME any cli2ost $SK_FLAVOR
9485 wait_flavor cli2mdt $SK_FLAVOR
9486 wait_flavor cli2ost $SK_FLAVOR
9488 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9490 wait_flavor all2all null
9496 local flavor=${1:-null}
9498 echo "setting all flavor to $flavor"
9500 # FIXME need parameter to this fn
9501 # and remove global vars
9502 local cnt_all2all=$(calc_connection_cnt all2all)
9504 local res=$(do_check_flavor all2all $flavor)
9505 if [ $res -eq $cnt_all2all ]; then
9506 echo "already have total $res $flavor connections"
9510 echo "found $res $flavor out of total $cnt_all2all connections"
9511 restore_to_default_flavor
9513 [[ $flavor = null ]] && return 0
9515 if $GSS_SK && [ $flavor != "null" ]; then
9517 set_rule $FSNAME any any $flavor
9518 wait_flavor all2all $flavor
9520 set_rule $FSNAME any cli2mdt $flavor
9521 set_rule $FSNAME any cli2ost $flavor
9522 set_rule $FSNAME any mdt2ost null
9523 set_rule $FSNAME any mdt2mdt null
9524 wait_flavor cli2mdt $flavor
9525 wait_flavor cli2ost $flavor
9527 echo "GSS_SK now at flavor: $flavor"
9529 set_rule $FSNAME any cli2mdt $flavor
9530 set_rule $FSNAME any cli2ost $flavor
9531 set_rule $FSNAME any mdt2ost null
9532 set_rule $FSNAME any mdt2mdt null
9533 wait_flavor cli2mdt $flavor
9534 wait_flavor cli2ost $flavor
9541 # Checking for shared logdir
9542 if [ ! -d $dir ]; then
9543 # Not found. Create local logdir
9546 touch $dir/check_file.$(hostname -s)
9551 check_write_access() {
9553 local list=${2:-$(comma_list $(nodes_list))}
9557 for node in ${list//,/ }; do
9558 file=$dir/check_file.$(short_nodename $node)
9559 if [[ ! -f "$file" ]]; then
9560 # Logdir not accessible/writable from this node.
9563 rm -f $file || return 1
9569 [[ -n $YAML_LOG ]] && return
9570 local save_umask=$(umask)
9573 export YAML_LOG=${LOGDIR}/results.yml
9577 # If the yaml log already exists then we will just append to it
9578 if [ ! -f $YAML_LOG ]; then
9579 if check_shared_dir $LOGDIR; then
9580 touch $LOGDIR/shared
9581 echo "Logging to shared log directory: $LOGDIR"
9583 echo "Logging to local directory: $LOGDIR"
9586 yml_nodes_file $LOGDIR >> $YAML_LOG
9587 yml_results_file >> $YAML_LOG
9592 # log actual client and server versions if needed for debugging
9593 log "Client: $(lustre_build_version client)"
9594 lustre_os_release echo client
9595 log "MDS: $(lustre_build_version mds1)"
9596 lustre_os_release echo mds1
9597 log "OSS: $(lustre_build_version ost1)"
9598 lustre_os_release echo ost1
9602 yml_log_test $1 >> $YAML_LOG
9606 yml_log_test_status "$@" >> $YAML_LOG
9609 log_sub_test_begin() {
9610 yml_log_sub_test_begin "$@" >> $YAML_LOG
9613 log_sub_test_end() {
9614 yml_log_sub_test_end "$@" >> $YAML_LOG
9620 local llverdev_opts="$*"
9621 local devname=$(basename $dev)
9622 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
9623 # loop devices aren't in /proc/partitions
9624 [[ -z "$size" ]] && size=$(stat -c %s $dev)
9626 local size_gb=$((size / 1024 / 1024)) # Gb
9628 local partial_arg=""
9629 # Run in partial (fast) mode if the size of a partition > 1 GB
9630 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
9632 llverdev --force $partial_arg $llverdev_opts $dev
9638 local llverfs_opts=$2
9639 local use_partial_arg=$3
9640 local partial_arg=""
9641 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
9643 # Run in partial (fast) mode if the size of a partition > 1 GB
9644 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
9646 llverfs $partial_arg $llverfs_opts $dir
9650 local devs=${1//,/ }
9653 local rslt=$TMP/sgpdd_survey
9655 # sgpdd-survey cleanups ${rslt}.* files
9657 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
9663 # returns the canonical name for an ldiskfs device
9668 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
9669 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
9670 echo dm-\\\${foo##*:};
9672 name=\\\$(basename \\\$dv);
9673 if [[ \\\$name = *flakey* ]]; then
9674 name=\\\$(lsblk -o NAME,KNAME |
9675 awk /\\\$name/'{print \\\$NF}');
9681 is_sanity_benchmark() {
9682 local benchmarks="dbench bonnie iozone fsx"
9685 for b in $benchmarks; do
9686 if [ "$b" == "$suite" ]; then
9694 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
9698 # Get the available size (KB) of a given obd target.
9705 [[ $facet != client ]] || return 0
9707 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
9712 # Get the page size (bytes) on a given facet node.
9713 # The local client page_size is directly available in PAGE_SIZE.
9717 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
9719 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
9720 page_size=$(do_facet $facet getconf PAGE_SIZE)
9721 echo -n ${page_size:-4096}
9725 # Get the block count of the filesystem.
9732 [ -z "$CLIENTONLY" ] &&
9733 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
9734 awk '/^Block count:/ {print $3}')
9738 # Check whether the "ea_inode" feature is enabled or not, to allow
9739 # ldiskfs xattrs over one block in size. Allow both the historical
9740 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
9741 large_xattr_enabled() {
9742 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
9744 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
9746 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
9747 grep -E -q '(ea_inode|large_xattr)'"
9748 return ${PIPESTATUS[0]}
9751 # Get the maximum xattr size supported by the filesystem.
9753 $LCTL get_param -n llite.*.max_easize
9756 # Dump the value of the named xattr from a file.
9761 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9764 # Generate a string with size of $size bytes.
9766 local size=${1:-1024} # in bytes
9768 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9771 reformat_external_journal() {
9776 local varbs=${facet}_BLOCKSIZE
9777 if [ -n "${!var}" ]; then
9778 local rcmd="do_facet $facet"
9779 local bs=${!varbs:-$BLCKSIZE}
9782 echo "reformat external journal on $facet:${!var}"
9783 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9787 # MDT file-level backup/restore
9788 mds_backup_restore() {
9791 local devname=$(mdsdevname $(facet_number $facet))
9792 local mntpt=$(facet_mntpt brpt)
9793 local rcmd="do_facet $facet"
9794 local metadata=${TMP}/backup_restore.tgz
9795 local opts=${MDS_MOUNT_FS_OPTS}
9796 local svc=${facet}_svc
9798 if ! ${rcmd} test -b ${devname}; then
9799 opts=$(csa_add "$opts" -o loop)
9802 echo "file-level backup/restore on $facet:${devname}"
9804 # step 1: build mount point
9805 ${rcmd} mkdir -p $mntpt
9806 # step 2: cleanup old backup
9807 ${rcmd} rm -f $metadata
9809 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9810 if [ ! -z $igif ]; then
9811 # step 3.5: rm .lustre
9812 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9814 # step 4: backup metadata
9816 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9817 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9819 ${rcmd} $UMOUNT $mntpt || return 5
9820 # step 6: reformat dev
9821 echo "reformat new device"
9822 format_mdt $(facet_number $facet)
9824 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9825 # step 8: restore metadata
9827 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9828 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9829 # step 9: remove recovery logs
9830 echo "remove recovery logs"
9831 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9832 # step 10: umount dev
9833 ${rcmd} $UMOUNT $mntpt || return 10
9834 # step 11: cleanup tmp backup
9835 ${rcmd} rm -f $metaea $metadata
9836 # step 12: reset device label - it's not virgin on
9837 ${rcmd} e2label $devname ${!svc}
9844 local devname=$(mdsdevname $(facet_number $facet))
9845 local mntpt=$(facet_mntpt brpt)
9846 local rcmd="do_facet $facet"
9847 local opts=${MDS_MOUNT_FS_OPTS}
9849 if ! ${rcmd} test -b ${devname}; then
9850 opts=$(csa_add "$opts" -o loop)
9853 echo "removing OI files on $facet: idx=${idx}"
9855 # step 1: build mount point
9856 ${rcmd} mkdir -p $mntpt
9858 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9859 if [ -z $idx ]; then
9860 # step 3: remove all OI files
9861 ${rcmd} rm -fv $mntpt/oi.16*
9862 elif [ $idx -lt 2 ]; then
9863 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9867 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9868 for ((i=${idx}; i<64; i=$((i * idx)))); do
9869 ${rcmd} rm -fv $mntpt/oi.16.${i}
9873 ${rcmd} $UMOUNT $mntpt || return 2
9874 # OI files will be recreated when mounted as lustre next time.
9877 # generate maloo upload-able log file name
9878 # \param logname specify unique part of file name
9879 generate_logname() {
9880 local logname=${1:-"default_logname"}
9882 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9885 # make directory on different MDTs
9890 local hash_name=("all_char" "fnv_1a_64" "crush")
9891 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9892 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9894 local overstripe_count
9895 local stripe_command="-c"
9897 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9898 hash_name+=("crush2")
9900 while getopts "c:C:H:i:p" opt; do
9902 c) dirstripe_count=$OPTARG;;
9903 C) overstripe_count=$OPTARG;;
9904 H) hash_type=$OPTARG;;
9905 i) dirstripe_index=$OPTARG;;
9907 \?) error "only support -c -H -i -p";;
9911 shift $((OPTIND - 1))
9912 [ $# -eq 1 ] || error "Only creating single directory is supported"
9915 local parent=$(dirname $path)
9916 if [ "$p_option" == "-p" ]; then
9917 [ -d $path ] && return 0
9918 if [ ! -d ${parent} ]; then
9919 mkdir -p ${parent} ||
9920 error "mkdir parent '$parent' failed"
9924 if [[ -n "$overstripe_count" ]]; then
9926 dirstripe_count=$overstripe_count
9929 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9930 mkdir $path || error "mkdir '$path' failed"
9934 if [ $dirstripe_index -eq -1 ]; then
9935 mdt_index=$((base % MDSCOUNT))
9937 mdt_index=$dirstripe_index
9940 # randomly choose hash type
9941 [ -z "$hash_type" ] &&
9942 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9944 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9945 if [ $dirstripe_count -eq -1 ]; then
9946 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9952 echo "striped dir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path"
9953 $LFS mkdir -i$mdt_index $stripe_command$dirstripe_count -H $hash_type $path ||
9954 error "mkdir -i $mdt_index $stripe_command$dirstripe_count -H $hash_type $path failed"
9958 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9960 # If called many times, passing @last_fd will avoid repeated searching
9961 # already-open FDs repeatedly if we know they are still in use.
9963 # usage: free_fd [last_fd]
9966 local max_fd=$(ulimit -n)
9967 local fd=$((${1:-2} + 1))
9969 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9972 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9976 check_mount_and_prep()
9978 is_mounted $MOUNT || setupall
9980 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9981 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9982 for idx in $(seq $MDSCOUNT); do
9983 local name="MDT$(printf '%04x' $((idx - 1)))"
9984 rm -rf $MOUNT/.lustre/lost+found/$name/*
9988 # calcule how many ost-objects to be created.
9989 precreated_ost_obj_count()
9993 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9994 local ost_name="OST$(printf '%04x' $ost_idx)"
9995 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
9996 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9997 osp.$proc_path.prealloc_last_id)
9998 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9999 osp.$proc_path.prealloc_next_id)
10000 echo $((last_id - next_id + 1))
10003 check_file_in_pool()
10008 local res=$($LFS getstripe $file | grep 0x | cut -f2)
10011 for t in $tlist ; do
10012 [ "$i" -eq "$t" ] && continue 2
10015 echo "pool list: $tlist"
10016 echo "striping: $res"
10017 error_noexit "$file not allocated in $pool"
10024 echo "Creating new pool"
10027 create_pool $FSNAME.$pool ||
10028 { error_noexit "No pool created, result code $?"; return 1; }
10029 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
10030 { error_noexit "$pool not in lfs pool_list"; return 2; }
10033 pool_add_targets() {
10034 echo "Adding targets to pool"
10040 if [ -z $last ]; then
10044 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