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]"
40 [ "$TESTSUITE" == "lfscktest" ] && return 0
41 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
42 local form="%-13s %-17s %s\n"
43 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
44 echo "------------------------------------------------------------------------------------"
45 for O in $TESTSUITE_LIST; do
48 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
51 local log=${TMP}/${o}.log
52 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
53 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
54 [ "${!O}" = "done" ] && \
55 printf "$form" "Done" "$O" "E=$skipped" && \
56 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
60 for O in $TESTSUITE_LIST; do
61 [ "${!O}" = "no" ] && \
62 printf "$form" "Skipped" "$O" ""
65 for O in $TESTSUITE_LIST; do
66 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
67 printf "$form" "UNFINISHED" "$O" ""
72 export LUSTRE=`absolute_path $LUSTRE`
73 export TESTSUITE=`basename $0 .sh`
74 export TEST_FAILED=false
76 export MKE2FS=${MKE2FS:-mke2fs}
77 export DEBUGFS=${DEBUGFS:-debugfs}
78 export TUNE2FS=${TUNE2FS:-tune2fs}
79 export E2LABEL=${E2LABEL:-e2label}
80 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
81 export E2FSCK=${E2FSCK:-e2fsck}
83 #[ -d /r ] && export ROOT=${ROOT:-/r}
84 export TMP=${TMP:-$ROOT/tmp}
85 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
86 export HOSTNAME=${HOSTNAME:-`hostname`}
87 if ! echo $PATH | grep -q $LUSTRE/utils; then
88 export PATH=$PATH:$LUSTRE/utils
90 if ! echo $PATH | grep -q $LUSTRE/test; then
91 export PATH=$PATH:$LUSTRE/tests
93 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
94 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
95 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
96 export PATH=$PATH:$LUSTRE/tests/racer
98 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
99 export PATH=$PATH:$LUSTRE/tests/mpi
101 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
102 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
103 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
104 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
105 [ ! -f "$LFS" ] && export LFS=$(which lfs)
106 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
107 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
108 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
109 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
110 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
111 export FSTYPE=${FSTYPE:-"ldiskfs"}
112 export NAME=${NAME:-local}
114 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
116 if [ "$ACCEPTOR_PORT" ]; then
117 export PORT_OPT="--port $ACCEPTOR_PORT"
120 # Paths on remote nodes, if different
121 export RLUSTRE=${RLUSTRE:-$LUSTRE}
122 export RPWD=${RPWD:-$PWD}
123 export I_MOUNTED=${I_MOUNTED:-"no"}
127 while getopts "rvwf:" opt $*; do
130 r) REFORMAT=--reformat;;
132 w) WRITECONF=writeconf;;
137 shift $((OPTIND - 1))
140 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
146 *) EXT=".ko"; USE_QUOTA=yes;;
152 BASE=`basename $module $EXT`
153 lsmod | grep -q ${BASE} || \
154 if [ -f ${LUSTRE}/${module}${EXT} ]; then
155 insmod ${LUSTRE}/${module}${EXT} $@
157 # must be testing a "make install" or "rpm" installation
163 if [ -n "$MODPROBE" ]; then
167 if [ "$HAVE_MODULES" = true ]; then
173 echo Loading modules from $LUSTRE
174 load_module ../lnet/libcfs/libcfs
175 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
176 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
178 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
179 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
180 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
181 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
182 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
184 # disable it for now since it only hides the stack overflow upon test w/
186 # if [ "$NETTYPE" = "tcp" -o "$NETTYPE" = "o2ib" -o "$NETTYPE" = "ptl" ]; then
187 # echo $LNETOPTS | grep -q "local_nid_dist_zero=0" ||
188 # LNETOPTS="$LNETOPTS local_nid_dist_zero=0"
190 echo "lnet options: '$LNETOPTS'"
191 # note that insmod will ignore anything in modprobe.conf
192 load_module ../lnet/lnet/lnet $LNETOPTS
193 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
194 load_module ../lnet/klnds/$LNETLND
195 load_module lvfs/lvfs
196 load_module obdclass/obdclass
197 load_module ptlrpc/ptlrpc
198 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota
203 if [ -z "$CLIENTONLY" ] && [ -z "$CLIENTMODSONLY" ]; then
206 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
207 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
208 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
209 load_module lvfs/fsfilt_$FSTYPE
211 load_module obdfilter/obdfilter
214 load_module llite/lustre
215 load_module llite/llite_lloop
216 rm -f $TMP/ogdb-$HOSTNAME
218 [ -d /r ] && OGDB="/r/tmp"
219 $LCTL modules > $OGDB/ogdb-$HOSTNAME
220 # 'mount' doesn't look in $PATH, just sbin
221 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
225 if [ `uname -r | cut -c 3` -eq 4 ]; then
233 MODULES=$($LCTL modules | awk '{ print $2 }')
234 while [ -n "$MODULES" ]; do
236 $RMMOD $MODULES >/dev/null 2>&1 || true
237 MODULES=$($LCTL modules | awk '{ print $2 }')
238 if [ -z "$MODULES" ]; then
242 echo "waiting, $((MAX - WAIT)) secs left"
244 if [ $WAIT -eq $MAX ]; then
245 echo "LNET modules $MODULES will not unload"
252 unload_dep_module() {
254 #libcfs 107852 17 llite_lloop,lustre,obdfilter,ost,...
256 local DEPS=$(lsmod | awk '($1 == "'$MODULE'") { print $4 }' | tr ',' ' ')
257 for SUBMOD in $DEPS; do
258 unload_dep_module $SUBMOD
260 [ "$MODULE" = "libcfs" ] && $LCTL dk $TMP/debug || true
261 $RMMOD $MODULE || true
265 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
266 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
267 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
268 echo "$LEAK_LUSTRE" 1>&2
269 echo "$LEAK_PORTALS" 1>&2
270 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
271 echo "Memory leaks detected"
272 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
278 wait_exit_ST client # bug 12845
280 lsmod | grep libcfs > /dev/null && $LCTL dl
281 [ -z "$CLIENTONLY" ] && unload_dep_module $FSTYPE
282 unload_dep_module libcfs
284 local MODULES=$($LCTL modules | awk '{ print $2 }')
285 if [ -n "$MODULES" ]; then
286 echo "Modules still loaded: "
288 if [ "$(lctl dl)" ]; then
289 echo "Lustre still loaded"
294 echo "Lustre stopped but LNET is still loaded, waiting..."
295 wait_for_lnet || return 3
300 check_mem_leak || return 254
302 echo "modules unloaded."
310 local dev=$(facet_active $facet)_dev
311 local opt=${facet}_opt
312 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
313 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
315 if [ $RC -ne 0 ]; then
316 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
317 echo "Start of ${!dev} on ${facet} failed ${RC}"
319 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
320 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
321 lctl set_param debug_mb=${DEBUG_SIZE}; \
324 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
325 [ -z "$label" ] && echo no label for ${!dev} && exit 1
326 eval export ${facet}_svc=${label}
327 echo Started ${label}
332 # start facet device options
338 eval export ${facet}_dev=${device}
339 eval export ${facet}_opt=\"$@\"
341 local varname=${facet}failover_dev
342 if [ -n "${!varname}" ] ; then
343 eval export ${facet}failover_dev=${!varname}
345 eval export ${facet}failover_dev=$device
348 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
358 HOST=`facet_active_host $facet`
359 [ -z $HOST ] && echo stop: no host for $facet && return 0
361 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
362 if [ ${running} -ne 0 ]; then
363 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
364 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
367 # umount should block, but we should wait for unrelated obd's
368 # like the MGS or MGC to also stop.
370 wait_exit_ST ${facet}
373 # set quota version (both administrative and operational quotas)
374 quota_set_version() {
375 do_facet mds "lctl set_param lquota.${FSNAME}-MDT*.quota_type=$1"
376 for j in `seq $OSTCOUNT`; do
377 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=$1"
381 # save quota version (both administrative and operational quotas)
382 # the function will also switch to the new version and the new type
383 quota_save_version() {
385 local ver=$(tr -c -d "123" <<< $spec)
386 local type=$(tr -c -d "ug" <<< $spec)
388 $LFS quotaoff -ug $MOUNT # just in case
389 [ -n "$ver" ] && quota_set_version $ver
390 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
392 do_facet mgs "lctl conf_param ${FSNAME}-MDT*.mdt.quota_type=$spec"
394 local osts=$(get_facets OST)
395 for ost in ${osts//,/ }; do
397 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
401 # client could mount several lustre
403 local fsname=${1:-$FSNAME}
405 do_facet mgs lctl get_param mds.${fsname}-MDT*.quota_type || rc=$?
406 do_nodes $(comma_list $(osts_nodes)) \
407 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
411 restore_quota_type () {
412 local mntpt=${1:-$MOUNT}
413 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
414 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
417 quota_save_version $old_QUOTA_TYPE
424 # 1. run quotacheck only if quota is off
425 # 2. save the original quota_type params, restore them after testing
427 # Suppose that quota type the same on mds and ost
428 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
429 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
430 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
431 export old_QUOTA_TYPE=$quota_type
432 quota_save_version $QUOTA_TYPE
435 local quota_usrs=$QUOTA_USERS
437 # get_filesystem_size
438 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
439 local blk_soft=$((disksz + 1024))
440 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
442 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
444 local i_hard=$((i_soft + i_soft / 20))
446 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
447 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
450 for usr in $quota_usrs; do
451 echo "Setting up quota on $client:$mntpt for $usr..."
453 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
455 eval $cmd || error "$cmd FAILED!"
457 # display the quota status
458 echo "Quota settings for $usr : "
459 $LFS quota -v -u $usr $mntpt || true
467 # Only supply -o to mount if we have options
468 if [ -n "$MOUNTOPT" ]; then
469 OPTIONS="-o $MOUNTOPT"
471 local device=$MGSNID:/$FSNAME
472 if [ -z "$mnt" -o -z "$FSNAME" ]; then
473 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
477 echo "Starting client: $client: $OPTIONS $device $mnt"
478 do_node $client mkdir -p $mnt
479 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
480 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
481 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
482 lctl set_param debug_mb=${DEBUG_SIZE}"
495 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
496 if [ $running -ne 0 ]; then
497 echo "Stopping client $client $mnt (opts:$force)"
498 do_node $client lsof -t $mnt || need_kill=no
499 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
500 pids=$(do_node $client lsof -t $mnt | sort -u);
501 if [ -n $pids ]; then
502 do_node $client kill -9 $pids || true
506 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
507 if [ $busy -ne 0 ] ; then
508 echo "$mnt is still busy, wait one second" && sleep 1
509 do_node $client umount $force $mnt
514 # nodes is comma list
515 sanity_mount_check_nodes () {
521 # FIXME: assume that all cluster nodes run the same os
522 [ "$(uname)" = Linux ] || return 0
525 for mnt in $mnts ; do
526 do_nodes $nodes "set -x; running=\\\$(grep -c $mnt' ' /proc/mounts);
527 mpts=\\\$(mount | grep -w -c $mnt);
528 if [ \\\$running -ne \\\$mpts ]; then
529 echo \\\$(hostname) env are INSANE!;
537 sanity_mount_check_servers () {
538 echo Checking servers environments
540 # FIXME: modify get_facets to display all facets wo params
541 local facets="$(get_facets OST),$(get_facets MDS)"
545 for facet in ${facets//,/ }; do
546 node=$(facet_host ${facet})
547 mnt=${MOUNT%/*}/${facet}
548 sanity_mount_check_nodes $node $mnt ||
549 { error "server $node environments are insane!"; return 1; }
553 sanity_mount_check_clients () {
554 local clients=${1:-$CLIENTS}
555 local mntpt=${2:-$MOUNT}
556 local mntpt2=${3:-$MOUNT2}
558 [ -z $clients ] && clients=$(hostname)
559 echo Checking clients $clients environments
561 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
562 error "clients environments are insane!"
565 sanity_mount_check () {
566 sanity_mount_check_servers || return 1
567 sanity_mount_check_clients || return 2
570 # mount clients if not mouted
571 zconf_mount_clients() {
576 # Only supply -o to mount if we have options
577 if [ -n "$MOUNTOPT" ]; then
578 OPTIONS="-o $MOUNTOPT"
580 local device=$MGSNID:/$FSNAME
581 if [ -z "$mnt" -o -z "$FSNAME" ]; then
582 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
586 echo "Starting client $clients: $OPTIONS $device $mnt"
588 do_nodes $clients "set -x;
589 running=\\\$(mount | grep -c $mnt' ');
591 if [ \\\$running -eq 0 ] ; then
593 mount -t lustre $OPTIONS $device $mnt;
598 echo "Started clients $clients: "
599 do_nodes $clients "mount | grep -w $mnt"
601 do_nodes $clients "sysctl -w lnet.debug=\\\"$PTLDEBUG\\\";
602 sysctl -w lnet.subsystem_debug=\\\"${SUBSYSTEM# }\\\";
603 sysctl -w lnet.debug_mb=${DEBUG_SIZE};"
608 zconf_umount_clients() {
615 echo "Stopping clients: $clients $mnt (opts:$force)"
616 do_nodes $clients "set -x; running=\\\$(grep -c $mnt' ' /proc/mounts);
617 if [ \\\$running -ne 0 ] ; then
618 echo Stopping client \\\$(hostname) client $mnt opts:$force;
619 lsof -t $mnt || need_kill=no;
620 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
621 pids=\\\$(lsof -t $mnt | sort -u);
622 if [ -n \\\"\\\$pids\\\" ]; then
626 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
627 if [ \\\$busy -ne 0 ] ; then
628 echo "$mnt is still busy, wait one second" && sleep 1;
634 shudown_node_hard () {
638 for i in $(seq $attempts) ; do
641 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
642 echo "waiting for $host to fail attempts=$attempts"
643 [ $i -lt $attempts ] || \
644 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
650 local mnt=${2:-$MOUNT}
653 if [ "$FAILURE_MODE" = HARD ]; then
654 shudown_node_hard $client
656 zconf_umount_clients $client $mnt -f
662 if [ "$FAILURE_MODE" = HARD ]; then
663 shudown_node_hard $(facet_active_host $facet)
664 elif [ "$FAILURE_MODE" = SOFT ]; then
671 if [ "$FAILURE_MODE" = HARD ]; then
672 $POWER_UP `facet_active_host $facet`
680 if [ "$FAILURE_MODE" = HARD ]; then
685 # recovery-scale functions
686 check_progs_installed () {
691 do_nodes $clients "set -x ; PATH=:$PATH; status=true;
692 for prog in $progs; do
693 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
694 echo \\\$prog missing on \\\$(hostname);
702 echo __$(echo $1 | tr '-' 'X')
705 start_client_load() {
708 local var=$(client_var_name $client)_load
709 eval export ${var}=$load
711 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
712 BREAK_ON_ERROR=$BREAK_ON_ERROR \
713 END_RUN_FILE=$END_RUN_FILE \
714 LOAD_PID_FILE=$LOAD_PID_FILE \
715 TESTSUITELOG=$TESTSUITELOG \
717 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
718 log "Started client load: ${load} on $client"
723 start_client_loads () {
724 local -a clients=(${1//,/ })
725 local numloads=${#CLIENT_LOADS[@]}
728 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
729 testnum=$((nodenum % numloads))
730 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
734 # only for remote client
735 check_client_load () {
737 local var=$(client_var_name $client)_load
738 local TESTLOAD=run_${!var}.sh
740 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
742 # bug 18914: try to connect several times not only when
743 # check ps, but while check_catastrophe also
746 while [ $RC = 254 -a $tries -gt 0 ]; do
750 if ! check_catastrophe $client; then
752 if [ $RC -eq 254 ]; then
753 # FIXME: not sure how long we shuold sleep here
757 echo "check catastrophe failed: RC=$RC "
762 # We can continue try to connect if RC=254
763 # Just print the warning about this
764 if [ $RC = 254 ]; then
765 echo "got a return status of $RC from do_node while checking catastrophe on $client"
768 # see if the load is still on the client
771 while [ $RC = 254 -a $tries -gt 0 ]; do
775 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
780 if [ $RC = 254 ]; then
781 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
782 # see if we can diagnose a bit why this is
787 check_client_loads () {
788 local clients=${1//,/ }
792 for client in $clients; do
793 check_client_load $client
795 if [ "$rc" != 0 ]; then
796 log "Client load failed on node $client, rc=$rc"
802 restart_client_loads () {
803 local clients=${1//,/ }
804 local expectedfail=${2:-""}
808 for client in $clients; do
809 check_client_load $client
811 if [ "$rc" != 0 -a "$expectedfail" ]; then
812 start_client_load $client
813 echo "Restarted client load: on $client. Checking ..."
814 check_client_load $client
816 if [ "$rc" != 0 ]; then
817 log "Client load failed to restart on node $client, rc=$rc"
818 # failure one client load means test fail
819 # we do not need to check other
827 # End recovery-scale functions
829 # verify that lustre actually cleaned up properly
831 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
832 error "LBUG/LASSERT detected"
833 BUSY=`dmesg | grep -i destruct || true`
836 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
840 check_mem_leak || exit 204
842 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
843 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
845 if [ "`/sbin/lsmod 2>&1 | egrep 'lnet|libcfs'`" ]; then
846 echo "$0: modules still loaded..." 1>&2
863 RESULT=$(do_node $node "$TEST")
864 if [ "$RESULT" == "$FINAL" ]; then
865 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
868 [ $WAIT -ge $MAX ] && break
869 echo "Waiting $((MAX - WAIT)) secs for update"
870 WAIT=$((WAIT + sleep))
873 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
877 wait_update_facet () {
880 wait_update $(facet_active_host $facet) "$@"
883 wait_delete_completed () {
884 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
885 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
889 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
891 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
892 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
893 [ "$TOTAL" -eq "$TOTALPREV" ] && break
894 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
898 echo "Delete completed."
903 check_network "$host" 900
904 while ! do_node $host "ls -d $LUSTRE " > /dev/null; do sleep 5; done
909 local host=`facet_active_host $facet`
913 wait_recovery_complete () {
916 # Use default policy if $2 is not passed by caller.
917 #define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
918 # as we are in process of changing obd_timeout in different ways
919 # let's set MAX longer than that
920 local MAX=${2:-$(( TIMEOUT * 4 ))}
922 local var_svc=${facet}_svc
923 local procfile="*.${!var_svc}.recovery_status"
927 while [ $WAIT -lt $MAX ]; do
928 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
929 [[ $STATUS = "status: COMPLETE" ]] && return 0
932 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
934 echo "$facet recovery not done in $MAX sec. $STATUS"
944 # conf-sanity 31 takes a long time cleanup
945 while [ $WAIT -lt 300 ]; do
946 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
947 [ -z "${running}" ] && return 0
948 echo "waited $WAIT for${running}"
949 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
951 WAIT=$((WAIT + INTERVAL))
953 echo "service didn't stop after $WAIT seconds. Still running:"
958 wait_remote_prog () {
964 [ "$PDSH" = "no_dsh" ] && return 0
966 while [ $WAIT -lt $2 ]; do
967 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
968 [ -z "${running}" ] && return 0 || true
969 echo "waited $WAIT for: "
971 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
973 WAIT=$((WAIT + INTERVAL))
975 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
976 [ -z "$pids" ] && return 0
977 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
978 # FIXME: not portable
980 cat /proc/${pid}/status || true
981 cat /proc/${pid}/wchan || true
992 # not every config has many clients
993 if [ -n "$CLIENTS" ]; then
994 $PDSH $CLIENTS "df $MOUNT" > /dev/null
996 df $MOUNT > /dev/null
1000 client_reconnect() {
1001 uname -n >> $MOUNT/recon
1002 if [ -z "$CLIENTS" ]; then
1003 df $MOUNT; uname -n >> $MOUNT/recon
1005 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1007 echo Connected clients:
1009 ls -l $MOUNT/recon > /dev/null
1016 echo "Failing $facet on node `facet_active_host $facet`"
1017 shutdown_facet $facet
1018 [ -n "$sleep_time" ] && sleep $sleep_time
1022 RECOVERY_START_TIME=`date +%s`
1023 echo "df pid is $DFPID"
1024 change_active $facet
1025 local TO=`facet_active_host $facet`
1026 echo "Failover $facet to $TO"
1028 mount_facet $facet || error "Restart of $facet failed"
1037 do_facet $facet sync
1039 local svc=${facet}_svc
1040 do_facet $facet $LCTL --device %${!svc} notransno
1041 do_facet $facet $LCTL --device %${!svc} readonly
1042 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1043 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1046 replay_barrier_nodf() {
1047 local facet=$1 echo running=${running}
1048 do_facet $facet sync
1049 local svc=${facet}_svc
1050 echo Replay barrier on ${!svc}
1051 do_facet $facet $LCTL --device %${!svc} notransno
1052 do_facet $facet $LCTL --device %${!svc} readonly
1053 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1054 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1057 mds_evict_client() {
1058 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
1059 local mdtdevice=$(get_mds_mdt_device_proc_path)
1060 do_facet mds "lctl set_param -n ${mdtdevice}.${mds_svc}.evict_client $UUID"
1063 ost_evict_client() {
1064 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
1065 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1069 facet_failover $* || error "failover: $?"
1070 df $MOUNT || error "post-failover df: $?"
1075 facet_failover $facet
1081 change_active $facet
1082 mount_facet $facet -o abort_recovery
1083 df $MOUNT || echo "first df failed: $?"
1085 df $MOUNT || error "post-failover df: $?"
1089 echo There is no lmc. This is mountconf, baby.
1094 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1095 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1101 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1107 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1108 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1109 if [ -z "$ID" ]; then
1110 echo "Could not get a ptl id for $1..."
1119 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1126 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1127 if type __h2elan >/dev/null 2>&1; then
1130 ID=`echo $1 | sed 's/[^0-9]*//g'`
1138 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1139 ID=`echo $1 | sed 's/[^0-9]*//g'`
1143 declare -fx h2openib
1146 h2name_or_ip "$1" "o2ib"
1153 [ "$facet" == client ] && echo -n $HOSTNAME && return
1154 varname=${facet}_HOST
1155 if [ -z "${!varname}" ]; then
1156 if [ "${facet:0:3}" == "ost" ]; then
1157 eval ${facet}_HOST=${ost_HOST}
1165 local activevar=${facet}active
1167 if [ -f $TMP/${facet}active ] ; then
1168 source $TMP/${facet}active
1171 active=${!activevar}
1172 if [ -z "$active" ] ; then
1179 facet_active_host() {
1181 local active=`facet_active $facet`
1182 if [ "$facet" == client ]; then
1185 echo `facet_host $active`
1191 local failover=${facet}failover
1192 host=`facet_host $failover`
1193 [ -z "$host" ] && return
1194 local curactive=`facet_active $facet`
1195 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1196 eval export ${facet}active=$facet
1198 eval export ${facet}active=$failover
1200 # save the active host for this facet
1201 local activevar=${facet}active
1202 echo "$activevar=${!activevar}" > $TMP/$activevar
1209 if [ "$HOST" = "$HOSTNAME" ]; then
1211 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1212 echo "cannot run remote command on $HOST with $myPDSH"
1216 echo "CMD: $HOST $@" >&2
1217 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1220 if [ "$myPDSH" = "rsh" ]; then
1221 # we need this because rsh does not return exit code of an executed command
1222 local command_status="$TMP/cs"
1223 rsh $HOST ":> $command_status"
1224 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1225 cd $RPWD; sh -c \"$@\") ||
1226 echo command failed >$command_status"
1227 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1230 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1231 return ${PIPESTATUS[0]}
1234 single_local_node () {
1235 [ "$1" = "$HOSTNAME" ]
1242 if $(single_local_node $rnodes); then
1247 # This is part from do_node
1250 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1251 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1254 echo "CMD: $rnodes $@" >&2
1255 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1258 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/\w+:\s//g"
1259 return ${PIPESTATUS[0]}
1265 local HOST=`facet_active_host $facet`
1266 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1273 # make sure its not already running
1275 rm -f $TMP/${facet}active
1276 do_facet ${facet} $MKFS $*
1282 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1283 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1291 # make sure we are using the primary server, so test-framework will
1292 # be able to clean up properly.
1293 activemds=`facet_active mds`
1294 if [ $activemds != "mds" ]; then
1298 local clients=$CLIENTS
1299 [ -z $clients ] && clients=$(hostname)
1301 zconf_umount_clients $clients $MOUNT "$*" || true
1302 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1304 [ "$CLIENTONLY" ] && return
1305 # The add fn does rm ${facet}active file, this would be enough
1306 # if we use do_facet <facet> only after the facet added, but
1307 # currently we use do_facet mds in local.sh
1309 rm -f ${TMP}/mdsactive
1310 for num in `seq $OSTCOUNT`; do
1312 rm -f $TMP/ost${num}active
1323 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1326 # We need ldiskfs here, may as well load them all
1328 [ "$CLIENTONLY" ] && return
1329 echo Formatting mds, osts
1331 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
1333 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
1336 for num in `seq $OSTCOUNT`; do
1338 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1340 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1346 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1351 zconf_umount `hostname` $1 || error "umount failed"
1352 zconf_mount `hostname` $1 || error "mount failed"
1355 writeconf_facet () {
1359 do_facet $facet "$TUNEFS --writeconf $dev"
1363 writeconf_facet mds $MDSDEV
1365 for num in `seq $OSTCOUNT`; do
1366 DEVNAME=`ostdevname $num`
1367 writeconf_facet ost$num $DEVNAME
1372 sanity_mount_check ||
1373 error "environments are insane!"
1376 if [ -z "$CLIENTONLY" ]; then
1377 echo Setup mdt, osts
1379 echo $WRITECONF | grep -q "writeconf" && \
1382 start mds $MDSDEV $MDS_MOUNT_OPTS
1383 # We started mds, now we should set failover variable properly.
1384 # Set mdsfailover_HOST if it is not set (the default failnode).
1385 if [ -z "$mdsfailover_HOST" ]; then
1386 mdsfailover_HOST=$(facet_host mds)
1389 for num in `seq $OSTCOUNT`; do
1390 DEVNAME=`ostdevname $num`
1391 start ost$num $DEVNAME $OST_MOUNT_OPTS
1393 # We started ost$num, now we should set ost${num}failover variable properly.
1394 # Set ost${num}failover_HOST if it is not set (the default failnode).
1395 varname=ost${num}failover_HOST
1396 if [ -z "${!varname}" ]; then
1397 eval ost${num}failover_HOST=$(facet_host ost${num})
1402 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1404 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1406 if [ "$MOUNT_2" ]; then
1407 mount_client $MOUNT2
1408 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1414 mounted_lustre_filesystems() {
1415 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1418 init_facet_vars () {
1425 eval export ${facet}_dev=${device}
1426 eval export ${facet}_opt=\"$@\"
1428 local dev=${facet}_dev
1429 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1430 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1432 eval export ${facet}_svc=${label}
1434 local varname=${facet}failover_HOST
1435 if [ -z "${!varname}" ]; then
1436 eval $varname=$(facet_host $facet)
1439 # ${facet}failover_dev is set in cfg file
1440 varname=${facet}failover_dev
1441 if [ -n "${!varname}" ] ; then
1442 eval export ${facet}failover_dev=${!varname}
1444 eval export ${facet}failover_dev=$device
1448 init_facets_vars () {
1450 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
1452 remote_ost_nodsh && return
1454 for num in `seq $OSTCOUNT`; do
1455 DEVNAME=`ostdevname $num`
1456 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1460 init_param_vars () {
1461 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1462 export MDSVER=$(do_facet mds "lctl get_param version" | cut -d. -f1,2)
1463 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1464 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1468 TIMEOUT=$(do_facet mds "lctl get_param -n timeout")
1470 log "Using TIMEOUT=$TIMEOUT"
1472 if [ "$ENABLE_QUOTA" ]; then
1473 setup_quota $MOUNT || return 2
1479 local myMGS_host=$mgs_HOST
1480 if [ "$NETTYPE" = "ptl" ]; then
1481 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1484 echo Checking config lustre mounted on $mntpt
1485 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1486 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1488 if [ "$mgshost" != "$myMGS_host" ]; then
1489 log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1490 Please use correct config or set mds_HOST correctly!"
1493 sanity_mount_check ||
1494 error "environments are insane!"
1498 local mdstimeout=$(do_facet mds "lctl get_param -n timeout")
1499 local cltimeout=$(lctl get_param -n timeout)
1500 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
1501 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
1506 check_and_setup_lustre() {
1507 local MOUNTED=$(mounted_lustre_filesystems)
1508 if [ -z "$MOUNTED" ] || ! $(echo $MOUNTED | grep -w -q $MOUNT); then
1509 [ "$REFORMAT" ] && formatall
1511 MOUNTED=$(mounted_lustre_filesystems | head -1)
1512 [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
1513 export I_MOUNTED=yes
1519 if [ "$ONLY" == "setup" ]; then
1524 cleanup_and_setup_lustre() {
1525 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
1526 lctl set_param debug=0 || true
1528 if [ "$ONLY" == "cleanup" ]; then
1532 check_and_setup_lustre
1535 check_and_cleanup_lustre() {
1536 if [ "`mount | grep $MOUNT`" ]; then
1537 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
1538 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
1540 if [ "$I_MOUNTED" = "yes" ]; then
1541 cleanupall -f || error "cleanup failed"
1553 while [ $NETWORK -eq 0 ]; do
1554 ping -c 1 -w 3 $1 > /dev/null
1555 if [ $? -eq 0 ]; then
1559 echo "waiting for $1, $((MAX - WAIT)) secs left"
1562 if [ $WAIT -gt $MAX ]; then
1563 echo "Network not available"
1569 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
1580 # the sed converts spaces to commas, but leaves the last space
1581 # alone, so the line doesn't end with a comma.
1582 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
1585 # list, excluded are the comma separated lists
1586 exclude_items_from_list () {
1592 for item in ${excluded//,/ }; do
1593 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
1595 echo $(comma_list $list)
1598 # list, expand are the comma separated lists
1600 local list=${1//,/ }
1601 local expand=${2//,/ }
1604 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
1605 echo $(comma_list $expanded)
1609 (cd `dirname $1`; echo $PWD/`basename $1`)
1613 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
1614 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
1620 OST ) for ((i=1; i<=$OSTCOUNT; i++)) do
1621 list="$list ${name}$i"
1623 * ) error "Invalid facet type"
1626 echo $(comma_list $list)
1629 ##################################
1630 # Adaptive Timeouts funcs
1633 # only check mds, we assume at_max is the same on all nodes
1634 local at_max=$(do_facet mds "lctl get_param -n at_max")
1635 if [ $at_max -eq 0 ]; then
1645 # suppose that all ost-s has the same at_max set
1646 if [ $facet == "ost" ]; then
1647 do_facet ost1 "lctl get_param -n at_max"
1649 do_facet $facet "lctl get_param -n at_max"
1659 if [ $facet == "ost" ]; then
1660 for i in `seq $OSTCOUNT`; do
1661 do_facet ost$i "lctl set_param at_max=$at_max"
1664 do_facet $facet "lctl set_param at_max=$at_max"
1669 ##################################
1673 # OBD_FAIL_MDS_ALL_REQUEST_NET
1675 do_facet mds lctl set_param fail_loc=0x123
1676 do_facet client "$1" || RC=$?
1677 do_facet mds lctl set_param fail_loc=0
1682 # OBD_FAIL_MDS_ALL_REPLY_NET
1684 do_facet mds lctl set_param fail_loc=0x122
1685 do_facet client "$@" || RC=$?
1686 do_facet mds lctl set_param fail_loc=0
1690 drop_reint_reply() {
1691 # OBD_FAIL_MDS_REINT_NET_REP
1693 do_facet mds lctl set_param fail_loc=0x119
1694 do_facet client "$@" || RC=$?
1695 do_facet mds lctl set_param fail_loc=0
1700 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1702 do_facet ost1 lctl set_param fail_loc=0x214
1703 do_facet client "$1" || RC=$?
1704 do_facet client "sync"
1705 do_facet ost1 lctl set_param fail_loc=0
1709 drop_ldlm_cancel() {
1710 #define OBD_FAIL_LDLM_CANCEL 0x304
1712 do_facet client lctl set_param fail_loc=0x304
1713 do_facet client "$@" || RC=$?
1714 do_facet client lctl set_param fail_loc=0
1718 drop_bl_callback() {
1719 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
1721 do_facet client lctl set_param fail_loc=0x305
1722 do_facet client "$@" || RC=$?
1723 do_facet client lctl set_param fail_loc=0
1728 #define OBD_FAIL_LDLM_REPLY 0x30c
1730 do_facet mds lctl set_param fail_loc=0x30c
1731 do_facet client "$@" || RC=$?
1732 do_facet mds lctl set_param fail_loc=0
1740 echo "clearing fail_loc on $facet"
1741 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
1744 set_nodes_failloc () {
1748 for node in $nodes ; do
1749 do_node $node lctl set_param fail_loc=$2
1753 cancel_lru_locks() {
1754 $LCTL mark "cancel_lru_locks $1 start"
1755 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
1756 $LCTL set_param -n $d=clear
1758 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
1759 $LCTL mark "cancel_lru_locks $1 stop"
1764 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
1765 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
1766 echo "$DEFAULT_LRU_SIZE"
1771 lctl set_param ldlm.namespaces.*$1*.lru_size=0
1774 lru_resize_disable()
1776 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
1781 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
1782 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
1783 echo there is still data in page cache $FILE ?
1784 lctl get_param -n $FILE
1791 create_fake_exports () {
1794 #obd_fail_val = num;
1795 #define OBD_FAIL_TGT_FAKE_EXP 0x708
1796 do_facet $facet "lctl set_param fail_val=$num"
1797 do_facet $facet "lctl set_param fail_loc=0x80000708"
1802 DEBUGSAVE="$(lctl get_param -n debug)"
1806 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
1810 ##################################
1812 ##################################
1815 local TYPE=${TYPE:-"FAIL"}
1817 lctl set_param fail_loc=0 2>/dev/null || true
1818 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
1819 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
1820 echo "Dumping lctl log to $ERRLOG"
1821 # We need to dump the logs on all nodes
1822 local NODES=$(nodes_list)
1823 for NODE in $NODES; do
1824 do_node $NODE $LCTL dk $ERRLOG
1827 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
1833 $FAIL_ON_ERROR && exit 1 || true
1841 # use only if we are ignoring failures for this test, bugno required.
1842 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
1843 # e.g. error_ignore 5494 "your message"
1845 local TYPE="IGNORE (bz$1)"
1851 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
1852 [ "$TESTSUITELOG" ] && \
1853 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
1856 build_test_filter() {
1857 [ "$ONLY" ] && log "only running test `echo $ONLY`"
1861 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
1862 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
1863 [ "$EXCEPT_SLOW" ] && \
1864 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
1865 for E in $EXCEPT $ALWAYS_EXCEPT; do
1866 eval EXCEPT_${E}=true
1868 for E in $EXCEPT_SLOW; do
1869 eval EXCEPT_SLOW_${E}=true
1871 for G in $GRANT_CHECK_LIST; do
1872 eval GCHECK_ONLY_${G}=true
1881 IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
1884 # print a newline if the last test was skipped
1885 export LAST_SKIPPED=
1889 export base=`basetest $1`
1890 if [ ! -z "$ONLY" ]; then
1892 if [ ${!testname}x != x ]; then
1893 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1898 if [ ${!testname}x != x ]; then
1899 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
1908 if [ ${!testname}x != x ]; then
1910 TESTNAME=test_$1 skip "skipping excluded test $1"
1913 testname=EXCEPT_$base
1914 if [ ${!testname}x != x ]; then
1916 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
1919 testname=EXCEPT_SLOW_$1
1920 if [ ${!testname}x != x ]; then
1922 TESTNAME=test_$1 skip "skipping SLOW test $1"
1925 testname=EXCEPT_SLOW_$base
1926 if [ ${!testname}x != x ]; then
1928 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
1938 EQUALS="======================================================================"
1942 local suffixlen=$((${#EQUALS} - ${#msg}))
1943 [ $suffixlen -lt 5 ] && suffixlen=5
1944 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
1949 lsmod | grep lnet > /dev/null || load_modules
1961 local NODES=$(nodes_list)
1962 for NODE in $NODES; do
1963 do_node $NODE $LCTL mark "$MSG" 2> /dev/null || true
1969 strace -o $TMP/$1.strace -ttt $*
1971 log "FINISHED: $*: rc $RC"
1976 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
1981 FFREE=`lctl get_param -n mds.*.filesfree`
1982 FTOTAL=`lctl get_param -n mds.*.filestotal`
1983 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
1987 local myNODES=$(nodes_list)
1990 echo -n "Resetting fail_loc on all nodes..."
1991 for NODE in $myNODES; do
1992 do_node $NODE "lctl set_param -n fail_loc=0 2>/dev/null || true"
2001 export tdir=d0.${TESTSUITE}/d${base}
2003 local SAVE_UMASK=`umask`
2006 local BEFORE=`date +%s`
2008 log "== test $testnum: $message == `date +%H:%M:%S` ($BEFORE)"
2010 export TESTNAME=test_$testnum
2012 test_${testnum} || error "test_$testnum failed with $?"
2016 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2017 check_catastrophe || error "LBUG/LASSERT detected"
2018 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2019 pass "($((`date +%s` - $BEFORE))s)"
2027 (cd `dirname $1`; echo $PWD/`basename $1`)
2031 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2032 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2037 export base=`basetest $1`
2038 [ "$CHECK_GRANT" == "no" ] && return 0
2040 testname=GCHECK_ONLY_${base}
2041 [ ${!testname}x == x ] && return 0
2043 echo -n "checking grant......"
2045 # write some data to sync client lost_grant
2046 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2047 for i in `seq $OSTCOUNT`; do
2048 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2049 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2050 count=1 > /dev/null 2>&1
2052 # sync all the data and make sure no pending data on server
2055 #get client grant and server grant
2057 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2058 client_grant=$((client_grant + $d))
2061 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2062 server_grant=$((server_grant + $d))
2065 # cleanup the check_grant file
2066 for i in `seq $OSTCOUNT`; do
2067 rm $DIR1/${tfile}_check_grant_$i
2070 #check whether client grant == server grant
2071 if [ $client_grant != $server_grant ]; then
2072 echo "failed: client:${client_grant} server: ${server_grant}"
2079 ########################
2085 ost=`echo $1 | awk -F_ '{print $3}'`
2086 if [ -z $ost ]; then
2087 ost=`echo $1 | sed 's/-osc.*//'`
2094 [ "$node" != "$(hostname)" ]
2099 remote_node $mds_HOST
2104 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2110 for node in $(osts_nodes) ; do
2111 remote_node $node && return 0
2118 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2124 MGS=$(facet_host mgs)
2125 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2129 remote_ost && remote_mds
2133 local OSTNODES=$(facet_host ost1)
2136 for num in `seq $OSTCOUNT`; do
2137 local myOST=$(facet_host ost$num)
2138 OSTNODES="$OSTNODES $myOST"
2140 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
2146 # FIXME. We need a list of clients
2147 local myNODES=$HOSTNAME
2150 # CLIENTS (if specified) contains the local client
2151 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
2153 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
2154 myNODES="$myNODES $(osts_nodes) $mds_HOST"
2157 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
2162 remote_nodes_list () {
2163 local rnodes=$(nodes_list)
2164 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2168 init_clients_lists () {
2169 # Sanity check: exclude the local client from RCLIENTS
2170 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2172 # Sanity check: exclude the dup entries
2173 rclients=$(for i in $rclients; do echo $i; done | sort -u)
2175 local clients="$SINGLECLIENT $HOSTNAME $rclients"
2177 # Sanity check: exclude the dup entries from CLIENTS
2178 # for those configs which has SINGLCLIENT set to local client
2179 clients=$(for i in $clients; do echo $i; done | sort -u)
2181 CLIENTS=`comma_list $clients`
2182 local -a remoteclients=($rclients)
2183 for ((i=0; $i<${#remoteclients[@]}; i++)); do
2184 varname=CLIENT$((i + 2))
2185 eval $varname=${remoteclients[i]}
2188 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
2191 get_random_entry () {
2194 rnodes=${rnodes//,/ }
2196 local -a nodes=($rnodes)
2197 local num=${#nodes[@]}
2198 local i=$((RANDOM * num * 2 / 65536))
2205 lctl get_param version | grep -q patchless
2209 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
2214 echo $nodes | wc -w || true
2218 local nodes=$(osts_nodes)
2219 local osscount=$(get_node_count "$nodes")
2220 [ ! "$OSTCOUNT" = "$osscount" ]
2223 generate_machine_file() {
2224 local nodes=${1//,/ }
2225 local machinefile=$2
2226 rm -f $machinefile || error "can't rm $machinefile"
2227 for node in $nodes; do
2228 echo $node >>$machinefile
2233 local file=$1/stripe
2235 $LFS getstripe -v $file || error
2239 check_runas_id_ret() {
2241 local myRUNAS_UID=$1
2242 local myRUNAS_GID=$2
2245 if [ -z "$myRUNAS" ]; then
2246 error_exit "myRUNAS command must be specified for check_runas_id"
2248 mkdir $DIR/d0_runas_test
2250 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
2251 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=1
2252 rm -rf $DIR/d0_runas_test
2257 local myRUNAS_UID=$1
2258 local myRUNAS_GID=$2
2261 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
2262 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
2263 Please set RUNAS_ID to some UID which exists on MDS and client or
2264 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
2267 # Run multiop in the background, but wait for it to print
2268 # "PAUSING" to its stdout before returning from this function.
2269 multiop_bg_pause() {
2270 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
2274 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
2277 echo "$MULTIOP_PROG $FILE v$ARGS"
2278 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
2280 echo "TMPPIPE=${TMPPIPE}"
2281 local multiop_output
2284 read -t 60 multiop_output multiop_pid < $TMPPIPE
2285 if [ $? -ne 0 ]; then
2290 if [ "$multiop_output" != "PAUSING" ]; then
2291 echo "Incorrect multiop output: $multiop_output"
2307 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
2313 inodes_available () {
2314 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
2318 # reset llite stat counters
2319 clear_llite_stats(){
2320 lctl set_param -n llite.*.stats 0
2323 # sum llite stat items
2324 calc_llite_stats() {
2325 local res=$(lctl get_param -n llite.*.stats |
2326 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
2331 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
2334 calc_osc_kbytes () {
2335 df $MOUNT > /dev/null
2336 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
2339 # save_lustre_params(node, parameter_mask)
2340 # generate a stream of formatted strings (<node> <param name>=<param value>)
2341 save_lustre_params() {
2343 do_node $1 "lctl get_param $2" | while read s; do echo "$1 $s"; done
2346 # restore lustre parameters from input stream, produces by save_lustre_params
2347 restore_lustre_params() {
2351 while IFS=" =" read node name val; do
2352 do_node $node "lctl set_param -n $name $val"
2356 check_catastrophe() {
2357 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
2358 local C=$CATASTROPHE
2359 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
2361 if [ $rnodes ]; then
2362 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
2363 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
2379 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
2381 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
2382 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
2383 stripe_index=`awk '/obdidx/ {start = 1; getline; print $1; exit}' $tmp_file`
2387 mdsrate_cleanup () {
2388 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
2391 delayed_recovery_enabled () {
2392 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
2395 ################################################################################
2396 # The following functions are used to enable interop testing between
2397 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
2399 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
2400 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
2401 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
2402 ################################################################################
2404 get_lustre_version () {
2405 local node=${1:-"mds"}
2406 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
2409 get_mds_version_major () {
2410 local version=$(get_lustre_version mds)
2411 echo $version | awk -F. '{print $1}'
2414 get_mds_version_minor () {
2415 local version=$(get_lustre_version mds)
2416 echo $version | awk -F. '{print $2}'
2419 get_mds_version_patch () {
2420 local version=$(get_lustre_version mds)
2421 echo $version | awk -F. '{print $3}'
2424 get_mds_version_fix () {
2425 local version=$(get_lustre_version mds)
2426 echo $version | awk -F. '{print $4}'
2429 get_mds_fsstat_proc_path() {
2430 local major=$(get_mds_version_major)
2431 local minor=$(get_mds_version_minor)
2432 if [ $major -le 1 -a $minor -le 8 ] ; then
2439 get_mds_mntdev_proc_path() {
2440 local fsstat_dev=$(get_mds_fsstat_proc_path)
2441 echo "$fsstat_dev.*.mntdev"
2444 get_mdtlov_proc_path() {
2446 local major=$(get_mds_version_major)
2447 local minor=$(get_mds_version_minor)
2448 if [ $major -le 1 -a $minor -le 8 ] ; then
2449 echo "${fsname}-mdtlov"
2451 echo "${fsname}-MDT0000-mdtlov"
2455 get_mdtosc_proc_path() {
2457 local major=$(get_mds_version_major)
2458 local minor=$(get_mds_version_minor)
2459 if [ $major -le 1 -a $minor -le 8 ] ; then
2462 echo "${ost}-osc-MDT0000"
2466 get_mds_mdt_device_proc_path() {
2467 local major=$(get_mds_version_major)
2468 local minor=$(get_mds_version_minor)
2469 if [ $major -le 1 -a $minor -le 8 ] ; then
2476 ########################
2477 convert_facet2name() {
2479 "ost" ) echo "OST0000" ;;
2480 "ost1") echo "OST0000" ;;
2481 "ost2") echo "OST0001" ;;
2482 "ost3") echo "OST0002" ;;
2483 "ost4") echo "OST0003" ;;
2484 "ost5") echo "OST0004" ;;
2485 *) error "unknown facet!" ;;
2489 get_clientosc_proc_path() {
2495 get_osc_import_name() {
2498 local name=$(convert_facet2name $ost)
2500 if [ "$node" == "mds" ]; then
2501 get_mdtosc_proc_path $name
2505 get_clientosc_proc_path $name
2509 wait_osc_import_state() {
2513 local ost=$(get_osc_import_name $node $ost_facet)
2518 CONN_PROC="osc.${FSNAME}-${ost}.ost_server_uuid"
2519 CONN_STATE=$(do_facet $node lctl get_param -n $CONN_PROC | cut -f2)
2520 while [ "${CONN_STATE}" != "${expected}" ]; do
2521 # for disconn we can check after proc entry is removed
2522 [ "x${CONN_STATE}" == "x" -a "${expected}" == "DISCONN" ] && return 0
2523 # disconnect rpc should be wait not more obd_timeout
2524 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
2525 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
2527 CONN_STATE=$(do_facet $node lctl get_param -n $CONN_PROC | cut -f2)
2531 log "${ost_facet} now in ${CONN_STATE} state"