2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'print_summary && 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}
14 #export PDSH="pdsh -S -Rssh -w"
16 # eg, assert_env LUSTRE MDSNODES OSTNODES CLIENTS
20 if [ -z "${!name}" ]; then
21 echo "$0: $name must be set"
25 [ $failed ] && exit 1 || true
30 [[ $DIR/ = $MOUNT/* ]] || \
31 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
32 [[ $DIR1/ = $MOUNT1/* ]] || \
33 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
34 [[ $DIR2/ = $MOUNT2/* ]] || \
35 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
37 [ -n "$failed" ] && exit 99 || true
41 echo "usage: $0 [-r] [-f cfgfile]"
48 [ "$TESTSUITE" == "lfscktest" ] && return 0
49 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
50 local form="%-13s %-17s %s\n"
51 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
52 echo "------------------------------------------------------------------------------------"
53 for O in $TESTSUITE_LIST; do
56 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
59 local log=${TMP}/${o}.log
60 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
61 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
62 [ "${!O}" = "done" ] && \
63 printf "$form" "Done" "$O" "E=$skipped" && \
64 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
68 for O in $TESTSUITE_LIST; do
69 [ "${!O}" = "no" ] && \
70 printf "$form" "Skipped" "$O" ""
73 for O in $TESTSUITE_LIST; do
74 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
75 printf "$form" "UNFINISHED" "$O" ""
80 export LUSTRE=`absolute_path $LUSTRE`
81 export TESTSUITE=`basename $0 .sh`
82 export TEST_FAILED=false
84 export MKE2FS=${MKE2FS:-mke2fs}
85 export DEBUGFS=${DEBUGFS:-debugfs}
86 export TUNE2FS=${TUNE2FS:-tune2fs}
87 export E2LABEL=${E2LABEL:-e2label}
88 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
89 export E2FSCK=${E2FSCK:-e2fsck}
91 #[ -d /r ] && export ROOT=${ROOT:-/r}
92 export TMP=${TMP:-$ROOT/tmp}
93 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
94 export HOSTNAME=${HOSTNAME:-`hostname`}
95 if ! echo $PATH | grep -q $LUSTRE/utils; then
96 export PATH=$PATH:$LUSTRE/utils
98 if ! echo $PATH | grep -q $LUSTRE/test; then
99 export PATH=$PATH:$LUSTRE/tests
101 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mdsrate"}
102 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
103 if ! echo $PATH | grep -q $LUSTRE/test/racer; then
104 export PATH=$PATH:$LUSTRE/tests/racer
106 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
107 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
108 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
109 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
110 [ ! -f "$LFS" ] && export LFS=$(which lfs)
111 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
112 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
113 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
114 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
115 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
116 export FSYTPE=${FSTYPE:-"ldiskfs"}
117 export NAME=${NAME:-local}
120 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
122 if [ "$ACCEPTOR_PORT" ]; then
123 export PORT_OPT="--port $ACCEPTOR_PORT"
126 # Paths on remote nodes, if different
127 export RLUSTRE=${RLUSTRE:-$LUSTRE}
128 export RPWD=${RPWD:-$PWD}
129 export I_MOUNTED=${I_MOUNTED:-"no"}
133 while getopts "rvwf:" opt $*; do
136 r) REFORMAT=--reformat;;
138 w) WRITECONF=writeconf;;
143 shift $((OPTIND - 1))
146 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
152 *) EXT=".ko"; USE_QUOTA=yes;;
158 BASE=`basename $module $EXT`
159 lsmod | grep -q ${BASE} || \
160 if [ -f ${LUSTRE}/${module}${EXT} ]; then
161 insmod ${LUSTRE}/${module}${EXT} $@
163 # must be testing a "make install" or "rpm" installation
169 if [ -n "$MODPROBE" ]; then
173 if [ "$HAVE_MODULES" = true ]; then
179 echo Loading modules from $LUSTRE
180 load_module ../lnet/libcfs/libcfs
181 [ "$PTLDEBUG" ] && lctl set_param debug=$PTLDEBUG
182 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug=${SUBSYSTEM# }
184 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
185 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
186 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
187 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
188 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
189 echo "lnet options: '$LNETOPTS'"
190 # note that insmod will ignore anything in modprobe.conf
191 load_module ../lnet/lnet/lnet $LNETOPTS
192 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
193 load_module ../lnet/klnds/$LNETLND
194 load_module lvfs/lvfs
195 load_module obdclass/obdclass
196 load_module ptlrpc/ptlrpc
197 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
202 if [ -z "$CLIENTONLY" ] && [ -z "$CLIENTMODSONLY" ]; then
205 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
206 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
207 load_module lvfs/fsfilt_$FSTYPE
209 load_module obdfilter/obdfilter
212 load_module llite/lustre
213 load_module llite/llite_lloop
214 rm -f $TMP/ogdb-$HOSTNAME
216 [ -d /r ] && OGDB="/r/tmp"
217 $LCTL modules > $OGDB/ogdb-$HOSTNAME
218 # 'mount' doesn't look in $PATH, just sbin
219 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
223 if [ `uname -r | cut -c 3` -eq 4 ]; then
231 MODULES=$($LCTL modules | awk '{ print $2 }')
232 while [ -n "$MODULES" ]; do
234 $RMMOD $MODULES >/dev/null 2>&1 || true
235 MODULES=$($LCTL modules | awk '{ print $2 }')
236 if [ -z "$MODULES" ]; then
240 echo "waiting, $((MAX - WAIT)) secs left"
242 if [ $WAIT -eq $MAX ]; then
243 echo "LNET modules $MODULES will not unload"
250 unload_dep_module() {
252 #libcfs 107852 17 llite_lloop,lustre,obdfilter,ost,...
254 local DEPS=$(lsmod | awk '($1 == "'$MODULE'") { print $4 }' | tr ',' ' ')
255 for SUBMOD in $DEPS; do
256 unload_dep_module $SUBMOD
258 [ "$MODULE" = "libcfs" ] && $LCTL dk $TMP/debug || true
259 $RMMOD $MODULE || true
263 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
264 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
265 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
266 echo "$LEAK_LUSTRE" 1>&2
267 echo "$LEAK_PORTALS" 1>&2
268 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
269 echo "Memory leaks detected"
270 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
276 wait_exit_ST client # bug 12845
278 lsmod | grep libcfs > /dev/null && $LCTL dl
279 [ -z "$CLIENTONLY" ] && unload_dep_module $FSTYPE
280 unload_dep_module libcfs
282 local MODULES=$($LCTL modules | awk '{ print $2 }')
283 if [ -n "$MODULES" ]; then
284 echo "Modules still loaded: "
286 if [ "$(lctl dl)" ]; then
287 echo "Lustre still loaded"
292 echo "Lustre stopped but LNET is still loaded, waiting..."
293 wait_for_lnet || return 3
298 check_mem_leak || return 254
300 echo "modules unloaded."
308 local dev=${facet}_dev
309 local opt=${facet}_opt
310 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
311 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
313 if [ $RC -ne 0 ]; then
314 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
315 echo "Start of ${!dev} on ${facet} failed ${RC}"
317 do_facet ${facet} "lctl set_param debug=$PTLDEBUG; \
318 lctl set_param subsystem_debug=${SUBSYSTEM# }; \
319 lctl set_param debug_mb=${DEBUG_SIZE}; \
322 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
323 [ -z "$label" ] && echo no label for ${!dev} && exit 1
324 eval export ${facet}_svc=${label}
325 echo Started ${label}
330 # start facet device options
336 eval export ${facet}_dev=${device}
337 eval export ${facet}_opt=\"$@\"
338 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
348 HOST=`facet_active_host $facet`
349 [ -z $HOST ] && echo stop: no host for $facet && return 0
351 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
352 if [ ${running} -ne 0 ]; then
353 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
354 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
357 # umount should block, but we should wait for unrelated obd's
358 # like the MGS or MGC to also stop.
360 wait_exit_ST ${facet}
367 # Only supply -o to mount if we have options
368 if [ -n "$MOUNTOPT" ]; then
369 OPTIONS="-o $MOUNTOPT"
371 local device=$MGSNID:/$FSNAME
372 if [ -z "$mnt" -o -z "$FSNAME" ]; then
373 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
377 echo "Starting client: $client: $OPTIONS $device $mnt"
378 do_node $client mkdir -p $mnt
379 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
380 do_node $client "lctl set_param debug=$PTLDEBUG;
381 lctl set_param subsystem_debug=${SUBSYSTEM# };
382 lctl set_param debug_mb=${DEBUG_SIZE}"
395 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
396 if [ $running -ne 0 ]; then
397 echo "Stopping client $client $mnt (opts:$force)"
398 do_node $client lsof -t $mnt || need_kill=no
399 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
400 pids=$(do_node $client lsof -t $mnt | sort -u);
401 if [ -n $pids ]; then
402 do_node $client kill -9 $pids || true
406 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
407 if [ $busy -ne 0 ] ; then
408 echo "$mnt is still busy, wait one second" && sleep 1
409 do_node $client umount $force $mnt
414 # mount clients if not mouted
415 zconf_mount_clients() {
420 # Only supply -o to mount if we have options
421 if [ -n "$MOUNTOPT" ]; then
422 OPTIONS="-o $MOUNTOPT"
424 local device=$MGSNID:/$FSNAME
425 if [ -z "$mnt" -o -z "$FSNAME" ]; then
426 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
430 echo "Starting client $clients: $OPTIONS $device $mnt"
431 do_nodes $clients "mount | grep $mnt || { mkdir -p $mnt && mount -t lustre $OPTIONS $device $mnt || false; }"
433 echo "Started clients $clients: "
434 do_nodes $clients "mount | grep $mnt"
436 do_nodes $clients "sysctl -w lnet.debug=$PTLDEBUG;
437 sysctl -w lnet.subsystem_debug=${SUBSYSTEM# };
438 sysctl -w lnet.debug_mb=${DEBUG_SIZE};"
443 zconf_umount_clients() {
450 echo "Stopping clients: $clients $mnt (opts:$force)"
451 do_nodes $clients "set -x; running=\\\$(grep -c $mnt' ' /proc/mounts)
452 if [ \\\$running -ne 0 ] ; then
453 echo Stopping client \\\$(hostname) client $mnt opts:$force
454 lsof -t $mnt || need_kill=no
455 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
456 pids=\\\$(lsof -t $mnt | sort -u);
457 if [ -n \\\$pids ]; then
461 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy")
462 if [ \\\$busy -ne 0 ] ; then
463 echo "$mnt is still busy, wait one second" && sleep 1
471 if [ "$FAILURE_MODE" = HARD ]; then
472 $POWER_DOWN `facet_active_host $facet`
474 elif [ "$FAILURE_MODE" = SOFT ]; then
481 if [ "$FAILURE_MODE" = HARD ]; then
482 $POWER_UP `facet_active_host $facet`
490 if [ "$FAILURE_MODE" = HARD ]; then
495 # recovery-scale functions
496 check_progs_installed () {
501 do_nodes $clients "set -x ; PATH=:$PATH status=true; for prog in $progs; do
502 which \\\$prog || { echo \\\$prog missing on \\\$(hostname) && status=false; }
507 start_client_load() {
508 local list=(${1//,/ })
511 local numloads=${#CLIENT_LOADS[@]}
512 local testnum=$((nodenum % numloads))
514 do_node ${list[nodenum]} "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
515 BREAK_ON_ERROR=$BREAK_ON_ERROR \
516 END_RUN_FILE=$END_RUN_FILE \
517 LOAD_PID_FILE=$LOAD_PID_FILE \
518 TESTSUITELOG=$TESTSUITELOG \
519 run_${CLIENT_LOADS[testnum]}.sh" &
520 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
521 log "Started client load: ${CLIENT_LOADS[testnum]} on ${list[nodenum]}"
523 eval export ${list[nodenum]}_load=${CLIENT_LOADS[testnum]}
527 start_client_loads () {
528 local clients=(${1//,/ })
530 for ((num=0; num < ${#clients[@]}; num++ )); do
531 start_client_load $1 $num
535 # only for remote client
536 check_client_load () {
538 local var=${client}_load
540 local TESTLOAD=run_${!var}.sh
542 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
544 check_catastrophe $client || return 2
546 # see if the load is still on the client
549 while [ $RC = 254 -a $tries -gt 0 ]; do
553 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
558 if [ $RC = 254 ]; then
559 echo "got a return status of $RC from do_node while checking (i.e. with 'ps') the client load on the remote system"
560 # see if we can diagnose a bit why this is
565 check_client_loads () {
566 local clients=${1//,/ }
570 for client in $clients; do
571 check_client_load $client
573 if [ "$rc" != 0 ]; then
574 log "Client load failed on node $client, rc=$rc"
579 # End recovery-scale functions
581 # verify that lustre actually cleaned up properly
583 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
584 error "LBUG/LASSERT detected"
585 BUSY=`dmesg | grep -i destruct || true`
588 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
592 check_mem_leak || exit 204
594 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
595 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
597 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
598 echo "$0: modules still loaded..." 1>&2
605 wait_delete_completed () {
606 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
607 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
611 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
613 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
614 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
615 [ "$TOTAL" -eq "$TOTALPREV" ] && break
616 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
620 echo "Delete completed."
625 check_network "$HOST" 900
626 while ! do_node $HOST "ls -d $LUSTRE " > /dev/null; do sleep 5; done
631 HOST=`facet_active_host $facet`
635 wait_mds_recovery_done () {
636 local timeout=`do_facet mds lctl get_param -n timeout`
637 #define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
638 # as we are in process of changing obd_timeout in different ways
639 # let's set MAX longer than that
640 MAX=$(( timeout * 4 ))
642 while [ $WAIT -lt $MAX ]; do
643 STATUS=`do_facet mds "lctl get_param -n mds.*-MDT*.recovery_status | grep status"`
644 echo $STATUS | grep COMPLETE && return 0
647 echo "Waiting $(($MAX - $WAIT)) secs for MDS recovery done"
649 echo "MDS recovery not done in $MAX sec"
659 # conf-sanity 31 takes a long time cleanup
660 while [ $WAIT -lt 300 ]; do
661 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
662 [ -z "${running}" ] && return 0
663 echo "waited $WAIT for${running}"
664 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
666 WAIT=$((WAIT + INTERVAL))
668 echo "service didn't stop after $WAIT seconds. Still running:"
673 wait_remote_prog () {
679 [ "$PDSH" = "no_dsh" ] && return 0
681 while [ $WAIT -lt $2 ]; do
682 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
683 [ -z "${running}" ] && return 0 || true
684 echo "waited $WAIT for: "
686 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
688 WAIT=$((WAIT + INTERVAL))
690 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
691 [ -z "$pids" ] && return 0
692 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
694 cat /proc/${pid}/status || true
695 cat /proc/${pid}/wchan || true
706 # not every config has many clients
707 if [ -n "$CLIENTS" ]; then
708 $PDSH $CLIENTS "df $MOUNT" > /dev/null
710 df $MOUNT > /dev/null
715 uname -n >> $MOUNT/recon
716 if [ -z "$CLIENTS" ]; then
717 df $MOUNT; uname -n >> $MOUNT/recon
719 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
721 echo Connected clients:
723 ls -l $MOUNT/recon > /dev/null
730 echo "Failing $facet on node `facet_active_host $facet`"
731 shutdown_facet $facet
732 [ -n "$sleep_time" ] && sleep $sleep_time
736 RECOVERY_START_TIME=`date +%s`
737 echo "df pid is $DFPID"
739 TO=`facet_active_host $facet`
740 echo "Failover $facet to $TO"
742 mount_facet $facet || error "Restart of $facet failed"
753 local svc=${facet}_svc
754 do_facet $facet $LCTL --device %${!svc} readonly
755 do_facet $facet $LCTL --device %${!svc} notransno
756 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
757 $LCTL mark "local REPLAY BARRIER on ${!svc}"
760 replay_barrier_nodf() {
761 local facet=$1 echo running=${running}
763 local svc=${facet}_svc
764 echo Replay barrier on ${!svc}
765 do_facet $facet $LCTL --device %${!svc} readonly
766 do_facet $facet $LCTL --device %${!svc} notransno
767 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
768 $LCTL mark "local REPLAY BARRIER on ${!svc}"
772 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
773 do_facet mds "lctl set_param -n mds.${mds_svc}.evict_client $UUID"
777 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
778 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
782 facet_failover $* || error "failover: $?"
783 df $MOUNT || error "post-failover df: $?"
788 facet_failover $facet
795 mount_facet $facet -o abort_recovery
796 df $MOUNT || echo "first df failed: $?"
798 df $MOUNT || error "post-failover df: $?"
802 echo There is no lmc. This is mountconf, baby.
807 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
808 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
814 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
820 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
821 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
822 if [ -z "$ID" ]; then
823 echo "Could not get a ptl id for $1..."
832 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
839 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
840 if type __h2elan >/dev/null 2>&1; then
843 ID=`echo $1 | sed 's/[^0-9]*//g'`
851 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
852 ID=`echo $1 | sed 's/[^0-9]*//g'`
859 h2name_or_ip "$1" "o2ib"
866 [ "$facet" == client ] && echo -n $HOSTNAME && return
867 varname=${facet}_HOST
868 if [ -z "${!varname}" ]; then
869 if [ "${facet:0:3}" == "ost" ]; then
870 eval ${facet}_HOST=${ost_HOST}
878 local activevar=${facet}active
880 if [ -f $TMP/${facet}active ] ; then
881 source $TMP/${facet}active
885 if [ -z "$active" ] ; then
892 facet_active_host() {
894 local active=`facet_active $facet`
895 if [ "$facet" == client ]; then
898 echo `facet_host $active`
904 failover=${facet}failover
905 host=`facet_host $failover`
906 [ -z "$host" ] && return
907 curactive=`facet_active $facet`
908 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
909 eval export ${facet}active=$facet
911 eval export ${facet}active=$failover
913 # save the active host for this facet
914 activevar=${facet}active
915 echo "$activevar=${!activevar}" > $TMP/$activevar
922 if [ "$HOST" = "$HOSTNAME" ]; then
924 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
925 echo "cannot run remote command on $HOST with $myPDSH"
929 echo "CMD: $HOST $@" >&2
930 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
933 if [ "$myPDSH" = "rsh" ]; then
934 # we need this because rsh does not return exit code of an executed command
935 local command_status="$TMP/cs"
936 rsh $HOST ":> $command_status"
937 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
938 cd $RPWD; sh -c \"$@\") ||
939 echo command failed >$command_status"
940 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
943 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
944 return ${PIPESTATUS[0]}
947 single_local_node () {
948 [ "$1" = "$HOSTNAME" ]
955 if $(single_local_node $rnodes); then
960 # This is part from do_node
963 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
964 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
967 echo "CMD: $rnodes $@" >&2
968 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
971 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/\w+:\s//g"
972 return ${PIPESTATUS[0]}
978 HOST=`facet_active_host $facet`
979 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
986 # make sure its not already running
988 rm -f $TMP/${facet}active
989 do_facet ${facet} $MKFS $*
995 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
996 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1004 # make sure we are using the primary server, so test-framework will
1005 # be able to clean up properly.
1006 activemds=`facet_active mds`
1007 if [ $activemds != "mds" ]; then
1011 # assume client mount is local
1012 grep " $MOUNT " /proc/mounts && zconf_umount $HOSTNAME $MOUNT $*
1013 grep " $MOUNT2 " /proc/mounts && zconf_umount $HOSTNAME $MOUNT2 $*
1015 if [ -n "$CLIENTS" ]; then
1016 zconf_umount_clients $CLIENTS $MOUNT "$*" || true
1017 [ -n "$MOUNT2" ] && zconf_umount_clients $CLIENTS $MOUNT2 "$*" || true
1020 [ "$CLIENTONLY" ] && return
1021 # The add fn does rm ${facet}active file, this would be enough
1022 # if we use do_facet <facet> only after the facet added, but
1023 # currently we use do_facet mds in local.sh
1025 rm -f ${TMP}/mdsactive
1026 for num in `seq $OSTCOUNT`; do
1028 rm -f $TMP/ost${num}active
1039 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1042 # We need ldiskfs here, may as well load them all
1044 [ "$CLIENTONLY" ] && return
1045 echo Formatting mds, osts
1047 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
1049 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
1052 for num in `seq $OSTCOUNT`; do
1054 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1056 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1062 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1067 zconf_umount `hostname` $1 || error "umount failed"
1068 zconf_mount `hostname` $1 || error "mount failed"
1075 do_facet $facet lsmod | grep -q obdclass || \
1076 do_facet $facet "modprobe obdclass"
1078 do_facet $facet "lctl set_param timeout=$timeout"
1081 writeconf_facet () {
1085 do_facet $facet "$TUNEFS --writeconf $dev"
1089 writeconf_facet mds $MDSDEV
1091 for num in `seq $OSTCOUNT`; do
1092 DEVNAME=`ostdevname $num`
1093 writeconf_facet ost$num $DEVNAME
1099 if [ -z "$CLIENTONLY" ]; then
1100 echo Setup mdt, osts
1102 echo $WRITECONF | grep -q "writeconf" && \
1105 set_obd_timeout mds $TIMEOUT
1106 start mds $MDSDEV $MDS_MOUNT_OPTS
1107 # We started mds, now we should set failover variable properly.
1108 # Set mdsfailover_HOST if it is not set (the default failnode).
1109 mdsfailover_HOST=$(facet_host mds)
1111 for num in `seq $OSTCOUNT`; do
1112 DEVNAME=`ostdevname $num`
1113 set_obd_timeout ost$num $TIMEOUT
1114 start ost$num $DEVNAME $OST_MOUNT_OPTS
1116 # We started ost$num, now we should set ost${num}failover variable properly.
1117 # Set ost${num}failover_HOST if it is not set (the default failnode).
1118 varname=ost${num}failover_HOST
1119 if [ -z "${!varname}" ]; then
1120 eval ost${num}failover_HOST=$(facet_host ost${num})
1125 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1127 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1129 if [ "$MOUNT_2" ]; then
1130 mount_client $MOUNT2
1131 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1137 mounted_lustre_filesystems() {
1138 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1141 init_facet_vars () {
1148 eval export ${facet}_dev=${device}
1149 eval export ${facet}_opt=\"$@\"
1151 local dev=${facet}_dev
1152 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1153 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1155 eval export ${facet}_svc=${label}
1157 local varname=${facet}failover_HOST
1158 if [ -z "${!varname}" ]; then
1159 eval $varname=$(facet_host $facet)
1163 init_facets_vars () {
1164 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
1166 for num in `seq $OSTCOUNT`; do
1167 DEVNAME=`ostdevname $num`
1168 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1172 init_versions_vars () {
1173 export MDSVER=$(do_facet mds "lctl get_param version" | cut -d. -f1,2)
1174 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1175 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1180 local myMGS_host=$mgs_HOST
1181 if [ "$NETTYPE" = "ptl" ]; then
1182 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1185 echo Checking config lustre mounted on $mntpt
1186 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1187 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1189 if [ "$mgshost" != "$myMGS_host" ]; then
1190 FAIL_ON_ERROR=true \
1191 error "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1192 Please use correct config or set mds_HOST correctly!"
1196 check_and_setup_lustre() {
1197 local MOUNTED=$(mounted_lustre_filesystems)
1198 if [ -z "$MOUNTED" ] || ! $(echo $MOUNTED | grep -w -q $MOUNT); then
1199 [ "$REFORMAT" ] && formatall
1201 MOUNTED=$(mounted_lustre_filesystems | head -1)
1202 [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
1203 export I_MOUNTED=yes
1209 if [ "$ONLY" == "setup" ]; then
1214 cleanup_and_setup_lustre() {
1215 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
1216 lctl set_param debug=0 || true
1218 if [ "$ONLY" == "cleanup" ]; then
1222 check_and_setup_lustre
1225 check_and_cleanup_lustre() {
1226 if [ "`mount | grep $MOUNT`" ]; then
1227 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
1229 if [ "$I_MOUNTED" = "yes" ]; then
1230 cleanupall -f || error "cleanup failed"
1242 while [ $NETWORK -eq 0 ]; do
1243 ping -c 1 -w 3 $1 > /dev/null
1244 if [ $? -eq 0 ]; then
1248 echo "waiting for $1, $((MAX - WAIT)) secs left"
1251 if [ $WAIT -gt $MAX ]; then
1252 echo "Network not available"
1258 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
1269 # the sed converts spaces to commas, but leaves the last space
1270 # alone, so the line doesn't end with a comma.
1271 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
1274 # list is comma separated list
1275 exclude_item_from_list () {
1280 list=$(echo " $list " | sed -re "s/\s+$excluded\s+/ /g")
1281 echo $(comma_list $list)
1285 (cd `dirname $1`; echo $PWD/`basename $1`)
1288 ##################################
1289 # Adaptive Timeouts funcs
1292 if [ -z "$AT_MAX_PATH" ]; then
1293 AT_MAX_PATH=$(do_facet mds "find /sys/ -name at_max")
1294 [ -z "$AT_MAX_PATH" ] && echo "missing /sys/.../at_max " && return 1
1300 at_is_valid || error "invalid call"
1302 # only check mds, we assume at_max is the same on all nodes
1303 local at_max=$(do_facet mds "cat $AT_MAX_PATH")
1304 if [ $at_max -eq 0 ]; then
1314 at_is_valid || error "invalid call"
1316 # suppose that all ost-s has the same at_max set
1317 if [ $facet == "ost" ]; then
1318 do_facet ost1 "cat $AT_MAX_PATH"
1320 do_facet $facet "cat $AT_MAX_PATH"
1328 at_is_valid || error "invalid call"
1332 if [ $facet == "ost" ]; then
1333 for i in `seq $OSTCOUNT`; do
1334 do_facet ost$i "echo $at_max > $AT_MAX_PATH"
1337 do_facet $facet "echo $at_max > $AT_MAX_PATH"
1342 ##################################
1346 # OBD_FAIL_MDS_ALL_REQUEST_NET
1348 do_facet mds lctl set_param fail_loc=0x123
1349 do_facet client "$1" || RC=$?
1350 do_facet mds lctl set_param fail_loc=0
1355 # OBD_FAIL_MDS_ALL_REPLY_NET
1357 do_facet mds lctl set_param fail_loc=0x122
1358 do_facet client "$@" || RC=$?
1359 do_facet mds lctl set_param fail_loc=0
1363 drop_reint_reply() {
1364 # OBD_FAIL_MDS_REINT_NET_REP
1366 do_facet mds lctl set_param fail_loc=0x119
1367 do_facet client "$@" || RC=$?
1368 do_facet mds lctl set_param fail_loc=0
1373 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1375 do_facet ost1 lctl set_param fail_loc=0x214
1376 do_facet client "$1" || RC=$?
1377 do_facet client "sync"
1378 do_facet ost1 lctl set_param fail_loc=0
1382 drop_ldlm_cancel() {
1383 #define OBD_FAIL_LDLM_CANCEL 0x304
1385 do_facet client lctl set_param fail_loc=0x304
1386 do_facet client "$@" || RC=$?
1387 do_facet client lctl set_param fail_loc=0
1391 drop_bl_callback() {
1392 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
1394 do_facet client lctl set_param fail_loc=0x305
1395 do_facet client "$@" || RC=$?
1396 do_facet client lctl set_param fail_loc=0
1401 #define OBD_FAIL_LDLM_REPLY 0x30c
1403 do_facet mds lctl set_param fail_loc=0x30c
1404 do_facet client "$@" || RC=$?
1405 do_facet mds lctl set_param fail_loc=0
1413 echo "clearing fail_loc on $facet"
1414 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
1417 set_nodes_failloc () {
1421 for node in $nodes ; do
1422 do_node $node lctl set_param fail_loc=$2
1426 cancel_lru_locks() {
1427 $LCTL mark "cancel_lru_locks $1 start"
1428 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
1429 $LCTL set_param -n $d=clear
1431 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
1432 $LCTL mark "cancel_lru_locks $1 stop"
1437 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
1438 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
1439 echo "$DEFAULT_LRU_SIZE"
1444 lctl set_param ldlm.namespaces.*$1*.lru_size=0
1447 lru_resize_disable()
1449 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
1454 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
1455 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
1456 echo there is still data in page cache $FILE ?
1457 lctl get_param -n $FILE
1464 create_fake_exports () {
1467 #obd_fail_val = num;
1468 #define OBD_FAIL_TGT_FAKE_EXP 0x708
1469 do_facet $facet "lctl set_param fail_val=$num"
1470 do_facet $facet "lctl set_param fail_loc=0x80000708"
1475 DEBUGSAVE="$(lctl get_param -n debug)"
1479 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
1483 ##################################
1485 ##################################
1488 local TYPE=${TYPE:-"FAIL"}
1490 lctl set_param fail_loc=0 2>/dev/null || true
1491 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
1492 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
1493 echo "Dumping lctl log to $ERRLOG"
1494 # We need to dump the logs on all nodes
1495 local NODES=$(nodes_list)
1496 for NODE in $NODES; do
1497 do_node $NODE $LCTL dk $ERRLOG
1500 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
1506 $FAIL_ON_ERROR && exit 1 || true
1514 # use only if we are ignoring failures for this test, bugno required.
1515 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
1516 # e.g. error_ignore 5494 "your message"
1518 local TYPE="IGNORE (bz$1)"
1524 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
1525 [ "$TESTSUITELOG" ] && \
1526 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
1529 build_test_filter() {
1530 [ "$ONLY" ] && log "only running test `echo $ONLY`"
1534 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
1535 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
1536 [ "$EXCEPT_SLOW" ] && \
1537 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
1538 for E in $EXCEPT $ALWAYS_EXCEPT; do
1539 eval EXCEPT_${E}=true
1541 for E in $EXCEPT_SLOW; do
1542 eval EXCEPT_SLOW_${E}=true
1544 for G in $GRANT_CHECK_LIST; do
1545 eval GCHECK_ONLY_${G}=true
1554 IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
1557 # print a newline if the last test was skipped
1558 export LAST_SKIPPED=
1562 export base=`basetest $1`
1563 if [ ! -z "$ONLY" ]; then
1565 if [ ${!testname}x != x ]; then
1566 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1571 if [ ${!testname}x != x ]; then
1572 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1581 if [ ${!testname}x != x ]; then
1583 TESTNAME=test_$1 skip "skipping excluded test $1"
1586 testname=EXCEPT_$base
1587 if [ ${!testname}x != x ]; then
1589 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
1592 testname=EXCEPT_SLOW_$1
1593 if [ ${!testname}x != x ]; then
1595 TESTNAME=test_$1 skip "skipping SLOW test $1"
1598 testname=EXCEPT_SLOW_$base
1599 if [ ${!testname}x != x ]; then
1601 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
1611 EQUALS="======================================================================"
1615 local suffixlen=$((${#EQUALS} - ${#msg}))
1616 [ $suffixlen -lt 5 ] && suffixlen=5
1617 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
1622 lsmod | grep lnet > /dev/null || load_modules
1634 local NODES=$(nodes_list)
1635 for NODE in $NODES; do
1636 do_node $NODE $LCTL mark "$MSG" 2> /dev/null || true
1642 strace -o $TMP/$1.strace -ttt $*
1644 log "FINISHED: $*: rc $RC"
1649 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
1654 FFREE=`lctl get_param -n mds.*.filesfree`
1655 FTOTAL=`lctl get_param -n mds.*.filestotal`
1656 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
1660 local myNODES=$(nodes_list)
1663 for NODE in $myNODES; do
1664 do_node $NODE "lctl set_param fail_loc=0 2>/dev/null || true"
1672 export tdir=d0.${TESTSUITE}/d${base}
1674 local SAVE_UMASK=`umask`
1678 log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
1680 export TESTNAME=test_$testnum
1682 test_${testnum} || error "test_$testnum failed with $?"
1686 check_grant ${testnum} || error "check_grant $testnum failed with $?"
1687 check_catastrophe || error "LBUG/LASSERT detected"
1688 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
1689 pass "($((`date +%s` - $BEFORE))s)"
1697 (cd `dirname $1`; echo $PWD/`basename $1`)
1701 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
1702 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
1707 export base=`basetest $1`
1708 [ "$CHECK_GRANT" == "no" ] && return 0
1710 testname=GCHECK_ONLY_${base}
1711 [ ${!testname}x == x ] && return 0
1713 echo -n "checking grant......"
1715 # write some data to sync client lost_grant
1716 rm -f $DIR1/${tfile}_check_grant_* 2>&1
1717 for i in `seq $OSTCOUNT`; do
1718 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
1719 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
1720 count=1 > /dev/null 2>&1
1722 # sync all the data and make sure no pending data on server
1725 #get client grant and server grant
1727 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
1728 client_grant=$((client_grant + $d))
1731 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
1732 server_grant=$((server_grant + $d))
1735 # cleanup the check_grant file
1736 for i in `seq $OSTCOUNT`; do
1737 rm $DIR1/${tfile}_check_grant_$i
1740 #check whether client grant == server grant
1741 if [ $client_grant != $server_grant ]; then
1742 echo "failed: client:${client_grant} server: ${server_grant}"
1749 ########################
1755 ost=`echo $1 | awk -F_ '{print $3}'`
1756 if [ -z $ost ]; then
1757 ost=`echo $1 | sed 's/-osc.*//'`
1764 [ "$node" != "$(hostname)" ]
1769 remote_node $mds_HOST
1774 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
1780 for node in $(osts_nodes) ; do
1781 remote_node $node && return 0
1788 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
1792 remote_ost && remote_mds
1796 local OSTNODES=$(facet_host ost1)
1799 for num in `seq $OSTCOUNT`; do
1800 local myOST=$(facet_host ost$num)
1801 OSTNODES="$OSTNODES $myOST"
1803 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
1809 # FIXME. We need a list of clients
1810 local myNODES=$HOSTNAME
1813 # CLIENTS (if specified) contains the local client
1814 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
1816 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
1817 myNODES="$myNODES $(osts_nodes) $mds_HOST"
1820 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
1825 remote_nodes_list () {
1826 local rnodes=$(nodes_list)
1827 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
1831 init_clients_lists () {
1832 # Sanity check: exclude the local client from RCLIENTS
1833 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
1835 # Sanity check: exclude the dup entries
1836 rclients=$(for i in $rclients; do echo $i; done | sort -u)
1838 local clients="$SINGLECLIENT $HOSTNAME $rclients"
1840 # Sanity check: exclude the dup entries from CLIENTS
1841 # for those configs which has SINGLCLIENT set to local client
1842 clients=$(for i in $clients; do echo $i; done | sort -u)
1844 CLIENTS=`comma_list $clients`
1845 local -a remoteclients=($rclients)
1846 for ((i=0; $i<${#remoteclients[@]}; i++)); do
1847 varname=CLIENT$((i + 2))
1848 eval $varname=${remoteclients[i]}
1851 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
1854 get_random_entry () {
1857 rnodes=${rnodes//,/ }
1859 local nodes=($rnodes)
1860 local num=${#nodes[@]}
1861 local i=$((RANDOM * num / 65536))
1868 lctl get_param version | grep -q patchless
1872 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
1877 echo $nodes | wc -w || true
1881 local nodes=$(osts_nodes)
1882 local osscount=$(get_node_count "$nodes")
1883 [ ! "$OSTCOUNT" = "$osscount" ]
1886 generate_machine_file() {
1887 local nodes=${1//,/ }
1888 local machinefile=$2
1889 rm -f $machinefile || error "can't rm $machinefile"
1890 for node in $nodes; do
1891 echo $node >>$machinefile
1896 local file=$1/stripe
1898 $LFS getstripe -v $file || error
1902 check_runas_id_ret() {
1904 local myRUNAS_UID=$1
1905 local myRUNAS_GID=$2
1908 if [ -z "$myRUNAS" ]; then
1909 error_exit "myRUNAS command must be specified for check_runas_id"
1911 mkdir $DIR/d0_runas_test
1913 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
1914 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=1
1915 rm -rf $DIR/d0_runas_test
1920 local myRUNAS_UID=$1
1921 local myRUNAS_GID=$2
1924 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
1925 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
1926 Please set RUNAS_ID to some UID which exists on MDS and client or
1927 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
1930 # Run multiop in the background, but wait for it to print
1931 # "PAUSING" to its stdout before returning from this function.
1932 multiop_bg_pause() {
1933 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
1937 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
1940 echo "$MULTIOP_PROG $FILE v$ARGS"
1941 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
1943 echo "TMPPIPE=${TMPPIPE}"
1944 local multiop_output
1947 read -t 60 multiop_output multiop_pid < $TMPPIPE
1948 if [ $? -ne 0 ]; then
1953 if [ "$multiop_output" != "PAUSING" ]; then
1954 echo "Incorrect multiop output: $multiop_output"
1965 local TARGET_RATE=$2
1966 local NUM_CLIENTS=$3
1969 local RATE=$(awk '/^Rate: [0-9\.]+ '"${OP}"'s\/sec/ { print $2}' ${LOG})
1971 # We need to use bc since the rate is a floating point number
1972 local RES=$(echo "${RATE} < ${TARGET_RATE}" | bc -l )
1973 if [ "${RES}" = 0 ]; then
1974 echo "Success: ${RATE} ${OP}s/sec met target rate" \
1975 "${TARGET_RATE} ${OP}s/sec for ${NUM_CLIENTS} client(s)."
1978 echo "Failure: ${RATE} ${OP}s/sec did not meet target rate" \
1979 "${TARGET_RATE} ${OP}s/sec for ${NUM_CLIENTS} client(s)."
1984 # reset llite stat counters
1985 clear_llite_stats(){
1986 lctl set_param -n llite.*.stats 0
1989 # sum llite stat items
1990 calc_llite_stats() {
1991 local res=$(lctl get_param -n llite.*.stats |
1992 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
1997 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
2000 calc_osc_kbytes () {
2001 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
2004 # save_lustre_params(node, parameter_mask)
2005 # generate a stream of formatted strings (<node> <param name>=<param value>)
2006 save_lustre_params() {
2008 do_node $1 "lctl get_param $2" | while read s; do echo "$1 $s"; done
2011 # restore lustre parameters from input stream, produces by save_lustre_params
2012 restore_lustre_params() {
2016 while IFS=" =" read node name val; do
2017 do_node $node "lctl set_param -n $name $val"
2021 check_catastrophe () {
2022 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
2024 [ -f $CATASTROPHE ] && [ $(cat $CATASTROPHE) -ne 0 ] && return 1
2025 if [ $rnodes ]; then
2026 do_nodes $rnodes "set -x; [ -f $CATASTROPHE ] && { [ \`cat $CATASTROPHE\` -eq 0 ] || false; } || true"
2041 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
2043 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
2044 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
2045 stripe_index=`awk '/obdidx/ {start = 1; getline; print $1; exit}' $tmp_file`
2050 local mpirun="$MPIRUN $MPIRUN_OPTIONS"
2051 local command="$mpirun $@"
2053 if [ "$MPI_USER" != root -a $mpirun ]; then
2054 echo "+ chmod 0777 $MOUNT"
2056 command="su $MPI_USER sh -c \"$command \""
2064 delayed_recovery_enabled () {
2065 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
2068 ################################################################################
2069 # The following functions are used to enable interop testing between
2070 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
2072 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
2073 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
2074 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
2075 ################################################################################
2077 get_lustre_version () {
2078 local node=${1:-"mds"}
2079 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
2082 get_mds_version_major () {
2083 local version=$(get_lustre_version mds)
2084 echo $version | awk -F. '{print $1}'
2087 get_mds_version_minor () {
2088 local version=$(get_lustre_version mds)
2089 echo $version | awk -F. '{print $2}'
2092 get_mds_version_patch () {
2093 local version=$(get_lustre_version mds)
2094 echo $version | awk -F. '{print $3}'
2097 get_mds_version_fix () {
2098 local version=$(get_lustre_version mds)
2099 echo $version | awk -F. '{print $4}'
2102 get_mds_fsstat_proc_path() {
2103 local major=$(get_mds_version_major)
2104 local minor=$(get_mds_version_minor)
2105 if [ $major -le 1 -a $minor -le 8 ] ; then
2112 get_mds_mntdev_proc_path() {
2113 local fsstat_dev=$(get_mds_fsstat_proc_path)
2114 echo "$fsstat_dev.*.mntdev"
2117 get_mdtlov_proc_path() {
2119 local major=$(get_mds_version_major)
2120 local minor=$(get_mds_version_minor)
2121 if [ $major -le 1 -a $minor -le 8 ] ; then
2122 echo "$fsname-mdtlov"
2124 echo "$fsname-MDT0000-mdtlov"
2128 get_mdtosc_proc_path() {
2130 local major=$(get_mds_version_major)
2131 local minor=$(get_mds_version_minor)
2132 if [ $major -le 1 -a $minor -le 8 ] ; then
2135 echo "${ost}-osc-MDT0000"