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 LFSCK1=${LFSCK1:-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 $LFSCK1` ]; 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=${OBDSURVEY:-$(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 `dirname $0`/../mds/mds.ko ]; then
170 export CLIENTMODSONLY=yes
175 while getopts "rvwf:" opt $*; do
178 r) REFORMAT=--reformat;;
180 w) WRITECONF=writeconf;;
185 shift $((OPTIND - 1))
188 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
193 *) EXT=".ko"; USE_QUOTA=yes;;
197 do_facet mgs lctl pool_list $1
201 local fsname=${1%%.*}
202 local poolname=${1##$fsname.}
204 do_facet mgs lctl pool_new $1
206 # get param should return err unless pool is created
207 [[ $RC -ne 0 ]] && return $RC
209 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
210 2>/dev/null || echo foo" "" || RC=1
211 if [[ $RC -eq 0 ]]; then
214 error "pool_new failed $1"
219 add_pool_to_list () {
220 local fsname=${1%%.*}
221 local poolname=${1##$fsname.}
223 local listvar=${fsname}_CREATED_POOLS
224 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
227 remove_pool_from_list () {
228 local fsname=${1%%.*}
229 local poolname=${1##$fsname.}
231 local listvar=${fsname}_CREATED_POOLS
232 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
236 /sbin/lsmod | grep -q $1
242 BASE=`basename $module $EXT`
244 module_loaded ${BASE} && return
246 if [ "$BASE" == "lnet_selftest" ] && \
247 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
248 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
250 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
251 insmod ${LUSTRE}/${module}${EXT} $@
253 # must be testing a "make install" or "rpm" installation
258 load_modules_local() {
259 if [ -n "$MODPROBE" ]; then
263 if [ "$HAVE_MODULES" = true ]; then
269 echo Loading modules from $LUSTRE
270 load_module ../lnet/libcfs/libcfs
271 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
272 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
274 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
275 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
276 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
277 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
278 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
280 # disable it for now since it only hides the stack overflow upon test w/
282 # if [ "$NETTYPE" = "tcp" -o "$NETTYPE" = "o2ib" -o "$NETTYPE" = "ptl" ]; then
283 # echo $LNETOPTS | grep -q "local_nid_dist_zero=0" ||
284 # LNETOPTS="$LNETOPTS local_nid_dist_zero=0"
286 echo "lnet options: '$LNETOPTS'"
287 # note that insmod will ignore anything in modprobe.conf
288 load_module ../lnet/lnet/lnet $LNETOPTS
289 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
290 load_module ../lnet/klnds/$LNETLND
291 load_module lvfs/lvfs
292 load_module obdclass/obdclass
293 load_module ptlrpc/ptlrpc
294 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota $LQUOTAOPTS
299 if ! client_only; then
302 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
303 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
304 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
305 load_module lvfs/fsfilt_$FSTYPE
307 load_module obdfilter/obdfilter
310 load_module llite/lustre
311 load_module llite/llite_lloop
312 rm -f $TMP/ogdb-$HOSTNAME
314 [ -d /r ] && OGDB="/r/tmp"
315 $LCTL modules > $OGDB/ogdb-$HOSTNAME
316 # 'mount' doesn't look in $PATH, just sbin
317 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
323 # load modules on remote nodes optionally
324 # lustre-tests have to be installed on these nodes
325 if $LOAD_MODULES_REMOTE ; then
326 local list=$(comma_list $(remote_nodes_list))
327 echo loading modules on $list
328 do_rpc_nodes $list load_modules
333 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
334 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
335 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
336 echo "$LEAK_LUSTRE" 1>&2
337 echo "$LEAK_PORTALS" 1>&2
338 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
339 echo "Memory leaks detected"
340 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
346 wait_exit_ST client # bug 12845
348 if $LOAD_MODULES_REMOTE ; then
349 local list=$(comma_list $(remote_nodes_list))
350 if [ ! -z $list ]; then
351 echo unloading modules on $list
352 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
353 do_rpc_nodes $list check_mem_leak
357 $LUSTRE_RMMOD $FSTYPE || return 2
361 check_mem_leak || return 254
363 echo "modules unloaded."
371 local dev=$(facet_active $facet)_dev
372 local opt=${facet}_opt
373 local mntpt=$(facet_mntpt $facet)
375 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
376 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} $mntpt
378 if [ $RC -ne 0 ]; then
379 echo "mount -t lustre $@ ${!dev} $mntpt"
380 echo "Start of ${!dev} on ${facet} failed ${RC}"
382 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
383 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
384 lctl set_param debug_mb=${DEBUG_SIZE}; \
387 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
388 [ -z "$label" ] && echo no label for ${!dev} && exit 1
389 eval export ${facet}_svc=${label}
390 echo Started ${label}
395 # start facet device options
401 eval export ${facet}_dev=${device}
402 eval export ${facet}_opt=\"$@\"
404 local varname=${facet}failover_dev
405 if [ -n "${!varname}" ] ; then
406 eval export ${facet}failover_dev=${!varname}
408 eval export ${facet}failover_dev=$device
411 local mntpt=$(facet_mntpt $facet)
412 do_facet ${facet} mkdir -p $mntpt
413 eval export ${facet}_MOUNT=$mntpt
423 local HOST=`facet_active_host $facet`
424 [ -z $HOST ] && echo stop: no host for $facet && return 0
426 local mntpt=$(facet_mntpt $facet)
427 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
428 if [ ${running} -ne 0 ]; then
429 echo "Stopping $mntpt (opts:$@)"
430 do_facet ${facet} umount -d $@ $mntpt
433 # umount should block, but we should wait for unrelated obd's
434 # like the MGS or MGC to also stop.
436 wait_exit_ST ${facet}
439 # set quota version (both administrative and operational quotas)
440 quota_set_version() {
441 do_facet mds "lctl set_param lquota.${FSNAME}-MDT*.quota_type=$1"
443 local osts=$(get_facets OST)
444 for ost in ${osts//,/ }; do
446 do_facet $ost "lctl set_param lquota.${!varsvc}.quota_type=$1"
450 # save quota version (both administrative and operational quotas)
451 # the function will also switch to the new version and the new type
452 quota_save_version() {
454 local ver=$(tr -c -d "123" <<< $spec)
455 local type=$(tr -c -d "ug" <<< $spec)
457 local lustre_version=$(get_lustre_version mds)
458 if [[ $lustre_version = 1.8* ]] ; then
459 $LFS quotaoff -ug $MOUNT # just in case
460 [ -n "$ver" ] && quota_set_version $ver
462 echo mds running $lustre_version
463 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
466 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
468 do_facet mgs "lctl conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=$spec"
470 local osts=$(get_facets OST)
471 for ost in ${osts//,/ }; do
473 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
477 # client could mount several lustre
479 local fsname=${1:-$FSNAME}
481 do_facet mgs lctl get_param md*.${fsname}-MDT*.quota_type || rc=$?
482 do_nodes $(comma_list $(osts_nodes)) \
483 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
487 restore_quota_type () {
488 local mntpt=${1:-$MOUNT}
489 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
490 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
493 quota_save_version $old_QUOTA_TYPE
500 # 1. run quotacheck only if quota is off
501 # 2. save the original quota_type params, restore them after testing
503 # Suppose that quota type the same on mds and ost
504 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
505 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
506 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
507 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
508 export old_QUOTA_TYPE=$quota_type
509 quota_save_version $QUOTA_TYPE
512 local quota_usrs=$QUOTA_USERS
514 # get_filesystem_size
515 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
516 local blk_soft=$((disksz + 1024))
517 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
519 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
521 local i_hard=$((i_soft + i_soft / 20))
523 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
524 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
527 for usr in $quota_usrs; do
528 echo "Setting up quota on $client:$mntpt for $usr..."
530 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
532 eval $cmd || error "$cmd FAILED!"
534 # display the quota status
535 echo "Quota settings for $usr : "
536 $LFS quota -v -u $usr $mntpt || true
544 # Only supply -o to mount if we have options
545 if [ -n "$MOUNTOPT" ]; then
546 OPTIONS="-o $MOUNTOPT"
548 local device=$MGSNID:/$FSNAME
549 if [ -z "$mnt" -o -z "$FSNAME" ]; then
550 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
554 echo "Starting client: $client: $OPTIONS $device $mnt"
555 do_node $client mkdir -p $mnt
556 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
557 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
558 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
559 lctl set_param debug_mb=${DEBUG_SIZE}"
572 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
573 if [ $running -ne 0 ]; then
574 echo "Stopping client $client $mnt (opts:$force)"
575 do_node $client lsof -t $mnt || need_kill=no
576 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
577 pids=$(do_node $client lsof -t $mnt | sort -u);
578 if [ -n $pids ]; then
579 do_node $client kill -9 $pids || true
583 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
584 if [ $busy -ne 0 ] ; then
585 echo "$mnt is still busy, wait one second" && sleep 1
586 do_node $client umount $force $mnt
591 # nodes is comma list
592 sanity_mount_check_nodes () {
598 # FIXME: assume that all cluster nodes run the same os
599 [ "$(uname)" = Linux ] || return 0
602 for mnt in $mnts ; do
603 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
604 mpts=\\\$(mount | grep -w -c $mnt);
605 if [ \\\$running -ne \\\$mpts ]; then
606 echo \\\$(hostname) env are INSANE!;
614 sanity_mount_check_servers () {
616 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
617 echo Checking servers environments
619 # FIXME: modify get_facets to display all facets wo params
620 local facets="$(get_facets OST),$(get_facets MDS),mgs"
624 for facet in ${facets//,/ }; do
625 node=$(facet_host ${facet})
626 mntpt=$(facet_mntpt $facet)
627 sanity_mount_check_nodes $node $mntpt ||
628 { error "server $node environments are insane!"; return 1; }
632 sanity_mount_check_clients () {
633 local clients=${1:-$CLIENTS}
634 local mntpt=${2:-$MOUNT}
635 local mntpt2=${3:-$MOUNT2}
637 [ -z $clients ] && clients=$(hostname)
638 echo Checking clients $clients environments
640 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
641 error "clients environments are insane!"
644 sanity_mount_check () {
645 sanity_mount_check_servers || return 1
646 sanity_mount_check_clients || return 2
649 # mount clients if not mouted
650 zconf_mount_clients() {
653 local OPTIONS=${3:-$MOUNTOPT}
655 # Only supply -o to mount if we have options
656 if [ "$OPTIONS" ]; then
657 OPTIONS="-o $OPTIONS"
659 local device=$MGSNID:/$FSNAME
660 if [ -z "$mnt" -o -z "$FSNAME" ]; then
661 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
665 echo "Starting client $clients: $OPTIONS $device $mnt"
668 running=\\\$(mount | grep -c $mnt' ');
670 if [ \\\$running -eq 0 ] ; then
672 mount -t lustre $OPTIONS $device $mnt;
677 echo "Started clients $clients: "
678 do_nodes $clients "mount | grep -w $mnt"
680 do_nodes $clients "sysctl -w lnet.debug=\\\"$PTLDEBUG\\\";
681 sysctl -w lnet.subsystem_debug=\\\"${SUBSYSTEM# }\\\";
682 sysctl -w lnet.debug_mb=${DEBUG_SIZE};"
687 zconf_umount_clients() {
694 echo "Stopping clients: $clients $mnt (opts:$force)"
695 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
696 if [ \\\$running -ne 0 ] ; then
697 echo Stopping client \\\$(hostname) $mnt opts:$force;
698 lsof -t $mnt || need_kill=no;
699 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
700 pids=\\\$(lsof -t $mnt | sort -u);
701 if [ -n \\\"\\\$pids\\\" ]; then
705 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
706 if [ \\\$busy -ne 0 ] ; then
707 echo "$mnt is still busy, wait one second" && sleep 1;
713 shudown_node_hard () {
717 for i in $(seq $attempts) ; do
720 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
721 echo "waiting for $host to fail attempts=$attempts"
722 [ $i -lt $attempts ] || \
723 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
729 local mnt=${2:-$MOUNT}
732 if [ "$FAILURE_MODE" = HARD ]; then
733 shudown_node_hard $client
735 zconf_umount_clients $client $mnt -f
741 if [ "$FAILURE_MODE" = HARD ]; then
742 shudown_node_hard $(facet_active_host $facet)
743 elif [ "$FAILURE_MODE" = SOFT ]; then
750 if [ "$FAILURE_MODE" = HARD ]; then
751 $POWER_UP `facet_active_host $facet`
759 if [ "$FAILURE_MODE" = HARD ]; then
765 # recovery-scale functions
766 check_progs_installed () {
771 do_nodes $clients "PATH=:$PATH; status=true;
772 for prog in $progs; do
773 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
774 echo \\\$prog missing on \\\$(hostname);
782 echo __$(echo $1 | tr '-' 'X')
785 start_client_load() {
788 local var=$(client_var_name $client)_load
789 eval export ${var}=$load
791 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
792 BREAK_ON_ERROR=$BREAK_ON_ERROR \
793 END_RUN_FILE=$END_RUN_FILE \
794 LOAD_PID_FILE=$LOAD_PID_FILE \
795 TESTSUITELOG=$TESTSUITELOG \
797 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
798 log "Started client load: ${load} on $client"
803 start_client_loads () {
804 local -a clients=(${1//,/ })
805 local numloads=${#CLIENT_LOADS[@]}
808 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
809 testnum=$((nodenum % numloads))
810 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
812 # bug 22169: wait the background threads to start
816 # only for remote client
817 check_client_load () {
819 local var=$(client_var_name $client)_load
820 local TESTLOAD=run_${!var}.sh
822 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
824 # bug 18914: try to connect several times not only when
825 # check ps, but while check_catastrophe also
828 while [ $RC = 254 -a $tries -gt 0 ]; do
832 if ! check_catastrophe $client; then
834 if [ $RC -eq 254 ]; then
835 # FIXME: not sure how long we shuold sleep here
839 echo "check catastrophe failed: RC=$RC "
844 # We can continue try to connect if RC=254
845 # Just print the warning about this
846 if [ $RC = 254 ]; then
847 echo "got a return status of $RC from do_node while checking catastrophe on $client"
850 # see if the load is still on the client
853 while [ $RC = 254 -a $tries -gt 0 ]; do
857 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
862 if [ $RC = 254 ]; then
863 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
864 # see if we can diagnose a bit why this is
869 check_client_loads () {
870 local clients=${1//,/ }
874 for client in $clients; do
875 check_client_load $client
877 if [ "$rc" != 0 ]; then
878 log "Client load failed on node $client, rc=$rc"
884 restart_client_loads () {
885 local clients=${1//,/ }
886 local expectedfail=${2:-""}
890 for client in $clients; do
891 check_client_load $client
893 if [ "$rc" != 0 -a "$expectedfail" ]; then
894 local var=$(client_var_name $client)_load
895 start_client_load $client ${!var}
896 echo "Restarted client load ${!var}: on $client. Checking ..."
897 check_client_load $client
899 if [ "$rc" != 0 ]; then
900 log "Client load failed to restart on node $client, rc=$rc"
901 # failure one client load means test fail
902 # we do not need to check other
910 # End recovery-scale functions
912 # verify that lustre actually cleaned up properly
914 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
915 error "LBUG/LASSERT detected"
916 BUSY=`dmesg | grep -i destruct || true`
919 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
923 check_mem_leak || exit 204
925 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
926 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
928 if module_loaded lnet || module_loaded libcfs; then
929 echo "$0: modules still loaded..." 1>&2
946 RESULT=$(do_node $node "$TEST")
947 if [ "$RESULT" == "$FINAL" ]; then
948 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
951 [ $WAIT -ge $MAX ] && break
952 echo "Waiting $((MAX - WAIT)) secs for update"
953 WAIT=$((WAIT + sleep))
956 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
960 wait_update_facet () {
963 wait_update $(facet_active_host $facet) "$@"
966 wait_delete_completed () {
967 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
968 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
972 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
974 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
975 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
976 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
977 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
981 echo "Delete is not completed in $MAX_WAIT sec"
987 check_network "$host" 900
988 while ! do_node $host hostname > /dev/null; do sleep 5; done
993 local host=`facet_active_host $facet`
997 wait_recovery_complete () {
1000 # Use default policy if $2 is not passed by caller.
1001 local MAX=${2:-$(max_recovery_time)}
1003 local var_svc=${facet}_svc
1004 local procfile="*.${!var_svc}.recovery_status"
1008 while [ $WAIT -lt $MAX ]; do
1009 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
1010 [[ $STATUS = "status: COMPLETE" ]] && return 0
1013 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
1015 echo "$facet recovery not done in $MAX sec. $STATUS"
1019 wait_mds_ost_sync () {
1020 # just because recovery is done doesn't mean we've finished
1021 # orphan cleanup. Wait for llogs to get synchronized.
1022 echo "Waiting for orphan cleanup..."
1023 # MAX value includes time needed for MDS-OST reconnection
1024 local MAX=$(( TIMEOUT * 2 ))
1026 while [ $WAIT -lt $MAX ]; do
1027 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1028 "$LCTL get_param -n obdfilter.*.mds_sync"))
1030 for ((i=0; i<${#sync[@]}; i++)); do
1031 [ ${sync[$i]} -eq 0 ] && continue
1032 # there is a not finished MDS-OST synchronization
1036 sleep 2 # increase waiting time and cover statfs cache
1037 [ ${con} -eq 1 ] && return 0
1038 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1041 echo "$facet recovery not done in $MAX sec. $STATUS"
1045 wait_destroy_complete () {
1046 echo "Waiting for destroy to be done..."
1047 # MAX value shouldn't be big as this mean server responsiveness
1048 # never increase this just to make test pass but investigate
1049 # why it takes so long time
1052 while [ $WAIT -lt $MAX ]; do
1053 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1055 for ((i=0; i<${#RPCs[@]}; i++)); do
1056 [ ${RPCs[$i]} -eq 0 ] && continue
1057 # there are still some destroy RPCs in flight
1062 [ ${con} -eq 1 ] && return 0 # done waiting
1063 echo "Waiting $WAIT secs for destroys to be done."
1066 echo "Destroys weren't done in $MAX sec."
1076 # conf-sanity 31 takes a long time cleanup
1077 while [ $WAIT -lt 300 ]; do
1078 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1079 [ -z "${running}" ] && return 0
1080 echo "waited $WAIT for${running}"
1081 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1083 WAIT=$((WAIT + INTERVAL))
1085 echo "service didn't stop after $WAIT seconds. Still running:"
1090 wait_remote_prog () {
1096 [ "$PDSH" = "no_dsh" ] && return 0
1098 while [ $WAIT -lt $2 ]; do
1099 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1100 [ -z "${running}" ] && return 0 || true
1101 echo "waited $WAIT for: "
1103 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1105 WAIT=$((WAIT + INTERVAL))
1107 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1108 [ -z "$pids" ] && return 0
1109 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1110 # FIXME: not portable
1111 for pid in $pids; do
1112 cat /proc/${pid}/status || true
1113 cat /proc/${pid}/wchan || true
1115 kill -9 $pid || true
1124 # not every config has many clients
1126 if [ -n "$CLIENTS" ]; then
1127 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1129 stat -f $MOUNT > /dev/null
1135 # usually checked on particular client or locally
1137 if [ ! -z "$client" ]; then
1138 $PDSH $client "stat -f $MOUNT" > /dev/null
1140 stat -f $MOUNT > /dev/null
1148 client_reconnect() {
1149 uname -n >> $MOUNT/recon
1150 if [ -z "$CLIENTS" ]; then
1151 df $MOUNT; uname -n >> $MOUNT/recon
1153 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1155 echo Connected clients:
1157 ls -l $MOUNT/recon > /dev/null
1164 echo "Failing $facet on node `facet_active_host $facet`"
1165 shutdown_facet $facet
1166 [ -n "$sleep_time" ] && sleep $sleep_time
1170 RECOVERY_START_TIME=`date +%s`
1171 echo "df pid is $DFPID"
1172 change_active $facet
1173 local TO=`facet_active_host $facet`
1174 echo "Failover $facet to $TO"
1176 mount_facet $facet || error "Restart of $facet failed"
1185 do_facet $facet sync
1187 local svc=${facet}_svc
1188 do_facet $facet $LCTL --device %${!svc} notransno
1189 do_facet $facet $LCTL --device %${!svc} readonly
1190 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1191 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1194 replay_barrier_nodf() {
1195 local facet=$1 echo running=${running}
1196 do_facet $facet sync
1197 local svc=${facet}_svc
1198 echo Replay barrier on ${!svc}
1199 do_facet $facet $LCTL --device %${!svc} notransno
1200 do_facet $facet $LCTL --device %${!svc} readonly
1201 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1202 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1205 mds_evict_client() {
1206 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
1207 local mdtdevice=$(get_mds_mdt_device_proc_path)
1208 do_facet mds "lctl set_param -n ${mdtdevice}.${mds_svc}.evict_client $UUID"
1211 ost_evict_client() {
1212 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
1213 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1217 facet_failover $* || error "failover: $?"
1218 clients_up || error "post-failover df: $?"
1223 facet_failover $facet
1229 change_active $facet
1230 mount_facet $facet -o abort_recovery
1231 clients_up || echo "first df failed: $?"
1232 clients_up || error "post-failover df: $?"
1236 echo There is no lmc. This is mountconf, baby.
1241 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1242 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1248 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1254 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1255 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1256 if [ -z "$ID" ]; then
1257 echo "Could not get a ptl id for $1..."
1266 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1273 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1274 if type __h2elan >/dev/null 2>&1; then
1277 ID=`echo $1 | sed 's/[^0-9]*//g'`
1285 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1286 ID=`echo $1 | sed 's/[^0-9]*//g'`
1290 declare -fx h2openib
1293 h2name_or_ip "$1" "o2ib"
1300 [ "$facet" == client ] && echo -n $HOSTNAME && return
1301 varname=${facet}_HOST
1302 if [ -z "${!varname}" ]; then
1303 if [ "${facet:0:3}" == "ost" ]; then
1304 eval ${facet}_HOST=${ost_HOST}
1312 local activevar=${facet}active
1314 if [ -f $TMP/${facet}active ] ; then
1315 source $TMP/${facet}active
1318 active=${!activevar}
1319 if [ -z "$active" ] ; then
1326 facet_active_host() {
1328 local active=`facet_active $facet`
1329 if [ "$facet" == client ]; then
1332 echo `facet_host $active`
1338 local failover=${facet}failover
1339 host=`facet_host $failover`
1340 [ -z "$host" ] && return
1341 local curactive=`facet_active $facet`
1342 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1343 eval export ${facet}active=$facet
1345 eval export ${facet}active=$failover
1347 # save the active host for this facet
1348 local activevar=${facet}active
1349 echo "$activevar=${!activevar}" > $TMP/$activevar
1354 # do not stripe off hostname if verbose, bug 19215
1355 if [ x$1 = x--verbose ]; then
1363 if [ "$HOST" = "$HOSTNAME" ]; then
1365 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1366 echo "cannot run remote command on $HOST with $myPDSH"
1370 echo "CMD: $HOST $@" >&2
1371 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1374 if [ "$myPDSH" = "rsh" ]; then
1375 # we need this because rsh does not return exit code of an executed command
1376 local command_status="$TMP/cs"
1377 rsh $HOST ":> $command_status"
1378 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1379 cd $RPWD; sh -c \"$@\") ||
1380 echo command failed >$command_status"
1381 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1386 # print HOSTNAME for myPDSH="no_dsh"
1387 if [[ $myPDSH = no_dsh ]]; then
1388 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1390 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1393 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1395 return ${PIPESTATUS[0]}
1399 do_node --verbose "$@"
1402 single_local_node () {
1403 [ "$1" = "$HOSTNAME" ]
1408 # do not stripe off hostname if verbose, bug 19215
1409 if [ x$1 = x--verbose ]; then
1417 if $(single_local_node $rnodes); then
1419 do_nodev $rnodes "$@"
1421 do_node $rnodes "$@"
1426 # This is part from do_node
1429 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1430 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1433 echo "CMD: $rnodes $@" >&2
1434 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1437 # do not replace anything from pdsh output if -N is used
1438 # -N Disable hostname: prefix on lines of output.
1439 if $verbose || [[ $myPDSH = *-N* ]]; then
1440 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1442 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1444 return ${PIPESTATUS[0]}
1450 local HOST=`facet_active_host $facet`
1451 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1456 do_nodes --verbose "$@"
1462 # make sure its not already running
1464 rm -f $TMP/${facet}active
1465 do_facet ${facet} $MKFS $*
1471 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1472 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1478 if combined_mgs_mds && [[ $facet = "mgs" ]] ; then
1481 local var=${facet}_MOUNT
1482 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1491 # make sure we are using the primary server, so test-framework will
1492 # be able to clean up properly.
1493 activemds=`facet_active mds`
1494 if [ $activemds != "mds" ]; then
1498 local clients=$CLIENTS
1499 [ -z $clients ] && clients=$(hostname)
1501 zconf_umount_clients $clients $MOUNT "$*" || true
1502 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1504 [ "$CLIENTONLY" ] && return
1505 # The add fn does rm ${facet}active file, this would be enough
1506 # if we use do_facet <facet> only after the facet added, but
1507 # currently we use do_facet mds in local.sh
1509 rm -f ${TMP}/mdsactive
1510 for num in `seq $OSTCOUNT`; do
1512 rm -f $TMP/ost${num}active
1514 if ! combined_mgs_mds ; then
1521 cleanup_echo_devs () {
1522 local devs=$($LCTL dl | grep echo | awk '{print $4}')
1524 for dev in $devs; do
1525 $LCTL --device $dev cleanup
1526 $LCTL --device $dev detach
1531 nfs_client_mode && return
1539 combined_mgs_mds () {
1540 [[ $MDSDEV = $MGSDEV ]] && [[ $mds_HOST = $mgs_HOST ]]
1544 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1547 # We need ldiskfs here, may as well load them all
1549 [ "$CLIENTONLY" ] && return
1550 echo Formatting mgs, mds, osts
1551 if ! combined_mgs_mds ; then
1552 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1556 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV || exit 10
1558 add mds $MDS_MKFS_OPTS $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
1561 for num in `seq $OSTCOUNT`; do
1563 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1565 add ost$num $OST_MKFS_OPTS $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1571 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1576 zconf_umount `hostname` $1 || error "umount failed"
1577 zconf_mount `hostname` $1 || error "mount failed"
1580 writeconf_facet () {
1584 do_facet $facet "$TUNEFS --writeconf $dev"
1588 writeconf_facet mds $MDSDEV
1590 for num in `seq $OSTCOUNT`; do
1591 DEVNAME=`ostdevname $num`
1592 writeconf_facet ost$num $DEVNAME
1597 nfs_client_mode && return
1599 sanity_mount_check ||
1600 error "environments are insane!"
1603 if [ -z "$CLIENTONLY" ]; then
1604 echo Setup mgs, mdt, osts
1606 echo $WRITECONF | grep -q "writeconf" && \
1609 if ! combined_mgs_mds ; then
1610 start mgs $MGSDEV $mgs_MOUNT_OPTS
1613 start mds $MDSDEV $MDS_MOUNT_OPTS
1614 # We started mds, now we should set failover variable properly.
1615 # Set mdsfailover_HOST if it is not set (the default failnode).
1616 if [ -z "$mdsfailover_HOST" ]; then
1617 mdsfailover_HOST=$(facet_host mds)
1620 for num in `seq $OSTCOUNT`; do
1621 DEVNAME=`ostdevname $num`
1622 start ost$num $DEVNAME $OST_MOUNT_OPTS
1624 # We started ost$num, now we should set ost${num}failover variable properly.
1625 # Set ost${num}failover_HOST if it is not set (the default failnode).
1626 varname=ost${num}failover_HOST
1627 if [ -z "${!varname}" ]; then
1628 eval ost${num}failover_HOST=$(facet_host ost${num})
1633 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1635 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1637 if [ "$MOUNT_2" ]; then
1638 mount_client $MOUNT2
1639 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1645 mounted_lustre_filesystems() {
1646 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1649 init_facet_vars () {
1650 [ "$CLIENTONLY" ] && return 0
1657 eval export ${facet}_dev=${device}
1658 eval export ${facet}_opt=\"$@\"
1660 local dev=${facet}_dev
1661 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1662 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1664 eval export ${facet}_svc=${label}
1666 local varname=${facet}failover_HOST
1667 if [ -z "${!varname}" ]; then
1668 eval $varname=$(facet_host $facet)
1671 # ${facet}failover_dev is set in cfg file
1672 varname=${facet}failover_dev
1673 if [ -n "${!varname}" ] ; then
1674 eval export ${facet}failover_dev=${!varname}
1676 eval export ${facet}failover_dev=$device
1679 # get mount point of already mounted device
1680 # is facet_dev is already mounted then use the real
1681 # mount point of this facet; otherwise use $(facet_mntpt $facet)
1682 # i.e. ${facet}_MOUNT if specified by user or default
1683 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
1684 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
1685 if [ -z $mntpt ]; then
1686 mntpt=$(facet_mntpt $facet)
1688 eval export ${facet}_MOUNT=$mntpt
1691 init_facets_vars () {
1693 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
1695 remote_ost_nodsh && return
1697 for num in `seq $OSTCOUNT`; do
1698 DEVNAME=`ostdevname $num`
1699 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1703 init_param_vars () {
1704 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1705 export MDSVER=$(do_facet mds "lctl get_param version" | cut -d. -f1,2)
1706 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1707 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1711 TIMEOUT=$(do_facet mds "lctl get_param -n timeout")
1713 log "Using TIMEOUT=$TIMEOUT"
1715 if [ "$ENABLE_QUOTA" ]; then
1716 setup_quota $MOUNT || return 2
1720 nfs_client_mode () {
1721 if [ "$NFSCLIENT" ]; then
1722 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1723 local clients=$CLIENTS
1724 [ -z $clients ] && clients=$(hostname)
1726 # FIXME: remove hostname when 19215 fixed
1727 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1728 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1729 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1735 check_config_client () {
1738 local mounted=$(mount | grep " $mntpt ")
1739 if [ "$CLIENTONLY" ]; then
1741 # CLIENTONLY should not depend on *_HOST settings
1742 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
1743 # in theory someone could create a new,
1744 # client-only config file that assumed lustre was already
1745 # configured and didn't set the MGSNID. If MGSNID is not set,
1746 # then we should use the mgs nid currently being used
1747 # as the default value. bug 18021
1748 [[ x$MGSNID = x ]] &&
1751 if [[ x$mgc != xMGC$MGSNID ]]; then
1752 if [ "$mgs_HOST" ]; then
1753 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
1754 [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
1755 error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
1761 local myMGS_host=$mgs_HOST
1762 if [ "$NETTYPE" = "ptl" ]; then
1763 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1766 echo Checking config lustre mounted on $mntpt
1767 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1768 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1770 # if [ "$mgshost" != "$myMGS_host" ]; then
1771 # error_exit "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1772 # Please use correct config or set mds_HOST correctly!"
1777 check_config_clients () {
1778 local clients=${CLIENTS:-$HOSTNAME}
1781 nfs_client_mode && return
1783 do_rpc_nodes $clients check_config_client $mntpt
1785 sanity_mount_check ||
1786 error "environments are insane!"
1790 local mdstimeout=$(do_facet mds "lctl get_param -n timeout")
1791 local cltimeout=$(lctl get_param -n timeout)
1792 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
1793 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
1800 local mounted=$(mounted_lustre_filesystems)
1802 echo $mounted' ' | grep -w -q $mntpt' '
1806 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
1810 # empty lustre filesystem may have empty directories lost+found and .lustre
1812 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
1813 -print | wc -l) = 1 ] || return 1
1814 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
1815 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
1819 check_and_setup_lustre() {
1820 nfs_client_mode && return
1822 local MOUNTED=$(mounted_lustre_filesystems)
1826 # both MOUNT and MOUNT2 are not mounted
1827 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
1828 [ "$REFORMAT" ] && formatall
1829 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
1831 is_mounted $MOUNT || error "NAME=$NAME not mounted"
1832 export I_MOUNTED=yes
1836 elif is_mounted $MOUNT2; then
1838 # MOUNT2 is mounted, while MOUNT_2 is not set
1839 if ! [ "$MOUNT_2" ]; then
1840 cleanup_mount $MOUNT2
1841 export I_UMOUNTED2=yes
1844 # MOUNT2 is mounted, MOUNT_2 is set
1846 # FIXME: what to do if check_config failed?
1848 # 1) remote client has mounted other Lustre fs ?
1849 # 2) it has insane env ?
1850 # let's try umount MOUNT2 on all clients and mount it again:
1851 if ! check_config_clients $MOUNT2; then
1852 cleanup_mount $MOUNT2
1853 restore_mount $MOUNT2
1854 export I_MOUNTED2=yes
1859 # MOUNT is mounted MOUNT2 is not mounted
1860 elif [ "$MOUNT_2" ]; then
1861 restore_mount $MOUNT2
1862 export I_MOUNTED2=yes
1866 # FIXME: what to do if check_config failed?
1868 # 1) remote client has mounted other Lustre fs?
1869 # 2) lustre is mounted on remote_clients atall ?
1870 check_config_clients $MOUNT
1874 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
1875 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
1876 lctl set_param debug_mb=${DEBUG_SIZE};
1879 if [ "$ONLY" == "setup" ]; then
1885 local clients=${CLIENTS:-$HOSTNAME}
1888 zconf_mount_clients $clients $mntpt
1892 local clients=${CLIENTS:-$HOSTNAME}
1895 zconf_umount_clients $clients $mntpt
1898 cleanup_and_setup_lustre() {
1899 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
1900 lctl set_param debug=0 || true
1902 if [ "$ONLY" == "cleanup" ]; then
1906 check_and_setup_lustre
1909 # Get all of the server target devices from a given server node and type.
1918 mdt) obd_type="osd" ;;
1919 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
1920 *) echo "invalid server type" && return 1 ;;
1923 devs=$(do_node $node "lctl get_param -n $obd_type.*.mntdev")
1924 for dev in $devs; do
1926 *loop*) do_node $node "losetup $dev" | \
1927 sed -e "s/.*(//" -e "s/).*//" ;;
1933 # Get all of the server target devices.
1939 for node in $(osts_nodes); do
1940 OSTDEVS[i]=$(get_mnt_devs $node ost)
1945 # Run e2fsck on MDT or OST device.
1952 df > /dev/null # update statfs data on disk
1953 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
1956 local rc=${PIPESTATUS[0]}
1957 [ $rc -le $FSCK_MAX_ERR ] || \
1958 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
1962 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
1969 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
1970 error "fail to create file in $SHARED_DIRECTORY")
1972 # make sure everything gets to the backing store
1973 local list=$(comma_list $CLIENTS $(facet_host mds) $(osts_nodes))
1974 do_nodes $list "sync; sleep 2; sync"
1976 do_nodes $list ls $tmp_file || \
1977 error "$SHARED_DIRECTORY is not a shared directory"
1980 run_e2fsck $(facet_host mds) $MDSDEV
1985 for node in $(osts_nodes); do
1986 for dev in ${OSTDEVS[i]}; do
1987 local ostdb_opt=`eval echo $OSTDB_OPT`
1988 run_e2fsck $node $dev $ostidx "$ostdb_opt"
1989 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
1990 ostidx=$((ostidx + 1))
1997 local cmd="$LFSCK1 -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2000 local rc=${PIPESTATUS[0]}
2001 [ $rc -le $FSCK_MAX_ERR ] || \
2002 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2003 echo "lfsck finished with rc=$rc"
2005 rm -rvf $MDSDB* $OSTDB* || true
2010 check_and_cleanup_lustre() {
2011 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2014 if [ "$SKIP_LFSCK" == "no" ]; then
2022 if is_mounted $MOUNT; then
2023 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2024 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2027 if [ "$I_UMOUNTED2" = "yes" ]; then
2028 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2031 if [ "$I_MOUNTED2" = "yes" ]; then
2032 cleanup_mount $MOUNT2
2035 if [ "$I_MOUNTED" = "yes" ]; then
2036 cleanupall -f || error "cleanup failed"
2048 while [ $NETWORK -eq 0 ]; do
2049 if ping -c 1 -w 3 $1 > /dev/null; then
2053 echo "waiting for $1, $((MAX - WAIT)) secs left"
2056 if [ $WAIT -gt $MAX ]; then
2057 echo "Network not available"
2063 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2074 # the sed converts spaces to commas, but leaves the last space
2075 # alone, so the line doesn't end with a comma.
2076 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2079 # list, excluded are the comma separated lists
2080 exclude_items_from_list () {
2086 for item in ${excluded//,/ }; do
2087 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2089 echo $(comma_list $list)
2092 # list, expand are the comma separated lists
2094 local list=${1//,/ }
2095 local expand=${2//,/ }
2098 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2099 echo $(comma_list $expanded)
2102 testslist_filter () {
2103 local script=$LUSTRE/tests/${TESTSUITE}.sh
2105 [ -f $script ] || return 0
2107 local start_at=$START_AT
2108 local stop_at=$STOP_AT
2110 local var=${TESTSUITE//-/_}_START_AT
2111 [ x"${!var}" != x ] && start_at=${!var}
2112 var=${TESTSUITE//-/_}_STOP_AT
2113 [ x"${!var}" != x ] && stop_at=${!var}
2115 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2116 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2117 /^'${start_at}'$/ {flag = 0}
2118 {if (flag == 1) print $0}
2119 /^'${stop_at}'$/ { flag = 1 }'
2123 (cd `dirname $1`; echo $PWD/`basename $1`)
2127 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
2128 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
2134 OST ) for ((i=1; i<=$OSTCOUNT; i++)) do
2135 list="$list ${name}$i"
2137 * ) error "Invalid facet type"
2140 echo $(comma_list $list)
2143 ##################################
2144 # Adaptive Timeouts funcs
2147 # only check mds, we assume at_max is the same on all nodes
2148 local at_max=$(do_facet mds "lctl get_param -n at_max")
2149 if [ $at_max -eq 0 ]; then
2159 # suppose that all ost-s has the same at_max set
2160 if [ $facet == "ost" ]; then
2161 do_facet ost1 "lctl get_param -n at_max"
2163 do_facet $facet "lctl get_param -n at_max"
2173 if [ $facet == "ost" ]; then
2174 for i in `seq $OSTCOUNT`; do
2175 do_facet ost$i "lctl set_param at_max=$at_max"
2178 do_facet $facet "lctl set_param at_max=$at_max"
2183 ##################################
2187 # OBD_FAIL_MDS_ALL_REQUEST_NET
2189 do_facet mds lctl set_param fail_loc=0x123
2190 do_facet client "$1" || RC=$?
2191 do_facet mds lctl set_param fail_loc=0
2196 # OBD_FAIL_MDS_ALL_REPLY_NET
2198 do_facet mds lctl set_param fail_loc=0x122
2199 do_facet client "$@" || RC=$?
2200 do_facet mds lctl set_param fail_loc=0
2204 drop_reint_reply() {
2205 # OBD_FAIL_MDS_REINT_NET_REP
2207 do_facet mds lctl set_param fail_loc=0x119
2208 do_facet client "$@" || RC=$?
2209 do_facet mds lctl set_param fail_loc=0
2214 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2216 do_facet ost1 lctl set_param fail_loc=0x214
2217 do_facet client "$1" || RC=$?
2218 do_facet client "sync"
2219 do_facet ost1 lctl set_param fail_loc=0
2223 drop_ldlm_cancel() {
2224 #define OBD_FAIL_LDLM_CANCEL 0x304
2226 do_facet client lctl set_param fail_loc=0x304
2227 do_facet client "$@" || RC=$?
2228 do_facet client lctl set_param fail_loc=0
2232 drop_bl_callback() {
2233 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2235 do_facet client lctl set_param fail_loc=0x305
2236 do_facet client "$@" || RC=$?
2237 do_facet client lctl set_param fail_loc=0
2242 #define OBD_FAIL_LDLM_REPLY 0x30c
2244 do_facet mds lctl set_param fail_loc=0x30c
2245 do_facet client "$@" || RC=$?
2246 do_facet mds lctl set_param fail_loc=0
2254 echo "clearing fail_loc on $facet"
2255 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2258 set_nodes_failloc () {
2259 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2262 cancel_lru_locks() {
2263 $LCTL mark "cancel_lru_locks $1 start"
2264 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2265 $LCTL set_param -n $d=clear
2267 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2268 $LCTL mark "cancel_lru_locks $1 stop"
2273 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2274 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2275 echo "$DEFAULT_LRU_SIZE"
2280 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2283 lru_resize_disable()
2285 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2290 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2291 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2292 echo there is still data in page cache $FILE ?
2293 lctl get_param -n $FILE
2300 create_fake_exports () {
2303 #obd_fail_val = num;
2304 #define OBD_FAIL_TGT_FAKE_EXP 0x708
2305 do_facet $facet "lctl set_param fail_val=$num"
2306 do_facet $facet "lctl set_param fail_loc=0x80000708"
2311 DEBUGSAVE="$(lctl get_param -n debug)"
2315 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
2319 ##################################
2321 ##################################
2324 local TYPE=${TYPE:-"FAIL"}
2327 [ -d "$SHARED_DIR_LOGS" ] && tmp=$SHARED_DIR_LOGS
2330 # do not dump logs if $1=false
2331 if [ "x$1" = "xfalse" ]; then
2336 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2339 ERRLOG=$tmp/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
2340 echo "Dumping lctl log to $ERRLOG"
2341 # We need to dump the logs on all nodes
2342 do_nodes $(comma_list $(nodes_list)) $NODE $LCTL dk $ERRLOG
2345 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2351 if $FAIL_ON_ERROR; then
2362 # use only if we are ignoring failures for this test, bugno required.
2363 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2364 # e.g. error_ignore 5494 "your message"
2366 local TYPE="IGNORE (bz$1)"
2372 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2376 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2377 [ "$TESTSUITELOG" ] && \
2378 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2381 build_test_filter() {
2382 EXCEPT="$EXCEPT $(testslist_filter)"
2384 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2388 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2389 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2390 [ "$EXCEPT_SLOW" ] && \
2391 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2392 for E in $EXCEPT $ALWAYS_EXCEPT; do
2393 eval EXCEPT_${E}=true
2395 for E in $EXCEPT_SLOW; do
2396 eval EXCEPT_SLOW_${E}=true
2398 for G in $GRANT_CHECK_LIST; do
2399 eval GCHECK_ONLY_${G}=true
2404 if [[ $1 = [a-z]* ]]; then
2411 # print a newline if the last test was skipped
2412 export LAST_SKIPPED=
2416 export base=`basetest $1`
2417 if [ ! -z "$ONLY" ]; then
2419 if [ ${!testname}x != x ]; then
2420 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2425 if [ ${!testname}x != x ]; then
2426 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2435 if [ ${!testname}x != x ]; then
2437 TESTNAME=test_$1 skip "skipping excluded test $1"
2440 testname=EXCEPT_$base
2441 if [ ${!testname}x != x ]; then
2443 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2446 testname=EXCEPT_SLOW_$1
2447 if [ ${!testname}x != x ]; then
2449 TESTNAME=test_$1 skip "skipping SLOW test $1"
2452 testname=EXCEPT_SLOW_$base
2453 if [ ${!testname}x != x ]; then
2455 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2465 EQUALS="======================================================================"
2469 local suffixlen=$((${#EQUALS} - ${#msg}))
2470 [ $suffixlen -lt 5 ] && suffixlen=5
2471 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
2476 module_loaded lnet || load_modules
2488 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2493 strace -o $TMP/$1.strace -ttt $*
2495 log "FINISHED: $*: rc $RC"
2500 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
2505 FFREE=`lctl get_param -n mds.*.filesfree`
2506 FTOTAL=`lctl get_param -n mds.*.filestotal`
2507 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2511 echo -n "Resetting fail_loc on all nodes..."
2512 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2520 export tdir=d0.${TESTSUITE}/d${base}
2522 local SAVE_UMASK=`umask`
2525 local BEFORE=`date +%s`
2527 log "== test $testnum: $message == `date +%H:%M:%S` ($BEFORE)"
2529 export TESTNAME=test_$testnum
2531 test_${testnum} || error "test_$testnum failed with $?"
2535 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2536 check_catastrophe || error "LBUG/LASSERT detected"
2537 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2538 pass "($((`date +%s` - $BEFORE))s)"
2546 (cd `dirname $1`; echo $PWD/`basename $1`)
2550 export base=`basetest $1`
2551 [ "$CHECK_GRANT" == "no" ] && return 0
2553 testname=GCHECK_ONLY_${base}
2554 [ ${!testname}x == x ] && return 0
2556 echo -n "checking grant......"
2558 local clients=$CLIENTS
2559 [ -z $clients ] && clients=$(hostname)
2561 # sync all the data and make sure no pending data on server
2562 do_nodes $clients sync
2565 client_grant=`do_nodes $clients \
2566 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
2567 awk '{total += $1} END{print total}'`
2570 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
2571 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
2572 awk '{total += $1} END{print total}'`
2574 # check whether client grant == server grant
2575 if [ $client_grant -ne $server_grant ]; then
2576 echo "failed: client:${client_grant} server: ${server_grant}."
2577 do_nodes $(comma_list $(osts_nodes)) \
2578 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
2579 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
2582 echo "pass: client:${client_grant} server: ${server_grant}"
2586 ########################
2592 ost=`echo $1 | awk -F_ '{print $3}'`
2593 if [ -z $ost ]; then
2594 ost=`echo $1 | sed 's/-osc.*//'`
2601 [ "$node" != "$(hostname)" ]
2606 remote_node $mds_HOST
2611 [ "$CLIENTONLY" ] && return 0 || true
2612 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2618 for node in $(osts_nodes) ; do
2619 remote_node $node && return 0
2626 [ "$CLIENTONLY" ] && return 0 || true
2627 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2633 MGS=$(facet_host mgs)
2634 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2638 remote_ost && remote_mds
2643 remote_mds_nodsh || remote_ost_nodsh || \
2644 $(single_local_node $(comma_list $(nodes_list)))
2648 local OSTNODES=$(facet_host ost1)
2651 for num in `seq $OSTCOUNT`; do
2652 local myOST=$(facet_host ost$num)
2653 OSTNODES="$OSTNODES $myOST"
2655 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
2661 # FIXME. We need a list of clients
2662 local myNODES=$HOSTNAME
2665 # CLIENTS (if specified) contains the local client
2666 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
2668 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
2669 myNODES="$myNODES $(osts_nodes) $mds_HOST"
2672 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
2677 remote_nodes_list () {
2678 local rnodes=$(nodes_list)
2679 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2683 init_clients_lists () {
2684 # Sanity check: exclude the local client from RCLIENTS
2685 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2687 # Sanity check: exclude the dup entries
2688 rclients=$(for i in $rclients; do echo $i; done | sort -u)
2690 local clients="$SINGLECLIENT $HOSTNAME $rclients"
2692 # Sanity check: exclude the dup entries from CLIENTS
2693 # for those configs which has SINGLCLIENT set to local client
2694 clients=$(for i in $clients; do echo $i; done | sort -u)
2696 CLIENTS=`comma_list $clients`
2697 local -a remoteclients=($rclients)
2698 for ((i=0; $i<${#remoteclients[@]}; i++)); do
2699 varname=CLIENT$((i + 2))
2700 eval $varname=${remoteclients[i]}
2703 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
2706 get_random_entry () {
2709 rnodes=${rnodes//,/ }
2711 local -a nodes=($rnodes)
2712 local num=${#nodes[@]}
2713 local i=$((RANDOM * num * 2 / 65536))
2719 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
2724 lctl get_param version | grep -q patchless
2728 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
2733 echo $nodes | wc -w || true
2737 local nodes=$(osts_nodes)
2738 local osscount=$(get_node_count "$nodes")
2739 [ ! "$OSTCOUNT" = "$osscount" ]
2742 generate_machine_file() {
2743 local nodes=${1//,/ }
2744 local machinefile=$2
2746 for node in $nodes; do
2747 echo $node >>$machinefile || \
2748 { echo "can not generate machinefile $machinefile" && return 1; }
2753 local file=$1/stripe
2755 $LFS getstripe -v $file || error
2759 setstripe_nfsserver () {
2762 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
2763 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
2765 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
2767 do_nodev $nfsserver lfs setstripe "$@"
2770 check_runas_id_ret() {
2772 local myRUNAS_UID=$1
2773 local myRUNAS_GID=$2
2776 if [ -z "$myRUNAS" ]; then
2777 error_exit "myRUNAS command must be specified for check_runas_id"
2779 mkdir $DIR/d0_runas_test
2781 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
2782 if ! $myRUNAS touch $DIR/d0_runas_test/f$$ ; then
2783 do_nodesv $(comma_list $(nodes_list)) grep -w $myRUNAS_UID /etc/passwd
2786 rm -rf $DIR/d0_runas_test
2791 local myRUNAS_UID=$1
2792 local myRUNAS_GID=$2
2795 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
2796 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
2797 Please set RUNAS_ID to some UID which exists on MDS and client or
2798 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
2801 # Run multiop in the background, but wait for it to print
2802 # "PAUSING" to its stdout before returning from this function.
2803 multiop_bg_pause() {
2804 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
2808 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
2811 echo "$MULTIOP_PROG $FILE v$ARGS"
2812 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
2814 echo "TMPPIPE=${TMPPIPE}"
2815 local multiop_output
2817 read -t 60 multiop_output < $TMPPIPE
2818 if [ $? -ne 0 ]; then
2823 if [ "$multiop_output" != "PAUSING" ]; then
2824 echo "Incorrect multiop output: $multiop_output"
2839 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
2845 inodes_available () {
2846 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
2850 mdsrate_inodes_available () {
2851 echo $(($(inodes_available) - 1))
2854 # reset llite stat counters
2855 clear_llite_stats(){
2856 lctl set_param -n llite.*.stats 0
2859 # sum llite stat items
2860 calc_llite_stats() {
2861 local res=$(lctl get_param -n llite.*.stats |
2862 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
2867 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
2870 calc_osc_kbytes () {
2871 df $MOUNT > /dev/null
2872 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
2875 # save_lustre_params(node, parameter_mask)
2876 # generate a stream of formatted strings (<node> <param name>=<param value>)
2877 save_lustre_params() {
2879 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
2882 # restore lustre parameters from input stream, produces by save_lustre_params
2883 restore_lustre_params() {
2887 while IFS=" =" read node name val; do
2888 do_node ${node//:/} "lctl set_param -n $name $val"
2892 check_catastrophe() {
2893 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
2894 local C=$CATASTROPHE
2895 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
2897 if [ $rnodes ]; then
2898 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
2899 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
2915 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
2917 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
2918 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
2919 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
2923 mdsrate_cleanup () {
2924 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
2927 delayed_recovery_enabled () {
2928 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
2931 ################################################################################
2932 # The following functions are used to enable interop testing between
2933 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
2935 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
2936 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
2937 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
2938 ################################################################################
2940 get_lustre_version () {
2941 local node=${1:-"mds"}
2942 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
2945 get_mds_version_major () {
2946 local version=$(get_lustre_version mds)
2947 echo $version | awk -F. '{print $1}'
2950 get_mds_version_minor () {
2951 local version=$(get_lustre_version mds)
2952 echo $version | awk -F. '{print $2}'
2955 get_mds_version_patch () {
2956 local version=$(get_lustre_version mds)
2957 echo $version | awk -F. '{print $3}'
2960 get_mds_version_fix () {
2961 local version=$(get_lustre_version mds)
2962 echo $version | awk -F. '{print $4}'
2965 get_mds_fsstat_proc_path() {
2966 local major=$(get_mds_version_major)
2967 local minor=$(get_mds_version_minor)
2968 if [ $major -le 1 -a $minor -le 8 ] ; then
2975 get_mds_mntdev_proc_path() {
2976 local fsstat_dev=$(get_mds_fsstat_proc_path)
2977 echo "$fsstat_dev.*.mntdev"
2980 get_mdtlov_proc_path() {
2982 local major=$(get_mds_version_major)
2983 local minor=$(get_mds_version_minor)
2984 if [ $major -le 1 -a $minor -le 8 ] ; then
2985 echo "${fsname}-mdtlov"
2987 echo "${fsname}-MDT0000-mdtlov"
2991 get_mdtosc_proc_path() {
2993 local major=$(get_mds_version_major)
2994 local minor=$(get_mds_version_minor)
2995 if [ $major -le 1 -a $minor -le 8 ] ; then
2998 echo "${ost}-osc-MDT0000"
3002 get_mds_mdt_device_proc_path() {
3003 local major=$(get_mds_version_major)
3004 local minor=$(get_mds_version_minor)
3005 if [ $major -le 1 -a $minor -le 8 ] ; then
3013 local major=$(get_mds_version_major)
3014 local minor=$(get_mds_version_minor)
3015 if [ $major -le 1 -a $minor -le 8 ] ; then
3022 ########################
3024 convert_facet2label() {
3027 if [ x$facet = xost ]; then
3031 local varsvc=${facet}_svc
3033 if [ -n ${!varsvc} ]; then
3036 error "No lablel for $facet!"
3040 get_clientosc_proc_path() {
3046 get_osc_import_name() {
3049 local label=$(convert_facet2label $ost)
3051 if [ "$facet" == "mds" ]; then
3052 get_mdtosc_proc_path $label
3056 get_clientosc_proc_path $label
3060 wait_import_state () {
3066 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3067 while [ "${CONN_STATE}" != "${expected}" ]; do
3068 if [ "${expected}" == "DISCONN" ]; then
3069 # for disconn we can check after proc entry is removed
3070 [ "x${CONN_STATE}" == "x" ] && return 0
3071 # with AT we can have connect request timeout ~ reconnect timeout
3072 # and test can't see real disconnect
3073 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3075 # disconnect rpc should be wait not more obd_timeout
3076 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3077 error "can't put import for $CONN_PROC into ${expected} state" && return 1
3079 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3083 log "$CONN_PROC now in ${CONN_STATE} state"
3087 wait_osc_import_state() {
3091 local ost=$(get_osc_import_name $facet $ost_facet)
3096 CONN_PROC="osc.${ost}.ost_server_uuid"
3097 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3098 while [ "${CONN_STATE}" != "${expected}" ]; do
3099 if [ "${expected}" == "DISCONN" ]; then
3100 # for disconn we can check after proc entry is removed
3101 [ "x${CONN_STATE}" == "x" ] && return 0
3102 # with AT enabled, we can have connect request timeout near of
3103 # reconnect timeout and test can't see real disconnect
3104 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3106 # disconnect rpc should be wait not more obd_timeout
3107 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3108 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3110 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3114 log "${ost_facet} now in ${CONN_STATE} state"
3118 get_clientmdc_proc_path() {
3126 do_nodesv $list "PATH=$LUSTRE/tests/:$PATH sh rpc.sh $@ "
3129 wait_clients_import_state () {
3135 local label=$(convert_facet2label $facet)
3138 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3139 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3140 *) error "unknown facet!" ;;
3143 if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
3144 error "import is not in ${expected} state"
3149 destroy_pool_int() {
3151 local OSTS=$(do_facet mds lctl pool_list $1 | awk '$1 !~ /^Pool:/ {print $1}')
3152 for ost in $OSTS; do
3153 do_facet mgs lctl pool_remove $1 $ost
3155 do_facet mgs lctl pool_destroy $1
3158 # <fsname>.<poolname> or <poolname>
3160 local fsname=${1%%.*}
3161 local poolname=${1##$fsname.}
3163 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3167 pool_list $fsname.$poolname || return $?
3169 destroy_pool_int $fsname.$poolname
3171 [[ $RC -ne 0 ]] && return $RC
3173 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3174 2>/dev/null || echo foo" "foo" || RC=1
3176 if [[ $RC -eq 0 ]]; then
3177 remove_pool_from_list $fsname.$poolname
3179 error "destroy pool failed $1"
3185 local fsname=${1:-$FSNAME}
3187 local listvar=${fsname}_CREATED_POOLS
3191 [ x${!listvar} = x ] && return 0
3193 echo destroy the created pools: ${!listvar}
3194 for poolname in ${!listvar//,/ }; do
3195 destroy_pool $fsname.$poolname
3200 local fsname=${1:-$FSNAME}
3202 destroy_pools $fsname
3208 local ts=$(date +%s)
3210 # bug 20237, comment 11
3211 # It would also be useful to provide the option
3212 # of writing the file to an NFS directory so it doesn't need to be copied.
3215 [ -d "$SHARED_DIR_LOGS" ] && tmp=$SHARED_DIR_LOGS && docp=false
3217 # dump lustre logs, dmesg
3218 do_nodes $list "log=$tmp/\\\$(hostname)-debug-$ts.log ;
3219 lctl dk \\\$log >/dev/null;
3220 log=$tmp/\\\$(hostname)-dmesg-$ts.log;
3223 # FIXME: does it make sense to collect the logs for $ts only, but all
3225 # rsync $TMP/*${TESTSUITE}* to gather the logs dumped by error fn
3226 local logs=$TMP/'*'${TESTSUITE}'*'
3228 logs=$logs' '$tmp/'*'$ts'*'
3230 for node in ${list//,/ }; do
3231 rsync -az $node:"$logs" $TMP
3234 local archive=$TMP/${TESTSUITE}-$ts.tar.bz2
3235 tar -jcf $archive $tmp/*$ts* $TMP/*${TESTSUITE}*
3241 local list=${1:-$(comma_list $(nodes_list))}
3243 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3255 for i in $(seq 0 $num_mntpts); do
3256 cmd="ls -laf ${mntpt_root}$i/$dir"
3262 for pid in $pids; do
3269 # target_start_and_reset_recovery_timer()
3270 # service_time = at_est2timeout(service_time);
3271 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3272 # INITIAL_CONNECT_TIMEOUT);
3273 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3274 #define CONNECTION_SWITCH_INC 1
3275 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3276 #define CONNECTION_SWITCH_MIN 5U
3278 max_recovery_time () {
3279 local init_connect_timeout=$(( TIMEOUT / 20 ))
3280 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3282 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3287 remove_mdt_files() {
3292 local mntpt=${MOUNT%/*}/$facet
3294 echo "removing files from $mdtdev on $facet: $files"
3295 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
3298 rm $mntpt/ROOT/$f || { rc=$?; break; }
3300 umount -f $mntpt || return $?
3304 duplicate_mdt_files() {
3309 local mntpt=${MOUNT%/*}/$facet
3311 echo "duplicating files on $mdtdev on $facet: $files"
3312 mkdir -p $mntpt || return $?
3313 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
3323 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
3324 pushd $mntpt/ROOT > /dev/null || return $?
3327 touch $f.bad || return $?
3328 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
3330 [ $rc -eq 0 ] || return $rc
3331 setfattr --restore $tmp || return $?
3337 local devs=${1//,/ }
3340 local rslt=$TMP/sgpdd_survey
3342 # sgpdd-survey cleanups ${rslt}.* files
3344 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"