3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export GSS_PIPEFS=false
15 export SHARED_KEY=${SHARED_KEY:-false}
16 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
17 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
18 export SK_MOUNTED=${SK_MOUNTED:-false}
19 export SK_FLAVOR=${SK_FLAVOR:-ski}
20 export SK_NO_KEY=${SK_NO_KEY:-true}
21 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
22 export SK_S2S=${SK_S2S:-false}
23 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
24 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
25 export IDENTITY_UPCALL=default
27 # specify environment variable containing batch job name for server statistics
28 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
30 #export PDSH="pdsh -S -Rssh -w"
31 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
32 export UMOUNT=${UMOUNT:-"umount -d"}
34 export LSNAPSHOT_CONF="/etc/ldev.conf"
35 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
37 # sles12 umount has a issue with -d option
38 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
39 export UMOUNT="umount"
42 # function used by scripts run on remote nodes
43 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
44 . $LUSTRE/tests/functions.sh
45 . $LUSTRE/tests/yaml.sh
47 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
49 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
51 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
53 if [ -f "$EXCEPT_LIST_FILE" ]; then
54 echo "Reading test skip list from $EXCEPT_LIST_FILE"
59 # check config files for options in decreasing order of preference
60 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
61 MODPROBECONF=/etc/modprobe.d/lustre.conf
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
63 MODPROBECONF=/etc/modprobe.d/Lustre
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
65 MODPROBECONF=/etc/modprobe.conf
67 sanitize_parameters() {
68 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
71 if [ -d "$path" ]; then
72 eval export $i=$(echo $path | sed -r 's/\/+$//g')
78 [[ $DIR/ = $MOUNT/* ]] ||
79 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
80 [[ $DIR1/ = $MOUNT1/* ]] ||
81 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
82 [[ $DIR2/ = $MOUNT2/* ]] ||
83 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
85 [ -n "$failed" ] && exit 99 || true
89 echo "usage: $0 [-r] [-f cfgfile]"
97 [ -z "$DEFAULT_SUITES"] && return 0
98 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
100 local form="%-13s %-17s %-9s %s %s\n"
101 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
102 echo "------------------------------------------------------------------------------------"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 [ "${!O}" = "no" ] && continue || true
106 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
107 local log=${TMP}/${o}.log
108 if is_sanity_benchmark $o; then
109 log=${TMP}/sanity-benchmark.log
114 local status=Unfinished
116 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
118 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
119 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
120 total=$(grep duration $log | awk '{ print $2 }')
121 if [ "${!O}" = "done" ]; then
125 local durations=$(egrep "^PASS|^FAIL" $log |
126 tr -d "("| sed s/s\)$//g |
127 awk '{ print $2":"$3"|" }')
128 details=$(printf "%s\n%s %s %s\n" "$details" \
129 "DDETAILS" "$O" "$(echo $durations)")
132 printf "$form" $status "$O" "${total}" "E=$skipped"
133 printf "$form" "-" "-" "-" "S=$(echo $slow)"
136 for O in $DEFAULT_SUITES; do
137 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
138 if [ "${!O}" = "no" ]; then
139 printf "$form" "Skipped" "$O" ""
143 # print the detailed tests durations if DDETAILS=true
150 export LUSTRE=$(absolute_path $LUSTRE)
151 export TESTSUITE=$(basename $0 .sh)
152 export TEST_FAILED=false
153 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
154 export RPC_MODE=${RPC_MODE:-false}
155 export DO_CLEANUP=${DO_CLEANUP:-true}
156 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
158 export MKE2FS=$MKE2FS
159 if [ -z "$MKE2FS" ]; then
160 if which mkfs.ldiskfs >/dev/null 2>&1; then
161 export MKE2FS=mkfs.ldiskfs
167 export DEBUGFS=$DEBUGFS
168 if [ -z "$DEBUGFS" ]; then
169 if which debugfs.ldiskfs >/dev/null 2>&1; then
170 export DEBUGFS=debugfs.ldiskfs
172 export DEBUGFS=debugfs
176 export TUNE2FS=$TUNE2FS
177 if [ -z "$TUNE2FS" ]; then
178 if which tunefs.ldiskfs >/dev/null 2>&1; then
179 export TUNE2FS=tunefs.ldiskfs
181 export TUNE2FS=tune2fs
185 export E2LABEL=$E2LABEL
186 if [ -z "$E2LABEL" ]; then
187 if which label.ldiskfs >/dev/null 2>&1; then
188 export E2LABEL=label.ldiskfs
190 export E2LABEL=e2label
194 export DUMPE2FS=$DUMPE2FS
195 if [ -z "$DUMPE2FS" ]; then
196 if which dumpfs.ldiskfs >/dev/null 2>&1; then
197 export DUMPE2FS=dumpfs.ldiskfs
199 export DUMPE2FS=dumpe2fs
203 export E2FSCK=$E2FSCK
204 if [ -z "$E2FSCK" ]; then
205 if which fsck.ldiskfs >/dev/null 2>&1; then
206 export E2FSCK=fsck.ldiskfs
212 export RESIZE2FS=$RESIZE2FS
213 if [ -z "$RESIZE2FS" ]; then
214 if which resizefs.ldiskfs >/dev/null 2>&1; then
215 export RESIZE2FS=resizefs.ldiskfs
217 export RESIZE2FS=resize2fs
221 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
222 export FSCK_MAX_ERR=4 # File system errors left uncorrected
224 export ZFS=${ZFS:-zfs}
225 export ZPOOL=${ZPOOL:-zpool}
226 export ZDB=${ZDB:-zdb}
227 export PARTPROBE=${PARTPROBE:-partprobe}
229 #[ -d /r ] && export ROOT=${ROOT:-/r}
230 export TMP=${TMP:-$ROOT/tmp}
231 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
232 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
233 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
235 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
236 if ! echo $PATH | grep -q $LUSTRE/utils; then
237 export PATH=$LUSTRE/utils:$PATH
239 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
240 export PATH=$LUSTRE/utils/gss:$PATH
242 if ! echo $PATH | grep -q $LUSTRE/tests; then
243 export PATH=$LUSTRE/tests:$PATH
245 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
246 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
248 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
249 [ ! -f "$LST" ] && export LST=$(which lst)
250 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
251 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
252 export MCREATE=${MCREATE:-mcreate}
253 export MULTIOP=${MULTIOP:-multiop}
254 # Ubuntu, at least, has a truncate command in /usr/bin
255 # so fully path our truncate command.
256 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
257 export FSX=${FSX:-$LUSTRE/tests/fsx}
258 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
259 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
260 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
261 export PATH=$LUSTRE/tests/racer:$PATH:
263 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
264 export PATH=$LUSTRE/tests/mpi:$PATH
266 export RSYNC_RSH=${RSYNC_RSH:-rsh}
268 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
269 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
270 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
271 [ ! -f "$LFS" ] && export LFS=$(which lfs)
272 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
273 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
275 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
276 if [ ! -f "$L_GETIDENTITY" ]; then
277 if `which l_getidentity > /dev/null 2>&1`; then
278 export L_GETIDENTITY=$(which l_getidentity)
280 export L_GETIDENTITY=NONE
283 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
284 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
285 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
286 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
287 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
288 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
289 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
290 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
291 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
292 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
293 [ ! -f "$LUSTRE_RMMOD" ] &&
294 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
295 export LUSTRE_ROUTES_COVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
296 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
297 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
298 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
299 [ ! -f "$LFS_MIGRATE" ] &&
300 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
301 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
302 [ ! -f "$LR_READER" ] &&
303 export LR_READER=$(which lr_reader 2> /dev/null)
304 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
305 export NAME=${NAME:-local}
306 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
307 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
308 export LGSSD=$(which lgssd)
309 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
310 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
311 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
313 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
315 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
316 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
318 if [ "$ACCEPTOR_PORT" ]; then
319 export PORT_OPT="--port $ACCEPTOR_PORT"
323 $RPC_MODE || echo "Using GSS shared-key feature"
324 which lgss_sk > /dev/null 2>&1 ||
325 error_exit "built with lgss_sk disabled! SEC=$SEC"
333 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
334 which lgss_keyring > /dev/null 2>&1 ||
335 error_exit "built with gss disabled! SEC=$SEC"
346 IDENTITY_UPCALL=false
350 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
352 # Paths on remote nodes, if different
353 export RLUSTRE=${RLUSTRE:-$LUSTRE}
354 export RPWD=${RPWD:-$PWD}
355 export I_MOUNTED=${I_MOUNTED:-"no"}
356 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
357 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
358 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
359 ! -f $LUSTRE/mdt/mdt.ko ]; then
360 export CLIENTMODSONLY=yes
363 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
364 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
368 while getopts "rvwf:" opt $*; do
373 w) WRITECONF=writeconf;;
378 shift $((OPTIND - 1))
381 # print the durations of each test if "true"
382 DDETAILS=${DDETAILS:-false}
383 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
388 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
395 ncpts=$(do_facet $facet "lctl get_param -n " \
396 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
398 if [ $ncpts -eq 0 ]; then
405 # Return a numeric version code based on a version string. The version
406 # code is useful for comparison two version strings to see which is newer.
408 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
409 eval set -- $(tr "[:punct:]" " " <<< $*)
411 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
414 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
415 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
417 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
419 # usage: lustre_build_version
421 # All Lustre versions support "lctl get_param" to report the version of the
422 # code running in the kernel (what our tests are interested in), but it
423 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
424 # the "version" parameter doesn't include "lustre: " at the beginning.
425 # If that fails, call "lctl lustre_build_version" which prints either (or both)
426 # the userspace and kernel build versions, but until 2.8.55 required root
427 # access to get the Lustre kernel version. If that also fails, fall back to
428 # using "lctl --version", which is easy to parse and works without the kernel
429 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
430 # not the module version, though they are usually the same.
432 # Various commands and their output format for different Lustre versions:
433 # lctl get_param version: 2.9.55
434 # lctl get_param version: lustre: 2.8.53
435 # lctl get_param version: lustre: 2.6.52
436 # kernel: patchless_client
437 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
438 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
439 # lctl lustre_build_version: error: lustre_build_version: Permission denied
440 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
441 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
442 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
443 # lctl --version: lctl 2.6.50
445 # output: prints version string to stdout in (up to 4) dotted-decimal values
446 lustre_build_version() {
447 local facet=${1:-client}
448 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
449 $LCTL lustre_build_version 2>/dev/null ||
450 $LCTL --version 2>/dev/null | cut -d' ' -f2")
451 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
452 [ -n "$lver" ] && ver="$lver"
454 sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' -e 's/_/./g' <<<$ver |
458 # Report the Lustre numeric build version code for the supplied facet.
459 lustre_version_code() {
460 version_code $(lustre_build_version $1)
464 /sbin/lsmod | grep -q "^\<$1\>"
476 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
479 # parallels can't load modules directly from prlfs, use /tmp instead
480 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
481 local target="$(mktemp)"
483 cp "$module" "$target"
486 [[ $rc == 0 ]] && PRLFS=true
494 # Load a module on the system where this is running.
496 # usage: load_module module_name [module arguments for insmod/modprobe]
498 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
499 # will be used as the arguments. Otherwise arguments will be obtained from
500 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
507 BASE=$(basename $module $EXT)
509 module_loaded ${BASE} && return
511 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
512 # else from modprobe.conf
513 if [ $# -eq 0 ]; then
514 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
515 # Bash until 4.x, so we resort to eval.
516 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
517 eval set -- \$$optvar
518 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
519 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
521 opt=$(awk -v var="^options $BASE" '$0 ~ var \
522 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
523 set -- $(echo -n $opt)
525 # Ensure we have accept=all for lnet
526 if [ $(basename $module) = lnet ]; then
527 # OK, this is a bit wordy...
528 local arg accept_all_present=false
531 [ "$arg" = accept=all ] && \
532 accept_all_present=true
534 $accept_all_present || set -- "$@" accept=all
540 [ $# -gt 0 ] && echo "${module} options: '$*'"
542 # Note that insmod will ignore anything in modprobe.conf, which is why
543 # we're passing options on the command-line.
544 if [[ "$BASE" == "lnet_selftest" ]] &&
545 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
546 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
547 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
548 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
549 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
551 # must be testing a "make install" or "rpm" installation
552 # note failed to load ptlrpc_gss is considered not fatal
553 if [[ "$BASE" == "ptlrpc_gss" ]]; then
554 modprobe $BASE "$@" 2>/dev/null ||
555 echo "gss/krb5 is not supported"
562 load_modules_local() {
563 if [ -n "$MODPROBE" ]; then
565 echo "Using modprobe to load modules"
569 echo Loading modules from $LUSTRE
573 if [ -f /sys/devices/system/cpu/online ]; then
574 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
575 echo "detected $ncpus online CPUs by sysfs"
577 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
579 if [ $rc -eq 0 ]; then
580 echo "detected $ncpus online CPUs by getconf"
582 echo "Can't detect number of CPUs"
587 # if there is only one CPU core, libcfs can only create one partition
588 # if there is more than 4 CPU cores, libcfs should create multiple CPU
589 # partitions. So we just force libcfs to create 2 partitions for
590 # system with 2 or 4 cores
591 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
592 # force to enable multiple CPU partitions
593 echo "Force libcfs to create 2 CPU partitions"
594 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
596 echo "libcfs will create CPU partition based on online CPUs"
599 load_module ../libcfs/libcfs/libcfs
600 # Prevent local MODOPTS_LIBCFS being passed as part of environment
601 # variable to remote nodes
605 load_module ../lnet/lnet/lnet
607 LNDPATH=${LNDPATH:-"../lnet/klnds"}
608 if [ -z "$LNETLND" ]; then
610 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
611 tcp*) LNETLND="socklnd/ksocklnd" ;;
612 *) local lnd="${NETTYPE%%[0-9]}lnd"
613 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
614 LNETLND="$lnd/k$lnd" ||
615 LNETLND="socklnd/ksocklnd"
618 load_module ../lnet/klnds/$LNETLND
619 load_module obdclass/obdclass
620 load_module ptlrpc/ptlrpc
621 load_module ptlrpc/gss/ptlrpc_gss
629 load_module obdecho/obdecho
630 if ! client_only; then
631 SYMLIST=/proc/kallsyms
632 grep -q crc16 $SYMLIST ||
633 { modprobe crc16 2>/dev/null || true; }
634 grep -q -w jbd2 $SYMLIST ||
635 { modprobe jbd2 2>/dev/null || true; }
636 load_module lfsck/lfsck
637 [ "$LQUOTA" != "no" ] &&
638 load_module quota/lquota $LQUOTAOPTS
639 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
640 lsmod | grep zfs >&/dev/null || modprobe zfs
641 load_module osd-zfs/osd_zfs
643 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
644 grep -q exportfs_decode_fh $SYMLIST ||
645 { modprobe exportfs 2> /dev/null || true; }
646 grep -q -w mbcache $SYMLIST ||
647 { modprobe mbcache 2>/dev/null || true; }
648 load_module ../ldiskfs/ldiskfs
649 load_module osd-ldiskfs/osd_ldiskfs
661 load_module llite/lustre
662 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
664 rm -f $OGDB/ogdb-$HOSTNAME
665 $LCTL modules > $OGDB/ogdb-$HOSTNAME
667 # 'mount' doesn't look in $PATH, just sbin
668 local mount_lustre=$LUSTRE/utils/mount.lustre
669 if [ -f $mount_lustre ]; then
670 local sbin_mount=$(readlink -f /sbin)/mount.lustre
671 if grep -qw "$sbin_mount" /proc/mounts; then
672 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
674 if ! grep -qw "$sbin_mount" /proc/mounts; then
675 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
676 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
677 cat <<- EOF > "$sbin_mount"
680 echo "This $sbin_mount just a mountpoint." 1>&2
681 echo "It is never supposed to be run." 1>&2
682 logger -p emerg -- "using stub $sbin_mount $@"
685 chmod a+x $sbin_mount
687 mount --bind $mount_lustre $sbin_mount ||
688 error "can't bind $mount_lustre to $sbin_mount"
696 # load modules on remote nodes optionally
697 # lustre-tests have to be installed on these nodes
698 if $LOAD_MODULES_REMOTE; then
699 local list=$(comma_list $(remote_nodes_list))
700 if [ -n "$list" ]; then
701 echo "loading modules on: '$list'"
702 do_rpc_nodes "$list" load_modules_local
708 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
709 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
710 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
711 echo "$LEAK_LUSTRE" 1>&2
712 echo "$LEAK_PORTALS" 1>&2
713 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
714 echo "Memory leaks detected"
715 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
721 wait_exit_ST client # bug 12845
723 $LUSTRE_RMMOD ldiskfs || return 2
725 if $LOAD_MODULES_REMOTE; then
726 local list=$(comma_list $(remote_nodes_list))
727 if [ -n "$list" ]; then
728 echo "unloading modules on: '$list'"
729 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
730 do_rpc_nodes "$list" check_mem_leak
734 local sbin_mount=$(readlink -f /sbin)/mount.lustre
735 if grep -qe "$sbin_mount " /proc/mounts; then
736 umount $sbin_mount || true
737 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
741 check_mem_leak || return 254
743 echo "modules unloaded."
748 local facet=${1:-$SINGLEMDS}
751 case $(facet_fstype $facet) in
752 ldiskfs) size=50;; # largest seen is 44, leave some headroom
753 zfs) size=$(lctl get_param osc.$FSNAME-OST*.import |
754 awk '/grant_block_size:/ { print $2 * 2; exit; }');;
761 local facet=${1:-$SINGLEMDS}
762 local fstype=$(facet_fstype $facet)
765 ldiskfs) size=4;; # ~4KB per inode
766 zfs) size=11;; # 10 to 11KB per inode
772 check_gss_daemon_nodes() {
776 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
777 if [ \\\"\\\$num\\\" -ne 1 ]; then
778 echo \\\$num instance of $dname;
783 check_gss_daemon_facet() {
787 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
788 if [ $num -ne 1 ]; then
789 echo "$num instance of $dname on $facet"
798 echo Stopping $@ on $list
799 do_nodes $list "killall -2 $@ 2>/dev/null || true"
802 # start gss daemons on all nodes, or "daemon" on "nodes" if set
803 start_gss_daemons() {
807 if [ "$nodes" ] && [ "$daemon" ] ; then
808 echo "Starting gss daemon on nodes: $nodes"
809 do_nodes $nodes "$daemon" || return 8
813 nodes=$(comma_list $(mdts_nodes))
814 echo "Starting gss daemon on mds: $nodes"
816 # Start all versions, in case of switching
817 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
819 do_nodes $nodes "$LSVCGSSD -v" || return 1
822 do_nodes $nodes "$LGSSD -v" || return 2
825 nodes=$(comma_list $(osts_nodes))
826 echo "Starting gss daemon on ost: $nodes"
828 # Start all versions, in case of switching
829 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
831 do_nodes $nodes "$LSVCGSSD -v" || return 3
833 # starting on clients
835 local clients=${CLIENTS:-$HOSTNAME}
837 echo "Starting $LGSSD on clients $clients "
838 do_nodes $clients "$LGSSD -v" || return 4
841 # wait daemons entering "stable" status
845 # check daemons are running
847 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
848 check_gss_daemon_nodes $nodes lsvcgssd || return 5
850 nodes=$(comma_list $(mdts_nodes))
851 check_gss_daemon_nodes $nodes lgssd || return 6
854 check_gss_daemon_nodes $clients lgssd || return 7
859 local nodes=$(comma_list $(mdts_nodes))
861 send_sigint $nodes lsvcgssd lgssd
863 nodes=$(comma_list $(osts_nodes))
864 send_sigint $nodes lsvcgssd
866 nodes=${CLIENTS:-$HOSTNAME}
867 send_sigint $nodes lgssd
871 # Add mount flags for shared key
873 if grep -q skpath <<< "$mt_opts" ; then
874 mt_opts=$(echo $mt_opts |
875 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
877 if [ -z "$mt_opts" ]; then
878 mt_opts="-o skpath=$SK_PATH"
880 mt_opts="$mt_opts,skpath=$SK_PATH"
896 if ! module_loaded ptlrpc_gss; then
897 load_module ptlrpc/gss/ptlrpc_gss
898 module_loaded ptlrpc_gss ||
899 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
902 if $GSS_KRB5 || $GSS_SK; then
903 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
906 if $GSS_SK && $SK_NO_KEY; then
907 local numclients=${1:-$CLIENTCOUNT}
908 local clients=${CLIENTS:-$HOSTNAME}
910 # security ctx config for keyring
913 mount -o bind $SK_OM_PATH /etc/request-key.d/
914 local lgssc_conf_line='create lgssc * * '
915 lgssc_conf_line+=$(which lgss_keyring)
916 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
918 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
919 echo "$lgssc_conf_line" > $lgssc_conf_file
920 [ -e $lgssc_conf_file ] ||
921 error_exit "Could not find key options in $lgssc_conf_file"
923 if ! local_mode; then
924 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
926 do_nodes $(comma_list $(all_nodes)) "mount \
927 -o bind $SK_OM_PATH \
929 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
930 $HOSTNAME:$lgssc_conf_file \
931 $lgssc_conf_file >/dev/null 2>&1"
934 # create shared key on all nodes
935 mkdir -p $SK_PATH/nodemap
936 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
937 $SK_PATH/$FSNAME-*.key
938 # for nodemap testing each client may need own key,
939 # and S2S now requires keys as well, both for "client"
942 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
943 -w $SK_PATH/$FSNAME-nmclient.key \
944 -d /dev/urandom >/dev/null 2>&1
945 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
946 -w $SK_PATH/$FSNAME-s2s-server.key \
947 -d /dev/urandom >/dev/null 2>&1
950 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
951 -d /dev/urandom >/dev/null 2>&1
953 for i in $(seq 0 $((numclients - 1))); do
954 lgss_sk -t server -f$FSNAME -n c$i \
955 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
959 if ! local_mode; then
960 do_nodes $(comma_list $(all_nodes)) "rsync -av \
961 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
963 # Set client keys to client type to generate prime P
965 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
966 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
968 do_nodes $clients "lgss_sk -t client -m \
969 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
970 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
971 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
973 # This is required for servers as well, if S2S in use
975 do_nodes $(comma_list $(mdts_nodes)) \
976 "cp $SK_PATH/$FSNAME-s2s-server.key \
977 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
978 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
980 do_nodes $(comma_list $(osts_nodes)) \
981 "cp $SK_PATH/$FSNAME-s2s-server.key \
982 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
983 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
985 do_nodes $clients "lgss_sk -t client \
986 -m $SK_PATH/$FSNAME-nmclient.key \
989 # mount options for servers and clients
990 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
991 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
992 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
993 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
997 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
999 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1006 # maybe cleanup credential cache?
1013 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1014 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1015 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1019 $RPC_MODE || echo "Cleaning up Shared Key.."
1020 do_nodes $(comma_list $(all_nodes)) "rm -f \
1021 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1022 # Remove the mount and clean up the files we added to SK_PATH
1023 do_nodes $(comma_list $(all_nodes)) "umount \
1024 /etc/request-key.d/"
1025 do_nodes $(comma_list $(all_nodes)) "rm -f \
1026 $SK_OM_PATH/lgssc.conf"
1027 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1034 local var=${facet}_svc
1042 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1043 tr '[:lower:]' '[:upper:]'
1049 if [ $facet == mgs ] || [ $facet == client ]; then
1053 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1061 if [ -n "${!var}" ]; then
1066 var=$(facet_type $facet)FSTYPE
1067 if [ -n "${!var}" ]; then
1072 if [ -n "$FSTYPE" ]; then
1077 if [[ $facet == mgs ]] && combined_mgs_mds; then
1089 local facets=$(get_facets)
1092 for facet in ${facets//,/ }; do
1093 if [ $node == $(facet_host $facet) ] ||
1094 [ $node == "$(facet_failover_host $facet)" ]; then
1095 fstype=$(facet_fstype $facet)
1096 if [[ $fstypes != *$fstype* ]]; then
1097 fstypes+="${fstypes:+,}$fstype"
1106 local num=$(facet_number $facet)
1109 if [[ $(facet_type $facet) = OST ]]; then
1110 index=OSTINDEX${num}
1111 if [[ -n "${!index}" ]]; then
1116 index=${OST_INDICES[num - 1]}
1119 [[ -n "$index" ]] || index=$((num - 1))
1127 local fstype=$(facet_fstype $facet)
1131 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1133 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1134 ${dev} 2>/dev/null");;
1136 error "unknown fstype!";;
1144 local device=$(mdsdevname $num)
1145 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1151 local device=$(ostdevname $num)
1152 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1157 # Get the device of a facet.
1164 mgs) device=$(mgsdevname) ;;
1165 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1166 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1167 fs2mds) device=$(mdsdevname 1_2) ;;
1168 fs2ost) device=$(ostdevname 1_2) ;;
1169 fs3ost) device=$(ostdevname 2_2) ;;
1177 # Get the virtual device of a facet.
1184 mgs) device=$(mgsvdevname) ;;
1185 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1186 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1187 fs2mds) device=$(mdsvdevname 1_2) ;;
1188 fs2ost) device=$(ostvdevname 1_2) ;;
1189 fs3ost) device=$(ostvdevname 2_2) ;;
1197 local virt=$(virt-what 2> /dev/null)
1199 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1201 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1204 VMware|KVM|VirtualBox|Parallels)
1205 echo $virt | tr '[A-Z]' '[a-z]' ;;
1211 # Re-read the partition table on failover partner host.
1212 # After a ZFS storage pool is created on a shared device, the partition table
1213 # on the device may change. However, the operating system on the failover
1214 # host may not notice the change automatically. Without the up-to-date partition
1215 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1216 # relative to partition rather than disk beginnings.
1218 # This function performs partprobe on the failover host to make it re-read the
1221 refresh_partition_table() {
1226 host=$(facet_passive_host $facet)
1227 if [[ -n "$host" ]]; then
1228 do_node $host "$PARTPROBE $device"
1233 # Get ZFS storage pool name.
1240 device=$(facet_device $facet)
1241 # poolname is string before "/"
1242 poolname="${device%%/*}"
1249 # Get ZFS local fsname.
1251 zfs_local_fsname() {
1253 local lfsname=$(basename $(facet_device $facet))
1259 # Create ZFS storage pool.
1266 local opts=${@:-"-o cachefile=none"}
1268 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1269 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1270 $ZPOOL create -f $opts $poolname $vdev"
1274 # Create ZFS file system.
1280 local opts=${@:-"-o mountpoint=legacy"}
1282 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1283 $ZFS create $opts $dataset"
1287 # Export ZFS storage pool.
1288 # Before exporting the pool, all datasets within the pool should be unmounted.
1296 poolname=$(zpool_name $facet)
1298 if [[ -n "$poolname" ]]; then
1299 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1300 grep -q ^$poolname/ /proc/mounts ||
1301 $ZPOOL export $opts $poolname"
1306 # Destroy ZFS storage pool.
1307 # Destroy the given pool and free up any devices for other use. This command
1308 # tries to unmount any active datasets before destroying the pool.
1309 # -f Force any active datasets contained within the pool to be unmounted.
1313 local poolname=${2:-$(zpool_name $facet)}
1315 if [[ -n "$poolname" ]]; then
1316 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1317 $ZPOOL destroy -f $poolname"
1322 # Import ZFS storage pool.
1323 # Force importing, even if the pool appears to be potentially active.
1328 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1331 poolname=$(zpool_name $facet)
1333 if [[ -n "$poolname" ]]; then
1334 opts+=" -d $(dirname $(facet_vdevice $facet))"
1335 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1336 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1337 $ZPOOL import -f $opts $poolname"
1342 # Reimport ZFS storage pool with new name
1347 local opts="-o cachefile=none"
1348 local poolname=$(zpool_name $facet)
1350 opts+=" -d $(dirname $(facet_vdevice $facet))"
1351 do_facet $facet "$ZPOOL export $poolname;
1352 $ZPOOL import $opts $poolname $newpool"
1356 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1357 # is not automatically imported on system startup.
1359 # In a failover environment, this will provide resource level fencing which
1360 # will ensure that the same ZFS storage pool will not be imported concurrently
1361 # on different nodes.
1363 disable_zpool_cache() {
1367 poolname=$(zpool_name $facet)
1369 if [[ -n "$poolname" ]]; then
1370 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1375 # This and set_osd_param() shall be used to access OSD parameters
1376 # once existed under "obdfilter":
1381 # writethrough_cache_enable
1385 local device=${2:-$FSNAME-OST*}
1388 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1389 osd-*.$device.$name 2>&1" | grep -v 'error:'
1394 local device=${2:-$FSNAME-OST*}
1398 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1399 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1403 local dz=${1:-$DEBUG_SIZE}
1405 if [ -f /sys/devices/system/cpu/possible ]; then
1406 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1408 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1411 # bug 19944, adjust size to be -gt num_possible_cpus()
1412 # promise 2MB for every cpu at least
1413 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1416 lctl set_param debug_mb=$dz
1419 set_default_debug () {
1420 local debug=${1:-"$PTLDEBUG"}
1421 local subsys=${2:-"$SUBSYSTEM"}
1422 local debug_size=${3:-$DEBUG_SIZE}
1424 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1425 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1427 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1430 set_default_debug_nodes () {
1433 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1434 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1438 do_rpc_nodes "$nodes" set_default_debug \
1439 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1442 set_default_debug_facet () {
1444 local node=$(facet_active_host $facet)
1445 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1447 set_default_debug_nodes $node
1451 local hostid=${1:-$(hostid)}
1453 if [ ! -s /etc/hostid ]; then
1454 printf $(echo -n $hostid |
1455 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1461 local facets=${1:-$(get_facets)}
1464 for facet in ${facets//,/ }; do
1467 [ $RC -eq 0 ] && continue
1469 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1470 skip "Restart of $facet failed!." && touch $LU482_FAILED
1472 error "Restart of $facet failed!"
1479 # Add argument "arg" (e.g., "loop") to the comma-separated list
1480 # of arguments for option "opt" (e.g., "-o") on command
1481 # line "opts" (e.g., "-o flock").
1487 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1489 if echo "$opts" | grep -q $opt_pattern; then
1490 opts=$(echo "$opts" | sed -e \
1491 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1493 opts+="${opts:+ }$opt $arg"
1501 local dev=$(facet_active $facet)_dev
1502 local opt=${facet}_opt
1503 local mntpt=$(facet_mntpt $facet)
1504 local opts="${!opt} $@"
1505 local fstype=$(facet_fstype $facet)
1508 module_loaded lustre || load_modules
1510 if [ $(facet_fstype $facet) == ldiskfs ] &&
1511 ! do_facet $facet test -b ${!dev}; then
1512 opts=$(csa_add "$opts" -o loop)
1515 if [[ $(facet_fstype $facet) == zfs ]]; then
1516 # import ZFS storage pool
1517 import_zpool $facet || return ${PIPESTATUS[0]}
1522 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1524 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1525 lustre:svname ${!dev}");;
1527 error "unknown fstype!";;
1530 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1531 # for testing LU-482 error handling in mount_facets() and test_0a()
1532 if [ -f $TMP/test-lu482-trigger ]; then
1535 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1540 if [ $RC -ne 0 ]; then
1541 echo "Start of ${!dev} on ${facet} failed ${RC}"
1545 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1546 if [[ "$health" != "healthy" ]]; then
1547 error "$facet is in a unhealthy state"
1550 set_default_debug_facet $facet
1552 if [[ $facet == mds* ]]; then
1554 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1557 if [[ $opts =~ .*nosvc.* ]]; then
1558 echo "Start ${!dev} without service"
1563 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1564 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1565 "" || error "${!dev} failed to initialize!";;
1567 wait_update_facet ${facet} "$ZFS get -H -o value \
1568 lustre:svname ${!dev} 2>/dev/null | \
1569 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1570 error "${!dev} failed to initialize!";;
1573 error "unknown fstype!";;
1577 # commit the device label change to disk
1578 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1579 echo "Commit the device label on ${!dev}"
1580 do_facet $facet "sync; sleep 1; sync"
1584 label=$(devicelabel ${facet} ${!dev})
1585 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1586 eval export ${facet}_svc=${label}
1587 echo Started ${label}
1592 # start facet device options
1598 eval export ${facet}_dev=${device}
1599 eval export ${facet}_opt=\"$@\"
1601 local varname=${facet}failover_dev
1602 if [ -n "${!varname}" ] ; then
1603 eval export ${facet}failover_dev=${!varname}
1605 eval export ${facet}failover_dev=$device
1608 local mntpt=$(facet_mntpt $facet)
1609 do_facet ${facet} mkdir -p $mntpt
1610 eval export ${facet}_MOUNT=$mntpt
1611 mount_facet ${facet}
1614 if [[ $facet == mds* ]]; then
1616 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1627 local HOST=`facet_active_host $facet`
1628 [ -z $HOST ] && echo stop: no host for $facet && return 0
1630 local mntpt=$(facet_mntpt $facet)
1631 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1632 if [ ${running} -ne 0 ]; then
1633 echo "Stopping $mntpt (opts:$@) on $HOST"
1634 do_facet ${facet} $UMOUNT $@ $mntpt
1637 # umount should block, but we should wait for unrelated obd's
1638 # like the MGS or MGC to also stop.
1639 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1641 if [[ $(facet_fstype $facet) == zfs ]]; then
1642 # export ZFS storage pool
1643 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1647 # save quota version (both administrative and operational quotas)
1648 # add an additional parameter if mountpoint is ever different from $MOUNT
1650 # XXX This function is kept for interoperability with old server (< 2.3.50),
1651 # it should be removed whenever we drop the interoperability for such
1653 quota_save_version() {
1654 local fsname=${2:-$FSNAME}
1656 local ver=$(tr -c -d "123" <<< $spec)
1657 local type=$(tr -c -d "ug" <<< $spec)
1659 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1661 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1663 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1665 local osts=$(get_facets OST)
1666 for ost in ${osts//,/ }; do
1668 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1672 # client could mount several lustre
1674 # XXX This function is kept for interoperability with old server (< 2.3.50),
1675 # it should be removed whenever we drop the interoperability for such
1678 local fsname=${1:-$FSNAME}
1680 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1682 do_nodes $(comma_list $(osts_nodes)) \
1683 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1687 # get mdt quota type
1689 local varsvc=${SINGLEMDS}_svc
1690 do_facet $SINGLEMDS $LCTL get_param -n \
1691 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1694 # get ost quota type
1696 # All OSTs should have same quota type
1697 local varsvc=ost1_svc
1698 do_facet ost1 $LCTL get_param -n \
1699 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1702 # restore old quota type settings
1704 if [ "$old_MDT_QUOTA_TYPE" ]; then
1705 do_facet mgs $LCTL conf_param \
1706 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1708 if [ "$old_OST_QUOTA_TYPE" ]; then
1709 do_facet mgs $LCTL conf_param \
1710 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1714 # Handle the case when there is a space in the lfs df
1715 # "filesystem summary" line the same as when there is no space.
1716 # This will allow fixing the "lfs df" summary line in the future.
1718 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1721 # Get free inodes on the MDT specified by mdt index, free indoes on
1722 # the whole filesystem will be returned when index == -1.
1728 if [ $index -eq -1 ]; then
1731 mdt_uuid=$(mdtuuid_from_index $index)
1734 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1739 # Get the OST device status from 'lfs df' with a given OST index.
1743 local mnt_pnt=${2:-$MOUNT}
1746 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1747 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1753 # save old quota type & set new quota type
1754 local mdt_qtype=$(mdt_quota_type)
1755 local ost_qtype=$(ost_quota_type)
1757 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1758 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1760 export old_MDT_QUOTA_TYPE=$mdt_qtype
1761 export old_OST_QUOTA_TYPE=$ost_qtype
1763 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1764 error "set mdt quota type failed"
1765 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1766 error "set ost quota type failed"
1768 local quota_usrs=$QUOTA_USERS
1770 # get_filesystem_size
1771 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1772 local blk_soft=$((disksz + 1024))
1773 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1775 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1776 local i_soft=$inodes
1777 local i_hard=$((i_soft + i_soft / 20))
1779 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1780 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1781 "inode-hardlimit: $i_hard"
1784 for usr in $quota_usrs; do
1785 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1787 cmd="$LFS setquota -$type $usr -b $blk_soft"
1788 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1790 eval $cmd || error "$cmd FAILED!"
1792 # display the quota status
1793 echo "Quota settings for $usr : "
1794 $LFS quota -v -u $usr $mntpt || true
1801 local opts=${3:-$MOUNT_OPTS}
1802 opts=${opts:+-o $opts}
1803 local flags=${4:-$MOUNT_FLAGS}
1805 local device=$MGSNID:/$FSNAME$FILESET
1806 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1807 echo "Bad mount command: opt=$flags $opts dev=$device " \
1812 echo "Starting client: $client: $flags $opts $device $mnt"
1813 do_node $client mkdir -p $mnt
1814 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1815 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1817 #disable FILESET if not supported
1818 do_nodes $client lctl get_param -n \
1819 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1820 device=$MGSNID:/$FSNAME
1821 do_node $client mkdir -p $mnt/$FILESET
1822 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1825 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1826 # Mount using nodemap key
1827 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1828 if $SK_UNIQUE_NM; then
1829 mountkey=$SK_PATH/nodemap/c0.key
1831 local prunedopts=$(echo $opts |
1832 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
1833 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
1836 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
1840 set_default_debug_nodes $client
1852 [ "$3" ] && force=-f
1853 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1854 if [ $running -ne 0 ]; then
1855 echo "Stopping client $client $mnt (opts:$force)"
1856 do_node $client lsof -t $mnt || need_kill=no
1857 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1858 pids=$(do_node $client lsof -t $mnt | sort -u);
1859 if [ -n $pids ]; then
1860 do_node $client kill -9 $pids || true
1864 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1865 if [ $busy -ne 0 ] ; then
1866 echo "$mnt is still busy, wait one second" && sleep 1
1867 do_node $client umount $force $mnt
1872 # Mount the file system on the MGS
1873 mount_mgs_client() {
1874 do_facet mgs "mkdir -p $MOUNT"
1875 zconf_mount $mgs_HOST $MOUNT $MOUNT_OPTS ||
1876 error "unable to mount $MOUNT on MGS"
1879 # Unmount the file system on the MGS
1880 umount_mgs_client() {
1881 zconf_umount $mgs_HOST $MOUNT
1882 do_facet mgs "rm -rf $MOUNT"
1885 # nodes is comma list
1886 sanity_mount_check_nodes () {
1892 # FIXME: assume that all cluster nodes run the same os
1893 [ "$(uname)" = Linux ] || return 0
1896 for mnt in $mnts ; do
1897 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1898 mpts=\\\$(mount | grep -c $mnt' ');
1899 if [ \\\$running -ne \\\$mpts ]; then
1900 echo \\\$(hostname) env are INSANE!;
1903 [ $? -eq 0 ] || rc=1
1908 sanity_mount_check_servers () {
1909 [ -n "$CLIENTONLY" ] &&
1910 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1911 echo Checking servers environments
1913 # FIXME: modify get_facets to display all facets wo params
1914 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1918 for facet in ${facets//,/ }; do
1919 node=$(facet_host ${facet})
1920 mntpt=$(facet_mntpt $facet)
1921 sanity_mount_check_nodes $node $mntpt ||
1922 { error "server $node environments are insane!"; return 1; }
1926 sanity_mount_check_clients () {
1927 local clients=${1:-$CLIENTS}
1928 local mntpt=${2:-$MOUNT}
1929 local mntpt2=${3:-$MOUNT2}
1931 [ -z $clients ] && clients=$(hostname)
1932 echo Checking clients $clients environments
1934 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1935 error "clients environments are insane!"
1938 sanity_mount_check () {
1939 sanity_mount_check_servers || return 1
1940 sanity_mount_check_clients || return 2
1943 # mount clients if not mouted
1944 zconf_mount_clients() {
1947 local opts=${3:-$MOUNT_OPTS}
1948 opts=${opts:+-o $opts}
1949 local flags=${4:-$MOUNT_FLAGS}
1950 local device=$MGSNID:/$FSNAME$FILESET
1951 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1952 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1957 echo "Starting client $clients: $flags $opts $device $mnt"
1958 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1959 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1960 # Mount with own nodemap key
1962 # Mount all server nodes first with per-NM keys
1963 for nmclient in ${clients//,/ }; do
1964 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
1965 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
1968 # set perms for per-nodemap keys else permission denied
1969 do_nodes $(comma_list $(all_nodes)) \
1970 "keyctl show | grep lustre | cut -c1-11 |
1972 xargs -IX keyctl setperm X 0x3f3f3f3f"
1973 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1975 for nmclient in ${clients//,/ }; do
1976 if $SK_UNIQUE_NM; then
1977 mountkey=$SK_PATH/nodemap/c$i.key
1979 do_node $nmclient "! grep -q $mnt' ' \
1980 /proc/mounts || umount $mnt"
1981 local prunedopts=$(add_sk_mntflag $prunedopts);
1982 prunedopts=$(echo $prunedopts | sed -e \
1983 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
1985 do_nodes $(comma_list $(all_server_nodes)) \
1988 do_node $nmclient $MOUNT_CMD $flags \
1989 $prunedopts $MGSNID:/$FSNAME $mnt ||
1994 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1996 do_nodes $clients $MOUNT_CMD $flags $opts \
1997 $MGSNID:/$FSNAME $mnt || return 1
1999 #disable FILESET if not supported
2000 do_nodes $clients lctl get_param -n \
2001 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2002 device=$MGSNID:/$FSNAME
2003 do_nodes $clients mkdir -p $mnt/$FILESET
2004 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2008 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2009 # Mount with nodemap key
2011 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2012 for nmclient in ${clients//,/ }; do
2013 if $SK_UNIQUE_NM; then
2014 mountkey=$SK_PATH/nodemap/c$i.key
2016 local prunedopts=$(echo $opts | sed -e \
2017 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2018 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2021 running=\\\$(mount | grep -c $mnt' ');
2023 if [ \\\$running -eq 0 ] ; then
2025 $MOUNT_CMD $flags $prunedopts $device $mnt;
2028 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2029 grep 'type lustre' | wc -l);
2030 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2031 echo zconf_mount_clients FAILED: \
2032 mount count \\\$running, not matching \
2033 with mount count of 'type lustre' \
2034 \\\$lustre_mnt_count;
2038 exit \\\$rc" || return ${PIPESTATUS[0]}
2045 if $SHARED_KEY; then
2046 tmpopts=$(add_sk_mntflag $opts)
2049 running=\\\$(mount | grep -c $mnt' ');
2051 if [ \\\$running -eq 0 ] ; then
2053 $MOUNT_CMD $flags $tmpopts $device $mnt;
2056 exit \\\$rc" || return ${PIPESTATUS[0]}
2059 echo "Started clients $clients: "
2060 do_nodes $clients "mount | grep $mnt' '"
2062 set_default_debug_nodes $clients
2067 zconf_umount_clients() {
2072 [ "$3" ] && force=-f
2074 echo "Stopping clients: $clients $mnt (opts:$force)"
2075 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2076 if [ \\\$running -ne 0 ] ; then
2077 echo Stopping client \\\$(hostname) $mnt opts:$force;
2078 lsof $mnt || need_kill=no;
2079 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2080 pids=\\\$(lsof -t $mnt | sort -u);
2081 if [ -n \\\"\\\$pids\\\" ]; then
2085 while umount $force $mnt 2>&1 | grep -q "busy"; do
2086 echo "$mnt is still busy, wait one second" && sleep 1;
2093 echo + $POWER_DOWN $node
2097 shutdown_node_hard () {
2099 local attempts=$SHUTDOWN_ATTEMPTS
2101 for i in $(seq $attempts) ; do
2104 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2105 echo "waiting for $host to fail attempts=$attempts"
2106 [ $i -lt $attempts ] || \
2107 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2113 local mnt=${2:-$MOUNT}
2116 if [ "$FAILURE_MODE" = HARD ]; then
2117 shutdown_node_hard $client
2119 zconf_umount_clients $client $mnt -f
2125 local facets="$(get_facets OST),$(get_facets MDS)"
2128 combined_mgs_mds || facets="$facets,mgs"
2130 for facet in ${facets//,/ }; do
2131 if [ $(facet_active_host $facet) == $host ]; then
2132 affected="$affected $facet"
2136 echo $(comma_list $affected)
2141 local host=${2:-$(facet_host $facet)}
2143 local label=$(convert_facet2label $facet)
2144 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2147 facets_up_on_host () {
2149 local facets=$(facets_on_host $host)
2152 for facet in ${facets//,/ }; do
2153 if $(facet_up $facet $host); then
2154 affected_up="$affected_up $facet"
2158 echo $(comma_list $affected_up)
2164 if [ "$FAILURE_MODE" = HARD ]; then
2165 shutdown_node_hard $(facet_active_host $facet)
2173 echo + $POWER_UP $node
2186 if [ "$FAILURE_MODE" = HARD ]; then
2187 reboot_node $(facet_active_host $facet)
2195 if [ "$FAILURE_MODE" = HARD ]; then
2205 for facet in ${facets//,/ }; do
2206 hosts=$(expand_list $hosts $(facet_host $facet) )
2212 _check_progs_installed () {
2216 for prog in $progs; do
2217 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2218 echo $prog missing on $(hostname)
2225 check_progs_installed () {
2229 do_rpc_nodes "$nodes" _check_progs_installed $@
2232 # recovery-scale functions
2234 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2237 start_client_load() {
2240 local var=$(node_var_name $client)_load
2241 eval export ${var}=$load
2243 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2244 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2245 END_RUN_FILE=$END_RUN_FILE \
2246 LOAD_PID_FILE=$LOAD_PID_FILE \
2247 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2248 TESTNAME=$TESTNAME \
2249 DBENCH_LIB=$DBENCH_LIB \
2250 DBENCH_SRC=$DBENCH_SRC \
2251 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2257 log "Started client load: ${load} on $client"
2259 # get the children process IDs
2260 local pids=$(ps --ppid $ppid -o pid= | xargs)
2261 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2265 start_client_loads () {
2266 local -a clients=(${1//,/ })
2267 local numloads=${#CLIENT_LOADS[@]}
2270 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2271 testnum=$((nodenum % numloads))
2272 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2274 # bug 22169: wait the background threads to start
2278 # only for remote client
2279 check_client_load () {
2281 local var=$(node_var_name $client)_load
2282 local testload=run_${!var}.sh
2284 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2286 # bug 18914: try to connect several times not only when
2287 # check ps, but while check_node_health also
2291 while [ $RC = 254 -a $tries -gt 0 ]; do
2295 if ! check_node_health $client; then
2297 if [ $RC -eq 254 ]; then
2298 # FIXME: not sure how long we shuold sleep here
2302 echo "check node health failed: RC=$RC "
2306 # We can continue try to connect if RC=254
2307 # Just print the warning about this
2308 if [ $RC = 254 ]; then
2309 echo "got a return status of $RC from do_node while checking " \
2310 "node health on $client"
2313 # see if the load is still on the client
2316 while [ $RC = 254 -a $tries -gt 0 ]; do
2320 if ! do_node $client \
2321 "ps auxwww | grep -v grep | grep -q $testload"; then
2326 if [ $RC = 254 ]; then
2327 echo "got a return status of $RC from do_node while checking " \
2328 "(node health and 'ps') the client load on $client"
2329 # see if we can diagnose a bit why this is
2334 check_client_loads () {
2335 local clients=${1//,/ }
2339 for client in $clients; do
2340 check_client_load $client
2342 if [ "$rc" != 0 ]; then
2343 log "Client load failed on node $client, rc=$rc"
2349 restart_client_loads () {
2350 local clients=${1//,/ }
2351 local expectedfail=${2:-""}
2355 for client in $clients; do
2356 check_client_load $client
2358 if [ "$rc" != 0 -a "$expectedfail" ]; then
2359 local var=$(node_var_name $client)_load
2360 start_client_load $client ${!var}
2361 echo "Restarted client load ${!var}: on $client. Checking ..."
2362 check_client_load $client
2364 if [ "$rc" != 0 ]; then
2365 log "Client load failed to restart on node $client, rc=$rc"
2366 # failure one client load means test fail
2367 # we do not need to check other
2376 # Start vmstat and save its process ID in a file.
2381 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2384 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2385 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2388 # Display the nodes on which client loads failed.
2389 print_end_run_file() {
2393 [ -s $file ] || return 0
2395 echo "Found the END_RUN_FILE file: $file"
2398 # A client load will stop if it finds the END_RUN_FILE file.
2399 # That does not mean the client load actually failed though.
2400 # The first node in END_RUN_FILE is the one we are interested in.
2403 if [ -n "$node" ]; then
2404 local var=$(node_var_name $node)_load
2406 local prefix=$TESTLOG_PREFIX
2407 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2408 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2409 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2411 echo "Client load ${!var} failed on node $node:"
2417 # Stop the process which had its PID saved in a file.
2422 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2424 do_nodes $nodes "test -f $pid_file &&
2425 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2428 # Stop all client loads.
2429 stop_client_loads() {
2430 local nodes=${1:-$CLIENTS}
2433 # stop the client loads
2434 stop_process $nodes $pid_file
2436 # clean up the processes that started them
2437 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2439 # End recovery-scale functions
2441 # verify that lustre actually cleaned up properly
2443 VAR=$(lctl get_param -n catastrophe 2>&1)
2444 if [ $? = 0 ] ; then
2445 if [ $VAR != 0 ]; then
2446 error "LBUG/LASSERT detected"
2449 BUSY=$(dmesg | grep -i destruct || true)
2450 if [ -n "$BUSY" ]; then
2452 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2456 check_mem_leak || exit 204
2458 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2459 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2462 if module_loaded lnet || module_loaded libcfs; then
2463 echo "$TESTSUITE: modules still loaded..." 1>&2
2472 if [[ "$1" == "--verbose" ]]; then
2487 PREV_RESULT=$(do_node $node "$TEST")
2489 RESULT=$(do_node $node "$TEST")
2490 if [[ "$RESULT" == "$FINAL" ]]; then
2491 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2492 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2496 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2497 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2501 [[ $WAIT -ge $MAX ]] && break
2502 [[ $((WAIT % print)) -eq 0 ]] &&
2503 echo "Waiting $((MAX - WAIT)) secs for update"
2504 WAIT=$((WAIT + sleep))
2507 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2511 wait_update_facet() {
2513 [ "$1" = "--verbose" ] && verbose="$1" && shift
2517 wait_update $verbose $(facet_active_host $facet) "$@"
2521 do_nodes $(comma_list $(mdts_nodes)) \
2522 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
2523 do_nodes $(comma_list $(osts_nodes)) \
2524 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2525 grep -v 'Found no match'
2529 # the occupied disk space will be released
2530 # only after DMUs are committed
2531 if [[ $(facet_fstype $1) == zfs ]]; then
2532 echo "sleep $2 for ZFS OSD"
2537 wait_delete_completed_mds() {
2538 local MAX_WAIT=${1:-20}
2539 # for ZFS, waiting more time for DMUs to be committed
2540 local ZFS_WAIT=${2:-5}
2542 local stime=$(date +%s)
2547 # find MDS with pending deletions
2548 for node in $(mdts_nodes); do
2549 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2550 2>/dev/null | calc_sum)
2551 if [[ $changes -eq 0 ]]; then
2554 mds2sync="$mds2sync $node"
2556 if [ -z "$mds2sync" ]; then
2557 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2560 mds2sync=$(comma_list $mds2sync)
2562 # sync MDS transactions
2563 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
2565 # wait till all changes are sent and commmitted by OSTs
2566 # for ldiskfs space is released upon execution, but DMU
2567 # do this upon commit
2570 while [[ $WAIT -ne $MAX_WAIT ]]; do
2571 changes=$(do_nodes $mds2sync \
2572 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2573 #echo "$node: $changes changes on all"
2574 if [[ $changes -eq 0 ]]; then
2575 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2583 echo "Delete is not completed in $((etime - stime)) seconds"
2584 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2590 # we can use "for" here because we are waiting the slowest
2591 for host in ${hostlist//,/ }; do
2592 check_network "$host" 900
2594 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2601 for facet in ${facetlist//,/ }; do
2602 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2604 wait_for_host $hostlist
2607 _wait_recovery_complete () {
2610 # Use default policy if $2 is not passed by caller.
2611 local MAX=${2:-$(max_recovery_time)}
2616 while [ $WAIT -lt $MAX ]; do
2617 STATUS=$(lctl get_param -n $param | grep status)
2619 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2622 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2624 echo "$param recovery not done in $MAX sec. $STATUS"
2628 wait_recovery_complete () {
2631 # with an assumption that at_max is the same on all nodes
2632 local MAX=${2:-$(max_recovery_time)}
2635 if [ "$FAILURE_MODE" = HARD ]; then
2636 facets=$(facets_on_host $(facet_active_host $facet))
2638 echo affected facets: $facets
2640 # we can use "for" here because we are waiting the slowest
2641 for facet in ${facets//,/ }; do
2642 local var_svc=${facet}_svc
2643 local param="*.${!var_svc}.recovery_status"
2645 local host=$(facet_active_host $facet)
2646 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2650 wait_mds_ost_sync () {
2651 # just because recovery is done doesn't mean we've finished
2652 # orphan cleanup. Wait for llogs to get synchronized.
2653 echo "Waiting for orphan cleanup..."
2654 # MAX value includes time needed for MDS-OST reconnection
2655 local MAX=$(( TIMEOUT * 2 ))
2656 local WAIT_TIMEOUT=${1:-$MAX}
2659 local list=$(comma_list $(mdts_nodes))
2660 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2661 if ! do_facet $SINGLEMDS \
2662 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2664 # old way, use mds_sync
2666 list=$(comma_list $(osts_nodes))
2667 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2670 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2671 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2672 local -a sync=($(do_nodes $list "$cmd"))
2675 for ((i=0; i<${#sync[@]}; i++)); do
2677 [ ${sync[$i]} -eq 1 ] && continue
2679 [ ${sync[$i]} -eq 0 ] && continue
2681 # there is a not finished MDS-OST synchronization
2685 sleep 2 # increase waiting time and cover statfs cache
2686 [ ${con} -eq 1 ] && return 0
2687 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2691 # show which nodes are not finished.
2692 do_nodes $list "$cmd"
2693 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2697 # Wait OSTs to be active on both client and MDT side.
2699 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2700 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2701 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2702 error "wait_update OSTs up on client failed"
2704 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
2705 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
2706 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2707 error "wait_update OSTs up on MDT0000 failed"
2710 wait_destroy_complete () {
2711 echo "Waiting for local destroys to complete"
2712 # MAX value shouldn't be big as this mean server responsiveness
2713 # never increase this just to make test pass but investigate
2714 # why it takes so long time
2717 while [ $WAIT -lt $MAX ]; do
2718 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2722 for ((i=0; i<${#RPCs[@]}; i++)); do
2723 [ ${RPCs[$i]} -eq 0 ] && continue
2724 # there are still some destroy RPCs in flight
2729 [ ${con} -eq 1 ] && return 0 # done waiting
2730 echo "Waiting ${WAIT}s for local destroys to complete"
2733 echo "Local destroys weren't done in $MAX sec."
2737 wait_delete_completed() {
2738 wait_delete_completed_mds $1 || return $?
2739 wait_destroy_complete
2748 # conf-sanity 31 takes a long time cleanup
2749 while [ $WAIT -lt 300 ]; do
2750 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2751 [ -z "${running}" ] && return 0
2752 echo "waited $WAIT for${running}"
2753 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2755 WAIT=$((WAIT + INTERVAL))
2757 echo "service didn't stop after $WAIT seconds. Still running:"
2762 wait_remote_prog () {
2768 [ "$PDSH" = "no_dsh" ] && return 0
2770 while [ $WAIT -lt $2 ]; do
2771 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2772 [ -z "${running}" ] && return 0 || true
2773 echo "waited $WAIT for: "
2775 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2777 WAIT=$((WAIT + INTERVAL))
2779 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2780 [ -z "$pids" ] && return 0
2781 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2782 # FIXME: not portable
2783 for pid in $pids; do
2784 cat /proc/${pid}/status || true
2785 cat /proc/${pid}/wchan || true
2787 kill -9 $pid || true
2796 local clients=${1:-$CLIENTS}
2798 if [ -z "$clients" ]; then
2801 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2806 # not every config has many clients
2812 # usually checked on particular client or locally
2821 client_reconnect_try() {
2822 local f=$MOUNT/recon
2825 if [ -z "$CLIENTS" ]; then
2826 $LFS df $MOUNT; uname -n >> $f
2828 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2830 echo "Connected clients: $(cat $f)"
2831 ls -l $f > /dev/null
2835 client_reconnect() {
2836 # one client_reconnect_try call does not always do the job...
2838 client_reconnect_try && break
2843 affected_facets () {
2846 local host=$(facet_active_host $facet)
2847 local affected=$facet
2849 if [ "$FAILURE_MODE" = HARD ]; then
2850 affected=$(facets_up_on_host $host)
2856 local E2FSCK_ON_MDT0=false
2857 if [ "$1" == "--fsck" ]; then
2859 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2871 #Because it will only get up facets, we need get affected
2872 #facets before shutdown
2873 #For HARD Failure mode, it needs make sure facets on the same
2874 #HOST will only be shutdown and reboot once
2875 for facet in ${facets//,/ }; do
2876 local affected_facet
2878 #check whether facet has been included in other affected facets
2879 for ((index=0; index<$total; index++)); do
2880 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2883 if [ $skip -eq 0 ]; then
2884 affecteds[$total]=$(affected_facets $facet)
2889 for ((index=0; index<$total; index++)); do
2890 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2891 local host=$(facet_active_host $facet)
2892 echo "Failing ${affecteds[index]} on $host"
2893 shutdown_facet $facet
2896 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2897 $(mdsdevname 1) "-n" || error "Running e2fsck")
2899 for ((index=0; index<$total; index++)); do
2900 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2901 echo reboot facets: ${affecteds[index]}
2905 change_active ${affecteds[index]}
2907 wait_for_facet ${affecteds[index]}
2908 # start mgs first if it is affected
2909 if ! combined_mgs_mds &&
2910 list_member ${affecteds[index]} mgs; then
2911 mount_facet mgs || error "Restart of mgs failed"
2913 # FIXME; has to be changed to mount all facets concurrently
2914 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2915 echo mount facets: ${affecteds[index]}
2916 mount_facets ${affecteds[index]}
2926 do_facet $facet "sync; sync; sync"
2929 # make sure there will be no seq change
2930 local clients=${CLIENTS:-$HOSTNAME}
2931 local f=fsa-\\\$\(hostname\)
2932 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2933 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2935 local svc=${facet}_svc
2936 do_facet $facet $LCTL --device ${!svc} notransno
2938 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2939 # in-memory state has to be cleared by either rebooting the host or
2940 # exporting and reimporting the pool.
2942 # Although the uberblocks are not updated when a pool is freezed,
2943 # transactions are still written to the disks. Modified blocks may be
2944 # cached in memory when tests try reading them back. The
2945 # export-and-reimport process also evicts any cached pool data from
2946 # memory to provide the correct "data loss" semantics.
2948 # In the test framework, the exporting and importing operations are
2949 # handled by stop() and mount_facet() separately, which are used
2950 # inside fail() and fail_abort().
2952 do_facet $facet $LCTL --device ${!svc} readonly
2953 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2954 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2957 replay_barrier_nodf() {
2958 local facet=$1 echo running=${running}
2959 do_facet $facet "sync; sync; sync"
2960 local svc=${facet}_svc
2961 echo Replay barrier on ${!svc}
2962 do_facet $facet $LCTL --device ${!svc} notransno
2963 do_facet $facet $LCTL --device ${!svc} readonly
2964 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2965 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2968 replay_barrier_nosync() {
2969 local facet=$1 echo running=${running}
2970 local svc=${facet}_svc
2971 echo Replay barrier on ${!svc}
2972 do_facet $facet $LCTL --device ${!svc} notransno
2973 do_facet $facet $LCTL --device ${!svc} readonly
2974 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2975 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2979 # Get Lustre client uuid for a given Lustre mount point.
2982 local mntpnt=${1:-$MOUNT}
2984 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2985 local uuid=$($LCTL get_param -n llite.$name.uuid)
2990 mds_evict_client() {
2991 local mntpnt=${1:-$MOUNT}
2992 local uuid=$(get_client_uuid $mntpnt)
2994 do_facet $SINGLEMDS \
2995 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2998 ost_evict_client() {
2999 local mntpnt=${1:-$MOUNT}
3000 local uuid=$(get_client_uuid $mntpnt)
3003 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
3008 local clients=${CLIENTS:-$HOSTNAME}
3010 facet_failover $* || error "failover: $?"
3011 wait_clients_import_state "$clients" "$facets" FULL
3012 clients_up || error "post-failover stat: $?"
3017 facet_failover $facet
3023 change_active $facet
3024 wait_for_facet $facet
3025 mount_facet $facet -o abort_recovery
3026 clients_up || echo "first stat failed: $?"
3027 clients_up || error "post-failover stat: $?"
3030 host_nids_address() {
3034 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
3038 if [ "$1" = "'*'" ]; then echo \'*\'; else
3044 if [[ -n "$NETTYPE" ]]; then
3045 h2name_or_ip "$1" "$NETTYPE"
3047 h2name_or_ip "$1" "$2"
3050 declare -fx h2nettype
3052 # Wrapper function to print the deprecation warning
3054 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3055 if [[ -n "$NETTYPE" ]]; then
3058 h2nettype "$1" "tcp"
3062 # Wrapper function to print the deprecation warning
3064 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3065 if [[ -n "$NETTYPE" ]]; then
3068 h2nettype "$1" "o2ib"
3072 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3073 # expressions format. As a bonus we can then just pass in those variables
3074 # to pdsh. What this function does is take a HOSTLIST type string and
3075 # expand it into a space deliminated list for us.
3083 [ -z "$hostlist" ] && return
3085 # Translate the case of [..],..,[..] to [..] .. [..]
3086 list="${hostlist/],/] }"
3088 [[ "$front" == *,* ]] && {
3091 list=${list/${old}/${new}}
3094 for item in $list; do
3095 # Test if we have any []'s at all
3096 if [ "$item" != "${item/\[/}" ]; then {
3097 # Expand the [*] into list
3101 if [ "$name" != "$item" ]; then
3102 group=${item#$name[*}
3105 for range in ${group//,/ }; do
3111 # Number of leading zeros
3114 end=$(echo $end | sed 's/0*//')
3115 [[ -z "$end" ]] && end=0
3116 [[ $padlen2 -gt $padlen ]] && {
3117 [[ $padlen2 -eq ${#end} ]] && padlen2=0
3120 begin=$(echo $begin | sed 's/0*//')
3121 [ -z $begin ] && begin=0
3123 if [ ! -z "${begin##[!0-9]*}" ]; then
3124 order=$(seq -f "%0${padlen}g" $begin $end)
3126 order=$(eval echo {$begin..$end});
3129 for num in $order; do
3130 value="${name#*,}${num}${back}"
3131 [ "$value" != "${value/\[/}" ] && {
3132 value=$(hostlist_expand "$value")
3134 myList="$myList $value"
3139 myList="$myList $item"
3142 myList=${myList//,/ }
3143 myList=${myList:1} # Remove first character which is a space
3145 # Filter any duplicates without sorting
3147 myList="${list%% *}"
3149 while [[ "$list" != ${myList##* } ]]; do
3150 local tlist=" $list"
3151 list=${tlist// ${list%% *} / }
3153 myList="$myList ${list%% *}"
3155 myList="${myList%* }";
3157 # We can select an object at an offset in the list
3160 for item in $myList; do
3162 [ $cnt -eq $offset ] && {
3166 [ $(get_node_count $myList) -ne 1 ] && myList=""
3175 [ "$facet" == client ] && echo -n $HOSTNAME && return
3176 varname=${facet}_HOST
3177 if [ -z "${!varname}" ]; then
3178 if [ "${facet:0:3}" == "ost" ]; then
3179 local fh=${facet%failover}_HOST
3180 eval export ${facet}_HOST=${!fh}
3181 if [ -z "${!varname}" ]; then
3182 eval export ${facet}_HOST=${ost_HOST}
3184 elif [ "${facet:0:3}" == "mdt" -o \
3185 "${facet:0:3}" == "mds" -o \
3186 "${facet:0:3}" == "mgs" ]; then
3187 eval export ${facet}_HOST=${mds_HOST}
3193 facet_failover_host() {
3197 var=${facet}failover_HOST
3198 if [ -n "${!var}" ]; then
3203 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
3204 "${facet:0:3}" == "mgs" ]; then
3206 eval export ${facet}failover_host=${mds_HOST}
3211 if [[ $facet == ost* ]]; then
3212 eval export ${facet}failover_host=${ost_HOST}
3220 [ "$CLIENTONLY" ] && echo $facet && return
3222 local failover=$(facet_failover_host $facet)
3224 # failover is not associated with all facet types:
3225 # "AGT" facet type (remote HSM agents) does not
3227 [[ -z "$failover" ]] && echo $facet && return
3229 local host=$(facet_host $facet)
3230 local dev=$(facet_device $facet)
3232 # ${facet}_svc can not be used here because of
3233 # facet_active() is called before this var initialized
3234 local svc=$(do_node $host $E2LABEL ${dev})
3236 # active facet is ${facet}failover if device is mounted on failover
3237 # on other cases active facet is $facet
3238 [[ $dev = $(do_node $failover \
3239 lctl get_param -n *.$svc.mntdev 2>/dev/null) ]] &&
3240 echo ${facet}failover && return
3248 local active=$(detect_active $facet)
3249 echo "${facet}active=$active" > $TMP/${facet}active
3254 local activevar=${facet}active
3256 # file is missing (nothing to store) if fail() is not
3257 # executed during this test session yet;
3259 # ost1active=ost1failover
3261 # let's detect active facet based on current lustre state
3262 if [ ! -f $TMP/${facet}active ] ; then
3265 source $TMP/${facet}active
3267 # is ${facet}active set somewhere else?
3268 active=${!activevar}
3269 [[ -z "$active" ]] && exit 1
3273 facet_active_host() {
3274 facet_host $(facet_active $1)
3277 # Get the passive failover partner host of facet.
3278 facet_passive_host() {
3280 [[ $facet = client ]] && return
3282 local host=${facet}_HOST
3283 local failover_host=${facet}failover_HOST
3284 local active_host=$(facet_active_host $facet)
3286 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
3288 if [[ $active_host = ${!host} ]]; then
3289 echo -n ${!failover_host}
3299 facetlist=$(exclude_items_from_list $facetlist mgs)
3301 for facet in ${facetlist//,/ }; do
3302 local failover=${facet}failover
3303 local host=`facet_host $failover`
3304 [ -z "$host" ] && return
3306 local curactive=`facet_active $facet`
3307 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3308 eval export ${facet}active=$facet
3310 eval export ${facet}active=$failover
3312 # save the active host for this facet
3313 local activevar=${facet}active
3314 echo "$activevar=${!activevar}" > $TMP/$activevar
3315 [[ $facet = mds1 ]] && combined_mgs_mds && \
3316 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3317 local TO=`facet_active_host $facet`
3318 echo "Failover $facet to $TO"
3324 # do not stripe off hostname if verbose, bug 19215
3325 if [ x$1 = x--verbose ]; then
3333 if [ "$HOST" = "$HOSTNAME" ]; then
3335 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3336 echo "cannot run remote command on $HOST with $myPDSH"
3340 echo "CMD: $HOST $@" >&2
3341 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3344 if [ "$myPDSH" = "rsh" ]; then
3345 # we need this because rsh does not return exit code of an executed command
3346 local command_status="$TMP/cs"
3347 rsh $HOST ":> $command_status"
3348 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3349 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3350 echo command failed >$command_status"
3351 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3356 # print HOSTNAME for myPDSH="no_dsh"
3357 if [[ $myPDSH = no_dsh ]]; then
3358 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3360 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3363 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3365 return ${PIPESTATUS[0]}
3369 do_node --verbose "$@"
3372 single_local_node () {
3373 [ "$1" = "$HOSTNAME" ]
3376 # Outputs environment variable assignments that should be passed to remote nodes
3380 local facets=$(get_facets)
3383 for var in ${!MODOPTS_*}; do
3384 value=${!var//\"/\\\"}
3385 echo -n " ${var}=\"$value\""
3388 for facet in ${facets//,/ }; do
3390 if [ -n "${!var}" ]; then
3391 echo -n " $var=${!var}"
3395 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3396 if [ -n "${!var}" ]; then
3397 echo -n " $var=${!var}"
3401 for var in VERBOSE; do
3402 if [ -n "${!var}" ]; then
3403 echo -n " $var=${!var}"
3407 if [ -n "$FSTYPE" ]; then
3408 echo -n " FSTYPE=$FSTYPE"
3411 for var in LNETLND NETTYPE; do
3412 if [ -n "${!var}" ]; then
3413 echo -n " $var=${!var}"
3420 # do not stripe off hostname if verbose, bug 19215
3421 if [ x$1 = x--verbose ]; then
3429 if single_local_node $rnodes; then
3431 do_nodev $rnodes "$@"
3433 do_node $rnodes "$@"
3438 # This is part from do_node
3441 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3442 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3444 export FANOUT=$(get_node_count "${rnodes//,/ }")
3446 echo "CMD: $rnodes $@" >&2
3447 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3450 # do not replace anything from pdsh output if -N is used
3451 # -N Disable hostname: prefix on lines of output.
3452 if $verbose || [[ $myPDSH = *-N* ]]; then
3453 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3455 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3457 return ${PIPESTATUS[0]}
3461 # Execute commands on a single service's host
3463 # The \a facet (service) may be on a local or remote node, which is
3464 # determined at the time the command is run.
3466 # usage: do_facet $facet command [arg ...]
3470 local HOST=$(facet_active_host $facet)
3471 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3475 # Function: do_facet_random_file $FACET $FILE $SIZE
3476 # Creates FILE with random content on the given FACET of given SIZE
3478 do_facet_random_file() {
3482 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3483 do_facet $facet "$cmd 2>/dev/null"
3486 do_facet_create_file() {
3490 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3491 do_facet $facet "$cmd 2>/dev/null"
3495 do_nodes --verbose "$@"
3501 # make sure its not already running
3503 rm -f $TMP/${facet}active
3504 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3505 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3507 if [[ $(facet_fstype $facet) == zfs ]]; then
3509 # After formatting a ZFS target, "cachefile=none" property will
3510 # be set on the ZFS storage pool so that the pool is not
3511 # automatically imported on system startup. And then the pool
3512 # will be exported so as to leave the importing and exporting
3513 # operations handled by mount_facet() and stop() separately.
3515 refresh_partition_table $facet $(facet_vdevice $facet)
3516 disable_zpool_cache $facet
3521 # Device formatted as ost
3524 local DEVNAME=OSTDEV$num
3526 local fstype=$(facet_fstype ost$num)
3530 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3531 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3533 #try $OSTZFSDEVn - independent of vdev
3534 DEVNAME=OSTZFSDEV$num
3535 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3537 error "unknown fstype!";;
3543 # Physical device location of data
3549 local fstype=$(facet_fstype ost$num)
3553 # vdevs are not supported by ldiskfs
3556 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3557 # Device formatted by zfs
3559 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3561 error "unknown fstype!";;
3567 # Logical device formatted for lustre
3570 local DEVNAME=MDSDEV$num
3572 local fstype=$(facet_fstype mds$num)
3576 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3577 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3579 # try $MDSZFSDEVn - independent of vdev
3580 DEVNAME=MDSZFSDEV$num
3581 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3583 error "unknown fstype!";;
3589 # Physical location of data
3593 local fstype=$(facet_fstype mds$num)
3597 # vdevs are not supported by ldiskfs
3600 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3601 # Device formatted by ZFS
3602 local DEVNAME=MDSDEV$num
3603 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3605 error "unknown fstype!";;
3613 local fstype=$(facet_fstype mgs)
3617 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3618 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3619 DEVPTR=$(mdsdevname 1)
3624 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3625 ( [ -z "$MGSZFSDEV" ] &&
3626 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3627 DEVPTR=$(mdsdevname 1)
3629 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3632 error "unknown fstype!";;
3641 local fstype=$(facet_fstype mgs)
3645 # vdevs are not supported by ldiskfs
3648 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3649 ( [ -z "$MGSDEV" ] &&
3650 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3651 VDEVPTR=$(mdsvdevname 1)
3652 elif [ -n "$MGSDEV" ]; then
3656 error "unknown fstype!";;
3664 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3666 local var=${facet}_MOUNT
3667 eval mntpt=${!var:-${MOUNT}-$facet}
3674 local dev=$(facet_device $facet)
3675 local mnt=${2:-$(facet_mntpt $facet)}
3678 if ! do_facet $facet test -b $dev; then
3681 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3686 local dev=$(facet_device $facet)
3687 local mnt=${2:-$(facet_mntpt $facet)}
3689 do_facet $facet $UMOUNT $mnt
3693 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3698 local ds=$(facet_device $facet)
3699 local mnt=${2:-$(facet_mntpt $facet)}
3704 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3705 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3706 do_facet $facet $ZFS set canmount=noauto $ds
3708 # The "legacy" mount method is used here because "zfs unmount $mnt"
3709 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3710 # targets are not available at the time, the stat(2) on $MOUNT will
3713 do_facet $facet $ZFS set mountpoint=legacy $ds
3714 do_facet $facet mount -t zfs $ds $mnt
3715 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3716 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3721 local ds=$(facet_device $facet)
3722 local mnt=${2:-$(facet_mntpt $facet)}
3723 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3724 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3725 local mntpt=${!var_mntpt}
3726 local canmnt=${!var_canmnt}
3730 do_facet $facet umount $mnt
3731 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3732 do_facet $facet $ZFS set canmount=$canmnt $ds
3739 local fstype=$(facet_fstype $facet)
3741 mount_$fstype $facet $mnt
3747 local fstype=$(facet_fstype $facet)
3749 unmount_$fstype $facet $mnt
3756 local clients=$CLIENTS
3757 [ -z $clients ] && clients=$(hostname)
3759 zconf_umount_clients $clients $MOUNT "$*" || true
3760 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3762 [ -n "$CLIENTONLY" ] && return
3764 # The add fn does rm ${facet}active file, this would be enough
3765 # if we use do_facet <facet> only after the facet added, but
3766 # currently we use do_facet mds in local.sh
3767 for num in `seq $MDSCOUNT`; do
3769 rm -f ${TMP}/mds${num}active
3771 combined_mgs_mds && rm -f $TMP/mgsactive
3773 for num in `seq $OSTCOUNT`; do
3775 rm -f $TMP/ost${num}active
3778 if ! combined_mgs_mds ; then
3785 cleanup_echo_devs () {
3788 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3790 for dev in $devs; do
3791 $LCTL --device $dev cleanup
3792 $LCTL --device $dev detach
3797 nfs_client_mode && return
3798 cifs_client_mode && return
3808 combined_mgs_mds () {
3809 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3810 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3814 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3818 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3824 local fsname=${3:-"$FSNAME"}
3825 local type=$(facet_type $facet)
3826 local index=$(facet_index $facet)
3827 local fstype=$(facet_fstype $facet)
3828 local host=$(facet_host $facet)
3833 if [ $type == MGS ] || ( [ $type == MDS ] &&
3834 [ "$dev" == $(mgsdevname) ] &&
3835 [ "$host" == "$(facet_host mgs)" ] ); then
3838 opts="--mgsnode=$MGSNID"
3841 if [ $type != MGS ]; then
3842 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3846 var=${facet}failover_HOST
3847 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3848 opts+=" --failnode=$(h2nettype ${!var})"
3851 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3852 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3854 if [ $type == MDS ]; then
3855 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3856 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3857 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3858 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3860 if [ $fstype == ldiskfs ]; then
3861 # Check for wide striping
3862 if [ $OSTCOUNT -gt 160 ]; then
3863 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3864 fs_mkfs_opts+="-O large_xattr"
3868 if [ -n "${!var}" ]; then
3869 fs_mkfs_opts+=" -J device=${!var}"
3871 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3873 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3877 if [ $type == OST ]; then
3878 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3880 if [ $fstype == ldiskfs ]; then
3882 if [ -n "${!var}" ]; then
3883 fs_mkfs_opts+=" -J device=${!var}"
3885 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3890 opts+=" --backfstype=$fstype"
3893 if [ -n "${!var}" ]; then
3894 opts+=" --device-size=${!var}"
3897 var=$(upper $fstype)_MKFS_OPTS
3898 fs_mkfs_opts+=${!var:+" ${!var}"}
3900 var=${type}_FS_MKFS_OPTS
3901 fs_mkfs_opts+=${!var:+" ${!var}"}
3903 if [ -n "${fs_mkfs_opts## }" ]; then
3904 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3908 opts+=${!var:+" ${!var}"}
3915 local type=$(facet_type $facet)
3916 local var=${type}_MOUNT_FS_OPTS
3918 if [ -n "${!var}" ]; then
3919 opts+=" --mountfsoptions=${!var}"
3924 check_ost_indices() {
3925 local index_count=${#OST_INDICES[@]}
3926 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3928 # OST count is greater than the index count in $OST_INDEX_LIST.
3929 # We need check whether there are duplicate indices.
3933 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3934 index=$(facet_index ost$i)
3935 for j in $(seq 0 $((index_count - 1))); do
3936 [[ $index -ne ${OST_INDICES[j]} ]] ||
3937 error "ost$i has the same index $index as ost$((j+1))"
3944 local facet_type=$1 # mgs || mds || ost
3946 local facet=${1}${2}
3949 case "$(facet_fstype $facet)" in
3951 device=$(${facet_type}devname $facet_num)
3954 device=$(${facet_type}vdevname $facet_num)
3957 error "Unhandled filesystem type"
3961 do_facet $facet "[ -e \"$device\" ]" && return
3963 # Note: the following check only works with absolute paths
3964 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
3965 error "$facet: device '$device' does not exist"
3967 do_facet $facet "touch \"${device}\""
3976 echo "Format mgs: $(mgsdevname)"
3977 reformat_external_journal mgs
3979 # touch "device" in case it is a loopback file for testing and needs to
3980 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
3981 # to non-existent files in /dev if the admin made a typo during setup
3984 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
3985 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3995 echo "Format mds$num: $(mdsdevname $num)"
3996 reformat_external_journal mds$num
3998 __touch_device mds $num
4000 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
4001 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
4002 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
4011 echo "Format ost$num: $(ostdevname $num)"
4012 reformat_external_journal ost$num
4014 __touch_device ost $num
4016 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
4017 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
4018 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
4023 # Set hostid for ZFS/SPL zpool import protection
4024 # (Assumes MDS version is also OSS version)
4025 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
4027 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
4030 # We need ldiskfs here, may as well load them all
4032 [ -n "$CLIENTONLY" ] && return
4033 echo Formatting mgs, mds, osts
4034 if ! combined_mgs_mds ; then
4038 for num in $(seq $MDSCOUNT); do
4042 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
4044 for num in $(seq $OSTCOUNT); do
4050 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
4054 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
4058 # 0: success, the old identity set already.
4059 # 1: success, the old identity does not set.
4064 local j=`expr $num - 1`
4065 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
4067 if [ -z "$MDT" ]; then
4071 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
4074 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
4076 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
4079 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
4081 if [ $old = "NONE" ]; then
4090 zconf_umount $HOSTNAME $1 || error "umount failed"
4091 zconf_mount $HOSTNAME $1 || error "mount failed"
4099 rm -f $TMP/${facet}active
4100 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
4105 local mdt_count=${1:-$MDSCOUNT}
4106 local ost_count=${2:-$OSTCOUNT}
4109 for num in $(seq $mdt_count); do
4110 DEVNAME=$(mdsdevname $num)
4111 writeconf_facet mds$num $DEVNAME || rc=$?
4114 for num in $(seq $ost_count); do
4115 DEVNAME=$(ostdevname $num)
4116 writeconf_facet ost$num $DEVNAME || rc=$?
4122 if ! combined_mgs_mds ; then
4123 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
4128 for num in $(seq $MDSCOUNT); do
4129 DEVNAME=$(mdsdevname $num)
4130 start mds$num $DEVNAME $MDS_MOUNT_OPTS
4132 # We started mds, now we should set failover variables properly.
4133 # Set mds${num}failover_HOST if unset (the default
4135 local varname=mds${num}failover_HOST
4136 if [ -z "${!varname}" ]; then
4137 eval mds${num}failover_HOST=$(facet_host mds$num)
4140 if [ $IDENTITY_UPCALL != "default" ]; then
4141 switch_identity $num $IDENTITY_UPCALL
4147 for num in $(seq $OSTCOUNT); do
4148 DEVNAME=$(ostdevname $num)
4149 start ost$num $DEVNAME $OST_MOUNT_OPTS
4151 # We started ost$num, now we should set ost${num}failover
4152 # variable properly. Set ost${num}failover_HOST if it is not
4153 # set (the default failnode).
4154 varname=ost${num}failover_HOST
4155 if [ -z "${!varname}" ]; then
4156 eval ost${num}failover_HOST=$(facet_host ost${num})
4163 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
4164 if [ ! -z $arg1 ]; then
4165 [ "$arg1" = "server_only" ] && return
4168 if [ -n "$CLIENTS" ]; then
4169 zconf_mount_clients $CLIENTS $MOUNT
4173 if [ "$MOUNT_2" ]; then
4174 mount_client $MOUNT2
4175 if [ -n "$CLIENTS" ]; then
4176 zconf_mount_clients $CLIENTS $MOUNT2
4181 sk_nodemap_setup() {
4182 local sk_map_name=${1:-$SK_S2SNM}
4183 local sk_map_nodes=${2:-$HOSTNAME}
4184 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
4185 for servernode in $sk_map_nodes; do
4186 local nids=$(do_nodes $servernode "$LCTL list_nids")
4187 for nid in $nids; do
4188 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
4189 $sk_map_name --range $nid"
4197 nfs_client_mode && return
4198 cifs_client_mode && return
4200 sanity_mount_check || error "environments are insane!"
4206 if [ -z "$CLIENTONLY" ]; then
4207 echo Setup mgs, mdt, osts
4208 echo $WRITECONF | grep -q "writeconf" && writeconf_all
4210 if $SK_MOUNTED; then
4211 echo "Shared Key file system already mounted"
4216 if $SHARED_KEY; then
4217 export SK_MOUNTED=true
4221 echo "GSS_SK: setting kernel keyring perms"
4222 do_nodes $(comma_list $(all_nodes)) \
4223 "keyctl show | grep lustre | cut -c1-11 |
4225 xargs -IX keyctl setperm X 0x3f3f3f3f"
4228 # Need to start one nodemap for servers,
4229 # and one for clients.
4230 sk_nodemap_setup $SK_S2SNM \
4231 $(comma_list $(all_server_nodes))
4233 sk_nodemap_setup $SK_S2SNMCLI \
4234 ${CLIENTS:-$HOSTNAME}
4235 echo "Nodemap set up for SK S2S, remounting."
4244 # wait a while to allow sptlrpc configuration be propogated to targets,
4245 # only needed when mounting new target devices.
4253 # by remounting mdt before ost, initial connect from mdt to ost might
4254 # timeout because ost is not ready yet. wait some time to its fully
4255 # recovery. initial obd_connect timeout is 5s; in GSS case it's
4256 # preceeded by a context negotiation rpc with $TIMEOUT.
4257 # FIXME better by monitoring import status.
4260 set_rule $FSNAME any cli2mdt $SK_FLAVOR
4261 set_rule $FSNAME any cli2ost $SK_FLAVOR
4262 wait_flavor cli2mdt $SK_FLAVOR
4263 wait_flavor cli2ost $SK_FLAVOR
4267 sleep $((TIMEOUT + 5))
4273 mounted_lustre_filesystems() {
4274 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
4277 init_facet_vars () {
4278 [ -n "$CLIENTONLY" ] && return 0
4285 eval export ${facet}_dev=${device}
4286 eval export ${facet}_opt=\"$@\"
4288 local dev=${facet}_dev
4290 # We need to loop for the label
4291 # in case its not initialized yet.
4292 for wait_time in {0,1,3,5,10}; do
4294 if [ $wait_time -gt 0 ]; then
4295 echo "${!dev} not yet initialized,"\
4296 "waiting ${wait_time} seconds."
4300 local label=$(devicelabel ${facet} ${!dev})
4302 # Check to make sure the label does
4303 # not include ffff at the end of the label.
4304 # This indicates it has not been initialized yet.
4306 if [[ $label =~ [f|F]{4}$ ]]; then
4307 # label is not initialized, unset the result
4308 # and either try again or fail
4315 [ -z "$label" ] && echo no label for ${!dev} && exit 1
4317 eval export ${facet}_svc=${label}
4319 local varname=${facet}failover_HOST
4320 if [ -z "${!varname}" ]; then
4321 eval export $varname=$(facet_host $facet)
4324 varname=${facet}_HOST
4325 if [ -z "${!varname}" ]; then
4326 eval export $varname=$(facet_host $facet)
4329 # ${facet}failover_dev is set in cfg file
4330 varname=${facet}failover_dev
4331 if [ -n "${!varname}" ] ; then
4332 eval export ${facet}failover_dev=${!varname}
4334 eval export ${facet}failover_dev=$device
4337 # get mount point of already mounted device
4338 # is facet_dev is already mounted then use the real
4339 # mount point of this facet; otherwise use $(facet_mntpt $facet)
4340 # i.e. ${facet}_MOUNT if specified by user or default
4341 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
4342 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
4343 if [ -z $mntpt ]; then
4344 mntpt=$(facet_mntpt $facet)
4346 eval export ${facet}_MOUNT=$mntpt
4349 init_facets_vars () {
4352 if ! remote_mds_nodsh; then
4353 for num in $(seq $MDSCOUNT); do
4354 DEVNAME=`mdsdevname $num`
4355 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
4359 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
4361 if ! remote_ost_nodsh; then
4362 for num in $(seq $OSTCOUNT); do
4363 DEVNAME=$(ostdevname $num)
4364 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
4369 osc_ensure_active () {
4374 while [ $period -lt $timeout ]; do
4375 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
4376 if [ $count -eq 0 ]; then
4380 echo "There are $count OST are inactive, wait $period seconds, and try again"
4382 period=$((period+3))
4385 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
4388 set_conf_param_and_check() {
4392 local ORIG=$(do_facet $myfacet "$TEST")
4393 if [ $# -gt 3 ]; then
4399 echo "Setting $PARAM from $ORIG to $FINAL"
4400 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
4401 error "conf_param $PARAM failed"
4403 wait_update_facet $myfacet "$TEST" "$FINAL" ||
4404 error "check $PARAM failed!"
4407 init_param_vars () {
4408 TIMEOUT=$(lctl get_param -n timeout)
4409 TIMEOUT=${TIMEOUT:-20}
4411 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
4413 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4414 log "Using TIMEOUT=$TIMEOUT"
4416 osc_ensure_active $SINGLEMDS $TIMEOUT
4417 osc_ensure_active client $TIMEOUT
4419 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
4420 local current_jobid_var=$($LCTL get_param -n jobid_var)
4422 if [ $JOBID_VAR = "existing" ]; then
4423 echo "keeping jobstats as $current_jobid_var"
4424 elif [ $current_jobid_var != $JOBID_VAR ]; then
4425 echo "seting jobstats to $JOBID_VAR"
4427 set_conf_param_and_check client \
4428 "$LCTL get_param -n jobid_var" \
4429 "$FSNAME.sys.jobid_var" $JOBID_VAR
4432 echo "jobstats not supported by server"
4435 if [ $QUOTA_AUTO -ne 0 ]; then
4436 if [ "$ENABLE_QUOTA" ]; then
4437 echo "enable quota as required"
4438 setup_quota $MOUNT || return 2
4440 echo "disable quota as required"
4441 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4447 nfs_client_mode () {
4448 if [ "$NFSCLIENT" ]; then
4449 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4450 local clients=$CLIENTS
4451 [ -z $clients ] && clients=$(hostname)
4453 # FIXME: remove hostname when 19215 fixed
4454 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4455 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4456 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4457 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4459 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4465 cifs_client_mode () {
4466 [ x$CIFSCLIENT = xyes ] &&
4467 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4470 check_config_client () {
4473 local mounted=$(mount | grep " $mntpt ")
4474 if [ -n "$CLIENTONLY" ]; then
4476 # CLIENTONLY should not depend on *_HOST settings
4477 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4478 # in theory someone could create a new,
4479 # client-only config file that assumed lustre was already
4480 # configured and didn't set the MGSNID. If MGSNID is not set,
4481 # then we should use the mgs nid currently being used
4482 # as the default value. bug 18021
4483 [[ x$MGSNID = x ]] &&
4486 if [[ x$mgc != xMGC$MGSNID ]]; then
4487 if [ "$mgs_HOST" ]; then
4488 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4489 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4490 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4496 echo Checking config lustre mounted on $mntpt
4497 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4498 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4502 check_config_clients () {
4503 local clients=${CLIENTS:-$HOSTNAME}
4506 nfs_client_mode && return
4507 cifs_client_mode && return
4509 do_rpc_nodes "$clients" check_config_client $mntpt
4511 sanity_mount_check || error "environments are insane!"
4515 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4516 local cltimeout=$(lctl get_param -n timeout)
4517 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4518 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4525 [ -z $mntpt ] && return 1
4526 local mounted=$(mounted_lustre_filesystems)
4528 echo $mounted' ' | grep -w -q $mntpt' '
4532 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4536 # empty lustre filesystem may have empty directories lost+found and .lustre
4538 # exclude .lustre & lost+found
4539 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4540 -print | wc -l) = 1 ] || return 1
4541 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4542 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4543 # exclude .lustre/fid (LU-2780)
4544 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4545 -print | wc -l) = 1 ] || return 1
4547 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4552 check_and_setup_lustre() {
4554 nfs_client_mode && return
4555 cifs_client_mode && return
4557 local MOUNTED=$(mounted_lustre_filesystems)
4561 # both MOUNT and MOUNT2 are not mounted
4562 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4563 [ "$REFORMAT" = "yes" ] && formatall
4564 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4566 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4567 export I_MOUNTED=yes
4571 elif is_mounted $MOUNT2; then
4573 # MOUNT2 is mounted, while MOUNT_2 is not set
4574 if ! [ "$MOUNT_2" ]; then
4575 cleanup_mount $MOUNT2
4576 export I_UMOUNTED2=yes
4579 # MOUNT2 is mounted, MOUNT_2 is set
4581 # FIXME: what to do if check_config failed?
4583 # 1) remote client has mounted other Lustre fs ?
4584 # 2) it has insane env ?
4585 # let's try umount MOUNT2 on all clients and mount it again:
4586 if ! check_config_clients $MOUNT2; then
4587 cleanup_mount $MOUNT2
4588 restore_mount $MOUNT2
4589 export I_MOUNTED2=yes
4594 # MOUNT is mounted MOUNT2 is not mounted
4595 elif [ "$MOUNT_2" ]; then
4596 restore_mount $MOUNT2
4597 export I_MOUNTED2=yes
4601 # FIXME: what to do if check_config failed?
4603 # 1) remote client has mounted other Lustre fs?
4604 # 2) lustre is mounted on remote_clients atall ?
4605 check_config_clients $MOUNT
4609 set_default_debug_nodes $(comma_list $(nodes_list))
4612 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4614 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4615 facets="$(get_facets OST)"
4616 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4617 facets="$facets,$(get_facets MDS)"
4618 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4619 facets="$facets,mgs"
4620 local nodes="$(facets_hosts ${facets})"
4621 if [ -n "$nodes" ] ; then
4622 do_nodes $nodes "$LCTL set_param \
4623 osd-ldiskfs.track_declares_assert=1 || true"
4634 if [ -z "$CLIENTONLY" ]; then
4635 # Enable remote MDT create for testing
4636 for num in $(seq $MDSCOUNT); do
4638 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4643 if [ "$ONLY" == "setup" ]; then
4649 local clients=${CLIENTS:-$HOSTNAME}
4652 zconf_mount_clients $clients $mntpt
4656 local clients=${CLIENTS:-$HOSTNAME}
4659 zconf_umount_clients $clients $mntpt
4662 cleanup_and_setup_lustre() {
4663 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4664 lctl set_param debug=0 || true
4666 if [ "$ONLY" == "cleanup" ]; then
4670 check_and_setup_lustre
4673 # Get all of the server target devices from a given server node and type.
4680 if [ "$type" == ost ]; then
4681 devs=$(get_osd_param $node "" mntdev)
4683 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4685 for dev in $devs; do
4687 *loop*) do_node $node "losetup $dev" | \
4688 sed -e "s/.*(//" -e "s/).*//" ;;
4694 # Get all of the server target devices.
4699 # Master MDS parameters used by lfsck
4700 MDTNODE=$(facet_active_host $SINGLEMDS)
4701 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4705 for node in $(mdts_nodes); do
4706 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4712 for node in $(osts_nodes); do
4713 OSTDEVS[i]=$(get_mnt_devs $node ost)
4718 # Run e2fsck on MDT or OST device.
4723 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4724 local log=$TMP/e2fsck.log
4728 do_node $node $cmd 2>&1 | tee $log
4730 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4732 if [ $MDSCOUNT -gt 1 ]; then
4733 skip "DNE mode isn't supported!"
4737 error "It's not DNE mode."
4742 [ $rc -le $FSCK_MAX_ERR ] ||
4743 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4749 # Run resize2fs on MDT or OST device.
4758 do_facet $facet "$RESIZE2FS $opts $device $size"
4761 # verify a directory is shared among nodes.
4762 check_shared_dir() {
4764 local list=${2:-$(comma_list $(nodes_list))}
4766 [ -z "$dir" ] && return 1
4767 do_rpc_nodes "$list" check_logdir $dir
4768 check_write_access $dir "$list" || return 1
4773 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4774 $LCTL set_param printk=+lfsck
4775 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4777 for k in $(seq $MDSCOUNT); do
4778 # wait up to 10+1 minutes for LFSCK to complete
4779 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4780 mdd.$(facet_svc mds${k}).lfsck_layout |
4781 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4782 error "MDS${k} layout isn't the expected 'completed'"
4783 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4784 mdd.$(facet_svc mds${k}).lfsck_namespace |
4785 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4786 error "MDS${k} namespace isn't the expected 'completed'"
4788 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4789 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4790 awk '/repaired/ { print $2 }' | calc_sum)
4791 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4792 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4793 awk '/repaired/ { print $2 }' | calc_sum)
4794 local repaired=$((rep_mdt + rep_ost))
4795 [ $repaired -eq 0 ] ||
4796 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4799 dump_file_contents() {
4805 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4806 error_noexit false \
4807 "Invalid parameters for dump_file_contents()"
4810 for node in ${nodes}; do
4811 do_node $node "for i in \\\$(find $dir -type f); do
4812 echo ====\\\${i}=======================;
4814 done" >> ${logname}.${node}.log
4818 dump_command_output() {
4824 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4825 error_noexit false \
4826 "Invalid parameters for dump_command_output()"
4830 for node in ${nodes}; do
4831 do_node $node "echo ====${cmd}=======================;
4832 $cmd" >> ${logname}.${node}.log
4839 # dump file contents from /proc/spl in case of zfs test
4840 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4841 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4842 dump_command_output \
4843 "$(osts_nodes)" "zpool events -v" "${logname}"
4846 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4847 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4848 dump_command_output \
4849 "$(mdts_nodes)" "zpool events -v" "${logname}"
4853 check_and_cleanup_lustre() {
4854 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4855 "$TESTSUITE" != "sanity-scrub" ]; then
4859 if is_mounted $MOUNT; then
4860 if $DO_CLEANUP; then
4861 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4862 error "remove sub-test dirs failed"
4866 [ "$ENABLE_QUOTA" ] && restore_quota || true
4869 if [ "$I_UMOUNTED2" = "yes" ]; then
4870 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4873 if [ "$I_MOUNTED2" = "yes" ]; then
4874 cleanup_mount $MOUNT2
4877 if [ "$I_MOUNTED" = "yes" ]; then
4878 cleanupall -f || error "cleanup failed"
4886 wait_for_function () {
4889 # suppress fn both stderr and stdout
4890 if [ "$1" = "--quiet" ]; then
4892 quiet=" > /dev/null 2>&1"
4904 eval $fn $quiet && return 0
4906 wait=$((wait + sleep))
4907 [ $wait -lt $max ] || return 1
4908 echo waiting $fn, $((max - wait)) secs left ...
4918 [ "$host" = "$HOSTNAME" ] && return 0
4920 echo "$(date +'%H:%M:%S (%s)') waiting for $host network $max secs ..."
4921 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4922 echo "Network not available!"
4926 echo "$(date +'%H:%M:%S (%s)') network interface is UP"
4934 # Convert a space-delimited list to a comma-delimited list. If the input is
4935 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4937 # echo is used to convert newlines to spaces, since it doesn't
4938 # introduce a trailing space as using "tr '\n' ' '" does
4939 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4945 echo $list | grep -qw $item
4948 # list, excluded are the comma separated lists
4949 exclude_items_from_list () {
4955 for item in ${excluded//,/ }; do
4956 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4958 echo $(comma_list $list)
4961 # list, expand are the comma separated lists
4963 local list=${1//,/ }
4964 local expand=${2//,/ }
4967 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4968 echo $(comma_list $expanded)
4971 testslist_filter () {
4972 local script=$LUSTRE/tests/${TESTSUITE}.sh
4974 [ -f $script ] || return 0
4976 local start_at=$START_AT
4977 local stop_at=$STOP_AT
4979 local var=${TESTSUITE//-/_}_START_AT
4980 [ x"${!var}" != x ] && start_at=${!var}
4981 var=${TESTSUITE//-/_}_STOP_AT
4982 [ x"${!var}" != x ] && stop_at=${!var}
4984 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4985 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4986 /^'${start_at}'$/ {flag = 0}
4987 {if (flag == 1) print $0}
4988 /^'${stop_at}'$/ { flag = 1 }'
4992 (cd `dirname $1`; echo $PWD/`basename $1`)
4996 local types=${1:-"OST MDS MGS"}
5000 for entry in $types; do
5001 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
5002 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
5005 MGS ) list="$list $name";;
5006 MDS|OST|AGT ) local count=${type}COUNT
5007 for ((i=1; i<=${!count}; i++)) do
5008 list="$list ${name}$i"
5010 * ) error "Invalid facet type"
5014 echo $(comma_list $list)
5017 ##################################
5018 # Adaptive Timeouts funcs
5021 # only check mds, we assume at_max is the same on all nodes
5022 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
5023 if [ $at_max -eq 0 ]; then
5034 # suppose that all ost-s have the same $at value set
5035 [ $facet != "ost" ] || facet=ost1
5037 do_facet $facet "lctl get_param -n $at"
5055 if [ $facet == "ost" ]; then
5056 facet=$(get_facets OST)
5057 elif [ $facet == "mds" ]; then
5058 facet=$(get_facets MDS)
5060 hosts=$(expand_list $hosts $(facets_hosts $facet))
5063 do_nodes $hosts lctl set_param at_max=$at_max
5066 ##################################
5070 # OBD_FAIL_MDS_ALL_REQUEST_NET
5072 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
5073 do_facet client "$1" || RC=$?
5074 do_facet $SINGLEMDS lctl set_param fail_loc=0
5079 # OBD_FAIL_MDS_ALL_REPLY_NET
5081 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
5083 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5087 drop_reint_reply() {
5088 # OBD_FAIL_MDS_REINT_NET_REP
5090 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
5092 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5096 drop_update_reply() {
5097 # OBD_FAIL_OUT_UPDATE_NET_REP
5101 do_facet mds${index} lctl set_param fail_loc=0x1701
5102 do_facet client "$@" || RC=$?
5103 do_facet mds${index} lctl set_param fail_loc=0
5108 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
5111 local timeout=${2:-0}
5112 # default is (obd_timeout / 4) if unspecified
5113 echo "timeout is $timeout/$2"
5114 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
5115 do_facet client "$1" || RC=$?
5116 do_facet client "sync"
5117 do_facet ost1 lctl set_param fail_loc=0
5121 drop_ldlm_cancel() {
5122 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
5124 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5125 do_nodes $list lctl set_param fail_loc=0x304
5127 do_facet client "$@" || RC=$?
5129 do_nodes $list lctl set_param fail_loc=0
5133 drop_bl_callback_once() {
5135 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5136 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5137 do_facet client lctl set_param fail_loc=0x80000305
5138 do_facet client "$@" || rc=$?
5139 do_facet client lctl set_param fail_loc=0
5140 do_facet client lctl set_param fail_val=0
5141 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5145 drop_bl_callback() {
5147 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5148 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5149 do_facet client lctl set_param fail_loc=0x305
5150 do_facet client "$@" || rc=$?
5151 do_facet client lctl set_param fail_loc=0
5152 do_facet client lctl set_param fail_val=0
5153 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5158 #define OBD_FAIL_LDLM_REPLY 0x30c
5160 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5161 do_nodes $list lctl set_param fail_loc=0x30c
5163 do_facet client "$@" || RC=$?
5165 do_nodes $list lctl set_param fail_loc=0
5169 drop_ldlm_reply_once() {
5170 #define OBD_FAIL_LDLM_REPLY 0x30c
5172 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5173 do_nodes $list lctl set_param fail_loc=0x8000030c
5175 do_facet client "$@" || RC=$?
5177 do_nodes $list lctl set_param fail_loc=0
5185 echo "clearing fail_loc on $facet"
5186 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
5189 set_nodes_failloc () {
5191 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
5194 cancel_lru_locks() {
5195 #$LCTL mark "cancel_lru_locks $1 start"
5196 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
5197 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
5198 #$LCTL mark "cancel_lru_locks $1 stop"
5203 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
5204 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
5205 echo "$DEFAULT_LRU_SIZE"
5210 lctl set_param ldlm.namespaces.*$1*.lru_size=0
5213 lru_resize_disable()
5215 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
5221 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
5227 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
5228 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
5229 echo there is still data in page cache $FILE ?
5230 lctl get_param -n $FILE
5238 DEBUGSAVE="$(lctl get_param -n debug)"
5239 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
5243 [ -n "$DEBUGSAVE" ] &&
5244 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
5248 [ -n "$DEBUGSAVE_SERVER" ] &&
5249 do_nodes $(comma_list $(all_server_nodes)) \
5250 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
5256 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
5259 debug_size_restore() {
5260 [ -n "$DEBUG_SIZE_SAVED" ] && \
5261 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
5265 start_full_debug_logging() {
5270 local DEBUG_SIZE=150
5272 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
5273 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
5276 stop_full_debug_logging() {
5281 # prints bash call stack
5282 print_stack_trace() {
5285 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
5286 local src=${BASH_SOURCE[$i]}
5287 local lineno=${BASH_LINENO[$i-1]}
5288 local funcname=${FUNCNAME[$i]}
5289 echo " = $src:$lineno:$funcname()"
5294 local TYPE=${TYPE:-"FAIL"}
5297 # do not dump logs if $1=false
5298 if [ "x$1" = "xfalse" ]; then
5303 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
5304 (print_stack_trace 2) >&2
5306 # We need to dump the logs on all nodes
5308 gather_logs $(comma_list $(nodes_list))
5312 [ "$TESTSUITELOG" ] &&
5313 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
5314 if [ -z "$*" ]; then
5315 echo "error() without useful message, please fix" > $LOGDIR/err
5317 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
5318 echo "$@" > $LOGDIR/ignore
5320 echo "$@" > $LOGDIR/err
5324 # cleanup the env for failed tests
5328 ##################################
5330 ##################################
5332 # usage: stack_trap arg sigspec
5334 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
5335 # command ``arg`` on top of previously defined commands for ``sigspec`` instead
5336 # of overwriting them.
5337 # stacked traps are executed in reverse order of their registration
5339 # arg and sigspec have the same meaning as in man (1) trap
5345 # Use "trap -p" to get the quoting right
5346 local old_trap="$(trap -p "$sigspec")"
5347 # Append ";" and remove the leading "trap -- '" added by "trap -p"
5348 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
5350 # Once again, use "trap -p" to get the quoting right
5351 local new_trap="$(trap -- "$arg" "$sigspec"
5353 trap -- '' "$sigspec")"
5355 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
5357 # The resulting string should be safe to "eval" as it is (supposedly
5358 # correctly) quoted by "trap -p"
5359 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
5368 local log=$TESTSUITELOG
5370 [ -f "$log" ] && grep -q FAIL $log && status=1
5384 # use only if we are ignoring failures for this test, bugno required.
5385 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
5386 # e.g. error_ignore bz5494 "your message" or
5387 # error_ignore LU-5494 "your message"
5389 local TYPE="IGNORE ($1)"
5394 error_and_remount() {
5396 remount_client $MOUNT
5400 # Throw an error if it's not running in vm - usually for performance
5403 local virt=$(running_in_vm)
5404 if [[ -n "$virt" ]]; then
5405 echo "running in VM '$virt', ignore error"
5406 error_ignore env=$virt "$@"
5413 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
5418 log " SKIP: $TESTSUITE $TESTNAME $@"
5420 if [[ -n "$ALWAYS_SKIPPED" ]]; then
5421 skip_logged $TESTNAME "$@"
5424 echo "$@" > $LOGDIR/skip
5427 [[ -n "$TESTSUITELOG" ]] &&
5428 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
5431 build_test_filter() {
5432 EXCEPT="$EXCEPT $(testslist_filter)"
5435 if [[ $O = [0-9]*-[0-9]* ]]; then
5436 for num in $(seq $(echo $O | tr '-' ' ')); do
5444 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
5445 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
5446 [ "$EXCEPT_SLOW" ] && \
5447 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
5448 for E in $EXCEPT; do
5449 eval EXCEPT_${E}=true
5451 for E in $ALWAYS_EXCEPT; do
5452 eval EXCEPT_ALWAYS_${E}=true
5454 for E in $EXCEPT_SLOW; do
5455 eval EXCEPT_SLOW_${E}=true
5457 for G in $GRANT_CHECK_LIST; do
5458 eval GCHECK_ONLY_${G}=true
5463 if [[ $1 = [a-z]* ]]; then
5470 # print a newline if the last test was skipped
5471 export LAST_SKIPPED=
5472 export ALWAYS_SKIPPED=
5474 # Main entry into test-framework. This is called with the name and
5475 # description of a test. The name is used to find the function to run
5476 # the test using "test_$name".
5478 # This supports a variety of methods of specifying specific test to
5479 # run or not run. These need to be documented...
5484 export base=$(basetest $1)
5485 if [ -n "$ONLY" ]; then
5487 if [ ${!testname}x != x ]; then
5488 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5489 run_one_logged $1 "$2"
5493 if [ ${!testname}x != x ]; then
5494 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5495 run_one_logged $1 "$2"
5505 if [ ${!testname}x != x ]; then
5506 TESTNAME=test_$1 skip "skipping excluded test $1"
5509 testname=EXCEPT_$base
5510 if [ ${!testname}x != x ]; then
5511 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5514 testname=EXCEPT_ALWAYS_$1
5515 if [ ${!testname}x != x ]; then
5516 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5519 testname=EXCEPT_ALWAYS_$base
5520 if [ ${!testname}x != x ]; then
5521 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5524 testname=EXCEPT_SLOW_$1
5525 if [ ${!testname}x != x ]; then
5526 TESTNAME=test_$1 skip "skipping SLOW test $1"
5529 testname=EXCEPT_SLOW_$base
5530 if [ ${!testname}x != x ]; then
5531 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5537 run_one_logged $1 "$2"
5544 load_module ../libcfs/libcfs/libcfs
5556 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5561 strace -o $TMP/$1.strace -ttt $*
5563 log "FINISHED: $*: rc $RC"
5570 banner test complete, duration $duration sec
5571 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5572 echo duration $duration >>$TESTSUITELOG
5576 # Set TEST_STATUS here. It will be used for logging the result.
5579 if [[ -f $LOGDIR/err ]]; then
5581 elif [[ -f $LOGDIR/skip ]]; then
5584 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5588 local FFREE=$(do_node $SINGLEMDS \
5589 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5590 local FTOTAL=$(do_node $SINGLEMDS \
5591 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5593 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5597 echo -n "Resetting fail_loc on all nodes..."
5598 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5599 fail_val=0 2>/dev/null" || true
5605 # Log a message (on all nodes) padded with "=" before and after.
5606 # Also appends a timestamp and prepends the testsuite name.
5609 EQUALS="===================================================================================================="
5611 msg="== ${TESTSUITE} $*"
5613 [[ $last != "=" && $last != " " ]] && msg="$msg "
5614 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5615 # always include at least == after the message
5616 log "$msg== $(date +"%H:%M:%S (%s)")"
5619 check_dmesg_for_errors() {
5621 local errors="VFS: Busy inodes after unmount of\|\
5622 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5623 group descriptors corrupted"
5625 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5626 [ -z "$res" ] && return 0
5627 echo "Kernel error detected: $res"
5632 # Run a single test function and cleanup after it.
5634 # This function should be run in a subshell so the test func can
5635 # exit() without stopping the whole script.
5640 export tfile=f${testnum}.${TESTSUITE}
5641 export tdir=d${testnum}.${TESTSUITE}
5642 export TESTNAME=test_$testnum
5643 local SAVE_UMASK=`umask`
5646 if ! grep -q $DIR /proc/mounts; then
5650 banner "test $testnum: $message"
5651 test_${testnum} || error "test_$testnum failed with $?"
5654 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5656 check_dmesg_for_errors || error "Error in dmesg detected"
5657 if [ "$PARALLEL" != "yes" ]; then
5658 ps auxww | grep -v grep | grep -q multiop &&
5659 error "multiop still running"
5670 # Wrapper around run_one to ensure:
5671 # - test runs in subshell
5672 # - output of test is saved to separate log file for error reporting
5673 # - test result is saved to data file
5676 local BEFORE=$(date +%s)
5678 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5679 local test_log=$LOGDIR/$name
5680 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5681 local zfs_debug_log=$LOGDIR/$zfs_log_name
5683 rm -rf $LOGDIR/ignore
5685 local SAVE_UMASK=$(umask)
5689 log_sub_test_begin test_${1}
5690 (run_one $1 "$2") 2>&1 | tee -i $test_log
5691 local RC=${PIPESTATUS[0]}
5693 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5694 echo "test_$1 returned $RC" | tee $LOGDIR/err
5696 duration=$(($(date +%s) - $BEFORE))
5697 pass "$1" "(${duration}s)"
5699 if [[ -f $LOGDIR/err ]]; then
5700 TEST_ERROR=$(cat $LOGDIR/err)
5701 elif [[ -f $LOGDIR/ignore ]]; then
5702 TEST_ERROR=$(cat $LOGDIR/ignore)
5703 elif [[ -f $LOGDIR/skip ]]; then
5704 TEST_ERROR=$(cat $LOGDIR/skip)
5706 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5708 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5712 if [ -f $LOGDIR/err ]; then
5713 log_zfs_info "$zfs_debug_log"
5714 $FAIL_ON_ERROR && exit $RC
5723 # Print information of skipped tests to result.yml
5726 log_sub_test_begin $1
5728 log_sub_test_end "SKIP" "0" "0" "$@"
5732 (cd $(dirname $1); echo $PWD/$(basename $1))
5737 export base=$(basetest $1)
5738 [ "$CHECK_GRANT" == "no" ] && return 0
5740 testnamebase=GCHECK_ONLY_${base}
5741 testname=GCHECK_ONLY_$1
5742 [ ${!testnamebase}x == x -a ${!testname}x == x ] && return 0
5744 echo -n "checking grant......"
5746 local clients=$CLIENTS
5747 [ -z "$clients" ] && clients=$(hostname)
5749 # sync all the data and make sure no pending data on server
5750 do_nodes $clients sync
5753 client_grant=$(do_nodes $clients \
5754 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5755 awk '{ total += $1 } END { printf("%0.0f", total) }')
5758 # which is tot_granted less grant_precreate
5759 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5761 "obdfilter.${FSNAME}-OST*.{tot_granted,tot_pending,grant_precreate}" |
5762 sed 's/=/ /'| awk '/tot_granted/{ total += $2 };
5763 /tot_pending/{ total -= $2 };
5764 /grant_precreate/{ total -= $2 };
5765 END { printf("%0.0f", total) }')
5767 # check whether client grant == server grant
5768 if [[ $client_grant -ne $server_grant ]]; then
5769 do_nodes $(comma_list $(osts_nodes)) \
5770 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
5771 "obdfilter.${FSNAME}-OST*.grant_*"
5772 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5773 error "failed: client:${client_grant} server: ${server_grant}."
5775 echo "pass: client:${client_grant} server: ${server_grant}"
5779 ########################
5785 ost=`echo $1 | awk -F_ '{print $3}'`
5786 if [ -z $ost ]; then
5787 ost=`echo $1 | sed 's/-osc.*//'`
5792 ostuuid_from_index()
5794 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5797 ostname_from_index() {
5798 local uuid=$(ostuuid_from_index $1)
5802 index_from_ostuuid()
5804 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5807 mdtuuid_from_index()
5809 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5813 # Return unique identifier for given hostname
5816 echo $host_name | md5sum | cut -d' ' -f1
5820 # Returns list of ip addresses for each interface
5822 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5827 # Cache address list to avoid mutiple execution of local_addr_list
5828 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5830 for i in $LOCAL_ADDR_LIST ; do
5831 [[ "$i" == "$addr" ]] && return 0
5838 local is_local="IS_LOCAL_$(host_id $host_name)"
5839 if [ -z "${!is_local-}" ] ; then
5841 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5842 is_local_addr "$host_ip" && eval $is_local=1
5844 [[ "${!is_local}" == "1" ]]
5849 local_node $node && return 1
5856 for node in $(mdts_nodes); do
5857 remote_node $node && return 0
5864 [ -n "$CLIENTONLY" ] && return 0 || true
5865 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5870 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5871 MSKIPPED=1 && return 1
5878 for node in $(osts_nodes) ; do
5879 remote_node $node && return 0
5886 [ -n "$CLIENTONLY" ] && return 0 || true
5887 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5892 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5893 OSKIPPED=1 && return 1
5899 [ -n "$CLIENTONLY" ] && return 0 || true
5901 MGS=$(facet_host mgs)
5902 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5907 remote_mds_nodsh || remote_ost_nodsh || \
5908 $(single_local_node $(comma_list $(nodes_list)))
5912 remote_ost && remote_mds
5915 # Get the active nodes for facets.
5923 for facet in ${facets//,/ }; do
5924 nodes="$nodes $(facet_active_host $facet)"
5927 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5931 # Get name of the active MGS node.
5933 echo -n $(facets_nodes $(get_facets MGS))
5936 # Get all of the active MDS nodes.
5938 echo -n $(facets_nodes $(get_facets MDS))
5941 # Get all of the active OSS nodes.
5943 echo -n $(facets_nodes $(get_facets OST))
5946 # Get all of the active AGT (HSM agent) nodes.
5948 echo -n $(facets_nodes $(get_facets AGT))
5951 # Get all of the client nodes and active server nodes.
5953 local nodes=$HOSTNAME
5957 # CLIENTS (if specified) contains the local client
5958 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5960 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5961 nodes="$nodes $(facets_nodes $(get_facets))"
5964 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5968 # Get all of the remote client nodes and remote active server nodes.
5969 remote_nodes_list () {
5970 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5973 # Get all of the MDS nodes, including active and passive nodes.
5977 local nodes="${mds_HOST} ${mdsfailover_HOST}"
5981 for i in $(seq $MDSCOUNT); do
5983 failover_host=mds${i}failover_HOST
5984 nodes="$nodes ${!host} ${!failover_host}"
5987 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5991 # Get all of the OSS nodes, including active and passive nodes.
5995 local nodes="${ost_HOST} ${ostfailover_HOST}"
5999 for i in $(seq $OSTCOUNT); do
6001 failover_host=ost${i}failover_HOST
6002 nodes="$nodes ${!host} ${!failover_host}"
6005 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
6009 # Get all of the server nodes, including active and passive nodes.
6010 all_server_nodes () {
6015 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
6017 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
6021 # Get all of the client and server nodes, including active and passive nodes.
6023 local nodes=$HOSTNAME
6027 # CLIENTS (if specified) contains the local client
6028 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
6030 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
6031 nodes="$nodes $(all_server_nodes)"
6034 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
6038 init_clients_lists () {
6039 # Sanity check: exclude the local client from RCLIENTS
6040 local clients=$(hostlist_expand "$RCLIENTS")
6041 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
6043 # Sanity check: exclude the dup entries
6044 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
6046 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
6048 # Sanity check: exclude the dup entries from CLIENTS
6049 # for those configs which has SINGLCLIENT set to local client
6050 clients=$(for i in $clients; do echo $i; done | sort -u)
6052 CLIENTS=$(comma_list $clients)
6053 local -a remoteclients=($RCLIENTS)
6054 for ((i=0; $i<${#remoteclients[@]}; i++)); do
6055 varname=CLIENT$((i + 2))
6056 eval $varname=${remoteclients[i]}
6059 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
6062 get_random_entry () {
6065 rnodes=${rnodes//,/ }
6067 local -a nodes=($rnodes)
6068 local num=${#nodes[@]}
6069 local i=$((RANDOM * num * 2 / 65536))
6075 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
6079 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
6080 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
6085 echo $nodes | wc -w || true
6089 local nodes=$(osts_nodes)
6090 local osscount=$(get_node_count "$nodes")
6091 [ ! "$OSTCOUNT" = "$osscount" ]
6095 local nodes=$(mdts_nodes)
6096 local mdtcount=$(get_node_count "$nodes")
6097 [ ! "$MDSCOUNT" = "$mdtcount" ]
6100 generate_machine_file() {
6101 local nodes=${1//,/ }
6102 local machinefile=$2
6104 for node in $nodes; do
6105 echo $node >>$machinefile || \
6106 { echo "can not generate machinefile $machinefile" && return 1; }
6111 local file=$1/stripe
6114 $LFS getstripe -v $file || error "getstripe $file failed"
6118 setstripe_nfsserver () {
6120 local nfsexportdir=$2
6124 local -a nfsexport=($(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
6125 { print $1 }' /proc/mounts | cut -f 1 -d :))
6127 # check that only one nfs mounted
6128 [[ -z $nfsexport ]] && echo "$dir is not nfs mounted" && return 1
6129 (( ${#nfsexport[@]} == 1 )) ||
6130 error "several nfs mounts found for $dir: ${nfsexport[@]} !"
6132 do_nodev ${nfsexport[0]} lfs setstripe $nfsexportdir "$@"
6135 # Check and add a test group.
6141 local gid=$(getent group $group_name | cut -d: -f3)
6142 if [[ -n "$gid" ]]; then
6143 [[ "$gid" -eq "$group_id" ]] || {
6144 error_noexit "inconsistent group ID:" \
6145 "new: $group_id, old: $gid"
6149 groupadd -g $group_id $group_name
6156 # Check and add a test user.
6169 local uid=$(getent passwd $user_name | cut -d: -f3)
6170 if [[ -n "$uid" ]]; then
6171 if [[ "$uid" -eq "$user_id" ]]; then
6172 local dir=$(getent passwd $user_name | cut -d: -f6)
6173 if [[ "$dir" != "$home" ]]; then
6175 usermod -d $home $user_name
6179 error_noexit "inconsistent user ID:" \
6180 "new: $user_id, old: $uid"
6185 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
6192 check_runas_id_ret() {
6194 local myRUNAS_UID=$1
6195 local myRUNAS_GID=$2
6198 if [ -z "$myRUNAS" ]; then
6199 error_exit "myRUNAS command must be specified for check_runas_id"
6202 $myRUNAS krb5_login.sh || \
6203 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
6205 mkdir $DIR/d0_runas_test
6207 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
6208 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
6209 rm -rf $DIR/d0_runas_test
6214 local myRUNAS_UID=$1
6215 local myRUNAS_GID=$2
6218 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
6219 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
6220 Please set RUNAS_ID to some UID which exists on MDS and client or
6221 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
6224 # obtain the UID/GID for MPI_USER
6228 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
6229 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
6231 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
6232 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
6235 # obtain and cache Kerberos ticket-granting ticket
6236 refresh_krb5_tgt() {
6237 local myRUNAS_UID=$1
6238 local myRUNAS_GID=$2
6241 if [ -z "$myRUNAS" ]; then
6242 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
6245 CLIENTS=${CLIENTS:-$HOSTNAME}
6246 do_nodes $CLIENTS "set -x
6247 if ! $myRUNAS krb5_login.sh; then
6248 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
6253 # Run multiop in the background, but wait for it to print
6254 # "PAUSING" to its stdout before returning from this function.
6255 multiop_bg_pause() {
6256 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
6260 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
6263 echo "$MULTIOP_PROG $FILE v$ARGS"
6264 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
6266 echo "TMPPIPE=${TMPPIPE}"
6267 read -t 60 multiop_output < $TMPPIPE
6268 if [ $? -ne 0 ]; then
6273 if [ "$multiop_output" != "PAUSING" ]; then
6274 echo "Incorrect multiop output: $multiop_output"
6289 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
6295 inodes_available () {
6296 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
6297 sort -un | head -n1) || return 1
6301 mdsrate_inodes_available () {
6302 local min_inodes=$(inodes_available)
6303 echo $((min_inodes * 99 / 100))
6306 # reset stat counters
6308 local paramfile="$1"
6309 lctl set_param -n $paramfile=0
6314 local paramfile="$1"
6316 lctl get_param -n $paramfile |
6317 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
6321 awk '{sum += $1} END { printf("%0.0f", sum) }'
6324 calc_osc_kbytes () {
6325 df $MOUNT > /dev/null
6326 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
6329 # save_lustre_params(comma separated facet list, parameter_mask)
6330 # generate a stream of formatted strings (<facet> <param name>=<param value>)
6331 save_lustre_params() {
6336 for facet in ${facets//,/ }; do
6337 facet_svc=$(facet_svc $facet)
6339 "params=\\\$($LCTL get_param $2);
6340 [[ -z \\\"$facet_svc\\\" ]] && param= ||
6341 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
6342 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
6343 while read s; do echo $facet \\\$s;
6344 done <<< \\\"\\\$param\\\""
6348 # restore lustre parameters from input stream, produces by save_lustre_params
6349 restore_lustre_params() {
6354 while IFS=" =" read facet name val; do
6355 do_facet $facet "$LCTL set_param -n $name $val"
6359 check_node_health() {
6360 local nodes=${1:-$(comma_list $(nodes_list))}
6362 for node in ${nodes//,/ }; do
6363 check_network "$node" 5
6364 if [ $? -eq 0 ]; then
6365 do_node $node "rc=0;
6366 val=\\\$($LCTL get_param -n catastrophe 2>&1);
6367 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
6368 echo \\\$(hostname -s): \\\$val;
6371 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
6376 mdsrate_cleanup () {
6378 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
6379 --nfiles $3 --dir $4 --filefmt $5 $6
6384 delayed_recovery_enabled () {
6385 local var=${SINGLEMDS}_svc
6386 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
6389 ########################
6391 convert_facet2label() {
6394 if [ x$facet = xost ]; then
6398 local varsvc=${facet}_svc
6400 if [ -n ${!varsvc} ]; then
6403 error "No lablel for $facet!"
6407 get_clientosc_proc_path() {
6408 echo "${1}-osc-ffff*"
6411 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
6412 # used by MDT would not be changed.
6413 # mdt lov: fsname-mdtlov
6414 # mdt osc: fsname-OSTXXXX-osc
6415 mds_on_old_device() {
6416 local mds=${1:-"$SINGLEMDS"}
6418 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
6419 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
6420 > /dev/null 2>&1" && return 0
6425 get_mdtosc_proc_path() {
6427 local ost_label=${2:-"*OST*"}
6429 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
6430 local mdt_label=$(convert_facet2label $mds_facet)
6431 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
6433 if [[ $ost_label = *OST* ]]; then
6434 echo "${ost_label}-osc-${mdt_index}"
6436 echo "${ost_label}-osp-${mdt_index}"
6440 get_osc_import_name() {
6443 local label=$(convert_facet2label $ost)
6445 if [ "${facet:0:3}" = "mds" ]; then
6446 get_mdtosc_proc_path $facet $label
6450 get_clientosc_proc_path $label
6454 _wait_import_state () {
6457 local maxtime=${3:-$(max_recovery_time)}
6458 local error_on_failure=${4:-1}
6462 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6463 while [ "${CONN_STATE}" != "${expected}" ]; do
6464 if [ "${expected}" == "DISCONN" ]; then
6465 # for disconn we can check after proc entry is removed
6466 [ "x${CONN_STATE}" == "x" ] && return 0
6467 # with AT enabled, we can have connect request timeout near of
6468 # reconnect timeout and test can't see real disconnect
6469 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
6471 if [ $i -ge $maxtime ]; then
6472 [ $error_on_failure -ne 0 ] && \
6473 error "can't put import for $CONN_PROC into ${expected}" \
6474 "state after $i sec, have ${CONN_STATE}"
6478 # Add uniq for multi-mount case
6479 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6483 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6487 wait_import_state() {
6490 local maxtime=${3:-$(max_recovery_time)}
6491 local error_on_failure=${4:-1}
6494 for param in ${params//,/ }; do
6495 _wait_import_state $state $param $maxtime $error_on_failure || return
6499 wait_import_state_mount() {
6500 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6504 wait_import_state $*
6507 # One client request could be timed out because server was not ready
6508 # when request was sent by client.
6509 # The request timeout calculation details :
6511 # /* We give the server rq_timeout secs to process the req, and
6512 # add the network latency for our local timeout. */
6513 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6514 # ptlrpc_at_get_net_latency(request) ;
6516 # ptlrpc_connect_import ()
6517 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6520 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6521 # ptlrpc_at_get_net_latency(request) ->
6522 # at_get (max (iat_net_latency=0, at_min)) = at_min
6525 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6526 # INITIAL_CONNECT_TIMEOUT + at_min
6528 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6529 # because we can not get this value in runtime,
6530 # the value depends on configure options, and it is not stored in /proc.
6532 # #define CONNECTION_SWITCH_MIN 5U
6533 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6535 request_timeout () {
6538 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6539 local init_connect_timeout=$TIMEOUT
6540 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6542 local at_min=$(at_get $facet at_min)
6544 echo $(( init_connect_timeout + at_min ))
6547 _wait_osc_import_state() {
6551 local target=$(get_osc_import_name $facet $ost_facet)
6552 local param="osc.${target}.ost_server_uuid"
6556 # 1. wait the deadline of client 1st request (it could be skipped)
6557 # 2. wait the deadline of client 2nd request
6558 local maxtime=$(( 2 * $(request_timeout $facet)))
6560 if [[ $facet == client* ]]; then
6561 # During setup time, the osc might not be setup, it need wait
6562 # until list_param can return valid value.
6563 params=$($LCTL list_param $param 2>/dev/null || true)
6564 while [ -z "$params" ]; do
6565 if [ $i -ge $maxtime ]; then
6566 echo "can't get $param in $maxtime secs"
6571 params=$($LCTL list_param $param 2>/dev/null || true)
6575 if [[ $ost_facet = mds* ]]; then
6576 # no OSP connection to itself
6577 if [[ $facet = $ost_facet ]]; then
6580 param="osp.${target}.mdt_server_uuid"
6584 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6585 wait_import_state $expected "$params" $maxtime; then
6586 error "$facet: import is not in $expected state after $maxtime"
6593 wait_osc_import_state() {
6599 if [[ $facet = mds ]]; then
6600 for num in $(seq $MDSCOUNT); do
6601 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6604 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6608 _wait_mgc_import_state() {
6611 local error_on_failure=${3:-1}
6612 local param="mgc.*.mgs_server_uuid"
6616 # 1. wait the deadline of client 1st request (it could be skipped)
6617 # 2. wait the deadline of client 2nd request
6618 local maxtime=$(( 2 * $(request_timeout $facet)))
6620 if [[ $facet == client* ]]; then
6621 # During setup time, the osc might not be setup, it need wait
6622 # until list_param can return valid value. And also if there
6623 # are mulitple osc entries we should list all of them before
6625 params=$($LCTL list_param $param 2>/dev/null || true)
6626 while [ -z "$params" ]; do
6627 if [ $i -ge $maxtime ]; then
6628 echo "can't get $param in $maxtime secs"
6633 params=$($LCTL list_param $param 2>/dev/null || true)
6636 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6637 wait_import_state $expected "$params" $maxtime \
6638 $error_on_failure; then
6639 if [ $error_on_failure -ne 0 ]; then
6640 error "import is not in ${expected} state"
6648 wait_mgc_import_state() {
6651 local error_on_failure=${3:-1}
6654 if [[ $facet = mds ]]; then
6655 for num in $(seq $MDSCOUNT); do
6656 _wait_mgc_import_state mds$num "$expected" \
6657 $error_on_failure || return
6660 _wait_mgc_import_state "$facet" "$expected"
6661 $error_on_failure || return
6665 wait_dne_interconnect() {
6668 if [ $MDSCOUNT -gt 1 ]; then
6669 for num in $(seq $MDSCOUNT); do
6670 wait_osc_import_state mds mds$num FULL
6675 get_clientmdc_proc_path() {
6679 get_clientmgc_proc_path() {
6687 [ -z "$list" ] && return 0
6689 # Add paths to lustre tests for 32 and 64 bit systems.
6690 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6691 local TESTPATH="$RLUSTRE/tests:"
6692 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6693 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6696 wait_clients_import_state () {
6703 if [ "$FAILURE_MODE" = HARD ]; then
6704 facets=$(facets_on_host $(facet_active_host $facet))
6707 for facet in ${facets//,/ }; do
6708 local label=$(convert_facet2label $facet)
6711 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6712 $label).ost_server_uuid" ;;
6713 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6714 $label).mds_server_uuid" ;;
6715 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6716 $label).mgs_server_uuid" ;;
6717 *) error "unknown facet!" ;;
6720 local params=$(expand_list $params $proc_path)
6723 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6725 error "import is not in ${expected} state"
6737 # wait until all MDTs are in the expected state
6738 for ((num = 1; num <= $MDSCOUNT; num++)); do
6739 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
6742 if [ $facet = "mds" ]; then
6743 mproc="osp.$mdtosp.active"
6744 [ $num -eq $((tgt_idx + 1)) ] && continue
6746 mproc="osc.$mdtosp.active"
6752 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
6756 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
6757 if [ $result -eq $expected ]; then
6758 echo -n "target updated after"
6759 echo "$wait sec (got $result)"
6763 if [ $wait -eq $max ]; then
6764 error "$tgt_name: wanted $expected got $result"
6766 echo "Waiting $((max - wait)) secs for $tgt_name"
6776 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6777 $LCTL get_param obdfilter.*.kbytesavail))
6778 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6779 $LCTL get_param -n obdfilter.*.tot_granted))
6780 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6781 $LCTL get_param -n obdfilter.*.kbytestotal))
6782 for ((i=0; i<${#AVAILA[@]}; i++)); do
6783 local -a AVAIL1=(${AVAILA[$i]//=/ })
6784 local -a TOTAL=(${TOTALA[$i]//=/ })
6785 GRANT=$((${GRANTA[$i]}/1024))
6786 # allow 1% of total space in bavail because of delayed
6787 # allocation with ZFS which might release some free space after
6788 # txg commit. For small devices, we set a mininum of 8MB
6789 local LIMIT=$((${TOTAL} / 100 + 8000))
6790 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6791 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6792 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6793 echo " FULL" || echo
6799 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6802 check_pool_not_exist() {
6803 local fsname=${1%%.*}
6804 local poolname=${1##$fsname.}
6805 [[ $# -ne 1 ]] && return 0
6806 [[ x$poolname = x ]] && return 0
6807 list_pool $fsname | grep -w $1 && return 1
6812 local fsname=${1%%.*}
6813 local poolname=${1##$fsname.}
6815 trap "destroy_test_pools $fsname" EXIT
6816 do_facet mgs lctl pool_new $1
6818 # get param should return err unless pool is created
6819 [[ $RC -ne 0 ]] && return $RC
6821 for mds_id in $(seq $MDSCOUNT); do
6822 local mdt_id=$((mds_id-1))
6823 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6824 wait_update_facet mds$mds_id \
6825 "lctl get_param -n lod.$lodname.pools.$poolname \
6826 2>/dev/null || echo foo" "" ||
6827 error "mds$mds_id: pool_new failed $1"
6829 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6830 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6836 add_pool_to_list () {
6837 local fsname=${1%%.*}
6838 local poolname=${1##$fsname.}
6840 local listvar=${fsname}_CREATED_POOLS
6841 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6845 remove_pool_from_list () {
6846 local fsname=${1%%.*}
6847 local poolname=${1##$fsname.}
6849 local listvar=${fsname}_CREATED_POOLS
6850 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6854 destroy_pool_int() {
6856 local OSTS=$(list_pool $1)
6857 for ost in $OSTS; do
6858 do_facet mgs lctl pool_remove $1 $ost
6860 do_facet mgs lctl pool_destroy $1
6863 # <fsname>.<poolname> or <poolname>
6865 local fsname=${1%%.*}
6866 local poolname=${1##$fsname.}
6868 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6872 check_pool_not_exist $fsname.$poolname
6873 [[ $? -eq 0 ]] && return 0
6875 destroy_pool_int $fsname.$poolname
6877 [[ $RC -ne 0 ]] && return $RC
6878 for mds_id in $(seq $MDSCOUNT); do
6879 local mdt_id=$((mds_id-1))
6880 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6881 wait_update_facet mds$mds_id \
6882 "lctl get_param -n lod.$lodname.pools.$poolname \
6883 2>/dev/null || echo foo" "foo" ||
6884 error "mds$mds_id: destroy pool failed $1"
6886 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6887 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6889 remove_pool_from_list $fsname.$poolname
6895 local fsname=${1:-$FSNAME}
6897 local listvar=${fsname}_CREATED_POOLS
6899 [ x${!listvar} = x ] && return 0
6901 echo "Destroy the created pools: ${!listvar}"
6902 for poolname in ${!listvar//,/ }; do
6903 destroy_pool $fsname.$poolname
6907 destroy_test_pools () {
6909 local fsname=${1:-$FSNAME}
6910 destroy_pools $fsname || true
6916 local ts=$(date +%s)
6919 if [[ ! -f "$YAML_LOG" ]]; then
6920 # init_logging is not performed before gather_logs,
6921 # so the $LOGDIR needs to be checked here
6922 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6925 [ -f $LOGDIR/shared ] && docp=false
6927 # dump lustre logs, dmesg
6929 prefix="$TESTLOG_PREFIX.$TESTNAME"
6931 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6933 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6934 echo "Dumping logs only on local client."
6935 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6936 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6941 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6942 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6944 if [ ! -f $LOGDIR/shared ]; then
6945 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6958 for i in $(seq 0 $num_mntpts); do
6959 cmd="ls -laf ${mntpt_root}$i/$dir"
6965 for pid in $pids; do
6972 # check_and_start_recovery_timer()
6973 # service_time = at_est2timeout(service_time);
6974 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6975 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6977 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6978 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6979 #define CONNECTION_SWITCH_MIN 5
6980 #define CONNECTION_SWITCH_INC 5
6981 max_recovery_time() {
6982 local init_connect_timeout=$((TIMEOUT / 20))
6983 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6985 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6986 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6988 echo -n $service_time
6991 recovery_time_min() {
6992 local connection_switch_min=5
6993 local connection_switch_inc=5
6994 local connection_switch_max
6995 local reconnect_delay_max
6996 local initial_connect_timeout
7000 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
7001 (($connection_switch_min > $TIMEOUT)) &&
7002 max=$connection_switch_min || max=$TIMEOUT
7003 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
7005 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
7006 timeout_20=$((TIMEOUT/20))
7007 (($connection_switch_min > $timeout_20)) &&
7008 initial_connect_timeout=$connection_switch_min ||
7009 initial_connect_timeout=$timeout_20
7011 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
7012 initial_connect_timeout))
7013 echo $((2 * reconnect_delay_max))
7016 get_clients_mount_count () {
7017 local clients=${CLIENTS:-$HOSTNAME}
7019 # we need to take into account the clients mounts and
7020 # exclude mds/ost mounts if any;
7021 do_nodes $clients cat /proc/mounts | grep lustre |
7022 grep -w $MOUNT | wc -l
7026 PROC_CLI="srpc_info"
7027 PROC_CON="srpc_contexts"
7035 if [ $M -lt $N ]; then
7039 while [ $N -lt $M ]; do
7049 calc_connection_cnt() {
7052 # MDT->MDT = 2 * C(M, 2)
7056 comb_m2=$(combination $MDSCOUNT 2)
7058 local num_clients=$(get_clients_mount_count)
7060 local cnt_mdt2mdt=$((comb_m2 * 2))
7061 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
7062 local cnt_cli2ost=$((num_clients * OSTCOUNT))
7063 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
7064 if is_mounted $MOUNT2; then
7065 cnt_cli2mdt=$((cnt_cli2mdt * 2))
7066 cnt_cli2ost=$((cnt_cli2ost * 2))
7074 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
7075 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
7076 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
7077 + cnt_cli2ost + cnt_cli2mdt))
7091 local cmd="$tgt.srpc.flavor"
7093 if [ $net == "any" ]; then
7098 if [ $dir != "any" ]; then
7103 log "Setting sptlrpc rule: $cmd"
7104 do_facet mgs "$LCTL conf_param $cmd"
7110 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
7120 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
7121 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
7123 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
7125 if [ "x$bulkspec" != "x" ]; then
7126 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
7128 if [ "x$algs" != "x" ]; then
7129 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
7131 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
7132 if [ $bulk == "bulkn" ]; then
7133 bulk_count=`echo "$output" | grep "bulk flavor" \
7134 | grep "null/null" | wc -l`
7135 elif [ $bulk == "bulki" ]; then
7136 bulk_count=`echo "$output" | grep "bulk flavor" \
7137 | grep "/null" | grep -v "null/" | wc -l`
7139 bulk_count=`echo "$output" | grep "bulk flavor" \
7140 | grep -v "/null" | grep -v "null/" | wc -l`
7144 [ $bulk_count -lt $count ] && count=$bulk_count
7155 local clients=${CLIENTS:-$HOSTNAME}
7157 for c in ${clients//,/ }; do
7158 local output=$(do_node $c lctl get_param -n \
7159 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
7160 local tmpcnt=$(count_flvr "$output" $flavor)
7161 if $GSS_SK && [ $flavor != "null" ]; then
7162 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7163 output=$(do_node $c lctl get_param -n \
7164 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
7165 local outcon=$(count_contexts "$output")
7166 if [ "$outcon" -lt "$tmpcnt" ]; then
7170 cnt=$((cnt + tmpcnt))
7180 local clients=${CLIENTS:-$HOSTNAME}
7182 for c in ${clients//,/ }; do
7183 local output=$(do_node $c lctl get_param -n \
7184 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
7185 local tmpcnt=$(count_flvr "$output" $flavor)
7186 if $GSS_SK && [ $flavor != "null" ]; then
7187 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7188 output=$(do_node $c lctl get_param -n \
7189 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
7190 local outcon=$(count_contexts "$output")
7191 if [ "$outcon" -lt "$tmpcnt" ]; then
7195 cnt=$((cnt + tmpcnt))
7205 if [ $MDSCOUNT -le 1 ]; then
7210 for num in `seq $MDSCOUNT`; do
7211 local output=$(do_facet mds$num lctl get_param -n \
7212 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
7213 local tmpcnt=$(count_flvr "$output" $flavor)
7214 if $GSS_SK && [ $flavor != "null" ]; then
7215 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7216 output=$(do_facet mds$num lctl get_param -n \
7217 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
7218 local outcon=$(count_contexts "$output")
7219 if [ "$outcon" -lt "$tmpcnt" ]; then
7223 cnt=$((cnt + tmpcnt))
7234 for num in `seq $MDSCOUNT`; do
7235 mdtosc=$(get_mdtosc_proc_path mds$num)
7236 mdtosc=${mdtosc/-MDT*/-MDT\*}
7237 local output=$(do_facet mds$num lctl get_param -n \
7238 osc.$mdtosc.$PROC_CLI 2>/dev/null)
7239 local tmpcnt=$(count_flvr "$output" $flavor)
7240 if $GSS_SK && [ $flavor != "null" ]; then
7241 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7242 output=$(do_facet mds$num lctl get_param -n \
7243 osc.$mdtosc.$PROC_CON 2>/dev/null)
7244 local outcon=$(count_contexts "$output")
7245 if [ "$outcon" -lt "$tmpcnt" ]; then
7249 cnt=$((cnt + tmpcnt))
7258 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
7260 count_flvr "$output" $flavor
7265 local dir=$1 # from to
7266 local flavor=$2 # flavor expected
7269 if [ $dir == "cli2mdt" ]; then
7270 res=`flvr_cnt_cli2mdt $flavor`
7271 elif [ $dir == "cli2ost" ]; then
7272 res=`flvr_cnt_cli2ost $flavor`
7273 elif [ $dir == "mdt2mdt" ]; then
7274 res=`flvr_cnt_mdt2mdt $flavor`
7275 elif [ $dir == "mdt2ost" ]; then
7276 res=`flvr_cnt_mdt2ost $flavor`
7277 elif [ $dir == "all2ost" ]; then
7278 res1=`flvr_cnt_mdt2ost $flavor`
7279 res2=`flvr_cnt_cli2ost $flavor`
7280 res=$((res1 + res2))
7281 elif [ $dir == "all2mdt" ]; then
7282 res1=`flvr_cnt_mdt2mdt $flavor`
7283 res2=`flvr_cnt_cli2mdt $flavor`
7284 res=$((res1 + res2))
7285 elif [ $dir == "all2all" ]; then
7286 res1=`flvr_cnt_mdt2ost $flavor`
7287 res2=`flvr_cnt_cli2ost $flavor`
7288 res3=`flvr_cnt_mdt2mdt $flavor`
7289 res4=`flvr_cnt_cli2mdt $flavor`
7290 res=$((res1 + res2 + res3 + res4))
7298 local dir=$1 # from to
7299 local flavor=$2 # flavor expected
7300 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
7301 local WAITFLAVOR_MAX=20 # how many retries before abort?
7304 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
7305 echo -n "checking $dir..."
7306 res=$(do_check_flavor $dir $flavor)
7307 echo "found $res/$expect $flavor connections"
7308 [ $res -ge $expect ] && return 0
7312 echo "Error checking $flavor of $dir: expect $expect, actual $res"
7313 # echo "Dumping additional logs for SK debug.."
7314 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
7316 gather_logs $(comma_list $(nodes_list))
7321 restore_to_default_flavor()
7323 local proc="mgs.MGS.live.$FSNAME"
7325 echo "restoring to default flavor..."
7327 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7328 grep ".srpc.flavor" | wc -l)
7330 # remove all existing rules if any
7331 if [ $nrule -ne 0 ]; then
7332 echo "$nrule existing rules"
7333 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7334 grep ".srpc.flavor."); do
7335 echo "remove rule: $rule"
7336 spec=`echo $rule | awk -F = '{print $1}'`
7337 do_facet mgs "$LCTL conf_param -d $spec"
7341 # verify no rules left
7342 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7343 grep ".srpc.flavor." | wc -l)
7344 [ $nrule -ne 0 ] && error "still $nrule rules left"
7346 # wait for default flavor to be applied
7349 set_rule $FSNAME any any $SK_FLAVOR
7350 wait_flavor all2all $SK_FLAVOR
7352 set_rule $FSNAME any cli2mdt $SK_FLAVOR
7353 set_rule $FSNAME any cli2ost $SK_FLAVOR
7354 wait_flavor cli2mdt $SK_FLAVOR
7355 wait_flavor cli2ost $SK_FLAVOR
7357 echo "GSS_SK now at default flavor: $SK_FLAVOR"
7359 wait_flavor all2all null
7365 local flavor=${1:-null}
7367 echo "setting all flavor to $flavor"
7369 # FIXME need parameter to this fn
7370 # and remove global vars
7371 local cnt_all2all=$(calc_connection_cnt all2all)
7373 local res=$(do_check_flavor all2all $flavor)
7374 if [ $res -eq $cnt_all2all ]; then
7375 echo "already have total $res $flavor connections"
7379 echo "found $res $flavor out of total $cnt_all2all connections"
7380 restore_to_default_flavor
7382 [[ $flavor = null ]] && return 0
7384 if $GSS_SK && [ $flavor != "null" ]; then
7386 set_rule $FSNAME any any $flavor
7387 wait_flavor all2all $flavor
7389 set_rule $FSNAME any cli2mdt $flavor
7390 set_rule $FSNAME any cli2ost $flavor
7391 set_rule $FSNAME any mdt2ost null
7392 set_rule $FSNAME any mdt2mdt null
7393 wait_flavor cli2mdt $flavor
7394 wait_flavor cli2ost $flavor
7396 echo "GSS_SK now at flavor: $flavor"
7398 set_rule $FSNAME any any $flavor
7399 wait_flavor all2all $flavor
7406 # Checking for shared logdir
7407 if [ ! -d $dir ]; then
7408 # Not found. Create local logdir
7411 touch $dir/check_file.$(hostname -s)
7416 check_write_access() {
7418 local list=${2:-$(comma_list $(nodes_list))}
7422 for node in ${list//,/ }; do
7423 file=$dir/check_file.$(short_nodename $node)
7424 if [[ ! -f "$file" ]]; then
7425 # Logdir not accessible/writable from this node.
7428 rm -f $file || return 1
7434 [[ -n $YAML_LOG ]] && return
7435 local save_umask=$(umask)
7438 export YAML_LOG=${LOGDIR}/results.yml
7442 # If the yaml log already exists then we will just append to it
7443 if [ ! -f $YAML_LOG ]; then
7444 if check_shared_dir $LOGDIR; then
7445 touch $LOGDIR/shared
7446 echo "Logging to shared log directory: $LOGDIR"
7448 echo "Logging to local directory: $LOGDIR"
7451 yml_nodes_file $LOGDIR >> $YAML_LOG
7452 yml_results_file >> $YAML_LOG
7457 # If modules are not yet loaded then older "lctl lustre_build_version"
7458 # will fail. Use lctl build version instead.
7459 log "Client: $($LCTL lustre_build_version)"
7460 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
7461 do_facet $SINGLEMDS $LCTL --version)"
7462 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
7463 do_facet ost1 $LCTL --version)"
7467 yml_log_test $1 >> $YAML_LOG
7471 yml_log_test_status $@ >> $YAML_LOG
7474 log_sub_test_begin() {
7475 yml_log_sub_test_begin "$@" >> $YAML_LOG
7478 log_sub_test_end() {
7479 yml_log_sub_test_end "$@" >> $YAML_LOG
7485 local llverdev_opts=$2
7486 local devname=$(basename $1)
7487 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
7488 # loop devices aren't in /proc/partitions
7489 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
7491 size=$(($size / 1024 / 1024)) # Gb
7493 local partial_arg=""
7494 # Run in partial (fast) mode if the size
7495 # of a partition > 1 GB
7496 [ $size -gt 1 ] && partial_arg="-p"
7498 llverdev --force $partial_arg $llverdev_opts $dev
7504 local llverfs_opts=$2
7505 local use_partial_arg=$3
7506 local partial_arg=""
7507 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
7509 # Run in partial (fast) mode if the size
7510 # of a partition > 1 GB
7511 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
7513 llverfs $partial_arg $llverfs_opts $dir
7516 #Remove objects from OST
7517 remove_ost_objects() {
7523 local mntpt=$(facet_mntpt $facet)
7524 local opts=$OST_MOUNT_OPTS
7528 echo "removing objects from $ostdev on $facet: $objids"
7529 if ! test -b $ostdev; then
7530 opts=$(csa_add "$opts" -o loop)
7532 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
7535 for i in $objids; do
7536 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
7538 umount -f $mntpt || return $?
7542 #Remove files from MDT
7543 remove_mdt_files() {
7548 local mntpt=$(facet_mntpt $facet)
7549 local opts=$MDS_MOUNT_OPTS
7551 echo "removing files from $mdtdev on $facet: $files"
7552 if [ $(facet_fstype $facet) == ldiskfs ] &&
7553 ! do_facet $facet test -b $mdtdev; then
7554 opts=$(csa_add "$opts" -o loop)
7556 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7560 rm $mntpt/ROOT/$f || { rc=$?; break; }
7562 umount -f $mntpt || return $?
7566 duplicate_mdt_files() {
7571 local mntpt=$(facet_mntpt $facet)
7572 local opts=$MDS_MOUNT_OPTS
7574 echo "duplicating files on $mdtdev on $facet: $files"
7575 mkdir -p $mntpt || return $?
7576 if [ $(facet_fstype $facet) == ldiskfs ] &&
7577 ! do_facet $facet test -b $mdtdev; then
7578 opts=$(csa_add "$opts" -o loop)
7580 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7591 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
7592 pushd $mntpt/ROOT > /dev/null || return $?
7595 touch $f.bad || return $?
7596 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
7598 [ $rc -eq 0 ] || return $rc
7599 setfattr --restore $tmp || return $?
7605 local devs=${1//,/ }
7608 local rslt=$TMP/sgpdd_survey
7610 # sgpdd-survey cleanups ${rslt}.* files
7612 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7618 # returns the canonical name for an ldiskfs device
7623 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7624 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7625 echo dm-\\\${foo##*:};
7627 echo \\\$(basename \\\$dv);
7631 is_sanity_benchmark() {
7632 local benchmarks="dbench bonnie iozone fsx"
7634 for b in $benchmarks; do
7635 if [ "$b" == "$suite" ]; then
7643 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
7647 # Get the available size (KB) of a given obd target.
7654 [[ $facet != client ]] || return 0
7656 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7661 # Get the page size (bytes) on a given facet node.
7665 local size=$(getconf PAGE_SIZE 2>/dev/null)
7667 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7668 echo -n ${size:-4096}
7672 # Get the block count of the filesystem.
7679 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7680 awk '/^Block count:/ {print $3}')
7684 # Get the block size of the filesystem.
7690 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7691 awk '/^Block size:/ {print $3}')
7695 # Check whether the "large_xattr" feature is enabled or not.
7696 large_xattr_enabled() {
7697 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7699 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7701 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7702 grep -E -q '(ea_inode|large_xattr)'"
7703 return ${PIPESTATUS[0]}
7706 # Get the maximum xattr size supported by the filesystem.
7710 if large_xattr_enabled; then
7711 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7714 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7715 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7717 # maximum xattr size = size of block - size of header -
7718 # size of 1 entry - 4 null bytes
7719 size=$((block_size - 32 - 32 - 4))
7725 # Dump the value of the named xattr from a file.
7730 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7733 # Generate a string with size of $size bytes.
7735 local size=${1:-1024} # in bytes
7737 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7740 reformat_external_journal() {
7745 if [ -n "${!var}" ]; then
7746 local rcmd="do_facet $facet"
7748 echo "reformat external journal on $facet:${!var}"
7749 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7753 # MDT file-level backup/restore
7754 mds_backup_restore() {
7757 local devname=$(mdsdevname $(facet_number $facet))
7758 local mntpt=$(facet_mntpt brpt)
7759 local rcmd="do_facet $facet"
7760 local metaea=${TMP}/backup_restore.ea
7761 local metadata=${TMP}/backup_restore.tgz
7762 local opts=${MDS_MOUNT_OPTS}
7763 local svc=${facet}_svc
7765 if ! ${rcmd} test -b ${devname}; then
7766 opts=$(csa_add "$opts" -o loop)
7769 echo "file-level backup/restore on $facet:${devname}"
7771 # step 1: build mount point
7772 ${rcmd} mkdir -p $mntpt
7773 # step 2: cleanup old backup
7774 ${rcmd} rm -f $metaea $metadata
7776 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7777 if [ ! -z $igif ]; then
7778 # step 3.5: rm .lustre
7779 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7781 # step 4: backup metaea
7783 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7785 # step 5: backup metadata
7787 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7789 ${rcmd} $UMOUNT $mntpt || return 4
7790 # step 8: reformat dev
7791 echo "reformat new device"
7792 format_mdt $(facet_number $facet)
7794 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7795 # step 10: restore metadata
7797 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7798 # step 11: restore metaea
7800 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7801 # step 12: remove recovery logs
7802 echo "remove recovery logs"
7803 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7804 # step 13: umount dev
7805 ${rcmd} $UMOUNT $mntpt || return 10
7806 # step 14: cleanup tmp backup
7807 ${rcmd} rm -f $metaea $metadata
7808 # step 15: reset device label - it's not virgin on
7809 ${rcmd} e2label $devname ${!svc}
7816 local devname=$(mdsdevname $(facet_number $facet))
7817 local mntpt=$(facet_mntpt brpt)
7818 local rcmd="do_facet $facet"
7819 local opts=${MDS_MOUNT_OPTS}
7821 if ! ${rcmd} test -b ${devname}; then
7822 opts=$(csa_add "$opts" -o loop)
7825 echo "removing OI files on $facet: idx=${idx}"
7827 # step 1: build mount point
7828 ${rcmd} mkdir -p $mntpt
7830 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7831 if [ -z $idx ]; then
7832 # step 3: remove all OI files
7833 ${rcmd} rm -fv $mntpt/oi.16*
7834 elif [ $idx -lt 2 ]; then
7835 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7839 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7840 for ((i=${idx}; i<64; i=$((i * idx)))); do
7841 ${rcmd} rm -fv $mntpt/oi.16.${i}
7845 ${rcmd} $UMOUNT $mntpt || return 2
7846 # OI files will be recreated when mounted as lustre next time.
7849 # generate maloo upload-able log file name
7850 # \param logname specify unique part of file name
7851 generate_logname() {
7852 local logname=${1:-"default_logname"}
7854 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7857 # make directory on different MDTs
7861 local stripe_count=2
7862 local stripe_index=-1
7865 while getopts "c:i:p" opt; do
7867 c) stripe_count=$OPTARG;;
7868 i) stripe_index=$OPTARG;;
7870 \?) error "only support -i -c -p";;
7874 shift $((OPTIND - 1))
7875 [ $# -eq 1 ] || error "Only creating single directory is supported"
7878 if [ "$p_option" == "-p" ]; then
7879 local parent=$(dirname $path)
7881 [ -d $path ] && return 0
7882 if [ ! -d ${parent} ]; then
7883 mkdir -p ${parent} ||
7884 error "mkdir parent '$parent' failed"
7888 if [ $MDSCOUNT -le 1 ]; then
7889 mkdir $path || error "mkdir '$path' failed"
7891 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7894 if [ $stripe_index -eq -1 ]; then
7895 mdt_index=$((test_num % MDSCOUNT))
7897 mdt_index=$stripe_index
7899 echo "striped dir -i$mdt_index -c$stripe_count $path"
7900 $LFS mkdir -i$mdt_index -c$stripe_count $path ||
7901 error "mkdir -i $mdt_index -c$stripe_count $path failed"
7905 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
7907 # If called many times, passing @last_fd will avoid repeated searching
7908 # already-open FDs repeatedly if we know they are still in use.
7910 # usage: free_fd [last_fd]
7913 local max_fd=$(ulimit -n)
7914 local fd=$((${1:-2} + 1))
7916 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7919 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7923 check_mount_and_prep()
7925 is_mounted $MOUNT || setupall
7927 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7928 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7929 for idx in $(seq $MDSCOUNT); do
7930 local name="MDT$(printf '%04x' $((idx - 1)))"
7931 rm -rf $MOUNT/.lustre/lost+found/$name/*
7935 # calcule how many ost-objects to be created.
7936 precreated_ost_obj_count()
7940 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7941 local ost_name="OST$(printf '%04x' $ost_idx)"
7942 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7943 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7944 osp.$proc_path.prealloc_last_id)
7945 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7946 osp.$proc_path.prealloc_next_id)
7947 echo $((last_id - next_id + 1))
7950 check_file_in_pool()
7955 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7958 for t in $tlist ; do
7959 [ "$i" -eq "$t" ] && continue 2
7962 echo "pool list: $tlist"
7963 echo "striping: $res"
7964 error_noexit "$file not allocated in $pool"
7971 echo "Creating new pool"
7974 create_pool $FSNAME.$pool ||
7975 { error_noexit "No pool created, result code $?"; return 1; }
7976 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7977 { error_noexit "$pool not in lfs pool_list"; return 2; }
7980 pool_add_targets() {
7981 echo "Adding targets to pool"
7987 local list=$(seq $first $step $last)
7989 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7990 do_facet mgs $LCTL pool_add \
7991 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7993 # wait for OSTs to be added to the pool
7994 for mds_id in $(seq $MDSCOUNT); do
7995 local mdt_id=$((mds_id-1))
7996 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7997 wait_update_facet mds$mds_id \
7998 "lctl get_param -n lod.$lodname.pools.$pool |
7999 sort -u | tr '\n' ' ' " "$t" || {
8000 error_noexit "mds$mds_id: Add to pool failed"
8004 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
8005 | sort -u | tr '\n' ' ' " "$t" || {
8006 error_noexit "Add to pool failed"
8009 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
8010 local addcount=$(((last - first) / step + 1))
8011 [ $lfscount -eq $addcount ] || {
8012 error_noexit "lfs pool_list bad ost count" \
8013 "$lfscount != $addcount"
8021 echo "Setting pool on directory $tdir"
8023 $SETSTRIPE -c 2 -p $pool $tdir && return 0
8025 error_noexit "Cannot set pool $pool to $tdir"
8032 echo "Checking pool on directory $tdir"
8034 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
8035 [ "$res" = "$pool" ] && return 0
8037 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
8041 pool_dir_rel_path() {
8042 echo "Testing relative path works well"
8047 mkdir -p $root/$tdir/$tdir
8049 pool_set_dir $pool $tdir || return 1
8050 pool_set_dir $pool ./$tdir || return 2
8051 pool_set_dir $pool ../$tdir || return 3
8052 pool_set_dir $pool ../$tdir/$tdir || return 4
8053 rm -rf $tdir; cd - > /dev/null
8056 pool_alloc_files() {
8057 echo "Checking files allocation from directory pool"
8064 for i in $(seq -w 1 $count)
8066 local file=$tdir/file-$i
8068 check_file_in_pool $file $pool "$tlist" || \
8069 failed=$((failed + 1))
8071 [ "$failed" = 0 ] && return 0
8073 error_noexit "$failed files not allocated in $pool"
8077 pool_create_files() {
8078 echo "Creating files in pool"
8086 for i in $(seq -w 1 $count)
8088 local file=$tdir/spoo-$i
8089 $SETSTRIPE -p $pool $file
8090 check_file_in_pool $file $pool "$tlist" || \
8091 failed=$((failed + 1))
8093 [ "$failed" = 0 ] && return 0
8095 error_noexit "$failed files not allocated in $pool"
8100 echo "Checking 'lfs df' output"
8103 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
8105 local res=$($LFS df --pool $FSNAME.$pool |
8107 grep "$FSNAME-OST" |
8109 [ "$res" = "$t" ] && return 0
8111 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
8115 pool_file_rel_path() {
8116 echo "Creating files in a pool with relative pathname"
8121 { error_noexit "unable to create $tdir"; return 1 ; }
8122 local file="/..$tdir/$tfile-1"
8123 $SETSTRIPE -p $pool $file ||
8124 { error_noexit "unable to create $file" ; return 2 ; }
8127 $SETSTRIPE -p $pool $tfile-2 || {
8128 error_noexit "unable to create $tfile-2 in $tdir"
8133 pool_remove_first_target() {
8134 echo "Removing first target from a pool"
8137 local pname="lov.$FSNAME-*.pools.$pool"
8138 local t=$($LCTL get_param -n $pname | head -1)
8139 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8140 for mds_id in $(seq $MDSCOUNT); do
8141 local mdt_id=$((mds_id-1))
8142 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8143 wait_update_facet mds$mds_id \
8144 "lctl get_param -n lod.$lodname.pools.$pool |
8146 error_noexit "mds$mds_id: $t not removed from" \
8151 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
8152 error_noexit "$t not removed from $FSNAME.$pool"
8157 pool_remove_all_targets() {
8158 echo "Removing all targets from pool"
8161 local pname="lov.$FSNAME-*.pools.$pool"
8162 for t in $($LCTL get_param -n $pname | sort -u)
8164 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8166 for mds_id in $(seq $MDSCOUNT); do
8167 local mdt_id=$((mds_id-1))
8168 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8169 wait_update_facet mds$mds_id "lctl get_param -n \
8170 lod.$lodname.pools.$pool" "" || {
8171 error_noexit "mds$mds_id: Pool $pool not drained"
8175 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
8176 error_noexit "Pool $FSNAME.$pool cannot be drained"
8179 # striping on an empty/nonexistant pool should fall back
8180 # to "pool of everything"
8182 error_noexit "failed to use fallback striping for empty pool"
8185 # setstripe on an empty pool should fail
8186 $SETSTRIPE -p $pool $file 2>/dev/null && {
8187 error_noexit "expected failure when creating file" \
8195 echo "Destroying pool"
8199 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
8202 # striping on an empty/nonexistant pool should fall back
8203 # to "pool of everything"
8205 error_noexit "failed to use fallback striping for missing pool"
8208 # setstripe on an empty pool should fail
8209 $SETSTRIPE -p $pool $file 2>/dev/null && {
8210 error_noexit "expected failure when creating file" \
8215 # get param should return err once pool is gone
8216 if wait_update $HOSTNAME "lctl get_param -n \
8217 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
8219 remove_pool_from_list $FSNAME.$pool
8222 error_noexit "Pool $FSNAME.$pool is not destroyed"
8226 # Get and check the actual stripe count of one file.
8227 # Usage: check_stripe_count <file> <expected_stripe_count>
8228 check_stripe_count() {
8233 [[ -z "$file" || -z "$expected" ]] &&
8234 error "check_stripe_count: invalid argument"
8236 local cmd="$GETSTRIPE -c $file"
8237 actual=$($cmd) || error "$cmd failed"
8238 actual=${actual%% *}
8240 if [[ $actual -ne $expected ]]; then
8241 [[ $expected -eq -1 ]] ||
8242 error "$cmd wrong: found $actual, expected $expected"
8243 [[ $actual -eq $OSTCOUNT ]] ||
8244 error "$cmd wrong: found $actual, expected $OSTCOUNT"
8248 # Get and check the actual list of OST indices on one file.
8249 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
8255 [[ -z "$file" || -z "$expected" ]] &&
8256 error "check_obdidx: invalid argument!"
8258 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
8259 grep -v obdidx | awk '{print $1}' | xargs))
8261 [[ $obdidx = $expected ]] ||
8262 error "list of OST indices on $file is $obdidx," \
8263 "should be $expected"
8266 # Get and check the actual OST index of the first stripe on one file.
8267 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
8268 check_start_ost_idx() {
8273 [[ -z "$file" || -z "$expected" ]] &&
8274 error "check_start_ost_idx: invalid argument!"
8276 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
8279 [[ $start_ost_idx = $expected ]] ||
8280 error "OST index of the first stripe on $file is" \
8281 "$start_ost_idx, should be $expected"
8284 killall_process () {
8285 local clients=${1:-$(hostname)}
8290 do_nodes $clients "killall $signal $name"
8295 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
8300 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
8305 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
8310 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
8315 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
8320 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
8327 do_facet mgs "cat $LSNAPSHOT_LOG"
8333 echo "Cleaning test environment ..."
8335 # Every lsnapshot command takes exclusive lock with others,
8336 # so can NOT destroy the snapshot during list with 'xargs'.
8338 local ssname=$(lsnapshot_list | grep snapshot_name |
8339 grep lss_ | awk '{ print $2 }' | head -n 1)
8340 [ -z "$ssname" ] && break
8342 lsnapshot_destroy -n $ssname -f ||
8343 lss_err "Fail to destroy $ssname by force"
8353 local host=$(facet_active_host $facet)
8354 local dir=$(dirname $(facet_vdevice $facet))
8355 local pool=$(zpool_name $facet)
8356 local lfsname=$(zfs_local_fsname $facet)
8357 local label=${FSNAME}-${role}$(printf '%04x' $idx)
8360 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
8366 do_facet mgs "rm -f $LSNAPSHOT_CONF"
8367 echo "Generating $LSNAPSHOT_CONF on MGS ..."
8369 if ! combined_mgs_mds ; then
8370 [ $(facet_fstype mgs) != zfs ] &&
8371 skip "Lustre snapshot 1 only works for ZFS backend" &&
8374 local host=$(facet_active_host mgs)
8375 local dir=$(dirname $(facet_vdevice mgs))
8376 local pool=$(zpool_name mgs)
8377 local lfsname=$(zfs_local_fsname mgs)
8380 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
8381 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
8384 for num in `seq $MDSCOUNT`; do
8385 [ $(facet_fstype mds$num) != zfs ] &&
8386 skip "Lustre snapshot 1 only works for ZFS backend" &&
8389 lss_gen_conf_one mds$num MDT $((num - 1)) ||
8390 lss_err "generate lss conf (mds$num)"
8393 for num in `seq $OSTCOUNT`; do
8394 [ $(facet_fstype ost$num) != zfs ] &&
8395 skip "Lustre snapshot 1 only works for ZFS backend" &&
8398 lss_gen_conf_one ost$num OST $((num - 1)) ||
8399 lss_err "generate lss conf (ost$num)"
8402 do_facet mgs "cat $LSNAPSHOT_CONF"
8405 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
8406 parse_plain_dir_param()
8411 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
8412 param="-c ${invalues[1]}"
8414 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
8415 param="$param -S ${invalues[3]}"
8417 if [[ ${invalues[4]} =~ "pattern:" ]]; then
8418 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
8419 param="$param -i ${invalues[6]}"
8421 param="$param -L ${invalues[5]} -i ${invalues[7]}"
8423 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
8424 param="$param -i ${invalues[5]}"
8432 local val=$(awk '{print $2}' <<< $line)
8434 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
8436 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
8438 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
8440 elif [[ $line =~ ^"lmm_pattern:" ]]; then
8445 parse_layout_param()
8452 if [[ ! -z $line ]]; then
8453 if [[ -z $mode ]]; then
8454 if [[ $line =~ ^"stripe_count:" ]]; then
8456 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
8458 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
8463 if [[ $mode = "plain_dir" ]]; then
8464 param=$(parse_plain_dir_param "$line")
8465 elif [[ $mode = "plain_file" ]]; then
8466 val=$(parse_plain_param "$line")
8467 [[ ! -z $val ]] && param="$param $val"
8468 elif [[ $mode = "pfl" ]]; then
8469 val=$(echo $line | awk '{print $2}')
8470 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
8471 if [[ $val = "EOF" ]]; then
8472 param="$param -E -1"
8474 param="$param -E $val"
8476 elif [[ $line =~ ^"stripe_count:" ]]; then
8478 val=$(parse_plain_dir_param "$line")
8482 val=$(parse_plain_param "$line")
8483 [[ ! -z $val ]] && param="$param $val"
8493 local param=$($LFS getstripe -d $1 | parse_layout_param)
8502 # Cancel locks before setting lfsck_verify_pfid so that errors are more
8504 cancel_lru_locks mdc
8505 cancel_lru_locks osc
8507 # make sure PFID is set correctly for files
8508 do_nodes $(comma_list $(osts_nodes)) \
8509 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
8512 cat $f &> /dev/nullA ||
8513 { rc=$?; echo "verify $f failed"; break; }
8516 do_nodes $(comma_list $(osts_nodes)) \
8517 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
8521 # check that clients "oscs" was evicted after "before"
8522 check_clients_evicted() {
8529 for osc in $oscs; do
8531 echo "Check state for $osc"
8532 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
8533 tail -n 3 | awk -F"[ [,]" \
8534 '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
8535 if (($? == 0)) && (($evicted > $before)); then
8536 echo "$osc is evicted at $evicted"
8541 [ $rc -eq 0 ] || error "client not evicted from OST"
8544 # check that clients OSCS current_state is FULL
8545 check_clients_full() {
8550 for osc in $oscs; do
8551 wait_update_facet client \
8552 "lctl get_param -n osc.$osc.state |
8553 grep 'current_state: FULL'" \
8554 "current_state: FULL" $timeout
8555 [ $? -eq 0 ] || error "$osc state is not FULL"
8559 # restore the layout saved by save_layout(). Only work with directories
8564 [ ! -d "$dir" ] && return
8566 [ -z "$layout" ] && {
8567 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
8571 setfattr -n trusted.lov -v $layout $dir ||
8572 error "error restoring layout '$layout' to '$dir'"
8575 # save the layout of a directory, the returned string will be used by
8576 # restore_layout() to restore the layout
8579 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
8580 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
8584 # save layout of a directory and restore it at exit
8585 save_layout_restore_at_exit() {
8587 local layout=$(save_layout $dir)
8589 stack_trap "restore_layout $dir $layout" EXIT