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 MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
171 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
172 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
173 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
174 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
175 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
176 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
177 export FSTYPE=${FSTYPE:-"ldiskfs"}
178 export NAME=${NAME:-local}
179 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
180 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
181 export LGSSD=$(which lgssd)
182 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
183 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
184 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
186 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
189 if [ "$ACCEPTOR_PORT" ]; then
190 export PORT_OPT="--port $ACCEPTOR_PORT"
195 echo "Using GSS/krb5 ptlrpc security flavor"
196 which lgss_keyring > /dev/null 2>&1 || \
197 error_exit "built with gss disabled! SEC=$SEC"
208 IDENTITY_UPCALL=false
211 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
213 # Paths on remote nodes, if different
214 export RLUSTRE=${RLUSTRE:-$LUSTRE}
215 export RPWD=${RPWD:-$PWD}
216 export I_MOUNTED=${I_MOUNTED:-"no"}
217 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
218 ! -f `dirname $0`/../mds/mds.ko ]; then
219 export CLIENTMODSONLY=yes
224 while getopts "rvwf:" opt $*; do
227 r) REFORMAT=--reformat;;
229 w) WRITECONF=writeconf;;
234 shift $((OPTIND - 1))
237 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
242 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
243 *) EXT=".ko"; USE_QUOTA=yes;;
248 /sbin/lsmod | grep -q $1
251 # Load a module on the system where this is running.
253 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
255 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
256 # will be used as the arguments. Otherwise arguments will be obtained from
257 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
264 BASE=`basename $module $EXT`
266 module_loaded ${BASE} && return
268 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
270 if [ $# -eq 0 ]; then
271 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
272 # Bash until 4.x, so we resort to eval.
273 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
274 eval set -- \$$optvar
275 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
276 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
277 set -- $(grep "^options\\s*\<${module}\>" $MODPROBECONF)
278 # Get rid of "options $module"
279 (($# > 0)) && shift 2
281 # Ensure we have accept=all for lnet
282 if [ $(basename $module) = lnet ]; then
283 # OK, this is a bit wordy...
284 local arg accept_all_present=false
286 [ "$arg" = accept=all ] && accept_all_present=true
288 $accept_all_present || set -- "$@" accept=all
293 [ $# -gt 0 ] && echo "${module} options: '$*'"
295 # Note that insmod will ignore anything in modprobe.conf, which is why we're
296 # passing options on the command-line.
297 if [ "$BASE" == "lnet_selftest" ] && \
298 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
299 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
300 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
301 insmod ${LUSTRE}/${module}${EXT} "$@"
303 # must be testing a "make install" or "rpm" installation
304 # note failed to load ptlrpc_gss is considered not fatal
305 if [ "$BASE" == "ptlrpc_gss" ]; then
306 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
313 load_modules_local() {
314 if [ -n "$MODPROBE" ]; then
316 echo "Using modprobe to load modules"
320 echo Loading modules from $LUSTRE
321 load_module ../libcfs/libcfs/libcfs
322 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
323 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
324 load_module ../lnet/lnet/lnet
325 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
326 load_module ../lnet/klnds/$LNETLND
327 load_module lvfs/lvfs
328 load_module obdclass/obdclass
329 load_module ptlrpc/ptlrpc
330 load_module ptlrpc/gss/ptlrpc_gss
331 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota
339 if ! client_only; then
340 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
341 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
342 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
347 load_module lvfs/fsfilt_$FSTYPE
351 load_module obdfilter/obdfilter
354 load_module llite/lustre
355 load_module llite/llite_lloop
356 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
358 rm -f $OGDB/ogdb-$HOSTNAME
359 $LCTL modules > $OGDB/ogdb-$HOSTNAME
361 # 'mount' doesn't look in $PATH, just sbin
362 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
368 # load modules on remote nodes optionally
369 # lustre-tests have to be installed on these nodes
370 if $LOAD_MODULES_REMOTE ; then
371 local list=$(comma_list $(remote_nodes_list))
372 echo loading modules on $list
373 do_rpc_nodes $list load_modules
378 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
379 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
380 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
381 echo "$LEAK_LUSTRE" 1>&2
382 echo "$LEAK_PORTALS" 1>&2
383 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
384 echo "Memory leaks detected"
385 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
391 wait_exit_ST client # bug 12845
393 $LUSTRE_RMMOD $FSTYPE || return 2
395 if $LOAD_MODULES_REMOTE ; then
396 local list=$(comma_list $(remote_nodes_list))
397 if [ ! -z $list ]; then
398 echo unloading modules on $list
399 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
400 do_rpc_nodes $list check_mem_leak
404 check_mem_leak || return 254
406 echo "modules unloaded."
410 check_gss_daemon_nodes() {
414 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
415 if [ \\\"\\\$num\\\" -ne 1 ]; then
416 echo \\\$num instance of $dname;
421 check_gss_daemon_facet() {
425 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
426 if [ $num -ne 1 ]; then
427 echo "$num instance of $dname on $facet"
436 echo Stopping $@ on $list
437 do_nodes $list "killall -2 $@ 2>/dev/null || true"
440 # start gss daemons on all nodes, or
441 # "daemon" on "list" if set
442 start_gss_daemons() {
446 if [ "$list" ] && [ "$daemon" ] ; then
447 echo "Starting gss daemon on nodes: $list"
448 do_nodes $list "$daemon" || return 8
452 local list=$(comma_list $(mdts_nodes))
454 echo "Starting gss daemon on mds: $list"
455 do_nodes $list "$LSVCGSSD -v" || return 1
457 do_nodes $list "$LGSSD -v" || return 2
460 list=$(comma_list $(osts_nodes))
461 echo "Starting gss daemon on ost: $list"
462 do_nodes $list "$LSVCGSSD -v" || return 3
463 # starting on clients
465 local clients=${CLIENTS:-`hostname`}
467 echo "Starting $LGSSD on clients $clients "
468 do_nodes $clients "$LGSSD -v" || return 4
471 # wait daemons entering "stable" status
475 # check daemons are running
477 list=$(comma_list $(mdts_nodes) $(osts_nodes))
478 check_gss_daemon_nodes $list lsvcgssd || return 5
480 list=$(comma_list $(mdts_nodes))
481 check_gss_daemon_nodes $list lgssd || return 6
484 check_gss_daemon_nodes $clients lgssd || return 7
489 local list=$(comma_list $(mdts_nodes))
491 send_sigint $list lsvcgssd lgssd
493 list=$(comma_list $(osts_nodes))
494 send_sigint $list lsvcgssd
496 list=${CLIENTS:-`hostname`}
497 send_sigint $list lgssd
502 if ! module_loaded ptlrpc_gss; then
503 load_module ptlrpc/gss/ptlrpc_gss
504 module_loaded ptlrpc_gss ||
505 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
507 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
509 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
510 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
518 # maybe cleanup credential cache?
524 local device=`mdsdevname $num`
525 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
531 local device=`ostdevname $num`
532 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
540 local dev=$(facet_active $facet)_dev
541 local opt=${facet}_opt
542 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
543 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
545 if [ $RC -ne 0 ]; then
546 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
547 echo "Start of ${!dev} on ${facet} failed ${RC}"
549 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
550 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
551 lctl set_param debug_mb=${DEBUG_SIZE}; \
554 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
555 [ -z "$label" ] && echo no label for ${!dev} && exit 1
556 eval export ${facet}_svc=${label}
557 echo Started ${label}
562 # start facet device options
568 eval export ${facet}_dev=${device}
569 eval export ${facet}_opt=\"$@\"
571 local varname=${facet}failover_dev
572 if [ -n "${!varname}" ] ; then
573 eval export ${facet}failover_dev=${!varname}
575 eval export ${facet}failover_dev=$device
578 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
588 HOST=`facet_active_host $facet`
589 [ -z $HOST ] && echo stop: no host for $facet && return 0
591 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
592 if [ ${running} -ne 0 ]; then
593 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
594 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
597 # umount should block, but we should wait for unrelated obd's
598 # like the MGS or MGC to also stop.
599 wait_exit_ST ${facet}
602 # save quota version (both administrative and operational quotas)
603 # add an additional parameter if mountpoint is ever different from $MOUNT
604 quota_save_version() {
605 local fsname=${2:-$FSNAME}
607 local ver=$(tr -c -d "123" <<< $spec)
608 local type=$(tr -c -d "ug" <<< $spec)
610 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
612 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
614 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
616 local osts=$(get_facets OST)
617 for ost in ${osts//,/ }; do
619 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
623 # client could mount several lustre
625 local fsname=${1:-$FSNAME}
627 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
628 do_nodes $(comma_list $(osts_nodes)) \
629 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
633 restore_quota_type () {
634 local mntpt=${1:-$MOUNT}
635 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
636 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
639 quota_save_version $old_QUOTA_TYPE
645 # We need save the original quota_type params, and restore them after testing
647 # Suppose that quota type the same on mds and ost
648 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
649 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
650 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
651 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
652 export old_QUOTA_TYPE=$quota_type
653 quota_save_version $QUOTA_TYPE
655 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
656 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
659 local quota_usrs=$QUOTA_USERS
661 # get_filesystem_size
662 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
663 local blk_soft=$((disksz + 1024))
664 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
666 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
668 local i_hard=$((i_soft + i_soft / 20))
670 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
671 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
674 for usr in $quota_usrs; do
675 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
677 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
679 eval $cmd || error "$cmd FAILED!"
681 # display the quota status
682 echo "Quota settings for $usr : "
683 $LFS quota -v -u $usr $mntpt || true
691 # Only supply -o to mount if we have options
692 if [ -n "$MOUNTOPT" ]; then
693 OPTIONS="-o $MOUNTOPT"
695 local device=$MGSNID:/$FSNAME
696 if [ -z "$mnt" -o -z "$FSNAME" ]; then
697 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
701 echo "Starting client: $client: $OPTIONS $device $mnt"
702 do_node $client mkdir -p $mnt
703 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
705 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
706 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
707 lctl set_param debug_mb=${DEBUG_SIZE}"
720 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
721 if [ $running -ne 0 ]; then
722 echo "Stopping client $client $mnt (opts:$force)"
723 do_node $client lsof -t $mnt || need_kill=no
724 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
725 pids=$(do_node $client lsof -t $mnt | sort -u);
726 if [ -n $pids ]; then
727 do_node $client kill -9 $pids || true
731 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
732 if [ $busy -ne 0 ] ; then
733 echo "$mnt is still busy, wait one second" && sleep 1
734 do_node $client umount $force $mnt
739 # nodes is comma list
740 sanity_mount_check_nodes () {
746 # FIXME: assume that all cluster nodes run the same os
747 [ "$(uname)" = Linux ] || return 0
750 for mnt in $mnts ; do
751 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
752 mpts=\\\$(mount | grep -w -c $mnt);
753 if [ \\\$running -ne \\\$mpts ]; then
754 echo \\\$(hostname) env are INSANE!;
762 sanity_mount_check_servers () {
764 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
765 echo Checking servers environments
767 # FIXME: modify get_facets to display all facets wo params
768 local facets="$(get_facets OST),$(get_facets MDS),mgs"
772 for facet in ${facets//,/ }; do
773 node=$(facet_host ${facet})
774 mnt=${MOUNT%/*}/${facet}
775 sanity_mount_check_nodes $node $mnt ||
776 { error "server $node environments are insane!"; return 1; }
780 sanity_mount_check_clients () {
781 local clients=${1:-$CLIENTS}
782 local mntpt=${2:-$MOUNT}
783 local mntpt2=${3:-$MOUNT2}
785 [ -z $clients ] && clients=$(hostname)
786 echo Checking clients $clients environments
788 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
789 error "clients environments are insane!"
792 sanity_mount_check () {
793 sanity_mount_check_servers || return 1
794 sanity_mount_check_clients || return 2
797 # mount clients if not mouted
798 zconf_mount_clients() {
801 local OPTIONS=${3:-$MOUNTOPT}
803 # Only supply -o to mount if we have options
804 if [ "$OPTIONS" ]; then
805 OPTIONS="-o $OPTIONS"
807 local device=$MGSNID:/$FSNAME
808 if [ -z "$mnt" -o -z "$FSNAME" ]; then
809 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
813 echo "Starting client $clients: $OPTIONS $device $mnt"
816 running=\\\$(mount | grep -c $mnt' ');
818 if [ \\\$running -eq 0 ] ; then
820 mount -t lustre $OPTIONS $device $mnt;
823 exit \\\$rc" || return ${PIPESTATUS[0]}
825 echo "Started clients $clients: "
826 do_nodes $clients "mount | grep -w $mnt"
828 do_nodes $clients "lctl set_param debug=\\\"$PTLDEBUG\\\";
829 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
830 lctl set_param debug_mb=${DEBUG_SIZE};"
835 zconf_umount_clients() {
842 echo "Stopping clients: $clients $mnt (opts:$force)"
843 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
844 if [ \\\$running -ne 0 ] ; then
845 echo Stopping client \\\$(hostname) $mnt opts:$force;
846 lsof -t $mnt || need_kill=no;
847 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
848 pids=\\\$(lsof -t $mnt | sort -u);
849 if [ -n \\\"\\\$pids\\\" ]; then
853 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
854 if [ \\\$busy -ne 0 ] ; then
855 echo "$mnt is still busy, wait one second" && sleep 1;
861 shudown_node_hard () {
865 for i in $(seq $attempts) ; do
868 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
869 echo "waiting for $host to fail attempts=$attempts"
870 [ $i -lt $attempts ] || \
871 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
877 local mnt=${2:-$MOUNT}
880 if [ "$FAILURE_MODE" = HARD ]; then
881 shudown_node_hard $client
883 zconf_umount_clients $client $mnt -f
889 if [ "$FAILURE_MODE" = HARD ]; then
890 shudown_node_hard $(facet_active_host $facet)
891 elif [ "$FAILURE_MODE" = SOFT ]; then
905 if [ "$FAILURE_MODE" = HARD ]; then
906 $POWER_UP `facet_active_host $facet`
914 if [ "$FAILURE_MODE" = HARD ]; then
920 # recovery-scale functions
921 check_progs_installed () {
926 do_nodes $clients "PATH=:$PATH; status=true;
927 for prog in $progs; do
928 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
929 echo \\\$prog missing on \\\$(hostname);
937 echo __$(echo $1 | tr '-' 'X')
940 start_client_load() {
943 local var=$(client_var_name $client)_load
944 eval export ${var}=$load
946 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
947 BREAK_ON_ERROR=$BREAK_ON_ERROR \
948 END_RUN_FILE=$END_RUN_FILE \
949 LOAD_PID_FILE=$LOAD_PID_FILE \
950 TESTSUITELOG=$TESTSUITELOG \
952 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
953 log "Started client load: ${load} on $client"
958 start_client_loads () {
959 local -a clients=(${1//,/ })
960 local numloads=${#CLIENT_LOADS[@]}
963 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
964 testnum=$((nodenum % numloads))
965 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
967 # bug 22169: wait the background threads to start
971 # only for remote client
972 check_client_load () {
974 local var=$(client_var_name $client)_load
975 local TESTLOAD=run_${!var}.sh
977 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
979 # bug 18914: try to connect several times not only when
980 # check ps, but while check_catastrophe also
983 while [ $RC = 254 -a $tries -gt 0 ]; do
987 if ! check_catastrophe $client; then
989 if [ $RC -eq 254 ]; then
990 # FIXME: not sure how long we shuold sleep here
994 echo "check catastrophe failed: RC=$RC "
998 # We can continue try to connect if RC=254
999 # Just print the warning about this
1000 if [ $RC = 254 ]; then
1001 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1004 # see if the load is still on the client
1007 while [ $RC = 254 -a $tries -gt 0 ]; do
1011 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1016 if [ $RC = 254 ]; then
1017 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1018 # see if we can diagnose a bit why this is
1023 check_client_loads () {
1024 local clients=${1//,/ }
1028 for client in $clients; do
1029 check_client_load $client
1031 if [ "$rc" != 0 ]; then
1032 log "Client load failed on node $client, rc=$rc"
1038 restart_client_loads () {
1039 local clients=${1//,/ }
1040 local expectedfail=${2:-""}
1044 for client in $clients; do
1045 check_client_load $client
1047 if [ "$rc" != 0 -a "$expectedfail" ]; then
1048 local var=$(client_var_name $client)_load
1049 start_client_load $client ${!var}
1050 echo "Restarted client load ${!var}: on $client. Checking ..."
1051 check_client_load $client
1053 if [ "$rc" != 0 ]; then
1054 log "Client load failed to restart on node $client, rc=$rc"
1055 # failure one client load means test fail
1056 # we do not need to check other
1064 # End recovery-scale functions
1066 # verify that lustre actually cleaned up properly
1068 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1069 error "LBUG/LASSERT detected"
1070 BUSY=`dmesg | grep -i destruct || true`
1071 if [ "$BUSY" ]; then
1073 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1077 check_mem_leak || exit 204
1079 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1080 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1082 if module_loaded lnet || module_loaded libcfs; then
1083 echo "$0: modules still loaded..." 1>&2
1100 RESULT=$(do_node $node "$TEST")
1101 if [ "$RESULT" == "$FINAL" ]; then
1102 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1105 [ $WAIT -ge $MAX ] && break
1106 echo "Waiting $((MAX - WAIT)) secs for update"
1107 WAIT=$((WAIT + sleep))
1110 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1114 wait_update_facet () {
1116 wait_update $(facet_active_host $facet) "$@"
1119 wait_delete_completed () {
1120 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1121 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1125 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1127 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1128 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1129 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1130 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1134 echo "Delete is not completed in $MAX_WAIT sec"
1140 check_network "$host" 900
1141 while ! do_node $host hostname > /dev/null; do sleep 5; done
1146 local host=`facet_active_host $facet`
1150 wait_recovery_complete () {
1153 # Use default policy if $2 is not passed by caller.
1154 local MAX=${2:-$(max_recovery_time)}
1156 local var_svc=${facet}_svc
1157 local procfile="*.${!var_svc}.recovery_status"
1161 while [ $WAIT -lt $MAX ]; do
1162 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
1163 [[ $STATUS = "status: COMPLETE" ]] && return 0
1166 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
1168 echo "$facet recovery not done in $MAX sec. $STATUS"
1172 wait_mds_ost_sync () {
1173 # just because recovery is done doesn't mean we've finished
1174 # orphan cleanup. Wait for llogs to get synchronized.
1175 echo "Waiting for orphan cleanup..."
1176 # MAX value includes time needed for MDS-OST reconnection
1177 local MAX=$(( TIMEOUT * 2 ))
1179 while [ $WAIT -lt $MAX ]; do
1180 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1181 "$LCTL get_param -n obdfilter.*.mds_sync"))
1183 for ((i=0; i<${#sync[@]}; i++)); do
1184 [ ${sync[$i]} -eq 0 ] && continue
1185 # there is a not finished MDS-OST synchronization
1189 sleep 2 # increase waiting time and cover statfs cache
1190 [ ${con} -eq 1 ] && return 0
1191 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1194 echo "$facet recovery not done in $MAX sec. $STATUS"
1198 wait_destroy_complete () {
1199 echo "Waiting for destroy to be done..."
1200 # MAX value shouldn't be big as this mean server responsiveness
1201 # never increase this just to make test pass but investigate
1202 # why it takes so long time
1205 while [ $WAIT -lt $MAX ]; do
1206 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1208 for ((i=0; i<${#RPCs[@]}; i++)); do
1209 [ ${RPCs[$i]} -eq 0 ] && continue
1210 # there are still some destroy RPCs in flight
1215 [ ${con} -eq 1 ] && return 0 # done waiting
1216 echo "Waiting $WAIT secs for destroys to be done."
1219 echo "Destroys weren't done in $MAX sec."
1229 # conf-sanity 31 takes a long time cleanup
1230 while [ $WAIT -lt 300 ]; do
1231 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1232 [ -z "${running}" ] && return 0
1233 echo "waited $WAIT for${running}"
1234 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1236 WAIT=$((WAIT + INTERVAL))
1238 echo "service didn't stop after $WAIT seconds. Still running:"
1243 wait_remote_prog () {
1249 [ "$PDSH" = "no_dsh" ] && return 0
1251 while [ $WAIT -lt $2 ]; do
1252 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1253 [ -z "${running}" ] && return 0 || true
1254 echo "waited $WAIT for: "
1256 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1258 WAIT=$((WAIT + INTERVAL))
1260 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1261 [ -z "$pids" ] && return 0
1262 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1263 # FIXME: not portable
1264 for pid in $pids; do
1265 cat /proc/${pid}/status || true
1266 cat /proc/${pid}/wchan || true
1268 kill -9 $pid || true
1277 # not every config has many clients
1279 if [ ! -z "$CLIENTS" ]; then
1280 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1282 stat -f $MOUNT > /dev/null
1288 # usually checked on particular client or locally
1290 if [ ! -z "$client" ]; then
1291 $PDSH $client "stat -f $MOUNT" > /dev/null
1293 stat -f $MOUNT > /dev/null
1301 client_reconnect() {
1302 uname -n >> $MOUNT/recon
1303 if [ -z "$CLIENTS" ]; then
1304 df $MOUNT; uname -n >> $MOUNT/recon
1306 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1308 echo Connected clients:
1310 ls -l $MOUNT/recon > /dev/null
1317 echo "Failing $facet on node `facet_active_host $facet`"
1318 shutdown_facet $facet
1319 [ -n "$sleep_time" ] && sleep $sleep_time
1321 change_active $facet
1322 local TO=`facet_active_host $facet`
1323 echo "Failover $facet to $TO"
1325 mount_facet $facet || error "Restart of $facet failed"
1334 do_facet $facet sync
1336 local svc=${facet}_svc
1337 do_facet $facet $LCTL --device %${!svc} notransno
1338 do_facet $facet $LCTL --device %${!svc} readonly
1339 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1340 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1343 replay_barrier_nodf() {
1344 local facet=$1 echo running=${running}
1345 do_facet $facet sync
1346 local svc=${facet}_svc
1347 echo Replay barrier on ${!svc}
1348 do_facet $facet $LCTL --device %${!svc} notransno
1349 do_facet $facet $LCTL --device %${!svc} readonly
1350 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1351 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1354 replay_barrier_nosync() {
1355 local facet=$1 echo running=${running}
1356 local svc=${facet}_svc
1357 echo Replay barrier on ${!svc}
1358 do_facet $facet $LCTL --device %${!svc} notransno
1359 do_facet $facet $LCTL --device %${!svc} readonly
1360 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1361 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1364 mds_evict_client() {
1365 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1366 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1369 ost_evict_client() {
1370 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1371 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1375 facet_failover $* || error "failover: $?"
1376 clients_up || error "post-failover df: $?"
1381 facet_failover $facet
1387 change_active $facet
1388 mount_facet $facet -o abort_recovery
1389 clients_up || echo "first df failed: $?"
1390 clients_up || error "post-failover df: $?"
1394 echo There is no lmc. This is mountconf, baby.
1399 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1400 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1406 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1412 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1413 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1414 if [ -z "$ID" ]; then
1415 echo "Could not get a ptl id for $1..."
1424 h2name_or_ip "$1" "tcp"
1429 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1430 if type __h2elan >/dev/null 2>&1; then
1433 ID=`echo $1 | sed 's/[^0-9]*//g'`
1441 h2name_or_ip "$1" "openib"
1443 declare -fx h2openib
1446 h2name_or_ip "$1" "o2ib"
1453 [ "$facet" == client ] && echo -n $HOSTNAME && return
1454 varname=${facet}_HOST
1455 if [ -z "${!varname}" ]; then
1456 if [ "${facet:0:3}" == "ost" ]; then
1457 eval ${facet}_HOST=${ost_HOST}
1465 local activevar=${facet}active
1467 if [ -f $TMP/${facet}active ] ; then
1468 source $TMP/${facet}active
1471 active=${!activevar}
1472 if [ -z "$active" ] ; then
1479 facet_active_host() {
1481 local active=`facet_active $facet`
1482 if [ "$facet" == client ]; then
1485 echo `facet_host $active`
1491 local failover=${facet}failover
1492 host=`facet_host $failover`
1493 [ -z "$host" ] && return
1494 local curactive=`facet_active $facet`
1495 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1496 eval export ${facet}active=$facet
1498 eval export ${facet}active=$failover
1500 # save the active host for this facet
1501 local activevar=${facet}active
1502 echo "$activevar=${!activevar}" > $TMP/$activevar
1507 # do not stripe off hostname if verbose, bug 19215
1508 if [ x$1 = x--verbose ]; then
1516 if [ "$HOST" = "$HOSTNAME" ]; then
1518 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1519 echo "cannot run remote command on $HOST with $myPDSH"
1523 echo "CMD: $HOST $@" >&2
1524 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1527 if [ "$myPDSH" = "rsh" ]; then
1528 # we need this because rsh does not return exit code of an executed command
1529 local command_status="$TMP/cs"
1530 rsh $HOST ":> $command_status"
1531 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1532 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1533 echo command failed >$command_status"
1534 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1539 # print HOSTNAME for myPDSH="no_dsh"
1540 if [[ $myPDSH = no_dsh ]]; then
1541 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1543 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1546 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1548 return ${PIPESTATUS[0]}
1552 do_node --verbose "$@"
1555 single_local_node () {
1556 [ "$1" = "$HOSTNAME" ]
1559 # Outputs environment variable assignments that should be passed to remote nodes
1564 for var in ${!MODOPTS_*}; do
1566 echo "${var}=\"$value\""
1572 # do not stripe off hostname if verbose, bug 19215
1573 if [ x$1 = x--verbose ]; then
1581 if single_local_node $rnodes; then
1583 do_nodev $rnodes "$@"
1585 do_node $rnodes "$@"
1590 # This is part from do_node
1593 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1594 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1597 echo "CMD: $rnodes $@" >&2
1598 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1602 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1604 $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"
1606 return ${PIPESTATUS[0]}
1612 local HOST=`facet_active_host $facet`
1613 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1618 do_nodes --verbose "$@"
1624 # make sure its not already running
1626 rm -f $TMP/${facet}active
1627 do_facet ${facet} $MKFS $*
1633 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1634 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1641 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1642 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1650 # make sure we are using the primary server, so test-framework will
1651 # be able to clean up properly.
1652 activemds=`facet_active mds1`
1653 if [ $activemds != "mds1" ]; then
1657 local clients=$CLIENTS
1658 [ -z $clients ] && clients=$(hostname)
1660 zconf_umount_clients $clients $MOUNT "$*" || true
1661 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1663 [ "$CLIENTONLY" ] && return
1664 # The add fn does rm ${facet}active file, this would be enough
1665 # if we use do_facet <facet> only after the facet added, but
1666 # currently we use do_facet mds in local.sh
1667 for num in `seq $MDSCOUNT`; do
1669 rm -f ${TMP}/mds${num}active
1672 for num in `seq $OSTCOUNT`; do
1674 rm -f $TMP/ost${num}active
1677 if ! combined_mgs_mds ; then
1685 nfs_client_mode && return
1695 test $nr = 1 && echo -n $MDS_MKFS_OPTS || echo -n $MDSn_MKFS_OPTS
1698 combined_mgs_mds () {
1699 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
1703 if [ "$IAMDIR" == "yes" ]; then
1704 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
1705 MDSn_MKFS_OPTS="$MDSn_MKFS_OPTS --iam-dir"
1708 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1711 # We need ldiskfs here, may as well load them all
1713 [ "$CLIENTONLY" ] && return
1714 echo Formatting mgs, mds, osts
1715 if ! combined_mgs_mds ; then
1716 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1719 for num in `seq $MDSCOUNT`; do
1720 echo "Format mds$num: $(mdsdevname $num)"
1722 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` || exit 9
1724 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` > /dev/null || exit 9
1728 for num in `seq $OSTCOUNT`; do
1729 echo "Format ost$num: $(ostdevname $num)"
1731 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` || exit 10
1733 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` > /dev/null || exit 10
1739 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1743 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
1747 # 0: success, the old identity set already.
1748 # 1: success, the old identity does not set.
1753 local j=`expr $num - 1`
1754 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
1756 if [ -z "$MDT" ]; then
1760 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
1763 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
1765 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
1768 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
1770 if [ $old = "NONE" ]; then
1779 zconf_umount `hostname` $1 || error "umount failed"
1780 zconf_mount `hostname` $1 || error "mount failed"
1783 writeconf_facet () {
1787 do_facet $facet "$TUNEFS --writeconf $dev"
1791 for num in `seq $MDSCOUNT`; do
1792 DEVNAME=$(mdsdevname $num)
1793 writeconf_facet mds$num $DEVNAME
1796 for num in `seq $OSTCOUNT`; do
1797 DEVNAME=$(ostdevname $num)
1798 writeconf_facet ost$num $DEVNAME
1803 nfs_client_mode && return
1805 sanity_mount_check ||
1806 error "environments are insane!"
1810 if [ -z "$CLIENTONLY" ]; then
1811 echo Setup mgs, mdt, osts
1812 echo $WRITECONF | grep -q "writeconf" && \
1814 if ! combined_mgs_mds ; then
1815 start mgs $MGSDEV $mgs_MOUNT_OPTS
1818 for num in `seq $MDSCOUNT`; do
1819 DEVNAME=$(mdsdevname $num)
1820 start mds$num $DEVNAME $MDS_MOUNT_OPTS
1822 # We started mds, now we should set failover variables properly.
1823 # Set mds${num}failover_HOST if it is not set (the default failnode).
1824 local varname=mds${num}failover_HOST
1825 if [ -z "${!varname}" ]; then
1826 eval mds${num}failover_HOST=$(facet_host mds$num)
1829 if [ $IDENTITY_UPCALL != "default" ]; then
1830 switch_identity $num $IDENTITY_UPCALL
1833 for num in `seq $OSTCOUNT`; do
1834 DEVNAME=$(ostdevname $num)
1835 start ost$num $DEVNAME $OST_MOUNT_OPTS
1837 # We started ost$num, now we should set ost${num}failover variable properly.
1838 # Set ost${num}failover_HOST if it is not set (the default failnode).
1839 varname=ost${num}failover_HOST
1840 if [ -z "${!varname}" ]; then
1841 eval ost${num}failover_HOST=$(facet_host ost${num})
1849 # wait a while to allow sptlrpc configuration be propogated to targets,
1850 # only needed when mounting new target devices.
1855 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1857 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1859 if [ "$MOUNT_2" ]; then
1860 mount_client $MOUNT2
1861 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1866 # by remounting mdt before ost, initial connect from mdt to ost might
1867 # timeout because ost is not ready yet. wait some time to its fully
1868 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
1869 # by a context negotiation rpc with $TIMEOUT.
1870 # FIXME better by monitoring import status.
1873 sleep $((TIMEOUT + 5))
1879 mounted_lustre_filesystems() {
1880 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1883 init_facet_vars () {
1884 [ "$CLIENTONLY" ] && return 0
1891 eval export ${facet}_dev=${device}
1892 eval export ${facet}_opt=\"$@\"
1894 local dev=${facet}_dev
1895 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1896 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1898 eval export ${facet}_svc=${label}
1900 local varname=${facet}failover_HOST
1901 if [ -z "${!varname}" ]; then
1902 eval $varname=$(facet_host $facet)
1905 # ${facet}failover_dev is set in cfg file
1906 varname=${facet}failover_dev
1907 if [ -n "${!varname}" ] ; then
1908 eval export ${facet}failover_dev=${!varname}
1910 eval export ${facet}failover_dev=$device
1914 init_facets_vars () {
1917 if ! remote_mds_nodsh; then
1918 for num in `seq $MDSCOUNT`; do
1919 DEVNAME=`mdsdevname $num`
1920 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
1924 remote_ost_nodsh && return
1926 for num in `seq $OSTCOUNT`; do
1927 DEVNAME=`ostdevname $num`
1928 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1932 osc_ensure_active () {
1938 while [ $period -lt $timeout ]; do
1939 count=$(do_facet $facet "lctl dl | grep '${FSNAME}-OST.*-osc-${type}' | grep ' IN ' 2>/dev/null | wc -l")
1940 if [ $count -eq 0 ]; then
1944 echo "There are $count OST are inactive, wait $period seconds, and try again"
1946 period=$((period+3))
1949 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
1952 init_param_vars () {
1953 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1954 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
1955 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1956 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1960 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
1962 log "Using TIMEOUT=$TIMEOUT"
1964 osc_ensure_active $SINGLEMDS M $TIMEOUT
1965 osc_ensure_active client c $TIMEOUT
1967 if [ $QUOTA_AUTO -ne 0 ]; then
1968 if [ "$ENABLE_QUOTA" ]; then
1969 echo "enable quota as required"
1970 setup_quota $MOUNT || return 2
1972 echo "disable quota as required"
1973 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
1980 nfs_client_mode () {
1981 if [ "$NFSCLIENT" ]; then
1982 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1983 local clients=$CLIENTS
1984 [ -z $clients ] && clients=$(hostname)
1986 # FIXME: remove hostname when 19215 fixed
1987 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1988 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1989 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1995 check_config_client () {
1998 local mounted=$(mount | grep " $mntpt ")
1999 if [ "$CLIENTONLY" ]; then
2001 # CLIENTONLY should not depend on *_HOST settings
2002 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2003 # in theory someone could create a new,
2004 # client-only config file that assumed lustre was already
2005 # configured and didn't set the MGSNID. If MGSNID is not set,
2006 # then we should use the mgs nid currently being used
2007 # as the default value. bug 18021
2008 [[ x$MGSNID = x ]] &&
2011 if [[ x$mgc != xMGC$MGSNID ]]; then
2012 if [ "$mgs_HOST" ]; then
2013 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2014 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2015 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2021 local myMGS_host=$mgs_HOST
2022 if [ "$NETTYPE" = "ptl" ]; then
2023 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2026 echo Checking config lustre mounted on $mntpt
2027 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2028 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2030 # if [ "$mgshost" != "$myMGS_host" ]; then
2031 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2032 # Please use correct config or set mds_HOST correctly!"
2037 check_config_clients () {
2038 local clients=${CLIENTS:-$HOSTNAME}
2041 nfs_client_mode && return
2043 do_rpc_nodes $clients check_config_client $mntpt
2045 sanity_mount_check ||
2046 error "environments are insane!"
2050 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2051 local cltimeout=$(lctl get_param -n timeout)
2052 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2053 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2060 [ -z $mntpt ] && return 1
2061 local mounted=$(mounted_lustre_filesystems)
2063 echo $mounted' ' | grep -w -q $mntpt' '
2067 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2071 # empty lustre filesystem may have empty directories lost+found and .lustre
2073 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2074 -print | wc -l) = 1 ] || return 1
2075 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2076 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2080 check_and_setup_lustre() {
2081 nfs_client_mode && return
2083 local MOUNTED=$(mounted_lustre_filesystems)
2087 # both MOUNT and MOUNT2 are not mounted
2088 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2089 [ "$REFORMAT" ] && formatall
2090 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2092 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2093 export I_MOUNTED=yes
2097 elif is_mounted $MOUNT2; then
2099 # MOUNT2 is mounted, while MOUNT_2 is not set
2100 if ! [ "$MOUNT_2" ]; then
2101 cleanup_mount $MOUNT2
2102 export I_UMOUNTED2=yes
2105 # MOUNT2 is mounted, MOUNT_2 is set
2107 # FIXME: what to do if check_config failed?
2109 # 1) remote client has mounted other Lustre fs ?
2110 # 2) it has insane env ?
2111 # let's try umount MOUNT2 on all clients and mount it again:
2112 if ! check_config_clients $MOUNT2; then
2113 cleanup_mount $MOUNT2
2114 restore_mount $MOUNT2
2115 export I_MOUNTED2=yes
2120 # MOUNT is mounted MOUNT2 is not mounted
2121 elif [ "$MOUNT_2" ]; then
2122 restore_mount $MOUNT2
2123 export I_MOUNTED2=yes
2127 # FIXME: what to do if check_config failed?
2129 # 1) remote client has mounted other Lustre fs?
2130 # 2) lustre is mounted on remote_clients atall ?
2131 check_config_clients $MOUNT
2135 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
2136 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
2137 lctl set_param debug_mb=${DEBUG_SIZE};
2144 if [ "$ONLY" == "setup" ]; then
2150 local clients=${CLIENTS:-$HOSTNAME}
2153 zconf_mount_clients $clients $mntpt
2157 local clients=${CLIENTS:-$HOSTNAME}
2160 zconf_umount_clients $clients $mntpt
2163 cleanup_and_setup_lustre() {
2164 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2165 lctl set_param debug=0 || true
2167 if [ "$ONLY" == "cleanup" ]; then
2171 check_and_setup_lustre
2174 # Get all of the server target devices from a given server node and type.
2183 mdt) obd_type="osd" ;;
2184 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2185 *) echo "invalid server type" && return 1 ;;
2188 devs=$(do_node $node "lctl get_param -n $obd_type.*.mntdev")
2189 for dev in $devs; do
2191 *loop*) do_node $node "losetup $dev" | \
2192 sed -e "s/.*(//" -e "s/).*//" ;;
2198 # Get all of the server target devices.
2203 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2207 for node in $(osts_nodes); do
2208 OSTDEVS[i]=$(get_mnt_devs $node ost)
2213 # Run e2fsck on MDT or OST device.
2220 df > /dev/null # update statfs data on disk
2221 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
2224 local rc=${PIPESTATUS[0]}
2225 [ $rc -le $FSCK_MAX_ERR ] || \
2226 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2230 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2237 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2238 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2239 error "fail to create file in $SHARED_DIRECTORY")
2241 # make sure everything gets to the backing store
2242 local list=$(comma_list $CLIENTS $(facet_host $SINGLEMDS) $(osts_nodes))
2243 do_nodes $list "sync; sleep 2; sync"
2245 do_nodes $list ls $tmp_file || \
2246 error "$SHARED_DIRECTORY is not a shared directory"
2249 run_e2fsck $(mdts_nodes) $MDTDEV
2254 for node in $(osts_nodes); do
2255 for dev in ${OSTDEVS[i]}; do
2256 local ostdb_opt=`eval echo $OSTDB_OPT`
2257 run_e2fsck $node $dev $ostidx "$ostdb_opt"
2258 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2259 ostidx=$((ostidx + 1))
2266 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2269 local rc=${PIPESTATUS[0]}
2270 [ $rc -le $FSCK_MAX_ERR ] || \
2271 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2272 echo "lfsck finished with rc=$rc"
2274 rm -rvf $MDSDB* $OSTDB* || true
2279 check_and_cleanup_lustre() {
2280 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2283 if [ "$SKIP_LFSCK" == "no" ]; then
2291 if is_mounted $MOUNT; then
2292 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2293 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2296 if [ "$I_UMOUNTED2" = "yes" ]; then
2297 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2300 if [ "$I_MOUNTED2" = "yes" ]; then
2301 cleanup_mount $MOUNT2
2304 if [ "$I_MOUNTED" = "yes" ]; then
2305 cleanupall -f || error "cleanup failed"
2317 while [ $NETWORK -eq 0 ]; do
2318 if ping -c 1 -w 3 $1 > /dev/null; then
2322 echo "waiting for $1, $((MAX - WAIT)) secs left"
2325 if [ $WAIT -gt $MAX ]; then
2326 echo "Network not available"
2332 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2343 # the sed converts spaces to commas, but leaves the last space
2344 # alone, so the line doesn't end with a comma.
2345 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2348 # list, excluded are the comma separated lists
2349 exclude_items_from_list () {
2355 for item in ${excluded//,/ }; do
2356 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2358 echo $(comma_list $list)
2361 # list, expand are the comma separated lists
2363 local list=${1//,/ }
2364 local expand=${2//,/ }
2367 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2368 echo $(comma_list $expanded)
2371 testslist_filter () {
2372 local script=$LUSTRE/tests/${TESTSUITE}.sh
2374 [ -f $script ] || return 0
2376 local start_at=$START_AT
2377 local stop_at=$STOP_AT
2379 local var=${TESTSUITE//-/_}_START_AT
2380 [ x"${!var}" != x ] && start_at=${!var}
2381 var=${TESTSUITE//-/_}_STOP_AT
2382 [ x"${!var}" != x ] && stop_at=${!var}
2384 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2385 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2386 /^'${start_at}'$/ {flag = 0}
2387 {if (flag == 1) print $0}
2388 /^'${stop_at}'$/ { flag = 1 }'
2392 (cd `dirname $1`; echo $PWD/`basename $1`)
2396 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
2397 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
2400 local count=${type}COUNT
2401 for ((i=1; i<=${!count}; i++)) do
2402 list="$list ${name}$i"
2404 echo $(comma_list $list)
2407 ##################################
2408 # Adaptive Timeouts funcs
2411 # only check mds, we assume at_max is the same on all nodes
2412 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2413 if [ $at_max -eq 0 ]; then
2423 # suppose that all ost-s has the same at_max set
2424 if [ $facet == "ost" ]; then
2425 do_facet ost1 "lctl get_param -n at_max"
2427 do_facet $facet "lctl get_param -n at_max"
2437 if [ $facet == "ost" ]; then
2438 for i in `seq $OSTCOUNT`; do
2439 do_facet ost$i "lctl set_param at_max=$at_max"
2442 elif [ $facet == "mds" ]; then
2443 for i in `seq $MDSCOUNT`; do
2444 do_facet mds$i "lctl set_param at_max=$at_max"
2447 do_facet $facet "lctl set_param at_max=$at_max"
2452 ##################################
2456 # OBD_FAIL_MDS_ALL_REQUEST_NET
2458 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2459 do_facet client "$1" || RC=$?
2460 do_facet $SINGLEMDS lctl set_param fail_loc=0
2465 # OBD_FAIL_MDS_ALL_REPLY_NET
2467 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2468 do_facet client "$@" || RC=$?
2469 do_facet $SINGLEMDS lctl set_param fail_loc=0
2473 drop_reint_reply() {
2474 # OBD_FAIL_MDS_REINT_NET_REP
2476 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2477 do_facet client "$@" || RC=$?
2478 do_facet $SINGLEMDS lctl set_param fail_loc=0
2483 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2485 do_facet ost1 lctl set_param fail_loc=0x214
2486 do_facet client "$1" || RC=$?
2487 do_facet client "sync"
2488 do_facet ost1 lctl set_param fail_loc=0
2492 drop_ldlm_cancel() {
2493 #define OBD_FAIL_LDLM_CANCEL 0x304
2495 do_facet client lctl set_param fail_loc=0x304
2496 do_facet client "$@" || RC=$?
2497 do_facet client lctl set_param fail_loc=0
2501 drop_bl_callback() {
2502 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2504 do_facet client lctl set_param fail_loc=0x305
2505 do_facet client "$@" || RC=$?
2506 do_facet client lctl set_param fail_loc=0
2511 #define OBD_FAIL_LDLM_REPLY 0x30c
2513 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2514 do_facet client "$@" || RC=$?
2515 do_facet $SINGLEMDS lctl set_param fail_loc=0
2523 echo "clearing fail_loc on $facet"
2524 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2527 set_nodes_failloc () {
2528 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2531 cancel_lru_locks() {
2532 $LCTL mark "cancel_lru_locks $1 start"
2533 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2534 $LCTL set_param -n $d=clear
2536 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2537 $LCTL mark "cancel_lru_locks $1 stop"
2542 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2543 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2544 echo "$DEFAULT_LRU_SIZE"
2549 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2552 lru_resize_disable()
2554 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2559 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2560 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2561 echo there is still data in page cache $FILE ?
2562 lctl get_param -n $FILE
2570 DEBUGSAVE="$(lctl get_param -n debug)"
2574 [ -n "$DEBUGSAVE" ] && \
2575 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
2580 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
2583 debug_size_restore() {
2584 [ -n "$DEBUG_SIZE_SAVED" ] && \
2585 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
2589 start_full_debug_logging() {
2594 local DEBUG_SIZE=150
2596 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
2597 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
2600 stop_full_debug_logging() {
2605 ##################################
2607 ##################################
2610 local TYPE=${TYPE:-"FAIL"}
2613 # do not dump logs if $1=false
2614 if [ "x$1" = "xfalse" ]; then
2619 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2621 # We need to dump the logs on all nodes
2623 gather_logs $(comma_list $(nodes_list))
2627 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2628 echo "$@" > $LOGDIR/err
2640 # use only if we are ignoring failures for this test, bugno required.
2641 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2642 # e.g. error_ignore 5494 "your message"
2644 local TYPE="IGNORE (bz$1)"
2650 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2655 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2656 [ "$TESTSUITELOG" ] && \
2657 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2660 build_test_filter() {
2661 EXCEPT="$EXCEPT $(testslist_filter)"
2663 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2667 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2668 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2669 [ "$EXCEPT_SLOW" ] && \
2670 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2671 for E in $EXCEPT $ALWAYS_EXCEPT; do
2672 eval EXCEPT_${E}=true
2674 for E in $EXCEPT_SLOW; do
2675 eval EXCEPT_SLOW_${E}=true
2677 for G in $GRANT_CHECK_LIST; do
2678 eval GCHECK_ONLY_${G}=true
2683 if [[ $1 = [a-z]* ]]; then
2690 # print a newline if the last test was skipped
2691 export LAST_SKIPPED=
2693 # Main entry into test-framework. This is called with the name and
2694 # description of a test. The name is used to find the function to run
2695 # the test using "test_$name".
2697 # This supports a variety of methods of specifying specific test to
2698 # run or not run. These need to be documented...
2703 export base=`basetest $1`
2704 if [ ! -z "$ONLY" ]; then
2706 if [ ${!testname}x != x ]; then
2707 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2708 run_one_logged $1 "$2"
2712 if [ ${!testname}x != x ]; then
2713 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2714 run_one_logged $1 "$2"
2722 if [ ${!testname}x != x ]; then
2724 TESTNAME=test_$1 skip "skipping excluded test $1"
2727 testname=EXCEPT_$base
2728 if [ ${!testname}x != x ]; then
2730 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2733 testname=EXCEPT_SLOW_$1
2734 if [ ${!testname}x != x ]; then
2736 TESTNAME=test_$1 skip "skipping SLOW test $1"
2739 testname=EXCEPT_SLOW_$base
2740 if [ ${!testname}x != x ]; then
2742 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2747 run_one_logged $1 "$2"
2758 module_loaded lnet || load_modules
2770 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2775 strace -o $TMP/$1.strace -ttt $*
2777 log "FINISHED: $*: rc $RC"
2782 # Set TEST_STATUS here; will be used for logging the result
2783 if [ -f $LOGDIR/err ]; then
2788 echo $TEST_STATUS " " $@
2792 FFREE=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filesfree | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2793 FTOTAL=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filestotal | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2794 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2798 echo -n "Resetting fail_loc on all nodes..."
2799 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2805 # Log a message (on all nodes) padded with "=" before and after.
2806 # Also appends a timestamp and prepends the testsuite name.
2809 EQUALS="===================================================================================================="
2811 msg="== ${TESTSUITE} $*"
2813 [[ $last != "=" && $last != " " ]] && msg="$msg "
2814 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
2815 # always include at least == after the message
2816 log "$msg== $(date +"%H:%M:%S (%s)")"
2820 # Run a single test function and cleanup after it.
2822 # This function should be run in a subshell so the test func can
2823 # exit() without stopping the whole script.
2829 export tdir=d0.${TESTSUITE}/d${base}
2830 export TESTNAME=test_$testnum
2831 local SAVE_UMASK=`umask`
2834 banner "test $testnum: $message"
2835 test_${testnum} || error "test_$testnum failed with $?"
2838 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2839 check_catastrophe || error "LBUG/LASSERT detected"
2840 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2848 # Wrapper around run_one to ensure:
2849 # - test runs in subshell
2850 # - output of test is saved to separate log file for error reporting
2851 # - test result is saved to data file
2854 local BEFORE=`date +%s`
2856 local name=${TESTSUITE}.test_${1}.test_log.$(hostname).log
2857 local test_log=$LOGDIR/$name
2861 log_sub_test_begin test_${1}
2862 (run_one $1 "$2") 2>&1 | tee $test_log
2863 local RC=${PIPESTATUS[0]}
2865 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
2866 echo "test_$1 returned $RC" | tee $LOGDIR/err
2868 duration=$((`date +%s` - $BEFORE))
2869 pass "(${duration}s)"
2870 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
2871 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
2873 if [ -f $LOGDIR/err ]; then
2874 $FAIL_ON_ERROR && exit $RC
2881 (cd `dirname $1`; echo $PWD/`basename $1`)
2885 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2886 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2891 export base=`basetest $1`
2892 [ "$CHECK_GRANT" == "no" ] && return 0
2894 testname=GCHECK_ONLY_${base}
2895 [ ${!testname}x == x ] && return 0
2897 echo -n "checking grant......"
2899 # write some data to sync client lost_grant
2900 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2901 for i in `seq $OSTCOUNT`; do
2902 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2903 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2904 count=1 > /dev/null 2>&1
2906 # sync all the data and make sure no pending data on server
2909 #get client grant and server grant
2911 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2912 client_grant=$((client_grant + $d))
2915 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2916 server_grant=$((server_grant + $d))
2919 # cleanup the check_grant file
2920 for i in `seq $OSTCOUNT`; do
2921 rm $DIR1/${tfile}_check_grant_$i
2924 #check whether client grant == server grant
2925 if [ $client_grant != $server_grant ]; then
2926 echo "failed: client:${client_grant} server: ${server_grant}"
2933 ########################
2939 ost=`echo $1 | awk -F_ '{print $3}'`
2940 if [ -z $ost ]; then
2941 ost=`echo $1 | sed 's/-osc.*//'`
2948 [ "$node" != "$(hostname)" ]
2954 for node in $(mdts_nodes); do
2955 remote_node $node && return 0
2962 [ "$CLIENTONLY" ] && return 0 || true
2963 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2968 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
2969 MSKIPPED=1 && return 1
2976 for node in $(osts_nodes) ; do
2977 remote_node $node && return 0
2984 [ "$CLIENTONLY" ] && return 0 || true
2985 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2990 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
2991 OSKIPPED=1 && return 1
2998 MGS=$(facet_host mgs)
2999 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3004 remote_mds_nodsh || remote_ost_nodsh || \
3005 $(single_local_node $(comma_list $(nodes_list)))
3011 for num in `seq $MDSCOUNT`; do
3012 MDSNODES="$MDSNODES $(facet_host mds$num)"
3014 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3020 remote_ost && remote_mds
3024 local OSTNODES=$(facet_host ost1)
3027 for num in `seq $OSTCOUNT`; do
3028 local myOST=$(facet_host ost$num)
3029 OSTNODES="$OSTNODES $myOST"
3031 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
3037 # FIXME. We need a list of clients
3038 local myNODES=$HOSTNAME
3041 # CLIENTS (if specified) contains the local client
3042 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3044 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3045 myNODES="$myNODES $(osts_nodes) $(mdts_nodes)"
3048 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3053 remote_nodes_list () {
3054 local rnodes=$(nodes_list)
3055 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3059 init_clients_lists () {
3060 # Sanity check: exclude the local client from RCLIENTS
3061 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3063 # Sanity check: exclude the dup entries
3064 rclients=$(for i in $rclients; do echo $i; done | sort -u)
3066 local clients="$SINGLECLIENT $HOSTNAME $rclients"
3068 # Sanity check: exclude the dup entries from CLIENTS
3069 # for those configs which has SINGLCLIENT set to local client
3070 clients=$(for i in $clients; do echo $i; done | sort -u)
3072 CLIENTS=`comma_list $clients`
3073 local -a remoteclients=($rclients)
3074 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3075 varname=CLIENT$((i + 2))
3076 eval $varname=${remoteclients[i]}
3079 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3082 get_random_entry () {
3085 rnodes=${rnodes//,/ }
3087 local -a nodes=($rnodes)
3088 local num=${#nodes[@]}
3089 local i=$((RANDOM * num * 2 / 65536))
3095 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3100 lctl get_param version | grep -q patchless
3104 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3109 echo $nodes | wc -w || true
3113 local nodes=$(osts_nodes)
3114 local osscount=$(get_node_count "$nodes")
3115 [ ! "$OSTCOUNT" = "$osscount" ]
3119 local nodes=$(mdts_nodes)
3120 local mdtcount=$(get_node_count "$nodes")
3121 [ ! "$MDSCOUNT" = "$mdtcount" ]
3124 generate_machine_file() {
3125 local nodes=${1//,/ }
3126 local machinefile=$2
3128 for node in $nodes; do
3129 echo $node >>$machinefile || \
3130 { echo "can not generate machinefile $machinefile" && return 1; }
3135 local file=$1/stripe
3137 $LFS getstripe -v $file || error
3141 setstripe_nfsserver () {
3144 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3145 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3147 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3149 do_nodev $nfsserver lfs setstripe "$@"
3152 check_runas_id_ret() {
3154 local myRUNAS_UID=$1
3155 local myRUNAS_GID=$2
3158 if [ -z "$myRUNAS" ]; then
3159 error_exit "myRUNAS command must be specified for check_runas_id"
3162 $myRUNAS krb5_login.sh || \
3163 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3165 mkdir $DIR/d0_runas_test
3167 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3168 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3169 rm -rf $DIR/d0_runas_test
3174 local myRUNAS_UID=$1
3175 local myRUNAS_GID=$2
3178 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3179 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3180 Please set RUNAS_ID to some UID which exists on MDS and client or
3181 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3184 # obtain the UID/GID for MPI_USER
3188 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3189 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3191 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3192 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3195 # obtain and cache Kerberos ticket-granting ticket
3196 refresh_krb5_tgt() {
3197 local myRUNAS_UID=$1
3198 local myRUNAS_GID=$2
3201 if [ -z "$myRUNAS" ]; then
3202 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3205 CLIENTS=${CLIENTS:-$HOSTNAME}
3206 do_nodes $CLIENTS "set -x
3207 if ! $myRUNAS krb5_login.sh; then
3208 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3213 # Run multiop in the background, but wait for it to print
3214 # "PAUSING" to its stdout before returning from this function.
3215 multiop_bg_pause() {
3216 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3220 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3223 echo "$MULTIOP_PROG $FILE v$ARGS"
3224 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3226 echo "TMPPIPE=${TMPPIPE}"
3227 read -t 60 multiop_output < $TMPPIPE
3228 if [ $? -ne 0 ]; then
3233 if [ "$multiop_output" != "PAUSING" ]; then
3234 echo "Incorrect multiop output: $multiop_output"
3249 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3255 inodes_available () {
3256 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3260 mdsrate_inodes_available () {
3261 echo $(($(inodes_available) - 1))
3264 # reset llite stat counters
3265 clear_llite_stats(){
3266 lctl set_param -n llite.*.stats 0
3269 # sum llite stat items
3270 calc_llite_stats() {
3271 local res=$(lctl get_param -n llite.*.stats |
3272 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3276 # reset osc stat counters
3278 lctl set_param -n osc.*.osc_stats 0
3281 # sum osc stat items
3283 local res=$(lctl get_param -n osc.*.osc_stats |
3284 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3289 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3292 calc_osc_kbytes () {
3293 df $MOUNT > /dev/null
3294 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3297 # save_lustre_params(node, parameter_mask)
3298 # generate a stream of formatted strings (<node> <param name>=<param value>)
3299 save_lustre_params() {
3301 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3304 # restore lustre parameters from input stream, produces by save_lustre_params
3305 restore_lustre_params() {
3309 while IFS=" =" read node name val; do
3310 do_node ${node//:/} "lctl set_param -n $name $val"
3314 check_catastrophe() {
3315 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3316 local C=$CATASTROPHE
3317 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3319 if [ $rnodes ]; then
3320 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3321 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3337 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3339 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3340 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3341 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3345 # CMD: determine mds index where directory inode presents
3348 local file=$dir/f0.get_mds_dir_tmpfile
3353 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3354 local -a oldused=($iused)
3356 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3358 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3359 local -a newused=($iused)
3362 for ((i=0; i<${#newused[@]}; i++)); do
3363 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3369 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3372 mdsrate_cleanup () {
3374 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3379 delayed_recovery_enabled () {
3380 local var=${SINGLEMDS}_svc
3381 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3384 ########################
3386 convert_facet2label() {
3389 if [ x$facet = xost ]; then
3393 local varsvc=${facet}_svc
3395 if [ -n ${!varsvc} ]; then
3398 error "No lablel for $facet!"
3402 get_clientosc_proc_path() {
3408 get_lustre_version () {
3409 local node=${1:-"mds"}
3410 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3413 get_mds_version_major () {
3414 local version=$(get_lustre_version mds)
3415 echo $version | awk -F. '{print $1}'
3418 get_mds_version_minor () {
3419 local version=$(get_lustre_version mds)
3420 echo $version | awk -F. '{print $2}'
3423 get_mdtosc_proc_path() {
3425 local major=$(get_mds_version_major)
3426 local minor=$(get_mds_version_minor)
3427 if [ $major -le 1 -a $minor -le 8 ] ; then
3430 echo "${ost}-osc-MDT0000"
3434 get_osc_import_name() {
3437 local label=$(convert_facet2label $ost)
3439 if [ "$facet" == "mds" ]; then
3440 get_mdtosc_proc_path $label
3444 get_clientosc_proc_path $label
3448 wait_import_state () {
3454 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3455 while [ "${CONN_STATE}" != "${expected}" ]; do
3456 if [ "${expected}" == "DISCONN" ]; then
3457 # for disconn we can check after proc entry is removed
3458 [ "x${CONN_STATE}" == "x" ] && return 0
3459 # with AT we can have connect request timeout ~ reconnect timeout
3460 # and test can't see real disconnect
3461 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3463 # disconnect rpc should be wait not more obd_timeout
3464 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3465 error "can't put import for $CONN_PROC into ${expected} state" && return 1
3467 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3471 log "$CONN_PROC now in ${CONN_STATE} state"
3475 wait_osc_import_state() {
3479 local ost=$(get_osc_import_name $facet $ost_facet)
3484 CONN_PROC="osc.${ost}.ost_server_uuid"
3485 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3486 while [ "${CONN_STATE}" != "${expected}" ]; do
3487 if [ "${expected}" == "DISCONN" ]; then
3488 # for disconn we can check after proc entry is removed
3489 [ "x${CONN_STATE}" == "x" ] && return 0
3490 # with AT we can have connect request timeout ~ reconnect timeout
3491 # and test can't see real disconnect
3492 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3494 # disconnect rpc should be wait not more obd_timeout
3495 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3496 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3498 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3502 log "${ost_facet} now in ${CONN_STATE} state"
3505 get_clientmdc_proc_path() {
3513 # Add paths to lustre tests for 32 and 64 bit systems.
3514 local RPATH="$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
3515 do_nodesv $list "PATH=$RPATH sh rpc.sh $@ "
3518 wait_clients_import_state () {
3524 local label=$(convert_facet2label $facet)
3527 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3528 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3529 *) error "unknown facet!" ;;
3532 if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
3533 error "import is not in ${expected} state"
3542 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
3543 $LCTL get_param obdfilter.*.kbytesavail))
3544 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
3545 $LCTL get_param -n obdfilter.*.tot_granted))
3546 for ((i=0; i<${#AVAILA[@]}; i++)); do
3547 local -a AVAIL1=(${AVAILA[$i]//=/ })
3548 GRANT=$((${GRANTA[$i]}/1024))
3549 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
3550 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
3556 do_facet mgs lctl pool_list $1
3560 local fsname=${1%%.*}
3561 local poolname=${1##$fsname.}
3563 do_facet mgs lctl pool_new $1
3565 # get param should return err unless pool is created
3566 [[ $RC -ne 0 ]] && return $RC
3568 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3569 2>/dev/null || echo foo" "" || RC=1
3570 if [[ $RC -eq 0 ]]; then
3573 error "pool_new failed $1"
3578 add_pool_to_list () {
3579 local fsname=${1%%.*}
3580 local poolname=${1##$fsname.}
3582 local listvar=${fsname}_CREATED_POOLS
3583 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
3586 remove_pool_from_list () {
3587 local fsname=${1%%.*}
3588 local poolname=${1##$fsname.}
3590 local listvar=${fsname}_CREATED_POOLS
3591 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
3594 destroy_pool_int() {
3596 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
3597 awk '$1 !~ /^Pool:/ {print $1}')
3598 for ost in $OSTS; do
3599 do_facet mgs lctl pool_remove $1 $ost
3601 do_facet mgs lctl pool_destroy $1
3604 # <fsname>.<poolname> or <poolname>
3606 local fsname=${1%%.*}
3607 local poolname=${1##$fsname.}
3609 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3613 pool_list $fsname.$poolname || return $?
3615 destroy_pool_int $fsname.$poolname
3617 [[ $RC -ne 0 ]] && return $RC
3619 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3620 2>/dev/null || echo foo" "foo" || RC=1
3622 if [[ $RC -eq 0 ]]; then
3623 remove_pool_from_list $fsname.$poolname
3625 error "destroy pool failed $1"
3631 local fsname=${1:-$FSNAME}
3633 local listvar=${fsname}_CREATED_POOLS
3637 [ x${!listvar} = x ] && return 0
3639 echo destroy the created pools: ${!listvar}
3640 for poolname in ${!listvar//,/ }; do
3641 destroy_pool $fsname.$poolname
3646 local fsname=${1:-$FSNAME}
3648 destroy_pools $fsname
3654 local ts=$(date +%s)
3656 # bug 20237, comment 11
3657 # It would also be useful to provide the option
3658 # of writing the file to an NFS directory so it doesn't need to be copied.
3661 [ -f $LOGDIR/shared ] && docp=false
3663 # dump lustre logs, dmesg
3665 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
3667 echo "Dumping lctl log to ${prefix}.*.${suffix}"
3669 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
3670 echo "Dumping logs only on local client."
3671 $LCTL dk > ${prefix}.debug_log.$(hostname).${suffix}
3672 dmesg > ${prefix}.dmesg.$(hostname).${suffix}
3677 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname).${suffix};
3678 dmesg > ${prefix}.dmesg.\\\$(hostname).${suffix}"
3679 if [ ! -f $LOGDIR/shared ]; then
3680 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
3683 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
3684 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
3690 local list=${1:-$(comma_list $(nodes_list))}
3692 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3704 for i in $(seq 0 $num_mntpts); do
3705 cmd="ls -laf ${mntpt_root}$i/$dir"
3711 for pid in $pids; do
3718 # target_start_and_reset_recovery_timer()
3719 # service_time = at_est2timeout(service_time);
3720 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3721 # INITIAL_CONNECT_TIMEOUT);
3722 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3723 #define CONNECTION_SWITCH_INC 1
3724 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3725 #define CONNECTION_SWITCH_MIN 5U
3727 max_recovery_time () {
3728 local init_connect_timeout=$(( TIMEOUT / 20 ))
3729 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3731 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3736 get_clients_mount_count () {
3737 local clients=${CLIENTS:-`hostname`}
3739 # we need to take into account the clients mounts and
3740 # exclude mds/ost mounts if any;
3741 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
3745 PROC_CLI="srpc_info"
3753 if [ $M -lt $N ]; then
3757 while [ $N -le $M ]; do
3767 calc_connection_cnt() {
3770 # MDT->MDT = 2 * C(M, 2)
3774 comb_m2=$(combination $MDSCOUNT 2)
3776 local num_clients=$(get_clients_mount_count)
3778 local cnt_mdt2mdt=$((comb_m2 * 2))
3779 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
3780 local cnt_cli2ost=$((num_clients * OSTCOUNT))
3781 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
3782 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
3783 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
3784 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
3798 local cmd="$tgt.srpc.flavor"
3800 if [ $net == "any" ]; then
3805 if [ $dir != "any" ]; then
3810 log "Setting sptlrpc rule: $cmd"
3811 do_facet mgs "$LCTL conf_param $cmd"
3820 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
3821 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
3823 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
3825 if [ "x$bulkspec" != "x" ]; then
3826 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
3828 if [ "x$algs" != "x" ]; then
3829 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
3831 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
3832 if [ $bulk == "bulkn" ]; then
3833 bulk_count=`echo "$output" | grep "bulk flavor" \
3834 | grep "null/null" | wc -l`
3835 elif [ $bulk == "bulki" ]; then
3836 bulk_count=`echo "$output" | grep "bulk flavor" \
3837 | grep "/null" | grep -v "null/" | wc -l`
3839 bulk_count=`echo "$output" | grep "bulk flavor" \
3840 | grep -v "/null" | grep -v "null/" | wc -l`
3844 [ $bulk_count -lt $count ] && count=$bulk_count
3855 local clients=${CLIENTS:-`hostname`}
3857 for c in ${clients//,/ }; do
3858 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
3859 tmpcnt=`count_flvr "$output" $flavor`
3860 cnt=$((cnt + tmpcnt))
3870 local clients=${CLIENTS:-`hostname`}
3872 for c in ${clients//,/ }; do
3873 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
3874 tmpcnt=`count_flvr "$output" $flavor`
3875 cnt=$((cnt + tmpcnt))
3885 if [ $MDSCOUNT -le 1 ]; then
3890 for num in `seq $MDSCOUNT`; do
3891 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
3892 tmpcnt=`count_flvr "$output" $flavor`
3893 cnt=$((cnt + tmpcnt))
3903 for num in `seq $MDSCOUNT`; do
3904 output=`do_facet mds$num lctl get_param -n osc.*OST*-osc-MDT*.$PROC_CLI 2>/dev/null`
3905 tmpcnt=`count_flvr "$output" $flavor`
3906 cnt=$((cnt + tmpcnt))
3915 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
3916 count_flvr "$output" $flavor
3921 local dir=$1 # from to
3922 local flavor=$2 # flavor expected
3925 if [ $dir == "cli2mdt" ]; then
3926 res=`flvr_cnt_cli2mdt $flavor`
3927 elif [ $dir == "cli2ost" ]; then
3928 res=`flvr_cnt_cli2ost $flavor`
3929 elif [ $dir == "mdt2mdt" ]; then
3930 res=`flvr_cnt_mdt2mdt $flavor`
3931 elif [ $dir == "mdt2ost" ]; then
3932 res=`flvr_cnt_mdt2ost $flavor`
3933 elif [ $dir == "all2ost" ]; then
3934 res1=`flvr_cnt_mdt2ost $flavor`
3935 res2=`flvr_cnt_cli2ost $flavor`
3936 res=$((res1 + res2))
3937 elif [ $dir == "all2mdt" ]; then
3938 res1=`flvr_cnt_mdt2mdt $flavor`
3939 res2=`flvr_cnt_cli2mdt $flavor`
3940 res=$((res1 + res2))
3941 elif [ $dir == "all2all" ]; then
3942 res1=`flvr_cnt_mdt2ost $flavor`
3943 res2=`flvr_cnt_cli2ost $flavor`
3944 res3=`flvr_cnt_mdt2mdt $flavor`
3945 res4=`flvr_cnt_cli2mdt $flavor`
3946 res=$((res1 + res2 + res3 + res4))
3954 local dir=$1 # from to
3955 local flavor=$2 # flavor expected
3956 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
3960 for ((i=0;i<20;i++)); do
3961 echo -n "checking..."
3962 res=$(do_check_flavor $dir $flavor)
3963 if [ $res -eq $expect ]; then
3964 echo "found $res $flavor connections of $dir, OK"
3967 echo "found $res $flavor connections of $dir, not ready ($expect)"
3972 echo "Error checking $flavor of $dir: expect $expect, actual $res"
3976 restore_to_default_flavor()
3978 local proc="mgs.MGS.live.$FSNAME"
3980 echo "restoring to default flavor..."
3982 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3984 # remove all existing rules if any
3985 if [ $nrule -ne 0 ]; then
3986 echo "$nrule existing rules"
3987 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
3988 echo "remove rule: $rule"
3989 spec=`echo $rule | awk -F = '{print $1}'`
3990 do_facet mgs "$LCTL conf_param $spec="
3994 # verify no rules left
3995 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3996 [ $nrule -ne 0 ] && error "still $nrule rules left"
3998 # wait for default flavor to be applied
3999 # currently default flavor for all connections are 'null'
4000 wait_flavor all2all null
4001 echo "now at default flavor settings"
4006 local flavor=${1:-null}
4008 echo "setting all flavor to $flavor"
4010 # FIXME need parameter to this fn
4011 # and remove global vars
4012 local cnt_all2all=$(calc_connection_cnt all2all)
4014 local res=$(do_check_flavor all2all $flavor)
4015 if [ $res -eq $cnt_all2all ]; then
4016 echo "already have total $res $flavor connections"
4020 echo "found $res $flavor out of total $cnt_all2all connections"
4021 restore_to_default_flavor
4023 [[ $flavor = null ]] && return 0
4025 set_rule $FSNAME any any $flavor
4026 wait_flavor all2all $flavor
4032 # Checking for shared logdir
4033 if [ ! -d $dir ]; then
4034 # Not found. Create local logdir
4037 touch $dir/node.$(hostname).yml
4042 check_write_access() {
4044 for node in $(nodes_list); do
4045 if [ ! -f "$dir/node.${node}.yml" ]; then
4046 # Logdir not accessible/writable from this node.
4054 if [[ -n $YAML_LOG ]]; then
4057 export YAML_LOG=${LOGDIR}/results.yml
4061 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $LOGDIR
4062 if check_write_access $LOGDIR; then
4063 touch $LOGDIR/shared
4064 echo "Logging to shared log directory: $LOGDIR"
4066 echo "Logging to local directory: $LOGDIR"
4069 yml_nodes_file $LOGDIR
4070 yml_results_file >> $YAML_LOG
4074 yml_log_test $1 >> $YAML_LOG
4078 yml_log_test_status $@ >> $YAML_LOG
4081 log_sub_test_begin() {
4082 yml_log_sub_test_begin $@ >> $YAML_LOG
4085 log_sub_test_end() {
4086 yml_log_sub_test_end $@ >> $YAML_LOG
4092 local devname=$(basename $1)
4093 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4094 # loop devices aren't in /proc/partitions
4095 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4097 size=$(($size / 1024 / 1024)) # Gb
4099 local partial_arg=""
4100 # Run in partial (fast) mode if the size
4101 # of a partition > 10 GB
4102 [ $size -gt 10 ] && partial_arg="-p"
4104 llverdev --force $partial_arg $dev
4107 remove_mdt_files() {
4112 local mntpt=${MOUNT%/*}/$facet
4114 echo "removing files from $mdtdev on $facet: $files"
4115 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4118 rm $mntpt/ROOT/$f || { rc=$?; break; }
4120 umount -f $mntpt || return $?
4124 duplicate_mdt_files() {
4129 local mntpt=${MOUNT%/*}/$facet
4131 echo "duplicating files on $mdtdev on $facet: $files"
4132 mkdir -p $mntpt || return $?
4133 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4143 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4144 pushd $mntpt/ROOT > /dev/null || return $?
4147 touch $f.bad || return $?
4148 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4150 [ $rc -eq 0 ] || return $rc
4151 setfattr --restore $tmp || return $?