2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4 trap 'print_summary && touch $TF_FAIL && \
5 echo "test-framework exiting on error"' ERR
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
13 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
14 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 #export PDSH="pdsh -S -Rssh -w"
17 # function used by scripts run on remote nodes
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
19 . $LUSTRE/tests/functions.sh
20 . $LUSTRE/tests/yaml.sh
22 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
24 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
26 if [ -f "$EXCEPT_LIST_FILE" ]; then
27 echo "Reading test skip list from $EXCEPT_LIST_FILE"
32 # check config files for options in decreasing order of preference
33 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
34 MODPROBECONF=/etc/modprobe.d/lustre.conf
35 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
36 MODPROBECONF=/etc/modprobe.d/Lustre
37 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
38 MODPROBECONF=/etc/modprobe.conf
42 [[ $DIR/ = $MOUNT/* ]] || \
43 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
44 [[ $DIR1/ = $MOUNT1/* ]] || \
45 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
46 [[ $DIR2/ = $MOUNT2/* ]] || \
47 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
49 [ -n "$failed" ] && exit 99 || true
53 echo "usage: $0 [-r] [-f cfgfile]"
61 [ "$TESTSUITE" == "lfsck" ] && return 0
62 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
64 local form="%-13s %-17s %-9s %s %s\n"
65 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
66 echo "------------------------------------------------------------------------------------"
67 for O in $DEFAULT_SUITES; do
68 [ "${!O}" = "no" ] && continue || true
69 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
70 local o=$(echo $O | tr "[:upper:]" "[:lower:]")
72 local log=${TMP}/${o}.log
73 if is_sanity_benchmark $o; then
74 log=${TMP}/sanity-benchmark.log
79 local status=Unfinished
81 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
82 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
83 total=$(grep duration $log | awk '{ print $2}')
84 if [ "${!O}" = "done" ]; then
88 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
89 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
92 printf "$form" $status "$O" "${total}" "E=$skipped"
93 printf "$form" "-" "-" "-" "S=$(echo $slow)"
96 for O in $DEFAULT_SUITES; do
97 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
98 if [ "${!O}" = "no" ]; then
100 # only for those tests suits which are run directly from acc-sm script:
101 # bonnie, iozone, etc.
102 if [ -f "$TESTSUITELOG" ] && grep FAIL $TESTSUITELOG | grep -q ' '$O ; then
103 printf "$form" "UNFINISHED" "$O" ""
105 printf "$form" "Skipped" "$O" ""
110 for O in $DEFAULT_SUITES; do
111 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
112 [ "${!O}" = "done" -o "${!O}" = "no" ] || \
113 printf "$form" "UNFINISHED" "$O" ""
118 export LUSTRE=`absolute_path $LUSTRE`
119 export TESTSUITE=`basename $0 .sh`
120 export TEST_FAILED=false
121 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
123 export MKE2FS=${MKE2FS:-mke2fs}
124 export DEBUGFS=${DEBUGFS:-debugfs}
125 export TUNE2FS=${TUNE2FS:-tune2fs}
126 export E2LABEL=${E2LABEL:-e2label}
127 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
128 export E2FSCK=${E2FSCK:-e2fsck}
129 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
131 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
132 export FSCK_MAX_ERR=4 # File system errors left uncorrected
135 #[ -d /r ] && export ROOT=${ROOT:-/r}
136 export TMP=${TMP:-$ROOT/tmp}
137 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
138 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
139 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
141 export HOSTNAME=${HOSTNAME:-`hostname -s`}
142 if ! echo $PATH | grep -q $LUSTRE/utils; then
143 export PATH=$PATH:$LUSTRE/utils
145 if ! echo ":$PATH:" | grep -q ":$LUSTRE/tests:"; then
146 export PATH=$LUSTRE/tests:$PATH
148 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
149 export PATH=$PATH:$LUSTRE/../lustre-iokit/sgpdd-survey
151 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
152 [ ! -f "$LST" ] && export LST=$(which lst)
153 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
154 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
155 # Ubuntu, at least, has a truncate command in /usr/bin
156 # so fully path our truncate command.
157 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
158 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
159 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
160 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
161 export PATH=$LUSTRE/tests/racer:$PATH:
163 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
164 export PATH=$PATH:$LUSTRE/tests/mpi
166 export RSYNC_RSH=${RSYNC_RSH:-rsh}
167 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
168 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
169 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
170 [ ! -f "$LFS" ] && export LFS=$(which lfs)
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}
181 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
183 if [ "$ACCEPTOR_PORT" ]; then
184 export PORT_OPT="--port $ACCEPTOR_PORT"
187 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
189 # Paths on remote nodes, if different
190 export RLUSTRE=${RLUSTRE:-$LUSTRE}
191 export RPWD=${RPWD:-$PWD}
192 export I_MOUNTED=${I_MOUNTED:-"no"}
193 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
194 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
195 ! -f `dirname $0`/../mds/mds.ko ]; then
196 export CLIENTMODSONLY=yes
199 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
203 while getopts "rvwf:" opt $*; do
206 r) REFORMAT=--reformat;;
208 w) WRITECONF=writeconf;;
213 shift $((OPTIND - 1))
216 # print the durations of each test if "true"
217 DDETAILS=${DDETAILS:-false}
218 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
224 *) EXT=".ko"; USE_QUOTA=yes;;
228 do_facet mgs lctl pool_list $1
232 local fsname=${1%%.*}
233 local poolname=${1##$fsname.}
235 do_facet mgs lctl pool_new $1
237 # get param should return err unless pool is created
238 [[ $RC -ne 0 ]] && return $RC
240 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
241 2>/dev/null || echo foo" "" || RC=1
242 if [[ $RC -eq 0 ]]; then
245 error "pool_new failed $1"
250 add_pool_to_list () {
251 local fsname=${1%%.*}
252 local poolname=${1##$fsname.}
254 local listvar=${fsname}_CREATED_POOLS
255 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
258 remove_pool_from_list () {
259 local fsname=${1%%.*}
260 local poolname=${1##$fsname.}
262 local listvar=${fsname}_CREATED_POOLS
263 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
267 /sbin/lsmod | grep -q $1
273 BASE=`basename $module $EXT`
275 module_loaded ${BASE} && return
277 if [ "$BASE" == "lnet_selftest" ] && \
278 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
279 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
281 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
282 insmod ${LUSTRE}/${module}${EXT} $@
284 # must be testing a "make install" or "rpm" installation
289 load_module_llite_lloop() {
290 local n1=$(uname -r | cut -d. -f1)
291 local n2=$(uname -r | cut -d. -f2)
292 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
294 # load the llite_lloop module for < 2.6.32 kernels
295 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
296 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]]; then
297 load_module llite/llite_lloop
301 load_modules_local() {
302 if [ -n "$MODPROBE" ]; then
306 if [ "$HAVE_MODULES" = true ]; then
312 echo Loading modules from $LUSTRE
313 load_module ../lnet/libcfs/libcfs
314 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
315 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
316 [ -z "$LNETOPTS" -a "$MODPROBECONF" ] && \
317 LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
318 echo $LNETOPTS | grep -q "accept=all" || LNETOPTS="$LNETOPTS accept=all";
320 # disable it for now since it only hides the stack overflow upon test w/
322 # if [ "$NETTYPE" = "tcp" -o "$NETTYPE" = "o2ib" -o "$NETTYPE" = "ptl" ]; then
323 # echo $LNETOPTS | grep -q "local_nid_dist_zero=0" ||
324 # LNETOPTS="$LNETOPTS local_nid_dist_zero=0"
326 echo "lnet options: '$LNETOPTS'"
327 # note that insmod will ignore anything in modprobe.conf
328 load_module ../lnet/lnet/lnet $LNETOPTS
329 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
330 load_module ../lnet/klnds/$LNETLND
331 load_module lvfs/lvfs
332 load_module obdclass/obdclass
333 load_module ptlrpc/ptlrpc
334 [ "$USE_QUOTA" = "yes" ] && load_module quota/lquota $LQUOTAOPTS
339 if ! client_only; then
342 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
343 grep -q -w jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
344 grep -q -w jbd2 /proc/kallsyms || { modprobe jbd2 2>/dev/null || true; }
345 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
346 load_module lvfs/fsfilt_$FSTYPE
348 load_module obdfilter/obdfilter
351 load_module llite/lustre
352 load_module_llite_lloop
353 rm -f $TMP/ogdb-$HOSTNAME
355 [ -d /r ] && OGDB="/r/tmp"
356 $LCTL modules > $OGDB/ogdb-$HOSTNAME
357 # 'mount' doesn't look in $PATH, just sbin
358 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
364 # load modules on remote nodes optionally
365 # lustre-tests have to be installed on these nodes
366 if $LOAD_MODULES_REMOTE ; then
367 local list=$(comma_list $(remote_nodes_list))
368 echo loading modules on $list
369 do_rpc_nodes $list load_modules
374 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
375 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
376 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
377 echo "$LEAK_LUSTRE" 1>&2
378 echo "$LEAK_PORTALS" 1>&2
379 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
380 echo "Memory leaks detected"
381 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
387 wait_exit_ST client # bug 12845
389 if $LOAD_MODULES_REMOTE ; then
390 local list=$(comma_list $(remote_nodes_list))
391 if [ ! -z $list ]; then
392 echo unloading modules on $list
393 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
394 do_rpc_nodes $list check_mem_leak
398 $LUSTRE_RMMOD $FSTYPE || return 2
402 check_mem_leak || return 254
404 echo "modules unloaded."
409 # This and set_obdfilter_param() shall be used to access OBDFilter parameters
410 # moved to OSD in 2.3, 2.4, or later server versions.
415 # writethrough_cache_enable
417 get_obdfilter_param() {
419 local device=${2:-$FSNAME-OST*}
422 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
423 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
426 set_obdfilter_param() {
428 local device=${2:-$FSNAME-OST*}
432 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
433 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
437 local dz=${1:-$DEBUG_SIZE}
439 if [ -f /sys/devices/system/cpu/possible ]; then
440 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
442 local cpus=$(getconf _NPROCESSORS_CONF)
445 # bug 19944, adjust size to be -gt num_possible_cpus()
446 # promise 2MB for every cpu at least
447 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
450 lctl set_param debug_mb=$dz
453 set_default_debug () {
454 local debug=${1:-"$PTLDEBUG"}
455 local subsystem_debug=${2:-"$SUBSYSTEM"}
456 local debug_size=${3:-$DEBUG_SIZE}
458 lctl set_param debug="$debug"
459 lctl set_param subsystem_debug="${subsystem_debug# }"
461 set_debug_size $debug_size
465 set_default_debug_nodes () {
468 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
469 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
473 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
474 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
477 set_default_debug_facet () {
479 local node=$(facet_active_host $facet)
480 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
482 set_default_debug_nodes $node
487 local facets=${1:-$(get_facets)}
490 for facet in ${facets//,/ }; do
491 mount_facet $facet || error "Restart of $facet failed!"
498 local dev=$(facet_active $facet)_dev
499 local opt=${facet}_opt
500 local mntpt=$(facet_mntpt $facet)
502 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
503 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
505 if [ $RC -ne 0 ]; then
506 echo "mount -t lustre $@ ${!dev} $mntpt"
507 echo "Start of ${!dev} on ${facet} failed ${RC}"
509 set_default_debug_facet $facet
511 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
512 [ -z "$label" ] && echo no label for ${!dev} && exit 1
513 eval export ${facet}_svc=${label}
514 echo Started ${label}
519 # start facet device options
525 eval export ${facet}_dev=${device}
526 eval export ${facet}_opt=\"$@\"
528 local varname=${facet}failover_dev
529 if [ -n "${!varname}" ] ; then
530 eval export ${facet}failover_dev=${!varname}
532 eval export ${facet}failover_dev=$device
535 local mntpt=$(facet_mntpt $facet)
536 do_facet ${facet} mkdir -p $mntpt
537 eval export ${facet}_MOUNT=$mntpt
547 local HOST=`facet_active_host $facet`
548 [ -z $HOST ] && echo stop: no host for $facet && return 0
550 local mntpt=$(facet_mntpt $facet)
551 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
552 if [ ${running} -ne 0 ]; then
553 echo "Stopping $mntpt (opts:$@)"
554 do_facet ${facet} umount -d $@ $mntpt
557 # umount should block, but we should wait for unrelated obd's
558 # like the MGS or MGC to also stop.
560 wait_exit_ST ${facet}
563 # set quota version (both administrative and operational quotas)
565 # XXX This function is kept for interoperability with old server (< 2.3.50),
566 # it should be removed whenever we drop the interoperability for such
568 quota_set_version() {
569 do_facet mds "lctl set_param lquota.${FSNAME}-MDT*.quota_type=$1"
571 local osts=$(get_facets OST)
572 for ost in ${osts//,/ }; do
574 do_facet $ost "lctl set_param lquota.${!varsvc}.quota_type=$1"
578 # save quota version (both administrative and operational quotas)
579 # the function will also switch to the new version and the new type
581 # XXX This function is kept for interoperability with old server (< 2.3.50),
582 # it should be removed whenever we drop the interoperability for such
584 quota_save_version() {
586 local ver=$(tr -c -d "123" <<< $spec)
587 local type=$(tr -c -d "ug" <<< $spec)
589 local lustre_version=$(get_lustre_version mds)
590 if [[ $lustre_version = 1.8* ]] ; then
591 $LFS quotaoff -ug $MOUNT # just in case
592 [ -n "$ver" ] && quota_set_version $ver
594 echo mds running $lustre_version
595 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
599 { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
601 do_facet mgs "lctl conf_param $FSNAME-MDT*.$(get_md_name).quota_type=$spec"
603 local osts=$(get_facets OST)
604 for ost in ${osts//,/ }; do
606 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
610 # client could mount several lustre
612 # XXX This function is kept for interoperability with old server (< 2.3.50),
613 # it should be removed whenever we drop the interoperability for such
616 local fsname=${1:-$FSNAME}
618 do_facet mds lctl get_param md*.${fsname}-MDT*.quota_type ||
620 do_nodes $(comma_list $(osts_nodes)) \
621 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
625 # XXX This function is kept for interoperability with old server (< 2.3.50),
626 # it should be removed whenever we drop the interoperability for such
628 restore_quota_old() {
629 local mntpt=${1:-$MOUNT}
630 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
631 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
634 quota_save_version $old_QUOTA_TYPE
637 # XXX This function is kept for interoperability with old server (< 2.3.50),
638 # it should be removed whenever we drop the interoperability for such
644 # 1. run quotacheck only if quota is off
645 # 2. save the original quota_type params, restore them after testing
647 # Suppose that quota type the same on mds and ost
648 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
649 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
650 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
651 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
652 export old_QUOTA_TYPE=$quota_type
653 quota_save_version $QUOTA_TYPE
656 local quota_usrs=$QUOTA_USERS
658 # get_filesystem_size
659 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
660 local blk_soft=$((disksz + 1024))
661 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
663 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
665 local i_hard=$((i_soft + i_soft / 20))
667 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
668 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
671 for usr in $quota_usrs; do
672 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
674 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
676 eval $cmd || error "$cmd FAILED!"
678 # display the quota status
679 echo "Quota settings for $usr : "
680 $LFS quota -v -u $usr $mntpt || true
687 do_facet mds $LCTL get_param -n \
688 osd-$FSTYPE.${!varsvc}.quota_slave.enabled
693 # All OSTs should have same quota type
694 local varsvc=ost1_svc
695 do_facet ost1 $LCTL get_param -n \
696 osd-$FSTYPE.${!varsvc}.quota_slave.enabled
699 # restore old quota type settings
701 if [ $(lustre_version_code mds) -lt $(version_code 2.3.50) ]; then
706 if [ "$old_MDT_QUOTA_TYPE" ]; then
707 do_facet mgs $LCTL conf_param \
708 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
711 if [ "$old_OST_QUOTA_TYPE" ]; then
712 do_facet mgs $LCTL conf_param \
713 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
718 if [ $(lustre_version_code mds) -lt $(version_code 2.3.50) ]; then
725 # save old quota type & set new quota type
726 local mdt_qtype=$(mdt_quota_type)
727 local ost_qtype=$(ost_quota_type)
729 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
730 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
732 export old_MDT_QUOTA_TYPE=$mdt_qtype
733 export old_OST_QUOTA_TYPE=$ost_qtype
735 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
736 error "set mdt quota type failed"
737 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
738 error "set ost quota type failed"
740 local quota_usrs=$QUOTA_USERS
742 # get_filesystem_size
743 local disksz=$(lfs df $mntpt | grep "filesystem summary:" |
745 local blk_soft=$((disksz + 1024))
746 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
748 local inodes=$(lfs df -i $mntpt | grep "filesystem summary:" |
751 local i_hard=$((i_soft + i_soft / 20))
753 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
754 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
755 "inode-hardlimit: $i_hard"
758 for usr in $quota_usrs; do
759 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
761 cmd="$LFS setquota -$type $usr -b $blk_soft"
762 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
764 eval $cmd || error "$cmd FAILED!"
766 # display the quota status
767 echo "Quota settings for $usr : "
768 $LFS quota -v -u $usr $mntpt || true
775 local OPTIONS=${3:-$MOUNTOPT}
777 local device=$MGSNID:/$FSNAME
778 if [ -z "$mnt" -o -z "$FSNAME" ]; then
779 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
783 echo "Starting client: $client: $OPTIONS $device $mnt"
784 do_node $client mkdir -p $mnt
785 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
786 set_default_debug_nodes $client
799 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
800 if [ $running -ne 0 ]; then
801 echo "Stopping client $client $mnt (opts:$force)"
802 do_node $client lsof -t $mnt || need_kill=no
803 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
804 pids=$(do_node $client lsof -t $mnt | sort -u);
805 if [ -n $pids ]; then
806 do_node $client kill -9 $pids || true
810 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
811 if [ $busy -ne 0 ] ; then
812 echo "$mnt is still busy, wait one second" && sleep 1
813 do_node $client umount $force $mnt
818 # nodes is comma list
819 sanity_mount_check_nodes () {
825 # FIXME: assume that all cluster nodes run the same os
826 [ "$(uname)" = Linux ] || return 0
829 for mnt in $mnts ; do
830 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
831 mpts=\\\$(mount | grep -c $mnt' ');
832 if [ \\\$running -ne \\\$mpts ]; then
833 echo \\\$(hostname) env are INSANE!;
841 sanity_mount_check_servers () {
843 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
844 echo Checking servers environments
846 # FIXME: modify get_facets to display all facets wo params
847 local facets="$(get_facets OST),$(get_facets MDS),mgs"
851 for facet in ${facets//,/ }; do
852 node=$(facet_host ${facet})
853 mntpt=$(facet_mntpt $facet)
854 sanity_mount_check_nodes $node $mntpt ||
855 { error "server $node environments are insane!"; return 1; }
859 sanity_mount_check_clients () {
860 local clients=${1:-$CLIENTS}
861 local mntpt=${2:-$MOUNT}
862 local mntpt2=${3:-$MOUNT2}
864 [ -z $clients ] && clients=$(hostname)
865 echo Checking clients $clients environments
867 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
868 error "clients environments are insane!"
871 sanity_mount_check () {
872 sanity_mount_check_servers || return 1
873 sanity_mount_check_clients || return 2
876 # mount clients if not mouted
877 zconf_mount_clients() {
880 local OPTIONS=${3:-$MOUNTOPT}
882 local device=$MGSNID:/$FSNAME
883 if [ -z "$mnt" -o -z "$FSNAME" ]; then
884 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
888 echo "Starting client $clients: $OPTIONS $device $mnt"
891 running=\\\$(mount | grep -c $mnt' ');
893 if [ \\\$running -eq 0 ] ; then
895 mount -t lustre $OPTIONS $device $mnt;
900 echo "Started clients $clients: "
901 do_nodes $clients "mount | grep $mnt' '"
903 set_default_debug_nodes $clients
908 zconf_umount_clients() {
915 echo "Stopping clients: $clients $mnt (opts:$force)"
916 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
917 if [ \\\$running -ne 0 ] ; then
918 echo Stopping client \\\$(hostname) $mnt opts:$force;
919 lsof -t $mnt || need_kill=no;
920 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
921 pids=\\\$(lsof -t $mnt | sort -u);
922 if [ -n \\\"\\\$pids\\\" ]; then
926 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
927 if [ \\\$busy -ne 0 ] ; then
928 echo "$mnt is still busy, wait one second" && sleep 1;
936 echo + $POWER_DOWN $node
940 shutdown_node_hard () {
942 local attempts=$SHUTDOWN_ATTEMPTS
944 for i in $(seq $attempts) ; do
947 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
948 echo "waiting for $host to fail attempts=$attempts"
949 [ $i -lt $attempts ] || \
950 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
956 local mnt=${2:-$MOUNT}
959 if [ "$FAILURE_MODE" = HARD ]; then
960 shutdown_node_hard $client
962 zconf_umount_clients $client $mnt -f
968 local facets="$(get_facets OST),$(get_facets MDS)"
971 combined_mgs_mds || facets="$facets,mgs"
973 for facet in ${facets//,/ }; do
974 if [ $(facet_active_host $facet) == $host ]; then
975 affected="$affected $facet"
979 echo $(comma_list $affected)
984 local host=${2:-$(facet_host $facet)}
986 local label=$(convert_facet2label $facet)
987 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
990 facets_up_on_host () {
992 local facets=$(facets_on_host $host)
995 for facet in ${facets//,/ }; do
996 if $(facet_up $facet $host); then
997 affected_up="$affected_up $facet"
1001 echo $(comma_list $affected_up)
1007 if [ "$FAILURE_MODE" = HARD ]; then
1008 shutdown_node_hard $(facet_active_host $facet)
1016 echo + $POWER_UP $node
1029 if [ "$FAILURE_MODE" = HARD ]; then
1030 reboot_node $(facet_active_host $facet)
1038 if [ "$FAILURE_MODE" = HARD ]; then
1048 for facet in ${facets//,/ }; do
1049 hosts=$(expand_list $hosts $(facet_host $facet) )
1055 _check_progs_installed () {
1059 for prog in $progs; do
1060 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1061 echo $prog missing on $(hostname)
1068 check_progs_installed () {
1072 do_rpc_nodes $nodes _check_progs_installed $@
1076 local node=${1//./_}
1080 start_client_load() {
1083 local var=$(node_var_name $client)_load
1084 eval export ${var}=$load
1086 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1087 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1088 END_RUN_FILE=$END_RUN_FILE \
1089 LOAD_PID_FILE=$LOAD_PID_FILE \
1090 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1091 TESTNAME=$TESTNAME \
1092 DBENCH_LIB=$DBENCH_LIB \
1093 DBENCH_SRC=$DBENCH_SRC \
1096 log "Started client load: ${load} on $client"
1098 # get the children process IDs
1099 local pids=$(ps --ppid $ppid -o pid= | xargs)
1100 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1104 start_client_loads () {
1105 local -a clients=(${1//,/ })
1106 local numloads=${#CLIENT_LOADS[@]}
1109 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1110 testnum=$((nodenum % numloads))
1111 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1113 # bug 22169: wait the background threads to start
1117 # only for remote client
1118 check_client_load () {
1120 local var=$(node_var_name $client)_load
1121 local TESTLOAD=run_${!var}.sh
1123 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1125 # bug 18914: try to connect several times not only when
1126 # check ps, but while check_catastrophe also
1129 while [ $RC = 254 -a $tries -gt 0 ]; do
1133 if ! check_catastrophe $client; then
1135 if [ $RC -eq 254 ]; then
1136 # FIXME: not sure how long we shuold sleep here
1140 echo "check catastrophe failed: RC=$RC "
1145 # We can continue try to connect if RC=254
1146 # Just print the warning about this
1147 if [ $RC = 254 ]; then
1148 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1151 # see if the load is still on the client
1154 while [ $RC = 254 -a $tries -gt 0 ]; do
1158 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1163 if [ $RC = 254 ]; then
1164 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1165 # see if we can diagnose a bit why this is
1170 check_client_loads () {
1171 local clients=${1//,/ }
1175 for client in $clients; do
1176 check_client_load $client
1178 if [ "$rc" != 0 ]; then
1179 log "Client load failed on node $client, rc=$rc"
1185 restart_client_loads () {
1186 local clients=${1//,/ }
1187 local expectedfail=${2:-""}
1191 for client in $clients; do
1192 check_client_load $client
1194 if [ "$rc" != 0 -a "$expectedfail" ]; then
1195 local var=$(node_var_name $client)_load
1196 start_client_load $client ${!var}
1197 echo "Restarted client load ${!var}: on $client. Checking ..."
1198 check_client_load $client
1200 if [ "$rc" != 0 ]; then
1201 log "Client load failed to restart on node $client, rc=$rc"
1202 # failure one client load means test fail
1203 # we do not need to check other
1212 # Start vmstat and save its process ID in a file.
1217 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1220 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1221 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1224 # Display the nodes on which client loads failed.
1225 print_end_run_file() {
1229 [ -s $file ] || return 0
1231 echo "Found the END_RUN_FILE file: $file"
1234 # A client load will stop if it finds the END_RUN_FILE file.
1235 # That does not mean the client load actually failed though.
1236 # The first node in END_RUN_FILE is the one we are interested in.
1239 if [ -n "$node" ]; then
1240 local var=$(node_var_name $node)_load
1242 local prefix=$TESTLOG_PREFIX
1243 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1244 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1245 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1247 echo "Client load ${!var} failed on node $node:"
1253 # Stop the process which had its PID saved in a file.
1258 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1260 do_nodes $nodes "test -f $pid_file &&
1261 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1264 # Stop all client loads.
1265 stop_client_loads() {
1266 local nodes=${1:-$CLIENTS}
1269 # stop the client loads
1270 stop_process $nodes $pid_file
1272 # clean up the processes that started them
1273 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1276 # verify that lustre actually cleaned up properly
1278 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1279 error "LBUG/LASSERT detected"
1280 BUSY=`dmesg | grep -i destruct || true`
1281 if [ "$BUSY" ]; then
1283 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1287 check_mem_leak || exit 204
1289 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1290 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1292 if module_loaded lnet || module_loaded libcfs; then
1293 echo "$0: modules still loaded..." 1>&2
1310 RESULT=$(do_node $node "$TEST")
1311 if [ "$RESULT" == "$FINAL" ]; then
1312 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1315 [ $WAIT -ge $MAX ] && break
1316 echo "Waiting $((MAX - WAIT)) secs for update"
1317 WAIT=$((WAIT + sleep))
1320 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1324 wait_update_facet () {
1327 wait_update $(facet_active_host $facet) "$@"
1331 if [ $(lustre_version_code mds) -ge $(version_code 2.2.58) ]; then
1332 do_nodes $(comma_list $(osts_nodes)) \
1333 "lctl set_param -n osd*.*OS*.force_sync 1 2>&1" |
1334 grep -v 'Found no match' || true
1338 wait_delete_completed_mds() {
1339 [[ $(lustre_version_code mds) -lt $(version_code 2.2.58) ]] &&
1342 local MAX_WAIT=${1:-20}
1344 local stime=`date +%s`
1349 # find MDS with pending deletions
1350 for node in $(mdts_nodes); do
1351 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
1352 2>/dev/null | calc_sum)
1353 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
1356 mds2sync="$mds2sync $node"
1358 if [ "$mds2sync" == "" ]; then
1361 mds2sync=$(comma_list $mds2sync)
1363 # sync MDS transactions
1364 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
1366 # wait till all changes are sent and commmitted by OSTs
1367 # for ldiskfs space is released upon execution, but DMU
1368 # do this upon commit
1371 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1372 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
1374 #echo "$node: $changes changes on all"
1375 if [ "$changes" -eq "0" ]; then
1377 #echo "delete took $((etime - stime)) seconds"
1385 echo "Delete is not completed in $((etime - stime)) seconds"
1386 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
1392 # we can use "for" here because we are waiting the slowest
1393 for host in ${hostlist//,/ }; do
1394 check_network "$host" 900
1396 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1403 for facet in ${facetlist//,/ }; do
1404 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1406 wait_for_host $hostlist
1409 _wait_recovery_complete () {
1412 # Use default policy if $2 is not passed by caller.
1413 local MAX=${2:-$(max_recovery_time)}
1418 while [ $WAIT -lt $MAX ]; do
1419 STATUS=$(lctl get_param -n $param | grep status)
1421 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1424 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1426 echo "$param recovery not done in $MAX sec. $STATUS"
1430 wait_recovery_complete () {
1433 # with an assumption that at_max is the same on all nodes
1434 local MAX=${2:-$(max_recovery_time)}
1437 if [ "$FAILURE_MODE" = HARD ]; then
1438 facets=$(facets_on_host $(facet_active_host $facet))
1440 echo affected facets: $facets
1442 # we can use "for" here because we are waiting the slowest
1443 for facet in ${facets//,/ }; do
1444 local var_svc=${facet}_svc
1445 local param="*.${!var_svc}.recovery_status"
1447 local host=$(facet_active_host $facet)
1448 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1452 wait_mds_ost_sync () {
1453 # just because recovery is done doesn't mean we've finished
1454 # orphan cleanup. Wait for llogs to get synchronized.
1455 echo "Waiting for orphan cleanup..."
1456 # MAX value includes time needed for MDS-OST reconnection
1457 local MAX=$(( TIMEOUT * 2 ))
1459 while [ $WAIT -lt $MAX ]; do
1460 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1461 "$LCTL get_param -n obdfilter.*.mds_sync"))
1463 for ((i=0; i<${#sync[@]}; i++)); do
1464 [ ${sync[$i]} -eq 0 ] && continue
1465 # there is a not finished MDS-OST synchronization
1469 sleep 2 # increase waiting time and cover statfs cache
1470 [ ${con} -eq 1 ] && return 0
1471 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1474 echo "$facet recovery not done in $MAX sec. $STATUS"
1478 wait_destroy_complete () {
1479 echo "Waiting for local destroys to complete"
1480 # MAX value shouldn't be big as this mean server responsiveness
1481 # never increase this just to make test pass but investigate
1482 # why it takes so long time
1485 while [ $WAIT -lt $MAX ]; do
1486 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1490 for ((i=0; i<${#RPCs[@]}; i++)); do
1491 [ ${RPCs[$i]} -eq 0 ] && continue
1492 # there are still some destroy RPCs in flight
1497 [ ${con} -eq 1 ] && return 0 # done waiting
1498 echo "Waiting ${WAIT}s for local destroys to complete"
1501 echo "Local destroys weren't done in $MAX sec."
1505 wait_delete_completed() {
1506 wait_delete_completed_mds $1 || return $?
1507 wait_destroy_complete
1516 # conf-sanity 31 takes a long time cleanup
1517 while [ $WAIT -lt 300 ]; do
1518 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1519 [ -z "${running}" ] && return 0
1520 echo "waited $WAIT for${running}"
1521 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1523 WAIT=$((WAIT + INTERVAL))
1525 echo "service didn't stop after $WAIT seconds. Still running:"
1530 wait_remote_prog () {
1536 [ "$PDSH" = "no_dsh" ] && return 0
1538 while [ $WAIT -lt $2 ]; do
1539 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1540 [ -z "${running}" ] && return 0 || true
1541 echo "waited $WAIT for: "
1543 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1545 WAIT=$((WAIT + INTERVAL))
1547 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1548 [ -z "$pids" ] && return 0
1549 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1550 # FIXME: not portable
1551 for pid in $pids; do
1552 cat /proc/${pid}/status || true
1553 cat /proc/${pid}/wchan || true
1555 kill -9 $pid || true
1564 # not every config has many clients
1566 if [ -n "$CLIENTS" ]; then
1567 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1569 stat -f $MOUNT > /dev/null
1575 # usually checked on particular client or locally
1577 if [ ! -z "$client" ]; then
1578 $PDSH $client "stat -f $MOUNT" > /dev/null
1580 stat -f $MOUNT > /dev/null
1588 client_reconnect() {
1589 uname -n >> $MOUNT/recon
1590 if [ -z "$CLIENTS" ]; then
1591 df $MOUNT; uname -n >> $MOUNT/recon
1593 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1595 echo Connected clients:
1597 ls -l $MOUNT/recon > /dev/null
1601 affected_facets () {
1604 local host=$(facet_active_host $facet)
1605 local affected=$facet
1607 if [ "$FAILURE_MODE" = HARD ]; then
1608 affected=$(facets_up_on_host $host)
1616 local host=$(facet_active_host $facet)
1618 echo "Failing $facet on node $host"
1620 local affected=$(affected_facets $facet)
1622 shutdown_facet $facet
1624 echo affected facets: $affected
1626 [ -n "$sleep_time" ] && sleep $sleep_time
1631 RECOVERY_START_TIME=`date +%s`
1632 echo "df pid is $dfpid"
1634 change_active $affected
1636 wait_for_facet $affected
1637 # start mgs first if it is affected
1638 if ! combined_mgs_mds && list_member $affected mgs; then
1639 mount_facet mgs || error "Restart of mgs failed"
1641 # FIXME; has to be changed to mount all facets concurrently
1642 affected=$(exclude_items_from_list $affected mgs)
1643 mount_facets $affected
1652 do_facet $facet sync
1654 local svc=${facet}_svc
1655 do_facet $facet $LCTL --device %${!svc} notransno
1656 do_facet $facet $LCTL --device %${!svc} readonly
1657 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1658 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1661 replay_barrier_nodf() {
1662 local facet=$1 echo running=${running}
1663 do_facet $facet sync
1664 local svc=${facet}_svc
1665 echo Replay barrier on ${!svc}
1666 do_facet $facet $LCTL --device %${!svc} notransno
1667 do_facet $facet $LCTL --device %${!svc} readonly
1668 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1669 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1672 mds_evict_client() {
1673 UUID=`lctl get_param -n mdc.${mds_svc}-mdc-*.uuid`
1674 local mdtdevice=$(get_mds_mdt_device_proc_path)
1675 do_facet mds "lctl set_param -n ${mdtdevice}.${mds_svc}.evict_client $UUID"
1678 ost_evict_client() {
1679 UUID=`lctl get_param -n osc.${ost1_svc}-osc-*.uuid`
1680 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1684 facet_failover $* || error "failover: $?"
1685 clients_up || error "post-failover df: $?"
1690 facet_failover $facet
1696 change_active $facet
1697 wait_for_facet $facet
1698 mount_facet $facet -o abort_recovery
1699 clients_up || echo "first df failed: $?"
1700 clients_up || error "post-failover df: $?"
1704 echo There is no lmc. This is mountconf, baby.
1709 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1710 ID=`$PDSH $1 $GMNALNID -l | cut -d\ -f2`
1716 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1722 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1723 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1724 if [ -z "$ID" ]; then
1725 echo "Could not get a ptl id for $1..."
1734 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1741 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1742 if type __h2elan >/dev/null 2>&1; then
1745 ID=`echo $1 | sed 's/[^0-9]*//g'`
1753 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1754 ID=`echo $1 | sed 's/[^0-9]*//g'`
1758 declare -fx h2openib
1761 h2name_or_ip "$1" "o2ib"
1768 [ "$facet" == client ] && echo -n $HOSTNAME && return
1769 varname=${facet}_HOST
1770 if [ -z "${!varname}" ]; then
1771 if [ "${facet:0:3}" == "ost" ]; then
1772 eval ${facet}_HOST=${ost_HOST}
1780 local activevar=${facet}active
1782 if [ -f $TMP/${facet}active ] ; then
1783 source $TMP/${facet}active
1786 active=${!activevar}
1787 if [ -z "$active" ] ; then
1794 facet_active_host() {
1796 local active=`facet_active $facet`
1797 if [ "$facet" == client ]; then
1800 echo `facet_host $active`
1808 facetlist=$(exclude_items_from_list $facetlist mgs)
1810 for facet in ${facetlist//,/ }; do
1811 local failover=${facet}failover
1812 local host=`facet_host $failover`
1813 [ -z "$host" ] && return
1815 local curactive=`facet_active $facet`
1816 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1817 eval export ${facet}active=$facet
1819 eval export ${facet}active=$failover
1821 # save the active host for this facet
1822 local activevar=${facet}active
1823 echo "$activevar=${!activevar}" > $TMP/$activevar
1824 [[ $facet = mds ]] && combined_mgs_mds && \
1825 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1826 local TO=`facet_active_host $facet`
1827 echo "Failover $facet to $TO"
1833 # do not stripe off hostname if verbose, bug 19215
1834 if [ x$1 = x--verbose ]; then
1842 if [ "$HOST" = "$HOSTNAME" ]; then
1844 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1845 echo "cannot run remote command on $HOST with $myPDSH"
1849 echo "CMD: $HOST $@" >&2
1850 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1853 if [ "$myPDSH" = "rsh" ]; then
1854 # we need this because rsh does not return exit code of an executed command
1855 local command_status="$TMP/cs"
1856 rsh $HOST ":> $command_status"
1857 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1858 cd $RPWD; sh -c \"$@\") ||
1859 echo command failed >$command_status"
1860 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1865 # print HOSTNAME for myPDSH="no_dsh"
1866 if [[ $myPDSH = no_dsh ]]; then
1867 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1869 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1872 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed "s/^${HOST}: //"
1874 return ${PIPESTATUS[0]}
1878 do_node --verbose "$@"
1881 single_local_node () {
1882 [ "$1" = "$HOSTNAME" ]
1887 # do not stripe off hostname if verbose, bug 19215
1888 if [ x$1 = x--verbose ]; then
1896 if single_local_node $rnodes; then
1898 do_nodev $rnodes "$@"
1900 do_node $rnodes "$@"
1905 # This is part from do_node
1908 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1909 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1911 export FANOUT=$(get_node_count "${rnodes//,/ }")
1913 echo "CMD: $rnodes $@" >&2
1914 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1917 # do not replace anything from pdsh output if -N is used
1918 # -N Disable hostname: prefix on lines of output.
1919 if $verbose || [[ $myPDSH = *-N* ]]; then
1920 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")"
1922 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1924 return ${PIPESTATUS[0]}
1930 local HOST=`facet_active_host $facet`
1931 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1936 do_nodes --verbose "$@"
1942 # make sure its not already running
1944 rm -f $TMP/${facet}active
1945 [[ $facet = mds ]] && combined_mgs_mds && rm -f $TMP/mgsactive
1946 do_facet ${facet} $MKFS $*
1952 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1953 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1959 if combined_mgs_mds && [[ $facet = "mgs" ]] ; then
1962 local var=${facet}_MOUNT
1963 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1972 # make sure we are using the primary server, so test-framework will
1973 # be able to clean up properly.
1974 activemds=`facet_active mds`
1975 if [ $activemds != "mds" ]; then
1979 local clients=$CLIENTS
1980 [ -z $clients ] && clients=$(hostname)
1982 zconf_umount_clients $clients $MOUNT "$*" || true
1983 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1985 [ "$CLIENTONLY" ] && return
1986 # The add fn does rm ${facet}active file, this would be enough
1987 # if we use do_facet <facet> only after the facet added, but
1988 # currently we use do_facet mds in local.sh
1990 rm -f ${TMP}/mdsactive
1991 combined_mgs_mds && rm -f $TMP/mgsactive
1992 for num in `seq $OSTCOUNT`; do
1994 rm -f $TMP/ost${num}active
1996 if ! combined_mgs_mds ; then
2003 cleanup_echo_devs () {
2004 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2006 for dev in $devs; do
2007 $LCTL --device $dev cleanup
2008 $LCTL --device $dev detach
2013 nfs_client_mode && return
2021 combined_mgs_mds () {
2022 [[ $MDSDEV = $MGSDEV ]] && [[ $mds_HOST = $mgs_HOST ]]
2028 local number=$(echo -n $facet | sed -e 's/^fs[0-9]\+//' |
2029 sed -e 's/^[a-z]\+//')
2031 [[ -z $number ]] && number=1
2039 local index=$(($(facet_number $facet) - 1))
2040 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2041 local optvar=${tgt}_MKFS_OPTS
2042 local opt=${!optvar}
2044 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2045 [[ $facet = mgs ]] && echo $opt && return
2048 [[ $opt != *--index* ]] && opt+=" --index=$index"
2051 # --failnode options
2052 local var=${facet}failover_HOST
2053 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2054 local failnode=$(h2$NETTYPE ${!var})
2055 failnode="--failnode=$failnode"
2056 # options does not contain
2057 # or contains wrong --failnode=
2058 if [[ $opt != *${failnode}* ]]; then
2059 opt=$(echo $opt | sed 's/--failnode=.* / /')
2060 opt="$opt $failnode"
2066 # no additional mkfs mds "--mgsnode" option for this configuration
2067 if [[ $facet = mds ]] && combined_mgs_mds; then
2072 # additional mkfs "--mgsnode"
2073 local mgsnode="--mgsnode=$MGSNID"
2074 opt=${opt//$mgsnode }
2075 for nid in ${MGSNID//:/ }; do
2076 local mgsnode="--mgsnode=$nid"
2077 # options does not contain
2079 if [[ $opt != *${mgsnode}" "* ]]; then
2080 opt="$opt --mgsnode=$nid"
2088 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2091 # We need ldiskfs here, may as well load them all
2093 [ "$CLIENTONLY" ] && return
2094 echo Formatting mgs, mds, osts
2095 if ! combined_mgs_mds ; then
2096 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2100 add mds $(mkfs_opts mds) $FSTYPE_OPT --reformat $MDSDEV || exit 10
2102 add mds $(mkfs_opts mds) $FSTYPE_OPT --reformat $MDSDEV > /dev/null || exit 10
2105 # the ost-s could have different OST_MKFS_OPTS
2106 # because of different failnode-s
2107 for num in `seq $OSTCOUNT`; do
2109 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2111 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2117 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2122 zconf_umount `hostname` $1 || error "umount failed"
2123 zconf_mount `hostname` $1 || error "mount failed"
2126 writeconf_facet () {
2130 do_facet $facet "$TUNEFS --writeconf $dev"
2134 writeconf_facet mds $MDSDEV
2136 for num in `seq $OSTCOUNT`; do
2137 DEVNAME=`ostdevname $num`
2138 writeconf_facet ost$num $DEVNAME
2143 nfs_client_mode && return
2145 sanity_mount_check ||
2146 error "environments are insane!"
2149 if [ -z "$CLIENTONLY" ]; then
2150 echo Setup mgs, mdt, osts
2152 echo $WRITECONF | grep -q "writeconf" && \
2155 if ! combined_mgs_mds ; then
2156 start mgs $MGSDEV $MGS_MOUNT_OPTS
2159 start mds $MDSDEV $MDS_MOUNT_OPTS
2160 # We started mds, now we should set failover variable properly.
2161 # Set mdsfailover_HOST if it is not set (the default failnode).
2162 if [ -z "$mdsfailover_HOST" ]; then
2163 mdsfailover_HOST=$(facet_host mds)
2166 for num in `seq $OSTCOUNT`; do
2167 DEVNAME=`ostdevname $num`
2168 start ost$num $DEVNAME $OST_MOUNT_OPTS
2170 # We started ost$num, now we should set ost${num}failover variable properly.
2171 # Set ost${num}failover_HOST if it is not set (the default failnode).
2172 varname=ost${num}failover_HOST
2173 if [ -z "${!varname}" ]; then
2174 eval ost${num}failover_HOST=$(facet_host ost${num})
2179 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2181 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2184 if [ "$MOUNT_2" ]; then
2185 mount_client $MOUNT2
2186 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2192 mounted_lustre_filesystems() {
2193 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2196 init_facet_vars () {
2197 [ "$CLIENTONLY" ] && return 0
2204 eval export ${facet}_dev=${device}
2205 eval export ${facet}_opt=\"$@\"
2207 local dev=${facet}_dev
2208 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2209 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2211 eval export ${facet}_svc=${label}
2213 local varname=${facet}failover_HOST
2214 if [ -z "${!varname}" ]; then
2215 eval $varname=$(facet_host $facet)
2218 # ${facet}failover_dev is set in cfg file
2219 varname=${facet}failover_dev
2220 if [ -n "${!varname}" ] ; then
2221 eval export ${facet}failover_dev=${!varname}
2223 eval export ${facet}failover_dev=$device
2226 # get mount point of already mounted device
2227 # is facet_dev is already mounted then use the real
2228 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2229 # i.e. ${facet}_MOUNT if specified by user or default
2230 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2231 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2232 if [ -z $mntpt ]; then
2233 mntpt=$(facet_mntpt $facet)
2235 eval export ${facet}_MOUNT=$mntpt
2238 init_facets_vars () {
2240 init_facet_vars mds $MDSDEV $MDS_MOUNT_OPTS
2242 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2244 remote_ost_nodsh && return
2246 for num in `seq $OSTCOUNT`; do
2247 DEVNAME=`ostdevname $num`
2248 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2252 init_param_vars () {
2254 TIMEOUT=$(do_facet mds "lctl get_param -n timeout")
2256 log "Using TIMEOUT=$TIMEOUT"
2258 if [ "$ENABLE_QUOTA" ]; then
2259 setup_quota $MOUNT || return 2
2263 nfs_client_mode () {
2264 if [ "$NFSCLIENT" ]; then
2265 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2266 local clients=$CLIENTS
2267 [ -z $clients ] && clients=$(hostname)
2269 do_nodesv $clients "grep ' '$MOUNT' ' /proc/mounts"
2270 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2271 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2272 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2274 do_nodesv ${nfsexport[0]} "df -T ${nfsexport[1]}"
2280 check_config_client () {
2283 local mounted=$(mount | grep " $mntpt ")
2284 if [ "$CLIENTONLY" ]; then
2286 # CLIENTONLY should not depend on *_HOST settings
2287 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2288 # in theory someone could create a new,
2289 # client-only config file that assumed lustre was already
2290 # configured and didn't set the MGSNID. If MGSNID is not set,
2291 # then we should use the mgs nid currently being used
2292 # as the default value. bug 18021
2293 [[ x$MGSNID = x ]] &&
2296 if [[ x$mgc != xMGC$MGSNID ]]; then
2297 if [ "$mgs_HOST" ]; then
2298 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2299 [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2300 error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2306 local myMGS_host=$mgs_HOST
2307 if [ "$NETTYPE" = "ptl" ]; then
2308 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2311 echo Checking config lustre mounted on $mntpt
2312 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2313 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2315 # if [ "$mgshost" != "$myMGS_host" ]; then
2316 # error_exit "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2317 # Please use correct config or set mds_HOST correctly!"
2322 check_config_clients () {
2323 local clients=${CLIENTS:-$HOSTNAME}
2326 nfs_client_mode && return
2328 do_rpc_nodes $clients check_config_client $mntpt
2330 sanity_mount_check ||
2331 error "environments are insane!"
2335 local mdstimeout=$(do_facet mds "lctl get_param -n timeout")
2336 local cltimeout=$(lctl get_param -n timeout)
2337 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2338 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2345 local mounted=$(mounted_lustre_filesystems)
2347 echo $mounted' ' | grep -w -q $mntpt' '
2351 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2355 # empty lustre filesystem may have empty directories lost+found and .lustre
2357 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2358 -print | wc -l) = 1 ] || return 1
2359 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2360 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2364 check_and_setup_lustre() {
2365 nfs_client_mode && return
2367 local MOUNTED=$(mounted_lustre_filesystems)
2371 # both MOUNT and MOUNT2 are not mounted
2372 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2373 [ "$REFORMAT" ] && formatall
2374 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2376 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2377 export I_MOUNTED=yes
2381 elif is_mounted $MOUNT2; then
2383 # MOUNT2 is mounted, while MOUNT_2 is not set
2384 if ! [ "$MOUNT_2" ]; then
2385 cleanup_mount $MOUNT2
2386 export I_UMOUNTED2=yes
2389 # MOUNT2 is mounted, MOUNT_2 is set
2391 # FIXME: what to do if check_config failed?
2393 # 1) remote client has mounted other Lustre fs ?
2394 # 2) it has insane env ?
2395 # let's try umount MOUNT2 on all clients and mount it again:
2396 if ! check_config_clients $MOUNT2; then
2397 cleanup_mount $MOUNT2
2398 restore_mount $MOUNT2
2399 export I_MOUNTED2=yes
2404 # MOUNT is mounted MOUNT2 is not mounted
2405 elif [ "$MOUNT_2" ]; then
2406 restore_mount $MOUNT2
2407 export I_MOUNTED2=yes
2411 # FIXME: what to do if check_config failed?
2413 # 1) remote client has mounted other Lustre fs?
2414 # 2) lustre is mounted on remote_clients atall ?
2415 check_config_clients $MOUNT
2419 set_default_debug_nodes $(comma_list $(nodes_list))
2421 if [ "$ONLY" == "setup" ]; then
2427 local clients=${CLIENTS:-$HOSTNAME}
2430 zconf_mount_clients $clients $mntpt
2434 local clients=${CLIENTS:-$HOSTNAME}
2437 zconf_umount_clients $clients $mntpt
2440 cleanup_and_setup_lustre() {
2441 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2442 lctl set_param debug=0 || true
2444 if [ "$ONLY" == "cleanup" ]; then
2448 check_and_setup_lustre
2451 # Get all of the server target devices from a given server node and type.
2458 if [ "$type" == ost ]; then
2459 devs=$(get_obdfilter_param $node "" mntdev)
2461 devs=$(do_node $node \
2462 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
2464 for dev in $devs; do
2466 *loop*) do_node $node "losetup $dev" | \
2467 sed -e "s/.*(//" -e "s/).*//" ;;
2473 # Get all of the server target devices.
2479 for node in $(osts_nodes); do
2480 OSTDEVS[i]=$(get_mnt_devs $node ost)
2485 # Run e2fsck on MDT or OST device.
2491 df > /dev/null # update statfs data on disk
2492 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2495 do_node $node $cmd || rc=$?
2496 [ $rc -le $FSCK_MAX_ERR ] || \
2497 error_exit "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2501 # verify a directory is shared among nodes.
2502 check_shared_dir() {
2505 [ -z "$dir" ] && return 1
2506 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2507 check_write_access $dir || return 1
2511 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2517 check_shared_dir $SHARED_DIRECTORY ||
2518 error "$SHARED_DIRECTORY isn't a shared directory"
2520 export MDSDB=$SHARED_DIRECTORY/mdsdb
2521 export OSTDB=$SHARED_DIRECTORY/ostdb
2523 run_e2fsck $(facet_host mds) $MDSDEV "--mdsdb $MDSDB"
2528 for node in $(osts_nodes); do
2529 for dev in ${OSTDEVS[i]}; do
2530 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2531 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2532 ostidx=$((ostidx + 1))
2539 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2543 [ $rc -le $FSCK_MAX_ERR ] || \
2544 error_exit "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2545 echo "lfsck finished with rc=$rc"
2547 rm -rvf $MDSDB* $OSTDB* || true
2551 check_and_cleanup_lustre() {
2552 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2558 if is_mounted $MOUNT; then
2559 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
2560 error "remove sub-test dirs failed"
2561 [ "$ENABLE_QUOTA" ] && restore_quota || true
2564 if [ "$I_UMOUNTED2" = "yes" ]; then
2565 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2568 if [ "$I_MOUNTED2" = "yes" ]; then
2569 cleanup_mount $MOUNT2
2572 if [ "$I_MOUNTED" = "yes" ]; then
2573 cleanupall -f || error "cleanup failed"
2581 wait_for_function () {
2584 # suppress fn both stderr and stdout
2585 if [ "$1" = "--quiet" ]; then
2587 quiet=" > /dev/null 2>&1"
2598 eval $fn $quiet && return 0
2600 wait=$((wait + sleep))
2601 [ $wait -lt $max ] || return 1
2602 echo waiting $fn, $((max - wait)) secs left ...
2612 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2613 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2614 echo "Network not available!"
2618 echo `date +"%H:%M:%S (%s)"` network interface is UP
2627 # the sed converts spaces to commas, but leaves the last space
2628 # alone, so the line doesn't end with a comma.
2629 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2635 echo $list | grep -qw $item
2638 # list, excluded are the comma separated lists
2639 exclude_items_from_list () {
2645 for item in ${excluded//,/ }; do
2646 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2648 echo $(comma_list $list)
2651 # list, expand are the comma separated lists
2653 local list=${1//,/ }
2654 local expand=${2//,/ }
2657 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2658 echo $(comma_list $expanded)
2661 testslist_filter () {
2662 local script=$LUSTRE/tests/${TESTSUITE}.sh
2664 [ -f $script ] || return 0
2666 local start_at=$START_AT
2667 local stop_at=$STOP_AT
2669 local var=${TESTSUITE//-/_}_START_AT
2670 [ x"${!var}" != x ] && start_at=${!var}
2671 var=${TESTSUITE//-/_}_STOP_AT
2672 [ x"${!var}" != x ] && stop_at=${!var}
2674 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2675 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2676 /^'${start_at}'$/ {flag = 0}
2677 {if (flag == 1) print $0}
2678 /^'${stop_at}'$/ { flag = 1 }'
2682 (cd `dirname $1`; echo $PWD/`basename $1`)
2686 local types=${1:-"OST MDS MGS"}
2689 for entry in $types; do
2690 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2691 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2694 MDS|MGS ) list="$list $name";;
2695 OST ) for ((i=1; i<=$OSTCOUNT; i++)) do
2696 list="$list ${name}$i"
2698 * ) error "Invalid facet type"
2702 echo $(comma_list $list)
2705 ##################################
2706 # Adaptive Timeouts funcs
2709 # only check mds, we assume at_max is the same on all nodes
2710 local at_max=$(do_facet mds "lctl get_param -n at_max")
2711 if [ $at_max -eq 0 ]; then
2722 # suppose that all ost-s have the same $at value set
2723 [ $facet != "ost" ] || facet=ost1
2725 do_facet $facet "lctl get_param -n $at"
2739 if [ $facet == "ost" ]; then
2740 facet=$(get_facets OST)
2742 hosts=$(expand_list $hosts $(facets_hosts $facet))
2745 do_nodes $hosts lctl set_param at_max=$at_max
2748 ##################################
2752 # OBD_FAIL_MDS_ALL_REQUEST_NET
2754 do_facet mds lctl set_param fail_loc=0x123
2755 do_facet client "$1" || RC=$?
2756 do_facet mds lctl set_param fail_loc=0
2761 # OBD_FAIL_MDS_ALL_REPLY_NET
2763 do_facet mds lctl set_param fail_loc=0x122
2764 do_facet client "$@" || RC=$?
2765 do_facet mds lctl set_param fail_loc=0
2769 drop_reint_reply() {
2770 # OBD_FAIL_MDS_REINT_NET_REP
2772 do_facet mds lctl set_param fail_loc=0x119
2773 do_facet client "$@" || RC=$?
2774 do_facet mds lctl set_param fail_loc=0
2779 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2781 do_facet ost1 lctl set_param fail_loc=0x214
2782 do_facet client "$1" || RC=$?
2783 do_facet client "sync"
2784 do_facet ost1 lctl set_param fail_loc=0
2788 drop_ldlm_cancel() {
2789 #define OBD_FAIL_LDLM_CANCEL 0x304
2791 do_facet client lctl set_param fail_loc=0x304
2792 do_facet client "$@" || RC=$?
2793 do_facet client lctl set_param fail_loc=0
2797 drop_bl_callback() {
2798 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2800 do_facet client lctl set_param fail_loc=0x305
2801 do_facet client "$@" || RC=$?
2802 do_facet client lctl set_param fail_loc=0
2807 #define OBD_FAIL_LDLM_REPLY 0x30c
2809 do_facet mds lctl set_param fail_loc=0x30c
2810 do_facet client "$@" || RC=$?
2811 do_facet mds lctl set_param fail_loc=0
2819 echo "clearing fail_loc on $facet"
2820 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2823 set_nodes_failloc () {
2824 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2827 cancel_lru_locks() {
2828 $LCTL mark "cancel_lru_locks $1 start"
2829 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2830 $LCTL set_param -n $d=clear
2832 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2833 $LCTL mark "cancel_lru_locks $1 stop"
2838 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2839 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2840 echo "$DEFAULT_LRU_SIZE"
2845 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2848 lru_resize_disable()
2850 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2855 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2856 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2857 echo there is still data in page cache $FILE ?
2858 lctl get_param -n $FILE
2865 create_fake_exports () {
2868 #obd_fail_val = num;
2869 #define OBD_FAIL_TGT_FAKE_EXP 0x708
2870 do_facet $facet "lctl set_param fail_val=$num"
2871 do_facet $facet "lctl set_param fail_loc=0x80000708"
2876 DEBUGSAVE="$(lctl get_param -n debug)"
2880 [ -n "$DEBUGSAVE" ] && lctl set_param debug="${DEBUGSAVE}"
2884 ##################################
2886 ##################################
2889 local TYPE=${TYPE:-"FAIL"}
2892 # do not dump logs if $1=false
2893 if [ "x$1" = "xfalse" ]; then
2898 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2901 # We need to dump the logs on all nodes
2903 gather_logs $(comma_list $(nodes_list))
2907 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2908 echo "$@" > $LOGDIR/err
2913 local log=$TESTSUITELOG
2915 [ -f "$log" ] && egrep -q .FAIL: $log && status=1
2921 if $FAIL_ON_ERROR; then
2932 # use only if we are ignoring failures for this test, bugno required.
2933 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2934 # e.g. error_ignore 5494 "your message"
2936 local TYPE="IGNORE (bz$1)"
2942 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2946 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2947 [ "$TESTSUITELOG" ] && \
2948 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2951 build_test_filter() {
2952 EXCEPT="$EXCEPT $(testslist_filter)"
2954 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2958 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2959 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2960 [ "$EXCEPT_SLOW" ] && \
2961 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2962 for E in $EXCEPT $ALWAYS_EXCEPT; do
2963 eval EXCEPT_${E}=true
2965 for E in $EXCEPT_SLOW; do
2966 eval EXCEPT_SLOW_${E}=true
2968 for G in $GRANT_CHECK_LIST; do
2969 eval GCHECK_ONLY_${G}=true
2974 if [[ $1 = [a-z]* ]]; then
2981 # print a newline if the last test was skipped
2982 export LAST_SKIPPED=
2986 export base=`basetest $1`
2987 if [ ! -z "$ONLY" ]; then
2989 if [ ${!testname}x != x ]; then
2990 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2991 run_one_logged $1 "$2"
2995 if [ ${!testname}x != x ]; then
2996 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2997 run_one_logged $1 "$2"
3005 if [ ${!testname}x != x ]; then
3007 TESTNAME=test_$1 skip "skipping excluded test $1"
3010 testname=EXCEPT_$base
3011 if [ ${!testname}x != x ]; then
3013 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3016 testname=EXCEPT_SLOW_$1
3017 if [ ${!testname}x != x ]; then
3019 TESTNAME=test_$1 skip "skipping SLOW test $1"
3022 testname=EXCEPT_SLOW_$base
3023 if [ ${!testname}x != x ]; then
3025 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3030 run_one_logged $1 "$2"
3035 EQUALS="======================================================================"
3039 local suffixlen=$((${#EQUALS} - ${#msg}))
3040 [ $suffixlen -lt 5 ] && suffixlen=5
3041 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
3046 module_loaded lnet || load_modules
3058 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3063 strace -o $TMP/$1.strace -ttt $*
3065 log "FINISHED: $*: rc $RC"
3070 equals_msg $1 test complete, duration $2 sec
3071 [ -f "$TESTSUITELOG" ] && grep ".IGNORE\|.FAIL" $TESTSUITELOG || true
3072 echo duration $2 >>$TESTSUITELOG
3076 # Set TEST_STATUS here; will be used for logging the result
3077 if [ -f $LOGDIR/err ]; then
3082 echo $TEST_STATUS " " $@
3086 FFREE=`lctl get_param -n mds.*.filesfree`
3087 FTOTAL=`lctl get_param -n mds.*.filestotal`
3088 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3092 echo -n "Resetting fail_loc on all nodes..."
3093 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3101 export tdir=d0.${TESTSUITE}/d${base}
3102 export TESTNAME=test_$testnum
3103 local SAVE_UMASK=`umask`
3107 log "== test $testnum: $message == `date +%H:%M:%S`"
3108 test_${testnum} || error "test_$testnum failed with $?"
3111 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3112 check_catastrophe || error "LBUG/LASSERT detected"
3113 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3121 local BEFORE=`date +%s`
3123 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3124 local test_log=$LOGDIR/$name
3126 local SAVE_UMASK=`umask`
3129 log_sub_test_begin test_${1}
3130 (run_one $1 "$2") 2>&1 | tee $test_log
3131 local RC=${PIPESTATUS[0]}
3133 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3134 echo "test_$1 returned $RC" | tee $LOGDIR/err
3136 duration=$((`date +%s` - $BEFORE))
3137 pass "(${duration}s)"
3138 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3139 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3141 if [ -f $LOGDIR/err ]; then
3142 $FAIL_ON_ERROR && exit $RC
3151 (cd `dirname $1`; echo $PWD/`basename $1`)
3155 export base=`basetest $1`
3156 [ "$CHECK_GRANT" == "no" ] && return 0
3158 testname=GCHECK_ONLY_${base}
3159 [ ${!testname}x == x ] && return 0
3161 echo -n "checking grant......"
3163 local clients=$CLIENTS
3164 [ -z $clients ] && clients=$(hostname)
3166 # sync all the data and make sure no pending data on server
3167 do_nodes $clients sync
3170 client_grant=`do_nodes $clients \
3171 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3172 awk '{total += $1} END{print total}'`
3175 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3176 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
3177 awk '{total += $1} END{print total}'`
3179 # check whether client grant == server grant
3180 if [ $client_grant -ne $server_grant ]; then
3181 echo "failed: client:${client_grant} server: ${server_grant}."
3182 do_nodes $(comma_list $(osts_nodes)) \
3183 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3184 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3187 echo "pass: client:${client_grant} server: ${server_grant}"
3191 ########################
3197 ost=`echo $1 | awk -F_ '{print $3}'`
3198 if [ -z $ost ]; then
3199 ost=`echo $1 | sed 's/-osc.*//'`
3204 ostuuid_from_index()
3206 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3209 ostname_from_index() {
3210 local uuid=$(ostuuid_from_index $1)
3214 index_from_ostuuid()
3216 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3221 [[ $node != $HOSTNAME ]]
3226 remote_node $mds_HOST
3231 [ "$CLIENTONLY" ] && return 0 || true
3232 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3237 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3238 MSKIPPED=1 && return 1
3245 for node in $(osts_nodes) ; do
3246 remote_node $node && return 0
3253 [ "$CLIENTONLY" ] && return 0 || true
3254 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3259 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3260 OSKIPPED=1 && return 1
3267 MGS=$(facet_host mgs)
3268 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3272 remote_ost && remote_mds
3277 remote_mds_nodsh || remote_ost_nodsh || \
3278 $(single_local_node $(comma_list $(nodes_list)))
3286 for facet in ${facets//,/ }; do
3287 if [ "$FAILURE_MODE" = HARD ]; then
3288 nodes="$nodes $(facet_active_host $facet)"
3290 nodes="$nodes $(facet_host $facet)"
3293 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3299 local facets=$(get_facets OST)
3300 local nodes=$(facets_nodes $facets)
3306 # FIXME. We need a list of clients
3307 local myNODES=$HOSTNAME
3310 # CLIENTS (if specified) contains the local client
3311 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3313 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3314 myNODES="$myNODES $(facets_nodes $(get_facets))"
3317 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3322 remote_nodes_list () {
3323 local rnodes=$(nodes_list)
3324 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3328 init_clients_lists () {
3329 # Sanity check: exclude the local client from RCLIENTS
3330 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3332 # Sanity check: exclude the dup entries
3333 rclients=$(for i in $rclients; do echo $i; done | sort -u)
3335 local clients="$SINGLECLIENT $HOSTNAME $rclients"
3337 # Sanity check: exclude the dup entries from CLIENTS
3338 # for those configs which has SINGLCLIENT set to local client
3339 clients=$(for i in $clients; do echo $i; done | sort -u)
3341 CLIENTS=`comma_list $clients`
3342 local -a remoteclients=($rclients)
3343 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3344 varname=CLIENT$((i + 2))
3345 eval $varname=${remoteclients[i]}
3348 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3351 get_random_entry () {
3354 rnodes=${rnodes//,/ }
3356 local -a nodes=($rnodes)
3357 local num=${#nodes[@]}
3358 local i=$((RANDOM * num * 2 / 65536))
3364 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3369 lctl get_param version | grep -q patchless
3373 [ "$(lustre_version_code client)" = "$(lustre_version_code mds)" -a \
3374 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
3379 echo $nodes | wc -w || true
3383 local nodes=$(osts_nodes)
3384 local osscount=$(get_node_count "$nodes")
3385 [ ! "$OSTCOUNT" = "$osscount" ]
3388 generate_machine_file() {
3389 local nodes=${1//,/ }
3390 local machinefile=$2
3392 for node in $nodes; do
3393 echo $node >>$machinefile || \
3394 { echo "can not generate machinefile $machinefile" && return 1; }
3399 local file=$1/stripe
3401 $LFS getstripe -v $file || error
3408 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3409 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3413 setstripe_nfsserver () {
3415 local nfsserver=$(nfs_server $dir)
3417 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3419 do_nodev $nfsserver lfs setstripe "$@"
3422 # Check and add a test group.
3428 local gid=$(getent group $group_name | cut -d: -f3)
3429 if [[ -n "$gid" ]]; then
3430 [[ "$gid" -eq "$group_id" ]] || {
3431 error_noexit "inconsistent group ID:" \
3432 "new: $group_id, old: $gid"
3436 groupadd -g $group_id $group_name
3443 # Check and add a test user.
3456 local uid=$(getent passwd $user_name | cut -d: -f3)
3457 if [[ -n "$uid" ]]; then
3458 if [[ "$uid" -eq "$user_id" ]]; then
3459 local dir=$(getent passwd $user_name | cut -d: -f6)
3460 if [[ "$dir" != "$home" ]]; then
3462 usermod -d $home $user_name
3466 error_noexit "inconsistent user ID:" \
3467 "new: $user_id, old: $uid"
3472 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
3479 check_runas_id_ret() {
3481 local myRUNAS_UID=$1
3482 local myRUNAS_GID=$2
3485 if [ -z "$myRUNAS" ]; then
3486 error_exit "myRUNAS command must be specified for check_runas_id"
3488 mkdir $DIR/d0_runas_test
3490 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3491 if ! $myRUNAS touch $DIR/d0_runas_test/f$$ ; then
3492 do_nodesv $(comma_list $(nodes_list)) grep -w $myRUNAS_UID /etc/passwd
3495 rm -rf $DIR/d0_runas_test
3500 local myRUNAS_UID=$1
3501 local myRUNAS_GID=$2
3504 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3505 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3506 Please set RUNAS_ID to some UID which exists on MDS and client or
3507 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3510 # Run multiop in the background, but wait for it to print
3511 # "PAUSING" to its stdout before returning from this function.
3512 multiop_bg_pause() {
3513 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3517 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3520 echo "$MULTIOP_PROG $FILE v$ARGS"
3521 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3523 echo "TMPPIPE=${TMPPIPE}"
3524 local multiop_output
3526 read -t 60 multiop_output < $TMPPIPE
3527 if [ $? -ne 0 ]; then
3532 if [ "$multiop_output" != "PAUSING" ]; then
3533 echo "Incorrect multiop output: $multiop_output"
3543 if [ x$1 = x--uniq ]; then
3553 # We need to run do_node in bg, because pdsh does not exit
3554 # if child process of run script exists.
3555 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
3556 # because of multiop_bg_pause -> $MULTIOP_PROG &
3557 # By the same reason we need sleep a bit after do_nodes starts
3558 # to let runmultiop_bg_pause start muliop and
3559 # update /tmp/multiop_bg.pid ;
3560 # The rm /tmp/multiop_bg.pid guarantees here that
3561 # we have the updated by runmultiop_bg_pause
3562 # /tmp/multiop_bg.pid file
3564 local pid_file=$TMP/multiop_bg.pid.$uniq
3565 do_node $client "rm -f $pid_file && MULTIOP_PID_FILE=$pid_file LUSTRE= runmultiop_bg_pause $file $cmds" &
3569 multiop_pid=$(do_node $client cat $pid_file)
3570 [ -n "$multiop_pid" ] || error "$client : Can not get multiop_pid from $pid_file "
3571 eval export $(node_var_name $client)_multiop_pid$uniq=$multiop_pid
3572 eval export $(node_var_name $client)_do_node_pid$uniq=$pid
3573 local var=$(node_var_name $client)_multiop_pid$uniq
3574 echo node $client multiop_bg started multiop_pid=${!var}
3580 if [ x$1 = x--uniq ]; then
3587 local multiop_pid=$(node_var_name $client)_multiop_pid$uniq
3588 local do_node_pid=$(node_var_name $client)_do_node_pid$uniq
3590 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
3591 do_node $client kill -USR1 ${!multiop_pid}
3593 wait ${!do_node_pid}
3603 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3609 inodes_available () {
3610 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3614 mdsrate_inodes_available () {
3615 local min_inodes=$(inodes_available)
3616 echo $((min_inodes * 99 / 100))
3619 # reset llite stat counters
3620 clear_llite_stats(){
3621 lctl set_param -n llite.*.stats 0
3624 # sum llite stat items
3625 calc_llite_stats() {
3626 local res=$(lctl get_param -n llite.*.stats |
3627 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3632 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3635 calc_osc_kbytes () {
3636 df $MOUNT > /dev/null
3637 $LCTL get_param -n osc.*[oO][sS][cC][-_]*.$1 | calc_sum
3640 # save_lustre_params(node, parameter_mask)
3641 # generate a stream of formatted strings (<node> <param name>=<param value>)
3642 save_lustre_params() {
3644 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3647 # restore lustre parameters from input stream, produces by save_lustre_params
3648 restore_lustre_params() {
3652 while IFS=" =" read node name val; do
3653 do_node ${node//:/} "lctl set_param -n $name $val"
3657 check_catastrophe() {
3658 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3659 local C=$CATASTROPHE
3660 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3662 if [ $rnodes ]; then
3663 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3664 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3680 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3682 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3683 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3684 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3688 mdsrate_cleanup () {
3689 mpi_run -np $1 ${MACHINEFILE_OPTION} $2 ${MDSRATE} --unlink --nfiles $3 \
3690 --dir $4 --filefmt $5 $6
3693 delayed_recovery_enabled () {
3694 do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age" > /dev/null 2>&1
3697 ################################################################################
3698 # The following functions are used to enable interop testing between
3699 # 1.8 and 2.0. The lprocfs layout changed from 1.8 to 2.0 as the followings:
3701 # {blocksize filesfree filestotal fstype kbytesavail kbytesfree kbytestotal mntdev} moved from mds to osd
3702 # mdt lov: fsname-mdtlov -> fsname-MDTXXXX-mdtlov
3703 # mdt osc: fsname-OSTXXXX-osc -> fsname-OSTXXXX-osc-MDTXXXX
3704 ################################################################################
3707 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
3708 eval set -- $(tr "[:punct:]" " " <<< $*)
3710 echo -n $((($1 << 16) | ($2 << 8) | $3))
3713 get_lustre_version() {
3714 local facet=${1:-"mds"}
3715 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3718 lustre_version_code() {
3719 local facet=${1:-"mds"}
3720 version_code $(get_lustre_version $1)
3723 get_mds_version_major () {
3724 local version=$(get_lustre_version mds)
3725 echo $version | awk -F. '{print $1}'
3728 get_mds_version_minor () {
3729 local version=$(get_lustre_version mds)
3730 echo $version | awk -F. '{print $2}'
3733 get_mds_version_patch () {
3734 local version=$(get_lustre_version mds)
3735 echo $version | awk -F. '{print $3}'
3738 get_mds_version_fix () {
3739 local version=$(get_lustre_version mds)
3740 echo $version | awk -F. '{print $4}'
3743 get_kernel_version () {
3744 local facet=${1:-"mds"}
3745 do_facet $facet uname -r | awk -F "-" '{print $1}'
3748 get_mds_kernel_major () {
3749 local version=$(get_kernel_version mds)
3750 echo $version | awk -F. '{print $1"."$2}'
3753 get_mds_kernel_minor () {
3754 local version=$(get_kernel_version mds)
3755 echo $version | awk -F. '{print $3}'
3758 get_mds_fsstat_proc_path() {
3759 local major=$(get_mds_version_major)
3760 local minor=$(get_mds_version_minor)
3761 if [ $major -le 1 -a $minor -le 8 ] ; then
3768 get_mds_mntdev_proc_path() {
3769 local fsstat_dev=$(get_mds_fsstat_proc_path)
3770 echo "$fsstat_dev.*.mntdev"
3773 get_mdtlov_proc_path() {
3775 local major=$(get_mds_version_major)
3776 local minor=$(get_mds_version_minor)
3777 if [ $major -le 1 -a $minor -le 8 ] ; then
3778 echo "${fsname}-mdtlov"
3780 echo "${fsname}-MDT0000-mdtlov"
3784 get_mdtosc_proc_path() {
3786 local major=$(get_mds_version_major)
3787 local minor=$(get_mds_version_minor)
3788 if [ $major -le 1 -a $minor -le 8 ] ; then
3791 echo "${ost}-osc-MDT0000"
3795 get_mds_mdt_device_proc_path() {
3796 local major=$(get_mds_version_major)
3797 local minor=$(get_mds_version_minor)
3798 if [ $major -le 1 -a $minor -le 8 ] ; then
3806 local major=$(get_mds_version_major)
3807 local minor=$(get_mds_version_minor)
3808 if [ $major -le 1 -a $minor -le 8 ] ; then
3815 ########################
3817 convert_facet2label() {
3820 if [ x$facet = xost ]; then
3824 local varsvc=${facet}_svc
3826 if [ -n ${!varsvc} ]; then
3829 error "No lablel for $facet!"
3833 get_clientosc_proc_path() {
3839 get_osc_import_name() {
3842 local label=$(convert_facet2label $ost)
3844 if [ "$facet" == "mds" ]; then
3845 get_mdtosc_proc_path $label
3849 get_clientosc_proc_path $label
3853 _wait_import_state () {
3856 local maxtime=${3:-$(max_recovery_time)}
3860 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3861 while [ "${CONN_STATE}" != "${expected}" ]; do
3862 if [ "${expected}" == "DISCONN" ]; then
3863 # for disconn we can check after proc entry is removed
3864 [ "x${CONN_STATE}" == "x" ] && return 0
3865 # with AT enabled, we can have connect request timeout near of
3866 # reconnect timeout and test can't see real disconnect
3867 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3869 [ $i -ge $maxtime ] && \
3870 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
3873 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3877 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
3881 wait_import_state() {
3884 local maxtime=${3:-$(max_recovery_time)}
3887 for param in ${params//,/ }; do
3888 _wait_import_state $state $param $maxtime || return
3892 # One client request could be timeouted because server was not ready
3893 # when request was sent by client.
3894 # The request timeout calculation details :
3896 # /* We give the server rq_timeout secs to process the req, and
3897 # add the network latency for our local timeout. */
3898 # request->rq_deadline = request->rq_sent + request->rq_timeout +
3899 # ptlrpc_at_get_net_latency(request) ;
3901 # ptlrpc_connect_import ()
3902 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
3905 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
3906 # ptlrpc_at_get_net_latency(request) ->
3907 # at_get (max (iat_net_latency=0, at_min)) = at_min
3910 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
3911 # INITIAL_CONNECT_TIMEOUT + at_min
3913 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
3914 # because we can not get this value in runtime,
3915 # the value depends on configure options, and it is not stored in /proc.
3917 # #define CONNECTION_SWITCH_MIN 5U
3919 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3921 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
3923 request_timeout () {
3926 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
3927 local init_connect_timeout=$TIMEOUT
3928 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
3930 local at_min=$(at_get $facet at_min)
3932 echo $(( init_connect_timeout + at_min ))
3935 wait_osc_import_state() {
3939 local ost=$(get_osc_import_name $facet $ost_facet)
3941 local param="osc.${ost}.ost_server_uuid"
3943 # 1. wait the deadline of client 1st request (it could be skipped)
3944 # 2. wait the deadline of client 2nd request
3945 local maxtime=$(( 2 * $(request_timeout $facet)))
3947 if ! do_rpc_nodes $(facet_host $facet) \
3948 _wait_import_state $expected $param $maxtime; then
3949 error "import is not in ${expected} state"
3956 get_clientmdc_proc_path() {
3964 # Add paths to lustre tests for 32 and 64 bit systems.
3965 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
3966 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
3969 wait_clients_import_state () {
3976 if [ "$FAILURE_MODE" = HARD ]; then
3977 facets=$(facets_on_host $(facet_active_host $facet))
3980 for facet in ${facets//,/ }; do
3981 local label=$(convert_facet2label $facet)
3984 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3985 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3986 *) error "unknown facet!" ;;
3988 local params=$(expand_list $params $proc_path)
3991 if ! do_rpc_nodes $list wait_import_state $expected $params; then
3992 error "import is not in ${expected} state"
3997 destroy_pool_int() {
3999 local OSTS=$(do_facet mds lctl pool_list $1 | awk '$1 !~ /^Pool:/ {print $1}')
4000 for ost in $OSTS; do
4001 do_facet mgs lctl pool_remove $1 $ost
4003 do_facet mgs lctl pool_destroy $1
4006 # <fsname>.<poolname> or <poolname>
4008 local fsname=${1%%.*}
4009 local poolname=${1##$fsname.}
4011 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4015 pool_list $fsname.$poolname || return $?
4017 destroy_pool_int $fsname.$poolname
4019 [[ $RC -ne 0 ]] && return $RC
4021 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4022 2>/dev/null || echo foo" "foo" || RC=1
4024 if [[ $RC -eq 0 ]]; then
4025 remove_pool_from_list $fsname.$poolname
4027 error "destroy pool failed $1"
4033 local fsname=${1:-$FSNAME}
4035 local listvar=${fsname}_CREATED_POOLS
4039 [ x${!listvar} = x ] && return 0
4041 echo destroy the created pools: ${!listvar}
4042 for poolname in ${!listvar//,/ }; do
4043 destroy_pool $fsname.$poolname
4048 local fsname=${1:-$FSNAME}
4050 destroy_pools $fsname
4056 local ts=$(date +%s)
4059 if [[ ! -f "$YAML_LOG" ]]; then
4060 # init_logging is not performed before gather_logs,
4061 # so the $LOGDIR needs to be checked here
4062 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4065 # bug 20237, comment 11
4066 # It would also be useful to provide the option
4067 # of writing the file to an NFS directory so it doesn't need to be copied.
4068 [ -f $LOGDIR/shared ] && docp=false
4070 # dump lustre logs, dmesg
4072 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
4074 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4076 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4077 echo "Dumping logs only on local client."
4078 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4079 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4083 do_nodes --verbose $list \
4084 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4085 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4087 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4100 for i in $(seq 0 $num_mntpts); do
4101 cmd="ls -laf ${mntpt_root}$i/$dir"
4107 for pid in $pids; do
4114 # target_start_and_reset_recovery_timer()
4115 # service_time = at_est2timeout(service_time);
4116 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4117 # INITIAL_CONNECT_TIMEOUT);
4118 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4119 #define CONNECTION_SWITCH_INC 1
4120 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4121 #define CONNECTION_SWITCH_MIN 5U
4123 max_recovery_time () {
4124 local init_connect_timeout=$(( TIMEOUT / 20 ))
4125 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4127 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4132 remove_mdt_files() {
4137 local mntpt=${MOUNT%/*}/$facet
4139 echo "removing files from $mdtdev on $facet: $files"
4140 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4143 rm $mntpt/ROOT/$f || { rc=$?; break; }
4145 umount -f $mntpt || return $?
4149 duplicate_mdt_files() {
4154 local mntpt=${MOUNT%/*}/$facet
4156 echo "duplicating files on $mdtdev on $facet: $files"
4157 mkdir -p $mntpt || return $?
4158 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4168 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4169 pushd $mntpt/ROOT > /dev/null || return $?
4172 touch $f.bad || return $?
4173 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4175 [ $rc -eq 0 ] || return $rc
4176 setfattr --restore $tmp || return $?
4182 local devs=${1//,/ }
4185 local rslt=$TMP/sgpdd_survey
4187 # sgpdd-survey cleanups ${rslt}.* files
4189 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4195 # returns the canonical name for an ldiskfs device
4200 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4201 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4202 echo dm-\\\${foo##*:};
4204 echo \\\$(basename \\\$dv);
4208 is_sanity_benchmark() {
4209 local benchmarks="dbench bonnie iozone fsx"
4211 for b in $benchmarks; do
4212 if [ "$b" == "$suite" ]; then
4220 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4225 # Checking for shared logdir
4226 if [ ! -d $dir ]; then
4227 # Not found. Create local logdir
4230 touch $dir/check_file.$(hostname -s)
4235 check_write_access() {
4240 for node in $(nodes_list); do
4241 file=$dir/check_file.$(short_hostname $node)
4242 if [[ ! -f $file ]]; then
4243 # Logdir not accessible/writable from this node.
4246 rm -f $file || return 1
4252 if [[ -n $YAML_LOG ]]; then
4255 local SAVE_UMASK=`umask`
4258 export YAML_LOG=${LOGDIR}/results.yml
4262 # If the yaml log already exists then we will just append to it.
4263 [[ -f $YAML_LOG ]] && return 0
4265 if check_shared_dir $LOGDIR; then
4266 touch $LOGDIR/shared
4267 echo "Logging to shared log directory: $LOGDIR"
4269 echo "Logging to local directory: $LOGDIR"
4272 yml_nodes_file $LOGDIR >> $YAML_LOG
4273 yml_results_file >> $YAML_LOG
4279 yml_log_test $1 >> $YAML_LOG
4283 yml_log_sub_test $@ >> $YAML_LOG
4287 yml_log_test_status $@ >> $YAML_LOG
4290 log_sub_test_begin() {
4291 yml_log_sub_test_begin $@ >> $YAML_LOG
4294 log_sub_test_end() {
4295 yml_log_sub_test_end $@ >> $YAML_LOG