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" ] &&
193 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
194 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
195 [ ! -f "$LFS_MIGRATE" ] &&
196 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
197 export FSTYPE=${FSTYPE:-"ldiskfs"}
198 export NAME=${NAME:-local}
199 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
200 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
201 export LGSSD=$(which lgssd)
202 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
203 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
204 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
206 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
209 if [ "$ACCEPTOR_PORT" ]; then
210 export PORT_OPT="--port $ACCEPTOR_PORT"
215 echo "Using GSS/krb5 ptlrpc security flavor"
216 which lgss_keyring > /dev/null 2>&1 || \
217 error_exit "built with gss disabled! SEC=$SEC"
228 IDENTITY_UPCALL=false
231 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
233 # Paths on remote nodes, if different
234 export RLUSTRE=${RLUSTRE:-$LUSTRE}
235 export RPWD=${RPWD:-$PWD}
236 export I_MOUNTED=${I_MOUNTED:-"no"}
237 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
238 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
239 ! -f `dirname $0`/../mds/mds.ko ]; then
240 export CLIENTMODSONLY=yes
243 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
247 while getopts "rvwf:" opt $*; do
250 r) REFORMAT=--reformat;;
252 w) WRITECONF=writeconf;;
257 shift $((OPTIND - 1))
260 # print the durations of each test if "true"
261 DDETAILS=${DDETAILS:-false}
262 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
267 echo -n $((($1 << 16) | ($2 << 8) | $3))
270 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
271 export LINUX_VERSION_CODE=$(kernel_version ${LINUX_VERSION//\./ })
274 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
275 *) EXT=".ko"; USE_QUOTA=yes;;
280 /sbin/lsmod | grep -q "^\<$1\>"
283 # Load a module on the system where this is running.
285 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
287 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
288 # will be used as the arguments. Otherwise arguments will be obtained from
289 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
296 BASE=`basename $module $EXT`
298 module_loaded ${BASE} && return
300 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
302 if [ $# -eq 0 ]; then
303 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
304 # Bash until 4.x, so we resort to eval.
305 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
306 eval set -- \$$optvar
307 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
308 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
309 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
310 # Get rid of "options $module"
311 (($# > 0)) && shift 2
313 # Ensure we have accept=all for lnet
314 if [ $(basename $module) = lnet ]; then
315 # OK, this is a bit wordy...
316 local arg accept_all_present=false
318 [ "$arg" = accept=all ] && accept_all_present=true
320 $accept_all_present || set -- "$@" accept=all
325 [ $# -gt 0 ] && echo "${module} options: '$*'"
327 # Note that insmod will ignore anything in modprobe.conf, which is why we're
328 # passing options on the command-line.
329 if [ "$BASE" == "lnet_selftest" ] && \
330 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
331 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
332 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
333 insmod ${LUSTRE}/${module}${EXT} "$@"
335 # must be testing a "make install" or "rpm" installation
336 # note failed to load ptlrpc_gss is considered not fatal
337 if [ "$BASE" == "ptlrpc_gss" ]; then
338 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
345 llite_lloop_enabled() {
346 local n1=$(uname -r | cut -d. -f1)
347 local n2=$(uname -r | cut -d. -f2)
348 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
350 # load the llite_lloop module for < 2.6.32 kernels
351 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
352 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
359 load_modules_local() {
360 if [ -n "$MODPROBE" ]; then
362 echo "Using modprobe to load modules"
366 echo Loading modules from $LUSTRE
367 load_module ../libcfs/libcfs/libcfs
368 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
369 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
370 load_module ../lnet/lnet/lnet
371 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
372 load_module ../lnet/klnds/$LNETLND
373 load_module lvfs/lvfs
374 load_module obdclass/obdclass
375 load_module ptlrpc/ptlrpc
376 load_module ptlrpc/gss/ptlrpc_gss
377 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
385 if ! client_only; then
386 SYMLIST=/proc/kallsyms
387 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
388 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
389 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
390 if [ "$FSTYPE" = "ldiskfs" ]; then
391 grep -q exportfs_decode_fh $SYMLIST ||
392 { modprobe exportfs 2> /dev/null || true; }
393 load_module ../ldiskfs/ldiskfs/ldiskfs
399 load_module lvfs/fsfilt_$FSTYPE
401 load_module osd-ldiskfs/osd_ldiskfs
403 load_module obdfilter/obdfilter
407 load_module llite/lustre
408 llite_lloop_enabled && load_module llite/llite_lloop
409 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
411 rm -f $OGDB/ogdb-$HOSTNAME
412 $LCTL modules > $OGDB/ogdb-$HOSTNAME
414 # 'mount' doesn't look in $PATH, just sbin
415 if [ -f $LUSTRE/utils/mount.lustre ] && \
416 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
417 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
418 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
425 # load modules on remote nodes optionally
426 # lustre-tests have to be installed on these nodes
427 if $LOAD_MODULES_REMOTE ; then
428 local list=$(comma_list $(remote_nodes_list))
429 echo loading modules on $list
430 do_rpc_nodes $list load_modules
435 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
436 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
437 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
438 echo "$LEAK_LUSTRE" 1>&2
439 echo "$LEAK_PORTALS" 1>&2
440 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
441 echo "Memory leaks detected"
442 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
448 wait_exit_ST client # bug 12845
450 $LUSTRE_RMMOD $FSTYPE || return 2
452 if $LOAD_MODULES_REMOTE ; then
453 local list=$(comma_list $(remote_nodes_list))
454 if [ ! -z $list ]; then
455 echo unloading modules on $list
456 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
457 do_rpc_nodes $list check_mem_leak
461 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
462 umount /sbin/mount.lustre || true
463 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
464 rm -f /sbin/mount.lustre || true
467 check_mem_leak || return 254
469 echo "modules unloaded."
473 check_gss_daemon_nodes() {
477 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
478 if [ \\\"\\\$num\\\" -ne 1 ]; then
479 echo \\\$num instance of $dname;
484 check_gss_daemon_facet() {
488 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
489 if [ $num -ne 1 ]; then
490 echo "$num instance of $dname on $facet"
499 echo Stopping $@ on $list
500 do_nodes $list "killall -2 $@ 2>/dev/null || true"
503 # start gss daemons on all nodes, or
504 # "daemon" on "list" if set
505 start_gss_daemons() {
509 if [ "$list" ] && [ "$daemon" ] ; then
510 echo "Starting gss daemon on nodes: $list"
511 do_nodes $list "$daemon" || return 8
515 local list=$(comma_list $(mdts_nodes))
517 echo "Starting gss daemon on mds: $list"
518 do_nodes $list "$LSVCGSSD -v" || return 1
520 do_nodes $list "$LGSSD -v" || return 2
523 list=$(comma_list $(osts_nodes))
524 echo "Starting gss daemon on ost: $list"
525 do_nodes $list "$LSVCGSSD -v" || return 3
526 # starting on clients
528 local clients=${CLIENTS:-`hostname`}
530 echo "Starting $LGSSD on clients $clients "
531 do_nodes $clients "$LGSSD -v" || return 4
534 # wait daemons entering "stable" status
538 # check daemons are running
540 list=$(comma_list $(mdts_nodes) $(osts_nodes))
541 check_gss_daemon_nodes $list lsvcgssd || return 5
543 list=$(comma_list $(mdts_nodes))
544 check_gss_daemon_nodes $list lgssd || return 6
547 check_gss_daemon_nodes $clients lgssd || return 7
552 local list=$(comma_list $(mdts_nodes))
554 send_sigint $list lsvcgssd lgssd
556 list=$(comma_list $(osts_nodes))
557 send_sigint $list lsvcgssd
559 list=${CLIENTS:-`hostname`}
560 send_sigint $list lgssd
565 if ! module_loaded ptlrpc_gss; then
566 load_module ptlrpc/gss/ptlrpc_gss
567 module_loaded ptlrpc_gss ||
568 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
570 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
572 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
573 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
581 # maybe cleanup credential cache?
587 local device=`mdsdevname $num`
588 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
594 local device=`ostdevname $num`
595 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
600 local dz=${1:-$DEBUG_SIZE}
602 if [ -f /sys/devices/system/cpu/possible ]; then
603 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
605 local cpus=$(getconf _NPROCESSORS_CONF)
608 # bug 19944, adjust size to be -gt num_possible_cpus()
609 # promise 2MB for every cpu at least
610 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
613 lctl set_param debug_mb=$dz
616 set_default_debug () {
617 local debug=${1:-"$PTLDEBUG"}
618 local subsys=${2:-"$SUBSYSTEM"}
619 local debug_size=${3:-$DEBUG_SIZE}
621 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
622 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
624 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
627 set_default_debug_nodes () {
630 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
631 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
635 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
636 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
639 set_default_debug_facet () {
641 local node=$(facet_active_host $facet)
642 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
644 set_default_debug_nodes $node
649 local facets=${1:-$(get_facets)}
652 for facet in ${facets//,/ }; do
653 mount_facet $facet || error "Restart of $facet failed!"
660 local dev=$(facet_active $facet)_dev
661 local opt=${facet}_opt
662 local mntpt=$(facet_mntpt $facet)
664 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
665 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
667 if [ $RC -ne 0 ]; then
668 echo "mount -t lustre $@ ${!dev} $mntpt"
669 echo "Start of ${!dev} on ${facet} failed ${RC}"
671 set_default_debug_facet $facet
673 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
674 [ -z "$label" ] && echo no label for ${!dev} && exit 1
675 eval export ${facet}_svc=${label}
676 echo Started ${label}
681 # start facet device options
687 eval export ${facet}_dev=${device}
688 eval export ${facet}_opt=\"$@\"
690 local varname=${facet}failover_dev
691 if [ -n "${!varname}" ] ; then
692 eval export ${facet}failover_dev=${!varname}
694 eval export ${facet}failover_dev=$device
697 local mntpt=$(facet_mntpt $facet)
698 do_facet ${facet} mkdir -p $mntpt
699 eval export ${facet}_MOUNT=$mntpt
709 local HOST=`facet_active_host $facet`
710 [ -z $HOST ] && echo stop: no host for $facet && return 0
712 local mntpt=$(facet_mntpt $facet)
713 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
714 if [ ${running} -ne 0 ]; then
715 echo "Stopping $mntpt (opts:$@) on $HOST"
716 do_facet ${facet} umount -d $@ $mntpt
719 # umount should block, but we should wait for unrelated obd's
720 # like the MGS or MGC to also stop.
721 wait_exit_ST ${facet}
724 # save quota version (both administrative and operational quotas)
725 # add an additional parameter if mountpoint is ever different from $MOUNT
726 quota_save_version() {
727 local fsname=${2:-$FSNAME}
729 local ver=$(tr -c -d "123" <<< $spec)
730 local type=$(tr -c -d "ug" <<< $spec)
732 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
734 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
736 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
738 local osts=$(get_facets OST)
739 for ost in ${osts//,/ }; do
741 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
745 # client could mount several lustre
747 local fsname=${1:-$FSNAME}
749 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
750 do_nodes $(comma_list $(osts_nodes)) \
751 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
755 restore_quota_type () {
756 local mntpt=${1:-$MOUNT}
757 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
758 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
761 quota_save_version $old_QUOTA_TYPE
767 # We need save the original quota_type params, and restore them after testing
769 # Suppose that quota type the same on mds and ost
770 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
771 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
772 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
773 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
774 export old_QUOTA_TYPE=$quota_type
775 quota_save_version $QUOTA_TYPE
777 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
778 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
781 local quota_usrs=$QUOTA_USERS
783 # get_filesystem_size
784 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
785 local blk_soft=$((disksz + 1024))
786 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
788 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
790 local i_hard=$((i_soft + i_soft / 20))
792 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
793 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
796 for usr in $quota_usrs; do
797 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
799 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
801 eval $cmd || error "$cmd FAILED!"
803 # display the quota status
804 echo "Quota settings for $usr : "
805 $LFS quota -v -u $usr $mntpt || true
812 local OPTIONS=${3:-$MOUNTOPT}
814 local device=$MGSNID:/$FSNAME
815 if [ -z "$mnt" -o -z "$FSNAME" ]; then
816 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
820 echo "Starting client: $client: $OPTIONS $device $mnt"
821 do_node $client mkdir -p $mnt
822 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
824 set_default_debug_nodes $client
837 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
838 if [ $running -ne 0 ]; then
839 echo "Stopping client $client $mnt (opts:$force)"
840 do_node $client lsof -t $mnt || need_kill=no
841 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
842 pids=$(do_node $client lsof -t $mnt | sort -u);
843 if [ -n $pids ]; then
844 do_node $client kill -9 $pids || true
848 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
849 if [ $busy -ne 0 ] ; then
850 echo "$mnt is still busy, wait one second" && sleep 1
851 do_node $client umount $force $mnt
856 # nodes is comma list
857 sanity_mount_check_nodes () {
863 # FIXME: assume that all cluster nodes run the same os
864 [ "$(uname)" = Linux ] || return 0
867 for mnt in $mnts ; do
868 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
869 mpts=\\\$(mount | grep -w -c $mnt);
870 if [ \\\$running -ne \\\$mpts ]; then
871 echo \\\$(hostname) env are INSANE!;
879 sanity_mount_check_servers () {
881 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
882 echo Checking servers environments
884 # FIXME: modify get_facets to display all facets wo params
885 local facets="$(get_facets OST),$(get_facets MDS),mgs"
889 for facet in ${facets//,/ }; do
890 node=$(facet_host ${facet})
891 mntpt=$(facet_mntpt $facet)
892 sanity_mount_check_nodes $node $mntpt ||
893 { error "server $node environments are insane!"; return 1; }
897 sanity_mount_check_clients () {
898 local clients=${1:-$CLIENTS}
899 local mntpt=${2:-$MOUNT}
900 local mntpt2=${3:-$MOUNT2}
902 [ -z $clients ] && clients=$(hostname)
903 echo Checking clients $clients environments
905 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
906 error "clients environments are insane!"
909 sanity_mount_check () {
910 sanity_mount_check_servers || return 1
911 sanity_mount_check_clients || return 2
914 # mount clients if not mouted
915 zconf_mount_clients() {
918 local OPTIONS=${3:-$MOUNTOPT}
920 local device=$MGSNID:/$FSNAME
921 if [ -z "$mnt" -o -z "$FSNAME" ]; then
922 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
926 echo "Starting client $clients: $OPTIONS $device $mnt"
929 running=\\\$(mount | grep -c $mnt' ');
931 if [ \\\$running -eq 0 ] ; then
933 mount -t lustre $OPTIONS $device $mnt;
936 exit \\\$rc" || return ${PIPESTATUS[0]}
938 echo "Started clients $clients: "
939 do_nodes $clients "mount | grep -w $mnt"
941 set_default_debug_nodes $clients
946 zconf_umount_clients() {
953 echo "Stopping clients: $clients $mnt (opts:$force)"
954 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
955 if [ \\\$running -ne 0 ] ; then
956 echo Stopping client \\\$(hostname) $mnt opts:$force;
957 lsof $mnt || need_kill=no;
958 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
959 pids=\\\$(lsof -t $mnt | sort -u);
960 if [ -n \\\"\\\$pids\\\" ]; then
964 while umount $force $mnt 2>&1 | grep -q "busy"; do
965 echo "$mnt is still busy, wait one second" && sleep 1;
972 echo + $POWER_DOWN $node
976 shutdown_node_hard () {
978 local attempts=$SHUTDOWN_ATTEMPTS
980 for i in $(seq $attempts) ; do
983 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
984 echo "waiting for $host to fail attempts=$attempts"
985 [ $i -lt $attempts ] || \
986 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
992 local mnt=${2:-$MOUNT}
995 if [ "$FAILURE_MODE" = HARD ]; then
996 shutdown_node_hard $client
998 zconf_umount_clients $client $mnt -f
1004 local facets="$(get_facets OST),$(get_facets MDS)"
1007 combined_mgs_mds || facets="$facets,mgs"
1009 for facet in ${facets//,/ }; do
1010 if [ $(facet_active_host $facet) == $host ]; then
1011 affected="$affected $facet"
1015 echo $(comma_list $affected)
1020 local host=${2:-$(facet_host $facet)}
1022 local label=$(convert_facet2label $facet)
1023 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1026 facets_up_on_host () {
1028 local facets=$(facets_on_host $host)
1031 for facet in ${facets//,/ }; do
1032 if $(facet_up $facet $host); then
1033 affected_up="$affected_up $facet"
1037 echo $(comma_list $affected_up)
1043 if [ "$FAILURE_MODE" = HARD ]; then
1044 shutdown_node_hard $(facet_active_host $facet)
1052 echo + $POWER_UP $node
1065 if [ "$FAILURE_MODE" = HARD ]; then
1066 reboot_node $(facet_active_host $facet)
1074 if [ "$FAILURE_MODE" = HARD ]; then
1084 for facet in ${facets//,/ }; do
1085 hosts=$(expand_list $hosts $(facet_host $facet) )
1091 _check_progs_installed () {
1095 for prog in $progs; do
1096 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1097 echo $prog missing on $(hostname)
1104 check_progs_installed () {
1108 do_rpc_nodes $nodes _check_progs_installed $@
1111 # recovery-scale functions
1113 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1116 start_client_load() {
1119 local var=$(node_var_name $client)_load
1120 eval export ${var}=$load
1122 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1123 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1124 END_RUN_FILE=$END_RUN_FILE \
1125 LOAD_PID_FILE=$LOAD_PID_FILE \
1126 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1127 TESTNAME=$TESTNAME \
1128 DBENCH_LIB=$DBENCH_LIB \
1129 DBENCH_SRC=$DBENCH_SRC \
1132 log "Started client load: ${load} on $client"
1134 # get the children process IDs
1135 local pids=$(ps --ppid $ppid -o pid= | xargs)
1136 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1140 start_client_loads () {
1141 local -a clients=(${1//,/ })
1142 local numloads=${#CLIENT_LOADS[@]}
1145 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1146 testnum=$((nodenum % numloads))
1147 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1149 # bug 22169: wait the background threads to start
1153 # only for remote client
1154 check_client_load () {
1156 local var=$(node_var_name $client)_load
1157 local TESTLOAD=run_${!var}.sh
1159 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1161 # bug 18914: try to connect several times not only when
1162 # check ps, but while check_catastrophe also
1165 while [ $RC = 254 -a $tries -gt 0 ]; do
1169 if ! check_catastrophe $client; then
1171 if [ $RC -eq 254 ]; then
1172 # FIXME: not sure how long we shuold sleep here
1176 echo "check catastrophe failed: RC=$RC "
1180 # We can continue try to connect if RC=254
1181 # Just print the warning about this
1182 if [ $RC = 254 ]; then
1183 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1186 # see if the load is still on the client
1189 while [ $RC = 254 -a $tries -gt 0 ]; do
1193 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1198 if [ $RC = 254 ]; then
1199 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1200 # see if we can diagnose a bit why this is
1205 check_client_loads () {
1206 local clients=${1//,/ }
1210 for client in $clients; do
1211 check_client_load $client
1213 if [ "$rc" != 0 ]; then
1214 log "Client load failed on node $client, rc=$rc"
1220 restart_client_loads () {
1221 local clients=${1//,/ }
1222 local expectedfail=${2:-""}
1226 for client in $clients; do
1227 check_client_load $client
1229 if [ "$rc" != 0 -a "$expectedfail" ]; then
1230 local var=$(node_var_name $client)_load
1231 start_client_load $client ${!var}
1232 echo "Restarted client load ${!var}: on $client. Checking ..."
1233 check_client_load $client
1235 if [ "$rc" != 0 ]; then
1236 log "Client load failed to restart on node $client, rc=$rc"
1237 # failure one client load means test fail
1238 # we do not need to check other
1247 # Start vmstat and save its process ID in a file.
1252 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1255 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1256 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1259 # Display the nodes on which client loads failed.
1260 print_end_run_file() {
1264 [ -s $file ] || return 0
1266 echo "Found the END_RUN_FILE file: $file"
1269 # A client load will stop if it finds the END_RUN_FILE file.
1270 # That does not mean the client load actually failed though.
1271 # The first node in END_RUN_FILE is the one we are interested in.
1274 if [ -n "$node" ]; then
1275 local var=$(node_var_name $node)_load
1277 local prefix=$TESTLOG_PREFIX
1278 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1279 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1280 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1282 echo "Client load ${!var} failed on node $node:"
1288 # Stop the process which had its PID saved in a file.
1293 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1295 do_nodes $nodes "test -f $pid_file &&
1296 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1299 # Stop all client loads.
1300 stop_client_loads() {
1301 local nodes=${1:-$CLIENTS}
1304 # stop the client loads
1305 stop_process $nodes $pid_file
1307 # clean up the processes that started them
1308 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1310 # End recovery-scale functions
1312 # verify that lustre actually cleaned up properly
1314 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1315 error "LBUG/LASSERT detected"
1316 BUSY=`dmesg | grep -i destruct || true`
1317 if [ "$BUSY" ]; then
1319 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1323 check_mem_leak || exit 204
1325 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1326 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1328 if module_loaded lnet || module_loaded libcfs; then
1329 echo "$0: modules still loaded..." 1>&2
1347 RESULT=$(do_node $node "$TEST")
1348 if [ "$RESULT" == "$FINAL" ]; then
1349 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1350 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1353 [ $WAIT -ge $MAX ] && break
1354 [ $((WAIT % print)) -eq 0 ] &&
1355 echo "Waiting $((MAX - WAIT)) secs for update"
1356 WAIT=$((WAIT + sleep))
1359 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1363 wait_update_facet () {
1365 wait_update $(facet_active_host $facet) "$@"
1368 wait_delete_completed () {
1369 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1370 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1374 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1376 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1377 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1378 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1379 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1383 echo "Delete is not completed in $MAX_WAIT sec"
1390 # we can use "for" here because we are waiting the slowest
1391 for host in ${hostlist//,/ }; do
1392 check_network "$host" 900
1394 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1401 for facet in ${facetlist//,/ }; do
1402 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1404 wait_for_host $hostlist
1407 _wait_recovery_complete () {
1410 # Use default policy if $2 is not passed by caller.
1411 local MAX=${2:-$(max_recovery_time)}
1416 while [ $WAIT -lt $MAX ]; do
1417 STATUS=$(lctl get_param -n $param | grep status)
1419 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1422 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1424 echo "$param recovery not done in $MAX sec. $STATUS"
1428 wait_recovery_complete () {
1431 # with an assumption that at_max is the same on all nodes
1432 local MAX=${2:-$(max_recovery_time)}
1435 if [ "$FAILURE_MODE" = HARD ]; then
1436 facets=$(facets_on_host $(facet_active_host $facet))
1438 echo affected facets: $facets
1440 # we can use "for" here because we are waiting the slowest
1441 for facet in ${facets//,/ }; do
1442 local var_svc=${facet}_svc
1443 local param="*.${!var_svc}.recovery_status"
1445 local host=$(facet_active_host $facet)
1446 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1450 wait_mds_ost_sync () {
1451 # just because recovery is done doesn't mean we've finished
1452 # orphan cleanup. Wait for llogs to get synchronized.
1453 echo "Waiting for orphan cleanup..."
1454 # MAX value includes time needed for MDS-OST reconnection
1455 local MAX=$(( TIMEOUT * 2 ))
1457 while [ $WAIT -lt $MAX ]; do
1458 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1459 "$LCTL get_param -n obdfilter.*.mds_sync"))
1462 for ((i=0; i<${#sync[@]}; i++)); do
1463 [ ${sync[$i]} -eq 0 ] && continue
1464 # there is a not finished MDS-OST synchronization
1468 sleep 2 # increase waiting time and cover statfs cache
1469 [ ${con} -eq 1 ] && return 0
1470 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1473 echo "$facet recovery not done in $MAX sec. $STATUS"
1477 wait_destroy_complete () {
1478 echo "Waiting for destroy to be done..."
1479 # MAX value shouldn't be big as this mean server responsiveness
1480 # never increase this just to make test pass but investigate
1481 # why it takes so long time
1484 while [ $WAIT -lt $MAX ]; do
1485 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1487 for ((i=0; i<${#RPCs[@]}; i++)); do
1488 [ ${RPCs[$i]} -eq 0 ] && continue
1489 # there are still some destroy RPCs in flight
1494 [ ${con} -eq 1 ] && return 0 # done waiting
1495 echo "Waiting $WAIT secs for destroys to be done."
1498 echo "Destroys weren't done in $MAX sec."
1508 # conf-sanity 31 takes a long time cleanup
1509 while [ $WAIT -lt 300 ]; do
1510 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1511 [ -z "${running}" ] && return 0
1512 echo "waited $WAIT for${running}"
1513 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1515 WAIT=$((WAIT + INTERVAL))
1517 echo "service didn't stop after $WAIT seconds. Still running:"
1522 wait_remote_prog () {
1528 [ "$PDSH" = "no_dsh" ] && return 0
1530 while [ $WAIT -lt $2 ]; do
1531 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1532 [ -z "${running}" ] && return 0 || true
1533 echo "waited $WAIT for: "
1535 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1537 WAIT=$((WAIT + INTERVAL))
1539 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1540 [ -z "$pids" ] && return 0
1541 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1542 # FIXME: not portable
1543 for pid in $pids; do
1544 cat /proc/${pid}/status || true
1545 cat /proc/${pid}/wchan || true
1547 kill -9 $pid || true
1556 # not every config has many clients
1558 if [ ! -z "$CLIENTS" ]; then
1559 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1561 stat -f $MOUNT > /dev/null
1567 # usually checked on particular client or locally
1569 if [ ! -z "$client" ]; then
1570 $PDSH $client "stat -f $MOUNT" > /dev/null
1572 stat -f $MOUNT > /dev/null
1580 client_reconnect() {
1581 uname -n >> $MOUNT/recon
1582 if [ -z "$CLIENTS" ]; then
1583 df $MOUNT; uname -n >> $MOUNT/recon
1585 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1587 echo Connected clients:
1589 ls -l $MOUNT/recon > /dev/null
1593 affected_facets () {
1596 local host=$(facet_active_host $facet)
1597 local affected=$facet
1599 if [ "$FAILURE_MODE" = HARD ]; then
1600 affected=$(facets_up_on_host $host)
1608 local host=$(facet_active_host $facet)
1610 echo "Failing $facet on node $host"
1612 # Make sure the client data is synced to disk. LU-924
1614 # We don't write client data synchrnously (to avoid flooding sync writes
1615 # when there are many clients connecting), so if the server reboots before
1616 # the client data reachs disk, the client data will be lost and the client
1617 # will be evicted after recovery, which is not what we expected.
1618 do_facet $facet "sync; sync; sync"
1620 local affected=$(affected_facets $facet)
1622 shutdown_facet $facet
1624 echo affected facets: $affected
1626 [ -n "$sleep_time" ] && sleep $sleep_time
1630 change_active $affected
1632 wait_for_facet $affected
1633 # start mgs first if it is affected
1634 if ! combined_mgs_mds && list_member $affected mgs; then
1635 mount_facet mgs || error "Restart of mgs failed"
1637 # FIXME; has to be changed to mount all facets concurrently
1638 affected=$(exclude_items_from_list $affected mgs)
1639 mount_facets $affected
1648 do_facet $facet "sync; sync; sync"
1651 # make sure there will be no seq change
1652 local clients=${CLIENTS:-$HOSTNAME}
1653 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1655 local svc=${facet}_svc
1656 do_facet $facet $LCTL --device %${!svc} notransno
1657 do_facet $facet $LCTL --device %${!svc} readonly
1658 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1659 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1662 replay_barrier_nodf() {
1663 local facet=$1 echo running=${running}
1664 do_facet $facet "sync; sync; sync"
1665 local svc=${facet}_svc
1666 echo Replay barrier on ${!svc}
1667 do_facet $facet $LCTL --device %${!svc} notransno
1668 do_facet $facet $LCTL --device %${!svc} readonly
1669 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1670 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1673 replay_barrier_nosync() {
1674 local facet=$1 echo running=${running}
1675 local svc=${facet}_svc
1676 echo Replay barrier on ${!svc}
1677 do_facet $facet $LCTL --device %${!svc} notransno
1678 do_facet $facet $LCTL --device %${!svc} readonly
1679 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1680 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1683 mds_evict_client() {
1684 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1685 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1688 ost_evict_client() {
1689 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1690 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1694 facet_failover $* || error "failover: $?"
1695 clients_up || error "post-failover df: $?"
1700 facet_failover $facet
1706 change_active $facet
1707 wait_for_facet $facet
1708 mount_facet $facet -o abort_recovery
1709 clients_up || echo "first df failed: $?"
1710 clients_up || error "post-failover df: $?"
1714 echo There is no lmc. This is mountconf, baby.
1718 host_nids_address() {
1722 if [ -n "$kind" ]; then
1723 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1725 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1731 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1737 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1738 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1739 if [ -z "$ID" ]; then
1740 echo "Could not get a ptl id for $1..."
1749 h2name_or_ip "$1" "tcp"
1754 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1755 if type __h2elan >/dev/null 2>&1; then
1758 ID=`echo $1 | sed 's/[^0-9]*//g'`
1766 h2name_or_ip "$1" "o2ib"
1770 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1771 # expressions format. As a bonus we can then just pass in those variables
1772 # to pdsh. What this function does is take a HOSTLIST type string and
1773 # expand it into a space deliminated list for us.
1781 [ -z "$hostlist" ] && return
1783 # Translate the case of [..],..,[..] to [..] .. [..]
1784 list="${hostlist/],/] }"
1786 [[ "$front" == *,* ]] && {
1789 list=${list/${old}/${new}}
1792 for item in $list; do
1793 # Test if we have any []'s at all
1794 if [ "$item" != "${item/\[/}" ]; then {
1795 # Expand the [*] into list
1799 if [ "$name" != "$item" ]; then
1800 group=${item#$name[*}
1803 for range in ${group//,/ }; do
1807 # Number of leading zeros
1810 end=$(echo $end | sed 's/0*//')
1811 [[ -z "$end" ]] && end=0
1812 [[ $padlen2 -gt $padlen ]] && {
1813 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1816 begin=$(echo $begin | sed 's/0*//')
1817 [ -z $begin ] && begin=0
1819 for num in $(seq -f "%0${padlen}g" $begin $end); do
1820 value="${name#*,}${num}${back}"
1821 [ "$value" != "${value/\[/}" ] && {
1822 value=$(hostlist_expand "$value")
1824 myList="$myList $value"
1829 myList="$myList $item"
1832 myList=${myList//,/ }
1833 myList=${myList:1} # Remove first character which is a space
1835 # Filter any duplicates without sorting
1837 myList="${list%% *}"
1839 while [[ "$list" != ${myList##* } ]]; do
1840 list=${list//${list%% *} /}
1841 myList="$myList ${list%% *}"
1843 myList="${myList%* }";
1845 # We can select an object at a offset in the list
1848 for item in $myList; do
1850 [ $cnt -eq $offset ] && {
1854 [ $(get_node_count $myList) -ne 1 ] && myList=""
1862 [ "$facet" == client ] && echo -n $HOSTNAME && return
1863 varname=${facet}_HOST
1864 if [ -z "${!varname}" ]; then
1865 if [ "${facet:0:3}" == "ost" ]; then
1866 eval ${facet}_HOST=${ost_HOST}
1874 local activevar=${facet}active
1876 if [ -f $TMP/${facet}active ] ; then
1877 source $TMP/${facet}active
1880 active=${!activevar}
1881 if [ -z "$active" ] ; then
1888 facet_active_host() {
1890 local active=`facet_active $facet`
1891 if [ "$facet" == client ]; then
1894 echo `facet_host $active`
1902 facetlist=$(exclude_items_from_list $facetlist mgs)
1904 for facet in ${facetlist//,/ }; do
1905 local failover=${facet}failover
1906 local host=`facet_host $failover`
1907 [ -z "$host" ] && return
1909 local curactive=`facet_active $facet`
1910 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1911 eval export ${facet}active=$facet
1913 eval export ${facet}active=$failover
1915 # save the active host for this facet
1916 local activevar=${facet}active
1917 echo "$activevar=${!activevar}" > $TMP/$activevar
1918 [[ $facet = mds1 ]] && combined_mgs_mds && \
1919 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1920 local TO=`facet_active_host $facet`
1921 echo "Failover $facet to $TO"
1927 # do not stripe off hostname if verbose, bug 19215
1928 if [ x$1 = x--verbose ]; then
1936 if [ "$HOST" = "$HOSTNAME" ]; then
1938 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1939 echo "cannot run remote command on $HOST with $myPDSH"
1943 echo "CMD: $HOST $@" >&2
1944 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1947 if [ "$myPDSH" = "rsh" ]; then
1948 # we need this because rsh does not return exit code of an executed command
1949 local command_status="$TMP/cs"
1950 rsh $HOST ":> $command_status"
1951 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1952 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1953 echo command failed >$command_status"
1954 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1959 # print HOSTNAME for myPDSH="no_dsh"
1960 if [[ $myPDSH = no_dsh ]]; then
1961 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1963 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1966 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1968 return ${PIPESTATUS[0]}
1972 do_node --verbose "$@"
1975 single_local_node () {
1976 [ "$1" = "$HOSTNAME" ]
1979 # Outputs environment variable assignments that should be passed to remote nodes
1984 for var in ${!MODOPTS_*}; do
1986 echo "${var}=\"$value\""
1992 # do not stripe off hostname if verbose, bug 19215
1993 if [ x$1 = x--verbose ]; then
2001 if single_local_node $rnodes; then
2003 do_nodev $rnodes "$@"
2005 do_node $rnodes "$@"
2010 # This is part from do_node
2013 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2014 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2017 echo "CMD: $rnodes $@" >&2
2018 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2021 # do not replace anything from pdsh output if -N is used
2022 # -N Disable hostname: prefix on lines of output.
2023 if $verbose || [[ $myPDSH = *-N* ]]; then
2024 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2026 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2028 return ${PIPESTATUS[0]}
2034 local HOST=`facet_active_host $facet`
2035 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2040 do_nodes --verbose "$@"
2046 # make sure its not already running
2048 rm -f $TMP/${facet}active
2049 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2050 do_facet ${facet} $MKFS $*
2056 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2057 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
2064 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2065 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
2071 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2073 local var=${facet}_MOUNT
2074 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2083 # make sure we are using the primary server, so test-framework will
2084 # be able to clean up properly.
2085 activemds=`facet_active mds1`
2086 if [ $activemds != "mds1" ]; then
2090 local clients=$CLIENTS
2091 [ -z $clients ] && clients=$(hostname)
2093 zconf_umount_clients $clients $MOUNT "$*" || true
2094 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2096 [ "$CLIENTONLY" ] && return
2097 # The add fn does rm ${facet}active file, this would be enough
2098 # if we use do_facet <facet> only after the facet added, but
2099 # currently we use do_facet mds in local.sh
2100 for num in `seq $MDSCOUNT`; do
2102 rm -f ${TMP}/mds${num}active
2104 combined_mgs_mds && rm -f $TMP/mgsactive
2106 for num in `seq $OSTCOUNT`; do
2108 rm -f $TMP/ost${num}active
2111 if ! combined_mgs_mds ; then
2118 cleanup_echo_devs () {
2119 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2121 for dev in $devs; do
2122 $LCTL --device $dev cleanup
2123 $LCTL --device $dev detach
2128 nfs_client_mode && return
2137 combined_mgs_mds () {
2138 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2144 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2145 local optvar=${tgt}_MKFS_OPTS
2146 local opt=${!optvar}
2148 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2149 [[ $facet = mgs ]] && echo $opt && return
2152 # --failnode options
2153 local var=${facet}failover_HOST
2154 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2155 local failnode=$(h2$NETTYPE ${!var})
2156 failnode="--failnode=$failnode"
2157 # options does not contain
2158 # or contains wrong --failnode=
2159 if [[ $opt != *${failnode}* ]]; then
2160 opt=$(echo $opt | sed 's/--failnode=.* / /')
2161 opt="$opt $failnode"
2167 # no additional mkfs mds "--mgsnode" option for this configuration
2168 if [[ $facet = mds ]] && combined_mgs_mds; then
2173 # additional mkfs "--mgsnode"
2174 local mgsnode="--mgsnode=$MGSNID"
2175 opt=${opt//$mgsnode }
2176 for nid in ${MGSNID//:/ }; do
2177 local mgsnode="--mgsnode=$nid"
2178 # options does not contain
2180 if [[ $opt != *${mgsnode}" "* ]]; then
2181 opt="$opt --mgsnode=$nid"
2189 if [ "$IAMDIR" == "yes" ]; then
2190 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2193 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2196 # We need ldiskfs here, may as well load them all
2198 [ "$CLIENTONLY" ] && return
2199 echo Formatting mgs, mds, osts
2200 if ! combined_mgs_mds ; then
2201 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2204 for num in `seq $MDSCOUNT`; do
2205 echo "Format mds$num: $(mdsdevname $num)"
2207 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2209 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2213 # the ost-s could have different OST_MKFS_OPTS
2214 # because of different failnode-s
2215 for num in `seq $OSTCOUNT`; do
2216 echo "Format ost$num: $(ostdevname $num)"
2218 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2220 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2226 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2230 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2234 # 0: success, the old identity set already.
2235 # 1: success, the old identity does not set.
2240 local j=`expr $num - 1`
2241 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2243 if [ -z "$MDT" ]; then
2247 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2250 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2252 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2255 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2257 if [ $old = "NONE" ]; then
2266 zconf_umount `hostname` $1 || error "umount failed"
2267 zconf_mount `hostname` $1 || error "mount failed"
2270 writeconf_facet () {
2274 do_facet $facet "$TUNEFS --writeconf $dev"
2278 for num in `seq $MDSCOUNT`; do
2279 DEVNAME=$(mdsdevname $num)
2280 writeconf_facet mds$num $DEVNAME
2283 for num in `seq $OSTCOUNT`; do
2284 DEVNAME=$(ostdevname $num)
2285 writeconf_facet ost$num $DEVNAME
2290 nfs_client_mode && return
2292 sanity_mount_check ||
2293 error "environments are insane!"
2297 if [ -z "$CLIENTONLY" ]; then
2298 echo Setup mgs, mdt, osts
2299 echo $WRITECONF | grep -q "writeconf" && \
2301 if ! combined_mgs_mds ; then
2302 start mgs $MGSDEV $MGS_MOUNT_OPTS
2305 for num in `seq $MDSCOUNT`; do
2306 DEVNAME=$(mdsdevname $num)
2307 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2309 # We started mds, now we should set failover variables properly.
2310 # Set mds${num}failover_HOST if it is not set (the default failnode).
2311 local varname=mds${num}failover_HOST
2312 if [ -z "${!varname}" ]; then
2313 eval mds${num}failover_HOST=$(facet_host mds$num)
2316 if [ $IDENTITY_UPCALL != "default" ]; then
2317 switch_identity $num $IDENTITY_UPCALL
2320 for num in `seq $OSTCOUNT`; do
2321 DEVNAME=$(ostdevname $num)
2322 start ost$num $DEVNAME $OST_MOUNT_OPTS
2324 # We started ost$num, now we should set ost${num}failover variable properly.
2325 # Set ost${num}failover_HOST if it is not set (the default failnode).
2326 varname=ost${num}failover_HOST
2327 if [ -z "${!varname}" ]; then
2328 eval ost${num}failover_HOST=$(facet_host ost${num})
2336 # wait a while to allow sptlrpc configuration be propogated to targets,
2337 # only needed when mounting new target devices.
2342 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2344 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2347 if [ "$MOUNT_2" ]; then
2348 mount_client $MOUNT2
2349 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2354 # by remounting mdt before ost, initial connect from mdt to ost might
2355 # timeout because ost is not ready yet. wait some time to its fully
2356 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2357 # by a context negotiation rpc with $TIMEOUT.
2358 # FIXME better by monitoring import status.
2361 sleep $((TIMEOUT + 5))
2367 mounted_lustre_filesystems() {
2368 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2371 init_facet_vars () {
2372 [ "$CLIENTONLY" ] && return 0
2379 eval export ${facet}_dev=${device}
2380 eval export ${facet}_opt=\"$@\"
2382 local dev=${facet}_dev
2383 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2384 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2386 eval export ${facet}_svc=${label}
2388 local varname=${facet}failover_HOST
2389 if [ -z "${!varname}" ]; then
2390 eval $varname=$(facet_host $facet)
2393 # ${facet}failover_dev is set in cfg file
2394 varname=${facet}failover_dev
2395 if [ -n "${!varname}" ] ; then
2396 eval export ${facet}failover_dev=${!varname}
2398 eval export ${facet}failover_dev=$device
2401 # get mount point of already mounted device
2402 # is facet_dev is already mounted then use the real
2403 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2404 # i.e. ${facet}_MOUNT if specified by user or default
2405 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2406 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2407 if [ -z $mntpt ]; then
2408 mntpt=$(facet_mntpt $facet)
2410 eval export ${facet}_MOUNT=$mntpt
2413 init_facets_vars () {
2416 if ! remote_mds_nodsh; then
2417 for num in `seq $MDSCOUNT`; do
2418 DEVNAME=`mdsdevname $num`
2419 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2423 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2425 remote_ost_nodsh && return
2427 for num in `seq $OSTCOUNT`; do
2428 DEVNAME=`ostdevname $num`
2429 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2433 osc_ensure_active () {
2438 while [ $period -lt $timeout ]; do
2439 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2440 if [ $count -eq 0 ]; then
2444 echo "There are $count OST are inactive, wait $period seconds, and try again"
2446 period=$((period+3))
2449 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2452 init_param_vars () {
2453 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2454 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2455 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2456 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2460 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2462 log "Using TIMEOUT=$TIMEOUT"
2464 osc_ensure_active $SINGLEMDS $TIMEOUT
2465 osc_ensure_active client $TIMEOUT
2467 if [ $QUOTA_AUTO -ne 0 ]; then
2468 if [ "$ENABLE_QUOTA" ]; then
2469 echo "enable quota as required"
2470 setup_quota $MOUNT || return 2
2472 echo "disable quota as required"
2473 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2480 nfs_client_mode () {
2481 if [ "$NFSCLIENT" ]; then
2482 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2483 local clients=$CLIENTS
2484 [ -z $clients ] && clients=$(hostname)
2486 # FIXME: remove hostname when 19215 fixed
2487 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2488 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2489 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2490 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2492 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2498 check_config_client () {
2501 local mounted=$(mount | grep " $mntpt ")
2502 if [ "$CLIENTONLY" ]; then
2504 # CLIENTONLY should not depend on *_HOST settings
2505 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2506 # in theory someone could create a new,
2507 # client-only config file that assumed lustre was already
2508 # configured and didn't set the MGSNID. If MGSNID is not set,
2509 # then we should use the mgs nid currently being used
2510 # as the default value. bug 18021
2511 [[ x$MGSNID = x ]] &&
2514 if [[ x$mgc != xMGC$MGSNID ]]; then
2515 if [ "$mgs_HOST" ]; then
2516 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2517 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2518 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2524 local myMGS_host=$mgs_HOST
2525 if [ "$NETTYPE" = "ptl" ]; then
2526 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2529 echo Checking config lustre mounted on $mntpt
2530 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2531 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2533 # if [ "$mgshost" != "$myMGS_host" ]; then
2534 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2535 # Please use correct config or set mds_HOST correctly!"
2540 check_config_clients () {
2541 local clients=${CLIENTS:-$HOSTNAME}
2544 nfs_client_mode && return
2546 do_rpc_nodes $clients check_config_client $mntpt
2548 sanity_mount_check ||
2549 error "environments are insane!"
2553 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2554 local cltimeout=$(lctl get_param -n timeout)
2555 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2556 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2563 [ -z $mntpt ] && return 1
2564 local mounted=$(mounted_lustre_filesystems)
2566 echo $mounted' ' | grep -w -q $mntpt' '
2570 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2574 # empty lustre filesystem may have empty directories lost+found and .lustre
2576 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2577 -print | wc -l) = 1 ] || return 1
2578 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2579 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2583 check_and_setup_lustre() {
2584 nfs_client_mode && return
2586 local MOUNTED=$(mounted_lustre_filesystems)
2590 # both MOUNT and MOUNT2 are not mounted
2591 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2592 [ "$REFORMAT" ] && formatall
2593 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2595 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2596 export I_MOUNTED=yes
2600 elif is_mounted $MOUNT2; then
2602 # MOUNT2 is mounted, while MOUNT_2 is not set
2603 if ! [ "$MOUNT_2" ]; then
2604 cleanup_mount $MOUNT2
2605 export I_UMOUNTED2=yes
2608 # MOUNT2 is mounted, MOUNT_2 is set
2610 # FIXME: what to do if check_config failed?
2612 # 1) remote client has mounted other Lustre fs ?
2613 # 2) it has insane env ?
2614 # let's try umount MOUNT2 on all clients and mount it again:
2615 if ! check_config_clients $MOUNT2; then
2616 cleanup_mount $MOUNT2
2617 restore_mount $MOUNT2
2618 export I_MOUNTED2=yes
2623 # MOUNT is mounted MOUNT2 is not mounted
2624 elif [ "$MOUNT_2" ]; then
2625 restore_mount $MOUNT2
2626 export I_MOUNTED2=yes
2630 # FIXME: what to do if check_config failed?
2632 # 1) remote client has mounted other Lustre fs?
2633 # 2) lustre is mounted on remote_clients atall ?
2634 check_config_clients $MOUNT
2638 set_default_debug_nodes $(comma_list $(nodes_list))
2644 if [ "$ONLY" == "setup" ]; then
2650 local clients=${CLIENTS:-$HOSTNAME}
2653 zconf_mount_clients $clients $mntpt
2657 local clients=${CLIENTS:-$HOSTNAME}
2660 zconf_umount_clients $clients $mntpt
2663 cleanup_and_setup_lustre() {
2664 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2665 lctl set_param debug=0 || true
2667 if [ "$ONLY" == "cleanup" ]; then
2671 check_and_setup_lustre
2674 # Get all of the server target devices from a given server node and type.
2683 mdt) obd_type="osd" ;;
2684 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2685 *) echo "invalid server type" && return 1 ;;
2688 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2689 for dev in $devs; do
2691 *loop*) do_node $node "losetup $dev" | \
2692 sed -e "s/.*(//" -e "s/).*//" ;;
2698 # Get all of the server target devices.
2703 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2707 for node in $(osts_nodes); do
2708 OSTDEVS[i]=$(get_mnt_devs $node ost)
2713 # Run e2fsck on MDT or OST device.
2719 df > /dev/null # update statfs data on disk
2720 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2723 do_node $node $cmd || rc=$?
2724 [ $rc -le $FSCK_MAX_ERR ] || \
2725 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2729 # verify a directory is shared among nodes.
2730 check_shared_dir() {
2733 [ -z "$dir" ] && return 1
2734 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2735 check_write_access $dir || return 1
2739 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2745 check_shared_dir $SHARED_DIRECTORY ||
2746 error "$SHARED_DIRECTORY isn't a shared directory"
2748 export MDSDB=$SHARED_DIRECTORY/mdsdb
2749 export OSTDB=$SHARED_DIRECTORY/ostdb
2751 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2753 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2758 for node in $(osts_nodes); do
2759 for dev in ${OSTDEVS[i]}; do
2760 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2761 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2762 ostidx=$((ostidx + 1))
2769 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2773 [ $rc -le $FSCK_MAX_ERR ] || \
2774 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2775 echo "lfsck finished with rc=$rc"
2777 rm -rvf $MDSDB* $OSTDB* || true
2781 check_and_cleanup_lustre() {
2782 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2788 if is_mounted $MOUNT; then
2789 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
2790 error "remove sub-test dirs failed"
2791 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2794 if [ "$I_UMOUNTED2" = "yes" ]; then
2795 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2798 if [ "$I_MOUNTED2" = "yes" ]; then
2799 cleanup_mount $MOUNT2
2802 if [ "$I_MOUNTED" = "yes" ]; then
2803 cleanupall -f || error "cleanup failed"
2811 wait_for_function () {
2814 # suppress fn both stderr and stdout
2815 if [ "$1" = "--quiet" ]; then
2817 quiet=" > /dev/null 2>&1"
2829 eval $fn $quiet && return 0
2831 wait=$((wait + sleep))
2832 [ $wait -lt $max ] || return 1
2833 echo waiting $fn, $((max - wait)) secs left ...
2843 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2844 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2845 echo "Network not available!"
2849 echo `date +"%H:%M:%S (%s)"` network interface is UP
2858 # the sed converts spaces to commas, but leaves the last space
2859 # alone, so the line doesn't end with a comma.
2860 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2866 echo $list | grep -qw $item
2869 # list, excluded are the comma separated lists
2870 exclude_items_from_list () {
2876 for item in ${excluded//,/ }; do
2877 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2879 echo $(comma_list $list)
2882 # list, expand are the comma separated lists
2884 local list=${1//,/ }
2885 local expand=${2//,/ }
2888 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2889 echo $(comma_list $expanded)
2892 testslist_filter () {
2893 local script=$LUSTRE/tests/${TESTSUITE}.sh
2895 [ -f $script ] || return 0
2897 local start_at=$START_AT
2898 local stop_at=$STOP_AT
2900 local var=${TESTSUITE//-/_}_START_AT
2901 [ x"${!var}" != x ] && start_at=${!var}
2902 var=${TESTSUITE//-/_}_STOP_AT
2903 [ x"${!var}" != x ] && stop_at=${!var}
2905 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2906 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2907 /^'${start_at}'$/ {flag = 0}
2908 {if (flag == 1) print $0}
2909 /^'${stop_at}'$/ { flag = 1 }'
2913 (cd `dirname $1`; echo $PWD/`basename $1`)
2917 local types=${1:-"OST MDS MGS"}
2921 for entry in $types; do
2922 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2923 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2926 MGS ) list="$list $name";;
2927 MDS|OST ) local count=${type}COUNT
2928 for ((i=1; i<=${!count}; i++)) do
2929 list="$list ${name}$i"
2931 * ) error "Invalid facet type"
2935 echo $(comma_list $list)
2938 ##################################
2939 # Adaptive Timeouts funcs
2942 # only check mds, we assume at_max is the same on all nodes
2943 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2944 if [ $at_max -eq 0 ]; then
2955 # suppose that all ost-s have the same $at value set
2956 [ $facet != "ost" ] || facet=ost1
2958 do_facet $facet "lctl get_param -n $at"
2972 if [ $facet == "ost" ]; then
2973 facet=$(get_facets OST)
2974 elif [ $facet == "mds" ]; then
2975 facet=$(get_facets MDS)
2977 hosts=$(expand_list $hosts $(facets_hosts $facet))
2980 do_nodes $hosts lctl set_param at_max=$at_max
2983 ##################################
2987 # OBD_FAIL_MDS_ALL_REQUEST_NET
2989 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2990 do_facet client "$1" || RC=$?
2991 do_facet $SINGLEMDS lctl set_param fail_loc=0
2996 # OBD_FAIL_MDS_ALL_REPLY_NET
2998 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2999 do_facet client "$@" || RC=$?
3000 do_facet $SINGLEMDS lctl set_param fail_loc=0
3004 drop_reint_reply() {
3005 # OBD_FAIL_MDS_REINT_NET_REP
3007 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3008 do_facet client "$@" || RC=$?
3009 do_facet $SINGLEMDS lctl set_param fail_loc=0
3014 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3016 do_facet ost1 lctl set_param fail_loc=0x214
3017 do_facet client "$1" || RC=$?
3018 do_facet client "sync"
3019 do_facet ost1 lctl set_param fail_loc=0
3023 drop_ldlm_cancel() {
3024 #define OBD_FAIL_LDLM_CANCEL 0x304
3026 do_facet client lctl set_param fail_loc=0x304
3027 do_facet client "$@" || RC=$?
3028 do_facet client lctl set_param fail_loc=0
3032 drop_bl_callback() {
3033 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3035 do_facet client lctl set_param fail_loc=0x305
3036 do_facet client "$@" || RC=$?
3037 do_facet client lctl set_param fail_loc=0
3042 #define OBD_FAIL_LDLM_REPLY 0x30c
3044 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3045 do_facet client "$@" || RC=$?
3046 do_facet $SINGLEMDS lctl set_param fail_loc=0
3054 echo "clearing fail_loc on $facet"
3055 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3058 set_nodes_failloc () {
3059 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3062 cancel_lru_locks() {
3063 $LCTL mark "cancel_lru_locks $1 start"
3064 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3065 $LCTL set_param -n $d=clear
3067 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3068 $LCTL mark "cancel_lru_locks $1 stop"
3073 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3074 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3075 echo "$DEFAULT_LRU_SIZE"
3080 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3083 lru_resize_disable()
3085 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3090 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3091 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3092 echo there is still data in page cache $FILE ?
3093 lctl get_param -n $FILE
3101 DEBUGSAVE="$(lctl get_param -n debug)"
3105 [ -n "$DEBUGSAVE" ] && \
3106 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3111 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3114 debug_size_restore() {
3115 [ -n "$DEBUG_SIZE_SAVED" ] && \
3116 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3120 start_full_debug_logging() {
3125 local DEBUG_SIZE=150
3127 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3128 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3131 stop_full_debug_logging() {
3136 ##################################
3138 ##################################
3141 local TYPE=${TYPE:-"FAIL"}
3144 # do not dump logs if $1=false
3145 if [ "x$1" = "xfalse" ]; then
3150 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3153 # We need to dump the logs on all nodes
3155 gather_logs $(comma_list $(nodes_list))
3159 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3160 echo "$@" > $LOGDIR/err
3165 local log=$TESTSUITELOG
3167 [ -f "$log" ] && grep -q FAIL: $log && status=1
3180 # use only if we are ignoring failures for this test, bugno required.
3181 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3182 # e.g. error_ignore 5494 "your message"
3184 local TYPE="IGNORE (bz$1)"
3190 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3195 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3196 [ "$ALWAYS_SKIPPED" ] && \
3197 skip_logged ${TESTNAME} "$@" || true
3198 [ "$TESTSUITELOG" ] && \
3199 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3202 build_test_filter() {
3203 EXCEPT="$EXCEPT $(testslist_filter)"
3205 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3209 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3210 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3211 [ "$EXCEPT_SLOW" ] && \
3212 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3213 for E in $EXCEPT; do
3214 eval EXCEPT_${E}=true
3216 for E in $ALWAYS_EXCEPT; do
3217 eval EXCEPT_ALWAYS_${E}=true
3219 for E in $EXCEPT_SLOW; do
3220 eval EXCEPT_SLOW_${E}=true
3222 for G in $GRANT_CHECK_LIST; do
3223 eval GCHECK_ONLY_${G}=true
3228 if [[ $1 = [a-z]* ]]; then
3235 # print a newline if the last test was skipped
3236 export LAST_SKIPPED=
3237 export ALWAYS_SKIPPED=
3239 # Main entry into test-framework. This is called with the name and
3240 # description of a test. The name is used to find the function to run
3241 # the test using "test_$name".
3243 # This supports a variety of methods of specifying specific test to
3244 # run or not run. These need to be documented...
3249 export base=`basetest $1`
3250 if [ ! -z "$ONLY" ]; then
3252 if [ ${!testname}x != x ]; then
3253 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3254 run_one_logged $1 "$2"
3258 if [ ${!testname}x != x ]; then
3259 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3260 run_one_logged $1 "$2"
3268 if [ ${!testname}x != x ]; then
3270 TESTNAME=test_$1 skip "skipping excluded test $1"
3273 testname=EXCEPT_$base
3274 if [ ${!testname}x != x ]; then
3276 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3279 testname=EXCEPT_ALWAYS_$1
3280 if [ ${!testname}x != x ]; then
3283 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3286 testname=EXCEPT_ALWAYS_$base
3287 if [ ${!testname}x != x ]; then
3290 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3293 testname=EXCEPT_SLOW_$1
3294 if [ ${!testname}x != x ]; then
3296 TESTNAME=test_$1 skip "skipping SLOW test $1"
3299 testname=EXCEPT_SLOW_$base
3300 if [ ${!testname}x != x ]; then
3302 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3308 run_one_logged $1 "$2"
3319 module_loaded lnet || load_modules
3331 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3336 strace -o $TMP/$1.strace -ttt $*
3338 log "FINISHED: $*: rc $RC"
3343 equals_msg $1 test complete, duration $2 sec
3344 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3345 echo duration $2 >>$TESTSUITELOG
3349 # Set TEST_STATUS here; will be used for logging the result
3350 if [ -f $LOGDIR/err ]; then
3355 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3359 local FFREE=$(do_node $SINGLEMDS \
3360 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3361 local FTOTAL=$(do_node $SINGLEMDS \
3362 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3364 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3368 echo -n "Resetting fail_loc on all nodes..."
3369 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3375 # Log a message (on all nodes) padded with "=" before and after.
3376 # Also appends a timestamp and prepends the testsuite name.
3379 EQUALS="===================================================================================================="
3381 msg="== ${TESTSUITE} $*"
3383 [[ $last != "=" && $last != " " ]] && msg="$msg "
3384 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3385 # always include at least == after the message
3386 log "$msg== $(date +"%H:%M:%S (%s)")"
3390 # Run a single test function and cleanup after it.
3392 # This function should be run in a subshell so the test func can
3393 # exit() without stopping the whole script.
3399 export tdir=d0.${TESTSUITE}/d${base}
3400 export TESTNAME=test_$testnum
3401 local SAVE_UMASK=`umask`
3404 banner "test $testnum: $message"
3405 test_${testnum} || error "test_$testnum failed with $?"
3408 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3409 check_catastrophe || error "LBUG/LASSERT detected"
3410 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3418 # Wrapper around run_one to ensure:
3419 # - test runs in subshell
3420 # - output of test is saved to separate log file for error reporting
3421 # - test result is saved to data file
3424 local BEFORE=`date +%s`
3426 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3427 local test_log=$LOGDIR/$name
3429 local SAVE_UMASK=`umask`
3433 log_sub_test_begin test_${1}
3434 (run_one $1 "$2") 2>&1 | tee -i $test_log
3435 local RC=${PIPESTATUS[0]}
3437 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3438 echo "test_$1 returned $RC" | tee $LOGDIR/err
3440 duration=$((`date +%s` - $BEFORE))
3441 pass "$1" "(${duration}s)"
3442 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3443 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3445 if [ -f $LOGDIR/err ]; then
3446 $FAIL_ON_ERROR && exit $RC
3455 # Print information of skipped tests to result.yml
3458 log_sub_test_begin $1
3459 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3463 (cd `dirname $1`; echo $PWD/`basename $1`)
3468 export base=`basetest $1`
3469 [ "$CHECK_GRANT" == "no" ] && return 0
3471 testname=GCHECK_ONLY_${base}
3472 [ ${!testname}x == x ] && return 0
3474 echo -n "checking grant......"
3476 local clients=$CLIENTS
3477 [ -z $clients ] && clients=$(hostname)
3479 # sync all the data and make sure no pending data on server
3480 do_nodes $clients sync
3483 client_grant=`do_nodes $clients \
3484 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3485 awk '{total += $1} END{print total}'`
3488 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3489 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3490 awk '{total += $1} END{print total}'`
3492 # check whether client grant == server grant
3493 if [ $client_grant -ne $server_grant ]; then
3494 echo "failed: client:${client_grant} server: ${server_grant}."
3495 do_nodes $(comma_list $(osts_nodes)) \
3496 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3497 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3500 echo "pass: client:${client_grant} server: ${server_grant}"
3505 ########################
3511 ost=`echo $1 | awk -F_ '{print $3}'`
3512 if [ -z $ost ]; then
3513 ost=`echo $1 | sed 's/-osc.*//'`
3518 ostuuid_from_index()
3520 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3523 ostname_from_index() {
3524 local uuid=$(ostuuid_from_index $1)
3528 index_from_ostuuid()
3530 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3533 mdtuuid_from_index()
3535 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3540 [ "$node" != "$(hostname)" ]
3546 for node in $(mdts_nodes); do
3547 remote_node $node && return 0
3554 [ "$CLIENTONLY" ] && return 0 || true
3555 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3560 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3561 MSKIPPED=1 && return 1
3568 for node in $(osts_nodes) ; do
3569 remote_node $node && return 0
3576 [ "$CLIENTONLY" ] && return 0 || true
3577 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3582 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3583 OSKIPPED=1 && return 1
3590 MGS=$(facet_host mgs)
3591 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3596 remote_mds_nodsh || remote_ost_nodsh || \
3597 $(single_local_node $(comma_list $(nodes_list)))
3603 for num in `seq $MDSCOUNT`; do
3604 MDSNODES="$MDSNODES $(facet_host mds$num)"
3606 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3612 remote_ost && remote_mds
3620 for facet in ${facets//,/ }; do
3621 if [ "$FAILURE_MODE" = HARD ]; then
3622 nodes="$nodes $(facet_active_host $facet)"
3624 nodes="$nodes $(facet_host $facet)"
3627 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3633 local facets=$(get_facets OST)
3634 local nodes=$(facets_nodes $facets)
3640 # FIXME. We need a list of clients
3641 local myNODES=$HOSTNAME
3644 # CLIENTS (if specified) contains the local client
3645 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3647 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3648 myNODES="$myNODES $(facets_nodes $(get_facets))"
3651 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3656 remote_nodes_list () {
3657 local rnodes=$(nodes_list)
3658 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3662 init_clients_lists () {
3663 # Sanity check: exclude the local client from RCLIENTS
3664 local clients=$(hostlist_expand "$RCLIENTS")
3665 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3667 # Sanity check: exclude the dup entries
3668 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3670 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3672 # Sanity check: exclude the dup entries from CLIENTS
3673 # for those configs which has SINGLCLIENT set to local client
3674 clients=$(for i in $clients; do echo $i; done | sort -u)
3676 CLIENTS=$(comma_list $clients)
3677 local -a remoteclients=($RCLIENTS)
3678 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3679 varname=CLIENT$((i + 2))
3680 eval $varname=${remoteclients[i]}
3683 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3686 get_random_entry () {
3689 rnodes=${rnodes//,/ }
3691 local -a nodes=($rnodes)
3692 local num=${#nodes[@]}
3693 local i=$((RANDOM * num * 2 / 65536))
3699 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3704 lctl get_param version | grep -q patchless
3708 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3713 echo $nodes | wc -w || true
3717 local nodes=$(osts_nodes)
3718 local osscount=$(get_node_count "$nodes")
3719 [ ! "$OSTCOUNT" = "$osscount" ]
3723 local nodes=$(mdts_nodes)
3724 local mdtcount=$(get_node_count "$nodes")
3725 [ ! "$MDSCOUNT" = "$mdtcount" ]
3728 generate_machine_file() {
3729 local nodes=${1//,/ }
3730 local machinefile=$2
3732 for node in $nodes; do
3733 echo $node >>$machinefile || \
3734 { echo "can not generate machinefile $machinefile" && return 1; }
3739 local file=$1/stripe
3741 $LFS getstripe -v $file || error
3745 setstripe_nfsserver () {
3748 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3749 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3751 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3753 do_nodev $nfsserver lfs setstripe "$@"
3756 check_runas_id_ret() {
3758 local myRUNAS_UID=$1
3759 local myRUNAS_GID=$2
3762 if [ -z "$myRUNAS" ]; then
3763 error_exit "myRUNAS command must be specified for check_runas_id"
3766 $myRUNAS krb5_login.sh || \
3767 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3769 mkdir $DIR/d0_runas_test
3771 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3772 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3773 rm -rf $DIR/d0_runas_test
3778 local myRUNAS_UID=$1
3779 local myRUNAS_GID=$2
3782 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3783 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3784 Please set RUNAS_ID to some UID which exists on MDS and client or
3785 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3788 # obtain the UID/GID for MPI_USER
3792 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3793 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3795 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3796 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3799 # obtain and cache Kerberos ticket-granting ticket
3800 refresh_krb5_tgt() {
3801 local myRUNAS_UID=$1
3802 local myRUNAS_GID=$2
3805 if [ -z "$myRUNAS" ]; then
3806 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3809 CLIENTS=${CLIENTS:-$HOSTNAME}
3810 do_nodes $CLIENTS "set -x
3811 if ! $myRUNAS krb5_login.sh; then
3812 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3817 # Run multiop in the background, but wait for it to print
3818 # "PAUSING" to its stdout before returning from this function.
3819 multiop_bg_pause() {
3820 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3824 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3827 echo "$MULTIOP_PROG $FILE v$ARGS"
3828 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3830 echo "TMPPIPE=${TMPPIPE}"
3831 read -t 60 multiop_output < $TMPPIPE
3832 if [ $? -ne 0 ]; then
3837 if [ "$multiop_output" != "PAUSING" ]; then
3838 echo "Incorrect multiop output: $multiop_output"
3853 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3859 inodes_available () {
3860 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3864 mdsrate_inodes_available () {
3865 local min_inodes=$(inodes_available)
3866 echo $((min_inodes * 99 / 100))
3869 # reset llite stat counters
3870 clear_llite_stats(){
3871 lctl set_param -n llite.*.stats 0
3874 # sum llite stat items
3875 calc_llite_stats() {
3876 local res=$(lctl get_param -n llite.*.stats |
3877 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3881 # reset osc stat counters
3883 lctl set_param -n osc.*.osc_stats 0
3886 # sum osc stat items
3888 local res=$(lctl get_param -n osc.*.osc_stats |
3889 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3894 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3897 calc_osc_kbytes () {
3898 df $MOUNT > /dev/null
3899 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3902 # save_lustre_params(node, parameter_mask)
3903 # generate a stream of formatted strings (<node> <param name>=<param value>)
3904 save_lustre_params() {
3906 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3909 # restore lustre parameters from input stream, produces by save_lustre_params
3910 restore_lustre_params() {
3914 while IFS=" =" read node name val; do
3915 do_node ${node//:/} "lctl set_param -n $name $val"
3919 check_catastrophe() {
3920 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3921 local C=$CATASTROPHE
3922 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3924 if [ $rnodes ]; then
3925 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3926 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3931 # CMD: determine mds index where directory inode presents
3934 local file=$dir/f0.get_mds_dir_tmpfile
3939 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3940 local -a oldused=($iused)
3942 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3944 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3945 local -a newused=($iused)
3948 for ((i=0; i<${#newused[@]}; i++)); do
3949 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3955 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3958 mdsrate_cleanup () {
3960 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3965 delayed_recovery_enabled () {
3966 local var=${SINGLEMDS}_svc
3967 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3970 ########################
3972 convert_facet2label() {
3975 if [ x$facet = xost ]; then
3979 local varsvc=${facet}_svc
3981 if [ -n ${!varsvc} ]; then
3984 error "No lablel for $facet!"
3988 get_clientosc_proc_path() {
3989 echo "${1}-osc-[^M]*"
3992 get_lustre_version () {
3993 local facet=${1:-"$SINGLEMDS"}
3994 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3997 get_mds_version_major () {
3998 local facet=${1:-"$SINGLEMDS"}
3999 local version=$(get_lustre_version $facet)
4000 echo $version | awk -F. '{print $1}'
4003 get_mds_version_minor () {
4004 local facet=${1:-"$SINGLEMDS"}
4005 local version=$(get_lustre_version $facet)
4006 echo $version | awk -F. '{print $2}'
4009 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4010 # used by MDT would not be changed.
4011 # mdt lov: fsname-mdtlov
4012 # mdt osc: fsname-OSTXXXX-osc
4013 mds_on_old_device() {
4014 local mds=${1:-"$SINGLEMDS"}
4015 local major=$(get_mds_version_major $mds)
4016 local minor=$(get_mds_version_minor $mds)
4018 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
4019 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4020 > /dev/null 2>&1" && return 0
4025 get_mdtosc_proc_path() {
4027 local ost_label=${2:-"*OST*"}
4029 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4030 local mdt_label=$(convert_facet2label $mds_facet)
4031 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4033 local major=$(get_mds_version_major $mds_facet)
4034 local minor=$(get_mds_version_minor $mds_facet)
4035 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
4036 echo "${ost_label}-osc"
4038 echo "${ost_label}-osc-${mdt_index}"
4042 get_osc_import_name() {
4045 local label=$(convert_facet2label $ost)
4047 if [ "${facet:0:3}" = "mds" ]; then
4048 get_mdtosc_proc_path $facet $label
4052 get_clientosc_proc_path $label
4056 _wait_import_state () {
4059 local maxtime=${3:-$(max_recovery_time)}
4063 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4064 while [ "${CONN_STATE}" != "${expected}" ]; do
4065 if [ "${expected}" == "DISCONN" ]; then
4066 # for disconn we can check after proc entry is removed
4067 [ "x${CONN_STATE}" == "x" ] && return 0
4068 # with AT enabled, we can have connect request timeout near of
4069 # reconnect timeout and test can't see real disconnect
4070 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4072 [ $i -ge $maxtime ] && \
4073 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4076 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4080 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4084 wait_import_state() {
4087 local maxtime=${3:-$(max_recovery_time)}
4090 for param in ${params//,/ }; do
4091 _wait_import_state $state $param $maxtime || return
4095 # One client request could be timed out because server was not ready
4096 # when request was sent by client.
4097 # The request timeout calculation details :
4099 # /* We give the server rq_timeout secs to process the req, and
4100 # add the network latency for our local timeout. */
4101 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4102 # ptlrpc_at_get_net_latency(request) ;
4104 # ptlrpc_connect_import ()
4105 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4108 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4109 # ptlrpc_at_get_net_latency(request) ->
4110 # at_get (max (iat_net_latency=0, at_min)) = at_min
4113 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4114 # INITIAL_CONNECT_TIMEOUT + at_min
4116 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4117 # because we can not get this value in runtime,
4118 # the value depends on configure options, and it is not stored in /proc.
4120 # #define CONNECTION_SWITCH_MIN 5U
4122 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4124 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4126 request_timeout () {
4129 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4130 local init_connect_timeout=$TIMEOUT
4131 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4133 local at_min=$(at_get $facet at_min)
4135 echo $(( init_connect_timeout + at_min ))
4138 wait_osc_import_state() {
4142 local ost=$(get_osc_import_name $facet $ost_facet)
4144 local param="osc.${ost}.ost_server_uuid"
4146 # 1. wait the deadline of client 1st request (it could be skipped)
4147 # 2. wait the deadline of client 2nd request
4148 local maxtime=$(( 2 * $(request_timeout $facet)))
4150 if ! do_rpc_nodes $(facet_host $facet) \
4151 _wait_import_state $expected $param $maxtime; then
4152 error "import is not in ${expected} state"
4159 get_clientmdc_proc_path() {
4167 # Add paths to lustre tests for 32 and 64 bit systems.
4168 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4169 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4172 wait_clients_import_state () {
4179 if [ "$FAILURE_MODE" = HARD ]; then
4180 facets=$(facets_on_host $(facet_active_host $facet))
4183 for facet in ${facets//,/ }; do
4184 local label=$(convert_facet2label $facet)
4187 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4188 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4189 *) error "unknown facet!" ;;
4191 local params=$(expand_list $params $proc_path)
4194 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4195 error "import is not in ${expected} state"
4204 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4205 $LCTL get_param obdfilter.*.kbytesavail))
4206 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4207 $LCTL get_param -n obdfilter.*.tot_granted))
4208 for ((i=0; i<${#AVAILA[@]}; i++)); do
4209 local -a AVAIL1=(${AVAILA[$i]//=/ })
4210 GRANT=$((${GRANTA[$i]}/1024))
4211 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4212 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4218 do_facet mgs lctl pool_list $1
4222 local fsname=${1%%.*}
4223 local poolname=${1##$fsname.}
4225 do_facet mgs lctl pool_new $1
4227 # get param should return err unless pool is created
4228 [[ $RC -ne 0 ]] && return $RC
4230 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4231 2>/dev/null || echo foo" "" || RC=1
4232 if [[ $RC -eq 0 ]]; then
4235 error "pool_new failed $1"
4240 add_pool_to_list () {
4241 local fsname=${1%%.*}
4242 local poolname=${1##$fsname.}
4244 local listvar=${fsname}_CREATED_POOLS
4245 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4248 remove_pool_from_list () {
4249 local fsname=${1%%.*}
4250 local poolname=${1##$fsname.}
4252 local listvar=${fsname}_CREATED_POOLS
4253 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4256 destroy_pool_int() {
4258 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4259 awk '$1 !~ /^Pool:/ {print $1}')
4260 for ost in $OSTS; do
4261 do_facet mgs lctl pool_remove $1 $ost
4263 do_facet mgs lctl pool_destroy $1
4266 # <fsname>.<poolname> or <poolname>
4268 local fsname=${1%%.*}
4269 local poolname=${1##$fsname.}
4271 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4275 pool_list $fsname.$poolname || return $?
4277 destroy_pool_int $fsname.$poolname
4279 [[ $RC -ne 0 ]] && return $RC
4281 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4282 2>/dev/null || echo foo" "foo" || RC=1
4284 if [[ $RC -eq 0 ]]; then
4285 remove_pool_from_list $fsname.$poolname
4287 error "destroy pool failed $1"
4293 local fsname=${1:-$FSNAME}
4295 local listvar=${fsname}_CREATED_POOLS
4299 [ x${!listvar} = x ] && return 0
4301 echo destroy the created pools: ${!listvar}
4302 for poolname in ${!listvar//,/ }; do
4303 destroy_pool $fsname.$poolname
4308 local fsname=${1:-$FSNAME}
4310 destroy_pools $fsname
4316 local ts=$(date +%s)
4319 if [[ ! -f "$YAML_LOG" ]]; then
4320 # init_logging is not performed before gather_logs,
4321 # so the $LOGDIR needs to be checked here
4322 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4325 [ -f $LOGDIR/shared ] && docp=false
4327 # dump lustre logs, dmesg
4329 prefix="$TESTLOG_PREFIX.$TESTNAME"
4331 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4333 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4334 echo "Dumping logs only on local client."
4335 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4336 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4341 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4342 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4343 if [ ! -f $LOGDIR/shared ]; then
4344 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4357 for i in $(seq 0 $num_mntpts); do
4358 cmd="ls -laf ${mntpt_root}$i/$dir"
4364 for pid in $pids; do
4371 # target_start_and_reset_recovery_timer()
4372 # service_time = at_est2timeout(service_time);
4373 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4374 # INITIAL_CONNECT_TIMEOUT);
4375 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4376 #define CONNECTION_SWITCH_INC 1
4377 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4378 #define CONNECTION_SWITCH_MIN 5U
4380 max_recovery_time () {
4381 local init_connect_timeout=$(( TIMEOUT / 20 ))
4382 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4384 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4389 get_clients_mount_count () {
4390 local clients=${CLIENTS:-`hostname`}
4392 # we need to take into account the clients mounts and
4393 # exclude mds/ost mounts if any;
4394 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4398 PROC_CLI="srpc_info"
4406 if [ $M -lt $N ]; then
4410 while [ $N -lt $M ]; do
4420 calc_connection_cnt() {
4423 # MDT->MDT = 2 * C(M, 2)
4427 comb_m2=$(combination $MDSCOUNT 2)
4429 local num_clients=$(get_clients_mount_count)
4431 local cnt_mdt2mdt=$((comb_m2 * 2))
4432 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4433 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4434 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4435 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4436 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4437 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4451 local cmd="$tgt.srpc.flavor"
4453 if [ $net == "any" ]; then
4458 if [ $dir != "any" ]; then
4463 log "Setting sptlrpc rule: $cmd"
4464 do_facet mgs "$LCTL conf_param $cmd"
4473 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4474 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4476 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4478 if [ "x$bulkspec" != "x" ]; then
4479 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4481 if [ "x$algs" != "x" ]; then
4482 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4484 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4485 if [ $bulk == "bulkn" ]; then
4486 bulk_count=`echo "$output" | grep "bulk flavor" \
4487 | grep "null/null" | wc -l`
4488 elif [ $bulk == "bulki" ]; then
4489 bulk_count=`echo "$output" | grep "bulk flavor" \
4490 | grep "/null" | grep -v "null/" | wc -l`
4492 bulk_count=`echo "$output" | grep "bulk flavor" \
4493 | grep -v "/null" | grep -v "null/" | wc -l`
4497 [ $bulk_count -lt $count ] && count=$bulk_count
4508 local clients=${CLIENTS:-`hostname`}
4510 for c in ${clients//,/ }; do
4511 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4512 tmpcnt=`count_flvr "$output" $flavor`
4513 cnt=$((cnt + tmpcnt))
4523 local clients=${CLIENTS:-`hostname`}
4525 for c in ${clients//,/ }; do
4526 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4527 tmpcnt=`count_flvr "$output" $flavor`
4528 cnt=$((cnt + tmpcnt))
4538 if [ $MDSCOUNT -le 1 ]; then
4543 for num in `seq $MDSCOUNT`; do
4544 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4545 tmpcnt=`count_flvr "$output" $flavor`
4546 cnt=$((cnt + tmpcnt))
4557 for num in `seq $MDSCOUNT`; do
4558 mdtosc=$(get_mdtosc_proc_path mds$num)
4559 mdtosc=${mdtosc/-MDT*/-MDT\*}
4560 output=$(do_facet mds$num lctl get_param -n \
4561 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4562 tmpcnt=`count_flvr "$output" $flavor`
4563 cnt=$((cnt + tmpcnt))
4572 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4573 count_flvr "$output" $flavor
4578 local dir=$1 # from to
4579 local flavor=$2 # flavor expected
4582 if [ $dir == "cli2mdt" ]; then
4583 res=`flvr_cnt_cli2mdt $flavor`
4584 elif [ $dir == "cli2ost" ]; then
4585 res=`flvr_cnt_cli2ost $flavor`
4586 elif [ $dir == "mdt2mdt" ]; then
4587 res=`flvr_cnt_mdt2mdt $flavor`
4588 elif [ $dir == "mdt2ost" ]; then
4589 res=`flvr_cnt_mdt2ost $flavor`
4590 elif [ $dir == "all2ost" ]; then
4591 res1=`flvr_cnt_mdt2ost $flavor`
4592 res2=`flvr_cnt_cli2ost $flavor`
4593 res=$((res1 + res2))
4594 elif [ $dir == "all2mdt" ]; then
4595 res1=`flvr_cnt_mdt2mdt $flavor`
4596 res2=`flvr_cnt_cli2mdt $flavor`
4597 res=$((res1 + res2))
4598 elif [ $dir == "all2all" ]; then
4599 res1=`flvr_cnt_mdt2ost $flavor`
4600 res2=`flvr_cnt_cli2ost $flavor`
4601 res3=`flvr_cnt_mdt2mdt $flavor`
4602 res4=`flvr_cnt_cli2mdt $flavor`
4603 res=$((res1 + res2 + res3 + res4))
4611 local dir=$1 # from to
4612 local flavor=$2 # flavor expected
4613 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4617 for ((i=0;i<20;i++)); do
4618 echo -n "checking $dir..."
4619 res=$(do_check_flavor $dir $flavor)
4620 echo "found $res/$expect $flavor connections"
4621 [ $res -ge $expect ] && return 0
4625 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4629 restore_to_default_flavor()
4631 local proc="mgs.MGS.live.$FSNAME"
4633 echo "restoring to default flavor..."
4635 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4637 # remove all existing rules if any
4638 if [ $nrule -ne 0 ]; then
4639 echo "$nrule existing rules"
4640 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4641 echo "remove rule: $rule"
4642 spec=`echo $rule | awk -F = '{print $1}'`
4643 do_facet mgs "$LCTL conf_param -d $spec"
4647 # verify no rules left
4648 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4649 [ $nrule -ne 0 ] && error "still $nrule rules left"
4651 # wait for default flavor to be applied
4652 # currently default flavor for all connections are 'null'
4653 wait_flavor all2all null
4654 echo "now at default flavor settings"
4659 local flavor=${1:-null}
4661 echo "setting all flavor to $flavor"
4663 # FIXME need parameter to this fn
4664 # and remove global vars
4665 local cnt_all2all=$(calc_connection_cnt all2all)
4667 local res=$(do_check_flavor all2all $flavor)
4668 if [ $res -eq $cnt_all2all ]; then
4669 echo "already have total $res $flavor connections"
4673 echo "found $res $flavor out of total $cnt_all2all connections"
4674 restore_to_default_flavor
4676 [[ $flavor = null ]] && return 0
4678 set_rule $FSNAME any any $flavor
4679 wait_flavor all2all $flavor
4685 # Checking for shared logdir
4686 if [ ! -d $dir ]; then
4687 # Not found. Create local logdir
4690 touch $dir/check_file.$(hostname -s)
4695 check_write_access() {
4700 for node in $(nodes_list); do
4701 file=$dir/check_file.$(short_hostname $node)
4702 if [[ ! -f "$file" ]]; then
4703 # Logdir not accessible/writable from this node.
4706 rm -f $file || return 1
4712 if [[ -n $YAML_LOG ]]; then
4715 local SAVE_UMASK=`umask`
4718 export YAML_LOG=${LOGDIR}/results.yml
4722 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
4723 if check_shared_dir $LOGDIR; then
4724 touch $LOGDIR/shared
4725 echo "Logging to shared log directory: $LOGDIR"
4727 echo "Logging to local directory: $LOGDIR"
4730 yml_nodes_file $LOGDIR >> $YAML_LOG
4731 yml_results_file >> $YAML_LOG
4738 yml_log_test $1 >> $YAML_LOG
4742 yml_log_test_status $@ >> $YAML_LOG
4745 log_sub_test_begin() {
4746 yml_log_sub_test_begin "$@" >> $YAML_LOG
4749 log_sub_test_end() {
4750 yml_log_sub_test_end "$@" >> $YAML_LOG
4756 local llverdev_opts=$2
4757 local devname=$(basename $1)
4758 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4759 # loop devices aren't in /proc/partitions
4760 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4762 size=$(($size / 1024 / 1024)) # Gb
4764 local partial_arg=""
4765 # Run in partial (fast) mode if the size
4766 # of a partition > 1 GB
4767 [ $size -gt 1 ] && partial_arg="-p"
4769 llverdev --force $partial_arg $llverdev_opts $dev
4775 local llverfs_opts=$2
4776 local partial_arg=""
4777 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4779 # Run in partial (fast) mode if the size
4780 # of a partition > 1 GB
4781 [ $size -gt 1 ] && partial_arg="-p"
4783 llverfs $partial_arg $llverfs_opts $dir
4786 remove_mdt_files() {
4791 local mntpt=$(facet_mntpt $facet)
4793 echo "removing files from $mdtdev on $facet: $files"
4794 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4797 rm $mntpt/ROOT/$f || { rc=$?; break; }
4799 umount -f $mntpt || return $?
4803 duplicate_mdt_files() {
4808 local mntpt=$(facet_mntpt $facet)
4810 echo "duplicating files on $mdtdev on $facet: $files"
4811 mkdir -p $mntpt || return $?
4812 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4822 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4823 pushd $mntpt/ROOT > /dev/null || return $?
4826 touch $f.bad || return $?
4827 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4829 [ $rc -eq 0 ] || return $rc
4830 setfattr --restore $tmp || return $?
4836 local devs=${1//,/ }
4839 local rslt=$TMP/sgpdd_survey
4841 # sgpdd-survey cleanups ${rslt}.* files
4843 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4849 # returns the canonical name for an ldiskfs device
4854 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4855 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4856 echo dm-\\\${foo##*:};
4858 echo \\\$(basename \\\$dv);
4862 is_sanity_benchmark() {
4863 local benchmarks="dbench bonnie iozone fsx"
4865 for b in $benchmarks; do
4866 if [ "$b" == "$suite" ]; then
4874 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4877 # Get the block size of the filesystem.
4883 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4884 awk '/^Block size:/ {print $3}')
4888 # Check whether the "large_xattr" feature is enabled or not.
4889 large_xattr_enabled() {
4890 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4892 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4893 return ${PIPESTATUS[0]}
4896 # Get the maximum xattr size supported by the filesystem.
4900 if large_xattr_enabled; then
4901 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4904 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4905 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4907 # maximum xattr size = size of block - size of header -
4908 # size of 1 entry - 4 null bytes
4909 size=$((block_size - 32 - 32 - 4))
4915 # Dump the value of the named xattr from a file.
4920 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4923 # Generate a string with size of $size bytes.
4925 local size=${1:-1024} # in bytes
4927 echo "$(head -c $size < /dev/zero | tr '\0' y)"