2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
5 trap 'print_summary && touch $TF_FAIL && \
6 echo "test-framework exiting on error"' ERR
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
13 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
20 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
21 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
22 export LOAD_LLOOP=${LOAD_LLOOP:-false}
24 #export PDSH="pdsh -S -Rssh -w"
26 # function used by scripts run on remote nodes
27 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
28 . $LUSTRE/tests/functions.sh
29 . $LUSTRE/tests/yaml.sh
31 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
33 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
35 if [ -f "$EXCEPT_LIST_FILE" ]; then
36 echo "Reading test skip list from $EXCEPT_LIST_FILE"
41 # check config files for options in decreasing order of preference
42 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
43 MODPROBECONF=/etc/modprobe.d/lustre.conf
44 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
45 MODPROBECONF=/etc/modprobe.d/Lustre
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
47 MODPROBECONF=/etc/modprobe.conf
51 [[ $DIR/ = $MOUNT/* ]] || \
52 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
53 [[ $DIR1/ = $MOUNT1/* ]] || \
54 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
55 [[ $DIR2/ = $MOUNT2/* ]] || \
56 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
58 [ -n "$failed" ] && exit 99 || true
62 echo "usage: $0 [-r] [-f cfgfile]"
70 [ "$TESTSUITE" == "lfsck" ] && return 0
71 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
73 local form="%-13s %-17s %-9s %s %s\n"
74 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
75 echo "------------------------------------------------------------------------------------"
76 for O in $DEFAULT_SUITES; do
77 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
78 [ "${!O}" = "no" ] && continue || true
79 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
80 local log=${TMP}/${o}.log
81 if is_sanity_benchmark $o; then
82 log=${TMP}/sanity-benchmark.log
87 local status=Unfinished
89 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
90 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
91 total=$(grep duration $log | awk '{ print $2}')
92 if [ "${!O}" = "done" ]; then
96 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
97 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
100 printf "$form" $status "$O" "${total}" "E=$skipped"
101 printf "$form" "-" "-" "-" "S=$(echo $slow)"
104 for O in $DEFAULT_SUITES; do
105 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
106 if [ "${!O}" = "no" ]; then
107 printf "$form" "Skipped" "$O" ""
111 # print the detailed tests durations if DDETAILS=true
118 export LUSTRE=`absolute_path $LUSTRE`
119 export TESTSUITE=`basename $0 .sh`
120 export TEST_FAILED=false
121 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
123 export MKE2FS=${MKE2FS:-mke2fs}
124 export DEBUGFS=${DEBUGFS:-debugfs}
125 export TUNE2FS=${TUNE2FS:-tune2fs}
126 export E2LABEL=${E2LABEL:-e2label}
127 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
128 export E2FSCK=${E2FSCK:-e2fsck}
129 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
131 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
132 export FSCK_MAX_ERR=4 # File system errors left uncorrected
134 #[ -d /r ] && export ROOT=${ROOT:-/r}
135 export TMP=${TMP:-$ROOT/tmp}
136 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
137 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
138 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
140 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
141 if ! echo $PATH | grep -q $LUSTRE/utils; then
142 export PATH=$LUSTRE/utils:$PATH
144 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
145 export PATH=$LUSTRE/utils/gss:$PATH
147 if ! echo $PATH | grep -q $LUSTRE/tests; then
148 export PATH=$LUSTRE/tests:$PATH
150 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
151 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
153 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
154 [ ! -f "$LST" ] && export LST=$(which lst)
155 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
156 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
157 # Ubuntu, at least, has a truncate command in /usr/bin
158 # so fully path our truncate command.
159 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
160 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
161 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
162 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
163 export PATH=$LUSTRE/tests/racer:$PATH:
165 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
166 export PATH=$LUSTRE/tests/mpi:$PATH
168 export RSYNC_RSH=${RSYNC_RSH:-rsh}
170 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
171 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
172 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
173 [ ! -f "$LFS" ] && export LFS=$(which lfs)
174 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
175 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
177 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
178 if [ ! -f "$L_GETIDENTITY" ]; then
179 if `which l_getidentity > /dev/null 2>&1`; then
180 export L_GETIDENTITY=$(which l_getidentity)
182 export L_GETIDENTITY=NONE
185 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
186 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
187 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
188 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
189 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
190 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
191 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
192 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
193 [ ! -f "$LUSTRE_RMMOD" ] &&
194 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
195 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
196 [ ! -f "$LFS_MIGRATE" ] &&
197 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
198 export FSTYPE=${FSTYPE:-"ldiskfs"}
199 export NAME=${NAME:-local}
200 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
201 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
202 export LGSSD=$(which lgssd)
203 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
204 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
205 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
207 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
210 if [ "$ACCEPTOR_PORT" ]; then
211 export PORT_OPT="--port $ACCEPTOR_PORT"
216 echo "Using GSS/krb5 ptlrpc security flavor"
217 which lgss_keyring > /dev/null 2>&1 || \
218 error_exit "built with gss disabled! SEC=$SEC"
229 IDENTITY_UPCALL=false
232 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
234 # Paths on remote nodes, if different
235 export RLUSTRE=${RLUSTRE:-$LUSTRE}
236 export RPWD=${RPWD:-$PWD}
237 export I_MOUNTED=${I_MOUNTED:-"no"}
238 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
239 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
240 ! -f `dirname $0`/../mds/mds.ko ]; then
241 export CLIENTMODSONLY=yes
244 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
248 while getopts "rvwf:" opt $*; do
251 r) REFORMAT=--reformat;;
253 w) WRITECONF=writeconf;;
258 shift $((OPTIND - 1))
261 # print the durations of each test if "true"
262 DDETAILS=${DDETAILS:-false}
263 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
268 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
269 eval set -- $(tr "[:punct:]" " " <<< $*)
271 echo -n $((($1 << 16) | ($2 << 8) | $3))
274 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
275 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
278 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
279 *) EXT=".ko"; USE_QUOTA=yes;;
284 /sbin/lsmod | grep -q "^\<$1\>"
287 # Load a module on the system where this is running.
289 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
291 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
292 # will be used as the arguments. Otherwise arguments will be obtained from
293 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
300 BASE=`basename $module $EXT`
302 module_loaded ${BASE} && return
304 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
306 if [ $# -eq 0 ]; then
307 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
308 # Bash until 4.x, so we resort to eval.
309 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
310 eval set -- \$$optvar
311 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
312 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
313 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
314 # Get rid of "options $module"
315 (($# > 0)) && shift 2
317 # Ensure we have accept=all for lnet
318 if [ $(basename $module) = lnet ]; then
319 # OK, this is a bit wordy...
320 local arg accept_all_present=false
322 [ "$arg" = accept=all ] && accept_all_present=true
324 $accept_all_present || set -- "$@" accept=all
329 [ $# -gt 0 ] && echo "${module} options: '$*'"
331 # Note that insmod will ignore anything in modprobe.conf, which is why we're
332 # passing options on the command-line.
333 if [ "$BASE" == "lnet_selftest" ] && \
334 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
335 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
336 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
337 insmod ${LUSTRE}/${module}${EXT} "$@"
339 # must be testing a "make install" or "rpm" installation
340 # note failed to load ptlrpc_gss is considered not fatal
341 if [ "$BASE" == "ptlrpc_gss" ]; then
342 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
349 llite_lloop_enabled() {
350 local n1=$(uname -r | cut -d. -f1)
351 local n2=$(uname -r | cut -d. -f2)
352 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
354 # load the llite_lloop module for < 2.6.32 kernels
355 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
356 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
363 load_modules_local() {
364 if [ -n "$MODPROBE" ]; then
366 echo "Using modprobe to load modules"
370 echo Loading modules from $LUSTRE
371 load_module ../libcfs/libcfs/libcfs
372 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
373 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
374 load_module ../lnet/lnet/lnet
375 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
376 load_module ../lnet/klnds/$LNETLND
377 load_module lvfs/lvfs
378 load_module obdclass/obdclass
379 load_module ptlrpc/ptlrpc
380 load_module ptlrpc/gss/ptlrpc_gss
388 if ! client_only; then
389 SYMLIST=/proc/kallsyms
390 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
391 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
392 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
393 if [ "$FSTYPE" = "ldiskfs" ]; then
394 grep -q exportfs_decode_fh $SYMLIST ||
395 { modprobe exportfs 2> /dev/null || true; }
396 load_module ../ldiskfs/ldiskfs/ldiskfs
398 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
403 load_module lvfs/fsfilt_$FSTYPE
405 load_module osd-ldiskfs/osd_ldiskfs
407 if [ "x$USE_OFD" = "xyes" ]; then
410 load_module obdfilter/obdfilter
415 load_module llite/lustre
416 llite_lloop_enabled && load_module llite/llite_lloop
417 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
419 rm -f $OGDB/ogdb-$HOSTNAME
420 $LCTL modules > $OGDB/ogdb-$HOSTNAME
422 # 'mount' doesn't look in $PATH, just sbin
423 if [ -f $LUSTRE/utils/mount.lustre ] && \
424 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
425 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
426 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
433 # load modules on remote nodes optionally
434 # lustre-tests have to be installed on these nodes
435 if $LOAD_MODULES_REMOTE ; then
436 local list=$(comma_list $(remote_nodes_list))
437 echo loading modules on $list
438 do_rpc_nodes $list load_modules
443 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
444 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
445 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
446 echo "$LEAK_LUSTRE" 1>&2
447 echo "$LEAK_PORTALS" 1>&2
448 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
449 echo "Memory leaks detected"
450 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
456 wait_exit_ST client # bug 12845
458 $LUSTRE_RMMOD $FSTYPE || return 2
460 if $LOAD_MODULES_REMOTE ; then
461 local list=$(comma_list $(remote_nodes_list))
462 if [ ! -z $list ]; then
463 echo unloading modules on $list
464 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
465 do_rpc_nodes $list check_mem_leak
469 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
470 umount /sbin/mount.lustre || true
471 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
472 rm -f /sbin/mount.lustre || true
475 check_mem_leak || return 254
477 echo "modules unloaded."
481 check_gss_daemon_nodes() {
485 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
486 if [ \\\"\\\$num\\\" -ne 1 ]; then
487 echo \\\$num instance of $dname;
492 check_gss_daemon_facet() {
496 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
497 if [ $num -ne 1 ]; then
498 echo "$num instance of $dname on $facet"
507 echo Stopping $@ on $list
508 do_nodes $list "killall -2 $@ 2>/dev/null || true"
511 # start gss daemons on all nodes, or
512 # "daemon" on "list" if set
513 start_gss_daemons() {
517 if [ "$list" ] && [ "$daemon" ] ; then
518 echo "Starting gss daemon on nodes: $list"
519 do_nodes $list "$daemon" || return 8
523 local list=$(comma_list $(mdts_nodes))
525 echo "Starting gss daemon on mds: $list"
526 do_nodes $list "$LSVCGSSD -v" || return 1
528 do_nodes $list "$LGSSD -v" || return 2
531 list=$(comma_list $(osts_nodes))
532 echo "Starting gss daemon on ost: $list"
533 do_nodes $list "$LSVCGSSD -v" || return 3
534 # starting on clients
536 local clients=${CLIENTS:-`hostname`}
538 echo "Starting $LGSSD on clients $clients "
539 do_nodes $clients "$LGSSD -v" || return 4
542 # wait daemons entering "stable" status
546 # check daemons are running
548 list=$(comma_list $(mdts_nodes) $(osts_nodes))
549 check_gss_daemon_nodes $list lsvcgssd || return 5
551 list=$(comma_list $(mdts_nodes))
552 check_gss_daemon_nodes $list lgssd || return 6
555 check_gss_daemon_nodes $clients lgssd || return 7
560 local list=$(comma_list $(mdts_nodes))
562 send_sigint $list lsvcgssd lgssd
564 list=$(comma_list $(osts_nodes))
565 send_sigint $list lsvcgssd
567 list=${CLIENTS:-`hostname`}
568 send_sigint $list lgssd
573 if ! module_loaded ptlrpc_gss; then
574 load_module ptlrpc/gss/ptlrpc_gss
575 module_loaded ptlrpc_gss ||
576 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
578 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
580 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
581 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
589 # maybe cleanup credential cache?
595 local device=`mdsdevname $num`
596 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
602 local device=`ostdevname $num`
603 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
608 local dz=${1:-$DEBUG_SIZE}
610 if [ -f /sys/devices/system/cpu/possible ]; then
611 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
613 local cpus=$(getconf _NPROCESSORS_CONF)
616 # bug 19944, adjust size to be -gt num_possible_cpus()
617 # promise 2MB for every cpu at least
618 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
621 lctl set_param debug_mb=$dz
624 set_default_debug () {
625 local debug=${1:-"$PTLDEBUG"}
626 local subsys=${2:-"$SUBSYSTEM"}
627 local debug_size=${3:-$DEBUG_SIZE}
629 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
630 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
632 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
635 set_default_debug_nodes () {
638 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
639 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
643 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
644 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
647 set_default_debug_facet () {
649 local node=$(facet_active_host $facet)
650 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
652 set_default_debug_nodes $node
657 local facets=${1:-$(get_facets)}
660 for facet in ${facets//,/ }; do
663 [ $RC -eq 0 ] && continue
665 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
666 skip "Restart of $facet failed!." && touch $LU482_FAILED
668 error "Restart of $facet failed!"
677 local dev=$(facet_active $facet)_dev
678 local opt=${facet}_opt
679 local mntpt=$(facet_mntpt $facet)
681 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
682 # for testing LU-482 error handling in mount_facets() and test_0a()
683 if [ -f $TMP/test-lu482-trigger ]; then
686 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} \
690 if [ $RC -ne 0 ]; then
691 echo "Start of ${!dev} on ${facet} failed ${RC}"
693 set_default_debug_facet $facet
695 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
696 [ -z "$label" ] && echo no label for ${!dev} && exit 1
697 eval export ${facet}_svc=${label}
698 echo Started ${label}
703 # start facet device options
709 eval export ${facet}_dev=${device}
710 eval export ${facet}_opt=\"$@\"
712 local varname=${facet}failover_dev
713 if [ -n "${!varname}" ] ; then
714 eval export ${facet}failover_dev=${!varname}
716 eval export ${facet}failover_dev=$device
719 local mntpt=$(facet_mntpt $facet)
720 do_facet ${facet} mkdir -p $mntpt
721 eval export ${facet}_MOUNT=$mntpt
731 local HOST=`facet_active_host $facet`
732 [ -z $HOST ] && echo stop: no host for $facet && return 0
734 local mntpt=$(facet_mntpt $facet)
735 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
736 if [ ${running} -ne 0 ]; then
737 echo "Stopping $mntpt (opts:$@) on $HOST"
738 do_facet ${facet} umount -d $@ $mntpt
741 # umount should block, but we should wait for unrelated obd's
742 # like the MGS or MGC to also stop.
743 wait_exit_ST ${facet}
746 # save quota version (both administrative and operational quotas)
747 # add an additional parameter if mountpoint is ever different from $MOUNT
748 quota_save_version() {
749 local fsname=${2:-$FSNAME}
751 local ver=$(tr -c -d "123" <<< $spec)
752 local type=$(tr -c -d "ug" <<< $spec)
754 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
756 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
758 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
760 local osts=$(get_facets OST)
761 for ost in ${osts//,/ }; do
763 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
767 # client could mount several lustre
769 local fsname=${1:-$FSNAME}
771 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
772 do_nodes $(comma_list $(osts_nodes)) \
773 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
777 restore_quota_type () {
778 local mntpt=${1:-$MOUNT}
779 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
780 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
783 quota_save_version $old_QUOTA_TYPE
789 # We need save the original quota_type params, and restore them after testing
791 # Suppose that quota type the same on mds and ost
792 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
793 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
794 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
795 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
796 export old_QUOTA_TYPE=$quota_type
797 quota_save_version $QUOTA_TYPE
799 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
800 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
803 local quota_usrs=$QUOTA_USERS
805 # get_filesystem_size
806 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
807 local blk_soft=$((disksz + 1024))
808 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
810 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
812 local i_hard=$((i_soft + i_soft / 20))
814 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
815 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
818 for usr in $quota_usrs; do
819 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
821 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
823 eval $cmd || error "$cmd FAILED!"
825 # display the quota status
826 echo "Quota settings for $usr : "
827 $LFS quota -v -u $usr $mntpt || true
834 local OPTIONS=${3:-$MOUNTOPT}
836 local device=$MGSNID:/$FSNAME
837 if [ -z "$mnt" -o -z "$FSNAME" ]; then
838 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
842 echo "Starting client: $client: $OPTIONS $device $mnt"
843 do_node $client mkdir -p $mnt
844 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
846 set_default_debug_nodes $client
859 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
860 if [ $running -ne 0 ]; then
861 echo "Stopping client $client $mnt (opts:$force)"
862 do_node $client lsof -t $mnt || need_kill=no
863 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
864 pids=$(do_node $client lsof -t $mnt | sort -u);
865 if [ -n $pids ]; then
866 do_node $client kill -9 $pids || true
870 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
871 if [ $busy -ne 0 ] ; then
872 echo "$mnt is still busy, wait one second" && sleep 1
873 do_node $client umount $force $mnt
878 # nodes is comma list
879 sanity_mount_check_nodes () {
885 # FIXME: assume that all cluster nodes run the same os
886 [ "$(uname)" = Linux ] || return 0
889 for mnt in $mnts ; do
890 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
891 mpts=\\\$(mount | grep -c $mnt' ');
892 if [ \\\$running -ne \\\$mpts ]; then
893 echo \\\$(hostname) env are INSANE!;
901 sanity_mount_check_servers () {
903 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
904 echo Checking servers environments
906 # FIXME: modify get_facets to display all facets wo params
907 local facets="$(get_facets OST),$(get_facets MDS),mgs"
911 for facet in ${facets//,/ }; do
912 node=$(facet_host ${facet})
913 mntpt=$(facet_mntpt $facet)
914 sanity_mount_check_nodes $node $mntpt ||
915 { error "server $node environments are insane!"; return 1; }
919 sanity_mount_check_clients () {
920 local clients=${1:-$CLIENTS}
921 local mntpt=${2:-$MOUNT}
922 local mntpt2=${3:-$MOUNT2}
924 [ -z $clients ] && clients=$(hostname)
925 echo Checking clients $clients environments
927 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
928 error "clients environments are insane!"
931 sanity_mount_check () {
932 sanity_mount_check_servers || return 1
933 sanity_mount_check_clients || return 2
936 # mount clients if not mouted
937 zconf_mount_clients() {
940 local OPTIONS=${3:-$MOUNTOPT}
942 local device=$MGSNID:/$FSNAME
943 if [ -z "$mnt" -o -z "$FSNAME" ]; then
944 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
948 echo "Starting client $clients: $OPTIONS $device $mnt"
951 running=\\\$(mount | grep -c $mnt' ');
953 if [ \\\$running -eq 0 ] ; then
955 mount -t lustre $OPTIONS $device $mnt;
958 exit \\\$rc" || return ${PIPESTATUS[0]}
960 echo "Started clients $clients: "
961 do_nodes $clients "mount | grep $mnt' '"
963 set_default_debug_nodes $clients
968 zconf_umount_clients() {
975 echo "Stopping clients: $clients $mnt (opts:$force)"
976 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
977 if [ \\\$running -ne 0 ] ; then
978 echo Stopping client \\\$(hostname) $mnt opts:$force;
979 lsof $mnt || need_kill=no;
980 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
981 pids=\\\$(lsof -t $mnt | sort -u);
982 if [ -n \\\"\\\$pids\\\" ]; then
986 while umount $force $mnt 2>&1 | grep -q "busy"; do
987 echo "$mnt is still busy, wait one second" && sleep 1;
994 echo + $POWER_DOWN $node
998 shutdown_node_hard () {
1000 local attempts=$SHUTDOWN_ATTEMPTS
1002 for i in $(seq $attempts) ; do
1005 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1006 echo "waiting for $host to fail attempts=$attempts"
1007 [ $i -lt $attempts ] || \
1008 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1014 local mnt=${2:-$MOUNT}
1017 if [ "$FAILURE_MODE" = HARD ]; then
1018 shutdown_node_hard $client
1020 zconf_umount_clients $client $mnt -f
1026 local facets="$(get_facets OST),$(get_facets MDS)"
1029 combined_mgs_mds || facets="$facets,mgs"
1031 for facet in ${facets//,/ }; do
1032 if [ $(facet_active_host $facet) == $host ]; then
1033 affected="$affected $facet"
1037 echo $(comma_list $affected)
1042 local host=${2:-$(facet_host $facet)}
1044 local label=$(convert_facet2label $facet)
1045 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1048 facets_up_on_host () {
1050 local facets=$(facets_on_host $host)
1053 for facet in ${facets//,/ }; do
1054 if $(facet_up $facet $host); then
1055 affected_up="$affected_up $facet"
1059 echo $(comma_list $affected_up)
1065 if [ "$FAILURE_MODE" = HARD ]; then
1066 shutdown_node_hard $(facet_active_host $facet)
1074 echo + $POWER_UP $node
1087 if [ "$FAILURE_MODE" = HARD ]; then
1088 reboot_node $(facet_active_host $facet)
1096 if [ "$FAILURE_MODE" = HARD ]; then
1106 for facet in ${facets//,/ }; do
1107 hosts=$(expand_list $hosts $(facet_host $facet) )
1113 _check_progs_installed () {
1117 for prog in $progs; do
1118 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1119 echo $prog missing on $(hostname)
1126 check_progs_installed () {
1130 do_rpc_nodes $nodes _check_progs_installed $@
1133 # recovery-scale functions
1135 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1138 start_client_load() {
1141 local var=$(node_var_name $client)_load
1142 eval export ${var}=$load
1144 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1145 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1146 END_RUN_FILE=$END_RUN_FILE \
1147 LOAD_PID_FILE=$LOAD_PID_FILE \
1148 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1149 TESTNAME=$TESTNAME \
1150 DBENCH_LIB=$DBENCH_LIB \
1151 DBENCH_SRC=$DBENCH_SRC \
1154 log "Started client load: ${load} on $client"
1156 # get the children process IDs
1157 local pids=$(ps --ppid $ppid -o pid= | xargs)
1158 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1162 start_client_loads () {
1163 local -a clients=(${1//,/ })
1164 local numloads=${#CLIENT_LOADS[@]}
1167 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1168 testnum=$((nodenum % numloads))
1169 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1171 # bug 22169: wait the background threads to start
1175 # only for remote client
1176 check_client_load () {
1178 local var=$(node_var_name $client)_load
1179 local TESTLOAD=run_${!var}.sh
1181 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1183 # bug 18914: try to connect several times not only when
1184 # check ps, but while check_catastrophe also
1187 while [ $RC = 254 -a $tries -gt 0 ]; do
1191 if ! check_catastrophe $client; then
1193 if [ $RC -eq 254 ]; then
1194 # FIXME: not sure how long we shuold sleep here
1198 echo "check catastrophe failed: RC=$RC "
1202 # We can continue try to connect if RC=254
1203 # Just print the warning about this
1204 if [ $RC = 254 ]; then
1205 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1208 # see if the load is still on the client
1211 while [ $RC = 254 -a $tries -gt 0 ]; do
1215 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1220 if [ $RC = 254 ]; then
1221 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1222 # see if we can diagnose a bit why this is
1227 check_client_loads () {
1228 local clients=${1//,/ }
1232 for client in $clients; do
1233 check_client_load $client
1235 if [ "$rc" != 0 ]; then
1236 log "Client load failed on node $client, rc=$rc"
1242 restart_client_loads () {
1243 local clients=${1//,/ }
1244 local expectedfail=${2:-""}
1248 for client in $clients; do
1249 check_client_load $client
1251 if [ "$rc" != 0 -a "$expectedfail" ]; then
1252 local var=$(node_var_name $client)_load
1253 start_client_load $client ${!var}
1254 echo "Restarted client load ${!var}: on $client. Checking ..."
1255 check_client_load $client
1257 if [ "$rc" != 0 ]; then
1258 log "Client load failed to restart on node $client, rc=$rc"
1259 # failure one client load means test fail
1260 # we do not need to check other
1269 # Start vmstat and save its process ID in a file.
1274 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1277 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1278 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1281 # Display the nodes on which client loads failed.
1282 print_end_run_file() {
1286 [ -s $file ] || return 0
1288 echo "Found the END_RUN_FILE file: $file"
1291 # A client load will stop if it finds the END_RUN_FILE file.
1292 # That does not mean the client load actually failed though.
1293 # The first node in END_RUN_FILE is the one we are interested in.
1296 if [ -n "$node" ]; then
1297 local var=$(node_var_name $node)_load
1299 local prefix=$TESTLOG_PREFIX
1300 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1301 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1302 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1304 echo "Client load ${!var} failed on node $node:"
1310 # Stop the process which had its PID saved in a file.
1315 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1317 do_nodes $nodes "test -f $pid_file &&
1318 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1321 # Stop all client loads.
1322 stop_client_loads() {
1323 local nodes=${1:-$CLIENTS}
1326 # stop the client loads
1327 stop_process $nodes $pid_file
1329 # clean up the processes that started them
1330 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1332 # End recovery-scale functions
1334 # verify that lustre actually cleaned up properly
1336 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1337 error "LBUG/LASSERT detected"
1338 BUSY=`dmesg | grep -i destruct || true`
1339 if [ "$BUSY" ]; then
1341 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1345 check_mem_leak || exit 204
1347 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1348 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1350 if module_loaded lnet || module_loaded libcfs; then
1351 echo "$0: modules still loaded..." 1>&2
1369 RESULT=$(do_node $node "$TEST")
1370 if [ "$RESULT" == "$FINAL" ]; then
1371 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1372 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1375 [ $WAIT -ge $MAX ] && break
1376 [ $((WAIT % print)) -eq 0 ] &&
1377 echo "Waiting $((MAX - WAIT)) secs for update"
1378 WAIT=$((WAIT + sleep))
1381 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1385 wait_update_facet () {
1387 wait_update $(facet_active_host $facet) "$@"
1390 wait_delete_completed () {
1391 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1392 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1396 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1398 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1399 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1400 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1401 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1405 echo "Delete is not completed in $MAX_WAIT sec"
1412 # we can use "for" here because we are waiting the slowest
1413 for host in ${hostlist//,/ }; do
1414 check_network "$host" 900
1416 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1423 for facet in ${facetlist//,/ }; do
1424 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1426 wait_for_host $hostlist
1429 _wait_recovery_complete () {
1432 # Use default policy if $2 is not passed by caller.
1433 local MAX=${2:-$(max_recovery_time)}
1438 while [ $WAIT -lt $MAX ]; do
1439 STATUS=$(lctl get_param -n $param | grep status)
1441 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1444 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1446 echo "$param recovery not done in $MAX sec. $STATUS"
1450 wait_recovery_complete () {
1453 # with an assumption that at_max is the same on all nodes
1454 local MAX=${2:-$(max_recovery_time)}
1457 if [ "$FAILURE_MODE" = HARD ]; then
1458 facets=$(facets_on_host $(facet_active_host $facet))
1460 echo affected facets: $facets
1462 # we can use "for" here because we are waiting the slowest
1463 for facet in ${facets//,/ }; do
1464 local var_svc=${facet}_svc
1465 local param="*.${!var_svc}.recovery_status"
1467 local host=$(facet_active_host $facet)
1468 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1472 wait_mds_ost_sync () {
1473 # just because recovery is done doesn't mean we've finished
1474 # orphan cleanup. Wait for llogs to get synchronized.
1475 echo "Waiting for orphan cleanup..."
1476 # MAX value includes time needed for MDS-OST reconnection
1477 local MAX=$(( TIMEOUT * 2 ))
1479 while [ $WAIT -lt $MAX ]; do
1480 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1481 "$LCTL get_param -n obdfilter.*.mds_sync"))
1484 for ((i=0; i<${#sync[@]}; i++)); do
1485 [ ${sync[$i]} -eq 0 ] && continue
1486 # there is a not finished MDS-OST synchronization
1490 sleep 2 # increase waiting time and cover statfs cache
1491 [ ${con} -eq 1 ] && return 0
1492 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1495 echo "$facet recovery not done in $MAX sec. $STATUS"
1499 wait_destroy_complete () {
1500 echo "Waiting for destroy to be done..."
1501 # MAX value shouldn't be big as this mean server responsiveness
1502 # never increase this just to make test pass but investigate
1503 # why it takes so long time
1506 while [ $WAIT -lt $MAX ]; do
1507 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1509 for ((i=0; i<${#RPCs[@]}; i++)); do
1510 [ ${RPCs[$i]} -eq 0 ] && continue
1511 # there are still some destroy RPCs in flight
1516 [ ${con} -eq 1 ] && return 0 # done waiting
1517 echo "Waiting $WAIT secs for destroys to be done."
1520 echo "Destroys weren't done in $MAX sec."
1530 # conf-sanity 31 takes a long time cleanup
1531 while [ $WAIT -lt 300 ]; do
1532 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1533 [ -z "${running}" ] && return 0
1534 echo "waited $WAIT for${running}"
1535 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1537 WAIT=$((WAIT + INTERVAL))
1539 echo "service didn't stop after $WAIT seconds. Still running:"
1544 wait_remote_prog () {
1550 [ "$PDSH" = "no_dsh" ] && return 0
1552 while [ $WAIT -lt $2 ]; do
1553 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1554 [ -z "${running}" ] && return 0 || true
1555 echo "waited $WAIT for: "
1557 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1559 WAIT=$((WAIT + INTERVAL))
1561 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1562 [ -z "$pids" ] && return 0
1563 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1564 # FIXME: not portable
1565 for pid in $pids; do
1566 cat /proc/${pid}/status || true
1567 cat /proc/${pid}/wchan || true
1569 kill -9 $pid || true
1578 # not every config has many clients
1580 if [ ! -z "$CLIENTS" ]; then
1581 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1583 stat -f $MOUNT > /dev/null
1589 # usually checked on particular client or locally
1591 if [ ! -z "$client" ]; then
1592 $PDSH $client "stat -f $MOUNT" > /dev/null
1594 stat -f $MOUNT > /dev/null
1602 client_reconnect() {
1603 uname -n >> $MOUNT/recon
1604 if [ -z "$CLIENTS" ]; then
1605 df $MOUNT; uname -n >> $MOUNT/recon
1607 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1609 echo Connected clients:
1611 ls -l $MOUNT/recon > /dev/null
1615 affected_facets () {
1618 local host=$(facet_active_host $facet)
1619 local affected=$facet
1621 if [ "$FAILURE_MODE" = HARD ]; then
1622 affected=$(facets_up_on_host $host)
1630 local host=$(facet_active_host $facet)
1632 echo "Failing $facet on node $host"
1634 # Make sure the client data is synced to disk. LU-924
1636 # We don't write client data synchrnously (to avoid flooding sync writes
1637 # when there are many clients connecting), so if the server reboots before
1638 # the client data reachs disk, the client data will be lost and the client
1639 # will be evicted after recovery, which is not what we expected.
1640 do_facet $facet "sync; sync; sync"
1642 local affected=$(affected_facets $facet)
1644 shutdown_facet $facet
1646 echo affected facets: $affected
1648 [ -n "$sleep_time" ] && sleep $sleep_time
1652 change_active $affected
1654 wait_for_facet $affected
1655 # start mgs first if it is affected
1656 if ! combined_mgs_mds && list_member $affected mgs; then
1657 mount_facet mgs || error "Restart of mgs failed"
1659 # FIXME; has to be changed to mount all facets concurrently
1660 affected=$(exclude_items_from_list $affected mgs)
1661 mount_facets $affected
1670 do_facet $facet "sync; sync; sync"
1673 # make sure there will be no seq change
1674 local clients=${CLIENTS:-$HOSTNAME}
1675 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1677 local svc=${facet}_svc
1678 do_facet $facet $LCTL --device %${!svc} notransno
1679 do_facet $facet $LCTL --device %${!svc} readonly
1680 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1681 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1684 replay_barrier_nodf() {
1685 local facet=$1 echo running=${running}
1686 do_facet $facet "sync; sync; sync"
1687 local svc=${facet}_svc
1688 echo Replay barrier on ${!svc}
1689 do_facet $facet $LCTL --device %${!svc} notransno
1690 do_facet $facet $LCTL --device %${!svc} readonly
1691 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1692 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1695 replay_barrier_nosync() {
1696 local facet=$1 echo running=${running}
1697 local svc=${facet}_svc
1698 echo Replay barrier on ${!svc}
1699 do_facet $facet $LCTL --device %${!svc} notransno
1700 do_facet $facet $LCTL --device %${!svc} readonly
1701 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1702 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1705 mds_evict_client() {
1706 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1707 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1710 ost_evict_client() {
1711 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1712 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1716 facet_failover $* || error "failover: $?"
1717 clients_up || error "post-failover df: $?"
1722 facet_failover $facet
1728 change_active $facet
1729 wait_for_facet $facet
1730 mount_facet $facet -o abort_recovery
1731 clients_up || echo "first df failed: $?"
1732 clients_up || error "post-failover df: $?"
1736 echo There is no lmc. This is mountconf, baby.
1740 host_nids_address() {
1744 if [ -n "$kind" ]; then
1745 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1747 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1753 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1759 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1760 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1761 if [ -z "$ID" ]; then
1762 echo "Could not get a ptl id for $1..."
1771 h2name_or_ip "$1" "tcp"
1776 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1777 if type __h2elan >/dev/null 2>&1; then
1780 ID=`echo $1 | sed 's/[^0-9]*//g'`
1788 h2name_or_ip "$1" "o2ib"
1792 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1793 # expressions format. As a bonus we can then just pass in those variables
1794 # to pdsh. What this function does is take a HOSTLIST type string and
1795 # expand it into a space deliminated list for us.
1803 [ -z "$hostlist" ] && return
1805 # Translate the case of [..],..,[..] to [..] .. [..]
1806 list="${hostlist/],/] }"
1808 [[ "$front" == *,* ]] && {
1811 list=${list/${old}/${new}}
1814 for item in $list; do
1815 # Test if we have any []'s at all
1816 if [ "$item" != "${item/\[/}" ]; then {
1817 # Expand the [*] into list
1821 if [ "$name" != "$item" ]; then
1822 group=${item#$name[*}
1825 for range in ${group//,/ }; do
1829 # Number of leading zeros
1832 end=$(echo $end | sed 's/0*//')
1833 [[ -z "$end" ]] && end=0
1834 [[ $padlen2 -gt $padlen ]] && {
1835 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1838 begin=$(echo $begin | sed 's/0*//')
1839 [ -z $begin ] && begin=0
1841 for num in $(seq -f "%0${padlen}g" $begin $end); do
1842 value="${name#*,}${num}${back}"
1843 [ "$value" != "${value/\[/}" ] && {
1844 value=$(hostlist_expand "$value")
1846 myList="$myList $value"
1851 myList="$myList $item"
1854 myList=${myList//,/ }
1855 myList=${myList:1} # Remove first character which is a space
1857 # Filter any duplicates without sorting
1859 myList="${list%% *}"
1861 while [[ "$list" != ${myList##* } ]]; do
1862 list=${list//${list%% *} /}
1863 myList="$myList ${list%% *}"
1865 myList="${myList%* }";
1867 # We can select an object at a offset in the list
1870 for item in $myList; do
1872 [ $cnt -eq $offset ] && {
1876 [ $(get_node_count $myList) -ne 1 ] && myList=""
1884 [ "$facet" == client ] && echo -n $HOSTNAME && return
1885 varname=${facet}_HOST
1886 if [ -z "${!varname}" ]; then
1887 if [ "${facet:0:3}" == "ost" ]; then
1888 eval ${facet}_HOST=${ost_HOST}
1896 local activevar=${facet}active
1898 if [ -f $TMP/${facet}active ] ; then
1899 source $TMP/${facet}active
1902 active=${!activevar}
1903 if [ -z "$active" ] ; then
1910 facet_active_host() {
1912 local active=`facet_active $facet`
1913 if [ "$facet" == client ]; then
1916 echo `facet_host $active`
1924 facetlist=$(exclude_items_from_list $facetlist mgs)
1926 for facet in ${facetlist//,/ }; do
1927 local failover=${facet}failover
1928 local host=`facet_host $failover`
1929 [ -z "$host" ] && return
1931 local curactive=`facet_active $facet`
1932 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1933 eval export ${facet}active=$facet
1935 eval export ${facet}active=$failover
1937 # save the active host for this facet
1938 local activevar=${facet}active
1939 echo "$activevar=${!activevar}" > $TMP/$activevar
1940 [[ $facet = mds1 ]] && combined_mgs_mds && \
1941 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1942 local TO=`facet_active_host $facet`
1943 echo "Failover $facet to $TO"
1949 # do not stripe off hostname if verbose, bug 19215
1950 if [ x$1 = x--verbose ]; then
1958 if [ "$HOST" = "$HOSTNAME" ]; then
1960 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1961 echo "cannot run remote command on $HOST with $myPDSH"
1965 echo "CMD: $HOST $@" >&2
1966 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1969 if [ "$myPDSH" = "rsh" ]; then
1970 # we need this because rsh does not return exit code of an executed command
1971 local command_status="$TMP/cs"
1972 rsh $HOST ":> $command_status"
1973 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1974 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1975 echo command failed >$command_status"
1976 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1981 # print HOSTNAME for myPDSH="no_dsh"
1982 if [[ $myPDSH = no_dsh ]]; then
1983 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1985 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1988 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1990 return ${PIPESTATUS[0]}
1994 do_node --verbose "$@"
1997 single_local_node () {
1998 [ "$1" = "$HOSTNAME" ]
2001 # Outputs environment variable assignments that should be passed to remote nodes
2006 for var in ${!MODOPTS_*}; do
2008 echo "${var}=\"$value\""
2014 # do not stripe off hostname if verbose, bug 19215
2015 if [ x$1 = x--verbose ]; then
2023 if single_local_node $rnodes; then
2025 do_nodev $rnodes "$@"
2027 do_node $rnodes "$@"
2032 # This is part from do_node
2035 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2036 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2038 export FANOUT=$(get_node_count "${rnodes//,/ }")
2040 echo "CMD: $rnodes $@" >&2
2041 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2044 # do not replace anything from pdsh output if -N is used
2045 # -N Disable hostname: prefix on lines of output.
2046 if $verbose || [[ $myPDSH = *-N* ]]; then
2047 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2049 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2051 return ${PIPESTATUS[0]}
2057 local HOST=`facet_active_host $facet`
2058 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2063 do_nodes --verbose "$@"
2069 # make sure its not already running
2071 rm -f $TMP/${facet}active
2072 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2073 do_facet ${facet} $MKFS $*
2079 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2080 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
2087 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2088 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
2094 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2096 local var=${facet}_MOUNT
2097 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2106 # make sure we are using the primary server, so test-framework will
2107 # be able to clean up properly.
2108 activemds=`facet_active mds1`
2109 if [ $activemds != "mds1" ]; then
2113 local clients=$CLIENTS
2114 [ -z $clients ] && clients=$(hostname)
2116 zconf_umount_clients $clients $MOUNT "$*" || true
2117 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2119 [ "$CLIENTONLY" ] && return
2120 # The add fn does rm ${facet}active file, this would be enough
2121 # if we use do_facet <facet> only after the facet added, but
2122 # currently we use do_facet mds in local.sh
2123 for num in `seq $MDSCOUNT`; do
2125 rm -f ${TMP}/mds${num}active
2127 combined_mgs_mds && rm -f $TMP/mgsactive
2129 for num in `seq $OSTCOUNT`; do
2131 rm -f $TMP/ost${num}active
2134 if ! combined_mgs_mds ; then
2141 cleanup_echo_devs () {
2142 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2144 for dev in $devs; do
2145 $LCTL --device $dev cleanup
2146 $LCTL --device $dev detach
2151 nfs_client_mode && return
2160 combined_mgs_mds () {
2161 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2167 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2168 local optvar=${tgt}_MKFS_OPTS
2169 local opt=${!optvar}
2171 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2172 [[ $facet = mgs ]] && echo $opt && return
2175 # --failnode options
2176 local var=${facet}failover_HOST
2177 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2178 local failnode=$(h2$NETTYPE ${!var})
2179 failnode="--failnode=$failnode"
2180 # options does not contain
2181 # or contains wrong --failnode=
2182 if [[ $opt != *${failnode}* ]]; then
2183 opt=$(echo $opt | sed 's/--failnode=.* / /')
2184 opt="$opt $failnode"
2190 # no additional mkfs mds "--mgsnode" option for this configuration
2191 if [[ $facet = mds ]] && combined_mgs_mds; then
2196 # additional mkfs "--mgsnode"
2197 local mgsnode="--mgsnode=$MGSNID"
2198 opt=${opt//$mgsnode }
2199 for nid in ${MGSNID//:/ }; do
2200 local mgsnode="--mgsnode=$nid"
2201 # options does not contain
2203 if [[ $opt != *${mgsnode}" "* ]]; then
2204 opt="$opt --mgsnode=$nid"
2212 if [ "$IAMDIR" == "yes" ]; then
2213 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2216 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2219 # We need ldiskfs here, may as well load them all
2221 [ "$CLIENTONLY" ] && return
2222 echo Formatting mgs, mds, osts
2223 if ! combined_mgs_mds ; then
2224 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2227 for num in `seq $MDSCOUNT`; do
2228 echo "Format mds$num: $(mdsdevname $num)"
2230 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2232 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2236 # the ost-s could have different OST_MKFS_OPTS
2237 # because of different failnode-s
2238 for num in `seq $OSTCOUNT`; do
2239 echo "Format ost$num: $(ostdevname $num)"
2241 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2243 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2249 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2253 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2257 # 0: success, the old identity set already.
2258 # 1: success, the old identity does not set.
2263 local j=`expr $num - 1`
2264 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2266 if [ -z "$MDT" ]; then
2270 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2273 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2275 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2278 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2280 if [ $old = "NONE" ]; then
2289 zconf_umount `hostname` $1 || error "umount failed"
2290 zconf_mount `hostname` $1 || error "mount failed"
2293 writeconf_facet () {
2297 do_facet $facet "$TUNEFS --writeconf $dev"
2301 for num in `seq $MDSCOUNT`; do
2302 DEVNAME=$(mdsdevname $num)
2303 writeconf_facet mds$num $DEVNAME
2306 for num in `seq $OSTCOUNT`; do
2307 DEVNAME=$(ostdevname $num)
2308 writeconf_facet ost$num $DEVNAME
2313 nfs_client_mode && return
2315 sanity_mount_check ||
2316 error "environments are insane!"
2320 if [ -z "$CLIENTONLY" ]; then
2321 echo Setup mgs, mdt, osts
2322 echo $WRITECONF | grep -q "writeconf" && \
2324 if ! combined_mgs_mds ; then
2325 start mgs $MGSDEV $MGS_MOUNT_OPTS
2328 for num in `seq $MDSCOUNT`; do
2329 DEVNAME=$(mdsdevname $num)
2330 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2332 # We started mds, now we should set failover variables properly.
2333 # Set mds${num}failover_HOST if it is not set (the default failnode).
2334 local varname=mds${num}failover_HOST
2335 if [ -z "${!varname}" ]; then
2336 eval mds${num}failover_HOST=$(facet_host mds$num)
2339 if [ $IDENTITY_UPCALL != "default" ]; then
2340 switch_identity $num $IDENTITY_UPCALL
2343 for num in `seq $OSTCOUNT`; do
2344 DEVNAME=$(ostdevname $num)
2345 start ost$num $DEVNAME $OST_MOUNT_OPTS
2347 # We started ost$num, now we should set ost${num}failover variable properly.
2348 # Set ost${num}failover_HOST if it is not set (the default failnode).
2349 varname=ost${num}failover_HOST
2350 if [ -z "${!varname}" ]; then
2351 eval ost${num}failover_HOST=$(facet_host ost${num})
2359 # wait a while to allow sptlrpc configuration be propogated to targets,
2360 # only needed when mounting new target devices.
2365 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2367 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2370 if [ "$MOUNT_2" ]; then
2371 mount_client $MOUNT2
2372 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2377 # by remounting mdt before ost, initial connect from mdt to ost might
2378 # timeout because ost is not ready yet. wait some time to its fully
2379 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2380 # by a context negotiation rpc with $TIMEOUT.
2381 # FIXME better by monitoring import status.
2384 sleep $((TIMEOUT + 5))
2390 mounted_lustre_filesystems() {
2391 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2394 init_facet_vars () {
2395 [ "$CLIENTONLY" ] && return 0
2402 eval export ${facet}_dev=${device}
2403 eval export ${facet}_opt=\"$@\"
2405 local dev=${facet}_dev
2406 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2407 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2409 eval export ${facet}_svc=${label}
2411 local varname=${facet}failover_HOST
2412 if [ -z "${!varname}" ]; then
2413 eval $varname=$(facet_host $facet)
2416 # ${facet}failover_dev is set in cfg file
2417 varname=${facet}failover_dev
2418 if [ -n "${!varname}" ] ; then
2419 eval export ${facet}failover_dev=${!varname}
2421 eval export ${facet}failover_dev=$device
2424 # get mount point of already mounted device
2425 # is facet_dev is already mounted then use the real
2426 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2427 # i.e. ${facet}_MOUNT if specified by user or default
2428 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2429 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2430 if [ -z $mntpt ]; then
2431 mntpt=$(facet_mntpt $facet)
2433 eval export ${facet}_MOUNT=$mntpt
2436 init_facets_vars () {
2439 if ! remote_mds_nodsh; then
2440 for num in `seq $MDSCOUNT`; do
2441 DEVNAME=`mdsdevname $num`
2442 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2446 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2448 remote_ost_nodsh && return
2450 for num in `seq $OSTCOUNT`; do
2451 DEVNAME=`ostdevname $num`
2452 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2456 osc_ensure_active () {
2461 while [ $period -lt $timeout ]; do
2462 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2463 if [ $count -eq 0 ]; then
2467 echo "There are $count OST are inactive, wait $period seconds, and try again"
2469 period=$((period+3))
2472 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2475 init_param_vars () {
2477 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2479 log "Using TIMEOUT=$TIMEOUT"
2481 osc_ensure_active $SINGLEMDS $TIMEOUT
2482 osc_ensure_active client $TIMEOUT
2484 if [ $QUOTA_AUTO -ne 0 ]; then
2485 if [ "$ENABLE_QUOTA" ]; then
2486 echo "enable quota as required"
2487 setup_quota $MOUNT || return 2
2489 echo "disable quota as required"
2490 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2497 nfs_client_mode () {
2498 if [ "$NFSCLIENT" ]; then
2499 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2500 local clients=$CLIENTS
2501 [ -z $clients ] && clients=$(hostname)
2503 # FIXME: remove hostname when 19215 fixed
2504 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2505 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2506 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2507 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2509 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2515 check_config_client () {
2518 local mounted=$(mount | grep " $mntpt ")
2519 if [ "$CLIENTONLY" ]; then
2521 # CLIENTONLY should not depend on *_HOST settings
2522 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2523 # in theory someone could create a new,
2524 # client-only config file that assumed lustre was already
2525 # configured and didn't set the MGSNID. If MGSNID is not set,
2526 # then we should use the mgs nid currently being used
2527 # as the default value. bug 18021
2528 [[ x$MGSNID = x ]] &&
2531 if [[ x$mgc != xMGC$MGSNID ]]; then
2532 if [ "$mgs_HOST" ]; then
2533 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2534 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2535 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2541 local myMGS_host=$mgs_HOST
2542 if [ "$NETTYPE" = "ptl" ]; then
2543 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2546 echo Checking config lustre mounted on $mntpt
2547 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2548 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2550 # if [ "$mgshost" != "$myMGS_host" ]; then
2551 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2552 # Please use correct config or set mds_HOST correctly!"
2557 check_config_clients () {
2558 local clients=${CLIENTS:-$HOSTNAME}
2561 nfs_client_mode && return
2563 do_rpc_nodes $clients check_config_client $mntpt
2565 sanity_mount_check ||
2566 error "environments are insane!"
2570 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2571 local cltimeout=$(lctl get_param -n timeout)
2572 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2573 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2580 [ -z $mntpt ] && return 1
2581 local mounted=$(mounted_lustre_filesystems)
2583 echo $mounted' ' | grep -w -q $mntpt' '
2587 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2591 # empty lustre filesystem may have empty directories lost+found and .lustre
2593 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2594 -print | wc -l) = 1 ] || return 1
2595 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2596 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2600 check_and_setup_lustre() {
2601 nfs_client_mode && return
2603 local MOUNTED=$(mounted_lustre_filesystems)
2607 # both MOUNT and MOUNT2 are not mounted
2608 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2609 [ "$REFORMAT" ] && formatall
2610 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2612 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2613 export I_MOUNTED=yes
2617 elif is_mounted $MOUNT2; then
2619 # MOUNT2 is mounted, while MOUNT_2 is not set
2620 if ! [ "$MOUNT_2" ]; then
2621 cleanup_mount $MOUNT2
2622 export I_UMOUNTED2=yes
2625 # MOUNT2 is mounted, MOUNT_2 is set
2627 # FIXME: what to do if check_config failed?
2629 # 1) remote client has mounted other Lustre fs ?
2630 # 2) it has insane env ?
2631 # let's try umount MOUNT2 on all clients and mount it again:
2632 if ! check_config_clients $MOUNT2; then
2633 cleanup_mount $MOUNT2
2634 restore_mount $MOUNT2
2635 export I_MOUNTED2=yes
2640 # MOUNT is mounted MOUNT2 is not mounted
2641 elif [ "$MOUNT_2" ]; then
2642 restore_mount $MOUNT2
2643 export I_MOUNTED2=yes
2647 # FIXME: what to do if check_config failed?
2649 # 1) remote client has mounted other Lustre fs?
2650 # 2) lustre is mounted on remote_clients atall ?
2651 check_config_clients $MOUNT
2655 set_default_debug_nodes $(comma_list $(nodes_list))
2661 if [ "$ONLY" == "setup" ]; then
2667 local clients=${CLIENTS:-$HOSTNAME}
2670 zconf_mount_clients $clients $mntpt
2674 local clients=${CLIENTS:-$HOSTNAME}
2677 zconf_umount_clients $clients $mntpt
2680 cleanup_and_setup_lustre() {
2681 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2682 lctl set_param debug=0 || true
2684 if [ "$ONLY" == "cleanup" ]; then
2688 check_and_setup_lustre
2691 # Get all of the server target devices from a given server node and type.
2700 mdt) obd_type="osd" ;;
2701 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2702 *) echo "invalid server type" && return 1 ;;
2705 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2706 for dev in $devs; do
2708 *loop*) do_node $node "losetup $dev" | \
2709 sed -e "s/.*(//" -e "s/).*//" ;;
2715 # Get all of the server target devices.
2720 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2724 for node in $(osts_nodes); do
2725 OSTDEVS[i]=$(get_mnt_devs $node ost)
2730 # Run e2fsck on MDT or OST device.
2736 df > /dev/null # update statfs data on disk
2737 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2740 do_node $node $cmd || rc=$?
2741 [ $rc -le $FSCK_MAX_ERR ] || \
2742 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2746 # verify a directory is shared among nodes.
2747 check_shared_dir() {
2750 [ -z "$dir" ] && return 1
2751 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2752 check_write_access $dir || return 1
2756 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2762 check_shared_dir $SHARED_DIRECTORY ||
2763 error "$SHARED_DIRECTORY isn't a shared directory"
2765 export MDSDB=$SHARED_DIRECTORY/mdsdb
2766 export OSTDB=$SHARED_DIRECTORY/ostdb
2768 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2770 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2775 for node in $(osts_nodes); do
2776 for dev in ${OSTDEVS[i]}; do
2777 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2778 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2779 ostidx=$((ostidx + 1))
2786 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2790 [ $rc -le $FSCK_MAX_ERR ] || \
2791 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2792 echo "lfsck finished with rc=$rc"
2794 rm -rvf $MDSDB* $OSTDB* || true
2798 check_and_cleanup_lustre() {
2799 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2805 if is_mounted $MOUNT; then
2806 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
2807 error "remove sub-test dirs failed"
2808 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2811 if [ "$I_UMOUNTED2" = "yes" ]; then
2812 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2815 if [ "$I_MOUNTED2" = "yes" ]; then
2816 cleanup_mount $MOUNT2
2819 if [ "$I_MOUNTED" = "yes" ]; then
2820 cleanupall -f || error "cleanup failed"
2828 wait_for_function () {
2831 # suppress fn both stderr and stdout
2832 if [ "$1" = "--quiet" ]; then
2834 quiet=" > /dev/null 2>&1"
2846 eval $fn $quiet && return 0
2848 wait=$((wait + sleep))
2849 [ $wait -lt $max ] || return 1
2850 echo waiting $fn, $((max - wait)) secs left ...
2860 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2861 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2862 echo "Network not available!"
2866 echo `date +"%H:%M:%S (%s)"` network interface is UP
2875 # the sed converts spaces to commas, but leaves the last space
2876 # alone, so the line doesn't end with a comma.
2877 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2883 echo $list | grep -qw $item
2886 # list, excluded are the comma separated lists
2887 exclude_items_from_list () {
2893 for item in ${excluded//,/ }; do
2894 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2896 echo $(comma_list $list)
2899 # list, expand are the comma separated lists
2901 local list=${1//,/ }
2902 local expand=${2//,/ }
2905 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2906 echo $(comma_list $expanded)
2909 testslist_filter () {
2910 local script=$LUSTRE/tests/${TESTSUITE}.sh
2912 [ -f $script ] || return 0
2914 local start_at=$START_AT
2915 local stop_at=$STOP_AT
2917 local var=${TESTSUITE//-/_}_START_AT
2918 [ x"${!var}" != x ] && start_at=${!var}
2919 var=${TESTSUITE//-/_}_STOP_AT
2920 [ x"${!var}" != x ] && stop_at=${!var}
2922 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2923 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2924 /^'${start_at}'$/ {flag = 0}
2925 {if (flag == 1) print $0}
2926 /^'${stop_at}'$/ { flag = 1 }'
2930 (cd `dirname $1`; echo $PWD/`basename $1`)
2934 local types=${1:-"OST MDS MGS"}
2938 for entry in $types; do
2939 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2940 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2943 MGS ) list="$list $name";;
2944 MDS|OST ) local count=${type}COUNT
2945 for ((i=1; i<=${!count}; i++)) do
2946 list="$list ${name}$i"
2948 * ) error "Invalid facet type"
2952 echo $(comma_list $list)
2955 ##################################
2956 # Adaptive Timeouts funcs
2959 # only check mds, we assume at_max is the same on all nodes
2960 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2961 if [ $at_max -eq 0 ]; then
2972 # suppose that all ost-s have the same $at value set
2973 [ $facet != "ost" ] || facet=ost1
2975 do_facet $facet "lctl get_param -n $at"
2989 if [ $facet == "ost" ]; then
2990 facet=$(get_facets OST)
2991 elif [ $facet == "mds" ]; then
2992 facet=$(get_facets MDS)
2994 hosts=$(expand_list $hosts $(facets_hosts $facet))
2997 do_nodes $hosts lctl set_param at_max=$at_max
3000 ##################################
3004 # OBD_FAIL_MDS_ALL_REQUEST_NET
3006 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
3007 do_facet client "$1" || RC=$?
3008 do_facet $SINGLEMDS lctl set_param fail_loc=0
3013 # OBD_FAIL_MDS_ALL_REPLY_NET
3015 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
3016 do_facet client "$@" || RC=$?
3017 do_facet $SINGLEMDS lctl set_param fail_loc=0
3021 drop_reint_reply() {
3022 # OBD_FAIL_MDS_REINT_NET_REP
3024 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3025 do_facet client "$@" || RC=$?
3026 do_facet $SINGLEMDS lctl set_param fail_loc=0
3031 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3033 do_facet ost1 lctl set_param fail_loc=0x214
3034 do_facet client "$1" || RC=$?
3035 do_facet client "sync"
3036 do_facet ost1 lctl set_param fail_loc=0
3040 drop_ldlm_cancel() {
3041 #define OBD_FAIL_LDLM_CANCEL 0x304
3043 do_facet client lctl set_param fail_loc=0x304
3044 do_facet client "$@" || RC=$?
3045 do_facet client lctl set_param fail_loc=0
3049 drop_bl_callback() {
3050 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3052 do_facet client lctl set_param fail_loc=0x305
3053 do_facet client "$@" || RC=$?
3054 do_facet client lctl set_param fail_loc=0
3059 #define OBD_FAIL_LDLM_REPLY 0x30c
3061 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3062 do_facet client "$@" || RC=$?
3063 do_facet $SINGLEMDS lctl set_param fail_loc=0
3071 echo "clearing fail_loc on $facet"
3072 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3075 set_nodes_failloc () {
3076 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3079 cancel_lru_locks() {
3080 $LCTL mark "cancel_lru_locks $1 start"
3081 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3082 $LCTL set_param -n $d=clear
3084 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3085 $LCTL mark "cancel_lru_locks $1 stop"
3090 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3091 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3092 echo "$DEFAULT_LRU_SIZE"
3097 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3100 lru_resize_disable()
3102 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3107 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3108 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3109 echo there is still data in page cache $FILE ?
3110 lctl get_param -n $FILE
3118 DEBUGSAVE="$(lctl get_param -n debug)"
3122 [ -n "$DEBUGSAVE" ] && \
3123 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3128 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3131 debug_size_restore() {
3132 [ -n "$DEBUG_SIZE_SAVED" ] && \
3133 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3137 start_full_debug_logging() {
3142 local DEBUG_SIZE=150
3144 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3145 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3148 stop_full_debug_logging() {
3153 ##################################
3155 ##################################
3158 local TYPE=${TYPE:-"FAIL"}
3161 # do not dump logs if $1=false
3162 if [ "x$1" = "xfalse" ]; then
3167 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3170 # We need to dump the logs on all nodes
3172 gather_logs $(comma_list $(nodes_list))
3176 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3177 echo "$@" > $LOGDIR/err
3182 local log=$TESTSUITELOG
3184 [ -f "$log" ] && grep -q FAIL: $log && status=1
3197 # use only if we are ignoring failures for this test, bugno required.
3198 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3199 # e.g. error_ignore 5494 "your message"
3201 local TYPE="IGNORE (bz$1)"
3207 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3212 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3213 [ "$ALWAYS_SKIPPED" ] && \
3214 skip_logged ${TESTNAME} "$@" || true
3215 [ "$TESTSUITELOG" ] && \
3216 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3219 build_test_filter() {
3220 EXCEPT="$EXCEPT $(testslist_filter)"
3222 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3226 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3227 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3228 [ "$EXCEPT_SLOW" ] && \
3229 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3230 for E in $EXCEPT; do
3231 eval EXCEPT_${E}=true
3233 for E in $ALWAYS_EXCEPT; do
3234 eval EXCEPT_ALWAYS_${E}=true
3236 for E in $EXCEPT_SLOW; do
3237 eval EXCEPT_SLOW_${E}=true
3239 for G in $GRANT_CHECK_LIST; do
3240 eval GCHECK_ONLY_${G}=true
3245 if [[ $1 = [a-z]* ]]; then
3252 # print a newline if the last test was skipped
3253 export LAST_SKIPPED=
3254 export ALWAYS_SKIPPED=
3256 # Main entry into test-framework. This is called with the name and
3257 # description of a test. The name is used to find the function to run
3258 # the test using "test_$name".
3260 # This supports a variety of methods of specifying specific test to
3261 # run or not run. These need to be documented...
3266 export base=`basetest $1`
3267 if [ ! -z "$ONLY" ]; then
3269 if [ ${!testname}x != x ]; then
3270 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3271 run_one_logged $1 "$2"
3275 if [ ${!testname}x != x ]; then
3276 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3277 run_one_logged $1 "$2"
3285 if [ ${!testname}x != x ]; then
3287 TESTNAME=test_$1 skip "skipping excluded test $1"
3290 testname=EXCEPT_$base
3291 if [ ${!testname}x != x ]; then
3293 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3296 testname=EXCEPT_ALWAYS_$1
3297 if [ ${!testname}x != x ]; then
3300 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3303 testname=EXCEPT_ALWAYS_$base
3304 if [ ${!testname}x != x ]; then
3307 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3310 testname=EXCEPT_SLOW_$1
3311 if [ ${!testname}x != x ]; then
3313 TESTNAME=test_$1 skip "skipping SLOW test $1"
3316 testname=EXCEPT_SLOW_$base
3317 if [ ${!testname}x != x ]; then
3319 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3325 run_one_logged $1 "$2"
3336 module_loaded lnet || load_modules
3348 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3353 strace -o $TMP/$1.strace -ttt $*
3355 log "FINISHED: $*: rc $RC"
3360 equals_msg $1 test complete, duration $2 sec
3361 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3362 echo duration $2 >>$TESTSUITELOG
3366 # Set TEST_STATUS here; will be used for logging the result
3367 if [ -f $LOGDIR/err ]; then
3372 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3376 local FFREE=$(do_node $SINGLEMDS \
3377 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3378 local FTOTAL=$(do_node $SINGLEMDS \
3379 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3381 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3385 echo -n "Resetting fail_loc on all nodes..."
3386 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3392 # Log a message (on all nodes) padded with "=" before and after.
3393 # Also appends a timestamp and prepends the testsuite name.
3396 EQUALS="===================================================================================================="
3398 msg="== ${TESTSUITE} $*"
3400 [[ $last != "=" && $last != " " ]] && msg="$msg "
3401 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3402 # always include at least == after the message
3403 log "$msg== $(date +"%H:%M:%S (%s)")"
3407 # Run a single test function and cleanup after it.
3409 # This function should be run in a subshell so the test func can
3410 # exit() without stopping the whole script.
3416 export tdir=d0.${TESTSUITE}/d${base}
3417 export TESTNAME=test_$testnum
3418 local SAVE_UMASK=`umask`
3421 banner "test $testnum: $message"
3422 test_${testnum} || error "test_$testnum failed with $?"
3425 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3426 check_catastrophe || error "LBUG/LASSERT detected"
3427 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3435 # Wrapper around run_one to ensure:
3436 # - test runs in subshell
3437 # - output of test is saved to separate log file for error reporting
3438 # - test result is saved to data file
3441 local BEFORE=`date +%s`
3443 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3444 local test_log=$LOGDIR/$name
3446 local SAVE_UMASK=`umask`
3450 log_sub_test_begin test_${1}
3451 (run_one $1 "$2") 2>&1 | tee -i $test_log
3452 local RC=${PIPESTATUS[0]}
3454 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3455 echo "test_$1 returned $RC" | tee $LOGDIR/err
3457 duration=$((`date +%s` - $BEFORE))
3458 pass "$1" "(${duration}s)"
3459 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3460 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3462 if [ -f $LOGDIR/err ]; then
3463 $FAIL_ON_ERROR && exit $RC
3472 # Print information of skipped tests to result.yml
3475 log_sub_test_begin $1
3476 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3480 (cd `dirname $1`; echo $PWD/`basename $1`)
3485 export base=`basetest $1`
3486 [ "$CHECK_GRANT" == "no" ] && return 0
3488 testname=GCHECK_ONLY_${base}
3489 [ ${!testname}x == x ] && return 0
3491 echo -n "checking grant......"
3493 local clients=$CLIENTS
3494 [ -z $clients ] && clients=$(hostname)
3496 # sync all the data and make sure no pending data on server
3497 do_nodes $clients sync
3500 client_grant=`do_nodes $clients \
3501 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3502 awk '{total += $1} END{print total}'`
3505 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3506 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3507 awk '{total += $1} END{print total}'`
3509 # check whether client grant == server grant
3510 if [ $client_grant -ne $server_grant ]; then
3511 echo "failed: client:${client_grant} server: ${server_grant}."
3512 do_nodes $(comma_list $(osts_nodes)) \
3513 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3514 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3517 echo "pass: client:${client_grant} server: ${server_grant}"
3522 ########################
3528 ost=`echo $1 | awk -F_ '{print $3}'`
3529 if [ -z $ost ]; then
3530 ost=`echo $1 | sed 's/-osc.*//'`
3535 ostuuid_from_index()
3537 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3540 ostname_from_index() {
3541 local uuid=$(ostuuid_from_index $1)
3545 index_from_ostuuid()
3547 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3550 mdtuuid_from_index()
3552 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3557 [ "$node" != "$(hostname)" ]
3563 for node in $(mdts_nodes); do
3564 remote_node $node && return 0
3571 [ "$CLIENTONLY" ] && return 0 || true
3572 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3577 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3578 MSKIPPED=1 && return 1
3585 for node in $(osts_nodes) ; do
3586 remote_node $node && return 0
3593 [ "$CLIENTONLY" ] && return 0 || true
3594 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3599 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3600 OSKIPPED=1 && return 1
3607 MGS=$(facet_host mgs)
3608 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3613 remote_mds_nodsh || remote_ost_nodsh || \
3614 $(single_local_node $(comma_list $(nodes_list)))
3620 for num in `seq $MDSCOUNT`; do
3621 MDSNODES="$MDSNODES $(facet_host mds$num)"
3623 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3629 remote_ost && remote_mds
3637 for facet in ${facets//,/ }; do
3638 if [ "$FAILURE_MODE" = HARD ]; then
3639 nodes="$nodes $(facet_active_host $facet)"
3641 nodes="$nodes $(facet_host $facet)"
3644 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3650 local facets=$(get_facets OST)
3651 local nodes=$(facets_nodes $facets)
3657 # FIXME. We need a list of clients
3658 local myNODES=$HOSTNAME
3661 # CLIENTS (if specified) contains the local client
3662 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3664 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3665 myNODES="$myNODES $(facets_nodes $(get_facets))"
3668 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3673 remote_nodes_list () {
3674 local rnodes=$(nodes_list)
3675 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3679 init_clients_lists () {
3680 # Sanity check: exclude the local client from RCLIENTS
3681 local clients=$(hostlist_expand "$RCLIENTS")
3682 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3684 # Sanity check: exclude the dup entries
3685 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3687 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3689 # Sanity check: exclude the dup entries from CLIENTS
3690 # for those configs which has SINGLCLIENT set to local client
3691 clients=$(for i in $clients; do echo $i; done | sort -u)
3693 CLIENTS=$(comma_list $clients)
3694 local -a remoteclients=($RCLIENTS)
3695 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3696 varname=CLIENT$((i + 2))
3697 eval $varname=${remoteclients[i]}
3700 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3703 get_random_entry () {
3706 rnodes=${rnodes//,/ }
3708 local -a nodes=($rnodes)
3709 local num=${#nodes[@]}
3710 local i=$((RANDOM * num * 2 / 65536))
3716 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3721 lctl get_param version | grep -q patchless
3725 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
3726 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
3731 echo $nodes | wc -w || true
3735 local nodes=$(osts_nodes)
3736 local osscount=$(get_node_count "$nodes")
3737 [ ! "$OSTCOUNT" = "$osscount" ]
3741 local nodes=$(mdts_nodes)
3742 local mdtcount=$(get_node_count "$nodes")
3743 [ ! "$MDSCOUNT" = "$mdtcount" ]
3746 generate_machine_file() {
3747 local nodes=${1//,/ }
3748 local machinefile=$2
3750 for node in $nodes; do
3751 echo $node >>$machinefile || \
3752 { echo "can not generate machinefile $machinefile" && return 1; }
3757 local file=$1/stripe
3759 $LFS getstripe -v $file || error
3763 setstripe_nfsserver () {
3766 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3767 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3769 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3771 do_nodev $nfsserver lfs setstripe "$@"
3774 check_runas_id_ret() {
3776 local myRUNAS_UID=$1
3777 local myRUNAS_GID=$2
3780 if [ -z "$myRUNAS" ]; then
3781 error_exit "myRUNAS command must be specified for check_runas_id"
3784 $myRUNAS krb5_login.sh || \
3785 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3787 mkdir $DIR/d0_runas_test
3789 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3790 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3791 rm -rf $DIR/d0_runas_test
3796 local myRUNAS_UID=$1
3797 local myRUNAS_GID=$2
3800 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3801 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3802 Please set RUNAS_ID to some UID which exists on MDS and client or
3803 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3806 # obtain the UID/GID for MPI_USER
3810 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3811 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3813 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3814 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3817 # obtain and cache Kerberos ticket-granting ticket
3818 refresh_krb5_tgt() {
3819 local myRUNAS_UID=$1
3820 local myRUNAS_GID=$2
3823 if [ -z "$myRUNAS" ]; then
3824 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3827 CLIENTS=${CLIENTS:-$HOSTNAME}
3828 do_nodes $CLIENTS "set -x
3829 if ! $myRUNAS krb5_login.sh; then
3830 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3835 # Run multiop in the background, but wait for it to print
3836 # "PAUSING" to its stdout before returning from this function.
3837 multiop_bg_pause() {
3838 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
3842 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3845 echo "$MULTIOP_PROG $FILE v$ARGS"
3846 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3848 echo "TMPPIPE=${TMPPIPE}"
3849 read -t 60 multiop_output < $TMPPIPE
3850 if [ $? -ne 0 ]; then
3855 if [ "$multiop_output" != "PAUSING" ]; then
3856 echo "Incorrect multiop output: $multiop_output"
3871 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3877 inodes_available () {
3878 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3882 mdsrate_inodes_available () {
3883 local min_inodes=$(inodes_available)
3884 echo $((min_inodes * 99 / 100))
3887 # reset llite stat counters
3888 clear_llite_stats(){
3889 lctl set_param -n llite.*.stats 0
3892 # sum llite stat items
3893 calc_llite_stats() {
3894 local res=$(lctl get_param -n llite.*.stats |
3895 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3899 # reset osc stat counters
3901 lctl set_param -n osc.*.osc_stats 0
3904 # sum osc stat items
3906 local res=$(lctl get_param -n osc.*.osc_stats |
3907 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3912 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3915 calc_osc_kbytes () {
3916 df $MOUNT > /dev/null
3917 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3920 # save_lustre_params(node, parameter_mask)
3921 # generate a stream of formatted strings (<node> <param name>=<param value>)
3922 save_lustre_params() {
3924 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3927 # restore lustre parameters from input stream, produces by save_lustre_params
3928 restore_lustre_params() {
3932 while IFS=" =" read node name val; do
3933 do_node ${node//:/} "lctl set_param -n $name $val"
3937 check_catastrophe() {
3938 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3939 local C=$CATASTROPHE
3940 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3942 if [ $rnodes ]; then
3943 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3944 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3949 # CMD: determine mds index where directory inode presents
3952 local file=$dir/f0.get_mds_dir_tmpfile
3957 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3958 local -a oldused=($iused)
3960 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3962 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3963 local -a newused=($iused)
3966 for ((i=0; i<${#newused[@]}; i++)); do
3967 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3973 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3976 mdsrate_cleanup () {
3978 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3983 delayed_recovery_enabled () {
3984 local var=${SINGLEMDS}_svc
3985 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3988 ########################
3990 convert_facet2label() {
3993 if [ x$facet = xost ]; then
3997 local varsvc=${facet}_svc
3999 if [ -n ${!varsvc} ]; then
4002 error "No lablel for $facet!"
4006 get_clientosc_proc_path() {
4007 echo "${1}-osc-[^M]*"
4010 get_lustre_version () {
4011 local facet=${1:-"$SINGLEMDS"}
4012 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
4015 lustre_version_code() {
4016 local facet=${1:-"$SINGLEMDS"}
4017 version_code $(get_lustre_version $1)
4020 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4021 # used by MDT would not be changed.
4022 # mdt lov: fsname-mdtlov
4023 # mdt osc: fsname-OSTXXXX-osc
4024 mds_on_old_device() {
4025 local mds=${1:-"$SINGLEMDS"}
4027 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
4028 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4029 > /dev/null 2>&1" && return 0
4034 get_mdtosc_proc_path() {
4036 local ost_label=${2:-"*OST*"}
4038 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4039 local mdt_label=$(convert_facet2label $mds_facet)
4040 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4042 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
4043 mds_on_old_device $mds_facet; then
4044 echo "${ost_label}-osc"
4046 echo "${ost_label}-osc-${mdt_index}"
4050 get_osc_import_name() {
4053 local label=$(convert_facet2label $ost)
4055 if [ "${facet:0:3}" = "mds" ]; then
4056 get_mdtosc_proc_path $facet $label
4060 get_clientosc_proc_path $label
4064 _wait_import_state () {
4067 local maxtime=${3:-$(max_recovery_time)}
4071 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4072 while [ "${CONN_STATE}" != "${expected}" ]; do
4073 if [ "${expected}" == "DISCONN" ]; then
4074 # for disconn we can check after proc entry is removed
4075 [ "x${CONN_STATE}" == "x" ] && return 0
4076 # with AT enabled, we can have connect request timeout near of
4077 # reconnect timeout and test can't see real disconnect
4078 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4080 [ $i -ge $maxtime ] && \
4081 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4084 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4088 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4092 wait_import_state() {
4095 local maxtime=${3:-$(max_recovery_time)}
4098 for param in ${params//,/ }; do
4099 _wait_import_state $state $param $maxtime || return
4103 # One client request could be timed out because server was not ready
4104 # when request was sent by client.
4105 # The request timeout calculation details :
4107 # /* We give the server rq_timeout secs to process the req, and
4108 # add the network latency for our local timeout. */
4109 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4110 # ptlrpc_at_get_net_latency(request) ;
4112 # ptlrpc_connect_import ()
4113 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4116 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4117 # ptlrpc_at_get_net_latency(request) ->
4118 # at_get (max (iat_net_latency=0, at_min)) = at_min
4121 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4122 # INITIAL_CONNECT_TIMEOUT + at_min
4124 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4125 # because we can not get this value in runtime,
4126 # the value depends on configure options, and it is not stored in /proc.
4128 # #define CONNECTION_SWITCH_MIN 5U
4129 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4131 request_timeout () {
4134 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4135 local init_connect_timeout=$TIMEOUT
4136 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4138 local at_min=$(at_get $facet at_min)
4140 echo $(( init_connect_timeout + at_min ))
4143 wait_osc_import_state() {
4147 local ost=$(get_osc_import_name $facet $ost_facet)
4149 local param="osc.${ost}.ost_server_uuid"
4151 # 1. wait the deadline of client 1st request (it could be skipped)
4152 # 2. wait the deadline of client 2nd request
4153 local maxtime=$(( 2 * $(request_timeout $facet)))
4155 if ! do_rpc_nodes $(facet_host $facet) \
4156 _wait_import_state $expected $param $maxtime; then
4157 error "import is not in ${expected} state"
4164 get_clientmdc_proc_path() {
4172 # Add paths to lustre tests for 32 and 64 bit systems.
4173 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4174 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4177 wait_clients_import_state () {
4184 if [ "$FAILURE_MODE" = HARD ]; then
4185 facets=$(facets_on_host $(facet_active_host $facet))
4188 for facet in ${facets//,/ }; do
4189 local label=$(convert_facet2label $facet)
4192 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4193 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4194 *) error "unknown facet!" ;;
4196 local params=$(expand_list $params $proc_path)
4199 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4200 error "import is not in ${expected} state"
4209 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4210 $LCTL get_param obdfilter.*.kbytesavail))
4211 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4212 $LCTL get_param -n obdfilter.*.tot_granted))
4213 for ((i=0; i<${#AVAILA[@]}; i++)); do
4214 local -a AVAIL1=(${AVAILA[$i]//=/ })
4215 GRANT=$((${GRANTA[$i]}/1024))
4216 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4217 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4223 do_facet mgs lctl pool_list $1
4227 local fsname=${1%%.*}
4228 local poolname=${1##$fsname.}
4230 do_facet mgs lctl pool_new $1
4232 # get param should return err unless pool is created
4233 [[ $RC -ne 0 ]] && return $RC
4235 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4236 2>/dev/null || echo foo" "" || RC=1
4237 if [[ $RC -eq 0 ]]; then
4240 error "pool_new failed $1"
4245 add_pool_to_list () {
4246 local fsname=${1%%.*}
4247 local poolname=${1##$fsname.}
4249 local listvar=${fsname}_CREATED_POOLS
4250 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4253 remove_pool_from_list () {
4254 local fsname=${1%%.*}
4255 local poolname=${1##$fsname.}
4257 local listvar=${fsname}_CREATED_POOLS
4258 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4261 destroy_pool_int() {
4263 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4264 awk '$1 !~ /^Pool:/ {print $1}')
4265 for ost in $OSTS; do
4266 do_facet mgs lctl pool_remove $1 $ost
4268 do_facet mgs lctl pool_destroy $1
4271 # <fsname>.<poolname> or <poolname>
4273 local fsname=${1%%.*}
4274 local poolname=${1##$fsname.}
4276 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4280 pool_list $fsname.$poolname || return $?
4282 destroy_pool_int $fsname.$poolname
4284 [[ $RC -ne 0 ]] && return $RC
4286 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4287 2>/dev/null || echo foo" "foo" || RC=1
4289 if [[ $RC -eq 0 ]]; then
4290 remove_pool_from_list $fsname.$poolname
4292 error "destroy pool failed $1"
4298 local fsname=${1:-$FSNAME}
4300 local listvar=${fsname}_CREATED_POOLS
4304 [ x${!listvar} = x ] && return 0
4306 echo destroy the created pools: ${!listvar}
4307 for poolname in ${!listvar//,/ }; do
4308 destroy_pool $fsname.$poolname
4313 local fsname=${1:-$FSNAME}
4315 destroy_pools $fsname
4321 local ts=$(date +%s)
4324 if [[ ! -f "$YAML_LOG" ]]; then
4325 # init_logging is not performed before gather_logs,
4326 # so the $LOGDIR needs to be checked here
4327 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4330 [ -f $LOGDIR/shared ] && docp=false
4332 # dump lustre logs, dmesg
4334 prefix="$TESTLOG_PREFIX.$TESTNAME"
4336 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4338 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4339 echo "Dumping logs only on local client."
4340 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4341 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4346 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4347 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4348 if [ ! -f $LOGDIR/shared ]; then
4349 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4362 for i in $(seq 0 $num_mntpts); do
4363 cmd="ls -laf ${mntpt_root}$i/$dir"
4369 for pid in $pids; do
4376 # target_start_and_reset_recovery_timer()
4377 # service_time = at_est2timeout(service_time);
4378 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4379 # INITIAL_CONNECT_TIMEOUT);
4380 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4381 #define CONNECTION_SWITCH_INC 1
4382 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4383 #define CONNECTION_SWITCH_MIN 5U
4385 max_recovery_time () {
4386 local init_connect_timeout=$(( TIMEOUT / 20 ))
4387 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4389 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4394 get_clients_mount_count () {
4395 local clients=${CLIENTS:-`hostname`}
4397 # we need to take into account the clients mounts and
4398 # exclude mds/ost mounts if any;
4399 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4403 PROC_CLI="srpc_info"
4411 if [ $M -lt $N ]; then
4415 while [ $N -lt $M ]; do
4425 calc_connection_cnt() {
4428 # MDT->MDT = 2 * C(M, 2)
4432 comb_m2=$(combination $MDSCOUNT 2)
4434 local num_clients=$(get_clients_mount_count)
4436 local cnt_mdt2mdt=$((comb_m2 * 2))
4437 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4438 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4439 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4440 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4441 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4442 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4456 local cmd="$tgt.srpc.flavor"
4458 if [ $net == "any" ]; then
4463 if [ $dir != "any" ]; then
4468 log "Setting sptlrpc rule: $cmd"
4469 do_facet mgs "$LCTL conf_param $cmd"
4478 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4479 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4481 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4483 if [ "x$bulkspec" != "x" ]; then
4484 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4486 if [ "x$algs" != "x" ]; then
4487 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4489 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4490 if [ $bulk == "bulkn" ]; then
4491 bulk_count=`echo "$output" | grep "bulk flavor" \
4492 | grep "null/null" | wc -l`
4493 elif [ $bulk == "bulki" ]; then
4494 bulk_count=`echo "$output" | grep "bulk flavor" \
4495 | grep "/null" | grep -v "null/" | wc -l`
4497 bulk_count=`echo "$output" | grep "bulk flavor" \
4498 | grep -v "/null" | grep -v "null/" | wc -l`
4502 [ $bulk_count -lt $count ] && count=$bulk_count
4513 local clients=${CLIENTS:-`hostname`}
4515 for c in ${clients//,/ }; do
4516 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4517 tmpcnt=`count_flvr "$output" $flavor`
4518 cnt=$((cnt + tmpcnt))
4528 local clients=${CLIENTS:-`hostname`}
4530 for c in ${clients//,/ }; do
4531 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4532 tmpcnt=`count_flvr "$output" $flavor`
4533 cnt=$((cnt + tmpcnt))
4543 if [ $MDSCOUNT -le 1 ]; then
4548 for num in `seq $MDSCOUNT`; do
4549 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4550 tmpcnt=`count_flvr "$output" $flavor`
4551 cnt=$((cnt + tmpcnt))
4562 for num in `seq $MDSCOUNT`; do
4563 mdtosc=$(get_mdtosc_proc_path mds$num)
4564 mdtosc=${mdtosc/-MDT*/-MDT\*}
4565 output=$(do_facet mds$num lctl get_param -n \
4566 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4567 tmpcnt=`count_flvr "$output" $flavor`
4568 cnt=$((cnt + tmpcnt))
4577 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4578 count_flvr "$output" $flavor
4583 local dir=$1 # from to
4584 local flavor=$2 # flavor expected
4587 if [ $dir == "cli2mdt" ]; then
4588 res=`flvr_cnt_cli2mdt $flavor`
4589 elif [ $dir == "cli2ost" ]; then
4590 res=`flvr_cnt_cli2ost $flavor`
4591 elif [ $dir == "mdt2mdt" ]; then
4592 res=`flvr_cnt_mdt2mdt $flavor`
4593 elif [ $dir == "mdt2ost" ]; then
4594 res=`flvr_cnt_mdt2ost $flavor`
4595 elif [ $dir == "all2ost" ]; then
4596 res1=`flvr_cnt_mdt2ost $flavor`
4597 res2=`flvr_cnt_cli2ost $flavor`
4598 res=$((res1 + res2))
4599 elif [ $dir == "all2mdt" ]; then
4600 res1=`flvr_cnt_mdt2mdt $flavor`
4601 res2=`flvr_cnt_cli2mdt $flavor`
4602 res=$((res1 + res2))
4603 elif [ $dir == "all2all" ]; then
4604 res1=`flvr_cnt_mdt2ost $flavor`
4605 res2=`flvr_cnt_cli2ost $flavor`
4606 res3=`flvr_cnt_mdt2mdt $flavor`
4607 res4=`flvr_cnt_cli2mdt $flavor`
4608 res=$((res1 + res2 + res3 + res4))
4616 local dir=$1 # from to
4617 local flavor=$2 # flavor expected
4618 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4622 for ((i=0;i<20;i++)); do
4623 echo -n "checking $dir..."
4624 res=$(do_check_flavor $dir $flavor)
4625 echo "found $res/$expect $flavor connections"
4626 [ $res -ge $expect ] && return 0
4630 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4634 restore_to_default_flavor()
4636 local proc="mgs.MGS.live.$FSNAME"
4638 echo "restoring to default flavor..."
4640 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4642 # remove all existing rules if any
4643 if [ $nrule -ne 0 ]; then
4644 echo "$nrule existing rules"
4645 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4646 echo "remove rule: $rule"
4647 spec=`echo $rule | awk -F = '{print $1}'`
4648 do_facet mgs "$LCTL conf_param -d $spec"
4652 # verify no rules left
4653 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4654 [ $nrule -ne 0 ] && error "still $nrule rules left"
4656 # wait for default flavor to be applied
4657 # currently default flavor for all connections are 'null'
4658 wait_flavor all2all null
4659 echo "now at default flavor settings"
4664 local flavor=${1:-null}
4666 echo "setting all flavor to $flavor"
4668 # FIXME need parameter to this fn
4669 # and remove global vars
4670 local cnt_all2all=$(calc_connection_cnt all2all)
4672 local res=$(do_check_flavor all2all $flavor)
4673 if [ $res -eq $cnt_all2all ]; then
4674 echo "already have total $res $flavor connections"
4678 echo "found $res $flavor out of total $cnt_all2all connections"
4679 restore_to_default_flavor
4681 [[ $flavor = null ]] && return 0
4683 set_rule $FSNAME any any $flavor
4684 wait_flavor all2all $flavor
4690 # Checking for shared logdir
4691 if [ ! -d $dir ]; then
4692 # Not found. Create local logdir
4695 touch $dir/check_file.$(hostname -s)
4700 check_write_access() {
4705 for node in $(nodes_list); do
4706 file=$dir/check_file.$(short_hostname $node)
4707 if [[ ! -f "$file" ]]; then
4708 # Logdir not accessible/writable from this node.
4711 rm -f $file || return 1
4717 if [[ -n $YAML_LOG ]]; then
4720 local SAVE_UMASK=`umask`
4723 export YAML_LOG=${LOGDIR}/results.yml
4727 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
4728 if check_shared_dir $LOGDIR; then
4729 touch $LOGDIR/shared
4730 echo "Logging to shared log directory: $LOGDIR"
4732 echo "Logging to local directory: $LOGDIR"
4735 yml_nodes_file $LOGDIR >> $YAML_LOG
4736 yml_results_file >> $YAML_LOG
4743 yml_log_test $1 >> $YAML_LOG
4747 yml_log_test_status $@ >> $YAML_LOG
4750 log_sub_test_begin() {
4751 yml_log_sub_test_begin "$@" >> $YAML_LOG
4754 log_sub_test_end() {
4755 yml_log_sub_test_end "$@" >> $YAML_LOG
4761 local llverdev_opts=$2
4762 local devname=$(basename $1)
4763 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4764 # loop devices aren't in /proc/partitions
4765 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4767 size=$(($size / 1024 / 1024)) # Gb
4769 local partial_arg=""
4770 # Run in partial (fast) mode if the size
4771 # of a partition > 1 GB
4772 [ $size -gt 1 ] && partial_arg="-p"
4774 llverdev --force $partial_arg $llverdev_opts $dev
4780 local llverfs_opts=$2
4781 local partial_arg=""
4782 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4784 # Run in partial (fast) mode if the size
4785 # of a partition > 1 GB
4786 [ $size -gt 1 ] && partial_arg="-p"
4788 llverfs $partial_arg $llverfs_opts $dir
4791 remove_mdt_files() {
4796 local mntpt=$(facet_mntpt $facet)
4798 echo "removing files from $mdtdev on $facet: $files"
4799 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4802 rm $mntpt/ROOT/$f || { rc=$?; break; }
4804 umount -f $mntpt || return $?
4808 duplicate_mdt_files() {
4813 local mntpt=$(facet_mntpt $facet)
4815 echo "duplicating files on $mdtdev on $facet: $files"
4816 mkdir -p $mntpt || return $?
4817 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4827 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4828 pushd $mntpt/ROOT > /dev/null || return $?
4831 touch $f.bad || return $?
4832 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4834 [ $rc -eq 0 ] || return $rc
4835 setfattr --restore $tmp || return $?
4841 local devs=${1//,/ }
4844 local rslt=$TMP/sgpdd_survey
4846 # sgpdd-survey cleanups ${rslt}.* files
4848 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4854 # returns the canonical name for an ldiskfs device
4859 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4860 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4861 echo dm-\\\${foo##*:};
4863 echo \\\$(basename \\\$dv);
4867 is_sanity_benchmark() {
4868 local benchmarks="dbench bonnie iozone fsx"
4870 for b in $benchmarks; do
4871 if [ "$b" == "$suite" ]; then
4879 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4882 # Get the block size of the filesystem.
4888 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4889 awk '/^Block size:/ {print $3}')
4893 # Check whether the "large_xattr" feature is enabled or not.
4894 large_xattr_enabled() {
4895 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4897 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4898 return ${PIPESTATUS[0]}
4901 # Get the maximum xattr size supported by the filesystem.
4905 if large_xattr_enabled; then
4906 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4909 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4910 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4912 # maximum xattr size = size of block - size of header -
4913 # size of 1 entry - 4 null bytes
4914 size=$((block_size - 32 - 32 - 4))
4920 # Dump the value of the named xattr from a file.
4925 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4928 # Generate a string with size of $size bytes.
4930 local size=${1:-1024} # in bytes
4932 echo "$(head -c $size < /dev/zero | tr '\0' y)"