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 if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
545 cmp $MOUNT_LUSTRE /sbin/mount.lustre ||
546 umount /sbin/mount.lustre
548 if ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
549 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
550 mount --bind $MOUNT_LUSTRE /sbin/mount.lustre
558 # load modules on remote nodes optionally
559 # lustre-tests have to be installed on these nodes
560 if $LOAD_MODULES_REMOTE; then
561 local list=$(comma_list $(remote_nodes_list))
562 if [ -n "$list" ]; then
563 echo "loading modules on: '$list'"
564 do_rpc_nodes "$list" load_modules_local
570 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
571 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
572 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
573 echo "$LEAK_LUSTRE" 1>&2
574 echo "$LEAK_PORTALS" 1>&2
575 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
576 echo "Memory leaks detected"
577 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
583 wait_exit_ST client # bug 12845
585 $LUSTRE_RMMOD ldiskfs || return 2
587 if $LOAD_MODULES_REMOTE; then
588 local list=$(comma_list $(remote_nodes_list))
589 if [ -n "$list" ]; then
590 echo "unloading modules on: '$list'"
591 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
592 do_rpc_nodes "$list" check_mem_leak
596 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
597 umount /sbin/mount.lustre || true
598 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
599 rm -f /sbin/mount.lustre || true
602 check_mem_leak || return 254
604 echo "modules unloaded."
609 local facet=${1:-$SINGLEMDS}
610 local fstype=$(facet_fstype $facet)
613 ldiskfs) size=50;; # largest seen is 44, leave some headroom
614 zfs) size=400;; # largest seen is 384
620 check_gss_daemon_nodes() {
624 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
625 if [ \\\"\\\$num\\\" -ne 1 ]; then
626 echo \\\$num instance of $dname;
631 check_gss_daemon_facet() {
635 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
636 if [ $num -ne 1 ]; then
637 echo "$num instance of $dname on $facet"
646 echo Stopping $@ on $list
647 do_nodes $list "killall -2 $@ 2>/dev/null || true"
650 # start gss daemons on all nodes, or
651 # "daemon" on "list" if set
652 start_gss_daemons() {
656 if [ "$list" ] && [ "$daemon" ] ; then
657 echo "Starting gss daemon on nodes: $list"
658 do_nodes $list "$daemon" || return 8
662 local list=$(comma_list $(mdts_nodes))
663 echo "Starting gss daemon on mds: $list"
664 do_nodes $list "$LSVCGSSD -v" || return 1
666 do_nodes $list "$LGSSD -v" || return 2
669 list=$(comma_list $(osts_nodes))
670 echo "Starting gss daemon on ost: $list"
671 do_nodes $list "$LSVCGSSD -v" || return 3
672 # starting on clients
674 local clients=${CLIENTS:-`hostname`}
676 echo "Starting $LGSSD on clients $clients "
677 do_nodes $clients "$LGSSD -v" || return 4
680 # wait daemons entering "stable" status
684 # check daemons are running
686 list=$(comma_list $(mdts_nodes) $(osts_nodes))
687 check_gss_daemon_nodes $list lsvcgssd || return 5
689 list=$(comma_list $(mdts_nodes))
690 check_gss_daemon_nodes $list lgssd || return 6
693 check_gss_daemon_nodes $clients lgssd || return 7
698 local list=$(comma_list $(mdts_nodes))
700 send_sigint $list lsvcgssd lgssd
702 list=$(comma_list $(osts_nodes))
703 send_sigint $list lsvcgssd
705 list=${CLIENTS:-`hostname`}
706 send_sigint $list lgssd
711 if ! module_loaded ptlrpc_gss; then
712 load_module ptlrpc/gss/ptlrpc_gss
713 module_loaded ptlrpc_gss ||
714 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
717 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
720 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
721 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
729 # maybe cleanup credential cache?
735 local var=${facet}_svc
743 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
744 tr '[:lower:]' '[:upper:]'
750 if [ $facet == mgs ]; then
754 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
762 if [ -n "${!var}" ]; then
767 var=$(facet_type $facet)FSTYPE
768 if [ -n "${!var}" ]; then
773 if [ -n "$FSTYPE" ]; then
778 if [[ $facet == mgs ]] && combined_mgs_mds; then
790 local facets=$(get_facets)
793 for facet in ${facets//,/ }; do
794 if [ $node == $(facet_host $facet) ] ||
795 [ $node == "$(facet_failover_host $facet)" ]; then
796 fstype=$(facet_fstype $facet)
797 if [[ $fstypes != *$fstype* ]]; then
798 fstypes+="${fstypes:+,}$fstype"
809 local fstype=$(facet_fstype $facet)
813 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
815 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
816 ${dev} 2>/dev/null");;
818 error "unknown fstype!";;
826 local device=$(mdsdevname $num)
827 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
833 local device=$(ostdevname $num)
834 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
839 # Get the device of a facet.
846 mgs) device=$(mgsdevname) ;;
847 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
848 ost*) device=$(ostdevname $(facet_number $facet)) ;;
849 fs2mds) device=$(mdsdevname 1_2) ;;
850 fs2ost) device=$(ostdevname 1_2) ;;
851 fs3ost) device=$(ostdevname 2_2) ;;
859 # Get the virtual device of a facet.
866 mgs) device=$(mgsvdevname) ;;
867 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
868 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
869 fs2mds) device=$(mdsvdevname 1_2) ;;
870 fs2ost) device=$(ostvdevname 1_2) ;;
871 fs3ost) device=$(ostvdevname 2_2) ;;
879 # Re-read the partition table on failover partner host.
880 # After a ZFS storage pool is created on a shared device, the partition table
881 # on the device may change. However, the operating system on the failover
882 # host may not notice the change automatically. Without the up-to-date partition
883 # block devices, 'zpool import ..' cannot find the labels, whose positions are
884 # relative to partition rather than disk beginnings.
886 # This function performs partprobe on the failover host to make it re-read the
889 refresh_partition_table() {
894 host=$(facet_passive_host $facet)
895 if [[ -n "$host" ]]; then
896 do_node $host "$PARTPROBE $device"
901 # Get ZFS storage pool name.
908 device=$(facet_device $facet)
909 # poolname is string before "/"
910 poolname="${device%%/*}"
916 # Create ZFS storage pool.
923 local opts=${@:-"-o cachefile=none"}
925 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
926 $ZPOOL create -f $opts $poolname $vdev"
930 # Create ZFS file system.
936 local opts=${@:-"-o mountpoint=legacy"}
938 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
939 $ZFS create $opts $dataset"
943 # Export ZFS storage pool.
944 # Before exporting the pool, all datasets within the pool should be unmounted.
952 poolname=$(zpool_name $facet)
954 if [[ -n "$poolname" ]]; then
955 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
956 grep -q ^$poolname/ /proc/mounts ||
957 $ZPOOL export $opts $poolname"
962 # Destroy ZFS storage pool.
963 # Destroy the given pool and free up any devices for other use. This command
964 # tries to unmount any active datasets before destroying the pool.
965 # -f Force any active datasets contained within the pool to be unmounted.
969 local poolname=${2:-$(zpool_name $facet)}
971 if [[ -n "$poolname" ]]; then
972 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
973 $ZPOOL destroy -f $poolname"
978 # Import ZFS storage pool.
979 # Force importing, even if the pool appears to be potentially active.
984 local opts=${@:-"-o cachefile=none"}
987 poolname=$(zpool_name $facet)
989 if [[ -n "$poolname" ]]; then
990 opts+=" -d $(dirname $(facet_vdevice $facet))"
991 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
992 $ZPOOL import -f $opts $poolname"
997 # Set the "cachefile=none" property on ZFS storage pool so that the pool
998 # is not automatically imported on system startup.
1000 # In a failover environment, this will provide resource level fencing which
1001 # will ensure that the same ZFS storage pool will not be imported concurrently
1002 # on different nodes.
1004 disable_zpool_cache() {
1008 poolname=$(zpool_name $facet)
1010 if [[ -n "$poolname" ]]; then
1011 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1016 # This and set_osd_param() shall be used to access OSD parameters
1017 # once existed under "obdfilter":
1022 # writethrough_cache_enable
1026 local device=${2:-$FSNAME-OST*}
1029 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1030 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1035 local device=${2:-$FSNAME-OST*}
1039 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1040 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1044 local dz=${1:-$DEBUG_SIZE}
1046 if [ -f /sys/devices/system/cpu/possible ]; then
1047 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1049 local cpus=$(getconf _NPROCESSORS_CONF)
1052 # bug 19944, adjust size to be -gt num_possible_cpus()
1053 # promise 2MB for every cpu at least
1054 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1057 lctl set_param debug_mb=$dz
1060 set_default_debug () {
1061 local debug=${1:-"$PTLDEBUG"}
1062 local subsys=${2:-"$SUBSYSTEM"}
1063 local debug_size=${3:-$DEBUG_SIZE}
1065 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1066 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1068 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1071 set_default_debug_nodes () {
1074 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1075 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1079 do_rpc_nodes "$nodes" set_default_debug \
1080 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1083 set_default_debug_facet () {
1085 local node=$(facet_active_host $facet)
1086 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1088 set_default_debug_nodes $node
1093 local facets=${1:-$(get_facets)}
1096 for facet in ${facets//,/ }; do
1099 [ $RC -eq 0 ] && continue
1101 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1102 skip "Restart of $facet failed!." && touch $LU482_FAILED
1104 error "Restart of $facet failed!"
1111 # Add argument "arg" (e.g., "loop") to the comma-separated list
1112 # of arguments for option "opt" (e.g., "-o") on command
1113 # line "opts" (e.g., "-o flock").
1119 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1121 if echo "$opts" | grep -q $opt_pattern; then
1122 opts=$(echo "$opts" | sed -e \
1123 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1125 opts+="${opts:+ }$opt $arg"
1133 local dev=$(facet_active $facet)_dev
1134 local opt=${facet}_opt
1135 local mntpt=$(facet_mntpt $facet)
1136 local opts="${!opt} $@"
1138 if [ $(facet_fstype $facet) == ldiskfs ] &&
1139 ! do_facet $facet test -b ${!dev}; then
1140 opts=$(csa_add "$opts" -o loop)
1143 if [[ $(facet_fstype $facet) == zfs ]]; then
1144 # import ZFS storage pool
1145 import_zpool $facet || return ${PIPESTATUS[0]}
1148 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1149 # for testing LU-482 error handling in mount_facets() and test_0a()
1150 if [ -f $TMP/test-lu482-trigger ]; then
1153 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1157 if [ $RC -ne 0 ]; then
1158 echo "Start of ${!dev} on ${facet} failed ${RC}"
1160 set_default_debug_facet $facet
1162 label=$(devicelabel ${facet} ${!dev})
1163 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1164 eval export ${facet}_svc=${label}
1165 echo Started ${label}
1170 # start facet device options
1176 eval export ${facet}_dev=${device}
1177 eval export ${facet}_opt=\"$@\"
1179 local varname=${facet}failover_dev
1180 if [ -n "${!varname}" ] ; then
1181 eval export ${facet}failover_dev=${!varname}
1183 eval export ${facet}failover_dev=$device
1186 local mntpt=$(facet_mntpt $facet)
1187 do_facet ${facet} mkdir -p $mntpt
1188 eval export ${facet}_MOUNT=$mntpt
1189 mount_facet ${facet}
1198 local HOST=`facet_active_host $facet`
1199 [ -z $HOST ] && echo stop: no host for $facet && return 0
1201 local mntpt=$(facet_mntpt $facet)
1202 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1203 if [ ${running} -ne 0 ]; then
1204 echo "Stopping $mntpt (opts:$@) on $HOST"
1205 do_facet ${facet} umount -d $@ $mntpt
1208 # umount should block, but we should wait for unrelated obd's
1209 # like the MGS or MGC to also stop.
1210 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1212 if [[ $(facet_fstype $facet) == zfs ]]; then
1213 # export ZFS storage pool
1218 # save quota version (both administrative and operational quotas)
1219 # add an additional parameter if mountpoint is ever different from $MOUNT
1221 # XXX This function is kept for interoperability with old server (< 2.3.50),
1222 # it should be removed whenever we drop the interoperability for such
1224 quota_save_version() {
1225 local fsname=${2:-$FSNAME}
1227 local ver=$(tr -c -d "123" <<< $spec)
1228 local type=$(tr -c -d "ug" <<< $spec)
1230 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1232 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1234 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1236 local osts=$(get_facets OST)
1237 for ost in ${osts//,/ }; do
1239 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1243 # client could mount several lustre
1245 # XXX This function is kept for interoperability with old server (< 2.3.50),
1246 # it should be removed whenever we drop the interoperability for such
1249 local fsname=${1:-$FSNAME}
1251 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1253 do_nodes $(comma_list $(osts_nodes)) \
1254 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1258 # XXX This function is kept for interoperability with old server (< 2.3.50),
1259 # it should be removed whenever we drop the interoperability for such
1261 restore_quota_old() {
1262 local mntpt=${1:-$MOUNT}
1263 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1264 if [ ! "$old_QUOTA_TYPE" ] ||
1265 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1268 quota_save_version $old_QUOTA_TYPE
1271 # XXX This function is kept for interoperability with old server (< 2.3.50),
1272 # it should be removed whenever we drop the interoperability for such
1277 # no quota enforcement for now and accounting works out of the box
1280 # We need save the original quota_type params, and restore them after testing
1282 # Suppose that quota type the same on mds and ost
1283 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1284 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1285 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1286 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1287 export old_QUOTA_TYPE=$quota_type
1288 quota_save_version $QUOTA_TYPE
1290 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1291 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1294 local quota_usrs=$QUOTA_USERS
1296 # get_filesystem_size
1297 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1298 local blk_soft=$((disksz + 1024))
1299 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1301 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1302 local i_soft=$Inodes
1303 local i_hard=$((i_soft + i_soft / 20))
1305 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1306 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1309 for usr in $quota_usrs; do
1310 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1312 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1314 eval $cmd || error "$cmd FAILED!"
1316 # display the quota status
1317 echo "Quota settings for $usr : "
1318 $LFS quota -v -u $usr $mntpt || true
1322 # get mdt quota type
1324 local varsvc=${SINGLEMDS}_svc
1325 do_facet $SINGLEMDS $LCTL get_param -n \
1326 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1329 # get ost quota type
1331 # All OSTs should have same quota type
1332 local varsvc=ost1_svc
1333 do_facet ost1 $LCTL get_param -n \
1334 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1337 # restore old quota type settings
1339 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1344 if [ "$old_MDT_QUOTA_TYPE" ]; then
1345 do_facet mgs $LCTL conf_param \
1346 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1348 if [ "$old_OST_QUOTA_TYPE" ]; then
1349 do_facet mgs $LCTL conf_param \
1350 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1354 # Handle the case when there is a space in the lfs df
1355 # "filesystem summary" line the same as when there is no space.
1356 # This will allow fixing the "lfs df" summary line in the future.
1358 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1361 # Get free inodes on the MDT specified by mdt index, free indoes on
1362 # the whole filesystem will be returned when index == -1.
1368 if [ $index -eq -1 ]; then
1371 mdt_uuid=$(mdtuuid_from_index $index)
1374 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1379 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1386 # save old quota type & set new quota type
1387 local mdt_qtype=$(mdt_quota_type)
1388 local ost_qtype=$(ost_quota_type)
1390 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1391 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1393 export old_MDT_QUOTA_TYPE=$mdt_qtype
1394 export old_OST_QUOTA_TYPE=$ost_qtype
1396 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1397 error "set mdt quota type failed"
1398 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1399 error "set ost quota type failed"
1401 local quota_usrs=$QUOTA_USERS
1403 # get_filesystem_size
1404 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1405 local blk_soft=$((disksz + 1024))
1406 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1408 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1409 local i_soft=$inodes
1410 local i_hard=$((i_soft + i_soft / 20))
1412 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1413 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1414 "inode-hardlimit: $i_hard"
1417 for usr in $quota_usrs; do
1418 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1420 cmd="$LFS setquota -$type $usr -b $blk_soft"
1421 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1423 eval $cmd || error "$cmd FAILED!"
1425 # display the quota status
1426 echo "Quota settings for $usr : "
1427 $LFS quota -v -u $usr $mntpt || true
1434 local OPTIONS=${3:-$MOUNTOPT}
1436 local device=$MGSNID:/$FSNAME
1437 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1438 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1442 echo "Starting client: $client: $OPTIONS $device $mnt"
1443 do_node $client mkdir -p $mnt
1444 do_node $client $MOUNT_CMD $OPTIONS $device $mnt || return 1
1446 set_default_debug_nodes $client
1458 [ "$3" ] && force=-f
1459 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1460 if [ $running -ne 0 ]; then
1461 echo "Stopping client $client $mnt (opts:$force)"
1462 do_node $client lsof -t $mnt || need_kill=no
1463 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1464 pids=$(do_node $client lsof -t $mnt | sort -u);
1465 if [ -n $pids ]; then
1466 do_node $client kill -9 $pids || true
1470 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1471 if [ $busy -ne 0 ] ; then
1472 echo "$mnt is still busy, wait one second" && sleep 1
1473 do_node $client umount $force $mnt
1478 # nodes is comma list
1479 sanity_mount_check_nodes () {
1485 # FIXME: assume that all cluster nodes run the same os
1486 [ "$(uname)" = Linux ] || return 0
1489 for mnt in $mnts ; do
1490 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1491 mpts=\\\$(mount | grep -c $mnt' ');
1492 if [ \\\$running -ne \\\$mpts ]; then
1493 echo \\\$(hostname) env are INSANE!;
1496 [ $? -eq 0 ] || rc=1
1501 sanity_mount_check_servers () {
1502 [ "$CLIENTONLY" ] &&
1503 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1504 echo Checking servers environments
1506 # FIXME: modify get_facets to display all facets wo params
1507 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1511 for facet in ${facets//,/ }; do
1512 node=$(facet_host ${facet})
1513 mntpt=$(facet_mntpt $facet)
1514 sanity_mount_check_nodes $node $mntpt ||
1515 { error "server $node environments are insane!"; return 1; }
1519 sanity_mount_check_clients () {
1520 local clients=${1:-$CLIENTS}
1521 local mntpt=${2:-$MOUNT}
1522 local mntpt2=${3:-$MOUNT2}
1524 [ -z $clients ] && clients=$(hostname)
1525 echo Checking clients $clients environments
1527 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1528 error "clients environments are insane!"
1531 sanity_mount_check () {
1532 sanity_mount_check_servers || return 1
1533 sanity_mount_check_clients || return 2
1536 # mount clients if not mouted
1537 zconf_mount_clients() {
1540 local OPTIONS=${3:-$MOUNTOPT}
1542 local device=$MGSNID:/$FSNAME
1543 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1544 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1548 echo "Starting client $clients: $OPTIONS $device $mnt"
1551 running=\\\$(mount | grep -c $mnt' ');
1553 if [ \\\$running -eq 0 ] ; then
1555 $MOUNT_CMD $OPTIONS $device $mnt;
1558 exit \\\$rc" || return ${PIPESTATUS[0]}
1560 echo "Started clients $clients: "
1561 do_nodes $clients "mount | grep $mnt' '"
1563 set_default_debug_nodes $clients
1568 zconf_umount_clients() {
1573 [ "$3" ] && force=-f
1575 echo "Stopping clients: $clients $mnt (opts:$force)"
1576 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1577 if [ \\\$running -ne 0 ] ; then
1578 echo Stopping client \\\$(hostname) $mnt opts:$force;
1579 lsof $mnt || need_kill=no;
1580 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1581 pids=\\\$(lsof -t $mnt | sort -u);
1582 if [ -n \\\"\\\$pids\\\" ]; then
1586 while umount $force $mnt 2>&1 | grep -q "busy"; do
1587 echo "$mnt is still busy, wait one second" && sleep 1;
1594 echo + $POWER_DOWN $node
1598 shutdown_node_hard () {
1600 local attempts=$SHUTDOWN_ATTEMPTS
1602 for i in $(seq $attempts) ; do
1605 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1606 echo "waiting for $host to fail attempts=$attempts"
1607 [ $i -lt $attempts ] || \
1608 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1614 local mnt=${2:-$MOUNT}
1617 if [ "$FAILURE_MODE" = HARD ]; then
1618 shutdown_node_hard $client
1620 zconf_umount_clients $client $mnt -f
1626 local facets="$(get_facets OST),$(get_facets MDS)"
1629 combined_mgs_mds || facets="$facets,mgs"
1631 for facet in ${facets//,/ }; do
1632 if [ $(facet_active_host $facet) == $host ]; then
1633 affected="$affected $facet"
1637 echo $(comma_list $affected)
1642 local host=${2:-$(facet_host $facet)}
1644 local label=$(convert_facet2label $facet)
1645 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1648 facets_up_on_host () {
1650 local facets=$(facets_on_host $host)
1653 for facet in ${facets//,/ }; do
1654 if $(facet_up $facet $host); then
1655 affected_up="$affected_up $facet"
1659 echo $(comma_list $affected_up)
1665 if [ "$FAILURE_MODE" = HARD ]; then
1666 shutdown_node_hard $(facet_active_host $facet)
1674 echo + $POWER_UP $node
1687 if [ "$FAILURE_MODE" = HARD ]; then
1688 reboot_node $(facet_active_host $facet)
1696 if [ "$FAILURE_MODE" = HARD ]; then
1706 for facet in ${facets//,/ }; do
1707 hosts=$(expand_list $hosts $(facet_host $facet) )
1713 _check_progs_installed () {
1717 for prog in $progs; do
1718 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1719 echo $prog missing on $(hostname)
1726 check_progs_installed () {
1730 do_rpc_nodes "$nodes" _check_progs_installed $@
1733 # recovery-scale functions
1735 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1738 start_client_load() {
1741 local var=$(node_var_name $client)_load
1742 eval export ${var}=$load
1744 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1745 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1746 END_RUN_FILE=$END_RUN_FILE \
1747 LOAD_PID_FILE=$LOAD_PID_FILE \
1748 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1749 TESTNAME=$TESTNAME \
1750 DBENCH_LIB=$DBENCH_LIB \
1751 DBENCH_SRC=$DBENCH_SRC \
1752 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1756 log "Started client load: ${load} on $client"
1758 # get the children process IDs
1759 local pids=$(ps --ppid $ppid -o pid= | xargs)
1760 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1764 start_client_loads () {
1765 local -a clients=(${1//,/ })
1766 local numloads=${#CLIENT_LOADS[@]}
1769 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1770 testnum=$((nodenum % numloads))
1771 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1773 # bug 22169: wait the background threads to start
1777 # only for remote client
1778 check_client_load () {
1780 local var=$(node_var_name $client)_load
1781 local TESTLOAD=run_${!var}.sh
1783 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1785 # bug 18914: try to connect several times not only when
1786 # check ps, but while check_catastrophe also
1789 while [ $RC = 254 -a $tries -gt 0 ]; do
1793 if ! check_catastrophe $client; then
1795 if [ $RC -eq 254 ]; then
1796 # FIXME: not sure how long we shuold sleep here
1800 echo "check catastrophe failed: RC=$RC "
1804 # We can continue try to connect if RC=254
1805 # Just print the warning about this
1806 if [ $RC = 254 ]; then
1807 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1810 # see if the load is still on the client
1813 while [ $RC = 254 -a $tries -gt 0 ]; do
1817 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1822 if [ $RC = 254 ]; then
1823 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1824 # see if we can diagnose a bit why this is
1829 check_client_loads () {
1830 local clients=${1//,/ }
1834 for client in $clients; do
1835 check_client_load $client
1837 if [ "$rc" != 0 ]; then
1838 log "Client load failed on node $client, rc=$rc"
1844 restart_client_loads () {
1845 local clients=${1//,/ }
1846 local expectedfail=${2:-""}
1850 for client in $clients; do
1851 check_client_load $client
1853 if [ "$rc" != 0 -a "$expectedfail" ]; then
1854 local var=$(node_var_name $client)_load
1855 start_client_load $client ${!var}
1856 echo "Restarted client load ${!var}: on $client. Checking ..."
1857 check_client_load $client
1859 if [ "$rc" != 0 ]; then
1860 log "Client load failed to restart on node $client, rc=$rc"
1861 # failure one client load means test fail
1862 # we do not need to check other
1871 # Start vmstat and save its process ID in a file.
1876 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1879 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1880 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1883 # Display the nodes on which client loads failed.
1884 print_end_run_file() {
1888 [ -s $file ] || return 0
1890 echo "Found the END_RUN_FILE file: $file"
1893 # A client load will stop if it finds the END_RUN_FILE file.
1894 # That does not mean the client load actually failed though.
1895 # The first node in END_RUN_FILE is the one we are interested in.
1898 if [ -n "$node" ]; then
1899 local var=$(node_var_name $node)_load
1901 local prefix=$TESTLOG_PREFIX
1902 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1903 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1904 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1906 echo "Client load ${!var} failed on node $node:"
1912 # Stop the process which had its PID saved in a file.
1917 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1919 do_nodes $nodes "test -f $pid_file &&
1920 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1923 # Stop all client loads.
1924 stop_client_loads() {
1925 local nodes=${1:-$CLIENTS}
1928 # stop the client loads
1929 stop_process $nodes $pid_file
1931 # clean up the processes that started them
1932 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1934 # End recovery-scale functions
1936 # verify that lustre actually cleaned up properly
1938 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1939 error "LBUG/LASSERT detected"
1940 BUSY=`dmesg | grep -i destruct || true`
1941 if [ "$BUSY" ]; then
1943 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1947 check_mem_leak || exit 204
1949 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
1950 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1953 if module_loaded lnet || module_loaded libcfs; then
1954 echo "$TESTSUITE: modules still loaded..." 1>&2
1963 if [[ "$1" == "--verbose" ]]; then
1978 PREV_RESULT=$(do_node $node "$TEST")
1980 RESULT=$(do_node $node "$TEST")
1981 if [[ "$RESULT" == "$FINAL" ]]; then
1982 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1983 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1987 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1988 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1992 [[ $WAIT -ge $MAX ]] && break
1993 [[ $((WAIT % print)) -eq 0 ]] &&
1994 echo "Waiting $((MAX - WAIT)) secs for update"
1995 WAIT=$((WAIT + sleep))
1998 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2002 wait_update_facet() {
2005 wait_update $(facet_active_host $facet) "$@"
2009 do_nodes $(comma_list $(mdts_nodes)) \
2010 "lctl set_param -n osd*.*MDT*.force_sync 1"
2011 do_nodes $(comma_list $(osts_nodes)) \
2012 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2013 grep -v 'Found no match'
2016 wait_delete_completed_mds() {
2017 local MAX_WAIT=${1:-20}
2019 local stime=`date +%s`
2024 # find MDS with pending deletions
2025 for node in $(mdts_nodes); do
2026 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
2027 2>/dev/null | calc_sum)
2028 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
2031 mds2sync="$mds2sync $node"
2033 if [ "$mds2sync" == "" ]; then
2036 mds2sync=$(comma_list $mds2sync)
2038 # sync MDS transactions
2039 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
2041 # wait till all changes are sent and commmitted by OSTs
2042 # for ldiskfs space is released upon execution, but DMU
2043 # do this upon commit
2046 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
2047 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
2049 #echo "$node: $changes changes on all"
2050 if [ "$changes" -eq "0" ]; then
2052 #echo "delete took $((etime - stime)) seconds"
2060 echo "Delete is not completed in $((etime - stime)) seconds"
2061 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
2067 # we can use "for" here because we are waiting the slowest
2068 for host in ${hostlist//,/ }; do
2069 check_network "$host" 900
2071 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2078 for facet in ${facetlist//,/ }; do
2079 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2081 wait_for_host $hostlist
2084 _wait_recovery_complete () {
2087 # Use default policy if $2 is not passed by caller.
2088 local MAX=${2:-$(max_recovery_time)}
2093 while [ $WAIT -lt $MAX ]; do
2094 STATUS=$(lctl get_param -n $param | grep status)
2096 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2099 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2101 echo "$param recovery not done in $MAX sec. $STATUS"
2105 wait_recovery_complete () {
2108 # with an assumption that at_max is the same on all nodes
2109 local MAX=${2:-$(max_recovery_time)}
2112 if [ "$FAILURE_MODE" = HARD ]; then
2113 facets=$(facets_on_host $(facet_active_host $facet))
2115 echo affected facets: $facets
2117 # we can use "for" here because we are waiting the slowest
2118 for facet in ${facets//,/ }; do
2119 local var_svc=${facet}_svc
2120 local param="*.${!var_svc}.recovery_status"
2122 local host=$(facet_active_host $facet)
2123 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2127 wait_mds_ost_sync () {
2128 # just because recovery is done doesn't mean we've finished
2129 # orphan cleanup. Wait for llogs to get synchronized.
2130 echo "Waiting for orphan cleanup..."
2131 # MAX value includes time needed for MDS-OST reconnection
2132 local MAX=$(( TIMEOUT * 2 ))
2133 local WAIT_TIMEOUT=${1:-$MAX}
2136 local list=$(comma_list $(mdts_nodes))
2137 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2138 if ! do_facet $SINGLEMDS \
2139 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2141 # old way, use mds_sync
2143 list=$(comma_list $(osts_nodes))
2144 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2147 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2148 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2149 local -a sync=($(do_nodes $list "$cmd"))
2152 for ((i=0; i<${#sync[@]}; i++)); do
2154 [ ${sync[$i]} -eq 1 ] && continue
2156 [ ${sync[$i]} -eq 0 ] && continue
2158 # there is a not finished MDS-OST synchronization
2162 sleep 2 # increase waiting time and cover statfs cache
2163 [ ${con} -eq 1 ] && return 0
2164 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2168 # show which nodes are not finished.
2169 do_nodes $list "$cmd"
2170 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2174 wait_destroy_complete () {
2175 echo "Waiting for local destroys to complete"
2176 # MAX value shouldn't be big as this mean server responsiveness
2177 # never increase this just to make test pass but investigate
2178 # why it takes so long time
2181 while [ $WAIT -lt $MAX ]; do
2182 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2186 for ((i=0; i<${#RPCs[@]}; i++)); do
2187 [ ${RPCs[$i]} -eq 0 ] && continue
2188 # there are still some destroy RPCs in flight
2193 [ ${con} -eq 1 ] && return 0 # done waiting
2194 echo "Waiting ${WAIT}s for local destroys to complete"
2197 echo "Local destroys weren't done in $MAX sec."
2201 wait_delete_completed() {
2202 wait_delete_completed_mds $1 || return $?
2203 wait_destroy_complete
2212 # conf-sanity 31 takes a long time cleanup
2213 while [ $WAIT -lt 300 ]; do
2214 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2215 [ -z "${running}" ] && return 0
2216 echo "waited $WAIT for${running}"
2217 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2219 WAIT=$((WAIT + INTERVAL))
2221 echo "service didn't stop after $WAIT seconds. Still running:"
2226 wait_remote_prog () {
2232 [ "$PDSH" = "no_dsh" ] && return 0
2234 while [ $WAIT -lt $2 ]; do
2235 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2236 [ -z "${running}" ] && return 0 || true
2237 echo "waited $WAIT for: "
2239 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2241 WAIT=$((WAIT + INTERVAL))
2243 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2244 [ -z "$pids" ] && return 0
2245 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2246 # FIXME: not portable
2247 for pid in $pids; do
2248 cat /proc/${pid}/status || true
2249 cat /proc/${pid}/wchan || true
2251 kill -9 $pid || true
2260 # not every config has many clients
2262 if [ ! -z "$CLIENTS" ]; then
2263 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2265 stat -f $MOUNT > /dev/null
2271 # usually checked on particular client or locally
2273 if [ ! -z "$client" ]; then
2274 $PDSH $client "stat -f $MOUNT" > /dev/null
2276 stat -f $MOUNT > /dev/null
2284 client_reconnect() {
2285 uname -n >> $MOUNT/recon
2286 if [ -z "$CLIENTS" ]; then
2287 df $MOUNT; uname -n >> $MOUNT/recon
2289 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2291 echo Connected clients:
2293 ls -l $MOUNT/recon > /dev/null
2297 affected_facets () {
2300 local host=$(facet_active_host $facet)
2301 local affected=$facet
2303 if [ "$FAILURE_MODE" = HARD ]; then
2304 affected=$(facets_up_on_host $host)
2318 #Because it will only get up facets, we need get affected
2319 #facets before shutdown
2320 #For HARD Failure mode, it needs make sure facets on the same
2321 #HOST will only be shutdown and reboot once
2322 for facet in ${facets//,/ }; do
2323 local affected_facet
2325 #check whether facet has been included in other affected facets
2326 for ((index=0; index<$total; index++)); do
2327 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2330 if [ $skip -eq 0 ]; then
2331 affecteds[$total]=$(affected_facets $facet)
2336 for ((index=0; index<$total; index++)); do
2337 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2338 local host=$(facet_active_host $facet)
2339 echo "Failing ${affecteds[index]} on $host"
2340 shutdown_facet $facet
2343 for ((index=0; index<$total; index++)); do
2344 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2345 echo reboot facets: ${affecteds[index]}
2349 change_active ${affecteds[index]}
2351 wait_for_facet ${affecteds[index]}
2352 # start mgs first if it is affected
2353 if ! combined_mgs_mds &&
2354 list_member ${affecteds[index]} mgs; then
2355 mount_facet mgs || error "Restart of mgs failed"
2357 # FIXME; has to be changed to mount all facets concurrently
2358 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2359 echo mount facets: ${affecteds[index]}
2360 mount_facets ${affecteds[index]}
2370 do_facet $facet "sync; sync; sync"
2373 # make sure there will be no seq change
2374 local clients=${CLIENTS:-$HOSTNAME}
2375 local f=fsa-\\\$\(hostname\)
2376 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2377 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2379 local svc=${facet}_svc
2380 do_facet $facet $LCTL --device ${!svc} notransno
2382 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2383 # in-memory state has to be cleared by either rebooting the host or
2384 # exporting and reimporting the pool.
2386 # Although the uberblocks are not updated when a pool is freezed,
2387 # transactions are still written to the disks. Modified blocks may be
2388 # cached in memory when tests try reading them back. The
2389 # export-and-reimport process also evicts any cached pool data from
2390 # memory to provide the correct "data loss" semantics.
2392 # In the test framework, the exporting and importing operations are
2393 # handled by stop() and mount_facet() separately, which are used
2394 # inside fail() and fail_abort().
2396 do_facet $facet $LCTL --device ${!svc} readonly
2397 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2398 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2401 replay_barrier_nodf() {
2402 local facet=$1 echo running=${running}
2403 do_facet $facet "sync; sync; sync"
2404 local svc=${facet}_svc
2405 echo Replay barrier on ${!svc}
2406 do_facet $facet $LCTL --device ${!svc} notransno
2407 do_facet $facet $LCTL --device ${!svc} readonly
2408 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2409 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2412 replay_barrier_nosync() {
2413 local facet=$1 echo running=${running}
2414 local svc=${facet}_svc
2415 echo Replay barrier on ${!svc}
2416 do_facet $facet $LCTL --device ${!svc} notransno
2417 do_facet $facet $LCTL --device ${!svc} readonly
2418 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2419 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2423 # Get Lustre client uuid for a given Lustre mount point.
2426 local mntpnt=${1:-$MOUNT}
2428 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2429 local uuid=$($LCTL get_param -n llite.$name.uuid)
2434 mds_evict_client() {
2435 local mntpnt=${1:-$MOUNT}
2436 local uuid=$(get_client_uuid $mntpnt)
2438 do_facet $SINGLEMDS \
2439 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2442 ost_evict_client() {
2443 local mntpnt=${1:-$MOUNT}
2444 local uuid=$(get_client_uuid $mntpnt)
2447 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2452 local clients=${CLIENTS:-$HOSTNAME}
2454 facet_failover $* || error "failover: $?"
2455 wait_clients_import_state "$clients" "$facets" FULL
2456 clients_up || error "post-failover df: $?"
2461 facet_failover $facet
2467 change_active $facet
2468 wait_for_facet $facet
2469 mount_facet $facet -o abort_recovery
2470 clients_up || echo "first df failed: $?"
2471 clients_up || error "post-failover df: $?"
2475 echo There is no lmc. This is mountconf, baby.
2479 host_nids_address() {
2483 if [ -n "$kind" ]; then
2484 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2486 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2492 if [ "$1" = "'*'" ]; then echo \'*\'; else
2498 if [ "$1" = "'*'" ]; then echo \'*\'; else
2499 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2501 if [ -z "$ID" ]; then
2502 echo "Could not get a ptl id for $1..."
2511 h2name_or_ip "$1" "tcp"
2516 if [ "$1" = "'*'" ]; then echo \'*\'; else
2517 if type __h2elan >/dev/null 2>&1; then
2520 ID=`echo $1 | sed 's/[^0-9]*//g'`
2528 h2name_or_ip "$1" "o2ib"
2532 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2533 # expressions format. As a bonus we can then just pass in those variables
2534 # to pdsh. What this function does is take a HOSTLIST type string and
2535 # expand it into a space deliminated list for us.
2543 [ -z "$hostlist" ] && return
2545 # Translate the case of [..],..,[..] to [..] .. [..]
2546 list="${hostlist/],/] }"
2548 [[ "$front" == *,* ]] && {
2551 list=${list/${old}/${new}}
2554 for item in $list; do
2555 # Test if we have any []'s at all
2556 if [ "$item" != "${item/\[/}" ]; then {
2557 # Expand the [*] into list
2561 if [ "$name" != "$item" ]; then
2562 group=${item#$name[*}
2565 for range in ${group//,/ }; do
2569 # Number of leading zeros
2572 end=$(echo $end | sed 's/0*//')
2573 [[ -z "$end" ]] && end=0
2574 [[ $padlen2 -gt $padlen ]] && {
2575 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2578 begin=$(echo $begin | sed 's/0*//')
2579 [ -z $begin ] && begin=0
2581 for num in $(seq -f "%0${padlen}g" $begin $end); do
2582 value="${name#*,}${num}${back}"
2583 [ "$value" != "${value/\[/}" ] && {
2584 value=$(hostlist_expand "$value")
2586 myList="$myList $value"
2591 myList="$myList $item"
2594 myList=${myList//,/ }
2595 myList=${myList:1} # Remove first character which is a space
2597 # Filter any duplicates without sorting
2599 myList="${list%% *}"
2601 while [[ "$list" != ${myList##* } ]]; do
2602 list=${list//${list%% *} /}
2603 myList="$myList ${list%% *}"
2605 myList="${myList%* }";
2607 # We can select an object at a offset in the list
2610 for item in $myList; do
2612 [ $cnt -eq $offset ] && {
2616 [ $(get_node_count $myList) -ne 1 ] && myList=""
2625 [ "$facet" == client ] && echo -n $HOSTNAME && return
2626 varname=${facet}_HOST
2627 if [ -z "${!varname}" ]; then
2628 if [ "${facet:0:3}" == "ost" ]; then
2629 local fh=${facet%failover}_HOST
2630 eval export ${facet}_HOST=${!fh}
2631 if [ -z "${!varname}" ]; then
2632 eval export ${facet}_HOST=${ost_HOST}
2634 elif [ "${facet:0:3}" == "mdt" -o \
2635 "${facet:0:3}" == "mds" -o \
2636 "${facet:0:3}" == "mgs" ]; then
2637 eval export ${facet}_HOST=${mds_HOST}
2643 facet_failover_host() {
2647 var=${facet}failover_HOST
2648 if [ -n "${!var}" ]; then
2653 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2654 "${facet:0:3}" == "mgs" ]; then
2656 eval export ${facet}failover_host=${mds_HOST}
2661 if [[ $facet == ost* ]]; then
2662 eval export ${facet}failover_host=${ost_HOST}
2670 local activevar=${facet}active
2672 if [ -f $TMP/${facet}active ] ; then
2673 source $TMP/${facet}active
2676 active=${!activevar}
2677 if [ -z "$active" ] ; then
2684 facet_active_host() {
2686 local active=`facet_active $facet`
2687 if [ "$facet" == client ]; then
2690 echo `facet_host $active`
2694 # Get the passive failover partner host of facet.
2695 facet_passive_host() {
2697 [[ $facet = client ]] && return
2699 local host=${facet}_HOST
2700 local failover_host=${facet}failover_HOST
2701 local active_host=$(facet_active_host $facet)
2703 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2705 if [[ $active_host = ${!host} ]]; then
2706 echo -n ${!failover_host}
2716 facetlist=$(exclude_items_from_list $facetlist mgs)
2718 for facet in ${facetlist//,/ }; do
2719 local failover=${facet}failover
2720 local host=`facet_host $failover`
2721 [ -z "$host" ] && return
2723 local curactive=`facet_active $facet`
2724 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2725 eval export ${facet}active=$facet
2727 eval export ${facet}active=$failover
2729 # save the active host for this facet
2730 local activevar=${facet}active
2731 echo "$activevar=${!activevar}" > $TMP/$activevar
2732 [[ $facet = mds1 ]] && combined_mgs_mds && \
2733 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2734 local TO=`facet_active_host $facet`
2735 echo "Failover $facet to $TO"
2741 # do not stripe off hostname if verbose, bug 19215
2742 if [ x$1 = x--verbose ]; then
2750 if [ "$HOST" = "$HOSTNAME" ]; then
2752 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2753 echo "cannot run remote command on $HOST with $myPDSH"
2757 echo "CMD: $HOST $@" >&2
2758 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2761 if [ "$myPDSH" = "rsh" ]; then
2762 # we need this because rsh does not return exit code of an executed command
2763 local command_status="$TMP/cs"
2764 rsh $HOST ":> $command_status"
2765 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2766 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2767 echo command failed >$command_status"
2768 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2773 # print HOSTNAME for myPDSH="no_dsh"
2774 if [[ $myPDSH = no_dsh ]]; then
2775 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2777 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2780 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2782 return ${PIPESTATUS[0]}
2786 do_node --verbose "$@"
2789 single_local_node () {
2790 [ "$1" = "$HOSTNAME" ]
2793 # Outputs environment variable assignments that should be passed to remote nodes
2797 local facets=$(get_facets)
2800 for var in ${!MODOPTS_*}; do
2802 echo -n " ${var}=\"$value\""
2805 for facet in ${facets//,/ }; do
2807 if [ -n "${!var}" ]; then
2808 echo -n " $var=${!var}"
2812 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2813 if [ -n "${!var}" ]; then
2814 echo -n " $var=${!var}"
2818 if [ -n "$FSTYPE" ]; then
2819 echo -n " FSTYPE=$FSTYPE"
2825 # do not stripe off hostname if verbose, bug 19215
2826 if [ x$1 = x--verbose ]; then
2834 if single_local_node $rnodes; then
2836 do_nodev $rnodes "$@"
2838 do_node $rnodes "$@"
2843 # This is part from do_node
2846 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2847 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2849 export FANOUT=$(get_node_count "${rnodes//,/ }")
2851 echo "CMD: $rnodes $@" >&2
2852 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2855 # do not replace anything from pdsh output if -N is used
2856 # -N Disable hostname: prefix on lines of output.
2857 if $verbose || [[ $myPDSH = *-N* ]]; then
2858 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2860 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2862 return ${PIPESTATUS[0]}
2868 local HOST=`facet_active_host $facet`
2869 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2873 # Function: do_facet_random_file $FACET $FILE $SIZE
2874 # Creates FILE with random content on the given FACET of given SIZE
2876 do_facet_random_file() {
2880 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2881 do_facet $facet "$cmd 2>/dev/null"
2884 do_facet_create_file() {
2888 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2889 do_facet $facet "$cmd 2>/dev/null"
2893 do_nodes --verbose "$@"
2899 # make sure its not already running
2901 rm -f $TMP/${facet}active
2902 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2903 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2905 if [[ $(facet_fstype $facet) == zfs ]]; then
2907 # After formatting a ZFS target, "cachefile=none" property will
2908 # be set on the ZFS storage pool so that the pool is not
2909 # automatically imported on system startup. And then the pool
2910 # will be exported so as to leave the importing and exporting
2911 # operations handled by mount_facet() and stop() separately.
2913 refresh_partition_table $facet $(facet_vdevice $facet)
2914 disable_zpool_cache $facet
2919 # Device formatted as ost
2922 local DEVNAME=OSTDEV$num
2924 local fstype=$(facet_fstype ost$num)
2928 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2929 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2931 #try $OSTZFSDEVn - independent of vdev
2932 DEVNAME=OSTZFSDEV$num
2933 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2935 error "unknown fstype!";;
2941 # Physical device location of data
2947 local fstype=$(facet_fstype ost$num)
2951 # vdevs are not supported by ldiskfs
2954 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2955 # Device formated by zfs
2957 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2959 error "unknown fstype!";;
2965 # Logical device formated for lustre
2968 local DEVNAME=MDSDEV$num
2970 local fstype=$(facet_fstype mds$num)
2974 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2975 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2977 # try $MDSZFSDEVn - independent of vdev
2978 DEVNAME=MDSZFSDEV$num
2979 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
2981 error "unknown fstype!";;
2987 # Physical location of data
2991 local fstype=$(facet_fstype mds$num)
2995 # vdevs are not supported by ldiskfs
2998 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2999 # Device formated by ZFS
3000 local DEVNAME=MDSDEV$num
3001 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3003 error "unknown fstype!";;
3011 local fstype=$(facet_fstype mgs)
3015 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3016 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3017 DEVPTR=$(mdsdevname 1)
3022 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3023 ( [ -z "$MGSZFSDEV" ] &&
3024 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3025 DEVPTR=$(mdsdevname 1)
3027 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3030 error "unknown fstype!";;
3039 local fstype=$(facet_fstype mgs)
3043 # vdevs are not supported by ldiskfs
3046 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3047 ( [ -z "$MGSDEV" ] &&
3048 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3049 VDEVPTR=$(mdsvdevname 1)
3050 elif [ -n "$MGSDEV" ]; then
3054 error "unknown fstype!";;
3062 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3064 local var=${facet}_MOUNT
3065 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3072 local dev=$(facet_device $facet)
3073 local mnt=$(facet_mntpt $facet)
3076 if ! do_facet $facet test -b $dev; then
3079 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3084 local dev=$(facet_device $facet)
3085 local mnt=$(facet_mntpt $facet)
3087 do_facet $facet umount -d $mnt
3091 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3096 local ds=$(facet_device $facet)
3097 local mnt=$(facet_mntpt $facet)
3102 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3103 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3104 do_facet $facet $ZFS set canmount=noauto $ds
3106 # The "legacy" mount method is used here because "zfs unmount $mnt"
3107 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3108 # targets are not available at the time, the stat(2) on $MOUNT will
3111 do_facet $facet $ZFS set mountpoint=legacy $ds
3112 do_facet $facet mount -t zfs $ds $mnt
3113 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3114 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3119 local ds=$(facet_device $facet)
3120 local mnt=$(facet_mntpt $facet)
3121 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3122 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3123 local mntpt=${!var_mntpt}
3124 local canmnt=${!var_canmnt}
3128 do_facet $facet umount $mnt
3129 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3130 do_facet $facet $ZFS set canmount=$canmnt $ds
3136 local fstype=$(facet_fstype $facet)
3138 mount_$fstype $facet
3143 local fstype=$(facet_fstype $facet)
3145 unmount_$fstype $facet
3152 # make sure we are using the primary server, so test-framework will
3153 # be able to clean up properly.
3154 activemds=`facet_active mds1`
3155 if [ $activemds != "mds1" ]; then
3159 local clients=$CLIENTS
3160 [ -z $clients ] && clients=$(hostname)
3162 zconf_umount_clients $clients $MOUNT "$*" || true
3163 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3165 [ "$CLIENTONLY" ] && return
3166 # The add fn does rm ${facet}active file, this would be enough
3167 # if we use do_facet <facet> only after the facet added, but
3168 # currently we use do_facet mds in local.sh
3169 for num in `seq $MDSCOUNT`; do
3171 rm -f ${TMP}/mds${num}active
3173 combined_mgs_mds && rm -f $TMP/mgsactive
3175 for num in `seq $OSTCOUNT`; do
3177 rm -f $TMP/ost${num}active
3180 if ! combined_mgs_mds ; then
3187 cleanup_echo_devs () {
3188 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3190 for dev in $devs; do
3191 $LCTL --device $dev cleanup
3192 $LCTL --device $dev detach
3197 nfs_client_mode && return
3206 combined_mgs_mds () {
3207 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3208 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3212 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3216 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3222 local fsname=${3:-"$FSNAME"}
3223 local type=$(facet_type $facet)
3224 local index=$(($(facet_number $facet) - 1))
3225 local fstype=$(facet_fstype $facet)
3226 local host=$(facet_host $facet)
3231 if [ $type == MGS ] && combined_mgs_mds; then
3235 if [ $type == MGS ] || ( [ $type == MDS ] &&
3236 [ "$dev" == $(mgsdevname) ] &&
3237 [ "$host" == "$(facet_host mgs)" ] ); then
3240 opts="--mgsnode=$MGSNID"
3243 if [ $type != MGS ]; then
3244 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3248 var=${facet}failover_HOST
3249 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3250 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3253 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3254 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3256 if [ $type == MDS ]; then
3257 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3258 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3259 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3260 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3261 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3263 if [ $fstype == ldiskfs ]; then
3264 # Check for wide striping
3265 if [ $OSTCOUNT -gt 160 ]; then
3266 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3267 fs_mkfs_opts+="-O large_xattr"
3270 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3271 if [ ! -z $EJOURNAL ]; then
3272 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3274 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3278 if [ $type == OST ]; then
3279 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3280 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3282 if [ $fstype == ldiskfs ]; then
3283 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3287 opts+=" --backfstype=$fstype"
3290 if [ -n "${!var}" ]; then
3291 opts+=" --device-size=${!var}"
3294 var=$(upper $fstype)_MKFS_OPTS
3295 fs_mkfs_opts+=${!var:+" ${!var}"}
3297 var=${type}_FS_MKFS_OPTS
3298 fs_mkfs_opts+=${!var:+" ${!var}"}
3300 if [ -n "${fs_mkfs_opts## }" ]; then
3301 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3305 opts+=${!var:+" ${!var}"}
3318 # We need ldiskfs here, may as well load them all
3320 [ "$CLIENTONLY" ] && return
3321 echo Formatting mgs, mds, osts
3322 if ! combined_mgs_mds ; then
3323 echo "Format mgs: $(mgsdevname)"
3324 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3325 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3329 for num in $(seq $MDSCOUNT); do
3330 echo "Format mds$num: $(mdsdevname $num)"
3331 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3332 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3333 ${quiet:+>/dev/null} || exit 10
3336 for num in $(seq $OSTCOUNT); do
3337 echo "Format ost$num: $(ostdevname $num)"
3338 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3339 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3340 ${quiet:+>/dev/null} || exit 10
3345 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3349 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3353 # 0: success, the old identity set already.
3354 # 1: success, the old identity does not set.
3359 local j=`expr $num - 1`
3360 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3362 if [ -z "$MDT" ]; then
3366 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3369 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3371 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3374 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3376 if [ $old = "NONE" ]; then
3385 zconf_umount `hostname` $1 || error "umount failed"
3386 zconf_mount `hostname` $1 || error "mount failed"
3394 rm -f $TMP/${facet}active
3395 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3400 local mdt_count=${1:-$MDSCOUNT}
3401 local ost_count=${2:-$OSTCOUNT}
3404 for num in $(seq $mdt_count); do
3405 DEVNAME=$(mdsdevname $num)
3406 writeconf_facet mds$num $DEVNAME || rc=$?
3409 for num in $(seq $ost_count); do
3410 DEVNAME=$(ostdevname $num)
3411 writeconf_facet ost$num $DEVNAME || rc=$?
3417 nfs_client_mode && return
3419 sanity_mount_check ||
3420 error "environments are insane!"
3424 if [ -z "$CLIENTONLY" ]; then
3425 echo Setup mgs, mdt, osts
3426 echo $WRITECONF | grep -q "writeconf" && \
3428 if ! combined_mgs_mds ; then
3429 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3432 for num in `seq $MDSCOUNT`; do
3433 DEVNAME=$(mdsdevname $num)
3434 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3436 # We started mds, now we should set failover variables properly.
3437 # Set mds${num}failover_HOST if it is not set (the default failnode).
3438 local varname=mds${num}failover_HOST
3439 if [ -z "${!varname}" ]; then
3440 eval mds${num}failover_HOST=$(facet_host mds$num)
3443 if [ $IDENTITY_UPCALL != "default" ]; then
3444 switch_identity $num $IDENTITY_UPCALL
3447 for num in `seq $OSTCOUNT`; do
3448 DEVNAME=$(ostdevname $num)
3449 start ost$num $DEVNAME $OST_MOUNT_OPTS
3451 # We started ost$num, now we should set ost${num}failover variable properly.
3452 # Set ost${num}failover_HOST if it is not set (the default failnode).
3453 varname=ost${num}failover_HOST
3454 if [ -z "${!varname}" ]; then
3455 eval ost${num}failover_HOST=$(facet_host ost${num})
3463 # wait a while to allow sptlrpc configuration be propogated to targets,
3464 # only needed when mounting new target devices.
3469 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3471 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3474 if [ "$MOUNT_2" ]; then
3475 mount_client $MOUNT2
3476 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3481 # by remounting mdt before ost, initial connect from mdt to ost might
3482 # timeout because ost is not ready yet. wait some time to its fully
3483 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3484 # by a context negotiation rpc with $TIMEOUT.
3485 # FIXME better by monitoring import status.
3488 sleep $((TIMEOUT + 5))
3494 mounted_lustre_filesystems() {
3495 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3498 init_facet_vars () {
3499 [ "$CLIENTONLY" ] && return 0
3506 eval export ${facet}_dev=${device}
3507 eval export ${facet}_opt=\"$@\"
3509 local dev=${facet}_dev
3511 # We need to loop for the label
3512 # in case its not initialized yet.
3513 for wait_time in {0,1,3,5,10}; do
3515 if [ $wait_time -gt 0 ]; then
3516 echo "${!dev} not yet initialized,"\
3517 "waiting ${wait_time} seconds."
3521 local label=$(devicelabel ${facet} ${!dev})
3523 # Check to make sure the label does
3524 # not include ffff at the end of the label.
3525 # This indicates it has not been initialized yet.
3527 if [[ $label =~ [f|F]{4}$ ]]; then
3528 # label is not initialized, unset the result
3529 # and either try again or fail
3536 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3538 eval export ${facet}_svc=${label}
3540 local varname=${facet}failover_HOST
3541 if [ -z "${!varname}" ]; then
3542 eval export $varname=$(facet_host $facet)
3545 varname=${facet}_HOST
3546 if [ -z "${!varname}" ]; then
3547 eval export $varname=$(facet_host $facet)
3550 # ${facet}failover_dev is set in cfg file
3551 varname=${facet}failover_dev
3552 if [ -n "${!varname}" ] ; then
3553 eval export ${facet}failover_dev=${!varname}
3555 eval export ${facet}failover_dev=$device
3558 # get mount point of already mounted device
3559 # is facet_dev is already mounted then use the real
3560 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3561 # i.e. ${facet}_MOUNT if specified by user or default
3562 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3563 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3564 if [ -z $mntpt ]; then
3565 mntpt=$(facet_mntpt $facet)
3567 eval export ${facet}_MOUNT=$mntpt
3570 init_facets_vars () {
3573 if ! remote_mds_nodsh; then
3574 for num in $(seq $MDSCOUNT); do
3575 DEVNAME=`mdsdevname $num`
3576 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3580 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3582 if ! remote_ost_nodsh; then
3583 for num in $(seq $OSTCOUNT); do
3584 DEVNAME=$(ostdevname $num)
3585 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3590 osc_ensure_active () {
3595 while [ $period -lt $timeout ]; do
3596 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3597 if [ $count -eq 0 ]; then
3601 echo "There are $count OST are inactive, wait $period seconds, and try again"
3603 period=$((period+3))
3606 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3609 set_conf_param_and_check() {
3613 local ORIG=$(do_facet $myfacet "$TEST")
3614 if [ $# -gt 3 ]; then
3620 echo "Setting $PARAM from $ORIG to $FINAL"
3621 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3622 error "conf_param $PARAM failed"
3624 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3625 error "check $PARAM failed!"
3628 init_param_vars () {
3630 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3632 log "Using TIMEOUT=$TIMEOUT"
3634 osc_ensure_active $SINGLEMDS $TIMEOUT
3635 osc_ensure_active client $TIMEOUT
3637 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3638 local current_jobid_var=$($LCTL get_param -n jobid_var)
3640 if [ $JOBID_VAR = "existing" ]; then
3641 echo "keeping jobstats as $current_jobid_var"
3642 elif [ $current_jobid_var != $JOBID_VAR ]; then
3643 echo "seting jobstats to $JOBID_VAR"
3645 set_conf_param_and_check client \
3646 "$LCTL get_param -n jobid_var" \
3647 "$FSNAME.sys.jobid_var" $JOBID_VAR
3650 echo "jobstats not supported by server"
3653 if [ $QUOTA_AUTO -ne 0 ]; then
3654 if [ "$ENABLE_QUOTA" ]; then
3655 echo "enable quota as required"
3656 setup_quota $MOUNT || return 2
3658 echo "disable quota as required"
3659 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3665 nfs_client_mode () {
3666 if [ "$NFSCLIENT" ]; then
3667 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3668 local clients=$CLIENTS
3669 [ -z $clients ] && clients=$(hostname)
3671 # FIXME: remove hostname when 19215 fixed
3672 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3673 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3674 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3675 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3677 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3683 check_config_client () {
3686 local mounted=$(mount | grep " $mntpt ")
3687 if [ "$CLIENTONLY" ]; then
3689 # CLIENTONLY should not depend on *_HOST settings
3690 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3691 # in theory someone could create a new,
3692 # client-only config file that assumed lustre was already
3693 # configured and didn't set the MGSNID. If MGSNID is not set,
3694 # then we should use the mgs nid currently being used
3695 # as the default value. bug 18021
3696 [[ x$MGSNID = x ]] &&
3699 if [[ x$mgc != xMGC$MGSNID ]]; then
3700 if [ "$mgs_HOST" ]; then
3701 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3702 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3703 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3709 local myMGS_host=$mgs_HOST
3710 if [ "$NETTYPE" = "ptl" ]; then
3711 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3714 echo Checking config lustre mounted on $mntpt
3715 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3716 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3718 # if [ "$mgshost" != "$myMGS_host" ]; then
3719 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3720 # Please use correct config or set mds_HOST correctly!"
3725 check_config_clients () {
3726 local clients=${CLIENTS:-$HOSTNAME}
3729 nfs_client_mode && return
3731 do_rpc_nodes "$clients" check_config_client $mntpt
3733 sanity_mount_check || error "environments are insane!"
3737 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3738 local cltimeout=$(lctl get_param -n timeout)
3739 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3740 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3747 [ -z $mntpt ] && return 1
3748 local mounted=$(mounted_lustre_filesystems)
3750 echo $mounted' ' | grep -w -q $mntpt' '
3754 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3758 # empty lustre filesystem may have empty directories lost+found and .lustre
3760 # exclude .lustre & lost+found
3761 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3762 -print | wc -l) = 1 ] || return 1
3763 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3764 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3765 # exclude .lustre/fid (LU-2780)
3766 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3767 -print | wc -l) = 1 ] || return 1
3769 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3774 check_and_setup_lustre() {
3775 nfs_client_mode && return
3777 local MOUNTED=$(mounted_lustre_filesystems)
3781 # both MOUNT and MOUNT2 are not mounted
3782 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3783 [ "$REFORMAT" ] && formatall
3784 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3786 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3787 export I_MOUNTED=yes
3791 elif is_mounted $MOUNT2; then
3793 # MOUNT2 is mounted, while MOUNT_2 is not set
3794 if ! [ "$MOUNT_2" ]; then
3795 cleanup_mount $MOUNT2
3796 export I_UMOUNTED2=yes
3799 # MOUNT2 is mounted, MOUNT_2 is set
3801 # FIXME: what to do if check_config failed?
3803 # 1) remote client has mounted other Lustre fs ?
3804 # 2) it has insane env ?
3805 # let's try umount MOUNT2 on all clients and mount it again:
3806 if ! check_config_clients $MOUNT2; then
3807 cleanup_mount $MOUNT2
3808 restore_mount $MOUNT2
3809 export I_MOUNTED2=yes
3814 # MOUNT is mounted MOUNT2 is not mounted
3815 elif [ "$MOUNT_2" ]; then
3816 restore_mount $MOUNT2
3817 export I_MOUNTED2=yes
3821 # FIXME: what to do if check_config failed?
3823 # 1) remote client has mounted other Lustre fs?
3824 # 2) lustre is mounted on remote_clients atall ?
3825 check_config_clients $MOUNT
3829 set_default_debug_nodes $(comma_list $(nodes_list))
3832 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3834 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3835 facets="$(get_facets OST)"
3836 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3837 facets="$facets,$(get_facets MDS)"
3838 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3839 facets="$facets,mgs"
3840 local nodes="$(facets_hosts ${facets})"
3841 if [ -n "$nodes" ] ; then
3842 do_nodes $nodes "$LCTL set_param \
3843 osd-ldiskfs.track_declares_assert=1 || true"
3852 if [ "$ONLY" == "setup" ]; then
3858 local clients=${CLIENTS:-$HOSTNAME}
3861 zconf_mount_clients $clients $mntpt
3865 local clients=${CLIENTS:-$HOSTNAME}
3868 zconf_umount_clients $clients $mntpt
3871 cleanup_and_setup_lustre() {
3872 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3873 lctl set_param debug=0 || true
3875 if [ "$ONLY" == "cleanup" ]; then
3879 check_and_setup_lustre
3882 # Get all of the server target devices from a given server node and type.
3889 if [ "$type" == ost ]; then
3890 devs=$(get_osd_param $node "" mntdev)
3892 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
3894 for dev in $devs; do
3896 *loop*) do_node $node "losetup $dev" | \
3897 sed -e "s/.*(//" -e "s/).*//" ;;
3903 # Get all of the server target devices.
3908 # Master MDS parameters used by lfsck
3909 MDTNODE=$(facet_active_host $SINGLEMDS)
3910 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
3914 for node in $(mdts_nodes); do
3915 MDTDEVS[i]=$(get_mnt_devs $node mdt)
3921 for node in $(osts_nodes); do
3922 OSTDEVS[i]=$(get_mnt_devs $node ost)
3927 # Run e2fsck on MDT or OST device.
3932 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3933 local log=$TMP/e2fsck.log
3937 do_node $node $cmd 2>&1 | tee $log
3939 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
3941 if [ $MDSCOUNT -gt 1 ]; then
3942 skip "DNE mode isn't supported!"
3946 error "It's not DNE mode."
3951 [ $rc -le $FSCK_MAX_ERR ] ||
3952 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3958 # Run resize2fs on MDT or OST device.
3967 do_facet $facet "$RESIZE2FS $opts $device $size"
3970 # verify a directory is shared among nodes.
3971 check_shared_dir() {
3973 local list=${2:-$(comma_list $(nodes_list))}
3975 [ -z "$dir" ] && return 1
3976 do_rpc_nodes "$list" check_logdir $dir
3977 check_write_access $dir "$list" || return 1
3981 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3988 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3989 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3991 check_shared_dir $SHARED_DIRECTORY ||
3992 error "$SHARED_DIRECTORY isn't a shared directory"
3994 export MDSDB=$SHARED_DIRECTORY/mdsdb
3995 export OSTDB=$SHARED_DIRECTORY/ostdb
3997 # DNE is not supported, so when running e2fsck on a DNE filesystem,
3998 # we only pass master MDS parameters.
3999 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4004 for node in $(osts_nodes); do
4005 for dev in ${OSTDEVS[i]}; do
4006 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4007 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4008 ostidx=$((ostidx + 1))
4014 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4015 run_lfsck_remote() {
4016 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4021 #Check if lustre is already mounted
4022 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4024 zconf_mount $client $MOUNT ||
4025 error "failed to mount Lustre on $client"
4029 do_node $client $cmd || rc=$?
4030 #Umount if necessary
4032 zconf_umount $client $MOUNT ||
4033 error "failed to unmount Lustre on $client"
4036 [ $rc -le $FSCK_MAX_ERR ] ||
4037 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4038 echo "lfsck finished with rc=$rc"
4044 local facets="client $SINGLEMDS"
4050 for facet in $facets; do
4051 node=$(facet_active_host $facet)
4052 if check_progs_installed $node $LFSCK_BIN; then
4057 ! $found && error "None of \"$facets\" supports lfsck"
4059 run_lfsck_remote $node || rc=$?
4061 rm -rvf $MDSDB* $OSTDB* || true
4065 check_and_cleanup_lustre() {
4066 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4072 if is_mounted $MOUNT; then
4073 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4074 error "remove sub-test dirs failed"
4075 [ "$ENABLE_QUOTA" ] && restore_quota || true
4078 if [ "$I_UMOUNTED2" = "yes" ]; then
4079 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4082 if [ "$I_MOUNTED2" = "yes" ]; then
4083 cleanup_mount $MOUNT2
4086 if [ "$I_MOUNTED" = "yes" ]; then
4087 cleanupall -f || error "cleanup failed"
4091 if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
4092 umount /sbin/mount.lustre
4099 wait_for_function () {
4102 # suppress fn both stderr and stdout
4103 if [ "$1" = "--quiet" ]; then
4105 quiet=" > /dev/null 2>&1"
4117 eval $fn $quiet && return 0
4119 wait=$((wait + sleep))
4120 [ $wait -lt $max ] || return 1
4121 echo waiting $fn, $((max - wait)) secs left ...
4131 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4132 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4133 echo "Network not available!"
4137 echo `date +"%H:%M:%S (%s)"` network interface is UP
4145 # Convert a space-delimited list to a comma-delimited list. If the input is
4146 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4148 # echo is used to convert newlines to spaces, since it doesn't
4149 # introduce a trailing space as using "tr '\n' ' '" does
4150 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4156 echo $list | grep -qw $item
4159 # list, excluded are the comma separated lists
4160 exclude_items_from_list () {
4166 for item in ${excluded//,/ }; do
4167 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4169 echo $(comma_list $list)
4172 # list, expand are the comma separated lists
4174 local list=${1//,/ }
4175 local expand=${2//,/ }
4178 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4179 echo $(comma_list $expanded)
4182 testslist_filter () {
4183 local script=$LUSTRE/tests/${TESTSUITE}.sh
4185 [ -f $script ] || return 0
4187 local start_at=$START_AT
4188 local stop_at=$STOP_AT
4190 local var=${TESTSUITE//-/_}_START_AT
4191 [ x"${!var}" != x ] && start_at=${!var}
4192 var=${TESTSUITE//-/_}_STOP_AT
4193 [ x"${!var}" != x ] && stop_at=${!var}
4195 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4196 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4197 /^'${start_at}'$/ {flag = 0}
4198 {if (flag == 1) print $0}
4199 /^'${stop_at}'$/ { flag = 1 }'
4203 (cd `dirname $1`; echo $PWD/`basename $1`)
4207 local types=${1:-"OST MDS MGS"}
4211 for entry in $types; do
4212 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4213 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4216 MGS ) list="$list $name";;
4217 MDS|OST|AGT ) local count=${type}COUNT
4218 for ((i=1; i<=${!count}; i++)) do
4219 list="$list ${name}$i"
4221 * ) error "Invalid facet type"
4225 echo $(comma_list $list)
4228 ##################################
4229 # Adaptive Timeouts funcs
4232 # only check mds, we assume at_max is the same on all nodes
4233 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4234 if [ $at_max -eq 0 ]; then
4245 # suppose that all ost-s have the same $at value set
4246 [ $facet != "ost" ] || facet=ost1
4248 do_facet $facet "lctl get_param -n $at"
4266 if [ $facet == "ost" ]; then
4267 facet=$(get_facets OST)
4268 elif [ $facet == "mds" ]; then
4269 facet=$(get_facets MDS)
4271 hosts=$(expand_list $hosts $(facets_hosts $facet))
4274 do_nodes $hosts lctl set_param at_max=$at_max
4277 ##################################
4281 # OBD_FAIL_MDS_ALL_REQUEST_NET
4283 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4284 do_facet client "$1" || RC=$?
4285 do_facet $SINGLEMDS lctl set_param fail_loc=0
4290 # OBD_FAIL_MDS_ALL_REPLY_NET
4292 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4293 do_facet client "$@" || RC=$?
4294 do_facet $SINGLEMDS lctl set_param fail_loc=0
4298 drop_reint_reply() {
4299 # OBD_FAIL_MDS_REINT_NET_REP
4301 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4302 do_facet client "$@" || RC=$?
4303 do_facet $SINGLEMDS lctl set_param fail_loc=0
4307 drop_update_reply() {
4308 # OBD_FAIL_UPDATE_OBJ_NET_REP
4312 do_facet mds${index} lctl set_param fail_loc=0x1701
4313 do_facet client "$@" || RC=$?
4314 do_facet mds${index} lctl set_param fail_loc=0
4319 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4322 local timeout=${2:-0}
4323 # default is (obd_timeout / 4) if unspecified
4324 echo "timeout is $timeout/$2"
4325 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4326 do_facet client "$1" || RC=$?
4327 do_facet client "sync"
4328 do_facet ost1 lctl set_param fail_loc=0
4332 drop_ldlm_cancel() {
4333 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4335 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4336 do_nodes $list lctl set_param fail_loc=0x304
4338 do_facet client "$@" || RC=$?
4340 do_nodes $list lctl set_param fail_loc=0
4344 drop_bl_callback() {
4345 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4347 do_facet client lctl set_param fail_loc=0x80000305
4348 do_facet client "$@" || RC=$?
4349 do_facet client lctl set_param fail_loc=0
4354 #define OBD_FAIL_LDLM_REPLY 0x30c
4356 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4357 do_facet client "$@" || RC=$?
4358 do_facet $SINGLEMDS lctl set_param fail_loc=0
4366 echo "clearing fail_loc on $facet"
4367 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4370 set_nodes_failloc () {
4371 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4374 cancel_lru_locks() {
4375 $LCTL mark "cancel_lru_locks $1 start"
4376 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4377 $LCTL set_param -n $d=clear
4379 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4380 $LCTL mark "cancel_lru_locks $1 stop"
4385 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4386 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4387 echo "$DEFAULT_LRU_SIZE"
4392 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4395 lru_resize_disable()
4397 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4402 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4403 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4404 echo there is still data in page cache $FILE ?
4405 lctl get_param -n $FILE
4413 DEBUGSAVE="$(lctl get_param -n debug)"
4417 [ -n "$DEBUGSAVE" ] && \
4418 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4423 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4426 debug_size_restore() {
4427 [ -n "$DEBUG_SIZE_SAVED" ] && \
4428 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4432 start_full_debug_logging() {
4437 local DEBUG_SIZE=150
4439 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4440 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4443 stop_full_debug_logging() {
4448 # prints bash call stack
4451 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4452 local s=${BASH_SOURCE[$i]}
4453 local l=${BASH_LINENO[$i-1]}
4454 local f=${FUNCNAME[$i]}
4455 echo " = $s:$l:$f()"
4459 ##################################
4461 ##################################
4464 local TYPE=${TYPE:-"FAIL"}
4467 # do not dump logs if $1=false
4468 if [ "x$1" = "xfalse" ]; then
4474 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4478 # We need to dump the logs on all nodes
4480 gather_logs $(comma_list $(nodes_list))
4484 [ "$TESTSUITELOG" ] &&
4485 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4486 if [ -z "$*" ]; then
4487 echo "error() without useful message, please fix" > $LOGDIR/err
4489 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4490 echo "$@" > $LOGDIR/ignore
4492 echo "$@" > $LOGDIR/err
4499 local log=$TESTSUITELOG
4501 [ -f "$log" ] && grep -q FAIL $log && status=1
4514 # use only if we are ignoring failures for this test, bugno required.
4515 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4516 # e.g. error_ignore bz5494 "your message" or
4517 # error_ignore LU-5494 "your message"
4519 local TYPE="IGNORE ($1)"
4524 error_and_remount() {
4526 remount_client $MOUNT
4531 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4536 log " SKIP: $TESTSUITE $TESTNAME $@"
4538 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4539 skip_logged $TESTNAME "$@"
4542 echo "$@" > $LOGDIR/skip
4545 [[ -n "$TESTSUITELOG" ]] &&
4546 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4549 build_test_filter() {
4550 EXCEPT="$EXCEPT $(testslist_filter)"
4553 if [[ $O = [0-9]*-[0-9]* ]]; then
4554 for num in $(seq $(echo $O | tr '-' ' ')); do
4562 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4563 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4564 [ "$EXCEPT_SLOW" ] && \
4565 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4566 for E in $EXCEPT; do
4567 eval EXCEPT_${E}=true
4569 for E in $ALWAYS_EXCEPT; do
4570 eval EXCEPT_ALWAYS_${E}=true
4572 for E in $EXCEPT_SLOW; do
4573 eval EXCEPT_SLOW_${E}=true
4575 for G in $GRANT_CHECK_LIST; do
4576 eval GCHECK_ONLY_${G}=true
4581 if [[ $1 = [a-z]* ]]; then
4588 # print a newline if the last test was skipped
4589 export LAST_SKIPPED=
4590 export ALWAYS_SKIPPED=
4592 # Main entry into test-framework. This is called with the name and
4593 # description of a test. The name is used to find the function to run
4594 # the test using "test_$name".
4596 # This supports a variety of methods of specifying specific test to
4597 # run or not run. These need to be documented...
4602 export base=`basetest $1`
4603 if [ ! -z "$ONLY" ]; then
4605 if [ ${!testname}x != x ]; then
4606 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4607 run_one_logged $1 "$2"
4611 if [ ${!testname}x != x ]; then
4612 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4613 run_one_logged $1 "$2"
4623 if [ ${!testname}x != x ]; then
4624 TESTNAME=test_$1 skip "skipping excluded test $1"
4627 testname=EXCEPT_$base
4628 if [ ${!testname}x != x ]; then
4629 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4632 testname=EXCEPT_ALWAYS_$1
4633 if [ ${!testname}x != x ]; then
4634 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4637 testname=EXCEPT_ALWAYS_$base
4638 if [ ${!testname}x != x ]; then
4639 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4642 testname=EXCEPT_SLOW_$1
4643 if [ ${!testname}x != x ]; then
4644 TESTNAME=test_$1 skip "skipping SLOW test $1"
4647 testname=EXCEPT_SLOW_$base
4648 if [ ${!testname}x != x ]; then
4649 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4655 run_one_logged $1 "$2"
4662 module_loaded lnet || load_modules
4674 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4679 strace -o $TMP/$1.strace -ttt $*
4681 log "FINISHED: $*: rc $RC"
4688 banner test complete, duration $duration sec
4689 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4690 echo duration $duration >>$TESTSUITELOG
4694 # Set TEST_STATUS here. It will be used for logging the result.
4697 if [[ -f $LOGDIR/err ]]; then
4699 elif [[ -f $LOGDIR/skip ]]; then
4702 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4706 local FFREE=$(do_node $SINGLEMDS \
4707 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4708 local FTOTAL=$(do_node $SINGLEMDS \
4709 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4711 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4715 echo -n "Resetting fail_loc on all nodes..."
4716 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4722 # Log a message (on all nodes) padded with "=" before and after.
4723 # Also appends a timestamp and prepends the testsuite name.
4726 EQUALS="===================================================================================================="
4728 msg="== ${TESTSUITE} $*"
4730 [[ $last != "=" && $last != " " ]] && msg="$msg "
4731 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4732 # always include at least == after the message
4733 log "$msg== $(date +"%H:%M:%S (%s)")"
4737 # Run a single test function and cleanup after it.
4739 # This function should be run in a subshell so the test func can
4740 # exit() without stopping the whole script.
4745 export tfile=f${testnum}.${TESTSUITE}
4746 export tdir=d${testnum}.${TESTSUITE}
4747 export TESTNAME=test_$testnum
4748 local SAVE_UMASK=`umask`
4751 banner "test $testnum: $message"
4752 test_${testnum} || error "test_$testnum failed with $?"
4755 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4756 check_catastrophe || error "LBUG/LASSERT detected"
4757 if [ "$PARALLEL" != "yes" ]; then
4758 ps auxww | grep -v grep | grep -q multiop &&
4759 error "multiop still running"
4769 # Wrapper around run_one to ensure:
4770 # - test runs in subshell
4771 # - output of test is saved to separate log file for error reporting
4772 # - test result is saved to data file
4775 local BEFORE=`date +%s`
4777 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4778 local test_log=$LOGDIR/$name
4780 rm -rf $LOGDIR/ignore
4782 local SAVE_UMASK=`umask`
4786 log_sub_test_begin test_${1}
4787 (run_one $1 "$2") 2>&1 | tee -i $test_log
4788 local RC=${PIPESTATUS[0]}
4790 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4791 echo "test_$1 returned $RC" | tee $LOGDIR/err
4793 duration=$((`date +%s` - $BEFORE))
4794 pass "$1" "(${duration}s)"
4796 if [[ -f $LOGDIR/err ]]; then
4797 TEST_ERROR=$(cat $LOGDIR/err)
4798 elif [[ -f $LOGDIR/ignore ]]; then
4799 TEST_ERROR=$(cat $LOGDIR/ignore)
4800 elif [[ -f $LOGDIR/skip ]]; then
4801 TEST_ERROR=$(cat $LOGDIR/skip)
4803 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4805 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4809 if [ -f $LOGDIR/err ]; then
4810 $FAIL_ON_ERROR && exit $RC
4819 # Print information of skipped tests to result.yml
4822 log_sub_test_begin $1
4824 log_sub_test_end "SKIP" "0" "0" "$@"
4828 (cd `dirname $1`; echo $PWD/`basename $1`)
4833 export base=`basetest $1`
4834 [ "$CHECK_GRANT" == "no" ] && return 0
4836 testname=GCHECK_ONLY_${base}
4837 [ ${!testname}x == x ] && return 0
4839 echo -n "checking grant......"
4841 local clients=$CLIENTS
4842 [ -z $clients ] && clients=$(hostname)
4844 # sync all the data and make sure no pending data on server
4845 do_nodes $clients sync
4848 client_grant=`do_nodes $clients \
4849 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4850 awk '{total += $1} END{print total}'`
4853 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4854 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4855 awk '{total += $1} END{print total}'`
4857 # check whether client grant == server grant
4858 if [ $client_grant -ne $server_grant ]; then
4859 echo "failed: client:${client_grant} server: ${server_grant}."
4860 do_nodes $(comma_list $(osts_nodes)) \
4861 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4862 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4865 echo "pass: client:${client_grant} server: ${server_grant}"
4870 ########################
4876 ost=`echo $1 | awk -F_ '{print $3}'`
4877 if [ -z $ost ]; then
4878 ost=`echo $1 | sed 's/-osc.*//'`
4883 ostuuid_from_index()
4885 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4888 ostname_from_index() {
4889 local uuid=$(ostuuid_from_index $1)
4893 index_from_ostuuid()
4895 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4898 mdtuuid_from_index()
4900 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4904 # Return unique identifier for given hostname
4907 echo $host_name | md5sum | cut -d' ' -f1
4911 # Returns list of ip addresses for each interface
4913 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4918 # Cache address list to avoid mutiple execution of local_addr_list
4919 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4921 for i in $LOCAL_ADDR_LIST ; do
4922 [[ "$i" == "$addr" ]] && return 0
4929 local is_local="IS_LOCAL_$(host_id $host_name)"
4930 if [ -z "${!is_local-}" ] ; then
4932 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4933 is_local_addr "$host_ip" && eval $is_local=1
4935 [[ "${!is_local}" == "1" ]]
4940 local_node $node && return 1
4947 for node in $(mdts_nodes); do
4948 remote_node $node && return 0
4955 [ "$CLIENTONLY" ] && return 0 || true
4956 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4961 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4962 MSKIPPED=1 && return 1
4969 for node in $(osts_nodes) ; do
4970 remote_node $node && return 0
4977 [ "$CLIENTONLY" ] && return 0 || true
4978 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4983 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4984 OSKIPPED=1 && return 1
4991 MGS=$(facet_host mgs)
4992 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4997 remote_mds_nodsh || remote_ost_nodsh || \
4998 $(single_local_node $(comma_list $(nodes_list)))
5002 remote_ost && remote_mds
5005 # Get the active nodes for facets.
5013 for facet in ${facets//,/ }; do
5014 nodes="$nodes $(facet_active_host $facet)"
5017 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5021 # Get all of the active MDS nodes.
5023 echo -n $(facets_nodes $(get_facets MDS))
5026 # Get all of the active OSS nodes.
5028 echo -n $(facets_nodes $(get_facets OST))
5031 # Get all of the active AGT (HSM agent) nodes.
5033 echo -n $(facets_nodes $(get_facets AGT))
5036 # Get all of the client nodes and active server nodes.
5038 local nodes=$HOSTNAME
5042 # CLIENTS (if specified) contains the local client
5043 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5045 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5046 nodes="$nodes $(facets_nodes $(get_facets))"
5049 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5053 # Get all of the remote client nodes and remote active server nodes.
5054 remote_nodes_list () {
5055 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5058 # Get all of the MDS nodes, including active and passive nodes.
5066 for i in $(seq $MDSCOUNT); do
5068 failover_host=mds${i}failover_HOST
5069 nodes="$nodes ${!host} ${!failover_host}"
5072 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5076 # Get all of the OSS nodes, including active and passive nodes.
5084 for i in $(seq $OSTCOUNT); do
5086 failover_host=ost${i}failover_HOST
5087 nodes="$nodes ${!host} ${!failover_host}"
5090 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5094 # Get all of the server nodes, including active and passive nodes.
5095 all_server_nodes () {
5100 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5102 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5106 # Get all of the client and server nodes, including active and passive nodes.
5108 local nodes=$HOSTNAME
5112 # CLIENTS (if specified) contains the local client
5113 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5115 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5116 nodes="$nodes $(all_server_nodes)"
5119 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5123 init_clients_lists () {
5124 # Sanity check: exclude the local client from RCLIENTS
5125 local clients=$(hostlist_expand "$RCLIENTS")
5126 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5128 # Sanity check: exclude the dup entries
5129 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5131 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5133 # Sanity check: exclude the dup entries from CLIENTS
5134 # for those configs which has SINGLCLIENT set to local client
5135 clients=$(for i in $clients; do echo $i; done | sort -u)
5137 CLIENTS=$(comma_list $clients)
5138 local -a remoteclients=($RCLIENTS)
5139 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5140 varname=CLIENT$((i + 2))
5141 eval $varname=${remoteclients[i]}
5144 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5147 get_random_entry () {
5150 rnodes=${rnodes//,/ }
5152 local -a nodes=($rnodes)
5153 local num=${#nodes[@]}
5154 local i=$((RANDOM * num * 2 / 65536))
5160 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5165 lctl get_param version | grep -q patchless
5169 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5170 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5175 echo $nodes | wc -w || true
5179 local nodes=$(osts_nodes)
5180 local osscount=$(get_node_count "$nodes")
5181 [ ! "$OSTCOUNT" = "$osscount" ]
5185 local nodes=$(mdts_nodes)
5186 local mdtcount=$(get_node_count "$nodes")
5187 [ ! "$MDSCOUNT" = "$mdtcount" ]
5190 generate_machine_file() {
5191 local nodes=${1//,/ }
5192 local machinefile=$2
5194 for node in $nodes; do
5195 echo $node >>$machinefile || \
5196 { echo "can not generate machinefile $machinefile" && return 1; }
5201 local file=$1/stripe
5204 $LFS getstripe -v $file || error "getstripe $file failed"
5208 setstripe_nfsserver () {
5211 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5212 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5214 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5216 do_nodev $nfsserver lfs setstripe "$@"
5219 # Check and add a test group.
5225 local gid=$(getent group $group_name | cut -d: -f3)
5226 if [[ -n "$gid" ]]; then
5227 [[ "$gid" -eq "$group_id" ]] || {
5228 error_noexit "inconsistent group ID:" \
5229 "new: $group_id, old: $gid"
5233 groupadd -g $group_id $group_name
5240 # Check and add a test user.
5253 local uid=$(getent passwd $user_name | cut -d: -f3)
5254 if [[ -n "$uid" ]]; then
5255 if [[ "$uid" -eq "$user_id" ]]; then
5256 local dir=$(getent passwd $user_name | cut -d: -f6)
5257 if [[ "$dir" != "$home" ]]; then
5259 usermod -d $home $user_name
5263 error_noexit "inconsistent user ID:" \
5264 "new: $user_id, old: $uid"
5269 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5276 check_runas_id_ret() {
5278 local myRUNAS_UID=$1
5279 local myRUNAS_GID=$2
5282 if [ -z "$myRUNAS" ]; then
5283 error_exit "myRUNAS command must be specified for check_runas_id"
5286 $myRUNAS krb5_login.sh || \
5287 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5289 mkdir $DIR/d0_runas_test
5291 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5292 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5293 rm -rf $DIR/d0_runas_test
5298 local myRUNAS_UID=$1
5299 local myRUNAS_GID=$2
5302 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5303 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5304 Please set RUNAS_ID to some UID which exists on MDS and client or
5305 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5308 # obtain the UID/GID for MPI_USER
5312 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5313 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5315 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5316 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5319 # obtain and cache Kerberos ticket-granting ticket
5320 refresh_krb5_tgt() {
5321 local myRUNAS_UID=$1
5322 local myRUNAS_GID=$2
5325 if [ -z "$myRUNAS" ]; then
5326 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5329 CLIENTS=${CLIENTS:-$HOSTNAME}
5330 do_nodes $CLIENTS "set -x
5331 if ! $myRUNAS krb5_login.sh; then
5332 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5337 # Run multiop in the background, but wait for it to print
5338 # "PAUSING" to its stdout before returning from this function.
5339 multiop_bg_pause() {
5340 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5344 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5347 echo "$MULTIOP_PROG $FILE v$ARGS"
5348 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5350 echo "TMPPIPE=${TMPPIPE}"
5351 read -t 60 multiop_output < $TMPPIPE
5352 if [ $? -ne 0 ]; then
5357 if [ "$multiop_output" != "PAUSING" ]; then
5358 echo "Incorrect multiop output: $multiop_output"
5373 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5379 inodes_available () {
5380 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5381 sort -un | head -n1) || return 1
5385 mdsrate_inodes_available () {
5386 local min_inodes=$(inodes_available)
5387 echo $((min_inodes * 99 / 100))
5390 # reset llite stat counters
5391 clear_llite_stats(){
5392 lctl set_param -n llite.*.stats 0
5395 # sum llite stat items
5396 calc_llite_stats() {
5397 local res=$(lctl get_param -n llite.*.stats |
5398 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5402 # reset osc stat counters
5404 lctl set_param -n osc.*.osc_stats 0
5407 # sum osc stat items
5409 local res=$(lctl get_param -n osc.*.osc_stats |
5410 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5415 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
5418 calc_osc_kbytes () {
5419 df $MOUNT > /dev/null
5420 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5423 # save_lustre_params(comma separated facet list, parameter_mask)
5424 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5425 save_lustre_params() {
5431 for facet in ${facets//,/ }; do
5432 node=$(facet_active_host $facet)
5433 [[ *\ $node\ * = " $nodes " ]] && continue
5434 nodes="$nodes $node"
5436 do_node $node "$LCTL get_param $2 |
5437 while read s; do echo $facet \\\$s; done"
5441 # restore lustre parameters from input stream, produces by save_lustre_params
5442 restore_lustre_params() {
5447 while IFS=" =" read facet name val; do
5448 do_facet $facet "$LCTL set_param -n $name $val"
5452 check_catastrophe() {
5453 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5454 local C=$CATASTROPHE
5455 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5457 [ -z "$rnodes" ] && return 0
5460 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5461 echo \\\$(< $C) || echo 0);
5462 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5465 if [ -n "$data" ]; then
5472 # CMD: determine mds index where directory inode presents
5475 local file=$dir/f0.get_mds_dir_tmpfile
5480 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5481 local -a oldused=($iused)
5483 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5485 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5486 local -a newused=($iused)
5489 for ((i=0; i<${#newused[@]}; i++)); do
5490 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5496 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5499 mdsrate_cleanup () {
5501 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5502 --nfiles $3 --dir $4 --filefmt $5 $6
5507 delayed_recovery_enabled () {
5508 local var=${SINGLEMDS}_svc
5509 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5512 ########################
5514 convert_facet2label() {
5517 if [ x$facet = xost ]; then
5521 local varsvc=${facet}_svc
5523 if [ -n ${!varsvc} ]; then
5526 error "No lablel for $facet!"
5530 get_clientosc_proc_path() {
5534 get_lustre_version () {
5535 local facet=${1:-"$SINGLEMDS"}
5536 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5539 lustre_version_code() {
5540 local facet=${1:-"$SINGLEMDS"}
5541 version_code $(get_lustre_version $1)
5544 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5545 # used by MDT would not be changed.
5546 # mdt lov: fsname-mdtlov
5547 # mdt osc: fsname-OSTXXXX-osc
5548 mds_on_old_device() {
5549 local mds=${1:-"$SINGLEMDS"}
5551 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5552 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5553 > /dev/null 2>&1" && return 0
5558 get_mdtosc_proc_path() {
5560 local ost_label=${2:-"*OST*"}
5562 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5563 local mdt_label=$(convert_facet2label $mds_facet)
5564 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5566 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5567 mds_on_old_device $mds_facet; then
5568 echo "${ost_label}-osc"
5570 echo "${ost_label}-osc-${mdt_index}"
5574 get_osc_import_name() {
5577 local label=$(convert_facet2label $ost)
5579 if [ "${facet:0:3}" = "mds" ]; then
5580 get_mdtosc_proc_path $facet $label
5584 get_clientosc_proc_path $label
5588 _wait_import_state () {
5591 local maxtime=${3:-$(max_recovery_time)}
5595 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5596 while [ "${CONN_STATE}" != "${expected}" ]; do
5597 if [ "${expected}" == "DISCONN" ]; then
5598 # for disconn we can check after proc entry is removed
5599 [ "x${CONN_STATE}" == "x" ] && return 0
5600 # with AT enabled, we can have connect request timeout near of
5601 # reconnect timeout and test can't see real disconnect
5602 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5604 [ $i -ge $maxtime ] && \
5605 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5608 # Add uniq for multi-mount case
5609 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5613 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5617 wait_import_state() {
5620 local maxtime=${3:-$(max_recovery_time)}
5623 for param in ${params//,/ }; do
5624 _wait_import_state $state $param $maxtime || return
5628 wait_import_state_mount() {
5629 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5633 wait_import_state $*
5636 # One client request could be timed out because server was not ready
5637 # when request was sent by client.
5638 # The request timeout calculation details :
5640 # /* We give the server rq_timeout secs to process the req, and
5641 # add the network latency for our local timeout. */
5642 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5643 # ptlrpc_at_get_net_latency(request) ;
5645 # ptlrpc_connect_import ()
5646 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5649 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5650 # ptlrpc_at_get_net_latency(request) ->
5651 # at_get (max (iat_net_latency=0, at_min)) = at_min
5654 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5655 # INITIAL_CONNECT_TIMEOUT + at_min
5657 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5658 # because we can not get this value in runtime,
5659 # the value depends on configure options, and it is not stored in /proc.
5661 # #define CONNECTION_SWITCH_MIN 5U
5662 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5664 request_timeout () {
5667 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5668 local init_connect_timeout=$TIMEOUT
5669 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5671 local at_min=$(at_get $facet at_min)
5673 echo $(( init_connect_timeout + at_min ))
5676 _wait_osc_import_state() {
5680 local ost=$(get_osc_import_name $facet $ost_facet)
5681 local param="osc.${ost}.ost_server_uuid"
5685 # 1. wait the deadline of client 1st request (it could be skipped)
5686 # 2. wait the deadline of client 2nd request
5687 local maxtime=$(( 2 * $(request_timeout $facet)))
5689 if [[ $facet == client* ]]; then
5690 # During setup time, the osc might not be setup, it need wait
5691 # until list_param can return valid value. And also if there
5692 # are mulitple osc entries we should list all of them before
5694 params=$($LCTL list_param $param 2>/dev/null || true)
5695 while [ -z "$params" ]; do
5696 if [ $i -ge $maxtime ]; then
5697 echo "can't get $param in $maxtime secs"
5702 params=$($LCTL list_param $param 2>/dev/null || true)
5705 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5706 wait_import_state $expected "$params" $maxtime; then
5707 error "import is not in ${expected} state"
5714 wait_osc_import_state() {
5720 if [[ $facet = mds ]]; then
5721 for num in $(seq $MDSCOUNT); do
5722 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5725 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5729 get_clientmdc_proc_path() {
5737 [ -z "$list" ] && return 0
5739 # Add paths to lustre tests for 32 and 64 bit systems.
5740 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5741 local TESTPATH="$RLUSTRE/tests:"
5742 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5743 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5746 wait_clients_import_state () {
5753 if [ "$FAILURE_MODE" = HARD ]; then
5754 facets=$(facets_on_host $(facet_active_host $facet))
5757 for facet in ${facets//,/ }; do
5758 local label=$(convert_facet2label $facet)
5761 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5762 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5763 *) error "unknown facet!" ;;
5765 local params=$(expand_list $params $proc_path)
5768 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5769 error "import is not in ${expected} state"
5779 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5780 $LCTL get_param obdfilter.*.kbytesavail))
5781 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5782 $LCTL get_param -n obdfilter.*.tot_granted))
5783 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5784 $LCTL get_param -n obdfilter.*.kbytestotal))
5785 for ((i=0; i<${#AVAILA[@]}; i++)); do
5786 local -a AVAIL1=(${AVAILA[$i]//=/ })
5787 local -a TOTAL=(${TOTALA[$i]//=/ })
5788 GRANT=$((${GRANTA[$i]}/1024))
5789 # allow 1% of total space in bavail because of delayed
5790 # allocation with ZFS which might release some free space after
5791 # txg commit. For small devices, we set a mininum of 8MB
5792 local LIMIT=$((${TOTAL} / 100 + 8000))
5793 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5794 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5795 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5796 echo " FULL" || echo
5802 do_facet mgs lctl pool_list $1
5806 local fsname=${1%%.*}
5807 local poolname=${1##$fsname.}
5809 do_facet mgs lctl pool_new $1
5811 # get param should return err unless pool is created
5812 [[ $RC -ne 0 ]] && return $RC
5814 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5815 2>/dev/null || echo foo" "" || RC=1
5816 if [[ $RC -eq 0 ]]; then
5819 error "pool_new failed $1"
5824 add_pool_to_list () {
5825 local fsname=${1%%.*}
5826 local poolname=${1##$fsname.}
5828 local listvar=${fsname}_CREATED_POOLS
5829 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5832 remove_pool_from_list () {
5833 local fsname=${1%%.*}
5834 local poolname=${1##$fsname.}
5836 local listvar=${fsname}_CREATED_POOLS
5837 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5840 destroy_pool_int() {
5842 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5843 awk '$1 !~ /^Pool:/ {print $1}')
5844 for ost in $OSTS; do
5845 do_facet mgs lctl pool_remove $1 $ost
5847 do_facet mgs lctl pool_destroy $1
5850 # <fsname>.<poolname> or <poolname>
5852 local fsname=${1%%.*}
5853 local poolname=${1##$fsname.}
5855 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5859 pool_list $fsname.$poolname || return $?
5861 destroy_pool_int $fsname.$poolname
5863 [[ $RC -ne 0 ]] && return $RC
5865 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5866 2>/dev/null || echo foo" "foo" || RC=1
5868 if [[ $RC -eq 0 ]]; then
5869 remove_pool_from_list $fsname.$poolname
5871 error "destroy pool failed $1"
5877 local fsname=${1:-$FSNAME}
5879 local listvar=${fsname}_CREATED_POOLS
5883 [ x${!listvar} = x ] && return 0
5885 echo destroy the created pools: ${!listvar}
5886 for poolname in ${!listvar//,/ }; do
5887 destroy_pool $fsname.$poolname
5892 local fsname=${1:-$FSNAME}
5894 destroy_pools $fsname
5900 local ts=$(date +%s)
5903 if [[ ! -f "$YAML_LOG" ]]; then
5904 # init_logging is not performed before gather_logs,
5905 # so the $LOGDIR needs to be checked here
5906 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5909 [ -f $LOGDIR/shared ] && docp=false
5911 # dump lustre logs, dmesg
5913 prefix="$TESTLOG_PREFIX.$TESTNAME"
5915 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5917 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5918 echo "Dumping logs only on local client."
5919 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5920 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5925 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5926 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5927 if [ ! -f $LOGDIR/shared ]; then
5928 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5941 for i in $(seq 0 $num_mntpts); do
5942 cmd="ls -laf ${mntpt_root}$i/$dir"
5948 for pid in $pids; do
5955 # target_start_and_reset_recovery_timer()
5956 # service_time = at_est2timeout(service_time);
5957 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5958 # INITIAL_CONNECT_TIMEOUT);
5959 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5960 #define CONNECTION_SWITCH_INC 1
5961 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5962 #define CONNECTION_SWITCH_MIN 5U
5964 max_recovery_time () {
5965 local init_connect_timeout=$(( TIMEOUT / 20 ))
5966 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5968 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5973 get_clients_mount_count () {
5974 local clients=${CLIENTS:-`hostname`}
5976 # we need to take into account the clients mounts and
5977 # exclude mds/ost mounts if any;
5978 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5982 PROC_CLI="srpc_info"
5990 if [ $M -lt $N ]; then
5994 while [ $N -lt $M ]; do
6004 calc_connection_cnt() {
6007 # MDT->MDT = 2 * C(M, 2)
6011 comb_m2=$(combination $MDSCOUNT 2)
6013 local num_clients=$(get_clients_mount_count)
6015 local cnt_mdt2mdt=$((comb_m2 * 2))
6016 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6017 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6018 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6019 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6020 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6021 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6035 local cmd="$tgt.srpc.flavor"
6037 if [ $net == "any" ]; then
6042 if [ $dir != "any" ]; then
6047 log "Setting sptlrpc rule: $cmd"
6048 do_facet mgs "$LCTL conf_param $cmd"
6057 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6058 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6060 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6062 if [ "x$bulkspec" != "x" ]; then
6063 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6065 if [ "x$algs" != "x" ]; then
6066 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6068 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6069 if [ $bulk == "bulkn" ]; then
6070 bulk_count=`echo "$output" | grep "bulk flavor" \
6071 | grep "null/null" | wc -l`
6072 elif [ $bulk == "bulki" ]; then
6073 bulk_count=`echo "$output" | grep "bulk flavor" \
6074 | grep "/null" | grep -v "null/" | wc -l`
6076 bulk_count=`echo "$output" | grep "bulk flavor" \
6077 | grep -v "/null" | grep -v "null/" | wc -l`
6081 [ $bulk_count -lt $count ] && count=$bulk_count
6092 local clients=${CLIENTS:-`hostname`}
6094 for c in ${clients//,/ }; do
6095 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6096 tmpcnt=`count_flvr "$output" $flavor`
6097 cnt=$((cnt + tmpcnt))
6107 local clients=${CLIENTS:-`hostname`}
6109 for c in ${clients//,/ }; do
6110 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6111 tmpcnt=`count_flvr "$output" $flavor`
6112 cnt=$((cnt + tmpcnt))
6122 if [ $MDSCOUNT -le 1 ]; then
6127 for num in `seq $MDSCOUNT`; do
6128 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6129 tmpcnt=`count_flvr "$output" $flavor`
6130 cnt=$((cnt + tmpcnt))
6141 for num in `seq $MDSCOUNT`; do
6142 mdtosc=$(get_mdtosc_proc_path mds$num)
6143 mdtosc=${mdtosc/-MDT*/-MDT\*}
6144 output=$(do_facet mds$num lctl get_param -n \
6145 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6146 tmpcnt=`count_flvr "$output" $flavor`
6147 cnt=$((cnt + tmpcnt))
6156 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6157 count_flvr "$output" $flavor
6162 local dir=$1 # from to
6163 local flavor=$2 # flavor expected
6166 if [ $dir == "cli2mdt" ]; then
6167 res=`flvr_cnt_cli2mdt $flavor`
6168 elif [ $dir == "cli2ost" ]; then
6169 res=`flvr_cnt_cli2ost $flavor`
6170 elif [ $dir == "mdt2mdt" ]; then
6171 res=`flvr_cnt_mdt2mdt $flavor`
6172 elif [ $dir == "mdt2ost" ]; then
6173 res=`flvr_cnt_mdt2ost $flavor`
6174 elif [ $dir == "all2ost" ]; then
6175 res1=`flvr_cnt_mdt2ost $flavor`
6176 res2=`flvr_cnt_cli2ost $flavor`
6177 res=$((res1 + res2))
6178 elif [ $dir == "all2mdt" ]; then
6179 res1=`flvr_cnt_mdt2mdt $flavor`
6180 res2=`flvr_cnt_cli2mdt $flavor`
6181 res=$((res1 + res2))
6182 elif [ $dir == "all2all" ]; then
6183 res1=`flvr_cnt_mdt2ost $flavor`
6184 res2=`flvr_cnt_cli2ost $flavor`
6185 res3=`flvr_cnt_mdt2mdt $flavor`
6186 res4=`flvr_cnt_cli2mdt $flavor`
6187 res=$((res1 + res2 + res3 + res4))
6195 local dir=$1 # from to
6196 local flavor=$2 # flavor expected
6197 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6201 for ((i=0;i<20;i++)); do
6202 echo -n "checking $dir..."
6203 res=$(do_check_flavor $dir $flavor)
6204 echo "found $res/$expect $flavor connections"
6205 [ $res -ge $expect ] && return 0
6209 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6213 restore_to_default_flavor()
6215 local proc="mgs.MGS.live.$FSNAME"
6217 echo "restoring to default flavor..."
6219 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6221 # remove all existing rules if any
6222 if [ $nrule -ne 0 ]; then
6223 echo "$nrule existing rules"
6224 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6225 echo "remove rule: $rule"
6226 spec=`echo $rule | awk -F = '{print $1}'`
6227 do_facet mgs "$LCTL conf_param -d $spec"
6231 # verify no rules left
6232 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6233 [ $nrule -ne 0 ] && error "still $nrule rules left"
6235 # wait for default flavor to be applied
6236 # currently default flavor for all connections are 'null'
6237 wait_flavor all2all null
6238 echo "now at default flavor settings"
6243 local flavor=${1:-null}
6245 echo "setting all flavor to $flavor"
6247 # FIXME need parameter to this fn
6248 # and remove global vars
6249 local cnt_all2all=$(calc_connection_cnt all2all)
6251 local res=$(do_check_flavor all2all $flavor)
6252 if [ $res -eq $cnt_all2all ]; then
6253 echo "already have total $res $flavor connections"
6257 echo "found $res $flavor out of total $cnt_all2all connections"
6258 restore_to_default_flavor
6260 [[ $flavor = null ]] && return 0
6262 set_rule $FSNAME any any $flavor
6263 wait_flavor all2all $flavor
6269 # Checking for shared logdir
6270 if [ ! -d $dir ]; then
6271 # Not found. Create local logdir
6274 touch $dir/check_file.$(hostname -s)
6279 check_write_access() {
6281 local list=${2:-$(comma_list $(nodes_list))}
6285 for node in ${list//,/ }; do
6286 file=$dir/check_file.$(short_nodename $node)
6287 if [[ ! -f "$file" ]]; then
6288 # Logdir not accessible/writable from this node.
6291 rm -f $file || return 1
6297 if [[ -n $YAML_LOG ]]; then
6300 local SAVE_UMASK=`umask`
6303 export YAML_LOG=${LOGDIR}/results.yml
6307 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6308 if check_shared_dir $LOGDIR; then
6309 touch $LOGDIR/shared
6310 echo "Logging to shared log directory: $LOGDIR"
6312 echo "Logging to local directory: $LOGDIR"
6315 yml_nodes_file $LOGDIR >> $YAML_LOG
6316 yml_results_file >> $YAML_LOG
6323 yml_log_test $1 >> $YAML_LOG
6327 yml_log_test_status $@ >> $YAML_LOG
6330 log_sub_test_begin() {
6331 yml_log_sub_test_begin "$@" >> $YAML_LOG
6334 log_sub_test_end() {
6335 yml_log_sub_test_end "$@" >> $YAML_LOG
6341 local llverdev_opts=$2
6342 local devname=$(basename $1)
6343 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6344 # loop devices aren't in /proc/partitions
6345 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6347 size=$(($size / 1024 / 1024)) # Gb
6349 local partial_arg=""
6350 # Run in partial (fast) mode if the size
6351 # of a partition > 1 GB
6352 [ $size -gt 1 ] && partial_arg="-p"
6354 llverdev --force $partial_arg $llverdev_opts $dev
6360 local llverfs_opts=$2
6361 local use_partial_arg=$3
6362 local partial_arg=""
6363 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6365 # Run in partial (fast) mode if the size
6366 # of a partition > 1 GB
6367 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6369 llverfs $partial_arg $llverfs_opts $dir
6372 #Remove objects from OST
6373 remove_ost_objects() {
6379 local mntpt=$(facet_mntpt $facet)
6380 local opts=$OST_MOUNT_OPTS
6384 echo "removing objects from $ostdev on $facet: $objids"
6385 if ! test -b $ostdev; then
6386 opts=$(csa_add "$opts" -o loop)
6388 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6391 for i in $objids; do
6392 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6394 umount -f $mntpt || return $?
6398 #Remove files from MDT
6399 remove_mdt_files() {
6404 local mntpt=$(facet_mntpt $facet)
6405 local opts=$MDS_MOUNT_OPTS
6407 echo "removing files from $mdtdev on $facet: $files"
6408 if [ $(facet_fstype $facet) == ldiskfs ] &&
6409 ! do_facet $facet test -b $mdtdev; then
6410 opts=$(csa_add "$opts" -o loop)
6412 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6416 rm $mntpt/ROOT/$f || { rc=$?; break; }
6418 umount -f $mntpt || return $?
6422 duplicate_mdt_files() {
6427 local mntpt=$(facet_mntpt $facet)
6428 local opts=$MDS_MOUNT_OPTS
6430 echo "duplicating files on $mdtdev on $facet: $files"
6431 mkdir -p $mntpt || return $?
6432 if [ $(facet_fstype $facet) == ldiskfs ] &&
6433 ! do_facet $facet test -b $mdtdev; then
6434 opts=$(csa_add "$opts" -o loop)
6436 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6447 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6448 pushd $mntpt/ROOT > /dev/null || return $?
6451 touch $f.bad || return $?
6452 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6454 [ $rc -eq 0 ] || return $rc
6455 setfattr --restore $tmp || return $?
6461 local devs=${1//,/ }
6464 local rslt=$TMP/sgpdd_survey
6466 # sgpdd-survey cleanups ${rslt}.* files
6468 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6474 # returns the canonical name for an ldiskfs device
6479 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6480 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6481 echo dm-\\\${foo##*:};
6483 echo \\\$(basename \\\$dv);
6487 is_sanity_benchmark() {
6488 local benchmarks="dbench bonnie iozone fsx"
6490 for b in $benchmarks; do
6491 if [ "$b" == "$suite" ]; then
6499 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6503 # Get the available size (KB) of a given obd target.
6510 [[ $facet != client ]] || return 0
6512 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6517 # Get the page size (bytes) on a given facet node.
6523 size=$(do_facet $facet getconf PAGE_SIZE)
6524 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6529 # Get the block count of the filesystem.
6536 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6537 awk '/^Block count:/ {print $3}')
6541 # Get the block size of the filesystem.
6547 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6548 awk '/^Block size:/ {print $3}')
6552 # Check whether the "large_xattr" feature is enabled or not.
6553 large_xattr_enabled() {
6554 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6556 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6558 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6559 grep -E -q '(ea_inode|large_xattr)'"
6560 return ${PIPESTATUS[0]}
6563 # Get the maximum xattr size supported by the filesystem.
6567 if large_xattr_enabled; then
6568 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6571 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6572 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6574 # maximum xattr size = size of block - size of header -
6575 # size of 1 entry - 4 null bytes
6576 size=$((block_size - 32 - 32 - 4))
6582 # Dump the value of the named xattr from a file.
6587 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6590 # Generate a string with size of $size bytes.
6592 local size=${1:-1024} # in bytes
6594 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6597 reformat_external_journal() {
6600 if [ ! -z ${EJOURNAL} ]; then
6601 local rcmd="do_facet $facet"
6603 echo "reformat external journal on $facet:${EJOURNAL}"
6604 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6608 # MDT file-level backup/restore
6609 mds_backup_restore() {
6612 local devname=$(mdsdevname $(facet_number $facet))
6613 local mntpt=$(facet_mntpt brpt)
6614 local rcmd="do_facet $facet"
6615 local metaea=${TMP}/backup_restore.ea
6616 local metadata=${TMP}/backup_restore.tgz
6617 local opts=${MDS_MOUNT_OPTS}
6618 local svc=${facet}_svc
6620 if ! ${rcmd} test -b ${devname}; then
6621 opts=$(csa_add "$opts" -o loop)
6624 echo "file-level backup/restore on $facet:${devname}"
6626 # step 1: build mount point
6627 ${rcmd} mkdir -p $mntpt
6628 # step 2: cleanup old backup
6629 ${rcmd} rm -f $metaea $metadata
6631 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6632 if [ ! -z $igif ]; then
6633 # step 3.5: rm .lustre
6634 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6636 # step 4: backup metaea
6638 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6640 # step 5: backup metadata
6642 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6644 ${rcmd} umount -d $mntpt || return 4
6645 # step 7: reformat external journal if needed
6646 reformat_external_journal $facet || return 5
6647 # step 8: reformat dev
6648 echo "reformat new device"
6649 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6650 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6651 > /dev/null || exit 6
6653 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6654 # step 10: restore metadata
6656 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6657 # step 11: restore metaea
6659 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6660 # step 12: remove recovery logs
6661 echo "remove recovery logs"
6662 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6663 # step 13: umount dev
6664 ${rcmd} umount -d $mntpt || return 10
6665 # step 14: cleanup tmp backup
6666 ${rcmd} rm -f $metaea $metadata
6667 # step 15: reset device label - it's not virgin on
6668 ${rcmd} e2label $devname ${!svc}
6675 local devname=$(mdsdevname $(facet_number $facet))
6676 local mntpt=$(facet_mntpt brpt)
6677 local rcmd="do_facet $facet"
6678 local opts=${MDS_MOUNT_OPTS}
6680 if ! ${rcmd} test -b ${devname}; then
6681 opts=$(csa_add "$opts" -o loop)
6684 echo "removing OI files on $facet: idx=${idx}"
6686 # step 1: build mount point
6687 ${rcmd} mkdir -p $mntpt
6689 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6690 if [ -z $idx ]; then
6691 # step 3: remove all OI files
6692 ${rcmd} rm -fv $mntpt/oi.16*
6693 elif [ $idx -lt 2 ]; then
6694 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6698 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6699 for ((i=${idx}; i<64; i=$((i * idx)))); do
6700 ${rcmd} rm -fv $mntpt/oi.16.${i}
6704 ${rcmd} umount -d $mntpt || return 2
6705 # OI files will be recreated when mounted as lustre next time.
6708 # generate maloo upload-able log file name
6709 # \param logname specify unique part of file name
6710 generate_logname() {
6711 local logname=${1:-"default_logname"}
6713 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6716 # make directory on different MDTs
6724 local stripe_count=2
6734 *) error "Only creating single directory is supported";;
6737 child=$(basename $path)
6738 parent=$(dirname $path)
6740 if [ "$option" == "-p" -o "$option2" == "-p" ]; then
6741 if [ -d $parent/$child ]; then
6747 if [ "${option:0:2}" == "-c" ]; then
6748 stripe_count=$(echo $option | sed 's/^-c//')
6751 if [ "${option2:0:2}" == "-c" ]; then
6752 stripe_count=$(echo $option2 | sed 's/^-c//')
6755 if [ ! -d ${parent} ]; then
6756 if [ "$p_option" == "-p" ]; then
6763 if [ $MDSCOUNT -le 1 ]; then
6764 mkdir $p_option $parent/$child || rc=$?
6766 local mdt_idx=$($LFS getstripe -M $parent)
6767 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6769 mdt_idx=$((test_num % MDSCOUNT))
6770 echo "striped dir -i$mdt_idx -c$stripe_count $path"
6771 $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
6776 # find the smallest and not in use file descriptor
6779 local max_fd=$(ulimit -n)
6781 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6784 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"