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 SK_SKIPFIRST=${SK_SKIPFIRST:-true}
26 export IDENTITY_UPCALL=default
28 export FLAKEY=${FLAKEY:-true}
29 # specify environment variable containing batch job name for server statistics
30 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
32 #export PDSH="pdsh -S -Rssh -w"
33 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
34 export UMOUNT=${UMOUNT:-"umount -d"}
36 export LSNAPSHOT_CONF="/etc/ldev.conf"
37 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
39 # sles12 umount has a issue with -d option
40 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
41 export UMOUNT="umount"
44 # function used by scripts run on remote nodes
45 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
46 . $LUSTRE/tests/functions.sh
47 . $LUSTRE/tests/yaml.sh
49 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
51 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
53 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
55 if [ -f "$EXCEPT_LIST_FILE" ]; then
56 echo "Reading test skip list from $EXCEPT_LIST_FILE"
61 # check config files for options in decreasing order of preference
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
63 MODPROBECONF=/etc/modprobe.d/lustre.conf
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
65 MODPROBECONF=/etc/modprobe.d/Lustre
66 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
67 MODPROBECONF=/etc/modprobe.conf
69 sanitize_parameters() {
70 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
73 if [ -d "$path" ]; then
74 eval export $i=$(echo $path | sed -r 's/\/+$//g')
80 [[ $DIR/ = $MOUNT/* ]] ||
81 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
82 [[ $DIR1/ = $MOUNT1/* ]] ||
83 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
84 [[ $DIR2/ = $MOUNT2/* ]] ||
85 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
87 [ -n "$failed" ] && exit 99 || true
91 echo "usage: $0 [-r] [-f cfgfile]"
99 [ -z "$DEFAULT_SUITES"] && return 0
100 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
102 local form="%-13s %-17s %-9s %s %s\n"
103 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
104 echo "------------------------------------------------------------------------------------"
105 for O in $DEFAULT_SUITES; do
106 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
107 [ "${!O}" = "no" ] && continue || true
108 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
109 local log=${TMP}/${o}.log
110 if is_sanity_benchmark $o; then
111 log=${TMP}/sanity-benchmark.log
116 local status=Unfinished
118 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
120 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
121 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
122 total=$(grep duration $log | awk '{ print $2 }')
123 if [ "${!O}" = "done" ]; then
127 local durations=$(egrep "^PASS|^FAIL" $log |
128 tr -d "("| sed s/s\)$//g |
129 awk '{ print $2":"$3"|" }')
130 details=$(printf "%s\n%s %s %s\n" "$details" \
131 "DDETAILS" "$O" "$(echo $durations)")
134 printf "$form" $status "$O" "${total}" "E=$skipped"
135 printf "$form" "-" "-" "-" "S=$(echo $slow)"
138 for O in $DEFAULT_SUITES; do
139 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
140 if [ "${!O}" = "no" ]; then
141 printf "$form" "Skipped" "$O" ""
145 # print the detailed tests durations if DDETAILS=true
152 export LUSTRE=$(absolute_path $LUSTRE)
153 export TESTSUITE=$(basename $0 .sh)
154 export TEST_FAILED=false
155 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
156 export RPC_MODE=${RPC_MODE:-false}
157 export DO_CLEANUP=${DO_CLEANUP:-true}
158 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
159 export CLEANUP_DM_DEV=false
160 export PAGE_SIZE=$(get_page_size client)
162 export MKE2FS=$MKE2FS
163 if [ -z "$MKE2FS" ]; then
164 if which mkfs.ldiskfs >/dev/null 2>&1; then
165 export MKE2FS=mkfs.ldiskfs
171 export DEBUGFS=$DEBUGFS
172 if [ -z "$DEBUGFS" ]; then
173 if which debugfs.ldiskfs >/dev/null 2>&1; then
174 export DEBUGFS=debugfs.ldiskfs
176 export DEBUGFS=debugfs
180 export TUNE2FS=$TUNE2FS
181 if [ -z "$TUNE2FS" ]; then
182 if which tunefs.ldiskfs >/dev/null 2>&1; then
183 export TUNE2FS=tunefs.ldiskfs
185 export TUNE2FS=tune2fs
189 export E2LABEL=$E2LABEL
190 if [ -z "$E2LABEL" ]; then
191 if which label.ldiskfs >/dev/null 2>&1; then
192 export E2LABEL=label.ldiskfs
194 export E2LABEL=e2label
198 export DUMPE2FS=$DUMPE2FS
199 if [ -z "$DUMPE2FS" ]; then
200 if which dumpfs.ldiskfs >/dev/null 2>&1; then
201 export DUMPE2FS=dumpfs.ldiskfs
203 export DUMPE2FS=dumpe2fs
207 export E2FSCK=$E2FSCK
208 if [ -z "$E2FSCK" ]; then
209 if which fsck.ldiskfs >/dev/null 2>&1; then
210 export E2FSCK=fsck.ldiskfs
216 export RESIZE2FS=$RESIZE2FS
217 if [ -z "$RESIZE2FS" ]; then
218 if which resizefs.ldiskfs >/dev/null 2>&1; then
219 export RESIZE2FS=resizefs.ldiskfs
221 export RESIZE2FS=resize2fs
225 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
226 export FSCK_MAX_ERR=4 # File system errors left uncorrected
228 export ZFS=${ZFS:-zfs}
229 export ZPOOL=${ZPOOL:-zpool}
230 export ZDB=${ZDB:-zdb}
231 export PARTPROBE=${PARTPROBE:-partprobe}
233 #[ -d /r ] && export ROOT=${ROOT:-/r}
234 export TMP=${TMP:-$ROOT/tmp}
235 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
236 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
237 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
239 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
240 if ! echo $PATH | grep -q $LUSTRE/utils; then
241 export PATH=$LUSTRE/utils:$PATH
243 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
244 export PATH=$LUSTRE/utils/gss:$PATH
246 if ! echo $PATH | grep -q $LUSTRE/tests; then
247 export PATH=$LUSTRE/tests:$PATH
249 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
250 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
252 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
253 [ ! -f "$LST" ] && export LST=$(which lst)
254 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
255 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
256 export MCREATE=${MCREATE:-mcreate}
257 export MULTIOP=${MULTIOP:-multiop}
258 # Ubuntu, at least, has a truncate command in /usr/bin
259 # so fully path our truncate command.
260 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
261 export FSX=${FSX:-$LUSTRE/tests/fsx}
262 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
263 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
264 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
265 export PATH=$LUSTRE/tests/racer:$PATH:
267 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
268 export PATH=$LUSTRE/tests/mpi:$PATH
270 export RSYNC_RSH=${RSYNC_RSH:-rsh}
272 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
273 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
274 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
275 [ ! -f "$LFS" ] && export LFS=$(which lfs)
276 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
277 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
279 export PERM_CMD=${PERM_CMD:-"$LCTL conf_param"}
281 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
282 if [ ! -f "$L_GETIDENTITY" ]; then
283 if `which l_getidentity > /dev/null 2>&1`; then
284 export L_GETIDENTITY=$(which l_getidentity)
286 export L_GETIDENTITY=NONE
289 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
290 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
291 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
292 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
293 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
294 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
295 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
296 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
297 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
298 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
299 [ ! -f "$LUSTRE_RMMOD" ] &&
300 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
301 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
302 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
303 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
304 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
305 [ ! -f "$LFS_MIGRATE" ] &&
306 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
307 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
308 [ ! -f "$LR_READER" ] &&
309 export LR_READER=$(which lr_reader 2> /dev/null)
310 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
311 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
312 [ ! -f "$LSOM_SYNC" ] &&
313 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
314 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
315 export NAME=${NAME:-local}
316 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
317 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
318 export LGSSD=$(which lgssd)
319 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
320 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
321 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
323 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
325 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
326 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
328 export DMSETUP=${DMSETUP:-dmsetup}
329 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
330 export LOSETUP=${LOSETUP:-losetup}
332 if [ "$ACCEPTOR_PORT" ]; then
333 export PORT_OPT="--port $ACCEPTOR_PORT"
337 $RPC_MODE || echo "Using GSS shared-key feature"
338 which lgss_sk > /dev/null 2>&1 ||
339 error_exit "built with lgss_sk disabled! SEC=$SEC"
347 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
348 which lgss_keyring > /dev/null 2>&1 ||
349 error_exit "built with gss disabled! SEC=$SEC"
360 IDENTITY_UPCALL=false
364 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
366 # Paths on remote nodes, if different
367 export RLUSTRE=${RLUSTRE:-$LUSTRE}
368 export RPWD=${RPWD:-$PWD}
369 export I_MOUNTED=${I_MOUNTED:-"no"}
370 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
371 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
372 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
373 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
374 ! -f $LUSTRE/mdt/mdt.ko ]; then
375 export CLIENTMODSONLY=yes
378 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
379 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
383 while getopts "rvwf:" opt $*; do
388 w) WRITECONF=writeconf;;
393 shift $((OPTIND - 1))
396 # print the durations of each test if "true"
397 DDETAILS=${DDETAILS:-false}
398 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
403 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
410 ncpts=$(do_facet $facet "lctl get_param -n " \
411 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
413 if [ $ncpts -eq 0 ]; then
420 # Return a numeric version code based on a version string. The version
421 # code is useful for comparison two version strings to see which is newer.
423 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
424 eval set -- $(tr "[:punct:]" " " <<< $*)
426 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
429 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
430 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
432 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
434 # usage: lustre_build_version
436 # All Lustre versions support "lctl get_param" to report the version of the
437 # code running in the kernel (what our tests are interested in), but it
438 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
439 # the "version" parameter doesn't include "lustre: " at the beginning.
440 # If that fails, call "lctl lustre_build_version" which prints either (or both)
441 # the userspace and kernel build versions, but until 2.8.55 required root
442 # access to get the Lustre kernel version. If that also fails, fall back to
443 # using "lctl --version", which is easy to parse and works without the kernel
444 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
445 # not the module version, though they are usually the same.
447 # Various commands and their output format for different Lustre versions:
448 # lctl get_param version: 2.9.55
449 # lctl get_param version: lustre: 2.8.53
450 # lctl get_param version: lustre: 2.6.52
451 # kernel: patchless_client
452 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
453 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
454 # lctl lustre_build_version: error: lustre_build_version: Permission denied
455 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
456 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
457 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
458 # lctl --version: lctl 2.6.50
460 # output: prints version string to stdout in (up to 4) dotted-decimal values
461 lustre_build_version() {
462 local facet=${1:-client}
463 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
464 $LCTL lustre_build_version 2>/dev/null ||
465 $LCTL --version 2>/dev/null | cut -d' ' -f2")
466 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
467 [ -n "$lver" ] && ver="$lver"
469 sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' -e 's/_/./g' <<<$ver |
473 # Report the Lustre numeric build version code for the supplied facet.
474 lustre_version_code() {
475 version_code $(lustre_build_version $1)
479 /sbin/lsmod | grep -q "^\<$1\>"
491 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
494 # parallels can't load modules directly from prlfs, use /tmp instead
495 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
496 local target="$(mktemp)"
498 cp "$module" "$target"
501 [[ $rc == 0 ]] && PRLFS=true
509 # Load a module on the system where this is running.
511 # usage: load_module module_name [module arguments for insmod/modprobe]
513 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
514 # will be used as the arguments. Otherwise arguments will be obtained from
515 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
518 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
521 local base=$(basename $module $ext)
523 local -A module_is_loaded_aa
527 for mod in $(lsmod | awk '{ print $1; }'); do
528 module_is_loaded_aa[${mod//-/_}]=true
532 ${module_is_loaded_aa[${1//-/_}]:-false}
535 if module_is_loaded $base; then
539 if [[ -f $LUSTRE/$module$ext ]]; then
540 path=$LUSTRE/$module$ext
541 elif [[ "$base" == lnet_selftest ]] &&
542 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
543 path=$LUSTRE/../lnet/selftest/$base$ext
548 if [[ -n "$path" ]]; then
549 # Try to load any non-Lustre modules that $module depends on.
550 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
551 if ! module_is_loaded $mod; then
557 # If no module arguments were passed then get them from
558 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
559 if [ $# -eq 0 ]; then
560 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
561 # not in Bash until 4.x, so we resort to eval.
562 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
563 eval set -- \$$optvar
564 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
565 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
567 opt=$(awk -v var="^options $base" '$0 ~ var \
568 {gsub("'"options $base"'",""); print}' \
570 set -- $(echo -n $opt)
572 # Ensure we have accept=all for lnet
573 if [[ "$base" == lnet ]]; then
574 # OK, this is a bit wordy...
575 local arg accept_all_present=false
578 [[ "$arg" == accept=all ]] &&
579 accept_all_present=true
582 $accept_all_present || set -- "$@" accept=all
589 [ $# -gt 0 ] && echo "${module} options: '$*'"
591 # Note that insmod will ignore anything in modprobe.conf, which is why
592 # we're passing options on the command-line. If $path does not exist
593 # then we must be testing a "make install" or"rpm" installation. Also
594 # note that failing to load ptlrpc_gss is not considered fatal.
595 if [[ -n "$path" ]]; then
596 lustre_insmod $path "$@"
597 elif [[ "$base" == ptlrpc_gss ]]; then
598 if ! modprobe $base "$@" 2>/dev/null; then
599 echo "gss/krb5 is not supported"
606 load_modules_local() {
607 if [ -n "$MODPROBE" ]; then
609 echo "Using modprobe to load modules"
613 echo Loading modules from $LUSTRE
617 if [ -f /sys/devices/system/cpu/online ]; then
618 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
619 echo "detected $ncpus online CPUs by sysfs"
621 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
623 if [ $rc -eq 0 ]; then
624 echo "detected $ncpus online CPUs by getconf"
626 echo "Can't detect number of CPUs"
631 # if there is only one CPU core, libcfs can only create one partition
632 # if there is more than 4 CPU cores, libcfs should create multiple CPU
633 # partitions. So we just force libcfs to create 2 partitions for
634 # system with 2 or 4 cores
635 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
636 # force to enable multiple CPU partitions
637 echo "Force libcfs to create 2 CPU partitions"
638 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
640 echo "libcfs will create CPU partition based on online CPUs"
643 load_module ../libcfs/libcfs/libcfs
644 # Prevent local MODOPTS_LIBCFS being passed as part of environment
645 # variable to remote nodes
649 load_module ../lnet/lnet/lnet
651 LNDPATH=${LNDPATH:-"../lnet/klnds"}
652 if [ -z "$LNETLND" ]; then
654 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
655 tcp*) LNETLND="socklnd/ksocklnd" ;;
656 *) local lnd="${NETTYPE%%[0-9]}lnd"
657 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
658 LNETLND="$lnd/k$lnd" ||
659 LNETLND="socklnd/ksocklnd"
662 load_module ../lnet/klnds/$LNETLND
663 load_module obdclass/obdclass
664 load_module ptlrpc/ptlrpc
665 load_module ptlrpc/gss/ptlrpc_gss
673 load_module obdecho/obdecho
674 if ! client_only; then
675 load_module lfsck/lfsck
676 [ "$LQUOTA" != "no" ] &&
677 load_module quota/lquota $LQUOTAOPTS
678 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
679 load_module osd-zfs/osd_zfs
680 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
681 load_module ../ldiskfs/ldiskfs
682 load_module osd-ldiskfs/osd_ldiskfs
694 load_module llite/lustre
695 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
697 rm -f $OGDB/ogdb-$HOSTNAME
698 $LCTL modules > $OGDB/ogdb-$HOSTNAME
700 # 'mount' doesn't look in $PATH, just sbin
701 local mount_lustre=$LUSTRE/utils/mount.lustre
702 if [ -f $mount_lustre ]; then
703 local sbin_mount=$(readlink -f /sbin)/mount.lustre
704 if grep -qw "$sbin_mount" /proc/mounts; then
705 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
707 if ! grep -qw "$sbin_mount" /proc/mounts; then
708 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
709 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
710 cat <<- EOF > "$sbin_mount"
713 echo "This $sbin_mount just a mountpoint." 1>&2
714 echo "It is never supposed to be run." 1>&2
715 logger -p emerg -- "using stub $sbin_mount $@"
718 chmod a+x $sbin_mount
720 mount --bind $mount_lustre $sbin_mount ||
721 error "can't bind $mount_lustre to $sbin_mount"
729 # load modules on remote nodes optionally
730 # lustre-tests have to be installed on these nodes
731 if $LOAD_MODULES_REMOTE; then
732 local list=$(comma_list $(remote_nodes_list))
733 if [ -n "$list" ]; then
734 echo "loading modules on: '$list'"
735 do_rpc_nodes "$list" load_modules_local
741 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
742 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
743 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
744 echo "$LEAK_LUSTRE" 1>&2
745 echo "$LEAK_PORTALS" 1>&2
746 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
747 echo "Memory leaks detected"
748 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
754 wait_exit_ST client # bug 12845
756 $LUSTRE_RMMOD ldiskfs || return 2
758 if $LOAD_MODULES_REMOTE; then
759 local list=$(comma_list $(remote_nodes_list))
760 if [ -n "$list" ]; then
761 echo "unloading modules on: '$list'"
762 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
763 do_rpc_nodes "$list" check_mem_leak
767 local sbin_mount=$(readlink -f /sbin)/mount.lustre
768 if grep -qe "$sbin_mount " /proc/mounts; then
769 umount $sbin_mount || true
770 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
774 check_mem_leak || return 254
776 echo "modules unloaded."
781 local facet=${1:-$SINGLEMDS}
784 case $(facet_fstype $facet) in
785 ldiskfs) size=50;; # largest seen is 44, leave some headroom
786 # grant_block_size is in bytes, allow at least 2x max blocksize
787 zfs) size=$(lctl get_param osc.$FSNAME*.import |
788 awk '/grant_block_size:/ {print $2/512; exit;}')
792 echo -n $((size * MDSCOUNT))
796 local facet=${1:-$SINGLEMDS}
797 local fstype=$(facet_fstype $facet)
800 ldiskfs) size=4;; # ~4KB per inode
801 zfs) size=11;; # 10 to 11KB per inode
807 check_gss_daemon_nodes() {
811 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
812 if [ \\\"\\\$num\\\" -ne 1 ]; then
813 echo \\\$num instance of $dname;
818 check_gss_daemon_facet() {
822 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
823 if [ $num -ne 1 ]; then
824 echo "$num instance of $dname on $facet"
833 echo Stopping $@ on $list
834 do_nodes $list "killall -2 $@ 2>/dev/null || true"
837 # start gss daemons on all nodes, or "daemon" on "nodes" if set
838 start_gss_daemons() {
842 if [ "$nodes" ] && [ "$daemon" ] ; then
843 echo "Starting gss daemon on nodes: $nodes"
844 do_nodes $nodes "$daemon" || return 8
848 nodes=$(comma_list $(mdts_nodes))
849 echo "Starting gss daemon on mds: $nodes"
851 # Start all versions, in case of switching
852 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
854 do_nodes $nodes "$LSVCGSSD -v" || return 1
857 do_nodes $nodes "$LGSSD -v" || return 2
860 nodes=$(comma_list $(osts_nodes))
861 echo "Starting gss daemon on ost: $nodes"
863 # Start all versions, in case of switching
864 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
866 do_nodes $nodes "$LSVCGSSD -v" || return 3
868 # starting on clients
870 local clients=${CLIENTS:-$HOSTNAME}
872 echo "Starting $LGSSD on clients $clients "
873 do_nodes $clients "$LGSSD -v" || return 4
876 # wait daemons entering "stable" status
880 # check daemons are running
882 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
883 check_gss_daemon_nodes $nodes lsvcgssd || return 5
885 nodes=$(comma_list $(mdts_nodes))
886 check_gss_daemon_nodes $nodes lgssd || return 6
889 check_gss_daemon_nodes $clients lgssd || return 7
894 local nodes=$(comma_list $(mdts_nodes))
896 send_sigint $nodes lsvcgssd lgssd
898 nodes=$(comma_list $(osts_nodes))
899 send_sigint $nodes lsvcgssd
901 nodes=${CLIENTS:-$HOSTNAME}
902 send_sigint $nodes lgssd
906 # Add mount flags for shared key
908 if grep -q skpath <<< "$mt_opts" ; then
909 mt_opts=$(echo $mt_opts |
910 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
912 if [ -z "$mt_opts" ]; then
913 mt_opts="-o skpath=$SK_PATH"
915 mt_opts="$mt_opts,skpath=$SK_PATH"
931 if ! module_loaded ptlrpc_gss; then
932 load_module ptlrpc/gss/ptlrpc_gss
933 module_loaded ptlrpc_gss ||
934 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
937 if $GSS_KRB5 || $GSS_SK; then
938 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
941 if $GSS_SK && $SK_NO_KEY; then
942 local numclients=${1:-$CLIENTCOUNT}
943 local clients=${CLIENTS:-$HOSTNAME}
945 # security ctx config for keyring
948 if grep -q request-key /proc/mounts > /dev/null; then
949 echo "SSK: Request key already mounted."
951 mount -o bind $SK_OM_PATH /etc/request-key.d/
953 local lgssc_conf_line='create lgssc * * '
954 lgssc_conf_line+=$(which lgss_keyring)
955 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
957 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
958 echo "$lgssc_conf_line" > $lgssc_conf_file
959 [ -e $lgssc_conf_file ] ||
960 error_exit "Could not find key options in $lgssc_conf_file"
962 if ! local_mode; then
963 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
965 do_nodes $(comma_list $(all_nodes)) "mount \
966 -o bind $SK_OM_PATH \
968 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
969 $HOSTNAME:$lgssc_conf_file \
970 $lgssc_conf_file >/dev/null 2>&1"
973 # create shared key on all nodes
974 mkdir -p $SK_PATH/nodemap
975 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
976 $SK_PATH/$FSNAME-*.key
977 # for nodemap testing each client may need own key,
978 # and S2S now requires keys as well, both for "client"
981 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
982 -w $SK_PATH/$FSNAME-nmclient.key \
983 -d /dev/urandom >/dev/null 2>&1
984 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
985 -w $SK_PATH/$FSNAME-s2s-server.key \
986 -d /dev/urandom >/dev/null 2>&1
989 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
990 -d /dev/urandom >/dev/null 2>&1
992 for i in $(seq 0 $((numclients - 1))); do
993 lgss_sk -t server -f$FSNAME -n c$i \
994 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
998 if ! local_mode; then
999 do_nodes $(comma_list $(all_nodes)) "rsync -av \
1000 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
1002 # Set client keys to client type to generate prime P
1004 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1005 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1007 do_nodes $clients "lgss_sk -t client -m \
1008 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1009 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1010 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1012 # This is required for servers as well, if S2S in use
1014 do_nodes $(comma_list $(mdts_nodes)) \
1015 "cp $SK_PATH/$FSNAME-s2s-server.key \
1016 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1017 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1019 do_nodes $(comma_list $(osts_nodes)) \
1020 "cp $SK_PATH/$FSNAME-s2s-server.key \
1021 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1022 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1024 do_nodes $clients "lgss_sk -t client \
1025 -m $SK_PATH/$FSNAME-nmclient.key \
1030 # mount options for servers and clients
1031 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1032 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1033 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1034 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1038 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
1040 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1047 # maybe cleanup credential cache?
1054 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1055 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1056 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1060 $RPC_MODE || echo "Cleaning up Shared Key.."
1061 do_nodes $(comma_list $(all_nodes)) "rm -f \
1062 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1063 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1064 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1065 # Remove the mount and clean up the files we added to SK_PATH
1066 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1067 request-key.d /proc/mounts; do umount \
1068 /etc/request-key.d/; done"
1069 do_nodes $(comma_list $(all_nodes)) "rm -f \
1070 $SK_OM_PATH/lgssc.conf"
1071 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1078 local var=${facet}_svc
1086 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1087 tr '[:lower:]' '[:upper:]'
1093 if [ $facet == mgs ] || [ $facet == client ]; then
1097 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1105 if [ -n "${!var}" ]; then
1110 var=$(facet_type $facet)FSTYPE
1111 if [ -n "${!var}" ]; then
1116 if [ -n "$FSTYPE" ]; then
1121 if [[ $facet == mgs ]] && combined_mgs_mds; then
1133 local facets=$(get_facets)
1136 for facet in ${facets//,/ }; do
1137 if [ $node == $(facet_host $facet) ] ||
1138 [ $node == "$(facet_failover_host $facet)" ]; then
1139 fstype=$(facet_fstype $facet)
1140 if [[ $fstypes != *$fstype* ]]; then
1141 fstypes+="${fstypes:+,}$fstype"
1150 local num=$(facet_number $facet)
1153 if [[ $(facet_type $facet) = OST ]]; then
1154 index=OSTINDEX${num}
1155 if [[ -n "${!index}" ]]; then
1160 index=${OST_INDICES[num - 1]}
1163 [[ -n "$index" ]] || index=$((num - 1))
1171 local fstype=$(facet_fstype $facet)
1175 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1177 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1178 ${dev} 2>/dev/null");;
1180 error "unknown fstype!";;
1188 local device=$(mdsdevname $num)
1189 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1195 local device=$(ostdevname $num)
1196 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1201 # Get the device of a facet.
1208 mgs) device=$(mgsdevname) ;;
1209 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1210 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1211 fs2mds) device=$(mdsdevname 1_2) ;;
1212 fs2ost) device=$(ostdevname 1_2) ;;
1213 fs3ost) device=$(ostdevname 2_2) ;;
1221 # Get the virtual device of a facet.
1228 mgs) device=$(mgsvdevname) ;;
1229 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1230 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1231 fs2mds) device=$(mdsvdevname 1_2) ;;
1232 fs2ost) device=$(ostvdevname 1_2) ;;
1233 fs3ost) device=$(ostvdevname 2_2) ;;
1241 local virt=$(virt-what 2> /dev/null)
1243 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1245 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1248 VMware|KVM|VirtualBox|Parallels)
1249 echo $virt | tr '[A-Z]' '[a-z]' ;;
1255 # Re-read the partition table on failover partner host.
1256 # After a ZFS storage pool is created on a shared device, the partition table
1257 # on the device may change. However, the operating system on the failover
1258 # host may not notice the change automatically. Without the up-to-date partition
1259 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1260 # relative to partition rather than disk beginnings.
1262 # This function performs partprobe on the failover host to make it re-read the
1265 refresh_partition_table() {
1270 host=$(facet_passive_host $facet)
1271 if [[ -n "$host" ]]; then
1272 do_node $host "$PARTPROBE $device"
1277 # Get ZFS storage pool name.
1284 device=$(facet_device $facet)
1285 # poolname is string before "/"
1286 poolname="${device%%/*}"
1293 # Get ZFS local fsname.
1295 zfs_local_fsname() {
1297 local lfsname=$(basename $(facet_device $facet))
1303 # Create ZFS storage pool.
1310 local opts=${@:-"-o cachefile=none"}
1312 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1313 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1314 $ZPOOL create -f $opts $poolname $vdev"
1318 # Create ZFS file system.
1324 local opts=${@:-"-o mountpoint=legacy"}
1326 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1327 $ZFS create $opts $dataset"
1331 # Export ZFS storage pool.
1332 # Before exporting the pool, all datasets within the pool should be unmounted.
1340 poolname=$(zpool_name $facet)
1342 if [[ -n "$poolname" ]]; then
1343 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1344 grep -q ^$poolname/ /proc/mounts ||
1345 $ZPOOL export $opts $poolname"
1350 # Destroy ZFS storage pool.
1351 # Destroy the given pool and free up any devices for other use. This command
1352 # tries to unmount any active datasets before destroying the pool.
1353 # -f Force any active datasets contained within the pool to be unmounted.
1357 local poolname=${2:-$(zpool_name $facet)}
1359 if [[ -n "$poolname" ]]; then
1360 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1361 $ZPOOL destroy -f $poolname"
1366 # Import ZFS storage pool.
1367 # Force importing, even if the pool appears to be potentially active.
1372 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1375 poolname=$(zpool_name $facet)
1377 if [[ -n "$poolname" ]]; then
1378 opts+=" -d $(dirname $(facet_vdevice $facet))"
1379 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1380 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1381 $ZPOOL import -f $opts $poolname"
1386 # Reimport ZFS storage pool with new name
1391 local opts="-o cachefile=none"
1392 local poolname=$(zpool_name $facet)
1394 opts+=" -d $(dirname $(facet_vdevice $facet))"
1395 do_facet $facet "$ZPOOL export $poolname;
1396 $ZPOOL import $opts $poolname $newpool"
1400 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1401 # is not automatically imported on system startup.
1403 # In a failover environment, this will provide resource level fencing which
1404 # will ensure that the same ZFS storage pool will not be imported concurrently
1405 # on different nodes.
1407 disable_zpool_cache() {
1411 poolname=$(zpool_name $facet)
1413 if [[ -n "$poolname" ]]; then
1414 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1419 # This and set_osd_param() shall be used to access OSD parameters
1420 # once existed under "obdfilter":
1425 # writethrough_cache_enable
1429 local device=${2:-$FSNAME-OST*}
1432 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1433 osd-*.$device.$name 2>&1" | grep -v 'error:'
1438 local device=${2:-$FSNAME-OST*}
1442 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1443 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1447 local dz=${1:-$DEBUG_SIZE}
1449 if [ -f /sys/devices/system/cpu/possible ]; then
1450 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1452 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1455 # bug 19944, adjust size to be -gt num_possible_cpus()
1456 # promise 2MB for every cpu at least
1457 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1460 lctl set_param debug_mb=$dz
1463 set_default_debug () {
1464 local debug=${1:-"$PTLDEBUG"}
1465 local subsys=${2:-"$SUBSYSTEM"}
1466 local debug_size=${3:-$DEBUG_SIZE}
1468 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1469 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1471 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1474 set_default_debug_nodes () {
1477 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1478 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1482 do_rpc_nodes "$nodes" set_default_debug \
1483 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1486 set_default_debug_facet () {
1488 local node=$(facet_active_host $facet)
1489 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1491 set_default_debug_nodes $node
1495 local hostid=${1:-$(hostid)}
1497 if [ ! -s /etc/hostid ]; then
1498 printf $(echo -n $hostid |
1499 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1505 local facets=${1:-$(get_facets)}
1508 for facet in ${facets//,/ }; do
1511 [ $RC -eq 0 ] && continue
1513 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1514 skip_noexit "Restart of $facet failed!." &&
1517 error "Restart of $facet failed!"
1524 # Add argument "arg" (e.g., "loop") to the comma-separated list
1525 # of arguments for option "opt" (e.g., "-o") on command
1526 # line "opts" (e.g., "-o flock").
1532 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1534 if echo "$opts" | grep -q $opt_pattern; then
1535 opts=$(echo "$opts" | sed -e \
1536 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1538 opts+="${opts:+ }$opt $arg"
1544 # Associate loop device with a given regular file.
1545 # Return the loop device.
1547 setup_loop_device() {
1551 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1552 if [[ -z \\\$loop_dev ]]; then
1553 loop_dev=\\\$($LOSETUP -f);
1554 $LOSETUP \\\$loop_dev $file || loop_dev=;
1556 echo -n \\\$loop_dev"
1560 # Detach a loop device.
1562 cleanup_loop_device() {
1566 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1567 $LOSETUP -d $loop_dev"
1571 # Check if a given device is a block device.
1578 [[ -n "$dev" ]] || return 1
1579 do_facet $facet "test -b $dev" || return 1
1580 if [[ -n "$size" ]]; then
1581 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1582 count=1 skip=$size 2>&1" |
1583 awk '($3 == "in") { print $1 }')
1584 [[ "$in" = "1+0" ]] || return 1
1589 # Check if a given device is a device-mapper device.
1595 [[ -n "$dev" ]] || return 1
1596 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1600 # Check if a given device is a device-mapper flakey device.
1602 is_dm_flakey_dev() {
1607 [[ -n "$dev" ]] || return 1
1609 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1611 [[ $type = flakey ]] && return 0 || return 1
1615 # Check if device-mapper flakey device is supported by the kernel
1616 # of $facet node or not.
1618 dm_flakey_supported() {
1622 do_facet $facet "modprobe dm-flakey;
1623 $DMSETUP targets | grep -q flakey" &> /dev/null
1627 # Get the device-mapper flakey device name of a given facet.
1629 dm_facet_devname() {
1631 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1633 echo -n ${facet}_flakey
1637 # Get the device-mapper flakey device of a given facet.
1638 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1640 dm_facet_devpath() {
1643 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1647 # Set a device-mapper device with a new table.
1649 # The table has the following format:
1650 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1652 # flakey <target_args> includes:
1653 # <destination_device> <offset> <up_interval> <down_interval> \
1654 # [<num_features> [<feature_arguments>]]
1656 # linear <target_args> includes:
1657 # <destination_device> <start_sector>
1659 dm_set_dev_table() {
1662 local target_type=$3
1668 read tmp num_sectors tmp real_dev tmp \
1669 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1671 case $target_type in
1673 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1676 table="0 $num_sectors linear $real_dev 0"
1678 *) error "invalid target type $target_type" ;;
1681 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1682 error "failed to suspend $dm_dev"
1683 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1684 error "failed to load $target_type table into $dm_dev"
1685 do_facet $facet "$DMSETUP resume $dm_dev" ||
1686 error "failed to resume $dm_dev"
1690 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1691 # feature parameter.
1694 # All write I/O is silently ignored.
1695 # Read I/O is handled correctly.
1697 dm_set_dev_readonly() {
1699 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1701 dm_set_dev_table $facet $dm_dev flakey
1705 # Set a device-mapper device to traditional linear mapping mode.
1707 dm_clear_dev_readonly() {
1709 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1711 dm_set_dev_table $facet $dm_dev linear
1715 # Set the device of a given facet as "read-only".
1717 set_dev_readonly() {
1719 local svc=${facet}_svc
1721 if [[ $(facet_fstype $facet) = zfs ]] ||
1722 ! dm_flakey_supported $facet; then
1723 do_facet $facet $LCTL --device ${!svc} readonly
1725 dm_set_dev_readonly $facet
1730 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1737 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1738 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1739 echo -n $num_sectors
1743 # Create a device-mapper device with a given block device or regular file (will
1744 # be associated with loop device).
1745 # Return the full path of the device-mapper device.
1749 local real_dev=$2 # destination device
1750 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1751 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1753 # check if the device-mapper device to be created already exists
1754 if is_dm_dev $facet $dm_dev; then
1755 # if the existing device was set to "read-only", then clear it
1756 ! is_dm_flakey_dev $facet $dm_dev ||
1757 dm_clear_dev_readonly $facet $dm_dev
1763 # check if the destination device is a block device, and if not,
1764 # associate it with a loop device
1765 is_blkdev $facet $real_dev ||
1766 real_dev=$(setup_loop_device $facet $real_dev)
1767 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1769 # now create the device-mapper device
1770 local num_sectors=$(get_num_sectors $facet $real_dev)
1771 local table="0 $num_sectors linear $real_dev 0"
1774 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1775 { rc=${PIPESTATUS[0]}; dm_dev=; }
1776 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1783 # Map the facet name to its device variable name.
1785 facet_device_alias() {
1787 local dev_alias=$facet
1790 fs2mds) dev_alias=mds1_2 ;;
1791 fs2ost) dev_alias=ost1_2 ;;
1792 fs3ost) dev_alias=ost2_2 ;;
1800 # Save the original value of the facet device and export the new value.
1806 local active_facet=$(facet_active $facet)
1807 local dev_alias=$(facet_device_alias $active_facet)
1808 local dev_name=${dev_alias}_dev
1809 local dev=${!dev_name}
1811 if [[ $active_facet = $facet ]]; then
1812 local failover_dev=${dev_alias}failover_dev
1813 if [[ ${!failover_dev} = $dev ]]; then
1814 eval export ${failover_dev}_saved=$dev
1815 eval export ${failover_dev}=$dm_dev
1818 dev_alias=$(facet_device_alias $facet)
1819 local facet_dev=${dev_alias}_dev
1820 if [[ ${!facet_dev} = $dev ]]; then
1821 eval export ${facet_dev}_saved=$dev
1822 eval export ${facet_dev}=$dm_dev
1826 eval export ${dev_name}_saved=$dev
1827 eval export ${dev_name}=$dm_dev
1831 # Restore the saved value of the facet device.
1836 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1837 local dev_alias=$(facet_device_alias $facet)
1839 local saved_dev=${dev_alias}_dev_saved
1840 [[ -z ${!saved_dev} ]] ||
1841 eval export ${dev_alias}_dev=${!saved_dev}
1843 saved_dev=${dev_alias}failover_dev_saved
1844 [[ -z ${!saved_dev} ]] ||
1845 eval export ${dev_alias}failover_dev=${!saved_dev}
1849 # Remove a device-mapper device.
1850 # If the destination device is a loop device, then also detach it.
1854 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1858 is_dm_dev $facet $dm_dev || return 0
1860 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
1861 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
1863 do_facet $facet "$DMSETUP remove $dm_dev"
1864 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1866 unexport_dm_dev $facet
1868 # detach a loop device
1869 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
1871 # unload dm-flakey module
1872 do_facet $facet "modprobe -r dm-flakey" || true
1878 local active_facet=$(facet_active $facet)
1879 local dev_alias=$(facet_device_alias $active_facet)
1880 local dev=${dev_alias}_dev
1881 local opt=${facet}_opt
1882 local mntpt=$(facet_mntpt $facet)
1883 local opts="${!opt} $@"
1884 local fstype=$(facet_fstype $facet)
1886 local dm_dev=${!dev}
1888 module_loaded lustre || load_modules
1892 if dm_flakey_supported $facet; then
1893 dm_dev=$(dm_create_dev $facet ${!dev})
1894 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
1897 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
1899 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
1901 # import ZFS storage pool
1902 import_zpool $facet || return ${PIPESTATUS[0]}
1904 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1905 lustre:svname $dm_dev");;
1907 error "unknown fstype!";;
1910 echo "Starting ${facet}: $opts $dm_dev $mntpt"
1911 # for testing LU-482 error handling in mount_facets() and test_0a()
1912 if [ -f $TMP/test-lu482-trigger ]; then
1916 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
1920 if [ $RC -ne 0 ]; then
1921 echo "Start of $dm_dev on ${facet} failed ${RC}"
1925 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1926 if [[ "$health" != "healthy" ]]; then
1927 error "$facet is in a unhealthy state"
1930 set_default_debug_facet $facet
1932 if [[ $facet == mds* ]]; then
1934 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1937 if [[ $opts =~ .*nosvc.* ]]; then
1938 echo "Start $dm_dev without service"
1943 wait_update_facet ${facet} "$E2LABEL $dm_dev \
1944 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1945 "" || error "$dm_dev failed to initialize!";;
1947 wait_update_facet ${facet} "$ZFS get -H -o value \
1948 lustre:svname $dm_dev 2>/dev/null | \
1949 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1950 error "$dm_dev failed to initialize!";;
1953 error "unknown fstype!";;
1957 # commit the device label change to disk
1958 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1959 echo "Commit the device label on ${!dev}"
1960 do_facet $facet "sync; sleep 1; sync"
1964 label=$(devicelabel ${facet} $dm_dev)
1965 [ -z "$label" ] && echo no label for $dm_dev && exit 1
1966 eval export ${facet}_svc=${label}
1967 echo Started ${label}
1969 export_dm_dev $facet $dm_dev
1974 # start facet device options
1980 local dev_alias=$(facet_device_alias $facet)
1982 eval export ${dev_alias}_dev=${device}
1983 eval export ${facet}_opt=\"$@\"
1985 local varname=${dev_alias}failover_dev
1986 if [ -n "${!varname}" ] ; then
1987 eval export ${dev_alias}failover_dev=${!varname}
1989 eval export ${dev_alias}failover_dev=$device
1992 local mntpt=$(facet_mntpt $facet)
1993 do_facet ${facet} mkdir -p $mntpt
1994 eval export ${facet}_MOUNT=$mntpt
1995 mount_facet ${facet}
1998 if [[ $facet == mds* ]]; then
2000 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
2011 local HOST=$(facet_active_host $facet)
2012 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2014 local mntpt=$(facet_mntpt $facet)
2015 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2016 if [ ${running} -ne 0 ]; then
2017 echo "Stopping $mntpt (opts:$@) on $HOST"
2018 do_facet ${facet} $UMOUNT $@ $mntpt
2021 # umount should block, but we should wait for unrelated obd's
2022 # like the MGS or MGC to also stop.
2023 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2025 if [[ $(facet_fstype $facet) == zfs ]]; then
2026 # export ZFS storage pool
2027 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2028 elif dm_flakey_supported $facet; then
2029 local host=${facet}_HOST
2030 local failover_host=${facet}failover_HOST
2031 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2032 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2033 dm_cleanup_dev $facet
2038 # get mdt quota type
2040 local varsvc=${SINGLEMDS}_svc
2041 do_facet $SINGLEMDS $LCTL get_param -n \
2042 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2045 # get ost quota type
2047 # All OSTs should have same quota type
2048 local varsvc=ost1_svc
2049 do_facet ost1 $LCTL get_param -n \
2050 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2053 # restore old quota type settings
2055 if [ "$old_MDT_QUOTA_TYPE" ]; then
2056 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2057 do_facet mgs $PERM_CMD \
2058 osd-*.$FSNAME-MDT*.quota_slave.enable = \
2061 do_facet mgs $PERM_CMD \
2062 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2065 if [ "$old_OST_QUOTA_TYPE" ]; then
2066 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2067 do_facet mgs $PERM_CMD \
2068 osd-*.$FSNAME-OST*.quota_slave.enable = \
2071 do_facet mgs $LCTL conf_param \
2072 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2077 # Handle the case when there is a space in the lfs df
2078 # "filesystem summary" line the same as when there is no space.
2079 # This will allow fixing the "lfs df" summary line in the future.
2081 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2084 # Get free inodes on the MDT specified by mdt index, free indoes on
2085 # the whole filesystem will be returned when index == -1.
2091 if [ $index -eq -1 ]; then
2094 mdt_uuid=$(mdtuuid_from_index $index)
2097 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2102 # Get the OST device status from 'lfs df' with a given OST index.
2106 local mnt_pnt=${2:-$MOUNT}
2109 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2110 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2116 # save old quota type & set new quota type
2117 local mdt_qtype=$(mdt_quota_type)
2118 local ost_qtype=$(ost_quota_type)
2120 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2121 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2123 export old_MDT_QUOTA_TYPE=$mdt_qtype
2124 export old_OST_QUOTA_TYPE=$ost_qtype
2126 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2127 do_facet mgs $PERM_CMD \
2128 osd-*.$FSNAME-MDT*.quota_slave.enable=$QUOTA_TYPE
2129 do_facet mgs $PERM_CMD \
2130 osd-*.$FSNAME-OST*.quota_slave.enable=$QUOTA_TYPE
2132 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2133 error "set mdt quota type failed"
2134 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2135 error "set ost quota type failed"
2138 local quota_usrs=$QUOTA_USERS
2140 # get_filesystem_size
2141 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2142 local blk_soft=$((disksz + 1024))
2143 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2145 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2146 local i_soft=$inodes
2147 local i_hard=$((i_soft + i_soft / 20))
2149 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2150 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2151 "inode-hardlimit: $i_hard"
2154 for usr in $quota_usrs; do
2155 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2157 cmd="$LFS setquota -$type $usr -b $blk_soft"
2158 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2160 eval $cmd || error "$cmd FAILED!"
2162 # display the quota status
2163 echo "Quota settings for $usr : "
2164 $LFS quota -v -u $usr $mntpt || true
2171 local opts=${3:-$MOUNT_OPTS}
2172 opts=${opts:+-o $opts}
2173 local flags=${4:-$MOUNT_FLAGS}
2175 local device=$MGSNID:/$FSNAME$FILESET
2176 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2177 echo "Bad mount command: opt=$flags $opts dev=$device " \
2182 echo "Starting client: $client: $flags $opts $device $mnt"
2183 do_node $client mkdir -p $mnt
2184 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2185 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2187 #disable FILESET if not supported
2188 do_nodes $client lctl get_param -n \
2189 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2190 device=$MGSNID:/$FSNAME
2191 do_node $client mkdir -p $mnt/$FILESET
2192 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2195 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2196 # Mount using nodemap key
2197 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2198 if $SK_UNIQUE_NM; then
2199 mountkey=$SK_PATH/nodemap/c0.key
2201 local prunedopts=$(echo $opts |
2202 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2203 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2206 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2210 set_default_debug_nodes $client
2222 [ "$3" ] && force=-f
2223 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2224 if [ $running -ne 0 ]; then
2225 echo "Stopping client $client $mnt (opts:$force)"
2226 do_node $client lsof -t $mnt || need_kill=no
2227 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
2228 pids=$(do_node $client lsof -t $mnt | sort -u);
2229 if [ -n $pids ]; then
2230 do_node $client kill -9 $pids || true
2234 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
2235 if [ $busy -ne 0 ] ; then
2236 echo "$mnt is still busy, wait one second" && sleep 1
2237 do_node $client umount $force $mnt
2242 # Mount the file system on the MGS
2243 mount_mgs_client() {
2244 do_facet mgs "mkdir -p $MOUNT"
2245 zconf_mount $mgs_HOST $MOUNT $MOUNT_OPTS ||
2246 error "unable to mount $MOUNT on MGS"
2249 # Unmount the file system on the MGS
2250 umount_mgs_client() {
2251 zconf_umount $mgs_HOST $MOUNT
2252 do_facet mgs "rm -rf $MOUNT"
2255 # nodes is comma list
2256 sanity_mount_check_nodes () {
2262 # FIXME: assume that all cluster nodes run the same os
2263 [ "$(uname)" = Linux ] || return 0
2266 for mnt in $mnts ; do
2267 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2268 mpts=\\\$(mount | grep -c $mnt' ');
2269 if [ \\\$running -ne \\\$mpts ]; then
2270 echo \\\$(hostname) env are INSANE!;
2273 [ $? -eq 0 ] || rc=1
2278 sanity_mount_check_servers () {
2279 [ -n "$CLIENTONLY" ] &&
2280 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2281 echo Checking servers environments
2283 # FIXME: modify get_facets to display all facets wo params
2284 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2288 for facet in ${facets//,/ }; do
2289 node=$(facet_host ${facet})
2290 mntpt=$(facet_mntpt $facet)
2291 sanity_mount_check_nodes $node $mntpt ||
2292 { error "server $node environments are insane!"; return 1; }
2296 sanity_mount_check_clients () {
2297 local clients=${1:-$CLIENTS}
2298 local mntpt=${2:-$MOUNT}
2299 local mntpt2=${3:-$MOUNT2}
2301 [ -z $clients ] && clients=$(hostname)
2302 echo Checking clients $clients environments
2304 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2305 error "clients environments are insane!"
2308 sanity_mount_check () {
2309 sanity_mount_check_servers || return 1
2310 sanity_mount_check_clients || return 2
2313 # mount clients if not mouted
2314 zconf_mount_clients() {
2317 local opts=${3:-$MOUNT_OPTS}
2318 opts=${opts:+-o $opts}
2319 local flags=${4:-$MOUNT_FLAGS}
2320 local device=$MGSNID:/$FSNAME$FILESET
2321 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2322 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2327 echo "Starting client $clients: $flags $opts $device $mnt"
2328 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
2329 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2330 # Mount with own nodemap key
2332 # Mount all server nodes first with per-NM keys
2333 for nmclient in ${clients//,/ }; do
2334 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2335 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2338 # set perms for per-nodemap keys else permission denied
2339 do_nodes $(comma_list $(all_nodes)) \
2340 "keyctl show | grep lustre | cut -c1-11 |
2342 xargs -IX keyctl setperm X 0x3f3f3f3f"
2343 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2345 for nmclient in ${clients//,/ }; do
2346 if $SK_UNIQUE_NM; then
2347 mountkey=$SK_PATH/nodemap/c$i.key
2349 do_node $nmclient "! grep -q $mnt' ' \
2350 /proc/mounts || umount $mnt"
2351 local prunedopts=$(add_sk_mntflag $prunedopts);
2352 prunedopts=$(echo $prunedopts | sed -e \
2353 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2355 do_nodes $(comma_list $(all_server_nodes)) \
2358 do_node $nmclient $MOUNT_CMD $flags \
2359 $prunedopts $MGSNID:/$FSNAME $mnt ||
2364 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2366 do_nodes $clients $MOUNT_CMD $flags $opts \
2367 $MGSNID:/$FSNAME $mnt || return 1
2369 #disable FILESET if not supported
2370 do_nodes $clients lctl get_param -n \
2371 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2372 device=$MGSNID:/$FSNAME
2373 do_nodes $clients mkdir -p $mnt/$FILESET
2374 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2378 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2379 # Mount with nodemap key
2381 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2382 for nmclient in ${clients//,/ }; do
2383 if $SK_UNIQUE_NM; then
2384 mountkey=$SK_PATH/nodemap/c$i.key
2386 local prunedopts=$(echo $opts | sed -e \
2387 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2388 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2391 running=\\\$(mount | grep -c $mnt' ');
2393 if [ \\\$running -eq 0 ] ; then
2395 $MOUNT_CMD $flags $prunedopts $device $mnt;
2398 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2399 grep 'type lustre' | wc -l);
2400 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2401 echo zconf_mount_clients FAILED: \
2402 mount count \\\$running, not matching \
2403 with mount count of 'type lustre' \
2404 \\\$lustre_mnt_count;
2408 exit \\\$rc" || return ${PIPESTATUS[0]}
2415 if $SHARED_KEY; then
2416 tmpopts=$(add_sk_mntflag $opts)
2419 running=\\\$(mount | grep -c $mnt' ');
2421 if [ \\\$running -eq 0 ] ; then
2423 $MOUNT_CMD $flags $tmpopts $device $mnt;
2426 exit \\\$rc" || return ${PIPESTATUS[0]}
2429 echo "Started clients $clients: "
2430 do_nodes $clients "mount | grep $mnt' '"
2432 set_default_debug_nodes $clients
2437 zconf_umount_clients() {
2442 [ "$3" ] && force=-f
2444 echo "Stopping clients: $clients $mnt (opts:$force)"
2445 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2446 if [ \\\$running -ne 0 ] ; then
2447 echo Stopping client \\\$(hostname) $mnt opts:$force;
2448 lsof $mnt || need_kill=no;
2449 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2450 pids=\\\$(lsof -t $mnt | sort -u);
2451 if [ -n \\\"\\\$pids\\\" ]; then
2455 while umount $force $mnt 2>&1 | grep -q "busy"; do
2456 echo "$mnt is still busy, wait one second" && sleep 1;
2463 echo + $POWER_DOWN $node
2467 shutdown_node_hard () {
2469 local attempts=$SHUTDOWN_ATTEMPTS
2471 for i in $(seq $attempts) ; do
2474 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2475 echo "waiting for $host to fail attempts=$attempts"
2476 [ $i -lt $attempts ] || \
2477 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2483 local mnt=${2:-$MOUNT}
2486 if [ "$FAILURE_MODE" = HARD ]; then
2487 shutdown_node_hard $client
2489 zconf_umount_clients $client $mnt -f
2495 local facets="$(get_facets OST),$(get_facets MDS)"
2498 combined_mgs_mds || facets="$facets,mgs"
2500 for facet in ${facets//,/ }; do
2501 if [ $(facet_active_host $facet) == $host ]; then
2502 affected="$affected $facet"
2506 echo $(comma_list $affected)
2511 local host=${2:-$(facet_host $facet)}
2513 local label=$(convert_facet2label $facet)
2514 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2517 facets_up_on_host () {
2519 local facets=$(facets_on_host $host)
2522 for facet in ${facets//,/ }; do
2523 if $(facet_up $facet $host); then
2524 affected_up="$affected_up $facet"
2528 echo $(comma_list $affected_up)
2533 local affected_facet
2534 local affected_facets
2536 if [[ "$FAILURE_MODE" = HARD ]]; then
2537 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2538 dm_flakey_supported $facet; then
2539 affected_facets=$(affected_facets $facet)
2540 for affected_facet in ${affected_facets//,/ }; do
2541 unexport_dm_dev $affected_facet
2545 shutdown_node_hard $(facet_active_host $facet)
2553 echo + $POWER_UP $node
2566 if [ "$FAILURE_MODE" = HARD ]; then
2567 reboot_node $(facet_active_host $facet)
2575 if [ "$FAILURE_MODE" = HARD ]; then
2585 for facet in ${facets//,/ }; do
2586 hosts=$(expand_list $hosts $(facet_host $facet) )
2592 _check_progs_installed () {
2596 for prog in $progs; do
2597 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2598 echo $prog missing on $(hostname)
2605 check_progs_installed () {
2609 do_rpc_nodes "$nodes" _check_progs_installed $@
2612 # recovery-scale functions
2614 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2617 start_client_load() {
2620 local var=$(node_var_name $client)_load
2621 eval export ${var}=$load
2623 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2624 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2625 END_RUN_FILE=$END_RUN_FILE \
2626 LOAD_PID_FILE=$LOAD_PID_FILE \
2627 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2628 TESTNAME=$TESTNAME \
2629 DBENCH_LIB=$DBENCH_LIB \
2630 DBENCH_SRC=$DBENCH_SRC \
2631 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2637 log "Started client load: ${load} on $client"
2639 # get the children process IDs
2640 local pids=$(ps --ppid $ppid -o pid= | xargs)
2641 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2645 start_client_loads () {
2646 local -a clients=(${1//,/ })
2647 local numloads=${#CLIENT_LOADS[@]}
2650 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2651 testnum=$((nodenum % numloads))
2652 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2654 # bug 22169: wait the background threads to start
2658 # only for remote client
2659 check_client_load () {
2661 local var=$(node_var_name $client)_load
2662 local testload=run_${!var}.sh
2664 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2666 # bug 18914: try to connect several times not only when
2667 # check ps, but while check_node_health also
2671 while [ $RC = 254 -a $tries -gt 0 ]; do
2675 if ! check_node_health $client; then
2677 if [ $RC -eq 254 ]; then
2678 # FIXME: not sure how long we shuold sleep here
2682 echo "check node health failed: RC=$RC "
2686 # We can continue try to connect if RC=254
2687 # Just print the warning about this
2688 if [ $RC = 254 ]; then
2689 echo "got a return status of $RC from do_node while checking " \
2690 "node health on $client"
2693 # see if the load is still on the client
2696 while [ $RC = 254 -a $tries -gt 0 ]; do
2700 if ! do_node $client \
2701 "ps auxwww | grep -v grep | grep -q $testload"; then
2706 if [ $RC = 254 ]; then
2707 echo "got a return status of $RC from do_node while checking " \
2708 "(node health and 'ps') the client load on $client"
2709 # see if we can diagnose a bit why this is
2714 check_client_loads () {
2715 local clients=${1//,/ }
2719 for client in $clients; do
2720 check_client_load $client
2722 if [ "$rc" != 0 ]; then
2723 log "Client load failed on node $client, rc=$rc"
2729 restart_client_loads () {
2730 local clients=${1//,/ }
2731 local expectedfail=${2:-""}
2735 for client in $clients; do
2736 check_client_load $client
2738 if [ "$rc" != 0 -a "$expectedfail" ]; then
2739 local var=$(node_var_name $client)_load
2740 start_client_load $client ${!var}
2741 echo "Restarted client load ${!var}: on $client. Checking ..."
2742 check_client_load $client
2744 if [ "$rc" != 0 ]; then
2745 log "Client load failed to restart on node $client, rc=$rc"
2746 # failure one client load means test fail
2747 # we do not need to check other
2756 # Start vmstat and save its process ID in a file.
2761 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2764 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2765 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2768 # Display the nodes on which client loads failed.
2769 print_end_run_file() {
2773 [ -s $file ] || return 0
2775 echo "Found the END_RUN_FILE file: $file"
2778 # A client load will stop if it finds the END_RUN_FILE file.
2779 # That does not mean the client load actually failed though.
2780 # The first node in END_RUN_FILE is the one we are interested in.
2783 if [ -n "$node" ]; then
2784 local var=$(node_var_name $node)_load
2786 local prefix=$TESTLOG_PREFIX
2787 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2788 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2789 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2791 echo "Client load ${!var} failed on node $node:"
2797 # Stop the process which had its PID saved in a file.
2802 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2804 do_nodes $nodes "test -f $pid_file &&
2805 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2808 # Stop all client loads.
2809 stop_client_loads() {
2810 local nodes=${1:-$CLIENTS}
2813 # stop the client loads
2814 stop_process $nodes $pid_file
2816 # clean up the processes that started them
2817 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2819 # End recovery-scale functions
2821 # verify that lustre actually cleaned up properly
2823 VAR=$(lctl get_param -n catastrophe 2>&1)
2824 if [ $? = 0 ] ; then
2825 if [ $VAR != 0 ]; then
2826 error "LBUG/LASSERT detected"
2829 BUSY=$(dmesg | grep -i destruct || true)
2830 if [ -n "$BUSY" ]; then
2832 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2836 check_mem_leak || exit 204
2838 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2839 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2842 if module_loaded lnet || module_loaded libcfs; then
2843 echo "$TESTSUITE: modules still loaded..." 1>&2
2852 if [[ "$1" == "--verbose" ]]; then
2867 PREV_RESULT=$(do_node $node "$TEST")
2869 RESULT=$(do_node $node "$TEST")
2870 if [[ "$RESULT" == "$FINAL" ]]; then
2871 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2872 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2876 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2877 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2881 [[ $WAIT -ge $MAX ]] && break
2882 [[ $((WAIT % print)) -eq 0 ]] &&
2883 echo "Waiting $((MAX - WAIT)) secs for update"
2884 WAIT=$((WAIT + sleep))
2887 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2891 wait_update_facet() {
2893 [ "$1" = "--verbose" ] && verbose="$1" && shift
2897 wait_update $verbose $(facet_active_host $facet) "$@"
2901 do_nodes $(comma_list $(mdts_nodes)) \
2902 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
2903 do_nodes $(comma_list $(osts_nodes)) \
2904 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2905 grep -v 'Found no match'
2909 local zfs_wait=${2:-5}
2911 # the occupied disk space will be released
2912 # only after TXGs are committed
2913 if [[ $(facet_fstype $1) == zfs ]]; then
2914 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
2919 wait_delete_completed_mds() {
2920 local max_wait=${1:-20}
2922 local stime=$(date +%s)
2927 # find MDS with pending deletions
2928 for node in $(mdts_nodes); do
2929 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2930 2>/dev/null | calc_sum)
2931 if [[ $changes -eq 0 ]]; then
2934 mds2sync="$mds2sync $node"
2936 if [ -z "$mds2sync" ]; then
2937 wait_zfs_commit $SINGLEMDS
2940 mds2sync=$(comma_list $mds2sync)
2942 # sync MDS transactions
2943 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
2945 # wait till all changes are sent and commmitted by OSTs
2946 # for ldiskfs space is released upon execution, but DMU
2947 # do this upon commit
2950 while [[ $WAIT -ne $max_wait ]]; do
2951 changes=$(do_nodes $mds2sync \
2952 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2953 #echo "$node: $changes changes on all"
2954 if [[ $changes -eq 0 ]]; then
2955 wait_zfs_commit $SINGLEMDS
2957 # the occupied disk space will be released
2958 # only after TXGs are committed
2959 wait_zfs_commit ost1
2967 echo "Delete is not completed in $((etime - stime)) seconds"
2968 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2975 # we can use "for" here because we are waiting the slowest
2976 for host in ${hostlist//,/ }; do
2977 check_network "$host" 900
2979 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2986 for facet in ${facetlist//,/ }; do
2987 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2989 wait_for_host $hostlist
2992 _wait_recovery_complete () {
2995 # Use default policy if $2 is not passed by caller.
2996 local MAX=${2:-$(max_recovery_time)}
3001 while [ $WAIT -lt $MAX ]; do
3002 STATUS=$(lctl get_param -n $param | grep status)
3004 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
3007 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3009 echo "$param recovery not done in $MAX sec. $STATUS"
3013 wait_recovery_complete () {
3016 # with an assumption that at_max is the same on all nodes
3017 local MAX=${2:-$(max_recovery_time)}
3020 if [ "$FAILURE_MODE" = HARD ]; then
3021 facets=$(facets_on_host $(facet_active_host $facet))
3023 echo affected facets: $facets
3025 # we can use "for" here because we are waiting the slowest
3026 for facet in ${facets//,/ }; do
3027 local var_svc=${facet}_svc
3028 local param="*.${!var_svc}.recovery_status"
3030 local host=$(facet_active_host $facet)
3031 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3035 wait_mds_ost_sync () {
3036 # just because recovery is done doesn't mean we've finished
3037 # orphan cleanup. Wait for llogs to get synchronized.
3038 echo "Waiting for orphan cleanup..."
3039 # MAX value includes time needed for MDS-OST reconnection
3040 local MAX=$(( TIMEOUT * 2 ))
3041 local WAIT_TIMEOUT=${1:-$MAX}
3044 local list=$(comma_list $(mdts_nodes))
3045 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3046 if ! do_facet $SINGLEMDS \
3047 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3049 # old way, use mds_sync
3051 list=$(comma_list $(osts_nodes))
3052 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3055 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3056 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3057 local -a sync=($(do_nodes $list "$cmd"))
3060 for ((i=0; i<${#sync[@]}; i++)); do
3062 [ ${sync[$i]} -eq 1 ] && continue
3064 [ ${sync[$i]} -eq 0 ] && continue
3066 # there is a not finished MDS-OST synchronization
3070 sleep 2 # increase waiting time and cover statfs cache
3071 [ ${con} -eq 1 ] && return 0
3072 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3076 # show which nodes are not finished.
3077 cmd=$(echo $cmd | sed 's/-n//')
3078 do_nodes $list "$cmd"
3079 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3083 # Wait OSTs to be active on both client and MDT side.
3085 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3086 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3087 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3088 error "wait_update OSTs up on client failed"
3090 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3091 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3092 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3093 error "wait_update OSTs up on MDT0000 failed"
3096 wait_destroy_complete () {
3097 echo "Waiting for local destroys to complete"
3098 # MAX value shouldn't be big as this mean server responsiveness
3099 # never increase this just to make test pass but investigate
3100 # why it takes so long time
3103 while [ $WAIT -lt $MAX ]; do
3104 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
3108 for ((i=0; i<${#RPCs[@]}; i++)); do
3109 [ ${RPCs[$i]} -eq 0 ] && continue
3110 # there are still some destroy RPCs in flight
3115 [ ${con} -eq 1 ] && return 0 # done waiting
3116 echo "Waiting ${WAIT}s for local destroys to complete"
3119 echo "Local destroys weren't done in $MAX sec."
3123 wait_delete_completed() {
3124 wait_delete_completed_mds $1 || return $?
3125 wait_destroy_complete || return $?
3134 # conf-sanity 31 takes a long time cleanup
3135 while [ $WAIT -lt 300 ]; do
3136 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3137 lctl dl | grep ' ST ' || true")
3138 [ -z "${running}" ] && return 0
3139 echo "waited $WAIT for${running}"
3140 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3142 WAIT=$((WAIT + INTERVAL))
3144 echo "service didn't stop after $WAIT seconds. Still running:"
3149 wait_remote_prog () {
3155 [ "$PDSH" = "no_dsh" ] && return 0
3157 while [ $WAIT -lt $2 ]; do
3158 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3159 [ -z "${running}" ] && return 0 || true
3160 echo "waited $WAIT for: "
3162 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3164 WAIT=$((WAIT + INTERVAL))
3166 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3167 [ -z "$pids" ] && return 0
3168 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3169 # FIXME: not portable
3170 for pid in $pids; do
3171 cat /proc/${pid}/status || true
3172 cat /proc/${pid}/wchan || true
3174 kill -9 $pid || true
3183 local clients=${1:-$CLIENTS}
3185 if [ -z "$clients" ]; then
3188 $PDSH $clients "$LFS df $MOUNT" > /dev/null
3193 # not every config has many clients
3199 # usually checked on particular client or locally
3208 client_reconnect_try() {
3209 local f=$MOUNT/recon
3212 if [ -z "$CLIENTS" ]; then
3213 $LFS df $MOUNT; uname -n >> $f
3215 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3217 echo "Connected clients: $(cat $f)"
3218 ls -l $f > /dev/null
3222 client_reconnect() {
3223 # one client_reconnect_try call does not always do the job...
3225 client_reconnect_try && break
3230 affected_facets () {
3233 local host=$(facet_active_host $facet)
3234 local affected=$facet
3236 if [ "$FAILURE_MODE" = HARD ]; then
3237 affected=$(facets_up_on_host $host)
3243 local E2FSCK_ON_MDT0=false
3244 if [ "$1" == "--fsck" ]; then
3246 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3258 #Because it will only get up facets, we need get affected
3259 #facets before shutdown
3260 #For HARD Failure mode, it needs make sure facets on the same
3261 #HOST will only be shutdown and reboot once
3262 for facet in ${facets//,/ }; do
3263 local affected_facet
3265 #check whether facet has been included in other affected facets
3266 for ((index=0; index<$total; index++)); do
3267 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
3270 if [ $skip -eq 0 ]; then
3271 affecteds[$total]=$(affected_facets $facet)
3276 for ((index=0; index<$total; index++)); do
3277 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3278 local host=$(facet_active_host $facet)
3279 echo "Failing ${affecteds[index]} on $host"
3280 shutdown_facet $facet
3283 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3284 $(mdsdevname 1) "-n" || error "Running e2fsck")
3286 for ((index=0; index<$total; index++)); do
3287 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3288 echo reboot facets: ${affecteds[index]}
3292 change_active ${affecteds[index]}
3294 wait_for_facet ${affecteds[index]}
3295 # start mgs first if it is affected
3296 if ! combined_mgs_mds &&
3297 list_member ${affecteds[index]} mgs; then
3298 mount_facet mgs || error "Restart of mgs failed"
3300 # FIXME; has to be changed to mount all facets concurrently
3301 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
3302 echo mount facets: ${affecteds[index]}
3303 mount_facets ${affecteds[index]}
3313 do_facet $facet "sync; sync; sync"
3316 # make sure there will be no seq change
3317 local clients=${CLIENTS:-$HOSTNAME}
3318 local f=fsa-\\\$\(hostname\)
3319 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
3320 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
3322 local svc=${facet}_svc
3323 do_facet $facet $LCTL --device ${!svc} notransno
3325 # If a ZFS OSD is made read-only here, its pool is "freezed". This
3326 # in-memory state has to be cleared by either rebooting the host or
3327 # exporting and reimporting the pool.
3329 # Although the uberblocks are not updated when a pool is freezed,
3330 # transactions are still written to the disks. Modified blocks may be
3331 # cached in memory when tests try reading them back. The
3332 # export-and-reimport process also evicts any cached pool data from
3333 # memory to provide the correct "data loss" semantics.
3335 # In the test framework, the exporting and importing operations are
3336 # handled by stop() and mount_facet() separately, which are used
3337 # inside fail() and fail_abort().
3339 set_dev_readonly $facet
3340 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3341 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3344 replay_barrier_nodf() {
3345 local facet=$1 echo running=${running}
3346 do_facet $facet "sync; sync; sync"
3347 local svc=${facet}_svc
3348 echo Replay barrier on ${!svc}
3349 do_facet $facet $LCTL --device ${!svc} notransno
3350 set_dev_readonly $facet
3351 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3352 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3355 replay_barrier_nosync() {
3356 local facet=$1 echo running=${running}
3357 local svc=${facet}_svc
3358 echo Replay barrier on ${!svc}
3359 do_facet $facet $LCTL --device ${!svc} notransno
3360 set_dev_readonly $facet
3361 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3362 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3366 # Get Lustre client uuid for a given Lustre mount point.
3369 local mntpnt=${1:-$MOUNT}
3371 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
3372 local uuid=$($LCTL get_param -n llite.$name.uuid)
3377 mds_evict_client() {
3378 local mntpnt=${1:-$MOUNT}
3379 local uuid=$(get_client_uuid $mntpnt)
3381 do_facet $SINGLEMDS \
3382 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
3385 ost_evict_client() {
3386 local mntpnt=${1:-$MOUNT}
3387 local uuid=$(get_client_uuid $mntpnt)
3390 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
3395 local clients=${CLIENTS:-$HOSTNAME}
3397 facet_failover $* || error "failover: $?"
3398 # to initiate all OSC idling connections
3400 wait_clients_import_state "$clients" "$facets" "\(FULL\|IDLE\)"
3401 clients_up || error "post-failover stat: $?"
3406 facet_failover $facet
3412 change_active $facet
3413 wait_for_facet $facet
3414 mount_facet $facet -o abort_recovery
3415 clients_up || echo "first stat failed: $?"
3416 clients_up || error "post-failover stat: $?"
3419 host_nids_address() {
3423 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
3427 if [ "$1" = "'*'" ]; then echo \'*\'; else
3433 if [[ -n "$NETTYPE" ]]; then
3434 h2name_or_ip "$1" "$NETTYPE"
3436 h2name_or_ip "$1" "$2"
3439 declare -fx h2nettype
3441 # Wrapper function to print the deprecation warning
3443 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3444 if [[ -n "$NETTYPE" ]]; then
3447 h2nettype "$1" "tcp"
3451 # Wrapper function to print the deprecation warning
3453 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3454 if [[ -n "$NETTYPE" ]]; then
3457 h2nettype "$1" "o2ib"
3461 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3462 # expressions format. As a bonus we can then just pass in those variables
3463 # to pdsh. What this function does is take a HOSTLIST type string and
3464 # expand it into a space deliminated list for us.
3472 [ -z "$hostlist" ] && return
3474 # Translate the case of [..],..,[..] to [..] .. [..]
3475 list="${hostlist/],/] }"
3477 [[ "$front" == *,* ]] && {
3480 list=${list/${old}/${new}}
3483 for item in $list; do
3484 # Test if we have any []'s at all
3485 if [ "$item" != "${item/\[/}" ]; then {
3486 # Expand the [*] into list
3490 if [ "$name" != "$item" ]; then
3491 group=${item#$name[*}
3494 for range in ${group//,/ }; do
3500 # Number of leading zeros
3503 end=$(echo $end | sed 's/0*//')
3504 [[ -z "$end" ]] && end=0
3505 [[ $padlen2 -gt $padlen ]] && {
3506 [[ $padlen2 -eq ${#end} ]] && padlen2=0
3509 begin=$(echo $begin | sed 's/0*//')
3510 [ -z $begin ] && begin=0
3512 if [ ! -z "${begin##[!0-9]*}" ]; then
3513 order=$(seq -f "%0${padlen}g" $begin $end)
3515 order=$(eval echo {$begin..$end});
3518 for num in $order; do
3519 value="${name#*,}${num}${back}"
3520 [ "$value" != "${value/\[/}" ] && {
3521 value=$(hostlist_expand "$value")
3523 myList="$myList $value"
3528 myList="$myList $item"
3531 myList=${myList//,/ }
3532 myList=${myList:1} # Remove first character which is a space
3534 # Filter any duplicates without sorting
3536 myList="${list%% *}"
3538 while [[ "$list" != ${myList##* } ]]; do
3539 local tlist=" $list"
3540 list=${tlist// ${list%% *} / }
3542 myList="$myList ${list%% *}"
3544 myList="${myList%* }";
3546 # We can select an object at an offset in the list
3549 for item in $myList; do
3551 [ $cnt -eq $offset ] && {
3555 [ $(get_node_count $myList) -ne 1 ] && myList=""
3564 [ "$facet" == client ] && echo -n $HOSTNAME && return
3565 varname=${facet}_HOST
3566 if [ -z "${!varname}" ]; then
3567 if [ "${facet:0:3}" == "ost" ]; then
3568 local fh=${facet%failover}_HOST
3569 eval export ${facet}_HOST=${!fh}
3570 if [ -z "${!varname}" ]; then
3571 eval export ${facet}_HOST=${ost_HOST}
3573 elif [ "${facet:0:3}" == "mdt" -o \
3574 "${facet:0:3}" == "mds" -o \
3575 "${facet:0:3}" == "mgs" ]; then
3576 eval export ${facet}_HOST=${mds_HOST}
3582 facet_failover_host() {
3586 var=${facet}failover_HOST
3587 if [ -n "${!var}" ]; then
3592 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
3593 "${facet:0:3}" == "mgs" ]; then
3595 eval export ${facet}failover_host=${mds_HOST}
3600 if [[ $facet == ost* ]]; then
3601 eval export ${facet}failover_host=${ost_HOST}
3609 local activevar=${facet}active
3611 if [ -f $TMP/${facet}active ] ; then
3612 source $TMP/${facet}active
3615 active=${!activevar}
3616 if [ -z "$active" ] ; then
3623 facet_active_host() {
3624 facet_host $(facet_active $1)
3627 # Get the passive failover partner host of facet.
3628 facet_passive_host() {
3630 [[ $facet = client ]] && return
3632 local host=${facet}_HOST
3633 local failover_host=${facet}failover_HOST
3634 local active_host=$(facet_active_host $facet)
3636 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
3638 if [[ $active_host = ${!host} ]]; then
3639 echo -n ${!failover_host}
3649 facetlist=$(exclude_items_from_list $facetlist mgs)
3651 for facet in ${facetlist//,/ }; do
3652 local failover=${facet}failover
3653 local host=`facet_host $failover`
3654 [ -z "$host" ] && return
3656 local curactive=`facet_active $facet`
3657 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3658 eval export ${facet}active=$facet
3660 eval export ${facet}active=$failover
3662 # save the active host for this facet
3663 local activevar=${facet}active
3664 echo "$activevar=${!activevar}" > $TMP/$activevar
3665 [[ $facet = mds1 ]] && combined_mgs_mds && \
3666 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3667 local TO=`facet_active_host $facet`
3668 echo "Failover $facet to $TO"
3674 # do not stripe off hostname if verbose, bug 19215
3675 if [ x$1 = x--verbose ]; then
3683 if [ "$HOST" = "$HOSTNAME" ]; then
3685 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3686 echo "cannot run remote command on $HOST with $myPDSH"
3690 echo "CMD: $HOST $@" >&2
3691 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3694 if [[ "$myPDSH" == "rsh" ]] ||
3695 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
3696 # we need this because rsh and pdsh do not return
3697 # exit code of an executed command
3698 local command_status="$TMP/cs"
3699 eval $myPDSH $HOST ":> $command_status"
3700 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
3701 PATH=\$PATH:/sbin:/usr/sbin;
3703 LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3704 echo command failed >$command_status"
3705 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
3710 # print HOSTNAME for myPDSH="no_dsh"
3711 if [[ $myPDSH = no_dsh ]]; then
3712 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3714 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3717 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3719 return ${PIPESTATUS[0]}
3723 do_node --verbose "$@"
3726 single_local_node () {
3727 [ "$1" = "$HOSTNAME" ]
3730 # Outputs environment variable assignments that should be passed to remote nodes
3734 local facets=$(get_facets)
3737 for var in ${!MODOPTS_*}; do
3738 value=${!var//\"/\\\"}
3739 echo -n " ${var}=\"$value\""
3742 for facet in ${facets//,/ }; do
3744 if [ -n "${!var}" ]; then
3745 echo -n " $var=${!var}"
3749 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3750 if [ -n "${!var}" ]; then
3751 echo -n " $var=${!var}"
3755 for var in VERBOSE; do
3756 if [ -n "${!var}" ]; then
3757 echo -n " $var=${!var}"
3761 if [ -n "$FSTYPE" ]; then
3762 echo -n " FSTYPE=$FSTYPE"
3765 for var in LNETLND NETTYPE; do
3766 if [ -n "${!var}" ]; then
3767 echo -n " $var=${!var}"
3774 # do not stripe off hostname if verbose, bug 19215
3775 if [ x$1 = x--verbose ]; then
3783 if single_local_node $rnodes; then
3785 do_nodev $rnodes "$@"
3787 do_node $rnodes "$@"
3792 # This is part from do_node
3795 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3796 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3798 export FANOUT=$(get_node_count "${rnodes//,/ }")
3800 echo "CMD: $rnodes $@" >&2
3801 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3804 # do not replace anything from pdsh output if -N is used
3805 # -N Disable hostname: prefix on lines of output.
3806 if $verbose || [[ $myPDSH = *-N* ]]; then
3807 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3809 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3811 return ${PIPESTATUS[0]}
3815 # Execute commands on a single service's host
3817 # The \a facet (service) may be on a local or remote node, which is
3818 # determined at the time the command is run.
3820 # usage: do_facet $facet command [arg ...]
3824 local HOST=$(facet_active_host $facet)
3825 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3829 # Function: do_facet_random_file $FACET $FILE $SIZE
3830 # Creates FILE with random content on the given FACET of given SIZE
3832 do_facet_random_file() {
3836 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3837 do_facet $facet "$cmd 2>/dev/null"
3840 do_facet_create_file() {