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:-""}
11 export VERBOSE=${VERBOSE:-false}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
19 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
20 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
21 export LOAD_LLOOP=${LOAD_LLOOP:-false}
23 #export PDSH="pdsh -S -Rssh -w"
25 # function used by scripts run on remote nodes
26 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
27 . $LUSTRE/tests/functions.sh
28 . $LUSTRE/tests/yaml.sh
30 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
32 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
34 if [ -f "$EXCEPT_LIST_FILE" ]; then
35 echo "Reading test skip list from $EXCEPT_LIST_FILE"
40 # check config files for options in decreasing order of preference
41 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
42 MODPROBECONF=/etc/modprobe.d/lustre.conf
43 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
44 MODPROBECONF=/etc/modprobe.d/Lustre
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
46 MODPROBECONF=/etc/modprobe.conf
50 [[ $DIR/ = $MOUNT/* ]] || \
51 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
52 [[ $DIR1/ = $MOUNT1/* ]] || \
53 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
54 [[ $DIR2/ = $MOUNT2/* ]] || \
55 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
57 [ -n "$failed" ] && exit 99 || true
61 echo "usage: $0 [-r] [-f cfgfile]"
69 [ "$TESTSUITE" == "lfsck" ] && return 0
70 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
72 local form="%-13s %-17s %-9s %s %s\n"
73 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
74 echo "------------------------------------------------------------------------------------"
75 for O in $DEFAULT_SUITES; do
76 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
77 [ "${!O}" = "no" ] && continue || true
78 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
79 local log=${TMP}/${o}.log
80 if is_sanity_benchmark $o; then
81 log=${TMP}/sanity-benchmark.log
86 local status=Unfinished
88 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
89 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
90 total=$(grep duration $log | awk '{ print $2}')
91 if [ "${!O}" = "done" ]; then
95 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
96 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
99 printf "$form" $status "$O" "${total}" "E=$skipped"
100 printf "$form" "-" "-" "-" "S=$(echo $slow)"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 if [ "${!O}" = "no" ]; then
106 printf "$form" "Skipped" "$O" ""
110 # print the detailed tests durations if DDETAILS=true
117 export LUSTRE=`absolute_path $LUSTRE`
118 export TESTSUITE=`basename $0 .sh`
119 export TEST_FAILED=false
120 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
122 export MKE2FS=${MKE2FS:-mke2fs}
123 export DEBUGFS=${DEBUGFS:-debugfs}
124 export TUNE2FS=${TUNE2FS:-tune2fs}
125 export E2LABEL=${E2LABEL:-e2label}
126 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
127 export E2FSCK=${E2FSCK:-e2fsck}
128 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
130 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
131 export FSCK_MAX_ERR=4 # File system errors left uncorrected
133 #[ -d /r ] && export ROOT=${ROOT:-/r}
134 export TMP=${TMP:-$ROOT/tmp}
135 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
136 if [[ -z $LOGDIRSET ]]; then
137 export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
138 export LOGDIRSET=true
140 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
141 if ! echo $PATH | grep -q $LUSTRE/utils; then
142 export PATH=$LUSTRE/utils:$PATH
144 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
145 export PATH=$LUSTRE/utils/gss:$PATH
147 if ! echo $PATH | grep -q $LUSTRE/tests; then
148 export PATH=$LUSTRE/tests:$PATH
150 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
151 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
153 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
154 [ ! -f "$LST" ] && export LST=$(which lst)
155 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
156 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
157 # Ubuntu, at least, has a truncate command in /usr/bin
158 # so fully path our truncate command.
159 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
160 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
161 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
162 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
163 export PATH=$LUSTRE/tests/racer:$PATH:
165 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
166 export PATH=$LUSTRE/tests/mpi:$PATH
168 export RSYNC_RSH=${RSYNC_RSH:-rsh}
169 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
170 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
171 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
172 [ ! -f "$LFS" ] && export LFS=$(which lfs)
173 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
174 if [ ! -f "$L_GETIDENTITY" ]; then
175 if `which l_getidentity > /dev/null 2>&1`; then
176 export L_GETIDENTITY=$(which l_getidentity)
178 export L_GETIDENTITY=NONE
181 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
182 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
183 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
184 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
185 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
186 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
187 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
188 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
189 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
190 export FSTYPE=${FSTYPE:-"ldiskfs"}
191 export NAME=${NAME:-local}
192 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
193 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
194 export LGSSD=$(which lgssd)
195 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
196 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
197 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
199 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
202 if [ "$ACCEPTOR_PORT" ]; then
203 export PORT_OPT="--port $ACCEPTOR_PORT"
208 echo "Using GSS/krb5 ptlrpc security flavor"
209 which lgss_keyring > /dev/null 2>&1 || \
210 error_exit "built with gss disabled! SEC=$SEC"
221 IDENTITY_UPCALL=false
224 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
226 # Paths on remote nodes, if different
227 export RLUSTRE=${RLUSTRE:-$LUSTRE}
228 export RPWD=${RPWD:-$PWD}
229 export I_MOUNTED=${I_MOUNTED:-"no"}
230 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
231 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
232 ! -f `dirname $0`/../mds/mds.ko ]; then
233 export CLIENTMODSONLY=yes
236 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
240 while getopts "rvwf:" opt $*; do
243 r) REFORMAT=--reformat;;
245 w) WRITECONF=writeconf;;
250 shift $((OPTIND - 1))
253 # print the durations of each test if "true"
254 DDETAILS=${DDETAILS:-false}
255 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
260 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
261 *) EXT=".ko"; USE_QUOTA=yes;;
266 /sbin/lsmod | grep -q "^\<$1\>"
269 # Load a module on the system where this is running.
271 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
273 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
274 # will be used as the arguments. Otherwise arguments will be obtained from
275 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
282 BASE=`basename $module $EXT`
284 module_loaded ${BASE} && return
286 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
288 if [ $# -eq 0 ]; then
289 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
290 # Bash until 4.x, so we resort to eval.
291 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
292 eval set -- \$$optvar
293 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
294 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
295 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
296 # Get rid of "options $module"
297 (($# > 0)) && shift 2
299 # Ensure we have accept=all for lnet
300 if [ $(basename $module) = lnet ]; then
301 # OK, this is a bit wordy...
302 local arg accept_all_present=false
304 [ "$arg" = accept=all ] && accept_all_present=true
306 $accept_all_present || set -- "$@" accept=all
311 [ $# -gt 0 ] && echo "${module} options: '$*'"
313 # Note that insmod will ignore anything in modprobe.conf, which is why we're
314 # passing options on the command-line.
315 if [ "$BASE" == "lnet_selftest" ] && \
316 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
317 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
318 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
319 insmod ${LUSTRE}/${module}${EXT} "$@"
321 # must be testing a "make install" or "rpm" installation
322 # note failed to load ptlrpc_gss is considered not fatal
323 if [ "$BASE" == "ptlrpc_gss" ]; then
324 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
331 llite_lloop_enabled() {
332 local n1=$(uname -r | cut -d. -f1)
333 local n2=$(uname -r | cut -d. -f2)
334 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
336 # load the llite_lloop module for < 2.6.32 kernels
337 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
338 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
345 load_modules_local() {
346 if [ -n "$MODPROBE" ]; then
348 echo "Using modprobe to load modules"
352 echo Loading modules from $LUSTRE
353 load_module ../libcfs/libcfs/libcfs
354 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
355 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
356 load_module ../lnet/lnet/lnet
357 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
358 load_module ../lnet/klnds/$LNETLND
359 load_module lvfs/lvfs
360 load_module obdclass/obdclass
361 load_module ptlrpc/ptlrpc
362 load_module ptlrpc/gss/ptlrpc_gss
363 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
371 if ! client_only; then
372 SYMLIST=/proc/kallsyms
373 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
374 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
375 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
376 if [ "$FSTYPE" = "ldiskfs" ]; then
377 grep -q exportfs_decode_fh $SYMLIST ||
378 { modprobe exportfs 2> /dev/null || true; }
379 load_module ../ldiskfs/ldiskfs/ldiskfs
385 load_module lvfs/fsfilt_$FSTYPE
387 load_module osd-ldiskfs/osd_ldiskfs
389 load_module obdfilter/obdfilter
393 load_module llite/lustre
394 llite_lloop_enabled && load_module llite/llite_lloop
395 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
397 rm -f $OGDB/ogdb-$HOSTNAME
398 $LCTL modules > $OGDB/ogdb-$HOSTNAME
400 # 'mount' doesn't look in $PATH, just sbin
401 if [ -f $LUSTRE/utils/mount.lustre ] && \
402 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
403 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
404 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
411 # load modules on remote nodes optionally
412 # lustre-tests have to be installed on these nodes
413 if $LOAD_MODULES_REMOTE ; then
414 local list=$(comma_list $(remote_nodes_list))
415 echo loading modules on $list
416 do_rpc_nodes $list load_modules
421 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
422 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
423 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
424 echo "$LEAK_LUSTRE" 1>&2
425 echo "$LEAK_PORTALS" 1>&2
426 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
427 echo "Memory leaks detected"
428 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
434 wait_exit_ST client # bug 12845
436 $LUSTRE_RMMOD $FSTYPE || return 2
438 if $LOAD_MODULES_REMOTE ; then
439 local list=$(comma_list $(remote_nodes_list))
440 if [ ! -z $list ]; then
441 echo unloading modules on $list
442 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
443 do_rpc_nodes $list check_mem_leak
447 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
448 umount /sbin/mount.lustre || true
449 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
450 rm -f /sbin/mount.lustre || true
453 check_mem_leak || return 254
455 echo "modules unloaded."
459 check_gss_daemon_nodes() {
463 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
464 if [ \\\"\\\$num\\\" -ne 1 ]; then
465 echo \\\$num instance of $dname;
470 check_gss_daemon_facet() {
474 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
475 if [ $num -ne 1 ]; then
476 echo "$num instance of $dname on $facet"
485 echo Stopping $@ on $list
486 do_nodes $list "killall -2 $@ 2>/dev/null || true"
489 # start gss daemons on all nodes, or
490 # "daemon" on "list" if set
491 start_gss_daemons() {
495 if [ "$list" ] && [ "$daemon" ] ; then
496 echo "Starting gss daemon on nodes: $list"
497 do_nodes $list "$daemon" || return 8
501 local list=$(comma_list $(mdts_nodes))
503 echo "Starting gss daemon on mds: $list"
504 do_nodes $list "$LSVCGSSD -v" || return 1
506 do_nodes $list "$LGSSD -v" || return 2
509 list=$(comma_list $(osts_nodes))
510 echo "Starting gss daemon on ost: $list"
511 do_nodes $list "$LSVCGSSD -v" || return 3
512 # starting on clients
514 local clients=${CLIENTS:-`hostname`}
516 echo "Starting $LGSSD on clients $clients "
517 do_nodes $clients "$LGSSD -v" || return 4
520 # wait daemons entering "stable" status
524 # check daemons are running
526 list=$(comma_list $(mdts_nodes) $(osts_nodes))
527 check_gss_daemon_nodes $list lsvcgssd || return 5
529 list=$(comma_list $(mdts_nodes))
530 check_gss_daemon_nodes $list lgssd || return 6
533 check_gss_daemon_nodes $clients lgssd || return 7
538 local list=$(comma_list $(mdts_nodes))
540 send_sigint $list lsvcgssd lgssd
542 list=$(comma_list $(osts_nodes))
543 send_sigint $list lsvcgssd
545 list=${CLIENTS:-`hostname`}
546 send_sigint $list lgssd
551 if ! module_loaded ptlrpc_gss; then
552 load_module ptlrpc/gss/ptlrpc_gss
553 module_loaded ptlrpc_gss ||
554 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
556 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
558 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
559 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
567 # maybe cleanup credential cache?
573 local device=`mdsdevname $num`
574 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
580 local device=`ostdevname $num`
581 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
586 local dz=${1:-$DEBUG_SIZE}
587 local cpus=$(getconf _NPROCESSORS_CONF)
589 # bug 19944, adjust size to be -gt num_possible_cpus()
590 # promise 2MB for every cpu at least
591 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
594 lctl set_param debug_mb=$dz
597 set_default_debug () {
598 local debug=${1:-"$PTLDEBUG"}
599 local subsystem_debug=${2:-"$SUBSYSTEM"}
600 local debug_size=${3:-$DEBUG_SIZE}
602 lctl set_param debug="$debug"
603 lctl set_param subsystem_debug="${subsystem_debug# }"
605 set_debug_size $debug_size
609 set_default_debug_nodes () {
612 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
613 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
617 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
618 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
621 set_default_debug_facet () {
623 local node=$(facet_active_host $facet)
624 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
626 set_default_debug_nodes $node
631 local facets=${1:-$(get_facets)}
634 for facet in ${facets//,/ }; do
635 mount_facet $facet || error "Restart of $facet failed!"
642 local dev=$(facet_active $facet)_dev
643 local opt=${facet}_opt
644 local mntpt=$(facet_mntpt $facet)
646 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
647 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
649 if [ $RC -ne 0 ]; then
650 echo "mount -t lustre $@ ${!dev} $mntpt"
651 echo "Start of ${!dev} on ${facet} failed ${RC}"
653 set_default_debug_facet $facet
655 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
656 [ -z "$label" ] && echo no label for ${!dev} && exit 1
657 eval export ${facet}_svc=${label}
658 echo Started ${label}
663 # start facet device options
669 eval export ${facet}_dev=${device}
670 eval export ${facet}_opt=\"$@\"
672 local varname=${facet}failover_dev
673 if [ -n "${!varname}" ] ; then
674 eval export ${facet}failover_dev=${!varname}
676 eval export ${facet}failover_dev=$device
679 local mntpt=$(facet_mntpt $facet)
680 do_facet ${facet} mkdir -p $mntpt
681 eval export ${facet}_MOUNT=$mntpt
691 local HOST=`facet_active_host $facet`
692 [ -z $HOST ] && echo stop: no host for $facet && return 0
694 local mntpt=$(facet_mntpt $facet)
695 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
696 if [ ${running} -ne 0 ]; then
697 echo "Stopping $mntpt (opts:$@) on $HOST"
698 do_facet ${facet} umount -d $@ $mntpt
701 # umount should block, but we should wait for unrelated obd's
702 # like the MGS or MGC to also stop.
703 wait_exit_ST ${facet}
706 # save quota version (both administrative and operational quotas)
707 # add an additional parameter if mountpoint is ever different from $MOUNT
708 quota_save_version() {
709 local fsname=${2:-$FSNAME}
711 local ver=$(tr -c -d "123" <<< $spec)
712 local type=$(tr -c -d "ug" <<< $spec)
714 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
716 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
718 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
720 local osts=$(get_facets OST)
721 for ost in ${osts//,/ }; do
723 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
727 # client could mount several lustre
729 local fsname=${1:-$FSNAME}
731 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
732 do_nodes $(comma_list $(osts_nodes)) \
733 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
737 restore_quota_type () {
738 local mntpt=${1:-$MOUNT}
739 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
740 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
743 quota_save_version $old_QUOTA_TYPE
749 # We need save the original quota_type params, and restore them after testing
751 # Suppose that quota type the same on mds and ost
752 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
753 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
754 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
755 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
756 export old_QUOTA_TYPE=$quota_type
757 quota_save_version $QUOTA_TYPE
759 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
760 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
763 local quota_usrs=$QUOTA_USERS
765 # get_filesystem_size
766 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
767 local blk_soft=$((disksz + 1024))
768 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
770 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
772 local i_hard=$((i_soft + i_soft / 20))
774 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
775 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
778 for usr in $quota_usrs; do
779 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
781 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
783 eval $cmd || error "$cmd FAILED!"
785 # display the quota status
786 echo "Quota settings for $usr : "
787 $LFS quota -v -u $usr $mntpt || true
794 local OPTIONS=${3:-$MOUNTOPT}
796 local device=$MGSNID:/$FSNAME
797 if [ -z "$mnt" -o -z "$FSNAME" ]; then
798 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
802 echo "Starting client: $client: $OPTIONS $device $mnt"
803 do_node $client mkdir -p $mnt
804 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
806 set_default_debug_nodes $client
819 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
820 if [ $running -ne 0 ]; then
821 echo "Stopping client $client $mnt (opts:$force)"
822 do_node $client lsof -t $mnt || need_kill=no
823 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
824 pids=$(do_node $client lsof -t $mnt | sort -u);
825 if [ -n $pids ]; then
826 do_node $client kill -9 $pids || true
830 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
831 if [ $busy -ne 0 ] ; then
832 echo "$mnt is still busy, wait one second" && sleep 1
833 do_node $client umount $force $mnt
838 # nodes is comma list
839 sanity_mount_check_nodes () {
845 # FIXME: assume that all cluster nodes run the same os
846 [ "$(uname)" = Linux ] || return 0
849 for mnt in $mnts ; do
850 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
851 mpts=\\\$(mount | grep -w -c $mnt);
852 if [ \\\$running -ne \\\$mpts ]; then
853 echo \\\$(hostname) env are INSANE!;
861 sanity_mount_check_servers () {
863 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
864 echo Checking servers environments
866 # FIXME: modify get_facets to display all facets wo params
867 local facets="$(get_facets OST),$(get_facets MDS),mgs"
871 for facet in ${facets//,/ }; do
872 node=$(facet_host ${facet})
873 mntpt=$(facet_mntpt $facet)
874 sanity_mount_check_nodes $node $mntpt ||
875 { error "server $node environments are insane!"; return 1; }
879 sanity_mount_check_clients () {
880 local clients=${1:-$CLIENTS}
881 local mntpt=${2:-$MOUNT}
882 local mntpt2=${3:-$MOUNT2}
884 [ -z $clients ] && clients=$(hostname)
885 echo Checking clients $clients environments
887 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
888 error "clients environments are insane!"
891 sanity_mount_check () {
892 sanity_mount_check_servers || return 1
893 sanity_mount_check_clients || return 2
896 # mount clients if not mouted
897 zconf_mount_clients() {
900 local OPTIONS=${3:-$MOUNTOPT}
902 local device=$MGSNID:/$FSNAME
903 if [ -z "$mnt" -o -z "$FSNAME" ]; then
904 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
908 echo "Starting client $clients: $OPTIONS $device $mnt"
911 running=\\\$(mount | grep -c $mnt' ');
913 if [ \\\$running -eq 0 ] ; then
915 mount -t lustre $OPTIONS $device $mnt;
918 exit \\\$rc" || return ${PIPESTATUS[0]}
920 echo "Started clients $clients: "
921 do_nodes $clients "mount | grep -w $mnt"
923 set_default_debug_nodes $clients
928 zconf_umount_clients() {
935 echo "Stopping clients: $clients $mnt (opts:$force)"
936 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
937 if [ \\\$running -ne 0 ] ; then
938 echo Stopping client \\\$(hostname) $mnt opts:$force;
939 lsof -t $mnt || need_kill=no;
940 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
941 pids=\\\$(lsof -t $mnt | sort -u);
942 if [ -n \\\"\\\$pids\\\" ]; then
946 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
947 if [ \\\$busy -ne 0 ] ; then
948 echo "$mnt is still busy, wait one second" && sleep 1;
956 echo + $POWER_DOWN $node
960 shutdown_node_hard () {
962 local attempts=$SHUTDOWN_ATTEMPTS
964 for i in $(seq $attempts) ; do
967 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
968 echo "waiting for $host to fail attempts=$attempts"
969 [ $i -lt $attempts ] || \
970 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
976 local mnt=${2:-$MOUNT}
979 if [ "$FAILURE_MODE" = HARD ]; then
980 shutdown_node_hard $client
982 zconf_umount_clients $client $mnt -f
988 local facets="$(get_facets OST),$(get_facets MDS)"
991 combined_mgs_mds || facets="$facets,mgs"
993 for facet in ${facets//,/ }; do
994 if [ $(facet_active_host $facet) == $host ]; then
995 affected="$affected $facet"
999 echo $(comma_list $affected)
1004 local host=${2:-$(facet_host $facet)}
1006 local label=$(convert_facet2label $facet)
1007 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1010 facets_up_on_host () {
1012 local facets=$(facets_on_host $host)
1015 for facet in ${facets//,/ }; do
1016 if $(facet_up $facet $host); then
1017 affected_up="$affected_up $facet"
1021 echo $(comma_list $affected_up)
1027 if [ "$FAILURE_MODE" = HARD ]; then
1028 shutdown_node_hard $(facet_active_host $facet)
1036 echo + $POWER_UP $node
1049 if [ "$FAILURE_MODE" = HARD ]; then
1050 reboot_node $(facet_active_host $facet)
1058 if [ "$FAILURE_MODE" = HARD ]; then
1068 for facet in ${facets//,/ }; do
1069 hosts=$(expand_list $hosts $(facet_host $facet) )
1075 _check_progs_installed () {
1079 for prog in $progs; do
1080 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1081 echo $prog missing on $(hostname)
1088 check_progs_installed () {
1092 do_rpc_nodes $nodes _check_progs_installed $@
1095 # recovery-scale functions
1097 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1100 start_client_load() {
1103 local var=$(node_var_name $client)_load
1104 eval export ${var}=$load
1106 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1107 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1108 END_RUN_FILE=$END_RUN_FILE \
1109 LOAD_PID_FILE=$LOAD_PID_FILE \
1110 TESTSUITELOG=$TESTSUITELOG \
1112 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
1113 log "Started client load: ${load} on $client"
1118 start_client_loads () {
1119 local -a clients=(${1//,/ })
1120 local numloads=${#CLIENT_LOADS[@]}
1123 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1124 testnum=$((nodenum % numloads))
1125 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1127 # bug 22169: wait the background threads to start
1131 # only for remote client
1132 check_client_load () {
1134 local var=$(node_var_name $client)_load
1135 local TESTLOAD=run_${!var}.sh
1137 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1139 # bug 18914: try to connect several times not only when
1140 # check ps, but while check_catastrophe also
1143 while [ $RC = 254 -a $tries -gt 0 ]; do
1147 if ! check_catastrophe $client; then
1149 if [ $RC -eq 254 ]; then
1150 # FIXME: not sure how long we shuold sleep here
1154 echo "check catastrophe failed: RC=$RC "
1158 # We can continue try to connect if RC=254
1159 # Just print the warning about this
1160 if [ $RC = 254 ]; then
1161 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1164 # see if the load is still on the client
1167 while [ $RC = 254 -a $tries -gt 0 ]; do
1171 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1176 if [ $RC = 254 ]; then
1177 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1178 # see if we can diagnose a bit why this is
1183 check_client_loads () {
1184 local clients=${1//,/ }
1188 for client in $clients; do
1189 check_client_load $client
1191 if [ "$rc" != 0 ]; then
1192 log "Client load failed on node $client, rc=$rc"
1198 restart_client_loads () {
1199 local clients=${1//,/ }
1200 local expectedfail=${2:-""}
1204 for client in $clients; do
1205 check_client_load $client
1207 if [ "$rc" != 0 -a "$expectedfail" ]; then
1208 local var=$(node_var_name $client)_load
1209 start_client_load $client ${!var}
1210 echo "Restarted client load ${!var}: on $client. Checking ..."
1211 check_client_load $client
1213 if [ "$rc" != 0 ]; then
1214 log "Client load failed to restart on node $client, rc=$rc"
1215 # failure one client load means test fail
1216 # we do not need to check other
1224 # End recovery-scale functions
1226 # verify that lustre actually cleaned up properly
1228 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1229 error "LBUG/LASSERT detected"
1230 BUSY=`dmesg | grep -i destruct || true`
1231 if [ "$BUSY" ]; then
1233 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1237 check_mem_leak || exit 204
1239 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1240 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1242 if module_loaded lnet || module_loaded libcfs; then
1243 echo "$0: modules still loaded..." 1>&2
1260 RESULT=$(do_node $node "$TEST")
1261 if [ "$RESULT" == "$FINAL" ]; then
1262 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1263 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1266 [ $WAIT -ge $MAX ] && break
1267 echo "Waiting $((MAX - WAIT)) secs for update"
1268 WAIT=$((WAIT + sleep))
1271 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1275 wait_update_facet () {
1277 wait_update $(facet_active_host $facet) "$@"
1280 wait_delete_completed () {
1281 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1282 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1286 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1288 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1289 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1290 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1291 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1295 echo "Delete is not completed in $MAX_WAIT sec"
1302 # we can use "for" here because we are waiting the slowest
1303 for host in ${hostlist//,/ }; do
1304 check_network "$host" 900
1306 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1313 for facet in ${facetlist//,/ }; do
1314 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1316 wait_for_host $hostlist
1319 _wait_recovery_complete () {
1322 # Use default policy if $2 is not passed by caller.
1323 local MAX=${2:-$(max_recovery_time)}
1328 while [ $WAIT -lt $MAX ]; do
1329 STATUS=$(lctl get_param -n $param | grep status)
1331 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1334 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1336 echo "$param recovery not done in $MAX sec. $STATUS"
1340 wait_recovery_complete () {
1343 # with an assumption that at_max is the same on all nodes
1344 local MAX=${2:-$(max_recovery_time)}
1347 if [ "$FAILURE_MODE" = HARD ]; then
1348 facets=$(facets_on_host $(facet_active_host $facet))
1350 echo affected facets: $facets
1352 # we can use "for" here because we are waiting the slowest
1353 for facet in ${facets//,/ }; do
1354 local var_svc=${facet}_svc
1355 local param="*.${!var_svc}.recovery_status"
1357 local host=$(facet_active_host $facet)
1358 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1362 wait_mds_ost_sync () {
1363 # just because recovery is done doesn't mean we've finished
1364 # orphan cleanup. Wait for llogs to get synchronized.
1365 echo "Waiting for orphan cleanup..."
1366 # MAX value includes time needed for MDS-OST reconnection
1367 local MAX=$(( TIMEOUT * 2 ))
1369 while [ $WAIT -lt $MAX ]; do
1370 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1371 "$LCTL get_param -n obdfilter.*.mds_sync"))
1374 for ((i=0; i<${#sync[@]}; i++)); do
1375 [ ${sync[$i]} -eq 0 ] && continue
1376 # there is a not finished MDS-OST synchronization
1380 sleep 2 # increase waiting time and cover statfs cache
1381 [ ${con} -eq 1 ] && return 0
1382 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1385 echo "$facet recovery not done in $MAX sec. $STATUS"
1389 wait_destroy_complete () {
1390 echo "Waiting for destroy to be done..."
1391 # MAX value shouldn't be big as this mean server responsiveness
1392 # never increase this just to make test pass but investigate
1393 # why it takes so long time
1396 while [ $WAIT -lt $MAX ]; do
1397 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1399 for ((i=0; i<${#RPCs[@]}; i++)); do
1400 [ ${RPCs[$i]} -eq 0 ] && continue
1401 # there are still some destroy RPCs in flight
1406 [ ${con} -eq 1 ] && return 0 # done waiting
1407 echo "Waiting $WAIT secs for destroys to be done."
1410 echo "Destroys weren't done in $MAX sec."
1420 # conf-sanity 31 takes a long time cleanup
1421 while [ $WAIT -lt 300 ]; do
1422 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1423 [ -z "${running}" ] && return 0
1424 echo "waited $WAIT for${running}"
1425 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1427 WAIT=$((WAIT + INTERVAL))
1429 echo "service didn't stop after $WAIT seconds. Still running:"
1434 wait_remote_prog () {
1440 [ "$PDSH" = "no_dsh" ] && return 0
1442 while [ $WAIT -lt $2 ]; do
1443 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1444 [ -z "${running}" ] && return 0 || true
1445 echo "waited $WAIT for: "
1447 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1449 WAIT=$((WAIT + INTERVAL))
1451 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1452 [ -z "$pids" ] && return 0
1453 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1454 # FIXME: not portable
1455 for pid in $pids; do
1456 cat /proc/${pid}/status || true
1457 cat /proc/${pid}/wchan || true
1459 kill -9 $pid || true
1468 # not every config has many clients
1470 if [ ! -z "$CLIENTS" ]; then
1471 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1473 stat -f $MOUNT > /dev/null
1479 # usually checked on particular client or locally
1481 if [ ! -z "$client" ]; then
1482 $PDSH $client "stat -f $MOUNT" > /dev/null
1484 stat -f $MOUNT > /dev/null
1492 client_reconnect() {
1493 uname -n >> $MOUNT/recon
1494 if [ -z "$CLIENTS" ]; then
1495 df $MOUNT; uname -n >> $MOUNT/recon
1497 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1499 echo Connected clients:
1501 ls -l $MOUNT/recon > /dev/null
1505 affected_facets () {
1508 local host=$(facet_active_host $facet)
1509 local affected=$facet
1511 if [ "$FAILURE_MODE" = HARD ]; then
1512 affected=$(facets_up_on_host $host)
1520 local host=$(facet_active_host $facet)
1522 echo "Failing $facet on node $host"
1524 # Make sure the client data is synced to disk. LU-924
1526 # We don't write client data synchrnously (to avoid flooding sync writes
1527 # when there are many clients connecting), so if the server reboots before
1528 # the client data reachs disk, the client data will be lost and the client
1529 # will be evicted after recovery, which is not what we expected.
1530 do_facet $facet "sync; sync; sync"
1532 local affected=$(affected_facets $facet)
1534 shutdown_facet $facet
1536 echo affected facets: $affected
1538 [ -n "$sleep_time" ] && sleep $sleep_time
1542 change_active $affected
1544 wait_for_facet $affected
1545 # start mgs first if it is affected
1546 if ! combined_mgs_mds && list_member $affected mgs; then
1547 mount_facet mgs || error "Restart of mgs failed"
1549 # FIXME; has to be changed to mount all facets concurrently
1550 affected=$(exclude_items_from_list $affected mgs)
1551 mount_facets $affected
1560 do_facet $facet "sync; sync; sync"
1563 # make sure there will be no seq change
1564 local clients=${CLIENTS:-$HOSTNAME}
1565 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1567 local svc=${facet}_svc
1568 do_facet $facet $LCTL --device %${!svc} notransno
1569 do_facet $facet $LCTL --device %${!svc} readonly
1570 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1571 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1574 replay_barrier_nodf() {
1575 local facet=$1 echo running=${running}
1576 do_facet $facet "sync; sync; sync"
1577 local svc=${facet}_svc
1578 echo Replay barrier on ${!svc}
1579 do_facet $facet $LCTL --device %${!svc} notransno
1580 do_facet $facet $LCTL --device %${!svc} readonly
1581 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1582 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1585 replay_barrier_nosync() {
1586 local facet=$1 echo running=${running}
1587 local svc=${facet}_svc
1588 echo Replay barrier on ${!svc}
1589 do_facet $facet $LCTL --device %${!svc} notransno
1590 do_facet $facet $LCTL --device %${!svc} readonly
1591 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1592 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1595 mds_evict_client() {
1596 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1597 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1600 ost_evict_client() {
1601 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1602 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1606 facet_failover $* || error "failover: $?"
1607 clients_up || error "post-failover df: $?"
1612 facet_failover $facet
1618 change_active $facet
1619 wait_for_facet $facet
1620 mount_facet $facet -o abort_recovery
1621 clients_up || echo "first df failed: $?"
1622 clients_up || error "post-failover df: $?"
1626 echo There is no lmc. This is mountconf, baby.
1630 host_nids_address() {
1634 if [ -n "$kind" ]; then
1635 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1637 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1643 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1649 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1650 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1651 if [ -z "$ID" ]; then
1652 echo "Could not get a ptl id for $1..."
1661 h2name_or_ip "$1" "tcp"
1666 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1667 if type __h2elan >/dev/null 2>&1; then
1670 ID=`echo $1 | sed 's/[^0-9]*//g'`
1678 h2name_or_ip "$1" "o2ib"
1682 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1683 # expressions format. As a bonus we can then just pass in those variables
1684 # to pdsh. What this function does is take a HOSTLIST type string and
1685 # expand it into a space deliminated list for us.
1693 [ -z "$hostlist" ] && return
1695 # Translate the case of [..],..,[..] to [..] .. [..]
1696 list="${hostlist/],/] }"
1698 [[ "$front" == *,* ]] && {
1701 list=${list/${old}/${new}}
1704 for item in $list; do
1705 # Test if we have any []'s at all
1706 if [ "$item" != "${item/\[/}" ]; then {
1707 # Expand the [*] into list
1711 if [ "$name" != "$item" ]; then
1712 group=${item#$name[*}
1715 for range in ${group//,/ }; do
1719 # Number of leading zeros
1722 end=$(echo $end | sed 's/0*//')
1723 [[ -z "$end" ]] && end=0
1724 [[ $padlen2 -gt $padlen ]] && {
1725 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1728 begin=$(echo $begin | sed 's/0*//')
1729 [ -z $begin ] && begin=0
1731 for num in $(seq -f "%0${padlen}g" $begin $end); do
1732 value="${name#*,}${num}${back}"
1733 [ "$value" != "${value/\[/}" ] && {
1734 value=$(hostlist_expand "$value")
1736 myList="$myList $value"
1741 myList="$myList $item"
1744 myList=${myList//,/ }
1745 myList=${myList:1} # Remove first character which is a space
1747 # Filter any duplicates without sorting
1749 myList="${list%% *}"
1751 while [[ "$list" != ${myList##* } ]]; do
1752 list=${list//${list%% *} /}
1753 myList="$myList ${list%% *}"
1755 myList="${myList%* }";
1757 # We can select an object at a offset in the list
1760 for item in $myList; do
1762 [ $cnt -eq $offset ] && {
1766 [ $(get_node_count $myList) -ne 1 ] && myList=""
1774 [ "$facet" == client ] && echo -n $HOSTNAME && return
1775 varname=${facet}_HOST
1776 if [ -z "${!varname}" ]; then
1777 if [ "${facet:0:3}" == "ost" ]; then
1778 eval ${facet}_HOST=${ost_HOST}
1786 local activevar=${facet}active
1788 if [ -f $TMP/${facet}active ] ; then
1789 source $TMP/${facet}active
1792 active=${!activevar}
1793 if [ -z "$active" ] ; then
1800 facet_active_host() {
1802 local active=`facet_active $facet`
1803 if [ "$facet" == client ]; then
1806 echo `facet_host $active`
1814 facetlist=$(exclude_items_from_list $facetlist mgs)
1816 for facet in ${facetlist//,/ }; do
1817 local failover=${facet}failover
1818 local host=`facet_host $failover`
1819 [ -z "$host" ] && return
1821 local curactive=`facet_active $facet`
1822 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1823 eval export ${facet}active=$facet
1825 eval export ${facet}active=$failover
1827 # save the active host for this facet
1828 local activevar=${facet}active
1829 echo "$activevar=${!activevar}" > $TMP/$activevar
1830 [[ $facet = mds1 ]] && combined_mgs_mds && \
1831 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1832 local TO=`facet_active_host $facet`
1833 echo "Failover $facet to $TO"
1839 # do not stripe off hostname if verbose, bug 19215
1840 if [ x$1 = x--verbose ]; then
1848 if [ "$HOST" = "$HOSTNAME" ]; then
1850 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1851 echo "cannot run remote command on $HOST with $myPDSH"
1855 echo "CMD: $HOST $@" >&2
1856 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1859 if [ "$myPDSH" = "rsh" ]; then
1860 # we need this because rsh does not return exit code of an executed command
1861 local command_status="$TMP/cs"
1862 rsh $HOST ":> $command_status"
1863 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1864 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1865 echo command failed >$command_status"
1866 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1871 # print HOSTNAME for myPDSH="no_dsh"
1872 if [[ $myPDSH = no_dsh ]]; then
1873 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1875 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1878 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1880 return ${PIPESTATUS[0]}
1884 do_node --verbose "$@"
1887 single_local_node () {
1888 [ "$1" = "$HOSTNAME" ]
1891 # Outputs environment variable assignments that should be passed to remote nodes
1896 for var in ${!MODOPTS_*}; do
1898 echo "${var}=\"$value\""
1904 # do not stripe off hostname if verbose, bug 19215
1905 if [ x$1 = x--verbose ]; then
1913 if single_local_node $rnodes; then
1915 do_nodev $rnodes "$@"
1917 do_node $rnodes "$@"
1922 # This is part from do_node
1925 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1926 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1929 echo "CMD: $rnodes $@" >&2
1930 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1933 # do not replace anything from pdsh output if -N is used
1934 # -N Disable hostname: prefix on lines of output.
1935 if $verbose || [[ $myPDSH = *-N* ]]; then
1936 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1938 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1940 return ${PIPESTATUS[0]}
1946 local HOST=`facet_active_host $facet`
1947 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1952 do_nodes --verbose "$@"
1958 # make sure its not already running
1960 rm -f $TMP/${facet}active
1961 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
1962 do_facet ${facet} $MKFS $*
1968 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1969 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1976 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1977 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1983 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
1985 local var=${facet}_MOUNT
1986 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1995 # make sure we are using the primary server, so test-framework will
1996 # be able to clean up properly.
1997 activemds=`facet_active mds1`
1998 if [ $activemds != "mds1" ]; then
2002 local clients=$CLIENTS
2003 [ -z $clients ] && clients=$(hostname)
2005 zconf_umount_clients $clients $MOUNT "$*" || true
2006 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2008 [ "$CLIENTONLY" ] && return
2009 # The add fn does rm ${facet}active file, this would be enough
2010 # if we use do_facet <facet> only after the facet added, but
2011 # currently we use do_facet mds in local.sh
2012 for num in `seq $MDSCOUNT`; do
2014 rm -f ${TMP}/mds${num}active
2016 combined_mgs_mds && rm -f $TMP/mgsactive
2018 for num in `seq $OSTCOUNT`; do
2020 rm -f $TMP/ost${num}active
2023 if ! combined_mgs_mds ; then
2030 cleanup_echo_devs () {
2031 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2033 for dev in $devs; do
2034 $LCTL --device $dev cleanup
2035 $LCTL --device $dev detach
2040 nfs_client_mode && return
2049 combined_mgs_mds () {
2050 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2056 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2057 local optvar=${tgt}_MKFS_OPTS
2058 local opt=${!optvar}
2060 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2061 [[ $facet = mgs ]] && echo $opt && return
2064 # --failnode options
2065 local var=${facet}failover_HOST
2066 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2067 local failnode=$(h2$NETTYPE ${!var})
2068 failnode="--failnode=$failnode"
2069 # options does not contain
2070 # or contains wrong --failnode=
2071 if [[ $opt != *${failnode}* ]]; then
2072 opt=$(echo $opt | sed 's/--failnode=.* / /')
2073 opt="$opt $failnode"
2079 # no additional mkfs mds "--mgsnode" option for this configuration
2080 if [[ $facet = mds ]] && combined_mgs_mds; then
2085 # additional mkfs "--mgsnode"
2086 local mgsnode="--mgsnode=$MGSNID"
2087 opt=${opt//$mgsnode }
2088 for nid in ${MGSNID//:/ }; do
2089 local mgsnode="--mgsnode=$nid"
2090 # options does not contain
2092 if [[ $opt != *${mgsnode}" "* ]]; then
2093 opt="$opt --mgsnode=$nid"
2101 if [ "$IAMDIR" == "yes" ]; then
2102 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2105 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2108 # We need ldiskfs here, may as well load them all
2110 [ "$CLIENTONLY" ] && return
2111 echo Formatting mgs, mds, osts
2112 if ! combined_mgs_mds ; then
2113 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2116 for num in `seq $MDSCOUNT`; do
2117 echo "Format mds$num: $(mdsdevname $num)"
2119 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2121 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2125 # the ost-s could have different OST_MKFS_OPTS
2126 # because of different failnode-s
2127 for num in `seq $OSTCOUNT`; do
2128 echo "Format ost$num: $(ostdevname $num)"
2130 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2132 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2138 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2142 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2146 # 0: success, the old identity set already.
2147 # 1: success, the old identity does not set.
2152 local j=`expr $num - 1`
2153 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2155 if [ -z "$MDT" ]; then
2159 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2162 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2164 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2167 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2169 if [ $old = "NONE" ]; then
2178 zconf_umount `hostname` $1 || error "umount failed"
2179 zconf_mount `hostname` $1 || error "mount failed"
2182 writeconf_facet () {
2186 do_facet $facet "$TUNEFS --writeconf $dev"
2190 for num in `seq $MDSCOUNT`; do
2191 DEVNAME=$(mdsdevname $num)
2192 writeconf_facet mds$num $DEVNAME
2195 for num in `seq $OSTCOUNT`; do
2196 DEVNAME=$(ostdevname $num)
2197 writeconf_facet ost$num $DEVNAME
2202 nfs_client_mode && return
2204 sanity_mount_check ||
2205 error "environments are insane!"
2209 if [ -z "$CLIENTONLY" ]; then
2210 echo Setup mgs, mdt, osts
2211 echo $WRITECONF | grep -q "writeconf" && \
2213 if ! combined_mgs_mds ; then
2214 start mgs $MGSDEV $MGS_MOUNT_OPTS
2217 for num in `seq $MDSCOUNT`; do
2218 DEVNAME=$(mdsdevname $num)
2219 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2221 # We started mds, now we should set failover variables properly.
2222 # Set mds${num}failover_HOST if it is not set (the default failnode).
2223 local varname=mds${num}failover_HOST
2224 if [ -z "${!varname}" ]; then
2225 eval mds${num}failover_HOST=$(facet_host mds$num)
2228 if [ $IDENTITY_UPCALL != "default" ]; then
2229 switch_identity $num $IDENTITY_UPCALL
2232 for num in `seq $OSTCOUNT`; do
2233 DEVNAME=$(ostdevname $num)
2234 start ost$num $DEVNAME $OST_MOUNT_OPTS
2236 # We started ost$num, now we should set ost${num}failover variable properly.
2237 # Set ost${num}failover_HOST if it is not set (the default failnode).
2238 varname=ost${num}failover_HOST
2239 if [ -z "${!varname}" ]; then
2240 eval ost${num}failover_HOST=$(facet_host ost${num})
2248 # wait a while to allow sptlrpc configuration be propogated to targets,
2249 # only needed when mounting new target devices.
2254 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2256 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2258 if [ "$MOUNT_2" ]; then
2259 mount_client $MOUNT2
2260 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2265 # by remounting mdt before ost, initial connect from mdt to ost might
2266 # timeout because ost is not ready yet. wait some time to its fully
2267 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2268 # by a context negotiation rpc with $TIMEOUT.
2269 # FIXME better by monitoring import status.
2272 sleep $((TIMEOUT + 5))
2278 mounted_lustre_filesystems() {
2279 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2282 init_facet_vars () {
2283 [ "$CLIENTONLY" ] && return 0
2290 eval export ${facet}_dev=${device}
2291 eval export ${facet}_opt=\"$@\"
2293 local dev=${facet}_dev
2294 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2295 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2297 eval export ${facet}_svc=${label}
2299 local varname=${facet}failover_HOST
2300 if [ -z "${!varname}" ]; then
2301 eval $varname=$(facet_host $facet)
2304 # ${facet}failover_dev is set in cfg file
2305 varname=${facet}failover_dev
2306 if [ -n "${!varname}" ] ; then
2307 eval export ${facet}failover_dev=${!varname}
2309 eval export ${facet}failover_dev=$device
2312 # get mount point of already mounted device
2313 # is facet_dev is already mounted then use the real
2314 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2315 # i.e. ${facet}_MOUNT if specified by user or default
2316 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2317 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2318 if [ -z $mntpt ]; then
2319 mntpt=$(facet_mntpt $facet)
2321 eval export ${facet}_MOUNT=$mntpt
2324 init_facets_vars () {
2327 if ! remote_mds_nodsh; then
2328 for num in `seq $MDSCOUNT`; do
2329 DEVNAME=`mdsdevname $num`
2330 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2334 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2336 remote_ost_nodsh && return
2338 for num in `seq $OSTCOUNT`; do
2339 DEVNAME=`ostdevname $num`
2340 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2344 osc_ensure_active () {
2349 while [ $period -lt $timeout ]; do
2350 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2351 if [ $count -eq 0 ]; then
2355 echo "There are $count OST are inactive, wait $period seconds, and try again"
2357 period=$((period+3))
2360 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2363 init_param_vars () {
2364 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2365 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2366 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2367 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2371 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2373 log "Using TIMEOUT=$TIMEOUT"
2375 osc_ensure_active $SINGLEMDS $TIMEOUT
2376 osc_ensure_active client $TIMEOUT
2378 if [ $QUOTA_AUTO -ne 0 ]; then
2379 if [ "$ENABLE_QUOTA" ]; then
2380 echo "enable quota as required"
2381 setup_quota $MOUNT || return 2
2383 echo "disable quota as required"
2384 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2391 nfs_client_mode () {
2392 if [ "$NFSCLIENT" ]; then
2393 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2394 local clients=$CLIENTS
2395 [ -z $clients ] && clients=$(hostname)
2397 # FIXME: remove hostname when 19215 fixed
2398 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2399 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2400 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2401 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2403 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2409 check_config_client () {
2412 local mounted=$(mount | grep " $mntpt ")
2413 if [ "$CLIENTONLY" ]; then
2415 # CLIENTONLY should not depend on *_HOST settings
2416 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2417 # in theory someone could create a new,
2418 # client-only config file that assumed lustre was already
2419 # configured and didn't set the MGSNID. If MGSNID is not set,
2420 # then we should use the mgs nid currently being used
2421 # as the default value. bug 18021
2422 [[ x$MGSNID = x ]] &&
2425 if [[ x$mgc != xMGC$MGSNID ]]; then
2426 if [ "$mgs_HOST" ]; then
2427 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2428 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2429 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2435 local myMGS_host=$mgs_HOST
2436 if [ "$NETTYPE" = "ptl" ]; then
2437 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2440 echo Checking config lustre mounted on $mntpt
2441 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2442 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2444 # if [ "$mgshost" != "$myMGS_host" ]; then
2445 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2446 # Please use correct config or set mds_HOST correctly!"
2451 check_config_clients () {
2452 local clients=${CLIENTS:-$HOSTNAME}
2455 nfs_client_mode && return
2457 do_rpc_nodes $clients check_config_client $mntpt
2459 sanity_mount_check ||
2460 error "environments are insane!"
2464 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2465 local cltimeout=$(lctl get_param -n timeout)
2466 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2467 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2474 [ -z $mntpt ] && return 1
2475 local mounted=$(mounted_lustre_filesystems)
2477 echo $mounted' ' | grep -w -q $mntpt' '
2481 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2485 # empty lustre filesystem may have empty directories lost+found and .lustre
2487 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2488 -print | wc -l) = 1 ] || return 1
2489 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2490 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2494 check_and_setup_lustre() {
2495 nfs_client_mode && return
2497 local MOUNTED=$(mounted_lustre_filesystems)
2501 # both MOUNT and MOUNT2 are not mounted
2502 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2503 [ "$REFORMAT" ] && formatall
2504 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2506 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2507 export I_MOUNTED=yes
2511 elif is_mounted $MOUNT2; then
2513 # MOUNT2 is mounted, while MOUNT_2 is not set
2514 if ! [ "$MOUNT_2" ]; then
2515 cleanup_mount $MOUNT2
2516 export I_UMOUNTED2=yes
2519 # MOUNT2 is mounted, MOUNT_2 is set
2521 # FIXME: what to do if check_config failed?
2523 # 1) remote client has mounted other Lustre fs ?
2524 # 2) it has insane env ?
2525 # let's try umount MOUNT2 on all clients and mount it again:
2526 if ! check_config_clients $MOUNT2; then
2527 cleanup_mount $MOUNT2
2528 restore_mount $MOUNT2
2529 export I_MOUNTED2=yes
2534 # MOUNT is mounted MOUNT2 is not mounted
2535 elif [ "$MOUNT_2" ]; then
2536 restore_mount $MOUNT2
2537 export I_MOUNTED2=yes
2541 # FIXME: what to do if check_config failed?
2543 # 1) remote client has mounted other Lustre fs?
2544 # 2) lustre is mounted on remote_clients atall ?
2545 check_config_clients $MOUNT
2549 set_default_debug_nodes $(comma_list $(nodes_list))
2555 if [ "$ONLY" == "setup" ]; then
2561 local clients=${CLIENTS:-$HOSTNAME}
2564 zconf_mount_clients $clients $mntpt
2568 local clients=${CLIENTS:-$HOSTNAME}
2571 zconf_umount_clients $clients $mntpt
2574 cleanup_and_setup_lustre() {
2575 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2576 lctl set_param debug=0 || true
2578 if [ "$ONLY" == "cleanup" ]; then
2582 check_and_setup_lustre
2585 # Get all of the server target devices from a given server node and type.
2594 mdt) obd_type="osd" ;;
2595 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2596 *) echo "invalid server type" && return 1 ;;
2599 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2600 for dev in $devs; do
2602 *loop*) do_node $node "losetup $dev" | \
2603 sed -e "s/.*(//" -e "s/).*//" ;;
2609 # Get all of the server target devices.
2614 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2618 for node in $(osts_nodes); do
2619 OSTDEVS[i]=$(get_mnt_devs $node ost)
2624 # Run e2fsck on MDT or OST device.
2630 df > /dev/null # update statfs data on disk
2631 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2634 do_node $node $cmd || rc=$?
2635 [ $rc -le $FSCK_MAX_ERR ] || \
2636 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2640 # verify a directory is shared among nodes.
2641 check_shared_dir() {
2644 [ -z "$dir" ] && return 1
2645 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
2646 check_write_access $dir || return 1
2650 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2656 check_shared_dir $SHARED_DIRECTORY ||
2657 error "$SHARED_DIRECTORY isn't a shared directory"
2659 export MDSDB=$SHARED_DIRECTORY/mdsdb
2660 export OSTDB=$SHARED_DIRECTORY/ostdb
2662 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2664 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2669 for node in $(osts_nodes); do
2670 for dev in ${OSTDEVS[i]}; do
2671 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2672 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2673 ostidx=$((ostidx + 1))
2680 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2684 [ $rc -le $FSCK_MAX_ERR ] || \
2685 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2686 echo "lfsck finished with rc=$rc"
2688 rm -rvf $MDSDB* $OSTDB* || true
2692 check_and_cleanup_lustre() {
2693 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2699 if is_mounted $MOUNT; then
2700 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2701 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2704 if [ "$I_UMOUNTED2" = "yes" ]; then
2705 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2708 if [ "$I_MOUNTED2" = "yes" ]; then
2709 cleanup_mount $MOUNT2
2712 if [ "$I_MOUNTED" = "yes" ]; then
2713 cleanupall -f || error "cleanup failed"
2721 wait_for_function () {
2724 # suppress fn both stderr and stdout
2725 if [ "$1" = "--quiet" ]; then
2727 quiet=" > /dev/null 2>&1"
2739 eval $fn $quiet && return 0
2741 wait=$((wait + sleep))
2742 [ $wait -lt $max ] || return 1
2743 echo waiting $fn, $((max - wait)) secs left ...
2753 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2754 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2755 echo "Network not available!"
2759 echo `date +"%H:%M:%S (%s)"` network interface is UP
2768 # the sed converts spaces to commas, but leaves the last space
2769 # alone, so the line doesn't end with a comma.
2770 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2776 echo $list | grep -qw $item
2779 # list, excluded are the comma separated lists
2780 exclude_items_from_list () {
2786 for item in ${excluded//,/ }; do
2787 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2789 echo $(comma_list $list)
2792 # list, expand are the comma separated lists
2794 local list=${1//,/ }
2795 local expand=${2//,/ }
2798 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2799 echo $(comma_list $expanded)
2802 testslist_filter () {
2803 local script=$LUSTRE/tests/${TESTSUITE}.sh
2805 [ -f $script ] || return 0
2807 local start_at=$START_AT
2808 local stop_at=$STOP_AT
2810 local var=${TESTSUITE//-/_}_START_AT
2811 [ x"${!var}" != x ] && start_at=${!var}
2812 var=${TESTSUITE//-/_}_STOP_AT
2813 [ x"${!var}" != x ] && stop_at=${!var}
2815 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2816 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2817 /^'${start_at}'$/ {flag = 0}
2818 {if (flag == 1) print $0}
2819 /^'${stop_at}'$/ { flag = 1 }'
2823 (cd `dirname $1`; echo $PWD/`basename $1`)
2827 local types=${1:-"OST MDS MGS"}
2831 for entry in $types; do
2832 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2833 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2836 MGS ) list="$list $name";;
2837 MDS|OST ) local count=${type}COUNT
2838 for ((i=1; i<=${!count}; i++)) do
2839 list="$list ${name}$i"
2841 * ) error "Invalid facet type"
2845 echo $(comma_list $list)
2848 ##################################
2849 # Adaptive Timeouts funcs
2852 # only check mds, we assume at_max is the same on all nodes
2853 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2854 if [ $at_max -eq 0 ]; then
2865 # suppose that all ost-s have the same $at value set
2866 [ $facet != "ost" ] || facet=ost1
2868 do_facet $facet "lctl get_param -n $at"
2882 if [ $facet == "ost" ]; then
2883 facet=$(get_facets OST)
2884 elif [ $facet == "mds" ]; then
2885 facet=$(get_facets MDS)
2887 hosts=$(expand_list $hosts $(facets_hosts $facet))
2890 do_nodes $hosts lctl set_param at_max=$at_max
2893 ##################################
2897 # OBD_FAIL_MDS_ALL_REQUEST_NET
2899 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2900 do_facet client "$1" || RC=$?
2901 do_facet $SINGLEMDS lctl set_param fail_loc=0
2906 # OBD_FAIL_MDS_ALL_REPLY_NET
2908 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2909 do_facet client "$@" || RC=$?
2910 do_facet $SINGLEMDS lctl set_param fail_loc=0
2914 drop_reint_reply() {
2915 # OBD_FAIL_MDS_REINT_NET_REP
2917 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2918 do_facet client "$@" || RC=$?
2919 do_facet $SINGLEMDS lctl set_param fail_loc=0
2924 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2926 do_facet ost1 lctl set_param fail_loc=0x214
2927 do_facet client "$1" || RC=$?
2928 do_facet client "sync"
2929 do_facet ost1 lctl set_param fail_loc=0
2933 drop_ldlm_cancel() {
2934 #define OBD_FAIL_LDLM_CANCEL 0x304
2936 do_facet client lctl set_param fail_loc=0x304
2937 do_facet client "$@" || RC=$?
2938 do_facet client lctl set_param fail_loc=0
2942 drop_bl_callback() {
2943 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2945 do_facet client lctl set_param fail_loc=0x305
2946 do_facet client "$@" || RC=$?
2947 do_facet client lctl set_param fail_loc=0
2952 #define OBD_FAIL_LDLM_REPLY 0x30c
2954 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2955 do_facet client "$@" || RC=$?
2956 do_facet $SINGLEMDS lctl set_param fail_loc=0
2964 echo "clearing fail_loc on $facet"
2965 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2968 set_nodes_failloc () {
2969 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2972 cancel_lru_locks() {
2973 $LCTL mark "cancel_lru_locks $1 start"
2974 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2975 $LCTL set_param -n $d=clear
2977 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2978 $LCTL mark "cancel_lru_locks $1 stop"
2983 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2984 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2985 echo "$DEFAULT_LRU_SIZE"
2990 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2993 lru_resize_disable()
2995 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3000 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3001 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3002 echo there is still data in page cache $FILE ?
3003 lctl get_param -n $FILE
3011 DEBUGSAVE="$(lctl get_param -n debug)"
3015 [ -n "$DEBUGSAVE" ] && \
3016 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3021 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3024 debug_size_restore() {
3025 [ -n "$DEBUG_SIZE_SAVED" ] && \
3026 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3030 start_full_debug_logging() {
3035 local DEBUG_SIZE=150
3037 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3038 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3041 stop_full_debug_logging() {
3046 ##################################
3048 ##################################
3051 local TYPE=${TYPE:-"FAIL"}
3054 # do not dump logs if $1=false
3055 if [ "x$1" = "xfalse" ]; then
3060 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3062 # We need to dump the logs on all nodes
3064 gather_logs $(comma_list $(nodes_list)) 0
3068 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3069 echo "$@" > $LOGDIR/err
3074 local log=$TESTSUITELOG
3076 [ -f "$log" ] && grep -q FAIL: $log && status=1
3089 # use only if we are ignoring failures for this test, bugno required.
3090 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3091 # e.g. error_ignore 5494 "your message"
3093 local TYPE="IGNORE (bz$1)"
3099 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3104 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3105 [ "$ALWAYS_SKIPPED" ] && \
3106 skip_logged ${TESTNAME} "$@" || true
3107 [ "$TESTSUITELOG" ] && \
3108 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3111 build_test_filter() {
3112 EXCEPT="$EXCEPT $(testslist_filter)"
3114 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3118 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3119 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3120 [ "$EXCEPT_SLOW" ] && \
3121 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3122 for E in $EXCEPT; do
3123 eval EXCEPT_${E}=true
3125 for E in $ALWAYS_EXCEPT; do
3126 eval EXCEPT_ALWAYS_${E}=true
3128 for E in $EXCEPT_SLOW; do
3129 eval EXCEPT_SLOW_${E}=true
3131 for G in $GRANT_CHECK_LIST; do
3132 eval GCHECK_ONLY_${G}=true
3137 if [[ $1 = [a-z]* ]]; then
3144 # print a newline if the last test was skipped
3145 export LAST_SKIPPED=
3146 export ALWAYS_SKIPPED=
3148 # Main entry into test-framework. This is called with the name and
3149 # description of a test. The name is used to find the function to run
3150 # the test using "test_$name".
3152 # This supports a variety of methods of specifying specific test to
3153 # run or not run. These need to be documented...
3158 export base=`basetest $1`
3159 if [ ! -z "$ONLY" ]; then
3161 if [ ${!testname}x != x ]; then
3162 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3163 run_one_logged $1 "$2"
3167 if [ ${!testname}x != x ]; then
3168 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3169 run_one_logged $1 "$2"
3177 if [ ${!testname}x != x ]; then
3179 TESTNAME=test_$1 skip "skipping excluded test $1"
3182 testname=EXCEPT_$base
3183 if [ ${!testname}x != x ]; then
3185 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3188 testname=EXCEPT_ALWAYS_$1
3189 if [ ${!testname}x != x ]; then
3192 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3195 testname=EXCEPT_ALWAYS_$base
3196 if [ ${!testname}x != x ]; then
3199 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3202 testname=EXCEPT_SLOW_$1
3203 if [ ${!testname}x != x ]; then
3205 TESTNAME=test_$1 skip "skipping SLOW test $1"
3208 testname=EXCEPT_SLOW_$base
3209 if [ ${!testname}x != x ]; then
3211 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3217 run_one_logged $1 "$2"
3228 module_loaded lnet || load_modules
3240 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3245 strace -o $TMP/$1.strace -ttt $*
3247 log "FINISHED: $*: rc $RC"
3252 equals_msg $1 test complete, duration $2 sec
3253 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3254 echo duration $2 >>$TESTSUITELOG
3258 # Set TEST_STATUS here; will be used for logging the result
3259 if [ -f $LOGDIR/err ]; then
3264 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3268 local FFREE=$(do_node $SINGLEMDS \
3269 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3270 local FTOTAL=$(do_node $SINGLEMDS \
3271 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3273 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3277 echo -n "Resetting fail_loc on all nodes..."
3278 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3284 # Log a message (on all nodes) padded with "=" before and after.
3285 # Also appends a timestamp and prepends the testsuite name.
3288 EQUALS="===================================================================================================="
3290 msg="== ${TESTSUITE} $*"
3292 [[ $last != "=" && $last != " " ]] && msg="$msg "
3293 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3294 # always include at least == after the message
3295 log "$msg== $(date +"%H:%M:%S (%s)")"
3299 # Run a single test function and cleanup after it.
3301 # This function should be run in a subshell so the test func can
3302 # exit() without stopping the whole script.
3308 export tdir=d0.${TESTSUITE}/d${base}
3309 export TESTNAME=test_$testnum
3310 local SAVE_UMASK=`umask`
3313 banner "test $testnum: $message"
3314 test_${testnum} || error "test_$testnum failed with $?"
3317 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3318 check_catastrophe || error "LBUG/LASSERT detected"
3319 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3327 # Wrapper around run_one to ensure:
3328 # - test runs in subshell
3329 # - output of test is saved to separate log file for error reporting
3330 # - test result is saved to data file
3333 local BEFORE=`date +%s`
3335 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3336 local test_log=$LOGDIR/$name
3338 local SAVE_UMASK=`umask`
3342 log_sub_test_begin test_${1}
3343 (run_one $1 "$2") 2>&1 | tee -i $test_log
3344 local RC=${PIPESTATUS[0]}
3346 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3347 echo "test_$1 returned $RC" | tee $LOGDIR/err
3349 duration=$((`date +%s` - $BEFORE))
3350 pass "$1" "(${duration}s)"
3351 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3352 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3354 if [ -f $LOGDIR/err ]; then
3355 $FAIL_ON_ERROR && exit $RC
3364 # Print information of skipped tests to result.yml
3367 log_sub_test_begin $1
3368 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3372 (cd `dirname $1`; echo $PWD/`basename $1`)
3377 export base=`basetest $1`
3378 [ "$CHECK_GRANT" == "no" ] && return 0
3380 testname=GCHECK_ONLY_${base}
3381 [ ${!testname}x == x ] && return 0
3383 echo -n "checking grant......"
3385 local clients=$CLIENTS
3386 [ -z $clients ] && clients=$(hostname)
3388 # sync all the data and make sure no pending data on server
3389 do_nodes $clients sync
3392 client_grant=`do_nodes $clients \
3393 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3394 awk '{total += $1} END{print total}'`
3397 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3398 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
3399 awk '{total += $1} END{print total}'`
3401 # check whether client grant == server grant
3402 if [ $client_grant -ne $server_grant ]; then
3403 echo "failed: client:${client_grant} server: ${server_grant}."
3404 do_nodes $(comma_list $(osts_nodes)) \
3405 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3406 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3409 echo "pass: client:${client_grant} server: ${server_grant}"
3414 ########################
3420 ost=`echo $1 | awk -F_ '{print $3}'`
3421 if [ -z $ost ]; then
3422 ost=`echo $1 | sed 's/-osc.*//'`
3427 ostuuid_from_index()
3429 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3432 ostname_from_index() {
3433 local uuid=$(ostuuid_from_index $1)
3437 index_from_ostuuid()
3439 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3444 [ "$node" != "$(hostname)" ]
3450 for node in $(mdts_nodes); do
3451 remote_node $node && return 0
3458 [ "$CLIENTONLY" ] && return 0 || true
3459 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3464 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3465 MSKIPPED=1 && return 1
3472 for node in $(osts_nodes) ; do
3473 remote_node $node && return 0
3480 [ "$CLIENTONLY" ] && return 0 || true
3481 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3486 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3487 OSKIPPED=1 && return 1
3494 MGS=$(facet_host mgs)
3495 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3500 remote_mds_nodsh || remote_ost_nodsh || \
3501 $(single_local_node $(comma_list $(nodes_list)))
3507 for num in `seq $MDSCOUNT`; do
3508 MDSNODES="$MDSNODES $(facet_host mds$num)"
3510 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3516 remote_ost && remote_mds
3524 for facet in ${facets//,/ }; do
3525 if [ "$FAILURE_MODE" = HARD ]; then
3526 nodes="$nodes $(facet_active_host $facet)"
3528 nodes="$nodes $(facet_host $facet)"
3531 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3537 local facets=$(get_facets OST)
3538 local nodes=$(facets_nodes $facets)
3544 # FIXME. We need a list of clients
3545 local myNODES=$HOSTNAME
3548 # CLIENTS (if specified) contains the local client
3549 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3551 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3552 myNODES="$myNODES $(facets_nodes $(get_facets))"
3555 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3560 remote_nodes_list () {
3561 local rnodes=$(nodes_list)
3562 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3566 init_clients_lists () {
3567 # Sanity check: exclude the local client from RCLIENTS
3568 local clients=$(hostlist_expand "$RCLIENTS")
3569 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3571 # Sanity check: exclude the dup entries
3572 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3574 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3576 # Sanity check: exclude the dup entries from CLIENTS
3577 # for those configs which has SINGLCLIENT set to local client
3578 clients=$(for i in $clients; do echo $i; done | sort -u)
3580 CLIENTS=$(comma_list $clients)
3581 local -a remoteclients=($RCLIENTS)
3582 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3583 varname=CLIENT$((i + 2))
3584 eval $varname=${remoteclients[i]}
3587 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3590 get_random_entry () {
3593 rnodes=${rnodes//,/ }
3595 local -a nodes=($rnodes)
3596 local num=${#nodes[@]}
3597 local i=$((RANDOM * num * 2 / 65536))
3603 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3608 lctl get_param version | grep -q patchless
3612 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3617 echo $nodes | wc -w || true
3621 local nodes=$(osts_nodes)
3622 local osscount=$(get_node_count "$nodes")
3623 [ ! "$OSTCOUNT" = "$osscount" ]
3627 local nodes=$(mdts_nodes)
3628 local mdtcount=$(get_node_count "$nodes")
3629 [ ! "$MDSCOUNT" = "$mdtcount" ]
3632 generate_machine_file() {
3633 local nodes=${1//,/ }
3634 local machinefile=$2
3636 for node in $nodes; do
3637 echo $node >>$machinefile || \
3638 { echo "can not generate machinefile $machinefile" && return 1; }
3643 local file=$1/stripe
3645 $LFS getstripe -v $file || error
3649 setstripe_nfsserver () {
3652 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3653 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3655 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3657 do_nodev $nfsserver lfs setstripe "$@"
3660 check_runas_id_ret() {
3662 local myRUNAS_UID=$1
3663 local myRUNAS_GID=$2
3666 if [ -z "$myRUNAS" ]; then
3667 error_exit "myRUNAS command must be specified for check_runas_id"
3670 $myRUNAS krb5_login.sh || \
3671 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3673 mkdir $DIR/d0_runas_test
3675 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3676 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3677 rm -rf $DIR/d0_runas_test
3682 local myRUNAS_UID=$1
3683 local myRUNAS_GID=$2
3686 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3687 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3688 Please set RUNAS_ID to some UID which exists on MDS and client or
3689 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3692 # obtain the UID/GID for MPI_USER
3696 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3697 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3699 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3700 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3703 # obtain and cache Kerberos ticket-granting ticket
3704 refresh_krb5_tgt() {
3705 local myRUNAS_UID=$1
3706 local myRUNAS_GID=$2
3709 if [ -z "$myRUNAS" ]; then
3710 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3713 CLIENTS=${CLIENTS:-$HOSTNAME}
3714 do_nodes $CLIENTS "set -x
3715 if ! $myRUNAS krb5_login.sh; then
3716 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3721 # Run multiop in the background, but wait for it to print
3722 # "PAUSING" to its stdout before returning from this function.
3723 multiop_bg_pause() {
3724 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3728 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3731 echo "$MULTIOP_PROG $FILE v$ARGS"
3732 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3734 echo "TMPPIPE=${TMPPIPE}"
3735 read -t 60 multiop_output < $TMPPIPE
3736 if [ $? -ne 0 ]; then
3741 if [ "$multiop_output" != "PAUSING" ]; then
3742 echo "Incorrect multiop output: $multiop_output"
3757 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3763 inodes_available () {
3764 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3768 mdsrate_inodes_available () {
3769 local min_inodes=$(inodes_available)
3770 echo $((min_inodes * 99 / 100))
3773 # reset llite stat counters
3774 clear_llite_stats(){
3775 lctl set_param -n llite.*.stats 0
3778 # sum llite stat items
3779 calc_llite_stats() {
3780 local res=$(lctl get_param -n llite.*.stats |
3781 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3785 # reset osc stat counters
3787 lctl set_param -n osc.*.osc_stats 0
3790 # sum osc stat items
3792 local res=$(lctl get_param -n osc.*.osc_stats |
3793 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3798 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3801 calc_osc_kbytes () {
3802 df $MOUNT > /dev/null
3803 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3806 # save_lustre_params(node, parameter_mask)
3807 # generate a stream of formatted strings (<node> <param name>=<param value>)
3808 save_lustre_params() {
3810 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3813 # restore lustre parameters from input stream, produces by save_lustre_params
3814 restore_lustre_params() {
3818 while IFS=" =" read node name val; do
3819 do_node ${node//:/} "lctl set_param -n $name $val"
3823 check_catastrophe() {
3824 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3825 local C=$CATASTROPHE
3826 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3828 if [ $rnodes ]; then
3829 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3830 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3846 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3848 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3849 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3850 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3854 # CMD: determine mds index where directory inode presents
3857 local file=$dir/f0.get_mds_dir_tmpfile
3862 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3863 local -a oldused=($iused)
3865 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3867 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3868 local -a newused=($iused)
3871 for ((i=0; i<${#newused[@]}; i++)); do
3872 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3878 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3881 mdsrate_cleanup () {
3883 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3888 delayed_recovery_enabled () {
3889 local var=${SINGLEMDS}_svc
3890 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3893 ########################
3895 convert_facet2label() {
3898 if [ x$facet = xost ]; then
3902 local varsvc=${facet}_svc
3904 if [ -n ${!varsvc} ]; then
3907 error "No lablel for $facet!"
3911 get_clientosc_proc_path() {
3912 echo "${1}-osc-[^M]*"
3915 get_lustre_version () {
3916 local facet=${1:-"$SINGLEMDS"}
3917 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3920 get_mds_version_major () {
3921 local facet=${1:-"$SINGLEMDS"}
3922 local version=$(get_lustre_version $facet)
3923 echo $version | awk -F. '{print $1}'
3926 get_mds_version_minor () {
3927 local facet=${1:-"$SINGLEMDS"}
3928 local version=$(get_lustre_version $facet)
3929 echo $version | awk -F. '{print $2}'
3932 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
3933 # used by MDT would not be changed.
3934 # mdt lov: fsname-mdtlov
3935 # mdt osc: fsname-OSTXXXX-osc
3936 mds_on_old_device() {
3937 local mds=${1:-"$SINGLEMDS"}
3938 local major=$(get_mds_version_major $mds)
3939 local minor=$(get_mds_version_minor $mds)
3941 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
3942 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
3943 > /dev/null 2>&1" && return 0
3948 get_mdtosc_proc_path() {
3950 local ost_label=${2:-"*OST*"}
3952 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
3953 local mdt_label=$(convert_facet2label $mds_facet)
3954 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
3956 local major=$(get_mds_version_major $mds_facet)
3957 local minor=$(get_mds_version_minor $mds_facet)
3958 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
3959 echo "${ost_label}-osc"
3961 echo "${ost_label}-osc-${mdt_index}"
3965 get_osc_import_name() {
3968 local label=$(convert_facet2label $ost)
3970 if [ "${facet:0:3}" = "mds" ]; then
3971 get_mdtosc_proc_path $facet $label
3975 get_clientosc_proc_path $label
3979 _wait_import_state () {
3982 local maxtime=${3:-$(max_recovery_time)}
3986 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3987 while [ "${CONN_STATE}" != "${expected}" ]; do
3988 if [ "${expected}" == "DISCONN" ]; then
3989 # for disconn we can check after proc entry is removed
3990 [ "x${CONN_STATE}" == "x" ] && return 0
3991 # with AT enabled, we can have connect request timeout near of
3992 # reconnect timeout and test can't see real disconnect
3993 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3995 [ $i -ge $maxtime ] && \
3996 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
3999 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4003 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4007 wait_import_state() {
4010 local maxtime=${3:-$(max_recovery_time)}
4013 for param in ${params//,/ }; do
4014 _wait_import_state $state $param $maxtime || return
4018 # One client request could be timed out because server was not ready
4019 # when request was sent by client.
4020 # The request timeout calculation details :
4022 # /* We give the server rq_timeout secs to process the req, and
4023 # add the network latency for our local timeout. */
4024 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4025 # ptlrpc_at_get_net_latency(request) ;
4027 # ptlrpc_connect_import ()
4028 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4031 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4032 # ptlrpc_at_get_net_latency(request) ->
4033 # at_get (max (iat_net_latency=0, at_min)) = at_min
4036 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4037 # INITIAL_CONNECT_TIMEOUT + at_min
4039 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4040 # because we can not get this value in runtime,
4041 # the value depends on configure options, and it is not stored in /proc.
4043 # #define CONNECTION_SWITCH_MIN 5U
4045 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4047 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4049 request_timeout () {
4052 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4053 local init_connect_timeout=$TIMEOUT
4054 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4056 local at_min=$(at_get $facet at_min)
4058 echo $(( init_connect_timeout + at_min ))
4061 wait_osc_import_state() {
4065 local ost=$(get_osc_import_name $facet $ost_facet)
4067 local param="osc.${ost}.ost_server_uuid"
4069 # 1. wait the deadline of client 1st request (it could be skipped)
4070 # 2. wait the deadline of client 2nd request
4071 local maxtime=$(( 2 * $(request_timeout $facet)))
4073 if ! do_rpc_nodes $(facet_host $facet) \
4074 _wait_import_state $expected $param $maxtime; then
4075 error "import is not in ${expected} state"
4082 get_clientmdc_proc_path() {
4090 # Add paths to lustre tests for 32 and 64 bit systems.
4091 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4092 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4095 wait_clients_import_state () {
4102 if [ "$FAILURE_MODE" = HARD ]; then
4103 facets=$(facets_on_host $(facet_active_host $facet))
4106 for facet in ${facets//,/ }; do
4107 local label=$(convert_facet2label $facet)
4110 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4111 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4112 *) error "unknown facet!" ;;
4114 local params=$(expand_list $params $proc_path)
4117 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4118 error "import is not in ${expected} state"
4127 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4128 $LCTL get_param obdfilter.*.kbytesavail))
4129 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4130 $LCTL get_param -n obdfilter.*.tot_granted))
4131 for ((i=0; i<${#AVAILA[@]}; i++)); do
4132 local -a AVAIL1=(${AVAILA[$i]//=/ })
4133 GRANT=$((${GRANTA[$i]}/1024))
4134 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4135 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4141 do_facet mgs lctl pool_list $1
4145 local fsname=${1%%.*}
4146 local poolname=${1##$fsname.}
4148 do_facet mgs lctl pool_new $1
4150 # get param should return err unless pool is created
4151 [[ $RC -ne 0 ]] && return $RC
4153 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4154 2>/dev/null || echo foo" "" || RC=1
4155 if [[ $RC -eq 0 ]]; then
4158 error "pool_new failed $1"
4163 add_pool_to_list () {
4164 local fsname=${1%%.*}
4165 local poolname=${1##$fsname.}
4167 local listvar=${fsname}_CREATED_POOLS
4168 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4171 remove_pool_from_list () {
4172 local fsname=${1%%.*}
4173 local poolname=${1##$fsname.}
4175 local listvar=${fsname}_CREATED_POOLS
4176 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4179 destroy_pool_int() {
4181 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4182 awk '$1 !~ /^Pool:/ {print $1}')
4183 for ost in $OSTS; do
4184 do_facet mgs lctl pool_remove $1 $ost
4186 do_facet mgs lctl pool_destroy $1
4189 # <fsname>.<poolname> or <poolname>
4191 local fsname=${1%%.*}
4192 local poolname=${1##$fsname.}
4194 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4198 pool_list $fsname.$poolname || return $?
4200 destroy_pool_int $fsname.$poolname
4202 [[ $RC -ne 0 ]] && return $RC
4204 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4205 2>/dev/null || echo foo" "foo" || RC=1
4207 if [[ $RC -eq 0 ]]; then
4208 remove_pool_from_list $fsname.$poolname
4210 error "destroy pool failed $1"
4216 local fsname=${1:-$FSNAME}
4218 local listvar=${fsname}_CREATED_POOLS
4222 [ x${!listvar} = x ] && return 0
4224 echo destroy the created pools: ${!listvar}
4225 for poolname in ${!listvar//,/ }; do
4226 destroy_pool $fsname.$poolname
4231 local fsname=${1:-$FSNAME}
4233 destroy_pools $fsname
4240 local ts=$(date +%s)
4242 [ -f $LOGDIR/shared ] && docp=false
4244 # dump lustre logs, dmesg
4246 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
4248 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4250 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4251 echo "Dumping logs only on local client."
4252 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4253 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4258 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4259 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4260 if [ ! -f $LOGDIR/shared ]; then
4261 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4264 if [ $tar_logs == 1 ]; then
4265 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
4266 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
4273 local list=${1:-$(comma_list $(nodes_list))}
4275 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
4287 for i in $(seq 0 $num_mntpts); do
4288 cmd="ls -laf ${mntpt_root}$i/$dir"
4294 for pid in $pids; do
4301 # target_start_and_reset_recovery_timer()
4302 # service_time = at_est2timeout(service_time);
4303 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4304 # INITIAL_CONNECT_TIMEOUT);
4305 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4306 #define CONNECTION_SWITCH_INC 1
4307 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4308 #define CONNECTION_SWITCH_MIN 5U
4310 max_recovery_time () {
4311 local init_connect_timeout=$(( TIMEOUT / 20 ))
4312 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4314 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4319 get_clients_mount_count () {
4320 local clients=${CLIENTS:-`hostname`}
4322 # we need to take into account the clients mounts and
4323 # exclude mds/ost mounts if any;
4324 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4328 PROC_CLI="srpc_info"
4336 if [ $M -lt $N ]; then
4340 while [ $N -lt $M ]; do
4350 calc_connection_cnt() {
4353 # MDT->MDT = 2 * C(M, 2)
4357 comb_m2=$(combination $MDSCOUNT 2)
4359 local num_clients=$(get_clients_mount_count)
4361 local cnt_mdt2mdt=$((comb_m2 * 2))
4362 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4363 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4364 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4365 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4366 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4367 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4381 local cmd="$tgt.srpc.flavor"
4383 if [ $net == "any" ]; then
4388 if [ $dir != "any" ]; then
4393 log "Setting sptlrpc rule: $cmd"
4394 do_facet mgs "$LCTL conf_param $cmd"
4403 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4404 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4406 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4408 if [ "x$bulkspec" != "x" ]; then
4409 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4411 if [ "x$algs" != "x" ]; then
4412 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4414 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4415 if [ $bulk == "bulkn" ]; then
4416 bulk_count=`echo "$output" | grep "bulk flavor" \
4417 | grep "null/null" | wc -l`
4418 elif [ $bulk == "bulki" ]; then
4419 bulk_count=`echo "$output" | grep "bulk flavor" \
4420 | grep "/null" | grep -v "null/" | wc -l`
4422 bulk_count=`echo "$output" | grep "bulk flavor" \
4423 | grep -v "/null" | grep -v "null/" | wc -l`
4427 [ $bulk_count -lt $count ] && count=$bulk_count
4438 local clients=${CLIENTS:-`hostname`}
4440 for c in ${clients//,/ }; do
4441 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4442 tmpcnt=`count_flvr "$output" $flavor`
4443 cnt=$((cnt + tmpcnt))
4453 local clients=${CLIENTS:-`hostname`}
4455 for c in ${clients//,/ }; do
4456 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4457 tmpcnt=`count_flvr "$output" $flavor`
4458 cnt=$((cnt + tmpcnt))
4468 if [ $MDSCOUNT -le 1 ]; then
4473 for num in `seq $MDSCOUNT`; do
4474 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4475 tmpcnt=`count_flvr "$output" $flavor`
4476 cnt=$((cnt + tmpcnt))
4487 for num in `seq $MDSCOUNT`; do
4488 mdtosc=$(get_mdtosc_proc_path mds$num)
4489 mdtosc=${mdtosc/-MDT*/-MDT\*}
4490 output=$(do_facet mds$num lctl get_param -n \
4491 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4492 tmpcnt=`count_flvr "$output" $flavor`
4493 cnt=$((cnt + tmpcnt))
4502 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4503 count_flvr "$output" $flavor
4508 local dir=$1 # from to
4509 local flavor=$2 # flavor expected
4512 if [ $dir == "cli2mdt" ]; then
4513 res=`flvr_cnt_cli2mdt $flavor`
4514 elif [ $dir == "cli2ost" ]; then
4515 res=`flvr_cnt_cli2ost $flavor`
4516 elif [ $dir == "mdt2mdt" ]; then
4517 res=`flvr_cnt_mdt2mdt $flavor`
4518 elif [ $dir == "mdt2ost" ]; then
4519 res=`flvr_cnt_mdt2ost $flavor`
4520 elif [ $dir == "all2ost" ]; then
4521 res1=`flvr_cnt_mdt2ost $flavor`
4522 res2=`flvr_cnt_cli2ost $flavor`
4523 res=$((res1 + res2))
4524 elif [ $dir == "all2mdt" ]; then
4525 res1=`flvr_cnt_mdt2mdt $flavor`
4526 res2=`flvr_cnt_cli2mdt $flavor`
4527 res=$((res1 + res2))
4528 elif [ $dir == "all2all" ]; then
4529 res1=`flvr_cnt_mdt2ost $flavor`
4530 res2=`flvr_cnt_cli2ost $flavor`
4531 res3=`flvr_cnt_mdt2mdt $flavor`
4532 res4=`flvr_cnt_cli2mdt $flavor`
4533 res=$((res1 + res2 + res3 + res4))
4541 local dir=$1 # from to
4542 local flavor=$2 # flavor expected
4543 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4547 for ((i=0;i<20;i++)); do
4548 echo -n "checking $dir..."
4549 res=$(do_check_flavor $dir $flavor)
4550 echo "found $res/$expect $flavor connections"
4551 [ $res -ge $expect ] && return 0
4555 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4559 restore_to_default_flavor()
4561 local proc="mgs.MGS.live.$FSNAME"
4563 echo "restoring to default flavor..."
4565 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4567 # remove all existing rules if any
4568 if [ $nrule -ne 0 ]; then
4569 echo "$nrule existing rules"
4570 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4571 echo "remove rule: $rule"
4572 spec=`echo $rule | awk -F = '{print $1}'`
4573 do_facet mgs "$LCTL conf_param -d $spec"
4577 # verify no rules left
4578 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4579 [ $nrule -ne 0 ] && error "still $nrule rules left"
4581 # wait for default flavor to be applied
4582 # currently default flavor for all connections are 'null'
4583 wait_flavor all2all null
4584 echo "now at default flavor settings"
4589 local flavor=${1:-null}
4591 echo "setting all flavor to $flavor"
4593 # FIXME need parameter to this fn
4594 # and remove global vars
4595 local cnt_all2all=$(calc_connection_cnt all2all)
4597 local res=$(do_check_flavor all2all $flavor)
4598 if [ $res -eq $cnt_all2all ]; then
4599 echo "already have total $res $flavor connections"
4603 echo "found $res $flavor out of total $cnt_all2all connections"
4604 restore_to_default_flavor
4606 [[ $flavor = null ]] && return 0
4608 set_rule $FSNAME any any $flavor
4609 wait_flavor all2all $flavor
4615 # Checking for shared logdir
4616 if [ ! -d $dir ]; then
4617 # Not found. Create local logdir
4620 touch $dir/node.$(hostname -s).yml
4625 check_write_access() {
4627 for node in $(nodes_list); do
4628 if [ ! -f "$dir/node.$(short_hostname ${node}).yml" ]; then
4629 # Logdir not accessible/writable from this node.
4633 rm -f $dir/node.*.yml
4638 if [[ -n $YAML_LOG ]]; then
4641 local SAVE_UMASK=`umask`
4644 export YAML_LOG=${LOGDIR}/results.yml
4648 if check_shared_dir $LOGDIR; then
4649 touch $LOGDIR/shared
4650 echo "Logging to shared log directory: $LOGDIR"
4652 echo "Logging to local directory: $LOGDIR"
4655 yml_nodes_file $LOGDIR >> $YAML_LOG
4656 yml_results_file >> $YAML_LOG
4662 yml_log_test $1 >> $YAML_LOG
4666 yml_log_test_status $@ >> $YAML_LOG
4669 log_sub_test_begin() {
4670 yml_log_sub_test_begin "$@" >> $YAML_LOG
4673 log_sub_test_end() {
4674 yml_log_sub_test_end "$@" >> $YAML_LOG
4680 local llverdev_opts=$2
4681 local devname=$(basename $1)
4682 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4683 # loop devices aren't in /proc/partitions
4684 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4686 size=$(($size / 1024 / 1024)) # Gb
4688 local partial_arg=""
4689 # Run in partial (fast) mode if the size
4690 # of a partition > 1 GB
4691 [ $size -gt 1 ] && partial_arg="-p"
4693 llverdev --force $partial_arg $llverdev_opts $dev
4699 local llverfs_opts=$2
4700 local partial_arg=""
4701 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4703 # Run in partial (fast) mode if the size
4704 # of a partition > 1 GB
4705 [ $size -gt 1 ] && partial_arg="-p"
4707 llverfs $partial_arg $llverfs_opts $dir
4710 remove_mdt_files() {
4715 local mntpt=$(facet_mntpt $facet)
4717 echo "removing files from $mdtdev on $facet: $files"
4718 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4721 rm $mntpt/ROOT/$f || { rc=$?; break; }
4723 umount -f $mntpt || return $?
4727 duplicate_mdt_files() {
4732 local mntpt=$(facet_mntpt $facet)
4734 echo "duplicating files on $mdtdev on $facet: $files"
4735 mkdir -p $mntpt || return $?
4736 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4746 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4747 pushd $mntpt/ROOT > /dev/null || return $?
4750 touch $f.bad || return $?
4751 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4753 [ $rc -eq 0 ] || return $rc
4754 setfattr --restore $tmp || return $?
4760 local devs=${1//,/ }
4763 local rslt=$TMP/sgpdd_survey
4765 # sgpdd-survey cleanups ${rslt}.* files
4767 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4773 # returns the canonical name for an ldiskfs device
4778 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4779 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4780 echo dm-\\\${foo##*:};
4782 echo \\\$(basename \\\$dv);
4786 is_sanity_benchmark() {
4787 local benchmarks="dbench bonnie iozone fsx"
4789 for b in $benchmarks; do
4790 if [ "$b" == "$suite" ]; then
4798 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4801 # Get the block size of the filesystem.
4807 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4808 awk '/^Block size:/ {print $3}')
4812 # Check whether the "large_xattr" feature is enabled or not.
4813 large_xattr_enabled() {
4814 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4816 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4817 return ${PIPESTATUS[0]}
4820 # Get the maximum xattr size supported by the filesystem.
4824 if large_xattr_enabled; then
4825 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4828 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4829 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4831 # maximum xattr size = size of block - size of header -
4832 # size of 1 entry - 4 null bytes
4833 size=$((block_size - 32 - 32 - 4))
4839 # Dump the value of the named xattr from a file.
4844 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4847 # Generate a string with size of $size bytes.
4849 local size=${1:-1024} # in bytes
4851 echo "$(head -c $size < /dev/zero | tr '\0' y)"