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 FSYTPE=${FSTYPE:-"ldiskfs"}
53 export NAME=${NAME:-local}
54 export LPROC=/proc/fs/lustre
56 if [ "$ACCEPTOR_PORT" ]; then
57 export PORT_OPT="--port $ACCEPTOR_PORT"
60 # Paths on remote nodes, if different
61 export RLUSTRE=${RLUSTRE:-$LUSTRE}
62 export RPWD=${RPWD:-$PWD}
66 while getopts "rvf:" opt $*; do
69 r) REFORMAT=--reformat;;
80 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
81 *) EXT=".ko"; USE_QUOTA=yes;;
87 BASE=`basename $module $EXT`
88 lsmod | grep -q ${BASE} || \
89 if [ -f ${LUSTRE}/${module}${EXT} ]; then
90 insmod ${LUSTRE}/${module}${EXT} $@
92 # must be testing a "make install" or "rpm" installation
98 if [ -n "$MODPROBE" ]; then
102 if [ "$HAVE_MODULES" = true ]; then
108 echo Loading modules from $LUSTRE
109 load_module ../lnet/libcfs/libcfs
110 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
111 [ -f /etc/modprobe.d/Lustre ] && MODPROBECONF=/etc/modprobe.d/Lustre
112 [ -z "$LNETOPTS" -a -n "$MODPROBECONF" ] && \
113 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
114 echo "lnet options: '$LNETOPTS'"
115 # note that insmod will ignore anything in modprobe.conf
116 load_module ../lnet/lnet/lnet $LNETOPTS
117 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
118 load_module ../lnet/klnds/$LNETLND
119 load_module lvfs/lvfs
120 load_module obdclass/obdclass
121 load_module ptlrpc/ptlrpc
122 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
127 if [ -z "$CLIENTONLY" ]; then
130 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
131 load_module lvfs/fsfilt_$FSTYPE
133 load_module obdfilter/obdfilter
136 load_module llite/lustre
137 rm -f $TMP/ogdb-`hostname`
139 [ -d /r ] && OGDB="/r/tmp"
140 $LCTL modules > $OGDB/ogdb-`hostname`
141 # 'mount' doesn't look in $PATH, just sbin
142 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
146 if [ `uname -r | cut -c 3` -eq 4 ]; then
154 MODULES=$($LCTL modules | awk '{ print $2 }')
155 while [ -n "$MODULES" ]; do
157 $RMMOD $MODULES >/dev/null 2>&1 || true
158 MODULES=$($LCTL modules | awk '{ print $2 }')
159 if [ -z "$MODULES" ]; then
163 echo "waiting, $((MAX - WAIT)) secs left"
165 if [ $WAIT -eq $MAX ]; then
166 echo "LNET modules $MODULES will not unload"
174 lsmod | grep lnet > /dev/null && $LCTL dl && $LCTL dk $TMP/debug
175 local MODULES=$($LCTL modules | awk '{ print $2 }')
176 $RMMOD $MODULES > /dev/null 2>&1 || true
177 # do it again, in case we tried to unload ksocklnd too early
178 MODULES=$($LCTL modules | awk '{ print $2 }')
179 [ -n "$MODULES" ] && $RMMOD $MODULES > /dev/null 2>&1 || true
180 MODULES=$($LCTL modules | awk '{ print $2 }')
181 if [ -n "$MODULES" ]; then
182 echo "Modules still loaded: "
184 if [ -e $LPROC ]; then
185 echo "Lustre still loaded"
186 cat $LPROC/devices || true
190 echo "Lustre stopped but LNET is still loaded, waiting..."
191 wait_for_lnet || return 3
196 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd mem.*leaked" || true)
197 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
198 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
199 echo "$LEAK_LUSTRE" 1>&2
200 echo "$LEAK_PORTALS" 1>&2
201 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
202 echo "Memory leaks detected"
203 [ -n "$IGNORE_LEAK" ] && echo "ignoring leaks" && return 0
206 echo "modules unloaded."
211 # start facet device options
217 echo "Starting ${facet}: $@ ${device} ${MOUNT%/*}/${facet}"
218 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
219 do_facet ${facet} mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
221 if [ $RC -ne 0 ]; then
222 echo mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
223 echo Start of ${device} on ${facet} failed ${RC}
225 do_facet ${facet} sync
226 label=$(do_facet ${facet} "e2label ${device}")
227 [ -z "$label" ] && echo no label for ${device} && exit 1
228 eval export ${facet}_svc=${label}
229 eval export ${facet}_dev=${device}
230 eval export ${facet}_opt=\"$@\"
231 echo Started ${label}
240 HOST=`facet_active_host $facet`
241 [ -z $HOST ] && echo stop: no host for $facet && return 0
243 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
244 if [ ${running} -ne 0 ]; then
245 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
246 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
249 # umount should block, but we should wait for unrelated obd's
250 # like the MGS or MGC to also stop.
253 # conf-sanity 31 takes a long time cleanup
254 while [ $WAIT -lt 300 ]; do
255 running=$(do_facet ${facet} "[ -e $LPROC ] && grep ST' ' $LPROC/devices") || true
256 if [ -z "${running}" ]; then
259 echo "waited $WAIT for${running}"
260 if [ $INTERVAL -lt 64 ]; then
261 INTERVAL=$((INTERVAL + INTERVAL))
264 WAIT=$((WAIT + INTERVAL))
266 echo "service didn't stop after $WAIT seconds. Still running:"
275 # Only supply -o to mount if we have options
276 if [ -n "$MOUNTOPT" ]; then
277 OPTIONS="-o $MOUNTOPT"
279 local device=$MGSNID:/$FSNAME
280 if [ -z "$mnt" -o -z "$FSNAME" ]; then
281 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
285 echo "Starting client: $OPTIONS $device $mnt"
286 do_node $client mkdir -p $mnt
287 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
289 do_node $client "sysctl -w lnet.debug=$PTLDEBUG; sysctl -w lnet.subsystem_debug=${SUBSYSTEM# }"
290 [ -d /r ] && $LCTL modules > /r/tmp/ogdb-`hostname`
298 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
299 if [ $running -ne 0 ]; then
300 echo "Stopping client $mnt (opts:$force)"
301 do_node $client umount $force $mnt
307 if [ "$FAILURE_MODE" = HARD ]; then
308 $POWER_DOWN `facet_active_host $facet`
310 elif [ "$FAILURE_MODE" = SOFT ]; then
317 if [ "$FAILURE_MODE" = HARD ]; then
318 $POWER_UP `facet_active_host $facet`
324 # verify that lustre actually cleaned up properly
326 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
327 error "LBUG/LASSERT detected"
328 BUSY=`dmesg | grep -i destruct || true`
331 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
334 LEAK_LUSTRE=`dmesg | tail -n 30 | grep "obd mem.*leaked" || true`
335 LEAK_PORTALS=`dmesg | tail -n 20 | grep "Portals memory leaked" || true`
336 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
337 echo "$0: $LEAK_LUSTRE" 1>&2
338 echo "$0: $LEAK_PORTALS" 1>&2
339 echo "$0: Memory leak(s) detected..." 1>&2
340 mv $TMP/debug $TMP/debug-leak.`date +%s`
344 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
345 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
347 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
348 echo "$0: modules still loaded..." 1>&2
357 check_network "$HOST" 900
358 while ! do_node $HOST "ls -d $LUSTRE " > /dev/null; do sleep 5; done
363 HOST=`facet_active_host $facet`
368 # not every config has many clients
369 if [ -n "$CLIENTS" ]; then
370 $PDSH $CLIENTS "df $MOUNT" > /dev/null
372 df $MOUNT > /dev/null
377 uname -n >> $MOUNT/recon
378 if [ ! -z "$CLIENTS" ]; then
379 $PDSH $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
381 echo Connected clients:
383 ls -l $MOUNT/recon > /dev/null
389 echo "Failing $facet on node `facet_active_host $facet`"
390 shutdown_facet $facet
394 echo "df pid is $DFPID"
396 TO=`facet_active_host $facet`
397 echo "Failover $facet to $TO"
399 local dev=${facet}_dev
400 local opt=${facet}_opt
401 start $facet ${!dev} ${!opt} || error "Restart of $facet failed"
412 local svc=${facet}_svc
413 do_facet $facet $LCTL --device %${!svc} readonly
414 do_facet $facet $LCTL --device %${!svc} notransno
415 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
416 $LCTL mark "local REPLAY BARRIER on ${!svc}"
419 replay_barrier_nodf() {
420 local facet=$1 echo running=${running}
422 local svc=${facet}_svc
423 echo Replay barrier on ${!svc}
424 do_facet $facet $LCTL --device %${!svc} readonly
425 do_facet $facet $LCTL --device %${!svc} notransno
426 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
427 $LCTL mark "local REPLAY BARRIER on ${!svc}"
431 UUID=`cat /proc/fs/lustre/mdc/${mds_svc}-mdc-*/uuid`
432 do_facet mds "echo $UUID > /proc/fs/lustre/mds/${mds_svc}/evict_client"
436 UUID=`cat /proc/fs/lustre/osc/${ost1_svc}-osc-*/uuid`
437 do_facet ost1 "echo $UUID > /proc/fs/lustre/obdfilter/${ost1_svc}/evict_client"
441 facet_failover $* || error "failover: $?"
442 df $MOUNT || error "post-failover df: $?"
449 local svc=${facet}_svc
450 local dev=${facet}_dev
451 local opt=${facet}_opt
452 start $facet ${!dev} ${!opt}
453 do_facet $facet lctl --device %${!svc} abort_recovery
454 df $MOUNT || echo "first df failed: $?"
456 df $MOUNT || error "post-failover df: $?"
460 echo There is no lmc. This is mountconf, baby.
465 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
466 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
472 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
473 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
474 if [ -z "$ID" ]; then
475 echo "Could not get a ptl id for $1..."
484 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
491 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
492 if type __h2elan >/dev/null 2>&1; then
495 ID=`echo $1 | sed 's/[^0-9]*//g'`
503 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
504 ID=`echo $1 | sed 's/[^0-9]*//g'`
512 varname=${facet}_HOST
513 if [ -z "${!varname}" ]; then
514 if [ "${facet:0:3}" == "ost" ]; then
515 eval ${facet}_HOST=${ost_HOST}
523 local activevar=${facet}active
525 if [ -f ./${facet}active ] ; then
526 source ./${facet}active
530 if [ -z "$active" ] ; then
537 facet_active_host() {
539 local active=`facet_active $facet`
540 if [ "$facet" == client ]; then
543 echo `facet_host $active`
549 failover=${facet}failover
550 host=`facet_host $failover`
551 [ -z "$host" ] && return
552 curactive=`facet_active $facet`
553 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
554 eval export ${facet}active=$facet
556 eval export ${facet}active=$failover
558 # save the active host for this facet
559 activevar=${facet}active
560 echo "$activevar=${!activevar}" > ./$activevar
567 if [ "$HOST" = "$(hostname)" ]; then
571 echo "CMD: $HOST $@" >&2
572 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
574 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
575 return ${PIPESTATUS[0]}
581 HOST=`facet_active_host $facet`
582 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
589 # make sure its not already running
592 do_facet ${facet} $MKFS $*
598 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
599 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
607 # make sure we are using the primary server, so test-framework will
608 # be able to clean up properly.
609 activemds=`facet_active mds`
610 if [ $activemds != "mds" ]; then
614 # assume client mount is local
615 grep " $MOUNT " /proc/mounts && zconf_umount `hostname` $MOUNT $*
616 grep " $MOUNT2 " /proc/mounts && zconf_umount `hostname` $MOUNT2 $*
617 [ "$CLIENTONLY" ] && return
619 for num in `seq $OSTCOUNT`; do
631 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
634 # We need ldiskfs here, may as well load them all
636 [ "$CLIENTONLY" ] && return
637 echo Formatting mds, osts
639 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
641 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
644 for num in `seq $OSTCOUNT`; do
646 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
648 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
654 grep " $1 " /proc/mounts || zconf_mount `hostname` $*
659 if [ -z "$CLIENTONLY" ]; then
661 echo $REFORMAT | grep -q "reformat" \
662 || do_facet mds "$TUNEFS --writeconf $MDSDEV"
663 start mds $MDSDEV $MDS_MOUNT_OPTS
664 for num in `seq $OSTCOUNT`; do
665 DEVNAME=`ostdevname $num`
666 start ost$num $DEVNAME $OST_MOUNT_OPTS
669 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
671 if [ "$MOUNT_2" ]; then
685 while [ $NETWORK -eq 0 ]; do
686 ping -c 1 -w 3 $1 > /dev/null
687 if [ $? -eq 0 ]; then
691 echo "waiting for $1, $((MAX - WAIT)) secs left"
694 if [ $WAIT -gt $MAX ]; then
695 echo "Network not available"
701 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
712 # the sed converts spaces to commas, but leaves the last space
713 # alone, so the line doesn't end with a comma.
714 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
718 (cd `dirname $1`; echo $PWD/`basename $1`)
721 ##################################
725 # OBD_FAIL_MDS_ALL_REQUEST_NET
727 do_facet mds sysctl -w lustre.fail_loc=0x123
728 do_facet client "$1" || RC=$?
729 do_facet mds sysctl -w lustre.fail_loc=0
734 # OBD_FAIL_MDS_ALL_REPLY_NET
736 do_facet mds sysctl -w lustre.fail_loc=0x122
737 do_facet client "$@" || RC=$?
738 do_facet mds sysctl -w lustre.fail_loc=0
743 # OBD_FAIL_MDS_REINT_NET_REP
745 do_facet mds sysctl -w lustre.fail_loc=0x119
746 do_facet client "$@" || RC=$?
747 do_facet mds sysctl -w lustre.fail_loc=0
752 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
754 do_facet ost1 sysctl -w lustre.fail_loc=0x214
755 do_facet client "$1" || RC=$?
756 do_facet client "sync"
757 do_facet ost1 sysctl -w lustre.fail_loc=0
762 #define OBD_FAIL_LDLM_CANCEL 0x304
764 do_facet client sysctl -w lustre.fail_loc=0x304
765 do_facet client "$@" || RC=$?
766 do_facet client sysctl -w lustre.fail_loc=0
771 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
773 do_facet client sysctl -w lustre.fail_loc=0x305
774 do_facet client "$@" || RC=$?
775 do_facet client sysctl -w lustre.fail_loc=0
780 #define OBD_FAIL_LDLM_REPLY 0x30c
782 do_facet mds sysctl -w lustre.fail_loc=0x30c
783 do_facet client "$@" || RC=$?
784 do_facet mds sysctl -w lustre.fail_loc=0
792 echo "clearing fail_loc on $facet"
793 do_facet $facet "sysctl -w lustre.fail_loc=0"
797 $LCTL mark "cancel_lru_locks $1 start"
798 for d in `find $LPROC/ldlm/namespaces | egrep -i $1`; do
799 [ -f $d/lru_size ] && echo clear > $d/lru_size
800 [ -f $d/lock_unused_count ] && grep [1-9] $d/lock_unused_count /dev/null
802 $LCTL mark "cancel_lru_locks $1 stop"
807 for a in /proc/fs/lustre/llite/*/dump_page_cache; do
808 if [ `wc -l $a | awk '{print $1}'` -gt 1 ]; then
809 echo there is still data in page cache $a ?
818 DEBUGSAVE="$(sysctl -n lnet.debug)"
822 [ -n "$DEBUGSAVE" ] && sysctl -w lnet.debug="${DEBUGSAVE}"
826 ##################################
830 sysctl -w lustre.fail_loc=0 2> /dev/null || true
831 log "${TESTSUITE} ${TESTNAME}: **** FAIL:" $@
832 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
833 echo "Dumping lctl log to $ERRLOG"
839 build_test_filter() {
840 [ "$ONLY" ] && log "only running test `echo $ONLY`"
844 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
845 log "skipping tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
846 for E in $EXCEPT $ALWAYS_EXCEPT; do
847 eval EXCEPT_${E}=true
856 IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
860 export base=`basetest $1`
861 if [ ! -z "$ONLY" ]; then
863 if [ ${!testname}x != x ]; then
868 if [ ${!testname}x != x ]; then
876 if [ ${!testname}x != x ]; then
877 log "skipping excluded test $1"
880 testname=EXCEPT_$base
881 if [ ${!testname}x != x ]; then
882 log "skipping excluded test $1 (base $base)"
890 EQUALS="======================================================================"
894 local suffixlen=$((${#EQUALS} - ${#msg}))
895 [ $suffixlen -lt 5 ] && suffixlen=5
896 printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS
901 lsmod | grep lnet > /dev/null || load_modules
902 $LCTL mark "$*" 2> /dev/null || true
910 FFREE=`cat /proc/fs/lustre/mds/*/filesfree`
911 FTOTAL=`cat /proc/fs/lustre/mds/*/filestotal`
912 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
921 # Pretty tests run faster.
922 equals_msg $testnum: $message
925 log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
927 export TESTNAME=test_$testnum
928 test_${testnum} || error "test_$testnum failed with $?"
930 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
931 error "LBUG/LASSERT detected"
932 pass "($((`date +%s` - $BEFORE))s)"
937 (cd `dirname $1`; echo $PWD/`basename $1`)