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
495 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
496 load_module ../lnet/klnds/$LNETLND
497 load_module obdclass/obdclass
498 load_module ptlrpc/ptlrpc
499 load_module ptlrpc/gss/ptlrpc_gss
507 load_module obdecho/obdecho
508 if ! client_only; then
509 SYMLIST=/proc/kallsyms
510 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
511 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
512 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
513 load_module lfsck/lfsck
514 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
515 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
517 load_module osd-zfs/osd_zfs
519 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
520 grep -q exportfs_decode_fh $SYMLIST ||
521 { modprobe exportfs 2> /dev/null || true; }
522 load_module ../ldiskfs/ldiskfs
523 load_module osd-ldiskfs/osd_ldiskfs
535 load_module llite/lustre
536 llite_lloop_enabled && load_module llite/llite_lloop
537 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
539 rm -f $OGDB/ogdb-$HOSTNAME
540 $LCTL modules > $OGDB/ogdb-$HOSTNAME
542 # 'mount' doesn't look in $PATH, just sbin
543 local mount_lustre=$LUSTRE/utils/mount.lustre
544 if [ -f $mount_lustre ]; then
545 local sbin_mount=/sbin/mount.lustre
546 if grep -qe "$sbin_mount " /proc/mounts; then
547 cmp $mount_lustre $sbin_mount || umount $sbin_mount
549 if ! grep -qe "$sbin_mount " /proc/mounts; then
550 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
551 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
552 cat <<- EOF > "$sbin_mount"
555 echo "This $sbin_mount just a mountpoint." 1>&2
556 echo "It is never supposed to be run." 1>&2
557 logger -p emerg -- "using stub $sbin_mount $@"
560 chmod a+x $sbin_mount
562 mount --bind $mount_lustre $sbin_mount ||
563 error "can't bind $mount_lustre to $sbin_mount"
571 # load modules on remote nodes optionally
572 # lustre-tests have to be installed on these nodes
573 if $LOAD_MODULES_REMOTE; then
574 local list=$(comma_list $(remote_nodes_list))
575 if [ -n "$list" ]; then
576 echo "loading modules on: '$list'"
577 do_rpc_nodes "$list" load_modules_local
583 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
584 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
585 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
586 echo "$LEAK_LUSTRE" 1>&2
587 echo "$LEAK_PORTALS" 1>&2
588 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
589 echo "Memory leaks detected"
590 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
596 wait_exit_ST client # bug 12845
598 $LUSTRE_RMMOD ldiskfs || return 2
600 if $LOAD_MODULES_REMOTE; then
601 local list=$(comma_list $(remote_nodes_list))
602 if [ -n "$list" ]; then
603 echo "unloading modules on: '$list'"
604 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
605 do_rpc_nodes "$list" check_mem_leak
609 local sbin_mount=/sbin/mount.lustre
610 if grep -qe "$sbin_mount " /proc/mounts; then
611 umount $sbin_mount || true
612 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
616 check_mem_leak || return 254
618 echo "modules unloaded."
623 local facet=${1:-$SINGLEMDS}
624 local fstype=$(facet_fstype $facet)
627 ldiskfs) size=50;; # largest seen is 44, leave some headroom
628 zfs) size=400;; # largest seen is 384
634 check_gss_daemon_nodes() {
638 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
639 if [ \\\"\\\$num\\\" -ne 1 ]; then
640 echo \\\$num instance of $dname;
645 check_gss_daemon_facet() {
649 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
650 if [ $num -ne 1 ]; then
651 echo "$num instance of $dname on $facet"
660 echo Stopping $@ on $list
661 do_nodes $list "killall -2 $@ 2>/dev/null || true"
664 # start gss daemons on all nodes, or
665 # "daemon" on "list" if set
666 start_gss_daemons() {
670 if [ "$list" ] && [ "$daemon" ] ; then
671 echo "Starting gss daemon on nodes: $list"
672 do_nodes $list "$daemon" || return 8
676 local list=$(comma_list $(mdts_nodes))
677 echo "Starting gss daemon on mds: $list"
678 do_nodes $list "$LSVCGSSD -v" || return 1
680 do_nodes $list "$LGSSD -v" || return 2
683 list=$(comma_list $(osts_nodes))
684 echo "Starting gss daemon on ost: $list"
685 do_nodes $list "$LSVCGSSD -v" || return 3
686 # starting on clients
688 local clients=${CLIENTS:-`hostname`}
690 echo "Starting $LGSSD on clients $clients "
691 do_nodes $clients "$LGSSD -v" || return 4
694 # wait daemons entering "stable" status
698 # check daemons are running
700 list=$(comma_list $(mdts_nodes) $(osts_nodes))
701 check_gss_daemon_nodes $list lsvcgssd || return 5
703 list=$(comma_list $(mdts_nodes))
704 check_gss_daemon_nodes $list lgssd || return 6
707 check_gss_daemon_nodes $clients lgssd || return 7
712 local list=$(comma_list $(mdts_nodes))
714 send_sigint $list lsvcgssd lgssd
716 list=$(comma_list $(osts_nodes))
717 send_sigint $list lsvcgssd
719 list=${CLIENTS:-`hostname`}
720 send_sigint $list lgssd
725 if ! module_loaded ptlrpc_gss; then
726 load_module ptlrpc/gss/ptlrpc_gss
727 module_loaded ptlrpc_gss ||
728 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
731 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
734 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
736 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
744 # maybe cleanup credential cache?
750 local var=${facet}_svc
758 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
759 tr '[:lower:]' '[:upper:]'
765 if [ $facet == mgs ]; then
769 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
777 if [ -n "${!var}" ]; then
782 var=$(facet_type $facet)FSTYPE
783 if [ -n "${!var}" ]; then
788 if [ -n "$FSTYPE" ]; then
793 if [[ $facet == mgs ]] && combined_mgs_mds; then
805 local facets=$(get_facets)
808 for facet in ${facets//,/ }; do
809 if [ $node == $(facet_host $facet) ] ||
810 [ $node == "$(facet_failover_host $facet)" ]; then
811 fstype=$(facet_fstype $facet)
812 if [[ $fstypes != *$fstype* ]]; then
813 fstypes+="${fstypes:+,}$fstype"
822 local num=$(facet_number $facet)
825 if [[ $(facet_type $facet) = OST ]]; then
827 if [[ -n "${!index}" ]]; then
832 index=${OST_INDICES[num - 1]}
835 [[ -n "$index" ]] || index=$((num - 1))
843 local fstype=$(facet_fstype $facet)
847 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
849 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
850 ${dev} 2>/dev/null");;
852 error "unknown fstype!";;
860 local device=$(mdsdevname $num)
861 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
867 local device=$(ostdevname $num)
868 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
873 # Get the device of a facet.
880 mgs) device=$(mgsdevname) ;;
881 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
882 ost*) device=$(ostdevname $(facet_number $facet)) ;;
883 fs2mds) device=$(mdsdevname 1_2) ;;
884 fs2ost) device=$(ostdevname 1_2) ;;
885 fs3ost) device=$(ostdevname 2_2) ;;
893 # Get the virtual device of a facet.
900 mgs) device=$(mgsvdevname) ;;
901 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
902 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
903 fs2mds) device=$(mdsvdevname 1_2) ;;
904 fs2ost) device=$(ostvdevname 1_2) ;;
905 fs3ost) device=$(ostvdevname 2_2) ;;
913 # Re-read the partition table on failover partner host.
914 # After a ZFS storage pool is created on a shared device, the partition table
915 # on the device may change. However, the operating system on the failover
916 # host may not notice the change automatically. Without the up-to-date partition
917 # block devices, 'zpool import ..' cannot find the labels, whose positions are
918 # relative to partition rather than disk beginnings.
920 # This function performs partprobe on the failover host to make it re-read the
923 refresh_partition_table() {
928 host=$(facet_passive_host $facet)
929 if [[ -n "$host" ]]; then
930 do_node $host "$PARTPROBE $device"
935 # Get ZFS storage pool name.
942 device=$(facet_device $facet)
943 # poolname is string before "/"
944 poolname="${device%%/*}"
950 # Create ZFS storage pool.
957 local opts=${@:-"-o cachefile=none"}
959 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
960 $ZPOOL create -f $opts $poolname $vdev"
964 # Create ZFS file system.
970 local opts=${@:-"-o mountpoint=legacy"}
972 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
973 $ZFS create $opts $dataset"
977 # Export ZFS storage pool.
978 # Before exporting the pool, all datasets within the pool should be unmounted.
986 poolname=$(zpool_name $facet)
988 if [[ -n "$poolname" ]]; then
989 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
990 grep -q ^$poolname/ /proc/mounts ||
991 $ZPOOL export $opts $poolname"
996 # Destroy ZFS storage pool.
997 # Destroy the given pool and free up any devices for other use. This command
998 # tries to unmount any active datasets before destroying the pool.
999 # -f Force any active datasets contained within the pool to be unmounted.
1003 local poolname=${2:-$(zpool_name $facet)}
1005 if [[ -n "$poolname" ]]; then
1006 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1007 $ZPOOL destroy -f $poolname"
1012 # Import ZFS storage pool.
1013 # Force importing, even if the pool appears to be potentially active.
1018 local opts=${@:-"-o cachefile=none"}
1021 poolname=$(zpool_name $facet)
1023 if [[ -n "$poolname" ]]; then
1024 opts+=" -d $(dirname $(facet_vdevice $facet))"
1025 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1026 $ZPOOL import -f $opts $poolname"
1031 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1032 # is not automatically imported on system startup.
1034 # In a failover environment, this will provide resource level fencing which
1035 # will ensure that the same ZFS storage pool will not be imported concurrently
1036 # on different nodes.
1038 disable_zpool_cache() {
1042 poolname=$(zpool_name $facet)
1044 if [[ -n "$poolname" ]]; then
1045 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1050 # This and set_osd_param() shall be used to access OSD parameters
1051 # once existed under "obdfilter":
1056 # writethrough_cache_enable
1060 local device=${2:-$FSNAME-OST*}
1063 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1064 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1069 local device=${2:-$FSNAME-OST*}
1073 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1074 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1078 local dz=${1:-$DEBUG_SIZE}
1080 if [ -f /sys/devices/system/cpu/possible ]; then
1081 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1083 local cpus=$(getconf _NPROCESSORS_CONF)
1086 # bug 19944, adjust size to be -gt num_possible_cpus()
1087 # promise 2MB for every cpu at least
1088 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1091 lctl set_param debug_mb=$dz
1094 set_default_debug () {
1095 local debug=${1:-"$PTLDEBUG"}
1096 local subsys=${2:-"$SUBSYSTEM"}
1097 local debug_size=${3:-$DEBUG_SIZE}
1099 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1100 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1102 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1105 set_default_debug_nodes () {
1108 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1109 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1113 do_rpc_nodes "$nodes" set_default_debug \
1114 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1117 set_default_debug_facet () {
1119 local node=$(facet_active_host $facet)
1120 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1122 set_default_debug_nodes $node
1127 local facets=${1:-$(get_facets)}
1130 for facet in ${facets//,/ }; do
1133 [ $RC -eq 0 ] && continue
1135 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1136 skip "Restart of $facet failed!." && touch $LU482_FAILED
1138 error "Restart of $facet failed!"
1145 # Add argument "arg" (e.g., "loop") to the comma-separated list
1146 # of arguments for option "opt" (e.g., "-o") on command
1147 # line "opts" (e.g., "-o flock").
1153 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1155 if echo "$opts" | grep -q $opt_pattern; then
1156 opts=$(echo "$opts" | sed -e \
1157 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1159 opts+="${opts:+ }$opt $arg"
1167 local dev=$(facet_active $facet)_dev
1168 local opt=${facet}_opt
1169 local mntpt=$(facet_mntpt $facet)
1170 local opts="${!opt} $@"
1172 if [ $(facet_fstype $facet) == ldiskfs ] &&
1173 ! do_facet $facet test -b ${!dev}; then
1174 opts=$(csa_add "$opts" -o loop)
1177 if [[ $(facet_fstype $facet) == zfs ]]; then
1178 # import ZFS storage pool
1179 import_zpool $facet || return ${PIPESTATUS[0]}
1182 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1183 # for testing LU-482 error handling in mount_facets() and test_0a()
1184 if [ -f $TMP/test-lu482-trigger ]; then
1187 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1191 if [ $RC -ne 0 ]; then
1192 echo "Start of ${!dev} on ${facet} failed ${RC}"
1194 set_default_debug_facet $facet
1196 label=$(devicelabel ${facet} ${!dev})
1197 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1198 eval export ${facet}_svc=${label}
1199 echo Started ${label}
1204 # start facet device options
1210 eval export ${facet}_dev=${device}
1211 eval export ${facet}_opt=\"$@\"
1213 local varname=${facet}failover_dev
1214 if [ -n "${!varname}" ] ; then
1215 eval export ${facet}failover_dev=${!varname}
1217 eval export ${facet}failover_dev=$device
1220 local mntpt=$(facet_mntpt $facet)
1221 do_facet ${facet} mkdir -p $mntpt
1222 eval export ${facet}_MOUNT=$mntpt
1223 mount_facet ${facet}
1226 if [[ $facet == mds* ]]; then
1228 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1239 local HOST=`facet_active_host $facet`
1240 [ -z $HOST ] && echo stop: no host for $facet && return 0
1242 local mntpt=$(facet_mntpt $facet)
1243 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1244 if [ ${running} -ne 0 ]; then
1245 echo "Stopping $mntpt (opts:$@) on $HOST"
1246 do_facet ${facet} umount -d $@ $mntpt
1249 # umount should block, but we should wait for unrelated obd's
1250 # like the MGS or MGC to also stop.
1251 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1253 if [[ $(facet_fstype $facet) == zfs ]]; then
1254 # export ZFS storage pool
1259 # save quota version (both administrative and operational quotas)
1260 # add an additional parameter if mountpoint is ever different from $MOUNT
1262 # XXX This function is kept for interoperability with old server (< 2.3.50),
1263 # it should be removed whenever we drop the interoperability for such
1265 quota_save_version() {
1266 local fsname=${2:-$FSNAME}
1268 local ver=$(tr -c -d "123" <<< $spec)
1269 local type=$(tr -c -d "ug" <<< $spec)
1271 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1273 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1275 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1277 local osts=$(get_facets OST)
1278 for ost in ${osts//,/ }; do
1280 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1284 # client could mount several lustre
1286 # XXX This function is kept for interoperability with old server (< 2.3.50),
1287 # it should be removed whenever we drop the interoperability for such
1290 local fsname=${1:-$FSNAME}
1292 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1294 do_nodes $(comma_list $(osts_nodes)) \
1295 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
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
1302 restore_quota_old() {
1303 local mntpt=${1:-$MOUNT}
1304 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1305 if [ ! "$old_QUOTA_TYPE" ] ||
1306 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1309 quota_save_version $old_QUOTA_TYPE
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
1318 # no quota enforcement for now and accounting works out of the box
1321 # We need save the original quota_type params, and restore them after testing
1323 # Suppose that quota type the same on mds and ost
1324 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1325 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1326 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1327 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1328 export old_QUOTA_TYPE=$quota_type
1329 quota_save_version $QUOTA_TYPE
1331 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1332 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1335 local quota_usrs=$QUOTA_USERS
1337 # get_filesystem_size
1338 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1339 local blk_soft=$((disksz + 1024))
1340 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1342 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1343 local i_soft=$Inodes
1344 local i_hard=$((i_soft + i_soft / 20))
1346 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1347 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1350 for usr in $quota_usrs; do
1351 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1353 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1355 eval $cmd || error "$cmd FAILED!"
1357 # display the quota status
1358 echo "Quota settings for $usr : "
1359 $LFS quota -v -u $usr $mntpt || true
1363 # get mdt quota type
1365 local varsvc=${SINGLEMDS}_svc
1366 do_facet $SINGLEMDS $LCTL get_param -n \
1367 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1370 # get ost quota type
1372 # All OSTs should have same quota type
1373 local varsvc=ost1_svc
1374 do_facet ost1 $LCTL get_param -n \
1375 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1378 # restore old quota type settings
1380 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1385 if [ "$old_MDT_QUOTA_TYPE" ]; then
1386 do_facet mgs $LCTL conf_param \
1387 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1389 if [ "$old_OST_QUOTA_TYPE" ]; then
1390 do_facet mgs $LCTL conf_param \
1391 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1395 # Handle the case when there is a space in the lfs df
1396 # "filesystem summary" line the same as when there is no space.
1397 # This will allow fixing the "lfs df" summary line in the future.
1399 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1402 # Get free inodes on the MDT specified by mdt index, free indoes on
1403 # the whole filesystem will be returned when index == -1.
1409 if [ $index -eq -1 ]; then
1412 mdt_uuid=$(mdtuuid_from_index $index)
1415 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1420 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1427 # save old quota type & set new quota type
1428 local mdt_qtype=$(mdt_quota_type)
1429 local ost_qtype=$(ost_quota_type)
1431 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1432 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1434 export old_MDT_QUOTA_TYPE=$mdt_qtype
1435 export old_OST_QUOTA_TYPE=$ost_qtype
1437 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1438 error "set mdt quota type failed"
1439 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1440 error "set ost quota type failed"
1442 local quota_usrs=$QUOTA_USERS
1444 # get_filesystem_size
1445 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1446 local blk_soft=$((disksz + 1024))
1447 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1449 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1450 local i_soft=$inodes
1451 local i_hard=$((i_soft + i_soft / 20))
1453 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1454 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1455 "inode-hardlimit: $i_hard"
1458 for usr in $quota_usrs; do
1459 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1461 cmd="$LFS setquota -$type $usr -b $blk_soft"
1462 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1464 eval $cmd || error "$cmd FAILED!"
1466 # display the quota status
1467 echo "Quota settings for $usr : "
1468 $LFS quota -v -u $usr $mntpt || true
1475 local opts=${3:-$MOUNT_OPTS}
1476 opts=${opts:+-o $opts}
1477 local flags=${4:-$MOUNT_FLAGS}
1479 local device=$MGSNID:/$FSNAME
1480 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1481 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1485 echo "Starting client: $client: $flags $opts $device $mnt"
1486 do_node $client mkdir -p $mnt
1487 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1489 set_default_debug_nodes $client
1501 [ "$3" ] && force=-f
1502 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1503 if [ $running -ne 0 ]; then
1504 echo "Stopping client $client $mnt (opts:$force)"
1505 do_node $client lsof -t $mnt || need_kill=no
1506 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1507 pids=$(do_node $client lsof -t $mnt | sort -u);
1508 if [ -n $pids ]; then
1509 do_node $client kill -9 $pids || true
1513 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1514 if [ $busy -ne 0 ] ; then
1515 echo "$mnt is still busy, wait one second" && sleep 1
1516 do_node $client umount $force $mnt
1521 # nodes is comma list
1522 sanity_mount_check_nodes () {
1528 # FIXME: assume that all cluster nodes run the same os
1529 [ "$(uname)" = Linux ] || return 0
1532 for mnt in $mnts ; do
1533 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1534 mpts=\\\$(mount | grep -c $mnt' ');
1535 if [ \\\$running -ne \\\$mpts ]; then
1536 echo \\\$(hostname) env are INSANE!;
1539 [ $? -eq 0 ] || rc=1
1544 sanity_mount_check_servers () {
1545 [ "$CLIENTONLY" ] &&
1546 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1547 echo Checking servers environments
1549 # FIXME: modify get_facets to display all facets wo params
1550 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1554 for facet in ${facets//,/ }; do
1555 node=$(facet_host ${facet})
1556 mntpt=$(facet_mntpt $facet)
1557 sanity_mount_check_nodes $node $mntpt ||
1558 { error "server $node environments are insane!"; return 1; }
1562 sanity_mount_check_clients () {
1563 local clients=${1:-$CLIENTS}
1564 local mntpt=${2:-$MOUNT}
1565 local mntpt2=${3:-$MOUNT2}
1567 [ -z $clients ] && clients=$(hostname)
1568 echo Checking clients $clients environments
1570 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1571 error "clients environments are insane!"
1574 sanity_mount_check () {
1575 sanity_mount_check_servers || return 1
1576 sanity_mount_check_clients || return 2
1579 # mount clients if not mouted
1580 zconf_mount_clients() {
1583 local opts=${3:-$MOUNT_OPTS}
1584 opts=${opts:+-o $opts}
1585 local flags=${4:-$MOUNT_FLAGS}
1587 local device=$MGSNID:/$FSNAME
1588 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1589 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1593 echo "Starting client $clients: $flags $opts $device $mnt"
1596 running=\\\$(mount | grep -c $mnt' ');
1598 if [ \\\$running -eq 0 ] ; then
1600 $MOUNT_CMD $flags $opts $device $mnt;
1603 exit \\\$rc" || return ${PIPESTATUS[0]}
1605 echo "Started clients $clients: "
1606 do_nodes $clients "mount | grep $mnt' '"
1608 set_default_debug_nodes $clients
1613 zconf_umount_clients() {
1618 [ "$3" ] && force=-f
1620 echo "Stopping clients: $clients $mnt (opts:$force)"
1621 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1622 if [ \\\$running -ne 0 ] ; then
1623 echo Stopping client \\\$(hostname) $mnt opts:$force;
1624 lsof $mnt || need_kill=no;
1625 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1626 pids=\\\$(lsof -t $mnt | sort -u);
1627 if [ -n \\\"\\\$pids\\\" ]; then
1631 while umount $force $mnt 2>&1 | grep -q "busy"; do
1632 echo "$mnt is still busy, wait one second" && sleep 1;
1639 echo + $POWER_DOWN $node
1643 shutdown_node_hard () {
1645 local attempts=$SHUTDOWN_ATTEMPTS
1647 for i in $(seq $attempts) ; do
1650 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1651 echo "waiting for $host to fail attempts=$attempts"
1652 [ $i -lt $attempts ] || \
1653 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1659 local mnt=${2:-$MOUNT}
1662 if [ "$FAILURE_MODE" = HARD ]; then
1663 shutdown_node_hard $client
1665 zconf_umount_clients $client $mnt -f
1671 local facets="$(get_facets OST),$(get_facets MDS)"
1674 combined_mgs_mds || facets="$facets,mgs"
1676 for facet in ${facets//,/ }; do
1677 if [ $(facet_active_host $facet) == $host ]; then
1678 affected="$affected $facet"
1682 echo $(comma_list $affected)
1687 local host=${2:-$(facet_host $facet)}
1689 local label=$(convert_facet2label $facet)
1690 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1693 facets_up_on_host () {
1695 local facets=$(facets_on_host $host)
1698 for facet in ${facets//,/ }; do
1699 if $(facet_up $facet $host); then
1700 affected_up="$affected_up $facet"
1704 echo $(comma_list $affected_up)
1710 if [ "$FAILURE_MODE" = HARD ]; then
1711 shutdown_node_hard $(facet_active_host $facet)
1719 echo + $POWER_UP $node
1732 if [ "$FAILURE_MODE" = HARD ]; then
1733 reboot_node $(facet_active_host $facet)
1741 if [ "$FAILURE_MODE" = HARD ]; then
1751 for facet in ${facets//,/ }; do
1752 hosts=$(expand_list $hosts $(facet_host $facet) )
1758 _check_progs_installed () {
1762 for prog in $progs; do
1763 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1764 echo $prog missing on $(hostname)
1771 check_progs_installed () {
1775 do_rpc_nodes "$nodes" _check_progs_installed $@
1778 # recovery-scale functions
1780 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1783 start_client_load() {
1786 local var=$(node_var_name $client)_load
1787 eval export ${var}=$load
1789 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1790 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1791 END_RUN_FILE=$END_RUN_FILE \
1792 LOAD_PID_FILE=$LOAD_PID_FILE \
1793 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1794 TESTNAME=$TESTNAME \
1795 DBENCH_LIB=$DBENCH_LIB \
1796 DBENCH_SRC=$DBENCH_SRC \
1797 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1801 log "Started client load: ${load} on $client"
1803 # get the children process IDs
1804 local pids=$(ps --ppid $ppid -o pid= | xargs)
1805 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1809 start_client_loads () {
1810 local -a clients=(${1//,/ })
1811 local numloads=${#CLIENT_LOADS[@]}
1814 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1815 testnum=$((nodenum % numloads))
1816 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1818 # bug 22169: wait the background threads to start
1822 # only for remote client
1823 check_client_load () {
1825 local var=$(node_var_name $client)_load
1826 local TESTLOAD=run_${!var}.sh
1828 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1830 # bug 18914: try to connect several times not only when
1831 # check ps, but while check_catastrophe also
1834 while [ $RC = 254 -a $tries -gt 0 ]; do
1838 if ! check_catastrophe $client; then
1840 if [ $RC -eq 254 ]; then
1841 # FIXME: not sure how long we shuold sleep here
1845 echo "check catastrophe failed: RC=$RC "
1849 # We can continue try to connect if RC=254
1850 # Just print the warning about this
1851 if [ $RC = 254 ]; then
1852 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1855 # see if the load is still on the client
1858 while [ $RC = 254 -a $tries -gt 0 ]; do
1862 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1867 if [ $RC = 254 ]; then
1868 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1869 # see if we can diagnose a bit why this is
1874 check_client_loads () {
1875 local clients=${1//,/ }
1879 for client in $clients; do
1880 check_client_load $client
1882 if [ "$rc" != 0 ]; then
1883 log "Client load failed on node $client, rc=$rc"
1889 restart_client_loads () {
1890 local clients=${1//,/ }
1891 local expectedfail=${2:-""}
1895 for client in $clients; do
1896 check_client_load $client
1898 if [ "$rc" != 0 -a "$expectedfail" ]; then
1899 local var=$(node_var_name $client)_load
1900 start_client_load $client ${!var}
1901 echo "Restarted client load ${!var}: on $client. Checking ..."
1902 check_client_load $client
1904 if [ "$rc" != 0 ]; then
1905 log "Client load failed to restart on node $client, rc=$rc"
1906 # failure one client load means test fail
1907 # we do not need to check other
1916 # Start vmstat and save its process ID in a file.
1921 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1924 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1925 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1928 # Display the nodes on which client loads failed.
1929 print_end_run_file() {
1933 [ -s $file ] || return 0
1935 echo "Found the END_RUN_FILE file: $file"
1938 # A client load will stop if it finds the END_RUN_FILE file.
1939 # That does not mean the client load actually failed though.
1940 # The first node in END_RUN_FILE is the one we are interested in.
1943 if [ -n "$node" ]; then
1944 local var=$(node_var_name $node)_load
1946 local prefix=$TESTLOG_PREFIX
1947 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1948 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1949 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1951 echo "Client load ${!var} failed on node $node:"
1957 # Stop the process which had its PID saved in a file.
1962 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1964 do_nodes $nodes "test -f $pid_file &&
1965 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1968 # Stop all client loads.
1969 stop_client_loads() {
1970 local nodes=${1:-$CLIENTS}
1973 # stop the client loads
1974 stop_process $nodes $pid_file
1976 # clean up the processes that started them
1977 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1979 # End recovery-scale functions
1981 # verify that lustre actually cleaned up properly
1983 VAR=$(lctl get_param -n catastrophe 2>&1)
1984 if [ $? = 0 ] ; then
1985 if [ $VAR != 0 ]; then
1986 error "LBUG/LASSERT detected"
1989 BUSY=$(dmesg | grep -i destruct || true)
1990 if [ -n "$BUSY" ]; then
1992 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
1996 check_mem_leak || exit 204
1998 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
1999 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2002 if module_loaded lnet || module_loaded libcfs; then
2003 echo "$TESTSUITE: modules still loaded..." 1>&2
2012 if [[ "$1" == "--verbose" ]]; then
2027 PREV_RESULT=$(do_node $node "$TEST")
2029 RESULT=$(do_node $node "$TEST")
2030 if [[ "$RESULT" == "$FINAL" ]]; then
2031 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2032 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2036 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2037 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2041 [[ $WAIT -ge $MAX ]] && break
2042 [[ $((WAIT % print)) -eq 0 ]] &&
2043 echo "Waiting $((MAX - WAIT)) secs for update"
2044 WAIT=$((WAIT + sleep))
2047 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2051 wait_update_facet() {
2054 wait_update $(facet_active_host $facet) "$@"
2058 do_nodes $(comma_list $(mdts_nodes)) \
2059 "lctl set_param -n osd*.*MDT*.force_sync 1"
2060 do_nodes $(comma_list $(osts_nodes)) \
2061 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2062 grep -v 'Found no match'
2065 wait_delete_completed_mds() {
2066 local MAX_WAIT=${1:-20}
2067 # for ZFS, waiting more time for DMUs to be committed
2068 local ZFS_WAIT=${2:-5}
2070 local stime=$(date +%s)
2075 # find MDS with pending deletions
2076 for node in $(mdts_nodes); do
2077 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2078 2>/dev/null | calc_sum)
2079 if [[ $changes -eq 0 ]]; then
2082 mds2sync="$mds2sync $node"
2084 if [ -z "$mds2sync" ]; then
2087 mds2sync=$(comma_list $mds2sync)
2089 # sync MDS transactions
2090 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2092 # wait till all changes are sent and commmitted by OSTs
2093 # for ldiskfs space is released upon execution, but DMU
2094 # do this upon commit
2097 while [[ $WAIT -ne $MAX_WAIT ]]; do
2098 changes=$(do_nodes $mds2sync \
2099 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2100 #echo "$node: $changes changes on all"
2101 if [[ $changes -eq 0 ]]; then
2103 #echo "delete took $((etime - stime)) seconds"
2105 # the occupied disk space will be released
2106 # only after DMUs are committed
2107 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2108 echo "sleep $ZFS_WAIT for ZFS OSD"
2119 echo "Delete is not completed in $((etime - stime)) seconds"
2120 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2126 # we can use "for" here because we are waiting the slowest
2127 for host in ${hostlist//,/ }; do
2128 check_network "$host" 900
2130 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2137 for facet in ${facetlist//,/ }; do
2138 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2140 wait_for_host $hostlist
2143 _wait_recovery_complete () {
2146 # Use default policy if $2 is not passed by caller.
2147 local MAX=${2:-$(max_recovery_time)}
2152 while [ $WAIT -lt $MAX ]; do
2153 STATUS=$(lctl get_param -n $param | grep status)
2155 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2158 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2160 echo "$param recovery not done in $MAX sec. $STATUS"
2164 wait_recovery_complete () {
2167 # with an assumption that at_max is the same on all nodes
2168 local MAX=${2:-$(max_recovery_time)}
2171 if [ "$FAILURE_MODE" = HARD ]; then
2172 facets=$(facets_on_host $(facet_active_host $facet))
2174 echo affected facets: $facets
2176 # we can use "for" here because we are waiting the slowest
2177 for facet in ${facets//,/ }; do
2178 local var_svc=${facet}_svc
2179 local param="*.${!var_svc}.recovery_status"
2181 local host=$(facet_active_host $facet)
2182 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2186 wait_mds_ost_sync () {
2187 # just because recovery is done doesn't mean we've finished
2188 # orphan cleanup. Wait for llogs to get synchronized.
2189 echo "Waiting for orphan cleanup..."
2190 # MAX value includes time needed for MDS-OST reconnection
2191 local MAX=$(( TIMEOUT * 2 ))
2192 local WAIT_TIMEOUT=${1:-$MAX}
2195 local list=$(comma_list $(mdts_nodes))
2196 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2197 if ! do_facet $SINGLEMDS \
2198 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2200 # old way, use mds_sync
2202 list=$(comma_list $(osts_nodes))
2203 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2206 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2207 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2208 local -a sync=($(do_nodes $list "$cmd"))
2211 for ((i=0; i<${#sync[@]}; i++)); do
2213 [ ${sync[$i]} -eq 1 ] && continue
2215 [ ${sync[$i]} -eq 0 ] && continue
2217 # there is a not finished MDS-OST synchronization
2221 sleep 2 # increase waiting time and cover statfs cache
2222 [ ${con} -eq 1 ] && return 0
2223 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2227 # show which nodes are not finished.
2228 do_nodes $list "$cmd"
2229 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2233 wait_destroy_complete () {
2234 echo "Waiting for local destroys to complete"
2235 # MAX value shouldn't be big as this mean server responsiveness
2236 # never increase this just to make test pass but investigate
2237 # why it takes so long time
2240 while [ $WAIT -lt $MAX ]; do
2241 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2245 for ((i=0; i<${#RPCs[@]}; i++)); do
2246 [ ${RPCs[$i]} -eq 0 ] && continue
2247 # there are still some destroy RPCs in flight
2252 [ ${con} -eq 1 ] && return 0 # done waiting
2253 echo "Waiting ${WAIT}s for local destroys to complete"
2256 echo "Local destroys weren't done in $MAX sec."
2260 wait_delete_completed() {
2261 wait_delete_completed_mds $1 || return $?
2262 wait_destroy_complete
2271 # conf-sanity 31 takes a long time cleanup
2272 while [ $WAIT -lt 300 ]; do
2273 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2274 [ -z "${running}" ] && return 0
2275 echo "waited $WAIT for${running}"
2276 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2278 WAIT=$((WAIT + INTERVAL))
2280 echo "service didn't stop after $WAIT seconds. Still running:"
2285 wait_remote_prog () {
2291 [ "$PDSH" = "no_dsh" ] && return 0
2293 while [ $WAIT -lt $2 ]; do
2294 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2295 [ -z "${running}" ] && return 0 || true
2296 echo "waited $WAIT for: "
2298 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2300 WAIT=$((WAIT + INTERVAL))
2302 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2303 [ -z "$pids" ] && return 0
2304 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2305 # FIXME: not portable
2306 for pid in $pids; do
2307 cat /proc/${pid}/status || true
2308 cat /proc/${pid}/wchan || true
2310 kill -9 $pid || true
2319 # not every config has many clients
2321 if [ ! -z "$CLIENTS" ]; then
2322 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2324 stat -f $MOUNT > /dev/null
2330 # usually checked on particular client or locally
2332 if [ ! -z "$client" ]; then
2333 $PDSH $client "stat -f $MOUNT" > /dev/null
2335 stat -f $MOUNT > /dev/null
2343 client_reconnect_try() {
2344 uname -n >> $MOUNT/recon
2345 if [ -z "$CLIENTS" ]; then
2346 df $MOUNT; uname -n >> $MOUNT/recon
2348 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2350 echo Connected clients:
2352 ls -l $MOUNT/recon > /dev/null
2356 client_reconnect() {
2357 # one client_reconnect_try call does not always do the job...
2359 client_reconnect_try && break
2364 affected_facets () {
2367 local host=$(facet_active_host $facet)
2368 local affected=$facet
2370 if [ "$FAILURE_MODE" = HARD ]; then
2371 affected=$(facets_up_on_host $host)
2385 #Because it will only get up facets, we need get affected
2386 #facets before shutdown
2387 #For HARD Failure mode, it needs make sure facets on the same
2388 #HOST will only be shutdown and reboot once
2389 for facet in ${facets//,/ }; do
2390 local affected_facet
2392 #check whether facet has been included in other affected facets
2393 for ((index=0; index<$total; index++)); do
2394 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2397 if [ $skip -eq 0 ]; then
2398 affecteds[$total]=$(affected_facets $facet)
2403 for ((index=0; index<$total; index++)); do
2404 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2405 local host=$(facet_active_host $facet)
2406 echo "Failing ${affecteds[index]} on $host"
2407 shutdown_facet $facet
2410 for ((index=0; index<$total; index++)); do
2411 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2412 echo reboot facets: ${affecteds[index]}
2416 change_active ${affecteds[index]}
2418 wait_for_facet ${affecteds[index]}
2419 # start mgs first if it is affected
2420 if ! combined_mgs_mds &&
2421 list_member ${affecteds[index]} mgs; then
2422 mount_facet mgs || error "Restart of mgs failed"
2424 # FIXME; has to be changed to mount all facets concurrently
2425 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2426 echo mount facets: ${affecteds[index]}
2427 mount_facets ${affecteds[index]}
2437 do_facet $facet "sync; sync; sync"
2440 # make sure there will be no seq change
2441 local clients=${CLIENTS:-$HOSTNAME}
2442 local f=fsa-\\\$\(hostname\)
2443 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2444 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2446 local svc=${facet}_svc
2447 do_facet $facet $LCTL --device ${!svc} notransno
2449 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2450 # in-memory state has to be cleared by either rebooting the host or
2451 # exporting and reimporting the pool.
2453 # Although the uberblocks are not updated when a pool is freezed,
2454 # transactions are still written to the disks. Modified blocks may be
2455 # cached in memory when tests try reading them back. The
2456 # export-and-reimport process also evicts any cached pool data from
2457 # memory to provide the correct "data loss" semantics.
2459 # In the test framework, the exporting and importing operations are
2460 # handled by stop() and mount_facet() separately, which are used
2461 # inside fail() and fail_abort().
2463 do_facet $facet $LCTL --device ${!svc} readonly
2464 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2465 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2468 replay_barrier_nodf() {
2469 local facet=$1 echo running=${running}
2470 do_facet $facet "sync; sync; sync"
2471 local svc=${facet}_svc
2472 echo Replay barrier on ${!svc}
2473 do_facet $facet $LCTL --device ${!svc} notransno
2474 do_facet $facet $LCTL --device ${!svc} readonly
2475 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2476 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2479 replay_barrier_nosync() {
2480 local facet=$1 echo running=${running}
2481 local svc=${facet}_svc
2482 echo Replay barrier on ${!svc}
2483 do_facet $facet $LCTL --device ${!svc} notransno
2484 do_facet $facet $LCTL --device ${!svc} readonly
2485 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2486 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2490 # Get Lustre client uuid for a given Lustre mount point.
2493 local mntpnt=${1:-$MOUNT}
2495 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2496 local uuid=$($LCTL get_param -n llite.$name.uuid)
2501 mds_evict_client() {
2502 local mntpnt=${1:-$MOUNT}
2503 local uuid=$(get_client_uuid $mntpnt)
2505 do_facet $SINGLEMDS \
2506 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2509 ost_evict_client() {
2510 local mntpnt=${1:-$MOUNT}
2511 local uuid=$(get_client_uuid $mntpnt)
2514 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2519 local clients=${CLIENTS:-$HOSTNAME}
2521 facet_failover $* || error "failover: $?"
2522 wait_clients_import_state "$clients" "$facets" FULL
2523 clients_up || error "post-failover df: $?"
2528 facet_failover $facet
2534 change_active $facet
2535 wait_for_facet $facet
2536 mount_facet $facet -o abort_recovery
2537 clients_up || echo "first df failed: $?"
2538 clients_up || error "post-failover df: $?"
2542 echo There is no lmc. This is mountconf, baby.
2546 host_nids_address() {
2550 if [ -n "$kind" ]; then
2551 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2553 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2559 if [ "$1" = "'*'" ]; then echo \'*\'; else
2565 if [ "$1" = "'*'" ]; then echo \'*\'; else
2566 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2568 if [ -z "$ID" ]; then
2569 echo "Could not get a ptl id for $1..."
2578 h2name_or_ip "$1" "tcp"
2583 if [ "$1" = "'*'" ]; then echo \'*\'; else
2584 if type __h2elan >/dev/null 2>&1; then
2587 ID=`echo $1 | sed 's/[^0-9]*//g'`
2595 h2name_or_ip "$1" "o2ib"
2599 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2600 # expressions format. As a bonus we can then just pass in those variables
2601 # to pdsh. What this function does is take a HOSTLIST type string and
2602 # expand it into a space deliminated list for us.
2610 [ -z "$hostlist" ] && return
2612 # Translate the case of [..],..,[..] to [..] .. [..]
2613 list="${hostlist/],/] }"
2615 [[ "$front" == *,* ]] && {
2618 list=${list/${old}/${new}}
2621 for item in $list; do
2622 # Test if we have any []'s at all
2623 if [ "$item" != "${item/\[/}" ]; then {
2624 # Expand the [*] into list
2628 if [ "$name" != "$item" ]; then
2629 group=${item#$name[*}
2632 for range in ${group//,/ }; do
2636 # Number of leading zeros
2639 end=$(echo $end | sed 's/0*//')
2640 [[ -z "$end" ]] && end=0
2641 [[ $padlen2 -gt $padlen ]] && {
2642 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2645 begin=$(echo $begin | sed 's/0*//')
2646 [ -z $begin ] && begin=0
2648 for num in $(seq -f "%0${padlen}g" $begin $end); do
2649 value="${name#*,}${num}${back}"
2650 [ "$value" != "${value/\[/}" ] && {
2651 value=$(hostlist_expand "$value")
2653 myList="$myList $value"
2658 myList="$myList $item"
2661 myList=${myList//,/ }
2662 myList=${myList:1} # Remove first character which is a space
2664 # Filter any duplicates without sorting
2666 myList="${list%% *}"
2668 while [[ "$list" != ${myList##* } ]]; do
2669 list=${list//${list%% *} /}
2670 myList="$myList ${list%% *}"
2672 myList="${myList%* }";
2674 # We can select an object at a offset in the list
2677 for item in $myList; do
2679 [ $cnt -eq $offset ] && {
2683 [ $(get_node_count $myList) -ne 1 ] && myList=""
2692 [ "$facet" == client ] && echo -n $HOSTNAME && return
2693 varname=${facet}_HOST
2694 if [ -z "${!varname}" ]; then
2695 if [ "${facet:0:3}" == "ost" ]; then
2696 local fh=${facet%failover}_HOST
2697 eval export ${facet}_HOST=${!fh}
2698 if [ -z "${!varname}" ]; then
2699 eval export ${facet}_HOST=${ost_HOST}
2701 elif [ "${facet:0:3}" == "mdt" -o \
2702 "${facet:0:3}" == "mds" -o \
2703 "${facet:0:3}" == "mgs" ]; then
2704 eval export ${facet}_HOST=${mds_HOST}
2710 facet_failover_host() {
2714 var=${facet}failover_HOST
2715 if [ -n "${!var}" ]; then
2720 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2721 "${facet:0:3}" == "mgs" ]; then
2723 eval export ${facet}failover_host=${mds_HOST}
2728 if [[ $facet == ost* ]]; then
2729 eval export ${facet}failover_host=${ost_HOST}
2737 local activevar=${facet}active
2739 if [ -f $TMP/${facet}active ] ; then
2740 source $TMP/${facet}active
2743 active=${!activevar}
2744 if [ -z "$active" ] ; then
2751 facet_active_host() {
2753 local active=`facet_active $facet`
2754 if [ "$facet" == client ]; then
2757 echo `facet_host $active`
2761 # Get the passive failover partner host of facet.
2762 facet_passive_host() {
2764 [[ $facet = client ]] && return
2766 local host=${facet}_HOST
2767 local failover_host=${facet}failover_HOST
2768 local active_host=$(facet_active_host $facet)
2770 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2772 if [[ $active_host = ${!host} ]]; then
2773 echo -n ${!failover_host}
2783 facetlist=$(exclude_items_from_list $facetlist mgs)
2785 for facet in ${facetlist//,/ }; do
2786 local failover=${facet}failover
2787 local host=`facet_host $failover`
2788 [ -z "$host" ] && return
2790 local curactive=`facet_active $facet`
2791 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2792 eval export ${facet}active=$facet
2794 eval export ${facet}active=$failover
2796 # save the active host for this facet
2797 local activevar=${facet}active
2798 echo "$activevar=${!activevar}" > $TMP/$activevar
2799 [[ $facet = mds1 ]] && combined_mgs_mds && \
2800 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2801 local TO=`facet_active_host $facet`
2802 echo "Failover $facet to $TO"
2808 # do not stripe off hostname if verbose, bug 19215
2809 if [ x$1 = x--verbose ]; then
2817 if [ "$HOST" = "$HOSTNAME" ]; then
2819 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2820 echo "cannot run remote command on $HOST with $myPDSH"
2824 echo "CMD: $HOST $@" >&2
2825 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2828 if [ "$myPDSH" = "rsh" ]; then
2829 # we need this because rsh does not return exit code of an executed command
2830 local command_status="$TMP/cs"
2831 rsh $HOST ":> $command_status"
2832 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2833 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2834 echo command failed >$command_status"
2835 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2840 # print HOSTNAME for myPDSH="no_dsh"
2841 if [[ $myPDSH = no_dsh ]]; then
2842 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2844 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2847 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2849 return ${PIPESTATUS[0]}
2853 do_node --verbose "$@"
2856 single_local_node () {
2857 [ "$1" = "$HOSTNAME" ]
2860 # Outputs environment variable assignments that should be passed to remote nodes
2864 local facets=$(get_facets)
2867 for var in ${!MODOPTS_*}; do
2868 value=${!var//\"/\\\"}
2869 echo -n " ${var}=\"$value\""
2872 for facet in ${facets//,/ }; do
2874 if [ -n "${!var}" ]; then
2875 echo -n " $var=${!var}"
2879 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2880 if [ -n "${!var}" ]; then
2881 echo -n " $var=${!var}"
2885 if [ -n "$FSTYPE" ]; then
2886 echo -n " FSTYPE=$FSTYPE"
2892 # do not stripe off hostname if verbose, bug 19215
2893 if [ x$1 = x--verbose ]; then
2901 if single_local_node $rnodes; then
2903 do_nodev $rnodes "$@"
2905 do_node $rnodes "$@"
2910 # This is part from do_node
2913 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2914 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2916 export FANOUT=$(get_node_count "${rnodes//,/ }")
2918 echo "CMD: $rnodes $@" >&2
2919 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2922 # do not replace anything from pdsh output if -N is used
2923 # -N Disable hostname: prefix on lines of output.
2924 if $verbose || [[ $myPDSH = *-N* ]]; then
2925 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2927 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2929 return ${PIPESTATUS[0]}
2935 local HOST=`facet_active_host $facet`
2936 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2940 # Function: do_facet_random_file $FACET $FILE $SIZE
2941 # Creates FILE with random content on the given FACET of given SIZE
2943 do_facet_random_file() {
2947 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2948 do_facet $facet "$cmd 2>/dev/null"
2951 do_facet_create_file() {
2955 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2956 do_facet $facet "$cmd 2>/dev/null"
2960 do_nodes --verbose "$@"
2966 # make sure its not already running
2968 rm -f $TMP/${facet}active
2969 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2970 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2972 if [[ $(facet_fstype $facet) == zfs ]]; then
2974 # After formatting a ZFS target, "cachefile=none" property will
2975 # be set on the ZFS storage pool so that the pool is not
2976 # automatically imported on system startup. And then the pool
2977 # will be exported so as to leave the importing and exporting
2978 # operations handled by mount_facet() and stop() separately.
2980 refresh_partition_table $facet $(facet_vdevice $facet)
2981 disable_zpool_cache $facet
2986 # Device formatted as ost
2989 local DEVNAME=OSTDEV$num
2991 local fstype=$(facet_fstype ost$num)
2995 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2996 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2998 #try $OSTZFSDEVn - independent of vdev
2999 DEVNAME=OSTZFSDEV$num
3000 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3002 error "unknown fstype!";;
3008 # Physical device location of data
3014 local fstype=$(facet_fstype ost$num)
3018 # vdevs are not supported by ldiskfs
3021 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3022 # Device formated by zfs
3024 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3026 error "unknown fstype!";;
3032 # Logical device formated for lustre
3035 local DEVNAME=MDSDEV$num
3037 local fstype=$(facet_fstype mds$num)
3041 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3042 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3044 # try $MDSZFSDEVn - independent of vdev
3045 DEVNAME=MDSZFSDEV$num
3046 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3048 error "unknown fstype!";;
3054 # Physical location of data
3058 local fstype=$(facet_fstype mds$num)
3062 # vdevs are not supported by ldiskfs
3065 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3066 # Device formated by ZFS
3067 local DEVNAME=MDSDEV$num
3068 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3070 error "unknown fstype!";;
3078 local fstype=$(facet_fstype mgs)
3082 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3083 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3084 DEVPTR=$(mdsdevname 1)
3089 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3090 ( [ -z "$MGSZFSDEV" ] &&
3091 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3092 DEVPTR=$(mdsdevname 1)
3094 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3097 error "unknown fstype!";;
3106 local fstype=$(facet_fstype mgs)
3110 # vdevs are not supported by ldiskfs
3113 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3114 ( [ -z "$MGSDEV" ] &&
3115 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3116 VDEVPTR=$(mdsvdevname 1)
3117 elif [ -n "$MGSDEV" ]; then
3121 error "unknown fstype!";;
3129 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3131 local var=${facet}_MOUNT
3132 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3139 local dev=$(facet_device $facet)
3140 local mnt=$(facet_mntpt $facet)
3143 if ! do_facet $facet test -b $dev; then
3146 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3151 local dev=$(facet_device $facet)
3152 local mnt=$(facet_mntpt $facet)
3154 do_facet $facet umount -d $mnt
3158 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3163 local ds=$(facet_device $facet)
3164 local mnt=$(facet_mntpt $facet)
3169 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3170 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3171 do_facet $facet $ZFS set canmount=noauto $ds
3173 # The "legacy" mount method is used here because "zfs unmount $mnt"
3174 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3175 # targets are not available at the time, the stat(2) on $MOUNT will
3178 do_facet $facet $ZFS set mountpoint=legacy $ds
3179 do_facet $facet mount -t zfs $ds $mnt
3180 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3181 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3186 local ds=$(facet_device $facet)
3187 local mnt=$(facet_mntpt $facet)
3188 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3189 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3190 local mntpt=${!var_mntpt}
3191 local canmnt=${!var_canmnt}
3195 do_facet $facet umount $mnt
3196 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3197 do_facet $facet $ZFS set canmount=$canmnt $ds
3203 local fstype=$(facet_fstype $facet)
3205 mount_$fstype $facet
3210 local fstype=$(facet_fstype $facet)
3212 unmount_$fstype $facet
3219 # make sure we are using the primary server, so test-framework will
3220 # be able to clean up properly.
3221 activemds=`facet_active mds1`
3222 if [ $activemds != "mds1" ]; then
3226 local clients=$CLIENTS
3227 [ -z $clients ] && clients=$(hostname)
3229 zconf_umount_clients $clients $MOUNT "$*" || true
3230 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3232 [ "$CLIENTONLY" ] && return
3233 # The add fn does rm ${facet}active file, this would be enough
3234 # if we use do_facet <facet> only after the facet added, but
3235 # currently we use do_facet mds in local.sh
3236 for num in `seq $MDSCOUNT`; do
3238 rm -f ${TMP}/mds${num}active
3240 combined_mgs_mds && rm -f $TMP/mgsactive
3242 for num in `seq $OSTCOUNT`; do
3244 rm -f $TMP/ost${num}active
3247 if ! combined_mgs_mds ; then
3254 cleanup_echo_devs () {
3255 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3257 for dev in $devs; do
3258 $LCTL --device $dev cleanup
3259 $LCTL --device $dev detach
3264 nfs_client_mode && return
3273 combined_mgs_mds () {
3274 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3275 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3279 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3283 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3289 local fsname=${3:-"$FSNAME"}
3290 local type=$(facet_type $facet)
3291 local index=$(facet_index $facet)
3292 local fstype=$(facet_fstype $facet)
3293 local host=$(facet_host $facet)
3298 if [ $type == MGS ] || ( [ $type == MDS ] &&
3299 [ "$dev" == $(mgsdevname) ] &&
3300 [ "$host" == "$(facet_host mgs)" ] ); then
3303 opts="--mgsnode=$MGSNID"
3306 if [ $type != MGS ]; then
3307 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3311 var=${facet}failover_HOST
3312 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3313 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3316 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3317 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3319 if [ $type == MDS ]; then
3320 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3321 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3322 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3323 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3324 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3326 if [ $fstype == ldiskfs ]; then
3327 # Check for wide striping
3328 if [ $OSTCOUNT -gt 160 ]; then
3329 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3330 fs_mkfs_opts+="-O large_xattr"
3333 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3334 if [ ! -z $EJOURNAL ]; then
3335 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3337 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3341 if [ $type == OST ]; then
3342 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3343 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3345 if [ $fstype == ldiskfs ]; then
3346 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3350 opts+=" --backfstype=$fstype"
3353 if [ -n "${!var}" ]; then
3354 opts+=" --device-size=${!var}"
3357 var=$(upper $fstype)_MKFS_OPTS
3358 fs_mkfs_opts+=${!var:+" ${!var}"}
3360 var=${type}_FS_MKFS_OPTS
3361 fs_mkfs_opts+=${!var:+" ${!var}"}
3363 if [ -n "${fs_mkfs_opts## }" ]; then
3364 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3368 opts+=${!var:+" ${!var}"}
3373 check_ost_indices() {
3374 local index_count=${#OST_INDICES[@]}
3375 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3377 # OST count is greater than the index count in $OST_INDEX_LIST.
3378 # We need check whether there are duplicate indices.
3382 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3383 index=$(facet_index ost$i)
3384 for j in $(seq 0 $((index_count - 1))); do
3385 [[ $index -ne ${OST_INDICES[j]} ]] ||
3386 error "ost$i has the same index $index as ost$((j+1))"
3399 # We need ldiskfs here, may as well load them all
3401 [ "$CLIENTONLY" ] && return
3402 echo Formatting mgs, mds, osts
3403 if ! combined_mgs_mds ; then
3404 echo "Format mgs: $(mgsdevname)"
3405 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3406 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3410 for num in $(seq $MDSCOUNT); do
3411 echo "Format mds$num: $(mdsdevname $num)"
3412 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3413 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3414 ${quiet:+>/dev/null} || exit 10
3417 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3419 for num in $(seq $OSTCOUNT); do
3420 echo "Format ost$num: $(ostdevname $num)"
3421 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3422 --reformat $(ostdevname $num) $(ostvdevname ${num}) \