3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
14 export GSS_PIPEFS=false
15 export IDENTITY_UPCALL=default
17 # specify environment variable containing batch job name for server statistics
18 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
20 #export PDSH="pdsh -S -Rssh -w"
21 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
22 export UMOUNT=${UMOUNT:-"umount -d"}
23 # sles12 umount has a issue with -d option
24 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
25 export UMOUNT="umount"
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
53 sanitize_parameters() {
54 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
57 if [ -d "$path" ]; then
58 eval export $i=$(echo $path | sed -r 's/\/+$//g')
64 [[ $DIR/ = $MOUNT/* ]] ||
65 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
66 [[ $DIR1/ = $MOUNT1/* ]] ||
67 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
68 [[ $DIR2/ = $MOUNT2/* ]] ||
69 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
71 [ -n "$failed" ] && exit 99 || true
75 echo "usage: $0 [-r] [-f cfgfile]"
83 [ -z "$DEFAULT_SUITES"] && return 0
84 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
86 local form="%-13s %-17s %-9s %s %s\n"
87 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
88 echo "------------------------------------------------------------------------------------"
89 for O in $DEFAULT_SUITES; do
90 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
91 [ "${!O}" = "no" ] && continue || true
92 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
93 local log=${TMP}/${o}.log
94 if is_sanity_benchmark $o; then
95 log=${TMP}/sanity-benchmark.log
100 local status=Unfinished
102 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
104 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
105 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
106 total=$(grep duration $log | awk '{ print $2 }')
107 if [ "${!O}" = "done" ]; then
111 local durations=$(egrep "^PASS|^FAIL" $log |
112 tr -d "("| sed s/s\)$//g |
113 awk '{ print $2":"$3"|" }')
114 details=$(printf "%s\n%s %s %s\n" "$details" \
115 "DDETAILS" "$O" "$(echo $durations)")
118 printf "$form" $status "$O" "${total}" "E=$skipped"
119 printf "$form" "-" "-" "-" "S=$(echo $slow)"
122 for O in $DEFAULT_SUITES; do
123 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
124 if [ "${!O}" = "no" ]; then
125 printf "$form" "Skipped" "$O" ""
129 # print the detailed tests durations if DDETAILS=true
136 export LUSTRE=$(absolute_path $LUSTRE)
137 export TESTSUITE=$(basename $0 .sh)
138 export TEST_FAILED=false
139 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
140 export RPC_MODE=${RPC_MODE:-false}
141 export DO_CLEANUP=${DO_CLEANUP:-true}
143 export MKE2FS=$MKE2FS
144 if [ -z "$MKE2FS" ]; then
145 if which mkfs.ldiskfs >/dev/null 2>&1; then
146 export MKE2FS=mkfs.ldiskfs
152 export DEBUGFS=$DEBUGFS
153 if [ -z "$DEBUGFS" ]; then
154 if which debugfs.ldiskfs >/dev/null 2>&1; then
155 export DEBUGFS=debugfs.ldiskfs
157 export DEBUGFS=debugfs
161 export TUNE2FS=$TUNE2FS
162 if [ -z "$TUNE2FS" ]; then
163 if which tunefs.ldiskfs >/dev/null 2>&1; then
164 export TUNE2FS=tunefs.ldiskfs
166 export TUNE2FS=tune2fs
170 export E2LABEL=$E2LABEL
171 if [ -z "$E2LABEL" ]; then
172 if which label.ldiskfs >/dev/null 2>&1; then
173 export E2LABEL=label.ldiskfs
175 export E2LABEL=e2label
179 export DUMPE2FS=$DUMPE2FS
180 if [ -z "$DUMPE2FS" ]; then
181 if which dumpfs.ldiskfs >/dev/null 2>&1; then
182 export DUMPE2FS=dumpfs.ldiskfs
184 export DUMPE2FS=dumpe2fs
188 export E2FSCK=$E2FSCK
189 if [ -z "$E2FSCK" ]; then
190 if which fsck.ldiskfs >/dev/null 2>&1; then
191 export E2FSCK=fsck.ldiskfs
197 export RESIZE2FS=$RESIZE2FS
198 if [ -z "$RESIZE2FS" ]; then
199 if which resizefs.ldiskfs >/dev/null 2>&1; then
200 export RESIZE2FS=resizefs.ldiskfs
202 export RESIZE2FS=resize2fs
206 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
207 export FSCK_MAX_ERR=4 # File system errors left uncorrected
209 export ZFS=${ZFS:-zfs}
210 export ZPOOL=${ZPOOL:-zpool}
211 export ZDB=${ZDB:-zdb}
212 export PARTPROBE=${PARTPROBE:-partprobe}
214 #[ -d /r ] && export ROOT=${ROOT:-/r}
215 export TMP=${TMP:-$ROOT/tmp}
216 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
217 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
218 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
220 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
221 if ! echo $PATH | grep -q $LUSTRE/utils; then
222 export PATH=$LUSTRE/utils:$PATH
224 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
225 export PATH=$LUSTRE/utils/gss:$PATH
227 if ! echo $PATH | grep -q $LUSTRE/tests; then
228 export PATH=$LUSTRE/tests:$PATH
230 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
231 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
233 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
234 [ ! -f "$LST" ] && export LST=$(which lst)
235 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
236 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
237 export MCREATE=${MCREATE:-mcreate}
238 # Ubuntu, at least, has a truncate command in /usr/bin
239 # so fully path our truncate command.
240 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
241 export FSX=${FSX:-$LUSTRE/tests/fsx}
242 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
243 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
244 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
245 export PATH=$LUSTRE/tests/racer:$PATH:
247 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
248 export PATH=$LUSTRE/tests/mpi:$PATH
250 export RSYNC_RSH=${RSYNC_RSH:-rsh}
252 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
253 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
254 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
255 [ ! -f "$LFS" ] && export LFS=$(which lfs)
256 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
257 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
259 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
260 if [ ! -f "$L_GETIDENTITY" ]; then
261 if `which l_getidentity > /dev/null 2>&1`; then
262 export L_GETIDENTITY=$(which l_getidentity)
264 export L_GETIDENTITY=NONE
267 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
268 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
269 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
270 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
271 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
272 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
273 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
274 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
275 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
276 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
277 [ ! -f "$LUSTRE_RMMOD" ] &&
278 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
279 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
280 [ ! -f "$LFS_MIGRATE" ] &&
281 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
282 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
283 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
284 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
285 export NAME=${NAME:-local}
286 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
287 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
288 export LGSSD=$(which lgssd)
289 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
290 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
291 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
293 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
295 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
296 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
298 if [ "$ACCEPTOR_PORT" ]; then
299 export PORT_OPT="--port $ACCEPTOR_PORT"
304 echo "Using GSS/krb5 ptlrpc security flavor"
305 which lgss_keyring > /dev/null 2>&1 || \
306 error_exit "built with gss disabled! SEC=$SEC"
317 IDENTITY_UPCALL=false
321 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
323 # Paths on remote nodes, if different
324 export RLUSTRE=${RLUSTRE:-$LUSTRE}
325 export RPWD=${RPWD:-$PWD}
326 export I_MOUNTED=${I_MOUNTED:-"no"}
327 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
328 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
329 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
330 ! -f $LUSTRE/mdt/mdt.ko ]; then
331 export CLIENTMODSONLY=yes
334 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
335 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
339 while getopts "rvwf:" opt $*; do
344 w) WRITECONF=writeconf;;
349 shift $((OPTIND - 1))
352 # print the durations of each test if "true"
353 DDETAILS=${DDETAILS:-false}
354 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
359 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
366 ncpts=$(do_facet $facet "lctl get_param -n " \
367 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
369 if [ $ncpts -eq 0 ]; then
376 # Return a numeric version code based on a version string. The version
377 # code is useful for comparison two version strings to see which is newer.
379 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
380 eval set -- $(tr "[:punct:]" " " <<< $*)
382 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
385 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
386 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
388 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
390 # usage: lustre_build_version
392 # All Lustre versions support "lctl get_param" to report the version of the
393 # code running in the kernel (what our tests are interested in), but it
394 # doesn't work without modules loaded. If that fails, use "lctl version"
395 # instead, which is easy to parse and works without the kernel modules,
396 # but was only added in 2.6.50. If that also fails, fall back to calling
397 # "lctl lustre_build_version" which prints either (or both) the userspace
398 # and kernel build versions, but is deprecated and should eventually be
401 # output: prints version string to stdout in dotted-decimal format
402 lustre_build_version() {
403 local facet=${1:-client}
406 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
407 awk '/lustre: / { print $2 }')
409 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
411 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
412 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
413 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
414 awk '/version:/ { print $3; exit; }')
415 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
418 # Report the Lustre numeric build version code for the supplied facet.
419 lustre_version_code() {
420 version_code $(lustre_build_version $1)
424 /sbin/lsmod | grep -q "^\<$1\>"
427 # Load a module on the system where this is running.
429 # usage: load_module module_name [module arguments for insmod/modprobe]
431 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
432 # will be used as the arguments. Otherwise arguments will be obtained from
433 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
440 BASE=$(basename $module $EXT)
442 module_loaded ${BASE} && return
444 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
445 # else from modprobe.conf
446 if [ $# -eq 0 ]; then
447 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
448 # Bash until 4.x, so we resort to eval.
449 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
450 eval set -- \$$optvar
451 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
452 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
454 opt=$(awk -v var="^options $BASE" '$0 ~ var \
455 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
456 set -- $(echo -n $opt)
458 # Ensure we have accept=all for lnet
459 if [ $(basename $module) = lnet ]; then
460 # OK, this is a bit wordy...
461 local arg accept_all_present=false
464 [ "$arg" = accept=all ] && \
465 accept_all_present=true
467 $accept_all_present || set -- "$@" accept=all
473 [ $# -gt 0 ] && echo "${module} options: '$*'"
475 # Note that insmod will ignore anything in modprobe.conf, which is why
476 # we're passing options on the command-line.
477 if [[ "$BASE" == "lnet_selftest" ]] &&
478 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
479 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
480 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
481 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
482 insmod ${LUSTRE}/${module}${EXT} "$@"
484 # must be testing a "make install" or "rpm" installation
485 # note failed to load ptlrpc_gss is considered not fatal
486 if [[ "$BASE" == "ptlrpc_gss" ]]; then
487 modprobe $BASE "$@" 2>/dev/null ||
488 echo "gss/krb5 is not supported"
495 load_modules_local() {
496 if [ -n "$MODPROBE" ]; then
498 echo "Using modprobe to load modules"
502 echo Loading modules from $LUSTRE
506 if [ -f /sys/devices/system/cpu/online ]; then
507 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
508 echo "detected $ncpus online CPUs by sysfs"
510 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
512 if [ $rc -eq 0 ]; then
513 echo "detected $ncpus online CPUs by getconf"
515 echo "Can't detect number of CPUs"
520 # if there is only one CPU core, libcfs can only create one partition
521 # if there is more than 4 CPU cores, libcfs should create multiple CPU
522 # partitions. So we just force libcfs to create 2 partitions for
523 # system with 2 or 4 cores
524 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
525 # force to enable multiple CPU partitions
526 echo "Force libcfs to create 2 CPU partitions"
527 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
529 echo "libcfs will create CPU partition based on online CPUs"
532 load_module ../libcfs/libcfs/libcfs
533 # Prevent local MODOPTS_LIBCFS being passed as part of environment
534 # variable to remote nodes
537 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
538 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
539 load_module ../lnet/lnet/lnet
542 LNETLND="o2iblnd/ko2iblnd"
547 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
548 load_module ../lnet/klnds/$LNETLND
549 load_module obdclass/obdclass
550 load_module ptlrpc/ptlrpc
551 load_module ptlrpc/gss/ptlrpc_gss
559 load_module obdecho/obdecho
560 if ! client_only; then
561 SYMLIST=/proc/kallsyms
562 grep -q crc16 $SYMLIST ||
563 { modprobe crc16 2>/dev/null || true; }
564 grep -q -w jbd2 $SYMLIST ||
565 { modprobe jbd2 2>/dev/null || true; }
566 load_module lfsck/lfsck
567 [ "$LQUOTA" != "no" ] &&
568 load_module quota/lquota $LQUOTAOPTS
569 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
571 load_module osd-zfs/osd_zfs
573 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
574 grep -q exportfs_decode_fh $SYMLIST ||
575 { modprobe exportfs 2> /dev/null || true; }
576 grep -q -w mbcache $SYMLIST ||
577 { modprobe mbcache 2>/dev/null || true; }
578 load_module ../ldiskfs/ldiskfs
579 load_module osd-ldiskfs/osd_ldiskfs
591 load_module llite/lustre
592 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
594 rm -f $OGDB/ogdb-$HOSTNAME
595 $LCTL modules > $OGDB/ogdb-$HOSTNAME
597 # 'mount' doesn't look in $PATH, just sbin
598 local mount_lustre=$LUSTRE/utils/mount.lustre
599 if [ -f $mount_lustre ]; then
600 local sbin_mount=$(readlink -f /sbin)/mount.lustre
601 if grep -qw "$sbin_mount" /proc/mounts; then
602 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
604 if ! grep -qw "$sbin_mount" /proc/mounts; then
605 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
606 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
607 cat <<- EOF > "$sbin_mount"
610 echo "This $sbin_mount just a mountpoint." 1>&2
611 echo "It is never supposed to be run." 1>&2
612 logger -p emerg -- "using stub $sbin_mount $@"
615 chmod a+x $sbin_mount
617 mount --bind $mount_lustre $sbin_mount ||
618 error "can't bind $mount_lustre to $sbin_mount"
626 # load modules on remote nodes optionally
627 # lustre-tests have to be installed on these nodes
628 if $LOAD_MODULES_REMOTE; then
629 local list=$(comma_list $(remote_nodes_list))
630 if [ -n "$list" ]; then
631 echo "loading modules on: '$list'"
632 do_rpc_nodes "$list" load_modules_local
638 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
639 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
640 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
641 echo "$LEAK_LUSTRE" 1>&2
642 echo "$LEAK_PORTALS" 1>&2
643 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
644 echo "Memory leaks detected"
645 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
651 wait_exit_ST client # bug 12845
653 $LUSTRE_RMMOD ldiskfs || return 2
655 if $LOAD_MODULES_REMOTE; then
656 local list=$(comma_list $(remote_nodes_list))
657 if [ -n "$list" ]; then
658 echo "unloading modules on: '$list'"
659 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
660 do_rpc_nodes "$list" check_mem_leak
664 local sbin_mount=$(readlink -f /sbin)/mount.lustre
665 if grep -qe "$sbin_mount " /proc/mounts; then
666 umount $sbin_mount || true
667 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
671 check_mem_leak || return 254
673 echo "modules unloaded."
678 local facet=${1:-$SINGLEMDS}
679 local fstype=$(facet_fstype $facet)
682 ldiskfs) size=50;; # largest seen is 44, leave some headroom
683 zfs) size=400;; # largest seen is 384
690 local facet=${1:-$SINGLEMDS}
691 local fstype=$(facet_fstype $facet)
694 ldiskfs) size=4;; # ~4KB per inode
695 zfs) size=11;; # 10 to 11KB per inode
701 check_gss_daemon_nodes() {
705 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
706 if [ \\\"\\\$num\\\" -ne 1 ]; then
707 echo \\\$num instance of $dname;
712 check_gss_daemon_facet() {
716 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
717 if [ $num -ne 1 ]; then
718 echo "$num instance of $dname on $facet"
727 echo Stopping $@ on $list
728 do_nodes $list "killall -2 $@ 2>/dev/null || true"
731 # start gss daemons on all nodes, or
732 # "daemon" on "list" if set
733 start_gss_daemons() {
737 if [ "$list" ] && [ "$daemon" ] ; then
738 echo "Starting gss daemon on nodes: $list"
739 do_nodes $list "$daemon" || return 8
743 local list=$(comma_list $(mdts_nodes))
744 echo "Starting gss daemon on mds: $list"
745 do_nodes $list "$LSVCGSSD -v" || return 1
747 do_nodes $list "$LGSSD -v" || return 2
750 list=$(comma_list $(osts_nodes))
751 echo "Starting gss daemon on ost: $list"
752 do_nodes $list "$LSVCGSSD -v" || return 3
753 # starting on clients
755 local clients=${CLIENTS:-`hostname`}
757 echo "Starting $LGSSD on clients $clients "
758 do_nodes $clients "$LGSSD -v" || return 4
761 # wait daemons entering "stable" status
765 # check daemons are running
767 list=$(comma_list $(mdts_nodes) $(osts_nodes))
768 check_gss_daemon_nodes $list lsvcgssd || return 5
770 list=$(comma_list $(mdts_nodes))
771 check_gss_daemon_nodes $list lgssd || return 6
774 check_gss_daemon_nodes $clients lgssd || return 7
779 local list=$(comma_list $(mdts_nodes))
781 send_sigint $list lsvcgssd lgssd
783 list=$(comma_list $(osts_nodes))
784 send_sigint $list lsvcgssd
786 list=${CLIENTS:-`hostname`}
787 send_sigint $list lgssd
792 if ! module_loaded ptlrpc_gss; then
793 load_module ptlrpc/gss/ptlrpc_gss
794 module_loaded ptlrpc_gss ||
795 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
798 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
801 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
803 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
811 # maybe cleanup credential cache?
817 local var=${facet}_svc
825 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
826 tr '[:lower:]' '[:upper:]'
832 if [ $facet == mgs ] || [ $facet == client ]; then
836 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
844 if [ -n "${!var}" ]; then
849 var=$(facet_type $facet)FSTYPE
850 if [ -n "${!var}" ]; then
855 if [ -n "$FSTYPE" ]; then
860 if [[ $facet == mgs ]] && combined_mgs_mds; then
872 local facets=$(get_facets)
875 for facet in ${facets//,/ }; do
876 if [ $node == $(facet_host $facet) ] ||
877 [ $node == "$(facet_failover_host $facet)" ]; then
878 fstype=$(facet_fstype $facet)
879 if [[ $fstypes != *$fstype* ]]; then
880 fstypes+="${fstypes:+,}$fstype"
889 local num=$(facet_number $facet)
892 if [[ $(facet_type $facet) = OST ]]; then
894 if [[ -n "${!index}" ]]; then
899 index=${OST_INDICES[num - 1]}
902 [[ -n "$index" ]] || index=$((num - 1))
910 local fstype=$(facet_fstype $facet)
914 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
916 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
917 ${dev} 2>/dev/null");;
919 error "unknown fstype!";;
927 local device=$(mdsdevname $num)
928 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
934 local device=$(ostdevname $num)
935 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
940 # Get the device of a facet.
947 mgs) device=$(mgsdevname) ;;
948 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
949 ost*) device=$(ostdevname $(facet_number $facet)) ;;
950 fs2mds) device=$(mdsdevname 1_2) ;;
951 fs2ost) device=$(ostdevname 1_2) ;;
952 fs3ost) device=$(ostdevname 2_2) ;;
960 # Get the virtual device of a facet.
967 mgs) device=$(mgsvdevname) ;;
968 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
969 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
970 fs2mds) device=$(mdsvdevname 1_2) ;;
971 fs2ost) device=$(ostvdevname 1_2) ;;
972 fs3ost) device=$(ostvdevname 2_2) ;;
980 local virt=$(virt-what 2> /dev/null)
982 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
984 virt=$(dmidecode -s system-product-name | awk '{print $1}')
987 VMware|KVM|VirtualBox|Parallels)
988 echo $virt | tr '[A-Z]' '[a-z]' ;;
994 # Re-read the partition table on failover partner host.
995 # After a ZFS storage pool is created on a shared device, the partition table
996 # on the device may change. However, the operating system on the failover
997 # host may not notice the change automatically. Without the up-to-date partition
998 # block devices, 'zpool import ..' cannot find the labels, whose positions are
999 # relative to partition rather than disk beginnings.
1001 # This function performs partprobe on the failover host to make it re-read the
1004 refresh_partition_table() {
1009 host=$(facet_passive_host $facet)
1010 if [[ -n "$host" ]]; then
1011 do_node $host "$PARTPROBE $device"
1016 # Get ZFS storage pool name.
1023 device=$(facet_device $facet)
1024 # poolname is string before "/"
1025 poolname="${device%%/*}"
1031 # Create ZFS storage pool.
1038 local opts=${@:-"-o cachefile=none"}
1040 do_facet $facet "modprobe zfs;
1041 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1042 $ZPOOL create -f $opts $poolname $vdev"
1046 # Create ZFS file system.
1052 local opts=${@:-"-o mountpoint=legacy"}
1054 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1055 $ZFS create $opts $dataset"
1059 # Export ZFS storage pool.
1060 # Before exporting the pool, all datasets within the pool should be unmounted.
1068 poolname=$(zpool_name $facet)
1070 if [[ -n "$poolname" ]]; then
1071 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1072 grep -q ^$poolname/ /proc/mounts ||
1073 $ZPOOL export $opts $poolname"
1078 # Destroy ZFS storage pool.
1079 # Destroy the given pool and free up any devices for other use. This command
1080 # tries to unmount any active datasets before destroying the pool.
1081 # -f Force any active datasets contained within the pool to be unmounted.
1085 local poolname=${2:-$(zpool_name $facet)}
1087 if [[ -n "$poolname" ]]; then
1088 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1089 $ZPOOL destroy -f $poolname"
1094 # Import ZFS storage pool.
1095 # Force importing, even if the pool appears to be potentially active.
1100 local opts=${@:-"-o cachefile=none"}
1103 poolname=$(zpool_name $facet)
1105 if [[ -n "$poolname" ]]; then
1106 opts+=" -d $(dirname $(facet_vdevice $facet))"
1107 do_facet $facet "modprobe zfs;
1108 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1109 $ZPOOL import -f $opts $poolname"
1114 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1115 # is not automatically imported on system startup.
1117 # In a failover environment, this will provide resource level fencing which
1118 # will ensure that the same ZFS storage pool will not be imported concurrently
1119 # on different nodes.
1121 disable_zpool_cache() {
1125 poolname=$(zpool_name $facet)
1127 if [[ -n "$poolname" ]]; then
1128 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1133 # This and set_osd_param() shall be used to access OSD parameters
1134 # once existed under "obdfilter":
1139 # writethrough_cache_enable
1143 local device=${2:-$FSNAME-OST*}
1146 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1147 osd-*.$device.$name 2>&1" | grep -v 'error:'
1152 local device=${2:-$FSNAME-OST*}
1156 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1157 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1161 local dz=${1:-$DEBUG_SIZE}
1163 if [ -f /sys/devices/system/cpu/possible ]; then
1164 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1166 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1169 # bug 19944, adjust size to be -gt num_possible_cpus()
1170 # promise 2MB for every cpu at least
1171 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1174 lctl set_param debug_mb=$dz
1177 set_default_debug () {
1178 local debug=${1:-"$PTLDEBUG"}
1179 local subsys=${2:-"$SUBSYSTEM"}
1180 local debug_size=${3:-$DEBUG_SIZE}
1182 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1183 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1185 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1188 set_default_debug_nodes () {
1191 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1192 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1196 do_rpc_nodes "$nodes" set_default_debug \
1197 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1200 set_default_debug_facet () {
1202 local node=$(facet_active_host $facet)
1203 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1205 set_default_debug_nodes $node
1209 local hostid=${1:-$(hostid)}
1211 if [ ! -s /etc/hostid ]; then
1212 printf $(echo -n $hostid |
1213 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1219 local facets=${1:-$(get_facets)}
1222 for facet in ${facets//,/ }; do
1225 [ $RC -eq 0 ] && continue
1227 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1228 skip "Restart of $facet failed!." && touch $LU482_FAILED
1230 error "Restart of $facet failed!"
1237 # Add argument "arg" (e.g., "loop") to the comma-separated list
1238 # of arguments for option "opt" (e.g., "-o") on command
1239 # line "opts" (e.g., "-o flock").
1245 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1247 if echo "$opts" | grep -q $opt_pattern; then
1248 opts=$(echo "$opts" | sed -e \
1249 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1251 opts+="${opts:+ }$opt $arg"
1259 local dev=$(facet_active $facet)_dev
1260 local opt=${facet}_opt
1261 local mntpt=$(facet_mntpt $facet)
1262 local opts="${!opt} $@"
1263 local fstype=$(facet_fstype $facet)
1266 module_loaded lustre || load_modules
1268 if [ $(facet_fstype $facet) == ldiskfs ] &&
1269 ! do_facet $facet test -b ${!dev}; then
1270 opts=$(csa_add "$opts" -o loop)
1273 if [[ $(facet_fstype $facet) == zfs ]]; then
1274 # import ZFS storage pool
1275 import_zpool $facet || return ${PIPESTATUS[0]}
1280 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1282 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1283 lustre:svname ${!dev}");;
1285 error "unknown fstype!";;
1288 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1289 # for testing LU-482 error handling in mount_facets() and test_0a()
1290 if [ -f $TMP/test-lu482-trigger ]; then
1293 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1298 if [ $RC -ne 0 ]; then
1299 echo "Start of ${!dev} on ${facet} failed ${RC}"
1303 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1304 if [[ "$health" != "healthy" ]]; then
1305 error "$facet is in a unhealthy state"
1308 set_default_debug_facet $facet
1310 if [[ $facet == mds* ]]; then
1312 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1315 if [[ $opts =~ .*nosvc.* ]]; then
1316 echo "Start ${!dev} without service"
1321 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1322 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1323 "" || error "${!dev} failed to initialize!";;
1325 wait_update_facet ${facet} "$ZFS get -H -o value \
1326 lustre:svname ${!dev} 2>/dev/null | \
1327 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1328 error "${!dev} failed to initialize!";;
1331 error "unknown fstype!";;
1335 # commit the device label change to disk
1336 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1337 echo "Commit the device label on ${!dev}"
1338 do_facet $facet "sync; sync; sync"
1343 label=$(devicelabel ${facet} ${!dev})
1344 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1345 eval export ${facet}_svc=${label}
1346 echo Started ${label}
1351 # start facet device options
1357 eval export ${facet}_dev=${device}
1358 eval export ${facet}_opt=\"$@\"
1360 local varname=${facet}failover_dev
1361 if [ -n "${!varname}" ] ; then
1362 eval export ${facet}failover_dev=${!varname}
1364 eval export ${facet}failover_dev=$device
1367 local mntpt=$(facet_mntpt $facet)
1368 do_facet ${facet} mkdir -p $mntpt
1369 eval export ${facet}_MOUNT=$mntpt
1370 mount_facet ${facet}
1373 if [[ $facet == mds* ]]; then
1375 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1386 local HOST=`facet_active_host $facet`
1387 [ -z $HOST ] && echo stop: no host for $facet && return 0
1389 local mntpt=$(facet_mntpt $facet)
1390 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1391 if [ ${running} -ne 0 ]; then
1392 echo "Stopping $mntpt (opts:$@) on $HOST"
1393 do_facet ${facet} $UMOUNT $@ $mntpt
1396 # umount should block, but we should wait for unrelated obd's
1397 # like the MGS or MGC to also stop.
1398 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1400 if [[ $(facet_fstype $facet) == zfs ]]; then
1401 # export ZFS storage pool
1406 # save quota version (both administrative and operational quotas)
1407 # add an additional parameter if mountpoint is ever different from $MOUNT
1409 # XXX This function is kept for interoperability with old server (< 2.3.50),
1410 # it should be removed whenever we drop the interoperability for such
1412 quota_save_version() {
1413 local fsname=${2:-$FSNAME}
1415 local ver=$(tr -c -d "123" <<< $spec)
1416 local type=$(tr -c -d "ug" <<< $spec)
1418 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1420 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1422 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1424 local osts=$(get_facets OST)
1425 for ost in ${osts//,/ }; do
1427 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1431 # client could mount several lustre
1433 # XXX This function is kept for interoperability with old server (< 2.3.50),
1434 # it should be removed whenever we drop the interoperability for such
1437 local fsname=${1:-$FSNAME}
1439 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1441 do_nodes $(comma_list $(osts_nodes)) \
1442 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1446 # get mdt quota type
1448 local varsvc=${SINGLEMDS}_svc
1449 do_facet $SINGLEMDS $LCTL get_param -n \
1450 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1453 # get ost quota type
1455 # All OSTs should have same quota type
1456 local varsvc=ost1_svc
1457 do_facet ost1 $LCTL get_param -n \
1458 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1461 # restore old quota type settings
1463 if [ "$old_MDT_QUOTA_TYPE" ]; then
1464 do_facet mgs $LCTL conf_param \
1465 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1467 if [ "$old_OST_QUOTA_TYPE" ]; then
1468 do_facet mgs $LCTL conf_param \
1469 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1473 # Handle the case when there is a space in the lfs df
1474 # "filesystem summary" line the same as when there is no space.
1475 # This will allow fixing the "lfs df" summary line in the future.
1477 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1480 # Get free inodes on the MDT specified by mdt index, free indoes on
1481 # the whole filesystem will be returned when index == -1.
1487 if [ $index -eq -1 ]; then
1490 mdt_uuid=$(mdtuuid_from_index $index)
1493 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1500 # save old quota type & set new quota type
1501 local mdt_qtype=$(mdt_quota_type)
1502 local ost_qtype=$(ost_quota_type)
1504 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1505 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1507 export old_MDT_QUOTA_TYPE=$mdt_qtype
1508 export old_OST_QUOTA_TYPE=$ost_qtype
1510 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1511 error "set mdt quota type failed"
1512 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1513 error "set ost quota type failed"
1515 local quota_usrs=$QUOTA_USERS
1517 # get_filesystem_size
1518 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1519 local blk_soft=$((disksz + 1024))
1520 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1522 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1523 local i_soft=$inodes
1524 local i_hard=$((i_soft + i_soft / 20))
1526 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1527 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1528 "inode-hardlimit: $i_hard"
1531 for usr in $quota_usrs; do
1532 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1534 cmd="$LFS setquota -$type $usr -b $blk_soft"
1535 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1537 eval $cmd || error "$cmd FAILED!"
1539 # display the quota status
1540 echo "Quota settings for $usr : "
1541 $LFS quota -v -u $usr $mntpt || true
1548 local opts=${3:-$MOUNT_OPTS}
1549 opts=${opts:+-o $opts}
1550 local flags=${4:-$MOUNT_FLAGS}
1552 local device=$MGSNID:/$FSNAME$FILESET
1553 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1554 echo "Bad mount command: opt=$flags $opts dev=$device " \
1559 echo "Starting client: $client: $flags $opts $device $mnt"
1560 do_node $client mkdir -p $mnt
1561 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1562 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1564 #disable FILESET if not supported
1565 do_nodes $client lctl get_param -n \
1566 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1567 device=$MGSNID:/$FSNAME
1568 do_node $client mkdir -p $mnt/$FILESET
1569 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1572 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1574 set_default_debug_nodes $client
1586 [ "$3" ] && force=-f
1587 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1588 if [ $running -ne 0 ]; then
1589 echo "Stopping client $client $mnt (opts:$force)"
1590 do_node $client lsof -t $mnt || need_kill=no
1591 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1592 pids=$(do_node $client lsof -t $mnt | sort -u);
1593 if [ -n $pids ]; then
1594 do_node $client kill -9 $pids || true
1598 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1599 if [ $busy -ne 0 ] ; then
1600 echo "$mnt is still busy, wait one second" && sleep 1
1601 do_node $client umount $force $mnt
1606 # nodes is comma list
1607 sanity_mount_check_nodes () {
1613 # FIXME: assume that all cluster nodes run the same os
1614 [ "$(uname)" = Linux ] || return 0
1617 for mnt in $mnts ; do
1618 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1619 mpts=\\\$(mount | grep -c $mnt' ');
1620 if [ \\\$running -ne \\\$mpts ]; then
1621 echo \\\$(hostname) env are INSANE!;
1624 [ $? -eq 0 ] || rc=1
1629 sanity_mount_check_servers () {
1630 [ -n "$CLIENTONLY" ] &&
1631 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1632 echo Checking servers environments
1634 # FIXME: modify get_facets to display all facets wo params
1635 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1639 for facet in ${facets//,/ }; do
1640 node=$(facet_host ${facet})
1641 mntpt=$(facet_mntpt $facet)
1642 sanity_mount_check_nodes $node $mntpt ||
1643 { error "server $node environments are insane!"; return 1; }
1647 sanity_mount_check_clients () {
1648 local clients=${1:-$CLIENTS}
1649 local mntpt=${2:-$MOUNT}
1650 local mntpt2=${3:-$MOUNT2}
1652 [ -z $clients ] && clients=$(hostname)
1653 echo Checking clients $clients environments
1655 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1656 error "clients environments are insane!"
1659 sanity_mount_check () {
1660 sanity_mount_check_servers || return 1
1661 sanity_mount_check_clients || return 2
1664 # mount clients if not mouted
1665 zconf_mount_clients() {
1668 local opts=${3:-$MOUNT_OPTS}
1669 opts=${opts:+-o $opts}
1670 local flags=${4:-$MOUNT_FLAGS}
1672 local device=$MGSNID:/$FSNAME$FILESET
1673 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1674 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1679 echo "Starting client $clients: $flags $opts $device $mnt"
1680 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1681 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1683 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1685 #disable FILESET if not supported
1686 do_nodes $clients lctl get_param -n \
1687 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1688 device=$MGSNID:/$FSNAME
1689 do_nodes $clients mkdir -p $mnt/$FILESET
1690 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1695 running=\\\$(mount | grep -c $mnt' ');
1697 if [ \\\$running -eq 0 ] ; then
1699 $MOUNT_CMD $flags $opts $device $mnt;
1702 exit \\\$rc" || return ${PIPESTATUS[0]}
1704 echo "Started clients $clients: "
1705 do_nodes $clients "mount | grep $mnt' '"
1707 set_default_debug_nodes $clients
1712 zconf_umount_clients() {
1717 [ "$3" ] && force=-f
1719 echo "Stopping clients: $clients $mnt (opts:$force)"
1720 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1721 if [ \\\$running -ne 0 ] ; then
1722 echo Stopping client \\\$(hostname) $mnt opts:$force;
1723 lsof $mnt || need_kill=no;
1724 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1725 pids=\\\$(lsof -t $mnt | sort -u);
1726 if [ -n \\\"\\\$pids\\\" ]; then
1730 while umount $force $mnt 2>&1 | grep -q "busy"; do
1731 echo "$mnt is still busy, wait one second" && sleep 1;
1738 echo + $POWER_DOWN $node
1742 shutdown_node_hard () {
1744 local attempts=$SHUTDOWN_ATTEMPTS
1746 for i in $(seq $attempts) ; do
1749 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1750 echo "waiting for $host to fail attempts=$attempts"
1751 [ $i -lt $attempts ] || \
1752 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1758 local mnt=${2:-$MOUNT}
1761 if [ "$FAILURE_MODE" = HARD ]; then
1762 shutdown_node_hard $client
1764 zconf_umount_clients $client $mnt -f
1770 local facets="$(get_facets OST),$(get_facets MDS)"
1773 combined_mgs_mds || facets="$facets,mgs"
1775 for facet in ${facets//,/ }; do
1776 if [ $(facet_active_host $facet) == $host ]; then
1777 affected="$affected $facet"
1781 echo $(comma_list $affected)
1786 local host=${2:-$(facet_host $facet)}
1788 local label=$(convert_facet2label $facet)
1789 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1792 facets_up_on_host () {
1794 local facets=$(facets_on_host $host)
1797 for facet in ${facets//,/ }; do
1798 if $(facet_up $facet $host); then
1799 affected_up="$affected_up $facet"
1803 echo $(comma_list $affected_up)
1809 if [ "$FAILURE_MODE" = HARD ]; then
1810 shutdown_node_hard $(facet_active_host $facet)
1818 echo + $POWER_UP $node
1831 if [ "$FAILURE_MODE" = HARD ]; then
1832 reboot_node $(facet_active_host $facet)
1840 if [ "$FAILURE_MODE" = HARD ]; then
1850 for facet in ${facets//,/ }; do
1851 hosts=$(expand_list $hosts $(facet_host $facet) )
1857 _check_progs_installed () {
1861 for prog in $progs; do
1862 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1863 echo $prog missing on $(hostname)
1870 check_progs_installed () {
1874 do_rpc_nodes "$nodes" _check_progs_installed $@
1877 # recovery-scale functions
1879 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1882 start_client_load() {
1885 local var=$(node_var_name $client)_load
1886 eval export ${var}=$load
1888 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1889 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1890 END_RUN_FILE=$END_RUN_FILE \
1891 LOAD_PID_FILE=$LOAD_PID_FILE \
1892 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1893 TESTNAME=$TESTNAME \
1894 DBENCH_LIB=$DBENCH_LIB \
1895 DBENCH_SRC=$DBENCH_SRC \
1896 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1900 log "Started client load: ${load} on $client"
1902 # get the children process IDs
1903 local pids=$(ps --ppid $ppid -o pid= | xargs)
1904 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1908 start_client_loads () {
1909 local -a clients=(${1//,/ })
1910 local numloads=${#CLIENT_LOADS[@]}
1913 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1914 testnum=$((nodenum % numloads))
1915 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1917 # bug 22169: wait the background threads to start
1921 # only for remote client
1922 check_client_load () {
1924 local var=$(node_var_name $client)_load
1925 local testload=run_${!var}.sh
1927 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
1929 # bug 18914: try to connect several times not only when
1930 # check ps, but while check_node_health also
1934 while [ $RC = 254 -a $tries -gt 0 ]; do
1938 if ! check_node_health $client; then
1940 if [ $RC -eq 254 ]; then
1941 # FIXME: not sure how long we shuold sleep here
1945 echo "check node health failed: RC=$RC "
1949 # We can continue try to connect if RC=254
1950 # Just print the warning about this
1951 if [ $RC = 254 ]; then
1952 echo "got a return status of $RC from do_node while checking " \
1953 "node health on $client"
1956 # see if the load is still on the client
1959 while [ $RC = 254 -a $tries -gt 0 ]; do
1963 if ! do_node $client \
1964 "ps auxwww | grep -v grep | grep -q $testload"; then
1969 if [ $RC = 254 ]; then
1970 echo "got a return status of $RC from do_node while checking " \
1971 "(node health and 'ps') the client load on $client"
1972 # see if we can diagnose a bit why this is
1977 check_client_loads () {
1978 local clients=${1//,/ }
1982 for client in $clients; do
1983 check_client_load $client
1985 if [ "$rc" != 0 ]; then
1986 log "Client load failed on node $client, rc=$rc"
1992 restart_client_loads () {
1993 local clients=${1//,/ }
1994 local expectedfail=${2:-""}
1998 for client in $clients; do
1999 check_client_load $client
2001 if [ "$rc" != 0 -a "$expectedfail" ]; then
2002 local var=$(node_var_name $client)_load
2003 start_client_load $client ${!var}
2004 echo "Restarted client load ${!var}: on $client. Checking ..."
2005 check_client_load $client
2007 if [ "$rc" != 0 ]; then
2008 log "Client load failed to restart on node $client, rc=$rc"
2009 # failure one client load means test fail
2010 # we do not need to check other
2019 # Start vmstat and save its process ID in a file.
2024 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2027 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2028 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2031 # Display the nodes on which client loads failed.
2032 print_end_run_file() {
2036 [ -s $file ] || return 0
2038 echo "Found the END_RUN_FILE file: $file"
2041 # A client load will stop if it finds the END_RUN_FILE file.
2042 # That does not mean the client load actually failed though.
2043 # The first node in END_RUN_FILE is the one we are interested in.
2046 if [ -n "$node" ]; then
2047 local var=$(node_var_name $node)_load
2049 local prefix=$TESTLOG_PREFIX
2050 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2051 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2052 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2054 echo "Client load ${!var} failed on node $node:"
2060 # Stop the process which had its PID saved in a file.
2065 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2067 do_nodes $nodes "test -f $pid_file &&
2068 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2071 # Stop all client loads.
2072 stop_client_loads() {
2073 local nodes=${1:-$CLIENTS}
2076 # stop the client loads
2077 stop_process $nodes $pid_file
2079 # clean up the processes that started them
2080 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2082 # End recovery-scale functions
2084 # verify that lustre actually cleaned up properly
2086 VAR=$(lctl get_param -n catastrophe 2>&1)
2087 if [ $? = 0 ] ; then
2088 if [ $VAR != 0 ]; then
2089 error "LBUG/LASSERT detected"
2092 BUSY=$(dmesg | grep -i destruct || true)
2093 if [ -n "$BUSY" ]; then
2095 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2099 check_mem_leak || exit 204
2101 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2102 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2105 if module_loaded lnet || module_loaded libcfs; then
2106 echo "$TESTSUITE: modules still loaded..." 1>&2
2115 if [[ "$1" == "--verbose" ]]; then
2130 PREV_RESULT=$(do_node $node "$TEST")
2132 RESULT=$(do_node $node "$TEST")
2133 if [[ "$RESULT" == "$FINAL" ]]; then
2134 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2135 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2139 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2140 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2144 [[ $WAIT -ge $MAX ]] && break
2145 [[ $((WAIT % print)) -eq 0 ]] &&
2146 echo "Waiting $((MAX - WAIT)) secs for update"
2147 WAIT=$((WAIT + sleep))
2150 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2154 wait_update_facet() {
2156 [ "$1" = "--verbose" ] && verbose="$1" && shift
2160 wait_update $verbose $(facet_active_host $facet) "$@"
2164 do_nodes $(comma_list $(mdts_nodes)) \
2165 "lctl set_param -n osd*.*MDT*.force_sync=1"
2166 do_nodes $(comma_list $(osts_nodes)) \
2167 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2168 grep -v 'Found no match'
2172 # the occupied disk space will be released
2173 # only after DMUs are committed
2174 if [[ $(facet_fstype $1) == zfs ]]; then
2175 echo "sleep $2 for ZFS OSD"
2180 wait_delete_completed_mds() {
2181 local MAX_WAIT=${1:-20}
2182 # for ZFS, waiting more time for DMUs to be committed
2183 local ZFS_WAIT=${2:-5}
2185 local stime=$(date +%s)
2190 # find MDS with pending deletions
2191 for node in $(mdts_nodes); do
2192 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2193 2>/dev/null | calc_sum)
2194 if [[ $changes -eq 0 ]]; then
2197 mds2sync="$mds2sync $node"
2199 if [ -z "$mds2sync" ]; then
2200 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2203 mds2sync=$(comma_list $mds2sync)
2205 # sync MDS transactions
2206 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2208 # wait till all changes are sent and commmitted by OSTs
2209 # for ldiskfs space is released upon execution, but DMU
2210 # do this upon commit
2213 while [[ $WAIT -ne $MAX_WAIT ]]; do
2214 changes=$(do_nodes $mds2sync \
2215 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2216 #echo "$node: $changes changes on all"
2217 if [[ $changes -eq 0 ]]; then
2218 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2226 echo "Delete is not completed in $((etime - stime)) seconds"
2227 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2233 # we can use "for" here because we are waiting the slowest
2234 for host in ${hostlist//,/ }; do
2235 check_network "$host" 900
2237 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2244 for facet in ${facetlist//,/ }; do
2245 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2247 wait_for_host $hostlist
2250 _wait_recovery_complete () {
2253 # Use default policy if $2 is not passed by caller.
2254 local MAX=${2:-$(max_recovery_time)}
2259 while [ $WAIT -lt $MAX ]; do
2260 STATUS=$(lctl get_param -n $param | grep status)
2262 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2265 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2267 echo "$param recovery not done in $MAX sec. $STATUS"
2271 wait_recovery_complete () {
2274 # with an assumption that at_max is the same on all nodes
2275 local MAX=${2:-$(max_recovery_time)}
2278 if [ "$FAILURE_MODE" = HARD ]; then
2279 facets=$(facets_on_host $(facet_active_host $facet))
2281 echo affected facets: $facets
2283 # we can use "for" here because we are waiting the slowest
2284 for facet in ${facets//,/ }; do
2285 local var_svc=${facet}_svc
2286 local param="*.${!var_svc}.recovery_status"
2288 local host=$(facet_active_host $facet)
2289 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2293 wait_mds_ost_sync () {
2294 # just because recovery is done doesn't mean we've finished
2295 # orphan cleanup. Wait for llogs to get synchronized.
2296 echo "Waiting for orphan cleanup..."
2297 # MAX value includes time needed for MDS-OST reconnection
2298 local MAX=$(( TIMEOUT * 2 ))
2299 local WAIT_TIMEOUT=${1:-$MAX}
2302 local list=$(comma_list $(mdts_nodes))
2303 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2304 if ! do_facet $SINGLEMDS \
2305 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2307 # old way, use mds_sync
2309 list=$(comma_list $(osts_nodes))
2310 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2313 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2314 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2315 local -a sync=($(do_nodes $list "$cmd"))
2318 for ((i=0; i<${#sync[@]}; i++)); do
2320 [ ${sync[$i]} -eq 1 ] && continue
2322 [ ${sync[$i]} -eq 0 ] && continue
2324 # there is a not finished MDS-OST synchronization
2328 sleep 2 # increase waiting time and cover statfs cache
2329 [ ${con} -eq 1 ] && return 0
2330 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2334 # show which nodes are not finished.
2335 do_nodes $list "$cmd"
2336 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2340 wait_destroy_complete () {
2341 echo "Waiting for local destroys to complete"
2342 # MAX value shouldn't be big as this mean server responsiveness
2343 # never increase this just to make test pass but investigate
2344 # why it takes so long time
2347 while [ $WAIT -lt $MAX ]; do
2348 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2352 for ((i=0; i<${#RPCs[@]}; i++)); do
2353 [ ${RPCs[$i]} -eq 0 ] && continue
2354 # there are still some destroy RPCs in flight
2359 [ ${con} -eq 1 ] && return 0 # done waiting
2360 echo "Waiting ${WAIT}s for local destroys to complete"
2363 echo "Local destroys weren't done in $MAX sec."
2367 wait_delete_completed() {
2368 wait_delete_completed_mds $1 || return $?
2369 wait_destroy_complete
2378 # conf-sanity 31 takes a long time cleanup
2379 while [ $WAIT -lt 300 ]; do
2380 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2381 [ -z "${running}" ] && return 0
2382 echo "waited $WAIT for${running}"
2383 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2385 WAIT=$((WAIT + INTERVAL))
2387 echo "service didn't stop after $WAIT seconds. Still running:"
2392 wait_remote_prog () {
2398 [ "$PDSH" = "no_dsh" ] && return 0
2400 while [ $WAIT -lt $2 ]; do
2401 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2402 [ -z "${running}" ] && return 0 || true
2403 echo "waited $WAIT for: "
2405 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2407 WAIT=$((WAIT + INTERVAL))
2409 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2410 [ -z "$pids" ] && return 0
2411 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2412 # FIXME: not portable
2413 for pid in $pids; do
2414 cat /proc/${pid}/status || true
2415 cat /proc/${pid}/wchan || true
2417 kill -9 $pid || true
2426 local clients=${1:-$CLIENTS}
2428 if [ -z "$clients" ]; then
2431 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2437 # not every config has many clients
2443 # usually checked on particular client or locally
2452 client_reconnect_try() {
2453 local f=$MOUNT/recon
2456 if [ -z "$CLIENTS" ]; then
2457 $LFS df $MOUNT; uname -n >> $f
2459 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2461 echo "Connected clients: $(cat $f)"
2462 ls -l $f > /dev/null
2466 client_reconnect() {
2467 # one client_reconnect_try call does not always do the job...
2469 client_reconnect_try && break
2474 affected_facets () {
2477 local host=$(facet_active_host $facet)
2478 local affected=$facet
2480 if [ "$FAILURE_MODE" = HARD ]; then
2481 affected=$(facets_up_on_host $host)
2487 local E2FSCK_ON_MDT0=false
2488 if [ "$1" == "--fsck" ]; then
2490 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2502 #Because it will only get up facets, we need get affected
2503 #facets before shutdown
2504 #For HARD Failure mode, it needs make sure facets on the same
2505 #HOST will only be shutdown and reboot once
2506 for facet in ${facets//,/ }; do
2507 local affected_facet
2509 #check whether facet has been included in other affected facets
2510 for ((index=0; index<$total; index++)); do
2511 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2514 if [ $skip -eq 0 ]; then
2515 affecteds[$total]=$(affected_facets $facet)
2520 for ((index=0; index<$total; index++)); do
2521 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2522 local host=$(facet_active_host $facet)
2523 echo "Failing ${affecteds[index]} on $host"
2524 shutdown_facet $facet
2527 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2528 $(mdsdevname 1) "-n" || error "Running e2fsck")
2530 for ((index=0; index<$total; index++)); do
2531 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2532 echo reboot facets: ${affecteds[index]}
2536 change_active ${affecteds[index]}
2538 wait_for_facet ${affecteds[index]}
2539 # start mgs first if it is affected
2540 if ! combined_mgs_mds &&
2541 list_member ${affecteds[index]} mgs; then
2542 mount_facet mgs || error "Restart of mgs failed"
2544 # FIXME; has to be changed to mount all facets concurrently
2545 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2546 echo mount facets: ${affecteds[index]}
2547 mount_facets ${affecteds[index]}
2557 do_facet $facet "sync; sync; sync"
2560 # make sure there will be no seq change
2561 local clients=${CLIENTS:-$HOSTNAME}
2562 local f=fsa-\\\$\(hostname\)
2563 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2564 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2566 local svc=${facet}_svc
2567 do_facet $facet $LCTL --device ${!svc} notransno
2569 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2570 # in-memory state has to be cleared by either rebooting the host or
2571 # exporting and reimporting the pool.
2573 # Although the uberblocks are not updated when a pool is freezed,
2574 # transactions are still written to the disks. Modified blocks may be
2575 # cached in memory when tests try reading them back. The
2576 # export-and-reimport process also evicts any cached pool data from
2577 # memory to provide the correct "data loss" semantics.
2579 # In the test framework, the exporting and importing operations are
2580 # handled by stop() and mount_facet() separately, which are used
2581 # inside fail() and fail_abort().
2583 do_facet $facet $LCTL --device ${!svc} readonly
2584 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2585 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2588 replay_barrier_nodf() {
2589 local facet=$1 echo running=${running}
2590 do_facet $facet "sync; sync; sync"
2591 local svc=${facet}_svc
2592 echo Replay barrier on ${!svc}
2593 do_facet $facet $LCTL --device ${!svc} notransno
2594 do_facet $facet $LCTL --device ${!svc} readonly
2595 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2596 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2599 replay_barrier_nosync() {
2600 local facet=$1 echo running=${running}
2601 local svc=${facet}_svc
2602 echo Replay barrier on ${!svc}
2603 do_facet $facet $LCTL --device ${!svc} notransno
2604 do_facet $facet $LCTL --device ${!svc} readonly
2605 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2606 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2610 # Get Lustre client uuid for a given Lustre mount point.
2613 local mntpnt=${1:-$MOUNT}
2615 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2616 local uuid=$($LCTL get_param -n llite.$name.uuid)
2621 mds_evict_client() {
2622 local mntpnt=${1:-$MOUNT}
2623 local uuid=$(get_client_uuid $mntpnt)
2625 do_facet $SINGLEMDS \
2626 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2629 ost_evict_client() {
2630 local mntpnt=${1:-$MOUNT}
2631 local uuid=$(get_client_uuid $mntpnt)
2634 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2639 local clients=${CLIENTS:-$HOSTNAME}
2641 facet_failover $* || error "failover: $?"
2642 wait_clients_import_state "$clients" "$facets" FULL
2643 clients_up || error "post-failover stat: $?"
2648 facet_failover $facet
2654 change_active $facet
2655 wait_for_facet $facet
2656 mount_facet $facet -o abort_recovery
2657 clients_up || echo "first stat failed: $?"
2658 clients_up || error "post-failover stat: $?"
2662 echo There is no lmc. This is mountconf, baby.
2666 host_nids_address() {
2670 if [ -n "$kind" ]; then
2671 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2673 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2679 if [ "$1" = "'*'" ]; then echo \'*\'; else
2685 if [ "$1" = "'*'" ]; then echo \'*\'; else
2686 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2688 if [ -z "$ID" ]; then
2689 echo "Could not get a ptl id for $1..."
2698 h2name_or_ip "$1" "tcp"
2703 if [ "$1" = "'*'" ]; then echo \'*\'; else
2704 if type __h2elan >/dev/null 2>&1; then
2707 ID=`echo $1 | sed 's/[^0-9]*//g'`
2715 h2name_or_ip "$1" "o2ib"
2719 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2720 # expressions format. As a bonus we can then just pass in those variables
2721 # to pdsh. What this function does is take a HOSTLIST type string and
2722 # expand it into a space deliminated list for us.
2730 [ -z "$hostlist" ] && return
2732 # Translate the case of [..],..,[..] to [..] .. [..]
2733 list="${hostlist/],/] }"
2735 [[ "$front" == *,* ]] && {
2738 list=${list/${old}/${new}}
2741 for item in $list; do
2742 # Test if we have any []'s at all
2743 if [ "$item" != "${item/\[/}" ]; then {
2744 # Expand the [*] into list
2748 if [ "$name" != "$item" ]; then
2749 group=${item#$name[*}
2752 for range in ${group//,/ }; do
2756 # Number of leading zeros
2759 end=$(echo $end | sed 's/0*//')
2760 [[ -z "$end" ]] && end=0
2761 [[ $padlen2 -gt $padlen ]] && {
2762 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2765 begin=$(echo $begin | sed 's/0*//')
2766 [ -z $begin ] && begin=0
2768 for num in $(seq -f "%0${padlen}g" $begin $end); do
2769 value="${name#*,}${num}${back}"
2770 [ "$value" != "${value/\[/}" ] && {
2771 value=$(hostlist_expand "$value")
2773 myList="$myList $value"
2778 myList="$myList $item"
2781 myList=${myList//,/ }
2782 myList=${myList:1} # Remove first character which is a space
2784 # Filter any duplicates without sorting
2786 myList="${list%% *}"
2788 while [[ "$list" != ${myList##* } ]]; do
2789 list=${list//${list%% *} /}
2790 myList="$myList ${list%% *}"
2792 myList="${myList%* }";
2794 # We can select an object at an offset in the list
2797 for item in $myList; do
2799 [ $cnt -eq $offset ] && {
2803 [ $(get_node_count $myList) -ne 1 ] && myList=""
2812 [ "$facet" == client ] && echo -n $HOSTNAME && return
2813 varname=${facet}_HOST
2814 if [ -z "${!varname}" ]; then
2815 if [ "${facet:0:3}" == "ost" ]; then
2816 local fh=${facet%failover}_HOST
2817 eval export ${facet}_HOST=${!fh}
2818 if [ -z "${!varname}" ]; then
2819 eval export ${facet}_HOST=${ost_HOST}
2821 elif [ "${facet:0:3}" == "mdt" -o \
2822 "${facet:0:3}" == "mds" -o \
2823 "${facet:0:3}" == "mgs" ]; then
2824 eval export ${facet}_HOST=${mds_HOST}
2830 facet_failover_host() {
2834 var=${facet}failover_HOST
2835 if [ -n "${!var}" ]; then
2840 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2841 "${facet:0:3}" == "mgs" ]; then
2843 eval export ${facet}failover_host=${mds_HOST}
2848 if [[ $facet == ost* ]]; then
2849 eval export ${facet}failover_host=${ost_HOST}
2857 local activevar=${facet}active
2859 if [ -f $TMP/${facet}active ] ; then
2860 source $TMP/${facet}active
2863 active=${!activevar}
2864 if [ -z "$active" ] ; then
2871 facet_active_host() {
2872 facet_host $(facet_active $1)
2875 # Get the passive failover partner host of facet.
2876 facet_passive_host() {
2878 [[ $facet = client ]] && return
2880 local host=${facet}_HOST
2881 local failover_host=${facet}failover_HOST
2882 local active_host=$(facet_active_host $facet)
2884 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2886 if [[ $active_host = ${!host} ]]; then
2887 echo -n ${!failover_host}
2897 facetlist=$(exclude_items_from_list $facetlist mgs)
2899 for facet in ${facetlist//,/ }; do
2900 local failover=${facet}failover
2901 local host=`facet_host $failover`
2902 [ -z "$host" ] && return
2904 local curactive=`facet_active $facet`
2905 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2906 eval export ${facet}active=$facet
2908 eval export ${facet}active=$failover
2910 # save the active host for this facet
2911 local activevar=${facet}active
2912 echo "$activevar=${!activevar}" > $TMP/$activevar
2913 [[ $facet = mds1 ]] && combined_mgs_mds && \
2914 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2915 local TO=`facet_active_host $facet`
2916 echo "Failover $facet to $TO"
2922 # do not stripe off hostname if verbose, bug 19215
2923 if [ x$1 = x--verbose ]; then
2931 if [ "$HOST" = "$HOSTNAME" ]; then
2933 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2934 echo "cannot run remote command on $HOST with $myPDSH"
2938 echo "CMD: $HOST $@" >&2
2939 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2942 if [ "$myPDSH" = "rsh" ]; then
2943 # we need this because rsh does not return exit code of an executed command
2944 local command_status="$TMP/cs"
2945 rsh $HOST ":> $command_status"
2946 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2947 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2948 echo command failed >$command_status"
2949 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2954 # print HOSTNAME for myPDSH="no_dsh"
2955 if [[ $myPDSH = no_dsh ]]; then
2956 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2958 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2961 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2963 return ${PIPESTATUS[0]}
2967 do_node --verbose "$@"
2970 single_local_node () {
2971 [ "$1" = "$HOSTNAME" ]
2974 # Outputs environment variable assignments that should be passed to remote nodes
2978 local facets=$(get_facets)
2981 for var in ${!MODOPTS_*}; do
2982 value=${!var//\"/\\\"}
2983 echo -n " ${var}=\"$value\""
2986 for facet in ${facets//,/ }; do
2988 if [ -n "${!var}" ]; then
2989 echo -n " $var=${!var}"
2993 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2994 if [ -n "${!var}" ]; then
2995 echo -n " $var=${!var}"
2999 for var in VERBOSE; do
3000 if [ -n "${!var}" ]; then
3001 echo -n " $var=${!var}"
3005 if [ -n "$FSTYPE" ]; then
3006 echo -n " FSTYPE=$FSTYPE"
3009 for var in LNETLND NETTYPE; do
3010 if [ -n "${!var}" ]; then
3011 echo -n " $var=${!var}"
3018 # do not stripe off hostname if verbose, bug 19215
3019 if [ x$1 = x--verbose ]; then
3027 if single_local_node $rnodes; then
3029 do_nodev $rnodes "$@"
3031 do_node $rnodes "$@"
3036 # This is part from do_node
3039 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3040 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3042 export FANOUT=$(get_node_count "${rnodes//,/ }")
3044 echo "CMD: $rnodes $@" >&2
3045 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3048 # do not replace anything from pdsh output if -N is used
3049 # -N Disable hostname: prefix on lines of output.
3050 if $verbose || [[ $myPDSH = *-N* ]]; then
3051 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3053 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3055 return ${PIPESTATUS[0]}
3059 # Execute commands on a single service's host
3061 # The \a facet (service) may be on a local or remote node, which is
3062 # determined at the time the command is run.
3064 # usage: do_facet $facet command [arg ...]
3068 local HOST=$(facet_active_host $facet)
3069 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3073 # Function: do_facet_random_file $FACET $FILE $SIZE
3074 # Creates FILE with random content on the given FACET of given SIZE
3076 do_facet_random_file() {
3080 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3081 do_facet $facet "$cmd 2>/dev/null"
3084 do_facet_create_file() {
3088 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3089 do_facet $facet "$cmd 2>/dev/null"
3093 do_nodes --verbose "$@"
3099 # make sure its not already running
3101 rm -f $TMP/${facet}active
3102 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3103 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3105 if [[ $(facet_fstype $facet) == zfs ]]; then
3107 # After formatting a ZFS target, "cachefile=none" property will
3108 # be set on the ZFS storage pool so that the pool is not
3109 # automatically imported on system startup. And then the pool
3110 # will be exported so as to leave the importing and exporting
3111 # operations handled by mount_facet() and stop() separately.
3113 refresh_partition_table $facet $(facet_vdevice $facet)
3114 disable_zpool_cache $facet
3119 # Device formatted as ost
3122 local DEVNAME=OSTDEV$num
3124 local fstype=$(facet_fstype ost$num)
3128 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3129 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3131 #try $OSTZFSDEVn - independent of vdev
3132 DEVNAME=OSTZFSDEV$num
3133 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3135 error "unknown fstype!";;
3141 # Physical device location of data
3147 local fstype=$(facet_fstype ost$num)
3151 # vdevs are not supported by ldiskfs
3154 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3155 # Device formatted by zfs
3157 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3159 error "unknown fstype!";;
3165 # Logical device formatted for lustre
3168 local DEVNAME=MDSDEV$num
3170 local fstype=$(facet_fstype mds$num)
3174 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3175 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3177 # try $MDSZFSDEVn - independent of vdev
3178 DEVNAME=MDSZFSDEV$num
3179 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3181 error "unknown fstype!";;
3187 # Physical location of data
3191 local fstype=$(facet_fstype mds$num)
3195 # vdevs are not supported by ldiskfs
3198 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3199 # Device formatted by ZFS
3200 local DEVNAME=MDSDEV$num
3201 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3203 error "unknown fstype!";;
3211 local fstype=$(facet_fstype mgs)
3215 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3216 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3217 DEVPTR=$(mdsdevname 1)
3222 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3223 ( [ -z "$MGSZFSDEV" ] &&
3224 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3225 DEVPTR=$(mdsdevname 1)
3227 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3230 error "unknown fstype!";;
3239 local fstype=$(facet_fstype mgs)
3243 # vdevs are not supported by ldiskfs
3246 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3247 ( [ -z "$MGSDEV" ] &&
3248 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3249 VDEVPTR=$(mdsvdevname 1)
3250 elif [ -n "$MGSDEV" ]; then
3254 error "unknown fstype!";;
3262 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3264 local var=${facet}_MOUNT
3265 eval mntpt=${!var:-${MOUNT}-$facet}
3272 local dev=$(facet_device $facet)
3273 local mnt=${2:-$(facet_mntpt $facet)}
3276 if ! do_facet $facet test -b $dev; then
3279 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3284 local dev=$(facet_device $facet)
3285 local mnt=${2:-$(facet_mntpt $facet)}
3287 do_facet $facet $UMOUNT $mnt
3291 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3296 local ds=$(facet_device $facet)
3297 local mnt=${2:-$(facet_mntpt $facet)}
3302 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3303 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3304 do_facet $facet $ZFS set canmount=noauto $ds
3306 # The "legacy" mount method is used here because "zfs unmount $mnt"
3307 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3308 # targets are not available at the time, the stat(2) on $MOUNT will
3311 do_facet $facet $ZFS set mountpoint=legacy $ds
3312 do_facet $facet mount -t zfs $ds $mnt
3313 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3314 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3319 local ds=$(facet_device $facet)
3320 local mnt=${2:-$(facet_mntpt $facet)}
3321 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3322 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3323 local mntpt=${!var_mntpt}
3324 local canmnt=${!var_canmnt}
3328 do_facet $facet umount $mnt
3329 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3330 do_facet $facet $ZFS set canmount=$canmnt $ds
3337 local fstype=$(facet_fstype $facet)
3339 mount_$fstype $facet $mnt
3345 local fstype=$(facet_fstype $facet)
3347 unmount_$fstype $facet $mnt
3354 # make sure we are using the primary server, so test-framework will
3355 # be able to clean up properly.
3356 activemds=`facet_active mds1`
3357 if [ $activemds != "mds1" ]; then
3361 local clients=$CLIENTS
3362 [ -z $clients ] && clients=$(hostname)
3364 zconf_umount_clients $clients $MOUNT "$*" || true
3365 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3367 [ -n "$CLIENTONLY" ] && return
3369 # The add fn does rm ${facet}active file, this would be enough
3370 # if we use do_facet <facet> only after the facet added, but
3371 # currently we use do_facet mds in local.sh
3372 for num in `seq $MDSCOUNT`; do
3374 rm -f ${TMP}/mds${num}active
3376 combined_mgs_mds && rm -f $TMP/mgsactive
3378 for num in `seq $OSTCOUNT`; do
3380 rm -f $TMP/ost${num}active
3383 if ! combined_mgs_mds ; then
3390 cleanup_echo_devs () {
3393 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3395 for dev in $devs; do
3396 $LCTL --device $dev cleanup
3397 $LCTL --device $dev detach
3402 nfs_client_mode && return
3403 cifs_client_mode && return
3412 combined_mgs_mds () {
3413 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3414 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3418 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3422 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3428 local fsname=${3:-"$FSNAME"}
3429 local type=$(facet_type $facet)
3430 local index=$(facet_index $facet)
3431 local fstype=$(facet_fstype $facet)
3432 local host=$(facet_host $facet)
3437 if [ $type == MGS ] || ( [ $type == MDS ] &&
3438 [ "$dev" == $(mgsdevname) ] &&
3439 [ "$host" == "$(facet_host mgs)" ] ); then
3442 opts="--mgsnode=$MGSNID"
3445 if [ $type != MGS ]; then
3446 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3450 var=${facet}failover_HOST
3451 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3452 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3455 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3456 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3458 if [ $type == MDS ]; then
3459 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3460 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3461 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3462 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3464 if [ $fstype == ldiskfs ]; then
3465 # Check for wide striping
3466 if [ $OSTCOUNT -gt 160 ]; then
3467 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3468 fs_mkfs_opts+="-O large_xattr"
3472 if [ -n "${!var}" ]; then
3473 fs_mkfs_opts+=" -J device=${!var}"
3475 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3477 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3481 if [ $type == OST ]; then
3482 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3484 if [ $fstype == ldiskfs ]; then
3486 if [ -n "${!var}" ]; then
3487 fs_mkfs_opts+=" -J device=${!var}"
3489 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3494 opts+=" --backfstype=$fstype"
3497 if [ -n "${!var}" ]; then
3498 opts+=" --device-size=${!var}"
3501 var=$(upper $fstype)_MKFS_OPTS
3502 fs_mkfs_opts+=${!var:+" ${!var}"}
3504 var=${type}_FS_MKFS_OPTS
3505 fs_mkfs_opts+=${!var:+" ${!var}"}
3507 if [ -n "${fs_mkfs_opts## }" ]; then
3508 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3512 opts+=${!var:+" ${!var}"}
3517 check_ost_indices() {
3518 local index_count=${#OST_INDICES[@]}
3519 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3521 # OST count is greater than the index count in $OST_INDEX_LIST.
3522 # We need check whether there are duplicate indices.
3526 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3527 index=$(facet_index ost$i)
3528 for j in $(seq 0 $((index_count - 1))); do
3529 [[ $index -ne ${OST_INDICES[j]} ]] ||
3530 error "ost$i has the same index $index as ost$((j+1))"
3541 echo "Format mgs: $(mgsdevname)"
3542 reformat_external_journal mgs
3543 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3544 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3554 echo "Format mds$num: $(mdsdevname $num)"
3555 reformat_external_journal mds$num
3556 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3557 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3558 ${quiet:+>/dev/null} || exit 10
3567 echo "Format ost$num: $(ostdevname $num)"
3568 reformat_external_journal ost$num
3569 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3570 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3571 ${quiet:+>/dev/null} || exit 10
3576 # Set hostid for ZFS/SPL zpool import protection
3577 # (Assumes MDS version is also OSS version)
3578 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3580 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3583 # We need ldiskfs here, may as well load them all
3585 [ -n "$CLIENTONLY" ] && return
3586 echo Formatting mgs, mds, osts
3587 if ! combined_mgs_mds ; then
3591 for num in $(seq $MDSCOUNT); do
3595 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3597 for num in $(seq $OSTCOUNT); do
3603 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3607 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3611 # 0: success, the old identity set already.
3612 # 1: success, the old identity does not set.
3617 local j=`expr $num - 1`
3618 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3620 if [ -z "$MDT" ]; then
3624 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3627 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3629 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3632 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3634 if [ $old = "NONE" ]; then
3643 zconf_umount `hostname` $1 || error "umount failed"
3644 zconf_mount `hostname` $1 || error "mount failed"
3652 rm -f $TMP/${facet}active
3653 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3658 local mdt_count=${1:-$MDSCOUNT}
3659 local ost_count=${2:-$OSTCOUNT}
3662 for num in $(seq $mdt_count); do
3663 DEVNAME=$(mdsdevname $num)
3664 writeconf_facet mds$num $DEVNAME || rc=$?
3667 for num in $(seq $ost_count); do
3668 DEVNAME=$(ostdevname $num)
3669 writeconf_facet ost$num $DEVNAME || rc=$?
3675 nfs_client_mode && return
3676 cifs_client_mode && return
3678 sanity_mount_check || error "environments are insane!"
3682 if [ -z "$CLIENTONLY" ]; then
3683 echo Setup mgs, mdt, osts
3684 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3685 if ! combined_mgs_mds ; then
3686 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3689 for num in `seq $MDSCOUNT`; do
3690 DEVNAME=$(mdsdevname $num)
3691 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3693 # We started mds, now we should set failover variables properly.
3694 # Set mds${num}failover_HOST if it is not set (the default failnode).
3695 local varname=mds${num}failover_HOST
3696 if [ -z "${!varname}" ]; then
3697 eval mds${num}failover_HOST=$(facet_host mds$num)
3700 if [ $IDENTITY_UPCALL != "default" ]; then
3701 switch_identity $num $IDENTITY_UPCALL
3704 for num in `seq $OSTCOUNT`; do
3705 DEVNAME=$(ostdevname $num)
3706 start ost$num $DEVNAME $OST_MOUNT_OPTS
3708 # We started ost$num, now we should set ost${num}failover variable properly.
3709 # Set ost${num}failover_HOST if it is not set (the default failnode).
3710 varname=ost${num}failover_HOST
3711 if [ -z "${!varname}" ]; then
3712 eval ost${num}failover_HOST=$(facet_host ost${num})
3720 # wait a while to allow sptlrpc configuration be propogated to targets,
3721 # only needed when mounting new target devices.
3726 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3728 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3731 if [ "$MOUNT_2" ]; then
3732 mount_client $MOUNT2
3733 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3738 # by remounting mdt before ost, initial connect from mdt to ost might
3739 # timeout because ost is not ready yet. wait some time to its fully
3740 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3741 # by a context negotiation rpc with $TIMEOUT.
3742 # FIXME better by monitoring import status.
3745 sleep $((TIMEOUT + 5))
3751 mounted_lustre_filesystems() {
3752 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3755 init_facet_vars () {
3756 [ -n "$CLIENTONLY" ] && return 0
3763 eval export ${facet}_dev=${device}
3764 eval export ${facet}_opt=\"$@\"
3766 local dev=${facet}_dev
3768 # We need to loop for the label
3769 # in case its not initialized yet.
3770 for wait_time in {0,1,3,5,10}; do
3772 if [ $wait_time -gt 0 ]; then
3773 echo "${!dev} not yet initialized,"\
3774 "waiting ${wait_time} seconds."
3778 local label=$(devicelabel ${facet} ${!dev})
3780 # Check to make sure the label does
3781 # not include ffff at the end of the label.
3782 # This indicates it has not been initialized yet.
3784 if [[ $label =~ [f|F]{4}$ ]]; then
3785 # label is not initialized, unset the result
3786 # and either try again or fail
3793 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3795 eval export ${facet}_svc=${label}
3797 local varname=${facet}failover_HOST
3798 if [ -z "${!varname}" ]; then
3799 eval export $varname=$(facet_host $facet)
3802 varname=${facet}_HOST
3803 if [ -z "${!varname}" ]; then
3804 eval export $varname=$(facet_host $facet)
3807 # ${facet}failover_dev is set in cfg file
3808 varname=${facet}failover_dev
3809 if [ -n "${!varname}" ] ; then
3810 eval export ${facet}failover_dev=${!varname}
3812 eval export ${facet}failover_dev=$device
3815 # get mount point of already mounted device
3816 # is facet_dev is already mounted then use the real
3817 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3818 # i.e. ${facet}_MOUNT if specified by user or default
3819 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3820 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3821 if [ -z $mntpt ]; then
3822 mntpt=$(facet_mntpt $facet)
3824 eval export ${facet}_MOUNT=$mntpt
3827 init_facets_vars () {
3830 if ! remote_mds_nodsh; then
3831 for num in $(seq $MDSCOUNT); do
3832 DEVNAME=`mdsdevname $num`
3833 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3837 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3839 if ! remote_ost_nodsh; then
3840 for num in $(seq $OSTCOUNT); do
3841 DEVNAME=$(ostdevname $num)
3842 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3847 osc_ensure_active () {
3852 while [ $period -lt $timeout ]; do
3853 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3854 if [ $count -eq 0 ]; then
3858 echo "There are $count OST are inactive, wait $period seconds, and try again"
3860 period=$((period+3))
3863 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3866 set_conf_param_and_check() {
3870 local ORIG=$(do_facet $myfacet "$TEST")
3871 if [ $# -gt 3 ]; then
3877 echo "Setting $PARAM from $ORIG to $FINAL"
3878 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3879 error "conf_param $PARAM failed"
3881 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3882 error "check $PARAM failed!"
3885 init_param_vars () {
3886 TIMEOUT=$(lctl get_param -n timeout)
3887 TIMEOUT=${TIMEOUT:-20}
3889 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3891 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3892 log "Using TIMEOUT=$TIMEOUT"
3894 osc_ensure_active $SINGLEMDS $TIMEOUT
3895 osc_ensure_active client $TIMEOUT
3897 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3898 local current_jobid_var=$($LCTL get_param -n jobid_var)
3900 if [ $JOBID_VAR = "existing" ]; then
3901 echo "keeping jobstats as $current_jobid_var"
3902 elif [ $current_jobid_var != $JOBID_VAR ]; then
3903 echo "seting jobstats to $JOBID_VAR"
3905 set_conf_param_and_check client \
3906 "$LCTL get_param -n jobid_var" \
3907 "$FSNAME.sys.jobid_var" $JOBID_VAR
3910 echo "jobstats not supported by server"
3913 if [ $QUOTA_AUTO -ne 0 ]; then
3914 if [ "$ENABLE_QUOTA" ]; then
3915 echo "enable quota as required"
3916 setup_quota $MOUNT || return 2
3918 echo "disable quota as required"
3919 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3925 nfs_client_mode () {
3926 if [ "$NFSCLIENT" ]; then
3927 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3928 local clients=$CLIENTS
3929 [ -z $clients ] && clients=$(hostname)
3931 # FIXME: remove hostname when 19215 fixed
3932 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3933 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3934 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3935 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3937 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3943 cifs_client_mode () {
3944 [ x$CIFSCLIENT = xyes ] &&
3945 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3948 check_config_client () {
3951 local mounted=$(mount | grep " $mntpt ")
3952 if [ -n "$CLIENTONLY" ]; then
3954 # CLIENTONLY should not depend on *_HOST settings
3955 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3956 # in theory someone could create a new,
3957 # client-only config file that assumed lustre was already
3958 # configured and didn't set the MGSNID. If MGSNID is not set,
3959 # then we should use the mgs nid currently being used
3960 # as the default value. bug 18021
3961 [[ x$MGSNID = x ]] &&
3964 if [[ x$mgc != xMGC$MGSNID ]]; then
3965 if [ "$mgs_HOST" ]; then
3966 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3967 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3968 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3974 local myMGS_host=$mgs_HOST
3975 if [ "$NETTYPE" = "ptl" ]; then
3976 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3979 echo Checking config lustre mounted on $mntpt
3980 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3981 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3983 # if [ "$mgshost" != "$myMGS_host" ]; then
3984 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3985 # Please use correct config or set mds_HOST correctly!"
3990 check_config_clients () {
3991 local clients=${CLIENTS:-$HOSTNAME}
3994 nfs_client_mode && return
3995 cifs_client_mode && return
3997 do_rpc_nodes "$clients" check_config_client $mntpt
3999 sanity_mount_check || error "environments are insane!"
4003 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4004 local cltimeout=$(lctl get_param -n timeout)
4005 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4006 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4013 [ -z $mntpt ] && return 1
4014 local mounted=$(mounted_lustre_filesystems)
4016 echo $mounted' ' | grep -w -q $mntpt' '
4020 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4024 # empty lustre filesystem may have empty directories lost+found and .lustre
4026 # exclude .lustre & lost+found
4027 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4028 -print | wc -l) = 1 ] || return 1
4029 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4030 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4031 # exclude .lustre/fid (LU-2780)
4032 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4033 -print | wc -l) = 1 ] || return 1
4035 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4040 check_and_setup_lustre() {
4042 nfs_client_mode && return
4043 cifs_client_mode && return
4045 local MOUNTED=$(mounted_lustre_filesystems)
4049 # both MOUNT and MOUNT2 are not mounted
4050 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4051 [ "$REFORMAT" = "yes" ] && formatall
4052 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4054 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4055 export I_MOUNTED=yes
4059 elif is_mounted $MOUNT2; then
4061 # MOUNT2 is mounted, while MOUNT_2 is not set
4062 if ! [ "$MOUNT_2" ]; then
4063 cleanup_mount $MOUNT2
4064 export I_UMOUNTED2=yes
4067 # MOUNT2 is mounted, MOUNT_2 is set
4069 # FIXME: what to do if check_config failed?
4071 # 1) remote client has mounted other Lustre fs ?
4072 # 2) it has insane env ?
4073 # let's try umount MOUNT2 on all clients and mount it again:
4074 if ! check_config_clients $MOUNT2; then
4075 cleanup_mount $MOUNT2
4076 restore_mount $MOUNT2
4077 export I_MOUNTED2=yes
4082 # MOUNT is mounted MOUNT2 is not mounted
4083 elif [ "$MOUNT_2" ]; then
4084 restore_mount $MOUNT2
4085 export I_MOUNTED2=yes
4089 # FIXME: what to do if check_config failed?
4091 # 1) remote client has mounted other Lustre fs?
4092 # 2) lustre is mounted on remote_clients atall ?
4093 check_config_clients $MOUNT
4097 set_default_debug_nodes $(comma_list $(nodes_list))
4100 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4102 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4103 facets="$(get_facets OST)"
4104 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4105 facets="$facets,$(get_facets MDS)"
4106 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4107 facets="$facets,mgs"
4108 local nodes="$(facets_hosts ${facets})"
4109 if [ -n "$nodes" ] ; then
4110 do_nodes $nodes "$LCTL set_param \
4111 osd-ldiskfs.track_declares_assert=1 || true"
4120 if [ -z "$CLIENTONLY" ]; then
4121 # Enable remote MDT create for testing
4122 for num in $(seq $MDSCOUNT); do
4124 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4129 if [ "$ONLY" == "setup" ]; then
4135 local clients=${CLIENTS:-$HOSTNAME}
4138 zconf_mount_clients $clients $mntpt
4142 local clients=${CLIENTS:-$HOSTNAME}
4145 zconf_umount_clients $clients $mntpt
4148 cleanup_and_setup_lustre() {
4149 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4150 lctl set_param debug=0 || true
4152 if [ "$ONLY" == "cleanup" ]; then
4156 check_and_setup_lustre
4159 # Get all of the server target devices from a given server node and type.
4166 if [ "$type" == ost ]; then
4167 devs=$(get_osd_param $node "" mntdev)
4169 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4171 for dev in $devs; do
4173 *loop*) do_node $node "losetup $dev" | \
4174 sed -e "s/.*(//" -e "s/).*//" ;;
4180 # Get all of the server target devices.
4185 # Master MDS parameters used by lfsck
4186 MDTNODE=$(facet_active_host $SINGLEMDS)
4187 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4191 for node in $(mdts_nodes); do
4192 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4198 for node in $(osts_nodes); do
4199 OSTDEVS[i]=$(get_mnt_devs $node ost)
4204 # Run e2fsck on MDT or OST device.
4209 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4210 local log=$TMP/e2fsck.log
4214 do_node $node $cmd 2>&1 | tee $log
4216 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4218 if [ $MDSCOUNT -gt 1 ]; then
4219 skip "DNE mode isn't supported!"
4223 error "It's not DNE mode."
4228 [ $rc -le $FSCK_MAX_ERR ] ||
4229 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4235 # Run resize2fs on MDT or OST device.
4244 do_facet $facet "$RESIZE2FS $opts $device $size"
4247 # verify a directory is shared among nodes.
4248 check_shared_dir() {
4250 local list=${2:-$(comma_list $(nodes_list))}
4252 [ -z "$dir" ] && return 1
4253 do_rpc_nodes "$list" check_logdir $dir
4254 check_write_access $dir "$list" || return 1
4259 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4260 $LCTL set_param printk=+lfsck
4261 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4263 for k in $(seq $MDSCOUNT); do
4264 # wait up to 10+1 minutes for LFSCK to complete
4265 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4266 mdd.$(facet_svc mds${k}).lfsck_layout |
4267 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4268 error "MDS${k} layout isn't the expected 'completed'"
4269 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4270 mdd.$(facet_svc mds${k}).lfsck_namespace |
4271 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4272 error "MDS${k} namespace isn't the expected 'completed'"
4274 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4275 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4276 awk '/repaired/ { print $2 }' | calc_sum)
4277 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4278 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4279 awk '/repaired/ { print $2 }' | calc_sum)
4280 local repaired=$((rep_mdt + rep_ost))
4281 [ $repaired -eq 0 ] ||
4282 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4285 dump_file_contents() {
4291 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4292 error_noexit false \
4293 "Invalid parameters for dump_file_contents()"
4296 for node in ${nodes}; do
4297 do_node $node "for i in \\\$(find $dir -type f); do
4298 echo ====\\\${i}=======================;
4300 done" >> ${logname}.${node}.log
4304 dump_command_output() {
4310 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4311 error_noexit false \
4312 "Invalid parameters for dump_command_output()"
4316 for node in ${nodes}; do
4317 do_node $node "echo ====${cmd}=======================;
4318 $cmd" >> ${logname}.${node}.log
4325 # dump file contents from /proc/spl in case of zfs test
4326 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4327 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4328 dump_command_output \
4329 "$(osts_nodes)" "zpool events -v" "${logname}"
4332 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4333 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4334 dump_command_output \
4335 "$(mdts_nodes)" "zpool events -v" "${logname}"
4339 check_and_cleanup_lustre() {
4340 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4341 "$TESTSUITE" != "sanity-scrub" ]; then
4345 if is_mounted $MOUNT; then
4346 if $DO_CLEANUP; then
4347 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4348 error "remove sub-test dirs failed"
4352 [ "$ENABLE_QUOTA" ] && restore_quota || true
4355 if [ "$I_UMOUNTED2" = "yes" ]; then
4356 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4359 if [ "$I_MOUNTED2" = "yes" ]; then
4360 cleanup_mount $MOUNT2
4363 if [ "$I_MOUNTED" = "yes" ]; then
4364 cleanupall -f || error "cleanup failed"
4372 wait_for_function () {
4375 # suppress fn both stderr and stdout
4376 if [ "$1" = "--quiet" ]; then
4378 quiet=" > /dev/null 2>&1"
4390 eval $fn $quiet && return 0
4392 wait=$((wait + sleep))
4393 [ $wait -lt $max ] || return 1
4394 echo waiting $fn, $((max - wait)) secs left ...
4404 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4405 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4406 echo "Network not available!"
4410 echo `date +"%H:%M:%S (%s)"` network interface is UP
4418 # Convert a space-delimited list to a comma-delimited list. If the input is
4419 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4421 # echo is used to convert newlines to spaces, since it doesn't
4422 # introduce a trailing space as using "tr '\n' ' '" does
4423 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4429 echo $list | grep -qw $item
4432 # list, excluded are the comma separated lists
4433 exclude_items_from_list () {
4439 for item in ${excluded//,/ }; do
4440 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4442 echo $(comma_list $list)
4445 # list, expand are the comma separated lists
4447 local list=${1//,/ }
4448 local expand=${2//,/ }
4451 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4452 echo $(comma_list $expanded)
4455 testslist_filter () {
4456 local script=$LUSTRE/tests/${TESTSUITE}.sh
4458 [ -f $script ] || return 0
4460 local start_at=$START_AT
4461 local stop_at=$STOP_AT
4463 local var=${TESTSUITE//-/_}_START_AT
4464 [ x"${!var}" != x ] && start_at=${!var}
4465 var=${TESTSUITE//-/_}_STOP_AT
4466 [ x"${!var}" != x ] && stop_at=${!var}
4468 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4469 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4470 /^'${start_at}'$/ {flag = 0}
4471 {if (flag == 1) print $0}
4472 /^'${stop_at}'$/ { flag = 1 }'
4476 (cd `dirname $1`; echo $PWD/`basename $1`)
4480 local types=${1:-"OST MDS MGS"}
4484 for entry in $types; do
4485 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4486 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4489 MGS ) list="$list $name";;
4490 MDS|OST|AGT ) local count=${type}COUNT
4491 for ((i=1; i<=${!count}; i++)) do
4492 list="$list ${name}$i"
4494 * ) error "Invalid facet type"
4498 echo $(comma_list $list)
4501 ##################################
4502 # Adaptive Timeouts funcs
4505 # only check mds, we assume at_max is the same on all nodes
4506 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4507 if [ $at_max -eq 0 ]; then
4518 # suppose that all ost-s have the same $at value set
4519 [ $facet != "ost" ] || facet=ost1
4521 do_facet $facet "lctl get_param -n $at"
4539 if [ $facet == "ost" ]; then
4540 facet=$(get_facets OST)
4541 elif [ $facet == "mds" ]; then
4542 facet=$(get_facets MDS)
4544 hosts=$(expand_list $hosts $(facets_hosts $facet))
4547 do_nodes $hosts lctl set_param at_max=$at_max
4550 ##################################
4554 # OBD_FAIL_MDS_ALL_REQUEST_NET
4556 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4557 do_facet client "$1" || RC=$?
4558 do_facet $SINGLEMDS lctl set_param fail_loc=0
4563 # OBD_FAIL_MDS_ALL_REPLY_NET
4565 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4567 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4571 drop_reint_reply() {
4572 # OBD_FAIL_MDS_REINT_NET_REP
4574 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4576 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4580 drop_update_reply() {
4581 # OBD_FAIL_OUT_UPDATE_NET_REP
4585 do_facet mds${index} lctl set_param fail_loc=0x1701
4586 do_facet client "$@" || RC=$?
4587 do_facet mds${index} lctl set_param fail_loc=0
4592 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4595 local timeout=${2:-0}
4596 # default is (obd_timeout / 4) if unspecified
4597 echo "timeout is $timeout/$2"
4598 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4599 do_facet client "$1" || RC=$?
4600 do_facet client "sync"
4601 do_facet ost1 lctl set_param fail_loc=0
4605 drop_ldlm_cancel() {
4606 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4608 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4609 do_nodes $list lctl set_param fail_loc=0x304
4611 do_facet client "$@" || RC=$?
4613 do_nodes $list lctl set_param fail_loc=0
4617 drop_bl_callback_once() {
4619 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4620 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4621 do_facet client lctl set_param fail_loc=0x80000305
4622 do_facet client "$@" || rc=$?
4623 do_facet client lctl set_param fail_loc=0
4624 do_facet client lctl set_param fail_val=0
4625 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4629 drop_bl_callback() {
4631 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4632 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4633 do_facet client lctl set_param fail_loc=0x305
4634 do_facet client "$@" || rc=$?
4635 do_facet client lctl set_param fail_loc=0
4636 do_facet client lctl set_param fail_val=0
4637 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4642 #define OBD_FAIL_LDLM_REPLY 0x30c
4644 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4645 do_nodes $list lctl set_param fail_loc=0x30c
4647 do_facet client "$@" || RC=$?
4649 do_nodes $list lctl set_param fail_loc=0
4653 drop_ldlm_reply_once() {
4654 #define OBD_FAIL_LDLM_REPLY 0x30c
4656 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4657 do_nodes $list lctl set_param fail_loc=0x8000030c
4659 do_facet client "$@" || RC=$?
4661 do_nodes $list lctl set_param fail_loc=0
4669 echo "clearing fail_loc on $facet"
4670 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4673 set_nodes_failloc () {
4675 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4678 cancel_lru_locks() {
4679 #$LCTL mark "cancel_lru_locks $1 start"
4680 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4681 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4682 #$LCTL mark "cancel_lru_locks $1 stop"
4687 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4688 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4689 echo "$DEFAULT_LRU_SIZE"
4694 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4697 lru_resize_disable()
4699 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4705 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4711 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4712 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4713 echo there is still data in page cache $FILE ?
4714 lctl get_param -n $FILE
4722 DEBUGSAVE="$(lctl get_param -n debug)"
4723 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4727 [ -n "$DEBUGSAVE" ] &&
4728 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4732 [ -n "$DEBUGSAVE_SERVER" ] &&
4733 do_nodes $(comma_list $(all_server_nodes)) \
4734 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4740 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4743 debug_size_restore() {
4744 [ -n "$DEBUG_SIZE_SAVED" ] && \
4745 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4749 start_full_debug_logging() {
4754 local DEBUG_SIZE=150
4756 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4757 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4760 stop_full_debug_logging() {
4765 # prints bash call stack
4766 print_stack_trace() {
4769 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4770 local src=${BASH_SOURCE[$i]}
4771 local lineno=${BASH_LINENO[$i-1]}
4772 local funcname=${FUNCNAME[$i]}
4773 echo " = $src:$lineno:$funcname()"
4778 local TYPE=${TYPE:-"FAIL"}
4781 # do not dump logs if $1=false
4782 if [ "x$1" = "xfalse" ]; then
4787 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4788 (print_stack_trace 2) >&2
4790 # We need to dump the logs on all nodes
4792 gather_logs $(comma_list $(nodes_list))
4796 [ "$TESTSUITELOG" ] &&
4797 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4798 if [ -z "$*" ]; then
4799 echo "error() without useful message, please fix" > $LOGDIR/err
4801 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4802 echo "$@" > $LOGDIR/ignore
4804 echo "$@" > $LOGDIR/err
4808 # cleanup the env for failed tests
4812 ##################################
4814 ##################################
4822 local log=$TESTSUITELOG
4824 [ -f "$log" ] && grep -q FAIL $log && status=1
4838 # use only if we are ignoring failures for this test, bugno required.
4839 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4840 # e.g. error_ignore bz5494 "your message" or
4841 # error_ignore LU-5494 "your message"
4843 local TYPE="IGNORE ($1)"
4848 error_and_remount() {
4850 remount_client $MOUNT
4854 # Throw an error if it's not running in vm - usually for performance
4857 local virt=$(running_in_vm)
4858 if [[ -n "$virt" ]]; then
4859 echo "running in VM '$virt', ignore error"
4860 error_ignore env=$virt "$@"
4867 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4872 log " SKIP: $TESTSUITE $TESTNAME $@"
4874 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4875 skip_logged $TESTNAME "$@"
4878 echo "$@" > $LOGDIR/skip
4881 [[ -n "$TESTSUITELOG" ]] &&
4882 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4885 build_test_filter() {
4886 EXCEPT="$EXCEPT $(testslist_filter)"
4889 if [[ $O = [0-9]*-[0-9]* ]]; then
4890 for num in $(seq $(echo $O | tr '-' ' ')); do
4898 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4899 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4900 [ "$EXCEPT_SLOW" ] && \
4901 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4902 for E in $EXCEPT; do
4903 eval EXCEPT_${E}=true
4905 for E in $ALWAYS_EXCEPT; do
4906 eval EXCEPT_ALWAYS_${E}=true
4908 for E in $EXCEPT_SLOW; do
4909 eval EXCEPT_SLOW_${E}=true
4911 for G in $GRANT_CHECK_LIST; do
4912 eval GCHECK_ONLY_${G}=true
4917 if [[ $1 = [a-z]* ]]; then
4924 # print a newline if the last test was skipped
4925 export LAST_SKIPPED=
4926 export ALWAYS_SKIPPED=
4928 # Main entry into test-framework. This is called with the name and
4929 # description of a test. The name is used to find the function to run
4930 # the test using "test_$name".
4932 # This supports a variety of methods of specifying specific test to
4933 # run or not run. These need to be documented...
4938 export base=$(basetest $1)
4939 if [ -n "$ONLY" ]; then
4941 if [ ${!testname}x != x ]; then
4942 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4943 run_one_logged $1 "$2"
4947 if [ ${!testname}x != x ]; then
4948 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4949 run_one_logged $1 "$2"
4959 if [ ${!testname}x != x ]; then
4960 TESTNAME=test_$1 skip "skipping excluded test $1"
4963 testname=EXCEPT_$base
4964 if [ ${!testname}x != x ]; then
4965 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4968 testname=EXCEPT_ALWAYS_$1
4969 if [ ${!testname}x != x ]; then
4970 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4973 testname=EXCEPT_ALWAYS_$base
4974 if [ ${!testname}x != x ]; then
4975 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4978 testname=EXCEPT_SLOW_$1
4979 if [ ${!testname}x != x ]; then
4980 TESTNAME=test_$1 skip "skipping SLOW test $1"
4983 testname=EXCEPT_SLOW_$base
4984 if [ ${!testname}x != x ]; then
4985 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4991 run_one_logged $1 "$2"
4998 load_module ../libcfs/libcfs/libcfs
5010 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5015 strace -o $TMP/$1.strace -ttt $*
5017 log "FINISHED: $*: rc $RC"
5024 banner test complete, duration $duration sec
5025 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5026 echo duration $duration >>$TESTSUITELOG
5030 # Set TEST_STATUS here. It will be used for logging the result.
5033 if [[ -f $LOGDIR/err ]]; then
5035 elif [[ -f $LOGDIR/skip ]]; then
5038 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5042 local FFREE=$(do_node $SINGLEMDS \
5043 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5044 local FTOTAL=$(do_node $SINGLEMDS \
5045 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5047 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5051 echo -n "Resetting fail_loc on all nodes..."
5052 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5053 fail_val=0 2>/dev/null" || true
5059 # Log a message (on all nodes) padded with "=" before and after.
5060 # Also appends a timestamp and prepends the testsuite name.
5063 EQUALS="===================================================================================================="
5065 msg="== ${TESTSUITE} $*"
5067 [[ $last != "=" && $last != " " ]] && msg="$msg "
5068 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5069 # always include at least == after the message
5070 log "$msg== $(date +"%H:%M:%S (%s)")"
5073 check_dmesg_for_errors() {
5075 local errors="VFS: Busy inodes after unmount of\|\
5076 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5077 group descriptors corrupted"
5079 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5080 [ -z "$res" ] && return 0
5081 echo "Kernel error detected: $res"
5086 # Run a single test function and cleanup after it.
5088 # This function should be run in a subshell so the test func can
5089 # exit() without stopping the whole script.
5094 export tfile=f${testnum}.${TESTSUITE}
5095 export tdir=d${testnum}.${TESTSUITE}
5096 export TESTNAME=test_$testnum
5097 local SAVE_UMASK=`umask`
5100 if ! grep -q $DIR /proc/mounts; then
5104 banner "test $testnum: $message"
5105 test_${testnum} || error "test_$testnum failed with $?"
5108 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5110 check_dmesg_for_errors || error "Error in dmesg detected"
5111 if [ "$PARALLEL" != "yes" ]; then
5112 ps auxww | grep -v grep | grep -q multiop &&
5113 error "multiop still running"
5124 # Wrapper around run_one to ensure:
5125 # - test runs in subshell
5126 # - output of test is saved to separate log file for error reporting
5127 # - test result is saved to data file
5130 local BEFORE=$(date +%s)
5132 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5133 local test_log=$LOGDIR/$name
5134 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5135 local zfs_debug_log=$LOGDIR/$zfs_log_name
5137 rm -rf $LOGDIR/ignore
5139 local SAVE_UMASK=$(umask)
5143 log_sub_test_begin test_${1}
5144 (run_one $1 "$2") 2>&1 | tee -i $test_log
5145 local RC=${PIPESTATUS[0]}
5147 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5148 echo "test_$1 returned $RC" | tee $LOGDIR/err
5150 duration=$(($(date +%s) - $BEFORE))
5151 pass "$1" "(${duration}s)"
5153 if [[ -f $LOGDIR/err ]]; then
5154 TEST_ERROR=$(cat $LOGDIR/err)
5155 elif [[ -f $LOGDIR/ignore ]]; then
5156 TEST_ERROR=$(cat $LOGDIR/ignore)
5157 elif [[ -f $LOGDIR/skip ]]; then
5158 TEST_ERROR=$(cat $LOGDIR/skip)
5160 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5162 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5166 if [ -f $LOGDIR/err ]; then
5167 log_zfs_info "$zfs_debug_log"
5168 $FAIL_ON_ERROR && exit $RC
5177 # Print information of skipped tests to result.yml
5180 log_sub_test_begin $1
5182 log_sub_test_end "SKIP" "0" "0" "$@"
5186 (cd $(dirname $1); echo $PWD/$(basename $1))
5191 export base=$(basetest $1)
5192 [ "$CHECK_GRANT" == "no" ] && return 0
5194 testname=GCHECK_ONLY_${base}
5195 [ ${!testname}x == x ] && return 0
5197 echo -n "checking grant......"
5199 local clients=$CLIENTS
5200 [ -z "$clients" ] && clients=$(hostname)
5202 # sync all the data and make sure no pending data on server
5203 do_nodes $clients sync
5206 client_grant=$(do_nodes $clients \
5207 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5208 awk '{ total += $1 } END { printf("%0.0f", total) }')
5211 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5212 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5213 awk '{ total += $1 } END { printf("%0.0f", total) }')
5215 # check whether client grant == server grant
5216 if [[ $client_grant -ne $server_grant ]]; then
5217 echo "failed: client:${client_grant} server: ${server_grant}."
5218 do_nodes $(comma_list $(osts_nodes)) \
5219 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5220 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5223 echo "pass: client:${client_grant} server: ${server_grant}"
5227 ########################
5233 ost=`echo $1 | awk -F_ '{print $3}'`
5234 if [ -z $ost ]; then
5235 ost=`echo $1 | sed 's/-osc.*//'`
5240 ostuuid_from_index()
5242 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5245 ostname_from_index() {
5246 local uuid=$(ostuuid_from_index $1)
5250 index_from_ostuuid()
5252 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5255 mdtuuid_from_index()
5257 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5261 # Return unique identifier for given hostname
5264 echo $host_name | md5sum | cut -d' ' -f1
5268 # Returns list of ip addresses for each interface
5270 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5275 # Cache address list to avoid mutiple execution of local_addr_list
5276 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5278 for i in $LOCAL_ADDR_LIST ; do
5279 [[ "$i" == "$addr" ]] && return 0
5286 local is_local="IS_LOCAL_$(host_id $host_name)"
5287 if [ -z "${!is_local-}" ] ; then
5289 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5290 is_local_addr "$host_ip" && eval $is_local=1
5292 [[ "${!is_local}" == "1" ]]
5297 local_node $node && return 1
5304 for node in $(mdts_nodes); do
5305 remote_node $node && return 0
5312 [ -n "$CLIENTONLY" ] && return 0 || true
5313 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5318 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5319 MSKIPPED=1 && return 1
5326 for node in $(osts_nodes) ; do
5327 remote_node $node && return 0
5334 [ -n "$CLIENTONLY" ] && return 0 || true
5335 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5340 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5341 OSKIPPED=1 && return 1
5347 [ -n "$CLIENTONLY" ] && return 0 || true
5349 MGS=$(facet_host mgs)
5350 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5355 remote_mds_nodsh || remote_ost_nodsh || \
5356 $(single_local_node $(comma_list $(nodes_list)))
5360 remote_ost && remote_mds
5363 # Get the active nodes for facets.
5371 for facet in ${facets//,/ }; do
5372 nodes="$nodes $(facet_active_host $facet)"
5375 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5379 # Get all of the active MDS nodes.
5381 echo -n $(facets_nodes $(get_facets MDS))
5384 # Get all of the active OSS nodes.
5386 echo -n $(facets_nodes $(get_facets OST))
5389 # Get all of the active AGT (HSM agent) nodes.
5391 echo -n $(facets_nodes $(get_facets AGT))
5394 # Get all of the client nodes and active server nodes.
5396 local nodes=$HOSTNAME
5400 # CLIENTS (if specified) contains the local client
5401 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5403 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5404 nodes="$nodes $(facets_nodes $(get_facets))"
5407 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5411 # Get all of the remote client nodes and remote active server nodes.
5412 remote_nodes_list () {
5413 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5416 # Get all of the MDS nodes, including active and passive nodes.
5424 for i in $(seq $MDSCOUNT); do
5426 failover_host=mds${i}failover_HOST
5427 nodes="$nodes ${!host} ${!failover_host}"
5430 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5434 # Get all of the OSS nodes, including active and passive nodes.
5442 for i in $(seq $OSTCOUNT); do
5444 failover_host=ost${i}failover_HOST
5445 nodes="$nodes ${!host} ${!failover_host}"
5448 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5452 # Get all of the server nodes, including active and passive nodes.
5453 all_server_nodes () {
5458 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5460 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5464 # Get all of the client and server nodes, including active and passive nodes.
5466 local nodes=$HOSTNAME
5470 # CLIENTS (if specified) contains the local client
5471 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5473 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5474 nodes="$nodes $(all_server_nodes)"
5477 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5481 init_clients_lists () {
5482 # Sanity check: exclude the local client from RCLIENTS
5483 local clients=$(hostlist_expand "$RCLIENTS")
5484 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5486 # Sanity check: exclude the dup entries
5487 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5489 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5491 # Sanity check: exclude the dup entries from CLIENTS
5492 # for those configs which has SINGLCLIENT set to local client
5493 clients=$(for i in $clients; do echo $i; done | sort -u)
5495 CLIENTS=$(comma_list $clients)
5496 local -a remoteclients=($RCLIENTS)
5497 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5498 varname=CLIENT$((i + 2))
5499 eval $varname=${remoteclients[i]}
5502 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5505 get_random_entry () {
5508 rnodes=${rnodes//,/ }
5510 local -a nodes=($rnodes)
5511 local num=${#nodes[@]}
5512 local i=$((RANDOM * num * 2 / 65536))
5518 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5522 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5523 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5528 echo $nodes | wc -w || true
5532 local nodes=$(osts_nodes)
5533 local osscount=$(get_node_count "$nodes")
5534 [ ! "$OSTCOUNT" = "$osscount" ]
5538 local nodes=$(mdts_nodes)
5539 local mdtcount=$(get_node_count "$nodes")
5540 [ ! "$MDSCOUNT" = "$mdtcount" ]
5543 generate_machine_file() {
5544 local nodes=${1//,/ }
5545 local machinefile=$2
5547 for node in $nodes; do
5548 echo $node >>$machinefile || \
5549 { echo "can not generate machinefile $machinefile" && return 1; }
5554 local file=$1/stripe
5557 $LFS getstripe -v $file || error "getstripe $file failed"
5561 setstripe_nfsserver () {
5564 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5565 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5567 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5569 do_nodev $nfsserver lfs setstripe "$@"
5572 # Check and add a test group.
5578 local gid=$(getent group $group_name | cut -d: -f3)
5579 if [[ -n "$gid" ]]; then
5580 [[ "$gid" -eq "$group_id" ]] || {
5581 error_noexit "inconsistent group ID:" \
5582 "new: $group_id, old: $gid"
5586 groupadd -g $group_id $group_name
5593 # Check and add a test user.
5606 local uid=$(getent passwd $user_name | cut -d: -f3)
5607 if [[ -n "$uid" ]]; then
5608 if [[ "$uid" -eq "$user_id" ]]; then
5609 local dir=$(getent passwd $user_name | cut -d: -f6)
5610 if [[ "$dir" != "$home" ]]; then
5612 usermod -d $home $user_name
5616 error_noexit "inconsistent user ID:" \
5617 "new: $user_id, old: $uid"
5622 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5629 check_runas_id_ret() {
5631 local myRUNAS_UID=$1
5632 local myRUNAS_GID=$2
5635 if [ -z "$myRUNAS" ]; then
5636 error_exit "myRUNAS command must be specified for check_runas_id"
5639 $myRUNAS krb5_login.sh || \
5640 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5642 mkdir $DIR/d0_runas_test
5644 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5645 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5646 rm -rf $DIR/d0_runas_test
5651 local myRUNAS_UID=$1
5652 local myRUNAS_GID=$2
5655 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5656 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5657 Please set RUNAS_ID to some UID which exists on MDS and client or
5658 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5661 # obtain the UID/GID for MPI_USER
5665 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5666 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5668 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5669 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5672 # obtain and cache Kerberos ticket-granting ticket
5673 refresh_krb5_tgt() {
5674 local myRUNAS_UID=$1
5675 local myRUNAS_GID=$2
5678 if [ -z "$myRUNAS" ]; then
5679 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5682 CLIENTS=${CLIENTS:-$HOSTNAME}
5683 do_nodes $CLIENTS "set -x
5684 if ! $myRUNAS krb5_login.sh; then
5685 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5690 # Run multiop in the background, but wait for it to print
5691 # "PAUSING" to its stdout before returning from this function.
5692 multiop_bg_pause() {
5693 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5697 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5700 echo "$MULTIOP_PROG $FILE v$ARGS"
5701 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5703 echo "TMPPIPE=${TMPPIPE}"
5704 read -t 60 multiop_output < $TMPPIPE
5705 if [ $? -ne 0 ]; then
5710 if [ "$multiop_output" != "PAUSING" ]; then
5711 echo "Incorrect multiop output: $multiop_output"
5726 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5732 inodes_available () {
5733 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5734 sort -un | head -n1) || return 1
5738 mdsrate_inodes_available () {
5739 local min_inodes=$(inodes_available)
5740 echo $((min_inodes * 99 / 100))
5743 # reset llite stat counters
5744 clear_llite_stats(){
5745 lctl set_param -n llite.*.stats 0
5748 # sum llite stat items
5749 calc_llite_stats() {
5750 local res=$(lctl get_param -n llite.*.stats |
5751 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5755 # reset osc stat counters
5757 lctl set_param -n osc.*.osc_stats 0
5760 # sum osc stat items
5762 local res=$(lctl get_param -n osc.*.osc_stats |
5763 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5768 awk '{sum += $1} END { printf("%0.0f", sum) }'
5771 calc_osc_kbytes () {
5772 df $MOUNT > /dev/null
5773 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5776 # save_lustre_params(comma separated facet list, parameter_mask)
5777 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5778 save_lustre_params() {
5784 for facet in ${facets//,/ }; do
5785 node=$(facet_active_host $facet)
5786 [[ *\ $node\ * = " $nodes " ]] && continue
5787 nodes="$nodes $node"
5789 do_node $node "$LCTL get_param $2 |
5790 while read s; do echo $facet \\\$s; done"
5794 # restore lustre parameters from input stream, produces by save_lustre_params
5795 restore_lustre_params() {
5800 while IFS=" =" read facet name val; do
5801 do_facet $facet "$LCTL set_param -n $name $val"
5805 check_node_health() {
5806 local nodes=${1:-$(comma_list $(nodes_list))}
5808 for node in ${nodes//,/ }; do
5809 check_network "$node" 5
5810 if [ $? -eq 0 ]; then
5811 do_node $node "rc=0;
5812 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5813 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5814 echo \\\$(hostname -s): \\\$val;
5817 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5822 mdsrate_cleanup () {
5824 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5825 --nfiles $3 --dir $4 --filefmt $5 $6
5830 delayed_recovery_enabled () {
5831 local var=${SINGLEMDS}_svc
5832 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5835 ########################
5837 convert_facet2label() {
5840 if [ x$facet = xost ]; then
5844 local varsvc=${facet}_svc
5846 if [ -n ${!varsvc} ]; then
5849 error "No lablel for $facet!"
5853 get_clientosc_proc_path() {
5857 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5858 # used by MDT would not be changed.
5859 # mdt lov: fsname-mdtlov
5860 # mdt osc: fsname-OSTXXXX-osc
5861 mds_on_old_device() {
5862 local mds=${1:-"$SINGLEMDS"}
5864 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5865 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5866 > /dev/null 2>&1" && return 0
5871 get_mdtosc_proc_path() {
5873 local ost_label=${2:-"*OST*"}
5875 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5876 local mdt_label=$(convert_facet2label $mds_facet)
5877 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5879 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5880 mds_on_old_device $mds_facet; then
5881 echo "${ost_label}-osc"
5882 elif [[ $ost_label = *OST* ]]; then
5883 echo "${ost_label}-osc-${mdt_index}"
5885 echo "${ost_label}-osp-${mdt_index}"
5889 get_osc_import_name() {
5892 local label=$(convert_facet2label $ost)
5894 if [ "${facet:0:3}" = "mds" ]; then
5895 get_mdtosc_proc_path $facet $label
5899 get_clientosc_proc_path $label
5903 _wait_import_state () {
5906 local maxtime=${3:-$(max_recovery_time)}
5907 local error_on_failure=${4:-1}
5911 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5912 while [ "${CONN_STATE}" != "${expected}" ]; do
5913 if [ "${expected}" == "DISCONN" ]; then
5914 # for disconn we can check after proc entry is removed
5915 [ "x${CONN_STATE}" == "x" ] && return 0
5916 # with AT enabled, we can have connect request timeout near of
5917 # reconnect timeout and test can't see real disconnect
5918 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5920 if [ $i -ge $maxtime ]; then
5921 [ $error_on_failure -ne 0 ] && \
5922 error "can't put import for $CONN_PROC into ${expected}" \
5923 "state after $i sec, have ${CONN_STATE}"
5927 # Add uniq for multi-mount case
5928 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5932 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5936 wait_import_state() {
5939 local maxtime=${3:-$(max_recovery_time)}
5940 local error_on_failure=${4:-1}
5943 for param in ${params//,/ }; do
5944 _wait_import_state $state $param $maxtime $error_on_failure || return
5948 wait_import_state_mount() {
5949 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5953 wait_import_state $*
5956 # One client request could be timed out because server was not ready
5957 # when request was sent by client.
5958 # The request timeout calculation details :
5960 # /* We give the server rq_timeout secs to process the req, and
5961 # add the network latency for our local timeout. */
5962 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5963 # ptlrpc_at_get_net_latency(request) ;
5965 # ptlrpc_connect_import ()
5966 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5969 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5970 # ptlrpc_at_get_net_latency(request) ->
5971 # at_get (max (iat_net_latency=0, at_min)) = at_min
5974 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5975 # INITIAL_CONNECT_TIMEOUT + at_min
5977 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5978 # because we can not get this value in runtime,
5979 # the value depends on configure options, and it is not stored in /proc.
5981 # #define CONNECTION_SWITCH_MIN 5U
5982 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5984 request_timeout () {
5987 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5988 local init_connect_timeout=$TIMEOUT
5989 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5991 local at_min=$(at_get $facet at_min)
5993 echo $(( init_connect_timeout + at_min ))
5996 _wait_osc_import_state() {
6000 local target=$(get_osc_import_name $facet $ost_facet)
6001 local param="osc.${target}.ost_server_uuid"
6005 # 1. wait the deadline of client 1st request (it could be skipped)
6006 # 2. wait the deadline of client 2nd request
6007 local maxtime=$(( 2 * $(request_timeout $facet)))
6009 if [[ $facet == client* ]]; then
6010 # During setup time, the osc might not be setup, it need wait
6011 # until list_param can return valid value. And also if there
6012 # are mulitple osc entries we should list all of them before
6014 params=$($LCTL list_param $param 2>/dev/null || true)
6015 while [ -z "$params" ]; do
6016 if [ $i -ge $maxtime ]; then
6017 echo "can't get $param in $maxtime secs"
6022 params=$($LCTL list_param $param 2>/dev/null || true)
6026 if [[ $ost_facet = mds* ]]; then
6027 # no OSP connection to itself
6028 if [[ $facet = $ost_facet ]]; then
6031 param="osp.${target}.mdt_server_uuid"
6035 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6036 wait_import_state $expected "$params" $maxtime; then
6037 error "import is not in ${expected} state"
6044 wait_osc_import_state() {
6050 if [[ $facet = mds ]]; then
6051 for num in $(seq $MDSCOUNT); do
6052 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6055 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6059 _wait_mgc_import_state() {
6062 local error_on_failure=${3:-1}
6063 local param="mgc.*.mgs_server_uuid"
6067 # 1. wait the deadline of client 1st request (it could be skipped)
6068 # 2. wait the deadline of client 2nd request
6069 local maxtime=$(( 2 * $(request_timeout $facet)))
6071 if [[ $facet == client* ]]; then
6072 # During setup time, the osc might not be setup, it need wait
6073 # until list_param can return valid value. And also if there
6074 # are mulitple osc entries we should list all of them before
6076 params=$($LCTL list_param $param 2>/dev/null || true)
6077 while [ -z "$params" ]; do
6078 if [ $i -ge $maxtime ]; then
6079 echo "can't get $param in $maxtime secs"
6084 params=$($LCTL list_param $param 2>/dev/null || true)
6087 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6088 wait_import_state $expected "$params" $maxtime \
6089 $error_on_failure; then
6090 if [ $error_on_failure -ne 0 ]; then
6091 error "import is not in ${expected} state"
6099 wait_mgc_import_state() {
6102 local error_on_failure=${3:-1}
6105 if [[ $facet = mds ]]; then
6106 for num in $(seq $MDSCOUNT); do
6107 _wait_mgc_import_state mds$num "$expected" \
6108 $error_on_failure || return
6111 _wait_mgc_import_state "$facet" "$expected"
6112 $error_on_failure || return
6116 wait_dne_interconnect() {
6119 if [ $MDSCOUNT -gt 1 ]; then
6120 for num in $(seq $MDSCOUNT); do
6121 wait_osc_import_state mds mds$num FULL
6126 get_clientmdc_proc_path() {
6130 get_clientmgc_proc_path() {
6138 [ -z "$list" ] && return 0
6140 # Add paths to lustre tests for 32 and 64 bit systems.
6141 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6142 local TESTPATH="$RLUSTRE/tests:"
6143 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6144 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6147 wait_clients_import_state () {
6154 if [ "$FAILURE_MODE" = HARD ]; then
6155 facets=$(facets_on_host $(facet_active_host $facet))
6158 for facet in ${facets//,/ }; do
6159 local label=$(convert_facet2label $facet)
6162 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6163 $label).ost_server_uuid" ;;
6164 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6165 $label).mds_server_uuid" ;;
6166 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6167 $label).mgs_server_uuid" ;;
6168 *) error "unknown facet!" ;;
6171 local params=$(expand_list $params $proc_path)
6174 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6176 error "import is not in ${expected} state"
6186 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6187 $LCTL get_param obdfilter.*.kbytesavail))
6188 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6189 $LCTL get_param -n obdfilter.*.tot_granted))
6190 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6191 $LCTL get_param -n obdfilter.*.kbytestotal))
6192 for ((i=0; i<${#AVAILA[@]}; i++)); do
6193 local -a AVAIL1=(${AVAILA[$i]//=/ })
6194 local -a TOTAL=(${TOTALA[$i]//=/ })
6195 GRANT=$((${GRANTA[$i]}/1024))
6196 # allow 1% of total space in bavail because of delayed
6197 # allocation with ZFS which might release some free space after
6198 # txg commit. For small devices, we set a mininum of 8MB
6199 local LIMIT=$((${TOTAL} / 100 + 8000))
6200 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6201 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6202 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6203 echo " FULL" || echo
6209 do_facet mgs lctl pool_list $1
6213 local fsname=${1%%.*}
6214 local poolname=${1##$fsname.}
6216 do_facet mgs lctl pool_new $1
6218 # get param should return err unless pool is created
6219 [[ $RC -ne 0 ]] && return $RC
6221 for mds_id in $(seq $MDSCOUNT); do
6222 local mdt_id=$((mds_id-1))
6223 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6224 wait_update_facet mds$mds_id \
6225 "lctl get_param -n lod.$lodname.pools.$poolname \
6226 2>/dev/null || echo foo" "" ||
6227 error "mds$mds_id: pool_new failed $1"
6229 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6230 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6236 add_pool_to_list () {
6237 local fsname=${1%%.*}
6238 local poolname=${1##$fsname.}
6240 local listvar=${fsname}_CREATED_POOLS
6241 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6245 remove_pool_from_list () {
6246 local fsname=${1%%.*}
6247 local poolname=${1##$fsname.}
6249 local listvar=${fsname}_CREATED_POOLS
6250 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6254 destroy_pool_int() {
6256 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6257 awk '$1 !~ /^Pool:/ {print $1}')
6258 for ost in $OSTS; do
6259 do_facet mgs lctl pool_remove $1 $ost
6261 do_facet mgs lctl pool_destroy $1
6264 # <fsname>.<poolname> or <poolname>
6266 local fsname=${1%%.*}
6267 local poolname=${1##$fsname.}
6269 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6273 pool_list $fsname.$poolname || return $?
6275 destroy_pool_int $fsname.$poolname
6277 [[ $RC -ne 0 ]] && return $RC
6278 for mds_id in $(seq $MDSCOUNT); do
6279 local mdt_id=$((mds_id-1))
6280 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6281 wait_update_facet mds$mds_id \
6282 "lctl get_param -n lod.$lodname.pools.$poolname \
6283 2>/dev/null || echo foo" "foo" ||
6284 error "mds$mds_id: destroy pool failed $1"
6286 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6287 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6289 remove_pool_from_list $fsname.$poolname
6294 local fsname=${1:-$FSNAME}
6296 local listvar=${fsname}_CREATED_POOLS
6300 [ x${!listvar} = x ] && return 0
6302 echo destroy the created pools: ${!listvar}
6303 for poolname in ${!listvar//,/ }; do
6304 destroy_pool $fsname.$poolname
6309 local fsname=${1:-$FSNAME}
6311 destroy_pools $fsname
6317 local ts=$(date +%s)
6320 if [[ ! -f "$YAML_LOG" ]]; then
6321 # init_logging is not performed before gather_logs,
6322 # so the $LOGDIR needs to be checked here
6323 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6326 [ -f $LOGDIR/shared ] && docp=false
6328 # dump lustre logs, dmesg
6330 prefix="$TESTLOG_PREFIX.$TESTNAME"
6332 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6334 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6335 echo "Dumping logs only on local client."
6336 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6337 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6342 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6343 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6344 if [ ! -f $LOGDIR/shared ]; then
6345 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6358 for i in $(seq 0 $num_mntpts); do
6359 cmd="ls -laf ${mntpt_root}$i/$dir"
6365 for pid in $pids; do
6372 # check_and_start_recovery_timer()
6373 # service_time = at_est2timeout(service_time);
6374 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6375 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6377 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6378 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6379 #define CONNECTION_SWITCH_MIN 5
6380 #define CONNECTION_SWITCH_INC 5
6381 max_recovery_time() {
6382 local init_connect_timeout=$((TIMEOUT / 20))
6383 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6385 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6386 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6388 echo -n $service_time
6391 recovery_time_min() {
6392 local connection_switch_min=5
6393 local connection_switch_inc=5
6394 local connection_switch_max
6395 local reconnect_delay_max
6396 local initial_connect_timeout
6400 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6401 (($connection_switch_min > $TIMEOUT)) &&
6402 max=$connection_switch_min || max=$TIMEOUT
6403 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6405 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6406 timeout_20=$((TIMEOUT/20))
6407 (($connection_switch_min > $timeout_20)) &&
6408 initial_connect_timeout=$connection_switch_min ||
6409 initial_connect_timeout=$timeout_20
6411 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6412 initial_connect_timeout))
6413 echo $((2 * reconnect_delay_max))
6416 get_clients_mount_count () {
6417 local clients=${CLIENTS:-`hostname`}
6419 # we need to take into account the clients mounts and
6420 # exclude mds/ost mounts if any;
6421 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6425 PROC_CLI="srpc_info"
6433 if [ $M -lt $N ]; then
6437 while [ $N -lt $M ]; do
6447 calc_connection_cnt() {
6450 # MDT->MDT = 2 * C(M, 2)
6454 comb_m2=$(combination $MDSCOUNT 2)
6456 local num_clients=$(get_clients_mount_count)
6458 local cnt_mdt2mdt=$((comb_m2 * 2))
6459 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6460 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6461 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6462 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6463 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6464 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6478 local cmd="$tgt.srpc.flavor"
6480 if [ $net == "any" ]; then
6485 if [ $dir != "any" ]; then
6490 log "Setting sptlrpc rule: $cmd"
6491 do_facet mgs "$LCTL conf_param $cmd"
6500 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6501 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6503 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6505 if [ "x$bulkspec" != "x" ]; then
6506 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6508 if [ "x$algs" != "x" ]; then
6509 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6511 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6512 if [ $bulk == "bulkn" ]; then
6513 bulk_count=`echo "$output" | grep "bulk flavor" \
6514 | grep "null/null" | wc -l`
6515 elif [ $bulk == "bulki" ]; then
6516 bulk_count=`echo "$output" | grep "bulk flavor" \
6517 | grep "/null" | grep -v "null/" | wc -l`
6519 bulk_count=`echo "$output" | grep "bulk flavor" \
6520 | grep -v "/null" | grep -v "null/" | wc -l`
6524 [ $bulk_count -lt $count ] && count=$bulk_count
6535 local clients=${CLIENTS:-`hostname`}
6537 for c in ${clients//,/ }; do
6538 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6539 tmpcnt=`count_flvr "$output" $flavor`
6540 cnt=$((cnt + tmpcnt))
6550 local clients=${CLIENTS:-`hostname`}
6552 for c in ${clients//,/ }; do
6553 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6554 tmpcnt=`count_flvr "$output" $flavor`
6555 cnt=$((cnt + tmpcnt))
6565 if [ $MDSCOUNT -le 1 ]; then
6570 for num in `seq $MDSCOUNT`; do
6571 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6572 tmpcnt=`count_flvr "$output" $flavor`
6573 cnt=$((cnt + tmpcnt))
6584 for num in `seq $MDSCOUNT`; do
6585 mdtosc=$(get_mdtosc_proc_path mds$num)
6586 mdtosc=${mdtosc/-MDT*/-MDT\*}
6587 output=$(do_facet mds$num lctl get_param -n \
6588 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6589 tmpcnt=`count_flvr "$output" $flavor`
6590 cnt=$((cnt + tmpcnt))
6599 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6600 count_flvr "$output" $flavor
6605 local dir=$1 # from to
6606 local flavor=$2 # flavor expected
6609 if [ $dir == "cli2mdt" ]; then
6610 res=`flvr_cnt_cli2mdt $flavor`
6611 elif [ $dir == "cli2ost" ]; then
6612 res=`flvr_cnt_cli2ost $flavor`
6613 elif [ $dir == "mdt2mdt" ]; then
6614 res=`flvr_cnt_mdt2mdt $flavor`
6615 elif [ $dir == "mdt2ost" ]; then
6616 res=`flvr_cnt_mdt2ost $flavor`
6617 elif [ $dir == "all2ost" ]; then
6618 res1=`flvr_cnt_mdt2ost $flavor`
6619 res2=`flvr_cnt_cli2ost $flavor`
6620 res=$((res1 + res2))
6621 elif [ $dir == "all2mdt" ]; then
6622 res1=`flvr_cnt_mdt2mdt $flavor`
6623 res2=`flvr_cnt_cli2mdt $flavor`
6624 res=$((res1 + res2))
6625 elif [ $dir == "all2all" ]; then
6626 res1=`flvr_cnt_mdt2ost $flavor`
6627 res2=`flvr_cnt_cli2ost $flavor`
6628 res3=`flvr_cnt_mdt2mdt $flavor`
6629 res4=`flvr_cnt_cli2mdt $flavor`
6630 res=$((res1 + res2 + res3 + res4))
6638 local dir=$1 # from to
6639 local flavor=$2 # flavor expected
6640 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6644 for ((i=0;i<20;i++)); do
6645 echo -n "checking $dir..."
6646 res=$(do_check_flavor $dir $flavor)
6647 echo "found $res/$expect $flavor connections"
6648 [ $res -ge $expect ] && return 0
6652 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6656 restore_to_default_flavor()
6658 local proc="mgs.MGS.live.$FSNAME"
6660 echo "restoring to default flavor..."
6662 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6664 # remove all existing rules if any
6665 if [ $nrule -ne 0 ]; then
6666 echo "$nrule existing rules"
6667 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6668 echo "remove rule: $rule"
6669 spec=`echo $rule | awk -F = '{print $1}'`
6670 do_facet mgs "$LCTL conf_param -d $spec"
6674 # verify no rules left
6675 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6676 [ $nrule -ne 0 ] && error "still $nrule rules left"
6678 # wait for default flavor to be applied
6679 # currently default flavor for all connections are 'null'
6680 wait_flavor all2all null
6681 echo "now at default flavor settings"
6686 local flavor=${1:-null}
6688 echo "setting all flavor to $flavor"
6690 # FIXME need parameter to this fn
6691 # and remove global vars
6692 local cnt_all2all=$(calc_connection_cnt all2all)
6694 local res=$(do_check_flavor all2all $flavor)
6695 if [ $res -eq $cnt_all2all ]; then
6696 echo "already have total $res $flavor connections"
6700 echo "found $res $flavor out of total $cnt_all2all connections"
6701 restore_to_default_flavor
6703 [[ $flavor = null ]] && return 0
6705 set_rule $FSNAME any any $flavor
6706 wait_flavor all2all $flavor
6712 # Checking for shared logdir
6713 if [ ! -d $dir ]; then
6714 # Not found. Create local logdir
6717 touch $dir/check_file.$(hostname -s)
6722 check_write_access() {
6724 local list=${2:-$(comma_list $(nodes_list))}
6728 for node in ${list//,/ }; do
6729 file=$dir/check_file.$(short_nodename $node)
6730 if [[ ! -f "$file" ]]; then
6731 # Logdir not accessible/writable from this node.
6734 rm -f $file || return 1
6740 [[ -n $YAML_LOG ]] && return
6741 local save_umask=$(umask)
6744 export YAML_LOG=${LOGDIR}/results.yml
6748 # If the yaml log already exists then we will just append to it
6749 if [ ! -f $YAML_LOG ]; then
6750 if check_shared_dir $LOGDIR; then
6751 touch $LOGDIR/shared
6752 echo "Logging to shared log directory: $LOGDIR"
6754 echo "Logging to local directory: $LOGDIR"
6757 yml_nodes_file $LOGDIR >> $YAML_LOG
6758 yml_results_file >> $YAML_LOG
6763 # If modules are not yet loaded then older "lctl lustre_build_version"
6764 # will fail. Use lctl build version instead.
6765 log "Client: $($LCTL lustre_build_version)"
6766 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6767 do_facet $SINGLEMDS $LCTL --version)"
6768 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6769 do_facet ost1 $LCTL --version)"
6773 yml_log_test $1 >> $YAML_LOG
6777 yml_log_test_status $@ >> $YAML_LOG
6780 log_sub_test_begin() {
6781 yml_log_sub_test_begin "$@" >> $YAML_LOG
6784 log_sub_test_end() {
6785 yml_log_sub_test_end "$@" >> $YAML_LOG
6791 local llverdev_opts=$2
6792 local devname=$(basename $1)
6793 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6794 # loop devices aren't in /proc/partitions
6795 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6797 size=$(($size / 1024 / 1024)) # Gb
6799 local partial_arg=""
6800 # Run in partial (fast) mode if the size
6801 # of a partition > 1 GB
6802 [ $size -gt 1 ] && partial_arg="-p"
6804 llverdev --force $partial_arg $llverdev_opts $dev
6810 local llverfs_opts=$2
6811 local use_partial_arg=$3
6812 local partial_arg=""
6813 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6815 # Run in partial (fast) mode if the size
6816 # of a partition > 1 GB
6817 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6819 llverfs $partial_arg $llverfs_opts $dir
6822 #Remove objects from OST
6823 remove_ost_objects() {
6829 local mntpt=$(facet_mntpt $facet)
6830 local opts=$OST_MOUNT_OPTS
6834 echo "removing objects from $ostdev on $facet: $objids"
6835 if ! test -b $ostdev; then
6836 opts=$(csa_add "$opts" -o loop)
6838 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6841 for i in $objids; do
6842 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6844 umount -f $mntpt || return $?
6848 #Remove files from MDT
6849 remove_mdt_files() {
6854 local mntpt=$(facet_mntpt $facet)
6855 local opts=$MDS_MOUNT_OPTS
6857 echo "removing files from $mdtdev on $facet: $files"
6858 if [ $(facet_fstype $facet) == ldiskfs ] &&
6859 ! do_facet $facet test -b $mdtdev; then
6860 opts=$(csa_add "$opts" -o loop)
6862 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6866 rm $mntpt/ROOT/$f || { rc=$?; break; }
6868 umount -f $mntpt || return $?
6872 duplicate_mdt_files() {
6877 local mntpt=$(facet_mntpt $facet)
6878 local opts=$MDS_MOUNT_OPTS
6880 echo "duplicating files on $mdtdev on $facet: $files"
6881 mkdir -p $mntpt || return $?
6882 if [ $(facet_fstype $facet) == ldiskfs ] &&
6883 ! do_facet $facet test -b $mdtdev; then
6884 opts=$(csa_add "$opts" -o loop)
6886 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6897 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6898 pushd $mntpt/ROOT > /dev/null || return $?
6901 touch $f.bad || return $?
6902 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6904 [ $rc -eq 0 ] || return $rc
6905 setfattr --restore $tmp || return $?
6911 local devs=${1//,/ }
6914 local rslt=$TMP/sgpdd_survey
6916 # sgpdd-survey cleanups ${rslt}.* files
6918 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6924 # returns the canonical name for an ldiskfs device
6929 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6930 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6931 echo dm-\\\${foo##*:};
6933 echo \\\$(basename \\\$dv);
6937 is_sanity_benchmark() {
6938 local benchmarks="dbench bonnie iozone fsx"
6940 for b in $benchmarks; do
6941 if [ "$b" == "$suite" ]; then
6949 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6953 # Get the available size (KB) of a given obd target.
6960 [[ $facet != client ]] || return 0
6962 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6967 # Get the page size (bytes) on a given facet node.
6971 local size=$(getconf PAGE_SIZE 2>/dev/null)
6973 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
6974 echo -n ${size:-4096}
6978 # Get the block count of the filesystem.
6985 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6986 awk '/^Block count:/ {print $3}')
6990 # Get the block size of the filesystem.
6996 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6997 awk '/^Block size:/ {print $3}')
7001 # Check whether the "large_xattr" feature is enabled or not.
7002 large_xattr_enabled() {
7003 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7005 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7007 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7008 grep -E -q '(ea_inode|large_xattr)'"
7009 return ${PIPESTATUS[0]}
7012 # Get the maximum xattr size supported by the filesystem.
7016 if large_xattr_enabled; then
7017 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7020 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7021 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7023 # maximum xattr size = size of block - size of header -
7024 # size of 1 entry - 4 null bytes
7025 size=$((block_size - 32 - 32 - 4))
7031 # Dump the value of the named xattr from a file.
7036 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7039 # Generate a string with size of $size bytes.
7041 local size=${1:-1024} # in bytes
7043 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7046 reformat_external_journal() {
7051 if [ -n "${!var}" ]; then
7052 local rcmd="do_facet $facet"
7054 echo "reformat external journal on $facet:${!var}"
7055 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7059 # MDT file-level backup/restore
7060 mds_backup_restore() {
7063 local devname=$(mdsdevname $(facet_number $facet))
7064 local mntpt=$(facet_mntpt brpt)
7065 local rcmd="do_facet $facet"
7066 local metaea=${TMP}/backup_restore.ea
7067 local metadata=${TMP}/backup_restore.tgz
7068 local opts=${MDS_MOUNT_OPTS}
7069 local svc=${facet}_svc
7071 if ! ${rcmd} test -b ${devname}; then
7072 opts=$(csa_add "$opts" -o loop)
7075 echo "file-level backup/restore on $facet:${devname}"
7077 # step 1: build mount point
7078 ${rcmd} mkdir -p $mntpt
7079 # step 2: cleanup old backup
7080 ${rcmd} rm -f $metaea $metadata
7082 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7083 if [ ! -z $igif ]; then
7084 # step 3.5: rm .lustre
7085 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7087 # step 4: backup metaea
7089 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7091 # step 5: backup metadata
7093 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7095 ${rcmd} $UMOUNT $mntpt || return 4
7096 # step 8: reformat dev
7097 echo "reformat new device"
7098 format_mdt $(facet_number $facet)
7100 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7101 # step 10: restore metadata
7103 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7104 # step 11: restore metaea
7106 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7107 # step 12: remove recovery logs
7108 echo "remove recovery logs"
7109 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7110 # step 13: umount dev
7111 ${rcmd} $UMOUNT $mntpt || return 10
7112 # step 14: cleanup tmp backup
7113 ${rcmd} rm -f $metaea $metadata
7114 # step 15: reset device label - it's not virgin on
7115 ${rcmd} e2label $devname ${!svc}
7122 local devname=$(mdsdevname $(facet_number $facet))
7123 local mntpt=$(facet_mntpt brpt)
7124 local rcmd="do_facet $facet"
7125 local opts=${MDS_MOUNT_OPTS}
7127 if ! ${rcmd} test -b ${devname}; then
7128 opts=$(csa_add "$opts" -o loop)
7131 echo "removing OI files on $facet: idx=${idx}"
7133 # step 1: build mount point
7134 ${rcmd} mkdir -p $mntpt
7136 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7137 if [ -z $idx ]; then
7138 # step 3: remove all OI files
7139 ${rcmd} rm -fv $mntpt/oi.16*
7140 elif [ $idx -lt 2 ]; then
7141 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7145 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7146 for ((i=${idx}; i<64; i=$((i * idx)))); do
7147 ${rcmd} rm -fv $mntpt/oi.16.${i}
7151 ${rcmd} $UMOUNT $mntpt || return 2
7152 # OI files will be recreated when mounted as lustre next time.
7155 # generate maloo upload-able log file name
7156 # \param logname specify unique part of file name
7157 generate_logname() {
7158 local logname=${1:-"default_logname"}
7160 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7163 # make directory on different MDTs
7167 local stripe_count=2
7168 local stripe_index=-1
7171 while getopts "c:i:p" opt; do
7173 c) stripe_count=$OPTARG;;
7174 i) stripe_index=$OPTARG;;
7176 \?) error "only support -i -c -p";;
7180 shift $((OPTIND - 1))
7181 [ $# -eq 1 ] || error "Only creating single directory is supported"
7184 if [ "$p_option" == "-p" ]; then
7185 local parent=$(dirname $path)
7187 [ -d $path ] && return 0
7188 [ ! -d ${parent} ] && mkdir -p ${parent}
7191 if [ $MDSCOUNT -le 1 ]; then
7194 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7197 if [ $stripe_index -eq -1 ]; then
7198 mdt_index=$((test_num % MDSCOUNT))
7200 mdt_index=$stripe_index
7202 echo "striped dir -i$mdt_index -c$stripe_count $path"
7203 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7207 # find the smallest and not in use file descriptor
7210 local max_fd=$(ulimit -n)
7212 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7215 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7219 check_mount_and_prep()
7221 is_mounted $MOUNT || setupall
7223 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7224 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7225 for idx in $(seq $MDSCOUNT); do
7226 local name="MDT$(printf '%04x' $((idx - 1)))"
7227 rm -rf $MOUNT/.lustre/lost+found/$name/*
7231 # calcule how many ost-objects to be created.
7232 precreated_ost_obj_count()
7236 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7237 local ost_name="OST$(printf '%04x' $ost_idx)"
7238 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7239 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7240 osp.$proc_path.prealloc_last_id)
7241 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7242 osp.$proc_path.prealloc_next_id)
7243 echo $((last_id - next_id + 1))
7246 check_file_in_pool()
7251 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7254 for t in $tlist ; do
7255 [ "$i" -eq "$t" ] && continue 2
7258 echo "pool list: $tlist"
7259 echo "striping: $res"
7260 error_noexit "$file not allocated in $pool"
7267 echo "Creating new pool"
7270 create_pool $FSNAME.$pool ||
7271 { error_noexit "No pool created, result code $?"; return 1; }
7272 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7273 { error_noexit "$pool not in lfs pool_list"; return 2; }
7276 pool_add_targets() {
7277 echo "Adding targets to pool"
7283 local list=$(seq $first $step $last)
7285 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7286 do_facet mgs $LCTL pool_add \
7287 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7289 # wait for OSTs to be added to the pool
7290 for mds_id in $(seq $MDSCOUNT); do
7291 local mdt_id=$((mds_id-1))
7292 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7293 wait_update_facet mds$mds_id \
7294 "lctl get_param -n lod.$lodname.pools.$pool |
7295 sort -u | tr '\n' ' ' " "$t" || {
7296 error_noexit "mds$mds_id: Add to pool failed"
7300 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7301 | sort -u | tr '\n' ' ' " "$t" || {
7302 error_noexit "Add to pool failed"
7305 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7306 local addcount=$(((last - first) / step + 1))
7307 [ $lfscount -eq $addcount ] || {
7308 error_noexit "lfs pool_list bad ost count" \
7309 "$lfscount != $addcount"
7317 echo "Setting pool on directory $tdir"
7319 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7321 error_noexit "Cannot set pool $pool to $tdir"
7328 echo "Checking pool on directory $tdir"
7330 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7331 [ "$res" = "$pool" ] && return 0
7333 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7337 pool_dir_rel_path() {
7338 echo "Testing relative path works well"
7343 mkdir -p $root/$tdir/$tdir
7345 pool_set_dir $pool $tdir || return 1
7346 pool_set_dir $pool ./$tdir || return 2
7347 pool_set_dir $pool ../$tdir || return 3
7348 pool_set_dir $pool ../$tdir/$tdir || return 4
7349 rm -rf $tdir; cd - > /dev/null
7352 pool_alloc_files() {
7353 echo "Checking files allocation from directory pool"
7360 for i in $(seq -w 1 $count)
7362 local file=$tdir/file-$i
7364 check_file_in_pool $file $pool "$tlist" || \
7365 failed=$((failed + 1))
7367 [ "$failed" = 0 ] && return 0
7369 error_noexit "$failed files not allocated in $pool"
7373 pool_create_files() {
7374 echo "Creating files in pool"
7382 for i in $(seq -w 1 $count)
7384 local file=$tdir/spoo-$i
7385 $SETSTRIPE -p $pool $file
7386 check_file_in_pool $file $pool "$tlist" || \
7387 failed=$((failed + 1))
7389 [ "$failed" = 0 ] && return 0
7391 error_noexit "$failed files not allocated in $pool"
7396 echo "Checking 'lfs df' output"
7399 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7401 local res=$($LFS df --pool $FSNAME.$pool |
7403 grep "$FSNAME-OST" |
7405 [ "$res" = "$t" ] && return 0
7407 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7411 pool_file_rel_path() {
7412 echo "Creating files in a pool with relative pathname"
7417 { error_noexit "unable to create $tdir"; return 1 ; }
7418 local file="/..$tdir/$tfile-1"
7419 $SETSTRIPE -p $pool $file ||
7420 { error_noexit "unable to create $file" ; return 2 ; }
7423 $SETSTRIPE -p $pool $tfile-2 || {
7424 error_noexit "unable to create $tfile-2 in $tdir"
7429 pool_remove_first_target() {
7430 echo "Removing first target from a pool"
7433 local pname="lov.$FSNAME-*.pools.$pool"
7434 local t=$($LCTL get_param -n $pname | head -1)
7435 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7436 for mds_id in $(seq $MDSCOUNT); do
7437 local mdt_id=$((mds_id-1))
7438 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7439 wait_update_facet mds$mds_id \
7440 "lctl get_param -n lod.$lodname.pools.$pool |
7442 error_noexit "mds$mds_id: $t not removed from" \
7447 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7448 error_noexit "$t not removed from $FSNAME.$pool"
7453 pool_remove_all_targets() {
7454 echo "Removing all targets from pool"
7457 local pname="lov.$FSNAME-*.pools.$pool"
7458 for t in $($LCTL get_param -n $pname | sort -u)
7460 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7462 for mds_id in $(seq $MDSCOUNT); do
7463 local mdt_id=$((mds_id-1))
7464 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7465 wait_update_facet mds$mds_id "lctl get_param -n \
7466 lod.$lodname.pools.$pool" "" || {
7467 error_noexit "mds$mds_id: Pool $pool not drained"
7471 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7472 error_noexit "Pool $FSNAME.$pool cannot be drained"
7475 # striping on an empty/nonexistant pool should fall back
7476 # to "pool of everything"
7478 error_noexit "failed to use fallback striping for empty pool"
7481 # setstripe on an empty pool should fail
7482 $SETSTRIPE -p $pool $file 2>/dev/null && {
7483 error_noexit "expected failure when creating file" \
7491 echo "Destroying pool"
7495 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7498 # striping on an empty/nonexistant pool should fall back
7499 # to "pool of everything"
7501 error_noexit "failed to use fallback striping for missing pool"
7504 # setstripe on an empty pool should fail
7505 $SETSTRIPE -p $pool $file 2>/dev/null && {
7506 error_noexit "expected failure when creating file" \
7511 # get param should return err once pool is gone
7512 if wait_update $HOSTNAME "lctl get_param -n \
7513 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7515 remove_pool_from_list $FSNAME.$pool
7518 error_noexit "Pool $FSNAME.$pool is not destroyed"
7522 # Get and check the actual stripe count of one file.
7523 # Usage: check_stripe_count <file> <expected_stripe_count>
7524 check_stripe_count() {
7529 [[ -z "$file" || -z "$expected" ]] &&
7530 error "check_stripe_count: invalid argument"
7532 local cmd="$GETSTRIPE -c $file"
7533 actual=$($cmd) || error "$cmd failed"
7534 actual=${actual%% *}
7536 if [[ $actual -ne $expected ]]; then
7537 [[ $expected -eq -1 ]] ||
7538 error "$cmd wrong: found $actual, expected $expected"
7539 [[ $actual -eq $OSTCOUNT ]] ||
7540 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7544 # Get and check the actual list of OST indices on one file.
7545 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7551 [[ -z "$file" || -z "$expected" ]] &&
7552 error "check_obdidx: invalid argument!"
7554 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7555 grep -v obdidx | awk '{print $1}' | xargs))
7557 [[ $obdidx = $expected ]] ||
7558 error "list of OST indices on $file is $obdidx," \
7559 "should be $expected"
7562 # Get and check the actual OST index of the first stripe on one file.
7563 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7564 check_start_ost_idx() {
7569 [[ -z "$file" || -z "$expected" ]] &&
7570 error "check_start_ost_idx: invalid argument!"
7572 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7575 [[ $start_ost_idx = $expected ]] ||
7576 error "OST index of the first stripe on $file is" \
7577 "$start_ost_idx, should be $expected"
7580 killall_process () {
7581 local clients=${1:-$(hostname)}
7586 do_nodes $clients "killall $signal $name"