3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
18 # specify environment variable containing batch job name for server statistics
19 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
21 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
22 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
23 export LOAD_LLOOP=${LOAD_LLOOP:-false}
25 #export PDSH="pdsh -S -Rssh -w"
26 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
55 [[ $DIR/ = $MOUNT/* ]] || \
56 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
57 [[ $DIR1/ = $MOUNT1/* ]] || \
58 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
59 [[ $DIR2/ = $MOUNT2/* ]] || \
60 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
62 [ -n "$failed" ] && exit 99 || true
66 echo "usage: $0 [-r] [-f cfgfile]"
74 [ "$TESTSUITE" == "lfsck" ] && return 0
75 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
77 local form="%-13s %-17s %-9s %s %s\n"
78 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
79 echo "------------------------------------------------------------------------------------"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 [ "${!O}" = "no" ] && continue || true
83 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
84 local log=${TMP}/${o}.log
85 if is_sanity_benchmark $o; then
86 log=${TMP}/sanity-benchmark.log
91 local status=Unfinished
93 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
95 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
96 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
97 total=$(grep duration $log | awk '{ print $2 }')
98 if [ "${!O}" = "done" ]; then
102 local durations=$(egrep "^PASS|^FAIL" $log |
103 tr -d "("| sed s/s\)$//g |
104 awk '{ print $2":"$3"|" }')
105 details=$(printf "%s\n%s %s %s\n" "$details" \
106 "DDETAILS" "$O" "$(echo $durations)")
109 printf "$form" $status "$O" "${total}" "E=$skipped"
110 printf "$form" "-" "-" "-" "S=$(echo $slow)"
113 for O in $DEFAULT_SUITES; do
114 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
115 if [ "${!O}" = "no" ]; then
116 printf "$form" "Skipped" "$O" ""
120 # print the detailed tests durations if DDETAILS=true
127 export LUSTRE=$(absolute_path $LUSTRE)
128 export TESTSUITE=$(basename $0 .sh)
129 export TEST_FAILED=false
130 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
131 export RPC_MODE=${RPC_MODE:-false}
133 export MKE2FS=$MKE2FS
134 if [ -z "$MKE2FS" ]; then
135 if which mkfs.ldiskfs >/dev/null 2>&1; then
136 export MKE2FS=mkfs.ldiskfs
142 export DEBUGFS=$DEBUGFS
143 if [ -z "$DEBUGFS" ]; then
144 if which debugfs.ldiskfs >/dev/null 2>&1; then
145 export DEBUGFS=debugfs.ldiskfs
147 export DEBUGFS=debugfs
151 export TUNE2FS=$TUNE2FS
152 if [ -z "$TUNE2FS" ]; then
153 if which tunefs.ldiskfs >/dev/null 2>&1; then
154 export TUNE2FS=tunefs.ldiskfs
156 export TUNE2FS=tune2fs
160 export E2LABEL=$E2LABEL
161 if [ -z "$E2LABEL" ]; then
162 if which label.ldiskfs >/dev/null 2>&1; then
163 export E2LABEL=label.ldiskfs
165 export E2LABEL=e2label
169 export DUMPE2FS=$DUMPE2FS
170 if [ -z "$DUMPE2FS" ]; then
171 if which dumpfs.ldiskfs >/dev/null 2>&1; then
172 export DUMPE2FS=dumpfs.ldiskfs
174 export DUMPE2FS=dumpe2fs
178 export E2FSCK=$E2FSCK
179 if [ -z "$E2FSCK" ]; then
180 if which fsck.ldiskfs >/dev/null 2>&1; then
181 export E2FSCK=fsck.ldiskfs
187 export RESIZE2FS=$RESIZE2FS
188 if [ -z "$RESIZE2FS" ]; then
189 if which resizefs.ldiskfs >/dev/null 2>&1; then
190 export RESIZE2FS=resizefs.ldiskfs
192 export RESIZE2FS=resize2fs
196 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
197 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
198 export FSCK_MAX_ERR=4 # File system errors left uncorrected
200 export ZFS=${ZFS:-zfs}
201 export ZPOOL=${ZPOOL:-zpool}
202 export ZDB=${ZDB:-zdb}
203 export PARTPROBE=${PARTPROBE:-partprobe}
205 #[ -d /r ] && export ROOT=${ROOT:-/r}
206 export TMP=${TMP:-$ROOT/tmp}
207 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
208 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
209 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
211 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
212 if ! echo $PATH | grep -q $LUSTRE/utils; then
213 export PATH=$LUSTRE/utils:$PATH
215 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
216 export PATH=$LUSTRE/utils/gss:$PATH
218 if ! echo $PATH | grep -q $LUSTRE/tests; then
219 export PATH=$LUSTRE/tests:$PATH
221 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
222 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
224 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
225 [ ! -f "$LST" ] && export LST=$(which lst)
226 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
227 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
228 export MCREATE=${MCREATE:-mcreate}
229 # Ubuntu, at least, has a truncate command in /usr/bin
230 # so fully path our truncate command.
231 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
232 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
233 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
234 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
235 export PATH=$LUSTRE/tests/racer:$PATH:
237 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
238 export PATH=$LUSTRE/tests/mpi:$PATH
240 export RSYNC_RSH=${RSYNC_RSH:-rsh}
242 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
243 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
244 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
245 [ ! -f "$LFS" ] && export LFS=$(which lfs)
246 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
247 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
249 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
250 if [ ! -f "$L_GETIDENTITY" ]; then
251 if `which l_getidentity > /dev/null 2>&1`; then
252 export L_GETIDENTITY=$(which l_getidentity)
254 export L_GETIDENTITY=NONE
257 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
258 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
259 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
260 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
261 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
262 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
263 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
264 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
265 [ ! -f "$LUSTRE_RMMOD" ] &&
266 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
267 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
268 [ ! -f "$LFS_MIGRATE" ] &&
269 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
270 export NAME=${NAME:-local}
271 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
272 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
273 export LGSSD=$(which lgssd)
274 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
275 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
276 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
278 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
281 if [ "$ACCEPTOR_PORT" ]; then
282 export PORT_OPT="--port $ACCEPTOR_PORT"
287 echo "Using GSS/krb5 ptlrpc security flavor"
288 which lgss_keyring > /dev/null 2>&1 || \
289 error_exit "built with gss disabled! SEC=$SEC"
300 IDENTITY_UPCALL=false
304 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
306 # Paths on remote nodes, if different
307 export RLUSTRE=${RLUSTRE:-$LUSTRE}
308 export RPWD=${RPWD:-$PWD}
309 export I_MOUNTED=${I_MOUNTED:-"no"}
310 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
311 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
312 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
313 ! -f $LUSTRE/mdt/mdt.ko ]; then
314 export CLIENTMODSONLY=yes
317 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
318 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
322 while getopts "rvwf:" opt $*; do
325 r) REFORMAT=--reformat;;
327 w) WRITECONF=writeconf;;
332 shift $((OPTIND - 1))
335 # print the durations of each test if "true"
336 DDETAILS=${DDETAILS:-false}
337 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
347 ncpts=$(do_facet $facet "lctl get_param -n " \
348 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
350 if [ $ncpts -eq 0 ]; then
358 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
359 eval set -- $(tr "[:punct:]" " " <<< $*)
361 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
364 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
365 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
368 /sbin/lsmod | grep -q "^\<$1\>"
371 # Load a module on the system where this is running.
373 # 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
722 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
730 # maybe cleanup credential cache?
736 local var=${facet}_svc
744 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
745 tr '[:lower:]' '[:upper:]'
751 if [ $facet == mgs ]; then
755 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
763 if [ -n "${!var}" ]; then
768 var=$(facet_type $facet)FSTYPE
769 if [ -n "${!var}" ]; then
774 if [ -n "$FSTYPE" ]; then
779 if [[ $facet == mgs ]] && combined_mgs_mds; then
791 local facets=$(get_facets)
794 for facet in ${facets//,/ }; do
795 if [ $node == $(facet_host $facet) ] ||
796 [ $node == "$(facet_failover_host $facet)" ]; then
797 fstype=$(facet_fstype $facet)
798 if [[ $fstypes != *$fstype* ]]; then
799 fstypes+="${fstypes:+,}$fstype"
810 local fstype=$(facet_fstype $facet)
814 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
816 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
817 ${dev} 2>/dev/null");;
819 error "unknown fstype!";;
827 local device=$(mdsdevname $num)
828 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
834 local device=$(ostdevname $num)
835 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
840 # Get the device of a facet.
847 mgs) device=$(mgsdevname) ;;
848 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
849 ost*) device=$(ostdevname $(facet_number $facet)) ;;
850 fs2mds) device=$(mdsdevname 1_2) ;;
851 fs2ost) device=$(ostdevname 1_2) ;;
852 fs3ost) device=$(ostdevname 2_2) ;;
860 # Get the virtual device of a facet.
867 mgs) device=$(mgsvdevname) ;;
868 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
869 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
870 fs2mds) device=$(mdsvdevname 1_2) ;;
871 fs2ost) device=$(ostvdevname 1_2) ;;
872 fs3ost) device=$(ostvdevname 2_2) ;;
880 # Re-read the partition table on failover partner host.
881 # After a ZFS storage pool is created on a shared device, the partition table
882 # on the device may change. However, the operating system on the failover
883 # host may not notice the change automatically. Without the up-to-date partition
884 # block devices, 'zpool import ..' cannot find the labels, whose positions are
885 # relative to partition rather than disk beginnings.
887 # This function performs partprobe on the failover host to make it re-read the
890 refresh_partition_table() {
895 host=$(facet_passive_host $facet)
896 if [[ -n "$host" ]]; then
897 do_node $host "$PARTPROBE $device"
902 # Get ZFS storage pool name.
909 device=$(facet_device $facet)
910 # poolname is string before "/"
911 poolname="${device%%/*}"
917 # Create ZFS storage pool.
924 local opts=${@:-"-o cachefile=none"}
926 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
927 $ZPOOL create -f $opts $poolname $vdev"
931 # Create ZFS file system.
937 local opts=${@:-"-o mountpoint=legacy"}
939 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
940 $ZFS create $opts $dataset"
944 # Export ZFS storage pool.
945 # Before exporting the pool, all datasets within the pool should be unmounted.
953 poolname=$(zpool_name $facet)
955 if [[ -n "$poolname" ]]; then
956 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
957 grep -q ^$poolname/ /proc/mounts ||
958 $ZPOOL export $opts $poolname"
963 # Destroy ZFS storage pool.
964 # Destroy the given pool and free up any devices for other use. This command
965 # tries to unmount any active datasets before destroying the pool.
966 # -f Force any active datasets contained within the pool to be unmounted.
970 local poolname=${2:-$(zpool_name $facet)}
972 if [[ -n "$poolname" ]]; then
973 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
974 $ZPOOL destroy -f $poolname"
979 # Import ZFS storage pool.
980 # Force importing, even if the pool appears to be potentially active.
985 local opts=${@:-"-o cachefile=none"}
988 poolname=$(zpool_name $facet)
990 if [[ -n "$poolname" ]]; then
991 opts+=" -d $(dirname $(facet_vdevice $facet))"
992 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
993 $ZPOOL import -f $opts $poolname"
998 # Set the "cachefile=none" property on ZFS storage pool so that the pool
999 # is not automatically imported on system startup.
1001 # In a failover environment, this will provide resource level fencing which
1002 # will ensure that the same ZFS storage pool will not be imported concurrently
1003 # on different nodes.
1005 disable_zpool_cache() {
1009 poolname=$(zpool_name $facet)
1011 if [[ -n "$poolname" ]]; then
1012 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1017 # This and set_osd_param() shall be used to access OSD parameters
1018 # once existed under "obdfilter":
1023 # writethrough_cache_enable
1027 local device=${2:-$FSNAME-OST*}
1030 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1031 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1036 local device=${2:-$FSNAME-OST*}
1040 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1041 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1045 local dz=${1:-$DEBUG_SIZE}
1047 if [ -f /sys/devices/system/cpu/possible ]; then
1048 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1050 local cpus=$(getconf _NPROCESSORS_CONF)
1053 # bug 19944, adjust size to be -gt num_possible_cpus()
1054 # promise 2MB for every cpu at least
1055 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1058 lctl set_param debug_mb=$dz
1061 set_default_debug () {
1062 local debug=${1:-"$PTLDEBUG"}
1063 local subsys=${2:-"$SUBSYSTEM"}
1064 local debug_size=${3:-$DEBUG_SIZE}
1066 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1067 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1069 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1072 set_default_debug_nodes () {
1075 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1076 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1080 do_rpc_nodes "$nodes" set_default_debug \
1081 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1084 set_default_debug_facet () {
1086 local node=$(facet_active_host $facet)
1087 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1089 set_default_debug_nodes $node
1094 local facets=${1:-$(get_facets)}
1097 for facet in ${facets//,/ }; do
1100 [ $RC -eq 0 ] && continue
1102 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1103 skip "Restart of $facet failed!." && touch $LU482_FAILED
1105 error "Restart of $facet failed!"
1112 # Add argument "arg" (e.g., "loop") to the comma-separated list
1113 # of arguments for option "opt" (e.g., "-o") on command
1114 # line "opts" (e.g., "-o flock").
1120 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1122 if echo "$opts" | grep -q $opt_pattern; then
1123 opts=$(echo "$opts" | sed -e \
1124 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1126 opts+="${opts:+ }$opt $arg"
1134 local dev=$(facet_active $facet)_dev
1135 local opt=${facet}_opt
1136 local mntpt=$(facet_mntpt $facet)
1137 local opts="${!opt} $@"
1139 if [ $(facet_fstype $facet) == ldiskfs ] &&
1140 ! do_facet $facet test -b ${!dev}; then
1141 opts=$(csa_add "$opts" -o loop)
1144 if [[ $(facet_fstype $facet) == zfs ]]; then
1145 # import ZFS storage pool
1146 import_zpool $facet || return ${PIPESTATUS[0]}
1149 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1150 # for testing LU-482 error handling in mount_facets() and test_0a()
1151 if [ -f $TMP/test-lu482-trigger ]; then
1154 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1158 if [ $RC -ne 0 ]; then
1159 echo "Start of ${!dev} on ${facet} failed ${RC}"
1161 set_default_debug_facet $facet
1163 label=$(devicelabel ${facet} ${!dev})
1164 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1165 eval export ${facet}_svc=${label}
1166 echo Started ${label}
1171 # start facet device options
1177 eval export ${facet}_dev=${device}
1178 eval export ${facet}_opt=\"$@\"
1180 local varname=${facet}failover_dev
1181 if [ -n "${!varname}" ] ; then
1182 eval export ${facet}failover_dev=${!varname}
1184 eval export ${facet}failover_dev=$device
1187 local mntpt=$(facet_mntpt $facet)
1188 do_facet ${facet} mkdir -p $mntpt
1189 eval export ${facet}_MOUNT=$mntpt
1190 mount_facet ${facet}
1193 if [[ $facet == mds* ]]; then
1195 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1206 local HOST=`facet_active_host $facet`
1207 [ -z $HOST ] && echo stop: no host for $facet && return 0
1209 local mntpt=$(facet_mntpt $facet)
1210 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1211 if [ ${running} -ne 0 ]; then
1212 echo "Stopping $mntpt (opts:$@) on $HOST"
1213 do_facet ${facet} umount -d $@ $mntpt
1216 # umount should block, but we should wait for unrelated obd's
1217 # like the MGS or MGC to also stop.
1218 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1220 if [[ $(facet_fstype $facet) == zfs ]]; then
1221 # export ZFS storage pool
1226 # save quota version (both administrative and operational quotas)
1227 # add an additional parameter if mountpoint is ever different from $MOUNT
1229 # XXX This function is kept for interoperability with old server (< 2.3.50),
1230 # it should be removed whenever we drop the interoperability for such
1232 quota_save_version() {
1233 local fsname=${2:-$FSNAME}
1235 local ver=$(tr -c -d "123" <<< $spec)
1236 local type=$(tr -c -d "ug" <<< $spec)
1238 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1240 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1242 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1244 local osts=$(get_facets OST)
1245 for ost in ${osts//,/ }; do
1247 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1251 # client could mount several lustre
1253 # XXX This function is kept for interoperability with old server (< 2.3.50),
1254 # it should be removed whenever we drop the interoperability for such
1257 local fsname=${1:-$FSNAME}
1259 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1261 do_nodes $(comma_list $(osts_nodes)) \
1262 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1266 # XXX This function is kept for interoperability with old server (< 2.3.50),
1267 # it should be removed whenever we drop the interoperability for such
1269 restore_quota_old() {
1270 local mntpt=${1:-$MOUNT}
1271 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1272 if [ ! "$old_QUOTA_TYPE" ] ||
1273 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1276 quota_save_version $old_QUOTA_TYPE
1279 # XXX This function is kept for interoperability with old server (< 2.3.50),
1280 # it should be removed whenever we drop the interoperability for such
1285 # no quota enforcement for now and accounting works out of the box
1288 # We need save the original quota_type params, and restore them after testing
1290 # Suppose that quota type the same on mds and ost
1291 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1292 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1293 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1294 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1295 export old_QUOTA_TYPE=$quota_type
1296 quota_save_version $QUOTA_TYPE
1298 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1299 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1302 local quota_usrs=$QUOTA_USERS
1304 # get_filesystem_size
1305 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1306 local blk_soft=$((disksz + 1024))
1307 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1309 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1310 local i_soft=$Inodes
1311 local i_hard=$((i_soft + i_soft / 20))
1313 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1314 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1317 for usr in $quota_usrs; do
1318 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1320 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1322 eval $cmd || error "$cmd FAILED!"
1324 # display the quota status
1325 echo "Quota settings for $usr : "
1326 $LFS quota -v -u $usr $mntpt || true
1330 # get mdt quota type
1332 local varsvc=${SINGLEMDS}_svc
1333 do_facet $SINGLEMDS $LCTL get_param -n \
1334 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1337 # get ost quota type
1339 # All OSTs should have same quota type
1340 local varsvc=ost1_svc
1341 do_facet ost1 $LCTL get_param -n \
1342 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1345 # restore old quota type settings
1347 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1352 if [ "$old_MDT_QUOTA_TYPE" ]; then
1353 do_facet mgs $LCTL conf_param \
1354 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1356 if [ "$old_OST_QUOTA_TYPE" ]; then
1357 do_facet mgs $LCTL conf_param \
1358 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1362 # Handle the case when there is a space in the lfs df
1363 # "filesystem summary" line the same as when there is no space.
1364 # This will allow fixing the "lfs df" summary line in the future.
1366 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1369 # Get free inodes on the MDT specified by mdt index, free indoes on
1370 # the whole filesystem will be returned when index == -1.
1376 if [ $index -eq -1 ]; then
1379 mdt_uuid=$(mdtuuid_from_index $index)
1382 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1387 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1394 # save old quota type & set new quota type
1395 local mdt_qtype=$(mdt_quota_type)
1396 local ost_qtype=$(ost_quota_type)
1398 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1399 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1401 export old_MDT_QUOTA_TYPE=$mdt_qtype
1402 export old_OST_QUOTA_TYPE=$ost_qtype
1404 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1405 error "set mdt quota type failed"
1406 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1407 error "set ost quota type failed"
1409 local quota_usrs=$QUOTA_USERS
1411 # get_filesystem_size
1412 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1413 local blk_soft=$((disksz + 1024))
1414 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1416 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1417 local i_soft=$inodes
1418 local i_hard=$((i_soft + i_soft / 20))
1420 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1421 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1422 "inode-hardlimit: $i_hard"
1425 for usr in $quota_usrs; do
1426 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1428 cmd="$LFS setquota -$type $usr -b $blk_soft"
1429 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1431 eval $cmd || error "$cmd FAILED!"
1433 # display the quota status
1434 echo "Quota settings for $usr : "
1435 $LFS quota -v -u $usr $mntpt || true
1442 local opts=${3:-$MOUNT_OPTS}
1443 opts=${opts:+-o $opts}
1444 local flags=${4:-$MOUNT_FLAGS}
1446 local device=$MGSNID:/$FSNAME
1447 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1448 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1452 echo "Starting client: $client: $flags $opts $device $mnt"
1453 do_node $client mkdir -p $mnt
1454 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1456 set_default_debug_nodes $client
1468 [ "$3" ] && force=-f
1469 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1470 if [ $running -ne 0 ]; then
1471 echo "Stopping client $client $mnt (opts:$force)"
1472 do_node $client lsof -t $mnt || need_kill=no
1473 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1474 pids=$(do_node $client lsof -t $mnt | sort -u);
1475 if [ -n $pids ]; then
1476 do_node $client kill -9 $pids || true
1480 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1481 if [ $busy -ne 0 ] ; then
1482 echo "$mnt is still busy, wait one second" && sleep 1
1483 do_node $client umount $force $mnt
1488 # nodes is comma list
1489 sanity_mount_check_nodes () {
1495 # FIXME: assume that all cluster nodes run the same os
1496 [ "$(uname)" = Linux ] || return 0
1499 for mnt in $mnts ; do
1500 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1501 mpts=\\\$(mount | grep -c $mnt' ');
1502 if [ \\\$running -ne \\\$mpts ]; then
1503 echo \\\$(hostname) env are INSANE!;
1506 [ $? -eq 0 ] || rc=1
1511 sanity_mount_check_servers () {
1512 [ "$CLIENTONLY" ] &&
1513 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1514 echo Checking servers environments
1516 # FIXME: modify get_facets to display all facets wo params
1517 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1521 for facet in ${facets//,/ }; do
1522 node=$(facet_host ${facet})
1523 mntpt=$(facet_mntpt $facet)
1524 sanity_mount_check_nodes $node $mntpt ||
1525 { error "server $node environments are insane!"; return 1; }
1529 sanity_mount_check_clients () {
1530 local clients=${1:-$CLIENTS}
1531 local mntpt=${2:-$MOUNT}
1532 local mntpt2=${3:-$MOUNT2}
1534 [ -z $clients ] && clients=$(hostname)
1535 echo Checking clients $clients environments
1537 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1538 error "clients environments are insane!"
1541 sanity_mount_check () {
1542 sanity_mount_check_servers || return 1
1543 sanity_mount_check_clients || return 2
1546 # mount clients if not mouted
1547 zconf_mount_clients() {
1550 local opts=${3:-$MOUNT_OPTS}
1551 opts=${opts:+-o $opts}
1552 local flags=${4:-$MOUNT_FLAGS}
1554 local device=$MGSNID:/$FSNAME
1555 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1556 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1560 echo "Starting client $clients: $flags $opts $device $mnt"
1563 running=\\\$(mount | grep -c $mnt' ');
1565 if [ \\\$running -eq 0 ] ; then
1567 $MOUNT_CMD $flags $opts $device $mnt;
1570 exit \\\$rc" || return ${PIPESTATUS[0]}
1572 echo "Started clients $clients: "
1573 do_nodes $clients "mount | grep $mnt' '"
1575 set_default_debug_nodes $clients
1580 zconf_umount_clients() {
1585 [ "$3" ] && force=-f
1587 echo "Stopping clients: $clients $mnt (opts:$force)"
1588 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1589 if [ \\\$running -ne 0 ] ; then
1590 echo Stopping client \\\$(hostname) $mnt opts:$force;
1591 lsof $mnt || need_kill=no;
1592 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1593 pids=\\\$(lsof -t $mnt | sort -u);
1594 if [ -n \\\"\\\$pids\\\" ]; then
1598 while umount $force $mnt 2>&1 | grep -q "busy"; do
1599 echo "$mnt is still busy, wait one second" && sleep 1;
1606 echo + $POWER_DOWN $node
1610 shutdown_node_hard () {
1612 local attempts=$SHUTDOWN_ATTEMPTS
1614 for i in $(seq $attempts) ; do
1617 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1618 echo "waiting for $host to fail attempts=$attempts"
1619 [ $i -lt $attempts ] || \
1620 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1626 local mnt=${2:-$MOUNT}
1629 if [ "$FAILURE_MODE" = HARD ]; then
1630 shutdown_node_hard $client
1632 zconf_umount_clients $client $mnt -f
1638 local facets="$(get_facets OST),$(get_facets MDS)"
1641 combined_mgs_mds || facets="$facets,mgs"
1643 for facet in ${facets//,/ }; do
1644 if [ $(facet_active_host $facet) == $host ]; then
1645 affected="$affected $facet"
1649 echo $(comma_list $affected)
1654 local host=${2:-$(facet_host $facet)}
1656 local label=$(convert_facet2label $facet)
1657 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1660 facets_up_on_host () {
1662 local facets=$(facets_on_host $host)
1665 for facet in ${facets//,/ }; do
1666 if $(facet_up $facet $host); then
1667 affected_up="$affected_up $facet"
1671 echo $(comma_list $affected_up)
1677 if [ "$FAILURE_MODE" = HARD ]; then
1678 shutdown_node_hard $(facet_active_host $facet)
1686 echo + $POWER_UP $node
1699 if [ "$FAILURE_MODE" = HARD ]; then
1700 reboot_node $(facet_active_host $facet)
1708 if [ "$FAILURE_MODE" = HARD ]; then
1718 for facet in ${facets//,/ }; do
1719 hosts=$(expand_list $hosts $(facet_host $facet) )
1725 _check_progs_installed () {
1729 for prog in $progs; do
1730 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1731 echo $prog missing on $(hostname)
1738 check_progs_installed () {
1742 do_rpc_nodes "$nodes" _check_progs_installed $@
1745 # recovery-scale functions
1747 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1750 start_client_load() {
1753 local var=$(node_var_name $client)_load
1754 eval export ${var}=$load
1756 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1757 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1758 END_RUN_FILE=$END_RUN_FILE \
1759 LOAD_PID_FILE=$LOAD_PID_FILE \
1760 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1761 TESTNAME=$TESTNAME \
1762 DBENCH_LIB=$DBENCH_LIB \
1763 DBENCH_SRC=$DBENCH_SRC \
1764 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1768 log "Started client load: ${load} on $client"
1770 # get the children process IDs
1771 local pids=$(ps --ppid $ppid -o pid= | xargs)
1772 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1776 start_client_loads () {
1777 local -a clients=(${1//,/ })
1778 local numloads=${#CLIENT_LOADS[@]}
1781 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1782 testnum=$((nodenum % numloads))
1783 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1785 # bug 22169: wait the background threads to start
1789 # only for remote client
1790 check_client_load () {
1792 local var=$(node_var_name $client)_load
1793 local TESTLOAD=run_${!var}.sh
1795 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1797 # bug 18914: try to connect several times not only when
1798 # check ps, but while check_catastrophe also
1801 while [ $RC = 254 -a $tries -gt 0 ]; do
1805 if ! check_catastrophe $client; then
1807 if [ $RC -eq 254 ]; then
1808 # FIXME: not sure how long we shuold sleep here
1812 echo "check catastrophe failed: RC=$RC "
1816 # We can continue try to connect if RC=254
1817 # Just print the warning about this
1818 if [ $RC = 254 ]; then
1819 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1822 # see if the load is still on the client
1825 while [ $RC = 254 -a $tries -gt 0 ]; do
1829 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1834 if [ $RC = 254 ]; then
1835 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1836 # see if we can diagnose a bit why this is
1841 check_client_loads () {
1842 local clients=${1//,/ }
1846 for client in $clients; do
1847 check_client_load $client
1849 if [ "$rc" != 0 ]; then
1850 log "Client load failed on node $client, rc=$rc"
1856 restart_client_loads () {
1857 local clients=${1//,/ }
1858 local expectedfail=${2:-""}
1862 for client in $clients; do
1863 check_client_load $client
1865 if [ "$rc" != 0 -a "$expectedfail" ]; then
1866 local var=$(node_var_name $client)_load
1867 start_client_load $client ${!var}
1868 echo "Restarted client load ${!var}: on $client. Checking ..."
1869 check_client_load $client
1871 if [ "$rc" != 0 ]; then
1872 log "Client load failed to restart on node $client, rc=$rc"
1873 # failure one client load means test fail
1874 # we do not need to check other
1883 # Start vmstat and save its process ID in a file.
1888 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1891 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1892 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1895 # Display the nodes on which client loads failed.
1896 print_end_run_file() {
1900 [ -s $file ] || return 0
1902 echo "Found the END_RUN_FILE file: $file"
1905 # A client load will stop if it finds the END_RUN_FILE file.
1906 # That does not mean the client load actually failed though.
1907 # The first node in END_RUN_FILE is the one we are interested in.
1910 if [ -n "$node" ]; then
1911 local var=$(node_var_name $node)_load
1913 local prefix=$TESTLOG_PREFIX
1914 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1915 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1916 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1918 echo "Client load ${!var} failed on node $node:"
1924 # Stop the process which had its PID saved in a file.
1929 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1931 do_nodes $nodes "test -f $pid_file &&
1932 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1935 # Stop all client loads.
1936 stop_client_loads() {
1937 local nodes=${1:-$CLIENTS}
1940 # stop the client loads
1941 stop_process $nodes $pid_file
1943 # clean up the processes that started them
1944 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1946 # End recovery-scale functions
1948 # verify that lustre actually cleaned up properly
1950 VAR=$(lctl get_param -n catastrophe 2>&1)
1951 if [ $? = 0 ] ; then
1952 if [ $VAR != 0 ]; then
1953 error "LBUG/LASSERT detected"
1956 BUSY=$(dmesg | grep -i destruct || true)
1957 if [ -n "$BUSY" ]; then
1959 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
1963 check_mem_leak || exit 204
1965 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
1966 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1969 if module_loaded lnet || module_loaded libcfs; then
1970 echo "$TESTSUITE: modules still loaded..." 1>&2
1979 if [[ "$1" == "--verbose" ]]; then
1994 PREV_RESULT=$(do_node $node "$TEST")
1996 RESULT=$(do_node $node "$TEST")
1997 if [[ "$RESULT" == "$FINAL" ]]; then
1998 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1999 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2003 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2004 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2008 [[ $WAIT -ge $MAX ]] && break
2009 [[ $((WAIT % print)) -eq 0 ]] &&
2010 echo "Waiting $((MAX - WAIT)) secs for update"
2011 WAIT=$((WAIT + sleep))
2014 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2018 wait_update_facet() {
2021 wait_update $(facet_active_host $facet) "$@"
2025 do_nodes $(comma_list $(mdts_nodes)) \
2026 "lctl set_param -n osd*.*MDT*.force_sync 1"
2027 do_nodes $(comma_list $(osts_nodes)) \
2028 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2029 grep -v 'Found no match'
2032 wait_delete_completed_mds() {
2033 local MAX_WAIT=${1:-20}
2035 local stime=$(date +%s)
2040 # find MDS with pending deletions
2041 for node in $(mdts_nodes); do
2042 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2043 2>/dev/null | calc_sum)
2044 if [[ $changes -eq 0 ]]; then
2047 mds2sync="$mds2sync $node"
2049 if [ -z "$mds2sync" ]; then
2052 mds2sync=$(comma_list $mds2sync)
2054 # sync MDS transactions
2055 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2057 # wait till all changes are sent and commmitted by OSTs
2058 # for ldiskfs space is released upon execution, but DMU
2059 # do this upon commit
2062 while [[ $WAIT -ne $MAX_WAIT ]]; do
2063 changes=$(do_nodes $mds2sync \
2064 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2065 #echo "$node: $changes changes on all"
2066 if [[ $changes -eq 0 ]]; then
2068 #echo "delete took $((etime - stime)) seconds"
2076 echo "Delete is not completed in $((etime - stime)) seconds"
2077 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2083 # we can use "for" here because we are waiting the slowest
2084 for host in ${hostlist//,/ }; do
2085 check_network "$host" 900
2087 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2094 for facet in ${facetlist//,/ }; do
2095 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2097 wait_for_host $hostlist
2100 _wait_recovery_complete () {
2103 # Use default policy if $2 is not passed by caller.
2104 local MAX=${2:-$(max_recovery_time)}
2109 while [ $WAIT -lt $MAX ]; do
2110 STATUS=$(lctl get_param -n $param | grep status)
2112 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2115 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2117 echo "$param recovery not done in $MAX sec. $STATUS"
2121 wait_recovery_complete () {
2124 # with an assumption that at_max is the same on all nodes
2125 local MAX=${2:-$(max_recovery_time)}
2128 if [ "$FAILURE_MODE" = HARD ]; then
2129 facets=$(facets_on_host $(facet_active_host $facet))
2131 echo affected facets: $facets
2133 # we can use "for" here because we are waiting the slowest
2134 for facet in ${facets//,/ }; do
2135 local var_svc=${facet}_svc
2136 local param="*.${!var_svc}.recovery_status"
2138 local host=$(facet_active_host $facet)
2139 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2143 wait_mds_ost_sync () {
2144 # just because recovery is done doesn't mean we've finished
2145 # orphan cleanup. Wait for llogs to get synchronized.
2146 echo "Waiting for orphan cleanup..."
2147 # MAX value includes time needed for MDS-OST reconnection
2148 local MAX=$(( TIMEOUT * 2 ))
2149 local WAIT_TIMEOUT=${1:-$MAX}
2152 local list=$(comma_list $(mdts_nodes))
2153 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2154 if ! do_facet $SINGLEMDS \
2155 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2157 # old way, use mds_sync
2159 list=$(comma_list $(osts_nodes))
2160 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2163 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2164 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2165 local -a sync=($(do_nodes $list "$cmd"))
2168 for ((i=0; i<${#sync[@]}; i++)); do
2170 [ ${sync[$i]} -eq 1 ] && continue
2172 [ ${sync[$i]} -eq 0 ] && continue
2174 # there is a not finished MDS-OST synchronization
2178 sleep 2 # increase waiting time and cover statfs cache
2179 [ ${con} -eq 1 ] && return 0
2180 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2184 # show which nodes are not finished.
2185 do_nodes $list "$cmd"
2186 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2190 wait_destroy_complete () {
2191 echo "Waiting for local destroys to complete"
2192 # MAX value shouldn't be big as this mean server responsiveness
2193 # never increase this just to make test pass but investigate
2194 # why it takes so long time
2197 while [ $WAIT -lt $MAX ]; do
2198 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2202 for ((i=0; i<${#RPCs[@]}; i++)); do
2203 [ ${RPCs[$i]} -eq 0 ] && continue
2204 # there are still some destroy RPCs in flight
2209 [ ${con} -eq 1 ] && return 0 # done waiting
2210 echo "Waiting ${WAIT}s for local destroys to complete"
2213 echo "Local destroys weren't done in $MAX sec."
2217 wait_delete_completed() {
2218 wait_delete_completed_mds $1 || return $?
2219 wait_destroy_complete
2228 # conf-sanity 31 takes a long time cleanup
2229 while [ $WAIT -lt 300 ]; do
2230 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2231 [ -z "${running}" ] && return 0
2232 echo "waited $WAIT for${running}"
2233 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2235 WAIT=$((WAIT + INTERVAL))
2237 echo "service didn't stop after $WAIT seconds. Still running:"
2242 wait_remote_prog () {
2248 [ "$PDSH" = "no_dsh" ] && return 0
2250 while [ $WAIT -lt $2 ]; do
2251 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2252 [ -z "${running}" ] && return 0 || true
2253 echo "waited $WAIT for: "
2255 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2257 WAIT=$((WAIT + INTERVAL))
2259 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2260 [ -z "$pids" ] && return 0
2261 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2262 # FIXME: not portable
2263 for pid in $pids; do
2264 cat /proc/${pid}/status || true
2265 cat /proc/${pid}/wchan || true
2267 kill -9 $pid || true
2276 # not every config has many clients
2278 if [ ! -z "$CLIENTS" ]; then
2279 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2281 stat -f $MOUNT > /dev/null
2287 # usually checked on particular client or locally
2289 if [ ! -z "$client" ]; then
2290 $PDSH $client "stat -f $MOUNT" > /dev/null
2292 stat -f $MOUNT > /dev/null
2300 client_reconnect_try() {
2301 uname -n >> $MOUNT/recon
2302 if [ -z "$CLIENTS" ]; then
2303 df $MOUNT; uname -n >> $MOUNT/recon
2305 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2307 echo Connected clients:
2309 ls -l $MOUNT/recon > /dev/null
2313 client_reconnect() {
2314 # one client_reconnect_try call does not always do the job...
2316 client_reconnect_try && break
2321 affected_facets () {
2324 local host=$(facet_active_host $facet)
2325 local affected=$facet
2327 if [ "$FAILURE_MODE" = HARD ]; then
2328 affected=$(facets_up_on_host $host)
2342 #Because it will only get up facets, we need get affected
2343 #facets before shutdown
2344 #For HARD Failure mode, it needs make sure facets on the same
2345 #HOST will only be shutdown and reboot once
2346 for facet in ${facets//,/ }; do
2347 local affected_facet
2349 #check whether facet has been included in other affected facets
2350 for ((index=0; index<$total; index++)); do
2351 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2354 if [ $skip -eq 0 ]; then
2355 affecteds[$total]=$(affected_facets $facet)
2360 for ((index=0; index<$total; index++)); do
2361 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2362 local host=$(facet_active_host $facet)
2363 echo "Failing ${affecteds[index]} on $host"
2364 shutdown_facet $facet
2367 for ((index=0; index<$total; index++)); do
2368 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2369 echo reboot facets: ${affecteds[index]}
2373 change_active ${affecteds[index]}
2375 wait_for_facet ${affecteds[index]}
2376 # start mgs first if it is affected
2377 if ! combined_mgs_mds &&
2378 list_member ${affecteds[index]} mgs; then
2379 mount_facet mgs || error "Restart of mgs failed"
2381 # FIXME; has to be changed to mount all facets concurrently
2382 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2383 echo mount facets: ${affecteds[index]}
2384 mount_facets ${affecteds[index]}
2394 do_facet $facet "sync; sync; sync"
2397 # make sure there will be no seq change
2398 local clients=${CLIENTS:-$HOSTNAME}
2399 local f=fsa-\\\$\(hostname\)
2400 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2401 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2403 local svc=${facet}_svc
2404 do_facet $facet $LCTL --device ${!svc} notransno
2406 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2407 # in-memory state has to be cleared by either rebooting the host or
2408 # exporting and reimporting the pool.
2410 # Although the uberblocks are not updated when a pool is freezed,
2411 # transactions are still written to the disks. Modified blocks may be
2412 # cached in memory when tests try reading them back. The
2413 # export-and-reimport process also evicts any cached pool data from
2414 # memory to provide the correct "data loss" semantics.
2416 # In the test framework, the exporting and importing operations are
2417 # handled by stop() and mount_facet() separately, which are used
2418 # inside fail() and fail_abort().
2420 do_facet $facet $LCTL --device ${!svc} readonly
2421 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2422 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2425 replay_barrier_nodf() {
2426 local facet=$1 echo running=${running}
2427 do_facet $facet "sync; sync; sync"
2428 local svc=${facet}_svc
2429 echo Replay barrier on ${!svc}
2430 do_facet $facet $LCTL --device ${!svc} notransno
2431 do_facet $facet $LCTL --device ${!svc} readonly
2432 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2433 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2436 replay_barrier_nosync() {
2437 local facet=$1 echo running=${running}
2438 local svc=${facet}_svc
2439 echo Replay barrier on ${!svc}
2440 do_facet $facet $LCTL --device ${!svc} notransno
2441 do_facet $facet $LCTL --device ${!svc} readonly
2442 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2443 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2447 # Get Lustre client uuid for a given Lustre mount point.
2450 local mntpnt=${1:-$MOUNT}
2452 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2453 local uuid=$($LCTL get_param -n llite.$name.uuid)
2458 mds_evict_client() {
2459 local mntpnt=${1:-$MOUNT}
2460 local uuid=$(get_client_uuid $mntpnt)
2462 do_facet $SINGLEMDS \
2463 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2466 ost_evict_client() {
2467 local mntpnt=${1:-$MOUNT}
2468 local uuid=$(get_client_uuid $mntpnt)
2471 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2476 local clients=${CLIENTS:-$HOSTNAME}
2478 facet_failover $* || error "failover: $?"
2479 wait_clients_import_state "$clients" "$facets" FULL
2480 clients_up || error "post-failover df: $?"
2485 facet_failover $facet
2491 change_active $facet
2492 wait_for_facet $facet
2493 mount_facet $facet -o abort_recovery
2494 clients_up || echo "first df failed: $?"
2495 clients_up || error "post-failover df: $?"
2499 echo There is no lmc. This is mountconf, baby.
2503 host_nids_address() {
2507 if [ -n "$kind" ]; then
2508 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2510 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2516 if [ "$1" = "'*'" ]; then echo \'*\'; else
2522 if [ "$1" = "'*'" ]; then echo \'*\'; else
2523 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2525 if [ -z "$ID" ]; then
2526 echo "Could not get a ptl id for $1..."
2535 h2name_or_ip "$1" "tcp"
2540 if [ "$1" = "'*'" ]; then echo \'*\'; else
2541 if type __h2elan >/dev/null 2>&1; then
2544 ID=`echo $1 | sed 's/[^0-9]*//g'`
2552 h2name_or_ip "$1" "o2ib"
2556 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2557 # expressions format. As a bonus we can then just pass in those variables
2558 # to pdsh. What this function does is take a HOSTLIST type string and
2559 # expand it into a space deliminated list for us.
2567 [ -z "$hostlist" ] && return
2569 # Translate the case of [..],..,[..] to [..] .. [..]
2570 list="${hostlist/],/] }"
2572 [[ "$front" == *,* ]] && {
2575 list=${list/${old}/${new}}
2578 for item in $list; do
2579 # Test if we have any []'s at all
2580 if [ "$item" != "${item/\[/}" ]; then {
2581 # Expand the [*] into list
2585 if [ "$name" != "$item" ]; then
2586 group=${item#$name[*}
2589 for range in ${group//,/ }; do
2593 # Number of leading zeros
2596 end=$(echo $end | sed 's/0*//')
2597 [[ -z "$end" ]] && end=0
2598 [[ $padlen2 -gt $padlen ]] && {
2599 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2602 begin=$(echo $begin | sed 's/0*//')
2603 [ -z $begin ] && begin=0
2605 for num in $(seq -f "%0${padlen}g" $begin $end); do
2606 value="${name#*,}${num}${back}"
2607 [ "$value" != "${value/\[/}" ] && {
2608 value=$(hostlist_expand "$value")
2610 myList="$myList $value"
2615 myList="$myList $item"
2618 myList=${myList//,/ }
2619 myList=${myList:1} # Remove first character which is a space
2621 # Filter any duplicates without sorting
2623 myList="${list%% *}"
2625 while [[ "$list" != ${myList##* } ]]; do
2626 list=${list//${list%% *} /}
2627 myList="$myList ${list%% *}"
2629 myList="${myList%* }";
2631 # We can select an object at a offset in the list
2634 for item in $myList; do
2636 [ $cnt -eq $offset ] && {
2640 [ $(get_node_count $myList) -ne 1 ] && myList=""
2649 [ "$facet" == client ] && echo -n $HOSTNAME && return
2650 varname=${facet}_HOST
2651 if [ -z "${!varname}" ]; then
2652 if [ "${facet:0:3}" == "ost" ]; then
2653 local fh=${facet%failover}_HOST
2654 eval export ${facet}_HOST=${!fh}
2655 if [ -z "${!varname}" ]; then
2656 eval export ${facet}_HOST=${ost_HOST}
2658 elif [ "${facet:0:3}" == "mdt" -o \
2659 "${facet:0:3}" == "mds" -o \
2660 "${facet:0:3}" == "mgs" ]; then
2661 eval export ${facet}_HOST=${mds_HOST}
2667 facet_failover_host() {
2671 var=${facet}failover_HOST
2672 if [ -n "${!var}" ]; then
2677 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2678 "${facet:0:3}" == "mgs" ]; then
2680 eval export ${facet}failover_host=${mds_HOST}
2685 if [[ $facet == ost* ]]; then
2686 eval export ${facet}failover_host=${ost_HOST}
2694 local activevar=${facet}active
2696 if [ -f $TMP/${facet}active ] ; then
2697 source $TMP/${facet}active
2700 active=${!activevar}
2701 if [ -z "$active" ] ; then
2708 facet_active_host() {
2710 local active=`facet_active $facet`
2711 if [ "$facet" == client ]; then
2714 echo `facet_host $active`
2718 # Get the passive failover partner host of facet.
2719 facet_passive_host() {
2721 [[ $facet = client ]] && return
2723 local host=${facet}_HOST
2724 local failover_host=${facet}failover_HOST
2725 local active_host=$(facet_active_host $facet)
2727 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2729 if [[ $active_host = ${!host} ]]; then
2730 echo -n ${!failover_host}
2740 facetlist=$(exclude_items_from_list $facetlist mgs)
2742 for facet in ${facetlist//,/ }; do
2743 local failover=${facet}failover
2744 local host=`facet_host $failover`
2745 [ -z "$host" ] && return
2747 local curactive=`facet_active $facet`
2748 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2749 eval export ${facet}active=$facet
2751 eval export ${facet}active=$failover
2753 # save the active host for this facet
2754 local activevar=${facet}active
2755 echo "$activevar=${!activevar}" > $TMP/$activevar
2756 [[ $facet = mds1 ]] && combined_mgs_mds && \
2757 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2758 local TO=`facet_active_host $facet`
2759 echo "Failover $facet to $TO"
2765 # do not stripe off hostname if verbose, bug 19215
2766 if [ x$1 = x--verbose ]; then
2774 if [ "$HOST" = "$HOSTNAME" ]; then
2776 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2777 echo "cannot run remote command on $HOST with $myPDSH"
2781 echo "CMD: $HOST $@" >&2
2782 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2785 if [ "$myPDSH" = "rsh" ]; then
2786 # we need this because rsh does not return exit code of an executed command
2787 local command_status="$TMP/cs"
2788 rsh $HOST ":> $command_status"
2789 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2790 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2791 echo command failed >$command_status"
2792 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2797 # print HOSTNAME for myPDSH="no_dsh"
2798 if [[ $myPDSH = no_dsh ]]; then
2799 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2801 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2804 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2806 return ${PIPESTATUS[0]}
2810 do_node --verbose "$@"
2813 single_local_node () {
2814 [ "$1" = "$HOSTNAME" ]
2817 # Outputs environment variable assignments that should be passed to remote nodes
2821 local facets=$(get_facets)
2824 for var in ${!MODOPTS_*}; do
2826 echo -n " ${var}=\"$value\""
2829 for facet in ${facets//,/ }; do
2831 if [ -n "${!var}" ]; then
2832 echo -n " $var=${!var}"
2836 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2837 if [ -n "${!var}" ]; then
2838 echo -n " $var=${!var}"
2842 if [ -n "$FSTYPE" ]; then
2843 echo -n " FSTYPE=$FSTYPE"
2849 # do not stripe off hostname if verbose, bug 19215
2850 if [ x$1 = x--verbose ]; then
2858 if single_local_node $rnodes; then
2860 do_nodev $rnodes "$@"
2862 do_node $rnodes "$@"
2867 # This is part from do_node
2870 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2871 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2873 export FANOUT=$(get_node_count "${rnodes//,/ }")
2875 echo "CMD: $rnodes $@" >&2
2876 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2879 # do not replace anything from pdsh output if -N is used
2880 # -N Disable hostname: prefix on lines of output.
2881 if $verbose || [[ $myPDSH = *-N* ]]; then
2882 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2884 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2886 return ${PIPESTATUS[0]}
2892 local HOST=`facet_active_host $facet`
2893 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2897 # Function: do_facet_random_file $FACET $FILE $SIZE
2898 # Creates FILE with random content on the given FACET of given SIZE
2900 do_facet_random_file() {
2904 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2905 do_facet $facet "$cmd 2>/dev/null"
2908 do_facet_create_file() {
2912 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2913 do_facet $facet "$cmd 2>/dev/null"
2917 do_nodes --verbose "$@"
2923 # make sure its not already running
2925 rm -f $TMP/${facet}active
2926 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2927 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2929 if [[ $(facet_fstype $facet) == zfs ]]; then
2931 # After formatting a ZFS target, "cachefile=none" property will
2932 # be set on the ZFS storage pool so that the pool is not
2933 # automatically imported on system startup. And then the pool
2934 # will be exported so as to leave the importing and exporting
2935 # operations handled by mount_facet() and stop() separately.
2937 refresh_partition_table $facet $(facet_vdevice $facet)
2938 disable_zpool_cache $facet
2943 # Device formatted as ost
2946 local DEVNAME=OSTDEV$num
2948 local fstype=$(facet_fstype ost$num)
2952 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2953 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2955 #try $OSTZFSDEVn - independent of vdev
2956 DEVNAME=OSTZFSDEV$num
2957 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2959 error "unknown fstype!";;
2965 # Physical device location of data
2971 local fstype=$(facet_fstype ost$num)
2975 # vdevs are not supported by ldiskfs
2978 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2979 # Device formated by zfs
2981 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2983 error "unknown fstype!";;
2989 # Logical device formated for lustre
2992 local DEVNAME=MDSDEV$num
2994 local fstype=$(facet_fstype mds$num)
2998 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2999 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3001 # try $MDSZFSDEVn - independent of vdev
3002 DEVNAME=MDSZFSDEV$num
3003 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3005 error "unknown fstype!";;
3011 # Physical location of data
3015 local fstype=$(facet_fstype mds$num)
3019 # vdevs are not supported by ldiskfs
3022 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3023 # Device formated by ZFS
3024 local DEVNAME=MDSDEV$num
3025 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3027 error "unknown fstype!";;
3035 local fstype=$(facet_fstype mgs)
3039 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3040 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3041 DEVPTR=$(mdsdevname 1)
3046 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3047 ( [ -z "$MGSZFSDEV" ] &&
3048 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3049 DEVPTR=$(mdsdevname 1)
3051 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3054 error "unknown fstype!";;
3063 local fstype=$(facet_fstype mgs)
3067 # vdevs are not supported by ldiskfs
3070 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3071 ( [ -z "$MGSDEV" ] &&
3072 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3073 VDEVPTR=$(mdsvdevname 1)
3074 elif [ -n "$MGSDEV" ]; then
3078 error "unknown fstype!";;
3086 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3088 local var=${facet}_MOUNT
3089 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3096 local dev=$(facet_device $facet)
3097 local mnt=$(facet_mntpt $facet)
3100 if ! do_facet $facet test -b $dev; then
3103 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3108 local dev=$(facet_device $facet)
3109 local mnt=$(facet_mntpt $facet)
3111 do_facet $facet umount -d $mnt
3115 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3120 local ds=$(facet_device $facet)
3121 local mnt=$(facet_mntpt $facet)
3126 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3127 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3128 do_facet $facet $ZFS set canmount=noauto $ds
3130 # The "legacy" mount method is used here because "zfs unmount $mnt"
3131 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3132 # targets are not available at the time, the stat(2) on $MOUNT will
3135 do_facet $facet $ZFS set mountpoint=legacy $ds
3136 do_facet $facet mount -t zfs $ds $mnt
3137 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3138 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3143 local ds=$(facet_device $facet)
3144 local mnt=$(facet_mntpt $facet)
3145 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3146 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3147 local mntpt=${!var_mntpt}
3148 local canmnt=${!var_canmnt}
3152 do_facet $facet umount $mnt
3153 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3154 do_facet $facet $ZFS set canmount=$canmnt $ds
3160 local fstype=$(facet_fstype $facet)
3162 mount_$fstype $facet
3167 local fstype=$(facet_fstype $facet)
3169 unmount_$fstype $facet
3176 # make sure we are using the primary server, so test-framework will
3177 # be able to clean up properly.
3178 activemds=`facet_active mds1`
3179 if [ $activemds != "mds1" ]; then
3183 local clients=$CLIENTS
3184 [ -z $clients ] && clients=$(hostname)
3186 zconf_umount_clients $clients $MOUNT "$*" || true
3187 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3189 [ "$CLIENTONLY" ] && return
3190 # The add fn does rm ${facet}active file, this would be enough
3191 # if we use do_facet <facet> only after the facet added, but
3192 # currently we use do_facet mds in local.sh
3193 for num in `seq $MDSCOUNT`; do
3195 rm -f ${TMP}/mds${num}active
3197 combined_mgs_mds && rm -f $TMP/mgsactive
3199 for num in `seq $OSTCOUNT`; do
3201 rm -f $TMP/ost${num}active
3204 if ! combined_mgs_mds ; then
3211 cleanup_echo_devs () {
3212 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3214 for dev in $devs; do
3215 $LCTL --device $dev cleanup
3216 $LCTL --device $dev detach
3221 nfs_client_mode && return
3230 combined_mgs_mds () {
3231 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3232 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3236 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3240 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3246 local fsname=${3:-"$FSNAME"}
3247 local type=$(facet_type $facet)
3248 local index=$(($(facet_number $facet) - 1))
3249 local fstype=$(facet_fstype $facet)
3250 local host=$(facet_host $facet)
3255 if [ $type == MGS ] && combined_mgs_mds; then
3259 if [ $type == MGS ] || ( [ $type == MDS ] &&
3260 [ "$dev" == $(mgsdevname) ] &&
3261 [ "$host" == "$(facet_host mgs)" ] ); then
3264 opts="--mgsnode=$MGSNID"
3267 if [ $type != MGS ]; then
3268 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3272 var=${facet}failover_HOST
3273 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3274 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3277 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3278 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3280 if [ $type == MDS ]; then
3281 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3282 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3283 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3284 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3285 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3287 if [ $fstype == ldiskfs ]; then
3288 # Check for wide striping
3289 if [ $OSTCOUNT -gt 160 ]; then
3290 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3291 fs_mkfs_opts+="-O large_xattr"
3294 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3295 if [ ! -z $EJOURNAL ]; then
3296 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3298 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3302 if [ $type == OST ]; then
3303 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3304 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3306 if [ $fstype == ldiskfs ]; then
3307 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3311 opts+=" --backfstype=$fstype"
3314 if [ -n "${!var}" ]; then
3315 opts+=" --device-size=${!var}"
3318 var=$(upper $fstype)_MKFS_OPTS
3319 fs_mkfs_opts+=${!var:+" ${!var}"}
3321 var=${type}_FS_MKFS_OPTS
3322 fs_mkfs_opts+=${!var:+" ${!var}"}
3324 if [ -n "${fs_mkfs_opts## }" ]; then
3325 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3329 opts+=${!var:+" ${!var}"}
3342 # We need ldiskfs here, may as well load them all
3344 [ "$CLIENTONLY" ] && return
3345 echo Formatting mgs, mds, osts
3346 if ! combined_mgs_mds ; then
3347 echo "Format mgs: $(mgsdevname)"
3348 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3349 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3353 for num in $(seq $MDSCOUNT); do
3354 echo "Format mds$num: $(mdsdevname $num)"
3355 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3356 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3357 ${quiet:+>/dev/null} || exit 10
3360 for num in $(seq $OSTCOUNT); do
3361 echo "Format ost$num: $(ostdevname $num)"
3362 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3363 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3364 ${quiet:+>/dev/null} || exit 10
3369 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3373 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3377 # 0: success, the old identity set already.
3378 # 1: success, the old identity does not set.
3383 local j=`expr $num - 1`
3384 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3386 if [ -z "$MDT" ]; then
3390 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3393 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3395 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3398 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3400 if [ $old = "NONE" ]; then
3409 zconf_umount `hostname` $1 || error "umount failed"
3410 zconf_mount `hostname` $1 || error "mount failed"
3418 rm -f $TMP/${facet}active
3419 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3424 local mdt_count=${1:-$MDSCOUNT}
3425 local ost_count=${2:-$OSTCOUNT}
3428 for num in $(seq $mdt_count); do
3429 DEVNAME=$(mdsdevname $num)
3430 writeconf_facet mds$num $DEVNAME || rc=$?
3433 for num in $(seq $ost_count); do
3434 DEVNAME=$(ostdevname $num)
3435 writeconf_facet ost$num $DEVNAME || rc=$?
3441 nfs_client_mode && return
3443 sanity_mount_check ||
3444 error "environments are insane!"
3448 if [ -z "$CLIENTONLY" ]; then
3449 echo Setup mgs, mdt, osts
3450 echo $WRITECONF | grep -q "writeconf" && \
3452 if ! combined_mgs_mds ; then
3453 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3456 for num in `seq $MDSCOUNT`; do
3457 DEVNAME=$(mdsdevname $num)
3458 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3460 # We started mds, now we should set failover variables properly.
3461 # Set mds${num}failover_HOST if it is not set (the default failnode).
3462 local varname=mds${num}failover_HOST
3463 if [ -z "${!varname}" ]; then
3464 eval mds${num}failover_HOST=$(facet_host mds$num)
3467 if [ $IDENTITY_UPCALL != "default" ]; then
3468 switch_identity $num $IDENTITY_UPCALL
3471 for num in `seq $OSTCOUNT`; do
3472 DEVNAME=$(ostdevname $num)
3473 start ost$num $DEVNAME $OST_MOUNT_OPTS
3475 # We started ost$num, now we should set ost${num}failover variable properly.
3476 # Set ost${num}failover_HOST if it is not set (the default failnode).
3477 varname=ost${num}failover_HOST
3478 if [ -z "${!varname}" ]; then
3479 eval ost${num}failover_HOST=$(facet_host ost${num})
3487 # wait a while to allow sptlrpc configuration be propogated to targets,
3488 # only needed when mounting new target devices.
3493 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3495 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3498 if [ "$MOUNT_2" ]; then
3499 mount_client $MOUNT2
3500 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3505 # by remounting mdt before ost, initial connect from mdt to ost might
3506 # timeout because ost is not ready yet. wait some time to its fully
3507 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3508 # by a context negotiation rpc with $TIMEOUT.
3509 # FIXME better by monitoring import status.
3512 sleep $((TIMEOUT + 5))
3518 mounted_lustre_filesystems() {
3519 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3522 init_facet_vars () {
3523 [ "$CLIENTONLY" ] && return 0
3530 eval export ${facet}_dev=${device}
3531 eval export ${facet}_opt=\"$@\"
3533 local dev=${facet}_dev
3535 # We need to loop for the label
3536 # in case its not initialized yet.
3537 for wait_time in {0,1,3,5,10}; do
3539 if [ $wait_time -gt 0 ]; then
3540 echo "${!dev} not yet initialized,"\
3541 "waiting ${wait_time} seconds."
3545 local label=$(devicelabel ${facet} ${!dev})
3547 # Check to make sure the label does
3548 # not include ffff at the end of the label.
3549 # This indicates it has not been initialized yet.
3551 if [[ $label =~ [f|F]{4}$ ]]; then
3552 # label is not initialized, unset the result
3553 # and either try again or fail
3560 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3562 eval export ${facet}_svc=${label}
3564 local varname=${facet}failover_HOST
3565 if [ -z "${!varname}" ]; then
3566 eval export $varname=$(facet_host $facet)
3569 varname=${facet}_HOST
3570 if [ -z "${!varname}" ]; then
3571 eval export $varname=$(facet_host $facet)
3574 # ${facet}failover_dev is set in cfg file
3575 varname=${facet}failover_dev
3576 if [ -n "${!varname}" ] ; then
3577 eval export ${facet}failover_dev=${!varname}
3579 eval export ${facet}failover_dev=$device
3582 # get mount point of already mounted device
3583 # is facet_dev is already mounted then use the real
3584 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3585 # i.e. ${facet}_MOUNT if specified by user or default
3586 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3587 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3588 if [ -z $mntpt ]; then
3589 mntpt=$(facet_mntpt $facet)
3591 eval export ${facet}_MOUNT=$mntpt
3594 init_facets_vars () {
3597 if ! remote_mds_nodsh; then
3598 for num in $(seq $MDSCOUNT); do
3599 DEVNAME=`mdsdevname $num`
3600 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3604 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3606 if ! remote_ost_nodsh; then
3607 for num in $(seq $OSTCOUNT); do
3608 DEVNAME=$(ostdevname $num)
3609 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3614 osc_ensure_active () {
3619 while [ $period -lt $timeout ]; do
3620 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3621 if [ $count -eq 0 ]; then
3625 echo "There are $count OST are inactive, wait $period seconds, and try again"
3627 period=$((period+3))
3630 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3633 set_conf_param_and_check() {
3637 local ORIG=$(do_facet $myfacet "$TEST")
3638 if [ $# -gt 3 ]; then
3644 echo "Setting $PARAM from $ORIG to $FINAL"
3645 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3646 error "conf_param $PARAM failed"
3648 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3649 error "check $PARAM failed!"
3652 init_param_vars () {
3654 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3656 log "Using TIMEOUT=$TIMEOUT"
3658 osc_ensure_active $SINGLEMDS $TIMEOUT
3659 osc_ensure_active client $TIMEOUT
3661 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3662 local current_jobid_var=$($LCTL get_param -n jobid_var)
3664 if [ $JOBID_VAR = "existing" ]; then
3665 echo "keeping jobstats as $current_jobid_var"
3666 elif [ $current_jobid_var != $JOBID_VAR ]; then
3667 echo "seting jobstats to $JOBID_VAR"
3669 set_conf_param_and_check client \
3670 "$LCTL get_param -n jobid_var" \
3671 "$FSNAME.sys.jobid_var" $JOBID_VAR
3674 echo "jobstats not supported by server"
3677 if [ $QUOTA_AUTO -ne 0 ]; then
3678 if [ "$ENABLE_QUOTA" ]; then
3679 echo "enable quota as required"
3680 setup_quota $MOUNT || return 2
3682 echo "disable quota as required"
3683 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3689 nfs_client_mode () {
3690 if [ "$NFSCLIENT" ]; then
3691 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3692 local clients=$CLIENTS
3693 [ -z $clients ] && clients=$(hostname)
3695 # FIXME: remove hostname when 19215 fixed
3696 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3697 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3698 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3699 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3701 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3707 check_config_client () {
3710 local mounted=$(mount | grep " $mntpt ")
3711 if [ "$CLIENTONLY" ]; then
3713 # CLIENTONLY should not depend on *_HOST settings
3714 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3715 # in theory someone could create a new,
3716 # client-only config file that assumed lustre was already
3717 # configured and didn't set the MGSNID. If MGSNID is not set,
3718 # then we should use the mgs nid currently being used
3719 # as the default value. bug 18021
3720 [[ x$MGSNID = x ]] &&
3723 if [[ x$mgc != xMGC$MGSNID ]]; then
3724 if [ "$mgs_HOST" ]; then
3725 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3726 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3727 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3733 local myMGS_host=$mgs_HOST
3734 if [ "$NETTYPE" = "ptl" ]; then
3735 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3738 echo Checking config lustre mounted on $mntpt
3739 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3740 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3742 # if [ "$mgshost" != "$myMGS_host" ]; then
3743 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3744 # Please use correct config or set mds_HOST correctly!"
3749 check_config_clients () {
3750 local clients=${CLIENTS:-$HOSTNAME}
3753 nfs_client_mode && return
3755 do_rpc_nodes "$clients" check_config_client $mntpt
3757 sanity_mount_check || error "environments are insane!"
3761 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3762 local cltimeout=$(lctl get_param -n timeout)
3763 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3764 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3771 [ -z $mntpt ] && return 1
3772 local mounted=$(mounted_lustre_filesystems)
3774 echo $mounted' ' | grep -w -q $mntpt' '
3778 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3782 # empty lustre filesystem may have empty directories lost+found and .lustre
3784 # exclude .lustre & lost+found
3785 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3786 -print | wc -l) = 1 ] || return 1
3787 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3788 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3789 # exclude .lustre/fid (LU-2780)
3790 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3791 -print | wc -l) = 1 ] || return 1
3793 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3798 check_and_setup_lustre() {
3799 nfs_client_mode && return
3801 local MOUNTED=$(mounted_lustre_filesystems)
3805 # both MOUNT and MOUNT2 are not mounted
3806 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3807 [ "$REFORMAT" ] && formatall
3808 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3810 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3811 export I_MOUNTED=yes
3815 elif is_mounted $MOUNT2; then
3817 # MOUNT2 is mounted, while MOUNT_2 is not set
3818 if ! [ "$MOUNT_2" ]; then
3819 cleanup_mount $MOUNT2
3820 export I_UMOUNTED2=yes
3823 # MOUNT2 is mounted, MOUNT_2 is set
3825 # FIXME: what to do if check_config failed?
3827 # 1) remote client has mounted other Lustre fs ?
3828 # 2) it has insane env ?
3829 # let's try umount MOUNT2 on all clients and mount it again:
3830 if ! check_config_clients $MOUNT2; then
3831 cleanup_mount $MOUNT2
3832 restore_mount $MOUNT2
3833 export I_MOUNTED2=yes
3838 # MOUNT is mounted MOUNT2 is not mounted
3839 elif [ "$MOUNT_2" ]; then
3840 restore_mount $MOUNT2
3841 export I_MOUNTED2=yes
3845 # FIXME: what to do if check_config failed?
3847 # 1) remote client has mounted other Lustre fs?
3848 # 2) lustre is mounted on remote_clients atall ?
3849 check_config_clients $MOUNT
3853 set_default_debug_nodes $(comma_list $(nodes_list))
3856 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3858 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3859 facets="$(get_facets OST)"
3860 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3861 facets="$facets,$(get_facets MDS)"
3862 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3863 facets="$facets,mgs"
3864 local nodes="$(facets_hosts ${facets})"
3865 if [ -n "$nodes" ] ; then
3866 do_nodes $nodes "$LCTL set_param \
3867 osd-ldiskfs.track_declares_assert=1 || true"
3876 #Enable remote MDT create for testing
3877 for num in $(seq $MDSCOUNT); do
3879 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
3883 if [ "$ONLY" == "setup" ]; then
3889 local clients=${CLIENTS:-$HOSTNAME}
3892 zconf_mount_clients $clients $mntpt
3896 local clients=${CLIENTS:-$HOSTNAME}
3899 zconf_umount_clients $clients $mntpt
3902 cleanup_and_setup_lustre() {
3903 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3904 lctl set_param debug=0 || true
3906 if [ "$ONLY" == "cleanup" ]; then
3910 check_and_setup_lustre
3913 # Get all of the server target devices from a given server node and type.
3920 if [ "$type" == ost ]; then
3921 devs=$(get_osd_param $node "" mntdev)
3923 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
3925 for dev in $devs; do
3927 *loop*) do_node $node "losetup $dev" | \
3928 sed -e "s/.*(//" -e "s/).*//" ;;
3934 # Get all of the server target devices.
3939 # Master MDS parameters used by lfsck
3940 MDTNODE=$(facet_active_host $SINGLEMDS)
3941 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
3945 for node in $(mdts_nodes); do
3946 MDTDEVS[i]=$(get_mnt_devs $node mdt)
3952 for node in $(osts_nodes); do
3953 OSTDEVS[i]=$(get_mnt_devs $node ost)
3958 # Run e2fsck on MDT or OST device.
3963 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3964 local log=$TMP/e2fsck.log
3968 do_node $node $cmd 2>&1 | tee $log
3970 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
3972 if [ $MDSCOUNT -gt 1 ]; then
3973 skip "DNE mode isn't supported!"
3977 error "It's not DNE mode."
3982 [ $rc -le $FSCK_MAX_ERR ] ||
3983 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3989 # Run resize2fs on MDT or OST device.
3998 do_facet $facet "$RESIZE2FS $opts $device $size"
4001 # verify a directory is shared among nodes.
4002 check_shared_dir() {
4004 local list=${2:-$(comma_list $(nodes_list))}
4006 [ -z "$dir" ] && return 1
4007 do_rpc_nodes "$list" check_logdir $dir
4008 check_write_access $dir "$list" || return 1
4012 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4019 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4020 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4022 check_shared_dir $SHARED_DIRECTORY ||
4023 error "$SHARED_DIRECTORY isn't a shared directory"
4025 export MDSDB=$SHARED_DIRECTORY/mdsdb
4026 export OSTDB=$SHARED_DIRECTORY/ostdb
4028 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4029 # we only pass master MDS parameters.
4030 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4035 for node in $(osts_nodes); do
4036 for dev in ${OSTDEVS[i]}; do
4037 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4038 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4039 ostidx=$((ostidx + 1))
4045 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4046 run_lfsck_remote() {
4047 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4052 #Check if lustre is already mounted
4053 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4055 zconf_mount $client $MOUNT ||
4056 error "failed to mount Lustre on $client"
4060 do_node $client $cmd || rc=$?
4061 #Umount if necessary
4063 zconf_umount $client $MOUNT ||
4064 error "failed to unmount Lustre on $client"
4067 [ $rc -le $FSCK_MAX_ERR ] ||
4068 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4069 echo "lfsck finished with rc=$rc"
4075 local facets="client $SINGLEMDS"
4081 for facet in $facets; do
4082 node=$(facet_active_host $facet)
4083 if check_progs_installed $node $LFSCK_BIN; then
4088 ! $found && error "None of \"$facets\" supports lfsck"
4090 run_lfsck_remote $node || rc=$?
4092 rm -rvf $MDSDB* $OSTDB* || true
4096 check_and_cleanup_lustre() {
4097 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4103 if is_mounted $MOUNT; then
4104 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4105 error "remove sub-test dirs failed"
4106 [ "$ENABLE_QUOTA" ] && restore_quota || true
4109 if [ "$I_UMOUNTED2" = "yes" ]; then
4110 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4113 if [ "$I_MOUNTED2" = "yes" ]; then
4114 cleanup_mount $MOUNT2
4117 if [ "$I_MOUNTED" = "yes" ]; then
4118 cleanupall -f || error "cleanup failed"
4122 if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
4123 umount /sbin/mount.lustre
4130 wait_for_function () {
4133 # suppress fn both stderr and stdout
4134 if [ "$1" = "--quiet" ]; then
4136 quiet=" > /dev/null 2>&1"
4148 eval $fn $quiet && return 0
4150 wait=$((wait + sleep))
4151 [ $wait -lt $max ] || return 1
4152 echo waiting $fn, $((max - wait)) secs left ...
4162 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4163 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4164 echo "Network not available!"
4168 echo `date +"%H:%M:%S (%s)"` network interface is UP
4176 # Convert a space-delimited list to a comma-delimited list. If the input is
4177 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4179 # echo is used to convert newlines to spaces, since it doesn't
4180 # introduce a trailing space as using "tr '\n' ' '" does
4181 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4187 echo $list | grep -qw $item
4190 # list, excluded are the comma separated lists
4191 exclude_items_from_list () {
4197 for item in ${excluded//,/ }; do
4198 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4200 echo $(comma_list $list)
4203 # list, expand are the comma separated lists
4205 local list=${1//,/ }
4206 local expand=${2//,/ }
4209 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4210 echo $(comma_list $expanded)
4213 testslist_filter () {
4214 local script=$LUSTRE/tests/${TESTSUITE}.sh
4216 [ -f $script ] || return 0
4218 local start_at=$START_AT
4219 local stop_at=$STOP_AT
4221 local var=${TESTSUITE//-/_}_START_AT
4222 [ x"${!var}" != x ] && start_at=${!var}
4223 var=${TESTSUITE//-/_}_STOP_AT
4224 [ x"${!var}" != x ] && stop_at=${!var}
4226 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4227 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4228 /^'${start_at}'$/ {flag = 0}
4229 {if (flag == 1) print $0}
4230 /^'${stop_at}'$/ { flag = 1 }'
4234 (cd `dirname $1`; echo $PWD/`basename $1`)
4238 local types=${1:-"OST MDS MGS"}
4242 for entry in $types; do
4243 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4244 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4247 MGS ) list="$list $name";;
4248 MDS|OST|AGT ) local count=${type}COUNT
4249 for ((i=1; i<=${!count}; i++)) do
4250 list="$list ${name}$i"
4252 * ) error "Invalid facet type"
4256 echo $(comma_list $list)
4259 ##################################
4260 # Adaptive Timeouts funcs
4263 # only check mds, we assume at_max is the same on all nodes
4264 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4265 if [ $at_max -eq 0 ]; then
4276 # suppose that all ost-s have the same $at value set
4277 [ $facet != "ost" ] || facet=ost1
4279 do_facet $facet "lctl get_param -n $at"
4297 if [ $facet == "ost" ]; then
4298 facet=$(get_facets OST)
4299 elif [ $facet == "mds" ]; then
4300 facet=$(get_facets MDS)
4302 hosts=$(expand_list $hosts $(facets_hosts $facet))
4305 do_nodes $hosts lctl set_param at_max=$at_max
4308 ##################################
4312 # OBD_FAIL_MDS_ALL_REQUEST_NET
4314 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4315 do_facet client "$1" || RC=$?
4316 do_facet $SINGLEMDS lctl set_param fail_loc=0
4321 # OBD_FAIL_MDS_ALL_REPLY_NET
4323 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4325 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4329 drop_reint_reply() {
4330 # OBD_FAIL_MDS_REINT_NET_REP
4332 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4334 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4338 drop_update_reply() {
4339 # OBD_FAIL_UPDATE_OBJ_NET_REP
4343 do_facet mds${index} lctl set_param fail_loc=0x1701
4344 do_facet client "$@" || RC=$?
4345 do_facet mds${index} lctl set_param fail_loc=0
4350 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4353 local timeout=${2:-0}
4354 # default is (obd_timeout / 4) if unspecified
4355 echo "timeout is $timeout/$2"
4356 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4357 do_facet client "$1" || RC=$?
4358 do_facet client "sync"
4359 do_facet ost1 lctl set_param fail_loc=0
4363 drop_ldlm_cancel() {
4364 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4366 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4367 do_nodes $list lctl set_param fail_loc=0x304
4369 do_facet client "$@" || RC=$?
4371 do_nodes $list lctl set_param fail_loc=0
4375 drop_bl_callback_once() {
4377 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4378 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4379 do_facet client lctl set_param fail_loc=0x80000305
4380 do_facet client "$@" || rc=$?
4381 do_facet client lctl set_param fail_loc=0
4382 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4386 drop_bl_callback() {
4388 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4389 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4390 do_facet client lctl set_param fail_loc=0x305
4391 do_facet client "$@" || rc=$?
4392 do_facet client lctl set_param fail_loc=0
4393 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4398 #define OBD_FAIL_LDLM_REPLY 0x30c
4400 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4401 do_nodes $list lctl set_param fail_loc=0x30c
4403 do_facet client "$@" || RC=$?
4405 do_nodes $list lctl set_param fail_loc=0
4409 drop_ldlm_reply_once() {
4410 #define OBD_FAIL_LDLM_REPLY 0x30c
4412 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4413 do_nodes $list lctl set_param fail_loc=0x8000030c
4415 do_facet client "$@" || RC=$?
4417 do_nodes $list lctl set_param fail_loc=0
4425 echo "clearing fail_loc on $facet"
4426 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4429 set_nodes_failloc () {
4430 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4433 cancel_lru_locks() {
4434 $LCTL mark "cancel_lru_locks $1 start"
4436 if [ $1 != "MGC" ]; then
4437 for d in $(lctl get_param -N ldlm.namespaces.*.lru_size |
4439 $LCTL set_param -n $d=clear
4441 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 |
4445 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lru_size \
4451 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lock_unused_count \
4453 if [ $(cat $d) != 0 ]; then
4454 echo "ldlm.namespaces.$(echo "$d" |
4455 cut -f 7 -d'/').lock_unused_count=$(cat $d)"
4460 $LCTL mark "cancel_lru_locks $1 stop"
4465 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4466 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4467 echo "$DEFAULT_LRU_SIZE"
4472 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4475 lru_resize_disable()
4477 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4483 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4489 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4490 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4491 echo there is still data in page cache $FILE ?
4492 lctl get_param -n $FILE
4500 DEBUGSAVE="$(lctl get_param -n debug)"
4504 [ -n "$DEBUGSAVE" ] && \
4505 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4510 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4513 debug_size_restore() {
4514 [ -n "$DEBUG_SIZE_SAVED" ] && \
4515 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4519 start_full_debug_logging() {
4524 local DEBUG_SIZE=150
4526 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4527 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4530 stop_full_debug_logging() {
4535 # prints bash call stack
4538 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4539 local s=${BASH_SOURCE[$i]}
4540 local l=${BASH_LINENO[$i-1]}
4541 local f=${FUNCNAME[$i]}
4542 echo " = $s:$l:$f()"
4546 ##################################
4548 ##################################
4551 local TYPE=${TYPE:-"FAIL"}
4554 # do not dump logs if $1=false
4555 if [ "x$1" = "xfalse" ]; then
4561 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4565 # We need to dump the logs on all nodes
4567 gather_logs $(comma_list $(nodes_list))
4571 [ "$TESTSUITELOG" ] &&
4572 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4573 if [ -z "$*" ]; then
4574 echo "error() without useful message, please fix" > $LOGDIR/err
4576 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4577 echo "$@" > $LOGDIR/ignore
4579 echo "$@" > $LOGDIR/err
4586 local log=$TESTSUITELOG
4588 [ -f "$log" ] && grep -q FAIL $log && status=1
4601 # use only if we are ignoring failures for this test, bugno required.
4602 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4603 # e.g. error_ignore bz5494 "your message" or
4604 # error_ignore LU-5494 "your message"
4606 local TYPE="IGNORE ($1)"
4611 error_and_remount() {
4613 remount_client $MOUNT
4618 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4623 log " SKIP: $TESTSUITE $TESTNAME $@"
4625 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4626 skip_logged $TESTNAME "$@"
4629 echo "$@" > $LOGDIR/skip
4632 [[ -n "$TESTSUITELOG" ]] &&
4633 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4636 build_test_filter() {
4637 EXCEPT="$EXCEPT $(testslist_filter)"
4640 if [[ $O = [0-9]*-[0-9]* ]]; then
4641 for num in $(seq $(echo $O | tr '-' ' ')); do
4649 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4650 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4651 [ "$EXCEPT_SLOW" ] && \
4652 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4653 for E in $EXCEPT; do
4654 eval EXCEPT_${E}=true
4656 for E in $ALWAYS_EXCEPT; do
4657 eval EXCEPT_ALWAYS_${E}=true
4659 for E in $EXCEPT_SLOW; do
4660 eval EXCEPT_SLOW_${E}=true
4662 for G in $GRANT_CHECK_LIST; do
4663 eval GCHECK_ONLY_${G}=true
4668 if [[ $1 = [a-z]* ]]; then
4675 # print a newline if the last test was skipped
4676 export LAST_SKIPPED=
4677 export ALWAYS_SKIPPED=
4679 # Main entry into test-framework. This is called with the name and
4680 # description of a test. The name is used to find the function to run
4681 # the test using "test_$name".
4683 # This supports a variety of methods of specifying specific test to
4684 # run or not run. These need to be documented...
4689 export base=$(basetest $1)
4690 if [ -n "$ONLY" ]; then
4692 if [ ${!testname}x != x ]; then
4693 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4694 run_one_logged $1 "$2"
4698 if [ ${!testname}x != x ]; then
4699 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4700 run_one_logged $1 "$2"
4710 if [ ${!testname}x != x ]; then
4711 TESTNAME=test_$1 skip "skipping excluded test $1"
4714 testname=EXCEPT_$base
4715 if [ ${!testname}x != x ]; then
4716 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4719 testname=EXCEPT_ALWAYS_$1
4720 if [ ${!testname}x != x ]; then
4721 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4724 testname=EXCEPT_ALWAYS_$base
4725 if [ ${!testname}x != x ]; then
4726 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4729 testname=EXCEPT_SLOW_$1
4730 if [ ${!testname}x != x ]; then
4731 TESTNAME=test_$1 skip "skipping SLOW test $1"
4734 testname=EXCEPT_SLOW_$base
4735 if [ ${!testname}x != x ]; then
4736 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4742 run_one_logged $1 "$2"
4749 module_loaded lnet || load_modules
4761 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4766 strace -o $TMP/$1.strace -ttt $*
4768 log "FINISHED: $*: rc $RC"
4775 banner test complete, duration $duration sec
4776 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4777 echo duration $duration >>$TESTSUITELOG
4781 # Set TEST_STATUS here. It will be used for logging the result.
4784 if [[ -f $LOGDIR/err ]]; then
4786 elif [[ -f $LOGDIR/skip ]]; then
4789 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4793 local FFREE=$(do_node $SINGLEMDS \
4794 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4795 local FTOTAL=$(do_node $SINGLEMDS \
4796 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4798 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4802 echo -n "Resetting fail_loc on all nodes..."
4803 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
4804 fail_val=0 2>/dev/null || true"
4810 # Log a message (on all nodes) padded with "=" before and after.
4811 # Also appends a timestamp and prepends the testsuite name.
4814 EQUALS="===================================================================================================="
4816 msg="== ${TESTSUITE} $*"
4818 [[ $last != "=" && $last != " " ]] && msg="$msg "
4819 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4820 # always include at least == after the message
4821 log "$msg== $(date +"%H:%M:%S (%s)")"
4825 # Run a single test function and cleanup after it.
4827 # This function should be run in a subshell so the test func can
4828 # exit() without stopping the whole script.
4833 export tfile=f${testnum}.${TESTSUITE}
4834 export tdir=d${testnum}.${TESTSUITE}
4835 export TESTNAME=test_$testnum
4836 local SAVE_UMASK=`umask`
4839 banner "test $testnum: $message"
4840 test_${testnum} || error "test_$testnum failed with $?"
4843 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4844 check_catastrophe || error "LBUG/LASSERT detected"
4845 if [ "$PARALLEL" != "yes" ]; then
4846 ps auxww | grep -v grep | grep -q multiop &&
4847 error "multiop still running"
4857 # Wrapper around run_one to ensure:
4858 # - test runs in subshell
4859 # - output of test is saved to separate log file for error reporting
4860 # - test result is saved to data file
4863 local BEFORE=$(date +%s)
4865 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4866 local test_log=$LOGDIR/$name
4868 rm -rf $LOGDIR/ignore
4870 local SAVE_UMASK=$(umask)
4874 log_sub_test_begin test_${1}
4875 (run_one $1 "$2") 2>&1 | tee -i $test_log
4876 local RC=${PIPESTATUS[0]}
4878 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4879 echo "test_$1 returned $RC" | tee $LOGDIR/err
4881 duration=$(($(date +%s) - $BEFORE))
4882 pass "$1" "(${duration}s)"
4884 if [[ -f $LOGDIR/err ]]; then
4885 TEST_ERROR=$(cat $LOGDIR/err)
4886 elif [[ -f $LOGDIR/ignore ]]; then
4887 TEST_ERROR=$(cat $LOGDIR/ignore)
4888 elif [[ -f $LOGDIR/skip ]]; then
4889 TEST_ERROR=$(cat $LOGDIR/skip)
4891 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4893 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4897 if [ -f $LOGDIR/err ]; then
4898 $FAIL_ON_ERROR && exit $RC
4907 # Print information of skipped tests to result.yml
4910 log_sub_test_begin $1
4912 log_sub_test_end "SKIP" "0" "0" "$@"
4916 (cd $(dirname $1); echo $PWD/$(basename $1))
4921 export base=$(basetest $1)
4922 [ "$CHECK_GRANT" == "no" ] && return 0
4924 testname=GCHECK_ONLY_${base}
4925 [ ${!testname}x == x ] && return 0
4927 echo -n "checking grant......"
4929 local clients=$CLIENTS
4930 [ -z "$clients" ] && clients=$(hostname)
4932 # sync all the data and make sure no pending data on server
4933 do_nodes $clients sync
4936 client_grant=$(do_nodes $clients \
4937 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
4938 awk '{ total += $1 } END { printf("%0.0f", total) }')
4941 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
4942 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4943 awk '{ total += $1 } END { printf("%0.0f", total) }')
4945 # check whether client grant == server grant
4946 if [[ $client_grant -ne $server_grant ]]; then
4947 echo "failed: client:${client_grant} server: ${server_grant}."
4948 do_nodes $(comma_list $(osts_nodes)) \
4949 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4950 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4953 echo "pass: client:${client_grant} server: ${server_grant}"
4957 ########################
4963 ost=`echo $1 | awk -F_ '{print $3}'`
4964 if [ -z $ost ]; then
4965 ost=`echo $1 | sed 's/-osc.*//'`
4970 ostuuid_from_index()
4972 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4975 ostname_from_index() {
4976 local uuid=$(ostuuid_from_index $1)
4980 index_from_ostuuid()
4982 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4985 mdtuuid_from_index()
4987 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4991 # Return unique identifier for given hostname
4994 echo $host_name | md5sum | cut -d' ' -f1
4998 # Returns list of ip addresses for each interface
5000 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5005 # Cache address list to avoid mutiple execution of local_addr_list
5006 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5008 for i in $LOCAL_ADDR_LIST ; do
5009 [[ "$i" == "$addr" ]] && return 0
5016 local is_local="IS_LOCAL_$(host_id $host_name)"
5017 if [ -z "${!is_local-}" ] ; then
5019 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5020 is_local_addr "$host_ip" && eval $is_local=1
5022 [[ "${!is_local}" == "1" ]]
5027 local_node $node && return 1
5034 for node in $(mdts_nodes); do
5035 remote_node $node && return 0
5042 [ "$CLIENTONLY" ] && return 0 || true
5043 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5048 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5049 MSKIPPED=1 && return 1
5056 for node in $(osts_nodes) ; do
5057 remote_node $node && return 0
5064 [ "$CLIENTONLY" ] && return 0 || true
5065 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5070 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5071 OSKIPPED=1 && return 1
5078 MGS=$(facet_host mgs)
5079 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5084 remote_mds_nodsh || remote_ost_nodsh || \
5085 $(single_local_node $(comma_list $(nodes_list)))
5089 remote_ost && remote_mds
5092 # Get the active nodes for facets.
5100 for facet in ${facets//,/ }; do
5101 nodes="$nodes $(facet_active_host $facet)"
5104 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5108 # Get all of the active MDS nodes.
5110 echo -n $(facets_nodes $(get_facets MDS))
5113 # Get all of the active OSS nodes.
5115 echo -n $(facets_nodes $(get_facets OST))
5118 # Get all of the active AGT (HSM agent) nodes.
5120 echo -n $(facets_nodes $(get_facets AGT))
5123 # Get all of the client nodes and active server nodes.
5125 local nodes=$HOSTNAME
5129 # CLIENTS (if specified) contains the local client
5130 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5132 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5133 nodes="$nodes $(facets_nodes $(get_facets))"
5136 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5140 # Get all of the remote client nodes and remote active server nodes.
5141 remote_nodes_list () {
5142 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5145 # Get all of the MDS nodes, including active and passive nodes.
5153 for i in $(seq $MDSCOUNT); do
5155 failover_host=mds${i}failover_HOST
5156 nodes="$nodes ${!host} ${!failover_host}"
5159 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5163 # Get all of the OSS nodes, including active and passive nodes.
5171 for i in $(seq $OSTCOUNT); do
5173 failover_host=ost${i}failover_HOST
5174 nodes="$nodes ${!host} ${!failover_host}"
5177 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5181 # Get all of the server nodes, including active and passive nodes.
5182 all_server_nodes () {
5187 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5189 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5193 # Get all of the client and server nodes, including active and passive nodes.
5195 local nodes=$HOSTNAME
5199 # CLIENTS (if specified) contains the local client
5200 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5202 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5203 nodes="$nodes $(all_server_nodes)"
5206 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5210 init_clients_lists () {
5211 # Sanity check: exclude the local client from RCLIENTS
5212 local clients=$(hostlist_expand "$RCLIENTS")
5213 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5215 # Sanity check: exclude the dup entries
5216 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5218 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5220 # Sanity check: exclude the dup entries from CLIENTS
5221 # for those configs which has SINGLCLIENT set to local client
5222 clients=$(for i in $clients; do echo $i; done | sort -u)
5224 CLIENTS=$(comma_list $clients)
5225 local -a remoteclients=($RCLIENTS)
5226 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5227 varname=CLIENT$((i + 2))
5228 eval $varname=${remoteclients[i]}
5231 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5234 get_random_entry () {
5237 rnodes=${rnodes//,/ }
5239 local -a nodes=($rnodes)
5240 local num=${#nodes[@]}
5241 local i=$((RANDOM * num * 2 / 65536))
5247 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5252 lctl get_param version | grep -q patchless
5256 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5257 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5262 echo $nodes | wc -w || true
5266 local nodes=$(osts_nodes)
5267 local osscount=$(get_node_count "$nodes")
5268 [ ! "$OSTCOUNT" = "$osscount" ]
5272 local nodes=$(mdts_nodes)
5273 local mdtcount=$(get_node_count "$nodes")
5274 [ ! "$MDSCOUNT" = "$mdtcount" ]
5277 generate_machine_file() {
5278 local nodes=${1//,/ }
5279 local machinefile=$2
5281 for node in $nodes; do
5282 echo $node >>$machinefile || \
5283 { echo "can not generate machinefile $machinefile" && return 1; }
5288 local file=$1/stripe
5291 $LFS getstripe -v $file || error "getstripe $file failed"
5295 setstripe_nfsserver () {
5298 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5299 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5301 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5303 do_nodev $nfsserver lfs setstripe "$@"
5306 # Check and add a test group.
5312 local gid=$(getent group $group_name | cut -d: -f3)
5313 if [[ -n "$gid" ]]; then
5314 [[ "$gid" -eq "$group_id" ]] || {
5315 error_noexit "inconsistent group ID:" \
5316 "new: $group_id, old: $gid"
5320 groupadd -g $group_id $group_name
5327 # Check and add a test user.
5340 local uid=$(getent passwd $user_name | cut -d: -f3)
5341 if [[ -n "$uid" ]]; then
5342 if [[ "$uid" -eq "$user_id" ]]; then
5343 local dir=$(getent passwd $user_name | cut -d: -f6)
5344 if [[ "$dir" != "$home" ]]; then
5346 usermod -d $home $user_name
5350 error_noexit "inconsistent user ID:" \
5351 "new: $user_id, old: $uid"
5356 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5363 check_runas_id_ret() {
5365 local myRUNAS_UID=$1
5366 local myRUNAS_GID=$2
5369 if [ -z "$myRUNAS" ]; then
5370 error_exit "myRUNAS command must be specified for check_runas_id"
5373 $myRUNAS krb5_login.sh || \
5374 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5376 mkdir $DIR/d0_runas_test
5378 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5379 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5380 rm -rf $DIR/d0_runas_test
5385 local myRUNAS_UID=$1
5386 local myRUNAS_GID=$2
5389 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5390 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5391 Please set RUNAS_ID to some UID which exists on MDS and client or
5392 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5395 # obtain the UID/GID for MPI_USER
5399 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5400 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5402 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5403 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5406 # obtain and cache Kerberos ticket-granting ticket
5407 refresh_krb5_tgt() {
5408 local myRUNAS_UID=$1
5409 local myRUNAS_GID=$2
5412 if [ -z "$myRUNAS" ]; then
5413 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5416 CLIENTS=${CLIENTS:-$HOSTNAME}
5417 do_nodes $CLIENTS "set -x
5418 if ! $myRUNAS krb5_login.sh; then
5419 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5424 # Run multiop in the background, but wait for it to print
5425 # "PAUSING" to its stdout before returning from this function.
5426 multiop_bg_pause() {
5427 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5431 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5434 echo "$MULTIOP_PROG $FILE v$ARGS"
5435 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5437 echo "TMPPIPE=${TMPPIPE}"
5438 read -t 60 multiop_output < $TMPPIPE
5439 if [ $? -ne 0 ]; then
5444 if [ "$multiop_output" != "PAUSING" ]; then
5445 echo "Incorrect multiop output: $multiop_output"
5460 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5466 inodes_available () {
5467 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5468 sort -un | head -n1) || return 1
5472 mdsrate_inodes_available () {
5473 local min_inodes=$(inodes_available)
5474 echo $((min_inodes * 99 / 100))
5477 # reset llite stat counters
5478 clear_llite_stats(){
5479 lctl set_param -n llite.*.stats 0
5482 # sum llite stat items
5483 calc_llite_stats() {
5484 local res=$(lctl get_param -n llite.*.stats |
5485 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5489 # reset osc stat counters
5491 lctl set_param -n osc.*.osc_stats 0
5494 # sum osc stat items
5496 local res=$(lctl get_param -n osc.*.osc_stats |
5497 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5502 awk '{sum += $1} END { printf("%0.0f", sum) }'
5505 calc_osc_kbytes () {
5506 df $MOUNT > /dev/null
5507 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5510 # save_lustre_params(comma separated facet list, parameter_mask)
5511 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5512 save_lustre_params() {
5518 for facet in ${facets//,/ }; do
5519 node=$(facet_active_host $facet)
5520 [[ *\ $node\ * = " $nodes " ]] && continue
5521 nodes="$nodes $node"
5523 do_node $node "$LCTL get_param $2 |
5524 while read s; do echo $facet \\\$s; done"
5528 # restore lustre parameters from input stream, produces by save_lustre_params
5529 restore_lustre_params() {
5534 while IFS=" =" read facet name val; do
5535 do_facet $facet "$LCTL set_param -n $name $val"
5539 check_catastrophe() {
5540 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5541 VAR=$(lctl get_param -n catastrophe 2>&1)
5542 if [ $? = 0 ] ; then
5543 if [ $VAR != 0 ]; then
5548 [ -z "$rnodes" ] && return 0
5551 data=$(do_nodes "$rnodes" "rc=\\\$(lctl get_param -n catastrophe);
5552 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5555 if [ -n "$data" ]; then
5562 # CMD: determine mds index where directory inode presents
5565 local file=$dir/f0.get_mds_dir_tmpfile
5570 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5571 local -a oldused=($iused)
5573 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5575 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5576 local -a newused=($iused)
5579 for ((i=0; i<${#newused[@]}; i++)); do
5580 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5586 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5589 mdsrate_cleanup () {
5591 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5592 --nfiles $3 --dir $4 --filefmt $5 $6
5597 delayed_recovery_enabled () {
5598 local var=${SINGLEMDS}_svc
5599 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5602 ########################
5604 convert_facet2label() {
5607 if [ x$facet = xost ]; then
5611 local varsvc=${facet}_svc
5613 if [ -n ${!varsvc} ]; then
5616 error "No lablel for $facet!"
5620 get_clientosc_proc_path() {
5624 get_lustre_version () {
5625 local facet=${1:-"$SINGLEMDS"}
5626 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5629 lustre_version_code() {
5630 local facet=${1:-"$SINGLEMDS"}
5631 version_code $(get_lustre_version $1)
5634 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5635 # used by MDT would not be changed.
5636 # mdt lov: fsname-mdtlov
5637 # mdt osc: fsname-OSTXXXX-osc
5638 mds_on_old_device() {
5639 local mds=${1:-"$SINGLEMDS"}
5641 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5642 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5643 > /dev/null 2>&1" && return 0
5648 get_mdtosc_proc_path() {
5650 local ost_label=${2:-"*OST*"}
5652 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5653 local mdt_label=$(convert_facet2label $mds_facet)
5654 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5656 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5657 mds_on_old_device $mds_facet; then
5658 echo "${ost_label}-osc"
5660 echo "${ost_label}-osc-${mdt_index}"
5664 get_osc_import_name() {
5667 local label=$(convert_facet2label $ost)
5669 if [ "${facet:0:3}" = "mds" ]; then
5670 get_mdtosc_proc_path $facet $label
5674 get_clientosc_proc_path $label
5678 _wait_import_state () {
5681 local maxtime=${3:-$(max_recovery_time)}
5685 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5686 while [ "${CONN_STATE}" != "${expected}" ]; do
5687 if [ "${expected}" == "DISCONN" ]; then
5688 # for disconn we can check after proc entry is removed
5689 [ "x${CONN_STATE}" == "x" ] && return 0
5690 # with AT enabled, we can have connect request timeout near of
5691 # reconnect timeout and test can't see real disconnect
5692 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5694 [ $i -ge $maxtime ] && \
5695 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5698 # Add uniq for multi-mount case
5699 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5703 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5707 wait_import_state() {
5710 local maxtime=${3:-$(max_recovery_time)}
5713 for param in ${params//,/ }; do
5714 _wait_import_state $state $param $maxtime || return
5718 wait_import_state_mount() {
5719 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5723 wait_import_state $*
5726 # One client request could be timed out because server was not ready
5727 # when request was sent by client.
5728 # The request timeout calculation details :
5730 # /* We give the server rq_timeout secs to process the req, and
5731 # add the network latency for our local timeout. */
5732 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5733 # ptlrpc_at_get_net_latency(request) ;
5735 # ptlrpc_connect_import ()
5736 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5739 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5740 # ptlrpc_at_get_net_latency(request) ->
5741 # at_get (max (iat_net_latency=0, at_min)) = at_min
5744 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5745 # INITIAL_CONNECT_TIMEOUT + at_min
5747 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5748 # because we can not get this value in runtime,
5749 # the value depends on configure options, and it is not stored in /proc.
5751 # #define CONNECTION_SWITCH_MIN 5U
5752 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5754 request_timeout () {
5757 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5758 local init_connect_timeout=$TIMEOUT
5759 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5761 local at_min=$(at_get $facet at_min)
5763 echo $(( init_connect_timeout + at_min ))
5766 _wait_osc_import_state() {
5770 local ost=$(get_osc_import_name $facet $ost_facet)
5771 local param="osc.${ost}.ost_server_uuid"
5775 # 1. wait the deadline of client 1st request (it could be skipped)
5776 # 2. wait the deadline of client 2nd request
5777 local maxtime=$(( 2 * $(request_timeout $facet)))
5779 if [[ $facet == client* ]]; then
5780 # During setup time, the osc might not be setup, it need wait
5781 # until list_param can return valid value. And also if there
5782 # are mulitple osc entries we should list all of them before
5784 params=$($LCTL list_param $param 2>/dev/null || true)
5785 while [ -z "$params" ]; do
5786 if [ $i -ge $maxtime ]; then
5787 echo "can't get $param in $maxtime secs"
5792 params=$($LCTL list_param $param 2>/dev/null || true)
5795 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5796 wait_import_state $expected "$params" $maxtime; then
5797 error "import is not in ${expected} state"
5804 wait_osc_import_state() {
5810 if [[ $facet = mds ]]; then
5811 for num in $(seq $MDSCOUNT); do
5812 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5815 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5819 get_clientmdc_proc_path() {
5827 [ -z "$list" ] && return 0
5829 # Add paths to lustre tests for 32 and 64 bit systems.
5830 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5831 local TESTPATH="$RLUSTRE/tests:"
5832 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5833 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5836 wait_clients_import_state () {
5843 if [ "$FAILURE_MODE" = HARD ]; then
5844 facets=$(facets_on_host $(facet_active_host $facet))
5847 for facet in ${facets//,/ }; do
5848 local label=$(convert_facet2label $facet)
5851 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5852 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5853 *) error "unknown facet!" ;;
5855 local params=$(expand_list $params $proc_path)
5858 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5859 error "import is not in ${expected} state"
5869 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5870 $LCTL get_param obdfilter.*.kbytesavail))
5871 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5872 $LCTL get_param -n obdfilter.*.tot_granted))
5873 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5874 $LCTL get_param -n obdfilter.*.kbytestotal))
5875 for ((i=0; i<${#AVAILA[@]}; i++)); do
5876 local -a AVAIL1=(${AVAILA[$i]//=/ })
5877 local -a TOTAL=(${TOTALA[$i]//=/ })
5878 GRANT=$((${GRANTA[$i]}/1024))
5879 # allow 1% of total space in bavail because of delayed
5880 # allocation with ZFS which might release some free space after
5881 # txg commit. For small devices, we set a mininum of 8MB
5882 local LIMIT=$((${TOTAL} / 100 + 8000))
5883 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5884 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5885 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5886 echo " FULL" || echo
5892 do_facet mgs lctl pool_list $1
5896 local fsname=${1%%.*}
5897 local poolname=${1##$fsname.}
5899 do_facet mgs lctl pool_new $1
5901 # get param should return err unless pool is created
5902 [[ $RC -ne 0 ]] && return $RC
5904 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5905 2>/dev/null || echo foo" "" || RC=1
5906 if [[ $RC -eq 0 ]]; then
5909 error "pool_new failed $1"
5914 add_pool_to_list () {
5915 local fsname=${1%%.*}
5916 local poolname=${1##$fsname.}
5918 local listvar=${fsname}_CREATED_POOLS
5919 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5922 remove_pool_from_list () {
5923 local fsname=${1%%.*}
5924 local poolname=${1##$fsname.}
5926 local listvar=${fsname}_CREATED_POOLS
5927 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5930 destroy_pool_int() {
5932 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5933 awk '$1 !~ /^Pool:/ {print $1}')
5934 for ost in $OSTS; do
5935 do_facet mgs lctl pool_remove $1 $ost
5937 do_facet mgs lctl pool_destroy $1
5940 # <fsname>.<poolname> or <poolname>
5942 local fsname=${1%%.*}
5943 local poolname=${1##$fsname.}
5945 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5949 pool_list $fsname.$poolname || return $?
5951 destroy_pool_int $fsname.$poolname
5953 [[ $RC -ne 0 ]] && return $RC
5955 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5956 2>/dev/null || echo foo" "foo" || RC=1
5958 if [[ $RC -eq 0 ]]; then
5959 remove_pool_from_list $fsname.$poolname
5961 error "destroy pool failed $1"
5967 local fsname=${1:-$FSNAME}
5969 local listvar=${fsname}_CREATED_POOLS
5973 [ x${!listvar} = x ] && return 0
5975 echo destroy the created pools: ${!listvar}
5976 for poolname in ${!listvar//,/ }; do
5977 destroy_pool $fsname.$poolname
5982 local fsname=${1:-$FSNAME}
5984 destroy_pools $fsname
5990 local ts=$(date +%s)
5993 if [[ ! -f "$YAML_LOG" ]]; then
5994 # init_logging is not performed before gather_logs,
5995 # so the $LOGDIR needs to be checked here
5996 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5999 [ -f $LOGDIR/shared ] && docp=false
6001 # dump lustre logs, dmesg
6003 prefix="$TESTLOG_PREFIX.$TESTNAME"
6005 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6007 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6008 echo "Dumping logs only on local client."
6009 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6010 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6015 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6016 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6017 if [ ! -f $LOGDIR/shared ]; then
6018 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6031 for i in $(seq 0 $num_mntpts); do
6032 cmd="ls -laf ${mntpt_root}$i/$dir"
6038 for pid in $pids; do
6045 # target_start_and_reset_recovery_timer()
6046 # service_time = at_est2timeout(service_time);
6047 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
6048 # INITIAL_CONNECT_TIMEOUT);
6049 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
6050 #define CONNECTION_SWITCH_INC 1
6051 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6052 #define CONNECTION_SWITCH_MIN 5U
6054 max_recovery_time () {
6055 local init_connect_timeout=$(( TIMEOUT / 20 ))
6056 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6058 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
6063 get_clients_mount_count () {
6064 local clients=${CLIENTS:-`hostname`}
6066 # we need to take into account the clients mounts and
6067 # exclude mds/ost mounts if any;
6068 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6072 PROC_CLI="srpc_info"
6080 if [ $M -lt $N ]; then
6084 while [ $N -lt $M ]; do
6094 calc_connection_cnt() {
6097 # MDT->MDT = 2 * C(M, 2)
6101 comb_m2=$(combination $MDSCOUNT 2)
6103 local num_clients=$(get_clients_mount_count)
6105 local cnt_mdt2mdt=$((comb_m2 * 2))
6106 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6107 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6108 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6109 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6110 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6111 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6125 local cmd="$tgt.srpc.flavor"
6127 if [ $net == "any" ]; then
6132 if [ $dir != "any" ]; then
6137 log "Setting sptlrpc rule: $cmd"
6138 do_facet mgs "$LCTL conf_param $cmd"
6147 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6148 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6150 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6152 if [ "x$bulkspec" != "x" ]; then
6153 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6155 if [ "x$algs" != "x" ]; then
6156 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6158 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6159 if [ $bulk == "bulkn" ]; then
6160 bulk_count=`echo "$output" | grep "bulk flavor" \
6161 | grep "null/null" | wc -l`
6162 elif [ $bulk == "bulki" ]; then
6163 bulk_count=`echo "$output" | grep "bulk flavor" \
6164 | grep "/null" | grep -v "null/" | wc -l`
6166 bulk_count=`echo "$output" | grep "bulk flavor" \
6167 | grep -v "/null" | grep -v "null/" | wc -l`
6171 [ $bulk_count -lt $count ] && count=$bulk_count
6182 local clients=${CLIENTS:-`hostname`}
6184 for c in ${clients//,/ }; do
6185 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6186 tmpcnt=`count_flvr "$output" $flavor`
6187 cnt=$((cnt + tmpcnt))
6197 local clients=${CLIENTS:-`hostname`}
6199 for c in ${clients//,/ }; do
6200 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6201 tmpcnt=`count_flvr "$output" $flavor`
6202 cnt=$((cnt + tmpcnt))
6212 if [ $MDSCOUNT -le 1 ]; then
6217 for num in `seq $MDSCOUNT`; do
6218 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6219 tmpcnt=`count_flvr "$output" $flavor`
6220 cnt=$((cnt + tmpcnt))
6231 for num in `seq $MDSCOUNT`; do
6232 mdtosc=$(get_mdtosc_proc_path mds$num)
6233 mdtosc=${mdtosc/-MDT*/-MDT\*}
6234 output=$(do_facet mds$num lctl get_param -n \
6235 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6236 tmpcnt=`count_flvr "$output" $flavor`
6237 cnt=$((cnt + tmpcnt))
6246 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6247 count_flvr "$output" $flavor
6252 local dir=$1 # from to
6253 local flavor=$2 # flavor expected
6256 if [ $dir == "cli2mdt" ]; then
6257 res=`flvr_cnt_cli2mdt $flavor`
6258 elif [ $dir == "cli2ost" ]; then
6259 res=`flvr_cnt_cli2ost $flavor`
6260 elif [ $dir == "mdt2mdt" ]; then
6261 res=`flvr_cnt_mdt2mdt $flavor`
6262 elif [ $dir == "mdt2ost" ]; then
6263 res=`flvr_cnt_mdt2ost $flavor`
6264 elif [ $dir == "all2ost" ]; then
6265 res1=`flvr_cnt_mdt2ost $flavor`
6266 res2=`flvr_cnt_cli2ost $flavor`
6267 res=$((res1 + res2))
6268 elif [ $dir == "all2mdt" ]; then
6269 res1=`flvr_cnt_mdt2mdt $flavor`
6270 res2=`flvr_cnt_cli2mdt $flavor`
6271 res=$((res1 + res2))
6272 elif [ $dir == "all2all" ]; then
6273 res1=`flvr_cnt_mdt2ost $flavor`
6274 res2=`flvr_cnt_cli2ost $flavor`
6275 res3=`flvr_cnt_mdt2mdt $flavor`
6276 res4=`flvr_cnt_cli2mdt $flavor`
6277 res=$((res1 + res2 + res3 + res4))
6285 local dir=$1 # from to
6286 local flavor=$2 # flavor expected
6287 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6291 for ((i=0;i<20;i++)); do
6292 echo -n "checking $dir..."
6293 res=$(do_check_flavor $dir $flavor)
6294 echo "found $res/$expect $flavor connections"
6295 [ $res -ge $expect ] && return 0
6299 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6303 restore_to_default_flavor()
6305 local proc="mgs.MGS.live.$FSNAME"
6307 echo "restoring to default flavor..."
6309 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6311 # remove all existing rules if any
6312 if [ $nrule -ne 0 ]; then
6313 echo "$nrule existing rules"
6314 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6315 echo "remove rule: $rule"
6316 spec=`echo $rule | awk -F = '{print $1}'`
6317 do_facet mgs "$LCTL conf_param -d $spec"
6321 # verify no rules left
6322 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6323 [ $nrule -ne 0 ] && error "still $nrule rules left"
6325 # wait for default flavor to be applied
6326 # currently default flavor for all connections are 'null'
6327 wait_flavor all2all null
6328 echo "now at default flavor settings"
6333 local flavor=${1:-null}
6335 echo "setting all flavor to $flavor"
6337 # FIXME need parameter to this fn
6338 # and remove global vars
6339 local cnt_all2all=$(calc_connection_cnt all2all)
6341 local res=$(do_check_flavor all2all $flavor)
6342 if [ $res -eq $cnt_all2all ]; then
6343 echo "already have total $res $flavor connections"
6347 echo "found $res $flavor out of total $cnt_all2all connections"
6348 restore_to_default_flavor
6350 [[ $flavor = null ]] && return 0
6352 set_rule $FSNAME any any $flavor
6353 wait_flavor all2all $flavor
6359 # Checking for shared logdir
6360 if [ ! -d $dir ]; then
6361 # Not found. Create local logdir
6364 touch $dir/check_file.$(hostname -s)
6369 check_write_access() {
6371 local list=${2:-$(comma_list $(nodes_list))}
6375 for node in ${list//,/ }; do
6376 file=$dir/check_file.$(short_nodename $node)
6377 if [[ ! -f "$file" ]]; then
6378 # Logdir not accessible/writable from this node.
6381 rm -f $file || return 1
6387 if [[ -n $YAML_LOG ]]; then
6390 local SAVE_UMASK=`umask`
6393 export YAML_LOG=${LOGDIR}/results.yml
6397 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6398 if check_shared_dir $LOGDIR; then
6399 touch $LOGDIR/shared
6400 echo "Logging to shared log directory: $LOGDIR"
6402 echo "Logging to local directory: $LOGDIR"
6405 yml_nodes_file $LOGDIR >> $YAML_LOG
6406 yml_results_file >> $YAML_LOG
6413 yml_log_test $1 >> $YAML_LOG
6417 yml_log_test_status $@ >> $YAML_LOG
6420 log_sub_test_begin() {
6421 yml_log_sub_test_begin "$@" >> $YAML_LOG
6424 log_sub_test_end() {
6425 yml_log_sub_test_end "$@" >> $YAML_LOG
6431 local llverdev_opts=$2
6432 local devname=$(basename $1)
6433 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6434 # loop devices aren't in /proc/partitions
6435 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6437 size=$(($size / 1024 / 1024)) # Gb
6439 local partial_arg=""
6440 # Run in partial (fast) mode if the size
6441 # of a partition > 1 GB
6442 [ $size -gt 1 ] && partial_arg="-p"
6444 llverdev --force $partial_arg $llverdev_opts $dev
6450 local llverfs_opts=$2
6451 local use_partial_arg=$3
6452 local partial_arg=""
6453 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6455 # Run in partial (fast) mode if the size
6456 # of a partition > 1 GB
6457 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6459 llverfs $partial_arg $llverfs_opts $dir
6462 #Remove objects from OST
6463 remove_ost_objects() {
6469 local mntpt=$(facet_mntpt $facet)
6470 local opts=$OST_MOUNT_OPTS
6474 echo "removing objects from $ostdev on $facet: $objids"
6475 if ! test -b $ostdev; then
6476 opts=$(csa_add "$opts" -o loop)
6478 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6481 for i in $objids; do
6482 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6484 umount -f $mntpt || return $?
6488 #Remove files from MDT
6489 remove_mdt_files() {
6494 local mntpt=$(facet_mntpt $facet)
6495 local opts=$MDS_MOUNT_OPTS
6497 echo "removing files from $mdtdev on $facet: $files"
6498 if [ $(facet_fstype $facet) == ldiskfs ] &&
6499 ! do_facet $facet test -b $mdtdev; then
6500 opts=$(csa_add "$opts" -o loop)
6502 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6506 rm $mntpt/ROOT/$f || { rc=$?; break; }
6508 umount -f $mntpt || return $?
6512 duplicate_mdt_files() {
6517 local mntpt=$(facet_mntpt $facet)
6518 local opts=$MDS_MOUNT_OPTS
6520 echo "duplicating files on $mdtdev on $facet: $files"
6521 mkdir -p $mntpt || return $?
6522 if [ $(facet_fstype $facet) == ldiskfs ] &&
6523 ! do_facet $facet test -b $mdtdev; then
6524 opts=$(csa_add "$opts" -o loop)
6526 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6537 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6538 pushd $mntpt/ROOT > /dev/null || return $?
6541 touch $f.bad || return $?
6542 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6544 [ $rc -eq 0 ] || return $rc
6545 setfattr --restore $tmp || return $?
6551 local devs=${1//,/ }
6554 local rslt=$TMP/sgpdd_survey
6556 # sgpdd-survey cleanups ${rslt}.* files
6558 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6564 # returns the canonical name for an ldiskfs device
6569 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6570 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6571 echo dm-\\\${foo##*:};
6573 echo \\\$(basename \\\$dv);
6577 is_sanity_benchmark() {
6578 local benchmarks="dbench bonnie iozone fsx"
6580 for b in $benchmarks; do
6581 if [ "$b" == "$suite" ]; then
6589 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6593 # Get the available size (KB) of a given obd target.
6600 [[ $facet != client ]] || return 0
6602 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6607 # Get the page size (bytes) on a given facet node.
6613 size=$(do_facet $facet getconf PAGE_SIZE)
6614 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6619 # Get the block count of the filesystem.
6626 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6627 awk '/^Block count:/ {print $3}')
6631 # Get the block size of the filesystem.
6637 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6638 awk '/^Block size:/ {print $3}')
6642 # Check whether the "large_xattr" feature is enabled or not.
6643 large_xattr_enabled() {
6644 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6646 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6648 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6649 grep -E -q '(ea_inode|large_xattr)'"
6650 return ${PIPESTATUS[0]}
6653 # Get the maximum xattr size supported by the filesystem.
6657 if large_xattr_enabled; then
6658 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6661 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6662 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6664 # maximum xattr size = size of block - size of header -
6665 # size of 1 entry - 4 null bytes
6666 size=$((block_size - 32 - 32 - 4))
6672 # Dump the value of the named xattr from a file.
6677 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6680 # Generate a string with size of $size bytes.
6682 local size=${1:-1024} # in bytes
6684 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6687 reformat_external_journal() {
6690 if [ ! -z ${EJOURNAL} ]; then
6691 local rcmd="do_facet $facet"
6693 echo "reformat external journal on $facet:${EJOURNAL}"
6694 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6698 # MDT file-level backup/restore
6699 mds_backup_restore() {
6702 local devname=$(mdsdevname $(facet_number $facet))
6703 local mntpt=$(facet_mntpt brpt)
6704 local rcmd="do_facet $facet"
6705 local metaea=${TMP}/backup_restore.ea
6706 local metadata=${TMP}/backup_restore.tgz
6707 local opts=${MDS_MOUNT_OPTS}
6708 local svc=${facet}_svc
6710 if ! ${rcmd} test -b ${devname}; then
6711 opts=$(csa_add "$opts" -o loop)
6714 echo "file-level backup/restore on $facet:${devname}"
6716 # step 1: build mount point
6717 ${rcmd} mkdir -p $mntpt
6718 # step 2: cleanup old backup
6719 ${rcmd} rm -f $metaea $metadata
6721 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6722 if [ ! -z $igif ]; then
6723 # step 3.5: rm .lustre
6724 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6726 # step 4: backup metaea
6728 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6730 # step 5: backup metadata
6732 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6734 ${rcmd} umount -d $mntpt || return 4
6735 # step 7: reformat external journal if needed
6736 reformat_external_journal $facet || return 5
6737 # step 8: reformat dev
6738 echo "reformat new device"
6739 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6740 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6741 > /dev/null || exit 6
6743 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6744 # step 10: restore metadata
6746 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6747 # step 11: restore metaea
6749 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6750 # step 12: remove recovery logs
6751 echo "remove recovery logs"
6752 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6753 # step 13: umount dev
6754 ${rcmd} umount -d $mntpt || return 10
6755 # step 14: cleanup tmp backup
6756 ${rcmd} rm -f $metaea $metadata
6757 # step 15: reset device label - it's not virgin on
6758 ${rcmd} e2label $devname ${!svc}
6765 local devname=$(mdsdevname $(facet_number $facet))
6766 local mntpt=$(facet_mntpt brpt)
6767 local rcmd="do_facet $facet"
6768 local opts=${MDS_MOUNT_OPTS}
6770 if ! ${rcmd} test -b ${devname}; then
6771 opts=$(csa_add "$opts" -o loop)
6774 echo "removing OI files on $facet: idx=${idx}"
6776 # step 1: build mount point
6777 ${rcmd} mkdir -p $mntpt
6779 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6780 if [ -z $idx ]; then
6781 # step 3: remove all OI files
6782 ${rcmd} rm -fv $mntpt/oi.16*
6783 elif [ $idx -lt 2 ]; then
6784 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6788 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6789 for ((i=${idx}; i<64; i=$((i * idx)))); do
6790 ${rcmd} rm -fv $mntpt/oi.16.${i}
6794 ${rcmd} umount -d $mntpt || return 2
6795 # OI files will be recreated when mounted as lustre next time.
6798 # generate maloo upload-able log file name
6799 # \param logname specify unique part of file name
6800 generate_logname() {
6801 local logname=${1:-"default_logname"}
6803 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6806 # make directory on different MDTs
6814 local stripe_count=2
6824 *) error "Only creating single directory is supported";;
6827 child=$(basename $path)
6828 parent=$(dirname $path)
6830 if [ "$option" == "-p" -o "$option2" == "-p" ]; then
6831 if [ -d $parent/$child ]; then
6837 if [ "${option:0:2}" == "-c" ]; then
6838 stripe_count=$(echo $option | sed 's/^-c//')
6841 if [ "${option2:0:2}" == "-c" ]; then
6842 stripe_count=$(echo $option2 | sed 's/^-c//')
6845 if [ ! -d ${parent} ]; then
6846 if [ "$p_option" == "-p" ]; then
6853 if [ $MDSCOUNT -le 1 ]; then
6854 mkdir $p_option $parent/$child || rc=$?
6856 local mdt_idx=$($LFS getstripe -M $parent)
6857 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6859 mdt_idx=$((test_num % MDSCOUNT))
6860 echo "striped dir -i$mdt_idx -c$stripe_count $path"
6861 $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
6866 # find the smallest and not in use file descriptor
6869 local max_fd=$(ulimit -n)
6871 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6874 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
6878 check_mount_and_prep()
6880 is_mounted $MOUNT || setupall
6882 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
6883 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
6886 # calcule how many ost-objects to be created.
6887 precreated_ost_obj_count()
6891 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
6892 local ost_name="OST$(printf '%04x' $ost_idx)"
6893 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
6894 local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6895 osp.$proc_path.prealloc_last_id)
6896 local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6897 osp.$proc_path.prealloc_next_id)
6899 echo $((last_id - next_id + 1))
6902 check_file_in_pool()
6907 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
6910 for t in $tlist ; do
6911 [ "$i" -eq "$t" ] && continue 2
6914 echo "pool list: $tlist"
6915 echo "striping: $res"
6916 error_noexit "$file not allocated in $pool"
6923 echo "Creating new pool"
6926 create_pool $FSNAME.$pool ||
6927 { error_noexit "No pool created, result code $?"; return 1; }
6928 [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
6929 { error_noexit "$pool not in lfs pool_list"; return 2; }
6932 pool_add_targets() {
6933 echo "Adding targets to pool"
6939 local list=$(seq $first $step $last)
6941 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
6942 do_facet mgs $LCTL pool_add \
6943 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
6944 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
6945 | sort -u | tr '\n' ' ' " "$t" || {
6946 error_noexit "Add to pool failed"
6949 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
6950 local addcount=$(((last - first) / step + 1))
6951 [ $lfscount -eq $addcount ] || {
6952 error_noexit "lfs pool_list bad ost count" \
6953 "$lfscount != $addcount"
6961 echo "Setting pool on directory $tdir"
6963 $SETSTRIPE -c 2 -p $pool $tdir && return 0
6965 error_noexit "Cannot set pool $pool to $tdir"
6972 echo "Checking pool on directory $tdir"
6974 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
6975 [ "$res" = "$pool" ] && return 0
6977 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
6981 pool_dir_rel_path() {
6982 echo "Testing relative path works well"
6987 mkdir -p $root/$tdir/$tdir
6989 pool_set_dir $pool $tdir || return 1
6990 pool_set_dir $pool ./$tdir || return 2
6991 pool_set_dir $pool ../$tdir || return 3
6992 pool_set_dir $pool ../$tdir/$tdir || return 4
6993 rm -rf $tdir; cd - > /dev/null
6996 pool_alloc_files() {
6997 echo "Checking files allocation from directory pool"
7004 for i in $(seq -w 1 $count)
7006 local file=$tdir/file-$i
7008 check_file_in_pool $file $pool "$tlist" || \
7009 failed=$((failed + 1))
7011 [ "$failed" = 0 ] && return 0
7013 error_noexit "$failed files not allocated in $pool"
7017 pool_create_files() {
7018 echo "Creating files in pool"
7026 for i in $(seq -w 1 $count)
7028 local file=$tdir/spoo-$i
7029 $SETSTRIPE -p $pool $file
7030 check_file_in_pool $file $pool "$tlist" || \
7031 failed=$((failed + 1))
7033 [ "$failed" = 0 ] && return 0
7035 error_noexit "$failed files not allocated in $pool"
7040 echo "Checking 'lfs df' output"
7043 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7045 local res=$($LFS df --pool $FSNAME.$pool |
7047 grep "$FSNAME-OST" |
7049 [ "$res" = "$t" ] && return 0
7051 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7055 pool_file_rel_path() {
7056 echo "Creating files in a pool with relative pathname"
7061 { error_noexit "unable to create $tdir"; return 1 ; }
7062 local file="/..$tdir/$tfile-1"
7063 $SETSTRIPE -p $pool $file ||
7064 { error_noexit "unable to create $file" ; return 2 ; }
7067 $SETSTRIPE -p $pool $tfile-2 || {
7068 error_noexit "unable to create $tfile-2 in $tdir"
7073 pool_remove_first_target() {
7074 echo "Removing first target from a pool"
7077 local pname="lov.$FSNAME-*.pools.$pool"
7078 local t=$($LCTL get_param -n $pname | head -1)
7079 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7080 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7081 error_noexit "$t not removed from $FSNAME.$pool"
7086 pool_remove_all_targets() {
7087 echo "Removing all targets from pool"
7090 local pname="lov.$FSNAME-*.pools.$pool"
7091 for t in $($LCTL get_param -n $pname | sort -u)
7093 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7095 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7096 error_noexit "Pool $FSNAME.$pool cannot be drained"
7099 # striping on an empty/nonexistant pool should fall back
7100 # to "pool of everything"
7102 error_noexit "failed to use fallback striping for empty pool"
7105 # setstripe on an empty pool should fail
7106 $SETSTRIPE -p $pool $file 2>/dev/null && {
7107 error_noexit "expected failure when creating file" \
7115 echo "Destroying pool"
7119 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7122 # striping on an empty/nonexistant pool should fall back
7123 # to "pool of everything"
7125 error_noexit "failed to use fallback striping for missing pool"
7128 # setstripe on an empty pool should fail
7129 $SETSTRIPE -p $pool $file 2>/dev/null && {
7130 error_noexit "expected failure when creating file" \
7135 # get param should return err once pool is gone
7136 if wait_update $HOSTNAME "lctl get_param -n \
7137 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7139 remove_pool_from_list $FSNAME.$pool
7142 error_noexit "Pool $FSNAME.$pool is not destroyed"