2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'print_summary && touch $TF_FAIL && \
5 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
19 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
20 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
21 export LOAD_LLOOP=${LOAD_LLOOP:-false}
23 #export PDSH="pdsh -S -Rssh -w"
25 # function used by scripts run on remote nodes
26 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
27 . $LUSTRE/tests/functions.sh
28 . $LUSTRE/tests/yaml.sh
30 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
32 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
34 if [ -f "$EXCEPT_LIST_FILE" ]; then
35 echo "Reading test skip list from $EXCEPT_LIST_FILE"
40 # check config files for options in decreasing order of preference
41 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
42 MODPROBECONF=/etc/modprobe.d/lustre.conf
43 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
44 MODPROBECONF=/etc/modprobe.d/Lustre
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
46 MODPROBECONF=/etc/modprobe.conf
50 [[ $DIR/ = $MOUNT/* ]] || \
51 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
52 [[ $DIR1/ = $MOUNT1/* ]] || \
53 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
54 [[ $DIR2/ = $MOUNT2/* ]] || \
55 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
57 [ -n "$failed" ] && exit 99 || true
61 echo "usage: $0 [-r] [-f cfgfile]"
69 [ "$TESTSUITE" == "lfsck" ] && return 0
70 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
72 local form="%-13s %-17s %-9s %s %s\n"
73 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
74 echo "------------------------------------------------------------------------------------"
75 for O in $DEFAULT_SUITES; do
76 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
77 [ "${!O}" = "no" ] && continue || true
78 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
79 local log=${TMP}/${o}.log
80 if is_sanity_benchmark $o; then
81 log=${TMP}/sanity-benchmark.log
86 local status=Unfinished
88 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
89 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
90 total=$(grep duration $log | awk '{ print $2}')
91 if [ "${!O}" = "done" ]; then
95 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
96 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
99 printf "$form" $status "$O" "${total}" "E=$skipped"
100 printf "$form" "-" "-" "-" "S=$(echo $slow)"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 if [ "${!O}" = "no" ]; then
106 printf "$form" "Skipped" "$O" ""
110 # print the detailed tests durations if DDETAILS=true
117 export LUSTRE=`absolute_path $LUSTRE`
118 export TESTSUITE=`basename $0 .sh`
119 export TEST_FAILED=false
120 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
122 export MKE2FS=${MKE2FS:-mke2fs}
123 export DEBUGFS=${DEBUGFS:-debugfs}
124 export TUNE2FS=${TUNE2FS:-tune2fs}
125 export E2LABEL=${E2LABEL:-e2label}
126 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
127 export E2FSCK=${E2FSCK:-e2fsck}
128 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
130 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
131 export FSCK_MAX_ERR=4 # File system errors left uncorrected
133 #[ -d /r ] && export ROOT=${ROOT:-/r}
134 export TMP=${TMP:-$ROOT/tmp}
135 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
136 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
137 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
139 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
140 if ! echo $PATH | grep -q $LUSTRE/utils; then
141 export PATH=$LUSTRE/utils:$PATH
143 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
144 export PATH=$LUSTRE/utils/gss:$PATH
146 if ! echo $PATH | grep -q $LUSTRE/tests; then
147 export PATH=$LUSTRE/tests:$PATH
149 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
150 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
152 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
153 [ ! -f "$LST" ] && export LST=$(which lst)
154 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
155 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
156 # Ubuntu, at least, has a truncate command in /usr/bin
157 # so fully path our truncate command.
158 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
159 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
160 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
161 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
162 export PATH=$LUSTRE/tests/racer:$PATH:
164 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
165 export PATH=$LUSTRE/tests/mpi:$PATH
167 export RSYNC_RSH=${RSYNC_RSH:-rsh}
169 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
170 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
171 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
172 [ ! -f "$LFS" ] && export LFS=$(which lfs)
173 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
174 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
176 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
177 if [ ! -f "$L_GETIDENTITY" ]; then
178 if `which l_getidentity > /dev/null 2>&1`; then
179 export L_GETIDENTITY=$(which l_getidentity)
181 export L_GETIDENTITY=NONE
184 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
185 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
186 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
187 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
188 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
189 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
190 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
191 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
192 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
193 export FSTYPE=${FSTYPE:-"ldiskfs"}
194 export NAME=${NAME:-local}
195 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
196 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
197 export LGSSD=$(which lgssd)
198 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
199 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
200 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
202 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
205 if [ "$ACCEPTOR_PORT" ]; then
206 export PORT_OPT="--port $ACCEPTOR_PORT"
211 echo "Using GSS/krb5 ptlrpc security flavor"
212 which lgss_keyring > /dev/null 2>&1 || \
213 error_exit "built with gss disabled! SEC=$SEC"
224 IDENTITY_UPCALL=false
227 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
229 # Paths on remote nodes, if different
230 export RLUSTRE=${RLUSTRE:-$LUSTRE}
231 export RPWD=${RPWD:-$PWD}
232 export I_MOUNTED=${I_MOUNTED:-"no"}
233 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
234 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
235 ! -f `dirname $0`/../mds/mds.ko ]; then
236 export CLIENTMODSONLY=yes
239 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
243 while getopts "rvwf:" opt $*; do
246 r) REFORMAT=--reformat;;
248 w) WRITECONF=writeconf;;
253 shift $((OPTIND - 1))
256 # print the durations of each test if "true"
257 DDETAILS=${DDETAILS:-false}
258 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
263 echo -n $((($1 << 16) | ($2 << 8) | $3))
266 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
267 export LINUX_VERSION_CODE=$(kernel_version ${LINUX_VERSION//\./ })
270 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
271 *) EXT=".ko"; USE_QUOTA=yes;;
276 /sbin/lsmod | grep -q "^\<$1\>"
279 # Load a module on the system where this is running.
281 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
283 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
284 # will be used as the arguments. Otherwise arguments will be obtained from
285 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
292 BASE=`basename $module $EXT`
294 module_loaded ${BASE} && return
296 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
298 if [ $# -eq 0 ]; then
299 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
300 # Bash until 4.x, so we resort to eval.
301 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
302 eval set -- \$$optvar
303 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
304 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
305 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
306 # Get rid of "options $module"
307 (($# > 0)) && shift 2
309 # Ensure we have accept=all for lnet
310 if [ $(basename $module) = lnet ]; then
311 # OK, this is a bit wordy...
312 local arg accept_all_present=false
314 [ "$arg" = accept=all ] && accept_all_present=true
316 $accept_all_present || set -- "$@" accept=all
321 [ $# -gt 0 ] && echo "${module} options: '$*'"
323 # Note that insmod will ignore anything in modprobe.conf, which is why we're
324 # passing options on the command-line.
325 if [ "$BASE" == "lnet_selftest" ] && \
326 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
327 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
328 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
329 insmod ${LUSTRE}/${module}${EXT} "$@"
331 # must be testing a "make install" or "rpm" installation
332 # note failed to load ptlrpc_gss is considered not fatal
333 if [ "$BASE" == "ptlrpc_gss" ]; then
334 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
341 llite_lloop_enabled() {
342 local n1=$(uname -r | cut -d. -f1)
343 local n2=$(uname -r | cut -d. -f2)
344 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
346 # load the llite_lloop module for < 2.6.32 kernels
347 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
348 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
355 load_modules_local() {
356 if [ -n "$MODPROBE" ]; then
358 echo "Using modprobe to load modules"
362 echo Loading modules from $LUSTRE
363 load_module ../libcfs/libcfs/libcfs
364 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
365 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
366 load_module ../lnet/lnet/lnet
367 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
368 load_module ../lnet/klnds/$LNETLND
369 load_module lvfs/lvfs
370 load_module obdclass/obdclass
371 load_module ptlrpc/ptlrpc
372 load_module ptlrpc/gss/ptlrpc_gss
373 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
381 if ! client_only; then
382 SYMLIST=/proc/kallsyms
383 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
384 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
385 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
386 if [ "$FSTYPE" = "ldiskfs" ]; then
387 grep -q exportfs_decode_fh $SYMLIST ||
388 { modprobe exportfs 2> /dev/null || true; }
389 load_module ../ldiskfs/ldiskfs/ldiskfs
395 load_module lvfs/fsfilt_$FSTYPE
397 load_module osd-ldiskfs/osd_ldiskfs
399 load_module obdfilter/obdfilter
403 load_module llite/lustre
404 llite_lloop_enabled && load_module llite/llite_lloop
405 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
407 rm -f $OGDB/ogdb-$HOSTNAME
408 $LCTL modules > $OGDB/ogdb-$HOSTNAME
410 # 'mount' doesn't look in $PATH, just sbin
411 if [ -f $LUSTRE/utils/mount.lustre ] && \
412 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
413 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
414 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
421 # load modules on remote nodes optionally
422 # lustre-tests have to be installed on these nodes
423 if $LOAD_MODULES_REMOTE ; then
424 local list=$(comma_list $(remote_nodes_list))
425 echo loading modules on $list
426 do_rpc_nodes $list load_modules
431 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
432 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
433 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
434 echo "$LEAK_LUSTRE" 1>&2
435 echo "$LEAK_PORTALS" 1>&2
436 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
437 echo "Memory leaks detected"
438 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
444 wait_exit_ST client # bug 12845
446 $LUSTRE_RMMOD $FSTYPE || return 2
448 if $LOAD_MODULES_REMOTE ; then
449 local list=$(comma_list $(remote_nodes_list))
450 if [ ! -z $list ]; then
451 echo unloading modules on $list
452 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
453 do_rpc_nodes $list check_mem_leak
457 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
458 umount /sbin/mount.lustre || true
459 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
460 rm -f /sbin/mount.lustre || true
463 check_mem_leak || return 254
465 echo "modules unloaded."
469 check_gss_daemon_nodes() {
473 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
474 if [ \\\"\\\$num\\\" -ne 1 ]; then
475 echo \\\$num instance of $dname;
480 check_gss_daemon_facet() {
484 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
485 if [ $num -ne 1 ]; then
486 echo "$num instance of $dname on $facet"
495 echo Stopping $@ on $list
496 do_nodes $list "killall -2 $@ 2>/dev/null || true"
499 # start gss daemons on all nodes, or
500 # "daemon" on "list" if set
501 start_gss_daemons() {
505 if [ "$list" ] && [ "$daemon" ] ; then
506 echo "Starting gss daemon on nodes: $list"
507 do_nodes $list "$daemon" || return 8
511 local list=$(comma_list $(mdts_nodes))
513 echo "Starting gss daemon on mds: $list"
514 do_nodes $list "$LSVCGSSD -v" || return 1
516 do_nodes $list "$LGSSD -v" || return 2
519 list=$(comma_list $(osts_nodes))
520 echo "Starting gss daemon on ost: $list"
521 do_nodes $list "$LSVCGSSD -v" || return 3
522 # starting on clients
524 local clients=${CLIENTS:-`hostname`}
526 echo "Starting $LGSSD on clients $clients "
527 do_nodes $clients "$LGSSD -v" || return 4
530 # wait daemons entering "stable" status
534 # check daemons are running
536 list=$(comma_list $(mdts_nodes) $(osts_nodes))
537 check_gss_daemon_nodes $list lsvcgssd || return 5
539 list=$(comma_list $(mdts_nodes))
540 check_gss_daemon_nodes $list lgssd || return 6
543 check_gss_daemon_nodes $clients lgssd || return 7
548 local list=$(comma_list $(mdts_nodes))
550 send_sigint $list lsvcgssd lgssd
552 list=$(comma_list $(osts_nodes))
553 send_sigint $list lsvcgssd
555 list=${CLIENTS:-`hostname`}
556 send_sigint $list lgssd
561 if ! module_loaded ptlrpc_gss; then
562 load_module ptlrpc/gss/ptlrpc_gss
563 module_loaded ptlrpc_gss ||
564 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
566 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
568 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
569 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
577 # maybe cleanup credential cache?
583 local device=`mdsdevname $num`
584 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
590 local device=`ostdevname $num`
591 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
596 local dz=${1:-$DEBUG_SIZE}
598 if [ -f /sys/devices/system/cpu/possible ]; then
599 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
601 local cpus=$(getconf _NPROCESSORS_CONF)
604 # bug 19944, adjust size to be -gt num_possible_cpus()
605 # promise 2MB for every cpu at least
606 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
609 lctl set_param debug_mb=$dz
612 set_default_debug () {
613 local debug=${1:-"$PTLDEBUG"}
614 local subsys=${2:-"$SUBSYSTEM"}
615 local debug_size=${3:-$DEBUG_SIZE}
617 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
618 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
620 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
623 set_default_debug_nodes () {
626 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
627 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
631 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
632 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
635 set_default_debug_facet () {
637 local node=$(facet_active_host $facet)
638 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
640 set_default_debug_nodes $node
645 local facets=${1:-$(get_facets)}
648 for facet in ${facets//,/ }; do
649 mount_facet $facet || error "Restart of $facet failed!"
656 local dev=$(facet_active $facet)_dev
657 local opt=${facet}_opt
658 local mntpt=$(facet_mntpt $facet)
660 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
661 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
663 if [ $RC -ne 0 ]; then
664 echo "mount -t lustre $@ ${!dev} $mntpt"
665 echo "Start of ${!dev} on ${facet} failed ${RC}"
667 set_default_debug_facet $facet
669 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
670 [ -z "$label" ] && echo no label for ${!dev} && exit 1
671 eval export ${facet}_svc=${label}
672 echo Started ${label}
677 # start facet device options
683 eval export ${facet}_dev=${device}
684 eval export ${facet}_opt=\"$@\"
686 local varname=${facet}failover_dev
687 if [ -n "${!varname}" ] ; then
688 eval export ${facet}failover_dev=${!varname}
690 eval export ${facet}failover_dev=$device
693 local mntpt=$(facet_mntpt $facet)
694 do_facet ${facet} mkdir -p $mntpt
695 eval export ${facet}_MOUNT=$mntpt
705 local HOST=`facet_active_host $facet`
706 [ -z $HOST ] && echo stop: no host for $facet && return 0
708 local mntpt=$(facet_mntpt $facet)
709 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
710 if [ ${running} -ne 0 ]; then
711 echo "Stopping $mntpt (opts:$@) on $HOST"
712 do_facet ${facet} umount -d $@ $mntpt
715 # umount should block, but we should wait for unrelated obd's
716 # like the MGS or MGC to also stop.
717 wait_exit_ST ${facet}
720 # save quota version (both administrative and operational quotas)
721 # add an additional parameter if mountpoint is ever different from $MOUNT
722 quota_save_version() {
723 local fsname=${2:-$FSNAME}
725 local ver=$(tr -c -d "123" <<< $spec)
726 local type=$(tr -c -d "ug" <<< $spec)
728 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
730 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
732 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
734 local osts=$(get_facets OST)
735 for ost in ${osts//,/ }; do
737 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
741 # client could mount several lustre
743 local fsname=${1:-$FSNAME}
745 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
746 do_nodes $(comma_list $(osts_nodes)) \
747 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
751 restore_quota_type () {
752 local mntpt=${1:-$MOUNT}
753 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
754 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
757 quota_save_version $old_QUOTA_TYPE
763 # We need save the original quota_type params, and restore them after testing
765 # Suppose that quota type the same on mds and ost
766 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
767 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
768 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
769 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
770 export old_QUOTA_TYPE=$quota_type
771 quota_save_version $QUOTA_TYPE
773 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
774 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
777 local quota_usrs=$QUOTA_USERS
779 # get_filesystem_size
780 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
781 local blk_soft=$((disksz + 1024))
782 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
784 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
786 local i_hard=$((i_soft + i_soft / 20))
788 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
789 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
792 for usr in $quota_usrs; do
793 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
795 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
797 eval $cmd || error "$cmd FAILED!"
799 # display the quota status
800 echo "Quota settings for $usr : "
801 $LFS quota -v -u $usr $mntpt || true
808 local OPTIONS=${3:-$MOUNTOPT}
810 local device=$MGSNID:/$FSNAME
811 if [ -z "$mnt" -o -z "$FSNAME" ]; then
812 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
816 echo "Starting client: $client: $OPTIONS $device $mnt"
817 do_node $client mkdir -p $mnt
818 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
820 set_default_debug_nodes $client
833 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
834 if [ $running -ne 0 ]; then
835 echo "Stopping client $client $mnt (opts:$force)"
836 do_node $client lsof -t $mnt || need_kill=no
837 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
838 pids=$(do_node $client lsof -t $mnt | sort -u);
839 if [ -n $pids ]; then
840 do_node $client kill -9 $pids || true
844 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
845 if [ $busy -ne 0 ] ; then
846 echo "$mnt is still busy, wait one second" && sleep 1
847 do_node $client umount $force $mnt
852 # nodes is comma list
853 sanity_mount_check_nodes () {
859 # FIXME: assume that all cluster nodes run the same os
860 [ "$(uname)" = Linux ] || return 0
863 for mnt in $mnts ; do
864 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
865 mpts=\\\$(mount | grep -w -c $mnt);
866 if [ \\\$running -ne \\\$mpts ]; then
867 echo \\\$(hostname) env are INSANE!;
875 sanity_mount_check_servers () {
877 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
878 echo Checking servers environments
880 # FIXME: modify get_facets to display all facets wo params
881 local facets="$(get_facets OST),$(get_facets MDS),mgs"
885 for facet in ${facets//,/ }; do
886 node=$(facet_host ${facet})
887 mntpt=$(facet_mntpt $facet)
888 sanity_mount_check_nodes $node $mntpt ||
889 { error "server $node environments are insane!"; return 1; }
893 sanity_mount_check_clients () {
894 local clients=${1:-$CLIENTS}
895 local mntpt=${2:-$MOUNT}
896 local mntpt2=${3:-$MOUNT2}
898 [ -z $clients ] && clients=$(hostname)
899 echo Checking clients $clients environments
901 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
902 error "clients environments are insane!"
905 sanity_mount_check () {
906 sanity_mount_check_servers || return 1
907 sanity_mount_check_clients || return 2
910 # mount clients if not mouted
911 zconf_mount_clients() {
914 local OPTIONS=${3:-$MOUNTOPT}
916 local device=$MGSNID:/$FSNAME
917 if [ -z "$mnt" -o -z "$FSNAME" ]; then
918 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
922 echo "Starting client $clients: $OPTIONS $device $mnt"
925 running=\\\$(mount | grep -c $mnt' ');
927 if [ \\\$running -eq 0 ] ; then
929 mount -t lustre $OPTIONS $device $mnt;
932 exit \\\$rc" || return ${PIPESTATUS[0]}
934 echo "Started clients $clients: "
935 do_nodes $clients "mount | grep -w $mnt"
937 set_default_debug_nodes $clients
942 zconf_umount_clients() {
949 echo "Stopping clients: $clients $mnt (opts:$force)"
950 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
951 if [ \\\$running -ne 0 ] ; then
952 echo Stopping client \\\$(hostname) $mnt opts:$force;
953 lsof $mnt || need_kill=no;
954 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
955 pids=\\\$(lsof -t $mnt | sort -u);
956 if [ -n \\\"\\\$pids\\\" ]; then
960 while umount $force $mnt 2>&1 | grep -q "busy"; do
961 echo "$mnt is still busy, wait one second" && sleep 1;
968 echo + $POWER_DOWN $node
972 shutdown_node_hard () {
974 local attempts=$SHUTDOWN_ATTEMPTS
976 for i in $(seq $attempts) ; do
979 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
980 echo "waiting for $host to fail attempts=$attempts"
981 [ $i -lt $attempts ] || \
982 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
988 local mnt=${2:-$MOUNT}
991 if [ "$FAILURE_MODE" = HARD ]; then
992 shutdown_node_hard $client
994 zconf_umount_clients $client $mnt -f
1000 local facets="$(get_facets OST),$(get_facets MDS)"
1003 combined_mgs_mds || facets="$facets,mgs"
1005 for facet in ${facets//,/ }; do
1006 if [ $(facet_active_host $facet) == $host ]; then
1007 affected="$affected $facet"
1011 echo $(comma_list $affected)
1016 local host=${2:-$(facet_host $facet)}
1018 local label=$(convert_facet2label $facet)
1019 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1022 facets_up_on_host () {
1024 local facets=$(facets_on_host $host)
1027 for facet in ${facets//,/ }; do
1028 if $(facet_up $facet $host); then
1029 affected_up="$affected_up $facet"
1033 echo $(comma_list $affected_up)
1039 if [ "$FAILURE_MODE" = HARD ]; then
1040 shutdown_node_hard $(facet_active_host $facet)
1048 echo + $POWER_UP $node
1061 if [ "$FAILURE_MODE" = HARD ]; then
1062 reboot_node $(facet_active_host $facet)
1070 if [ "$FAILURE_MODE" = HARD ]; then
1080 for facet in ${facets//,/ }; do
1081 hosts=$(expand_list $hosts $(facet_host $facet) )
1087 _check_progs_installed () {
1091 for prog in $progs; do
1092 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1093 echo $prog missing on $(hostname)
1100 check_progs_installed () {
1104 do_rpc_nodes $nodes _check_progs_installed $@
1107 # recovery-scale functions
1109 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1112 start_client_load() {
1115 local var=$(node_var_name $client)_load
1116 eval export ${var}=$load
1118 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1119 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1120 END_RUN_FILE=$END_RUN_FILE \
1121 LOAD_PID_FILE=$LOAD_PID_FILE \
1122 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1123 TESTNAME=$TESTNAME \
1126 log "Started client load: ${load} on $client"
1128 # get the children process IDs
1129 local pids=$(ps --ppid $ppid -o pid= | xargs)
1130 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1134 start_client_loads () {
1135 local -a clients=(${1//,/ })
1136 local numloads=${#CLIENT_LOADS[@]}
1139 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1140 testnum=$((nodenum % numloads))
1141 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1143 # bug 22169: wait the background threads to start
1147 # only for remote client
1148 check_client_load () {
1150 local var=$(node_var_name $client)_load
1151 local TESTLOAD=run_${!var}.sh
1153 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1155 # bug 18914: try to connect several times not only when
1156 # check ps, but while check_catastrophe also
1159 while [ $RC = 254 -a $tries -gt 0 ]; do
1163 if ! check_catastrophe $client; then
1165 if [ $RC -eq 254 ]; then
1166 # FIXME: not sure how long we shuold sleep here
1170 echo "check catastrophe failed: RC=$RC "
1174 # We can continue try to connect if RC=254
1175 # Just print the warning about this
1176 if [ $RC = 254 ]; then
1177 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1180 # see if the load is still on the client
1183 while [ $RC = 254 -a $tries -gt 0 ]; do
1187 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1192 if [ $RC = 254 ]; then
1193 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1194 # see if we can diagnose a bit why this is
1199 check_client_loads () {
1200 local clients=${1//,/ }
1204 for client in $clients; do
1205 check_client_load $client
1207 if [ "$rc" != 0 ]; then
1208 log "Client load failed on node $client, rc=$rc"
1214 restart_client_loads () {
1215 local clients=${1//,/ }
1216 local expectedfail=${2:-""}
1220 for client in $clients; do
1221 check_client_load $client
1223 if [ "$rc" != 0 -a "$expectedfail" ]; then
1224 local var=$(node_var_name $client)_load
1225 start_client_load $client ${!var}
1226 echo "Restarted client load ${!var}: on $client. Checking ..."
1227 check_client_load $client
1229 if [ "$rc" != 0 ]; then
1230 log "Client load failed to restart on node $client, rc=$rc"
1231 # failure one client load means test fail
1232 # we do not need to check other
1241 # Start vmstat and save its process ID in a file.
1246 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1249 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1250 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1253 # Display the nodes on which client loads failed.
1254 print_end_run_file() {
1258 [ -s $file ] || return 0
1260 echo "Found the END_RUN_FILE file: $file"
1263 # A client load will stop if it finds the END_RUN_FILE file.
1264 # That does not mean the client load actually failed though.
1265 # The first node in END_RUN_FILE is the one we are interested in.
1268 if [ -n "$node" ]; then
1269 local var=$(node_var_name $node)_load
1271 local prefix=$TESTLOG_PREFIX
1272 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1273 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1274 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1276 echo "Client load ${!var} failed on node $node:"
1282 # Stop the process which had its PID saved in a file.
1287 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1289 do_nodes $nodes "test -f $pid_file &&
1290 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1293 # Stop all client loads.
1294 stop_client_loads() {
1295 local nodes=${1:-$CLIENTS}
1298 # stop the client loads
1299 stop_process $nodes $pid_file
1301 # clean up the processes that started them
1302 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1304 # End recovery-scale functions
1306 # verify that lustre actually cleaned up properly
1308 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1309 error "LBUG/LASSERT detected"
1310 BUSY=`dmesg | grep -i destruct || true`
1311 if [ "$BUSY" ]; then
1313 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1317 check_mem_leak || exit 204
1319 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1320 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1322 if module_loaded lnet || module_loaded libcfs; then
1323 echo "$0: modules still loaded..." 1>&2
1341 RESULT=$(do_node $node "$TEST")
1342 if [ "$RESULT" == "$FINAL" ]; then
1343 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1344 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1347 [ $WAIT -ge $MAX ] && break
1348 [ $((WAIT % print)) -eq 0 ] &&
1349 echo "Waiting $((MAX - WAIT)) secs for update"
1350 WAIT=$((WAIT + sleep))
1353 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1357 wait_update_facet () {
1359 wait_update $(facet_active_host $facet) "$@"
1362 wait_delete_completed () {
1363 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1364 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1368 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1370 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1371 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1372 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1373 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1377 echo "Delete is not completed in $MAX_WAIT sec"
1384 # we can use "for" here because we are waiting the slowest
1385 for host in ${hostlist//,/ }; do
1386 check_network "$host" 900
1388 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1395 for facet in ${facetlist//,/ }; do
1396 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1398 wait_for_host $hostlist
1401 _wait_recovery_complete () {
1404 # Use default policy if $2 is not passed by caller.
1405 local MAX=${2:-$(max_recovery_time)}
1410 while [ $WAIT -lt $MAX ]; do
1411 STATUS=$(lctl get_param -n $param | grep status)
1413 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1416 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1418 echo "$param recovery not done in $MAX sec. $STATUS"
1422 wait_recovery_complete () {
1425 # with an assumption that at_max is the same on all nodes
1426 local MAX=${2:-$(max_recovery_time)}
1429 if [ "$FAILURE_MODE" = HARD ]; then
1430 facets=$(facets_on_host $(facet_active_host $facet))
1432 echo affected facets: $facets
1434 # we can use "for" here because we are waiting the slowest
1435 for facet in ${facets//,/ }; do
1436 local var_svc=${facet}_svc
1437 local param="*.${!var_svc}.recovery_status"
1439 local host=$(facet_active_host $facet)
1440 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1444 wait_mds_ost_sync () {
1445 # just because recovery is done doesn't mean we've finished
1446 # orphan cleanup. Wait for llogs to get synchronized.
1447 echo "Waiting for orphan cleanup..."
1448 # MAX value includes time needed for MDS-OST reconnection
1449 local MAX=$(( TIMEOUT * 2 ))
1451 while [ $WAIT -lt $MAX ]; do
1452 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1453 "$LCTL get_param -n obdfilter.*.mds_sync"))
1456 for ((i=0; i<${#sync[@]}; i++)); do
1457 [ ${sync[$i]} -eq 0 ] && continue
1458 # there is a not finished MDS-OST synchronization
1462 sleep 2 # increase waiting time and cover statfs cache
1463 [ ${con} -eq 1 ] && return 0
1464 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1467 echo "$facet recovery not done in $MAX sec. $STATUS"
1471 wait_destroy_complete () {
1472 echo "Waiting for destroy to be done..."
1473 # MAX value shouldn't be big as this mean server responsiveness
1474 # never increase this just to make test pass but investigate
1475 # why it takes so long time
1478 while [ $WAIT -lt $MAX ]; do
1479 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1481 for ((i=0; i<${#RPCs[@]}; i++)); do
1482 [ ${RPCs[$i]} -eq 0 ] && continue
1483 # there are still some destroy RPCs in flight
1488 [ ${con} -eq 1 ] && return 0 # done waiting
1489 echo "Waiting $WAIT secs for destroys to be done."
1492 echo "Destroys weren't done in $MAX sec."
1502 # conf-sanity 31 takes a long time cleanup
1503 while [ $WAIT -lt 300 ]; do
1504 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1505 [ -z "${running}" ] && return 0
1506 echo "waited $WAIT for${running}"
1507 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1509 WAIT=$((WAIT + INTERVAL))
1511 echo "service didn't stop after $WAIT seconds. Still running:"
1516 wait_remote_prog () {
1522 [ "$PDSH" = "no_dsh" ] && return 0
1524 while [ $WAIT -lt $2 ]; do
1525 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1526 [ -z "${running}" ] && return 0 || true
1527 echo "waited $WAIT for: "
1529 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1531 WAIT=$((WAIT + INTERVAL))
1533 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1534 [ -z "$pids" ] && return 0
1535 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1536 # FIXME: not portable
1537 for pid in $pids; do
1538 cat /proc/${pid}/status || true
1539 cat /proc/${pid}/wchan || true
1541 kill -9 $pid || true
1550 # not every config has many clients
1552 if [ ! -z "$CLIENTS" ]; then
1553 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1555 stat -f $MOUNT > /dev/null
1561 # usually checked on particular client or locally
1563 if [ ! -z "$client" ]; then
1564 $PDSH $client "stat -f $MOUNT" > /dev/null
1566 stat -f $MOUNT > /dev/null
1574 client_reconnect() {
1575 uname -n >> $MOUNT/recon
1576 if [ -z "$CLIENTS" ]; then
1577 df $MOUNT; uname -n >> $MOUNT/recon
1579 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1581 echo Connected clients:
1583 ls -l $MOUNT/recon > /dev/null
1587 affected_facets () {
1590 local host=$(facet_active_host $facet)
1591 local affected=$facet
1593 if [ "$FAILURE_MODE" = HARD ]; then
1594 affected=$(facets_up_on_host $host)
1602 local host=$(facet_active_host $facet)
1604 echo "Failing $facet on node $host"
1606 # Make sure the client data is synced to disk. LU-924
1608 # We don't write client data synchrnously (to avoid flooding sync writes
1609 # when there are many clients connecting), so if the server reboots before
1610 # the client data reachs disk, the client data will be lost and the client
1611 # will be evicted after recovery, which is not what we expected.
1612 do_facet $facet "sync; sync; sync"
1614 local affected=$(affected_facets $facet)
1616 shutdown_facet $facet
1618 echo affected facets: $affected
1620 [ -n "$sleep_time" ] && sleep $sleep_time
1624 change_active $affected
1626 wait_for_facet $affected
1627 # start mgs first if it is affected
1628 if ! combined_mgs_mds && list_member $affected mgs; then
1629 mount_facet mgs || error "Restart of mgs failed"
1631 # FIXME; has to be changed to mount all facets concurrently
1632 affected=$(exclude_items_from_list $affected mgs)
1633 mount_facets $affected
1642 do_facet $facet "sync; sync; sync"
1645 # make sure there will be no seq change
1646 local clients=${CLIENTS:-$HOSTNAME}
1647 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1649 local svc=${facet}_svc
1650 do_facet $facet $LCTL --device %${!svc} notransno
1651 do_facet $facet $LCTL --device %${!svc} readonly
1652 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1653 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1656 replay_barrier_nodf() {
1657 local facet=$1 echo running=${running}
1658 do_facet $facet "sync; sync; sync"
1659 local svc=${facet}_svc
1660 echo Replay barrier on ${!svc}
1661 do_facet $facet $LCTL --device %${!svc} notransno
1662 do_facet $facet $LCTL --device %${!svc} readonly
1663 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1664 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1667 replay_barrier_nosync() {
1668 local facet=$1 echo running=${running}
1669 local svc=${facet}_svc
1670 echo Replay barrier on ${!svc}
1671 do_facet $facet $LCTL --device %${!svc} notransno
1672 do_facet $facet $LCTL --device %${!svc} readonly
1673 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1674 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1677 mds_evict_client() {
1678 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1679 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1682 ost_evict_client() {
1683 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1684 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1688 facet_failover $* || error "failover: $?"
1689 clients_up || error "post-failover df: $?"
1694 facet_failover $facet
1700 change_active $facet
1701 wait_for_facet $facet
1702 mount_facet $facet -o abort_recovery
1703 clients_up || echo "first df failed: $?"
1704 clients_up || error "post-failover df: $?"
1708 echo There is no lmc. This is mountconf, baby.
1712 host_nids_address() {
1716 if [ -n "$kind" ]; then
1717 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1719 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1725 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1731 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1732 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1733 if [ -z "$ID" ]; then
1734 echo "Could not get a ptl id for $1..."
1743 h2name_or_ip "$1" "tcp"
1748 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1749 if type __h2elan >/dev/null 2>&1; then
1752 ID=`echo $1 | sed 's/[^0-9]*//g'`
1760 h2name_or_ip "$1" "o2ib"
1764 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1765 # expressions format. As a bonus we can then just pass in those variables
1766 # to pdsh. What this function does is take a HOSTLIST type string and
1767 # expand it into a space deliminated list for us.
1775 [ -z "$hostlist" ] && return
1777 # Translate the case of [..],..,[..] to [..] .. [..]
1778 list="${hostlist/],/] }"
1780 [[ "$front" == *,* ]] && {
1783 list=${list/${old}/${new}}
1786 for item in $list; do
1787 # Test if we have any []'s at all
1788 if [ "$item" != "${item/\[/}" ]; then {
1789 # Expand the [*] into list
1793 if [ "$name" != "$item" ]; then
1794 group=${item#$name[*}
1797 for range in ${group//,/ }; do
1801 # Number of leading zeros
1804 end=$(echo $end | sed 's/0*//')
1805 [[ -z "$end" ]] && end=0
1806 [[ $padlen2 -gt $padlen ]] && {
1807 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1810 begin=$(echo $begin | sed 's/0*//')
1811 [ -z $begin ] && begin=0
1813 for num in $(seq -f "%0${padlen}g" $begin $end); do
1814 value="${name#*,}${num}${back}"
1815 [ "$value" != "${value/\[/}" ] && {
1816 value=$(hostlist_expand "$value")
1818 myList="$myList $value"
1823 myList="$myList $item"
1826 myList=${myList//,/ }
1827 myList=${myList:1} # Remove first character which is a space
1829 # Filter any duplicates without sorting
1831 myList="${list%% *}"
1833 while [[ "$list" != ${myList##* } ]]; do
1834 list=${list//${list%% *} /}
1835 myList="$myList ${list%% *}"
1837 myList="${myList%* }";
1839 # We can select an object at a offset in the list
1842 for item in $myList; do
1844 [ $cnt -eq $offset ] && {
1848 [ $(get_node_count $myList) -ne 1 ] && myList=""
1856 [ "$facet" == client ] && echo -n $HOSTNAME && return
1857 varname=${facet}_HOST
1858 if [ -z "${!varname}" ]; then
1859 if [ "${facet:0:3}" == "ost" ]; then
1860 eval ${facet}_HOST=${ost_HOST}
1868 local activevar=${facet}active
1870 if [ -f $TMP/${facet}active ] ; then
1871 source $TMP/${facet}active
1874 active=${!activevar}
1875 if [ -z "$active" ] ; then
1882 facet_active_host() {
1884 local active=`facet_active $facet`
1885 if [ "$facet" == client ]; then
1888 echo `facet_host $active`
1896 facetlist=$(exclude_items_from_list $facetlist mgs)
1898 for facet in ${facetlist//,/ }; do
1899 local failover=${facet}failover
1900 local host=`facet_host $failover`
1901 [ -z "$host" ] && return
1903 local curactive=`facet_active $facet`
1904 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1905 eval export ${facet}active=$facet
1907 eval export ${facet}active=$failover
1909 # save the active host for this facet
1910 local activevar=${facet}active
1911 echo "$activevar=${!activevar}" > $TMP/$activevar
1912 [[ $facet = mds1 ]] && combined_mgs_mds && \
1913 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1914 local TO=`facet_active_host $facet`
1915 echo "Failover $facet to $TO"
1921 # do not stripe off hostname if verbose, bug 19215
1922 if [ x$1 = x--verbose ]; then
1930 if [ "$HOST" = "$HOSTNAME" ]; then
1932 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1933 echo "cannot run remote command on $HOST with $myPDSH"
1937 echo "CMD: $HOST $@" >&2
1938 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1941 if [ "$myPDSH" = "rsh" ]; then
1942 # we need this because rsh does not return exit code of an executed command
1943 local command_status="$TMP/cs"
1944 rsh $HOST ":> $command_status"
1945 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1946 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1947 echo command failed >$command_status"
1948 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1953 # print HOSTNAME for myPDSH="no_dsh"
1954 if [[ $myPDSH = no_dsh ]]; then
1955 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1957 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1960 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1962 return ${PIPESTATUS[0]}
1966 do_node --verbose "$@"
1969 single_local_node () {
1970 [ "$1" = "$HOSTNAME" ]
1973 # Outputs environment variable assignments that should be passed to remote nodes
1978 for var in ${!MODOPTS_*}; do
1980 echo "${var}=\"$value\""
1986 # do not stripe off hostname if verbose, bug 19215
1987 if [ x$1 = x--verbose ]; then
1995 if single_local_node $rnodes; then
1997 do_nodev $rnodes "$@"
1999 do_node $rnodes "$@"
2004 # This is part from do_node
2007 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2008 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2011 echo "CMD: $rnodes $@" >&2
2012 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2015 # do not replace anything from pdsh output if -N is used
2016 # -N Disable hostname: prefix on lines of output.
2017 if $verbose || [[ $myPDSH = *-N* ]]; then
2018 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2020 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2022 return ${PIPESTATUS[0]}
2028 local HOST=`facet_active_host $facet`
2029 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2034 do_nodes --verbose "$@"
2040 # make sure its not already running
2042 rm -f $TMP/${facet}active
2043 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2044 do_facet ${facet} $MKFS $*
2050 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2051 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
2058 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2059 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
2065 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2067 local var=${facet}_MOUNT
2068 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2077 # make sure we are using the primary server, so test-framework will
2078 # be able to clean up properly.
2079 activemds=`facet_active mds1`
2080 if [ $activemds != "mds1" ]; then
2084 local clients=$CLIENTS
2085 [ -z $clients ] && clients=$(hostname)
2087 zconf_umount_clients $clients $MOUNT "$*" || true
2088 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2090 [ "$CLIENTONLY" ] && return
2091 # The add fn does rm ${facet}active file, this would be enough
2092 # if we use do_facet <facet> only after the facet added, but
2093 # currently we use do_facet mds in local.sh
2094 for num in `seq $MDSCOUNT`; do
2096 rm -f ${TMP}/mds${num}active
2098 combined_mgs_mds && rm -f $TMP/mgsactive
2100 for num in `seq $OSTCOUNT`; do
2102 rm -f $TMP/ost${num}active
2105 if ! combined_mgs_mds ; then
2112 cleanup_echo_devs () {
2113 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2115 for dev in $devs; do
2116 $LCTL --device $dev cleanup
2117 $LCTL --device $dev detach
2122 nfs_client_mode && return
2131 combined_mgs_mds () {
2132 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2138 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2139 local optvar=${tgt}_MKFS_OPTS
2140 local opt=${!optvar}
2142 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2143 [[ $facet = mgs ]] && echo $opt && return
2146 # --failnode options
2147 local var=${facet}failover_HOST
2148 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2149 local failnode=$(h2$NETTYPE ${!var})
2150 failnode="--failnode=$failnode"
2151 # options does not contain
2152 # or contains wrong --failnode=
2153 if [[ $opt != *${failnode}* ]]; then
2154 opt=$(echo $opt | sed 's/--failnode=.* / /')
2155 opt="$opt $failnode"
2161 # no additional mkfs mds "--mgsnode" option for this configuration
2162 if [[ $facet = mds ]] && combined_mgs_mds; then
2167 # additional mkfs "--mgsnode"
2168 local mgsnode="--mgsnode=$MGSNID"
2169 opt=${opt//$mgsnode }
2170 for nid in ${MGSNID//:/ }; do
2171 local mgsnode="--mgsnode=$nid"
2172 # options does not contain
2174 if [[ $opt != *${mgsnode}" "* ]]; then
2175 opt="$opt --mgsnode=$nid"
2183 if [ "$IAMDIR" == "yes" ]; then
2184 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2187 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2190 # We need ldiskfs here, may as well load them all
2192 [ "$CLIENTONLY" ] && return
2193 echo Formatting mgs, mds, osts
2194 if ! combined_mgs_mds ; then
2195 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2198 for num in `seq $MDSCOUNT`; do
2199 echo "Format mds$num: $(mdsdevname $num)"
2201 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2203 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2207 # the ost-s could have different OST_MKFS_OPTS
2208 # because of different failnode-s
2209 for num in `seq $OSTCOUNT`; do
2210 echo "Format ost$num: $(ostdevname $num)"
2212 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2214 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2220 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2224 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2228 # 0: success, the old identity set already.
2229 # 1: success, the old identity does not set.
2234 local j=`expr $num - 1`
2235 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2237 if [ -z "$MDT" ]; then
2241 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2244 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2246 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2249 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2251 if [ $old = "NONE" ]; then
2260 zconf_umount `hostname` $1 || error "umount failed"
2261 zconf_mount `hostname` $1 || error "mount failed"
2264 writeconf_facet () {
2268 do_facet $facet "$TUNEFS --writeconf $dev"
2272 for num in `seq $MDSCOUNT`; do
2273 DEVNAME=$(mdsdevname $num)
2274 writeconf_facet mds$num $DEVNAME
2277 for num in `seq $OSTCOUNT`; do
2278 DEVNAME=$(ostdevname $num)
2279 writeconf_facet ost$num $DEVNAME
2284 nfs_client_mode && return
2286 sanity_mount_check ||
2287 error "environments are insane!"
2291 if [ -z "$CLIENTONLY" ]; then
2292 echo Setup mgs, mdt, osts
2293 echo $WRITECONF | grep -q "writeconf" && \
2295 if ! combined_mgs_mds ; then
2296 start mgs $MGSDEV $MGS_MOUNT_OPTS
2299 for num in `seq $MDSCOUNT`; do
2300 DEVNAME=$(mdsdevname $num)
2301 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2303 # We started mds, now we should set failover variables properly.
2304 # Set mds${num}failover_HOST if it is not set (the default failnode).
2305 local varname=mds${num}failover_HOST
2306 if [ -z "${!varname}" ]; then
2307 eval mds${num}failover_HOST=$(facet_host mds$num)
2310 if [ $IDENTITY_UPCALL != "default" ]; then
2311 switch_identity $num $IDENTITY_UPCALL
2314 for num in `seq $OSTCOUNT`; do
2315 DEVNAME=$(ostdevname $num)
2316 start ost$num $DEVNAME $OST_MOUNT_OPTS
2318 # We started ost$num, now we should set ost${num}failover variable properly.
2319 # Set ost${num}failover_HOST if it is not set (the default failnode).
2320 varname=ost${num}failover_HOST
2321 if [ -z "${!varname}" ]; then
2322 eval ost${num}failover_HOST=$(facet_host ost${num})
2330 # wait a while to allow sptlrpc configuration be propogated to targets,
2331 # only needed when mounting new target devices.
2336 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2338 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2341 if [ "$MOUNT_2" ]; then
2342 mount_client $MOUNT2
2343 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2348 # by remounting mdt before ost, initial connect from mdt to ost might
2349 # timeout because ost is not ready yet. wait some time to its fully
2350 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2351 # by a context negotiation rpc with $TIMEOUT.
2352 # FIXME better by monitoring import status.
2355 sleep $((TIMEOUT + 5))
2361 mounted_lustre_filesystems() {
2362 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2365 init_facet_vars () {
2366 [ "$CLIENTONLY" ] && return 0
2373 eval export ${facet}_dev=${device}
2374 eval export ${facet}_opt=\"$@\"
2376 local dev=${facet}_dev
2377 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2378 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2380 eval export ${facet}_svc=${label}
2382 local varname=${facet}failover_HOST
2383 if [ -z "${!varname}" ]; then
2384 eval $varname=$(facet_host $facet)
2387 # ${facet}failover_dev is set in cfg file
2388 varname=${facet}failover_dev
2389 if [ -n "${!varname}" ] ; then
2390 eval export ${facet}failover_dev=${!varname}
2392 eval export ${facet}failover_dev=$device
2395 # get mount point of already mounted device
2396 # is facet_dev is already mounted then use the real
2397 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2398 # i.e. ${facet}_MOUNT if specified by user or default
2399 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2400 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2401 if [ -z $mntpt ]; then
2402 mntpt=$(facet_mntpt $facet)
2404 eval export ${facet}_MOUNT=$mntpt
2407 init_facets_vars () {
2410 if ! remote_mds_nodsh; then
2411 for num in `seq $MDSCOUNT`; do
2412 DEVNAME=`mdsdevname $num`
2413 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2417 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2419 remote_ost_nodsh && return
2421 for num in `seq $OSTCOUNT`; do
2422 DEVNAME=`ostdevname $num`
2423 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2427 osc_ensure_active () {
2432 while [ $period -lt $timeout ]; do
2433 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2434 if [ $count -eq 0 ]; then
2438 echo "There are $count OST are inactive, wait $period seconds, and try again"
2440 period=$((period+3))
2443 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2446 init_param_vars () {
2447 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2448 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2449 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2450 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2454 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2456 log "Using TIMEOUT=$TIMEOUT"
2458 osc_ensure_active $SINGLEMDS $TIMEOUT
2459 osc_ensure_active client $TIMEOUT
2461 if [ $QUOTA_AUTO -ne 0 ]; then
2462 if [ "$ENABLE_QUOTA" ]; then
2463 echo "enable quota as required"
2464 setup_quota $MOUNT || return 2
2466 echo "disable quota as required"
2467 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2474 nfs_client_mode () {
2475 if [ "$NFSCLIENT" ]; then
2476 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2477 local clients=$CLIENTS
2478 [ -z $clients ] && clients=$(hostname)
2480 # FIXME: remove hostname when 19215 fixed
2481 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2482 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2483 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2484 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2486 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2492 check_config_client () {
2495 local mounted=$(mount | grep " $mntpt ")
2496 if [ "$CLIENTONLY" ]; then
2498 # CLIENTONLY should not depend on *_HOST settings
2499 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2500 # in theory someone could create a new,
2501 # client-only config file that assumed lustre was already
2502 # configured and didn't set the MGSNID. If MGSNID is not set,
2503 # then we should use the mgs nid currently being used
2504 # as the default value. bug 18021
2505 [[ x$MGSNID = x ]] &&
2508 if [[ x$mgc != xMGC$MGSNID ]]; then
2509 if [ "$mgs_HOST" ]; then
2510 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2511 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2512 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2518 local myMGS_host=$mgs_HOST
2519 if [ "$NETTYPE" = "ptl" ]; then
2520 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2523 echo Checking config lustre mounted on $mntpt
2524 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2525 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2527 # if [ "$mgshost" != "$myMGS_host" ]; then
2528 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2529 # Please use correct config or set mds_HOST correctly!"
2534 check_config_clients () {
2535 local clients=${CLIENTS:-$HOSTNAME}
2538 nfs_client_mode && return
2540 do_rpc_nodes $clients check_config_client $mntpt
2542 sanity_mount_check ||
2543 error "environments are insane!"
2547 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2548 local cltimeout=$(lctl get_param -n timeout)
2549 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2550 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2557 [ -z $mntpt ] && return 1
2558 local mounted=$(mounted_lustre_filesystems)
2560 echo $mounted' ' | grep -w -q $mntpt' '
2564 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2568 # empty lustre filesystem may have empty directories lost+found and .lustre
2570 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2571 -print | wc -l) = 1 ] || return 1
2572 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2573 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2577 check_and_setup_lustre() {
2578 nfs_client_mode && return
2580 local MOUNTED=$(mounted_lustre_filesystems)
2584 # both MOUNT and MOUNT2 are not mounted
2585 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2586 [ "$REFORMAT" ] && formatall
2587 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2589 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2590 export I_MOUNTED=yes
2594 elif is_mounted $MOUNT2; then
2596 # MOUNT2 is mounted, while MOUNT_2 is not set
2597 if ! [ "$MOUNT_2" ]; then
2598 cleanup_mount $MOUNT2
2599 export I_UMOUNTED2=yes
2602 # MOUNT2 is mounted, MOUNT_2 is set
2604 # FIXME: what to do if check_config failed?
2606 # 1) remote client has mounted other Lustre fs ?
2607 # 2) it has insane env ?
2608 # let's try umount MOUNT2 on all clients and mount it again:
2609 if ! check_config_clients $MOUNT2; then
2610 cleanup_mount $MOUNT2
2611 restore_mount $MOUNT2
2612 export I_MOUNTED2=yes
2617 # MOUNT is mounted MOUNT2 is not mounted
2618 elif [ "$MOUNT_2" ]; then
2619 restore_mount $MOUNT2
2620 export I_MOUNTED2=yes
2624 # FIXME: what to do if check_config failed?
2626 # 1) remote client has mounted other Lustre fs?
2627 # 2) lustre is mounted on remote_clients atall ?
2628 check_config_clients $MOUNT
2632 set_default_debug_nodes $(comma_list $(nodes_list))
2638 if [ "$ONLY" == "setup" ]; then
2644 local clients=${CLIENTS:-$HOSTNAME}
2647 zconf_mount_clients $clients $mntpt
2651 local clients=${CLIENTS:-$HOSTNAME}
2654 zconf_umount_clients $clients $mntpt
2657 cleanup_and_setup_lustre() {
2658 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2659 lctl set_param debug=0 || true
2661 if [ "$ONLY" == "cleanup" ]; then
2665 check_and_setup_lustre
2668 # Get all of the server target devices from a given server node and type.
2677 mdt) obd_type="osd" ;;
2678 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2679 *) echo "invalid server type" && return 1 ;;
2682 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2683 for dev in $devs; do
2685 *loop*) do_node $node "losetup $dev" | \
2686 sed -e "s/.*(//" -e "s/).*//" ;;
2692 # Get all of the server target devices.
2697 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2701 for node in $(osts_nodes); do
2702 OSTDEVS[i]=$(get_mnt_devs $node ost)
2707 # Run e2fsck on MDT or OST device.
2713 df > /dev/null # update statfs data on disk
2714 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2717 do_node $node $cmd || rc=$?
2718 [ $rc -le $FSCK_MAX_ERR ] || \
2719 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2723 # verify a directory is shared among nodes.
2724 check_shared_dir() {
2727 [ -z "$dir" ] && return 1
2728 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2729 check_write_access $dir || return 1
2733 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2739 check_shared_dir $SHARED_DIRECTORY ||
2740 error "$SHARED_DIRECTORY isn't a shared directory"
2742 export MDSDB=$SHARED_DIRECTORY/mdsdb
2743 export OSTDB=$SHARED_DIRECTORY/ostdb
2745 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2747 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2752 for node in $(osts_nodes); do
2753 for dev in ${OSTDEVS[i]}; do
2754 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2755 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2756 ostidx=$((ostidx + 1))
2763 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2767 [ $rc -le $FSCK_MAX_ERR ] || \
2768 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2769 echo "lfsck finished with rc=$rc"
2771 rm -rvf $MDSDB* $OSTDB* || true
2775 check_and_cleanup_lustre() {
2776 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2782 if is_mounted $MOUNT; then
2783 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
2784 error "remove sub-test dirs failed"
2785 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2788 if [ "$I_UMOUNTED2" = "yes" ]; then
2789 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2792 if [ "$I_MOUNTED2" = "yes" ]; then
2793 cleanup_mount $MOUNT2
2796 if [ "$I_MOUNTED" = "yes" ]; then
2797 cleanupall -f || error "cleanup failed"
2805 wait_for_function () {
2808 # suppress fn both stderr and stdout
2809 if [ "$1" = "--quiet" ]; then
2811 quiet=" > /dev/null 2>&1"
2823 eval $fn $quiet && return 0
2825 wait=$((wait + sleep))
2826 [ $wait -lt $max ] || return 1
2827 echo waiting $fn, $((max - wait)) secs left ...
2837 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2838 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2839 echo "Network not available!"
2843 echo `date +"%H:%M:%S (%s)"` network interface is UP
2852 # the sed converts spaces to commas, but leaves the last space
2853 # alone, so the line doesn't end with a comma.
2854 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2860 echo $list | grep -qw $item
2863 # list, excluded are the comma separated lists
2864 exclude_items_from_list () {
2870 for item in ${excluded//,/ }; do
2871 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2873 echo $(comma_list $list)
2876 # list, expand are the comma separated lists
2878 local list=${1//,/ }
2879 local expand=${2//,/ }
2882 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2883 echo $(comma_list $expanded)
2886 testslist_filter () {
2887 local script=$LUSTRE/tests/${TESTSUITE}.sh
2889 [ -f $script ] || return 0
2891 local start_at=$START_AT
2892 local stop_at=$STOP_AT
2894 local var=${TESTSUITE//-/_}_START_AT
2895 [ x"${!var}" != x ] && start_at=${!var}
2896 var=${TESTSUITE//-/_}_STOP_AT
2897 [ x"${!var}" != x ] && stop_at=${!var}
2899 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2900 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2901 /^'${start_at}'$/ {flag = 0}
2902 {if (flag == 1) print $0}
2903 /^'${stop_at}'$/ { flag = 1 }'
2907 (cd `dirname $1`; echo $PWD/`basename $1`)
2911 local types=${1:-"OST MDS MGS"}
2915 for entry in $types; do
2916 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2917 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2920 MGS ) list="$list $name";;
2921 MDS|OST ) local count=${type}COUNT
2922 for ((i=1; i<=${!count}; i++)) do
2923 list="$list ${name}$i"
2925 * ) error "Invalid facet type"
2929 echo $(comma_list $list)
2932 ##################################
2933 # Adaptive Timeouts funcs
2936 # only check mds, we assume at_max is the same on all nodes
2937 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2938 if [ $at_max -eq 0 ]; then
2949 # suppose that all ost-s have the same $at value set
2950 [ $facet != "ost" ] || facet=ost1
2952 do_facet $facet "lctl get_param -n $at"
2966 if [ $facet == "ost" ]; then
2967 facet=$(get_facets OST)
2968 elif [ $facet == "mds" ]; then
2969 facet=$(get_facets MDS)
2971 hosts=$(expand_list $hosts $(facets_hosts $facet))
2974 do_nodes $hosts lctl set_param at_max=$at_max
2977 ##################################
2981 # OBD_FAIL_MDS_ALL_REQUEST_NET
2983 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2984 do_facet client "$1" || RC=$?
2985 do_facet $SINGLEMDS lctl set_param fail_loc=0
2990 # OBD_FAIL_MDS_ALL_REPLY_NET
2992 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2993 do_facet client "$@" || RC=$?
2994 do_facet $SINGLEMDS lctl set_param fail_loc=0
2998 drop_reint_reply() {
2999 # OBD_FAIL_MDS_REINT_NET_REP
3001 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3002 do_facet client "$@" || RC=$?
3003 do_facet $SINGLEMDS lctl set_param fail_loc=0
3008 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3010 do_facet ost1 lctl set_param fail_loc=0x214
3011 do_facet client "$1" || RC=$?
3012 do_facet client "sync"
3013 do_facet ost1 lctl set_param fail_loc=0
3017 drop_ldlm_cancel() {
3018 #define OBD_FAIL_LDLM_CANCEL 0x304
3020 do_facet client lctl set_param fail_loc=0x304
3021 do_facet client "$@" || RC=$?
3022 do_facet client lctl set_param fail_loc=0
3026 drop_bl_callback() {
3027 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3029 do_facet client lctl set_param fail_loc=0x305
3030 do_facet client "$@" || RC=$?
3031 do_facet client lctl set_param fail_loc=0
3036 #define OBD_FAIL_LDLM_REPLY 0x30c
3038 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3039 do_facet client "$@" || RC=$?
3040 do_facet $SINGLEMDS lctl set_param fail_loc=0
3048 echo "clearing fail_loc on $facet"
3049 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3052 set_nodes_failloc () {
3053 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3056 cancel_lru_locks() {
3057 $LCTL mark "cancel_lru_locks $1 start"
3058 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3059 $LCTL set_param -n $d=clear
3061 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3062 $LCTL mark "cancel_lru_locks $1 stop"
3067 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3068 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3069 echo "$DEFAULT_LRU_SIZE"
3074 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3077 lru_resize_disable()
3079 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3084 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3085 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3086 echo there is still data in page cache $FILE ?
3087 lctl get_param -n $FILE
3095 DEBUGSAVE="$(lctl get_param -n debug)"
3099 [ -n "$DEBUGSAVE" ] && \
3100 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3105 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3108 debug_size_restore() {
3109 [ -n "$DEBUG_SIZE_SAVED" ] && \
3110 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3114 start_full_debug_logging() {
3119 local DEBUG_SIZE=150
3121 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3122 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3125 stop_full_debug_logging() {
3130 ##################################
3132 ##################################
3135 local TYPE=${TYPE:-"FAIL"}
3138 # do not dump logs if $1=false
3139 if [ "x$1" = "xfalse" ]; then
3144 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3147 # We need to dump the logs on all nodes
3149 gather_logs $(comma_list $(nodes_list))
3153 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3154 echo "$@" > $LOGDIR/err
3159 local log=$TESTSUITELOG
3161 [ -f "$log" ] && grep -q FAIL: $log && status=1
3174 # use only if we are ignoring failures for this test, bugno required.
3175 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3176 # e.g. error_ignore 5494 "your message"
3178 local TYPE="IGNORE (bz$1)"
3184 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3189 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3190 [ "$ALWAYS_SKIPPED" ] && \
3191 skip_logged ${TESTNAME} "$@" || true
3192 [ "$TESTSUITELOG" ] && \
3193 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3196 build_test_filter() {
3197 EXCEPT="$EXCEPT $(testslist_filter)"
3199 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3203 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3204 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3205 [ "$EXCEPT_SLOW" ] && \
3206 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3207 for E in $EXCEPT; do
3208 eval EXCEPT_${E}=true
3210 for E in $ALWAYS_EXCEPT; do
3211 eval EXCEPT_ALWAYS_${E}=true
3213 for E in $EXCEPT_SLOW; do
3214 eval EXCEPT_SLOW_${E}=true
3216 for G in $GRANT_CHECK_LIST; do
3217 eval GCHECK_ONLY_${G}=true
3222 if [[ $1 = [a-z]* ]]; then
3229 # print a newline if the last test was skipped
3230 export LAST_SKIPPED=
3231 export ALWAYS_SKIPPED=
3233 # Main entry into test-framework. This is called with the name and
3234 # description of a test. The name is used to find the function to run
3235 # the test using "test_$name".
3237 # This supports a variety of methods of specifying specific test to
3238 # run or not run. These need to be documented...
3243 export base=`basetest $1`
3244 if [ ! -z "$ONLY" ]; then
3246 if [ ${!testname}x != x ]; then
3247 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3248 run_one_logged $1 "$2"
3252 if [ ${!testname}x != x ]; then
3253 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3254 run_one_logged $1 "$2"
3262 if [ ${!testname}x != x ]; then
3264 TESTNAME=test_$1 skip "skipping excluded test $1"
3267 testname=EXCEPT_$base
3268 if [ ${!testname}x != x ]; then
3270 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3273 testname=EXCEPT_ALWAYS_$1
3274 if [ ${!testname}x != x ]; then
3277 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3280 testname=EXCEPT_ALWAYS_$base
3281 if [ ${!testname}x != x ]; then
3284 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3287 testname=EXCEPT_SLOW_$1
3288 if [ ${!testname}x != x ]; then
3290 TESTNAME=test_$1 skip "skipping SLOW test $1"
3293 testname=EXCEPT_SLOW_$base
3294 if [ ${!testname}x != x ]; then
3296 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3302 run_one_logged $1 "$2"
3313 module_loaded lnet || load_modules
3325 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3330 strace -o $TMP/$1.strace -ttt $*
3332 log "FINISHED: $*: rc $RC"
3337 equals_msg $1 test complete, duration $2 sec
3338 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3339 echo duration $2 >>$TESTSUITELOG
3343 # Set TEST_STATUS here; will be used for logging the result
3344 if [ -f $LOGDIR/err ]; then
3349 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3353 local FFREE=$(do_node $SINGLEMDS \
3354 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3355 local FTOTAL=$(do_node $SINGLEMDS \
3356 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3358 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3362 echo -n "Resetting fail_loc on all nodes..."
3363 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3369 # Log a message (on all nodes) padded with "=" before and after.
3370 # Also appends a timestamp and prepends the testsuite name.
3373 EQUALS="===================================================================================================="
3375 msg="== ${TESTSUITE} $*"
3377 [[ $last != "=" && $last != " " ]] && msg="$msg "
3378 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3379 # always include at least == after the message
3380 log "$msg== $(date +"%H:%M:%S (%s)")"
3384 # Run a single test function and cleanup after it.
3386 # This function should be run in a subshell so the test func can
3387 # exit() without stopping the whole script.
3393 export tdir=d0.${TESTSUITE}/d${base}
3394 export TESTNAME=test_$testnum
3395 local SAVE_UMASK=`umask`
3398 banner "test $testnum: $message"
3399 test_${testnum} || error "test_$testnum failed with $?"
3402 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3403 check_catastrophe || error "LBUG/LASSERT detected"
3404 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3412 # Wrapper around run_one to ensure:
3413 # - test runs in subshell
3414 # - output of test is saved to separate log file for error reporting
3415 # - test result is saved to data file
3418 local BEFORE=`date +%s`
3420 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3421 local test_log=$LOGDIR/$name
3423 local SAVE_UMASK=`umask`
3427 log_sub_test_begin test_${1}
3428 (run_one $1 "$2") 2>&1 | tee -i $test_log
3429 local RC=${PIPESTATUS[0]}
3431 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3432 echo "test_$1 returned $RC" | tee $LOGDIR/err
3434 duration=$((`date +%s` - $BEFORE))
3435 pass "$1" "(${duration}s)"
3436 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3437 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3439 if [ -f $LOGDIR/err ]; then
3440 $FAIL_ON_ERROR && exit $RC
3449 # Print information of skipped tests to result.yml
3452 log_sub_test_begin $1
3453 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3457 (cd `dirname $1`; echo $PWD/`basename $1`)
3462 export base=`basetest $1`
3463 [ "$CHECK_GRANT" == "no" ] && return 0
3465 testname=GCHECK_ONLY_${base}
3466 [ ${!testname}x == x ] && return 0
3468 echo -n "checking grant......"
3470 local clients=$CLIENTS
3471 [ -z $clients ] && clients=$(hostname)
3473 # sync all the data and make sure no pending data on server
3474 do_nodes $clients sync
3477 client_grant=`do_nodes $clients \
3478 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3479 awk '{total += $1} END{print total}'`
3482 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3483 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3484 awk '{total += $1} END{print total}'`
3486 # check whether client grant == server grant
3487 if [ $client_grant -ne $server_grant ]; then
3488 echo "failed: client:${client_grant} server: ${server_grant}."
3489 do_nodes $(comma_list $(osts_nodes)) \
3490 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3491 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3494 echo "pass: client:${client_grant} server: ${server_grant}"
3499 ########################
3505 ost=`echo $1 | awk -F_ '{print $3}'`
3506 if [ -z $ost ]; then
3507 ost=`echo $1 | sed 's/-osc.*//'`
3512 ostuuid_from_index()
3514 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3517 ostname_from_index() {
3518 local uuid=$(ostuuid_from_index $1)
3522 index_from_ostuuid()
3524 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3527 mdtuuid_from_index()
3529 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3534 [ "$node" != "$(hostname)" ]
3540 for node in $(mdts_nodes); do
3541 remote_node $node && return 0
3548 [ "$CLIENTONLY" ] && return 0 || true
3549 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3554 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3555 MSKIPPED=1 && return 1
3562 for node in $(osts_nodes) ; do
3563 remote_node $node && return 0
3570 [ "$CLIENTONLY" ] && return 0 || true
3571 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3576 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3577 OSKIPPED=1 && return 1
3584 MGS=$(facet_host mgs)
3585 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3590 remote_mds_nodsh || remote_ost_nodsh || \
3591 $(single_local_node $(comma_list $(nodes_list)))
3597 for num in `seq $MDSCOUNT`; do
3598 MDSNODES="$MDSNODES $(facet_host mds$num)"
3600 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3606 remote_ost && remote_mds
3614 for facet in ${facets//,/ }; do
3615 if [ "$FAILURE_MODE" = HARD ]; then
3616 nodes="$nodes $(facet_active_host $facet)"
3618 nodes="$nodes $(facet_host $facet)"
3621 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3627 local facets=$(get_facets OST)
3628 local nodes=$(facets_nodes $facets)
3634 # FIXME. We need a list of clients
3635 local myNODES=$HOSTNAME
3638 # CLIENTS (if specified) contains the local client
3639 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3641 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3642 myNODES="$myNODES $(facets_nodes $(get_facets))"
3645 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3650 remote_nodes_list () {
3651 local rnodes=$(nodes_list)
3652 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3656 init_clients_lists () {
3657 # Sanity check: exclude the local client from RCLIENTS
3658 local clients=$(hostlist_expand "$RCLIENTS")
3659 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3661 # Sanity check: exclude the dup entries
3662 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3664 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3666 # Sanity check: exclude the dup entries from CLIENTS
3667 # for those configs which has SINGLCLIENT set to local client
3668 clients=$(for i in $clients; do echo $i; done | sort -u)
3670 CLIENTS=$(comma_list $clients)
3671 local -a remoteclients=($RCLIENTS)
3672 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3673 varname=CLIENT$((i + 2))
3674 eval $varname=${remoteclients[i]}
3677 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3680 get_random_entry () {
3683 rnodes=${rnodes//,/ }
3685 local -a nodes=($rnodes)
3686 local num=${#nodes[@]}
3687 local i=$((RANDOM * num * 2 / 65536))
3693 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3698 lctl get_param version | grep -q patchless
3702 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3707 echo $nodes | wc -w || true
3711 local nodes=$(osts_nodes)
3712 local osscount=$(get_node_count "$nodes")
3713 [ ! "$OSTCOUNT" = "$osscount" ]
3717 local nodes=$(mdts_nodes)
3718 local mdtcount=$(get_node_count "$nodes")
3719 [ ! "$MDSCOUNT" = "$mdtcount" ]
3722 generate_machine_file() {
3723 local nodes=${1//,/ }
3724 local machinefile=$2
3726 for node in $nodes; do
3727 echo $node >>$machinefile || \
3728 { echo "can not generate machinefile $machinefile" && return 1; }
3733 local file=$1/stripe
3735 $LFS getstripe -v $file || error
3739 setstripe_nfsserver () {
3742 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3743 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3745 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3747 do_nodev $nfsserver lfs setstripe "$@"
3750 check_runas_id_ret() {
3752 local myRUNAS_UID=$1
3753 local myRUNAS_GID=$2
3756 if [ -z "$myRUNAS" ]; then
3757 error_exit "myRUNAS command must be specified for check_runas_id"
3760 $myRUNAS krb5_login.sh || \
3761 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3763 mkdir $DIR/d0_runas_test
3765 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3766 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3767 rm -rf $DIR/d0_runas_test
3772 local myRUNAS_UID=$1
3773 local myRUNAS_GID=$2
3776 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3777 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3778 Please set RUNAS_ID to some UID which exists on MDS and client or
3779 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3782 # obtain the UID/GID for MPI_USER
3786 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3787 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3789 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3790 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3793 # obtain and cache Kerberos ticket-granting ticket
3794 refresh_krb5_tgt() {
3795 local myRUNAS_UID=$1
3796 local myRUNAS_GID=$2
3799 if [ -z "$myRUNAS" ]; then
3800 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3803 CLIENTS=${CLIENTS:-$HOSTNAME}
3804 do_nodes $CLIENTS "set -x
3805 if ! $myRUNAS krb5_login.sh; then
3806 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3811 # Run multiop in the background, but wait for it to print
3812 # "PAUSING" to its stdout before returning from this function.
3813 multiop_bg_pause() {
3814 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3818 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3821 echo "$MULTIOP_PROG $FILE v$ARGS"
3822 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3824 echo "TMPPIPE=${TMPPIPE}"
3825 read -t 60 multiop_output < $TMPPIPE
3826 if [ $? -ne 0 ]; then
3831 if [ "$multiop_output" != "PAUSING" ]; then
3832 echo "Incorrect multiop output: $multiop_output"
3847 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3853 inodes_available () {
3854 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3858 mdsrate_inodes_available () {
3859 local min_inodes=$(inodes_available)
3860 echo $((min_inodes * 99 / 100))
3863 # reset llite stat counters
3864 clear_llite_stats(){
3865 lctl set_param -n llite.*.stats 0
3868 # sum llite stat items
3869 calc_llite_stats() {
3870 local res=$(lctl get_param -n llite.*.stats |
3871 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3875 # reset osc stat counters
3877 lctl set_param -n osc.*.osc_stats 0
3880 # sum osc stat items
3882 local res=$(lctl get_param -n osc.*.osc_stats |
3883 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3888 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3891 calc_osc_kbytes () {
3892 df $MOUNT > /dev/null
3893 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3896 # save_lustre_params(node, parameter_mask)
3897 # generate a stream of formatted strings (<node> <param name>=<param value>)
3898 save_lustre_params() {
3900 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3903 # restore lustre parameters from input stream, produces by save_lustre_params
3904 restore_lustre_params() {
3908 while IFS=" =" read node name val; do
3909 do_node ${node//:/} "lctl set_param -n $name $val"
3913 check_catastrophe() {
3914 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3915 local C=$CATASTROPHE
3916 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3918 if [ $rnodes ]; then
3919 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3920 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3925 # CMD: determine mds index where directory inode presents
3928 local file=$dir/f0.get_mds_dir_tmpfile
3933 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3934 local -a oldused=($iused)
3936 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3938 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3939 local -a newused=($iused)
3942 for ((i=0; i<${#newused[@]}; i++)); do
3943 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3949 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3952 mdsrate_cleanup () {
3954 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3959 delayed_recovery_enabled () {
3960 local var=${SINGLEMDS}_svc
3961 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3964 ########################
3966 convert_facet2label() {
3969 if [ x$facet = xost ]; then
3973 local varsvc=${facet}_svc
3975 if [ -n ${!varsvc} ]; then
3978 error "No lablel for $facet!"
3982 get_clientosc_proc_path() {
3983 echo "${1}-osc-[^M]*"
3986 get_lustre_version () {
3987 local facet=${1:-"$SINGLEMDS"}
3988 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3991 get_mds_version_major () {
3992 local facet=${1:-"$SINGLEMDS"}
3993 local version=$(get_lustre_version $facet)
3994 echo $version | awk -F. '{print $1}'
3997 get_mds_version_minor () {
3998 local facet=${1:-"$SINGLEMDS"}
3999 local version=$(get_lustre_version $facet)
4000 echo $version | awk -F. '{print $2}'
4003 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4004 # used by MDT would not be changed.
4005 # mdt lov: fsname-mdtlov
4006 # mdt osc: fsname-OSTXXXX-osc
4007 mds_on_old_device() {
4008 local mds=${1:-"$SINGLEMDS"}
4009 local major=$(get_mds_version_major $mds)
4010 local minor=$(get_mds_version_minor $mds)
4012 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
4013 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4014 > /dev/null 2>&1" && return 0
4019 get_mdtosc_proc_path() {
4021 local ost_label=${2:-"*OST*"}
4023 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4024 local mdt_label=$(convert_facet2label $mds_facet)
4025 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4027 local major=$(get_mds_version_major $mds_facet)
4028 local minor=$(get_mds_version_minor $mds_facet)
4029 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
4030 echo "${ost_label}-osc"
4032 echo "${ost_label}-osc-${mdt_index}"
4036 get_osc_import_name() {
4039 local label=$(convert_facet2label $ost)
4041 if [ "${facet:0:3}" = "mds" ]; then
4042 get_mdtosc_proc_path $facet $label
4046 get_clientosc_proc_path $label
4050 _wait_import_state () {
4053 local maxtime=${3:-$(max_recovery_time)}
4057 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4058 while [ "${CONN_STATE}" != "${expected}" ]; do
4059 if [ "${expected}" == "DISCONN" ]; then
4060 # for disconn we can check after proc entry is removed
4061 [ "x${CONN_STATE}" == "x" ] && return 0
4062 # with AT enabled, we can have connect request timeout near of
4063 # reconnect timeout and test can't see real disconnect
4064 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4066 [ $i -ge $maxtime ] && \
4067 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4070 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4074 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4078 wait_import_state() {
4081 local maxtime=${3:-$(max_recovery_time)}
4084 for param in ${params//,/ }; do
4085 _wait_import_state $state $param $maxtime || return
4089 # One client request could be timed out because server was not ready
4090 # when request was sent by client.
4091 # The request timeout calculation details :
4093 # /* We give the server rq_timeout secs to process the req, and
4094 # add the network latency for our local timeout. */
4095 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4096 # ptlrpc_at_get_net_latency(request) ;
4098 # ptlrpc_connect_import ()
4099 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4102 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4103 # ptlrpc_at_get_net_latency(request) ->
4104 # at_get (max (iat_net_latency=0, at_min)) = at_min
4107 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4108 # INITIAL_CONNECT_TIMEOUT + at_min
4110 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4111 # because we can not get this value in runtime,
4112 # the value depends on configure options, and it is not stored in /proc.
4114 # #define CONNECTION_SWITCH_MIN 5U
4116 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4118 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4120 request_timeout () {
4123 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4124 local init_connect_timeout=$TIMEOUT
4125 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4127 local at_min=$(at_get $facet at_min)
4129 echo $(( init_connect_timeout + at_min ))
4132 wait_osc_import_state() {
4136 local ost=$(get_osc_import_name $facet $ost_facet)
4138 local param="osc.${ost}.ost_server_uuid"
4140 # 1. wait the deadline of client 1st request (it could be skipped)
4141 # 2. wait the deadline of client 2nd request
4142 local maxtime=$(( 2 * $(request_timeout $facet)))
4144 if ! do_rpc_nodes $(facet_host $facet) \
4145 _wait_import_state $expected $param $maxtime; then
4146 error "import is not in ${expected} state"
4153 get_clientmdc_proc_path() {
4161 # Add paths to lustre tests for 32 and 64 bit systems.
4162 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4163 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4166 wait_clients_import_state () {
4173 if [ "$FAILURE_MODE" = HARD ]; then
4174 facets=$(facets_on_host $(facet_active_host $facet))
4177 for facet in ${facets//,/ }; do
4178 local label=$(convert_facet2label $facet)
4181 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4182 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4183 *) error "unknown facet!" ;;
4185 local params=$(expand_list $params $proc_path)
4188 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4189 error "import is not in ${expected} state"
4198 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4199 $LCTL get_param obdfilter.*.kbytesavail))
4200 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4201 $LCTL get_param -n obdfilter.*.tot_granted))
4202 for ((i=0; i<${#AVAILA[@]}; i++)); do
4203 local -a AVAIL1=(${AVAILA[$i]//=/ })
4204 GRANT=$((${GRANTA[$i]}/1024))
4205 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4206 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4212 do_facet mgs lctl pool_list $1
4216 local fsname=${1%%.*}
4217 local poolname=${1##$fsname.}
4219 do_facet mgs lctl pool_new $1
4221 # get param should return err unless pool is created
4222 [[ $RC -ne 0 ]] && return $RC
4224 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4225 2>/dev/null || echo foo" "" || RC=1
4226 if [[ $RC -eq 0 ]]; then
4229 error "pool_new failed $1"
4234 add_pool_to_list () {
4235 local fsname=${1%%.*}
4236 local poolname=${1##$fsname.}
4238 local listvar=${fsname}_CREATED_POOLS
4239 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4242 remove_pool_from_list () {
4243 local fsname=${1%%.*}
4244 local poolname=${1##$fsname.}
4246 local listvar=${fsname}_CREATED_POOLS
4247 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4250 destroy_pool_int() {
4252 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4253 awk '$1 !~ /^Pool:/ {print $1}')
4254 for ost in $OSTS; do
4255 do_facet mgs lctl pool_remove $1 $ost
4257 do_facet mgs lctl pool_destroy $1
4260 # <fsname>.<poolname> or <poolname>
4262 local fsname=${1%%.*}
4263 local poolname=${1##$fsname.}
4265 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4269 pool_list $fsname.$poolname || return $?
4271 destroy_pool_int $fsname.$poolname
4273 [[ $RC -ne 0 ]] && return $RC
4275 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4276 2>/dev/null || echo foo" "foo" || RC=1
4278 if [[ $RC -eq 0 ]]; then
4279 remove_pool_from_list $fsname.$poolname
4281 error "destroy pool failed $1"
4287 local fsname=${1:-$FSNAME}
4289 local listvar=${fsname}_CREATED_POOLS
4293 [ x${!listvar} = x ] && return 0
4295 echo destroy the created pools: ${!listvar}
4296 for poolname in ${!listvar//,/ }; do
4297 destroy_pool $fsname.$poolname
4302 local fsname=${1:-$FSNAME}
4304 destroy_pools $fsname
4310 local ts=$(date +%s)
4312 [ -f $LOGDIR/shared ] && docp=false
4314 # dump lustre logs, dmesg
4316 prefix="$TESTLOG_PREFIX.$TESTNAME"
4318 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4320 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4321 echo "Dumping logs only on local client."
4322 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4323 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4328 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4329 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4330 if [ ! -f $LOGDIR/shared ]; then
4331 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4344 for i in $(seq 0 $num_mntpts); do
4345 cmd="ls -laf ${mntpt_root}$i/$dir"
4351 for pid in $pids; do
4358 # target_start_and_reset_recovery_timer()
4359 # service_time = at_est2timeout(service_time);
4360 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4361 # INITIAL_CONNECT_TIMEOUT);
4362 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4363 #define CONNECTION_SWITCH_INC 1
4364 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4365 #define CONNECTION_SWITCH_MIN 5U
4367 max_recovery_time () {
4368 local init_connect_timeout=$(( TIMEOUT / 20 ))
4369 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4371 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4376 get_clients_mount_count () {
4377 local clients=${CLIENTS:-`hostname`}
4379 # we need to take into account the clients mounts and
4380 # exclude mds/ost mounts if any;
4381 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4385 PROC_CLI="srpc_info"
4393 if [ $M -lt $N ]; then
4397 while [ $N -lt $M ]; do
4407 calc_connection_cnt() {
4410 # MDT->MDT = 2 * C(M, 2)
4414 comb_m2=$(combination $MDSCOUNT 2)
4416 local num_clients=$(get_clients_mount_count)
4418 local cnt_mdt2mdt=$((comb_m2 * 2))
4419 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4420 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4421 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4422 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4423 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4424 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4438 local cmd="$tgt.srpc.flavor"
4440 if [ $net == "any" ]; then
4445 if [ $dir != "any" ]; then
4450 log "Setting sptlrpc rule: $cmd"
4451 do_facet mgs "$LCTL conf_param $cmd"
4460 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4461 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4463 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4465 if [ "x$bulkspec" != "x" ]; then
4466 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4468 if [ "x$algs" != "x" ]; then
4469 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4471 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4472 if [ $bulk == "bulkn" ]; then
4473 bulk_count=`echo "$output" | grep "bulk flavor" \
4474 | grep "null/null" | wc -l`
4475 elif [ $bulk == "bulki" ]; then
4476 bulk_count=`echo "$output" | grep "bulk flavor" \
4477 | grep "/null" | grep -v "null/" | wc -l`
4479 bulk_count=`echo "$output" | grep "bulk flavor" \
4480 | grep -v "/null" | grep -v "null/" | wc -l`
4484 [ $bulk_count -lt $count ] && count=$bulk_count
4495 local clients=${CLIENTS:-`hostname`}
4497 for c in ${clients//,/ }; do
4498 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4499 tmpcnt=`count_flvr "$output" $flavor`
4500 cnt=$((cnt + tmpcnt))
4510 local clients=${CLIENTS:-`hostname`}
4512 for c in ${clients//,/ }; do
4513 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4514 tmpcnt=`count_flvr "$output" $flavor`
4515 cnt=$((cnt + tmpcnt))
4525 if [ $MDSCOUNT -le 1 ]; then
4530 for num in `seq $MDSCOUNT`; do
4531 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4532 tmpcnt=`count_flvr "$output" $flavor`
4533 cnt=$((cnt + tmpcnt))
4544 for num in `seq $MDSCOUNT`; do
4545 mdtosc=$(get_mdtosc_proc_path mds$num)
4546 mdtosc=${mdtosc/-MDT*/-MDT\*}
4547 output=$(do_facet mds$num lctl get_param -n \
4548 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4549 tmpcnt=`count_flvr "$output" $flavor`
4550 cnt=$((cnt + tmpcnt))
4559 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4560 count_flvr "$output" $flavor
4565 local dir=$1 # from to
4566 local flavor=$2 # flavor expected
4569 if [ $dir == "cli2mdt" ]; then
4570 res=`flvr_cnt_cli2mdt $flavor`
4571 elif [ $dir == "cli2ost" ]; then
4572 res=`flvr_cnt_cli2ost $flavor`
4573 elif [ $dir == "mdt2mdt" ]; then
4574 res=`flvr_cnt_mdt2mdt $flavor`
4575 elif [ $dir == "mdt2ost" ]; then
4576 res=`flvr_cnt_mdt2ost $flavor`
4577 elif [ $dir == "all2ost" ]; then
4578 res1=`flvr_cnt_mdt2ost $flavor`
4579 res2=`flvr_cnt_cli2ost $flavor`
4580 res=$((res1 + res2))
4581 elif [ $dir == "all2mdt" ]; then
4582 res1=`flvr_cnt_mdt2mdt $flavor`
4583 res2=`flvr_cnt_cli2mdt $flavor`
4584 res=$((res1 + res2))
4585 elif [ $dir == "all2all" ]; then
4586 res1=`flvr_cnt_mdt2ost $flavor`
4587 res2=`flvr_cnt_cli2ost $flavor`
4588 res3=`flvr_cnt_mdt2mdt $flavor`
4589 res4=`flvr_cnt_cli2mdt $flavor`
4590 res=$((res1 + res2 + res3 + res4))
4598 local dir=$1 # from to
4599 local flavor=$2 # flavor expected
4600 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4604 for ((i=0;i<20;i++)); do
4605 echo -n "checking $dir..."
4606 res=$(do_check_flavor $dir $flavor)
4607 echo "found $res/$expect $flavor connections"
4608 [ $res -ge $expect ] && return 0
4612 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4616 restore_to_default_flavor()
4618 local proc="mgs.MGS.live.$FSNAME"
4620 echo "restoring to default flavor..."
4622 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4624 # remove all existing rules if any
4625 if [ $nrule -ne 0 ]; then
4626 echo "$nrule existing rules"
4627 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4628 echo "remove rule: $rule"
4629 spec=`echo $rule | awk -F = '{print $1}'`
4630 do_facet mgs "$LCTL conf_param -d $spec"
4634 # verify no rules left
4635 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4636 [ $nrule -ne 0 ] && error "still $nrule rules left"
4638 # wait for default flavor to be applied
4639 # currently default flavor for all connections are 'null'
4640 wait_flavor all2all null
4641 echo "now at default flavor settings"
4646 local flavor=${1:-null}
4648 echo "setting all flavor to $flavor"
4650 # FIXME need parameter to this fn
4651 # and remove global vars
4652 local cnt_all2all=$(calc_connection_cnt all2all)
4654 local res=$(do_check_flavor all2all $flavor)
4655 if [ $res -eq $cnt_all2all ]; then
4656 echo "already have total $res $flavor connections"
4660 echo "found $res $flavor out of total $cnt_all2all connections"
4661 restore_to_default_flavor
4663 [[ $flavor = null ]] && return 0
4665 set_rule $FSNAME any any $flavor
4666 wait_flavor all2all $flavor
4672 # Checking for shared logdir
4673 if [ ! -d $dir ]; then
4674 # Not found. Create local logdir
4677 touch $dir/node.$(hostname -s).yml
4682 check_write_access() {
4684 for node in $(nodes_list); do
4685 if [ ! -f "$dir/node.$(short_hostname ${node}).yml" ]; then
4686 # Logdir not accessible/writable from this node.
4690 rm -f $dir/node.*.yml
4695 if [[ -n $YAML_LOG ]]; then
4698 local SAVE_UMASK=`umask`
4701 export YAML_LOG=${LOGDIR}/results.yml
4705 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
4706 if check_shared_dir $LOGDIR; then
4707 touch $LOGDIR/shared
4708 echo "Logging to shared log directory: $LOGDIR"
4710 echo "Logging to local directory: $LOGDIR"
4713 yml_nodes_file $LOGDIR >> $YAML_LOG
4714 yml_results_file >> $YAML_LOG
4721 yml_log_test $1 >> $YAML_LOG
4725 yml_log_test_status $@ >> $YAML_LOG
4728 log_sub_test_begin() {
4729 yml_log_sub_test_begin "$@" >> $YAML_LOG
4732 log_sub_test_end() {
4733 yml_log_sub_test_end "$@" >> $YAML_LOG
4739 local llverdev_opts=$2
4740 local devname=$(basename $1)
4741 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4742 # loop devices aren't in /proc/partitions
4743 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4745 size=$(($size / 1024 / 1024)) # Gb
4747 local partial_arg=""
4748 # Run in partial (fast) mode if the size
4749 # of a partition > 1 GB
4750 [ $size -gt 1 ] && partial_arg="-p"
4752 llverdev --force $partial_arg $llverdev_opts $dev
4758 local llverfs_opts=$2
4759 local partial_arg=""
4760 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4762 # Run in partial (fast) mode if the size
4763 # of a partition > 1 GB
4764 [ $size -gt 1 ] && partial_arg="-p"
4766 llverfs $partial_arg $llverfs_opts $dir
4769 remove_mdt_files() {
4774 local mntpt=$(facet_mntpt $facet)
4776 echo "removing files from $mdtdev on $facet: $files"
4777 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4780 rm $mntpt/ROOT/$f || { rc=$?; break; }
4782 umount -f $mntpt || return $?
4786 duplicate_mdt_files() {
4791 local mntpt=$(facet_mntpt $facet)
4793 echo "duplicating files on $mdtdev on $facet: $files"
4794 mkdir -p $mntpt || return $?
4795 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4805 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4806 pushd $mntpt/ROOT > /dev/null || return $?
4809 touch $f.bad || return $?
4810 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4812 [ $rc -eq 0 ] || return $rc
4813 setfattr --restore $tmp || return $?
4819 local devs=${1//,/ }
4822 local rslt=$TMP/sgpdd_survey
4824 # sgpdd-survey cleanups ${rslt}.* files
4826 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4832 # returns the canonical name for an ldiskfs device
4837 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4838 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4839 echo dm-\\\${foo##*:};
4841 echo \\\$(basename \\\$dv);
4845 is_sanity_benchmark() {
4846 local benchmarks="dbench bonnie iozone fsx"
4848 for b in $benchmarks; do
4849 if [ "$b" == "$suite" ]; then
4857 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4860 # Get the block size of the filesystem.
4866 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4867 awk '/^Block size:/ {print $3}')
4871 # Check whether the "large_xattr" feature is enabled or not.
4872 large_xattr_enabled() {
4873 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4875 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4876 return ${PIPESTATUS[0]}
4879 # Get the maximum xattr size supported by the filesystem.
4883 if large_xattr_enabled; then
4884 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4887 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4888 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4890 # maximum xattr size = size of block - size of header -
4891 # size of 1 entry - 4 null bytes
4892 size=$((block_size - 32 - 32 - 4))
4898 # Dump the value of the named xattr from a file.
4903 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4906 # Generate a string with size of $size bytes.
4908 local size=${1:-1024} # in bytes
4910 echo "$(head -c $size < /dev/zero | tr '\0' y)"