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
20 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
22 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
24 if [ -f "$EXCEPT_LIST_FILE" ]; then
25 echo "Reading test skip list from $EXCEPT_LIST_FILE"
32 [[ $DIR/ = $MOUNT/* ]] || \
33 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
34 [[ $DIR1/ = $MOUNT1/* ]] || \
35 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
36 [[ $DIR2/ = $MOUNT2/* ]] || \
37 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
39 [ -n "$failed" ] && exit 99 || true
43 echo "usage: $0 [-r] [-f cfgfile]"
51 [ "$TESTSUITE" == "lfscktest" ] && return 0
52 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
53 local form="%-13s %-17s %s\n"
54 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
55 echo "------------------------------------------------------------------------------------"
56 for O in $TESTSUITE_LIST; do
59 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
62 local log=${TMP}/${o}.log
63 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
64 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
65 [ "${!O}" = "done" ] && \
66 printf "$form" "Done" "$O" "E=$skipped" && \
67 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
71 for O in $TESTSUITE_LIST; do
72 if [ "${!O}" = "no" ]; then
74 # only for those tests suits which are run directly from acc-sm script:
75 # bonnie, iozone, etc.
76 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
77 printf "$form" "UNFINISHED" "$O" ""
79 printf "$form" "Skipped" "$O" ""
84 for O in $TESTSUITE_LIST; do
85 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
86 printf "$form" "UNFINISHED" "$O" ""
91 export LUSTRE=`absolute_path $LUSTRE`
92 export TESTSUITE=`basename $0 .sh`
93 export TEST_FAILED=false
94 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
96 export MKE2FS=${MKE2FS:-mke2fs}
97 export DEBUGFS=${DEBUGFS:-debugfs}
98 export TUNE2FS=${TUNE2FS:-tune2fs}
99 export E2LABEL=${E2LABEL:-e2label}
100 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
101 export E2FSCK=${E2FSCK:-e2fsck}
102 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
103 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check filesystem after each test suit
104 export SKIP_LFSCK=${SKIP_LFSCK:-"yes"} # bug 13698, change to "no" when fixed
105 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-"/tmp"}
106 export FSCK_MAX_ERR=4 # File system errors left uncorrected
107 if [ "$SKIP_LFSCK" == "no" ]; then
108 if [ ! -x `which $LFSCK_BIN` ]; then
110 error_exit "$E2FSCK does not support lfsck"
113 export MDSDB=${MDSDB:-$SHARED_DIRECTORY/mdsdb}
114 export OSTDB=${OSTDB:-$SHARED_DIRECTORY/ostdb}
115 export MDSDB_OPT="--mdsdb $MDSDB"
116 export OSTDB_OPT="--ostdb $OSTDB-\$ostidx"
120 #[ -d /r ] && export ROOT=${ROOT:-/r}
121 export TMP=${TMP:-$ROOT/tmp}
122 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
123 export HOSTNAME=${HOSTNAME:-`hostname`}
124 if ! echo $PATH | grep -q $LUSTRE/utils; then
125 export PATH=$PATH:$LUSTRE/utils
127 if ! echo $PATH | grep -q $LUSTRE/test; then
128 export PATH=$PATH:$LUSTRE/tests
130 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
131 [ ! -f "$LST" ] && export LST=$(which lst)
132 export SGPDDSURVEY=${SGPDDSURVEY:-$(which sgpdd-survey)}
133 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
134 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
135 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
136 export PATH=$PATH:$LUSTRE/tests/racer
138 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
139 export PATH=$PATH:$LUSTRE/tests/mpi
141 export RSYNC_RSH=${RSYNC_RSH:-rsh}
142 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
143 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
144 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
145 [ ! -f "$LFS" ] && export LFS=$(which lfs)
146 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
147 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
148 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
149 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
150 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
151 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
152 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
153 export FSTYPE=${FSTYPE:-"ldiskfs"}
154 export NAME=${NAME:-local}
156 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
158 if [ "$ACCEPTOR_PORT" ]; then
159 export PORT_OPT="--port $ACCEPTOR_PORT"
162 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
164 # Paths on remote nodes, if different
165 export RLUSTRE=${RLUSTRE:-$LUSTRE}
166 export RPWD=${RPWD:-$PWD}
167 export I_MOUNTED=${I_MOUNTED:-"no"}
168 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
169 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
170 ! -f `dirname $0`/../mds/mds.ko ]; then
171 export CLIENTMODSONLY=yes
176 while getopts "rvwf:" opt $*; do
179 r) REFORMAT=--reformat;;
181 w) WRITECONF=writeconf;;
186 shift $((OPTIND - 1))
189 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
194 *) EXT=".ko"; USE_QUOTA=yes;;
198 do_facet mgs lctl pool_list $1
202 local fsname=${1%%.*}
203 local poolname=${1##$fsname.}
205 do_facet mgs lctl pool_new $1
207 # get param should return err unless pool is created
208 [[ $RC -ne 0 ]] && return $RC
210 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
211 2>/dev/null || echo foo" "" || RC=1
212 if [[ $RC -eq 0 ]]; then
215 error "pool_new failed $1"
220 add_pool_to_list () {
221 local fsname=${1%%.*}
222 local poolname=${1##$fsname.}
224 local listvar=${fsname}_CREATED_POOLS
225 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
228 remove_pool_from_list () {
229 local fsname=${1%%.*}
230 local poolname=${1##$fsname.}
232 local listvar=${fsname}_CREATED_POOLS
233 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
237 /sbin/lsmod | grep -q $1
243 BASE=`basename $module $EXT`
245 module_loaded ${BASE} && return
247 if [ "$BASE" == "lnet_selftest" ] && \
248 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
249 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
251 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
252 insmod ${LUSTRE}/${module}${EXT} $@
254 # must be testing a "make install" or "rpm" installation
259 load_modules_local() {
260 if [ -n "$MODPROBE" ]; then
264 if [ "$HAVE_MODULES" = true ]; then
270 echo Loading modules from $LUSTRE
271 load_module ../lnet/libcfs/libcfs
272 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
273 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
275 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
276 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
277 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
278 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
279 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
281 # disable it for now since it only hides the stack overflow upon test w/
283 # if [ "$NETTYPE" = "tcp" -o "$NETTYPE" = "o2ib" -o "$NETTYPE" = "ptl" ]; then
284 # echo $LNETOPTS | grep -q "local_nid_dist_zero=0" ||
285 # LNETOPTS="$LNETOPTS local_nid_dist_zero=0"
287 echo "lnet options: '$LNETOPTS'"
288 # note that insmod will ignore anything in modprobe.conf
289 load_module ../lnet/lnet/lnet $LNETOPTS
290 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
291 load_module ../lnet/klnds/$LNETLND
292 load_module lvfs/lvfs
293 load_module obdclass/obdclass
294 load_module ptlrpc/ptlrpc
295 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota $LQUOTAOPTS
300 if ! client_only; then
303 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
304 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
305 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
306 load_module lvfs/fsfilt_$FSTYPE
308 load_module obdfilter/obdfilter
311 load_module llite/lustre
312 load_module llite/llite_lloop
313 rm -f $TMP/ogdb-$HOSTNAME
315 [ -d /r ] && OGDB="/r/tmp"
316 $LCTL modules > $OGDB/ogdb-$HOSTNAME
317 # 'mount' doesn't look in $PATH, just sbin
318 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
324 # load modules on remote nodes optionally
325 # lustre-tests have to be installed on these nodes
326 if $LOAD_MODULES_REMOTE ; then
327 local list=$(comma_list $(remote_nodes_list))
328 echo loading modules on $list
329 do_rpc_nodes $list load_modules
334 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
335 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
336 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
337 echo "$LEAK_LUSTRE" 1>&2
338 echo "$LEAK_PORTALS" 1>&2
339 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
340 echo "Memory leaks detected"
341 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
347 wait_exit_ST client # bug 12845
349 if $LOAD_MODULES_REMOTE ; then
350 local list=$(comma_list $(remote_nodes_list))
351 if [ ! -z $list ]; then
352 echo unloading modules on $list
353 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
354 do_rpc_nodes $list check_mem_leak
358 $LUSTRE_RMMOD $FSTYPE || return 2
362 check_mem_leak || return 254
364 echo "modules unloaded."
372 local dev=$(facet_active $facet)_dev
373 local opt=${facet}_opt
374 local mntpt=$(facet_mntpt $facet)
376 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
377 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} $mntpt
379 if [ $RC -ne 0 ]; then
380 echo "mount -t lustre $@ ${!dev} $mntpt"
381 echo "Start of ${!dev} on ${facet} failed ${RC}"
383 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
384 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
385 lctl set_param debug_mb=${DEBUG_SIZE}; \
388 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
389 [ -z "$label" ] && echo no label for ${!dev} && exit 1
390 eval export ${facet}_svc=${label}
391 echo Started ${label}
396 # start facet device options
402 eval export ${facet}_dev=${device}
403 eval export ${facet}_opt=\"$@\"
405 local varname=${facet}failover_dev
406 if [ -n "${!varname}" ] ; then
407 eval export ${facet}failover_dev=${!varname}
409 eval export ${facet}failover_dev=$device
412 local mntpt=$(facet_mntpt $facet)
413 do_facet ${facet} mkdir -p $mntpt
414 eval export ${facet}_MOUNT=$mntpt
424 local HOST=`facet_active_host $facet`
425 [ -z $HOST ] && echo stop: no host for $facet && return 0
427 local mntpt=$(facet_mntpt $facet)
428 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
429 if [ ${running} -ne 0 ]; then
430 echo "Stopping $mntpt (opts:$@)"
431 do_facet ${facet} umount -d $@ $mntpt
434 # umount should block, but we should wait for unrelated obd's
435 # like the MGS or MGC to also stop.
437 wait_exit_ST ${facet}
440 # set quota version (both administrative and operational quotas)
441 quota_set_version() {
442 do_facet mds "lctl set_param lquota.${FSNAME}-MDT*.quota_type=$1"
444 local osts=$(get_facets OST)
445 for ost in ${osts//,/ }; do
447 do_facet $ost "lctl set_param lquota.${!varsvc}.quota_type=$1"
451 # save quota version (both administrative and operational quotas)
452 # the function will also switch to the new version and the new type
453 quota_save_version() {
455 local ver=$(tr -c -d "123" <<< $spec)
456 local type=$(tr -c -d "ug" <<< $spec)
458 local lustre_version=$(get_lustre_version mds)
459 if [[ $lustre_version = 1.8* ]] ; then
460 $LFS quotaoff -ug $MOUNT # just in case
461 [ -n "$ver" ] && quota_set_version $ver
463 echo mds running $lustre_version
464 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
467 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
469 do_facet mgs "lctl conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=$spec"
471 local osts=$(get_facets OST)
472 for ost in ${osts//,/ }; do
474 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
478 # client could mount several lustre
480 local fsname=${1:-$FSNAME}
482 do_facet mgs lctl get_param md*.${fsname}-MDT*.quota_type || rc=$?
483 do_nodes $(comma_list $(osts_nodes)) \
484 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
488 restore_quota_type () {
489 local mntpt=${1:-$MOUNT}
490 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
491 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
494 quota_save_version $old_QUOTA_TYPE
501 # 1. run quotacheck only if quota is off
502 # 2. save the original quota_type params, restore them after testing
504 # Suppose that quota type the same on mds and ost
505 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
506 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
507 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
508 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
509 export old_QUOTA_TYPE=$quota_type
510 quota_save_version $QUOTA_TYPE
513 local quota_usrs=$QUOTA_USERS
515 # get_filesystem_size
516 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
517 local blk_soft=$((disksz + 1024))
518 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
520 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
522 local i_hard=$((i_soft + i_soft / 20))
524 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
525 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
528 for usr in $quota_usrs; do
529 echo "Setting up quota on $client:$mntpt for $usr..."
531 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
533 eval $cmd || error "$cmd FAILED!"
535 # display the quota status
536 echo "Quota settings for $usr : "
537 $LFS quota -v -u $usr $mntpt || true
545 # Only supply -o to mount if we have options
546 if [ -n "$MOUNTOPT" ]; then
547 OPTIONS="-o $MOUNTOPT"
549 local device=$MGSNID:/$FSNAME
550 if [ -z "$mnt" -o -z "$FSNAME" ]; then
551 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
555 echo "Starting client: $client: $OPTIONS $device $mnt"
556 do_node $client mkdir -p $mnt
557 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
558 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
559 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
560 lctl set_param debug_mb=${DEBUG_SIZE}"
573 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
574 if [ $running -ne 0 ]; then
575 echo "Stopping client $client $mnt (opts:$force)"
576 do_node $client lsof -t $mnt || need_kill=no
577 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
578 pids=$(do_node $client lsof -t $mnt | sort -u);
579 if [ -n $pids ]; then
580 do_node $client kill -9 $pids || true
584 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
585 if [ $busy -ne 0 ] ; then
586 echo "$mnt is still busy, wait one second" && sleep 1
587 do_node $client umount $force $mnt
592 # nodes is comma list
593 sanity_mount_check_nodes () {
599 # FIXME: assume that all cluster nodes run the same os
600 [ "$(uname)" = Linux ] || return 0
603 for mnt in $mnts ; do
604 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
605 mpts=\\\$(mount | grep -w -c $mnt);
606 if [ \\\$running -ne \\\$mpts ]; then
607 echo \\\$(hostname) env are INSANE!;
615 sanity_mount_check_servers () {
617 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
618 echo Checking servers environments
620 # FIXME: modify get_facets to display all facets wo params
621 local facets="$(get_facets OST),$(get_facets MDS),mgs"
625 for facet in ${facets//,/ }; do
626 node=$(facet_host ${facet})
627 mntpt=$(facet_mntpt $facet)
628 sanity_mount_check_nodes $node $mntpt ||
629 { error "server $node environments are insane!"; return 1; }
633 sanity_mount_check_clients () {
634 local clients=${1:-$CLIENTS}
635 local mntpt=${2:-$MOUNT}
636 local mntpt2=${3:-$MOUNT2}
638 [ -z $clients ] && clients=$(hostname)
639 echo Checking clients $clients environments
641 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
642 error "clients environments are insane!"
645 sanity_mount_check () {
646 sanity_mount_check_servers || return 1
647 sanity_mount_check_clients || return 2
650 # mount clients if not mouted
651 zconf_mount_clients() {
654 local OPTIONS=${3:-$MOUNTOPT}
656 # Only supply -o to mount if we have options
657 if [ "$OPTIONS" ]; then
658 OPTIONS="-o $OPTIONS"
660 local device=$MGSNID:/$FSNAME
661 if [ -z "$mnt" -o -z "$FSNAME" ]; then
662 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
666 echo "Starting client $clients: $OPTIONS $device $mnt"
669 running=\\\$(mount | grep -c $mnt' ');
671 if [ \\\$running -eq 0 ] ; then
673 mount -t lustre $OPTIONS $device $mnt;
678 echo "Started clients $clients: "
679 do_nodes $clients "mount | grep -w $mnt"
681 do_nodes $clients "sysctl -w lnet.debug=\\\"$PTLDEBUG\\\";
682 sysctl -w lnet.subsystem_debug=\\\"${SUBSYSTEM# }\\\";
683 sysctl -w lnet.debug_mb=${DEBUG_SIZE};"
688 zconf_umount_clients() {
695 echo "Stopping clients: $clients $mnt (opts:$force)"
696 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
697 if [ \\\$running -ne 0 ] ; then
698 echo Stopping client \\\$(hostname) $mnt opts:$force;
699 lsof -t $mnt || need_kill=no;
700 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
701 pids=\\\$(lsof -t $mnt | sort -u);
702 if [ -n \\\"\\\$pids\\\" ]; then
706 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
707 if [ \\\$busy -ne 0 ] ; then
708 echo "$mnt is still busy, wait one second" && sleep 1;
716 echo + $POWER_DOWN $node
720 shutdown_node_hard () {
724 for i in $(seq $attempts) ; do
727 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
728 echo "waiting for $host to fail attempts=$attempts"
729 [ $i -lt $attempts ] || \
730 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
736 local mnt=${2:-$MOUNT}
739 if [ "$FAILURE_MODE" = HARD ]; then
740 shutdown_node_hard $client
742 zconf_umount_clients $client $mnt -f
748 local facets="$(get_facets OST),$(get_facets MDS)"
751 combined_mgs_mds || facets="$facets,mgs"
753 for facet in ${facets//,/ }; do
754 if [ $(facet_active_host $facet) == $host ]; then
755 affected="$affected $facet"
759 echo $(comma_list $affected)
765 if [ "$FAILURE_MODE" = HARD ]; then
766 shutdown_node_hard $(facet_active_host $facet)
774 echo + $POWER_UP $node
787 if [ "$FAILURE_MODE" = HARD ]; then
788 reboot_node $(facet_active_host $facet)
796 if [ "$FAILURE_MODE" = HARD ]; then
802 # recovery-scale functions
803 check_progs_installed () {
808 do_nodes $clients "PATH=:$PATH; status=true;
809 for prog in $progs; do
810 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
811 echo \\\$prog missing on \\\$(hostname);
819 echo __$(echo $1 | tr '-' 'X')
822 start_client_load() {
825 local var=$(client_var_name $client)_load
826 eval export ${var}=$load
828 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
829 BREAK_ON_ERROR=$BREAK_ON_ERROR \
830 END_RUN_FILE=$END_RUN_FILE \
831 LOAD_PID_FILE=$LOAD_PID_FILE \
832 TESTSUITELOG=$TESTSUITELOG \
834 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
835 log "Started client load: ${load} on $client"
840 start_client_loads () {
841 local -a clients=(${1//,/ })
842 local numloads=${#CLIENT_LOADS[@]}
845 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
846 testnum=$((nodenum % numloads))
847 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
849 # bug 22169: wait the background threads to start
853 # only for remote client
854 check_client_load () {
856 local var=$(client_var_name $client)_load
857 local TESTLOAD=run_${!var}.sh
859 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
861 # bug 18914: try to connect several times not only when
862 # check ps, but while check_catastrophe also
865 while [ $RC = 254 -a $tries -gt 0 ]; do
869 if ! check_catastrophe $client; then
871 if [ $RC -eq 254 ]; then
872 # FIXME: not sure how long we shuold sleep here
876 echo "check catastrophe failed: RC=$RC "
881 # We can continue try to connect if RC=254
882 # Just print the warning about this
883 if [ $RC = 254 ]; then
884 echo "got a return status of $RC from do_node while checking catastrophe on $client"
887 # see if the load is still on the client
890 while [ $RC = 254 -a $tries -gt 0 ]; do
894 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
899 if [ $RC = 254 ]; then
900 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
901 # see if we can diagnose a bit why this is
906 check_client_loads () {
907 local clients=${1//,/ }
911 for client in $clients; do
912 check_client_load $client
914 if [ "$rc" != 0 ]; then
915 log "Client load failed on node $client, rc=$rc"
921 restart_client_loads () {
922 local clients=${1//,/ }
923 local expectedfail=${2:-""}
927 for client in $clients; do
928 check_client_load $client
930 if [ "$rc" != 0 -a "$expectedfail" ]; then
931 local var=$(client_var_name $client)_load
932 start_client_load $client ${!var}
933 echo "Restarted client load ${!var}: on $client. Checking ..."
934 check_client_load $client
936 if [ "$rc" != 0 ]; then
937 log "Client load failed to restart on node $client, rc=$rc"
938 # failure one client load means test fail
939 # we do not need to check other
947 # End recovery-scale functions
949 # verify that lustre actually cleaned up properly
951 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
952 error "LBUG/LASSERT detected"
953 BUSY=`dmesg | grep -i destruct || true`
956 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
960 check_mem_leak || exit 204
962 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
963 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
965 if module_loaded lnet || module_loaded libcfs; then
966 echo "$0: modules still loaded..." 1>&2
983 RESULT=$(do_node $node "$TEST")
984 if [ "$RESULT" == "$FINAL" ]; then
985 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
988 [ $WAIT -ge $MAX ] && break
989 echo "Waiting $((MAX - WAIT)) secs for update"
990 WAIT=$((WAIT + sleep))
993 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
997 wait_update_facet () {
1000 wait_update $(facet_active_host $facet) "$@"
1003 wait_delete_completed () {
1004 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1005 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1009 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1011 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1012 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1013 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1014 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1018 echo "Delete is not completed in $MAX_WAIT sec"
1025 # we can use "for" here because we are waiting the slowest
1026 for host in ${hostlist//,/ }; do
1027 check_network "$host" 900
1029 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1036 for facet in ${facetlist//,/ }; do
1037 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1039 wait_for_host $hostlist
1042 _wait_recovery_complete () {
1045 # Use default policy if $2 is not passed by caller.
1046 local MAX=${2:-$(max_recovery_time)}
1051 while [ $WAIT -lt $MAX ]; do
1052 STATUS=$(lctl get_param -n $param | grep status)
1054 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1057 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1059 echo "$param recovery not done in $MAX sec. $STATUS"
1063 wait_recovery_complete () {
1066 # with an assumption that at_max is the same on all nodes
1067 local MAX=${2:-$(max_recovery_time)}
1070 if [ "$FAILURE_MODE" = HARD ]; then
1071 facets=$(facets_on_host $(facet_active_host $facet))
1073 echo affected facets: $facets
1075 # we can use "for" here because we are waiting the slowest
1076 for facet in ${facets//,/ }; do
1077 local var_svc=${facet}_svc
1078 local param="*.${!var_svc}.recovery_status"
1080 local host=$(facet_active_host $facet)
1081 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1085 wait_mds_ost_sync () {
1086 # just because recovery is done doesn't mean we've finished
1087 # orphan cleanup. Wait for llogs to get synchronized.
1088 echo "Waiting for orphan cleanup..."
1089 # MAX value includes time needed for MDS-OST reconnection
1090 local MAX=$(( TIMEOUT * 2 ))
1092 while [ $WAIT -lt $MAX ]; do
1093 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1094 "$LCTL get_param -n obdfilter.*.mds_sync"))
1096 for ((i=0; i<${#sync[@]}; i++)); do
1097 [ ${sync[$i]} -eq 0 ] && continue
1098 # there is a not finished MDS-OST synchronization
1102 sleep 2 # increase waiting time and cover statfs cache
1103 [ ${con} -eq 1 ] && return 0
1104 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1107 echo "$facet recovery not done in $MAX sec. $STATUS"
1111 wait_destroy_complete () {
1112 echo "Waiting for destroy to be done..."
1113 # MAX value shouldn't be big as this mean server responsiveness
1114 # never increase this just to make test pass but investigate
1115 # why it takes so long time
1118 while [ $WAIT -lt $MAX ]; do
1119 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1121 for ((i=0; i<${#RPCs[@]}; i++)); do
1122 [ ${RPCs[$i]} -eq 0 ] && continue
1123 # there are still some destroy RPCs in flight
1128 [ ${con} -eq 1 ] && return 0 # done waiting
1129 echo "Waiting $WAIT secs for destroys to be done."
1132 echo "Destroys weren't done in $MAX sec."
1142 # conf-sanity 31 takes a long time cleanup
1143 while [ $WAIT -lt 300 ]; do
1144 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1145 [ -z "${running}" ] && return 0
1146 echo "waited $WAIT for${running}"
1147 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1149 WAIT=$((WAIT + INTERVAL))
1151 echo "service didn't stop after $WAIT seconds. Still running:"
1156 wait_remote_prog () {
1162 [ "$PDSH" = "no_dsh" ] && return 0
1164 while [ $WAIT -lt $2 ]; do
1165 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1166 [ -z "${running}" ] && return 0 || true
1167 echo "waited $WAIT for: "
1169 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1171 WAIT=$((WAIT + INTERVAL))
1173 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1174 [ -z "$pids" ] && return 0
1175 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1176 # FIXME: not portable
1177 for pid in $pids; do
1178 cat /proc/${pid}/status || true
1179 cat /proc/${pid}/wchan || true
1181 kill -9 $pid || true
1190 # not every config has many clients
1192 if [ -n "$CLIENTS" ]; then
1193 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1195 stat -f $MOUNT > /dev/null
1201 # usually checked on particular client or locally
1203 if [ ! -z "$client" ]; then
1204 $PDSH $client "stat -f $MOUNT" > /dev/null
1206 stat -f $MOUNT > /dev/null
1214 client_reconnect() {
1215 uname -n >> $MOUNT/recon
1216 if [ -z "$CLIENTS" ]; then
1217 df $MOUNT; uname -n >> $MOUNT/recon
1219 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1221 echo Connected clients:
1223 ls -l $MOUNT/recon > /dev/null
1230 local host=$(facet_active_host $facet)
1232 echo "Failing $facet on node $host"
1234 local affected=$facet
1236 if [ "$FAILURE_MODE" = HARD ]; then
1237 affected=$(facets_on_host $host)
1240 shutdown_facet $facet
1242 echo affected facets: $affected
1244 [ -n "$sleep_time" ] && sleep $sleep_time
1249 RECOVERY_START_TIME=`date +%s`
1250 echo "df pid is $dfpid"
1252 change_active $affected
1254 wait_for_facet $affected
1255 # start mgs first if it is affected
1256 if ! combined_mgs_mds && list_member $affected mgs; then
1257 mount_facet mgs || error "Restart of mgs failed"
1259 # FIXME; has to be changed to mount all facets concurrently
1260 affected=$(exclude_items_from_list $affected mgs)
1261 for facet in ${affected//,/ }; do
1262 mount_facet $facet || error "Restart of $facet on node $host failed!"
1272 do_facet $facet sync
1274 local svc=${facet}_svc
1275 do_facet $facet $LCTL --device %${!svc} notransno
1276 do_facet $facet $LCTL --device %${!svc} readonly
1277 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1278 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1281 replay_barrier_nodf() {
1282 local facet=$1 echo running=${running}
1283 do_facet $facet sync
1284 local svc=${facet}_svc
1285 echo Replay barrier on ${!svc}
1286 do_facet $facet $LCTL --device %${!svc} notransno
1287 do_facet $facet $LCTL --device %${!svc} readonly
1288 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1289 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1292 mds_evict_client() {
1293 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
1294 local mdtdevice=$(get_mds_mdt_device_proc_path)
1295 do_facet mds "lctl set_param -n ${mdtdevice}.${mds_svc}.evict_client $UUID"
1298 ost_evict_client() {
1299 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
1300 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1304 facet_failover $* || error "failover: $?"
1305 clients_up || error "post-failover df: $?"
1310 facet_failover $facet
1316 change_active $facet
1317 mount_facet $facet -o abort_recovery
1318 clients_up || echo "first df failed: $?"
1319 clients_up || error "post-failover df: $?"
1323 echo There is no lmc. This is mountconf, baby.
1328 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1329 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1335 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1341 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1342 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1343 if [ -z "$ID" ]; then
1344 echo "Could not get a ptl id for $1..."
1353 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1360 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1361 if type __h2elan >/dev/null 2>&1; then
1364 ID=`echo $1 | sed 's/[^0-9]*//g'`
1372 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1373 ID=`echo $1 | sed 's/[^0-9]*//g'`
1377 declare -fx h2openib
1380 h2name_or_ip "$1" "o2ib"
1387 [ "$facet" == client ] && echo -n $HOSTNAME && return
1388 varname=${facet}_HOST
1389 if [ -z "${!varname}" ]; then
1390 if [ "${facet:0:3}" == "ost" ]; then
1391 eval ${facet}_HOST=${ost_HOST}
1399 local activevar=${facet}active
1401 if [ -f $TMP/${facet}active ] ; then
1402 source $TMP/${facet}active
1405 active=${!activevar}
1406 if [ -z "$active" ] ; then
1413 facet_active_host() {
1415 local active=`facet_active $facet`
1416 if [ "$facet" == client ]; then
1419 echo `facet_host $active`
1427 facetlist=$(exclude_items_from_list $facetlist mgs)
1429 for facet in ${facetlist//,/ }; do
1430 local failover=${facet}failover
1431 local host=`facet_host $failover`
1432 [ -z "$host" ] && return
1434 local curactive=`facet_active $facet`
1435 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1436 eval export ${facet}active=$facet
1438 eval export ${facet}active=$failover
1440 # save the active host for this facet
1441 local activevar=${facet}active
1442 echo "$activevar=${!activevar}" > $TMP/$activevar
1443 local TO=`facet_active_host $facet`
1444 echo "Failover $facet to $TO"
1450 # do not stripe off hostname if verbose, bug 19215
1451 if [ x$1 = x--verbose ]; then
1459 if [ "$HOST" = "$HOSTNAME" ]; then
1461 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1462 echo "cannot run remote command on $HOST with $myPDSH"
1466 echo "CMD: $HOST $@" >&2
1467 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1470 if [ "$myPDSH" = "rsh" ]; then
1471 # we need this because rsh does not return exit code of an executed command
1472 local command_status="$TMP/cs"
1473 rsh $HOST ":> $command_status"
1474 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1475 cd $RPWD; sh -c \"$@\") ||
1476 echo command failed >$command_status"
1477 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1482 # print HOSTNAME for myPDSH="no_dsh"
1483 if [[ $myPDSH = no_dsh ]]; then
1484 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1486 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1489 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1491 return ${PIPESTATUS[0]}
1495 do_node --verbose "$@"
1498 single_local_node () {
1499 [ "$1" = "$HOSTNAME" ]
1504 # do not stripe off hostname if verbose, bug 19215
1505 if [ x$1 = x--verbose ]; then
1513 if $(single_local_node $rnodes); then
1515 do_nodev $rnodes "$@"
1517 do_node $rnodes "$@"
1522 # This is part from do_node
1525 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1526 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1529 echo "CMD: $rnodes $@" >&2
1530 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1533 # do not replace anything from pdsh output if -N is used
1534 # -N Disable hostname: prefix on lines of output.
1535 if $verbose || [[ $myPDSH = *-N* ]]; then
1536 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1538 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1540 return ${PIPESTATUS[0]}
1546 local HOST=`facet_active_host $facet`
1547 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1552 do_nodes --verbose "$@"
1558 # make sure its not already running
1560 rm -f $TMP/${facet}active
1561 do_facet ${facet} $MKFS $*
1567 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1568 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1574 if combined_mgs_mds && [[ $facet = "mgs" ]] ; then
1577 local var=${facet}_MOUNT
1578 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1587 # make sure we are using the primary server, so test-framework will
1588 # be able to clean up properly.
1589 activemds=`facet_active mds`
1590 if [ $activemds != "mds" ]; then
1594 local clients=$CLIENTS
1595 [ -z $clients ] && clients=$(hostname)
1597 zconf_umount_clients $clients $MOUNT "$*" || true
1598 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1600 [ "$CLIENTONLY" ] && return
1601 # The add fn does rm ${facet}active file, this would be enough
1602 # if we use do_facet <facet> only after the facet added, but
1603 # currently we use do_facet mds in local.sh
1605 rm -f ${TMP}/mdsactive
1606 for num in `seq $OSTCOUNT`; do
1608 rm -f $TMP/ost${num}active
1610 if ! combined_mgs_mds ; then
1617 cleanup_echo_devs () {
1618 local devs=$($LCTL dl | grep echo | awk '{print $4}')
1620 for dev in $devs; do
1621 $LCTL --device $dev cleanup
1622 $LCTL --device $dev detach
1627 nfs_client_mode && return
1635 combined_mgs_mds () {
1636 [[ $MDSDEV = $MGSDEV ]] && [[ $mds_HOST = $mgs_HOST ]]
1642 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
1643 local optvar=${tgt}_MKFS_OPTS
1644 local opt=${!optvar}
1646 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
1647 [[ $facet = mgs ]] && echo $opt && return
1650 # --failnode options
1651 local var=${facet}failover_HOST
1652 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
1653 local failnode=$(h2$NETTYPE ${!var})
1654 failnode="--failnode=$failnode"
1655 # options does not contain
1656 # or contains wrong --failnode=
1657 if [[ $opt != *${failnode}* ]]; then
1658 opt=$(echo $opt | sed 's/--failnode=.* / /')
1659 opt="$opt $failnode"
1665 # no additional mkfs mds "--mgsnode" option for this configuration
1666 if [[ $facet = mds ]] && combined_mgs_mds; then
1671 # additional mkfs "--mgsnode"
1672 local mgsnode="--mgsnode=$MGSNID"
1673 opt=${opt//$mgsnode }
1674 for nid in ${MGSNID//:/ }; do
1675 local mgsnode="--mgsnode=$nid"
1676 # options does not contain
1678 if [[ $opt != *${mgsnode}" "* ]]; then
1679 opt="$opt --mgsnode=$nid"
1687 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1690 # We need ldiskfs here, may as well load them all
1692 [ "$CLIENTONLY" ] && return
1693 echo Formatting mgs, mds, osts
1694 if ! combined_mgs_mds ; then
1695 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
1699 add mds $(mkfs_opts mds) $FSTYPE_OPT --reformat $MDSDEV || exit 10
1701 add mds $(mkfs_opts mds) $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
1704 # the ost-s could have different OST_MKFS_OPTS
1705 # because of different failnode-s
1706 for num in `seq $OSTCOUNT`; do
1708 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1710 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1716 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1721 zconf_umount `hostname` $1 || error "umount failed"
1722 zconf_mount `hostname` $1 || error "mount failed"
1725 writeconf_facet () {
1729 do_facet $facet "$TUNEFS --writeconf $dev"
1733 writeconf_facet mds $MDSDEV
1735 for num in `seq $OSTCOUNT`; do
1736 DEVNAME=`ostdevname $num`
1737 writeconf_facet ost$num $DEVNAME
1742 nfs_client_mode && return
1744 sanity_mount_check ||
1745 error "environments are insane!"
1748 if [ -z "$CLIENTONLY" ]; then
1749 echo Setup mgs, mdt, osts
1751 echo $WRITECONF | grep -q "writeconf" && \
1754 if ! combined_mgs_mds ; then
1755 start mgs $MGSDEV $MGS_MOUNT_OPTS
1758 start mds $MDSDEV $MDS_MOUNT_OPTS
1759 # We started mds, now we should set failover variable properly.
1760 # Set mdsfailover_HOST if it is not set (the default failnode).
1761 if [ -z "$mdsfailover_HOST" ]; then
1762 mdsfailover_HOST=$(facet_host mds)
1765 for num in `seq $OSTCOUNT`; do
1766 DEVNAME=`ostdevname $num`
1767 start ost$num $DEVNAME $OST_MOUNT_OPTS
1769 # We started ost$num, now we should set ost${num}failover variable properly.
1770 # Set ost${num}failover_HOST if it is not set (the default failnode).
1771 varname=ost${num}failover_HOST
1772 if [ -z "${!varname}" ]; then
1773 eval ost${num}failover_HOST=$(facet_host ost${num})
1778 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1780 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1782 if [ "$MOUNT_2" ]; then
1783 mount_client $MOUNT2
1784 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1790 mounted_lustre_filesystems() {
1791 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1794 init_facet_vars () {
1795 [ "$CLIENTONLY" ] && return 0
1802 eval export ${facet}_dev=${device}
1803 eval export ${facet}_opt=\"$@\"
1805 local dev=${facet}_dev
1806 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1807 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1809 eval export ${facet}_svc=${label}
1811 local varname=${facet}failover_HOST
1812 if [ -z "${!varname}" ]; then
1813 eval $varname=$(facet_host $facet)
1816 # ${facet}failover_dev is set in cfg file
1817 varname=${facet}failover_dev
1818 if [ -n "${!varname}" ] ; then
1819 eval export ${facet}failover_dev=${!varname}
1821 eval export ${facet}failover_dev=$device
1824 # get mount point of already mounted device
1825 # is facet_dev is already mounted then use the real
1826 # mount point of this facet; otherwise use $(facet_mntpt $facet)
1827 # i.e. ${facet}_MOUNT if specified by user or default
1828 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
1829 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
1830 if [ -z $mntpt ]; then
1831 mntpt=$(facet_mntpt $facet)
1833 eval export ${facet}_MOUNT=$mntpt
1836 init_facets_vars () {
1838 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
1840 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
1842 remote_ost_nodsh && return
1844 for num in `seq $OSTCOUNT`; do
1845 DEVNAME=`ostdevname $num`
1846 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1850 init_param_vars () {
1851 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1852 export MDSVER=$(do_facet mds "lctl get_param version" | cut -d. -f1,2)
1853 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1854 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1858 TIMEOUT=$(do_facet mds "lctl get_param -n timeout")
1860 log "Using TIMEOUT=$TIMEOUT"
1862 if [ "$ENABLE_QUOTA" ]; then
1863 setup_quota $MOUNT || return 2
1867 nfs_client_mode () {
1868 if [ "$NFSCLIENT" ]; then
1869 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1870 local clients=$CLIENTS
1871 [ -z $clients ] && clients=$(hostname)
1873 # FIXME: remove hostname when 19215 fixed
1874 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1875 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1876 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1882 check_config_client () {
1885 local mounted=$(mount | grep " $mntpt ")
1886 if [ "$CLIENTONLY" ]; then
1888 # CLIENTONLY should not depend on *_HOST settings
1889 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
1890 # in theory someone could create a new,
1891 # client-only config file that assumed lustre was already
1892 # configured and didn't set the MGSNID. If MGSNID is not set,
1893 # then we should use the mgs nid currently being used
1894 # as the default value. bug 18021
1895 [[ x$MGSNID = x ]] &&
1898 if [[ x$mgc != xMGC$MGSNID ]]; then
1899 if [ "$mgs_HOST" ]; then
1900 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
1901 [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
1902 error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
1908 local myMGS_host=$mgs_HOST
1909 if [ "$NETTYPE" = "ptl" ]; then
1910 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1913 echo Checking config lustre mounted on $mntpt
1914 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1915 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1917 # if [ "$mgshost" != "$myMGS_host" ]; then
1918 # error_exit "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1919 # Please use correct config or set mds_HOST correctly!"
1924 check_config_clients () {
1925 local clients=${CLIENTS:-$HOSTNAME}
1928 nfs_client_mode && return
1930 do_rpc_nodes $clients check_config_client $mntpt
1932 sanity_mount_check ||
1933 error "environments are insane!"
1937 local mdstimeout=$(do_facet mds "lctl get_param -n timeout")
1938 local cltimeout=$(lctl get_param -n timeout)
1939 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
1940 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
1947 local mounted=$(mounted_lustre_filesystems)
1949 echo $mounted' ' | grep -w -q $mntpt' '
1953 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
1957 # empty lustre filesystem may have empty directories lost+found and .lustre
1959 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
1960 -print | wc -l) = 1 ] || return 1
1961 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
1962 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
1966 check_and_setup_lustre() {
1967 nfs_client_mode && return
1969 local MOUNTED=$(mounted_lustre_filesystems)
1973 # both MOUNT and MOUNT2 are not mounted
1974 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
1975 [ "$REFORMAT" ] && formatall
1976 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
1978 is_mounted $MOUNT || error "NAME=$NAME not mounted"
1979 export I_MOUNTED=yes
1983 elif is_mounted $MOUNT2; then
1985 # MOUNT2 is mounted, while MOUNT_2 is not set
1986 if ! [ "$MOUNT_2" ]; then
1987 cleanup_mount $MOUNT2
1988 export I_UMOUNTED2=yes
1991 # MOUNT2 is mounted, MOUNT_2 is set
1993 # FIXME: what to do if check_config failed?
1995 # 1) remote client has mounted other Lustre fs ?
1996 # 2) it has insane env ?
1997 # let's try umount MOUNT2 on all clients and mount it again:
1998 if ! check_config_clients $MOUNT2; then
1999 cleanup_mount $MOUNT2
2000 restore_mount $MOUNT2
2001 export I_MOUNTED2=yes
2006 # MOUNT is mounted MOUNT2 is not mounted
2007 elif [ "$MOUNT_2" ]; then
2008 restore_mount $MOUNT2
2009 export I_MOUNTED2=yes
2013 # FIXME: what to do if check_config failed?
2015 # 1) remote client has mounted other Lustre fs?
2016 # 2) lustre is mounted on remote_clients atall ?
2017 check_config_clients $MOUNT
2021 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
2022 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
2023 lctl set_param debug_mb=${DEBUG_SIZE};
2026 if [ "$ONLY" == "setup" ]; then
2032 local clients=${CLIENTS:-$HOSTNAME}
2035 zconf_mount_clients $clients $mntpt
2039 local clients=${CLIENTS:-$HOSTNAME}
2042 zconf_umount_clients $clients $mntpt
2045 cleanup_and_setup_lustre() {
2046 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2047 lctl set_param debug=0 || true
2049 if [ "$ONLY" == "cleanup" ]; then
2053 check_and_setup_lustre
2056 # Get all of the server target devices from a given server node and type.
2065 mdt) obd_type="osd" ;;
2066 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2067 *) echo "invalid server type" && return 1 ;;
2070 devs=$(do_node $node "lctl get_param -n $obd_type.*.mntdev")
2071 for dev in $devs; do
2073 *loop*) do_node $node "losetup $dev" | \
2074 sed -e "s/.*(//" -e "s/).*//" ;;
2080 # Get all of the server target devices.
2086 for node in $(osts_nodes); do
2087 OSTDEVS[i]=$(get_mnt_devs $node ost)
2092 # Run e2fsck on MDT or OST device.
2099 df > /dev/null # update statfs data on disk
2100 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
2103 do_node $node $cmd || rc=$?
2104 [ $rc -le $FSCK_MAX_ERR ] || \
2105 error_exit "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2109 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2116 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2117 error_exit "fail to create file in $SHARED_DIRECTORY")
2119 # make sure everything gets to the backing store
2120 local list=$(comma_list $CLIENTS $(facet_host mds) $(osts_nodes))
2121 do_nodes $list "sync; sleep 2; sync"
2123 do_nodes $list ls $tmp_file || \
2124 error_exit "$SHARED_DIRECTORY is not a shared directory"
2127 run_e2fsck $(facet_host mds) $MDSDEV
2132 for node in $(osts_nodes); do
2133 for dev in ${OSTDEVS[i]}; do
2134 local ostdb_opt=`eval echo $OSTDB_OPT`
2135 run_e2fsck $node $dev $ostidx "$ostdb_opt"
2136 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2137 ostidx=$((ostidx + 1))
2144 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2148 [ $rc -le $FSCK_MAX_ERR ] || \
2149 error_exit "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2150 echo "lfsck finished with rc=$rc"
2152 rm -rvf $MDSDB* $OSTDB* || true
2156 check_and_cleanup_lustre() {
2157 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2160 if [ "$SKIP_LFSCK" == "no" ]; then
2167 if is_mounted $MOUNT; then
2168 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2169 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2172 if [ "$I_UMOUNTED2" = "yes" ]; then
2173 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2176 if [ "$I_MOUNTED2" = "yes" ]; then
2177 cleanup_mount $MOUNT2
2180 if [ "$I_MOUNTED" = "yes" ]; then
2181 cleanupall -f || error "cleanup failed"
2193 while [ $NETWORK -eq 0 ]; do
2194 if ping -c 1 -w 3 $1 > /dev/null; then
2198 echo "waiting for $1, $((MAX - WAIT)) secs left"
2201 if [ $WAIT -gt $MAX ]; then
2202 echo "Network not available"
2208 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2219 # the sed converts spaces to commas, but leaves the last space
2220 # alone, so the line doesn't end with a comma.
2221 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2227 echo $list | grep -qw $item
2230 # list, excluded are the comma separated lists
2231 exclude_items_from_list () {
2237 for item in ${excluded//,/ }; do
2238 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2240 echo $(comma_list $list)
2243 # list, expand are the comma separated lists
2245 local list=${1//,/ }
2246 local expand=${2//,/ }
2249 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2250 echo $(comma_list $expanded)
2253 testslist_filter () {
2254 local script=$LUSTRE/tests/${TESTSUITE}.sh
2256 [ -f $script ] || return 0
2258 local start_at=$START_AT
2259 local stop_at=$STOP_AT
2261 local var=${TESTSUITE//-/_}_START_AT
2262 [ x"${!var}" != x ] && start_at=${!var}
2263 var=${TESTSUITE//-/_}_STOP_AT
2264 [ x"${!var}" != x ] && stop_at=${!var}
2266 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2267 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2268 /^'${start_at}'$/ {flag = 0}
2269 {if (flag == 1) print $0}
2270 /^'${stop_at}'$/ { flag = 1 }'
2274 (cd `dirname $1`; echo $PWD/`basename $1`)
2278 local types=${1:-"OST MDS MGS"}
2281 for entry in $types; do
2282 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2283 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2286 MDS|MGS ) list="$list $name";;
2287 OST ) for ((i=1; i<=$OSTCOUNT; i++)) do
2288 list="$list ${name}$i"
2290 * ) error "Invalid facet type"
2294 echo $(comma_list $list)
2297 ##################################
2298 # Adaptive Timeouts funcs
2301 # only check mds, we assume at_max is the same on all nodes
2302 local at_max=$(do_facet mds "lctl get_param -n at_max")
2303 if [ $at_max -eq 0 ]; then
2313 # suppose that all ost-s has the same at_max set
2314 if [ $facet == "ost" ]; then
2315 do_facet ost1 "lctl get_param -n at_max"
2317 do_facet $facet "lctl get_param -n at_max"
2327 if [ $facet == "ost" ]; then
2328 for i in `seq $OSTCOUNT`; do
2329 do_facet ost$i "lctl set_param at_max=$at_max"
2332 do_facet $facet "lctl set_param at_max=$at_max"
2337 ##################################
2341 # OBD_FAIL_MDS_ALL_REQUEST_NET
2343 do_facet mds lctl set_param fail_loc=0x123
2344 do_facet client "$1" || RC=$?
2345 do_facet mds lctl set_param fail_loc=0
2350 # OBD_FAIL_MDS_ALL_REPLY_NET
2352 do_facet mds lctl set_param fail_loc=0x122
2353 do_facet client "$@" || RC=$?
2354 do_facet mds lctl set_param fail_loc=0
2358 drop_reint_reply() {
2359 # OBD_FAIL_MDS_REINT_NET_REP
2361 do_facet mds lctl set_param fail_loc=0x119
2362 do_facet client "$@" || RC=$?
2363 do_facet mds lctl set_param fail_loc=0
2368 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2370 do_facet ost1 lctl set_param fail_loc=0x214
2371 do_facet client "$1" || RC=$?
2372 do_facet client "sync"
2373 do_facet ost1 lctl set_param fail_loc=0
2377 drop_ldlm_cancel() {
2378 #define OBD_FAIL_LDLM_CANCEL 0x304
2380 do_facet client lctl set_param fail_loc=0x304
2381 do_facet client "$@" || RC=$?
2382 do_facet client lctl set_param fail_loc=0
2386 drop_bl_callback() {
2387 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2389 do_facet client lctl set_param fail_loc=0x305
2390 do_facet client "$@" || RC=$?
2391 do_facet client lctl set_param fail_loc=0
2396 #define OBD_FAIL_LDLM_REPLY 0x30c
2398 do_facet mds lctl set_param fail_loc=0x30c
2399 do_facet client "$@" || RC=$?
2400 do_facet mds lctl set_param fail_loc=0
2408 echo "clearing fail_loc on $facet"
2409 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2412 set_nodes_failloc () {
2413 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2416 cancel_lru_locks() {
2417 $LCTL mark "cancel_lru_locks $1 start"
2418 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2419 $LCTL set_param -n $d=clear
2421 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2422 $LCTL mark "cancel_lru_locks $1 stop"
2427 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2428 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2429 echo "$DEFAULT_LRU_SIZE"
2434 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2437 lru_resize_disable()
2439 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2444 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2445 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2446 echo there is still data in page cache $FILE ?
2447 lctl get_param -n $FILE
2454 create_fake_exports () {
2457 #obd_fail_val = num;
2458 #define OBD_FAIL_TGT_FAKE_EXP 0x708
2459 do_facet $facet "lctl set_param fail_val=$num"
2460 do_facet $facet "lctl set_param fail_loc=0x80000708"
2465 DEBUGSAVE="$(lctl get_param -n debug)"
2469 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
2473 ##################################
2475 ##################################
2478 local TYPE=${TYPE:-"FAIL"}
2481 [ -d "$SHARED_DIR_LOGS" ] && tmp=$SHARED_DIR_LOGS
2484 # do not dump logs if $1=false
2485 if [ "x$1" = "xfalse" ]; then
2490 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2493 ERRLOG=$tmp/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
2494 echo "Dumping lctl log to $ERRLOG"
2495 # We need to dump the logs on all nodes
2496 do_nodes $(comma_list $(nodes_list)) $NODE $LCTL dk $ERRLOG
2499 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2505 if $FAIL_ON_ERROR; then
2516 # use only if we are ignoring failures for this test, bugno required.
2517 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2518 # e.g. error_ignore 5494 "your message"
2520 local TYPE="IGNORE (bz$1)"
2526 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2530 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2531 [ "$TESTSUITELOG" ] && \
2532 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2535 build_test_filter() {
2536 EXCEPT="$EXCEPT $(testslist_filter)"
2538 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2542 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2543 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2544 [ "$EXCEPT_SLOW" ] && \
2545 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2546 for E in $EXCEPT $ALWAYS_EXCEPT; do
2547 eval EXCEPT_${E}=true
2549 for E in $EXCEPT_SLOW; do
2550 eval EXCEPT_SLOW_${E}=true
2552 for G in $GRANT_CHECK_LIST; do
2553 eval GCHECK_ONLY_${G}=true
2558 if [[ $1 = [a-z]* ]]; then
2565 # print a newline if the last test was skipped
2566 export LAST_SKIPPED=
2570 export base=`basetest $1`
2571 if [ ! -z "$ONLY" ]; then
2573 if [ ${!testname}x != x ]; then
2574 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2579 if [ ${!testname}x != x ]; then
2580 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2589 if [ ${!testname}x != x ]; then
2591 TESTNAME=test_$1 skip "skipping excluded test $1"
2594 testname=EXCEPT_$base
2595 if [ ${!testname}x != x ]; then
2597 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2600 testname=EXCEPT_SLOW_$1
2601 if [ ${!testname}x != x ]; then
2603 TESTNAME=test_$1 skip "skipping SLOW test $1"
2606 testname=EXCEPT_SLOW_$base
2607 if [ ${!testname}x != x ]; then
2609 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2619 EQUALS="======================================================================"
2623 local suffixlen=$((${#EQUALS} - ${#msg}))
2624 [ $suffixlen -lt 5 ] && suffixlen=5
2625 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
2630 module_loaded lnet || load_modules
2642 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2647 strace -o $TMP/$1.strace -ttt $*
2649 log "FINISHED: $*: rc $RC"
2654 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
2659 FFREE=`lctl get_param -n mds.*.filesfree`
2660 FTOTAL=`lctl get_param -n mds.*.filestotal`
2661 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2665 echo -n "Resetting fail_loc on all nodes..."
2666 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2674 export tdir=d0.${TESTSUITE}/d${base}
2676 local SAVE_UMASK=`umask`
2679 local BEFORE=`date +%s`
2681 log "== test $testnum: $message == `date +%H:%M:%S` ($BEFORE)"
2683 export TESTNAME=test_$testnum
2685 test_${testnum} || error "test_$testnum failed with $?"
2689 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2690 check_catastrophe || error "LBUG/LASSERT detected"
2691 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2692 pass "($((`date +%s` - $BEFORE))s)"
2700 (cd `dirname $1`; echo $PWD/`basename $1`)
2704 export base=`basetest $1`
2705 [ "$CHECK_GRANT" == "no" ] && return 0
2707 testname=GCHECK_ONLY_${base}
2708 [ ${!testname}x == x ] && return 0
2710 echo -n "checking grant......"
2712 local clients=$CLIENTS
2713 [ -z $clients ] && clients=$(hostname)
2715 # sync all the data and make sure no pending data on server
2716 do_nodes $clients sync
2719 client_grant=`do_nodes $clients \
2720 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
2721 awk '{total += $1} END{print total}'`
2724 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
2725 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
2726 awk '{total += $1} END{print total}'`
2728 # check whether client grant == server grant
2729 if [ $client_grant -ne $server_grant ]; then
2730 echo "failed: client:${client_grant} server: ${server_grant}."
2731 do_nodes $(comma_list $(osts_nodes)) \
2732 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
2733 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
2736 echo "pass: client:${client_grant} server: ${server_grant}"
2740 ########################
2746 ost=`echo $1 | awk -F_ '{print $3}'`
2747 if [ -z $ost ]; then
2748 ost=`echo $1 | sed 's/-osc.*//'`
2753 ostuuid_from_index()
2755 $LFS osts $2 | awk '/^'$1'/ { print $2 }'
2760 [ "$node" != "$(hostname)" ]
2765 remote_node $mds_HOST
2770 [ "$CLIENTONLY" ] && return 0 || true
2771 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2777 for node in $(osts_nodes) ; do
2778 remote_node $node && return 0
2785 [ "$CLIENTONLY" ] && return 0 || true
2786 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2792 MGS=$(facet_host mgs)
2793 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2797 remote_ost && remote_mds
2802 remote_mds_nodsh || remote_ost_nodsh || \
2803 $(single_local_node $(comma_list $(nodes_list)))
2811 for facet in ${facets//,/ }; do
2812 if [ "$FAILURE_MODE" = HARD ]; then
2813 nodes="$nodes $(facet_active_host $facet)"
2815 nodes="$nodes $(facet_host $facet)"
2818 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
2824 local facets=$(get_facets OST)
2825 local nodes=$(facets_nodes $facets)
2831 # FIXME. We need a list of clients
2832 local myNODES=$HOSTNAME
2835 # CLIENTS (if specified) contains the local client
2836 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
2838 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
2839 myNODES="$myNODES $(facets_nodes $(get_facets))"
2842 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
2847 remote_nodes_list () {
2848 local rnodes=$(nodes_list)
2849 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2853 init_clients_lists () {
2854 # Sanity check: exclude the local client from RCLIENTS
2855 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2857 # Sanity check: exclude the dup entries
2858 rclients=$(for i in $rclients; do echo $i; done | sort -u)
2860 local clients="$SINGLECLIENT $HOSTNAME $rclients"
2862 # Sanity check: exclude the dup entries from CLIENTS
2863 # for those configs which has SINGLCLIENT set to local client
2864 clients=$(for i in $clients; do echo $i; done | sort -u)
2866 CLIENTS=`comma_list $clients`
2867 local -a remoteclients=($rclients)
2868 for ((i=0; $i<${#remoteclients[@]}; i++)); do
2869 varname=CLIENT$((i + 2))
2870 eval $varname=${remoteclients[i]}
2873 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
2876 get_random_entry () {
2879 rnodes=${rnodes//,/ }
2881 local -a nodes=($rnodes)
2882 local num=${#nodes[@]}
2883 local i=$((RANDOM * num * 2 / 65536))
2889 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
2894 lctl get_param version | grep -q patchless
2898 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
2903 echo $nodes | wc -w || true
2907 local nodes=$(osts_nodes)
2908 local osscount=$(get_node_count "$nodes")
2909 [ ! "$OSTCOUNT" = "$osscount" ]
2912 generate_machine_file() {
2913 local nodes=${1//,/ }
2914 local machinefile=$2
2916 for node in $nodes; do
2917 echo $node >>$machinefile || \
2918 { echo "can not generate machinefile $machinefile" && return 1; }
2923 local file=$1/stripe
2925 $LFS getstripe -v $file || error
2929 setstripe_nfsserver () {
2932 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
2933 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
2935 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
2937 do_nodev $nfsserver lfs setstripe "$@"
2940 check_runas_id_ret() {
2942 local myRUNAS_UID=$1
2943 local myRUNAS_GID=$2
2946 if [ -z "$myRUNAS" ]; then
2947 error_exit "myRUNAS command must be specified for check_runas_id"
2949 mkdir $DIR/d0_runas_test
2951 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
2952 if ! $myRUNAS touch $DIR/d0_runas_test/f$$ ; then
2953 do_nodesv $(comma_list $(nodes_list)) grep -w $myRUNAS_UID /etc/passwd
2956 rm -rf $DIR/d0_runas_test
2961 local myRUNAS_UID=$1
2962 local myRUNAS_GID=$2
2965 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
2966 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
2967 Please set RUNAS_ID to some UID which exists on MDS and client or
2968 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
2971 # Run multiop in the background, but wait for it to print
2972 # "PAUSING" to its stdout before returning from this function.
2973 multiop_bg_pause() {
2974 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
2978 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
2981 echo "$MULTIOP_PROG $FILE v$ARGS"
2982 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
2984 echo "TMPPIPE=${TMPPIPE}"
2985 local multiop_output
2987 read -t 60 multiop_output < $TMPPIPE
2988 if [ $? -ne 0 ]; then
2993 if [ "$multiop_output" != "PAUSING" ]; then
2994 echo "Incorrect multiop output: $multiop_output"
3009 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3015 inodes_available () {
3016 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3020 mdsrate_inodes_available () {
3021 echo $(($(inodes_available) - 1))
3024 # reset llite stat counters
3025 clear_llite_stats(){
3026 lctl set_param -n llite.*.stats 0
3029 # sum llite stat items
3030 calc_llite_stats() {
3031 local res=$(lctl get_param -n llite.*.stats |
3032 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3037 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3040 calc_osc_kbytes () {
3041 df $MOUNT > /dev/null
3042 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
3045 # save_lustre_params(node, parameter_mask)
3046 # generate a stream of formatted strings (<node> <param name>=<param value>)
3047 save_lustre_params() {
3049 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3052 # restore lustre parameters from input stream, produces by save_lustre_params
3053 restore_lustre_params() {
3057 while IFS=" =" read node name val; do
3058 do_node ${node//:/} "lctl set_param -n $name $val"
3062 check_catastrophe() {
3063 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3064 local C=$CATASTROPHE
3065 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3067 if [ $rnodes ]; then
3068 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3069 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3085 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3087 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3088 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3089 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3093 mdsrate_cleanup () {
3094 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3097 delayed_recovery_enabled () {
3098 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
3101 ################################################################################
3102 # The following functions are used to enable interop testing between
3103 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
3105 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
3106 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
3107 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
3108 ################################################################################
3110 get_lustre_version () {
3111 local node=${1:-"mds"}
3112 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3115 get_mds_version_major () {
3116 local version=$(get_lustre_version mds)
3117 echo $version | awk -F. '{print $1}'
3120 get_mds_version_minor () {
3121 local version=$(get_lustre_version mds)
3122 echo $version | awk -F. '{print $2}'
3125 get_mds_version_patch () {
3126 local version=$(get_lustre_version mds)
3127 echo $version | awk -F. '{print $3}'
3130 get_mds_version_fix () {
3131 local version=$(get_lustre_version mds)
3132 echo $version | awk -F. '{print $4}'
3135 get_kernel_version () {
3136 local facet=${1:-"mds"}
3137 do_facet $facet uname -r | awk -F "-" '{print $1}'
3140 get_mds_kernel_major () {
3141 local version=$(get_kernel_version mds)
3142 echo $version | awk -F. '{print $1"."$2}'
3145 get_mds_kernel_minor () {
3146 local version=$(get_kernel_version mds)
3147 echo $version | awk -F. '{print $3}'
3150 get_mds_fsstat_proc_path() {
3151 local major=$(get_mds_version_major)
3152 local minor=$(get_mds_version_minor)
3153 if [ $major -le 1 -a $minor -le 8 ] ; then
3160 get_mds_mntdev_proc_path() {
3161 local fsstat_dev=$(get_mds_fsstat_proc_path)
3162 echo "$fsstat_dev.*.mntdev"
3165 get_mdtlov_proc_path() {
3167 local major=$(get_mds_version_major)
3168 local minor=$(get_mds_version_minor)
3169 if [ $major -le 1 -a $minor -le 8 ] ; then
3170 echo "${fsname}-mdtlov"
3172 echo "${fsname}-MDT0000-mdtlov"
3176 get_mdtosc_proc_path() {
3178 local major=$(get_mds_version_major)
3179 local minor=$(get_mds_version_minor)
3180 if [ $major -le 1 -a $minor -le 8 ] ; then
3183 echo "${ost}-osc-MDT0000"
3187 get_mds_mdt_device_proc_path() {
3188 local major=$(get_mds_version_major)
3189 local minor=$(get_mds_version_minor)
3190 if [ $major -le 1 -a $minor -le 8 ] ; then
3198 local major=$(get_mds_version_major)
3199 local minor=$(get_mds_version_minor)
3200 if [ $major -le 1 -a $minor -le 8 ] ; then
3207 ########################
3209 convert_facet2label() {
3212 if [ x$facet = xost ]; then
3216 local varsvc=${facet}_svc
3218 if [ -n ${!varsvc} ]; then
3221 error "No lablel for $facet!"
3225 get_clientosc_proc_path() {
3231 get_osc_import_name() {
3234 local label=$(convert_facet2label $ost)
3236 if [ "$facet" == "mds" ]; then
3237 get_mdtosc_proc_path $label
3241 get_clientosc_proc_path $label
3245 _wait_import_state () {
3248 local maxtime=${3:-max_recovery_time}
3252 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3253 while [ "${CONN_STATE}" != "${expected}" ]; do
3254 [ $i -ge $maxtime ] && \
3255 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
3258 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3262 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
3266 wait_import_state() {
3269 local maxtime=${3:-max_recovery_time}
3272 for param in ${params//,/ }; do
3273 _wait_import_state $state $param $maxtime || return
3276 wait_osc_import_state() {
3280 local ost=$(get_osc_import_name $facet $ost_facet)
3285 CONN_PROC="osc.${ost}.ost_server_uuid"
3286 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3287 while [ "${CONN_STATE}" != "${expected}" ]; do
3288 if [ "${expected}" == "DISCONN" ]; then
3289 # for disconn we can check after proc entry is removed
3290 [ "x${CONN_STATE}" == "x" ] && return 0
3291 # with AT enabled, we can have connect request timeout near of
3292 # reconnect timeout and test can't see real disconnect
3293 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3295 # disconnect rpc should be wait not more obd_timeout
3296 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3297 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3299 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3303 log "${ost_facet} now in ${CONN_STATE} state"
3307 get_clientmdc_proc_path() {
3315 do_nodesv $list "PATH=$LUSTRE/tests/:$PATH sh rpc.sh $@ "
3318 wait_clients_import_state () {
3325 if [ "$FAILURE_MODE" = HARD ]; then
3326 facets=$(facets_on_host $(facet_active_host $facet))
3329 for facet in ${facets//,/ }; do
3330 local label=$(convert_facet2label $facet)
3333 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3334 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3335 *) error "unknown facet!" ;;
3337 local params=$(expand_list $params $proc_path)
3340 if ! do_rpc_nodes $list wait_import_state $expected $params; then
3341 error "import is not in ${expected} state"
3346 destroy_pool_int() {
3348 local OSTS=$(do_facet mds lctl pool_list $1 | awk '$1 !~ /^Pool:/ {print $1}')
3349 for ost in $OSTS; do
3350 do_facet mgs lctl pool_remove $1 $ost
3352 do_facet mgs lctl pool_destroy $1
3355 # <fsname>.<poolname> or <poolname>
3357 local fsname=${1%%.*}
3358 local poolname=${1##$fsname.}
3360 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3364 pool_list $fsname.$poolname || return $?
3366 destroy_pool_int $fsname.$poolname
3368 [[ $RC -ne 0 ]] && return $RC
3370 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3371 2>/dev/null || echo foo" "foo" || RC=1
3373 if [[ $RC -eq 0 ]]; then
3374 remove_pool_from_list $fsname.$poolname
3376 error "destroy pool failed $1"
3382 local fsname=${1:-$FSNAME}
3384 local listvar=${fsname}_CREATED_POOLS
3388 [ x${!listvar} = x ] && return 0
3390 echo destroy the created pools: ${!listvar}
3391 for poolname in ${!listvar//,/ }; do
3392 destroy_pool $fsname.$poolname
3397 local fsname=${1:-$FSNAME}
3399 destroy_pools $fsname
3405 local ts=$(date +%s)
3407 # bug 20237, comment 11
3408 # It would also be useful to provide the option
3409 # of writing the file to an NFS directory so it doesn't need to be copied.
3412 [ -d "$SHARED_DIR_LOGS" ] && tmp=$SHARED_DIR_LOGS && docp=false
3414 # dump lustre logs, dmesg
3415 do_nodes $list "log=$tmp/\\\$(hostname)-debug-$ts.log ;
3416 lctl dk \\\$log >/dev/null;
3417 log=$tmp/\\\$(hostname)-dmesg-$ts.log;
3420 # FIXME: does it make sense to collect the logs for $ts only, but all
3422 # rsync $TMP/*${TESTSUITE}* to gather the logs dumped by error fn
3423 local logs=$TMP/'*'${TESTSUITE}'*'
3425 logs=$logs' '$tmp/'*'$ts'*'
3427 for node in ${list//,/ }; do
3428 rsync -az $node:"$logs" $TMP
3431 local archive=$TMP/${TESTSUITE}-$ts.tar.bz2
3432 tar -jcf $archive $tmp/*$ts* $TMP/*${TESTSUITE}*
3438 local list=${1:-$(comma_list $(nodes_list))}
3440 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3452 for i in $(seq 0 $num_mntpts); do
3453 cmd="ls -laf ${mntpt_root}$i/$dir"
3459 for pid in $pids; do
3466 # target_start_and_reset_recovery_timer()
3467 # service_time = at_est2timeout(service_time);
3468 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3469 # INITIAL_CONNECT_TIMEOUT);
3470 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3471 #define CONNECTION_SWITCH_INC 1
3472 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3473 #define CONNECTION_SWITCH_MIN 5U
3475 max_recovery_time () {
3476 local init_connect_timeout=$(( TIMEOUT / 20 ))
3477 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3479 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3484 remove_mdt_files() {
3489 local mntpt=${MOUNT%/*}/$facet
3491 echo "removing files from $mdtdev on $facet: $files"
3492 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
3495 rm $mntpt/ROOT/$f || { rc=$?; break; }
3497 umount -f $mntpt || return $?
3501 duplicate_mdt_files() {
3506 local mntpt=${MOUNT%/*}/$facet
3508 echo "duplicating files on $mdtdev on $facet: $files"
3509 mkdir -p $mntpt || return $?
3510 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
3520 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
3521 pushd $mntpt/ROOT > /dev/null || return $?
3524 touch $f.bad || return $?
3525 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
3527 [ $rc -eq 0 ] || return $rc
3528 setfattr --restore $tmp || return $?
3534 local devs=${1//,/ }
3537 local rslt=$TMP/sgpdd_survey
3539 # sgpdd-survey cleanups ${rslt}.* files
3541 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"