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}
1192 if [[ $facet == mds* ]]; then
1194 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1205 local HOST=`facet_active_host $facet`
1206 [ -z $HOST ] && echo stop: no host for $facet && return 0
1208 local mntpt=$(facet_mntpt $facet)
1209 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1210 if [ ${running} -ne 0 ]; then
1211 echo "Stopping $mntpt (opts:$@) on $HOST"
1212 do_facet ${facet} umount -d $@ $mntpt
1215 # umount should block, but we should wait for unrelated obd's
1216 # like the MGS or MGC to also stop.
1217 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1219 if [[ $(facet_fstype $facet) == zfs ]]; then
1220 # export ZFS storage pool
1225 # save quota version (both administrative and operational quotas)
1226 # add an additional parameter if mountpoint is ever different from $MOUNT
1228 # XXX This function is kept for interoperability with old server (< 2.3.50),
1229 # it should be removed whenever we drop the interoperability for such
1231 quota_save_version() {
1232 local fsname=${2:-$FSNAME}
1234 local ver=$(tr -c -d "123" <<< $spec)
1235 local type=$(tr -c -d "ug" <<< $spec)
1237 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1239 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1241 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1243 local osts=$(get_facets OST)
1244 for ost in ${osts//,/ }; do
1246 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1250 # client could mount several lustre
1252 # XXX This function is kept for interoperability with old server (< 2.3.50),
1253 # it should be removed whenever we drop the interoperability for such
1256 local fsname=${1:-$FSNAME}
1258 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1260 do_nodes $(comma_list $(osts_nodes)) \
1261 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1265 # XXX This function is kept for interoperability with old server (< 2.3.50),
1266 # it should be removed whenever we drop the interoperability for such
1268 restore_quota_old() {
1269 local mntpt=${1:-$MOUNT}
1270 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1271 if [ ! "$old_QUOTA_TYPE" ] ||
1272 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1275 quota_save_version $old_QUOTA_TYPE
1278 # XXX This function is kept for interoperability with old server (< 2.3.50),
1279 # it should be removed whenever we drop the interoperability for such
1284 # no quota enforcement for now and accounting works out of the box
1287 # We need save the original quota_type params, and restore them after testing
1289 # Suppose that quota type the same on mds and ost
1290 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1291 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1292 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1293 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1294 export old_QUOTA_TYPE=$quota_type
1295 quota_save_version $QUOTA_TYPE
1297 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1298 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1301 local quota_usrs=$QUOTA_USERS
1303 # get_filesystem_size
1304 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1305 local blk_soft=$((disksz + 1024))
1306 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1308 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1309 local i_soft=$Inodes
1310 local i_hard=$((i_soft + i_soft / 20))
1312 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1313 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1316 for usr in $quota_usrs; do
1317 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1319 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1321 eval $cmd || error "$cmd FAILED!"
1323 # display the quota status
1324 echo "Quota settings for $usr : "
1325 $LFS quota -v -u $usr $mntpt || true
1329 # get mdt quota type
1331 local varsvc=${SINGLEMDS}_svc
1332 do_facet $SINGLEMDS $LCTL get_param -n \
1333 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1336 # get ost quota type
1338 # All OSTs should have same quota type
1339 local varsvc=ost1_svc
1340 do_facet ost1 $LCTL get_param -n \
1341 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1344 # restore old quota type settings
1346 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1351 if [ "$old_MDT_QUOTA_TYPE" ]; then
1352 do_facet mgs $LCTL conf_param \
1353 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1355 if [ "$old_OST_QUOTA_TYPE" ]; then
1356 do_facet mgs $LCTL conf_param \
1357 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1361 # Handle the case when there is a space in the lfs df
1362 # "filesystem summary" line the same as when there is no space.
1363 # This will allow fixing the "lfs df" summary line in the future.
1365 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1368 # Get free inodes on the MDT specified by mdt index, free indoes on
1369 # the whole filesystem will be returned when index == -1.
1375 if [ $index -eq -1 ]; then
1378 mdt_uuid=$(mdtuuid_from_index $index)
1381 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1386 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1393 # save old quota type & set new quota type
1394 local mdt_qtype=$(mdt_quota_type)
1395 local ost_qtype=$(ost_quota_type)
1397 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1398 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1400 export old_MDT_QUOTA_TYPE=$mdt_qtype
1401 export old_OST_QUOTA_TYPE=$ost_qtype
1403 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1404 error "set mdt quota type failed"
1405 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1406 error "set ost quota type failed"
1408 local quota_usrs=$QUOTA_USERS
1410 # get_filesystem_size
1411 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1412 local blk_soft=$((disksz + 1024))
1413 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1415 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1416 local i_soft=$inodes
1417 local i_hard=$((i_soft + i_soft / 20))
1419 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1420 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1421 "inode-hardlimit: $i_hard"
1424 for usr in $quota_usrs; do
1425 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1427 cmd="$LFS setquota -$type $usr -b $blk_soft"
1428 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1430 eval $cmd || error "$cmd FAILED!"
1432 # display the quota status
1433 echo "Quota settings for $usr : "
1434 $LFS quota -v -u $usr $mntpt || true
1441 local OPTIONS=${3:-$MOUNTOPT}
1443 local device=$MGSNID:/$FSNAME
1444 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1445 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1449 echo "Starting client: $client: $OPTIONS $device $mnt"
1450 do_node $client mkdir -p $mnt
1451 do_node $client $MOUNT_CMD $OPTIONS $device $mnt || return 1
1453 set_default_debug_nodes $client
1465 [ "$3" ] && force=-f
1466 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1467 if [ $running -ne 0 ]; then
1468 echo "Stopping client $client $mnt (opts:$force)"
1469 do_node $client lsof -t $mnt || need_kill=no
1470 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1471 pids=$(do_node $client lsof -t $mnt | sort -u);
1472 if [ -n $pids ]; then
1473 do_node $client kill -9 $pids || true
1477 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1478 if [ $busy -ne 0 ] ; then
1479 echo "$mnt is still busy, wait one second" && sleep 1
1480 do_node $client umount $force $mnt
1485 # nodes is comma list
1486 sanity_mount_check_nodes () {
1492 # FIXME: assume that all cluster nodes run the same os
1493 [ "$(uname)" = Linux ] || return 0
1496 for mnt in $mnts ; do
1497 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1498 mpts=\\\$(mount | grep -c $mnt' ');
1499 if [ \\\$running -ne \\\$mpts ]; then
1500 echo \\\$(hostname) env are INSANE!;
1503 [ $? -eq 0 ] || rc=1
1508 sanity_mount_check_servers () {
1509 [ "$CLIENTONLY" ] &&
1510 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1511 echo Checking servers environments
1513 # FIXME: modify get_facets to display all facets wo params
1514 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1518 for facet in ${facets//,/ }; do
1519 node=$(facet_host ${facet})
1520 mntpt=$(facet_mntpt $facet)
1521 sanity_mount_check_nodes $node $mntpt ||
1522 { error "server $node environments are insane!"; return 1; }
1526 sanity_mount_check_clients () {
1527 local clients=${1:-$CLIENTS}
1528 local mntpt=${2:-$MOUNT}
1529 local mntpt2=${3:-$MOUNT2}
1531 [ -z $clients ] && clients=$(hostname)
1532 echo Checking clients $clients environments
1534 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1535 error "clients environments are insane!"
1538 sanity_mount_check () {
1539 sanity_mount_check_servers || return 1
1540 sanity_mount_check_clients || return 2
1543 # mount clients if not mouted
1544 zconf_mount_clients() {
1547 local OPTIONS=${3:-$MOUNTOPT}
1549 local device=$MGSNID:/$FSNAME
1550 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1551 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1555 echo "Starting client $clients: $OPTIONS $device $mnt"
1558 running=\\\$(mount | grep -c $mnt' ');
1560 if [ \\\$running -eq 0 ] ; then
1562 $MOUNT_CMD $OPTIONS $device $mnt;
1565 exit \\\$rc" || return ${PIPESTATUS[0]}
1567 echo "Started clients $clients: "
1568 do_nodes $clients "mount | grep $mnt' '"
1570 set_default_debug_nodes $clients
1575 zconf_umount_clients() {
1580 [ "$3" ] && force=-f
1582 echo "Stopping clients: $clients $mnt (opts:$force)"
1583 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1584 if [ \\\$running -ne 0 ] ; then
1585 echo Stopping client \\\$(hostname) $mnt opts:$force;
1586 lsof $mnt || need_kill=no;
1587 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1588 pids=\\\$(lsof -t $mnt | sort -u);
1589 if [ -n \\\"\\\$pids\\\" ]; then
1593 while umount $force $mnt 2>&1 | grep -q "busy"; do
1594 echo "$mnt is still busy, wait one second" && sleep 1;
1601 echo + $POWER_DOWN $node
1605 shutdown_node_hard () {
1607 local attempts=$SHUTDOWN_ATTEMPTS
1609 for i in $(seq $attempts) ; do
1612 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1613 echo "waiting for $host to fail attempts=$attempts"
1614 [ $i -lt $attempts ] || \
1615 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1621 local mnt=${2:-$MOUNT}
1624 if [ "$FAILURE_MODE" = HARD ]; then
1625 shutdown_node_hard $client
1627 zconf_umount_clients $client $mnt -f
1633 local facets="$(get_facets OST),$(get_facets MDS)"
1636 combined_mgs_mds || facets="$facets,mgs"
1638 for facet in ${facets//,/ }; do
1639 if [ $(facet_active_host $facet) == $host ]; then
1640 affected="$affected $facet"
1644 echo $(comma_list $affected)
1649 local host=${2:-$(facet_host $facet)}
1651 local label=$(convert_facet2label $facet)
1652 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1655 facets_up_on_host () {
1657 local facets=$(facets_on_host $host)
1660 for facet in ${facets//,/ }; do
1661 if $(facet_up $facet $host); then
1662 affected_up="$affected_up $facet"
1666 echo $(comma_list $affected_up)
1672 if [ "$FAILURE_MODE" = HARD ]; then
1673 shutdown_node_hard $(facet_active_host $facet)
1681 echo + $POWER_UP $node
1694 if [ "$FAILURE_MODE" = HARD ]; then
1695 reboot_node $(facet_active_host $facet)
1703 if [ "$FAILURE_MODE" = HARD ]; then
1713 for facet in ${facets//,/ }; do
1714 hosts=$(expand_list $hosts $(facet_host $facet) )
1720 _check_progs_installed () {
1724 for prog in $progs; do
1725 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1726 echo $prog missing on $(hostname)
1733 check_progs_installed () {
1737 do_rpc_nodes "$nodes" _check_progs_installed $@
1740 # recovery-scale functions
1742 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1745 start_client_load() {
1748 local var=$(node_var_name $client)_load
1749 eval export ${var}=$load
1751 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1752 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1753 END_RUN_FILE=$END_RUN_FILE \
1754 LOAD_PID_FILE=$LOAD_PID_FILE \
1755 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1756 TESTNAME=$TESTNAME \
1757 DBENCH_LIB=$DBENCH_LIB \
1758 DBENCH_SRC=$DBENCH_SRC \
1759 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1763 log "Started client load: ${load} on $client"
1765 # get the children process IDs
1766 local pids=$(ps --ppid $ppid -o pid= | xargs)
1767 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1771 start_client_loads () {
1772 local -a clients=(${1//,/ })
1773 local numloads=${#CLIENT_LOADS[@]}
1776 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1777 testnum=$((nodenum % numloads))
1778 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1780 # bug 22169: wait the background threads to start
1784 # only for remote client
1785 check_client_load () {
1787 local var=$(node_var_name $client)_load
1788 local TESTLOAD=run_${!var}.sh
1790 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1792 # bug 18914: try to connect several times not only when
1793 # check ps, but while check_catastrophe also
1796 while [ $RC = 254 -a $tries -gt 0 ]; do
1800 if ! check_catastrophe $client; then
1802 if [ $RC -eq 254 ]; then
1803 # FIXME: not sure how long we shuold sleep here
1807 echo "check catastrophe failed: RC=$RC "
1811 # We can continue try to connect if RC=254
1812 # Just print the warning about this
1813 if [ $RC = 254 ]; then
1814 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1817 # see if the load is still on the client
1820 while [ $RC = 254 -a $tries -gt 0 ]; do
1824 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1829 if [ $RC = 254 ]; then
1830 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1831 # see if we can diagnose a bit why this is
1836 check_client_loads () {
1837 local clients=${1//,/ }
1841 for client in $clients; do
1842 check_client_load $client
1844 if [ "$rc" != 0 ]; then
1845 log "Client load failed on node $client, rc=$rc"
1851 restart_client_loads () {
1852 local clients=${1//,/ }
1853 local expectedfail=${2:-""}
1857 for client in $clients; do
1858 check_client_load $client
1860 if [ "$rc" != 0 -a "$expectedfail" ]; then
1861 local var=$(node_var_name $client)_load
1862 start_client_load $client ${!var}
1863 echo "Restarted client load ${!var}: on $client. Checking ..."
1864 check_client_load $client
1866 if [ "$rc" != 0 ]; then
1867 log "Client load failed to restart on node $client, rc=$rc"
1868 # failure one client load means test fail
1869 # we do not need to check other
1878 # Start vmstat and save its process ID in a file.
1883 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1886 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1887 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1890 # Display the nodes on which client loads failed.
1891 print_end_run_file() {
1895 [ -s $file ] || return 0
1897 echo "Found the END_RUN_FILE file: $file"
1900 # A client load will stop if it finds the END_RUN_FILE file.
1901 # That does not mean the client load actually failed though.
1902 # The first node in END_RUN_FILE is the one we are interested in.
1905 if [ -n "$node" ]; then
1906 local var=$(node_var_name $node)_load
1908 local prefix=$TESTLOG_PREFIX
1909 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1910 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1911 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1913 echo "Client load ${!var} failed on node $node:"
1919 # Stop the process which had its PID saved in a file.
1924 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1926 do_nodes $nodes "test -f $pid_file &&
1927 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1930 # Stop all client loads.
1931 stop_client_loads() {
1932 local nodes=${1:-$CLIENTS}
1935 # stop the client loads
1936 stop_process $nodes $pid_file
1938 # clean up the processes that started them
1939 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1941 # End recovery-scale functions
1943 # verify that lustre actually cleaned up properly
1945 [ -f "$CATASTROPHE" ] && [[ $(< $CATASTROPHE) -ne 0 ]] &&
1946 error "LBUG/LASSERT detected"
1947 BUSY=$(dmesg | grep -i destruct || true)
1948 if [ -n "$BUSY" ]; then
1950 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
1954 check_mem_leak || exit 204
1956 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
1957 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1960 if module_loaded lnet || module_loaded libcfs; then
1961 echo "$TESTSUITE: modules still loaded..." 1>&2
1970 if [[ "$1" == "--verbose" ]]; then
1985 PREV_RESULT=$(do_node $node "$TEST")
1987 RESULT=$(do_node $node "$TEST")
1988 if [[ "$RESULT" == "$FINAL" ]]; then
1989 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1990 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1994 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1995 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1999 [[ $WAIT -ge $MAX ]] && break
2000 [[ $((WAIT % print)) -eq 0 ]] &&
2001 echo "Waiting $((MAX - WAIT)) secs for update"
2002 WAIT=$((WAIT + sleep))
2005 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2009 wait_update_facet() {
2012 wait_update $(facet_active_host $facet) "$@"
2016 do_nodes $(comma_list $(mdts_nodes)) \
2017 "lctl set_param -n osd*.*MDT*.force_sync 1"
2018 do_nodes $(comma_list $(osts_nodes)) \
2019 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2020 grep -v 'Found no match'
2023 wait_delete_completed_mds() {
2024 local MAX_WAIT=${1:-20}
2026 local stime=$(date +%s)
2031 # find MDS with pending deletions
2032 for node in $(mdts_nodes); do
2033 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2034 2>/dev/null | calc_sum)
2035 if [[ $changes -eq 0 ]]; then
2038 mds2sync="$mds2sync $node"
2040 if [ -z "$mds2sync" ]; then
2043 mds2sync=$(comma_list $mds2sync)
2045 # sync MDS transactions
2046 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2048 # wait till all changes are sent and commmitted by OSTs
2049 # for ldiskfs space is released upon execution, but DMU
2050 # do this upon commit
2053 while [[ $WAIT -ne $MAX_WAIT ]]; do
2054 changes=$(do_nodes $mds2sync \
2055 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2056 #echo "$node: $changes changes on all"
2057 if [[ $changes -eq 0 ]]; then
2059 #echo "delete took $((etime - stime)) seconds"
2067 echo "Delete is not completed in $((etime - stime)) seconds"
2068 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2074 # we can use "for" here because we are waiting the slowest
2075 for host in ${hostlist//,/ }; do
2076 check_network "$host" 900
2078 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2085 for facet in ${facetlist//,/ }; do
2086 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2088 wait_for_host $hostlist
2091 _wait_recovery_complete () {
2094 # Use default policy if $2 is not passed by caller.
2095 local MAX=${2:-$(max_recovery_time)}
2100 while [ $WAIT -lt $MAX ]; do
2101 STATUS=$(lctl get_param -n $param | grep status)
2103 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2106 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2108 echo "$param recovery not done in $MAX sec. $STATUS"
2112 wait_recovery_complete () {
2115 # with an assumption that at_max is the same on all nodes
2116 local MAX=${2:-$(max_recovery_time)}
2119 if [ "$FAILURE_MODE" = HARD ]; then
2120 facets=$(facets_on_host $(facet_active_host $facet))
2122 echo affected facets: $facets
2124 # we can use "for" here because we are waiting the slowest
2125 for facet in ${facets//,/ }; do
2126 local var_svc=${facet}_svc
2127 local param="*.${!var_svc}.recovery_status"
2129 local host=$(facet_active_host $facet)
2130 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2134 wait_mds_ost_sync () {
2135 # just because recovery is done doesn't mean we've finished
2136 # orphan cleanup. Wait for llogs to get synchronized.
2137 echo "Waiting for orphan cleanup..."
2138 # MAX value includes time needed for MDS-OST reconnection
2139 local MAX=$(( TIMEOUT * 2 ))
2140 local WAIT_TIMEOUT=${1:-$MAX}
2143 local list=$(comma_list $(mdts_nodes))
2144 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2145 if ! do_facet $SINGLEMDS \
2146 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2148 # old way, use mds_sync
2150 list=$(comma_list $(osts_nodes))
2151 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2154 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2155 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2156 local -a sync=($(do_nodes $list "$cmd"))
2159 for ((i=0; i<${#sync[@]}; i++)); do
2161 [ ${sync[$i]} -eq 1 ] && continue
2163 [ ${sync[$i]} -eq 0 ] && continue
2165 # there is a not finished MDS-OST synchronization
2169 sleep 2 # increase waiting time and cover statfs cache
2170 [ ${con} -eq 1 ] && return 0
2171 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2175 # show which nodes are not finished.
2176 do_nodes $list "$cmd"
2177 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2181 wait_destroy_complete () {
2182 echo "Waiting for local destroys to complete"
2183 # MAX value shouldn't be big as this mean server responsiveness
2184 # never increase this just to make test pass but investigate
2185 # why it takes so long time
2188 while [ $WAIT -lt $MAX ]; do
2189 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2193 for ((i=0; i<${#RPCs[@]}; i++)); do
2194 [ ${RPCs[$i]} -eq 0 ] && continue
2195 # there are still some destroy RPCs in flight
2200 [ ${con} -eq 1 ] && return 0 # done waiting
2201 echo "Waiting ${WAIT}s for local destroys to complete"
2204 echo "Local destroys weren't done in $MAX sec."
2208 wait_delete_completed() {
2209 wait_delete_completed_mds $1 || return $?
2210 wait_destroy_complete
2219 # conf-sanity 31 takes a long time cleanup
2220 while [ $WAIT -lt 300 ]; do
2221 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2222 [ -z "${running}" ] && return 0
2223 echo "waited $WAIT for${running}"
2224 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2226 WAIT=$((WAIT + INTERVAL))
2228 echo "service didn't stop after $WAIT seconds. Still running:"
2233 wait_remote_prog () {
2239 [ "$PDSH" = "no_dsh" ] && return 0
2241 while [ $WAIT -lt $2 ]; do
2242 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2243 [ -z "${running}" ] && return 0 || true
2244 echo "waited $WAIT for: "
2246 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2248 WAIT=$((WAIT + INTERVAL))
2250 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2251 [ -z "$pids" ] && return 0
2252 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2253 # FIXME: not portable
2254 for pid in $pids; do
2255 cat /proc/${pid}/status || true
2256 cat /proc/${pid}/wchan || true
2258 kill -9 $pid || true
2267 # not every config has many clients
2269 if [ ! -z "$CLIENTS" ]; then
2270 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2272 stat -f $MOUNT > /dev/null
2278 # usually checked on particular client or locally
2280 if [ ! -z "$client" ]; then
2281 $PDSH $client "stat -f $MOUNT" > /dev/null
2283 stat -f $MOUNT > /dev/null
2291 client_reconnect_try() {
2292 uname -n >> $MOUNT/recon
2293 if [ -z "$CLIENTS" ]; then
2294 df $MOUNT; uname -n >> $MOUNT/recon
2296 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2298 echo Connected clients:
2300 ls -l $MOUNT/recon > /dev/null
2304 client_reconnect() {
2305 # one client_reconnect_try call does not always do the job...
2307 client_reconnect_try && break
2312 affected_facets () {
2315 local host=$(facet_active_host $facet)
2316 local affected=$facet
2318 if [ "$FAILURE_MODE" = HARD ]; then
2319 affected=$(facets_up_on_host $host)
2333 #Because it will only get up facets, we need get affected
2334 #facets before shutdown
2335 #For HARD Failure mode, it needs make sure facets on the same
2336 #HOST will only be shutdown and reboot once
2337 for facet in ${facets//,/ }; do
2338 local affected_facet
2340 #check whether facet has been included in other affected facets
2341 for ((index=0; index<$total; index++)); do
2342 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2345 if [ $skip -eq 0 ]; then
2346 affecteds[$total]=$(affected_facets $facet)
2351 for ((index=0; index<$total; index++)); do
2352 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2353 local host=$(facet_active_host $facet)
2354 echo "Failing ${affecteds[index]} on $host"
2355 shutdown_facet $facet
2358 for ((index=0; index<$total; index++)); do
2359 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2360 echo reboot facets: ${affecteds[index]}
2364 change_active ${affecteds[index]}
2366 wait_for_facet ${affecteds[index]}
2367 # start mgs first if it is affected
2368 if ! combined_mgs_mds &&
2369 list_member ${affecteds[index]} mgs; then
2370 mount_facet mgs || error "Restart of mgs failed"
2372 # FIXME; has to be changed to mount all facets concurrently
2373 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2374 echo mount facets: ${affecteds[index]}
2375 mount_facets ${affecteds[index]}
2385 do_facet $facet "sync; sync; sync"
2388 # make sure there will be no seq change
2389 local clients=${CLIENTS:-$HOSTNAME}
2390 local f=fsa-\\\$\(hostname\)
2391 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2392 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2394 local svc=${facet}_svc
2395 do_facet $facet $LCTL --device ${!svc} notransno
2397 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2398 # in-memory state has to be cleared by either rebooting the host or
2399 # exporting and reimporting the pool.
2401 # Although the uberblocks are not updated when a pool is freezed,
2402 # transactions are still written to the disks. Modified blocks may be
2403 # cached in memory when tests try reading them back. The
2404 # export-and-reimport process also evicts any cached pool data from
2405 # memory to provide the correct "data loss" semantics.
2407 # In the test framework, the exporting and importing operations are
2408 # handled by stop() and mount_facet() separately, which are used
2409 # inside fail() and fail_abort().
2411 do_facet $facet $LCTL --device ${!svc} readonly
2412 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2413 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2416 replay_barrier_nodf() {
2417 local facet=$1 echo running=${running}
2418 do_facet $facet "sync; sync; sync"
2419 local svc=${facet}_svc
2420 echo Replay barrier on ${!svc}
2421 do_facet $facet $LCTL --device ${!svc} notransno
2422 do_facet $facet $LCTL --device ${!svc} readonly
2423 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2424 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2427 replay_barrier_nosync() {
2428 local facet=$1 echo running=${running}
2429 local svc=${facet}_svc
2430 echo Replay barrier on ${!svc}
2431 do_facet $facet $LCTL --device ${!svc} notransno
2432 do_facet $facet $LCTL --device ${!svc} readonly
2433 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2434 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2438 # Get Lustre client uuid for a given Lustre mount point.
2441 local mntpnt=${1:-$MOUNT}
2443 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2444 local uuid=$($LCTL get_param -n llite.$name.uuid)
2449 mds_evict_client() {
2450 local mntpnt=${1:-$MOUNT}
2451 local uuid=$(get_client_uuid $mntpnt)
2453 do_facet $SINGLEMDS \
2454 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2457 ost_evict_client() {
2458 local mntpnt=${1:-$MOUNT}
2459 local uuid=$(get_client_uuid $mntpnt)
2462 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2467 local clients=${CLIENTS:-$HOSTNAME}
2469 facet_failover $* || error "failover: $?"
2470 wait_clients_import_state "$clients" "$facets" FULL
2471 clients_up || error "post-failover df: $?"
2476 facet_failover $facet
2482 change_active $facet
2483 wait_for_facet $facet
2484 mount_facet $facet -o abort_recovery
2485 clients_up || echo "first df failed: $?"
2486 clients_up || error "post-failover df: $?"
2490 echo There is no lmc. This is mountconf, baby.
2494 host_nids_address() {
2498 if [ -n "$kind" ]; then
2499 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2501 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2507 if [ "$1" = "'*'" ]; then echo \'*\'; else
2513 if [ "$1" = "'*'" ]; then echo \'*\'; else
2514 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2516 if [ -z "$ID" ]; then
2517 echo "Could not get a ptl id for $1..."
2526 h2name_or_ip "$1" "tcp"
2531 if [ "$1" = "'*'" ]; then echo \'*\'; else
2532 if type __h2elan >/dev/null 2>&1; then
2535 ID=`echo $1 | sed 's/[^0-9]*//g'`
2543 h2name_or_ip "$1" "o2ib"
2547 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2548 # expressions format. As a bonus we can then just pass in those variables
2549 # to pdsh. What this function does is take a HOSTLIST type string and
2550 # expand it into a space deliminated list for us.
2558 [ -z "$hostlist" ] && return
2560 # Translate the case of [..],..,[..] to [..] .. [..]
2561 list="${hostlist/],/] }"
2563 [[ "$front" == *,* ]] && {
2566 list=${list/${old}/${new}}
2569 for item in $list; do
2570 # Test if we have any []'s at all
2571 if [ "$item" != "${item/\[/}" ]; then {
2572 # Expand the [*] into list
2576 if [ "$name" != "$item" ]; then
2577 group=${item#$name[*}
2580 for range in ${group//,/ }; do
2584 # Number of leading zeros
2587 end=$(echo $end | sed 's/0*//')
2588 [[ -z "$end" ]] && end=0
2589 [[ $padlen2 -gt $padlen ]] && {
2590 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2593 begin=$(echo $begin | sed 's/0*//')
2594 [ -z $begin ] && begin=0
2596 for num in $(seq -f "%0${padlen}g" $begin $end); do
2597 value="${name#*,}${num}${back}"
2598 [ "$value" != "${value/\[/}" ] && {
2599 value=$(hostlist_expand "$value")
2601 myList="$myList $value"
2606 myList="$myList $item"
2609 myList=${myList//,/ }
2610 myList=${myList:1} # Remove first character which is a space
2612 # Filter any duplicates without sorting
2614 myList="${list%% *}"
2616 while [[ "$list" != ${myList##* } ]]; do
2617 list=${list//${list%% *} /}
2618 myList="$myList ${list%% *}"
2620 myList="${myList%* }";
2622 # We can select an object at a offset in the list
2625 for item in $myList; do
2627 [ $cnt -eq $offset ] && {
2631 [ $(get_node_count $myList) -ne 1 ] && myList=""
2640 [ "$facet" == client ] && echo -n $HOSTNAME && return
2641 varname=${facet}_HOST
2642 if [ -z "${!varname}" ]; then
2643 if [ "${facet:0:3}" == "ost" ]; then
2644 local fh=${facet%failover}_HOST
2645 eval export ${facet}_HOST=${!fh}
2646 if [ -z "${!varname}" ]; then
2647 eval export ${facet}_HOST=${ost_HOST}
2649 elif [ "${facet:0:3}" == "mdt" -o \
2650 "${facet:0:3}" == "mds" -o \
2651 "${facet:0:3}" == "mgs" ]; then
2652 eval export ${facet}_HOST=${mds_HOST}
2658 facet_failover_host() {
2662 var=${facet}failover_HOST
2663 if [ -n "${!var}" ]; then
2668 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2669 "${facet:0:3}" == "mgs" ]; then
2671 eval export ${facet}failover_host=${mds_HOST}
2676 if [[ $facet == ost* ]]; then
2677 eval export ${facet}failover_host=${ost_HOST}
2685 local activevar=${facet}active
2687 if [ -f $TMP/${facet}active ] ; then
2688 source $TMP/${facet}active
2691 active=${!activevar}
2692 if [ -z "$active" ] ; then
2699 facet_active_host() {
2701 local active=`facet_active $facet`
2702 if [ "$facet" == client ]; then
2705 echo `facet_host $active`
2709 # Get the passive failover partner host of facet.
2710 facet_passive_host() {
2712 [[ $facet = client ]] && return
2714 local host=${facet}_HOST
2715 local failover_host=${facet}failover_HOST
2716 local active_host=$(facet_active_host $facet)
2718 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2720 if [[ $active_host = ${!host} ]]; then
2721 echo -n ${!failover_host}
2731 facetlist=$(exclude_items_from_list $facetlist mgs)
2733 for facet in ${facetlist//,/ }; do
2734 local failover=${facet}failover
2735 local host=`facet_host $failover`
2736 [ -z "$host" ] && return
2738 local curactive=`facet_active $facet`
2739 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2740 eval export ${facet}active=$facet
2742 eval export ${facet}active=$failover
2744 # save the active host for this facet
2745 local activevar=${facet}active
2746 echo "$activevar=${!activevar}" > $TMP/$activevar
2747 [[ $facet = mds1 ]] && combined_mgs_mds && \
2748 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2749 local TO=`facet_active_host $facet`
2750 echo "Failover $facet to $TO"
2756 # do not stripe off hostname if verbose, bug 19215
2757 if [ x$1 = x--verbose ]; then
2765 if [ "$HOST" = "$HOSTNAME" ]; then
2767 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2768 echo "cannot run remote command on $HOST with $myPDSH"
2772 echo "CMD: $HOST $@" >&2
2773 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2776 if [ "$myPDSH" = "rsh" ]; then
2777 # we need this because rsh does not return exit code of an executed command
2778 local command_status="$TMP/cs"
2779 rsh $HOST ":> $command_status"
2780 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2781 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2782 echo command failed >$command_status"
2783 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2788 # print HOSTNAME for myPDSH="no_dsh"
2789 if [[ $myPDSH = no_dsh ]]; then
2790 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2792 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2795 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2797 return ${PIPESTATUS[0]}
2801 do_node --verbose "$@"
2804 single_local_node () {
2805 [ "$1" = "$HOSTNAME" ]
2808 # Outputs environment variable assignments that should be passed to remote nodes
2812 local facets=$(get_facets)
2815 for var in ${!MODOPTS_*}; do
2817 echo -n " ${var}=\"$value\""
2820 for facet in ${facets//,/ }; do
2822 if [ -n "${!var}" ]; then
2823 echo -n " $var=${!var}"
2827 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2828 if [ -n "${!var}" ]; then
2829 echo -n " $var=${!var}"
2833 if [ -n "$FSTYPE" ]; then
2834 echo -n " FSTYPE=$FSTYPE"
2840 # do not stripe off hostname if verbose, bug 19215
2841 if [ x$1 = x--verbose ]; then
2849 if single_local_node $rnodes; then
2851 do_nodev $rnodes "$@"
2853 do_node $rnodes "$@"
2858 # This is part from do_node
2861 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2862 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2864 export FANOUT=$(get_node_count "${rnodes//,/ }")
2866 echo "CMD: $rnodes $@" >&2
2867 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2870 # do not replace anything from pdsh output if -N is used
2871 # -N Disable hostname: prefix on lines of output.
2872 if $verbose || [[ $myPDSH = *-N* ]]; then
2873 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2875 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2877 return ${PIPESTATUS[0]}
2883 local HOST=`facet_active_host $facet`
2884 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2888 # Function: do_facet_random_file $FACET $FILE $SIZE
2889 # Creates FILE with random content on the given FACET of given SIZE
2891 do_facet_random_file() {
2895 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2896 do_facet $facet "$cmd 2>/dev/null"
2899 do_facet_create_file() {
2903 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2904 do_facet $facet "$cmd 2>/dev/null"
2908 do_nodes --verbose "$@"
2914 # make sure its not already running
2916 rm -f $TMP/${facet}active
2917 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2918 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2920 if [[ $(facet_fstype $facet) == zfs ]]; then
2922 # After formatting a ZFS target, "cachefile=none" property will
2923 # be set on the ZFS storage pool so that the pool is not
2924 # automatically imported on system startup. And then the pool
2925 # will be exported so as to leave the importing and exporting
2926 # operations handled by mount_facet() and stop() separately.
2928 refresh_partition_table $facet $(facet_vdevice $facet)
2929 disable_zpool_cache $facet
2934 # Device formatted as ost
2937 local DEVNAME=OSTDEV$num
2939 local fstype=$(facet_fstype ost$num)
2943 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2944 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2946 #try $OSTZFSDEVn - independent of vdev
2947 DEVNAME=OSTZFSDEV$num
2948 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2950 error "unknown fstype!";;
2956 # Physical device location of data
2962 local fstype=$(facet_fstype ost$num)
2966 # vdevs are not supported by ldiskfs
2969 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2970 # Device formated by zfs
2972 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2974 error "unknown fstype!";;
2980 # Logical device formated for lustre
2983 local DEVNAME=MDSDEV$num
2985 local fstype=$(facet_fstype mds$num)
2989 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2990 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2992 # try $MDSZFSDEVn - independent of vdev
2993 DEVNAME=MDSZFSDEV$num
2994 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
2996 error "unknown fstype!";;
3002 # Physical location of data
3006 local fstype=$(facet_fstype mds$num)
3010 # vdevs are not supported by ldiskfs
3013 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3014 # Device formated by ZFS
3015 local DEVNAME=MDSDEV$num
3016 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3018 error "unknown fstype!";;
3026 local fstype=$(facet_fstype mgs)
3030 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3031 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3032 DEVPTR=$(mdsdevname 1)
3037 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3038 ( [ -z "$MGSZFSDEV" ] &&
3039 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3040 DEVPTR=$(mdsdevname 1)
3042 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3045 error "unknown fstype!";;
3054 local fstype=$(facet_fstype mgs)
3058 # vdevs are not supported by ldiskfs
3061 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3062 ( [ -z "$MGSDEV" ] &&
3063 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3064 VDEVPTR=$(mdsvdevname 1)
3065 elif [ -n "$MGSDEV" ]; then
3069 error "unknown fstype!";;
3077 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3079 local var=${facet}_MOUNT
3080 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3087 local dev=$(facet_device $facet)
3088 local mnt=$(facet_mntpt $facet)
3091 if ! do_facet $facet test -b $dev; then
3094 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3099 local dev=$(facet_device $facet)
3100 local mnt=$(facet_mntpt $facet)
3102 do_facet $facet umount -d $mnt
3106 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3111 local ds=$(facet_device $facet)
3112 local mnt=$(facet_mntpt $facet)
3117 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3118 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3119 do_facet $facet $ZFS set canmount=noauto $ds
3121 # The "legacy" mount method is used here because "zfs unmount $mnt"
3122 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3123 # targets are not available at the time, the stat(2) on $MOUNT will
3126 do_facet $facet $ZFS set mountpoint=legacy $ds
3127 do_facet $facet mount -t zfs $ds $mnt
3128 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3129 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3134 local ds=$(facet_device $facet)
3135 local mnt=$(facet_mntpt $facet)
3136 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3137 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3138 local mntpt=${!var_mntpt}
3139 local canmnt=${!var_canmnt}
3143 do_facet $facet umount $mnt
3144 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3145 do_facet $facet $ZFS set canmount=$canmnt $ds
3151 local fstype=$(facet_fstype $facet)
3153 mount_$fstype $facet
3158 local fstype=$(facet_fstype $facet)
3160 unmount_$fstype $facet
3167 # make sure we are using the primary server, so test-framework will
3168 # be able to clean up properly.
3169 activemds=`facet_active mds1`
3170 if [ $activemds != "mds1" ]; then
3174 local clients=$CLIENTS
3175 [ -z $clients ] && clients=$(hostname)
3177 zconf_umount_clients $clients $MOUNT "$*" || true
3178 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3180 [ "$CLIENTONLY" ] && return
3181 # The add fn does rm ${facet}active file, this would be enough
3182 # if we use do_facet <facet> only after the facet added, but
3183 # currently we use do_facet mds in local.sh
3184 for num in `seq $MDSCOUNT`; do
3186 rm -f ${TMP}/mds${num}active
3188 combined_mgs_mds && rm -f $TMP/mgsactive
3190 for num in `seq $OSTCOUNT`; do
3192 rm -f $TMP/ost${num}active
3195 if ! combined_mgs_mds ; then
3202 cleanup_echo_devs () {
3203 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3205 for dev in $devs; do
3206 $LCTL --device $dev cleanup
3207 $LCTL --device $dev detach
3212 nfs_client_mode && return
3221 combined_mgs_mds () {
3222 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3223 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3227 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3231 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3237 local fsname=${3:-"$FSNAME"}
3238 local type=$(facet_type $facet)
3239 local index=$(($(facet_number $facet) - 1))
3240 local fstype=$(facet_fstype $facet)
3241 local host=$(facet_host $facet)
3246 if [ $type == MGS ] && combined_mgs_mds; then
3250 if [ $type == MGS ] || ( [ $type == MDS ] &&
3251 [ "$dev" == $(mgsdevname) ] &&
3252 [ "$host" == "$(facet_host mgs)" ] ); then
3255 opts="--mgsnode=$MGSNID"
3258 if [ $type != MGS ]; then
3259 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3263 var=${facet}failover_HOST
3264 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3265 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3268 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3269 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3271 if [ $type == MDS ]; then
3272 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3273 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3274 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3275 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3276 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3278 if [ $fstype == ldiskfs ]; then
3279 # Check for wide striping
3280 if [ $OSTCOUNT -gt 160 ]; then
3281 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3282 fs_mkfs_opts+="-O large_xattr"
3285 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3286 if [ ! -z $EJOURNAL ]; then
3287 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3289 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3293 if [ $type == OST ]; then
3294 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3295 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3297 if [ $fstype == ldiskfs ]; then
3298 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3302 opts+=" --backfstype=$fstype"
3305 if [ -n "${!var}" ]; then
3306 opts+=" --device-size=${!var}"
3309 var=$(upper $fstype)_MKFS_OPTS
3310 fs_mkfs_opts+=${!var:+" ${!var}"}
3312 var=${type}_FS_MKFS_OPTS
3313 fs_mkfs_opts+=${!var:+" ${!var}"}
3315 if [ -n "${fs_mkfs_opts## }" ]; then
3316 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3320 opts+=${!var:+" ${!var}"}
3333 # We need ldiskfs here, may as well load them all
3335 [ "$CLIENTONLY" ] && return
3336 echo Formatting mgs, mds, osts
3337 if ! combined_mgs_mds ; then
3338 echo "Format mgs: $(mgsdevname)"
3339 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3340 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3344 for num in $(seq $MDSCOUNT); do
3345 echo "Format mds$num: $(mdsdevname $num)"
3346 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3347 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3348 ${quiet:+>/dev/null} || exit 10
3351 for num in $(seq $OSTCOUNT); do
3352 echo "Format ost$num: $(ostdevname $num)"
3353 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3354 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3355 ${quiet:+>/dev/null} || exit 10
3360 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3364 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3368 # 0: success, the old identity set already.
3369 # 1: success, the old identity does not set.
3374 local j=`expr $num - 1`
3375 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3377 if [ -z "$MDT" ]; then
3381 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3384 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3386 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3389 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3391 if [ $old = "NONE" ]; then
3400 zconf_umount `hostname` $1 || error "umount failed"
3401 zconf_mount `hostname` $1 || error "mount failed"
3409 rm -f $TMP/${facet}active
3410 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3415 local mdt_count=${1:-$MDSCOUNT}
3416 local ost_count=${2:-$OSTCOUNT}
3419 for num in $(seq $mdt_count); do
3420 DEVNAME=$(mdsdevname $num)
3421 writeconf_facet mds$num $DEVNAME || rc=$?
3424 for num in $(seq $ost_count); do
3425 DEVNAME=$(ostdevname $num)
3426 writeconf_facet ost$num $DEVNAME || rc=$?
3432 nfs_client_mode && return
3434 sanity_mount_check ||
3435 error "environments are insane!"
3439 if [ -z "$CLIENTONLY" ]; then
3440 echo Setup mgs, mdt, osts
3441 echo $WRITECONF | grep -q "writeconf" && \
3443 if ! combined_mgs_mds ; then
3444 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3447 for num in `seq $MDSCOUNT`; do
3448 DEVNAME=$(mdsdevname $num)
3449 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3451 # We started mds, now we should set failover variables properly.
3452 # Set mds${num}failover_HOST if it is not set (the default failnode).
3453 local varname=mds${num}failover_HOST
3454 if [ -z "${!varname}" ]; then
3455 eval mds${num}failover_HOST=$(facet_host mds$num)
3458 if [ $IDENTITY_UPCALL != "default" ]; then
3459 switch_identity $num $IDENTITY_UPCALL
3462 for num in `seq $OSTCOUNT`; do
3463 DEVNAME=$(ostdevname $num)
3464 start ost$num $DEVNAME $OST_MOUNT_OPTS
3466 # We started ost$num, now we should set ost${num}failover variable properly.
3467 # Set ost${num}failover_HOST if it is not set (the default failnode).
3468 varname=ost${num}failover_HOST
3469 if [ -z "${!varname}" ]; then
3470 eval ost${num}failover_HOST=$(facet_host ost${num})
3478 # wait a while to allow sptlrpc configuration be propogated to targets,
3479 # only needed when mounting new target devices.
3484 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3486 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3489 if [ "$MOUNT_2" ]; then
3490 mount_client $MOUNT2
3491 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3496 # by remounting mdt before ost, initial connect from mdt to ost might
3497 # timeout because ost is not ready yet. wait some time to its fully
3498 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3499 # by a context negotiation rpc with $TIMEOUT.
3500 # FIXME better by monitoring import status.
3503 sleep $((TIMEOUT + 5))
3509 mounted_lustre_filesystems() {
3510 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3513 init_facet_vars () {
3514 [ "$CLIENTONLY" ] && return 0
3521 eval export ${facet}_dev=${device}
3522 eval export ${facet}_opt=\"$@\"
3524 local dev=${facet}_dev
3526 # We need to loop for the label
3527 # in case its not initialized yet.
3528 for wait_time in {0,1,3,5,10}; do
3530 if [ $wait_time -gt 0 ]; then
3531 echo "${!dev} not yet initialized,"\
3532 "waiting ${wait_time} seconds."
3536 local label=$(devicelabel ${facet} ${!dev})
3538 # Check to make sure the label does
3539 # not include ffff at the end of the label.
3540 # This indicates it has not been initialized yet.
3542 if [[ $label =~ [f|F]{4}$ ]]; then
3543 # label is not initialized, unset the result
3544 # and either try again or fail
3551 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3553 eval export ${facet}_svc=${label}
3555 local varname=${facet}failover_HOST
3556 if [ -z "${!varname}" ]; then
3557 eval export $varname=$(facet_host $facet)
3560 varname=${facet}_HOST
3561 if [ -z "${!varname}" ]; then
3562 eval export $varname=$(facet_host $facet)
3565 # ${facet}failover_dev is set in cfg file
3566 varname=${facet}failover_dev
3567 if [ -n "${!varname}" ] ; then
3568 eval export ${facet}failover_dev=${!varname}
3570 eval export ${facet}failover_dev=$device
3573 # get mount point of already mounted device
3574 # is facet_dev is already mounted then use the real
3575 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3576 # i.e. ${facet}_MOUNT if specified by user or default
3577 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3578 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3579 if [ -z $mntpt ]; then
3580 mntpt=$(facet_mntpt $facet)
3582 eval export ${facet}_MOUNT=$mntpt
3585 init_facets_vars () {
3588 if ! remote_mds_nodsh; then
3589 for num in $(seq $MDSCOUNT); do
3590 DEVNAME=`mdsdevname $num`
3591 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3595 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3597 if ! remote_ost_nodsh; then
3598 for num in $(seq $OSTCOUNT); do
3599 DEVNAME=$(ostdevname $num)
3600 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3605 osc_ensure_active () {
3610 while [ $period -lt $timeout ]; do
3611 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3612 if [ $count -eq 0 ]; then
3616 echo "There are $count OST are inactive, wait $period seconds, and try again"
3618 period=$((period+3))
3621 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3624 set_conf_param_and_check() {
3628 local ORIG=$(do_facet $myfacet "$TEST")
3629 if [ $# -gt 3 ]; then
3635 echo "Setting $PARAM from $ORIG to $FINAL"
3636 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3637 error "conf_param $PARAM failed"
3639 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3640 error "check $PARAM failed!"
3643 init_param_vars () {
3645 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3647 log "Using TIMEOUT=$TIMEOUT"
3649 osc_ensure_active $SINGLEMDS $TIMEOUT
3650 osc_ensure_active client $TIMEOUT
3652 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3653 local current_jobid_var=$($LCTL get_param -n jobid_var)
3655 if [ $JOBID_VAR = "existing" ]; then
3656 echo "keeping jobstats as $current_jobid_var"
3657 elif [ $current_jobid_var != $JOBID_VAR ]; then
3658 echo "seting jobstats to $JOBID_VAR"
3660 set_conf_param_and_check client \
3661 "$LCTL get_param -n jobid_var" \
3662 "$FSNAME.sys.jobid_var" $JOBID_VAR
3665 echo "jobstats not supported by server"
3668 if [ $QUOTA_AUTO -ne 0 ]; then
3669 if [ "$ENABLE_QUOTA" ]; then
3670 echo "enable quota as required"
3671 setup_quota $MOUNT || return 2
3673 echo "disable quota as required"
3674 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3680 nfs_client_mode () {
3681 if [ "$NFSCLIENT" ]; then
3682 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3683 local clients=$CLIENTS
3684 [ -z $clients ] && clients=$(hostname)
3686 # FIXME: remove hostname when 19215 fixed
3687 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3688 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3689 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3690 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3692 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3698 check_config_client () {
3701 local mounted=$(mount | grep " $mntpt ")
3702 if [ "$CLIENTONLY" ]; then
3704 # CLIENTONLY should not depend on *_HOST settings
3705 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3706 # in theory someone could create a new,
3707 # client-only config file that assumed lustre was already
3708 # configured and didn't set the MGSNID. If MGSNID is not set,
3709 # then we should use the mgs nid currently being used
3710 # as the default value. bug 18021
3711 [[ x$MGSNID = x ]] &&
3714 if [[ x$mgc != xMGC$MGSNID ]]; then
3715 if [ "$mgs_HOST" ]; then
3716 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3717 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3718 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3724 local myMGS_host=$mgs_HOST
3725 if [ "$NETTYPE" = "ptl" ]; then
3726 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3729 echo Checking config lustre mounted on $mntpt
3730 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3731 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3733 # if [ "$mgshost" != "$myMGS_host" ]; then
3734 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3735 # Please use correct config or set mds_HOST correctly!"
3740 check_config_clients () {
3741 local clients=${CLIENTS:-$HOSTNAME}
3744 nfs_client_mode && return
3746 do_rpc_nodes "$clients" check_config_client $mntpt
3748 sanity_mount_check || error "environments are insane!"
3752 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3753 local cltimeout=$(lctl get_param -n timeout)
3754 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3755 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3762 [ -z $mntpt ] && return 1
3763 local mounted=$(mounted_lustre_filesystems)
3765 echo $mounted' ' | grep -w -q $mntpt' '
3769 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3773 # empty lustre filesystem may have empty directories lost+found and .lustre
3775 # exclude .lustre & lost+found
3776 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3777 -print | wc -l) = 1 ] || return 1
3778 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3779 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3780 # exclude .lustre/fid (LU-2780)
3781 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3782 -print | wc -l) = 1 ] || return 1
3784 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3789 check_and_setup_lustre() {
3790 nfs_client_mode && return
3792 local MOUNTED=$(mounted_lustre_filesystems)
3796 # both MOUNT and MOUNT2 are not mounted
3797 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3798 [ "$REFORMAT" ] && formatall
3799 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3801 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3802 export I_MOUNTED=yes
3806 elif is_mounted $MOUNT2; then
3808 # MOUNT2 is mounted, while MOUNT_2 is not set
3809 if ! [ "$MOUNT_2" ]; then
3810 cleanup_mount $MOUNT2
3811 export I_UMOUNTED2=yes
3814 # MOUNT2 is mounted, MOUNT_2 is set
3816 # FIXME: what to do if check_config failed?
3818 # 1) remote client has mounted other Lustre fs ?
3819 # 2) it has insane env ?
3820 # let's try umount MOUNT2 on all clients and mount it again:
3821 if ! check_config_clients $MOUNT2; then
3822 cleanup_mount $MOUNT2
3823 restore_mount $MOUNT2
3824 export I_MOUNTED2=yes
3829 # MOUNT is mounted MOUNT2 is not mounted
3830 elif [ "$MOUNT_2" ]; then
3831 restore_mount $MOUNT2
3832 export I_MOUNTED2=yes
3836 # FIXME: what to do if check_config failed?
3838 # 1) remote client has mounted other Lustre fs?
3839 # 2) lustre is mounted on remote_clients atall ?
3840 check_config_clients $MOUNT
3844 set_default_debug_nodes $(comma_list $(nodes_list))
3847 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3849 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3850 facets="$(get_facets OST)"
3851 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3852 facets="$facets,$(get_facets MDS)"
3853 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3854 facets="$facets,mgs"
3855 local nodes="$(facets_hosts ${facets})"
3856 if [ -n "$nodes" ] ; then
3857 do_nodes $nodes "$LCTL set_param \
3858 osd-ldiskfs.track_declares_assert=1 || true"
3867 #Enable remote MDT create for testing
3868 for num in $(seq $MDSCOUNT); do
3870 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
3874 if [ "$ONLY" == "setup" ]; then
3880 local clients=${CLIENTS:-$HOSTNAME}
3883 zconf_mount_clients $clients $mntpt
3887 local clients=${CLIENTS:-$HOSTNAME}
3890 zconf_umount_clients $clients $mntpt
3893 cleanup_and_setup_lustre() {
3894 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3895 lctl set_param debug=0 || true
3897 if [ "$ONLY" == "cleanup" ]; then
3901 check_and_setup_lustre
3904 # Get all of the server target devices from a given server node and type.
3911 if [ "$type" == ost ]; then
3912 devs=$(get_osd_param $node "" mntdev)
3914 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
3916 for dev in $devs; do
3918 *loop*) do_node $node "losetup $dev" | \
3919 sed -e "s/.*(//" -e "s/).*//" ;;
3925 # Get all of the server target devices.
3930 # Master MDS parameters used by lfsck
3931 MDTNODE=$(facet_active_host $SINGLEMDS)
3932 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
3936 for node in $(mdts_nodes); do
3937 MDTDEVS[i]=$(get_mnt_devs $node mdt)
3943 for node in $(osts_nodes); do
3944 OSTDEVS[i]=$(get_mnt_devs $node ost)
3949 # Run e2fsck on MDT or OST device.
3954 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3955 local log=$TMP/e2fsck.log
3959 do_node $node $cmd 2>&1 | tee $log
3961 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
3963 if [ $MDSCOUNT -gt 1 ]; then
3964 skip "DNE mode isn't supported!"
3968 error "It's not DNE mode."
3973 [ $rc -le $FSCK_MAX_ERR ] ||
3974 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3980 # Run resize2fs on MDT or OST device.
3989 do_facet $facet "$RESIZE2FS $opts $device $size"
3992 # verify a directory is shared among nodes.
3993 check_shared_dir() {
3995 local list=${2:-$(comma_list $(nodes_list))}
3997 [ -z "$dir" ] && return 1
3998 do_rpc_nodes "$list" check_logdir $dir
3999 check_write_access $dir "$list" || return 1
4003 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4010 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4011 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4013 check_shared_dir $SHARED_DIRECTORY ||
4014 error "$SHARED_DIRECTORY isn't a shared directory"
4016 export MDSDB=$SHARED_DIRECTORY/mdsdb
4017 export OSTDB=$SHARED_DIRECTORY/ostdb
4019 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4020 # we only pass master MDS parameters.
4021 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4026 for node in $(osts_nodes); do
4027 for dev in ${OSTDEVS[i]}; do
4028 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4029 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4030 ostidx=$((ostidx + 1))
4036 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4037 run_lfsck_remote() {
4038 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4043 #Check if lustre is already mounted
4044 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4046 zconf_mount $client $MOUNT ||
4047 error "failed to mount Lustre on $client"
4051 do_node $client $cmd || rc=$?
4052 #Umount if necessary
4054 zconf_umount $client $MOUNT ||
4055 error "failed to unmount Lustre on $client"
4058 [ $rc -le $FSCK_MAX_ERR ] ||
4059 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4060 echo "lfsck finished with rc=$rc"
4066 local facets="client $SINGLEMDS"
4072 for facet in $facets; do
4073 node=$(facet_active_host $facet)
4074 if check_progs_installed $node $LFSCK_BIN; then
4079 ! $found && error "None of \"$facets\" supports lfsck"
4081 run_lfsck_remote $node || rc=$?
4083 rm -rvf $MDSDB* $OSTDB* || true
4087 check_and_cleanup_lustre() {
4088 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4094 if is_mounted $MOUNT; then
4095 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4096 error "remove sub-test dirs failed"
4097 [ "$ENABLE_QUOTA" ] && restore_quota || true
4100 if [ "$I_UMOUNTED2" = "yes" ]; then
4101 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4104 if [ "$I_MOUNTED2" = "yes" ]; then
4105 cleanup_mount $MOUNT2
4108 if [ "$I_MOUNTED" = "yes" ]; then
4109 cleanupall -f || error "cleanup failed"
4113 if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
4114 umount /sbin/mount.lustre
4121 wait_for_function () {
4124 # suppress fn both stderr and stdout
4125 if [ "$1" = "--quiet" ]; then
4127 quiet=" > /dev/null 2>&1"
4139 eval $fn $quiet && return 0
4141 wait=$((wait + sleep))
4142 [ $wait -lt $max ] || return 1
4143 echo waiting $fn, $((max - wait)) secs left ...
4153 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4154 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4155 echo "Network not available!"
4159 echo `date +"%H:%M:%S (%s)"` network interface is UP
4167 # Convert a space-delimited list to a comma-delimited list. If the input is
4168 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4170 # echo is used to convert newlines to spaces, since it doesn't
4171 # introduce a trailing space as using "tr '\n' ' '" does
4172 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4178 echo $list | grep -qw $item
4181 # list, excluded are the comma separated lists
4182 exclude_items_from_list () {
4188 for item in ${excluded//,/ }; do
4189 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4191 echo $(comma_list $list)
4194 # list, expand are the comma separated lists
4196 local list=${1//,/ }
4197 local expand=${2//,/ }
4200 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4201 echo $(comma_list $expanded)
4204 testslist_filter () {
4205 local script=$LUSTRE/tests/${TESTSUITE}.sh
4207 [ -f $script ] || return 0
4209 local start_at=$START_AT
4210 local stop_at=$STOP_AT
4212 local var=${TESTSUITE//-/_}_START_AT
4213 [ x"${!var}" != x ] && start_at=${!var}
4214 var=${TESTSUITE//-/_}_STOP_AT
4215 [ x"${!var}" != x ] && stop_at=${!var}
4217 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4218 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4219 /^'${start_at}'$/ {flag = 0}
4220 {if (flag == 1) print $0}
4221 /^'${stop_at}'$/ { flag = 1 }'
4225 (cd `dirname $1`; echo $PWD/`basename $1`)
4229 local types=${1:-"OST MDS MGS"}
4233 for entry in $types; do
4234 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4235 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4238 MGS ) list="$list $name";;
4239 MDS|OST|AGT ) local count=${type}COUNT
4240 for ((i=1; i<=${!count}; i++)) do
4241 list="$list ${name}$i"
4243 * ) error "Invalid facet type"
4247 echo $(comma_list $list)
4250 ##################################
4251 # Adaptive Timeouts funcs
4254 # only check mds, we assume at_max is the same on all nodes
4255 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4256 if [ $at_max -eq 0 ]; then
4267 # suppose that all ost-s have the same $at value set
4268 [ $facet != "ost" ] || facet=ost1
4270 do_facet $facet "lctl get_param -n $at"
4288 if [ $facet == "ost" ]; then
4289 facet=$(get_facets OST)
4290 elif [ $facet == "mds" ]; then
4291 facet=$(get_facets MDS)
4293 hosts=$(expand_list $hosts $(facets_hosts $facet))
4296 do_nodes $hosts lctl set_param at_max=$at_max
4299 ##################################
4303 # OBD_FAIL_MDS_ALL_REQUEST_NET
4305 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4306 do_facet client "$1" || RC=$?
4307 do_facet $SINGLEMDS lctl set_param fail_loc=0
4312 # OBD_FAIL_MDS_ALL_REPLY_NET
4314 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4316 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4320 drop_reint_reply() {
4321 # OBD_FAIL_MDS_REINT_NET_REP
4323 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4325 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4329 drop_update_reply() {
4330 # OBD_FAIL_UPDATE_OBJ_NET_REP
4334 do_facet mds${index} lctl set_param fail_loc=0x1701
4335 do_facet client "$@" || RC=$?
4336 do_facet mds${index} lctl set_param fail_loc=0
4341 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4344 local timeout=${2:-0}
4345 # default is (obd_timeout / 4) if unspecified
4346 echo "timeout is $timeout/$2"
4347 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4348 do_facet client "$1" || RC=$?
4349 do_facet client "sync"
4350 do_facet ost1 lctl set_param fail_loc=0
4354 drop_ldlm_cancel() {
4355 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4357 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4358 do_nodes $list lctl set_param fail_loc=0x304
4360 do_facet client "$@" || RC=$?
4362 do_nodes $list lctl set_param fail_loc=0
4366 drop_bl_callback() {
4367 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4369 do_facet client lctl set_param fail_loc=0x80000305
4370 do_facet client "$@" || RC=$?
4371 do_facet client lctl set_param fail_loc=0
4376 #define OBD_FAIL_LDLM_REPLY 0x30c
4378 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4379 do_nodes $list lctl set_param fail_loc=0x30c
4381 do_facet client "$@" || RC=$?
4383 do_nodes $list lctl set_param fail_loc=0
4387 drop_ldlm_reply_once() {
4388 #define OBD_FAIL_LDLM_REPLY 0x30c
4390 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4391 do_nodes $list lctl set_param fail_loc=0x8000030c
4393 do_facet client "$@" || RC=$?
4395 do_nodes $list lctl set_param fail_loc=0
4403 echo "clearing fail_loc on $facet"
4404 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4407 set_nodes_failloc () {
4408 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4411 cancel_lru_locks() {
4412 $LCTL mark "cancel_lru_locks $1 start"
4413 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4414 $LCTL set_param -n $d=clear
4416 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4417 $LCTL mark "cancel_lru_locks $1 stop"
4422 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4423 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4424 echo "$DEFAULT_LRU_SIZE"
4429 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4432 lru_resize_disable()
4434 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4440 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4446 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4447 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4448 echo there is still data in page cache $FILE ?
4449 lctl get_param -n $FILE
4457 DEBUGSAVE="$(lctl get_param -n debug)"
4461 [ -n "$DEBUGSAVE" ] && \
4462 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4467 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4470 debug_size_restore() {
4471 [ -n "$DEBUG_SIZE_SAVED" ] && \
4472 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4476 start_full_debug_logging() {
4481 local DEBUG_SIZE=150
4483 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4484 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4487 stop_full_debug_logging() {
4492 # prints bash call stack
4495 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4496 local s=${BASH_SOURCE[$i]}
4497 local l=${BASH_LINENO[$i-1]}
4498 local f=${FUNCNAME[$i]}
4499 echo " = $s:$l:$f()"
4503 ##################################
4505 ##################################
4508 local TYPE=${TYPE:-"FAIL"}
4511 # do not dump logs if $1=false
4512 if [ "x$1" = "xfalse" ]; then
4518 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4522 # We need to dump the logs on all nodes
4524 gather_logs $(comma_list $(nodes_list))
4528 [ "$TESTSUITELOG" ] &&
4529 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4530 if [ -z "$*" ]; then
4531 echo "error() without useful message, please fix" > $LOGDIR/err
4533 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4534 echo "$@" > $LOGDIR/ignore
4536 echo "$@" > $LOGDIR/err
4543 local log=$TESTSUITELOG
4545 [ -f "$log" ] && grep -q FAIL $log && status=1
4558 # use only if we are ignoring failures for this test, bugno required.
4559 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4560 # e.g. error_ignore bz5494 "your message" or
4561 # error_ignore LU-5494 "your message"
4563 local TYPE="IGNORE ($1)"
4568 error_and_remount() {
4570 remount_client $MOUNT
4575 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4580 log " SKIP: $TESTSUITE $TESTNAME $@"
4582 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4583 skip_logged $TESTNAME "$@"
4586 echo "$@" > $LOGDIR/skip
4589 [[ -n "$TESTSUITELOG" ]] &&
4590 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4593 build_test_filter() {
4594 EXCEPT="$EXCEPT $(testslist_filter)"
4597 if [[ $O = [0-9]*-[0-9]* ]]; then
4598 for num in $(seq $(echo $O | tr '-' ' ')); do
4606 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4607 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4608 [ "$EXCEPT_SLOW" ] && \
4609 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4610 for E in $EXCEPT; do
4611 eval EXCEPT_${E}=true
4613 for E in $ALWAYS_EXCEPT; do
4614 eval EXCEPT_ALWAYS_${E}=true
4616 for E in $EXCEPT_SLOW; do
4617 eval EXCEPT_SLOW_${E}=true
4619 for G in $GRANT_CHECK_LIST; do
4620 eval GCHECK_ONLY_${G}=true
4625 if [[ $1 = [a-z]* ]]; then
4632 # print a newline if the last test was skipped
4633 export LAST_SKIPPED=
4634 export ALWAYS_SKIPPED=
4636 # Main entry into test-framework. This is called with the name and
4637 # description of a test. The name is used to find the function to run
4638 # the test using "test_$name".
4640 # This supports a variety of methods of specifying specific test to
4641 # run or not run. These need to be documented...
4646 export base=$(basetest $1)
4647 if [ -n "$ONLY" ]; then
4649 if [ ${!testname}x != x ]; then
4650 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4651 run_one_logged $1 "$2"
4655 if [ ${!testname}x != x ]; then
4656 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4657 run_one_logged $1 "$2"
4667 if [ ${!testname}x != x ]; then
4668 TESTNAME=test_$1 skip "skipping excluded test $1"
4671 testname=EXCEPT_$base
4672 if [ ${!testname}x != x ]; then
4673 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4676 testname=EXCEPT_ALWAYS_$1
4677 if [ ${!testname}x != x ]; then
4678 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4681 testname=EXCEPT_ALWAYS_$base
4682 if [ ${!testname}x != x ]; then
4683 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4686 testname=EXCEPT_SLOW_$1
4687 if [ ${!testname}x != x ]; then
4688 TESTNAME=test_$1 skip "skipping SLOW test $1"
4691 testname=EXCEPT_SLOW_$base
4692 if [ ${!testname}x != x ]; then
4693 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4699 run_one_logged $1 "$2"
4706 module_loaded lnet || load_modules
4718 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4723 strace -o $TMP/$1.strace -ttt $*
4725 log "FINISHED: $*: rc $RC"
4732 banner test complete, duration $duration sec
4733 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4734 echo duration $duration >>$TESTSUITELOG
4738 # Set TEST_STATUS here. It will be used for logging the result.
4741 if [[ -f $LOGDIR/err ]]; then
4743 elif [[ -f $LOGDIR/skip ]]; then
4746 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4750 local FFREE=$(do_node $SINGLEMDS \
4751 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4752 local FTOTAL=$(do_node $SINGLEMDS \
4753 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4755 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4759 echo -n "Resetting fail_loc on all nodes..."
4760 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4766 # Log a message (on all nodes) padded with "=" before and after.
4767 # Also appends a timestamp and prepends the testsuite name.
4770 EQUALS="===================================================================================================="
4772 msg="== ${TESTSUITE} $*"
4774 [[ $last != "=" && $last != " " ]] && msg="$msg "
4775 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4776 # always include at least == after the message
4777 log "$msg== $(date +"%H:%M:%S (%s)")"
4781 # Run a single test function and cleanup after it.
4783 # This function should be run in a subshell so the test func can
4784 # exit() without stopping the whole script.
4789 export tfile=f${testnum}.${TESTSUITE}
4790 export tdir=d${testnum}.${TESTSUITE}
4791 export TESTNAME=test_$testnum
4792 local SAVE_UMASK=`umask`
4795 banner "test $testnum: $message"
4796 test_${testnum} || error "test_$testnum failed with $?"
4799 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4800 check_catastrophe || error "LBUG/LASSERT detected"
4801 if [ "$PARALLEL" != "yes" ]; then
4802 ps auxww | grep -v grep | grep -q multiop &&
4803 error "multiop still running"
4813 # Wrapper around run_one to ensure:
4814 # - test runs in subshell
4815 # - output of test is saved to separate log file for error reporting
4816 # - test result is saved to data file
4819 local BEFORE=$(date +%s)
4821 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4822 local test_log=$LOGDIR/$name
4824 rm -rf $LOGDIR/ignore
4826 local SAVE_UMASK=$(umask)
4830 log_sub_test_begin test_${1}
4831 (run_one $1 "$2") 2>&1 | tee -i $test_log
4832 local RC=${PIPESTATUS[0]}
4834 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4835 echo "test_$1 returned $RC" | tee $LOGDIR/err
4837 duration=$(($(date +%s) - $BEFORE))
4838 pass "$1" "(${duration}s)"
4840 if [[ -f $LOGDIR/err ]]; then
4841 TEST_ERROR=$(cat $LOGDIR/err)
4842 elif [[ -f $LOGDIR/ignore ]]; then
4843 TEST_ERROR=$(cat $LOGDIR/ignore)
4844 elif [[ -f $LOGDIR/skip ]]; then
4845 TEST_ERROR=$(cat $LOGDIR/skip)
4847 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4849 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4853 if [ -f $LOGDIR/err ]; then
4854 $FAIL_ON_ERROR && exit $RC
4863 # Print information of skipped tests to result.yml
4866 log_sub_test_begin $1
4868 log_sub_test_end "SKIP" "0" "0" "$@"
4872 (cd $(dirname $1); echo $PWD/$(basename $1))
4877 export base=$(basetest $1)
4878 [ "$CHECK_GRANT" == "no" ] && return 0
4880 testname=GCHECK_ONLY_${base}
4881 [ ${!testname}x == x ] && return 0
4883 echo -n "checking grant......"
4885 local clients=$CLIENTS
4886 [ -z "$clients" ] && clients=$(hostname)
4888 # sync all the data and make sure no pending data on server
4889 do_nodes $clients sync
4892 client_grant=$(do_nodes $clients \
4893 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
4894 awk '{ total += $1 } END { printf("%0.0f", total) }')
4897 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
4898 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4899 awk '{ total += $1 } END { printf("%0.0f", total) }')
4901 # check whether client grant == server grant
4902 if [[ $client_grant -ne $server_grant ]]; then
4903 echo "failed: client:${client_grant} server: ${server_grant}."
4904 do_nodes $(comma_list $(osts_nodes)) \
4905 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4906 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4909 echo "pass: client:${client_grant} server: ${server_grant}"
4913 ########################
4919 ost=`echo $1 | awk -F_ '{print $3}'`
4920 if [ -z $ost ]; then
4921 ost=`echo $1 | sed 's/-osc.*//'`
4926 ostuuid_from_index()
4928 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4931 ostname_from_index() {
4932 local uuid=$(ostuuid_from_index $1)
4936 index_from_ostuuid()
4938 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4941 mdtuuid_from_index()
4943 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4947 # Return unique identifier for given hostname
4950 echo $host_name | md5sum | cut -d' ' -f1
4954 # Returns list of ip addresses for each interface
4956 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4961 # Cache address list to avoid mutiple execution of local_addr_list
4962 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4964 for i in $LOCAL_ADDR_LIST ; do
4965 [[ "$i" == "$addr" ]] && return 0
4972 local is_local="IS_LOCAL_$(host_id $host_name)"
4973 if [ -z "${!is_local-}" ] ; then
4975 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4976 is_local_addr "$host_ip" && eval $is_local=1
4978 [[ "${!is_local}" == "1" ]]
4983 local_node $node && return 1
4990 for node in $(mdts_nodes); do
4991 remote_node $node && return 0
4998 [ "$CLIENTONLY" ] && return 0 || true
4999 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5004 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5005 MSKIPPED=1 && return 1
5012 for node in $(osts_nodes) ; do
5013 remote_node $node && return 0
5020 [ "$CLIENTONLY" ] && return 0 || true
5021 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5026 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5027 OSKIPPED=1 && return 1
5034 MGS=$(facet_host mgs)
5035 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5040 remote_mds_nodsh || remote_ost_nodsh || \
5041 $(single_local_node $(comma_list $(nodes_list)))
5045 remote_ost && remote_mds
5048 # Get the active nodes for facets.
5056 for facet in ${facets//,/ }; do
5057 nodes="$nodes $(facet_active_host $facet)"
5060 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5064 # Get all of the active MDS nodes.
5066 echo -n $(facets_nodes $(get_facets MDS))
5069 # Get all of the active OSS nodes.
5071 echo -n $(facets_nodes $(get_facets OST))
5074 # Get all of the active AGT (HSM agent) nodes.
5076 echo -n $(facets_nodes $(get_facets AGT))
5079 # Get all of the client nodes and active server nodes.
5081 local nodes=$HOSTNAME
5085 # CLIENTS (if specified) contains the local client
5086 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5088 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5089 nodes="$nodes $(facets_nodes $(get_facets))"
5092 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5096 # Get all of the remote client nodes and remote active server nodes.
5097 remote_nodes_list () {
5098 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5101 # Get all of the MDS nodes, including active and passive nodes.
5109 for i in $(seq $MDSCOUNT); do
5111 failover_host=mds${i}failover_HOST
5112 nodes="$nodes ${!host} ${!failover_host}"
5115 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5119 # Get all of the OSS nodes, including active and passive nodes.
5127 for i in $(seq $OSTCOUNT); do
5129 failover_host=ost${i}failover_HOST
5130 nodes="$nodes ${!host} ${!failover_host}"
5133 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5137 # Get all of the server nodes, including active and passive nodes.
5138 all_server_nodes () {
5143 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5145 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5149 # Get all of the client and server nodes, including active and passive nodes.
5151 local nodes=$HOSTNAME
5155 # CLIENTS (if specified) contains the local client
5156 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5158 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5159 nodes="$nodes $(all_server_nodes)"
5162 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5166 init_clients_lists () {
5167 # Sanity check: exclude the local client from RCLIENTS
5168 local clients=$(hostlist_expand "$RCLIENTS")
5169 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5171 # Sanity check: exclude the dup entries
5172 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5174 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5176 # Sanity check: exclude the dup entries from CLIENTS
5177 # for those configs which has SINGLCLIENT set to local client
5178 clients=$(for i in $clients; do echo $i; done | sort -u)
5180 CLIENTS=$(comma_list $clients)
5181 local -a remoteclients=($RCLIENTS)
5182 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5183 varname=CLIENT$((i + 2))
5184 eval $varname=${remoteclients[i]}
5187 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5190 get_random_entry () {
5193 rnodes=${rnodes//,/ }
5195 local -a nodes=($rnodes)
5196 local num=${#nodes[@]}
5197 local i=$((RANDOM * num * 2 / 65536))
5203 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5208 lctl get_param version | grep -q patchless
5212 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5213 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5218 echo $nodes | wc -w || true
5222 local nodes=$(osts_nodes)
5223 local osscount=$(get_node_count "$nodes")
5224 [ ! "$OSTCOUNT" = "$osscount" ]
5228 local nodes=$(mdts_nodes)
5229 local mdtcount=$(get_node_count "$nodes")
5230 [ ! "$MDSCOUNT" = "$mdtcount" ]
5233 generate_machine_file() {
5234 local nodes=${1//,/ }
5235 local machinefile=$2
5237 for node in $nodes; do
5238 echo $node >>$machinefile || \
5239 { echo "can not generate machinefile $machinefile" && return 1; }
5244 local file=$1/stripe
5247 $LFS getstripe -v $file || error "getstripe $file failed"
5251 setstripe_nfsserver () {
5254 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5255 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5257 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5259 do_nodev $nfsserver lfs setstripe "$@"
5262 # Check and add a test group.
5268 local gid=$(getent group $group_name | cut -d: -f3)
5269 if [[ -n "$gid" ]]; then
5270 [[ "$gid" -eq "$group_id" ]] || {
5271 error_noexit "inconsistent group ID:" \
5272 "new: $group_id, old: $gid"
5276 groupadd -g $group_id $group_name
5283 # Check and add a test user.
5296 local uid=$(getent passwd $user_name | cut -d: -f3)
5297 if [[ -n "$uid" ]]; then
5298 if [[ "$uid" -eq "$user_id" ]]; then
5299 local dir=$(getent passwd $user_name | cut -d: -f6)
5300 if [[ "$dir" != "$home" ]]; then
5302 usermod -d $home $user_name
5306 error_noexit "inconsistent user ID:" \
5307 "new: $user_id, old: $uid"
5312 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5319 check_runas_id_ret() {
5321 local myRUNAS_UID=$1
5322 local myRUNAS_GID=$2
5325 if [ -z "$myRUNAS" ]; then
5326 error_exit "myRUNAS command must be specified for check_runas_id"
5329 $myRUNAS krb5_login.sh || \
5330 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5332 mkdir $DIR/d0_runas_test
5334 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5335 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5336 rm -rf $DIR/d0_runas_test
5341 local myRUNAS_UID=$1
5342 local myRUNAS_GID=$2
5345 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5346 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5347 Please set RUNAS_ID to some UID which exists on MDS and client or
5348 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5351 # obtain the UID/GID for MPI_USER
5355 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5356 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5358 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5359 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5362 # obtain and cache Kerberos ticket-granting ticket
5363 refresh_krb5_tgt() {
5364 local myRUNAS_UID=$1
5365 local myRUNAS_GID=$2
5368 if [ -z "$myRUNAS" ]; then
5369 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5372 CLIENTS=${CLIENTS:-$HOSTNAME}
5373 do_nodes $CLIENTS "set -x
5374 if ! $myRUNAS krb5_login.sh; then
5375 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5380 # Run multiop in the background, but wait for it to print
5381 # "PAUSING" to its stdout before returning from this function.
5382 multiop_bg_pause() {
5383 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5387 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5390 echo "$MULTIOP_PROG $FILE v$ARGS"
5391 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5393 echo "TMPPIPE=${TMPPIPE}"
5394 read -t 60 multiop_output < $TMPPIPE
5395 if [ $? -ne 0 ]; then
5400 if [ "$multiop_output" != "PAUSING" ]; then
5401 echo "Incorrect multiop output: $multiop_output"
5416 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5422 inodes_available () {
5423 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5424 sort -un | head -n1) || return 1
5428 mdsrate_inodes_available () {
5429 local min_inodes=$(inodes_available)
5430 echo $((min_inodes * 99 / 100))
5433 # reset llite stat counters
5434 clear_llite_stats(){
5435 lctl set_param -n llite.*.stats 0
5438 # sum llite stat items
5439 calc_llite_stats() {
5440 local res=$(lctl get_param -n llite.*.stats |
5441 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5445 # reset osc stat counters
5447 lctl set_param -n osc.*.osc_stats 0
5450 # sum osc stat items
5452 local res=$(lctl get_param -n osc.*.osc_stats |
5453 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5458 awk '{sum += $1} END { printf("%0.0f", sum) }'
5461 calc_osc_kbytes () {
5462 df $MOUNT > /dev/null
5463 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5466 # save_lustre_params(comma separated facet list, parameter_mask)
5467 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5468 save_lustre_params() {
5474 for facet in ${facets//,/ }; do
5475 node=$(facet_active_host $facet)
5476 [[ *\ $node\ * = " $nodes " ]] && continue
5477 nodes="$nodes $node"
5479 do_node $node "$LCTL get_param $2 |
5480 while read s; do echo $facet \\\$s; done"
5484 # restore lustre parameters from input stream, produces by save_lustre_params
5485 restore_lustre_params() {
5490 while IFS=" =" read facet name val; do
5491 do_facet $facet "$LCTL set_param -n $name $val"
5495 check_catastrophe() {
5496 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5497 local C=$CATASTROPHE
5498 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5500 [ -z "$rnodes" ] && return 0
5503 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5504 echo \\\$(< $C) || echo 0);
5505 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5508 if [ -n "$data" ]; then
5515 # CMD: determine mds index where directory inode presents
5518 local file=$dir/f0.get_mds_dir_tmpfile
5523 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5524 local -a oldused=($iused)
5526 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5528 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5529 local -a newused=($iused)
5532 for ((i=0; i<${#newused[@]}; i++)); do
5533 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5539 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5542 mdsrate_cleanup () {
5544 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5545 --nfiles $3 --dir $4 --filefmt $5 $6
5550 delayed_recovery_enabled () {
5551 local var=${SINGLEMDS}_svc
5552 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5555 ########################
5557 convert_facet2label() {
5560 if [ x$facet = xost ]; then
5564 local varsvc=${facet}_svc
5566 if [ -n ${!varsvc} ]; then
5569 error "No lablel for $facet!"
5573 get_clientosc_proc_path() {
5577 get_lustre_version () {
5578 local facet=${1:-"$SINGLEMDS"}
5579 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5582 lustre_version_code() {
5583 local facet=${1:-"$SINGLEMDS"}
5584 version_code $(get_lustre_version $1)
5587 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5588 # used by MDT would not be changed.
5589 # mdt lov: fsname-mdtlov
5590 # mdt osc: fsname-OSTXXXX-osc
5591 mds_on_old_device() {
5592 local mds=${1:-"$SINGLEMDS"}
5594 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5595 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5596 > /dev/null 2>&1" && return 0
5601 get_mdtosc_proc_path() {
5603 local ost_label=${2:-"*OST*"}
5605 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5606 local mdt_label=$(convert_facet2label $mds_facet)
5607 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5609 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5610 mds_on_old_device $mds_facet; then
5611 echo "${ost_label}-osc"
5613 echo "${ost_label}-osc-${mdt_index}"
5617 get_osc_import_name() {
5620 local label=$(convert_facet2label $ost)
5622 if [ "${facet:0:3}" = "mds" ]; then
5623 get_mdtosc_proc_path $facet $label
5627 get_clientosc_proc_path $label
5631 _wait_import_state () {
5634 local maxtime=${3:-$(max_recovery_time)}
5638 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5639 while [ "${CONN_STATE}" != "${expected}" ]; do
5640 if [ "${expected}" == "DISCONN" ]; then
5641 # for disconn we can check after proc entry is removed
5642 [ "x${CONN_STATE}" == "x" ] && return 0
5643 # with AT enabled, we can have connect request timeout near of
5644 # reconnect timeout and test can't see real disconnect
5645 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5647 [ $i -ge $maxtime ] && \
5648 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5651 # Add uniq for multi-mount case
5652 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5656 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5660 wait_import_state() {
5663 local maxtime=${3:-$(max_recovery_time)}
5666 for param in ${params//,/ }; do
5667 _wait_import_state $state $param $maxtime || return
5671 wait_import_state_mount() {
5672 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5676 wait_import_state $*
5679 # One client request could be timed out because server was not ready
5680 # when request was sent by client.
5681 # The request timeout calculation details :
5683 # /* We give the server rq_timeout secs to process the req, and
5684 # add the network latency for our local timeout. */
5685 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5686 # ptlrpc_at_get_net_latency(request) ;
5688 # ptlrpc_connect_import ()
5689 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5692 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5693 # ptlrpc_at_get_net_latency(request) ->
5694 # at_get (max (iat_net_latency=0, at_min)) = at_min
5697 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5698 # INITIAL_CONNECT_TIMEOUT + at_min
5700 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5701 # because we can not get this value in runtime,
5702 # the value depends on configure options, and it is not stored in /proc.
5704 # #define CONNECTION_SWITCH_MIN 5U
5705 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5707 request_timeout () {
5710 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5711 local init_connect_timeout=$TIMEOUT
5712 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5714 local at_min=$(at_get $facet at_min)
5716 echo $(( init_connect_timeout + at_min ))
5719 _wait_osc_import_state() {
5723 local ost=$(get_osc_import_name $facet $ost_facet)
5724 local param="osc.${ost}.ost_server_uuid"
5728 # 1. wait the deadline of client 1st request (it could be skipped)
5729 # 2. wait the deadline of client 2nd request
5730 local maxtime=$(( 2 * $(request_timeout $facet)))
5732 if [[ $facet == client* ]]; then
5733 # During setup time, the osc might not be setup, it need wait
5734 # until list_param can return valid value. And also if there
5735 # are mulitple osc entries we should list all of them before
5737 params=$($LCTL list_param $param 2>/dev/null || true)
5738 while [ -z "$params" ]; do
5739 if [ $i -ge $maxtime ]; then
5740 echo "can't get $param in $maxtime secs"
5745 params=$($LCTL list_param $param 2>/dev/null || true)
5748 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5749 wait_import_state $expected "$params" $maxtime; then
5750 error "import is not in ${expected} state"
5757 wait_osc_import_state() {
5763 if [[ $facet = mds ]]; then
5764 for num in $(seq $MDSCOUNT); do
5765 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5768 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5772 get_clientmdc_proc_path() {
5780 [ -z "$list" ] && return 0
5782 # Add paths to lustre tests for 32 and 64 bit systems.
5783 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5784 local TESTPATH="$RLUSTRE/tests:"
5785 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5786 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5789 wait_clients_import_state () {
5796 if [ "$FAILURE_MODE" = HARD ]; then
5797 facets=$(facets_on_host $(facet_active_host $facet))
5800 for facet in ${facets//,/ }; do
5801 local label=$(convert_facet2label $facet)
5804 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5805 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5806 *) error "unknown facet!" ;;
5808 local params=$(expand_list $params $proc_path)
5811 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5812 error "import is not in ${expected} state"
5822 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5823 $LCTL get_param obdfilter.*.kbytesavail))
5824 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5825 $LCTL get_param -n obdfilter.*.tot_granted))
5826 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5827 $LCTL get_param -n obdfilter.*.kbytestotal))
5828 for ((i=0; i<${#AVAILA[@]}; i++)); do
5829 local -a AVAIL1=(${AVAILA[$i]//=/ })
5830 local -a TOTAL=(${TOTALA[$i]//=/ })
5831 GRANT=$((${GRANTA[$i]}/1024))
5832 # allow 1% of total space in bavail because of delayed
5833 # allocation with ZFS which might release some free space after
5834 # txg commit. For small devices, we set a mininum of 8MB
5835 local LIMIT=$((${TOTAL} / 100 + 8000))
5836 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5837 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5838 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5839 echo " FULL" || echo
5845 do_facet mgs lctl pool_list $1
5849 local fsname=${1%%.*}
5850 local poolname=${1##$fsname.}
5852 do_facet mgs lctl pool_new $1
5854 # get param should return err unless pool is created
5855 [[ $RC -ne 0 ]] && return $RC
5857 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5858 2>/dev/null || echo foo" "" || RC=1
5859 if [[ $RC -eq 0 ]]; then
5862 error "pool_new failed $1"
5867 add_pool_to_list () {
5868 local fsname=${1%%.*}
5869 local poolname=${1##$fsname.}
5871 local listvar=${fsname}_CREATED_POOLS
5872 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5875 remove_pool_from_list () {
5876 local fsname=${1%%.*}
5877 local poolname=${1##$fsname.}
5879 local listvar=${fsname}_CREATED_POOLS
5880 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5883 destroy_pool_int() {
5885 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5886 awk '$1 !~ /^Pool:/ {print $1}')
5887 for ost in $OSTS; do
5888 do_facet mgs lctl pool_remove $1 $ost
5890 do_facet mgs lctl pool_destroy $1
5893 # <fsname>.<poolname> or <poolname>
5895 local fsname=${1%%.*}
5896 local poolname=${1##$fsname.}
5898 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5902 pool_list $fsname.$poolname || return $?
5904 destroy_pool_int $fsname.$poolname
5906 [[ $RC -ne 0 ]] && return $RC
5908 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5909 2>/dev/null || echo foo" "foo" || RC=1
5911 if [[ $RC -eq 0 ]]; then
5912 remove_pool_from_list $fsname.$poolname
5914 error "destroy pool failed $1"
5920 local fsname=${1:-$FSNAME}
5922 local listvar=${fsname}_CREATED_POOLS
5926 [ x${!listvar} = x ] && return 0
5928 echo destroy the created pools: ${!listvar}
5929 for poolname in ${!listvar//,/ }; do
5930 destroy_pool $fsname.$poolname
5935 local fsname=${1:-$FSNAME}
5937 destroy_pools $fsname
5943 local ts=$(date +%s)
5946 if [[ ! -f "$YAML_LOG" ]]; then
5947 # init_logging is not performed before gather_logs,
5948 # so the $LOGDIR needs to be checked here
5949 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5952 [ -f $LOGDIR/shared ] && docp=false
5954 # dump lustre logs, dmesg
5956 prefix="$TESTLOG_PREFIX.$TESTNAME"
5958 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5960 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5961 echo "Dumping logs only on local client."
5962 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5963 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5968 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5969 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5970 if [ ! -f $LOGDIR/shared ]; then
5971 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5984 for i in $(seq 0 $num_mntpts); do
5985 cmd="ls -laf ${mntpt_root}$i/$dir"
5991 for pid in $pids; do
5998 # target_start_and_reset_recovery_timer()
5999 # service_time = at_est2timeout(service_time);
6000 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
6001 # INITIAL_CONNECT_TIMEOUT);
6002 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
6003 #define CONNECTION_SWITCH_INC 1
6004 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6005 #define CONNECTION_SWITCH_MIN 5U
6007 max_recovery_time () {
6008 local init_connect_timeout=$(( TIMEOUT / 20 ))
6009 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6011 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
6016 get_clients_mount_count () {
6017 local clients=${CLIENTS:-`hostname`}
6019 # we need to take into account the clients mounts and
6020 # exclude mds/ost mounts if any;
6021 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6025 PROC_CLI="srpc_info"
6033 if [ $M -lt $N ]; then
6037 while [ $N -lt $M ]; do
6047 calc_connection_cnt() {
6050 # MDT->MDT = 2 * C(M, 2)
6054 comb_m2=$(combination $MDSCOUNT 2)
6056 local num_clients=$(get_clients_mount_count)
6058 local cnt_mdt2mdt=$((comb_m2 * 2))
6059 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6060 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6061 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6062 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6063 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6064 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6078 local cmd="$tgt.srpc.flavor"
6080 if [ $net == "any" ]; then
6085 if [ $dir != "any" ]; then
6090 log "Setting sptlrpc rule: $cmd"
6091 do_facet mgs "$LCTL conf_param $cmd"
6100 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6101 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6103 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6105 if [ "x$bulkspec" != "x" ]; then
6106 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6108 if [ "x$algs" != "x" ]; then
6109 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6111 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6112 if [ $bulk == "bulkn" ]; then
6113 bulk_count=`echo "$output" | grep "bulk flavor" \
6114 | grep "null/null" | wc -l`
6115 elif [ $bulk == "bulki" ]; then
6116 bulk_count=`echo "$output" | grep "bulk flavor" \
6117 | grep "/null" | grep -v "null/" | wc -l`
6119 bulk_count=`echo "$output" | grep "bulk flavor" \
6120 | grep -v "/null" | grep -v "null/" | wc -l`
6124 [ $bulk_count -lt $count ] && count=$bulk_count
6135 local clients=${CLIENTS:-`hostname`}
6137 for c in ${clients//,/ }; do
6138 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6139 tmpcnt=`count_flvr "$output" $flavor`
6140 cnt=$((cnt + tmpcnt))
6150 local clients=${CLIENTS:-`hostname`}
6152 for c in ${clients//,/ }; do
6153 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6154 tmpcnt=`count_flvr "$output" $flavor`
6155 cnt=$((cnt + tmpcnt))
6165 if [ $MDSCOUNT -le 1 ]; then
6170 for num in `seq $MDSCOUNT`; do
6171 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6172 tmpcnt=`count_flvr "$output" $flavor`
6173 cnt=$((cnt + tmpcnt))
6184 for num in `seq $MDSCOUNT`; do
6185 mdtosc=$(get_mdtosc_proc_path mds$num)
6186 mdtosc=${mdtosc/-MDT*/-MDT\*}
6187 output=$(do_facet mds$num lctl get_param -n \
6188 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6189 tmpcnt=`count_flvr "$output" $flavor`
6190 cnt=$((cnt + tmpcnt))
6199 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6200 count_flvr "$output" $flavor
6205 local dir=$1 # from to
6206 local flavor=$2 # flavor expected
6209 if [ $dir == "cli2mdt" ]; then
6210 res=`flvr_cnt_cli2mdt $flavor`
6211 elif [ $dir == "cli2ost" ]; then
6212 res=`flvr_cnt_cli2ost $flavor`
6213 elif [ $dir == "mdt2mdt" ]; then
6214 res=`flvr_cnt_mdt2mdt $flavor`
6215 elif [ $dir == "mdt2ost" ]; then
6216 res=`flvr_cnt_mdt2ost $flavor`
6217 elif [ $dir == "all2ost" ]; then
6218 res1=`flvr_cnt_mdt2ost $flavor`
6219 res2=`flvr_cnt_cli2ost $flavor`
6220 res=$((res1 + res2))
6221 elif [ $dir == "all2mdt" ]; then
6222 res1=`flvr_cnt_mdt2mdt $flavor`
6223 res2=`flvr_cnt_cli2mdt $flavor`
6224 res=$((res1 + res2))
6225 elif [ $dir == "all2all" ]; then
6226 res1=`flvr_cnt_mdt2ost $flavor`
6227 res2=`flvr_cnt_cli2ost $flavor`
6228 res3=`flvr_cnt_mdt2mdt $flavor`
6229 res4=`flvr_cnt_cli2mdt $flavor`
6230 res=$((res1 + res2 + res3 + res4))
6238 local dir=$1 # from to
6239 local flavor=$2 # flavor expected
6240 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6244 for ((i=0;i<20;i++)); do
6245 echo -n "checking $dir..."
6246 res=$(do_check_flavor $dir $flavor)
6247 echo "found $res/$expect $flavor connections"
6248 [ $res -ge $expect ] && return 0
6252 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6256 restore_to_default_flavor()
6258 local proc="mgs.MGS.live.$FSNAME"
6260 echo "restoring to default flavor..."
6262 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6264 # remove all existing rules if any
6265 if [ $nrule -ne 0 ]; then
6266 echo "$nrule existing rules"
6267 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6268 echo "remove rule: $rule"
6269 spec=`echo $rule | awk -F = '{print $1}'`
6270 do_facet mgs "$LCTL conf_param -d $spec"
6274 # verify no rules left
6275 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6276 [ $nrule -ne 0 ] && error "still $nrule rules left"
6278 # wait for default flavor to be applied
6279 # currently default flavor for all connections are 'null'
6280 wait_flavor all2all null
6281 echo "now at default flavor settings"
6286 local flavor=${1:-null}
6288 echo "setting all flavor to $flavor"
6290 # FIXME need parameter to this fn
6291 # and remove global vars
6292 local cnt_all2all=$(calc_connection_cnt all2all)
6294 local res=$(do_check_flavor all2all $flavor)
6295 if [ $res -eq $cnt_all2all ]; then
6296 echo "already have total $res $flavor connections"
6300 echo "found $res $flavor out of total $cnt_all2all connections"
6301 restore_to_default_flavor
6303 [[ $flavor = null ]] && return 0
6305 set_rule $FSNAME any any $flavor
6306 wait_flavor all2all $flavor
6312 # Checking for shared logdir
6313 if [ ! -d $dir ]; then
6314 # Not found. Create local logdir
6317 touch $dir/check_file.$(hostname -s)
6322 check_write_access() {
6324 local list=${2:-$(comma_list $(nodes_list))}
6328 for node in ${list//,/ }; do
6329 file=$dir/check_file.$(short_nodename $node)
6330 if [[ ! -f "$file" ]]; then
6331 # Logdir not accessible/writable from this node.
6334 rm -f $file || return 1
6340 if [[ -n $YAML_LOG ]]; then
6343 local SAVE_UMASK=`umask`
6346 export YAML_LOG=${LOGDIR}/results.yml
6350 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6351 if check_shared_dir $LOGDIR; then
6352 touch $LOGDIR/shared
6353 echo "Logging to shared log directory: $LOGDIR"
6355 echo "Logging to local directory: $LOGDIR"
6358 yml_nodes_file $LOGDIR >> $YAML_LOG
6359 yml_results_file >> $YAML_LOG
6366 yml_log_test $1 >> $YAML_LOG
6370 yml_log_test_status $@ >> $YAML_LOG
6373 log_sub_test_begin() {
6374 yml_log_sub_test_begin "$@" >> $YAML_LOG
6377 log_sub_test_end() {
6378 yml_log_sub_test_end "$@" >> $YAML_LOG
6384 local llverdev_opts=$2
6385 local devname=$(basename $1)
6386 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6387 # loop devices aren't in /proc/partitions
6388 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6390 size=$(($size / 1024 / 1024)) # Gb
6392 local partial_arg=""
6393 # Run in partial (fast) mode if the size
6394 # of a partition > 1 GB
6395 [ $size -gt 1 ] && partial_arg="-p"
6397 llverdev --force $partial_arg $llverdev_opts $dev
6403 local llverfs_opts=$2
6404 local use_partial_arg=$3
6405 local partial_arg=""
6406 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6408 # Run in partial (fast) mode if the size
6409 # of a partition > 1 GB
6410 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6412 llverfs $partial_arg $llverfs_opts $dir
6415 #Remove objects from OST
6416 remove_ost_objects() {
6422 local mntpt=$(facet_mntpt $facet)
6423 local opts=$OST_MOUNT_OPTS
6427 echo "removing objects from $ostdev on $facet: $objids"
6428 if ! test -b $ostdev; then
6429 opts=$(csa_add "$opts" -o loop)
6431 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6434 for i in $objids; do
6435 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6437 umount -f $mntpt || return $?
6441 #Remove files from MDT
6442 remove_mdt_files() {
6447 local mntpt=$(facet_mntpt $facet)
6448 local opts=$MDS_MOUNT_OPTS
6450 echo "removing files from $mdtdev on $facet: $files"
6451 if [ $(facet_fstype $facet) == ldiskfs ] &&
6452 ! do_facet $facet test -b $mdtdev; then
6453 opts=$(csa_add "$opts" -o loop)
6455 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6459 rm $mntpt/ROOT/$f || { rc=$?; break; }
6461 umount -f $mntpt || return $?
6465 duplicate_mdt_files() {
6470 local mntpt=$(facet_mntpt $facet)
6471 local opts=$MDS_MOUNT_OPTS
6473 echo "duplicating files on $mdtdev on $facet: $files"
6474 mkdir -p $mntpt || return $?
6475 if [ $(facet_fstype $facet) == ldiskfs ] &&
6476 ! do_facet $facet test -b $mdtdev; then
6477 opts=$(csa_add "$opts" -o loop)
6479 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6490 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6491 pushd $mntpt/ROOT > /dev/null || return $?
6494 touch $f.bad || return $?
6495 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6497 [ $rc -eq 0 ] || return $rc
6498 setfattr --restore $tmp || return $?
6504 local devs=${1//,/ }
6507 local rslt=$TMP/sgpdd_survey
6509 # sgpdd-survey cleanups ${rslt}.* files
6511 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6517 # returns the canonical name for an ldiskfs device
6522 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6523 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6524 echo dm-\\\${foo##*:};
6526 echo \\\$(basename \\\$dv);
6530 is_sanity_benchmark() {
6531 local benchmarks="dbench bonnie iozone fsx"
6533 for b in $benchmarks; do
6534 if [ "$b" == "$suite" ]; then
6542 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6546 # Get the available size (KB) of a given obd target.
6553 [[ $facet != client ]] || return 0
6555 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6560 # Get the page size (bytes) on a given facet node.
6566 size=$(do_facet $facet getconf PAGE_SIZE)
6567 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6572 # Get the block count of the filesystem.
6579 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6580 awk '/^Block count:/ {print $3}')
6584 # Get the block size of the filesystem.
6590 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6591 awk '/^Block size:/ {print $3}')
6595 # Check whether the "large_xattr" feature is enabled or not.
6596 large_xattr_enabled() {
6597 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6599 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6601 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6602 grep -E -q '(ea_inode|large_xattr)'"
6603 return ${PIPESTATUS[0]}
6606 # Get the maximum xattr size supported by the filesystem.
6610 if large_xattr_enabled; then
6611 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6614 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6615 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6617 # maximum xattr size = size of block - size of header -
6618 # size of 1 entry - 4 null bytes
6619 size=$((block_size - 32 - 32 - 4))
6625 # Dump the value of the named xattr from a file.
6630 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6633 # Generate a string with size of $size bytes.
6635 local size=${1:-1024} # in bytes
6637 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6640 reformat_external_journal() {
6643 if [ ! -z ${EJOURNAL} ]; then
6644 local rcmd="do_facet $facet"
6646 echo "reformat external journal on $facet:${EJOURNAL}"
6647 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6651 # MDT file-level backup/restore
6652 mds_backup_restore() {
6655 local devname=$(mdsdevname $(facet_number $facet))
6656 local mntpt=$(facet_mntpt brpt)
6657 local rcmd="do_facet $facet"
6658 local metaea=${TMP}/backup_restore.ea
6659 local metadata=${TMP}/backup_restore.tgz
6660 local opts=${MDS_MOUNT_OPTS}
6661 local svc=${facet}_svc
6663 if ! ${rcmd} test -b ${devname}; then
6664 opts=$(csa_add "$opts" -o loop)
6667 echo "file-level backup/restore on $facet:${devname}"
6669 # step 1: build mount point
6670 ${rcmd} mkdir -p $mntpt
6671 # step 2: cleanup old backup
6672 ${rcmd} rm -f $metaea $metadata
6674 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6675 if [ ! -z $igif ]; then
6676 # step 3.5: rm .lustre
6677 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6679 # step 4: backup metaea
6681 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6683 # step 5: backup metadata
6685 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6687 ${rcmd} umount -d $mntpt || return 4
6688 # step 7: reformat external journal if needed
6689 reformat_external_journal $facet || return 5
6690 # step 8: reformat dev
6691 echo "reformat new device"
6692 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6693 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6694 > /dev/null || exit 6
6696 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6697 # step 10: restore metadata
6699 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6700 # step 11: restore metaea
6702 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6703 # step 12: remove recovery logs
6704 echo "remove recovery logs"
6705 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6706 # step 13: umount dev
6707 ${rcmd} umount -d $mntpt || return 10
6708 # step 14: cleanup tmp backup
6709 ${rcmd} rm -f $metaea $metadata
6710 # step 15: reset device label - it's not virgin on
6711 ${rcmd} e2label $devname ${!svc}
6718 local devname=$(mdsdevname $(facet_number $facet))
6719 local mntpt=$(facet_mntpt brpt)
6720 local rcmd="do_facet $facet"
6721 local opts=${MDS_MOUNT_OPTS}
6723 if ! ${rcmd} test -b ${devname}; then
6724 opts=$(csa_add "$opts" -o loop)
6727 echo "removing OI files on $facet: idx=${idx}"
6729 # step 1: build mount point
6730 ${rcmd} mkdir -p $mntpt
6732 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6733 if [ -z $idx ]; then
6734 # step 3: remove all OI files
6735 ${rcmd} rm -fv $mntpt/oi.16*
6736 elif [ $idx -lt 2 ]; then
6737 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6741 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6742 for ((i=${idx}; i<64; i=$((i * idx)))); do
6743 ${rcmd} rm -fv $mntpt/oi.16.${i}
6747 ${rcmd} umount -d $mntpt || return 2
6748 # OI files will be recreated when mounted as lustre next time.
6751 # generate maloo upload-able log file name
6752 # \param logname specify unique part of file name
6753 generate_logname() {
6754 local logname=${1:-"default_logname"}
6756 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6759 # make directory on different MDTs
6767 local stripe_count=2
6777 *) error "Only creating single directory is supported";;
6780 child=$(basename $path)
6781 parent=$(dirname $path)
6783 if [ "$option" == "-p" -o "$option2" == "-p" ]; then
6784 if [ -d $parent/$child ]; then
6790 if [ "${option:0:2}" == "-c" ]; then
6791 stripe_count=$(echo $option | sed 's/^-c//')
6794 if [ "${option2:0:2}" == "-c" ]; then
6795 stripe_count=$(echo $option2 | sed 's/^-c//')
6798 if [ ! -d ${parent} ]; then
6799 if [ "$p_option" == "-p" ]; then
6806 if [ $MDSCOUNT -le 1 ]; then
6807 mkdir $p_option $parent/$child || rc=$?
6809 local mdt_idx=$($LFS getstripe -M $parent)
6810 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6812 mdt_idx=$((test_num % MDSCOUNT))
6813 echo "striped dir -i$mdt_idx -c$stripe_count $path"
6814 $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
6819 # find the smallest and not in use file descriptor
6822 local max_fd=$(ulimit -n)
6824 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6827 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
6831 check_mount_and_prep()
6833 is_mounted $MOUNT || setupall
6835 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
6836 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
6839 # calcule how many ost-objects to be created.
6840 precreated_ost_obj_count()
6844 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
6845 local ost_name="OST$(printf '%04x' $ost_idx)"
6846 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
6847 local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6848 osp.$proc_path.prealloc_last_id)
6849 local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6850 osp.$proc_path.prealloc_next_id)
6852 echo $((last_id - next_id + 1))