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 [ "$TESTSUITE" == "lfsck" ] && return 0
75 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
77 local form="%-13s %-17s %-9s %s %s\n"
78 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
79 echo "------------------------------------------------------------------------------------"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 [ "${!O}" = "no" ] && continue || true
83 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
84 local log=${TMP}/${o}.log
85 if is_sanity_benchmark $o; then
86 log=${TMP}/sanity-benchmark.log
91 local status=Unfinished
93 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
95 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
96 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
97 total=$(grep duration $log | awk '{ print $2 }')
98 if [ "${!O}" = "done" ]; then
102 local durations=$(egrep "^PASS|^FAIL" $log |
103 tr -d "("| sed s/s\)$//g |
104 awk '{ print $2":"$3"|" }')
105 details=$(printf "%s\n%s %s %s\n" "$details" \
106 "DDETAILS" "$O" "$(echo $durations)")
109 printf "$form" $status "$O" "${total}" "E=$skipped"
110 printf "$form" "-" "-" "-" "S=$(echo $slow)"
113 for O in $DEFAULT_SUITES; do
114 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
115 if [ "${!O}" = "no" ]; then
116 printf "$form" "Skipped" "$O" ""
120 # print the detailed tests durations if DDETAILS=true
127 export LUSTRE=$(absolute_path $LUSTRE)
128 export TESTSUITE=$(basename $0 .sh)
129 export TEST_FAILED=false
130 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
131 export RPC_MODE=${RPC_MODE:-false}
133 export MKE2FS=$MKE2FS
134 if [ -z "$MKE2FS" ]; then
135 if which mkfs.ldiskfs >/dev/null 2>&1; then
136 export MKE2FS=mkfs.ldiskfs
142 export DEBUGFS=$DEBUGFS
143 if [ -z "$DEBUGFS" ]; then
144 if which debugfs.ldiskfs >/dev/null 2>&1; then
145 export DEBUGFS=debugfs.ldiskfs
147 export DEBUGFS=debugfs
151 export TUNE2FS=$TUNE2FS
152 if [ -z "$TUNE2FS" ]; then
153 if which tunefs.ldiskfs >/dev/null 2>&1; then
154 export TUNE2FS=tunefs.ldiskfs
156 export TUNE2FS=tune2fs
160 export E2LABEL=$E2LABEL
161 if [ -z "$E2LABEL" ]; then
162 if which label.ldiskfs >/dev/null 2>&1; then
163 export E2LABEL=label.ldiskfs
165 export E2LABEL=e2label
169 export DUMPE2FS=$DUMPE2FS
170 if [ -z "$DUMPE2FS" ]; then
171 if which dumpfs.ldiskfs >/dev/null 2>&1; then
172 export DUMPE2FS=dumpfs.ldiskfs
174 export DUMPE2FS=dumpe2fs
178 export E2FSCK=$E2FSCK
179 if [ -z "$E2FSCK" ]; then
180 if which fsck.ldiskfs >/dev/null 2>&1; then
181 export E2FSCK=fsck.ldiskfs
187 export RESIZE2FS=$RESIZE2FS
188 if [ -z "$RESIZE2FS" ]; then
189 if which resizefs.ldiskfs >/dev/null 2>&1; then
190 export RESIZE2FS=resizefs.ldiskfs
192 export RESIZE2FS=resize2fs
196 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
197 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
198 export FSCK_MAX_ERR=4 # File system errors left uncorrected
200 export ZFS=${ZFS:-zfs}
201 export ZPOOL=${ZPOOL:-zpool}
202 export ZDB=${ZDB:-zdb}
203 export PARTPROBE=${PARTPROBE:-partprobe}
205 #[ -d /r ] && export ROOT=${ROOT:-/r}
206 export TMP=${TMP:-$ROOT/tmp}
207 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
208 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
209 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
211 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
212 if ! echo $PATH | grep -q $LUSTRE/utils; then
213 export PATH=$LUSTRE/utils:$PATH
215 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
216 export PATH=$LUSTRE/utils/gss:$PATH
218 if ! echo $PATH | grep -q $LUSTRE/tests; then
219 export PATH=$LUSTRE/tests:$PATH
221 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
222 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
224 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
225 [ ! -f "$LST" ] && export LST=$(which lst)
226 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
227 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
228 export MCREATE=${MCREATE:-mcreate}
229 # Ubuntu, at least, has a truncate command in /usr/bin
230 # so fully path our truncate command.
231 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
232 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
233 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
234 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
235 export PATH=$LUSTRE/tests/racer:$PATH:
237 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
238 export PATH=$LUSTRE/tests/mpi:$PATH
240 export RSYNC_RSH=${RSYNC_RSH:-rsh}
242 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
243 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
244 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
245 [ ! -f "$LFS" ] && export LFS=$(which lfs)
246 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
247 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
249 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
250 if [ ! -f "$L_GETIDENTITY" ]; then
251 if `which l_getidentity > /dev/null 2>&1`; then
252 export L_GETIDENTITY=$(which l_getidentity)
254 export L_GETIDENTITY=NONE
257 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
258 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
259 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
260 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
261 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
262 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
263 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
264 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
265 [ ! -f "$LUSTRE_RMMOD" ] &&
266 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
267 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
268 [ ! -f "$LFS_MIGRATE" ] &&
269 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
270 export NAME=${NAME:-local}
271 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
272 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
273 export LGSSD=$(which lgssd)
274 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
275 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
276 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
278 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
281 if [ "$ACCEPTOR_PORT" ]; then
282 export PORT_OPT="--port $ACCEPTOR_PORT"
287 echo "Using GSS/krb5 ptlrpc security flavor"
288 which lgss_keyring > /dev/null 2>&1 || \
289 error_exit "built with gss disabled! SEC=$SEC"
300 IDENTITY_UPCALL=false
304 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
306 # Paths on remote nodes, if different
307 export RLUSTRE=${RLUSTRE:-$LUSTRE}
308 export RPWD=${RPWD:-$PWD}
309 export I_MOUNTED=${I_MOUNTED:-"no"}
310 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
311 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
312 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
313 ! -f $LUSTRE/mdt/mdt.ko ]; then
314 export CLIENTMODSONLY=yes
317 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
318 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
322 while getopts "rvwf:" opt $*; do
325 r) REFORMAT=--reformat;;
327 w) WRITECONF=writeconf;;
332 shift $((OPTIND - 1))
335 # print the durations of each test if "true"
336 DDETAILS=${DDETAILS:-false}
337 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
347 ncpts=$(do_facet $facet "lctl get_param -n " \
348 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
350 if [ $ncpts -eq 0 ]; then
358 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
359 eval set -- $(tr "[:punct:]" " " <<< $*)
361 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
364 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
365 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
368 /sbin/lsmod | grep -q "^\<$1\>"
371 # Load a module on the system where this is running.
373 # usage: load_module module_name [module arguments for insmod/modprobe]
375 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
376 # will be used as the arguments. Otherwise arguments will be obtained from
377 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
384 BASE=`basename $module $EXT`
386 module_loaded ${BASE} && return
388 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
390 if [ $# -eq 0 ]; then
391 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
392 # Bash until 4.x, so we resort to eval.
393 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
394 eval set -- \$$optvar
395 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
396 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
398 opt=$(awk -v var="^options $BASE" '$0 ~ var \
399 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
400 set -- $(echo -n $opt)
402 # Ensure we have accept=all for lnet
403 if [ $(basename $module) = lnet ]; then
404 # OK, this is a bit wordy...
405 local arg accept_all_present=false
408 [ "$arg" = accept=all ] && \
409 accept_all_present=true
411 $accept_all_present || set -- "$@" accept=all
417 [ $# -gt 0 ] && echo "${module} options: '$*'"
419 # Note that insmod will ignore anything in modprobe.conf, which is why
420 # we're passing options on the command-line.
421 if [[ "$BASE" == "lnet_selftest" ]] &&
422 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
423 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
424 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
425 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
426 insmod ${LUSTRE}/${module}${EXT} "$@"
428 # must be testing a "make install" or "rpm" installation
429 # note failed to load ptlrpc_gss is considered not fatal
430 if [[ "$BASE" == "ptlrpc_gss" ]]; then
431 modprobe $BASE "$@" 2>/dev/null ||
432 echo "gss/krb5 is not supported"
439 llite_lloop_enabled() {
440 local n1=$(uname -r | cut -d. -f1)
441 local n2=$(uname -r | cut -d. -f2)
442 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
444 # load the llite_lloop module for < 2.6.32 kernels
445 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
446 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
453 load_modules_local() {
454 if [ -n "$MODPROBE" ]; then
456 echo "Using modprobe to load modules"
460 echo Loading modules from $LUSTRE
464 if [ -f /sys/devices/system/cpu/online ]; then
465 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
466 echo "detected $ncpus online CPUs by sysfs"
468 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
470 if [ $rc -eq 0 ]; then
471 echo "detected $ncpus online CPUs by getconf"
473 echo "Can't detect number of CPUs"
478 # if there is only one CPU core, libcfs can only create one partition
479 # if there is more than 4 CPU cores, libcfs should create multiple CPU
480 # partitions. So we just force libcfs to create 2 partitions for
481 # system with 2 or 4 cores
482 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
483 # force to enable multiple CPU partitions
484 echo "Force libcfs to create 2 CPU partitions"
485 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
487 echo "libcfs will create CPU partition based on online CPUs"
490 load_module ../libcfs/libcfs/libcfs
492 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
493 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
494 load_module ../lnet/lnet/lnet
497 LNETLND="o2iblnd/ko2iblnd"
502 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
503 load_module ../lnet/klnds/$LNETLND
504 load_module obdclass/obdclass
505 load_module ptlrpc/ptlrpc
506 load_module ptlrpc/gss/ptlrpc_gss
514 load_module obdecho/obdecho
515 if ! client_only; then
516 SYMLIST=/proc/kallsyms
517 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
518 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
519 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
520 load_module lfsck/lfsck
521 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
522 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
524 load_module osd-zfs/osd_zfs
526 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
527 grep -q exportfs_decode_fh $SYMLIST ||
528 { modprobe exportfs 2> /dev/null || true; }
529 load_module ../ldiskfs/ldiskfs
530 load_module osd-ldiskfs/osd_ldiskfs
542 load_module llite/lustre
543 llite_lloop_enabled && load_module llite/llite_lloop
544 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
546 rm -f $OGDB/ogdb-$HOSTNAME
547 $LCTL modules > $OGDB/ogdb-$HOSTNAME
549 # 'mount' doesn't look in $PATH, just sbin
550 local mount_lustre=$LUSTRE/utils/mount.lustre
551 if [ -f $mount_lustre ]; then
552 local sbin_mount=/sbin/mount.lustre
553 if grep -qw "$sbin_mount" /proc/mounts; then
554 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
556 if ! grep -qw "$sbin_mount" /proc/mounts; then
557 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
558 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
559 cat <<- EOF > "$sbin_mount"
562 echo "This $sbin_mount just a mountpoint." 1>&2
563 echo "It is never supposed to be run." 1>&2
564 logger -p emerg -- "using stub $sbin_mount $@"
567 chmod a+x $sbin_mount
569 mount --bind $mount_lustre $sbin_mount ||
570 error "can't bind $mount_lustre to $sbin_mount"
578 # load modules on remote nodes optionally
579 # lustre-tests have to be installed on these nodes
580 if $LOAD_MODULES_REMOTE; then
581 local list=$(comma_list $(remote_nodes_list))
582 if [ -n "$list" ]; then
583 echo "loading modules on: '$list'"
584 do_rpc_nodes "$list" load_modules_local
590 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
591 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
592 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
593 echo "$LEAK_LUSTRE" 1>&2
594 echo "$LEAK_PORTALS" 1>&2
595 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
596 echo "Memory leaks detected"
597 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
603 wait_exit_ST client # bug 12845
605 $LUSTRE_RMMOD ldiskfs || return 2
607 if $LOAD_MODULES_REMOTE; then
608 local list=$(comma_list $(remote_nodes_list))
609 if [ -n "$list" ]; then
610 echo "unloading modules on: '$list'"
611 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
612 do_rpc_nodes "$list" check_mem_leak
616 local sbin_mount=/sbin/mount.lustre
617 if grep -qe "$sbin_mount " /proc/mounts; then
618 umount $sbin_mount || true
619 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
623 check_mem_leak || return 254
625 echo "modules unloaded."
630 local facet=${1:-$SINGLEMDS}
631 local fstype=$(facet_fstype $facet)
634 ldiskfs) size=50;; # largest seen is 44, leave some headroom
635 zfs) size=400;; # largest seen is 384
641 check_gss_daemon_nodes() {
645 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
646 if [ \\\"\\\$num\\\" -ne 1 ]; then
647 echo \\\$num instance of $dname;
652 check_gss_daemon_facet() {
656 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
657 if [ $num -ne 1 ]; then
658 echo "$num instance of $dname on $facet"
667 echo Stopping $@ on $list
668 do_nodes $list "killall -2 $@ 2>/dev/null || true"
671 # start gss daemons on all nodes, or
672 # "daemon" on "list" if set
673 start_gss_daemons() {
677 if [ "$list" ] && [ "$daemon" ] ; then
678 echo "Starting gss daemon on nodes: $list"
679 do_nodes $list "$daemon" || return 8
683 local list=$(comma_list $(mdts_nodes))
684 echo "Starting gss daemon on mds: $list"
685 do_nodes $list "$LSVCGSSD -v" || return 1
687 do_nodes $list "$LGSSD -v" || return 2
690 list=$(comma_list $(osts_nodes))
691 echo "Starting gss daemon on ost: $list"
692 do_nodes $list "$LSVCGSSD -v" || return 3
693 # starting on clients
695 local clients=${CLIENTS:-`hostname`}
697 echo "Starting $LGSSD on clients $clients "
698 do_nodes $clients "$LGSSD -v" || return 4
701 # wait daemons entering "stable" status
705 # check daemons are running
707 list=$(comma_list $(mdts_nodes) $(osts_nodes))
708 check_gss_daemon_nodes $list lsvcgssd || return 5
710 list=$(comma_list $(mdts_nodes))
711 check_gss_daemon_nodes $list lgssd || return 6
714 check_gss_daemon_nodes $clients lgssd || return 7
719 local list=$(comma_list $(mdts_nodes))
721 send_sigint $list lsvcgssd lgssd
723 list=$(comma_list $(osts_nodes))
724 send_sigint $list lsvcgssd
726 list=${CLIENTS:-`hostname`}
727 send_sigint $list lgssd
732 if ! module_loaded ptlrpc_gss; then
733 load_module ptlrpc/gss/ptlrpc_gss
734 module_loaded ptlrpc_gss ||
735 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
738 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
741 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
743 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
751 # maybe cleanup credential cache?
757 local var=${facet}_svc
765 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
766 tr '[:lower:]' '[:upper:]'
772 if [ $facet == mgs ]; then
776 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
784 if [ -n "${!var}" ]; then
789 var=$(facet_type $facet)FSTYPE
790 if [ -n "${!var}" ]; then
795 if [ -n "$FSTYPE" ]; then
800 if [[ $facet == mgs ]] && combined_mgs_mds; then
812 local facets=$(get_facets)
815 for facet in ${facets//,/ }; do
816 if [ $node == $(facet_host $facet) ] ||
817 [ $node == "$(facet_failover_host $facet)" ]; then
818 fstype=$(facet_fstype $facet)
819 if [[ $fstypes != *$fstype* ]]; then
820 fstypes+="${fstypes:+,}$fstype"
829 local num=$(facet_number $facet)
832 if [[ $(facet_type $facet) = OST ]]; then
834 if [[ -n "${!index}" ]]; then
839 index=${OST_INDICES[num - 1]}
842 [[ -n "$index" ]] || index=$((num - 1))
850 local fstype=$(facet_fstype $facet)
854 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
856 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
857 ${dev} 2>/dev/null");;
859 error "unknown fstype!";;
867 local device=$(mdsdevname $num)
868 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
874 local device=$(ostdevname $num)
875 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
880 # Get the device of a facet.
887 mgs) device=$(mgsdevname) ;;
888 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
889 ost*) device=$(ostdevname $(facet_number $facet)) ;;
890 fs2mds) device=$(mdsdevname 1_2) ;;
891 fs2ost) device=$(ostdevname 1_2) ;;
892 fs3ost) device=$(ostdevname 2_2) ;;
900 # Get the virtual device of a facet.
907 mgs) device=$(mgsvdevname) ;;
908 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
909 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
910 fs2mds) device=$(mdsvdevname 1_2) ;;
911 fs2ost) device=$(ostvdevname 1_2) ;;
912 fs3ost) device=$(ostvdevname 2_2) ;;
920 # Re-read the partition table on failover partner host.
921 # After a ZFS storage pool is created on a shared device, the partition table
922 # on the device may change. However, the operating system on the failover
923 # host may not notice the change automatically. Without the up-to-date partition
924 # block devices, 'zpool import ..' cannot find the labels, whose positions are
925 # relative to partition rather than disk beginnings.
927 # This function performs partprobe on the failover host to make it re-read the
930 refresh_partition_table() {
935 host=$(facet_passive_host $facet)
936 if [[ -n "$host" ]]; then
937 do_node $host "$PARTPROBE $device"
942 # Get ZFS storage pool name.
949 device=$(facet_device $facet)
950 # poolname is string before "/"
951 poolname="${device%%/*}"
957 # Create ZFS storage pool.
964 local opts=${@:-"-o cachefile=none"}
966 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
967 $ZPOOL create -f $opts $poolname $vdev"
971 # Create ZFS file system.
977 local opts=${@:-"-o mountpoint=legacy"}
979 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
980 $ZFS create $opts $dataset"
984 # Export ZFS storage pool.
985 # Before exporting the pool, all datasets within the pool should be unmounted.
993 poolname=$(zpool_name $facet)
995 if [[ -n "$poolname" ]]; then
996 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
997 grep -q ^$poolname/ /proc/mounts ||
998 $ZPOOL export $opts $poolname"
1003 # Destroy ZFS storage pool.
1004 # Destroy the given pool and free up any devices for other use. This command
1005 # tries to unmount any active datasets before destroying the pool.
1006 # -f Force any active datasets contained within the pool to be unmounted.
1010 local poolname=${2:-$(zpool_name $facet)}
1012 if [[ -n "$poolname" ]]; then
1013 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1014 $ZPOOL destroy -f $poolname"
1019 # Import ZFS storage pool.
1020 # Force importing, even if the pool appears to be potentially active.
1025 local opts=${@:-"-o cachefile=none"}
1028 poolname=$(zpool_name $facet)
1030 if [[ -n "$poolname" ]]; then
1031 opts+=" -d $(dirname $(facet_vdevice $facet))"
1032 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1033 $ZPOOL import -f $opts $poolname"
1038 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1039 # is not automatically imported on system startup.
1041 # In a failover environment, this will provide resource level fencing which
1042 # will ensure that the same ZFS storage pool will not be imported concurrently
1043 # on different nodes.
1045 disable_zpool_cache() {
1049 poolname=$(zpool_name $facet)
1051 if [[ -n "$poolname" ]]; then
1052 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1057 # This and set_osd_param() shall be used to access OSD parameters
1058 # once existed under "obdfilter":
1063 # writethrough_cache_enable
1067 local device=${2:-$FSNAME-OST*}
1070 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1071 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1076 local device=${2:-$FSNAME-OST*}
1080 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1081 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1085 local dz=${1:-$DEBUG_SIZE}
1087 if [ -f /sys/devices/system/cpu/possible ]; then
1088 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1090 local cpus=$(getconf _NPROCESSORS_CONF)
1093 # bug 19944, adjust size to be -gt num_possible_cpus()
1094 # promise 2MB for every cpu at least
1095 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1098 lctl set_param debug_mb=$dz
1101 set_default_debug () {
1102 local debug=${1:-"$PTLDEBUG"}
1103 local subsys=${2:-"$SUBSYSTEM"}
1104 local debug_size=${3:-$DEBUG_SIZE}
1106 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1107 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1109 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1112 set_default_debug_nodes () {
1115 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1116 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1120 do_rpc_nodes "$nodes" set_default_debug \
1121 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1124 set_default_debug_facet () {
1126 local node=$(facet_active_host $facet)
1127 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1129 set_default_debug_nodes $node
1134 local facets=${1:-$(get_facets)}
1137 for facet in ${facets//,/ }; do
1140 [ $RC -eq 0 ] && continue
1142 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1143 skip "Restart of $facet failed!." && touch $LU482_FAILED
1145 error "Restart of $facet failed!"
1152 # Add argument "arg" (e.g., "loop") to the comma-separated list
1153 # of arguments for option "opt" (e.g., "-o") on command
1154 # line "opts" (e.g., "-o flock").
1160 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1162 if echo "$opts" | grep -q $opt_pattern; then
1163 opts=$(echo "$opts" | sed -e \
1164 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1166 opts+="${opts:+ }$opt $arg"
1174 local dev=$(facet_active $facet)_dev
1175 local opt=${facet}_opt
1176 local mntpt=$(facet_mntpt $facet)
1177 local opts="${!opt} $@"
1179 if [ $(facet_fstype $facet) == ldiskfs ] &&
1180 ! do_facet $facet test -b ${!dev}; then
1181 opts=$(csa_add "$opts" -o loop)
1184 if [[ $(facet_fstype $facet) == zfs ]]; then
1185 # import ZFS storage pool
1186 import_zpool $facet || return ${PIPESTATUS[0]}
1189 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1190 # for testing LU-482 error handling in mount_facets() and test_0a()
1191 if [ -f $TMP/test-lu482-trigger ]; then
1194 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1198 if [ $RC -ne 0 ]; then
1199 echo "Start of ${!dev} on ${facet} failed ${RC}"
1201 set_default_debug_facet $facet
1203 if [[ $facet == mds* ]]; then
1205 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1209 label=$(devicelabel ${facet} ${!dev})
1210 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1211 eval export ${facet}_svc=${label}
1212 echo Started ${label}
1217 # start facet device options
1223 eval export ${facet}_dev=${device}
1224 eval export ${facet}_opt=\"$@\"
1226 local varname=${facet}failover_dev
1227 if [ -n "${!varname}" ] ; then
1228 eval export ${facet}failover_dev=${!varname}
1230 eval export ${facet}failover_dev=$device
1233 local mntpt=$(facet_mntpt $facet)
1234 do_facet ${facet} mkdir -p $mntpt
1235 eval export ${facet}_MOUNT=$mntpt
1236 mount_facet ${facet}
1239 if [[ $facet == mds* ]]; then
1241 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1252 local HOST=`facet_active_host $facet`
1253 [ -z $HOST ] && echo stop: no host for $facet && return 0
1255 local mntpt=$(facet_mntpt $facet)
1256 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1257 if [ ${running} -ne 0 ]; then
1258 echo "Stopping $mntpt (opts:$@) on $HOST"
1259 do_facet ${facet} umount -d $@ $mntpt
1262 # umount should block, but we should wait for unrelated obd's
1263 # like the MGS or MGC to also stop.
1264 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1266 if [[ $(facet_fstype $facet) == zfs ]]; then
1267 # export ZFS storage pool
1272 # save quota version (both administrative and operational quotas)
1273 # add an additional parameter if mountpoint is ever different from $MOUNT
1275 # XXX This function is kept for interoperability with old server (< 2.3.50),
1276 # it should be removed whenever we drop the interoperability for such
1278 quota_save_version() {
1279 local fsname=${2:-$FSNAME}
1281 local ver=$(tr -c -d "123" <<< $spec)
1282 local type=$(tr -c -d "ug" <<< $spec)
1284 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1286 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1288 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1290 local osts=$(get_facets OST)
1291 for ost in ${osts//,/ }; do
1293 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1297 # client could mount several lustre
1299 # XXX This function is kept for interoperability with old server (< 2.3.50),
1300 # it should be removed whenever we drop the interoperability for such
1303 local fsname=${1:-$FSNAME}
1305 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1307 do_nodes $(comma_list $(osts_nodes)) \
1308 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1312 # XXX This function is kept for interoperability with old server (< 2.3.50),
1313 # it should be removed whenever we drop the interoperability for such
1315 restore_quota_old() {
1316 local mntpt=${1:-$MOUNT}
1317 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1318 if [ ! "$old_QUOTA_TYPE" ] ||
1319 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1322 quota_save_version $old_QUOTA_TYPE
1325 # XXX This function is kept for interoperability with old server (< 2.3.50),
1326 # it should be removed whenever we drop the interoperability for such
1331 # no quota enforcement for now and accounting works out of the box
1334 # We need save the original quota_type params, and restore them after testing
1336 # Suppose that quota type the same on mds and ost
1337 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1338 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1339 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1340 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1341 export old_QUOTA_TYPE=$quota_type
1342 quota_save_version $QUOTA_TYPE
1344 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1345 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1348 local quota_usrs=$QUOTA_USERS
1350 # get_filesystem_size
1351 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1352 local blk_soft=$((disksz + 1024))
1353 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1355 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1356 local i_soft=$Inodes
1357 local i_hard=$((i_soft + i_soft / 20))
1359 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1360 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1363 for usr in $quota_usrs; do
1364 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1366 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1368 eval $cmd || error "$cmd FAILED!"
1370 # display the quota status
1371 echo "Quota settings for $usr : "
1372 $LFS quota -v -u $usr $mntpt || true
1376 # get mdt quota type
1378 local varsvc=${SINGLEMDS}_svc
1379 do_facet $SINGLEMDS $LCTL get_param -n \
1380 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1383 # get ost quota type
1385 # All OSTs should have same quota type
1386 local varsvc=ost1_svc
1387 do_facet ost1 $LCTL get_param -n \
1388 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1391 # restore old quota type settings
1393 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1398 if [ "$old_MDT_QUOTA_TYPE" ]; then
1399 do_facet mgs $LCTL conf_param \
1400 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1402 if [ "$old_OST_QUOTA_TYPE" ]; then
1403 do_facet mgs $LCTL conf_param \
1404 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1408 # Handle the case when there is a space in the lfs df
1409 # "filesystem summary" line the same as when there is no space.
1410 # This will allow fixing the "lfs df" summary line in the future.
1412 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1415 # Get free inodes on the MDT specified by mdt index, free indoes on
1416 # the whole filesystem will be returned when index == -1.
1422 if [ $index -eq -1 ]; then
1425 mdt_uuid=$(mdtuuid_from_index $index)
1428 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1433 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1440 # save old quota type & set new quota type
1441 local mdt_qtype=$(mdt_quota_type)
1442 local ost_qtype=$(ost_quota_type)
1444 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1445 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1447 export old_MDT_QUOTA_TYPE=$mdt_qtype
1448 export old_OST_QUOTA_TYPE=$ost_qtype
1450 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1451 error "set mdt quota type failed"
1452 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1453 error "set ost quota type failed"
1455 local quota_usrs=$QUOTA_USERS
1457 # get_filesystem_size
1458 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1459 local blk_soft=$((disksz + 1024))
1460 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1462 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1463 local i_soft=$inodes
1464 local i_hard=$((i_soft + i_soft / 20))
1466 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1467 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1468 "inode-hardlimit: $i_hard"
1471 for usr in $quota_usrs; do
1472 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1474 cmd="$LFS setquota -$type $usr -b $blk_soft"
1475 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1477 eval $cmd || error "$cmd FAILED!"
1479 # display the quota status
1480 echo "Quota settings for $usr : "
1481 $LFS quota -v -u $usr $mntpt || true
1488 local opts=${3:-$MOUNT_OPTS}
1489 opts=${opts:+-o $opts}
1490 local flags=${4:-$MOUNT_FLAGS}
1492 local device=$MGSNID:/$FSNAME
1493 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1494 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1498 echo "Starting client: $client: $flags $opts $device $mnt"
1499 do_node $client mkdir -p $mnt
1500 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1502 set_default_debug_nodes $client
1514 [ "$3" ] && force=-f
1515 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1516 if [ $running -ne 0 ]; then
1517 echo "Stopping client $client $mnt (opts:$force)"
1518 do_node $client lsof -t $mnt || need_kill=no
1519 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1520 pids=$(do_node $client lsof -t $mnt | sort -u);
1521 if [ -n $pids ]; then
1522 do_node $client kill -9 $pids || true
1526 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1527 if [ $busy -ne 0 ] ; then
1528 echo "$mnt is still busy, wait one second" && sleep 1
1529 do_node $client umount $force $mnt
1534 # nodes is comma list
1535 sanity_mount_check_nodes () {
1541 # FIXME: assume that all cluster nodes run the same os
1542 [ "$(uname)" = Linux ] || return 0
1545 for mnt in $mnts ; do
1546 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1547 mpts=\\\$(mount | grep -c $mnt' ');
1548 if [ \\\$running -ne \\\$mpts ]; then
1549 echo \\\$(hostname) env are INSANE!;
1552 [ $? -eq 0 ] || rc=1
1557 sanity_mount_check_servers () {
1558 [ "$CLIENTONLY" ] &&
1559 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1560 echo Checking servers environments
1562 # FIXME: modify get_facets to display all facets wo params
1563 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1567 for facet in ${facets//,/ }; do
1568 node=$(facet_host ${facet})
1569 mntpt=$(facet_mntpt $facet)
1570 sanity_mount_check_nodes $node $mntpt ||
1571 { error "server $node environments are insane!"; return 1; }
1575 sanity_mount_check_clients () {
1576 local clients=${1:-$CLIENTS}
1577 local mntpt=${2:-$MOUNT}
1578 local mntpt2=${3:-$MOUNT2}
1580 [ -z $clients ] && clients=$(hostname)
1581 echo Checking clients $clients environments
1583 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1584 error "clients environments are insane!"
1587 sanity_mount_check () {
1588 sanity_mount_check_servers || return 1
1589 sanity_mount_check_clients || return 2
1592 # mount clients if not mouted
1593 zconf_mount_clients() {
1596 local opts=${3:-$MOUNT_OPTS}
1597 opts=${opts:+-o $opts}
1598 local flags=${4:-$MOUNT_FLAGS}
1600 local device=$MGSNID:/$FSNAME
1601 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1602 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1606 echo "Starting client $clients: $flags $opts $device $mnt"
1609 running=\\\$(mount | grep -c $mnt' ');
1611 if [ \\\$running -eq 0 ] ; then
1613 $MOUNT_CMD $flags $opts $device $mnt;
1616 exit \\\$rc" || return ${PIPESTATUS[0]}
1618 echo "Started clients $clients: "
1619 do_nodes $clients "mount | grep $mnt' '"
1621 set_default_debug_nodes $clients
1626 zconf_umount_clients() {
1631 [ "$3" ] && force=-f
1633 echo "Stopping clients: $clients $mnt (opts:$force)"
1634 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1635 if [ \\\$running -ne 0 ] ; then
1636 echo Stopping client \\\$(hostname) $mnt opts:$force;
1637 lsof $mnt || need_kill=no;
1638 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1639 pids=\\\$(lsof -t $mnt | sort -u);
1640 if [ -n \\\"\\\$pids\\\" ]; then
1644 while umount $force $mnt 2>&1 | grep -q "busy"; do
1645 echo "$mnt is still busy, wait one second" && sleep 1;
1652 echo + $POWER_DOWN $node
1656 shutdown_node_hard () {
1658 local attempts=$SHUTDOWN_ATTEMPTS
1660 for i in $(seq $attempts) ; do
1663 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1664 echo "waiting for $host to fail attempts=$attempts"
1665 [ $i -lt $attempts ] || \
1666 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1672 local mnt=${2:-$MOUNT}
1675 if [ "$FAILURE_MODE" = HARD ]; then
1676 shutdown_node_hard $client
1678 zconf_umount_clients $client $mnt -f
1684 local facets="$(get_facets OST),$(get_facets MDS)"
1687 combined_mgs_mds || facets="$facets,mgs"
1689 for facet in ${facets//,/ }; do
1690 if [ $(facet_active_host $facet) == $host ]; then
1691 affected="$affected $facet"
1695 echo $(comma_list $affected)
1700 local host=${2:-$(facet_host $facet)}
1702 local label=$(convert_facet2label $facet)
1703 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1706 facets_up_on_host () {
1708 local facets=$(facets_on_host $host)
1711 for facet in ${facets//,/ }; do
1712 if $(facet_up $facet $host); then
1713 affected_up="$affected_up $facet"
1717 echo $(comma_list $affected_up)
1723 if [ "$FAILURE_MODE" = HARD ]; then
1724 shutdown_node_hard $(facet_active_host $facet)
1732 echo + $POWER_UP $node
1745 if [ "$FAILURE_MODE" = HARD ]; then
1746 reboot_node $(facet_active_host $facet)
1754 if [ "$FAILURE_MODE" = HARD ]; then
1764 for facet in ${facets//,/ }; do
1765 hosts=$(expand_list $hosts $(facet_host $facet) )
1771 _check_progs_installed () {
1775 for prog in $progs; do
1776 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1777 echo $prog missing on $(hostname)
1784 check_progs_installed () {
1788 do_rpc_nodes "$nodes" _check_progs_installed $@
1791 # recovery-scale functions
1793 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1796 start_client_load() {
1799 local var=$(node_var_name $client)_load
1800 eval export ${var}=$load
1802 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1803 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1804 END_RUN_FILE=$END_RUN_FILE \
1805 LOAD_PID_FILE=$LOAD_PID_FILE \
1806 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1807 TESTNAME=$TESTNAME \
1808 DBENCH_LIB=$DBENCH_LIB \
1809 DBENCH_SRC=$DBENCH_SRC \
1810 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1814 log "Started client load: ${load} on $client"
1816 # get the children process IDs
1817 local pids=$(ps --ppid $ppid -o pid= | xargs)
1818 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1822 start_client_loads () {
1823 local -a clients=(${1//,/ })
1824 local numloads=${#CLIENT_LOADS[@]}
1827 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1828 testnum=$((nodenum % numloads))
1829 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1831 # bug 22169: wait the background threads to start
1835 # only for remote client
1836 check_client_load () {
1838 local var=$(node_var_name $client)_load
1839 local TESTLOAD=run_${!var}.sh
1841 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1843 # bug 18914: try to connect several times not only when
1844 # check ps, but while check_catastrophe also
1847 while [ $RC = 254 -a $tries -gt 0 ]; do
1851 if ! check_catastrophe $client; then
1853 if [ $RC -eq 254 ]; then
1854 # FIXME: not sure how long we shuold sleep here
1858 echo "check catastrophe failed: RC=$RC "
1862 # We can continue try to connect if RC=254
1863 # Just print the warning about this
1864 if [ $RC = 254 ]; then
1865 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1868 # see if the load is still on the client
1871 while [ $RC = 254 -a $tries -gt 0 ]; do
1875 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1880 if [ $RC = 254 ]; then
1881 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1882 # see if we can diagnose a bit why this is
1887 check_client_loads () {
1888 local clients=${1//,/ }
1892 for client in $clients; do
1893 check_client_load $client
1895 if [ "$rc" != 0 ]; then
1896 log "Client load failed on node $client, rc=$rc"
1902 restart_client_loads () {
1903 local clients=${1//,/ }
1904 local expectedfail=${2:-""}
1908 for client in $clients; do
1909 check_client_load $client
1911 if [ "$rc" != 0 -a "$expectedfail" ]; then
1912 local var=$(node_var_name $client)_load
1913 start_client_load $client ${!var}
1914 echo "Restarted client load ${!var}: on $client. Checking ..."
1915 check_client_load $client
1917 if [ "$rc" != 0 ]; then
1918 log "Client load failed to restart on node $client, rc=$rc"
1919 # failure one client load means test fail
1920 # we do not need to check other
1929 # Start vmstat and save its process ID in a file.
1934 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1937 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1938 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1941 # Display the nodes on which client loads failed.
1942 print_end_run_file() {
1946 [ -s $file ] || return 0
1948 echo "Found the END_RUN_FILE file: $file"
1951 # A client load will stop if it finds the END_RUN_FILE file.
1952 # That does not mean the client load actually failed though.
1953 # The first node in END_RUN_FILE is the one we are interested in.
1956 if [ -n "$node" ]; then
1957 local var=$(node_var_name $node)_load
1959 local prefix=$TESTLOG_PREFIX
1960 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1961 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1962 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1964 echo "Client load ${!var} failed on node $node:"
1970 # Stop the process which had its PID saved in a file.
1975 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1977 do_nodes $nodes "test -f $pid_file &&
1978 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1981 # Stop all client loads.
1982 stop_client_loads() {
1983 local nodes=${1:-$CLIENTS}
1986 # stop the client loads
1987 stop_process $nodes $pid_file
1989 # clean up the processes that started them
1990 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1992 # End recovery-scale functions
1994 # verify that lustre actually cleaned up properly
1996 VAR=$(lctl get_param -n catastrophe 2>&1)
1997 if [ $? = 0 ] ; then
1998 if [ $VAR != 0 ]; then
1999 error "LBUG/LASSERT detected"
2002 BUSY=$(dmesg | grep -i destruct || true)
2003 if [ -n "$BUSY" ]; then
2005 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2009 check_mem_leak || exit 204
2011 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2012 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2015 if module_loaded lnet || module_loaded libcfs; then
2016 echo "$TESTSUITE: modules still loaded..." 1>&2
2025 if [[ "$1" == "--verbose" ]]; then
2040 PREV_RESULT=$(do_node $node "$TEST")
2042 RESULT=$(do_node $node "$TEST")
2043 if [[ "$RESULT" == "$FINAL" ]]; then
2044 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2045 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2049 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2050 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2054 [[ $WAIT -ge $MAX ]] && break
2055 [[ $((WAIT % print)) -eq 0 ]] &&
2056 echo "Waiting $((MAX - WAIT)) secs for update"
2057 WAIT=$((WAIT + sleep))
2060 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2064 wait_update_facet() {
2067 wait_update $(facet_active_host $facet) "$@"
2071 do_nodes $(comma_list $(mdts_nodes)) \
2072 "lctl set_param -n osd*.*MDT*.force_sync 1"
2073 do_nodes $(comma_list $(osts_nodes)) \
2074 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2075 grep -v 'Found no match'
2078 wait_delete_completed_mds() {
2079 local MAX_WAIT=${1:-20}
2080 # for ZFS, waiting more time for DMUs to be committed
2081 local ZFS_WAIT=${2:-5}
2083 local stime=$(date +%s)
2088 # find MDS with pending deletions
2089 for node in $(mdts_nodes); do
2090 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2091 2>/dev/null | calc_sum)
2092 if [[ $changes -eq 0 ]]; then
2095 mds2sync="$mds2sync $node"
2097 if [ -z "$mds2sync" ]; then
2100 mds2sync=$(comma_list $mds2sync)
2102 # sync MDS transactions
2103 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2105 # wait till all changes are sent and commmitted by OSTs
2106 # for ldiskfs space is released upon execution, but DMU
2107 # do this upon commit
2110 while [[ $WAIT -ne $MAX_WAIT ]]; do
2111 changes=$(do_nodes $mds2sync \
2112 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2113 #echo "$node: $changes changes on all"
2114 if [[ $changes -eq 0 ]]; then
2116 #echo "delete took $((etime - stime)) seconds"
2118 # the occupied disk space will be released
2119 # only after DMUs are committed
2120 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2121 echo "sleep $ZFS_WAIT for ZFS OSD"
2132 echo "Delete is not completed in $((etime - stime)) seconds"
2133 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2139 # we can use "for" here because we are waiting the slowest
2140 for host in ${hostlist//,/ }; do
2141 check_network "$host" 900
2143 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2150 for facet in ${facetlist//,/ }; do
2151 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2153 wait_for_host $hostlist
2156 _wait_recovery_complete () {
2159 # Use default policy if $2 is not passed by caller.
2160 local MAX=${2:-$(max_recovery_time)}
2165 while [ $WAIT -lt $MAX ]; do
2166 STATUS=$(lctl get_param -n $param | grep status)
2168 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2171 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2173 echo "$param recovery not done in $MAX sec. $STATUS"
2177 wait_recovery_complete () {
2180 # with an assumption that at_max is the same on all nodes
2181 local MAX=${2:-$(max_recovery_time)}
2184 if [ "$FAILURE_MODE" = HARD ]; then
2185 facets=$(facets_on_host $(facet_active_host $facet))
2187 echo affected facets: $facets
2189 # we can use "for" here because we are waiting the slowest
2190 for facet in ${facets//,/ }; do
2191 local var_svc=${facet}_svc
2192 local param="*.${!var_svc}.recovery_status"
2194 local host=$(facet_active_host $facet)
2195 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2199 wait_mds_ost_sync () {
2200 # just because recovery is done doesn't mean we've finished
2201 # orphan cleanup. Wait for llogs to get synchronized.
2202 echo "Waiting for orphan cleanup..."
2203 # MAX value includes time needed for MDS-OST reconnection
2204 local MAX=$(( TIMEOUT * 2 ))
2205 local WAIT_TIMEOUT=${1:-$MAX}
2208 local list=$(comma_list $(mdts_nodes))
2209 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2210 if ! do_facet $SINGLEMDS \
2211 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2213 # old way, use mds_sync
2215 list=$(comma_list $(osts_nodes))
2216 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2219 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2220 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2221 local -a sync=($(do_nodes $list "$cmd"))
2224 for ((i=0; i<${#sync[@]}; i++)); do
2226 [ ${sync[$i]} -eq 1 ] && continue
2228 [ ${sync[$i]} -eq 0 ] && continue
2230 # there is a not finished MDS-OST synchronization
2234 sleep 2 # increase waiting time and cover statfs cache
2235 [ ${con} -eq 1 ] && return 0
2236 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2240 # show which nodes are not finished.
2241 do_nodes $list "$cmd"
2242 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2246 wait_destroy_complete () {
2247 echo "Waiting for local destroys to complete"
2248 # MAX value shouldn't be big as this mean server responsiveness
2249 # never increase this just to make test pass but investigate
2250 # why it takes so long time
2253 while [ $WAIT -lt $MAX ]; do
2254 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2258 for ((i=0; i<${#RPCs[@]}; i++)); do
2259 [ ${RPCs[$i]} -eq 0 ] && continue
2260 # there are still some destroy RPCs in flight
2265 [ ${con} -eq 1 ] && return 0 # done waiting
2266 echo "Waiting ${WAIT}s for local destroys to complete"
2269 echo "Local destroys weren't done in $MAX sec."
2273 wait_delete_completed() {
2274 wait_delete_completed_mds $1 || return $?
2275 wait_destroy_complete
2284 # conf-sanity 31 takes a long time cleanup
2285 while [ $WAIT -lt 300 ]; do
2286 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2287 [ -z "${running}" ] && return 0
2288 echo "waited $WAIT for${running}"
2289 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2291 WAIT=$((WAIT + INTERVAL))
2293 echo "service didn't stop after $WAIT seconds. Still running:"
2298 wait_remote_prog () {
2304 [ "$PDSH" = "no_dsh" ] && return 0
2306 while [ $WAIT -lt $2 ]; do
2307 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2308 [ -z "${running}" ] && return 0 || true
2309 echo "waited $WAIT for: "
2311 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2313 WAIT=$((WAIT + INTERVAL))
2315 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2316 [ -z "$pids" ] && return 0
2317 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2318 # FIXME: not portable
2319 for pid in $pids; do
2320 cat /proc/${pid}/status || true
2321 cat /proc/${pid}/wchan || true
2323 kill -9 $pid || true
2332 # not every config has many clients
2334 if [ ! -z "$CLIENTS" ]; then
2335 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2337 stat -f $MOUNT > /dev/null
2343 # usually checked on particular client or locally
2345 if [ ! -z "$client" ]; then
2346 $PDSH $client "stat -f $MOUNT" > /dev/null
2348 stat -f $MOUNT > /dev/null
2356 client_reconnect_try() {
2357 uname -n >> $MOUNT/recon
2358 if [ -z "$CLIENTS" ]; then
2359 df $MOUNT; uname -n >> $MOUNT/recon
2361 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2363 echo Connected clients:
2365 ls -l $MOUNT/recon > /dev/null
2369 client_reconnect() {
2370 # one client_reconnect_try call does not always do the job...
2372 client_reconnect_try && break
2377 affected_facets () {
2380 local host=$(facet_active_host $facet)
2381 local affected=$facet
2383 if [ "$FAILURE_MODE" = HARD ]; then
2384 affected=$(facets_up_on_host $host)
2398 #Because it will only get up facets, we need get affected
2399 #facets before shutdown
2400 #For HARD Failure mode, it needs make sure facets on the same
2401 #HOST will only be shutdown and reboot once
2402 for facet in ${facets//,/ }; do
2403 local affected_facet
2405 #check whether facet has been included in other affected facets
2406 for ((index=0; index<$total; index++)); do
2407 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2410 if [ $skip -eq 0 ]; then
2411 affecteds[$total]=$(affected_facets $facet)
2416 for ((index=0; index<$total; index++)); do
2417 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2418 local host=$(facet_active_host $facet)
2419 echo "Failing ${affecteds[index]} on $host"
2420 shutdown_facet $facet
2423 for ((index=0; index<$total; index++)); do
2424 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2425 echo reboot facets: ${affecteds[index]}
2429 change_active ${affecteds[index]}
2431 wait_for_facet ${affecteds[index]}
2432 # start mgs first if it is affected
2433 if ! combined_mgs_mds &&
2434 list_member ${affecteds[index]} mgs; then
2435 mount_facet mgs || error "Restart of mgs failed"
2437 # FIXME; has to be changed to mount all facets concurrently
2438 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2439 echo mount facets: ${affecteds[index]}
2440 mount_facets ${affecteds[index]}
2450 do_facet $facet "sync; sync; sync"
2453 # make sure there will be no seq change
2454 local clients=${CLIENTS:-$HOSTNAME}
2455 local f=fsa-\\\$\(hostname\)
2456 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2457 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2459 local svc=${facet}_svc
2460 do_facet $facet $LCTL --device ${!svc} notransno
2462 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2463 # in-memory state has to be cleared by either rebooting the host or
2464 # exporting and reimporting the pool.
2466 # Although the uberblocks are not updated when a pool is freezed,
2467 # transactions are still written to the disks. Modified blocks may be
2468 # cached in memory when tests try reading them back. The
2469 # export-and-reimport process also evicts any cached pool data from
2470 # memory to provide the correct "data loss" semantics.
2472 # In the test framework, the exporting and importing operations are
2473 # handled by stop() and mount_facet() separately, which are used
2474 # inside fail() and fail_abort().
2476 do_facet $facet $LCTL --device ${!svc} readonly
2477 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2478 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2481 replay_barrier_nodf() {
2482 local facet=$1 echo running=${running}
2483 do_facet $facet "sync; sync; sync"
2484 local svc=${facet}_svc
2485 echo Replay barrier on ${!svc}
2486 do_facet $facet $LCTL --device ${!svc} notransno
2487 do_facet $facet $LCTL --device ${!svc} readonly
2488 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2489 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2492 replay_barrier_nosync() {
2493 local facet=$1 echo running=${running}
2494 local svc=${facet}_svc
2495 echo Replay barrier on ${!svc}
2496 do_facet $facet $LCTL --device ${!svc} notransno
2497 do_facet $facet $LCTL --device ${!svc} readonly
2498 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2499 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2503 # Get Lustre client uuid for a given Lustre mount point.
2506 local mntpnt=${1:-$MOUNT}
2508 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2509 local uuid=$($LCTL get_param -n llite.$name.uuid)
2514 mds_evict_client() {
2515 local mntpnt=${1:-$MOUNT}
2516 local uuid=$(get_client_uuid $mntpnt)
2518 do_facet $SINGLEMDS \
2519 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2522 ost_evict_client() {
2523 local mntpnt=${1:-$MOUNT}
2524 local uuid=$(get_client_uuid $mntpnt)
2527 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2532 local clients=${CLIENTS:-$HOSTNAME}
2534 facet_failover $* || error "failover: $?"
2535 wait_clients_import_state "$clients" "$facets" FULL
2536 clients_up || error "post-failover df: $?"
2541 facet_failover $facet
2547 change_active $facet
2548 wait_for_facet $facet
2549 mount_facet $facet -o abort_recovery
2550 clients_up || echo "first df failed: $?"
2551 clients_up || error "post-failover df: $?"
2555 echo There is no lmc. This is mountconf, baby.
2559 host_nids_address() {
2563 if [ -n "$kind" ]; then
2564 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2566 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2572 if [ "$1" = "'*'" ]; then echo \'*\'; else
2578 if [ "$1" = "'*'" ]; then echo \'*\'; else
2579 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2581 if [ -z "$ID" ]; then
2582 echo "Could not get a ptl id for $1..."
2591 h2name_or_ip "$1" "tcp"
2596 if [ "$1" = "'*'" ]; then echo \'*\'; else
2597 if type __h2elan >/dev/null 2>&1; then
2600 ID=`echo $1 | sed 's/[^0-9]*//g'`
2608 h2name_or_ip "$1" "o2ib"
2612 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2613 # expressions format. As a bonus we can then just pass in those variables
2614 # to pdsh. What this function does is take a HOSTLIST type string and
2615 # expand it into a space deliminated list for us.
2623 [ -z "$hostlist" ] && return
2625 # Translate the case of [..],..,[..] to [..] .. [..]
2626 list="${hostlist/],/] }"
2628 [[ "$front" == *,* ]] && {
2631 list=${list/${old}/${new}}
2634 for item in $list; do
2635 # Test if we have any []'s at all
2636 if [ "$item" != "${item/\[/}" ]; then {
2637 # Expand the [*] into list
2641 if [ "$name" != "$item" ]; then
2642 group=${item#$name[*}
2645 for range in ${group//,/ }; do
2649 # Number of leading zeros
2652 end=$(echo $end | sed 's/0*//')
2653 [[ -z "$end" ]] && end=0
2654 [[ $padlen2 -gt $padlen ]] && {
2655 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2658 begin=$(echo $begin | sed 's/0*//')
2659 [ -z $begin ] && begin=0
2661 for num in $(seq -f "%0${padlen}g" $begin $end); do
2662 value="${name#*,}${num}${back}"
2663 [ "$value" != "${value/\[/}" ] && {
2664 value=$(hostlist_expand "$value")
2666 myList="$myList $value"
2671 myList="$myList $item"
2674 myList=${myList//,/ }
2675 myList=${myList:1} # Remove first character which is a space
2677 # Filter any duplicates without sorting
2679 myList="${list%% *}"
2681 while [[ "$list" != ${myList##* } ]]; do
2682 list=${list//${list%% *} /}
2683 myList="$myList ${list%% *}"
2685 myList="${myList%* }";
2687 # We can select an object at an offset in the list
2690 for item in $myList; do
2692 [ $cnt -eq $offset ] && {
2696 [ $(get_node_count $myList) -ne 1 ] && myList=""
2705 [ "$facet" == client ] && echo -n $HOSTNAME && return
2706 varname=${facet}_HOST
2707 if [ -z "${!varname}" ]; then
2708 if [ "${facet:0:3}" == "ost" ]; then
2709 local fh=${facet%failover}_HOST
2710 eval export ${facet}_HOST=${!fh}
2711 if [ -z "${!varname}" ]; then
2712 eval export ${facet}_HOST=${ost_HOST}
2714 elif [ "${facet:0:3}" == "mdt" -o \
2715 "${facet:0:3}" == "mds" -o \
2716 "${facet:0:3}" == "mgs" ]; then
2717 eval export ${facet}_HOST=${mds_HOST}
2723 facet_failover_host() {
2727 var=${facet}failover_HOST
2728 if [ -n "${!var}" ]; then
2733 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2734 "${facet:0:3}" == "mgs" ]; then
2736 eval export ${facet}failover_host=${mds_HOST}
2741 if [[ $facet == ost* ]]; then
2742 eval export ${facet}failover_host=${ost_HOST}
2750 local activevar=${facet}active
2752 if [ -f $TMP/${facet}active ] ; then
2753 source $TMP/${facet}active
2756 active=${!activevar}
2757 if [ -z "$active" ] ; then
2764 facet_active_host() {
2766 local active=`facet_active $facet`
2767 if [ "$facet" == client ]; then
2770 echo `facet_host $active`
2774 # Get the passive failover partner host of facet.
2775 facet_passive_host() {
2777 [[ $facet = client ]] && return
2779 local host=${facet}_HOST
2780 local failover_host=${facet}failover_HOST
2781 local active_host=$(facet_active_host $facet)
2783 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2785 if [[ $active_host = ${!host} ]]; then
2786 echo -n ${!failover_host}
2796 facetlist=$(exclude_items_from_list $facetlist mgs)
2798 for facet in ${facetlist//,/ }; do
2799 local failover=${facet}failover
2800 local host=`facet_host $failover`
2801 [ -z "$host" ] && return
2803 local curactive=`facet_active $facet`
2804 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2805 eval export ${facet}active=$facet
2807 eval export ${facet}active=$failover
2809 # save the active host for this facet
2810 local activevar=${facet}active
2811 echo "$activevar=${!activevar}" > $TMP/$activevar
2812 [[ $facet = mds1 ]] && combined_mgs_mds && \
2813 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2814 local TO=`facet_active_host $facet`
2815 echo "Failover $facet to $TO"
2821 # do not stripe off hostname if verbose, bug 19215
2822 if [ x$1 = x--verbose ]; then
2830 if [ "$HOST" = "$HOSTNAME" ]; then
2832 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2833 echo "cannot run remote command on $HOST with $myPDSH"
2837 echo "CMD: $HOST $@" >&2
2838 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2841 if [ "$myPDSH" = "rsh" ]; then
2842 # we need this because rsh does not return exit code of an executed command
2843 local command_status="$TMP/cs"
2844 rsh $HOST ":> $command_status"
2845 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2846 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2847 echo command failed >$command_status"
2848 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2853 # print HOSTNAME for myPDSH="no_dsh"
2854 if [[ $myPDSH = no_dsh ]]; then
2855 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2857 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2860 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2862 return ${PIPESTATUS[0]}
2866 do_node --verbose "$@"
2869 single_local_node () {
2870 [ "$1" = "$HOSTNAME" ]
2873 # Outputs environment variable assignments that should be passed to remote nodes
2877 local facets=$(get_facets)
2880 for var in ${!MODOPTS_*}; do
2881 value=${!var//\"/\\\"}
2882 echo -n " ${var}=\"$value\""
2885 for facet in ${facets//,/ }; do
2887 if [ -n "${!var}" ]; then
2888 echo -n " $var=${!var}"
2892 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2893 if [ -n "${!var}" ]; then
2894 echo -n " $var=${!var}"
2898 if [ -n "$FSTYPE" ]; then
2899 echo -n " FSTYPE=$FSTYPE"
2902 for var in LNETLND NETTYPE; do
2903 if [ -n "${!var}" ]; then
2904 echo -n " $var=${!var}"
2911 # do not stripe off hostname if verbose, bug 19215
2912 if [ x$1 = x--verbose ]; then
2920 if single_local_node $rnodes; then
2922 do_nodev $rnodes "$@"
2924 do_node $rnodes "$@"
2929 # This is part from do_node
2932 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2933 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2935 export FANOUT=$(get_node_count "${rnodes//,/ }")
2937 echo "CMD: $rnodes $@" >&2
2938 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2941 # do not replace anything from pdsh output if -N is used
2942 # -N Disable hostname: prefix on lines of output.
2943 if $verbose || [[ $myPDSH = *-N* ]]; then
2944 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2946 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2948 return ${PIPESTATUS[0]}
2954 local HOST=`facet_active_host $facet`
2955 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2959 # Function: do_facet_random_file $FACET $FILE $SIZE
2960 # Creates FILE with random content on the given FACET of given SIZE
2962 do_facet_random_file() {
2966 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2967 do_facet $facet "$cmd 2>/dev/null"
2970 do_facet_create_file() {
2974 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2975 do_facet $facet "$cmd 2>/dev/null"
2979 do_nodes --verbose "$@"
2985 # make sure its not already running
2987 rm -f $TMP/${facet}active
2988 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2989 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2991 if [[ $(facet_fstype $facet) == zfs ]]; then
2993 # After formatting a ZFS target, "cachefile=none" property will
2994 # be set on the ZFS storage pool so that the pool is not
2995 # automatically imported on system startup. And then the pool
2996 # will be exported so as to leave the importing and exporting
2997 # operations handled by mount_facet() and stop() separately.
2999 refresh_partition_table $facet $(facet_vdevice $facet)
3000 disable_zpool_cache $facet
3005 # Device formatted as ost
3008 local DEVNAME=OSTDEV$num
3010 local fstype=$(facet_fstype ost$num)
3014 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3015 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3017 #try $OSTZFSDEVn - independent of vdev
3018 DEVNAME=OSTZFSDEV$num
3019 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3021 error "unknown fstype!";;
3027 # Physical device location of data
3033 local fstype=$(facet_fstype ost$num)
3037 # vdevs are not supported by ldiskfs
3040 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3041 # Device formatted by zfs
3043 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3045 error "unknown fstype!";;
3051 # Logical device formatted for lustre
3054 local DEVNAME=MDSDEV$num
3056 local fstype=$(facet_fstype mds$num)
3060 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3061 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3063 # try $MDSZFSDEVn - independent of vdev
3064 DEVNAME=MDSZFSDEV$num
3065 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3067 error "unknown fstype!";;
3073 # Physical location of data
3077 local fstype=$(facet_fstype mds$num)
3081 # vdevs are not supported by ldiskfs
3084 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3085 # Device formatted by ZFS
3086 local DEVNAME=MDSDEV$num
3087 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3089 error "unknown fstype!";;
3097 local fstype=$(facet_fstype mgs)
3101 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3102 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3103 DEVPTR=$(mdsdevname 1)
3108 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3109 ( [ -z "$MGSZFSDEV" ] &&
3110 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3111 DEVPTR=$(mdsdevname 1)
3113 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3116 error "unknown fstype!";;
3125 local fstype=$(facet_fstype mgs)
3129 # vdevs are not supported by ldiskfs
3132 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3133 ( [ -z "$MGSDEV" ] &&
3134 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3135 VDEVPTR=$(mdsvdevname 1)
3136 elif [ -n "$MGSDEV" ]; then
3140 error "unknown fstype!";;
3148 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3150 local var=${facet}_MOUNT
3151 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3158 local dev=$(facet_device $facet)
3159 local mnt=$(facet_mntpt $facet)
3162 if ! do_facet $facet test -b $dev; then
3165 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3170 local dev=$(facet_device $facet)
3171 local mnt=$(facet_mntpt $facet)
3173 do_facet $facet umount -d $mnt
3177 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3182 local ds=$(facet_device $facet)
3183 local mnt=$(facet_mntpt $facet)
3188 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3189 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3190 do_facet $facet $ZFS set canmount=noauto $ds
3192 # The "legacy" mount method is used here because "zfs unmount $mnt"
3193 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3194 # targets are not available at the time, the stat(2) on $MOUNT will
3197 do_facet $facet $ZFS set mountpoint=legacy $ds
3198 do_facet $facet mount -t zfs $ds $mnt
3199 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3200 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3205 local ds=$(facet_device $facet)
3206 local mnt=$(facet_mntpt $facet)
3207 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3208 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3209 local mntpt=${!var_mntpt}
3210 local canmnt=${!var_canmnt}
3214 do_facet $facet umount $mnt
3215 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3216 do_facet $facet $ZFS set canmount=$canmnt $ds
3222 local fstype=$(facet_fstype $facet)
3224 mount_$fstype $facet
3229 local fstype=$(facet_fstype $facet)
3231 unmount_$fstype $facet
3238 # make sure we are using the primary server, so test-framework will
3239 # be able to clean up properly.
3240 activemds=`facet_active mds1`
3241 if [ $activemds != "mds1" ]; then
3245 local clients=$CLIENTS
3246 [ -z $clients ] && clients=$(hostname)
3248 zconf_umount_clients $clients $MOUNT "$*" || true
3249 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3251 [ "$CLIENTONLY" ] && return
3252 # The add fn does rm ${facet}active file, this would be enough
3253 # if we use do_facet <facet> only after the facet added, but
3254 # currently we use do_facet mds in local.sh
3255 for num in `seq $MDSCOUNT`; do
3257 rm -f ${TMP}/mds${num}active
3259 combined_mgs_mds && rm -f $TMP/mgsactive
3261 for num in `seq $OSTCOUNT`; do
3263 rm -f $TMP/ost${num}active
3266 if ! combined_mgs_mds ; then
3273 cleanup_echo_devs () {
3274 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3276 for dev in $devs; do
3277 $LCTL --device $dev cleanup
3278 $LCTL --device $dev detach
3283 nfs_client_mode && return
3292 combined_mgs_mds () {
3293 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3294 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3298 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3302 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3308 local fsname=${3:-"$FSNAME"}
3309 local type=$(facet_type $facet)
3310 local index=$(facet_index $facet)
3311 local fstype=$(facet_fstype $facet)
3312 local host=$(facet_host $facet)
3317 if [ $type == MGS ] || ( [ $type == MDS ] &&
3318 [ "$dev" == $(mgsdevname) ] &&
3319 [ "$host" == "$(facet_host mgs)" ] ); then
3322 opts="--mgsnode=$MGSNID"
3325 if [ $type != MGS ]; then
3326 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3330 var=${facet}failover_HOST
3331 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3332 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3335 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3336 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3338 if [ $type == MDS ]; then
3339 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3340 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3341 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3342 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3343 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3345 if [ $fstype == ldiskfs ]; then
3346 # Check for wide striping
3347 if [ $OSTCOUNT -gt 160 ]; then
3348 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3349 fs_mkfs_opts+="-O large_xattr"
3352 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3353 if [ ! -z $EJOURNAL ]; then
3354 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3356 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3360 if [ $type == OST ]; then
3361 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3362 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3364 if [ $fstype == ldiskfs ]; then
3365 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3369 opts+=" --backfstype=$fstype"
3372 if [ -n "${!var}" ]; then
3373 opts+=" --device-size=${!var}"
3376 var=$(upper $fstype)_MKFS_OPTS
3377 fs_mkfs_opts+=${!var:+" ${!var}"}
3379 var=${type}_FS_MKFS_OPTS
3380 fs_mkfs_opts+=${!var:+" ${!var}"}
3382 if [ -n "${fs_mkfs_opts## }" ]; then
3383 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3387 opts+=${!var:+" ${!var}"}
3392 check_ost_indices() {
3393 local index_count=${#OST_INDICES[@]}
3394 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3396 # OST count is greater than the index count in $OST_INDEX_LIST.
3397 # We need check whether there are duplicate indices.
3401 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3402 index=$(facet_index ost$i)
3403 for j in $(seq 0 $((index_count - 1))); do
3404 [[ $index -ne ${OST_INDICES[j]} ]] ||
3405 error "ost$i has the same index $index as ost$((j+1))"
3418 # We need ldiskfs here, may as well load them all
3420 [ "$CLIENTONLY" ] && return
3421 echo Formatting mgs, mds, osts
3422 if ! combined_mgs_mds ; then
3423 echo "Format mgs: $(mgsdevname)"
3424 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \