3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export GSS_PIPEFS=false
15 export SHARED_KEY=${SHARED_KEY:-false}
16 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
17 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
18 export SK_MOUNTED=${SK_MOUNTED:-false}
19 export SK_FLAVOR=${SK_FLAVOR:-ski}
20 export SK_NO_KEY=${SK_NO_KEY:-true}
21 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
22 export SK_S2S=${SK_S2S:-false}
23 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
24 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
25 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
26 export IDENTITY_UPCALL=default
28 export FLAKEY=${FLAKEY:-true}
29 # specify environment variable containing batch job name for server statistics
30 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
32 #export PDSH="pdsh -S -Rssh -w"
33 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
34 export UMOUNT=${UMOUNT:-"umount -d"}
36 export LSNAPSHOT_CONF="/etc/ldev.conf"
37 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
39 # sles12 umount has a issue with -d option
40 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
41 export UMOUNT="umount"
44 # function used by scripts run on remote nodes
45 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
46 . $LUSTRE/tests/functions.sh
47 . $LUSTRE/tests/yaml.sh
49 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
51 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
53 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
55 if [ -f "$EXCEPT_LIST_FILE" ]; then
56 echo "Reading test skip list from $EXCEPT_LIST_FILE"
61 # check config files for options in decreasing order of preference
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
63 MODPROBECONF=/etc/modprobe.d/lustre.conf
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
65 MODPROBECONF=/etc/modprobe.d/Lustre
66 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
67 MODPROBECONF=/etc/modprobe.conf
69 sanitize_parameters() {
70 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
73 if [ -d "$path" ]; then
74 eval export $i=$(echo $path | sed -r 's/\/+$//g')
80 [[ $DIR/ = $MOUNT/* ]] ||
81 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
82 [[ $DIR1/ = $MOUNT1/* ]] ||
83 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
84 [[ $DIR2/ = $MOUNT2/* ]] ||
85 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
87 [ -n "$failed" ] && exit 99 || true
91 echo "usage: $0 [-r] [-f cfgfile]"
99 [ -z "$DEFAULT_SUITES"] && return 0
100 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
102 local form="%-13s %-17s %-9s %s %s\n"
103 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
104 echo "------------------------------------------------------------------------------------"
105 for O in $DEFAULT_SUITES; do
106 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
107 [ "${!O}" = "no" ] && continue || true
108 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
109 local log=${TMP}/${o}.log
110 if is_sanity_benchmark $o; then
111 log=${TMP}/sanity-benchmark.log
116 local status=Unfinished
118 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
120 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
121 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
122 total=$(grep duration $log | awk '{ print $2 }')
123 if [ "${!O}" = "done" ]; then
127 local durations=$(egrep "^PASS|^FAIL" $log |
128 tr -d "("| sed s/s\)$//g |
129 awk '{ print $2":"$3"|" }')
130 details=$(printf "%s\n%s %s %s\n" "$details" \
131 "DDETAILS" "$O" "$(echo $durations)")
134 printf "$form" $status "$O" "${total}" "E=$skipped"
135 printf "$form" "-" "-" "-" "S=$(echo $slow)"
138 for O in $DEFAULT_SUITES; do
139 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
140 if [ "${!O}" = "no" ]; then
141 printf "$form" "Skipped" "$O" ""
145 # print the detailed tests durations if DDETAILS=true
152 export LUSTRE=$(absolute_path $LUSTRE)
153 export TESTSUITE=$(basename $0 .sh)
154 export TEST_FAILED=false
155 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
156 export RPC_MODE=${RPC_MODE:-false}
157 export DO_CLEANUP=${DO_CLEANUP:-true}
158 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
159 export CLEANUP_DM_DEV=false
160 export PAGE_SIZE=$(get_page_size client)
162 export MKE2FS=$MKE2FS
163 if [ -z "$MKE2FS" ]; then
164 if which mkfs.ldiskfs >/dev/null 2>&1; then
165 export MKE2FS=mkfs.ldiskfs
171 export DEBUGFS=$DEBUGFS
172 if [ -z "$DEBUGFS" ]; then
173 if which debugfs.ldiskfs >/dev/null 2>&1; then
174 export DEBUGFS=debugfs.ldiskfs
176 export DEBUGFS=debugfs
180 export TUNE2FS=$TUNE2FS
181 if [ -z "$TUNE2FS" ]; then
182 if which tunefs.ldiskfs >/dev/null 2>&1; then
183 export TUNE2FS=tunefs.ldiskfs
185 export TUNE2FS=tune2fs
189 export E2LABEL=$E2LABEL
190 if [ -z "$E2LABEL" ]; then
191 if which label.ldiskfs >/dev/null 2>&1; then
192 export E2LABEL=label.ldiskfs
194 export E2LABEL=e2label
198 export DUMPE2FS=$DUMPE2FS
199 if [ -z "$DUMPE2FS" ]; then
200 if which dumpfs.ldiskfs >/dev/null 2>&1; then
201 export DUMPE2FS=dumpfs.ldiskfs
203 export DUMPE2FS=dumpe2fs
207 export E2FSCK=$E2FSCK
208 if [ -z "$E2FSCK" ]; then
209 if which fsck.ldiskfs >/dev/null 2>&1; then
210 export E2FSCK=fsck.ldiskfs
216 export RESIZE2FS=$RESIZE2FS
217 if [ -z "$RESIZE2FS" ]; then
218 if which resizefs.ldiskfs >/dev/null 2>&1; then
219 export RESIZE2FS=resizefs.ldiskfs
221 export RESIZE2FS=resize2fs
225 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
226 export FSCK_MAX_ERR=4 # File system errors left uncorrected
228 export ZFS=${ZFS:-zfs}
229 export ZPOOL=${ZPOOL:-zpool}
230 export ZDB=${ZDB:-zdb}
231 export PARTPROBE=${PARTPROBE:-partprobe}
233 #[ -d /r ] && export ROOT=${ROOT:-/r}
234 export TMP=${TMP:-$ROOT/tmp}
235 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
236 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
237 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
239 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
240 if ! echo $PATH | grep -q $LUSTRE/utils; then
241 export PATH=$LUSTRE/utils:$PATH
243 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
244 export PATH=$LUSTRE/utils/gss:$PATH
246 if ! echo $PATH | grep -q $LUSTRE/tests; then
247 export PATH=$LUSTRE/tests:$PATH
249 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
250 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
252 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
253 [ ! -f "$LST" ] && export LST=$(which lst)
254 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
255 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
256 export MCREATE=${MCREATE:-mcreate}
257 export MULTIOP=${MULTIOP:-multiop}
258 # Ubuntu, at least, has a truncate command in /usr/bin
259 # so fully path our truncate command.
260 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
261 export FSX=${FSX:-$LUSTRE/tests/fsx}
262 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
263 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
264 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
265 export PATH=$LUSTRE/tests/racer:$PATH:
267 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
268 export PATH=$LUSTRE/tests/mpi:$PATH
270 export RSYNC_RSH=${RSYNC_RSH:-rsh}
272 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
273 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
274 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
275 [ ! -f "$LFS" ] && export LFS=$(which lfs)
276 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
277 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
279 export PERM_CMD=${PERM_CMD:-"$LCTL conf_param"}
281 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
282 if [ ! -f "$L_GETIDENTITY" ]; then
283 if `which l_getidentity > /dev/null 2>&1`; then
284 export L_GETIDENTITY=$(which l_getidentity)
286 export L_GETIDENTITY=NONE
289 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
290 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
291 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
292 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
293 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
294 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
295 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
296 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
297 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
298 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
299 [ ! -f "$LUSTRE_RMMOD" ] &&
300 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
301 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
302 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
303 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
304 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
305 [ ! -f "$LFS_MIGRATE" ] &&
306 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
307 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
308 [ ! -f "$LR_READER" ] &&
309 export LR_READER=$(which lr_reader 2> /dev/null)
310 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
311 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
312 [ ! -f "$LSOM_SYNC" ] &&
313 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
314 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
315 export NAME=${NAME:-local}
316 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
317 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
318 export LGSSD=$(which lgssd)
319 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
320 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
321 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
323 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
325 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
326 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
328 export DMSETUP=${DMSETUP:-dmsetup}
329 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
330 export LOSETUP=${LOSETUP:-losetup}
332 if [ "$ACCEPTOR_PORT" ]; then
333 export PORT_OPT="--port $ACCEPTOR_PORT"
337 $RPC_MODE || echo "Using GSS shared-key feature"
338 which lgss_sk > /dev/null 2>&1 ||
339 error_exit "built with lgss_sk disabled! SEC=$SEC"
347 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
348 which lgss_keyring > /dev/null 2>&1 ||
349 error_exit "built with gss disabled! SEC=$SEC"
360 IDENTITY_UPCALL=false
364 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
366 # Paths on remote nodes, if different
367 export RLUSTRE=${RLUSTRE:-$LUSTRE}
368 export RPWD=${RPWD:-$PWD}
369 export I_MOUNTED=${I_MOUNTED:-"no"}
370 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
371 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
372 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
373 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
374 ! -f $LUSTRE/mdt/mdt.ko ]; then
375 export CLIENTMODSONLY=yes
378 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
379 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
383 while getopts "rvwf:" opt $*; do
388 w) WRITECONF=writeconf;;
393 shift $((OPTIND - 1))
396 # print the durations of each test if "true"
397 DDETAILS=${DDETAILS:-false}
398 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
403 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
410 ncpts=$(do_facet $facet "lctl get_param -n " \
411 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
413 if [ $ncpts -eq 0 ]; then
420 # Return a numeric version code based on a version string. The version
421 # code is useful for comparison two version strings to see which is newer.
423 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
424 eval set -- $(tr "[:punct:]" " " <<< $*)
426 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
429 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
430 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
432 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
434 # usage: lustre_build_version
436 # All Lustre versions support "lctl get_param" to report the version of the
437 # code running in the kernel (what our tests are interested in), but it
438 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
439 # the "version" parameter doesn't include "lustre: " at the beginning.
440 # If that fails, call "lctl lustre_build_version" which prints either (or both)
441 # the userspace and kernel build versions, but until 2.8.55 required root
442 # access to get the Lustre kernel version. If that also fails, fall back to
443 # using "lctl --version", which is easy to parse and works without the kernel
444 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
445 # not the module version, though they are usually the same.
447 # Various commands and their output format for different Lustre versions:
448 # lctl get_param version: 2.9.55
449 # lctl get_param version: lustre: 2.8.53
450 # lctl get_param version: lustre: 2.6.52
451 # kernel: patchless_client
452 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
453 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
454 # lctl lustre_build_version: error: lustre_build_version: Permission denied
455 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
456 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
457 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
458 # lctl --version: lctl 2.6.50
460 # output: prints version string to stdout in (up to 4) dotted-decimal values
461 lustre_build_version() {
462 local facet=${1:-client}
463 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
464 $LCTL lustre_build_version 2>/dev/null ||
465 $LCTL --version 2>/dev/null | cut -d' ' -f2")
466 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
467 [ -n "$lver" ] && ver="$lver"
469 sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' -e 's/_/./g' <<<$ver |
473 # Report the Lustre numeric build version code for the supplied facet.
474 lustre_version_code() {
475 version_code $(lustre_build_version $1)
479 /sbin/lsmod | grep -q "^\<$1\>"
491 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
494 # parallels can't load modules directly from prlfs, use /tmp instead
495 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
496 local target="$(mktemp)"
498 cp "$module" "$target"
501 [[ $rc == 0 ]] && PRLFS=true
509 # Load a module on the system where this is running.
511 # usage: load_module module_name [module arguments for insmod/modprobe]
513 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
514 # will be used as the arguments. Otherwise arguments will be obtained from
515 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
518 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
521 local base=$(basename $module $ext)
523 local -A module_is_loaded_aa
527 for mod in $(lsmod | awk '{ print $1; }'); do
528 module_is_loaded_aa[${mod//-/_}]=true
532 ${module_is_loaded_aa[${1//-/_}]:-false}
535 if module_is_loaded $base; then
539 if [[ -f $LUSTRE/$module$ext ]]; then
540 path=$LUSTRE/$module$ext
541 elif [[ "$base" == lnet_selftest ]] &&
542 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
543 path=$LUSTRE/../lnet/selftest/$base$ext
548 if [[ -n "$path" ]]; then
549 # Try to load any non-Lustre modules that $module depends on.
550 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
551 if ! module_is_loaded $mod; then
557 # If no module arguments were passed then get them from
558 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
559 if [ $# -eq 0 ]; then
560 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
561 # not in Bash until 4.x, so we resort to eval.
562 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
563 eval set -- \$$optvar
564 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
565 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
567 opt=$(awk -v var="^options $base" '$0 ~ var \
568 {gsub("'"options $base"'",""); print}' \
570 set -- $(echo -n $opt)
572 # Ensure we have accept=all for lnet
573 if [[ "$base" == lnet ]]; then
574 # OK, this is a bit wordy...
575 local arg accept_all_present=false
578 [[ "$arg" == accept=all ]] &&
579 accept_all_present=true
582 $accept_all_present || set -- "$@" accept=all
589 [ $# -gt 0 ] && echo "${module} options: '$*'"
591 # Note that insmod will ignore anything in modprobe.conf, which is why
592 # we're passing options on the command-line. If $path does not exist
593 # then we must be testing a "make install" or"rpm" installation. Also
594 # note that failing to load ptlrpc_gss is not considered fatal.
595 if [[ -n "$path" ]]; then
596 lustre_insmod $path "$@"
597 elif [[ "$base" == ptlrpc_gss ]]; then
598 if ! modprobe $base "$@" 2>/dev/null; then
599 echo "gss/krb5 is not supported"
606 load_modules_local() {
607 if [ -n "$MODPROBE" ]; then
609 echo "Using modprobe to load modules"
613 # Create special udev test rules on every node
614 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
615 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
617 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
619 udevadm control --reload-rules
622 echo Loading modules from $LUSTRE
626 if [ -f /sys/devices/system/cpu/online ]; then
627 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
628 echo "detected $ncpus online CPUs by sysfs"
630 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
632 if [ $rc -eq 0 ]; then
633 echo "detected $ncpus online CPUs by getconf"
635 echo "Can't detect number of CPUs"
640 # if there is only one CPU core, libcfs can only create one partition
641 # if there is more than 4 CPU cores, libcfs should create multiple CPU
642 # partitions. So we just force libcfs to create 2 partitions for
643 # system with 2 or 4 cores
644 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
645 # force to enable multiple CPU partitions
646 echo "Force libcfs to create 2 CPU partitions"
647 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
649 echo "libcfs will create CPU partition based on online CPUs"
652 load_module ../libcfs/libcfs/libcfs
653 # Prevent local MODOPTS_LIBCFS being passed as part of environment
654 # variable to remote nodes
658 load_module ../lnet/lnet/lnet
660 LNDPATH=${LNDPATH:-"../lnet/klnds"}
661 if [ -z "$LNETLND" ]; then
663 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
664 tcp*) LNETLND="socklnd/ksocklnd" ;;
665 *) local lnd="${NETTYPE%%[0-9]}lnd"
666 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
667 LNETLND="$lnd/k$lnd" ||
668 LNETLND="socklnd/ksocklnd"
671 load_module ../lnet/klnds/$LNETLND
672 load_module obdclass/obdclass
673 load_module ptlrpc/ptlrpc
674 load_module ptlrpc/gss/ptlrpc_gss
682 load_module obdecho/obdecho
683 if ! client_only; then
684 load_module lfsck/lfsck
685 [ "$LQUOTA" != "no" ] &&
686 load_module quota/lquota $LQUOTAOPTS
687 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
688 load_module osd-zfs/osd_zfs
689 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
690 load_module ../ldiskfs/ldiskfs
691 load_module osd-ldiskfs/osd_ldiskfs
703 load_module llite/lustre
704 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
706 rm -f $OGDB/ogdb-$HOSTNAME
707 $LCTL modules > $OGDB/ogdb-$HOSTNAME
709 # 'mount' doesn't look in $PATH, just sbin
710 local mount_lustre=$LUSTRE/utils/mount.lustre
711 if [ -f $mount_lustre ]; then
712 local sbin_mount=$(readlink -f /sbin)/mount.lustre
713 if grep -qw "$sbin_mount" /proc/mounts; then
714 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
716 if ! grep -qw "$sbin_mount" /proc/mounts; then
717 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
718 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
719 cat <<- EOF > "$sbin_mount"
722 echo "This $sbin_mount just a mountpoint." 1>&2
723 echo "It is never supposed to be run." 1>&2
724 logger -p emerg -- "using stub $sbin_mount $@"
727 chmod a+x $sbin_mount
729 mount --bind $mount_lustre $sbin_mount ||
730 error "can't bind $mount_lustre to $sbin_mount"
738 # load modules on remote nodes optionally
739 # lustre-tests have to be installed on these nodes
740 if $LOAD_MODULES_REMOTE; then
741 local list=$(comma_list $(remote_nodes_list))
742 if [ -n "$list" ]; then
743 echo "loading modules on: '$list'"
744 do_rpc_nodes "$list" load_modules_local
750 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
751 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
752 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
753 echo "$LEAK_LUSTRE" 1>&2
754 echo "$LEAK_PORTALS" 1>&2
755 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
756 echo "Memory leaks detected"
757 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
763 wait_exit_ST client # bug 12845
765 $LUSTRE_RMMOD ldiskfs || return 2
767 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
768 rm /etc/udev/rules.d/99-lustre-test.rules
769 udevadm control --reload-rules
772 if $LOAD_MODULES_REMOTE; then
773 local list=$(comma_list $(remote_nodes_list))
774 if [ -n "$list" ]; then
775 echo "unloading modules on: '$list'"
776 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
777 do_rpc_nodes "$list" check_mem_leak
778 do_rpc_nodes "$list" "rm /etc/udev/rules.d/99-lustre-test.rules"
779 do_rpc_nodes "$list" "udevadm control --reload-rules"
780 do_rpc_nodes "$list" "udevadm trigger"
784 local sbin_mount=$(readlink -f /sbin)/mount.lustre
785 if grep -qe "$sbin_mount " /proc/mounts; then
786 umount $sbin_mount || true
787 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
791 check_mem_leak || return 254
793 echo "modules unloaded."
798 local facet=${1:-$SINGLEMDS}
801 case $(facet_fstype $facet) in
802 ldiskfs) size=50;; # largest seen is 44, leave some headroom
803 # grant_block_size is in bytes, allow at least 2x max blocksize
804 zfs) size=$(lctl get_param osc.$FSNAME*.import |
805 awk '/grant_block_size:/ {print $2/512; exit;}')
809 echo -n $((size * MDSCOUNT))
813 local facet=${1:-$SINGLEMDS}
814 local fstype=$(facet_fstype $facet)
817 ldiskfs) size=4;; # ~4KB per inode
818 zfs) size=11;; # 10 to 11KB per inode
824 check_gss_daemon_nodes() {
828 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
829 if [ \\\"\\\$num\\\" -ne 1 ]; then
830 echo \\\$num instance of $dname;
835 check_gss_daemon_facet() {
839 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
840 if [ $num -ne 1 ]; then
841 echo "$num instance of $dname on $facet"
850 echo Stopping $@ on $list
851 do_nodes $list "killall -2 $@ 2>/dev/null || true"
854 # start gss daemons on all nodes, or "daemon" on "nodes" if set
855 start_gss_daemons() {
859 if [ "$nodes" ] && [ "$daemon" ] ; then
860 echo "Starting gss daemon on nodes: $nodes"
861 do_nodes $nodes "$daemon" || return 8
865 nodes=$(comma_list $(mdts_nodes))
866 echo "Starting gss daemon on mds: $nodes"
868 # Start all versions, in case of switching
869 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
871 do_nodes $nodes "$LSVCGSSD -v" || return 1
874 do_nodes $nodes "$LGSSD -v" || return 2
877 nodes=$(comma_list $(osts_nodes))
878 echo "Starting gss daemon on ost: $nodes"
880 # Start all versions, in case of switching
881 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
883 do_nodes $nodes "$LSVCGSSD -v" || return 3
885 # starting on clients
887 local clients=${CLIENTS:-$HOSTNAME}
889 echo "Starting $LGSSD on clients $clients "
890 do_nodes $clients "$LGSSD -v" || return 4
893 # wait daemons entering "stable" status
897 # check daemons are running
899 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
900 check_gss_daemon_nodes $nodes lsvcgssd || return 5
902 nodes=$(comma_list $(mdts_nodes))
903 check_gss_daemon_nodes $nodes lgssd || return 6
906 check_gss_daemon_nodes $clients lgssd || return 7
911 local nodes=$(comma_list $(mdts_nodes))
913 send_sigint $nodes lsvcgssd lgssd
915 nodes=$(comma_list $(osts_nodes))
916 send_sigint $nodes lsvcgssd
918 nodes=${CLIENTS:-$HOSTNAME}
919 send_sigint $nodes lgssd
923 # Add mount flags for shared key
925 if grep -q skpath <<< "$mt_opts" ; then
926 mt_opts=$(echo $mt_opts |
927 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
929 if [ -z "$mt_opts" ]; then
930 mt_opts="-o skpath=$SK_PATH"
932 mt_opts="$mt_opts,skpath=$SK_PATH"
948 if ! module_loaded ptlrpc_gss; then
949 load_module ptlrpc/gss/ptlrpc_gss
950 module_loaded ptlrpc_gss ||
951 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
954 if $GSS_KRB5 || $GSS_SK; then
955 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
958 if $GSS_SK && $SK_NO_KEY; then
959 local numclients=${1:-$CLIENTCOUNT}
960 local clients=${CLIENTS:-$HOSTNAME}
962 # security ctx config for keyring
965 if grep -q request-key /proc/mounts > /dev/null; then
966 echo "SSK: Request key already mounted."
968 mount -o bind $SK_OM_PATH /etc/request-key.d/
970 local lgssc_conf_line='create lgssc * * '
971 lgssc_conf_line+=$(which lgss_keyring)
972 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
974 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
975 echo "$lgssc_conf_line" > $lgssc_conf_file
976 [ -e $lgssc_conf_file ] ||
977 error_exit "Could not find key options in $lgssc_conf_file"
979 if ! local_mode; then
980 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
982 do_nodes $(comma_list $(all_nodes)) "mount \
983 -o bind $SK_OM_PATH \
985 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
986 $HOSTNAME:$lgssc_conf_file \
987 $lgssc_conf_file >/dev/null 2>&1"
990 # create shared key on all nodes
991 mkdir -p $SK_PATH/nodemap
992 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
993 $SK_PATH/$FSNAME-*.key
994 # for nodemap testing each client may need own key,
995 # and S2S now requires keys as well, both for "client"
998 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
999 -w $SK_PATH/$FSNAME-nmclient.key \
1000 -d /dev/urandom >/dev/null 2>&1
1001 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
1002 -w $SK_PATH/$FSNAME-s2s-server.key \
1003 -d /dev/urandom >/dev/null 2>&1
1006 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1007 -d /dev/urandom >/dev/null 2>&1
1009 for i in $(seq 0 $((numclients - 1))); do
1010 lgss_sk -t server -f$FSNAME -n c$i \
1011 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1015 if ! local_mode; then
1016 do_nodes $(comma_list $(all_nodes)) "rsync -av \
1017 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
1019 # Set client keys to client type to generate prime P
1021 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1022 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1024 do_nodes $clients "lgss_sk -t client -m \
1025 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1026 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1027 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1029 # This is required for servers as well, if S2S in use
1031 do_nodes $(comma_list $(mdts_nodes)) \
1032 "cp $SK_PATH/$FSNAME-s2s-server.key \
1033 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1034 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1036 do_nodes $(comma_list $(osts_nodes)) \
1037 "cp $SK_PATH/$FSNAME-s2s-server.key \
1038 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1039 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1041 do_nodes $clients "lgss_sk -t client \
1042 -m $SK_PATH/$FSNAME-nmclient.key \
1047 # mount options for servers and clients
1048 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1049 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1050 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1051 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1055 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
1057 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1064 # maybe cleanup credential cache?
1071 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1072 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1073 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1077 $RPC_MODE || echo "Cleaning up Shared Key.."
1078 do_nodes $(comma_list $(all_nodes)) "rm -f \
1079 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1080 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1081 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1082 # Remove the mount and clean up the files we added to SK_PATH
1083 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1084 request-key.d /proc/mounts; do umount \
1085 /etc/request-key.d/; done"
1086 do_nodes $(comma_list $(all_nodes)) "rm -f \
1087 $SK_OM_PATH/lgssc.conf"
1088 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1095 local var=${facet}_svc
1103 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1104 tr '[:lower:]' '[:upper:]'
1110 if [ $facet == mgs ] || [ $facet == client ]; then
1114 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1122 if [ -n "${!var}" ]; then
1127 var=$(facet_type $facet)FSTYPE
1128 if [ -n "${!var}" ]; then
1133 if [ -n "$FSTYPE" ]; then
1138 if [[ $facet == mgs ]] && combined_mgs_mds; then
1150 local facets=$(get_facets)
1153 for facet in ${facets//,/ }; do
1154 if [ $node == $(facet_host $facet) ] ||
1155 [ $node == "$(facet_failover_host $facet)" ]; then
1156 fstype=$(facet_fstype $facet)
1157 if [[ $fstypes != *$fstype* ]]; then
1158 fstypes+="${fstypes:+,}$fstype"
1167 local num=$(facet_number $facet)
1170 if [[ $(facet_type $facet) = OST ]]; then
1171 index=OSTINDEX${num}
1172 if [[ -n "${!index}" ]]; then
1177 index=${OST_INDICES[num - 1]}
1180 [[ -n "$index" ]] || index=$((num - 1))
1188 local fstype=$(facet_fstype $facet)
1192 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1194 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1195 ${dev} 2>/dev/null");;
1197 error "unknown fstype!";;
1205 local device=$(mdsdevname $num)
1206 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1212 local device=$(ostdevname $num)
1213 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1218 # Get the device of a facet.
1225 mgs) device=$(mgsdevname) ;;
1226 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1227 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1228 fs2mds) device=$(mdsdevname 1_2) ;;
1229 fs2ost) device=$(ostdevname 1_2) ;;
1230 fs3ost) device=$(ostdevname 2_2) ;;
1238 # Get the virtual device of a facet.
1245 mgs) device=$(mgsvdevname) ;;
1246 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1247 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1248 fs2mds) device=$(mdsvdevname 1_2) ;;
1249 fs2ost) device=$(ostvdevname 1_2) ;;
1250 fs3ost) device=$(ostvdevname 2_2) ;;
1258 local virt=$(virt-what 2> /dev/null)
1260 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1262 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1265 VMware|KVM|VirtualBox|Parallels)
1266 echo $virt | tr '[A-Z]' '[a-z]' ;;
1272 # Re-read the partition table on failover partner host.
1273 # After a ZFS storage pool is created on a shared device, the partition table
1274 # on the device may change. However, the operating system on the failover
1275 # host may not notice the change automatically. Without the up-to-date partition
1276 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1277 # relative to partition rather than disk beginnings.
1279 # This function performs partprobe on the failover host to make it re-read the
1282 refresh_partition_table() {
1287 host=$(facet_passive_host $facet)
1288 if [[ -n "$host" ]]; then
1289 do_node $host "$PARTPROBE $device"
1294 # Get ZFS storage pool name.
1301 device=$(facet_device $facet)
1302 # poolname is string before "/"
1303 poolname="${device%%/*}"
1310 # Get ZFS local fsname.
1312 zfs_local_fsname() {
1314 local lfsname=$(basename $(facet_device $facet))
1320 # Create ZFS storage pool.
1327 local opts=${@:-"-o cachefile=none"}
1329 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1330 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1331 $ZPOOL create -f $opts $poolname $vdev"
1335 # Create ZFS file system.
1341 local opts=${@:-"-o mountpoint=legacy"}
1343 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1344 $ZFS create $opts $dataset"
1348 # Export ZFS storage pool.
1349 # Before exporting the pool, all datasets within the pool should be unmounted.
1357 poolname=$(zpool_name $facet)
1359 if [[ -n "$poolname" ]]; then
1360 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1361 grep -q ^$poolname/ /proc/mounts ||
1362 $ZPOOL export $opts $poolname"
1367 # Destroy ZFS storage pool.
1368 # Destroy the given pool and free up any devices for other use. This command
1369 # tries to unmount any active datasets before destroying the pool.
1370 # -f Force any active datasets contained within the pool to be unmounted.
1374 local poolname=${2:-$(zpool_name $facet)}
1376 if [[ -n "$poolname" ]]; then
1377 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1378 $ZPOOL destroy -f $poolname"
1383 # Import ZFS storage pool.
1384 # Force importing, even if the pool appears to be potentially active.
1389 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1392 poolname=$(zpool_name $facet)
1394 if [[ -n "$poolname" ]]; then
1395 opts+=" -d $(dirname $(facet_vdevice $facet))"
1396 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1397 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1398 $ZPOOL import -f $opts $poolname"
1403 # Reimport ZFS storage pool with new name
1408 local opts="-o cachefile=none"
1409 local poolname=$(zpool_name $facet)
1411 opts+=" -d $(dirname $(facet_vdevice $facet))"
1412 do_facet $facet "$ZPOOL export $poolname;
1413 $ZPOOL import $opts $poolname $newpool"
1417 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1418 # is not automatically imported on system startup.
1420 # In a failover environment, this will provide resource level fencing which
1421 # will ensure that the same ZFS storage pool will not be imported concurrently
1422 # on different nodes.
1424 disable_zpool_cache() {
1428 poolname=$(zpool_name $facet)
1430 if [[ -n "$poolname" ]]; then
1431 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1436 # This and set_osd_param() shall be used to access OSD parameters
1437 # once existed under "obdfilter":
1442 # writethrough_cache_enable
1446 local device=${2:-$FSNAME-OST*}
1449 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1450 osd-*.$device.$name 2>&1" | grep -v 'error:'
1455 local device=${2:-$FSNAME-OST*}
1459 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1460 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1464 local dz=${1:-$DEBUG_SIZE}
1466 if [ -f /sys/devices/system/cpu/possible ]; then
1467 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1469 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1472 # bug 19944, adjust size to be -gt num_possible_cpus()
1473 # promise 2MB for every cpu at least
1474 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1477 lctl set_param debug_mb=$dz
1480 set_default_debug () {
1481 local debug=${1:-"$PTLDEBUG"}
1482 local subsys=${2:-"$SUBSYSTEM"}
1483 local debug_size=${3:-$DEBUG_SIZE}
1485 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1486 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1488 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1491 set_default_debug_nodes () {
1494 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1495 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1499 do_rpc_nodes "$nodes" set_default_debug \
1500 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1503 set_default_debug_facet () {
1505 local node=$(facet_active_host $facet)
1506 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1508 set_default_debug_nodes $node
1512 local hostid=${1:-$(hostid)}
1514 if [ ! -s /etc/hostid ]; then
1515 printf $(echo -n $hostid |
1516 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1522 local facets=${1:-$(get_facets)}
1525 for facet in ${facets//,/ }; do
1528 [ $RC -eq 0 ] && continue
1530 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1531 skip_noexit "Restart of $facet failed!." &&
1534 error "Restart of $facet failed!"
1541 # Add argument "arg" (e.g., "loop") to the comma-separated list
1542 # of arguments for option "opt" (e.g., "-o") on command
1543 # line "opts" (e.g., "-o flock").
1549 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1551 if echo "$opts" | grep -q $opt_pattern; then
1552 opts=$(echo "$opts" | sed -e \
1553 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1555 opts+="${opts:+ }$opt $arg"
1561 # Associate loop device with a given regular file.
1562 # Return the loop device.
1564 setup_loop_device() {
1568 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1569 if [[ -z \\\$loop_dev ]]; then
1570 loop_dev=\\\$($LOSETUP -f);
1571 $LOSETUP \\\$loop_dev $file || loop_dev=;
1573 echo -n \\\$loop_dev"
1577 # Detach a loop device.
1579 cleanup_loop_device() {
1583 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1584 $LOSETUP -d $loop_dev"
1588 # Check if a given device is a block device.
1595 [[ -n "$dev" ]] || return 1
1596 do_facet $facet "test -b $dev" || return 1
1597 if [[ -n "$size" ]]; then
1598 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1599 count=1 skip=$size 2>&1" |
1600 awk '($3 == "in") { print $1 }')
1601 [[ "$in" = "1+0" ]] || return 1
1606 # Check if a given device is a device-mapper device.
1612 [[ -n "$dev" ]] || return 1
1613 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1617 # Check if a given device is a device-mapper flakey device.
1619 is_dm_flakey_dev() {
1624 [[ -n "$dev" ]] || return 1
1626 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1628 [[ $type = flakey ]] && return 0 || return 1
1632 # Check if device-mapper flakey device is supported by the kernel
1633 # of $facet node or not.
1635 dm_flakey_supported() {
1639 do_facet $facet "modprobe dm-flakey;
1640 $DMSETUP targets | grep -q flakey" &> /dev/null
1644 # Get the device-mapper flakey device name of a given facet.
1646 dm_facet_devname() {
1648 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1650 echo -n ${facet}_flakey
1654 # Get the device-mapper flakey device of a given facet.
1655 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1657 dm_facet_devpath() {
1660 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1664 # Set a device-mapper device with a new table.
1666 # The table has the following format:
1667 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1669 # flakey <target_args> includes:
1670 # <destination_device> <offset> <up_interval> <down_interval> \
1671 # [<num_features> [<feature_arguments>]]
1673 # linear <target_args> includes:
1674 # <destination_device> <start_sector>
1676 dm_set_dev_table() {
1679 local target_type=$3
1685 read tmp num_sectors tmp real_dev tmp \
1686 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1688 case $target_type in
1690 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1693 table="0 $num_sectors linear $real_dev 0"
1695 *) error "invalid target type $target_type" ;;
1698 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1699 error "failed to suspend $dm_dev"
1700 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1701 error "failed to load $target_type table into $dm_dev"
1702 do_facet $facet "$DMSETUP resume $dm_dev" ||
1703 error "failed to resume $dm_dev"
1707 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1708 # feature parameter.
1711 # All write I/O is silently ignored.
1712 # Read I/O is handled correctly.
1714 dm_set_dev_readonly() {
1716 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1718 dm_set_dev_table $facet $dm_dev flakey
1722 # Set a device-mapper device to traditional linear mapping mode.
1724 dm_clear_dev_readonly() {
1726 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1728 dm_set_dev_table $facet $dm_dev linear
1732 # Set the device of a given facet as "read-only".
1734 set_dev_readonly() {
1736 local svc=${facet}_svc
1738 if [[ $(facet_fstype $facet) = zfs ]] ||
1739 ! dm_flakey_supported $facet; then
1740 do_facet $facet $LCTL --device ${!svc} readonly
1742 dm_set_dev_readonly $facet
1747 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1754 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1755 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1756 echo -n $num_sectors
1760 # Create a device-mapper device with a given block device or regular file (will
1761 # be associated with loop device).
1762 # Return the full path of the device-mapper device.
1766 local real_dev=$2 # destination device
1767 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1768 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1770 # check if the device-mapper device to be created already exists
1771 if is_dm_dev $facet $dm_dev; then
1772 # if the existing device was set to "read-only", then clear it
1773 ! is_dm_flakey_dev $facet $dm_dev ||
1774 dm_clear_dev_readonly $facet $dm_dev
1780 # check if the destination device is a block device, and if not,
1781 # associate it with a loop device
1782 is_blkdev $facet $real_dev ||
1783 real_dev=$(setup_loop_device $facet $real_dev)
1784 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1786 # now create the device-mapper device
1787 local num_sectors=$(get_num_sectors $facet $real_dev)
1788 local table="0 $num_sectors linear $real_dev 0"
1791 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1792 { rc=${PIPESTATUS[0]}; dm_dev=; }
1793 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1800 # Map the facet name to its device variable name.
1802 facet_device_alias() {
1804 local dev_alias=$facet
1807 fs2mds) dev_alias=mds1_2 ;;
1808 fs2ost) dev_alias=ost1_2 ;;
1809 fs3ost) dev_alias=ost2_2 ;;
1817 # Save the original value of the facet device and export the new value.
1823 local active_facet=$(facet_active $facet)
1824 local dev_alias=$(facet_device_alias $active_facet)
1825 local dev_name=${dev_alias}_dev
1826 local dev=${!dev_name}
1828 if [[ $active_facet = $facet ]]; then
1829 local failover_dev=${dev_alias}failover_dev
1830 if [[ ${!failover_dev} = $dev ]]; then
1831 eval export ${failover_dev}_saved=$dev
1832 eval export ${failover_dev}=$dm_dev
1835 dev_alias=$(facet_device_alias $facet)
1836 local facet_dev=${dev_alias}_dev
1837 if [[ ${!facet_dev} = $dev ]]; then
1838 eval export ${facet_dev}_saved=$dev
1839 eval export ${facet_dev}=$dm_dev
1843 eval export ${dev_name}_saved=$dev
1844 eval export ${dev_name}=$dm_dev
1848 # Restore the saved value of the facet device.
1853 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1854 local dev_alias=$(facet_device_alias $facet)
1856 local saved_dev=${dev_alias}_dev_saved
1857 [[ -z ${!saved_dev} ]] ||
1858 eval export ${dev_alias}_dev=${!saved_dev}
1860 saved_dev=${dev_alias}failover_dev_saved
1861 [[ -z ${!saved_dev} ]] ||
1862 eval export ${dev_alias}failover_dev=${!saved_dev}
1866 # Remove a device-mapper device.
1867 # If the destination device is a loop device, then also detach it.
1871 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1875 is_dm_dev $facet $dm_dev || return 0
1877 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
1878 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
1880 do_facet $facet "$DMSETUP remove $dm_dev"
1881 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1883 unexport_dm_dev $facet
1885 # detach a loop device
1886 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
1888 # unload dm-flakey module
1889 do_facet $facet "modprobe -r dm-flakey" || true
1895 local active_facet=$(facet_active $facet)
1896 local dev_alias=$(facet_device_alias $active_facet)
1897 local dev=${dev_alias}_dev
1898 local opt=${facet}_opt
1899 local mntpt=$(facet_mntpt $facet)
1900 local opts="${!opt} $@"
1901 local fstype=$(facet_fstype $facet)
1903 local dm_dev=${!dev}
1905 module_loaded lustre || load_modules
1909 if dm_flakey_supported $facet; then
1910 dm_dev=$(dm_create_dev $facet ${!dev})
1911 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
1914 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
1916 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
1918 # import ZFS storage pool
1919 import_zpool $facet || return ${PIPESTATUS[0]}
1921 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1922 lustre:svname $dm_dev");;
1924 error "unknown fstype!";;
1927 echo "Starting ${facet}: $opts $dm_dev $mntpt"
1928 # for testing LU-482 error handling in mount_facets() and test_0a()
1929 if [ -f $TMP/test-lu482-trigger ]; then
1933 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
1937 if [ $RC -ne 0 ]; then
1938 echo "Start of $dm_dev on ${facet} failed ${RC}"
1942 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1943 if [[ "$health" != "healthy" ]]; then
1944 error "$facet is in a unhealthy state"
1947 set_default_debug_facet $facet
1949 if [[ $facet == mds* ]]; then
1951 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1954 if [[ $opts =~ .*nosvc.* ]]; then
1955 echo "Start $dm_dev without service"
1960 wait_update_facet ${facet} "$E2LABEL $dm_dev \
1961 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1962 "" || error "$dm_dev failed to initialize!";;
1964 wait_update_facet ${facet} "$ZFS get -H -o value \
1965 lustre:svname $dm_dev 2>/dev/null | \
1966 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1967 error "$dm_dev failed to initialize!";;
1970 error "unknown fstype!";;
1974 # commit the device label change to disk
1975 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1976 echo "Commit the device label on ${!dev}"
1977 do_facet $facet "sync; sleep 1; sync"
1981 label=$(devicelabel ${facet} $dm_dev)
1982 [ -z "$label" ] && echo no label for $dm_dev && exit 1
1983 eval export ${facet}_svc=${label}
1984 echo Started ${label}
1986 export_dm_dev $facet $dm_dev
1991 # start facet device options
1997 local dev_alias=$(facet_device_alias $facet)
1999 eval export ${dev_alias}_dev=${device}
2000 eval export ${facet}_opt=\"$@\"
2002 local varname=${dev_alias}failover_dev
2003 if [ -n "${!varname}" ] ; then
2004 eval export ${dev_alias}failover_dev=${!varname}
2006 eval export ${dev_alias}failover_dev=$device
2009 local mntpt=$(facet_mntpt $facet)
2010 do_facet ${facet} mkdir -p $mntpt
2011 eval export ${facet}_MOUNT=$mntpt
2012 mount_facet ${facet}
2015 if [[ $facet == mds* ]]; then
2017 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
2028 local HOST=$(facet_active_host $facet)
2029 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2031 local mntpt=$(facet_mntpt $facet)
2032 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2033 if [ ${running} -ne 0 ]; then
2034 echo "Stopping $mntpt (opts:$@) on $HOST"
2035 do_facet ${facet} $UMOUNT $@ $mntpt
2038 # umount should block, but we should wait for unrelated obd's
2039 # like the MGS or MGC to also stop.
2040 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2042 if [[ $(facet_fstype $facet) == zfs ]]; then
2043 # export ZFS storage pool
2044 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2045 elif dm_flakey_supported $facet; then
2046 local host=${facet}_HOST
2047 local failover_host=${facet}failover_HOST
2048 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2049 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2050 dm_cleanup_dev $facet
2055 # get mdt quota type
2057 local varsvc=${SINGLEMDS}_svc
2058 do_facet $SINGLEMDS $LCTL get_param -n \
2059 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2062 # get ost quota type
2064 # All OSTs should have same quota type
2065 local varsvc=ost1_svc
2066 do_facet ost1 $LCTL get_param -n \
2067 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2070 # restore old quota type settings
2072 if [ "$old_MDT_QUOTA_TYPE" ]; then
2073 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2074 do_facet mgs $PERM_CMD \
2075 osd-*.$FSNAME-MDT*.quota_slave.enable = \
2078 do_facet mgs $PERM_CMD \
2079 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2082 if [ "$old_OST_QUOTA_TYPE" ]; then
2083 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2084 do_facet mgs $PERM_CMD \
2085 osd-*.$FSNAME-OST*.quota_slave.enable = \
2088 do_facet mgs $LCTL conf_param \
2089 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2094 # Handle the case when there is a space in the lfs df
2095 # "filesystem summary" line the same as when there is no space.
2096 # This will allow fixing the "lfs df" summary line in the future.
2098 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2101 # Get free inodes on the MDT specified by mdt index, free indoes on
2102 # the whole filesystem will be returned when index == -1.
2108 if [ $index -eq -1 ]; then
2111 mdt_uuid=$(mdtuuid_from_index $index)
2114 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2119 # Get the OST device status from 'lfs df' with a given OST index.
2123 local mnt_pnt=${2:-$MOUNT}
2126 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2127 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2133 # save old quota type & set new quota type
2134 local mdt_qtype=$(mdt_quota_type)
2135 local ost_qtype=$(ost_quota_type)
2137 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2138 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2140 export old_MDT_QUOTA_TYPE=$mdt_qtype
2141 export old_OST_QUOTA_TYPE=$ost_qtype
2143 if [[ $PERM_CMD = *"set_param -P"* ]]; then
2144 do_facet mgs $PERM_CMD \
2145 osd-*.$FSNAME-MDT*.quota_slave.enable=$QUOTA_TYPE
2146 do_facet mgs $PERM_CMD \
2147 osd-*.$FSNAME-OST*.quota_slave.enable=$QUOTA_TYPE
2149 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2150 error "set mdt quota type failed"
2151 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2152 error "set ost quota type failed"
2155 local quota_usrs=$QUOTA_USERS
2157 # get_filesystem_size
2158 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2159 local blk_soft=$((disksz + 1024))
2160 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2162 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2163 local i_soft=$inodes
2164 local i_hard=$((i_soft + i_soft / 20))
2166 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2167 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2168 "inode-hardlimit: $i_hard"
2171 for usr in $quota_usrs; do
2172 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2174 cmd="$LFS setquota -$type $usr -b $blk_soft"
2175 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2177 eval $cmd || error "$cmd FAILED!"
2179 # display the quota status
2180 echo "Quota settings for $usr : "
2181 $LFS quota -v -u $usr $mntpt || true
2188 local opts=${3:-$MOUNT_OPTS}
2189 opts=${opts:+-o $opts}
2190 local flags=${4:-$MOUNT_FLAGS}
2192 local device=$MGSNID:/$FSNAME$FILESET
2193 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2194 echo "Bad mount command: opt=$flags $opts dev=$device " \
2199 echo "Starting client: $client: $flags $opts $device $mnt"
2200 do_node $client mkdir -p $mnt
2201 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2202 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2204 #disable FILESET if not supported
2205 do_nodes $client lctl get_param -n \
2206 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2207 device=$MGSNID:/$FSNAME
2208 do_node $client mkdir -p $mnt/$FILESET
2209 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2212 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2213 # Mount using nodemap key
2214 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2215 if $SK_UNIQUE_NM; then
2216 mountkey=$SK_PATH/nodemap/c0.key
2218 local prunedopts=$(echo $opts |
2219 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2220 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2223 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2227 set_default_debug_nodes $client
2239 [ "$3" ] && force=-f
2240 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2241 if [ $running -ne 0 ]; then
2242 echo "Stopping client $client $mnt (opts:$force)"
2243 do_node $client lsof -t $mnt || need_kill=no
2244 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
2245 pids=$(do_node $client lsof -t $mnt | sort -u);
2246 if [ -n $pids ]; then
2247 do_node $client kill -9 $pids || true
2251 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
2252 if [ $busy -ne 0 ] ; then
2253 echo "$mnt is still busy, wait one second" && sleep 1
2254 do_node $client umount $force $mnt
2259 # Mount the file system on the MGS
2260 mount_mgs_client() {
2261 do_facet mgs "mkdir -p $MOUNT"
2262 zconf_mount $mgs_HOST $MOUNT $MOUNT_OPTS ||
2263 error "unable to mount $MOUNT on MGS"
2266 # Unmount the file system on the MGS
2267 umount_mgs_client() {
2268 zconf_umount $mgs_HOST $MOUNT
2269 do_facet mgs "rm -rf $MOUNT"
2272 # nodes is comma list
2273 sanity_mount_check_nodes () {
2279 # FIXME: assume that all cluster nodes run the same os
2280 [ "$(uname)" = Linux ] || return 0
2283 for mnt in $mnts ; do
2284 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2285 mpts=\\\$(mount | grep -c $mnt' ');
2286 if [ \\\$running -ne \\\$mpts ]; then
2287 echo \\\$(hostname) env are INSANE!;
2290 [ $? -eq 0 ] || rc=1
2295 sanity_mount_check_servers () {
2296 [ -n "$CLIENTONLY" ] &&
2297 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2298 echo Checking servers environments
2300 # FIXME: modify get_facets to display all facets wo params
2301 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2305 for facet in ${facets//,/ }; do
2306 node=$(facet_host ${facet})
2307 mntpt=$(facet_mntpt $facet)
2308 sanity_mount_check_nodes $node $mntpt ||
2309 { error "server $node environments are insane!"; return 1; }
2313 sanity_mount_check_clients () {
2314 local clients=${1:-$CLIENTS}
2315 local mntpt=${2:-$MOUNT}
2316 local mntpt2=${3:-$MOUNT2}
2318 [ -z $clients ] && clients=$(hostname)
2319 echo Checking clients $clients environments
2321 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2322 error "clients environments are insane!"
2325 sanity_mount_check () {
2326 sanity_mount_check_servers || return 1
2327 sanity_mount_check_clients || return 2
2330 # mount clients if not mouted
2331 zconf_mount_clients() {
2334 local opts=${3:-$MOUNT_OPTS}
2335 opts=${opts:+-o $opts}
2336 local flags=${4:-$MOUNT_FLAGS}
2337 local device=$MGSNID:/$FSNAME$FILESET
2338 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2339 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2344 echo "Starting client $clients: $flags $opts $device $mnt"
2345 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
2346 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2347 # Mount with own nodemap key
2349 # Mount all server nodes first with per-NM keys
2350 for nmclient in ${clients//,/ }; do
2351 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2352 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2355 # set perms for per-nodemap keys else permission denied
2356 do_nodes $(comma_list $(all_nodes)) \
2357 "keyctl show | grep lustre | cut -c1-11 |
2359 xargs -IX keyctl setperm X 0x3f3f3f3f"
2360 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2362 for nmclient in ${clients//,/ }; do
2363 if $SK_UNIQUE_NM; then
2364 mountkey=$SK_PATH/nodemap/c$i.key
2366 do_node $nmclient "! grep -q $mnt' ' \
2367 /proc/mounts || umount $mnt"
2368 local prunedopts=$(add_sk_mntflag $prunedopts);
2369 prunedopts=$(echo $prunedopts | sed -e \
2370 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2372 do_nodes $(comma_list $(all_server_nodes)) \
2375 do_node $nmclient $MOUNT_CMD $flags \
2376 $prunedopts $MGSNID:/$FSNAME $mnt ||
2381 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2383 do_nodes $clients $MOUNT_CMD $flags $opts \
2384 $MGSNID:/$FSNAME $mnt || return 1
2386 #disable FILESET if not supported
2387 do_nodes $clients lctl get_param -n \
2388 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2389 device=$MGSNID:/$FSNAME
2390 do_nodes $clients mkdir -p $mnt/$FILESET
2391 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2395 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2396 # Mount with nodemap key
2398 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2399 for nmclient in ${clients//,/ }; do
2400 if $SK_UNIQUE_NM; then
2401 mountkey=$SK_PATH/nodemap/c$i.key
2403 local prunedopts=$(echo $opts | sed -e \
2404 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2405 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2408 running=\\\$(mount | grep -c $mnt' ');
2410 if [ \\\$running -eq 0 ] ; then
2412 $MOUNT_CMD $flags $prunedopts $device $mnt;
2415 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2416 grep 'type lustre' | wc -l);
2417 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2418 echo zconf_mount_clients FAILED: \
2419 mount count \\\$running, not matching \
2420 with mount count of 'type lustre' \
2421 \\\$lustre_mnt_count;
2425 exit \\\$rc" || return ${PIPESTATUS[0]}
2432 if $SHARED_KEY; then
2433 tmpopts=$(add_sk_mntflag $opts)
2436 running=\\\$(mount | grep -c $mnt' ');
2438 if [ \\\$running -eq 0 ] ; then
2440 $MOUNT_CMD $flags $tmpopts $device $mnt;
2443 exit \\\$rc" || return ${PIPESTATUS[0]}
2446 echo "Started clients $clients: "
2447 do_nodes $clients "mount | grep $mnt' '"
2449 set_default_debug_nodes $clients
2454 zconf_umount_clients() {
2459 [ "$3" ] && force=-f
2461 echo "Stopping clients: $clients $mnt (opts:$force)"
2462 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2463 if [ \\\$running -ne 0 ] ; then
2464 echo Stopping client \\\$(hostname) $mnt opts:$force;
2465 lsof $mnt || need_kill=no;
2466 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2467 pids=\\\$(lsof -t $mnt | sort -u);
2468 if [ -n \\\"\\\$pids\\\" ]; then
2472 while umount $force $mnt 2>&1 | grep -q "busy"; do
2473 echo "$mnt is still busy, wait one second" && sleep 1;
2480 echo + $POWER_DOWN $node
2484 shutdown_node_hard () {
2486 local attempts=$SHUTDOWN_ATTEMPTS
2488 for i in $(seq $attempts) ; do
2491 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2492 echo "waiting for $host to fail attempts=$attempts"
2493 [ $i -lt $attempts ] || \
2494 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2500 local mnt=${2:-$MOUNT}
2503 if [ "$FAILURE_MODE" = HARD ]; then
2504 shutdown_node_hard $client
2506 zconf_umount_clients $client $mnt -f
2512 local facets="$(get_facets OST),$(get_facets MDS)"
2515 combined_mgs_mds || facets="$facets,mgs"
2517 for facet in ${facets//,/ }; do
2518 if [ $(facet_active_host $facet) == $host ]; then
2519 affected="$affected $facet"
2523 echo $(comma_list $affected)
2528 local host=${2:-$(facet_host $facet)}
2530 local label=$(convert_facet2label $facet)
2531 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2534 facets_up_on_host () {
2536 local facets=$(facets_on_host $host)
2539 for facet in ${facets//,/ }; do
2540 if $(facet_up $facet $host); then
2541 affected_up="$affected_up $facet"
2545 echo $(comma_list $affected_up)
2550 local affected_facet
2551 local affected_facets
2553 if [[ "$FAILURE_MODE" = HARD ]]; then
2554 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2555 dm_flakey_supported $facet; then
2556 affected_facets=$(affected_facets $facet)
2557 for affected_facet in ${affected_facets//,/ }; do
2558 unexport_dm_dev $affected_facet
2562 shutdown_node_hard $(facet_active_host $facet)
2570 echo + $POWER_UP $node
2583 if [ "$FAILURE_MODE" = HARD ]; then
2584 reboot_node $(facet_active_host $facet)
2592 if [ "$FAILURE_MODE" = HARD ]; then
2602 for facet in ${facets//,/ }; do
2603 hosts=$(expand_list $hosts $(facet_host $facet) )
2609 _check_progs_installed () {
2613 for prog in $progs; do
2614 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2615 echo $prog missing on $(hostname)
2622 check_progs_installed () {
2626 do_rpc_nodes "$nodes" _check_progs_installed $@
2629 # recovery-scale functions
2631 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2634 start_client_load() {
2637 local var=$(node_var_name $client)_load
2638 eval export ${var}=$load
2640 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2641 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2642 END_RUN_FILE=$END_RUN_FILE \
2643 LOAD_PID_FILE=$LOAD_PID_FILE \
2644 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2645 TESTNAME=$TESTNAME \
2646 DBENCH_LIB=$DBENCH_LIB \
2647 DBENCH_SRC=$DBENCH_SRC \
2648 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2654 log "Started client load: ${load} on $client"
2656 # get the children process IDs
2657 local pids=$(ps --ppid $ppid -o pid= | xargs)
2658 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2662 start_client_loads () {
2663 local -a clients=(${1//,/ })
2664 local numloads=${#CLIENT_LOADS[@]}
2667 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2668 testnum=$((nodenum % numloads))
2669 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2671 # bug 22169: wait the background threads to start
2675 # only for remote client
2676 check_client_load () {
2678 local var=$(node_var_name $client)_load
2679 local testload=run_${!var}.sh
2681 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2683 # bug 18914: try to connect several times not only when
2684 # check ps, but while check_node_health also
2688 while [ $RC = 254 -a $tries -gt 0 ]; do
2692 if ! check_node_health $client; then
2694 if [ $RC -eq 254 ]; then
2695 # FIXME: not sure how long we shuold sleep here
2699 echo "check node health failed: RC=$RC "
2703 # We can continue try to connect if RC=254
2704 # Just print the warning about this
2705 if [ $RC = 254 ]; then
2706 echo "got a return status of $RC from do_node while checking " \
2707 "node health on $client"
2710 # see if the load is still on the client
2713 while [ $RC = 254 -a $tries -gt 0 ]; do
2717 if ! do_node $client \
2718 "ps auxwww | grep -v grep | grep -q $testload"; then
2723 if [ $RC = 254 ]; then
2724 echo "got a return status of $RC from do_node while checking " \
2725 "(node health and 'ps') the client load on $client"
2726 # see if we can diagnose a bit why this is
2731 check_client_loads () {
2732 local clients=${1//,/ }
2736 for client in $clients; do
2737 check_client_load $client
2739 if [ "$rc" != 0 ]; then
2740 log "Client load failed on node $client, rc=$rc"
2746 restart_client_loads () {
2747 local clients=${1//,/ }
2748 local expectedfail=${2:-""}
2752 for client in $clients; do
2753 check_client_load $client
2755 if [ "$rc" != 0 -a "$expectedfail" ]; then
2756 local var=$(node_var_name $client)_load
2757 start_client_load $client ${!var}
2758 echo "Restarted client load ${!var}: on $client. Checking ..."
2759 check_client_load $client
2761 if [ "$rc" != 0 ]; then
2762 log "Client load failed to restart on node $client, rc=$rc"
2763 # failure one client load means test fail
2764 # we do not need to check other
2773 # Start vmstat and save its process ID in a file.
2778 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2781 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2782 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2785 # Display the nodes on which client loads failed.
2786 print_end_run_file() {
2790 [ -s $file ] || return 0
2792 echo "Found the END_RUN_FILE file: $file"
2795 # A client load will stop if it finds the END_RUN_FILE file.
2796 # That does not mean the client load actually failed though.
2797 # The first node in END_RUN_FILE is the one we are interested in.
2800 if [ -n "$node" ]; then
2801 local var=$(node_var_name $node)_load
2803 local prefix=$TESTLOG_PREFIX
2804 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2805 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2806 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2808 echo "Client load ${!var} failed on node $node:"
2814 # Stop the process which had its PID saved in a file.
2819 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2821 do_nodes $nodes "test -f $pid_file &&
2822 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2825 # Stop all client loads.
2826 stop_client_loads() {
2827 local nodes=${1:-$CLIENTS}
2830 # stop the client loads
2831 stop_process $nodes $pid_file
2833 # clean up the processes that started them
2834 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2836 # End recovery-scale functions
2838 # verify that lustre actually cleaned up properly
2840 VAR=$(lctl get_param -n catastrophe 2>&1)
2841 if [ $? = 0 ] ; then
2842 if [ $VAR != 0 ]; then
2843 error "LBUG/LASSERT detected"
2846 BUSY=$(dmesg | grep -i destruct || true)
2847 if [ -n "$BUSY" ]; then
2849 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2853 check_mem_leak || exit 204
2855 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2856 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2859 if module_loaded lnet || module_loaded libcfs; then
2860 echo "$TESTSUITE: modules still loaded..." 1>&2
2869 if [[ "$1" == "--verbose" ]]; then
2884 PREV_RESULT=$(do_node $node "$TEST")
2886 RESULT=$(do_node $node "$TEST")
2887 if [[ "$RESULT" == "$FINAL" ]]; then
2888 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2889 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2893 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2894 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2898 [[ $WAIT -ge $MAX ]] && break
2899 [[ $((WAIT % print)) -eq 0 ]] &&
2900 echo "Waiting $((MAX - WAIT)) secs for update"
2901 WAIT=$((WAIT + sleep))
2904 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2908 wait_update_facet() {
2910 [ "$1" = "--verbose" ] && verbose="$1" && shift
2914 wait_update $verbose $(facet_active_host $facet) "$@"
2918 do_nodes $(comma_list $(mdts_nodes)) \
2919 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
2920 do_nodes $(comma_list $(osts_nodes)) \
2921 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2922 grep -v 'Found no match'
2926 local zfs_wait=${2:-5}
2928 # the occupied disk space will be released
2929 # only after TXGs are committed
2930 if [[ $(facet_fstype $1) == zfs ]]; then
2931 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
2936 wait_delete_completed_mds() {
2937 local max_wait=${1:-20}
2939 local stime=$(date +%s)
2944 # find MDS with pending deletions
2945 for node in $(mdts_nodes); do
2946 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2947 2>/dev/null | calc_sum)
2948 if [[ $changes -eq 0 ]]; then
2951 mds2sync="$mds2sync $node"
2953 if [ -z "$mds2sync" ]; then
2954 wait_zfs_commit $SINGLEMDS
2957 mds2sync=$(comma_list $mds2sync)
2959 # sync MDS transactions
2960 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
2962 # wait till all changes are sent and commmitted by OSTs
2963 # for ldiskfs space is released upon execution, but DMU
2964 # do this upon commit
2967 while [[ $WAIT -ne $max_wait ]]; do
2968 changes=$(do_nodes $mds2sync \
2969 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2970 #echo "$node: $changes changes on all"
2971 if [[ $changes -eq 0 ]]; then
2972 wait_zfs_commit $SINGLEMDS
2974 # the occupied disk space will be released
2975 # only after TXGs are committed
2976 wait_zfs_commit ost1
2984 echo "Delete is not completed in $((etime - stime)) seconds"
2985 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2992 # we can use "for" here because we are waiting the slowest
2993 for host in ${hostlist//,/ }; do
2994 check_network "$host" 900
2996 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3003 for facet in ${facetlist//,/ }; do
3004 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3006 wait_for_host $hostlist
3009 _wait_recovery_complete () {
3012 # Use default policy if $2 is not passed by caller.
3013 local MAX=${2:-$(max_recovery_time)}
3018 while [ $WAIT -lt $MAX ]; do
3019 STATUS=$(lctl get_param -n $param | grep status)
3021 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
3024 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3026 echo "$param recovery not done in $MAX sec. $STATUS"
3030 wait_recovery_complete () {
3033 # with an assumption that at_max is the same on all nodes
3034 local MAX=${2:-$(max_recovery_time)}
3037 if [ "$FAILURE_MODE" = HARD ]; then
3038 facets=$(facets_on_host $(facet_active_host $facet))
3040 echo affected facets: $facets
3042 # we can use "for" here because we are waiting the slowest
3043 for facet in ${facets//,/ }; do
3044 local var_svc=${facet}_svc
3045 local param="*.${!var_svc}.recovery_status"
3047 local host=$(facet_active_host $facet)
3048 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3052 wait_mds_ost_sync () {
3053 # just because recovery is done doesn't mean we've finished
3054 # orphan cleanup. Wait for llogs to get synchronized.
3055 echo "Waiting for orphan cleanup..."
3056 # MAX value includes time needed for MDS-OST reconnection
3057 local MAX=$(( TIMEOUT * 2 ))
3058 local WAIT_TIMEOUT=${1:-$MAX}
3061 local list=$(comma_list $(mdts_nodes))
3062 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3063 if ! do_facet $SINGLEMDS \
3064 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3066 # old way, use mds_sync
3068 list=$(comma_list $(osts_nodes))
3069 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3072 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3073 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3074 local -a sync=($(do_nodes $list "$cmd"))
3077 for ((i=0; i<${#sync[@]}; i++)); do
3079 [ ${sync[$i]} -eq 1 ] && continue
3081 [ ${sync[$i]} -eq 0 ] && continue
3083 # there is a not finished MDS-OST synchronization
3087 sleep 2 # increase waiting time and cover statfs cache
3088 [ ${con} -eq 1 ] && return 0
3089 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3093 # show which nodes are not finished.
3094 cmd=$(echo $cmd | sed 's/-n//')
3095 do_nodes $list "$cmd"
3096 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3100 # Wait OSTs to be active on both client and MDT side.
3102 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3103 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3104 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3105 error "wait_update OSTs up on client failed"
3107 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3108 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3109 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3110 error "wait_update OSTs up on MDT0000 failed"
3113 wait_destroy_complete () {
3114 echo "Waiting for local destroys to complete"
3115 # MAX value shouldn't be big as this mean server responsiveness
3116 # never increase this just to make test pass but investigate
3117 # why it takes so long time
3120 while [ $WAIT -lt $MAX ]; do
3121 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
3125 for ((i=0; i<${#RPCs[@]}; i++)); do
3126 [ ${RPCs[$i]} -eq 0 ] && continue
3127 # there are still some destroy RPCs in flight
3132 [ ${con} -eq 1 ] && return 0 # done waiting
3133 echo "Waiting ${WAIT}s for local destroys to complete"
3136 echo "Local destroys weren't done in $MAX sec."
3140 wait_delete_completed() {
3141 wait_delete_completed_mds $1 || return $?
3142 wait_destroy_complete || return $?
3151 # conf-sanity 31 takes a long time cleanup
3152 while [ $WAIT -lt 300 ]; do
3153 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3154 lctl dl | grep ' ST ' || true")
3155 [ -z "${running}" ] && return 0
3156 echo "waited $WAIT for${running}"
3157 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3159 WAIT=$((WAIT + INTERVAL))
3161 echo "service didn't stop after $WAIT seconds. Still running:"
3166 wait_remote_prog () {
3172 [ "$PDSH" = "no_dsh" ] && return 0
3174 while [ $WAIT -lt $2 ]; do
3175 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3176 [ -z "${running}" ] && return 0 || true
3177 echo "waited $WAIT for: "
3179 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3181 WAIT=$((WAIT + INTERVAL))
3183 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3184 [ -z "$pids" ] && return 0
3185 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3186 # FIXME: not portable
3187 for pid in $pids; do
3188 cat /proc/${pid}/status || true
3189 cat /proc/${pid}/wchan || true
3191 kill -9 $pid || true
3200 local clients=${1:-$CLIENTS}
3202 if [ -z "$clients" ]; then
3205 $PDSH $clients "$LFS df $MOUNT" > /dev/null
3210 # not every config has many clients
3216 # usually checked on particular client or locally
3225 client_reconnect_try() {
3226 local f=$MOUNT/recon
3229 if [ -z "$CLIENTS" ]; then
3230 $LFS df $MOUNT; uname -n >> $f
3232 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3234 echo "Connected clients: $(cat $f)"
3235 ls -l $f > /dev/null
3239 client_reconnect() {
3240 # one client_reconnect_try call does not always do the job...
3242 client_reconnect_try && break
3247 affected_facets () {
3250 local host=$(facet_active_host $facet)
3251 local affected=$facet
3253 if [ "$FAILURE_MODE" = HARD ]; then
3254 affected=$(facets_up_on_host $host)
3260 local E2FSCK_ON_MDT0=false
3261 if [ "$1" == "--fsck" ]; then
3263 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3275 #Because it will only get up facets, we need get affected
3276 #facets before shutdown
3277 #For HARD Failure mode, it needs make sure facets on the same
3278 #HOST will only be shutdown and reboot once
3279 for facet in ${facets//,/ }; do
3280 local affected_facet
3282 #check whether facet has been included in other affected facets
3283 for ((index=0; index<$total; index++)); do
3284 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
3287 if [ $skip -eq 0 ]; then
3288 affecteds[$total]=$(affected_facets $facet)