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=$LUSTRE/tests:$PATH
146 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
147 [ ! -f "$LST" ] && export LST=$(which lst)
148 export SGPDDSURVEY=${SGPDDSURVEY:-$(which sgpdd-survey)}
149 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
150 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
151 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
152 export PATH=$LUSTRE/tests/racer:$PATH:
154 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
155 export PATH=$PATH:$LUSTRE/tests/mpi
157 export RSYNC_RSH=${RSYNC_RSH:-rsh}
158 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
159 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
160 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
161 [ ! -f "$LFS" ] && export LFS=$(which lfs)
162 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
163 if [ ! -f "$L_GETIDENTITY" ]; then
164 if `which l_getidentity > /dev/null 2>&1`; then
165 export L_GETIDENTITY=$(which l_getidentity)
167 export L_GETIDENTITY=NONE
170 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
171 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
172 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
173 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
174 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
175 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
176 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
177 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
178 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
179 export FSTYPE=${FSTYPE:-"ldiskfs"}
180 export NAME=${NAME:-local}
181 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
182 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
183 export LGSSD=$(which lgssd)
184 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
185 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
186 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
188 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
191 if [ "$ACCEPTOR_PORT" ]; then
192 export PORT_OPT="--port $ACCEPTOR_PORT"
197 echo "Using GSS/krb5 ptlrpc security flavor"
198 which lgss_keyring > /dev/null 2>&1 || \
199 error_exit "built with gss disabled! SEC=$SEC"
210 IDENTITY_UPCALL=false
213 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
215 # Paths on remote nodes, if different
216 export RLUSTRE=${RLUSTRE:-$LUSTRE}
217 export RPWD=${RPWD:-$PWD}
218 export I_MOUNTED=${I_MOUNTED:-"no"}
219 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
220 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
221 ! -f `dirname $0`/../mds/mds.ko ]; then
222 export CLIENTMODSONLY=yes
227 while getopts "rvwf:" opt $*; do
230 r) REFORMAT=--reformat;;
232 w) WRITECONF=writeconf;;
237 shift $((OPTIND - 1))
240 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
245 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
246 *) EXT=".ko"; USE_QUOTA=yes;;
251 /sbin/lsmod | grep -q $1
254 # Load a module on the system where this is running.
256 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
258 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
259 # will be used as the arguments. Otherwise arguments will be obtained from
260 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
267 BASE=`basename $module $EXT`
269 module_loaded ${BASE} && return
271 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
273 if [ $# -eq 0 ]; then
274 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
275 # Bash until 4.x, so we resort to eval.
276 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
277 eval set -- \$$optvar
278 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
279 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
280 set -- $(grep "^options\\s*\<${module}\>" $MODPROBECONF)
281 # Get rid of "options $module"
282 (($# > 0)) && shift 2
284 # Ensure we have accept=all for lnet
285 if [ $(basename $module) = lnet ]; then
286 # OK, this is a bit wordy...
287 local arg accept_all_present=false
289 [ "$arg" = accept=all ] && accept_all_present=true
291 $accept_all_present || set -- "$@" accept=all
296 [ $# -gt 0 ] && echo "${module} options: '$*'"
298 # Note that insmod will ignore anything in modprobe.conf, which is why we're
299 # passing options on the command-line.
300 if [ "$BASE" == "lnet_selftest" ] && \
301 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
302 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
303 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
304 insmod ${LUSTRE}/${module}${EXT} "$@"
306 # must be testing a "make install" or "rpm" installation
307 # note failed to load ptlrpc_gss is considered not fatal
308 if [ "$BASE" == "ptlrpc_gss" ]; then
309 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
316 load_modules_local() {
317 if [ -n "$MODPROBE" ]; then
319 echo "Using modprobe to load modules"
323 echo Loading modules from $LUSTRE
324 load_module ../libcfs/libcfs/libcfs
325 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
326 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
327 load_module ../lnet/lnet/lnet
328 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
329 load_module ../lnet/klnds/$LNETLND
330 load_module lvfs/lvfs
331 load_module obdclass/obdclass
332 load_module ptlrpc/ptlrpc
333 load_module ptlrpc/gss/ptlrpc_gss
334 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
342 if ! client_only; then
343 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
344 grep -q jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
345 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
350 load_module lvfs/fsfilt_$FSTYPE
352 load_module osd-ldiskfs/osd_ldiskfs
354 load_module obdfilter/obdfilter
357 load_module llite/lustre
358 load_module llite/llite_lloop
359 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
361 rm -f $OGDB/ogdb-$HOSTNAME
362 $LCTL modules > $OGDB/ogdb-$HOSTNAME
364 # 'mount' doesn't look in $PATH, just sbin
365 [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
371 # load modules on remote nodes optionally
372 # lustre-tests have to be installed on these nodes
373 if $LOAD_MODULES_REMOTE ; then
374 local list=$(comma_list $(remote_nodes_list))
375 echo loading modules on $list
376 do_rpc_nodes $list load_modules
381 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
382 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
383 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
384 echo "$LEAK_LUSTRE" 1>&2
385 echo "$LEAK_PORTALS" 1>&2
386 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
387 echo "Memory leaks detected"
388 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
394 wait_exit_ST client # bug 12845
396 $LUSTRE_RMMOD $FSTYPE || return 2
398 if $LOAD_MODULES_REMOTE ; then
399 local list=$(comma_list $(remote_nodes_list))
400 if [ ! -z $list ]; then
401 echo unloading modules on $list
402 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
403 do_rpc_nodes $list check_mem_leak
407 check_mem_leak || return 254
409 echo "modules unloaded."
413 check_gss_daemon_nodes() {
417 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
418 if [ \\\"\\\$num\\\" -ne 1 ]; then
419 echo \\\$num instance of $dname;
424 check_gss_daemon_facet() {
428 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
429 if [ $num -ne 1 ]; then
430 echo "$num instance of $dname on $facet"
439 echo Stopping $@ on $list
440 do_nodes $list "killall -2 $@ 2>/dev/null || true"
443 # start gss daemons on all nodes, or
444 # "daemon" on "list" if set
445 start_gss_daemons() {
449 if [ "$list" ] && [ "$daemon" ] ; then
450 echo "Starting gss daemon on nodes: $list"
451 do_nodes $list "$daemon" || return 8
455 local list=$(comma_list $(mdts_nodes))
457 echo "Starting gss daemon on mds: $list"
458 do_nodes $list "$LSVCGSSD -v" || return 1
460 do_nodes $list "$LGSSD -v" || return 2
463 list=$(comma_list $(osts_nodes))
464 echo "Starting gss daemon on ost: $list"
465 do_nodes $list "$LSVCGSSD -v" || return 3
466 # starting on clients
468 local clients=${CLIENTS:-`hostname`}
470 echo "Starting $LGSSD on clients $clients "
471 do_nodes $clients "$LGSSD -v" || return 4
474 # wait daemons entering "stable" status
478 # check daemons are running
480 list=$(comma_list $(mdts_nodes) $(osts_nodes))
481 check_gss_daemon_nodes $list lsvcgssd || return 5
483 list=$(comma_list $(mdts_nodes))
484 check_gss_daemon_nodes $list lgssd || return 6
487 check_gss_daemon_nodes $clients lgssd || return 7
492 local list=$(comma_list $(mdts_nodes))
494 send_sigint $list lsvcgssd lgssd
496 list=$(comma_list $(osts_nodes))
497 send_sigint $list lsvcgssd
499 list=${CLIENTS:-`hostname`}
500 send_sigint $list lgssd
505 if ! module_loaded ptlrpc_gss; then
506 load_module ptlrpc/gss/ptlrpc_gss
507 module_loaded ptlrpc_gss ||
508 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
510 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
512 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
513 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
521 # maybe cleanup credential cache?
527 local device=`mdsdevname $num`
528 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
534 local device=`ostdevname $num`
535 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
541 local facets=${1:-$(get_facets)}
544 for facet in ${facets//,/ }; do
545 mount_facet $facet || error "Restart of $facet failed!"
552 local dev=$(facet_active $facet)_dev
553 local opt=${facet}_opt
554 local mntpt=$(facet_mntpt $facet)
556 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
557 do_facet ${facet} mount -t lustre ${!opt} $@ ${!dev} $mntpt
559 if [ $RC -ne 0 ]; then
560 echo "mount -t lustre $@ ${!dev} $mntpt"
561 echo "Start of ${!dev} on ${facet} failed ${RC}"
563 do_facet ${facet} "lctl set_param debug=\\\"$PTLDEBUG\\\"; \
564 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\"; \
565 lctl set_param debug_mb=${DEBUG_SIZE}; \
568 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
569 [ -z "$label" ] && echo no label for ${!dev} && exit 1
570 eval export ${facet}_svc=${label}
571 echo Started ${label}
576 # start facet device options
582 eval export ${facet}_dev=${device}
583 eval export ${facet}_opt=\"$@\"
585 local varname=${facet}failover_dev
586 if [ -n "${!varname}" ] ; then
587 eval export ${facet}failover_dev=${!varname}
589 eval export ${facet}failover_dev=$device
592 local mntpt=$(facet_mntpt $facet)
593 do_facet ${facet} mkdir -p $mntpt
594 eval export ${facet}_MOUNT=$mntpt
604 local HOST=`facet_active_host $facet`
605 [ -z $HOST ] && echo stop: no host for $facet && return 0
607 local mntpt=$(facet_mntpt $facet)
608 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
609 if [ ${running} -ne 0 ]; then
610 echo "Stopping $mntpt (opts:$@)"
611 do_facet ${facet} umount -d $@ $mntpt
614 # umount should block, but we should wait for unrelated obd's
615 # like the MGS or MGC to also stop.
616 wait_exit_ST ${facet}
619 # save quota version (both administrative and operational quotas)
620 # add an additional parameter if mountpoint is ever different from $MOUNT
621 quota_save_version() {
622 local fsname=${2:-$FSNAME}
624 local ver=$(tr -c -d "123" <<< $spec)
625 local type=$(tr -c -d "ug" <<< $spec)
627 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
629 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
631 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
633 local osts=$(get_facets OST)
634 for ost in ${osts//,/ }; do
636 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
640 # client could mount several lustre
642 local fsname=${1:-$FSNAME}
644 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
645 do_nodes $(comma_list $(osts_nodes)) \
646 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
650 restore_quota_type () {
651 local mntpt=${1:-$MOUNT}
652 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
653 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
656 quota_save_version $old_QUOTA_TYPE
662 # We need save the original quota_type params, and restore them after testing
664 # Suppose that quota type the same on mds and ost
665 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
666 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
667 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
668 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
669 export old_QUOTA_TYPE=$quota_type
670 quota_save_version $QUOTA_TYPE
672 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
673 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
676 local quota_usrs=$QUOTA_USERS
678 # get_filesystem_size
679 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
680 local blk_soft=$((disksz + 1024))
681 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
683 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
685 local i_hard=$((i_soft + i_soft / 20))
687 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
688 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
691 for usr in $quota_usrs; do
692 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
694 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
696 eval $cmd || error "$cmd FAILED!"
698 # display the quota status
699 echo "Quota settings for $usr : "
700 $LFS quota -v -u $usr $mntpt || true
708 # Only supply -o to mount if we have options
709 if [ -n "$MOUNTOPT" ]; then
710 OPTIONS="-o $MOUNTOPT"
712 local device=$MGSNID:/$FSNAME
713 if [ -z "$mnt" -o -z "$FSNAME" ]; then
714 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
718 echo "Starting client: $client: $OPTIONS $device $mnt"
719 do_node $client mkdir -p $mnt
720 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
722 do_node $client "lctl set_param debug=\\\"$PTLDEBUG\\\";
723 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
724 lctl set_param debug_mb=${DEBUG_SIZE}"
737 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
738 if [ $running -ne 0 ]; then
739 echo "Stopping client $client $mnt (opts:$force)"
740 do_node $client lsof -t $mnt || need_kill=no
741 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
742 pids=$(do_node $client lsof -t $mnt | sort -u);
743 if [ -n $pids ]; then
744 do_node $client kill -9 $pids || true
748 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
749 if [ $busy -ne 0 ] ; then
750 echo "$mnt is still busy, wait one second" && sleep 1
751 do_node $client umount $force $mnt
756 # nodes is comma list
757 sanity_mount_check_nodes () {
763 # FIXME: assume that all cluster nodes run the same os
764 [ "$(uname)" = Linux ] || return 0
767 for mnt in $mnts ; do
768 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
769 mpts=\\\$(mount | grep -w -c $mnt);
770 if [ \\\$running -ne \\\$mpts ]; then
771 echo \\\$(hostname) env are INSANE!;
779 sanity_mount_check_servers () {
781 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
782 echo Checking servers environments
784 # FIXME: modify get_facets to display all facets wo params
785 local facets="$(get_facets OST),$(get_facets MDS),mgs"
789 for facet in ${facets//,/ }; do
790 node=$(facet_host ${facet})
791 mntpt=$(facet_mntpt $facet)
792 sanity_mount_check_nodes $node $mntpt ||
793 { error "server $node environments are insane!"; return 1; }
797 sanity_mount_check_clients () {
798 local clients=${1:-$CLIENTS}
799 local mntpt=${2:-$MOUNT}
800 local mntpt2=${3:-$MOUNT2}
802 [ -z $clients ] && clients=$(hostname)
803 echo Checking clients $clients environments
805 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
806 error "clients environments are insane!"
809 sanity_mount_check () {
810 sanity_mount_check_servers || return 1
811 sanity_mount_check_clients || return 2
814 # mount clients if not mouted
815 zconf_mount_clients() {
818 local OPTIONS=${3:-$MOUNTOPT}
820 # Only supply -o to mount if we have options
821 if [ "$OPTIONS" ]; then
822 OPTIONS="-o $OPTIONS"
824 local device=$MGSNID:/$FSNAME
825 if [ -z "$mnt" -o -z "$FSNAME" ]; then
826 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
830 echo "Starting client $clients: $OPTIONS $device $mnt"
833 running=\\\$(mount | grep -c $mnt' ');
835 if [ \\\$running -eq 0 ] ; then
837 mount -t lustre $OPTIONS $device $mnt;
840 exit \\\$rc" || return ${PIPESTATUS[0]}
842 echo "Started clients $clients: "
843 do_nodes $clients "mount | grep -w $mnt"
845 do_nodes $clients "lctl set_param debug=\\\"$PTLDEBUG\\\";
846 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
847 lctl set_param debug_mb=${DEBUG_SIZE};"
852 zconf_umount_clients() {
859 echo "Stopping clients: $clients $mnt (opts:$force)"
860 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
861 if [ \\\$running -ne 0 ] ; then
862 echo Stopping client \\\$(hostname) $mnt opts:$force;
863 lsof -t $mnt || need_kill=no;
864 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
865 pids=\\\$(lsof -t $mnt | sort -u);
866 if [ -n \\\"\\\$pids\\\" ]; then
870 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
871 if [ \\\$busy -ne 0 ] ; then
872 echo "$mnt is still busy, wait one second" && sleep 1;
880 echo + $POWER_DOWN $node
884 shutdown_node_hard () {
888 for i in $(seq $attempts) ; do
891 ping -w 3 -c 1 $host > /dev/null 2>&1 || return 0
892 echo "waiting for $host to fail attempts=$attempts"
893 [ $i -lt $attempts ] || \
894 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
900 local mnt=${2:-$MOUNT}
903 if [ "$FAILURE_MODE" = HARD ]; then
904 shutdown_node_hard $client
906 zconf_umount_clients $client $mnt -f
912 local facets="$(get_facets OST),$(get_facets MDS)"
915 combined_mgs_mds || facets="$facets,mgs"
917 for facet in ${facets//,/ }; do
918 if [ $(facet_active_host $facet) == $host ]; then
919 affected="$affected $facet"
923 echo $(comma_list $affected)
928 local host=${2:-$(facet_host $facet)}
930 local label=$(convert_facet2label $facet)
931 do_node $host lctl dl | awk '{print $4}' | grep -q $label
934 facets_up_on_host () {
936 local facets=$(facets_on_host $host)
939 for facet in ${facets//,/ }; do
940 if $(facet_up $facet $host); then
941 affected_up="$affected_up $facet"
945 echo $(comma_list $affected_up)
951 if [ "$FAILURE_MODE" = HARD ]; then
952 shutdown_node_hard $(facet_active_host $facet)
960 echo + $POWER_UP $node
973 if [ "$FAILURE_MODE" = HARD ]; then
974 reboot_node $(facet_active_host $facet)
982 if [ "$FAILURE_MODE" = HARD ]; then
988 # recovery-scale functions
989 check_progs_installed () {
994 do_nodes $clients "PATH=:$PATH; status=true;
995 for prog in $progs; do
996 if ! [ \\\"\\\$(which \\\$prog)\\\" -o \\\"\\\${!prog}\\\" ]; then
997 echo \\\$prog missing on \\\$(hostname);
1005 echo __$(echo $1 | tr '-' 'X')
1008 start_client_load() {
1011 local var=$(client_var_name $client)_load
1012 eval export ${var}=$load
1014 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1015 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1016 END_RUN_FILE=$END_RUN_FILE \
1017 LOAD_PID_FILE=$LOAD_PID_FILE \
1018 TESTSUITELOG=$TESTSUITELOG \
1020 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
1021 log "Started client load: ${load} on $client"
1026 start_client_loads () {
1027 local -a clients=(${1//,/ })
1028 local numloads=${#CLIENT_LOADS[@]}
1031 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1032 testnum=$((nodenum % numloads))
1033 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1035 # bug 22169: wait the background threads to start
1039 # only for remote client
1040 check_client_load () {
1042 local var=$(client_var_name $client)_load
1043 local TESTLOAD=run_${!var}.sh
1045 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1047 # bug 18914: try to connect several times not only when
1048 # check ps, but while check_catastrophe also
1051 while [ $RC = 254 -a $tries -gt 0 ]; do
1055 if ! check_catastrophe $client; then
1057 if [ $RC -eq 254 ]; then
1058 # FIXME: not sure how long we shuold sleep here
1062 echo "check catastrophe failed: RC=$RC "
1066 # We can continue try to connect if RC=254
1067 # Just print the warning about this
1068 if [ $RC = 254 ]; then
1069 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1072 # see if the load is still on the client
1075 while [ $RC = 254 -a $tries -gt 0 ]; do
1079 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1084 if [ $RC = 254 ]; then
1085 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1086 # see if we can diagnose a bit why this is
1091 check_client_loads () {
1092 local clients=${1//,/ }
1096 for client in $clients; do
1097 check_client_load $client
1099 if [ "$rc" != 0 ]; then
1100 log "Client load failed on node $client, rc=$rc"
1106 restart_client_loads () {
1107 local clients=${1//,/ }
1108 local expectedfail=${2:-""}
1112 for client in $clients; do
1113 check_client_load $client
1115 if [ "$rc" != 0 -a "$expectedfail" ]; then
1116 local var=$(client_var_name $client)_load
1117 start_client_load $client ${!var}
1118 echo "Restarted client load ${!var}: on $client. Checking ..."
1119 check_client_load $client
1121 if [ "$rc" != 0 ]; then
1122 log "Client load failed to restart on node $client, rc=$rc"
1123 # failure one client load means test fail
1124 # we do not need to check other
1132 # End recovery-scale functions
1134 # verify that lustre actually cleaned up properly
1136 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1137 error "LBUG/LASSERT detected"
1138 BUSY=`dmesg | grep -i destruct || true`
1139 if [ "$BUSY" ]; then
1141 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1145 check_mem_leak || exit 204
1147 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1148 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1150 if module_loaded lnet || module_loaded libcfs; then
1151 echo "$0: modules still loaded..." 1>&2
1168 RESULT=$(do_node $node "$TEST")
1169 if [ "$RESULT" == "$FINAL" ]; then
1170 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1173 [ $WAIT -ge $MAX ] && break
1174 echo "Waiting $((MAX - WAIT)) secs for update"
1175 WAIT=$((WAIT + sleep))
1178 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1182 wait_update_facet () {
1184 wait_update $(facet_active_host $facet) "$@"
1187 wait_delete_completed () {
1188 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1189 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1193 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1195 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1196 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1197 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1198 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1202 echo "Delete is not completed in $MAX_WAIT sec"
1209 # we can use "for" here because we are waiting the slowest
1210 for host in ${hostlist//,/ }; do
1211 check_network "$host" 900
1213 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1220 for facet in ${facetlist//,/ }; do
1221 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1223 wait_for_host $hostlist
1226 _wait_recovery_complete () {
1229 # Use default policy if $2 is not passed by caller.
1230 local MAX=${2:-$(max_recovery_time)}
1235 while [ $WAIT -lt $MAX ]; do
1236 STATUS=$(lctl get_param -n $param | grep status)
1238 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1241 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1243 echo "$param recovery not done in $MAX sec. $STATUS"
1247 wait_recovery_complete () {
1250 # with an assumption that at_max is the same on all nodes
1251 local MAX=${2:-$(max_recovery_time)}
1254 if [ "$FAILURE_MODE" = HARD ]; then
1255 facets=$(facets_on_host $(facet_active_host $facet))
1257 echo affected facets: $facets
1259 # we can use "for" here because we are waiting the slowest
1260 for facet in ${facets//,/ }; do
1261 local var_svc=${facet}_svc
1262 local param="*.${!var_svc}.recovery_status"
1264 local host=$(facet_active_host $facet)
1265 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1269 wait_mds_ost_sync () {
1270 # just because recovery is done doesn't mean we've finished
1271 # orphan cleanup. Wait for llogs to get synchronized.
1272 echo "Waiting for orphan cleanup..."
1273 # MAX value includes time needed for MDS-OST reconnection
1274 local MAX=$(( TIMEOUT * 2 ))
1276 while [ $WAIT -lt $MAX ]; do
1277 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1278 "$LCTL get_param -n obdfilter.*.mds_sync"))
1281 for ((i=0; i<${#sync[@]}; i++)); do
1282 [ ${sync[$i]} -eq 0 ] && continue
1283 # there is a not finished MDS-OST synchronization
1287 sleep 2 # increase waiting time and cover statfs cache
1288 [ ${con} -eq 1 ] && return 0
1289 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1292 echo "$facet recovery not done in $MAX sec. $STATUS"
1296 wait_destroy_complete () {
1297 echo "Waiting for destroy to be done..."
1298 # MAX value shouldn't be big as this mean server responsiveness
1299 # never increase this just to make test pass but investigate
1300 # why it takes so long time
1303 while [ $WAIT -lt $MAX ]; do
1304 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1306 for ((i=0; i<${#RPCs[@]}; i++)); do
1307 [ ${RPCs[$i]} -eq 0 ] && continue
1308 # there are still some destroy RPCs in flight
1313 [ ${con} -eq 1 ] && return 0 # done waiting
1314 echo "Waiting $WAIT secs for destroys to be done."
1317 echo "Destroys weren't done in $MAX sec."
1327 # conf-sanity 31 takes a long time cleanup
1328 while [ $WAIT -lt 300 ]; do
1329 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1330 [ -z "${running}" ] && return 0
1331 echo "waited $WAIT for${running}"
1332 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1334 WAIT=$((WAIT + INTERVAL))
1336 echo "service didn't stop after $WAIT seconds. Still running:"
1341 wait_remote_prog () {
1347 [ "$PDSH" = "no_dsh" ] && return 0
1349 while [ $WAIT -lt $2 ]; do
1350 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1351 [ -z "${running}" ] && return 0 || true
1352 echo "waited $WAIT for: "
1354 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1356 WAIT=$((WAIT + INTERVAL))
1358 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1359 [ -z "$pids" ] && return 0
1360 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1361 # FIXME: not portable
1362 for pid in $pids; do
1363 cat /proc/${pid}/status || true
1364 cat /proc/${pid}/wchan || true
1366 kill -9 $pid || true
1375 # not every config has many clients
1377 if [ ! -z "$CLIENTS" ]; then
1378 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1380 stat -f $MOUNT > /dev/null
1386 # usually checked on particular client or locally
1388 if [ ! -z "$client" ]; then
1389 $PDSH $client "stat -f $MOUNT" > /dev/null
1391 stat -f $MOUNT > /dev/null
1399 client_reconnect() {
1400 uname -n >> $MOUNT/recon
1401 if [ -z "$CLIENTS" ]; then
1402 df $MOUNT; uname -n >> $MOUNT/recon
1404 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1406 echo Connected clients:
1408 ls -l $MOUNT/recon > /dev/null
1412 affected_facets () {
1415 local host=$(facet_active_host $facet)
1416 local affected=$facet
1418 if [ "$FAILURE_MODE" = HARD ]; then
1419 affected=$(facets_up_on_host $host)
1427 local host=$(facet_active_host $facet)
1429 echo "Failing $facet on node $host"
1431 local affected=$(affected_facets $facet)
1433 shutdown_facet $facet
1435 echo affected facets: $affected
1437 [ -n "$sleep_time" ] && sleep $sleep_time
1441 change_active $affected
1443 wait_for_facet $affected
1444 # start mgs first if it is affected
1445 if ! combined_mgs_mds && list_member $affected mgs; then
1446 mount_facet mgs || error "Restart of mgs failed"
1448 # FIXME; has to be changed to mount all facets concurrently
1449 affected=$(exclude_items_from_list $affected mgs)
1450 mount_facets $affected
1459 do_facet $facet sync
1461 local svc=${facet}_svc
1462 do_facet $facet $LCTL --device %${!svc} notransno
1463 do_facet $facet $LCTL --device %${!svc} readonly
1464 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1465 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1468 replay_barrier_nodf() {
1469 local facet=$1 echo running=${running}
1470 do_facet $facet sync
1471 local svc=${facet}_svc
1472 echo Replay barrier on ${!svc}
1473 do_facet $facet $LCTL --device %${!svc} notransno
1474 do_facet $facet $LCTL --device %${!svc} readonly
1475 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1476 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1479 replay_barrier_nosync() {
1480 local facet=$1 echo running=${running}
1481 local svc=${facet}_svc
1482 echo Replay barrier on ${!svc}
1483 do_facet $facet $LCTL --device %${!svc} notransno
1484 do_facet $facet $LCTL --device %${!svc} readonly
1485 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1486 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1489 mds_evict_client() {
1490 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1491 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1494 ost_evict_client() {
1495 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1496 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1500 facet_failover $* || error "failover: $?"
1501 clients_up || error "post-failover df: $?"
1506 facet_failover $facet
1512 change_active $facet
1513 mount_facet $facet -o abort_recovery
1514 clients_up || echo "first df failed: $?"
1515 clients_up || error "post-failover df: $?"
1519 echo There is no lmc. This is mountconf, baby.
1524 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1530 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1531 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1532 if [ -z "$ID" ]; then
1533 echo "Could not get a ptl id for $1..."
1542 h2name_or_ip "$1" "tcp"
1547 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1548 if type __h2elan >/dev/null 2>&1; then
1551 ID=`echo $1 | sed 's/[^0-9]*//g'`
1559 h2name_or_ip "$1" "o2ib"
1566 [ "$facet" == client ] && echo -n $HOSTNAME && return
1567 varname=${facet}_HOST
1568 if [ -z "${!varname}" ]; then
1569 if [ "${facet:0:3}" == "ost" ]; then
1570 eval ${facet}_HOST=${ost_HOST}
1578 local activevar=${facet}active
1580 if [ -f $TMP/${facet}active ] ; then
1581 source $TMP/${facet}active
1584 active=${!activevar}
1585 if [ -z "$active" ] ; then
1592 facet_active_host() {
1594 local active=`facet_active $facet`
1595 if [ "$facet" == client ]; then
1598 echo `facet_host $active`
1606 facetlist=$(exclude_items_from_list $facetlist mgs)
1608 for facet in ${facetlist//,/ }; do
1609 local failover=${facet}failover
1610 local host=`facet_host $failover`
1611 [ -z "$host" ] && return
1613 local curactive=`facet_active $facet`
1614 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1615 eval export ${facet}active=$facet
1617 eval export ${facet}active=$failover
1619 # save the active host for this facet
1620 local activevar=${facet}active
1621 echo "$activevar=${!activevar}" > $TMP/$activevar
1622 local TO=`facet_active_host $facet`
1623 echo "Failover $facet to $TO"
1629 # do not stripe off hostname if verbose, bug 19215
1630 if [ x$1 = x--verbose ]; then
1638 if [ "$HOST" = "$HOSTNAME" ]; then
1640 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1641 echo "cannot run remote command on $HOST with $myPDSH"
1645 echo "CMD: $HOST $@" >&2
1646 $myPDSH $HOST $LCTL mark "$@" > /dev/null 2>&1 || :
1649 if [ "$myPDSH" = "rsh" ]; then
1650 # we need this because rsh does not return exit code of an executed command
1651 local command_status="$TMP/cs"
1652 rsh $HOST ":> $command_status"
1653 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1654 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1655 echo command failed >$command_status"
1656 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1661 # print HOSTNAME for myPDSH="no_dsh"
1662 if [[ $myPDSH = no_dsh ]]; then
1663 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1665 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1668 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1670 return ${PIPESTATUS[0]}
1674 do_node --verbose "$@"
1677 single_local_node () {
1678 [ "$1" = "$HOSTNAME" ]
1681 # Outputs environment variable assignments that should be passed to remote nodes
1686 for var in ${!MODOPTS_*}; do
1688 echo "${var}=\"$value\""
1694 # do not stripe off hostname if verbose, bug 19215
1695 if [ x$1 = x--verbose ]; then
1703 if single_local_node $rnodes; then
1705 do_nodev $rnodes "$@"
1707 do_node $rnodes "$@"
1712 # This is part from do_node
1715 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1716 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1719 echo "CMD: $rnodes $@" >&2
1720 $myPDSH $rnodes $LCTL mark "$@" > /dev/null 2>&1 || :
1723 # do not replace anything from pdsh output if -N is used
1724 # -N Disable hostname: prefix on lines of output.
1725 if $verbose || [[ $myPDSH = *-N* ]]; then
1726 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1728 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1730 return ${PIPESTATUS[0]}
1736 local HOST=`facet_active_host $facet`
1737 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1742 do_nodes --verbose "$@"
1748 # make sure its not already running
1750 rm -f $TMP/${facet}active
1751 do_facet ${facet} $MKFS $*
1757 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1758 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1765 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1766 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1772 local var=${facet}_MOUNT
1773 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1782 # make sure we are using the primary server, so test-framework will
1783 # be able to clean up properly.
1784 activemds=`facet_active mds1`
1785 if [ $activemds != "mds1" ]; then
1789 local clients=$CLIENTS
1790 [ -z $clients ] && clients=$(hostname)
1792 zconf_umount_clients $clients $MOUNT "$*" || true
1793 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
1795 [ "$CLIENTONLY" ] && return
1796 # The add fn does rm ${facet}active file, this would be enough
1797 # if we use do_facet <facet> only after the facet added, but
1798 # currently we use do_facet mds in local.sh
1799 for num in `seq $MDSCOUNT`; do
1801 rm -f ${TMP}/mds${num}active
1804 for num in `seq $OSTCOUNT`; do
1806 rm -f $TMP/ost${num}active
1809 if ! combined_mgs_mds ; then
1816 cleanup_echo_devs () {
1817 local devs=$($LCTL dl | grep echo | awk '{print $4}')
1819 for dev in $devs; do
1820 $LCTL --device $dev cleanup
1821 $LCTL --device $dev detach
1826 nfs_client_mode && return
1835 combined_mgs_mds () {
1836 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
1842 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
1843 local optvar=${tgt}_MKFS_OPTS
1844 local opt=${!optvar}
1846 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
1847 [[ $facet = mgs ]] && echo $opt && return
1850 # --failnode options
1851 local var=${facet}failover_HOST
1852 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
1853 local failnode=$(h2$NETTYPE ${!var})
1854 failnode="--failnode=$failnode"
1855 # options does not contain
1856 # or contains wrong --failnode=
1857 if [[ $opt != *${failnode}* ]]; then
1858 opt=$(echo $opt | sed 's/--failnode=.* / /')
1859 opt="$opt $failnode"
1865 # no additional mkfs mds "--mgsnode" option for this configuration
1866 if [[ $facet = mds ]] && combined_mgs_mds; then
1871 # additional mkfs "--mgsnode"
1872 local mgsnode="--mgsnode=$MGSNID"
1873 opt=${opt//$mgsnode }
1874 for nid in ${MGSNID//:/ }; do
1875 local mgsnode="--mgsnode=$nid"
1876 # options does not contain
1878 if [[ $opt != *${mgsnode}" "* ]]; then
1879 opt="$opt --mgsnode=$nid"
1887 if [ "$IAMDIR" == "yes" ]; then
1888 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
1891 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
1894 # We need ldiskfs here, may as well load them all
1896 [ "$CLIENTONLY" ] && return
1897 echo Formatting mgs, mds, osts
1898 if ! combined_mgs_mds ; then
1899 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
1902 for num in `seq $MDSCOUNT`; do
1903 echo "Format mds$num: $(mdsdevname $num)"
1905 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
1907 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
1911 # the ost-s could have different OST_MKFS_OPTS
1912 # because of different failnode-s
1913 for num in `seq $OSTCOUNT`; do
1914 echo "Format ost$num: $(ostdevname $num)"
1916 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
1918 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
1924 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
1928 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
1932 # 0: success, the old identity set already.
1933 # 1: success, the old identity does not set.
1938 local j=`expr $num - 1`
1939 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
1941 if [ -z "$MDT" ]; then
1945 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
1948 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
1950 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
1953 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
1955 if [ $old = "NONE" ]; then
1964 zconf_umount `hostname` $1 || error "umount failed"
1965 zconf_mount `hostname` $1 || error "mount failed"
1968 writeconf_facet () {
1972 do_facet $facet "$TUNEFS --writeconf $dev"
1976 for num in `seq $MDSCOUNT`; do
1977 DEVNAME=$(mdsdevname $num)
1978 writeconf_facet mds$num $DEVNAME
1981 for num in `seq $OSTCOUNT`; do
1982 DEVNAME=$(ostdevname $num)
1983 writeconf_facet ost$num $DEVNAME
1988 nfs_client_mode && return
1990 sanity_mount_check ||
1991 error "environments are insane!"
1995 if [ -z "$CLIENTONLY" ]; then
1996 echo Setup mgs, mdt, osts
1997 echo $WRITECONF | grep -q "writeconf" && \
1999 if ! combined_mgs_mds ; then
2000 start mgs $MGSDEV $MGS_MOUNT_OPTS
2003 for num in `seq $MDSCOUNT`; do
2004 DEVNAME=$(mdsdevname $num)
2005 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2007 # We started mds, now we should set failover variables properly.
2008 # Set mds${num}failover_HOST if it is not set (the default failnode).
2009 local varname=mds${num}failover_HOST
2010 if [ -z "${!varname}" ]; then
2011 eval mds${num}failover_HOST=$(facet_host mds$num)
2014 if [ $IDENTITY_UPCALL != "default" ]; then
2015 switch_identity $num $IDENTITY_UPCALL
2018 for num in `seq $OSTCOUNT`; do
2019 DEVNAME=$(ostdevname $num)
2020 start ost$num $DEVNAME $OST_MOUNT_OPTS
2022 # We started ost$num, now we should set ost${num}failover variable properly.
2023 # Set ost${num}failover_HOST if it is not set (the default failnode).
2024 varname=ost${num}failover_HOST
2025 if [ -z "${!varname}" ]; then
2026 eval ost${num}failover_HOST=$(facet_host ost${num})
2034 # wait a while to allow sptlrpc configuration be propogated to targets,
2035 # only needed when mounting new target devices.
2040 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2042 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2044 if [ "$MOUNT_2" ]; then
2045 mount_client $MOUNT2
2046 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2051 # by remounting mdt before ost, initial connect from mdt to ost might
2052 # timeout because ost is not ready yet. wait some time to its fully
2053 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2054 # by a context negotiation rpc with $TIMEOUT.
2055 # FIXME better by monitoring import status.
2058 sleep $((TIMEOUT + 5))
2064 mounted_lustre_filesystems() {
2065 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2068 init_facet_vars () {
2069 [ "$CLIENTONLY" ] && return 0
2076 eval export ${facet}_dev=${device}
2077 eval export ${facet}_opt=\"$@\"
2079 local dev=${facet}_dev
2080 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2081 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2083 eval export ${facet}_svc=${label}
2085 local varname=${facet}failover_HOST
2086 if [ -z "${!varname}" ]; then
2087 eval $varname=$(facet_host $facet)
2090 # ${facet}failover_dev is set in cfg file
2091 varname=${facet}failover_dev
2092 if [ -n "${!varname}" ] ; then
2093 eval export ${facet}failover_dev=${!varname}
2095 eval export ${facet}failover_dev=$device
2098 # get mount point of already mounted device
2099 # is facet_dev is already mounted then use the real
2100 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2101 # i.e. ${facet}_MOUNT if specified by user or default
2102 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2103 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2104 if [ -z $mntpt ]; then
2105 mntpt=$(facet_mntpt $facet)
2107 eval export ${facet}_MOUNT=$mntpt
2110 init_facets_vars () {
2113 if ! remote_mds_nodsh; then
2114 for num in `seq $MDSCOUNT`; do
2115 DEVNAME=`mdsdevname $num`
2116 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2120 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2122 remote_ost_nodsh && return
2124 for num in `seq $OSTCOUNT`; do
2125 DEVNAME=`ostdevname $num`
2126 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2130 osc_ensure_active () {
2135 while [ $period -lt $timeout ]; do
2136 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2137 if [ $count -eq 0 ]; then
2141 echo "There are $count OST are inactive, wait $period seconds, and try again"
2143 period=$((period+3))
2146 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2149 init_param_vars () {
2150 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2151 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2152 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2153 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2157 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2159 log "Using TIMEOUT=$TIMEOUT"
2161 osc_ensure_active $SINGLEMDS $TIMEOUT
2162 osc_ensure_active client $TIMEOUT
2164 if [ $QUOTA_AUTO -ne 0 ]; then
2165 if [ "$ENABLE_QUOTA" ]; then
2166 echo "enable quota as required"
2167 setup_quota $MOUNT || return 2
2169 echo "disable quota as required"
2170 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2177 nfs_client_mode () {
2178 if [ "$NFSCLIENT" ]; then
2179 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2180 local clients=$CLIENTS
2181 [ -z $clients ] && clients=$(hostname)
2183 # FIXME: remove hostname when 19215 fixed
2184 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2185 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2186 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2192 check_config_client () {
2195 local mounted=$(mount | grep " $mntpt ")
2196 if [ "$CLIENTONLY" ]; then
2198 # CLIENTONLY should not depend on *_HOST settings
2199 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2200 # in theory someone could create a new,
2201 # client-only config file that assumed lustre was already
2202 # configured and didn't set the MGSNID. If MGSNID is not set,
2203 # then we should use the mgs nid currently being used
2204 # as the default value. bug 18021
2205 [[ x$MGSNID = x ]] &&
2208 if [[ x$mgc != xMGC$MGSNID ]]; then
2209 if [ "$mgs_HOST" ]; then
2210 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2211 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2212 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2218 local myMGS_host=$mgs_HOST
2219 if [ "$NETTYPE" = "ptl" ]; then
2220 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2223 echo Checking config lustre mounted on $mntpt
2224 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2225 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2227 # if [ "$mgshost" != "$myMGS_host" ]; then
2228 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2229 # Please use correct config or set mds_HOST correctly!"
2234 check_config_clients () {
2235 local clients=${CLIENTS:-$HOSTNAME}
2238 nfs_client_mode && return
2240 do_rpc_nodes $clients check_config_client $mntpt
2242 sanity_mount_check ||
2243 error "environments are insane!"
2247 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2248 local cltimeout=$(lctl get_param -n timeout)
2249 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2250 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2257 [ -z $mntpt ] && return 1
2258 local mounted=$(mounted_lustre_filesystems)
2260 echo $mounted' ' | grep -w -q $mntpt' '
2264 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2268 # empty lustre filesystem may have empty directories lost+found and .lustre
2270 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2271 -print | wc -l) = 1 ] || return 1
2272 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2273 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2277 check_and_setup_lustre() {
2278 nfs_client_mode && return
2280 local MOUNTED=$(mounted_lustre_filesystems)
2284 # both MOUNT and MOUNT2 are not mounted
2285 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2286 [ "$REFORMAT" ] && formatall
2287 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2289 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2290 export I_MOUNTED=yes
2294 elif is_mounted $MOUNT2; then
2296 # MOUNT2 is mounted, while MOUNT_2 is not set
2297 if ! [ "$MOUNT_2" ]; then
2298 cleanup_mount $MOUNT2
2299 export I_UMOUNTED2=yes
2302 # MOUNT2 is mounted, MOUNT_2 is set
2304 # FIXME: what to do if check_config failed?
2306 # 1) remote client has mounted other Lustre fs ?
2307 # 2) it has insane env ?
2308 # let's try umount MOUNT2 on all clients and mount it again:
2309 if ! check_config_clients $MOUNT2; then
2310 cleanup_mount $MOUNT2
2311 restore_mount $MOUNT2
2312 export I_MOUNTED2=yes
2317 # MOUNT is mounted MOUNT2 is not mounted
2318 elif [ "$MOUNT_2" ]; then
2319 restore_mount $MOUNT2
2320 export I_MOUNTED2=yes
2324 # FIXME: what to do if check_config failed?
2326 # 1) remote client has mounted other Lustre fs?
2327 # 2) lustre is mounted on remote_clients atall ?
2328 check_config_clients $MOUNT
2332 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=\\\"$PTLDEBUG\\\";
2333 lctl set_param subsystem_debug=\\\"${SUBSYSTEM# }\\\";
2334 lctl set_param debug_mb=${DEBUG_SIZE};
2341 if [ "$ONLY" == "setup" ]; then
2347 local clients=${CLIENTS:-$HOSTNAME}
2350 zconf_mount_clients $clients $mntpt
2354 local clients=${CLIENTS:-$HOSTNAME}
2357 zconf_umount_clients $clients $mntpt
2360 cleanup_and_setup_lustre() {
2361 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2362 lctl set_param debug=0 || true
2364 if [ "$ONLY" == "cleanup" ]; then
2368 check_and_setup_lustre
2371 # Get all of the server target devices from a given server node and type.
2380 mdt) obd_type="osd" ;;
2381 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2382 *) echo "invalid server type" && return 1 ;;
2385 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2386 for dev in $devs; do
2388 *loop*) do_node $node "losetup $dev" | \
2389 sed -e "s/.*(//" -e "s/).*//" ;;
2395 # Get all of the server target devices.
2400 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2404 for node in $(osts_nodes); do
2405 OSTDEVS[i]=$(get_mnt_devs $node ost)
2410 # Run e2fsck on MDT or OST device.
2417 df > /dev/null # update statfs data on disk
2418 local cmd="$E2FSCK -d -v -f -n $MDSDB_OPT $ostdb_opt $target_dev"
2421 do_node $node $cmd || rc=$?
2422 [ $rc -le $FSCK_MAX_ERR ] || \
2423 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2427 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2434 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2435 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2436 error "fail to create file in $SHARED_DIRECTORY")
2438 # make sure everything gets to the backing store
2439 local list=$(comma_list $CLIENTS $(facet_host $SINGLEMDS) $(osts_nodes))
2440 do_nodes $list "sync; sleep 2; sync"
2442 do_nodes $list ls $tmp_file || \
2443 error "$SHARED_DIRECTORY is not a shared directory"
2446 run_e2fsck $(mdts_nodes) $MDTDEV
2451 for node in $(osts_nodes); do
2452 for dev in ${OSTDEVS[i]}; do
2453 local ostdb_opt=`eval echo $OSTDB_OPT`
2454 run_e2fsck $node $dev $ostidx "$ostdb_opt"
2455 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2456 ostidx=$((ostidx + 1))
2463 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2467 [ $rc -le $FSCK_MAX_ERR ] || \
2468 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2469 echo "lfsck finished with rc=$rc"
2471 rm -rvf $MDSDB* $OSTDB* || true
2475 check_and_cleanup_lustre() {
2476 if [ "$LFSCK_ALWAYS" = "yes" ]; then
2479 if [ "$SKIP_LFSCK" == "no" ]; then
2486 if is_mounted $MOUNT; then
2487 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2488 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2491 if [ "$I_UMOUNTED2" = "yes" ]; then
2492 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2495 if [ "$I_MOUNTED2" = "yes" ]; then
2496 cleanup_mount $MOUNT2
2499 if [ "$I_MOUNTED" = "yes" ]; then
2500 cleanupall -f || error "cleanup failed"
2512 while [ $NETWORK -eq 0 ]; do
2513 if ping -c 1 -w 3 $1 > /dev/null; then
2517 echo "waiting for $1, $((MAX - WAIT)) secs left"
2520 if [ $WAIT -gt $MAX ]; then
2521 echo "Network not available"
2527 while( !($DSH2 $1 "netstat -tna | grep -q $2") ) ; do
2538 # the sed converts spaces to commas, but leaves the last space
2539 # alone, so the line doesn't end with a comma.
2540 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2546 echo $list | grep -qw $item
2549 # list, excluded are the comma separated lists
2550 exclude_items_from_list () {
2556 for item in ${excluded//,/ }; do
2557 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2559 echo $(comma_list $list)
2562 # list, expand are the comma separated lists
2564 local list=${1//,/ }
2565 local expand=${2//,/ }
2568 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2569 echo $(comma_list $expanded)
2572 testslist_filter () {
2573 local script=$LUSTRE/tests/${TESTSUITE}.sh
2575 [ -f $script ] || return 0
2577 local start_at=$START_AT
2578 local stop_at=$STOP_AT
2580 local var=${TESTSUITE//-/_}_START_AT
2581 [ x"${!var}" != x ] && start_at=${!var}
2582 var=${TESTSUITE//-/_}_STOP_AT
2583 [ x"${!var}" != x ] && stop_at=${!var}
2585 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2586 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2587 /^'${start_at}'$/ {flag = 0}
2588 {if (flag == 1) print $0}
2589 /^'${stop_at}'$/ { flag = 1 }'
2593 (cd `dirname $1`; echo $PWD/`basename $1`)
2597 local types=${1:-"OST MDS MGS"}
2601 for entry in $types; do
2602 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2603 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2606 MGS ) list="$list $name";;
2607 MDS|OST ) local count=${type}COUNT
2608 for ((i=1; i<=${!count}; i++)) do
2609 list="$list ${name}$i"
2611 * ) error "Invalid facet type"
2615 echo $(comma_list $list)
2618 ##################################
2619 # Adaptive Timeouts funcs
2622 # only check mds, we assume at_max is the same on all nodes
2623 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2624 if [ $at_max -eq 0 ]; then
2634 # suppose that all ost-s has the same at_max set
2635 if [ $facet == "ost" ]; then
2636 do_facet ost1 "lctl get_param -n at_max"
2638 do_facet $facet "lctl get_param -n at_max"
2648 if [ $facet == "ost" ]; then
2649 for i in `seq $OSTCOUNT`; do
2650 do_facet ost$i "lctl set_param at_max=$at_max"
2653 elif [ $facet == "mds" ]; then
2654 for i in `seq $MDSCOUNT`; do
2655 do_facet mds$i "lctl set_param at_max=$at_max"
2658 do_facet $facet "lctl set_param at_max=$at_max"
2663 ##################################
2667 # OBD_FAIL_MDS_ALL_REQUEST_NET
2669 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2670 do_facet client "$1" || RC=$?
2671 do_facet $SINGLEMDS lctl set_param fail_loc=0
2676 # OBD_FAIL_MDS_ALL_REPLY_NET
2678 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2679 do_facet client "$@" || RC=$?
2680 do_facet $SINGLEMDS lctl set_param fail_loc=0
2684 drop_reint_reply() {
2685 # OBD_FAIL_MDS_REINT_NET_REP
2687 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2688 do_facet client "$@" || RC=$?
2689 do_facet $SINGLEMDS lctl set_param fail_loc=0
2694 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2696 do_facet ost1 lctl set_param fail_loc=0x214
2697 do_facet client "$1" || RC=$?
2698 do_facet client "sync"
2699 do_facet ost1 lctl set_param fail_loc=0
2703 drop_ldlm_cancel() {
2704 #define OBD_FAIL_LDLM_CANCEL 0x304
2706 do_facet client lctl set_param fail_loc=0x304
2707 do_facet client "$@" || RC=$?
2708 do_facet client lctl set_param fail_loc=0
2712 drop_bl_callback() {
2713 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2715 do_facet client lctl set_param fail_loc=0x305
2716 do_facet client "$@" || RC=$?
2717 do_facet client lctl set_param fail_loc=0
2722 #define OBD_FAIL_LDLM_REPLY 0x30c
2724 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2725 do_facet client "$@" || RC=$?
2726 do_facet $SINGLEMDS lctl set_param fail_loc=0
2734 echo "clearing fail_loc on $facet"
2735 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2738 set_nodes_failloc () {
2739 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2742 cancel_lru_locks() {
2743 $LCTL mark "cancel_lru_locks $1 start"
2744 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2745 $LCTL set_param -n $d=clear
2747 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2748 $LCTL mark "cancel_lru_locks $1 stop"
2753 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2754 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2755 echo "$DEFAULT_LRU_SIZE"
2760 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2763 lru_resize_disable()
2765 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2770 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2771 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2772 echo there is still data in page cache $FILE ?
2773 lctl get_param -n $FILE
2781 DEBUGSAVE="$(lctl get_param -n debug)"
2785 [ -n "$DEBUGSAVE" ] && \
2786 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
2791 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
2794 debug_size_restore() {
2795 [ -n "$DEBUG_SIZE_SAVED" ] && \
2796 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
2800 start_full_debug_logging() {
2805 local DEBUG_SIZE=150
2807 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
2808 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
2811 stop_full_debug_logging() {
2816 ##################################
2818 ##################################
2821 local TYPE=${TYPE:-"FAIL"}
2824 # do not dump logs if $1=false
2825 if [ "x$1" = "xfalse" ]; then
2830 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
2832 # We need to dump the logs on all nodes
2834 gather_logs $(comma_list $(nodes_list))
2838 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
2839 echo "$@" > $LOGDIR/err
2851 # use only if we are ignoring failures for this test, bugno required.
2852 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
2853 # e.g. error_ignore 5494 "your message"
2855 local TYPE="IGNORE (bz$1)"
2861 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
2866 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
2867 [ "$TESTSUITELOG" ] && \
2868 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
2871 build_test_filter() {
2872 EXCEPT="$EXCEPT $(testslist_filter)"
2874 [ "$ONLY" ] && log "only running test `echo $ONLY`"
2878 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
2879 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
2880 [ "$EXCEPT_SLOW" ] && \
2881 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
2882 for E in $EXCEPT $ALWAYS_EXCEPT; do
2883 eval EXCEPT_${E}=true
2885 for E in $EXCEPT_SLOW; do
2886 eval EXCEPT_SLOW_${E}=true
2888 for G in $GRANT_CHECK_LIST; do
2889 eval GCHECK_ONLY_${G}=true
2894 if [[ $1 = [a-z]* ]]; then
2901 # print a newline if the last test was skipped
2902 export LAST_SKIPPED=
2904 # Main entry into test-framework. This is called with the name and
2905 # description of a test. The name is used to find the function to run
2906 # the test using "test_$name".
2908 # This supports a variety of methods of specifying specific test to
2909 # run or not run. These need to be documented...
2914 export base=`basetest $1`
2915 if [ ! -z "$ONLY" ]; then
2917 if [ ${!testname}x != x ]; then
2918 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2919 run_one_logged $1 "$2"
2923 if [ ${!testname}x != x ]; then
2924 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
2925 run_one_logged $1 "$2"
2933 if [ ${!testname}x != x ]; then
2935 TESTNAME=test_$1 skip "skipping excluded test $1"
2938 testname=EXCEPT_$base
2939 if [ ${!testname}x != x ]; then
2941 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
2944 testname=EXCEPT_SLOW_$1
2945 if [ ${!testname}x != x ]; then
2947 TESTNAME=test_$1 skip "skipping SLOW test $1"
2950 testname=EXCEPT_SLOW_$base
2951 if [ ${!testname}x != x ]; then
2953 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
2958 run_one_logged $1 "$2"
2969 module_loaded lnet || load_modules
2981 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
2986 strace -o $TMP/$1.strace -ttt $*
2988 log "FINISHED: $*: rc $RC"
2993 # Set TEST_STATUS here; will be used for logging the result
2994 if [ -f $LOGDIR/err ]; then
2999 echo $TEST_STATUS " " $@
3003 FFREE=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filesfree | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
3004 FTOTAL=$(do_node $SINGLEMDS lctl get_param -n osd.*MDT*.filestotal | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
3005 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3009 echo -n "Resetting fail_loc on all nodes..."
3010 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3016 # Log a message (on all nodes) padded with "=" before and after.
3017 # Also appends a timestamp and prepends the testsuite name.
3020 EQUALS="===================================================================================================="
3022 msg="== ${TESTSUITE} $*"
3024 [[ $last != "=" && $last != " " ]] && msg="$msg "
3025 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3026 # always include at least == after the message
3027 log "$msg== $(date +"%H:%M:%S (%s)")"
3031 # Run a single test function and cleanup after it.
3033 # This function should be run in a subshell so the test func can
3034 # exit() without stopping the whole script.
3040 export tdir=d0.${TESTSUITE}/d${base}
3041 export TESTNAME=test_$testnum
3042 local SAVE_UMASK=`umask`
3045 banner "test $testnum: $message"
3046 test_${testnum} || error "test_$testnum failed with $?"
3049 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3050 check_catastrophe || error "LBUG/LASSERT detected"
3051 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3059 # Wrapper around run_one to ensure:
3060 # - test runs in subshell
3061 # - output of test is saved to separate log file for error reporting
3062 # - test result is saved to data file
3065 local BEFORE=`date +%s`
3067 local name=${TESTSUITE}.test_${1}.test_log.$(hostname).log
3068 local test_log=$LOGDIR/$name
3072 log_sub_test_begin test_${1}
3073 (run_one $1 "$2") 2>&1 | tee $test_log
3074 local RC=${PIPESTATUS[0]}
3076 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3077 echo "test_$1 returned $RC" | tee $LOGDIR/err
3079 duration=$((`date +%s` - $BEFORE))
3080 pass "(${duration}s)"
3081 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3082 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3084 if [ -f $LOGDIR/err ]; then
3085 $FAIL_ON_ERROR && exit $RC
3092 (cd `dirname $1`; echo $PWD/`basename $1`)
3096 [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
3097 [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
3102 export base=`basetest $1`
3103 [ "$CHECK_GRANT" == "no" ] && return 0
3105 testname=GCHECK_ONLY_${base}
3106 [ ${!testname}x == x ] && return 0
3108 echo -n "checking grant......"
3110 # write some data to sync client lost_grant
3111 rm -f $DIR1/${tfile}_check_grant_* 2>&1
3112 for i in `seq $OSTCOUNT`; do
3113 $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
3114 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
3115 count=1 > /dev/null 2>&1
3117 # sync all the data and make sure no pending data on server
3120 #get client grant and server grant
3122 for d in `lctl get_param -n osc.*.cur_grant_bytes`; do
3123 client_grant=$((client_grant + $d))
3126 for d in `lctl get_param -n obdfilter.*.tot_granted`; do
3127 server_grant=$((server_grant + $d))
3130 # cleanup the check_grant file
3131 for i in `seq $OSTCOUNT`; do
3132 rm $DIR1/${tfile}_check_grant_$i
3135 #check whether client grant == server grant
3136 if [ $client_grant != $server_grant ]; then
3137 echo "failed: client:${client_grant} server: ${server_grant}"
3144 ########################
3150 ost=`echo $1 | awk -F_ '{print $3}'`
3151 if [ -z $ost ]; then
3152 ost=`echo $1 | sed 's/-osc.*//'`
3157 ostuuid_from_index()
3159 $LFS osts $2 | awk '/^'$1'/ { print $2 }'
3164 [ "$node" != "$(hostname)" ]
3170 for node in $(mdts_nodes); do
3171 remote_node $node && return 0
3178 [ "$CLIENTONLY" ] && return 0 || true
3179 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3184 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3185 MSKIPPED=1 && return 1
3192 for node in $(osts_nodes) ; do
3193 remote_node $node && return 0
3200 [ "$CLIENTONLY" ] && return 0 || true
3201 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3206 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3207 OSKIPPED=1 && return 1
3214 MGS=$(facet_host mgs)
3215 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3220 remote_mds_nodsh || remote_ost_nodsh || \
3221 $(single_local_node $(comma_list $(nodes_list)))
3227 for num in `seq $MDSCOUNT`; do
3228 MDSNODES="$MDSNODES $(facet_host mds$num)"
3230 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3236 remote_ost && remote_mds
3244 for facet in ${facets//,/ }; do
3245 if [ "$FAILURE_MODE" = HARD ]; then
3246 nodes="$nodes $(facet_active_host $facet)"
3248 nodes="$nodes $(facet_host $facet)"
3251 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3257 local facets=$(get_facets OST)
3258 local nodes=$(facets_nodes $facets)
3264 # FIXME. We need a list of clients
3265 local myNODES=$HOSTNAME
3268 # CLIENTS (if specified) contains the local client
3269 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3271 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3272 myNODES="$myNODES $(facets_nodes $(get_facets))"
3275 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3280 remote_nodes_list () {
3281 local rnodes=$(nodes_list)
3282 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3286 init_clients_lists () {
3287 # Sanity check: exclude the local client from RCLIENTS
3288 local rclients=$(echo " $RCLIENTS " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3290 # Sanity check: exclude the dup entries
3291 rclients=$(for i in $rclients; do echo $i; done | sort -u)
3293 local clients="$SINGLECLIENT $HOSTNAME $rclients"
3295 # Sanity check: exclude the dup entries from CLIENTS
3296 # for those configs which has SINGLCLIENT set to local client
3297 clients=$(for i in $clients; do echo $i; done | sort -u)
3299 CLIENTS=`comma_list $clients`
3300 local -a remoteclients=($rclients)
3301 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3302 varname=CLIENT$((i + 2))
3303 eval $varname=${remoteclients[i]}
3306 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3309 get_random_entry () {
3312 rnodes=${rnodes//,/ }
3314 local -a nodes=($rnodes)
3315 local num=${#nodes[@]}
3316 local i=$((RANDOM * num * 2 / 65536))
3322 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3327 lctl get_param version | grep -q patchless
3331 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3336 echo $nodes | wc -w || true
3340 local nodes=$(osts_nodes)
3341 local osscount=$(get_node_count "$nodes")
3342 [ ! "$OSTCOUNT" = "$osscount" ]
3346 local nodes=$(mdts_nodes)
3347 local mdtcount=$(get_node_count "$nodes")
3348 [ ! "$MDSCOUNT" = "$mdtcount" ]
3351 generate_machine_file() {
3352 local nodes=${1//,/ }
3353 local machinefile=$2
3355 for node in $nodes; do
3356 echo $node >>$machinefile || \
3357 { echo "can not generate machinefile $machinefile" && return 1; }
3362 local file=$1/stripe
3364 $LFS getstripe -v $file || error
3368 setstripe_nfsserver () {
3371 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3372 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3374 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3376 do_nodev $nfsserver lfs setstripe "$@"
3379 check_runas_id_ret() {
3381 local myRUNAS_UID=$1
3382 local myRUNAS_GID=$2
3385 if [ -z "$myRUNAS" ]; then
3386 error_exit "myRUNAS command must be specified for check_runas_id"
3389 $myRUNAS krb5_login.sh || \
3390 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3392 mkdir $DIR/d0_runas_test
3394 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3395 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3396 rm -rf $DIR/d0_runas_test
3401 local myRUNAS_UID=$1
3402 local myRUNAS_GID=$2
3405 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3406 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3407 Please set RUNAS_ID to some UID which exists on MDS and client or
3408 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3411 # obtain the UID/GID for MPI_USER
3415 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3416 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3418 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3419 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3422 # obtain and cache Kerberos ticket-granting ticket
3423 refresh_krb5_tgt() {
3424 local myRUNAS_UID=$1
3425 local myRUNAS_GID=$2
3428 if [ -z "$myRUNAS" ]; then
3429 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3432 CLIENTS=${CLIENTS:-$HOSTNAME}
3433 do_nodes $CLIENTS "set -x
3434 if ! $myRUNAS krb5_login.sh; then
3435 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3440 # Run multiop in the background, but wait for it to print
3441 # "PAUSING" to its stdout before returning from this function.
3442 multiop_bg_pause() {
3443 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3447 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3450 echo "$MULTIOP_PROG $FILE v$ARGS"
3451 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3453 echo "TMPPIPE=${TMPPIPE}"
3454 read -t 60 multiop_output < $TMPPIPE
3455 if [ $? -ne 0 ]; then
3460 if [ "$multiop_output" != "PAUSING" ]; then
3461 echo "Incorrect multiop output: $multiop_output"
3476 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3482 inodes_available () {
3483 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3487 mdsrate_inodes_available () {
3488 echo $(($(inodes_available) - 1))
3491 # reset llite stat counters
3492 clear_llite_stats(){
3493 lctl set_param -n llite.*.stats 0
3496 # sum llite stat items
3497 calc_llite_stats() {
3498 local res=$(lctl get_param -n llite.*.stats |
3499 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3503 # reset osc stat counters
3505 lctl set_param -n osc.*.osc_stats 0
3508 # sum osc stat items
3510 local res=$(lctl get_param -n osc.*.osc_stats |
3511 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3516 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3519 calc_osc_kbytes () {
3520 df $MOUNT > /dev/null
3521 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3524 # save_lustre_params(node, parameter_mask)
3525 # generate a stream of formatted strings (<node> <param name>=<param value>)
3526 save_lustre_params() {
3528 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3531 # restore lustre parameters from input stream, produces by save_lustre_params
3532 restore_lustre_params() {
3536 while IFS=" =" read node name val; do
3537 do_node ${node//:/} "lctl set_param -n $name $val"
3541 check_catastrophe() {
3542 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3543 local C=$CATASTROPHE
3544 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3546 if [ $rnodes ]; then
3547 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3548 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3564 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3566 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3567 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3568 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3572 # CMD: determine mds index where directory inode presents
3575 local file=$dir/f0.get_mds_dir_tmpfile
3580 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3581 local -a oldused=($iused)
3583 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3585 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3586 local -a newused=($iused)
3589 for ((i=0; i<${#newused[@]}; i++)); do
3590 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3596 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3599 mdsrate_cleanup () {
3601 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3606 delayed_recovery_enabled () {
3607 local var=${SINGLEMDS}_svc
3608 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3611 ########################
3613 convert_facet2label() {
3616 if [ x$facet = xost ]; then
3620 local varsvc=${facet}_svc
3622 if [ -n ${!varsvc} ]; then
3625 error "No lablel for $facet!"
3629 get_clientosc_proc_path() {
3635 get_lustre_version () {
3636 local facet=${1:-"$SINGLEMDS"}
3637 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3640 get_mds_version_major () {
3641 local facet=${1:-"$SINGLEMDS"}
3642 local version=$(get_lustre_version $facet)
3643 echo $version | awk -F. '{print $1}'
3646 get_mds_version_minor () {
3647 local facet=${1:-"$SINGLEMDS"}
3648 local version=$(get_lustre_version $facet)
3649 echo $version | awk -F. '{print $2}'
3652 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
3653 # used by MDT would not be changed.
3654 # mdt lov: fsname-mdtlov
3655 # mdt osc: fsname-OSTXXXX-osc
3656 mds_on_old_device() {
3657 local mds=${1:-"$SINGLEMDS"}
3658 local major=$(get_mds_version_major $mds)
3659 local minor=$(get_mds_version_minor $mds)
3661 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
3662 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
3663 > /dev/null 2>&1" && return 0
3668 get_mdtosc_proc_path() {
3670 local ost_label=${2:-"*OST*"}
3672 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
3673 local mdt_label=$(convert_facet2label $mds_facet)
3674 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
3676 local major=$(get_mds_version_major $mds_facet)
3677 local minor=$(get_mds_version_minor $mds_facet)
3678 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
3679 echo "${ost_label}-osc"
3681 echo "${ost_label}-osc-${mdt_index}"
3685 get_osc_import_name() {
3688 local label=$(convert_facet2label $ost)
3690 if [ "${facet:0:3}" = "mds" ]; then
3691 get_mdtosc_proc_path $facet $label
3695 get_clientosc_proc_path $label
3699 _wait_import_state () {
3702 local maxtime=${3:-max_recovery_time}
3706 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3707 while [ "${CONN_STATE}" != "${expected}" ]; do
3708 [ $i -ge $maxtime ] && \
3709 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
3712 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3716 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
3720 wait_import_state() {
3723 local maxtime=${3:-max_recovery_time}
3726 for param in ${params//,/ }; do
3727 _wait_import_state $state $param $maxtime || return
3730 wait_osc_import_state() {
3734 local ost=$(get_osc_import_name $facet $ost_facet)
3739 CONN_PROC="osc.${ost}.ost_server_uuid"
3740 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3741 while [ "${CONN_STATE}" != "${expected}" ]; do
3742 if [ "${expected}" == "DISCONN" ]; then
3743 # for disconn we can check after proc entry is removed
3744 [ "x${CONN_STATE}" == "x" ] && return 0
3745 # with AT we can have connect request timeout ~ reconnect timeout
3746 # and test can't see real disconnect
3747 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3749 # disconnect rpc should be wait not more obd_timeout
3750 [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
3751 error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
3753 CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3757 log "${ost_facet} now in ${CONN_STATE} state"
3760 get_clientmdc_proc_path() {
3768 # Add paths to lustre tests for 32 and 64 bit systems.
3769 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
3770 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
3773 wait_clients_import_state () {
3780 if [ "$FAILURE_MODE" = HARD ]; then
3781 facets=$(facets_on_host $(facet_active_host $facet))
3784 for facet in ${facets//,/ }; do
3785 local label=$(convert_facet2label $facet)
3788 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
3789 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
3790 *) error "unknown facet!" ;;
3792 local params=$(expand_list $params $proc_path)
3795 if ! do_rpc_nodes $list wait_import_state $expected $params; then
3796 error "import is not in ${expected} state"
3805 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
3806 $LCTL get_param obdfilter.*.kbytesavail))
3807 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
3808 $LCTL get_param -n obdfilter.*.tot_granted))
3809 for ((i=0; i<${#AVAILA[@]}; i++)); do
3810 local -a AVAIL1=(${AVAILA[$i]//=/ })
3811 GRANT=$((${GRANTA[$i]}/1024))
3812 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
3813 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
3819 do_facet mgs lctl pool_list $1
3823 local fsname=${1%%.*}
3824 local poolname=${1##$fsname.}
3826 do_facet mgs lctl pool_new $1
3828 # get param should return err unless pool is created
3829 [[ $RC -ne 0 ]] && return $RC
3831 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3832 2>/dev/null || echo foo" "" || RC=1
3833 if [[ $RC -eq 0 ]]; then
3836 error "pool_new failed $1"
3841 add_pool_to_list () {
3842 local fsname=${1%%.*}
3843 local poolname=${1##$fsname.}
3845 local listvar=${fsname}_CREATED_POOLS
3846 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
3849 remove_pool_from_list () {
3850 local fsname=${1%%.*}
3851 local poolname=${1##$fsname.}
3853 local listvar=${fsname}_CREATED_POOLS
3854 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
3857 destroy_pool_int() {
3859 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
3860 awk '$1 !~ /^Pool:/ {print $1}')
3861 for ost in $OSTS; do
3862 do_facet mgs lctl pool_remove $1 $ost
3864 do_facet mgs lctl pool_destroy $1
3867 # <fsname>.<poolname> or <poolname>
3869 local fsname=${1%%.*}
3870 local poolname=${1##$fsname.}
3872 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
3876 pool_list $fsname.$poolname || return $?
3878 destroy_pool_int $fsname.$poolname
3880 [[ $RC -ne 0 ]] && return $RC
3882 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
3883 2>/dev/null || echo foo" "foo" || RC=1
3885 if [[ $RC -eq 0 ]]; then
3886 remove_pool_from_list $fsname.$poolname
3888 error "destroy pool failed $1"
3894 local fsname=${1:-$FSNAME}
3896 local listvar=${fsname}_CREATED_POOLS
3900 [ x${!listvar} = x ] && return 0
3902 echo destroy the created pools: ${!listvar}
3903 for poolname in ${!listvar//,/ }; do
3904 destroy_pool $fsname.$poolname
3909 local fsname=${1:-$FSNAME}
3911 destroy_pools $fsname
3917 local ts=$(date +%s)
3919 [ -f $LOGDIR/shared ] && docp=false
3921 # dump lustre logs, dmesg
3923 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
3925 echo "Dumping lctl log to ${prefix}.*.${suffix}"
3927 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
3928 echo "Dumping logs only on local client."
3929 $LCTL dk > ${prefix}.debug_log.$(hostname).${suffix}
3930 dmesg > ${prefix}.dmesg.$(hostname).${suffix}
3935 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname).${suffix};
3936 dmesg > ${prefix}.dmesg.\\\$(hostname).${suffix}"
3937 if [ ! -f $LOGDIR/shared ]; then
3938 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
3941 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
3942 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
3948 local list=${1:-$(comma_list $(nodes_list))}
3950 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
3962 for i in $(seq 0 $num_mntpts); do
3963 cmd="ls -laf ${mntpt_root}$i/$dir"
3969 for pid in $pids; do
3976 # target_start_and_reset_recovery_timer()
3977 # service_time = at_est2timeout(service_time);
3978 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
3979 # INITIAL_CONNECT_TIMEOUT);
3980 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
3981 #define CONNECTION_SWITCH_INC 1
3982 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
3983 #define CONNECTION_SWITCH_MIN 5U
3985 max_recovery_time () {
3986 local init_connect_timeout=$(( TIMEOUT / 20 ))
3987 [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5
3989 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
3994 get_clients_mount_count () {
3995 local clients=${CLIENTS:-`hostname`}
3997 # we need to take into account the clients mounts and
3998 # exclude mds/ost mounts if any;
3999 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4003 PROC_CLI="srpc_info"
4011 if [ $M -lt $N ]; then
4015 while [ $N -lt $M ]; do
4025 calc_connection_cnt() {
4028 # MDT->MDT = 2 * C(M, 2)
4032 comb_m2=$(combination $MDSCOUNT 2)
4034 local num_clients=$(get_clients_mount_count)
4036 local cnt_mdt2mdt=$((comb_m2 * 2))
4037 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4038 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4039 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4040 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4041 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4042 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4056 local cmd="$tgt.srpc.flavor"
4058 if [ $net == "any" ]; then
4063 if [ $dir != "any" ]; then
4068 log "Setting sptlrpc rule: $cmd"
4069 do_facet mgs "$LCTL conf_param $cmd"
4078 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4079 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4081 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4083 if [ "x$bulkspec" != "x" ]; then
4084 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4086 if [ "x$algs" != "x" ]; then
4087 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4089 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4090 if [ $bulk == "bulkn" ]; then
4091 bulk_count=`echo "$output" | grep "bulk flavor" \
4092 | grep "null/null" | wc -l`
4093 elif [ $bulk == "bulki" ]; then
4094 bulk_count=`echo "$output" | grep "bulk flavor" \
4095 | grep "/null" | grep -v "null/" | wc -l`
4097 bulk_count=`echo "$output" | grep "bulk flavor" \
4098 | grep -v "/null" | grep -v "null/" | wc -l`
4102 [ $bulk_count -lt $count ] && count=$bulk_count
4113 local clients=${CLIENTS:-`hostname`}
4115 for c in ${clients//,/ }; do
4116 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4117 tmpcnt=`count_flvr "$output" $flavor`
4118 cnt=$((cnt + tmpcnt))
4128 local clients=${CLIENTS:-`hostname`}
4130 for c in ${clients//,/ }; do
4131 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4132 tmpcnt=`count_flvr "$output" $flavor`
4133 cnt=$((cnt + tmpcnt))
4143 if [ $MDSCOUNT -le 1 ]; then
4148 for num in `seq $MDSCOUNT`; do
4149 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4150 tmpcnt=`count_flvr "$output" $flavor`
4151 cnt=$((cnt + tmpcnt))
4162 for num in `seq $MDSCOUNT`; do
4163 mdtosc=$(get_mdtosc_proc_path mds$num)
4164 mdtosc=${mdtosc/-MDT*/-MDT\*}
4165 output=$(do_facet mds$num lctl get_param -n \
4166 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4167 tmpcnt=`count_flvr "$output" $flavor`
4168 cnt=$((cnt + tmpcnt))
4177 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4178 count_flvr "$output" $flavor
4183 local dir=$1 # from to
4184 local flavor=$2 # flavor expected
4187 if [ $dir == "cli2mdt" ]; then
4188 res=`flvr_cnt_cli2mdt $flavor`
4189 elif [ $dir == "cli2ost" ]; then
4190 res=`flvr_cnt_cli2ost $flavor`
4191 elif [ $dir == "mdt2mdt" ]; then
4192 res=`flvr_cnt_mdt2mdt $flavor`
4193 elif [ $dir == "mdt2ost" ]; then
4194 res=`flvr_cnt_mdt2ost $flavor`
4195 elif [ $dir == "all2ost" ]; then
4196 res1=`flvr_cnt_mdt2ost $flavor`
4197 res2=`flvr_cnt_cli2ost $flavor`
4198 res=$((res1 + res2))
4199 elif [ $dir == "all2mdt" ]; then
4200 res1=`flvr_cnt_mdt2mdt $flavor`
4201 res2=`flvr_cnt_cli2mdt $flavor`
4202 res=$((res1 + res2))
4203 elif [ $dir == "all2all" ]; then
4204 res1=`flvr_cnt_mdt2ost $flavor`
4205 res2=`flvr_cnt_cli2ost $flavor`
4206 res3=`flvr_cnt_mdt2mdt $flavor`
4207 res4=`flvr_cnt_cli2mdt $flavor`
4208 res=$((res1 + res2 + res3 + res4))
4216 local dir=$1 # from to
4217 local flavor=$2 # flavor expected
4218 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4222 for ((i=0;i<20;i++)); do
4223 echo -n "checking $dir..."
4224 res=$(do_check_flavor $dir $flavor)
4225 echo "found $res/$expect $flavor connections"
4226 [ $res -eq $expect ] && return 0
4230 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4234 restore_to_default_flavor()
4236 local proc="mgs.MGS.live.$FSNAME"
4238 echo "restoring to default flavor..."
4240 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4242 # remove all existing rules if any
4243 if [ $nrule -ne 0 ]; then
4244 echo "$nrule existing rules"
4245 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4246 echo "remove rule: $rule"
4247 spec=`echo $rule | awk -F = '{print $1}'`
4248 do_facet mgs "$LCTL conf_param -d $spec"
4252 # verify no rules left
4253 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4254 [ $nrule -ne 0 ] && error "still $nrule rules left"
4256 # wait for default flavor to be applied
4257 # currently default flavor for all connections are 'null'
4258 wait_flavor all2all null
4259 echo "now at default flavor settings"
4264 local flavor=${1:-null}
4266 echo "setting all flavor to $flavor"
4268 # FIXME need parameter to this fn
4269 # and remove global vars
4270 local cnt_all2all=$(calc_connection_cnt all2all)
4272 local res=$(do_check_flavor all2all $flavor)
4273 if [ $res -eq $cnt_all2all ]; then
4274 echo "already have total $res $flavor connections"
4278 echo "found $res $flavor out of total $cnt_all2all connections"
4279 restore_to_default_flavor
4281 [[ $flavor = null ]] && return 0
4283 set_rule $FSNAME any any $flavor
4284 wait_flavor all2all $flavor
4290 # Checking for shared logdir
4291 if [ ! -d $dir ]; then
4292 # Not found. Create local logdir
4295 touch $dir/node.$(hostname).yml
4300 check_write_access() {
4302 for node in $(nodes_list); do
4303 if [ ! -f "$dir/node.${node}.yml" ]; then
4304 # Logdir not accessible/writable from this node.
4312 if [[ -n $YAML_LOG ]]; then
4315 export YAML_LOG=${LOGDIR}/results.yml
4319 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $LOGDIR
4320 if check_write_access $LOGDIR; then
4321 touch $LOGDIR/shared
4322 echo "Logging to shared log directory: $LOGDIR"
4324 echo "Logging to local directory: $LOGDIR"
4327 yml_nodes_file $LOGDIR
4328 yml_results_file >> $YAML_LOG
4332 yml_log_test $1 >> $YAML_LOG
4336 yml_log_test_status $@ >> $YAML_LOG
4339 log_sub_test_begin() {
4340 yml_log_sub_test_begin $@ >> $YAML_LOG
4343 log_sub_test_end() {
4344 yml_log_sub_test_end $@ >> $YAML_LOG
4350 local devname=$(basename $1)
4351 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4352 # loop devices aren't in /proc/partitions
4353 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4355 size=$(($size / 1024 / 1024)) # Gb
4357 local partial_arg=""
4358 # Run in partial (fast) mode if the size
4359 # of a partition > 10 GB
4360 [ $size -gt 10 ] && partial_arg="-p"
4362 llverdev --force $partial_arg $dev
4365 remove_mdt_files() {
4370 local mntpt=${MOUNT%/*}/$facet
4372 echo "removing files from $mdtdev on $facet: $files"
4373 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4376 rm $mntpt/ROOT/$f || { rc=$?; break; }
4378 umount -f $mntpt || return $?
4382 duplicate_mdt_files() {
4387 local mntpt=${MOUNT%/*}/$facet
4389 echo "duplicating files on $mdtdev on $facet: $files"
4390 mkdir -p $mntpt || return $?
4391 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4401 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4402 pushd $mntpt/ROOT > /dev/null || return $?
4405 touch $f.bad || return $?
4406 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4408 [ $rc -eq 0 ] || return $rc
4409 setfattr --restore $tmp || return $?
4415 local devs=${1//,/ }
4418 local rslt=$TMP/sgpdd_survey
4420 # sgpdd-survey cleanups ${rslt}.* files
4422 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"