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:-""}
12 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
13 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
20 #export PDSH="pdsh -S -Rssh -w"
22 # function used by scripts run on remote nodes
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/functions.sh
25 . $LUSTRE/tests/yaml.sh
27 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
29 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
31 if [ -f "$EXCEPT_LIST_FILE" ]; then
32 echo "Reading test skip list from $EXCEPT_LIST_FILE"
37 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
38 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] && MODPROBECONF=/etc/modprobe.d/Lustre
42 [[ $DIR/ = $MOUNT/* ]] || \
43 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
44 [[ $DIR1/ = $MOUNT1/* ]] || \
45 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
46 [[ $DIR2/ = $MOUNT2/* ]] || \
47 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
49 [ -n "$failed" ] && exit 99 || true
53 echo "usage: $0 [-r] [-f cfgfile]"
61 [ "$TESTSUITE" == "lfsck" ] && return 0
62 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
63 local form="%-13s %-17s %s\n"
64 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
65 echo "------------------------------------------------------------------------------------"
66 for O in $DEFAULT_SUITES; do
69 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
70 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
72 local log=${TMP}/${o}.log
73 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
74 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
75 [ "${!O}" = "done" ] && \
76 printf "$form" "Done" "$O" "E=$skipped" && \
77 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
81 for O in $DEFAULT_SUITES; do
82 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
83 if [ "${!O}" = "no" ]; then
85 # only for those tests suits which are run directly from acc-sm script:
86 # bonnie, iozone, etc.
87 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
88 printf "$form" "UNFINISHED" "$O" ""
90 printf "$form" "Skipped" "$O" ""
95 for O in $DEFAULT_SUITES; do
96 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
97 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
98 printf "$form" "UNFINISHED" "$O" ""
103 export LUSTRE=`absolute_path $LUSTRE`
104 export TESTSUITE=`basename $0 .sh`
105 export TEST_FAILED=false
106 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
108 export MKE2FS=${MKE2FS:-mke2fs}
109 export DEBUGFS=${DEBUGFS:-debugfs}
110 export TUNE2FS=${TUNE2FS:-tune2fs}
111 export E2LABEL=${E2LABEL:-e2label}
112 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
113 export E2FSCK=${E2FSCK:-e2fsck}
114 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
115 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check filesystem after each test suit
116 export SKIP_LFSCK=${SKIP_LFSCK:-"yes"} # bug 13698, change to "no" when fixed
117 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-"/tmp"}
118 export FSCK_MAX_ERR=4 # File system errors left uncorrected
119 if [ "$SKIP_LFSCK" == "no" ]; then
120 if [ ! -x `which $LFSCK_BIN` ]; then
122 error_exit "$E2FSCK does not support lfsck"
125 export MDSDB=${MDSDB:-$SHARED_DIRECTORY/mdsdb}
126 export OSTDB=${OSTDB:-$SHARED_DIRECTORY/ostdb}
127 export MDSDB_OPT="--mdsdb $MDSDB"
128 export OSTDB_OPT="--ostdb $OSTDB-\$ostidx"
130 #[ -d /r ] && export ROOT=${ROOT:-/r}
131 export TMP=${TMP:-$ROOT/tmp}
132 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
133 if [[ -z $LOGDIRSET ]]; then
134 export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
135 export LOGDIRSET=true
137 export HOSTNAME=${HOSTNAME:-`hostname`}
138 if ! echo $PATH | grep -q $LUSTRE/utils; then
139 export PATH=$PATH:$LUSTRE/utils
141 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
142 export PATH=$PATH:$LUSTRE/utils/gss
144 if ! echo $PATH | grep -q $LUSTRE/tests; then
145 export PATH=$PATH:$LUSTRE/tests
147 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
148 [ ! -f "$LST" ] && export LST=$(which lst)
149 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
150 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
151 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
152 export PATH=$LUSTRE/tests/racer:$PATH:
154 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
155 export PATH=$PATH:$LUSTRE/tests/mpi
157 export RSYNC_RSH=${RSYNC_RSH:-rsh}
158 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
159 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
160 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
161 [ ! -f "$LFS" ] && export LFS=$(which lfs)
162 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
163 if [ ! -f "$L_GETIDENTITY" ]; then
164 if `which l_getidentity > /dev/null 2>&1`; then
165 export L_GETIDENTITY=$(which l_getidentity)
167 export L_GETIDENTITY=NONE
170 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
171 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
172 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
173 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
174 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
175 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
176 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
177 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
178 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
179 export FSTYPE=${FSTYPE:-"ldiskfs"}
180 export NAME=${NAME:-local}
181 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
182 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
183 export LGSSD=$(which lgssd)
184 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
185 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
186 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
188 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
191 if [ "$ACCEPTOR_PORT" ]; then
192 export PORT_OPT="--port $ACCEPTOR_PORT"
197 echo "Using GSS/krb5 ptlrpc security flavor"
198 which lgss_keyring > /dev/null 2>&1 || \
199 error_exit "built with gss disabled! SEC=$SEC"
210 IDENTITY_UPCALL=false
213 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
215 # Paths on remote nodes, if different
216 export RLUSTRE=${RLUSTRE:-$LUSTRE}
217 export RPWD=${RPWD:-$PWD}
218 export I_MOUNTED=${I_MOUNTED:-"no"}
219 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
220 ! -f `dirname $0`/../mds/mds.ko ]; then
221 export CLIENTMODSONLY=yes
226 while getopts "rvwf:" opt $*; do
229 r) REFORMAT=--reformat;;
231 w) WRITECONF=writeconf;;
236 shift $((OPTIND - 1))
239 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
244 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
245 *) EXT=".ko"; USE_QUOTA=yes;;
250 /sbin/lsmod | grep -q $1
253 # Load a module on the system where this is running.
255 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
257 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
258 # will be used as the arguments. Otherwise arguments will be obtained from
259 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
266 BASE=`basename $module $EXT`
268 module_loaded ${BASE} && return
270 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
272 if [ $# -eq 0 ]; then
273 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
274 # Bash until 4.x, so we resort to eval.
275 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
276 eval set -- \$$optvar
277 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
278 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
279 set -- $(grep "^options\\s*\<${module}\>" $MODPROBECONF)
280 # Get rid of "options $module"
281 (($# > 0)) && shift 2
283 # Ensure we have accept=all for lnet
284 if [ $(basename $module) = lnet ]; then
285 # OK, this is a bit wordy...
286 local arg accept_all_present=false
288 [ "$arg" = accept=all ] && accept_all_present=true
290 $accept_all_present || set -- "$@" accept=all
295 [ $# -gt 0 ] && echo "${module} options: '$*'"
297 # Note that insmod will ignore anything in modprobe.conf, which is why we're
298 # passing options on the command-line.
299 if [ "$BASE" == "lnet_selftest" ] && \
300 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
301 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
302 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
303 insmod ${LUSTRE}/${module}${EXT} "$@"
305 # must be testing a "make install" or "rpm" installation
306 # note failed to load ptlrpc_gss is considered not fatal
307 if [ "$BASE" == "ptlrpc_gss" ]; then
308 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
315 load_modules_local() {
316 if [ -n "$MODPROBE" ]; then
318 echo "Using modprobe to load modules"
322 echo Loading modules from $LUSTRE
323 load_module ../libcfs/libcfs/libcfs
324 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
325 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
326 load_module ../lnet/lnet/lnet
327 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
328 load_module ../lnet/klnds/$LNETLND
329 load_module lvfs/lvfs
330 load_module obdclass/obdclass
331 load_module ptlrpc/ptlrpc
332 load_module ptlrpc/gss/ptlrpc_gss
333 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota
341 if ! client_only; then
342 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
343 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
344 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
349 load_module lvfs/fsfilt_$FSTYPE
353 load_module obdfilter/obdfilter
356 load_module llite/lustre
357 load_module llite/llite_lloop
358 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
360 rm -f $OGDB/ogdb-$HOSTNAME
361 $LCTL modules > $OGDB/ogdb-$HOSTNAME
363 # 'mount' doesn't look in $PATH, just sbin
364 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
370 # load modules on remote nodes optionally
371 # lustre-tests have to be installed on these nodes
372 if $LOAD_MODULES_REMOTE ; then
373 local list=$(comma_list $(remote_nodes_list))
374 echo loading modules on $list
375 do_rpc_nodes $list load_modules
380 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
381 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
382 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
383 echo "$LEAK_LUSTRE" 1>&2
384 echo "$LEAK_PORTALS" 1>&2
385 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
386 echo "Memory leaks detected"
387 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
393 wait_exit_ST client # bug 12845
395 $LUSTRE_RMMOD $FSTYPE || return 2
397 if $LOAD_MODULES_REMOTE ; then
398 local list=$(comma_list $(remote_nodes_list))
399 if [ ! -z $list ]; then
400 echo unloading modules on $list
401 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
402 do_rpc_nodes $list check_mem_leak
406 check_mem_leak || return 254
408 echo "modules unloaded."
412 check_gss_daemon_nodes() {
416 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
417 if [ \\\"\\\$num\\\" -ne 1 ]; then
418 echo \\\$num instance of $dname;
423 check_gss_daemon_facet() {
427 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
428 if [ $num -ne 1 ]; then
429 echo "$num instance of $dname on $facet"
438 echo Stopping $@ on $list
439 do_nodes $list "killall -2 $@ 2>/dev/null || true"
442 # start gss daemons on all nodes, or
443 # "daemon" on "list" if set
444 start_gss_daemons() {
448 if [ "$list" ] && [ "$daemon" ] ; then
449 echo "Starting gss daemon on nodes: $list"
450 do_nodes $list "$daemon" || return 8
454 local list=$(comma_list $(mdts_nodes))
456 echo "Starting gss daemon on mds: $list"
457 do_nodes $list "$LSVCGSSD -v" || return 1
459 do_nodes $list "$LGSSD -v" || return 2
462 list=$(comma_list $(osts_nodes))
463 echo "Starting gss daemon on ost: $list"
464 do_nodes $list "$LSVCGSSD -v" || return 3
465 # starting on clients
467 local clients=${CLIENTS:-`hostname`}
469 echo "Starting $LGSSD on clients $clients "
470 do_nodes $clients "$LGSSD -v" || return 4
473 # wait daemons entering "stable" status
477 # check daemons are running
479 list=$(comma_list $(mdts_nodes) $(osts_nodes))
480 check_gss_daemon_nodes $list lsvcgssd || return 5
482 list=$(comma_list $(mdts_nodes))
483 check_gss_daemon_nodes $list lgssd || return 6
486 check_gss_daemon_nodes $clients lgssd || return 7
491 local list=$(comma_list $(mdts_nodes))
493 send_sigint $list lsvcgssd lgssd
495 list=$(comma_list $(osts_nodes))
496 send_sigint $list lsvcgssd
498 list=${CLIENTS:-`hostname`}
499 send_sigint $list lgssd
504 if ! module_loaded ptlrpc_gss; then
505 load_module ptlrpc/gss/ptlrpc_gss
506 module_loaded ptlrpc_gss ||
507 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
509 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
511 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
512 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
520 # maybe cleanup credential cache?
526 local device=`mdsdevname $num`
527 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
533 local device=`ostdevname $num`
534 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
542 local dev=$(facet_active $facet)_dev
543 local opt=${facet}_opt
544 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
545 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
547 if [ $RC -ne 0 ]; then
548 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
549 echo "Start of ${!dev} on ${facet} failed ${RC}"
551 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
552 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
553 lctl set_param debug_mb=${DEBUG_SIZE}; \
556 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
557 [ -z "$label" ] && echo no label for ${!dev} && exit 1
558 eval export ${facet}_svc=${label}
559 echo Started ${label}
564 # start facet device options
570 eval export ${facet}_dev=${device}
571 eval export ${facet}_opt=\"$@\"
573 local varname=${facet}failover_dev
574 if [ -n "${!varname}" ] ; then
575 eval export ${facet}failover_dev=${!varname}
577 eval export ${facet}failover_dev=$device
580 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
590 HOST=`facet_active_host $facet`
591 [ -z $HOST ] && echo stop: no host for $facet && return 0
593 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
594 if [ ${running} -ne 0 ]; then
595 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
596 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
599 # umount should block, but we should wait for unrelated obd's
600 # like the MGS or MGC to also stop.
601 wait_exit_ST ${facet}
604 # save quota version (both administrative and operational quotas)
605 # add an additional parameter if mountpoint is ever different from $MOUNT
606 quota_save_version() {
607 local fsname=${2:-$FSNAME}
609 local ver=$(tr -c -d "123" <<< $spec)
610 local type=$(tr -c -d "ug" <<< $spec)
612 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
614 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
616 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
618 local osts=$(get_facets OST)
619 for ost in ${osts//,/ }; do
621 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
625 # client could mount several lustre
627 local fsname=${1:-$FSNAME}
629 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
630 do_nodes $(comma_list $(osts_nodes)) \
631 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
635 restore_quota_type () {
636 local mntpt=${1:-$MOUNT}
637 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
638 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
641 quota_save_version $old_QUOTA_TYPE
647 # We need save the original quota_type params, and restore them after testing
649 # Suppose that quota type the same on mds and ost
650 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
651 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
652 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
653 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
654 export old_QUOTA_TYPE=$quota_type
655 quota_save_version $QUOTA_TYPE
657 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
658 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
661 local quota_usrs=$QUOTA_USERS
663 # get_filesystem_size
664 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
665 local blk_soft=$((disksz + 1024))
666 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
668 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
670 local i_hard=$((i_soft + i_soft / 20))
672 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
673 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
676 for usr in $quota_usrs; do
677 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
679 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
681 eval $cmd || error "$cmd FAILED!"
683 # display the quota status
684 echo "Quota settings for $usr : "
685 $LFS quota -v -u $usr $mntpt || true
693 # Only supply -o to mount if we have options
694 if [ -n "$MOUNTOPT" ]; then
695 OPTIONS="-o $MOUNTOPT"
697 local device=$MGSNID:/$FSNAME
698 if [ -z "$mnt" -o -z "$FSNAME" ]; then
699 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
703 echo "Starting client: $client: $OPTIONS $device $mnt"
704 do_node $client mkdir -p $mnt
705 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
707 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
708 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
709 lctl set_param debug_mb=${DEBUG_SIZE}"
722 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
723 if [ $running -ne 0 ]; then
724 echo "Stopping client $client $mnt (opts:$force)"
725 do_node $client lsof -t $mnt || need_kill=no
726 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
727 pids=$(do_node $client lsof -t $mnt | sort -u);
728 if [ -n $pids ]; then
729 do_node $client kill -9 $pids || true
733 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
734 if [ $busy -ne 0 ] ; then
735 echo "$mnt is still busy, wait one second" && sleep 1
736 do_node $client umount $force $mnt
741 # nodes is comma list
742 sanity_mount_check_nodes () {
748 # FIXME: assume that all cluster nodes run the same os
749 [ "$(uname)" = Linux ] || return 0
752 for mnt in $mnts ; do
753 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
754 mpts=\\\$(mount | grep -w -c $mnt);
755 if [ \\\$running -ne \\\$mpts ]; then
756 echo \\\$(hostname) env are INSANE!;
764 sanity_mount_check_servers () {
766 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
767 echo Checking servers environments
769 # FIXME: modify get_facets to display all facets wo params
770 local facets="$(get_facets OST),$(get_facets MDS),mgs"
774 for facet in ${facets//,/ }; do
775 node=$(facet_host ${facet})
776 mnt=${MOUNT%/*}/${facet}
777 sanity_mount_check_nodes $node $mnt ||
778 { error "server $node environments are insane!"; return 1; }
782 sanity_mount_check_clients () {
783 local clients=${1:-$CLIENTS}
784 local mntpt=${2:-$MOUNT}
785 local mntpt2=${3:-$MOUNT2}
787 [ -z $clients ] && clients=$(hostname)
788 echo Checking clients $clients environments
790 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
791 error "clients environments are insane!"
794 sanity_mount_check () {
795 sanity_mount_check_servers || return 1
796 sanity_mount_check_clients || return 2
799 # mount clients if not mouted
800 zconf_mount_clients() {
803 local OPTIONS=${3:-$MOUNTOPT}
805 # Only supply -o to mount if we have options
806 if [ "$OPTIONS" ]; then
807 OPTIONS="-o $OPTIONS"
809 local device=$MGSNID:/$FSNAME
810 if [ -z "$mnt" -o -z "$FSNAME" ]; then
811 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
815 echo "Starting client $clients: $OPTIONS $device $mnt"
818 running=\\\$(mount | grep -c $mnt' ');
820 if [ \\\$running -eq 0 ] ; then
822 mount -t lustre $OPTIONS $device $mnt;
825 exit \\\$rc" || return ${PIPESTATUS[0]}
827 echo "Started clients $clients: "
828 do_nodes $clients "mount | grep -w $mnt"
830 do_nodes $clients "lctl set_param debug=\\\"$PTLDEBUG\\\";
831 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
832 lctl set_param debug_mb=${DEBUG_SIZE};"
837 zconf_umount_clients() {
844 echo "Stopping clients: $clients $mnt (opts:$force)"
845 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
846 if [ \\\$running -ne 0 ] ; then
847 echo Stopping client \\\$(hostname) $mnt opts:$force;
848 lsof -t $mnt || need_kill=no;
849 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
850 pids=\\\$(lsof -t $mnt | sort -u);
851 if [ -n \\\"\\\$pids\\\" ]; then
855 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
856 if [ \\\$busy -ne 0 ] ; then
857 echo "$mnt is still busy, wait one second" && sleep 1;
863 shudown_node_hard () {
867 for i in $(seq $attempts) ; do
870 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
871 echo "waiting for $host to fail attempts=$attempts"
872 [ $i -lt $attempts ] || \
873 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
879 local mnt=${2:-$MOUNT}
882 if [ "$FAILURE_MODE" = HARD ]; then
883 shudown_node_hard $client
885 zconf_umount_clients $client $mnt -f
891 if [ "$FAILURE_MODE" = HARD ]; then
892 shudown_node_hard $(facet_active_host $facet)
893 elif [ "$FAILURE_MODE" = SOFT ]; then
907 if [ "$FAILURE_MODE" = HARD ]; then
908 $POWER_UP `facet_active_host $facet`
916 if [ "$FAILURE_MODE" = HARD ]; then
922 # recovery-scale functions
923 check_progs_installed () {
928 do_nodes $clients "PATH=:$PATH; status=true;
929 for prog in $progs; do
930 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
931 echo \\\$prog missing on \\\$(hostname);
939 echo __$(echo $1 | tr '-' 'X')
942 start_client_load() {
945 local var=$(client_var_name $client)_load
946 eval export ${var}=$load
948 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
949 BREAK_ON_ERROR=$BREAK_ON_ERROR \
950 END_RUN_FILE=$END_RUN_FILE \
951 LOAD_PID_FILE=$LOAD_PID_FILE \
952 TESTSUITELOG=$TESTSUITELOG \
954 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
955 log "Started client load: ${load} on $client"
960 start_client_loads () {
961 local -a clients=(${1//,/ })
962 local numloads=${#CLIENT_LOADS[@]}
965 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
966 testnum=$((nodenum % numloads))
967 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
969 # bug 22169: wait the background threads to start
973 # only for remote client
974 check_client_load () {
976 local var=$(client_var_name $client)_load
977 local TESTLOAD=run_${!var}.sh
979 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
981 # bug 18914: try to connect several times not only when
982 # check ps, but while check_catastrophe also
985 while [ $RC = 254 -a $tries -gt 0 ]; do
989 if ! check_catastrophe $client; then
991 if [ $RC -eq 254 ]; then
992 # FIXME: not sure how long we shuold sleep here
996 echo "check catastrophe failed: RC=$RC "
1000 # We can continue try to connect if RC=254
1001 # Just print the warning about this
1002 if [ $RC = 254 ]; then
1003 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1006 # see if the load is still on the client
1009 while [ $RC = 254 -a $tries -gt 0 ]; do
1013 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1018 if [ $RC = 254 ]; then
1019 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1020 # see if we can diagnose a bit why this is
1025 check_client_loads () {
1026 local clients=${1//,/ }
1030 for client in $clients; do
1031 check_client_load $client
1033 if [ "$rc" != 0 ]; then
1034 log "Client load failed on node $client, rc=$rc"
1040 restart_client_loads () {
1041 local clients=${1//,/ }
1042 local expectedfail=${2:-""}
1046 for client in $clients; do
1047 check_client_load $client
1049 if [ "$rc" != 0 -a "$expectedfail" ]; then
1050 local var=$(client_var_name $client)_load
1051 start_client_load $client ${!var}
1052 echo "Restarted client load ${!var}: on $client. Checking ..."
1053 check_client_load $client
1055 if [ "$rc" != 0 ]; then
1056 log "Client load failed to restart on node $client, rc=$rc"
1057 # failure one client load means test fail
1058 # we do not need to check other
1066 # End recovery-scale functions
1068 # verify that lustre actually cleaned up properly
1070 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1071 error "LBUG/LASSERT detected"
1072 BUSY=`dmesg | grep -i destruct || true`
1073 if [ "$BUSY" ]; then
1075 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1079 check_mem_leak || exit 204
1081 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1082 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1084 if module_loaded lnet || module_loaded libcfs; then
1085 echo "$0: modules still loaded..." 1>&2
1102 RESULT=$(do_node $node "$TEST")
1103 if [ "$RESULT" == "$FINAL" ]; then
1104 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1107 [ $WAIT -ge $MAX ] && break
1108 echo "Waiting $((MAX - WAIT)) secs for update"
1109 WAIT=$((WAIT + sleep))
1112 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1116 wait_update_facet () {
1118 wait_update $(facet_active_host $facet) "$@"
1121 wait_delete_completed () {
1122 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1123 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1127 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1129 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1130 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1131 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1132 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1136 echo "Delete is not completed in $MAX_WAIT sec"
1142 check_network "$host" 900
1143 while ! do_node $host hostname > /dev/null; do sleep 5; done
1148 local host=`facet_active_host $facet`
1152 wait_recovery_complete () {
1155 # Use default policy if $2 is not passed by caller.
1156 local MAX=${2:-$(max_recovery_time)}
1158 local var_svc=${facet}_svc
1159 local procfile="*.${!var_svc}.recovery_status"
1163 while [ $WAIT -lt $MAX ]; do
1164 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
1165 [[ $STATUS = "status: COMPLETE" ]] && return 0
1168 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
1170 echo "$facet recovery not done in $MAX sec. $STATUS"
1174 wait_mds_ost_sync () {
1175 # just because recovery is done doesn't mean we've finished
1176 # orphan cleanup. Wait for llogs to get synchronized.
1177 echo "Waiting for orphan cleanup..."
1178 # MAX value includes time needed for MDS-OST reconnection
1179 local MAX=$(( TIMEOUT * 2 ))
1181 while [ $WAIT -lt $MAX ]; do
1182 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1183 "$LCTL get_param -n obdfilter.*.mds_sync"))
1185 for ((i=0; i<${#sync[@]}; i++)); do
1186 [ ${sync[$i]} -eq 0 ] && continue
1187 # there is a not finished MDS-OST synchronization
1191 sleep 2 # increase waiting time and cover statfs cache
1192 [ ${con} -eq 1 ] && return 0
1193 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1196 echo "$facet recovery not done in $MAX sec. $STATUS"
1200 wait_destroy_complete () {
1201 echo "Waiting for destroy to be done..."
1202 # MAX value shouldn't be big as this mean server responsiveness
1203 # never increase this just to make test pass but investigate
1204 # why it takes so long time
1207 while [ $WAIT -lt $MAX ]; do
1208 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1210 for ((i=0; i<${#RPCs[@]}; i++)); do
1211 [ ${RPCs[$i]} -eq 0 ] && continue
1212 # there are still some destroy RPCs in flight
1217 [ ${con} -eq 1 ] && return 0 # done waiting
1218 echo "Waiting $WAIT secs for destroys to be done."
1221 echo "Destroys weren't done in $MAX sec."
1231 # conf-sanity 31 takes a long time cleanup
1232 while [ $WAIT -lt 300 ]; do
1233 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1234 [ -z "${running}" ] && return 0
1235 echo "waited $WAIT for${running}"
1236 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1238 WAIT=$((WAIT + INTERVAL))
1240 echo "service didn't stop after $WAIT seconds. Still running:"
1245 wait_remote_prog () {
1251 [ "$PDSH" = "no_dsh" ] && return 0
1253 while [ $WAIT -lt $2 ]; do
1254 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1255 [ -z "${running}" ] && return 0 || true
1256 echo "waited $WAIT for: "
1258 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1260 WAIT=$((WAIT + INTERVAL))
1262 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1263 [ -z "$pids" ] && return 0
1264 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1265 # FIXME: not portable
1266 for pid in $pids; do
1267 cat /proc/${pid}/status || true
1268 cat /proc/${pid}/wchan || true
1270 kill -9 $pid || true
1279 # not every config has many clients
1281 if [ ! -z "$CLIENTS" ]; then
1282 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1284 stat -f $MOUNT > /dev/null
1290 # usually checked on particular client or locally
1292 if [ ! -z "$client" ]; then
1293 $PDSH $client "stat -f $MOUNT" > /dev/null
1295 stat -f $MOUNT > /dev/null
1303 client_reconnect() {
1304 uname -n >> $MOUNT/recon
1305 if [ -z "$CLIENTS" ]; then
1306 df $MOUNT; uname -n >> $MOUNT/recon
1308 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1310 echo Connected clients:
1312 ls -l $MOUNT/recon > /dev/null
1319 echo "Failing $facet on node `facet_active_host $facet`"
1320 shutdown_facet $facet
1321 [ -n "$sleep_time" ] && sleep $sleep_time
1323 change_active $facet
1324 local TO=`facet_active_host $facet`
1325 echo "Failover $facet to $TO"
1327 mount_facet $facet || error "Restart of $facet failed"
1336 do_facet $facet sync
1338 local svc=${facet}_svc
1339 do_facet $facet $LCTL --device %${!svc} notransno
1340 do_facet $facet $LCTL --device %${!svc} readonly
1341 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1342 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1345 replay_barrier_nodf() {
1346 local facet=$1 echo running=${running}
1347 do_facet $facet sync
1348 local svc=${facet}_svc
1349 echo Replay barrier on ${!svc}
1350 do_facet $facet $LCTL --device %${!svc} notransno
1351 do_facet $facet $LCTL --device %${!svc} readonly
1352 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1353 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1356 replay_barrier_nosync() {
1357 local facet=$1 echo running=${running}
1358 local svc=${facet}_svc
1359 echo Replay barrier on ${!svc}
1360 do_facet $facet $LCTL --device %${!svc} notransno
1361 do_facet $facet $LCTL --device %${!svc} readonly
1362 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1363 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1366 mds_evict_client() {
1367 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1368 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1371 ost_evict_client() {
1372 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1373 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1377 facet_failover $* || error "failover: $?"
1378 clients_up || error "post-failover df: $?"
1383 facet_failover $facet
1389 change_active $facet
1390 mount_facet $facet -o abort_recovery
1391 clients_up || echo "first df failed: $?"
1392 clients_up || error "post-failover df: $?"
1396 echo There is no lmc. This is mountconf, baby.
1401 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1402 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1408 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1414 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1415 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1416 if [ -z "$ID" ]; then
1417 echo "Could not get a ptl id for $1..."
1426 h2name_or_ip "$1" "tcp"
1431 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1432 if type __h2elan >/dev/null 2>&1; then
1435 ID=`echo $1 | sed 's/[^0-9]*//g'`
1443 h2name_or_ip "$1" "openib"
1445 declare -fx h2openib
1448 h2name_or_ip "$1" "o2ib"
1455 [ "$facet" == client ] && echo -n $HOSTNAME && return
1456 varname=${facet}_HOST
1457 if [ -z "${!varname}" ]; then
1458 if [ "${facet:0:3}" == "ost" ]; then
1459 eval ${facet}_HOST=${ost_HOST}
1467 local activevar=${facet}active
1469 if [ -f $TMP/${facet}active ] ; then
1470 source $TMP/${facet}active
1473 active=${!activevar}
1474 if [ -z "$active" ] ; then
1481 facet_active_host() {
1483 local active=`facet_active $facet`
1484 if [ "$facet" == client ]; then
1487 echo `facet_host $active`
1493 local failover=${facet}failover
1494 host=`facet_host $failover`
1495 [ -z "$host" ] && return
1496 local curactive=`facet_active $facet`
1497 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1498 eval export ${facet}active=$facet
1500 eval export ${facet}active=$failover
1502 # save the active host for this facet
1503 local activevar=${facet}active
1504 echo "$activevar=${!activevar}" > $TMP/$activevar
1509 # do not stripe off hostname if verbose, bug 19215
1510 if [ x$1 = x--verbose ]; then
1518 if [ "$HOST" = "$HOSTNAME" ]; then
1520 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1521 echo "cannot run remote command on $HOST with $myPDSH"
1525 echo "CMD: $HOST $@" >&2
1526 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1529 if [ "$myPDSH" = "rsh" ]; then
1530 # we need this because rsh does not return exit code of an executed command
1531 local command_status="$TMP/cs"
1532 rsh $HOST ":> $command_status"
1533 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1534 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1535 echo command failed >$command_status"
1536 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1541 # print HOSTNAME for myPDSH="no_dsh"
1542 if [[ $myPDSH = no_dsh ]]; then
1543 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1545 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1548 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1550 return ${PIPESTATUS[0]}
1554 do_node --verbose "$@"
1557 single_local_node () {
1558 [ "$1" = "$HOSTNAME" ]
1561 # Outputs environment variable assignments that should be passed to remote nodes
1566 for var in ${!MODOPTS_*}; do
1568 echo "${var}=\"$value\""
1574 # do not stripe off hostname if verbose, bug 19215
1575 if [ x$1 = x--verbose ]; then
1583 if single_local_node $rnodes; then
1585 do_nodev $rnodes "$@"
1587 do_node $rnodes "$@"
1592 # This is part from do_node
1595 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1596 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1599 echo "CMD: $rnodes $@" >&2
1600 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1604 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1606 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/\w+:\s//g"
1608 return ${PIPESTATUS[0]}
1614 local HOST=`facet_active_host $facet`
1615 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1620 do_nodes --verbose "$@"
1626 # make sure its not already running
1628 rm -f $TMP/${facet}active
1629 do_facet ${facet} $MKFS $*
1635 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1636 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1643 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1644 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1652 # make sure we are using the primary server, so test-framework will
1653 # be able to clean up properly.
1654 activemds=`facet_active mds1`
1655 if [ $activemds != "mds1" ]; then
1659 local clients=$CLIENTS
1660 [ -z $clients ] && clients=$(hostname)
1662 zconf_umount_clients $clients $MOUNT "$*" || true
1663 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1665 [ "$CLIENTONLY" ] && return
1666 # The add fn does rm ${facet}active file, this would be enough
1667 # if we use do_facet <facet> only after the facet added, but
1668 # currently we use do_facet mds in local.sh
1669 for num in `seq $MDSCOUNT`; do
1671 rm -f ${TMP}/mds${num}active
1674 for num in `seq $OSTCOUNT`; do
1676 rm -f $TMP/ost${num}active
1679 if ! combined_mgs_mds ; then
1687 nfs_client_mode && return
1697 test $nr = 1 && echo -n $MDS_MKFS_OPTS || echo -n $MDSn_MKFS_OPTS
1700 combined_mgs_mds () {
1701 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
1705 if [ "$IAMDIR" == "yes" ]; then
1706 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
1707 MDSn_MKFS_OPTS="$MDSn_MKFS_OPTS --iam-dir"
1710 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1713 # We need ldiskfs here, may as well load them all
1715 [ "$CLIENTONLY" ] && return
1716 echo Formatting mgs, mds, osts
1717 if ! combined_mgs_mds ; then
1718 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1721 for num in `seq $MDSCOUNT`; do
1722 echo "Format mds$num: $(mdsdevname $num)"
1724 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` || exit 9
1726 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` > /dev/null || exit 9
1730 for num in `seq $OSTCOUNT`; do
1731 echo "Format ost$num: $(ostdevname $num)"
1733 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` || exit 10
1735 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` > /dev/null || exit 10
1741 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1745 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
1749 # 0: success, the old identity set already.
1750 # 1: success, the old identity does not set.
1755 local j=`expr $num - 1`
1756 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
1758 if [ -z "$MDT" ]; then
1762 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
1765 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
1767 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
1770 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
1772 if [ $old = "NONE" ]; then
1781 zconf_umount `hostname` $1 || error "umount failed"
1782 zconf_mount `hostname` $1 || error "mount failed"
1785 writeconf_facet () {
1789 do_facet $facet "$TUNEFS --writeconf $dev"
1793 for num in `seq $MDSCOUNT`; do
1794 DEVNAME=$(mdsdevname $num)
1795 writeconf_facet mds$num $DEVNAME
1798 for num in `seq $OSTCOUNT`; do
1799 DEVNAME=$(ostdevname $num)
1800 writeconf_facet ost$num $DEVNAME
1805 nfs_client_mode && return
1807 sanity_mount_check ||
1808 error "environments are insane!"
1812 if [ -z "$CLIENTONLY" ]; then
1813 echo Setup mgs, mdt, osts
1814 echo $WRITECONF | grep -q "writeconf" && \
1816 if ! combined_mgs_mds ; then
1817 start mgs $MGSDEV $mgs_MOUNT_OPTS
1820 for num in `seq $MDSCOUNT`; do
1821 DEVNAME=$(mdsdevname $num)
1822 start mds$num $DEVNAME $MDS_MOUNT_OPTS
1824 # We started mds, now we should set failover variables properly.
1825 # Set mds${num}failover_HOST if it is not set (the default failnode).
1826 local varname=mds${num}failover_HOST
1827 if [ -z "${!varname}" ]; then
1828 eval mds${num}failover_HOST=$(facet_host mds$num)
1831 if [ $IDENTITY_UPCALL != "default" ]; then
1832 switch_identity $num $IDENTITY_UPCALL
1835 for num in `seq $OSTCOUNT`; do
1836 DEVNAME=$(ostdevname $num)
1837 start ost$num $DEVNAME $OST_MOUNT_OPTS
1839 # We started ost$num, now we should set ost${num}failover variable properly.
1840 # Set ost${num}failover_HOST if it is not set (the default failnode).
1841 varname=ost${num}failover_HOST
1842 if [ -z "${!varname}" ]; then
1843 eval ost${num}failover_HOST=$(facet_host ost${num})
1851 # wait a while to allow sptlrpc configuration be propogated to targets,
1852 # only needed when mounting new target devices.
1857 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1859 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1861 if [ "$MOUNT_2" ]; then
1862 mount_client $MOUNT2
1863 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1868 # by remounting mdt before ost, initial connect from mdt to ost might
1869 # timeout because ost is not ready yet. wait some time to its fully
1870 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
1871 # by a context negotiation rpc with $TIMEOUT.
1872 # FIXME better by monitoring import status.
1875 sleep $((TIMEOUT + 5))
1881 mounted_lustre_filesystems() {
1882 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1885 init_facet_vars () {
1886 [ "$CLIENTONLY" ] && return 0
1893 eval export ${facet}_dev=${device}
1894 eval export ${facet}_opt=\"$@\"
1896 local dev=${facet}_dev
1897 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1898 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1900 eval export ${facet}_svc=${label}
1902 local varname=${facet}failover_HOST
1903 if [ -z "${!varname}" ]; then
1904 eval $varname=$(facet_host $facet)
1907 # ${facet}failover_dev is set in cfg file
1908 varname=${facet}failover_dev
1909 if [ -n "${!varname}" ] ; then
1910 eval export ${facet}failover_dev=${!varname}
1912 eval export ${facet}failover_dev=$device
1916 init_facets_vars () {
1919 if ! remote_mds_nodsh; then
1920 for num in `seq $MDSCOUNT`; do
1921 DEVNAME=`mdsdevname $num`
1922 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
1926 remote_ost_nodsh && return
1928 for num in `seq $OSTCOUNT`; do
1929 DEVNAME=`ostdevname $num`
1930 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1934 osc_ensure_active () {
1940 while [ $period -lt $timeout ]; do
1941 count=$(do_facet $facet "lctl dl | grep '${FSNAME}-OST.*-osc-${type}' | grep ' IN ' 2>/dev/null | wc -l")
1942 if [ $count -eq 0 ]; then
1946 echo "There are $count OST are inactive, wait $period seconds, and try again"
1948 period=$((period+3))
1951 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
1954 init_param_vars () {
1955 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1956 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
1957 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1958 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1962 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
1964 log "Using TIMEOUT=$TIMEOUT"
1966 osc_ensure_active $SINGLEMDS M $TIMEOUT
1967 osc_ensure_active client c $TIMEOUT
1969 if [ $QUOTA_AUTO -ne 0 ]; then
1970 if [ "$ENABLE_QUOTA" ]; then
1971 echo "enable quota as required"
1972 setup_quota $MOUNT || return 2
1974 echo "disable quota as required"
1975 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
1982 nfs_client_mode () {
1983 if [ "$NFSCLIENT" ]; then
1984 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1985 local clients=$CLIENTS
1986 [ -z $clients ] && clients=$(hostname)
1988 # FIXME: remove hostname when 19215 fixed
1989 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1990 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1991 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1997 check_config_client () {
2000 local mounted=$(mount | grep " $mntpt ")
2001 if [ "$CLIENTONLY" ]; then
2003 # CLIENTONLY should not depend on *_HOST settings
2004 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2005 # in theory someone could create a new,
2006 # client-only config file that assumed lustre was already
2007 # configured and didn't set the MGSNID. If MGSNID is not set,
2008 # then we should use the mgs nid currently being used
2009 # as the default value. bug 18021
2010 [[ x$MGSNID = x ]] &&
2013 if [[ x$mgc != xMGC$MGSNID ]]; then
2014 if [ "$mgs_HOST" ]; then
2015 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2016 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2017 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2023 local myMGS_host=$mgs_HOST
2024 if [ "$NETTYPE" = "ptl" ]; then
2025 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2028 echo Checking config lustre mounted on $mntpt
2029 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2030 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2032 # if [ "$mgshost" != "$myMGS_host" ]; then
2033 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2034 # Please use correct config or set mds_HOST correctly!"
2039 check_config_clients () {
2040 local clients=${CLIENTS:-$HOSTNAME}
2043 nfs_client_mode && return
2045 do_rpc_nodes $clients check_config_client $mntpt
2047 sanity_mount_check ||
2048 error "environments are insane!"
2052 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2053 local cltimeout=$(lctl get_param -n timeout)
2054 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2055 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2062 [ -z $mntpt ] && return 1
2063 local mounted=$(mounted_lustre_filesystems)
2065 echo $mounted' ' | grep -w -q $mntpt' '
2069 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2073 # empty lustre filesystem may have empty directories lost+found and .lustre
2075 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2076 -print | wc -l) = 1 ] || return 1
2077 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2078 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2082 check_and_setup_lustre() {
2083 nfs_client_mode && return
2085 local MOUNTED=$(mounted_lustre_filesystems)
2089 # both MOUNT and MOUNT2 are not mounted
2090 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2091 [ "$REFORMAT" ] && formatall
2092 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2094 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2095 export I_MOUNTED=yes
2099 elif is_mounted $MOUNT2; then
2101 # MOUNT2 is mounted, while MOUNT_2 is not set
2102 if ! [ "$MOUNT_2" ]; then
2103 cleanup_mount $MOUNT2
2104 export I_UMOUNTED2=yes
2107 # MOUNT2 is mounted, MOUNT_2 is set
2109 # FIXME: what to do if check_config failed?
2111 # 1) remote client has mounted other Lustre fs ?
2112 # 2) it has insane env ?
2113 # let's try umount MOUNT2 on all clients and mount it again:
2114 if ! check_config_clients $MOUNT2; then
2115 cleanup_mount $MOUNT2
2116 restore_mount $MOUNT2
2117 export I_MOUNTED2=yes
2122 # MOUNT is mounted MOUNT2 is not mounted
2123 elif [ "$MOUNT_2" ]; then
2124 restore_mount $MOUNT2
2125 export I_MOUNTED2=yes
2129 # FIXME: what to do if check_config failed?
2131 # 1) remote client has mounted other Lustre fs?
2132 # 2) lustre is mounted on remote_clients atall ?
2133 check_config_clients $MOUNT
2137 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
2138 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
2139 lctl set_param debug_mb=${DEBUG_SIZE};
2146 if [ "$ONLY" == "setup" ]; then
2152 local clients=${CLIENTS:-$HOSTNAME}
2155 zconf_mount_clients $clients $mntpt
2159 local clients=${CLIENTS:-$HOSTNAME}
2162 zconf_umount_clients $clients $mntpt
2165 cleanup_and_setup_lustre() {
2166 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2167 lctl set_param debug=0 || true
2169 if [ "$ONLY" == "cleanup" ]; then
2173 check_and_setup_lustre
2176 # Get all of the server target devices from a given server node and type.
2185 mdt) obd_type="osd" ;;
2186 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2187 *) echo "invalid server type" && return 1 ;;
2190 devs=$(do_node $node "lctl get_param -n $obd_type.*.mntdev")
2191 for dev in $devs; do
2193 *loop*) do_node $node "losetup $dev" | \
2194 sed -e "s/.*(//" -e "s/).*//" ;;
2200 # Get all of the server target devices.
2205 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2209 for node in $(osts_nodes); do
2210 OSTDEVS[i]=$(get_mnt_devs $node ost)
2215 # Run e2fsck on MDT or OST device.
2222 df > /dev/null # update statfs data on disk
2223 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
2226 local rc=${PIPESTATUS[0]}
2227 [ $rc -le $FSCK_MAX_ERR ] || \
2228 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2232 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2239 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2240 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2241 error "fail to create file in $SHARED_DIRECTORY")
2243 # make sure everything gets to the backing store
2244 local list=$(comma_list $CLIENTS $(facet_host $SINGLEMDS) $(osts_nodes))
2245 do_nodes $list "sync; sleep 2; sync"
2247 do_nodes $list ls $tmp_file || \
2248 error "$SHARED_DIRECTORY is not a shared directory"
2251 run_e2fsck $(mdts_nodes) $MDTDEV
2256 for node in $(osts_nodes); do
2257 for dev in ${OSTDEVS[i]}; do
2258 local ostdb_opt=`eval echo $OSTDB_OPT`
2259 run_e2fsck $node $dev $ostidx "$ostdb_opt"
2260 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2261 ostidx=$((ostidx + 1))
2268 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2271 local rc=${PIPESTATUS[0]}
2272 [ $rc -le $FSCK_MAX_ERR ] || \
2273 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2274 echo "lfsck finished with rc=$rc"
2276 rm -rvf $MDSDB* $OSTDB* || true
2281 check_and_cleanup_lustre() {
2282 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2285 if [ "$SKIP_LFSCK" == "no" ]; then
2293 if is_mounted $MOUNT; then
2294 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2295 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2298 if [ "$I_UMOUNTED2" = "yes" ]; then
2299 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2302 if [ "$I_MOUNTED2" = "yes" ]; then
2303 cleanup_mount $MOUNT2
2306 if [ "$I_MOUNTED" = "yes" ]; then
2307 cleanupall -f || error "cleanup failed"
2319 while [ $NETWORK -eq 0 ]; do
2320 if ping -c 1 -w 3 $1 > /dev/null; then
2324 echo "waiting for $1, $((MAX - WAIT)) secs left"
2327 if [ $WAIT -gt $MAX ]; then
2328 echo "Network not available"
2334 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2345 # the sed converts spaces to commas, but leaves the last space
2346 # alone, so the line doesn't end with a comma.
2347 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2350 # list, excluded are the comma separated lists
2351 exclude_items_from_list () {
2357 for item in ${excluded//,/ }; do
2358 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2360 echo $(comma_list $list)
2363 # list, expand are the comma separated lists
2365 local list=${1//,/ }
2366 local expand=${2//,/ }
2369 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2370 echo $(comma_list $expanded)
2373 testslist_filter () {
2374 local script=$LUSTRE/tests/${TESTSUITE}.sh
2376 [ -f $script ] || return 0
2378 local start_at=$START_AT
2379 local stop_at=$STOP_AT
2381 local var=${TESTSUITE//-/_}_START_AT
2382 [ x"${!var}" != x ] && start_at=${!var}
2383 var=${TESTSUITE//-/_}_STOP_AT
2384 [ x"${!var}" != x ] && stop_at=${!var}
2386 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2387 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2388 /^'${start_at}'$/ {flag = 0}
2389 {if (flag == 1) print $0}
2390 /^'${stop_at}'$/ { flag = 1 }'
2394 (cd `dirname $1`; echo $PWD/`basename $1`)
2398 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
2399 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
2402 local count=${type}COUNT
2403 for ((i=1; i<=${!count}; i++)) do
2404 list="$list ${name}$i"
2406 echo $(comma_list $list)
2409 ##################################
2410 # Adaptive Timeouts funcs
2413 # only check mds, we assume at_max is the same on all nodes
2414 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2415 if [ $at_max -eq 0 ]; then
2425 # suppose that all ost-s has the same at_max set
2426 if [ $facet == "ost" ]; then
2427 do_facet ost1 "lctl get_param -n at_max"
2429 do_facet $facet "lctl get_param -n at_max"
2439 if [ $facet == "ost" ]; then
2440 for i in `seq $OSTCOUNT`; do
2441 do_facet ost$i "lctl set_param at_max=$at_max"
2444 elif [ $facet == "mds" ]; then
2445 for i in `seq $MDSCOUNT`; do
2446 do_facet mds$i "lctl set_param at_max=$at_max"
2449 do_facet $facet "lctl set_param at_max=$at_max"
2454 ##################################
2458 # OBD_FAIL_MDS_ALL_REQUEST_NET
2460 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2461 do_facet client "$1" || RC=$?
2462 do_facet $SINGLEMDS lctl set_param fail_loc=0
2467 # OBD_FAIL_MDS_ALL_REPLY_NET
2469 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2470 do_facet client "$@" || RC=$?
2471 do_facet $SINGLEMDS lctl set_param fail_loc=0
2475 drop_reint_reply() {
2476 # OBD_FAIL_MDS_REINT_NET_REP
2478 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2479 do_facet client "$@" || RC=$?
2480 do_facet $SINGLEMDS lctl set_param fail_loc=0
2485 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2487 do_facet ost1 lctl set_param fail_loc=0x214
2488 do_facet client "$1" || RC=$?
2489 do_facet client "sync"
2490 do_facet ost1 lctl set_param fail_loc=0
2494 drop_ldlm_cancel() {
2495 #define OBD_FAIL_LDLM_CANCEL 0x304
2497 do_facet client lctl set_param fail_loc=0x304
2498 do_facet client "$@" || RC=$?
2499 do_facet client lctl set_param fail_loc=0
2503 drop_bl_callback() {
2504 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2506 do_facet client lctl set_param fail_loc=0x305
2507 do_facet client "$@" || RC=$?
2508 do_facet client lctl set_param fail_loc=0
2513 #define OBD_FAIL_LDLM_REPLY 0x30c
2515 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2516 do_facet client "$@" || RC=$?
2517 do_facet $SINGLEMDS lctl set_param fail_loc=0
2525 echo "clearing fail_loc on $facet"
2526 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2529 set_nodes_failloc () {
2530 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2533 cancel_lru_locks() {
2534 $LCTL mark "cancel_lru_locks $1 start"
2535 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2536 $LCTL set_param -n $d=clear
2538 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2539 $LCTL mark "cancel_lru_locks $1 stop"
2544 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2545 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2546 echo "$DEFAULT_LRU_SIZE"
2551 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2554 lru_resize_disable()
2556 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2561 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2562 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2563 echo there is still data in page cache $FILE ?
2564 lctl get_param -n $FILE
2572 DEBUGSAVE="$(lctl get_param -n debug)"
2576 [ -n "$DEBUGSAVE" ] && \
2577 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
2582 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
2585 debug_size_restore() {
2586 [ -n "$DEBUG_SIZE_SAVED" ] && \
2587 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
2591 start_full_debug_logging() {
2596 local DEBUG_SIZE=150
2598 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
2599 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
2602 stop_full_debug_logging() {
2607 ##################################
2609 ##################################
2612 local TYPE=${TYPE:-"FAIL"}
2615 # do not dump logs if $1=false
2616 if [ "x$1" = "xfalse" ]; then
2621 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2623 # We need to dump the logs on all nodes
2625 gather_logs $(comma_list $(nodes_list))
2629 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2630 echo "$@" > $LOGDIR/err
2642 # use only if we are ignoring failures for this test, bugno required.
2643 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2644 # e.g. error_ignore 5494 "your message"
2646 local TYPE="IGNORE (bz$1)"
2652 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2657 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2658 [ "$TESTSUITELOG" ] && \
2659 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2662 build_test_filter() {
2663 EXCEPT="$EXCEPT $(testslist_filter)"
2665 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2669 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2670 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2671 [ "$EXCEPT_SLOW" ] && \
2672 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2673 for E in $EXCEPT $ALWAYS_EXCEPT; do
2674 eval EXCEPT_${E}=true
2676 for E in $EXCEPT_SLOW; do
2677 eval EXCEPT_SLOW_${E}=true
2679 for G in $GRANT_CHECK_LIST; do
2680 eval GCHECK_ONLY_${G}=true
2685 if [[ $1 = [a-z]* ]]; then
2692 # print a newline if the last test was skipped
2693 export LAST_SKIPPED=
2695 # Main entry into test-framework. This is called with the name and
2696 # description of a test. The name is used to find the function to run
2697 # the test using "test_$name".
2699 # This supports a variety of methods of specifying specific test to
2700 # run or not run. These need to be documented...
2705 export base=`basetest $1`
2706 if [ ! -z "$ONLY" ]; then
2708 if [ ${!testname}x != x ]; then
2709 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2710 run_one_logged $1 "$2"
2714 if [ ${!testname}x != x ]; then
2715 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2716 run_one_logged $1 "$2"
2724 if [ ${!testname}x != x ]; then
2726 TESTNAME=test_$1 skip "skipping excluded test $1"
2729 testname=EXCEPT_$base
2730 if [ ${!testname}x != x ]; then
2732 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2735 testname=EXCEPT_SLOW_$1
2736 if [ ${!testname}x != x ]; then
2738 TESTNAME=test_$1 skip "skipping SLOW test $1"
2741 testname=EXCEPT_SLOW_$base
2742 if [ ${!testname}x != x ]; then
2744 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2749 run_one_logged $1 "$2"
2760 module_loaded lnet || load_modules
2772 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2777 strace -o $TMP/$1.strace -ttt $*
2779 log "FINISHED: $*: rc $RC"
2784 # Set TEST_STATUS here; will be used for logging the result
2785 if [ -f $LOGDIR/err ]; then
2790 echo $TEST_STATUS " " $@
2794 FFREE=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filesfree | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2795 FTOTAL=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filestotal | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2796 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2800 echo -n "Resetting fail_loc on all nodes..."
2801 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2807 # Log a message (on all nodes) padded with "=" before and after.
2808 # Also appends a timestamp and prepends the testsuite name.
2811 EQUALS="===================================================================================================="
2813 msg="== ${TESTSUITE} $*"
2815 [[ $last != "=" && $last != " " ]] && msg="$msg "
2816 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
2817 # always include at least == after the message
2818 log "$msg== $(date +"%H:%M:%S (%s)")"
2822 # Run a single test function and cleanup after it.
2824 # This function should be run in a subshell so the test func can
2825 # exit() without stopping the whole script.
2831 export tdir=d0.${TESTSUITE}/d${base}
2832 export TESTNAME=test_$testnum
2833 local SAVE_UMASK=`umask`
2836 banner "test $testnum: $message"
2837 test_${testnum} || error "test_$testnum failed with $?"
2840 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2841 check_catastrophe || error "LBUG/LASSERT detected"
2842 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2850 # Wrapper around run_one to ensure:
2851 # - test runs in subshell
2852 # - output of test is saved to separate log file for error reporting
2853 # - test result is saved to data file
2856 local BEFORE=`date +%s`
2858 local name=${TESTSUITE}.test_${1}.test_log.$(hostname).log
2859 local test_log=$LOGDIR/$name
2863 log_sub_test_begin test_${1}
2864 (run_one $1 "$2") 2>&1 | tee $test_log
2865 local RC=${PIPESTATUS[0]}
2867 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
2868 echo "test_$1 returned $RC" | tee $LOGDIR/err
2870 duration=$((`date +%s` - $BEFORE))
2871 pass "(${duration}s)"
2872 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
2873 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
2875 if [ -f $LOGDIR/err ]; then
2876 $FAIL_ON_ERROR && exit $RC
2883 (cd `dirname $1`; echo $PWD/`basename $1`)
2887 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2888 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2893 export base=`basetest $1`
2894 [ "$CHECK_GRANT" == "no" ] && return 0
2896 testname=GCHECK_ONLY_${base}
2897 [ ${!testname}x == x ] && return 0
2899 echo -n "checking grant......"
2901 # write some data to sync client lost_grant
2902 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2903 for i in `seq $OSTCOUNT`; do
2904 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2905 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2906 count=1 > /dev/null 2>&1
2908 # sync all the data and make sure no pending data on server
2911 #get client grant and server grant
2913 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2914 client_grant=$((client_grant + $d))
2917 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2918 server_grant=$((server_grant + $d))
2921 # cleanup the check_grant file
2922 for i in `seq $OSTCOUNT`; do
2923 rm $DIR1/${tfile}_check_grant_$i
2926 #check whether client grant == server grant
2927 if [ $client_grant != $server_grant ]; then
2928 echo "failed: client:${client_grant} server: ${server_grant}"
2935 ########################
2941 ost=`echo $1 | awk -F_ '{print $3}'`
2942 if [ -z $ost ]; then
2943 ost=`echo $1 | sed 's/-osc.*//'`
2950 [ "$node" != "$(hostname)" ]
2956 for node in $(mdts_nodes); do
2957 remote_node $node && return 0
2964 [ "$CLIENTONLY" ] && return 0 || true
2965 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2970 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
2971 MSKIPPED=1 && return 1
2978 for node in $(osts_nodes) ; do
2979 remote_node $node && return 0
2986 [ "$CLIENTONLY" ] && return 0 || true
2987 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2992 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
2993 OSKIPPED=1 && return 1
3000 MGS=$(facet_host mgs)
3001 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3006 remote_mds_nodsh || remote_ost_nodsh || \
3007 $(single_local_node $(comma_list $(nodes_list)))
3013 for num in `seq $MDSCOUNT`; do
3014 MDSNODES="$MDSNODES $(facet_host mds$num)"
3016 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3022 remote_ost && remote_mds
3026 local OSTNODES=$(facet_host ost1)
3029 for num in `seq $OSTCOUNT`; do
3030 local myOST=$(facet_host ost$num)
3031 OSTNODES="$OSTNODES $myOST"
3033 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
3039 # FIXME. We need a list of clients
3040 local myNODES=$HOSTNAME
3043 # CLIENTS (if specified) contains the local client
3044 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3046 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3047 myNODES="$myNODES $(osts_nodes) $(mdts_nodes)"
3050 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3055 remote_nodes_list () {
3056 local rnodes=$(nodes_list)
3057 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3061 init_clients_lists () {
3062 # Sanity check: exclude the local client from RCLIENTS
3063 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3065 # Sanity check: exclude the dup entries
3066 rclients=$(for i in $rclients; do echo $i; done | sort -u)
3068 local clients="$SINGLECLIENT $HOSTNAME $rclients"
3070 # Sanity check: exclude the dup entries from CLIENTS
3071 # for those configs which has SINGLCLIENT set to local client
3072 clients=$(for i in $clients; do echo $i; done | sort -u)
3074 CLIENTS=`comma_list $clients`
3075 local -a remoteclients=($rclients)
3076 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3077 varname=CLIENT$((i + 2))
3078 eval $varname=${remoteclients[i]}
3081 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3084 get_random_entry () {
3087 rnodes=${rnodes//,/ }
3089 local -a nodes=($rnodes)
3090 local num=${#nodes[@]}
3091 local i=$((RANDOM * num * 2 / 65536))
3097 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3102 lctl get_param version | grep -q patchless
3106 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3111 echo $nodes | wc -w || true
3115 local nodes=$(osts_nodes)
3116 local osscount=$(get_node_count "$nodes")
3117 [ ! "$OSTCOUNT" = "$osscount" ]
3121 local nodes=$(mdts_nodes)
3122 local mdtcount=$(get_node_count "$nodes")
3123 [ ! "$MDSCOUNT" = "$mdtcount" ]
3126 generate_machine_file() {
3127 local nodes=${1//,/ }
3128 local machinefile=$2
3130 for node in $nodes; do
3131 echo $node >>$machinefile || \
3132 { echo "can not generate machinefile $machinefile" && return 1; }
3137 local file=$1/stripe
3139 $LFS getstripe -v $file || error
3143 setstripe_nfsserver () {
3146 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3147 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3149 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3151 do_nodev $nfsserver lfs setstripe "$@"
3154 check_runas_id_ret() {
3156 local myRUNAS_UID=$1
3157 local myRUNAS_GID=$2
3160 if [ -z "$myRUNAS" ]; then
3161 error_exit "myRUNAS command must be specified for check_runas_id"
3164 $myRUNAS krb5_login.sh || \
3165 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3167 mkdir $DIR/d0_runas_test
3169 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3170 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3171 rm -rf $DIR/d0_runas_test
3176 local myRUNAS_UID=$1
3177 local myRUNAS_GID=$2
3180 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3181 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3182 Please set RUNAS_ID to some UID which exists on MDS and client or
3183 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3186 # obtain the UID/GID for MPI_USER
3190 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3191 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3193 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3194 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3197 # obtain and cache Kerberos ticket-granting ticket
3198 refresh_krb5_tgt() {
3199 local myRUNAS_UID=$1
3200 local myRUNAS_GID=$2
3203 if [ -z "$myRUNAS" ]; then
3204 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3207 CLIENTS=${CLIENTS:-$HOSTNAME}
3208 do_nodes $CLIENTS "set -x
3209 if ! $myRUNAS krb5_login.sh; then
3210 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3215 # Run multiop in the background, but wait for it to print
3216 # "PAUSING" to its stdout before returning from this function.
3217 multiop_bg_pause() {
3218 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3222 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3225 echo "$MULTIOP_PROG $FILE v$ARGS"
3226 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3228 echo "TMPPIPE=${TMPPIPE}"
3229 read -t 60 multiop_output < $TMPPIPE
3230 if [ $? -ne 0 ]; then
3235 if [ "$multiop_output" != "PAUSING" ]; then
3236 echo "Incorrect multiop output: $multiop_output"
3251 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3257 inodes_available () {
3258 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3262 mdsrate_inodes_available () {
3263 echo $(($(inodes_available) - 1))
3266 # reset llite stat counters
3267 clear_llite_stats(){
3268 lctl set_param -n llite.*.stats 0
3271 # sum llite stat items
3272 calc_llite_stats() {
3273 local res=$(lctl get_param -n llite.*.stats |
3274 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3278 # reset osc stat counters
3280 lctl set_param -n osc.*.osc_stats 0
3283 # sum osc stat items
3285 local res=$(lctl get_param -n osc.*.osc_stats |
3286 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3291 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3294 calc_osc_kbytes () {
3295 df $MOUNT > /dev/null
3296 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3299 # save_lustre_params(node, parameter_mask)
3300 # generate a stream of formatted strings (<node> <param name>=<param value>)
3301 save_lustre_params() {
3303 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3306 # restore lustre parameters from input stream, produces by save_lustre_params
3307 restore_lustre_params() {
3311 while IFS=" =" read node name val; do
3312 do_node ${node//:/} "lctl set_param -n $name $val"
3316 check_catastrophe() {
3317 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3318 local C=$CATASTROPHE
3319 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3321 if [ $rnodes ]; then
3322 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3323 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3339 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3341 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3342 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3343 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3347 # CMD: determine mds index where directory inode presents
3350 local file=$dir/f0.get_mds_dir_tmpfile
3355 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3356 local -a oldused=($iused)
3358 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3360 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3361 local -a newused=($iused)
3364 for ((i=0; i<${#newused[@]}; i++)); do
3365 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3371 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3374 mdsrate_cleanup () {
3376 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3381 delayed_recovery_enabled () {
3382 local var=${SINGLEMDS}_svc
3383 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3386 ########################
3388 convert_facet2label() {
3391 if [ x$facet = xost ]; then
3395 local varsvc=${facet}_svc
3397 if [ -n ${!varsvc} ]; then
3400 error "No lablel for $facet!"
3404 get_clientosc_proc_path() {
3410 get_lustre_version () {
3411 local node=${1:-"mds"}
3412 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3415 get_mds_version_major () {
3416 local version=$(get_lustre_version mds)
3417 echo $version | awk -F. '{print $1}'
3420 get_mds_version_minor () {
3421 local version=$(get_lustre_version mds)
3422 echo $version | awk -F. '{print $2}'
3425 get_mdtosc_proc_path() {
3427 local major=$(get_mds_version_major)
3428 local minor=$(get_mds_version_minor)
3429 if [ $major -le 1 -a $minor -le 8 ] ; then
3432 echo "${ost}-osc-MDT0000"
3436 get_osc_import_name() {
3439 local label=$(convert_facet2label $ost)
3441 if [ "$facet" == "mds" ]; then
3442 get_mdtosc_proc_path $label
3446 get_clientosc_proc_path $label
3450 wait_import_state () {
3456 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3457 while [ "${CONN_STATE}" != "${expected}" ]; do
3458 if [ "${expected}" == "DISCONN" ]; then
3459 # for disconn we can check after proc entry is removed
3460 [ "x${CONN_STATE}" == "x" ] && return 0
3461 # with AT we can have connect request timeout ~ reconnect timeout
3462 # and test can't see real disconnect
3463 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3465 # disconnect rpc should be wait not more obd_timeout
3466 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3467 error "can't put import for $CONN_PROC into ${expected} state" && return 1
3469 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3473 log "$CONN_PROC now in ${CONN_STATE} state"
3477 wait_osc_import_state() {
3481 local ost=$(get_osc_import_name $facet $ost_facet)
3486 CONN_PROC="osc.${ost}.ost_server_uuid"
3487 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3488 while [ "${CONN_STATE}" != "${expected}" ]; do
3489 if [ "${expected}" == "DISCONN" ]; then
3490 # for disconn we can check after proc entry is removed
3491 [ "x${CONN_STATE}" == "x" ] && return 0
3492 # with AT we can have connect request timeout ~ reconnect timeout
3493 # and test can't see real disconnect
3494 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3496 # disconnect rpc should be wait not more obd_timeout
3497 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3498 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3500 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3504 log "${ost_facet} now in ${CONN_STATE} state"
3507 get_clientmdc_proc_path() {
3515 # Add paths to lustre tests for 32 and 64 bit systems.
3516 local RPATH="$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
3517 do_nodesv $list "PATH=$RPATH sh rpc.sh $@ "
3520 wait_clients_import_state () {
3526 local label=$(convert_facet2label $facet)
3529 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3530 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3531 *) error "unknown facet!" ;;
3534 if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
3535 error "import is not in ${expected} state"
3544 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
3545 $LCTL get_param obdfilter.*.kbytesavail))
3546 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
3547 $LCTL get_param -n obdfilter.*.tot_granted))
3548 for ((i=0; i<${#AVAILA[@]}; i++)); do
3549 local -a AVAIL1=(${AVAILA[$i]//=/ })
3550 GRANT=$((${GRANTA[$i]}/1024))
3551 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
3552 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
3558 do_facet mgs lctl pool_list $1
3562 local fsname=${1%%.*}
3563 local poolname=${1##$fsname.}
3565 do_facet mgs lctl pool_new $1
3567 # get param should return err unless pool is created
3568 [[ $RC -ne 0 ]] && return $RC
3570 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3571 2>/dev/null || echo foo" "" || RC=1
3572 if [[ $RC -eq 0 ]]; then
3575 error "pool_new failed $1"
3580 add_pool_to_list () {
3581 local fsname=${1%%.*}
3582 local poolname=${1##$fsname.}
3584 local listvar=${fsname}_CREATED_POOLS
3585 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
3588 remove_pool_from_list () {
3589 local fsname=${1%%.*}
3590 local poolname=${1##$fsname.}
3592 local listvar=${fsname}_CREATED_POOLS
3593 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
3596 destroy_pool_int() {
3598 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
3599 awk '$1 !~ /^Pool:/ {print $1}')
3600 for ost in $OSTS; do
3601 do_facet mgs lctl pool_remove $1 $ost
3603 do_facet mgs lctl pool_destroy $1
3606 # <fsname>.<poolname> or <poolname>
3608 local fsname=${1%%.*}
3609 local poolname=${1##$fsname.}
3611 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3615 pool_list $fsname.$poolname || return $?
3617 destroy_pool_int $fsname.$poolname
3619 [[ $RC -ne 0 ]] && return $RC
3621 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3622 2>/dev/null || echo foo" "foo" || RC=1
3624 if [[ $RC -eq 0 ]]; then
3625 remove_pool_from_list $fsname.$poolname
3627 error "destroy pool failed $1"
3633 local fsname=${1:-$FSNAME}
3635 local listvar=${fsname}_CREATED_POOLS
3639 [ x${!listvar} = x ] && return 0
3641 echo destroy the created pools: ${!listvar}
3642 for poolname in ${!listvar//,/ }; do
3643 destroy_pool $fsname.$poolname
3648 local fsname=${1:-$FSNAME}
3650 destroy_pools $fsname
3656 local ts=$(date +%s)
3658 # bug 20237, comment 11
3659 # It would also be useful to provide the option
3660 # of writing the file to an NFS directory so it doesn't need to be copied.
3663 [ -f $LOGDIR/shared ] && docp=false
3665 # dump lustre logs, dmesg
3667 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
3669 echo "Dumping lctl log to ${prefix}.*.${suffix}"
3671 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
3672 echo "Dumping logs only on local client."
3673 $LCTL dk > ${prefix}.debug_log.$(hostname).${suffix}
3674 dmesg > ${prefix}.dmesg.$(hostname).${suffix}
3679 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname).${suffix};
3680 dmesg > ${prefix}.dmesg.\\\$(hostname).${suffix}"
3681 if [ ! -f $LOGDIR/shared ]; then
3682 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
3685 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
3686 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
3692 local list=${1:-$(comma_list $(nodes_list))}
3694 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3706 for i in $(seq 0 $num_mntpts); do
3707 cmd="ls -laf ${mntpt_root}$i/$dir"
3713 for pid in $pids; do
3720 # target_start_and_reset_recovery_timer()
3721 # service_time = at_est2timeout(service_time);
3722 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3723 # INITIAL_CONNECT_TIMEOUT);
3724 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3725 #define CONNECTION_SWITCH_INC 1
3726 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3727 #define CONNECTION_SWITCH_MIN 5U
3729 max_recovery_time () {
3730 local init_connect_timeout=$(( TIMEOUT / 20 ))
3731 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3733 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3738 get_clients_mount_count () {
3739 local clients=${CLIENTS:-`hostname`}
3741 # we need to take into account the clients mounts and
3742 # exclude mds/ost mounts if any;
3743 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
3747 PROC_CLI="srpc_info"
3755 if [ $M -lt $N ]; then
3759 while [ $N -lt $M ]; do
3769 calc_connection_cnt() {
3772 # MDT->MDT = 2 * C(M, 2)
3776 comb_m2=$(combination $MDSCOUNT 2)
3778 local num_clients=$(get_clients_mount_count)
3780 local cnt_mdt2mdt=$((comb_m2 * 2))
3781 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
3782 local cnt_cli2ost=$((num_clients * OSTCOUNT))
3783 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
3784 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
3785 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
3786 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
3800 local cmd="$tgt.srpc.flavor"
3802 if [ $net == "any" ]; then
3807 if [ $dir != "any" ]; then
3812 log "Setting sptlrpc rule: $cmd"
3813 do_facet mgs "$LCTL conf_param $cmd"
3822 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
3823 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
3825 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
3827 if [ "x$bulkspec" != "x" ]; then
3828 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
3830 if [ "x$algs" != "x" ]; then
3831 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
3833 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
3834 if [ $bulk == "bulkn" ]; then
3835 bulk_count=`echo "$output" | grep "bulk flavor" \
3836 | grep "null/null" | wc -l`
3837 elif [ $bulk == "bulki" ]; then
3838 bulk_count=`echo "$output" | grep "bulk flavor" \
3839 | grep "/null" | grep -v "null/" | wc -l`
3841 bulk_count=`echo "$output" | grep "bulk flavor" \
3842 | grep -v "/null" | grep -v "null/" | wc -l`
3846 [ $bulk_count -lt $count ] && count=$bulk_count
3857 local clients=${CLIENTS:-`hostname`}
3859 for c in ${clients//,/ }; do
3860 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
3861 tmpcnt=`count_flvr "$output" $flavor`
3862 cnt=$((cnt + tmpcnt))
3872 local clients=${CLIENTS:-`hostname`}
3874 for c in ${clients//,/ }; do
3875 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
3876 tmpcnt=`count_flvr "$output" $flavor`
3877 cnt=$((cnt + tmpcnt))
3887 if [ $MDSCOUNT -le 1 ]; then
3892 for num in `seq $MDSCOUNT`; do
3893 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
3894 tmpcnt=`count_flvr "$output" $flavor`
3895 cnt=$((cnt + tmpcnt))
3905 for num in `seq $MDSCOUNT`; do
3906 output=`do_facet mds$num lctl get_param -n osc.*OST*-osc-MDT*.$PROC_CLI 2>/dev/null`
3907 tmpcnt=`count_flvr "$output" $flavor`
3908 cnt=$((cnt + tmpcnt))
3917 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
3918 count_flvr "$output" $flavor
3923 local dir=$1 # from to
3924 local flavor=$2 # flavor expected
3927 if [ $dir == "cli2mdt" ]; then
3928 res=`flvr_cnt_cli2mdt $flavor`
3929 elif [ $dir == "cli2ost" ]; then
3930 res=`flvr_cnt_cli2ost $flavor`
3931 elif [ $dir == "mdt2mdt" ]; then
3932 res=`flvr_cnt_mdt2mdt $flavor`
3933 elif [ $dir == "mdt2ost" ]; then
3934 res=`flvr_cnt_mdt2ost $flavor`
3935 elif [ $dir == "all2ost" ]; then
3936 res1=`flvr_cnt_mdt2ost $flavor`
3937 res2=`flvr_cnt_cli2ost $flavor`
3938 res=$((res1 + res2))
3939 elif [ $dir == "all2mdt" ]; then
3940 res1=`flvr_cnt_mdt2mdt $flavor`
3941 res2=`flvr_cnt_cli2mdt $flavor`
3942 res=$((res1 + res2))
3943 elif [ $dir == "all2all" ]; then
3944 res1=`flvr_cnt_mdt2ost $flavor`
3945 res2=`flvr_cnt_cli2ost $flavor`
3946 res3=`flvr_cnt_mdt2mdt $flavor`
3947 res4=`flvr_cnt_cli2mdt $flavor`
3948 res=$((res1 + res2 + res3 + res4))
3956 local dir=$1 # from to
3957 local flavor=$2 # flavor expected
3958 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
3962 for ((i=0;i<20;i++)); do
3963 echo -n "checking..."
3964 res=$(do_check_flavor $dir $flavor)
3965 if [ $res -eq $expect ]; then
3966 echo "found $res $flavor connections of $dir, OK"
3969 echo "found $res $flavor connections of $dir, not ready ($expect)"
3975 echo "Error checking $flavor of $dir: expect $expect, actual $res"
3979 restore_to_default_flavor()
3981 local proc="mgs.MGS.live.$FSNAME"
3983 echo "restoring to default flavor..."
3985 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3987 # remove all existing rules if any
3988 if [ $nrule -ne 0 ]; then
3989 echo "$nrule existing rules"
3990 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
3991 echo "remove rule: $rule"
3992 spec=`echo $rule | awk -F = '{print $1}'`
3993 do_facet mgs "$LCTL conf_param $spec="
3997 # verify no rules left
3998 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3999 [ $nrule -ne 0 ] && error "still $nrule rules left"
4001 # wait for default flavor to be applied
4002 # currently default flavor for all connections are 'null'
4003 wait_flavor all2all null
4004 echo "now at default flavor settings"
4009 local flavor=${1:-null}
4011 echo "setting all flavor to $flavor"
4013 # FIXME need parameter to this fn
4014 # and remove global vars
4015 local cnt_all2all=$(calc_connection_cnt all2all)
4017 local res=$(do_check_flavor all2all $flavor)
4018 if [ $res -eq $cnt_all2all ]; then
4019 echo "already have total $res $flavor connections"
4023 echo "found $res $flavor out of total $cnt_all2all connections"
4024 restore_to_default_flavor
4026 [[ $flavor = null ]] && return 0
4028 set_rule $FSNAME any any $flavor
4029 wait_flavor all2all $flavor
4035 # Checking for shared logdir
4036 if [ ! -d $dir ]; then
4037 # Not found. Create local logdir
4040 touch $dir/node.$(hostname).yml
4045 check_write_access() {
4047 for node in $(nodes_list); do
4048 if [ ! -f "$dir/node.${node}.yml" ]; then
4049 # Logdir not accessible/writable from this node.
4057 if [[ -n $YAML_LOG ]]; then
4060 export YAML_LOG=${LOGDIR}/results.yml
4064 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $LOGDIR
4065 if check_write_access $LOGDIR; then
4066 touch $LOGDIR/shared
4067 echo "Logging to shared log directory: $LOGDIR"
4069 echo "Logging to local directory: $LOGDIR"
4072 yml_nodes_file $LOGDIR
4073 yml_results_file >> $YAML_LOG
4077 yml_log_test $1 >> $YAML_LOG
4081 yml_log_test_status $@ >> $YAML_LOG
4084 log_sub_test_begin() {
4085 yml_log_sub_test_begin $@ >> $YAML_LOG
4088 log_sub_test_end() {
4089 yml_log_sub_test_end $@ >> $YAML_LOG
4095 local devname=$(basename $1)
4096 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4097 # loop devices aren't in /proc/partitions
4098 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4100 size=$(($size / 1024 / 1024)) # Gb
4102 local partial_arg=""
4103 # Run in partial (fast) mode if the size
4104 # of a partition > 10 GB
4105 [ $size -gt 10 ] && partial_arg="-p"
4107 llverdev --force $partial_arg $dev
4110 remove_mdt_files() {
4115 local mntpt=${MOUNT%/*}/$facet
4117 echo "removing files from $mdtdev on $facet: $files"
4118 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4121 rm $mntpt/ROOT/$f || { rc=$?; break; }
4123 umount -f $mntpt || return $?
4127 duplicate_mdt_files() {
4132 local mntpt=${MOUNT%/*}/$facet
4134 echo "duplicating files on $mdtdev on $facet: $files"
4135 mkdir -p $mntpt || return $?
4136 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4146 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4147 pushd $mntpt/ROOT > /dev/null || return $?
4150 touch $f.bad || return $?
4151 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4153 [ $rc -eq 0 ] || return $rc
4154 setfattr --restore $tmp || return $?