2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'print_summary && touch $TF_FAIL && \
5 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 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
24 . $LUSTRE/tests/yaml.sh
26 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
28 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
30 if [ -f "$EXCEPT_LIST_FILE" ]; then
31 echo "Reading test skip list from $EXCEPT_LIST_FILE"
36 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
37 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] && MODPROBECONF=/etc/modprobe.d/Lustre
41 [[ $DIR/ = $MOUNT/* ]] || \
42 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
43 [[ $DIR1/ = $MOUNT1/* ]] || \
44 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
45 [[ $DIR2/ = $MOUNT2/* ]] || \
46 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
48 [ -n "$failed" ] && exit 99 || true
52 echo "usage: $0 [-r] [-f cfgfile]"
60 [ "$TESTSUITE" == "lfsck" ] && return 0
61 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
62 local form="%-13s %-17s %s\n"
63 printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
64 echo "------------------------------------------------------------------------------------"
65 for O in $DEFAULT_SUITES; do
68 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
69 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
71 local log=${TMP}/${o}.log
72 [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
73 [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
74 [ "${!O}" = "done" ] && \
75 printf "$form" "Done" "$O" "E=$skipped" && \
76 [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 if [ "${!O}" = "no" ]; then
84 # only for those tests suits which are run directly from acc-sm script:
85 # bonnie, iozone, etc.
86 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
87 printf "$form" "UNFINISHED" "$O" ""
89 printf "$form" "Skipped" "$O" ""
94 for O in $DEFAULT_SUITES; do
95 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
96 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
97 printf "$form" "UNFINISHED" "$O" ""
102 export LUSTRE=`absolute_path $LUSTRE`
103 export TESTSUITE=`basename $0 .sh`
104 export TEST_FAILED=false
105 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
107 export MKE2FS=${MKE2FS:-mke2fs}
108 export DEBUGFS=${DEBUGFS:-debugfs}
109 export TUNE2FS=${TUNE2FS:-tune2fs}
110 export E2LABEL=${E2LABEL:-e2label}
111 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
112 export E2FSCK=${E2FSCK:-e2fsck}
113 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
114 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check filesystem after each test suit
115 export SKIP_LFSCK=${SKIP_LFSCK:-"yes"} # bug 13698, change to "no" when fixed
116 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-"/tmp"}
117 export FSCK_MAX_ERR=4 # File system errors left uncorrected
118 if [ "$SKIP_LFSCK" == "no" ]; then
119 if [ ! -x `which $LFSCK_BIN` ]; then
121 error_exit "$E2FSCK does not support lfsck"
124 export MDSDB=${MDSDB:-$SHARED_DIRECTORY/mdsdb}
125 export OSTDB=${OSTDB:-$SHARED_DIRECTORY/ostdb}
126 export MDSDB_OPT="--mdsdb $MDSDB"
127 export OSTDB_OPT="--ostdb $OSTDB-\$ostidx"
129 #[ -d /r ] && export ROOT=${ROOT:-/r}
130 export TMP=${TMP:-$ROOT/tmp}
131 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
132 if [[ -z $LOGDIRSET ]]; then
133 export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
134 export LOGDIRSET=true
136 export HOSTNAME=${HOSTNAME:-`hostname`}
137 if ! echo $PATH | grep -q $LUSTRE/utils; then
138 export PATH=$PATH:$LUSTRE/utils
140 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
141 export PATH=$PATH:$LUSTRE/utils/gss
143 if ! echo $PATH | grep -q $LUSTRE/tests; then
144 export PATH=$PATH:$LUSTRE/tests
146 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
147 [ ! -f "$LST" ] && export LST=$(which lst)
148 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
149 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
150 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
151 export PATH=$LUSTRE/tests/racer:$PATH:
153 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
154 export PATH=$PATH:$LUSTRE/tests/mpi
156 export RSYNC_RSH=${RSYNC_RSH:-rsh}
157 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
158 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
159 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
160 [ ! -f "$LFS" ] && export LFS=$(which lfs)
161 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
162 if [ ! -f "$L_GETIDENTITY" ]; then
163 if `which l_getidentity > /dev/null 2>&1`; then
164 export L_GETIDENTITY=$(which l_getidentity)
166 export L_GETIDENTITY=NONE
169 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
170 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
171 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
172 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
173 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
174 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
175 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
176 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
177 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
178 export FSTYPE=${FSTYPE:-"ldiskfs"}
179 export NAME=${NAME:-local}
180 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
181 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
182 export LGSSD=$(which lgssd)
183 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
184 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
185 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
187 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
190 if [ "$ACCEPTOR_PORT" ]; then
191 export PORT_OPT="--port $ACCEPTOR_PORT"
196 echo "Using GSS/krb5 ptlrpc security flavor"
197 which lgss_keyring > /dev/null 2>&1 || \
198 error_exit "built with gss disabled! SEC=$SEC"
209 IDENTITY_UPCALL=false
212 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
214 # Paths on remote nodes, if different
215 export RLUSTRE=${RLUSTRE:-$LUSTRE}
216 export RPWD=${RPWD:-$PWD}
217 export I_MOUNTED=${I_MOUNTED:-"no"}
218 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
219 ! -f `dirname $0`/../mds/mds.ko ]; then
220 export CLIENTMODSONLY=yes
225 while getopts "rvwf:" opt $*; do
228 r) REFORMAT=--reformat;;
230 w) WRITECONF=writeconf;;
235 shift $((OPTIND - 1))
238 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
243 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
244 *) EXT=".ko"; USE_QUOTA=yes;;
249 /sbin/lsmod | grep -q $1
252 # Load a module on the system where this is running.
254 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
256 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
257 # will be used as the arguments. Otherwise arguments will be obtained from
258 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
265 BASE=`basename $module $EXT`
267 module_loaded ${BASE} && return
269 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
271 if [ $# -eq 0 ]; then
272 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
273 # Bash until 4.x, so we resort to eval.
274 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
275 eval set -- \$$optvar
276 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
277 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
278 set -- $(grep "^options\\s*\<${module}\>" $MODPROBECONF)
279 # Get rid of "options $module"
280 (($# > 0)) && shift 2
282 # Ensure we have accept=all for lnet
283 if [ $(basename $module) = lnet ]; then
284 # OK, this is a bit wordy...
285 local arg accept_all_present=false
287 [ "$arg" = accept=all ] && accept_all_present=true
289 $accept_all_present || set -- "$@" accept=all
294 [ $# -gt 0 ] && echo "${module} options: '$*'"
296 # Note that insmod will ignore anything in modprobe.conf, which is why we're
297 # passing options on the command-line.
298 if [ "$BASE" == "lnet_selftest" ] && \
299 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
300 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
301 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
302 insmod ${LUSTRE}/${module}${EXT} "$@"
304 # must be testing a "make install" or "rpm" installation
305 # note failed to load ptlrpc_gss is considered not fatal
306 if [ "$BASE" == "ptlrpc_gss" ]; then
307 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
314 load_modules_local() {
315 if [ -n "$MODPROBE" ]; then
317 echo "Using modprobe to load modules"
321 echo Loading modules from $LUSTRE
322 load_module ../libcfs/libcfs/libcfs
323 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
324 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
325 load_module ../lnet/lnet/lnet
326 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
327 load_module ../lnet/klnds/$LNETLND
328 load_module lvfs/lvfs
329 load_module obdclass/obdclass
330 load_module ptlrpc/ptlrpc
331 load_module ptlrpc/gss/ptlrpc_gss
332 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota
340 if ! client_only; then
341 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
342 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
343 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
348 load_module lvfs/fsfilt_$FSTYPE
350 load_module osd-ldiskfs/osd_ldiskfs
352 load_module obdfilter/obdfilter
355 load_module llite/lustre
356 load_module llite/llite_lloop
357 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
359 rm -f $OGDB/ogdb-$HOSTNAME
360 $LCTL modules > $OGDB/ogdb-$HOSTNAME
362 # 'mount' doesn't look in $PATH, just sbin
363 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
369 # load modules on remote nodes optionally
370 # lustre-tests have to be installed on these nodes
371 if $LOAD_MODULES_REMOTE ; then
372 local list=$(comma_list $(remote_nodes_list))
373 echo loading modules on $list
374 do_rpc_nodes $list load_modules
379 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
380 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
381 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
382 echo "$LEAK_LUSTRE" 1>&2
383 echo "$LEAK_PORTALS" 1>&2
384 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
385 echo "Memory leaks detected"
386 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
392 wait_exit_ST client # bug 12845
394 $LUSTRE_RMMOD $FSTYPE || return 2
396 if $LOAD_MODULES_REMOTE ; then
397 local list=$(comma_list $(remote_nodes_list))
398 if [ ! -z $list ]; then
399 echo unloading modules on $list
400 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
401 do_rpc_nodes $list check_mem_leak
405 check_mem_leak || return 254
407 echo "modules unloaded."
411 check_gss_daemon_nodes() {
415 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
416 if [ \\\"\\\$num\\\" -ne 1 ]; then
417 echo \\\$num instance of $dname;
422 check_gss_daemon_facet() {
426 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
427 if [ $num -ne 1 ]; then
428 echo "$num instance of $dname on $facet"
437 echo Stopping $@ on $list
438 do_nodes $list "killall -2 $@ 2>/dev/null || true"
441 # start gss daemons on all nodes, or
442 # "daemon" on "list" if set
443 start_gss_daemons() {
447 if [ "$list" ] && [ "$daemon" ] ; then
448 echo "Starting gss daemon on nodes: $list"
449 do_nodes $list "$daemon" || return 8
453 local list=$(comma_list $(mdts_nodes))
455 echo "Starting gss daemon on mds: $list"
456 do_nodes $list "$LSVCGSSD -v" || return 1
458 do_nodes $list "$LGSSD -v" || return 2
461 list=$(comma_list $(osts_nodes))
462 echo "Starting gss daemon on ost: $list"
463 do_nodes $list "$LSVCGSSD -v" || return 3
464 # starting on clients
466 local clients=${CLIENTS:-`hostname`}
468 echo "Starting $LGSSD on clients $clients "
469 do_nodes $clients "$LGSSD -v" || return 4
472 # wait daemons entering "stable" status
476 # check daemons are running
478 list=$(comma_list $(mdts_nodes) $(osts_nodes))
479 check_gss_daemon_nodes $list lsvcgssd || return 5
481 list=$(comma_list $(mdts_nodes))
482 check_gss_daemon_nodes $list lgssd || return 6
485 check_gss_daemon_nodes $clients lgssd || return 7
490 local list=$(comma_list $(mdts_nodes))
492 send_sigint $list lsvcgssd lgssd
494 list=$(comma_list $(osts_nodes))
495 send_sigint $list lsvcgssd
497 list=${CLIENTS:-`hostname`}
498 send_sigint $list lgssd
503 if ! module_loaded ptlrpc_gss; then
504 load_module ptlrpc/gss/ptlrpc_gss
505 module_loaded ptlrpc_gss ||
506 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
508 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
510 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
511 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
519 # maybe cleanup credential cache?
525 local device=`mdsdevname $num`
526 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
532 local device=`ostdevname $num`
533 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
541 local dev=$(facet_active $facet)_dev
542 local opt=${facet}_opt
543 echo "Starting ${facet}: ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}"
544 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} ${MOUNT%/*}/${facet}
546 if [ $RC -ne 0 ]; then
547 echo "mount -t lustre $@ ${!dev} ${MOUNT%/*}/${facet}"
548 echo "Start of ${!dev} on ${facet} failed ${RC}"
550 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
551 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
552 lctl set_param debug_mb=${DEBUG_SIZE}; \
555 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
556 [ -z "$label" ] && echo no label for ${!dev} && exit 1
557 eval export ${facet}_svc=${label}
558 echo Started ${label}
563 # start facet device options
569 eval export ${facet}_dev=${device}
570 eval export ${facet}_opt=\"$@\"
572 local varname=${facet}failover_dev
573 if [ -n "${!varname}" ] ; then
574 eval export ${facet}failover_dev=${!varname}
576 eval export ${facet}failover_dev=$device
579 do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
589 HOST=`facet_active_host $facet`
590 [ -z $HOST ] && echo stop: no host for $facet && return 0
592 running=$(do_facet ${facet} "grep -c ${MOUNT%/*}/${facet}' ' /proc/mounts") || true
593 if [ ${running} -ne 0 ]; then
594 echo "Stopping ${MOUNT%/*}/${facet} (opts:$@)"
595 do_facet ${facet} umount -d $@ ${MOUNT%/*}/${facet}
598 # umount should block, but we should wait for unrelated obd's
599 # like the MGS or MGC to also stop.
600 wait_exit_ST ${facet}
603 # save quota version (both administrative and operational quotas)
604 # add an additional parameter if mountpoint is ever different from $MOUNT
605 quota_save_version() {
606 local fsname=${2:-$FSNAME}
608 local ver=$(tr -c -d "123" <<< $spec)
609 local type=$(tr -c -d "ug" <<< $spec)
611 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
613 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
615 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
617 local osts=$(get_facets OST)
618 for ost in ${osts//,/ }; do
620 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
624 # client could mount several lustre
626 local fsname=${1:-$FSNAME}
628 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
629 do_nodes $(comma_list $(osts_nodes)) \
630 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
634 restore_quota_type () {
635 local mntpt=${1:-$MOUNT}
636 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
637 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
640 quota_save_version $old_QUOTA_TYPE
646 # We need save the original quota_type params, and restore them after testing
648 # Suppose that quota type the same on mds and ost
649 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
650 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
651 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
652 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
653 export old_QUOTA_TYPE=$quota_type
654 quota_save_version $QUOTA_TYPE
656 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
657 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
660 local quota_usrs=$QUOTA_USERS
662 # get_filesystem_size
663 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
664 local blk_soft=$((disksz + 1024))
665 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
667 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
669 local i_hard=$((i_soft + i_soft / 20))
671 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
672 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
675 for usr in $quota_usrs; do
676 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
678 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
680 eval $cmd || error "$cmd FAILED!"
682 # display the quota status
683 echo "Quota settings for $usr : "
684 $LFS quota -v -u $usr $mntpt || true
692 # Only supply -o to mount if we have options
693 if [ -n "$MOUNTOPT" ]; then
694 OPTIONS="-o $MOUNTOPT"
696 local device=$MGSNID:/$FSNAME
697 if [ -z "$mnt" -o -z "$FSNAME" ]; then
698 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
702 echo "Starting client: $client: $OPTIONS $device $mnt"
703 do_node $client mkdir -p $mnt
704 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
706 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
707 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
708 lctl set_param debug_mb=${DEBUG_SIZE}"
721 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
722 if [ $running -ne 0 ]; then
723 echo "Stopping client $client $mnt (opts:$force)"
724 do_node $client lsof -t $mnt || need_kill=no
725 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
726 pids=$(do_node $client lsof -t $mnt | sort -u);
727 if [ -n $pids ]; then
728 do_node $client kill -9 $pids || true
732 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
733 if [ $busy -ne 0 ] ; then
734 echo "$mnt is still busy, wait one second" && sleep 1
735 do_node $client umount $force $mnt
740 # nodes is comma list
741 sanity_mount_check_nodes () {
747 # FIXME: assume that all cluster nodes run the same os
748 [ "$(uname)" = Linux ] || return 0
751 for mnt in $mnts ; do
752 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
753 mpts=\\\$(mount | grep -w -c $mnt);
754 if [ \\\$running -ne \\\$mpts ]; then
755 echo \\\$(hostname) env are INSANE!;
763 sanity_mount_check_servers () {
765 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
766 echo Checking servers environments
768 # FIXME: modify get_facets to display all facets wo params
769 local facets="$(get_facets OST),$(get_facets MDS),mgs"
773 for facet in ${facets//,/ }; do
774 node=$(facet_host ${facet})
775 mnt=${MOUNT%/*}/${facet}
776 sanity_mount_check_nodes $node $mnt ||
777 { error "server $node environments are insane!"; return 1; }
781 sanity_mount_check_clients () {
782 local clients=${1:-$CLIENTS}
783 local mntpt=${2:-$MOUNT}
784 local mntpt2=${3:-$MOUNT2}
786 [ -z $clients ] && clients=$(hostname)
787 echo Checking clients $clients environments
789 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
790 error "clients environments are insane!"
793 sanity_mount_check () {
794 sanity_mount_check_servers || return 1
795 sanity_mount_check_clients || return 2
798 # mount clients if not mouted
799 zconf_mount_clients() {
802 local OPTIONS=${3:-$MOUNTOPT}
804 # Only supply -o to mount if we have options
805 if [ "$OPTIONS" ]; then
806 OPTIONS="-o $OPTIONS"
808 local device=$MGSNID:/$FSNAME
809 if [ -z "$mnt" -o -z "$FSNAME" ]; then
810 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
814 echo "Starting client $clients: $OPTIONS $device $mnt"
817 running=\\\$(mount | grep -c $mnt' ');
819 if [ \\\$running -eq 0 ] ; then
821 mount -t lustre $OPTIONS $device $mnt;
824 exit \\\$rc" || return ${PIPESTATUS[0]}
826 echo "Started clients $clients: "
827 do_nodes $clients "mount | grep -w $mnt"
829 do_nodes $clients "lctl set_param debug=\\\"$PTLDEBUG\\\";
830 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
831 lctl set_param debug_mb=${DEBUG_SIZE};"
836 zconf_umount_clients() {
843 echo "Stopping clients: $clients $mnt (opts:$force)"
844 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
845 if [ \\\$running -ne 0 ] ; then
846 echo Stopping client \\\$(hostname) $mnt opts:$force;
847 lsof -t $mnt || need_kill=no;
848 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
849 pids=\\\$(lsof -t $mnt | sort -u);
850 if [ -n \\\"\\\$pids\\\" ]; then
854 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
855 if [ \\\$busy -ne 0 ] ; then
856 echo "$mnt is still busy, wait one second" && sleep 1;
862 shudown_node_hard () {
866 for i in $(seq $attempts) ; do
869 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
870 echo "waiting for $host to fail attempts=$attempts"
871 [ $i -lt $attempts ] || \
872 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
878 local mnt=${2:-$MOUNT}
881 if [ "$FAILURE_MODE" = HARD ]; then
882 shudown_node_hard $client
884 zconf_umount_clients $client $mnt -f
890 if [ "$FAILURE_MODE" = HARD ]; then
891 shudown_node_hard $(facet_active_host $facet)
892 elif [ "$FAILURE_MODE" = SOFT ]; then
906 if [ "$FAILURE_MODE" = HARD ]; then
907 $POWER_UP `facet_active_host $facet`
915 if [ "$FAILURE_MODE" = HARD ]; then
921 # recovery-scale functions
922 check_progs_installed () {
927 do_nodes $clients "PATH=:$PATH; status=true;
928 for prog in $progs; do
929 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
930 echo \\\$prog missing on \\\$(hostname);
938 echo __$(echo $1 | tr '-' 'X')
941 start_client_load() {
944 local var=$(client_var_name $client)_load
945 eval export ${var}=$load
947 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
948 BREAK_ON_ERROR=$BREAK_ON_ERROR \
949 END_RUN_FILE=$END_RUN_FILE \
950 LOAD_PID_FILE=$LOAD_PID_FILE \
951 TESTSUITELOG=$TESTSUITELOG \
953 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
954 log "Started client load: ${load} on $client"
959 start_client_loads () {
960 local -a clients=(${1//,/ })
961 local numloads=${#CLIENT_LOADS[@]}
964 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
965 testnum=$((nodenum % numloads))
966 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
968 # bug 22169: wait the background threads to start
972 # only for remote client
973 check_client_load () {
975 local var=$(client_var_name $client)_load
976 local TESTLOAD=run_${!var}.sh
978 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
980 # bug 18914: try to connect several times not only when
981 # check ps, but while check_catastrophe also
984 while [ $RC = 254 -a $tries -gt 0 ]; do
988 if ! check_catastrophe $client; then
990 if [ $RC -eq 254 ]; then
991 # FIXME: not sure how long we shuold sleep here
995 echo "check catastrophe failed: RC=$RC "
999 # We can continue try to connect if RC=254
1000 # Just print the warning about this
1001 if [ $RC = 254 ]; then
1002 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1005 # see if the load is still on the client
1008 while [ $RC = 254 -a $tries -gt 0 ]; do
1012 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1017 if [ $RC = 254 ]; then
1018 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1019 # see if we can diagnose a bit why this is
1024 check_client_loads () {
1025 local clients=${1//,/ }
1029 for client in $clients; do
1030 check_client_load $client
1032 if [ "$rc" != 0 ]; then
1033 log "Client load failed on node $client, rc=$rc"
1039 restart_client_loads () {
1040 local clients=${1//,/ }
1041 local expectedfail=${2:-""}
1045 for client in $clients; do
1046 check_client_load $client
1048 if [ "$rc" != 0 -a "$expectedfail" ]; then
1049 local var=$(client_var_name $client)_load
1050 start_client_load $client ${!var}
1051 echo "Restarted client load ${!var}: on $client. Checking ..."
1052 check_client_load $client
1054 if [ "$rc" != 0 ]; then
1055 log "Client load failed to restart on node $client, rc=$rc"
1056 # failure one client load means test fail
1057 # we do not need to check other
1065 # End recovery-scale functions
1067 # verify that lustre actually cleaned up properly
1069 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1070 error "LBUG/LASSERT detected"
1071 BUSY=`dmesg | grep -i destruct || true`
1072 if [ "$BUSY" ]; then
1074 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1078 check_mem_leak || exit 204
1080 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1081 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1083 if module_loaded lnet || module_loaded libcfs; then
1084 echo "$0: modules still loaded..." 1>&2
1101 RESULT=$(do_node $node "$TEST")
1102 if [ "$RESULT" == "$FINAL" ]; then
1103 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1106 [ $WAIT -ge $MAX ] && break
1107 echo "Waiting $((MAX - WAIT)) secs for update"
1108 WAIT=$((WAIT + sleep))
1111 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1115 wait_update_facet () {
1117 wait_update $(facet_active_host $facet) "$@"
1120 wait_delete_completed () {
1121 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1122 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1126 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1128 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1129 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1130 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1131 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1135 echo "Delete is not completed in $MAX_WAIT sec"
1141 check_network "$host" 900
1142 while ! do_node $host hostname > /dev/null; do sleep 5; done
1147 local host=`facet_active_host $facet`
1151 wait_recovery_complete () {
1154 # Use default policy if $2 is not passed by caller.
1155 local MAX=${2:-$(max_recovery_time)}
1157 local var_svc=${facet}_svc
1158 local procfile="*.${!var_svc}.recovery_status"
1162 while [ $WAIT -lt $MAX ]; do
1163 STATUS=$(do_facet $facet lctl get_param -n $procfile | grep status)
1164 [[ $STATUS = "status: COMPLETE" ]] && return 0
1167 echo "Waiting $((MAX - WAIT)) secs for $facet recovery done. $STATUS"
1169 echo "$facet recovery not done in $MAX sec. $STATUS"
1173 wait_mds_ost_sync () {
1174 # just because recovery is done doesn't mean we've finished
1175 # orphan cleanup. Wait for llogs to get synchronized.
1176 echo "Waiting for orphan cleanup..."
1177 # MAX value includes time needed for MDS-OST reconnection
1178 local MAX=$(( TIMEOUT * 2 ))
1180 while [ $WAIT -lt $MAX ]; do
1181 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1182 "$LCTL get_param -n obdfilter.*.mds_sync"))
1185 for ((i=0; i<${#sync[@]}; i++)); do
1186 [ ${sync[$i]} -eq 0 ] && continue
1187 # there is a not finished MDS-OST synchronization
1191 sleep 2 # increase waiting time and cover statfs cache
1192 [ ${con} -eq 1 ] && return 0
1193 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1196 echo "$facet recovery not done in $MAX sec. $STATUS"
1200 wait_destroy_complete () {
1201 echo "Waiting for destroy to be done..."
1202 # MAX value shouldn't be big as this mean server responsiveness
1203 # never increase this just to make test pass but investigate
1204 # why it takes so long time
1207 while [ $WAIT -lt $MAX ]; do
1208 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1210 for ((i=0; i<${#RPCs[@]}; i++)); do
1211 [ ${RPCs[$i]} -eq 0 ] && continue
1212 # there are still some destroy RPCs in flight
1217 [ ${con} -eq 1 ] && return 0 # done waiting
1218 echo "Waiting $WAIT secs for destroys to be done."
1221 echo "Destroys weren't done in $MAX sec."
1231 # conf-sanity 31 takes a long time cleanup
1232 while [ $WAIT -lt 300 ]; do
1233 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1234 [ -z "${running}" ] && return 0
1235 echo "waited $WAIT for${running}"
1236 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1238 WAIT=$((WAIT + INTERVAL))
1240 echo "service didn't stop after $WAIT seconds. Still running:"
1245 wait_remote_prog () {
1251 [ "$PDSH" = "no_dsh" ] && return 0
1253 while [ $WAIT -lt $2 ]; do
1254 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1255 [ -z "${running}" ] && return 0 || true
1256 echo "waited $WAIT for: "
1258 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1260 WAIT=$((WAIT + INTERVAL))
1262 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1263 [ -z "$pids" ] && return 0
1264 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1265 # FIXME: not portable
1266 for pid in $pids; do
1267 cat /proc/${pid}/status || true
1268 cat /proc/${pid}/wchan || true
1270 kill -9 $pid || true
1279 # not every config has many clients
1281 if [ ! -z "$CLIENTS" ]; then
1282 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1284 stat -f $MOUNT > /dev/null
1290 # usually checked on particular client or locally
1292 if [ ! -z "$client" ]; then
1293 $PDSH $client "stat -f $MOUNT" > /dev/null
1295 stat -f $MOUNT > /dev/null
1303 client_reconnect() {
1304 uname -n >> $MOUNT/recon
1305 if [ -z "$CLIENTS" ]; then
1306 df $MOUNT; uname -n >> $MOUNT/recon
1308 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1310 echo Connected clients:
1312 ls -l $MOUNT/recon > /dev/null
1319 echo "Failing $facet on node `facet_active_host $facet`"
1320 shutdown_facet $facet
1321 [ -n "$sleep_time" ] && sleep $sleep_time
1323 change_active $facet
1324 local TO=`facet_active_host $facet`
1325 echo "Failover $facet to $TO"
1327 mount_facet $facet || error "Restart of $facet failed"
1336 do_facet $facet sync
1338 local svc=${facet}_svc
1339 do_facet $facet $LCTL --device %${!svc} notransno
1340 do_facet $facet $LCTL --device %${!svc} readonly
1341 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1342 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1345 replay_barrier_nodf() {
1346 local facet=$1 echo running=${running}
1347 do_facet $facet sync
1348 local svc=${facet}_svc
1349 echo Replay barrier on ${!svc}
1350 do_facet $facet $LCTL --device %${!svc} notransno
1351 do_facet $facet $LCTL --device %${!svc} readonly
1352 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1353 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1356 replay_barrier_nosync() {
1357 local facet=$1 echo running=${running}
1358 local svc=${facet}_svc
1359 echo Replay barrier on ${!svc}
1360 do_facet $facet $LCTL --device %${!svc} notransno
1361 do_facet $facet $LCTL --device %${!svc} readonly
1362 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1363 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1366 mds_evict_client() {
1367 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1368 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1371 ost_evict_client() {
1372 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1373 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1377 facet_failover $* || error "failover: $?"
1378 clients_up || error "post-failover df: $?"
1383 facet_failover $facet
1389 change_active $facet
1390 mount_facet $facet -o abort_recovery
1391 clients_up || echo "first df failed: $?"
1392 clients_up || error "post-failover df: $?"
1396 echo There is no lmc. This is mountconf, baby.
1401 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1407 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1408 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1409 if [ -z "$ID" ]; then
1410 echo "Could not get a ptl id for $1..."
1419 h2name_or_ip "$1" "tcp"
1424 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1425 if type __h2elan >/dev/null 2>&1; then
1428 ID=`echo $1 | sed 's/[^0-9]*//g'`
1436 h2name_or_ip "$1" "openib"
1438 declare -fx h2openib
1441 h2name_or_ip "$1" "o2ib"
1448 [ "$facet" == client ] && echo -n $HOSTNAME && return
1449 varname=${facet}_HOST
1450 if [ -z "${!varname}" ]; then
1451 if [ "${facet:0:3}" == "ost" ]; then
1452 eval ${facet}_HOST=${ost_HOST}
1460 local activevar=${facet}active
1462 if [ -f $TMP/${facet}active ] ; then
1463 source $TMP/${facet}active
1466 active=${!activevar}
1467 if [ -z "$active" ] ; then
1474 facet_active_host() {
1476 local active=`facet_active $facet`
1477 if [ "$facet" == client ]; then
1480 echo `facet_host $active`
1486 local failover=${facet}failover
1487 host=`facet_host $failover`
1488 [ -z "$host" ] && return
1489 local curactive=`facet_active $facet`
1490 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1491 eval export ${facet}active=$facet
1493 eval export ${facet}active=$failover
1495 # save the active host for this facet
1496 local activevar=${facet}active
1497 echo "$activevar=${!activevar}" > $TMP/$activevar
1502 # do not stripe off hostname if verbose, bug 19215
1503 if [ x$1 = x--verbose ]; then
1511 if [ "$HOST" = "$HOSTNAME" ]; then
1513 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1514 echo "cannot run remote command on $HOST with $myPDSH"
1518 echo "CMD: $HOST $@" >&2
1519 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1522 if [ "$myPDSH" = "rsh" ]; then
1523 # we need this because rsh does not return exit code of an executed command
1524 local command_status="$TMP/cs"
1525 rsh $HOST ":> $command_status"
1526 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1527 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1528 echo command failed >$command_status"
1529 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1534 # print HOSTNAME for myPDSH="no_dsh"
1535 if [[ $myPDSH = no_dsh ]]; then
1536 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1538 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1541 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1543 return ${PIPESTATUS[0]}
1547 do_node --verbose "$@"
1550 single_local_node () {
1551 [ "$1" = "$HOSTNAME" ]
1554 # Outputs environment variable assignments that should be passed to remote nodes
1559 for var in ${!MODOPTS_*}; do
1561 echo "${var}=\"$value\""
1567 # do not stripe off hostname if verbose, bug 19215
1568 if [ x$1 = x--verbose ]; then
1576 if single_local_node $rnodes; then
1578 do_nodev $rnodes "$@"
1580 do_node $rnodes "$@"
1585 # This is part from do_node
1588 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1589 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1592 echo "CMD: $rnodes $@" >&2
1593 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1597 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1599 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/\w+:\s//g"
1601 return ${PIPESTATUS[0]}
1607 local HOST=`facet_active_host $facet`
1608 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1613 do_nodes --verbose "$@"
1619 # make sure its not already running
1621 rm -f $TMP/${facet}active
1622 do_facet ${facet} $MKFS $*
1628 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1629 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1636 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1637 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1645 # make sure we are using the primary server, so test-framework will
1646 # be able to clean up properly.
1647 activemds=`facet_active mds1`
1648 if [ $activemds != "mds1" ]; then
1652 local clients=$CLIENTS
1653 [ -z $clients ] && clients=$(hostname)
1655 zconf_umount_clients $clients $MOUNT "$*" || true
1656 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1658 [ "$CLIENTONLY" ] && return
1659 # The add fn does rm ${facet}active file, this would be enough
1660 # if we use do_facet <facet> only after the facet added, but
1661 # currently we use do_facet mds in local.sh
1662 for num in `seq $MDSCOUNT`; do
1664 rm -f ${TMP}/mds${num}active
1667 for num in `seq $OSTCOUNT`; do
1669 rm -f $TMP/ost${num}active
1672 if ! combined_mgs_mds ; then
1680 nfs_client_mode && return
1690 test $nr = 1 && echo -n $MDS_MKFS_OPTS || echo -n $MDSn_MKFS_OPTS
1693 combined_mgs_mds () {
1694 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
1698 if [ "$IAMDIR" == "yes" ]; then
1699 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
1700 MDSn_MKFS_OPTS="$MDSn_MKFS_OPTS --iam-dir"
1703 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1706 # We need ldiskfs here, may as well load them all
1708 [ "$CLIENTONLY" ] && return
1709 echo Formatting mgs, mds, osts
1710 if ! combined_mgs_mds ; then
1711 add mgs $mgs_MKFS_OPTS $FSTYPE_OPT --reformat $MGSDEV || exit 10
1714 for num in `seq $MDSCOUNT`; do
1715 echo "Format mds$num: $(mdsdevname $num)"
1717 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` || exit 9
1719 add mds$num `mdsmkfsopts $num` $FSTYPE_OPT --reformat `mdsdevname $num` > /dev/null || exit 9
1723 for num in `seq $OSTCOUNT`; do
1724 echo "Format ost$num: $(ostdevname $num)"
1726 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` || exit 10
1728 add ost$num $OST_MKFS_OPTS --reformat `ostdevname $num` > /dev/null || exit 10
1734 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1738 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
1742 # 0: success, the old identity set already.
1743 # 1: success, the old identity does not set.
1748 local j=`expr $num - 1`
1749 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
1751 if [ -z "$MDT" ]; then
1755 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
1758 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
1760 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
1763 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
1765 if [ $old = "NONE" ]; then
1774 zconf_umount `hostname` $1 || error "umount failed"
1775 zconf_mount `hostname` $1 || error "mount failed"
1778 writeconf_facet () {
1782 do_facet $facet "$TUNEFS --writeconf $dev"
1786 for num in `seq $MDSCOUNT`; do
1787 DEVNAME=$(mdsdevname $num)
1788 writeconf_facet mds$num $DEVNAME
1791 for num in `seq $OSTCOUNT`; do
1792 DEVNAME=$(ostdevname $num)
1793 writeconf_facet ost$num $DEVNAME
1798 nfs_client_mode && return
1800 sanity_mount_check ||
1801 error "environments are insane!"
1805 if [ -z "$CLIENTONLY" ]; then
1806 echo Setup mgs, mdt, osts
1807 echo $WRITECONF | grep -q "writeconf" && \
1809 if ! combined_mgs_mds ; then
1810 start mgs $MGSDEV $mgs_MOUNT_OPTS
1813 for num in `seq $MDSCOUNT`; do
1814 DEVNAME=$(mdsdevname $num)
1815 start mds$num $DEVNAME $MDS_MOUNT_OPTS
1817 # We started mds, now we should set failover variables properly.
1818 # Set mds${num}failover_HOST if it is not set (the default failnode).
1819 local varname=mds${num}failover_HOST
1820 if [ -z "${!varname}" ]; then
1821 eval mds${num}failover_HOST=$(facet_host mds$num)
1824 if [ $IDENTITY_UPCALL != "default" ]; then
1825 switch_identity $num $IDENTITY_UPCALL
1828 for num in `seq $OSTCOUNT`; do
1829 DEVNAME=$(ostdevname $num)
1830 start ost$num $DEVNAME $OST_MOUNT_OPTS
1832 # We started ost$num, now we should set ost${num}failover variable properly.
1833 # Set ost${num}failover_HOST if it is not set (the default failnode).
1834 varname=ost${num}failover_HOST
1835 if [ -z "${!varname}" ]; then
1836 eval ost${num}failover_HOST=$(facet_host ost${num})
1844 # wait a while to allow sptlrpc configuration be propogated to targets,
1845 # only needed when mounting new target devices.
1850 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
1852 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
1854 if [ "$MOUNT_2" ]; then
1855 mount_client $MOUNT2
1856 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
1861 # by remounting mdt before ost, initial connect from mdt to ost might
1862 # timeout because ost is not ready yet. wait some time to its fully
1863 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
1864 # by a context negotiation rpc with $TIMEOUT.
1865 # FIXME better by monitoring import status.
1868 sleep $((TIMEOUT + 5))
1874 mounted_lustre_filesystems() {
1875 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
1878 init_facet_vars () {
1879 [ "$CLIENTONLY" ] && return 0
1886 eval export ${facet}_dev=${device}
1887 eval export ${facet}_opt=\"$@\"
1889 local dev=${facet}_dev
1890 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
1891 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1893 eval export ${facet}_svc=${label}
1895 local varname=${facet}failover_HOST
1896 if [ -z "${!varname}" ]; then
1897 eval $varname=$(facet_host $facet)
1900 # ${facet}failover_dev is set in cfg file
1901 varname=${facet}failover_dev
1902 if [ -n "${!varname}" ] ; then
1903 eval export ${facet}failover_dev=${!varname}
1905 eval export ${facet}failover_dev=$device
1909 init_facets_vars () {
1912 if ! remote_mds_nodsh; then
1913 for num in `seq $MDSCOUNT`; do
1914 DEVNAME=`mdsdevname $num`
1915 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
1919 remote_ost_nodsh && return
1921 for num in `seq $OSTCOUNT`; do
1922 DEVNAME=`ostdevname $num`
1923 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
1927 osc_ensure_active () {
1933 while [ $period -lt $timeout ]; do
1934 count=$(do_facet $facet "lctl dl | grep '${FSNAME}-OST.*-osc-${type}' | grep ' IN ' 2>/dev/null | wc -l")
1935 if [ $count -eq 0 ]; then
1939 echo "There are $count OST are inactive, wait $period seconds, and try again"
1941 period=$((period+3))
1944 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
1947 init_param_vars () {
1948 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
1949 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
1950 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
1951 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
1955 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
1957 log "Using TIMEOUT=$TIMEOUT"
1959 osc_ensure_active $SINGLEMDS M $TIMEOUT
1960 osc_ensure_active client c $TIMEOUT
1962 if [ $QUOTA_AUTO -ne 0 ]; then
1963 if [ "$ENABLE_QUOTA" ]; then
1964 echo "enable quota as required"
1965 setup_quota $MOUNT || return 2
1967 echo "disable quota as required"
1968 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
1975 nfs_client_mode () {
1976 if [ "$NFSCLIENT" ]; then
1977 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
1978 local clients=$CLIENTS
1979 [ -z $clients ] && clients=$(hostname)
1981 # FIXME: remove hostname when 19215 fixed
1982 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
1983 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
1984 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
1990 check_config_client () {
1993 local mounted=$(mount | grep " $mntpt ")
1994 if [ "$CLIENTONLY" ]; then
1996 # CLIENTONLY should not depend on *_HOST settings
1997 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
1998 # in theory someone could create a new,
1999 # client-only config file that assumed lustre was already
2000 # configured and didn't set the MGSNID. If MGSNID is not set,
2001 # then we should use the mgs nid currently being used
2002 # as the default value. bug 18021
2003 [[ x$MGSNID = x ]] &&
2006 if [[ x$mgc != xMGC$MGSNID ]]; then
2007 if [ "$mgs_HOST" ]; then
2008 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2009 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2010 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2016 local myMGS_host=$mgs_HOST
2017 if [ "$NETTYPE" = "ptl" ]; then
2018 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2021 echo Checking config lustre mounted on $mntpt
2022 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2023 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2025 # if [ "$mgshost" != "$myMGS_host" ]; then
2026 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2027 # Please use correct config or set mds_HOST correctly!"
2032 check_config_clients () {
2033 local clients=${CLIENTS:-$HOSTNAME}
2036 nfs_client_mode && return
2038 do_rpc_nodes $clients check_config_client $mntpt
2040 sanity_mount_check ||
2041 error "environments are insane!"
2045 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2046 local cltimeout=$(lctl get_param -n timeout)
2047 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2048 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2055 [ -z $mntpt ] && return 1
2056 local mounted=$(mounted_lustre_filesystems)
2058 echo $mounted' ' | grep -w -q $mntpt' '
2062 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2066 # empty lustre filesystem may have empty directories lost+found and .lustre
2068 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2069 -print | wc -l) = 1 ] || return 1
2070 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2071 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2075 check_and_setup_lustre() {
2076 nfs_client_mode && return
2078 local MOUNTED=$(mounted_lustre_filesystems)
2082 # both MOUNT and MOUNT2 are not mounted
2083 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2084 [ "$REFORMAT" ] && formatall
2085 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2087 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2088 export I_MOUNTED=yes
2092 elif is_mounted $MOUNT2; then
2094 # MOUNT2 is mounted, while MOUNT_2 is not set
2095 if ! [ "$MOUNT_2" ]; then
2096 cleanup_mount $MOUNT2
2097 export I_UMOUNTED2=yes
2100 # MOUNT2 is mounted, MOUNT_2 is set
2102 # FIXME: what to do if check_config failed?
2104 # 1) remote client has mounted other Lustre fs ?
2105 # 2) it has insane env ?
2106 # let's try umount MOUNT2 on all clients and mount it again:
2107 if ! check_config_clients $MOUNT2; then
2108 cleanup_mount $MOUNT2
2109 restore_mount $MOUNT2
2110 export I_MOUNTED2=yes
2115 # MOUNT is mounted MOUNT2 is not mounted
2116 elif [ "$MOUNT_2" ]; then
2117 restore_mount $MOUNT2
2118 export I_MOUNTED2=yes
2122 # FIXME: what to do if check_config failed?
2124 # 1) remote client has mounted other Lustre fs?
2125 # 2) lustre is mounted on remote_clients atall ?
2126 check_config_clients $MOUNT
2130 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
2131 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
2132 lctl set_param debug_mb=${DEBUG_SIZE};
2139 if [ "$ONLY" == "setup" ]; then
2145 local clients=${CLIENTS:-$HOSTNAME}
2148 zconf_mount_clients $clients $mntpt
2152 local clients=${CLIENTS:-$HOSTNAME}
2155 zconf_umount_clients $clients $mntpt
2158 cleanup_and_setup_lustre() {
2159 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2160 lctl set_param debug=0 || true
2162 if [ "$ONLY" == "cleanup" ]; then
2166 check_and_setup_lustre
2169 # Get all of the server target devices from a given server node and type.
2178 mdt) obd_type="osd" ;;
2179 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2180 *) echo "invalid server type" && return 1 ;;
2183 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2184 for dev in $devs; do
2186 *loop*) do_node $node "losetup $dev" | \
2187 sed -e "s/.*(//" -e "s/).*//" ;;
2193 # Get all of the server target devices.
2198 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2202 for node in $(osts_nodes); do
2203 OSTDEVS[i]=$(get_mnt_devs $node ost)
2208 # Run e2fsck on MDT or OST device.
2215 df > /dev/null # update statfs data on disk
2216 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
2219 local rc=${PIPESTATUS[0]}
2220 [ $rc -le $FSCK_MAX_ERR ] || \
2221 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2225 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2232 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2233 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2234 error "fail to create file in $SHARED_DIRECTORY")
2236 # make sure everything gets to the backing store
2237 local list=$(comma_list $CLIENTS $(facet_host $SINGLEMDS) $(osts_nodes))
2238 do_nodes $list "sync; sleep 2; sync"
2240 do_nodes $list ls $tmp_file || \
2241 error "$SHARED_DIRECTORY is not a shared directory"
2244 run_e2fsck $(mdts_nodes) $MDTDEV
2249 for node in $(osts_nodes); do
2250 for dev in ${OSTDEVS[i]}; do
2251 local ostdb_opt=`eval echo $OSTDB_OPT`
2252 run_e2fsck $node $dev $ostidx "$ostdb_opt"
2253 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2254 ostidx=$((ostidx + 1))
2261 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2264 local rc=${PIPESTATUS[0]}
2265 [ $rc -le $FSCK_MAX_ERR ] || \
2266 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2267 echo "lfsck finished with rc=$rc"
2269 rm -rvf $MDSDB* $OSTDB* || true
2274 check_and_cleanup_lustre() {
2275 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2278 if [ "$SKIP_LFSCK" == "no" ]; then
2286 if is_mounted $MOUNT; then
2287 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2288 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2291 if [ "$I_UMOUNTED2" = "yes" ]; then
2292 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2295 if [ "$I_MOUNTED2" = "yes" ]; then
2296 cleanup_mount $MOUNT2
2299 if [ "$I_MOUNTED" = "yes" ]; then
2300 cleanupall -f || error "cleanup failed"
2312 while [ $NETWORK -eq 0 ]; do
2313 if ping -c 1 -w 3 $1 > /dev/null; then
2317 echo "waiting for $1, $((MAX - WAIT)) secs left"
2320 if [ $WAIT -gt $MAX ]; then
2321 echo "Network not available"
2327 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2338 # the sed converts spaces to commas, but leaves the last space
2339 # alone, so the line doesn't end with a comma.
2340 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2343 # list, excluded are the comma separated lists
2344 exclude_items_from_list () {
2350 for item in ${excluded//,/ }; do
2351 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2353 echo $(comma_list $list)
2356 # list, expand are the comma separated lists
2358 local list=${1//,/ }
2359 local expand=${2//,/ }
2362 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2363 echo $(comma_list $expanded)
2366 testslist_filter () {
2367 local script=$LUSTRE/tests/${TESTSUITE}.sh
2369 [ -f $script ] || return 0
2371 local start_at=$START_AT
2372 local stop_at=$STOP_AT
2374 local var=${TESTSUITE//-/_}_START_AT
2375 [ x"${!var}" != x ] && start_at=${!var}
2376 var=${TESTSUITE//-/_}_STOP_AT
2377 [ x"${!var}" != x ] && stop_at=${!var}
2379 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2380 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2381 /^'${start_at}'$/ {flag = 0}
2382 {if (flag == 1) print $0}
2383 /^'${stop_at}'$/ { flag = 1 }'
2387 (cd `dirname $1`; echo $PWD/`basename $1`)
2391 local name=$(echo $1 | tr "[:upper:]" "[:lower:]")
2392 local type=$(echo $1 | tr "[:lower:]" "[:upper:]")
2395 local count=${type}COUNT
2396 for ((i=1; i<=${!count}; i++)) do
2397 list="$list ${name}$i"
2399 echo $(comma_list $list)
2402 ##################################
2403 # Adaptive Timeouts funcs
2406 # only check mds, we assume at_max is the same on all nodes
2407 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2408 if [ $at_max -eq 0 ]; then
2418 # suppose that all ost-s has the same at_max set
2419 if [ $facet == "ost" ]; then
2420 do_facet ost1 "lctl get_param -n at_max"
2422 do_facet $facet "lctl get_param -n at_max"
2432 if [ $facet == "ost" ]; then
2433 for i in `seq $OSTCOUNT`; do
2434 do_facet ost$i "lctl set_param at_max=$at_max"
2437 elif [ $facet == "mds" ]; then
2438 for i in `seq $MDSCOUNT`; do
2439 do_facet mds$i "lctl set_param at_max=$at_max"
2442 do_facet $facet "lctl set_param at_max=$at_max"
2447 ##################################
2451 # OBD_FAIL_MDS_ALL_REQUEST_NET
2453 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2454 do_facet client "$1" || RC=$?
2455 do_facet $SINGLEMDS lctl set_param fail_loc=0
2460 # OBD_FAIL_MDS_ALL_REPLY_NET
2462 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2463 do_facet client "$@" || RC=$?
2464 do_facet $SINGLEMDS lctl set_param fail_loc=0
2468 drop_reint_reply() {
2469 # OBD_FAIL_MDS_REINT_NET_REP
2471 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2472 do_facet client "$@" || RC=$?
2473 do_facet $SINGLEMDS lctl set_param fail_loc=0
2478 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2480 do_facet ost1 lctl set_param fail_loc=0x214
2481 do_facet client "$1" || RC=$?
2482 do_facet client "sync"
2483 do_facet ost1 lctl set_param fail_loc=0
2487 drop_ldlm_cancel() {
2488 #define OBD_FAIL_LDLM_CANCEL 0x304
2490 do_facet client lctl set_param fail_loc=0x304
2491 do_facet client "$@" || RC=$?
2492 do_facet client lctl set_param fail_loc=0
2496 drop_bl_callback() {
2497 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2499 do_facet client lctl set_param fail_loc=0x305
2500 do_facet client "$@" || RC=$?
2501 do_facet client lctl set_param fail_loc=0
2506 #define OBD_FAIL_LDLM_REPLY 0x30c
2508 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2509 do_facet client "$@" || RC=$?
2510 do_facet $SINGLEMDS lctl set_param fail_loc=0
2518 echo "clearing fail_loc on $facet"
2519 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2522 set_nodes_failloc () {
2523 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2526 cancel_lru_locks() {
2527 $LCTL mark "cancel_lru_locks $1 start"
2528 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2529 $LCTL set_param -n $d=clear
2531 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2532 $LCTL mark "cancel_lru_locks $1 stop"
2537 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2538 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2539 echo "$DEFAULT_LRU_SIZE"
2544 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2547 lru_resize_disable()
2549 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2554 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2555 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2556 echo there is still data in page cache $FILE ?
2557 lctl get_param -n $FILE
2565 DEBUGSAVE="$(lctl get_param -n debug)"
2569 [ -n "$DEBUGSAVE" ] && \
2570 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
2575 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
2578 debug_size_restore() {
2579 [ -n "$DEBUG_SIZE_SAVED" ] && \
2580 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
2584 start_full_debug_logging() {
2589 local DEBUG_SIZE=150
2591 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
2592 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
2595 stop_full_debug_logging() {
2600 ##################################
2602 ##################################
2605 local TYPE=${TYPE:-"FAIL"}
2608 # do not dump logs if $1=false
2609 if [ "x$1" = "xfalse" ]; then
2614 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2616 # We need to dump the logs on all nodes
2618 gather_logs $(comma_list $(nodes_list))
2622 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2623 echo "$@" > $LOGDIR/err
2635 # use only if we are ignoring failures for this test, bugno required.
2636 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2637 # e.g. error_ignore 5494 "your message"
2639 local TYPE="IGNORE (bz$1)"
2645 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2650 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2651 [ "$TESTSUITELOG" ] && \
2652 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2655 build_test_filter() {
2656 EXCEPT="$EXCEPT $(testslist_filter)"
2658 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2662 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2663 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2664 [ "$EXCEPT_SLOW" ] && \
2665 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2666 for E in $EXCEPT $ALWAYS_EXCEPT; do
2667 eval EXCEPT_${E}=true
2669 for E in $EXCEPT_SLOW; do
2670 eval EXCEPT_SLOW_${E}=true
2672 for G in $GRANT_CHECK_LIST; do
2673 eval GCHECK_ONLY_${G}=true
2678 if [[ $1 = [a-z]* ]]; then
2685 # print a newline if the last test was skipped
2686 export LAST_SKIPPED=
2688 # Main entry into test-framework. This is called with the name and
2689 # description of a test. The name is used to find the function to run
2690 # the test using "test_$name".
2692 # This supports a variety of methods of specifying specific test to
2693 # run or not run. These need to be documented...
2698 export base=`basetest $1`
2699 if [ ! -z "$ONLY" ]; then
2701 if [ ${!testname}x != x ]; then
2702 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2703 run_one_logged $1 "$2"
2707 if [ ${!testname}x != x ]; then
2708 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2709 run_one_logged $1 "$2"
2717 if [ ${!testname}x != x ]; then
2719 TESTNAME=test_$1 skip "skipping excluded test $1"
2722 testname=EXCEPT_$base
2723 if [ ${!testname}x != x ]; then
2725 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2728 testname=EXCEPT_SLOW_$1
2729 if [ ${!testname}x != x ]; then
2731 TESTNAME=test_$1 skip "skipping SLOW test $1"
2734 testname=EXCEPT_SLOW_$base
2735 if [ ${!testname}x != x ]; then
2737 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2742 run_one_logged $1 "$2"
2753 module_loaded lnet || load_modules
2765 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2770 strace -o $TMP/$1.strace -ttt $*
2772 log "FINISHED: $*: rc $RC"
2777 # Set TEST_STATUS here; will be used for logging the result
2778 if [ -f $LOGDIR/err ]; then
2783 echo $TEST_STATUS " " $@
2787 FFREE=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filesfree | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2788 FTOTAL=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filestotal | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2789 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
2793 echo -n "Resetting fail_loc on all nodes..."
2794 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
2800 # Log a message (on all nodes) padded with "=" before and after.
2801 # Also appends a timestamp and prepends the testsuite name.
2804 EQUALS="===================================================================================================="
2806 msg="== ${TESTSUITE} $*"
2808 [[ $last != "=" && $last != " " ]] && msg="$msg "
2809 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
2810 # always include at least == after the message
2811 log "$msg== $(date +"%H:%M:%S (%s)")"
2815 # Run a single test function and cleanup after it.
2817 # This function should be run in a subshell so the test func can
2818 # exit() without stopping the whole script.
2824 export tdir=d0.${TESTSUITE}/d${base}
2825 export TESTNAME=test_$testnum
2826 local SAVE_UMASK=`umask`
2829 banner "test $testnum: $message"
2830 test_${testnum} || error "test_$testnum failed with $?"
2833 check_grant ${testnum} || error "check_grant $testnum failed with $?"
2834 check_catastrophe || error "LBUG/LASSERT detected"
2835 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
2843 # Wrapper around run_one to ensure:
2844 # - test runs in subshell
2845 # - output of test is saved to separate log file for error reporting
2846 # - test result is saved to data file
2849 local BEFORE=`date +%s`
2851 local name=${TESTSUITE}.test_${1}.test_log.$(hostname).log
2852 local test_log=$LOGDIR/$name
2856 log_sub_test_begin test_${1}
2857 (run_one $1 "$2") 2>&1 | tee $test_log
2858 local RC=${PIPESTATUS[0]}
2860 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
2861 echo "test_$1 returned $RC" | tee $LOGDIR/err
2863 duration=$((`date +%s` - $BEFORE))
2864 pass "(${duration}s)"
2865 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
2866 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
2868 if [ -f $LOGDIR/err ]; then
2869 $FAIL_ON_ERROR && exit $RC
2876 (cd `dirname $1`; echo $PWD/`basename $1`)
2880 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
2881 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
2886 export base=`basetest $1`
2887 [ "$CHECK_GRANT" == "no" ] && return 0
2889 testname=GCHECK_ONLY_${base}
2890 [ ${!testname}x == x ] && return 0
2892 echo -n "checking grant......"
2894 # write some data to sync client lost_grant
2895 rm -f $DIR1/${tfile}_check_grant_* 2>&1
2896 for i in `seq $OSTCOUNT`; do
2897 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
2898 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
2899 count=1 > /dev/null 2>&1
2901 # sync all the data and make sure no pending data on server
2904 #get client grant and server grant
2906 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
2907 client_grant=$((client_grant + $d))
2910 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
2911 server_grant=$((server_grant + $d))
2914 # cleanup the check_grant file
2915 for i in `seq $OSTCOUNT`; do
2916 rm $DIR1/${tfile}_check_grant_$i
2919 #check whether client grant == server grant
2920 if [ $client_grant != $server_grant ]; then
2921 echo "failed: client:${client_grant} server: ${server_grant}"
2928 ########################
2934 ost=`echo $1 | awk -F_ '{print $3}'`
2935 if [ -z $ost ]; then
2936 ost=`echo $1 | sed 's/-osc.*//'`
2943 [ "$node" != "$(hostname)" ]
2949 for node in $(mdts_nodes); do
2950 remote_node $node && return 0
2957 [ "$CLIENTONLY" ] && return 0 || true
2958 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
2963 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
2964 MSKIPPED=1 && return 1
2971 for node in $(osts_nodes) ; do
2972 remote_node $node && return 0
2979 [ "$CLIENTONLY" ] && return 0 || true
2980 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2985 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
2986 OSKIPPED=1 && return 1
2993 MGS=$(facet_host mgs)
2994 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
2999 remote_mds_nodsh || remote_ost_nodsh || \
3000 $(single_local_node $(comma_list $(nodes_list)))
3006 for num in `seq $MDSCOUNT`; do
3007 MDSNODES="$MDSNODES $(facet_host mds$num)"
3009 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3015 remote_ost && remote_mds
3019 local OSTNODES=$(facet_host ost1)
3022 for num in `seq $OSTCOUNT`; do
3023 local myOST=$(facet_host ost$num)
3024 OSTNODES="$OSTNODES $myOST"
3026 NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
3032 # FIXME. We need a list of clients
3033 local myNODES=$HOSTNAME
3036 # CLIENTS (if specified) contains the local client
3037 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3039 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3040 myNODES="$myNODES $(osts_nodes) $(mdts_nodes)"
3043 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3048 remote_nodes_list () {
3049 local rnodes=$(nodes_list)
3050 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3054 init_clients_lists () {
3055 # Sanity check: exclude the local client from RCLIENTS
3056 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3058 # Sanity check: exclude the dup entries
3059 rclients=$(for i in $rclients; do echo $i; done | sort -u)
3061 local clients="$SINGLECLIENT $HOSTNAME $rclients"
3063 # Sanity check: exclude the dup entries from CLIENTS
3064 # for those configs which has SINGLCLIENT set to local client
3065 clients=$(for i in $clients; do echo $i; done | sort -u)
3067 CLIENTS=`comma_list $clients`
3068 local -a remoteclients=($rclients)
3069 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3070 varname=CLIENT$((i + 2))
3071 eval $varname=${remoteclients[i]}
3074 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3077 get_random_entry () {
3080 rnodes=${rnodes//,/ }
3082 local -a nodes=($rnodes)
3083 local num=${#nodes[@]}
3084 local i=$((RANDOM * num * 2 / 65536))
3090 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3095 lctl get_param version | grep -q patchless
3099 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3104 echo $nodes | wc -w || true
3108 local nodes=$(osts_nodes)
3109 local osscount=$(get_node_count "$nodes")
3110 [ ! "$OSTCOUNT" = "$osscount" ]
3114 local nodes=$(mdts_nodes)
3115 local mdtcount=$(get_node_count "$nodes")
3116 [ ! "$MDSCOUNT" = "$mdtcount" ]
3119 generate_machine_file() {
3120 local nodes=${1//,/ }
3121 local machinefile=$2
3123 for node in $nodes; do
3124 echo $node >>$machinefile || \
3125 { echo "can not generate machinefile $machinefile" && return 1; }
3130 local file=$1/stripe
3132 $LFS getstripe -v $file || error
3136 setstripe_nfsserver () {
3139 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3140 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3142 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3144 do_nodev $nfsserver lfs setstripe "$@"
3147 check_runas_id_ret() {
3149 local myRUNAS_UID=$1
3150 local myRUNAS_GID=$2
3153 if [ -z "$myRUNAS" ]; then
3154 error_exit "myRUNAS command must be specified for check_runas_id"
3157 $myRUNAS krb5_login.sh || \
3158 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3160 mkdir $DIR/d0_runas_test
3162 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3163 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3164 rm -rf $DIR/d0_runas_test
3169 local myRUNAS_UID=$1
3170 local myRUNAS_GID=$2
3173 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3174 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3175 Please set RUNAS_ID to some UID which exists on MDS and client or
3176 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3179 # obtain the UID/GID for MPI_USER
3183 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3184 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3186 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3187 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3190 # obtain and cache Kerberos ticket-granting ticket
3191 refresh_krb5_tgt() {
3192 local myRUNAS_UID=$1
3193 local myRUNAS_GID=$2
3196 if [ -z "$myRUNAS" ]; then
3197 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3200 CLIENTS=${CLIENTS:-$HOSTNAME}
3201 do_nodes $CLIENTS "set -x
3202 if ! $myRUNAS krb5_login.sh; then
3203 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3208 # Run multiop in the background, but wait for it to print
3209 # "PAUSING" to its stdout before returning from this function.
3210 multiop_bg_pause() {
3211 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3215 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3218 echo "$MULTIOP_PROG $FILE v$ARGS"
3219 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3221 echo "TMPPIPE=${TMPPIPE}"
3222 read -t 60 multiop_output < $TMPPIPE
3223 if [ $? -ne 0 ]; then
3228 if [ "$multiop_output" != "PAUSING" ]; then
3229 echo "Incorrect multiop output: $multiop_output"
3244 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3250 inodes_available () {
3251 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3255 mdsrate_inodes_available () {
3256 echo $(($(inodes_available) - 1))
3259 # reset llite stat counters
3260 clear_llite_stats(){
3261 lctl set_param -n llite.*.stats 0
3264 # sum llite stat items
3265 calc_llite_stats() {
3266 local res=$(lctl get_param -n llite.*.stats |
3267 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3271 # reset osc stat counters
3273 lctl set_param -n osc.*.osc_stats 0
3276 # sum osc stat items
3278 local res=$(lctl get_param -n osc.*.osc_stats |
3279 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3284 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3287 calc_osc_kbytes () {
3288 df $MOUNT > /dev/null
3289 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3292 # save_lustre_params(node, parameter_mask)
3293 # generate a stream of formatted strings (<node> <param name>=<param value>)
3294 save_lustre_params() {
3296 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3299 # restore lustre parameters from input stream, produces by save_lustre_params
3300 restore_lustre_params() {
3304 while IFS=" =" read node name val; do
3305 do_node ${node//:/} "lctl set_param -n $name $val"
3309 check_catastrophe() {
3310 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3311 local C=$CATASTROPHE
3312 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3314 if [ $rnodes ]; then
3315 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3316 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3332 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3334 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3335 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3336 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3340 # CMD: determine mds index where directory inode presents
3343 local file=$dir/f0.get_mds_dir_tmpfile
3348 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3349 local -a oldused=($iused)
3351 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3353 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3354 local -a newused=($iused)
3357 for ((i=0; i<${#newused[@]}; i++)); do
3358 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3364 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3367 mdsrate_cleanup () {
3369 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3374 delayed_recovery_enabled () {
3375 local var=${SINGLEMDS}_svc
3376 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3379 ########################
3381 convert_facet2label() {
3384 if [ x$facet = xost ]; then
3388 local varsvc=${facet}_svc
3390 if [ -n ${!varsvc} ]; then
3393 error "No lablel for $facet!"
3397 get_clientosc_proc_path() {
3403 get_lustre_version () {
3404 local node=${1:-"mds"}
3405 do_facet $node $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3408 get_mds_version_major () {
3409 local version=$(get_lustre_version mds)
3410 echo $version | awk -F. '{print $1}'
3413 get_mds_version_minor () {
3414 local version=$(get_lustre_version mds)
3415 echo $version | awk -F. '{print $2}'
3418 get_mdtosc_proc_path() {
3420 local major=$(get_mds_version_major)
3421 local minor=$(get_mds_version_minor)
3422 if [ $major -le 1 -a $minor -le 8 ] ; then
3425 echo "${ost}-osc-MDT0000"
3429 get_osc_import_name() {
3432 local label=$(convert_facet2label $ost)
3434 if [ "$facet" == "mds" ]; then
3435 get_mdtosc_proc_path $label
3439 get_clientosc_proc_path $label
3443 wait_import_state () {
3449 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3450 while [ "${CONN_STATE}" != "${expected}" ]; do
3451 if [ "${expected}" == "DISCONN" ]; then
3452 # for disconn we can check after proc entry is removed
3453 [ "x${CONN_STATE}" == "x" ] && return 0
3454 # with AT we can have connect request timeout ~ reconnect timeout
3455 # and test can't see real disconnect
3456 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3458 # disconnect rpc should be wait not more obd_timeout
3459 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3460 error "can't put import for $CONN_PROC into ${expected} state" && return 1
3462 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3466 log "$CONN_PROC now in ${CONN_STATE} state"
3470 wait_osc_import_state() {
3474 local ost=$(get_osc_import_name $facet $ost_facet)
3479 CONN_PROC="osc.${ost}.ost_server_uuid"
3480 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3481 while [ "${CONN_STATE}" != "${expected}" ]; do
3482 if [ "${expected}" == "DISCONN" ]; then
3483 # for disconn we can check after proc entry is removed
3484 [ "x${CONN_STATE}" == "x" ] && return 0
3485 # with AT we can have connect request timeout ~ reconnect timeout
3486 # and test can't see real disconnect
3487 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3489 # disconnect rpc should be wait not more obd_timeout
3490 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3491 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3493 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3497 log "${ost_facet} now in ${CONN_STATE} state"
3500 get_clientmdc_proc_path() {
3508 # Add paths to lustre tests for 32 and 64 bit systems.
3509 local RPATH="$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
3510 do_nodesv $list "PATH=$RPATH sh rpc.sh $@ "
3513 wait_clients_import_state () {
3519 local label=$(convert_facet2label $facet)
3522 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3523 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3524 *) error "unknown facet!" ;;
3527 if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
3528 error "import is not in ${expected} state"
3537 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
3538 $LCTL get_param obdfilter.*.kbytesavail))
3539 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
3540 $LCTL get_param -n obdfilter.*.tot_granted))
3541 for ((i=0; i<${#AVAILA[@]}; i++)); do
3542 local -a AVAIL1=(${AVAILA[$i]//=/ })
3543 GRANT=$((${GRANTA[$i]}/1024))
3544 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
3545 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
3551 do_facet mgs lctl pool_list $1
3555 local fsname=${1%%.*}
3556 local poolname=${1##$fsname.}
3558 do_facet mgs lctl pool_new $1
3560 # get param should return err unless pool is created
3561 [[ $RC -ne 0 ]] && return $RC
3563 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3564 2>/dev/null || echo foo" "" || RC=1
3565 if [[ $RC -eq 0 ]]; then
3568 error "pool_new failed $1"
3573 add_pool_to_list () {
3574 local fsname=${1%%.*}
3575 local poolname=${1##$fsname.}
3577 local listvar=${fsname}_CREATED_POOLS
3578 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
3581 remove_pool_from_list () {
3582 local fsname=${1%%.*}
3583 local poolname=${1##$fsname.}
3585 local listvar=${fsname}_CREATED_POOLS
3586 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
3589 destroy_pool_int() {
3591 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
3592 awk '$1 !~ /^Pool:/ {print $1}')
3593 for ost in $OSTS; do
3594 do_facet mgs lctl pool_remove $1 $ost
3596 do_facet mgs lctl pool_destroy $1
3599 # <fsname>.<poolname> or <poolname>
3601 local fsname=${1%%.*}
3602 local poolname=${1##$fsname.}
3604 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3608 pool_list $fsname.$poolname || return $?
3610 destroy_pool_int $fsname.$poolname
3612 [[ $RC -ne 0 ]] && return $RC
3614 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3615 2>/dev/null || echo foo" "foo" || RC=1
3617 if [[ $RC -eq 0 ]]; then
3618 remove_pool_from_list $fsname.$poolname
3620 error "destroy pool failed $1"
3626 local fsname=${1:-$FSNAME}
3628 local listvar=${fsname}_CREATED_POOLS
3632 [ x${!listvar} = x ] && return 0
3634 echo destroy the created pools: ${!listvar}
3635 for poolname in ${!listvar//,/ }; do
3636 destroy_pool $fsname.$poolname
3641 local fsname=${1:-$FSNAME}
3643 destroy_pools $fsname
3649 local ts=$(date +%s)
3651 # bug 20237, comment 11
3652 # It would also be useful to provide the option
3653 # of writing the file to an NFS directory so it doesn't need to be copied.
3656 [ -f $LOGDIR/shared ] && docp=false
3658 # dump lustre logs, dmesg
3660 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
3662 echo "Dumping lctl log to ${prefix}.*.${suffix}"
3664 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
3665 echo "Dumping logs only on local client."
3666 $LCTL dk > ${prefix}.debug_log.$(hostname).${suffix}
3667 dmesg > ${prefix}.dmesg.$(hostname).${suffix}
3672 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname).${suffix};
3673 dmesg > ${prefix}.dmesg.\\\$(hostname).${suffix}"
3674 if [ ! -f $LOGDIR/shared ]; then
3675 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
3678 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
3679 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
3685 local list=${1:-$(comma_list $(nodes_list))}
3687 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3699 for i in $(seq 0 $num_mntpts); do
3700 cmd="ls -laf ${mntpt_root}$i/$dir"
3706 for pid in $pids; do
3713 # target_start_and_reset_recovery_timer()
3714 # service_time = at_est2timeout(service_time);
3715 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3716 # INITIAL_CONNECT_TIMEOUT);
3717 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3718 #define CONNECTION_SWITCH_INC 1
3719 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3720 #define CONNECTION_SWITCH_MIN 5U
3722 max_recovery_time () {
3723 local init_connect_timeout=$(( TIMEOUT / 20 ))
3724 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3726 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3731 get_clients_mount_count () {
3732 local clients=${CLIENTS:-`hostname`}
3734 # we need to take into account the clients mounts and
3735 # exclude mds/ost mounts if any;
3736 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
3740 PROC_CLI="srpc_info"
3748 if [ $M -lt $N ]; then
3752 while [ $N -lt $M ]; do
3762 calc_connection_cnt() {
3765 # MDT->MDT = 2 * C(M, 2)
3769 comb_m2=$(combination $MDSCOUNT 2)
3771 local num_clients=$(get_clients_mount_count)
3773 local cnt_mdt2mdt=$((comb_m2 * 2))
3774 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
3775 local cnt_cli2ost=$((num_clients * OSTCOUNT))
3776 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
3777 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
3778 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
3779 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
3793 local cmd="$tgt.srpc.flavor"
3795 if [ $net == "any" ]; then
3800 if [ $dir != "any" ]; then
3805 log "Setting sptlrpc rule: $cmd"
3806 do_facet mgs "$LCTL conf_param $cmd"
3815 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
3816 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
3818 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
3820 if [ "x$bulkspec" != "x" ]; then
3821 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
3823 if [ "x$algs" != "x" ]; then
3824 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
3826 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
3827 if [ $bulk == "bulkn" ]; then
3828 bulk_count=`echo "$output" | grep "bulk flavor" \
3829 | grep "null/null" | wc -l`
3830 elif [ $bulk == "bulki" ]; then
3831 bulk_count=`echo "$output" | grep "bulk flavor" \
3832 | grep "/null" | grep -v "null/" | wc -l`
3834 bulk_count=`echo "$output" | grep "bulk flavor" \
3835 | grep -v "/null" | grep -v "null/" | wc -l`
3839 [ $bulk_count -lt $count ] && count=$bulk_count
3850 local clients=${CLIENTS:-`hostname`}
3852 for c in ${clients//,/ }; do
3853 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
3854 tmpcnt=`count_flvr "$output" $flavor`
3855 cnt=$((cnt + tmpcnt))
3865 local clients=${CLIENTS:-`hostname`}
3867 for c in ${clients//,/ }; do
3868 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
3869 tmpcnt=`count_flvr "$output" $flavor`
3870 cnt=$((cnt + tmpcnt))
3880 if [ $MDSCOUNT -le 1 ]; then
3885 for num in `seq $MDSCOUNT`; do
3886 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
3887 tmpcnt=`count_flvr "$output" $flavor`
3888 cnt=$((cnt + tmpcnt))
3898 for num in `seq $MDSCOUNT`; do
3899 output=`do_facet mds$num lctl get_param -n osc.*OST*-osc-MDT*.$PROC_CLI 2>/dev/null`
3900 tmpcnt=`count_flvr "$output" $flavor`
3901 cnt=$((cnt + tmpcnt))
3910 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
3911 count_flvr "$output" $flavor
3916 local dir=$1 # from to
3917 local flavor=$2 # flavor expected
3920 if [ $dir == "cli2mdt" ]; then
3921 res=`flvr_cnt_cli2mdt $flavor`
3922 elif [ $dir == "cli2ost" ]; then
3923 res=`flvr_cnt_cli2ost $flavor`
3924 elif [ $dir == "mdt2mdt" ]; then
3925 res=`flvr_cnt_mdt2mdt $flavor`
3926 elif [ $dir == "mdt2ost" ]; then
3927 res=`flvr_cnt_mdt2ost $flavor`
3928 elif [ $dir == "all2ost" ]; then
3929 res1=`flvr_cnt_mdt2ost $flavor`
3930 res2=`flvr_cnt_cli2ost $flavor`
3931 res=$((res1 + res2))
3932 elif [ $dir == "all2mdt" ]; then
3933 res1=`flvr_cnt_mdt2mdt $flavor`
3934 res2=`flvr_cnt_cli2mdt $flavor`
3935 res=$((res1 + res2))
3936 elif [ $dir == "all2all" ]; then
3937 res1=`flvr_cnt_mdt2ost $flavor`
3938 res2=`flvr_cnt_cli2ost $flavor`
3939 res3=`flvr_cnt_mdt2mdt $flavor`
3940 res4=`flvr_cnt_cli2mdt $flavor`
3941 res=$((res1 + res2 + res3 + res4))
3949 local dir=$1 # from to
3950 local flavor=$2 # flavor expected
3951 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
3955 for ((i=0;i<20;i++)); do
3956 echo -n "checking..."
3957 res=$(do_check_flavor $dir $flavor)
3958 if [ $res -eq $expect ]; then
3959 echo "found $res $flavor connections of $dir, OK"
3962 echo "found $res $flavor connections of $dir, not ready ($expect)"
3968 echo "Error checking $flavor of $dir: expect $expect, actual $res"
3972 restore_to_default_flavor()
3974 local proc="mgs.MGS.live.$FSNAME"
3976 echo "restoring to default flavor..."
3978 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3980 # remove all existing rules if any
3981 if [ $nrule -ne 0 ]; then
3982 echo "$nrule existing rules"
3983 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
3984 echo "remove rule: $rule"
3985 spec=`echo $rule | awk -F = '{print $1}'`
3986 do_facet mgs "$LCTL conf_param $spec="
3990 # verify no rules left
3991 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
3992 [ $nrule -ne 0 ] && error "still $nrule rules left"
3994 # wait for default flavor to be applied
3995 # currently default flavor for all connections are 'null'
3996 wait_flavor all2all null
3997 echo "now at default flavor settings"
4002 local flavor=${1:-null}
4004 echo "setting all flavor to $flavor"
4006 # FIXME need parameter to this fn
4007 # and remove global vars
4008 local cnt_all2all=$(calc_connection_cnt all2all)
4010 local res=$(do_check_flavor all2all $flavor)
4011 if [ $res -eq $cnt_all2all ]; then
4012 echo "already have total $res $flavor connections"
4016 echo "found $res $flavor out of total $cnt_all2all connections"
4017 restore_to_default_flavor
4019 [[ $flavor = null ]] && return 0
4021 set_rule $FSNAME any any $flavor
4022 wait_flavor all2all $flavor
4028 # Checking for shared logdir
4029 if [ ! -d $dir ]; then
4030 # Not found. Create local logdir
4033 touch $dir/node.$(hostname).yml
4038 check_write_access() {
4040 for node in $(nodes_list); do
4041 if [ ! -f "$dir/node.${node}.yml" ]; then
4042 # Logdir not accessible/writable from this node.
4050 if [[ -n $YAML_LOG ]]; then
4053 export YAML_LOG=${LOGDIR}/results.yml
4057 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $LOGDIR
4058 if check_write_access $LOGDIR; then
4059 touch $LOGDIR/shared
4060 echo "Logging to shared log directory: $LOGDIR"
4062 echo "Logging to local directory: $LOGDIR"
4065 yml_nodes_file $LOGDIR
4066 yml_results_file >> $YAML_LOG
4070 yml_log_test $1 >> $YAML_LOG
4074 yml_log_test_status $@ >> $YAML_LOG
4077 log_sub_test_begin() {
4078 yml_log_sub_test_begin $@ >> $YAML_LOG
4081 log_sub_test_end() {
4082 yml_log_sub_test_end $@ >> $YAML_LOG
4088 local devname=$(basename $1)
4089 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4090 # loop devices aren't in /proc/partitions
4091 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4093 size=$(($size / 1024 / 1024)) # Gb
4095 local partial_arg=""
4096 # Run in partial (fast) mode if the size
4097 # of a partition > 10 GB
4098 [ $size -gt 10 ] && partial_arg="-p"
4100 llverdev --force $partial_arg $dev
4103 remove_mdt_files() {
4108 local mntpt=${MOUNT%/*}/$facet
4110 echo "removing files from $mdtdev on $facet: $files"
4111 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4114 rm $mntpt/ROOT/$f || { rc=$?; break; }
4116 umount -f $mntpt || return $?
4120 duplicate_mdt_files() {
4125 local mntpt=${MOUNT%/*}/$facet
4127 echo "duplicating files on $mdtdev on $facet: $files"
4128 mkdir -p $mntpt || return $?
4129 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4139 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4140 pushd $mntpt/ROOT > /dev/null || return $?
4143 touch $f.bad || return $?
4144 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4146 [ $rc -eq 0 ] || return $rc
4147 setfattr --restore $tmp || return $?