3 trap 'print_summary && touch $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
14 export GSS_PIPEFS=false
15 export IDENTITY_UPCALL=default
17 # specify environment variable containing batch job name for server statistics
18 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
20 #export PDSH="pdsh -S -Rssh -w"
21 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
22 export UMOUNT=${UMOUNT:-"umount -d"}
24 export LSNAPSHOT_CONF="/etc/ldev.conf"
25 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
27 # sles12 umount has a issue with -d option
28 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
29 export UMOUNT="umount"
32 # function used by scripts run on remote nodes
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/functions.sh
35 . $LUSTRE/tests/yaml.sh
37 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
39 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
41 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
43 if [ -f "$EXCEPT_LIST_FILE" ]; then
44 echo "Reading test skip list from $EXCEPT_LIST_FILE"
49 # check config files for options in decreasing order of preference
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
51 MODPROBECONF=/etc/modprobe.d/lustre.conf
52 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
53 MODPROBECONF=/etc/modprobe.d/Lustre
54 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
55 MODPROBECONF=/etc/modprobe.conf
57 sanitize_parameters() {
58 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
61 if [ -d "$path" ]; then
62 eval export $i=$(echo $path | sed -r 's/\/+$//g')
68 [[ $DIR/ = $MOUNT/* ]] ||
69 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
70 [[ $DIR1/ = $MOUNT1/* ]] ||
71 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
72 [[ $DIR2/ = $MOUNT2/* ]] ||
73 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
75 [ -n "$failed" ] && exit 99 || true
79 echo "usage: $0 [-r] [-f cfgfile]"
87 [ -z "$DEFAULT_SUITES"] && return 0
88 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
90 local form="%-13s %-17s %-9s %s %s\n"
91 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
92 echo "------------------------------------------------------------------------------------"
93 for O in $DEFAULT_SUITES; do
94 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
95 [ "${!O}" = "no" ] && continue || true
96 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
97 local log=${TMP}/${o}.log
98 if is_sanity_benchmark $o; then
99 log=${TMP}/sanity-benchmark.log
104 local status=Unfinished
106 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
108 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
109 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
110 total=$(grep duration $log | awk '{ print $2 }')
111 if [ "${!O}" = "done" ]; then
115 local durations=$(egrep "^PASS|^FAIL" $log |
116 tr -d "("| sed s/s\)$//g |
117 awk '{ print $2":"$3"|" }')
118 details=$(printf "%s\n%s %s %s\n" "$details" \
119 "DDETAILS" "$O" "$(echo $durations)")
122 printf "$form" $status "$O" "${total}" "E=$skipped"
123 printf "$form" "-" "-" "-" "S=$(echo $slow)"
126 for O in $DEFAULT_SUITES; do
127 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
128 if [ "${!O}" = "no" ]; then
129 printf "$form" "Skipped" "$O" ""
133 # print the detailed tests durations if DDETAILS=true
140 export LUSTRE=$(absolute_path $LUSTRE)
141 export TESTSUITE=$(basename $0 .sh)
142 export TEST_FAILED=false
143 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
144 export RPC_MODE=${RPC_MODE:-false}
145 export DO_CLEANUP=${DO_CLEANUP:-true}
146 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
148 export MKE2FS=$MKE2FS
149 if [ -z "$MKE2FS" ]; then
150 if which mkfs.ldiskfs >/dev/null 2>&1; then
151 export MKE2FS=mkfs.ldiskfs
157 export DEBUGFS=$DEBUGFS
158 if [ -z "$DEBUGFS" ]; then
159 if which debugfs.ldiskfs >/dev/null 2>&1; then
160 export DEBUGFS=debugfs.ldiskfs
162 export DEBUGFS=debugfs
166 export TUNE2FS=$TUNE2FS
167 if [ -z "$TUNE2FS" ]; then
168 if which tunefs.ldiskfs >/dev/null 2>&1; then
169 export TUNE2FS=tunefs.ldiskfs
171 export TUNE2FS=tune2fs
175 export E2LABEL=$E2LABEL
176 if [ -z "$E2LABEL" ]; then
177 if which label.ldiskfs >/dev/null 2>&1; then
178 export E2LABEL=label.ldiskfs
180 export E2LABEL=e2label
184 export DUMPE2FS=$DUMPE2FS
185 if [ -z "$DUMPE2FS" ]; then
186 if which dumpfs.ldiskfs >/dev/null 2>&1; then
187 export DUMPE2FS=dumpfs.ldiskfs
189 export DUMPE2FS=dumpe2fs
193 export E2FSCK=$E2FSCK
194 if [ -z "$E2FSCK" ]; then
195 if which fsck.ldiskfs >/dev/null 2>&1; then
196 export E2FSCK=fsck.ldiskfs
202 export RESIZE2FS=$RESIZE2FS
203 if [ -z "$RESIZE2FS" ]; then
204 if which resizefs.ldiskfs >/dev/null 2>&1; then
205 export RESIZE2FS=resizefs.ldiskfs
207 export RESIZE2FS=resize2fs
211 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
212 export FSCK_MAX_ERR=4 # File system errors left uncorrected
214 export ZFS=${ZFS:-zfs}
215 export ZPOOL=${ZPOOL:-zpool}
216 export ZDB=${ZDB:-zdb}
217 export PARTPROBE=${PARTPROBE:-partprobe}
219 #[ -d /r ] && export ROOT=${ROOT:-/r}
220 export TMP=${TMP:-$ROOT/tmp}
221 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
222 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
223 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
225 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
226 if ! echo $PATH | grep -q $LUSTRE/utils; then
227 export PATH=$LUSTRE/utils:$PATH
229 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
230 export PATH=$LUSTRE/utils/gss:$PATH
232 if ! echo $PATH | grep -q $LUSTRE/tests; then
233 export PATH=$LUSTRE/tests:$PATH
235 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
236 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
238 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
239 [ ! -f "$LST" ] && export LST=$(which lst)
240 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
241 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
242 export MCREATE=${MCREATE:-mcreate}
243 # Ubuntu, at least, has a truncate command in /usr/bin
244 # so fully path our truncate command.
245 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
246 export FSX=${FSX:-$LUSTRE/tests/fsx}
247 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
248 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
249 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
250 export PATH=$LUSTRE/tests/racer:$PATH:
252 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
253 export PATH=$LUSTRE/tests/mpi:$PATH
255 export RSYNC_RSH=${RSYNC_RSH:-rsh}
257 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
258 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
259 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
260 [ ! -f "$LFS" ] && export LFS=$(which lfs)
261 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
262 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
264 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
265 if [ ! -f "$L_GETIDENTITY" ]; then
266 if `which l_getidentity > /dev/null 2>&1`; then
267 export L_GETIDENTITY=$(which l_getidentity)
269 export L_GETIDENTITY=NONE
272 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
273 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
274 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
275 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
276 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
277 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
278 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
279 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
280 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
281 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
282 [ ! -f "$LUSTRE_RMMOD" ] &&
283 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
284 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
285 [ ! -f "$LFS_MIGRATE" ] &&
286 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
287 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
288 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
289 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
290 export NAME=${NAME:-local}
291 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
292 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
293 export LGSSD=$(which lgssd)
294 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
295 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
296 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
298 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
300 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
301 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
303 if [ "$ACCEPTOR_PORT" ]; then
304 export PORT_OPT="--port $ACCEPTOR_PORT"
309 echo "Using GSS/krb5 ptlrpc security flavor"
310 which lgss_keyring > /dev/null 2>&1 || \
311 error_exit "built with gss disabled! SEC=$SEC"
322 IDENTITY_UPCALL=false
326 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
328 # Paths on remote nodes, if different
329 export RLUSTRE=${RLUSTRE:-$LUSTRE}
330 export RPWD=${RPWD:-$PWD}
331 export I_MOUNTED=${I_MOUNTED:-"no"}
332 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
333 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
334 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
335 ! -f $LUSTRE/mdt/mdt.ko ]; then
336 export CLIENTMODSONLY=yes
339 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
340 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
344 while getopts "rvwf:" opt $*; do
349 w) WRITECONF=writeconf;;
354 shift $((OPTIND - 1))
357 # print the durations of each test if "true"
358 DDETAILS=${DDETAILS:-false}
359 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
364 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
371 ncpts=$(do_facet $facet "lctl get_param -n " \
372 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
374 if [ $ncpts -eq 0 ]; then
381 # Return a numeric version code based on a version string. The version
382 # code is useful for comparison two version strings to see which is newer.
384 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
385 eval set -- $(tr "[:punct:]" " " <<< $*)
387 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
390 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
391 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
393 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
395 # usage: lustre_build_version
397 # All Lustre versions support "lctl get_param" to report the version of the
398 # code running in the kernel (what our tests are interested in), but it
399 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
400 # the "version" parameter doesn't include "lustre: " at the beginning.
401 # If that fails, call "lctl lustre_build_version" which prints either (or both)
402 # the userspace and kernel build versions, but until 2.8.55 required root
403 # access to get the Lustre kernel version. If that also fails, fall back to
404 # using "lctl --version", which is easy to parse and works without the kernel
405 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
406 # not the module version, though they are usually the same.
408 # Various commands and their output format for different Lustre versions:
409 # lctl get_param version: 2.9.55
410 # lctl get_param version: lustre: 2.8.53
411 # lctl get_param version: lustre: 2.6.52
412 # kernel: patchless_client
413 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
414 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
415 # lctl lustre_build_version: error: lustre_build_version: Permission denied
416 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
417 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
418 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
419 # lctl --version: lctl 2.6.50
421 # output: prints version string to stdout in (up to 4) dotted-decimal values
422 lustre_build_version() {
423 local facet=${1:-client}
426 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
427 $LCTL lustre_build_version 2>/dev/null ||
428 $LCTL --version 2>/dev/null | cut -d' ' -f2")
429 local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
430 [ -n "$lver" ] && ver="$lver"
432 sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
436 # Report the Lustre numeric build version code for the supplied facet.
437 lustre_version_code() {
438 version_code $(lustre_build_version $1)
442 /sbin/lsmod | grep -q "^\<$1\>"
454 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
457 # parallels can't load modules directly from prlfs, use /tmp instead
458 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
459 local target="$(mktemp)"
461 cp "$module" "$target"
464 [[ $rc == 0 ]] && PRLFS=true
472 # Load a module on the system where this is running.
474 # usage: load_module module_name [module arguments for insmod/modprobe]
476 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
477 # will be used as the arguments. Otherwise arguments will be obtained from
478 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
485 BASE=$(basename $module $EXT)
487 module_loaded ${BASE} && return
489 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
490 # else from modprobe.conf
491 if [ $# -eq 0 ]; then
492 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
493 # Bash until 4.x, so we resort to eval.
494 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
495 eval set -- \$$optvar
496 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
497 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
499 opt=$(awk -v var="^options $BASE" '$0 ~ var \
500 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
501 set -- $(echo -n $opt)
503 # Ensure we have accept=all for lnet
504 if [ $(basename $module) = lnet ]; then
505 # OK, this is a bit wordy...
506 local arg accept_all_present=false
509 [ "$arg" = accept=all ] && \
510 accept_all_present=true
512 $accept_all_present || set -- "$@" accept=all
518 [ $# -gt 0 ] && echo "${module} options: '$*'"
520 # Note that insmod will ignore anything in modprobe.conf, which is why
521 # we're passing options on the command-line.
522 if [[ "$BASE" == "lnet_selftest" ]] &&
523 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
524 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
525 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
526 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
527 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
529 # must be testing a "make install" or "rpm" installation
530 # note failed to load ptlrpc_gss is considered not fatal
531 if [[ "$BASE" == "ptlrpc_gss" ]]; then
532 modprobe $BASE "$@" 2>/dev/null ||
533 echo "gss/krb5 is not supported"
540 load_modules_local() {
541 if [ -n "$MODPROBE" ]; then
543 echo "Using modprobe to load modules"
547 echo Loading modules from $LUSTRE
551 if [ -f /sys/devices/system/cpu/online ]; then
552 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
553 echo "detected $ncpus online CPUs by sysfs"
555 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
557 if [ $rc -eq 0 ]; then
558 echo "detected $ncpus online CPUs by getconf"
560 echo "Can't detect number of CPUs"
565 # if there is only one CPU core, libcfs can only create one partition
566 # if there is more than 4 CPU cores, libcfs should create multiple CPU
567 # partitions. So we just force libcfs to create 2 partitions for
568 # system with 2 or 4 cores
569 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
570 # force to enable multiple CPU partitions
571 echo "Force libcfs to create 2 CPU partitions"
572 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
574 echo "libcfs will create CPU partition based on online CPUs"
577 load_module ../libcfs/libcfs/libcfs
578 # Prevent local MODOPTS_LIBCFS being passed as part of environment
579 # variable to remote nodes
583 load_module ../lnet/lnet/lnet
585 LNDPATH=${LNDPATH:-"../lnet/klnds"}
586 if [ -z "$LNETLND" ]; then
588 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
589 tcp*) LNETLND="socklnd/ksocklnd" ;;
590 *) local lnd="${NETTYPE%%[0-9]}lnd"
591 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
592 LNETLND="$lnd/k$lnd" ||
593 LNETLND="socklnd/ksocklnd"
596 load_module ../lnet/klnds/$LNETLND
597 load_module obdclass/obdclass
598 load_module ptlrpc/ptlrpc
599 load_module ptlrpc/gss/ptlrpc_gss
607 load_module obdecho/obdecho
608 if ! client_only; then
609 SYMLIST=/proc/kallsyms
610 grep -q crc16 $SYMLIST ||
611 { modprobe crc16 2>/dev/null || true; }
612 grep -q -w jbd2 $SYMLIST ||
613 { modprobe jbd2 2>/dev/null || true; }
614 load_module lfsck/lfsck
615 [ "$LQUOTA" != "no" ] &&
616 load_module quota/lquota $LQUOTAOPTS
617 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
618 lsmod | grep zfs >&/dev/null || modprobe zfs
619 load_module osd-zfs/osd_zfs
621 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
622 grep -q exportfs_decode_fh $SYMLIST ||
623 { modprobe exportfs 2> /dev/null || true; }
624 grep -q -w mbcache $SYMLIST ||
625 { modprobe mbcache 2>/dev/null || true; }
626 load_module ../ldiskfs/ldiskfs
627 load_module osd-ldiskfs/osd_ldiskfs
639 load_module llite/lustre
640 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
642 rm -f $OGDB/ogdb-$HOSTNAME
643 $LCTL modules > $OGDB/ogdb-$HOSTNAME
645 # 'mount' doesn't look in $PATH, just sbin
646 local mount_lustre=$LUSTRE/utils/mount.lustre
647 if [ -f $mount_lustre ]; then
648 local sbin_mount=$(readlink -f /sbin)/mount.lustre
649 if grep -qw "$sbin_mount" /proc/mounts; then
650 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
652 if ! grep -qw "$sbin_mount" /proc/mounts; then
653 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
654 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
655 cat <<- EOF > "$sbin_mount"
658 echo "This $sbin_mount just a mountpoint." 1>&2
659 echo "It is never supposed to be run." 1>&2
660 logger -p emerg -- "using stub $sbin_mount $@"
663 chmod a+x $sbin_mount
665 mount --bind $mount_lustre $sbin_mount ||
666 error "can't bind $mount_lustre to $sbin_mount"
674 # load modules on remote nodes optionally
675 # lustre-tests have to be installed on these nodes
676 if $LOAD_MODULES_REMOTE; then
677 local list=$(comma_list $(remote_nodes_list))
678 if [ -n "$list" ]; then
679 echo "loading modules on: '$list'"
680 do_rpc_nodes "$list" load_modules_local
686 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
687 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
688 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
689 echo "$LEAK_LUSTRE" 1>&2
690 echo "$LEAK_PORTALS" 1>&2
691 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
692 echo "Memory leaks detected"
693 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
699 wait_exit_ST client # bug 12845
701 $LUSTRE_RMMOD ldiskfs || return 2
703 if $LOAD_MODULES_REMOTE; then
704 local list=$(comma_list $(remote_nodes_list))
705 if [ -n "$list" ]; then
706 echo "unloading modules on: '$list'"
707 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
708 do_rpc_nodes "$list" check_mem_leak
712 local sbin_mount=$(readlink -f /sbin)/mount.lustre
713 if grep -qe "$sbin_mount " /proc/mounts; then
714 umount $sbin_mount || true
715 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
719 check_mem_leak || return 254
721 echo "modules unloaded."
726 local facet=${1:-$SINGLEMDS}
727 local fstype=$(facet_fstype $facet)
730 ldiskfs) size=50;; # largest seen is 44, leave some headroom
731 zfs) size=400;; # largest seen is 384
738 local facet=${1:-$SINGLEMDS}
739 local fstype=$(facet_fstype $facet)
742 ldiskfs) size=4;; # ~4KB per inode
743 zfs) size=11;; # 10 to 11KB per inode
749 check_gss_daemon_nodes() {
753 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
754 if [ \\\"\\\$num\\\" -ne 1 ]; then
755 echo \\\$num instance of $dname;
760 check_gss_daemon_facet() {
764 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
765 if [ $num -ne 1 ]; then
766 echo "$num instance of $dname on $facet"
775 echo Stopping $@ on $list
776 do_nodes $list "killall -2 $@ 2>/dev/null || true"
779 # start gss daemons on all nodes, or
780 # "daemon" on "list" if set
781 start_gss_daemons() {
785 if [ "$list" ] && [ "$daemon" ] ; then
786 echo "Starting gss daemon on nodes: $list"
787 do_nodes $list "$daemon" || return 8
791 local list=$(comma_list $(mdts_nodes))
792 echo "Starting gss daemon on mds: $list"
793 do_nodes $list "$LSVCGSSD -v" || return 1
795 do_nodes $list "$LGSSD -v" || return 2
798 list=$(comma_list $(osts_nodes))
799 echo "Starting gss daemon on ost: $list"
800 do_nodes $list "$LSVCGSSD -v" || return 3
801 # starting on clients
803 local clients=${CLIENTS:-`hostname`}
805 echo "Starting $LGSSD on clients $clients "
806 do_nodes $clients "$LGSSD -v" || return 4
809 # wait daemons entering "stable" status
813 # check daemons are running
815 list=$(comma_list $(mdts_nodes) $(osts_nodes))
816 check_gss_daemon_nodes $list lsvcgssd || return 5
818 list=$(comma_list $(mdts_nodes))
819 check_gss_daemon_nodes $list lgssd || return 6
822 check_gss_daemon_nodes $clients lgssd || return 7
827 local list=$(comma_list $(mdts_nodes))
829 send_sigint $list lsvcgssd lgssd
831 list=$(comma_list $(osts_nodes))
832 send_sigint $list lsvcgssd
834 list=${CLIENTS:-`hostname`}
835 send_sigint $list lgssd
840 if ! module_loaded ptlrpc_gss; then
841 load_module ptlrpc/gss/ptlrpc_gss
842 module_loaded ptlrpc_gss ||
843 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
846 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
849 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
851 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
859 # maybe cleanup credential cache?
865 local var=${facet}_svc
873 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
874 tr '[:lower:]' '[:upper:]'
880 if [ $facet == mgs ] || [ $facet == client ]; then
884 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
892 if [ -n "${!var}" ]; then
897 var=$(facet_type $facet)FSTYPE
898 if [ -n "${!var}" ]; then
903 if [ -n "$FSTYPE" ]; then
908 if [[ $facet == mgs ]] && combined_mgs_mds; then
920 local facets=$(get_facets)
923 for facet in ${facets//,/ }; do
924 if [ $node == $(facet_host $facet) ] ||
925 [ $node == "$(facet_failover_host $facet)" ]; then
926 fstype=$(facet_fstype $facet)
927 if [[ $fstypes != *$fstype* ]]; then
928 fstypes+="${fstypes:+,}$fstype"
937 local num=$(facet_number $facet)
940 if [[ $(facet_type $facet) = OST ]]; then
942 if [[ -n "${!index}" ]]; then
947 index=${OST_INDICES[num - 1]}
950 [[ -n "$index" ]] || index=$((num - 1))
958 local fstype=$(facet_fstype $facet)
962 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
964 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
965 ${dev} 2>/dev/null");;
967 error "unknown fstype!";;
975 local device=$(mdsdevname $num)
976 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
982 local device=$(ostdevname $num)
983 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
988 # Get the device of a facet.
995 mgs) device=$(mgsdevname) ;;
996 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
997 ost*) device=$(ostdevname $(facet_number $facet)) ;;
998 fs2mds) device=$(mdsdevname 1_2) ;;
999 fs2ost) device=$(ostdevname 1_2) ;;
1000 fs3ost) device=$(ostdevname 2_2) ;;
1008 # Get the virtual device of a facet.
1015 mgs) device=$(mgsvdevname) ;;
1016 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1017 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1018 fs2mds) device=$(mdsvdevname 1_2) ;;
1019 fs2ost) device=$(ostvdevname 1_2) ;;
1020 fs3ost) device=$(ostvdevname 2_2) ;;
1028 local virt=$(virt-what 2> /dev/null)
1030 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1032 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1035 VMware|KVM|VirtualBox|Parallels)
1036 echo $virt | tr '[A-Z]' '[a-z]' ;;
1042 # Re-read the partition table on failover partner host.
1043 # After a ZFS storage pool is created on a shared device, the partition table
1044 # on the device may change. However, the operating system on the failover
1045 # host may not notice the change automatically. Without the up-to-date partition
1046 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1047 # relative to partition rather than disk beginnings.
1049 # This function performs partprobe on the failover host to make it re-read the
1052 refresh_partition_table() {
1057 host=$(facet_passive_host $facet)
1058 if [[ -n "$host" ]]; then
1059 do_node $host "$PARTPROBE $device"
1064 # Get ZFS storage pool name.
1071 device=$(facet_device $facet)
1072 # poolname is string before "/"
1073 poolname="${device%%/*}"
1080 # Get ZFS local fsname.
1082 zfs_local_fsname() {
1084 local lfsname=$(basename $(facet_device $facet))
1090 # Create ZFS storage pool.
1097 local opts=${@:-"-o cachefile=none"}
1099 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1100 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1101 $ZPOOL create -f $opts $poolname $vdev"
1105 # Create ZFS file system.
1111 local opts=${@:-"-o mountpoint=legacy"}
1113 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1114 $ZFS create $opts $dataset"
1118 # Export ZFS storage pool.
1119 # Before exporting the pool, all datasets within the pool should be unmounted.
1127 poolname=$(zpool_name $facet)
1129 if [[ -n "$poolname" ]]; then
1130 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1131 grep -q ^$poolname/ /proc/mounts ||
1132 $ZPOOL export $opts $poolname"
1137 # Destroy ZFS storage pool.
1138 # Destroy the given pool and free up any devices for other use. This command
1139 # tries to unmount any active datasets before destroying the pool.
1140 # -f Force any active datasets contained within the pool to be unmounted.
1144 local poolname=${2:-$(zpool_name $facet)}
1146 if [[ -n "$poolname" ]]; then
1147 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1148 $ZPOOL destroy -f $poolname"
1153 # Import ZFS storage pool.
1154 # Force importing, even if the pool appears to be potentially active.
1159 local opts=${@:-"-o cachefile=none"}
1162 poolname=$(zpool_name $facet)
1164 if [[ -n "$poolname" ]]; then
1165 opts+=" -d $(dirname $(facet_vdevice $facet))"
1166 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1167 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1168 $ZPOOL import -f $opts $poolname"
1173 # Reimport ZFS storage pool with new name
1178 local opts="-o cachefile=none"
1179 local poolname=$(zpool_name $facet)
1181 opts+=" -d $(dirname $(facet_vdevice $facet))"
1182 do_facet $facet "$ZPOOL export $poolname;
1183 $ZPOOL import $opts $poolname $newpool"
1187 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1188 # is not automatically imported on system startup.
1190 # In a failover environment, this will provide resource level fencing which
1191 # will ensure that the same ZFS storage pool will not be imported concurrently
1192 # on different nodes.
1194 disable_zpool_cache() {
1198 poolname=$(zpool_name $facet)
1200 if [[ -n "$poolname" ]]; then
1201 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1206 # This and set_osd_param() shall be used to access OSD parameters
1207 # once existed under "obdfilter":
1212 # writethrough_cache_enable
1216 local device=${2:-$FSNAME-OST*}
1219 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1220 osd-*.$device.$name 2>&1" | grep -v 'error:'
1225 local device=${2:-$FSNAME-OST*}
1229 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1230 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1234 local dz=${1:-$DEBUG_SIZE}
1236 if [ -f /sys/devices/system/cpu/possible ]; then
1237 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1239 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1242 # bug 19944, adjust size to be -gt num_possible_cpus()
1243 # promise 2MB for every cpu at least
1244 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1247 lctl set_param debug_mb=$dz
1250 set_default_debug () {
1251 local debug=${1:-"$PTLDEBUG"}
1252 local subsys=${2:-"$SUBSYSTEM"}
1253 local debug_size=${3:-$DEBUG_SIZE}
1255 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1256 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1258 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1261 set_default_debug_nodes () {
1264 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1265 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1269 do_rpc_nodes "$nodes" set_default_debug \
1270 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1273 set_default_debug_facet () {
1275 local node=$(facet_active_host $facet)
1276 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1278 set_default_debug_nodes $node
1282 local hostid=${1:-$(hostid)}
1284 if [ ! -s /etc/hostid ]; then
1285 printf $(echo -n $hostid |
1286 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1292 local facets=${1:-$(get_facets)}
1295 for facet in ${facets//,/ }; do
1298 [ $RC -eq 0 ] && continue
1300 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1301 skip "Restart of $facet failed!." && touch $LU482_FAILED
1303 error "Restart of $facet failed!"
1310 # Add argument "arg" (e.g., "loop") to the comma-separated list
1311 # of arguments for option "opt" (e.g., "-o") on command
1312 # line "opts" (e.g., "-o flock").
1318 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1320 if echo "$opts" | grep -q $opt_pattern; then
1321 opts=$(echo "$opts" | sed -e \
1322 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1324 opts+="${opts:+ }$opt $arg"
1332 local dev=$(facet_active $facet)_dev
1333 local opt=${facet}_opt
1334 local mntpt=$(facet_mntpt $facet)
1335 local opts="${!opt} $@"
1336 local fstype=$(facet_fstype $facet)
1339 module_loaded lustre || load_modules
1341 if [ $(facet_fstype $facet) == ldiskfs ] &&
1342 ! do_facet $facet test -b ${!dev}; then
1343 opts=$(csa_add "$opts" -o loop)
1346 if [[ $(facet_fstype $facet) == zfs ]]; then
1347 # import ZFS storage pool
1348 import_zpool $facet || return ${PIPESTATUS[0]}
1353 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1355 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1356 lustre:svname ${!dev}");;
1358 error "unknown fstype!";;
1361 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1362 # for testing LU-482 error handling in mount_facets() and test_0a()
1363 if [ -f $TMP/test-lu482-trigger ]; then
1366 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1371 if [ $RC -ne 0 ]; then
1372 echo "Start of ${!dev} on ${facet} failed ${RC}"
1376 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1377 if [[ "$health" != "healthy" ]]; then
1378 error "$facet is in a unhealthy state"
1381 set_default_debug_facet $facet
1383 if [[ $facet == mds* ]]; then
1385 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1388 if [[ $opts =~ .*nosvc.* ]]; then
1389 echo "Start ${!dev} without service"
1394 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1395 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1396 "" || error "${!dev} failed to initialize!";;
1398 wait_update_facet ${facet} "$ZFS get -H -o value \
1399 lustre:svname ${!dev} 2>/dev/null | \
1400 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1401 error "${!dev} failed to initialize!";;
1404 error "unknown fstype!";;
1408 # commit the device label change to disk
1409 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1410 echo "Commit the device label on ${!dev}"
1411 do_facet $facet "sync; sleep 1; sync"
1415 label=$(devicelabel ${facet} ${!dev})
1416 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1417 eval export ${facet}_svc=${label}
1418 echo Started ${label}
1423 # start facet device options
1429 eval export ${facet}_dev=${device}
1430 eval export ${facet}_opt=\"$@\"
1432 local varname=${facet}failover_dev
1433 if [ -n "${!varname}" ] ; then
1434 eval export ${facet}failover_dev=${!varname}
1436 eval export ${facet}failover_dev=$device
1439 local mntpt=$(facet_mntpt $facet)
1440 do_facet ${facet} mkdir -p $mntpt
1441 eval export ${facet}_MOUNT=$mntpt
1442 mount_facet ${facet}
1445 if [[ $facet == mds* ]]; then
1447 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1458 local HOST=`facet_active_host $facet`
1459 [ -z $HOST ] && echo stop: no host for $facet && return 0
1461 local mntpt=$(facet_mntpt $facet)
1462 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1463 if [ ${running} -ne 0 ]; then
1464 echo "Stopping $mntpt (opts:$@) on $HOST"
1465 do_facet ${facet} $UMOUNT $@ $mntpt
1468 # umount should block, but we should wait for unrelated obd's
1469 # like the MGS or MGC to also stop.
1470 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1472 if [[ $(facet_fstype $facet) == zfs ]]; then
1473 # export ZFS storage pool
1474 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1478 # save quota version (both administrative and operational quotas)
1479 # add an additional parameter if mountpoint is ever different from $MOUNT
1481 # XXX This function is kept for interoperability with old server (< 2.3.50),
1482 # it should be removed whenever we drop the interoperability for such
1484 quota_save_version() {
1485 local fsname=${2:-$FSNAME}
1487 local ver=$(tr -c -d "123" <<< $spec)
1488 local type=$(tr -c -d "ug" <<< $spec)
1490 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1492 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1494 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1496 local osts=$(get_facets OST)
1497 for ost in ${osts//,/ }; do
1499 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1503 # client could mount several lustre
1505 # XXX This function is kept for interoperability with old server (< 2.3.50),
1506 # it should be removed whenever we drop the interoperability for such
1509 local fsname=${1:-$FSNAME}
1511 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1513 do_nodes $(comma_list $(osts_nodes)) \
1514 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1518 # get mdt quota type
1520 local varsvc=${SINGLEMDS}_svc
1521 do_facet $SINGLEMDS $LCTL get_param -n \
1522 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1525 # get ost quota type
1527 # All OSTs should have same quota type
1528 local varsvc=ost1_svc
1529 do_facet ost1 $LCTL get_param -n \
1530 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1533 # restore old quota type settings
1535 if [ "$old_MDT_QUOTA_TYPE" ]; then
1536 do_facet mgs $LCTL conf_param \
1537 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1539 if [ "$old_OST_QUOTA_TYPE" ]; then
1540 do_facet mgs $LCTL conf_param \
1541 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1545 # Handle the case when there is a space in the lfs df
1546 # "filesystem summary" line the same as when there is no space.
1547 # This will allow fixing the "lfs df" summary line in the future.
1549 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1552 # Get free inodes on the MDT specified by mdt index, free indoes on
1553 # the whole filesystem will be returned when index == -1.
1559 if [ $index -eq -1 ]; then
1562 mdt_uuid=$(mdtuuid_from_index $index)
1565 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1570 # Get the OST device status from 'lfs df' with a given OST index.
1574 local mnt_pnt=${2:-$MOUNT}
1577 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1578 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1584 # save old quota type & set new quota type
1585 local mdt_qtype=$(mdt_quota_type)
1586 local ost_qtype=$(ost_quota_type)
1588 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1589 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1591 export old_MDT_QUOTA_TYPE=$mdt_qtype
1592 export old_OST_QUOTA_TYPE=$ost_qtype
1594 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1595 error "set mdt quota type failed"
1596 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1597 error "set ost quota type failed"
1599 local quota_usrs=$QUOTA_USERS
1601 # get_filesystem_size
1602 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1603 local blk_soft=$((disksz + 1024))
1604 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1606 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1607 local i_soft=$inodes
1608 local i_hard=$((i_soft + i_soft / 20))
1610 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1611 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1612 "inode-hardlimit: $i_hard"
1615 for usr in $quota_usrs; do
1616 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1618 cmd="$LFS setquota -$type $usr -b $blk_soft"
1619 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1621 eval $cmd || error "$cmd FAILED!"
1623 # display the quota status
1624 echo "Quota settings for $usr : "
1625 $LFS quota -v -u $usr $mntpt || true
1632 local opts=${3:-$MOUNT_OPTS}
1633 opts=${opts:+-o $opts}
1634 local flags=${4:-$MOUNT_FLAGS}
1636 local device=$MGSNID:/$FSNAME$FILESET
1637 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1638 echo "Bad mount command: opt=$flags $opts dev=$device " \
1643 echo "Starting client: $client: $flags $opts $device $mnt"
1644 do_node $client mkdir -p $mnt
1645 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1646 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1648 #disable FILESET if not supported
1649 do_nodes $client lctl get_param -n \
1650 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1651 device=$MGSNID:/$FSNAME
1652 do_node $client mkdir -p $mnt/$FILESET
1653 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1656 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1658 set_default_debug_nodes $client
1670 [ "$3" ] && force=-f
1671 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1672 if [ $running -ne 0 ]; then
1673 echo "Stopping client $client $mnt (opts:$force)"
1674 do_node $client lsof -t $mnt || need_kill=no
1675 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1676 pids=$(do_node $client lsof -t $mnt | sort -u);
1677 if [ -n $pids ]; then
1678 do_node $client kill -9 $pids || true
1682 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1683 if [ $busy -ne 0 ] ; then
1684 echo "$mnt is still busy, wait one second" && sleep 1
1685 do_node $client umount $force $mnt
1690 # nodes is comma list
1691 sanity_mount_check_nodes () {
1697 # FIXME: assume that all cluster nodes run the same os
1698 [ "$(uname)" = Linux ] || return 0
1701 for mnt in $mnts ; do
1702 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1703 mpts=\\\$(mount | grep -c $mnt' ');
1704 if [ \\\$running -ne \\\$mpts ]; then
1705 echo \\\$(hostname) env are INSANE!;
1708 [ $? -eq 0 ] || rc=1
1713 sanity_mount_check_servers () {
1714 [ -n "$CLIENTONLY" ] &&
1715 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1716 echo Checking servers environments
1718 # FIXME: modify get_facets to display all facets wo params
1719 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1723 for facet in ${facets//,/ }; do
1724 node=$(facet_host ${facet})
1725 mntpt=$(facet_mntpt $facet)
1726 sanity_mount_check_nodes $node $mntpt ||
1727 { error "server $node environments are insane!"; return 1; }
1731 sanity_mount_check_clients () {
1732 local clients=${1:-$CLIENTS}
1733 local mntpt=${2:-$MOUNT}
1734 local mntpt2=${3:-$MOUNT2}
1736 [ -z $clients ] && clients=$(hostname)
1737 echo Checking clients $clients environments
1739 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1740 error "clients environments are insane!"
1743 sanity_mount_check () {
1744 sanity_mount_check_servers || return 1
1745 sanity_mount_check_clients || return 2
1748 # mount clients if not mouted
1749 zconf_mount_clients() {
1752 local opts=${3:-$MOUNT_OPTS}
1753 opts=${opts:+-o $opts}
1754 local flags=${4:-$MOUNT_FLAGS}
1756 local device=$MGSNID:/$FSNAME$FILESET
1757 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1758 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1763 echo "Starting client $clients: $flags $opts $device $mnt"
1764 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1765 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1767 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1769 #disable FILESET if not supported
1770 do_nodes $clients lctl get_param -n \
1771 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1772 device=$MGSNID:/$FSNAME
1773 do_nodes $clients mkdir -p $mnt/$FILESET
1774 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1779 running=\\\$(mount | grep -c $mnt' ');
1781 if [ \\\$running -eq 0 ] ; then
1783 $MOUNT_CMD $flags $opts $device $mnt;
1786 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
1787 grep 'type lustre' | wc -l);
1788 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
1789 echo zconf_mount_clients FAILED: \
1790 mount count \\\$running, not matching \
1791 with mount count of 'type lustre' \
1792 \\\$lustre_mnt_count;
1796 exit \\\$rc" || return ${PIPESTATUS[0]}
1798 echo "Started clients $clients: "
1799 do_nodes $clients "mount | grep $mnt' '"
1801 set_default_debug_nodes $clients
1806 zconf_umount_clients() {
1811 [ "$3" ] && force=-f
1813 echo "Stopping clients: $clients $mnt (opts:$force)"
1814 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1815 if [ \\\$running -ne 0 ] ; then
1816 echo Stopping client \\\$(hostname) $mnt opts:$force;
1817 lsof $mnt || need_kill=no;
1818 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1819 pids=\\\$(lsof -t $mnt | sort -u);
1820 if [ -n \\\"\\\$pids\\\" ]; then
1824 while umount $force $mnt 2>&1 | grep -q "busy"; do
1825 echo "$mnt is still busy, wait one second" && sleep 1;
1832 echo + $POWER_DOWN $node
1836 shutdown_node_hard () {
1838 local attempts=$SHUTDOWN_ATTEMPTS
1840 for i in $(seq $attempts) ; do
1843 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1844 echo "waiting for $host to fail attempts=$attempts"
1845 [ $i -lt $attempts ] || \
1846 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1852 local mnt=${2:-$MOUNT}
1855 if [ "$FAILURE_MODE" = HARD ]; then
1856 shutdown_node_hard $client
1858 zconf_umount_clients $client $mnt -f
1864 local facets="$(get_facets OST),$(get_facets MDS)"
1867 combined_mgs_mds || facets="$facets,mgs"
1869 for facet in ${facets//,/ }; do
1870 if [ $(facet_active_host $facet) == $host ]; then
1871 affected="$affected $facet"
1875 echo $(comma_list $affected)
1880 local host=${2:-$(facet_host $facet)}
1882 local label=$(convert_facet2label $facet)
1883 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1886 facets_up_on_host () {
1888 local facets=$(facets_on_host $host)
1891 for facet in ${facets//,/ }; do
1892 if $(facet_up $facet $host); then
1893 affected_up="$affected_up $facet"
1897 echo $(comma_list $affected_up)
1903 if [ "$FAILURE_MODE" = HARD ]; then
1904 shutdown_node_hard $(facet_active_host $facet)
1912 echo + $POWER_UP $node
1925 if [ "$FAILURE_MODE" = HARD ]; then
1926 reboot_node $(facet_active_host $facet)
1934 if [ "$FAILURE_MODE" = HARD ]; then
1944 for facet in ${facets//,/ }; do
1945 hosts=$(expand_list $hosts $(facet_host $facet) )
1951 _check_progs_installed () {
1955 for prog in $progs; do
1956 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1957 echo $prog missing on $(hostname)
1964 check_progs_installed () {
1968 do_rpc_nodes "$nodes" _check_progs_installed $@
1971 # recovery-scale functions
1973 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1976 start_client_load() {
1979 local var=$(node_var_name $client)_load
1980 eval export ${var}=$load
1982 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1983 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1984 END_RUN_FILE=$END_RUN_FILE \
1985 LOAD_PID_FILE=$LOAD_PID_FILE \
1986 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1987 TESTNAME=$TESTNAME \
1988 DBENCH_LIB=$DBENCH_LIB \
1989 DBENCH_SRC=$DBENCH_SRC \
1990 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1996 log "Started client load: ${load} on $client"
1998 # get the children process IDs
1999 local pids=$(ps --ppid $ppid -o pid= | xargs)
2000 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2004 start_client_loads () {
2005 local -a clients=(${1//,/ })
2006 local numloads=${#CLIENT_LOADS[@]}
2009 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2010 testnum=$((nodenum % numloads))
2011 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2013 # bug 22169: wait the background threads to start
2017 # only for remote client
2018 check_client_load () {
2020 local var=$(node_var_name $client)_load
2021 local testload=run_${!var}.sh
2023 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2025 # bug 18914: try to connect several times not only when
2026 # check ps, but while check_node_health also
2030 while [ $RC = 254 -a $tries -gt 0 ]; do
2034 if ! check_node_health $client; then
2036 if [ $RC -eq 254 ]; then
2037 # FIXME: not sure how long we shuold sleep here
2041 echo "check node health failed: RC=$RC "
2045 # We can continue try to connect if RC=254
2046 # Just print the warning about this
2047 if [ $RC = 254 ]; then
2048 echo "got a return status of $RC from do_node while checking " \
2049 "node health on $client"
2052 # see if the load is still on the client
2055 while [ $RC = 254 -a $tries -gt 0 ]; do
2059 if ! do_node $client \
2060 "ps auxwww | grep -v grep | grep -q $testload"; then
2065 if [ $RC = 254 ]; then
2066 echo "got a return status of $RC from do_node while checking " \
2067 "(node health and 'ps') the client load on $client"
2068 # see if we can diagnose a bit why this is
2073 check_client_loads () {
2074 local clients=${1//,/ }
2078 for client in $clients; do
2079 check_client_load $client
2081 if [ "$rc" != 0 ]; then
2082 log "Client load failed on node $client, rc=$rc"
2088 restart_client_loads () {
2089 local clients=${1//,/ }
2090 local expectedfail=${2:-""}
2094 for client in $clients; do
2095 check_client_load $client
2097 if [ "$rc" != 0 -a "$expectedfail" ]; then
2098 local var=$(node_var_name $client)_load
2099 start_client_load $client ${!var}
2100 echo "Restarted client load ${!var}: on $client. Checking ..."
2101 check_client_load $client
2103 if [ "$rc" != 0 ]; then
2104 log "Client load failed to restart on node $client, rc=$rc"
2105 # failure one client load means test fail
2106 # we do not need to check other
2115 # Start vmstat and save its process ID in a file.
2120 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2123 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2124 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2127 # Display the nodes on which client loads failed.
2128 print_end_run_file() {
2132 [ -s $file ] || return 0
2134 echo "Found the END_RUN_FILE file: $file"
2137 # A client load will stop if it finds the END_RUN_FILE file.
2138 # That does not mean the client load actually failed though.
2139 # The first node in END_RUN_FILE is the one we are interested in.
2142 if [ -n "$node" ]; then
2143 local var=$(node_var_name $node)_load
2145 local prefix=$TESTLOG_PREFIX
2146 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2147 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2148 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2150 echo "Client load ${!var} failed on node $node:"
2156 # Stop the process which had its PID saved in a file.
2161 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2163 do_nodes $nodes "test -f $pid_file &&
2164 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2167 # Stop all client loads.
2168 stop_client_loads() {
2169 local nodes=${1:-$CLIENTS}
2172 # stop the client loads
2173 stop_process $nodes $pid_file
2175 # clean up the processes that started them
2176 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2178 # End recovery-scale functions
2180 # verify that lustre actually cleaned up properly
2182 VAR=$(lctl get_param -n catastrophe 2>&1)
2183 if [ $? = 0 ] ; then
2184 if [ $VAR != 0 ]; then
2185 error "LBUG/LASSERT detected"
2188 BUSY=$(dmesg | grep -i destruct || true)
2189 if [ -n "$BUSY" ]; then
2191 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2195 check_mem_leak || exit 204
2197 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2198 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2201 if module_loaded lnet || module_loaded libcfs; then
2202 echo "$TESTSUITE: modules still loaded..." 1>&2
2211 if [[ "$1" == "--verbose" ]]; then
2226 PREV_RESULT=$(do_node $node "$TEST")
2228 RESULT=$(do_node $node "$TEST")
2229 if [[ "$RESULT" == "$FINAL" ]]; then
2230 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2231 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2235 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2236 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2240 [[ $WAIT -ge $MAX ]] && break
2241 [[ $((WAIT % print)) -eq 0 ]] &&
2242 echo "Waiting $((MAX - WAIT)) secs for update"
2243 WAIT=$((WAIT + sleep))
2246 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2250 wait_update_facet() {
2252 [ "$1" = "--verbose" ] && verbose="$1" && shift
2256 wait_update $verbose $(facet_active_host $facet) "$@"
2260 do_nodes $(comma_list $(mdts_nodes)) \
2261 "lctl set_param -n osd*.*MDT*.force_sync=1"
2262 do_nodes $(comma_list $(osts_nodes)) \
2263 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2264 grep -v 'Found no match'
2268 # the occupied disk space will be released
2269 # only after DMUs are committed
2270 if [[ $(facet_fstype $1) == zfs ]]; then
2271 echo "sleep $2 for ZFS OSD"
2276 wait_delete_completed_mds() {
2277 local MAX_WAIT=${1:-20}
2278 # for ZFS, waiting more time for DMUs to be committed
2279 local ZFS_WAIT=${2:-5}
2281 local stime=$(date +%s)
2286 # find MDS with pending deletions
2287 for node in $(mdts_nodes); do
2288 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2289 2>/dev/null | calc_sum)
2290 if [[ $changes -eq 0 ]]; then
2293 mds2sync="$mds2sync $node"
2295 if [ -z "$mds2sync" ]; then
2296 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2299 mds2sync=$(comma_list $mds2sync)
2301 # sync MDS transactions
2302 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2304 # wait till all changes are sent and commmitted by OSTs
2305 # for ldiskfs space is released upon execution, but DMU
2306 # do this upon commit
2309 while [[ $WAIT -ne $MAX_WAIT ]]; do
2310 changes=$(do_nodes $mds2sync \
2311 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2312 #echo "$node: $changes changes on all"
2313 if [[ $changes -eq 0 ]]; then
2314 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2322 echo "Delete is not completed in $((etime - stime)) seconds"
2323 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2329 # we can use "for" here because we are waiting the slowest
2330 for host in ${hostlist//,/ }; do
2331 check_network "$host" 900
2333 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2340 for facet in ${facetlist//,/ }; do
2341 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2343 wait_for_host $hostlist
2346 _wait_recovery_complete () {
2349 # Use default policy if $2 is not passed by caller.
2350 local MAX=${2:-$(max_recovery_time)}
2355 while [ $WAIT -lt $MAX ]; do
2356 STATUS=$(lctl get_param -n $param | grep status)
2358 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2361 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2363 echo "$param recovery not done in $MAX sec. $STATUS"
2367 wait_recovery_complete () {
2370 # with an assumption that at_max is the same on all nodes
2371 local MAX=${2:-$(max_recovery_time)}
2374 if [ "$FAILURE_MODE" = HARD ]; then
2375 facets=$(facets_on_host $(facet_active_host $facet))
2377 echo affected facets: $facets
2379 # we can use "for" here because we are waiting the slowest
2380 for facet in ${facets//,/ }; do
2381 local var_svc=${facet}_svc
2382 local param="*.${!var_svc}.recovery_status"
2384 local host=$(facet_active_host $facet)
2385 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2389 wait_mds_ost_sync () {
2390 # just because recovery is done doesn't mean we've finished
2391 # orphan cleanup. Wait for llogs to get synchronized.
2392 echo "Waiting for orphan cleanup..."
2393 # MAX value includes time needed for MDS-OST reconnection
2394 local MAX=$(( TIMEOUT * 2 ))
2395 local WAIT_TIMEOUT=${1:-$MAX}
2398 local list=$(comma_list $(mdts_nodes))
2399 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2400 if ! do_facet $SINGLEMDS \
2401 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2403 # old way, use mds_sync
2405 list=$(comma_list $(osts_nodes))
2406 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2409 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2410 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2411 local -a sync=($(do_nodes $list "$cmd"))
2414 for ((i=0; i<${#sync[@]}; i++)); do
2416 [ ${sync[$i]} -eq 1 ] && continue
2418 [ ${sync[$i]} -eq 0 ] && continue
2420 # there is a not finished MDS-OST synchronization
2424 sleep 2 # increase waiting time and cover statfs cache
2425 [ ${con} -eq 1 ] && return 0
2426 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2430 # show which nodes are not finished.
2431 do_nodes $list "$cmd"
2432 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2436 # Wait OSTs to be active on both client and MDT side.
2438 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2439 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2440 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2441 error "wait_update OSTs up on client failed"
2443 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
2444 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
2445 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2446 error "wait_update OSTs up on MDT0000 failed"
2449 wait_destroy_complete () {
2450 echo "Waiting for local destroys to complete"
2451 # MAX value shouldn't be big as this mean server responsiveness
2452 # never increase this just to make test pass but investigate
2453 # why it takes so long time
2456 while [ $WAIT -lt $MAX ]; do
2457 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2461 for ((i=0; i<${#RPCs[@]}; i++)); do
2462 [ ${RPCs[$i]} -eq 0 ] && continue
2463 # there are still some destroy RPCs in flight
2468 [ ${con} -eq 1 ] && return 0 # done waiting
2469 echo "Waiting ${WAIT}s for local destroys to complete"
2472 echo "Local destroys weren't done in $MAX sec."
2476 wait_delete_completed() {
2477 wait_delete_completed_mds $1 || return $?
2478 wait_destroy_complete
2487 # conf-sanity 31 takes a long time cleanup
2488 while [ $WAIT -lt 300 ]; do
2489 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2490 [ -z "${running}" ] && return 0
2491 echo "waited $WAIT for${running}"
2492 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2494 WAIT=$((WAIT + INTERVAL))
2496 echo "service didn't stop after $WAIT seconds. Still running:"
2501 wait_remote_prog () {
2507 [ "$PDSH" = "no_dsh" ] && return 0
2509 while [ $WAIT -lt $2 ]; do
2510 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2511 [ -z "${running}" ] && return 0 || true
2512 echo "waited $WAIT for: "
2514 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2516 WAIT=$((WAIT + INTERVAL))
2518 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2519 [ -z "$pids" ] && return 0
2520 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2521 # FIXME: not portable
2522 for pid in $pids; do
2523 cat /proc/${pid}/status || true
2524 cat /proc/${pid}/wchan || true
2526 kill -9 $pid || true
2535 local clients=${1:-$CLIENTS}
2537 if [ -z "$clients" ]; then
2540 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2546 # not every config has many clients
2552 # usually checked on particular client or locally
2561 client_reconnect_try() {
2562 local f=$MOUNT/recon
2565 if [ -z "$CLIENTS" ]; then
2566 $LFS df $MOUNT; uname -n >> $f
2568 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2570 echo "Connected clients: $(cat $f)"
2571 ls -l $f > /dev/null
2575 client_reconnect() {
2576 # one client_reconnect_try call does not always do the job...
2578 client_reconnect_try && break
2583 affected_facets () {
2586 local host=$(facet_active_host $facet)
2587 local affected=$facet
2589 if [ "$FAILURE_MODE" = HARD ]; then
2590 affected=$(facets_up_on_host $host)
2596 local E2FSCK_ON_MDT0=false
2597 if [ "$1" == "--fsck" ]; then
2599 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2611 #Because it will only get up facets, we need get affected
2612 #facets before shutdown
2613 #For HARD Failure mode, it needs make sure facets on the same
2614 #HOST will only be shutdown and reboot once
2615 for facet in ${facets//,/ }; do
2616 local affected_facet
2618 #check whether facet has been included in other affected facets
2619 for ((index=0; index<$total; index++)); do
2620 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2623 if [ $skip -eq 0 ]; then
2624 affecteds[$total]=$(affected_facets $facet)
2629 for ((index=0; index<$total; index++)); do
2630 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2631 local host=$(facet_active_host $facet)
2632 echo "Failing ${affecteds[index]} on $host"
2633 shutdown_facet $facet
2636 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2637 $(mdsdevname 1) "-n" || error "Running e2fsck")
2639 for ((index=0; index<$total; index++)); do
2640 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2641 echo reboot facets: ${affecteds[index]}
2645 change_active ${affecteds[index]}
2647 wait_for_facet ${affecteds[index]}
2648 # start mgs first if it is affected
2649 if ! combined_mgs_mds &&
2650 list_member ${affecteds[index]} mgs; then
2651 mount_facet mgs || error "Restart of mgs failed"
2653 # FIXME; has to be changed to mount all facets concurrently
2654 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2655 echo mount facets: ${affecteds[index]}
2656 mount_facets ${affecteds[index]}
2666 do_facet $facet "sync; sync; sync"
2669 # make sure there will be no seq change
2670 local clients=${CLIENTS:-$HOSTNAME}
2671 local f=fsa-\\\$\(hostname\)
2672 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2673 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2675 local svc=${facet}_svc
2676 do_facet $facet $LCTL --device ${!svc} notransno
2678 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2679 # in-memory state has to be cleared by either rebooting the host or
2680 # exporting and reimporting the pool.
2682 # Although the uberblocks are not updated when a pool is freezed,
2683 # transactions are still written to the disks. Modified blocks may be
2684 # cached in memory when tests try reading them back. The
2685 # export-and-reimport process also evicts any cached pool data from
2686 # memory to provide the correct "data loss" semantics.
2688 # In the test framework, the exporting and importing operations are
2689 # handled by stop() and mount_facet() separately, which are used
2690 # inside fail() and fail_abort().
2692 do_facet $facet $LCTL --device ${!svc} readonly
2693 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2694 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2697 replay_barrier_nodf() {
2698 local facet=$1 echo running=${running}
2699 do_facet $facet "sync; sync; sync"
2700 local svc=${facet}_svc
2701 echo Replay barrier on ${!svc}
2702 do_facet $facet $LCTL --device ${!svc} notransno
2703 do_facet $facet $LCTL --device ${!svc} readonly
2704 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2705 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2708 replay_barrier_nosync() {
2709 local facet=$1 echo running=${running}
2710 local svc=${facet}_svc
2711 echo Replay barrier on ${!svc}
2712 do_facet $facet $LCTL --device ${!svc} notransno
2713 do_facet $facet $LCTL --device ${!svc} readonly
2714 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2715 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2719 # Get Lustre client uuid for a given Lustre mount point.
2722 local mntpnt=${1:-$MOUNT}
2724 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2725 local uuid=$($LCTL get_param -n llite.$name.uuid)
2730 mds_evict_client() {
2731 local mntpnt=${1:-$MOUNT}
2732 local uuid=$(get_client_uuid $mntpnt)
2734 do_facet $SINGLEMDS \
2735 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2738 ost_evict_client() {
2739 local mntpnt=${1:-$MOUNT}
2740 local uuid=$(get_client_uuid $mntpnt)
2743 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2748 local clients=${CLIENTS:-$HOSTNAME}
2750 facet_failover $* || error "failover: $?"
2751 wait_clients_import_state "$clients" "$facets" FULL
2752 clients_up || error "post-failover stat: $?"
2757 facet_failover $facet
2763 change_active $facet
2764 wait_for_facet $facet
2765 mount_facet $facet -o abort_recovery
2766 clients_up || echo "first stat failed: $?"
2767 clients_up || error "post-failover stat: $?"
2770 host_nids_address() {
2774 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
2778 if [ "$1" = "'*'" ]; then echo \'*\'; else
2784 if [[ -n "$NETTYPE" ]]; then
2785 h2name_or_ip "$1" "$NETTYPE"
2787 h2name_or_ip "$1" "$2"
2790 declare -fx h2nettype
2792 # Wrapper function to print the deprecation warning
2794 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
2795 if [[ -n "$NETTYPE" ]]; then
2798 h2nettype "$1" "tcp"
2802 # Wrapper function to print the deprecation warning
2804 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
2805 if [[ -n "$NETTYPE" ]]; then
2808 h2nettype "$1" "o2ib"
2812 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2813 # expressions format. As a bonus we can then just pass in those variables
2814 # to pdsh. What this function does is take a HOSTLIST type string and
2815 # expand it into a space deliminated list for us.
2823 [ -z "$hostlist" ] && return
2825 # Translate the case of [..],..,[..] to [..] .. [..]
2826 list="${hostlist/],/] }"
2828 [[ "$front" == *,* ]] && {
2831 list=${list/${old}/${new}}
2834 for item in $list; do
2835 # Test if we have any []'s at all
2836 if [ "$item" != "${item/\[/}" ]; then {
2837 # Expand the [*] into list
2841 if [ "$name" != "$item" ]; then
2842 group=${item#$name[*}
2845 for range in ${group//,/ }; do
2851 # Number of leading zeros
2854 end=$(echo $end | sed 's/0*//')
2855 [[ -z "$end" ]] && end=0
2856 [[ $padlen2 -gt $padlen ]] && {
2857 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2860 begin=$(echo $begin | sed 's/0*//')
2861 [ -z $begin ] && begin=0
2863 if [ ! -z "${begin##[!0-9]*}" ]; then
2864 order=$(seq -f "%0${padlen}g" $begin $end)
2866 order=$(eval echo {$begin..$end});
2869 for num in $order; do
2870 value="${name#*,}${num}${back}"
2871 [ "$value" != "${value/\[/}" ] && {
2872 value=$(hostlist_expand "$value")
2874 myList="$myList $value"
2879 myList="$myList $item"
2882 myList=${myList//,/ }
2883 myList=${myList:1} # Remove first character which is a space
2885 # Filter any duplicates without sorting
2887 myList="${list%% *}"
2889 while [[ "$list" != ${myList##* } ]]; do
2890 local tlist=" $list"
2891 list=${tlist// ${list%% *} / }
2893 myList="$myList ${list%% *}"
2895 myList="${myList%* }";
2897 # We can select an object at an offset in the list
2900 for item in $myList; do
2902 [ $cnt -eq $offset ] && {
2906 [ $(get_node_count $myList) -ne 1 ] && myList=""
2915 [ "$facet" == client ] && echo -n $HOSTNAME && return
2916 varname=${facet}_HOST
2917 if [ -z "${!varname}" ]; then
2918 if [ "${facet:0:3}" == "ost" ]; then
2919 local fh=${facet%failover}_HOST
2920 eval export ${facet}_HOST=${!fh}
2921 if [ -z "${!varname}" ]; then
2922 eval export ${facet}_HOST=${ost_HOST}
2924 elif [ "${facet:0:3}" == "mdt" -o \
2925 "${facet:0:3}" == "mds" -o \
2926 "${facet:0:3}" == "mgs" ]; then
2927 eval export ${facet}_HOST=${mds_HOST}
2933 facet_failover_host() {
2937 var=${facet}failover_HOST
2938 if [ -n "${!var}" ]; then
2943 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2944 "${facet:0:3}" == "mgs" ]; then
2946 eval export ${facet}failover_host=${mds_HOST}
2951 if [[ $facet == ost* ]]; then
2952 eval export ${facet}failover_host=${ost_HOST}
2960 local activevar=${facet}active
2962 if [ -f $TMP/${facet}active ] ; then
2963 source $TMP/${facet}active
2966 active=${!activevar}
2967 if [ -z "$active" ] ; then
2974 facet_active_host() {
2975 facet_host $(facet_active $1)
2978 # Get the passive failover partner host of facet.
2979 facet_passive_host() {
2981 [[ $facet = client ]] && return
2983 local host=${facet}_HOST
2984 local failover_host=${facet}failover_HOST
2985 local active_host=$(facet_active_host $facet)
2987 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2989 if [[ $active_host = ${!host} ]]; then
2990 echo -n ${!failover_host}
3000 facetlist=$(exclude_items_from_list $facetlist mgs)
3002 for facet in ${facetlist//,/ }; do
3003 local failover=${facet}failover
3004 local host=`facet_host $failover`
3005 [ -z "$host" ] && return
3007 local curactive=`facet_active $facet`
3008 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3009 eval export ${facet}active=$facet
3011 eval export ${facet}active=$failover
3013 # save the active host for this facet
3014 local activevar=${facet}active
3015 echo "$activevar=${!activevar}" > $TMP/$activevar
3016 [[ $facet = mds1 ]] && combined_mgs_mds && \
3017 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3018 local TO=`facet_active_host $facet`
3019 echo "Failover $facet to $TO"
3025 # do not stripe off hostname if verbose, bug 19215
3026 if [ x$1 = x--verbose ]; then
3034 if [ "$HOST" = "$HOSTNAME" ]; then
3036 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3037 echo "cannot run remote command on $HOST with $myPDSH"
3041 echo "CMD: $HOST $@" >&2
3042 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3045 if [ "$myPDSH" = "rsh" ]; then
3046 # we need this because rsh does not return exit code of an executed command
3047 local command_status="$TMP/cs"
3048 rsh $HOST ":> $command_status"
3049 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3050 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3051 echo command failed >$command_status"
3052 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3057 # print HOSTNAME for myPDSH="no_dsh"
3058 if [[ $myPDSH = no_dsh ]]; then
3059 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3061 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3064 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3066 return ${PIPESTATUS[0]}
3070 do_node --verbose "$@"
3073 single_local_node () {
3074 [ "$1" = "$HOSTNAME" ]
3077 # Outputs environment variable assignments that should be passed to remote nodes
3081 local facets=$(get_facets)
3084 for var in ${!MODOPTS_*}; do
3085 value=${!var//\"/\\\"}
3086 echo -n " ${var}=\"$value\""
3089 for facet in ${facets//,/ }; do
3091 if [ -n "${!var}" ]; then
3092 echo -n " $var=${!var}"
3096 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3097 if [ -n "${!var}" ]; then
3098 echo -n " $var=${!var}"
3102 for var in VERBOSE; do
3103 if [ -n "${!var}" ]; then
3104 echo -n " $var=${!var}"
3108 if [ -n "$FSTYPE" ]; then
3109 echo -n " FSTYPE=$FSTYPE"
3112 for var in LNETLND NETTYPE; do
3113 if [ -n "${!var}" ]; then
3114 echo -n " $var=${!var}"
3121 # do not stripe off hostname if verbose, bug 19215
3122 if [ x$1 = x--verbose ]; then
3130 if single_local_node $rnodes; then
3132 do_nodev $rnodes "$@"
3134 do_node $rnodes "$@"
3139 # This is part from do_node
3142 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3143 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3145 export FANOUT=$(get_node_count "${rnodes//,/ }")
3147 echo "CMD: $rnodes $@" >&2
3148 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3151 # do not replace anything from pdsh output if -N is used
3152 # -N Disable hostname: prefix on lines of output.
3153 if $verbose || [[ $myPDSH = *-N* ]]; then
3154 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3156 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3158 return ${PIPESTATUS[0]}
3162 # Execute commands on a single service's host
3164 # The \a facet (service) may be on a local or remote node, which is
3165 # determined at the time the command is run.
3167 # usage: do_facet $facet command [arg ...]
3171 local HOST=$(facet_active_host $facet)
3172 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3176 # Function: do_facet_random_file $FACET $FILE $SIZE
3177 # Creates FILE with random content on the given FACET of given SIZE
3179 do_facet_random_file() {
3183 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3184 do_facet $facet "$cmd 2>/dev/null"
3187 do_facet_create_file() {
3191 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3192 do_facet $facet "$cmd 2>/dev/null"
3196 do_nodes --verbose "$@"
3202 # make sure its not already running
3204 rm -f $TMP/${facet}active
3205 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3206 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3208 if [[ $(facet_fstype $facet) == zfs ]]; then
3210 # After formatting a ZFS target, "cachefile=none" property will
3211 # be set on the ZFS storage pool so that the pool is not
3212 # automatically imported on system startup. And then the pool
3213 # will be exported so as to leave the importing and exporting
3214 # operations handled by mount_facet() and stop() separately.
3216 refresh_partition_table $facet $(facet_vdevice $facet)
3217 disable_zpool_cache $facet
3222 # Device formatted as ost
3225 local DEVNAME=OSTDEV$num
3227 local fstype=$(facet_fstype ost$num)
3231 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3232 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3234 #try $OSTZFSDEVn - independent of vdev
3235 DEVNAME=OSTZFSDEV$num
3236 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3238 error "unknown fstype!";;
3244 # Physical device location of data
3250 local fstype=$(facet_fstype ost$num)
3254 # vdevs are not supported by ldiskfs
3257 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3258 # Device formatted by zfs
3260 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3262 error "unknown fstype!";;
3268 # Logical device formatted for lustre
3271 local DEVNAME=MDSDEV$num
3273 local fstype=$(facet_fstype mds$num)
3277 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3278 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3280 # try $MDSZFSDEVn - independent of vdev
3281 DEVNAME=MDSZFSDEV$num
3282 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3284 error "unknown fstype!";;
3290 # Physical location of data
3294 local fstype=$(facet_fstype mds$num)
3298 # vdevs are not supported by ldiskfs
3301 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3302 # Device formatted by ZFS
3303 local DEVNAME=MDSDEV$num
3304 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3306 error "unknown fstype!";;
3314 local fstype=$(facet_fstype mgs)
3318 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3319 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3320 DEVPTR=$(mdsdevname 1)
3325 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3326 ( [ -z "$MGSZFSDEV" ] &&
3327 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3328 DEVPTR=$(mdsdevname 1)
3330 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3333 error "unknown fstype!";;
3342 local fstype=$(facet_fstype mgs)
3346 # vdevs are not supported by ldiskfs
3349 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3350 ( [ -z "$MGSDEV" ] &&
3351 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3352 VDEVPTR=$(mdsvdevname 1)
3353 elif [ -n "$MGSDEV" ]; then
3357 error "unknown fstype!";;
3365 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3367 local var=${facet}_MOUNT
3368 eval mntpt=${!var:-${MOUNT}-$facet}
3375 local dev=$(facet_device $facet)
3376 local mnt=${2:-$(facet_mntpt $facet)