3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
18 # specify environment variable containing batch job name for server statistics
19 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
21 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
22 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
23 export LOAD_LLOOP=${LOAD_LLOOP:-false}
25 #export PDSH="pdsh -S -Rssh -w"
26 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
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
55 [[ $DIR/ = $MOUNT/* ]] || \
56 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
57 [[ $DIR1/ = $MOUNT1/* ]] || \
58 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
59 [[ $DIR2/ = $MOUNT2/* ]] || \
60 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
62 [ -n "$failed" ] && exit 99 || true
66 echo "usage: $0 [-r] [-f cfgfile]"
74 [ -z "$DEFAULT_SUITES"] && return 0
75 [ "$TESTSUITE" == "lfsck" ] && return 0
76 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
78 local form="%-13s %-17s %-9s %s %s\n"
79 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
80 echo "------------------------------------------------------------------------------------"
81 for O in $DEFAULT_SUITES; do
82 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
83 [ "${!O}" = "no" ] && continue || true
84 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
85 local log=${TMP}/${o}.log
86 if is_sanity_benchmark $o; then
87 log=${TMP}/sanity-benchmark.log
92 local status=Unfinished
94 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
96 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
97 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
98 total=$(grep duration $log | awk '{ print $2 }')
99 if [ "${!O}" = "done" ]; then
103 local durations=$(egrep "^PASS|^FAIL" $log |
104 tr -d "("| sed s/s\)$//g |
105 awk '{ print $2":"$3"|" }')
106 details=$(printf "%s\n%s %s %s\n" "$details" \
107 "DDETAILS" "$O" "$(echo $durations)")
110 printf "$form" $status "$O" "${total}" "E=$skipped"
111 printf "$form" "-" "-" "-" "S=$(echo $slow)"
114 for O in $DEFAULT_SUITES; do
115 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
116 if [ "${!O}" = "no" ]; then
117 printf "$form" "Skipped" "$O" ""
121 # print the detailed tests durations if DDETAILS=true
128 export LUSTRE=$(absolute_path $LUSTRE)
129 export TESTSUITE=$(basename $0 .sh)
130 export TEST_FAILED=false
131 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
132 export RPC_MODE=${RPC_MODE:-false}
134 export MKE2FS=$MKE2FS
135 if [ -z "$MKE2FS" ]; then
136 if which mkfs.ldiskfs >/dev/null 2>&1; then
137 export MKE2FS=mkfs.ldiskfs
143 export DEBUGFS=$DEBUGFS
144 if [ -z "$DEBUGFS" ]; then
145 if which debugfs.ldiskfs >/dev/null 2>&1; then
146 export DEBUGFS=debugfs.ldiskfs
148 export DEBUGFS=debugfs
152 export TUNE2FS=$TUNE2FS
153 if [ -z "$TUNE2FS" ]; then
154 if which tunefs.ldiskfs >/dev/null 2>&1; then
155 export TUNE2FS=tunefs.ldiskfs
157 export TUNE2FS=tune2fs
161 export E2LABEL=$E2LABEL
162 if [ -z "$E2LABEL" ]; then
163 if which label.ldiskfs >/dev/null 2>&1; then
164 export E2LABEL=label.ldiskfs
166 export E2LABEL=e2label
170 export DUMPE2FS=$DUMPE2FS
171 if [ -z "$DUMPE2FS" ]; then
172 if which dumpfs.ldiskfs >/dev/null 2>&1; then
173 export DUMPE2FS=dumpfs.ldiskfs
175 export DUMPE2FS=dumpe2fs
179 export E2FSCK=$E2FSCK
180 if [ -z "$E2FSCK" ]; then
181 if which fsck.ldiskfs >/dev/null 2>&1; then
182 export E2FSCK=fsck.ldiskfs
188 export RESIZE2FS=$RESIZE2FS
189 if [ -z "$RESIZE2FS" ]; then
190 if which resizefs.ldiskfs >/dev/null 2>&1; then
191 export RESIZE2FS=resizefs.ldiskfs
193 export RESIZE2FS=resize2fs
197 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
198 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
199 export FSCK_MAX_ERR=4 # File system errors left uncorrected
201 export ZFS=${ZFS:-zfs}
202 export ZPOOL=${ZPOOL:-zpool}
203 export ZDB=${ZDB:-zdb}
204 export PARTPROBE=${PARTPROBE:-partprobe}
206 #[ -d /r ] && export ROOT=${ROOT:-/r}
207 export TMP=${TMP:-$ROOT/tmp}
208 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
209 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
210 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
212 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
213 if ! echo $PATH | grep -q $LUSTRE/utils; then
214 export PATH=$LUSTRE/utils:$PATH
216 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
217 export PATH=$LUSTRE/utils/gss:$PATH
219 if ! echo $PATH | grep -q $LUSTRE/tests; then
220 export PATH=$LUSTRE/tests:$PATH
222 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
223 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
225 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
226 [ ! -f "$LST" ] && export LST=$(which lst)
227 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
228 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
229 export MCREATE=${MCREATE:-mcreate}
230 # Ubuntu, at least, has a truncate command in /usr/bin
231 # so fully path our truncate command.
232 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
233 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
234 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
235 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
236 export PATH=$LUSTRE/tests/racer:$PATH:
238 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
239 export PATH=$LUSTRE/tests/mpi:$PATH
241 export RSYNC_RSH=${RSYNC_RSH:-rsh}
243 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
244 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
245 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
246 [ ! -f "$LFS" ] && export LFS=$(which lfs)
247 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
248 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
250 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
251 if [ ! -f "$L_GETIDENTITY" ]; then
252 if `which l_getidentity > /dev/null 2>&1`; then
253 export L_GETIDENTITY=$(which l_getidentity)
255 export L_GETIDENTITY=NONE
258 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
259 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
260 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
261 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
262 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
263 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
264 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
265 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
266 [ ! -f "$LUSTRE_RMMOD" ] &&
267 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
268 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
269 [ ! -f "$LFS_MIGRATE" ] &&
270 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
271 export NAME=${NAME:-local}
272 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
273 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
274 export LGSSD=$(which lgssd)
275 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
276 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
277 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
279 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
282 if [ "$ACCEPTOR_PORT" ]; then
283 export PORT_OPT="--port $ACCEPTOR_PORT"
288 echo "Using GSS/krb5 ptlrpc security flavor"
289 which lgss_keyring > /dev/null 2>&1 || \
290 error_exit "built with gss disabled! SEC=$SEC"
301 IDENTITY_UPCALL=false
305 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
307 # Paths on remote nodes, if different
308 export RLUSTRE=${RLUSTRE:-$LUSTRE}
309 export RPWD=${RPWD:-$PWD}
310 export I_MOUNTED=${I_MOUNTED:-"no"}
311 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
312 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
313 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
314 ! -f $LUSTRE/mdt/mdt.ko ]; then
315 export CLIENTMODSONLY=yes
318 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
319 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
323 while getopts "rvwf:" opt $*; do
326 r) REFORMAT=--reformat;;
328 w) WRITECONF=writeconf;;
333 shift $((OPTIND - 1))
336 # print the durations of each test if "true"
337 DDETAILS=${DDETAILS:-false}
338 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
343 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
350 ncpts=$(do_facet $facet "lctl get_param -n " \
351 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
353 if [ $ncpts -eq 0 ]; then
360 # Return a numeric version code based on a version string. The version
361 # code is useful for comparison two version strings to see which is newer.
363 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
364 eval set -- $(tr "[:punct:]" " " <<< $*)
366 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
369 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
370 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
372 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
374 # usage: lustre_build_version
376 # All Lustre versions support "lctl get_param" to report the version of the
377 # code running in the kernel (what our tests are interested in), but it
378 # doesn't work without modules loaded. If that fails, use "lctl version"
379 # instead, which is easy to parse and works without the kernel modules,
380 # but was only added in 2.6.50. If that also fails, fall back to calling
381 # "lctl lustre_build_version" which prints either (or both) the userspace
382 # and kernel build versions, but is deprecated and should eventually be
385 # output: prints version string to stdout in dotted-decimal format
386 lustre_build_version() {
387 local facet=${1:-client}
390 # kernel: patchless_client
391 # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
392 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
393 awk '/lustre: / { print $2 }')
395 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
397 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
398 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
399 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
400 awk '/version:/ { print $3; exit; }')
401 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
404 # Report the Lustre numeric build version code for the supplied facet.
405 lustre_version_code() {
406 version_code $(lustre_build_version $1)
410 /sbin/lsmod | grep -q "^\<$1\>"
413 # Load a module on the system where this is running.
415 # usage: load_module module_name [module arguments for insmod/modprobe]
417 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
418 # will be used as the arguments. Otherwise arguments will be obtained from
419 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
426 BASE=$(basename $module $EXT)
428 module_loaded ${BASE} && return
430 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
431 # else from modprobe.conf
432 if [ $# -eq 0 ]; then
433 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
434 # Bash until 4.x, so we resort to eval.
435 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
436 eval set -- \$$optvar
437 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
438 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
440 opt=$(awk -v var="^options $BASE" '$0 ~ var \
441 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
442 set -- $(echo -n $opt)
444 # Ensure we have accept=all for lnet
445 if [ $(basename $module) = lnet ]; then
446 # OK, this is a bit wordy...
447 local arg accept_all_present=false
450 [ "$arg" = accept=all ] && \
451 accept_all_present=true
453 $accept_all_present || set -- "$@" accept=all
459 [ $# -gt 0 ] && echo "${module} options: '$*'"
461 # Note that insmod will ignore anything in modprobe.conf, which is why
462 # we're passing options on the command-line.
463 if [[ "$BASE" == "lnet_selftest" ]] &&
464 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
465 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
466 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
467 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
468 insmod ${LUSTRE}/${module}${EXT} "$@"
470 # must be testing a "make install" or "rpm" installation
471 # note failed to load ptlrpc_gss is considered not fatal
472 if [[ "$BASE" == "ptlrpc_gss" ]]; then
473 modprobe $BASE "$@" 2>/dev/null ||
474 echo "gss/krb5 is not supported"
481 llite_lloop_enabled() {
482 local n1=$(uname -r | cut -d. -f1)
483 local n2=$(uname -r | cut -d. -f2)
484 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
486 # load the llite_lloop module for < 2.6.32 kernels
487 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
488 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
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 || { modprobe crc16 2>/dev/null || true; }
560 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
561 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
562 load_module lfsck/lfsck
563 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
564 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
566 load_module osd-zfs/osd_zfs
568 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
569 grep -q exportfs_decode_fh $SYMLIST ||
570 { modprobe exportfs 2> /dev/null || true; }
571 load_module ../ldiskfs/ldiskfs
572 load_module osd-ldiskfs/osd_ldiskfs
584 load_module llite/lustre
585 llite_lloop_enabled && load_module llite/llite_lloop
586 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
588 rm -f $OGDB/ogdb-$HOSTNAME
589 $LCTL modules > $OGDB/ogdb-$HOSTNAME
591 # 'mount' doesn't look in $PATH, just sbin
592 local mount_lustre=$LUSTRE/utils/mount.lustre
593 if [ -f $mount_lustre ]; then
594 local sbin_mount=/sbin/mount.lustre
595 if grep -qw "$sbin_mount" /proc/mounts; then
596 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
598 if ! grep -qw "$sbin_mount" /proc/mounts; then
599 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
600 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
601 cat <<- EOF > "$sbin_mount"
604 echo "This $sbin_mount just a mountpoint." 1>&2
605 echo "It is never supposed to be run." 1>&2
606 logger -p emerg -- "using stub $sbin_mount $@"
609 chmod a+x $sbin_mount
611 mount --bind $mount_lustre $sbin_mount ||
612 error "can't bind $mount_lustre to $sbin_mount"
620 # load modules on remote nodes optionally
621 # lustre-tests have to be installed on these nodes
622 if $LOAD_MODULES_REMOTE; then
623 local list=$(comma_list $(remote_nodes_list))
624 if [ -n "$list" ]; then
625 echo "loading modules on: '$list'"
626 do_rpc_nodes "$list" load_modules_local
632 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
633 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
634 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
635 echo "$LEAK_LUSTRE" 1>&2
636 echo "$LEAK_PORTALS" 1>&2
637 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
638 echo "Memory leaks detected"
639 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
645 wait_exit_ST client # bug 12845
647 $LUSTRE_RMMOD ldiskfs || return 2
649 if $LOAD_MODULES_REMOTE; then
650 local list=$(comma_list $(remote_nodes_list))
651 if [ -n "$list" ]; then
652 echo "unloading modules on: '$list'"
653 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
654 do_rpc_nodes "$list" check_mem_leak
658 local sbin_mount=/sbin/mount.lustre
659 if grep -qe "$sbin_mount " /proc/mounts; then
660 umount $sbin_mount || true
661 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
665 check_mem_leak || return 254
667 echo "modules unloaded."
672 local facet=${1:-$SINGLEMDS}
673 local fstype=$(facet_fstype $facet)
676 ldiskfs) size=50;; # largest seen is 44, leave some headroom
677 zfs) size=400;; # largest seen is 384
683 check_gss_daemon_nodes() {
687 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
688 if [ \\\"\\\$num\\\" -ne 1 ]; then
689 echo \\\$num instance of $dname;
694 check_gss_daemon_facet() {
698 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
699 if [ $num -ne 1 ]; then
700 echo "$num instance of $dname on $facet"
709 echo Stopping $@ on $list
710 do_nodes $list "killall -2 $@ 2>/dev/null || true"
713 # start gss daemons on all nodes, or
714 # "daemon" on "list" if set
715 start_gss_daemons() {
719 if [ "$list" ] && [ "$daemon" ] ; then
720 echo "Starting gss daemon on nodes: $list"
721 do_nodes $list "$daemon" || return 8
725 local list=$(comma_list $(mdts_nodes))
726 echo "Starting gss daemon on mds: $list"
727 do_nodes $list "$LSVCGSSD -v" || return 1
729 do_nodes $list "$LGSSD -v" || return 2
732 list=$(comma_list $(osts_nodes))
733 echo "Starting gss daemon on ost: $list"
734 do_nodes $list "$LSVCGSSD -v" || return 3
735 # starting on clients
737 local clients=${CLIENTS:-`hostname`}
739 echo "Starting $LGSSD on clients $clients "
740 do_nodes $clients "$LGSSD -v" || return 4
743 # wait daemons entering "stable" status
747 # check daemons are running
749 list=$(comma_list $(mdts_nodes) $(osts_nodes))
750 check_gss_daemon_nodes $list lsvcgssd || return 5
752 list=$(comma_list $(mdts_nodes))
753 check_gss_daemon_nodes $list lgssd || return 6
756 check_gss_daemon_nodes $clients lgssd || return 7
761 local list=$(comma_list $(mdts_nodes))
763 send_sigint $list lsvcgssd lgssd
765 list=$(comma_list $(osts_nodes))
766 send_sigint $list lsvcgssd
768 list=${CLIENTS:-`hostname`}
769 send_sigint $list lgssd
774 if ! module_loaded ptlrpc_gss; then
775 load_module ptlrpc/gss/ptlrpc_gss
776 module_loaded ptlrpc_gss ||
777 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
780 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
783 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
785 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
793 # maybe cleanup credential cache?
799 local var=${facet}_svc
807 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
808 tr '[:lower:]' '[:upper:]'
814 if [ $facet == mgs ]; then
818 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
826 if [ -n "${!var}" ]; then
831 var=$(facet_type $facet)FSTYPE
832 if [ -n "${!var}" ]; then
837 if [ -n "$FSTYPE" ]; then
842 if [[ $facet == mgs ]] && combined_mgs_mds; then
854 local facets=$(get_facets)
857 for facet in ${facets//,/ }; do
858 if [ $node == $(facet_host $facet) ] ||
859 [ $node == "$(facet_failover_host $facet)" ]; then
860 fstype=$(facet_fstype $facet)
861 if [[ $fstypes != *$fstype* ]]; then
862 fstypes+="${fstypes:+,}$fstype"
871 local num=$(facet_number $facet)
874 if [[ $(facet_type $facet) = OST ]]; then
876 if [[ -n "${!index}" ]]; then
881 index=${OST_INDICES[num - 1]}
884 [[ -n "$index" ]] || index=$((num - 1))
892 local fstype=$(facet_fstype $facet)
896 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
898 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
899 ${dev} 2>/dev/null");;
901 error "unknown fstype!";;
909 local device=$(mdsdevname $num)
910 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
916 local device=$(ostdevname $num)
917 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
922 # Get the device of a facet.
929 mgs) device=$(mgsdevname) ;;
930 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
931 ost*) device=$(ostdevname $(facet_number $facet)) ;;
932 fs2mds) device=$(mdsdevname 1_2) ;;
933 fs2ost) device=$(ostdevname 1_2) ;;
934 fs3ost) device=$(ostdevname 2_2) ;;
942 # Get the virtual device of a facet.
949 mgs) device=$(mgsvdevname) ;;
950 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
951 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
952 fs2mds) device=$(mdsvdevname 1_2) ;;
953 fs2ost) device=$(ostvdevname 1_2) ;;
954 fs3ost) device=$(ostvdevname 2_2) ;;
962 # Re-read the partition table on failover partner host.
963 # After a ZFS storage pool is created on a shared device, the partition table
964 # on the device may change. However, the operating system on the failover
965 # host may not notice the change automatically. Without the up-to-date partition
966 # block devices, 'zpool import ..' cannot find the labels, whose positions are
967 # relative to partition rather than disk beginnings.
969 # This function performs partprobe on the failover host to make it re-read the
972 refresh_partition_table() {
977 host=$(facet_passive_host $facet)
978 if [[ -n "$host" ]]; then
979 do_node $host "$PARTPROBE $device"
984 # Get ZFS storage pool name.
991 device=$(facet_device $facet)
992 # poolname is string before "/"
993 poolname="${device%%/*}"
999 # Create ZFS storage pool.
1006 local opts=${@:-"-o cachefile=none"}
1008 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1009 $ZPOOL create -f $opts $poolname $vdev"
1013 # Create ZFS file system.
1019 local opts=${@:-"-o mountpoint=legacy"}
1021 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1022 $ZFS create $opts $dataset"
1026 # Export ZFS storage pool.
1027 # Before exporting the pool, all datasets within the pool should be unmounted.
1035 poolname=$(zpool_name $facet)
1037 if [[ -n "$poolname" ]]; then
1038 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1039 grep -q ^$poolname/ /proc/mounts ||
1040 $ZPOOL export $opts $poolname"
1045 # Destroy ZFS storage pool.
1046 # Destroy the given pool and free up any devices for other use. This command
1047 # tries to unmount any active datasets before destroying the pool.
1048 # -f Force any active datasets contained within the pool to be unmounted.
1052 local poolname=${2:-$(zpool_name $facet)}
1054 if [[ -n "$poolname" ]]; then
1055 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1056 $ZPOOL destroy -f $poolname"
1061 # Import ZFS storage pool.
1062 # Force importing, even if the pool appears to be potentially active.
1067 local opts=${@:-"-o cachefile=none"}
1070 poolname=$(zpool_name $facet)
1072 if [[ -n "$poolname" ]]; then
1073 opts+=" -d $(dirname $(facet_vdevice $facet))"
1074 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1075 $ZPOOL import -f $opts $poolname"
1080 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1081 # is not automatically imported on system startup.
1083 # In a failover environment, this will provide resource level fencing which
1084 # will ensure that the same ZFS storage pool will not be imported concurrently
1085 # on different nodes.
1087 disable_zpool_cache() {
1091 poolname=$(zpool_name $facet)
1093 if [[ -n "$poolname" ]]; then
1094 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1099 # This and set_osd_param() shall be used to access OSD parameters
1100 # once existed under "obdfilter":
1105 # writethrough_cache_enable
1109 local device=${2:-$FSNAME-OST*}
1112 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1113 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1118 local device=${2:-$FSNAME-OST*}
1122 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1123 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1127 local dz=${1:-$DEBUG_SIZE}
1129 if [ -f /sys/devices/system/cpu/possible ]; then
1130 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1132 local cpus=$(getconf _NPROCESSORS_CONF)
1135 # bug 19944, adjust size to be -gt num_possible_cpus()
1136 # promise 2MB for every cpu at least
1137 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1140 lctl set_param debug_mb=$dz
1143 set_default_debug () {
1144 local debug=${1:-"$PTLDEBUG"}
1145 local subsys=${2:-"$SUBSYSTEM"}
1146 local debug_size=${3:-$DEBUG_SIZE}
1148 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1149 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1151 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1154 set_default_debug_nodes () {
1157 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1158 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1162 do_rpc_nodes "$nodes" set_default_debug \
1163 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1166 set_default_debug_facet () {
1168 local node=$(facet_active_host $facet)
1169 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1171 set_default_debug_nodes $node
1176 local facets=${1:-$(get_facets)}
1179 for facet in ${facets//,/ }; do
1182 [ $RC -eq 0 ] && continue
1184 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1185 skip "Restart of $facet failed!." && touch $LU482_FAILED
1187 error "Restart of $facet failed!"
1194 # Add argument "arg" (e.g., "loop") to the comma-separated list
1195 # of arguments for option "opt" (e.g., "-o") on command
1196 # line "opts" (e.g., "-o flock").
1202 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1204 if echo "$opts" | grep -q $opt_pattern; then
1205 opts=$(echo "$opts" | sed -e \
1206 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1208 opts+="${opts:+ }$opt $arg"
1216 local dev=$(facet_active $facet)_dev
1217 local opt=${facet}_opt
1218 local mntpt=$(facet_mntpt $facet)
1219 local opts="${!opt} $@"
1221 if [ $(facet_fstype $facet) == ldiskfs ] &&
1222 ! do_facet $facet test -b ${!dev}; then
1223 opts=$(csa_add "$opts" -o loop)
1226 if [[ $(facet_fstype $facet) == zfs ]]; then
1227 # import ZFS storage pool
1228 import_zpool $facet || return ${PIPESTATUS[0]}
1231 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1232 # for testing LU-482 error handling in mount_facets() and test_0a()
1233 if [ -f $TMP/test-lu482-trigger ]; then
1236 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1240 if [ $RC -ne 0 ]; then
1241 echo "Start of ${!dev} on ${facet} failed ${RC}"
1243 set_default_debug_facet $facet
1245 if [[ $facet == mds* ]]; then
1247 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1251 label=$(devicelabel ${facet} ${!dev})
1252 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1253 eval export ${facet}_svc=${label}
1254 echo Started ${label}
1259 # start facet device options
1265 eval export ${facet}_dev=${device}
1266 eval export ${facet}_opt=\"$@\"
1268 local varname=${facet}failover_dev
1269 if [ -n "${!varname}" ] ; then
1270 eval export ${facet}failover_dev=${!varname}
1272 eval export ${facet}failover_dev=$device
1275 local mntpt=$(facet_mntpt $facet)
1276 do_facet ${facet} mkdir -p $mntpt
1277 eval export ${facet}_MOUNT=$mntpt
1278 mount_facet ${facet}
1281 if [[ $facet == mds* ]]; then
1283 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1294 local HOST=`facet_active_host $facet`
1295 [ -z $HOST ] && echo stop: no host for $facet && return 0
1297 local mntpt=$(facet_mntpt $facet)
1298 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1299 if [ ${running} -ne 0 ]; then
1300 echo "Stopping $mntpt (opts:$@) on $HOST"
1301 do_facet ${facet} umount -d $@ $mntpt
1304 # umount should block, but we should wait for unrelated obd's
1305 # like the MGS or MGC to also stop.
1306 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1308 if [[ $(facet_fstype $facet) == zfs ]]; then
1309 # export ZFS storage pool
1314 # save quota version (both administrative and operational quotas)
1315 # add an additional parameter if mountpoint is ever different from $MOUNT
1317 # XXX This function is kept for interoperability with old server (< 2.3.50),
1318 # it should be removed whenever we drop the interoperability for such
1320 quota_save_version() {
1321 local fsname=${2:-$FSNAME}
1323 local ver=$(tr -c -d "123" <<< $spec)
1324 local type=$(tr -c -d "ug" <<< $spec)
1326 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1328 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1330 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1332 local osts=$(get_facets OST)
1333 for ost in ${osts//,/ }; do
1335 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1339 # client could mount several lustre
1341 # XXX This function is kept for interoperability with old server (< 2.3.50),
1342 # it should be removed whenever we drop the interoperability for such
1345 local fsname=${1:-$FSNAME}
1347 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1349 do_nodes $(comma_list $(osts_nodes)) \
1350 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1354 # XXX This function is kept for interoperability with old server (< 2.3.50),
1355 # it should be removed whenever we drop the interoperability for such
1357 restore_quota_old() {
1358 local mntpt=${1:-$MOUNT}
1359 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1360 if [ ! "$old_QUOTA_TYPE" ] ||
1361 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1364 quota_save_version $old_QUOTA_TYPE
1367 # XXX This function is kept for interoperability with old server (< 2.3.50),
1368 # it should be removed whenever we drop the interoperability for such
1373 # no quota enforcement for now and accounting works out of the box
1376 # We need save the original quota_type params, and restore them after testing
1378 # Suppose that quota type the same on mds and ost
1379 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1380 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1381 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1382 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1383 export old_QUOTA_TYPE=$quota_type
1384 quota_save_version $QUOTA_TYPE
1386 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1387 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1390 local quota_usrs=$QUOTA_USERS
1392 # get_filesystem_size
1393 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1394 local blk_soft=$((disksz + 1024))
1395 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1397 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1398 local i_soft=$Inodes
1399 local i_hard=$((i_soft + i_soft / 20))
1401 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1402 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1405 for usr in $quota_usrs; do
1406 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1408 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1410 eval $cmd || error "$cmd FAILED!"
1412 # display the quota status
1413 echo "Quota settings for $usr : "
1414 $LFS quota -v -u $usr $mntpt || true
1418 # get mdt quota type
1420 local varsvc=${SINGLEMDS}_svc
1421 do_facet $SINGLEMDS $LCTL get_param -n \
1422 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1425 # get ost quota type
1427 # All OSTs should have same quota type
1428 local varsvc=ost1_svc
1429 do_facet ost1 $LCTL get_param -n \
1430 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1433 # restore old quota type settings
1435 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1440 if [ "$old_MDT_QUOTA_TYPE" ]; then
1441 do_facet mgs $LCTL conf_param \
1442 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1444 if [ "$old_OST_QUOTA_TYPE" ]; then
1445 do_facet mgs $LCTL conf_param \
1446 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1450 # Handle the case when there is a space in the lfs df
1451 # "filesystem summary" line the same as when there is no space.
1452 # This will allow fixing the "lfs df" summary line in the future.
1454 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1457 # Get free inodes on the MDT specified by mdt index, free indoes on
1458 # the whole filesystem will be returned when index == -1.
1464 if [ $index -eq -1 ]; then
1467 mdt_uuid=$(mdtuuid_from_index $index)
1470 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1475 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1482 # save old quota type & set new quota type
1483 local mdt_qtype=$(mdt_quota_type)
1484 local ost_qtype=$(ost_quota_type)
1486 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1487 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1489 export old_MDT_QUOTA_TYPE=$mdt_qtype
1490 export old_OST_QUOTA_TYPE=$ost_qtype
1492 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1493 error "set mdt quota type failed"
1494 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1495 error "set ost quota type failed"
1497 local quota_usrs=$QUOTA_USERS
1499 # get_filesystem_size
1500 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1501 local blk_soft=$((disksz + 1024))
1502 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1504 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1505 local i_soft=$inodes
1506 local i_hard=$((i_soft + i_soft / 20))
1508 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1509 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1510 "inode-hardlimit: $i_hard"
1513 for usr in $quota_usrs; do
1514 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1516 cmd="$LFS setquota -$type $usr -b $blk_soft"
1517 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1519 eval $cmd || error "$cmd FAILED!"
1521 # display the quota status
1522 echo "Quota settings for $usr : "
1523 $LFS quota -v -u $usr $mntpt || true
1530 local opts=${3:-$MOUNT_OPTS}
1531 opts=${opts:+-o $opts}
1532 local flags=${4:-$MOUNT_FLAGS}
1534 local device=$MGSNID:/$FSNAME
1535 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1536 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1540 echo "Starting client: $client: $flags $opts $device $mnt"
1541 do_node $client mkdir -p $mnt
1542 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1544 set_default_debug_nodes $client
1556 [ "$3" ] && force=-f
1557 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1558 if [ $running -ne 0 ]; then
1559 echo "Stopping client $client $mnt (opts:$force)"
1560 do_node $client lsof -t $mnt || need_kill=no
1561 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1562 pids=$(do_node $client lsof -t $mnt | sort -u);
1563 if [ -n $pids ]; then
1564 do_node $client kill -9 $pids || true
1568 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1569 if [ $busy -ne 0 ] ; then
1570 echo "$mnt is still busy, wait one second" && sleep 1
1571 do_node $client umount $force $mnt
1576 # nodes is comma list
1577 sanity_mount_check_nodes () {
1583 # FIXME: assume that all cluster nodes run the same os
1584 [ "$(uname)" = Linux ] || return 0
1587 for mnt in $mnts ; do
1588 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1589 mpts=\\\$(mount | grep -c $mnt' ');
1590 if [ \\\$running -ne \\\$mpts ]; then
1591 echo \\\$(hostname) env are INSANE!;
1594 [ $? -eq 0 ] || rc=1
1599 sanity_mount_check_servers () {
1600 [ "$CLIENTONLY" ] &&
1601 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1602 echo Checking servers environments
1604 # FIXME: modify get_facets to display all facets wo params
1605 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1609 for facet in ${facets//,/ }; do
1610 node=$(facet_host ${facet})
1611 mntpt=$(facet_mntpt $facet)
1612 sanity_mount_check_nodes $node $mntpt ||
1613 { error "server $node environments are insane!"; return 1; }
1617 sanity_mount_check_clients () {
1618 local clients=${1:-$CLIENTS}
1619 local mntpt=${2:-$MOUNT}
1620 local mntpt2=${3:-$MOUNT2}
1622 [ -z $clients ] && clients=$(hostname)
1623 echo Checking clients $clients environments
1625 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1626 error "clients environments are insane!"
1629 sanity_mount_check () {
1630 sanity_mount_check_servers || return 1
1631 sanity_mount_check_clients || return 2
1634 # mount clients if not mouted
1635 zconf_mount_clients() {
1638 local opts=${3:-$MOUNT_OPTS}
1639 opts=${opts:+-o $opts}
1640 local flags=${4:-$MOUNT_FLAGS}
1642 local device=$MGSNID:/$FSNAME
1643 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1644 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1648 echo "Starting client $clients: $flags $opts $device $mnt"
1651 running=\\\$(mount | grep -c $mnt' ');
1653 if [ \\\$running -eq 0 ] ; then
1655 $MOUNT_CMD $flags $opts $device $mnt;
1658 exit \\\$rc" || return ${PIPESTATUS[0]}
1660 echo "Started clients $clients: "
1661 do_nodes $clients "mount | grep $mnt' '"
1663 set_default_debug_nodes $clients
1668 zconf_umount_clients() {
1673 [ "$3" ] && force=-f
1675 echo "Stopping clients: $clients $mnt (opts:$force)"
1676 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1677 if [ \\\$running -ne 0 ] ; then
1678 echo Stopping client \\\$(hostname) $mnt opts:$force;
1679 lsof $mnt || need_kill=no;
1680 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1681 pids=\\\$(lsof -t $mnt | sort -u);
1682 if [ -n \\\"\\\$pids\\\" ]; then
1686 while umount $force $mnt 2>&1 | grep -q "busy"; do
1687 echo "$mnt is still busy, wait one second" && sleep 1;
1694 echo + $POWER_DOWN $node
1698 shutdown_node_hard () {
1700 local attempts=$SHUTDOWN_ATTEMPTS
1702 for i in $(seq $attempts) ; do
1705 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1706 echo "waiting for $host to fail attempts=$attempts"
1707 [ $i -lt $attempts ] || \
1708 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1714 local mnt=${2:-$MOUNT}
1717 if [ "$FAILURE_MODE" = HARD ]; then
1718 shutdown_node_hard $client
1720 zconf_umount_clients $client $mnt -f
1726 local facets="$(get_facets OST),$(get_facets MDS)"
1729 combined_mgs_mds || facets="$facets,mgs"
1731 for facet in ${facets//,/ }; do
1732 if [ $(facet_active_host $facet) == $host ]; then
1733 affected="$affected $facet"
1737 echo $(comma_list $affected)
1742 local host=${2:-$(facet_host $facet)}
1744 local label=$(convert_facet2label $facet)
1745 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1748 facets_up_on_host () {
1750 local facets=$(facets_on_host $host)
1753 for facet in ${facets//,/ }; do
1754 if $(facet_up $facet $host); then
1755 affected_up="$affected_up $facet"
1759 echo $(comma_list $affected_up)
1765 if [ "$FAILURE_MODE" = HARD ]; then
1766 shutdown_node_hard $(facet_active_host $facet)
1774 echo + $POWER_UP $node
1787 if [ "$FAILURE_MODE" = HARD ]; then
1788 reboot_node $(facet_active_host $facet)
1796 if [ "$FAILURE_MODE" = HARD ]; then
1806 for facet in ${facets//,/ }; do
1807 hosts=$(expand_list $hosts $(facet_host $facet) )
1813 _check_progs_installed () {
1817 for prog in $progs; do
1818 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1819 echo $prog missing on $(hostname)
1826 check_progs_installed () {
1830 do_rpc_nodes "$nodes" _check_progs_installed $@
1833 # recovery-scale functions
1835 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1838 start_client_load() {
1841 local var=$(node_var_name $client)_load
1842 eval export ${var}=$load
1844 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1845 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1846 END_RUN_FILE=$END_RUN_FILE \
1847 LOAD_PID_FILE=$LOAD_PID_FILE \
1848 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1849 TESTNAME=$TESTNAME \
1850 DBENCH_LIB=$DBENCH_LIB \
1851 DBENCH_SRC=$DBENCH_SRC \
1852 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1856 log "Started client load: ${load} on $client"
1858 # get the children process IDs
1859 local pids=$(ps --ppid $ppid -o pid= | xargs)
1860 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1864 start_client_loads () {
1865 local -a clients=(${1//,/ })
1866 local numloads=${#CLIENT_LOADS[@]}
1869 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1870 testnum=$((nodenum % numloads))
1871 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1873 # bug 22169: wait the background threads to start
1877 # only for remote client
1878 check_client_load () {
1880 local var=$(node_var_name $client)_load
1881 local TESTLOAD=run_${!var}.sh
1883 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1885 # bug 18914: try to connect several times not only when
1886 # check ps, but while check_catastrophe also
1889 while [ $RC = 254 -a $tries -gt 0 ]; do
1893 if ! check_catastrophe $client; then
1895 if [ $RC -eq 254 ]; then
1896 # FIXME: not sure how long we shuold sleep here
1900 echo "check catastrophe failed: RC=$RC "
1904 # We can continue try to connect if RC=254
1905 # Just print the warning about this
1906 if [ $RC = 254 ]; then
1907 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1910 # see if the load is still on the client
1913 while [ $RC = 254 -a $tries -gt 0 ]; do
1917 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1922 if [ $RC = 254 ]; then
1923 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1924 # see if we can diagnose a bit why this is
1929 check_client_loads () {
1930 local clients=${1//,/ }
1934 for client in $clients; do
1935 check_client_load $client
1937 if [ "$rc" != 0 ]; then
1938 log "Client load failed on node $client, rc=$rc"
1944 restart_client_loads () {
1945 local clients=${1//,/ }
1946 local expectedfail=${2:-""}
1950 for client in $clients; do
1951 check_client_load $client
1953 if [ "$rc" != 0 -a "$expectedfail" ]; then
1954 local var=$(node_var_name $client)_load
1955 start_client_load $client ${!var}
1956 echo "Restarted client load ${!var}: on $client. Checking ..."
1957 check_client_load $client
1959 if [ "$rc" != 0 ]; then
1960 log "Client load failed to restart on node $client, rc=$rc"
1961 # failure one client load means test fail
1962 # we do not need to check other
1971 # Start vmstat and save its process ID in a file.
1976 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1979 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1980 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1983 # Display the nodes on which client loads failed.
1984 print_end_run_file() {
1988 [ -s $file ] || return 0
1990 echo "Found the END_RUN_FILE file: $file"
1993 # A client load will stop if it finds the END_RUN_FILE file.
1994 # That does not mean the client load actually failed though.
1995 # The first node in END_RUN_FILE is the one we are interested in.
1998 if [ -n "$node" ]; then
1999 local var=$(node_var_name $node)_load
2001 local prefix=$TESTLOG_PREFIX
2002 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2003 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2004 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2006 echo "Client load ${!var} failed on node $node:"
2012 # Stop the process which had its PID saved in a file.
2017 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2019 do_nodes $nodes "test -f $pid_file &&
2020 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2023 # Stop all client loads.
2024 stop_client_loads() {
2025 local nodes=${1:-$CLIENTS}
2028 # stop the client loads
2029 stop_process $nodes $pid_file
2031 # clean up the processes that started them
2032 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2034 # End recovery-scale functions
2036 # verify that lustre actually cleaned up properly
2038 VAR=$(lctl get_param -n catastrophe 2>&1)
2039 if [ $? = 0 ] ; then
2040 if [ $VAR != 0 ]; then
2041 error "LBUG/LASSERT detected"
2044 BUSY=$(dmesg | grep -i destruct || true)
2045 if [ -n "$BUSY" ]; then
2047 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2051 check_mem_leak || exit 204
2053 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2054 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2057 if module_loaded lnet || module_loaded libcfs; then
2058 echo "$TESTSUITE: modules still loaded..." 1>&2
2067 if [[ "$1" == "--verbose" ]]; then
2082 PREV_RESULT=$(do_node $node "$TEST")
2084 RESULT=$(do_node $node "$TEST")
2085 if [[ "$RESULT" == "$FINAL" ]]; then
2086 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2087 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2091 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2092 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2096 [[ $WAIT -ge $MAX ]] && break
2097 [[ $((WAIT % print)) -eq 0 ]] &&
2098 echo "Waiting $((MAX - WAIT)) secs for update"
2099 WAIT=$((WAIT + sleep))
2102 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2106 wait_update_facet() {
2109 wait_update $(facet_active_host $facet) "$@"
2113 do_nodes $(comma_list $(mdts_nodes)) \
2114 "lctl set_param -n osd*.*MDT*.force_sync 1"
2115 do_nodes $(comma_list $(osts_nodes)) \
2116 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2117 grep -v 'Found no match'
2120 wait_delete_completed_mds() {
2121 local MAX_WAIT=${1:-20}
2122 # for ZFS, waiting more time for DMUs to be committed
2123 local ZFS_WAIT=${2:-5}
2125 local stime=$(date +%s)
2130 # find MDS with pending deletions
2131 for node in $(mdts_nodes); do
2132 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2133 2>/dev/null | calc_sum)
2134 if [[ $changes -eq 0 ]]; then
2137 mds2sync="$mds2sync $node"
2139 if [ -z "$mds2sync" ]; then
2142 mds2sync=$(comma_list $mds2sync)
2144 # sync MDS transactions
2145 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2147 # wait till all changes are sent and commmitted by OSTs
2148 # for ldiskfs space is released upon execution, but DMU
2149 # do this upon commit
2152 while [[ $WAIT -ne $MAX_WAIT ]]; do
2153 changes=$(do_nodes $mds2sync \
2154 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2155 #echo "$node: $changes changes on all"
2156 if [[ $changes -eq 0 ]]; then
2158 #echo "delete took $((etime - stime)) seconds"
2160 # the occupied disk space will be released
2161 # only after DMUs are committed
2162 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2163 echo "sleep $ZFS_WAIT for ZFS OSD"
2174 echo "Delete is not completed in $((etime - stime)) seconds"
2175 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2181 # we can use "for" here because we are waiting the slowest
2182 for host in ${hostlist//,/ }; do
2183 check_network "$host" 900
2185 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2192 for facet in ${facetlist//,/ }; do
2193 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2195 wait_for_host $hostlist
2198 _wait_recovery_complete () {
2201 # Use default policy if $2 is not passed by caller.
2202 local MAX=${2:-$(max_recovery_time)}
2207 while [ $WAIT -lt $MAX ]; do
2208 STATUS=$(lctl get_param -n $param | grep status)
2210 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2213 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2215 echo "$param recovery not done in $MAX sec. $STATUS"
2219 wait_recovery_complete () {
2222 # with an assumption that at_max is the same on all nodes
2223 local MAX=${2:-$(max_recovery_time)}
2226 if [ "$FAILURE_MODE" = HARD ]; then
2227 facets=$(facets_on_host $(facet_active_host $facet))
2229 echo affected facets: $facets
2231 # we can use "for" here because we are waiting the slowest
2232 for facet in ${facets//,/ }; do
2233 local var_svc=${facet}_svc
2234 local param="*.${!var_svc}.recovery_status"
2236 local host=$(facet_active_host $facet)
2237 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2241 wait_mds_ost_sync () {
2242 # just because recovery is done doesn't mean we've finished
2243 # orphan cleanup. Wait for llogs to get synchronized.
2244 echo "Waiting for orphan cleanup..."
2245 # MAX value includes time needed for MDS-OST reconnection
2246 local MAX=$(( TIMEOUT * 2 ))
2247 local WAIT_TIMEOUT=${1:-$MAX}
2250 local list=$(comma_list $(mdts_nodes))
2251 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2252 if ! do_facet $SINGLEMDS \
2253 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2255 # old way, use mds_sync
2257 list=$(comma_list $(osts_nodes))
2258 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2261 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2262 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2263 local -a sync=($(do_nodes $list "$cmd"))
2266 for ((i=0; i<${#sync[@]}; i++)); do
2268 [ ${sync[$i]} -eq 1 ] && continue
2270 [ ${sync[$i]} -eq 0 ] && continue
2272 # there is a not finished MDS-OST synchronization
2276 sleep 2 # increase waiting time and cover statfs cache
2277 [ ${con} -eq 1 ] && return 0
2278 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2282 # show which nodes are not finished.
2283 do_nodes $list "$cmd"
2284 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2288 wait_destroy_complete () {
2289 echo "Waiting for local destroys to complete"
2290 # MAX value shouldn't be big as this mean server responsiveness
2291 # never increase this just to make test pass but investigate
2292 # why it takes so long time
2295 while [ $WAIT -lt $MAX ]; do
2296 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2300 for ((i=0; i<${#RPCs[@]}; i++)); do
2301 [ ${RPCs[$i]} -eq 0 ] && continue
2302 # there are still some destroy RPCs in flight
2307 [ ${con} -eq 1 ] && return 0 # done waiting
2308 echo "Waiting ${WAIT}s for local destroys to complete"
2311 echo "Local destroys weren't done in $MAX sec."
2315 wait_delete_completed() {
2316 wait_delete_completed_mds $1 || return $?
2317 wait_destroy_complete
2326 # conf-sanity 31 takes a long time cleanup
2327 while [ $WAIT -lt 300 ]; do
2328 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2329 [ -z "${running}" ] && return 0
2330 echo "waited $WAIT for${running}"
2331 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2333 WAIT=$((WAIT + INTERVAL))
2335 echo "service didn't stop after $WAIT seconds. Still running:"
2340 wait_remote_prog () {
2346 [ "$PDSH" = "no_dsh" ] && return 0
2348 while [ $WAIT -lt $2 ]; do
2349 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2350 [ -z "${running}" ] && return 0 || true
2351 echo "waited $WAIT for: "
2353 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2355 WAIT=$((WAIT + INTERVAL))
2357 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2358 [ -z "$pids" ] && return 0
2359 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2360 # FIXME: not portable
2361 for pid in $pids; do
2362 cat /proc/${pid}/status || true
2363 cat /proc/${pid}/wchan || true
2365 kill -9 $pid || true
2374 # not every config has many clients
2376 if [ ! -z "$CLIENTS" ]; then
2377 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2379 stat -f $MOUNT > /dev/null
2385 # usually checked on particular client or locally
2387 if [ ! -z "$client" ]; then
2388 $PDSH $client "stat -f $MOUNT" > /dev/null
2390 stat -f $MOUNT > /dev/null
2398 client_reconnect_try() {
2399 uname -n >> $MOUNT/recon
2400 if [ -z "$CLIENTS" ]; then
2401 df $MOUNT; uname -n >> $MOUNT/recon
2403 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2405 echo Connected clients:
2407 ls -l $MOUNT/recon > /dev/null
2411 client_reconnect() {
2412 # one client_reconnect_try call does not always do the job...
2414 client_reconnect_try && break
2419 affected_facets () {
2422 local host=$(facet_active_host $facet)
2423 local affected=$facet
2425 if [ "$FAILURE_MODE" = HARD ]; then
2426 affected=$(facets_up_on_host $host)
2440 #Because it will only get up facets, we need get affected
2441 #facets before shutdown
2442 #For HARD Failure mode, it needs make sure facets on the same
2443 #HOST will only be shutdown and reboot once
2444 for facet in ${facets//,/ }; do
2445 local affected_facet
2447 #check whether facet has been included in other affected facets
2448 for ((index=0; index<$total; index++)); do
2449 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2452 if [ $skip -eq 0 ]; then
2453 affecteds[$total]=$(affected_facets $facet)
2458 for ((index=0; index<$total; index++)); do
2459 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2460 local host=$(facet_active_host $facet)
2461 echo "Failing ${affecteds[index]} on $host"
2462 shutdown_facet $facet
2465 for ((index=0; index<$total; index++)); do
2466 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2467 echo reboot facets: ${affecteds[index]}
2471 change_active ${affecteds[index]}
2473 wait_for_facet ${affecteds[index]}
2474 # start mgs first if it is affected
2475 if ! combined_mgs_mds &&
2476 list_member ${affecteds[index]} mgs; then
2477 mount_facet mgs || error "Restart of mgs failed"
2479 # FIXME; has to be changed to mount all facets concurrently
2480 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2481 echo mount facets: ${affecteds[index]}
2482 mount_facets ${affecteds[index]}
2492 do_facet $facet "sync; sync; sync"
2495 # make sure there will be no seq change
2496 local clients=${CLIENTS:-$HOSTNAME}
2497 local f=fsa-\\\$\(hostname\)
2498 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2499 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2501 local svc=${facet}_svc
2502 do_facet $facet $LCTL --device ${!svc} notransno
2504 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2505 # in-memory state has to be cleared by either rebooting the host or
2506 # exporting and reimporting the pool.
2508 # Although the uberblocks are not updated when a pool is freezed,
2509 # transactions are still written to the disks. Modified blocks may be
2510 # cached in memory when tests try reading them back. The
2511 # export-and-reimport process also evicts any cached pool data from
2512 # memory to provide the correct "data loss" semantics.
2514 # In the test framework, the exporting and importing operations are
2515 # handled by stop() and mount_facet() separately, which are used
2516 # inside fail() and fail_abort().
2518 do_facet $facet $LCTL --device ${!svc} readonly
2519 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2520 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2523 replay_barrier_nodf() {
2524 local facet=$1 echo running=${running}
2525 do_facet $facet "sync; sync; sync"
2526 local svc=${facet}_svc
2527 echo Replay barrier on ${!svc}
2528 do_facet $facet $LCTL --device ${!svc} notransno
2529 do_facet $facet $LCTL --device ${!svc} readonly
2530 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2531 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2534 replay_barrier_nosync() {
2535 local facet=$1 echo running=${running}
2536 local svc=${facet}_svc
2537 echo Replay barrier on ${!svc}
2538 do_facet $facet $LCTL --device ${!svc} notransno
2539 do_facet $facet $LCTL --device ${!svc} readonly
2540 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2541 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2545 # Get Lustre client uuid for a given Lustre mount point.
2548 local mntpnt=${1:-$MOUNT}
2550 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2551 local uuid=$($LCTL get_param -n llite.$name.uuid)
2556 mds_evict_client() {
2557 local mntpnt=${1:-$MOUNT}
2558 local uuid=$(get_client_uuid $mntpnt)
2560 do_facet $SINGLEMDS \
2561 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2564 ost_evict_client() {
2565 local mntpnt=${1:-$MOUNT}
2566 local uuid=$(get_client_uuid $mntpnt)
2569 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2574 local clients=${CLIENTS:-$HOSTNAME}
2576 facet_failover $* || error "failover: $?"
2577 wait_clients_import_state "$clients" "$facets" FULL
2578 clients_up || error "post-failover df: $?"
2583 facet_failover $facet
2589 change_active $facet
2590 wait_for_facet $facet
2591 mount_facet $facet -o abort_recovery
2592 clients_up || echo "first df failed: $?"
2593 clients_up || error "post-failover df: $?"
2597 echo There is no lmc. This is mountconf, baby.
2601 host_nids_address() {
2605 if [ -n "$kind" ]; then
2606 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2608 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2614 if [ "$1" = "'*'" ]; then echo \'*\'; else
2620 if [ "$1" = "'*'" ]; then echo \'*\'; else
2621 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2623 if [ -z "$ID" ]; then
2624 echo "Could not get a ptl id for $1..."
2633 h2name_or_ip "$1" "tcp"
2638 if [ "$1" = "'*'" ]; then echo \'*\'; else
2639 if type __h2elan >/dev/null 2>&1; then
2642 ID=`echo $1 | sed 's/[^0-9]*//g'`
2650 h2name_or_ip "$1" "o2ib"
2654 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2655 # expressions format. As a bonus we can then just pass in those variables
2656 # to pdsh. What this function does is take a HOSTLIST type string and
2657 # expand it into a space deliminated list for us.
2665 [ -z "$hostlist" ] && return
2667 # Translate the case of [..],..,[..] to [..] .. [..]
2668 list="${hostlist/],/] }"
2670 [[ "$front" == *,* ]] && {
2673 list=${list/${old}/${new}}
2676 for item in $list; do
2677 # Test if we have any []'s at all
2678 if [ "$item" != "${item/\[/}" ]; then {
2679 # Expand the [*] into list
2683 if [ "$name" != "$item" ]; then
2684 group=${item#$name[*}
2687 for range in ${group//,/ }; do
2691 # Number of leading zeros
2694 end=$(echo $end | sed 's/0*//')
2695 [[ -z "$end" ]] && end=0
2696 [[ $padlen2 -gt $padlen ]] && {
2697 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2700 begin=$(echo $begin | sed 's/0*//')
2701 [ -z $begin ] && begin=0
2703 for num in $(seq -f "%0${padlen}g" $begin $end); do
2704 value="${name#*,}${num}${back}"
2705 [ "$value" != "${value/\[/}" ] && {
2706 value=$(hostlist_expand "$value")
2708 myList="$myList $value"
2713 myList="$myList $item"
2716 myList=${myList//,/ }
2717 myList=${myList:1} # Remove first character which is a space
2719 # Filter any duplicates without sorting
2721 myList="${list%% *}"
2723 while [[ "$list" != ${myList##* } ]]; do
2724 list=${list//${list%% *} /}
2725 myList="$myList ${list%% *}"
2727 myList="${myList%* }";
2729 # We can select an object at an offset in the list
2732 for item in $myList; do
2734 [ $cnt -eq $offset ] && {
2738 [ $(get_node_count $myList) -ne 1 ] && myList=""
2747 [ "$facet" == client ] && echo -n $HOSTNAME && return
2748 varname=${facet}_HOST
2749 if [ -z "${!varname}" ]; then
2750 if [ "${facet:0:3}" == "ost" ]; then
2751 local fh=${facet%failover}_HOST
2752 eval export ${facet}_HOST=${!fh}
2753 if [ -z "${!varname}" ]; then
2754 eval export ${facet}_HOST=${ost_HOST}
2756 elif [ "${facet:0:3}" == "mdt" -o \
2757 "${facet:0:3}" == "mds" -o \
2758 "${facet:0:3}" == "mgs" ]; then
2759 eval export ${facet}_HOST=${mds_HOST}
2765 facet_failover_host() {
2769 var=${facet}failover_HOST
2770 if [ -n "${!var}" ]; then
2775 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2776 "${facet:0:3}" == "mgs" ]; then
2778 eval export ${facet}failover_host=${mds_HOST}
2783 if [[ $facet == ost* ]]; then
2784 eval export ${facet}failover_host=${ost_HOST}
2792 local activevar=${facet}active
2794 if [ -f $TMP/${facet}active ] ; then
2795 source $TMP/${facet}active
2798 active=${!activevar}
2799 if [ -z "$active" ] ; then
2806 facet_active_host() {
2807 facet_host $(facet_active $1)
2810 # Get the passive failover partner host of facet.
2811 facet_passive_host() {
2813 [[ $facet = client ]] && return
2815 local host=${facet}_HOST
2816 local failover_host=${facet}failover_HOST
2817 local active_host=$(facet_active_host $facet)
2819 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2821 if [[ $active_host = ${!host} ]]; then
2822 echo -n ${!failover_host}
2832 facetlist=$(exclude_items_from_list $facetlist mgs)
2834 for facet in ${facetlist//,/ }; do
2835 local failover=${facet}failover
2836 local host=`facet_host $failover`
2837 [ -z "$host" ] && return
2839 local curactive=`facet_active $facet`
2840 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2841 eval export ${facet}active=$facet
2843 eval export ${facet}active=$failover
2845 # save the active host for this facet
2846 local activevar=${facet}active
2847 echo "$activevar=${!activevar}" > $TMP/$activevar
2848 [[ $facet = mds1 ]] && combined_mgs_mds && \
2849 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2850 local TO=`facet_active_host $facet`
2851 echo "Failover $facet to $TO"
2857 # do not stripe off hostname if verbose, bug 19215
2858 if [ x$1 = x--verbose ]; then
2866 if [ "$HOST" = "$HOSTNAME" ]; then
2868 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2869 echo "cannot run remote command on $HOST with $myPDSH"
2873 echo "CMD: $HOST $@" >&2
2874 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2877 if [ "$myPDSH" = "rsh" ]; then
2878 # we need this because rsh does not return exit code of an executed command
2879 local command_status="$TMP/cs"
2880 rsh $HOST ":> $command_status"
2881 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2882 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2883 echo command failed >$command_status"
2884 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2889 # print HOSTNAME for myPDSH="no_dsh"
2890 if [[ $myPDSH = no_dsh ]]; then
2891 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2893 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2896 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2898 return ${PIPESTATUS[0]}
2902 do_node --verbose "$@"
2905 single_local_node () {
2906 [ "$1" = "$HOSTNAME" ]
2909 # Outputs environment variable assignments that should be passed to remote nodes
2913 local facets=$(get_facets)
2916 for var in ${!MODOPTS_*}; do
2917 value=${!var//\"/\\\"}
2918 echo -n " ${var}=\"$value\""
2921 for facet in ${facets//,/ }; do
2923 if [ -n "${!var}" ]; then
2924 echo -n " $var=${!var}"
2928 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2929 if [ -n "${!var}" ]; then
2930 echo -n " $var=${!var}"
2934 if [ -n "$FSTYPE" ]; then
2935 echo -n " FSTYPE=$FSTYPE"
2938 for var in LNETLND NETTYPE; do
2939 if [ -n "${!var}" ]; then
2940 echo -n " $var=${!var}"
2947 # do not stripe off hostname if verbose, bug 19215
2948 if [ x$1 = x--verbose ]; then
2956 if single_local_node $rnodes; then
2958 do_nodev $rnodes "$@"
2960 do_node $rnodes "$@"
2965 # This is part from do_node
2968 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2969 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2971 export FANOUT=$(get_node_count "${rnodes//,/ }")
2973 echo "CMD: $rnodes $@" >&2
2974 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2977 # do not replace anything from pdsh output if -N is used
2978 # -N Disable hostname: prefix on lines of output.
2979 if $verbose || [[ $myPDSH = *-N* ]]; then
2980 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2982 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2984 return ${PIPESTATUS[0]}
2988 # Execute commands on a single service's host
2990 # The \a facet (service) may be on a local or remote node, which is
2991 # determined at the time the command is run.
2993 # usage: do_facet $facet command [arg ...]
2997 local HOST=$(facet_active_host $facet)
2998 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3002 # Function: do_facet_random_file $FACET $FILE $SIZE
3003 # Creates FILE with random content on the given FACET of given SIZE
3005 do_facet_random_file() {
3009 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3010 do_facet $facet "$cmd 2>/dev/null"
3013 do_facet_create_file() {
3017 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3018 do_facet $facet "$cmd 2>/dev/null"
3022 do_nodes --verbose "$@"
3028 # make sure its not already running
3030 rm -f $TMP/${facet}active
3031 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3032 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3034 if [[ $(facet_fstype $facet) == zfs ]]; then
3036 # After formatting a ZFS target, "cachefile=none" property will
3037 # be set on the ZFS storage pool so that the pool is not
3038 # automatically imported on system startup. And then the pool
3039 # will be exported so as to leave the importing and exporting
3040 # operations handled by mount_facet() and stop() separately.
3042 refresh_partition_table $facet $(facet_vdevice $facet)
3043 disable_zpool_cache $facet
3048 # Device formatted as ost
3051 local DEVNAME=OSTDEV$num
3053 local fstype=$(facet_fstype ost$num)
3057 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3058 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3060 #try $OSTZFSDEVn - independent of vdev
3061 DEVNAME=OSTZFSDEV$num
3062 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3064 error "unknown fstype!";;
3070 # Physical device location of data
3076 local fstype=$(facet_fstype ost$num)
3080 # vdevs are not supported by ldiskfs
3083 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3084 # Device formatted by zfs
3086 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3088 error "unknown fstype!";;
3094 # Logical device formatted for lustre
3097 local DEVNAME=MDSDEV$num
3099 local fstype=$(facet_fstype mds$num)
3103 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3104 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3106 # try $MDSZFSDEVn - independent of vdev
3107 DEVNAME=MDSZFSDEV$num
3108 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3110 error "unknown fstype!";;
3116 # Physical location of data
3120 local fstype=$(facet_fstype mds$num)
3124 # vdevs are not supported by ldiskfs
3127 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3128 # Device formatted by ZFS
3129 local DEVNAME=MDSDEV$num
3130 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3132 error "unknown fstype!";;
3140 local fstype=$(facet_fstype mgs)
3144 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3145 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3146 DEVPTR=$(mdsdevname 1)
3151 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3152 ( [ -z "$MGSZFSDEV" ] &&
3153 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3154 DEVPTR=$(mdsdevname 1)
3156 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3159 error "unknown fstype!";;
3168 local fstype=$(facet_fstype mgs)
3172 # vdevs are not supported by ldiskfs
3175 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3176 ( [ -z "$MGSDEV" ] &&
3177 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3178 VDEVPTR=$(mdsvdevname 1)
3179 elif [ -n "$MGSDEV" ]; then
3183 error "unknown fstype!";;
3191 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3193 local var=${facet}_MOUNT
3194 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3201 local dev=$(facet_device $facet)
3202 local mnt=$(facet_mntpt $facet)
3205 if ! do_facet $facet test -b $dev; then
3208 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3213 local dev=$(facet_device $facet)
3214 local mnt=$(facet_mntpt $facet)
3216 do_facet $facet umount -d $mnt
3220 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3225 local ds=$(facet_device $facet)
3226 local mnt=$(facet_mntpt $facet)
3231 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3232 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3233 do_facet $facet $ZFS set canmount=noauto $ds
3235 # The "legacy" mount method is used here because "zfs unmount $mnt"
3236 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3237 # targets are not available at the time, the stat(2) on $MOUNT will
3240 do_facet $facet $ZFS set mountpoint=legacy $ds
3241 do_facet $facet mount -t zfs $ds $mnt
3242 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3243 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3248 local ds=$(facet_device $facet)
3249 local mnt=$(facet_mntpt $facet)
3250 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3251 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3252 local mntpt=${!var_mntpt}
3253 local canmnt=${!var_canmnt}
3257 do_facet $facet umount $mnt
3258 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3259 do_facet $facet $ZFS set canmount=$canmnt $ds
3265 local fstype=$(facet_fstype $facet)
3267 mount_$fstype $facet
3272 local fstype=$(facet_fstype $facet)
3274 unmount_$fstype $facet
3281 # make sure we are using the primary server, so test-framework will
3282 # be able to clean up properly.
3283 activemds=`facet_active mds1`
3284 if [ $activemds != "mds1" ]; then
3288 local clients=$CLIENTS
3289 [ -z $clients ] && clients=$(hostname)
3291 zconf_umount_clients $clients $MOUNT "$*" || true
3292 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3294 [ "$CLIENTONLY" ] && return
3295 # The add fn does rm ${facet}active file, this would be enough
3296 # if we use do_facet <facet> only after the facet added, but
3297 # currently we use do_facet mds in local.sh
3298 for num in `seq $MDSCOUNT`; do
3300 rm -f ${TMP}/mds${num}active
3302 combined_mgs_mds && rm -f $TMP/mgsactive
3304 for num in `seq $OSTCOUNT`; do
3306 rm -f $TMP/ost${num}active
3309 if ! combined_mgs_mds ; then
3316 cleanup_echo_devs () {
3317 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3319 for dev in $devs; do
3320 $LCTL --device $dev cleanup
3321 $LCTL --device $dev detach
3326 nfs_client_mode && return
3335 combined_mgs_mds () {
3336 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3337 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3341 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3345 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3351 local fsname=${3:-"$FSNAME"}
3352 local type=$(facet_type $facet)
3353 local index=$(facet_index $facet)
3354 local fstype=$(facet_fstype $facet)
3355 local host=$(facet_host $facet)
3360 if [ $type == MGS ] || ( [ $type == MDS ] &&
3361 [ "$dev" == $(mgsdevname) ] &&
3362 [ "$host" == "$(facet_host mgs)" ] ); then
3365 opts="--mgsnode=$MGSNID"
3368 if [ $type != MGS ]; then
3369 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3373 var=${facet}failover_HOST
3374 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3375 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3378 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3379 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3381 if [ $type == MDS ]; then
3382 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3383 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3384 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3385 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3386 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3388 if [ $fstype == ldiskfs ]; then
3389 # Check for wide striping
3390 if [ $OSTCOUNT -gt 160 ]; then
3391 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3392 fs_mkfs_opts+="-O large_xattr"
3395 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3396 if [ ! -z $EJOURNAL ]; then
3397 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3399 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3403 if [ $type == OST ]; then
3404 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3405 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3407 if [ $fstype == ldiskfs ]; then
3408 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3412 opts+=" --backfstype=$fstype"
3415 if [ -n "${!var}" ]; then
3416 opts+=" --device-size=${!var}"
3419 var=$(upper $fstype)_MKFS_OPTS
3420 fs_mkfs_opts+=${!var:+" ${!var}"}
3422 var=${type}_FS_MKFS_OPTS