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 if [[ -z $LOGDIRSET ]]; then
137 export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
138 export LOGDIRSET=true
140 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
141 if ! echo $PATH | grep -q $LUSTRE/utils; then
142 export PATH=$LUSTRE/utils:$PATH
144 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
145 export PATH=$LUSTRE/utils/gss:$PATH
147 if ! echo $PATH | grep -q $LUSTRE/tests; then
148 export PATH=$LUSTRE/tests:$PATH
150 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
151 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
153 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
154 [ ! -f "$LST" ] && export LST=$(which lst)
155 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
156 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
157 # Ubuntu, at least, has a truncate command in /usr/bin
158 # so fully path our truncate command.
159 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
160 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
161 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
162 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
163 export PATH=$LUSTRE/tests/racer:$PATH:
165 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
166 export PATH=$LUSTRE/tests/mpi:$PATH
168 export RSYNC_RSH=${RSYNC_RSH:-rsh}
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 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
174 if [ ! -f "$L_GETIDENTITY" ]; then
175 if `which l_getidentity > /dev/null 2>&1`; then
176 export L_GETIDENTITY=$(which l_getidentity)
178 export L_GETIDENTITY=NONE
181 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
182 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
183 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
184 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
185 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
186 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
187 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
188 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
189 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
190 export FSTYPE=${FSTYPE:-"ldiskfs"}
191 export NAME=${NAME:-local}
192 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
193 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
194 export LGSSD=$(which lgssd)
195 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
196 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
197 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
199 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
202 if [ "$ACCEPTOR_PORT" ]; then
203 export PORT_OPT="--port $ACCEPTOR_PORT"
208 echo "Using GSS/krb5 ptlrpc security flavor"
209 which lgss_keyring > /dev/null 2>&1 || \
210 error_exit "built with gss disabled! SEC=$SEC"
221 IDENTITY_UPCALL=false
224 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
226 # Paths on remote nodes, if different
227 export RLUSTRE=${RLUSTRE:-$LUSTRE}
228 export RPWD=${RPWD:-$PWD}
229 export I_MOUNTED=${I_MOUNTED:-"no"}
230 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
231 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
232 ! -f `dirname $0`/../mds/mds.ko ]; then
233 export CLIENTMODSONLY=yes
236 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
240 while getopts "rvwf:" opt $*; do
243 r) REFORMAT=--reformat;;
245 w) WRITECONF=writeconf;;
250 shift $((OPTIND - 1))
253 # print the durations of each test if "true"
254 DDETAILS=${DDETAILS:-false}
255 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
260 echo -n $((($1 << 16) | ($2 << 8) | $3))
263 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
264 export LINUX_VERSION_CODE=$(kernel_version ${LINUX_VERSION//\./ })
267 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
268 *) EXT=".ko"; USE_QUOTA=yes;;
273 /sbin/lsmod | grep -q "^\<$1\>"
276 # Load a module on the system where this is running.
278 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
280 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
281 # will be used as the arguments. Otherwise arguments will be obtained from
282 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
289 BASE=`basename $module $EXT`
291 module_loaded ${BASE} && return
293 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
295 if [ $# -eq 0 ]; then
296 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
297 # Bash until 4.x, so we resort to eval.
298 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
299 eval set -- \$$optvar
300 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
301 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
302 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
303 # Get rid of "options $module"
304 (($# > 0)) && shift 2
306 # Ensure we have accept=all for lnet
307 if [ $(basename $module) = lnet ]; then
308 # OK, this is a bit wordy...
309 local arg accept_all_present=false
311 [ "$arg" = accept=all ] && accept_all_present=true
313 $accept_all_present || set -- "$@" accept=all
318 [ $# -gt 0 ] && echo "${module} options: '$*'"
320 # Note that insmod will ignore anything in modprobe.conf, which is why we're
321 # passing options on the command-line.
322 if [ "$BASE" == "lnet_selftest" ] && \
323 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
324 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
325 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
326 insmod ${LUSTRE}/${module}${EXT} "$@"
328 # must be testing a "make install" or "rpm" installation
329 # note failed to load ptlrpc_gss is considered not fatal
330 if [ "$BASE" == "ptlrpc_gss" ]; then
331 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
338 llite_lloop_enabled() {
339 local n1=$(uname -r | cut -d. -f1)
340 local n2=$(uname -r | cut -d. -f2)
341 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
343 # load the llite_lloop module for < 2.6.32 kernels
344 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
345 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
352 load_modules_local() {
353 if [ -n "$MODPROBE" ]; then
355 echo "Using modprobe to load modules"
359 echo Loading modules from $LUSTRE
360 load_module ../libcfs/libcfs/libcfs
361 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
362 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
363 load_module ../lnet/lnet/lnet
364 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
365 load_module ../lnet/klnds/$LNETLND
366 load_module lvfs/lvfs
367 load_module obdclass/obdclass
368 load_module ptlrpc/ptlrpc
369 load_module ptlrpc/gss/ptlrpc_gss
370 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
378 if ! client_only; then
379 SYMLIST=/proc/kallsyms
380 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
381 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
382 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
383 if [ "$FSTYPE" = "ldiskfs" ]; then
384 grep -q exportfs_decode_fh $SYMLIST ||
385 { modprobe exportfs 2> /dev/null || true; }
386 load_module ../ldiskfs/ldiskfs/ldiskfs
392 load_module lvfs/fsfilt_$FSTYPE
394 load_module osd-ldiskfs/osd_ldiskfs
396 load_module obdfilter/obdfilter
400 load_module llite/lustre
401 llite_lloop_enabled && load_module llite/llite_lloop
402 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
404 rm -f $OGDB/ogdb-$HOSTNAME
405 $LCTL modules > $OGDB/ogdb-$HOSTNAME
407 # 'mount' doesn't look in $PATH, just sbin
408 if [ -f $LUSTRE/utils/mount.lustre ] && \
409 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
410 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
411 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
418 # load modules on remote nodes optionally
419 # lustre-tests have to be installed on these nodes
420 if $LOAD_MODULES_REMOTE ; then
421 local list=$(comma_list $(remote_nodes_list))
422 echo loading modules on $list
423 do_rpc_nodes $list load_modules
428 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
429 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
430 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
431 echo "$LEAK_LUSTRE" 1>&2
432 echo "$LEAK_PORTALS" 1>&2
433 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
434 echo "Memory leaks detected"
435 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
441 wait_exit_ST client # bug 12845
443 $LUSTRE_RMMOD $FSTYPE || return 2
445 if $LOAD_MODULES_REMOTE ; then
446 local list=$(comma_list $(remote_nodes_list))
447 if [ ! -z $list ]; then
448 echo unloading modules on $list
449 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
450 do_rpc_nodes $list check_mem_leak
454 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
455 umount /sbin/mount.lustre || true
456 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
457 rm -f /sbin/mount.lustre || true
460 check_mem_leak || return 254
462 echo "modules unloaded."
466 check_gss_daemon_nodes() {
470 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
471 if [ \\\"\\\$num\\\" -ne 1 ]; then
472 echo \\\$num instance of $dname;
477 check_gss_daemon_facet() {
481 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
482 if [ $num -ne 1 ]; then
483 echo "$num instance of $dname on $facet"
492 echo Stopping $@ on $list
493 do_nodes $list "killall -2 $@ 2>/dev/null || true"
496 # start gss daemons on all nodes, or
497 # "daemon" on "list" if set
498 start_gss_daemons() {
502 if [ "$list" ] && [ "$daemon" ] ; then
503 echo "Starting gss daemon on nodes: $list"
504 do_nodes $list "$daemon" || return 8
508 local list=$(comma_list $(mdts_nodes))
510 echo "Starting gss daemon on mds: $list"
511 do_nodes $list "$LSVCGSSD -v" || return 1
513 do_nodes $list "$LGSSD -v" || return 2
516 list=$(comma_list $(osts_nodes))
517 echo "Starting gss daemon on ost: $list"
518 do_nodes $list "$LSVCGSSD -v" || return 3
519 # starting on clients
521 local clients=${CLIENTS:-`hostname`}
523 echo "Starting $LGSSD on clients $clients "
524 do_nodes $clients "$LGSSD -v" || return 4
527 # wait daemons entering "stable" status
531 # check daemons are running
533 list=$(comma_list $(mdts_nodes) $(osts_nodes))
534 check_gss_daemon_nodes $list lsvcgssd || return 5
536 list=$(comma_list $(mdts_nodes))
537 check_gss_daemon_nodes $list lgssd || return 6
540 check_gss_daemon_nodes $clients lgssd || return 7
545 local list=$(comma_list $(mdts_nodes))
547 send_sigint $list lsvcgssd lgssd
549 list=$(comma_list $(osts_nodes))
550 send_sigint $list lsvcgssd
552 list=${CLIENTS:-`hostname`}
553 send_sigint $list lgssd
558 if ! module_loaded ptlrpc_gss; then
559 load_module ptlrpc/gss/ptlrpc_gss
560 module_loaded ptlrpc_gss ||
561 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
563 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
565 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
566 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
574 # maybe cleanup credential cache?
580 local device=`mdsdevname $num`
581 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
587 local device=`ostdevname $num`
588 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
593 local dz=${1:-$DEBUG_SIZE}
594 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
596 # bug 19944, adjust size to be -gt num_possible_cpus()
597 # promise 2MB for every cpu at least
598 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
601 lctl set_param debug_mb=$dz
604 set_default_debug () {
605 local debug=${1:-"$PTLDEBUG"}
606 local subsys=${2:-"$SUBSYSTEM"}
607 local debug_size=${3:-$DEBUG_SIZE}
609 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
610 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
612 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
615 set_default_debug_nodes () {
618 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
619 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
623 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
624 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
627 set_default_debug_facet () {
629 local node=$(facet_active_host $facet)
630 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
632 set_default_debug_nodes $node
637 local facets=${1:-$(get_facets)}
640 for facet in ${facets//,/ }; do
641 mount_facet $facet || error "Restart of $facet failed!"
648 local dev=$(facet_active $facet)_dev
649 local opt=${facet}_opt
650 local mntpt=$(facet_mntpt $facet)
652 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
653 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
655 if [ $RC -ne 0 ]; then
656 echo "mount -t lustre $@ ${!dev} $mntpt"
657 echo "Start of ${!dev} on ${facet} failed ${RC}"
659 set_default_debug_facet $facet
661 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
662 [ -z "$label" ] && echo no label for ${!dev} && exit 1
663 eval export ${facet}_svc=${label}
664 echo Started ${label}
669 # start facet device options
675 eval export ${facet}_dev=${device}
676 eval export ${facet}_opt=\"$@\"
678 local varname=${facet}failover_dev
679 if [ -n "${!varname}" ] ; then
680 eval export ${facet}failover_dev=${!varname}
682 eval export ${facet}failover_dev=$device
685 local mntpt=$(facet_mntpt $facet)
686 do_facet ${facet} mkdir -p $mntpt
687 eval export ${facet}_MOUNT=$mntpt
697 local HOST=`facet_active_host $facet`
698 [ -z $HOST ] && echo stop: no host for $facet && return 0
700 local mntpt=$(facet_mntpt $facet)
701 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
702 if [ ${running} -ne 0 ]; then
703 echo "Stopping $mntpt (opts:$@) on $HOST"
704 do_facet ${facet} umount -d $@ $mntpt
707 # umount should block, but we should wait for unrelated obd's
708 # like the MGS or MGC to also stop.
709 wait_exit_ST ${facet}
712 # save quota version (both administrative and operational quotas)
713 # add an additional parameter if mountpoint is ever different from $MOUNT
714 quota_save_version() {
715 local fsname=${2:-$FSNAME}
717 local ver=$(tr -c -d "123" <<< $spec)
718 local type=$(tr -c -d "ug" <<< $spec)
720 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
722 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
724 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
726 local osts=$(get_facets OST)
727 for ost in ${osts//,/ }; do
729 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
733 # client could mount several lustre
735 local fsname=${1:-$FSNAME}
737 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
738 do_nodes $(comma_list $(osts_nodes)) \
739 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
743 restore_quota_type () {
744 local mntpt=${1:-$MOUNT}
745 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
746 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
749 quota_save_version $old_QUOTA_TYPE
755 # We need save the original quota_type params, and restore them after testing
757 # Suppose that quota type the same on mds and ost
758 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
759 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
760 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
761 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
762 export old_QUOTA_TYPE=$quota_type
763 quota_save_version $QUOTA_TYPE
765 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
766 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
769 local quota_usrs=$QUOTA_USERS
771 # get_filesystem_size
772 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
773 local blk_soft=$((disksz + 1024))
774 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
776 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
778 local i_hard=$((i_soft + i_soft / 20))
780 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
781 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
784 for usr in $quota_usrs; do
785 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
787 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
789 eval $cmd || error "$cmd FAILED!"
791 # display the quota status
792 echo "Quota settings for $usr : "
793 $LFS quota -v -u $usr $mntpt || true
800 local OPTIONS=${3:-$MOUNTOPT}
802 local device=$MGSNID:/$FSNAME
803 if [ -z "$mnt" -o -z "$FSNAME" ]; then
804 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
808 echo "Starting client: $client: $OPTIONS $device $mnt"
809 do_node $client mkdir -p $mnt
810 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
812 set_default_debug_nodes $client
825 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
826 if [ $running -ne 0 ]; then
827 echo "Stopping client $client $mnt (opts:$force)"
828 do_node $client lsof -t $mnt || need_kill=no
829 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
830 pids=$(do_node $client lsof -t $mnt | sort -u);
831 if [ -n $pids ]; then
832 do_node $client kill -9 $pids || true
836 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
837 if [ $busy -ne 0 ] ; then
838 echo "$mnt is still busy, wait one second" && sleep 1
839 do_node $client umount $force $mnt
844 # nodes is comma list
845 sanity_mount_check_nodes () {
851 # FIXME: assume that all cluster nodes run the same os
852 [ "$(uname)" = Linux ] || return 0
855 for mnt in $mnts ; do
856 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
857 mpts=\\\$(mount | grep -w -c $mnt);
858 if [ \\\$running -ne \\\$mpts ]; then
859 echo \\\$(hostname) env are INSANE!;
867 sanity_mount_check_servers () {
869 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
870 echo Checking servers environments
872 # FIXME: modify get_facets to display all facets wo params
873 local facets="$(get_facets OST),$(get_facets MDS),mgs"
877 for facet in ${facets//,/ }; do
878 node=$(facet_host ${facet})
879 mntpt=$(facet_mntpt $facet)
880 sanity_mount_check_nodes $node $mntpt ||
881 { error "server $node environments are insane!"; return 1; }
885 sanity_mount_check_clients () {
886 local clients=${1:-$CLIENTS}
887 local mntpt=${2:-$MOUNT}
888 local mntpt2=${3:-$MOUNT2}
890 [ -z $clients ] && clients=$(hostname)
891 echo Checking clients $clients environments
893 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
894 error "clients environments are insane!"
897 sanity_mount_check () {
898 sanity_mount_check_servers || return 1
899 sanity_mount_check_clients || return 2
902 # mount clients if not mouted
903 zconf_mount_clients() {
906 local OPTIONS=${3:-$MOUNTOPT}
908 local device=$MGSNID:/$FSNAME
909 if [ -z "$mnt" -o -z "$FSNAME" ]; then
910 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
914 echo "Starting client $clients: $OPTIONS $device $mnt"
917 running=\\\$(mount | grep -c $mnt' ');
919 if [ \\\$running -eq 0 ] ; then
921 mount -t lustre $OPTIONS $device $mnt;
924 exit \\\$rc" || return ${PIPESTATUS[0]}
926 echo "Started clients $clients: "
927 do_nodes $clients "mount | grep -w $mnt"
929 set_default_debug_nodes $clients
934 zconf_umount_clients() {
941 echo "Stopping clients: $clients $mnt (opts:$force)"
942 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
943 if [ \\\$running -ne 0 ] ; then
944 echo Stopping client \\\$(hostname) $mnt opts:$force;
945 lsof $mnt || need_kill=no;
946 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
947 pids=\\\$(lsof -t $mnt | sort -u);
948 if [ -n \\\"\\\$pids\\\" ]; then
952 while umount $force $mnt 2>&1 | grep -q "busy"; do
953 echo "$mnt is still busy, wait one second" && sleep 1;
960 echo + $POWER_DOWN $node
964 shutdown_node_hard () {
966 local attempts=$SHUTDOWN_ATTEMPTS
968 for i in $(seq $attempts) ; do
971 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
972 echo "waiting for $host to fail attempts=$attempts"
973 [ $i -lt $attempts ] || \
974 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
980 local mnt=${2:-$MOUNT}
983 if [ "$FAILURE_MODE" = HARD ]; then
984 shutdown_node_hard $client
986 zconf_umount_clients $client $mnt -f
992 local facets="$(get_facets OST),$(get_facets MDS)"
995 combined_mgs_mds || facets="$facets,mgs"
997 for facet in ${facets//,/ }; do
998 if [ $(facet_active_host $facet) == $host ]; then
999 affected="$affected $facet"
1003 echo $(comma_list $affected)
1008 local host=${2:-$(facet_host $facet)}
1010 local label=$(convert_facet2label $facet)
1011 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1014 facets_up_on_host () {
1016 local facets=$(facets_on_host $host)
1019 for facet in ${facets//,/ }; do
1020 if $(facet_up $facet $host); then
1021 affected_up="$affected_up $facet"
1025 echo $(comma_list $affected_up)
1031 if [ "$FAILURE_MODE" = HARD ]; then
1032 shutdown_node_hard $(facet_active_host $facet)
1040 echo + $POWER_UP $node
1053 if [ "$FAILURE_MODE" = HARD ]; then
1054 reboot_node $(facet_active_host $facet)
1062 if [ "$FAILURE_MODE" = HARD ]; then
1072 for facet in ${facets//,/ }; do
1073 hosts=$(expand_list $hosts $(facet_host $facet) )
1079 _check_progs_installed () {
1083 for prog in $progs; do
1084 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1085 echo $prog missing on $(hostname)
1092 check_progs_installed () {
1096 do_rpc_nodes $nodes _check_progs_installed $@
1099 # recovery-scale functions
1101 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1104 start_client_load() {
1107 local var=$(node_var_name $client)_load
1108 eval export ${var}=$load
1110 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1111 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1112 END_RUN_FILE=$END_RUN_FILE \
1113 LOAD_PID_FILE=$LOAD_PID_FILE \
1114 TESTSUITELOG=$TESTSUITELOG \
1116 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
1117 log "Started client load: ${load} on $client"
1122 start_client_loads () {
1123 local -a clients=(${1//,/ })
1124 local numloads=${#CLIENT_LOADS[@]}
1127 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1128 testnum=$((nodenum % numloads))
1129 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1131 # bug 22169: wait the background threads to start
1135 # only for remote client
1136 check_client_load () {
1138 local var=$(node_var_name $client)_load
1139 local TESTLOAD=run_${!var}.sh
1141 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1143 # bug 18914: try to connect several times not only when
1144 # check ps, but while check_catastrophe also
1147 while [ $RC = 254 -a $tries -gt 0 ]; do
1151 if ! check_catastrophe $client; then
1153 if [ $RC -eq 254 ]; then
1154 # FIXME: not sure how long we shuold sleep here
1158 echo "check catastrophe failed: RC=$RC "
1162 # We can continue try to connect if RC=254
1163 # Just print the warning about this
1164 if [ $RC = 254 ]; then
1165 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1168 # see if the load is still on the client
1171 while [ $RC = 254 -a $tries -gt 0 ]; do
1175 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1180 if [ $RC = 254 ]; then
1181 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1182 # see if we can diagnose a bit why this is
1187 check_client_loads () {
1188 local clients=${1//,/ }
1192 for client in $clients; do
1193 check_client_load $client
1195 if [ "$rc" != 0 ]; then
1196 log "Client load failed on node $client, rc=$rc"
1202 restart_client_loads () {
1203 local clients=${1//,/ }
1204 local expectedfail=${2:-""}
1208 for client in $clients; do
1209 check_client_load $client
1211 if [ "$rc" != 0 -a "$expectedfail" ]; then
1212 local var=$(node_var_name $client)_load
1213 start_client_load $client ${!var}
1214 echo "Restarted client load ${!var}: on $client. Checking ..."
1215 check_client_load $client
1217 if [ "$rc" != 0 ]; then
1218 log "Client load failed to restart on node $client, rc=$rc"
1219 # failure one client load means test fail
1220 # we do not need to check other
1228 # End recovery-scale functions
1230 # verify that lustre actually cleaned up properly
1232 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1233 error "LBUG/LASSERT detected"
1234 BUSY=`dmesg | grep -i destruct || true`
1235 if [ "$BUSY" ]; then
1237 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1241 check_mem_leak || exit 204
1243 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1244 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1246 if module_loaded lnet || module_loaded libcfs; then
1247 echo "$0: modules still loaded..." 1>&2
1265 RESULT=$(do_node $node "$TEST")
1266 if [ "$RESULT" == "$FINAL" ]; then
1267 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1268 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1271 [ $WAIT -ge $MAX ] && break
1272 [ $((WAIT % print)) -eq 0 ] &&
1273 echo "Waiting $((MAX - WAIT)) secs for update"
1274 WAIT=$((WAIT + sleep))
1277 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1281 wait_update_facet () {
1283 wait_update $(facet_active_host $facet) "$@"
1286 wait_delete_completed () {
1287 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1288 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1292 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1294 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1295 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1296 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1297 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1301 echo "Delete is not completed in $MAX_WAIT sec"
1308 # we can use "for" here because we are waiting the slowest
1309 for host in ${hostlist//,/ }; do
1310 check_network "$host" 900
1312 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1319 for facet in ${facetlist//,/ }; do
1320 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1322 wait_for_host $hostlist
1325 _wait_recovery_complete () {
1328 # Use default policy if $2 is not passed by caller.
1329 local MAX=${2:-$(max_recovery_time)}
1334 while [ $WAIT -lt $MAX ]; do
1335 STATUS=$(lctl get_param -n $param | grep status)
1337 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1340 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1342 echo "$param recovery not done in $MAX sec. $STATUS"
1346 wait_recovery_complete () {
1349 # with an assumption that at_max is the same on all nodes
1350 local MAX=${2:-$(max_recovery_time)}
1353 if [ "$FAILURE_MODE" = HARD ]; then
1354 facets=$(facets_on_host $(facet_active_host $facet))
1356 echo affected facets: $facets
1358 # we can use "for" here because we are waiting the slowest
1359 for facet in ${facets//,/ }; do
1360 local var_svc=${facet}_svc
1361 local param="*.${!var_svc}.recovery_status"
1363 local host=$(facet_active_host $facet)
1364 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1368 wait_mds_ost_sync () {
1369 # just because recovery is done doesn't mean we've finished
1370 # orphan cleanup. Wait for llogs to get synchronized.
1371 echo "Waiting for orphan cleanup..."
1372 # MAX value includes time needed for MDS-OST reconnection
1373 local MAX=$(( TIMEOUT * 2 ))
1375 while [ $WAIT -lt $MAX ]; do
1376 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1377 "$LCTL get_param -n obdfilter.*.mds_sync"))
1380 for ((i=0; i<${#sync[@]}; i++)); do
1381 [ ${sync[$i]} -eq 0 ] && continue
1382 # there is a not finished MDS-OST synchronization
1386 sleep 2 # increase waiting time and cover statfs cache
1387 [ ${con} -eq 1 ] && return 0
1388 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1391 echo "$facet recovery not done in $MAX sec. $STATUS"
1395 wait_destroy_complete () {
1396 echo "Waiting for destroy to be done..."
1397 # MAX value shouldn't be big as this mean server responsiveness
1398 # never increase this just to make test pass but investigate
1399 # why it takes so long time
1402 while [ $WAIT -lt $MAX ]; do
1403 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1405 for ((i=0; i<${#RPCs[@]}; i++)); do
1406 [ ${RPCs[$i]} -eq 0 ] && continue
1407 # there are still some destroy RPCs in flight
1412 [ ${con} -eq 1 ] && return 0 # done waiting
1413 echo "Waiting $WAIT secs for destroys to be done."
1416 echo "Destroys weren't done in $MAX sec."
1426 # conf-sanity 31 takes a long time cleanup
1427 while [ $WAIT -lt 300 ]; do
1428 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1429 [ -z "${running}" ] && return 0
1430 echo "waited $WAIT for${running}"
1431 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1433 WAIT=$((WAIT + INTERVAL))
1435 echo "service didn't stop after $WAIT seconds. Still running:"
1440 wait_remote_prog () {
1446 [ "$PDSH" = "no_dsh" ] && return 0
1448 while [ $WAIT -lt $2 ]; do
1449 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1450 [ -z "${running}" ] && return 0 || true
1451 echo "waited $WAIT for: "
1453 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1455 WAIT=$((WAIT + INTERVAL))
1457 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1458 [ -z "$pids" ] && return 0
1459 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1460 # FIXME: not portable
1461 for pid in $pids; do
1462 cat /proc/${pid}/status || true
1463 cat /proc/${pid}/wchan || true
1465 kill -9 $pid || true
1474 # not every config has many clients
1476 if [ ! -z "$CLIENTS" ]; then
1477 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1479 stat -f $MOUNT > /dev/null
1485 # usually checked on particular client or locally
1487 if [ ! -z "$client" ]; then
1488 $PDSH $client "stat -f $MOUNT" > /dev/null
1490 stat -f $MOUNT > /dev/null
1498 client_reconnect() {
1499 uname -n >> $MOUNT/recon
1500 if [ -z "$CLIENTS" ]; then
1501 df $MOUNT; uname -n >> $MOUNT/recon
1503 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1505 echo Connected clients:
1507 ls -l $MOUNT/recon > /dev/null
1511 affected_facets () {
1514 local host=$(facet_active_host $facet)
1515 local affected=$facet
1517 if [ "$FAILURE_MODE" = HARD ]; then
1518 affected=$(facets_up_on_host $host)
1526 local host=$(facet_active_host $facet)
1528 echo "Failing $facet on node $host"
1530 # Make sure the client data is synced to disk. LU-924
1532 # We don't write client data synchrnously (to avoid flooding sync writes
1533 # when there are many clients connecting), so if the server reboots before
1534 # the client data reachs disk, the client data will be lost and the client
1535 # will be evicted after recovery, which is not what we expected.
1536 do_facet $facet "sync; sync; sync"
1538 local affected=$(affected_facets $facet)
1540 shutdown_facet $facet
1542 echo affected facets: $affected
1544 [ -n "$sleep_time" ] && sleep $sleep_time
1548 change_active $affected
1550 wait_for_facet $affected
1551 # start mgs first if it is affected
1552 if ! combined_mgs_mds && list_member $affected mgs; then
1553 mount_facet mgs || error "Restart of mgs failed"
1555 # FIXME; has to be changed to mount all facets concurrently
1556 affected=$(exclude_items_from_list $affected mgs)
1557 mount_facets $affected
1566 do_facet $facet "sync; sync; sync"
1569 # make sure there will be no seq change
1570 local clients=${CLIENTS:-$HOSTNAME}
1571 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1573 local svc=${facet}_svc
1574 do_facet $facet $LCTL --device %${!svc} notransno
1575 do_facet $facet $LCTL --device %${!svc} readonly
1576 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1577 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1580 replay_barrier_nodf() {
1581 local facet=$1 echo running=${running}
1582 do_facet $facet "sync; sync; sync"
1583 local svc=${facet}_svc
1584 echo Replay barrier on ${!svc}
1585 do_facet $facet $LCTL --device %${!svc} notransno
1586 do_facet $facet $LCTL --device %${!svc} readonly
1587 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1588 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1591 replay_barrier_nosync() {
1592 local facet=$1 echo running=${running}
1593 local svc=${facet}_svc
1594 echo Replay barrier on ${!svc}
1595 do_facet $facet $LCTL --device %${!svc} notransno
1596 do_facet $facet $LCTL --device %${!svc} readonly
1597 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1598 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1601 mds_evict_client() {
1602 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1603 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1606 ost_evict_client() {
1607 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1608 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1612 facet_failover $* || error "failover: $?"
1613 clients_up || error "post-failover df: $?"
1618 facet_failover $facet
1624 change_active $facet
1625 wait_for_facet $facet
1626 mount_facet $facet -o abort_recovery
1627 clients_up || echo "first df failed: $?"
1628 clients_up || error "post-failover df: $?"
1632 echo There is no lmc. This is mountconf, baby.
1636 host_nids_address() {
1640 if [ -n "$kind" ]; then
1641 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1643 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1649 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1655 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1656 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1657 if [ -z "$ID" ]; then
1658 echo "Could not get a ptl id for $1..."
1667 h2name_or_ip "$1" "tcp"
1672 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1673 if type __h2elan >/dev/null 2>&1; then
1676 ID=`echo $1 | sed 's/[^0-9]*//g'`
1684 h2name_or_ip "$1" "o2ib"
1688 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1689 # expressions format. As a bonus we can then just pass in those variables
1690 # to pdsh. What this function does is take a HOSTLIST type string and
1691 # expand it into a space deliminated list for us.
1699 [ -z "$hostlist" ] && return
1701 # Translate the case of [..],..,[..] to [..] .. [..]
1702 list="${hostlist/],/] }"
1704 [[ "$front" == *,* ]] && {
1707 list=${list/${old}/${new}}
1710 for item in $list; do
1711 # Test if we have any []'s at all
1712 if [ "$item" != "${item/\[/}" ]; then {
1713 # Expand the [*] into list
1717 if [ "$name" != "$item" ]; then
1718 group=${item#$name[*}
1721 for range in ${group//,/ }; do
1725 # Number of leading zeros
1728 end=$(echo $end | sed 's/0*//')
1729 [[ -z "$end" ]] && end=0
1730 [[ $padlen2 -gt $padlen ]] && {
1731 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1734 begin=$(echo $begin | sed 's/0*//')
1735 [ -z $begin ] && begin=0
1737 for num in $(seq -f "%0${padlen}g" $begin $end); do
1738 value="${name#*,}${num}${back}"
1739 [ "$value" != "${value/\[/}" ] && {
1740 value=$(hostlist_expand "$value")
1742 myList="$myList $value"
1747 myList="$myList $item"
1750 myList=${myList//,/ }
1751 myList=${myList:1} # Remove first character which is a space
1753 # Filter any duplicates without sorting
1755 myList="${list%% *}"
1757 while [[ "$list" != ${myList##* } ]]; do
1758 list=${list//${list%% *} /}
1759 myList="$myList ${list%% *}"
1761 myList="${myList%* }";
1763 # We can select an object at a offset in the list
1766 for item in $myList; do
1768 [ $cnt -eq $offset ] && {
1772 [ $(get_node_count $myList) -ne 1 ] && myList=""
1780 [ "$facet" == client ] && echo -n $HOSTNAME && return
1781 varname=${facet}_HOST
1782 if [ -z "${!varname}" ]; then
1783 if [ "${facet:0:3}" == "ost" ]; then
1784 eval ${facet}_HOST=${ost_HOST}
1792 local activevar=${facet}active
1794 if [ -f $TMP/${facet}active ] ; then
1795 source $TMP/${facet}active
1798 active=${!activevar}
1799 if [ -z "$active" ] ; then
1806 facet_active_host() {
1808 local active=`facet_active $facet`
1809 if [ "$facet" == client ]; then
1812 echo `facet_host $active`
1820 facetlist=$(exclude_items_from_list $facetlist mgs)
1822 for facet in ${facetlist//,/ }; do
1823 local failover=${facet}failover
1824 local host=`facet_host $failover`
1825 [ -z "$host" ] && return
1827 local curactive=`facet_active $facet`
1828 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1829 eval export ${facet}active=$facet
1831 eval export ${facet}active=$failover
1833 # save the active host for this facet
1834 local activevar=${facet}active
1835 echo "$activevar=${!activevar}" > $TMP/$activevar
1836 [[ $facet = mds1 ]] && combined_mgs_mds && \
1837 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1838 local TO=`facet_active_host $facet`
1839 echo "Failover $facet to $TO"
1845 # do not stripe off hostname if verbose, bug 19215
1846 if [ x$1 = x--verbose ]; then
1854 if [ "$HOST" = "$HOSTNAME" ]; then
1856 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1857 echo "cannot run remote command on $HOST with $myPDSH"
1861 echo "CMD: $HOST $@" >&2
1862 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1865 if [ "$myPDSH" = "rsh" ]; then
1866 # we need this because rsh does not return exit code of an executed command
1867 local command_status="$TMP/cs"
1868 rsh $HOST ":> $command_status"
1869 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1870 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1871 echo command failed >$command_status"
1872 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1877 # print HOSTNAME for myPDSH="no_dsh"
1878 if [[ $myPDSH = no_dsh ]]; then
1879 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1881 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1884 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1886 return ${PIPESTATUS[0]}
1890 do_node --verbose "$@"
1893 single_local_node () {
1894 [ "$1" = "$HOSTNAME" ]
1897 # Outputs environment variable assignments that should be passed to remote nodes
1902 for var in ${!MODOPTS_*}; do
1904 echo "${var}=\"$value\""
1910 # do not stripe off hostname if verbose, bug 19215
1911 if [ x$1 = x--verbose ]; then
1919 if single_local_node $rnodes; then
1921 do_nodev $rnodes "$@"
1923 do_node $rnodes "$@"
1928 # This is part from do_node
1931 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1932 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1935 echo "CMD: $rnodes $@" >&2
1936 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1939 # do not replace anything from pdsh output if -N is used
1940 # -N Disable hostname: prefix on lines of output.
1941 if $verbose || [[ $myPDSH = *-N* ]]; then
1942 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1944 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1946 return ${PIPESTATUS[0]}
1952 local HOST=`facet_active_host $facet`
1953 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1958 do_nodes --verbose "$@"
1964 # make sure its not already running
1966 rm -f $TMP/${facet}active
1967 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
1968 do_facet ${facet} $MKFS $*
1974 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1975 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1982 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1983 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1989 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
1991 local var=${facet}_MOUNT
1992 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2001 # make sure we are using the primary server, so test-framework will
2002 # be able to clean up properly.
2003 activemds=`facet_active mds1`
2004 if [ $activemds != "mds1" ]; then
2008 local clients=$CLIENTS
2009 [ -z $clients ] && clients=$(hostname)
2011 zconf_umount_clients $clients $MOUNT "$*" || true
2012 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2014 [ "$CLIENTONLY" ] && return
2015 # The add fn does rm ${facet}active file, this would be enough
2016 # if we use do_facet <facet> only after the facet added, but
2017 # currently we use do_facet mds in local.sh
2018 for num in `seq $MDSCOUNT`; do
2020 rm -f ${TMP}/mds${num}active
2022 combined_mgs_mds && rm -f $TMP/mgsactive
2024 for num in `seq $OSTCOUNT`; do
2026 rm -f $TMP/ost${num}active
2029 if ! combined_mgs_mds ; then
2036 cleanup_echo_devs () {
2037 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2039 for dev in $devs; do
2040 $LCTL --device $dev cleanup
2041 $LCTL --device $dev detach
2046 nfs_client_mode && return
2055 combined_mgs_mds () {
2056 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2062 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2063 local optvar=${tgt}_MKFS_OPTS
2064 local opt=${!optvar}
2066 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2067 [[ $facet = mgs ]] && echo $opt && return
2070 # --failnode options
2071 local var=${facet}failover_HOST
2072 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2073 local failnode=$(h2$NETTYPE ${!var})
2074 failnode="--failnode=$failnode"
2075 # options does not contain
2076 # or contains wrong --failnode=
2077 if [[ $opt != *${failnode}* ]]; then
2078 opt=$(echo $opt | sed 's/--failnode=.* / /')
2079 opt="$opt $failnode"
2085 # no additional mkfs mds "--mgsnode" option for this configuration
2086 if [[ $facet = mds ]] && combined_mgs_mds; then
2091 # additional mkfs "--mgsnode"
2092 local mgsnode="--mgsnode=$MGSNID"
2093 opt=${opt//$mgsnode }
2094 for nid in ${MGSNID//:/ }; do
2095 local mgsnode="--mgsnode=$nid"
2096 # options does not contain
2098 if [[ $opt != *${mgsnode}" "* ]]; then
2099 opt="$opt --mgsnode=$nid"
2107 if [ "$IAMDIR" == "yes" ]; then
2108 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2111 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2114 # We need ldiskfs here, may as well load them all
2116 [ "$CLIENTONLY" ] && return
2117 echo Formatting mgs, mds, osts
2118 if ! combined_mgs_mds ; then
2119 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2122 for num in `seq $MDSCOUNT`; do
2123 echo "Format mds$num: $(mdsdevname $num)"
2125 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2127 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2131 # the ost-s could have different OST_MKFS_OPTS
2132 # because of different failnode-s
2133 for num in `seq $OSTCOUNT`; do
2134 echo "Format ost$num: $(ostdevname $num)"
2136 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2138 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2144 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2148 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2152 # 0: success, the old identity set already.
2153 # 1: success, the old identity does not set.
2158 local j=`expr $num - 1`
2159 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2161 if [ -z "$MDT" ]; then
2165 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2168 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2170 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2173 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2175 if [ $old = "NONE" ]; then
2184 zconf_umount `hostname` $1 || error "umount failed"
2185 zconf_mount `hostname` $1 || error "mount failed"
2188 writeconf_facet () {
2192 do_facet $facet "$TUNEFS --writeconf $dev"
2196 for num in `seq $MDSCOUNT`; do
2197 DEVNAME=$(mdsdevname $num)
2198 writeconf_facet mds$num $DEVNAME
2201 for num in `seq $OSTCOUNT`; do
2202 DEVNAME=$(ostdevname $num)
2203 writeconf_facet ost$num $DEVNAME
2208 nfs_client_mode && return
2210 sanity_mount_check ||
2211 error "environments are insane!"
2215 if [ -z "$CLIENTONLY" ]; then
2216 echo Setup mgs, mdt, osts
2217 echo $WRITECONF | grep -q "writeconf" && \
2219 if ! combined_mgs_mds ; then
2220 start mgs $MGSDEV $MGS_MOUNT_OPTS
2223 for num in `seq $MDSCOUNT`; do
2224 DEVNAME=$(mdsdevname $num)
2225 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2227 # We started mds, now we should set failover variables properly.
2228 # Set mds${num}failover_HOST if it is not set (the default failnode).
2229 local varname=mds${num}failover_HOST
2230 if [ -z "${!varname}" ]; then
2231 eval mds${num}failover_HOST=$(facet_host mds$num)
2234 if [ $IDENTITY_UPCALL != "default" ]; then
2235 switch_identity $num $IDENTITY_UPCALL
2238 for num in `seq $OSTCOUNT`; do
2239 DEVNAME=$(ostdevname $num)
2240 start ost$num $DEVNAME $OST_MOUNT_OPTS
2242 # We started ost$num, now we should set ost${num}failover variable properly.
2243 # Set ost${num}failover_HOST if it is not set (the default failnode).
2244 varname=ost${num}failover_HOST
2245 if [ -z "${!varname}" ]; then
2246 eval ost${num}failover_HOST=$(facet_host ost${num})
2254 # wait a while to allow sptlrpc configuration be propogated to targets,
2255 # only needed when mounting new target devices.
2260 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2262 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2264 if [ "$MOUNT_2" ]; then
2265 mount_client $MOUNT2
2266 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2271 # by remounting mdt before ost, initial connect from mdt to ost might
2272 # timeout because ost is not ready yet. wait some time to its fully
2273 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2274 # by a context negotiation rpc with $TIMEOUT.
2275 # FIXME better by monitoring import status.
2278 sleep $((TIMEOUT + 5))
2284 mounted_lustre_filesystems() {
2285 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2288 init_facet_vars () {
2289 [ "$CLIENTONLY" ] && return 0
2296 eval export ${facet}_dev=${device}
2297 eval export ${facet}_opt=\"$@\"
2299 local dev=${facet}_dev
2300 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2301 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2303 eval export ${facet}_svc=${label}
2305 local varname=${facet}failover_HOST
2306 if [ -z "${!varname}" ]; then
2307 eval $varname=$(facet_host $facet)
2310 # ${facet}failover_dev is set in cfg file
2311 varname=${facet}failover_dev
2312 if [ -n "${!varname}" ] ; then
2313 eval export ${facet}failover_dev=${!varname}
2315 eval export ${facet}failover_dev=$device
2318 # get mount point of already mounted device
2319 # is facet_dev is already mounted then use the real
2320 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2321 # i.e. ${facet}_MOUNT if specified by user or default
2322 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2323 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2324 if [ -z $mntpt ]; then
2325 mntpt=$(facet_mntpt $facet)
2327 eval export ${facet}_MOUNT=$mntpt
2330 init_facets_vars () {
2333 if ! remote_mds_nodsh; then
2334 for num in `seq $MDSCOUNT`; do
2335 DEVNAME=`mdsdevname $num`
2336 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2340 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2342 remote_ost_nodsh && return
2344 for num in `seq $OSTCOUNT`; do
2345 DEVNAME=`ostdevname $num`
2346 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2350 osc_ensure_active () {
2355 while [ $period -lt $timeout ]; do
2356 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2357 if [ $count -eq 0 ]; then
2361 echo "There are $count OST are inactive, wait $period seconds, and try again"
2363 period=$((period+3))
2366 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2369 init_param_vars () {
2370 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2371 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2372 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2373 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2377 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2379 log "Using TIMEOUT=$TIMEOUT"
2381 osc_ensure_active $SINGLEMDS $TIMEOUT
2382 osc_ensure_active client $TIMEOUT
2384 if [ $QUOTA_AUTO -ne 0 ]; then
2385 if [ "$ENABLE_QUOTA" ]; then
2386 echo "enable quota as required"
2387 setup_quota $MOUNT || return 2
2389 echo "disable quota as required"
2390 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2397 nfs_client_mode () {
2398 if [ "$NFSCLIENT" ]; then
2399 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2400 local clients=$CLIENTS
2401 [ -z $clients ] && clients=$(hostname)
2403 # FIXME: remove hostname when 19215 fixed
2404 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2405 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2406 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2407 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2409 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2415 check_config_client () {
2418 local mounted=$(mount | grep " $mntpt ")
2419 if [ "$CLIENTONLY" ]; then
2421 # CLIENTONLY should not depend on *_HOST settings
2422 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2423 # in theory someone could create a new,
2424 # client-only config file that assumed lustre was already
2425 # configured and didn't set the MGSNID. If MGSNID is not set,
2426 # then we should use the mgs nid currently being used
2427 # as the default value. bug 18021
2428 [[ x$MGSNID = x ]] &&
2431 if [[ x$mgc != xMGC$MGSNID ]]; then
2432 if [ "$mgs_HOST" ]; then
2433 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2434 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2435 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2441 local myMGS_host=$mgs_HOST
2442 if [ "$NETTYPE" = "ptl" ]; then
2443 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2446 echo Checking config lustre mounted on $mntpt
2447 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2448 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2450 # if [ "$mgshost" != "$myMGS_host" ]; then
2451 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2452 # Please use correct config or set mds_HOST correctly!"
2457 check_config_clients () {
2458 local clients=${CLIENTS:-$HOSTNAME}
2461 nfs_client_mode && return
2463 do_rpc_nodes $clients check_config_client $mntpt
2465 sanity_mount_check ||
2466 error "environments are insane!"
2470 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2471 local cltimeout=$(lctl get_param -n timeout)
2472 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2473 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2480 [ -z $mntpt ] && return 1
2481 local mounted=$(mounted_lustre_filesystems)
2483 echo $mounted' ' | grep -w -q $mntpt' '
2487 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2491 # empty lustre filesystem may have empty directories lost+found and .lustre
2493 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2494 -print | wc -l) = 1 ] || return 1
2495 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2496 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2500 check_and_setup_lustre() {
2501 nfs_client_mode && return
2503 local MOUNTED=$(mounted_lustre_filesystems)
2507 # both MOUNT and MOUNT2 are not mounted
2508 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2509 [ "$REFORMAT" ] && formatall
2510 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2512 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2513 export I_MOUNTED=yes
2517 elif is_mounted $MOUNT2; then
2519 # MOUNT2 is mounted, while MOUNT_2 is not set
2520 if ! [ "$MOUNT_2" ]; then
2521 cleanup_mount $MOUNT2
2522 export I_UMOUNTED2=yes
2525 # MOUNT2 is mounted, MOUNT_2 is set
2527 # FIXME: what to do if check_config failed?
2529 # 1) remote client has mounted other Lustre fs ?
2530 # 2) it has insane env ?
2531 # let's try umount MOUNT2 on all clients and mount it again:
2532 if ! check_config_clients $MOUNT2; then
2533 cleanup_mount $MOUNT2
2534 restore_mount $MOUNT2
2535 export I_MOUNTED2=yes
2540 # MOUNT is mounted MOUNT2 is not mounted
2541 elif [ "$MOUNT_2" ]; then
2542 restore_mount $MOUNT2
2543 export I_MOUNTED2=yes
2547 # FIXME: what to do if check_config failed?
2549 # 1) remote client has mounted other Lustre fs?
2550 # 2) lustre is mounted on remote_clients atall ?
2551 check_config_clients $MOUNT
2555 set_default_debug_nodes $(comma_list $(nodes_list))
2561 if [ "$ONLY" == "setup" ]; then
2567 local clients=${CLIENTS:-$HOSTNAME}
2570 zconf_mount_clients $clients $mntpt
2574 local clients=${CLIENTS:-$HOSTNAME}
2577 zconf_umount_clients $clients $mntpt
2580 cleanup_and_setup_lustre() {
2581 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2582 lctl set_param debug=0 || true
2584 if [ "$ONLY" == "cleanup" ]; then
2588 check_and_setup_lustre
2591 # Get all of the server target devices from a given server node and type.
2600 mdt) obd_type="osd" ;;
2601 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2602 *) echo "invalid server type" && return 1 ;;
2605 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2606 for dev in $devs; do
2608 *loop*) do_node $node "losetup $dev" | \
2609 sed -e "s/.*(//" -e "s/).*//" ;;
2615 # Get all of the server target devices.
2620 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2624 for node in $(osts_nodes); do
2625 OSTDEVS[i]=$(get_mnt_devs $node ost)
2630 # Run e2fsck on MDT or OST device.
2636 df > /dev/null # update statfs data on disk
2637 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2640 do_node $node $cmd || rc=$?
2641 [ $rc -le $FSCK_MAX_ERR ] || \
2642 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2646 # verify a directory is shared among nodes.
2647 check_shared_dir() {
2650 [ -z "$dir" ] && return 1
2651 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2652 check_write_access $dir || return 1
2656 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2662 check_shared_dir $SHARED_DIRECTORY ||
2663 error "$SHARED_DIRECTORY isn't a shared directory"
2665 export MDSDB=$SHARED_DIRECTORY/mdsdb
2666 export OSTDB=$SHARED_DIRECTORY/ostdb
2668 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2670 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2675 for node in $(osts_nodes); do
2676 for dev in ${OSTDEVS[i]}; do
2677 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2678 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2679 ostidx=$((ostidx + 1))
2686 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2690 [ $rc -le $FSCK_MAX_ERR ] || \
2691 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2692 echo "lfsck finished with rc=$rc"
2694 rm -rvf $MDSDB* $OSTDB* || true
2698 check_and_cleanup_lustre() {
2699 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2705 if is_mounted $MOUNT; then
2706 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2707 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2710 if [ "$I_UMOUNTED2" = "yes" ]; then
2711 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2714 if [ "$I_MOUNTED2" = "yes" ]; then
2715 cleanup_mount $MOUNT2
2718 if [ "$I_MOUNTED" = "yes" ]; then
2719 cleanupall -f || error "cleanup failed"
2727 wait_for_function () {
2730 # suppress fn both stderr and stdout
2731 if [ "$1" = "--quiet" ]; then
2733 quiet=" > /dev/null 2>&1"
2745 eval $fn $quiet && return 0
2747 wait=$((wait + sleep))
2748 [ $wait -lt $max ] || return 1
2749 echo waiting $fn, $((max - wait)) secs left ...
2759 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2760 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2761 echo "Network not available!"
2765 echo `date +"%H:%M:%S (%s)"` network interface is UP
2774 # the sed converts spaces to commas, but leaves the last space
2775 # alone, so the line doesn't end with a comma.
2776 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2782 echo $list | grep -qw $item
2785 # list, excluded are the comma separated lists
2786 exclude_items_from_list () {
2792 for item in ${excluded//,/ }; do
2793 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2795 echo $(comma_list $list)
2798 # list, expand are the comma separated lists
2800 local list=${1//,/ }
2801 local expand=${2//,/ }
2804 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2805 echo $(comma_list $expanded)
2808 testslist_filter () {
2809 local script=$LUSTRE/tests/${TESTSUITE}.sh
2811 [ -f $script ] || return 0
2813 local start_at=$START_AT
2814 local stop_at=$STOP_AT
2816 local var=${TESTSUITE//-/_}_START_AT
2817 [ x"${!var}" != x ] && start_at=${!var}
2818 var=${TESTSUITE//-/_}_STOP_AT
2819 [ x"${!var}" != x ] && stop_at=${!var}
2821 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2822 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2823 /^'${start_at}'$/ {flag = 0}
2824 {if (flag == 1) print $0}
2825 /^'${stop_at}'$/ { flag = 1 }'
2829 (cd `dirname $1`; echo $PWD/`basename $1`)
2833 local types=${1:-"OST MDS MGS"}
2837 for entry in $types; do
2838 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2839 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2842 MGS ) list="$list $name";;
2843 MDS|OST ) local count=${type}COUNT
2844 for ((i=1; i<=${!count}; i++)) do
2845 list="$list ${name}$i"
2847 * ) error "Invalid facet type"
2851 echo $(comma_list $list)
2854 ##################################
2855 # Adaptive Timeouts funcs
2858 # only check mds, we assume at_max is the same on all nodes
2859 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2860 if [ $at_max -eq 0 ]; then
2871 # suppose that all ost-s have the same $at value set
2872 [ $facet != "ost" ] || facet=ost1
2874 do_facet $facet "lctl get_param -n $at"
2888 if [ $facet == "ost" ]; then
2889 facet=$(get_facets OST)
2890 elif [ $facet == "mds" ]; then
2891 facet=$(get_facets MDS)
2893 hosts=$(expand_list $hosts $(facets_hosts $facet))
2896 do_nodes $hosts lctl set_param at_max=$at_max
2899 ##################################
2903 # OBD_FAIL_MDS_ALL_REQUEST_NET
2905 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2906 do_facet client "$1" || RC=$?
2907 do_facet $SINGLEMDS lctl set_param fail_loc=0
2912 # OBD_FAIL_MDS_ALL_REPLY_NET
2914 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2915 do_facet client "$@" || RC=$?
2916 do_facet $SINGLEMDS lctl set_param fail_loc=0
2920 drop_reint_reply() {
2921 # OBD_FAIL_MDS_REINT_NET_REP
2923 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2924 do_facet client "$@" || RC=$?
2925 do_facet $SINGLEMDS lctl set_param fail_loc=0
2930 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2932 do_facet ost1 lctl set_param fail_loc=0x214
2933 do_facet client "$1" || RC=$?
2934 do_facet client "sync"
2935 do_facet ost1 lctl set_param fail_loc=0
2939 drop_ldlm_cancel() {
2940 #define OBD_FAIL_LDLM_CANCEL 0x304
2942 do_facet client lctl set_param fail_loc=0x304
2943 do_facet client "$@" || RC=$?
2944 do_facet client lctl set_param fail_loc=0
2948 drop_bl_callback() {
2949 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2951 do_facet client lctl set_param fail_loc=0x305
2952 do_facet client "$@" || RC=$?
2953 do_facet client lctl set_param fail_loc=0
2958 #define OBD_FAIL_LDLM_REPLY 0x30c
2960 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2961 do_facet client "$@" || RC=$?
2962 do_facet $SINGLEMDS lctl set_param fail_loc=0
2970 echo "clearing fail_loc on $facet"
2971 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2974 set_nodes_failloc () {
2975 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2978 cancel_lru_locks() {
2979 $LCTL mark "cancel_lru_locks $1 start"
2980 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2981 $LCTL set_param -n $d=clear
2983 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2984 $LCTL mark "cancel_lru_locks $1 stop"
2989 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2990 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2991 echo "$DEFAULT_LRU_SIZE"
2996 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2999 lru_resize_disable()
3001 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3006 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3007 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3008 echo there is still data in page cache $FILE ?
3009 lctl get_param -n $FILE
3017 DEBUGSAVE="$(lctl get_param -n debug)"
3021 [ -n "$DEBUGSAVE" ] && \
3022 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3027 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3030 debug_size_restore() {
3031 [ -n "$DEBUG_SIZE_SAVED" ] && \
3032 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3036 start_full_debug_logging() {
3041 local DEBUG_SIZE=150
3043 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3044 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3047 stop_full_debug_logging() {
3052 ##################################
3054 ##################################
3057 local TYPE=${TYPE:-"FAIL"}
3060 # do not dump logs if $1=false
3061 if [ "x$1" = "xfalse" ]; then
3066 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3068 # We need to dump the logs on all nodes
3070 gather_logs $(comma_list $(nodes_list)) 0
3074 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3075 echo "$@" > $LOGDIR/err
3080 local log=$TESTSUITELOG
3082 [ -f "$log" ] && grep -q FAIL: $log && status=1
3095 # use only if we are ignoring failures for this test, bugno required.
3096 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3097 # e.g. error_ignore 5494 "your message"
3099 local TYPE="IGNORE (bz$1)"
3105 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3110 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3111 [ "$ALWAYS_SKIPPED" ] && \
3112 skip_logged ${TESTNAME} "$@" || true
3113 [ "$TESTSUITELOG" ] && \
3114 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3117 build_test_filter() {
3118 EXCEPT="$EXCEPT $(testslist_filter)"
3120 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3124 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3125 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3126 [ "$EXCEPT_SLOW" ] && \
3127 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3128 for E in $EXCEPT; do
3129 eval EXCEPT_${E}=true
3131 for E in $ALWAYS_EXCEPT; do
3132 eval EXCEPT_ALWAYS_${E}=true
3134 for E in $EXCEPT_SLOW; do
3135 eval EXCEPT_SLOW_${E}=true
3137 for G in $GRANT_CHECK_LIST; do
3138 eval GCHECK_ONLY_${G}=true
3143 if [[ $1 = [a-z]* ]]; then
3150 # print a newline if the last test was skipped
3151 export LAST_SKIPPED=
3152 export ALWAYS_SKIPPED=
3154 # Main entry into test-framework. This is called with the name and
3155 # description of a test. The name is used to find the function to run
3156 # the test using "test_$name".
3158 # This supports a variety of methods of specifying specific test to
3159 # run or not run. These need to be documented...
3164 export base=`basetest $1`
3165 if [ ! -z "$ONLY" ]; then
3167 if [ ${!testname}x != x ]; then
3168 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3169 run_one_logged $1 "$2"
3173 if [ ${!testname}x != x ]; then
3174 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3175 run_one_logged $1 "$2"
3183 if [ ${!testname}x != x ]; then
3185 TESTNAME=test_$1 skip "skipping excluded test $1"
3188 testname=EXCEPT_$base
3189 if [ ${!testname}x != x ]; then
3191 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3194 testname=EXCEPT_ALWAYS_$1
3195 if [ ${!testname}x != x ]; then
3198 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3201 testname=EXCEPT_ALWAYS_$base
3202 if [ ${!testname}x != x ]; then
3205 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3208 testname=EXCEPT_SLOW_$1
3209 if [ ${!testname}x != x ]; then
3211 TESTNAME=test_$1 skip "skipping SLOW test $1"
3214 testname=EXCEPT_SLOW_$base
3215 if [ ${!testname}x != x ]; then
3217 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3223 run_one_logged $1 "$2"
3234 module_loaded lnet || load_modules
3246 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3251 strace -o $TMP/$1.strace -ttt $*
3253 log "FINISHED: $*: rc $RC"
3258 equals_msg $1 test complete, duration $2 sec
3259 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3260 echo duration $2 >>$TESTSUITELOG
3264 # Set TEST_STATUS here; will be used for logging the result
3265 if [ -f $LOGDIR/err ]; then
3270 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3274 local FFREE=$(do_node $SINGLEMDS \
3275 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3276 local FTOTAL=$(do_node $SINGLEMDS \
3277 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3279 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3283 echo -n "Resetting fail_loc on all nodes..."
3284 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3290 # Log a message (on all nodes) padded with "=" before and after.
3291 # Also appends a timestamp and prepends the testsuite name.
3294 EQUALS="===================================================================================================="
3296 msg="== ${TESTSUITE} $*"
3298 [[ $last != "=" && $last != " " ]] && msg="$msg "
3299 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3300 # always include at least == after the message
3301 log "$msg== $(date +"%H:%M:%S (%s)")"
3305 # Run a single test function and cleanup after it.
3307 # This function should be run in a subshell so the test func can
3308 # exit() without stopping the whole script.
3314 export tdir=d0.${TESTSUITE}/d${base}
3315 export TESTNAME=test_$testnum
3316 local SAVE_UMASK=`umask`
3319 banner "test $testnum: $message"
3320 test_${testnum} || error "test_$testnum failed with $?"
3323 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3324 check_catastrophe || error "LBUG/LASSERT detected"
3325 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3333 # Wrapper around run_one to ensure:
3334 # - test runs in subshell
3335 # - output of test is saved to separate log file for error reporting
3336 # - test result is saved to data file
3339 local BEFORE=`date +%s`
3341 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3342 local test_log=$LOGDIR/$name
3344 local SAVE_UMASK=`umask`
3348 log_sub_test_begin test_${1}
3349 (run_one $1 "$2") 2>&1 | tee -i $test_log
3350 local RC=${PIPESTATUS[0]}
3352 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3353 echo "test_$1 returned $RC" | tee $LOGDIR/err
3355 duration=$((`date +%s` - $BEFORE))
3356 pass "$1" "(${duration}s)"
3357 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3358 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3360 if [ -f $LOGDIR/err ]; then
3361 $FAIL_ON_ERROR && exit $RC
3370 # Print information of skipped tests to result.yml
3373 log_sub_test_begin $1
3374 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3378 (cd `dirname $1`; echo $PWD/`basename $1`)
3383 export base=`basetest $1`
3384 [ "$CHECK_GRANT" == "no" ] && return 0
3386 testname=GCHECK_ONLY_${base}
3387 [ ${!testname}x == x ] && return 0
3389 echo -n "checking grant......"
3391 local clients=$CLIENTS
3392 [ -z $clients ] && clients=$(hostname)
3394 # sync all the data and make sure no pending data on server
3395 do_nodes $clients sync
3398 client_grant=`do_nodes $clients \
3399 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3400 awk '{total += $1} END{print total}'`
3403 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3404 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
3405 awk '{total += $1} END{print total}'`
3407 # check whether client grant == server grant
3408 if [ $client_grant -ne $server_grant ]; then
3409 echo "failed: client:${client_grant} server: ${server_grant}."
3410 do_nodes $(comma_list $(osts_nodes)) \
3411 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3412 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3415 echo "pass: client:${client_grant} server: ${server_grant}"
3420 ########################
3426 ost=`echo $1 | awk -F_ '{print $3}'`
3427 if [ -z $ost ]; then
3428 ost=`echo $1 | sed 's/-osc.*//'`
3433 ostuuid_from_index()
3435 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3438 ostname_from_index() {
3439 local uuid=$(ostuuid_from_index $1)
3443 index_from_ostuuid()
3445 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3448 mdtuuid_from_index()
3450 $LFS mdts $2 | awk '/^'$1'/ { print $2 }'
3455 [ "$node" != "$(hostname)" ]
3461 for node in $(mdts_nodes); do
3462 remote_node $node && return 0
3469 [ "$CLIENTONLY" ] && return 0 || true
3470 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3475 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3476 MSKIPPED=1 && return 1
3483 for node in $(osts_nodes) ; do
3484 remote_node $node && return 0
3491 [ "$CLIENTONLY" ] && return 0 || true
3492 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3497 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3498 OSKIPPED=1 && return 1
3505 MGS=$(facet_host mgs)
3506 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3511 remote_mds_nodsh || remote_ost_nodsh || \
3512 $(single_local_node $(comma_list $(nodes_list)))
3518 for num in `seq $MDSCOUNT`; do
3519 MDSNODES="$MDSNODES $(facet_host mds$num)"
3521 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3527 remote_ost && remote_mds
3535 for facet in ${facets//,/ }; do
3536 if [ "$FAILURE_MODE" = HARD ]; then
3537 nodes="$nodes $(facet_active_host $facet)"
3539 nodes="$nodes $(facet_host $facet)"
3542 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3548 local facets=$(get_facets OST)
3549 local nodes=$(facets_nodes $facets)
3555 # FIXME. We need a list of clients
3556 local myNODES=$HOSTNAME
3559 # CLIENTS (if specified) contains the local client
3560 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3562 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3563 myNODES="$myNODES $(facets_nodes $(get_facets))"
3566 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3571 remote_nodes_list () {
3572 local rnodes=$(nodes_list)
3573 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3577 init_clients_lists () {
3578 # Sanity check: exclude the local client from RCLIENTS
3579 local clients=$(hostlist_expand "$RCLIENTS")
3580 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3582 # Sanity check: exclude the dup entries
3583 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3585 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3587 # Sanity check: exclude the dup entries from CLIENTS
3588 # for those configs which has SINGLCLIENT set to local client
3589 clients=$(for i in $clients; do echo $i; done | sort -u)
3591 CLIENTS=$(comma_list $clients)
3592 local -a remoteclients=($RCLIENTS)
3593 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3594 varname=CLIENT$((i + 2))
3595 eval $varname=${remoteclients[i]}
3598 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3601 get_random_entry () {
3604 rnodes=${rnodes//,/ }
3606 local -a nodes=($rnodes)
3607 local num=${#nodes[@]}
3608 local i=$((RANDOM * num * 2 / 65536))
3614 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3619 lctl get_param version | grep -q patchless
3623 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3628 echo $nodes | wc -w || true
3632 local nodes=$(osts_nodes)
3633 local osscount=$(get_node_count "$nodes")
3634 [ ! "$OSTCOUNT" = "$osscount" ]
3638 local nodes=$(mdts_nodes)
3639 local mdtcount=$(get_node_count "$nodes")
3640 [ ! "$MDSCOUNT" = "$mdtcount" ]
3643 generate_machine_file() {
3644 local nodes=${1//,/ }
3645 local machinefile=$2
3647 for node in $nodes; do
3648 echo $node >>$machinefile || \
3649 { echo "can not generate machinefile $machinefile" && return 1; }
3654 local file=$1/stripe
3656 $LFS getstripe -v $file || error
3660 setstripe_nfsserver () {
3663 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3664 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3666 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3668 do_nodev $nfsserver lfs setstripe "$@"
3671 check_runas_id_ret() {
3673 local myRUNAS_UID=$1
3674 local myRUNAS_GID=$2
3677 if [ -z "$myRUNAS" ]; then
3678 error_exit "myRUNAS command must be specified for check_runas_id"
3681 $myRUNAS krb5_login.sh || \
3682 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3684 mkdir $DIR/d0_runas_test
3686 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3687 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3688 rm -rf $DIR/d0_runas_test
3693 local myRUNAS_UID=$1
3694 local myRUNAS_GID=$2
3697 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3698 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3699 Please set RUNAS_ID to some UID which exists on MDS and client or
3700 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3703 # obtain the UID/GID for MPI_USER
3707 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3708 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3710 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3711 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3714 # obtain and cache Kerberos ticket-granting ticket
3715 refresh_krb5_tgt() {
3716 local myRUNAS_UID=$1
3717 local myRUNAS_GID=$2
3720 if [ -z "$myRUNAS" ]; then
3721 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3724 CLIENTS=${CLIENTS:-$HOSTNAME}
3725 do_nodes $CLIENTS "set -x
3726 if ! $myRUNAS krb5_login.sh; then
3727 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3732 # Run multiop in the background, but wait for it to print
3733 # "PAUSING" to its stdout before returning from this function.
3734 multiop_bg_pause() {
3735 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3739 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3742 echo "$MULTIOP_PROG $FILE v$ARGS"
3743 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3745 echo "TMPPIPE=${TMPPIPE}"
3746 read -t 60 multiop_output < $TMPPIPE
3747 if [ $? -ne 0 ]; then
3752 if [ "$multiop_output" != "PAUSING" ]; then
3753 echo "Incorrect multiop output: $multiop_output"
3768 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3774 inodes_available () {
3775 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3779 mdsrate_inodes_available () {
3780 local min_inodes=$(inodes_available)
3781 echo $((min_inodes * 99 / 100))
3784 # reset llite stat counters
3785 clear_llite_stats(){
3786 lctl set_param -n llite.*.stats 0
3789 # sum llite stat items
3790 calc_llite_stats() {
3791 local res=$(lctl get_param -n llite.*.stats |
3792 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3796 # reset osc stat counters
3798 lctl set_param -n osc.*.osc_stats 0
3801 # sum osc stat items
3803 local res=$(lctl get_param -n osc.*.osc_stats |
3804 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3809 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3812 calc_osc_kbytes () {
3813 df $MOUNT > /dev/null
3814 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3817 # save_lustre_params(node, parameter_mask)
3818 # generate a stream of formatted strings (<node> <param name>=<param value>)
3819 save_lustre_params() {
3821 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3824 # restore lustre parameters from input stream, produces by save_lustre_params
3825 restore_lustre_params() {
3829 while IFS=" =" read node name val; do
3830 do_node ${node//:/} "lctl set_param -n $name $val"
3834 check_catastrophe() {
3835 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3836 local C=$CATASTROPHE
3837 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3839 if [ $rnodes ]; then
3840 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3841 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3857 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3859 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3860 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3861 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3865 # CMD: determine mds index where directory inode presents
3868 local file=$dir/f0.get_mds_dir_tmpfile
3873 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3874 local -a oldused=($iused)
3876 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3878 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3879 local -a newused=($iused)
3882 for ((i=0; i<${#newused[@]}; i++)); do
3883 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3889 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3892 mdsrate_cleanup () {
3894 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3899 delayed_recovery_enabled () {
3900 local var=${SINGLEMDS}_svc
3901 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3904 ########################
3906 convert_facet2label() {
3909 if [ x$facet = xost ]; then
3913 local varsvc=${facet}_svc
3915 if [ -n ${!varsvc} ]; then
3918 error "No lablel for $facet!"
3922 get_clientosc_proc_path() {
3923 echo "${1}-osc-[^M]*"
3926 get_lustre_version () {
3927 local facet=${1:-"$SINGLEMDS"}
3928 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3931 get_mds_version_major () {
3932 local facet=${1:-"$SINGLEMDS"}
3933 local version=$(get_lustre_version $facet)
3934 echo $version | awk -F. '{print $1}'
3937 get_mds_version_minor () {
3938 local facet=${1:-"$SINGLEMDS"}
3939 local version=$(get_lustre_version $facet)
3940 echo $version | awk -F. '{print $2}'
3943 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
3944 # used by MDT would not be changed.
3945 # mdt lov: fsname-mdtlov
3946 # mdt osc: fsname-OSTXXXX-osc
3947 mds_on_old_device() {
3948 local mds=${1:-"$SINGLEMDS"}
3949 local major=$(get_mds_version_major $mds)
3950 local minor=$(get_mds_version_minor $mds)
3952 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
3953 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
3954 > /dev/null 2>&1" && return 0
3959 get_mdtosc_proc_path() {
3961 local ost_label=${2:-"*OST*"}
3963 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
3964 local mdt_label=$(convert_facet2label $mds_facet)
3965 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
3967 local major=$(get_mds_version_major $mds_facet)
3968 local minor=$(get_mds_version_minor $mds_facet)
3969 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
3970 echo "${ost_label}-osc"
3972 echo "${ost_label}-osc-${mdt_index}"
3976 get_osc_import_name() {
3979 local label=$(convert_facet2label $ost)
3981 if [ "${facet:0:3}" = "mds" ]; then
3982 get_mdtosc_proc_path $facet $label
3986 get_clientosc_proc_path $label
3990 _wait_import_state () {
3993 local maxtime=${3:-$(max_recovery_time)}
3997 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3998 while [ "${CONN_STATE}" != "${expected}" ]; do
3999 if [ "${expected}" == "DISCONN" ]; then
4000 # for disconn we can check after proc entry is removed
4001 [ "x${CONN_STATE}" == "x" ] && return 0
4002 # with AT enabled, we can have connect request timeout near of
4003 # reconnect timeout and test can't see real disconnect
4004 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4006 [ $i -ge $maxtime ] && \
4007 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4010 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4014 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4018 wait_import_state() {
4021 local maxtime=${3:-$(max_recovery_time)}
4024 for param in ${params//,/ }; do
4025 _wait_import_state $state $param $maxtime || return
4029 # One client request could be timed out because server was not ready
4030 # when request was sent by client.
4031 # The request timeout calculation details :
4033 # /* We give the server rq_timeout secs to process the req, and
4034 # add the network latency for our local timeout. */
4035 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4036 # ptlrpc_at_get_net_latency(request) ;
4038 # ptlrpc_connect_import ()
4039 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4042 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4043 # ptlrpc_at_get_net_latency(request) ->
4044 # at_get (max (iat_net_latency=0, at_min)) = at_min
4047 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4048 # INITIAL_CONNECT_TIMEOUT + at_min
4050 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4051 # because we can not get this value in runtime,
4052 # the value depends on configure options, and it is not stored in /proc.
4054 # #define CONNECTION_SWITCH_MIN 5U
4056 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4058 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4060 request_timeout () {
4063 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4064 local init_connect_timeout=$TIMEOUT
4065 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4067 local at_min=$(at_get $facet at_min)
4069 echo $(( init_connect_timeout + at_min ))
4072 wait_osc_import_state() {
4076 local ost=$(get_osc_import_name $facet $ost_facet)
4078 local param="osc.${ost}.ost_server_uuid"
4080 # 1. wait the deadline of client 1st request (it could be skipped)
4081 # 2. wait the deadline of client 2nd request
4082 local maxtime=$(( 2 * $(request_timeout $facet)))
4084 if ! do_rpc_nodes $(facet_host $facet) \
4085 _wait_import_state $expected $param $maxtime; then
4086 error "import is not in ${expected} state"
4093 get_clientmdc_proc_path() {
4101 # Add paths to lustre tests for 32 and 64 bit systems.
4102 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4103 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4106 wait_clients_import_state () {
4113 if [ "$FAILURE_MODE" = HARD ]; then
4114 facets=$(facets_on_host $(facet_active_host $facet))
4117 for facet in ${facets//,/ }; do
4118 local label=$(convert_facet2label $facet)
4121 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4122 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4123 *) error "unknown facet!" ;;
4125 local params=$(expand_list $params $proc_path)
4128 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4129 error "import is not in ${expected} state"
4138 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4139 $LCTL get_param obdfilter.*.kbytesavail))
4140 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4141 $LCTL get_param -n obdfilter.*.tot_granted))
4142 for ((i=0; i<${#AVAILA[@]}; i++)); do
4143 local -a AVAIL1=(${AVAILA[$i]//=/ })
4144 GRANT=$((${GRANTA[$i]}/1024))
4145 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4146 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4152 do_facet mgs lctl pool_list $1
4156 local fsname=${1%%.*}
4157 local poolname=${1##$fsname.}
4159 do_facet mgs lctl pool_new $1
4161 # get param should return err unless pool is created
4162 [[ $RC -ne 0 ]] && return $RC
4164 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4165 2>/dev/null || echo foo" "" || RC=1
4166 if [[ $RC -eq 0 ]]; then
4169 error "pool_new failed $1"
4174 add_pool_to_list () {
4175 local fsname=${1%%.*}
4176 local poolname=${1##$fsname.}
4178 local listvar=${fsname}_CREATED_POOLS
4179 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4182 remove_pool_from_list () {
4183 local fsname=${1%%.*}
4184 local poolname=${1##$fsname.}
4186 local listvar=${fsname}_CREATED_POOLS
4187 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4190 destroy_pool_int() {
4192 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4193 awk '$1 !~ /^Pool:/ {print $1}')
4194 for ost in $OSTS; do
4195 do_facet mgs lctl pool_remove $1 $ost
4197 do_facet mgs lctl pool_destroy $1
4200 # <fsname>.<poolname> or <poolname>
4202 local fsname=${1%%.*}
4203 local poolname=${1##$fsname.}
4205 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4209 pool_list $fsname.$poolname || return $?
4211 destroy_pool_int $fsname.$poolname
4213 [[ $RC -ne 0 ]] && return $RC
4215 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4216 2>/dev/null || echo foo" "foo" || RC=1
4218 if [[ $RC -eq 0 ]]; then
4219 remove_pool_from_list $fsname.$poolname
4221 error "destroy pool failed $1"
4227 local fsname=${1:-$FSNAME}
4229 local listvar=${fsname}_CREATED_POOLS
4233 [ x${!listvar} = x ] && return 0
4235 echo destroy the created pools: ${!listvar}
4236 for poolname in ${!listvar//,/ }; do
4237 destroy_pool $fsname.$poolname
4242 local fsname=${1:-$FSNAME}
4244 destroy_pools $fsname
4251 local ts=$(date +%s)
4253 [ -f $LOGDIR/shared ] && docp=false
4255 # dump lustre logs, dmesg
4257 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
4259 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4261 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4262 echo "Dumping logs only on local client."
4263 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4264 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4269 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4270 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4271 if [ ! -f $LOGDIR/shared ]; then
4272 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4275 if [ $tar_logs == 1 ]; then
4276 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
4277 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
4284 local list=${1:-$(comma_list $(nodes_list))}
4286 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
4298 for i in $(seq 0 $num_mntpts); do
4299 cmd="ls -laf ${mntpt_root}$i/$dir"
4305 for pid in $pids; do
4312 # target_start_and_reset_recovery_timer()
4313 # service_time = at_est2timeout(service_time);
4314 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4315 # INITIAL_CONNECT_TIMEOUT);
4316 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4317 #define CONNECTION_SWITCH_INC 1
4318 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4319 #define CONNECTION_SWITCH_MIN 5U
4321 max_recovery_time () {
4322 local init_connect_timeout=$(( TIMEOUT / 20 ))
4323 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4325 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4330 get_clients_mount_count () {
4331 local clients=${CLIENTS:-`hostname`}
4333 # we need to take into account the clients mounts and
4334 # exclude mds/ost mounts if any;
4335 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4339 PROC_CLI="srpc_info"
4347 if [ $M -lt $N ]; then
4351 while [ $N -lt $M ]; do
4361 calc_connection_cnt() {
4364 # MDT->MDT = 2 * C(M, 2)
4368 comb_m2=$(combination $MDSCOUNT 2)
4370 local num_clients=$(get_clients_mount_count)
4372 local cnt_mdt2mdt=$((comb_m2 * 2))
4373 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4374 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4375 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4376 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4377 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4378 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4392 local cmd="$tgt.srpc.flavor"
4394 if [ $net == "any" ]; then
4399 if [ $dir != "any" ]; then
4404 log "Setting sptlrpc rule: $cmd"
4405 do_facet mgs "$LCTL conf_param $cmd"
4414 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4415 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4417 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4419 if [ "x$bulkspec" != "x" ]; then
4420 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4422 if [ "x$algs" != "x" ]; then
4423 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4425 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4426 if [ $bulk == "bulkn" ]; then
4427 bulk_count=`echo "$output" | grep "bulk flavor" \
4428 | grep "null/null" | wc -l`
4429 elif [ $bulk == "bulki" ]; then
4430 bulk_count=`echo "$output" | grep "bulk flavor" \
4431 | grep "/null" | grep -v "null/" | wc -l`
4433 bulk_count=`echo "$output" | grep "bulk flavor" \
4434 | grep -v "/null" | grep -v "null/" | wc -l`
4438 [ $bulk_count -lt $count ] && count=$bulk_count
4449 local clients=${CLIENTS:-`hostname`}
4451 for c in ${clients//,/ }; do
4452 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4453 tmpcnt=`count_flvr "$output" $flavor`
4454 cnt=$((cnt + tmpcnt))
4464 local clients=${CLIENTS:-`hostname`}
4466 for c in ${clients//,/ }; do
4467 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4468 tmpcnt=`count_flvr "$output" $flavor`
4469 cnt=$((cnt + tmpcnt))
4479 if [ $MDSCOUNT -le 1 ]; then
4484 for num in `seq $MDSCOUNT`; do
4485 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4486 tmpcnt=`count_flvr "$output" $flavor`
4487 cnt=$((cnt + tmpcnt))
4498 for num in `seq $MDSCOUNT`; do
4499 mdtosc=$(get_mdtosc_proc_path mds$num)
4500 mdtosc=${mdtosc/-MDT*/-MDT\*}
4501 output=$(do_facet mds$num lctl get_param -n \
4502 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4503 tmpcnt=`count_flvr "$output" $flavor`
4504 cnt=$((cnt + tmpcnt))
4513 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4514 count_flvr "$output" $flavor
4519 local dir=$1 # from to
4520 local flavor=$2 # flavor expected
4523 if [ $dir == "cli2mdt" ]; then
4524 res=`flvr_cnt_cli2mdt $flavor`
4525 elif [ $dir == "cli2ost" ]; then
4526 res=`flvr_cnt_cli2ost $flavor`
4527 elif [ $dir == "mdt2mdt" ]; then
4528 res=`flvr_cnt_mdt2mdt $flavor`
4529 elif [ $dir == "mdt2ost" ]; then
4530 res=`flvr_cnt_mdt2ost $flavor`
4531 elif [ $dir == "all2ost" ]; then
4532 res1=`flvr_cnt_mdt2ost $flavor`
4533 res2=`flvr_cnt_cli2ost $flavor`
4534 res=$((res1 + res2))
4535 elif [ $dir == "all2mdt" ]; then
4536 res1=`flvr_cnt_mdt2mdt $flavor`
4537 res2=`flvr_cnt_cli2mdt $flavor`
4538 res=$((res1 + res2))
4539 elif [ $dir == "all2all" ]; then
4540 res1=`flvr_cnt_mdt2ost $flavor`
4541 res2=`flvr_cnt_cli2ost $flavor`
4542 res3=`flvr_cnt_mdt2mdt $flavor`
4543 res4=`flvr_cnt_cli2mdt $flavor`
4544 res=$((res1 + res2 + res3 + res4))
4552 local dir=$1 # from to
4553 local flavor=$2 # flavor expected
4554 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4558 for ((i=0;i<20;i++)); do
4559 echo -n "checking $dir..."
4560 res=$(do_check_flavor $dir $flavor)
4561 echo "found $res/$expect $flavor connections"
4562 [ $res -ge $expect ] && return 0
4566 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4570 restore_to_default_flavor()
4572 local proc="mgs.MGS.live.$FSNAME"
4574 echo "restoring to default flavor..."
4576 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4578 # remove all existing rules if any
4579 if [ $nrule -ne 0 ]; then
4580 echo "$nrule existing rules"
4581 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4582 echo "remove rule: $rule"
4583 spec=`echo $rule | awk -F = '{print $1}'`
4584 do_facet mgs "$LCTL conf_param -d $spec"
4588 # verify no rules left
4589 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4590 [ $nrule -ne 0 ] && error "still $nrule rules left"
4592 # wait for default flavor to be applied
4593 # currently default flavor for all connections are 'null'
4594 wait_flavor all2all null
4595 echo "now at default flavor settings"
4600 local flavor=${1:-null}
4602 echo "setting all flavor to $flavor"
4604 # FIXME need parameter to this fn
4605 # and remove global vars
4606 local cnt_all2all=$(calc_connection_cnt all2all)
4608 local res=$(do_check_flavor all2all $flavor)
4609 if [ $res -eq $cnt_all2all ]; then
4610 echo "already have total $res $flavor connections"
4614 echo "found $res $flavor out of total $cnt_all2all connections"
4615 restore_to_default_flavor
4617 [[ $flavor = null ]] && return 0
4619 set_rule $FSNAME any any $flavor
4620 wait_flavor all2all $flavor
4626 # Checking for shared logdir
4627 if [ ! -d $dir ]; then
4628 # Not found. Create local logdir
4631 touch $dir/node.$(hostname -s).yml
4636 check_write_access() {
4638 for node in $(nodes_list); do
4639 if [ ! -f "$dir/node.$(short_hostname ${node}).yml" ]; then
4640 # Logdir not accessible/writable from this node.
4644 rm -f $dir/node.*.yml
4649 if [[ -n $YAML_LOG ]]; then
4652 local SAVE_UMASK=`umask`
4655 export YAML_LOG=${LOGDIR}/results.yml
4659 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
4660 if check_shared_dir $LOGDIR; then
4661 touch $LOGDIR/shared
4662 echo "Logging to shared log directory: $LOGDIR"
4664 echo "Logging to local directory: $LOGDIR"
4667 yml_nodes_file $LOGDIR >> $YAML_LOG
4668 yml_results_file >> $YAML_LOG
4675 yml_log_test $1 >> $YAML_LOG
4679 yml_log_test_status $@ >> $YAML_LOG
4682 log_sub_test_begin() {
4683 yml_log_sub_test_begin "$@" >> $YAML_LOG
4686 log_sub_test_end() {
4687 yml_log_sub_test_end "$@" >> $YAML_LOG
4693 local llverdev_opts=$2
4694 local devname=$(basename $1)
4695 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4696 # loop devices aren't in /proc/partitions
4697 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4699 size=$(($size / 1024 / 1024)) # Gb
4701 local partial_arg=""
4702 # Run in partial (fast) mode if the size
4703 # of a partition > 1 GB
4704 [ $size -gt 1 ] && partial_arg="-p"
4706 llverdev --force $partial_arg $llverdev_opts $dev
4712 local llverfs_opts=$2
4713 local partial_arg=""
4714 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4716 # Run in partial (fast) mode if the size
4717 # of a partition > 1 GB
4718 [ $size -gt 1 ] && partial_arg="-p"
4720 llverfs $partial_arg $llverfs_opts $dir
4723 remove_mdt_files() {
4728 local mntpt=$(facet_mntpt $facet)
4730 echo "removing files from $mdtdev on $facet: $files"
4731 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4734 rm $mntpt/ROOT/$f || { rc=$?; break; }
4736 umount -f $mntpt || return $?
4740 duplicate_mdt_files() {
4745 local mntpt=$(facet_mntpt $facet)
4747 echo "duplicating files on $mdtdev on $facet: $files"
4748 mkdir -p $mntpt || return $?
4749 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4759 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4760 pushd $mntpt/ROOT > /dev/null || return $?
4763 touch $f.bad || return $?
4764 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4766 [ $rc -eq 0 ] || return $rc
4767 setfattr --restore $tmp || return $?
4773 local devs=${1//,/ }
4776 local rslt=$TMP/sgpdd_survey
4778 # sgpdd-survey cleanups ${rslt}.* files
4780 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4786 # returns the canonical name for an ldiskfs device
4791 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4792 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4793 echo dm-\\\${foo##*:};
4795 echo \\\$(basename \\\$dv);
4799 is_sanity_benchmark() {
4800 local benchmarks="dbench bonnie iozone fsx"
4802 for b in $benchmarks; do
4803 if [ "$b" == "$suite" ]; then
4811 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4814 # Get the block size of the filesystem.
4820 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4821 awk '/^Block size:/ {print $3}')
4825 # Check whether the "large_xattr" feature is enabled or not.
4826 large_xattr_enabled() {
4827 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4829 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4830 return ${PIPESTATUS[0]}
4833 # Get the maximum xattr size supported by the filesystem.
4837 if large_xattr_enabled; then
4838 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4841 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4842 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4844 # maximum xattr size = size of block - size of header -
4845 # size of 1 entry - 4 null bytes
4846 size=$((block_size - 32 - 32 - 4))
4852 # Dump the value of the named xattr from a file.
4857 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4860 # Generate a string with size of $size bytes.
4862 local size=${1:-1024} # in bytes
4864 echo "$(head -c $size < /dev/zero | tr '\0' y)"