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}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
19 #export PDSH="pdsh -S -Rssh -w"
21 # function used by scripts run on remote nodes
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
23 . $LUSTRE/tests/functions.sh
27 [[ $DIR/ = $MOUNT/* ]] || \
28 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
29 [[ $DIR1/ = $MOUNT1/* ]] || \
30 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
31 [[ $DIR2/ = $MOUNT2/* ]] || \
32 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
34 [ -n "$failed" ] && exit 99 || true
38 echo "usage: $0 [-r] [-f cfgfile]"
46 [ "$TESTSUITE" == "lfscktest" ] && return 0
47 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
48 local form="%-13s %-17s %s\n"
49 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
50 echo "------------------------------------------------------------------------------------"
51 for O in $TESTSUITE_LIST; do
54 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
57 local log=${TMP}/${o}.log
58 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
59 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
60 [ "${!O}" = "done" ] && \
61 printf "$form" "Done" "$O" "E=$skipped" && \
62 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
66 for O in $TESTSUITE_LIST; do
67 if [ "${!O}" = "no" ]; then
69 # only for those tests suits which are run directly from acc-sm script:
70 # bonnie, iozone, etc.
71 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
72 printf "$form" "UNFINISHED" "$O" ""
74 printf "$form" "Skipped" "$O" ""
79 for O in $TESTSUITE_LIST; do
80 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
81 printf "$form" "UNFINISHED" "$O" ""
86 export LUSTRE=`absolute_path $LUSTRE`
87 export TESTSUITE=`basename $0 .sh`
88 export TEST_FAILED=false
89 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
91 export MKE2FS=${MKE2FS:-mke2fs}
92 export DEBUGFS=${DEBUGFS:-debugfs}
93 export TUNE2FS=${TUNE2FS:-tune2fs}
94 export E2LABEL=${E2LABEL:-e2label}
95 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
96 export E2FSCK=${E2FSCK:-e2fsck}
98 #[ -d /r ] && export ROOT=${ROOT:-/r}
99 export TMP=${TMP:-$ROOT/tmp}
100 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
101 export HOSTNAME=${HOSTNAME:-`hostname`}
102 if ! echo $PATH | grep -q $LUSTRE/utils; then
103 export PATH=$PATH:$LUSTRE/utils
105 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
106 export PATH=$PATH:$LUSTRE/utils/gss
108 if ! echo $PATH | grep -q $LUSTRE/tests; then
109 export PATH=$PATH:$LUSTRE/tests
111 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
112 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
113 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
114 export PATH=$PATH:$LUSTRE/tests/racer
116 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
117 export PATH=$PATH:$LUSTRE/tests/mpi
119 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
120 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
121 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
122 [ ! -f "$LFS" ] && export LFS=$(which lfs)
123 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
124 if [ ! -f "$L_GETIDENTITY" ]; then
125 if `which l_getidentity > /dev/null 2>&1`; then
126 export L_GETIDENTITY=$(which l_getidentity)
128 export L_GETIDENTITY=NONE
131 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
132 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
133 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
134 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
135 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
136 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
137 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
138 export FSTYPE=${FSTYPE:-"ldiskfs"}
139 export NAME=${NAME:-local}
140 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
141 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
142 export LGSSD=$(which lgssd)
143 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
144 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
145 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
147 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
150 if [ "$ACCEPTOR_PORT" ]; then
151 export PORT_OPT="--port $ACCEPTOR_PORT"
156 echo "Using GSS/krb5 ptlrpc security flavor"
157 which lgss_keyring > /dev/null 2>&1 || \
158 error "built with gss disabled! SEC=$SEC"
169 IDENTITY_UPCALL=false
172 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
174 # Paths on remote nodes, if different
175 export RLUSTRE=${RLUSTRE:-$LUSTRE}
176 export RPWD=${RPWD:-$PWD}
177 export I_MOUNTED=${I_MOUNTED:-"no"}
181 while getopts "rvwf:" opt $*; do
184 r) REFORMAT=--reformat;;
186 w) WRITECONF=writeconf;;
191 shift $((OPTIND - 1))
194 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
199 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
200 *) EXT=".ko"; USE_QUOTA=yes;;
207 BASE=`basename $module $EXT`
208 lsmod | grep -q ${BASE} || \
209 if [ -f ${LUSTRE}/${module}${EXT} ]; then
210 insmod ${LUSTRE}/${module}${EXT} $@
212 # must be testing a "make install" or "rpm" installation
213 # note failed to load ptlrpc_gss is considered not fatal
214 if [ "$BASE" == "ptlrpc_gss" ]; then
215 modprobe $BASE $@ 2>/dev/null || echo "gss/krb5 is not supported"
222 load_modules_local() {
223 if [ -n "$MODPROBE" ]; then
227 if [ "$HAVE_MODULES" = true ]; then
233 echo Loading modules from $LUSTRE
234 load_module ../libcfs/libcfs/libcfs
235 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
236 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
238 [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
239 [ ! "$MODPROBECONF" -a -d /etc/modprobe.d ] && MODPROBECONF=/etc/modprobe.d/Lustre
240 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
241 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
242 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
243 echo "lnet options: '$LNETOPTS'"
244 # note that insmod will ignore anything in modprobe.conf
245 load_module ../lnet/lnet/lnet $LNETOPTS
246 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
247 load_module ../lnet/klnds/$LNETLND
248 load_module lvfs/lvfs
249 load_module obdclass/obdclass
250 load_module ptlrpc/ptlrpc
251 load_module ptlrpc/gss/ptlrpc_gss
252 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota
260 if [ -z "$CLIENTONLY" ] && [ -z "$CLIENTMODSONLY" ]; then
261 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
262 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
263 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
268 load_module lvfs/fsfilt_$FSTYPE
272 load_module obdfilter/obdfilter
275 load_module llite/lustre
276 load_module llite/llite_lloop
277 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
279 rm -f $OGDB/ogdb-$HOSTNAME
280 $LCTL modules > $OGDB/ogdb-$HOSTNAME
282 # 'mount' doesn't look in $PATH, just sbin
283 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
289 # load modules on remote nodes optionally
290 # lustre-tests have to be installed on these nodes
291 if $LOAD_MODULES_REMOTE ; then
292 local list=$(comma_list $(remote_nodes_list))
293 echo loading modules on $list
294 do_rpc_nodes $list load_modules
299 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
300 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
301 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
302 echo "$LEAK_LUSTRE" 1>&2
303 echo "$LEAK_PORTALS" 1>&2
304 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
305 echo "Memory leaks detected"
306 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
312 wait_exit_ST client # bug 12845
314 $LUSTRE_RMMOD $FSTYPE || return 2
316 if $LOAD_MODULES_REMOTE ; then
317 local list=$(comma_list $(remote_nodes_list))
318 echo unloading modules on $list
319 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
320 do_rpc_nodes $list check_mem_leak
325 check_mem_leak || return 254
327 echo "modules unloaded."
331 check_gss_daemon_facet() {
335 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
336 if [ $num -ne 1 ]; then
337 echo "$num instance of $dname on $facet"
346 do_facet $facet "killall -2 $@ 2>/dev/null || true"
349 start_gss_daemons() {
351 for num in `seq $MDSCOUNT`; do
352 do_facet mds$num "$LSVCGSSD -v"
354 do_facet mds$num "$LGSSD -v"
358 for num in `seq $OSTCOUNT`; do
359 do_facet ost$num "$LSVCGSSD -v"
362 # FIXME: is "client" the right facet name?
364 do_facet client "$LGSSD -v"
367 # wait daemons entering "stable" status
371 # check daemons are running
373 for num in `seq $MDSCOUNT`; do
374 check_gss_daemon_facet mds$num lsvcgssd
376 check_gss_daemon_facet mds$num lgssd
379 for num in `seq $OSTCOUNT`; do
380 check_gss_daemon_facet ost$num lsvcgssd
383 check_gss_daemon_facet client lgssd
388 for num in `seq $MDSCOUNT`; do
389 send_sigint mds$num lsvcgssd lgssd
391 for num in `seq $OSTCOUNT`; do
392 send_sigint ost$num lsvcgssd
394 send_sigint client lgssd
401 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
402 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
410 # maybe cleanup credential cache?
416 local device=`mdsdevname $num`
417 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
423 local device=`ostdevname $num`
424 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
432 local dev=$(facet_active $facet)_dev
433 local opt=${facet}_opt
434 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
435 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
437 if [ $RC -ne 0 ]; then
438 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
439 echo "Start of ${!dev} on ${facet} failed ${RC}"
441 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
442 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
443 lctl set_param debug_mb=${DEBUG_SIZE}; \
446 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
447 [ -z "$label" ] && echo no label for ${!dev} && exit 1
448 eval export ${facet}_svc=${label}
449 echo Started ${label}
454 # start facet device options
460 eval export ${facet}_dev=${device}
461 eval export ${facet}_opt=\"$@\"
463 local varname=${facet}failover_dev
464 if [ -n "${!varname}" ] ; then
465 eval export ${facet}failover_dev=${!varname}
467 eval export ${facet}failover_dev=$device
470 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
480 HOST=`facet_active_host $facet`
481 [ -z $HOST ] && echo stop: no host for $facet && return 0
483 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
484 if [ ${running} -ne 0 ]; then
485 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
486 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
489 # umount should block, but we should wait for unrelated obd's
490 # like the MGS or MGC to also stop.
491 wait_exit_ST ${facet}
494 # save quota version (both administrative and operational quotas)
495 # add an additional parameter if mountpoint is ever different from $MOUNT
496 quota_save_version() {
497 local fsname=${2:-$FSNAME}
499 local ver=$(tr -c -d "123" <<< $spec)
500 local type=$(tr -c -d "ug" <<< $spec)
502 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
504 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
506 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
508 local osts=$(get_facets OST)
509 for ost in ${osts//,/ }; do
511 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
515 # client could mount several lustre
517 local fsname=${1:-$FSNAME}
519 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
520 do_nodes $(comma_list $(osts_nodes)) \
521 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
525 restore_quota_type () {
526 local mntpt=${1:-$MOUNT}
527 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
528 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
531 quota_save_version $old_QUOTA_TYPE
538 # 1. run quotacheck only if quota is off
539 # 2. save the original quota_type params, restore them after testing
541 # Suppose that quota type the same on mds and ost
542 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
543 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
544 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
545 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
546 export old_QUOTA_TYPE=$quota_type
547 quota_save_version $QUOTA_TYPE
550 local quota_usrs=$QUOTA_USERS
552 # get_filesystem_size
553 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
554 local blk_soft=$((disksz + 1024))
555 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
557 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
559 local i_hard=$((i_soft + i_soft / 20))
561 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
562 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
565 for usr in $quota_usrs; do
566 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
568 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
570 eval $cmd || error "$cmd FAILED!"
572 # display the quota status
573 echo "Quota settings for $usr : "
574 $LFS quota -v -u $usr $mntpt || true
582 # Only supply -o to mount if we have options
583 if [ -n "$MOUNTOPT" ]; then
584 OPTIONS="-o $MOUNTOPT"
586 local device=$MGSNID:/$FSNAME
587 if [ -z "$mnt" -o -z "$FSNAME" ]; then
588 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
592 echo "Starting client: $client: $OPTIONS $device $mnt"
593 do_node $client mkdir -p $mnt
594 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
596 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
597 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
598 lctl set_param debug_mb=${DEBUG_SIZE}"
611 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
612 if [ $running -ne 0 ]; then
613 echo "Stopping client $client $mnt (opts:$force)"
614 do_node $client lsof -t $mnt || need_kill=no
615 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
616 pids=$(do_node $client lsof -t $mnt | sort -u);
617 if [ -n $pids ]; then
618 do_node $client kill -9 $pids || true
622 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
623 if [ $busy -ne 0 ] ; then
624 echo "$mnt is still busy, wait one second" && sleep 1
625 do_node $client umount $force $mnt
630 # nodes is comma list
631 sanity_mount_check_nodes () {
637 # FIXME: assume that all cluster nodes run the same os
638 [ "$(uname)" = Linux ] || return 0
641 for mnt in $mnts ; do
642 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
643 mpts=\\\$(mount | grep -w -c $mnt);
644 if [ \\\$running -ne \\\$mpts ]; then
645 echo \\\$(hostname) env are INSANE!;
653 sanity_mount_check_servers () {
655 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
656 echo Checking servers environments
658 # FIXME: modify get_facets to display all facets wo params
659 local facets="$(get_facets OST),$(get_facets MDS),mgs"
663 for facet in ${facets//,/ }; do
664 node=$(facet_host ${facet})
665 mnt=${MOUNT%/*}/${facet}
666 sanity_mount_check_nodes $node $mnt ||
667 { error "server $node environments are insane!"; return 1; }
671 sanity_mount_check_clients () {
672 local clients=${1:-$CLIENTS}
673 local mntpt=${2:-$MOUNT}
674 local mntpt2=${3:-$MOUNT2}
676 [ -z $clients ] && clients=$(hostname)
677 echo Checking clients $clients environments
679 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
680 error "clients environments are insane!"
683 sanity_mount_check () {
684 sanity_mount_check_servers || return 1
685 sanity_mount_check_clients || return 2
688 # mount clients if not mouted
689 zconf_mount_clients() {
695 # Only supply -o to mount if we have options
696 if [ -n "$MOUNTOPT" ]; then
697 OPTIONS="-o $MOUNTOPT"
699 local device=$MGSNID:/$FSNAME
700 if [ -z "$mnt" -o -z "$FSNAME" ]; then
701 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
705 echo "Starting client $clients: $OPTIONS $device $mnt"
708 running=\\\$(mount | grep -c $mnt' ');
710 if [ \\\$running -eq 0 ] ; then
712 mount -t lustre $OPTIONS $device $mnt;
715 exit \\\$rc" || return ${PIPESTATUS[0]}
717 echo "Started clients $clients: "
718 do_nodes $clients "mount | grep -w $mnt"
720 do_nodes $clients "lctl set_param debug=\\\"$PTLDEBUG\\\";
721 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
722 lctl set_param debug_mb=${DEBUG_SIZE};"
727 zconf_umount_clients() {
734 echo "Stopping clients: $clients $mnt (opts:$force)"
735 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
736 if [ \\\$running -ne 0 ] ; then
737 echo Stopping client \\\$(hostname) client $mnt opts:$force;
738 lsof -t $mnt || need_kill=no;
739 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
740 pids=\\\$(lsof -t $mnt | sort -u);
741 if [ -n \\\"\\\$pids\\\" ]; then
745 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
746 if [ \\\$busy -ne 0 ] ; then
747 echo "$mnt is still busy, wait one second" && sleep 1;
753 shudown_node_hard () {
757 for i in $(seq $attempts) ; do
760 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
761 echo "waiting for $host to fail attempts=$attempts"
762 [ $i -lt $attempts ] || \
763 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
769 local mnt=${2:-$MOUNT}
772 if [ "$FAILURE_MODE" = HARD ]; then
773 shudown_node_hard $client
775 zconf_umount_clients $client $mnt -f
781 if [ "$FAILURE_MODE" = HARD ]; then
782 shudown_node_hard $(facet_active_host $facet)
783 elif [ "$FAILURE_MODE" = SOFT ]; then
790 if [ "$FAILURE_MODE" = HARD ]; then
791 $POWER_UP `facet_active_host $facet`
799 if [ "$FAILURE_MODE" = HARD ]; then
805 # recovery-scale functions
806 check_progs_installed () {
811 do_nodes $clients "PATH=:$PATH; status=true;
812 for prog in $progs; do
813 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
814 echo \\\$prog missing on \\\$(hostname);
822 echo __$(echo $1 | tr '-' 'X')
825 start_client_load() {
828 local var=$(client_var_name $client)_load
829 eval export ${var}=$load
831 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
832 BREAK_ON_ERROR=$BREAK_ON_ERROR \
833 END_RUN_FILE=$END_RUN_FILE \
834 LOAD_PID_FILE=$LOAD_PID_FILE \
835 TESTSUITELOG=$TESTSUITELOG \
837 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
838 log "Started client load: ${load} on $client"
843 start_client_loads () {
844 local -a clients=(${1//,/ })
845 local numloads=${#CLIENT_LOADS[@]}
848 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
849 testnum=$((nodenum % numloads))
850 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
854 # only for remote client
855 check_client_load () {
857 local var=$(client_var_name $client)_load
858 local TESTLOAD=run_${!var}.sh
860 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
862 # bug 18914: try to connect several times not only when
863 # check ps, but while check_catastrophe also
866 while [ $RC = 254 -a $tries -gt 0 ]; do
870 if ! check_catastrophe $client; then
872 if [ $RC -eq 254 ]; then
873 # FIXME: not sure how long we shuold sleep here
877 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 [ "`/sbin/lsmod 2>&1 | egrep 'lnet|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 () {
999 wait_update $(facet_active_host $facet) "$@"
1002 wait_delete_completed () {
1003 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1004 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1008 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1010 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1011 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1012 [ "$TOTAL" -eq "$TOTALPREV" ] && break
1013 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1017 echo "Delete completed."
1022 check_network "$host" 900
1023 while ! do_node $host hostname > /dev/null; do sleep 5; done
1028 local host=`facet_active_host $facet`
1032 wait_recovery_complete () {
1035 # Use default policy if $2 is not passed by caller.
1036 #define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
1037 # as we are in process of changing obd_timeout in different ways
1038 # let's set MAX longer than that
1039 local MAX=${2:-$(( TIMEOUT * 4 ))}
1041 local var_svc=${facet}_svc
1042 local procfile="*.${!var_svc}.recovery_status"
1046 while [ $WAIT -lt $MAX ]; do
1047 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
1048 [[ $STATUS = "status: COMPLETE" ]] && return 0
1051 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
1053 echo "$facet recovery not done in $MAX sec. $STATUS"
1063 # conf-sanity 31 takes a long time cleanup
1064 while [ $WAIT -lt 300 ]; do
1065 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1066 [ -z "${running}" ] && return 0
1067 echo "waited $WAIT for${running}"
1068 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1070 WAIT=$((WAIT + INTERVAL))
1072 echo "service didn't stop after $WAIT seconds. Still running:"
1077 wait_remote_prog () {
1083 [ "$PDSH" = "no_dsh" ] && return 0
1085 while [ $WAIT -lt $2 ]; do
1086 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1087 [ -z "${running}" ] && return 0 || true
1088 echo "waited $WAIT for: "
1090 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1092 WAIT=$((WAIT + INTERVAL))
1094 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1095 [ -z "$pids" ] && return 0
1096 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1097 # FIXME: not portable
1098 for pid in $pids; do
1099 cat /proc/${pid}/status || true
1100 cat /proc/${pid}/wchan || true
1102 kill -9 $pid || true
1111 # not every config has many clients
1112 if [ ! -z "$CLIENTS" ]; then
1113 $PDSH $CLIENTS "df $MOUNT" > /dev/null
1115 df $MOUNT > /dev/null
1119 client_reconnect() {
1120 uname -n >> $MOUNT/recon
1121 if [ -z "$CLIENTS" ]; then
1122 df $MOUNT; uname -n >> $MOUNT/recon
1124 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1126 echo Connected clients:
1128 ls -l $MOUNT/recon > /dev/null
1135 echo "Failing $facet on node `facet_active_host $facet`"
1136 shutdown_facet $facet
1137 [ -n "$sleep_time" ] && sleep $sleep_time
1139 change_active $facet
1140 local TO=`facet_active_host $facet`
1141 echo "Failover $facet to $TO"
1143 mount_facet $facet || error "Restart of $facet failed"
1152 do_facet $facet sync
1154 local svc=${facet}_svc
1155 do_facet $facet $LCTL --device %${!svc} notransno
1156 do_facet $facet $LCTL --device %${!svc} readonly
1157 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1158 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1161 replay_barrier_nodf() {
1162 local facet=$1 echo running=${running}
1163 do_facet $facet sync
1164 local svc=${facet}_svc
1165 echo Replay barrier on ${!svc}
1166 do_facet $facet $LCTL --device %${!svc} notransno
1167 do_facet $facet $LCTL --device %${!svc} readonly
1168 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1169 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1172 replay_barrier_nosync() {
1173 local facet=$1 echo running=${running}
1174 local svc=${facet}_svc
1175 echo Replay barrier on ${!svc}
1176 do_facet $facet $LCTL --device %${!svc} notransno
1177 do_facet $facet $LCTL --device %${!svc} readonly
1178 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1179 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1182 mds_evict_client() {
1183 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1184 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1187 ost_evict_client() {
1188 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1189 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1193 facet_failover $* || error "failover: $?"
1194 client_df || error "post-failover df: $?"
1199 facet_failover $facet
1205 change_active $facet
1206 mount_facet $facet -o abort_recovery
1207 client_df || echo "first df failed: $?"
1209 client_df || error "post-failover df: $?"
1213 echo There is no lmc. This is mountconf, baby.
1218 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1219 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1225 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1231 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1232 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1233 if [ -z "$ID" ]; then
1234 echo "Could not get a ptl id for $1..."
1243 h2name_or_ip "$1" "tcp"
1248 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1249 if type __h2elan >/dev/null 2>&1; then
1252 ID=`echo $1 | sed 's/[^0-9]*//g'`
1260 h2name_or_ip "$1" "openib"
1262 declare -fx h2openib
1265 h2name_or_ip "$1" "o2ib"
1272 [ "$facet" == client ] && echo -n $HOSTNAME && return
1273 varname=${facet}_HOST
1274 if [ -z "${!varname}" ]; then
1275 if [ "${facet:0:3}" == "ost" ]; then
1276 eval ${facet}_HOST=${ost_HOST}
1284 local activevar=${facet}active
1286 if [ -f $TMP/${facet}active ] ; then
1287 source $TMP/${facet}active
1290 active=${!activevar}
1291 if [ -z "$active" ] ; then
1298 facet_active_host() {
1300 local active=`facet_active $facet`
1301 if [ "$facet" == client ]; then
1304 echo `facet_host $active`
1310 local failover=${facet}failover
1311 host=`facet_host $failover`
1312 [ -z "$host" ] && return
1313 local curactive=`facet_active $facet`
1314 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1315 eval export ${facet}active=$facet
1317 eval export ${facet}active=$failover
1319 # save the active host for this facet
1320 local activevar=${facet}active
1321 echo "$activevar=${!activevar}" > $TMP/$activevar
1326 # do not stripe off hostname if verbose, bug 19215
1327 if [ x$1 = x--verbose ]; then
1335 if [ "$HOST" = "$HOSTNAME" ]; then
1337 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1338 echo "cannot run remote command on $HOST with $myPDSH"
1342 echo "CMD: $HOST $@" >&2
1343 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1346 if [ "$myPDSH" = "rsh" ]; then
1347 # we need this because rsh does not return exit code of an executed command
1348 local command_status="$TMP/cs"
1349 rsh $HOST ":> $command_status"
1350 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1351 cd $RPWD; sh -c \"$@\") ||
1352 echo command failed >$command_status"
1353 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1358 # print HOSTNAME for myPDSH="no_dsh"
1359 if [[ $myPDSH = no_dsh ]]; then
1360 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1362 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1365 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1367 return ${PIPESTATUS[0]}
1370 single_local_node () {
1371 [ "$1" = "$HOSTNAME" ]
1376 # do not stripe off hostname if verbose, bug 19215
1377 if [ x$1 = x--verbose ]; then
1385 if $(single_local_node $rnodes); then
1387 do_node --verbose $rnodes $@
1394 # This is part from do_node
1397 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1398 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1401 echo "CMD: $rnodes $@" >&2
1402 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1406 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1408 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/\w+:\s//g"
1410 return ${PIPESTATUS[0]}
1416 local HOST=`facet_active_host $facet`
1417 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1424 # make sure its not already running
1426 rm -f $TMP/${facet}active
1427 do_facet ${facet} $MKFS $*
1433 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1434 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1441 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1442 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1450 # make sure we are using the primary server, so test-framework will
1451 # be able to clean up properly.
1452 activemds=`facet_active mds1`
1453 if [ $activemds != "mds1" ]; then
1457 local clients=$CLIENTS
1458 [ -z $clients ] && clients=$(hostname)
1460 zconf_umount_clients $clients $MOUNT "$*" || true
1461 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1463 [ "$CLIENTONLY" ] && return
1464 # The add fn does rm ${facet}active file, this would be enough
1465 # if we use do_facet <facet> only after the facet added, but
1466 # currently we use do_facet mds in local.sh
1467 for num in `seq $MDSCOUNT`; do
1469 rm -f ${TMP}/mds${num}active
1472 for num in `seq $OSTCOUNT`; do
1474 rm -f $TMP/ost${num}active
1481 nfs_client_mode && return
1491 test $nr = 1 && echo -n $MDS_MKFS_OPTS || echo -n $MDSn_MKFS_OPTS
1495 if [ "$IAMDIR" == "yes" ]; then
1496 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
1497 MDSn_MKFS_OPTS="$MDSn_MKFS_OPTS --iam-dir"
1500 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1502 if [ ! -z $SEC ]; then
1503 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --param srpc.flavor.default=$SEC"
1504 MDSn_MKFS_OPTS="$MDSn_MKFS_OPTS --param srpc.flavor.default=$SEC"
1505 OST_MKFS_OPTS="$OST_MKFS_OPTS --param srpc.flavor.default=$SEC"
1509 # We need ldiskfs here, may as well load them all
1511 [ "$CLIENTONLY" ] && return
1512 echo Formatting mgs, mds, osts
1513 if [[ $MDSDEV1 != $MGSDEV ]] || [[ $mds1_HOST != $mgs_HOST ]]; then
1514 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1517 for num in `seq $MDSCOUNT`; do
1518 echo "Format mds$num: $(mdsdevname $num)"
1520 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` || exit 9
1522 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` > /dev/null || exit 9
1526 for num in `seq $OSTCOUNT`; do
1527 echo "Format ost$num: $(ostdevname $num)"
1529 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` || exit 10
1531 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` > /dev/null || exit 10
1537 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1541 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
1545 # 0: success, the old identity set already.
1546 # 1: success, the old identity does not set.
1551 local j=`expr $num - 1`
1552 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
1554 if [ -z "$MDT" ]; then
1558 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
1561 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
1563 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
1566 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush \"-1\""
1568 if [ $old = "NONE" ]; then
1577 zconf_umount `hostname` $1 || error "umount failed"
1578 zconf_mount `hostname` $1 || error "mount failed"
1581 writeconf_facet () {
1585 do_facet $facet "$TUNEFS --writeconf $dev"
1589 for num in `seq $MDSCOUNT`; do
1590 DEVNAME=$(mdsdevname $num)
1591 writeconf_facet mds$num $DEVNAME
1594 for num in `seq $OSTCOUNT`; do
1595 DEVNAME=$(ostdevname $num)
1596 writeconf_facet ost$num $DEVNAME
1601 nfs_client_mode && return
1603 sanity_mount_check ||
1604 error "environments are insane!"
1608 if [ -z "$CLIENTONLY" ]; then
1609 echo Setup mgs, mdt, osts
1610 echo $WRITECONF | grep -q "writeconf" && \
1612 if [[ $mds1_HOST != $mgs_HOST ]] || [[ $MDSDEV1 != $MGSDEV ]]; then
1613 start mgs $MGSDEV $mgs_MOUNT_OPTS
1616 for num in `seq $MDSCOUNT`; do
1617 DEVNAME=$(mdsdevname $num)
1618 start mds$num $DEVNAME $MDS_MOUNT_OPTS
1620 # We started mds, now we should set failover variables properly.
1621 # Set mds${num}failover_HOST if it is not set (the default failnode).
1622 local varname=mds${num}failover_HOST
1623 if [ -z "${!varname}" ]; then
1624 eval mds${num}failover_HOST=$(facet_host mds$num)
1627 if [ $IDENTITY_UPCALL != "default" ]; then
1628 switch_identity $num $IDENTITY_UPCALL
1631 for num in `seq $OSTCOUNT`; do
1632 DEVNAME=$(ostdevname $num)
1633 start ost$num $DEVNAME $OST_MOUNT_OPTS
1635 # We started ost$num, now we should set ost${num}failover variable properly.
1636 # Set ost${num}failover_HOST if it is not set (the default failnode).
1637 varname=ost${num}failover_HOST
1638 if [ -z "${!varname}" ]; then
1639 eval ost${num}failover_HOST=$(facet_host ost${num})
1644 # wait a while to allow sptlrpc configuration be propogated to targets,
1645 # only needed when mounting new target devices.
1648 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1650 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1652 if [ "$MOUNT_2" ]; then
1653 mount_client $MOUNT2
1654 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1659 # by remounting mdt before ost, initial connect from mdt to ost might
1660 # timeout because ost is not ready yet. wait some time to its fully
1661 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
1662 # by a context negotiation rpc with $TIMEOUT.
1663 # FIXME better by monitoring import status.
1665 sleep $((TIMEOUT + 5))
1671 mounted_lustre_filesystems() {
1672 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1675 init_facet_vars () {
1676 [ "$CLIENTONLY" ] && return 0
1683 eval export ${facet}_dev=${device}
1684 eval export ${facet}_opt=\"$@\"
1686 local dev=${facet}_dev
1687 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1688 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1690 eval export ${facet}_svc=${label}
1692 local varname=${facet}failover_HOST
1693 if [ -z "${!varname}" ]; then
1694 eval $varname=$(facet_host $facet)
1697 # ${facet}failover_dev is set in cfg file
1698 varname=${facet}failover_dev
1699 if [ -n "${!varname}" ] ; then
1700 eval export ${facet}failover_dev=${!varname}
1702 eval export ${facet}failover_dev=$device
1706 init_facets_vars () {
1709 if ! remote_mds_nodsh; then
1710 for num in `seq $MDSCOUNT`; do
1711 DEVNAME=`mdsdevname $num`
1712 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
1716 remote_ost_nodsh && return
1718 for num in `seq $OSTCOUNT`; do
1719 DEVNAME=`ostdevname $num`
1720 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1724 osc_ensure_active () {
1730 while [ $period -lt $timeout ]; do
1731 count=$(do_facet $facet "lctl dl | grep '${FSNAME}-OST.*-osc-${type}' | grep ' IN ' 2>/dev/null | wc -l")
1732 if [ $count -eq 0 ]; then
1736 echo "There are $count OST are inactive, wait $period seconds, and try again"
1738 period=$((period+3))
1741 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
1745 SOM_ENABLED=$(do_facet $SINGLEMDS "$LCTL get_param mdt.*.som" | awk -F= ' {print $2}' | head -n 1)
1749 init_param_vars () {
1750 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1751 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
1752 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1753 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1757 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
1759 log "Using TIMEOUT=$TIMEOUT"
1761 osc_ensure_active $SINGLEMDS M $TIMEOUT
1762 osc_ensure_active client c $TIMEOUT
1764 if [ x"$(som_check)" = x"enabled" ]; then
1767 if [ "$ENABLE_QUOTA" ]; then
1768 setup_quota $MOUNT || return 2
1772 nfs_client_mode () {
1773 if [ "$NFSCLIENT" ]; then
1774 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1775 local clients=$CLIENTS
1776 [ -z $clients ] && clients=$(hostname)
1778 # FIXME: remove hostname when 19215 fixed
1779 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1780 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1781 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1788 nfs_client_mode && return
1792 local mounted=$(mount | grep " $mntpt ")
1793 if [ "$CLIENTONLY" ]; then
1795 # CLIENTONLY should not depend on *_HOST settings
1796 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
1797 # in theory someone could create a new,
1798 # client-only config file that assumed lustre was already
1799 # configured and didn't set the MGSNID. If MGSNID is not set,
1800 # then we should use the mgs nid currently being used
1801 # as the default value. bug 18021
1802 [[ x$MGSNID = x ]] &&
1805 if [[ x$mgc != xMGC$MGSNID ]]; then
1806 if [ "$mgs_HOST" ]; then
1807 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
1808 [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
1809 error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
1815 local myMGS_host=$mgs_HOST
1816 if [ "$NETTYPE" = "ptl" ]; then
1817 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
1820 echo Checking config lustre mounted on $mntpt
1821 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
1822 mgshost=$(echo $mgshost | awk -F: '{print $1}')
1824 # if [ "$mgshost" != "$myMGS_host" ]; then
1825 # error_exit "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
1826 # Please use correct config or set mds_HOST correctly!"
1829 sanity_mount_check ||
1830 error "environments are insane!"
1834 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
1835 local cltimeout=$(lctl get_param -n timeout)
1836 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
1837 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
1842 check_and_setup_lustre() {
1843 nfs_client_mode && return
1845 local MOUNTED=$(mounted_lustre_filesystems)
1846 if [ -z "$MOUNTED" ] || ! $(echo $MOUNTED | grep -w -q $MOUNT); then
1847 [ "$REFORMAT" ] && formatall
1849 MOUNTED=$(mounted_lustre_filesystems | head -1)
1850 [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
1851 export I_MOUNTED=yes
1857 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
1858 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
1859 lctl set_param debug_mb=${DEBUG_SIZE};
1862 if [ "$ONLY" == "setup" ]; then
1867 cleanup_and_setup_lustre() {
1868 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
1869 lctl set_param debug=0 || true
1871 if [ "$ONLY" == "cleanup" ]; then
1875 check_and_setup_lustre
1878 check_and_cleanup_lustre() {
1879 if [ "`mount | grep $MOUNT`" ]; then
1880 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
1881 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
1883 if [ "$I_MOUNTED" = "yes" ]; then
1884 cleanupall -f || error "cleanup failed"
1896 while [ $NETWORK -eq 0 ]; do
1897 if ping -c 1 -w 3 $1 > /dev/null; then
1901 echo "waiting for $1, $((MAX - WAIT)) secs left"
1904 if [ $WAIT -gt $MAX ]; then
1905 echo "Network not available"
1911 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
1922 # the sed converts spaces to commas, but leaves the last space
1923 # alone, so the line doesn't end with a comma.
1924 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
1927 # list, excluded are the comma separated lists
1928 exclude_items_from_list () {
1934 for item in ${excluded//,/ }; do
1935 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
1937 echo $(comma_list $list)
1940 # list, expand are the comma separated lists
1942 local list=${1//,/ }
1943 local expand=${2//,/ }
1946 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
1947 echo $(comma_list $expanded)
1950 testslist_filter () {
1951 local script=$LUSTRE/tests/${TESTSUITE}.sh
1953 [ -f $script ] || return 0
1955 local start_at=$START_AT
1956 local stop_at=$STOP_AT
1958 local var=${TESTSUITE}_START_AT
1959 [ x"${!var}" != x ] && start_at=${!var}
1960 var=${TESTSUITE}_STOP_AT
1961 [ x"${!var}" != x ] && stop_at=${!var}
1963 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
1964 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
1965 /^'${start_at}'$/ {flag = 0}
1966 {if (flag == 1) print $0}
1967 /^'${stop_at}'$/ { flag = 1 }'
1971 (cd `dirname $1`; echo $PWD/`basename $1`)
1975 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
1976 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
1979 local count=${type}COUNT
1980 for ((i=1; i<=${!count}; i++)) do
1981 list="$list ${name}$i"
1983 echo $(comma_list $list)
1986 ##################################
1987 # Adaptive Timeouts funcs
1990 # only check mds, we assume at_max is the same on all nodes
1991 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
1992 if [ $at_max -eq 0 ]; then
2002 # suppose that all ost-s has the same at_max set
2003 if [ $facet == "ost" ]; then
2004 do_facet ost1 "lctl get_param -n at_max"
2006 do_facet $facet "lctl get_param -n at_max"
2016 if [ $facet == "ost" ]; then
2017 for i in `seq $OSTCOUNT`; do
2018 do_facet ost$i "lctl set_param at_max=$at_max"
2021 elif [ $facet == "mds" ]; then
2022 for i in `seq $MDSCOUNT`; do
2023 do_facet mds$i "lctl set_param at_max=$at_max"
2026 do_facet $facet "lctl set_param at_max=$at_max"
2031 ##################################
2035 # OBD_FAIL_MDS_ALL_REQUEST_NET
2037 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2038 do_facet client "$1" || RC=$?
2039 do_facet $SINGLEMDS lctl set_param fail_loc=0
2044 # OBD_FAIL_MDS_ALL_REPLY_NET
2046 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2047 do_facet client "$@" || RC=$?
2048 do_facet $SINGLEMDS lctl set_param fail_loc=0
2052 drop_reint_reply() {
2053 # OBD_FAIL_MDS_REINT_NET_REP
2055 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2056 do_facet client "$@" || RC=$?
2057 do_facet $SINGLEMDS lctl set_param fail_loc=0
2062 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2064 do_facet ost1 lctl set_param fail_loc=0x214
2065 do_facet client "$1" || RC=$?
2066 do_facet client "sync"
2067 do_facet ost1 lctl set_param fail_loc=0
2071 drop_ldlm_cancel() {
2072 #define OBD_FAIL_LDLM_CANCEL 0x304
2074 do_facet client lctl set_param fail_loc=0x304
2075 do_facet client "$@" || RC=$?
2076 do_facet client lctl set_param fail_loc=0
2080 drop_bl_callback() {
2081 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2083 do_facet client lctl set_param fail_loc=0x305
2084 do_facet client "$@" || RC=$?
2085 do_facet client lctl set_param fail_loc=0
2090 #define OBD_FAIL_LDLM_REPLY 0x30c
2092 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2093 do_facet client "$@" || RC=$?
2094 do_facet $SINGLEMDS lctl set_param fail_loc=0
2102 echo "clearing fail_loc on $facet"
2103 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2106 set_nodes_failloc () {
2107 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2110 cancel_lru_locks() {
2111 $LCTL mark "cancel_lru_locks $1 start"
2112 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2113 $LCTL set_param -n $d=clear
2115 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2116 $LCTL mark "cancel_lru_locks $1 stop"
2121 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2122 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2123 echo "$DEFAULT_LRU_SIZE"
2128 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2131 lru_resize_disable()
2133 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2138 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2139 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2140 echo there is still data in page cache $FILE ?
2141 lctl get_param -n $FILE
2145 if [[ $MDSDEV1 != $MGSDEV ]]; then
2153 DEBUGSAVE="$(lctl get_param -n debug)"
2157 [ -n "$DEBUGSAVE" ] && \
2158 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
2163 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
2166 debug_size_restore() {
2167 [ -n "$DEBUG_SIZE_SAVED" ] && \
2168 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
2172 start_full_debug_logging() {
2177 local DEBUG_SIZE=150
2179 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
2180 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
2183 stop_full_debug_logging() {
2188 ##################################
2190 ##################################
2193 local TYPE=${TYPE:-"FAIL"}
2195 lctl set_param fail_loc=0 2>/dev/null || true
2198 # do not dump logs if $1=false
2199 if [ "x$1" = "xfalse" ]; then
2204 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2207 ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
2208 echo "Dumping lctl log to $ERRLOG"
2209 # We need to dump the logs on all nodes
2210 do_nodes $(comma_list $(nodes_list)) $NODE $LCTL dk $ERRLOG
2213 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2219 $FAIL_ON_ERROR && exit 1 || true
2227 # use only if we are ignoring failures for this test, bugno required.
2228 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2229 # e.g. error_ignore 5494 "your message"
2231 local TYPE="IGNORE (bz$1)"
2237 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2242 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2243 [ "$TESTSUITELOG" ] && \
2244 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2247 build_test_filter() {
2248 EXCEPT="$EXCEPT $(testslist_filter)"
2250 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2254 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2255 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2256 [ "$EXCEPT_SLOW" ] && \
2257 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2258 for E in $EXCEPT $ALWAYS_EXCEPT; do
2259 eval EXCEPT_${E}=true
2261 for E in $EXCEPT_SLOW; do
2262 eval EXCEPT_SLOW_${E}=true
2264 for G in $GRANT_CHECK_LIST; do
2265 eval GCHECK_ONLY_${G}=true
2273 # print a newline if the last test was skipped
2274 export LAST_SKIPPED=
2278 export base=`basetest $1`
2279 if [ ! -z "$ONLY" ]; then
2281 if [ ${!testname}x != x ]; then
2282 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2287 if [ ${!testname}x != x ]; then
2288 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2297 if [ ${!testname}x != x ]; then
2299 TESTNAME=test_$1 skip "skipping excluded test $1"
2302 testname=EXCEPT_$base
2303 if [ ${!testname}x != x ]; then
2305 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2308 testname=EXCEPT_SLOW_$1
2309 if [ ${!testname}x != x ]; then
2311 TESTNAME=test_$1 skip "skipping SLOW test $1"
2314 testname=EXCEPT_SLOW_$base
2315 if [ ${!testname}x != x ]; then
2317 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2327 EQUALS="======================================================================"
2331 local suffixlen=$((${#EQUALS} - ${#msg}))
2332 [ $suffixlen -lt 5 ] && suffixlen=5
2333 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
2338 lsmod | grep lnet > /dev/null || load_modules
2350 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2355 strace -o $TMP/$1.strace -ttt $*
2357 log "FINISHED: $*: rc $RC"
2362 $TEST_FAILED && echo -n "FAIL " || echo -n "PASS "
2367 FFREE=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filesfree | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2368 FTOTAL=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filestotal | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2369 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2373 echo -n "Resetting fail_loc on all nodes..."
2374 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2382 export tdir=d0.${TESTSUITE}/d${base}
2384 local SAVE_UMASK=`umask`
2387 local BEFORE=`date +%s`
2389 log "== test $testnum: $message == `date +%H:%M:%S` ($BEFORE)"
2391 export TESTNAME=test_$testnum
2393 test_${testnum} || error "test_$testnum failed with $?"
2397 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2398 check_catastrophe || error "LBUG/LASSERT detected"
2399 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2400 pass "($((`date +%s` - $BEFORE))s)"
2408 (cd `dirname $1`; echo $PWD/`basename $1`)
2412 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2413 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2418 export base=`basetest $1`
2419 [ "$CHECK_GRANT" == "no" ] && return 0
2421 testname=GCHECK_ONLY_${base}
2422 [ ${!testname}x == x ] && return 0
2424 echo -n "checking grant......"
2426 # write some data to sync client lost_grant
2427 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2428 for i in `seq $OSTCOUNT`; do
2429 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2430 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2431 count=1 > /dev/null 2>&1
2433 # sync all the data and make sure no pending data on server
2436 #get client grant and server grant
2438 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2439 client_grant=$((client_grant + $d))
2442 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2443 server_grant=$((server_grant + $d))
2446 # cleanup the check_grant file
2447 for i in `seq $OSTCOUNT`; do
2448 rm $DIR1/${tfile}_check_grant_$i
2451 #check whether client grant == server grant
2452 if [ $client_grant != $server_grant ]; then
2453 echo "failed: client:${client_grant} server: ${server_grant}"
2460 ########################
2466 ost=`echo $1 | awk -F_ '{print $3}'`
2467 if [ -z $ost ]; then
2468 ost=`echo $1 | sed 's/-osc.*//'`
2475 [ "$node" != "$(hostname)" ]
2481 for node in $(mdts_nodes); do
2482 remote_node $node && return 0
2489 [ "$CLIENTONLY" ] && return 0 || true
2490 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2496 for node in $(osts_nodes) ; do
2497 remote_node $node && return 0
2504 [ "$CLIENTONLY" ] && return 0 || true
2505 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2511 MGS=$(facet_host mgs)
2512 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2518 for num in `seq $MDSCOUNT`; do
2519 MDSNODES="$MDSNODES $(facet_host mds$num)"
2521 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
2527 remote_ost && remote_mds
2531 local OSTNODES=$(facet_host ost1)
2534 for num in `seq $OSTCOUNT`; do
2535 local myOST=$(facet_host ost$num)
2536 OSTNODES="$OSTNODES $myOST"
2538 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
2544 # FIXME. We need a list of clients
2545 local myNODES=$HOSTNAME
2548 # CLIENTS (if specified) contains the local client
2549 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
2551 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
2552 myNODES="$myNODES $(osts_nodes) $(mdts_nodes)"
2555 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
2560 remote_nodes_list () {
2561 local rnodes=$(nodes_list)
2562 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2566 init_clients_lists () {
2567 # Sanity check: exclude the local client from RCLIENTS
2568 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
2570 # Sanity check: exclude the dup entries
2571 rclients=$(for i in $rclients; do echo $i; done | sort -u)
2573 local clients="$SINGLECLIENT $HOSTNAME $rclients"
2575 # Sanity check: exclude the dup entries from CLIENTS
2576 # for those configs which has SINGLCLIENT set to local client
2577 clients=$(for i in $clients; do echo $i; done | sort -u)
2579 CLIENTS=`comma_list $clients`
2580 local -a remoteclients=($rclients)
2581 for ((i=0; $i<${#remoteclients[@]}; i++)); do
2582 varname=CLIENT$((i + 2))
2583 eval $varname=${remoteclients[i]}
2586 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
2589 get_random_entry () {
2592 rnodes=${rnodes//,/ }
2594 local -a nodes=($rnodes)
2595 local num=${#nodes[@]}
2596 local i=$((RANDOM * num * 2 / 65536))
2603 lctl get_param version | grep -q patchless
2607 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
2612 echo $nodes | wc -w || true
2616 local nodes=$(osts_nodes)
2617 local osscount=$(get_node_count "$nodes")
2618 [ ! "$OSTCOUNT" = "$osscount" ]
2622 local nodes=$(mdts_nodes)
2623 local mdtcount=$(get_node_count "$nodes")
2624 [ ! "$MDSCOUNT" = "$mdtcount" ]
2627 generate_machine_file() {
2628 local nodes=${1//,/ }
2629 local machinefile=$2
2630 rm -f $machinefile || error "can't rm $machinefile"
2631 for node in $nodes; do
2632 echo $node >>$machinefile
2637 local file=$1/stripe
2639 $LFS getstripe -v $file || error
2643 check_runas_id_ret() {
2645 local myRUNAS_UID=$1
2646 local myRUNAS_GID=$2
2649 if [ -z "$myRUNAS" ]; then
2650 error_exit "myRUNAS command must be specified for check_runas_id"
2653 $myRUNAS krb5_login.sh || \
2654 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
2656 mkdir $DIR/d0_runas_test
2658 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
2659 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
2660 rm -rf $DIR/d0_runas_test
2665 local myRUNAS_UID=$1
2666 local myRUNAS_GID=$2
2669 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
2670 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
2671 Please set RUNAS_ID to some UID which exists on MDS and client or
2672 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
2675 # obtain the UID/GID for MPI_USER
2679 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
2680 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
2682 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
2683 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
2686 # obtain and cache Kerberos ticket-granting ticket
2687 refresh_krb5_tgt() {
2688 local myRUNAS_UID=$1
2689 local myRUNAS_GID=$2
2692 if [ -z "$myRUNAS" ]; then
2693 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
2696 CLIENTS=${CLIENTS:-$HOSTNAME}
2697 do_nodes $CLIENTS "set -x
2698 if ! $myRUNAS krb5_login.sh; then
2699 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
2704 # Run multiop in the background, but wait for it to print
2705 # "PAUSING" to its stdout before returning from this function.
2706 multiop_bg_pause() {
2707 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
2711 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
2714 echo "$MULTIOP_PROG $FILE v$ARGS"
2715 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
2717 echo "TMPPIPE=${TMPPIPE}"
2718 read -t 60 multiop_output < $TMPPIPE
2719 if [ $? -ne 0 ]; then
2724 if [ "$multiop_output" != "PAUSING" ]; then
2725 echo "Incorrect multiop output: $multiop_output"
2740 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
2746 inodes_available () {
2747 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
2751 # reset llite stat counters
2752 clear_llite_stats(){
2753 lctl set_param -n llite.*.stats 0
2756 # sum llite stat items
2757 calc_llite_stats() {
2758 local res=$(lctl get_param -n llite.*.stats |
2759 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
2763 # reset osc stat counters
2765 lctl set_param -n osc.*.osc_stats 0
2768 # sum osc stat items
2770 local res=$(lctl get_param -n osc.*.osc_stats |
2771 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
2776 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
2779 calc_osc_kbytes () {
2780 df $MOUNT > /dev/null
2781 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
2784 # save_lustre_params(node, parameter_mask)
2785 # generate a stream of formatted strings (<node> <param name>=<param value>)
2786 save_lustre_params() {
2788 do_nodes --verbose $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
2791 # restore lustre parameters from input stream, produces by save_lustre_params
2792 restore_lustre_params() {
2796 while IFS=" =" read node name val; do
2797 do_node ${node//:/} "lctl set_param -n $name $val"
2801 check_catastrophe() {
2802 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
2803 local C=$CATASTROPHE
2804 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
2806 if [ $rnodes ]; then
2807 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
2808 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
2824 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
2826 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
2827 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
2828 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
2832 # CMD: determine mds index where directory inode presents
2835 local file=$dir/f0.get_mds_dir_tmpfile
2839 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
2840 local -a oldused=($iused)
2844 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
2845 local -a newused=($iused)
2848 for ((i=0; i<${#newused[@]}; i++)); do
2849 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
2855 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
2858 mdsrate_cleanup () {
2859 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
2862 delayed_recovery_enabled () {
2863 local var=${SINGLEMDS}_svc
2864 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
2867 ########################
2869 convert_facet2label() {
2872 if [ x$facet = xost ]; then
2876 local varsvc=${facet}_svc
2878 if [ -n ${!varsvc} ]; then
2881 error "No lablel for $facet!"
2885 get_clientosc_proc_path() {
2891 get_lustre_version () {
2892 local node=${1:-"mds"}
2893 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
2896 get_mds_version_major () {
2897 local version=$(get_lustre_version mds)
2898 echo $version | awk -F. '{print $1}'
2901 get_mds_version_minor () {
2902 local version=$(get_lustre_version mds)
2903 echo $version | awk -F. '{print $2}'
2906 get_mdtosc_proc_path() {
2908 local major=$(get_mds_version_major)
2909 local minor=$(get_mds_version_minor)
2910 if [ $major -le 1 -a $minor -le 8 ] ; then
2913 echo "${ost}-osc-MDT0000"
2917 get_osc_import_name() {
2920 local label=$(convert_facet2label $ost)
2922 if [ "$facet" == "mds" ]; then
2923 get_mdtosc_proc_path $label
2927 get_clientosc_proc_path $label
2931 wait_import_state () {
2937 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
2938 while [ "${CONN_STATE}" != "${expected}" ]; do
2939 if [ "${expected}" == "DISCONN" ]; then
2940 # for disconn we can check after proc entry is removed
2941 [ "x${CONN_STATE}" == "x" ] && return 0
2942 # with AT we can have connect request timeout ~ reconnect timeout
2943 # and test can't see real disconnect
2944 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
2946 # disconnect rpc should be wait not more obd_timeout
2947 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
2948 error "can't put import for $CONN_PROC into ${expected} state" && return 1
2950 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
2954 log "$CONN_PROC now in ${CONN_STATE} state"
2958 wait_osc_import_state() {
2962 local ost=$(get_osc_import_name $facet $ost_facet)
2967 CONN_PROC="osc.${ost}.ost_server_uuid"
2968 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
2969 while [ "${CONN_STATE}" != "${expected}" ]; do
2970 if [ "${expected}" == "DISCONN" ]; then
2971 # for disconn we can check after proc entry is removed
2972 [ "x${CONN_STATE}" == "x" ] && return 0
2973 # with AT we can have connect request timeout ~ reconnect timeout
2974 # and test can't see real disconnect
2975 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
2977 # disconnect rpc should be wait not more obd_timeout
2978 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
2979 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
2981 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
2985 log "${ost_facet} now in ${CONN_STATE} state"
2989 get_clientmdc_proc_path() {
2997 do_nodes --verbose $list "PATH=$LUSTRE/tests/:$PATH sh rpc.sh $@ "
3000 wait_clients_import_state () {
3006 local label=$(convert_facet2label $facet)
3009 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3010 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3011 *) error "unknown facet!" ;;
3015 if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
3016 error "import is not in ${expected} state"
3025 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
3026 $LCTL get_param obdfilter.*.kbytesavail))
3027 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
3028 $LCTL get_param -n obdfilter.*.tot_granted))
3029 for ((i=0; i<${#AVAILA[@]}; i++)); do
3030 local -a AVAIL1=(${AVAILA[$i]//=/ })
3031 GRANT=$((${GRANTA[$i]}/1024))
3032 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
3033 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
3041 local ts=$(date +%s)
3043 # bug 20237, comment 11
3044 # It would also be useful to provide the option
3045 # of writing the file to an NFS directory so it doesn't need to be copied.
3048 [ -d "$SHARED_DIR_LOGS" ] && tmp=$SHARED_DIR_LOGS && docp=false
3050 # dump lustre logs, dmesg
3051 do_nodes $list "log=$tmp/\\\$(hostname)-debug-$ts.log ;
3052 lctl dk \\\$log >/dev/null;
3053 log=$tmp/\\\$(hostname)-dmesg-$ts.log;
3056 # FIXME: does it make sense to collect the logs for $ts only, but all
3058 # rsync $TMP/*${TESTSUITE}* to gather the logs dumped by error fn
3059 local logs=$TMP/'*'${TESTSUITE}'*'
3061 logs=$logs' '$tmp/'*'$ts'*'
3063 for node in ${list//,/ }; do
3064 rsync -az $node:"$logs" $TMP
3067 local archive=$TMP/${TESTSUITE}-$ts.tar.bz2
3068 tar -jcf $archive $tmp/*$ts* $TMP/*${TESTSUITE}*
3074 local list=${1:-$(comma_list $(nodes_list))}
3076 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true