3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
13 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
19 # specify environment variable containing batch job name for server statistics
20 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
22 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
23 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
24 export LOAD_LLOOP=${LOAD_LLOOP:-false}
26 #export PDSH="pdsh -S -Rssh -w"
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 }' | sed 's/test_//g')
94 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
95 total=$(grep duration $log | awk '{ print $2}')
96 if [ "${!O}" = "done" ]; then
100 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
101 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
104 printf "$form" $status "$O" "${total}" "E=$skipped"
105 printf "$form" "-" "-" "-" "S=$(echo $slow)"
108 for O in $DEFAULT_SUITES; do
109 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
110 if [ "${!O}" = "no" ]; then
111 printf "$form" "Skipped" "$O" ""
115 # print the detailed tests durations if DDETAILS=true
122 export LUSTRE=$(absolute_path $LUSTRE)
123 export TESTSUITE=$(basename $0 .sh)
124 export TEST_FAILED=false
125 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
126 export RPC_MODE=${RPC_MODE:-false}
128 export MKE2FS=$MKE2FS
129 if [ -z "$MKE2FS" ]; then
130 if which mkfs.ldiskfs >/dev/null 2>&1; then
131 export MKE2FS=mkfs.ldiskfs
137 export DEBUGFS=$DEBUGFS
138 if [ -z "$DEBUGFS" ]; then
139 if which debugfs.ldiskfs >/dev/null 2>&1; then
140 export DEBUGFS=debugfs.ldiskfs
142 export DEBUGFS=debugfs
146 export TUNE2FS=$TUNE2FS
147 if [ -z "$TUNE2FS" ]; then
148 if which tunefs.ldiskfs >/dev/null 2>&1; then
149 export TUNE2FS=tunefs.ldiskfs
151 export TUNE2FS=tune2fs
155 export E2LABEL=$E2LABEL
156 if [ -z "$E2LABEL" ]; then
157 if which label.ldiskfs >/dev/null 2>&1; then
158 export E2LABEL=label.ldiskfs
160 export E2LABEL=e2label
164 export DUMPE2FS=$DUMPE2FS
165 if [ -z "$DUMPE2FS" ]; then
166 if which dumpfs.ldiskfs >/dev/null 2>&1; then
167 export DUMPE2FS=dumpfs.ldiskfs
169 export DUMPE2FS=dumpe2fs
173 export E2FSCK=$E2FSCK
174 if [ -z "$E2FSCK" ]; then
175 if which fsck.ldiskfs >/dev/null 2>&1; then
176 export E2FSCK=fsck.ldiskfs
182 export RESIZE2FS=$RESIZE2FS
183 if [ -z "$RESIZE2FS" ]; then
184 if which resizefs.ldiskfs >/dev/null 2>&1; then
185 export RESIZE2FS=resizefs.ldiskfs
187 export RESIZE2FS=resize2fs
191 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
192 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
193 export FSCK_MAX_ERR=4 # File system errors left uncorrected
195 export ZFS=${ZFS:-zfs}
196 export ZPOOL=${ZPOOL:-zpool}
197 export ZDB=${ZDB:-zdb}
198 export PARTPROBE=${PARTPROBE:-partprobe}
200 #[ -d /r ] && export ROOT=${ROOT:-/r}
201 export TMP=${TMP:-$ROOT/tmp}
202 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
203 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
204 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
206 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
207 if ! echo $PATH | grep -q $LUSTRE/utils; then
208 export PATH=$LUSTRE/utils:$PATH
210 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
211 export PATH=$LUSTRE/utils/gss:$PATH
213 if ! echo $PATH | grep -q $LUSTRE/tests; then
214 export PATH=$LUSTRE/tests:$PATH
216 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
217 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
219 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
220 [ ! -f "$LST" ] && export LST=$(which lst)
221 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
222 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
223 # Ubuntu, at least, has a truncate command in /usr/bin
224 # so fully path our truncate command.
225 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
226 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
227 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
228 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
229 export PATH=$LUSTRE/tests/racer:$PATH:
231 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
232 export PATH=$LUSTRE/tests/mpi:$PATH
234 export RSYNC_RSH=${RSYNC_RSH:-rsh}
236 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
237 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
238 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
239 [ ! -f "$LFS" ] && export LFS=$(which lfs)
240 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
241 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
243 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
244 if [ ! -f "$L_GETIDENTITY" ]; then
245 if `which l_getidentity > /dev/null 2>&1`; then
246 export L_GETIDENTITY=$(which l_getidentity)
248 export L_GETIDENTITY=NONE
251 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
252 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
253 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
254 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
255 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
256 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
257 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
258 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
259 [ ! -f "$LUSTRE_RMMOD" ] &&
260 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
261 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
262 [ ! -f "$LFS_MIGRATE" ] &&
263 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
264 export NAME=${NAME:-local}
265 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
266 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
267 export LGSSD=$(which lgssd)
268 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
269 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
270 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
272 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
275 if [ "$ACCEPTOR_PORT" ]; then
276 export PORT_OPT="--port $ACCEPTOR_PORT"
281 echo "Using GSS/krb5 ptlrpc security flavor"
282 which lgss_keyring > /dev/null 2>&1 || \
283 error_exit "built with gss disabled! SEC=$SEC"
294 IDENTITY_UPCALL=false
298 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
300 # Paths on remote nodes, if different
301 export RLUSTRE=${RLUSTRE:-$LUSTRE}
302 export RPWD=${RPWD:-$PWD}
303 export I_MOUNTED=${I_MOUNTED:-"no"}
304 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
305 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
306 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
307 ! -f $LUSTRE/mdt/mdt.ko ]; then
308 export CLIENTMODSONLY=yes
311 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
312 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
316 while getopts "rvwf:" opt $*; do
319 r) REFORMAT=--reformat;;
321 w) WRITECONF=writeconf;;
326 shift $((OPTIND - 1))
329 # print the durations of each test if "true"
330 DDETAILS=${DDETAILS:-false}
331 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
341 ncpts=$(do_facet $facet "lctl get_param -n " \
342 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
344 if [ $ncpts -eq 0 ]; then
352 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
353 eval set -- $(tr "[:punct:]" " " <<< $*)
355 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
358 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
359 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
362 /sbin/lsmod | grep -q "^\<$1\>"
365 # Load a module on the system where this is running.
367 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
369 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
370 # will be used as the arguments. Otherwise arguments will be obtained from
371 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
378 BASE=`basename $module $EXT`
380 module_loaded ${BASE} && return
382 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
384 if [ $# -eq 0 ]; then
385 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
386 # Bash until 4.x, so we resort to eval.
387 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
388 eval set -- \$$optvar
389 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
390 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
392 opt=$(awk -v var="^options $BASE" '$0 ~ var \
393 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
394 set -- $(echo -n $opt)
396 # Ensure we have accept=all for lnet
397 if [ $(basename $module) = lnet ]; then
398 # OK, this is a bit wordy...
399 local arg accept_all_present=false
402 [ "$arg" = accept=all ] && \
403 accept_all_present=true
405 $accept_all_present || set -- "$@" accept=all
411 [ $# -gt 0 ] && echo "${module} options: '$*'"
413 # Note that insmod will ignore anything in modprobe.conf, which is why we're
414 # passing options on the command-line.
415 if [ "$BASE" == "lnet_selftest" ] && \
416 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
417 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
418 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
419 insmod ${LUSTRE}/${module}${EXT} "$@"
421 # must be testing a "make install" or "rpm" installation
422 # note failed to load ptlrpc_gss is considered not fatal
423 if [ "$BASE" == "ptlrpc_gss" ]; then
424 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
431 llite_lloop_enabled() {
432 local n1=$(uname -r | cut -d. -f1)
433 local n2=$(uname -r | cut -d. -f2)
434 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
436 # load the llite_lloop module for < 2.6.32 kernels
437 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
438 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
445 load_modules_local() {
446 if [ -n "$MODPROBE" ]; then
448 echo "Using modprobe to load modules"
452 echo Loading modules from $LUSTRE
456 if [ -f /sys/devices/system/cpu/online ]; then
457 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
458 echo "detected $ncpus online CPUs by sysfs"
460 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
462 if [ $rc -eq 0 ]; then
463 echo "detected $ncpus online CPUs by getconf"
465 echo "Can't detect number of CPUs"
470 # if there is only one CPU core, libcfs can only create one partition
471 # if there is more than 4 CPU cores, libcfs should create multiple CPU
472 # partitions. So we just force libcfs to create 2 partitions for
473 # system with 2 or 4 cores
474 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
475 # force to enable multiple CPU partitions
476 echo "Force libcfs to create 2 CPU partitions"
477 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
479 echo "libcfs will create CPU partition based on online CPUs"
482 load_module ../libcfs/libcfs/libcfs
484 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
485 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
486 load_module ../lnet/lnet/lnet
487 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
488 load_module ../lnet/klnds/$LNETLND
489 load_module obdclass/obdclass
490 load_module ptlrpc/ptlrpc
491 load_module ptlrpc/gss/ptlrpc_gss
499 load_module obdecho/obdecho
500 if ! client_only; then
501 SYMLIST=/proc/kallsyms
502 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
503 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
504 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
505 load_module lfsck/lfsck
506 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
507 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
509 load_module osd-zfs/osd_zfs
511 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
512 grep -q exportfs_decode_fh $SYMLIST ||
513 { modprobe exportfs 2> /dev/null || true; }
514 load_module ../ldiskfs/ldiskfs
515 load_module osd-ldiskfs/osd_ldiskfs
528 load_module llite/lustre
529 llite_lloop_enabled && load_module llite/llite_lloop
530 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
532 rm -f $OGDB/ogdb-$HOSTNAME
533 $LCTL modules > $OGDB/ogdb-$HOSTNAME
535 # 'mount' doesn't look in $PATH, just sbin
536 if [ -f $LUSTRE/utils/mount.lustre ] && \
537 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
538 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
539 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
546 # load modules on remote nodes optionally
547 # lustre-tests have to be installed on these nodes
548 if $LOAD_MODULES_REMOTE; then
549 local list=$(comma_list $(remote_nodes_list))
550 if [ -n "$list" ]; then
551 echo "loading modules on: '$list'"
552 do_rpc_nodes "$list" load_modules_local
558 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
559 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
560 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
561 echo "$LEAK_LUSTRE" 1>&2
562 echo "$LEAK_PORTALS" 1>&2
563 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
564 echo "Memory leaks detected"
565 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
571 wait_exit_ST client # bug 12845
573 $LUSTRE_RMMOD ldiskfs || return 2
575 if $LOAD_MODULES_REMOTE; then
576 local list=$(comma_list $(remote_nodes_list))
577 if [ -n "$list" ]; then
578 echo "unloading modules on: '$list'"
579 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
580 do_rpc_nodes "$list" check_mem_leak
584 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
585 umount /sbin/mount.lustre || true
586 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
587 rm -f /sbin/mount.lustre || true
590 check_mem_leak || return 254
592 echo "modules unloaded."
597 local facet=${1:-$SINGLEMDS}
598 local fstype=$(facet_fstype $facet)
601 ldiskfs) size=50;; # largest seen is 44, leave some headroom
602 zfs) size=400;; # largest seen is 384
608 check_gss_daemon_nodes() {
612 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
613 if [ \\\"\\\$num\\\" -ne 1 ]; then
614 echo \\\$num instance of $dname;
619 check_gss_daemon_facet() {
623 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
624 if [ $num -ne 1 ]; then
625 echo "$num instance of $dname on $facet"
634 echo Stopping $@ on $list
635 do_nodes $list "killall -2 $@ 2>/dev/null || true"
638 # start gss daemons on all nodes, or
639 # "daemon" on "list" if set
640 start_gss_daemons() {
644 if [ "$list" ] && [ "$daemon" ] ; then
645 echo "Starting gss daemon on nodes: $list"
646 do_nodes $list "$daemon" || return 8
650 local list=$(comma_list $(mdts_nodes))
652 echo "Starting gss daemon on mds: $list"
653 do_nodes $list "$LSVCGSSD -v" || return 1
655 do_nodes $list "$LGSSD -v" || return 2
658 list=$(comma_list $(osts_nodes))
659 echo "Starting gss daemon on ost: $list"
660 do_nodes $list "$LSVCGSSD -v" || return 3
661 # starting on clients
663 local clients=${CLIENTS:-`hostname`}
665 echo "Starting $LGSSD on clients $clients "
666 do_nodes $clients "$LGSSD -v" || return 4
669 # wait daemons entering "stable" status
673 # check daemons are running
675 list=$(comma_list $(mdts_nodes) $(osts_nodes))
676 check_gss_daemon_nodes $list lsvcgssd || return 5
678 list=$(comma_list $(mdts_nodes))
679 check_gss_daemon_nodes $list lgssd || return 6
682 check_gss_daemon_nodes $clients lgssd || return 7
687 local list=$(comma_list $(mdts_nodes))
689 send_sigint $list lsvcgssd lgssd
691 list=$(comma_list $(osts_nodes))
692 send_sigint $list lsvcgssd
694 list=${CLIENTS:-`hostname`}
695 send_sigint $list lgssd
700 if ! module_loaded ptlrpc_gss; then
701 load_module ptlrpc/gss/ptlrpc_gss
702 module_loaded ptlrpc_gss ||
703 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
705 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
707 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
708 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
716 # maybe cleanup credential cache?
722 local var=${facet}_svc
730 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
731 tr '[:lower:]' '[:upper:]'
737 if [ $facet == mgs ]; then
741 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
749 if [ -n "${!var}" ]; then
754 var=$(facet_type $facet)FSTYPE
755 if [ -n "${!var}" ]; then
760 if [ -n "$FSTYPE" ]; then
765 if [[ $facet == mgs ]] && combined_mgs_mds; then
777 local facets=$(get_facets)
780 for facet in ${facets//,/ }; do
781 if [ $node == $(facet_host $facet) ] ||
782 [ $node == "$(facet_failover_host $facet)" ]; then
783 fstype=$(facet_fstype $facet)
784 if [[ $fstypes != *$fstype* ]]; then
785 fstypes+="${fstypes:+,}$fstype"
796 local fstype=$(facet_fstype $facet)
800 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
802 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
803 ${dev} 2>/dev/null");;
805 error "unknown fstype!";;
813 local device=$(mdsdevname $num)
814 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
820 local device=$(ostdevname $num)
821 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
826 # Get the device of a facet.
833 mgs) device=$(mgsdevname) ;;
834 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
835 ost*) device=$(ostdevname $(facet_number $facet)) ;;
836 fs2mds) device=$(mdsdevname 1_2) ;;
837 fs2ost) device=$(ostdevname 1_2) ;;
838 fs3ost) device=$(ostdevname 2_2) ;;
846 # Get the virtual device of a facet.
853 mgs) device=$(mgsvdevname) ;;
854 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
855 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
856 fs2mds) device=$(mdsvdevname 1_2) ;;
857 fs2ost) device=$(ostvdevname 1_2) ;;
858 fs3ost) device=$(ostvdevname 2_2) ;;
866 # Re-read the partition table on failover partner host.
867 # After a ZFS storage pool is created on a shared device, the partition table
868 # on the device may change. However, the operating system on the failover
869 # host may not notice the change automatically. Without the up-to-date partition
870 # block devices, 'zpool import ..' cannot find the labels, whose positions are
871 # relative to partition rather than disk beginnings.
873 # This function performs partprobe on the failover host to make it re-read the
876 refresh_partition_table() {
881 host=$(facet_passive_host $facet)
882 if [[ -n "$host" ]]; then
883 do_node $host "$PARTPROBE $device"
888 # Get ZFS storage pool name.
895 device=$(facet_device $facet)
896 # poolname is string before "/"
897 poolname="${device%%/*}"
903 # Export ZFS storage pool.
904 # Before exporting the pool, all datasets within the pool should be unmounted.
912 poolname=$(zpool_name $facet)
914 if [[ -n "$poolname" ]]; then
915 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
916 grep -q ^$poolname/ /proc/mounts ||
917 $ZPOOL export $opts $poolname"
922 # Import ZFS storage pool.
923 # Force importing, even if the pool appears to be potentially active.
928 local opts=${@:-"-o cachefile=none"}
931 poolname=$(zpool_name $facet)
933 if [[ -n "$poolname" ]]; then
934 opts+=" -d $(dirname $(facet_vdevice $facet))"
935 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
936 $ZPOOL import -f $opts $poolname"
941 # Set the "cachefile=none" property on ZFS storage pool so that the pool
942 # is not automatically imported on system startup.
944 # In a failover environment, this will provide resource level fencing which
945 # will ensure that the same ZFS storage pool will not be imported concurrently
946 # on different nodes.
948 disable_zpool_cache() {
952 poolname=$(zpool_name $facet)
954 if [[ -n "$poolname" ]]; then
955 do_facet $facet "$ZPOOL set cachefile=none $poolname"
960 # This and set_osd_param() shall be used to access OSD parameters
961 # once existed under "obdfilter":
966 # writethrough_cache_enable
970 local device=${2:-$FSNAME-OST*}
973 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
974 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
979 local device=${2:-$FSNAME-OST*}
983 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
984 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
988 local dz=${1:-$DEBUG_SIZE}
990 if [ -f /sys/devices/system/cpu/possible ]; then
991 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
993 local cpus=$(getconf _NPROCESSORS_CONF)
996 # bug 19944, adjust size to be -gt num_possible_cpus()
997 # promise 2MB for every cpu at least
998 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1001 lctl set_param debug_mb=$dz
1004 set_default_debug () {
1005 local debug=${1:-"$PTLDEBUG"}
1006 local subsys=${2:-"$SUBSYSTEM"}
1007 local debug_size=${3:-$DEBUG_SIZE}
1009 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1010 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1012 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1015 set_default_debug_nodes () {
1018 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1019 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1023 do_rpc_nodes "$nodes" set_default_debug \
1024 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1027 set_default_debug_facet () {
1029 local node=$(facet_active_host $facet)
1030 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1032 set_default_debug_nodes $node
1037 local facets=${1:-$(get_facets)}
1040 for facet in ${facets//,/ }; do
1043 [ $RC -eq 0 ] && continue
1045 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1046 skip "Restart of $facet failed!." && touch $LU482_FAILED
1048 error "Restart of $facet failed!"
1055 # Add argument "arg" (e.g., "loop") to the comma-separated list
1056 # of arguments for option "opt" (e.g., "-o") on command
1057 # line "opts" (e.g., "-o flock").
1063 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1065 if echo "$opts" | grep -q $opt_pattern; then
1066 opts=$(echo "$opts" | sed -e \
1067 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1069 opts+="${opts:+ }$opt $arg"
1077 local dev=$(facet_active $facet)_dev
1078 local opt=${facet}_opt
1079 local mntpt=$(facet_mntpt $facet)
1080 local opts="${!opt} $@"
1082 if [ $(facet_fstype $facet) == ldiskfs ] &&
1083 ! do_facet $facet test -b ${!dev}; then
1084 opts=$(csa_add "$opts" -o loop)
1087 if [[ $(facet_fstype $facet) == zfs ]]; then
1088 # import ZFS storage pool
1089 import_zpool $facet || return ${PIPESTATUS[0]}
1092 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1093 # for testing LU-482 error handling in mount_facets() and test_0a()
1094 if [ -f $TMP/test-lu482-trigger ]; then
1097 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
1101 if [ $RC -ne 0 ]; then
1102 echo "Start of ${!dev} on ${facet} failed ${RC}"
1104 set_default_debug_facet $facet
1106 label=$(devicelabel ${facet} ${!dev})
1107 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1108 eval export ${facet}_svc=${label}
1109 echo Started ${label}
1114 # start facet device options
1120 eval export ${facet}_dev=${device}
1121 eval export ${facet}_opt=\"$@\"
1123 local varname=${facet}failover_dev
1124 if [ -n "${!varname}" ] ; then
1125 eval export ${facet}failover_dev=${!varname}
1127 eval export ${facet}failover_dev=$device
1130 local mntpt=$(facet_mntpt $facet)
1131 do_facet ${facet} mkdir -p $mntpt
1132 eval export ${facet}_MOUNT=$mntpt
1133 mount_facet ${facet}
1142 local HOST=`facet_active_host $facet`
1143 [ -z $HOST ] && echo stop: no host for $facet && return 0
1145 local mntpt=$(facet_mntpt $facet)
1146 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1147 if [ ${running} -ne 0 ]; then
1148 echo "Stopping $mntpt (opts:$@) on $HOST"
1149 do_facet ${facet} umount -d $@ $mntpt
1152 # umount should block, but we should wait for unrelated obd's
1153 # like the MGS or MGC to also stop.
1154 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1156 if [[ $(facet_fstype $facet) == zfs ]]; then
1157 # export ZFS storage pool
1162 # save quota version (both administrative and operational quotas)
1163 # add an additional parameter if mountpoint is ever different from $MOUNT
1165 # XXX This function is kept for interoperability with old server (< 2.3.50),
1166 # it should be removed whenever we drop the interoperability for such
1168 quota_save_version() {
1169 local fsname=${2:-$FSNAME}
1171 local ver=$(tr -c -d "123" <<< $spec)
1172 local type=$(tr -c -d "ug" <<< $spec)
1174 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1176 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1178 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1180 local osts=$(get_facets OST)
1181 for ost in ${osts//,/ }; do
1183 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1187 # client could mount several lustre
1189 # XXX This function is kept for interoperability with old server (< 2.3.50),
1190 # it should be removed whenever we drop the interoperability for such
1193 local fsname=${1:-$FSNAME}
1195 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1197 do_nodes $(comma_list $(osts_nodes)) \
1198 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1202 # XXX This function is kept for interoperability with old server (< 2.3.50),
1203 # it should be removed whenever we drop the interoperability for such
1205 restore_quota_old() {
1206 local mntpt=${1:-$MOUNT}
1207 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1208 if [ ! "$old_QUOTA_TYPE" ] ||
1209 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1212 quota_save_version $old_QUOTA_TYPE
1215 # XXX This function is kept for interoperability with old server (< 2.3.50),
1216 # it should be removed whenever we drop the interoperability for such
1221 # no quota enforcement for now and accounting works out of the box
1224 # We need save the original quota_type params, and restore them after testing
1226 # Suppose that quota type the same on mds and ost
1227 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1228 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1229 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1230 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1231 export old_QUOTA_TYPE=$quota_type
1232 quota_save_version $QUOTA_TYPE
1234 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1235 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1238 local quota_usrs=$QUOTA_USERS
1240 # get_filesystem_size
1241 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1242 local blk_soft=$((disksz + 1024))
1243 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1245 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1246 local i_soft=$Inodes
1247 local i_hard=$((i_soft + i_soft / 20))
1249 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1250 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1253 for usr in $quota_usrs; do
1254 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1256 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1258 eval $cmd || error "$cmd FAILED!"
1260 # display the quota status
1261 echo "Quota settings for $usr : "
1262 $LFS quota -v -u $usr $mntpt || true
1266 # get mdt quota type
1268 local varsvc=${SINGLEMDS}_svc
1269 do_facet $SINGLEMDS $LCTL get_param -n \
1270 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1273 # get ost quota type
1275 # All OSTs should have same quota type
1276 local varsvc=ost1_svc
1277 do_facet ost1 $LCTL get_param -n \
1278 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1281 # restore old quota type settings
1283 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1288 if [ "$old_MDT_QUOTA_TYPE" ]; then
1289 do_facet mgs $LCTL conf_param \
1290 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1292 if [ "$old_OST_QUOTA_TYPE" ]; then
1293 do_facet mgs $LCTL conf_param \
1294 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1298 # Handle the case when there is a space in the lfs df
1299 # "filesystem summary" line the same as when there is no space.
1300 # This will allow fixing the "lfs df" summary line in the future.
1302 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1305 # Get free inodes on the MDT specified by mdt index, free indoes on
1306 # the whole filesystem will be returned when index == -1.
1312 if [ $index -eq -1 ]; then
1315 mdt_uuid=$(mdtuuid_from_index $index)
1318 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1323 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1330 # save old quota type & set new quota type
1331 local mdt_qtype=$(mdt_quota_type)
1332 local ost_qtype=$(ost_quota_type)
1334 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1335 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1337 export old_MDT_QUOTA_TYPE=$mdt_qtype
1338 export old_OST_QUOTA_TYPE=$ost_qtype
1340 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1341 error "set mdt quota type failed"
1342 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1343 error "set ost quota type failed"
1345 local quota_usrs=$QUOTA_USERS
1347 # get_filesystem_size
1348 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1349 local blk_soft=$((disksz + 1024))
1350 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1352 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1353 local i_soft=$inodes
1354 local i_hard=$((i_soft + i_soft / 20))
1356 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1357 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1358 "inode-hardlimit: $i_hard"
1361 for usr in $quota_usrs; do
1362 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1364 cmd="$LFS setquota -$type $usr -b $blk_soft"
1365 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1367 eval $cmd || error "$cmd FAILED!"
1369 # display the quota status
1370 echo "Quota settings for $usr : "
1371 $LFS quota -v -u $usr $mntpt || true
1378 local OPTIONS=${3:-$MOUNTOPT}
1380 local device=$MGSNID:/$FSNAME
1381 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1382 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1386 echo "Starting client: $client: $OPTIONS $device $mnt"
1387 do_node $client mkdir -p $mnt
1388 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1390 set_default_debug_nodes $client
1402 [ "$3" ] && force=-f
1403 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1404 if [ $running -ne 0 ]; then
1405 echo "Stopping client $client $mnt (opts:$force)"
1406 do_node $client lsof -t $mnt || need_kill=no
1407 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1408 pids=$(do_node $client lsof -t $mnt | sort -u);
1409 if [ -n $pids ]; then
1410 do_node $client kill -9 $pids || true
1414 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1415 if [ $busy -ne 0 ] ; then
1416 echo "$mnt is still busy, wait one second" && sleep 1
1417 do_node $client umount $force $mnt
1422 # nodes is comma list
1423 sanity_mount_check_nodes () {
1429 # FIXME: assume that all cluster nodes run the same os
1430 [ "$(uname)" = Linux ] || return 0
1433 for mnt in $mnts ; do
1434 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1435 mpts=\\\$(mount | grep -c $mnt' ');
1436 if [ \\\$running -ne \\\$mpts ]; then
1437 echo \\\$(hostname) env are INSANE!;
1440 [ $? -eq 0 ] || rc=1
1445 sanity_mount_check_servers () {
1446 [ "$CLIENTONLY" ] &&
1447 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1448 echo Checking servers environments
1450 # FIXME: modify get_facets to display all facets wo params
1451 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1455 for facet in ${facets//,/ }; do
1456 node=$(facet_host ${facet})
1457 mntpt=$(facet_mntpt $facet)
1458 sanity_mount_check_nodes $node $mntpt ||
1459 { error "server $node environments are insane!"; return 1; }
1463 sanity_mount_check_clients () {
1464 local clients=${1:-$CLIENTS}
1465 local mntpt=${2:-$MOUNT}
1466 local mntpt2=${3:-$MOUNT2}
1468 [ -z $clients ] && clients=$(hostname)
1469 echo Checking clients $clients environments
1471 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1472 error "clients environments are insane!"
1475 sanity_mount_check () {
1476 sanity_mount_check_servers || return 1
1477 sanity_mount_check_clients || return 2
1480 # mount clients if not mouted
1481 zconf_mount_clients() {
1484 local OPTIONS=${3:-$MOUNTOPT}
1486 local device=$MGSNID:/$FSNAME
1487 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1488 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1492 echo "Starting client $clients: $OPTIONS $device $mnt"
1495 running=\\\$(mount | grep -c $mnt' ');
1497 if [ \\\$running -eq 0 ] ; then
1499 mount -t lustre $OPTIONS $device $mnt;
1502 exit \\\$rc" || return ${PIPESTATUS[0]}
1504 echo "Started clients $clients: "
1505 do_nodes $clients "mount | grep $mnt' '"
1507 set_default_debug_nodes $clients
1512 zconf_umount_clients() {
1517 [ "$3" ] && force=-f
1519 echo "Stopping clients: $clients $mnt (opts:$force)"
1520 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1521 if [ \\\$running -ne 0 ] ; then
1522 echo Stopping client \\\$(hostname) $mnt opts:$force;
1523 lsof $mnt || need_kill=no;
1524 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1525 pids=\\\$(lsof -t $mnt | sort -u);
1526 if [ -n \\\"\\\$pids\\\" ]; then
1530 while umount $force $mnt 2>&1 | grep -q "busy"; do
1531 echo "$mnt is still busy, wait one second" && sleep 1;
1538 echo + $POWER_DOWN $node
1542 shutdown_node_hard () {
1544 local attempts=$SHUTDOWN_ATTEMPTS
1546 for i in $(seq $attempts) ; do
1549 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1550 echo "waiting for $host to fail attempts=$attempts"
1551 [ $i -lt $attempts ] || \
1552 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1558 local mnt=${2:-$MOUNT}
1561 if [ "$FAILURE_MODE" = HARD ]; then
1562 shutdown_node_hard $client
1564 zconf_umount_clients $client $mnt -f
1570 local facets="$(get_facets OST),$(get_facets MDS)"
1573 combined_mgs_mds || facets="$facets,mgs"
1575 for facet in ${facets//,/ }; do
1576 if [ $(facet_active_host $facet) == $host ]; then
1577 affected="$affected $facet"
1581 echo $(comma_list $affected)
1586 local host=${2:-$(facet_host $facet)}
1588 local label=$(convert_facet2label $facet)
1589 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1592 facets_up_on_host () {
1594 local facets=$(facets_on_host $host)
1597 for facet in ${facets//,/ }; do
1598 if $(facet_up $facet $host); then
1599 affected_up="$affected_up $facet"
1603 echo $(comma_list $affected_up)
1609 if [ "$FAILURE_MODE" = HARD ]; then
1610 shutdown_node_hard $(facet_active_host $facet)
1618 echo + $POWER_UP $node
1631 if [ "$FAILURE_MODE" = HARD ]; then
1632 reboot_node $(facet_active_host $facet)
1640 if [ "$FAILURE_MODE" = HARD ]; then
1650 for facet in ${facets//,/ }; do
1651 hosts=$(expand_list $hosts $(facet_host $facet) )
1657 _check_progs_installed () {
1661 for prog in $progs; do
1662 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1663 echo $prog missing on $(hostname)
1670 check_progs_installed () {
1674 do_rpc_nodes "$nodes" _check_progs_installed $@
1677 # recovery-scale functions
1679 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1682 start_client_load() {
1685 local var=$(node_var_name $client)_load
1686 eval export ${var}=$load
1688 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1689 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1690 END_RUN_FILE=$END_RUN_FILE \
1691 LOAD_PID_FILE=$LOAD_PID_FILE \
1692 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1693 TESTNAME=$TESTNAME \
1694 DBENCH_LIB=$DBENCH_LIB \
1695 DBENCH_SRC=$DBENCH_SRC \
1696 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1700 log "Started client load: ${load} on $client"
1702 # get the children process IDs
1703 local pids=$(ps --ppid $ppid -o pid= | xargs)
1704 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1708 start_client_loads () {
1709 local -a clients=(${1//,/ })
1710 local numloads=${#CLIENT_LOADS[@]}
1713 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1714 testnum=$((nodenum % numloads))
1715 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1717 # bug 22169: wait the background threads to start
1721 # only for remote client
1722 check_client_load () {
1724 local var=$(node_var_name $client)_load
1725 local TESTLOAD=run_${!var}.sh
1727 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1729 # bug 18914: try to connect several times not only when
1730 # check ps, but while check_catastrophe also
1733 while [ $RC = 254 -a $tries -gt 0 ]; do
1737 if ! check_catastrophe $client; then
1739 if [ $RC -eq 254 ]; then
1740 # FIXME: not sure how long we shuold sleep here
1744 echo "check catastrophe failed: RC=$RC "
1748 # We can continue try to connect if RC=254
1749 # Just print the warning about this
1750 if [ $RC = 254 ]; then
1751 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1754 # see if the load is still on the client
1757 while [ $RC = 254 -a $tries -gt 0 ]; do
1761 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1766 if [ $RC = 254 ]; then
1767 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1768 # see if we can diagnose a bit why this is
1773 check_client_loads () {
1774 local clients=${1//,/ }
1778 for client in $clients; do
1779 check_client_load $client
1781 if [ "$rc" != 0 ]; then
1782 log "Client load failed on node $client, rc=$rc"
1788 restart_client_loads () {
1789 local clients=${1//,/ }
1790 local expectedfail=${2:-""}
1794 for client in $clients; do
1795 check_client_load $client
1797 if [ "$rc" != 0 -a "$expectedfail" ]; then
1798 local var=$(node_var_name $client)_load
1799 start_client_load $client ${!var}
1800 echo "Restarted client load ${!var}: on $client. Checking ..."
1801 check_client_load $client
1803 if [ "$rc" != 0 ]; then
1804 log "Client load failed to restart on node $client, rc=$rc"
1805 # failure one client load means test fail
1806 # we do not need to check other
1815 # Start vmstat and save its process ID in a file.
1820 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1823 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1824 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1827 # Display the nodes on which client loads failed.
1828 print_end_run_file() {
1832 [ -s $file ] || return 0
1834 echo "Found the END_RUN_FILE file: $file"
1837 # A client load will stop if it finds the END_RUN_FILE file.
1838 # That does not mean the client load actually failed though.
1839 # The first node in END_RUN_FILE is the one we are interested in.
1842 if [ -n "$node" ]; then
1843 local var=$(node_var_name $node)_load
1845 local prefix=$TESTLOG_PREFIX
1846 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1847 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1848 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1850 echo "Client load ${!var} failed on node $node:"
1856 # Stop the process which had its PID saved in a file.
1861 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1863 do_nodes $nodes "test -f $pid_file &&
1864 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1867 # Stop all client loads.
1868 stop_client_loads() {
1869 local nodes=${1:-$CLIENTS}
1872 # stop the client loads
1873 stop_process $nodes $pid_file
1875 # clean up the processes that started them
1876 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1878 # End recovery-scale functions
1880 # verify that lustre actually cleaned up properly
1882 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1883 error "LBUG/LASSERT detected"
1884 BUSY=`dmesg | grep -i destruct || true`
1885 if [ "$BUSY" ]; then
1887 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1891 check_mem_leak || exit 204
1893 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
1894 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1897 if module_loaded lnet || module_loaded libcfs; then
1898 echo "$TESTSUITE: modules still loaded..." 1>&2
1907 if [[ "$1" == "--verbose" ]]; then
1923 RESULT=$(do_node $node "$TEST")
1924 if [[ "$RESULT" == "$FINAL" ]]; then
1925 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1926 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1930 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1931 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1935 [[ $WAIT -ge $MAX ]] && break
1936 [[ $((WAIT % print)) -eq 0 ]] &&
1937 echo "Waiting $((MAX - WAIT)) secs for update"
1938 WAIT=$((WAIT + sleep))
1941 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1945 wait_update_facet() {
1948 wait_update $(facet_active_host $facet) "$@"
1952 do_nodes $(comma_list $(mdts_nodes)) \
1953 "lctl set_param -n osd*.*MDT*.force_sync 1"
1954 do_nodes $(comma_list $(osts_nodes)) \
1955 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
1956 grep -v 'Found no match'
1959 wait_delete_completed_mds() {
1960 local MAX_WAIT=${1:-20}
1962 local stime=`date +%s`
1967 # find MDS with pending deletions
1968 for node in $(mdts_nodes); do
1969 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
1970 2>/dev/null | calc_sum)
1971 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
1974 mds2sync="$mds2sync $node"
1976 if [ "$mds2sync" == "" ]; then
1979 mds2sync=$(comma_list $mds2sync)
1981 # sync MDS transactions
1982 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
1984 # wait till all changes are sent and commmitted by OSTs
1985 # for ldiskfs space is released upon execution, but DMU
1986 # do this upon commit
1989 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1990 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
1992 #echo "$node: $changes changes on all"
1993 if [ "$changes" -eq "0" ]; then
1995 #echo "delete took $((etime - stime)) seconds"
2003 echo "Delete is not completed in $((etime - stime)) seconds"
2004 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
2010 # we can use "for" here because we are waiting the slowest
2011 for host in ${hostlist//,/ }; do
2012 check_network "$host" 900
2014 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2021 for facet in ${facetlist//,/ }; do
2022 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2024 wait_for_host $hostlist
2027 _wait_recovery_complete () {
2030 # Use default policy if $2 is not passed by caller.
2031 local MAX=${2:-$(max_recovery_time)}
2036 while [ $WAIT -lt $MAX ]; do
2037 STATUS=$(lctl get_param -n $param | grep status)
2039 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2042 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2044 echo "$param recovery not done in $MAX sec. $STATUS"
2048 wait_recovery_complete () {
2051 # with an assumption that at_max is the same on all nodes
2052 local MAX=${2:-$(max_recovery_time)}
2055 if [ "$FAILURE_MODE" = HARD ]; then
2056 facets=$(facets_on_host $(facet_active_host $facet))
2058 echo affected facets: $facets
2060 # we can use "for" here because we are waiting the slowest
2061 for facet in ${facets//,/ }; do
2062 local var_svc=${facet}_svc
2063 local param="*.${!var_svc}.recovery_status"
2065 local host=$(facet_active_host $facet)
2066 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2070 wait_mds_ost_sync () {
2071 # just because recovery is done doesn't mean we've finished
2072 # orphan cleanup. Wait for llogs to get synchronized.
2073 echo "Waiting for orphan cleanup..."
2074 # MAX value includes time needed for MDS-OST reconnection
2075 local MAX=$(( TIMEOUT * 2 ))
2076 local WAIT_TIMEOUT=${1:-$MAX}
2079 local list=$(comma_list $(mdts_nodes))
2080 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2081 if ! do_facet $SINGLEMDS \
2082 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2084 # old way, use mds_sync
2086 list=$(comma_list $(osts_nodes))
2087 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2090 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2091 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2092 local -a sync=($(do_nodes $list "$cmd"))
2095 for ((i=0; i<${#sync[@]}; i++)); do
2097 [ ${sync[$i]} -eq 1 ] && continue
2099 [ ${sync[$i]} -eq 0 ] && continue
2101 # there is a not finished MDS-OST synchronization
2105 sleep 2 # increase waiting time and cover statfs cache
2106 [ ${con} -eq 1 ] && return 0
2107 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2111 # show which nodes are not finished.
2112 do_nodes $list "$cmd"
2113 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2117 wait_destroy_complete () {
2118 echo "Waiting for local destroys to complete"
2119 # MAX value shouldn't be big as this mean server responsiveness
2120 # never increase this just to make test pass but investigate
2121 # why it takes so long time
2124 while [ $WAIT -lt $MAX ]; do
2125 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2129 for ((i=0; i<${#RPCs[@]}; i++)); do
2130 [ ${RPCs[$i]} -eq 0 ] && continue
2131 # there are still some destroy RPCs in flight
2136 [ ${con} -eq 1 ] && return 0 # done waiting
2137 echo "Waiting ${WAIT}s for local destroys to complete"
2140 echo "Local destroys weren't done in $MAX sec."
2144 wait_delete_completed() {
2145 wait_delete_completed_mds $1 || return $?
2146 wait_destroy_complete
2155 # conf-sanity 31 takes a long time cleanup
2156 while [ $WAIT -lt 300 ]; do
2157 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2158 [ -z "${running}" ] && return 0
2159 echo "waited $WAIT for${running}"
2160 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2162 WAIT=$((WAIT + INTERVAL))
2164 echo "service didn't stop after $WAIT seconds. Still running:"
2169 wait_remote_prog () {
2175 [ "$PDSH" = "no_dsh" ] && return 0
2177 while [ $WAIT -lt $2 ]; do
2178 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2179 [ -z "${running}" ] && return 0 || true
2180 echo "waited $WAIT for: "
2182 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2184 WAIT=$((WAIT + INTERVAL))
2186 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2187 [ -z "$pids" ] && return 0
2188 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2189 # FIXME: not portable
2190 for pid in $pids; do
2191 cat /proc/${pid}/status || true
2192 cat /proc/${pid}/wchan || true
2194 kill -9 $pid || true
2203 # not every config has many clients
2205 if [ ! -z "$CLIENTS" ]; then
2206 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2208 stat -f $MOUNT > /dev/null
2214 # usually checked on particular client or locally
2216 if [ ! -z "$client" ]; then
2217 $PDSH $client "stat -f $MOUNT" > /dev/null
2219 stat -f $MOUNT > /dev/null
2227 client_reconnect() {
2228 uname -n >> $MOUNT/recon
2229 if [ -z "$CLIENTS" ]; then
2230 df $MOUNT; uname -n >> $MOUNT/recon
2232 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2234 echo Connected clients:
2236 ls -l $MOUNT/recon > /dev/null
2240 affected_facets () {
2243 local host=$(facet_active_host $facet)
2244 local affected=$facet
2246 if [ "$FAILURE_MODE" = HARD ]; then
2247 affected=$(facets_up_on_host $host)
2261 #Because it will only get up facets, we need get affected
2262 #facets before shutdown
2263 #For HARD Failure mode, it needs make sure facets on the same
2264 #HOST will only be shutdown and reboot once
2265 for facet in ${facets//,/ }; do
2266 local affected_facet
2268 #check whether facet has been included in other affected facets
2269 for ((index=0; index<$total; index++)); do
2270 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2273 if [ $skip -eq 0 ]; then
2274 affecteds[$total]=$(affected_facets $facet)
2279 for ((index=0; index<$total; index++)); do
2280 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2281 local host=$(facet_active_host $facet)
2282 echo "Failing ${affecteds[index]} on $host"
2283 shutdown_facet $facet
2286 for ((index=0; index<$total; index++)); do
2287 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2288 echo reboot facets: ${affecteds[index]}
2292 change_active ${affecteds[index]}
2294 wait_for_facet ${affecteds[index]}
2295 # start mgs first if it is affected
2296 if ! combined_mgs_mds &&
2297 list_member ${affecteds[index]} mgs; then
2298 mount_facet mgs || error "Restart of mgs failed"
2300 # FIXME; has to be changed to mount all facets concurrently
2301 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2302 echo mount facets: ${affecteds[index]}
2303 mount_facets ${affecteds[index]}
2313 do_facet $facet "sync; sync; sync"
2316 # make sure there will be no seq change
2317 local clients=${CLIENTS:-$HOSTNAME}
2318 local f=fsa-\\\$\(hostname\)
2319 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2320 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2322 local svc=${facet}_svc
2323 do_facet $facet $LCTL --device ${!svc} notransno
2325 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2326 # in-memory state has to be cleared by either rebooting the host or
2327 # exporting and reimporting the pool.
2329 # Although the uberblocks are not updated when a pool is freezed,
2330 # transactions are still written to the disks. Modified blocks may be
2331 # cached in memory when tests try reading them back. The
2332 # export-and-reimport process also evicts any cached pool data from
2333 # memory to provide the correct "data loss" semantics.
2335 # In the test framework, the exporting and importing operations are
2336 # handled by stop() and mount_facet() separately, which are used
2337 # inside fail() and fail_abort().
2339 do_facet $facet $LCTL --device ${!svc} readonly
2340 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2341 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2344 replay_barrier_nodf() {
2345 local facet=$1 echo running=${running}
2346 do_facet $facet "sync; sync; sync"
2347 local svc=${facet}_svc
2348 echo Replay barrier on ${!svc}
2349 do_facet $facet $LCTL --device ${!svc} notransno
2350 do_facet $facet $LCTL --device ${!svc} readonly
2351 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2352 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2355 replay_barrier_nosync() {
2356 local facet=$1 echo running=${running}
2357 local svc=${facet}_svc
2358 echo Replay barrier on ${!svc}
2359 do_facet $facet $LCTL --device ${!svc} notransno
2360 do_facet $facet $LCTL --device ${!svc} readonly
2361 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2362 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2366 # Get Lustre client uuid for a given Lustre mount point.
2369 local mntpnt=${1:-$MOUNT}
2371 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2372 local uuid=$($LCTL get_param -n llite.$name.uuid)
2377 mds_evict_client() {
2378 local mntpnt=${1:-$MOUNT}
2379 local uuid=$(get_client_uuid $mntpnt)
2381 do_facet $SINGLEMDS \
2382 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2385 ost_evict_client() {
2386 local mntpnt=${1:-$MOUNT}
2387 local uuid=$(get_client_uuid $mntpnt)
2390 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2395 local clients=${CLIENTS:-$HOSTNAME}
2397 facet_failover $* || error "failover: $?"
2398 wait_clients_import_state "$clients" "$facets" FULL
2399 clients_up || error "post-failover df: $?"
2404 facet_failover $facet
2410 change_active $facet
2411 wait_for_facet $facet
2412 mount_facet $facet -o abort_recovery
2413 clients_up || echo "first df failed: $?"
2414 clients_up || error "post-failover df: $?"
2418 echo There is no lmc. This is mountconf, baby.
2422 host_nids_address() {
2426 if [ -n "$kind" ]; then
2427 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2429 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2435 if [ "$1" = "'*'" ]; then echo \'*\'; else
2441 if [ "$1" = "'*'" ]; then echo \'*\'; else
2442 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2444 if [ -z "$ID" ]; then
2445 echo "Could not get a ptl id for $1..."
2454 h2name_or_ip "$1" "tcp"
2459 if [ "$1" = "'*'" ]; then echo \'*\'; else
2460 if type __h2elan >/dev/null 2>&1; then
2463 ID=`echo $1 | sed 's/[^0-9]*//g'`
2471 h2name_or_ip "$1" "o2ib"
2475 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2476 # expressions format. As a bonus we can then just pass in those variables
2477 # to pdsh. What this function does is take a HOSTLIST type string and
2478 # expand it into a space deliminated list for us.
2486 [ -z "$hostlist" ] && return
2488 # Translate the case of [..],..,[..] to [..] .. [..]
2489 list="${hostlist/],/] }"
2491 [[ "$front" == *,* ]] && {
2494 list=${list/${old}/${new}}
2497 for item in $list; do
2498 # Test if we have any []'s at all
2499 if [ "$item" != "${item/\[/}" ]; then {
2500 # Expand the [*] into list
2504 if [ "$name" != "$item" ]; then
2505 group=${item#$name[*}
2508 for range in ${group//,/ }; do
2512 # Number of leading zeros
2515 end=$(echo $end | sed 's/0*//')
2516 [[ -z "$end" ]] && end=0
2517 [[ $padlen2 -gt $padlen ]] && {
2518 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2521 begin=$(echo $begin | sed 's/0*//')
2522 [ -z $begin ] && begin=0
2524 for num in $(seq -f "%0${padlen}g" $begin $end); do
2525 value="${name#*,}${num}${back}"
2526 [ "$value" != "${value/\[/}" ] && {
2527 value=$(hostlist_expand "$value")
2529 myList="$myList $value"
2534 myList="$myList $item"
2537 myList=${myList//,/ }
2538 myList=${myList:1} # Remove first character which is a space
2540 # Filter any duplicates without sorting
2542 myList="${list%% *}"
2544 while [[ "$list" != ${myList##* } ]]; do
2545 list=${list//${list%% *} /}
2546 myList="$myList ${list%% *}"
2548 myList="${myList%* }";
2550 # We can select an object at a offset in the list
2553 for item in $myList; do
2555 [ $cnt -eq $offset ] && {
2559 [ $(get_node_count $myList) -ne 1 ] && myList=""
2568 [ "$facet" == client ] && echo -n $HOSTNAME && return
2569 varname=${facet}_HOST
2570 if [ -z "${!varname}" ]; then
2571 if [ "${facet:0:3}" == "ost" ]; then
2572 eval export ${facet}_HOST=${ost_HOST}
2573 elif [ "${facet:0:3}" == "mdt" -o \
2574 "${facet:0:3}" == "mds" -o \
2575 "${facet:0:3}" == "mgs" ]; then
2576 eval export ${facet}_HOST=${mds_HOST}
2582 facet_failover_host() {
2586 var=${facet}failover_HOST
2587 if [ -n "${!var}" ]; then
2592 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2593 "${facet:0:3}" == "mgs" ]; then
2595 eval export ${facet}failover_host=${mds_HOST}
2600 if [[ $facet == ost* ]]; then
2601 eval export ${facet}failover_host=${ost_HOST}
2609 local activevar=${facet}active
2611 if [ -f $TMP/${facet}active ] ; then
2612 source $TMP/${facet}active
2615 active=${!activevar}
2616 if [ -z "$active" ] ; then
2623 facet_active_host() {
2625 local active=`facet_active $facet`
2626 if [ "$facet" == client ]; then
2629 echo `facet_host $active`
2633 # Get the passive failover partner host of facet.
2634 facet_passive_host() {
2636 [[ $facet = client ]] && return
2638 local host=${facet}_HOST
2639 local failover_host=${facet}failover_HOST
2640 local active_host=$(facet_active_host $facet)
2642 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2644 if [[ $active_host = ${!host} ]]; then
2645 echo -n ${!failover_host}
2655 facetlist=$(exclude_items_from_list $facetlist mgs)
2657 for facet in ${facetlist//,/ }; do
2658 local failover=${facet}failover
2659 local host=`facet_host $failover`
2660 [ -z "$host" ] && return
2662 local curactive=`facet_active $facet`
2663 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2664 eval export ${facet}active=$facet
2666 eval export ${facet}active=$failover
2668 # save the active host for this facet
2669 local activevar=${facet}active
2670 echo "$activevar=${!activevar}" > $TMP/$activevar
2671 [[ $facet = mds1 ]] && combined_mgs_mds && \
2672 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2673 local TO=`facet_active_host $facet`
2674 echo "Failover $facet to $TO"
2680 # do not stripe off hostname if verbose, bug 19215
2681 if [ x$1 = x--verbose ]; then
2689 if [ "$HOST" = "$HOSTNAME" ]; then
2691 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2692 echo "cannot run remote command on $HOST with $myPDSH"
2696 echo "CMD: $HOST $@" >&2
2697 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2700 if [ "$myPDSH" = "rsh" ]; then
2701 # we need this because rsh does not return exit code of an executed command
2702 local command_status="$TMP/cs"
2703 rsh $HOST ":> $command_status"
2704 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2705 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2706 echo command failed >$command_status"
2707 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2712 # print HOSTNAME for myPDSH="no_dsh"
2713 if [[ $myPDSH = no_dsh ]]; then
2714 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2716 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2719 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2721 return ${PIPESTATUS[0]}
2725 do_node --verbose "$@"
2728 single_local_node () {
2729 [ "$1" = "$HOSTNAME" ]
2732 # Outputs environment variable assignments that should be passed to remote nodes
2736 local facets=$(get_facets)
2739 for var in ${!MODOPTS_*}; do
2741 echo -n " ${var}=\"$value\""
2744 for facet in ${facets//,/ }; do
2746 if [ -n "${!var}" ]; then
2747 echo -n " $var=${!var}"
2751 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2752 if [ -n "${!var}" ]; then
2753 echo -n " $var=${!var}"
2757 if [ -n "$FSTYPE" ]; then
2758 echo -n " FSTYPE=$FSTYPE"
2764 # do not stripe off hostname if verbose, bug 19215
2765 if [ x$1 = x--verbose ]; then
2773 if single_local_node $rnodes; then
2775 do_nodev $rnodes "$@"
2777 do_node $rnodes "$@"
2782 # This is part from do_node
2785 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2786 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2788 export FANOUT=$(get_node_count "${rnodes//,/ }")
2790 echo "CMD: $rnodes $@" >&2
2791 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2794 # do not replace anything from pdsh output if -N is used
2795 # -N Disable hostname: prefix on lines of output.
2796 if $verbose || [[ $myPDSH = *-N* ]]; then
2797 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2799 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2801 return ${PIPESTATUS[0]}
2807 local HOST=`facet_active_host $facet`
2808 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2812 # Function: do_facet_random_file $FACET $FILE $SIZE
2813 # Creates FILE with random content on the given FACET of given SIZE
2815 do_facet_random_file() {
2819 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2820 do_facet $facet "$cmd 2>/dev/null"
2823 do_facet_create_file() {
2827 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2828 do_facet $facet "$cmd 2>/dev/null"
2832 do_nodes --verbose "$@"
2838 # make sure its not already running
2840 rm -f $TMP/${facet}active
2841 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2842 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2844 if [[ $(facet_fstype $facet) == zfs ]]; then
2846 # After formatting a ZFS target, "cachefile=none" property will
2847 # be set on the ZFS storage pool so that the pool is not
2848 # automatically imported on system startup. And then the pool
2849 # will be exported so as to leave the importing and exporting
2850 # operations handled by mount_facet() and stop() separately.
2852 refresh_partition_table $facet $(facet_vdevice $facet)
2853 disable_zpool_cache $facet
2862 local fstype=$(facet_fstype ost$num)
2866 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2867 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2869 #dataset name is independent of vdev device names
2870 eval DEVPTR=${FSNAME}-ost${num}/ost${num};;
2872 error "unknown fstype!";;
2882 local fstype=$(facet_fstype ost$num)
2886 # vdevs are not supported by ldiskfs
2889 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2890 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2892 error "unknown fstype!";;
2902 local fstype=$(facet_fstype mds$num)
2906 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2907 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2909 #dataset name is independent of vdev device names
2910 eval DEVPTR=${FSNAME}-mdt${num}/mdt${num};;
2912 error "unknown fstype!";;
2922 local fstype=$(facet_fstype mds$num)
2926 # vdevs are not supported by ldiskfs
2929 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2930 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2932 error "unknown fstype!";;
2940 local fstype=$(facet_fstype mgs)
2944 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2945 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
2946 DEVPTR=$(mdsdevname 1)
2951 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2952 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
2953 DEVPTR=$(mdsdevname 1)
2955 DEVPTR=${FSNAME}-mgs/mgs
2958 error "unknown fstype!";;
2968 local fstype=$(facet_fstype mgs)
2972 # vdevs are not supported by ldiskfs
2975 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2976 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
2977 VDEVPTR=$(mdsvdevname 1)
2982 error "unknown fstype!";;
2990 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2992 local var=${facet}_MOUNT
2993 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3000 local dev=$(facet_device $facet)
3001 local mnt=$(facet_mntpt $facet)
3004 if ! do_facet $facet test -b $dev; then
3007 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3012 local dev=$(facet_device $facet)
3013 local mnt=$(facet_mntpt $facet)
3015 do_facet $facet umount -d $mnt
3019 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3024 local ds=$(facet_device $facet)
3025 local mnt=$(facet_mntpt $facet)
3030 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3031 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3032 do_facet $facet $ZFS set canmount=noauto $ds
3034 # The "legacy" mount method is used here because "zfs unmount $mnt"
3035 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3036 # targets are not available at the time, the stat(2) on $MOUNT will
3039 do_facet $facet $ZFS set mountpoint=legacy $ds
3040 do_facet $facet mount -t zfs $ds $mnt
3041 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3042 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3047 local ds=$(facet_device $facet)
3048 local mnt=$(facet_mntpt $facet)
3049 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3050 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3051 local mntpt=${!var_mntpt}
3052 local canmnt=${!var_canmnt}
3056 do_facet $facet umount $mnt
3057 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3058 do_facet $facet $ZFS set canmount=$canmnt $ds
3064 local fstype=$(facet_fstype $facet)
3066 mount_$fstype $facet
3071 local fstype=$(facet_fstype $facet)
3073 unmount_$fstype $facet
3080 # make sure we are using the primary server, so test-framework will
3081 # be able to clean up properly.
3082 activemds=`facet_active mds1`
3083 if [ $activemds != "mds1" ]; then
3087 local clients=$CLIENTS
3088 [ -z $clients ] && clients=$(hostname)
3090 zconf_umount_clients $clients $MOUNT "$*" || true
3091 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3093 [ "$CLIENTONLY" ] && return
3094 # The add fn does rm ${facet}active file, this would be enough
3095 # if we use do_facet <facet> only after the facet added, but
3096 # currently we use do_facet mds in local.sh
3097 for num in `seq $MDSCOUNT`; do
3099 rm -f ${TMP}/mds${num}active
3101 combined_mgs_mds && rm -f $TMP/mgsactive
3103 for num in `seq $OSTCOUNT`; do
3105 rm -f $TMP/ost${num}active
3108 if ! combined_mgs_mds ; then
3115 cleanup_echo_devs () {
3116 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3118 for dev in $devs; do
3119 $LCTL --device $dev cleanup
3120 $LCTL --device $dev detach
3125 nfs_client_mode && return
3134 combined_mgs_mds () {
3135 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3136 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3140 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3144 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3150 local fsname=${3:-"$FSNAME"}
3151 local type=$(facet_type $facet)
3152 local index=$(($(facet_number $facet) - 1))
3153 local fstype=$(facet_fstype $facet)
3154 local host=$(facet_host $facet)
3159 if [ $type == MGS ] && combined_mgs_mds; then
3163 if [ $type == MGS ] || ( [ $type == MDS ] &&
3164 [ "$dev" == $(mgsdevname) ] &&
3165 [ "$host" == "$(facet_host mgs)" ] ); then
3168 opts="--mgsnode=$MGSNID"
3171 if [ $type != MGS ]; then
3172 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3176 var=${facet}failover_HOST
3177 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3178 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3181 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3182 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3184 if [ $type == MDS ]; then
3185 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3186 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3187 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3188 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3189 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3191 if [ $fstype == ldiskfs ]; then
3192 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3193 if [ ! -z $EJOURNAL ]; then
3194 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3196 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3200 if [ $type == OST ]; then
3201 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3202 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3204 if [ $fstype == ldiskfs ]; then
3205 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3209 opts+=" --backfstype=$fstype"
3212 if [ -n "${!var}" ]; then
3213 opts+=" --device-size=${!var}"
3216 var=$(upper $fstype)_MKFS_OPTS
3217 fs_mkfs_opts+=${!var:+" ${!var}"}
3219 var=${type}_FS_MKFS_OPTS
3220 fs_mkfs_opts+=${!var:+" ${!var}"}
3222 if [ -n "${fs_mkfs_opts## }" ]; then
3223 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3227 opts+=${!var:+" ${!var}"}
3240 # We need ldiskfs here, may as well load them all
3242 [ "$CLIENTONLY" ] && return
3243 echo Formatting mgs, mds, osts
3244 if ! combined_mgs_mds ; then
3245 echo "Format mgs: $(mgsdevname)"
3246 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3247 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3251 for num in $(seq $MDSCOUNT); do
3252 echo "Format mds$num: $(mdsdevname $num)"
3253 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3254 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3255 ${quiet:+>/dev/null} || exit 10
3258 for num in $(seq $OSTCOUNT); do
3259 echo "Format ost$num: $(ostdevname $num)"
3260 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3261 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3262 ${quiet:+>/dev/null} || exit 10
3267 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3271 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3275 # 0: success, the old identity set already.
3276 # 1: success, the old identity does not set.
3281 local j=`expr $num - 1`
3282 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3284 if [ -z "$MDT" ]; then
3288 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3291 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3293 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3296 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3298 if [ $old = "NONE" ]; then
3307 zconf_umount `hostname` $1 || error "umount failed"
3308 zconf_mount `hostname` $1 || error "mount failed"
3316 rm -f $TMP/${facet}active
3317 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3322 local mdt_count=${1:-$MDSCOUNT}
3323 local ost_count=${2:-$OSTCOUNT}
3326 for num in $(seq $mdt_count); do
3327 DEVNAME=$(mdsdevname $num)
3328 writeconf_facet mds$num $DEVNAME || rc=$?
3331 for num in $(seq $ost_count); do
3332 DEVNAME=$(ostdevname $num)
3333 writeconf_facet ost$num $DEVNAME || rc=$?
3339 nfs_client_mode && return
3341 sanity_mount_check ||
3342 error "environments are insane!"
3346 if [ -z "$CLIENTONLY" ]; then
3347 echo Setup mgs, mdt, osts
3348 echo $WRITECONF | grep -q "writeconf" && \
3350 if ! combined_mgs_mds ; then
3351 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3354 for num in `seq $MDSCOUNT`; do
3355 DEVNAME=$(mdsdevname $num)
3356 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3358 # We started mds, now we should set failover variables properly.
3359 # Set mds${num}failover_HOST if it is not set (the default failnode).
3360 local varname=mds${num}failover_HOST
3361 if [ -z "${!varname}" ]; then
3362 eval mds${num}failover_HOST=$(facet_host mds$num)
3365 if [ $IDENTITY_UPCALL != "default" ]; then
3366 switch_identity $num $IDENTITY_UPCALL
3369 for num in `seq $OSTCOUNT`; do
3370 DEVNAME=$(ostdevname $num)
3371 start ost$num $DEVNAME $OST_MOUNT_OPTS
3373 # We started ost$num, now we should set ost${num}failover variable properly.
3374 # Set ost${num}failover_HOST if it is not set (the default failnode).
3375 varname=ost${num}failover_HOST
3376 if [ -z "${!varname}" ]; then
3377 eval ost${num}failover_HOST=$(facet_host ost${num})
3385 # wait a while to allow sptlrpc configuration be propogated to targets,
3386 # only needed when mounting new target devices.
3391 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3393 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3396 if [ "$MOUNT_2" ]; then
3397 mount_client $MOUNT2
3398 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3403 # by remounting mdt before ost, initial connect from mdt to ost might
3404 # timeout because ost is not ready yet. wait some time to its fully
3405 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3406 # by a context negotiation rpc with $TIMEOUT.
3407 # FIXME better by monitoring import status.
3410 sleep $((TIMEOUT + 5))
3416 mounted_lustre_filesystems() {
3417 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3420 init_facet_vars () {
3421 [ "$CLIENTONLY" ] && return 0
3428 eval export ${facet}_dev=${device}
3429 eval export ${facet}_opt=\"$@\"
3431 local dev=${facet}_dev
3433 # We need to loop for the label
3434 # in case its not initialized yet.
3435 for wait_time in {0,1,3,5,10}; do
3437 if [ $wait_time -gt 0 ]; then
3438 echo "${!dev} not yet initialized,"\
3439 "waiting ${wait_time} seconds."
3443 local label=$(devicelabel ${facet} ${!dev})
3445 # Check to make sure the label does
3446 # not include ffff at the end of the label.
3447 # This indicates it has not been initialized yet.
3449 if [[ $label =~ [f|F]{4}$ ]]; then
3450 # label is not initialized, unset the result
3451 # and either try again or fail
3458 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3460 eval export ${facet}_svc=${label}
3462 local varname=${facet}failover_HOST
3463 if [ -z "${!varname}" ]; then
3464 eval export $varname=$(facet_host $facet)
3467 varname=${facet}_HOST
3468 if [ -z "${!varname}" ]; then
3469 eval export $varname=$(facet_host $facet)
3472 # ${facet}failover_dev is set in cfg file
3473 varname=${facet}failover_dev
3474 if [ -n "${!varname}" ] ; then
3475 eval export ${facet}failover_dev=${!varname}
3477 eval export ${facet}failover_dev=$device
3480 # get mount point of already mounted device
3481 # is facet_dev is already mounted then use the real
3482 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3483 # i.e. ${facet}_MOUNT if specified by user or default
3484 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3485 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3486 if [ -z $mntpt ]; then
3487 mntpt=$(facet_mntpt $facet)
3489 eval export ${facet}_MOUNT=$mntpt
3492 init_facets_vars () {
3495 if ! remote_mds_nodsh; then
3496 for num in $(seq $MDSCOUNT); do
3497 DEVNAME=`mdsdevname $num`
3498 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3502 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3504 if ! remote_ost_nodsh; then
3505 for num in $(seq $OSTCOUNT); do
3506 DEVNAME=$(ostdevname $num)
3507 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3512 osc_ensure_active () {
3517 while [ $period -lt $timeout ]; do
3518 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3519 if [ $count -eq 0 ]; then
3523 echo "There are $count OST are inactive, wait $period seconds, and try again"
3525 period=$((period+3))
3528 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3531 set_conf_param_and_check() {
3535 local ORIG=$(do_facet $myfacet "$TEST")
3536 if [ $# -gt 3 ]; then
3542 echo "Setting $PARAM from $ORIG to $FINAL"
3543 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3544 error "conf_param $PARAM failed"
3546 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3547 error "check $PARAM failed!"
3550 init_param_vars () {
3552 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3554 log "Using TIMEOUT=$TIMEOUT"
3556 osc_ensure_active $SINGLEMDS $TIMEOUT
3557 osc_ensure_active client $TIMEOUT
3559 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3560 local current_jobid_var=$($LCTL get_param -n jobid_var)
3562 if [ $JOBID_VAR = "existing" ]; then
3563 echo "keeping jobstats as $current_jobid_var"
3564 elif [ $current_jobid_var != $JOBID_VAR ]; then
3565 echo "seting jobstats to $JOBID_VAR"
3567 set_conf_param_and_check client \
3568 "$LCTL get_param -n jobid_var" \
3569 "$FSNAME.sys.jobid_var" $JOBID_VAR
3572 echo "jobstats not supported by server"
3575 if [ $QUOTA_AUTO -ne 0 ]; then
3576 if [ "$ENABLE_QUOTA" ]; then
3577 echo "enable quota as required"
3578 setup_quota $MOUNT || return 2
3580 echo "disable quota as required"
3581 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3587 nfs_client_mode () {
3588 if [ "$NFSCLIENT" ]; then
3589 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3590 local clients=$CLIENTS
3591 [ -z $clients ] && clients=$(hostname)
3593 # FIXME: remove hostname when 19215 fixed
3594 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3595 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3596 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3597 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3599 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3605 check_config_client () {
3608 local mounted=$(mount | grep " $mntpt ")
3609 if [ "$CLIENTONLY" ]; then
3611 # CLIENTONLY should not depend on *_HOST settings
3612 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3613 # in theory someone could create a new,
3614 # client-only config file that assumed lustre was already
3615 # configured and didn't set the MGSNID. If MGSNID is not set,
3616 # then we should use the mgs nid currently being used
3617 # as the default value. bug 18021
3618 [[ x$MGSNID = x ]] &&
3621 if [[ x$mgc != xMGC$MGSNID ]]; then
3622 if [ "$mgs_HOST" ]; then
3623 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3624 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3625 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3631 local myMGS_host=$mgs_HOST
3632 if [ "$NETTYPE" = "ptl" ]; then
3633 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3636 echo Checking config lustre mounted on $mntpt
3637 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3638 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3640 # if [ "$mgshost" != "$myMGS_host" ]; then
3641 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3642 # Please use correct config or set mds_HOST correctly!"
3647 check_config_clients () {
3648 local clients=${CLIENTS:-$HOSTNAME}
3651 nfs_client_mode && return
3653 do_rpc_nodes "$clients" check_config_client $mntpt
3655 sanity_mount_check || error "environments are insane!"
3659 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3660 local cltimeout=$(lctl get_param -n timeout)
3661 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3662 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3669 [ -z $mntpt ] && return 1
3670 local mounted=$(mounted_lustre_filesystems)
3672 echo $mounted' ' | grep -w -q $mntpt' '
3676 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3680 # empty lustre filesystem may have empty directories lost+found and .lustre
3682 # exclude .lustre & lost+found
3683 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3684 -print | wc -l) = 1 ] || return 1
3685 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3686 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3687 # exclude .lustre/fid (LU-2780)
3688 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3689 -print | wc -l) = 1 ] || return 1
3691 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3696 check_and_setup_lustre() {
3697 nfs_client_mode && return
3699 local MOUNTED=$(mounted_lustre_filesystems)
3703 # both MOUNT and MOUNT2 are not mounted
3704 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3705 [ "$REFORMAT" ] && formatall
3706 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3708 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3709 export I_MOUNTED=yes
3713 elif is_mounted $MOUNT2; then
3715 # MOUNT2 is mounted, while MOUNT_2 is not set
3716 if ! [ "$MOUNT_2" ]; then
3717 cleanup_mount $MOUNT2
3718 export I_UMOUNTED2=yes
3721 # MOUNT2 is mounted, MOUNT_2 is set
3723 # FIXME: what to do if check_config failed?
3725 # 1) remote client has mounted other Lustre fs ?
3726 # 2) it has insane env ?
3727 # let's try umount MOUNT2 on all clients and mount it again:
3728 if ! check_config_clients $MOUNT2; then
3729 cleanup_mount $MOUNT2
3730 restore_mount $MOUNT2
3731 export I_MOUNTED2=yes
3736 # MOUNT is mounted MOUNT2 is not mounted
3737 elif [ "$MOUNT_2" ]; then
3738 restore_mount $MOUNT2
3739 export I_MOUNTED2=yes
3743 # FIXME: what to do if check_config failed?
3745 # 1) remote client has mounted other Lustre fs?
3746 # 2) lustre is mounted on remote_clients atall ?
3747 check_config_clients $MOUNT
3751 set_default_debug_nodes $(comma_list $(nodes_list))
3754 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3756 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3757 facets="$(get_facets OST)"
3758 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3759 facets="$facets,$(get_facets MDS)"
3760 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3761 facets="$facets,mgs"
3762 local nodes="$(facets_hosts ${facets})"
3763 if [ -n "$nodes" ] ; then
3764 do_nodes $nodes "$LCTL set_param \
3765 osd-ldiskfs.track_declares_assert=1 || true"
3774 if [ "$ONLY" == "setup" ]; then
3780 local clients=${CLIENTS:-$HOSTNAME}
3783 zconf_mount_clients $clients $mntpt
3787 local clients=${CLIENTS:-$HOSTNAME}
3790 zconf_umount_clients $clients $mntpt
3793 cleanup_and_setup_lustre() {
3794 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3795 lctl set_param debug=0 || true
3797 if [ "$ONLY" == "cleanup" ]; then
3801 check_and_setup_lustre
3804 # Get all of the server target devices from a given server node and type.
3811 if [ "$type" == ost ]; then
3812 devs=$(get_osd_param $node "" mntdev)
3814 devs=$(do_node $node \
3815 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3817 for dev in $devs; do
3819 *loop*) do_node $node "losetup $dev" | \
3820 sed -e "s/.*(//" -e "s/).*//" ;;
3826 # Get all of the server target devices.
3831 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3835 for node in $(osts_nodes); do
3836 OSTDEVS[i]=$(get_mnt_devs $node ost)
3841 # Run e2fsck on MDT or OST device.
3847 df > /dev/null # update statfs data on disk
3848 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3851 do_node $node $cmd || rc=$?
3852 [ $rc -le $FSCK_MAX_ERR ] || \
3853 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3858 # Run resize2fs on MDT or OST device.
3867 do_facet $facet "$RESIZE2FS $opts $device $size"
3870 # verify a directory is shared among nodes.
3871 check_shared_dir() {
3873 local list=${2:-$(comma_list $(nodes_list))}
3875 [ -z "$dir" ] && return 1
3876 do_rpc_nodes "$list" check_logdir $dir
3877 check_write_access $dir "$list" || return 1
3881 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3887 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3888 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3890 check_shared_dir $SHARED_DIRECTORY ||
3891 error "$SHARED_DIRECTORY isn't a shared directory"
3893 export MDSDB=$SHARED_DIRECTORY/mdsdb
3894 export OSTDB=$SHARED_DIRECTORY/ostdb
3896 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3898 run_e2fsck $(mdts_nodes) $MDTDEV "-n --mdsdb $MDSDB"
3903 for node in $(osts_nodes); do
3904 for dev in ${OSTDEVS[i]}; do
3905 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3906 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3907 ostidx=$((ostidx + 1))
3913 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
3914 run_lfsck_remote() {
3915 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3920 #Check if lustre is already mounted
3921 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
3923 zconf_mount $client $MOUNT ||
3924 error "failed to mount Lustre on $client"
3928 do_node $node $cmd || rc=$?
3929 #Umount if necessary
3931 zconf_umount $client $MOUNT ||
3932 error "failed to unmount Lustre on $client"
3935 [ $rc -le $FSCK_MAX_ERR ] ||
3936 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3937 echo "lfsck finished with rc=$rc"
3943 local facets="client $SINGLEMDS"
3949 for facet in $facets; do
3950 node=$(facet_active_host $facet)
3951 if check_progs_installed $node $LFSCK_BIN; then
3956 ! $found && error "None of \"$facets\" supports lfsck"
3958 run_lfsck_remote $node || rc=$?
3960 rm -rvf $MDSDB* $OSTDB* || true
3964 check_and_cleanup_lustre() {
3965 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
3971 if is_mounted $MOUNT; then
3972 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
3973 error "remove sub-test dirs failed"
3974 [ "$ENABLE_QUOTA" ] && restore_quota || true
3977 if [ "$I_UMOUNTED2" = "yes" ]; then
3978 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
3981 if [ "$I_MOUNTED2" = "yes" ]; then
3982 cleanup_mount $MOUNT2
3985 if [ "$I_MOUNTED" = "yes" ]; then
3986 cleanupall -f || error "cleanup failed"
3994 wait_for_function () {
3997 # suppress fn both stderr and stdout
3998 if [ "$1" = "--quiet" ]; then
4000 quiet=" > /dev/null 2>&1"
4012 eval $fn $quiet && return 0
4014 wait=$((wait + sleep))
4015 [ $wait -lt $max ] || return 1
4016 echo waiting $fn, $((max - wait)) secs left ...
4026 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4027 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4028 echo "Network not available!"
4032 echo `date +"%H:%M:%S (%s)"` network interface is UP
4040 # Convert a space-delimited list to a comma-delimited list. If the input is
4041 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4043 # echo is used to convert newlines to spaces, since it doesn't
4044 # introduce a trailing space as using "tr '\n' ' '" does
4045 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4051 echo $list | grep -qw $item
4054 # list, excluded are the comma separated lists
4055 exclude_items_from_list () {
4061 for item in ${excluded//,/ }; do
4062 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4064 echo $(comma_list $list)
4067 # list, expand are the comma separated lists
4069 local list=${1//,/ }
4070 local expand=${2//,/ }
4073 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4074 echo $(comma_list $expanded)
4077 testslist_filter () {
4078 local script=$LUSTRE/tests/${TESTSUITE}.sh
4080 [ -f $script ] || return 0
4082 local start_at=$START_AT
4083 local stop_at=$STOP_AT
4085 local var=${TESTSUITE//-/_}_START_AT
4086 [ x"${!var}" != x ] && start_at=${!var}
4087 var=${TESTSUITE//-/_}_STOP_AT
4088 [ x"${!var}" != x ] && stop_at=${!var}
4090 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4091 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4092 /^'${start_at}'$/ {flag = 0}
4093 {if (flag == 1) print $0}
4094 /^'${stop_at}'$/ { flag = 1 }'
4098 (cd `dirname $1`; echo $PWD/`basename $1`)
4102 local types=${1:-"OST MDS MGS"}
4106 for entry in $types; do
4107 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4108 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4111 MGS ) list="$list $name";;
4112 MDS|OST|AGT ) local count=${type}COUNT
4113 for ((i=1; i<=${!count}; i++)) do
4114 list="$list ${name}$i"
4116 * ) error "Invalid facet type"
4120 echo $(comma_list $list)
4123 ##################################
4124 # Adaptive Timeouts funcs
4127 # only check mds, we assume at_max is the same on all nodes
4128 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4129 if [ $at_max -eq 0 ]; then
4140 # suppose that all ost-s have the same $at value set
4141 [ $facet != "ost" ] || facet=ost1
4143 do_facet $facet "lctl get_param -n $at"
4161 if [ $facet == "ost" ]; then
4162 facet=$(get_facets OST)
4163 elif [ $facet == "mds" ]; then
4164 facet=$(get_facets MDS)
4166 hosts=$(expand_list $hosts $(facets_hosts $facet))
4169 do_nodes $hosts lctl set_param at_max=$at_max
4172 ##################################
4176 # OBD_FAIL_MDS_ALL_REQUEST_NET
4178 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4179 do_facet client "$1" || RC=$?
4180 do_facet $SINGLEMDS lctl set_param fail_loc=0
4185 # OBD_FAIL_MDS_ALL_REPLY_NET
4187 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4188 do_facet client "$@" || RC=$?
4189 do_facet $SINGLEMDS lctl set_param fail_loc=0
4193 drop_reint_reply() {
4194 # OBD_FAIL_MDS_REINT_NET_REP
4196 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4197 do_facet client "$@" || RC=$?
4198 do_facet $SINGLEMDS lctl set_param fail_loc=0
4202 drop_update_reply() {
4203 # OBD_FAIL_UPDATE_OBJ_NET_REP
4207 do_facet mds${index} lctl set_param fail_loc=0x1701
4208 do_facet client "$@" || RC=$?
4209 do_facet mds${index} lctl set_param fail_loc=0
4214 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4216 do_facet ost1 lctl set_param fail_loc=0x214
4217 do_facet client "$1" || RC=$?
4218 do_facet client "sync"
4219 do_facet ost1 lctl set_param fail_loc=0
4223 drop_ldlm_cancel() {
4224 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4226 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4227 do_nodes $list lctl set_param fail_loc=0x304
4229 do_facet client "$@" || RC=$?
4231 do_nodes $list lctl set_param fail_loc=0
4235 drop_bl_callback() {
4236 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4238 do_facet client lctl set_param fail_loc=0x80000305
4239 do_facet client "$@" || RC=$?
4240 do_facet client lctl set_param fail_loc=0
4245 #define OBD_FAIL_LDLM_REPLY 0x30c
4247 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4248 do_facet client "$@" || RC=$?
4249 do_facet $SINGLEMDS lctl set_param fail_loc=0
4257 echo "clearing fail_loc on $facet"
4258 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4261 set_nodes_failloc () {
4262 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
4265 cancel_lru_locks() {
4266 $LCTL mark "cancel_lru_locks $1 start"
4267 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4268 $LCTL set_param -n $d=clear
4270 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4271 $LCTL mark "cancel_lru_locks $1 stop"
4276 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4277 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4278 echo "$DEFAULT_LRU_SIZE"
4283 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4286 lru_resize_disable()
4288 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4293 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4294 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4295 echo there is still data in page cache $FILE ?
4296 lctl get_param -n $FILE
4304 DEBUGSAVE="$(lctl get_param -n debug)"
4308 [ -n "$DEBUGSAVE" ] && \
4309 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4314 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4317 debug_size_restore() {
4318 [ -n "$DEBUG_SIZE_SAVED" ] && \
4319 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4323 start_full_debug_logging() {
4328 local DEBUG_SIZE=150
4330 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4331 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4334 stop_full_debug_logging() {
4339 # prints bash call stack
4342 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4343 local s=${BASH_SOURCE[$i]}
4344 local l=${BASH_LINENO[$i-1]}
4345 local f=${FUNCNAME[$i]}
4346 echo " = $s:$l:$f()"
4350 ##################################
4352 ##################################
4355 local TYPE=${TYPE:-"FAIL"}
4358 # do not dump logs if $1=false
4359 if [ "x$1" = "xfalse" ]; then
4365 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4369 # We need to dump the logs on all nodes
4371 gather_logs $(comma_list $(nodes_list))
4375 [ "$TESTSUITELOG" ] &&
4376 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4377 if [ -z "$*" ]; then
4378 echo "error() without useful message, please fix" > $LOGDIR/err
4380 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4381 echo "$@" > $LOGDIR/ignore
4383 echo "$@" > $LOGDIR/err
4390 local log=$TESTSUITELOG
4392 [ -f "$log" ] && grep -q FAIL $log && status=1
4405 # use only if we are ignoring failures for this test, bugno required.
4406 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4407 # e.g. error_ignore bz5494 "your message" or
4408 # error_ignore LU-5494 "your message"
4410 local TYPE="IGNORE ($1)"
4415 error_and_remount() {
4417 remount_client $MOUNT
4422 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4427 log " SKIP: $TESTSUITE $TESTNAME $@"
4429 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4430 skip_logged $TESTNAME "$@"
4433 echo "$@" > $LOGDIR/skip
4436 [[ -n "$TESTSUITELOG" ]] &&
4437 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4440 build_test_filter() {
4441 EXCEPT="$EXCEPT $(testslist_filter)"
4443 [ "$ONLY" ] && log "only running test `echo $ONLY`"
4447 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4448 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4449 [ "$EXCEPT_SLOW" ] && \
4450 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4451 for E in $EXCEPT; do
4452 eval EXCEPT_${E}=true
4454 for E in $ALWAYS_EXCEPT; do
4455 eval EXCEPT_ALWAYS_${E}=true
4457 for E in $EXCEPT_SLOW; do
4458 eval EXCEPT_SLOW_${E}=true
4460 for G in $GRANT_CHECK_LIST; do
4461 eval GCHECK_ONLY_${G}=true
4466 if [[ $1 = [a-z]* ]]; then
4473 # print a newline if the last test was skipped
4474 export LAST_SKIPPED=
4475 export ALWAYS_SKIPPED=
4477 # Main entry into test-framework. This is called with the name and
4478 # description of a test. The name is used to find the function to run
4479 # the test using "test_$name".
4481 # This supports a variety of methods of specifying specific test to
4482 # run or not run. These need to be documented...
4487 export base=`basetest $1`
4488 if [ ! -z "$ONLY" ]; then
4490 if [ ${!testname}x != x ]; then
4491 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4492 run_one_logged $1 "$2"
4496 if [ ${!testname}x != x ]; then
4497 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4498 run_one_logged $1 "$2"
4508 if [ ${!testname}x != x ]; then
4509 TESTNAME=test_$1 skip "skipping excluded test $1"
4512 testname=EXCEPT_$base
4513 if [ ${!testname}x != x ]; then
4514 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4517 testname=EXCEPT_ALWAYS_$1
4518 if [ ${!testname}x != x ]; then
4519 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4522 testname=EXCEPT_ALWAYS_$base
4523 if [ ${!testname}x != x ]; then
4524 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4527 testname=EXCEPT_SLOW_$1
4528 if [ ${!testname}x != x ]; then
4529 TESTNAME=test_$1 skip "skipping SLOW test $1"
4532 testname=EXCEPT_SLOW_$base
4533 if [ ${!testname}x != x ]; then
4534 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4540 run_one_logged $1 "$2"
4547 module_loaded lnet || load_modules
4559 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4564 strace -o $TMP/$1.strace -ttt $*
4566 log "FINISHED: $*: rc $RC"
4573 banner test complete, duration $duration sec
4574 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4575 echo duration $duration >>$TESTSUITELOG
4579 # Set TEST_STATUS here. It will be used for logging the result.
4582 if [[ -f $LOGDIR/err ]]; then
4584 elif [[ -f $LOGDIR/skip ]]; then
4587 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4591 local FFREE=$(do_node $SINGLEMDS \
4592 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4593 local FTOTAL=$(do_node $SINGLEMDS \
4594 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4596 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4600 echo -n "Resetting fail_loc on all nodes..."
4601 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4607 # Log a message (on all nodes) padded with "=" before and after.
4608 # Also appends a timestamp and prepends the testsuite name.
4611 EQUALS="===================================================================================================="
4613 msg="== ${TESTSUITE} $*"
4615 [[ $last != "=" && $last != " " ]] && msg="$msg "
4616 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4617 # always include at least == after the message
4618 log "$msg== $(date +"%H:%M:%S (%s)")"
4622 # Run a single test function and cleanup after it.
4624 # This function should be run in a subshell so the test func can
4625 # exit() without stopping the whole script.
4630 tfile=f.${TESTSUITE}.${testnum}
4631 export tdir=d0.${TESTSUITE}/d${base}
4632 export TESTNAME=test_$testnum
4633 local SAVE_UMASK=`umask`
4636 banner "test $testnum: $message"
4637 test_${testnum} || error "test_$testnum failed with $?"
4640 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4641 check_catastrophe || error "LBUG/LASSERT detected"
4642 if [ "$PARALLEL" != "yes" ]; then
4643 ps auxww | grep -v grep | grep -q multiop &&
4644 error "multiop still running"
4653 # Wrapper around run_one to ensure:
4654 # - test runs in subshell
4655 # - output of test is saved to separate log file for error reporting
4656 # - test result is saved to data file
4659 local BEFORE=`date +%s`
4661 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4662 local test_log=$LOGDIR/$name
4664 rm -rf $LOGDIR/ignore
4666 local SAVE_UMASK=`umask`
4670 log_sub_test_begin test_${1}
4671 (run_one $1 "$2") 2>&1 | tee -i $test_log
4672 local RC=${PIPESTATUS[0]}
4674 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4675 echo "test_$1 returned $RC" | tee $LOGDIR/err
4677 duration=$((`date +%s` - $BEFORE))
4678 pass "$1" "(${duration}s)"
4680 if [[ -f $LOGDIR/err ]]; then
4681 TEST_ERROR=$(cat $LOGDIR/err)
4682 elif [[ -f $LOGDIR/ignore ]]; then
4683 TEST_ERROR=$(cat $LOGDIR/ignore)
4684 elif [[ -f $LOGDIR/skip ]]; then
4685 TEST_ERROR=$(cat $LOGDIR/skip)
4687 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4689 if [ -f $LOGDIR/err ]; then
4690 $FAIL_ON_ERROR && exit $RC
4699 # Print information of skipped tests to result.yml
4702 log_sub_test_begin $1
4704 log_sub_test_end "SKIP" "0" "0" "$@"
4708 (cd `dirname $1`; echo $PWD/`basename $1`)
4713 export base=`basetest $1`
4714 [ "$CHECK_GRANT" == "no" ] && return 0
4716 testname=GCHECK_ONLY_${base}
4717 [ ${!testname}x == x ] && return 0
4719 echo -n "checking grant......"
4721 local clients=$CLIENTS
4722 [ -z $clients ] && clients=$(hostname)
4724 # sync all the data and make sure no pending data on server
4725 do_nodes $clients sync
4728 client_grant=`do_nodes $clients \
4729 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4730 awk '{total += $1} END{print total}'`
4733 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4734 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4735 awk '{total += $1} END{print total}'`
4737 # check whether client grant == server grant
4738 if [ $client_grant -ne $server_grant ]; then
4739 echo "failed: client:${client_grant} server: ${server_grant}."
4740 do_nodes $(comma_list $(osts_nodes)) \
4741 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4742 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4745 echo "pass: client:${client_grant} server: ${server_grant}"
4750 ########################
4756 ost=`echo $1 | awk -F_ '{print $3}'`
4757 if [ -z $ost ]; then
4758 ost=`echo $1 | sed 's/-osc.*//'`
4763 ostuuid_from_index()
4765 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4768 ostname_from_index() {
4769 local uuid=$(ostuuid_from_index $1)
4773 index_from_ostuuid()
4775 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4778 mdtuuid_from_index()
4780 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4784 # Return unique identifier for given hostname
4787 echo $host_name | md5sum | cut -d' ' -f1
4791 # Returns list of ip addresses for each interface
4793 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4798 # Cache address list to avoid mutiple execution of local_addr_list
4799 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4801 for i in $LOCAL_ADDR_LIST ; do
4802 [[ "$i" == "$addr" ]] && return 0
4809 local is_local="IS_LOCAL_$(host_id $host_name)"
4810 if [ -z "${!is_local-}" ] ; then
4812 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4813 is_local_addr "$host_ip" && eval $is_local=1
4815 [[ "${!is_local}" == "1" ]]
4820 local_node $node && return 1
4827 for node in $(mdts_nodes); do
4828 remote_node $node && return 0
4835 [ "$CLIENTONLY" ] && return 0 || true
4836 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4841 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4842 MSKIPPED=1 && return 1
4849 for node in $(osts_nodes) ; do
4850 remote_node $node && return 0
4857 [ "$CLIENTONLY" ] && return 0 || true
4858 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4863 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4864 OSKIPPED=1 && return 1
4871 MGS=$(facet_host mgs)
4872 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4877 remote_mds_nodsh || remote_ost_nodsh || \
4878 $(single_local_node $(comma_list $(nodes_list)))
4882 remote_ost && remote_mds
4885 # Get the active nodes for facets.
4893 for facet in ${facets//,/ }; do
4894 nodes="$nodes $(facet_active_host $facet)"
4897 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4901 # Get all of the active MDS nodes.
4903 echo -n $(facets_nodes $(get_facets MDS))
4906 # Get all of the active OSS nodes.
4908 echo -n $(facets_nodes $(get_facets OST))
4911 # Get all of the active AGT (HSM agent) nodes.
4913 echo -n $(facets_nodes $(get_facets AGT))
4916 # Get all of the client nodes and active server nodes.
4918 local nodes=$HOSTNAME
4922 # CLIENTS (if specified) contains the local client
4923 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4925 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4926 nodes="$nodes $(facets_nodes $(get_facets))"
4929 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4933 # Get all of the remote client nodes and remote active server nodes.
4934 remote_nodes_list () {
4935 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
4938 # Get all of the MDS nodes, including active and passive nodes.
4946 for i in $(seq $MDSCOUNT); do
4948 failover_host=mds${i}failover_HOST
4949 nodes="$nodes ${!host} ${!failover_host}"
4952 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4956 # Get all of the OSS nodes, including active and passive nodes.
4964 for i in $(seq $OSTCOUNT); do
4966 failover_host=ost${i}failover_HOST
4967 nodes="$nodes ${!host} ${!failover_host}"
4970 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4974 # Get all of the server nodes, including active and passive nodes.
4975 all_server_nodes () {
4980 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
4982 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4986 # Get all of the client and server nodes, including active and passive nodes.
4988 local nodes=$HOSTNAME
4992 # CLIENTS (if specified) contains the local client
4993 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4995 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4996 nodes="$nodes $(all_server_nodes)"
4999 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5003 init_clients_lists () {
5004 # Sanity check: exclude the local client from RCLIENTS
5005 local clients=$(hostlist_expand "$RCLIENTS")
5006 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5008 # Sanity check: exclude the dup entries
5009 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5011 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5013 # Sanity check: exclude the dup entries from CLIENTS
5014 # for those configs which has SINGLCLIENT set to local client
5015 clients=$(for i in $clients; do echo $i; done | sort -u)
5017 CLIENTS=$(comma_list $clients)
5018 local -a remoteclients=($RCLIENTS)
5019 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5020 varname=CLIENT$((i + 2))
5021 eval $varname=${remoteclients[i]}
5024 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5027 get_random_entry () {
5030 rnodes=${rnodes//,/ }
5032 local -a nodes=($rnodes)
5033 local num=${#nodes[@]}
5034 local i=$((RANDOM * num * 2 / 65536))
5040 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5045 lctl get_param version | grep -q patchless
5049 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5050 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5055 echo $nodes | wc -w || true
5059 local nodes=$(osts_nodes)
5060 local osscount=$(get_node_count "$nodes")
5061 [ ! "$OSTCOUNT" = "$osscount" ]
5065 local nodes=$(mdts_nodes)
5066 local mdtcount=$(get_node_count "$nodes")
5067 [ ! "$MDSCOUNT" = "$mdtcount" ]
5070 generate_machine_file() {
5071 local nodes=${1//,/ }
5072 local machinefile=$2
5074 for node in $nodes; do
5075 echo $node >>$machinefile || \
5076 { echo "can not generate machinefile $machinefile" && return 1; }
5081 local file=$1/stripe
5084 $LFS getstripe -v $file || error "getstripe $file failed"
5088 setstripe_nfsserver () {
5091 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5092 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
5094 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5096 do_nodev $nfsserver lfs setstripe "$@"
5099 # Check and add a test group.
5105 local gid=$(getent group $group_name | cut -d: -f3)
5106 if [[ -n "$gid" ]]; then
5107 [[ "$gid" -eq "$group_id" ]] || {
5108 error_noexit "inconsistent group ID:" \
5109 "new: $group_id, old: $gid"
5113 groupadd -g $group_id $group_name
5120 # Check and add a test user.
5133 local uid=$(getent passwd $user_name | cut -d: -f3)
5134 if [[ -n "$uid" ]]; then
5135 if [[ "$uid" -eq "$user_id" ]]; then
5136 local dir=$(getent passwd $user_name | cut -d: -f6)
5137 if [[ "$dir" != "$home" ]]; then
5139 usermod -d $home $user_name
5143 error_noexit "inconsistent user ID:" \
5144 "new: $user_id, old: $uid"
5149 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5156 check_runas_id_ret() {
5158 local myRUNAS_UID=$1
5159 local myRUNAS_GID=$2
5162 if [ -z "$myRUNAS" ]; then
5163 error_exit "myRUNAS command must be specified for check_runas_id"
5166 $myRUNAS krb5_login.sh || \
5167 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5169 mkdir $DIR/d0_runas_test
5171 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5172 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5173 rm -rf $DIR/d0_runas_test
5178 local myRUNAS_UID=$1
5179 local myRUNAS_GID=$2
5182 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5183 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5184 Please set RUNAS_ID to some UID which exists on MDS and client or
5185 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5188 # obtain the UID/GID for MPI_USER
5192 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5193 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5195 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5196 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5199 # obtain and cache Kerberos ticket-granting ticket
5200 refresh_krb5_tgt() {
5201 local myRUNAS_UID=$1
5202 local myRUNAS_GID=$2
5205 if [ -z "$myRUNAS" ]; then
5206 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5209 CLIENTS=${CLIENTS:-$HOSTNAME}
5210 do_nodes $CLIENTS "set -x
5211 if ! $myRUNAS krb5_login.sh; then
5212 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5217 # Run multiop in the background, but wait for it to print
5218 # "PAUSING" to its stdout before returning from this function.
5219 multiop_bg_pause() {
5220 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5224 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5227 echo "$MULTIOP_PROG $FILE v$ARGS"
5228 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5230 echo "TMPPIPE=${TMPPIPE}"
5231 read -t 60 multiop_output < $TMPPIPE
5232 if [ $? -ne 0 ]; then
5237 if [ "$multiop_output" != "PAUSING" ]; then
5238 echo "Incorrect multiop output: $multiop_output"
5253 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5259 inodes_available () {
5260 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
5264 mdsrate_inodes_available () {
5265 local min_inodes=$(inodes_available)
5266 echo $((min_inodes * 99 / 100))
5269 # reset llite stat counters
5270 clear_llite_stats(){
5271 lctl set_param -n llite.*.stats 0
5274 # sum llite stat items
5275 calc_llite_stats() {
5276 local res=$(lctl get_param -n llite.*.stats |
5277 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5281 # reset osc stat counters
5283 lctl set_param -n osc.*.osc_stats 0
5286 # sum osc stat items
5288 local res=$(lctl get_param -n osc.*.osc_stats |
5289 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5294 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
5297 calc_osc_kbytes () {
5298 df $MOUNT > /dev/null
5299 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5302 # save_lustre_params(comma separated facet list, parameter_mask)
5303 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5304 save_lustre_params() {
5310 for facet in ${facets//,/ }; do
5311 node=$(facet_active_host $facet)
5312 [[ *\ $node\ * = " $nodes " ]] && continue
5313 nodes="$nodes $node"
5315 do_node $node "$LCTL get_param $2 |
5316 while read s; do echo $facet \\\$s; done"
5320 # restore lustre parameters from input stream, produces by save_lustre_params
5321 restore_lustre_params() {
5326 while IFS=" =" read facet name val; do
5327 do_facet $facet "$LCTL set_param -n $name $val"
5331 check_catastrophe() {
5332 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5333 local C=$CATASTROPHE
5334 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5336 [ -z "$rnodes" ] && return 0
5339 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5340 echo \\\$(< $C) || echo 0);
5341 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5344 if [ -n "$data" ]; then
5351 # CMD: determine mds index where directory inode presents
5354 local file=$dir/f0.get_mds_dir_tmpfile
5359 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5360 local -a oldused=($iused)
5362 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5364 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5365 local -a newused=($iused)
5368 for ((i=0; i<${#newused[@]}; i++)); do
5369 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5375 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5378 mdsrate_cleanup () {
5380 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5381 --nfiles $3 --dir $4 --filefmt $5 $6
5386 delayed_recovery_enabled () {
5387 local var=${SINGLEMDS}_svc
5388 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5391 ########################
5393 convert_facet2label() {
5396 if [ x$facet = xost ]; then
5400 local varsvc=${facet}_svc
5402 if [ -n ${!varsvc} ]; then
5405 error "No lablel for $facet!"
5409 get_clientosc_proc_path() {
5413 get_lustre_version () {
5414 local facet=${1:-"$SINGLEMDS"}
5415 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5418 lustre_version_code() {
5419 local facet=${1:-"$SINGLEMDS"}
5420 version_code $(get_lustre_version $1)
5423 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5424 # used by MDT would not be changed.
5425 # mdt lov: fsname-mdtlov
5426 # mdt osc: fsname-OSTXXXX-osc
5427 mds_on_old_device() {
5428 local mds=${1:-"$SINGLEMDS"}
5430 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5431 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5432 > /dev/null 2>&1" && return 0
5437 get_mdtosc_proc_path() {
5439 local ost_label=${2:-"*OST*"}
5441 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5442 local mdt_label=$(convert_facet2label $mds_facet)
5443 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5445 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5446 mds_on_old_device $mds_facet; then
5447 echo "${ost_label}-osc"
5449 echo "${ost_label}-osc-${mdt_index}"
5453 get_osc_import_name() {
5456 local label=$(convert_facet2label $ost)
5458 if [ "${facet:0:3}" = "mds" ]; then
5459 get_mdtosc_proc_path $facet $label
5463 get_clientosc_proc_path $label
5467 _wait_import_state () {
5470 local maxtime=${3:-$(max_recovery_time)}
5474 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5475 while [ "${CONN_STATE}" != "${expected}" ]; do
5476 if [ "${expected}" == "DISCONN" ]; then
5477 # for disconn we can check after proc entry is removed
5478 [ "x${CONN_STATE}" == "x" ] && return 0
5479 # with AT enabled, we can have connect request timeout near of
5480 # reconnect timeout and test can't see real disconnect
5481 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5483 [ $i -ge $maxtime ] && \
5484 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5487 # Add uniq for multi-mount case
5488 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5492 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5496 wait_import_state() {
5499 local maxtime=${3:-$(max_recovery_time)}
5502 for param in ${params//,/ }; do
5503 _wait_import_state $state $param $maxtime || return
5507 wait_import_state_mount() {
5508 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5512 wait_import_state $*
5515 # One client request could be timed out because server was not ready
5516 # when request was sent by client.
5517 # The request timeout calculation details :
5519 # /* We give the server rq_timeout secs to process the req, and
5520 # add the network latency for our local timeout. */
5521 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5522 # ptlrpc_at_get_net_latency(request) ;
5524 # ptlrpc_connect_import ()
5525 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5528 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5529 # ptlrpc_at_get_net_latency(request) ->
5530 # at_get (max (iat_net_latency=0, at_min)) = at_min
5533 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5534 # INITIAL_CONNECT_TIMEOUT + at_min
5536 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5537 # because we can not get this value in runtime,
5538 # the value depends on configure options, and it is not stored in /proc.
5540 # #define CONNECTION_SWITCH_MIN 5U
5541 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5543 request_timeout () {
5546 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5547 local init_connect_timeout=$TIMEOUT
5548 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5550 local at_min=$(at_get $facet at_min)
5552 echo $(( init_connect_timeout + at_min ))
5555 _wait_osc_import_state() {
5559 local ost=$(get_osc_import_name $facet $ost_facet)
5561 local param="osc.${ost}.ost_server_uuid"
5564 # 1. wait the deadline of client 1st request (it could be skipped)
5565 # 2. wait the deadline of client 2nd request
5566 local maxtime=$(( 2 * $(request_timeout $facet)))
5568 #During setup time, the osc might not be setup, it need wait
5569 #until list_param can return valid value. And also if there
5570 #are mulitple osc entries we should list all of them before
5572 local params=$($LCTL list_param $param 2>/dev/null || true)
5573 while [ -z "$params" ]; do
5574 if [ $i -ge $maxtime ]; then
5575 echo "can't get $param by list_param in $maxtime secs"
5576 if [[ $facet != client* ]]; then
5577 echo "Go with $param directly"
5586 params=$($LCTL list_param $param 2>/dev/null || true)
5589 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5590 wait_import_state $expected "$params" $maxtime; then
5591 error "import is not in ${expected} state"
5598 wait_osc_import_state() {
5604 if [[ $facet = mds ]]; then
5605 for num in $(seq $MDSCOUNT); do
5606 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5609 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5613 get_clientmdc_proc_path() {
5621 [ -z "$list" ] && return 0
5623 # Add paths to lustre tests for 32 and 64 bit systems.
5624 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5625 local TESTPATH="$RLUSTRE/tests:"
5626 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5627 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5630 wait_clients_import_state () {
5637 if [ "$FAILURE_MODE" = HARD ]; then
5638 facets=$(facets_on_host $(facet_active_host $facet))
5641 for facet in ${facets//,/ }; do
5642 local label=$(convert_facet2label $facet)
5645 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5646 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5647 *) error "unknown facet!" ;;
5649 local params=$(expand_list $params $proc_path)
5652 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5653 error "import is not in ${expected} state"
5663 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5664 $LCTL get_param obdfilter.*.kbytesavail))
5665 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5666 $LCTL get_param -n obdfilter.*.tot_granted))
5667 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5668 $LCTL get_param -n obdfilter.*.kbytestotal))
5669 for ((i=0; i<${#AVAILA[@]}; i++)); do
5670 local -a AVAIL1=(${AVAILA[$i]//=/ })
5671 local -a TOTAL=(${TOTALA[$i]//=/ })
5672 GRANT=$((${GRANTA[$i]}/1024))
5673 # allow 1% of total space in bavail because of delayed
5674 # allocation with ZFS which might release some free space after
5675 # txg commit. For small devices, we set a mininum of 8MB
5676 local LIMIT=$((${TOTAL} / 100 + 8000))
5677 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5678 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5679 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5680 echo " FULL" || echo
5686 do_facet mgs lctl pool_list $1
5690 local fsname=${1%%.*}
5691 local poolname=${1##$fsname.}
5693 do_facet mgs lctl pool_new $1
5695 # get param should return err unless pool is created
5696 [[ $RC -ne 0 ]] && return $RC
5698 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5699 2>/dev/null || echo foo" "" || RC=1
5700 if [[ $RC -eq 0 ]]; then
5703 error "pool_new failed $1"
5708 add_pool_to_list () {
5709 local fsname=${1%%.*}
5710 local poolname=${1##$fsname.}
5712 local listvar=${fsname}_CREATED_POOLS
5713 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5716 remove_pool_from_list () {
5717 local fsname=${1%%.*}
5718 local poolname=${1##$fsname.}
5720 local listvar=${fsname}_CREATED_POOLS
5721 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5724 destroy_pool_int() {
5726 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5727 awk '$1 !~ /^Pool:/ {print $1}')
5728 for ost in $OSTS; do
5729 do_facet mgs lctl pool_remove $1 $ost
5731 do_facet mgs lctl pool_destroy $1
5734 # <fsname>.<poolname> or <poolname>
5736 local fsname=${1%%.*}
5737 local poolname=${1##$fsname.}
5739 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5743 pool_list $fsname.$poolname || return $?
5745 destroy_pool_int $fsname.$poolname
5747 [[ $RC -ne 0 ]] && return $RC
5749 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5750 2>/dev/null || echo foo" "foo" || RC=1
5752 if [[ $RC -eq 0 ]]; then
5753 remove_pool_from_list $fsname.$poolname
5755 error "destroy pool failed $1"
5761 local fsname=${1:-$FSNAME}
5763 local listvar=${fsname}_CREATED_POOLS
5767 [ x${!listvar} = x ] && return 0
5769 echo destroy the created pools: ${!listvar}
5770 for poolname in ${!listvar//,/ }; do
5771 destroy_pool $fsname.$poolname
5776 local fsname=${1:-$FSNAME}
5778 destroy_pools $fsname
5784 local ts=$(date +%s)
5787 if [[ ! -f "$YAML_LOG" ]]; then
5788 # init_logging is not performed before gather_logs,
5789 # so the $LOGDIR needs to be checked here
5790 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5793 [ -f $LOGDIR/shared ] && docp=false
5795 # dump lustre logs, dmesg
5797 prefix="$TESTLOG_PREFIX.$TESTNAME"
5799 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5801 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5802 echo "Dumping logs only on local client."
5803 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5804 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5809 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5810 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5811 if [ ! -f $LOGDIR/shared ]; then
5812 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5825 for i in $(seq 0 $num_mntpts); do
5826 cmd="ls -laf ${mntpt_root}$i/$dir"
5832 for pid in $pids; do
5839 # target_start_and_reset_recovery_timer()
5840 # service_time = at_est2timeout(service_time);
5841 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5842 # INITIAL_CONNECT_TIMEOUT);
5843 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5844 #define CONNECTION_SWITCH_INC 1
5845 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5846 #define CONNECTION_SWITCH_MIN 5U
5848 max_recovery_time () {
5849 local init_connect_timeout=$(( TIMEOUT / 20 ))
5850 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5852 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5857 get_clients_mount_count () {
5858 local clients=${CLIENTS:-`hostname`}
5860 # we need to take into account the clients mounts and
5861 # exclude mds/ost mounts if any;
5862 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5866 PROC_CLI="srpc_info"
5874 if [ $M -lt $N ]; then
5878 while [ $N -lt $M ]; do
5888 calc_connection_cnt() {
5891 # MDT->MDT = 2 * C(M, 2)
5895 comb_m2=$(combination $MDSCOUNT 2)
5897 local num_clients=$(get_clients_mount_count)
5899 local cnt_mdt2mdt=$((comb_m2 * 2))
5900 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
5901 local cnt_cli2ost=$((num_clients * OSTCOUNT))
5902 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
5903 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
5904 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
5905 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
5919 local cmd="$tgt.srpc.flavor"
5921 if [ $net == "any" ]; then
5926 if [ $dir != "any" ]; then
5931 log "Setting sptlrpc rule: $cmd"
5932 do_facet mgs "$LCTL conf_param $cmd"
5941 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
5942 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
5944 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
5946 if [ "x$bulkspec" != "x" ]; then
5947 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
5949 if [ "x$algs" != "x" ]; then
5950 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
5952 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
5953 if [ $bulk == "bulkn" ]; then
5954 bulk_count=`echo "$output" | grep "bulk flavor" \
5955 | grep "null/null" | wc -l`
5956 elif [ $bulk == "bulki" ]; then
5957 bulk_count=`echo "$output" | grep "bulk flavor" \
5958 | grep "/null" | grep -v "null/" | wc -l`
5960 bulk_count=`echo "$output" | grep "bulk flavor" \
5961 | grep -v "/null" | grep -v "null/" | wc -l`
5965 [ $bulk_count -lt $count ] && count=$bulk_count
5976 local clients=${CLIENTS:-`hostname`}
5978 for c in ${clients//,/ }; do
5979 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
5980 tmpcnt=`count_flvr "$output" $flavor`
5981 cnt=$((cnt + tmpcnt))
5991 local clients=${CLIENTS:-`hostname`}
5993 for c in ${clients//,/ }; do
5994 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
5995 tmpcnt=`count_flvr "$output" $flavor`
5996 cnt=$((cnt + tmpcnt))
6006 if [ $MDSCOUNT -le 1 ]; then
6011 for num in `seq $MDSCOUNT`; do
6012 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6013 tmpcnt=`count_flvr "$output" $flavor`
6014 cnt=$((cnt + tmpcnt))
6025 for num in `seq $MDSCOUNT`; do
6026 mdtosc=$(get_mdtosc_proc_path mds$num)
6027 mdtosc=${mdtosc/-MDT*/-MDT\*}
6028 output=$(do_facet mds$num lctl get_param -n \
6029 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6030 tmpcnt=`count_flvr "$output" $flavor`
6031 cnt=$((cnt + tmpcnt))
6040 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6041 count_flvr "$output" $flavor
6046 local dir=$1 # from to
6047 local flavor=$2 # flavor expected
6050 if [ $dir == "cli2mdt" ]; then
6051 res=`flvr_cnt_cli2mdt $flavor`
6052 elif [ $dir == "cli2ost" ]; then
6053 res=`flvr_cnt_cli2ost $flavor`
6054 elif [ $dir == "mdt2mdt" ]; then
6055 res=`flvr_cnt_mdt2mdt $flavor`
6056 elif [ $dir == "mdt2ost" ]; then
6057 res=`flvr_cnt_mdt2ost $flavor`
6058 elif [ $dir == "all2ost" ]; then
6059 res1=`flvr_cnt_mdt2ost $flavor`
6060 res2=`flvr_cnt_cli2ost $flavor`
6061 res=$((res1 + res2))
6062 elif [ $dir == "all2mdt" ]; then
6063 res1=`flvr_cnt_mdt2mdt $flavor`
6064 res2=`flvr_cnt_cli2mdt $flavor`
6065 res=$((res1 + res2))
6066 elif [ $dir == "all2all" ]; then
6067 res1=`flvr_cnt_mdt2ost $flavor`
6068 res2=`flvr_cnt_cli2ost $flavor`
6069 res3=`flvr_cnt_mdt2mdt $flavor`
6070 res4=`flvr_cnt_cli2mdt $flavor`
6071 res=$((res1 + res2 + res3 + res4))
6079 local dir=$1 # from to
6080 local flavor=$2 # flavor expected
6081 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6085 for ((i=0;i<20;i++)); do
6086 echo -n "checking $dir..."
6087 res=$(do_check_flavor $dir $flavor)
6088 echo "found $res/$expect $flavor connections"
6089 [ $res -ge $expect ] && return 0
6093 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6097 restore_to_default_flavor()
6099 local proc="mgs.MGS.live.$FSNAME"
6101 echo "restoring to default flavor..."
6103 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6105 # remove all existing rules if any
6106 if [ $nrule -ne 0 ]; then
6107 echo "$nrule existing rules"
6108 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6109 echo "remove rule: $rule"
6110 spec=`echo $rule | awk -F = '{print $1}'`
6111 do_facet mgs "$LCTL conf_param -d $spec"
6115 # verify no rules left
6116 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6117 [ $nrule -ne 0 ] && error "still $nrule rules left"
6119 # wait for default flavor to be applied
6120 # currently default flavor for all connections are 'null'
6121 wait_flavor all2all null
6122 echo "now at default flavor settings"
6127 local flavor=${1:-null}
6129 echo "setting all flavor to $flavor"
6131 # FIXME need parameter to this fn
6132 # and remove global vars
6133 local cnt_all2all=$(calc_connection_cnt all2all)
6135 local res=$(do_check_flavor all2all $flavor)
6136 if [ $res -eq $cnt_all2all ]; then
6137 echo "already have total $res $flavor connections"
6141 echo "found $res $flavor out of total $cnt_all2all connections"
6142 restore_to_default_flavor
6144 [[ $flavor = null ]] && return 0
6146 set_rule $FSNAME any any $flavor
6147 wait_flavor all2all $flavor
6153 # Checking for shared logdir
6154 if [ ! -d $dir ]; then
6155 # Not found. Create local logdir
6158 touch $dir/check_file.$(hostname -s)
6163 check_write_access() {
6165 local list=${2:-$(comma_list $(nodes_list))}
6169 for node in ${list//,/ }; do
6170 file=$dir/check_file.$(short_nodename $node)
6171 if [[ ! -f "$file" ]]; then
6172 # Logdir not accessible/writable from this node.
6175 rm -f $file || return 1
6181 if [[ -n $YAML_LOG ]]; then
6184 local SAVE_UMASK=`umask`
6187 export YAML_LOG=${LOGDIR}/results.yml
6191 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6192 if check_shared_dir $LOGDIR; then
6193 touch $LOGDIR/shared
6194 echo "Logging to shared log directory: $LOGDIR"
6196 echo "Logging to local directory: $LOGDIR"
6199 yml_nodes_file $LOGDIR >> $YAML_LOG
6200 yml_results_file >> $YAML_LOG
6207 yml_log_test $1 >> $YAML_LOG
6211 yml_log_test_status $@ >> $YAML_LOG
6214 log_sub_test_begin() {
6215 yml_log_sub_test_begin "$@" >> $YAML_LOG
6218 log_sub_test_end() {
6219 yml_log_sub_test_end "$@" >> $YAML_LOG
6225 local llverdev_opts=$2
6226 local devname=$(basename $1)
6227 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6228 # loop devices aren't in /proc/partitions
6229 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6231 size=$(($size / 1024 / 1024)) # Gb
6233 local partial_arg=""
6234 # Run in partial (fast) mode if the size
6235 # of a partition > 1 GB
6236 [ $size -gt 1 ] && partial_arg="-p"
6238 llverdev --force $partial_arg $llverdev_opts $dev
6244 local llverfs_opts=$2
6245 local use_partial_arg=$3
6246 local partial_arg=""
6247 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6249 # Run in partial (fast) mode if the size
6250 # of a partition > 1 GB
6251 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6253 llverfs $partial_arg $llverfs_opts $dir
6256 #Remove objects from OST
6257 remove_ost_objects() {
6263 local mntpt=$(facet_mntpt $facet)
6264 local opts=$OST_MOUNT_OPTS
6268 echo "removing objects from $ostdev on $facet: $objids"
6269 if ! test -b $ostdev; then
6270 opts=$(csa_add "$opts" -o loop)
6272 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6275 for i in $objids; do
6276 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6278 umount -f $mntpt || return $?
6282 #Remove files from MDT
6283 remove_mdt_files() {
6288 local mntpt=$(facet_mntpt $facet)
6289 local opts=$MDS_MOUNT_OPTS
6291 echo "removing files from $mdtdev on $facet: $files"
6292 if [ $(facet_fstype $facet) == ldiskfs ] &&
6293 ! do_facet $facet test -b $mdtdev; then
6294 opts=$(csa_add "$opts" -o loop)
6296 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6300 rm $mntpt/ROOT/$f || { rc=$?; break; }
6302 umount -f $mntpt || return $?
6306 duplicate_mdt_files() {
6311 local mntpt=$(facet_mntpt $facet)
6312 local opts=$MDS_MOUNT_OPTS
6314 echo "duplicating files on $mdtdev on $facet: $files"
6315 mkdir -p $mntpt || return $?
6316 if [ $(facet_fstype $facet) == ldiskfs ] &&
6317 ! do_facet $facet test -b $mdtdev; then
6318 opts=$(csa_add "$opts" -o loop)
6320 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6331 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6332 pushd $mntpt/ROOT > /dev/null || return $?
6335 touch $f.bad || return $?
6336 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6338 [ $rc -eq 0 ] || return $rc
6339 setfattr --restore $tmp || return $?
6345 local devs=${1//,/ }
6348 local rslt=$TMP/sgpdd_survey
6350 # sgpdd-survey cleanups ${rslt}.* files
6352 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6358 # returns the canonical name for an ldiskfs device
6363 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6364 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6365 echo dm-\\\${foo##*:};
6367 echo \\\$(basename \\\$dv);
6371 is_sanity_benchmark() {
6372 local benchmarks="dbench bonnie iozone fsx"
6374 for b in $benchmarks; do
6375 if [ "$b" == "$suite" ]; then
6383 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6387 # Get the block count of the filesystem.
6394 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6395 awk '/^Block count:/ {print $3}')
6399 # Get the block size of the filesystem.
6405 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6406 awk '/^Block size:/ {print $3}')
6410 # Check whether the "large_xattr" feature is enabled or not.
6411 large_xattr_enabled() {
6412 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6414 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6416 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6417 grep -E -q '(ea_inode|large_xattr)'"
6418 return ${PIPESTATUS[0]}
6421 # Get the maximum xattr size supported by the filesystem.
6425 if large_xattr_enabled; then
6426 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6429 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6430 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6432 # maximum xattr size = size of block - size of header -
6433 # size of 1 entry - 4 null bytes
6434 size=$((block_size - 32 - 32 - 4))
6440 # Dump the value of the named xattr from a file.
6445 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6448 # Generate a string with size of $size bytes.
6450 local size=${1:-1024} # in bytes
6452 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6455 reformat_external_journal() {
6458 if [ ! -z ${EJOURNAL} ]; then
6459 local rcmd="do_facet $facet"
6461 echo "reformat external journal on $facet:${EJOURNAL}"
6462 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6466 # MDT file-level backup/restore
6467 mds_backup_restore() {
6470 local devname=$(mdsdevname $(facet_number $facet))
6471 local mntpt=$(facet_mntpt brpt)
6472 local rcmd="do_facet $facet"
6473 local metaea=${TMP}/backup_restore.ea
6474 local metadata=${TMP}/backup_restore.tgz
6475 local opts=${MDS_MOUNT_OPTS}
6476 local svc=${facet}_svc
6478 if ! ${rcmd} test -b ${devname}; then
6479 opts=$(csa_add "$opts" -o loop)
6482 echo "file-level backup/restore on $facet:${devname}"
6484 # step 1: build mount point
6485 ${rcmd} mkdir -p $mntpt
6486 # step 2: cleanup old backup
6487 ${rcmd} rm -f $metaea $metadata
6489 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6490 if [ ! -z $igif ]; then
6491 # step 3.5: rm .lustre
6492 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6494 # step 4: backup metaea
6496 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6498 # step 5: backup metadata
6500 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6502 ${rcmd} umount -d $mntpt || return 4
6503 # step 7: reformat external journal if needed
6504 reformat_external_journal $facet || return 5
6505 # step 8: reformat dev
6506 echo "reformat new device"
6507 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6508 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6509 > /dev/null || exit 6
6511 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6512 # step 10: restore metadata
6514 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6515 # step 11: restore metaea
6517 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6518 # step 12: remove recovery logs
6519 echo "remove recovery logs"
6520 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6521 # step 13: umount dev
6522 ${rcmd} umount -d $mntpt || return 10
6523 # step 14: cleanup tmp backup
6524 ${rcmd} rm -f $metaea $metadata
6525 # step 15: reset device label - it's not virgin on
6526 ${rcmd} e2label $devname ${!svc}
6533 local devname=$(mdsdevname $(facet_number $facet))
6534 local mntpt=$(facet_mntpt brpt)
6535 local rcmd="do_facet $facet"
6536 local opts=${MDS_MOUNT_OPTS}
6538 if ! ${rcmd} test -b ${devname}; then
6539 opts=$(csa_add "$opts" -o loop)
6542 echo "removing OI files on $facet: idx=${idx}"
6544 # step 1: build mount point
6545 ${rcmd} mkdir -p $mntpt
6547 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6548 if [ -z $idx ]; then
6549 # step 3: remove all OI files
6550 ${rcmd} rm -fv $mntpt/oi.16*
6551 elif [ $idx -lt 2 ]; then
6552 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6556 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6557 for ((i=${idx}; i<64; i=$((i * idx)))); do
6558 ${rcmd} rm -fv $mntpt/oi.16.${i}
6562 ${rcmd} umount -d $mntpt || return 2
6563 # OI files will be recreated when mounted as lustre next time.
6566 # generate maloo upload-able log file name
6567 # \param logname specify unique part of file name
6568 generate_logname() {
6569 local logname=${1:-"default_logname"}
6571 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6574 # make directory on different MDTs
6586 *) error "Only creating single directory is supported";;
6589 child=$(basename $path)
6590 parent=$(dirname $path)
6592 if [ "$option" == "-p" -a -d $parent/$child ]; then
6596 if [ ! -d ${parent} ]; then
6597 if [ "$option" == "-p" ]; then
6604 if [ $MDSCOUNT -le 1 ]; then
6605 mkdir $option $parent/$child || rc=$?
6607 local mdt_idx=$($LFS getstripe -M $parent)
6608 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6610 if [ "$mdt_idx" -ne 0 ]; then
6611 mkdir $option $parent/$child || rc=$?
6613 mdt_idx=$((test_num % MDSCOUNT))
6614 echo "mkdir $mdt_idx for $parent/$child"
6615 $LFS setdirstripe -i $mdt_idx $parent/$child || rc=$?
6621 # find the smallest and not in use file descriptor
6624 local max_fd=$(ulimit -n)
6626 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6629 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"