3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
14 export GSS_PIPEFS=false
15 export IDENTITY_UPCALL=default
17 # specify environment variable containing batch job name for server statistics
18 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
20 #export PDSH="pdsh -S -Rssh -w"
21 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
22 export UMOUNT=${UMOUNT:-"umount -d"}
23 # sles12 umount has a issue with -d option
24 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
25 export UMOUNT="umount"
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
53 sanitize_parameters() {
54 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
57 if [ -d "$path" ]; then
58 eval export $i=$(echo $path | sed -r 's/\/+$//g')
64 [[ $DIR/ = $MOUNT/* ]] ||
65 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
66 [[ $DIR1/ = $MOUNT1/* ]] ||
67 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
68 [[ $DIR2/ = $MOUNT2/* ]] ||
69 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
71 [ -n "$failed" ] && exit 99 || true
75 echo "usage: $0 [-r] [-f cfgfile]"
83 [ -z "$DEFAULT_SUITES"] && return 0
84 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
86 local form="%-13s %-17s %-9s %s %s\n"
87 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
88 echo "------------------------------------------------------------------------------------"
89 for O in $DEFAULT_SUITES; do
90 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
91 [ "${!O}" = "no" ] && continue || true
92 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
93 local log=${TMP}/${o}.log
94 if is_sanity_benchmark $o; then
95 log=${TMP}/sanity-benchmark.log
100 local status=Unfinished
102 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
104 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
105 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
106 total=$(grep duration $log | awk '{ print $2 }')
107 if [ "${!O}" = "done" ]; then
111 local durations=$(egrep "^PASS|^FAIL" $log |
112 tr -d "("| sed s/s\)$//g |
113 awk '{ print $2":"$3"|" }')
114 details=$(printf "%s\n%s %s %s\n" "$details" \
115 "DDETAILS" "$O" "$(echo $durations)")
118 printf "$form" $status "$O" "${total}" "E=$skipped"
119 printf "$form" "-" "-" "-" "S=$(echo $slow)"
122 for O in $DEFAULT_SUITES; do
123 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
124 if [ "${!O}" = "no" ]; then
125 printf "$form" "Skipped" "$O" ""
129 # print the detailed tests durations if DDETAILS=true
136 export LUSTRE=$(absolute_path $LUSTRE)
137 export TESTSUITE=$(basename $0 .sh)
138 export TEST_FAILED=false
139 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
140 export RPC_MODE=${RPC_MODE:-false}
141 export DO_CLEANUP=${DO_CLEANUP:-true}
143 export MKE2FS=$MKE2FS
144 if [ -z "$MKE2FS" ]; then
145 if which mkfs.ldiskfs >/dev/null 2>&1; then
146 export MKE2FS=mkfs.ldiskfs
152 export DEBUGFS=$DEBUGFS
153 if [ -z "$DEBUGFS" ]; then
154 if which debugfs.ldiskfs >/dev/null 2>&1; then
155 export DEBUGFS=debugfs.ldiskfs
157 export DEBUGFS=debugfs
161 export TUNE2FS=$TUNE2FS
162 if [ -z "$TUNE2FS" ]; then
163 if which tunefs.ldiskfs >/dev/null 2>&1; then
164 export TUNE2FS=tunefs.ldiskfs
166 export TUNE2FS=tune2fs
170 export E2LABEL=$E2LABEL
171 if [ -z "$E2LABEL" ]; then
172 if which label.ldiskfs >/dev/null 2>&1; then
173 export E2LABEL=label.ldiskfs
175 export E2LABEL=e2label
179 export DUMPE2FS=$DUMPE2FS
180 if [ -z "$DUMPE2FS" ]; then
181 if which dumpfs.ldiskfs >/dev/null 2>&1; then
182 export DUMPE2FS=dumpfs.ldiskfs
184 export DUMPE2FS=dumpe2fs
188 export E2FSCK=$E2FSCK
189 if [ -z "$E2FSCK" ]; then
190 if which fsck.ldiskfs >/dev/null 2>&1; then
191 export E2FSCK=fsck.ldiskfs
197 export RESIZE2FS=$RESIZE2FS
198 if [ -z "$RESIZE2FS" ]; then
199 if which resizefs.ldiskfs >/dev/null 2>&1; then
200 export RESIZE2FS=resizefs.ldiskfs
202 export RESIZE2FS=resize2fs
206 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
207 export FSCK_MAX_ERR=4 # File system errors left uncorrected
209 export ZFS=${ZFS:-zfs}
210 export ZPOOL=${ZPOOL:-zpool}
211 export ZDB=${ZDB:-zdb}
212 export PARTPROBE=${PARTPROBE:-partprobe}
214 #[ -d /r ] && export ROOT=${ROOT:-/r}
215 export TMP=${TMP:-$ROOT/tmp}
216 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
217 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
218 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
220 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
221 if ! echo $PATH | grep -q $LUSTRE/utils; then
222 export PATH=$LUSTRE/utils:$PATH
224 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
225 export PATH=$LUSTRE/utils/gss:$PATH
227 if ! echo $PATH | grep -q $LUSTRE/tests; then
228 export PATH=$LUSTRE/tests:$PATH
230 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
231 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
233 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
234 [ ! -f "$LST" ] && export LST=$(which lst)
235 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
236 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
237 export MCREATE=${MCREATE:-mcreate}
238 # Ubuntu, at least, has a truncate command in /usr/bin
239 # so fully path our truncate command.
240 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
241 export FSX=${FSX:-$LUSTRE/tests/fsx}
242 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
243 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
244 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
245 export PATH=$LUSTRE/tests/racer:$PATH:
247 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
248 export PATH=$LUSTRE/tests/mpi:$PATH
250 export RSYNC_RSH=${RSYNC_RSH:-rsh}
252 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
253 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
254 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
255 [ ! -f "$LFS" ] && export LFS=$(which lfs)
256 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
257 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
259 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
260 if [ ! -f "$L_GETIDENTITY" ]; then
261 if `which l_getidentity > /dev/null 2>&1`; then
262 export L_GETIDENTITY=$(which l_getidentity)
264 export L_GETIDENTITY=NONE
267 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
268 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
269 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
270 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
271 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
272 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
273 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
274 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
275 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
276 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
277 [ ! -f "$LUSTRE_RMMOD" ] &&
278 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
279 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
280 [ ! -f "$LFS_MIGRATE" ] &&
281 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
282 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
283 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
284 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
285 export NAME=${NAME:-local}
286 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
287 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
288 export LGSSD=$(which lgssd)
289 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
290 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
291 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
293 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
295 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
296 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
298 if [ "$ACCEPTOR_PORT" ]; then
299 export PORT_OPT="--port $ACCEPTOR_PORT"
304 echo "Using GSS/krb5 ptlrpc security flavor"
305 which lgss_keyring > /dev/null 2>&1 || \
306 error_exit "built with gss disabled! SEC=$SEC"
317 IDENTITY_UPCALL=false
321 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
323 # Paths on remote nodes, if different
324 export RLUSTRE=${RLUSTRE:-$LUSTRE}
325 export RPWD=${RPWD:-$PWD}
326 export I_MOUNTED=${I_MOUNTED:-"no"}
327 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
328 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
329 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
330 ! -f $LUSTRE/mdt/mdt.ko ]; then
331 export CLIENTMODSONLY=yes
334 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
335 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
339 while getopts "rvwf:" opt $*; do
344 w) WRITECONF=writeconf;;
349 shift $((OPTIND - 1))
352 # print the durations of each test if "true"
353 DDETAILS=${DDETAILS:-false}
354 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
359 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
366 ncpts=$(do_facet $facet "lctl get_param -n " \
367 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
369 if [ $ncpts -eq 0 ]; then
376 # Return a numeric version code based on a version string. The version
377 # code is useful for comparison two version strings to see which is newer.
379 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
380 eval set -- $(tr "[:punct:]" " " <<< $*)
382 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
385 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
386 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
388 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
390 # usage: lustre_build_version
392 # All Lustre versions support "lctl get_param" to report the version of the
393 # code running in the kernel (what our tests are interested in), but it
394 # doesn't work without modules loaded. If that fails, use "lctl version"
395 # instead, which is easy to parse and works without the kernel modules,
396 # but was only added in 2.6.50. If that also fails, fall back to calling
397 # "lctl lustre_build_version" which prints either (or both) the userspace
398 # and kernel build versions, but is deprecated and should eventually be
401 # output: prints version string to stdout in dotted-decimal format
402 lustre_build_version() {
403 local facet=${1:-client}
406 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
407 awk '/lustre: / { print $2 }')
409 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
411 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
412 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
413 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
414 awk '/version:/ { print $3; exit; }')
415 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
418 # Report the Lustre numeric build version code for the supplied facet.
419 lustre_version_code() {
420 version_code $(lustre_build_version $1)
424 /sbin/lsmod | grep -q "^\<$1\>"
427 # Load a module on the system where this is running.
429 # usage: load_module module_name [module arguments for insmod/modprobe]
431 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
432 # will be used as the arguments. Otherwise arguments will be obtained from
433 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
440 BASE=$(basename $module $EXT)
442 module_loaded ${BASE} && return
444 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
445 # else from modprobe.conf
446 if [ $# -eq 0 ]; then
447 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
448 # Bash until 4.x, so we resort to eval.
449 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
450 eval set -- \$$optvar
451 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
452 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
454 opt=$(awk -v var="^options $BASE" '$0 ~ var \
455 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
456 set -- $(echo -n $opt)
458 # Ensure we have accept=all for lnet
459 if [ $(basename $module) = lnet ]; then
460 # OK, this is a bit wordy...
461 local arg accept_all_present=false
464 [ "$arg" = accept=all ] && \
465 accept_all_present=true
467 $accept_all_present || set -- "$@" accept=all
473 [ $# -gt 0 ] && echo "${module} options: '$*'"
475 # Note that insmod will ignore anything in modprobe.conf, which is why
476 # we're passing options on the command-line.
477 if [[ "$BASE" == "lnet_selftest" ]] &&
478 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
479 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
480 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
481 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
482 insmod ${LUSTRE}/${module}${EXT} "$@"
484 # must be testing a "make install" or "rpm" installation
485 # note failed to load ptlrpc_gss is considered not fatal
486 if [[ "$BASE" == "ptlrpc_gss" ]]; then
487 modprobe $BASE "$@" 2>/dev/null ||
488 echo "gss/krb5 is not supported"
495 load_modules_local() {
496 if [ -n "$MODPROBE" ]; then
498 echo "Using modprobe to load modules"
502 echo Loading modules from $LUSTRE
506 if [ -f /sys/devices/system/cpu/online ]; then
507 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
508 echo "detected $ncpus online CPUs by sysfs"
510 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
512 if [ $rc -eq 0 ]; then
513 echo "detected $ncpus online CPUs by getconf"
515 echo "Can't detect number of CPUs"
520 # if there is only one CPU core, libcfs can only create one partition
521 # if there is more than 4 CPU cores, libcfs should create multiple CPU
522 # partitions. So we just force libcfs to create 2 partitions for
523 # system with 2 or 4 cores
524 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
525 # force to enable multiple CPU partitions
526 echo "Force libcfs to create 2 CPU partitions"
527 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
529 echo "libcfs will create CPU partition based on online CPUs"
532 load_module ../libcfs/libcfs/libcfs
534 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
535 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
536 load_module ../lnet/lnet/lnet
539 LNETLND="o2iblnd/ko2iblnd"
544 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
545 load_module ../lnet/klnds/$LNETLND
546 load_module obdclass/obdclass
547 load_module ptlrpc/ptlrpc
548 load_module ptlrpc/gss/ptlrpc_gss
556 load_module obdecho/obdecho
557 if ! client_only; then
558 SYMLIST=/proc/kallsyms
559 grep -q crc16 $SYMLIST ||
560 { modprobe crc16 2>/dev/null || true; }
561 grep -q -w jbd2 $SYMLIST ||
562 { modprobe jbd2 2>/dev/null || true; }
563 load_module lfsck/lfsck
564 [ "$LQUOTA" != "no" ] &&
565 load_module quota/lquota $LQUOTAOPTS
566 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
568 load_module osd-zfs/osd_zfs
570 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
571 grep -q exportfs_decode_fh $SYMLIST ||
572 { modprobe exportfs 2> /dev/null || true; }
573 grep -q -w mbcache $SYMLIST ||
574 { modprobe mbcache 2>/dev/null || true; }
575 load_module ../ldiskfs/ldiskfs
576 load_module osd-ldiskfs/osd_ldiskfs
588 load_module llite/lustre
589 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
591 rm -f $OGDB/ogdb-$HOSTNAME
592 $LCTL modules > $OGDB/ogdb-$HOSTNAME
594 # 'mount' doesn't look in $PATH, just sbin
595 local mount_lustre=$LUSTRE/utils/mount.lustre
596 if [ -f $mount_lustre ]; then
597 local sbin_mount=$(readlink -f /sbin)/mount.lustre
598 if grep -qw "$sbin_mount" /proc/mounts; then
599 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
601 if ! grep -qw "$sbin_mount" /proc/mounts; then
602 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
603 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
604 cat <<- EOF > "$sbin_mount"
607 echo "This $sbin_mount just a mountpoint." 1>&2
608 echo "It is never supposed to be run." 1>&2
609 logger -p emerg -- "using stub $sbin_mount $@"
612 chmod a+x $sbin_mount
614 mount --bind $mount_lustre $sbin_mount ||
615 error "can't bind $mount_lustre to $sbin_mount"
623 # load modules on remote nodes optionally
624 # lustre-tests have to be installed on these nodes
625 if $LOAD_MODULES_REMOTE; then
626 local list=$(comma_list $(remote_nodes_list))
627 if [ -n "$list" ]; then
628 echo "loading modules on: '$list'"
629 do_rpc_nodes "$list" load_modules_local
635 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
636 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
637 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
638 echo "$LEAK_LUSTRE" 1>&2
639 echo "$LEAK_PORTALS" 1>&2
640 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
641 echo "Memory leaks detected"
642 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
648 wait_exit_ST client # bug 12845
650 $LUSTRE_RMMOD ldiskfs || return 2
652 if $LOAD_MODULES_REMOTE; then
653 local list=$(comma_list $(remote_nodes_list))
654 if [ -n "$list" ]; then
655 echo "unloading modules on: '$list'"
656 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
657 do_rpc_nodes "$list" check_mem_leak
661 local sbin_mount=$(readlink -f /sbin)/mount.lustre
662 if grep -qe "$sbin_mount " /proc/mounts; then
663 umount $sbin_mount || true
664 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
668 check_mem_leak || return 254
670 echo "modules unloaded."
675 local facet=${1:-$SINGLEMDS}
676 local fstype=$(facet_fstype $facet)
679 ldiskfs) size=50;; # largest seen is 44, leave some headroom
680 zfs) size=400;; # largest seen is 384
687 local facet=${1:-$SINGLEMDS}
688 local fstype=$(facet_fstype $facet)
691 ldiskfs) size=4;; # ~4KB per inode
692 zfs) size=11;; # 10 to 11KB per inode
698 check_gss_daemon_nodes() {
702 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
703 if [ \\\"\\\$num\\\" -ne 1 ]; then
704 echo \\\$num instance of $dname;
709 check_gss_daemon_facet() {
713 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
714 if [ $num -ne 1 ]; then
715 echo "$num instance of $dname on $facet"
724 echo Stopping $@ on $list
725 do_nodes $list "killall -2 $@ 2>/dev/null || true"
728 # start gss daemons on all nodes, or
729 # "daemon" on "list" if set
730 start_gss_daemons() {
734 if [ "$list" ] && [ "$daemon" ] ; then
735 echo "Starting gss daemon on nodes: $list"
736 do_nodes $list "$daemon" || return 8
740 local list=$(comma_list $(mdts_nodes))
741 echo "Starting gss daemon on mds: $list"
742 do_nodes $list "$LSVCGSSD -v" || return 1
744 do_nodes $list "$LGSSD -v" || return 2
747 list=$(comma_list $(osts_nodes))
748 echo "Starting gss daemon on ost: $list"
749 do_nodes $list "$LSVCGSSD -v" || return 3
750 # starting on clients
752 local clients=${CLIENTS:-`hostname`}
754 echo "Starting $LGSSD on clients $clients "
755 do_nodes $clients "$LGSSD -v" || return 4
758 # wait daemons entering "stable" status
762 # check daemons are running
764 list=$(comma_list $(mdts_nodes) $(osts_nodes))
765 check_gss_daemon_nodes $list lsvcgssd || return 5
767 list=$(comma_list $(mdts_nodes))
768 check_gss_daemon_nodes $list lgssd || return 6
771 check_gss_daemon_nodes $clients lgssd || return 7
776 local list=$(comma_list $(mdts_nodes))
778 send_sigint $list lsvcgssd lgssd
780 list=$(comma_list $(osts_nodes))
781 send_sigint $list lsvcgssd
783 list=${CLIENTS:-`hostname`}
784 send_sigint $list lgssd
789 if ! module_loaded ptlrpc_gss; then
790 load_module ptlrpc/gss/ptlrpc_gss
791 module_loaded ptlrpc_gss ||
792 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
795 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
798 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
800 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
808 # maybe cleanup credential cache?
814 local var=${facet}_svc
822 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
823 tr '[:lower:]' '[:upper:]'
829 if [ $facet == mgs ] || [ $facet == client ]; then
833 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
841 if [ -n "${!var}" ]; then
846 var=$(facet_type $facet)FSTYPE
847 if [ -n "${!var}" ]; then
852 if [ -n "$FSTYPE" ]; then
857 if [[ $facet == mgs ]] && combined_mgs_mds; then
869 local facets=$(get_facets)
872 for facet in ${facets//,/ }; do
873 if [ $node == $(facet_host $facet) ] ||
874 [ $node == "$(facet_failover_host $facet)" ]; then
875 fstype=$(facet_fstype $facet)
876 if [[ $fstypes != *$fstype* ]]; then
877 fstypes+="${fstypes:+,}$fstype"
886 local num=$(facet_number $facet)
889 if [[ $(facet_type $facet) = OST ]]; then
891 if [[ -n "${!index}" ]]; then
896 index=${OST_INDICES[num - 1]}
899 [[ -n "$index" ]] || index=$((num - 1))
907 local fstype=$(facet_fstype $facet)
911 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
913 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
914 ${dev} 2>/dev/null");;
916 error "unknown fstype!";;
924 local device=$(mdsdevname $num)
925 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
931 local device=$(ostdevname $num)
932 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
937 # Get the device of a facet.
944 mgs) device=$(mgsdevname) ;;
945 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
946 ost*) device=$(ostdevname $(facet_number $facet)) ;;
947 fs2mds) device=$(mdsdevname 1_2) ;;
948 fs2ost) device=$(ostdevname 1_2) ;;
949 fs3ost) device=$(ostdevname 2_2) ;;
957 # Get the virtual device of a facet.
964 mgs) device=$(mgsvdevname) ;;
965 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
966 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
967 fs2mds) device=$(mdsvdevname 1_2) ;;
968 fs2ost) device=$(ostvdevname 1_2) ;;
969 fs3ost) device=$(ostvdevname 2_2) ;;
977 local virt=$(virt-what 2> /dev/null)
979 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
981 virt=$(dmidecode -s system-product-name | awk '{print $1}')
984 VMware|KVM|VirtualBox|Parallels)
985 echo $virt | tr '[A-Z]' '[a-z]' ;;
991 # Re-read the partition table on failover partner host.
992 # After a ZFS storage pool is created on a shared device, the partition table
993 # on the device may change. However, the operating system on the failover
994 # host may not notice the change automatically. Without the up-to-date partition
995 # block devices, 'zpool import ..' cannot find the labels, whose positions are
996 # relative to partition rather than disk beginnings.
998 # This function performs partprobe on the failover host to make it re-read the
1001 refresh_partition_table() {
1006 host=$(facet_passive_host $facet)
1007 if [[ -n "$host" ]]; then
1008 do_node $host "$PARTPROBE $device"
1013 # Get ZFS storage pool name.
1020 device=$(facet_device $facet)
1021 # poolname is string before "/"
1022 poolname="${device%%/*}"
1028 # Create ZFS storage pool.
1035 local opts=${@:-"-o cachefile=none"}
1037 do_facet $facet "modprobe zfs;
1038 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1039 $ZPOOL create -f $opts $poolname $vdev"
1043 # Create ZFS file system.
1049 local opts=${@:-"-o mountpoint=legacy"}
1051 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1052 $ZFS create $opts $dataset"
1056 # Export ZFS storage pool.
1057 # Before exporting the pool, all datasets within the pool should be unmounted.
1065 poolname=$(zpool_name $facet)
1067 if [[ -n "$poolname" ]]; then
1068 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1069 grep -q ^$poolname/ /proc/mounts ||
1070 $ZPOOL export $opts $poolname"
1075 # Destroy ZFS storage pool.
1076 # Destroy the given pool and free up any devices for other use. This command
1077 # tries to unmount any active datasets before destroying the pool.
1078 # -f Force any active datasets contained within the pool to be unmounted.
1082 local poolname=${2:-$(zpool_name $facet)}
1084 if [[ -n "$poolname" ]]; then
1085 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1086 $ZPOOL destroy -f $poolname"
1091 # Import ZFS storage pool.
1092 # Force importing, even if the pool appears to be potentially active.
1097 local opts=${@:-"-o cachefile=none"}
1100 poolname=$(zpool_name $facet)
1102 if [[ -n "$poolname" ]]; then
1103 opts+=" -d $(dirname $(facet_vdevice $facet))"
1104 do_facet $facet "modprobe zfs;
1105 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1106 $ZPOOL import -f $opts $poolname"
1111 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1112 # is not automatically imported on system startup.
1114 # In a failover environment, this will provide resource level fencing which
1115 # will ensure that the same ZFS storage pool will not be imported concurrently
1116 # on different nodes.
1118 disable_zpool_cache() {
1122 poolname=$(zpool_name $facet)
1124 if [[ -n "$poolname" ]]; then
1125 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1130 # This and set_osd_param() shall be used to access OSD parameters
1131 # once existed under "obdfilter":
1136 # writethrough_cache_enable
1140 local device=${2:-$FSNAME-OST*}
1143 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1144 osd-*.$device.$name 2>&1" | grep -v 'error:'
1149 local device=${2:-$FSNAME-OST*}
1153 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1154 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1158 local dz=${1:-$DEBUG_SIZE}
1160 if [ -f /sys/devices/system/cpu/possible ]; then
1161 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1163 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1166 # bug 19944, adjust size to be -gt num_possible_cpus()
1167 # promise 2MB for every cpu at least
1168 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1171 lctl set_param debug_mb=$dz
1174 set_default_debug () {
1175 local debug=${1:-"$PTLDEBUG"}
1176 local subsys=${2:-"$SUBSYSTEM"}
1177 local debug_size=${3:-$DEBUG_SIZE}
1179 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1180 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1182 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1185 set_default_debug_nodes () {
1188 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1189 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1193 do_rpc_nodes "$nodes" set_default_debug \
1194 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1197 set_default_debug_facet () {
1199 local node=$(facet_active_host $facet)
1200 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1202 set_default_debug_nodes $node
1206 local hostid=${1:-$(hostid)}
1208 if [ ! -s /etc/hostid ]; then
1209 printf $(echo -n $hostid |
1210 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1216 local facets=${1:-$(get_facets)}
1219 for facet in ${facets//,/ }; do
1222 [ $RC -eq 0 ] && continue
1224 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1225 skip "Restart of $facet failed!." && touch $LU482_FAILED
1227 error "Restart of $facet failed!"
1234 # Add argument "arg" (e.g., "loop") to the comma-separated list
1235 # of arguments for option "opt" (e.g., "-o") on command
1236 # line "opts" (e.g., "-o flock").
1242 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1244 if echo "$opts" | grep -q $opt_pattern; then
1245 opts=$(echo "$opts" | sed -e \
1246 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1248 opts+="${opts:+ }$opt $arg"
1256 local dev=$(facet_active $facet)_dev
1257 local opt=${facet}_opt
1258 local mntpt=$(facet_mntpt $facet)
1259 local opts="${!opt} $@"
1260 local fstype=$(facet_fstype $facet)
1263 module_loaded lustre || load_modules
1265 if [ $(facet_fstype $facet) == ldiskfs ] &&
1266 ! do_facet $facet test -b ${!dev}; then
1267 opts=$(csa_add "$opts" -o loop)
1270 if [[ $(facet_fstype $facet) == zfs ]]; then
1271 # import ZFS storage pool
1272 import_zpool $facet || return ${PIPESTATUS[0]}
1277 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1279 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1280 lustre:svname ${!dev}");;
1282 error "unknown fstype!";;
1285 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1286 # for testing LU-482 error handling in mount_facets() and test_0a()
1287 if [ -f $TMP/test-lu482-trigger ]; then
1290 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1295 if [ $RC -ne 0 ]; then
1296 echo "Start of ${!dev} on ${facet} failed ${RC}"
1300 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1301 if [[ "$health" != "healthy" ]]; then
1302 error "$facet is in a unhealthy state"
1305 set_default_debug_facet $facet
1307 if [[ $facet == mds* ]]; then
1309 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1312 if [[ $opts =~ .*nosvc.* ]]; then
1313 echo "Start ${!dev} without service"
1318 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1319 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1320 "" || error "${!dev} failed to initialize!";;
1322 wait_update_facet ${facet} "$ZFS get -H -o value \
1323 lustre:svname ${!dev} 2>/dev/null | \
1324 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1325 error "${!dev} failed to initialize!";;
1328 error "unknown fstype!";;
1332 # commit the device label change to disk
1333 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1334 echo "Commit the device label on ${!dev}"
1335 do_facet $facet "sync; sync; sync"
1340 label=$(devicelabel ${facet} ${!dev})
1341 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1342 eval export ${facet}_svc=${label}
1343 echo Started ${label}
1348 # start facet device options
1354 eval export ${facet}_dev=${device}
1355 eval export ${facet}_opt=\"$@\"
1357 local varname=${facet}failover_dev
1358 if [ -n "${!varname}" ] ; then
1359 eval export ${facet}failover_dev=${!varname}
1361 eval export ${facet}failover_dev=$device
1364 local mntpt=$(facet_mntpt $facet)
1365 do_facet ${facet} mkdir -p $mntpt
1366 eval export ${facet}_MOUNT=$mntpt
1367 mount_facet ${facet}
1370 if [[ $facet == mds* ]]; then
1372 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1383 local HOST=`facet_active_host $facet`
1384 [ -z $HOST ] && echo stop: no host for $facet && return 0
1386 local mntpt=$(facet_mntpt $facet)
1387 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1388 if [ ${running} -ne 0 ]; then
1389 echo "Stopping $mntpt (opts:$@) on $HOST"
1390 do_facet ${facet} $UMOUNT $@ $mntpt
1393 # umount should block, but we should wait for unrelated obd's
1394 # like the MGS or MGC to also stop.
1395 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1397 if [[ $(facet_fstype $facet) == zfs ]]; then
1398 # export ZFS storage pool
1403 # save quota version (both administrative and operational quotas)
1404 # add an additional parameter if mountpoint is ever different from $MOUNT
1406 # XXX This function is kept for interoperability with old server (< 2.3.50),
1407 # it should be removed whenever we drop the interoperability for such
1409 quota_save_version() {
1410 local fsname=${2:-$FSNAME}
1412 local ver=$(tr -c -d "123" <<< $spec)
1413 local type=$(tr -c -d "ug" <<< $spec)
1415 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1417 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1419 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1421 local osts=$(get_facets OST)
1422 for ost in ${osts//,/ }; do
1424 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1428 # client could mount several lustre
1430 # XXX This function is kept for interoperability with old server (< 2.3.50),
1431 # it should be removed whenever we drop the interoperability for such
1434 local fsname=${1:-$FSNAME}
1436 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1438 do_nodes $(comma_list $(osts_nodes)) \
1439 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1443 # get mdt quota type
1445 local varsvc=${SINGLEMDS}_svc
1446 do_facet $SINGLEMDS $LCTL get_param -n \
1447 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1450 # get ost quota type
1452 # All OSTs should have same quota type
1453 local varsvc=ost1_svc
1454 do_facet ost1 $LCTL get_param -n \
1455 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1458 # restore old quota type settings
1460 if [ "$old_MDT_QUOTA_TYPE" ]; then
1461 do_facet mgs $LCTL conf_param \
1462 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1464 if [ "$old_OST_QUOTA_TYPE" ]; then
1465 do_facet mgs $LCTL conf_param \
1466 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1470 # Handle the case when there is a space in the lfs df
1471 # "filesystem summary" line the same as when there is no space.
1472 # This will allow fixing the "lfs df" summary line in the future.
1474 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1477 # Get free inodes on the MDT specified by mdt index, free indoes on
1478 # the whole filesystem will be returned when index == -1.
1484 if [ $index -eq -1 ]; then
1487 mdt_uuid=$(mdtuuid_from_index $index)
1490 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1497 # save old quota type & set new quota type
1498 local mdt_qtype=$(mdt_quota_type)
1499 local ost_qtype=$(ost_quota_type)
1501 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1502 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1504 export old_MDT_QUOTA_TYPE=$mdt_qtype
1505 export old_OST_QUOTA_TYPE=$ost_qtype
1507 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1508 error "set mdt quota type failed"
1509 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1510 error "set ost quota type failed"
1512 local quota_usrs=$QUOTA_USERS
1514 # get_filesystem_size
1515 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1516 local blk_soft=$((disksz + 1024))
1517 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1519 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1520 local i_soft=$inodes
1521 local i_hard=$((i_soft + i_soft / 20))
1523 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1524 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1525 "inode-hardlimit: $i_hard"
1528 for usr in $quota_usrs; do
1529 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1531 cmd="$LFS setquota -$type $usr -b $blk_soft"
1532 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1534 eval $cmd || error "$cmd FAILED!"
1536 # display the quota status
1537 echo "Quota settings for $usr : "
1538 $LFS quota -v -u $usr $mntpt || true
1545 local opts=${3:-$MOUNT_OPTS}
1546 opts=${opts:+-o $opts}
1547 local flags=${4:-$MOUNT_FLAGS}
1549 local device=$MGSNID:/$FSNAME$FILESET
1550 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1551 echo "Bad mount command: opt=$flags $opts dev=$device " \
1556 echo "Starting client: $client: $flags $opts $device $mnt"
1557 do_node $client mkdir -p $mnt
1558 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1559 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1561 #disable FILESET if not supported
1562 do_nodes $client lctl get_param -n \
1563 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1564 device=$MGSNID:/$FSNAME
1565 do_node $client mkdir -p $mnt/$FILESET
1566 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1569 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1571 set_default_debug_nodes $client
1583 [ "$3" ] && force=-f
1584 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1585 if [ $running -ne 0 ]; then
1586 echo "Stopping client $client $mnt (opts:$force)"
1587 do_node $client lsof -t $mnt || need_kill=no
1588 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1589 pids=$(do_node $client lsof -t $mnt | sort -u);
1590 if [ -n $pids ]; then
1591 do_node $client kill -9 $pids || true
1595 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1596 if [ $busy -ne 0 ] ; then
1597 echo "$mnt is still busy, wait one second" && sleep 1
1598 do_node $client umount $force $mnt
1603 # nodes is comma list
1604 sanity_mount_check_nodes () {
1610 # FIXME: assume that all cluster nodes run the same os
1611 [ "$(uname)" = Linux ] || return 0
1614 for mnt in $mnts ; do
1615 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1616 mpts=\\\$(mount | grep -c $mnt' ');
1617 if [ \\\$running -ne \\\$mpts ]; then
1618 echo \\\$(hostname) env are INSANE!;
1621 [ $? -eq 0 ] || rc=1
1626 sanity_mount_check_servers () {
1627 [ -n "$CLIENTONLY" ] &&
1628 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1629 echo Checking servers environments
1631 # FIXME: modify get_facets to display all facets wo params
1632 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1636 for facet in ${facets//,/ }; do
1637 node=$(facet_host ${facet})
1638 mntpt=$(facet_mntpt $facet)
1639 sanity_mount_check_nodes $node $mntpt ||
1640 { error "server $node environments are insane!"; return 1; }
1644 sanity_mount_check_clients () {
1645 local clients=${1:-$CLIENTS}
1646 local mntpt=${2:-$MOUNT}
1647 local mntpt2=${3:-$MOUNT2}
1649 [ -z $clients ] && clients=$(hostname)
1650 echo Checking clients $clients environments
1652 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1653 error "clients environments are insane!"
1656 sanity_mount_check () {
1657 sanity_mount_check_servers || return 1
1658 sanity_mount_check_clients || return 2
1661 # mount clients if not mouted
1662 zconf_mount_clients() {
1665 local opts=${3:-$MOUNT_OPTS}
1666 opts=${opts:+-o $opts}
1667 local flags=${4:-$MOUNT_FLAGS}
1669 local device=$MGSNID:/$FSNAME$FILESET
1670 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1671 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1676 echo "Starting client $clients: $flags $opts $device $mnt"
1677 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1678 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1680 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1682 #disable FILESET if not supported
1683 do_nodes $clients lctl get_param -n \
1684 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1685 device=$MGSNID:/$FSNAME
1686 do_nodes $clients mkdir -p $mnt/$FILESET
1687 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1692 running=\\\$(mount | grep -c $mnt' ');
1694 if [ \\\$running -eq 0 ] ; then
1696 $MOUNT_CMD $flags $opts $device $mnt;
1699 exit \\\$rc" || return ${PIPESTATUS[0]}
1701 echo "Started clients $clients: "
1702 do_nodes $clients "mount | grep $mnt' '"
1704 set_default_debug_nodes $clients
1709 zconf_umount_clients() {
1714 [ "$3" ] && force=-f
1716 echo "Stopping clients: $clients $mnt (opts:$force)"
1717 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1718 if [ \\\$running -ne 0 ] ; then
1719 echo Stopping client \\\$(hostname) $mnt opts:$force;
1720 lsof $mnt || need_kill=no;
1721 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1722 pids=\\\$(lsof -t $mnt | sort -u);
1723 if [ -n \\\"\\\$pids\\\" ]; then
1727 while umount $force $mnt 2>&1 | grep -q "busy"; do
1728 echo "$mnt is still busy, wait one second" && sleep 1;
1735 echo + $POWER_DOWN $node
1739 shutdown_node_hard () {
1741 local attempts=$SHUTDOWN_ATTEMPTS
1743 for i in $(seq $attempts) ; do
1746 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1747 echo "waiting for $host to fail attempts=$attempts"
1748 [ $i -lt $attempts ] || \
1749 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1755 local mnt=${2:-$MOUNT}
1758 if [ "$FAILURE_MODE" = HARD ]; then
1759 shutdown_node_hard $client
1761 zconf_umount_clients $client $mnt -f
1767 local facets="$(get_facets OST),$(get_facets MDS)"
1770 combined_mgs_mds || facets="$facets,mgs"
1772 for facet in ${facets//,/ }; do
1773 if [ $(facet_active_host $facet) == $host ]; then
1774 affected="$affected $facet"
1778 echo $(comma_list $affected)
1783 local host=${2:-$(facet_host $facet)}
1785 local label=$(convert_facet2label $facet)
1786 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1789 facets_up_on_host () {
1791 local facets=$(facets_on_host $host)
1794 for facet in ${facets//,/ }; do
1795 if $(facet_up $facet $host); then
1796 affected_up="$affected_up $facet"
1800 echo $(comma_list $affected_up)
1806 if [ "$FAILURE_MODE" = HARD ]; then
1807 shutdown_node_hard $(facet_active_host $facet)
1815 echo + $POWER_UP $node
1828 if [ "$FAILURE_MODE" = HARD ]; then
1829 reboot_node $(facet_active_host $facet)
1837 if [ "$FAILURE_MODE" = HARD ]; then
1847 for facet in ${facets//,/ }; do
1848 hosts=$(expand_list $hosts $(facet_host $facet) )
1854 _check_progs_installed () {
1858 for prog in $progs; do
1859 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1860 echo $prog missing on $(hostname)
1867 check_progs_installed () {
1871 do_rpc_nodes "$nodes" _check_progs_installed $@
1874 # recovery-scale functions
1876 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1879 start_client_load() {
1882 local var=$(node_var_name $client)_load
1883 eval export ${var}=$load
1885 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1886 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1887 END_RUN_FILE=$END_RUN_FILE \
1888 LOAD_PID_FILE=$LOAD_PID_FILE \
1889 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1890 TESTNAME=$TESTNAME \
1891 DBENCH_LIB=$DBENCH_LIB \
1892 DBENCH_SRC=$DBENCH_SRC \
1893 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1897 log "Started client load: ${load} on $client"
1899 # get the children process IDs
1900 local pids=$(ps --ppid $ppid -o pid= | xargs)
1901 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1905 start_client_loads () {
1906 local -a clients=(${1//,/ })
1907 local numloads=${#CLIENT_LOADS[@]}
1910 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1911 testnum=$((nodenum % numloads))
1912 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1914 # bug 22169: wait the background threads to start
1918 # only for remote client
1919 check_client_load () {
1921 local var=$(node_var_name $client)_load
1922 local testload=run_${!var}.sh
1924 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
1926 # bug 18914: try to connect several times not only when
1927 # check ps, but while check_node_health also
1931 while [ $RC = 254 -a $tries -gt 0 ]; do
1935 if ! check_node_health $client; then
1937 if [ $RC -eq 254 ]; then
1938 # FIXME: not sure how long we shuold sleep here
1942 echo "check node health failed: RC=$RC "
1946 # We can continue try to connect if RC=254
1947 # Just print the warning about this
1948 if [ $RC = 254 ]; then
1949 echo "got a return status of $RC from do_node while checking " \
1950 "node health on $client"
1953 # see if the load is still on the client
1956 while [ $RC = 254 -a $tries -gt 0 ]; do
1960 if ! do_node $client \
1961 "ps auxwww | grep -v grep | grep -q $testload"; then
1966 if [ $RC = 254 ]; then
1967 echo "got a return status of $RC from do_node while checking " \
1968 "(node health and 'ps') the client load on $client"
1969 # see if we can diagnose a bit why this is
1974 check_client_loads () {
1975 local clients=${1//,/ }
1979 for client in $clients; do
1980 check_client_load $client
1982 if [ "$rc" != 0 ]; then
1983 log "Client load failed on node $client, rc=$rc"
1989 restart_client_loads () {
1990 local clients=${1//,/ }
1991 local expectedfail=${2:-""}
1995 for client in $clients; do
1996 check_client_load $client
1998 if [ "$rc" != 0 -a "$expectedfail" ]; then
1999 local var=$(node_var_name $client)_load
2000 start_client_load $client ${!var}
2001 echo "Restarted client load ${!var}: on $client. Checking ..."
2002 check_client_load $client
2004 if [ "$rc" != 0 ]; then
2005 log "Client load failed to restart on node $client, rc=$rc"
2006 # failure one client load means test fail
2007 # we do not need to check other
2016 # Start vmstat and save its process ID in a file.
2021 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2024 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2025 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2028 # Display the nodes on which client loads failed.
2029 print_end_run_file() {
2033 [ -s $file ] || return 0
2035 echo "Found the END_RUN_FILE file: $file"
2038 # A client load will stop if it finds the END_RUN_FILE file.
2039 # That does not mean the client load actually failed though.
2040 # The first node in END_RUN_FILE is the one we are interested in.
2043 if [ -n "$node" ]; then
2044 local var=$(node_var_name $node)_load
2046 local prefix=$TESTLOG_PREFIX
2047 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2048 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2049 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2051 echo "Client load ${!var} failed on node $node:"
2057 # Stop the process which had its PID saved in a file.
2062 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2064 do_nodes $nodes "test -f $pid_file &&
2065 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2068 # Stop all client loads.
2069 stop_client_loads() {
2070 local nodes=${1:-$CLIENTS}
2073 # stop the client loads
2074 stop_process $nodes $pid_file
2076 # clean up the processes that started them
2077 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2079 # End recovery-scale functions
2081 # verify that lustre actually cleaned up properly
2083 VAR=$(lctl get_param -n catastrophe 2>&1)
2084 if [ $? = 0 ] ; then
2085 if [ $VAR != 0 ]; then
2086 error "LBUG/LASSERT detected"
2089 BUSY=$(dmesg | grep -i destruct || true)
2090 if [ -n "$BUSY" ]; then
2092 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2096 check_mem_leak || exit 204
2098 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2099 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2102 if module_loaded lnet || module_loaded libcfs; then
2103 echo "$TESTSUITE: modules still loaded..." 1>&2
2112 if [[ "$1" == "--verbose" ]]; then
2127 PREV_RESULT=$(do_node $node "$TEST")
2129 RESULT=$(do_node $node "$TEST")
2130 if [[ "$RESULT" == "$FINAL" ]]; then
2131 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2132 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2136 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2137 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2141 [[ $WAIT -ge $MAX ]] && break
2142 [[ $((WAIT % print)) -eq 0 ]] &&
2143 echo "Waiting $((MAX - WAIT)) secs for update"
2144 WAIT=$((WAIT + sleep))
2147 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2151 wait_update_facet() {
2153 [ "$1" = "--verbose" ] && verbose="$1" && shift
2157 wait_update $verbose $(facet_active_host $facet) "$@"
2161 do_nodes $(comma_list $(mdts_nodes)) \
2162 "lctl set_param -n osd*.*MDT*.force_sync=1"
2163 do_nodes $(comma_list $(osts_nodes)) \
2164 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2165 grep -v 'Found no match'
2169 # the occupied disk space will be released
2170 # only after DMUs are committed
2171 if [[ $(facet_fstype $1) == zfs ]]; then
2172 echo "sleep $2 for ZFS OSD"
2177 wait_delete_completed_mds() {
2178 local MAX_WAIT=${1:-20}
2179 # for ZFS, waiting more time for DMUs to be committed
2180 local ZFS_WAIT=${2:-5}
2182 local stime=$(date +%s)
2187 # find MDS with pending deletions
2188 for node in $(mdts_nodes); do
2189 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2190 2>/dev/null | calc_sum)
2191 if [[ $changes -eq 0 ]]; then
2194 mds2sync="$mds2sync $node"
2196 if [ -z "$mds2sync" ]; then
2197 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2200 mds2sync=$(comma_list $mds2sync)
2202 # sync MDS transactions
2203 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2205 # wait till all changes are sent and commmitted by OSTs
2206 # for ldiskfs space is released upon execution, but DMU
2207 # do this upon commit
2210 while [[ $WAIT -ne $MAX_WAIT ]]; do
2211 changes=$(do_nodes $mds2sync \
2212 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2213 #echo "$node: $changes changes on all"
2214 if [[ $changes -eq 0 ]]; then
2215 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2223 echo "Delete is not completed in $((etime - stime)) seconds"
2224 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2230 # we can use "for" here because we are waiting the slowest
2231 for host in ${hostlist//,/ }; do
2232 check_network "$host" 900
2234 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2241 for facet in ${facetlist//,/ }; do
2242 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2244 wait_for_host $hostlist
2247 _wait_recovery_complete () {
2250 # Use default policy if $2 is not passed by caller.
2251 local MAX=${2:-$(max_recovery_time)}
2256 while [ $WAIT -lt $MAX ]; do
2257 STATUS=$(lctl get_param -n $param | grep status)
2259 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2262 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2264 echo "$param recovery not done in $MAX sec. $STATUS"
2268 wait_recovery_complete () {
2271 # with an assumption that at_max is the same on all nodes
2272 local MAX=${2:-$(max_recovery_time)}
2275 if [ "$FAILURE_MODE" = HARD ]; then
2276 facets=$(facets_on_host $(facet_active_host $facet))
2278 echo affected facets: $facets
2280 # we can use "for" here because we are waiting the slowest
2281 for facet in ${facets//,/ }; do
2282 local var_svc=${facet}_svc
2283 local param="*.${!var_svc}.recovery_status"
2285 local host=$(facet_active_host $facet)
2286 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2290 wait_mds_ost_sync () {
2291 # just because recovery is done doesn't mean we've finished
2292 # orphan cleanup. Wait for llogs to get synchronized.
2293 echo "Waiting for orphan cleanup..."
2294 # MAX value includes time needed for MDS-OST reconnection
2295 local MAX=$(( TIMEOUT * 2 ))
2296 local WAIT_TIMEOUT=${1:-$MAX}
2299 local list=$(comma_list $(mdts_nodes))
2300 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2301 if ! do_facet $SINGLEMDS \
2302 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2304 # old way, use mds_sync
2306 list=$(comma_list $(osts_nodes))
2307 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2310 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2311 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2312 local -a sync=($(do_nodes $list "$cmd"))
2315 for ((i=0; i<${#sync[@]}; i++)); do
2317 [ ${sync[$i]} -eq 1 ] && continue
2319 [ ${sync[$i]} -eq 0 ] && continue
2321 # there is a not finished MDS-OST synchronization
2325 sleep 2 # increase waiting time and cover statfs cache
2326 [ ${con} -eq 1 ] && return 0
2327 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2331 # show which nodes are not finished.
2332 do_nodes $list "$cmd"
2333 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2337 wait_destroy_complete () {
2338 echo "Waiting for local destroys to complete"
2339 # MAX value shouldn't be big as this mean server responsiveness
2340 # never increase this just to make test pass but investigate
2341 # why it takes so long time
2344 while [ $WAIT -lt $MAX ]; do
2345 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2349 for ((i=0; i<${#RPCs[@]}; i++)); do
2350 [ ${RPCs[$i]} -eq 0 ] && continue
2351 # there are still some destroy RPCs in flight
2356 [ ${con} -eq 1 ] && return 0 # done waiting
2357 echo "Waiting ${WAIT}s for local destroys to complete"
2360 echo "Local destroys weren't done in $MAX sec."
2364 wait_delete_completed() {
2365 wait_delete_completed_mds $1 || return $?
2366 wait_destroy_complete
2375 # conf-sanity 31 takes a long time cleanup
2376 while [ $WAIT -lt 300 ]; do
2377 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2378 [ -z "${running}" ] && return 0
2379 echo "waited $WAIT for${running}"
2380 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2382 WAIT=$((WAIT + INTERVAL))
2384 echo "service didn't stop after $WAIT seconds. Still running:"
2389 wait_remote_prog () {
2395 [ "$PDSH" = "no_dsh" ] && return 0
2397 while [ $WAIT -lt $2 ]; do
2398 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2399 [ -z "${running}" ] && return 0 || true
2400 echo "waited $WAIT for: "
2402 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2404 WAIT=$((WAIT + INTERVAL))
2406 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2407 [ -z "$pids" ] && return 0
2408 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2409 # FIXME: not portable
2410 for pid in $pids; do
2411 cat /proc/${pid}/status || true
2412 cat /proc/${pid}/wchan || true
2414 kill -9 $pid || true
2423 local clients=${1:-$CLIENTS}
2425 if [ -z "$clients" ]; then
2428 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2434 # not every config has many clients
2440 # usually checked on particular client or locally
2449 client_reconnect_try() {
2450 local f=$MOUNT/recon
2453 if [ -z "$CLIENTS" ]; then
2454 $LFS df $MOUNT; uname -n >> $f
2456 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2458 echo "Connected clients: $(cat $f)"
2459 ls -l $f > /dev/null
2463 client_reconnect() {
2464 # one client_reconnect_try call does not always do the job...
2466 client_reconnect_try && break
2471 affected_facets () {
2474 local host=$(facet_active_host $facet)
2475 local affected=$facet
2477 if [ "$FAILURE_MODE" = HARD ]; then
2478 affected=$(facets_up_on_host $host)
2484 local E2FSCK_ON_MDT0=false
2485 if [ "$1" == "--fsck" ]; then
2487 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2499 #Because it will only get up facets, we need get affected
2500 #facets before shutdown
2501 #For HARD Failure mode, it needs make sure facets on the same
2502 #HOST will only be shutdown and reboot once
2503 for facet in ${facets//,/ }; do
2504 local affected_facet
2506 #check whether facet has been included in other affected facets
2507 for ((index=0; index<$total; index++)); do
2508 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2511 if [ $skip -eq 0 ]; then
2512 affecteds[$total]=$(affected_facets $facet)
2517 for ((index=0; index<$total; index++)); do
2518 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2519 local host=$(facet_active_host $facet)
2520 echo "Failing ${affecteds[index]} on $host"
2521 shutdown_facet $facet
2524 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2525 $(mdsdevname 1) "-n" || error "Running e2fsck")
2527 for ((index=0; index<$total; index++)); do
2528 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2529 echo reboot facets: ${affecteds[index]}
2533 change_active ${affecteds[index]}
2535 wait_for_facet ${affecteds[index]}
2536 # start mgs first if it is affected
2537 if ! combined_mgs_mds &&
2538 list_member ${affecteds[index]} mgs; then
2539 mount_facet mgs || error "Restart of mgs failed"
2541 # FIXME; has to be changed to mount all facets concurrently
2542 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2543 echo mount facets: ${affecteds[index]}
2544 mount_facets ${affecteds[index]}
2554 do_facet $facet "sync; sync; sync"
2557 # make sure there will be no seq change
2558 local clients=${CLIENTS:-$HOSTNAME}
2559 local f=fsa-\\\$\(hostname\)
2560 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2561 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2563 local svc=${facet}_svc
2564 do_facet $facet $LCTL --device ${!svc} notransno
2566 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2567 # in-memory state has to be cleared by either rebooting the host or
2568 # exporting and reimporting the pool.
2570 # Although the uberblocks are not updated when a pool is freezed,
2571 # transactions are still written to the disks. Modified blocks may be
2572 # cached in memory when tests try reading them back. The
2573 # export-and-reimport process also evicts any cached pool data from
2574 # memory to provide the correct "data loss" semantics.
2576 # In the test framework, the exporting and importing operations are
2577 # handled by stop() and mount_facet() separately, which are used
2578 # inside fail() and fail_abort().
2580 do_facet $facet $LCTL --device ${!svc} readonly
2581 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2582 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2585 replay_barrier_nodf() {
2586 local facet=$1 echo running=${running}
2587 do_facet $facet "sync; sync; sync"
2588 local svc=${facet}_svc
2589 echo Replay barrier on ${!svc}
2590 do_facet $facet $LCTL --device ${!svc} notransno
2591 do_facet $facet $LCTL --device ${!svc} readonly
2592 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2593 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2596 replay_barrier_nosync() {
2597 local facet=$1 echo running=${running}
2598 local svc=${facet}_svc
2599 echo Replay barrier on ${!svc}
2600 do_facet $facet $LCTL --device ${!svc} notransno
2601 do_facet $facet $LCTL --device ${!svc} readonly
2602 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2603 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2607 # Get Lustre client uuid for a given Lustre mount point.
2610 local mntpnt=${1:-$MOUNT}
2612 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2613 local uuid=$($LCTL get_param -n llite.$name.uuid)
2618 mds_evict_client() {
2619 local mntpnt=${1:-$MOUNT}
2620 local uuid=$(get_client_uuid $mntpnt)
2622 do_facet $SINGLEMDS \
2623 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2626 ost_evict_client() {
2627 local mntpnt=${1:-$MOUNT}
2628 local uuid=$(get_client_uuid $mntpnt)
2631 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2636 local clients=${CLIENTS:-$HOSTNAME}
2638 facet_failover $* || error "failover: $?"
2639 wait_clients_import_state "$clients" "$facets" FULL
2640 clients_up || error "post-failover stat: $?"
2645 facet_failover $facet
2651 change_active $facet
2652 wait_for_facet $facet
2653 mount_facet $facet -o abort_recovery
2654 clients_up || echo "first stat failed: $?"
2655 clients_up || error "post-failover stat: $?"
2659 echo There is no lmc. This is mountconf, baby.
2663 host_nids_address() {
2667 if [ -n "$kind" ]; then
2668 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2670 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2676 if [ "$1" = "'*'" ]; then echo \'*\'; else
2682 if [ "$1" = "'*'" ]; then echo \'*\'; else
2683 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2685 if [ -z "$ID" ]; then
2686 echo "Could not get a ptl id for $1..."
2695 h2name_or_ip "$1" "tcp"
2700 if [ "$1" = "'*'" ]; then echo \'*\'; else
2701 if type __h2elan >/dev/null 2>&1; then
2704 ID=`echo $1 | sed 's/[^0-9]*//g'`
2712 h2name_or_ip "$1" "o2ib"
2716 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2717 # expressions format. As a bonus we can then just pass in those variables
2718 # to pdsh. What this function does is take a HOSTLIST type string and
2719 # expand it into a space deliminated list for us.
2727 [ -z "$hostlist" ] && return
2729 # Translate the case of [..],..,[..] to [..] .. [..]
2730 list="${hostlist/],/] }"
2732 [[ "$front" == *,* ]] && {
2735 list=${list/${old}/${new}}
2738 for item in $list; do
2739 # Test if we have any []'s at all
2740 if [ "$item" != "${item/\[/}" ]; then {
2741 # Expand the [*] into list
2745 if [ "$name" != "$item" ]; then
2746 group=${item#$name[*}
2749 for range in ${group//,/ }; do
2753 # Number of leading zeros
2756 end=$(echo $end | sed 's/0*//')
2757 [[ -z "$end" ]] && end=0
2758 [[ $padlen2 -gt $padlen ]] && {
2759 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2762 begin=$(echo $begin | sed 's/0*//')
2763 [ -z $begin ] && begin=0
2765 for num in $(seq -f "%0${padlen}g" $begin $end); do
2766 value="${name#*,}${num}${back}"
2767 [ "$value" != "${value/\[/}" ] && {
2768 value=$(hostlist_expand "$value")
2770 myList="$myList $value"
2775 myList="$myList $item"
2778 myList=${myList//,/ }
2779 myList=${myList:1} # Remove first character which is a space
2781 # Filter any duplicates without sorting
2783 myList="${list%% *}"
2785 while [[ "$list" != ${myList##* } ]]; do
2786 list=${list//${list%% *} /}
2787 myList="$myList ${list%% *}"
2789 myList="${myList%* }";
2791 # We can select an object at an offset in the list
2794 for item in $myList; do
2796 [ $cnt -eq $offset ] && {
2800 [ $(get_node_count $myList) -ne 1 ] && myList=""
2809 [ "$facet" == client ] && echo -n $HOSTNAME && return
2810 varname=${facet}_HOST
2811 if [ -z "${!varname}" ]; then
2812 if [ "${facet:0:3}" == "ost" ]; then
2813 local fh=${facet%failover}_HOST
2814 eval export ${facet}_HOST=${!fh}
2815 if [ -z "${!varname}" ]; then
2816 eval export ${facet}_HOST=${ost_HOST}
2818 elif [ "${facet:0:3}" == "mdt" -o \
2819 "${facet:0:3}" == "mds" -o \
2820 "${facet:0:3}" == "mgs" ]; then
2821 eval export ${facet}_HOST=${mds_HOST}
2827 facet_failover_host() {
2831 var=${facet}failover_HOST
2832 if [ -n "${!var}" ]; then
2837 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2838 "${facet:0:3}" == "mgs" ]; then
2840 eval export ${facet}failover_host=${mds_HOST}
2845 if [[ $facet == ost* ]]; then
2846 eval export ${facet}failover_host=${ost_HOST}
2854 local activevar=${facet}active
2856 if [ -f $TMP/${facet}active ] ; then
2857 source $TMP/${facet}active
2860 active=${!activevar}
2861 if [ -z "$active" ] ; then
2868 facet_active_host() {
2869 facet_host $(facet_active $1)
2872 # Get the passive failover partner host of facet.
2873 facet_passive_host() {
2875 [[ $facet = client ]] && return
2877 local host=${facet}_HOST
2878 local failover_host=${facet}failover_HOST
2879 local active_host=$(facet_active_host $facet)
2881 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2883 if [[ $active_host = ${!host} ]]; then
2884 echo -n ${!failover_host}
2894 facetlist=$(exclude_items_from_list $facetlist mgs)
2896 for facet in ${facetlist//,/ }; do
2897 local failover=${facet}failover
2898 local host=`facet_host $failover`
2899 [ -z "$host" ] && return
2901 local curactive=`facet_active $facet`
2902 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2903 eval export ${facet}active=$facet
2905 eval export ${facet}active=$failover
2907 # save the active host for this facet
2908 local activevar=${facet}active
2909 echo "$activevar=${!activevar}" > $TMP/$activevar
2910 [[ $facet = mds1 ]] && combined_mgs_mds && \
2911 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2912 local TO=`facet_active_host $facet`
2913 echo "Failover $facet to $TO"
2919 # do not stripe off hostname if verbose, bug 19215
2920 if [ x$1 = x--verbose ]; then
2928 if [ "$HOST" = "$HOSTNAME" ]; then
2930 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2931 echo "cannot run remote command on $HOST with $myPDSH"
2935 echo "CMD: $HOST $@" >&2
2936 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2939 if [ "$myPDSH" = "rsh" ]; then
2940 # we need this because rsh does not return exit code of an executed command
2941 local command_status="$TMP/cs"
2942 rsh $HOST ":> $command_status"
2943 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2944 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2945 echo command failed >$command_status"
2946 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2951 # print HOSTNAME for myPDSH="no_dsh"
2952 if [[ $myPDSH = no_dsh ]]; then
2953 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2955 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2958 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2960 return ${PIPESTATUS[0]}
2964 do_node --verbose "$@"
2967 single_local_node () {
2968 [ "$1" = "$HOSTNAME" ]
2971 # Outputs environment variable assignments that should be passed to remote nodes
2975 local facets=$(get_facets)
2978 for var in ${!MODOPTS_*}; do
2979 value=${!var//\"/\\\"}
2980 echo -n " ${var}=\"$value\""
2983 for facet in ${facets//,/ }; do
2985 if [ -n "${!var}" ]; then
2986 echo -n " $var=${!var}"
2990 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2991 if [ -n "${!var}" ]; then
2992 echo -n " $var=${!var}"
2996 for var in VERBOSE; do
2997 if [ -n "${!var}" ]; then
2998 echo -n " $var=${!var}"
3002 if [ -n "$FSTYPE" ]; then
3003 echo -n " FSTYPE=$FSTYPE"
3006 for var in LNETLND NETTYPE; do
3007 if [ -n "${!var}" ]; then
3008 echo -n " $var=${!var}"
3015 # do not stripe off hostname if verbose, bug 19215
3016 if [ x$1 = x--verbose ]; then
3024 if single_local_node $rnodes; then
3026 do_nodev $rnodes "$@"
3028 do_node $rnodes "$@"
3033 # This is part from do_node
3036 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3037 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3039 export FANOUT=$(get_node_count "${rnodes//,/ }")
3041 echo "CMD: $rnodes $@" >&2
3042 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3045 # do not replace anything from pdsh output if -N is used
3046 # -N Disable hostname: prefix on lines of output.
3047 if $verbose || [[ $myPDSH = *-N* ]]; then
3048 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3050 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3052 return ${PIPESTATUS[0]}
3056 # Execute commands on a single service's host
3058 # The \a facet (service) may be on a local or remote node, which is
3059 # determined at the time the command is run.
3061 # usage: do_facet $facet command [arg ...]
3065 local HOST=$(facet_active_host $facet)
3066 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3070 # Function: do_facet_random_file $FACET $FILE $SIZE
3071 # Creates FILE with random content on the given FACET of given SIZE
3073 do_facet_random_file() {
3077 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3078 do_facet $facet "$cmd 2>/dev/null"
3081 do_facet_create_file() {
3085 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3086 do_facet $facet "$cmd 2>/dev/null"
3090 do_nodes --verbose "$@"
3096 # make sure its not already running
3098 rm -f $TMP/${facet}active
3099 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3100 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3102 if [[ $(facet_fstype $facet) == zfs ]]; then
3104 # After formatting a ZFS target, "cachefile=none" property will
3105 # be set on the ZFS storage pool so that the pool is not
3106 # automatically imported on system startup. And then the pool
3107 # will be exported so as to leave the importing and exporting
3108 # operations handled by mount_facet() and stop() separately.
3110 refresh_partition_table $facet $(facet_vdevice $facet)
3111 disable_zpool_cache $facet
3116 # Device formatted as ost
3119 local DEVNAME=OSTDEV$num
3121 local fstype=$(facet_fstype ost$num)
3125 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3126 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3128 #try $OSTZFSDEVn - independent of vdev
3129 DEVNAME=OSTZFSDEV$num
3130 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3132 error "unknown fstype!";;
3138 # Physical device location of data
3144 local fstype=$(facet_fstype ost$num)
3148 # vdevs are not supported by ldiskfs
3151 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3152 # Device formatted by zfs
3154 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3156 error "unknown fstype!";;
3162 # Logical device formatted for lustre
3165 local DEVNAME=MDSDEV$num
3167 local fstype=$(facet_fstype mds$num)
3171 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3172 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3174 # try $MDSZFSDEVn - independent of vdev
3175 DEVNAME=MDSZFSDEV$num
3176 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3178 error "unknown fstype!";;
3184 # Physical location of data
3188 local fstype=$(facet_fstype mds$num)
3192 # vdevs are not supported by ldiskfs
3195 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3196 # Device formatted by ZFS
3197 local DEVNAME=MDSDEV$num
3198 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3200 error "unknown fstype!";;
3208 local fstype=$(facet_fstype mgs)
3212 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3213 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3214 DEVPTR=$(mdsdevname 1)
3219 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3220 ( [ -z "$MGSZFSDEV" ] &&
3221 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3222 DEVPTR=$(mdsdevname 1)
3224 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3227 error "unknown fstype!";;
3236 local fstype=$(facet_fstype mgs)
3240 # vdevs are not supported by ldiskfs
3243 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3244 ( [ -z "$MGSDEV" ] &&
3245 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3246 VDEVPTR=$(mdsvdevname 1)
3247 elif [ -n "$MGSDEV" ]; then
3251 error "unknown fstype!";;
3259 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3261 local var=${facet}_MOUNT
3262 eval mntpt=${!var:-${MOUNT}-$facet}
3269 local dev=$(facet_device $facet)
3270 local mnt=${2:-$(facet_mntpt $facet)}
3273 if ! do_facet $facet test -b $dev; then
3276 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3281 local dev=$(facet_device $facet)
3282 local mnt=${2:-$(facet_mntpt $facet)}
3284 do_facet $facet $UMOUNT $mnt
3288 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3293 local ds=$(facet_device $facet)
3294 local mnt=${2:-$(facet_mntpt $facet)}
3299 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3300 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3301 do_facet $facet $ZFS set canmount=noauto $ds
3303 # The "legacy" mount method is used here because "zfs unmount $mnt"
3304 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3305 # targets are not available at the time, the stat(2) on $MOUNT will
3308 do_facet $facet $ZFS set mountpoint=legacy $ds
3309 do_facet $facet mount -t zfs $ds $mnt
3310 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3311 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3316 local ds=$(facet_device $facet)
3317 local mnt=${2:-$(facet_mntpt $facet)}
3318 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3319 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3320 local mntpt=${!var_mntpt}
3321 local canmnt=${!var_canmnt}
3325 do_facet $facet umount $mnt
3326 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3327 do_facet $facet $ZFS set canmount=$canmnt $ds
3334 local fstype=$(facet_fstype $facet)
3336 mount_$fstype $facet $mnt
3342 local fstype=$(facet_fstype $facet)
3344 unmount_$fstype $facet $mnt
3351 # make sure we are using the primary server, so test-framework will
3352 # be able to clean up properly.
3353 activemds=`facet_active mds1`
3354 if [ $activemds != "mds1" ]; then
3358 local clients=$CLIENTS
3359 [ -z $clients ] && clients=$(hostname)
3361 zconf_umount_clients $clients $MOUNT "$*" || true
3362 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3364 [ -n "$CLIENTONLY" ] && return
3366 # The add fn does rm ${facet}active file, this would be enough
3367 # if we use do_facet <facet> only after the facet added, but
3368 # currently we use do_facet mds in local.sh
3369 for num in `seq $MDSCOUNT`; do
3371 rm -f ${TMP}/mds${num}active
3373 combined_mgs_mds && rm -f $TMP/mgsactive
3375 for num in `seq $OSTCOUNT`; do
3377 rm -f $TMP/ost${num}active
3380 if ! combined_mgs_mds ; then
3387 cleanup_echo_devs () {
3390 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3392 for dev in $devs; do
3393 $LCTL --device $dev cleanup
3394 $LCTL --device $dev detach
3399 nfs_client_mode && return
3400 cifs_client_mode && return
3409 combined_mgs_mds () {
3410 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3411 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3415 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3419 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3425 local fsname=${3:-"$FSNAME"}
3426 local type=$(facet_type $facet)
3427 local index=$(facet_index $facet)
3428 local fstype=$(facet_fstype $facet)
3429 local host=$(facet_host $facet)
3434 if [ $type == MGS ] || ( [ $type == MDS ] &&
3435 [ "$dev" == $(mgsdevname) ] &&
3436 [ "$host" == "$(facet_host mgs)" ] ); then
3439 opts="--mgsnode=$MGSNID"
3442 if [ $type != MGS ]; then
3443 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3447 var=${facet}failover_HOST
3448 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3449 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3452 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3453 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3455 if [ $type == MDS ]; then
3456 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3457 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3458 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3459 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3461 if [ $fstype == ldiskfs ]; then
3462 # Check for wide striping
3463 if [ $OSTCOUNT -gt 160 ]; then
3464 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3465 fs_mkfs_opts+="-O large_xattr"
3469 if [ -n "${!var}" ]; then
3470 fs_mkfs_opts+=" -J device=${!var}"
3472 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3474 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3478 if [ $type == OST ]; then
3479 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3481 if [ $fstype == ldiskfs ]; then
3483 if [ -n "${!var}" ]; then
3484 fs_mkfs_opts+=" -J device=${!var}"
3486 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3491 opts+=" --backfstype=$fstype"
3494 if [ -n "${!var}" ]; then
3495 opts+=" --device-size=${!var}"
3498 var=$(upper $fstype)_MKFS_OPTS
3499 fs_mkfs_opts+=${!var:+" ${!var}"}
3501 var=${type}_FS_MKFS_OPTS
3502 fs_mkfs_opts+=${!var:+" ${!var}"}
3504 if [ -n "${fs_mkfs_opts## }" ]; then
3505 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3509 opts+=${!var:+" ${!var}"}
3514 check_ost_indices() {
3515 local index_count=${#OST_INDICES[@]}
3516 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3518 # OST count is greater than the index count in $OST_INDEX_LIST.
3519 # We need check whether there are duplicate indices.
3523 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3524 index=$(facet_index ost$i)
3525 for j in $(seq 0 $((index_count - 1))); do
3526 [[ $index -ne ${OST_INDICES[j]} ]] ||
3527 error "ost$i has the same index $index as ost$((j+1))"
3538 echo "Format mgs: $(mgsdevname)"
3539 reformat_external_journal mgs
3540 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3541 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3551 echo "Format mds$num: $(mdsdevname $num)"
3552 reformat_external_journal mds$num
3553 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3554 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3555 ${quiet:+>/dev/null} || exit 10
3564 echo "Format ost$num: $(ostdevname $num)"
3565 reformat_external_journal ost$num
3566 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3567 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3568 ${quiet:+>/dev/null} || exit 10
3573 # Set hostid for ZFS/SPL zpool import protection
3574 # (Assumes MDS version is also OSS version)
3575 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3577 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3580 # We need ldiskfs here, may as well load them all
3582 [ -n "$CLIENTONLY" ] && return
3583 echo Formatting mgs, mds, osts
3584 if ! combined_mgs_mds ; then
3588 for num in $(seq $MDSCOUNT); do
3592 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3594 for num in $(seq $OSTCOUNT); do
3600 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3604 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3608 # 0: success, the old identity set already.
3609 # 1: success, the old identity does not set.
3614 local j=`expr $num - 1`
3615 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3617 if [ -z "$MDT" ]; then
3621 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3624 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3626 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3629 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3631 if [ $old = "NONE" ]; then
3640 zconf_umount `hostname` $1 || error "umount failed"
3641 zconf_mount `hostname` $1 || error "mount failed"
3649 rm -f $TMP/${facet}active
3650 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3655 local mdt_count=${1:-$MDSCOUNT}
3656 local ost_count=${2:-$OSTCOUNT}
3659 for num in $(seq $mdt_count); do
3660 DEVNAME=$(mdsdevname $num)
3661 writeconf_facet mds$num $DEVNAME || rc=$?
3664 for num in $(seq $ost_count); do
3665 DEVNAME=$(ostdevname $num)
3666 writeconf_facet ost$num $DEVNAME || rc=$?
3672 nfs_client_mode && return
3673 cifs_client_mode && return
3675 sanity_mount_check || error "environments are insane!"
3679 if [ -z "$CLIENTONLY" ]; then
3680 echo Setup mgs, mdt, osts
3681 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3682 if ! combined_mgs_mds ; then
3683 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3686 for num in `seq $MDSCOUNT`; do
3687 DEVNAME=$(mdsdevname $num)
3688 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3690 # We started mds, now we should set failover variables properly.
3691 # Set mds${num}failover_HOST if it is not set (the default failnode).
3692 local varname=mds${num}failover_HOST
3693 if [ -z "${!varname}" ]; then
3694 eval mds${num}failover_HOST=$(facet_host mds$num)
3697 if [ $IDENTITY_UPCALL != "default" ]; then
3698 switch_identity $num $IDENTITY_UPCALL
3701 for num in `seq $OSTCOUNT`; do
3702 DEVNAME=$(ostdevname $num)
3703 start ost$num $DEVNAME $OST_MOUNT_OPTS
3705 # We started ost$num, now we should set ost${num}failover variable properly.
3706 # Set ost${num}failover_HOST if it is not set (the default failnode).
3707 varname=ost${num}failover_HOST
3708 if [ -z "${!varname}" ]; then
3709 eval ost${num}failover_HOST=$(facet_host ost${num})
3717 # wait a while to allow sptlrpc configuration be propogated to targets,
3718 # only needed when mounting new target devices.
3723 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3725 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3728 if [ "$MOUNT_2" ]; then
3729 mount_client $MOUNT2
3730 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3735 # by remounting mdt before ost, initial connect from mdt to ost might
3736 # timeout because ost is not ready yet. wait some time to its fully
3737 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3738 # by a context negotiation rpc with $TIMEOUT.
3739 # FIXME better by monitoring import status.
3742 sleep $((TIMEOUT + 5))
3748 mounted_lustre_filesystems() {
3749 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3752 init_facet_vars () {
3753 [ -n "$CLIENTONLY" ] && return 0
3760 eval export ${facet}_dev=${device}
3761 eval export ${facet}_opt=\"$@\"
3763 local dev=${facet}_dev
3765 # We need to loop for the label
3766 # in case its not initialized yet.
3767 for wait_time in {0,1,3,5,10}; do
3769 if [ $wait_time -gt 0 ]; then
3770 echo "${!dev} not yet initialized,"\
3771 "waiting ${wait_time} seconds."
3775 local label=$(devicelabel ${facet} ${!dev})
3777 # Check to make sure the label does
3778 # not include ffff at the end of the label.
3779 # This indicates it has not been initialized yet.
3781 if [[ $label =~ [f|F]{4}$ ]]; then
3782 # label is not initialized, unset the result
3783 # and either try again or fail
3790 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3792 eval export ${facet}_svc=${label}
3794 local varname=${facet}failover_HOST
3795 if [ -z "${!varname}" ]; then
3796 eval export $varname=$(facet_host $facet)
3799 varname=${facet}_HOST
3800 if [ -z "${!varname}" ]; then
3801 eval export $varname=$(facet_host $facet)
3804 # ${facet}failover_dev is set in cfg file
3805 varname=${facet}failover_dev
3806 if [ -n "${!varname}" ] ; then
3807 eval export ${facet}failover_dev=${!varname}
3809 eval export ${facet}failover_dev=$device
3812 # get mount point of already mounted device
3813 # is facet_dev is already mounted then use the real
3814 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3815 # i.e. ${facet}_MOUNT if specified by user or default
3816 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3817 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3818 if [ -z $mntpt ]; then
3819 mntpt=$(facet_mntpt $facet)
3821 eval export ${facet}_MOUNT=$mntpt
3824 init_facets_vars () {
3827 if ! remote_mds_nodsh; then
3828 for num in $(seq $MDSCOUNT); do
3829 DEVNAME=`mdsdevname $num`
3830 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3834 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3836 if ! remote_ost_nodsh; then
3837 for num in $(seq $OSTCOUNT); do
3838 DEVNAME=$(ostdevname $num)
3839 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3844 osc_ensure_active () {
3849 while [ $period -lt $timeout ]; do
3850 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3851 if [ $count -eq 0 ]; then
3855 echo "There are $count OST are inactive, wait $period seconds, and try again"
3857 period=$((period+3))
3860 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3863 set_conf_param_and_check() {
3867 local ORIG=$(do_facet $myfacet "$TEST")
3868 if [ $# -gt 3 ]; then
3874 echo "Setting $PARAM from $ORIG to $FINAL"
3875 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3876 error "conf_param $PARAM failed"
3878 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3879 error "check $PARAM failed!"
3882 init_param_vars () {
3883 TIMEOUT=$(lctl get_param -n timeout)
3884 TIMEOUT=${TIMEOUT:-20}
3886 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3888 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3889 log "Using TIMEOUT=$TIMEOUT"
3891 osc_ensure_active $SINGLEMDS $TIMEOUT
3892 osc_ensure_active client $TIMEOUT
3894 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3895 local current_jobid_var=$($LCTL get_param -n jobid_var)
3897 if [ $JOBID_VAR = "existing" ]; then
3898 echo "keeping jobstats as $current_jobid_var"
3899 elif [ $current_jobid_var != $JOBID_VAR ]; then
3900 echo "seting jobstats to $JOBID_VAR"
3902 set_conf_param_and_check client \
3903 "$LCTL get_param -n jobid_var" \
3904 "$FSNAME.sys.jobid_var" $JOBID_VAR
3907 echo "jobstats not supported by server"
3910 if [ $QUOTA_AUTO -ne 0 ]; then
3911 if [ "$ENABLE_QUOTA" ]; then
3912 echo "enable quota as required"
3913 setup_quota $MOUNT || return 2
3915 echo "disable quota as required"
3916 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3922 nfs_client_mode () {
3923 if [ "$NFSCLIENT" ]; then
3924 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3925 local clients=$CLIENTS
3926 [ -z $clients ] && clients=$(hostname)
3928 # FIXME: remove hostname when 19215 fixed
3929 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3930 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3931 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3932 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3934 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3940 cifs_client_mode () {
3941 [ x$CIFSCLIENT = xyes ] &&
3942 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3945 check_config_client () {
3948 local mounted=$(mount | grep " $mntpt ")
3949 if [ -n "$CLIENTONLY" ]; then
3951 # CLIENTONLY should not depend on *_HOST settings
3952 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3953 # in theory someone could create a new,
3954 # client-only config file that assumed lustre was already
3955 # configured and didn't set the MGSNID. If MGSNID is not set,
3956 # then we should use the mgs nid currently being used
3957 # as the default value. bug 18021
3958 [[ x$MGSNID = x ]] &&
3961 if [[ x$mgc != xMGC$MGSNID ]]; then
3962 if [ "$mgs_HOST" ]; then
3963 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3964 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3965 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3971 local myMGS_host=$mgs_HOST
3972 if [ "$NETTYPE" = "ptl" ]; then
3973 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3976 echo Checking config lustre mounted on $mntpt
3977 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3978 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3980 # if [ "$mgshost" != "$myMGS_host" ]; then
3981 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3982 # Please use correct config or set mds_HOST correctly!"
3987 check_config_clients () {
3988 local clients=${CLIENTS:-$HOSTNAME}
3991 nfs_client_mode && return
3992 cifs_client_mode && return
3994 do_rpc_nodes "$clients" check_config_client $mntpt
3996 sanity_mount_check || error "environments are insane!"
4000 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4001 local cltimeout=$(lctl get_param -n timeout)
4002 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4003 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4010 [ -z $mntpt ] && return 1
4011 local mounted=$(mounted_lustre_filesystems)
4013 echo $mounted' ' | grep -w -q $mntpt' '
4017 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4021 # empty lustre filesystem may have empty directories lost+found and .lustre
4023 # exclude .lustre & lost+found
4024 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4025 -print | wc -l) = 1 ] || return 1
4026 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4027 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4028 # exclude .lustre/fid (LU-2780)
4029 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4030 -print | wc -l) = 1 ] || return 1
4032 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4037 check_and_setup_lustre() {
4039 nfs_client_mode && return
4040 cifs_client_mode && return
4042 local MOUNTED=$(mounted_lustre_filesystems)
4046 # both MOUNT and MOUNT2 are not mounted
4047 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4048 [ "$REFORMAT" = "yes" ] && formatall
4049 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4051 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4052 export I_MOUNTED=yes
4056 elif is_mounted $MOUNT2; then
4058 # MOUNT2 is mounted, while MOUNT_2 is not set
4059 if ! [ "$MOUNT_2" ]; then
4060 cleanup_mount $MOUNT2
4061 export I_UMOUNTED2=yes
4064 # MOUNT2 is mounted, MOUNT_2 is set
4066 # FIXME: what to do if check_config failed?
4068 # 1) remote client has mounted other Lustre fs ?
4069 # 2) it has insane env ?
4070 # let's try umount MOUNT2 on all clients and mount it again:
4071 if ! check_config_clients $MOUNT2; then
4072 cleanup_mount $MOUNT2
4073 restore_mount $MOUNT2
4074 export I_MOUNTED2=yes
4079 # MOUNT is mounted MOUNT2 is not mounted
4080 elif [ "$MOUNT_2" ]; then
4081 restore_mount $MOUNT2
4082 export I_MOUNTED2=yes
4086 # FIXME: what to do if check_config failed?
4088 # 1) remote client has mounted other Lustre fs?
4089 # 2) lustre is mounted on remote_clients atall ?
4090 check_config_clients $MOUNT
4094 set_default_debug_nodes $(comma_list $(nodes_list))
4097 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4099 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4100 facets="$(get_facets OST)"
4101 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4102 facets="$facets,$(get_facets MDS)"
4103 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4104 facets="$facets,mgs"
4105 local nodes="$(facets_hosts ${facets})"
4106 if [ -n "$nodes" ] ; then
4107 do_nodes $nodes "$LCTL set_param \
4108 osd-ldiskfs.track_declares_assert=1 || true"
4117 if [ -z "$CLIENTONLY" ]; then
4118 # Enable remote MDT create for testing
4119 for num in $(seq $MDSCOUNT); do
4121 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4126 if [ "$ONLY" == "setup" ]; then
4132 local clients=${CLIENTS:-$HOSTNAME}
4135 zconf_mount_clients $clients $mntpt
4139 local clients=${CLIENTS:-$HOSTNAME}
4142 zconf_umount_clients $clients $mntpt
4145 cleanup_and_setup_lustre() {
4146 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4147 lctl set_param debug=0 || true
4149 if [ "$ONLY" == "cleanup" ]; then
4153 check_and_setup_lustre
4156 # Get all of the server target devices from a given server node and type.
4163 if [ "$type" == ost ]; then
4164 devs=$(get_osd_param $node "" mntdev)
4166 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4168 for dev in $devs; do
4170 *loop*) do_node $node "losetup $dev" | \
4171 sed -e "s/.*(//" -e "s/).*//" ;;
4177 # Get all of the server target devices.
4182 # Master MDS parameters used by lfsck
4183 MDTNODE=$(facet_active_host $SINGLEMDS)
4184 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4188 for node in $(mdts_nodes); do
4189 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4195 for node in $(osts_nodes); do
4196 OSTDEVS[i]=$(get_mnt_devs $node ost)
4201 # Run e2fsck on MDT or OST device.
4206 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4207 local log=$TMP/e2fsck.log
4211 do_node $node $cmd 2>&1 | tee $log
4213 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4215 if [ $MDSCOUNT -gt 1 ]; then
4216 skip "DNE mode isn't supported!"
4220 error "It's not DNE mode."
4225 [ $rc -le $FSCK_MAX_ERR ] ||
4226 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4232 # Run resize2fs on MDT or OST device.
4241 do_facet $facet "$RESIZE2FS $opts $device $size"
4244 # verify a directory is shared among nodes.
4245 check_shared_dir() {
4247 local list=${2:-$(comma_list $(nodes_list))}
4249 [ -z "$dir" ] && return 1
4250 do_rpc_nodes "$list" check_logdir $dir
4251 check_write_access $dir "$list" || return 1
4256 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4257 $LCTL set_param printk=+lfsck
4258 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4260 for k in $(seq $MDSCOUNT); do
4261 # wait up to 10+1 minutes for LFSCK to complete
4262 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4263 mdd.$(facet_svc mds${k}).lfsck_layout |
4264 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4265 error "MDS${k} layout isn't the expected 'completed'"
4266 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4267 mdd.$(facet_svc mds${k}).lfsck_namespace |
4268 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4269 error "MDS${k} namespace isn't the expected 'completed'"
4271 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4272 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4273 awk '/repaired/ { print $2 }' | calc_sum)
4274 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4275 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4276 awk '/repaired/ { print $2 }' | calc_sum)
4277 local repaired=$((rep_mdt + rep_ost))
4278 [ $repaired -eq 0 ] ||
4279 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4282 dump_file_contents() {
4288 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4289 error_noexit false \
4290 "Invalid parameters for dump_file_contents()"
4293 for node in ${nodes}; do
4294 do_node $node "for i in \\\$(find $dir -type f); do
4295 echo ====\\\${i}=======================;
4297 done" >> ${logname}.${node}.log
4301 dump_command_output() {
4307 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4308 error_noexit false \
4309 "Invalid parameters for dump_command_output()"
4313 for node in ${nodes}; do
4314 do_node $node "echo ====${cmd}=======================;
4315 $cmd" >> ${logname}.${node}.log
4322 # dump file contents from /proc/spl in case of zfs test
4323 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4324 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4325 dump_command_output \
4326 "$(osts_nodes)" "zpool events -v" "${logname}"
4329 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4330 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4331 dump_command_output \
4332 "$(mdts_nodes)" "zpool events -v" "${logname}"
4336 check_and_cleanup_lustre() {
4337 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4338 "$TESTSUITE" != "sanity-scrub" ]; then
4342 if is_mounted $MOUNT; then
4343 if $DO_CLEANUP; then
4344 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4345 error "remove sub-test dirs failed"
4349 [ "$ENABLE_QUOTA" ] && restore_quota || true
4352 if [ "$I_UMOUNTED2" = "yes" ]; then
4353 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4356 if [ "$I_MOUNTED2" = "yes" ]; then
4357 cleanup_mount $MOUNT2
4360 if [ "$I_MOUNTED" = "yes" ]; then
4361 cleanupall -f || error "cleanup failed"
4369 wait_for_function () {
4372 # suppress fn both stderr and stdout
4373 if [ "$1" = "--quiet" ]; then
4375 quiet=" > /dev/null 2>&1"
4387 eval $fn $quiet && return 0
4389 wait=$((wait + sleep))
4390 [ $wait -lt $max ] || return 1
4391 echo waiting $fn, $((max - wait)) secs left ...
4401 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4402 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4403 echo "Network not available!"
4407 echo `date +"%H:%M:%S (%s)"` network interface is UP
4415 # Convert a space-delimited list to a comma-delimited list. If the input is
4416 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4418 # echo is used to convert newlines to spaces, since it doesn't
4419 # introduce a trailing space as using "tr '\n' ' '" does
4420 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4426 echo $list | grep -qw $item
4429 # list, excluded are the comma separated lists
4430 exclude_items_from_list () {
4436 for item in ${excluded//,/ }; do
4437 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4439 echo $(comma_list $list)
4442 # list, expand are the comma separated lists
4444 local list=${1//,/ }
4445 local expand=${2//,/ }
4448 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4449 echo $(comma_list $expanded)
4452 testslist_filter () {
4453 local script=$LUSTRE/tests/${TESTSUITE}.sh
4455 [ -f $script ] || return 0
4457 local start_at=$START_AT
4458 local stop_at=$STOP_AT
4460 local var=${TESTSUITE//-/_}_START_AT
4461 [ x"${!var}" != x ] && start_at=${!var}
4462 var=${TESTSUITE//-/_}_STOP_AT
4463 [ x"${!var}" != x ] && stop_at=${!var}
4465 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4466 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4467 /^'${start_at}'$/ {flag = 0}
4468 {if (flag == 1) print $0}
4469 /^'${stop_at}'$/ { flag = 1 }'
4473 (cd `dirname $1`; echo $PWD/`basename $1`)
4477 local types=${1:-"OST MDS MGS"}
4481 for entry in $types; do
4482 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4483 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4486 MGS ) list="$list $name";;
4487 MDS|OST|AGT ) local count=${type}COUNT
4488 for ((i=1; i<=${!count}; i++)) do
4489 list="$list ${name}$i"
4491 * ) error "Invalid facet type"
4495 echo $(comma_list $list)
4498 ##################################
4499 # Adaptive Timeouts funcs
4502 # only check mds, we assume at_max is the same on all nodes
4503 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4504 if [ $at_max -eq 0 ]; then
4515 # suppose that all ost-s have the same $at value set
4516 [ $facet != "ost" ] || facet=ost1
4518 do_facet $facet "lctl get_param -n $at"
4536 if [ $facet == "ost" ]; then
4537 facet=$(get_facets OST)
4538 elif [ $facet == "mds" ]; then
4539 facet=$(get_facets MDS)
4541 hosts=$(expand_list $hosts $(facets_hosts $facet))
4544 do_nodes $hosts lctl set_param at_max=$at_max
4547 ##################################
4551 # OBD_FAIL_MDS_ALL_REQUEST_NET
4553 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4554 do_facet client "$1" || RC=$?
4555 do_facet $SINGLEMDS lctl set_param fail_loc=0
4560 # OBD_FAIL_MDS_ALL_REPLY_NET
4562 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4564 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4568 drop_reint_reply() {
4569 # OBD_FAIL_MDS_REINT_NET_REP
4571 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4573 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4577 drop_update_reply() {
4578 # OBD_FAIL_OUT_UPDATE_NET_REP
4582 do_facet mds${index} lctl set_param fail_loc=0x1701
4583 do_facet client "$@" || RC=$?
4584 do_facet mds${index} lctl set_param fail_loc=0
4589 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4592 local timeout=${2:-0}
4593 # default is (obd_timeout / 4) if unspecified
4594 echo "timeout is $timeout/$2"
4595 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4596 do_facet client "$1" || RC=$?
4597 do_facet client "sync"
4598 do_facet ost1 lctl set_param fail_loc=0
4602 drop_ldlm_cancel() {
4603 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4605 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4606 do_nodes $list lctl set_param fail_loc=0x304
4608 do_facet client "$@" || RC=$?
4610 do_nodes $list lctl set_param fail_loc=0
4614 drop_bl_callback_once() {
4616 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4617 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4618 do_facet client lctl set_param fail_loc=0x80000305
4619 do_facet client "$@" || rc=$?
4620 do_facet client lctl set_param fail_loc=0
4621 do_facet client lctl set_param fail_val=0
4622 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4626 drop_bl_callback() {
4628 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4629 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4630 do_facet client lctl set_param fail_loc=0x305
4631 do_facet client "$@" || rc=$?
4632 do_facet client lctl set_param fail_loc=0
4633 do_facet client lctl set_param fail_val=0
4634 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4639 #define OBD_FAIL_LDLM_REPLY 0x30c
4641 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4642 do_nodes $list lctl set_param fail_loc=0x30c
4644 do_facet client "$@" || RC=$?
4646 do_nodes $list lctl set_param fail_loc=0
4650 drop_ldlm_reply_once() {
4651 #define OBD_FAIL_LDLM_REPLY 0x30c
4653 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4654 do_nodes $list lctl set_param fail_loc=0x8000030c
4656 do_facet client "$@" || RC=$?
4658 do_nodes $list lctl set_param fail_loc=0
4666 echo "clearing fail_loc on $facet"
4667 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4670 set_nodes_failloc () {
4672 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4675 cancel_lru_locks() {
4676 #$LCTL mark "cancel_lru_locks $1 start"
4677 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4678 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4679 #$LCTL mark "cancel_lru_locks $1 stop"
4684 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4685 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4686 echo "$DEFAULT_LRU_SIZE"
4691 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4694 lru_resize_disable()
4696 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4702 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4708 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4709 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4710 echo there is still data in page cache $FILE ?
4711 lctl get_param -n $FILE
4719 DEBUGSAVE="$(lctl get_param -n debug)"
4720 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4724 [ -n "$DEBUGSAVE" ] &&
4725 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4729 [ -n "$DEBUGSAVE_SERVER" ] &&
4730 do_nodes $(comma_list $(all_server_nodes)) \
4731 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4737 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4740 debug_size_restore() {
4741 [ -n "$DEBUG_SIZE_SAVED" ] && \
4742 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4746 start_full_debug_logging() {
4751 local DEBUG_SIZE=150
4753 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4754 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4757 stop_full_debug_logging() {
4762 # prints bash call stack
4763 print_stack_trace() {
4766 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4767 local src=${BASH_SOURCE[$i]}
4768 local lineno=${BASH_LINENO[$i-1]}
4769 local funcname=${FUNCNAME[$i]}
4770 echo " = $src:$lineno:$funcname()"
4775 local TYPE=${TYPE:-"FAIL"}
4778 # do not dump logs if $1=false
4779 if [ "x$1" = "xfalse" ]; then
4784 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4785 (print_stack_trace 2) >&2
4787 # We need to dump the logs on all nodes
4789 gather_logs $(comma_list $(nodes_list))
4793 [ "$TESTSUITELOG" ] &&
4794 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4795 if [ -z "$*" ]; then
4796 echo "error() without useful message, please fix" > $LOGDIR/err
4798 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4799 echo "$@" > $LOGDIR/ignore
4801 echo "$@" > $LOGDIR/err
4805 # cleanup the env for failed tests
4809 ##################################
4811 ##################################
4819 local log=$TESTSUITELOG
4821 [ -f "$log" ] && grep -q FAIL $log && status=1
4835 # use only if we are ignoring failures for this test, bugno required.
4836 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4837 # e.g. error_ignore bz5494 "your message" or
4838 # error_ignore LU-5494 "your message"
4840 local TYPE="IGNORE ($1)"
4845 error_and_remount() {
4847 remount_client $MOUNT
4851 # Throw an error if it's not running in vm - usually for performance
4854 local virt=$(running_in_vm)
4855 if [[ -n "$virt" ]]; then
4856 echo "running in VM '$virt', ignore error"
4857 error_ignore env=$virt "$@"
4864 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4869 log " SKIP: $TESTSUITE $TESTNAME $@"
4871 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4872 skip_logged $TESTNAME "$@"
4875 echo "$@" > $LOGDIR/skip
4878 [[ -n "$TESTSUITELOG" ]] &&
4879 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4882 build_test_filter() {
4883 EXCEPT="$EXCEPT $(testslist_filter)"
4886 if [[ $O = [0-9]*-[0-9]* ]]; then
4887 for num in $(seq $(echo $O | tr '-' ' ')); do
4895 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4896 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4897 [ "$EXCEPT_SLOW" ] && \
4898 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4899 for E in $EXCEPT; do
4900 eval EXCEPT_${E}=true
4902 for E in $ALWAYS_EXCEPT; do
4903 eval EXCEPT_ALWAYS_${E}=true
4905 for E in $EXCEPT_SLOW; do
4906 eval EXCEPT_SLOW_${E}=true
4908 for G in $GRANT_CHECK_LIST; do
4909 eval GCHECK_ONLY_${G}=true
4914 if [[ $1 = [a-z]* ]]; then
4921 # print a newline if the last test was skipped
4922 export LAST_SKIPPED=
4923 export ALWAYS_SKIPPED=
4925 # Main entry into test-framework. This is called with the name and
4926 # description of a test. The name is used to find the function to run
4927 # the test using "test_$name".
4929 # This supports a variety of methods of specifying specific test to
4930 # run or not run. These need to be documented...
4935 export base=$(basetest $1)
4936 if [ -n "$ONLY" ]; then
4938 if [ ${!testname}x != x ]; then
4939 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4940 run_one_logged $1 "$2"
4944 if [ ${!testname}x != x ]; then
4945 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4946 run_one_logged $1 "$2"
4956 if [ ${!testname}x != x ]; then
4957 TESTNAME=test_$1 skip "skipping excluded test $1"
4960 testname=EXCEPT_$base
4961 if [ ${!testname}x != x ]; then
4962 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4965 testname=EXCEPT_ALWAYS_$1
4966 if [ ${!testname}x != x ]; then
4967 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4970 testname=EXCEPT_ALWAYS_$base
4971 if [ ${!testname}x != x ]; then
4972 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4975 testname=EXCEPT_SLOW_$1
4976 if [ ${!testname}x != x ]; then
4977 TESTNAME=test_$1 skip "skipping SLOW test $1"
4980 testname=EXCEPT_SLOW_$base
4981 if [ ${!testname}x != x ]; then
4982 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4988 run_one_logged $1 "$2"
4995 load_module ../libcfs/libcfs/libcfs
5007 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5012 strace -o $TMP/$1.strace -ttt $*
5014 log "FINISHED: $*: rc $RC"
5021 banner test complete, duration $duration sec
5022 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5023 echo duration $duration >>$TESTSUITELOG
5027 # Set TEST_STATUS here. It will be used for logging the result.
5030 if [[ -f $LOGDIR/err ]]; then
5032 elif [[ -f $LOGDIR/skip ]]; then
5035 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5039 local FFREE=$(do_node $SINGLEMDS \
5040 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5041 local FTOTAL=$(do_node $SINGLEMDS \
5042 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5044 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5048 echo -n "Resetting fail_loc on all nodes..."
5049 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5050 fail_val=0 2>/dev/null" || true
5056 # Log a message (on all nodes) padded with "=" before and after.
5057 # Also appends a timestamp and prepends the testsuite name.
5060 EQUALS="===================================================================================================="
5062 msg="== ${TESTSUITE} $*"
5064 [[ $last != "=" && $last != " " ]] && msg="$msg "
5065 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5066 # always include at least == after the message
5067 log "$msg== $(date +"%H:%M:%S (%s)")"
5070 check_dmesg_for_errors() {
5072 local errors="VFS: Busy inodes after unmount of\|\
5073 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5074 group descriptors corrupted"
5076 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5077 [ -z "$res" ] && return 0
5078 echo "Kernel error detected: $res"
5083 # Run a single test function and cleanup after it.
5085 # This function should be run in a subshell so the test func can
5086 # exit() without stopping the whole script.
5091 export tfile=f${testnum}.${TESTSUITE}
5092 export tdir=d${testnum}.${TESTSUITE}
5093 export TESTNAME=test_$testnum
5094 local SAVE_UMASK=`umask`
5097 if ! grep -q $DIR /proc/mounts; then
5101 banner "test $testnum: $message"
5102 test_${testnum} || error "test_$testnum failed with $?"
5105 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5107 check_dmesg_for_errors || error "Error in dmesg detected"
5108 if [ "$PARALLEL" != "yes" ]; then
5109 ps auxww | grep -v grep | grep -q multiop &&
5110 error "multiop still running"
5121 # Wrapper around run_one to ensure:
5122 # - test runs in subshell
5123 # - output of test is saved to separate log file for error reporting
5124 # - test result is saved to data file
5127 local BEFORE=$(date +%s)
5129 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5130 local test_log=$LOGDIR/$name
5131 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5132 local zfs_debug_log=$LOGDIR/$zfs_log_name
5134 rm -rf $LOGDIR/ignore
5136 local SAVE_UMASK=$(umask)
5140 log_sub_test_begin test_${1}
5141 (run_one $1 "$2") 2>&1 | tee -i $test_log
5142 local RC=${PIPESTATUS[0]}
5144 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5145 echo "test_$1 returned $RC" | tee $LOGDIR/err
5147 duration=$(($(date +%s) - $BEFORE))
5148 pass "$1" "(${duration}s)"
5150 if [[ -f $LOGDIR/err ]]; then
5151 TEST_ERROR=$(cat $LOGDIR/err)
5152 elif [[ -f $LOGDIR/ignore ]]; then
5153 TEST_ERROR=$(cat $LOGDIR/ignore)
5154 elif [[ -f $LOGDIR/skip ]]; then
5155 TEST_ERROR=$(cat $LOGDIR/skip)
5157 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5159 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5163 if [ -f $LOGDIR/err ]; then
5164 log_zfs_info "$zfs_debug_log"
5165 $FAIL_ON_ERROR && exit $RC
5174 # Print information of skipped tests to result.yml
5177 log_sub_test_begin $1
5179 log_sub_test_end "SKIP" "0" "0" "$@"
5183 (cd $(dirname $1); echo $PWD/$(basename $1))
5188 export base=$(basetest $1)
5189 [ "$CHECK_GRANT" == "no" ] && return 0
5191 testname=GCHECK_ONLY_${base}
5192 [ ${!testname}x == x ] && return 0
5194 echo -n "checking grant......"
5196 local clients=$CLIENTS
5197 [ -z "$clients" ] && clients=$(hostname)
5199 # sync all the data and make sure no pending data on server
5200 do_nodes $clients sync
5203 client_grant=$(do_nodes $clients \
5204 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5205 awk '{ total += $1 } END { printf("%0.0f", total) }')
5208 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5209 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5210 awk '{ total += $1 } END { printf("%0.0f", total) }')
5212 # check whether client grant == server grant
5213 if [[ $client_grant -ne $server_grant ]]; then
5214 echo "failed: client:${client_grant} server: ${server_grant}."
5215 do_nodes $(comma_list $(osts_nodes)) \
5216 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5217 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5220 echo "pass: client:${client_grant} server: ${server_grant}"
5224 ########################
5230 ost=`echo $1 | awk -F_ '{print $3}'`
5231 if [ -z $ost ]; then
5232 ost=`echo $1 | sed 's/-osc.*//'`
5237 ostuuid_from_index()
5239 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5242 ostname_from_index() {
5243 local uuid=$(ostuuid_from_index $1)
5247 index_from_ostuuid()
5249 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5252 mdtuuid_from_index()
5254 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5258 # Return unique identifier for given hostname
5261 echo $host_name | md5sum | cut -d' ' -f1
5265 # Returns list of ip addresses for each interface
5267 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5272 # Cache address list to avoid mutiple execution of local_addr_list
5273 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5275 for i in $LOCAL_ADDR_LIST ; do
5276 [[ "$i" == "$addr" ]] && return 0
5283 local is_local="IS_LOCAL_$(host_id $host_name)"
5284 if [ -z "${!is_local-}" ] ; then
5286 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5287 is_local_addr "$host_ip" && eval $is_local=1
5289 [[ "${!is_local}" == "1" ]]
5294 local_node $node && return 1
5301 for node in $(mdts_nodes); do
5302 remote_node $node && return 0
5309 [ -n "$CLIENTONLY" ] && return 0 || true
5310 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5315 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5316 MSKIPPED=1 && return 1
5323 for node in $(osts_nodes) ; do
5324 remote_node $node && return 0
5331 [ -n "$CLIENTONLY" ] && return 0 || true
5332 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5337 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5338 OSKIPPED=1 && return 1
5344 [ -n "$CLIENTONLY" ] && return 0 || true
5346 MGS=$(facet_host mgs)
5347 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5352 remote_mds_nodsh || remote_ost_nodsh || \
5353 $(single_local_node $(comma_list $(nodes_list)))
5357 remote_ost && remote_mds
5360 # Get the active nodes for facets.
5368 for facet in ${facets//,/ }; do
5369 nodes="$nodes $(facet_active_host $facet)"
5372 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5376 # Get all of the active MDS nodes.
5378 echo -n $(facets_nodes $(get_facets MDS))
5381 # Get all of the active OSS nodes.
5383 echo -n $(facets_nodes $(get_facets OST))
5386 # Get all of the active AGT (HSM agent) nodes.
5388 echo -n $(facets_nodes $(get_facets AGT))
5391 # Get all of the client nodes and active server nodes.
5393 local nodes=$HOSTNAME
5397 # CLIENTS (if specified) contains the local client
5398 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5400 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5401 nodes="$nodes $(facets_nodes $(get_facets))"
5404 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5408 # Get all of the remote client nodes and remote active server nodes.
5409 remote_nodes_list () {
5410 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5413 # Get all of the MDS nodes, including active and passive nodes.
5421 for i in $(seq $MDSCOUNT); do
5423 failover_host=mds${i}failover_HOST
5424 nodes="$nodes ${!host} ${!failover_host}"
5427 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5431 # Get all of the OSS nodes, including active and passive nodes.
5439 for i in $(seq $OSTCOUNT); do
5441 failover_host=ost${i}failover_HOST
5442 nodes="$nodes ${!host} ${!failover_host}"
5445 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5449 # Get all of the server nodes, including active and passive nodes.
5450 all_server_nodes () {
5455 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5457 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5461 # Get all of the client and server nodes, including active and passive nodes.
5463 local nodes=$HOSTNAME
5467 # CLIENTS (if specified) contains the local client
5468 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5470 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5471 nodes="$nodes $(all_server_nodes)"
5474 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5478 init_clients_lists () {
5479 # Sanity check: exclude the local client from RCLIENTS
5480 local clients=$(hostlist_expand "$RCLIENTS")
5481 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5483 # Sanity check: exclude the dup entries
5484 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5486 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5488 # Sanity check: exclude the dup entries from CLIENTS
5489 # for those configs which has SINGLCLIENT set to local client
5490 clients=$(for i in $clients; do echo $i; done | sort -u)
5492 CLIENTS=$(comma_list $clients)
5493 local -a remoteclients=($RCLIENTS)
5494 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5495 varname=CLIENT$((i + 2))
5496 eval $varname=${remoteclients[i]}
5499 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5502 get_random_entry () {
5505 rnodes=${rnodes//,/ }
5507 local -a nodes=($rnodes)
5508 local num=${#nodes[@]}
5509 local i=$((RANDOM * num * 2 / 65536))
5515 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5519 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5520 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5525 echo $nodes | wc -w || true
5529 local nodes=$(osts_nodes)
5530 local osscount=$(get_node_count "$nodes")
5531 [ ! "$OSTCOUNT" = "$osscount" ]
5535 local nodes=$(mdts_nodes)
5536 local mdtcount=$(get_node_count "$nodes")
5537 [ ! "$MDSCOUNT" = "$mdtcount" ]
5540 generate_machine_file() {
5541 local nodes=${1//,/ }
5542 local machinefile=$2
5544 for node in $nodes; do
5545 echo $node >>$machinefile || \
5546 { echo "can not generate machinefile $machinefile" && return 1; }
5551 local file=$1/stripe
5554 $LFS getstripe -v $file || error "getstripe $file failed"
5558 setstripe_nfsserver () {
5561 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5562 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5564 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5566 do_nodev $nfsserver lfs setstripe "$@"
5569 # Check and add a test group.
5575 local gid=$(getent group $group_name | cut -d: -f3)
5576 if [[ -n "$gid" ]]; then
5577 [[ "$gid" -eq "$group_id" ]] || {
5578 error_noexit "inconsistent group ID:" \
5579 "new: $group_id, old: $gid"
5583 groupadd -g $group_id $group_name
5590 # Check and add a test user.
5603 local uid=$(getent passwd $user_name | cut -d: -f3)
5604 if [[ -n "$uid" ]]; then
5605 if [[ "$uid" -eq "$user_id" ]]; then
5606 local dir=$(getent passwd $user_name | cut -d: -f6)
5607 if [[ "$dir" != "$home" ]]; then
5609 usermod -d $home $user_name
5613 error_noexit "inconsistent user ID:" \
5614 "new: $user_id, old: $uid"
5619 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5626 check_runas_id_ret() {
5628 local myRUNAS_UID=$1
5629 local myRUNAS_GID=$2
5632 if [ -z "$myRUNAS" ]; then
5633 error_exit "myRUNAS command must be specified for check_runas_id"
5636 $myRUNAS krb5_login.sh || \
5637 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5639 mkdir $DIR/d0_runas_test
5641 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5642 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5643 rm -rf $DIR/d0_runas_test
5648 local myRUNAS_UID=$1
5649 local myRUNAS_GID=$2
5652 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5653 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5654 Please set RUNAS_ID to some UID which exists on MDS and client or
5655 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5658 # obtain the UID/GID for MPI_USER
5662 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5663 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5665 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5666 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5669 # obtain and cache Kerberos ticket-granting ticket
5670 refresh_krb5_tgt() {
5671 local myRUNAS_UID=$1
5672 local myRUNAS_GID=$2
5675 if [ -z "$myRUNAS" ]; then
5676 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5679 CLIENTS=${CLIENTS:-$HOSTNAME}
5680 do_nodes $CLIENTS "set -x
5681 if ! $myRUNAS krb5_login.sh; then
5682 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5687 # Run multiop in the background, but wait for it to print
5688 # "PAUSING" to its stdout before returning from this function.
5689 multiop_bg_pause() {
5690 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5694 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5697 echo "$MULTIOP_PROG $FILE v$ARGS"
5698 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5700 echo "TMPPIPE=${TMPPIPE}"
5701 read -t 60 multiop_output < $TMPPIPE
5702 if [ $? -ne 0 ]; then
5707 if [ "$multiop_output" != "PAUSING" ]; then
5708 echo "Incorrect multiop output: $multiop_output"
5723 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5729 inodes_available () {
5730 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5731 sort -un | head -n1) || return 1
5735 mdsrate_inodes_available () {
5736 local min_inodes=$(inodes_available)
5737 echo $((min_inodes * 99 / 100))
5740 # reset llite stat counters
5741 clear_llite_stats(){
5742 lctl set_param -n llite.*.stats 0
5745 # sum llite stat items
5746 calc_llite_stats() {
5747 local res=$(lctl get_param -n llite.*.stats |
5748 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5752 # reset osc stat counters
5754 lctl set_param -n osc.*.osc_stats 0
5757 # sum osc stat items
5759 local res=$(lctl get_param -n osc.*.osc_stats |
5760 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5765 awk '{sum += $1} END { printf("%0.0f", sum) }'
5768 calc_osc_kbytes () {
5769 df $MOUNT > /dev/null
5770 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5773 # save_lustre_params(comma separated facet list, parameter_mask)
5774 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5775 save_lustre_params() {
5781 for facet in ${facets//,/ }; do
5782 node=$(facet_active_host $facet)
5783 [[ *\ $node\ * = " $nodes " ]] && continue
5784 nodes="$nodes $node"
5786 do_node $node "$LCTL get_param $2 |
5787 while read s; do echo $facet \\\$s; done"
5791 # restore lustre parameters from input stream, produces by save_lustre_params
5792 restore_lustre_params() {
5797 while IFS=" =" read facet name val; do
5798 do_facet $facet "$LCTL set_param -n $name $val"
5802 check_node_health() {
5803 local nodes=${1:-$(comma_list $(nodes_list))}
5805 for node in ${nodes//,/ }; do
5806 check_network "$node" 5
5807 if [ $? -eq 0 ]; then
5808 do_node $node "rc=0;
5809 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5810 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5811 echo \\\$(hostname -s): \\\$val;
5814 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5819 mdsrate_cleanup () {
5821 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5822 --nfiles $3 --dir $4 --filefmt $5 $6
5827 delayed_recovery_enabled () {
5828 local var=${SINGLEMDS}_svc
5829 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5832 ########################
5834 convert_facet2label() {
5837 if [ x$facet = xost ]; then
5841 local varsvc=${facet}_svc
5843 if [ -n ${!varsvc} ]; then
5846 error "No lablel for $facet!"
5850 get_clientosc_proc_path() {
5854 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5855 # used by MDT would not be changed.
5856 # mdt lov: fsname-mdtlov
5857 # mdt osc: fsname-OSTXXXX-osc
5858 mds_on_old_device() {
5859 local mds=${1:-"$SINGLEMDS"}
5861 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5862 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5863 > /dev/null 2>&1" && return 0
5868 get_mdtosc_proc_path() {
5870 local ost_label=${2:-"*OST*"}
5872 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5873 local mdt_label=$(convert_facet2label $mds_facet)
5874 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5876 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5877 mds_on_old_device $mds_facet; then
5878 echo "${ost_label}-osc"
5879 elif [[ $ost_label = *OST* ]]; then
5880 echo "${ost_label}-osc-${mdt_index}"
5882 echo "${ost_label}-osp-${mdt_index}"
5886 get_osc_import_name() {
5889 local label=$(convert_facet2label $ost)
5891 if [ "${facet:0:3}" = "mds" ]; then
5892 get_mdtosc_proc_path $facet $label
5896 get_clientosc_proc_path $label
5900 _wait_import_state () {
5903 local maxtime=${3:-$(max_recovery_time)}
5904 local error_on_failure=${4:-1}
5908 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5909 while [ "${CONN_STATE}" != "${expected}" ]; do
5910 if [ "${expected}" == "DISCONN" ]; then
5911 # for disconn we can check after proc entry is removed
5912 [ "x${CONN_STATE}" == "x" ] && return 0
5913 # with AT enabled, we can have connect request timeout near of
5914 # reconnect timeout and test can't see real disconnect
5915 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5917 if [ $i -ge $maxtime ]; then
5918 [ $error_on_failure -ne 0 ] && \
5919 error "can't put import for $CONN_PROC into ${expected}" \
5920 "state after $i sec, have ${CONN_STATE}"
5924 # Add uniq for multi-mount case
5925 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5929 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5933 wait_import_state() {
5936 local maxtime=${3:-$(max_recovery_time)}
5937 local error_on_failure=${4:-1}
5940 for param in ${params//,/ }; do
5941 _wait_import_state $state $param $maxtime $error_on_failure || return
5945 wait_import_state_mount() {
5946 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5950 wait_import_state $*
5953 # One client request could be timed out because server was not ready
5954 # when request was sent by client.
5955 # The request timeout calculation details :
5957 # /* We give the server rq_timeout secs to process the req, and
5958 # add the network latency for our local timeout. */
5959 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5960 # ptlrpc_at_get_net_latency(request) ;
5962 # ptlrpc_connect_import ()
5963 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5966 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5967 # ptlrpc_at_get_net_latency(request) ->
5968 # at_get (max (iat_net_latency=0, at_min)) = at_min
5971 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5972 # INITIAL_CONNECT_TIMEOUT + at_min
5974 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5975 # because we can not get this value in runtime,
5976 # the value depends on configure options, and it is not stored in /proc.
5978 # #define CONNECTION_SWITCH_MIN 5U
5979 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5981 request_timeout () {
5984 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5985 local init_connect_timeout=$TIMEOUT
5986 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5988 local at_min=$(at_get $facet at_min)
5990 echo $(( init_connect_timeout + at_min ))
5993 _wait_osc_import_state() {
5997 local target=$(get_osc_import_name $facet $ost_facet)
5998 local param="osc.${target}.ost_server_uuid"
6002 # 1. wait the deadline of client 1st request (it could be skipped)
6003 # 2. wait the deadline of client 2nd request
6004 local maxtime=$(( 2 * $(request_timeout $facet)))
6006 if [[ $facet == client* ]]; then
6007 # During setup time, the osc might not be setup, it need wait
6008 # until list_param can return valid value. And also if there
6009 # are mulitple osc entries we should list all of them before
6011 params=$($LCTL list_param $param 2>/dev/null || true)
6012 while [ -z "$params" ]; do
6013 if [ $i -ge $maxtime ]; then
6014 echo "can't get $param in $maxtime secs"
6019 params=$($LCTL list_param $param 2>/dev/null || true)
6023 if [[ $ost_facet = mds* ]]; then
6024 # no OSP connection to itself
6025 if [[ $facet = $ost_facet ]]; then
6028 param="osp.${target}.mdt_server_uuid"
6032 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6033 wait_import_state $expected "$params" $maxtime; then
6034 error "import is not in ${expected} state"
6041 wait_osc_import_state() {
6047 if [[ $facet = mds ]]; then
6048 for num in $(seq $MDSCOUNT); do
6049 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6052 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6056 _wait_mgc_import_state() {
6059 local error_on_failure=${3:-1}
6060 local param="mgc.*.mgs_server_uuid"
6064 # 1. wait the deadline of client 1st request (it could be skipped)
6065 # 2. wait the deadline of client 2nd request
6066 local maxtime=$(( 2 * $(request_timeout $facet)))
6068 if [[ $facet == client* ]]; then
6069 # During setup time, the osc might not be setup, it need wait
6070 # until list_param can return valid value. And also if there
6071 # are mulitple osc entries we should list all of them before
6073 params=$($LCTL list_param $param 2>/dev/null || true)
6074 while [ -z "$params" ]; do
6075 if [ $i -ge $maxtime ]; then
6076 echo "can't get $param in $maxtime secs"
6081 params=$($LCTL list_param $param 2>/dev/null || true)
6084 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6085 wait_import_state $expected "$params" $maxtime \
6086 $error_on_failure; then
6087 if [ $error_on_failure -ne 0 ]; then
6088 error "import is not in ${expected} state"
6096 wait_mgc_import_state() {
6099 local error_on_failure=${3:-1}
6102 if [[ $facet = mds ]]; then
6103 for num in $(seq $MDSCOUNT); do
6104 _wait_mgc_import_state mds$num "$expected" \
6105 $error_on_failure || return
6108 _wait_mgc_import_state "$facet" "$expected"
6109 $error_on_failure || return
6113 wait_dne_interconnect() {
6116 if [ $MDSCOUNT -gt 1 ]; then
6117 for num in $(seq $MDSCOUNT); do
6118 wait_osc_import_state mds mds$num FULL
6123 get_clientmdc_proc_path() {
6127 get_clientmgc_proc_path() {
6135 [ -z "$list" ] && return 0
6137 # Add paths to lustre tests for 32 and 64 bit systems.
6138 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6139 local TESTPATH="$RLUSTRE/tests:"
6140 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6141 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6144 wait_clients_import_state () {
6151 if [ "$FAILURE_MODE" = HARD ]; then
6152 facets=$(facets_on_host $(facet_active_host $facet))
6155 for facet in ${facets//,/ }; do
6156 local label=$(convert_facet2label $facet)
6159 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6160 $label).ost_server_uuid" ;;
6161 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6162 $label).mds_server_uuid" ;;
6163 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6164 $label).mgs_server_uuid" ;;
6165 *) error "unknown facet!" ;;
6168 local params=$(expand_list $params $proc_path)
6171 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6173 error "import is not in ${expected} state"
6183 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6184 $LCTL get_param obdfilter.*.kbytesavail))
6185 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6186 $LCTL get_param -n obdfilter.*.tot_granted))
6187 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6188 $LCTL get_param -n obdfilter.*.kbytestotal))
6189 for ((i=0; i<${#AVAILA[@]}; i++)); do
6190 local -a AVAIL1=(${AVAILA[$i]//=/ })
6191 local -a TOTAL=(${TOTALA[$i]//=/ })
6192 GRANT=$((${GRANTA[$i]}/1024))
6193 # allow 1% of total space in bavail because of delayed
6194 # allocation with ZFS which might release some free space after
6195 # txg commit. For small devices, we set a mininum of 8MB
6196 local LIMIT=$((${TOTAL} / 100 + 8000))
6197 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6198 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6199 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6200 echo " FULL" || echo
6206 do_facet mgs lctl pool_list $1
6210 local fsname=${1%%.*}
6211 local poolname=${1##$fsname.}
6213 do_facet mgs lctl pool_new $1
6215 # get param should return err unless pool is created
6216 [[ $RC -ne 0 ]] && return $RC
6218 for mds_id in $(seq $MDSCOUNT); do
6219 local mdt_id=$((mds_id-1))
6220 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6221 wait_update_facet mds$mds_id \
6222 "lctl get_param -n lod.$lodname.pools.$poolname \
6223 2>/dev/null || echo foo" "" ||
6224 error "mds$mds_id: pool_new failed $1"
6226 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6227 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6233 add_pool_to_list () {
6234 local fsname=${1%%.*}
6235 local poolname=${1##$fsname.}
6237 local listvar=${fsname}_CREATED_POOLS
6238 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6242 remove_pool_from_list () {
6243 local fsname=${1%%.*}
6244 local poolname=${1##$fsname.}
6246 local listvar=${fsname}_CREATED_POOLS
6247 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6251 destroy_pool_int() {
6253 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6254 awk '$1 !~ /^Pool:/ {print $1}')
6255 for ost in $OSTS; do
6256 do_facet mgs lctl pool_remove $1 $ost
6258 do_facet mgs lctl pool_destroy $1
6261 # <fsname>.<poolname> or <poolname>
6263 local fsname=${1%%.*}
6264 local poolname=${1##$fsname.}
6266 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6270 pool_list $fsname.$poolname || return $?
6272 destroy_pool_int $fsname.$poolname
6274 [[ $RC -ne 0 ]] && return $RC
6275 for mds_id in $(seq $MDSCOUNT); do
6276 local mdt_id=$((mds_id-1))
6277 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6278 wait_update_facet mds$mds_id \
6279 "lctl get_param -n lod.$lodname.pools.$poolname \
6280 2>/dev/null || echo foo" "foo" ||
6281 error "mds$mds_id: destroy pool failed $1"
6283 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6284 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6286 remove_pool_from_list $fsname.$poolname
6291 local fsname=${1:-$FSNAME}
6293 local listvar=${fsname}_CREATED_POOLS
6297 [ x${!listvar} = x ] && return 0
6299 echo destroy the created pools: ${!listvar}
6300 for poolname in ${!listvar//,/ }; do
6301 destroy_pool $fsname.$poolname
6306 local fsname=${1:-$FSNAME}
6308 destroy_pools $fsname
6314 local ts=$(date +%s)
6317 if [[ ! -f "$YAML_LOG" ]]; then
6318 # init_logging is not performed before gather_logs,
6319 # so the $LOGDIR needs to be checked here
6320 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6323 [ -f $LOGDIR/shared ] && docp=false
6325 # dump lustre logs, dmesg
6327 prefix="$TESTLOG_PREFIX.$TESTNAME"
6329 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6331 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6332 echo "Dumping logs only on local client."
6333 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6334 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6339 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6340 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6341 if [ ! -f $LOGDIR/shared ]; then
6342 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6355 for i in $(seq 0 $num_mntpts); do
6356 cmd="ls -laf ${mntpt_root}$i/$dir"
6362 for pid in $pids; do
6369 # check_and_start_recovery_timer()
6370 # service_time = at_est2timeout(service_time);
6371 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6372 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6374 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6375 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6376 #define CONNECTION_SWITCH_MIN 5
6377 #define CONNECTION_SWITCH_INC 5
6378 max_recovery_time() {
6379 local init_connect_timeout=$((TIMEOUT / 20))
6380 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6382 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6383 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6385 echo -n $service_time
6388 recovery_time_min() {
6389 local connection_switch_min=5
6390 local connection_switch_inc=5
6391 local connection_switch_max
6392 local reconnect_delay_max
6393 local initial_connect_timeout
6397 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6398 (($connection_switch_min > $TIMEOUT)) &&
6399 max=$connection_switch_min || max=$TIMEOUT
6400 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6402 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6403 timeout_20=$((TIMEOUT/20))
6404 (($connection_switch_min > $timeout_20)) &&
6405 initial_connect_timeout=$connection_switch_min ||
6406 initial_connect_timeout=$timeout_20
6408 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6409 initial_connect_timeout))
6410 echo $((2 * reconnect_delay_max))
6413 get_clients_mount_count () {
6414 local clients=${CLIENTS:-`hostname`}
6416 # we need to take into account the clients mounts and
6417 # exclude mds/ost mounts if any;
6418 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6422 PROC_CLI="srpc_info"
6430 if [ $M -lt $N ]; then
6434 while [ $N -lt $M ]; do
6444 calc_connection_cnt() {
6447 # MDT->MDT = 2 * C(M, 2)
6451 comb_m2=$(combination $MDSCOUNT 2)
6453 local num_clients=$(get_clients_mount_count)
6455 local cnt_mdt2mdt=$((comb_m2 * 2))
6456 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6457 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6458 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6459 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6460 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6461 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6475 local cmd="$tgt.srpc.flavor"
6477 if [ $net == "any" ]; then
6482 if [ $dir != "any" ]; then
6487 log "Setting sptlrpc rule: $cmd"
6488 do_facet mgs "$LCTL conf_param $cmd"
6497 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6498 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6500 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6502 if [ "x$bulkspec" != "x" ]; then
6503 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6505 if [ "x$algs" != "x" ]; then
6506 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6508 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6509 if [ $bulk == "bulkn" ]; then
6510 bulk_count=`echo "$output" | grep "bulk flavor" \
6511 | grep "null/null" | wc -l`
6512 elif [ $bulk == "bulki" ]; then
6513 bulk_count=`echo "$output" | grep "bulk flavor" \
6514 | grep "/null" | grep -v "null/" | wc -l`
6516 bulk_count=`echo "$output" | grep "bulk flavor" \
6517 | grep -v "/null" | grep -v "null/" | wc -l`
6521 [ $bulk_count -lt $count ] && count=$bulk_count
6532 local clients=${CLIENTS:-`hostname`}
6534 for c in ${clients//,/ }; do
6535 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6536 tmpcnt=`count_flvr "$output" $flavor`
6537 cnt=$((cnt + tmpcnt))
6547 local clients=${CLIENTS:-`hostname`}
6549 for c in ${clients//,/ }; do
6550 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6551 tmpcnt=`count_flvr "$output" $flavor`
6552 cnt=$((cnt + tmpcnt))
6562 if [ $MDSCOUNT -le 1 ]; then
6567 for num in `seq $MDSCOUNT`; do
6568 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6569 tmpcnt=`count_flvr "$output" $flavor`
6570 cnt=$((cnt + tmpcnt))
6581 for num in `seq $MDSCOUNT`; do
6582 mdtosc=$(get_mdtosc_proc_path mds$num)
6583 mdtosc=${mdtosc/-MDT*/-MDT\*}
6584 output=$(do_facet mds$num lctl get_param -n \
6585 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6586 tmpcnt=`count_flvr "$output" $flavor`
6587 cnt=$((cnt + tmpcnt))
6596 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6597 count_flvr "$output" $flavor
6602 local dir=$1 # from to
6603 local flavor=$2 # flavor expected
6606 if [ $dir == "cli2mdt" ]; then
6607 res=`flvr_cnt_cli2mdt $flavor`
6608 elif [ $dir == "cli2ost" ]; then
6609 res=`flvr_cnt_cli2ost $flavor`
6610 elif [ $dir == "mdt2mdt" ]; then
6611 res=`flvr_cnt_mdt2mdt $flavor`
6612 elif [ $dir == "mdt2ost" ]; then
6613 res=`flvr_cnt_mdt2ost $flavor`
6614 elif [ $dir == "all2ost" ]; then
6615 res1=`flvr_cnt_mdt2ost $flavor`
6616 res2=`flvr_cnt_cli2ost $flavor`
6617 res=$((res1 + res2))
6618 elif [ $dir == "all2mdt" ]; then
6619 res1=`flvr_cnt_mdt2mdt $flavor`
6620 res2=`flvr_cnt_cli2mdt $flavor`
6621 res=$((res1 + res2))
6622 elif [ $dir == "all2all" ]; then
6623 res1=`flvr_cnt_mdt2ost $flavor`
6624 res2=`flvr_cnt_cli2ost $flavor`
6625 res3=`flvr_cnt_mdt2mdt $flavor`
6626 res4=`flvr_cnt_cli2mdt $flavor`
6627 res=$((res1 + res2 + res3 + res4))
6635 local dir=$1 # from to
6636 local flavor=$2 # flavor expected
6637 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6641 for ((i=0;i<20;i++)); do
6642 echo -n "checking $dir..."
6643 res=$(do_check_flavor $dir $flavor)
6644 echo "found $res/$expect $flavor connections"
6645 [ $res -ge $expect ] && return 0
6649 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6653 restore_to_default_flavor()
6655 local proc="mgs.MGS.live.$FSNAME"
6657 echo "restoring to default flavor..."
6659 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6661 # remove all existing rules if any
6662 if [ $nrule -ne 0 ]; then
6663 echo "$nrule existing rules"
6664 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6665 echo "remove rule: $rule"
6666 spec=`echo $rule | awk -F = '{print $1}'`
6667 do_facet mgs "$LCTL conf_param -d $spec"
6671 # verify no rules left
6672 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6673 [ $nrule -ne 0 ] && error "still $nrule rules left"
6675 # wait for default flavor to be applied
6676 # currently default flavor for all connections are 'null'
6677 wait_flavor all2all null
6678 echo "now at default flavor settings"
6683 local flavor=${1:-null}
6685 echo "setting all flavor to $flavor"
6687 # FIXME need parameter to this fn
6688 # and remove global vars
6689 local cnt_all2all=$(calc_connection_cnt all2all)
6691 local res=$(do_check_flavor all2all $flavor)
6692 if [ $res -eq $cnt_all2all ]; then
6693 echo "already have total $res $flavor connections"
6697 echo "found $res $flavor out of total $cnt_all2all connections"
6698 restore_to_default_flavor
6700 [[ $flavor = null ]] && return 0
6702 set_rule $FSNAME any any $flavor
6703 wait_flavor all2all $flavor
6709 # Checking for shared logdir
6710 if [ ! -d $dir ]; then
6711 # Not found. Create local logdir
6714 touch $dir/check_file.$(hostname -s)
6719 check_write_access() {
6721 local list=${2:-$(comma_list $(nodes_list))}
6725 for node in ${list//,/ }; do
6726 file=$dir/check_file.$(short_nodename $node)
6727 if [[ ! -f "$file" ]]; then
6728 # Logdir not accessible/writable from this node.
6731 rm -f $file || return 1
6737 [[ -n $YAML_LOG ]] && return
6738 local save_umask=$(umask)
6741 export YAML_LOG=${LOGDIR}/results.yml
6745 # If the yaml log already exists then we will just append to it
6746 if [ ! -f $YAML_LOG ]; then
6747 if check_shared_dir $LOGDIR; then
6748 touch $LOGDIR/shared
6749 echo "Logging to shared log directory: $LOGDIR"
6751 echo "Logging to local directory: $LOGDIR"
6754 yml_nodes_file $LOGDIR >> $YAML_LOG
6755 yml_results_file >> $YAML_LOG
6760 # If modules are not yet loaded then older "lctl lustre_build_version"
6761 # will fail. Use lctl build version instead.
6762 log "Client: $($LCTL lustre_build_version)"
6763 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6764 do_facet $SINGLEMDS $LCTL --version)"
6765 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6766 do_facet ost1 $LCTL --version)"
6770 yml_log_test $1 >> $YAML_LOG
6774 yml_log_test_status $@ >> $YAML_LOG
6777 log_sub_test_begin() {
6778 yml_log_sub_test_begin "$@" >> $YAML_LOG
6781 log_sub_test_end() {
6782 yml_log_sub_test_end "$@" >> $YAML_LOG
6788 local llverdev_opts=$2
6789 local devname=$(basename $1)
6790 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6791 # loop devices aren't in /proc/partitions
6792 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6794 size=$(($size / 1024 / 1024)) # Gb
6796 local partial_arg=""
6797 # Run in partial (fast) mode if the size
6798 # of a partition > 1 GB
6799 [ $size -gt 1 ] && partial_arg="-p"
6801 llverdev --force $partial_arg $llverdev_opts $dev
6807 local llverfs_opts=$2
6808 local use_partial_arg=$3
6809 local partial_arg=""
6810 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6812 # Run in partial (fast) mode if the size
6813 # of a partition > 1 GB
6814 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6816 llverfs $partial_arg $llverfs_opts $dir
6819 #Remove objects from OST
6820 remove_ost_objects() {
6826 local mntpt=$(facet_mntpt $facet)
6827 local opts=$OST_MOUNT_OPTS
6831 echo "removing objects from $ostdev on $facet: $objids"
6832 if ! test -b $ostdev; then
6833 opts=$(csa_add "$opts" -o loop)
6835 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6838 for i in $objids; do
6839 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6841 umount -f $mntpt || return $?
6845 #Remove files from MDT
6846 remove_mdt_files() {
6851 local mntpt=$(facet_mntpt $facet)
6852 local opts=$MDS_MOUNT_OPTS
6854 echo "removing files from $mdtdev on $facet: $files"
6855 if [ $(facet_fstype $facet) == ldiskfs ] &&
6856 ! do_facet $facet test -b $mdtdev; then
6857 opts=$(csa_add "$opts" -o loop)
6859 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6863 rm $mntpt/ROOT/$f || { rc=$?; break; }
6865 umount -f $mntpt || return $?
6869 duplicate_mdt_files() {
6874 local mntpt=$(facet_mntpt $facet)
6875 local opts=$MDS_MOUNT_OPTS
6877 echo "duplicating files on $mdtdev on $facet: $files"
6878 mkdir -p $mntpt || return $?
6879 if [ $(facet_fstype $facet) == ldiskfs ] &&
6880 ! do_facet $facet test -b $mdtdev; then
6881 opts=$(csa_add "$opts" -o loop)
6883 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6894 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6895 pushd $mntpt/ROOT > /dev/null || return $?
6898 touch $f.bad || return $?
6899 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6901 [ $rc -eq 0 ] || return $rc
6902 setfattr --restore $tmp || return $?
6908 local devs=${1//,/ }
6911 local rslt=$TMP/sgpdd_survey
6913 # sgpdd-survey cleanups ${rslt}.* files
6915 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6921 # returns the canonical name for an ldiskfs device
6926 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6927 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6928 echo dm-\\\${foo##*:};
6930 echo \\\$(basename \\\$dv);
6934 is_sanity_benchmark() {
6935 local benchmarks="dbench bonnie iozone fsx"
6937 for b in $benchmarks; do
6938 if [ "$b" == "$suite" ]; then
6946 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6950 # Get the available size (KB) of a given obd target.
6957 [[ $facet != client ]] || return 0
6959 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6964 # Get the page size (bytes) on a given facet node.
6968 local size=$(getconf PAGE_SIZE 2>/dev/null)
6970 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
6971 echo -n ${size:-4096}
6975 # Get the block count of the filesystem.
6982 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6983 awk '/^Block count:/ {print $3}')
6987 # Get the block size of the filesystem.
6993 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6994 awk '/^Block size:/ {print $3}')
6998 # Check whether the "large_xattr" feature is enabled or not.
6999 large_xattr_enabled() {
7000 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7002 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7004 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7005 grep -E -q '(ea_inode|large_xattr)'"
7006 return ${PIPESTATUS[0]}
7009 # Get the maximum xattr size supported by the filesystem.
7013 if large_xattr_enabled; then
7014 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7017 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7018 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7020 # maximum xattr size = size of block - size of header -
7021 # size of 1 entry - 4 null bytes
7022 size=$((block_size - 32 - 32 - 4))
7028 # Dump the value of the named xattr from a file.
7033 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7036 # Generate a string with size of $size bytes.
7038 local size=${1:-1024} # in bytes
7040 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7043 reformat_external_journal() {
7048 if [ -n "${!var}" ]; then
7049 local rcmd="do_facet $facet"
7051 echo "reformat external journal on $facet:${!var}"
7052 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7056 # MDT file-level backup/restore
7057 mds_backup_restore() {
7060 local devname=$(mdsdevname $(facet_number $facet))
7061 local mntpt=$(facet_mntpt brpt)
7062 local rcmd="do_facet $facet"
7063 local metaea=${TMP}/backup_restore.ea
7064 local metadata=${TMP}/backup_restore.tgz
7065 local opts=${MDS_MOUNT_OPTS}
7066 local svc=${facet}_svc
7068 if ! ${rcmd} test -b ${devname}; then
7069 opts=$(csa_add "$opts" -o loop)
7072 echo "file-level backup/restore on $facet:${devname}"
7074 # step 1: build mount point
7075 ${rcmd} mkdir -p $mntpt
7076 # step 2: cleanup old backup
7077 ${rcmd} rm -f $metaea $metadata
7079 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7080 if [ ! -z $igif ]; then
7081 # step 3.5: rm .lustre
7082 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7084 # step 4: backup metaea
7086 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7088 # step 5: backup metadata
7090 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7092 ${rcmd} $UMOUNT $mntpt || return 4
7093 # step 8: reformat dev
7094 echo "reformat new device"
7095 format_mdt $(facet_number $facet)
7097 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7098 # step 10: restore metadata
7100 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7101 # step 11: restore metaea
7103 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7104 # step 12: remove recovery logs
7105 echo "remove recovery logs"
7106 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7107 # step 13: umount dev
7108 ${rcmd} $UMOUNT $mntpt || return 10
7109 # step 14: cleanup tmp backup
7110 ${rcmd} rm -f $metaea $metadata
7111 # step 15: reset device label - it's not virgin on
7112 ${rcmd} e2label $devname ${!svc}
7119 local devname=$(mdsdevname $(facet_number $facet))
7120 local mntpt=$(facet_mntpt brpt)
7121 local rcmd="do_facet $facet"
7122 local opts=${MDS_MOUNT_OPTS}
7124 if ! ${rcmd} test -b ${devname}; then
7125 opts=$(csa_add "$opts" -o loop)
7128 echo "removing OI files on $facet: idx=${idx}"
7130 # step 1: build mount point
7131 ${rcmd} mkdir -p $mntpt
7133 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7134 if [ -z $idx ]; then
7135 # step 3: remove all OI files
7136 ${rcmd} rm -fv $mntpt/oi.16*
7137 elif [ $idx -lt 2 ]; then
7138 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7142 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7143 for ((i=${idx}; i<64; i=$((i * idx)))); do
7144 ${rcmd} rm -fv $mntpt/oi.16.${i}
7148 ${rcmd} $UMOUNT $mntpt || return 2
7149 # OI files will be recreated when mounted as lustre next time.
7152 # generate maloo upload-able log file name
7153 # \param logname specify unique part of file name
7154 generate_logname() {
7155 local logname=${1:-"default_logname"}
7157 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7160 # make directory on different MDTs
7164 local stripe_count=2
7165 local stripe_index=-1
7168 while getopts "c:i:p" opt; do
7170 c) stripe_count=$OPTARG;;
7171 i) stripe_index=$OPTARG;;
7173 \?) error "only support -i -c -p";;
7177 shift $((OPTIND - 1))
7178 [ $# -eq 1 ] || error "Only creating single directory is supported"
7181 if [ "$p_option" == "-p" ]; then
7182 local parent=$(dirname $path)
7184 [ -d $path ] && return 0
7185 [ ! -d ${parent} ] && mkdir -p ${parent}
7188 if [ $MDSCOUNT -le 1 ]; then
7191 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7194 if [ $stripe_index -eq -1 ]; then
7195 mdt_index=$((test_num % MDSCOUNT))
7197 mdt_index=$stripe_index
7199 echo "striped dir -i$mdt_index -c$stripe_count $path"
7200 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7204 # find the smallest and not in use file descriptor
7207 local max_fd=$(ulimit -n)
7209 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7212 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7216 check_mount_and_prep()
7218 is_mounted $MOUNT || setupall
7220 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7221 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7222 for idx in $(seq $MDSCOUNT); do
7223 local name="MDT$(printf '%04x' $((idx - 1)))"
7224 rm -rf $MOUNT/.lustre/lost+found/$name/*
7228 # calcule how many ost-objects to be created.
7229 precreated_ost_obj_count()
7233 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7234 local ost_name="OST$(printf '%04x' $ost_idx)"
7235 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7236 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7237 osp.$proc_path.prealloc_last_id)
7238 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7239 osp.$proc_path.prealloc_next_id)
7240 echo $((last_id - next_id + 1))
7243 check_file_in_pool()
7248 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7251 for t in $tlist ; do
7252 [ "$i" -eq "$t" ] && continue 2
7255 echo "pool list: $tlist"
7256 echo "striping: $res"
7257 error_noexit "$file not allocated in $pool"
7264 echo "Creating new pool"
7267 create_pool $FSNAME.$pool ||
7268 { error_noexit "No pool created, result code $?"; return 1; }
7269 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7270 { error_noexit "$pool not in lfs pool_list"; return 2; }
7273 pool_add_targets() {
7274 echo "Adding targets to pool"
7280 local list=$(seq $first $step $last)
7282 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7283 do_facet mgs $LCTL pool_add \
7284 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7286 # wait for OSTs to be added to the pool
7287 for mds_id in $(seq $MDSCOUNT); do
7288 local mdt_id=$((mds_id-1))
7289 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7290 wait_update_facet mds$mds_id \
7291 "lctl get_param -n lod.$lodname.pools.$pool |
7292 sort -u | tr '\n' ' ' " "$t" || {
7293 error_noexit "mds$mds_id: Add to pool failed"
7297 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7298 | sort -u | tr '\n' ' ' " "$t" || {
7299 error_noexit "Add to pool failed"
7302 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7303 local addcount=$(((last - first) / step + 1))
7304 [ $lfscount -eq $addcount ] || {
7305 error_noexit "lfs pool_list bad ost count" \
7306 "$lfscount != $addcount"
7314 echo "Setting pool on directory $tdir"
7316 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7318 error_noexit "Cannot set pool $pool to $tdir"
7325 echo "Checking pool on directory $tdir"
7327 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7328 [ "$res" = "$pool" ] && return 0
7330 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7334 pool_dir_rel_path() {
7335 echo "Testing relative path works well"
7340 mkdir -p $root/$tdir/$tdir
7342 pool_set_dir $pool $tdir || return 1
7343 pool_set_dir $pool ./$tdir || return 2
7344 pool_set_dir $pool ../$tdir || return 3
7345 pool_set_dir $pool ../$tdir/$tdir || return 4
7346 rm -rf $tdir; cd - > /dev/null
7349 pool_alloc_files() {
7350 echo "Checking files allocation from directory pool"
7357 for i in $(seq -w 1 $count)
7359 local file=$tdir/file-$i
7361 check_file_in_pool $file $pool "$tlist" || \
7362 failed=$((failed + 1))
7364 [ "$failed" = 0 ] && return 0
7366 error_noexit "$failed files not allocated in $pool"
7370 pool_create_files() {
7371 echo "Creating files in pool"
7379 for i in $(seq -w 1 $count)
7381 local file=$tdir/spoo-$i
7382 $SETSTRIPE -p $pool $file
7383 check_file_in_pool $file $pool "$tlist" || \
7384 failed=$((failed + 1))
7386 [ "$failed" = 0 ] && return 0
7388 error_noexit "$failed files not allocated in $pool"
7393 echo "Checking 'lfs df' output"
7396 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7398 local res=$($LFS df --pool $FSNAME.$pool |
7400 grep "$FSNAME-OST" |
7402 [ "$res" = "$t" ] && return 0
7404 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7408 pool_file_rel_path() {
7409 echo "Creating files in a pool with relative pathname"
7414 { error_noexit "unable to create $tdir"; return 1 ; }
7415 local file="/..$tdir/$tfile-1"
7416 $SETSTRIPE -p $pool $file ||
7417 { error_noexit "unable to create $file" ; return 2 ; }
7420 $SETSTRIPE -p $pool $tfile-2 || {
7421 error_noexit "unable to create $tfile-2 in $tdir"
7426 pool_remove_first_target() {
7427 echo "Removing first target from a pool"
7430 local pname="lov.$FSNAME-*.pools.$pool"
7431 local t=$($LCTL get_param -n $pname | head -1)
7432 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7433 for mds_id in $(seq $MDSCOUNT); do
7434 local mdt_id=$((mds_id-1))
7435 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7436 wait_update_facet mds$mds_id \
7437 "lctl get_param -n lod.$lodname.pools.$pool |
7439 error_noexit "mds$mds_id: $t not removed from" \
7444 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7445 error_noexit "$t not removed from $FSNAME.$pool"
7450 pool_remove_all_targets() {
7451 echo "Removing all targets from pool"
7454 local pname="lov.$FSNAME-*.pools.$pool"
7455 for t in $($LCTL get_param -n $pname | sort -u)
7457 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7459 for mds_id in $(seq $MDSCOUNT); do
7460 local mdt_id=$((mds_id-1))
7461 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7462 wait_update_facet mds$mds_id "lctl get_param -n \
7463 lod.$lodname.pools.$pool" "" || {
7464 error_noexit "mds$mds_id: Pool $pool not drained"
7468 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7469 error_noexit "Pool $FSNAME.$pool cannot be drained"
7472 # striping on an empty/nonexistant pool should fall back
7473 # to "pool of everything"
7475 error_noexit "failed to use fallback striping for empty pool"
7478 # setstripe on an empty pool should fail
7479 $SETSTRIPE -p $pool $file 2>/dev/null && {
7480 error_noexit "expected failure when creating file" \
7488 echo "Destroying pool"
7492 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7495 # striping on an empty/nonexistant pool should fall back
7496 # to "pool of everything"
7498 error_noexit "failed to use fallback striping for missing pool"
7501 # setstripe on an empty pool should fail
7502 $SETSTRIPE -p $pool $file 2>/dev/null && {
7503 error_noexit "expected failure when creating file" \
7508 # get param should return err once pool is gone
7509 if wait_update $HOSTNAME "lctl get_param -n \
7510 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7512 remove_pool_from_list $FSNAME.$pool
7515 error_noexit "Pool $FSNAME.$pool is not destroyed"
7519 # Get and check the actual stripe count of one file.
7520 # Usage: check_stripe_count <file> <expected_stripe_count>
7521 check_stripe_count() {
7526 [[ -z "$file" || -z "$expected" ]] &&
7527 error "check_stripe_count: invalid argument"
7529 local cmd="$GETSTRIPE -c $file"
7530 actual=$($cmd) || error "$cmd failed"
7531 actual=${actual%% *}
7533 if [[ $actual -ne $expected ]]; then
7534 [[ $expected -eq -1 ]] ||
7535 error "$cmd wrong: found $actual, expected $expected"
7536 [[ $actual -eq $OSTCOUNT ]] ||
7537 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7541 # Get and check the actual list of OST indices on one file.
7542 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7548 [[ -z "$file" || -z "$expected" ]] &&
7549 error "check_obdidx: invalid argument!"
7551 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7552 grep -v obdidx | awk '{print $1}' | xargs))
7554 [[ $obdidx = $expected ]] ||
7555 error "list of OST indices on $file is $obdidx," \
7556 "should be $expected"
7559 # Get and check the actual OST index of the first stripe on one file.
7560 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7561 check_start_ost_idx() {
7566 [[ -z "$file" || -z "$expected" ]] &&
7567 error "check_start_ost_idx: invalid argument!"
7569 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7572 [[ $start_ost_idx = $expected ]] ||
7573 error "OST index of the first stripe on $file is" \
7574 "$start_ost_idx, should be $expected"
7577 killall_process () {
7578 local clients=${1:-$(hostname)}
7583 do_nodes $clients "killall $signal $name"