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 # function used by scripts run on remote nodes
17 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
18 . $LUSTRE/tests/functions.sh
22 [[ $DIR/ = $MOUNT/* ]] || \
23 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
24 [[ $DIR1/ = $MOUNT1/* ]] || \
25 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
26 [[ $DIR2/ = $MOUNT2/* ]] || \
27 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
29 [ -n "$failed" ] && exit 99 || true
33 echo "usage: $0 [-r] [-f cfgfile]"
41 [ "$TESTSUITE" == "lfscktest" ] && return 0
42 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
43 local form="%-13s %-17s %s\n"
44 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
45 echo "------------------------------------------------------------------------------------"
46 for O in $TESTSUITE_LIST; do
49 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
52 local log=${TMP}/${o}.log
53 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
54 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
55 [ "${!O}" = "done" ] && \
56 printf "$form" "Done" "$O" "E=$skipped" && \
57 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
61 for O in $TESTSUITE_LIST; do
62 if [ "${!O}" = "no" ]; then
64 # only for those tests suits which are run directly from acc-sm script:
65 # bonnie, iozone, etc.
66 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
67 printf "$form" "UNFINISHED" "$O" ""
69 printf "$form" "Skipped" "$O" ""
74 for O in $TESTSUITE_LIST; do
75 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
76 printf "$form" "UNFINISHED" "$O" ""
81 export LUSTRE=`absolute_path $LUSTRE`
82 export TESTSUITE=`basename $0 .sh`
83 export TEST_FAILED=false
84 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
86 export MKE2FS=${MKE2FS:-mke2fs}
87 export DEBUGFS=${DEBUGFS:-debugfs}
88 export TUNE2FS=${TUNE2FS:-tune2fs}
89 export E2LABEL=${E2LABEL:-e2label}
90 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
91 export E2FSCK=${E2FSCK:-e2fsck}
93 #[ -d /r ] && export ROOT=${ROOT:-/r}
94 export TMP=${TMP:-$ROOT/tmp}
95 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
96 export HOSTNAME=${HOSTNAME:-`hostname`}
97 if ! echo $PATH | grep -q $LUSTRE/utils; then
98 export PATH=$PATH:$LUSTRE/utils
100 if ! echo $PATH | grep -q $LUSTRE/test; then
101 export PATH=$PATH:$LUSTRE/tests
103 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
104 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
105 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
106 export PATH=$PATH:$LUSTRE/tests/racer
108 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
109 export PATH=$PATH:$LUSTRE/tests/mpi
111 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
112 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
113 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
114 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
115 [ ! -f "$LFS" ] && export LFS=$(which lfs)
116 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
117 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
118 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
119 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
120 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
121 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
122 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
123 export FSTYPE=${FSTYPE:-"ldiskfs"}
124 export NAME=${NAME:-local}
126 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
128 if [ "$ACCEPTOR_PORT" ]; then
129 export PORT_OPT="--port $ACCEPTOR_PORT"
132 # Paths on remote nodes, if different
133 export RLUSTRE=${RLUSTRE:-$LUSTRE}
134 export RPWD=${RPWD:-$PWD}
135 export I_MOUNTED=${I_MOUNTED:-"no"}
139 while getopts "rvwf:" opt $*; do
142 r) REFORMAT=--reformat;;
144 w) WRITECONF=writeconf;;
149 shift $((OPTIND - 1))
152 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
157 *) EXT=".ko"; USE_QUOTA=yes;;
163 BASE=`basename $module $EXT`
164 lsmod | grep -q ${BASE} || \
165 if [ -f ${LUSTRE}/${module}${EXT} ]; then
166 insmod ${LUSTRE}/${module}${EXT} $@
168 # must be testing a "make install" or "rpm" installation
174 if [ -n "$MODPROBE" ]; then
178 if [ "$HAVE_MODULES" = true ]; then
184 echo Loading modules from $LUSTRE
185 load_module ../lnet/libcfs/libcfs
186 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
187 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
189 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
190 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
191 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
192 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
193 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
195 # disable it for now since it only hides the stack overflow upon test w/
197 # if [ "$NETTYPE" = "tcp" -o "$NETTYPE" = "o2ib" -o "$NETTYPE" = "ptl" ]; then
198 # echo $LNETOPTS | grep -q "local_nid_dist_zero=0" ||
199 # LNETOPTS="$LNETOPTS local_nid_dist_zero=0"
201 echo "lnet options: '$LNETOPTS'"
202 # note that insmod will ignore anything in modprobe.conf
203 load_module ../lnet/lnet/lnet $LNETOPTS
204 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
205 load_module ../lnet/klnds/$LNETLND
206 load_module lvfs/lvfs
207 load_module obdclass/obdclass
208 load_module ptlrpc/ptlrpc
209 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
214 if [ -z "$CLIENTONLY" ] && [ -z "$CLIENTMODSONLY" ]; then
217 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
218 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
219 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
220 load_module lvfs/fsfilt_$FSTYPE
222 load_module obdfilter/obdfilter
225 load_module llite/lustre
226 load_module llite/llite_lloop
227 rm -f $TMP/ogdb-$HOSTNAME
229 [ -d /r ] && OGDB="/r/tmp"
230 $LCTL modules > $OGDB/ogdb-$HOSTNAME
231 # 'mount' doesn't look in $PATH, just sbin
232 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
236 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
237 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
238 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
239 echo "$LEAK_LUSTRE" 1>&2
240 echo "$LEAK_PORTALS" 1>&2
241 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
242 echo "Memory leaks detected"
243 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
249 wait_exit_ST client # bug 12845
251 $LUSTRE_RMMOD $FSTYPE || return 2
255 check_mem_leak || return 254
257 echo "modules unloaded."
265 local dev=$(facet_active $facet)_dev
266 local opt=${facet}_opt
267 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
268 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
270 if [ $RC -ne 0 ]; then
271 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
272 echo "Start of ${!dev} on ${facet} failed ${RC}"
274 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
275 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
276 lctl set_param debug_mb=${DEBUG_SIZE}; \
279 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
280 [ -z "$label" ] && echo no label for ${!dev} && exit 1
281 eval export ${facet}_svc=${label}
282 echo Started ${label}
287 # start facet device options
293 eval export ${facet}_dev=${device}
294 eval export ${facet}_opt=\"$@\"
296 local varname=${facet}failover_dev
297 if [ -n "${!varname}" ] ; then
298 eval export ${facet}failover_dev=${!varname}
300 eval export ${facet}failover_dev=$device
303 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
313 HOST=`facet_active_host $facet`
314 [ -z $HOST ] && echo stop: no host for $facet && return 0
316 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
317 if [ ${running} -ne 0 ]; then
318 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
319 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
322 # umount should block, but we should wait for unrelated obd's
323 # like the MGS or MGC to also stop.
325 wait_exit_ST ${facet}
328 # set quota version (both administrative and operational quotas)
329 quota_set_version() {
330 do_facet mds "lctl set_param lquota.${FSNAME}-MDT*.quota_type=$1"
331 for j in `seq $OSTCOUNT`; do
332 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=$1"
336 # save quota version (both administrative and operational quotas)
337 # the function will also switch to the new version and the new type
338 quota_save_version() {
340 local ver=$(tr -c -d "123" <<< $spec)
341 local type=$(tr -c -d "ug" <<< $spec)
343 $LFS quotaoff -ug $MOUNT # just in case
344 [ -n "$ver" ] && quota_set_version $ver
345 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
347 do_facet mgs "lctl conf_param ${FSNAME}-MDT*.mdt.quota_type=$spec"
349 local osts=$(get_facets OST)
350 for ost in ${osts//,/ }; do
352 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
356 # client could mount several lustre
358 local fsname=${1:-$FSNAME}
360 do_facet mgs lctl get_param mds.${fsname}-MDT*.quota_type || rc=$?
361 do_nodes $(comma_list $(osts_nodes)) \
362 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
366 restore_quota_type () {
367 local mntpt=${1:-$MOUNT}
368 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
369 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
372 quota_save_version $old_QUOTA_TYPE
379 # 1. run quotacheck only if quota is off
380 # 2. save the original quota_type params, restore them after testing
382 # Suppose that quota type the same on mds and ost
383 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
384 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
385 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
386 export old_QUOTA_TYPE=$quota_type
387 quota_save_version $QUOTA_TYPE
390 local quota_usrs=$QUOTA_USERS
392 # get_filesystem_size
393 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
394 local blk_soft=$((disksz + 1024))
395 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
397 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
399 local i_hard=$((i_soft + i_soft / 20))
401 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
402 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
405 for usr in $quota_usrs; do
406 echo "Setting up quota on $client:$mntpt for $usr..."
408 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
410 eval $cmd || error "$cmd FAILED!"
412 # display the quota status
413 echo "Quota settings for $usr : "
414 $LFS quota -v -u $usr $mntpt || true
422 # Only supply -o to mount if we have options
423 if [ -n "$MOUNTOPT" ]; then
424 OPTIONS="-o $MOUNTOPT"
426 local device=$MGSNID:/$FSNAME
427 if [ -z "$mnt" -o -z "$FSNAME" ]; then
428 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
432 echo "Starting client: $client: $OPTIONS $device $mnt"
433 do_node $client mkdir -p $mnt
434 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
435 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
436 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
437 lctl set_param debug_mb=${DEBUG_SIZE}"
450 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
451 if [ $running -ne 0 ]; then
452 echo "Stopping client $client $mnt (opts:$force)"
453 do_node $client lsof -t $mnt || need_kill=no
454 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
455 pids=$(do_node $client lsof -t $mnt | sort -u);
456 if [ -n $pids ]; then
457 do_node $client kill -9 $pids || true
461 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
462 if [ $busy -ne 0 ] ; then
463 echo "$mnt is still busy, wait one second" && sleep 1
464 do_node $client umount $force $mnt
469 # nodes is comma list
470 sanity_mount_check_nodes () {
476 # FIXME: assume that all cluster nodes run the same os
477 [ "$(uname)" = Linux ] || return 0
480 for mnt in $mnts ; do
481 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
482 mpts=\\\$(mount | grep -w -c $mnt);
483 if [ \\\$running -ne \\\$mpts ]; then
484 echo \\\$(hostname) env are INSANE!;
492 sanity_mount_check_servers () {
494 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
495 echo Checking servers environments
497 # FIXME: modify get_facets to display all facets wo params
498 local facets="$(get_facets OST),$(get_facets MDS),mgs"
502 for facet in ${facets//,/ }; do
503 node=$(facet_host ${facet})
504 mnt=${MOUNT%/*}/${facet}
505 sanity_mount_check_nodes $node $mnt ||
506 { error "server $node environments are insane!"; return 1; }
510 sanity_mount_check_clients () {
511 local clients=${1:-$CLIENTS}
512 local mntpt=${2:-$MOUNT}
513 local mntpt2=${3:-$MOUNT2}
515 [ -z $clients ] && clients=$(hostname)
516 echo Checking clients $clients environments
518 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
519 error "clients environments are insane!"
522 sanity_mount_check () {
523 sanity_mount_check_servers || return 1
524 sanity_mount_check_clients || return 2
527 # mount clients if not mouted
528 zconf_mount_clients() {
533 # Only supply -o to mount if we have options
534 if [ -n "$MOUNTOPT" ]; then
535 OPTIONS="-o $MOUNTOPT"
537 local device=$MGSNID:/$FSNAME
538 if [ -z "$mnt" -o -z "$FSNAME" ]; then
539 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
543 echo "Starting client $clients: $OPTIONS $device $mnt"
546 running=\\\$(mount | grep -c $mnt' ');
548 if [ \\\$running -eq 0 ] ; then
550 mount -t lustre $OPTIONS $device $mnt;
555 echo "Started clients $clients: "
556 do_nodes $clients "mount | grep -w $mnt"
558 do_nodes $clients "sysctl -w lnet.debug=\\\"$PTLDEBUG\\\";
559 sysctl -w lnet.subsystem_debug=\\\"${SUBSYSTEM# }\\\";
560 sysctl -w lnet.debug_mb=${DEBUG_SIZE};"
565 zconf_umount_clients() {
572 echo "Stopping clients: $clients $mnt (opts:$force)"
573 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
574 if [ \\\$running -ne 0 ] ; then
575 echo Stopping client \\\$(hostname) client $mnt opts:$force;
576 lsof -t $mnt || need_kill=no;
577 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
578 pids=\\\$(lsof -t $mnt | sort -u);
579 if [ -n \\\"\\\$pids\\\" ]; then
583 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
584 if [ \\\$busy -ne 0 ] ; then
585 echo "$mnt is still busy, wait one second" && sleep 1;
591 shudown_node_hard () {
595 for i in $(seq $attempts) ; do
598 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
599 echo "waiting for $host to fail attempts=$attempts"
600 [ $i -lt $attempts ] || \
601 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
607 local mnt=${2:-$MOUNT}
610 if [ "$FAILURE_MODE" = HARD ]; then
611 shudown_node_hard $client
613 zconf_umount_clients $client $mnt -f
619 if [ "$FAILURE_MODE" = HARD ]; then
620 shudown_node_hard $(facet_active_host $facet)
621 elif [ "$FAILURE_MODE" = SOFT ]; then
628 if [ "$FAILURE_MODE" = HARD ]; then
629 $POWER_UP `facet_active_host $facet`
637 if [ "$FAILURE_MODE" = HARD ]; then
643 # recovery-scale functions
644 check_progs_installed () {
649 do_nodes $clients "PATH=:$PATH; status=true;
650 for prog in $progs; do
651 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
652 echo \\\$prog missing on \\\$(hostname);
660 echo __$(echo $1 | tr '-' 'X')
663 start_client_load() {
666 local var=$(client_var_name $client)_load
667 eval export ${var}=$load
669 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
670 BREAK_ON_ERROR=$BREAK_ON_ERROR \
671 END_RUN_FILE=$END_RUN_FILE \
672 LOAD_PID_FILE=$LOAD_PID_FILE \
673 TESTSUITELOG=$TESTSUITELOG \
675 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
676 log "Started client load: ${load} on $client"
681 start_client_loads () {
682 local -a clients=(${1//,/ })
683 local numloads=${#CLIENT_LOADS[@]}
686 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
687 testnum=$((nodenum % numloads))
688 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
692 # only for remote client
693 check_client_load () {
695 local var=$(client_var_name $client)_load
696 local TESTLOAD=run_${!var}.sh
698 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
700 # bug 18914: try to connect several times not only when
701 # check ps, but while check_catastrophe also
704 while [ $RC = 254 -a $tries -gt 0 ]; do
708 if ! check_catastrophe $client; then
710 if [ $RC -eq 254 ]; then
711 # FIXME: not sure how long we shuold sleep here
715 echo "check catastrophe failed: RC=$RC "
720 # We can continue try to connect if RC=254
721 # Just print the warning about this
722 if [ $RC = 254 ]; then
723 echo "got a return status of $RC from do_node while checking catastrophe on $client"
726 # see if the load is still on the client
729 while [ $RC = 254 -a $tries -gt 0 ]; do
733 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
738 if [ $RC = 254 ]; then
739 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
740 # see if we can diagnose a bit why this is
745 check_client_loads () {
746 local clients=${1//,/ }
750 for client in $clients; do
751 check_client_load $client
753 if [ "$rc" != 0 ]; then
754 log "Client load failed on node $client, rc=$rc"
760 restart_client_loads () {
761 local clients=${1//,/ }
762 local expectedfail=${2:-""}
766 for client in $clients; do
767 check_client_load $client
769 if [ "$rc" != 0 -a "$expectedfail" ]; then
770 local var=$(client_var_name $client)_load
771 start_client_load $client ${!var}
772 echo "Restarted client load ${!var}: on $client. Checking ..."
773 check_client_load $client
775 if [ "$rc" != 0 ]; then
776 log "Client load failed to restart on node $client, rc=$rc"
777 # failure one client load means test fail
778 # we do not need to check other
786 # End recovery-scale functions
788 # verify that lustre actually cleaned up properly
790 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
791 error "LBUG/LASSERT detected"
792 BUSY=`dmesg | grep -i destruct || true`
795 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
799 check_mem_leak || exit 204
801 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
802 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
804 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
805 echo "$0: modules still loaded..." 1>&2
822 RESULT=$(do_node $node "$TEST")
823 if [ "$RESULT" == "$FINAL" ]; then
824 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
827 [ $WAIT -ge $MAX ] && break
828 echo "Waiting $((MAX - WAIT)) secs for update"
829 WAIT=$((WAIT + sleep))
832 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
836 wait_update_facet () {
839 wait_update $(facet_active_host $facet) "$@"
842 wait_delete_completed () {
843 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
844 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
848 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
850 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
851 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
852 [ "$TOTAL" -eq "$TOTALPREV" ] && break
853 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
857 echo "Delete completed."
862 check_network "$host" 900
863 while ! do_node $host hostname > /dev/null; do sleep 5; done
868 local host=`facet_active_host $facet`
872 wait_recovery_complete () {
875 # Use default policy if $2 is not passed by caller.
876 #define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
877 # as we are in process of changing obd_timeout in different ways
878 # let's set MAX longer than that
879 local MAX=${2:-$(( TIMEOUT * 4 ))}
881 local var_svc=${facet}_svc
882 local procfile="*.${!var_svc}.recovery_status"
886 while [ $WAIT -lt $MAX ]; do
887 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
888 [[ $STATUS = "status: COMPLETE" ]] && return 0
891 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
893 echo "$facet recovery not done in $MAX sec. $STATUS"
903 # conf-sanity 31 takes a long time cleanup
904 while [ $WAIT -lt 300 ]; do
905 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
906 [ -z "${running}" ] && return 0
907 echo "waited $WAIT for${running}"
908 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
910 WAIT=$((WAIT + INTERVAL))
912 echo "service didn't stop after $WAIT seconds. Still running:"
917 wait_remote_prog () {
923 [ "$PDSH" = "no_dsh" ] && return 0
925 while [ $WAIT -lt $2 ]; do
926 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
927 [ -z "${running}" ] && return 0 || true
928 echo "waited $WAIT for: "
930 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
932 WAIT=$((WAIT + INTERVAL))
934 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
935 [ -z "$pids" ] && return 0
936 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
937 # FIXME: not portable
939 cat /proc/${pid}/status || true
940 cat /proc/${pid}/wchan || true
951 # not every config has many clients
952 if [ -n "$CLIENTS" ]; then
953 $PDSH $CLIENTS "df $MOUNT" > /dev/null
955 df $MOUNT > /dev/null
960 uname -n >> $MOUNT/recon
961 if [ -z "$CLIENTS" ]; then
962 df $MOUNT; uname -n >> $MOUNT/recon
964 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
966 echo Connected clients:
968 ls -l $MOUNT/recon > /dev/null
975 echo "Failing $facet on node `facet_active_host $facet`"
976 shutdown_facet $facet
977 [ -n "$sleep_time" ] && sleep $sleep_time
981 RECOVERY_START_TIME=`date +%s`
982 echo "df pid is $DFPID"
984 local TO=`facet_active_host $facet`
985 echo "Failover $facet to $TO"
987 mount_facet $facet || error "Restart of $facet failed"
998 local svc=${facet}_svc
999 do_facet $facet $LCTL --device %${!svc} notransno
1000 do_facet $facet $LCTL --device %${!svc} readonly
1001 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1002 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1005 replay_barrier_nodf() {
1006 local facet=$1 echo running=${running}
1007 do_facet $facet sync
1008 local svc=${facet}_svc
1009 echo Replay barrier on ${!svc}
1010 do_facet $facet $LCTL --device %${!svc} notransno
1011 do_facet $facet $LCTL --device %${!svc} readonly
1012 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1013 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1016 mds_evict_client() {
1017 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
1018 local mdtdevice=$(get_mds_mdt_device_proc_path)
1019 do_facet mds "lctl set_param -n ${mdtdevice}.${mds_svc}.evict_client $UUID"
1022 ost_evict_client() {
1023 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
1024 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1028 facet_failover $* || error "failover: $?"
1029 df $MOUNT || error "post-failover df: $?"
1034 facet_failover $facet
1040 change_active $facet
1041 mount_facet $facet -o abort_recovery
1042 df $MOUNT || echo "first df failed: $?"
1044 df $MOUNT || error "post-failover df: $?"
1048 echo There is no lmc. This is mountconf, baby.
1053 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1054 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1060 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1066 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1067 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1068 if [ -z "$ID" ]; then
1069 echo "Could not get a ptl id for $1..."
1078 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1085 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1086 if type __h2elan >/dev/null 2>&1; then
1089 ID=`echo $1 | sed 's/[^0-9]*//g'`
1097 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1098 ID=`echo $1 | sed 's/[^0-9]*//g'`
1102 declare -fx h2openib
1105 h2name_or_ip "$1" "o2ib"
1112 [ "$facet" == client ] && echo -n $HOSTNAME && return
1113 varname=${facet}_HOST
1114 if [ -z "${!varname}" ]; then
1115 if [ "${facet:0:3}" == "ost" ]; then
1116 eval ${facet}_HOST=${ost_HOST}
1124 local activevar=${facet}active
1126 if [ -f $TMP/${facet}active ] ; then
1127 source $TMP/${facet}active
1130 active=${!activevar}
1131 if [ -z "$active" ] ; then
1138 facet_active_host() {
1140 local active=`facet_active $facet`
1141 if [ "$facet" == client ]; then
1144 echo `facet_host $active`
1150 local failover=${facet}failover
1151 host=`facet_host $failover`
1152 [ -z "$host" ] && return
1153 local curactive=`facet_active $facet`
1154 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1155 eval export ${facet}active=$facet
1157 eval export ${facet}active=$failover
1159 # save the active host for this facet
1160 local activevar=${facet}active
1161 echo "$activevar=${!activevar}" > $TMP/$activevar
1166 # do not stripe off hostname if verbose, bug 19215
1167 if [ x$1 = x--verbose ]; then
1175 if [ "$HOST" = "$HOSTNAME" ]; then
1177 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1178 echo "cannot run remote command on $HOST with $myPDSH"
1182 echo "CMD: $HOST $@" >&2
1183 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1186 if [ "$myPDSH" = "rsh" ]; then
1187 # we need this because rsh does not return exit code of an executed command
1188 local command_status="$TMP/cs"
1189 rsh $HOST ":> $command_status"
1190 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1191 cd $RPWD; sh -c \"$@\") ||
1192 echo command failed >$command_status"
1193 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1198 # print HOSTNAME for myPDSH="no_dsh"
1199 if [[ $myPDSH = no_dsh ]]; then
1200 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1202 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1205 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1207 return ${PIPESTATUS[0]}
1210 single_local_node () {
1211 [ "$1" = "$HOSTNAME" ]
1216 # do not stripe off hostname if verbose, bug 19215
1217 if [ x$1 = x--verbose ]; then
1225 if $(single_local_node $rnodes); then
1227 do_node --verbose $rnodes $@
1234 # This is part from do_node
1237 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1238 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1241 echo "CMD: $rnodes $@" >&2
1242 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1246 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1248 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/\w+:\s//g"
1250 return ${PIPESTATUS[0]}
1256 local HOST=`facet_active_host $facet`
1257 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1264 # make sure its not already running
1266 rm -f $TMP/${facet}active
1267 do_facet ${facet} $MKFS $*
1273 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1274 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1282 # make sure we are using the primary server, so test-framework will
1283 # be able to clean up properly.
1284 activemds=`facet_active mds`
1285 if [ $activemds != "mds" ]; then
1289 local clients=$CLIENTS
1290 [ -z $clients ] && clients=$(hostname)
1292 zconf_umount_clients $clients $MOUNT "$*" || true
1293 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1295 [ "$CLIENTONLY" ] && return
1296 # The add fn does rm ${facet}active file, this would be enough
1297 # if we use do_facet <facet> only after the facet added, but
1298 # currently we use do_facet mds in local.sh
1300 rm -f ${TMP}/mdsactive
1301 for num in `seq $OSTCOUNT`; do
1303 rm -f $TMP/ost${num}active
1305 if [[ $MDSDEV != $MGSDEV ]]; then
1313 nfs_client_mode && return
1320 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1323 # We need ldiskfs here, may as well load them all
1325 [ "$CLIENTONLY" ] && return
1326 echo Formatting mgs, mds, osts
1327 if [[ $MDSDEV != $MGSDEV ]] || [[ $mds_HOST != $mgs_HOST ]]; then
1328 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1332 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
1334 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
1337 for num in `seq $OSTCOUNT`; do
1339 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1341 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1347 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1352 zconf_umount `hostname` $1 || error "umount failed"
1353 zconf_mount `hostname` $1 || error "mount failed"
1356 writeconf_facet () {
1360 do_facet $facet "$TUNEFS --writeconf $dev"
1364 writeconf_facet mds $MDSDEV
1366 for num in `seq $OSTCOUNT`; do
1367 DEVNAME=`ostdevname $num`
1368 writeconf_facet ost$num $DEVNAME
1373 nfs_client_mode && return
1375 sanity_mount_check ||
1376 error "environments are insane!"
1379 if [ -z "$CLIENTONLY" ]; then
1380 echo Setup mgs, mdt, osts
1382 echo $WRITECONF | grep -q "writeconf" && \
1385 if [[ $mds_HOST != $mgs_HOST ]] || [[ $MDSDEV != $MGSDEV ]]; then
1386 start mgs $MGSDEV $mgs_MOUNT_OPTS
1389 start mds $MDSDEV $MDS_MOUNT_OPTS
1390 # We started mds, now we should set failover variable properly.
1391 # Set mdsfailover_HOST if it is not set (the default failnode).
1392 if [ -z "$mdsfailover_HOST" ]; then
1393 mdsfailover_HOST=$(facet_host mds)
1396 for num in `seq $OSTCOUNT`; do
1397 DEVNAME=`ostdevname $num`
1398 start ost$num $DEVNAME $OST_MOUNT_OPTS
1400 # We started ost$num, now we should set ost${num}failover variable properly.
1401 # Set ost${num}failover_HOST if it is not set (the default failnode).
1402 varname=ost${num}failover_HOST
1403 if [ -z "${!varname}" ]; then
1404 eval ost${num}failover_HOST=$(facet_host ost${num})
1409 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1411 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1413 if [ "$MOUNT_2" ]; then
1414 mount_client $MOUNT2
1415 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1421 mounted_lustre_filesystems() {
1422 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1425 init_facet_vars () {
1426 [ "$CLIENTONLY" ] && return 0
1433 eval export ${facet}_dev=${device}
1434 eval export ${facet}_opt=\"$@\"
1436 local dev=${facet}_dev
1437 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1438 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1440 eval export ${facet}_svc=${label}
1442 local varname=${facet}failover_HOST
1443 if [ -z "${!varname}" ]; then
1444 eval $varname=$(facet_host $facet)
1447 # ${facet}failover_dev is set in cfg file
1448 varname=${facet}failover_dev
1449 if [ -n "${!varname}" ] ; then
1450 eval export ${facet}failover_dev=${!varname}
1452 eval export ${facet}failover_dev=$device
1456 init_facets_vars () {
1458 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
1460 remote_ost_nodsh && return
1462 for num in `seq $OSTCOUNT`; do
1463 DEVNAME=`ostdevname $num`
1464 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1468 init_param_vars () {
1469 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1470 export MDSVER=$(do_facet mds "lctl get_param version" | cut -d. -f1,2)
1471 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1472 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1476 TIMEOUT=$(do_facet mds "lctl get_param -n timeout")
1478 log "Using TIMEOUT=$TIMEOUT"
1480 if [ "$ENABLE_QUOTA" ]; then
1481 setup_quota $MOUNT || return 2
1485 nfs_client_mode () {
1486 if [ "$NFSCLIENT" ]; then
1487 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1488 local clients=$CLIENTS
1489 [ -z $clients ] && clients=$(hostname)
1491 # FIXME: remove hostname when 19215 fixed
1492 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1493 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1494 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1501 nfs_client_mode && return
1505 local mounted=$(mount | grep " $mntpt ")
1506 if [ "$CLIENTONLY" ]; then
1508 # CLIENTONLY should not depend on *_HOST settings
1509 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
1510 # in theory someone could create a new,
1511 # client-only config file that assumed lustre was already
1512 # configured and didn't set the MGSNID. If MGSNID is not set,
1513 # then we should use the mgs nid currently being used
1514 # as the default value. bug 18021
1515 [[ x$MGSNID = x ]] &&
1518 if [[ x$mgc != xMGC$MGSNID ]]; then
1519 if [ "$mgs_HOST" ]; then
1520 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
1521 [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
1522 error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
1528 local myMGS_host=$mgs_HOST
1529 if [ "$NETTYPE" = "ptl" ]; then
1530 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1533 echo Checking config lustre mounted on $mntpt
1534 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1535 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1537 # if [ "$mgshost" != "$myMGS_host" ]; then
1538 # error_exit "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1539 # Please use correct config or set mds_HOST correctly!"
1542 sanity_mount_check ||
1543 error "environments are insane!"
1547 local mdstimeout=$(do_facet mds "lctl get_param -n timeout")
1548 local cltimeout=$(lctl get_param -n timeout)
1549 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
1550 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
1555 check_and_setup_lustre() {
1556 nfs_client_mode && return
1558 local MOUNTED=$(mounted_lustre_filesystems)
1559 if [ -z "$MOUNTED" ] || ! $(echo $MOUNTED | grep -w -q $MOUNT); then
1560 [ "$REFORMAT" ] && formatall
1562 MOUNTED=$(mounted_lustre_filesystems | head -1)
1563 [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
1564 export I_MOUNTED=yes
1570 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
1571 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
1572 lctl set_param debug_mb=${DEBUG_SIZE};
1575 if [ "$ONLY" == "setup" ]; then
1580 cleanup_and_setup_lustre() {
1581 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
1582 lctl set_param debug=0 || true
1584 if [ "$ONLY" == "cleanup" ]; then
1588 check_and_setup_lustre
1591 check_and_cleanup_lustre() {
1592 if [ "`mount | grep $MOUNT`" ]; then
1593 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
1594 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
1596 if [ "$I_MOUNTED" = "yes" ]; then
1597 cleanupall -f || error "cleanup failed"
1609 while [ $NETWORK -eq 0 ]; do
1610 if ping -c 1 -w 3 $1 > /dev/null; then
1614 echo "waiting for $1, $((MAX - WAIT)) secs left"
1617 if [ $WAIT -gt $MAX ]; then
1618 echo "Network not available"
1624 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
1635 # the sed converts spaces to commas, but leaves the last space
1636 # alone, so the line doesn't end with a comma.
1637 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
1640 # list, excluded are the comma separated lists
1641 exclude_items_from_list () {
1647 for item in ${excluded//,/ }; do
1648 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
1650 echo $(comma_list $list)
1653 # list, expand are the comma separated lists
1655 local list=${1//,/ }
1656 local expand=${2//,/ }
1659 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
1660 echo $(comma_list $expanded)
1663 testslist_filter () {
1664 local script=$LUSTRE/tests/${TESTSUITE}.sh
1666 [ -f $script ] || return 0
1668 local start_at=$START_AT
1669 local stop_at=$STOP_AT
1671 local var=${TESTSUITE}_START_AT
1672 [ x"${!var}" != x ] && start_at=${!var}
1673 var=${TESTSUITE}_STOP_AT
1674 [ x"${!var}" != x ] && stop_at=${!var}
1676 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
1677 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
1678 /^'${start_at}'$/ {flag = 0}
1679 {if (flag == 1) print $0}
1680 /^'${stop_at}'$/ { flag = 1 }'
1684 (cd `dirname $1`; echo $PWD/`basename $1`)
1688 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
1689 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
1695 OST ) for ((i=1; i<=$OSTCOUNT; i++)) do
1696 list="$list ${name}$i"
1698 * ) error "Invalid facet type"
1701 echo $(comma_list $list)
1704 ##################################
1705 # Adaptive Timeouts funcs
1708 # only check mds, we assume at_max is the same on all nodes
1709 local at_max=$(do_facet mds "lctl get_param -n at_max")
1710 if [ $at_max -eq 0 ]; then
1720 # suppose that all ost-s has the same at_max set
1721 if [ $facet == "ost" ]; then
1722 do_facet ost1 "lctl get_param -n at_max"
1724 do_facet $facet "lctl get_param -n at_max"
1734 if [ $facet == "ost" ]; then
1735 for i in `seq $OSTCOUNT`; do
1736 do_facet ost$i "lctl set_param at_max=$at_max"
1739 do_facet $facet "lctl set_param at_max=$at_max"
1744 ##################################
1748 # OBD_FAIL_MDS_ALL_REQUEST_NET
1750 do_facet mds lctl set_param fail_loc=0x123
1751 do_facet client "$1" || RC=$?
1752 do_facet mds lctl set_param fail_loc=0
1757 # OBD_FAIL_MDS_ALL_REPLY_NET
1759 do_facet mds lctl set_param fail_loc=0x122
1760 do_facet client "$@" || RC=$?
1761 do_facet mds lctl set_param fail_loc=0
1765 drop_reint_reply() {
1766 # OBD_FAIL_MDS_REINT_NET_REP
1768 do_facet mds lctl set_param fail_loc=0x119
1769 do_facet client "$@" || RC=$?
1770 do_facet mds lctl set_param fail_loc=0
1775 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1777 do_facet ost1 lctl set_param fail_loc=0x214
1778 do_facet client "$1" || RC=$?
1779 do_facet client "sync"
1780 do_facet ost1 lctl set_param fail_loc=0
1784 drop_ldlm_cancel() {
1785 #define OBD_FAIL_LDLM_CANCEL 0x304
1787 do_facet client lctl set_param fail_loc=0x304
1788 do_facet client "$@" || RC=$?
1789 do_facet client lctl set_param fail_loc=0
1793 drop_bl_callback() {
1794 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
1796 do_facet client lctl set_param fail_loc=0x305
1797 do_facet client "$@" || RC=$?
1798 do_facet client lctl set_param fail_loc=0
1803 #define OBD_FAIL_LDLM_REPLY 0x30c
1805 do_facet mds lctl set_param fail_loc=0x30c
1806 do_facet client "$@" || RC=$?
1807 do_facet mds lctl set_param fail_loc=0
1815 echo "clearing fail_loc on $facet"
1816 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
1819 set_nodes_failloc () {
1820 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
1823 cancel_lru_locks() {
1824 $LCTL mark "cancel_lru_locks $1 start"
1825 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
1826 $LCTL set_param -n $d=clear
1828 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
1829 $LCTL mark "cancel_lru_locks $1 stop"
1834 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
1835 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
1836 echo "$DEFAULT_LRU_SIZE"
1841 lctl set_param ldlm.namespaces.*$1*.lru_size=0
1844 lru_resize_disable()
1846 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
1851 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
1852 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
1853 echo there is still data in page cache $FILE ?
1854 lctl get_param -n $FILE
1861 create_fake_exports () {
1864 #obd_fail_val = num;
1865 #define OBD_FAIL_TGT_FAKE_EXP 0x708
1866 do_facet $facet "lctl set_param fail_val=$num"
1867 do_facet $facet "lctl set_param fail_loc=0x80000708"
1872 DEBUGSAVE="$(lctl get_param -n debug)"
1876 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
1880 ##################################
1882 ##################################
1885 local TYPE=${TYPE:-"FAIL"}
1887 lctl set_param fail_loc=0 2>/dev/null || true
1890 # do not dump logs if $1=false
1891 if [ "x$1" = "xfalse" ]; then
1896 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
1899 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
1900 echo "Dumping lctl log to $ERRLOG"
1901 # We need to dump the logs on all nodes
1902 do_nodes $(comma_list $(nodes_list)) $NODE $LCTL dk $ERRLOG
1905 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
1911 $FAIL_ON_ERROR && exit 1 || true
1919 # use only if we are ignoring failures for this test, bugno required.
1920 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
1921 # e.g. error_ignore 5494 "your message"
1923 local TYPE="IGNORE (bz$1)"
1929 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
1933 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
1934 [ "$TESTSUITELOG" ] && \
1935 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
1938 build_test_filter() {
1939 EXCEPT="$EXCEPT $(testslist_filter)"
1941 [ "$ONLY" ] && log "only running test `echo $ONLY`"
1945 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
1946 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
1947 [ "$EXCEPT_SLOW" ] && \
1948 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
1949 for E in $EXCEPT $ALWAYS_EXCEPT; do
1950 eval EXCEPT_${E}=true
1952 for E in $EXCEPT_SLOW; do
1953 eval EXCEPT_SLOW_${E}=true
1955 for G in $GRANT_CHECK_LIST; do
1956 eval GCHECK_ONLY_${G}=true
1964 # print a newline if the last test was skipped
1965 export LAST_SKIPPED=
1969 export base=`basetest $1`
1970 if [ ! -z "$ONLY" ]; then
1972 if [ ${!testname}x != x ]; then
1973 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1978 if [ ${!testname}x != x ]; then
1979 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1988 if [ ${!testname}x != x ]; then
1990 TESTNAME=test_$1 skip "skipping excluded test $1"
1993 testname=EXCEPT_$base
1994 if [ ${!testname}x != x ]; then
1996 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
1999 testname=EXCEPT_SLOW_$1
2000 if [ ${!testname}x != x ]; then
2002 TESTNAME=test_$1 skip "skipping SLOW test $1"
2005 testname=EXCEPT_SLOW_$base
2006 if [ ${!testname}x != x ]; then
2008 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2018 EQUALS="======================================================================"
2022 local suffixlen=$((${#EQUALS} - ${#msg}))
2023 [ $suffixlen -lt 5 ] && suffixlen=5
2024 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
2029 lsmod | grep lnet > /dev/null || load_modules
2041 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2046 strace -o $TMP/$1.strace -ttt $*
2048 log "FINISHED: $*: rc $RC"
2053 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
2058 FFREE=`lctl get_param -n mds.*.filesfree`
2059 FTOTAL=`lctl get_param -n mds.*.filestotal`
2060 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2064 echo -n "Resetting fail_loc on all nodes..."
2065 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2073 export tdir=d0.${TESTSUITE}/d${base}
2075 local SAVE_UMASK=`umask`
2078 local BEFORE=`date +%s`
2080 log "== test $testnum: $message == `date +%H:%M:%S` ($BEFORE)"
2082 export TESTNAME=test_$testnum
2084 test_${testnum} || error "test_$testnum failed with $?"
2088 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2089 check_catastrophe || error "LBUG/LASSERT detected"
2090 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2091 pass "($((`date +%s` - $BEFORE))s)"
2099 (cd `dirname $1`; echo $PWD/`basename $1`)
2103 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2104 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2109 export base=`basetest $1`
2110 [ "$CHECK_GRANT" == "no" ] && return 0
2112 testname=GCHECK_ONLY_${base}
2113 [ ${!testname}x == x ] && return 0
2115 echo -n "checking grant......"
2117 # write some data to sync client lost_grant
2118 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2119 for i in `seq $OSTCOUNT`; do
2120 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2121 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2122 count=1 > /dev/null 2>&1
2124 # sync all the data and make sure no pending data on server
2127 #get client grant and server grant
2129 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2130 client_grant=$((client_grant + $d))
2133 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2134 server_grant=$((server_grant + $d))
2137 # cleanup the check_grant file
2138 for i in `seq $OSTCOUNT`; do
2139 rm $DIR1/${tfile}_check_grant_$i
2142 #check whether client grant == server grant
2143 if [ $client_grant != $server_grant ]; then
2144 echo "failed: client:${client_grant} server: ${server_grant}"
2151 ########################
2157 ost=`echo $1 | awk -F_ '{print $3}'`
2158 if [ -z $ost ]; then
2159 ost=`echo $1 | sed 's/-osc.*//'`
2166 [ "$node" != "$(hostname)" ]
2171 remote_node $mds_HOST
2176 [ "$CLIENTONLY" ] && return 0 || true
2177 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2183 for node in $(osts_nodes) ; do
2184 remote_node $node && return 0
2191 [ "$CLIENTONLY" ] && return 0 || true
2192 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2198 MGS=$(facet_host mgs)
2199 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2203 remote_ost && remote_mds
2207 local OSTNODES=$(facet_host ost1)
2210 for num in `seq $OSTCOUNT`; do
2211 local myOST=$(facet_host ost$num)
2212 OSTNODES="$OSTNODES $myOST"
2214 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
2220 # FIXME. We need a list of clients
2221 local myNODES=$HOSTNAME
2224 # CLIENTS (if specified) contains the local client
2225 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
2227 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
2228 myNODES="$myNODES $(osts_nodes) $mds_HOST"
2231 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
2236 remote_nodes_list () {
2237 local rnodes=$(nodes_list)
2238 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2242 init_clients_lists () {
2243 # Sanity check: exclude the local client from RCLIENTS
2244 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2246 # Sanity check: exclude the dup entries
2247 rclients=$(for i in $rclients; do echo $i; done | sort -u)
2249 local clients="$SINGLECLIENT $HOSTNAME $rclients"
2251 # Sanity check: exclude the dup entries from CLIENTS
2252 # for those configs which has SINGLCLIENT set to local client
2253 clients=$(for i in $clients; do echo $i; done | sort -u)
2255 CLIENTS=`comma_list $clients`
2256 local -a remoteclients=($rclients)
2257 for ((i=0; $i<${#remoteclients[@]}; i++)); do
2258 varname=CLIENT$((i + 2))
2259 eval $varname=${remoteclients[i]}
2262 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
2265 get_random_entry () {
2268 rnodes=${rnodes//,/ }
2270 local -a nodes=($rnodes)
2271 local num=${#nodes[@]}
2272 local i=$((RANDOM * num * 2 / 65536))
2279 lctl get_param version | grep -q patchless
2283 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
2288 echo $nodes | wc -w || true
2292 local nodes=$(osts_nodes)
2293 local osscount=$(get_node_count "$nodes")
2294 [ ! "$OSTCOUNT" = "$osscount" ]
2297 generate_machine_file() {
2298 local nodes=${1//,/ }
2299 local machinefile=$2
2300 rm -f $machinefile || error "can't rm $machinefile"
2301 for node in $nodes; do
2302 echo $node >>$machinefile
2307 local file=$1/stripe
2309 $LFS getstripe -v $file || error
2313 check_runas_id_ret() {
2315 local myRUNAS_UID=$1
2316 local myRUNAS_GID=$2
2319 if [ -z "$myRUNAS" ]; then
2320 error_exit "myRUNAS command must be specified for check_runas_id"
2322 mkdir $DIR/d0_runas_test
2324 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
2325 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=1
2326 rm -rf $DIR/d0_runas_test
2331 local myRUNAS_UID=$1
2332 local myRUNAS_GID=$2
2335 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
2336 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
2337 Please set RUNAS_ID to some UID which exists on MDS and client or
2338 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
2341 # Run multiop in the background, but wait for it to print
2342 # "PAUSING" to its stdout before returning from this function.
2343 multiop_bg_pause() {
2344 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
2348 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
2351 echo "$MULTIOP_PROG $FILE v$ARGS"
2352 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
2354 echo "TMPPIPE=${TMPPIPE}"
2355 local multiop_output
2357 read -t 60 multiop_output < $TMPPIPE
2358 if [ $? -ne 0 ]; then
2363 if [ "$multiop_output" != "PAUSING" ]; then
2364 echo "Incorrect multiop output: $multiop_output"
2379 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
2385 inodes_available () {
2386 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
2390 # reset llite stat counters
2391 clear_llite_stats(){
2392 lctl set_param -n llite.*.stats 0
2395 # sum llite stat items
2396 calc_llite_stats() {
2397 local res=$(lctl get_param -n llite.*.stats |
2398 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
2403 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
2406 calc_osc_kbytes () {
2407 df $MOUNT > /dev/null
2408 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
2411 # save_lustre_params(node, parameter_mask)
2412 # generate a stream of formatted strings (<node> <param name>=<param value>)
2413 save_lustre_params() {
2415 do_nodes --verbose $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
2418 # restore lustre parameters from input stream, produces by save_lustre_params
2419 restore_lustre_params() {
2423 while IFS=" =" read node name val; do
2424 do_node ${node//:/} "lctl set_param -n $name $val"
2428 check_catastrophe() {
2429 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
2430 local C=$CATASTROPHE
2431 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
2433 if [ $rnodes ]; then
2434 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
2435 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
2451 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
2453 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
2454 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
2455 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
2459 mdsrate_cleanup () {
2460 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
2463 delayed_recovery_enabled () {
2464 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
2467 ################################################################################
2468 # The following functions are used to enable interop testing between
2469 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
2471 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
2472 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
2473 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
2474 ################################################################################
2476 get_lustre_version () {
2477 local node=${1:-"mds"}
2478 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
2481 get_mds_version_major () {
2482 local version=$(get_lustre_version mds)
2483 echo $version | awk -F. '{print $1}'
2486 get_mds_version_minor () {
2487 local version=$(get_lustre_version mds)
2488 echo $version | awk -F. '{print $2}'
2491 get_mds_version_patch () {
2492 local version=$(get_lustre_version mds)
2493 echo $version | awk -F. '{print $3}'
2496 get_mds_version_fix () {
2497 local version=$(get_lustre_version mds)
2498 echo $version | awk -F. '{print $4}'
2501 get_mds_fsstat_proc_path() {
2502 local major=$(get_mds_version_major)
2503 local minor=$(get_mds_version_minor)
2504 if [ $major -le 1 -a $minor -le 8 ] ; then
2511 get_mds_mntdev_proc_path() {
2512 local fsstat_dev=$(get_mds_fsstat_proc_path)
2513 echo "$fsstat_dev.*.mntdev"
2516 get_mdtlov_proc_path() {
2518 local major=$(get_mds_version_major)
2519 local minor=$(get_mds_version_minor)
2520 if [ $major -le 1 -a $minor -le 8 ] ; then
2521 echo "${fsname}-mdtlov"
2523 echo "${fsname}-MDT0000-mdtlov"
2527 get_mdtosc_proc_path() {
2529 local major=$(get_mds_version_major)
2530 local minor=$(get_mds_version_minor)
2531 if [ $major -le 1 -a $minor -le 8 ] ; then
2534 echo "${ost}-osc-MDT0000"
2538 get_mds_mdt_device_proc_path() {
2539 local major=$(get_mds_version_major)
2540 local minor=$(get_mds_version_minor)
2541 if [ $major -le 1 -a $minor -le 8 ] ; then
2548 ########################
2549 convert_facet2name() {
2551 "ost" ) echo "OST0000" ;;
2552 "ost1") echo "OST0000" ;;
2553 "ost2") echo "OST0001" ;;
2554 "ost3") echo "OST0002" ;;
2555 "ost4") echo "OST0003" ;;
2556 "ost5") echo "OST0004" ;;
2557 *) error "unknown facet!" ;;
2561 get_clientosc_proc_path() {
2567 get_osc_import_name() {
2570 local name=$(convert_facet2name $ost)
2572 if [ "$node" == "mds" ]; then
2573 get_mdtosc_proc_path $name
2577 get_clientosc_proc_path $name
2581 wait_osc_import_state() {
2585 local ost=$(get_osc_import_name $node $ost_facet)
2590 CONN_PROC="osc.${FSNAME}-${ost}.ost_server_uuid"
2591 CONN_STATE=$(do_facet $node lctl get_param -n $CONN_PROC | cut -f2)
2592 while [ "${CONN_STATE}" != "${expected}" ]; do
2593 if [ "${expected}" == "DISCONN" ]; then
2594 # for disconn we can check after proc entry is removed
2595 [ "x${CONN_STATE}" == "x" ] && return 0
2596 # with AT enabled, we can have connect request timeout near of
2597 # reconnect timeout and test can't see real disconnect
2598 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
2600 # disconnect rpc should be wait not more obd_timeout
2601 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
2602 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
2604 CONN_STATE=$(do_facet $node lctl get_param -n $CONN_PROC | cut -f2)
2608 log "${ost_facet} now in ${CONN_STATE} state"