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'
2168 wait_delete_completed_mds() {
2169 local MAX_WAIT=${1:-20}
2170 # for ZFS, waiting more time for DMUs to be committed
2171 local ZFS_WAIT=${2:-5}
2173 local stime=$(date +%s)
2178 # find MDS with pending deletions
2179 for node in $(mdts_nodes); do
2180 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2181 2>/dev/null | calc_sum)
2182 if [[ $changes -eq 0 ]]; then
2185 mds2sync="$mds2sync $node"
2187 if [ -z "$mds2sync" ]; then
2190 mds2sync=$(comma_list $mds2sync)
2192 # sync MDS transactions
2193 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2195 # wait till all changes are sent and commmitted by OSTs
2196 # for ldiskfs space is released upon execution, but DMU
2197 # do this upon commit
2200 while [[ $WAIT -ne $MAX_WAIT ]]; do
2201 changes=$(do_nodes $mds2sync \
2202 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2203 #echo "$node: $changes changes on all"
2204 if [[ $changes -eq 0 ]]; then
2206 #echo "delete took $((etime - stime)) seconds"
2208 # the occupied disk space will be released
2209 # only after DMUs are committed
2210 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2211 echo "sleep $ZFS_WAIT for ZFS OSD"
2222 echo "Delete is not completed in $((etime - stime)) seconds"
2223 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2229 # we can use "for" here because we are waiting the slowest
2230 for host in ${hostlist//,/ }; do
2231 check_network "$host" 900
2233 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2240 for facet in ${facetlist//,/ }; do
2241 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2243 wait_for_host $hostlist
2246 _wait_recovery_complete () {
2249 # Use default policy if $2 is not passed by caller.
2250 local MAX=${2:-$(max_recovery_time)}
2255 while [ $WAIT -lt $MAX ]; do
2256 STATUS=$(lctl get_param -n $param | grep status)
2258 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2261 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2263 echo "$param recovery not done in $MAX sec. $STATUS"
2267 wait_recovery_complete () {
2270 # with an assumption that at_max is the same on all nodes
2271 local MAX=${2:-$(max_recovery_time)}
2274 if [ "$FAILURE_MODE" = HARD ]; then
2275 facets=$(facets_on_host $(facet_active_host $facet))
2277 echo affected facets: $facets
2279 # we can use "for" here because we are waiting the slowest
2280 for facet in ${facets//,/ }; do
2281 local var_svc=${facet}_svc
2282 local param="*.${!var_svc}.recovery_status"
2284 local host=$(facet_active_host $facet)
2285 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2289 wait_mds_ost_sync () {
2290 # just because recovery is done doesn't mean we've finished
2291 # orphan cleanup. Wait for llogs to get synchronized.
2292 echo "Waiting for orphan cleanup..."
2293 # MAX value includes time needed for MDS-OST reconnection
2294 local MAX=$(( TIMEOUT * 2 ))
2295 local WAIT_TIMEOUT=${1:-$MAX}
2298 local list=$(comma_list $(mdts_nodes))
2299 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2300 if ! do_facet $SINGLEMDS \
2301 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2303 # old way, use mds_sync
2305 list=$(comma_list $(osts_nodes))
2306 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2309 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2310 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2311 local -a sync=($(do_nodes $list "$cmd"))
2314 for ((i=0; i<${#sync[@]}; i++)); do
2316 [ ${sync[$i]} -eq 1 ] && continue
2318 [ ${sync[$i]} -eq 0 ] && continue
2320 # there is a not finished MDS-OST synchronization
2324 sleep 2 # increase waiting time and cover statfs cache
2325 [ ${con} -eq 1 ] && return 0
2326 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2330 # show which nodes are not finished.
2331 do_nodes $list "$cmd"
2332 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2336 wait_destroy_complete () {
2337 echo "Waiting for local destroys to complete"
2338 # MAX value shouldn't be big as this mean server responsiveness
2339 # never increase this just to make test pass but investigate
2340 # why it takes so long time
2343 while [ $WAIT -lt $MAX ]; do
2344 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2348 for ((i=0; i<${#RPCs[@]}; i++)); do
2349 [ ${RPCs[$i]} -eq 0 ] && continue
2350 # there are still some destroy RPCs in flight
2355 [ ${con} -eq 1 ] && return 0 # done waiting
2356 echo "Waiting ${WAIT}s for local destroys to complete"
2359 echo "Local destroys weren't done in $MAX sec."
2363 wait_delete_completed() {
2364 wait_delete_completed_mds $1 || return $?
2365 wait_destroy_complete
2374 # conf-sanity 31 takes a long time cleanup
2375 while [ $WAIT -lt 300 ]; do
2376 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2377 [ -z "${running}" ] && return 0
2378 echo "waited $WAIT for${running}"
2379 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2381 WAIT=$((WAIT + INTERVAL))
2383 echo "service didn't stop after $WAIT seconds. Still running:"
2388 wait_remote_prog () {
2394 [ "$PDSH" = "no_dsh" ] && return 0
2396 while [ $WAIT -lt $2 ]; do
2397 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2398 [ -z "${running}" ] && return 0 || true
2399 echo "waited $WAIT for: "
2401 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2403 WAIT=$((WAIT + INTERVAL))
2405 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2406 [ -z "$pids" ] && return 0
2407 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2408 # FIXME: not portable
2409 for pid in $pids; do
2410 cat /proc/${pid}/status || true
2411 cat /proc/${pid}/wchan || true
2413 kill -9 $pid || true
2422 local clients=${1:-$CLIENTS}
2424 if [ -z "$clients" ]; then
2427 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2433 # not every config has many clients
2439 # usually checked on particular client or locally
2448 client_reconnect_try() {
2449 local f=$MOUNT/recon
2452 if [ -z "$CLIENTS" ]; then
2453 $LFS df $MOUNT; uname -n >> $f
2455 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2457 echo "Connected clients: $(cat $f)"
2458 ls -l $f > /dev/null
2462 client_reconnect() {
2463 # one client_reconnect_try call does not always do the job...
2465 client_reconnect_try && break
2470 affected_facets () {
2473 local host=$(facet_active_host $facet)
2474 local affected=$facet
2476 if [ "$FAILURE_MODE" = HARD ]; then
2477 affected=$(facets_up_on_host $host)
2483 local E2FSCK_ON_MDT0=false
2484 if [ "$1" == "--fsck" ]; then
2486 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2498 #Because it will only get up facets, we need get affected
2499 #facets before shutdown
2500 #For HARD Failure mode, it needs make sure facets on the same
2501 #HOST will only be shutdown and reboot once
2502 for facet in ${facets//,/ }; do
2503 local affected_facet
2505 #check whether facet has been included in other affected facets
2506 for ((index=0; index<$total; index++)); do
2507 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2510 if [ $skip -eq 0 ]; then
2511 affecteds[$total]=$(affected_facets $facet)
2516 for ((index=0; index<$total; index++)); do
2517 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2518 local host=$(facet_active_host $facet)
2519 echo "Failing ${affecteds[index]} on $host"
2520 shutdown_facet $facet
2523 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2524 $(mdsdevname 1) "-n" || error "Running e2fsck")
2526 for ((index=0; index<$total; index++)); do
2527 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2528 echo reboot facets: ${affecteds[index]}
2532 change_active ${affecteds[index]}
2534 wait_for_facet ${affecteds[index]}
2535 # start mgs first if it is affected
2536 if ! combined_mgs_mds &&
2537 list_member ${affecteds[index]} mgs; then
2538 mount_facet mgs || error "Restart of mgs failed"
2540 # FIXME; has to be changed to mount all facets concurrently
2541 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2542 echo mount facets: ${affecteds[index]}
2543 mount_facets ${affecteds[index]}
2553 do_facet $facet "sync; sync; sync"
2556 # make sure there will be no seq change
2557 local clients=${CLIENTS:-$HOSTNAME}
2558 local f=fsa-\\\$\(hostname\)
2559 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2560 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2562 local svc=${facet}_svc
2563 do_facet $facet $LCTL --device ${!svc} notransno
2565 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2566 # in-memory state has to be cleared by either rebooting the host or
2567 # exporting and reimporting the pool.
2569 # Although the uberblocks are not updated when a pool is freezed,
2570 # transactions are still written to the disks. Modified blocks may be
2571 # cached in memory when tests try reading them back. The
2572 # export-and-reimport process also evicts any cached pool data from
2573 # memory to provide the correct "data loss" semantics.
2575 # In the test framework, the exporting and importing operations are
2576 # handled by stop() and mount_facet() separately, which are used
2577 # inside fail() and fail_abort().
2579 do_facet $facet $LCTL --device ${!svc} readonly
2580 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2581 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2584 replay_barrier_nodf() {
2585 local facet=$1 echo running=${running}
2586 do_facet $facet "sync; sync; sync"
2587 local svc=${facet}_svc
2588 echo Replay barrier on ${!svc}
2589 do_facet $facet $LCTL --device ${!svc} notransno
2590 do_facet $facet $LCTL --device ${!svc} readonly
2591 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2592 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2595 replay_barrier_nosync() {
2596 local facet=$1 echo running=${running}
2597 local svc=${facet}_svc
2598 echo Replay barrier on ${!svc}
2599 do_facet $facet $LCTL --device ${!svc} notransno
2600 do_facet $facet $LCTL --device ${!svc} readonly
2601 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2602 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2606 # Get Lustre client uuid for a given Lustre mount point.
2609 local mntpnt=${1:-$MOUNT}
2611 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2612 local uuid=$($LCTL get_param -n llite.$name.uuid)
2617 mds_evict_client() {
2618 local mntpnt=${1:-$MOUNT}
2619 local uuid=$(get_client_uuid $mntpnt)
2621 do_facet $SINGLEMDS \
2622 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2625 ost_evict_client() {
2626 local mntpnt=${1:-$MOUNT}
2627 local uuid=$(get_client_uuid $mntpnt)
2630 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2635 local clients=${CLIENTS:-$HOSTNAME}
2637 facet_failover $* || error "failover: $?"
2638 wait_clients_import_state "$clients" "$facets" FULL
2639 clients_up || error "post-failover stat: $?"
2644 facet_failover $facet
2650 change_active $facet
2651 wait_for_facet $facet
2652 mount_facet $facet -o abort_recovery
2653 clients_up || echo "first stat failed: $?"
2654 clients_up || error "post-failover stat: $?"
2658 echo There is no lmc. This is mountconf, baby.
2662 host_nids_address() {
2666 if [ -n "$kind" ]; then
2667 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2669 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2675 if [ "$1" = "'*'" ]; then echo \'*\'; else
2681 if [ "$1" = "'*'" ]; then echo \'*\'; else
2682 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2684 if [ -z "$ID" ]; then
2685 echo "Could not get a ptl id for $1..."
2694 h2name_or_ip "$1" "tcp"
2699 if [ "$1" = "'*'" ]; then echo \'*\'; else
2700 if type __h2elan >/dev/null 2>&1; then
2703 ID=`echo $1 | sed 's/[^0-9]*//g'`
2711 h2name_or_ip "$1" "o2ib"
2715 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2716 # expressions format. As a bonus we can then just pass in those variables
2717 # to pdsh. What this function does is take a HOSTLIST type string and
2718 # expand it into a space deliminated list for us.
2726 [ -z "$hostlist" ] && return
2728 # Translate the case of [..],..,[..] to [..] .. [..]
2729 list="${hostlist/],/] }"
2731 [[ "$front" == *,* ]] && {
2734 list=${list/${old}/${new}}
2737 for item in $list; do
2738 # Test if we have any []'s at all
2739 if [ "$item" != "${item/\[/}" ]; then {
2740 # Expand the [*] into list
2744 if [ "$name" != "$item" ]; then
2745 group=${item#$name[*}
2748 for range in ${group//,/ }; do
2752 # Number of leading zeros
2755 end=$(echo $end | sed 's/0*//')
2756 [[ -z "$end" ]] && end=0
2757 [[ $padlen2 -gt $padlen ]] && {
2758 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2761 begin=$(echo $begin | sed 's/0*//')
2762 [ -z $begin ] && begin=0
2764 for num in $(seq -f "%0${padlen}g" $begin $end); do
2765 value="${name#*,}${num}${back}"
2766 [ "$value" != "${value/\[/}" ] && {
2767 value=$(hostlist_expand "$value")
2769 myList="$myList $value"
2774 myList="$myList $item"
2777 myList=${myList//,/ }
2778 myList=${myList:1} # Remove first character which is a space
2780 # Filter any duplicates without sorting
2782 myList="${list%% *}"
2784 while [[ "$list" != ${myList##* } ]]; do
2785 list=${list//${list%% *} /}
2786 myList="$myList ${list%% *}"
2788 myList="${myList%* }";
2790 # We can select an object at an offset in the list
2793 for item in $myList; do
2795 [ $cnt -eq $offset ] && {
2799 [ $(get_node_count $myList) -ne 1 ] && myList=""
2808 [ "$facet" == client ] && echo -n $HOSTNAME && return
2809 varname=${facet}_HOST
2810 if [ -z "${!varname}" ]; then
2811 if [ "${facet:0:3}" == "ost" ]; then
2812 local fh=${facet%failover}_HOST
2813 eval export ${facet}_HOST=${!fh}
2814 if [ -z "${!varname}" ]; then
2815 eval export ${facet}_HOST=${ost_HOST}
2817 elif [ "${facet:0:3}" == "mdt" -o \
2818 "${facet:0:3}" == "mds" -o \
2819 "${facet:0:3}" == "mgs" ]; then
2820 eval export ${facet}_HOST=${mds_HOST}
2826 facet_failover_host() {
2830 var=${facet}failover_HOST
2831 if [ -n "${!var}" ]; then
2836 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2837 "${facet:0:3}" == "mgs" ]; then
2839 eval export ${facet}failover_host=${mds_HOST}
2844 if [[ $facet == ost* ]]; then
2845 eval export ${facet}failover_host=${ost_HOST}
2853 local activevar=${facet}active
2855 if [ -f $TMP/${facet}active ] ; then
2856 source $TMP/${facet}active
2859 active=${!activevar}
2860 if [ -z "$active" ] ; then
2867 facet_active_host() {
2868 facet_host $(facet_active $1)
2871 # Get the passive failover partner host of facet.
2872 facet_passive_host() {
2874 [[ $facet = client ]] && return
2876 local host=${facet}_HOST
2877 local failover_host=${facet}failover_HOST
2878 local active_host=$(facet_active_host $facet)
2880 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2882 if [[ $active_host = ${!host} ]]; then
2883 echo -n ${!failover_host}
2893 facetlist=$(exclude_items_from_list $facetlist mgs)
2895 for facet in ${facetlist//,/ }; do
2896 local failover=${facet}failover
2897 local host=`facet_host $failover`
2898 [ -z "$host" ] && return
2900 local curactive=`facet_active $facet`
2901 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2902 eval export ${facet}active=$facet
2904 eval export ${facet}active=$failover
2906 # save the active host for this facet
2907 local activevar=${facet}active
2908 echo "$activevar=${!activevar}" > $TMP/$activevar
2909 [[ $facet = mds1 ]] && combined_mgs_mds && \
2910 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2911 local TO=`facet_active_host $facet`
2912 echo "Failover $facet to $TO"
2918 # do not stripe off hostname if verbose, bug 19215
2919 if [ x$1 = x--verbose ]; then
2927 if [ "$HOST" = "$HOSTNAME" ]; then
2929 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2930 echo "cannot run remote command on $HOST with $myPDSH"
2934 echo "CMD: $HOST $@" >&2
2935 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2938 if [ "$myPDSH" = "rsh" ]; then
2939 # we need this because rsh does not return exit code of an executed command
2940 local command_status="$TMP/cs"
2941 rsh $HOST ":> $command_status"
2942 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2943 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2944 echo command failed >$command_status"
2945 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2950 # print HOSTNAME for myPDSH="no_dsh"
2951 if [[ $myPDSH = no_dsh ]]; then
2952 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2954 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2957 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2959 return ${PIPESTATUS[0]}
2963 do_node --verbose "$@"
2966 single_local_node () {
2967 [ "$1" = "$HOSTNAME" ]
2970 # Outputs environment variable assignments that should be passed to remote nodes
2974 local facets=$(get_facets)
2977 for var in ${!MODOPTS_*}; do
2978 value=${!var//\"/\\\"}
2979 echo -n " ${var}=\"$value\""
2982 for facet in ${facets//,/ }; do
2984 if [ -n "${!var}" ]; then
2985 echo -n " $var=${!var}"
2989 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2990 if [ -n "${!var}" ]; then
2991 echo -n " $var=${!var}"
2995 for var in VERBOSE; do
2996 if [ -n "${!var}" ]; then
2997 echo -n " $var=${!var}"
3001 if [ -n "$FSTYPE" ]; then
3002 echo -n " FSTYPE=$FSTYPE"
3005 for var in LNETLND NETTYPE; do
3006 if [ -n "${!var}" ]; then
3007 echo -n " $var=${!var}"
3014 # do not stripe off hostname if verbose, bug 19215
3015 if [ x$1 = x--verbose ]; then
3023 if single_local_node $rnodes; then
3025 do_nodev $rnodes "$@"
3027 do_node $rnodes "$@"
3032 # This is part from do_node
3035 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3036 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3038 export FANOUT=$(get_node_count "${rnodes//,/ }")
3040 echo "CMD: $rnodes $@" >&2
3041 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3044 # do not replace anything from pdsh output if -N is used
3045 # -N Disable hostname: prefix on lines of output.
3046 if $verbose || [[ $myPDSH = *-N* ]]; then
3047 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3049 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3051 return ${PIPESTATUS[0]}
3055 # Execute commands on a single service's host
3057 # The \a facet (service) may be on a local or remote node, which is
3058 # determined at the time the command is run.
3060 # usage: do_facet $facet command [arg ...]
3064 local HOST=$(facet_active_host $facet)
3065 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3069 # Function: do_facet_random_file $FACET $FILE $SIZE
3070 # Creates FILE with random content on the given FACET of given SIZE
3072 do_facet_random_file() {
3076 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3077 do_facet $facet "$cmd 2>/dev/null"
3080 do_facet_create_file() {
3084 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3085 do_facet $facet "$cmd 2>/dev/null"
3089 do_nodes --verbose "$@"
3095 # make sure its not already running
3097 rm -f $TMP/${facet}active
3098 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3099 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3101 if [[ $(facet_fstype $facet) == zfs ]]; then
3103 # After formatting a ZFS target, "cachefile=none" property will
3104 # be set on the ZFS storage pool so that the pool is not
3105 # automatically imported on system startup. And then the pool
3106 # will be exported so as to leave the importing and exporting
3107 # operations handled by mount_facet() and stop() separately.
3109 refresh_partition_table $facet $(facet_vdevice $facet)
3110 disable_zpool_cache $facet
3115 # Device formatted as ost
3118 local DEVNAME=OSTDEV$num
3120 local fstype=$(facet_fstype ost$num)
3124 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3125 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3127 #try $OSTZFSDEVn - independent of vdev
3128 DEVNAME=OSTZFSDEV$num
3129 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3131 error "unknown fstype!";;
3137 # Physical device location of data
3143 local fstype=$(facet_fstype ost$num)
3147 # vdevs are not supported by ldiskfs
3150 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3151 # Device formatted by zfs
3153 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3155 error "unknown fstype!";;
3161 # Logical device formatted for lustre
3164 local DEVNAME=MDSDEV$num
3166 local fstype=$(facet_fstype mds$num)
3170 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3171 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3173 # try $MDSZFSDEVn - independent of vdev
3174 DEVNAME=MDSZFSDEV$num
3175 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3177 error "unknown fstype!";;
3183 # Physical location of data
3187 local fstype=$(facet_fstype mds$num)
3191 # vdevs are not supported by ldiskfs
3194 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3195 # Device formatted by ZFS
3196 local DEVNAME=MDSDEV$num
3197 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3199 error "unknown fstype!";;
3207 local fstype=$(facet_fstype mgs)
3211 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3212 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3213 DEVPTR=$(mdsdevname 1)
3218 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3219 ( [ -z "$MGSZFSDEV" ] &&
3220 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3221 DEVPTR=$(mdsdevname 1)
3223 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3226 error "unknown fstype!";;
3235 local fstype=$(facet_fstype mgs)
3239 # vdevs are not supported by ldiskfs
3242 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3243 ( [ -z "$MGSDEV" ] &&
3244 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3245 VDEVPTR=$(mdsvdevname 1)
3246 elif [ -n "$MGSDEV" ]; then
3250 error "unknown fstype!";;
3258 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3260 local var=${facet}_MOUNT
3261 eval mntpt=${!var:-${MOUNT}-$facet}
3268 local dev=$(facet_device $facet)
3269 local mnt=${2:-$(facet_mntpt $facet)}
3272 if ! do_facet $facet test -b $dev; then
3275 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3280 local dev=$(facet_device $facet)
3281 local mnt=${2:-$(facet_mntpt $facet)}
3283 do_facet $facet $UMOUNT $mnt
3287 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3292 local ds=$(facet_device $facet)
3293 local mnt=${2:-$(facet_mntpt $facet)}
3298 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3299 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3300 do_facet $facet $ZFS set canmount=noauto $ds
3302 # The "legacy" mount method is used here because "zfs unmount $mnt"
3303 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3304 # targets are not available at the time, the stat(2) on $MOUNT will
3307 do_facet $facet $ZFS set mountpoint=legacy $ds
3308 do_facet $facet mount -t zfs $ds $mnt
3309 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3310 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3315 local ds=$(facet_device $facet)
3316 local mnt=${2:-$(facet_mntpt $facet)}
3317 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3318 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3319 local mntpt=${!var_mntpt}
3320 local canmnt=${!var_canmnt}
3324 do_facet $facet umount $mnt
3325 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3326 do_facet $facet $ZFS set canmount=$canmnt $ds
3333 local fstype=$(facet_fstype $facet)
3335 mount_$fstype $facet $mnt
3341 local fstype=$(facet_fstype $facet)
3343 unmount_$fstype $facet $mnt
3350 # make sure we are using the primary server, so test-framework will
3351 # be able to clean up properly.
3352 activemds=`facet_active mds1`
3353 if [ $activemds != "mds1" ]; then
3357 local clients=$CLIENTS
3358 [ -z $clients ] && clients=$(hostname)
3360 zconf_umount_clients $clients $MOUNT "$*" || true
3361 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3363 [ -n "$CLIENTONLY" ] && return
3365 # The add fn does rm ${facet}active file, this would be enough
3366 # if we use do_facet <facet> only after the facet added, but
3367 # currently we use do_facet mds in local.sh
3368 for num in `seq $MDSCOUNT`; do
3370 rm -f ${TMP}/mds${num}active
3372 combined_mgs_mds && rm -f $TMP/mgsactive
3374 for num in `seq $OSTCOUNT`; do
3376 rm -f $TMP/ost${num}active
3379 if ! combined_mgs_mds ; then
3386 cleanup_echo_devs () {
3389 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3391 for dev in $devs; do
3392 $LCTL --device $dev cleanup
3393 $LCTL --device $dev detach
3398 nfs_client_mode && return
3399 cifs_client_mode && return
3408 combined_mgs_mds () {
3409 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3410 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3414 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3418 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3424 local fsname=${3:-"$FSNAME"}
3425 local type=$(facet_type $facet)
3426 local index=$(facet_index $facet)
3427 local fstype=$(facet_fstype $facet)
3428 local host=$(facet_host $facet)
3433 if [ $type == MGS ] || ( [ $type == MDS ] &&
3434 [ "$dev" == $(mgsdevname) ] &&
3435 [ "$host" == "$(facet_host mgs)" ] ); then
3438 opts="--mgsnode=$MGSNID"
3441 if [ $type != MGS ]; then
3442 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3446 var=${facet}failover_HOST
3447 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3448 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3451 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3452 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3454 if [ $type == MDS ]; then
3455 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3456 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3457 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3458 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3460 if [ $fstype == ldiskfs ]; then
3461 # Check for wide striping
3462 if [ $OSTCOUNT -gt 160 ]; then
3463 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3464 fs_mkfs_opts+="-O large_xattr"
3468 if [ -n "${!var}" ]; then
3469 fs_mkfs_opts+=" -J device=${!var}"
3471 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3473 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3477 if [ $type == OST ]; then
3478 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3480 if [ $fstype == ldiskfs ]; then
3482 if [ -n "${!var}" ]; then
3483 fs_mkfs_opts+=" -J device=${!var}"
3485 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3490 opts+=" --backfstype=$fstype"
3493 if [ -n "${!var}" ]; then
3494 opts+=" --device-size=${!var}"
3497 var=$(upper $fstype)_MKFS_OPTS
3498 fs_mkfs_opts+=${!var:+" ${!var}"}
3500 var=${type}_FS_MKFS_OPTS
3501 fs_mkfs_opts+=${!var:+" ${!var}"}
3503 if [ -n "${fs_mkfs_opts## }" ]; then
3504 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3508 opts+=${!var:+" ${!var}"}
3513 check_ost_indices() {
3514 local index_count=${#OST_INDICES[@]}
3515 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3517 # OST count is greater than the index count in $OST_INDEX_LIST.
3518 # We need check whether there are duplicate indices.
3522 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3523 index=$(facet_index ost$i)
3524 for j in $(seq 0 $((index_count - 1))); do
3525 [[ $index -ne ${OST_INDICES[j]} ]] ||
3526 error "ost$i has the same index $index as ost$((j+1))"
3537 echo "Format mgs: $(mgsdevname)"
3538 reformat_external_journal mgs
3539 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3540 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3550 echo "Format mds$num: $(mdsdevname $num)"
3551 reformat_external_journal mds$num
3552 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3553 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3554 ${quiet:+>/dev/null} || exit 10
3563 echo "Format ost$num: $(ostdevname $num)"
3564 reformat_external_journal ost$num
3565 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3566 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3567 ${quiet:+>/dev/null} || exit 10
3572 # Set hostid for ZFS/SPL zpool import protection
3573 # (Assumes MDS version is also OSS version)
3574 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3576 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3579 # We need ldiskfs here, may as well load them all
3581 [ -n "$CLIENTONLY" ] && return
3582 echo Formatting mgs, mds, osts
3583 if ! combined_mgs_mds ; then
3587 for num in $(seq $MDSCOUNT); do
3591 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3593 for num in $(seq $OSTCOUNT); do
3599 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3603 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3607 # 0: success, the old identity set already.
3608 # 1: success, the old identity does not set.
3613 local j=`expr $num - 1`
3614 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3616 if [ -z "$MDT" ]; then
3620 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3623 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3625 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3628 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3630 if [ $old = "NONE" ]; then
3639 zconf_umount `hostname` $1 || error "umount failed"
3640 zconf_mount `hostname` $1 || error "mount failed"
3648 rm -f $TMP/${facet}active
3649 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3654 local mdt_count=${1:-$MDSCOUNT}
3655 local ost_count=${2:-$OSTCOUNT}
3658 for num in $(seq $mdt_count); do
3659 DEVNAME=$(mdsdevname $num)
3660 writeconf_facet mds$num $DEVNAME || rc=$?
3663 for num in $(seq $ost_count); do
3664 DEVNAME=$(ostdevname $num)
3665 writeconf_facet ost$num $DEVNAME || rc=$?
3671 nfs_client_mode && return
3672 cifs_client_mode && return
3674 sanity_mount_check || error "environments are insane!"
3678 if [ -z "$CLIENTONLY" ]; then
3679 echo Setup mgs, mdt, osts
3680 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3681 if ! combined_mgs_mds ; then
3682 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3685 for num in `seq $MDSCOUNT`; do
3686 DEVNAME=$(mdsdevname $num)
3687 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3689 # We started mds, now we should set failover variables properly.
3690 # Set mds${num}failover_HOST if it is not set (the default failnode).
3691 local varname=mds${num}failover_HOST
3692 if [ -z "${!varname}" ]; then
3693 eval mds${num}failover_HOST=$(facet_host mds$num)
3696 if [ $IDENTITY_UPCALL != "default" ]; then
3697 switch_identity $num $IDENTITY_UPCALL
3700 for num in `seq $OSTCOUNT`; do
3701 DEVNAME=$(ostdevname $num)
3702 start ost$num $DEVNAME $OST_MOUNT_OPTS
3704 # We started ost$num, now we should set ost${num}failover variable properly.
3705 # Set ost${num}failover_HOST if it is not set (the default failnode).
3706 varname=ost${num}failover_HOST
3707 if [ -z "${!varname}" ]; then
3708 eval ost${num}failover_HOST=$(facet_host ost${num})
3716 # wait a while to allow sptlrpc configuration be propogated to targets,
3717 # only needed when mounting new target devices.
3722 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3724 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3727 if [ "$MOUNT_2" ]; then
3728 mount_client $MOUNT2
3729 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3734 # by remounting mdt before ost, initial connect from mdt to ost might
3735 # timeout because ost is not ready yet. wait some time to its fully
3736 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3737 # by a context negotiation rpc with $TIMEOUT.
3738 # FIXME better by monitoring import status.
3741 sleep $((TIMEOUT + 5))
3747 mounted_lustre_filesystems() {
3748 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3751 init_facet_vars () {
3752 [ -n "$CLIENTONLY" ] && return 0
3759 eval export ${facet}_dev=${device}
3760 eval export ${facet}_opt=\"$@\"
3762 local dev=${facet}_dev
3764 # We need to loop for the label
3765 # in case its not initialized yet.
3766 for wait_time in {0,1,3,5,10}; do
3768 if [ $wait_time -gt 0 ]; then
3769 echo "${!dev} not yet initialized,"\
3770 "waiting ${wait_time} seconds."
3774 local label=$(devicelabel ${facet} ${!dev})
3776 # Check to make sure the label does
3777 # not include ffff at the end of the label.
3778 # This indicates it has not been initialized yet.
3780 if [[ $label =~ [f|F]{4}$ ]]; then
3781 # label is not initialized, unset the result
3782 # and either try again or fail
3789 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3791 eval export ${facet}_svc=${label}
3793 local varname=${facet}failover_HOST
3794 if [ -z "${!varname}" ]; then
3795 eval export $varname=$(facet_host $facet)
3798 varname=${facet}_HOST
3799 if [ -z "${!varname}" ]; then
3800 eval export $varname=$(facet_host $facet)
3803 # ${facet}failover_dev is set in cfg file
3804 varname=${facet}failover_dev
3805 if [ -n "${!varname}" ] ; then
3806 eval export ${facet}failover_dev=${!varname}
3808 eval export ${facet}failover_dev=$device
3811 # get mount point of already mounted device
3812 # is facet_dev is already mounted then use the real
3813 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3814 # i.e. ${facet}_MOUNT if specified by user or default
3815 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3816 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3817 if [ -z $mntpt ]; then
3818 mntpt=$(facet_mntpt $facet)
3820 eval export ${facet}_MOUNT=$mntpt
3823 init_facets_vars () {
3826 if ! remote_mds_nodsh; then
3827 for num in $(seq $MDSCOUNT); do
3828 DEVNAME=`mdsdevname $num`
3829 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3833 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3835 if ! remote_ost_nodsh; then
3836 for num in $(seq $OSTCOUNT); do
3837 DEVNAME=$(ostdevname $num)
3838 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3843 osc_ensure_active () {
3848 while [ $period -lt $timeout ]; do
3849 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3850 if [ $count -eq 0 ]; then
3854 echo "There are $count OST are inactive, wait $period seconds, and try again"
3856 period=$((period+3))
3859 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3862 set_conf_param_and_check() {
3866 local ORIG=$(do_facet $myfacet "$TEST")
3867 if [ $# -gt 3 ]; then
3873 echo "Setting $PARAM from $ORIG to $FINAL"
3874 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3875 error "conf_param $PARAM failed"
3877 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3878 error "check $PARAM failed!"
3881 init_param_vars () {
3882 TIMEOUT=$(lctl get_param -n timeout)
3883 TIMEOUT=${TIMEOUT:-20}
3885 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3887 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3888 log "Using TIMEOUT=$TIMEOUT"
3890 osc_ensure_active $SINGLEMDS $TIMEOUT
3891 osc_ensure_active client $TIMEOUT
3893 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3894 local current_jobid_var=$($LCTL get_param -n jobid_var)
3896 if [ $JOBID_VAR = "existing" ]; then
3897 echo "keeping jobstats as $current_jobid_var"
3898 elif [ $current_jobid_var != $JOBID_VAR ]; then
3899 echo "seting jobstats to $JOBID_VAR"
3901 set_conf_param_and_check client \
3902 "$LCTL get_param -n jobid_var" \
3903 "$FSNAME.sys.jobid_var" $JOBID_VAR
3906 echo "jobstats not supported by server"
3909 if [ $QUOTA_AUTO -ne 0 ]; then
3910 if [ "$ENABLE_QUOTA" ]; then
3911 echo "enable quota as required"
3912 setup_quota $MOUNT || return 2
3914 echo "disable quota as required"
3915 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3921 nfs_client_mode () {
3922 if [ "$NFSCLIENT" ]; then
3923 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3924 local clients=$CLIENTS
3925 [ -z $clients ] && clients=$(hostname)
3927 # FIXME: remove hostname when 19215 fixed
3928 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3929 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3930 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3931 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3933 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3939 cifs_client_mode () {
3940 [ x$CIFSCLIENT = xyes ] &&
3941 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3944 check_config_client () {
3947 local mounted=$(mount | grep " $mntpt ")
3948 if [ -n "$CLIENTONLY" ]; then
3950 # CLIENTONLY should not depend on *_HOST settings
3951 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3952 # in theory someone could create a new,
3953 # client-only config file that assumed lustre was already
3954 # configured and didn't set the MGSNID. If MGSNID is not set,
3955 # then we should use the mgs nid currently being used
3956 # as the default value. bug 18021
3957 [[ x$MGSNID = x ]] &&
3960 if [[ x$mgc != xMGC$MGSNID ]]; then
3961 if [ "$mgs_HOST" ]; then
3962 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3963 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3964 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3970 local myMGS_host=$mgs_HOST
3971 if [ "$NETTYPE" = "ptl" ]; then
3972 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3975 echo Checking config lustre mounted on $mntpt
3976 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3977 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3979 # if [ "$mgshost" != "$myMGS_host" ]; then
3980 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3981 # Please use correct config or set mds_HOST correctly!"
3986 check_config_clients () {
3987 local clients=${CLIENTS:-$HOSTNAME}
3990 nfs_client_mode && return
3991 cifs_client_mode && return
3993 do_rpc_nodes "$clients" check_config_client $mntpt
3995 sanity_mount_check || error "environments are insane!"
3999 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4000 local cltimeout=$(lctl get_param -n timeout)
4001 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4002 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4009 [ -z $mntpt ] && return 1
4010 local mounted=$(mounted_lustre_filesystems)
4012 echo $mounted' ' | grep -w -q $mntpt' '
4016 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4020 # empty lustre filesystem may have empty directories lost+found and .lustre
4022 # exclude .lustre & lost+found
4023 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4024 -print | wc -l) = 1 ] || return 1
4025 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4026 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4027 # exclude .lustre/fid (LU-2780)
4028 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4029 -print | wc -l) = 1 ] || return 1
4031 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4036 check_and_setup_lustre() {
4038 nfs_client_mode && return
4039 cifs_client_mode && return
4041 local MOUNTED=$(mounted_lustre_filesystems)
4045 # both MOUNT and MOUNT2 are not mounted
4046 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4047 [ "$REFORMAT" = "yes" ] && formatall
4048 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4050 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4051 export I_MOUNTED=yes
4055 elif is_mounted $MOUNT2; then
4057 # MOUNT2 is mounted, while MOUNT_2 is not set
4058 if ! [ "$MOUNT_2" ]; then
4059 cleanup_mount $MOUNT2
4060 export I_UMOUNTED2=yes
4063 # MOUNT2 is mounted, MOUNT_2 is set
4065 # FIXME: what to do if check_config failed?
4067 # 1) remote client has mounted other Lustre fs ?
4068 # 2) it has insane env ?
4069 # let's try umount MOUNT2 on all clients and mount it again:
4070 if ! check_config_clients $MOUNT2; then
4071 cleanup_mount $MOUNT2
4072 restore_mount $MOUNT2
4073 export I_MOUNTED2=yes
4078 # MOUNT is mounted MOUNT2 is not mounted
4079 elif [ "$MOUNT_2" ]; then
4080 restore_mount $MOUNT2
4081 export I_MOUNTED2=yes
4085 # FIXME: what to do if check_config failed?
4087 # 1) remote client has mounted other Lustre fs?
4088 # 2) lustre is mounted on remote_clients atall ?
4089 check_config_clients $MOUNT
4093 set_default_debug_nodes $(comma_list $(nodes_list))
4096 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4098 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4099 facets="$(get_facets OST)"
4100 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4101 facets="$facets,$(get_facets MDS)"
4102 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4103 facets="$facets,mgs"
4104 local nodes="$(facets_hosts ${facets})"
4105 if [ -n "$nodes" ] ; then
4106 do_nodes $nodes "$LCTL set_param \
4107 osd-ldiskfs.track_declares_assert=1 || true"
4116 if [ -z "$CLIENTONLY" ]; then
4117 # Enable remote MDT create for testing
4118 for num in $(seq $MDSCOUNT); do
4120 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4125 if [ "$ONLY" == "setup" ]; then
4131 local clients=${CLIENTS:-$HOSTNAME}
4134 zconf_mount_clients $clients $mntpt
4138 local clients=${CLIENTS:-$HOSTNAME}
4141 zconf_umount_clients $clients $mntpt
4144 cleanup_and_setup_lustre() {
4145 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4146 lctl set_param debug=0 || true
4148 if [ "$ONLY" == "cleanup" ]; then
4152 check_and_setup_lustre
4155 # Get all of the server target devices from a given server node and type.
4162 if [ "$type" == ost ]; then
4163 devs=$(get_osd_param $node "" mntdev)
4165 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4167 for dev in $devs; do
4169 *loop*) do_node $node "losetup $dev" | \
4170 sed -e "s/.*(//" -e "s/).*//" ;;
4176 # Get all of the server target devices.
4181 # Master MDS parameters used by lfsck
4182 MDTNODE=$(facet_active_host $SINGLEMDS)
4183 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4187 for node in $(mdts_nodes); do
4188 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4194 for node in $(osts_nodes); do
4195 OSTDEVS[i]=$(get_mnt_devs $node ost)
4200 # Run e2fsck on MDT or OST device.
4205 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4206 local log=$TMP/e2fsck.log
4210 do_node $node $cmd 2>&1 | tee $log
4212 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4214 if [ $MDSCOUNT -gt 1 ]; then
4215 skip "DNE mode isn't supported!"
4219 error "It's not DNE mode."
4224 [ $rc -le $FSCK_MAX_ERR ] ||
4225 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4231 # Run resize2fs on MDT or OST device.
4240 do_facet $facet "$RESIZE2FS $opts $device $size"
4243 # verify a directory is shared among nodes.
4244 check_shared_dir() {
4246 local list=${2:-$(comma_list $(nodes_list))}
4248 [ -z "$dir" ] && return 1
4249 do_rpc_nodes "$list" check_logdir $dir
4250 check_write_access $dir "$list" || return 1
4255 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4256 $LCTL set_param printk=+lfsck
4257 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4259 for k in $(seq $MDSCOUNT); do
4260 # wait up to 10+1 minutes for LFSCK to complete
4261 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4262 mdd.$(facet_svc mds${k}).lfsck_layout |
4263 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4264 error "MDS${k} layout isn't the expected 'completed'"
4265 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4266 mdd.$(facet_svc mds${k}).lfsck_namespace |
4267 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4268 error "MDS${k} namespace isn't the expected 'completed'"
4270 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4271 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4272 awk '/repaired/ { print $2 }' | calc_sum)
4273 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4274 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4275 awk '/repaired/ { print $2 }' | calc_sum)
4276 local repaired=$((rep_mdt + rep_ost))
4277 [ $repaired -eq 0 ] ||
4278 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4281 dump_file_contents() {
4287 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4288 error_noexit false \
4289 "Invalid parameters for dump_file_contents()"
4292 for node in ${nodes}; do
4293 do_node $node "for i in \\\$(find $dir -type f); do
4294 echo ====\\\${i}=======================;
4296 done" >> ${logname}.${node}.log
4300 dump_command_output() {
4306 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4307 error_noexit false \
4308 "Invalid parameters for dump_command_output()"
4312 for node in ${nodes}; do
4313 do_node $node "echo ====${cmd}=======================;
4314 $cmd" >> ${logname}.${node}.log
4321 # dump file contents from /proc/spl in case of zfs test
4322 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4323 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4324 dump_command_output \
4325 "$(osts_nodes)" "zpool events -v" "${logname}"
4328 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4329 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4330 dump_command_output \
4331 "$(mdts_nodes)" "zpool events -v" "${logname}"
4335 check_and_cleanup_lustre() {
4336 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4337 "$TESTSUITE" != "sanity-scrub" ]; then
4341 if is_mounted $MOUNT; then
4342 if $DO_CLEANUP; then
4343 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4344 error "remove sub-test dirs failed"
4348 [ "$ENABLE_QUOTA" ] && restore_quota || true
4351 if [ "$I_UMOUNTED2" = "yes" ]; then
4352 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4355 if [ "$I_MOUNTED2" = "yes" ]; then
4356 cleanup_mount $MOUNT2
4359 if [ "$I_MOUNTED" = "yes" ]; then
4360 cleanupall -f || error "cleanup failed"
4368 wait_for_function () {
4371 # suppress fn both stderr and stdout
4372 if [ "$1" = "--quiet" ]; then
4374 quiet=" > /dev/null 2>&1"
4386 eval $fn $quiet && return 0
4388 wait=$((wait + sleep))
4389 [ $wait -lt $max ] || return 1
4390 echo waiting $fn, $((max - wait)) secs left ...
4400 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4401 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4402 echo "Network not available!"
4406 echo `date +"%H:%M:%S (%s)"` network interface is UP
4414 # Convert a space-delimited list to a comma-delimited list. If the input is
4415 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4417 # echo is used to convert newlines to spaces, since it doesn't
4418 # introduce a trailing space as using "tr '\n' ' '" does
4419 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4425 echo $list | grep -qw $item
4428 # list, excluded are the comma separated lists
4429 exclude_items_from_list () {
4435 for item in ${excluded//,/ }; do
4436 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4438 echo $(comma_list $list)
4441 # list, expand are the comma separated lists
4443 local list=${1//,/ }
4444 local expand=${2//,/ }
4447 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4448 echo $(comma_list $expanded)
4451 testslist_filter () {
4452 local script=$LUSTRE/tests/${TESTSUITE}.sh
4454 [ -f $script ] || return 0
4456 local start_at=$START_AT
4457 local stop_at=$STOP_AT
4459 local var=${TESTSUITE//-/_}_START_AT
4460 [ x"${!var}" != x ] && start_at=${!var}
4461 var=${TESTSUITE//-/_}_STOP_AT
4462 [ x"${!var}" != x ] && stop_at=${!var}
4464 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4465 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4466 /^'${start_at}'$/ {flag = 0}
4467 {if (flag == 1) print $0}
4468 /^'${stop_at}'$/ { flag = 1 }'
4472 (cd `dirname $1`; echo $PWD/`basename $1`)
4476 local types=${1:-"OST MDS MGS"}
4480 for entry in $types; do
4481 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4482 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4485 MGS ) list="$list $name";;
4486 MDS|OST|AGT ) local count=${type}COUNT
4487 for ((i=1; i<=${!count}; i++)) do
4488 list="$list ${name}$i"
4490 * ) error "Invalid facet type"
4494 echo $(comma_list $list)
4497 ##################################
4498 # Adaptive Timeouts funcs
4501 # only check mds, we assume at_max is the same on all nodes
4502 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4503 if [ $at_max -eq 0 ]; then
4514 # suppose that all ost-s have the same $at value set
4515 [ $facet != "ost" ] || facet=ost1
4517 do_facet $facet "lctl get_param -n $at"
4535 if [ $facet == "ost" ]; then
4536 facet=$(get_facets OST)
4537 elif [ $facet == "mds" ]; then
4538 facet=$(get_facets MDS)
4540 hosts=$(expand_list $hosts $(facets_hosts $facet))
4543 do_nodes $hosts lctl set_param at_max=$at_max
4546 ##################################
4550 # OBD_FAIL_MDS_ALL_REQUEST_NET
4552 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4553 do_facet client "$1" || RC=$?
4554 do_facet $SINGLEMDS lctl set_param fail_loc=0
4559 # OBD_FAIL_MDS_ALL_REPLY_NET
4561 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4563 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4567 drop_reint_reply() {
4568 # OBD_FAIL_MDS_REINT_NET_REP
4570 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4572 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4576 drop_update_reply() {
4577 # OBD_FAIL_OUT_UPDATE_NET_REP
4581 do_facet mds${index} lctl set_param fail_loc=0x1701
4582 do_facet client "$@" || RC=$?
4583 do_facet mds${index} lctl set_param fail_loc=0
4588 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4591 local timeout=${2:-0}
4592 # default is (obd_timeout / 4) if unspecified
4593 echo "timeout is $timeout/$2"
4594 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4595 do_facet client "$1" || RC=$?
4596 do_facet client "sync"
4597 do_facet ost1 lctl set_param fail_loc=0
4601 drop_ldlm_cancel() {
4602 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4604 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4605 do_nodes $list lctl set_param fail_loc=0x304
4607 do_facet client "$@" || RC=$?
4609 do_nodes $list lctl set_param fail_loc=0
4613 drop_bl_callback_once() {
4615 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4616 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4617 do_facet client lctl set_param fail_loc=0x80000305
4618 do_facet client "$@" || rc=$?
4619 do_facet client lctl set_param fail_loc=0
4620 do_facet client lctl set_param fail_val=0
4621 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4625 drop_bl_callback() {
4627 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4628 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4629 do_facet client lctl set_param fail_loc=0x305
4630 do_facet client "$@" || rc=$?
4631 do_facet client lctl set_param fail_loc=0
4632 do_facet client lctl set_param fail_val=0
4633 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4638 #define OBD_FAIL_LDLM_REPLY 0x30c
4640 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4641 do_nodes $list lctl set_param fail_loc=0x30c
4643 do_facet client "$@" || RC=$?
4645 do_nodes $list lctl set_param fail_loc=0
4649 drop_ldlm_reply_once() {
4650 #define OBD_FAIL_LDLM_REPLY 0x30c
4652 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4653 do_nodes $list lctl set_param fail_loc=0x8000030c
4655 do_facet client "$@" || RC=$?
4657 do_nodes $list lctl set_param fail_loc=0
4665 echo "clearing fail_loc on $facet"
4666 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4669 set_nodes_failloc () {
4671 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4674 cancel_lru_locks() {
4675 #$LCTL mark "cancel_lru_locks $1 start"
4676 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4677 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4678 #$LCTL mark "cancel_lru_locks $1 stop"
4683 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4684 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4685 echo "$DEFAULT_LRU_SIZE"
4690 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4693 lru_resize_disable()
4695 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4701 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4707 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4708 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4709 echo there is still data in page cache $FILE ?
4710 lctl get_param -n $FILE
4718 DEBUGSAVE="$(lctl get_param -n debug)"
4719 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4723 [ -n "$DEBUGSAVE" ] &&
4724 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4728 [ -n "$DEBUGSAVE_SERVER" ] &&
4729 do_nodes $(comma_list $(all_server_nodes)) \
4730 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4736 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4739 debug_size_restore() {
4740 [ -n "$DEBUG_SIZE_SAVED" ] && \
4741 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4745 start_full_debug_logging() {
4750 local DEBUG_SIZE=150
4752 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4753 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4756 stop_full_debug_logging() {
4761 # prints bash call stack
4762 print_stack_trace() {
4765 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4766 local src=${BASH_SOURCE[$i]}
4767 local lineno=${BASH_LINENO[$i-1]}
4768 local funcname=${FUNCNAME[$i]}
4769 echo " = $src:$lineno:$funcname()"
4774 local TYPE=${TYPE:-"FAIL"}
4777 # do not dump logs if $1=false
4778 if [ "x$1" = "xfalse" ]; then
4783 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4784 (print_stack_trace 2) >&2
4786 # We need to dump the logs on all nodes
4788 gather_logs $(comma_list $(nodes_list))
4792 [ "$TESTSUITELOG" ] &&
4793 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4794 if [ -z "$*" ]; then
4795 echo "error() without useful message, please fix" > $LOGDIR/err
4797 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4798 echo "$@" > $LOGDIR/ignore
4800 echo "$@" > $LOGDIR/err
4804 # cleanup the env for failed tests
4808 ##################################
4810 ##################################
4818 local log=$TESTSUITELOG
4820 [ -f "$log" ] && grep -q FAIL $log && status=1
4834 # use only if we are ignoring failures for this test, bugno required.
4835 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4836 # e.g. error_ignore bz5494 "your message" or
4837 # error_ignore LU-5494 "your message"
4839 local TYPE="IGNORE ($1)"
4844 error_and_remount() {
4846 remount_client $MOUNT
4850 # Throw an error if it's not running in vm - usually for performance
4853 local virt=$(running_in_vm)
4854 if [[ -n "$virt" ]]; then
4855 echo "running in VM '$virt', ignore error"
4856 error_ignore env=$virt "$@"
4863 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4868 log " SKIP: $TESTSUITE $TESTNAME $@"
4870 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4871 skip_logged $TESTNAME "$@"
4874 echo "$@" > $LOGDIR/skip
4877 [[ -n "$TESTSUITELOG" ]] &&
4878 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4881 build_test_filter() {
4882 EXCEPT="$EXCEPT $(testslist_filter)"
4885 if [[ $O = [0-9]*-[0-9]* ]]; then
4886 for num in $(seq $(echo $O | tr '-' ' ')); do
4894 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4895 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4896 [ "$EXCEPT_SLOW" ] && \
4897 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4898 for E in $EXCEPT; do
4899 eval EXCEPT_${E}=true
4901 for E in $ALWAYS_EXCEPT; do
4902 eval EXCEPT_ALWAYS_${E}=true
4904 for E in $EXCEPT_SLOW; do
4905 eval EXCEPT_SLOW_${E}=true
4907 for G in $GRANT_CHECK_LIST; do
4908 eval GCHECK_ONLY_${G}=true
4913 if [[ $1 = [a-z]* ]]; then
4920 # print a newline if the last test was skipped
4921 export LAST_SKIPPED=
4922 export ALWAYS_SKIPPED=
4924 # Main entry into test-framework. This is called with the name and
4925 # description of a test. The name is used to find the function to run
4926 # the test using "test_$name".
4928 # This supports a variety of methods of specifying specific test to
4929 # run or not run. These need to be documented...
4934 export base=$(basetest $1)
4935 if [ -n "$ONLY" ]; then
4937 if [ ${!testname}x != x ]; then
4938 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4939 run_one_logged $1 "$2"
4943 if [ ${!testname}x != x ]; then
4944 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4945 run_one_logged $1 "$2"
4955 if [ ${!testname}x != x ]; then
4956 TESTNAME=test_$1 skip "skipping excluded test $1"
4959 testname=EXCEPT_$base
4960 if [ ${!testname}x != x ]; then
4961 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4964 testname=EXCEPT_ALWAYS_$1
4965 if [ ${!testname}x != x ]; then
4966 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4969 testname=EXCEPT_ALWAYS_$base
4970 if [ ${!testname}x != x ]; then
4971 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4974 testname=EXCEPT_SLOW_$1
4975 if [ ${!testname}x != x ]; then
4976 TESTNAME=test_$1 skip "skipping SLOW test $1"
4979 testname=EXCEPT_SLOW_$base
4980 if [ ${!testname}x != x ]; then
4981 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4987 run_one_logged $1 "$2"
4994 load_module ../libcfs/libcfs/libcfs
5006 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5011 strace -o $TMP/$1.strace -ttt $*
5013 log "FINISHED: $*: rc $RC"
5020 banner test complete, duration $duration sec
5021 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5022 echo duration $duration >>$TESTSUITELOG
5026 # Set TEST_STATUS here. It will be used for logging the result.
5029 if [[ -f $LOGDIR/err ]]; then
5031 elif [[ -f $LOGDIR/skip ]]; then
5034 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5038 local FFREE=$(do_node $SINGLEMDS \
5039 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5040 local FTOTAL=$(do_node $SINGLEMDS \
5041 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5043 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5047 echo -n "Resetting fail_loc on all nodes..."
5048 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5049 fail_val=0 2>/dev/null" || true
5055 # Log a message (on all nodes) padded with "=" before and after.
5056 # Also appends a timestamp and prepends the testsuite name.
5059 EQUALS="===================================================================================================="
5061 msg="== ${TESTSUITE} $*"
5063 [[ $last != "=" && $last != " " ]] && msg="$msg "
5064 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5065 # always include at least == after the message
5066 log "$msg== $(date +"%H:%M:%S (%s)")"
5069 check_dmesg_for_errors() {
5071 local errors="VFS: Busy inodes after unmount of\|\
5072 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5073 group descriptors corrupted"
5075 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5076 [ -z "$res" ] && return 0
5077 echo "Kernel error detected: $res"
5082 # Run a single test function and cleanup after it.
5084 # This function should be run in a subshell so the test func can
5085 # exit() without stopping the whole script.
5090 export tfile=f${testnum}.${TESTSUITE}
5091 export tdir=d${testnum}.${TESTSUITE}
5092 export TESTNAME=test_$testnum
5093 local SAVE_UMASK=`umask`
5096 if ! grep -q $DIR /proc/mounts; then
5100 banner "test $testnum: $message"
5101 test_${testnum} || error "test_$testnum failed with $?"
5104 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5106 check_dmesg_for_errors || error "Error in dmesg detected"
5107 if [ "$PARALLEL" != "yes" ]; then
5108 ps auxww | grep -v grep | grep -q multiop &&
5109 error "multiop still running"
5120 # Wrapper around run_one to ensure:
5121 # - test runs in subshell
5122 # - output of test is saved to separate log file for error reporting
5123 # - test result is saved to data file
5126 local BEFORE=$(date +%s)
5128 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5129 local test_log=$LOGDIR/$name
5130 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5131 local zfs_debug_log=$LOGDIR/$zfs_log_name
5133 rm -rf $LOGDIR/ignore
5135 local SAVE_UMASK=$(umask)
5139 log_sub_test_begin test_${1}
5140 (run_one $1 "$2") 2>&1 | tee -i $test_log
5141 local RC=${PIPESTATUS[0]}
5143 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5144 echo "test_$1 returned $RC" | tee $LOGDIR/err
5146 duration=$(($(date +%s) - $BEFORE))
5147 pass "$1" "(${duration}s)"
5149 if [[ -f $LOGDIR/err ]]; then
5150 TEST_ERROR=$(cat $LOGDIR/err)
5151 elif [[ -f $LOGDIR/ignore ]]; then
5152 TEST_ERROR=$(cat $LOGDIR/ignore)
5153 elif [[ -f $LOGDIR/skip ]]; then
5154 TEST_ERROR=$(cat $LOGDIR/skip)
5156 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5158 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5162 if [ -f $LOGDIR/err ]; then
5163 log_zfs_info "$zfs_debug_log"
5164 $FAIL_ON_ERROR && exit $RC
5173 # Print information of skipped tests to result.yml
5176 log_sub_test_begin $1
5178 log_sub_test_end "SKIP" "0" "0" "$@"
5182 (cd $(dirname $1); echo $PWD/$(basename $1))
5187 export base=$(basetest $1)
5188 [ "$CHECK_GRANT" == "no" ] && return 0
5190 testname=GCHECK_ONLY_${base}
5191 [ ${!testname}x == x ] && return 0
5193 echo -n "checking grant......"
5195 local clients=$CLIENTS
5196 [ -z "$clients" ] && clients=$(hostname)
5198 # sync all the data and make sure no pending data on server
5199 do_nodes $clients sync
5202 client_grant=$(do_nodes $clients \
5203 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5204 awk '{ total += $1 } END { printf("%0.0f", total) }')
5207 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5208 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5209 awk '{ total += $1 } END { printf("%0.0f", total) }')
5211 # check whether client grant == server grant
5212 if [[ $client_grant -ne $server_grant ]]; then
5213 echo "failed: client:${client_grant} server: ${server_grant}."
5214 do_nodes $(comma_list $(osts_nodes)) \
5215 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5216 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5219 echo "pass: client:${client_grant} server: ${server_grant}"
5223 ########################
5229 ost=`echo $1 | awk -F_ '{print $3}'`
5230 if [ -z $ost ]; then
5231 ost=`echo $1 | sed 's/-osc.*//'`
5236 ostuuid_from_index()
5238 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5241 ostname_from_index() {
5242 local uuid=$(ostuuid_from_index $1)
5246 index_from_ostuuid()
5248 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5251 mdtuuid_from_index()
5253 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5257 # Return unique identifier for given hostname
5260 echo $host_name | md5sum | cut -d' ' -f1
5264 # Returns list of ip addresses for each interface
5266 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5271 # Cache address list to avoid mutiple execution of local_addr_list
5272 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5274 for i in $LOCAL_ADDR_LIST ; do
5275 [[ "$i" == "$addr" ]] && return 0
5282 local is_local="IS_LOCAL_$(host_id $host_name)"
5283 if [ -z "${!is_local-}" ] ; then
5285 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5286 is_local_addr "$host_ip" && eval $is_local=1
5288 [[ "${!is_local}" == "1" ]]
5293 local_node $node && return 1
5300 for node in $(mdts_nodes); do
5301 remote_node $node && return 0
5308 [ -n "$CLIENTONLY" ] && return 0 || true
5309 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5314 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5315 MSKIPPED=1 && return 1
5322 for node in $(osts_nodes) ; do
5323 remote_node $node && return 0
5330 [ -n "$CLIENTONLY" ] && return 0 || true
5331 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5336 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5337 OSKIPPED=1 && return 1
5343 [ -n "$CLIENTONLY" ] && return 0 || true
5345 MGS=$(facet_host mgs)
5346 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5351 remote_mds_nodsh || remote_ost_nodsh || \
5352 $(single_local_node $(comma_list $(nodes_list)))
5356 remote_ost && remote_mds
5359 # Get the active nodes for facets.
5367 for facet in ${facets//,/ }; do
5368 nodes="$nodes $(facet_active_host $facet)"
5371 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5375 # Get all of the active MDS nodes.
5377 echo -n $(facets_nodes $(get_facets MDS))
5380 # Get all of the active OSS nodes.
5382 echo -n $(facets_nodes $(get_facets OST))
5385 # Get all of the active AGT (HSM agent) nodes.
5387 echo -n $(facets_nodes $(get_facets AGT))
5390 # Get all of the client nodes and active server nodes.
5392 local nodes=$HOSTNAME
5396 # CLIENTS (if specified) contains the local client
5397 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5399 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5400 nodes="$nodes $(facets_nodes $(get_facets))"
5403 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5407 # Get all of the remote client nodes and remote active server nodes.
5408 remote_nodes_list () {
5409 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5412 # Get all of the MDS nodes, including active and passive nodes.
5420 for i in $(seq $MDSCOUNT); do
5422 failover_host=mds${i}failover_HOST
5423 nodes="$nodes ${!host} ${!failover_host}"
5426 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5430 # Get all of the OSS nodes, including active and passive nodes.
5438 for i in $(seq $OSTCOUNT); do
5440 failover_host=ost${i}failover_HOST
5441 nodes="$nodes ${!host} ${!failover_host}"
5444 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5448 # Get all of the server nodes, including active and passive nodes.
5449 all_server_nodes () {
5454 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5456 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5460 # Get all of the client and server nodes, including active and passive nodes.
5462 local nodes=$HOSTNAME
5466 # CLIENTS (if specified) contains the local client
5467 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5469 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5470 nodes="$nodes $(all_server_nodes)"
5473 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5477 init_clients_lists () {
5478 # Sanity check: exclude the local client from RCLIENTS
5479 local clients=$(hostlist_expand "$RCLIENTS")
5480 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5482 # Sanity check: exclude the dup entries
5483 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5485 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5487 # Sanity check: exclude the dup entries from CLIENTS
5488 # for those configs which has SINGLCLIENT set to local client
5489 clients=$(for i in $clients; do echo $i; done | sort -u)
5491 CLIENTS=$(comma_list $clients)
5492 local -a remoteclients=($RCLIENTS)
5493 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5494 varname=CLIENT$((i + 2))
5495 eval $varname=${remoteclients[i]}
5498 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5501 get_random_entry () {
5504 rnodes=${rnodes//,/ }
5506 local -a nodes=($rnodes)
5507 local num=${#nodes[@]}
5508 local i=$((RANDOM * num * 2 / 65536))
5514 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5518 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5519 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5524 echo $nodes | wc -w || true
5528 local nodes=$(osts_nodes)
5529 local osscount=$(get_node_count "$nodes")
5530 [ ! "$OSTCOUNT" = "$osscount" ]
5534 local nodes=$(mdts_nodes)
5535 local mdtcount=$(get_node_count "$nodes")
5536 [ ! "$MDSCOUNT" = "$mdtcount" ]
5539 generate_machine_file() {
5540 local nodes=${1//,/ }
5541 local machinefile=$2
5543 for node in $nodes; do
5544 echo $node >>$machinefile || \
5545 { echo "can not generate machinefile $machinefile" && return 1; }
5550 local file=$1/stripe
5553 $LFS getstripe -v $file || error "getstripe $file failed"
5557 setstripe_nfsserver () {
5560 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5561 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5563 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5565 do_nodev $nfsserver lfs setstripe "$@"
5568 # Check and add a test group.
5574 local gid=$(getent group $group_name | cut -d: -f3)
5575 if [[ -n "$gid" ]]; then
5576 [[ "$gid" -eq "$group_id" ]] || {
5577 error_noexit "inconsistent group ID:" \
5578 "new: $group_id, old: $gid"
5582 groupadd -g $group_id $group_name
5589 # Check and add a test user.
5602 local uid=$(getent passwd $user_name | cut -d: -f3)
5603 if [[ -n "$uid" ]]; then
5604 if [[ "$uid" -eq "$user_id" ]]; then
5605 local dir=$(getent passwd $user_name | cut -d: -f6)
5606 if [[ "$dir" != "$home" ]]; then
5608 usermod -d $home $user_name
5612 error_noexit "inconsistent user ID:" \
5613 "new: $user_id, old: $uid"
5618 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5625 check_runas_id_ret() {
5627 local myRUNAS_UID=$1
5628 local myRUNAS_GID=$2
5631 if [ -z "$myRUNAS" ]; then
5632 error_exit "myRUNAS command must be specified for check_runas_id"
5635 $myRUNAS krb5_login.sh || \
5636 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5638 mkdir $DIR/d0_runas_test
5640 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5641 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5642 rm -rf $DIR/d0_runas_test
5647 local myRUNAS_UID=$1
5648 local myRUNAS_GID=$2
5651 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5652 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5653 Please set RUNAS_ID to some UID which exists on MDS and client or
5654 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5657 # obtain the UID/GID for MPI_USER
5661 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5662 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5664 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5665 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5668 # obtain and cache Kerberos ticket-granting ticket
5669 refresh_krb5_tgt() {
5670 local myRUNAS_UID=$1
5671 local myRUNAS_GID=$2
5674 if [ -z "$myRUNAS" ]; then
5675 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5678 CLIENTS=${CLIENTS:-$HOSTNAME}
5679 do_nodes $CLIENTS "set -x
5680 if ! $myRUNAS krb5_login.sh; then
5681 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5686 # Run multiop in the background, but wait for it to print
5687 # "PAUSING" to its stdout before returning from this function.
5688 multiop_bg_pause() {
5689 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5693 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5696 echo "$MULTIOP_PROG $FILE v$ARGS"
5697 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5699 echo "TMPPIPE=${TMPPIPE}"
5700 read -t 60 multiop_output < $TMPPIPE
5701 if [ $? -ne 0 ]; then
5706 if [ "$multiop_output" != "PAUSING" ]; then
5707 echo "Incorrect multiop output: $multiop_output"
5722 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5728 inodes_available () {
5729 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5730 sort -un | head -n1) || return 1
5734 mdsrate_inodes_available () {
5735 local min_inodes=$(inodes_available)
5736 echo $((min_inodes * 99 / 100))
5739 # reset llite stat counters
5740 clear_llite_stats(){
5741 lctl set_param -n llite.*.stats 0
5744 # sum llite stat items
5745 calc_llite_stats() {
5746 local res=$(lctl get_param -n llite.*.stats |
5747 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5751 # reset osc stat counters
5753 lctl set_param -n osc.*.osc_stats 0
5756 # sum osc stat items
5758 local res=$(lctl get_param -n osc.*.osc_stats |
5759 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5764 awk '{sum += $1} END { printf("%0.0f", sum) }'
5767 calc_osc_kbytes () {
5768 df $MOUNT > /dev/null
5769 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5772 # save_lustre_params(comma separated facet list, parameter_mask)
5773 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5774 save_lustre_params() {
5780 for facet in ${facets//,/ }; do
5781 node=$(facet_active_host $facet)
5782 [[ *\ $node\ * = " $nodes " ]] && continue
5783 nodes="$nodes $node"
5785 do_node $node "$LCTL get_param $2 |
5786 while read s; do echo $facet \\\$s; done"
5790 # restore lustre parameters from input stream, produces by save_lustre_params
5791 restore_lustre_params() {
5796 while IFS=" =" read facet name val; do
5797 do_facet $facet "$LCTL set_param -n $name $val"
5801 check_node_health() {
5802 local nodes=${1:-$(comma_list $(nodes_list))}
5804 for node in ${nodes//,/ }; do
5805 check_network "$node" 5
5806 if [ $? -eq 0 ]; then
5807 do_node $node "rc=0;
5808 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5809 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5810 echo \\\$(hostname -s): \\\$val;
5813 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5818 mdsrate_cleanup () {
5820 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5821 --nfiles $3 --dir $4 --filefmt $5 $6
5826 delayed_recovery_enabled () {
5827 local var=${SINGLEMDS}_svc
5828 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5831 ########################
5833 convert_facet2label() {
5836 if [ x$facet = xost ]; then
5840 local varsvc=${facet}_svc
5842 if [ -n ${!varsvc} ]; then
5845 error "No lablel for $facet!"
5849 get_clientosc_proc_path() {
5853 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5854 # used by MDT would not be changed.
5855 # mdt lov: fsname-mdtlov
5856 # mdt osc: fsname-OSTXXXX-osc
5857 mds_on_old_device() {
5858 local mds=${1:-"$SINGLEMDS"}
5860 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5861 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5862 > /dev/null 2>&1" && return 0
5867 get_mdtosc_proc_path() {
5869 local ost_label=${2:-"*OST*"}
5871 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5872 local mdt_label=$(convert_facet2label $mds_facet)
5873 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5875 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5876 mds_on_old_device $mds_facet; then
5877 echo "${ost_label}-osc"
5878 elif [[ $ost_label = *OST* ]]; then
5879 echo "${ost_label}-osc-${mdt_index}"
5881 echo "${ost_label}-osp-${mdt_index}"
5885 get_osc_import_name() {
5888 local label=$(convert_facet2label $ost)
5890 if [ "${facet:0:3}" = "mds" ]; then
5891 get_mdtosc_proc_path $facet $label
5895 get_clientosc_proc_path $label
5899 _wait_import_state () {
5902 local maxtime=${3:-$(max_recovery_time)}
5903 local error_on_failure=${4:-1}
5907 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5908 while [ "${CONN_STATE}" != "${expected}" ]; do
5909 if [ "${expected}" == "DISCONN" ]; then
5910 # for disconn we can check after proc entry is removed
5911 [ "x${CONN_STATE}" == "x" ] && return 0
5912 # with AT enabled, we can have connect request timeout near of
5913 # reconnect timeout and test can't see real disconnect
5914 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5916 if [ $i -ge $maxtime ]; then
5917 [ $error_on_failure -ne 0 ] && \
5918 error "can't put import for $CONN_PROC into ${expected}" \
5919 "state after $i sec, have ${CONN_STATE}"
5923 # Add uniq for multi-mount case
5924 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5928 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5932 wait_import_state() {
5935 local maxtime=${3:-$(max_recovery_time)}
5936 local error_on_failure=${4:-1}
5939 for param in ${params//,/ }; do
5940 _wait_import_state $state $param $maxtime $error_on_failure || return
5944 wait_import_state_mount() {
5945 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5949 wait_import_state $*
5952 # One client request could be timed out because server was not ready
5953 # when request was sent by client.
5954 # The request timeout calculation details :
5956 # /* We give the server rq_timeout secs to process the req, and
5957 # add the network latency for our local timeout. */
5958 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5959 # ptlrpc_at_get_net_latency(request) ;
5961 # ptlrpc_connect_import ()
5962 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5965 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5966 # ptlrpc_at_get_net_latency(request) ->
5967 # at_get (max (iat_net_latency=0, at_min)) = at_min
5970 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5971 # INITIAL_CONNECT_TIMEOUT + at_min
5973 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5974 # because we can not get this value in runtime,
5975 # the value depends on configure options, and it is not stored in /proc.
5977 # #define CONNECTION_SWITCH_MIN 5U
5978 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5980 request_timeout () {
5983 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5984 local init_connect_timeout=$TIMEOUT
5985 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5987 local at_min=$(at_get $facet at_min)
5989 echo $(( init_connect_timeout + at_min ))
5992 _wait_osc_import_state() {
5996 local target=$(get_osc_import_name $facet $ost_facet)
5997 local param="osc.${target}.ost_server_uuid"
6001 # 1. wait the deadline of client 1st request (it could be skipped)
6002 # 2. wait the deadline of client 2nd request
6003 local maxtime=$(( 2 * $(request_timeout $facet)))
6005 if [[ $facet == client* ]]; then
6006 # During setup time, the osc might not be setup, it need wait
6007 # until list_param can return valid value. And also if there
6008 # are mulitple osc entries we should list all of them before
6010 params=$($LCTL list_param $param 2>/dev/null || true)
6011 while [ -z "$params" ]; do
6012 if [ $i -ge $maxtime ]; then
6013 echo "can't get $param in $maxtime secs"
6018 params=$($LCTL list_param $param 2>/dev/null || true)
6022 if [[ $ost_facet = mds* ]]; then
6023 # no OSP connection to itself
6024 if [[ $facet = $ost_facet ]]; then
6027 param="osp.${target}.mdt_server_uuid"
6031 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6032 wait_import_state $expected "$params" $maxtime; then
6033 error "import is not in ${expected} state"
6040 wait_osc_import_state() {
6046 if [[ $facet = mds ]]; then
6047 for num in $(seq $MDSCOUNT); do
6048 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6051 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6055 _wait_mgc_import_state() {
6058 local error_on_failure=${3:-1}
6059 local param="mgc.*.mgs_server_uuid"
6063 # 1. wait the deadline of client 1st request (it could be skipped)
6064 # 2. wait the deadline of client 2nd request
6065 local maxtime=$(( 2 * $(request_timeout $facet)))
6067 if [[ $facet == client* ]]; then
6068 # During setup time, the osc might not be setup, it need wait
6069 # until list_param can return valid value. And also if there
6070 # are mulitple osc entries we should list all of them before
6072 params=$($LCTL list_param $param 2>/dev/null || true)
6073 while [ -z "$params" ]; do
6074 if [ $i -ge $maxtime ]; then
6075 echo "can't get $param in $maxtime secs"
6080 params=$($LCTL list_param $param 2>/dev/null || true)
6083 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6084 wait_import_state $expected "$params" $maxtime \
6085 $error_on_failure; then
6086 if [ $error_on_failure -ne 0 ]; then
6087 error "import is not in ${expected} state"
6095 wait_mgc_import_state() {
6098 local error_on_failure=${3:-1}
6101 if [[ $facet = mds ]]; then
6102 for num in $(seq $MDSCOUNT); do
6103 _wait_mgc_import_state mds$num "$expected" \
6104 $error_on_failure || return
6107 _wait_mgc_import_state "$facet" "$expected"
6108 $error_on_failure || return
6112 wait_dne_interconnect() {
6115 if [ $MDSCOUNT -gt 1 ]; then
6116 for num in $(seq $MDSCOUNT); do
6117 wait_osc_import_state mds mds$num FULL
6122 get_clientmdc_proc_path() {
6126 get_clientmgc_proc_path() {
6134 [ -z "$list" ] && return 0
6136 # Add paths to lustre tests for 32 and 64 bit systems.
6137 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6138 local TESTPATH="$RLUSTRE/tests:"
6139 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6140 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6143 wait_clients_import_state () {
6150 if [ "$FAILURE_MODE" = HARD ]; then
6151 facets=$(facets_on_host $(facet_active_host $facet))
6154 for facet in ${facets//,/ }; do
6155 local label=$(convert_facet2label $facet)
6158 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6159 $label).ost_server_uuid" ;;
6160 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6161 $label).mds_server_uuid" ;;
6162 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6163 $label).mgs_server_uuid" ;;
6164 *) error "unknown facet!" ;;
6167 local params=$(expand_list $params $proc_path)
6170 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6172 error "import is not in ${expected} state"
6182 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6183 $LCTL get_param obdfilter.*.kbytesavail))
6184 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6185 $LCTL get_param -n obdfilter.*.tot_granted))
6186 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6187 $LCTL get_param -n obdfilter.*.kbytestotal))
6188 for ((i=0; i<${#AVAILA[@]}; i++)); do
6189 local -a AVAIL1=(${AVAILA[$i]//=/ })
6190 local -a TOTAL=(${TOTALA[$i]//=/ })
6191 GRANT=$((${GRANTA[$i]}/1024))
6192 # allow 1% of total space in bavail because of delayed
6193 # allocation with ZFS which might release some free space after
6194 # txg commit. For small devices, we set a mininum of 8MB
6195 local LIMIT=$((${TOTAL} / 100 + 8000))
6196 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6197 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6198 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6199 echo " FULL" || echo
6205 do_facet mgs lctl pool_list $1
6209 local fsname=${1%%.*}
6210 local poolname=${1##$fsname.}
6212 do_facet mgs lctl pool_new $1
6214 # get param should return err unless pool is created
6215 [[ $RC -ne 0 ]] && return $RC
6217 for mds_id in $(seq $MDSCOUNT); do
6218 local mdt_id=$((mds_id-1))
6219 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6220 wait_update_facet mds$mds_id \
6221 "lctl get_param -n lod.$lodname.pools.$poolname \
6222 2>/dev/null || echo foo" "" ||
6223 error "mds$mds_id: pool_new failed $1"
6225 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6226 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6232 add_pool_to_list () {
6233 local fsname=${1%%.*}
6234 local poolname=${1##$fsname.}
6236 local listvar=${fsname}_CREATED_POOLS
6237 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6241 remove_pool_from_list () {
6242 local fsname=${1%%.*}
6243 local poolname=${1##$fsname.}
6245 local listvar=${fsname}_CREATED_POOLS
6246 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6250 destroy_pool_int() {
6252 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6253 awk '$1 !~ /^Pool:/ {print $1}')
6254 for ost in $OSTS; do
6255 do_facet mgs lctl pool_remove $1 $ost
6257 do_facet mgs lctl pool_destroy $1
6260 # <fsname>.<poolname> or <poolname>
6262 local fsname=${1%%.*}
6263 local poolname=${1##$fsname.}
6265 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6269 pool_list $fsname.$poolname || return $?
6271 destroy_pool_int $fsname.$poolname
6273 [[ $RC -ne 0 ]] && return $RC
6274 for mds_id in $(seq $MDSCOUNT); do
6275 local mdt_id=$((mds_id-1))
6276 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6277 wait_update_facet mds$mds_id \
6278 "lctl get_param -n lod.$lodname.pools.$poolname \
6279 2>/dev/null || echo foo" "foo" ||
6280 error "mds$mds_id: destroy pool failed $1"
6282 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6283 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6285 remove_pool_from_list $fsname.$poolname
6290 local fsname=${1:-$FSNAME}
6292 local listvar=${fsname}_CREATED_POOLS
6296 [ x${!listvar} = x ] && return 0
6298 echo destroy the created pools: ${!listvar}
6299 for poolname in ${!listvar//,/ }; do
6300 destroy_pool $fsname.$poolname
6305 local fsname=${1:-$FSNAME}
6307 destroy_pools $fsname
6313 local ts=$(date +%s)
6316 if [[ ! -f "$YAML_LOG" ]]; then
6317 # init_logging is not performed before gather_logs,
6318 # so the $LOGDIR needs to be checked here
6319 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6322 [ -f $LOGDIR/shared ] && docp=false
6324 # dump lustre logs, dmesg
6326 prefix="$TESTLOG_PREFIX.$TESTNAME"
6328 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6330 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6331 echo "Dumping logs only on local client."
6332 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6333 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6338 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6339 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6340 if [ ! -f $LOGDIR/shared ]; then
6341 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6354 for i in $(seq 0 $num_mntpts); do
6355 cmd="ls -laf ${mntpt_root}$i/$dir"
6361 for pid in $pids; do
6368 # check_and_start_recovery_timer()
6369 # service_time = at_est2timeout(service_time);
6370 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6371 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6373 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6374 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6375 #define CONNECTION_SWITCH_MIN 5
6376 #define CONNECTION_SWITCH_INC 5
6377 max_recovery_time() {
6378 local init_connect_timeout=$((TIMEOUT / 20))
6379 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6381 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6382 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6384 echo -n $service_time
6387 recovery_time_min() {
6388 local connection_switch_min=5
6389 local connection_switch_inc=5
6390 local connection_switch_max
6391 local reconnect_delay_max
6392 local initial_connect_timeout
6396 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6397 (($connection_switch_min > $TIMEOUT)) &&
6398 max=$connection_switch_min || max=$TIMEOUT
6399 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6401 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6402 timeout_20=$((TIMEOUT/20))
6403 (($connection_switch_min > $timeout_20)) &&
6404 initial_connect_timeout=$connection_switch_min ||
6405 initial_connect_timeout=$timeout_20
6407 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6408 initial_connect_timeout))
6409 echo $((2 * reconnect_delay_max))
6412 get_clients_mount_count () {
6413 local clients=${CLIENTS:-`hostname`}
6415 # we need to take into account the clients mounts and
6416 # exclude mds/ost mounts if any;
6417 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6421 PROC_CLI="srpc_info"
6429 if [ $M -lt $N ]; then
6433 while [ $N -lt $M ]; do
6443 calc_connection_cnt() {
6446 # MDT->MDT = 2 * C(M, 2)
6450 comb_m2=$(combination $MDSCOUNT 2)
6452 local num_clients=$(get_clients_mount_count)
6454 local cnt_mdt2mdt=$((comb_m2 * 2))
6455 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6456 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6457 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6458 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6459 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6460 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6474 local cmd="$tgt.srpc.flavor"
6476 if [ $net == "any" ]; then
6481 if [ $dir != "any" ]; then
6486 log "Setting sptlrpc rule: $cmd"
6487 do_facet mgs "$LCTL conf_param $cmd"
6496 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6497 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6499 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6501 if [ "x$bulkspec" != "x" ]; then
6502 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6504 if [ "x$algs" != "x" ]; then
6505 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6507 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6508 if [ $bulk == "bulkn" ]; then
6509 bulk_count=`echo "$output" | grep "bulk flavor" \
6510 | grep "null/null" | wc -l`
6511 elif [ $bulk == "bulki" ]; then
6512 bulk_count=`echo "$output" | grep "bulk flavor" \
6513 | grep "/null" | grep -v "null/" | wc -l`
6515 bulk_count=`echo "$output" | grep "bulk flavor" \
6516 | grep -v "/null" | grep -v "null/" | wc -l`
6520 [ $bulk_count -lt $count ] && count=$bulk_count
6531 local clients=${CLIENTS:-`hostname`}
6533 for c in ${clients//,/ }; do
6534 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6535 tmpcnt=`count_flvr "$output" $flavor`
6536 cnt=$((cnt + tmpcnt))
6546 local clients=${CLIENTS:-`hostname`}
6548 for c in ${clients//,/ }; do
6549 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6550 tmpcnt=`count_flvr "$output" $flavor`
6551 cnt=$((cnt + tmpcnt))
6561 if [ $MDSCOUNT -le 1 ]; then
6566 for num in `seq $MDSCOUNT`; do
6567 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6568 tmpcnt=`count_flvr "$output" $flavor`
6569 cnt=$((cnt + tmpcnt))
6580 for num in `seq $MDSCOUNT`; do
6581 mdtosc=$(get_mdtosc_proc_path mds$num)
6582 mdtosc=${mdtosc/-MDT*/-MDT\*}
6583 output=$(do_facet mds$num lctl get_param -n \
6584 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6585 tmpcnt=`count_flvr "$output" $flavor`
6586 cnt=$((cnt + tmpcnt))
6595 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6596 count_flvr "$output" $flavor
6601 local dir=$1 # from to
6602 local flavor=$2 # flavor expected
6605 if [ $dir == "cli2mdt" ]; then
6606 res=`flvr_cnt_cli2mdt $flavor`
6607 elif [ $dir == "cli2ost" ]; then
6608 res=`flvr_cnt_cli2ost $flavor`
6609 elif [ $dir == "mdt2mdt" ]; then
6610 res=`flvr_cnt_mdt2mdt $flavor`
6611 elif [ $dir == "mdt2ost" ]; then
6612 res=`flvr_cnt_mdt2ost $flavor`
6613 elif [ $dir == "all2ost" ]; then
6614 res1=`flvr_cnt_mdt2ost $flavor`
6615 res2=`flvr_cnt_cli2ost $flavor`
6616 res=$((res1 + res2))
6617 elif [ $dir == "all2mdt" ]; then
6618 res1=`flvr_cnt_mdt2mdt $flavor`
6619 res2=`flvr_cnt_cli2mdt $flavor`
6620 res=$((res1 + res2))
6621 elif [ $dir == "all2all" ]; then
6622 res1=`flvr_cnt_mdt2ost $flavor`
6623 res2=`flvr_cnt_cli2ost $flavor`
6624 res3=`flvr_cnt_mdt2mdt $flavor`
6625 res4=`flvr_cnt_cli2mdt $flavor`
6626 res=$((res1 + res2 + res3 + res4))
6634 local dir=$1 # from to
6635 local flavor=$2 # flavor expected
6636 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6640 for ((i=0;i<20;i++)); do
6641 echo -n "checking $dir..."
6642 res=$(do_check_flavor $dir $flavor)
6643 echo "found $res/$expect $flavor connections"
6644 [ $res -ge $expect ] && return 0
6648 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6652 restore_to_default_flavor()
6654 local proc="mgs.MGS.live.$FSNAME"
6656 echo "restoring to default flavor..."
6658 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6660 # remove all existing rules if any
6661 if [ $nrule -ne 0 ]; then
6662 echo "$nrule existing rules"
6663 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6664 echo "remove rule: $rule"
6665 spec=`echo $rule | awk -F = '{print $1}'`
6666 do_facet mgs "$LCTL conf_param -d $spec"
6670 # verify no rules left
6671 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6672 [ $nrule -ne 0 ] && error "still $nrule rules left"
6674 # wait for default flavor to be applied
6675 # currently default flavor for all connections are 'null'
6676 wait_flavor all2all null
6677 echo "now at default flavor settings"
6682 local flavor=${1:-null}
6684 echo "setting all flavor to $flavor"
6686 # FIXME need parameter to this fn
6687 # and remove global vars
6688 local cnt_all2all=$(calc_connection_cnt all2all)
6690 local res=$(do_check_flavor all2all $flavor)
6691 if [ $res -eq $cnt_all2all ]; then
6692 echo "already have total $res $flavor connections"
6696 echo "found $res $flavor out of total $cnt_all2all connections"
6697 restore_to_default_flavor
6699 [[ $flavor = null ]] && return 0
6701 set_rule $FSNAME any any $flavor
6702 wait_flavor all2all $flavor
6708 # Checking for shared logdir
6709 if [ ! -d $dir ]; then
6710 # Not found. Create local logdir
6713 touch $dir/check_file.$(hostname -s)
6718 check_write_access() {
6720 local list=${2:-$(comma_list $(nodes_list))}
6724 for node in ${list//,/ }; do
6725 file=$dir/check_file.$(short_nodename $node)
6726 if [[ ! -f "$file" ]]; then
6727 # Logdir not accessible/writable from this node.
6730 rm -f $file || return 1
6736 [[ -n $YAML_LOG ]] && return
6737 local save_umask=$(umask)
6740 export YAML_LOG=${LOGDIR}/results.yml
6744 # If the yaml log already exists then we will just append to it
6745 if [ ! -f $YAML_LOG ]; then
6746 if check_shared_dir $LOGDIR; then
6747 touch $LOGDIR/shared
6748 echo "Logging to shared log directory: $LOGDIR"
6750 echo "Logging to local directory: $LOGDIR"
6753 yml_nodes_file $LOGDIR >> $YAML_LOG
6754 yml_results_file >> $YAML_LOG
6759 # If modules are not yet loaded then older "lctl lustre_build_version"
6760 # will fail. Use lctl build version instead.
6761 log "Client: $($LCTL lustre_build_version)"
6762 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6763 do_facet $SINGLEMDS $LCTL --version)"
6764 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6765 do_facet ost1 $LCTL --version)"
6769 yml_log_test $1 >> $YAML_LOG
6773 yml_log_test_status $@ >> $YAML_LOG
6776 log_sub_test_begin() {
6777 yml_log_sub_test_begin "$@" >> $YAML_LOG
6780 log_sub_test_end() {
6781 yml_log_sub_test_end "$@" >> $YAML_LOG
6787 local llverdev_opts=$2
6788 local devname=$(basename $1)
6789 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6790 # loop devices aren't in /proc/partitions
6791 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6793 size=$(($size / 1024 / 1024)) # Gb
6795 local partial_arg=""
6796 # Run in partial (fast) mode if the size
6797 # of a partition > 1 GB
6798 [ $size -gt 1 ] && partial_arg="-p"
6800 llverdev --force $partial_arg $llverdev_opts $dev
6806 local llverfs_opts=$2
6807 local use_partial_arg=$3
6808 local partial_arg=""
6809 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6811 # Run in partial (fast) mode if the size
6812 # of a partition > 1 GB
6813 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6815 llverfs $partial_arg $llverfs_opts $dir
6818 #Remove objects from OST
6819 remove_ost_objects() {
6825 local mntpt=$(facet_mntpt $facet)
6826 local opts=$OST_MOUNT_OPTS
6830 echo "removing objects from $ostdev on $facet: $objids"
6831 if ! test -b $ostdev; then
6832 opts=$(csa_add "$opts" -o loop)
6834 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6837 for i in $objids; do
6838 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6840 umount -f $mntpt || return $?
6844 #Remove files from MDT
6845 remove_mdt_files() {
6850 local mntpt=$(facet_mntpt $facet)
6851 local opts=$MDS_MOUNT_OPTS
6853 echo "removing files from $mdtdev on $facet: $files"
6854 if [ $(facet_fstype $facet) == ldiskfs ] &&
6855 ! do_facet $facet test -b $mdtdev; then
6856 opts=$(csa_add "$opts" -o loop)
6858 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6862 rm $mntpt/ROOT/$f || { rc=$?; break; }
6864 umount -f $mntpt || return $?
6868 duplicate_mdt_files() {
6873 local mntpt=$(facet_mntpt $facet)
6874 local opts=$MDS_MOUNT_OPTS
6876 echo "duplicating files on $mdtdev on $facet: $files"
6877 mkdir -p $mntpt || return $?
6878 if [ $(facet_fstype $facet) == ldiskfs ] &&
6879 ! do_facet $facet test -b $mdtdev; then
6880 opts=$(csa_add "$opts" -o loop)
6882 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6893 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6894 pushd $mntpt/ROOT > /dev/null || return $?
6897 touch $f.bad || return $?
6898 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6900 [ $rc -eq 0 ] || return $rc
6901 setfattr --restore $tmp || return $?
6907 local devs=${1//,/ }
6910 local rslt=$TMP/sgpdd_survey
6912 # sgpdd-survey cleanups ${rslt}.* files
6914 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6920 # returns the canonical name for an ldiskfs device
6925 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6926 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6927 echo dm-\\\${foo##*:};
6929 echo \\\$(basename \\\$dv);
6933 is_sanity_benchmark() {
6934 local benchmarks="dbench bonnie iozone fsx"
6936 for b in $benchmarks; do
6937 if [ "$b" == "$suite" ]; then
6945 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6949 # Get the available size (KB) of a given obd target.
6956 [[ $facet != client ]] || return 0
6958 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6963 # Get the page size (bytes) on a given facet node.
6967 local size=$(getconf PAGE_SIZE 2>/dev/null)
6969 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
6970 echo -n ${size:-4096}
6974 # Get the block count of the filesystem.
6981 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6982 awk '/^Block count:/ {print $3}')
6986 # Get the block size of the filesystem.
6992 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6993 awk '/^Block size:/ {print $3}')
6997 # Check whether the "large_xattr" feature is enabled or not.
6998 large_xattr_enabled() {
6999 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7001 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7003 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7004 grep -E -q '(ea_inode|large_xattr)'"
7005 return ${PIPESTATUS[0]}
7008 # Get the maximum xattr size supported by the filesystem.
7012 if large_xattr_enabled; then
7013 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7016 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7017 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7019 # maximum xattr size = size of block - size of header -
7020 # size of 1 entry - 4 null bytes
7021 size=$((block_size - 32 - 32 - 4))
7027 # Dump the value of the named xattr from a file.
7032 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7035 # Generate a string with size of $size bytes.
7037 local size=${1:-1024} # in bytes
7039 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7042 reformat_external_journal() {
7047 if [ -n "${!var}" ]; then
7048 local rcmd="do_facet $facet"
7050 echo "reformat external journal on $facet:${!var}"
7051 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7055 # MDT file-level backup/restore
7056 mds_backup_restore() {
7059 local devname=$(mdsdevname $(facet_number $facet))
7060 local mntpt=$(facet_mntpt brpt)
7061 local rcmd="do_facet $facet"
7062 local metaea=${TMP}/backup_restore.ea
7063 local metadata=${TMP}/backup_restore.tgz
7064 local opts=${MDS_MOUNT_OPTS}
7065 local svc=${facet}_svc
7067 if ! ${rcmd} test -b ${devname}; then
7068 opts=$(csa_add "$opts" -o loop)
7071 echo "file-level backup/restore on $facet:${devname}"
7073 # step 1: build mount point
7074 ${rcmd} mkdir -p $mntpt
7075 # step 2: cleanup old backup
7076 ${rcmd} rm -f $metaea $metadata
7078 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7079 if [ ! -z $igif ]; then
7080 # step 3.5: rm .lustre
7081 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7083 # step 4: backup metaea
7085 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7087 # step 5: backup metadata
7089 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7091 ${rcmd} $UMOUNT $mntpt || return 4
7092 # step 8: reformat dev
7093 echo "reformat new device"
7094 format_mdt $(facet_number $facet)
7096 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7097 # step 10: restore metadata
7099 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7100 # step 11: restore metaea
7102 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7103 # step 12: remove recovery logs
7104 echo "remove recovery logs"
7105 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7106 # step 13: umount dev
7107 ${rcmd} $UMOUNT $mntpt || return 10
7108 # step 14: cleanup tmp backup
7109 ${rcmd} rm -f $metaea $metadata
7110 # step 15: reset device label - it's not virgin on
7111 ${rcmd} e2label $devname ${!svc}
7118 local devname=$(mdsdevname $(facet_number $facet))
7119 local mntpt=$(facet_mntpt brpt)
7120 local rcmd="do_facet $facet"
7121 local opts=${MDS_MOUNT_OPTS}
7123 if ! ${rcmd} test -b ${devname}; then
7124 opts=$(csa_add "$opts" -o loop)
7127 echo "removing OI files on $facet: idx=${idx}"
7129 # step 1: build mount point
7130 ${rcmd} mkdir -p $mntpt
7132 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7133 if [ -z $idx ]; then
7134 # step 3: remove all OI files
7135 ${rcmd} rm -fv $mntpt/oi.16*
7136 elif [ $idx -lt 2 ]; then
7137 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7141 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7142 for ((i=${idx}; i<64; i=$((i * idx)))); do
7143 ${rcmd} rm -fv $mntpt/oi.16.${i}
7147 ${rcmd} $UMOUNT $mntpt || return 2
7148 # OI files will be recreated when mounted as lustre next time.
7151 # generate maloo upload-able log file name
7152 # \param logname specify unique part of file name
7153 generate_logname() {
7154 local logname=${1:-"default_logname"}
7156 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7159 # make directory on different MDTs
7163 local stripe_count=2
7164 local stripe_index=-1
7167 while getopts "c:i:p" opt; do
7169 c) stripe_count=$OPTARG;;
7170 i) stripe_index=$OPTARG;;
7172 \?) error "only support -i -c -p";;
7176 shift $((OPTIND - 1))
7177 [ $# -eq 1 ] || error "Only creating single directory is supported"
7180 if [ "$p_option" == "-p" ]; then
7181 local parent=$(dirname $path)
7183 [ -d $path ] && return 0
7184 [ ! -d ${parent} ] && mkdir -p ${parent}
7187 if [ $MDSCOUNT -le 1 ]; then
7190 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7193 if [ $stripe_index -eq -1 ]; then
7194 mdt_index=$((test_num % MDSCOUNT))
7196 mdt_index=$stripe_index
7198 echo "striped dir -i$mdt_index -c$stripe_count $path"
7199 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7203 # find the smallest and not in use file descriptor
7206 local max_fd=$(ulimit -n)
7208 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7211 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7215 check_mount_and_prep()
7217 is_mounted $MOUNT || setupall
7219 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7220 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7221 for idx in $(seq $MDSCOUNT); do
7222 local name="MDT$(printf '%04x' $((idx - 1)))"
7223 rm -rf $MOUNT/.lustre/lost+found/$name/*
7227 # calcule how many ost-objects to be created.
7228 precreated_ost_obj_count()
7232 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7233 local ost_name="OST$(printf '%04x' $ost_idx)"
7234 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7235 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7236 osp.$proc_path.prealloc_last_id)
7237 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7238 osp.$proc_path.prealloc_next_id)
7239 echo $((last_id - next_id + 1))
7242 check_file_in_pool()
7247 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7250 for t in $tlist ; do
7251 [ "$i" -eq "$t" ] && continue 2
7254 echo "pool list: $tlist"
7255 echo "striping: $res"
7256 error_noexit "$file not allocated in $pool"
7263 echo "Creating new pool"
7266 create_pool $FSNAME.$pool ||
7267 { error_noexit "No pool created, result code $?"; return 1; }
7268 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7269 { error_noexit "$pool not in lfs pool_list"; return 2; }
7272 pool_add_targets() {
7273 echo "Adding targets to pool"
7279 local list=$(seq $first $step $last)
7281 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7282 do_facet mgs $LCTL pool_add \
7283 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7285 # wait for OSTs to be added to the pool
7286 for mds_id in $(seq $MDSCOUNT); do
7287 local mdt_id=$((mds_id-1))
7288 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7289 wait_update_facet mds$mds_id \
7290 "lctl get_param -n lod.$lodname.pools.$pool |
7291 sort -u | tr '\n' ' ' " "$t" || {
7292 error_noexit "mds$mds_id: Add to pool failed"
7296 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7297 | sort -u | tr '\n' ' ' " "$t" || {
7298 error_noexit "Add to pool failed"
7301 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7302 local addcount=$(((last - first) / step + 1))
7303 [ $lfscount -eq $addcount ] || {
7304 error_noexit "lfs pool_list bad ost count" \
7305 "$lfscount != $addcount"
7313 echo "Setting pool on directory $tdir"
7315 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7317 error_noexit "Cannot set pool $pool to $tdir"
7324 echo "Checking pool on directory $tdir"
7326 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7327 [ "$res" = "$pool" ] && return 0
7329 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7333 pool_dir_rel_path() {
7334 echo "Testing relative path works well"
7339 mkdir -p $root/$tdir/$tdir
7341 pool_set_dir $pool $tdir || return 1
7342 pool_set_dir $pool ./$tdir || return 2
7343 pool_set_dir $pool ../$tdir || return 3
7344 pool_set_dir $pool ../$tdir/$tdir || return 4
7345 rm -rf $tdir; cd - > /dev/null
7348 pool_alloc_files() {
7349 echo "Checking files allocation from directory pool"
7356 for i in $(seq -w 1 $count)
7358 local file=$tdir/file-$i
7360 check_file_in_pool $file $pool "$tlist" || \
7361 failed=$((failed + 1))
7363 [ "$failed" = 0 ] && return 0
7365 error_noexit "$failed files not allocated in $pool"
7369 pool_create_files() {
7370 echo "Creating files in pool"
7378 for i in $(seq -w 1 $count)
7380 local file=$tdir/spoo-$i
7381 $SETSTRIPE -p $pool $file
7382 check_file_in_pool $file $pool "$tlist" || \
7383 failed=$((failed + 1))
7385 [ "$failed" = 0 ] && return 0
7387 error_noexit "$failed files not allocated in $pool"
7392 echo "Checking 'lfs df' output"
7395 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7397 local res=$($LFS df --pool $FSNAME.$pool |
7399 grep "$FSNAME-OST" |
7401 [ "$res" = "$t" ] && return 0
7403 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7407 pool_file_rel_path() {
7408 echo "Creating files in a pool with relative pathname"
7413 { error_noexit "unable to create $tdir"; return 1 ; }
7414 local file="/..$tdir/$tfile-1"
7415 $SETSTRIPE -p $pool $file ||
7416 { error_noexit "unable to create $file" ; return 2 ; }
7419 $SETSTRIPE -p $pool $tfile-2 || {
7420 error_noexit "unable to create $tfile-2 in $tdir"
7425 pool_remove_first_target() {
7426 echo "Removing first target from a pool"
7429 local pname="lov.$FSNAME-*.pools.$pool"
7430 local t=$($LCTL get_param -n $pname | head -1)
7431 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7432 for mds_id in $(seq $MDSCOUNT); do
7433 local mdt_id=$((mds_id-1))
7434 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7435 wait_update_facet mds$mds_id \
7436 "lctl get_param -n lod.$lodname.pools.$pool |
7438 error_noexit "mds$mds_id: $t not removed from" \
7443 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7444 error_noexit "$t not removed from $FSNAME.$pool"
7449 pool_remove_all_targets() {
7450 echo "Removing all targets from pool"
7453 local pname="lov.$FSNAME-*.pools.$pool"
7454 for t in $($LCTL get_param -n $pname | sort -u)
7456 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7458 for mds_id in $(seq $MDSCOUNT); do
7459 local mdt_id=$((mds_id-1))
7460 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7461 wait_update_facet mds$mds_id "lctl get_param -n \
7462 lod.$lodname.pools.$pool" "" || {
7463 error_noexit "mds$mds_id: Pool $pool not drained"
7467 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7468 error_noexit "Pool $FSNAME.$pool cannot be drained"
7471 # striping on an empty/nonexistant pool should fall back
7472 # to "pool of everything"
7474 error_noexit "failed to use fallback striping for empty pool"
7477 # setstripe on an empty pool should fail
7478 $SETSTRIPE -p $pool $file 2>/dev/null && {
7479 error_noexit "expected failure when creating file" \
7487 echo "Destroying pool"
7491 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7494 # striping on an empty/nonexistant pool should fall back
7495 # to "pool of everything"
7497 error_noexit "failed to use fallback striping for missing pool"
7500 # setstripe on an empty pool should fail
7501 $SETSTRIPE -p $pool $file 2>/dev/null && {
7502 error_noexit "expected failure when creating file" \
7507 # get param should return err once pool is gone
7508 if wait_update $HOSTNAME "lctl get_param -n \
7509 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7511 remove_pool_from_list $FSNAME.$pool
7514 error_noexit "Pool $FSNAME.$pool is not destroyed"
7518 # Get and check the actual stripe count of one file.
7519 # Usage: check_stripe_count <file> <expected_stripe_count>
7520 check_stripe_count() {
7525 [[ -z "$file" || -z "$expected" ]] &&
7526 error "check_stripe_count: invalid argument"
7528 local cmd="$GETSTRIPE -c $file"
7529 actual=$($cmd) || error "$cmd failed"
7530 actual=${actual%% *}
7532 if [[ $actual -ne $expected ]]; then
7533 [[ $expected -eq -1 ]] ||
7534 error "$cmd wrong: found $actual, expected $expected"
7535 [[ $actual -eq $OSTCOUNT ]] ||
7536 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7540 # Get and check the actual list of OST indices on one file.
7541 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7547 [[ -z "$file" || -z "$expected" ]] &&
7548 error "check_obdidx: invalid argument!"
7550 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7551 grep -v obdidx | awk '{print $1}' | xargs))
7553 [[ $obdidx = $expected ]] ||
7554 error "list of OST indices on $file is $obdidx," \
7555 "should be $expected"
7558 # Get and check the actual OST index of the first stripe on one file.
7559 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7560 check_start_ost_idx() {
7565 [[ -z "$file" || -z "$expected" ]] &&
7566 error "check_start_ost_idx: invalid argument!"
7568 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7571 [[ $start_ost_idx = $expected ]] ||
7572 error "OST index of the first stripe on $file is" \
7573 "$start_ost_idx, should be $expected"
7576 killall_process () {
7577 local clients=${1:-$(hostname)}
7582 do_nodes $clients "killall $signal $name"