2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
11 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
13 #export PDSH="pdsh -S -Rssh -w"
15 # eg, assert_env LUSTRE MDSNODES OSTNODES CLIENTS
19 if [ -z "${!name}" ]; then
20 echo "$0: $name must be set"
24 [ $failed ] && exit 1 || true
28 echo "usage: $0 [-r] [-f cfgfile]"
35 export LUSTRE=`absolute_path $LUSTRE`
36 export TESTSUITE=`basename $0 .sh`
37 export LTESTDIR=${LTESTDIR:-$LUSTRE/../ltest}
39 [ -d /r ] && export ROOT=${ROOT:-/r}
40 export TMP=${TMP:-$ROOT/tmp}
42 export PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests
43 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
44 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
45 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
46 [ ! -f "$LFS" ] && export LFS=$(which lfs)
47 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
48 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
49 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
50 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
51 export CHECKSTAT="${CHECKSTAT:-checkstat} "
52 export NAME=${NAME:-local}
53 export LPROC=/proc/fs/lustre
55 if [ "$ACCEPTOR_PORT" ]; then
56 export PORT_OPT="--port $ACCEPTOR_PORT"
59 # Paths on remote nodes, if different
60 export RLUSTRE=${RLUSTRE:-$LUSTRE}
61 export RPWD=${RPWD:-$PWD}
65 while getopts "rvf:" opt $*; do
68 r) REFORMAT=--reformat;;
79 2.4.*) EXT=".o"; USE_QUOTA=no;;
80 *) EXT=".ko"; USE_QUOTA=yes;;
86 BASE=`basename $module $EXT`
87 lsmod | grep -q ${BASE} || \
88 if [ -f ${LUSTRE}/${module}${EXT} ]; then
89 insmod ${LUSTRE}/${module}${EXT} $@
91 # must be testing a "make install" or "rpm" installation
97 if [ -n "$MODPROBE" ]; then
101 if [ "$HAVE_MODULES" = true ]; then
107 echo Loading modules from $LUSTRE
108 load_module ../lnet/libcfs/libcfs
109 [ -z "$LNETOPTS" ] && \
110 LNETOPTS=$(awk '/^options lnet/ { print $0}' /etc/modprobe.conf | sed 's/^options lnet //g')
111 echo "lnet options: '$LNETOPTS'"
112 # note that insmod will ignore anything in modprobe.conf
113 load_module ../lnet/lnet/lnet $LNETOPTS
114 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
115 load_module ../lnet/klnds/$LNETLND
116 load_module lvfs/lvfs
117 load_module obdclass/obdclass
118 load_module ptlrpc/ptlrpc
119 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
124 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
125 load_module lvfs/fsfilt_$FSTYPE
127 load_module obdfilter/obdfilter
128 load_module llite/lustre
131 rm -f $TMP/ogdb-`hostname`
133 [ -d /r ] && OGDB="/r/tmp"
134 $LCTL modules > $OGDB/ogdb-`hostname`
135 # 'mount' doesn't look in $PATH, just sbin
136 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
140 if [ `uname -r | cut -c 3` -eq 4 ]; then
148 MODULES=$($LCTL modules | awk '{ print $2 }')
149 while [ -n "$MODULES" ]; do
151 $RMMOD $MODULES >/dev/null 2>&1 || true
152 MODULES=$($LCTL modules | awk '{ print $2 }')
153 if [ -z "$MODULES" ]; then
157 echo "waiting, $((MAX - WAIT)) secs left"
159 if [ $WAIT -eq $MAX ]; then
160 echo "LNET modules $MODULES will not unload"
168 lsmod | grep lnet > /dev/null && $LCTL dl && $LCTL dk $TMP/debug
169 local MODULES=$($LCTL modules | awk '{ print $2 }')
170 $RMMOD $MODULES > /dev/null 2>&1 || true
171 # do it again, in case we tried to unload ksocklnd too early
172 MODULES=$($LCTL modules | awk '{ print $2 }')
173 [ -n "$MODULES" ] && $RMMOD $MODULES > /dev/null 2>&1 || true
174 MODULES=$($LCTL modules | awk '{ print $2 }')
175 if [ -n "$MODULES" ]; then
176 echo "Modules still loaded: "
178 if [ -e $LPROC ]; then
179 echo "Lustre still loaded"
180 cat $LPROC/devices || true
184 echo "Lustre stopped but LNET is still loaded, waiting..."
185 wait_for_lnet || return 3
190 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd mem.*leaked" || true)
191 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
192 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
193 echo "$LEAK_LUSTRE" 1>&2
194 echo "$LEAK_PORTALS" 1>&2
195 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
196 echo "Memory leaks detected"
197 [ -n "$IGNORE_LEAK" ] && echo "ignoring leaks" && return 0
200 echo "modules unloaded."
205 # start facet device options
211 echo "Starting ${facet}: $@ ${device} ${MOUNT%/*}/${facet}"
212 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
213 do_facet ${facet} mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
215 if [ $RC -ne 0 ]; then
216 echo mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
217 echo Start of ${device} on ${facet} failed ${RC}
219 do_facet ${facet} sync
220 label=$(do_facet ${facet} "e2label ${device}")
221 [ -z "$label" ] && echo no label for ${device} && exit 1
222 eval export ${facet}_svc=${label}
223 eval export ${facet}_dev=${device}
224 eval export ${facet}_opt=\"$@\"
225 echo Started ${label}
234 HOST=`facet_active_host $facet`
235 [ -z $HOST ] && echo stop: no host for $facet && return 0
237 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
238 if [ ${running} -ne 0 ]; then
239 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
240 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
243 # umount should block, but we should wait for unrelated obd's
244 # like the MGS or MGC to also stop.
247 # conf-sanity 31 takes a long time cleanup
248 while [ $WAIT -lt 300 ]; do
249 running=$(do_facet ${facet} "[ -e $LPROC ] && grep ST' ' $LPROC/devices") || true
250 if [ -z "${running}" ]; then
253 echo "waited $WAIT for${running}"
254 if [ $INTERVAL -lt 64 ]; then
255 INTERVAL=$((INTERVAL + INTERVAL))
258 WAIT=$((WAIT + INTERVAL))
260 echo "service didn't stop after $WAIT seconds. Still running:"
269 # Only supply -o to mount if we have options
270 if [ -n "$MOUNTOPT" ]; then
271 OPTIONS="-o $MOUNTOPT"
273 local device=$MGSNID:/$FSNAME
274 if [ -z "$mnt" -o -z "$FSNAME" ]; then
275 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
279 echo "Starting client: $OPTIONS $device $mnt"
280 do_node $client mkdir -p $mnt
281 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
283 do_node $client "sysctl -w lnet.debug=$PTLDEBUG; sysctl -w lnet.subsystem_debug=${SUBSYSTEM# }"
284 [ -d /r ] && $LCTL modules > /r/tmp/ogdb-`hostname`
292 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
293 if [ $running -ne 0 ]; then
294 echo "Stopping client $mnt (opts:$force)"
295 do_node $client umount $force $mnt
301 if [ "$FAILURE_MODE" = HARD ]; then
302 $POWER_DOWN `facet_active_host $facet`
304 elif [ "$FAILURE_MODE" = SOFT ]; then
311 if [ "$FAILURE_MODE" = HARD ]; then
312 $POWER_UP `facet_active_host $facet`
318 # verify that lustre actually cleaned up properly
320 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
321 error "LBUG/LASSERT detected"
322 BUSY=`dmesg | grep -i destruct || true`
325 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
328 LEAK_LUSTRE=`dmesg | tail -n 30 | grep "obd mem.*leaked" || true`
329 LEAK_PORTALS=`dmesg | tail -n 20 | grep "Portals memory leaked" || true`
330 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
331 echo "$0: $LEAK_LUSTRE" 1>&2
332 echo "$0: $LEAK_PORTALS" 1>&2
333 echo "$0: Memory leak(s) detected..." 1>&2
334 mv $TMP/debug $TMP/debug-leak.`date +%s`
338 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
339 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
341 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
342 echo "$0: modules still loaded..." 1>&2
351 check_network "$HOST" 900
352 while ! do_node $HOST "ls -d $LUSTRE " > /dev/null; do sleep 5; done
357 HOST=`facet_active_host $facet`
362 # not every config has many clients
363 if [ ! -z "$CLIENTS" ]; then
364 $PDSH $CLIENTS "df $MOUNT" > /dev/null
369 uname -n >> $MOUNT/recon
370 if [ ! -z "$CLIENTS" ]; then
371 $PDSH $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
373 echo Connected clients:
375 ls -l $MOUNT/recon > /dev/null
381 echo "Failing $facet on node `facet_active_host $facet`"
382 shutdown_facet $facet
386 echo "df pid is $DFPID"
388 TO=`facet_active_host $facet`
389 echo "Failover $facet to $TO"
391 local dev=${facet}_dev
392 local opt=${facet}_opt
393 start $facet ${!dev} ${!opt}
404 local svc=${facet}_svc
405 do_facet $facet $LCTL --device %${!svc} readonly
406 do_facet $facet $LCTL --device %${!svc} notransno
407 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
408 $LCTL mark "local REPLAY BARRIER on ${!svc}"
411 replay_barrier_nodf() {
412 local facet=$1 echo running=${running}
414 local svc=${facet}_svc
415 echo Replay barrier on ${!svc}
416 do_facet $facet $LCTL --device %${!svc} readonly
417 do_facet $facet $LCTL --device %${!svc} notransno
418 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
419 $LCTL mark "local REPLAY BARRIER on ${!svc}"
423 UUID=`cat /proc/fs/lustre/mdc/${mds_svc}-mdc-*/uuid`
424 do_facet mds "echo $UUID > /proc/fs/lustre/mds/${mds_svc}/evict_client"
428 UUID=`cat /proc/fs/lustre/osc/${ost1_svc}-osc-*/uuid`
429 do_facet ost1 "echo $UUID > /proc/fs/lustre/obdfilter/${ost1_svc}/evict_client"
433 facet_failover $* || error "failover: $?"
434 df $MOUNT || error "post-failover df: $?"
441 local svc=${facet}_svc
442 local dev=${facet}_dev
443 local opt=${facet}_opt
444 start $facet ${!dev} ${!opt}
445 do_facet $facet lctl --device %${!svc} abort_recovery
446 df $MOUNT || echo "first df failed: $?"
448 df $MOUNT || error "post-failover df: $?"
452 echo There is no lmc. This is mountconf, baby.
457 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
458 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
464 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
465 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
466 if [ -z "$ID" ]; then
467 echo "Could not get a ptl id for $1..."
476 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
483 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
484 if type __h2elan >/dev/null 2>&1; then
487 ID=`echo $1 | sed 's/[^0-9]*//g'`
495 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
496 ID=`echo $1 | sed 's/[^0-9]*//g'`
504 varname=${facet}_HOST
505 if [ -z "${!varname}" ]; then
506 if [ "${facet:0:3}" == "ost" ]; then
507 eval ${facet}_HOST=${ost_HOST}
515 local activevar=${facet}active
517 if [ -f ./${facet}active ] ; then
518 source ./${facet}active
522 if [ -z "$active" ] ; then
529 facet_active_host() {
531 local active=`facet_active $facet`
532 if [ "$facet" == client ]; then
535 echo `facet_host $active`
541 failover=${facet}failover
542 host=`facet_host $failover`
543 [ -z "$host" ] && return
544 curactive=`facet_active $facet`
545 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
546 eval export ${facet}active=$facet
548 eval export ${facet}active=$failover
550 # save the active host for this facet
551 activevar=${facet}active
552 echo "$activevar=${!activevar}" > ./$activevar
559 if [ "$HOST" = "$(hostname)" ]; then
563 echo "CMD: $HOST $@" >&2
564 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
566 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
567 return ${PIPESTATUS[0]}
573 HOST=`facet_active_host $facet`
574 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
581 # make sure its not already running
584 do_facet ${facet} $MKFS $*
590 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
591 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
599 # make sure we are using the primary server, so test-framework will
600 # be able to clean up properly.
601 activemds=`facet_active mds`
602 if [ $activemds != "mds" ]; then
606 # assume client mount is local
607 grep " $MOUNT " /proc/mounts && zconf_umount `hostname` $MOUNT $*
608 grep " $MOUNT2 " /proc/mounts && zconf_umount `hostname` $MOUNT2 $*
610 for num in `seq $OSTCOUNT`; do
622 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
625 # We need ldiskfs here, may as well load them all
627 [ "$CLIENTONLY" ] && return
628 echo Formatting mds, osts
630 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
632 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
635 for num in `seq $OSTCOUNT`; do
637 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
639 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
645 grep " $1 " /proc/mounts || zconf_mount `hostname` $*
650 if [ -z "$CLIENTONLY" ]; then
652 echo $REFORMAT | grep -q "reformat" \
653 || do_facet mds "$TUNEFS --writeconf $MDSDEV"
654 start mds $MDSDEV $MDS_MOUNT_OPTS
655 for num in `seq $OSTCOUNT`; do
656 DEVNAME=`ostdevname $num`
657 start ost$num $DEVNAME $OST_MOUNT_OPTS
660 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
662 if [ "$MOUNT_2" ]; then
676 while [ $NETWORK -eq 0 ]; do
677 ping -c 1 -w 3 $1 > /dev/null
678 if [ $? -eq 0 ]; then
682 echo "waiting for $1, $((MAX - WAIT)) secs left"
685 if [ $WAIT -gt $MAX ]; then
686 echo "Network not available"
692 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
703 # the sed converts spaces to commas, but leaves the last space
704 # alone, so the line doesn't end with a comma.
705 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
709 (cd `dirname $1`; echo $PWD/`basename $1`)
712 ##################################
716 # OBD_FAIL_MDS_ALL_REQUEST_NET
718 do_facet mds sysctl -w lustre.fail_loc=0x123
719 do_facet client "$1" || RC=$?
720 do_facet mds sysctl -w lustre.fail_loc=0
725 # OBD_FAIL_MDS_ALL_REPLY_NET
727 do_facet mds sysctl -w lustre.fail_loc=0x122
728 do_facet client "$@" || RC=$?
729 do_facet mds sysctl -w lustre.fail_loc=0
734 # OBD_FAIL_MDS_REINT_NET_REP
736 do_facet mds sysctl -w lustre.fail_loc=0x119
737 do_facet client "$@" || RC=$?
738 do_facet mds sysctl -w lustre.fail_loc=0
743 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
745 do_facet ost1 sysctl -w lustre.fail_loc=0x214
746 do_facet client "$1" || RC=$?
747 do_facet client "sync"
748 do_facet ost1 sysctl -w lustre.fail_loc=0
753 #define OBD_FAIL_LDLM_CANCEL 0x304
755 do_facet client sysctl -w lustre.fail_loc=0x304
756 do_facet client "$@" || RC=$?
757 do_facet client sysctl -w lustre.fail_loc=0
762 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
764 do_facet client sysctl -w lustre.fail_loc=0x305
765 do_facet client "$@" || RC=$?
766 do_facet client sysctl -w lustre.fail_loc=0
771 #define OBD_FAIL_LDLM_REPLY 0x30c
773 do_facet mds sysctl -w lustre.fail_loc=0x30c
774 do_facet client "$@" || RC=$?
775 do_facet mds sysctl -w lustre.fail_loc=0
783 echo "clearing fail_loc on $facet"
784 do_facet $facet "sysctl -w lustre.fail_loc=0"
788 $LCTL mark "cancel_lru_locks $1 start"
789 for d in `find $LPROC/ldlm/namespaces | egrep -i $1`; do
790 [ -f $d/lru_size ] && echo clear > $d/lru_size
791 [ -f $d/lock_unused_count ] && grep [1-9] $d/lock_unused_count /dev/null
793 $LCTL mark "cancel_lru_locks $1 stop"
798 for a in /proc/fs/lustre/llite/*/dump_page_cache; do
799 if [ `wc -l $a | awk '{print $1}'` -gt 1 ]; then
800 echo there is still data in page cache $a ?
809 DEBUGSAVE="$(sysctl -n lnet.debug)"
813 [ -n "$DEBUGSAVE" ] && sysctl -w lnet.debug=\"$DEBUGSAVE\"
817 ##################################
821 sysctl -w lustre.fail_loc=0 2> /dev/null || true
822 log "${TESTSUITE} ${TESTNAME}: **** FAIL:" $@
823 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
824 echo "Dumping lctl log to $ERRLOG"
830 build_test_filter() {
831 [ "$ONLY" ] && log "only running test `echo $ONLY`"
835 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
836 log "skipping tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
837 for E in $EXCEPT $ALWAYS_EXCEPT; do
838 eval EXCEPT_${E}=true
847 IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
851 export base=`basetest $1`
852 if [ ! -z "$ONLY" ]; then
854 if [ ${!testname}x != x ]; then
859 if [ ${!testname}x != x ]; then
867 if [ ${!testname}x != x ]; then
868 log "skipping excluded test $1"
871 testname=EXCEPT_$base
872 if [ ${!testname}x != x ]; then
873 log "skipping excluded test $1 (base $base)"
881 EQUALS="======================================================================"
885 local suffixlen=$((${#EQUALS} - ${#msg}))
886 [ $suffixlen -lt 5 ] && suffixlen=5
887 printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS
892 lsmod | grep lnet > /dev/null || load_modules
893 $LCTL mark "$*" 2> /dev/null || true
901 FFREE=`cat /proc/fs/lustre/mds/*/filesfree`
902 FTOTAL=`cat /proc/fs/lustre/mds/*/filestotal`
903 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
912 # Pretty tests run faster.
913 equals_msg $testnum: $message
916 log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
918 export TESTNAME=test_$testnum
919 test_${testnum} || error "test_$testnum failed with $?"
921 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
922 error "LBUG/LASSERT detected"
923 pass "($((`date +%s` - $BEFORE))s)"
928 (cd `dirname $1`; echo $PWD/`basename $1`)