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}
157 export CLEANUP_DM_DEV=false
159 export MKE2FS=$MKE2FS
160 if [ -z "$MKE2FS" ]; then
161 if which mkfs.ldiskfs >/dev/null 2>&1; then
162 export MKE2FS=mkfs.ldiskfs
168 export DEBUGFS=$DEBUGFS
169 if [ -z "$DEBUGFS" ]; then
170 if which debugfs.ldiskfs >/dev/null 2>&1; then
171 export DEBUGFS=debugfs.ldiskfs
173 export DEBUGFS=debugfs
177 export TUNE2FS=$TUNE2FS
178 if [ -z "$TUNE2FS" ]; then
179 if which tunefs.ldiskfs >/dev/null 2>&1; then
180 export TUNE2FS=tunefs.ldiskfs
182 export TUNE2FS=tune2fs
186 export E2LABEL=$E2LABEL
187 if [ -z "$E2LABEL" ]; then
188 if which label.ldiskfs >/dev/null 2>&1; then
189 export E2LABEL=label.ldiskfs
191 export E2LABEL=e2label
195 export DUMPE2FS=$DUMPE2FS
196 if [ -z "$DUMPE2FS" ]; then
197 if which dumpfs.ldiskfs >/dev/null 2>&1; then
198 export DUMPE2FS=dumpfs.ldiskfs
200 export DUMPE2FS=dumpe2fs
204 export E2FSCK=$E2FSCK
205 if [ -z "$E2FSCK" ]; then
206 if which fsck.ldiskfs >/dev/null 2>&1; then
207 export E2FSCK=fsck.ldiskfs
213 export RESIZE2FS=$RESIZE2FS
214 if [ -z "$RESIZE2FS" ]; then
215 if which resizefs.ldiskfs >/dev/null 2>&1; then
216 export RESIZE2FS=resizefs.ldiskfs
218 export RESIZE2FS=resize2fs
222 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
223 export FSCK_MAX_ERR=4 # File system errors left uncorrected
225 export ZFS=${ZFS:-zfs}
226 export ZPOOL=${ZPOOL:-zpool}
227 export ZDB=${ZDB:-zdb}
228 export PARTPROBE=${PARTPROBE:-partprobe}
230 #[ -d /r ] && export ROOT=${ROOT:-/r}
231 export TMP=${TMP:-$ROOT/tmp}
232 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
233 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
234 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
236 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
237 if ! echo $PATH | grep -q $LUSTRE/utils; then
238 export PATH=$LUSTRE/utils:$PATH
240 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
241 export PATH=$LUSTRE/utils/gss:$PATH
243 if ! echo $PATH | grep -q $LUSTRE/tests; then
244 export PATH=$LUSTRE/tests:$PATH
246 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
247 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
249 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
250 [ ! -f "$LST" ] && export LST=$(which lst)
251 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
252 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
253 export MCREATE=${MCREATE:-mcreate}
254 export MULTIOP=${MULTIOP:-multiop}
255 # Ubuntu, at least, has a truncate command in /usr/bin
256 # so fully path our truncate command.
257 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
258 export FSX=${FSX:-$LUSTRE/tests/fsx}
259 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
260 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
261 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
262 export PATH=$LUSTRE/tests/racer:$PATH:
264 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
265 export PATH=$LUSTRE/tests/mpi:$PATH
267 export RSYNC_RSH=${RSYNC_RSH:-rsh}
269 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
270 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
271 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
272 [ ! -f "$LFS" ] && export LFS=$(which lfs)
273 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
274 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
276 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
277 if [ ! -f "$L_GETIDENTITY" ]; then
278 if `which l_getidentity > /dev/null 2>&1`; then
279 export L_GETIDENTITY=$(which l_getidentity)
281 export L_GETIDENTITY=NONE
284 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
285 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
286 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
287 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
288 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
289 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
290 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
291 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
292 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
293 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
294 [ ! -f "$LUSTRE_RMMOD" ] &&
295 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
296 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
297 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
298 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
299 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
300 [ ! -f "$LFS_MIGRATE" ] &&
301 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
302 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
303 [ ! -f "$LR_READER" ] &&
304 export LR_READER=$(which lr_reader 2> /dev/null)
305 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
306 export NAME=${NAME:-local}
307 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
308 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
309 export LGSSD=$(which lgssd)
310 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
311 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
312 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
314 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
316 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
317 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
319 export DMSETUP=${DMSETUP:-dmsetup}
320 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
321 export LOSETUP=${LOSETUP:-losetup}
323 if [ "$ACCEPTOR_PORT" ]; then
324 export PORT_OPT="--port $ACCEPTOR_PORT"
328 $RPC_MODE || echo "Using GSS shared-key feature"
329 which lgss_sk > /dev/null 2>&1 ||
330 error_exit "built with lgss_sk disabled! SEC=$SEC"
338 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
339 which lgss_keyring > /dev/null 2>&1 ||
340 error_exit "built with gss disabled! SEC=$SEC"
351 IDENTITY_UPCALL=false
355 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
357 # Paths on remote nodes, if different
358 export RLUSTRE=${RLUSTRE:-$LUSTRE}
359 export RPWD=${RPWD:-$PWD}
360 export I_MOUNTED=${I_MOUNTED:-"no"}
361 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
362 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
363 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
364 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
365 ! -f $LUSTRE/mdt/mdt.ko ]; then
366 export CLIENTMODSONLY=yes
369 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
370 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
374 while getopts "rvwf:" opt $*; do
379 w) WRITECONF=writeconf;;
384 shift $((OPTIND - 1))
387 # print the durations of each test if "true"
388 DDETAILS=${DDETAILS:-false}
389 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
394 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
401 ncpts=$(do_facet $facet "lctl get_param -n " \
402 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
404 if [ $ncpts -eq 0 ]; then
411 # Return a numeric version code based on a version string. The version
412 # code is useful for comparison two version strings to see which is newer.
414 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
415 eval set -- $(tr "[:punct:]" " " <<< $*)
417 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
420 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
421 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
423 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
425 # usage: lustre_build_version
427 # All Lustre versions support "lctl get_param" to report the version of the
428 # code running in the kernel (what our tests are interested in), but it
429 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
430 # the "version" parameter doesn't include "lustre: " at the beginning.
431 # If that fails, call "lctl lustre_build_version" which prints either (or both)
432 # the userspace and kernel build versions, but until 2.8.55 required root
433 # access to get the Lustre kernel version. If that also fails, fall back to
434 # using "lctl --version", which is easy to parse and works without the kernel
435 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
436 # not the module version, though they are usually the same.
438 # Various commands and their output format for different Lustre versions:
439 # lctl get_param version: 2.9.55
440 # lctl get_param version: lustre: 2.8.53
441 # lctl get_param version: lustre: 2.6.52
442 # kernel: patchless_client
443 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
444 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
445 # lctl lustre_build_version: error: lustre_build_version: Permission denied
446 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
447 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
448 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
449 # lctl --version: lctl 2.6.50
451 # output: prints version string to stdout in (up to 4) dotted-decimal values
452 lustre_build_version() {
453 local facet=${1:-client}
454 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
455 $LCTL lustre_build_version 2>/dev/null ||
456 $LCTL --version 2>/dev/null | cut -d' ' -f2")
457 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
458 [ -n "$lver" ] && ver="$lver"
460 sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' -e 's/_/./g' <<<$ver |
464 # Report the Lustre numeric build version code for the supplied facet.
465 lustre_version_code() {
466 version_code $(lustre_build_version $1)
470 /sbin/lsmod | grep -q "^\<$1\>"
482 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
485 # parallels can't load modules directly from prlfs, use /tmp instead
486 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
487 local target="$(mktemp)"
489 cp "$module" "$target"
492 [[ $rc == 0 ]] && PRLFS=true
500 # Load a module on the system where this is running.
502 # usage: load_module module_name [module arguments for insmod/modprobe]
504 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
505 # will be used as the arguments. Otherwise arguments will be obtained from
506 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
513 BASE=$(basename $module $EXT)
515 module_loaded ${BASE} && return
517 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
518 # else from modprobe.conf
519 if [ $# -eq 0 ]; then
520 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
521 # Bash until 4.x, so we resort to eval.
522 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
523 eval set -- \$$optvar
524 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
525 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
527 opt=$(awk -v var="^options $BASE" '$0 ~ var \
528 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
529 set -- $(echo -n $opt)
531 # Ensure we have accept=all for lnet
532 if [ $(basename $module) = lnet ]; then
533 # OK, this is a bit wordy...
534 local arg accept_all_present=false
537 [ "$arg" = accept=all ] && \
538 accept_all_present=true
540 $accept_all_present || set -- "$@" accept=all
546 [ $# -gt 0 ] && echo "${module} options: '$*'"
548 # Note that insmod will ignore anything in modprobe.conf, which is why
549 # we're passing options on the command-line.
550 if [[ "$BASE" == "lnet_selftest" ]] &&
551 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
552 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
553 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
554 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
555 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
557 # must be testing a "make install" or "rpm" installation
558 # note failed to load ptlrpc_gss is considered not fatal
559 if [[ "$BASE" == "ptlrpc_gss" ]]; then
560 modprobe $BASE "$@" 2>/dev/null ||
561 echo "gss/krb5 is not supported"
568 load_modules_local() {
569 if [ -n "$MODPROBE" ]; then
571 echo "Using modprobe to load modules"
575 echo Loading modules from $LUSTRE
579 if [ -f /sys/devices/system/cpu/online ]; then
580 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
581 echo "detected $ncpus online CPUs by sysfs"
583 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
585 if [ $rc -eq 0 ]; then
586 echo "detected $ncpus online CPUs by getconf"
588 echo "Can't detect number of CPUs"
593 # if there is only one CPU core, libcfs can only create one partition
594 # if there is more than 4 CPU cores, libcfs should create multiple CPU
595 # partitions. So we just force libcfs to create 2 partitions for
596 # system with 2 or 4 cores
597 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
598 # force to enable multiple CPU partitions
599 echo "Force libcfs to create 2 CPU partitions"
600 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
602 echo "libcfs will create CPU partition based on online CPUs"
605 load_module ../libcfs/libcfs/libcfs
606 # Prevent local MODOPTS_LIBCFS being passed as part of environment
607 # variable to remote nodes
611 load_module ../lnet/lnet/lnet
613 LNDPATH=${LNDPATH:-"../lnet/klnds"}
614 if [ -z "$LNETLND" ]; then
616 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
617 tcp*) LNETLND="socklnd/ksocklnd" ;;
618 *) local lnd="${NETTYPE%%[0-9]}lnd"
619 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
620 LNETLND="$lnd/k$lnd" ||
621 LNETLND="socklnd/ksocklnd"
624 load_module ../lnet/klnds/$LNETLND
625 load_module obdclass/obdclass
626 load_module ptlrpc/ptlrpc
627 load_module ptlrpc/gss/ptlrpc_gss
635 load_module obdecho/obdecho
636 if ! client_only; then
637 SYMLIST=/proc/kallsyms
638 grep -q crc16 $SYMLIST ||
639 { modprobe crc16 2>/dev/null || true; }
640 grep -q -w jbd2 $SYMLIST ||
641 { modprobe jbd2 2>/dev/null || true; }
642 load_module lfsck/lfsck
643 [ "$LQUOTA" != "no" ] &&
644 load_module quota/lquota $LQUOTAOPTS
645 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
646 lsmod | grep zfs >&/dev/null || modprobe zfs
647 load_module osd-zfs/osd_zfs
649 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
650 grep -q exportfs_decode_fh $SYMLIST ||
651 { modprobe exportfs 2> /dev/null || true; }
652 grep -q -w mbcache $SYMLIST ||
653 { modprobe mbcache 2>/dev/null || true; }
654 load_module ../ldiskfs/ldiskfs
655 load_module osd-ldiskfs/osd_ldiskfs
667 load_module llite/lustre
668 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
670 rm -f $OGDB/ogdb-$HOSTNAME
671 $LCTL modules > $OGDB/ogdb-$HOSTNAME
673 # 'mount' doesn't look in $PATH, just sbin
674 local mount_lustre=$LUSTRE/utils/mount.lustre
675 if [ -f $mount_lustre ]; then
676 local sbin_mount=$(readlink -f /sbin)/mount.lustre
677 if grep -qw "$sbin_mount" /proc/mounts; then
678 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
680 if ! grep -qw "$sbin_mount" /proc/mounts; then
681 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
682 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
683 cat <<- EOF > "$sbin_mount"
686 echo "This $sbin_mount just a mountpoint." 1>&2
687 echo "It is never supposed to be run." 1>&2
688 logger -p emerg -- "using stub $sbin_mount $@"
691 chmod a+x $sbin_mount
693 mount --bind $mount_lustre $sbin_mount ||
694 error "can't bind $mount_lustre to $sbin_mount"
702 # load modules on remote nodes optionally
703 # lustre-tests have to be installed on these nodes
704 if $LOAD_MODULES_REMOTE; then
705 local list=$(comma_list $(remote_nodes_list))
706 if [ -n "$list" ]; then
707 echo "loading modules on: '$list'"
708 do_rpc_nodes "$list" load_modules_local
714 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
715 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
716 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
717 echo "$LEAK_LUSTRE" 1>&2
718 echo "$LEAK_PORTALS" 1>&2
719 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
720 echo "Memory leaks detected"
721 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
727 wait_exit_ST client # bug 12845
729 $LUSTRE_RMMOD ldiskfs || return 2
731 if $LOAD_MODULES_REMOTE; then
732 local list=$(comma_list $(remote_nodes_list))
733 if [ -n "$list" ]; then
734 echo "unloading modules on: '$list'"
735 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
736 do_rpc_nodes "$list" check_mem_leak
740 local sbin_mount=$(readlink -f /sbin)/mount.lustre
741 if grep -qe "$sbin_mount " /proc/mounts; then
742 umount $sbin_mount || true
743 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
747 check_mem_leak || return 254
749 echo "modules unloaded."
754 local facet=${1:-$SINGLEMDS}
757 case $(facet_fstype $facet) in
758 ldiskfs) size=50;; # largest seen is 44, leave some headroom
759 # grant_block_size is in bytes, allow at least 2x max blocksize
760 zfs) size=$(lctl get_param osc.$FSNAME*.import |
761 awk '/grant_block_size:/ {print $2/512; exit;}')
769 local facet=${1:-$SINGLEMDS}
770 local fstype=$(facet_fstype $facet)
773 ldiskfs) size=4;; # ~4KB per inode
774 zfs) size=11;; # 10 to 11KB per inode
780 check_gss_daemon_nodes() {
784 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
785 if [ \\\"\\\$num\\\" -ne 1 ]; then
786 echo \\\$num instance of $dname;
791 check_gss_daemon_facet() {
795 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
796 if [ $num -ne 1 ]; then
797 echo "$num instance of $dname on $facet"
806 echo Stopping $@ on $list
807 do_nodes $list "killall -2 $@ 2>/dev/null || true"
810 # start gss daemons on all nodes, or "daemon" on "nodes" if set
811 start_gss_daemons() {
815 if [ "$nodes" ] && [ "$daemon" ] ; then
816 echo "Starting gss daemon on nodes: $nodes"
817 do_nodes $nodes "$daemon" || return 8
821 nodes=$(comma_list $(mdts_nodes))
822 echo "Starting gss daemon on mds: $nodes"
824 # Start all versions, in case of switching
825 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
827 do_nodes $nodes "$LSVCGSSD -v" || return 1
830 do_nodes $nodes "$LGSSD -v" || return 2
833 nodes=$(comma_list $(osts_nodes))
834 echo "Starting gss daemon on ost: $nodes"
836 # Start all versions, in case of switching
837 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
839 do_nodes $nodes "$LSVCGSSD -v" || return 3
841 # starting on clients
843 local clients=${CLIENTS:-$HOSTNAME}
845 echo "Starting $LGSSD on clients $clients "
846 do_nodes $clients "$LGSSD -v" || return 4
849 # wait daemons entering "stable" status
853 # check daemons are running
855 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
856 check_gss_daemon_nodes $nodes lsvcgssd || return 5
858 nodes=$(comma_list $(mdts_nodes))
859 check_gss_daemon_nodes $nodes lgssd || return 6
862 check_gss_daemon_nodes $clients lgssd || return 7
867 local nodes=$(comma_list $(mdts_nodes))
869 send_sigint $nodes lsvcgssd lgssd
871 nodes=$(comma_list $(osts_nodes))
872 send_sigint $nodes lsvcgssd
874 nodes=${CLIENTS:-$HOSTNAME}
875 send_sigint $nodes lgssd
879 # Add mount flags for shared key
881 if grep -q skpath <<< "$mt_opts" ; then
882 mt_opts=$(echo $mt_opts |
883 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
885 if [ -z "$mt_opts" ]; then
886 mt_opts="-o skpath=$SK_PATH"
888 mt_opts="$mt_opts,skpath=$SK_PATH"
904 if ! module_loaded ptlrpc_gss; then
905 load_module ptlrpc/gss/ptlrpc_gss
906 module_loaded ptlrpc_gss ||
907 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
910 if $GSS_KRB5 || $GSS_SK; then
911 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
914 if $GSS_SK && $SK_NO_KEY; then
915 local numclients=${1:-$CLIENTCOUNT}
916 local clients=${CLIENTS:-$HOSTNAME}
918 # security ctx config for keyring
921 mount -o bind $SK_OM_PATH /etc/request-key.d/
922 local lgssc_conf_line='create lgssc * * '
923 lgssc_conf_line+=$(which lgss_keyring)
924 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
926 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
927 echo "$lgssc_conf_line" > $lgssc_conf_file
928 [ -e $lgssc_conf_file ] ||
929 error_exit "Could not find key options in $lgssc_conf_file"
931 if ! local_mode; then
932 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
934 do_nodes $(comma_list $(all_nodes)) "mount \
935 -o bind $SK_OM_PATH \
937 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
938 $HOSTNAME:$lgssc_conf_file \
939 $lgssc_conf_file >/dev/null 2>&1"
942 # create shared key on all nodes
943 mkdir -p $SK_PATH/nodemap
944 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
945 $SK_PATH/$FSNAME-*.key
946 # for nodemap testing each client may need own key,
947 # and S2S now requires keys as well, both for "client"
950 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
951 -w $SK_PATH/$FSNAME-nmclient.key \
952 -d /dev/urandom >/dev/null 2>&1
953 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
954 -w $SK_PATH/$FSNAME-s2s-server.key \
955 -d /dev/urandom >/dev/null 2>&1
958 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
959 -d /dev/urandom >/dev/null 2>&1
961 for i in $(seq 0 $((numclients - 1))); do
962 lgss_sk -t server -f$FSNAME -n c$i \
963 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
967 if ! local_mode; then
968 do_nodes $(comma_list $(all_nodes)) "rsync -av \
969 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
971 # Set client keys to client type to generate prime P
973 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
974 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
976 do_nodes $clients "lgss_sk -t client -m \
977 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
978 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
979 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
981 # This is required for servers as well, if S2S in use
983 do_nodes $(comma_list $(mdts_nodes)) \
984 "cp $SK_PATH/$FSNAME-s2s-server.key \
985 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
986 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
988 do_nodes $(comma_list $(osts_nodes)) \
989 "cp $SK_PATH/$FSNAME-s2s-server.key \
990 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
991 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
993 do_nodes $clients "lgss_sk -t client \
994 -m $SK_PATH/$FSNAME-nmclient.key \
997 # mount options for servers and clients
998 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
999 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1000 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1001 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1005 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
1007 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1014 # maybe cleanup credential cache?
1021 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1022 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1023 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1027 $RPC_MODE || echo "Cleaning up Shared Key.."
1028 do_nodes $(comma_list $(all_nodes)) "rm -f \
1029 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1030 # Remove the mount and clean up the files we added to SK_PATH
1031 do_nodes $(comma_list $(all_nodes)) "umount \
1032 /etc/request-key.d/"
1033 do_nodes $(comma_list $(all_nodes)) "rm -f \
1034 $SK_OM_PATH/lgssc.conf"
1035 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1042 local var=${facet}_svc
1050 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1051 tr '[:lower:]' '[:upper:]'
1057 if [ $facet == mgs ] || [ $facet == client ]; then
1061 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1069 if [ -n "${!var}" ]; then
1074 var=$(facet_type $facet)FSTYPE
1075 if [ -n "${!var}" ]; then
1080 if [ -n "$FSTYPE" ]; then
1085 if [[ $facet == mgs ]] && combined_mgs_mds; then
1097 local facets=$(get_facets)
1100 for facet in ${facets//,/ }; do
1101 if [ $node == $(facet_host $facet) ] ||
1102 [ $node == "$(facet_failover_host $facet)" ]; then
1103 fstype=$(facet_fstype $facet)
1104 if [[ $fstypes != *$fstype* ]]; then
1105 fstypes+="${fstypes:+,}$fstype"
1114 local num=$(facet_number $facet)
1117 if [[ $(facet_type $facet) = OST ]]; then
1118 index=OSTINDEX${num}
1119 if [[ -n "${!index}" ]]; then
1124 index=${OST_INDICES[num - 1]}
1127 [[ -n "$index" ]] || index=$((num - 1))
1135 local fstype=$(facet_fstype $facet)
1139 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1141 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1142 ${dev} 2>/dev/null");;
1144 error "unknown fstype!";;
1152 local device=$(mdsdevname $num)
1153 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1159 local device=$(ostdevname $num)
1160 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1165 # Get the device of a facet.
1172 mgs) device=$(mgsdevname) ;;
1173 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1174 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1175 fs2mds) device=$(mdsdevname 1_2) ;;
1176 fs2ost) device=$(ostdevname 1_2) ;;
1177 fs3ost) device=$(ostdevname 2_2) ;;
1185 # Get the virtual device of a facet.
1192 mgs) device=$(mgsvdevname) ;;
1193 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1194 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1195 fs2mds) device=$(mdsvdevname 1_2) ;;
1196 fs2ost) device=$(ostvdevname 1_2) ;;
1197 fs3ost) device=$(ostvdevname 2_2) ;;
1205 local virt=$(virt-what 2> /dev/null)
1207 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1209 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1212 VMware|KVM|VirtualBox|Parallels)
1213 echo $virt | tr '[A-Z]' '[a-z]' ;;
1219 # Re-read the partition table on failover partner host.
1220 # After a ZFS storage pool is created on a shared device, the partition table
1221 # on the device may change. However, the operating system on the failover
1222 # host may not notice the change automatically. Without the up-to-date partition
1223 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1224 # relative to partition rather than disk beginnings.
1226 # This function performs partprobe on the failover host to make it re-read the
1229 refresh_partition_table() {
1234 host=$(facet_passive_host $facet)
1235 if [[ -n "$host" ]]; then
1236 do_node $host "$PARTPROBE $device"
1241 # Get ZFS storage pool name.
1248 device=$(facet_device $facet)
1249 # poolname is string before "/"
1250 poolname="${device%%/*}"
1257 # Get ZFS local fsname.
1259 zfs_local_fsname() {
1261 local lfsname=$(basename $(facet_device $facet))
1267 # Create ZFS storage pool.
1274 local opts=${@:-"-o cachefile=none"}
1276 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1277 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1278 $ZPOOL create -f $opts $poolname $vdev"
1282 # Create ZFS file system.
1288 local opts=${@:-"-o mountpoint=legacy"}
1290 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1291 $ZFS create $opts $dataset"
1295 # Export ZFS storage pool.
1296 # Before exporting the pool, all datasets within the pool should be unmounted.
1304 poolname=$(zpool_name $facet)
1306 if [[ -n "$poolname" ]]; then
1307 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1308 grep -q ^$poolname/ /proc/mounts ||
1309 $ZPOOL export $opts $poolname"
1314 # Destroy ZFS storage pool.
1315 # Destroy the given pool and free up any devices for other use. This command
1316 # tries to unmount any active datasets before destroying the pool.
1317 # -f Force any active datasets contained within the pool to be unmounted.
1321 local poolname=${2:-$(zpool_name $facet)}
1323 if [[ -n "$poolname" ]]; then
1324 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1325 $ZPOOL destroy -f $poolname"
1330 # Import ZFS storage pool.
1331 # Force importing, even if the pool appears to be potentially active.
1336 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1339 poolname=$(zpool_name $facet)
1341 if [[ -n "$poolname" ]]; then
1342 opts+=" -d $(dirname $(facet_vdevice $facet))"
1343 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1344 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1345 $ZPOOL import -f $opts $poolname"
1350 # Reimport ZFS storage pool with new name
1355 local opts="-o cachefile=none"
1356 local poolname=$(zpool_name $facet)
1358 opts+=" -d $(dirname $(facet_vdevice $facet))"
1359 do_facet $facet "$ZPOOL export $poolname;
1360 $ZPOOL import $opts $poolname $newpool"
1364 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1365 # is not automatically imported on system startup.
1367 # In a failover environment, this will provide resource level fencing which
1368 # will ensure that the same ZFS storage pool will not be imported concurrently
1369 # on different nodes.
1371 disable_zpool_cache() {
1375 poolname=$(zpool_name $facet)
1377 if [[ -n "$poolname" ]]; then
1378 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1383 # This and set_osd_param() shall be used to access OSD parameters
1384 # once existed under "obdfilter":
1389 # writethrough_cache_enable
1393 local device=${2:-$FSNAME-OST*}
1396 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1397 osd-*.$device.$name 2>&1" | grep -v 'error:'
1402 local device=${2:-$FSNAME-OST*}
1406 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1407 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1411 local dz=${1:-$DEBUG_SIZE}
1413 if [ -f /sys/devices/system/cpu/possible ]; then
1414 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1416 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1419 # bug 19944, adjust size to be -gt num_possible_cpus()
1420 # promise 2MB for every cpu at least
1421 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1424 lctl set_param debug_mb=$dz
1427 set_default_debug () {
1428 local debug=${1:-"$PTLDEBUG"}
1429 local subsys=${2:-"$SUBSYSTEM"}
1430 local debug_size=${3:-$DEBUG_SIZE}
1432 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1433 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1435 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1438 set_default_debug_nodes () {
1441 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1442 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1446 do_rpc_nodes "$nodes" set_default_debug \
1447 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1450 set_default_debug_facet () {
1452 local node=$(facet_active_host $facet)
1453 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1455 set_default_debug_nodes $node
1459 local hostid=${1:-$(hostid)}
1461 if [ ! -s /etc/hostid ]; then
1462 printf $(echo -n $hostid |
1463 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1469 local facets=${1:-$(get_facets)}
1472 for facet in ${facets//,/ }; do
1475 [ $RC -eq 0 ] && continue
1477 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1478 skip_noexit "Restart of $facet failed!." &&
1481 error "Restart of $facet failed!"
1488 # Add argument "arg" (e.g., "loop") to the comma-separated list
1489 # of arguments for option "opt" (e.g., "-o") on command
1490 # line "opts" (e.g., "-o flock").
1496 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1498 if echo "$opts" | grep -q $opt_pattern; then
1499 opts=$(echo "$opts" | sed -e \
1500 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1502 opts+="${opts:+ }$opt $arg"
1508 # Associate loop device with a given regular file.
1509 # Return the loop device.
1511 setup_loop_device() {
1515 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1516 if [[ -z \\\$loop_dev ]]; then
1517 loop_dev=\\\$($LOSETUP -f);
1518 $LOSETUP \\\$loop_dev $file || loop_dev=;
1520 echo -n \\\$loop_dev"
1524 # Detach a loop device.
1526 cleanup_loop_device() {
1530 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1531 $LOSETUP -d $loop_dev"
1535 # Check if a given device is a block device.
1542 [[ -n "$dev" ]] || return 1
1543 do_facet $facet "test -b $dev" || return 1
1544 if [[ -n "$size" ]]; then
1545 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1546 count=1 skip=$size 2>&1" |
1547 awk '($3 == "in") { print $1 }')
1548 [[ "$in" = "1+0" ]] || return 1
1553 # Check if a given device is a device-mapper device.
1559 [[ -n "$dev" ]] || return 1
1560 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1564 # Check if a given device is a device-mapper flakey device.
1566 is_dm_flakey_dev() {
1571 [[ -n "$dev" ]] || return 1
1573 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1575 [[ $type = flakey ]] && return 0 || return 1
1579 # Check if device-mapper flakey device is supported by the kernel
1580 # of $facet node or not.
1582 dm_flakey_supported() {
1585 do_facet $facet "modprobe dm-flakey;
1586 $DMSETUP targets | grep -q flakey" &> /dev/null
1590 # Get the device-mapper flakey device name of a given facet.
1592 dm_facet_devname() {
1594 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1596 echo -n ${facet}_flakey
1600 # Get the device-mapper flakey device of a given facet.
1601 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1603 dm_facet_devpath() {
1606 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1610 # Set a device-mapper device with a new table.
1612 # The table has the following format:
1613 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1615 # flakey <target_args> includes:
1616 # <destination_device> <offset> <up_interval> <down_interval> \
1617 # [<num_features> [<feature_arguments>]]
1619 # linear <target_args> includes:
1620 # <destination_device> <start_sector>
1622 dm_set_dev_table() {
1625 local target_type=$3
1631 read tmp num_sectors tmp real_dev tmp \
1632 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1634 case $target_type in
1636 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1639 table="0 $num_sectors linear $real_dev 0"
1641 *) error "invalid target type $target_type" ;;
1644 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1645 error "failed to suspend $dm_dev"
1646 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1647 error "failed to load $target_type table into $dm_dev"
1648 do_facet $facet "$DMSETUP resume $dm_dev" ||
1649 error "failed to resume $dm_dev"
1653 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1654 # feature parameter.
1657 # All write I/O is silently ignored.
1658 # Read I/O is handled correctly.
1660 dm_set_dev_readonly() {
1662 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1664 dm_set_dev_table $facet $dm_dev flakey
1668 # Set a device-mapper device to traditional linear mapping mode.
1670 dm_clear_dev_readonly() {
1672 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1674 dm_set_dev_table $facet $dm_dev linear
1678 # Set the device of a given facet as "read-only".
1680 set_dev_readonly() {
1682 local svc=${facet}_svc
1684 if [[ $(facet_fstype $facet) = zfs ]] ||
1685 ! dm_flakey_supported $facet; then
1686 do_facet $facet $LCTL --device ${!svc} readonly
1688 dm_set_dev_readonly $facet
1693 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1700 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1701 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1702 echo -n $num_sectors
1706 # Create a device-mapper device with a given block device or regular file (will
1707 # be associated with loop device).
1708 # Return the full path of the device-mapper device.
1712 local real_dev=$2 # destination device
1713 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1714 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1716 # check if the device-mapper device to be created already exists
1717 if is_dm_dev $facet $dm_dev; then
1718 # if the existing device was set to "read-only", then clear it
1719 ! is_dm_flakey_dev $facet $dm_dev ||
1720 dm_clear_dev_readonly $facet $dm_dev
1726 # check if the destination device is a block device, and if not,
1727 # associate it with a loop device
1728 is_blkdev $facet $real_dev ||
1729 real_dev=$(setup_loop_device $facet $real_dev)
1730 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1732 # now create the device-mapper device
1733 local num_sectors=$(get_num_sectors $facet $real_dev)
1734 local table="0 $num_sectors linear $real_dev 0"
1737 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1738 { rc=${PIPESTATUS[0]}; dm_dev=; }
1739 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1746 # Map the facet name to its device variable name.
1748 facet_device_alias() {
1750 local dev_alias=$facet
1753 fs2mds) dev_alias=mds1_2 ;;
1754 fs2ost) dev_alias=ost1_2 ;;
1755 fs3ost) dev_alias=ost2_2 ;;
1763 # Save the original value of the facet device and export the new value.
1769 local active_facet=$(facet_active $facet)
1770 local dev_alias=$(facet_device_alias $active_facet)
1771 local dev_name=${dev_alias}_dev
1772 local dev=${!dev_name}
1774 if [[ $active_facet = $facet ]]; then
1775 local failover_dev=${dev_alias}failover_dev
1776 if [[ ${!failover_dev} = $dev ]]; then
1777 eval export ${failover_dev}_saved=$dev
1778 eval export ${failover_dev}=$dm_dev
1781 dev_alias=$(facet_device_alias $facet)
1782 local facet_dev=${dev_alias}_dev
1783 if [[ ${!facet_dev} = $dev ]]; then
1784 eval export ${facet_dev}_saved=$dev
1785 eval export ${facet_dev}=$dm_dev
1789 eval export ${dev_name}_saved=$dev
1790 eval export ${dev_name}=$dm_dev
1794 # Restore the saved value of the facet device.
1799 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1800 local dev_alias=$(facet_device_alias $facet)
1802 local saved_dev=${dev_alias}_dev_saved
1803 [[ -z ${!saved_dev} ]] ||
1804 eval export ${dev_alias}_dev=${!saved_dev}
1806 saved_dev=${dev_alias}failover_dev_saved
1807 [[ -z ${!saved_dev} ]] ||
1808 eval export ${dev_alias}failover_dev=${!saved_dev}
1812 # Remove a device-mapper device.
1813 # If the destination device is a loop device, then also detach it.
1817 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1821 is_dm_dev $facet $dm_dev || return 0
1823 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
1824 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
1826 do_facet $facet "$DMSETUP remove $dm_dev"
1827 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1829 unexport_dm_dev $facet
1831 # detach a loop device
1832 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
1834 # unload dm-flakey module
1835 do_facet $facet "modprobe -r dm-flakey" || true
1841 local active_facet=$(facet_active $facet)
1842 local dev_alias=$(facet_device_alias $active_facet)
1843 local dev=${dev_alias}_dev
1844 local opt=${facet}_opt
1845 local mntpt=$(facet_mntpt $facet)
1846 local opts="${!opt} $@"
1847 local fstype=$(facet_fstype $facet)
1849 local dm_dev=${!dev}
1851 module_loaded lustre || load_modules
1855 if dm_flakey_supported $facet; then
1856 dm_dev=$(dm_create_dev $facet ${!dev})
1857 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
1860 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
1862 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
1864 # import ZFS storage pool
1865 import_zpool $facet || return ${PIPESTATUS[0]}
1867 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1868 lustre:svname $dm_dev");;
1870 error "unknown fstype!";;
1873 echo "Starting ${facet}: $opts $dm_dev $mntpt"
1874 # for testing LU-482 error handling in mount_facets() and test_0a()
1875 if [ -f $TMP/test-lu482-trigger ]; then
1879 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
1883 if [ $RC -ne 0 ]; then
1884 echo "Start of $dm_dev on ${facet} failed ${RC}"
1888 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1889 if [[ "$health" != "healthy" ]]; then
1890 error "$facet is in a unhealthy state"
1893 set_default_debug_facet $facet
1895 if [[ $facet == mds* ]]; then
1897 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1900 if [[ $opts =~ .*nosvc.* ]]; then
1901 echo "Start $dm_dev without service"
1906 wait_update_facet ${facet} "$E2LABEL $dm_dev \
1907 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1908 "" || error "$dm_dev failed to initialize!";;
1910 wait_update_facet ${facet} "$ZFS get -H -o value \
1911 lustre:svname $dm_dev 2>/dev/null | \
1912 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1913 error "$dm_dev failed to initialize!";;
1916 error "unknown fstype!";;
1920 # commit the device label change to disk
1921 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1922 echo "Commit the device label on ${!dev}"
1923 do_facet $facet "sync; sleep 1; sync"
1927 label=$(devicelabel ${facet} $dm_dev)
1928 [ -z "$label" ] && echo no label for $dm_dev && exit 1
1929 eval export ${facet}_svc=${label}
1930 echo Started ${label}
1932 export_dm_dev $facet $dm_dev
1937 # start facet device options
1943 local dev_alias=$(facet_device_alias $facet)
1945 eval export ${dev_alias}_dev=${device}
1946 eval export ${facet}_opt=\"$@\"
1948 local varname=${dev_alias}failover_dev
1949 if [ -n "${!varname}" ] ; then
1950 eval export ${dev_alias}failover_dev=${!varname}
1952 eval export ${dev_alias}failover_dev=$device
1955 local mntpt=$(facet_mntpt $facet)
1956 do_facet ${facet} mkdir -p $mntpt
1957 eval export ${facet}_MOUNT=$mntpt
1958 mount_facet ${facet}
1961 if [[ $facet == mds* ]]; then
1963 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1974 local HOST=$(facet_active_host $facet)
1975 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
1977 local mntpt=$(facet_mntpt $facet)
1978 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
1979 if [ ${running} -ne 0 ]; then
1980 echo "Stopping $mntpt (opts:$@) on $HOST"
1981 do_facet ${facet} $UMOUNT $@ $mntpt
1984 # umount should block, but we should wait for unrelated obd's
1985 # like the MGS or MGC to also stop.
1986 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1988 if [[ $(facet_fstype $facet) == zfs ]]; then
1989 # export ZFS storage pool
1990 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1991 elif dm_flakey_supported $facet; then
1992 local host=${facet}_HOST
1993 local failover_host=${facet}failover_HOST
1994 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
1995 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
1996 dm_cleanup_dev $facet
2001 # save quota version (both administrative and operational quotas)
2002 # add an additional parameter if mountpoint is ever different from $MOUNT
2004 # XXX This function is kept for interoperability with old server (< 2.3.50),
2005 # it should be removed whenever we drop the interoperability for such
2007 quota_save_version() {
2008 local fsname=${2:-$FSNAME}
2010 local ver=$(tr -c -d "123" <<< $spec)
2011 local type=$(tr -c -d "ug" <<< $spec)
2013 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
2015 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
2017 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
2019 local osts=$(get_facets OST)
2020 for ost in ${osts//,/ }; do
2022 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
2026 # client could mount several lustre
2028 # XXX This function is kept for interoperability with old server (< 2.3.50),
2029 # it should be removed whenever we drop the interoperability for such
2032 local fsname=${1:-$FSNAME}
2034 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
2036 do_nodes $(comma_list $(osts_nodes)) \
2037 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
2041 # get mdt quota type
2043 local varsvc=${SINGLEMDS}_svc
2044 do_facet $SINGLEMDS $LCTL get_param -n \
2045 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2048 # get ost quota type
2050 # All OSTs should have same quota type
2051 local varsvc=ost1_svc
2052 do_facet ost1 $LCTL get_param -n \
2053 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2056 # restore old quota type settings
2058 if [ "$old_MDT_QUOTA_TYPE" ]; then
2059 do_facet mgs $LCTL conf_param \
2060 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2062 if [ "$old_OST_QUOTA_TYPE" ]; then
2063 do_facet mgs $LCTL conf_param \
2064 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2068 # Handle the case when there is a space in the lfs df
2069 # "filesystem summary" line the same as when there is no space.
2070 # This will allow fixing the "lfs df" summary line in the future.
2072 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2075 # Get free inodes on the MDT specified by mdt index, free indoes on
2076 # the whole filesystem will be returned when index == -1.
2082 if [ $index -eq -1 ]; then
2085 mdt_uuid=$(mdtuuid_from_index $index)
2088 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2093 # Get the OST device status from 'lfs df' with a given OST index.
2097 local mnt_pnt=${2:-$MOUNT}
2100 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2101 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2107 # save old quota type & set new quota type
2108 local mdt_qtype=$(mdt_quota_type)
2109 local ost_qtype=$(ost_quota_type)
2111 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2112 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2114 export old_MDT_QUOTA_TYPE=$mdt_qtype
2115 export old_OST_QUOTA_TYPE=$ost_qtype
2117 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
2118 error "set mdt quota type failed"
2119 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
2120 error "set ost quota type failed"
2122 local quota_usrs=$QUOTA_USERS
2124 # get_filesystem_size
2125 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2126 local blk_soft=$((disksz + 1024))
2127 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2129 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2130 local i_soft=$inodes
2131 local i_hard=$((i_soft + i_soft / 20))
2133 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2134 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2135 "inode-hardlimit: $i_hard"
2138 for usr in $quota_usrs; do
2139 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2141 cmd="$LFS setquota -$type $usr -b $blk_soft"
2142 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2144 eval $cmd || error "$cmd FAILED!"
2146 # display the quota status
2147 echo "Quota settings for $usr : "
2148 $LFS quota -v -u $usr $mntpt || true
2155 local opts=${3:-$MOUNT_OPTS}
2156 opts=${opts:+-o $opts}
2157 local flags=${4:-$MOUNT_FLAGS}
2159 local device=$MGSNID:/$FSNAME$FILESET
2160 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2161 echo "Bad mount command: opt=$flags $opts dev=$device " \
2166 echo "Starting client: $client: $flags $opts $device $mnt"
2167 do_node $client mkdir -p $mnt
2168 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2169 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2171 #disable FILESET if not supported
2172 do_nodes $client lctl get_param -n \
2173 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2174 device=$MGSNID:/$FSNAME
2175 do_node $client mkdir -p $mnt/$FILESET
2176 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2179 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2180 # Mount using nodemap key
2181 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2182 if $SK_UNIQUE_NM; then
2183 mountkey=$SK_PATH/nodemap/c0.key
2185 local prunedopts=$(echo $opts |
2186 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2187 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2190 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2194 set_default_debug_nodes $client
2206 [ "$3" ] && force=-f
2207 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2208 if [ $running -ne 0 ]; then
2209 echo "Stopping client $client $mnt (opts:$force)"
2210 do_node $client lsof -t $mnt || need_kill=no
2211 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
2212 pids=$(do_node $client lsof -t $mnt | sort -u);
2213 if [ -n $pids ]; then
2214 do_node $client kill -9 $pids || true
2218 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
2219 if [ $busy -ne 0 ] ; then
2220 echo "$mnt is still busy, wait one second" && sleep 1
2221 do_node $client umount $force $mnt
2226 # Mount the file system on the MGS
2227 mount_mgs_client() {
2228 do_facet mgs "mkdir -p $MOUNT"
2229 zconf_mount $mgs_HOST $MOUNT $MOUNT_OPTS ||
2230 error "unable to mount $MOUNT on MGS"
2233 # Unmount the file system on the MGS
2234 umount_mgs_client() {
2235 zconf_umount $mgs_HOST $MOUNT
2236 do_facet mgs "rm -rf $MOUNT"
2239 # nodes is comma list
2240 sanity_mount_check_nodes () {
2246 # FIXME: assume that all cluster nodes run the same os
2247 [ "$(uname)" = Linux ] || return 0
2250 for mnt in $mnts ; do
2251 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2252 mpts=\\\$(mount | grep -c $mnt' ');
2253 if [ \\\$running -ne \\\$mpts ]; then
2254 echo \\\$(hostname) env are INSANE!;
2257 [ $? -eq 0 ] || rc=1
2262 sanity_mount_check_servers () {
2263 [ -n "$CLIENTONLY" ] &&
2264 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2265 echo Checking servers environments
2267 # FIXME: modify get_facets to display all facets wo params
2268 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2272 for facet in ${facets//,/ }; do
2273 node=$(facet_host ${facet})
2274 mntpt=$(facet_mntpt $facet)
2275 sanity_mount_check_nodes $node $mntpt ||
2276 { error "server $node environments are insane!"; return 1; }
2280 sanity_mount_check_clients () {
2281 local clients=${1:-$CLIENTS}
2282 local mntpt=${2:-$MOUNT}
2283 local mntpt2=${3:-$MOUNT2}
2285 [ -z $clients ] && clients=$(hostname)
2286 echo Checking clients $clients environments
2288 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2289 error "clients environments are insane!"
2292 sanity_mount_check () {
2293 sanity_mount_check_servers || return 1
2294 sanity_mount_check_clients || return 2
2297 # mount clients if not mouted
2298 zconf_mount_clients() {
2301 local opts=${3:-$MOUNT_OPTS}
2302 opts=${opts:+-o $opts}
2303 local flags=${4:-$MOUNT_FLAGS}
2304 local device=$MGSNID:/$FSNAME$FILESET
2305 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2306 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2311 echo "Starting client $clients: $flags $opts $device $mnt"
2312 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
2313 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2314 # Mount with own nodemap key
2316 # Mount all server nodes first with per-NM keys
2317 for nmclient in ${clients//,/ }; do
2318 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2319 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2322 # set perms for per-nodemap keys else permission denied
2323 do_nodes $(comma_list $(all_nodes)) \
2324 "keyctl show | grep lustre | cut -c1-11 |
2326 xargs -IX keyctl setperm X 0x3f3f3f3f"
2327 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2329 for nmclient in ${clients//,/ }; do
2330 if $SK_UNIQUE_NM; then
2331 mountkey=$SK_PATH/nodemap/c$i.key
2333 do_node $nmclient "! grep -q $mnt' ' \
2334 /proc/mounts || umount $mnt"
2335 local prunedopts=$(add_sk_mntflag $prunedopts);
2336 prunedopts=$(echo $prunedopts | sed -e \
2337 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2339 do_nodes $(comma_list $(all_server_nodes)) \
2342 do_node $nmclient $MOUNT_CMD $flags \
2343 $prunedopts $MGSNID:/$FSNAME $mnt ||
2348 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2350 do_nodes $clients $MOUNT_CMD $flags $opts \
2351 $MGSNID:/$FSNAME $mnt || return 1
2353 #disable FILESET if not supported
2354 do_nodes $clients lctl get_param -n \
2355 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2356 device=$MGSNID:/$FSNAME
2357 do_nodes $clients mkdir -p $mnt/$FILESET
2358 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2362 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2363 # Mount with nodemap key
2365 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2366 for nmclient in ${clients//,/ }; do
2367 if $SK_UNIQUE_NM; then
2368 mountkey=$SK_PATH/nodemap/c$i.key
2370 local prunedopts=$(echo $opts | sed -e \
2371 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2372 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2375 running=\\\$(mount | grep -c $mnt' ');
2377 if [ \\\$running -eq 0 ] ; then
2379 $MOUNT_CMD $flags $prunedopts $device $mnt;
2382 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2383 grep 'type lustre' | wc -l);
2384 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2385 echo zconf_mount_clients FAILED: \
2386 mount count \\\$running, not matching \
2387 with mount count of 'type lustre' \
2388 \\\$lustre_mnt_count;
2392 exit \\\$rc" || return ${PIPESTATUS[0]}
2399 if $SHARED_KEY; then
2400 tmpopts=$(add_sk_mntflag $opts)
2403 running=\\\$(mount | grep -c $mnt' ');
2405 if [ \\\$running -eq 0 ] ; then
2407 $MOUNT_CMD $flags $tmpopts $device $mnt;
2410 exit \\\$rc" || return ${PIPESTATUS[0]}
2413 echo "Started clients $clients: "
2414 do_nodes $clients "mount | grep $mnt' '"
2416 set_default_debug_nodes $clients
2421 zconf_umount_clients() {
2426 [ "$3" ] && force=-f
2428 echo "Stopping clients: $clients $mnt (opts:$force)"
2429 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2430 if [ \\\$running -ne 0 ] ; then
2431 echo Stopping client \\\$(hostname) $mnt opts:$force;
2432 lsof $mnt || need_kill=no;
2433 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2434 pids=\\\$(lsof -t $mnt | sort -u);
2435 if [ -n \\\"\\\$pids\\\" ]; then
2439 while umount $force $mnt 2>&1 | grep -q "busy"; do
2440 echo "$mnt is still busy, wait one second" && sleep 1;
2447 echo + $POWER_DOWN $node
2451 shutdown_node_hard () {
2453 local attempts=$SHUTDOWN_ATTEMPTS
2455 for i in $(seq $attempts) ; do
2458 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2459 echo "waiting for $host to fail attempts=$attempts"
2460 [ $i -lt $attempts ] || \
2461 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2467 local mnt=${2:-$MOUNT}
2470 if [ "$FAILURE_MODE" = HARD ]; then
2471 shutdown_node_hard $client
2473 zconf_umount_clients $client $mnt -f
2479 local facets="$(get_facets OST),$(get_facets MDS)"
2482 combined_mgs_mds || facets="$facets,mgs"
2484 for facet in ${facets//,/ }; do
2485 if [ $(facet_active_host $facet) == $host ]; then
2486 affected="$affected $facet"
2490 echo $(comma_list $affected)
2495 local host=${2:-$(facet_host $facet)}
2497 local label=$(convert_facet2label $facet)
2498 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2501 facets_up_on_host () {
2503 local facets=$(facets_on_host $host)
2506 for facet in ${facets//,/ }; do
2507 if $(facet_up $facet $host); then
2508 affected_up="$affected_up $facet"
2512 echo $(comma_list $affected_up)
2517 local affected_facet
2518 local affected_facets
2520 if [[ "$FAILURE_MODE" = HARD ]]; then
2521 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2522 dm_flakey_supported $facet; then
2523 affected_facets=$(affected_facets $facet)
2524 for affected_facet in ${affected_facets//,/ }; do
2525 unexport_dm_dev $affected_facet
2529 shutdown_node_hard $(facet_active_host $facet)
2537 echo + $POWER_UP $node
2550 if [ "$FAILURE_MODE" = HARD ]; then
2551 reboot_node $(facet_active_host $facet)
2559 if [ "$FAILURE_MODE" = HARD ]; then
2569 for facet in ${facets//,/ }; do
2570 hosts=$(expand_list $hosts $(facet_host $facet) )
2576 _check_progs_installed () {
2580 for prog in $progs; do
2581 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2582 echo $prog missing on $(hostname)
2589 check_progs_installed () {
2593 do_rpc_nodes "$nodes" _check_progs_installed $@
2596 # recovery-scale functions
2598 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2601 start_client_load() {
2604 local var=$(node_var_name $client)_load
2605 eval export ${var}=$load
2607 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2608 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2609 END_RUN_FILE=$END_RUN_FILE \
2610 LOAD_PID_FILE=$LOAD_PID_FILE \
2611 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2612 TESTNAME=$TESTNAME \
2613 DBENCH_LIB=$DBENCH_LIB \
2614 DBENCH_SRC=$DBENCH_SRC \
2615 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2621 log "Started client load: ${load} on $client"
2623 # get the children process IDs
2624 local pids=$(ps --ppid $ppid -o pid= | xargs)
2625 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2629 start_client_loads () {
2630 local -a clients=(${1//,/ })
2631 local numloads=${#CLIENT_LOADS[@]}
2634 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2635 testnum=$((nodenum % numloads))
2636 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2638 # bug 22169: wait the background threads to start
2642 # only for remote client
2643 check_client_load () {
2645 local var=$(node_var_name $client)_load
2646 local testload=run_${!var}.sh
2648 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2650 # bug 18914: try to connect several times not only when
2651 # check ps, but while check_node_health also
2655 while [ $RC = 254 -a $tries -gt 0 ]; do
2659 if ! check_node_health $client; then
2661 if [ $RC -eq 254 ]; then
2662 # FIXME: not sure how long we shuold sleep here
2666 echo "check node health failed: RC=$RC "
2670 # We can continue try to connect if RC=254
2671 # Just print the warning about this
2672 if [ $RC = 254 ]; then
2673 echo "got a return status of $RC from do_node while checking " \
2674 "node health on $client"
2677 # see if the load is still on the client
2680 while [ $RC = 254 -a $tries -gt 0 ]; do
2684 if ! do_node $client \
2685 "ps auxwww | grep -v grep | grep -q $testload"; then
2690 if [ $RC = 254 ]; then
2691 echo "got a return status of $RC from do_node while checking " \
2692 "(node health and 'ps') the client load on $client"
2693 # see if we can diagnose a bit why this is
2698 check_client_loads () {
2699 local clients=${1//,/ }
2703 for client in $clients; do
2704 check_client_load $client
2706 if [ "$rc" != 0 ]; then
2707 log "Client load failed on node $client, rc=$rc"
2713 restart_client_loads () {
2714 local clients=${1//,/ }
2715 local expectedfail=${2:-""}
2719 for client in $clients; do
2720 check_client_load $client
2722 if [ "$rc" != 0 -a "$expectedfail" ]; then
2723 local var=$(node_var_name $client)_load
2724 start_client_load $client ${!var}
2725 echo "Restarted client load ${!var}: on $client. Checking ..."
2726 check_client_load $client
2728 if [ "$rc" != 0 ]; then
2729 log "Client load failed to restart on node $client, rc=$rc"
2730 # failure one client load means test fail
2731 # we do not need to check other
2740 # Start vmstat and save its process ID in a file.
2745 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2748 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2749 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2752 # Display the nodes on which client loads failed.
2753 print_end_run_file() {
2757 [ -s $file ] || return 0
2759 echo "Found the END_RUN_FILE file: $file"
2762 # A client load will stop if it finds the END_RUN_FILE file.
2763 # That does not mean the client load actually failed though.
2764 # The first node in END_RUN_FILE is the one we are interested in.
2767 if [ -n "$node" ]; then
2768 local var=$(node_var_name $node)_load
2770 local prefix=$TESTLOG_PREFIX
2771 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2772 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2773 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2775 echo "Client load ${!var} failed on node $node:"
2781 # Stop the process which had its PID saved in a file.
2786 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2788 do_nodes $nodes "test -f $pid_file &&
2789 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2792 # Stop all client loads.
2793 stop_client_loads() {
2794 local nodes=${1:-$CLIENTS}
2797 # stop the client loads
2798 stop_process $nodes $pid_file
2800 # clean up the processes that started them
2801 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2803 # End recovery-scale functions
2805 # verify that lustre actually cleaned up properly
2807 VAR=$(lctl get_param -n catastrophe 2>&1)
2808 if [ $? = 0 ] ; then
2809 if [ $VAR != 0 ]; then
2810 error "LBUG/LASSERT detected"
2813 BUSY=$(dmesg | grep -i destruct || true)
2814 if [ -n "$BUSY" ]; then
2816 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2820 check_mem_leak || exit 204
2822 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2823 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2826 if module_loaded lnet || module_loaded libcfs; then
2827 echo "$TESTSUITE: modules still loaded..." 1>&2
2836 if [[ "$1" == "--verbose" ]]; then
2851 PREV_RESULT=$(do_node $node "$TEST")
2853 RESULT=$(do_node $node "$TEST")
2854 if [[ "$RESULT" == "$FINAL" ]]; then
2855 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2856 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2860 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2861 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2865 [[ $WAIT -ge $MAX ]] && break
2866 [[ $((WAIT % print)) -eq 0 ]] &&
2867 echo "Waiting $((MAX - WAIT)) secs for update"
2868 WAIT=$((WAIT + sleep))
2871 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2875 wait_update_facet() {
2877 [ "$1" = "--verbose" ] && verbose="$1" && shift
2881 wait_update $verbose $(facet_active_host $facet) "$@"
2885 do_nodes $(comma_list $(mdts_nodes)) \
2886 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
2887 do_nodes $(comma_list $(osts_nodes)) \
2888 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2889 grep -v 'Found no match'
2893 local zfs_wait=${2:-5}
2895 # the occupied disk space will be released
2896 # only after TXGs are committed
2897 if [[ $(facet_fstype $1) == zfs ]]; then
2898 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
2903 wait_delete_completed_mds() {
2904 local max_wait=${1:-20}
2906 local stime=$(date +%s)
2911 # find MDS with pending deletions
2912 for node in $(mdts_nodes); do
2913 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2914 2>/dev/null | calc_sum)
2915 if [[ $changes -eq 0 ]]; then
2918 mds2sync="$mds2sync $node"
2920 if [ -z "$mds2sync" ]; then
2921 wait_zfs_commit $SINGLEMDS
2924 mds2sync=$(comma_list $mds2sync)
2926 # sync MDS transactions
2927 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
2929 # wait till all changes are sent and commmitted by OSTs
2930 # for ldiskfs space is released upon execution, but DMU
2931 # do this upon commit
2934 while [[ $WAIT -ne $max_wait ]]; do
2935 changes=$(do_nodes $mds2sync \
2936 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2937 #echo "$node: $changes changes on all"
2938 if [[ $changes -eq 0 ]]; then
2939 wait_zfs_commit $SINGLEMDS
2941 # the occupied disk space will be released
2942 # only after TXGs are committed
2943 wait_zfs_commit ost1
2951 echo "Delete is not completed in $((etime - stime)) seconds"
2952 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2959 # we can use "for" here because we are waiting the slowest
2960 for host in ${hostlist//,/ }; do
2961 check_network "$host" 900
2963 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2970 for facet in ${facetlist//,/ }; do
2971 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2973 wait_for_host $hostlist
2976 _wait_recovery_complete () {
2979 # Use default policy if $2 is not passed by caller.
2980 local MAX=${2:-$(max_recovery_time)}
2985 while [ $WAIT -lt $MAX ]; do
2986 STATUS=$(lctl get_param -n $param | grep status)
2988 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2991 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2993 echo "$param recovery not done in $MAX sec. $STATUS"
2997 wait_recovery_complete () {
3000 # with an assumption that at_max is the same on all nodes
3001 local MAX=${2:-$(max_recovery_time)}
3004 if [ "$FAILURE_MODE" = HARD ]; then
3005 facets=$(facets_on_host $(facet_active_host $facet))
3007 echo affected facets: $facets
3009 # we can use "for" here because we are waiting the slowest
3010 for facet in ${facets//,/ }; do
3011 local var_svc=${facet}_svc
3012 local param="*.${!var_svc}.recovery_status"
3014 local host=$(facet_active_host $facet)
3015 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3019 wait_mds_ost_sync () {
3020 # just because recovery is done doesn't mean we've finished
3021 # orphan cleanup. Wait for llogs to get synchronized.
3022 echo "Waiting for orphan cleanup..."
3023 # MAX value includes time needed for MDS-OST reconnection
3024 local MAX=$(( TIMEOUT * 2 ))
3025 local WAIT_TIMEOUT=${1:-$MAX}
3028 local list=$(comma_list $(mdts_nodes))
3029 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3030 if ! do_facet $SINGLEMDS \
3031 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3033 # old way, use mds_sync
3035 list=$(comma_list $(osts_nodes))
3036 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3039 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3040 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3041 local -a sync=($(do_nodes $list "$cmd"))
3044 for ((i=0; i<${#sync[@]}; i++)); do
3046 [ ${sync[$i]} -eq 1 ] && continue
3048 [ ${sync[$i]} -eq 0 ] && continue
3050 # there is a not finished MDS-OST synchronization
3054 sleep 2 # increase waiting time and cover statfs cache
3055 [ ${con} -eq 1 ] && return 0
3056 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3060 # show which nodes are not finished.
3061 cmd=$(echo $cmd | sed '/-n//')
3062 do_nodes $list "$cmd"
3063 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3067 # Wait OSTs to be active on both client and MDT side.
3069 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3070 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3071 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3072 error "wait_update OSTs up on client failed"
3074 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3075 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3076 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3077 error "wait_update OSTs up on MDT0000 failed"
3080 wait_destroy_complete () {
3081 echo "Waiting for local destroys to complete"
3082 # MAX value shouldn't be big as this mean server responsiveness
3083 # never increase this just to make test pass but investigate
3084 # why it takes so long time
3087 while [ $WAIT -lt $MAX ]; do
3088 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
3092 for ((i=0; i<${#RPCs[@]}; i++)); do
3093 [ ${RPCs[$i]} -eq 0 ] && continue
3094 # there are still some destroy RPCs in flight
3099 [ ${con} -eq 1 ] && return 0 # done waiting
3100 echo "Waiting ${WAIT}s for local destroys to complete"
3103 echo "Local destroys weren't done in $MAX sec."
3107 wait_delete_completed() {
3108 wait_delete_completed_mds $1 || return $?
3109 wait_destroy_complete || return $?
3118 # conf-sanity 31 takes a long time cleanup
3119 while [ $WAIT -lt 300 ]; do
3120 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3121 lctl dl | grep ' ST ' || true")
3122 [ -z "${running}" ] && return 0
3123 echo "waited $WAIT for${running}"
3124 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3126 WAIT=$((WAIT + INTERVAL))
3128 echo "service didn't stop after $WAIT seconds. Still running:"
3133 wait_remote_prog () {
3139 [ "$PDSH" = "no_dsh" ] && return 0
3141 while [ $WAIT -lt $2 ]; do
3142 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3143 [ -z "${running}" ] && return 0 || true
3144 echo "waited $WAIT for: "
3146 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3148 WAIT=$((WAIT + INTERVAL))
3150 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3151 [ -z "$pids" ] && return 0
3152 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3153 # FIXME: not portable
3154 for pid in $pids; do
3155 cat /proc/${pid}/status || true
3156 cat /proc/${pid}/wchan || true
3158 kill -9 $pid || true
3167 local clients=${1:-$CLIENTS}
3169 if [ -z "$clients" ]; then
3172 $PDSH $clients "$LFS df $MOUNT" > /dev/null
3177 # not every config has many clients
3183 # usually checked on particular client or locally
3192 client_reconnect_try() {
3193 local f=$MOUNT/recon
3196 if [ -z "$CLIENTS" ]; then
3197 $LFS df $MOUNT; uname -n >> $f
3199 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3201 echo "Connected clients: $(cat $f)"
3202 ls -l $f > /dev/null
3206 client_reconnect() {
3207 # one client_reconnect_try call does not always do the job...
3209 client_reconnect_try && break
3214 affected_facets () {
3217 local host=$(facet_active_host $facet)
3218 local affected=$facet
3220 if [ "$FAILURE_MODE" = HARD ]; then
3221 affected=$(facets_up_on_host $host)
3227 local E2FSCK_ON_MDT0=false
3228 if [ "$1" == "--fsck" ]; then
3230 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3242 #Because it will only get up facets, we need get affected
3243 #facets before shutdown
3244 #For HARD Failure mode, it needs make sure facets on the same
3245 #HOST will only be shutdown and reboot once
3246 for facet in ${facets//,/ }; do
3247 local affected_facet
3249 #check whether facet has been included in other affected facets
3250 for ((index=0; index<$total; index++)); do
3251 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
3254 if [ $skip -eq 0 ]; then
3255 affecteds[$total]=$(affected_facets $facet)
3260 for ((index=0; index<$total; index++)); do
3261 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3262 local host=$(facet_active_host $facet)
3263 echo "Failing ${affecteds[index]} on $host"
3264 shutdown_facet $facet
3267 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3268 $(mdsdevname 1) "-n" || error "Running e2fsck")
3270 for ((index=0; index<$total; index++)); do
3271 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3272 echo reboot facets: ${affecteds[index]}
3276 change_active ${affecteds[index]}
3278 wait_for_facet ${affecteds[index]}
3279 # start mgs first if it is affected
3280 if ! combined_mgs_mds &&
3281 list_member ${affecteds[index]} mgs; then
3282 mount_facet mgs || error "Restart of mgs failed"
3284 # FIXME; has to be changed to mount all facets concurrently
3285 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
3286 echo mount facets: ${affecteds[index]}
3287 mount_facets ${affecteds[index]}
3297 do_facet $facet "sync; sync; sync"
3300 # make sure there will be no seq change