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 # This is used by a small number of tests to share state between the client
134 # running the tests, or in some cases between the servers (e.g. lfsck.sh).
135 # It needs to be a non-lustre filesystem that is available on all the nodes.
136 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-"/tmp"}
137 export MDSDB=${MDSDB:-$SHARED_DIRECTORY/mdsdb}
138 export OSTDB=${OSTDB:-$SHARED_DIRECTORY/ostdb}
140 #[ -d /r ] && export ROOT=${ROOT:-/r}
141 export TMP=${TMP:-$ROOT/tmp}
142 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
143 if [[ -z $LOGDIRSET ]]; then
144 export LOGDIR=${LOGDIR:-${TMP}/test_logs/}/$(date +%s)
145 export LOGDIRSET=true
147 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
148 if ! echo $PATH | grep -q $LUSTRE/utils; then
149 export PATH=$LUSTRE/utils:$PATH
151 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
152 export PATH=$LUSTRE/utils/gss:$PATH
154 if ! echo $PATH | grep -q $LUSTRE/tests; then
155 export PATH=$LUSTRE/tests:$PATH
157 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
158 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
160 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
161 [ ! -f "$LST" ] && export LST=$(which lst)
162 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
163 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
164 # Ubuntu, at least, has a truncate command in /usr/bin
165 # so fully path our truncate command.
166 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
167 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
168 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
169 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
170 export PATH=$LUSTRE/tests/racer:$PATH:
172 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
173 export PATH=$LUSTRE/tests/mpi:$PATH
175 export RSYNC_RSH=${RSYNC_RSH:-rsh}
176 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
177 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
178 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
179 [ ! -f "$LFS" ] && export LFS=$(which lfs)
180 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
181 if [ ! -f "$L_GETIDENTITY" ]; then
182 if `which l_getidentity > /dev/null 2>&1`; then
183 export L_GETIDENTITY=$(which l_getidentity)
185 export L_GETIDENTITY=NONE
188 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
189 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
190 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
191 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
192 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
193 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
194 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
195 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
196 [ ! -f "$LUSTRE_RMMOD" ] && export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
197 export FSTYPE=${FSTYPE:-"ldiskfs"}
198 export NAME=${NAME:-local}
199 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
200 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
201 export LGSSD=$(which lgssd)
202 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
203 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
204 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
206 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
209 if [ "$ACCEPTOR_PORT" ]; then
210 export PORT_OPT="--port $ACCEPTOR_PORT"
215 echo "Using GSS/krb5 ptlrpc security flavor"
216 which lgss_keyring > /dev/null 2>&1 || \
217 error_exit "built with gss disabled! SEC=$SEC"
228 IDENTITY_UPCALL=false
231 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
233 # Paths on remote nodes, if different
234 export RLUSTRE=${RLUSTRE:-$LUSTRE}
235 export RPWD=${RPWD:-$PWD}
236 export I_MOUNTED=${I_MOUNTED:-"no"}
237 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
238 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
239 ! -f `dirname $0`/../mds/mds.ko ]; then
240 export CLIENTMODSONLY=yes
243 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
247 while getopts "rvwf:" opt $*; do
250 r) REFORMAT=--reformat;;
252 w) WRITECONF=writeconf;;
257 shift $((OPTIND - 1))
260 # print the durations of each test if "true"
261 DDETAILS=${DDETAILS:-false}
262 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
267 2.4.*) EXT=".o"; USE_QUOTA=no; [ ! "$CLIENTONLY" ] && FSTYPE=ext3;;
268 *) EXT=".ko"; USE_QUOTA=yes;;
273 /sbin/lsmod | grep -q "^\<$1\>"
276 # Load a module on the system where this is running.
278 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
280 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
281 # will be used as the arguments. Otherwise arguments will be obtained from
282 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
289 BASE=`basename $module $EXT`
291 module_loaded ${BASE} && return
293 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
295 if [ $# -eq 0 ]; then
296 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
297 # Bash until 4.x, so we resort to eval.
298 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
299 eval set -- \$$optvar
300 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
301 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
302 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
303 # Get rid of "options $module"
304 (($# > 0)) && shift 2
306 # Ensure we have accept=all for lnet
307 if [ $(basename $module) = lnet ]; then
308 # OK, this is a bit wordy...
309 local arg accept_all_present=false
311 [ "$arg" = accept=all ] && accept_all_present=true
313 $accept_all_present || set -- "$@" accept=all
318 [ $# -gt 0 ] && echo "${module} options: '$*'"
320 # Note that insmod will ignore anything in modprobe.conf, which is why we're
321 # passing options on the command-line.
322 if [ "$BASE" == "lnet_selftest" ] && \
323 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
324 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
325 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
326 insmod ${LUSTRE}/${module}${EXT} "$@"
328 # must be testing a "make install" or "rpm" installation
329 # note failed to load ptlrpc_gss is considered not fatal
330 if [ "$BASE" == "ptlrpc_gss" ]; then
331 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
338 llite_lloop_enabled() {
339 local n1=$(uname -r | cut -d. -f1)
340 local n2=$(uname -r | cut -d. -f2)
341 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
343 # load the llite_lloop module for < 2.6.32 kernels
344 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
345 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
352 load_modules_local() {
353 if [ -n "$MODPROBE" ]; then
355 echo "Using modprobe to load modules"
359 echo Loading modules from $LUSTRE
360 load_module ../libcfs/libcfs/libcfs
361 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
362 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
363 load_module ../lnet/lnet/lnet
364 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
365 load_module ../lnet/klnds/$LNETLND
366 load_module lvfs/lvfs
367 load_module obdclass/obdclass
368 load_module ptlrpc/ptlrpc
369 load_module ptlrpc/gss/ptlrpc_gss
370 [ "$USE_QUOTA" = "yes" -a "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
378 if ! client_only; then
379 grep -q crc16 /proc/kallsyms || { modprobe crc16 2>/dev/null || true; }
380 grep -q -w jbd /proc/kallsyms || { modprobe jbd 2>/dev/null || true; }
381 grep -q -w jbd2 /proc/kallsyms || { modprobe jbd2 2>/dev/null || true; }
382 [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
387 load_module lvfs/fsfilt_$FSTYPE
389 load_module osd-ldiskfs/osd_ldiskfs
391 load_module obdfilter/obdfilter
395 load_module llite/lustre
396 llite_lloop_enabled && load_module llite/llite_lloop
397 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
399 rm -f $OGDB/ogdb-$HOSTNAME
400 $LCTL modules > $OGDB/ogdb-$HOSTNAME
402 # 'mount' doesn't look in $PATH, just sbin
403 if [ -f $LUSTRE/utils/mount.lustre ] && \
404 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
405 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
406 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
413 # load modules on remote nodes optionally
414 # lustre-tests have to be installed on these nodes
415 if $LOAD_MODULES_REMOTE ; then
416 local list=$(comma_list $(remote_nodes_list))
417 echo loading modules on $list
418 do_rpc_nodes $list load_modules
423 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
424 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
425 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
426 echo "$LEAK_LUSTRE" 1>&2
427 echo "$LEAK_PORTALS" 1>&2
428 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
429 echo "Memory leaks detected"
430 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
436 wait_exit_ST client # bug 12845
438 $LUSTRE_RMMOD $FSTYPE || return 2
440 if $LOAD_MODULES_REMOTE ; then
441 local list=$(comma_list $(remote_nodes_list))
442 if [ ! -z $list ]; then
443 echo unloading modules on $list
444 do_rpc_nodes $list $LUSTRE_RMMOD $FSTYPE
445 do_rpc_nodes $list check_mem_leak
449 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
450 umount /sbin/mount.lustre || true
451 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
452 rm -f /sbin/mount.lustre || true
455 check_mem_leak || return 254
457 echo "modules unloaded."
461 check_gss_daemon_nodes() {
465 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
466 if [ \\\"\\\$num\\\" -ne 1 ]; then
467 echo \\\$num instance of $dname;
472 check_gss_daemon_facet() {
476 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
477 if [ $num -ne 1 ]; then
478 echo "$num instance of $dname on $facet"
487 echo Stopping $@ on $list
488 do_nodes $list "killall -2 $@ 2>/dev/null || true"
491 # start gss daemons on all nodes, or
492 # "daemon" on "list" if set
493 start_gss_daemons() {
497 if [ "$list" ] && [ "$daemon" ] ; then
498 echo "Starting gss daemon on nodes: $list"
499 do_nodes $list "$daemon" || return 8
503 local list=$(comma_list $(mdts_nodes))
505 echo "Starting gss daemon on mds: $list"
506 do_nodes $list "$LSVCGSSD -v" || return 1
508 do_nodes $list "$LGSSD -v" || return 2
511 list=$(comma_list $(osts_nodes))
512 echo "Starting gss daemon on ost: $list"
513 do_nodes $list "$LSVCGSSD -v" || return 3
514 # starting on clients
516 local clients=${CLIENTS:-`hostname`}
518 echo "Starting $LGSSD on clients $clients "
519 do_nodes $clients "$LGSSD -v" || return 4
522 # wait daemons entering "stable" status
526 # check daemons are running
528 list=$(comma_list $(mdts_nodes) $(osts_nodes))
529 check_gss_daemon_nodes $list lsvcgssd || return 5
531 list=$(comma_list $(mdts_nodes))
532 check_gss_daemon_nodes $list lgssd || return 6
535 check_gss_daemon_nodes $clients lgssd || return 7
540 local list=$(comma_list $(mdts_nodes))
542 send_sigint $list lsvcgssd lgssd
544 list=$(comma_list $(osts_nodes))
545 send_sigint $list lsvcgssd
547 list=${CLIENTS:-`hostname`}
548 send_sigint $list lgssd
553 if ! module_loaded ptlrpc_gss; then
554 load_module ptlrpc/gss/ptlrpc_gss
555 module_loaded ptlrpc_gss ||
556 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
558 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
560 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
561 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
569 # maybe cleanup credential cache?
575 local device=`mdsdevname $num`
576 local label=`do_facet mds$num "e2label ${device}" | grep -v "CMD: "`
582 local device=`ostdevname $num`
583 local label=`do_facet ost$num "e2label ${device}" | grep -v "CMD: "`
588 local dz=${1:-$DEBUG_SIZE}
589 local cpus=$(getconf _NPROCESSORS_CONF)
591 # bug 19944, adjust size to be -gt num_possible_cpus()
592 # promise 2MB for every cpu at least
593 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
596 lctl set_param debug_mb=$dz
599 set_default_debug () {
600 local debug=${1:-"$PTLDEBUG"}
601 local subsystem_debug=${2:-"$SUBSYSTEM"}
602 local debug_size=${3:-$DEBUG_SIZE}
604 lctl set_param debug="$debug"
605 lctl set_param subsystem_debug="${subsystem_debug# }"
607 set_debug_size $debug_size
611 set_default_debug_nodes () {
614 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
615 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
619 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
620 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
623 set_default_debug_facet () {
625 local node=$(facet_active_host $facet)
626 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
628 set_default_debug_nodes $node
633 local facets=${1:-$(get_facets)}
636 for facet in ${facets//,/ }; do
637 mount_facet $facet || error "Restart of $facet failed!"
644 local dev=$(facet_active $facet)_dev
645 local opt=${facet}_opt
646 local mntpt=$(facet_mntpt $facet)
648 echo "Starting ${facet}: ${!opt} $@ ${!dev} $mntpt"
649 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre ${!opt} $@ ${!dev} $mntpt"
651 if [ $RC -ne 0 ]; then
652 echo "mount -t lustre $@ ${!dev} $mntpt"
653 echo "Start of ${!dev} on ${facet} failed ${RC}"
655 set_default_debug_facet $facet
657 label=$(do_facet ${facet} "$E2LABEL ${!dev}")
658 [ -z "$label" ] && echo no label for ${!dev} && exit 1
659 eval export ${facet}_svc=${label}
660 echo Started ${label}
665 # start facet device options
671 eval export ${facet}_dev=${device}
672 eval export ${facet}_opt=\"$@\"
674 local varname=${facet}failover_dev
675 if [ -n "${!varname}" ] ; then
676 eval export ${facet}failover_dev=${!varname}
678 eval export ${facet}failover_dev=$device
681 local mntpt=$(facet_mntpt $facet)
682 do_facet ${facet} mkdir -p $mntpt
683 eval export ${facet}_MOUNT=$mntpt
693 local HOST=`facet_active_host $facet`
694 [ -z $HOST ] && echo stop: no host for $facet && return 0
696 local mntpt=$(facet_mntpt $facet)
697 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
698 if [ ${running} -ne 0 ]; then
699 echo "Stopping $mntpt (opts:$@) on $HOST"
700 do_facet ${facet} umount -d $@ $mntpt
703 # umount should block, but we should wait for unrelated obd's
704 # like the MGS or MGC to also stop.
705 wait_exit_ST ${facet}
708 # save quota version (both administrative and operational quotas)
709 # add an additional parameter if mountpoint is ever different from $MOUNT
710 quota_save_version() {
711 local fsname=${2:-$FSNAME}
713 local ver=$(tr -c -d "123" <<< $spec)
714 local type=$(tr -c -d "ug" <<< $spec)
716 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
718 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
720 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
722 local osts=$(get_facets OST)
723 for ost in ${osts//,/ }; do
725 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
729 # client could mount several lustre
731 local fsname=${1:-$FSNAME}
733 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
734 do_nodes $(comma_list $(osts_nodes)) \
735 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
739 restore_quota_type () {
740 local mntpt=${1:-$MOUNT}
741 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
742 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
745 quota_save_version $old_QUOTA_TYPE
751 # We need save the original quota_type params, and restore them after testing
753 # Suppose that quota type the same on mds and ost
754 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
755 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
756 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
757 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
758 export old_QUOTA_TYPE=$quota_type
759 quota_save_version $QUOTA_TYPE
761 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
762 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
765 local quota_usrs=$QUOTA_USERS
767 # get_filesystem_size
768 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
769 local blk_soft=$((disksz + 1024))
770 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
772 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
774 local i_hard=$((i_soft + i_soft / 20))
776 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
777 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
780 for usr in $quota_usrs; do
781 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
783 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
785 eval $cmd || error "$cmd FAILED!"
787 # display the quota status
788 echo "Quota settings for $usr : "
789 $LFS quota -v -u $usr $mntpt || true
796 local OPTIONS=${3:-$MOUNTOPT}
798 local device=$MGSNID:/$FSNAME
799 if [ -z "$mnt" -o -z "$FSNAME" ]; then
800 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
804 echo "Starting client: $client: $OPTIONS $device $mnt"
805 do_node $client mkdir -p $mnt
806 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
808 set_default_debug_nodes $client
821 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
822 if [ $running -ne 0 ]; then
823 echo "Stopping client $client $mnt (opts:$force)"
824 do_node $client lsof -t $mnt || need_kill=no
825 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
826 pids=$(do_node $client lsof -t $mnt | sort -u);
827 if [ -n $pids ]; then
828 do_node $client kill -9 $pids || true
832 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
833 if [ $busy -ne 0 ] ; then
834 echo "$mnt is still busy, wait one second" && sleep 1
835 do_node $client umount $force $mnt
840 # nodes is comma list
841 sanity_mount_check_nodes () {
847 # FIXME: assume that all cluster nodes run the same os
848 [ "$(uname)" = Linux ] || return 0
851 for mnt in $mnts ; do
852 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
853 mpts=\\\$(mount | grep -w -c $mnt);
854 if [ \\\$running -ne \\\$mpts ]; then
855 echo \\\$(hostname) env are INSANE!;
863 sanity_mount_check_servers () {
865 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
866 echo Checking servers environments
868 # FIXME: modify get_facets to display all facets wo params
869 local facets="$(get_facets OST),$(get_facets MDS),mgs"
873 for facet in ${facets//,/ }; do
874 node=$(facet_host ${facet})
875 mntpt=$(facet_mntpt $facet)
876 sanity_mount_check_nodes $node $mntpt ||
877 { error "server $node environments are insane!"; return 1; }
881 sanity_mount_check_clients () {
882 local clients=${1:-$CLIENTS}
883 local mntpt=${2:-$MOUNT}
884 local mntpt2=${3:-$MOUNT2}
886 [ -z $clients ] && clients=$(hostname)
887 echo Checking clients $clients environments
889 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
890 error "clients environments are insane!"
893 sanity_mount_check () {
894 sanity_mount_check_servers || return 1
895 sanity_mount_check_clients || return 2
898 # mount clients if not mouted
899 zconf_mount_clients() {
902 local OPTIONS=${3:-$MOUNTOPT}
904 local device=$MGSNID:/$FSNAME
905 if [ -z "$mnt" -o -z "$FSNAME" ]; then
906 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
910 echo "Starting client $clients: $OPTIONS $device $mnt"
913 running=\\\$(mount | grep -c $mnt' ');
915 if [ \\\$running -eq 0 ] ; then
917 mount -t lustre $OPTIONS $device $mnt;
920 exit \\\$rc" || return ${PIPESTATUS[0]}
922 echo "Started clients $clients: "
923 do_nodes $clients "mount | grep -w $mnt"
925 set_default_debug_nodes $clients
930 zconf_umount_clients() {
937 echo "Stopping clients: $clients $mnt (opts:$force)"
938 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
939 if [ \\\$running -ne 0 ] ; then
940 echo Stopping client \\\$(hostname) $mnt opts:$force;
941 lsof -t $mnt || need_kill=no;
942 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
943 pids=\\\$(lsof -t $mnt | sort -u);
944 if [ -n \\\"\\\$pids\\\" ]; then
948 busy=\\\$(umount $force $mnt 2>&1 | grep -c "busy");
949 if [ \\\$busy -ne 0 ] ; then
950 echo "$mnt is still busy, wait one second" && sleep 1;
958 echo + $POWER_DOWN $node
962 shutdown_node_hard () {
964 local attempts=$SHUTDOWN_ATTEMPTS
966 for i in $(seq $attempts) ; do
969 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
970 echo "waiting for $host to fail attempts=$attempts"
971 [ $i -lt $attempts ] || \
972 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
978 local mnt=${2:-$MOUNT}
981 if [ "$FAILURE_MODE" = HARD ]; then
982 shutdown_node_hard $client
984 zconf_umount_clients $client $mnt -f
990 local facets="$(get_facets OST),$(get_facets MDS)"
993 combined_mgs_mds || facets="$facets,mgs"
995 for facet in ${facets//,/ }; do
996 if [ $(facet_active_host $facet) == $host ]; then
997 affected="$affected $facet"
1001 echo $(comma_list $affected)
1006 local host=${2:-$(facet_host $facet)}
1008 local label=$(convert_facet2label $facet)
1009 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1012 facets_up_on_host () {
1014 local facets=$(facets_on_host $host)
1017 for facet in ${facets//,/ }; do
1018 if $(facet_up $facet $host); then
1019 affected_up="$affected_up $facet"
1023 echo $(comma_list $affected_up)
1029 if [ "$FAILURE_MODE" = HARD ]; then
1030 shutdown_node_hard $(facet_active_host $facet)
1038 echo + $POWER_UP $node
1051 if [ "$FAILURE_MODE" = HARD ]; then
1052 reboot_node $(facet_active_host $facet)
1060 if [ "$FAILURE_MODE" = HARD ]; then
1070 for facet in ${facets//,/ }; do
1071 hosts=$(expand_list $hosts $(facet_host $facet) )
1077 _check_progs_installed () {
1081 for prog in $progs; do
1082 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1083 echo $prog missing on $(hostname)
1090 check_progs_installed () {
1094 do_rpc_nodes $nodes _check_progs_installed $@
1097 # recovery-scale functions
1099 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1102 start_client_load() {
1105 local var=$(node_var_name $client)_load
1106 eval export ${var}=$load
1108 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1109 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1110 END_RUN_FILE=$END_RUN_FILE \
1111 LOAD_PID_FILE=$LOAD_PID_FILE \
1112 TESTSUITELOG=$TESTSUITELOG \
1114 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $!"
1115 log "Started client load: ${load} on $client"
1120 start_client_loads () {
1121 local -a clients=(${1//,/ })
1122 local numloads=${#CLIENT_LOADS[@]}
1125 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1126 testnum=$((nodenum % numloads))
1127 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1129 # bug 22169: wait the background threads to start
1133 # only for remote client
1134 check_client_load () {
1136 local var=$(node_var_name $client)_load
1137 local TESTLOAD=run_${!var}.sh
1139 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1141 # bug 18914: try to connect several times not only when
1142 # check ps, but while check_catastrophe also
1145 while [ $RC = 254 -a $tries -gt 0 ]; do
1149 if ! check_catastrophe $client; then
1151 if [ $RC -eq 254 ]; then
1152 # FIXME: not sure how long we shuold sleep here
1156 echo "check catastrophe failed: RC=$RC "
1160 # We can continue try to connect if RC=254
1161 # Just print the warning about this
1162 if [ $RC = 254 ]; then
1163 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1166 # see if the load is still on the client
1169 while [ $RC = 254 -a $tries -gt 0 ]; do
1173 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1178 if [ $RC = 254 ]; then
1179 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1180 # see if we can diagnose a bit why this is
1185 check_client_loads () {
1186 local clients=${1//,/ }
1190 for client in $clients; do
1191 check_client_load $client
1193 if [ "$rc" != 0 ]; then
1194 log "Client load failed on node $client, rc=$rc"
1200 restart_client_loads () {
1201 local clients=${1//,/ }
1202 local expectedfail=${2:-""}
1206 for client in $clients; do
1207 check_client_load $client
1209 if [ "$rc" != 0 -a "$expectedfail" ]; then
1210 local var=$(node_var_name $client)_load
1211 start_client_load $client ${!var}
1212 echo "Restarted client load ${!var}: on $client. Checking ..."
1213 check_client_load $client
1215 if [ "$rc" != 0 ]; then
1216 log "Client load failed to restart on node $client, rc=$rc"
1217 # failure one client load means test fail
1218 # we do not need to check other
1226 # End recovery-scale functions
1228 # verify that lustre actually cleaned up properly
1230 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1231 error "LBUG/LASSERT detected"
1232 BUSY=`dmesg | grep -i destruct || true`
1233 if [ "$BUSY" ]; then
1235 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1239 check_mem_leak || exit 204
1241 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1242 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1244 if module_loaded lnet || module_loaded libcfs; then
1245 echo "$0: modules still loaded..." 1>&2
1262 RESULT=$(do_node $node "$TEST")
1263 if [ "$RESULT" == "$FINAL" ]; then
1264 echo "Updated after $WAIT sec: wanted '$FINAL' got '$RESULT'"
1267 [ $WAIT -ge $MAX ] && break
1268 echo "Waiting $((MAX - WAIT)) secs for update"
1269 WAIT=$((WAIT + sleep))
1272 echo "Update not seen after $MAX sec: wanted '$FINAL' got '$RESULT'"
1276 wait_update_facet () {
1278 wait_update $(facet_active_host $facet) "$@"
1281 wait_delete_completed () {
1282 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1283 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1287 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1289 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1290 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1291 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1292 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1296 echo "Delete is not completed in $MAX_WAIT sec"
1303 # we can use "for" here because we are waiting the slowest
1304 for host in ${hostlist//,/ }; do
1305 check_network "$host" 900
1307 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1314 for facet in ${facetlist//,/ }; do
1315 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1317 wait_for_host $hostlist
1320 _wait_recovery_complete () {
1323 # Use default policy if $2 is not passed by caller.
1324 local MAX=${2:-$(max_recovery_time)}
1329 while [ $WAIT -lt $MAX ]; do
1330 STATUS=$(lctl get_param -n $param | grep status)
1332 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1335 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1337 echo "$param recovery not done in $MAX sec. $STATUS"
1341 wait_recovery_complete () {
1344 # with an assumption that at_max is the same on all nodes
1345 local MAX=${2:-$(max_recovery_time)}
1348 if [ "$FAILURE_MODE" = HARD ]; then
1349 facets=$(facets_on_host $(facet_active_host $facet))
1351 echo affected facets: $facets
1353 # we can use "for" here because we are waiting the slowest
1354 for facet in ${facets//,/ }; do
1355 local var_svc=${facet}_svc
1356 local param="*.${!var_svc}.recovery_status"
1358 local host=$(facet_active_host $facet)
1359 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1363 wait_mds_ost_sync () {
1364 # just because recovery is done doesn't mean we've finished
1365 # orphan cleanup. Wait for llogs to get synchronized.
1366 echo "Waiting for orphan cleanup..."
1367 # MAX value includes time needed for MDS-OST reconnection
1368 local MAX=$(( TIMEOUT * 2 ))
1370 while [ $WAIT -lt $MAX ]; do
1371 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1372 "$LCTL get_param -n obdfilter.*.mds_sync"))
1375 for ((i=0; i<${#sync[@]}; i++)); do
1376 [ ${sync[$i]} -eq 0 ] && continue
1377 # there is a not finished MDS-OST synchronization
1381 sleep 2 # increase waiting time and cover statfs cache
1382 [ ${con} -eq 1 ] && return 0
1383 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1386 echo "$facet recovery not done in $MAX sec. $STATUS"
1390 wait_destroy_complete () {
1391 echo "Waiting for destroy to be done..."
1392 # MAX value shouldn't be big as this mean server responsiveness
1393 # never increase this just to make test pass but investigate
1394 # why it takes so long time
1397 while [ $WAIT -lt $MAX ]; do
1398 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1400 for ((i=0; i<${#RPCs[@]}; i++)); do
1401 [ ${RPCs[$i]} -eq 0 ] && continue
1402 # there are still some destroy RPCs in flight
1407 [ ${con} -eq 1 ] && return 0 # done waiting
1408 echo "Waiting $WAIT secs for destroys to be done."
1411 echo "Destroys weren't done in $MAX sec."
1421 # conf-sanity 31 takes a long time cleanup
1422 while [ $WAIT -lt 300 ]; do
1423 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1424 [ -z "${running}" ] && return 0
1425 echo "waited $WAIT for${running}"
1426 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1428 WAIT=$((WAIT + INTERVAL))
1430 echo "service didn't stop after $WAIT seconds. Still running:"
1435 wait_remote_prog () {
1441 [ "$PDSH" = "no_dsh" ] && return 0
1443 while [ $WAIT -lt $2 ]; do
1444 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1445 [ -z "${running}" ] && return 0 || true
1446 echo "waited $WAIT for: "
1448 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1450 WAIT=$((WAIT + INTERVAL))
1452 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1453 [ -z "$pids" ] && return 0
1454 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1455 # FIXME: not portable
1456 for pid in $pids; do
1457 cat /proc/${pid}/status || true
1458 cat /proc/${pid}/wchan || true
1460 kill -9 $pid || true
1469 # not every config has many clients
1471 if [ ! -z "$CLIENTS" ]; then
1472 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1474 stat -f $MOUNT > /dev/null
1480 # usually checked on particular client or locally
1482 if [ ! -z "$client" ]; then
1483 $PDSH $client "stat -f $MOUNT" > /dev/null
1485 stat -f $MOUNT > /dev/null
1493 client_reconnect() {
1494 uname -n >> $MOUNT/recon
1495 if [ -z "$CLIENTS" ]; then
1496 df $MOUNT; uname -n >> $MOUNT/recon
1498 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1500 echo Connected clients:
1502 ls -l $MOUNT/recon > /dev/null
1506 affected_facets () {
1509 local host=$(facet_active_host $facet)
1510 local affected=$facet
1512 if [ "$FAILURE_MODE" = HARD ]; then
1513 affected=$(facets_up_on_host $host)
1521 local host=$(facet_active_host $facet)
1523 echo "Failing $facet on node $host"
1525 # Make sure the client data is synced to disk. LU-924
1527 # We don't write client data synchrnously (to avoid flooding sync writes
1528 # when there are many clients connecting), so if the server reboots before
1529 # the client data reachs disk, the client data will be lost and the client
1530 # will be evicted after recovery, which is not what we expected.
1531 do_facet $facet "sync; sync; sync"
1533 local affected=$(affected_facets $facet)
1535 shutdown_facet $facet
1537 echo affected facets: $affected
1539 [ -n "$sleep_time" ] && sleep $sleep_time
1543 change_active $affected
1545 wait_for_facet $affected
1546 # start mgs first if it is affected
1547 if ! combined_mgs_mds && list_member $affected mgs; then
1548 mount_facet mgs || error "Restart of mgs failed"
1550 # FIXME; has to be changed to mount all facets concurrently
1551 affected=$(exclude_items_from_list $affected mgs)
1552 mount_facets $affected
1561 do_facet $facet "sync; sync; sync"
1564 # make sure there will be no seq change
1565 local clients=${CLIENTS:-$HOSTNAME}
1566 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1568 local svc=${facet}_svc
1569 do_facet $facet $LCTL --device %${!svc} notransno
1570 do_facet $facet $LCTL --device %${!svc} readonly
1571 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1572 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1575 replay_barrier_nodf() {
1576 local facet=$1 echo running=${running}
1577 do_facet $facet "sync; sync; sync"
1578 local svc=${facet}_svc
1579 echo Replay barrier on ${!svc}
1580 do_facet $facet $LCTL --device %${!svc} notransno
1581 do_facet $facet $LCTL --device %${!svc} readonly
1582 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1583 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1586 replay_barrier_nosync() {
1587 local facet=$1 echo running=${running}
1588 local svc=${facet}_svc
1589 echo Replay barrier on ${!svc}
1590 do_facet $facet $LCTL --device %${!svc} notransno
1591 do_facet $facet $LCTL --device %${!svc} readonly
1592 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1593 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1596 mds_evict_client() {
1597 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1598 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1601 ost_evict_client() {
1602 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1603 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1607 facet_failover $* || error "failover: $?"
1608 clients_up || error "post-failover df: $?"
1613 facet_failover $facet
1619 change_active $facet
1620 wait_for_facet $facet
1621 mount_facet $facet -o abort_recovery
1622 clients_up || echo "first df failed: $?"
1623 clients_up || error "post-failover df: $?"
1627 echo There is no lmc. This is mountconf, baby.
1631 host_nids_address() {
1635 if [ -n "$kind" ]; then
1636 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1638 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1644 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1650 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1651 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1652 if [ -z "$ID" ]; then
1653 echo "Could not get a ptl id for $1..."
1662 h2name_or_ip "$1" "tcp"
1667 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1668 if type __h2elan >/dev/null 2>&1; then
1671 ID=`echo $1 | sed 's/[^0-9]*//g'`
1679 h2name_or_ip "$1" "o2ib"
1683 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
1684 # expressions format. As a bonus we can then just pass in those variables
1685 # to pdsh. What this function does is take a HOSTLIST type string and
1686 # expand it into a space deliminated list for us.
1694 [ -z "$hostlist" ] && return
1696 # Translate the case of [..],..,[..] to [..] .. [..]
1697 list="${hostlist/],/] }"
1699 [[ "$front" == *,* ]] && {
1702 list=${list/${old}/${new}}
1705 for item in $list; do
1706 # Test if we have any []'s at all
1707 if [ "$item" != "${item/\[/}" ]; then {
1708 # Expand the [*] into list
1712 if [ "$name" != "$item" ]; then
1713 group=${item#$name[*}
1716 for range in ${group//,/ }; do
1720 # Number of leading zeros
1723 end=$(echo $end | sed 's/0*//')
1724 [[ -z "$end" ]] && end=0
1725 [[ $padlen2 -gt $padlen ]] && {
1726 [[ $padlen2 -eq ${#end} ]] && padlen2=0
1729 begin=$(echo $begin | sed 's/0*//')
1730 [ -z $begin ] && begin=0
1732 for num in $(seq -f "%0${padlen}g" $begin $end); do
1733 value="${name#*,}${num}${back}"
1734 [ "$value" != "${value/\[/}" ] && {
1735 value=$(hostlist_expand "$value")
1737 myList="$myList $value"
1742 myList="$myList $item"
1745 myList=${myList//,/ }
1746 myList=${myList:1} # Remove first character which is a space
1748 # Filter any duplicates without sorting
1750 myList="${list%% *}"
1752 while [[ "$list" != ${myList##* } ]]; do
1753 list=${list//${list%% *} /}
1754 myList="$myList ${list%% *}"
1756 myList="${myList%* }";
1758 # We can select an object at a offset in the list
1761 for item in $myList; do
1763 [ $cnt -eq $offset ] && {
1767 [ $(get_node_count $myList) -ne 1 ] && myList=""
1775 [ "$facet" == client ] && echo -n $HOSTNAME && return
1776 varname=${facet}_HOST
1777 if [ -z "${!varname}" ]; then
1778 if [ "${facet:0:3}" == "ost" ]; then
1779 eval ${facet}_HOST=${ost_HOST}
1787 local activevar=${facet}active
1789 if [ -f $TMP/${facet}active ] ; then
1790 source $TMP/${facet}active
1793 active=${!activevar}
1794 if [ -z "$active" ] ; then
1801 facet_active_host() {
1803 local active=`facet_active $facet`
1804 if [ "$facet" == client ]; then
1807 echo `facet_host $active`
1815 facetlist=$(exclude_items_from_list $facetlist mgs)
1817 for facet in ${facetlist//,/ }; do
1818 local failover=${facet}failover
1819 local host=`facet_host $failover`
1820 [ -z "$host" ] && return
1822 local curactive=`facet_active $facet`
1823 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
1824 eval export ${facet}active=$facet
1826 eval export ${facet}active=$failover
1828 # save the active host for this facet
1829 local activevar=${facet}active
1830 echo "$activevar=${!activevar}" > $TMP/$activevar
1831 [[ $facet = mds1 ]] && combined_mgs_mds && \
1832 echo "mgsactive=${!activevar}" > $TMP/mgsactive
1833 local TO=`facet_active_host $facet`
1834 echo "Failover $facet to $TO"
1840 # do not stripe off hostname if verbose, bug 19215
1841 if [ x$1 = x--verbose ]; then
1849 if [ "$HOST" = "$HOSTNAME" ]; then
1851 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
1852 echo "cannot run remote command on $HOST with $myPDSH"
1856 echo "CMD: $HOST $@" >&2
1857 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1860 if [ "$myPDSH" = "rsh" ]; then
1861 # we need this because rsh does not return exit code of an executed command
1862 local command_status="$TMP/cs"
1863 rsh $HOST ":> $command_status"
1864 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
1865 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
1866 echo command failed >$command_status"
1867 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
1872 # print HOSTNAME for myPDSH="no_dsh"
1873 if [[ $myPDSH = no_dsh ]]; then
1874 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
1876 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
1879 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
1881 return ${PIPESTATUS[0]}
1885 do_node --verbose "$@"
1888 single_local_node () {
1889 [ "$1" = "$HOSTNAME" ]
1892 # Outputs environment variable assignments that should be passed to remote nodes
1897 for var in ${!MODOPTS_*}; do
1899 echo "${var}=\"$value\""
1905 # do not stripe off hostname if verbose, bug 19215
1906 if [ x$1 = x--verbose ]; then
1914 if single_local_node $rnodes; then
1916 do_nodev $rnodes "$@"
1918 do_node $rnodes "$@"
1923 # This is part from do_node
1926 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
1927 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
1930 echo "CMD: $rnodes $@" >&2
1931 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
1934 # do not replace anything from pdsh output if -N is used
1935 # -N Disable hostname: prefix on lines of output.
1936 if $verbose || [[ $myPDSH = *-N* ]]; then
1937 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
1939 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
1941 return ${PIPESTATUS[0]}
1947 local HOST=`facet_active_host $facet`
1948 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
1953 do_nodes --verbose "$@"
1959 # make sure its not already running
1961 rm -f $TMP/${facet}active
1962 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
1963 do_facet ${facet} $MKFS $*
1969 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
1970 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}}
1977 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
1978 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}}
1984 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
1986 local var=${facet}_MOUNT
1987 eval mntpt=${!var:-${MOUNT%/*}/$facet}
1996 # make sure we are using the primary server, so test-framework will
1997 # be able to clean up properly.
1998 activemds=`facet_active mds1`
1999 if [ $activemds != "mds1" ]; then
2003 local clients=$CLIENTS
2004 [ -z $clients ] && clients=$(hostname)
2006 zconf_umount_clients $clients $MOUNT "$*" || true
2007 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2009 [ "$CLIENTONLY" ] && return
2010 # The add fn does rm ${facet}active file, this would be enough
2011 # if we use do_facet <facet> only after the facet added, but
2012 # currently we use do_facet mds in local.sh
2013 for num in `seq $MDSCOUNT`; do
2015 rm -f ${TMP}/mds${num}active
2017 combined_mgs_mds && rm -f $TMP/mgsactive
2019 for num in `seq $OSTCOUNT`; do
2021 rm -f $TMP/ost${num}active
2024 if ! combined_mgs_mds ; then
2031 cleanup_echo_devs () {
2032 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2034 for dev in $devs; do
2035 $LCTL --device $dev cleanup
2036 $LCTL --device $dev detach
2041 nfs_client_mode && return
2050 combined_mgs_mds () {
2051 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2057 local tgt=$(echo $facet | tr -d [:digit:] | tr "[:lower:]" "[:upper:]")
2058 local optvar=${tgt}_MKFS_OPTS
2059 local opt=${!optvar}
2061 # FIXME: ! combo mgs/mds + mgsfailover is not supported yet
2062 [[ $facet = mgs ]] && echo $opt && return
2065 # --failnode options
2066 local var=${facet}failover_HOST
2067 if [ x"${!var}" != x ] && [ x"${!var}" != x$(facet_host $facet) ] ; then
2068 local failnode=$(h2$NETTYPE ${!var})
2069 failnode="--failnode=$failnode"
2070 # options does not contain
2071 # or contains wrong --failnode=
2072 if [[ $opt != *${failnode}* ]]; then
2073 opt=$(echo $opt | sed 's/--failnode=.* / /')
2074 opt="$opt $failnode"
2080 # no additional mkfs mds "--mgsnode" option for this configuration
2081 if [[ $facet = mds ]] && combined_mgs_mds; then
2086 # additional mkfs "--mgsnode"
2087 local mgsnode="--mgsnode=$MGSNID"
2088 opt=${opt//$mgsnode }
2089 for nid in ${MGSNID//:/ }; do
2090 local mgsnode="--mgsnode=$nid"
2091 # options does not contain
2093 if [[ $opt != *${mgsnode}" "* ]]; then
2094 opt="$opt --mgsnode=$nid"
2102 if [ "$IAMDIR" == "yes" ]; then
2103 MDS_MKFS_OPTS="$MDS_MKFS_OPTS --iam-dir"
2106 [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
2109 # We need ldiskfs here, may as well load them all
2111 [ "$CLIENTONLY" ] && return
2112 echo Formatting mgs, mds, osts
2113 if ! combined_mgs_mds ; then
2114 add mgs $(mkfs_opts mgs) $FSTYPE_OPT --reformat $MGSDEV || exit 10
2117 for num in `seq $MDSCOUNT`; do
2118 echo "Format mds$num: $(mdsdevname $num)"
2120 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) || exit 10
2122 add mds$num $(mkfs_opts mds) $FSTYPE_OPT --reformat $(mdsdevname $num) > /dev/null || exit 10
2126 # the ost-s could have different OST_MKFS_OPTS
2127 # because of different failnode-s
2128 for num in `seq $OSTCOUNT`; do
2129 echo "Format ost$num: $(ostdevname $num)"
2131 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` || exit 10
2133 add ost$num $(mkfs_opts ost${num}) $FSTYPE_OPT --reformat `ostdevname $num` > /dev/null || exit 10
2139 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2143 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2147 # 0: success, the old identity set already.
2148 # 1: success, the old identity does not set.
2153 local j=`expr $num - 1`
2154 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2156 if [ -z "$MDT" ]; then
2160 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2163 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2165 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2168 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2170 if [ $old = "NONE" ]; then
2179 zconf_umount `hostname` $1 || error "umount failed"
2180 zconf_mount `hostname` $1 || error "mount failed"
2183 writeconf_facet () {
2187 do_facet $facet "$TUNEFS --writeconf $dev"
2191 for num in `seq $MDSCOUNT`; do
2192 DEVNAME=$(mdsdevname $num)
2193 writeconf_facet mds$num $DEVNAME
2196 for num in `seq $OSTCOUNT`; do
2197 DEVNAME=$(ostdevname $num)
2198 writeconf_facet ost$num $DEVNAME
2203 nfs_client_mode && return
2205 sanity_mount_check ||
2206 error "environments are insane!"
2210 if [ -z "$CLIENTONLY" ]; then
2211 echo Setup mgs, mdt, osts
2212 echo $WRITECONF | grep -q "writeconf" && \
2214 if ! combined_mgs_mds ; then
2215 start mgs $MGSDEV $MGS_MOUNT_OPTS
2218 for num in `seq $MDSCOUNT`; do
2219 DEVNAME=$(mdsdevname $num)
2220 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2222 # We started mds, now we should set failover variables properly.
2223 # Set mds${num}failover_HOST if it is not set (the default failnode).
2224 local varname=mds${num}failover_HOST
2225 if [ -z "${!varname}" ]; then
2226 eval mds${num}failover_HOST=$(facet_host mds$num)
2229 if [ $IDENTITY_UPCALL != "default" ]; then
2230 switch_identity $num $IDENTITY_UPCALL
2233 for num in `seq $OSTCOUNT`; do
2234 DEVNAME=$(ostdevname $num)
2235 start ost$num $DEVNAME $OST_MOUNT_OPTS
2237 # We started ost$num, now we should set ost${num}failover variable properly.
2238 # Set ost${num}failover_HOST if it is not set (the default failnode).
2239 varname=ost${num}failover_HOST
2240 if [ -z "${!varname}" ]; then
2241 eval ost${num}failover_HOST=$(facet_host ost${num})
2249 # wait a while to allow sptlrpc configuration be propogated to targets,
2250 # only needed when mounting new target devices.
2255 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2257 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2259 if [ "$MOUNT_2" ]; then
2260 mount_client $MOUNT2
2261 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2266 # by remounting mdt before ost, initial connect from mdt to ost might
2267 # timeout because ost is not ready yet. wait some time to its fully
2268 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2269 # by a context negotiation rpc with $TIMEOUT.
2270 # FIXME better by monitoring import status.
2273 sleep $((TIMEOUT + 5))
2279 mounted_lustre_filesystems() {
2280 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2283 init_facet_vars () {
2284 [ "$CLIENTONLY" ] && return 0
2291 eval export ${facet}_dev=${device}
2292 eval export ${facet}_opt=\"$@\"
2294 local dev=${facet}_dev
2295 local label=$(do_facet ${facet} "$E2LABEL ${!dev}")
2296 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2298 eval export ${facet}_svc=${label}
2300 local varname=${facet}failover_HOST
2301 if [ -z "${!varname}" ]; then
2302 eval $varname=$(facet_host $facet)
2305 # ${facet}failover_dev is set in cfg file
2306 varname=${facet}failover_dev
2307 if [ -n "${!varname}" ] ; then
2308 eval export ${facet}failover_dev=${!varname}
2310 eval export ${facet}failover_dev=$device
2313 # get mount point of already mounted device
2314 # is facet_dev is already mounted then use the real
2315 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2316 # i.e. ${facet}_MOUNT if specified by user or default
2317 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2318 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2319 if [ -z $mntpt ]; then
2320 mntpt=$(facet_mntpt $facet)
2322 eval export ${facet}_MOUNT=$mntpt
2325 init_facets_vars () {
2328 if ! remote_mds_nodsh; then
2329 for num in `seq $MDSCOUNT`; do
2330 DEVNAME=`mdsdevname $num`
2331 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2335 combined_mgs_mds || init_facet_vars mgs $MGSDEV $MGS_MOUNT_OPTS
2337 remote_ost_nodsh && return
2339 for num in `seq $OSTCOUNT`; do
2340 DEVNAME=`ostdevname $num`
2341 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2345 osc_ensure_active () {
2350 while [ $period -lt $timeout ]; do
2351 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2352 if [ $count -eq 0 ]; then
2356 echo "There are $count OST are inactive, wait $period seconds, and try again"
2358 period=$((period+3))
2361 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2364 init_param_vars () {
2365 if ! remote_ost_nodsh && ! remote_mds_nodsh; then
2366 export MDSVER=$(do_facet $SINGLEMDS "lctl get_param version" | cut -d. -f1,2)
2367 export OSTVER=$(do_facet ost1 "lctl get_param version" | cut -d. -f1,2)
2368 export CLIVER=$(lctl get_param version | cut -d. -f 1,2)
2372 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2374 log "Using TIMEOUT=$TIMEOUT"
2376 osc_ensure_active $SINGLEMDS $TIMEOUT
2377 osc_ensure_active client $TIMEOUT
2379 if [ $QUOTA_AUTO -ne 0 ]; then
2380 if [ "$ENABLE_QUOTA" ]; then
2381 echo "enable quota as required"
2382 setup_quota $MOUNT || return 2
2384 echo "disable quota as required"
2385 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2392 nfs_client_mode () {
2393 if [ "$NFSCLIENT" ]; then
2394 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2395 local clients=$CLIENTS
2396 [ -z $clients ] && clients=$(hostname)
2398 # FIXME: remove hostname when 19215 fixed
2399 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2400 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2401 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2402 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2404 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2410 check_config_client () {
2413 local mounted=$(mount | grep " $mntpt ")
2414 if [ "$CLIENTONLY" ]; then
2416 # CLIENTONLY should not depend on *_HOST settings
2417 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2418 # in theory someone could create a new,
2419 # client-only config file that assumed lustre was already
2420 # configured and didn't set the MGSNID. If MGSNID is not set,
2421 # then we should use the mgs nid currently being used
2422 # as the default value. bug 18021
2423 [[ x$MGSNID = x ]] &&
2426 if [[ x$mgc != xMGC$MGSNID ]]; then
2427 if [ "$mgs_HOST" ]; then
2428 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2429 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2430 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2436 local myMGS_host=$mgs_HOST
2437 if [ "$NETTYPE" = "ptl" ]; then
2438 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2441 echo Checking config lustre mounted on $mntpt
2442 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2443 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2445 # if [ "$mgshost" != "$myMGS_host" ]; then
2446 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2447 # Please use correct config or set mds_HOST correctly!"
2452 check_config_clients () {
2453 local clients=${CLIENTS:-$HOSTNAME}
2456 nfs_client_mode && return
2458 do_rpc_nodes $clients check_config_client $mntpt
2460 sanity_mount_check ||
2461 error "environments are insane!"
2465 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2466 local cltimeout=$(lctl get_param -n timeout)
2467 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2468 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2475 [ -z $mntpt ] && return 1
2476 local mounted=$(mounted_lustre_filesystems)
2478 echo $mounted' ' | grep -w -q $mntpt' '
2482 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2486 # empty lustre filesystem may have empty directories lost+found and .lustre
2488 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2489 -print | wc -l) = 1 ] || return 1
2490 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2491 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2495 check_and_setup_lustre() {
2496 nfs_client_mode && return
2498 local MOUNTED=$(mounted_lustre_filesystems)
2502 # both MOUNT and MOUNT2 are not mounted
2503 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2504 [ "$REFORMAT" ] && formatall
2505 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2507 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2508 export I_MOUNTED=yes
2512 elif is_mounted $MOUNT2; then
2514 # MOUNT2 is mounted, while MOUNT_2 is not set
2515 if ! [ "$MOUNT_2" ]; then
2516 cleanup_mount $MOUNT2
2517 export I_UMOUNTED2=yes
2520 # MOUNT2 is mounted, MOUNT_2 is set
2522 # FIXME: what to do if check_config failed?
2524 # 1) remote client has mounted other Lustre fs ?
2525 # 2) it has insane env ?
2526 # let's try umount MOUNT2 on all clients and mount it again:
2527 if ! check_config_clients $MOUNT2; then
2528 cleanup_mount $MOUNT2
2529 restore_mount $MOUNT2
2530 export I_MOUNTED2=yes
2535 # MOUNT is mounted MOUNT2 is not mounted
2536 elif [ "$MOUNT_2" ]; then
2537 restore_mount $MOUNT2
2538 export I_MOUNTED2=yes
2542 # FIXME: what to do if check_config failed?
2544 # 1) remote client has mounted other Lustre fs?
2545 # 2) lustre is mounted on remote_clients atall ?
2546 check_config_clients $MOUNT
2550 set_default_debug_nodes $(comma_list $(nodes_list))
2556 if [ "$ONLY" == "setup" ]; then
2562 local clients=${CLIENTS:-$HOSTNAME}
2565 zconf_mount_clients $clients $mntpt
2569 local clients=${CLIENTS:-$HOSTNAME}
2572 zconf_umount_clients $clients $mntpt
2575 cleanup_and_setup_lustre() {
2576 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
2577 lctl set_param debug=0 || true
2579 if [ "$ONLY" == "cleanup" ]; then
2583 check_and_setup_lustre
2586 # Get all of the server target devices from a given server node and type.
2595 mdt) obd_type="osd" ;;
2596 ost) obd_type="obdfilter" ;; # needs to be fixed when OST also uses an OSD
2597 *) echo "invalid server type" && return 1 ;;
2600 devs=$(do_node $node "lctl get_param -n $obd_type*.*.mntdev")
2601 for dev in $devs; do
2603 *loop*) do_node $node "losetup $dev" | \
2604 sed -e "s/.*(//" -e "s/).*//" ;;
2610 # Get all of the server target devices.
2615 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
2619 for node in $(osts_nodes); do
2620 OSTDEVS[i]=$(get_mnt_devs $node ost)
2625 # Run e2fsck on MDT or OST device.
2631 df > /dev/null # update statfs data on disk
2632 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
2635 do_node $node $cmd || rc=$?
2636 [ $rc -le $FSCK_MAX_ERR ] || \
2637 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2641 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
2648 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
2649 tmp_file=$(mktemp -p $SHARED_DIRECTORY ||
2650 error "fail to create file in $SHARED_DIRECTORY")
2652 # make sure everything gets to the backing store
2653 local list=$(comma_list $CLIENTS $(facet_host $SINGLEMDS) $(osts_nodes))
2654 do_nodes $list "sync; sleep 2; sync"
2656 do_nodes $list ls $tmp_file || \
2657 error "$SHARED_DIRECTORY is not a shared directory"
2660 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
2665 for node in $(osts_nodes); do
2666 for dev in ${OSTDEVS[i]}; do
2667 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
2668 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
2669 ostidx=$((ostidx + 1))
2676 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
2680 [ $rc -le $FSCK_MAX_ERR ] || \
2681 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
2682 echo "lfsck finished with rc=$rc"
2684 rm -rvf $MDSDB* $OSTDB* || true
2688 check_and_cleanup_lustre() {
2689 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
2695 if is_mounted $MOUNT; then
2696 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
2697 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
2700 if [ "$I_UMOUNTED2" = "yes" ]; then
2701 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
2704 if [ "$I_MOUNTED2" = "yes" ]; then
2705 cleanup_mount $MOUNT2
2708 if [ "$I_MOUNTED" = "yes" ]; then
2709 cleanupall -f || error "cleanup failed"
2717 wait_for_function () {
2720 # suppress fn both stderr and stdout
2721 if [ "$1" = "--quiet" ]; then
2723 quiet=" > /dev/null 2>&1"
2735 eval $fn $quiet && return 0
2737 wait=$((wait + sleep))
2738 [ $wait -lt $max ] || return 1
2739 echo waiting $fn, $((max - wait)) secs left ...
2749 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
2750 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
2751 echo "Network not available!"
2755 echo `date +"%H:%M:%S (%s)"` network interface is UP
2764 # the sed converts spaces to commas, but leaves the last space
2765 # alone, so the line doesn't end with a comma.
2766 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
2772 echo $list | grep -qw $item
2775 # list, excluded are the comma separated lists
2776 exclude_items_from_list () {
2782 for item in ${excluded//,/ }; do
2783 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
2785 echo $(comma_list $list)
2788 # list, expand are the comma separated lists
2790 local list=${1//,/ }
2791 local expand=${2//,/ }
2794 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
2795 echo $(comma_list $expanded)
2798 testslist_filter () {
2799 local script=$LUSTRE/tests/${TESTSUITE}.sh
2801 [ -f $script ] || return 0
2803 local start_at=$START_AT
2804 local stop_at=$STOP_AT
2806 local var=${TESTSUITE//-/_}_START_AT
2807 [ x"${!var}" != x ] && start_at=${!var}
2808 var=${TESTSUITE//-/_}_STOP_AT
2809 [ x"${!var}" != x ] && stop_at=${!var}
2811 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
2812 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
2813 /^'${start_at}'$/ {flag = 0}
2814 {if (flag == 1) print $0}
2815 /^'${stop_at}'$/ { flag = 1 }'
2819 (cd `dirname $1`; echo $PWD/`basename $1`)
2823 local types=${1:-"OST MDS MGS"}
2827 for entry in $types; do
2828 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
2829 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
2832 MGS ) list="$list $name";;
2833 MDS|OST ) local count=${type}COUNT
2834 for ((i=1; i<=${!count}; i++)) do
2835 list="$list ${name}$i"
2837 * ) error "Invalid facet type"
2841 echo $(comma_list $list)
2844 ##################################
2845 # Adaptive Timeouts funcs
2848 # only check mds, we assume at_max is the same on all nodes
2849 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
2850 if [ $at_max -eq 0 ]; then
2861 # suppose that all ost-s have the same $at value set
2862 [ $facet != "ost" ] || facet=ost1
2864 do_facet $facet "lctl get_param -n $at"
2878 if [ $facet == "ost" ]; then
2879 facet=$(get_facets OST)
2880 elif [ $facet == "mds" ]; then
2881 facet=$(get_facets MDS)
2883 hosts=$(expand_list $hosts $(facets_hosts $facet))
2886 do_nodes $hosts lctl set_param at_max=$at_max
2889 ##################################
2893 # OBD_FAIL_MDS_ALL_REQUEST_NET
2895 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
2896 do_facet client "$1" || RC=$?
2897 do_facet $SINGLEMDS lctl set_param fail_loc=0
2902 # OBD_FAIL_MDS_ALL_REPLY_NET
2904 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
2905 do_facet client "$@" || RC=$?
2906 do_facet $SINGLEMDS lctl set_param fail_loc=0
2910 drop_reint_reply() {
2911 # OBD_FAIL_MDS_REINT_NET_REP
2913 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2914 do_facet client "$@" || RC=$?
2915 do_facet $SINGLEMDS lctl set_param fail_loc=0
2920 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2922 do_facet ost1 lctl set_param fail_loc=0x214
2923 do_facet client "$1" || RC=$?
2924 do_facet client "sync"
2925 do_facet ost1 lctl set_param fail_loc=0
2929 drop_ldlm_cancel() {
2930 #define OBD_FAIL_LDLM_CANCEL 0x304
2932 do_facet client lctl set_param fail_loc=0x304
2933 do_facet client "$@" || RC=$?
2934 do_facet client lctl set_param fail_loc=0
2938 drop_bl_callback() {
2939 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
2941 do_facet client lctl set_param fail_loc=0x305
2942 do_facet client "$@" || RC=$?
2943 do_facet client lctl set_param fail_loc=0
2948 #define OBD_FAIL_LDLM_REPLY 0x30c
2950 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
2951 do_facet client "$@" || RC=$?
2952 do_facet $SINGLEMDS lctl set_param fail_loc=0
2960 echo "clearing fail_loc on $facet"
2961 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
2964 set_nodes_failloc () {
2965 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
2968 cancel_lru_locks() {
2969 $LCTL mark "cancel_lru_locks $1 start"
2970 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
2971 $LCTL set_param -n $d=clear
2973 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
2974 $LCTL mark "cancel_lru_locks $1 stop"
2979 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
2980 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
2981 echo "$DEFAULT_LRU_SIZE"
2986 lctl set_param ldlm.namespaces.*$1*.lru_size=0
2989 lru_resize_disable()
2991 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
2996 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
2997 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
2998 echo there is still data in page cache $FILE ?
2999 lctl get_param -n $FILE
3007 DEBUGSAVE="$(lctl get_param -n debug)"
3011 [ -n "$DEBUGSAVE" ] && \
3012 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3017 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3020 debug_size_restore() {
3021 [ -n "$DEBUG_SIZE_SAVED" ] && \
3022 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3026 start_full_debug_logging() {
3031 local DEBUG_SIZE=150
3033 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3034 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3037 stop_full_debug_logging() {
3042 ##################################
3044 ##################################
3047 local TYPE=${TYPE:-"FAIL"}
3050 # do not dump logs if $1=false
3051 if [ "x$1" = "xfalse" ]; then
3056 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3058 # We need to dump the logs on all nodes
3060 gather_logs $(comma_list $(nodes_list)) 0
3064 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3065 echo "$@" > $LOGDIR/err
3070 local log=$TESTSUITELOG
3072 [ -f "$log" ] && grep -q FAIL: $log && status=1
3085 # use only if we are ignoring failures for this test, bugno required.
3086 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3087 # e.g. error_ignore 5494 "your message"
3089 local TYPE="IGNORE (bz$1)"
3095 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3100 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3101 [ "$ALWAYS_SKIPPED" ] && \
3102 skip_logged ${TESTNAME} "$@" || true
3103 [ "$TESTSUITELOG" ] && \
3104 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3107 build_test_filter() {
3108 EXCEPT="$EXCEPT $(testslist_filter)"
3110 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3114 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3115 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3116 [ "$EXCEPT_SLOW" ] && \
3117 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3118 for E in $EXCEPT; do
3119 eval EXCEPT_${E}=true
3121 for E in $ALWAYS_EXCEPT; do
3122 eval EXCEPT_ALWAYS_${E}=true
3124 for E in $EXCEPT_SLOW; do
3125 eval EXCEPT_SLOW_${E}=true
3127 for G in $GRANT_CHECK_LIST; do
3128 eval GCHECK_ONLY_${G}=true
3133 if [[ $1 = [a-z]* ]]; then
3140 # print a newline if the last test was skipped
3141 export LAST_SKIPPED=
3142 export ALWAYS_SKIPPED=
3144 # Main entry into test-framework. This is called with the name and
3145 # description of a test. The name is used to find the function to run
3146 # the test using "test_$name".
3148 # This supports a variety of methods of specifying specific test to
3149 # run or not run. These need to be documented...
3154 export base=`basetest $1`
3155 if [ ! -z "$ONLY" ]; then
3157 if [ ${!testname}x != x ]; then
3158 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3159 run_one_logged $1 "$2"
3163 if [ ${!testname}x != x ]; then
3164 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3165 run_one_logged $1 "$2"
3173 if [ ${!testname}x != x ]; then
3175 TESTNAME=test_$1 skip "skipping excluded test $1"
3178 testname=EXCEPT_$base
3179 if [ ${!testname}x != x ]; then
3181 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3184 testname=EXCEPT_ALWAYS_$1
3185 if [ ${!testname}x != x ]; then
3188 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3191 testname=EXCEPT_ALWAYS_$base
3192 if [ ${!testname}x != x ]; then
3195 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3198 testname=EXCEPT_SLOW_$1
3199 if [ ${!testname}x != x ]; then
3201 TESTNAME=test_$1 skip "skipping SLOW test $1"
3204 testname=EXCEPT_SLOW_$base
3205 if [ ${!testname}x != x ]; then
3207 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3213 run_one_logged $1 "$2"
3224 module_loaded lnet || load_modules
3236 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3241 strace -o $TMP/$1.strace -ttt $*
3243 log "FINISHED: $*: rc $RC"
3248 equals_msg $1 test complete, duration $2 sec
3249 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3250 echo duration $2 >>$TESTSUITELOG
3254 # Set TEST_STATUS here; will be used for logging the result
3255 if [ -f $LOGDIR/err ]; then
3260 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3264 local FFREE=$(do_node $SINGLEMDS \
3265 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3266 local FTOTAL=$(do_node $SINGLEMDS \
3267 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3269 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3273 echo -n "Resetting fail_loc on all nodes..."
3274 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3280 # Log a message (on all nodes) padded with "=" before and after.
3281 # Also appends a timestamp and prepends the testsuite name.
3284 EQUALS="===================================================================================================="
3286 msg="== ${TESTSUITE} $*"
3288 [[ $last != "=" && $last != " " ]] && msg="$msg "
3289 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3290 # always include at least == after the message
3291 log "$msg== $(date +"%H:%M:%S (%s)")"
3295 # Run a single test function and cleanup after it.
3297 # This function should be run in a subshell so the test func can
3298 # exit() without stopping the whole script.
3304 export tdir=d0.${TESTSUITE}/d${base}
3305 export TESTNAME=test_$testnum
3306 local SAVE_UMASK=`umask`
3309 banner "test $testnum: $message"
3310 test_${testnum} || error "test_$testnum failed with $?"
3313 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3314 check_catastrophe || error "LBUG/LASSERT detected"
3315 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3323 # Wrapper around run_one to ensure:
3324 # - test runs in subshell
3325 # - output of test is saved to separate log file for error reporting
3326 # - test result is saved to data file
3329 local BEFORE=`date +%s`
3331 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3332 local test_log=$LOGDIR/$name
3334 local SAVE_UMASK=`umask`
3338 log_sub_test_begin test_${1}
3339 (run_one $1 "$2") 2>&1 | tee -i $test_log
3340 local RC=${PIPESTATUS[0]}
3342 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3343 echo "test_$1 returned $RC" | tee $LOGDIR/err
3345 duration=$((`date +%s` - $BEFORE))
3346 pass "$1" "(${duration}s)"
3347 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3348 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3350 if [ -f $LOGDIR/err ]; then
3351 $FAIL_ON_ERROR && exit $RC
3360 # Print information of skipped tests to result.yml
3363 log_sub_test_begin $1
3364 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3368 (cd `dirname $1`; echo $PWD/`basename $1`)
3373 export base=`basetest $1`
3374 [ "$CHECK_GRANT" == "no" ] && return 0
3376 testname=GCHECK_ONLY_${base}
3377 [ ${!testname}x == x ] && return 0
3379 echo -n "checking grant......"
3381 local clients=$CLIENTS
3382 [ -z $clients ] && clients=$(hostname)
3384 # sync all the data and make sure no pending data on server
3385 do_nodes $clients sync
3388 client_grant=`do_nodes $clients \
3389 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3390 awk '{total += $1} END{print total}'`
3393 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3394 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" | \
3395 awk '{total += $1} END{print total}'`
3397 # check whether client grant == server grant
3398 if [ $client_grant -ne $server_grant ]; then
3399 echo "failed: client:${client_grant} server: ${server_grant}."
3400 do_nodes $(comma_list $(osts_nodes)) \
3401 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3402 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3405 echo "pass: client:${client_grant} server: ${server_grant}"
3410 ########################
3416 ost=`echo $1 | awk -F_ '{print $3}'`
3417 if [ -z $ost ]; then
3418 ost=`echo $1 | sed 's/-osc.*//'`
3423 ostuuid_from_index()
3425 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3428 ostname_from_index() {
3429 local uuid=$(ostuuid_from_index $1)
3433 index_from_ostuuid()
3435 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3440 [ "$node" != "$(hostname)" ]
3446 for node in $(mdts_nodes); do
3447 remote_node $node && return 0
3454 [ "$CLIENTONLY" ] && return 0 || true
3455 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3460 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3461 MSKIPPED=1 && return 1
3468 for node in $(osts_nodes) ; do
3469 remote_node $node && return 0
3476 [ "$CLIENTONLY" ] && return 0 || true
3477 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3482 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3483 OSKIPPED=1 && return 1
3490 MGS=$(facet_host mgs)
3491 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3496 remote_mds_nodsh || remote_ost_nodsh || \
3497 $(single_local_node $(comma_list $(nodes_list)))
3503 for num in `seq $MDSCOUNT`; do
3504 MDSNODES="$MDSNODES $(facet_host mds$num)"
3506 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
3512 remote_ost && remote_mds
3520 for facet in ${facets//,/ }; do
3521 if [ "$FAILURE_MODE" = HARD ]; then
3522 nodes="$nodes $(facet_active_host $facet)"
3524 nodes="$nodes $(facet_host $facet)"
3527 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
3533 local facets=$(get_facets OST)
3534 local nodes=$(facets_nodes $facets)
3540 # FIXME. We need a list of clients
3541 local myNODES=$HOSTNAME
3544 # CLIENTS (if specified) contains the local client
3545 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
3547 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
3548 myNODES="$myNODES $(facets_nodes $(get_facets))"
3551 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
3556 remote_nodes_list () {
3557 local rnodes=$(nodes_list)
3558 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
3562 init_clients_lists () {
3563 # Sanity check: exclude the local client from RCLIENTS
3564 local clients=$(hostlist_expand "$RCLIENTS")
3565 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
3567 # Sanity check: exclude the dup entries
3568 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
3570 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
3572 # Sanity check: exclude the dup entries from CLIENTS
3573 # for those configs which has SINGLCLIENT set to local client
3574 clients=$(for i in $clients; do echo $i; done | sort -u)
3576 CLIENTS=$(comma_list $clients)
3577 local -a remoteclients=($RCLIENTS)
3578 for ((i=0; $i<${#remoteclients[@]}; i++)); do
3579 varname=CLIENT$((i + 2))
3580 eval $varname=${remoteclients[i]}
3583 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
3586 get_random_entry () {
3589 rnodes=${rnodes//,/ }
3591 local -a nodes=($rnodes)
3592 local num=${#nodes[@]}
3593 local i=$((RANDOM * num * 2 / 65536))
3599 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
3604 lctl get_param version | grep -q patchless
3608 [ "$MDSVER" = "$CLIVER" -a "$OSTVER" = "$CLIVER" ]
3613 echo $nodes | wc -w || true
3617 local nodes=$(osts_nodes)
3618 local osscount=$(get_node_count "$nodes")
3619 [ ! "$OSTCOUNT" = "$osscount" ]
3623 local nodes=$(mdts_nodes)
3624 local mdtcount=$(get_node_count "$nodes")
3625 [ ! "$MDSCOUNT" = "$mdtcount" ]
3628 generate_machine_file() {
3629 local nodes=${1//,/ }
3630 local machinefile=$2
3632 for node in $nodes; do
3633 echo $node >>$machinefile || \
3634 { echo "can not generate machinefile $machinefile" && return 1; }
3639 local file=$1/stripe
3641 $LFS getstripe -v $file || error
3645 setstripe_nfsserver () {
3648 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
3649 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
3651 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
3653 do_nodev $nfsserver lfs setstripe "$@"
3656 check_runas_id_ret() {
3658 local myRUNAS_UID=$1
3659 local myRUNAS_GID=$2
3662 if [ -z "$myRUNAS" ]; then
3663 error_exit "myRUNAS command must be specified for check_runas_id"
3666 $myRUNAS krb5_login.sh || \
3667 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
3669 mkdir $DIR/d0_runas_test
3671 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
3672 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
3673 rm -rf $DIR/d0_runas_test
3678 local myRUNAS_UID=$1
3679 local myRUNAS_GID=$2
3682 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
3683 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
3684 Please set RUNAS_ID to some UID which exists on MDS and client or
3685 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
3688 # obtain the UID/GID for MPI_USER
3692 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
3693 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
3695 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
3696 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
3699 # obtain and cache Kerberos ticket-granting ticket
3700 refresh_krb5_tgt() {
3701 local myRUNAS_UID=$1
3702 local myRUNAS_GID=$2
3705 if [ -z "$myRUNAS" ]; then
3706 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
3709 CLIENTS=${CLIENTS:-$HOSTNAME}
3710 do_nodes $CLIENTS "set -x
3711 if ! $myRUNAS krb5_login.sh; then
3712 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
3717 # Run multiop in the background, but wait for it to print
3718 # "PAUSING" to its stdout before returning from this function.
3719 multiop_bg_pause() {
3720 MULTIOP_PROG=${MULTIOP_PROG:-multiop}
3724 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
3727 echo "$MULTIOP_PROG $FILE v$ARGS"
3728 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
3730 echo "TMPPIPE=${TMPPIPE}"
3731 read -t 60 multiop_output < $TMPPIPE
3732 if [ $? -ne 0 ]; then
3737 if [ "$multiop_output" != "PAUSING" ]; then
3738 echo "Incorrect multiop output: $multiop_output"
3753 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
3759 inodes_available () {
3760 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
3764 mdsrate_inodes_available () {
3765 local min_inodes=$(inodes_available)
3766 echo $((min_inodes * 99 / 100))
3769 # reset llite stat counters
3770 clear_llite_stats(){
3771 lctl set_param -n llite.*.stats 0
3774 # sum llite stat items
3775 calc_llite_stats() {
3776 local res=$(lctl get_param -n llite.*.stats |
3777 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3781 # reset osc stat counters
3783 lctl set_param -n osc.*.osc_stats 0
3786 # sum osc stat items
3788 local res=$(lctl get_param -n osc.*.osc_stats |
3789 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
3794 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
3797 calc_osc_kbytes () {
3798 df $MOUNT > /dev/null
3799 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
3802 # save_lustre_params(node, parameter_mask)
3803 # generate a stream of formatted strings (<node> <param name>=<param value>)
3804 save_lustre_params() {
3806 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
3809 # restore lustre parameters from input stream, produces by save_lustre_params
3810 restore_lustre_params() {
3814 while IFS=" =" read node name val; do
3815 do_node ${node//:/} "lctl set_param -n $name $val"
3819 check_catastrophe() {
3820 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
3821 local C=$CATASTROPHE
3822 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
3824 if [ $rnodes ]; then
3825 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
3826 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
3842 do_facet $1 $3 lfs getstripe -v $2 > $tmp_file
3844 stripe_size=`awk '$1 ~ /size/ {print $2}' $tmp_file`
3845 stripe_count=`awk '$1 ~ /count/ {print $2}' $tmp_file`
3846 stripe_index=`awk '$1 ~ /stripe_offset/ {print $2}' $tmp_file`
3850 # CMD: determine mds index where directory inode presents
3853 local file=$dir/f0.get_mds_dir_tmpfile
3858 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3859 local -a oldused=($iused)
3861 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
3863 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
3864 local -a newused=($iused)
3867 for ((i=0; i<${#newused[@]}; i++)); do
3868 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
3874 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
3877 mdsrate_cleanup () {
3879 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
3884 delayed_recovery_enabled () {
3885 local var=${SINGLEMDS}_svc
3886 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
3889 ########################
3891 convert_facet2label() {
3894 if [ x$facet = xost ]; then
3898 local varsvc=${facet}_svc
3900 if [ -n ${!varsvc} ]; then
3903 error "No lablel for $facet!"
3907 get_clientosc_proc_path() {
3908 echo "${1}-osc-[^M]*"
3911 get_lustre_version () {
3912 local facet=${1:-"$SINGLEMDS"}
3913 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
3916 get_mds_version_major () {
3917 local facet=${1:-"$SINGLEMDS"}
3918 local version=$(get_lustre_version $facet)
3919 echo $version | awk -F. '{print $1}'
3922 get_mds_version_minor () {
3923 local facet=${1:-"$SINGLEMDS"}
3924 local version=$(get_lustre_version $facet)
3925 echo $version | awk -F. '{print $2}'
3928 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
3929 # used by MDT would not be changed.
3930 # mdt lov: fsname-mdtlov
3931 # mdt osc: fsname-OSTXXXX-osc
3932 mds_on_old_device() {
3933 local mds=${1:-"$SINGLEMDS"}
3934 local major=$(get_mds_version_major $mds)
3935 local minor=$(get_mds_version_minor $mds)
3937 if [ $major -ge 2 ] || [ $major -eq 1 -a $minor -gt 8 ]; then
3938 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
3939 > /dev/null 2>&1" && return 0
3944 get_mdtosc_proc_path() {
3946 local ost_label=${2:-"*OST*"}
3948 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
3949 local mdt_label=$(convert_facet2label $mds_facet)
3950 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
3952 local major=$(get_mds_version_major $mds_facet)
3953 local minor=$(get_mds_version_minor $mds_facet)
3954 if [ $major -le 1 -a $minor -le 8 ] || mds_on_old_device $mds_facet; then
3955 echo "${ost_label}-osc"
3957 echo "${ost_label}-osc-${mdt_index}"
3961 get_osc_import_name() {
3964 local label=$(convert_facet2label $ost)
3966 if [ "${facet:0:3}" = "mds" ]; then
3967 get_mdtosc_proc_path $facet $label
3971 get_clientosc_proc_path $label
3975 _wait_import_state () {
3978 local maxtime=${3:-$(max_recovery_time)}
3982 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3983 while [ "${CONN_STATE}" != "${expected}" ]; do
3984 if [ "${expected}" == "DISCONN" ]; then
3985 # for disconn we can check after proc entry is removed
3986 [ "x${CONN_STATE}" == "x" ] && return 0
3987 # with AT enabled, we can have connect request timeout near of
3988 # reconnect timeout and test can't see real disconnect
3989 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
3991 [ $i -ge $maxtime ] && \
3992 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
3995 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
3999 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4003 wait_import_state() {
4006 local maxtime=${3:-$(max_recovery_time)}
4009 for param in ${params//,/ }; do
4010 _wait_import_state $state $param $maxtime || return
4014 # One client request could be timed out because server was not ready
4015 # when request was sent by client.
4016 # The request timeout calculation details :
4018 # /* We give the server rq_timeout secs to process the req, and
4019 # add the network latency for our local timeout. */
4020 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4021 # ptlrpc_at_get_net_latency(request) ;
4023 # ptlrpc_connect_import ()
4024 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4027 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4028 # ptlrpc_at_get_net_latency(request) ->
4029 # at_get (max (iat_net_latency=0, at_min)) = at_min
4032 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4033 # INITIAL_CONNECT_TIMEOUT + at_min
4035 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4036 # because we can not get this value in runtime,
4037 # the value depends on configure options, and it is not stored in /proc.
4039 # #define CONNECTION_SWITCH_MIN 5U
4041 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4043 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/2)
4045 request_timeout () {
4048 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4049 local init_connect_timeout=$TIMEOUT
4050 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4052 local at_min=$(at_get $facet at_min)
4054 echo $(( init_connect_timeout + at_min ))
4057 wait_osc_import_state() {
4061 local ost=$(get_osc_import_name $facet $ost_facet)
4063 local param="osc.${ost}.ost_server_uuid"
4065 # 1. wait the deadline of client 1st request (it could be skipped)
4066 # 2. wait the deadline of client 2nd request
4067 local maxtime=$(( 2 * $(request_timeout $facet)))
4069 if ! do_rpc_nodes $(facet_host $facet) \
4070 _wait_import_state $expected $param $maxtime; then
4071 error "import is not in ${expected} state"
4078 get_clientmdc_proc_path() {
4086 # Add paths to lustre tests for 32 and 64 bit systems.
4087 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4088 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4091 wait_clients_import_state () {
4098 if [ "$FAILURE_MODE" = HARD ]; then
4099 facets=$(facets_on_host $(facet_active_host $facet))
4102 for facet in ${facets//,/ }; do
4103 local label=$(convert_facet2label $facet)
4106 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4107 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4108 *) error "unknown facet!" ;;
4110 local params=$(expand_list $params $proc_path)
4113 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4114 error "import is not in ${expected} state"
4123 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4124 $LCTL get_param obdfilter.*.kbytesavail))
4125 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4126 $LCTL get_param -n obdfilter.*.tot_granted))
4127 for ((i=0; i<${#AVAILA[@]}; i++)); do
4128 local -a AVAIL1=(${AVAILA[$i]//=/ })
4129 GRANT=$((${GRANTA[$i]}/1024))
4130 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} grnt=$GRANT diff=$((AVAIL1[1] - GRANT))
4131 [ $((AVAIL1[1] - GRANT)) -lt 400 ] && OSCFULL=0 && echo " FULL" || echo
4137 do_facet mgs lctl pool_list $1
4141 local fsname=${1%%.*}
4142 local poolname=${1##$fsname.}
4144 do_facet mgs lctl pool_new $1
4146 # get param should return err unless pool is created
4147 [[ $RC -ne 0 ]] && return $RC
4149 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4150 2>/dev/null || echo foo" "" || RC=1
4151 if [[ $RC -eq 0 ]]; then
4154 error "pool_new failed $1"
4159 add_pool_to_list () {
4160 local fsname=${1%%.*}
4161 local poolname=${1##$fsname.}
4163 local listvar=${fsname}_CREATED_POOLS
4164 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4167 remove_pool_from_list () {
4168 local fsname=${1%%.*}
4169 local poolname=${1##$fsname.}
4171 local listvar=${fsname}_CREATED_POOLS
4172 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4175 destroy_pool_int() {
4177 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4178 awk '$1 !~ /^Pool:/ {print $1}')
4179 for ost in $OSTS; do
4180 do_facet mgs lctl pool_remove $1 $ost
4182 do_facet mgs lctl pool_destroy $1
4185 # <fsname>.<poolname> or <poolname>
4187 local fsname=${1%%.*}
4188 local poolname=${1##$fsname.}
4190 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4194 pool_list $fsname.$poolname || return $?
4196 destroy_pool_int $fsname.$poolname
4198 [[ $RC -ne 0 ]] && return $RC
4200 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4201 2>/dev/null || echo foo" "foo" || RC=1
4203 if [[ $RC -eq 0 ]]; then
4204 remove_pool_from_list $fsname.$poolname
4206 error "destroy pool failed $1"
4212 local fsname=${1:-$FSNAME}
4214 local listvar=${fsname}_CREATED_POOLS
4218 [ x${!listvar} = x ] && return 0
4220 echo destroy the created pools: ${!listvar}
4221 for poolname in ${!listvar//,/ }; do
4222 destroy_pool $fsname.$poolname
4227 local fsname=${1:-$FSNAME}
4229 destroy_pools $fsname
4236 local ts=$(date +%s)
4238 [ -f $LOGDIR/shared ] && docp=false
4240 # dump lustre logs, dmesg
4242 prefix="$LOGDIR/${TESTSUITE}.${TESTNAME}"
4244 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4246 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4247 echo "Dumping logs only on local client."
4248 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4249 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4254 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4255 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4256 if [ ! -f $LOGDIR/shared ]; then
4257 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4260 if [ $tar_logs == 1 ]; then
4261 local archive=$LOGDIR/${TESTSUITE}-$ts.tar.bz2
4262 tar -jcf $archive $LOGDIR/*$ts* $LOGDIR/*${TESTSUITE}*
4269 local list=${1:-$(comma_list $(nodes_list))}
4271 [ -n ${TESTSUITE} ] && do_nodes $list "rm -f $TMP/*${TESTSUITE}*" || true
4283 for i in $(seq 0 $num_mntpts); do
4284 cmd="ls -laf ${mntpt_root}$i/$dir"
4290 for pid in $pids; do
4297 # target_start_and_reset_recovery_timer()
4298 # service_time = at_est2timeout(service_time);
4299 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4300 # INITIAL_CONNECT_TIMEOUT);
4301 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4302 #define CONNECTION_SWITCH_INC 1
4303 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4304 #define CONNECTION_SWITCH_MIN 5U
4306 max_recovery_time () {
4307 local init_connect_timeout=$(( TIMEOUT / 20 ))
4308 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4310 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4315 get_clients_mount_count () {
4316 local clients=${CLIENTS:-`hostname`}
4318 # we need to take into account the clients mounts and
4319 # exclude mds/ost mounts if any;
4320 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4324 PROC_CLI="srpc_info"
4332 if [ $M -lt $N ]; then
4336 while [ $N -lt $M ]; do
4346 calc_connection_cnt() {
4349 # MDT->MDT = 2 * C(M, 2)
4353 comb_m2=$(combination $MDSCOUNT 2)
4355 local num_clients=$(get_clients_mount_count)
4357 local cnt_mdt2mdt=$((comb_m2 * 2))
4358 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4359 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4360 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4361 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4362 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4363 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4377 local cmd="$tgt.srpc.flavor"
4379 if [ $net == "any" ]; then
4384 if [ $dir != "any" ]; then
4389 log "Setting sptlrpc rule: $cmd"
4390 do_facet mgs "$LCTL conf_param $cmd"
4399 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4400 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4402 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4404 if [ "x$bulkspec" != "x" ]; then
4405 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4407 if [ "x$algs" != "x" ]; then
4408 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4410 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4411 if [ $bulk == "bulkn" ]; then
4412 bulk_count=`echo "$output" | grep "bulk flavor" \
4413 | grep "null/null" | wc -l`
4414 elif [ $bulk == "bulki" ]; then
4415 bulk_count=`echo "$output" | grep "bulk flavor" \
4416 | grep "/null" | grep -v "null/" | wc -l`
4418 bulk_count=`echo "$output" | grep "bulk flavor" \
4419 | grep -v "/null" | grep -v "null/" | wc -l`
4423 [ $bulk_count -lt $count ] && count=$bulk_count
4434 local clients=${CLIENTS:-`hostname`}
4436 for c in ${clients//,/ }; do
4437 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4438 tmpcnt=`count_flvr "$output" $flavor`
4439 cnt=$((cnt + tmpcnt))
4449 local clients=${CLIENTS:-`hostname`}
4451 for c in ${clients//,/ }; do
4452 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4453 tmpcnt=`count_flvr "$output" $flavor`
4454 cnt=$((cnt + tmpcnt))
4464 if [ $MDSCOUNT -le 1 ]; then
4469 for num in `seq $MDSCOUNT`; do
4470 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4471 tmpcnt=`count_flvr "$output" $flavor`
4472 cnt=$((cnt + tmpcnt))
4483 for num in `seq $MDSCOUNT`; do
4484 mdtosc=$(get_mdtosc_proc_path mds$num)
4485 mdtosc=${mdtosc/-MDT*/-MDT\*}
4486 output=$(do_facet mds$num lctl get_param -n \
4487 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4488 tmpcnt=`count_flvr "$output" $flavor`
4489 cnt=$((cnt + tmpcnt))
4498 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4499 count_flvr "$output" $flavor
4504 local dir=$1 # from to
4505 local flavor=$2 # flavor expected
4508 if [ $dir == "cli2mdt" ]; then
4509 res=`flvr_cnt_cli2mdt $flavor`
4510 elif [ $dir == "cli2ost" ]; then
4511 res=`flvr_cnt_cli2ost $flavor`
4512 elif [ $dir == "mdt2mdt" ]; then
4513 res=`flvr_cnt_mdt2mdt $flavor`
4514 elif [ $dir == "mdt2ost" ]; then
4515 res=`flvr_cnt_mdt2ost $flavor`
4516 elif [ $dir == "all2ost" ]; then
4517 res1=`flvr_cnt_mdt2ost $flavor`
4518 res2=`flvr_cnt_cli2ost $flavor`
4519 res=$((res1 + res2))
4520 elif [ $dir == "all2mdt" ]; then
4521 res1=`flvr_cnt_mdt2mdt $flavor`
4522 res2=`flvr_cnt_cli2mdt $flavor`
4523 res=$((res1 + res2))
4524 elif [ $dir == "all2all" ]; then
4525 res1=`flvr_cnt_mdt2ost $flavor`
4526 res2=`flvr_cnt_cli2ost $flavor`
4527 res3=`flvr_cnt_mdt2mdt $flavor`
4528 res4=`flvr_cnt_cli2mdt $flavor`
4529 res=$((res1 + res2 + res3 + res4))
4537 local dir=$1 # from to
4538 local flavor=$2 # flavor expected
4539 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
4543 for ((i=0;i<20;i++)); do
4544 echo -n "checking $dir..."
4545 res=$(do_check_flavor $dir $flavor)
4546 echo "found $res/$expect $flavor connections"
4547 [ $res -eq $expect ] && return 0
4551 echo "Error checking $flavor of $dir: expect $expect, actual $res"
4555 restore_to_default_flavor()
4557 local proc="mgs.MGS.live.$FSNAME"
4559 echo "restoring to default flavor..."
4561 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4563 # remove all existing rules if any
4564 if [ $nrule -ne 0 ]; then
4565 echo "$nrule existing rules"
4566 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
4567 echo "remove rule: $rule"
4568 spec=`echo $rule | awk -F = '{print $1}'`
4569 do_facet mgs "$LCTL conf_param -d $spec"
4573 # verify no rules left
4574 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
4575 [ $nrule -ne 0 ] && error "still $nrule rules left"
4577 # wait for default flavor to be applied
4578 # currently default flavor for all connections are 'null'
4579 wait_flavor all2all null
4580 echo "now at default flavor settings"
4585 local flavor=${1:-null}
4587 echo "setting all flavor to $flavor"
4589 # FIXME need parameter to this fn
4590 # and remove global vars
4591 local cnt_all2all=$(calc_connection_cnt all2all)
4593 local res=$(do_check_flavor all2all $flavor)
4594 if [ $res -eq $cnt_all2all ]; then
4595 echo "already have total $res $flavor connections"
4599 echo "found $res $flavor out of total $cnt_all2all connections"
4600 restore_to_default_flavor
4602 [[ $flavor = null ]] && return 0
4604 set_rule $FSNAME any any $flavor
4605 wait_flavor all2all $flavor
4611 # Checking for shared logdir
4612 if [ ! -d $dir ]; then
4613 # Not found. Create local logdir
4616 touch $dir/node.$(hostname -s).yml
4621 check_write_access() {
4623 for node in $(nodes_list); do
4624 if [ ! -f "$dir/node.$(short_hostname ${node}).yml" ]; then
4625 # Logdir not accessible/writable from this node.
4633 if [[ -n $YAML_LOG ]]; then
4636 local SAVE_UMASK=`umask`
4639 export YAML_LOG=${LOGDIR}/results.yml
4643 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $LOGDIR
4644 if check_write_access $LOGDIR; then
4645 touch $LOGDIR/shared
4646 echo "Logging to shared log directory: $LOGDIR"
4648 echo "Logging to local directory: $LOGDIR"
4651 yml_nodes_file $LOGDIR >> $YAML_LOG
4652 yml_results_file >> $YAML_LOG
4658 yml_log_test $1 >> $YAML_LOG
4662 yml_log_test_status $@ >> $YAML_LOG
4665 log_sub_test_begin() {
4666 yml_log_sub_test_begin "$@" >> $YAML_LOG
4669 log_sub_test_end() {
4670 yml_log_sub_test_end "$@" >> $YAML_LOG
4676 local llverdev_opts=$2
4677 local devname=$(basename $1)
4678 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
4679 # loop devices aren't in /proc/partitions
4680 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
4682 size=$(($size / 1024 / 1024)) # Gb
4684 local partial_arg=""
4685 # Run in partial (fast) mode if the size
4686 # of a partition > 1 GB
4687 [ $size -gt 1 ] && partial_arg="-p"
4689 llverdev --force $partial_arg $llverdev_opts $dev
4695 local llverfs_opts=$2
4696 local partial_arg=""
4697 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
4699 # Run in partial (fast) mode if the size
4700 # of a partition > 1 GB
4701 [ $size -gt 1 ] && partial_arg="-p"
4703 llverfs $partial_arg $llverfs_opts $dir
4706 remove_mdt_files() {
4711 local mntpt=$(facet_mntpt $facet)
4713 echo "removing files from $mdtdev on $facet: $files"
4714 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4717 rm $mntpt/ROOT/$f || { rc=$?; break; }
4719 umount -f $mntpt || return $?
4723 duplicate_mdt_files() {
4728 local mntpt=$(facet_mntpt $facet)
4730 echo "duplicating files on $mdtdev on $facet: $files"
4731 mkdir -p $mntpt || return $?
4732 mount -t $FSTYPE $MDS_MOUNT_OPTS $mdtdev $mntpt || return $?
4742 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
4743 pushd $mntpt/ROOT > /dev/null || return $?
4746 touch $f.bad || return $?
4747 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
4749 [ $rc -eq 0 ] || return $rc
4750 setfattr --restore $tmp || return $?
4756 local devs=${1//,/ }
4759 local rslt=$TMP/sgpdd_survey
4761 # sgpdd-survey cleanups ${rslt}.* files
4763 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
4769 # returns the canonical name for an ldiskfs device
4774 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
4775 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
4776 echo dm-\\\${foo##*:};
4778 echo \\\$(basename \\\$dv);
4782 is_sanity_benchmark() {
4783 local benchmarks="dbench bonnie iozone fsx"
4785 for b in $benchmarks; do
4786 if [ "$b" == "$suite" ]; then
4794 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
4797 # Get the block size of the filesystem.
4803 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
4804 awk '/^Block size:/ {print $3}')
4808 # Check whether the "large_xattr" feature is enabled or not.
4809 large_xattr_enabled() {
4810 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4812 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
4813 return ${PIPESTATUS[0]}
4816 # Get the maximum xattr size supported by the filesystem.
4820 if large_xattr_enabled; then
4821 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
4824 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4825 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
4827 # maximum xattr size = size of block - size of header -
4828 # size of 1 entry - 4 null bytes
4829 size=$((block_size - 32 - 32 - 4))
4835 # Dump the value of the named xattr from a file.
4840 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
4843 # Generate a string with size of $size bytes.
4845 local size=${1:-1024} # in bytes
4847 echo "$(head -c $size < /dev/zero | tr '\0' y)"