2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'echo "test-framework exiting on error"' ERR
11 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
14 # eg, assert_env LUSTRE MDSNODES OSTNODES CLIENTS
18 if [ -z "${!name}" ]; then
19 echo "$0: $name must be set"
23 [ $failed ] && exit 1 || true
27 echo "usage: $0 [-r] [-f cfgfile]"
34 export LUSTRE=`absolute_path $LUSTRE`
35 export TESTSUITE=`basename $0 .sh`
36 export LTESTDIR=${LTESTDIR:-$LUSTRE/../ltest}
38 [ -d /r ] && export ROOT=${ROOT:-/r}
39 export TMP=${TMP:-$ROOT/tmp}
41 export PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests
42 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
43 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
44 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
45 export CHECKSTAT="${CHECKSTAT:-checkstat} "
46 export FSYTPE=${FSTYPE:-"ext3"}
47 export NAME=${NAME:-local}
48 export LPROC=/proc/fs/lustre
50 if [ "$ACCEPTOR_PORT" ]; then
51 export PORT_OPT="--port $ACCEPTOR_PORT"
54 # Paths on remote nodes, if different
55 export RLUSTRE=${RLUSTRE:-$LUSTRE}
56 export RPWD=${RPWD:-$PWD}
60 while getopts "rvf:" opt $*; do
63 r) REFORMAT=--reformat;;
74 2.4.*) EXT=".o"; USE_QUOTA=no; FSTYPE=ext3 ;;
75 *) EXT=".ko"; USE_QUOTA=yes; FSTYPE=ldiskfs ;;
81 BASE=`basename $module $EXT`
82 lsmod | grep -q ${BASE} || \
83 if [ -f ${LUSTRE}/${module}${EXT} ]; then
84 insmod ${LUSTRE}/${module}${EXT} $@
86 # must be testing a "make install" or "rpm" installation
92 if [ -n "$MODPROBE" ]; then
96 if [ "$HAVE_MODULES" = true ]; then
102 echo Loading modules from $LUSTRE
103 load_module ../lnet/libcfs/libcfs
104 # note that insmod will ignore anything in modprobe.conf
105 load_module ../lnet/lnet/lnet $LNETOPTS
106 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
107 load_module ../lnet/klnds/$LNETLND
108 load_module lvfs/lvfs
109 load_module obdclass/obdclass
110 load_module ptlrpc/ptlrpc
111 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
116 [ "$FSTYPE" = "ldiskfs" ] && load_module ldiskfs/ldiskfs
117 load_module lvfs/fsfilt_$FSTYPE
119 load_module obdfilter/obdfilter
120 load_module llite/lustre
123 rm -f $TMP/ogdb-`hostname`
124 $LCTL modules > $TMP/ogdb-`hostname`
125 # 'mount' doesn't look in $PATH, just sbin
126 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
130 if [ `uname -r | cut -c 3` -eq 4 ]; then
138 MODULES=$($LCTL modules | awk '{ print $2 }')
139 while [ -n "$MODULES" ]; do
141 $RMMOD $MODULES >/dev/null 2>&1 || true
142 MODULES=$($LCTL modules | awk '{ print $2 }')
143 if [ -z "$MODULES" ]; then
147 echo "waiting, $((MAX - WAIT)) secs left"
149 if [ $WAIT -eq $MAX ]; then
150 echo "LNET modules $MODULES will not unload"
158 lsmod | grep lnet > /dev/null && $LCTL dl && $LCTL dk $TMP/debug
159 local MODULES=$($LCTL modules | awk '{ print $2 }')
160 $RMMOD $MODULES >/dev/null 2>&1 || true
161 # do it again, in case we tried to unload ksocklnd too early
162 MODULES=$($LCTL modules | awk '{ print $2 }')
163 [ -n "$MODULES" ] && $RMMOD $MODULES >/dev/null || true
164 MODULES=$($LCTL modules | awk '{ print $2 }')
165 if [ -n "$MODULES" ]; then
166 echo "Modules still loaded: "
168 if [ -e $LPROC ]; then
169 echo "Lustre still loaded"
170 cat $LPROC/devices || true
174 echo "Lustre stopped, but LNET is still loaded"
175 wait_for_lnet || return 3
180 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd mem.*leaked" || true)
181 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
182 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
183 echo "$LEAK_LUSTRE" 1>&2
184 echo "$LEAK_PORTALS" 1>&2
185 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
186 echo "Memory leaks detected"
187 [ "$LEAK_LUSTRE" -a $(echo $LEAK_LUSTRE | awk 'leaked=$8 {print leaked % 56}') == 0 ] && echo "ignoring known bug 10818" && return 0
190 echo "modules unloaded."
195 # start facet device options
201 echo "Starting ${facet}: $@ ${device} ${MOUNT%/*}/${facet}"
202 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
203 do_facet ${facet} mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
205 if [ $RC -ne 0 ]; then
206 echo mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
207 echo Start of ${device} on ${facet} failed ${RC}
209 do_facet ${facet} sync
210 label=`do_facet ${facet} "e2label ${device}" | grep -v "CMD: "`
211 [ -z "$label" ] && echo no label for ${device} && exit 1
212 eval export ${facet}_svc=${label}
213 eval export ${facet}_dev=${device}
214 eval export ${facet}_opt=\"$@\"
215 echo Started ${label}
224 HOST=`facet_active_host $facet`
225 [ -z $HOST ] && echo stop: no host for $facet && return 0
227 running=`do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts" | grep -v "CMD: "`
228 if [ ${running} -ne 0 ]; then
229 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
230 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
233 # umount should block, but we should wait for unrelated obd's
234 # like the MGS or MGC to also stop.
237 # conf-sanity 31 takes a long time cleanup
238 while [ $WAIT -lt 300 ]; do
239 running=$(do_facet ${facet} "[ -e $LPROC ] && grep ST' ' $LPROC/devices" | grep -v "CMD: ") || true
240 if [ -z "${running}" ]; then
243 echo "waited $WAIT for${running}"
244 if [ $INTERVAL -lt 64 ]; then
245 INTERVAL=$((INTERVAL + INTERVAL))
248 WAIT=$((WAIT + INTERVAL))
250 echo "service didn't stop after $WAIT seconds. Still running:"
259 # Only supply -o to mount if we have options
260 if [ -n "$MOUNTOPT" ]; then
261 OPTIONS="-o $MOUNTOPT"
263 local device=$MGSNID:/$FSNAME
264 if [ -z "$mnt" -o -z "$FSNAME" ]; then
265 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
269 echo "Starting client: $OPTIONS $device $mnt"
270 do_node $client mkdir -p $mnt
271 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
273 do_node $client "sysctl -w lnet.debug=$PTLDEBUG; sysctl -w lnet.subsystem_debug=${SUBSYSTEM# }"
274 [ -d /r ] && $LCTL modules > /r/tmp/ogdb-`hostname`
282 local running=`do_node $client "grep -c $mnt' ' /proc/mounts" | grep -v "CMD: "`
283 if [ $running -ne 0 ]; then
284 echo "Stopping client $mnt (opts:$force)"
285 do_node $client umount $force $mnt
291 if [ "$FAILURE_MODE" = HARD ]; then
292 $POWER_DOWN `facet_active_host $facet`
294 elif [ "$FAILURE_MODE" = SOFT ]; then
301 if [ "$FAILURE_MODE" = HARD ]; then
302 $POWER_UP `facet_active_host $facet`
308 # verify that lustre actually cleaned up properly
310 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
311 error "LBUG/LASSERT detected"
312 BUSY=`dmesg | grep -i destruct || true`
315 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
318 LEAK_LUSTRE=`dmesg | tail -n 30 | grep "obd mem.*leaked" || true`
319 LEAK_PORTALS=`dmesg | tail -n 20 | grep "Portals memory leaked" || true`
320 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
321 echo "$0: $LEAK_LUSTRE" 1>&2
322 echo "$0: $LEAK_PORTALS" 1>&2
323 echo "$0: Memory leak(s) detected..." 1>&2
324 mv $TMP/debug $TMP/debug-leak.`date +%s`
328 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
329 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
331 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
332 echo "$0: modules still loaded..." 1>&2
341 check_network "$HOST" 900
342 while ! do_node $HOST "ls -d $LUSTRE " > /dev/null; do sleep 5; done
347 HOST=`facet_active_host $facet`
352 # not every config has many clients
353 if [ ! -z "$CLIENTS" ]; then
354 $PDSH $CLIENTS "df $MOUNT" > /dev/null
359 uname -n >> $MOUNT/recon
360 if [ ! -z "$CLIENTS" ]; then
361 $PDSH $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
363 echo Connected clients:
365 ls -l $MOUNT/recon > /dev/null
371 echo "Failing $facet on node `facet_active_host $facet`"
372 shutdown_facet $facet
376 echo "df pid is $DFPID"
378 TO=`facet_active_host $facet`
379 echo "Failover $facet to $TO"
381 local dev=${facet}_dev
382 local opt=${facet}_opt
383 start $facet ${!dev} ${!opt}
394 local svc=${facet}_svc
395 do_facet $facet $LCTL --device %${!svc} readonly
396 do_facet $facet $LCTL --device %${!svc} notransno
397 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
398 $LCTL mark "local REPLAY BARRIER on ${!svc}"
401 replay_barrier_nodf() {
402 local facet=$1 echo running=${running}
404 local svc=${facet}_svc
405 echo Replay barrier on ${!svc}
406 do_facet $facet $LCTL --device %${!svc} readonly
407 do_facet $facet $LCTL --device %${!svc} notransno
408 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
409 $LCTL mark "local REPLAY BARRIER on ${!svc}"
413 UUID=`cat /proc/fs/lustre/mdc/${mds_svc}-mdc-*/uuid`
414 do_facet mds "echo $UUID > /proc/fs/lustre/mds/${mds_svc}/evict_client"
418 UUID=`cat /proc/fs/lustre/osc/${ost1_svc}-osc-*/uuid`
419 do_facet ost1 "echo $UUID > /proc/fs/lustre/obdfilter/${ost1_svc}/evict_client"
423 facet_failover $* || error "failover: $?"
424 df $MOUNT || error "post-failover df: $?"
431 local svc=${facet}_svc
432 local dev=${facet}_dev
433 local opt=${facet}_opt
434 start $facet ${!dev} ${!opt}
435 do_facet $facet lctl --device %${!svc} abort_recovery
436 df $MOUNT || echo "first df failed: $?"
438 df $MOUNT || error "post-failover df: $?"
442 echo There is no lmc. This is mountconf, baby.
447 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
448 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
454 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
461 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
462 if type __h2elan >/dev/null 2>&1; then
465 ID=`echo $1 | sed 's/[^0-9]*//g'`
473 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
474 ID=`echo $1 | sed 's/[^0-9]*//g'`
482 varname=${facet}_HOST
483 if [ -z "${!varname}" ]; then
484 if [ "${facet:0:3}" == "ost" ]; then
485 eval ${facet}_HOST=${ost_HOST}
493 local activevar=${facet}active
495 if [ -f ./${facet}active ] ; then
496 source ./${facet}active
500 if [ -z "$active" ] ; then
507 facet_active_host() {
509 local active=`facet_active $facet`
510 if [ "$facet" == client ]; then
513 echo `facet_host $active`
519 failover=${facet}failover
520 host=`facet_host $failover`
521 [ -z "$host" ] && return
522 curactive=`facet_active $facet`
523 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
524 eval export ${facet}active=$facet
526 eval export ${facet}active=$failover
528 # save the active host for this facet
529 activevar=${facet}active
530 echo "$activevar=${!activevar}" > ./$activevar
537 if [ "$HOST" = "$(hostname)" ]; then
542 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
544 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
550 HOST=`facet_active_host $facet`
551 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
558 # make sure its not already running
561 do_facet ${facet} $MKFS $*
567 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
568 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
576 # make sure we are using the primary server, so test-framework will
577 # be able to clean up properly.
578 activemds=`facet_active mds`
579 if [ $activemds != "mds" ]; then
583 # assume client mount is local
584 grep " $MOUNT " /proc/mounts && zconf_umount `hostname` $MOUNT $*
585 grep " $MOUNT2 " /proc/mounts && zconf_umount `hostname` $MOUNT2 $*
587 for num in `seq $OSTCOUNT`; do
600 # We need ldiskfs here, may as well load them all
602 echo Formatting mds, osts
604 add mds $MDS_MKFS_OPTS --reformat $MDSDEV || exit 10
606 add mds $MDS_MKFS_OPTS --reformat $MDSDEV > /dev/null || exit 10
609 for num in `seq $OSTCOUNT`; do
611 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` || exit 10
613 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` > /dev/null || exit 10
619 grep " $1 " /proc/mounts || zconf_mount `hostname` $*
625 start mds $MDSDEV $MDS_MOUNT_OPTS
626 for num in `seq $OSTCOUNT`; do
627 DEVNAME=`ostdevname $num`
628 start ost$num $DEVNAME $OST_MOUNT_OPTS
630 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
643 while [ $NETWORK -eq 0 ]; do
644 ping -c 1 -w 3 $1 > /dev/null
645 if [ $? -eq 0 ]; then
649 echo "waiting for $1, $((MAX - WAIT)) secs left"
652 if [ $WAIT -gt $MAX ]; then
653 echo "Network not available"
659 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
670 # the sed converts spaces to commas, but leaves the last space
671 # alone, so the line doesn't end with a comma.
672 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
676 (cd `dirname $1`; echo $PWD/`basename $1`)
679 ##################################
683 # OBD_FAIL_MDS_ALL_REQUEST_NET
685 do_facet mds sysctl -w lustre.fail_loc=0x123
686 do_facet client "$1" || RC=$?
687 do_facet mds sysctl -w lustre.fail_loc=0
692 # OBD_FAIL_MDS_ALL_REPLY_NET
694 do_facet mds sysctl -w lustre.fail_loc=0x122
695 do_facet client "$@" || RC=$?
696 do_facet mds sysctl -w lustre.fail_loc=0
701 # OBD_FAIL_MDS_REINT_NET_REP
703 do_facet mds sysctl -w lustre.fail_loc=0x119
704 do_facet client "$@" || RC=$?
705 do_facet mds sysctl -w lustre.fail_loc=0
710 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
712 do_facet ost1 sysctl -w lustre.fail_loc=0x214
713 do_facet client "$1" || RC=$?
714 do_facet client "sync"
715 do_facet ost1 sysctl -w lustre.fail_loc=0
720 #define OBD_FAIL_LDLM_CANCEL 0x304
722 do_facet client sysctl -w lustre.fail_loc=0x304
723 do_facet client "$@" || RC=$?
724 do_facet client sysctl -w lustre.fail_loc=0
729 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
731 do_facet client sysctl -w lustre.fail_loc=0x305
732 do_facet client "$@" || RC=$?
733 do_facet client sysctl -w lustre.fail_loc=0
738 #define OBD_FAIL_LDLM_REPLY 0x30c
740 do_facet mds sysctl -w lustre.fail_loc=0x30c
741 do_facet client "$@" || RC=$?
742 do_facet mds sysctl -w lustre.fail_loc=0
750 echo "clearing fail_loc on $facet"
751 do_facet $facet "sysctl -w lustre.fail_loc=0"
755 $LCTL mark "cancel_lru_locks $1 start"
756 for d in `find $LPROC/ldlm/namespaces | egrep -i $1`; do
757 [ -f $d/lru_size ] && echo clear > $d/lru_size
758 [ -f $d/lock_unused_count ] && grep [1-9] $d/lock_unused_count /dev/null
760 $LCTL mark "cancel_lru_locks $1 stop"
765 for a in /proc/fs/lustre/llite/*/dump_page_cache; do
766 if [ `wc -l $a | awk '{print $1}'` -gt 1 ]; then
767 echo there is still data in page cache $a ?
775 ##################################
778 sysctl -w lustre.fail_loc=0 2> /dev/null || true
779 echo "${TESTSUITE}: **** FAIL:" $@
780 log "FAIL: $TESTNAME $@"
784 build_test_filter() {
785 [ "$ONLY" ] && log "only running test `echo $ONLY`"
789 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
790 log "skipping tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
791 for E in $EXCEPT $ALWAYS_EXCEPT; do
792 eval EXCEPT_${E}=true
801 IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
805 export base=`basetest $1`
806 if [ ! -z "$ONLY" ]; then
808 if [ ${!testname}x != x ]; then
813 if [ ${!testname}x != x ]; then
821 if [ ${!testname}x != x ]; then
822 log "skipping excluded test $1"
825 testname=EXCEPT_$base
826 if [ ${!testname}x != x ]; then
827 log "skipping excluded test $1 (base $base)"
835 EQUALS="======================================================================"
839 local suffixlen=$((${#EQUALS} - ${#msg}))
840 [ $suffixlen -lt 5 ] && suffixlen=5
841 printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS
846 lsmod | grep lnet > /dev/null || load_modules
847 $LCTL mark "$*" 2> /dev/null || true
855 FFREE=`cat /proc/fs/lustre/mds/*/filesfree`
856 FTOTAL=`cat /proc/fs/lustre/mds/*/filestotal`
857 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
866 # Pretty tests run faster.
867 equals_msg $testnum: $message
870 log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
872 export TESTNAME=test_$testnum
873 test_${testnum} || error "test_$testnum failed with $?"
875 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
876 error "LBUG/LASSERT detected"
877 pass "($((`date +%s` - $BEFORE))s)"
882 (cd `dirname $1`; echo $PWD/`basename $1`)