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 GSS_PIPEFS=false
15 export SHARED_KEY=${SHARED_KEY:-false}
16 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
17 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
18 export SK_MOUNTED=${SK_MOUNTED:-false}
19 export SK_FLAVOR=${SK_FLAVOR:-ski}
20 export SK_NO_KEY=${SK_NO_KEY:-true}
21 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
22 export SK_S2S=${SK_S2S:-false}
23 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
24 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
25 export IDENTITY_UPCALL=default
27 # specify environment variable containing batch job name for server statistics
28 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
30 #export PDSH="pdsh -S -Rssh -w"
31 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
32 export UMOUNT=${UMOUNT:-"umount -d"}
34 export LSNAPSHOT_CONF="/etc/ldev.conf"
35 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
37 # sles12 umount has a issue with -d option
38 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
39 export UMOUNT="umount"
42 # function used by scripts run on remote nodes
43 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
44 . $LUSTRE/tests/functions.sh
45 . $LUSTRE/tests/yaml.sh
47 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
49 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
51 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
53 if [ -f "$EXCEPT_LIST_FILE" ]; then
54 echo "Reading test skip list from $EXCEPT_LIST_FILE"
59 # check config files for options in decreasing order of preference
60 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
61 MODPROBECONF=/etc/modprobe.d/lustre.conf
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
63 MODPROBECONF=/etc/modprobe.d/Lustre
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
65 MODPROBECONF=/etc/modprobe.conf
67 sanitize_parameters() {
68 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
71 if [ -d "$path" ]; then
72 eval export $i=$(echo $path | sed -r 's/\/+$//g')
78 [[ $DIR/ = $MOUNT/* ]] ||
79 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
80 [[ $DIR1/ = $MOUNT1/* ]] ||
81 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
82 [[ $DIR2/ = $MOUNT2/* ]] ||
83 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
85 [ -n "$failed" ] && exit 99 || true
89 echo "usage: $0 [-r] [-f cfgfile]"
97 [ -z "$DEFAULT_SUITES"] && return 0
98 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
100 local form="%-13s %-17s %-9s %s %s\n"
101 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
102 echo "------------------------------------------------------------------------------------"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 [ "${!O}" = "no" ] && continue || true
106 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
107 local log=${TMP}/${o}.log
108 if is_sanity_benchmark $o; then
109 log=${TMP}/sanity-benchmark.log
114 local status=Unfinished
116 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
118 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
119 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
120 total=$(grep duration $log | awk '{ print $2 }')
121 if [ "${!O}" = "done" ]; then
125 local durations=$(egrep "^PASS|^FAIL" $log |
126 tr -d "("| sed s/s\)$//g |
127 awk '{ print $2":"$3"|" }')
128 details=$(printf "%s\n%s %s %s\n" "$details" \
129 "DDETAILS" "$O" "$(echo $durations)")
132 printf "$form" $status "$O" "${total}" "E=$skipped"
133 printf "$form" "-" "-" "-" "S=$(echo $slow)"
136 for O in $DEFAULT_SUITES; do
137 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
138 if [ "${!O}" = "no" ]; then
139 printf "$form" "Skipped" "$O" ""
143 # print the detailed tests durations if DDETAILS=true
150 export LUSTRE=$(absolute_path $LUSTRE)
151 export TESTSUITE=$(basename $0 .sh)
152 export TEST_FAILED=false
153 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
154 export RPC_MODE=${RPC_MODE:-false}
155 export DO_CLEANUP=${DO_CLEANUP:-true}
156 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
158 export MKE2FS=$MKE2FS
159 if [ -z "$MKE2FS" ]; then
160 if which mkfs.ldiskfs >/dev/null 2>&1; then
161 export MKE2FS=mkfs.ldiskfs
167 export DEBUGFS=$DEBUGFS
168 if [ -z "$DEBUGFS" ]; then
169 if which debugfs.ldiskfs >/dev/null 2>&1; then
170 export DEBUGFS=debugfs.ldiskfs
172 export DEBUGFS=debugfs
176 export TUNE2FS=$TUNE2FS
177 if [ -z "$TUNE2FS" ]; then
178 if which tunefs.ldiskfs >/dev/null 2>&1; then
179 export TUNE2FS=tunefs.ldiskfs
181 export TUNE2FS=tune2fs
185 export E2LABEL=$E2LABEL
186 if [ -z "$E2LABEL" ]; then
187 if which label.ldiskfs >/dev/null 2>&1; then
188 export E2LABEL=label.ldiskfs
190 export E2LABEL=e2label
194 export DUMPE2FS=$DUMPE2FS
195 if [ -z "$DUMPE2FS" ]; then
196 if which dumpfs.ldiskfs >/dev/null 2>&1; then
197 export DUMPE2FS=dumpfs.ldiskfs
199 export DUMPE2FS=dumpe2fs
203 export E2FSCK=$E2FSCK
204 if [ -z "$E2FSCK" ]; then
205 if which fsck.ldiskfs >/dev/null 2>&1; then
206 export E2FSCK=fsck.ldiskfs
212 export RESIZE2FS=$RESIZE2FS
213 if [ -z "$RESIZE2FS" ]; then
214 if which resizefs.ldiskfs >/dev/null 2>&1; then
215 export RESIZE2FS=resizefs.ldiskfs
217 export RESIZE2FS=resize2fs
221 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
222 export FSCK_MAX_ERR=4 # File system errors left uncorrected
224 export ZFS=${ZFS:-zfs}
225 export ZPOOL=${ZPOOL:-zpool}
226 export ZDB=${ZDB:-zdb}
227 export PARTPROBE=${PARTPROBE:-partprobe}
229 #[ -d /r ] && export ROOT=${ROOT:-/r}
230 export TMP=${TMP:-$ROOT/tmp}
231 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
232 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
233 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
235 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
236 if ! echo $PATH | grep -q $LUSTRE/utils; then
237 export PATH=$LUSTRE/utils:$PATH
239 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
240 export PATH=$LUSTRE/utils/gss:$PATH
242 if ! echo $PATH | grep -q $LUSTRE/tests; then
243 export PATH=$LUSTRE/tests:$PATH
245 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
246 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
248 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
249 [ ! -f "$LST" ] && export LST=$(which lst)
250 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
251 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
252 export MCREATE=${MCREATE:-mcreate}
253 # Ubuntu, at least, has a truncate command in /usr/bin
254 # so fully path our truncate command.
255 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
256 export FSX=${FSX:-$LUSTRE/tests/fsx}
257 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
258 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
259 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
260 export PATH=$LUSTRE/tests/racer:$PATH:
262 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
263 export PATH=$LUSTRE/tests/mpi:$PATH
265 export RSYNC_RSH=${RSYNC_RSH:-rsh}
267 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
268 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
269 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
270 [ ! -f "$LFS" ] && export LFS=$(which lfs)
271 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
272 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
274 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
275 if [ ! -f "$L_GETIDENTITY" ]; then
276 if `which l_getidentity > /dev/null 2>&1`; then
277 export L_GETIDENTITY=$(which l_getidentity)
279 export L_GETIDENTITY=NONE
282 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
283 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
284 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
285 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
286 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
287 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
288 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
289 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
290 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
291 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
292 [ ! -f "$LUSTRE_RMMOD" ] &&
293 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
294 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
295 [ ! -f "$LFS_MIGRATE" ] &&
296 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
297 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
298 [ ! -f "$LR_READER" ] &&
299 export LR_READER=$(which lr_reader 2> /dev/null)
300 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
301 export NAME=${NAME:-local}
302 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
303 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
304 export LGSSD=$(which lgssd)
305 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
306 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
307 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
309 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
311 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
312 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
314 if [ "$ACCEPTOR_PORT" ]; then
315 export PORT_OPT="--port $ACCEPTOR_PORT"
319 $RPC_MODE || echo "Using GSS shared-key feature"
320 which lgss_sk > /dev/null 2>&1 ||
321 error_exit "built with lgss_sk disabled! SEC=$SEC"
329 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
330 which lgss_keyring > /dev/null 2>&1 ||
331 error_exit "built with gss disabled! SEC=$SEC"
342 IDENTITY_UPCALL=false
346 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
348 # Paths on remote nodes, if different
349 export RLUSTRE=${RLUSTRE:-$LUSTRE}
350 export RPWD=${RPWD:-$PWD}
351 export I_MOUNTED=${I_MOUNTED:-"no"}
352 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
353 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
354 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
355 ! -f $LUSTRE/mdt/mdt.ko ]; then
356 export CLIENTMODSONLY=yes
359 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
360 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
364 while getopts "rvwf:" opt $*; do
369 w) WRITECONF=writeconf;;
374 shift $((OPTIND - 1))
377 # print the durations of each test if "true"
378 DDETAILS=${DDETAILS:-false}
379 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
384 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
391 ncpts=$(do_facet $facet "lctl get_param -n " \
392 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
394 if [ $ncpts -eq 0 ]; then
401 # Return a numeric version code based on a version string. The version
402 # code is useful for comparison two version strings to see which is newer.
404 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
405 eval set -- $(tr "[:punct:]" " " <<< $*)
407 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
410 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
411 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
413 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
415 # usage: lustre_build_version
417 # All Lustre versions support "lctl get_param" to report the version of the
418 # code running in the kernel (what our tests are interested in), but it
419 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
420 # the "version" parameter doesn't include "lustre: " at the beginning.
421 # If that fails, call "lctl lustre_build_version" which prints either (or both)
422 # the userspace and kernel build versions, but until 2.8.55 required root
423 # access to get the Lustre kernel version. If that also fails, fall back to
424 # using "lctl --version", which is easy to parse and works without the kernel
425 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
426 # not the module version, though they are usually the same.
428 # Various commands and their output format for different Lustre versions:
429 # lctl get_param version: 2.9.55
430 # lctl get_param version: lustre: 2.8.53
431 # lctl get_param version: lustre: 2.6.52
432 # kernel: patchless_client
433 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
434 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
435 # lctl lustre_build_version: error: lustre_build_version: Permission denied
436 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
437 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
438 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
439 # lctl --version: lctl 2.6.50
441 # output: prints version string to stdout in (up to 4) dotted-decimal values
442 lustre_build_version() {
443 local facet=${1:-client}
446 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
447 $LCTL lustre_build_version 2>/dev/null ||
448 $LCTL --version 2>/dev/null | cut -d' ' -f2")
449 local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
450 [ -n "$lver" ] && ver="$lver"
452 sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
456 # Report the Lustre numeric build version code for the supplied facet.
457 lustre_version_code() {
458 version_code $(lustre_build_version $1)
462 /sbin/lsmod | grep -q "^\<$1\>"
474 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
477 # parallels can't load modules directly from prlfs, use /tmp instead
478 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
479 local target="$(mktemp)"
481 cp "$module" "$target"
484 [[ $rc == 0 ]] && PRLFS=true
492 # Load a module on the system where this is running.
494 # usage: load_module module_name [module arguments for insmod/modprobe]
496 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
497 # will be used as the arguments. Otherwise arguments will be obtained from
498 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
505 BASE=$(basename $module $EXT)
507 module_loaded ${BASE} && return
509 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
510 # else from modprobe.conf
511 if [ $# -eq 0 ]; then
512 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
513 # Bash until 4.x, so we resort to eval.
514 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
515 eval set -- \$$optvar
516 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
517 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
519 opt=$(awk -v var="^options $BASE" '$0 ~ var \
520 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
521 set -- $(echo -n $opt)
523 # Ensure we have accept=all for lnet
524 if [ $(basename $module) = lnet ]; then
525 # OK, this is a bit wordy...
526 local arg accept_all_present=false
529 [ "$arg" = accept=all ] && \
530 accept_all_present=true
532 $accept_all_present || set -- "$@" accept=all
538 [ $# -gt 0 ] && echo "${module} options: '$*'"
540 # Note that insmod will ignore anything in modprobe.conf, which is why
541 # we're passing options on the command-line.
542 if [[ "$BASE" == "lnet_selftest" ]] &&
543 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
544 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
545 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
546 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
547 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
549 # must be testing a "make install" or "rpm" installation
550 # note failed to load ptlrpc_gss is considered not fatal
551 if [[ "$BASE" == "ptlrpc_gss" ]]; then
552 modprobe $BASE "$@" 2>/dev/null ||
553 echo "gss/krb5 is not supported"
560 load_modules_local() {
561 if [ -n "$MODPROBE" ]; then
563 echo "Using modprobe to load modules"
567 echo Loading modules from $LUSTRE
571 if [ -f /sys/devices/system/cpu/online ]; then
572 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
573 echo "detected $ncpus online CPUs by sysfs"
575 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
577 if [ $rc -eq 0 ]; then
578 echo "detected $ncpus online CPUs by getconf"
580 echo "Can't detect number of CPUs"
585 # if there is only one CPU core, libcfs can only create one partition
586 # if there is more than 4 CPU cores, libcfs should create multiple CPU
587 # partitions. So we just force libcfs to create 2 partitions for
588 # system with 2 or 4 cores
589 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
590 # force to enable multiple CPU partitions
591 echo "Force libcfs to create 2 CPU partitions"
592 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
594 echo "libcfs will create CPU partition based on online CPUs"
597 load_module ../libcfs/libcfs/libcfs
598 # Prevent local MODOPTS_LIBCFS being passed as part of environment
599 # variable to remote nodes
603 load_module ../lnet/lnet/lnet
605 LNDPATH=${LNDPATH:-"../lnet/klnds"}
606 if [ -z "$LNETLND" ]; then
608 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
609 tcp*) LNETLND="socklnd/ksocklnd" ;;
610 *) local lnd="${NETTYPE%%[0-9]}lnd"
611 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
612 LNETLND="$lnd/k$lnd" ||
613 LNETLND="socklnd/ksocklnd"
616 load_module ../lnet/klnds/$LNETLND
617 load_module obdclass/obdclass
618 load_module ptlrpc/ptlrpc
619 load_module ptlrpc/gss/ptlrpc_gss
627 load_module obdecho/obdecho
628 if ! client_only; then
629 SYMLIST=/proc/kallsyms
630 grep -q crc16 $SYMLIST ||
631 { modprobe crc16 2>/dev/null || true; }
632 grep -q -w jbd2 $SYMLIST ||
633 { modprobe jbd2 2>/dev/null || true; }
634 load_module lfsck/lfsck
635 [ "$LQUOTA" != "no" ] &&
636 load_module quota/lquota $LQUOTAOPTS
637 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
638 lsmod | grep zfs >&/dev/null || modprobe zfs
639 load_module osd-zfs/osd_zfs
641 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
642 grep -q exportfs_decode_fh $SYMLIST ||
643 { modprobe exportfs 2> /dev/null || true; }
644 grep -q -w mbcache $SYMLIST ||
645 { modprobe mbcache 2>/dev/null || true; }
646 load_module ../ldiskfs/ldiskfs
647 load_module osd-ldiskfs/osd_ldiskfs
659 load_module llite/lustre
660 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
662 rm -f $OGDB/ogdb-$HOSTNAME
663 $LCTL modules > $OGDB/ogdb-$HOSTNAME
665 # 'mount' doesn't look in $PATH, just sbin
666 local mount_lustre=$LUSTRE/utils/mount.lustre
667 if [ -f $mount_lustre ]; then
668 local sbin_mount=$(readlink -f /sbin)/mount.lustre
669 if grep -qw "$sbin_mount" /proc/mounts; then
670 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
672 if ! grep -qw "$sbin_mount" /proc/mounts; then
673 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
674 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
675 cat <<- EOF > "$sbin_mount"
678 echo "This $sbin_mount just a mountpoint." 1>&2
679 echo "It is never supposed to be run." 1>&2
680 logger -p emerg -- "using stub $sbin_mount $@"
683 chmod a+x $sbin_mount
685 mount --bind $mount_lustre $sbin_mount ||
686 error "can't bind $mount_lustre to $sbin_mount"
694 # load modules on remote nodes optionally
695 # lustre-tests have to be installed on these nodes
696 if $LOAD_MODULES_REMOTE; then
697 local list=$(comma_list $(remote_nodes_list))
698 if [ -n "$list" ]; then
699 echo "loading modules on: '$list'"
700 do_rpc_nodes "$list" load_modules_local
706 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
707 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
708 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
709 echo "$LEAK_LUSTRE" 1>&2
710 echo "$LEAK_PORTALS" 1>&2
711 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
712 echo "Memory leaks detected"
713 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
719 wait_exit_ST client # bug 12845
721 $LUSTRE_RMMOD ldiskfs || return 2
723 if $LOAD_MODULES_REMOTE; then
724 local list=$(comma_list $(remote_nodes_list))
725 if [ -n "$list" ]; then
726 echo "unloading modules on: '$list'"
727 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
728 do_rpc_nodes "$list" check_mem_leak
732 local sbin_mount=$(readlink -f /sbin)/mount.lustre
733 if grep -qe "$sbin_mount " /proc/mounts; then
734 umount $sbin_mount || true
735 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
739 check_mem_leak || return 254
741 echo "modules unloaded."
746 local facet=${1:-$SINGLEMDS}
747 local fstype=$(facet_fstype $facet)
750 ldiskfs) size=50;; # largest seen is 44, leave some headroom
751 zfs) size=400;; # largest seen is 384
758 local facet=${1:-$SINGLEMDS}
759 local fstype=$(facet_fstype $facet)
762 ldiskfs) size=4;; # ~4KB per inode
763 zfs) size=11;; # 10 to 11KB per inode
769 check_gss_daemon_nodes() {
773 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
774 if [ \\\"\\\$num\\\" -ne 1 ]; then
775 echo \\\$num instance of $dname;
780 check_gss_daemon_facet() {
784 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
785 if [ $num -ne 1 ]; then
786 echo "$num instance of $dname on $facet"
795 echo Stopping $@ on $list
796 do_nodes $list "killall -2 $@ 2>/dev/null || true"
799 # start gss daemons on all nodes, or "daemon" on "nodes" if set
800 start_gss_daemons() {
804 if [ "$nodes" ] && [ "$daemon" ] ; then
805 echo "Starting gss daemon on nodes: $nodes"
806 do_nodes $nodes "$daemon" || return 8
810 nodes=$(comma_list $(mdts_nodes))
811 echo "Starting gss daemon on mds: $nodes"
813 # Start all versions, in case of switching
814 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
816 do_nodes $nodes "$LSVCGSSD -v" || return 1
819 do_nodes $nodes "$LGSSD -v" || return 2
822 nodes=$(comma_list $(osts_nodes))
823 echo "Starting gss daemon on ost: $nodes"
825 # Start all versions, in case of switching
826 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
828 do_nodes $nodes "$LSVCGSSD -v" || return 3
830 # starting on clients
832 local clients=${CLIENTS:-$HOSTNAME}
834 echo "Starting $LGSSD on clients $clients "
835 do_nodes $clients "$LGSSD -v" || return 4
838 # wait daemons entering "stable" status
842 # check daemons are running
844 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
845 check_gss_daemon_nodes $nodes lsvcgssd || return 5
847 nodes=$(comma_list $(mdts_nodes))
848 check_gss_daemon_nodes $nodes lgssd || return 6
851 check_gss_daemon_nodes $clients lgssd || return 7
856 local nodes=$(comma_list $(mdts_nodes))
858 send_sigint $nodes lsvcgssd lgssd
860 nodes=$(comma_list $(osts_nodes))
861 send_sigint $nodes lsvcgssd
863 nodes=${CLIENTS:-$HOSTNAME}
864 send_sigint $nodes lgssd
868 # Add mount flags for shared key
870 if grep -q skpath <<< "$mt_opts" ; then
871 mt_opts=$(echo $mt_opts |
872 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
874 if [ -z "$mt_opts" ]; then
875 mt_opts="-o skpath=$SK_PATH"
877 mt_opts="$mt_opts,skpath=$SK_PATH"
893 if ! module_loaded ptlrpc_gss; then
894 load_module ptlrpc/gss/ptlrpc_gss
895 module_loaded ptlrpc_gss ||
896 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
899 if $GSS_KRB5 || $GSS_SK; then
900 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
903 if $GSS_SK && $SK_NO_KEY; then
904 local numclients=${1:-$CLIENTCOUNT}
905 local clients=${CLIENTS:-$HOSTNAME}
907 # security ctx config for keyring
910 mount -o bind $SK_OM_PATH /etc/request-key.d/
911 local lgssc_conf_line='create lgssc * * '
912 lgssc_conf_line+=$(which lgss_keyring)
913 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
915 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
916 echo "$lgssc_conf_line" > $lgssc_conf_file
917 [ -e $lgssc_conf_file ] ||
918 error_exit "Could not find key options in $lgssc_conf_file"
920 if ! local_mode; then
921 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
923 do_nodes $(comma_list $(all_nodes)) "mount \
924 -o bind $SK_OM_PATH \
926 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
927 $HOSTNAME:$lgssc_conf_file \
928 $lgssc_conf_file >/dev/null 2>&1"
931 # create shared key on all nodes
932 mkdir -p $SK_PATH/nodemap
933 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
934 $SK_PATH/$FSNAME-*.key
935 # for nodemap testing each client may need own key,
936 # and S2S now requires keys as well, both for "client"
939 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
940 -w $SK_PATH/$FSNAME-nmclient.key \
941 -d /dev/urandom >/dev/null 2>&1
942 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
943 -w $SK_PATH/$FSNAME-s2s-server.key \
944 -d /dev/urandom >/dev/null 2>&1
947 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
948 -d /dev/urandom >/dev/null 2>&1
950 for i in $(seq 0 $((numclients - 1))); do
951 lgss_sk -t server -f$FSNAME -n c$i \
952 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
956 if ! local_mode; then
957 do_nodes $(comma_list $(all_nodes)) "rsync -av \
958 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
960 # Set client keys to client type to generate prime P
962 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
963 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
965 do_nodes $clients "lgss_sk -t client -m \
966 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
967 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
968 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
970 # This is required for servers as well, if S2S in use
972 do_nodes $(comma_list $(mdts_nodes)) \
973 "cp $SK_PATH/$FSNAME-s2s-server.key \
974 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
975 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
977 do_nodes $(comma_list $(osts_nodes)) \
978 "cp $SK_PATH/$FSNAME-s2s-server.key \
979 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
980 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
982 do_nodes $clients "lgss_sk -t client \
983 -m $SK_PATH/$FSNAME-nmclient.key \
986 # mount options for servers and clients
987 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
988 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
989 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
990 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
994 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
996 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1003 # maybe cleanup credential cache?
1010 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1011 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1012 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1016 $RPC_MODE || echo "Cleaning up Shared Key.."
1017 do_nodes $(comma_list $(all_nodes)) "rm -f \
1018 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1019 # Remove the mount and clean up the files we added to SK_PATH
1020 do_nodes $(comma_list $(all_nodes)) "umount \
1021 /etc/request-key.d/"
1022 do_nodes $(comma_list $(all_nodes)) "rm -f \
1023 $SK_OM_PATH/lgssc.conf"
1024 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1031 local var=${facet}_svc
1039 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1040 tr '[:lower:]' '[:upper:]'
1046 if [ $facet == mgs ] || [ $facet == client ]; then
1050 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1058 if [ -n "${!var}" ]; then
1063 var=$(facet_type $facet)FSTYPE
1064 if [ -n "${!var}" ]; then
1069 if [ -n "$FSTYPE" ]; then
1074 if [[ $facet == mgs ]] && combined_mgs_mds; then
1086 local facets=$(get_facets)
1089 for facet in ${facets//,/ }; do
1090 if [ $node == $(facet_host $facet) ] ||
1091 [ $node == "$(facet_failover_host $facet)" ]; then
1092 fstype=$(facet_fstype $facet)
1093 if [[ $fstypes != *$fstype* ]]; then
1094 fstypes+="${fstypes:+,}$fstype"
1103 local num=$(facet_number $facet)
1106 if [[ $(facet_type $facet) = OST ]]; then
1107 index=OSTINDEX${num}
1108 if [[ -n "${!index}" ]]; then
1113 index=${OST_INDICES[num - 1]}
1116 [[ -n "$index" ]] || index=$((num - 1))
1124 local fstype=$(facet_fstype $facet)
1128 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1130 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1131 ${dev} 2>/dev/null");;
1133 error "unknown fstype!";;
1141 local device=$(mdsdevname $num)
1142 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1148 local device=$(ostdevname $num)
1149 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1154 # Get the device of a facet.
1161 mgs) device=$(mgsdevname) ;;
1162 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1163 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1164 fs2mds) device=$(mdsdevname 1_2) ;;
1165 fs2ost) device=$(ostdevname 1_2) ;;
1166 fs3ost) device=$(ostdevname 2_2) ;;
1174 # Get the virtual device of a facet.
1181 mgs) device=$(mgsvdevname) ;;
1182 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1183 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1184 fs2mds) device=$(mdsvdevname 1_2) ;;
1185 fs2ost) device=$(ostvdevname 1_2) ;;
1186 fs3ost) device=$(ostvdevname 2_2) ;;
1194 local virt=$(virt-what 2> /dev/null)
1196 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1198 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1201 VMware|KVM|VirtualBox|Parallels)
1202 echo $virt | tr '[A-Z]' '[a-z]' ;;
1208 # Re-read the partition table on failover partner host.
1209 # After a ZFS storage pool is created on a shared device, the partition table
1210 # on the device may change. However, the operating system on the failover
1211 # host may not notice the change automatically. Without the up-to-date partition
1212 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1213 # relative to partition rather than disk beginnings.
1215 # This function performs partprobe on the failover host to make it re-read the
1218 refresh_partition_table() {
1223 host=$(facet_passive_host $facet)
1224 if [[ -n "$host" ]]; then
1225 do_node $host "$PARTPROBE $device"
1230 # Get ZFS storage pool name.
1237 device=$(facet_device $facet)
1238 # poolname is string before "/"
1239 poolname="${device%%/*}"
1246 # Get ZFS local fsname.
1248 zfs_local_fsname() {
1250 local lfsname=$(basename $(facet_device $facet))
1256 # Create ZFS storage pool.
1263 local opts=${@:-"-o cachefile=none"}
1265 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1266 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1267 $ZPOOL create -f $opts $poolname $vdev"
1271 # Create ZFS file system.
1277 local opts=${@:-"-o mountpoint=legacy"}
1279 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1280 $ZFS create $opts $dataset"
1284 # Export ZFS storage pool.
1285 # Before exporting the pool, all datasets within the pool should be unmounted.
1293 poolname=$(zpool_name $facet)
1295 if [[ -n "$poolname" ]]; then
1296 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1297 grep -q ^$poolname/ /proc/mounts ||
1298 $ZPOOL export $opts $poolname"
1303 # Destroy ZFS storage pool.
1304 # Destroy the given pool and free up any devices for other use. This command
1305 # tries to unmount any active datasets before destroying the pool.
1306 # -f Force any active datasets contained within the pool to be unmounted.
1310 local poolname=${2:-$(zpool_name $facet)}
1312 if [[ -n "$poolname" ]]; then
1313 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1314 $ZPOOL destroy -f $poolname"
1319 # Import ZFS storage pool.
1320 # Force importing, even if the pool appears to be potentially active.
1325 local opts=${@:-"-o cachefile=none"}
1328 poolname=$(zpool_name $facet)
1330 if [[ -n "$poolname" ]]; then
1331 opts+=" -d $(dirname $(facet_vdevice $facet))"
1332 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1333 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1334 $ZPOOL import -f $opts $poolname"
1339 # Reimport ZFS storage pool with new name
1344 local opts="-o cachefile=none"
1345 local poolname=$(zpool_name $facet)
1347 opts+=" -d $(dirname $(facet_vdevice $facet))"
1348 do_facet $facet "$ZPOOL export $poolname;
1349 $ZPOOL import $opts $poolname $newpool"
1353 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1354 # is not automatically imported on system startup.
1356 # In a failover environment, this will provide resource level fencing which
1357 # will ensure that the same ZFS storage pool will not be imported concurrently
1358 # on different nodes.
1360 disable_zpool_cache() {
1364 poolname=$(zpool_name $facet)
1366 if [[ -n "$poolname" ]]; then
1367 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1372 # This and set_osd_param() shall be used to access OSD parameters
1373 # once existed under "obdfilter":
1378 # writethrough_cache_enable
1382 local device=${2:-$FSNAME-OST*}
1385 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1386 osd-*.$device.$name 2>&1" | grep -v 'error:'
1391 local device=${2:-$FSNAME-OST*}
1395 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1396 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1400 local dz=${1:-$DEBUG_SIZE}
1402 if [ -f /sys/devices/system/cpu/possible ]; then
1403 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1405 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1408 # bug 19944, adjust size to be -gt num_possible_cpus()
1409 # promise 2MB for every cpu at least
1410 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1413 lctl set_param debug_mb=$dz
1416 set_default_debug () {
1417 local debug=${1:-"$PTLDEBUG"}
1418 local subsys=${2:-"$SUBSYSTEM"}
1419 local debug_size=${3:-$DEBUG_SIZE}
1421 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1422 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1424 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1427 set_default_debug_nodes () {
1430 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1431 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1435 do_rpc_nodes "$nodes" set_default_debug \
1436 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1439 set_default_debug_facet () {
1441 local node=$(facet_active_host $facet)
1442 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1444 set_default_debug_nodes $node
1448 local hostid=${1:-$(hostid)}
1450 if [ ! -s /etc/hostid ]; then
1451 printf $(echo -n $hostid |
1452 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1458 local facets=${1:-$(get_facets)}
1461 for facet in ${facets//,/ }; do
1464 [ $RC -eq 0 ] && continue
1466 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1467 skip "Restart of $facet failed!." && touch $LU482_FAILED
1469 error "Restart of $facet failed!"
1476 # Add argument "arg" (e.g., "loop") to the comma-separated list
1477 # of arguments for option "opt" (e.g., "-o") on command
1478 # line "opts" (e.g., "-o flock").
1484 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1486 if echo "$opts" | grep -q $opt_pattern; then
1487 opts=$(echo "$opts" | sed -e \
1488 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1490 opts+="${opts:+ }$opt $arg"
1498 local dev=$(facet_active $facet)_dev
1499 local opt=${facet}_opt
1500 local mntpt=$(facet_mntpt $facet)
1501 local opts="${!opt} $@"
1502 local fstype=$(facet_fstype $facet)
1505 module_loaded lustre || load_modules
1507 if [ $(facet_fstype $facet) == ldiskfs ] &&
1508 ! do_facet $facet test -b ${!dev}; then
1509 opts=$(csa_add "$opts" -o loop)
1512 if [[ $(facet_fstype $facet) == zfs ]]; then
1513 # import ZFS storage pool
1514 import_zpool $facet || return ${PIPESTATUS[0]}
1519 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1521 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1522 lustre:svname ${!dev}");;
1524 error "unknown fstype!";;
1527 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1528 # for testing LU-482 error handling in mount_facets() and test_0a()
1529 if [ -f $TMP/test-lu482-trigger ]; then
1532 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1537 if [ $RC -ne 0 ]; then
1538 echo "Start of ${!dev} on ${facet} failed ${RC}"
1542 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1543 if [[ "$health" != "healthy" ]]; then
1544 error "$facet is in a unhealthy state"
1547 set_default_debug_facet $facet
1549 if [[ $facet == mds* ]]; then
1551 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1554 if [[ $opts =~ .*nosvc.* ]]; then
1555 echo "Start ${!dev} without service"
1560 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1561 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1562 "" || error "${!dev} failed to initialize!";;
1564 wait_update_facet ${facet} "$ZFS get -H -o value \
1565 lustre:svname ${!dev} 2>/dev/null | \
1566 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1567 error "${!dev} failed to initialize!";;
1570 error "unknown fstype!";;
1574 # commit the device label change to disk
1575 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1576 echo "Commit the device label on ${!dev}"
1577 do_facet $facet "sync; sleep 1; sync"
1581 label=$(devicelabel ${facet} ${!dev})
1582 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1583 eval export ${facet}_svc=${label}
1584 echo Started ${label}
1589 # start facet device options
1595 eval export ${facet}_dev=${device}
1596 eval export ${facet}_opt=\"$@\"
1598 local varname=${facet}failover_dev
1599 if [ -n "${!varname}" ] ; then
1600 eval export ${facet}failover_dev=${!varname}
1602 eval export ${facet}failover_dev=$device
1605 local mntpt=$(facet_mntpt $facet)
1606 do_facet ${facet} mkdir -p $mntpt
1607 eval export ${facet}_MOUNT=$mntpt
1608 mount_facet ${facet}
1611 if [[ $facet == mds* ]]; then
1613 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1624 local HOST=`facet_active_host $facet`
1625 [ -z $HOST ] && echo stop: no host for $facet && return 0
1627 local mntpt=$(facet_mntpt $facet)
1628 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1629 if [ ${running} -ne 0 ]; then
1630 echo "Stopping $mntpt (opts:$@) on $HOST"
1631 do_facet ${facet} $UMOUNT $@ $mntpt
1634 # umount should block, but we should wait for unrelated obd's
1635 # like the MGS or MGC to also stop.
1636 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1638 if [[ $(facet_fstype $facet) == zfs ]]; then
1639 # export ZFS storage pool
1640 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1644 # save quota version (both administrative and operational quotas)
1645 # add an additional parameter if mountpoint is ever different from $MOUNT
1647 # XXX This function is kept for interoperability with old server (< 2.3.50),
1648 # it should be removed whenever we drop the interoperability for such
1650 quota_save_version() {
1651 local fsname=${2:-$FSNAME}
1653 local ver=$(tr -c -d "123" <<< $spec)
1654 local type=$(tr -c -d "ug" <<< $spec)
1656 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1658 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1660 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1662 local osts=$(get_facets OST)
1663 for ost in ${osts//,/ }; do
1665 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1669 # client could mount several lustre
1671 # XXX This function is kept for interoperability with old server (< 2.3.50),
1672 # it should be removed whenever we drop the interoperability for such
1675 local fsname=${1:-$FSNAME}
1677 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1679 do_nodes $(comma_list $(osts_nodes)) \
1680 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1684 # get mdt quota type
1686 local varsvc=${SINGLEMDS}_svc
1687 do_facet $SINGLEMDS $LCTL get_param -n \
1688 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1691 # get ost quota type
1693 # All OSTs should have same quota type
1694 local varsvc=ost1_svc
1695 do_facet ost1 $LCTL get_param -n \
1696 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1699 # restore old quota type settings
1701 if [ "$old_MDT_QUOTA_TYPE" ]; then
1702 do_facet mgs $LCTL conf_param \
1703 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1705 if [ "$old_OST_QUOTA_TYPE" ]; then
1706 do_facet mgs $LCTL conf_param \
1707 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1711 # Handle the case when there is a space in the lfs df
1712 # "filesystem summary" line the same as when there is no space.
1713 # This will allow fixing the "lfs df" summary line in the future.
1715 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1718 # Get free inodes on the MDT specified by mdt index, free indoes on
1719 # the whole filesystem will be returned when index == -1.
1725 if [ $index -eq -1 ]; then
1728 mdt_uuid=$(mdtuuid_from_index $index)
1731 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1736 # Get the OST device status from 'lfs df' with a given OST index.
1740 local mnt_pnt=${2:-$MOUNT}
1743 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1744 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1750 # save old quota type & set new quota type
1751 local mdt_qtype=$(mdt_quota_type)
1752 local ost_qtype=$(ost_quota_type)
1754 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1755 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1757 export old_MDT_QUOTA_TYPE=$mdt_qtype
1758 export old_OST_QUOTA_TYPE=$ost_qtype
1760 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1761 error "set mdt quota type failed"
1762 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1763 error "set ost quota type failed"
1765 local quota_usrs=$QUOTA_USERS
1767 # get_filesystem_size
1768 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1769 local blk_soft=$((disksz + 1024))
1770 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1772 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1773 local i_soft=$inodes
1774 local i_hard=$((i_soft + i_soft / 20))
1776 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1777 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1778 "inode-hardlimit: $i_hard"
1781 for usr in $quota_usrs; do
1782 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1784 cmd="$LFS setquota -$type $usr -b $blk_soft"
1785 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1787 eval $cmd || error "$cmd FAILED!"
1789 # display the quota status
1790 echo "Quota settings for $usr : "
1791 $LFS quota -v -u $usr $mntpt || true
1798 local opts=${3:-$MOUNT_OPTS}
1799 opts=${opts:+-o $opts}
1800 local flags=${4:-$MOUNT_FLAGS}
1802 local device=$MGSNID:/$FSNAME$FILESET
1803 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1804 echo "Bad mount command: opt=$flags $opts dev=$device " \
1809 echo "Starting client: $client: $flags $opts $device $mnt"
1810 do_node $client mkdir -p $mnt
1811 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1812 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1814 #disable FILESET if not supported
1815 do_nodes $client lctl get_param -n \
1816 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1817 device=$MGSNID:/$FSNAME
1818 do_node $client mkdir -p $mnt/$FILESET
1819 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1822 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1823 # Mount using nodemap key
1824 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1825 if $SK_UNIQUE_NM; then
1826 mountkey=$SK_PATH/nodemap/c0.key
1828 local prunedopts=$(echo $opts |
1829 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
1830 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
1833 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
1837 set_default_debug_nodes $client
1849 [ "$3" ] && force=-f
1850 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1851 if [ $running -ne 0 ]; then
1852 echo "Stopping client $client $mnt (opts:$force)"
1853 do_node $client lsof -t $mnt || need_kill=no
1854 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1855 pids=$(do_node $client lsof -t $mnt | sort -u);
1856 if [ -n $pids ]; then
1857 do_node $client kill -9 $pids || true
1861 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1862 if [ $busy -ne 0 ] ; then
1863 echo "$mnt is still busy, wait one second" && sleep 1
1864 do_node $client umount $force $mnt
1869 # nodes is comma list
1870 sanity_mount_check_nodes () {
1876 # FIXME: assume that all cluster nodes run the same os
1877 [ "$(uname)" = Linux ] || return 0
1880 for mnt in $mnts ; do
1881 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1882 mpts=\\\$(mount | grep -c $mnt' ');
1883 if [ \\\$running -ne \\\$mpts ]; then
1884 echo \\\$(hostname) env are INSANE!;
1887 [ $? -eq 0 ] || rc=1
1892 sanity_mount_check_servers () {
1893 [ -n "$CLIENTONLY" ] &&
1894 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1895 echo Checking servers environments
1897 # FIXME: modify get_facets to display all facets wo params
1898 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1902 for facet in ${facets//,/ }; do
1903 node=$(facet_host ${facet})
1904 mntpt=$(facet_mntpt $facet)
1905 sanity_mount_check_nodes $node $mntpt ||
1906 { error "server $node environments are insane!"; return 1; }
1910 sanity_mount_check_clients () {
1911 local clients=${1:-$CLIENTS}
1912 local mntpt=${2:-$MOUNT}
1913 local mntpt2=${3:-$MOUNT2}
1915 [ -z $clients ] && clients=$(hostname)
1916 echo Checking clients $clients environments
1918 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1919 error "clients environments are insane!"
1922 sanity_mount_check () {
1923 sanity_mount_check_servers || return 1
1924 sanity_mount_check_clients || return 2
1927 # mount clients if not mouted
1928 zconf_mount_clients() {
1931 local opts=${3:-$MOUNT_OPTS}
1932 opts=${opts:+-o $opts}
1933 local flags=${4:-$MOUNT_FLAGS}
1934 local device=$MGSNID:/$FSNAME$FILESET
1935 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1936 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1941 echo "Starting client $clients: $flags $opts $device $mnt"
1942 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1943 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1944 # Mount with own nodemap key
1946 # Mount all server nodes first with per-NM keys
1947 for nmclient in ${clients//,/ }; do
1948 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
1949 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
1952 # set perms for per-nodemap keys else permission denied
1953 do_nodes $(comma_list $(all_nodes)) \
1954 "keyctl show | grep lustre | cut -c1-11 |
1956 xargs -IX keyctl setperm X 0x3f3f3f3f"
1957 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1959 for nmclient in ${clients//,/ }; do
1960 if $SK_UNIQUE_NM; then
1961 mountkey=$SK_PATH/nodemap/c$i.key
1963 do_node $nmclient "! grep -q $mnt' ' \
1964 /proc/mounts || umount $mnt"
1965 local prunedopts=$(add_sk_mntflag $prunedopts);
1966 prunedopts=$(echo $prunedopts | sed -e \
1967 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
1969 do_nodes $(comma_list $(all_server_nodes)) \
1972 do_node $nmclient $MOUNT_CMD $flags \
1973 $prunedopts $MGSNID:/$FSNAME $mnt ||
1978 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1980 do_nodes $clients $MOUNT_CMD $flags $opts \
1981 $MGSNID:/$FSNAME $mnt || return 1
1983 #disable FILESET if not supported
1984 do_nodes $clients lctl get_param -n \
1985 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1986 device=$MGSNID:/$FSNAME
1987 do_nodes $clients mkdir -p $mnt/$FILESET
1988 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1992 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1993 # Mount with nodemap key
1995 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1996 for nmclient in ${clients//,/ }; do
1997 if $SK_UNIQUE_NM; then
1998 mountkey=$SK_PATH/nodemap/c$i.key
2000 local prunedopts=$(echo $opts | sed -e \
2001 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2002 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2005 running=\\\$(mount | grep -c $mnt' ');
2007 if [ \\\$running -eq 0 ] ; then
2009 $MOUNT_CMD $flags $prunedopts $device $mnt;
2012 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2013 grep 'type lustre' | wc -l);
2014 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2015 echo zconf_mount_clients FAILED: \
2016 mount count \\\$running, not matching \
2017 with mount count of 'type lustre' \
2018 \\\$lustre_mnt_count;
2022 exit \\\$rc" || return ${PIPESTATUS[0]}
2029 if $SHARED_KEY; then
2030 tmpopts=$(add_sk_mntflag $opts)
2033 running=\\\$(mount | grep -c $mnt' ');
2035 if [ \\\$running -eq 0 ] ; then
2037 $MOUNT_CMD $flags $tmpopts $device $mnt;
2040 exit \\\$rc" || return ${PIPESTATUS[0]}
2043 echo "Started clients $clients: "
2044 do_nodes $clients "mount | grep $mnt' '"
2046 set_default_debug_nodes $clients
2051 zconf_umount_clients() {
2056 [ "$3" ] && force=-f
2058 echo "Stopping clients: $clients $mnt (opts:$force)"
2059 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2060 if [ \\\$running -ne 0 ] ; then
2061 echo Stopping client \\\$(hostname) $mnt opts:$force;
2062 lsof $mnt || need_kill=no;
2063 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2064 pids=\\\$(lsof -t $mnt | sort -u);
2065 if [ -n \\\"\\\$pids\\\" ]; then
2069 while umount $force $mnt 2>&1 | grep -q "busy"; do
2070 echo "$mnt is still busy, wait one second" && sleep 1;
2077 echo + $POWER_DOWN $node
2081 shutdown_node_hard () {
2083 local attempts=$SHUTDOWN_ATTEMPTS
2085 for i in $(seq $attempts) ; do
2088 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2089 echo "waiting for $host to fail attempts=$attempts"
2090 [ $i -lt $attempts ] || \
2091 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2097 local mnt=${2:-$MOUNT}
2100 if [ "$FAILURE_MODE" = HARD ]; then
2101 shutdown_node_hard $client
2103 zconf_umount_clients $client $mnt -f
2109 local facets="$(get_facets OST),$(get_facets MDS)"
2112 combined_mgs_mds || facets="$facets,mgs"
2114 for facet in ${facets//,/ }; do
2115 if [ $(facet_active_host $facet) == $host ]; then
2116 affected="$affected $facet"
2120 echo $(comma_list $affected)
2125 local host=${2:-$(facet_host $facet)}
2127 local label=$(convert_facet2label $facet)
2128 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2131 facets_up_on_host () {
2133 local facets=$(facets_on_host $host)
2136 for facet in ${facets//,/ }; do
2137 if $(facet_up $facet $host); then
2138 affected_up="$affected_up $facet"
2142 echo $(comma_list $affected_up)
2148 if [ "$FAILURE_MODE" = HARD ]; then
2149 shutdown_node_hard $(facet_active_host $facet)
2157 echo + $POWER_UP $node
2170 if [ "$FAILURE_MODE" = HARD ]; then
2171 reboot_node $(facet_active_host $facet)
2179 if [ "$FAILURE_MODE" = HARD ]; then
2189 for facet in ${facets//,/ }; do
2190 hosts=$(expand_list $hosts $(facet_host $facet) )
2196 _check_progs_installed () {
2200 for prog in $progs; do
2201 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2202 echo $prog missing on $(hostname)
2209 check_progs_installed () {
2213 do_rpc_nodes "$nodes" _check_progs_installed $@
2216 # recovery-scale functions
2218 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2221 start_client_load() {
2224 local var=$(node_var_name $client)_load
2225 eval export ${var}=$load
2227 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2228 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2229 END_RUN_FILE=$END_RUN_FILE \
2230 LOAD_PID_FILE=$LOAD_PID_FILE \
2231 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2232 TESTNAME=$TESTNAME \
2233 DBENCH_LIB=$DBENCH_LIB \
2234 DBENCH_SRC=$DBENCH_SRC \
2235 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2241 log "Started client load: ${load} on $client"
2243 # get the children process IDs
2244 local pids=$(ps --ppid $ppid -o pid= | xargs)
2245 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2249 start_client_loads () {
2250 local -a clients=(${1//,/ })
2251 local numloads=${#CLIENT_LOADS[@]}
2254 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2255 testnum=$((nodenum % numloads))
2256 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2258 # bug 22169: wait the background threads to start
2262 # only for remote client
2263 check_client_load () {
2265 local var=$(node_var_name $client)_load
2266 local testload=run_${!var}.sh
2268 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2270 # bug 18914: try to connect several times not only when
2271 # check ps, but while check_node_health also
2275 while [ $RC = 254 -a $tries -gt 0 ]; do
2279 if ! check_node_health $client; then
2281 if [ $RC -eq 254 ]; then
2282 # FIXME: not sure how long we shuold sleep here
2286 echo "check node health failed: RC=$RC "
2290 # We can continue try to connect if RC=254
2291 # Just print the warning about this
2292 if [ $RC = 254 ]; then
2293 echo "got a return status of $RC from do_node while checking " \
2294 "node health on $client"
2297 # see if the load is still on the client
2300 while [ $RC = 254 -a $tries -gt 0 ]; do
2304 if ! do_node $client \
2305 "ps auxwww | grep -v grep | grep -q $testload"; then
2310 if [ $RC = 254 ]; then
2311 echo "got a return status of $RC from do_node while checking " \
2312 "(node health and 'ps') the client load on $client"
2313 # see if we can diagnose a bit why this is
2318 check_client_loads () {
2319 local clients=${1//,/ }
2323 for client in $clients; do
2324 check_client_load $client
2326 if [ "$rc" != 0 ]; then
2327 log "Client load failed on node $client, rc=$rc"
2333 restart_client_loads () {
2334 local clients=${1//,/ }
2335 local expectedfail=${2:-""}
2339 for client in $clients; do
2340 check_client_load $client
2342 if [ "$rc" != 0 -a "$expectedfail" ]; then
2343 local var=$(node_var_name $client)_load
2344 start_client_load $client ${!var}
2345 echo "Restarted client load ${!var}: on $client. Checking ..."
2346 check_client_load $client
2348 if [ "$rc" != 0 ]; then
2349 log "Client load failed to restart on node $client, rc=$rc"
2350 # failure one client load means test fail
2351 # we do not need to check other
2360 # Start vmstat and save its process ID in a file.
2365 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2368 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2369 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2372 # Display the nodes on which client loads failed.
2373 print_end_run_file() {
2377 [ -s $file ] || return 0
2379 echo "Found the END_RUN_FILE file: $file"
2382 # A client load will stop if it finds the END_RUN_FILE file.
2383 # That does not mean the client load actually failed though.
2384 # The first node in END_RUN_FILE is the one we are interested in.
2387 if [ -n "$node" ]; then
2388 local var=$(node_var_name $node)_load
2390 local prefix=$TESTLOG_PREFIX
2391 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2392 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2393 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2395 echo "Client load ${!var} failed on node $node:"
2401 # Stop the process which had its PID saved in a file.
2406 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2408 do_nodes $nodes "test -f $pid_file &&
2409 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2412 # Stop all client loads.
2413 stop_client_loads() {
2414 local nodes=${1:-$CLIENTS}
2417 # stop the client loads
2418 stop_process $nodes $pid_file
2420 # clean up the processes that started them
2421 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2423 # End recovery-scale functions
2425 # verify that lustre actually cleaned up properly
2427 VAR=$(lctl get_param -n catastrophe 2>&1)
2428 if [ $? = 0 ] ; then
2429 if [ $VAR != 0 ]; then
2430 error "LBUG/LASSERT detected"
2433 BUSY=$(dmesg | grep -i destruct || true)
2434 if [ -n "$BUSY" ]; then
2436 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2440 check_mem_leak || exit 204
2442 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2443 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2446 if module_loaded lnet || module_loaded libcfs; then
2447 echo "$TESTSUITE: modules still loaded..." 1>&2
2456 if [[ "$1" == "--verbose" ]]; then
2471 PREV_RESULT=$(do_node $node "$TEST")
2473 RESULT=$(do_node $node "$TEST")
2474 if [[ "$RESULT" == "$FINAL" ]]; then
2475 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2476 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2480 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2481 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2485 [[ $WAIT -ge $MAX ]] && break
2486 [[ $((WAIT % print)) -eq 0 ]] &&
2487 echo "Waiting $((MAX - WAIT)) secs for update"
2488 WAIT=$((WAIT + sleep))
2491 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2495 wait_update_facet() {
2497 [ "$1" = "--verbose" ] && verbose="$1" && shift
2501 wait_update $verbose $(facet_active_host $facet) "$@"
2505 do_nodes $(comma_list $(mdts_nodes)) \
2506 "lctl set_param -n osd*.*MDT*.force_sync=1"
2507 do_nodes $(comma_list $(osts_nodes)) \
2508 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2509 grep -v 'Found no match'
2513 # the occupied disk space will be released
2514 # only after DMUs are committed
2515 if [[ $(facet_fstype $1) == zfs ]]; then
2516 echo "sleep $2 for ZFS OSD"
2521 wait_delete_completed_mds() {
2522 local MAX_WAIT=${1:-20}
2523 # for ZFS, waiting more time for DMUs to be committed
2524 local ZFS_WAIT=${2:-5}
2526 local stime=$(date +%s)
2531 # find MDS with pending deletions
2532 for node in $(mdts_nodes); do
2533 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2534 2>/dev/null | calc_sum)
2535 if [[ $changes -eq 0 ]]; then
2538 mds2sync="$mds2sync $node"
2540 if [ -z "$mds2sync" ]; then
2541 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2544 mds2sync=$(comma_list $mds2sync)
2546 # sync MDS transactions
2547 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2549 # wait till all changes are sent and commmitted by OSTs
2550 # for ldiskfs space is released upon execution, but DMU
2551 # do this upon commit
2554 while [[ $WAIT -ne $MAX_WAIT ]]; do
2555 changes=$(do_nodes $mds2sync \
2556 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2557 #echo "$node: $changes changes on all"
2558 if [[ $changes -eq 0 ]]; then
2559 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2567 echo "Delete is not completed in $((etime - stime)) seconds"
2568 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2574 # we can use "for" here because we are waiting the slowest
2575 for host in ${hostlist//,/ }; do
2576 check_network "$host" 900
2578 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2585 for facet in ${facetlist//,/ }; do
2586 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2588 wait_for_host $hostlist
2591 _wait_recovery_complete () {
2594 # Use default policy if $2 is not passed by caller.
2595 local MAX=${2:-$(max_recovery_time)}
2600 while [ $WAIT -lt $MAX ]; do
2601 STATUS=$(lctl get_param -n $param | grep status)
2603 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2606 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2608 echo "$param recovery not done in $MAX sec. $STATUS"
2612 wait_recovery_complete () {
2615 # with an assumption that at_max is the same on all nodes
2616 local MAX=${2:-$(max_recovery_time)}
2619 if [ "$FAILURE_MODE" = HARD ]; then
2620 facets=$(facets_on_host $(facet_active_host $facet))
2622 echo affected facets: $facets
2624 # we can use "for" here because we are waiting the slowest
2625 for facet in ${facets//,/ }; do
2626 local var_svc=${facet}_svc
2627 local param="*.${!var_svc}.recovery_status"
2629 local host=$(facet_active_host $facet)
2630 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2634 wait_mds_ost_sync () {
2635 # just because recovery is done doesn't mean we've finished
2636 # orphan cleanup. Wait for llogs to get synchronized.
2637 echo "Waiting for orphan cleanup..."
2638 # MAX value includes time needed for MDS-OST reconnection
2639 local MAX=$(( TIMEOUT * 2 ))
2640 local WAIT_TIMEOUT=${1:-$MAX}
2643 local list=$(comma_list $(mdts_nodes))
2644 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2645 if ! do_facet $SINGLEMDS \
2646 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2648 # old way, use mds_sync
2650 list=$(comma_list $(osts_nodes))
2651 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2654 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2655 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2656 local -a sync=($(do_nodes $list "$cmd"))
2659 for ((i=0; i<${#sync[@]}; i++)); do
2661 [ ${sync[$i]} -eq 1 ] && continue
2663 [ ${sync[$i]} -eq 0 ] && continue
2665 # there is a not finished MDS-OST synchronization
2669 sleep 2 # increase waiting time and cover statfs cache
2670 [ ${con} -eq 1 ] && return 0
2671 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2675 # show which nodes are not finished.
2676 do_nodes $list "$cmd"
2677 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2681 # Wait OSTs to be active on both client and MDT side.
2683 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2684 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2685 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2686 error "wait_update OSTs up on client failed"
2688 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
2689 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
2690 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2691 error "wait_update OSTs up on MDT0000 failed"
2694 wait_destroy_complete () {
2695 echo "Waiting for local destroys to complete"
2696 # MAX value shouldn't be big as this mean server responsiveness
2697 # never increase this just to make test pass but investigate
2698 # why it takes so long time
2701 while [ $WAIT -lt $MAX ]; do
2702 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2706 for ((i=0; i<${#RPCs[@]}; i++)); do
2707 [ ${RPCs[$i]} -eq 0 ] && continue
2708 # there are still some destroy RPCs in flight
2713 [ ${con} -eq 1 ] && return 0 # done waiting
2714 echo "Waiting ${WAIT}s for local destroys to complete"
2717 echo "Local destroys weren't done in $MAX sec."
2721 wait_delete_completed() {
2722 wait_delete_completed_mds $1 || return $?
2723 wait_destroy_complete
2732 # conf-sanity 31 takes a long time cleanup
2733 while [ $WAIT -lt 300 ]; do
2734 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2735 [ -z "${running}" ] && return 0
2736 echo "waited $WAIT for${running}"
2737 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2739 WAIT=$((WAIT + INTERVAL))
2741 echo "service didn't stop after $WAIT seconds. Still running:"
2746 wait_remote_prog () {
2752 [ "$PDSH" = "no_dsh" ] && return 0
2754 while [ $WAIT -lt $2 ]; do
2755 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2756 [ -z "${running}" ] && return 0 || true
2757 echo "waited $WAIT for: "
2759 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2761 WAIT=$((WAIT + INTERVAL))
2763 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2764 [ -z "$pids" ] && return 0
2765 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2766 # FIXME: not portable
2767 for pid in $pids; do
2768 cat /proc/${pid}/status || true
2769 cat /proc/${pid}/wchan || true
2771 kill -9 $pid || true
2780 local clients=${1:-$CLIENTS}
2782 if [ -z "$clients" ]; then
2785 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2790 # not every config has many clients
2796 # usually checked on particular client or locally
2805 client_reconnect_try() {
2806 local f=$MOUNT/recon
2809 if [ -z "$CLIENTS" ]; then
2810 $LFS df $MOUNT; uname -n >> $f
2812 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2814 echo "Connected clients: $(cat $f)"
2815 ls -l $f > /dev/null
2819 client_reconnect() {
2820 # one client_reconnect_try call does not always do the job...
2822 client_reconnect_try && break
2827 affected_facets () {
2830 local host=$(facet_active_host $facet)
2831 local affected=$facet
2833 if [ "$FAILURE_MODE" = HARD ]; then
2834 affected=$(facets_up_on_host $host)
2840 local E2FSCK_ON_MDT0=false
2841 if [ "$1" == "--fsck" ]; then
2843 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2855 #Because it will only get up facets, we need get affected
2856 #facets before shutdown
2857 #For HARD Failure mode, it needs make sure facets on the same
2858 #HOST will only be shutdown and reboot once
2859 for facet in ${facets//,/ }; do
2860 local affected_facet
2862 #check whether facet has been included in other affected facets
2863 for ((index=0; index<$total; index++)); do
2864 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2867 if [ $skip -eq 0 ]; then
2868 affecteds[$total]=$(affected_facets $facet)
2873 for ((index=0; index<$total; index++)); do
2874 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2875 local host=$(facet_active_host $facet)
2876 echo "Failing ${affecteds[index]} on $host"
2877 shutdown_facet $facet
2880 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2881 $(mdsdevname 1) "-n" || error "Running e2fsck")
2883 for ((index=0; index<$total; index++)); do
2884 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2885 echo reboot facets: ${affecteds[index]}
2889 change_active ${affecteds[index]}
2891 wait_for_facet ${affecteds[index]}
2892 # start mgs first if it is affected
2893 if ! combined_mgs_mds &&
2894 list_member ${affecteds[index]} mgs; then
2895 mount_facet mgs || error "Restart of mgs failed"
2897 # FIXME; has to be changed to mount all facets concurrently
2898 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2899 echo mount facets: ${affecteds[index]}
2900 mount_facets ${affecteds[index]}
2910 do_facet $facet "sync; sync; sync"
2913 # make sure there will be no seq change
2914 local clients=${CLIENTS:-$HOSTNAME}
2915 local f=fsa-\\\$\(hostname\)
2916 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2917 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2919 local svc=${facet}_svc
2920 do_facet $facet $LCTL --device ${!svc} notransno
2922 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2923 # in-memory state has to be cleared by either rebooting the host or
2924 # exporting and reimporting the pool.
2926 # Although the uberblocks are not updated when a pool is freezed,
2927 # transactions are still written to the disks. Modified blocks may be
2928 # cached in memory when tests try reading them back. The
2929 # export-and-reimport process also evicts any cached pool data from
2930 # memory to provide the correct "data loss" semantics.
2932 # In the test framework, the exporting and importing operations are
2933 # handled by stop() and mount_facet() separately, which are used
2934 # inside fail() and fail_abort().
2936 do_facet $facet $LCTL --device ${!svc} readonly
2937 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2938 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2941 replay_barrier_nodf() {
2942 local facet=$1 echo running=${running}
2943 do_facet $facet "sync; sync; sync"
2944 local svc=${facet}_svc
2945 echo Replay barrier on ${!svc}
2946 do_facet $facet $LCTL --device ${!svc} notransno
2947 do_facet $facet $LCTL --device ${!svc} readonly
2948 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2949 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2952 replay_barrier_nosync() {
2953 local facet=$1 echo running=${running}
2954 local svc=${facet}_svc
2955 echo Replay barrier on ${!svc}
2956 do_facet $facet $LCTL --device ${!svc} notransno
2957 do_facet $facet $LCTL --device ${!svc} readonly
2958 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2959 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2963 # Get Lustre client uuid for a given Lustre mount point.
2966 local mntpnt=${1:-$MOUNT}
2968 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2969 local uuid=$($LCTL get_param -n llite.$name.uuid)
2974 mds_evict_client() {
2975 local mntpnt=${1:-$MOUNT}
2976 local uuid=$(get_client_uuid $mntpnt)
2978 do_facet $SINGLEMDS \
2979 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2982 ost_evict_client() {
2983 local mntpnt=${1:-$MOUNT}
2984 local uuid=$(get_client_uuid $mntpnt)
2987 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2992 local clients=${CLIENTS:-$HOSTNAME}
2994 facet_failover $* || error "failover: $?"
2995 wait_clients_import_state "$clients" "$facets" FULL
2996 clients_up || error "post-failover stat: $?"
3001 facet_failover $facet
3007 change_active $facet
3008 wait_for_facet $facet
3009 mount_facet $facet -o abort_recovery
3010 clients_up || echo "first stat failed: $?"
3011 clients_up || error "post-failover stat: $?"
3014 host_nids_address() {
3018 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
3022 if [ "$1" = "'*'" ]; then echo \'*\'; else
3028 if [[ -n "$NETTYPE" ]]; then
3029 h2name_or_ip "$1" "$NETTYPE"
3031 h2name_or_ip "$1" "$2"
3034 declare -fx h2nettype
3036 # Wrapper function to print the deprecation warning
3038 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3039 if [[ -n "$NETTYPE" ]]; then
3042 h2nettype "$1" "tcp"
3046 # Wrapper function to print the deprecation warning
3048 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3049 if [[ -n "$NETTYPE" ]]; then
3052 h2nettype "$1" "o2ib"
3056 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3057 # expressions format. As a bonus we can then just pass in those variables
3058 # to pdsh. What this function does is take a HOSTLIST type string and
3059 # expand it into a space deliminated list for us.
3067 [ -z "$hostlist" ] && return
3069 # Translate the case of [..],..,[..] to [..] .. [..]
3070 list="${hostlist/],/] }"
3072 [[ "$front" == *,* ]] && {
3075 list=${list/${old}/${new}}
3078 for item in $list; do
3079 # Test if we have any []'s at all
3080 if [ "$item" != "${item/\[/}" ]; then {
3081 # Expand the [*] into list
3085 if [ "$name" != "$item" ]; then
3086 group=${item#$name[*}
3089 for range in ${group//,/ }; do
3095 # Number of leading zeros
3098 end=$(echo $end | sed 's/0*//')
3099 [[ -z "$end" ]] && end=0
3100 [[ $padlen2 -gt $padlen ]] && {
3101 [[ $padlen2 -eq ${#end} ]] && padlen2=0
3104 begin=$(echo $begin | sed 's/0*//')
3105 [ -z $begin ] && begin=0
3107 if [ ! -z "${begin##[!0-9]*}" ]; then
3108 order=$(seq -f "%0${padlen}g" $begin $end)
3110 order=$(eval echo {$begin..$end});
3113 for num in $order; do
3114 value="${name#*,}${num}${back}"
3115 [ "$value" != "${value/\[/}" ] && {
3116 value=$(hostlist_expand "$value")
3118 myList="$myList $value"
3123 myList="$myList $item"
3126 myList=${myList//,/ }
3127 myList=${myList:1} # Remove first character which is a space
3129 # Filter any duplicates without sorting
3131 myList="${list%% *}"
3133 while [[ "$list" != ${myList##* } ]]; do
3134 local tlist=" $list"
3135 list=${tlist// ${list%% *} / }
3137 myList="$myList ${list%% *}"
3139 myList="${myList%* }";
3141 # We can select an object at an offset in the list
3144 for item in $myList; do
3146 [ $cnt -eq $offset ] && {
3150 [ $(get_node_count $myList) -ne 1 ] && myList=""
3159 [ "$facet" == client ] && echo -n $HOSTNAME && return
3160 varname=${facet}_HOST
3161 if [ -z "${!varname}" ]; then
3162 if [ "${facet:0:3}" == "ost" ]; then
3163 local fh=${facet%failover}_HOST
3164 eval export ${facet}_HOST=${!fh}
3165 if [ -z "${!varname}" ]; then
3166 eval export ${facet}_HOST=${ost_HOST}
3168 elif [ "${facet:0:3}" == "mdt" -o \
3169 "${facet:0:3}" == "mds" -o \
3170 "${facet:0:3}" == "mgs" ]; then
3171 eval export ${facet}_HOST=${mds_HOST}
3177 facet_failover_host() {
3181 var=${facet}failover_HOST
3182 if [ -n "${!var}" ]; then
3187 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
3188 "${facet:0:3}" == "mgs" ]; then
3190 eval export ${facet}failover_host=${mds_HOST}
3195 if [[ $facet == ost* ]]; then
3196 eval export ${facet}failover_host=${ost_HOST}
3204 local activevar=${facet}active
3206 if [ -f $TMP/${facet}active ] ; then
3207 source $TMP/${facet}active
3210 active=${!activevar}
3211 if [ -z "$active" ] ; then
3218 facet_active_host() {
3219 facet_host $(facet_active $1)
3222 # Get the passive failover partner host of facet.
3223 facet_passive_host() {
3225 [[ $facet = client ]] && return
3227 local host=${facet}_HOST
3228 local failover_host=${facet}failover_HOST
3229 local active_host=$(facet_active_host $facet)
3231 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
3233 if [[ $active_host = ${!host} ]]; then
3234 echo -n ${!failover_host}
3244 facetlist=$(exclude_items_from_list $facetlist mgs)
3246 for facet in ${facetlist//,/ }; do
3247 local failover=${facet}failover
3248 local host=`facet_host $failover`
3249 [ -z "$host" ] && return
3251 local curactive=`facet_active $facet`
3252 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3253 eval export ${facet}active=$facet
3255 eval export ${facet}active=$failover
3257 # save the active host for this facet
3258 local activevar=${facet}active
3259 echo "$activevar=${!activevar}" > $TMP/$activevar
3260 [[ $facet = mds1 ]] && combined_mgs_mds && \
3261 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3262 local TO=`facet_active_host $facet`
3263 echo "Failover $facet to $TO"
3269 # do not stripe off hostname if verbose, bug 19215
3270 if [ x$1 = x--verbose ]; then
3278 if [ "$HOST" = "$HOSTNAME" ]; then
3280 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3281 echo "cannot run remote command on $HOST with $myPDSH"
3285 echo "CMD: $HOST $@" >&2
3286 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3289 if [ "$myPDSH" = "rsh" ]; then
3290 # we need this because rsh does not return exit code of an executed command
3291 local command_status="$TMP/cs"
3292 rsh $HOST ":> $command_status"
3293 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3294 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3295 echo command failed >$command_status"
3296 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true