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 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
21 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
22 export LOAD_LLOOP=${LOAD_LLOOP:-false}
24 #export PDSH="pdsh -S -Rssh -w"
25 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
26 export UMOUNT=${UMOUNT:-"umount -d"}
27 # sles12 umount has a issue with -d option
28 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
29 export UMOUNT="umount"
32 # function used by scripts run on remote nodes
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/functions.sh
35 . $LUSTRE/tests/yaml.sh
37 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
39 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
41 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
43 if [ -f "$EXCEPT_LIST_FILE" ]; then
44 echo "Reading test skip list from $EXCEPT_LIST_FILE"
49 # check config files for options in decreasing order of preference
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
51 MODPROBECONF=/etc/modprobe.d/lustre.conf
52 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
53 MODPROBECONF=/etc/modprobe.d/Lustre
54 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
55 MODPROBECONF=/etc/modprobe.conf
57 sanitize_parameters() {
58 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
61 if [ -d "$path" ]; then
62 eval export $i=$(echo $path | sed -r 's/\/+$//g')
68 [[ $DIR/ = $MOUNT/* ]] ||
69 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
70 [[ $DIR1/ = $MOUNT1/* ]] ||
71 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
72 [[ $DIR2/ = $MOUNT2/* ]] ||
73 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
75 [ -n "$failed" ] && exit 99 || true
79 echo "usage: $0 [-r] [-f cfgfile]"
87 [ -z "$DEFAULT_SUITES"] && return 0
88 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
90 local form="%-13s %-17s %-9s %s %s\n"
91 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
92 echo "------------------------------------------------------------------------------------"
93 for O in $DEFAULT_SUITES; do
94 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
95 [ "${!O}" = "no" ] && continue || true
96 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
97 local log=${TMP}/${o}.log
98 if is_sanity_benchmark $o; then
99 log=${TMP}/sanity-benchmark.log
104 local status=Unfinished
106 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
108 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
109 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
110 total=$(grep duration $log | awk '{ print $2 }')
111 if [ "${!O}" = "done" ]; then
115 local durations=$(egrep "^PASS|^FAIL" $log |
116 tr -d "("| sed s/s\)$//g |
117 awk '{ print $2":"$3"|" }')
118 details=$(printf "%s\n%s %s %s\n" "$details" \
119 "DDETAILS" "$O" "$(echo $durations)")
122 printf "$form" $status "$O" "${total}" "E=$skipped"
123 printf "$form" "-" "-" "-" "S=$(echo $slow)"
126 for O in $DEFAULT_SUITES; do
127 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
128 if [ "${!O}" = "no" ]; then
129 printf "$form" "Skipped" "$O" ""
133 # print the detailed tests durations if DDETAILS=true
140 export LUSTRE=$(absolute_path $LUSTRE)
141 export TESTSUITE=$(basename $0 .sh)
142 export TEST_FAILED=false
143 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
144 export RPC_MODE=${RPC_MODE:-false}
145 export DO_CLEANUP=${DO_CLEANUP:-true}
147 export MKE2FS=$MKE2FS
148 if [ -z "$MKE2FS" ]; then
149 if which mkfs.ldiskfs >/dev/null 2>&1; then
150 export MKE2FS=mkfs.ldiskfs
156 export DEBUGFS=$DEBUGFS
157 if [ -z "$DEBUGFS" ]; then
158 if which debugfs.ldiskfs >/dev/null 2>&1; then
159 export DEBUGFS=debugfs.ldiskfs
161 export DEBUGFS=debugfs
165 export TUNE2FS=$TUNE2FS
166 if [ -z "$TUNE2FS" ]; then
167 if which tunefs.ldiskfs >/dev/null 2>&1; then
168 export TUNE2FS=tunefs.ldiskfs
170 export TUNE2FS=tune2fs
174 export E2LABEL=$E2LABEL
175 if [ -z "$E2LABEL" ]; then
176 if which label.ldiskfs >/dev/null 2>&1; then
177 export E2LABEL=label.ldiskfs
179 export E2LABEL=e2label
183 export DUMPE2FS=$DUMPE2FS
184 if [ -z "$DUMPE2FS" ]; then
185 if which dumpfs.ldiskfs >/dev/null 2>&1; then
186 export DUMPE2FS=dumpfs.ldiskfs
188 export DUMPE2FS=dumpe2fs
192 export E2FSCK=$E2FSCK
193 if [ -z "$E2FSCK" ]; then
194 if which fsck.ldiskfs >/dev/null 2>&1; then
195 export E2FSCK=fsck.ldiskfs
201 export RESIZE2FS=$RESIZE2FS
202 if [ -z "$RESIZE2FS" ]; then
203 if which resizefs.ldiskfs >/dev/null 2>&1; then
204 export RESIZE2FS=resizefs.ldiskfs
206 export RESIZE2FS=resize2fs
210 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
211 export FSCK_MAX_ERR=4 # File system errors left uncorrected
213 export ZFS=${ZFS:-zfs}
214 export ZPOOL=${ZPOOL:-zpool}
215 export ZDB=${ZDB:-zdb}
216 export PARTPROBE=${PARTPROBE:-partprobe}
218 #[ -d /r ] && export ROOT=${ROOT:-/r}
219 export TMP=${TMP:-$ROOT/tmp}
220 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
221 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
222 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
224 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
225 if ! echo $PATH | grep -q $LUSTRE/utils; then
226 export PATH=$LUSTRE/utils:$PATH
228 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
229 export PATH=$LUSTRE/utils/gss:$PATH
231 if ! echo $PATH | grep -q $LUSTRE/tests; then
232 export PATH=$LUSTRE/tests:$PATH
234 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
235 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
237 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
238 [ ! -f "$LST" ] && export LST=$(which lst)
239 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
240 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
241 export MCREATE=${MCREATE:-mcreate}
242 # Ubuntu, at least, has a truncate command in /usr/bin
243 # so fully path our truncate command.
244 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
245 export FSX=${FSX:-$LUSTRE/tests/fsx}
246 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
247 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
248 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
249 export PATH=$LUSTRE/tests/racer:$PATH:
251 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
252 export PATH=$LUSTRE/tests/mpi:$PATH
254 export RSYNC_RSH=${RSYNC_RSH:-rsh}
256 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
257 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
258 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
259 [ ! -f "$LFS" ] && export LFS=$(which lfs)
260 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
261 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
263 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
264 if [ ! -f "$L_GETIDENTITY" ]; then
265 if `which l_getidentity > /dev/null 2>&1`; then
266 export L_GETIDENTITY=$(which l_getidentity)
268 export L_GETIDENTITY=NONE
271 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
272 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
273 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
274 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
275 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
276 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
277 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
278 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
279 [ ! -f "$LUSTRE_RMMOD" ] &&
280 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
281 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
282 [ ! -f "$LFS_MIGRATE" ] &&
283 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
284 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
285 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
286 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
287 export NAME=${NAME:-local}
288 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
289 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
290 export LGSSD=$(which lgssd)
291 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
292 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
293 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
295 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
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 llite_lloop_enabled() {
496 local n1=$(uname -r | cut -d. -f1)
497 local n2=$(uname -r | cut -d. -f2)
498 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
500 # load the llite_lloop module for < 2.6.32 kernels
501 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
502 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
509 load_modules_local() {
510 if [ -n "$MODPROBE" ]; then
512 echo "Using modprobe to load modules"
516 echo Loading modules from $LUSTRE
520 if [ -f /sys/devices/system/cpu/online ]; then
521 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
522 echo "detected $ncpus online CPUs by sysfs"
524 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
526 if [ $rc -eq 0 ]; then
527 echo "detected $ncpus online CPUs by getconf"
529 echo "Can't detect number of CPUs"
534 # if there is only one CPU core, libcfs can only create one partition
535 # if there is more than 4 CPU cores, libcfs should create multiple CPU
536 # partitions. So we just force libcfs to create 2 partitions for
537 # system with 2 or 4 cores
538 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
539 # force to enable multiple CPU partitions
540 echo "Force libcfs to create 2 CPU partitions"
541 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
543 echo "libcfs will create CPU partition based on online CPUs"
546 load_module ../libcfs/libcfs/libcfs
548 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
549 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
550 load_module ../lnet/lnet/lnet
553 LNETLND="o2iblnd/ko2iblnd"
558 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
559 load_module ../lnet/klnds/$LNETLND
560 load_module obdclass/obdclass
561 load_module ptlrpc/ptlrpc
562 load_module ptlrpc/gss/ptlrpc_gss
570 load_module obdecho/obdecho
571 if ! client_only; then
572 SYMLIST=/proc/kallsyms
573 grep -q crc16 $SYMLIST ||
574 { modprobe crc16 2>/dev/null || true; }
575 grep -q -w jbd2 $SYMLIST ||
576 { modprobe jbd2 2>/dev/null || true; }
577 load_module lfsck/lfsck
578 [ "$LQUOTA" != "no" ] &&
579 load_module quota/lquota $LQUOTAOPTS
580 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
582 load_module osd-zfs/osd_zfs
584 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
585 grep -q exportfs_decode_fh $SYMLIST ||
586 { modprobe exportfs 2> /dev/null || true; }
587 grep -q -w mbcache $SYMLIST ||
588 { modprobe mbcache 2>/dev/null || true; }
589 load_module ../ldiskfs/ldiskfs
590 load_module osd-ldiskfs/osd_ldiskfs
602 load_module llite/lustre
603 llite_lloop_enabled && load_module llite/llite_lloop
604 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
606 rm -f $OGDB/ogdb-$HOSTNAME
607 $LCTL modules > $OGDB/ogdb-$HOSTNAME
609 # 'mount' doesn't look in $PATH, just sbin
610 local mount_lustre=$LUSTRE/utils/mount.lustre
611 if [ -f $mount_lustre ]; then
612 local sbin_mount=$(readlink -f /sbin)/mount.lustre
613 if grep -qw "$sbin_mount" /proc/mounts; then
614 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
616 if ! grep -qw "$sbin_mount" /proc/mounts; then
617 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
618 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
619 cat <<- EOF > "$sbin_mount"
622 echo "This $sbin_mount just a mountpoint." 1>&2
623 echo "It is never supposed to be run." 1>&2
624 logger -p emerg -- "using stub $sbin_mount $@"
627 chmod a+x $sbin_mount
629 mount --bind $mount_lustre $sbin_mount ||
630 error "can't bind $mount_lustre to $sbin_mount"
638 # load modules on remote nodes optionally
639 # lustre-tests have to be installed on these nodes
640 if $LOAD_MODULES_REMOTE; then
641 local list=$(comma_list $(remote_nodes_list))
642 if [ -n "$list" ]; then
643 echo "loading modules on: '$list'"
644 do_rpc_nodes "$list" load_modules_local
650 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
651 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
652 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
653 echo "$LEAK_LUSTRE" 1>&2
654 echo "$LEAK_PORTALS" 1>&2
655 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
656 echo "Memory leaks detected"
657 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
663 wait_exit_ST client # bug 12845
665 $LUSTRE_RMMOD ldiskfs || return 2
667 if $LOAD_MODULES_REMOTE; then
668 local list=$(comma_list $(remote_nodes_list))
669 if [ -n "$list" ]; then
670 echo "unloading modules on: '$list'"
671 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
672 do_rpc_nodes "$list" check_mem_leak
676 local sbin_mount=$(readlink -f /sbin)/mount.lustre
677 if grep -qe "$sbin_mount " /proc/mounts; then
678 umount $sbin_mount || true
679 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
683 check_mem_leak || return 254
685 echo "modules unloaded."
690 local facet=${1:-$SINGLEMDS}
691 local fstype=$(facet_fstype $facet)
694 ldiskfs) size=50;; # largest seen is 44, leave some headroom
695 zfs) size=400;; # largest seen is 384
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 # Re-read the partition table on failover partner host.
981 # After a ZFS storage pool is created on a shared device, the partition table
982 # on the device may change. However, the operating system on the failover
983 # host may not notice the change automatically. Without the up-to-date partition
984 # block devices, 'zpool import ..' cannot find the labels, whose positions are
985 # relative to partition rather than disk beginnings.
987 # This function performs partprobe on the failover host to make it re-read the
990 refresh_partition_table() {
995 host=$(facet_passive_host $facet)
996 if [[ -n "$host" ]]; then
997 do_node $host "$PARTPROBE $device"
1002 # Get ZFS storage pool name.
1009 device=$(facet_device $facet)
1010 # poolname is string before "/"
1011 poolname="${device%%/*}"
1017 # Create ZFS storage pool.
1024 local opts=${@:-"-o cachefile=none"}
1026 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1027 $ZPOOL create -f $opts $poolname $vdev"
1031 # Create ZFS file system.
1037 local opts=${@:-"-o mountpoint=legacy"}
1039 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1040 $ZFS create $opts $dataset"
1044 # Export ZFS storage pool.
1045 # Before exporting the pool, all datasets within the pool should be unmounted.
1053 poolname=$(zpool_name $facet)
1055 if [[ -n "$poolname" ]]; then
1056 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1057 grep -q ^$poolname/ /proc/mounts ||
1058 $ZPOOL export $opts $poolname"
1063 # Destroy ZFS storage pool.
1064 # Destroy the given pool and free up any devices for other use. This command
1065 # tries to unmount any active datasets before destroying the pool.
1066 # -f Force any active datasets contained within the pool to be unmounted.
1070 local poolname=${2:-$(zpool_name $facet)}
1072 if [[ -n "$poolname" ]]; then
1073 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1074 $ZPOOL destroy -f $poolname"
1079 # Import ZFS storage pool.
1080 # Force importing, even if the pool appears to be potentially active.
1085 local opts=${@:-"-o cachefile=none"}
1088 poolname=$(zpool_name $facet)
1090 if [[ -n "$poolname" ]]; then
1091 opts+=" -d $(dirname $(facet_vdevice $facet))"
1092 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1093 $ZPOOL import -f $opts $poolname"
1098 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1099 # is not automatically imported on system startup.
1101 # In a failover environment, this will provide resource level fencing which
1102 # will ensure that the same ZFS storage pool will not be imported concurrently
1103 # on different nodes.
1105 disable_zpool_cache() {
1109 poolname=$(zpool_name $facet)
1111 if [[ -n "$poolname" ]]; then
1112 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1117 # This and set_osd_param() shall be used to access OSD parameters
1118 # once existed under "obdfilter":
1123 # writethrough_cache_enable
1127 local device=${2:-$FSNAME-OST*}
1130 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1131 osd-*.$device.$name 2>&1" | grep -v 'error:'
1136 local device=${2:-$FSNAME-OST*}
1140 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1141 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1145 local dz=${1:-$DEBUG_SIZE}
1147 if [ -f /sys/devices/system/cpu/possible ]; then
1148 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1150 local cpus=$(getconf _NPROCESSORS_CONF)
1153 # bug 19944, adjust size to be -gt num_possible_cpus()
1154 # promise 2MB for every cpu at least
1155 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1158 lctl set_param debug_mb=$dz
1161 set_default_debug () {
1162 local debug=${1:-"$PTLDEBUG"}
1163 local subsys=${2:-"$SUBSYSTEM"}
1164 local debug_size=${3:-$DEBUG_SIZE}
1166 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1167 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1169 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1172 set_default_debug_nodes () {
1175 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1176 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1180 do_rpc_nodes "$nodes" set_default_debug \
1181 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1184 set_default_debug_facet () {
1186 local node=$(facet_active_host $facet)
1187 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1189 set_default_debug_nodes $node
1193 local hostid=${1:-$(hostid)}
1195 if [ ! -s /etc/hostid ]; then
1196 printf $(echo -n $hostid |
1197 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1203 local facets=${1:-$(get_facets)}
1206 for facet in ${facets//,/ }; do
1209 [ $RC -eq 0 ] && continue
1211 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1212 skip "Restart of $facet failed!." && touch $LU482_FAILED
1214 error "Restart of $facet failed!"
1221 # Add argument "arg" (e.g., "loop") to the comma-separated list
1222 # of arguments for option "opt" (e.g., "-o") on command
1223 # line "opts" (e.g., "-o flock").
1229 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1231 if echo "$opts" | grep -q $opt_pattern; then
1232 opts=$(echo "$opts" | sed -e \
1233 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1235 opts+="${opts:+ }$opt $arg"
1243 local dev=$(facet_active $facet)_dev
1244 local opt=${facet}_opt
1245 local mntpt=$(facet_mntpt $facet)
1246 local opts="${!opt} $@"
1247 local fstype=$(facet_fstype $facet)
1250 module_loaded lustre || load_modules
1252 if [ $(facet_fstype $facet) == ldiskfs ] &&
1253 ! do_facet $facet test -b ${!dev}; then
1254 opts=$(csa_add "$opts" -o loop)
1257 if [[ $(facet_fstype $facet) == zfs ]]; then
1258 # import ZFS storage pool
1259 import_zpool $facet || return ${PIPESTATUS[0]}
1264 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1266 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1267 lustre:svname ${!dev}");;
1269 error "unknown fstype!";;
1272 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1273 # for testing LU-482 error handling in mount_facets() and test_0a()
1274 if [ -f $TMP/test-lu482-trigger ]; then
1277 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1282 if [ $RC -ne 0 ]; then
1283 echo "Start of ${!dev} on ${facet} failed ${RC}"
1287 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1288 if [[ "$health" != "healthy" ]]; then
1289 error "$facet is in a unhealthy state"
1292 set_default_debug_facet $facet
1294 if [[ $facet == mds* ]]; then
1296 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1299 if [[ $opts =~ .*nosvc.* ]]; then
1300 echo "Start ${!dev} without service"
1305 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1306 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1307 "" || error "${!dev} failed to initialize!";;
1309 wait_update_facet ${facet} "$ZFS get -H -o value \
1310 lustre:svname ${!dev} 2>/dev/null | \
1311 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1312 error "${!dev} failed to initialize!";;
1315 error "unknown fstype!";;
1319 # commit the device label change to disk
1320 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1321 do_facet $facet "sync; sync; sync"
1325 label=$(devicelabel ${facet} ${!dev})
1326 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1327 eval export ${facet}_svc=${label}
1328 echo Started ${label}
1333 # start facet device options
1339 eval export ${facet}_dev=${device}
1340 eval export ${facet}_opt=\"$@\"
1342 local varname=${facet}failover_dev
1343 if [ -n "${!varname}" ] ; then
1344 eval export ${facet}failover_dev=${!varname}
1346 eval export ${facet}failover_dev=$device
1349 local mntpt=$(facet_mntpt $facet)
1350 do_facet ${facet} mkdir -p $mntpt
1351 eval export ${facet}_MOUNT=$mntpt
1352 mount_facet ${facet}
1355 if [[ $facet == mds* ]]; then
1357 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1368 local HOST=`facet_active_host $facet`
1369 [ -z $HOST ] && echo stop: no host for $facet && return 0
1371 local mntpt=$(facet_mntpt $facet)
1372 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1373 if [ ${running} -ne 0 ]; then
1374 echo "Stopping $mntpt (opts:$@) on $HOST"
1375 do_facet ${facet} $UMOUNT $@ $mntpt
1378 # umount should block, but we should wait for unrelated obd's
1379 # like the MGS or MGC to also stop.
1380 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1382 if [[ $(facet_fstype $facet) == zfs ]]; then
1383 # export ZFS storage pool
1388 # save quota version (both administrative and operational quotas)
1389 # add an additional parameter if mountpoint is ever different from $MOUNT
1391 # XXX This function is kept for interoperability with old server (< 2.3.50),
1392 # it should be removed whenever we drop the interoperability for such
1394 quota_save_version() {
1395 local fsname=${2:-$FSNAME}
1397 local ver=$(tr -c -d "123" <<< $spec)
1398 local type=$(tr -c -d "ug" <<< $spec)
1400 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1402 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1404 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1406 local osts=$(get_facets OST)
1407 for ost in ${osts//,/ }; do
1409 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1413 # client could mount several lustre
1415 # XXX This function is kept for interoperability with old server (< 2.3.50),
1416 # it should be removed whenever we drop the interoperability for such
1419 local fsname=${1:-$FSNAME}
1421 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1423 do_nodes $(comma_list $(osts_nodes)) \
1424 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1428 # get mdt quota type
1430 local varsvc=${SINGLEMDS}_svc
1431 do_facet $SINGLEMDS $LCTL get_param -n \
1432 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1435 # get ost quota type
1437 # All OSTs should have same quota type
1438 local varsvc=ost1_svc
1439 do_facet ost1 $LCTL get_param -n \
1440 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1443 # restore old quota type settings
1445 if [ "$old_MDT_QUOTA_TYPE" ]; then
1446 do_facet mgs $LCTL conf_param \
1447 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1449 if [ "$old_OST_QUOTA_TYPE" ]; then
1450 do_facet mgs $LCTL conf_param \
1451 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1455 # Handle the case when there is a space in the lfs df
1456 # "filesystem summary" line the same as when there is no space.
1457 # This will allow fixing the "lfs df" summary line in the future.
1459 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1462 # Get free inodes on the MDT specified by mdt index, free indoes on
1463 # the whole filesystem will be returned when index == -1.
1469 if [ $index -eq -1 ]; then
1472 mdt_uuid=$(mdtuuid_from_index $index)
1475 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1482 # save old quota type & set new quota type
1483 local mdt_qtype=$(mdt_quota_type)
1484 local ost_qtype=$(ost_quota_type)
1486 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1487 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1489 export old_MDT_QUOTA_TYPE=$mdt_qtype
1490 export old_OST_QUOTA_TYPE=$ost_qtype
1492 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1493 error "set mdt quota type failed"
1494 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1495 error "set ost quota type failed"
1497 local quota_usrs=$QUOTA_USERS
1499 # get_filesystem_size
1500 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1501 local blk_soft=$((disksz + 1024))
1502 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1504 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1505 local i_soft=$inodes
1506 local i_hard=$((i_soft + i_soft / 20))
1508 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1509 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1510 "inode-hardlimit: $i_hard"
1513 for usr in $quota_usrs; do
1514 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1516 cmd="$LFS setquota -$type $usr -b $blk_soft"
1517 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1519 eval $cmd || error "$cmd FAILED!"
1521 # display the quota status
1522 echo "Quota settings for $usr : "
1523 $LFS quota -v -u $usr $mntpt || true
1530 local opts=${3:-$MOUNT_OPTS}
1531 opts=${opts:+-o $opts}
1532 local flags=${4:-$MOUNT_FLAGS}
1534 local device=$MGSNID:/$FSNAME$FILESET
1535 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1536 echo "Bad mount command: opt=$flags $opts dev=$device " \
1541 echo "Starting client: $client: $flags $opts $device $mnt"
1542 do_node $client mkdir -p $mnt
1543 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1544 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1546 #disable FILESET if not supported
1547 do_nodes $client lctl get_param -n \
1548 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1549 device=$MGSNID:/$FSNAME
1550 do_node $client mkdir -p $mnt/$FILESET
1551 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1554 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1556 set_default_debug_nodes $client
1568 [ "$3" ] && force=-f
1569 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1570 if [ $running -ne 0 ]; then
1571 echo "Stopping client $client $mnt (opts:$force)"
1572 do_node $client lsof -t $mnt || need_kill=no
1573 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1574 pids=$(do_node $client lsof -t $mnt | sort -u);
1575 if [ -n $pids ]; then
1576 do_node $client kill -9 $pids || true
1580 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1581 if [ $busy -ne 0 ] ; then
1582 echo "$mnt is still busy, wait one second" && sleep 1
1583 do_node $client umount $force $mnt
1588 # nodes is comma list
1589 sanity_mount_check_nodes () {
1595 # FIXME: assume that all cluster nodes run the same os
1596 [ "$(uname)" = Linux ] || return 0
1599 for mnt in $mnts ; do
1600 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1601 mpts=\\\$(mount | grep -c $mnt' ');
1602 if [ \\\$running -ne \\\$mpts ]; then
1603 echo \\\$(hostname) env are INSANE!;
1606 [ $? -eq 0 ] || rc=1
1611 sanity_mount_check_servers () {
1612 [ "$CLIENTONLY" ] &&
1613 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1614 echo Checking servers environments
1616 # FIXME: modify get_facets to display all facets wo params
1617 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1621 for facet in ${facets//,/ }; do
1622 node=$(facet_host ${facet})
1623 mntpt=$(facet_mntpt $facet)
1624 sanity_mount_check_nodes $node $mntpt ||
1625 { error "server $node environments are insane!"; return 1; }
1629 sanity_mount_check_clients () {
1630 local clients=${1:-$CLIENTS}
1631 local mntpt=${2:-$MOUNT}
1632 local mntpt2=${3:-$MOUNT2}
1634 [ -z $clients ] && clients=$(hostname)
1635 echo Checking clients $clients environments
1637 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1638 error "clients environments are insane!"
1641 sanity_mount_check () {
1642 sanity_mount_check_servers || return 1
1643 sanity_mount_check_clients || return 2
1646 # mount clients if not mouted
1647 zconf_mount_clients() {
1650 local opts=${3:-$MOUNT_OPTS}
1651 opts=${opts:+-o $opts}
1652 local flags=${4:-$MOUNT_FLAGS}
1654 local device=$MGSNID:/$FSNAME$FILESET
1655 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1656 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1661 echo "Starting client $clients: $flags $opts $device $mnt"
1662 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1663 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1665 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1667 #disable FILESET if not supported
1668 do_nodes $clients lctl get_param -n \
1669 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1670 device=$MGSNID:/$FSNAME
1671 do_nodes $clients mkdir -p $mnt/$FILESET
1672 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1677 running=\\\$(mount | grep -c $mnt' ');
1679 if [ \\\$running -eq 0 ] ; then
1681 $MOUNT_CMD $flags $opts $device $mnt;
1684 exit \\\$rc" || return ${PIPESTATUS[0]}
1686 echo "Started clients $clients: "
1687 do_nodes $clients "mount | grep $mnt' '"
1689 set_default_debug_nodes $clients
1694 zconf_umount_clients() {
1699 [ "$3" ] && force=-f
1701 echo "Stopping clients: $clients $mnt (opts:$force)"
1702 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1703 if [ \\\$running -ne 0 ] ; then
1704 echo Stopping client \\\$(hostname) $mnt opts:$force;
1705 lsof $mnt || need_kill=no;
1706 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1707 pids=\\\$(lsof -t $mnt | sort -u);
1708 if [ -n \\\"\\\$pids\\\" ]; then
1712 while umount $force $mnt 2>&1 | grep -q "busy"; do
1713 echo "$mnt is still busy, wait one second" && sleep 1;
1720 echo + $POWER_DOWN $node
1724 shutdown_node_hard () {
1726 local attempts=$SHUTDOWN_ATTEMPTS
1728 for i in $(seq $attempts) ; do
1731 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1732 echo "waiting for $host to fail attempts=$attempts"
1733 [ $i -lt $attempts ] || \
1734 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1740 local mnt=${2:-$MOUNT}
1743 if [ "$FAILURE_MODE" = HARD ]; then
1744 shutdown_node_hard $client
1746 zconf_umount_clients $client $mnt -f
1752 local facets="$(get_facets OST),$(get_facets MDS)"
1755 combined_mgs_mds || facets="$facets,mgs"
1757 for facet in ${facets//,/ }; do
1758 if [ $(facet_active_host $facet) == $host ]; then
1759 affected="$affected $facet"
1763 echo $(comma_list $affected)
1768 local host=${2:-$(facet_host $facet)}
1770 local label=$(convert_facet2label $facet)
1771 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1774 facets_up_on_host () {
1776 local facets=$(facets_on_host $host)
1779 for facet in ${facets//,/ }; do
1780 if $(facet_up $facet $host); then
1781 affected_up="$affected_up $facet"
1785 echo $(comma_list $affected_up)
1791 if [ "$FAILURE_MODE" = HARD ]; then
1792 shutdown_node_hard $(facet_active_host $facet)
1800 echo + $POWER_UP $node
1813 if [ "$FAILURE_MODE" = HARD ]; then
1814 reboot_node $(facet_active_host $facet)
1822 if [ "$FAILURE_MODE" = HARD ]; then
1832 for facet in ${facets//,/ }; do
1833 hosts=$(expand_list $hosts $(facet_host $facet) )
1839 _check_progs_installed () {
1843 for prog in $progs; do
1844 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1845 echo $prog missing on $(hostname)
1852 check_progs_installed () {
1856 do_rpc_nodes "$nodes" _check_progs_installed $@
1859 # recovery-scale functions
1861 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1864 start_client_load() {
1867 local var=$(node_var_name $client)_load
1868 eval export ${var}=$load
1870 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1871 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1872 END_RUN_FILE=$END_RUN_FILE \
1873 LOAD_PID_FILE=$LOAD_PID_FILE \
1874 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1875 TESTNAME=$TESTNAME \
1876 DBENCH_LIB=$DBENCH_LIB \
1877 DBENCH_SRC=$DBENCH_SRC \
1878 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1882 log "Started client load: ${load} on $client"
1884 # get the children process IDs
1885 local pids=$(ps --ppid $ppid -o pid= | xargs)
1886 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1890 start_client_loads () {
1891 local -a clients=(${1//,/ })
1892 local numloads=${#CLIENT_LOADS[@]}
1895 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1896 testnum=$((nodenum % numloads))
1897 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1899 # bug 22169: wait the background threads to start
1903 # only for remote client
1904 check_client_load () {
1906 local var=$(node_var_name $client)_load
1907 local TESTLOAD=run_${!var}.sh
1909 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1911 # bug 18914: try to connect several times not only when
1912 # check ps, but while check_catastrophe also
1915 while [ $RC = 254 -a $tries -gt 0 ]; do
1919 if ! check_catastrophe $client; then
1921 if [ $RC -eq 254 ]; then
1922 # FIXME: not sure how long we shuold sleep here
1926 echo "check catastrophe failed: RC=$RC "
1930 # We can continue try to connect if RC=254
1931 # Just print the warning about this
1932 if [ $RC = 254 ]; then
1933 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1936 # see if the load is still on the client
1939 while [ $RC = 254 -a $tries -gt 0 ]; do
1943 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1948 if [ $RC = 254 ]; then
1949 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1950 # see if we can diagnose a bit why this is
1955 check_client_loads () {
1956 local clients=${1//,/ }
1960 for client in $clients; do
1961 check_client_load $client
1963 if [ "$rc" != 0 ]; then
1964 log "Client load failed on node $client, rc=$rc"
1970 restart_client_loads () {
1971 local clients=${1//,/ }
1972 local expectedfail=${2:-""}
1976 for client in $clients; do
1977 check_client_load $client
1979 if [ "$rc" != 0 -a "$expectedfail" ]; then
1980 local var=$(node_var_name $client)_load
1981 start_client_load $client ${!var}
1982 echo "Restarted client load ${!var}: on $client. Checking ..."
1983 check_client_load $client
1985 if [ "$rc" != 0 ]; then
1986 log "Client load failed to restart on node $client, rc=$rc"
1987 # failure one client load means test fail
1988 # we do not need to check other
1997 # Start vmstat and save its process ID in a file.
2002 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2005 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2006 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2009 # Display the nodes on which client loads failed.
2010 print_end_run_file() {
2014 [ -s $file ] || return 0
2016 echo "Found the END_RUN_FILE file: $file"
2019 # A client load will stop if it finds the END_RUN_FILE file.
2020 # That does not mean the client load actually failed though.
2021 # The first node in END_RUN_FILE is the one we are interested in.
2024 if [ -n "$node" ]; then
2025 local var=$(node_var_name $node)_load
2027 local prefix=$TESTLOG_PREFIX
2028 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2029 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2030 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2032 echo "Client load ${!var} failed on node $node:"
2038 # Stop the process which had its PID saved in a file.
2043 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2045 do_nodes $nodes "test -f $pid_file &&
2046 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2049 # Stop all client loads.
2050 stop_client_loads() {
2051 local nodes=${1:-$CLIENTS}
2054 # stop the client loads
2055 stop_process $nodes $pid_file
2057 # clean up the processes that started them
2058 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2060 # End recovery-scale functions
2062 # verify that lustre actually cleaned up properly
2064 VAR=$(lctl get_param -n catastrophe 2>&1)
2065 if [ $? = 0 ] ; then
2066 if [ $VAR != 0 ]; then
2067 error "LBUG/LASSERT detected"
2070 BUSY=$(dmesg | grep -i destruct || true)
2071 if [ -n "$BUSY" ]; then
2073 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2077 check_mem_leak || exit 204
2079 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2080 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2083 if module_loaded lnet || module_loaded libcfs; then
2084 echo "$TESTSUITE: modules still loaded..." 1>&2
2093 if [[ "$1" == "--verbose" ]]; then
2108 PREV_RESULT=$(do_node $node "$TEST")
2110 RESULT=$(do_node $node "$TEST")
2111 if [[ "$RESULT" == "$FINAL" ]]; then
2112 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2113 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2117 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2118 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2122 [[ $WAIT -ge $MAX ]] && break
2123 [[ $((WAIT % print)) -eq 0 ]] &&
2124 echo "Waiting $((MAX - WAIT)) secs for update"
2125 WAIT=$((WAIT + sleep))
2128 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2132 wait_update_facet() {
2134 [ "$1" = "--verbose" ] && verbose="$1" && shift
2138 wait_update $verbose $(facet_active_host $facet) "$@"
2142 do_nodes $(comma_list $(mdts_nodes)) \
2143 "lctl set_param -n osd*.*MDT*.force_sync=1"
2144 do_nodes $(comma_list $(osts_nodes)) \
2145 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2146 grep -v 'Found no match'
2149 wait_delete_completed_mds() {
2150 local MAX_WAIT=${1:-20}
2151 # for ZFS, waiting more time for DMUs to be committed
2152 local ZFS_WAIT=${2:-5}
2154 local stime=$(date +%s)
2159 # find MDS with pending deletions
2160 for node in $(mdts_nodes); do
2161 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2162 2>/dev/null | calc_sum)
2163 if [[ $changes -eq 0 ]]; then
2166 mds2sync="$mds2sync $node"
2168 if [ -z "$mds2sync" ]; then
2171 mds2sync=$(comma_list $mds2sync)
2173 # sync MDS transactions
2174 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2176 # wait till all changes are sent and commmitted by OSTs
2177 # for ldiskfs space is released upon execution, but DMU
2178 # do this upon commit
2181 while [[ $WAIT -ne $MAX_WAIT ]]; do
2182 changes=$(do_nodes $mds2sync \
2183 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2184 #echo "$node: $changes changes on all"
2185 if [[ $changes -eq 0 ]]; then
2187 #echo "delete took $((etime - stime)) seconds"
2189 # the occupied disk space will be released
2190 # only after DMUs are committed
2191 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2192 echo "sleep $ZFS_WAIT for ZFS OSD"
2203 echo "Delete is not completed in $((etime - stime)) seconds"
2204 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2210 # we can use "for" here because we are waiting the slowest
2211 for host in ${hostlist//,/ }; do
2212 check_network "$host" 900
2214 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2221 for facet in ${facetlist//,/ }; do
2222 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2224 wait_for_host $hostlist
2227 _wait_recovery_complete () {
2230 # Use default policy if $2 is not passed by caller.
2231 local MAX=${2:-$(max_recovery_time)}
2236 while [ $WAIT -lt $MAX ]; do
2237 STATUS=$(lctl get_param -n $param | grep status)
2239 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2242 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2244 echo "$param recovery not done in $MAX sec. $STATUS"
2248 wait_recovery_complete () {
2251 # with an assumption that at_max is the same on all nodes
2252 local MAX=${2:-$(max_recovery_time)}
2255 if [ "$FAILURE_MODE" = HARD ]; then
2256 facets=$(facets_on_host $(facet_active_host $facet))
2258 echo affected facets: $facets
2260 # we can use "for" here because we are waiting the slowest
2261 for facet in ${facets//,/ }; do
2262 local var_svc=${facet}_svc
2263 local param="*.${!var_svc}.recovery_status"
2265 local host=$(facet_active_host $facet)
2266 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2270 wait_mds_ost_sync () {
2271 # just because recovery is done doesn't mean we've finished
2272 # orphan cleanup. Wait for llogs to get synchronized.
2273 echo "Waiting for orphan cleanup..."
2274 # MAX value includes time needed for MDS-OST reconnection
2275 local MAX=$(( TIMEOUT * 2 ))
2276 local WAIT_TIMEOUT=${1:-$MAX}
2279 local list=$(comma_list $(mdts_nodes))
2280 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2281 if ! do_facet $SINGLEMDS \
2282 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2284 # old way, use mds_sync
2286 list=$(comma_list $(osts_nodes))
2287 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2290 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2291 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2292 local -a sync=($(do_nodes $list "$cmd"))
2295 for ((i=0; i<${#sync[@]}; i++)); do
2297 [ ${sync[$i]} -eq 1 ] && continue
2299 [ ${sync[$i]} -eq 0 ] && continue
2301 # there is a not finished MDS-OST synchronization
2305 sleep 2 # increase waiting time and cover statfs cache
2306 [ ${con} -eq 1 ] && return 0
2307 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2311 # show which nodes are not finished.
2312 do_nodes $list "$cmd"
2313 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2317 wait_destroy_complete () {
2318 echo "Waiting for local destroys to complete"
2319 # MAX value shouldn't be big as this mean server responsiveness
2320 # never increase this just to make test pass but investigate
2321 # why it takes so long time
2324 while [ $WAIT -lt $MAX ]; do
2325 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2329 for ((i=0; i<${#RPCs[@]}; i++)); do
2330 [ ${RPCs[$i]} -eq 0 ] && continue
2331 # there are still some destroy RPCs in flight
2336 [ ${con} -eq 1 ] && return 0 # done waiting
2337 echo "Waiting ${WAIT}s for local destroys to complete"
2340 echo "Local destroys weren't done in $MAX sec."
2344 wait_delete_completed() {
2345 wait_delete_completed_mds $1 || return $?
2346 wait_destroy_complete
2355 # conf-sanity 31 takes a long time cleanup
2356 while [ $WAIT -lt 300 ]; do
2357 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2358 [ -z "${running}" ] && return 0
2359 echo "waited $WAIT for${running}"
2360 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2362 WAIT=$((WAIT + INTERVAL))
2364 echo "service didn't stop after $WAIT seconds. Still running:"
2369 wait_remote_prog () {
2375 [ "$PDSH" = "no_dsh" ] && return 0
2377 while [ $WAIT -lt $2 ]; do
2378 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2379 [ -z "${running}" ] && return 0 || true
2380 echo "waited $WAIT for: "
2382 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2384 WAIT=$((WAIT + INTERVAL))
2386 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2387 [ -z "$pids" ] && return 0
2388 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2389 # FIXME: not portable
2390 for pid in $pids; do
2391 cat /proc/${pid}/status || true
2392 cat /proc/${pid}/wchan || true
2394 kill -9 $pid || true
2403 # not every config has many clients
2405 if [ ! -z "$CLIENTS" ]; then
2406 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2408 stat -f $MOUNT > /dev/null
2414 # usually checked on particular client or locally
2416 if [ ! -z "$client" ]; then
2417 $PDSH $client "stat -f $MOUNT" > /dev/null
2419 stat -f $MOUNT > /dev/null
2427 client_reconnect_try() {
2428 uname -n >> $MOUNT/recon
2429 if [ -z "$CLIENTS" ]; then
2430 df $MOUNT; uname -n >> $MOUNT/recon
2432 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2434 echo Connected clients:
2436 ls -l $MOUNT/recon > /dev/null
2440 client_reconnect() {
2441 # one client_reconnect_try call does not always do the job...
2443 client_reconnect_try && break
2448 affected_facets () {
2451 local host=$(facet_active_host $facet)
2452 local affected=$facet
2454 if [ "$FAILURE_MODE" = HARD ]; then
2455 affected=$(facets_up_on_host $host)
2461 local E2FSCK_ON_MDT0=false
2462 if [ "$1" == "--fsck" ]; then
2464 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2476 #Because it will only get up facets, we need get affected
2477 #facets before shutdown
2478 #For HARD Failure mode, it needs make sure facets on the same
2479 #HOST will only be shutdown and reboot once
2480 for facet in ${facets//,/ }; do
2481 local affected_facet
2483 #check whether facet has been included in other affected facets
2484 for ((index=0; index<$total; index++)); do
2485 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2488 if [ $skip -eq 0 ]; then
2489 affecteds[$total]=$(affected_facets $facet)
2494 for ((index=0; index<$total; index++)); do
2495 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2496 local host=$(facet_active_host $facet)
2497 echo "Failing ${affecteds[index]} on $host"
2498 shutdown_facet $facet
2501 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2502 $(mdsdevname 1) "-n" || error "Running e2fsck")
2504 for ((index=0; index<$total; index++)); do
2505 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2506 echo reboot facets: ${affecteds[index]}
2510 change_active ${affecteds[index]}
2512 wait_for_facet ${affecteds[index]}
2513 # start mgs first if it is affected
2514 if ! combined_mgs_mds &&
2515 list_member ${affecteds[index]} mgs; then
2516 mount_facet mgs || error "Restart of mgs failed"
2518 # FIXME; has to be changed to mount all facets concurrently
2519 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2520 echo mount facets: ${affecteds[index]}
2521 mount_facets ${affecteds[index]}
2531 do_facet $facet "sync; sync; sync"
2534 # make sure there will be no seq change
2535 local clients=${CLIENTS:-$HOSTNAME}
2536 local f=fsa-\\\$\(hostname\)
2537 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2538 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2540 local svc=${facet}_svc
2541 do_facet $facet $LCTL --device ${!svc} notransno
2543 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2544 # in-memory state has to be cleared by either rebooting the host or
2545 # exporting and reimporting the pool.
2547 # Although the uberblocks are not updated when a pool is freezed,
2548 # transactions are still written to the disks. Modified blocks may be
2549 # cached in memory when tests try reading them back. The
2550 # export-and-reimport process also evicts any cached pool data from
2551 # memory to provide the correct "data loss" semantics.
2553 # In the test framework, the exporting and importing operations are
2554 # handled by stop() and mount_facet() separately, which are used
2555 # inside fail() and fail_abort().
2557 do_facet $facet $LCTL --device ${!svc} readonly
2558 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2559 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2562 replay_barrier_nodf() {
2563 local facet=$1 echo running=${running}
2564 do_facet $facet "sync; sync; sync"
2565 local svc=${facet}_svc
2566 echo Replay barrier on ${!svc}
2567 do_facet $facet $LCTL --device ${!svc} notransno
2568 do_facet $facet $LCTL --device ${!svc} readonly
2569 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2570 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2573 replay_barrier_nosync() {
2574 local facet=$1 echo running=${running}
2575 local svc=${facet}_svc
2576 echo Replay barrier on ${!svc}
2577 do_facet $facet $LCTL --device ${!svc} notransno
2578 do_facet $facet $LCTL --device ${!svc} readonly
2579 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2580 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2584 # Get Lustre client uuid for a given Lustre mount point.
2587 local mntpnt=${1:-$MOUNT}
2589 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2590 local uuid=$($LCTL get_param -n llite.$name.uuid)
2595 mds_evict_client() {
2596 local mntpnt=${1:-$MOUNT}
2597 local uuid=$(get_client_uuid $mntpnt)
2599 do_facet $SINGLEMDS \
2600 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2603 ost_evict_client() {
2604 local mntpnt=${1:-$MOUNT}
2605 local uuid=$(get_client_uuid $mntpnt)
2608 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2613 local clients=${CLIENTS:-$HOSTNAME}
2615 facet_failover $* || error "failover: $?"
2616 wait_clients_import_state "$clients" "$facets" FULL
2617 clients_up || error "post-failover df: $?"
2622 facet_failover $facet
2628 change_active $facet
2629 wait_for_facet $facet
2630 mount_facet $facet -o abort_recovery
2631 clients_up || echo "first df failed: $?"
2632 clients_up || error "post-failover df: $?"
2636 echo There is no lmc. This is mountconf, baby.
2640 host_nids_address() {
2644 if [ -n "$kind" ]; then
2645 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2647 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2653 if [ "$1" = "'*'" ]; then echo \'*\'; else
2659 if [ "$1" = "'*'" ]; then echo \'*\'; else
2660 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2662 if [ -z "$ID" ]; then
2663 echo "Could not get a ptl id for $1..."
2672 h2name_or_ip "$1" "tcp"
2677 if [ "$1" = "'*'" ]; then echo \'*\'; else
2678 if type __h2elan >/dev/null 2>&1; then
2681 ID=`echo $1 | sed 's/[^0-9]*//g'`
2689 h2name_or_ip "$1" "o2ib"
2693 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2694 # expressions format. As a bonus we can then just pass in those variables
2695 # to pdsh. What this function does is take a HOSTLIST type string and
2696 # expand it into a space deliminated list for us.
2704 [ -z "$hostlist" ] && return
2706 # Translate the case of [..],..,[..] to [..] .. [..]
2707 list="${hostlist/],/] }"
2709 [[ "$front" == *,* ]] && {
2712 list=${list/${old}/${new}}
2715 for item in $list; do
2716 # Test if we have any []'s at all
2717 if [ "$item" != "${item/\[/}" ]; then {
2718 # Expand the [*] into list
2722 if [ "$name" != "$item" ]; then
2723 group=${item#$name[*}
2726 for range in ${group//,/ }; do
2730 # Number of leading zeros
2733 end=$(echo $end | sed 's/0*//')
2734 [[ -z "$end" ]] && end=0
2735 [[ $padlen2 -gt $padlen ]] && {
2736 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2739 begin=$(echo $begin | sed 's/0*//')
2740 [ -z $begin ] && begin=0
2742 for num in $(seq -f "%0${padlen}g" $begin $end); do
2743 value="${name#*,}${num}${back}"
2744 [ "$value" != "${value/\[/}" ] && {
2745 value=$(hostlist_expand "$value")
2747 myList="$myList $value"
2752 myList="$myList $item"
2755 myList=${myList//,/ }
2756 myList=${myList:1} # Remove first character which is a space
2758 # Filter any duplicates without sorting
2760 myList="${list%% *}"
2762 while [[ "$list" != ${myList##* } ]]; do
2763 list=${list//${list%% *} /}
2764 myList="$myList ${list%% *}"
2766 myList="${myList%* }";
2768 # We can select an object at an offset in the list
2771 for item in $myList; do
2773 [ $cnt -eq $offset ] && {
2777 [ $(get_node_count $myList) -ne 1 ] && myList=""
2786 [ "$facet" == client ] && echo -n $HOSTNAME && return
2787 varname=${facet}_HOST
2788 if [ -z "${!varname}" ]; then
2789 if [ "${facet:0:3}" == "ost" ]; then
2790 local fh=${facet%failover}_HOST
2791 eval export ${facet}_HOST=${!fh}
2792 if [ -z "${!varname}" ]; then
2793 eval export ${facet}_HOST=${ost_HOST}
2795 elif [ "${facet:0:3}" == "mdt" -o \
2796 "${facet:0:3}" == "mds" -o \
2797 "${facet:0:3}" == "mgs" ]; then
2798 eval export ${facet}_HOST=${mds_HOST}
2804 facet_failover_host() {
2808 var=${facet}failover_HOST
2809 if [ -n "${!var}" ]; then
2814 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2815 "${facet:0:3}" == "mgs" ]; then
2817 eval export ${facet}failover_host=${mds_HOST}
2822 if [[ $facet == ost* ]]; then
2823 eval export ${facet}failover_host=${ost_HOST}
2831 local activevar=${facet}active
2833 if [ -f $TMP/${facet}active ] ; then
2834 source $TMP/${facet}active
2837 active=${!activevar}
2838 if [ -z "$active" ] ; then
2845 facet_active_host() {
2846 facet_host $(facet_active $1)
2849 # Get the passive failover partner host of facet.
2850 facet_passive_host() {
2852 [[ $facet = client ]] && return
2854 local host=${facet}_HOST
2855 local failover_host=${facet}failover_HOST
2856 local active_host=$(facet_active_host $facet)
2858 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2860 if [[ $active_host = ${!host} ]]; then
2861 echo -n ${!failover_host}
2871 facetlist=$(exclude_items_from_list $facetlist mgs)
2873 for facet in ${facetlist//,/ }; do
2874 local failover=${facet}failover
2875 local host=`facet_host $failover`
2876 [ -z "$host" ] && return
2878 local curactive=`facet_active $facet`
2879 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2880 eval export ${facet}active=$facet
2882 eval export ${facet}active=$failover
2884 # save the active host for this facet
2885 local activevar=${facet}active
2886 echo "$activevar=${!activevar}" > $TMP/$activevar
2887 [[ $facet = mds1 ]] && combined_mgs_mds && \
2888 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2889 local TO=`facet_active_host $facet`
2890 echo "Failover $facet to $TO"
2896 # do not stripe off hostname if verbose, bug 19215
2897 if [ x$1 = x--verbose ]; then
2905 if [ "$HOST" = "$HOSTNAME" ]; then
2907 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2908 echo "cannot run remote command on $HOST with $myPDSH"
2912 echo "CMD: $HOST $@" >&2
2913 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2916 if [ "$myPDSH" = "rsh" ]; then
2917 # we need this because rsh does not return exit code of an executed command
2918 local command_status="$TMP/cs"
2919 rsh $HOST ":> $command_status"
2920 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2921 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2922 echo command failed >$command_status"
2923 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2928 # print HOSTNAME for myPDSH="no_dsh"
2929 if [[ $myPDSH = no_dsh ]]; then
2930 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2932 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2935 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2937 return ${PIPESTATUS[0]}
2941 do_node --verbose "$@"
2944 single_local_node () {
2945 [ "$1" = "$HOSTNAME" ]
2948 # Outputs environment variable assignments that should be passed to remote nodes
2952 local facets=$(get_facets)
2955 for var in ${!MODOPTS_*}; do
2956 value=${!var//\"/\\\"}
2957 echo -n " ${var}=\"$value\""
2960 for facet in ${facets//,/ }; do
2962 if [ -n "${!var}" ]; then
2963 echo -n " $var=${!var}"
2967 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2968 if [ -n "${!var}" ]; then
2969 echo -n " $var=${!var}"
2973 for var in VERBOSE; do
2974 if [ -n "${!var}" ]; then
2975 echo -n " $var=${!var}"
2979 if [ -n "$FSTYPE" ]; then
2980 echo -n " FSTYPE=$FSTYPE"
2983 for var in LNETLND NETTYPE; do
2984 if [ -n "${!var}" ]; then
2985 echo -n " $var=${!var}"
2992 # do not stripe off hostname if verbose, bug 19215
2993 if [ x$1 = x--verbose ]; then
3001 if single_local_node $rnodes; then
3003 do_nodev $rnodes "$@"
3005 do_node $rnodes "$@"
3010 # This is part from do_node
3013 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3014 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3016 export FANOUT=$(get_node_count "${rnodes//,/ }")
3018 echo "CMD: $rnodes $@" >&2
3019 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3022 # do not replace anything from pdsh output if -N is used
3023 # -N Disable hostname: prefix on lines of output.
3024 if $verbose || [[ $myPDSH = *-N* ]]; then
3025 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3027 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3029 return ${PIPESTATUS[0]}
3033 # Execute commands on a single service's host
3035 # The \a facet (service) may be on a local or remote node, which is
3036 # determined at the time the command is run.
3038 # usage: do_facet $facet command [arg ...]
3042 local HOST=$(facet_active_host $facet)
3043 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3047 # Function: do_facet_random_file $FACET $FILE $SIZE
3048 # Creates FILE with random content on the given FACET of given SIZE
3050 do_facet_random_file() {
3054 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3055 do_facet $facet "$cmd 2>/dev/null"
3058 do_facet_create_file() {
3062 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3063 do_facet $facet "$cmd 2>/dev/null"
3067 do_nodes --verbose "$@"
3073 # make sure its not already running
3075 rm -f $TMP/${facet}active
3076 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3077 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3079 if [[ $(facet_fstype $facet) == zfs ]]; then
3081 # After formatting a ZFS target, "cachefile=none" property will
3082 # be set on the ZFS storage pool so that the pool is not
3083 # automatically imported on system startup. And then the pool
3084 # will be exported so as to leave the importing and exporting
3085 # operations handled by mount_facet() and stop() separately.
3087 refresh_partition_table $facet $(facet_vdevice $facet)
3088 disable_zpool_cache $facet
3093 # Device formatted as ost
3096 local DEVNAME=OSTDEV$num
3098 local fstype=$(facet_fstype ost$num)
3102 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3103 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3105 #try $OSTZFSDEVn - independent of vdev
3106 DEVNAME=OSTZFSDEV$num
3107 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3109 error "unknown fstype!";;
3115 # Physical device location of data
3121 local fstype=$(facet_fstype ost$num)
3125 # vdevs are not supported by ldiskfs
3128 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3129 # Device formatted by zfs
3131 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3133 error "unknown fstype!";;
3139 # Logical device formatted for lustre
3142 local DEVNAME=MDSDEV$num
3144 local fstype=$(facet_fstype mds$num)
3148 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3149 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3151 # try $MDSZFSDEVn - independent of vdev
3152 DEVNAME=MDSZFSDEV$num
3153 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3155 error "unknown fstype!";;
3161 # Physical location of data
3165 local fstype=$(facet_fstype mds$num)
3169 # vdevs are not supported by ldiskfs
3172 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3173 # Device formatted by ZFS
3174 local DEVNAME=MDSDEV$num
3175 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3177 error "unknown fstype!";;
3185 local fstype=$(facet_fstype mgs)
3189 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3190 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3191 DEVPTR=$(mdsdevname 1)
3196 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3197 ( [ -z "$MGSZFSDEV" ] &&
3198 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3199 DEVPTR=$(mdsdevname 1)
3201 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3204 error "unknown fstype!";;
3213 local fstype=$(facet_fstype mgs)
3217 # vdevs are not supported by ldiskfs
3220 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3221 ( [ -z "$MGSDEV" ] &&
3222 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3223 VDEVPTR=$(mdsvdevname 1)
3224 elif [ -n "$MGSDEV" ]; then
3228 error "unknown fstype!";;
3236 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3238 local var=${facet}_MOUNT
3239 eval mntpt=${!var:-${MOUNT}-$facet}
3246 local dev=$(facet_device $facet)
3247 local mnt=$(facet_mntpt $facet)
3250 if ! do_facet $facet test -b $dev; then
3253 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3258 local dev=$(facet_device $facet)
3259 local mnt=$(facet_mntpt $facet)
3261 do_facet $facet $UMOUNT $mnt
3265 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3270 local ds=$(facet_device $facet)
3271 local mnt=$(facet_mntpt $facet)
3276 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3277 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3278 do_facet $facet $ZFS set canmount=noauto $ds
3280 # The "legacy" mount method is used here because "zfs unmount $mnt"
3281 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3282 # targets are not available at the time, the stat(2) on $MOUNT will
3285 do_facet $facet $ZFS set mountpoint=legacy $ds
3286 do_facet $facet mount -t zfs $ds $mnt
3287 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3288 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3293 local ds=$(facet_device $facet)
3294 local mnt=$(facet_mntpt $facet)
3295 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3296 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3297 local mntpt=${!var_mntpt}
3298 local canmnt=${!var_canmnt}
3302 do_facet $facet umount $mnt
3303 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3304 do_facet $facet $ZFS set canmount=$canmnt $ds
3310 local fstype=$(facet_fstype $facet)
3312 mount_$fstype $facet
3317 local fstype=$(facet_fstype $facet)
3319 unmount_$fstype $facet
3326 # make sure we are using the primary server, so test-framework will
3327 # be able to clean up properly.
3328 activemds=`facet_active mds1`
3329 if [ $activemds != "mds1" ]; then
3333 local clients=$CLIENTS
3334 [ -z $clients ] && clients=$(hostname)
3336 zconf_umount_clients $clients $MOUNT "$*" || true
3337 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3339 [ "$CLIENTONLY" ] && return
3340 # The add fn does rm ${facet}active file, this would be enough
3341 # if we use do_facet <facet> only after the facet added, but
3342 # currently we use do_facet mds in local.sh
3343 for num in `seq $MDSCOUNT`; do
3345 rm -f ${TMP}/mds${num}active
3347 combined_mgs_mds && rm -f $TMP/mgsactive
3349 for num in `seq $OSTCOUNT`; do
3351 rm -f $TMP/ost${num}active
3354 if ! combined_mgs_mds ; then
3361 cleanup_echo_devs () {
3362 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3364 for dev in $devs; do
3365 $LCTL --device $dev cleanup
3366 $LCTL --device $dev detach
3371 nfs_client_mode && return
3372 cifs_client_mode && return
3381 combined_mgs_mds () {
3382 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3383 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3387 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3391 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3397 local fsname=${3:-"$FSNAME"}
3398 local type=$(facet_type $facet)
3399 local index=$(facet_index $facet)
3400 local fstype=$(facet_fstype $facet)
3401 local host=$(facet_host $facet)
3406 if [ $type == MGS ] || ( [ $type == MDS ] &&
3407 [ "$dev" == $(mgsdevname) ] &&
3408 [ "$host" == "$(facet_host mgs)" ] ); then
3411 opts="--mgsnode=$MGSNID"
3414 if [ $type != MGS ]; then
3415 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3419 var=${facet}failover_HOST
3420 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3421 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3424 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3425 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3427 if [ $type == MDS ]; then
3428 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3429 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3430 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3431 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3432 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3434 if [ $fstype == ldiskfs ]; then
3435 # Check for wide striping
3436 if [ $OSTCOUNT -gt 160 ]; then
3437 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3438 fs_mkfs_opts+="-O large_xattr"
3442 if [ -n "${!var}" ]; then
3443 fs_mkfs_opts+=" -J device=${!var}"
3445 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3447 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3451 if [ $type == OST ]; then
3452 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3453 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3455 if [ $fstype == ldiskfs ]; then
3457 if [ -n "${!var}" ]; then
3458 fs_mkfs_opts+=" -J device=${!var}"
3460 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3465 opts+=" --backfstype=$fstype"
3468 if [ -n "${!var}" ]; then
3469 opts+=" --device-size=${!var}"
3472 var=$(upper $fstype)_MKFS_OPTS
3473 fs_mkfs_opts+=${!var:+" ${!var}"}
3475 var=${type}_FS_MKFS_OPTS
3476 fs_mkfs_opts+=${!var:+" ${!var}"}
3478 if [ -n "${fs_mkfs_opts## }" ]; then
3479 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3483 opts+=${!var:+" ${!var}"}
3488 check_ost_indices() {
3489 local index_count=${#OST_INDICES[@]}
3490 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3492 # OST count is greater than the index count in $OST_INDEX_LIST.
3493 # We need check whether there are duplicate indices.
3497 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3498 index=$(facet_index ost$i)
3499 for j in $(seq 0 $((index_count - 1))); do
3500 [[ $index -ne ${OST_INDICES[j]} ]] ||
3501 error "ost$i has the same index $index as ost$((j+1))"
3512 echo "Format mgs: $(mgsdevname)"
3513 reformat_external_journal mgs
3514 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3515 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3525 echo "Format mds$num: $(mdsdevname $num)"
3526 reformat_external_journal mds$num
3527 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3528 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3529 ${quiet:+>/dev/null} || exit 10
3538 echo "Format ost$num: $(ostdevname $num)"
3539 reformat_external_journal ost$num
3540 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3541 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3542 ${quiet:+>/dev/null} || exit 10
3547 # Set hostid for ZFS/SPL zpool import protection
3548 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3550 # We need ldiskfs here, may as well load them all
3552 [ "$CLIENTONLY" ] && return
3553 echo Formatting mgs, mds, osts
3554 if ! combined_mgs_mds ; then
3558 for num in $(seq $MDSCOUNT); do
3562 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3564 for num in $(seq $OSTCOUNT); do
3570 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3574 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3578 # 0: success, the old identity set already.
3579 # 1: success, the old identity does not set.
3584 local j=`expr $num - 1`
3585 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3587 if [ -z "$MDT" ]; then
3591 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3594 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3596 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3599 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3601 if [ $old = "NONE" ]; then
3610 zconf_umount `hostname` $1 || error "umount failed"
3611 zconf_mount `hostname` $1 || error "mount failed"
3619 rm -f $TMP/${facet}active
3620 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3625 local mdt_count=${1:-$MDSCOUNT}
3626 local ost_count=${2:-$OSTCOUNT}
3629 for num in $(seq $mdt_count); do
3630 DEVNAME=$(mdsdevname $num)
3631 writeconf_facet mds$num $DEVNAME || rc=$?
3634 for num in $(seq $ost_count); do
3635 DEVNAME=$(ostdevname $num)
3636 writeconf_facet ost$num $DEVNAME || rc=$?
3642 nfs_client_mode && return
3643 cifs_client_mode && return
3645 sanity_mount_check ||
3646 error "environments are insane!"
3650 if [ -z "$CLIENTONLY" ]; then
3651 echo Setup mgs, mdt, osts
3652 echo $WRITECONF | grep -q "writeconf" && \
3654 if ! combined_mgs_mds ; then
3655 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3658 for num in `seq $MDSCOUNT`; do
3659 DEVNAME=$(mdsdevname $num)
3660 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3662 # We started mds, now we should set failover variables properly.
3663 # Set mds${num}failover_HOST if it is not set (the default failnode).
3664 local varname=mds${num}failover_HOST
3665 if [ -z "${!varname}" ]; then
3666 eval mds${num}failover_HOST=$(facet_host mds$num)
3669 if [ $IDENTITY_UPCALL != "default" ]; then
3670 switch_identity $num $IDENTITY_UPCALL
3673 for num in `seq $OSTCOUNT`; do
3674 DEVNAME=$(ostdevname $num)
3675 start ost$num $DEVNAME $OST_MOUNT_OPTS
3677 # We started ost$num, now we should set ost${num}failover variable properly.
3678 # Set ost${num}failover_HOST if it is not set (the default failnode).
3679 varname=ost${num}failover_HOST
3680 if [ -z "${!varname}" ]; then
3681 eval ost${num}failover_HOST=$(facet_host ost${num})
3689 # wait a while to allow sptlrpc configuration be propogated to targets,
3690 # only needed when mounting new target devices.
3695 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3697 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3700 if [ "$MOUNT_2" ]; then
3701 mount_client $MOUNT2
3702 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3707 # by remounting mdt before ost, initial connect from mdt to ost might
3708 # timeout because ost is not ready yet. wait some time to its fully
3709 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3710 # by a context negotiation rpc with $TIMEOUT.
3711 # FIXME better by monitoring import status.
3714 sleep $((TIMEOUT + 5))
3720 mounted_lustre_filesystems() {
3721 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3724 init_facet_vars () {
3725 [ "$CLIENTONLY" ] && return 0
3732 eval export ${facet}_dev=${device}
3733 eval export ${facet}_opt=\"$@\"
3735 local dev=${facet}_dev
3737 # We need to loop for the label
3738 # in case its not initialized yet.
3739 for wait_time in {0,1,3,5,10}; do
3741 if [ $wait_time -gt 0 ]; then
3742 echo "${!dev} not yet initialized,"\
3743 "waiting ${wait_time} seconds."
3747 local label=$(devicelabel ${facet} ${!dev})
3749 # Check to make sure the label does
3750 # not include ffff at the end of the label.
3751 # This indicates it has not been initialized yet.
3753 if [[ $label =~ [f|F]{4}$ ]]; then
3754 # label is not initialized, unset the result
3755 # and either try again or fail
3762 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3764 eval export ${facet}_svc=${label}
3766 local varname=${facet}failover_HOST
3767 if [ -z "${!varname}" ]; then
3768 eval export $varname=$(facet_host $facet)
3771 varname=${facet}_HOST
3772 if [ -z "${!varname}" ]; then
3773 eval export $varname=$(facet_host $facet)
3776 # ${facet}failover_dev is set in cfg file
3777 varname=${facet}failover_dev
3778 if [ -n "${!varname}" ] ; then
3779 eval export ${facet}failover_dev=${!varname}
3781 eval export ${facet}failover_dev=$device
3784 # get mount point of already mounted device
3785 # is facet_dev is already mounted then use the real
3786 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3787 # i.e. ${facet}_MOUNT if specified by user or default
3788 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3789 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3790 if [ -z $mntpt ]; then
3791 mntpt=$(facet_mntpt $facet)
3793 eval export ${facet}_MOUNT=$mntpt
3796 init_facets_vars () {
3799 if ! remote_mds_nodsh; then
3800 for num in $(seq $MDSCOUNT); do
3801 DEVNAME=`mdsdevname $num`
3802 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3806 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3808 if ! remote_ost_nodsh; then
3809 for num in $(seq $OSTCOUNT); do
3810 DEVNAME=$(ostdevname $num)
3811 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3816 osc_ensure_active () {
3821 while [ $period -lt $timeout ]; do
3822 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3823 if [ $count -eq 0 ]; then
3827 echo "There are $count OST are inactive, wait $period seconds, and try again"
3829 period=$((period+3))
3832 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3835 set_conf_param_and_check() {
3839 local ORIG=$(do_facet $myfacet "$TEST")
3840 if [ $# -gt 3 ]; then
3846 echo "Setting $PARAM from $ORIG to $FINAL"
3847 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3848 error "conf_param $PARAM failed"
3850 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3851 error "check $PARAM failed!"
3854 init_param_vars () {
3856 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3858 log "Using TIMEOUT=$TIMEOUT"
3860 osc_ensure_active $SINGLEMDS $TIMEOUT
3861 osc_ensure_active client $TIMEOUT
3863 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3864 local current_jobid_var=$($LCTL get_param -n jobid_var)
3866 if [ $JOBID_VAR = "existing" ]; then
3867 echo "keeping jobstats as $current_jobid_var"
3868 elif [ $current_jobid_var != $JOBID_VAR ]; then
3869 echo "seting jobstats to $JOBID_VAR"
3871 set_conf_param_and_check client \
3872 "$LCTL get_param -n jobid_var" \
3873 "$FSNAME.sys.jobid_var" $JOBID_VAR
3876 echo "jobstats not supported by server"
3879 if [ $QUOTA_AUTO -ne 0 ]; then
3880 if [ "$ENABLE_QUOTA" ]; then
3881 echo "enable quota as required"
3882 setup_quota $MOUNT || return 2
3884 echo "disable quota as required"
3885 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3891 nfs_client_mode () {
3892 if [ "$NFSCLIENT" ]; then
3893 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3894 local clients=$CLIENTS
3895 [ -z $clients ] && clients=$(hostname)
3897 # FIXME: remove hostname when 19215 fixed
3898 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3899 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3900 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3901 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3903 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3909 cifs_client_mode () {
3910 [ x$CIFSCLIENT = xyes ] &&
3911 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3914 check_config_client () {
3917 local mounted=$(mount | grep " $mntpt ")
3918 if [ "$CLIENTONLY" ]; then
3920 # CLIENTONLY should not depend on *_HOST settings
3921 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3922 # in theory someone could create a new,
3923 # client-only config file that assumed lustre was already
3924 # configured and didn't set the MGSNID. If MGSNID is not set,
3925 # then we should use the mgs nid currently being used
3926 # as the default value. bug 18021
3927 [[ x$MGSNID = x ]] &&
3930 if [[ x$mgc != xMGC$MGSNID ]]; then
3931 if [ "$mgs_HOST" ]; then
3932 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3933 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3934 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3940 local myMGS_host=$mgs_HOST
3941 if [ "$NETTYPE" = "ptl" ]; then
3942 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3945 echo Checking config lustre mounted on $mntpt
3946 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3947 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3949 # if [ "$mgshost" != "$myMGS_host" ]; then
3950 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3951 # Please use correct config or set mds_HOST correctly!"
3956 check_config_clients () {
3957 local clients=${CLIENTS:-$HOSTNAME}
3960 nfs_client_mode && return
3961 cifs_client_mode && return
3963 do_rpc_nodes "$clients" check_config_client $mntpt
3965 sanity_mount_check || error "environments are insane!"
3969 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3970 local cltimeout=$(lctl get_param -n timeout)
3971 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3972 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3979 [ -z $mntpt ] && return 1
3980 local mounted=$(mounted_lustre_filesystems)
3982 echo $mounted' ' | grep -w -q $mntpt' '
3986 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3990 # empty lustre filesystem may have empty directories lost+found and .lustre
3992 # exclude .lustre & lost+found
3993 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3994 -print | wc -l) = 1 ] || return 1
3995 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3996 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3997 # exclude .lustre/fid (LU-2780)
3998 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3999 -print | wc -l) = 1 ] || return 1
4001 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4006 check_and_setup_lustre() {
4008 nfs_client_mode && return
4009 cifs_client_mode && return
4011 local MOUNTED=$(mounted_lustre_filesystems)
4015 # both MOUNT and MOUNT2 are not mounted
4016 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4017 [ "$REFORMAT" = "yes" ] && formatall
4018 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4020 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4021 export I_MOUNTED=yes
4025 elif is_mounted $MOUNT2; then
4027 # MOUNT2 is mounted, while MOUNT_2 is not set
4028 if ! [ "$MOUNT_2" ]; then
4029 cleanup_mount $MOUNT2
4030 export I_UMOUNTED2=yes
4033 # MOUNT2 is mounted, MOUNT_2 is set
4035 # FIXME: what to do if check_config failed?
4037 # 1) remote client has mounted other Lustre fs ?
4038 # 2) it has insane env ?
4039 # let's try umount MOUNT2 on all clients and mount it again:
4040 if ! check_config_clients $MOUNT2; then
4041 cleanup_mount $MOUNT2
4042 restore_mount $MOUNT2
4043 export I_MOUNTED2=yes
4048 # MOUNT is mounted MOUNT2 is not mounted
4049 elif [ "$MOUNT_2" ]; then
4050 restore_mount $MOUNT2
4051 export I_MOUNTED2=yes
4055 # FIXME: what to do if check_config failed?
4057 # 1) remote client has mounted other Lustre fs?
4058 # 2) lustre is mounted on remote_clients atall ?
4059 check_config_clients $MOUNT
4063 set_default_debug_nodes $(comma_list $(nodes_list))
4066 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
4068 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4069 facets="$(get_facets OST)"
4070 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4071 facets="$facets,$(get_facets MDS)"
4072 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4073 facets="$facets,mgs"
4074 local nodes="$(facets_hosts ${facets})"
4075 if [ -n "$nodes" ] ; then
4076 do_nodes $nodes "$LCTL set_param \
4077 osd-ldiskfs.track_declares_assert=1 || true"
4086 #Enable remote MDT create for testing
4087 for num in $(seq $MDSCOUNT); do
4089 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4093 if [ "$ONLY" == "setup" ]; then
4099 local clients=${CLIENTS:-$HOSTNAME}
4102 zconf_mount_clients $clients $mntpt
4106 local clients=${CLIENTS:-$HOSTNAME}
4109 zconf_umount_clients $clients $mntpt
4112 cleanup_and_setup_lustre() {
4113 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4114 lctl set_param debug=0 || true
4116 if [ "$ONLY" == "cleanup" ]; then
4120 check_and_setup_lustre
4123 # Get all of the server target devices from a given server node and type.
4130 if [ "$type" == ost ]; then
4131 devs=$(get_osd_param $node "" mntdev)
4133 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4135 for dev in $devs; do
4137 *loop*) do_node $node "losetup $dev" | \
4138 sed -e "s/.*(//" -e "s/).*//" ;;
4144 # Get all of the server target devices.
4149 # Master MDS parameters used by lfsck
4150 MDTNODE=$(facet_active_host $SINGLEMDS)
4151 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4155 for node in $(mdts_nodes); do
4156 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4162 for node in $(osts_nodes); do
4163 OSTDEVS[i]=$(get_mnt_devs $node ost)
4168 # Run e2fsck on MDT or OST device.
4173 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4174 local log=$TMP/e2fsck.log
4178 do_node $node $cmd 2>&1 | tee $log
4180 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4182 if [ $MDSCOUNT -gt 1 ]; then
4183 skip "DNE mode isn't supported!"
4187 error "It's not DNE mode."
4192 [ $rc -le $FSCK_MAX_ERR ] ||
4193 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4199 # Run resize2fs on MDT or OST device.
4208 do_facet $facet "$RESIZE2FS $opts $device $size"
4211 # verify a directory is shared among nodes.
4212 check_shared_dir() {
4214 local list=${2:-$(comma_list $(nodes_list))}
4216 [ -z "$dir" ] && return 1
4217 do_rpc_nodes "$list" check_logdir $dir
4218 check_write_access $dir "$list" || return 1
4223 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4224 $LCTL set_param printk=+lfsck
4225 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4227 for k in $(seq $MDSCOUNT); do
4228 # wait up to 10+1 minutes for LFSCK to complete
4229 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4230 mdd.$(facet_svc mds${k}).lfsck_layout |
4231 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4232 error "MDS${k} layout isn't the expected 'completed'"
4233 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4234 mdd.$(facet_svc mds${k}).lfsck_namespace |
4235 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4236 error "MDS${k} namespace isn't the expected 'completed'"
4238 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4239 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4240 awk '/repaired/ { print $2 }' | calc_sum)
4241 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4242 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4243 awk '/repaired/ { print $2 }' | calc_sum)
4244 local repaired=$((rep_mdt + rep_ost))
4245 [ $repaired -eq 0 ] ||
4246 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4249 dump_file_contents() {
4255 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4256 error_noexit false \
4257 "Invalid parameters for dump_file_contents()"
4260 for node in ${nodes}; do
4261 do_node $node "for i in \\\$(find $dir -type f); do
4262 echo ====\\\${i}=======================;
4264 done" >> ${logname}.${node}.log
4268 dump_command_output() {
4274 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4275 error_noexit false \
4276 "Invalid parameters for dump_command_output()"
4280 for node in ${nodes}; do
4281 do_node $node "echo ====${cmd}=======================;
4282 $cmd" >> ${logname}.${node}.log
4289 # dump file contents from /proc/spl in case of zfs test
4290 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4291 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4292 dump_command_output \
4293 "$(osts_nodes)" "zpool events -v" "${logname}"
4296 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4297 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4298 dump_command_output \
4299 "$(mdts_nodes)" "zpool events -v" "${logname}"
4303 check_and_cleanup_lustre() {
4304 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4305 "$TESTSUITE" != "sanity-scrub" ]; then
4309 if is_mounted $MOUNT; then
4310 if $DO_CLEANUP; then
4311 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4312 error "remove sub-test dirs failed"
4316 [ "$ENABLE_QUOTA" ] && restore_quota || true
4319 if [ "$I_UMOUNTED2" = "yes" ]; then
4320 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4323 if [ "$I_MOUNTED2" = "yes" ]; then
4324 cleanup_mount $MOUNT2
4327 if [ "$I_MOUNTED" = "yes" ]; then
4328 cleanupall -f || error "cleanup failed"
4336 wait_for_function () {
4339 # suppress fn both stderr and stdout
4340 if [ "$1" = "--quiet" ]; then
4342 quiet=" > /dev/null 2>&1"
4354 eval $fn $quiet && return 0
4356 wait=$((wait + sleep))
4357 [ $wait -lt $max ] || return 1
4358 echo waiting $fn, $((max - wait)) secs left ...
4368 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4369 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4370 echo "Network not available!"
4374 echo `date +"%H:%M:%S (%s)"` network interface is UP
4382 # Convert a space-delimited list to a comma-delimited list. If the input is
4383 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4385 # echo is used to convert newlines to spaces, since it doesn't
4386 # introduce a trailing space as using "tr '\n' ' '" does
4387 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4393 echo $list | grep -qw $item
4396 # list, excluded are the comma separated lists
4397 exclude_items_from_list () {
4403 for item in ${excluded//,/ }; do
4404 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4406 echo $(comma_list $list)
4409 # list, expand are the comma separated lists
4411 local list=${1//,/ }
4412 local expand=${2//,/ }
4415 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4416 echo $(comma_list $expanded)
4419 testslist_filter () {
4420 local script=$LUSTRE/tests/${TESTSUITE}.sh
4422 [ -f $script ] || return 0
4424 local start_at=$START_AT
4425 local stop_at=$STOP_AT
4427 local var=${TESTSUITE//-/_}_START_AT
4428 [ x"${!var}" != x ] && start_at=${!var}
4429 var=${TESTSUITE//-/_}_STOP_AT
4430 [ x"${!var}" != x ] && stop_at=${!var}
4432 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4433 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4434 /^'${start_at}'$/ {flag = 0}
4435 {if (flag == 1) print $0}
4436 /^'${stop_at}'$/ { flag = 1 }'
4440 (cd `dirname $1`; echo $PWD/`basename $1`)
4444 local types=${1:-"OST MDS MGS"}
4448 for entry in $types; do
4449 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4450 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4453 MGS ) list="$list $name";;
4454 MDS|OST|AGT ) local count=${type}COUNT
4455 for ((i=1; i<=${!count}; i++)) do
4456 list="$list ${name}$i"
4458 * ) error "Invalid facet type"
4462 echo $(comma_list $list)
4465 ##################################
4466 # Adaptive Timeouts funcs
4469 # only check mds, we assume at_max is the same on all nodes
4470 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4471 if [ $at_max -eq 0 ]; then
4482 # suppose that all ost-s have the same $at value set
4483 [ $facet != "ost" ] || facet=ost1
4485 do_facet $facet "lctl get_param -n $at"
4503 if [ $facet == "ost" ]; then
4504 facet=$(get_facets OST)
4505 elif [ $facet == "mds" ]; then
4506 facet=$(get_facets MDS)
4508 hosts=$(expand_list $hosts $(facets_hosts $facet))
4511 do_nodes $hosts lctl set_param at_max=$at_max
4514 ##################################
4518 # OBD_FAIL_MDS_ALL_REQUEST_NET
4520 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4521 do_facet client "$1" || RC=$?
4522 do_facet $SINGLEMDS lctl set_param fail_loc=0
4527 # OBD_FAIL_MDS_ALL_REPLY_NET
4529 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4531 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4535 drop_reint_reply() {
4536 # OBD_FAIL_MDS_REINT_NET_REP
4538 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4540 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4544 drop_update_reply() {
4545 # OBD_FAIL_OUT_UPDATE_NET_REP
4549 do_facet mds${index} lctl set_param fail_loc=0x1701
4550 do_facet client "$@" || RC=$?
4551 do_facet mds${index} lctl set_param fail_loc=0
4556 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4559 local timeout=${2:-0}
4560 # default is (obd_timeout / 4) if unspecified
4561 echo "timeout is $timeout/$2"
4562 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4563 do_facet client "$1" || RC=$?
4564 do_facet client "sync"
4565 do_facet ost1 lctl set_param fail_loc=0
4569 drop_ldlm_cancel() {
4570 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4572 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4573 do_nodes $list lctl set_param fail_loc=0x304
4575 do_facet client "$@" || RC=$?
4577 do_nodes $list lctl set_param fail_loc=0
4581 drop_bl_callback_once() {
4583 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4584 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4585 do_facet client lctl set_param fail_loc=0x80000305
4586 do_facet client "$@" || rc=$?
4587 do_facet client lctl set_param fail_loc=0
4588 do_facet client lctl set_param fail_val=0
4589 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4593 drop_bl_callback() {
4595 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4596 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4597 do_facet client lctl set_param fail_loc=0x305
4598 do_facet client "$@" || rc=$?
4599 do_facet client lctl set_param fail_loc=0
4600 do_facet client lctl set_param fail_val=0
4601 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4606 #define OBD_FAIL_LDLM_REPLY 0x30c
4608 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4609 do_nodes $list lctl set_param fail_loc=0x30c
4611 do_facet client "$@" || RC=$?
4613 do_nodes $list lctl set_param fail_loc=0
4617 drop_ldlm_reply_once() {
4618 #define OBD_FAIL_LDLM_REPLY 0x30c
4620 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4621 do_nodes $list lctl set_param fail_loc=0x8000030c
4623 do_facet client "$@" || RC=$?
4625 do_nodes $list lctl set_param fail_loc=0
4633 echo "clearing fail_loc on $facet"
4634 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4637 set_nodes_failloc () {
4639 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4642 cancel_lru_locks() {
4643 #$LCTL mark "cancel_lru_locks $1 start"
4644 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4645 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4646 #$LCTL mark "cancel_lru_locks $1 stop"
4651 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4652 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4653 echo "$DEFAULT_LRU_SIZE"
4658 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4661 lru_resize_disable()
4663 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4669 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4675 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4676 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4677 echo there is still data in page cache $FILE ?
4678 lctl get_param -n $FILE
4686 DEBUGSAVE="$(lctl get_param -n debug)"
4690 [ -n "$DEBUGSAVE" ] && \
4691 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4696 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4699 debug_size_restore() {
4700 [ -n "$DEBUG_SIZE_SAVED" ] && \
4701 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4705 start_full_debug_logging() {
4710 local DEBUG_SIZE=150
4712 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4713 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4716 stop_full_debug_logging() {
4721 # prints bash call stack
4722 print_stack_trace() {
4725 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4726 local src=${BASH_SOURCE[$i]}
4727 local lineno=${BASH_LINENO[$i-1]}
4728 local funcname=${FUNCNAME[$i]}
4729 echo " = $src:$lineno:$funcname()"
4734 local TYPE=${TYPE:-"FAIL"}
4737 # do not dump logs if $1=false
4738 if [ "x$1" = "xfalse" ]; then
4743 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4744 (print_stack_trace 2) >&2
4746 # We need to dump the logs on all nodes
4748 gather_logs $(comma_list $(nodes_list))
4752 [ "$TESTSUITELOG" ] &&
4753 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4754 if [ -z "$*" ]; then
4755 echo "error() without useful message, please fix" > $LOGDIR/err
4757 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4758 echo "$@" > $LOGDIR/ignore
4760 echo "$@" > $LOGDIR/err
4764 # cleanup the env for failed tests
4768 ##################################
4770 ##################################
4778 local log=$TESTSUITELOG
4780 [ -f "$log" ] && grep -q FAIL $log && status=1
4794 # use only if we are ignoring failures for this test, bugno required.
4795 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4796 # e.g. error_ignore bz5494 "your message" or
4797 # error_ignore LU-5494 "your message"
4799 local TYPE="IGNORE ($1)"
4804 error_and_remount() {
4806 remount_client $MOUNT
4811 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4816 log " SKIP: $TESTSUITE $TESTNAME $@"
4818 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4819 skip_logged $TESTNAME "$@"
4822 echo "$@" > $LOGDIR/skip
4825 [[ -n "$TESTSUITELOG" ]] &&
4826 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4829 build_test_filter() {
4830 EXCEPT="$EXCEPT $(testslist_filter)"
4833 if [[ $O = [0-9]*-[0-9]* ]]; then
4834 for num in $(seq $(echo $O | tr '-' ' ')); do
4842 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4843 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4844 [ "$EXCEPT_SLOW" ] && \
4845 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4846 for E in $EXCEPT; do
4847 eval EXCEPT_${E}=true
4849 for E in $ALWAYS_EXCEPT; do
4850 eval EXCEPT_ALWAYS_${E}=true
4852 for E in $EXCEPT_SLOW; do
4853 eval EXCEPT_SLOW_${E}=true
4855 for G in $GRANT_CHECK_LIST; do
4856 eval GCHECK_ONLY_${G}=true
4861 if [[ $1 = [a-z]* ]]; then
4868 # print a newline if the last test was skipped
4869 export LAST_SKIPPED=
4870 export ALWAYS_SKIPPED=
4872 # Main entry into test-framework. This is called with the name and
4873 # description of a test. The name is used to find the function to run
4874 # the test using "test_$name".
4876 # This supports a variety of methods of specifying specific test to
4877 # run or not run. These need to be documented...
4882 export base=$(basetest $1)
4883 if [ -n "$ONLY" ]; then
4885 if [ ${!testname}x != x ]; then
4886 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4887 run_one_logged $1 "$2"
4891 if [ ${!testname}x != x ]; then
4892 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4893 run_one_logged $1 "$2"
4903 if [ ${!testname}x != x ]; then
4904 TESTNAME=test_$1 skip "skipping excluded test $1"
4907 testname=EXCEPT_$base
4908 if [ ${!testname}x != x ]; then
4909 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4912 testname=EXCEPT_ALWAYS_$1
4913 if [ ${!testname}x != x ]; then
4914 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4917 testname=EXCEPT_ALWAYS_$base
4918 if [ ${!testname}x != x ]; then
4919 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4922 testname=EXCEPT_SLOW_$1
4923 if [ ${!testname}x != x ]; then
4924 TESTNAME=test_$1 skip "skipping SLOW test $1"
4927 testname=EXCEPT_SLOW_$base
4928 if [ ${!testname}x != x ]; then
4929 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4935 run_one_logged $1 "$2"
4942 load_module ../libcfs/libcfs/libcfs
4954 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4959 strace -o $TMP/$1.strace -ttt $*
4961 log "FINISHED: $*: rc $RC"
4968 banner test complete, duration $duration sec
4969 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4970 echo duration $duration >>$TESTSUITELOG
4974 # Set TEST_STATUS here. It will be used for logging the result.
4977 if [[ -f $LOGDIR/err ]]; then
4979 elif [[ -f $LOGDIR/skip ]]; then
4982 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4986 local FFREE=$(do_node $SINGLEMDS \
4987 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4988 local FTOTAL=$(do_node $SINGLEMDS \
4989 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4991 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4995 echo -n "Resetting fail_loc on all nodes..."
4996 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
4997 fail_val=0 2>/dev/null || true"
5003 # Log a message (on all nodes) padded with "=" before and after.
5004 # Also appends a timestamp and prepends the testsuite name.
5007 EQUALS="===================================================================================================="
5009 msg="== ${TESTSUITE} $*"
5011 [[ $last != "=" && $last != " " ]] && msg="$msg "
5012 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5013 # always include at least == after the message
5014 log "$msg== $(date +"%H:%M:%S (%s)")"
5017 check_dmesg_for_errors() {
5019 local errors="VFS: Busy inodes after unmount of\|\
5020 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5021 group descriptors corrupted"
5023 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5024 [ -z "$res" ] && return 0
5025 echo "Kernel error detected: $res"
5030 # Run a single test function and cleanup after it.
5032 # This function should be run in a subshell so the test func can
5033 # exit() without stopping the whole script.
5038 export tfile=f${testnum}.${TESTSUITE}
5039 export tdir=d${testnum}.${TESTSUITE}
5040 export TESTNAME=test_$testnum
5041 local SAVE_UMASK=`umask`
5044 if ! grep -q $DIR /proc/mounts; then
5048 banner "test $testnum: $message"
5049 test_${testnum} || error "test_$testnum failed with $?"
5052 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5053 check_catastrophe || error "LBUG/LASSERT detected"
5054 check_dmesg_for_errors || error "Error in dmesg detected"
5055 if [ "$PARALLEL" != "yes" ]; then
5056 ps auxww | grep -v grep | grep -q multiop &&
5057 error "multiop still running"
5068 # Wrapper around run_one to ensure:
5069 # - test runs in subshell
5070 # - output of test is saved to separate log file for error reporting
5071 # - test result is saved to data file
5074 local BEFORE=$(date +%s)
5076 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5077 local test_log=$LOGDIR/$name
5078 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5079 local zfs_debug_log=$LOGDIR/$zfs_log_name
5081 rm -rf $LOGDIR/ignore
5083 local SAVE_UMASK=$(umask)
5087 log_sub_test_begin test_${1}
5088 (run_one $1 "$2") 2>&1 | tee -i $test_log
5089 local RC=${PIPESTATUS[0]}
5091 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5092 echo "test_$1 returned $RC" | tee $LOGDIR/err
5094 duration=$(($(date +%s) - $BEFORE))
5095 pass "$1" "(${duration}s)"
5097 if [[ -f $LOGDIR/err ]]; then
5098 TEST_ERROR=$(cat $LOGDIR/err)
5099 elif [[ -f $LOGDIR/ignore ]]; then
5100 TEST_ERROR=$(cat $LOGDIR/ignore)
5101 elif [[ -f $LOGDIR/skip ]]; then
5102 TEST_ERROR=$(cat $LOGDIR/skip)
5104 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5106 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5110 if [ -f $LOGDIR/err ]; then
5111 log_zfs_info "$zfs_debug_log"
5112 $FAIL_ON_ERROR && exit $RC
5121 # Print information of skipped tests to result.yml
5124 log_sub_test_begin $1
5126 log_sub_test_end "SKIP" "0" "0" "$@"
5130 (cd $(dirname $1); echo $PWD/$(basename $1))
5135 export base=$(basetest $1)
5136 [ "$CHECK_GRANT" == "no" ] && return 0
5138 testname=GCHECK_ONLY_${base}
5139 [ ${!testname}x == x ] && return 0
5141 echo -n "checking grant......"
5143 local clients=$CLIENTS
5144 [ -z "$clients" ] && clients=$(hostname)
5146 # sync all the data and make sure no pending data on server
5147 do_nodes $clients sync
5150 client_grant=$(do_nodes $clients \
5151 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5152 awk '{ total += $1 } END { printf("%0.0f", total) }')
5155 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5156 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5157 awk '{ total += $1 } END { printf("%0.0f", total) }')
5159 # check whether client grant == server grant
5160 if [[ $client_grant -ne $server_grant ]]; then
5161 echo "failed: client:${client_grant} server: ${server_grant}."
5162 do_nodes $(comma_list $(osts_nodes)) \
5163 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5164 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5167 echo "pass: client:${client_grant} server: ${server_grant}"
5171 ########################
5177 ost=`echo $1 | awk -F_ '{print $3}'`
5178 if [ -z $ost ]; then
5179 ost=`echo $1 | sed 's/-osc.*//'`
5184 ostuuid_from_index()
5186 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5189 ostname_from_index() {
5190 local uuid=$(ostuuid_from_index $1)
5194 index_from_ostuuid()
5196 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5199 mdtuuid_from_index()
5201 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5205 # Return unique identifier for given hostname
5208 echo $host_name | md5sum | cut -d' ' -f1
5212 # Returns list of ip addresses for each interface
5214 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5219 # Cache address list to avoid mutiple execution of local_addr_list
5220 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5222 for i in $LOCAL_ADDR_LIST ; do
5223 [[ "$i" == "$addr" ]] && return 0
5230 local is_local="IS_LOCAL_$(host_id $host_name)"
5231 if [ -z "${!is_local-}" ] ; then
5233 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5234 is_local_addr "$host_ip" && eval $is_local=1
5236 [[ "${!is_local}" == "1" ]]
5241 local_node $node && return 1
5248 for node in $(mdts_nodes); do
5249 remote_node $node && return 0
5256 [ "$CLIENTONLY" ] && return 0 || true
5257 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5262 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5263 MSKIPPED=1 && return 1
5270 for node in $(osts_nodes) ; do
5271 remote_node $node && return 0
5278 [ "$CLIENTONLY" ] && return 0 || true
5279 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5284 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5285 OSKIPPED=1 && return 1
5291 [ "$CLIENTONLY" ] && return 0 || true
5293 MGS=$(facet_host mgs)
5294 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5299 remote_mds_nodsh || remote_ost_nodsh || \
5300 $(single_local_node $(comma_list $(nodes_list)))
5304 remote_ost && remote_mds
5307 # Get the active nodes for facets.
5315 for facet in ${facets//,/ }; do
5316 nodes="$nodes $(facet_active_host $facet)"
5319 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5323 # Get all of the active MDS nodes.
5325 echo -n $(facets_nodes $(get_facets MDS))
5328 # Get all of the active OSS nodes.
5330 echo -n $(facets_nodes $(get_facets OST))
5333 # Get all of the active AGT (HSM agent) nodes.
5335 echo -n $(facets_nodes $(get_facets AGT))
5338 # Get all of the client nodes and active server nodes.
5340 local nodes=$HOSTNAME
5344 # CLIENTS (if specified) contains the local client
5345 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5347 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5348 nodes="$nodes $(facets_nodes $(get_facets))"
5351 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5355 # Get all of the remote client nodes and remote active server nodes.
5356 remote_nodes_list () {
5357 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5360 # Get all of the MDS nodes, including active and passive nodes.
5368 for i in $(seq $MDSCOUNT); do
5370 failover_host=mds${i}failover_HOST
5371 nodes="$nodes ${!host} ${!failover_host}"
5374 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5378 # Get all of the OSS nodes, including active and passive nodes.
5386 for i in $(seq $OSTCOUNT); do
5388 failover_host=ost${i}failover_HOST
5389 nodes="$nodes ${!host} ${!failover_host}"
5392 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5396 # Get all of the server nodes, including active and passive nodes.
5397 all_server_nodes () {
5402 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5404 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5408 # Get all of the client and server nodes, including active and passive nodes.
5410 local nodes=$HOSTNAME
5414 # CLIENTS (if specified) contains the local client
5415 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5417 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5418 nodes="$nodes $(all_server_nodes)"
5421 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5425 init_clients_lists () {
5426 # Sanity check: exclude the local client from RCLIENTS
5427 local clients=$(hostlist_expand "$RCLIENTS")
5428 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5430 # Sanity check: exclude the dup entries
5431 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5433 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5435 # Sanity check: exclude the dup entries from CLIENTS
5436 # for those configs which has SINGLCLIENT set to local client
5437 clients=$(for i in $clients; do echo $i; done | sort -u)
5439 CLIENTS=$(comma_list $clients)
5440 local -a remoteclients=($RCLIENTS)
5441 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5442 varname=CLIENT$((i + 2))
5443 eval $varname=${remoteclients[i]}
5446 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5449 get_random_entry () {
5452 rnodes=${rnodes//,/ }
5454 local -a nodes=($rnodes)
5455 local num=${#nodes[@]}
5456 local i=$((RANDOM * num * 2 / 65536))
5462 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5466 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5467 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5472 echo $nodes | wc -w || true
5476 local nodes=$(osts_nodes)
5477 local osscount=$(get_node_count "$nodes")
5478 [ ! "$OSTCOUNT" = "$osscount" ]
5482 local nodes=$(mdts_nodes)
5483 local mdtcount=$(get_node_count "$nodes")
5484 [ ! "$MDSCOUNT" = "$mdtcount" ]
5487 generate_machine_file() {
5488 local nodes=${1//,/ }
5489 local machinefile=$2
5491 for node in $nodes; do
5492 echo $node >>$machinefile || \
5493 { echo "can not generate machinefile $machinefile" && return 1; }
5498 local file=$1/stripe
5501 $LFS getstripe -v $file || error "getstripe $file failed"
5505 setstripe_nfsserver () {
5508 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5509 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5511 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5513 do_nodev $nfsserver lfs setstripe "$@"
5516 # Check and add a test group.
5522 local gid=$(getent group $group_name | cut -d: -f3)
5523 if [[ -n "$gid" ]]; then
5524 [[ "$gid" -eq "$group_id" ]] || {
5525 error_noexit "inconsistent group ID:" \
5526 "new: $group_id, old: $gid"
5530 groupadd -g $group_id $group_name
5537 # Check and add a test user.
5550 local uid=$(getent passwd $user_name | cut -d: -f3)
5551 if [[ -n "$uid" ]]; then
5552 if [[ "$uid" -eq "$user_id" ]]; then
5553 local dir=$(getent passwd $user_name | cut -d: -f6)
5554 if [[ "$dir" != "$home" ]]; then
5556 usermod -d $home $user_name
5560 error_noexit "inconsistent user ID:" \
5561 "new: $user_id, old: $uid"
5566 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5573 check_runas_id_ret() {
5575 local myRUNAS_UID=$1
5576 local myRUNAS_GID=$2
5579 if [ -z "$myRUNAS" ]; then
5580 error_exit "myRUNAS command must be specified for check_runas_id"
5583 $myRUNAS krb5_login.sh || \
5584 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5586 mkdir $DIR/d0_runas_test
5588 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5589 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5590 rm -rf $DIR/d0_runas_test
5595 local myRUNAS_UID=$1
5596 local myRUNAS_GID=$2
5599 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5600 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5601 Please set RUNAS_ID to some UID which exists on MDS and client or
5602 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5605 # obtain the UID/GID for MPI_USER
5609 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5610 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5612 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5613 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5616 # obtain and cache Kerberos ticket-granting ticket
5617 refresh_krb5_tgt() {
5618 local myRUNAS_UID=$1
5619 local myRUNAS_GID=$2
5622 if [ -z "$myRUNAS" ]; then
5623 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5626 CLIENTS=${CLIENTS:-$HOSTNAME}
5627 do_nodes $CLIENTS "set -x
5628 if ! $myRUNAS krb5_login.sh; then
5629 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5634 # Run multiop in the background, but wait for it to print
5635 # "PAUSING" to its stdout before returning from this function.
5636 multiop_bg_pause() {
5637 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5641 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5644 echo "$MULTIOP_PROG $FILE v$ARGS"
5645 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5647 echo "TMPPIPE=${TMPPIPE}"
5648 read -t 60 multiop_output < $TMPPIPE
5649 if [ $? -ne 0 ]; then
5654 if [ "$multiop_output" != "PAUSING" ]; then
5655 echo "Incorrect multiop output: $multiop_output"
5670 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5676 inodes_available () {
5677 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5678 sort -un | head -n1) || return 1
5682 mdsrate_inodes_available () {
5683 local min_inodes=$(inodes_available)
5684 echo $((min_inodes * 99 / 100))
5687 # reset llite stat counters
5688 clear_llite_stats(){
5689 lctl set_param -n llite.*.stats 0
5692 # sum llite stat items
5693 calc_llite_stats() {
5694 local res=$(lctl get_param -n llite.*.stats |
5695 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5699 # reset osc stat counters
5701 lctl set_param -n osc.*.osc_stats 0
5704 # sum osc stat items
5706 local res=$(lctl get_param -n osc.*.osc_stats |
5707 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5712 awk '{sum += $1} END { printf("%0.0f", sum) }'
5715 calc_osc_kbytes () {
5716 df $MOUNT > /dev/null
5717 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5720 # save_lustre_params(comma separated facet list, parameter_mask)
5721 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5722 save_lustre_params() {
5728 for facet in ${facets//,/ }; do
5729 node=$(facet_active_host $facet)
5730 [[ *\ $node\ * = " $nodes " ]] && continue
5731 nodes="$nodes $node"
5733 do_node $node "$LCTL get_param $2 |
5734 while read s; do echo $facet \\\$s; done"
5738 # restore lustre parameters from input stream, produces by save_lustre_params
5739 restore_lustre_params() {
5744 while IFS=" =" read facet name val; do
5745 do_facet $facet "$LCTL set_param -n $name $val"
5749 check_catastrophe() {
5750 local nodes=${1:-$(comma_list $(nodes_list))}
5752 do_nodes $nodes "rc=0;
5753 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5754 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5755 echo \\\$(hostname -s): \\\$val;
5761 mdsrate_cleanup () {
5763 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5764 --nfiles $3 --dir $4 --filefmt $5 $6
5769 delayed_recovery_enabled () {
5770 local var=${SINGLEMDS}_svc
5771 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5774 ########################
5776 convert_facet2label() {
5779 if [ x$facet = xost ]; then
5783 local varsvc=${facet}_svc
5785 if [ -n ${!varsvc} ]; then
5788 error "No lablel for $facet!"
5792 get_clientosc_proc_path() {
5796 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5797 # used by MDT would not be changed.
5798 # mdt lov: fsname-mdtlov
5799 # mdt osc: fsname-OSTXXXX-osc
5800 mds_on_old_device() {
5801 local mds=${1:-"$SINGLEMDS"}
5803 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5804 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5805 > /dev/null 2>&1" && return 0
5810 get_mdtosc_proc_path() {
5812 local ost_label=${2:-"*OST*"}
5814 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5815 local mdt_label=$(convert_facet2label $mds_facet)
5816 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5818 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5819 mds_on_old_device $mds_facet; then
5820 echo "${ost_label}-osc"
5821 elif [[ $ost_label = *OST* ]]; then
5822 echo "${ost_label}-osc-${mdt_index}"
5824 echo "${ost_label}-osp-${mdt_index}"
5828 get_osc_import_name() {
5831 local label=$(convert_facet2label $ost)
5833 if [ "${facet:0:3}" = "mds" ]; then
5834 get_mdtosc_proc_path $facet $label
5838 get_clientosc_proc_path $label
5842 _wait_import_state () {
5845 local maxtime=${3:-$(max_recovery_time)}
5846 local error_on_failure=${4:-1}
5850 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5851 while [ "${CONN_STATE}" != "${expected}" ]; do
5852 if [ "${expected}" == "DISCONN" ]; then
5853 # for disconn we can check after proc entry is removed
5854 [ "x${CONN_STATE}" == "x" ] && return 0
5855 # with AT enabled, we can have connect request timeout near of
5856 # reconnect timeout and test can't see real disconnect
5857 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5859 if [ $i -ge $maxtime ]; then
5860 [ $error_on_failure -ne 0 ] && \
5861 error "can't put import for $CONN_PROC into ${expected}" \
5862 "state after $i sec, have ${CONN_STATE}"
5866 # Add uniq for multi-mount case
5867 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5871 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5875 wait_import_state() {
5878 local maxtime=${3:-$(max_recovery_time)}
5879 local error_on_failure=${4:-1}
5882 for param in ${params//,/ }; do
5883 _wait_import_state $state $param $maxtime $error_on_failure || return
5887 wait_import_state_mount() {
5888 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5892 wait_import_state $*
5895 # One client request could be timed out because server was not ready
5896 # when request was sent by client.
5897 # The request timeout calculation details :
5899 # /* We give the server rq_timeout secs to process the req, and
5900 # add the network latency for our local timeout. */
5901 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5902 # ptlrpc_at_get_net_latency(request) ;
5904 # ptlrpc_connect_import ()
5905 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5908 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5909 # ptlrpc_at_get_net_latency(request) ->
5910 # at_get (max (iat_net_latency=0, at_min)) = at_min
5913 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5914 # INITIAL_CONNECT_TIMEOUT + at_min
5916 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5917 # because we can not get this value in runtime,
5918 # the value depends on configure options, and it is not stored in /proc.
5920 # #define CONNECTION_SWITCH_MIN 5U
5921 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5923 request_timeout () {
5926 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5927 local init_connect_timeout=$TIMEOUT
5928 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5930 local at_min=$(at_get $facet at_min)
5932 echo $(( init_connect_timeout + at_min ))
5935 _wait_osc_import_state() {
5939 local target=$(get_osc_import_name $facet $ost_facet)
5940 local param="osc.${target}.ost_server_uuid"
5944 # 1. wait the deadline of client 1st request (it could be skipped)
5945 # 2. wait the deadline of client 2nd request
5946 local maxtime=$(( 2 * $(request_timeout $facet)))
5948 if [[ $facet == client* ]]; then
5949 # During setup time, the osc might not be setup, it need wait
5950 # until list_param can return valid value. And also if there
5951 # are mulitple osc entries we should list all of them before
5953 params=$($LCTL list_param $param 2>/dev/null || true)
5954 while [ -z "$params" ]; do
5955 if [ $i -ge $maxtime ]; then
5956 echo "can't get $param in $maxtime secs"
5961 params=$($LCTL list_param $param 2>/dev/null || true)
5965 if [[ $ost_facet = mds* ]]; then
5966 # no OSP connection to itself
5967 if [[ $facet = $ost_facet ]]; then
5970 param="osp.${target}.mdt_server_uuid"
5974 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5975 wait_import_state $expected "$params" $maxtime; then
5976 error "import is not in ${expected} state"
5983 wait_osc_import_state() {
5989 if [[ $facet = mds ]]; then
5990 for num in $(seq $MDSCOUNT); do
5991 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5994 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5998 _wait_mgc_import_state() {
6001 local error_on_failure=${3:-1}
6002 local param="mgc.*.mgs_server_uuid"
6006 # 1. wait the deadline of client 1st request (it could be skipped)
6007 # 2. wait the deadline of client 2nd request
6008 local maxtime=$(( 2 * $(request_timeout $facet)))
6010 if [[ $facet == client* ]]; then
6011 # During setup time, the osc might not be setup, it need wait
6012 # until list_param can return valid value. And also if there
6013 # are mulitple osc entries we should list all of them before
6015 params=$($LCTL list_param $param 2>/dev/null || true)
6016 while [ -z "$params" ]; do
6017 if [ $i -ge $maxtime ]; then
6018 echo "can't get $param in $maxtime secs"
6023 params=$($LCTL list_param $param 2>/dev/null || true)
6026 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6027 wait_import_state $expected "$params" $maxtime \
6028 $error_on_failure; then
6029 if [ $error_on_failure -ne 0 ]; then
6030 error "import is not in ${expected} state"
6038 wait_mgc_import_state() {
6041 local error_on_failure=${3:-1}
6044 if [[ $facet = mds ]]; then
6045 for num in $(seq $MDSCOUNT); do
6046 _wait_mgc_import_state mds$num "$expected" \
6047 $error_on_failure || return
6050 _wait_mgc_import_state "$facet" "$expected"
6051 $error_on_failure || return
6055 wait_dne_interconnect() {
6058 if [ $MDSCOUNT -gt 1 ]; then
6059 for num in $(seq $MDSCOUNT); do
6060 wait_osc_import_state mds mds$num FULL
6065 get_clientmdc_proc_path() {
6069 get_clientmgc_proc_path() {
6077 [ -z "$list" ] && return 0
6079 # Add paths to lustre tests for 32 and 64 bit systems.
6080 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6081 local TESTPATH="$RLUSTRE/tests:"
6082 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6083 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6086 wait_clients_import_state () {
6093 if [ "$FAILURE_MODE" = HARD ]; then
6094 facets=$(facets_on_host $(facet_active_host $facet))
6097 for facet in ${facets//,/ }; do
6098 local label=$(convert_facet2label $facet)
6101 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6102 $label).ost_server_uuid" ;;
6103 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6104 $label).mds_server_uuid" ;;
6105 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6106 $label).mgs_server_uuid" ;;
6107 *) error "unknown facet!" ;;
6110 local params=$(expand_list $params $proc_path)
6113 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6115 error "import is not in ${expected} state"
6125 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6126 $LCTL get_param obdfilter.*.kbytesavail))
6127 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6128 $LCTL get_param -n obdfilter.*.tot_granted))
6129 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6130 $LCTL get_param -n obdfilter.*.kbytestotal))
6131 for ((i=0; i<${#AVAILA[@]}; i++)); do
6132 local -a AVAIL1=(${AVAILA[$i]//=/ })
6133 local -a TOTAL=(${TOTALA[$i]//=/ })
6134 GRANT=$((${GRANTA[$i]}/1024))
6135 # allow 1% of total space in bavail because of delayed
6136 # allocation with ZFS which might release some free space after
6137 # txg commit. For small devices, we set a mininum of 8MB
6138 local LIMIT=$((${TOTAL} / 100 + 8000))
6139 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6140 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6141 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6142 echo " FULL" || echo
6148 do_facet mgs lctl pool_list $1
6152 local fsname=${1%%.*}
6153 local poolname=${1##$fsname.}
6155 do_facet mgs lctl pool_new $1
6157 # get param should return err unless pool is created
6158 [[ $RC -ne 0 ]] && return $RC
6160 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6161 2>/dev/null || echo foo" "" || RC=1
6162 if [[ $RC -eq 0 ]]; then
6165 error "pool_new failed $1"
6170 add_pool_to_list () {
6171 local fsname=${1%%.*}
6172 local poolname=${1##$fsname.}
6174 local listvar=${fsname}_CREATED_POOLS
6175 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6179 remove_pool_from_list () {
6180 local fsname=${1%%.*}
6181 local poolname=${1##$fsname.}
6183 local listvar=${fsname}_CREATED_POOLS
6184 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6188 destroy_pool_int() {
6190 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6191 awk '$1 !~ /^Pool:/ {print $1}')
6192 for ost in $OSTS; do
6193 do_facet mgs lctl pool_remove $1 $ost
6195 do_facet mgs lctl pool_destroy $1
6198 # <fsname>.<poolname> or <poolname>
6200 local fsname=${1%%.*}
6201 local poolname=${1##$fsname.}
6203 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6207 pool_list $fsname.$poolname || return $?
6209 destroy_pool_int $fsname.$poolname
6211 [[ $RC -ne 0 ]] && return $RC
6213 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6214 2>/dev/null || echo foo" "foo" || RC=1
6216 if [[ $RC -eq 0 ]]; then
6217 remove_pool_from_list $fsname.$poolname
6219 error "destroy pool failed $1"
6225 local fsname=${1:-$FSNAME}
6227 local listvar=${fsname}_CREATED_POOLS
6231 [ x${!listvar} = x ] && return 0
6233 echo destroy the created pools: ${!listvar}
6234 for poolname in ${!listvar//,/ }; do
6235 destroy_pool $fsname.$poolname
6240 local fsname=${1:-$FSNAME}
6242 destroy_pools $fsname
6248 local ts=$(date +%s)
6251 if [[ ! -f "$YAML_LOG" ]]; then
6252 # init_logging is not performed before gather_logs,
6253 # so the $LOGDIR needs to be checked here
6254 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6257 [ -f $LOGDIR/shared ] && docp=false
6259 # dump lustre logs, dmesg
6261 prefix="$TESTLOG_PREFIX.$TESTNAME"
6263 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6265 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6266 echo "Dumping logs only on local client."
6267 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6268 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6273 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6274 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6275 if [ ! -f $LOGDIR/shared ]; then
6276 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6289 for i in $(seq 0 $num_mntpts); do
6290 cmd="ls -laf ${mntpt_root}$i/$dir"
6296 for pid in $pids; do
6303 # check_and_start_recovery_timer()
6304 # service_time = at_est2timeout(service_time);
6305 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6306 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6308 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6309 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6310 #define CONNECTION_SWITCH_MIN 5
6311 #define CONNECTION_SWITCH_INC 5
6312 max_recovery_time() {
6313 local init_connect_timeout=$((TIMEOUT / 20))
6314 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6316 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6317 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6319 echo -n $service_time
6322 recovery_time_min() {
6323 local connection_switch_min=5
6324 local connection_switch_inc=5
6325 local connection_switch_max
6326 local reconnect_delay_max
6327 local initial_connect_timeout
6331 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6332 (($connection_switch_min > $TIMEOUT)) &&
6333 max=$connection_switch_min || max=$TIMEOUT
6334 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6336 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6337 timeout_20=$((TIMEOUT/20))
6338 (($connection_switch_min > $timeout_20)) &&
6339 initial_connect_timeout=$connection_switch_min ||
6340 initial_connect_timeout=$timeout_20
6342 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6343 initial_connect_timeout))
6344 echo $((2 * reconnect_delay_max))
6347 get_clients_mount_count () {
6348 local clients=${CLIENTS:-`hostname`}
6350 # we need to take into account the clients mounts and
6351 # exclude mds/ost mounts if any;
6352 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6356 PROC_CLI="srpc_info"
6364 if [ $M -lt $N ]; then
6368 while [ $N -lt $M ]; do
6378 calc_connection_cnt() {
6381 # MDT->MDT = 2 * C(M, 2)
6385 comb_m2=$(combination $MDSCOUNT 2)
6387 local num_clients=$(get_clients_mount_count)
6389 local cnt_mdt2mdt=$((comb_m2 * 2))
6390 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6391 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6392 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6393 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6394 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6395 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6409 local cmd="$tgt.srpc.flavor"
6411 if [ $net == "any" ]; then
6416 if [ $dir != "any" ]; then
6421 log "Setting sptlrpc rule: $cmd"
6422 do_facet mgs "$LCTL conf_param $cmd"
6431 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6432 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6434 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6436 if [ "x$bulkspec" != "x" ]; then
6437 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6439 if [ "x$algs" != "x" ]; then
6440 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6442 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6443 if [ $bulk == "bulkn" ]; then
6444 bulk_count=`echo "$output" | grep "bulk flavor" \
6445 | grep "null/null" | wc -l`
6446 elif [ $bulk == "bulki" ]; then
6447 bulk_count=`echo "$output" | grep "bulk flavor" \
6448 | grep "/null" | grep -v "null/" | wc -l`
6450 bulk_count=`echo "$output" | grep "bulk flavor" \
6451 | grep -v "/null" | grep -v "null/" | wc -l`
6455 [ $bulk_count -lt $count ] && count=$bulk_count
6466 local clients=${CLIENTS:-`hostname`}
6468 for c in ${clients//,/ }; do
6469 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6470 tmpcnt=`count_flvr "$output" $flavor`
6471 cnt=$((cnt + tmpcnt))
6481 local clients=${CLIENTS:-`hostname`}
6483 for c in ${clients//,/ }; do
6484 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6485 tmpcnt=`count_flvr "$output" $flavor`
6486 cnt=$((cnt + tmpcnt))
6496 if [ $MDSCOUNT -le 1 ]; then
6501 for num in `seq $MDSCOUNT`; do
6502 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6503 tmpcnt=`count_flvr "$output" $flavor`
6504 cnt=$((cnt + tmpcnt))
6515 for num in `seq $MDSCOUNT`; do
6516 mdtosc=$(get_mdtosc_proc_path mds$num)
6517 mdtosc=${mdtosc/-MDT*/-MDT\*}
6518 output=$(do_facet mds$num lctl get_param -n \
6519 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6520 tmpcnt=`count_flvr "$output" $flavor`
6521 cnt=$((cnt + tmpcnt))
6530 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6531 count_flvr "$output" $flavor
6536 local dir=$1 # from to
6537 local flavor=$2 # flavor expected
6540 if [ $dir == "cli2mdt" ]; then
6541 res=`flvr_cnt_cli2mdt $flavor`
6542 elif [ $dir == "cli2ost" ]; then
6543 res=`flvr_cnt_cli2ost $flavor`
6544 elif [ $dir == "mdt2mdt" ]; then
6545 res=`flvr_cnt_mdt2mdt $flavor`
6546 elif [ $dir == "mdt2ost" ]; then
6547 res=`flvr_cnt_mdt2ost $flavor`
6548 elif [ $dir == "all2ost" ]; then
6549 res1=`flvr_cnt_mdt2ost $flavor`
6550 res2=`flvr_cnt_cli2ost $flavor`
6551 res=$((res1 + res2))
6552 elif [ $dir == "all2mdt" ]; then
6553 res1=`flvr_cnt_mdt2mdt $flavor`
6554 res2=`flvr_cnt_cli2mdt $flavor`
6555 res=$((res1 + res2))
6556 elif [ $dir == "all2all" ]; then
6557 res1=`flvr_cnt_mdt2ost $flavor`
6558 res2=`flvr_cnt_cli2ost $flavor`
6559 res3=`flvr_cnt_mdt2mdt $flavor`
6560 res4=`flvr_cnt_cli2mdt $flavor`
6561 res=$((res1 + res2 + res3 + res4))
6569 local dir=$1 # from to
6570 local flavor=$2 # flavor expected
6571 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6575 for ((i=0;i<20;i++)); do
6576 echo -n "checking $dir..."
6577 res=$(do_check_flavor $dir $flavor)
6578 echo "found $res/$expect $flavor connections"
6579 [ $res -ge $expect ] && return 0
6583 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6587 restore_to_default_flavor()
6589 local proc="mgs.MGS.live.$FSNAME"
6591 echo "restoring to default flavor..."
6593 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6595 # remove all existing rules if any
6596 if [ $nrule -ne 0 ]; then
6597 echo "$nrule existing rules"
6598 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6599 echo "remove rule: $rule"
6600 spec=`echo $rule | awk -F = '{print $1}'`
6601 do_facet mgs "$LCTL conf_param -d $spec"
6605 # verify no rules left
6606 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6607 [ $nrule -ne 0 ] && error "still $nrule rules left"
6609 # wait for default flavor to be applied
6610 # currently default flavor for all connections are 'null'
6611 wait_flavor all2all null
6612 echo "now at default flavor settings"
6617 local flavor=${1:-null}
6619 echo "setting all flavor to $flavor"
6621 # FIXME need parameter to this fn
6622 # and remove global vars
6623 local cnt_all2all=$(calc_connection_cnt all2all)
6625 local res=$(do_check_flavor all2all $flavor)
6626 if [ $res -eq $cnt_all2all ]; then
6627 echo "already have total $res $flavor connections"
6631 echo "found $res $flavor out of total $cnt_all2all connections"
6632 restore_to_default_flavor
6634 [[ $flavor = null ]] && return 0
6636 set_rule $FSNAME any any $flavor
6637 wait_flavor all2all $flavor
6643 # Checking for shared logdir
6644 if [ ! -d $dir ]; then
6645 # Not found. Create local logdir
6648 touch $dir/check_file.$(hostname -s)
6653 check_write_access() {
6655 local list=${2:-$(comma_list $(nodes_list))}
6659 for node in ${list//,/ }; do
6660 file=$dir/check_file.$(short_nodename $node)
6661 if [[ ! -f "$file" ]]; then
6662 # Logdir not accessible/writable from this node.
6665 rm -f $file || return 1
6671 [[ -n $YAML_LOG ]] && return
6672 local save_umask=$(umask)
6675 export YAML_LOG=${LOGDIR}/results.yml
6679 # If the yaml log already exists then we will just append to it
6680 if [ ! -f $YAML_LOG ]; then
6681 if check_shared_dir $LOGDIR; then
6682 touch $LOGDIR/shared
6683 echo "Logging to shared log directory: $LOGDIR"
6685 echo "Logging to local directory: $LOGDIR"
6688 yml_nodes_file $LOGDIR >> $YAML_LOG
6689 yml_results_file >> $YAML_LOG
6694 # If modules are not yet loaded then older "lctl lustre_build_version"
6695 # will fail. Use lctl build version instead.
6696 log "Client: $($LCTL lustre_build_version)"
6697 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6698 do_facet $SINGLEMDS $LCTL --version)"
6699 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6700 do_facet ost1 $LCTL --version)"
6704 yml_log_test $1 >> $YAML_LOG
6708 yml_log_test_status $@ >> $YAML_LOG
6711 log_sub_test_begin() {
6712 yml_log_sub_test_begin "$@" >> $YAML_LOG
6715 log_sub_test_end() {
6716 yml_log_sub_test_end "$@" >> $YAML_LOG
6722 local llverdev_opts=$2
6723 local devname=$(basename $1)
6724 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6725 # loop devices aren't in /proc/partitions
6726 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6728 size=$(($size / 1024 / 1024)) # Gb
6730 local partial_arg=""
6731 # Run in partial (fast) mode if the size
6732 # of a partition > 1 GB
6733 [ $size -gt 1 ] && partial_arg="-p"
6735 llverdev --force $partial_arg $llverdev_opts $dev
6741 local llverfs_opts=$2
6742 local use_partial_arg=$3
6743 local partial_arg=""
6744 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6746 # Run in partial (fast) mode if the size
6747 # of a partition > 1 GB
6748 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6750 llverfs $partial_arg $llverfs_opts $dir
6753 #Remove objects from OST
6754 remove_ost_objects() {
6760 local mntpt=$(facet_mntpt $facet)
6761 local opts=$OST_MOUNT_OPTS
6765 echo "removing objects from $ostdev on $facet: $objids"
6766 if ! test -b $ostdev; then
6767 opts=$(csa_add "$opts" -o loop)
6769 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6772 for i in $objids; do
6773 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6775 umount -f $mntpt || return $?
6779 #Remove files from MDT
6780 remove_mdt_files() {
6785 local mntpt=$(facet_mntpt $facet)
6786 local opts=$MDS_MOUNT_OPTS
6788 echo "removing files from $mdtdev on $facet: $files"
6789 if [ $(facet_fstype $facet) == ldiskfs ] &&
6790 ! do_facet $facet test -b $mdtdev; then
6791 opts=$(csa_add "$opts" -o loop)
6793 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6797 rm $mntpt/ROOT/$f || { rc=$?; break; }
6799 umount -f $mntpt || return $?
6803 duplicate_mdt_files() {
6808 local mntpt=$(facet_mntpt $facet)
6809 local opts=$MDS_MOUNT_OPTS
6811 echo "duplicating files on $mdtdev on $facet: $files"
6812 mkdir -p $mntpt || return $?
6813 if [ $(facet_fstype $facet) == ldiskfs ] &&
6814 ! do_facet $facet test -b $mdtdev; then
6815 opts=$(csa_add "$opts" -o loop)
6817 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6828 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6829 pushd $mntpt/ROOT > /dev/null || return $?
6832 touch $f.bad || return $?
6833 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6835 [ $rc -eq 0 ] || return $rc
6836 setfattr --restore $tmp || return $?
6842 local devs=${1//,/ }
6845 local rslt=$TMP/sgpdd_survey
6847 # sgpdd-survey cleanups ${rslt}.* files
6849 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6855 # returns the canonical name for an ldiskfs device
6860 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6861 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6862 echo dm-\\\${foo##*:};
6864 echo \\\$(basename \\\$dv);
6868 is_sanity_benchmark() {
6869 local benchmarks="dbench bonnie iozone fsx"
6871 for b in $benchmarks; do
6872 if [ "$b" == "$suite" ]; then
6880 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6884 # Get the available size (KB) of a given obd target.
6891 [[ $facet != client ]] || return 0
6893 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6898 # Get the page size (bytes) on a given facet node.
6904 size=$(do_facet $facet getconf PAGE_SIZE)
6905 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6910 # Get the block count of the filesystem.
6917 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6918 awk '/^Block count:/ {print $3}')
6922 # Get the block size of the filesystem.
6928 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6929 awk '/^Block size:/ {print $3}')
6933 # Check whether the "large_xattr" feature is enabled or not.
6934 large_xattr_enabled() {
6935 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6937 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6939 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6940 grep -E -q '(ea_inode|large_xattr)'"
6941 return ${PIPESTATUS[0]}
6944 # Get the maximum xattr size supported by the filesystem.
6948 if large_xattr_enabled; then
6949 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6952 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6953 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6955 # maximum xattr size = size of block - size of header -
6956 # size of 1 entry - 4 null bytes
6957 size=$((block_size - 32 - 32 - 4))
6963 # Dump the value of the named xattr from a file.
6968 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6971 # Generate a string with size of $size bytes.
6973 local size=${1:-1024} # in bytes
6975 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6978 reformat_external_journal() {
6983 if [ -n "${!var}" ]; then
6984 local rcmd="do_facet $facet"
6986 echo "reformat external journal on $facet:${!var}"
6987 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
6991 # MDT file-level backup/restore
6992 mds_backup_restore() {
6995 local devname=$(mdsdevname $(facet_number $facet))
6996 local mntpt=$(facet_mntpt brpt)
6997 local rcmd="do_facet $facet"
6998 local metaea=${TMP}/backup_restore.ea
6999 local metadata=${TMP}/backup_restore.tgz
7000 local opts=${MDS_MOUNT_OPTS}
7001 local svc=${facet}_svc
7003 if ! ${rcmd} test -b ${devname}; then
7004 opts=$(csa_add "$opts" -o loop)
7007 echo "file-level backup/restore on $facet:${devname}"
7009 # step 1: build mount point
7010 ${rcmd} mkdir -p $mntpt
7011 # step 2: cleanup old backup
7012 ${rcmd} rm -f $metaea $metadata
7014 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7015 if [ ! -z $igif ]; then
7016 # step 3.5: rm .lustre
7017 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7019 # step 4: backup metaea
7021 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7023 # step 5: backup metadata
7025 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7027 ${rcmd} $UMOUNT $mntpt || return 4
7028 # step 8: reformat dev
7029 echo "reformat new device"
7030 format_mdt $(facet_number $facet)
7032 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7033 # step 10: restore metadata
7035 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7036 # step 11: restore metaea
7038 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7039 # step 12: remove recovery logs
7040 echo "remove recovery logs"
7041 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7042 # step 13: umount dev
7043 ${rcmd} $UMOUNT $mntpt || return 10
7044 # step 14: cleanup tmp backup
7045 ${rcmd} rm -f $metaea $metadata
7046 # step 15: reset device label - it's not virgin on
7047 ${rcmd} e2label $devname ${!svc}
7054 local devname=$(mdsdevname $(facet_number $facet))
7055 local mntpt=$(facet_mntpt brpt)
7056 local rcmd="do_facet $facet"
7057 local opts=${MDS_MOUNT_OPTS}
7059 if ! ${rcmd} test -b ${devname}; then
7060 opts=$(csa_add "$opts" -o loop)
7063 echo "removing OI files on $facet: idx=${idx}"
7065 # step 1: build mount point
7066 ${rcmd} mkdir -p $mntpt
7068 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7069 if [ -z $idx ]; then
7070 # step 3: remove all OI files
7071 ${rcmd} rm -fv $mntpt/oi.16*
7072 elif [ $idx -lt 2 ]; then
7073 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7077 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7078 for ((i=${idx}; i<64; i=$((i * idx)))); do
7079 ${rcmd} rm -fv $mntpt/oi.16.${i}
7083 ${rcmd} $UMOUNT $mntpt || return 2
7084 # OI files will be recreated when mounted as lustre next time.
7087 # generate maloo upload-able log file name
7088 # \param logname specify unique part of file name
7089 generate_logname() {
7090 local logname=${1:-"default_logname"}
7092 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7095 # make directory on different MDTs
7099 local stripe_count=2
7100 local stripe_index=-1
7103 while getopts "c:i:p" opt; do
7105 c) stripe_count=$OPTARG;;
7106 i) stripe_index=$OPTARG;;
7108 \?) error "only support -i -c -p";;
7112 shift $((OPTIND - 1))
7113 [ $# -eq 1 ] || error "Only creating single directory is supported"
7116 if [ "$p_option" == "-p" ]; then
7117 local parent=$(dirname $path)
7119 [ -d $path ] && return 0
7120 [ ! -d ${parent} ] && mkdir -p ${parent}
7123 if [ $MDSCOUNT -le 1 ]; then
7126 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7129 if [ $stripe_index -eq -1 ]; then
7130 mdt_index=$((test_num % MDSCOUNT))
7132 mdt_index=$stripe_index
7134 echo "striped dir -i$mdt_index -c$stripe_count $path"
7135 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7139 # find the smallest and not in use file descriptor
7142 local max_fd=$(ulimit -n)
7144 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7147 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7151 check_mount_and_prep()
7153 is_mounted $MOUNT || setupall
7155 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7156 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7157 for idx in $(seq $MDSCOUNT); do
7158 local name="MDT$(printf '%04x' $((idx - 1)))"
7159 rm -rf $MOUNT/.lustre/lost+found/$name/*
7163 # calcule how many ost-objects to be created.
7164 precreated_ost_obj_count()
7168 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7169 local ost_name="OST$(printf '%04x' $ost_idx)"
7170 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7171 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7172 osp.$proc_path.prealloc_last_id)
7173 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7174 osp.$proc_path.prealloc_next_id)
7175 echo $((last_id - next_id + 1))
7178 check_file_in_pool()
7183 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7186 for t in $tlist ; do
7187 [ "$i" -eq "$t" ] && continue 2
7190 echo "pool list: $tlist"
7191 echo "striping: $res"
7192 error_noexit "$file not allocated in $pool"
7199 echo "Creating new pool"
7202 create_pool $FSNAME.$pool ||
7203 { error_noexit "No pool created, result code $?"; return 1; }
7204 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7205 { error_noexit "$pool not in lfs pool_list"; return 2; }
7208 pool_add_targets() {
7209 echo "Adding targets to pool"
7215 local list=$(seq $first $step $last)
7217 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7218 do_facet mgs $LCTL pool_add \
7219 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7220 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7221 | sort -u | tr '\n' ' ' " "$t" || {
7222 error_noexit "Add to pool failed"
7225 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7226 local addcount=$(((last - first) / step + 1))
7227 [ $lfscount -eq $addcount ] || {
7228 error_noexit "lfs pool_list bad ost count" \
7229 "$lfscount != $addcount"
7237 echo "Setting pool on directory $tdir"
7239 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7241 error_noexit "Cannot set pool $pool to $tdir"
7248 echo "Checking pool on directory $tdir"
7250 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7251 [ "$res" = "$pool" ] && return 0
7253 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7257 pool_dir_rel_path() {
7258 echo "Testing relative path works well"
7263 mkdir -p $root/$tdir/$tdir
7265 pool_set_dir $pool $tdir || return 1
7266 pool_set_dir $pool ./$tdir || return 2
7267 pool_set_dir $pool ../$tdir || return 3
7268 pool_set_dir $pool ../$tdir/$tdir || return 4
7269 rm -rf $tdir; cd - > /dev/null
7272 pool_alloc_files() {
7273 echo "Checking files allocation from directory pool"
7280 for i in $(seq -w 1 $count)
7282 local file=$tdir/file-$i
7284 check_file_in_pool $file $pool "$tlist" || \
7285 failed=$((failed + 1))
7287 [ "$failed" = 0 ] && return 0
7289 error_noexit "$failed files not allocated in $pool"
7293 pool_create_files() {
7294 echo "Creating files in pool"
7302 for i in $(seq -w 1 $count)
7304 local file=$tdir/spoo-$i
7305 $SETSTRIPE -p $pool $file
7306 check_file_in_pool $file $pool "$tlist" || \
7307 failed=$((failed + 1))
7309 [ "$failed" = 0 ] && return 0
7311 error_noexit "$failed files not allocated in $pool"
7316 echo "Checking 'lfs df' output"
7319 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7321 local res=$($LFS df --pool $FSNAME.$pool |
7323 grep "$FSNAME-OST" |
7325 [ "$res" = "$t" ] && return 0
7327 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7331 pool_file_rel_path() {
7332 echo "Creating files in a pool with relative pathname"
7337 { error_noexit "unable to create $tdir"; return 1 ; }
7338 local file="/..$tdir/$tfile-1"
7339 $SETSTRIPE -p $pool $file ||
7340 { error_noexit "unable to create $file" ; return 2 ; }
7343 $SETSTRIPE -p $pool $tfile-2 || {
7344 error_noexit "unable to create $tfile-2 in $tdir"
7349 pool_remove_first_target() {
7350 echo "Removing first target from a pool"
7353 local pname="lov.$FSNAME-*.pools.$pool"
7354 local t=$($LCTL get_param -n $pname | head -1)
7355 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7356 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7357 error_noexit "$t not removed from $FSNAME.$pool"
7362 pool_remove_all_targets() {
7363 echo "Removing all targets from pool"
7366 local pname="lov.$FSNAME-*.pools.$pool"
7367 for t in $($LCTL get_param -n $pname | sort -u)
7369 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7371 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7372 error_noexit "Pool $FSNAME.$pool cannot be drained"
7375 # striping on an empty/nonexistant pool should fall back
7376 # to "pool of everything"
7378 error_noexit "failed to use fallback striping for empty pool"
7381 # setstripe on an empty pool should fail
7382 $SETSTRIPE -p $pool $file 2>/dev/null && {
7383 error_noexit "expected failure when creating file" \
7391 echo "Destroying pool"
7395 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7398 # striping on an empty/nonexistant pool should fall back
7399 # to "pool of everything"
7401 error_noexit "failed to use fallback striping for missing pool"
7404 # setstripe on an empty pool should fail
7405 $SETSTRIPE -p $pool $file 2>/dev/null && {
7406 error_noexit "expected failure when creating file" \
7411 # get param should return err once pool is gone
7412 if wait_update $HOSTNAME "lctl get_param -n \
7413 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7415 remove_pool_from_list $FSNAME.$pool
7418 error_noexit "Pool $FSNAME.$pool is not destroyed"
7422 # Get and check the actual stripe count of one file.
7423 # Usage: check_stripe_count <file> <expected_stripe_count>
7424 check_stripe_count() {
7429 [[ -z "$file" || -z "$expected" ]] &&
7430 error "check_stripe_count: invalid argument"
7432 local cmd="$GETSTRIPE -c $file"
7433 actual=$($cmd) || error "$cmd failed"
7434 actual=${actual%% *}
7436 if [[ $actual -ne $expected ]]; then
7437 [[ $expected -eq -1 ]] ||
7438 error "$cmd wrong: found $actual, expected $expected"
7439 [[ $actual -eq $OSTCOUNT ]] ||
7440 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7444 # Get and check the actual list of OST indices on one file.
7445 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7451 [[ -z "$file" || -z "$expected" ]] &&
7452 error "check_obdidx: invalid argument!"
7454 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7455 grep -v obdidx | awk '{print $1}' | xargs))
7457 [[ $obdidx = $expected ]] ||
7458 error "list of OST indices on $file is $obdidx," \
7459 "should be $expected"
7462 # Get and check the actual OST index of the first stripe on one file.
7463 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7464 check_start_ost_idx() {
7469 [[ -z "$file" || -z "$expected" ]] &&
7470 error "check_start_ost_idx: invalid argument!"
7472 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7475 [[ $start_ost_idx = $expected ]] ||
7476 error "OST index of the first stripe on $file is" \
7477 "$start_ost_idx, should be $expected"
7480 killall_process () {
7481 local clients=${1:-$(hostname)}
7486 do_nodes $clients "killall $signal $name"