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}
13 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
19 # specify environment variable containing batch job name for server statistics
20 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
22 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
23 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
24 export LOAD_LLOOP=${LOAD_LLOOP:-false}
26 #export PDSH="pdsh -S -Rssh -w"
27 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
29 # function used by scripts run on remote nodes
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/functions.sh
32 . $LUSTRE/tests/yaml.sh
34 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
36 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
38 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
40 if [ -f "$EXCEPT_LIST_FILE" ]; then
41 echo "Reading test skip list from $EXCEPT_LIST_FILE"
46 # check config files for options in decreasing order of preference
47 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
48 MODPROBECONF=/etc/modprobe.d/lustre.conf
49 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
50 MODPROBECONF=/etc/modprobe.d/Lustre
51 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
52 MODPROBECONF=/etc/modprobe.conf
56 [[ $DIR/ = $MOUNT/* ]] || \
57 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
58 [[ $DIR1/ = $MOUNT1/* ]] || \
59 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
60 [[ $DIR2/ = $MOUNT2/* ]] || \
61 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
63 [ -n "$failed" ] && exit 99 || true
67 echo "usage: $0 [-r] [-f cfgfile]"
75 [ "$TESTSUITE" == "lfsck" ] && return 0
76 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
78 local form="%-13s %-17s %-9s %s %s\n"
79 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
80 echo "------------------------------------------------------------------------------------"
81 for O in $DEFAULT_SUITES; do
82 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
83 [ "${!O}" = "no" ] && continue || true
84 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
85 local log=${TMP}/${o}.log
86 if is_sanity_benchmark $o; then
87 log=${TMP}/sanity-benchmark.log
92 local status=Unfinished
94 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
96 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
97 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
98 total=$(grep duration $log | awk '{ print $2 }')
99 if [ "${!O}" = "done" ]; then
103 local durations=$(egrep "^PASS|^FAIL" $log |
104 tr -d "("| sed s/s\)$//g |
105 awk '{ print $2":"$3"|" }')
106 details=$(printf "%s\n%s %s %s\n" "$details" \
107 "DDETAILS" "$O" "$(echo $durations)")
110 printf "$form" $status "$O" "${total}" "E=$skipped"
111 printf "$form" "-" "-" "-" "S=$(echo $slow)"
114 for O in $DEFAULT_SUITES; do
115 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
116 if [ "${!O}" = "no" ]; then
117 printf "$form" "Skipped" "$O" ""
121 # print the detailed tests durations if DDETAILS=true
128 export LUSTRE=$(absolute_path $LUSTRE)
129 export TESTSUITE=$(basename $0 .sh)
130 export TEST_FAILED=false
131 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
132 export RPC_MODE=${RPC_MODE:-false}
134 export MKE2FS=$MKE2FS
135 if [ -z "$MKE2FS" ]; then
136 if which mkfs.ldiskfs >/dev/null 2>&1; then
137 export MKE2FS=mkfs.ldiskfs
143 export DEBUGFS=$DEBUGFS
144 if [ -z "$DEBUGFS" ]; then
145 if which debugfs.ldiskfs >/dev/null 2>&1; then
146 export DEBUGFS=debugfs.ldiskfs
148 export DEBUGFS=debugfs
152 export TUNE2FS=$TUNE2FS
153 if [ -z "$TUNE2FS" ]; then
154 if which tunefs.ldiskfs >/dev/null 2>&1; then
155 export TUNE2FS=tunefs.ldiskfs
157 export TUNE2FS=tune2fs
161 export E2LABEL=$E2LABEL
162 if [ -z "$E2LABEL" ]; then
163 if which label.ldiskfs >/dev/null 2>&1; then
164 export E2LABEL=label.ldiskfs
166 export E2LABEL=e2label
170 export DUMPE2FS=$DUMPE2FS
171 if [ -z "$DUMPE2FS" ]; then
172 if which dumpfs.ldiskfs >/dev/null 2>&1; then
173 export DUMPE2FS=dumpfs.ldiskfs
175 export DUMPE2FS=dumpe2fs
179 export E2FSCK=$E2FSCK
180 if [ -z "$E2FSCK" ]; then
181 if which fsck.ldiskfs >/dev/null 2>&1; then
182 export E2FSCK=fsck.ldiskfs
188 export RESIZE2FS=$RESIZE2FS
189 if [ -z "$RESIZE2FS" ]; then
190 if which resizefs.ldiskfs >/dev/null 2>&1; then
191 export RESIZE2FS=resizefs.ldiskfs
193 export RESIZE2FS=resize2fs
197 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
198 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
199 export FSCK_MAX_ERR=4 # File system errors left uncorrected
201 export ZFS=${ZFS:-zfs}
202 export ZPOOL=${ZPOOL:-zpool}
203 export ZDB=${ZDB:-zdb}
204 export PARTPROBE=${PARTPROBE:-partprobe}
206 #[ -d /r ] && export ROOT=${ROOT:-/r}
207 export TMP=${TMP:-$ROOT/tmp}
208 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
209 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
210 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
212 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
213 if ! echo $PATH | grep -q $LUSTRE/utils; then
214 export PATH=$LUSTRE/utils:$PATH
216 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
217 export PATH=$LUSTRE/utils/gss:$PATH
219 if ! echo $PATH | grep -q $LUSTRE/tests; then
220 export PATH=$LUSTRE/tests:$PATH
222 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
223 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
225 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
226 [ ! -f "$LST" ] && export LST=$(which lst)
227 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
228 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
229 # 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 # Synopsis: 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 we're
420 # 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 insmod ${LUSTRE}/${module}${EXT} "$@"
427 # must be testing a "make install" or "rpm" installation
428 # note failed to load ptlrpc_gss is considered not fatal
429 if [ "$BASE" == "ptlrpc_gss" ]; then
430 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
437 llite_lloop_enabled() {
438 local n1=$(uname -r | cut -d. -f1)
439 local n2=$(uname -r | cut -d. -f2)
440 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
442 # load the llite_lloop module for < 2.6.32 kernels
443 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
444 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
451 load_modules_local() {
452 if [ -n "$MODPROBE" ]; then
454 echo "Using modprobe to load modules"
458 echo Loading modules from $LUSTRE
462 if [ -f /sys/devices/system/cpu/online ]; then
463 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
464 echo "detected $ncpus online CPUs by sysfs"
466 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
468 if [ $rc -eq 0 ]; then
469 echo "detected $ncpus online CPUs by getconf"
471 echo "Can't detect number of CPUs"
476 # if there is only one CPU core, libcfs can only create one partition
477 # if there is more than 4 CPU cores, libcfs should create multiple CPU
478 # partitions. So we just force libcfs to create 2 partitions for
479 # system with 2 or 4 cores
480 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
481 # force to enable multiple CPU partitions
482 echo "Force libcfs to create 2 CPU partitions"
483 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
485 echo "libcfs will create CPU partition based on online CPUs"
488 load_module ../libcfs/libcfs/libcfs
490 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
491 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
492 load_module ../lnet/lnet/lnet
493 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
494 load_module ../lnet/klnds/$LNETLND
495 load_module obdclass/obdclass
496 load_module ptlrpc/ptlrpc
497 load_module ptlrpc/gss/ptlrpc_gss
505 load_module obdecho/obdecho
506 if ! client_only; then
507 SYMLIST=/proc/kallsyms
508 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
509 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
510 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
511 load_module lfsck/lfsck
512 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
513 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
515 load_module osd-zfs/osd_zfs
517 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
518 grep -q exportfs_decode_fh $SYMLIST ||
519 { modprobe exportfs 2> /dev/null || true; }
520 load_module ../ldiskfs/ldiskfs
521 load_module osd-ldiskfs/osd_ldiskfs
523 load_module nodemap/nodemap
534 load_module llite/lustre
535 llite_lloop_enabled && load_module llite/llite_lloop
536 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
538 rm -f $OGDB/ogdb-$HOSTNAME
539 $LCTL modules > $OGDB/ogdb-$HOSTNAME
541 # 'mount' doesn't look in $PATH, just sbin
542 local mount_lustre=$LUSTRE/utils/mount.lustre
543 if [ -f $mount_lustre ]; then
544 local sbin_mount=/sbin/mount.lustre
545 if grep -qe "$sbin_mount " /proc/mounts; then
546 cmp $mount_lustre $sbin_mount || umount $sbin_mount
548 if ! grep -qe "$sbin_mount " /proc/mounts; then
549 if [ ! -s "$sbin_mount" ]; then
550 cat <<- EOF > "$sbin_mount"
553 echo "This $sbin_mount just a mountpoint." 1>&2
554 echo "It is never supposed to be run." 1>&2
555 logger -p emerg -- "using stub $sbin_mount $@"
558 chmod a+x $sbin_mount
560 mount --bind $mount_lustre $sbin_mount
568 # load modules on remote nodes optionally
569 # lustre-tests have to be installed on these nodes
570 if $LOAD_MODULES_REMOTE; then
571 local list=$(comma_list $(remote_nodes_list))
572 if [ -n "$list" ]; then
573 echo "loading modules on: '$list'"
574 do_rpc_nodes "$list" load_modules_local
580 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
581 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
582 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
583 echo "$LEAK_LUSTRE" 1>&2
584 echo "$LEAK_PORTALS" 1>&2
585 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
586 echo "Memory leaks detected"
587 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
593 wait_exit_ST client # bug 12845
595 $LUSTRE_RMMOD ldiskfs || return 2
597 if $LOAD_MODULES_REMOTE; then
598 local list=$(comma_list $(remote_nodes_list))
599 if [ -n "$list" ]; then
600 echo "unloading modules on: '$list'"
601 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
602 do_rpc_nodes "$list" check_mem_leak
606 local sbin_mount=/sbin/mount.lustre
607 if grep -qe "$sbin_mount " /proc/mounts; then
608 umount $sbin_mount || true
609 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
613 check_mem_leak || return 254
615 echo "modules unloaded."
620 local facet=${1:-$SINGLEMDS}
621 local fstype=$(facet_fstype $facet)
624 ldiskfs) size=50;; # largest seen is 44, leave some headroom
625 zfs) size=400;; # largest seen is 384
631 check_gss_daemon_nodes() {
635 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
636 if [ \\\"\\\$num\\\" -ne 1 ]; then
637 echo \\\$num instance of $dname;
642 check_gss_daemon_facet() {
646 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
647 if [ $num -ne 1 ]; then
648 echo "$num instance of $dname on $facet"
657 echo Stopping $@ on $list
658 do_nodes $list "killall -2 $@ 2>/dev/null || true"
661 # start gss daemons on all nodes, or
662 # "daemon" on "list" if set
663 start_gss_daemons() {
667 if [ "$list" ] && [ "$daemon" ] ; then
668 echo "Starting gss daemon on nodes: $list"
669 do_nodes $list "$daemon" || return 8
673 local list=$(comma_list $(mdts_nodes))
674 echo "Starting gss daemon on mds: $list"
675 do_nodes $list "$LSVCGSSD -v" || return 1
677 do_nodes $list "$LGSSD -v" || return 2
680 list=$(comma_list $(osts_nodes))
681 echo "Starting gss daemon on ost: $list"
682 do_nodes $list "$LSVCGSSD -v" || return 3
683 # starting on clients
685 local clients=${CLIENTS:-`hostname`}
687 echo "Starting $LGSSD on clients $clients "
688 do_nodes $clients "$LGSSD -v" || return 4
691 # wait daemons entering "stable" status
695 # check daemons are running
697 list=$(comma_list $(mdts_nodes) $(osts_nodes))
698 check_gss_daemon_nodes $list lsvcgssd || return 5
700 list=$(comma_list $(mdts_nodes))
701 check_gss_daemon_nodes $list lgssd || return 6
704 check_gss_daemon_nodes $clients lgssd || return 7
709 local list=$(comma_list $(mdts_nodes))
711 send_sigint $list lsvcgssd lgssd
713 list=$(comma_list $(osts_nodes))
714 send_sigint $list lsvcgssd
716 list=${CLIENTS:-`hostname`}
717 send_sigint $list lgssd
722 if ! module_loaded ptlrpc_gss; then
723 load_module ptlrpc/gss/ptlrpc_gss
724 module_loaded ptlrpc_gss ||
725 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
728 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
731 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
732 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
740 # maybe cleanup credential cache?
746 local var=${facet}_svc
754 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
755 tr '[:lower:]' '[:upper:]'
761 if [ $facet == mgs ]; then
765 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
773 if [ -n "${!var}" ]; then
778 var=$(facet_type $facet)FSTYPE
779 if [ -n "${!var}" ]; then
784 if [ -n "$FSTYPE" ]; then
789 if [[ $facet == mgs ]] && combined_mgs_mds; then
801 local facets=$(get_facets)
804 for facet in ${facets//,/ }; do
805 if [ $node == $(facet_host $facet) ] ||
806 [ $node == "$(facet_failover_host $facet)" ]; then
807 fstype=$(facet_fstype $facet)
808 if [[ $fstypes != *$fstype* ]]; then
809 fstypes+="${fstypes:+,}$fstype"
820 local fstype=$(facet_fstype $facet)
824 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
826 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
827 ${dev} 2>/dev/null");;
829 error "unknown fstype!";;
837 local device=$(mdsdevname $num)
838 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
844 local device=$(ostdevname $num)
845 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
850 # Get the device of a facet.
857 mgs) device=$(mgsdevname) ;;
858 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
859 ost*) device=$(ostdevname $(facet_number $facet)) ;;
860 fs2mds) device=$(mdsdevname 1_2) ;;
861 fs2ost) device=$(ostdevname 1_2) ;;
862 fs3ost) device=$(ostdevname 2_2) ;;
870 # Get the virtual device of a facet.
877 mgs) device=$(mgsvdevname) ;;
878 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
879 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
880 fs2mds) device=$(mdsvdevname 1_2) ;;
881 fs2ost) device=$(ostvdevname 1_2) ;;
882 fs3ost) device=$(ostvdevname 2_2) ;;
890 # Re-read the partition table on failover partner host.
891 # After a ZFS storage pool is created on a shared device, the partition table
892 # on the device may change. However, the operating system on the failover
893 # host may not notice the change automatically. Without the up-to-date partition
894 # block devices, 'zpool import ..' cannot find the labels, whose positions are
895 # relative to partition rather than disk beginnings.
897 # This function performs partprobe on the failover host to make it re-read the
900 refresh_partition_table() {
905 host=$(facet_passive_host $facet)
906 if [[ -n "$host" ]]; then
907 do_node $host "$PARTPROBE $device"
912 # Get ZFS storage pool name.
919 device=$(facet_device $facet)
920 # poolname is string before "/"
921 poolname="${device%%/*}"
927 # Create ZFS storage pool.
934 local opts=${@:-"-o cachefile=none"}
936 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
937 $ZPOOL create -f $opts $poolname $vdev"
941 # Create ZFS file system.
947 local opts=${@:-"-o mountpoint=legacy"}
949 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
950 $ZFS create $opts $dataset"
954 # Export ZFS storage pool.
955 # Before exporting the pool, all datasets within the pool should be unmounted.
963 poolname=$(zpool_name $facet)
965 if [[ -n "$poolname" ]]; then
966 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
967 grep -q ^$poolname/ /proc/mounts ||
968 $ZPOOL export $opts $poolname"
973 # Destroy ZFS storage pool.
974 # Destroy the given pool and free up any devices for other use. This command
975 # tries to unmount any active datasets before destroying the pool.
976 # -f Force any active datasets contained within the pool to be unmounted.
980 local poolname=${2:-$(zpool_name $facet)}
982 if [[ -n "$poolname" ]]; then
983 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
984 $ZPOOL destroy -f $poolname"
989 # Import ZFS storage pool.
990 # Force importing, even if the pool appears to be potentially active.
995 local opts=${@:-"-o cachefile=none"}
998 poolname=$(zpool_name $facet)
1000 if [[ -n "$poolname" ]]; then
1001 opts+=" -d $(dirname $(facet_vdevice $facet))"
1002 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1003 $ZPOOL import -f $opts $poolname"
1008 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1009 # is not automatically imported on system startup.
1011 # In a failover environment, this will provide resource level fencing which
1012 # will ensure that the same ZFS storage pool will not be imported concurrently
1013 # on different nodes.
1015 disable_zpool_cache() {
1019 poolname=$(zpool_name $facet)
1021 if [[ -n "$poolname" ]]; then
1022 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1027 # This and set_osd_param() shall be used to access OSD parameters
1028 # once existed under "obdfilter":
1033 # writethrough_cache_enable
1037 local device=${2:-$FSNAME-OST*}
1040 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1041 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1046 local device=${2:-$FSNAME-OST*}
1050 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1051 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1055 local dz=${1:-$DEBUG_SIZE}
1057 if [ -f /sys/devices/system/cpu/possible ]; then
1058 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1060 local cpus=$(getconf _NPROCESSORS_CONF)
1063 # bug 19944, adjust size to be -gt num_possible_cpus()
1064 # promise 2MB for every cpu at least
1065 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1068 lctl set_param debug_mb=$dz
1071 set_default_debug () {
1072 local debug=${1:-"$PTLDEBUG"}
1073 local subsys=${2:-"$SUBSYSTEM"}
1074 local debug_size=${3:-$DEBUG_SIZE}
1076 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1077 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1079 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1082 set_default_debug_nodes () {
1085 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1086 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1090 do_rpc_nodes "$nodes" set_default_debug \
1091 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1094 set_default_debug_facet () {
1096 local node=$(facet_active_host $facet)
1097 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1099 set_default_debug_nodes $node
1104 local facets=${1:-$(get_facets)}
1107 for facet in ${facets//,/ }; do
1110 [ $RC -eq 0 ] && continue
1112 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1113 skip "Restart of $facet failed!." && touch $LU482_FAILED
1115 error "Restart of $facet failed!"
1122 # Add argument "arg" (e.g., "loop") to the comma-separated list
1123 # of arguments for option "opt" (e.g., "-o") on command
1124 # line "opts" (e.g., "-o flock").
1130 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1132 if echo "$opts" | grep -q $opt_pattern; then
1133 opts=$(echo "$opts" | sed -e \
1134 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1136 opts+="${opts:+ }$opt $arg"
1144 local dev=$(facet_active $facet)_dev
1145 local opt=${facet}_opt
1146 local mntpt=$(facet_mntpt $facet)
1147 local opts="${!opt} $@"
1149 if [ $(facet_fstype $facet) == ldiskfs ] &&
1150 ! do_facet $facet test -b ${!dev}; then
1151 opts=$(csa_add "$opts" -o loop)
1154 if [[ $(facet_fstype $facet) == zfs ]]; then
1155 # import ZFS storage pool
1156 import_zpool $facet || return ${PIPESTATUS[0]}
1159 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1160 # for testing LU-482 error handling in mount_facets() and test_0a()
1161 if [ -f $TMP/test-lu482-trigger ]; then
1164 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1168 if [ $RC -ne 0 ]; then
1169 echo "Start of ${!dev} on ${facet} failed ${RC}"
1171 set_default_debug_facet $facet
1173 label=$(devicelabel ${facet} ${!dev})
1174 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1175 eval export ${facet}_svc=${label}
1176 echo Started ${label}
1181 # start facet device options
1187 eval export ${facet}_dev=${device}
1188 eval export ${facet}_opt=\"$@\"
1190 local varname=${facet}failover_dev
1191 if [ -n "${!varname}" ] ; then
1192 eval export ${facet}failover_dev=${!varname}
1194 eval export ${facet}failover_dev=$device
1197 local mntpt=$(facet_mntpt $facet)
1198 do_facet ${facet} mkdir -p $mntpt
1199 eval export ${facet}_MOUNT=$mntpt
1200 mount_facet ${facet}
1203 if [[ $facet == mds* ]]; then
1205 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1216 local HOST=`facet_active_host $facet`
1217 [ -z $HOST ] && echo stop: no host for $facet && return 0
1219 local mntpt=$(facet_mntpt $facet)
1220 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1221 if [ ${running} -ne 0 ]; then
1222 echo "Stopping $mntpt (opts:$@) on $HOST"
1223 do_facet ${facet} umount -d $@ $mntpt
1226 # umount should block, but we should wait for unrelated obd's
1227 # like the MGS or MGC to also stop.
1228 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1230 if [[ $(facet_fstype $facet) == zfs ]]; then
1231 # export ZFS storage pool
1236 # save quota version (both administrative and operational quotas)
1237 # add an additional parameter if mountpoint is ever different from $MOUNT
1239 # XXX This function is kept for interoperability with old server (< 2.3.50),
1240 # it should be removed whenever we drop the interoperability for such
1242 quota_save_version() {
1243 local fsname=${2:-$FSNAME}
1245 local ver=$(tr -c -d "123" <<< $spec)
1246 local type=$(tr -c -d "ug" <<< $spec)
1248 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1250 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1252 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1254 local osts=$(get_facets OST)
1255 for ost in ${osts//,/ }; do
1257 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1261 # client could mount several lustre
1263 # XXX This function is kept for interoperability with old server (< 2.3.50),
1264 # it should be removed whenever we drop the interoperability for such
1267 local fsname=${1:-$FSNAME}
1269 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1271 do_nodes $(comma_list $(osts_nodes)) \
1272 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1276 # XXX This function is kept for interoperability with old server (< 2.3.50),
1277 # it should be removed whenever we drop the interoperability for such
1279 restore_quota_old() {
1280 local mntpt=${1:-$MOUNT}
1281 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1282 if [ ! "$old_QUOTA_TYPE" ] ||
1283 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1286 quota_save_version $old_QUOTA_TYPE
1289 # XXX This function is kept for interoperability with old server (< 2.3.50),
1290 # it should be removed whenever we drop the interoperability for such
1295 # no quota enforcement for now and accounting works out of the box
1298 # We need save the original quota_type params, and restore them after testing
1300 # Suppose that quota type the same on mds and ost
1301 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1302 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1303 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1304 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1305 export old_QUOTA_TYPE=$quota_type
1306 quota_save_version $QUOTA_TYPE
1308 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1309 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1312 local quota_usrs=$QUOTA_USERS
1314 # get_filesystem_size
1315 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1316 local blk_soft=$((disksz + 1024))
1317 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1319 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1320 local i_soft=$Inodes
1321 local i_hard=$((i_soft + i_soft / 20))
1323 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1324 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1327 for usr in $quota_usrs; do
1328 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1330 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1332 eval $cmd || error "$cmd FAILED!"
1334 # display the quota status
1335 echo "Quota settings for $usr : "
1336 $LFS quota -v -u $usr $mntpt || true
1340 # get mdt quota type
1342 local varsvc=${SINGLEMDS}_svc
1343 do_facet $SINGLEMDS $LCTL get_param -n \
1344 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1347 # get ost quota type
1349 # All OSTs should have same quota type
1350 local varsvc=ost1_svc
1351 do_facet ost1 $LCTL get_param -n \
1352 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1355 # restore old quota type settings
1357 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1362 if [ "$old_MDT_QUOTA_TYPE" ]; then
1363 do_facet mgs $LCTL conf_param \
1364 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1366 if [ "$old_OST_QUOTA_TYPE" ]; then
1367 do_facet mgs $LCTL conf_param \
1368 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1372 # Handle the case when there is a space in the lfs df
1373 # "filesystem summary" line the same as when there is no space.
1374 # This will allow fixing the "lfs df" summary line in the future.
1376 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1379 # Get free inodes on the MDT specified by mdt index, free indoes on
1380 # the whole filesystem will be returned when index == -1.
1386 if [ $index -eq -1 ]; then
1389 mdt_uuid=$(mdtuuid_from_index $index)
1392 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1397 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1404 # save old quota type & set new quota type
1405 local mdt_qtype=$(mdt_quota_type)
1406 local ost_qtype=$(ost_quota_type)
1408 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1409 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1411 export old_MDT_QUOTA_TYPE=$mdt_qtype
1412 export old_OST_QUOTA_TYPE=$ost_qtype
1414 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1415 error "set mdt quota type failed"
1416 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1417 error "set ost quota type failed"
1419 local quota_usrs=$QUOTA_USERS
1421 # get_filesystem_size
1422 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1423 local blk_soft=$((disksz + 1024))
1424 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1426 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1427 local i_soft=$inodes
1428 local i_hard=$((i_soft + i_soft / 20))
1430 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1431 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1432 "inode-hardlimit: $i_hard"
1435 for usr in $quota_usrs; do
1436 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1438 cmd="$LFS setquota -$type $usr -b $blk_soft"
1439 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1441 eval $cmd || error "$cmd FAILED!"
1443 # display the quota status
1444 echo "Quota settings for $usr : "
1445 $LFS quota -v -u $usr $mntpt || true
1452 local OPTIONS=${3:-$MOUNTOPT}
1454 local device=$MGSNID:/$FSNAME
1455 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1456 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1460 echo "Starting client: $client: $OPTIONS $device $mnt"
1461 do_node $client mkdir -p $mnt
1462 do_node $client $MOUNT_CMD $OPTIONS $device $mnt || return 1
1464 set_default_debug_nodes $client
1476 [ "$3" ] && force=-f
1477 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1478 if [ $running -ne 0 ]; then
1479 echo "Stopping client $client $mnt (opts:$force)"
1480 do_node $client lsof -t $mnt || need_kill=no
1481 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1482 pids=$(do_node $client lsof -t $mnt | sort -u);
1483 if [ -n $pids ]; then
1484 do_node $client kill -9 $pids || true
1488 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1489 if [ $busy -ne 0 ] ; then
1490 echo "$mnt is still busy, wait one second" && sleep 1
1491 do_node $client umount $force $mnt
1496 # nodes is comma list
1497 sanity_mount_check_nodes () {
1503 # FIXME: assume that all cluster nodes run the same os
1504 [ "$(uname)" = Linux ] || return 0
1507 for mnt in $mnts ; do
1508 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1509 mpts=\\\$(mount | grep -c $mnt' ');
1510 if [ \\\$running -ne \\\$mpts ]; then
1511 echo \\\$(hostname) env are INSANE!;
1514 [ $? -eq 0 ] || rc=1
1519 sanity_mount_check_servers () {
1520 [ "$CLIENTONLY" ] &&
1521 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1522 echo Checking servers environments
1524 # FIXME: modify get_facets to display all facets wo params
1525 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1529 for facet in ${facets//,/ }; do
1530 node=$(facet_host ${facet})
1531 mntpt=$(facet_mntpt $facet)
1532 sanity_mount_check_nodes $node $mntpt ||
1533 { error "server $node environments are insane!"; return 1; }
1537 sanity_mount_check_clients () {
1538 local clients=${1:-$CLIENTS}
1539 local mntpt=${2:-$MOUNT}
1540 local mntpt2=${3:-$MOUNT2}
1542 [ -z $clients ] && clients=$(hostname)
1543 echo Checking clients $clients environments
1545 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1546 error "clients environments are insane!"
1549 sanity_mount_check () {
1550 sanity_mount_check_servers || return 1
1551 sanity_mount_check_clients || return 2
1554 # mount clients if not mouted
1555 zconf_mount_clients() {
1558 local OPTIONS=${3:-$MOUNTOPT}
1560 local device=$MGSNID:/$FSNAME
1561 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1562 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1566 echo "Starting client $clients: $OPTIONS $device $mnt"
1569 running=\\\$(mount | grep -c $mnt' ');
1571 if [ \\\$running -eq 0 ] ; then
1573 $MOUNT_CMD $OPTIONS $device $mnt;
1576 exit \\\$rc" || return ${PIPESTATUS[0]}
1578 echo "Started clients $clients: "
1579 do_nodes $clients "mount | grep $mnt' '"
1581 set_default_debug_nodes $clients
1586 zconf_umount_clients() {
1591 [ "$3" ] && force=-f
1593 echo "Stopping clients: $clients $mnt (opts:$force)"
1594 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1595 if [ \\\$running -ne 0 ] ; then
1596 echo Stopping client \\\$(hostname) $mnt opts:$force;
1597 lsof $mnt || need_kill=no;
1598 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1599 pids=\\\$(lsof -t $mnt | sort -u);
1600 if [ -n \\\"\\\$pids\\\" ]; then
1604 while umount $force $mnt 2>&1 | grep -q "busy"; do
1605 echo "$mnt is still busy, wait one second" && sleep 1;
1612 echo + $POWER_DOWN $node
1616 shutdown_node_hard () {
1618 local attempts=$SHUTDOWN_ATTEMPTS
1620 for i in $(seq $attempts) ; do
1623 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1624 echo "waiting for $host to fail attempts=$attempts"
1625 [ $i -lt $attempts ] || \
1626 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1632 local mnt=${2:-$MOUNT}
1635 if [ "$FAILURE_MODE" = HARD ]; then
1636 shutdown_node_hard $client
1638 zconf_umount_clients $client $mnt -f
1644 local facets="$(get_facets OST),$(get_facets MDS)"
1647 combined_mgs_mds || facets="$facets,mgs"
1649 for facet in ${facets//,/ }; do
1650 if [ $(facet_active_host $facet) == $host ]; then
1651 affected="$affected $facet"
1655 echo $(comma_list $affected)
1660 local host=${2:-$(facet_host $facet)}
1662 local label=$(convert_facet2label $facet)
1663 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1666 facets_up_on_host () {
1668 local facets=$(facets_on_host $host)
1671 for facet in ${facets//,/ }; do
1672 if $(facet_up $facet $host); then
1673 affected_up="$affected_up $facet"
1677 echo $(comma_list $affected_up)
1683 if [ "$FAILURE_MODE" = HARD ]; then
1684 shutdown_node_hard $(facet_active_host $facet)
1692 echo + $POWER_UP $node
1705 if [ "$FAILURE_MODE" = HARD ]; then
1706 reboot_node $(facet_active_host $facet)
1714 if [ "$FAILURE_MODE" = HARD ]; then
1724 for facet in ${facets//,/ }; do
1725 hosts=$(expand_list $hosts $(facet_host $facet) )
1731 _check_progs_installed () {
1735 for prog in $progs; do
1736 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1737 echo $prog missing on $(hostname)
1744 check_progs_installed () {
1748 do_rpc_nodes "$nodes" _check_progs_installed $@
1751 # recovery-scale functions
1753 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1756 start_client_load() {
1759 local var=$(node_var_name $client)_load
1760 eval export ${var}=$load
1762 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1763 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1764 END_RUN_FILE=$END_RUN_FILE \
1765 LOAD_PID_FILE=$LOAD_PID_FILE \
1766 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1767 TESTNAME=$TESTNAME \
1768 DBENCH_LIB=$DBENCH_LIB \
1769 DBENCH_SRC=$DBENCH_SRC \
1770 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1774 log "Started client load: ${load} on $client"
1776 # get the children process IDs
1777 local pids=$(ps --ppid $ppid -o pid= | xargs)
1778 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1782 start_client_loads () {
1783 local -a clients=(${1//,/ })
1784 local numloads=${#CLIENT_LOADS[@]}
1787 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1788 testnum=$((nodenum % numloads))
1789 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1791 # bug 22169: wait the background threads to start
1795 # only for remote client
1796 check_client_load () {
1798 local var=$(node_var_name $client)_load
1799 local TESTLOAD=run_${!var}.sh
1801 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1803 # bug 18914: try to connect several times not only when
1804 # check ps, but while check_catastrophe also
1807 while [ $RC = 254 -a $tries -gt 0 ]; do
1811 if ! check_catastrophe $client; then
1813 if [ $RC -eq 254 ]; then
1814 # FIXME: not sure how long we shuold sleep here
1818 echo "check catastrophe failed: RC=$RC "
1822 # We can continue try to connect if RC=254
1823 # Just print the warning about this
1824 if [ $RC = 254 ]; then
1825 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1828 # see if the load is still on the client
1831 while [ $RC = 254 -a $tries -gt 0 ]; do
1835 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1840 if [ $RC = 254 ]; then
1841 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1842 # see if we can diagnose a bit why this is
1847 check_client_loads () {
1848 local clients=${1//,/ }
1852 for client in $clients; do
1853 check_client_load $client
1855 if [ "$rc" != 0 ]; then
1856 log "Client load failed on node $client, rc=$rc"
1862 restart_client_loads () {
1863 local clients=${1//,/ }
1864 local expectedfail=${2:-""}
1868 for client in $clients; do
1869 check_client_load $client
1871 if [ "$rc" != 0 -a "$expectedfail" ]; then
1872 local var=$(node_var_name $client)_load
1873 start_client_load $client ${!var}
1874 echo "Restarted client load ${!var}: on $client. Checking ..."
1875 check_client_load $client
1877 if [ "$rc" != 0 ]; then
1878 log "Client load failed to restart on node $client, rc=$rc"
1879 # failure one client load means test fail
1880 # we do not need to check other
1889 # Start vmstat and save its process ID in a file.
1894 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1897 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1898 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1901 # Display the nodes on which client loads failed.
1902 print_end_run_file() {
1906 [ -s $file ] || return 0
1908 echo "Found the END_RUN_FILE file: $file"
1911 # A client load will stop if it finds the END_RUN_FILE file.
1912 # That does not mean the client load actually failed though.
1913 # The first node in END_RUN_FILE is the one we are interested in.
1916 if [ -n "$node" ]; then
1917 local var=$(node_var_name $node)_load
1919 local prefix=$TESTLOG_PREFIX
1920 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1921 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1922 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1924 echo "Client load ${!var} failed on node $node:"
1930 # Stop the process which had its PID saved in a file.
1935 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1937 do_nodes $nodes "test -f $pid_file &&
1938 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1941 # Stop all client loads.
1942 stop_client_loads() {
1943 local nodes=${1:-$CLIENTS}
1946 # stop the client loads
1947 stop_process $nodes $pid_file
1949 # clean up the processes that started them
1950 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1952 # End recovery-scale functions
1954 # verify that lustre actually cleaned up properly
1956 [ -f "$CATASTROPHE" ] && [[ $(< $CATASTROPHE) -ne 0 ]] &&
1957 error "LBUG/LASSERT detected"
1958 BUSY=$(dmesg | grep -i destruct || true)
1959 if [ -n "$BUSY" ]; then
1961 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
1965 check_mem_leak || exit 204
1967 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
1968 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1971 if module_loaded lnet || module_loaded libcfs; then
1972 echo "$TESTSUITE: modules still loaded..." 1>&2
1981 if [[ "$1" == "--verbose" ]]; then
1996 PREV_RESULT=$(do_node $node "$TEST")
1998 RESULT=$(do_node $node "$TEST")
1999 if [[ "$RESULT" == "$FINAL" ]]; then
2000 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2001 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2005 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2006 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2010 [[ $WAIT -ge $MAX ]] && break
2011 [[ $((WAIT % print)) -eq 0 ]] &&
2012 echo "Waiting $((MAX - WAIT)) secs for update"
2013 WAIT=$((WAIT + sleep))
2016 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2020 wait_update_facet() {
2023 wait_update $(facet_active_host $facet) "$@"
2027 do_nodes $(comma_list $(mdts_nodes)) \
2028 "lctl set_param -n osd*.*MDT*.force_sync 1"
2029 do_nodes $(comma_list $(osts_nodes)) \
2030 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2031 grep -v 'Found no match'
2034 wait_delete_completed_mds() {
2035 local MAX_WAIT=${1:-20}
2037 local stime=$(date +%s)
2042 # find MDS with pending deletions
2043 for node in $(mdts_nodes); do
2044 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2045 2>/dev/null | calc_sum)
2046 if [[ $changes -eq 0 ]]; then
2049 mds2sync="$mds2sync $node"
2051 if [ -z "$mds2sync" ]; then
2054 mds2sync=$(comma_list $mds2sync)
2056 # sync MDS transactions
2057 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2059 # wait till all changes are sent and commmitted by OSTs
2060 # for ldiskfs space is released upon execution, but DMU
2061 # do this upon commit
2064 while [[ $WAIT -ne $MAX_WAIT ]]; do
2065 changes=$(do_nodes $mds2sync \
2066 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2067 #echo "$node: $changes changes on all"
2068 if [[ $changes -eq 0 ]]; then
2070 #echo "delete took $((etime - stime)) seconds"
2078 echo "Delete is not completed in $((etime - stime)) seconds"
2079 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2085 # we can use "for" here because we are waiting the slowest
2086 for host in ${hostlist//,/ }; do
2087 check_network "$host" 900
2089 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2096 for facet in ${facetlist//,/ }; do
2097 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2099 wait_for_host $hostlist
2102 _wait_recovery_complete () {
2105 # Use default policy if $2 is not passed by caller.
2106 local MAX=${2:-$(max_recovery_time)}
2111 while [ $WAIT -lt $MAX ]; do
2112 STATUS=$(lctl get_param -n $param | grep status)
2114 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2117 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2119 echo "$param recovery not done in $MAX sec. $STATUS"
2123 wait_recovery_complete () {
2126 # with an assumption that at_max is the same on all nodes
2127 local MAX=${2:-$(max_recovery_time)}
2130 if [ "$FAILURE_MODE" = HARD ]; then
2131 facets=$(facets_on_host $(facet_active_host $facet))
2133 echo affected facets: $facets
2135 # we can use "for" here because we are waiting the slowest
2136 for facet in ${facets//,/ }; do
2137 local var_svc=${facet}_svc
2138 local param="*.${!var_svc}.recovery_status"
2140 local host=$(facet_active_host $facet)
2141 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2145 wait_mds_ost_sync () {
2146 # just because recovery is done doesn't mean we've finished
2147 # orphan cleanup. Wait for llogs to get synchronized.
2148 echo "Waiting for orphan cleanup..."
2149 # MAX value includes time needed for MDS-OST reconnection
2150 local MAX=$(( TIMEOUT * 2 ))
2151 local WAIT_TIMEOUT=${1:-$MAX}
2154 local list=$(comma_list $(mdts_nodes))
2155 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2156 if ! do_facet $SINGLEMDS \
2157 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2159 # old way, use mds_sync
2161 list=$(comma_list $(osts_nodes))
2162 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2165 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2166 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2167 local -a sync=($(do_nodes $list "$cmd"))
2170 for ((i=0; i<${#sync[@]}; i++)); do
2172 [ ${sync[$i]} -eq 1 ] && continue
2174 [ ${sync[$i]} -eq 0 ] && continue
2176 # there is a not finished MDS-OST synchronization
2180 sleep 2 # increase waiting time and cover statfs cache
2181 [ ${con} -eq 1 ] && return 0
2182 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2186 # show which nodes are not finished.
2187 do_nodes $list "$cmd"
2188 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2192 wait_destroy_complete () {
2193 echo "Waiting for local destroys to complete"
2194 # MAX value shouldn't be big as this mean server responsiveness
2195 # never increase this just to make test pass but investigate
2196 # why it takes so long time
2199 while [ $WAIT -lt $MAX ]; do
2200 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2204 for ((i=0; i<${#RPCs[@]}; i++)); do
2205 [ ${RPCs[$i]} -eq 0 ] && continue
2206 # there are still some destroy RPCs in flight
2211 [ ${con} -eq 1 ] && return 0 # done waiting
2212 echo "Waiting ${WAIT}s for local destroys to complete"
2215 echo "Local destroys weren't done in $MAX sec."
2219 wait_delete_completed() {
2220 wait_delete_completed_mds $1 || return $?
2221 wait_destroy_complete
2230 # conf-sanity 31 takes a long time cleanup
2231 while [ $WAIT -lt 300 ]; do
2232 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2233 [ -z "${running}" ] && return 0
2234 echo "waited $WAIT for${running}"
2235 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2237 WAIT=$((WAIT + INTERVAL))
2239 echo "service didn't stop after $WAIT seconds. Still running:"
2244 wait_remote_prog () {
2250 [ "$PDSH" = "no_dsh" ] && return 0
2252 while [ $WAIT -lt $2 ]; do
2253 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2254 [ -z "${running}" ] && return 0 || true
2255 echo "waited $WAIT for: "
2257 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2259 WAIT=$((WAIT + INTERVAL))
2261 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2262 [ -z "$pids" ] && return 0
2263 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2264 # FIXME: not portable
2265 for pid in $pids; do
2266 cat /proc/${pid}/status || true
2267 cat /proc/${pid}/wchan || true
2269 kill -9 $pid || true
2278 # not every config has many clients
2280 if [ ! -z "$CLIENTS" ]; then
2281 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2283 stat -f $MOUNT > /dev/null
2289 # usually checked on particular client or locally
2291 if [ ! -z "$client" ]; then
2292 $PDSH $client "stat -f $MOUNT" > /dev/null
2294 stat -f $MOUNT > /dev/null
2302 client_reconnect_try() {
2303 uname -n >> $MOUNT/recon
2304 if [ -z "$CLIENTS" ]; then
2305 df $MOUNT; uname -n >> $MOUNT/recon
2307 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2309 echo Connected clients:
2311 ls -l $MOUNT/recon > /dev/null
2315 client_reconnect() {
2316 # one client_reconnect_try call does not always do the job...
2318 client_reconnect_try && break
2323 affected_facets () {
2326 local host=$(facet_active_host $facet)
2327 local affected=$facet
2329 if [ "$FAILURE_MODE" = HARD ]; then
2330 affected=$(facets_up_on_host $host)
2344 #Because it will only get up facets, we need get affected
2345 #facets before shutdown
2346 #For HARD Failure mode, it needs make sure facets on the same
2347 #HOST will only be shutdown and reboot once
2348 for facet in ${facets//,/ }; do
2349 local affected_facet
2351 #check whether facet has been included in other affected facets
2352 for ((index=0; index<$total; index++)); do
2353 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2356 if [ $skip -eq 0 ]; then
2357 affecteds[$total]=$(affected_facets $facet)
2362 for ((index=0; index<$total; index++)); do
2363 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2364 local host=$(facet_active_host $facet)
2365 echo "Failing ${affecteds[index]} on $host"
2366 shutdown_facet $facet
2369 for ((index=0; index<$total; index++)); do
2370 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2371 echo reboot facets: ${affecteds[index]}
2375 change_active ${affecteds[index]}
2377 wait_for_facet ${affecteds[index]}
2378 # start mgs first if it is affected
2379 if ! combined_mgs_mds &&
2380 list_member ${affecteds[index]} mgs; then
2381 mount_facet mgs || error "Restart of mgs failed"
2383 # FIXME; has to be changed to mount all facets concurrently
2384 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2385 echo mount facets: ${affecteds[index]}
2386 mount_facets ${affecteds[index]}
2396 do_facet $facet "sync; sync; sync"
2399 # make sure there will be no seq change
2400 local clients=${CLIENTS:-$HOSTNAME}
2401 local f=fsa-\\\$\(hostname\)
2402 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2403 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2405 local svc=${facet}_svc
2406 do_facet $facet $LCTL --device ${!svc} notransno
2408 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2409 # in-memory state has to be cleared by either rebooting the host or
2410 # exporting and reimporting the pool.
2412 # Although the uberblocks are not updated when a pool is freezed,
2413 # transactions are still written to the disks. Modified blocks may be
2414 # cached in memory when tests try reading them back. The
2415 # export-and-reimport process also evicts any cached pool data from
2416 # memory to provide the correct "data loss" semantics.
2418 # In the test framework, the exporting and importing operations are
2419 # handled by stop() and mount_facet() separately, which are used
2420 # inside fail() and fail_abort().
2422 do_facet $facet $LCTL --device ${!svc} readonly
2423 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2424 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2427 replay_barrier_nodf() {
2428 local facet=$1 echo running=${running}
2429 do_facet $facet "sync; sync; sync"
2430 local svc=${facet}_svc
2431 echo Replay barrier on ${!svc}
2432 do_facet $facet $LCTL --device ${!svc} notransno
2433 do_facet $facet $LCTL --device ${!svc} readonly
2434 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2435 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2438 replay_barrier_nosync() {
2439 local facet=$1 echo running=${running}
2440 local svc=${facet}_svc
2441 echo Replay barrier on ${!svc}
2442 do_facet $facet $LCTL --device ${!svc} notransno
2443 do_facet $facet $LCTL --device ${!svc} readonly
2444 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2445 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2449 # Get Lustre client uuid for a given Lustre mount point.
2452 local mntpnt=${1:-$MOUNT}
2454 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2455 local uuid=$($LCTL get_param -n llite.$name.uuid)
2460 mds_evict_client() {
2461 local mntpnt=${1:-$MOUNT}
2462 local uuid=$(get_client_uuid $mntpnt)
2464 do_facet $SINGLEMDS \
2465 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2468 ost_evict_client() {
2469 local mntpnt=${1:-$MOUNT}
2470 local uuid=$(get_client_uuid $mntpnt)
2473 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2478 local clients=${CLIENTS:-$HOSTNAME}
2480 facet_failover $* || error "failover: $?"
2481 wait_clients_import_state "$clients" "$facets" FULL
2482 clients_up || error "post-failover df: $?"
2487 facet_failover $facet
2493 change_active $facet
2494 wait_for_facet $facet
2495 mount_facet $facet -o abort_recovery
2496 clients_up || echo "first df failed: $?"
2497 clients_up || error "post-failover df: $?"
2501 echo There is no lmc. This is mountconf, baby.
2505 host_nids_address() {
2509 if [ -n "$kind" ]; then
2510 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2512 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2518 if [ "$1" = "'*'" ]; then echo \'*\'; else
2524 if [ "$1" = "'*'" ]; then echo \'*\'; else
2525 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2527 if [ -z "$ID" ]; then
2528 echo "Could not get a ptl id for $1..."
2537 h2name_or_ip "$1" "tcp"
2542 if [ "$1" = "'*'" ]; then echo \'*\'; else
2543 if type __h2elan >/dev/null 2>&1; then
2546 ID=`echo $1 | sed 's/[^0-9]*//g'`
2554 h2name_or_ip "$1" "o2ib"
2558 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2559 # expressions format. As a bonus we can then just pass in those variables
2560 # to pdsh. What this function does is take a HOSTLIST type string and
2561 # expand it into a space deliminated list for us.
2569 [ -z "$hostlist" ] && return
2571 # Translate the case of [..],..,[..] to [..] .. [..]
2572 list="${hostlist/],/] }"
2574 [[ "$front" == *,* ]] && {
2577 list=${list/${old}/${new}}
2580 for item in $list; do
2581 # Test if we have any []'s at all
2582 if [ "$item" != "${item/\[/}" ]; then {
2583 # Expand the [*] into list
2587 if [ "$name" != "$item" ]; then
2588 group=${item#$name[*}
2591 for range in ${group//,/ }; do
2595 # Number of leading zeros
2598 end=$(echo $end | sed 's/0*//')
2599 [[ -z "$end" ]] && end=0
2600 [[ $padlen2 -gt $padlen ]] && {
2601 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2604 begin=$(echo $begin | sed 's/0*//')
2605 [ -z $begin ] && begin=0
2607 for num in $(seq -f "%0${padlen}g" $begin $end); do
2608 value="${name#*,}${num}${back}"
2609 [ "$value" != "${value/\[/}" ] && {
2610 value=$(hostlist_expand "$value")
2612 myList="$myList $value"
2617 myList="$myList $item"
2620 myList=${myList//,/ }
2621 myList=${myList:1} # Remove first character which is a space
2623 # Filter any duplicates without sorting
2625 myList="${list%% *}"
2627 while [[ "$list" != ${myList##* } ]]; do
2628 list=${list//${list%% *} /}
2629 myList="$myList ${list%% *}"
2631 myList="${myList%* }";
2633 # We can select an object at a offset in the list
2636 for item in $myList; do
2638 [ $cnt -eq $offset ] && {
2642 [ $(get_node_count $myList) -ne 1 ] && myList=""
2651 [ "$facet" == client ] && echo -n $HOSTNAME && return
2652 varname=${facet}_HOST
2653 if [ -z "${!varname}" ]; then
2654 if [ "${facet:0:3}" == "ost" ]; then
2655 local fh=${facet%failover}_HOST
2656 eval export ${facet}_HOST=${!fh}
2657 if [ -z "${!varname}" ]; then
2658 eval export ${facet}_HOST=${ost_HOST}
2660 elif [ "${facet:0:3}" == "mdt" -o \
2661 "${facet:0:3}" == "mds" -o \
2662 "${facet:0:3}" == "mgs" ]; then
2663 eval export ${facet}_HOST=${mds_HOST}
2669 facet_failover_host() {
2673 var=${facet}failover_HOST
2674 if [ -n "${!var}" ]; then
2679 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2680 "${facet:0:3}" == "mgs" ]; then
2682 eval export ${facet}failover_host=${mds_HOST}
2687 if [[ $facet == ost* ]]; then
2688 eval export ${facet}failover_host=${ost_HOST}
2696 local activevar=${facet}active
2698 if [ -f $TMP/${facet}active ] ; then
2699 source $TMP/${facet}active
2702 active=${!activevar}
2703 if [ -z "$active" ] ; then
2710 facet_active_host() {
2712 local active=`facet_active $facet`
2713 if [ "$facet" == client ]; then
2716 echo `facet_host $active`
2720 # Get the passive failover partner host of facet.
2721 facet_passive_host() {
2723 [[ $facet = client ]] && return
2725 local host=${facet}_HOST
2726 local failover_host=${facet}failover_HOST
2727 local active_host=$(facet_active_host $facet)
2729 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2731 if [[ $active_host = ${!host} ]]; then
2732 echo -n ${!failover_host}
2742 facetlist=$(exclude_items_from_list $facetlist mgs)
2744 for facet in ${facetlist//,/ }; do
2745 local failover=${facet}failover
2746 local host=`facet_host $failover`
2747 [ -z "$host" ] && return
2749 local curactive=`facet_active $facet`
2750 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2751 eval export ${facet}active=$facet
2753 eval export ${facet}active=$failover
2755 # save the active host for this facet
2756 local activevar=${facet}active
2757 echo "$activevar=${!activevar}" > $TMP/$activevar
2758 [[ $facet = mds1 ]] && combined_mgs_mds && \
2759 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2760 local TO=`facet_active_host $facet`
2761 echo "Failover $facet to $TO"
2767 # do not stripe off hostname if verbose, bug 19215
2768 if [ x$1 = x--verbose ]; then
2776 if [ "$HOST" = "$HOSTNAME" ]; then
2778 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2779 echo "cannot run remote command on $HOST with $myPDSH"
2783 echo "CMD: $HOST $@" >&2
2784 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2787 if [ "$myPDSH" = "rsh" ]; then
2788 # we need this because rsh does not return exit code of an executed command
2789 local command_status="$TMP/cs"
2790 rsh $HOST ":> $command_status"
2791 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2792 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2793 echo command failed >$command_status"
2794 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2799 # print HOSTNAME for myPDSH="no_dsh"
2800 if [[ $myPDSH = no_dsh ]]; then
2801 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2803 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2806 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2808 return ${PIPESTATUS[0]}
2812 do_node --verbose "$@"
2815 single_local_node () {
2816 [ "$1" = "$HOSTNAME" ]
2819 # Outputs environment variable assignments that should be passed to remote nodes
2823 local facets=$(get_facets)
2826 for var in ${!MODOPTS_*}; do
2828 echo -n " ${var}=\"$value\""
2831 for facet in ${facets//,/ }; do
2833 if [ -n "${!var}" ]; then
2834 echo -n " $var=${!var}"
2838 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2839 if [ -n "${!var}" ]; then
2840 echo -n " $var=${!var}"
2844 if [ -n "$FSTYPE" ]; then
2845 echo -n " FSTYPE=$FSTYPE"
2851 # do not stripe off hostname if verbose, bug 19215
2852 if [ x$1 = x--verbose ]; then
2860 if single_local_node $rnodes; then
2862 do_nodev $rnodes "$@"
2864 do_node $rnodes "$@"
2869 # This is part from do_node
2872 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2873 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2875 export FANOUT=$(get_node_count "${rnodes//,/ }")
2877 echo "CMD: $rnodes $@" >&2
2878 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2881 # do not replace anything from pdsh output if -N is used
2882 # -N Disable hostname: prefix on lines of output.
2883 if $verbose || [[ $myPDSH = *-N* ]]; then
2884 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2886 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2888 return ${PIPESTATUS[0]}
2894 local HOST=`facet_active_host $facet`
2895 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2899 # Function: do_facet_random_file $FACET $FILE $SIZE
2900 # Creates FILE with random content on the given FACET of given SIZE
2902 do_facet_random_file() {
2906 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2907 do_facet $facet "$cmd 2>/dev/null"
2910 do_facet_create_file() {
2914 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2915 do_facet $facet "$cmd 2>/dev/null"
2919 do_nodes --verbose "$@"
2925 # make sure its not already running
2927 rm -f $TMP/${facet}active
2928 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2929 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2931 if [[ $(facet_fstype $facet) == zfs ]]; then
2933 # After formatting a ZFS target, "cachefile=none" property will
2934 # be set on the ZFS storage pool so that the pool is not
2935 # automatically imported on system startup. And then the pool
2936 # will be exported so as to leave the importing and exporting
2937 # operations handled by mount_facet() and stop() separately.
2939 refresh_partition_table $facet $(facet_vdevice $facet)
2940 disable_zpool_cache $facet
2945 # Device formatted as ost
2948 local DEVNAME=OSTDEV$num
2950 local fstype=$(facet_fstype ost$num)
2954 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2955 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2957 #try $OSTZFSDEVn - independent of vdev
2958 DEVNAME=OSTZFSDEV$num
2959 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2961 error "unknown fstype!";;
2967 # Physical device location of data
2973 local fstype=$(facet_fstype ost$num)
2977 # vdevs are not supported by ldiskfs
2980 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2981 # Device formated by zfs
2983 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2985 error "unknown fstype!";;
2991 # Logical device formated for lustre
2994 local DEVNAME=MDSDEV$num
2996 local fstype=$(facet_fstype mds$num)
3000 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3001 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3003 # try $MDSZFSDEVn - independent of vdev
3004 DEVNAME=MDSZFSDEV$num
3005 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3007 error "unknown fstype!";;
3013 # Physical location of data
3017 local fstype=$(facet_fstype mds$num)
3021 # vdevs are not supported by ldiskfs
3024 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3025 # Device formated by ZFS
3026 local DEVNAME=MDSDEV$num
3027 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3029 error "unknown fstype!";;
3037 local fstype=$(facet_fstype mgs)
3041 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3042 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3043 DEVPTR=$(mdsdevname 1)
3048 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3049 ( [ -z "$MGSZFSDEV" ] &&
3050 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3051 DEVPTR=$(mdsdevname 1)
3053 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3056 error "unknown fstype!";;
3065 local fstype=$(facet_fstype mgs)
3069 # vdevs are not supported by ldiskfs
3072 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3073 ( [ -z "$MGSDEV" ] &&
3074 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3075 VDEVPTR=$(mdsvdevname 1)
3076 elif [ -n "$MGSDEV" ]; then
3080 error "unknown fstype!";;
3088 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3090 local var=${facet}_MOUNT
3091 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3098 local dev=$(facet_device $facet)
3099 local mnt=$(facet_mntpt $facet)
3102 if ! do_facet $facet test -b $dev; then
3105 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3110 local dev=$(facet_device $facet)
3111 local mnt=$(facet_mntpt $facet)
3113 do_facet $facet umount -d $mnt
3117 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3122 local ds=$(facet_device $facet)
3123 local mnt=$(facet_mntpt $facet)
3128 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3129 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3130 do_facet $facet $ZFS set canmount=noauto $ds
3132 # The "legacy" mount method is used here because "zfs unmount $mnt"
3133 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3134 # targets are not available at the time, the stat(2) on $MOUNT will
3137 do_facet $facet $ZFS set mountpoint=legacy $ds
3138 do_facet $facet mount -t zfs $ds $mnt
3139 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3140 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3145 local ds=$(facet_device $facet)
3146 local mnt=$(facet_mntpt $facet)
3147 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3148 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3149 local mntpt=${!var_mntpt}
3150 local canmnt=${!var_canmnt}
3154 do_facet $facet umount $mnt
3155 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3156 do_facet $facet $ZFS set canmount=$canmnt $ds
3162 local fstype=$(facet_fstype $facet)
3164 mount_$fstype $facet
3169 local fstype=$(facet_fstype $facet)
3171 unmount_$fstype $facet
3178 # make sure we are using the primary server, so test-framework will
3179 # be able to clean up properly.
3180 activemds=`facet_active mds1`
3181 if [ $activemds != "mds1" ]; then
3185 local clients=$CLIENTS
3186 [ -z $clients ] && clients=$(hostname)
3188 zconf_umount_clients $clients $MOUNT "$*" || true
3189 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3191 [ "$CLIENTONLY" ] && return
3192 # The add fn does rm ${facet}active file, this would be enough
3193 # if we use do_facet <facet> only after the facet added, but
3194 # currently we use do_facet mds in local.sh
3195 for num in `seq $MDSCOUNT`; do
3197 rm -f ${TMP}/mds${num}active
3199 combined_mgs_mds && rm -f $TMP/mgsactive
3201 for num in `seq $OSTCOUNT`; do
3203 rm -f $TMP/ost${num}active
3206 if ! combined_mgs_mds ; then
3213 cleanup_echo_devs () {
3214 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3216 for dev in $devs; do
3217 $LCTL --device $dev cleanup
3218 $LCTL --device $dev detach
3223 nfs_client_mode && return
3232 combined_mgs_mds () {
3233 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3234 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3238 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3242 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3248 local fsname=${3:-"$FSNAME"}
3249 local type=$(facet_type $facet)
3250 local index=$(($(facet_number $facet) - 1))
3251 local fstype=$(facet_fstype $facet)
3252 local host=$(facet_host $facet)
3257 if [ $type == MGS ] && combined_mgs_mds; then
3261 if [ $type == MGS ] || ( [ $type == MDS ] &&
3262 [ "$dev" == $(mgsdevname) ] &&
3263 [ "$host" == "$(facet_host mgs)" ] ); then
3266 opts="--mgsnode=$MGSNID"
3269 if [ $type != MGS ]; then
3270 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3274 var=${facet}failover_HOST
3275 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3276 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3279 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3280 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3282 if [ $type == MDS ]; then
3283 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3284 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3285 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3286 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3287 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3289 if [ $fstype == ldiskfs ]; then
3290 # Check for wide striping
3291 if [ $OSTCOUNT -gt 160 ]; then
3292 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3293 fs_mkfs_opts+="-O large_xattr"
3296 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3297 if [ ! -z $EJOURNAL ]; then
3298 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3300 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3304 if [ $type == OST ]; then
3305 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3306 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3308 if [ $fstype == ldiskfs ]; then
3309 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3313 opts+=" --backfstype=$fstype"
3316 if [ -n "${!var}" ]; then
3317 opts+=" --device-size=${!var}"
3320 var=$(upper $fstype)_MKFS_OPTS
3321 fs_mkfs_opts+=${!var:+" ${!var}"}
3323 var=${type}_FS_MKFS_OPTS
3324 fs_mkfs_opts+=${!var:+" ${!var}"}
3326 if [ -n "${fs_mkfs_opts## }" ]; then
3327 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3331 opts+=${!var:+" ${!var}"}
3344 # We need ldiskfs here, may as well load them all
3346 [ "$CLIENTONLY" ] && return
3347 echo Formatting mgs, mds, osts
3348 if ! combined_mgs_mds ; then
3349 echo "Format mgs: $(mgsdevname)"
3350 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3351 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3355 for num in $(seq $MDSCOUNT); do
3356 echo "Format mds$num: $(mdsdevname $num)"
3357 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3358 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3359 ${quiet:+>/dev/null} || exit 10
3362 for num in $(seq $OSTCOUNT); do
3363 echo "Format ost$num: $(ostdevname $num)"
3364 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3365 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3366 ${quiet:+>/dev/null} || exit 10
3371 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3375 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3379 # 0: success, the old identity set already.
3380 # 1: success, the old identity does not set.
3385 local j=`expr $num - 1`
3386 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3388 if [ -z "$MDT" ]; then
3392 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3395 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3397 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3400 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3402 if [ $old = "NONE" ]; then
3411 zconf_umount `hostname` $1 || error "umount failed"
3412 zconf_mount `hostname` $1 || error "mount failed"
3420 rm -f $TMP/${facet}active
3421 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3426 local mdt_count=${1:-$MDSCOUNT}
3427 local ost_count=${2:-$OSTCOUNT}
3430 for num in $(seq $mdt_count); do
3431 DEVNAME=$(mdsdevname $num)
3432 writeconf_facet mds$num $DEVNAME || rc=$?
3435 for num in $(seq $ost_count); do
3436 DEVNAME=$(ostdevname $num)
3437 writeconf_facet ost$num $DEVNAME || rc=$?
3443 nfs_client_mode && return
3445 sanity_mount_check ||
3446 error "environments are insane!"
3450 if [ -z "$CLIENTONLY" ]; then
3451 echo Setup mgs, mdt, osts
3452 echo $WRITECONF | grep -q "writeconf" && \
3454 if ! combined_mgs_mds ; then
3455 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3458 for num in `seq $MDSCOUNT`; do
3459 DEVNAME=$(mdsdevname $num)
3460 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3462 # We started mds, now we should set failover variables properly.
3463 # Set mds${num}failover_HOST if it is not set (the default failnode).
3464 local varname=mds${num}failover_HOST
3465 if [ -z "${!varname}" ]; then
3466 eval mds${num}failover_HOST=$(facet_host mds$num)
3469 if [ $IDENTITY_UPCALL != "default" ]; then
3470 switch_identity $num $IDENTITY_UPCALL
3473 for num in `seq $OSTCOUNT`; do
3474 DEVNAME=$(ostdevname $num)
3475 start ost$num $DEVNAME $OST_MOUNT_OPTS
3477 # We started ost$num, now we should set ost${num}failover variable properly.
3478 # Set ost${num}failover_HOST if it is not set (the default failnode).
3479 varname=ost${num}failover_HOST
3480 if [ -z "${!varname}" ]; then
3481 eval ost${num}failover_HOST=$(facet_host ost${num})
3489 # wait a while to allow sptlrpc configuration be propogated to targets,
3490 # only needed when mounting new target devices.
3495 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3497 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3500 if [ "$MOUNT_2" ]; then
3501 mount_client $MOUNT2
3502 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3507 # by remounting mdt before ost, initial connect from mdt to ost might
3508 # timeout because ost is not ready yet. wait some time to its fully
3509 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3510 # by a context negotiation rpc with $TIMEOUT.
3511 # FIXME better by monitoring import status.
3514 sleep $((TIMEOUT + 5))
3520 mounted_lustre_filesystems() {
3521 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3524 init_facet_vars () {
3525 [ "$CLIENTONLY" ] && return 0
3532 eval export ${facet}_dev=${device}
3533 eval export ${facet}_opt=\"$@\"
3535 local dev=${facet}_dev
3537 # We need to loop for the label
3538 # in case its not initialized yet.
3539 for wait_time in {0,1,3,5,10}; do
3541 if [ $wait_time -gt 0 ]; then
3542 echo "${!dev} not yet initialized,"\
3543 "waiting ${wait_time} seconds."
3547 local label=$(devicelabel ${facet} ${!dev})
3549 # Check to make sure the label does
3550 # not include ffff at the end of the label.
3551 # This indicates it has not been initialized yet.
3553 if [[ $label =~ [f|F]{4}$ ]]; then
3554 # label is not initialized, unset the result
3555 # and either try again or fail
3562 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3564 eval export ${facet}_svc=${label}
3566 local varname=${facet}failover_HOST
3567 if [ -z "${!varname}" ]; then
3568 eval export $varname=$(facet_host $facet)
3571 varname=${facet}_HOST
3572 if [ -z "${!varname}" ]; then
3573 eval export $varname=$(facet_host $facet)
3576 # ${facet}failover_dev is set in cfg file
3577 varname=${facet}failover_dev
3578 if [ -n "${!varname}" ] ; then
3579 eval export ${facet}failover_dev=${!varname}
3581 eval export ${facet}failover_dev=$device
3584 # get mount point of already mounted device
3585 # is facet_dev is already mounted then use the real
3586 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3587 # i.e. ${facet}_MOUNT if specified by user or default
3588 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3589 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3590 if [ -z $mntpt ]; then
3591 mntpt=$(facet_mntpt $facet)
3593 eval export ${facet}_MOUNT=$mntpt
3596 init_facets_vars () {
3599 if ! remote_mds_nodsh; then
3600 for num in $(seq $MDSCOUNT); do
3601 DEVNAME=`mdsdevname $num`
3602 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3606 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3608 if ! remote_ost_nodsh; then
3609 for num in $(seq $OSTCOUNT); do
3610 DEVNAME=$(ostdevname $num)
3611 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3616 osc_ensure_active () {
3621 while [ $period -lt $timeout ]; do
3622 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3623 if [ $count -eq 0 ]; then
3627 echo "There are $count OST are inactive, wait $period seconds, and try again"
3629 period=$((period+3))
3632 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3635 set_conf_param_and_check() {
3639 local ORIG=$(do_facet $myfacet "$TEST")
3640 if [ $# -gt 3 ]; then
3646 echo "Setting $PARAM from $ORIG to $FINAL"
3647 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3648 error "conf_param $PARAM failed"
3650 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3651 error "check $PARAM failed!"
3654 init_param_vars () {
3656 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3658 log "Using TIMEOUT=$TIMEOUT"
3660 osc_ensure_active $SINGLEMDS $TIMEOUT
3661 osc_ensure_active client $TIMEOUT
3663 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3664 local current_jobid_var=$($LCTL get_param -n jobid_var)
3666 if [ $JOBID_VAR = "existing" ]; then
3667 echo "keeping jobstats as $current_jobid_var"
3668 elif [ $current_jobid_var != $JOBID_VAR ]; then
3669 echo "seting jobstats to $JOBID_VAR"
3671 set_conf_param_and_check client \
3672 "$LCTL get_param -n jobid_var" \
3673 "$FSNAME.sys.jobid_var" $JOBID_VAR
3676 echo "jobstats not supported by server"
3679 if [ $QUOTA_AUTO -ne 0 ]; then
3680 if [ "$ENABLE_QUOTA" ]; then
3681 echo "enable quota as required"
3682 setup_quota $MOUNT || return 2
3684 echo "disable quota as required"
3685 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3691 nfs_client_mode () {
3692 if [ "$NFSCLIENT" ]; then
3693 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3694 local clients=$CLIENTS
3695 [ -z $clients ] && clients=$(hostname)
3697 # FIXME: remove hostname when 19215 fixed
3698 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3699 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3700 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3701 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3703 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3709 check_config_client () {
3712 local mounted=$(mount | grep " $mntpt ")
3713 if [ "$CLIENTONLY" ]; then
3715 # CLIENTONLY should not depend on *_HOST settings
3716 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3717 # in theory someone could create a new,
3718 # client-only config file that assumed lustre was already
3719 # configured and didn't set the MGSNID. If MGSNID is not set,
3720 # then we should use the mgs nid currently being used
3721 # as the default value. bug 18021
3722 [[ x$MGSNID = x ]] &&
3725 if [[ x$mgc != xMGC$MGSNID ]]; then
3726 if [ "$mgs_HOST" ]; then
3727 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3728 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3729 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3735 local myMGS_host=$mgs_HOST
3736 if [ "$NETTYPE" = "ptl" ]; then
3737 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3740 echo Checking config lustre mounted on $mntpt
3741 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3742 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3744 # if [ "$mgshost" != "$myMGS_host" ]; then
3745 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3746 # Please use correct config or set mds_HOST correctly!"
3751 check_config_clients () {
3752 local clients=${CLIENTS:-$HOSTNAME}
3755 nfs_client_mode && return
3757 do_rpc_nodes "$clients" check_config_client $mntpt
3759 sanity_mount_check || error "environments are insane!"
3763 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3764 local cltimeout=$(lctl get_param -n timeout)
3765 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3766 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3773 [ -z $mntpt ] && return 1
3774 local mounted=$(mounted_lustre_filesystems)
3776 echo $mounted' ' | grep -w -q $mntpt' '
3780 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3784 # empty lustre filesystem may have empty directories lost+found and .lustre
3786 # exclude .lustre & lost+found
3787 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3788 -print | wc -l) = 1 ] || return 1
3789 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3790 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3791 # exclude .lustre/fid (LU-2780)
3792 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3793 -print | wc -l) = 1 ] || return 1
3795 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3800 check_and_setup_lustre() {
3801 nfs_client_mode && return
3803 local MOUNTED=$(mounted_lustre_filesystems)
3807 # both MOUNT and MOUNT2 are not mounted
3808 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3809 [ "$REFORMAT" ] && formatall
3810 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3812 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3813 export I_MOUNTED=yes
3817 elif is_mounted $MOUNT2; then
3819 # MOUNT2 is mounted, while MOUNT_2 is not set
3820 if ! [ "$MOUNT_2" ]; then
3821 cleanup_mount $MOUNT2
3822 export I_UMOUNTED2=yes
3825 # MOUNT2 is mounted, MOUNT_2 is set
3827 # FIXME: what to do if check_config failed?
3829 # 1) remote client has mounted other Lustre fs ?
3830 # 2) it has insane env ?
3831 # let's try umount MOUNT2 on all clients and mount it again:
3832 if ! check_config_clients $MOUNT2; then
3833 cleanup_mount $MOUNT2
3834 restore_mount $MOUNT2
3835 export I_MOUNTED2=yes
3840 # MOUNT is mounted MOUNT2 is not mounted
3841 elif [ "$MOUNT_2" ]; then
3842 restore_mount $MOUNT2
3843 export I_MOUNTED2=yes
3847 # FIXME: what to do if check_config failed?
3849 # 1) remote client has mounted other Lustre fs?
3850 # 2) lustre is mounted on remote_clients atall ?
3851 check_config_clients $MOUNT
3855 set_default_debug_nodes $(comma_list $(nodes_list))
3858 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3860 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3861 facets="$(get_facets OST)"
3862 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3863 facets="$facets,$(get_facets MDS)"
3864 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3865 facets="$facets,mgs"
3866 local nodes="$(facets_hosts ${facets})"
3867 if [ -n "$nodes" ] ; then
3868 do_nodes $nodes "$LCTL set_param \
3869 osd-ldiskfs.track_declares_assert=1 || true"
3878 #Enable remote MDT create for testing
3879 for num in $(seq $MDSCOUNT); do
3881 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
3885 if [ "$ONLY" == "setup" ]; then
3891 local clients=${CLIENTS:-$HOSTNAME}
3894 zconf_mount_clients $clients $mntpt
3898 local clients=${CLIENTS:-$HOSTNAME}
3901 zconf_umount_clients $clients $mntpt
3904 cleanup_and_setup_lustre() {
3905 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3906 lctl set_param debug=0 || true
3908 if [ "$ONLY" == "cleanup" ]; then
3912 check_and_setup_lustre
3915 # Get all of the server target devices from a given server node and type.
3922 if [ "$type" == ost ]; then
3923 devs=$(get_osd_param $node "" mntdev)
3925 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
3927 for dev in $devs; do
3929 *loop*) do_node $node "losetup $dev" | \
3930 sed -e "s/.*(//" -e "s/).*//" ;;
3936 # Get all of the server target devices.
3941 # Master MDS parameters used by lfsck
3942 MDTNODE=$(facet_active_host $SINGLEMDS)
3943 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
3947 for node in $(mdts_nodes); do
3948 MDTDEVS[i]=$(get_mnt_devs $node mdt)
3954 for node in $(osts_nodes); do
3955 OSTDEVS[i]=$(get_mnt_devs $node ost)
3960 # Run e2fsck on MDT or OST device.
3965 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3966 local log=$TMP/e2fsck.log
3970 do_node $node $cmd 2>&1 | tee $log
3972 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
3974 if [ $MDSCOUNT -gt 1 ]; then
3975 skip "DNE mode isn't supported!"
3979 error "It's not DNE mode."
3984 [ $rc -le $FSCK_MAX_ERR ] ||
3985 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3991 # Run resize2fs on MDT or OST device.
4000 do_facet $facet "$RESIZE2FS $opts $device $size"
4003 # verify a directory is shared among nodes.
4004 check_shared_dir() {
4006 local list=${2:-$(comma_list $(nodes_list))}
4008 [ -z "$dir" ] && return 1
4009 do_rpc_nodes "$list" check_logdir $dir
4010 check_write_access $dir "$list" || return 1
4014 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4021 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4022 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4024 check_shared_dir $SHARED_DIRECTORY ||
4025 error "$SHARED_DIRECTORY isn't a shared directory"
4027 export MDSDB=$SHARED_DIRECTORY/mdsdb
4028 export OSTDB=$SHARED_DIRECTORY/ostdb
4030 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4031 # we only pass master MDS parameters.
4032 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4037 for node in $(osts_nodes); do
4038 for dev in ${OSTDEVS[i]}; do
4039 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4040 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4041 ostidx=$((ostidx + 1))
4047 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4048 run_lfsck_remote() {
4049 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4054 #Check if lustre is already mounted
4055 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4057 zconf_mount $client $MOUNT ||
4058 error "failed to mount Lustre on $client"
4062 do_node $client $cmd || rc=$?
4063 #Umount if necessary
4065 zconf_umount $client $MOUNT ||
4066 error "failed to unmount Lustre on $client"
4069 [ $rc -le $FSCK_MAX_ERR ] ||
4070 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4071 echo "lfsck finished with rc=$rc"
4077 local facets="client $SINGLEMDS"
4083 for facet in $facets; do
4084 node=$(facet_active_host $facet)
4085 if check_progs_installed $node $LFSCK_BIN; then
4090 ! $found && error "None of \"$facets\" supports lfsck"
4092 run_lfsck_remote $node || rc=$?
4094 rm -rvf $MDSDB* $OSTDB* || true
4098 check_and_cleanup_lustre() {
4099 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4105 if is_mounted $MOUNT; then
4106 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4107 error "remove sub-test dirs failed"
4108 [ "$ENABLE_QUOTA" ] && restore_quota || true
4111 if [ "$I_UMOUNTED2" = "yes" ]; then
4112 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4115 if [ "$I_MOUNTED2" = "yes" ]; then
4116 cleanup_mount $MOUNT2
4119 if [ "$I_MOUNTED" = "yes" ]; then
4120 cleanupall -f || error "cleanup failed"
4128 wait_for_function () {
4131 # suppress fn both stderr and stdout
4132 if [ "$1" = "--quiet" ]; then
4134 quiet=" > /dev/null 2>&1"
4146 eval $fn $quiet && return 0
4148 wait=$((wait + sleep))
4149 [ $wait -lt $max ] || return 1
4150 echo waiting $fn, $((max - wait)) secs left ...
4160 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4161 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4162 echo "Network not available!"
4166 echo `date +"%H:%M:%S (%s)"` network interface is UP
4174 # Convert a space-delimited list to a comma-delimited list. If the input is
4175 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4177 # echo is used to convert newlines to spaces, since it doesn't
4178 # introduce a trailing space as using "tr '\n' ' '" does
4179 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4185 echo $list | grep -qw $item
4188 # list, excluded are the comma separated lists
4189 exclude_items_from_list () {
4195 for item in ${excluded//,/ }; do
4196 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4198 echo $(comma_list $list)
4201 # list, expand are the comma separated lists
4203 local list=${1//,/ }
4204 local expand=${2//,/ }
4207 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4208 echo $(comma_list $expanded)
4211 testslist_filter () {
4212 local script=$LUSTRE/tests/${TESTSUITE}.sh
4214 [ -f $script ] || return 0
4216 local start_at=$START_AT
4217 local stop_at=$STOP_AT
4219 local var=${TESTSUITE//-/_}_START_AT
4220 [ x"${!var}" != x ] && start_at=${!var}
4221 var=${TESTSUITE//-/_}_STOP_AT
4222 [ x"${!var}" != x ] && stop_at=${!var}
4224 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4225 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4226 /^'${start_at}'$/ {flag = 0}
4227 {if (flag == 1) print $0}
4228 /^'${stop_at}'$/ { flag = 1 }'
4232 (cd `dirname $1`; echo $PWD/`basename $1`)
4236 local types=${1:-"OST MDS MGS"}
4240 for entry in $types; do
4241 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4242 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4245 MGS ) list="$list $name";;
4246 MDS|OST|AGT ) local count=${type}COUNT
4247 for ((i=1; i<=${!count}; i++)) do
4248 list="$list ${name}$i"
4250 * ) error "Invalid facet type"
4254 echo $(comma_list $list)
4257 ##################################
4258 # Adaptive Timeouts funcs
4261 # only check mds, we assume at_max is the same on all nodes
4262 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4263 if [ $at_max -eq 0 ]; then
4274 # suppose that all ost-s have the same $at value set
4275 [ $facet != "ost" ] || facet=ost1
4277 do_facet $facet "lctl get_param -n $at"
4295 if [ $facet == "ost" ]; then
4296 facet=$(get_facets OST)
4297 elif [ $facet == "mds" ]; then
4298 facet=$(get_facets MDS)
4300 hosts=$(expand_list $hosts $(facets_hosts $facet))
4303 do_nodes $hosts lctl set_param at_max=$at_max
4306 ##################################
4310 # OBD_FAIL_MDS_ALL_REQUEST_NET
4312 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4313 do_facet client "$1" || RC=$?
4314 do_facet $SINGLEMDS lctl set_param fail_loc=0
4319 # OBD_FAIL_MDS_ALL_REPLY_NET
4321 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4322 do_facet client "$@" || RC=$?
4323 do_facet $SINGLEMDS lctl set_param fail_loc=0
4327 drop_reint_reply() {
4328 # OBD_FAIL_MDS_REINT_NET_REP
4330 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4331 do_facet client "$@" || RC=$?
4332 do_facet $SINGLEMDS lctl set_param fail_loc=0
4336 drop_update_reply() {
4337 # OBD_FAIL_UPDATE_OBJ_NET_REP
4341 do_facet mds${index} lctl set_param fail_loc=0x1701
4342 do_facet client "$@" || RC=$?
4343 do_facet mds${index} lctl set_param fail_loc=0
4348 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4351 local timeout=${2:-0}
4352 # default is (obd_timeout / 4) if unspecified
4353 echo "timeout is $timeout/$2"
4354 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4355 do_facet client "$1" || RC=$?
4356 do_facet client "sync"
4357 do_facet ost1 lctl set_param fail_loc=0
4361 drop_ldlm_cancel() {
4362 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4364 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4365 do_nodes $list lctl set_param fail_loc=0x304
4367 do_facet client "$@" || RC=$?
4369 do_nodes $list lctl set_param fail_loc=0
4373 drop_bl_callback() {
4374 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4376 do_facet client lctl set_param fail_loc=0x80000305
4377 do_facet client "$@" || RC=$?
4378 do_facet client lctl set_param fail_loc=0
4383 #define OBD_FAIL_LDLM_REPLY 0x30c
4385 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4386 do_facet client "$@" || RC=$?
4387 do_facet $SINGLEMDS lctl set_param fail_loc=0
4395 echo "clearing fail_loc on $facet"
4396 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4399 set_nodes_failloc () {
4400 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4403 cancel_lru_locks() {
4404 $LCTL mark "cancel_lru_locks $1 start"
4405 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4406 $LCTL set_param -n $d=clear
4408 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4409 $LCTL mark "cancel_lru_locks $1 stop"
4414 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4415 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4416 echo "$DEFAULT_LRU_SIZE"
4421 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4424 lru_resize_disable()
4426 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4432 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4438 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4439 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4440 echo there is still data in page cache $FILE ?
4441 lctl get_param -n $FILE
4449 DEBUGSAVE="$(lctl get_param -n debug)"
4453 [ -n "$DEBUGSAVE" ] && \
4454 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4459 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4462 debug_size_restore() {
4463 [ -n "$DEBUG_SIZE_SAVED" ] && \
4464 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4468 start_full_debug_logging() {
4473 local DEBUG_SIZE=150
4475 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4476 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4479 stop_full_debug_logging() {
4484 # prints bash call stack
4487 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4488 local s=${BASH_SOURCE[$i]}
4489 local l=${BASH_LINENO[$i-1]}
4490 local f=${FUNCNAME[$i]}
4491 echo " = $s:$l:$f()"
4495 ##################################
4497 ##################################
4500 local TYPE=${TYPE:-"FAIL"}
4503 # do not dump logs if $1=false
4504 if [ "x$1" = "xfalse" ]; then
4510 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4514 # We need to dump the logs on all nodes
4516 gather_logs $(comma_list $(nodes_list))
4520 [ "$TESTSUITELOG" ] &&
4521 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4522 if [ -z "$*" ]; then
4523 echo "error() without useful message, please fix" > $LOGDIR/err
4525 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4526 echo "$@" > $LOGDIR/ignore
4528 echo "$@" > $LOGDIR/err
4535 local log=$TESTSUITELOG
4537 [ -f "$log" ] && grep -q FAIL $log && status=1
4550 # use only if we are ignoring failures for this test, bugno required.
4551 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4552 # e.g. error_ignore bz5494 "your message" or
4553 # error_ignore LU-5494 "your message"
4555 local TYPE="IGNORE ($1)"
4560 error_and_remount() {
4562 remount_client $MOUNT
4567 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4572 log " SKIP: $TESTSUITE $TESTNAME $@"
4574 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4575 skip_logged $TESTNAME "$@"
4578 echo "$@" > $LOGDIR/skip
4581 [[ -n "$TESTSUITELOG" ]] &&
4582 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4585 build_test_filter() {
4586 EXCEPT="$EXCEPT $(testslist_filter)"
4589 if [[ $O = [0-9]*-[0-9]* ]]; then
4590 for num in $(seq $(echo $O | tr '-' ' ')); do
4598 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4599 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4600 [ "$EXCEPT_SLOW" ] && \
4601 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4602 for E in $EXCEPT; do
4603 eval EXCEPT_${E}=true
4605 for E in $ALWAYS_EXCEPT; do
4606 eval EXCEPT_ALWAYS_${E}=true
4608 for E in $EXCEPT_SLOW; do
4609 eval EXCEPT_SLOW_${E}=true
4611 for G in $GRANT_CHECK_LIST; do
4612 eval GCHECK_ONLY_${G}=true
4617 if [[ $1 = [a-z]* ]]; then
4624 # print a newline if the last test was skipped
4625 export LAST_SKIPPED=
4626 export ALWAYS_SKIPPED=
4628 # Main entry into test-framework. This is called with the name and
4629 # description of a test. The name is used to find the function to run
4630 # the test using "test_$name".
4632 # This supports a variety of methods of specifying specific test to
4633 # run or not run. These need to be documented...
4638 export base=$(basetest $1)
4639 if [ -n "$ONLY" ]; then
4641 if [ ${!testname}x != x ]; then
4642 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4643 run_one_logged $1 "$2"
4647 if [ ${!testname}x != x ]; then
4648 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4649 run_one_logged $1 "$2"
4659 if [ ${!testname}x != x ]; then
4660 TESTNAME=test_$1 skip "skipping excluded test $1"
4663 testname=EXCEPT_$base
4664 if [ ${!testname}x != x ]; then
4665 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4668 testname=EXCEPT_ALWAYS_$1
4669 if [ ${!testname}x != x ]; then
4670 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4673 testname=EXCEPT_ALWAYS_$base
4674 if [ ${!testname}x != x ]; then
4675 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4678 testname=EXCEPT_SLOW_$1
4679 if [ ${!testname}x != x ]; then
4680 TESTNAME=test_$1 skip "skipping SLOW test $1"
4683 testname=EXCEPT_SLOW_$base
4684 if [ ${!testname}x != x ]; then
4685 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4691 run_one_logged $1 "$2"
4698 module_loaded lnet || load_modules
4710 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4715 strace -o $TMP/$1.strace -ttt $*
4717 log "FINISHED: $*: rc $RC"
4724 banner test complete, duration $duration sec
4725 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4726 echo duration $duration >>$TESTSUITELOG
4730 # Set TEST_STATUS here. It will be used for logging the result.
4733 if [[ -f $LOGDIR/err ]]; then
4735 elif [[ -f $LOGDIR/skip ]]; then
4738 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4742 local FFREE=$(do_node $SINGLEMDS \
4743 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4744 local FTOTAL=$(do_node $SINGLEMDS \
4745 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4747 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4751 echo -n "Resetting fail_loc on all nodes..."
4752 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4758 # Log a message (on all nodes) padded with "=" before and after.
4759 # Also appends a timestamp and prepends the testsuite name.
4762 EQUALS="===================================================================================================="
4764 msg="== ${TESTSUITE} $*"
4766 [[ $last != "=" && $last != " " ]] && msg="$msg "
4767 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4768 # always include at least == after the message
4769 log "$msg== $(date +"%H:%M:%S (%s)")"
4773 # Run a single test function and cleanup after it.
4775 # This function should be run in a subshell so the test func can
4776 # exit() without stopping the whole script.
4781 export tfile=f${testnum}.${TESTSUITE}
4782 export tdir=d${testnum}.${TESTSUITE}
4783 export TESTNAME=test_$testnum
4784 local SAVE_UMASK=`umask`
4787 banner "test $testnum: $message"
4788 test_${testnum} || error "test_$testnum failed with $?"
4791 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4792 check_catastrophe || error "LBUG/LASSERT detected"
4793 if [ "$PARALLEL" != "yes" ]; then
4794 ps auxww | grep -v grep | grep -q multiop &&
4795 error "multiop still running"
4805 # Wrapper around run_one to ensure:
4806 # - test runs in subshell
4807 # - output of test is saved to separate log file for error reporting
4808 # - test result is saved to data file
4811 local BEFORE=$(date +%s)
4813 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4814 local test_log=$LOGDIR/$name
4816 rm -rf $LOGDIR/ignore
4818 local SAVE_UMASK=$(umask)
4822 log_sub_test_begin test_${1}
4823 (run_one $1 "$2") 2>&1 | tee -i $test_log
4824 local RC=${PIPESTATUS[0]}
4826 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4827 echo "test_$1 returned $RC" | tee $LOGDIR/err
4829 duration=$(($(date +%s) - $BEFORE))
4830 pass "$1" "(${duration}s)"
4832 if [[ -f $LOGDIR/err ]]; then
4833 TEST_ERROR=$(cat $LOGDIR/err)
4834 elif [[ -f $LOGDIR/ignore ]]; then
4835 TEST_ERROR=$(cat $LOGDIR/ignore)
4836 elif [[ -f $LOGDIR/skip ]]; then
4837 TEST_ERROR=$(cat $LOGDIR/skip)
4839 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4841 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4845 if [ -f $LOGDIR/err ]; then
4846 $FAIL_ON_ERROR && exit $RC
4855 # Print information of skipped tests to result.yml
4858 log_sub_test_begin $1
4860 log_sub_test_end "SKIP" "0" "0" "$@"
4864 (cd $(dirname $1); echo $PWD/$(basename $1))
4869 export base=$(basetest $1)
4870 [ "$CHECK_GRANT" == "no" ] && return 0
4872 testname=GCHECK_ONLY_${base}
4873 [ ${!testname}x == x ] && return 0
4875 echo -n "checking grant......"
4877 local clients=$CLIENTS
4878 [ -z "$clients" ] && clients=$(hostname)
4880 # sync all the data and make sure no pending data on server
4881 do_nodes $clients sync
4884 client_grant=$(do_nodes $clients \
4885 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
4886 awk '{ total += $1 } END { printf("%0.0f", total) }')
4889 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
4890 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4891 awk '{ total += $1 } END { printf("%0.0f", total) }')
4893 # check whether client grant == server grant
4894 if [[ $client_grant -ne $server_grant ]]; then
4895 echo "failed: client:${client_grant} server: ${server_grant}."
4896 do_nodes $(comma_list $(osts_nodes)) \
4897 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4898 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4901 echo "pass: client:${client_grant} server: ${server_grant}"
4905 ########################
4911 ost=`echo $1 | awk -F_ '{print $3}'`
4912 if [ -z $ost ]; then
4913 ost=`echo $1 | sed 's/-osc.*//'`
4918 ostuuid_from_index()
4920 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4923 ostname_from_index() {
4924 local uuid=$(ostuuid_from_index $1)
4928 index_from_ostuuid()
4930 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4933 mdtuuid_from_index()
4935 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4939 # Return unique identifier for given hostname
4942 echo $host_name | md5sum | cut -d' ' -f1
4946 # Returns list of ip addresses for each interface
4948 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4953 # Cache address list to avoid mutiple execution of local_addr_list
4954 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4956 for i in $LOCAL_ADDR_LIST ; do
4957 [[ "$i" == "$addr" ]] && return 0
4964 local is_local="IS_LOCAL_$(host_id $host_name)"
4965 if [ -z "${!is_local-}" ] ; then
4967 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4968 is_local_addr "$host_ip" && eval $is_local=1
4970 [[ "${!is_local}" == "1" ]]
4975 local_node $node && return 1
4982 for node in $(mdts_nodes); do
4983 remote_node $node && return 0
4990 [ "$CLIENTONLY" ] && return 0 || true
4991 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4996 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4997 MSKIPPED=1 && return 1
5004 for node in $(osts_nodes) ; do
5005 remote_node $node && return 0
5012 [ "$CLIENTONLY" ] && return 0 || true
5013 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5018 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5019 OSKIPPED=1 && return 1
5026 MGS=$(facet_host mgs)
5027 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5032 remote_mds_nodsh || remote_ost_nodsh || \
5033 $(single_local_node $(comma_list $(nodes_list)))
5037 remote_ost && remote_mds
5040 # Get the active nodes for facets.
5048 for facet in ${facets//,/ }; do
5049 nodes="$nodes $(facet_active_host $facet)"
5052 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5056 # Get all of the active MDS nodes.
5058 echo -n $(facets_nodes $(get_facets MDS))
5061 # Get all of the active OSS nodes.
5063 echo -n $(facets_nodes $(get_facets OST))
5066 # Get all of the active AGT (HSM agent) nodes.
5068 echo -n $(facets_nodes $(get_facets AGT))
5071 # Get all of the client nodes and active server nodes.
5073 local nodes=$HOSTNAME
5077 # CLIENTS (if specified) contains the local client
5078 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5080 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5081 nodes="$nodes $(facets_nodes $(get_facets))"
5084 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5088 # Get all of the remote client nodes and remote active server nodes.
5089 remote_nodes_list () {
5090 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5093 # Get all of the MDS nodes, including active and passive nodes.
5101 for i in $(seq $MDSCOUNT); do
5103 failover_host=mds${i}failover_HOST
5104 nodes="$nodes ${!host} ${!failover_host}"
5107 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5111 # Get all of the OSS nodes, including active and passive nodes.
5119 for i in $(seq $OSTCOUNT); do
5121 failover_host=ost${i}failover_HOST
5122 nodes="$nodes ${!host} ${!failover_host}"
5125 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5129 # Get all of the server nodes, including active and passive nodes.
5130 all_server_nodes () {
5135 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5137 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5141 # Get all of the client and server nodes, including active and passive nodes.
5143 local nodes=$HOSTNAME
5147 # CLIENTS (if specified) contains the local client
5148 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5150 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5151 nodes="$nodes $(all_server_nodes)"
5154 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5158 init_clients_lists () {
5159 # Sanity check: exclude the local client from RCLIENTS
5160 local clients=$(hostlist_expand "$RCLIENTS")
5161 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5163 # Sanity check: exclude the dup entries
5164 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5166 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5168 # Sanity check: exclude the dup entries from CLIENTS
5169 # for those configs which has SINGLCLIENT set to local client
5170 clients=$(for i in $clients; do echo $i; done | sort -u)
5172 CLIENTS=$(comma_list $clients)
5173 local -a remoteclients=($RCLIENTS)
5174 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5175 varname=CLIENT$((i + 2))
5176 eval $varname=${remoteclients[i]}
5179 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5182 get_random_entry () {
5185 rnodes=${rnodes//,/ }
5187 local -a nodes=($rnodes)
5188 local num=${#nodes[@]}
5189 local i=$((RANDOM * num * 2 / 65536))
5195 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5200 lctl get_param version | grep -q patchless
5204 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5205 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5210 echo $nodes | wc -w || true
5214 local nodes=$(osts_nodes)
5215 local osscount=$(get_node_count "$nodes")
5216 [ ! "$OSTCOUNT" = "$osscount" ]
5220 local nodes=$(mdts_nodes)
5221 local mdtcount=$(get_node_count "$nodes")
5222 [ ! "$MDSCOUNT" = "$mdtcount" ]
5225 generate_machine_file() {
5226 local nodes=${1//,/ }
5227 local machinefile=$2
5229 for node in $nodes; do
5230 echo $node >>$machinefile || \
5231 { echo "can not generate machinefile $machinefile" && return 1; }
5236 local file=$1/stripe
5239 $LFS getstripe -v $file || error "getstripe $file failed"
5243 setstripe_nfsserver () {
5246 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5247 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5249 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5251 do_nodev $nfsserver lfs setstripe "$@"
5254 # Check and add a test group.
5260 local gid=$(getent group $group_name | cut -d: -f3)
5261 if [[ -n "$gid" ]]; then
5262 [[ "$gid" -eq "$group_id" ]] || {
5263 error_noexit "inconsistent group ID:" \
5264 "new: $group_id, old: $gid"
5268 groupadd -g $group_id $group_name
5275 # Check and add a test user.
5288 local uid=$(getent passwd $user_name | cut -d: -f3)
5289 if [[ -n "$uid" ]]; then
5290 if [[ "$uid" -eq "$user_id" ]]; then
5291 local dir=$(getent passwd $user_name | cut -d: -f6)
5292 if [[ "$dir" != "$home" ]]; then
5294 usermod -d $home $user_name
5298 error_noexit "inconsistent user ID:" \
5299 "new: $user_id, old: $uid"
5304 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5311 check_runas_id_ret() {
5313 local myRUNAS_UID=$1
5314 local myRUNAS_GID=$2
5317 if [ -z "$myRUNAS" ]; then
5318 error_exit "myRUNAS command must be specified for check_runas_id"
5321 $myRUNAS krb5_login.sh || \
5322 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5324 mkdir $DIR/d0_runas_test
5326 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5327 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5328 rm -rf $DIR/d0_runas_test
5333 local myRUNAS_UID=$1
5334 local myRUNAS_GID=$2
5337 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5338 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5339 Please set RUNAS_ID to some UID which exists on MDS and client or
5340 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5343 # obtain the UID/GID for MPI_USER
5347 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5348 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5350 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5351 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5354 # obtain and cache Kerberos ticket-granting ticket
5355 refresh_krb5_tgt() {
5356 local myRUNAS_UID=$1
5357 local myRUNAS_GID=$2
5360 if [ -z "$myRUNAS" ]; then
5361 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5364 CLIENTS=${CLIENTS:-$HOSTNAME}
5365 do_nodes $CLIENTS "set -x
5366 if ! $myRUNAS krb5_login.sh; then
5367 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5372 # Run multiop in the background, but wait for it to print
5373 # "PAUSING" to its stdout before returning from this function.
5374 multiop_bg_pause() {
5375 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5379 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5382 echo "$MULTIOP_PROG $FILE v$ARGS"
5383 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5385 echo "TMPPIPE=${TMPPIPE}"
5386 read -t 60 multiop_output < $TMPPIPE
5387 if [ $? -ne 0 ]; then
5392 if [ "$multiop_output" != "PAUSING" ]; then
5393 echo "Incorrect multiop output: $multiop_output"
5408 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5414 inodes_available () {
5415 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5416 sort -un | head -n1) || return 1
5420 mdsrate_inodes_available () {
5421 local min_inodes=$(inodes_available)
5422 echo $((min_inodes * 99 / 100))
5425 # reset llite stat counters
5426 clear_llite_stats(){
5427 lctl set_param -n llite.*.stats 0
5430 # sum llite stat items
5431 calc_llite_stats() {
5432 local res=$(lctl get_param -n llite.*.stats |
5433 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5437 # reset osc stat counters
5439 lctl set_param -n osc.*.osc_stats 0
5442 # sum osc stat items
5444 local res=$(lctl get_param -n osc.*.osc_stats |
5445 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5450 awk '{sum += $1} END { printf("%0.0f", sum) }'
5453 calc_osc_kbytes () {
5454 df $MOUNT > /dev/null
5455 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5458 # save_lustre_params(comma separated facet list, parameter_mask)
5459 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5460 save_lustre_params() {
5466 for facet in ${facets//,/ }; do
5467 node=$(facet_active_host $facet)
5468 [[ *\ $node\ * = " $nodes " ]] && continue
5469 nodes="$nodes $node"
5471 do_node $node "$LCTL get_param $2 |
5472 while read s; do echo $facet \\\$s; done"
5476 # restore lustre parameters from input stream, produces by save_lustre_params
5477 restore_lustre_params() {
5482 while IFS=" =" read facet name val; do
5483 do_facet $facet "$LCTL set_param -n $name $val"
5487 check_catastrophe() {
5488 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5489 local C=$CATASTROPHE
5490 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5492 [ -z "$rnodes" ] && return 0
5495 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5496 echo \\\$(< $C) || echo 0);
5497 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5500 if [ -n "$data" ]; then
5507 # CMD: determine mds index where directory inode presents
5510 local file=$dir/f0.get_mds_dir_tmpfile
5515 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5516 local -a oldused=($iused)
5518 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5520 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5521 local -a newused=($iused)
5524 for ((i=0; i<${#newused[@]}; i++)); do
5525 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5531 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5534 mdsrate_cleanup () {
5536 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5537 --nfiles $3 --dir $4 --filefmt $5 $6
5542 delayed_recovery_enabled () {
5543 local var=${SINGLEMDS}_svc
5544 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5547 ########################
5549 convert_facet2label() {
5552 if [ x$facet = xost ]; then
5556 local varsvc=${facet}_svc
5558 if [ -n ${!varsvc} ]; then
5561 error "No lablel for $facet!"
5565 get_clientosc_proc_path() {
5569 get_lustre_version () {
5570 local facet=${1:-"$SINGLEMDS"}
5571 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5574 lustre_version_code() {
5575 local facet=${1:-"$SINGLEMDS"}
5576 version_code $(get_lustre_version $1)
5579 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5580 # used by MDT would not be changed.
5581 # mdt lov: fsname-mdtlov
5582 # mdt osc: fsname-OSTXXXX-osc
5583 mds_on_old_device() {
5584 local mds=${1:-"$SINGLEMDS"}
5586 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5587 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5588 > /dev/null 2>&1" && return 0
5593 get_mdtosc_proc_path() {
5595 local ost_label=${2:-"*OST*"}
5597 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5598 local mdt_label=$(convert_facet2label $mds_facet)
5599 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5601 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5602 mds_on_old_device $mds_facet; then
5603 echo "${ost_label}-osc"
5605 echo "${ost_label}-osc-${mdt_index}"
5609 get_osc_import_name() {
5612 local label=$(convert_facet2label $ost)
5614 if [ "${facet:0:3}" = "mds" ]; then
5615 get_mdtosc_proc_path $facet $label
5619 get_clientosc_proc_path $label
5623 _wait_import_state () {
5626 local maxtime=${3:-$(max_recovery_time)}
5630 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5631 while [ "${CONN_STATE}" != "${expected}" ]; do
5632 if [ "${expected}" == "DISCONN" ]; then
5633 # for disconn we can check after proc entry is removed
5634 [ "x${CONN_STATE}" == "x" ] && return 0
5635 # with AT enabled, we can have connect request timeout near of
5636 # reconnect timeout and test can't see real disconnect
5637 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5639 [ $i -ge $maxtime ] && \
5640 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5643 # Add uniq for multi-mount case
5644 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5648 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5652 wait_import_state() {
5655 local maxtime=${3:-$(max_recovery_time)}
5658 for param in ${params//,/ }; do
5659 _wait_import_state $state $param $maxtime || return
5663 wait_import_state_mount() {
5664 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5668 wait_import_state $*
5671 # One client request could be timed out because server was not ready
5672 # when request was sent by client.
5673 # The request timeout calculation details :
5675 # /* We give the server rq_timeout secs to process the req, and
5676 # add the network latency for our local timeout. */
5677 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5678 # ptlrpc_at_get_net_latency(request) ;
5680 # ptlrpc_connect_import ()
5681 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5684 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5685 # ptlrpc_at_get_net_latency(request) ->
5686 # at_get (max (iat_net_latency=0, at_min)) = at_min
5689 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5690 # INITIAL_CONNECT_TIMEOUT + at_min
5692 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5693 # because we can not get this value in runtime,
5694 # the value depends on configure options, and it is not stored in /proc.
5696 # #define CONNECTION_SWITCH_MIN 5U
5697 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5699 request_timeout () {
5702 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5703 local init_connect_timeout=$TIMEOUT
5704 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5706 local at_min=$(at_get $facet at_min)
5708 echo $(( init_connect_timeout + at_min ))
5711 _wait_osc_import_state() {
5715 local ost=$(get_osc_import_name $facet $ost_facet)
5716 local param="osc.${ost}.ost_server_uuid"
5720 # 1. wait the deadline of client 1st request (it could be skipped)
5721 # 2. wait the deadline of client 2nd request
5722 local maxtime=$(( 2 * $(request_timeout $facet)))
5724 if [[ $facet == client* ]]; then
5725 # During setup time, the osc might not be setup, it need wait
5726 # until list_param can return valid value. And also if there
5727 # are mulitple osc entries we should list all of them before
5729 params=$($LCTL list_param $param 2>/dev/null || true)
5730 while [ -z "$params" ]; do
5731 if [ $i -ge $maxtime ]; then
5732 echo "can't get $param in $maxtime secs"
5737 params=$($LCTL list_param $param 2>/dev/null || true)
5740 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5741 wait_import_state $expected "$params" $maxtime; then
5742 error "import is not in ${expected} state"
5749 wait_osc_import_state() {
5755 if [[ $facet = mds ]]; then
5756 for num in $(seq $MDSCOUNT); do
5757 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5760 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5764 get_clientmdc_proc_path() {
5772 [ -z "$list" ] && return 0
5774 # Add paths to lustre tests for 32 and 64 bit systems.
5775 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5776 local TESTPATH="$RLUSTRE/tests:"
5777 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5778 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5781 wait_clients_import_state () {
5788 if [ "$FAILURE_MODE" = HARD ]; then
5789 facets=$(facets_on_host $(facet_active_host $facet))
5792 for facet in ${facets//,/ }; do
5793 local label=$(convert_facet2label $facet)
5796 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5797 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5798 *) error "unknown facet!" ;;
5800 local params=$(expand_list $params $proc_path)
5803 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5804 error "import is not in ${expected} state"
5814 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5815 $LCTL get_param obdfilter.*.kbytesavail))
5816 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5817 $LCTL get_param -n obdfilter.*.tot_granted))
5818 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5819 $LCTL get_param -n obdfilter.*.kbytestotal))
5820 for ((i=0; i<${#AVAILA[@]}; i++)); do
5821 local -a AVAIL1=(${AVAILA[$i]//=/ })
5822 local -a TOTAL=(${TOTALA[$i]//=/ })
5823 GRANT=$((${GRANTA[$i]}/1024))
5824 # allow 1% of total space in bavail because of delayed
5825 # allocation with ZFS which might release some free space after
5826 # txg commit. For small devices, we set a mininum of 8MB
5827 local LIMIT=$((${TOTAL} / 100 + 8000))
5828 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5829 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5830 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5831 echo " FULL" || echo
5837 do_facet mgs lctl pool_list $1
5841 local fsname=${1%%.*}
5842 local poolname=${1##$fsname.}
5844 do_facet mgs lctl pool_new $1
5846 # get param should return err unless pool is created
5847 [[ $RC -ne 0 ]] && return $RC
5849 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5850 2>/dev/null || echo foo" "" || RC=1
5851 if [[ $RC -eq 0 ]]; then
5854 error "pool_new failed $1"
5859 add_pool_to_list () {
5860 local fsname=${1%%.*}
5861 local poolname=${1##$fsname.}
5863 local listvar=${fsname}_CREATED_POOLS
5864 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5867 remove_pool_from_list () {
5868 local fsname=${1%%.*}
5869 local poolname=${1##$fsname.}
5871 local listvar=${fsname}_CREATED_POOLS
5872 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5875 destroy_pool_int() {
5877 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5878 awk '$1 !~ /^Pool:/ {print $1}')
5879 for ost in $OSTS; do
5880 do_facet mgs lctl pool_remove $1 $ost
5882 do_facet mgs lctl pool_destroy $1
5885 # <fsname>.<poolname> or <poolname>
5887 local fsname=${1%%.*}
5888 local poolname=${1##$fsname.}
5890 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5894 pool_list $fsname.$poolname || return $?
5896 destroy_pool_int $fsname.$poolname
5898 [[ $RC -ne 0 ]] && return $RC
5900 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5901 2>/dev/null || echo foo" "foo" || RC=1
5903 if [[ $RC -eq 0 ]]; then
5904 remove_pool_from_list $fsname.$poolname
5906 error "destroy pool failed $1"
5912 local fsname=${1:-$FSNAME}
5914 local listvar=${fsname}_CREATED_POOLS
5918 [ x${!listvar} = x ] && return 0
5920 echo destroy the created pools: ${!listvar}
5921 for poolname in ${!listvar//,/ }; do
5922 destroy_pool $fsname.$poolname
5927 local fsname=${1:-$FSNAME}
5929 destroy_pools $fsname
5935 local ts=$(date +%s)
5938 if [[ ! -f "$YAML_LOG" ]]; then
5939 # init_logging is not performed before gather_logs,
5940 # so the $LOGDIR needs to be checked here
5941 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5944 [ -f $LOGDIR/shared ] && docp=false
5946 # dump lustre logs, dmesg
5948 prefix="$TESTLOG_PREFIX.$TESTNAME"
5950 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5952 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5953 echo "Dumping logs only on local client."
5954 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5955 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5960 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5961 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5962 if [ ! -f $LOGDIR/shared ]; then
5963 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5976 for i in $(seq 0 $num_mntpts); do
5977 cmd="ls -laf ${mntpt_root}$i/$dir"
5983 for pid in $pids; do
5990 # target_start_and_reset_recovery_timer()
5991 # service_time = at_est2timeout(service_time);
5992 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5993 # INITIAL_CONNECT_TIMEOUT);
5994 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5995 #define CONNECTION_SWITCH_INC 1
5996 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5997 #define CONNECTION_SWITCH_MIN 5U
5999 max_recovery_time () {
6000 local init_connect_timeout=$(( TIMEOUT / 20 ))
6001 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6003 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
6008 get_clients_mount_count () {
6009 local clients=${CLIENTS:-`hostname`}
6011 # we need to take into account the clients mounts and
6012 # exclude mds/ost mounts if any;
6013 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6017 PROC_CLI="srpc_info"
6025 if [ $M -lt $N ]; then
6029 while [ $N -lt $M ]; do
6039 calc_connection_cnt() {
6042 # MDT->MDT = 2 * C(M, 2)
6046 comb_m2=$(combination $MDSCOUNT 2)
6048 local num_clients=$(get_clients_mount_count)
6050 local cnt_mdt2mdt=$((comb_m2 * 2))
6051 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6052 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6053 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6054 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6055 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6056 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6070 local cmd="$tgt.srpc.flavor"
6072 if [ $net == "any" ]; then
6077 if [ $dir != "any" ]; then
6082 log "Setting sptlrpc rule: $cmd"
6083 do_facet mgs "$LCTL conf_param $cmd"
6092 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6093 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6095 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6097 if [ "x$bulkspec" != "x" ]; then
6098 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6100 if [ "x$algs" != "x" ]; then
6101 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6103 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6104 if [ $bulk == "bulkn" ]; then
6105 bulk_count=`echo "$output" | grep "bulk flavor" \
6106 | grep "null/null" | wc -l`
6107 elif [ $bulk == "bulki" ]; then
6108 bulk_count=`echo "$output" | grep "bulk flavor" \
6109 | grep "/null" | grep -v "null/" | wc -l`
6111 bulk_count=`echo "$output" | grep "bulk flavor" \
6112 | grep -v "/null" | grep -v "null/" | wc -l`
6116 [ $bulk_count -lt $count ] && count=$bulk_count
6127 local clients=${CLIENTS:-`hostname`}
6129 for c in ${clients//,/ }; do
6130 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6131 tmpcnt=`count_flvr "$output" $flavor`
6132 cnt=$((cnt + tmpcnt))
6142 local clients=${CLIENTS:-`hostname`}
6144 for c in ${clients//,/ }; do
6145 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6146 tmpcnt=`count_flvr "$output" $flavor`
6147 cnt=$((cnt + tmpcnt))
6157 if [ $MDSCOUNT -le 1 ]; then
6162 for num in `seq $MDSCOUNT`; do
6163 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6164 tmpcnt=`count_flvr "$output" $flavor`
6165 cnt=$((cnt + tmpcnt))
6176 for num in `seq $MDSCOUNT`; do
6177 mdtosc=$(get_mdtosc_proc_path mds$num)
6178 mdtosc=${mdtosc/-MDT*/-MDT\*}
6179 output=$(do_facet mds$num lctl get_param -n \
6180 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6181 tmpcnt=`count_flvr "$output" $flavor`
6182 cnt=$((cnt + tmpcnt))
6191 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6192 count_flvr "$output" $flavor
6197 local dir=$1 # from to
6198 local flavor=$2 # flavor expected
6201 if [ $dir == "cli2mdt" ]; then
6202 res=`flvr_cnt_cli2mdt $flavor`
6203 elif [ $dir == "cli2ost" ]; then
6204 res=`flvr_cnt_cli2ost $flavor`
6205 elif [ $dir == "mdt2mdt" ]; then
6206 res=`flvr_cnt_mdt2mdt $flavor`
6207 elif [ $dir == "mdt2ost" ]; then
6208 res=`flvr_cnt_mdt2ost $flavor`
6209 elif [ $dir == "all2ost" ]; then
6210 res1=`flvr_cnt_mdt2ost $flavor`
6211 res2=`flvr_cnt_cli2ost $flavor`
6212 res=$((res1 + res2))
6213 elif [ $dir == "all2mdt" ]; then
6214 res1=`flvr_cnt_mdt2mdt $flavor`
6215 res2=`flvr_cnt_cli2mdt $flavor`
6216 res=$((res1 + res2))
6217 elif [ $dir == "all2all" ]; then
6218 res1=`flvr_cnt_mdt2ost $flavor`
6219 res2=`flvr_cnt_cli2ost $flavor`
6220 res3=`flvr_cnt_mdt2mdt $flavor`
6221 res4=`flvr_cnt_cli2mdt $flavor`
6222 res=$((res1 + res2 + res3 + res4))
6230 local dir=$1 # from to
6231 local flavor=$2 # flavor expected
6232 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6236 for ((i=0;i<20;i++)); do
6237 echo -n "checking $dir..."
6238 res=$(do_check_flavor $dir $flavor)
6239 echo "found $res/$expect $flavor connections"
6240 [ $res -ge $expect ] && return 0
6244 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6248 restore_to_default_flavor()
6250 local proc="mgs.MGS.live.$FSNAME"
6252 echo "restoring to default flavor..."
6254 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6256 # remove all existing rules if any
6257 if [ $nrule -ne 0 ]; then
6258 echo "$nrule existing rules"
6259 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6260 echo "remove rule: $rule"
6261 spec=`echo $rule | awk -F = '{print $1}'`
6262 do_facet mgs "$LCTL conf_param -d $spec"
6266 # verify no rules left
6267 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6268 [ $nrule -ne 0 ] && error "still $nrule rules left"
6270 # wait for default flavor to be applied
6271 # currently default flavor for all connections are 'null'
6272 wait_flavor all2all null
6273 echo "now at default flavor settings"
6278 local flavor=${1:-null}
6280 echo "setting all flavor to $flavor"
6282 # FIXME need parameter to this fn
6283 # and remove global vars
6284 local cnt_all2all=$(calc_connection_cnt all2all)
6286 local res=$(do_check_flavor all2all $flavor)
6287 if [ $res -eq $cnt_all2all ]; then
6288 echo "already have total $res $flavor connections"
6292 echo "found $res $flavor out of total $cnt_all2all connections"
6293 restore_to_default_flavor
6295 [[ $flavor = null ]] && return 0
6297 set_rule $FSNAME any any $flavor
6298 wait_flavor all2all $flavor
6304 # Checking for shared logdir
6305 if [ ! -d $dir ]; then
6306 # Not found. Create local logdir
6309 touch $dir/check_file.$(hostname -s)
6314 check_write_access() {
6316 local list=${2:-$(comma_list $(nodes_list))}
6320 for node in ${list//,/ }; do
6321 file=$dir/check_file.$(short_nodename $node)
6322 if [[ ! -f "$file" ]]; then
6323 # Logdir not accessible/writable from this node.
6326 rm -f $file || return 1
6332 if [[ -n $YAML_LOG ]]; then
6335 local SAVE_UMASK=`umask`
6338 export YAML_LOG=${LOGDIR}/results.yml
6342 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6343 if check_shared_dir $LOGDIR; then
6344 touch $LOGDIR/shared
6345 echo "Logging to shared log directory: $LOGDIR"
6347 echo "Logging to local directory: $LOGDIR"
6350 yml_nodes_file $LOGDIR >> $YAML_LOG
6351 yml_results_file >> $YAML_LOG
6358 yml_log_test $1 >> $YAML_LOG
6362 yml_log_test_status $@ >> $YAML_LOG
6365 log_sub_test_begin() {
6366 yml_log_sub_test_begin "$@" >> $YAML_LOG
6369 log_sub_test_end() {
6370 yml_log_sub_test_end "$@" >> $YAML_LOG
6376 local llverdev_opts=$2
6377 local devname=$(basename $1)
6378 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6379 # loop devices aren't in /proc/partitions
6380 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6382 size=$(($size / 1024 / 1024)) # Gb
6384 local partial_arg=""
6385 # Run in partial (fast) mode if the size
6386 # of a partition > 1 GB
6387 [ $size -gt 1 ] && partial_arg="-p"
6389 llverdev --force $partial_arg $llverdev_opts $dev
6395 local llverfs_opts=$2
6396 local use_partial_arg=$3
6397 local partial_arg=""
6398 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6400 # Run in partial (fast) mode if the size
6401 # of a partition > 1 GB
6402 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6404 llverfs $partial_arg $llverfs_opts $dir
6407 #Remove objects from OST
6408 remove_ost_objects() {
6414 local mntpt=$(facet_mntpt $facet)
6415 local opts=$OST_MOUNT_OPTS
6419 echo "removing objects from $ostdev on $facet: $objids"
6420 if ! test -b $ostdev; then
6421 opts=$(csa_add "$opts" -o loop)
6423 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6426 for i in $objids; do
6427 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6429 umount -f $mntpt || return $?
6433 #Remove files from MDT
6434 remove_mdt_files() {
6439 local mntpt=$(facet_mntpt $facet)
6440 local opts=$MDS_MOUNT_OPTS
6442 echo "removing files from $mdtdev on $facet: $files"
6443 if [ $(facet_fstype $facet) == ldiskfs ] &&
6444 ! do_facet $facet test -b $mdtdev; then
6445 opts=$(csa_add "$opts" -o loop)
6447 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6451 rm $mntpt/ROOT/$f || { rc=$?; break; }
6453 umount -f $mntpt || return $?
6457 duplicate_mdt_files() {
6462 local mntpt=$(facet_mntpt $facet)
6463 local opts=$MDS_MOUNT_OPTS
6465 echo "duplicating files on $mdtdev on $facet: $files"
6466 mkdir -p $mntpt || return $?
6467 if [ $(facet_fstype $facet) == ldiskfs ] &&
6468 ! do_facet $facet test -b $mdtdev; then
6469 opts=$(csa_add "$opts" -o loop)
6471 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6482 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6483 pushd $mntpt/ROOT > /dev/null || return $?
6486 touch $f.bad || return $?
6487 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6489 [ $rc -eq 0 ] || return $rc
6490 setfattr --restore $tmp || return $?
6496 local devs=${1//,/ }
6499 local rslt=$TMP/sgpdd_survey
6501 # sgpdd-survey cleanups ${rslt}.* files
6503 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6509 # returns the canonical name for an ldiskfs device
6514 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6515 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6516 echo dm-\\\${foo##*:};
6518 echo \\\$(basename \\\$dv);
6522 is_sanity_benchmark() {
6523 local benchmarks="dbench bonnie iozone fsx"
6525 for b in $benchmarks; do
6526 if [ "$b" == "$suite" ]; then
6534 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6538 # Get the available size (KB) of a given obd target.
6545 [[ $facet != client ]] || return 0
6547 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6552 # Get the page size (bytes) on a given facet node.
6558 size=$(do_facet $facet getconf PAGE_SIZE)
6559 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6564 # Get the block count of the filesystem.
6571 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6572 awk '/^Block count:/ {print $3}')
6576 # Get the block size of the filesystem.
6582 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6583 awk '/^Block size:/ {print $3}')
6587 # Check whether the "large_xattr" feature is enabled or not.
6588 large_xattr_enabled() {
6589 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6591 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6593 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6594 grep -E -q '(ea_inode|large_xattr)'"
6595 return ${PIPESTATUS[0]}
6598 # Get the maximum xattr size supported by the filesystem.
6602 if large_xattr_enabled; then
6603 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6606 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6607 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6609 # maximum xattr size = size of block - size of header -
6610 # size of 1 entry - 4 null bytes
6611 size=$((block_size - 32 - 32 - 4))
6617 # Dump the value of the named xattr from a file.
6622 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6625 # Generate a string with size of $size bytes.
6627 local size=${1:-1024} # in bytes
6629 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6632 reformat_external_journal() {
6635 if [ ! -z ${EJOURNAL} ]; then
6636 local rcmd="do_facet $facet"
6638 echo "reformat external journal on $facet:${EJOURNAL}"
6639 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6643 # MDT file-level backup/restore
6644 mds_backup_restore() {
6647 local devname=$(mdsdevname $(facet_number $facet))
6648 local mntpt=$(facet_mntpt brpt)
6649 local rcmd="do_facet $facet"
6650 local metaea=${TMP}/backup_restore.ea
6651 local metadata=${TMP}/backup_restore.tgz
6652 local opts=${MDS_MOUNT_OPTS}
6653 local svc=${facet}_svc
6655 if ! ${rcmd} test -b ${devname}; then
6656 opts=$(csa_add "$opts" -o loop)
6659 echo "file-level backup/restore on $facet:${devname}"
6661 # step 1: build mount point
6662 ${rcmd} mkdir -p $mntpt
6663 # step 2: cleanup old backup
6664 ${rcmd} rm -f $metaea $metadata
6666 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6667 if [ ! -z $igif ]; then
6668 # step 3.5: rm .lustre
6669 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6671 # step 4: backup metaea
6673 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6675 # step 5: backup metadata
6677 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6679 ${rcmd} umount -d $mntpt || return 4
6680 # step 7: reformat external journal if needed
6681 reformat_external_journal $facet || return 5
6682 # step 8: reformat dev
6683 echo "reformat new device"
6684 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6685 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6686 > /dev/null || exit 6
6688 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6689 # step 10: restore metadata
6691 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6692 # step 11: restore metaea
6694 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6695 # step 12: remove recovery logs
6696 echo "remove recovery logs"
6697 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6698 # step 13: umount dev
6699 ${rcmd} umount -d $mntpt || return 10
6700 # step 14: cleanup tmp backup
6701 ${rcmd} rm -f $metaea $metadata
6702 # step 15: reset device label - it's not virgin on
6703 ${rcmd} e2label $devname ${!svc}
6710 local devname=$(mdsdevname $(facet_number $facet))
6711 local mntpt=$(facet_mntpt brpt)
6712 local rcmd="do_facet $facet"
6713 local opts=${MDS_MOUNT_OPTS}
6715 if ! ${rcmd} test -b ${devname}; then
6716 opts=$(csa_add "$opts" -o loop)
6719 echo "removing OI files on $facet: idx=${idx}"
6721 # step 1: build mount point
6722 ${rcmd} mkdir -p $mntpt
6724 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6725 if [ -z $idx ]; then
6726 # step 3: remove all OI files
6727 ${rcmd} rm -fv $mntpt/oi.16*
6728 elif [ $idx -lt 2 ]; then
6729 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6733 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6734 for ((i=${idx}; i<64; i=$((i * idx)))); do
6735 ${rcmd} rm -fv $mntpt/oi.16.${i}
6739 ${rcmd} umount -d $mntpt || return 2
6740 # OI files will be recreated when mounted as lustre next time.
6743 # generate maloo upload-able log file name
6744 # \param logname specify unique part of file name
6745 generate_logname() {
6746 local logname=${1:-"default_logname"}
6748 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6751 # make directory on different MDTs
6759 local stripe_count=2
6769 *) error "Only creating single directory is supported";;
6772 child=$(basename $path)
6773 parent=$(dirname $path)
6775 if [ "$option" == "-p" -o "$option2" == "-p" ]; then
6776 if [ -d $parent/$child ]; then
6782 if [ "${option:0:2}" == "-c" ]; then
6783 stripe_count=$(echo $option | sed 's/^-c//')
6786 if [ "${option2:0:2}" == "-c" ]; then
6787 stripe_count=$(echo $option2 | sed 's/^-c//')
6790 if [ ! -d ${parent} ]; then
6791 if [ "$p_option" == "-p" ]; then
6798 if [ $MDSCOUNT -le 1 ]; then
6799 mkdir $p_option $parent/$child || rc=$?
6801 local mdt_idx=$($LFS getstripe -M $parent)
6802 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6804 mdt_idx=$((test_num % MDSCOUNT))
6805 echo "striped dir -i$mdt_idx -c$stripe_count $path"
6806 $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
6811 # find the smallest and not in use file descriptor
6814 local max_fd=$(ulimit -n)
6816 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6819 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
6823 check_mount_and_prep()
6825 is_mounted $MOUNT || setupall
6827 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
6828 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
6831 # calcule how many ost-objects to be created.
6832 precreated_ost_obj_count()
6836 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
6837 local ost_name="OST$(printf '%04x' $ost_idx)"
6838 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
6839 local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6840 osp.$proc_path.prealloc_last_id)
6841 local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6842 osp.$proc_path.prealloc_next_id)
6844 echo $((last_id - next_id + 1))