2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'print_summary && touch $TF_FAIL && \
5 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
19 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
20 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
21 export LOAD_LLOOP=${LOAD_LLOOP:-false}
23 #export PDSH="pdsh -S -Rssh -w"
25 # function used by scripts run on remote nodes
26 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
27 . $LUSTRE/tests/functions.sh
28 . $LUSTRE/tests/yaml.sh
30 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
32 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
34 if [ -f "$EXCEPT_LIST_FILE" ]; then
35 echo "Reading test skip list from $EXCEPT_LIST_FILE"
40 # check config files for options in decreasing order of preference
41 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
42 MODPROBECONF=/etc/modprobe.d/lustre.conf
43 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
44 MODPROBECONF=/etc/modprobe.d/Lustre
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
46 MODPROBECONF=/etc/modprobe.conf
50 [[ $DIR/ = $MOUNT/* ]] || \
51 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
52 [[ $DIR1/ = $MOUNT1/* ]] || \
53 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
54 [[ $DIR2/ = $MOUNT2/* ]] || \
55 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
57 [ -n "$failed" ] && exit 99 || true
61 echo "usage: $0 [-r] [-f cfgfile]"
69 [ "$TESTSUITE" == "lfsck" ] && return 0
70 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
72 local form="%-13s %-17s %-9s %s %s\n"
73 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
74 echo "------------------------------------------------------------------------------------"
75 for O in $DEFAULT_SUITES; do
76 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
77 [ "${!O}" = "no" ] && continue || true
78 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
79 local log=${TMP}/${o}.log
80 if is_sanity_benchmark $o; then
81 log=${TMP}/sanity-benchmark.log
86 local status=Unfinished
88 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
89 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
90 total=$(grep duration $log | awk '{ print $2}')
91 if [ "${!O}" = "done" ]; then
95 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
96 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
99 printf "$form" $status "$O" "${total}" "E=$skipped"
100 printf "$form" "-" "-" "-" "S=$(echo $slow)"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 if [ "${!O}" = "no" ]; then
106 printf "$form" "Skipped" "$O" ""
110 # print the detailed tests durations if DDETAILS=true
117 export LUSTRE=`absolute_path $LUSTRE`
118 export TESTSUITE=`basename $0 .sh`
119 export TEST_FAILED=false
120 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
122 export MKE2FS=${MKE2FS:-mke2fs}
123 export DEBUGFS=${DEBUGFS:-debugfs}
124 export TUNE2FS=${TUNE2FS:-tune2fs}
125 export E2LABEL=${E2LABEL:-e2label}
126 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
127 export E2FSCK=${E2FSCK:-e2fsck}
128 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
130 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
131 export FSCK_MAX_ERR=4 # File system errors left uncorrected
133 #[ -d /r ] && export ROOT=${ROOT:-/r}
134 export TMP=${TMP:-$ROOT/tmp}
135 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
136 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
137 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
139 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
140 if ! echo $PATH | grep -q $LUSTRE/utils; then
141 export PATH=$LUSTRE/utils:$PATH
143 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
144 export PATH=$LUSTRE/utils/gss:$PATH
146 if ! echo $PATH | grep -q $LUSTRE/tests; then
147 export PATH=$LUSTRE/tests:$PATH
149 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
150 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
152 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
153 [ ! -f "$LST" ] && export LST=$(which lst)
154 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
155 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
156 # Ubuntu, at least, has a truncate command in /usr/bin
157 # so fully path our truncate command.
158 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
159 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
160 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
161 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
162 export PATH=$LUSTRE/tests/racer:$PATH:
164 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
165 export PATH=$LUSTRE/tests/mpi:$PATH
167 export RSYNC_RSH=${RSYNC_RSH:-rsh}
169 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
170 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
171 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
172 [ ! -f "$LFS" ] && export LFS=$(which lfs)
173 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
174 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
176 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
177 if [ ! -f "$L_GETIDENTITY" ]; then
178 if `which l_getidentity > /dev/null 2>&1`; then
179 export L_GETIDENTITY=$(which l_getidentity)
181 export L_GETIDENTITY=NONE
184 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
185 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
186 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
187 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
188 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
189 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
190 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
191 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
192 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
193 export FSTYPE=${FSTYPE:-"ldiskfs"}
194 export NAME=${NAME:-local}
195 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
196 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
197 export LGSSD=$(which lgssd)
198 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
199 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
200 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
202 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
205 if [ "$ACCEPTOR_PORT" ]; then
206 export PORT_OPT="--port $ACCEPTOR_PORT"
211 echo "Using GSS/krb5 ptlrpc security flavor"
212 which lgss_keyring > /dev/null 2>&1 || \
213 error_exit "built with gss disabled! SEC=$SEC"
224 IDENTITY_UPCALL=false
227 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
229 # Paths on remote nodes, if different
230 export RLUSTRE=${RLUSTRE:-$LUSTRE}
231 export RPWD=${RPWD:-$PWD}
232 export I_MOUNTED=${I_MOUNTED:-"no"}
233 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
234 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
235 ! -f `dirname $0`/../mds/mds.ko ]; then
236 export CLIENTMODSONLY=yes
239 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
243 while getopts "rvwf:" opt $*; do
246 r) REFORMAT=--reformat;;
248 w) WRITECONF=writeconf;;
253 shift $((OPTIND - 1))
256 # print the durations of each test if "true"
257 DDETAILS=${DDETAILS:-false}
258 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
263 echo -n $((($1 << 16) | ($2 << 8) | $3))
266 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
267 export LINUX_VERSION_CODE=$(kernel_version ${LINUX_VERSION//\./ })
270 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
271 *) EXT=".ko"; USE_QUOTA=yes;;
276 /sbin/lsmod | grep -q "^\<$1\>"
279 # Load a module on the system where this is running.
281 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
283 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
284 # will be used as the arguments. Otherwise arguments will be obtained from
285 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
292 BASE=`basename $module $EXT`
294 module_loaded ${BASE} && return
296 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
298 if [ $# -eq 0 ]; then
299 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
300 # Bash until 4.x, so we resort to eval.
301 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
302 eval set -- \$$optvar
303 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
304 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
305 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
306 # Get rid of "options $module"
307 (($# > 0)) && shift 2
309 # Ensure we have accept=all for lnet
310 if [ $(basename $module) = lnet ]; then
311 # OK, this is a bit wordy...
312 local arg accept_all_present=false
314 [ "$arg" = accept=all ] && accept_all_present=true
316 $accept_all_present || set -- "$@" accept=all
321 [ $# -gt 0 ] && echo "${module} options: '$*'"
323 # Note that insmod will ignore anything in modprobe.conf, which is why we're
324 # passing options on the command-line.
325 if [ "$BASE" == "lnet_selftest" ] && \
326 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
327 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
328 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
329 insmod ${LUSTRE}/${module}${EXT} "$@"
331 # must be testing a "make install" or "rpm" installation
332 # note failed to load ptlrpc_gss is considered not fatal
333 if [ "$BASE" == "ptlrpc_gss" ]; then
334 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
341 llite_lloop_enabled() {
342 local n1=$(uname -r | cut -d. -f1)
343 local n2=$(uname -r | cut -d. -f2)
344 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
346 # load the llite_lloop module for < 2.6.32 kernels
347 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
348 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
355 load_modules_local() {
356 if [ -n "$MODPROBE" ]; then
358 echo "Using modprobe to load modules"
362 echo Loading modules from $LUSTRE
363 load_module ../libcfs/libcfs/libcfs
364 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
365 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
366 load_module ../lnet/lnet/lnet
367 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
368 load_module ../lnet/klnds/$LNETLND
369 load_module lvfs/lvfs
370 load_module obdclass/obdclass
371 load_module ptlrpc/ptlrpc
372 load_module ptlrpc/gss/ptlrpc_gss
373 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
381 if ! client_only; then
382 SYMLIST=/proc/kallsyms
383 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
384 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
385 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
386 if [ "$FSTYPE" = "ldiskfs" ]; then
387 grep -q exportfs_decode_fh $SYMLIST ||
388 { modprobe exportfs 2> /dev/null || true; }
389 load_module ../ldiskfs/ldiskfs/ldiskfs
395 load_module lvfs/fsfilt_$FSTYPE
397 load_module osd-ldiskfs/osd_ldiskfs
399 load_module obdfilter/obdfilter
403 load_module llite/lustre
404 llite_lloop_enabled && load_module llite/llite_lloop
405 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
407 rm -f $OGDB/ogdb-$HOSTNAME
408 $LCTL modules > $OGDB/ogdb-$HOSTNAME
410 # 'mount' doesn't look in $PATH, just sbin
411 if [ -f $LUSTRE/utils/mount.lustre ] && \
412 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
413 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
414 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
421 # load modules on remote nodes optionally
422 # lustre-tests have to be installed on these nodes
423 if $LOAD_MODULES_REMOTE ; then
424 local list=$(comma_list $(remote_nodes_list))
425 echo loading modules on $list
426 do_rpc_nodes $list load_modules
431 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
432 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
433 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
434 echo "$LEAK_LUSTRE" 1>&2
435 echo "$LEAK_PORTALS" 1>&2
436 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
437 echo "Memory leaks detected"
438 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
444 wait_exit_ST client # bug 12845
446 $LUSTRE_RMMOD $FSTYPE || return 2
448 if $LOAD_MODULES_REMOTE ; then
449 local list=$(comma_list $(remote_nodes_list))
450 if [ ! -z $list ]; then
451 echo unloading modules on $list
452 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
453 do_rpc_nodes $list check_mem_leak
457 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
458 umount /sbin/mount.lustre || true
459 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
460 rm -f /sbin/mount.lustre || true
463 check_mem_leak || return 254
465 echo "modules unloaded."
469 check_gss_daemon_nodes() {
473 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
474 if [ \\\"\\\$num\\\" -ne 1 ]; then
475 echo \\\$num instance of $dname;
480 check_gss_daemon_facet() {
484 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
485 if [ $num -ne 1 ]; then
486 echo "$num instance of $dname on $facet"
495 echo Stopping $@ on $list
496 do_nodes $list "killall -2 $@ 2>/dev/null || true"
499 # start gss daemons on all nodes, or
500 # "daemon" on "list" if set
501 start_gss_daemons() {
505 if [ "$list" ] && [ "$daemon" ] ; then
506 echo "Starting gss daemon on nodes: $list"
507 do_nodes $list "$daemon" || return 8
511 local list=$(comma_list $(mdts_nodes))
513 echo "Starting gss daemon on mds: $list"
514 do_nodes $list "$LSVCGSSD -v" || return 1
516 do_nodes $list "$LGSSD -v" || return 2
519 list=$(comma_list $(osts_nodes))
520 echo "Starting gss daemon on ost: $list"
521 do_nodes $list "$LSVCGSSD -v" || return 3
522 # starting on clients
524 local clients=${CLIENTS:-`hostname`}
526 echo "Starting $LGSSD on clients $clients "
527 do_nodes $clients "$LGSSD -v" || return 4
530 # wait daemons entering "stable" status
534 # check daemons are running
536 list=$(comma_list $(mdts_nodes) $(osts_nodes))
537 check_gss_daemon_nodes $list lsvcgssd || return 5
539 list=$(comma_list $(mdts_nodes))
540 check_gss_daemon_nodes $list lgssd || return 6
543 check_gss_daemon_nodes $clients lgssd || return 7
548 local list=$(comma_list $(mdts_nodes))
550 send_sigint $list lsvcgssd lgssd
552 list=$(comma_list $(osts_nodes))
553 send_sigint $list lsvcgssd
555 list=${CLIENTS:-`hostname`}
556 send_sigint $list lgssd
561 if ! module_loaded ptlrpc_gss; then
562 load_module ptlrpc/gss/ptlrpc_gss
563 module_loaded ptlrpc_gss ||
564 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
566 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
568 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
569 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
577 # maybe cleanup credential cache?
583 local device=`mdsdevname $num`
584 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
590 local device=`ostdevname $num`
591 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
596 local dz=${1:-$DEBUG_SIZE}
598 if [ -f /sys/devices/system/cpu/possible ]; then
599 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
601 local cpus=$(getconf _NPROCESSORS_CONF)
604 # bug 19944, adjust size to be -gt num_possible_cpus()
605 # promise 2MB for every cpu at least
606 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
609 lctl set_param debug_mb=$dz
612 set_default_debug () {
613 local debug=${1:-"$PTLDEBUG"}
614 local subsys=${2:-"$SUBSYSTEM"}
615 local debug_size=${3:-$DEBUG_SIZE}
617 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
618 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
620 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
623 set_default_debug_nodes () {
626 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
627 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
631 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
632 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
635 set_default_debug_facet () {
637 local node=$(facet_active_host $facet)
638 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
640 set_default_debug_nodes $node
645 local facets=${1:-$(get_facets)}
648 for facet in ${facets//,/ }; do
649 mount_facet $facet || error "Restart of $facet failed!"
656 local dev=$(facet_active $facet)_dev
657 local opt=${facet}_opt
658 local mntpt=$(facet_mntpt $facet)
660 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
661 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
663 if [ $RC -ne 0 ]; then
664 echo "mount -t lustre $@ ${!dev} $mntpt"
665 echo "Start of ${!dev} on ${facet} failed ${RC}"
667 set_default_debug_facet $facet
669 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
670 [ -z "$label" ] && echo no label for ${!dev} && exit 1
671 eval export ${facet}_svc=${label}
672 echo Started ${label}
677 # start facet device options
683 eval export ${facet}_dev=${device}
684 eval export ${facet}_opt=\"$@\"
686 local varname=${facet}failover_dev
687 if [ -n "${!varname}" ] ; then
688 eval export ${facet}failover_dev=${!varname}
690 eval export ${facet}failover_dev=$device
693 local mntpt=$(facet_mntpt $facet)
694 do_facet ${facet} mkdir -p $mntpt
695 eval export ${facet}_MOUNT=$mntpt
705 local HOST=`facet_active_host $facet`
706 [ -z $HOST ] && echo stop: no host for $facet && return 0
708 local mntpt=$(facet_mntpt $facet)
709 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
710 if [ ${running} -ne 0 ]; then
711 echo "Stopping $mntpt (opts:$@) on $HOST"
712 do_facet ${facet} umount -d $@ $mntpt
715 # umount should block, but we should wait for unrelated obd's
716 # like the MGS or MGC to also stop.
717 wait_exit_ST ${facet}
720 # save quota version (both administrative and operational quotas)
721 # add an additional parameter if mountpoint is ever different from $MOUNT
722 quota_save_version() {
723 local fsname=${2:-$FSNAME}
725 local ver=$(tr -c -d "123" <<< $spec)
726 local type=$(tr -c -d "ug" <<< $spec)
728 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
730 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
732 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
734 local osts=$(get_facets OST)
735 for ost in ${osts//,/ }; do
737 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
741 # client could mount several lustre
743 local fsname=${1:-$FSNAME}
745 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
746 do_nodes $(comma_list $(osts_nodes)) \
747 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
751 restore_quota_type () {
752 local mntpt=${1:-$MOUNT}
753 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
754 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
757 quota_save_version $old_QUOTA_TYPE
763 # We need save the original quota_type params, and restore them after testing
765 # Suppose that quota type the same on mds and ost
766 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
767 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
768 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
769 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
770 export old_QUOTA_TYPE=$quota_type
771 quota_save_version $QUOTA_TYPE
773 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
774 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
777 local quota_usrs=$QUOTA_USERS
779 # get_filesystem_size
780 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
781 local blk_soft=$((disksz + 1024))
782 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
784 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
786 local i_hard=$((i_soft + i_soft / 20))
788 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
789 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
792 for usr in $quota_usrs; do
793 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
795 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
797 eval $cmd || error "$cmd FAILED!"
799 # display the quota status
800 echo "Quota settings for $usr : "
801 $LFS quota -v -u $usr $mntpt || true
808 local OPTIONS=${3:-$MOUNTOPT}
810 local device=$MGSNID:/$FSNAME
811 if [ -z "$mnt" -o -z "$FSNAME" ]; then
812 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
816 echo "Starting client: $client: $OPTIONS $device $mnt"
817 do_node $client mkdir -p $mnt
818 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
820 set_default_debug_nodes $client
833 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
834 if [ $running -ne 0 ]; then
835 echo "Stopping client $client $mnt (opts:$force)"
836 do_node $client lsof -t $mnt || need_kill=no
837 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
838 pids=$(do_node $client lsof -t $mnt | sort -u);
839 if [ -n $pids ]; then
840 do_node $client kill -9 $pids || true
844 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
845 if [ $busy -ne 0 ] ; then
846 echo "$mnt is still busy, wait one second" && sleep 1
847 do_node $client umount $force $mnt
852 # nodes is comma list
853 sanity_mount_check_nodes () {
859 # FIXME: assume that all cluster nodes run the same os
860 [ "$(uname)" = Linux ] || return 0
863 for mnt in $mnts ; do
864 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
865 mpts=\\\$(mount | grep -w -c $mnt);
866 if [ \\\$running -ne \\\$mpts ]; then
867 echo \\\$(hostname) env are INSANE!;
875 sanity_mount_check_servers () {
877 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
878 echo Checking servers environments
880 # FIXME: modify get_facets to display all facets wo params
881 local facets="$(get_facets OST),$(get_facets MDS),mgs"
885 for facet in ${facets//,/ }; do
886 node=$(facet_host ${facet})
887 mntpt=$(facet_mntpt $facet)
888 sanity_mount_check_nodes $node $mntpt ||
889 { error "server $node environments are insane!"; return 1; }
893 sanity_mount_check_clients () {
894 local clients=${1:-$CLIENTS}
895 local mntpt=${2:-$MOUNT}
896 local mntpt2=${3:-$MOUNT2}
898 [ -z $clients ] && clients=$(hostname)
899 echo Checking clients $clients environments
901 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
902 error "clients environments are insane!"
905 sanity_mount_check () {
906 sanity_mount_check_servers || return 1
907 sanity_mount_check_clients || return 2
910 # mount clients if not mouted
911 zconf_mount_clients() {
914 local OPTIONS=${3:-$MOUNTOPT}
916 local device=$MGSNID:/$FSNAME
917 if [ -z "$mnt" -o -z "$FSNAME" ]; then
918 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
922 echo "Starting client $clients: $OPTIONS $device $mnt"
925 running=\\\$(mount | grep -c $mnt' ');
927 if [ \\\$running -eq 0 ] ; then
929 mount -t lustre $OPTIONS $device $mnt;
932 exit \\\$rc" || return ${PIPESTATUS[0]}
934 echo "Started clients $clients: "
935 do_nodes $clients "mount | grep -w $mnt"
937 set_default_debug_nodes $clients
942 zconf_umount_clients() {
949 echo "Stopping clients: $clients $mnt (opts:$force)"
950 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
951 if [ \\\$running -ne 0 ] ; then
952 echo Stopping client \\\$(hostname) $mnt opts:$force;
953 lsof $mnt || need_kill=no;
954 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
955 pids=\\\$(lsof -t $mnt | sort -u);
956 if [ -n \\\"\\\$pids\\\" ]; then
960 while umount $force $mnt 2>&1 | grep -q "busy"; do
961 echo "$mnt is still busy, wait one second" && sleep 1;
968 echo + $POWER_DOWN $node
972 shutdown_node_hard () {
974 local attempts=$SHUTDOWN_ATTEMPTS
976 for i in $(seq $attempts) ; do
979 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
980 echo "waiting for $host to fail attempts=$attempts"
981 [ $i -lt $attempts ] || \
982 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
988 local mnt=${2:-$MOUNT}
991 if [ "$FAILURE_MODE" = HARD ]; then
992 shutdown_node_hard $client
994 zconf_umount_clients $client $mnt -f
1000 local facets="$(get_facets OST),$(get_facets MDS)"
1003 combined_mgs_mds || facets="$facets,mgs"
1005 for facet in ${facets//,/ }; do
1006 if [ $(facet_active_host $facet) == $host ]; then
1007 affected="$affected $facet"
1011 echo $(comma_list $affected)
1016 local host=${2:-$(facet_host $facet)}
1018 local label=$(convert_facet2label $facet)
1019 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1022 facets_up_on_host () {
1024 local facets=$(facets_on_host $host)
1027 for facet in ${facets//,/ }; do
1028 if $(facet_up $facet $host); then
1029 affected_up="$affected_up $facet"
1033 echo $(comma_list $affected_up)
1039 if [ "$FAILURE_MODE" = HARD ]; then
1040 shutdown_node_hard $(facet_active_host $facet)
1048 echo + $POWER_UP $node
1061 if [ "$FAILURE_MODE" = HARD ]; then
1062 reboot_node $(facet_active_host $facet)
1070 if [ "$FAILURE_MODE" = HARD ]; then
1080 for facet in ${facets//,/ }; do
1081 hosts=$(expand_list $hosts $(facet_host $facet) )
1087 _check_progs_installed () {
1091 for prog in $progs; do
1092 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1093 echo $prog missing on $(hostname)
1100 check_progs_installed () {
1104 do_rpc_nodes $nodes _check_progs_installed $@
1107 # recovery-scale functions
1109 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1112 start_client_load() {
1115 local var=$(node_var_name $client)_load
1116 eval export ${var}=$load
1118 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1119 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1120 END_RUN_FILE=$END_RUN_FILE \
1121 LOAD_PID_FILE=$LOAD_PID_FILE \
1122 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1123 TESTNAME=$TESTNAME \
1124 DBENCH_LIB=$DBENCH_LIB \
1125 DBENCH_SRC=$DBENCH_SRC \
1128 log "Started client load: ${load} on $client"
1130 # get the children process IDs
1131 local pids=$(ps --ppid $ppid -o pid= | xargs)
1132 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1136 start_client_loads () {
1137 local -a clients=(${1//,/ })
1138 local numloads=${#CLIENT_LOADS[@]}
1141 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1142 testnum=$((nodenum % numloads))
1143 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1145 # bug 22169: wait the background threads to start
1149 # only for remote client
1150 check_client_load () {
1152 local var=$(node_var_name $client)_load
1153 local TESTLOAD=run_${!var}.sh
1155 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1157 # bug 18914: try to connect several times not only when
1158 # check ps, but while check_catastrophe also
1161 while [ $RC = 254 -a $tries -gt 0 ]; do
1165 if ! check_catastrophe $client; then
1167 if [ $RC -eq 254 ]; then
1168 # FIXME: not sure how long we shuold sleep here
1172 echo "check catastrophe failed: RC=$RC "
1176 # We can continue try to connect if RC=254
1177 # Just print the warning about this
1178 if [ $RC = 254 ]; then
1179 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1182 # see if the load is still on the client
1185 while [ $RC = 254 -a $tries -gt 0 ]; do
1189 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1194 if [ $RC = 254 ]; then
1195 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1196 # see if we can diagnose a bit why this is
1201 check_client_loads () {
1202 local clients=${1//,/ }
1206 for client in $clients; do
1207 check_client_load $client
1209 if [ "$rc" != 0 ]; then
1210 log "Client load failed on node $client, rc=$rc"
1216 restart_client_loads () {
1217 local clients=${1//,/ }
1218 local expectedfail=${2:-""}
1222 for client in $clients; do
1223 check_client_load $client
1225 if [ "$rc" != 0 -a "$expectedfail" ]; then
1226 local var=$(node_var_name $client)_load
1227 start_client_load $client ${!var}
1228 echo "Restarted client load ${!var}: on $client. Checking ..."
1229 check_client_load $client
1231 if [ "$rc" != 0 ]; then
1232 log "Client load failed to restart on node $client, rc=$rc"
1233 # failure one client load means test fail
1234 # we do not need to check other
1243 # Start vmstat and save its process ID in a file.
1248 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1251 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1252 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1255 # Display the nodes on which client loads failed.
1256 print_end_run_file() {
1260 [ -s $file ] || return 0
1262 echo "Found the END_RUN_FILE file: $file"
1265 # A client load will stop if it finds the END_RUN_FILE file.
1266 # That does not mean the client load actually failed though.
1267 # The first node in END_RUN_FILE is the one we are interested in.
1270 if [ -n "$node" ]; then
1271 local var=$(node_var_name $node)_load
1273 local prefix=$TESTLOG_PREFIX
1274 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1275 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1276 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1278 echo "Client load ${!var} failed on node $node:"
1284 # Stop the process which had its PID saved in a file.
1289 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1291 do_nodes $nodes "test -f $pid_file &&
1292 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1295 # Stop all client loads.
1296 stop_client_loads() {
1297 local nodes=${1:-$CLIENTS}
1300 # stop the client loads
1301 stop_process $nodes $pid_file
1303 # clean up the processes that started them
1304 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1306 # End recovery-scale functions
1308 # verify that lustre actually cleaned up properly
1310 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1311 error "LBUG/LASSERT detected"
1312 BUSY=`dmesg | grep -i destruct || true`
1313 if [ "$BUSY" ]; then
1315 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1319 check_mem_leak || exit 204
1321 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1322 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1324 if module_loaded lnet || module_loaded libcfs; then
1325 echo "$0: modules still loaded..." 1>&2
1343 RESULT=$(do_node $node "$TEST")
1344 if [ "$RESULT" == "$FINAL" ]; then
1345 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1346 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1349 [ $WAIT -ge $MAX ] && break
1350 [ $((WAIT % print)) -eq 0 ] &&
1351 echo "Waiting $((MAX - WAIT)) secs for update"
1352 WAIT=$((WAIT + sleep))
1355 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1359 wait_update_facet () {
1361 wait_update $(facet_active_host $facet) "$@"
1364 wait_delete_completed () {
1365 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1366 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1370 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1372 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1373 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1374 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1375 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1379 echo "Delete is not completed in $MAX_WAIT sec"
1386 # we can use "for" here because we are waiting the slowest
1387 for host in ${hostlist//,/ }; do
1388 check_network "$host" 900
1390 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1397 for facet in ${facetlist//,/ }; do
1398 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1400 wait_for_host $hostlist
1403 _wait_recovery_complete () {
1406 # Use default policy if $2 is not passed by caller.
1407 local MAX=${2:-$(max_recovery_time)}
1412 while [ $WAIT -lt $MAX ]; do
1413 STATUS=$(lctl get_param -n $param | grep status)
1415 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1418 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1420 echo "$param recovery not done in $MAX sec. $STATUS"
1424 wait_recovery_complete () {
1427 # with an assumption that at_max is the same on all nodes
1428 local MAX=${2:-$(max_recovery_time)}
1431 if [ "$FAILURE_MODE" = HARD ]; then
1432 facets=$(facets_on_host $(facet_active_host $facet))
1434 echo affected facets: $facets
1436 # we can use "for" here because we are waiting the slowest
1437 for facet in ${facets//,/ }; do
1438 local var_svc=${facet}_svc
1439 local param="*.${!var_svc}.recovery_status"
1441 local host=$(facet_active_host $facet)
1442 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1446 wait_mds_ost_sync () {
1447 # just because recovery is done doesn't mean we've finished
1448 # orphan cleanup. Wait for llogs to get synchronized.
1449 echo "Waiting for orphan cleanup..."
1450 # MAX value includes time needed for MDS-OST reconnection
1451 local MAX=$(( TIMEOUT * 2 ))
1453 while [ $WAIT -lt $MAX ]; do
1454 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1455 "$LCTL get_param -n obdfilter.*.mds_sync"))
1458 for ((i=0; i<${#sync[@]}; i++)); do
1459 [ ${sync[$i]} -eq 0 ] && continue
1460 # there is a not finished MDS-OST synchronization
1464 sleep 2 # increase waiting time and cover statfs cache
1465 [ ${con} -eq 1 ] && return 0
1466 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1469 echo "$facet recovery not done in $MAX sec. $STATUS"
1473 wait_destroy_complete () {
1474 echo "Waiting for destroy to be done..."
1475 # MAX value shouldn't be big as this mean server responsiveness
1476 # never increase this just to make test pass but investigate
1477 # why it takes so long time
1480 while [ $WAIT -lt $MAX ]; do
1481 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1483 for ((i=0; i<${#RPCs[@]}; i++)); do
1484 [ ${RPCs[$i]} -eq 0 ] && continue
1485 # there are still some destroy RPCs in flight
1490 [ ${con} -eq 1 ] && return 0 # done waiting
1491 echo "Waiting $WAIT secs for destroys to be done."
1494 echo "Destroys weren't done in $MAX sec."
1504 # conf-sanity 31 takes a long time cleanup
1505 while [ $WAIT -lt 300 ]; do
1506 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1507 [ -z "${running}" ] && return 0
1508 echo "waited $WAIT for${running}"
1509 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1511 WAIT=$((WAIT + INTERVAL))
1513 echo "service didn't stop after $WAIT seconds. Still running:"
1518 wait_remote_prog () {
1524 [ "$PDSH" = "no_dsh" ] && return 0
1526 while [ $WAIT -lt $2 ]; do
1527 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1528 [ -z "${running}" ] && return 0 || true
1529 echo "waited $WAIT for: "
1531 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1533 WAIT=$((WAIT + INTERVAL))
1535 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1536 [ -z "$pids" ] && return 0
1537 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1538 # FIXME: not portable
1539 for pid in $pids; do
1540 cat /proc/${pid}/status || true
1541 cat /proc/${pid}/wchan || true
1543 kill -9 $pid || true
1552 # not every config has many clients
1554 if [ ! -z "$CLIENTS" ]; then
1555 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1557 stat -f $MOUNT > /dev/null
1563 # usually checked on particular client or locally
1565 if [ ! -z "$client" ]; then
1566 $PDSH $client "stat -f $MOUNT" > /dev/null
1568 stat -f $MOUNT > /dev/null
1576 client_reconnect() {
1577 uname -n >> $MOUNT/recon
1578 if [ -z "$CLIENTS" ]; then
1579 df $MOUNT; uname -n >> $MOUNT/recon
1581 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1583 echo Connected clients:
1585 ls -l $MOUNT/recon > /dev/null
1589 affected_facets () {
1592 local host=$(facet_active_host $facet)
1593 local affected=$facet
1595 if [ "$FAILURE_MODE" = HARD ]; then
1596 affected=$(facets_up_on_host $host)
1604 local host=$(facet_active_host $facet)
1606 echo "Failing $facet on node $host"
1608 # Make sure the client data is synced to disk. LU-924
1610 # We don't write client data synchrnously (to avoid flooding sync writes
1611 # when there are many clients connecting), so if the server reboots before
1612 # the client data reachs disk, the client data will be lost and the client
1613 # will be evicted after recovery, which is not what we expected.
1614 do_facet $facet "sync; sync; sync"
1616 local affected=$(affected_facets $facet)
1618 shutdown_facet $facet
1620 echo affected facets: $affected
1622 [ -n "$sleep_time" ] && sleep $sleep_time
1626 change_active $affected
1628 wait_for_facet $affected
1629 # start mgs first if it is affected
1630 if ! combined_mgs_mds && list_member $affected mgs; then
1631 mount_facet mgs || error "Restart of mgs failed"
1633 # FIXME; has to be changed to mount all facets concurrently
1634 affected=$(exclude_items_from_list $affected mgs)
1635 mount_facets $affected
1644 do_facet $facet "sync; sync; sync"
1647 # make sure there will be no seq change
1648 local clients=${CLIENTS:-$HOSTNAME}
1649 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1651 local svc=${facet}_svc
1652 do_facet $facet $LCTL --device %${!svc} notransno
1653 do_facet $facet $LCTL --device %${!svc} readonly
1654 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1655 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1658 replay_barrier_nodf() {
1659 local facet=$1 echo running=${running}
1660 do_facet $facet "sync; sync; sync"
1661 local svc=${facet}_svc
1662 echo Replay barrier on ${!svc}
1663 do_facet $facet $LCTL --device %${!svc} notransno
1664 do_facet $facet $LCTL --device %${!svc} readonly
1665 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1666 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1669 replay_barrier_nosync() {
1670 local facet=$1 echo running=${running}
1671 local svc=${facet}_svc
1672 echo Replay barrier on ${!svc}
1673 do_facet $facet $LCTL --device %${!svc} notransno
1674 do_facet $facet $LCTL --device %${!svc} readonly
1675 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1676 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1679 mds_evict_client() {
1680 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1681 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1684 ost_evict_client() {
1685 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1686 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1690 facet_failover $* || error "failover: $?"
1691 clients_up || error "post-failover df: $?"
1696 facet_failover $facet
1702 change_active $facet
1703 wait_for_facet $facet
1704 mount_facet $facet -o abort_recovery
1705 clients_up || echo "first df failed: $?"
1706 clients_up || error "post-failover df: $?"
1710 echo There is no lmc. This is mountconf, baby.
1714 host_nids_address() {
1718 if [ -n "$kind" ]; then
1719 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1721 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1727 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1733 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1734 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1735 if [ -z "$ID" ]; then
1736 echo "Could not get a ptl id for $1..."
1745 h2name_or_ip "$1" "tcp"
1750 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1751 if type __h2elan >/dev/null 2>&1; then
1754 ID=`echo $1 | sed 's/[^0-9]*//g'`
1762 h2name_or_ip "$1" "o2ib"
1766 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1767 # expressions format. As a bonus we can then just pass in those variables
1768 # to pdsh. What this function does is take a HOSTLIST type string and
1769 # expand it into a space deliminated list for us.
1777 [ -z "$hostlist" ] && return
1779 # Translate the case of [..],..,[..] to [..] .. [..]
1780 list="${hostlist/],/] }"
1782 [[ "$front" == *,* ]] && {
1785 list=${list/${old}/${new}}
1788 for item in $list; do
1789 # Test if we have any []'s at all
1790 if [ "$item" != "${item/\[/}" ]; then {
1791 # Expand the [*] into list
1795 if [ "$name" != "$item" ]; then
1796 group=${item#$name[*}
1799 for range in ${group//,/ }; do
1803 # Number of leading zeros
1806 end=$(echo $end | sed 's/0*//')
1807 [[ -z "$end" ]] && end=0
1808 [[ $padlen2 -gt $padlen ]] && {
1809 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1812 begin=$(echo $begin | sed 's/0*//')
1813 [ -z $begin ] && begin=0
1815 for num in $(seq -f "%0${padlen}g" $begin $end); do
1816 value="${name#*,}${num}${back}"
1817 [ "$value" != "${value/\[/}" ] && {
1818 value=$(hostlist_expand "$value")
1820 myList="$myList $value"
1825 myList="$myList $item"
1828 myList=${myList//,/ }
1829 myList=${myList:1} # Remove first character which is a space
1831 # Filter any duplicates without sorting
1833 myList="${list%% *}"
1835 while [[ "$list" != ${myList##* } ]]; do
1836 list=${list//${list%% *} /}
1837 myList="$myList ${list%% *}"
1839 myList="${myList%* }";
1841 # We can select an object at a offset in the list
1844 for item in $myList; do
1846 [ $cnt -eq $offset ] && {
1850 [ $(get_node_count $myList) -ne 1 ] && myList=""
1858 [ "$facet" == client ] && echo -n $HOSTNAME && return
1859 varname=${facet}_HOST
1860 if [ -z "${!varname}" ]; then
1861 if [ "${facet:0:3}" == "ost" ]; then
1862 eval ${facet}_HOST=${ost_HOST}
1870 local activevar=${facet}active
1872 if [ -f $TMP/${facet}active ] ; then
1873 source $TMP/${facet}active
1876 active=${!activevar}
1877 if [ -z "$active" ] ; then
1884 facet_active_host() {
1886 local active=`facet_active $facet`
1887 if [ "$facet" == client ]; then
1890 echo `facet_host $active`
1898 facetlist=$(exclude_items_from_list $facetlist mgs)
1900 for facet in ${facetlist//,/ }; do
1901 local failover=${facet}failover
1902 local host=`facet_host $failover`
1903 [ -z "$host" ] && return
1905 local curactive=`facet_active $facet`
1906 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1907 eval export ${facet}active=$facet
1909 eval export ${facet}active=$failover
1911 # save the active host for this facet
1912 local activevar=${facet}active
1913 echo "$activevar=${!activevar}" > $TMP/$activevar
1914 [[ $facet = mds1 ]] && combined_mgs_mds && \
1915 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1916 local TO=`facet_active_host $facet`
1917 echo "Failover $facet to $TO"
1923 # do not stripe off hostname if verbose, bug 19215
1924 if [ x$1 = x--verbose ]; then
1932 if [ "$HOST" = "$HOSTNAME" ]; then
1934 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1935 echo "cannot run remote command on $HOST with $myPDSH"
1939 echo "CMD: $HOST $@" >&2
1940 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1943 if [ "$myPDSH" = "rsh" ]; then
1944 # we need this because rsh does not return exit code of an executed command
1945 local command_status="$TMP/cs"
1946 rsh $HOST ":> $command_status"
1947 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1948 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1949 echo command failed >$command_status"
1950 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1955 # print HOSTNAME for myPDSH="no_dsh"
1956 if [[ $myPDSH = no_dsh ]]; then
1957 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1959 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1962 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1964 return ${PIPESTATUS[0]}
1968 do_node --verbose "$@"
1971 single_local_node () {
1972 [ "$1" = "$HOSTNAME" ]
1975 # Outputs environment variable assignments that should be passed to remote nodes
1980 for var in ${!MODOPTS_*}; do
1982 echo "${var}=\"$value\""
1988 # do not stripe off hostname if verbose, bug 19215
1989 if [ x$1 = x--verbose ]; then
1997 if single_local_node $rnodes; then
1999 do_nodev $rnodes "$@"
2001 do_node $rnodes "$@"
2006 # This is part from do_node
2009 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2010 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2013 echo "CMD: $rnodes $@" >&2
2014 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2017 # do not replace anything from pdsh output if -N is used
2018 # -N Disable hostname: prefix on lines of output.
2019 if $verbose || [[ $myPDSH = *-N* ]]; then
2020 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2022 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2024 return ${PIPESTATUS[0]}
2030 local HOST=`facet_active_host $facet`
2031 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2036 do_nodes --verbose "$@"
2042 # make sure its not already running
2044 rm -f $TMP/${facet}active
2045 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2046 do_facet ${facet} $MKFS $*
2052 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2053 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
2060 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2061 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
2067 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2069 local var=${facet}_MOUNT
2070 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2079 # make sure we are using the primary server, so test-framework will
2080 # be able to clean up properly.
2081 activemds=`facet_active mds1`
2082 if [ $activemds != "mds1" ]; then
2086 local clients=$CLIENTS
2087 [ -z $clients ] && clients=$(hostname)
2089 zconf_umount_clients $clients $MOUNT "$*" || true
2090 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2092 [ "$CLIENTONLY" ] && return
2093 # The add fn does rm ${facet}active file, this would be enough
2094 # if we use do_facet <facet> only after the facet added, but
2095 # currently we use do_facet mds in local.sh
2096 for num in `seq $MDSCOUNT`; do
2098 rm -f ${TMP}/mds${num}active
2100 combined_mgs_mds && rm -f $TMP/mgsactive
2102 for num in `seq $OSTCOUNT`; do
2104 rm -f $TMP/ost${num}active
2107 if ! combined_mgs_mds ; then
2114 cleanup_echo_devs () {
2115 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2117 for dev in $devs; do
2118 $LCTL --device $dev cleanup
2119 $LCTL --device $dev detach
2124 nfs_client_mode && return
2133 combined_mgs_mds () {
2134 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2140 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2141 local optvar=${tgt}_MKFS_OPTS
2142 local opt=${!optvar}
2144 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2145 [[ $facet = mgs ]] && echo $opt && return
2148 # --failnode options
2149 local var=${facet}failover_HOST
2150 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2151 local failnode=$(h2$NETTYPE ${!var})
2152 failnode="--failnode=$failnode"
2153 # options does not contain
2154 # or contains wrong --failnode=
2155 if [[ $opt != *${failnode}* ]]; then
2156 opt=$(echo $opt | sed 's/--failnode=.* / /')
2157 opt="$opt $failnode"
2163 # no additional mkfs mds "--mgsnode" option for this configuration
2164 if [[ $facet = mds ]] && combined_mgs_mds; then
2169 # additional mkfs "--mgsnode"
2170 local mgsnode="--mgsnode=$MGSNID"
2171 opt=${opt//$mgsnode }
2172 for nid in ${MGSNID//:/ }; do
2173 local mgsnode="--mgsnode=$nid"
2174 # options does not contain
2176 if [[ $opt != *${mgsnode}" "* ]]; then
2177 opt="$opt --mgsnode=$nid"
2185 if [ "$IAMDIR" == "yes" ]; then
2186 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2189 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2192 # We need ldiskfs here, may as well load them all
2194 [ "$CLIENTONLY" ] && return
2195 echo Formatting mgs, mds, osts
2196 if ! combined_mgs_mds ; then
2197 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2200 for num in `seq $MDSCOUNT`; do
2201 echo "Format mds$num: $(mdsdevname $num)"
2203 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2205 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2209 # the ost-s could have different OST_MKFS_OPTS
2210 # because of different failnode-s
2211 for num in `seq $OSTCOUNT`; do
2212 echo "Format ost$num: $(ostdevname $num)"
2214 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2216 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2222 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2226 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2230 # 0: success, the old identity set already.
2231 # 1: success, the old identity does not set.
2236 local j=`expr $num - 1`
2237 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2239 if [ -z "$MDT" ]; then
2243 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2246 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2248 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2251 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2253 if [ $old = "NONE" ]; then
2262 zconf_umount `hostname` $1 || error "umount failed"
2263 zconf_mount `hostname` $1 || error "mount failed"
2266 writeconf_facet () {
2270 do_facet $facet "$TUNEFS --writeconf $dev"
2274 for num in `seq $MDSCOUNT`; do
2275 DEVNAME=$(mdsdevname $num)
2276 writeconf_facet mds$num $DEVNAME
2279 for num in `seq $OSTCOUNT`; do
2280 DEVNAME=$(ostdevname $num)
2281 writeconf_facet ost$num $DEVNAME
2286 nfs_client_mode && return
2288 sanity_mount_check ||
2289 error "environments are insane!"
2293 if [ -z "$CLIENTONLY" ]; then
2294 echo Setup mgs, mdt, osts
2295 echo $WRITECONF | grep -q "writeconf" && \
2297 if ! combined_mgs_mds ; then
2298 start mgs $MGSDEV $MGS_MOUNT_OPTS
2301 for num in `seq $MDSCOUNT`; do
2302 DEVNAME=$(mdsdevname $num)
2303 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2305 # We started mds, now we should set failover variables properly.
2306 # Set mds${num}failover_HOST if it is not set (the default failnode).
2307 local varname=mds${num}failover_HOST
2308 if [ -z "${!varname}" ]; then
2309 eval mds${num}failover_HOST=$(facet_host mds$num)
2312 if [ $IDENTITY_UPCALL != "default" ]; then
2313 switch_identity $num $IDENTITY_UPCALL
2316 for num in `seq $OSTCOUNT`; do
2317 DEVNAME=$(ostdevname $num)
2318 start ost$num $DEVNAME $OST_MOUNT_OPTS
2320 # We started ost$num, now we should set ost${num}failover variable properly.
2321 # Set ost${num}failover_HOST if it is not set (the default failnode).
2322 varname=ost${num}failover_HOST
2323 if [ -z "${!varname}" ]; then
2324 eval ost${num}failover_HOST=$(facet_host ost${num})
2332 # wait a while to allow sptlrpc configuration be propogated to targets,
2333 # only needed when mounting new target devices.
2338 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2340 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2343 if [ "$MOUNT_2" ]; then
2344 mount_client $MOUNT2
2345 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2350 # by remounting mdt before ost, initial connect from mdt to ost might
2351 # timeout because ost is not ready yet. wait some time to its fully
2352 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2353 # by a context negotiation rpc with $TIMEOUT.
2354 # FIXME better by monitoring import status.
2357 sleep $((TIMEOUT + 5))
2363 mounted_lustre_filesystems() {
2364 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2367 init_facet_vars () {
2368 [ "$CLIENTONLY" ] && return 0
2375 eval export ${facet}_dev=${device}
2376 eval export ${facet}_opt=\"$@\"
2378 local dev=${facet}_dev
2379 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2380 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2382 eval export ${facet}_svc=${label}
2384 local varname=${facet}failover_HOST
2385 if [ -z "${!varname}" ]; then
2386 eval $varname=$(facet_host $facet)
2389 # ${facet}failover_dev is set in cfg file
2390 varname=${facet}failover_dev
2391 if [ -n "${!varname}" ] ; then
2392 eval export ${facet}failover_dev=${!varname}
2394 eval export ${facet}failover_dev=$device
2397 # get mount point of already mounted device
2398 # is facet_dev is already mounted then use the real
2399 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2400 # i.e. ${facet}_MOUNT if specified by user or default
2401 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2402 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2403 if [ -z $mntpt ]; then
2404 mntpt=$(facet_mntpt $facet)
2406 eval export ${facet}_MOUNT=$mntpt
2409 init_facets_vars () {
2412 if ! remote_mds_nodsh; then
2413 for num in `seq $MDSCOUNT`; do
2414 DEVNAME=`mdsdevname $num`
2415 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2419 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2421 remote_ost_nodsh && return
2423 for num in `seq $OSTCOUNT`; do
2424 DEVNAME=`ostdevname $num`
2425 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2429 osc_ensure_active () {
2434 while [ $period -lt $timeout ]; do
2435 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2436 if [ $count -eq 0 ]; then
2440 echo "There are $count OST are inactive, wait $period seconds, and try again"
2442 period=$((period+3))
2445 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2448 init_param_vars () {
2449 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2450 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2451 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2452 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2456 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2458 log "Using TIMEOUT=$TIMEOUT"
2460 osc_ensure_active $SINGLEMDS $TIMEOUT
2461 osc_ensure_active client $TIMEOUT
2463 if [ $QUOTA_AUTO -ne 0 ]; then
2464 if [ "$ENABLE_QUOTA" ]; then
2465 echo "enable quota as required"
2466 setup_quota $MOUNT || return 2
2468 echo "disable quota as required"
2469 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2476 nfs_client_mode () {
2477 if [ "$NFSCLIENT" ]; then
2478 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2479 local clients=$CLIENTS
2480 [ -z $clients ] && clients=$(hostname)
2482 # FIXME: remove hostname when 19215 fixed
2483 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2484 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2485 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2486 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2488 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2494 check_config_client () {
2497 local mounted=$(mount | grep " $mntpt ")
2498 if [ "$CLIENTONLY" ]; then
2500 # CLIENTONLY should not depend on *_HOST settings
2501 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2502 # in theory someone could create a new,
2503 # client-only config file that assumed lustre was already
2504 # configured and didn't set the MGSNID. If MGSNID is not set,
2505 # then we should use the mgs nid currently being used
2506 # as the default value. bug 18021
2507 [[ x$MGSNID = x ]] &&
2510 if [[ x$mgc != xMGC$MGSNID ]]; then
2511 if [ "$mgs_HOST" ]; then
2512 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2513 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2514 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2520 local myMGS_host=$mgs_HOST
2521 if [ "$NETTYPE" = "ptl" ]; then
2522 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2525 echo Checking config lustre mounted on $mntpt
2526 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2527 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2529 # if [ "$mgshost" != "$myMGS_host" ]; then
2530 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2531 # Please use correct config or set mds_HOST correctly!"
2536 check_config_clients () {
2537 local clients=${CLIENTS:-$HOSTNAME}
2540 nfs_client_mode && return
2542 do_rpc_nodes $clients check_config_client $mntpt
2544 sanity_mount_check ||
2545 error "environments are insane!"
2549 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2550 local cltimeout=$(lctl get_param -n timeout)
2551 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2552 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2559 [ -z $mntpt ] && return 1
2560 local mounted=$(mounted_lustre_filesystems)
2562 echo $mounted' ' | grep -w -q $mntpt' '
2566 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2570 # empty lustre filesystem may have empty directories lost+found and .lustre
2572 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2573 -print | wc -l) = 1 ] || return 1
2574 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2575 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2579 check_and_setup_lustre() {
2580 nfs_client_mode && return
2582 local MOUNTED=$(mounted_lustre_filesystems)
2586 # both MOUNT and MOUNT2 are not mounted
2587 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2588 [ "$REFORMAT" ] && formatall
2589 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2591 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2592 export I_MOUNTED=yes
2596 elif is_mounted $MOUNT2; then
2598 # MOUNT2 is mounted, while MOUNT_2 is not set
2599 if ! [ "$MOUNT_2" ]; then
2600 cleanup_mount $MOUNT2
2601 export I_UMOUNTED2=yes
2604 # MOUNT2 is mounted, MOUNT_2 is set
2606 # FIXME: what to do if check_config failed?
2608 # 1) remote client has mounted other Lustre fs ?
2609 # 2) it has insane env ?
2610 # let's try umount MOUNT2 on all clients and mount it again:
2611 if ! check_config_clients $MOUNT2; then
2612 cleanup_mount $MOUNT2
2613 restore_mount $MOUNT2
2614 export I_MOUNTED2=yes
2619 # MOUNT is mounted MOUNT2 is not mounted
2620 elif [ "$MOUNT_2" ]; then
2621 restore_mount $MOUNT2
2622 export I_MOUNTED2=yes
2626 # FIXME: what to do if check_config failed?
2628 # 1) remote client has mounted other Lustre fs?
2629 # 2) lustre is mounted on remote_clients atall ?
2630 check_config_clients $MOUNT
2634 set_default_debug_nodes $(comma_list $(nodes_list))
2640 if [ "$ONLY" == "setup" ]; then
2646 local clients=${CLIENTS:-$HOSTNAME}
2649 zconf_mount_clients $clients $mntpt
2653 local clients=${CLIENTS:-$HOSTNAME}
2656 zconf_umount_clients $clients $mntpt
2659 cleanup_and_setup_lustre() {
2660 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2661 lctl set_param debug=0 || true
2663 if [ "$ONLY" == "cleanup" ]; then
2667 check_and_setup_lustre
2670 # Get all of the server target devices from a given server node and type.
2679 mdt) obd_type="osd" ;;
2680 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2681 *) echo "invalid server type" && return 1 ;;
2684 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2685 for dev in $devs; do
2687 *loop*) do_node $node "losetup $dev" | \
2688 sed -e "s/.*(//" -e "s/).*//" ;;
2694 # Get all of the server target devices.
2699 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2703 for node in $(osts_nodes); do
2704 OSTDEVS[i]=$(get_mnt_devs $node ost)
2709 # Run e2fsck on MDT or OST device.
2715 df > /dev/null # update statfs data on disk
2716 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2719 do_node $node $cmd || rc=$?
2720 [ $rc -le $FSCK_MAX_ERR ] || \
2721 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2725 # verify a directory is shared among nodes.
2726 check_shared_dir() {
2729 [ -z "$dir" ] && return 1
2730 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2731 check_write_access $dir || return 1
2735 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2741 check_shared_dir $SHARED_DIRECTORY ||
2742 error "$SHARED_DIRECTORY isn't a shared directory"
2744 export MDSDB=$SHARED_DIRECTORY/mdsdb
2745 export OSTDB=$SHARED_DIRECTORY/ostdb
2747 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2749 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2754 for node in $(osts_nodes); do
2755 for dev in ${OSTDEVS[i]}; do
2756 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2757 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2758 ostidx=$((ostidx + 1))
2765 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2769 [ $rc -le $FSCK_MAX_ERR ] || \
2770 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2771 echo "lfsck finished with rc=$rc"
2773 rm -rvf $MDSDB* $OSTDB* || true
2777 check_and_cleanup_lustre() {
2778 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2784 if is_mounted $MOUNT; then
2785 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
2786 error "remove sub-test dirs failed"
2787 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2790 if [ "$I_UMOUNTED2" = "yes" ]; then
2791 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2794 if [ "$I_MOUNTED2" = "yes" ]; then
2795 cleanup_mount $MOUNT2
2798 if [ "$I_MOUNTED" = "yes" ]; then
2799 cleanupall -f || error "cleanup failed"
2807 wait_for_function () {
2810 # suppress fn both stderr and stdout
2811 if [ "$1" = "--quiet" ]; then
2813 quiet=" > /dev/null 2>&1"
2825 eval $fn $quiet && return 0
2827 wait=$((wait + sleep))
2828 [ $wait -lt $max ] || return 1
2829 echo waiting $fn, $((max - wait)) secs left ...
2839 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2840 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2841 echo "Network not available!"
2845 echo `date +"%H:%M:%S (%s)"` network interface is UP
2854 # the sed converts spaces to commas, but leaves the last space
2855 # alone, so the line doesn't end with a comma.
2856 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2862 echo $list | grep -qw $item
2865 # list, excluded are the comma separated lists
2866 exclude_items_from_list () {
2872 for item in ${excluded//,/ }; do
2873 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2875 echo $(comma_list $list)
2878 # list, expand are the comma separated lists
2880 local list=${1//,/ }
2881 local expand=${2//,/ }
2884 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2885 echo $(comma_list $expanded)
2888 testslist_filter () {
2889 local script=$LUSTRE/tests/${TESTSUITE}.sh
2891 [ -f $script ] || return 0
2893 local start_at=$START_AT
2894 local stop_at=$STOP_AT
2896 local var=${TESTSUITE//-/_}_START_AT
2897 [ x"${!var}" != x ] && start_at=${!var}
2898 var=${TESTSUITE//-/_}_STOP_AT
2899 [ x"${!var}" != x ] && stop_at=${!var}
2901 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2902 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2903 /^'${start_at}'$/ {flag = 0}
2904 {if (flag == 1) print $0}
2905 /^'${stop_at}'$/ { flag = 1 }'
2909 (cd `dirname $1`; echo $PWD/`basename $1`)
2913 local types=${1:-"OST MDS MGS"}
2917 for entry in $types; do
2918 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2919 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2922 MGS ) list="$list $name";;
2923 MDS|OST ) local count=${type}COUNT
2924 for ((i=1; i<=${!count}; i++)) do
2925 list="$list ${name}$i"
2927 * ) error "Invalid facet type"
2931 echo $(comma_list $list)
2934 ##################################
2935 # Adaptive Timeouts funcs
2938 # only check mds, we assume at_max is the same on all nodes
2939 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2940 if [ $at_max -eq 0 ]; then
2951 # suppose that all ost-s have the same $at value set
2952 [ $facet != "ost" ] || facet=ost1
2954 do_facet $facet "lctl get_param -n $at"
2968 if [ $facet == "ost" ]; then
2969 facet=$(get_facets OST)
2970 elif [ $facet == "mds" ]; then
2971 facet=$(get_facets MDS)
2973 hosts=$(expand_list $hosts $(facets_hosts $facet))
2976 do_nodes $hosts lctl set_param at_max=$at_max
2979 ##################################
2983 # OBD_FAIL_MDS_ALL_REQUEST_NET
2985 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2986 do_facet client "$1" || RC=$?
2987 do_facet $SINGLEMDS lctl set_param fail_loc=0
2992 # OBD_FAIL_MDS_ALL_REPLY_NET
2994 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2995 do_facet client "$@" || RC=$?
2996 do_facet $SINGLEMDS lctl set_param fail_loc=0
3000 drop_reint_reply() {
3001 # OBD_FAIL_MDS_REINT_NET_REP
3003 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3004 do_facet client "$@" || RC=$?
3005 do_facet $SINGLEMDS lctl set_param fail_loc=0
3010 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3012 do_facet ost1 lctl set_param fail_loc=0x214
3013 do_facet client "$1" || RC=$?
3014 do_facet client "sync"
3015 do_facet ost1 lctl set_param fail_loc=0
3019 drop_ldlm_cancel() {
3020 #define OBD_FAIL_LDLM_CANCEL 0x304
3022 do_facet client lctl set_param fail_loc=0x304
3023 do_facet client "$@" || RC=$?
3024 do_facet client lctl set_param fail_loc=0
3028 drop_bl_callback() {
3029 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3031 do_facet client lctl set_param fail_loc=0x305
3032 do_facet client "$@" || RC=$?
3033 do_facet client lctl set_param fail_loc=0
3038 #define OBD_FAIL_LDLM_REPLY 0x30c
3040 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3041 do_facet client "$@" || RC=$?
3042 do_facet $SINGLEMDS lctl set_param fail_loc=0
3050 echo "clearing fail_loc on $facet"
3051 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3054 set_nodes_failloc () {
3055 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3058 cancel_lru_locks() {
3059 $LCTL mark "cancel_lru_locks $1 start"
3060 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3061 $LCTL set_param -n $d=clear
3063 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3064 $LCTL mark "cancel_lru_locks $1 stop"
3069 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3070 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3071 echo "$DEFAULT_LRU_SIZE"
3076 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3079 lru_resize_disable()
3081 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3086 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3087 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3088 echo there is still data in page cache $FILE ?
3089 lctl get_param -n $FILE
3097 DEBUGSAVE="$(lctl get_param -n debug)"
3101 [ -n "$DEBUGSAVE" ] && \
3102 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3107 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3110 debug_size_restore() {
3111 [ -n "$DEBUG_SIZE_SAVED" ] && \
3112 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3116 start_full_debug_logging() {
3121 local DEBUG_SIZE=150
3123 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3124 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3127 stop_full_debug_logging() {
3132 ##################################
3134 ##################################
3137 local TYPE=${TYPE:-"FAIL"}
3140 # do not dump logs if $1=false
3141 if [ "x$1" = "xfalse" ]; then
3146 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3149 # We need to dump the logs on all nodes
3151 gather_logs $(comma_list $(nodes_list))
3155 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3156 echo "$@" > $LOGDIR/err
3161 local log=$TESTSUITELOG
3163 [ -f "$log" ] && grep -q FAIL: $log && status=1
3176 # use only if we are ignoring failures for this test, bugno required.
3177 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3178 # e.g. error_ignore 5494 "your message"
3180 local TYPE="IGNORE (bz$1)"
3186 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3191 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3192 [ "$ALWAYS_SKIPPED" ] && \
3193 skip_logged ${TESTNAME} "$@" || true
3194 [ "$TESTSUITELOG" ] && \
3195 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3198 build_test_filter() {
3199 EXCEPT="$EXCEPT $(testslist_filter)"
3201 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3205 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3206 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3207 [ "$EXCEPT_SLOW" ] && \
3208 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3209 for E in $EXCEPT; do
3210 eval EXCEPT_${E}=true
3212 for E in $ALWAYS_EXCEPT; do
3213 eval EXCEPT_ALWAYS_${E}=true
3215 for E in $EXCEPT_SLOW; do
3216 eval EXCEPT_SLOW_${E}=true
3218 for G in $GRANT_CHECK_LIST; do
3219 eval GCHECK_ONLY_${G}=true
3224 if [[ $1 = [a-z]* ]]; then
3231 # print a newline if the last test was skipped
3232 export LAST_SKIPPED=
3233 export ALWAYS_SKIPPED=
3235 # Main entry into test-framework. This is called with the name and
3236 # description of a test. The name is used to find the function to run
3237 # the test using "test_$name".
3239 # This supports a variety of methods of specifying specific test to
3240 # run or not run. These need to be documented...
3245 export base=`basetest $1`
3246 if [ ! -z "$ONLY" ]; then
3248 if [ ${!testname}x != x ]; then
3249 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3250 run_one_logged $1 "$2"
3254 if [ ${!testname}x != x ]; then
3255 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3256 run_one_logged $1 "$2"
3264 if [ ${!testname}x != x ]; then
3266 TESTNAME=test_$1 skip "skipping excluded test $1"
3269 testname=EXCEPT_$base
3270 if [ ${!testname}x != x ]; then
3272 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3275 testname=EXCEPT_ALWAYS_$1
3276 if [ ${!testname}x != x ]; then
3279 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3282 testname=EXCEPT_ALWAYS_$base
3283 if [ ${!testname}x != x ]; then
3286 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3289 testname=EXCEPT_SLOW_$1
3290 if [ ${!testname}x != x ]; then
3292 TESTNAME=test_$1 skip "skipping SLOW test $1"
3295 testname=EXCEPT_SLOW_$base
3296 if [ ${!testname}x != x ]; then
3298 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3304 run_one_logged $1 "$2"
3315 module_loaded lnet || load_modules
3327 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3332 strace -o $TMP/$1.strace -ttt $*
3334 log "FINISHED: $*: rc $RC"
3339 equals_msg $1 test complete, duration $2 sec
3340 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3341 echo duration $2 >>$TESTSUITELOG
3345 # Set TEST_STATUS here; will be used for logging the result
3346 if [ -f $LOGDIR/err ]; then
3351 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3355 local FFREE=$(do_node $SINGLEMDS \
3356 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3357 local FTOTAL=$(do_node $SINGLEMDS \
3358 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3360 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3364 echo -n "Resetting fail_loc on all nodes..."
3365 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3371 # Log a message (on all nodes) padded with "=" before and after.
3372 # Also appends a timestamp and prepends the testsuite name.
3375 EQUALS="===================================================================================================="
3377 msg="== ${TESTSUITE} $*"
3379 [[ $last != "=" && $last != " " ]] && msg="$msg "
3380 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3381 # always include at least == after the message
3382 log "$msg== $(date +"%H:%M:%S (%s)")"
3386 # Run a single test function and cleanup after it.
3388 # This function should be run in a subshell so the test func can
3389 # exit() without stopping the whole script.
3395 export tdir=d0.${TESTSUITE}/d${base}
3396 export TESTNAME=test_$testnum
3397 local SAVE_UMASK=`umask`
3400 banner "test $testnum: $message"
3401 test_${testnum} || error "test_$testnum failed with $?"
3404 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3405 check_catastrophe || error "LBUG/LASSERT detected"
3406 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3414 # Wrapper around run_one to ensure:
3415 # - test runs in subshell
3416 # - output of test is saved to separate log file for error reporting
3417 # - test result is saved to data file
3420 local BEFORE=`date +%s`
3422 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3423 local test_log=$LOGDIR/$name
3425 local SAVE_UMASK=`umask`
3429 log_sub_test_begin test_${1}
3430 (run_one $1 "$2") 2>&1 | tee -i $test_log
3431 local RC=${PIPESTATUS[0]}
3433 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3434 echo "test_$1 returned $RC" | tee $LOGDIR/err
3436 duration=$((`date +%s` - $BEFORE))
3437 pass "$1" "(${duration}s)"
3438 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3439 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3441 if [ -f $LOGDIR/err ]; then
3442 $FAIL_ON_ERROR && exit $RC
3451 # Print information of skipped tests to result.yml
3454 log_sub_test_begin $1
3455 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3459 (cd `dirname $1`; echo $PWD/`basename $1`)
3464 export base=`basetest $1`
3465 [ "$CHECK_GRANT" == "no" ] && return 0
3467 testname=GCHECK_ONLY_${base}
3468 [ ${!testname}x == x ] && return 0
3470 echo -n "checking grant......"
3472 local clients=$CLIENTS
3473 [ -z $clients ] && clients=$(hostname)
3475 # sync all the data and make sure no pending data on server
3476 do_nodes $clients sync
3479 client_grant=`do_nodes $clients \
3480 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3481 awk '{total += $1} END{print total}'`
3484 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3485 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3486 awk '{total += $1} END{print total}'`
3488 # check whether client grant == server grant
3489 if [ $client_grant -ne $server_grant ]; then
3490 echo "failed: client:${client_grant} server: ${server_grant}."
3491 do_nodes $(comma_list $(osts_nodes)) \
3492 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3493 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3496 echo "pass: client:${client_grant} server: ${server_grant}"
3501 ########################
3507 ost=`echo $1 | awk -F_ '{print $3}'`
3508 if [ -z $ost ]; then
3509 ost=`echo $1 | sed 's/-osc.*//'`
3514 ostuuid_from_index()
3516 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3519 ostname_from_index() {
3520 local uuid=$(ostuuid_from_index $1)
3524 index_from_ostuuid()
3526 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3529 mdtuuid_from_index()
3531 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3536 [ "$node" != "$(hostname)" ]
3542 for node in $(mdts_nodes); do
3543 remote_node $node && return 0
3550 [ "$CLIENTONLY" ] && return 0 || true
3551 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3556 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3557 MSKIPPED=1 && return 1
3564 for node in $(osts_nodes) ; do
3565 remote_node $node && return 0
3572 [ "$CLIENTONLY" ] && return 0 || true
3573 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3578 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3579 OSKIPPED=1 && return 1
3586 MGS=$(facet_host mgs)
3587 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3592 remote_mds_nodsh || remote_ost_nodsh || \
3593 $(single_local_node $(comma_list $(nodes_list)))
3599 for num in `seq $MDSCOUNT`; do
3600 MDSNODES="$MDSNODES $(facet_host mds$num)"
3602 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3608 remote_ost && remote_mds
3616 for facet in ${facets//,/ }; do
3617 if [ "$FAILURE_MODE" = HARD ]; then
3618 nodes="$nodes $(facet_active_host $facet)"
3620 nodes="$nodes $(facet_host $facet)"
3623 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3629 local facets=$(get_facets OST)
3630 local nodes=$(facets_nodes $facets)
3636 # FIXME. We need a list of clients
3637 local myNODES=$HOSTNAME
3640 # CLIENTS (if specified) contains the local client
3641 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3643 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3644 myNODES="$myNODES $(facets_nodes $(get_facets))"
3647 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3652 remote_nodes_list () {
3653 local rnodes=$(nodes_list)
3654 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3658 init_clients_lists () {
3659 # Sanity check: exclude the local client from RCLIENTS
3660 local clients=$(hostlist_expand "$RCLIENTS")
3661 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3663 # Sanity check: exclude the dup entries
3664 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3666 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3668 # Sanity check: exclude the dup entries from CLIENTS
3669 # for those configs which has SINGLCLIENT set to local client
3670 clients=$(for i in $clients; do echo $i; done | sort -u)
3672 CLIENTS=$(comma_list $clients)
3673 local -a remoteclients=($RCLIENTS)
3674 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3675 varname=CLIENT$((i + 2))
3676 eval $varname=${remoteclients[i]}
3679 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3682 get_random_entry () {
3685 rnodes=${rnodes//,/ }
3687 local -a nodes=($rnodes)
3688 local num=${#nodes[@]}
3689 local i=$((RANDOM * num * 2 / 65536))
3695 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3700 lctl get_param version | grep -q patchless
3704 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3709 echo $nodes | wc -w || true
3713 local nodes=$(osts_nodes)
3714 local osscount=$(get_node_count "$nodes")
3715 [ ! "$OSTCOUNT" = "$osscount" ]
3719 local nodes=$(mdts_nodes)
3720 local mdtcount=$(get_node_count "$nodes")
3721 [ ! "$MDSCOUNT" = "$mdtcount" ]
3724 generate_machine_file() {
3725 local nodes=${1//,/ }
3726 local machinefile=$2
3728 for node in $nodes; do
3729 echo $node >>$machinefile || \
3730 { echo "can not generate machinefile $machinefile" && return 1; }
3735 local file=$1/stripe
3737 $LFS getstripe -v $file || error
3741 setstripe_nfsserver () {
3744 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3745 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3747 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3749 do_nodev $nfsserver lfs setstripe "$@"
3752 check_runas_id_ret() {
3754 local myRUNAS_UID=$1
3755 local myRUNAS_GID=$2
3758 if [ -z "$myRUNAS" ]; then
3759 error_exit "myRUNAS command must be specified for check_runas_id"
3762 $myRUNAS krb5_login.sh || \
3763 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3765 mkdir $DIR/d0_runas_test
3767 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3768 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3769 rm -rf $DIR/d0_runas_test
3774 local myRUNAS_UID=$1
3775 local myRUNAS_GID=$2
3778 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3779 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3780 Please set RUNAS_ID to some UID which exists on MDS and client or
3781 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3784 # obtain the UID/GID for MPI_USER
3788 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3789 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3791 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3792 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3795 # obtain and cache Kerberos ticket-granting ticket
3796 refresh_krb5_tgt() {
3797 local myRUNAS_UID=$1
3798 local myRUNAS_GID=$2
3801 if [ -z "$myRUNAS" ]; then
3802 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3805 CLIENTS=${CLIENTS:-$HOSTNAME}
3806 do_nodes $CLIENTS "set -x
3807 if ! $myRUNAS krb5_login.sh; then
3808 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3813 # Run multiop in the background, but wait for it to print
3814 # "PAUSING" to its stdout before returning from this function.
3815 multiop_bg_pause() {
3816 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3820 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3823 echo "$MULTIOP_PROG $FILE v$ARGS"
3824 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3826 echo "TMPPIPE=${TMPPIPE}"
3827 read -t 60 multiop_output < $TMPPIPE
3828 if [ $? -ne 0 ]; then
3833 if [ "$multiop_output" != "PAUSING" ]; then
3834 echo "Incorrect multiop output: $multiop_output"
3849 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3855 inodes_available () {
3856 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3860 mdsrate_inodes_available () {
3861 local min_inodes=$(inodes_available)
3862 echo $((min_inodes * 99 / 100))
3865 # reset llite stat counters
3866 clear_llite_stats(){
3867 lctl set_param -n llite.*.stats 0
3870 # sum llite stat items
3871 calc_llite_stats() {
3872 local res=$(lctl get_param -n llite.*.stats |
3873 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3877 # reset osc stat counters
3879 lctl set_param -n osc.*.osc_stats 0
3882 # sum osc stat items
3884 local res=$(lctl get_param -n osc.*.osc_stats |
3885 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3890 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3893 calc_osc_kbytes () {
3894 df $MOUNT > /dev/null
3895 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3898 # save_lustre_params(node, parameter_mask)
3899 # generate a stream of formatted strings (<node> <param name>=<param value>)
3900 save_lustre_params() {
3902 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3905 # restore lustre parameters from input stream, produces by save_lustre_params
3906 restore_lustre_params() {
3910 while IFS=" =" read node name val; do
3911 do_node ${node//:/} "lctl set_param -n $name $val"
3915 check_catastrophe() {
3916 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3917 local C=$CATASTROPHE
3918 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3920 if [ $rnodes ]; then
3921 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3922 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3927 # CMD: determine mds index where directory inode presents
3930 local file=$dir/f0.get_mds_dir_tmpfile
3935 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3936 local -a oldused=($iused)
3938 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3940 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3941 local -a newused=($iused)
3944 for ((i=0; i<${#newused[@]}; i++)); do
3945 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3951 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3954 mdsrate_cleanup () {
3956 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3961 delayed_recovery_enabled () {
3962 local var=${SINGLEMDS}_svc
3963 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3966 ########################
3968 convert_facet2label() {
3971 if [ x$facet = xost ]; then
3975 local varsvc=${facet}_svc
3977 if [ -n ${!varsvc} ]; then
3980 error "No lablel for $facet!"
3984 get_clientosc_proc_path() {
3985 echo "${1}-osc-[^M]*"
3988 get_lustre_version () {
3989 local facet=${1:-"$SINGLEMDS"}
3990 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3993 get_mds_version_major () {
3994 local facet=${1:-"$SINGLEMDS"}
3995 local version=$(get_lustre_version $facet)
3996 echo $version | awk -F. '{print $1}'
3999 get_mds_version_minor () {
4000 local facet=${1:-"$SINGLEMDS"}
4001 local version=$(get_lustre_version $facet)
4002 echo $version | awk -F. '{print $2}'
4005 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4006 # used by MDT would not be changed.
4007 # mdt lov: fsname-mdtlov
4008 # mdt osc: fsname-OSTXXXX-osc
4009 mds_on_old_device() {
4010 local mds=${1:-"$SINGLEMDS"}
4011 local major=$(get_mds_version_major $mds)
4012 local minor=$(get_mds_version_minor $mds)
4014 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
4015 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4016 > /dev/null 2>&1" && return 0
4021 get_mdtosc_proc_path() {
4023 local ost_label=${2:-"*OST*"}
4025 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4026 local mdt_label=$(convert_facet2label $mds_facet)
4027 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4029 local major=$(get_mds_version_major $mds_facet)
4030 local minor=$(get_mds_version_minor $mds_facet)
4031 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
4032 echo "${ost_label}-osc"
4034 echo "${ost_label}-osc-${mdt_index}"
4038 get_osc_import_name() {
4041 local label=$(convert_facet2label $ost)
4043 if [ "${facet:0:3}" = "mds" ]; then
4044 get_mdtosc_proc_path $facet $label
4048 get_clientosc_proc_path $label
4052 _wait_import_state () {
4055 local maxtime=${3:-$(max_recovery_time)}
4059 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4060 while [ "${CONN_STATE}" != "${expected}" ]; do
4061 if [ "${expected}" == "DISCONN" ]; then
4062 # for disconn we can check after proc entry is removed
4063 [ "x${CONN_STATE}" == "x" ] && return 0
4064 # with AT enabled, we can have connect request timeout near of
4065 # reconnect timeout and test can't see real disconnect
4066 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4068 [ $i -ge $maxtime ] && \
4069 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4072 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4076 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4080 wait_import_state() {
4083 local maxtime=${3:-$(max_recovery_time)}
4086 for param in ${params//,/ }; do
4087 _wait_import_state $state $param $maxtime || return
4091 # One client request could be timed out because server was not ready
4092 # when request was sent by client.
4093 # The request timeout calculation details :
4095 # /* We give the server rq_timeout secs to process the req, and
4096 # add the network latency for our local timeout. */
4097 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4098 # ptlrpc_at_get_net_latency(request) ;
4100 # ptlrpc_connect_import ()
4101 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4104 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4105 # ptlrpc_at_get_net_latency(request) ->
4106 # at_get (max (iat_net_latency=0, at_min)) = at_min
4109 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4110 # INITIAL_CONNECT_TIMEOUT + at_min
4112 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4113 # because we can not get this value in runtime,
4114 # the value depends on configure options, and it is not stored in /proc.
4116 # #define CONNECTION_SWITCH_MIN 5U
4118 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4120 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4122 request_timeout () {
4125 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4126 local init_connect_timeout=$TIMEOUT
4127 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4129 local at_min=$(at_get $facet at_min)
4131 echo $(( init_connect_timeout + at_min ))
4134 wait_osc_import_state() {
4138 local ost=$(get_osc_import_name $facet $ost_facet)
4140 local param="osc.${ost}.ost_server_uuid"
4142 # 1. wait the deadline of client 1st request (it could be skipped)
4143 # 2. wait the deadline of client 2nd request
4144 local maxtime=$(( 2 * $(request_timeout $facet)))
4146 if ! do_rpc_nodes $(facet_host $facet) \
4147 _wait_import_state $expected $param $maxtime; then
4148 error "import is not in ${expected} state"
4155 get_clientmdc_proc_path() {
4163 # Add paths to lustre tests for 32 and 64 bit systems.
4164 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4165 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4168 wait_clients_import_state () {
4175 if [ "$FAILURE_MODE" = HARD ]; then
4176 facets=$(facets_on_host $(facet_active_host $facet))
4179 for facet in ${facets//,/ }; do
4180 local label=$(convert_facet2label $facet)
4183 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4184 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4185 *) error "unknown facet!" ;;
4187 local params=$(expand_list $params $proc_path)
4190 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4191 error "import is not in ${expected} state"
4200 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4201 $LCTL get_param obdfilter.*.kbytesavail))
4202 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4203 $LCTL get_param -n obdfilter.*.tot_granted))
4204 for ((i=0; i<${#AVAILA[@]}; i++)); do
4205 local -a AVAIL1=(${AVAILA[$i]//=/ })
4206 GRANT=$((${GRANTA[$i]}/1024))
4207 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4208 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4214 do_facet mgs lctl pool_list $1
4218 local fsname=${1%%.*}
4219 local poolname=${1##$fsname.}
4221 do_facet mgs lctl pool_new $1
4223 # get param should return err unless pool is created
4224 [[ $RC -ne 0 ]] && return $RC
4226 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4227 2>/dev/null || echo foo" "" || RC=1
4228 if [[ $RC -eq 0 ]]; then
4231 error "pool_new failed $1"
4236 add_pool_to_list () {
4237 local fsname=${1%%.*}
4238 local poolname=${1##$fsname.}
4240 local listvar=${fsname}_CREATED_POOLS
4241 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4244 remove_pool_from_list () {
4245 local fsname=${1%%.*}
4246 local poolname=${1##$fsname.}
4248 local listvar=${fsname}_CREATED_POOLS
4249 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4252 destroy_pool_int() {
4254 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4255 awk '$1 !~ /^Pool:/ {print $1}')
4256 for ost in $OSTS; do
4257 do_facet mgs lctl pool_remove $1 $ost
4259 do_facet mgs lctl pool_destroy $1
4262 # <fsname>.<poolname> or <poolname>
4264 local fsname=${1%%.*}
4265 local poolname=${1##$fsname.}
4267 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4271 pool_list $fsname.$poolname || return $?
4273 destroy_pool_int $fsname.$poolname
4275 [[ $RC -ne 0 ]] && return $RC
4277 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4278 2>/dev/null || echo foo" "foo" || RC=1
4280 if [[ $RC -eq 0 ]]; then
4281 remove_pool_from_list $fsname.$poolname
4283 error "destroy pool failed $1"
4289 local fsname=${1:-$FSNAME}
4291 local listvar=${fsname}_CREATED_POOLS
4295 [ x${!listvar} = x ] && return 0
4297 echo destroy the created pools: ${!listvar}
4298 for poolname in ${!listvar//,/ }; do
4299 destroy_pool $fsname.$poolname
4304 local fsname=${1:-$FSNAME}
4306 destroy_pools $fsname
4312 local ts=$(date +%s)
4315 if [[ ! -f "$YAML_LOG" ]]; then
4316 # init_logging is not performed before gather_logs,
4317 # so the $LOGDIR needs to be checked here
4318 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4321 [ -f $LOGDIR/shared ] && docp=false
4323 # dump lustre logs, dmesg
4325 prefix="$TESTLOG_PREFIX.$TESTNAME"
4327 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4329 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4330 echo "Dumping logs only on local client."
4331 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4332 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4337 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4338 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4339 if [ ! -f $LOGDIR/shared ]; then
4340 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4353 for i in $(seq 0 $num_mntpts); do
4354 cmd="ls -laf ${mntpt_root}$i/$dir"
4360 for pid in $pids; do
4367 # target_start_and_reset_recovery_timer()
4368 # service_time = at_est2timeout(service_time);
4369 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4370 # INITIAL_CONNECT_TIMEOUT);
4371 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4372 #define CONNECTION_SWITCH_INC 1
4373 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4374 #define CONNECTION_SWITCH_MIN 5U
4376 max_recovery_time () {
4377 local init_connect_timeout=$(( TIMEOUT / 20 ))
4378 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4380 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4385 get_clients_mount_count () {
4386 local clients=${CLIENTS:-`hostname`}
4388 # we need to take into account the clients mounts and
4389 # exclude mds/ost mounts if any;
4390 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4394 PROC_CLI="srpc_info"
4402 if [ $M -lt $N ]; then
4406 while [ $N -lt $M ]; do
4416 calc_connection_cnt() {
4419 # MDT->MDT = 2 * C(M, 2)
4423 comb_m2=$(combination $MDSCOUNT 2)
4425 local num_clients=$(get_clients_mount_count)
4427 local cnt_mdt2mdt=$((comb_m2 * 2))
4428 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4429 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4430 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4431 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4432 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4433 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4447 local cmd="$tgt.srpc.flavor"
4449 if [ $net == "any" ]; then
4454 if [ $dir != "any" ]; then
4459 log "Setting sptlrpc rule: $cmd"
4460 do_facet mgs "$LCTL conf_param $cmd"
4469 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4470 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4472 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4474 if [ "x$bulkspec" != "x" ]; then
4475 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4477 if [ "x$algs" != "x" ]; then
4478 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4480 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4481 if [ $bulk == "bulkn" ]; then
4482 bulk_count=`echo "$output" | grep "bulk flavor" \
4483 | grep "null/null" | wc -l`
4484 elif [ $bulk == "bulki" ]; then
4485 bulk_count=`echo "$output" | grep "bulk flavor" \
4486 | grep "/null" | grep -v "null/" | wc -l`
4488 bulk_count=`echo "$output" | grep "bulk flavor" \
4489 | grep -v "/null" | grep -v "null/" | wc -l`
4493 [ $bulk_count -lt $count ] && count=$bulk_count
4504 local clients=${CLIENTS:-`hostname`}
4506 for c in ${clients//,/ }; do
4507 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4508 tmpcnt=`count_flvr "$output" $flavor`
4509 cnt=$((cnt + tmpcnt))
4519 local clients=${CLIENTS:-`hostname`}
4521 for c in ${clients//,/ }; do
4522 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4523 tmpcnt=`count_flvr "$output" $flavor`
4524 cnt=$((cnt + tmpcnt))
4534 if [ $MDSCOUNT -le 1 ]; then
4539 for num in `seq $MDSCOUNT`; do
4540 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4541 tmpcnt=`count_flvr "$output" $flavor`
4542 cnt=$((cnt + tmpcnt))
4553 for num in `seq $MDSCOUNT`; do
4554 mdtosc=$(get_mdtosc_proc_path mds$num)
4555 mdtosc=${mdtosc/-MDT*/-MDT\*}
4556 output=$(do_facet mds$num lctl get_param -n \
4557 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4558 tmpcnt=`count_flvr "$output" $flavor`
4559 cnt=$((cnt + tmpcnt))
4568 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4569 count_flvr "$output" $flavor
4574 local dir=$1 # from to
4575 local flavor=$2 # flavor expected
4578 if [ $dir == "cli2mdt" ]; then
4579 res=`flvr_cnt_cli2mdt $flavor`
4580 elif [ $dir == "cli2ost" ]; then
4581 res=`flvr_cnt_cli2ost $flavor`
4582 elif [ $dir == "mdt2mdt" ]; then
4583 res=`flvr_cnt_mdt2mdt $flavor`
4584 elif [ $dir == "mdt2ost" ]; then
4585 res=`flvr_cnt_mdt2ost $flavor`
4586 elif [ $dir == "all2ost" ]; then
4587 res1=`flvr_cnt_mdt2ost $flavor`
4588 res2=`flvr_cnt_cli2ost $flavor`
4589 res=$((res1 + res2))
4590 elif [ $dir == "all2mdt" ]; then
4591 res1=`flvr_cnt_mdt2mdt $flavor`
4592 res2=`flvr_cnt_cli2mdt $flavor`
4593 res=$((res1 + res2))
4594 elif [ $dir == "all2all" ]; then
4595 res1=`flvr_cnt_mdt2ost $flavor`
4596 res2=`flvr_cnt_cli2ost $flavor`
4597 res3=`flvr_cnt_mdt2mdt $flavor`
4598 res4=`flvr_cnt_cli2mdt $flavor`
4599 res=$((res1 + res2 + res3 + res4))
4607 local dir=$1 # from to
4608 local flavor=$2 # flavor expected
4609 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4613 for ((i=0;i<20;i++)); do
4614 echo -n "checking $dir..."
4615 res=$(do_check_flavor $dir $flavor)
4616 echo "found $res/$expect $flavor connections"
4617 [ $res -ge $expect ] && return 0
4621 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4625 restore_to_default_flavor()
4627 local proc="mgs.MGS.live.$FSNAME"
4629 echo "restoring to default flavor..."
4631 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4633 # remove all existing rules if any
4634 if [ $nrule -ne 0 ]; then
4635 echo "$nrule existing rules"
4636 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4637 echo "remove rule: $rule"
4638 spec=`echo $rule | awk -F = '{print $1}'`
4639 do_facet mgs "$LCTL conf_param -d $spec"
4643 # verify no rules left
4644 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4645 [ $nrule -ne 0 ] && error "still $nrule rules left"
4647 # wait for default flavor to be applied
4648 # currently default flavor for all connections are 'null'
4649 wait_flavor all2all null
4650 echo "now at default flavor settings"
4655 local flavor=${1:-null}
4657 echo "setting all flavor to $flavor"
4659 # FIXME need parameter to this fn
4660 # and remove global vars
4661 local cnt_all2all=$(calc_connection_cnt all2all)
4663 local res=$(do_check_flavor all2all $flavor)
4664 if [ $res -eq $cnt_all2all ]; then
4665 echo "already have total $res $flavor connections"
4669 echo "found $res $flavor out of total $cnt_all2all connections"
4670 restore_to_default_flavor
4672 [[ $flavor = null ]] && return 0
4674 set_rule $FSNAME any any $flavor
4675 wait_flavor all2all $flavor
4681 # Checking for shared logdir
4682 if [ ! -d $dir ]; then
4683 # Not found. Create local logdir
4686 touch $dir/check_file.$(hostname -s)
4691 check_write_access() {
4696 for node in $(nodes_list); do
4697 file=$dir/check_file.$(short_hostname $node)
4698 if [[ ! -f "$file" ]]; then
4699 # Logdir not accessible/writable from this node.
4702 rm -f $file || return 1
4708 if [[ -n $YAML_LOG ]]; then
4711 local SAVE_UMASK=`umask`
4714 export YAML_LOG=${LOGDIR}/results.yml
4718 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
4719 if check_shared_dir $LOGDIR; then
4720 touch $LOGDIR/shared
4721 echo "Logging to shared log directory: $LOGDIR"
4723 echo "Logging to local directory: $LOGDIR"
4726 yml_nodes_file $LOGDIR >> $YAML_LOG
4727 yml_results_file >> $YAML_LOG
4734 yml_log_test $1 >> $YAML_LOG
4738 yml_log_test_status $@ >> $YAML_LOG
4741 log_sub_test_begin() {
4742 yml_log_sub_test_begin "$@" >> $YAML_LOG
4745 log_sub_test_end() {
4746 yml_log_sub_test_end "$@" >> $YAML_LOG
4752 local llverdev_opts=$2
4753 local devname=$(basename $1)
4754 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4755 # loop devices aren't in /proc/partitions
4756 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4758 size=$(($size / 1024 / 1024)) # Gb
4760 local partial_arg=""
4761 # Run in partial (fast) mode if the size
4762 # of a partition > 1 GB
4763 [ $size -gt 1 ] && partial_arg="-p"
4765 llverdev --force $partial_arg $llverdev_opts $dev
4771 local llverfs_opts=$2
4772 local partial_arg=""
4773 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4775 # Run in partial (fast) mode if the size
4776 # of a partition > 1 GB
4777 [ $size -gt 1 ] && partial_arg="-p"
4779 llverfs $partial_arg $llverfs_opts $dir
4782 remove_mdt_files() {
4787 local mntpt=$(facet_mntpt $facet)
4789 echo "removing files from $mdtdev on $facet: $files"
4790 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4793 rm $mntpt/ROOT/$f || { rc=$?; break; }
4795 umount -f $mntpt || return $?
4799 duplicate_mdt_files() {
4804 local mntpt=$(facet_mntpt $facet)
4806 echo "duplicating files on $mdtdev on $facet: $files"
4807 mkdir -p $mntpt || return $?
4808 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4818 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4819 pushd $mntpt/ROOT > /dev/null || return $?
4822 touch $f.bad || return $?
4823 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4825 [ $rc -eq 0 ] || return $rc
4826 setfattr --restore $tmp || return $?
4832 local devs=${1//,/ }
4835 local rslt=$TMP/sgpdd_survey
4837 # sgpdd-survey cleanups ${rslt}.* files
4839 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4845 # returns the canonical name for an ldiskfs device
4850 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4851 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4852 echo dm-\\\${foo##*:};
4854 echo \\\$(basename \\\$dv);
4858 is_sanity_benchmark() {
4859 local benchmarks="dbench bonnie iozone fsx"
4861 for b in $benchmarks; do
4862 if [ "$b" == "$suite" ]; then
4870 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4873 # Get the block size of the filesystem.
4879 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4880 awk '/^Block size:/ {print $3}')
4884 # Check whether the "large_xattr" feature is enabled or not.
4885 large_xattr_enabled() {
4886 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4888 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4889 return ${PIPESTATUS[0]}
4892 # Get the maximum xattr size supported by the filesystem.
4896 if large_xattr_enabled; then
4897 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4900 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4901 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4903 # maximum xattr size = size of block - size of header -
4904 # size of 1 entry - 4 null bytes
4905 size=$((block_size - 32 - 32 - 4))
4911 # Dump the value of the named xattr from a file.
4916 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4919 # Generate a string with size of $size bytes.
4921 local size=${1:-1024} # in bytes
4923 echo "$(head -c $size < /dev/zero | tr '\0' y)"