3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
18 # specify environment variable containing batch job name for server statistics
19 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
21 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
22 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
23 export LOAD_LLOOP=${LOAD_LLOOP:-false}
25 #export PDSH="pdsh -S -Rssh -w"
26 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
55 [[ $DIR/ = $MOUNT/* ]] || \
56 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
57 [[ $DIR1/ = $MOUNT1/* ]] || \
58 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
59 [[ $DIR2/ = $MOUNT2/* ]] || \
60 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
62 [ -n "$failed" ] && exit 99 || true
66 echo "usage: $0 [-r] [-f cfgfile]"
74 [ "$TESTSUITE" == "lfsck" ] && return 0
75 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
77 local form="%-13s %-17s %-9s %s %s\n"
78 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
79 echo "------------------------------------------------------------------------------------"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 [ "${!O}" = "no" ] && continue || true
83 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
84 local log=${TMP}/${o}.log
85 if is_sanity_benchmark $o; then
86 log=${TMP}/sanity-benchmark.log
91 local status=Unfinished
93 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
95 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
96 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
97 total=$(grep duration $log | awk '{ print $2 }')
98 if [ "${!O}" = "done" ]; then
102 local durations=$(egrep "^PASS|^FAIL" $log |
103 tr -d "("| sed s/s\)$//g |
104 awk '{ print $2":"$3"|" }')
105 details=$(printf "%s\n%s %s %s\n" "$details" \
106 "DDETAILS" "$O" "$(echo $durations)")
109 printf "$form" $status "$O" "${total}" "E=$skipped"
110 printf "$form" "-" "-" "-" "S=$(echo $slow)"
113 for O in $DEFAULT_SUITES; do
114 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
115 if [ "${!O}" = "no" ]; then
116 printf "$form" "Skipped" "$O" ""
120 # print the detailed tests durations if DDETAILS=true
127 export LUSTRE=$(absolute_path $LUSTRE)
128 export TESTSUITE=$(basename $0 .sh)
129 export TEST_FAILED=false
130 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
131 export RPC_MODE=${RPC_MODE:-false}
133 export MKE2FS=$MKE2FS
134 if [ -z "$MKE2FS" ]; then
135 if which mkfs.ldiskfs >/dev/null 2>&1; then
136 export MKE2FS=mkfs.ldiskfs
142 export DEBUGFS=$DEBUGFS
143 if [ -z "$DEBUGFS" ]; then
144 if which debugfs.ldiskfs >/dev/null 2>&1; then
145 export DEBUGFS=debugfs.ldiskfs
147 export DEBUGFS=debugfs
151 export TUNE2FS=$TUNE2FS
152 if [ -z "$TUNE2FS" ]; then
153 if which tunefs.ldiskfs >/dev/null 2>&1; then
154 export TUNE2FS=tunefs.ldiskfs
156 export TUNE2FS=tune2fs
160 export E2LABEL=$E2LABEL
161 if [ -z "$E2LABEL" ]; then
162 if which label.ldiskfs >/dev/null 2>&1; then
163 export E2LABEL=label.ldiskfs
165 export E2LABEL=e2label
169 export DUMPE2FS=$DUMPE2FS
170 if [ -z "$DUMPE2FS" ]; then
171 if which dumpfs.ldiskfs >/dev/null 2>&1; then
172 export DUMPE2FS=dumpfs.ldiskfs
174 export DUMPE2FS=dumpe2fs
178 export E2FSCK=$E2FSCK
179 if [ -z "$E2FSCK" ]; then
180 if which fsck.ldiskfs >/dev/null 2>&1; then
181 export E2FSCK=fsck.ldiskfs
187 export RESIZE2FS=$RESIZE2FS
188 if [ -z "$RESIZE2FS" ]; then
189 if which resizefs.ldiskfs >/dev/null 2>&1; then
190 export RESIZE2FS=resizefs.ldiskfs
192 export RESIZE2FS=resize2fs
196 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
197 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
198 export FSCK_MAX_ERR=4 # File system errors left uncorrected
200 export ZFS=${ZFS:-zfs}
201 export ZPOOL=${ZPOOL:-zpool}
202 export ZDB=${ZDB:-zdb}
203 export PARTPROBE=${PARTPROBE:-partprobe}
205 #[ -d /r ] && export ROOT=${ROOT:-/r}
206 export TMP=${TMP:-$ROOT/tmp}
207 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
208 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
209 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
211 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
212 if ! echo $PATH | grep -q $LUSTRE/utils; then
213 export PATH=$LUSTRE/utils:$PATH
215 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
216 export PATH=$LUSTRE/utils/gss:$PATH
218 if ! echo $PATH | grep -q $LUSTRE/tests; then
219 export PATH=$LUSTRE/tests:$PATH
221 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
222 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
224 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
225 [ ! -f "$LST" ] && export LST=$(which lst)
226 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
227 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
228 export MCREATE=${MCREATE:-mcreate}
229 # Ubuntu, at least, has a truncate command in /usr/bin
230 # so fully path our truncate command.
231 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
232 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
233 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
234 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
235 export PATH=$LUSTRE/tests/racer:$PATH:
237 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
238 export PATH=$LUSTRE/tests/mpi:$PATH
240 export RSYNC_RSH=${RSYNC_RSH:-rsh}
242 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
243 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
244 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
245 [ ! -f "$LFS" ] && export LFS=$(which lfs)
246 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
247 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
249 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
250 if [ ! -f "$L_GETIDENTITY" ]; then
251 if `which l_getidentity > /dev/null 2>&1`; then
252 export L_GETIDENTITY=$(which l_getidentity)
254 export L_GETIDENTITY=NONE
257 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
258 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
259 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
260 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
261 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
262 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
263 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
264 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
265 [ ! -f "$LUSTRE_RMMOD" ] &&
266 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
267 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
268 [ ! -f "$LFS_MIGRATE" ] &&
269 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
270 export NAME=${NAME:-local}
271 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
272 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
273 export LGSSD=$(which lgssd)
274 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
275 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
276 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
278 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
281 if [ "$ACCEPTOR_PORT" ]; then
282 export PORT_OPT="--port $ACCEPTOR_PORT"
287 echo "Using GSS/krb5 ptlrpc security flavor"
288 which lgss_keyring > /dev/null 2>&1 || \
289 error_exit "built with gss disabled! SEC=$SEC"
300 IDENTITY_UPCALL=false
304 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
306 # Paths on remote nodes, if different
307 export RLUSTRE=${RLUSTRE:-$LUSTRE}
308 export RPWD=${RPWD:-$PWD}
309 export I_MOUNTED=${I_MOUNTED:-"no"}
310 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
311 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
312 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
313 ! -f $LUSTRE/mdt/mdt.ko ]; then
314 export CLIENTMODSONLY=yes
317 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
318 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
322 while getopts "rvwf:" opt $*; do
325 r) REFORMAT=--reformat;;
327 w) WRITECONF=writeconf;;
332 shift $((OPTIND - 1))
335 # print the durations of each test if "true"
336 DDETAILS=${DDETAILS:-false}
337 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
347 ncpts=$(do_facet $facet "lctl get_param -n " \
348 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
350 if [ $ncpts -eq 0 ]; then
357 # Return a numeric version code based on a version string. The version
358 # code is useful for comparison two version strings to see which is newer.
360 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
361 eval set -- $(tr "[:punct:]" " " <<< $*)
363 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
366 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
367 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
369 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
371 # usage: lustre_build_version
373 # All Lustre versions support "lctl get_param" to report the version of the
374 # code running in the kernel (what our tests are interested in), but it
375 # doesn't work without modules loaded. If that fails, use "lctl version"
376 # instead, which is easy to parse and works without the kernel modules,
377 # but was only added in 2.6.50. If that also fails, fall back to calling
378 # "lctl lustre_build_version" which prints either (or both) the userspace
379 # and kernel build versions, but is deprecated and should eventually be
382 # output: prints version string to stdout in dotted-decimal format
383 lustre_build_version() {
384 local facet=${1:-client}
387 # kernel: patchless_client
388 # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
389 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
390 awk '/lustre: / { print $2 }')
392 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
394 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
395 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
396 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
397 awk '/version:/ { print $3; exit; }')
398 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
401 # Report the Lustre numeric build version code for the supplied facet.
402 lustre_version_code() {
403 version_code $(lustre_build_version $1)
407 /sbin/lsmod | grep -q "^\<$1\>"
410 # Load a module on the system where this is running.
412 # usage: load_module module_name [module arguments for insmod/modprobe]
414 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
415 # will be used as the arguments. Otherwise arguments will be obtained from
416 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
423 BASE=$(basename $module $EXT)
425 module_loaded ${BASE} && return
427 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
428 # else from modprobe.conf
429 if [ $# -eq 0 ]; then
430 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
431 # Bash until 4.x, so we resort to eval.
432 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
433 eval set -- \$$optvar
434 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
435 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
437 opt=$(awk -v var="^options $BASE" '$0 ~ var \
438 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
439 set -- $(echo -n $opt)
441 # Ensure we have accept=all for lnet
442 if [ $(basename $module) = lnet ]; then
443 # OK, this is a bit wordy...
444 local arg accept_all_present=false
447 [ "$arg" = accept=all ] && \
448 accept_all_present=true
450 $accept_all_present || set -- "$@" accept=all
456 [ $# -gt 0 ] && echo "${module} options: '$*'"
458 # Note that insmod will ignore anything in modprobe.conf, which is why
459 # we're passing options on the command-line.
460 if [[ "$BASE" == "lnet_selftest" ]] &&
461 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
462 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
463 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
464 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
465 insmod ${LUSTRE}/${module}${EXT} "$@"
467 # must be testing a "make install" or "rpm" installation
468 # note failed to load ptlrpc_gss is considered not fatal
469 if [[ "$BASE" == "ptlrpc_gss" ]]; then
470 modprobe $BASE "$@" 2>/dev/null ||
471 echo "gss/krb5 is not supported"
478 llite_lloop_enabled() {
479 local n1=$(uname -r | cut -d. -f1)
480 local n2=$(uname -r | cut -d. -f2)
481 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
483 # load the llite_lloop module for < 2.6.32 kernels
484 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
485 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
492 load_modules_local() {
493 if [ -n "$MODPROBE" ]; then
495 echo "Using modprobe to load modules"
499 echo Loading modules from $LUSTRE
503 if [ -f /sys/devices/system/cpu/online ]; then
504 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
505 echo "detected $ncpus online CPUs by sysfs"
507 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
509 if [ $rc -eq 0 ]; then
510 echo "detected $ncpus online CPUs by getconf"
512 echo "Can't detect number of CPUs"
517 # if there is only one CPU core, libcfs can only create one partition
518 # if there is more than 4 CPU cores, libcfs should create multiple CPU
519 # partitions. So we just force libcfs to create 2 partitions for
520 # system with 2 or 4 cores
521 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
522 # force to enable multiple CPU partitions
523 echo "Force libcfs to create 2 CPU partitions"
524 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
526 echo "libcfs will create CPU partition based on online CPUs"
529 load_module ../libcfs/libcfs/libcfs
531 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
532 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
533 load_module ../lnet/lnet/lnet
536 LNETLND="o2iblnd/ko2iblnd"
541 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
542 load_module ../lnet/klnds/$LNETLND
543 load_module obdclass/obdclass
544 load_module ptlrpc/ptlrpc
545 load_module ptlrpc/gss/ptlrpc_gss
553 load_module obdecho/obdecho
554 if ! client_only; then
555 SYMLIST=/proc/kallsyms
556 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
557 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
558 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
559 load_module lfsck/lfsck
560 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
561 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
563 load_module osd-zfs/osd_zfs
565 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
566 grep -q exportfs_decode_fh $SYMLIST ||
567 { modprobe exportfs 2> /dev/null || true; }
568 load_module ../ldiskfs/ldiskfs
569 load_module osd-ldiskfs/osd_ldiskfs
581 load_module llite/lustre
582 llite_lloop_enabled && load_module llite/llite_lloop
583 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
585 rm -f $OGDB/ogdb-$HOSTNAME
586 $LCTL modules > $OGDB/ogdb-$HOSTNAME
588 # 'mount' doesn't look in $PATH, just sbin
589 local mount_lustre=$LUSTRE/utils/mount.lustre
590 if [ -f $mount_lustre ]; then
591 local sbin_mount=/sbin/mount.lustre
592 if grep -qw "$sbin_mount" /proc/mounts; then
593 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
595 if ! grep -qw "$sbin_mount" /proc/mounts; then
596 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
597 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
598 cat <<- EOF > "$sbin_mount"
601 echo "This $sbin_mount just a mountpoint." 1>&2
602 echo "It is never supposed to be run." 1>&2
603 logger -p emerg -- "using stub $sbin_mount $@"
606 chmod a+x $sbin_mount
608 mount --bind $mount_lustre $sbin_mount ||
609 error "can't bind $mount_lustre to $sbin_mount"
617 # load modules on remote nodes optionally
618 # lustre-tests have to be installed on these nodes
619 if $LOAD_MODULES_REMOTE; then
620 local list=$(comma_list $(remote_nodes_list))
621 if [ -n "$list" ]; then
622 echo "loading modules on: '$list'"
623 do_rpc_nodes "$list" load_modules_local
629 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
630 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
631 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
632 echo "$LEAK_LUSTRE" 1>&2
633 echo "$LEAK_PORTALS" 1>&2
634 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
635 echo "Memory leaks detected"
636 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
642 wait_exit_ST client # bug 12845
644 $LUSTRE_RMMOD ldiskfs || return 2
646 if $LOAD_MODULES_REMOTE; then
647 local list=$(comma_list $(remote_nodes_list))
648 if [ -n "$list" ]; then
649 echo "unloading modules on: '$list'"
650 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
651 do_rpc_nodes "$list" check_mem_leak
655 local sbin_mount=/sbin/mount.lustre
656 if grep -qe "$sbin_mount " /proc/mounts; then
657 umount $sbin_mount || true
658 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
662 check_mem_leak || return 254
664 echo "modules unloaded."
669 local facet=${1:-$SINGLEMDS}
670 local fstype=$(facet_fstype $facet)
673 ldiskfs) size=50;; # largest seen is 44, leave some headroom
674 zfs) size=400;; # largest seen is 384
680 check_gss_daemon_nodes() {
684 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
685 if [ \\\"\\\$num\\\" -ne 1 ]; then
686 echo \\\$num instance of $dname;
691 check_gss_daemon_facet() {
695 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
696 if [ $num -ne 1 ]; then
697 echo "$num instance of $dname on $facet"
706 echo Stopping $@ on $list
707 do_nodes $list "killall -2 $@ 2>/dev/null || true"
710 # start gss daemons on all nodes, or
711 # "daemon" on "list" if set
712 start_gss_daemons() {
716 if [ "$list" ] && [ "$daemon" ] ; then
717 echo "Starting gss daemon on nodes: $list"
718 do_nodes $list "$daemon" || return 8
722 local list=$(comma_list $(mdts_nodes))
723 echo "Starting gss daemon on mds: $list"
724 do_nodes $list "$LSVCGSSD -v" || return 1
726 do_nodes $list "$LGSSD -v" || return 2
729 list=$(comma_list $(osts_nodes))
730 echo "Starting gss daemon on ost: $list"
731 do_nodes $list "$LSVCGSSD -v" || return 3
732 # starting on clients
734 local clients=${CLIENTS:-`hostname`}
736 echo "Starting $LGSSD on clients $clients "
737 do_nodes $clients "$LGSSD -v" || return 4
740 # wait daemons entering "stable" status
744 # check daemons are running
746 list=$(comma_list $(mdts_nodes) $(osts_nodes))
747 check_gss_daemon_nodes $list lsvcgssd || return 5
749 list=$(comma_list $(mdts_nodes))
750 check_gss_daemon_nodes $list lgssd || return 6
753 check_gss_daemon_nodes $clients lgssd || return 7
758 local list=$(comma_list $(mdts_nodes))
760 send_sigint $list lsvcgssd lgssd
762 list=$(comma_list $(osts_nodes))
763 send_sigint $list lsvcgssd
765 list=${CLIENTS:-`hostname`}
766 send_sigint $list lgssd
771 if ! module_loaded ptlrpc_gss; then
772 load_module ptlrpc/gss/ptlrpc_gss
773 module_loaded ptlrpc_gss ||
774 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
777 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
780 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
782 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
790 # maybe cleanup credential cache?
796 local var=${facet}_svc
804 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
805 tr '[:lower:]' '[:upper:]'
811 if [ $facet == mgs ]; then
815 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
823 if [ -n "${!var}" ]; then
828 var=$(facet_type $facet)FSTYPE
829 if [ -n "${!var}" ]; then
834 if [ -n "$FSTYPE" ]; then
839 if [[ $facet == mgs ]] && combined_mgs_mds; then
851 local facets=$(get_facets)
854 for facet in ${facets//,/ }; do
855 if [ $node == $(facet_host $facet) ] ||
856 [ $node == "$(facet_failover_host $facet)" ]; then
857 fstype=$(facet_fstype $facet)
858 if [[ $fstypes != *$fstype* ]]; then
859 fstypes+="${fstypes:+,}$fstype"
868 local num=$(facet_number $facet)
871 if [[ $(facet_type $facet) = OST ]]; then
873 if [[ -n "${!index}" ]]; then
878 index=${OST_INDICES[num - 1]}
881 [[ -n "$index" ]] || index=$((num - 1))
889 local fstype=$(facet_fstype $facet)
893 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
895 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
896 ${dev} 2>/dev/null");;
898 error "unknown fstype!";;
906 local device=$(mdsdevname $num)
907 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
913 local device=$(ostdevname $num)
914 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
919 # Get the device of a facet.
926 mgs) device=$(mgsdevname) ;;
927 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
928 ost*) device=$(ostdevname $(facet_number $facet)) ;;
929 fs2mds) device=$(mdsdevname 1_2) ;;
930 fs2ost) device=$(ostdevname 1_2) ;;
931 fs3ost) device=$(ostdevname 2_2) ;;
939 # Get the virtual device of a facet.
946 mgs) device=$(mgsvdevname) ;;
947 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
948 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
949 fs2mds) device=$(mdsvdevname 1_2) ;;
950 fs2ost) device=$(ostvdevname 1_2) ;;
951 fs3ost) device=$(ostvdevname 2_2) ;;
959 # Re-read the partition table on failover partner host.
960 # After a ZFS storage pool is created on a shared device, the partition table
961 # on the device may change. However, the operating system on the failover
962 # host may not notice the change automatically. Without the up-to-date partition
963 # block devices, 'zpool import ..' cannot find the labels, whose positions are
964 # relative to partition rather than disk beginnings.
966 # This function performs partprobe on the failover host to make it re-read the
969 refresh_partition_table() {
974 host=$(facet_passive_host $facet)
975 if [[ -n "$host" ]]; then
976 do_node $host "$PARTPROBE $device"
981 # Get ZFS storage pool name.
988 device=$(facet_device $facet)
989 # poolname is string before "/"
990 poolname="${device%%/*}"
996 # Create ZFS storage pool.
1003 local opts=${@:-"-o cachefile=none"}
1005 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1006 $ZPOOL create -f $opts $poolname $vdev"
1010 # Create ZFS file system.
1016 local opts=${@:-"-o mountpoint=legacy"}
1018 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1019 $ZFS create $opts $dataset"
1023 # Export ZFS storage pool.
1024 # Before exporting the pool, all datasets within the pool should be unmounted.
1032 poolname=$(zpool_name $facet)
1034 if [[ -n "$poolname" ]]; then
1035 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1036 grep -q ^$poolname/ /proc/mounts ||
1037 $ZPOOL export $opts $poolname"
1042 # Destroy ZFS storage pool.
1043 # Destroy the given pool and free up any devices for other use. This command
1044 # tries to unmount any active datasets before destroying the pool.
1045 # -f Force any active datasets contained within the pool to be unmounted.
1049 local poolname=${2:-$(zpool_name $facet)}
1051 if [[ -n "$poolname" ]]; then
1052 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1053 $ZPOOL destroy -f $poolname"
1058 # Import ZFS storage pool.
1059 # Force importing, even if the pool appears to be potentially active.
1064 local opts=${@:-"-o cachefile=none"}
1067 poolname=$(zpool_name $facet)
1069 if [[ -n "$poolname" ]]; then
1070 opts+=" -d $(dirname $(facet_vdevice $facet))"
1071 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1072 $ZPOOL import -f $opts $poolname"
1077 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1078 # is not automatically imported on system startup.
1080 # In a failover environment, this will provide resource level fencing which
1081 # will ensure that the same ZFS storage pool will not be imported concurrently
1082 # on different nodes.
1084 disable_zpool_cache() {
1088 poolname=$(zpool_name $facet)
1090 if [[ -n "$poolname" ]]; then
1091 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1096 # This and set_osd_param() shall be used to access OSD parameters
1097 # once existed under "obdfilter":
1102 # writethrough_cache_enable
1106 local device=${2:-$FSNAME-OST*}
1109 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1110 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1115 local device=${2:-$FSNAME-OST*}
1119 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1120 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1124 local dz=${1:-$DEBUG_SIZE}
1126 if [ -f /sys/devices/system/cpu/possible ]; then
1127 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1129 local cpus=$(getconf _NPROCESSORS_CONF)
1132 # bug 19944, adjust size to be -gt num_possible_cpus()
1133 # promise 2MB for every cpu at least
1134 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1137 lctl set_param debug_mb=$dz
1140 set_default_debug () {
1141 local debug=${1:-"$PTLDEBUG"}
1142 local subsys=${2:-"$SUBSYSTEM"}
1143 local debug_size=${3:-$DEBUG_SIZE}
1145 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1146 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1148 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1151 set_default_debug_nodes () {
1154 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1155 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1159 do_rpc_nodes "$nodes" set_default_debug \
1160 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1163 set_default_debug_facet () {
1165 local node=$(facet_active_host $facet)
1166 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1168 set_default_debug_nodes $node
1173 local facets=${1:-$(get_facets)}
1176 for facet in ${facets//,/ }; do
1179 [ $RC -eq 0 ] && continue
1181 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1182 skip "Restart of $facet failed!." && touch $LU482_FAILED
1184 error "Restart of $facet failed!"
1191 # Add argument "arg" (e.g., "loop") to the comma-separated list
1192 # of arguments for option "opt" (e.g., "-o") on command
1193 # line "opts" (e.g., "-o flock").
1199 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1201 if echo "$opts" | grep -q $opt_pattern; then
1202 opts=$(echo "$opts" | sed -e \
1203 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1205 opts+="${opts:+ }$opt $arg"
1213 local dev=$(facet_active $facet)_dev
1214 local opt=${facet}_opt
1215 local mntpt=$(facet_mntpt $facet)
1216 local opts="${!opt} $@"
1218 if [ $(facet_fstype $facet) == ldiskfs ] &&
1219 ! do_facet $facet test -b ${!dev}; then
1220 opts=$(csa_add "$opts" -o loop)
1223 if [[ $(facet_fstype $facet) == zfs ]]; then
1224 # import ZFS storage pool
1225 import_zpool $facet || return ${PIPESTATUS[0]}
1228 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1229 # for testing LU-482 error handling in mount_facets() and test_0a()
1230 if [ -f $TMP/test-lu482-trigger ]; then
1233 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1237 if [ $RC -ne 0 ]; then
1238 echo "Start of ${!dev} on ${facet} failed ${RC}"
1240 set_default_debug_facet $facet
1242 if [[ $facet == mds* ]]; then
1244 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1248 label=$(devicelabel ${facet} ${!dev})
1249 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1250 eval export ${facet}_svc=${label}
1251 echo Started ${label}
1256 # start facet device options
1262 eval export ${facet}_dev=${device}
1263 eval export ${facet}_opt=\"$@\"
1265 local varname=${facet}failover_dev
1266 if [ -n "${!varname}" ] ; then
1267 eval export ${facet}failover_dev=${!varname}
1269 eval export ${facet}failover_dev=$device
1272 local mntpt=$(facet_mntpt $facet)
1273 do_facet ${facet} mkdir -p $mntpt
1274 eval export ${facet}_MOUNT=$mntpt
1275 mount_facet ${facet}
1278 if [[ $facet == mds* ]]; then
1280 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1291 local HOST=`facet_active_host $facet`
1292 [ -z $HOST ] && echo stop: no host for $facet && return 0
1294 local mntpt=$(facet_mntpt $facet)
1295 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1296 if [ ${running} -ne 0 ]; then
1297 echo "Stopping $mntpt (opts:$@) on $HOST"
1298 do_facet ${facet} umount -d $@ $mntpt
1301 # umount should block, but we should wait for unrelated obd's
1302 # like the MGS or MGC to also stop.
1303 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1305 if [[ $(facet_fstype $facet) == zfs ]]; then
1306 # export ZFS storage pool
1311 # save quota version (both administrative and operational quotas)
1312 # add an additional parameter if mountpoint is ever different from $MOUNT
1314 # XXX This function is kept for interoperability with old server (< 2.3.50),
1315 # it should be removed whenever we drop the interoperability for such
1317 quota_save_version() {
1318 local fsname=${2:-$FSNAME}
1320 local ver=$(tr -c -d "123" <<< $spec)
1321 local type=$(tr -c -d "ug" <<< $spec)
1323 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1325 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1327 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1329 local osts=$(get_facets OST)
1330 for ost in ${osts//,/ }; do
1332 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1336 # client could mount several lustre
1338 # XXX This function is kept for interoperability with old server (< 2.3.50),
1339 # it should be removed whenever we drop the interoperability for such
1342 local fsname=${1:-$FSNAME}
1344 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1346 do_nodes $(comma_list $(osts_nodes)) \
1347 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1351 # XXX This function is kept for interoperability with old server (< 2.3.50),
1352 # it should be removed whenever we drop the interoperability for such
1354 restore_quota_old() {
1355 local mntpt=${1:-$MOUNT}
1356 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1357 if [ ! "$old_QUOTA_TYPE" ] ||
1358 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1361 quota_save_version $old_QUOTA_TYPE
1364 # XXX This function is kept for interoperability with old server (< 2.3.50),
1365 # it should be removed whenever we drop the interoperability for such
1370 # no quota enforcement for now and accounting works out of the box
1373 # We need save the original quota_type params, and restore them after testing
1375 # Suppose that quota type the same on mds and ost
1376 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1377 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1378 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1379 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1380 export old_QUOTA_TYPE=$quota_type
1381 quota_save_version $QUOTA_TYPE
1383 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1384 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1387 local quota_usrs=$QUOTA_USERS
1389 # get_filesystem_size
1390 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1391 local blk_soft=$((disksz + 1024))
1392 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1394 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1395 local i_soft=$Inodes
1396 local i_hard=$((i_soft + i_soft / 20))
1398 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1399 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1402 for usr in $quota_usrs; do
1403 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1405 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1407 eval $cmd || error "$cmd FAILED!"
1409 # display the quota status
1410 echo "Quota settings for $usr : "
1411 $LFS quota -v -u $usr $mntpt || true
1415 # get mdt quota type
1417 local varsvc=${SINGLEMDS}_svc
1418 do_facet $SINGLEMDS $LCTL get_param -n \
1419 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1422 # get ost quota type
1424 # All OSTs should have same quota type
1425 local varsvc=ost1_svc
1426 do_facet ost1 $LCTL get_param -n \
1427 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1430 # restore old quota type settings
1432 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1437 if [ "$old_MDT_QUOTA_TYPE" ]; then
1438 do_facet mgs $LCTL conf_param \
1439 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1441 if [ "$old_OST_QUOTA_TYPE" ]; then
1442 do_facet mgs $LCTL conf_param \
1443 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1447 # Handle the case when there is a space in the lfs df
1448 # "filesystem summary" line the same as when there is no space.
1449 # This will allow fixing the "lfs df" summary line in the future.
1451 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1454 # Get free inodes on the MDT specified by mdt index, free indoes on
1455 # the whole filesystem will be returned when index == -1.
1461 if [ $index -eq -1 ]; then
1464 mdt_uuid=$(mdtuuid_from_index $index)
1467 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1472 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1479 # save old quota type & set new quota type
1480 local mdt_qtype=$(mdt_quota_type)
1481 local ost_qtype=$(ost_quota_type)
1483 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1484 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1486 export old_MDT_QUOTA_TYPE=$mdt_qtype
1487 export old_OST_QUOTA_TYPE=$ost_qtype
1489 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1490 error "set mdt quota type failed"
1491 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1492 error "set ost quota type failed"
1494 local quota_usrs=$QUOTA_USERS
1496 # get_filesystem_size
1497 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1498 local blk_soft=$((disksz + 1024))
1499 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1501 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1502 local i_soft=$inodes
1503 local i_hard=$((i_soft + i_soft / 20))
1505 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1506 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1507 "inode-hardlimit: $i_hard"
1510 for usr in $quota_usrs; do
1511 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1513 cmd="$LFS setquota -$type $usr -b $blk_soft"
1514 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1516 eval $cmd || error "$cmd FAILED!"
1518 # display the quota status
1519 echo "Quota settings for $usr : "
1520 $LFS quota -v -u $usr $mntpt || true
1527 local opts=${3:-$MOUNT_OPTS}
1528 opts=${opts:+-o $opts}
1529 local flags=${4:-$MOUNT_FLAGS}
1531 local device=$MGSNID:/$FSNAME
1532 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1533 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1537 echo "Starting client: $client: $flags $opts $device $mnt"
1538 do_node $client mkdir -p $mnt
1539 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1541 set_default_debug_nodes $client
1553 [ "$3" ] && force=-f
1554 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1555 if [ $running -ne 0 ]; then
1556 echo "Stopping client $client $mnt (opts:$force)"
1557 do_node $client lsof -t $mnt || need_kill=no
1558 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1559 pids=$(do_node $client lsof -t $mnt | sort -u);
1560 if [ -n $pids ]; then
1561 do_node $client kill -9 $pids || true
1565 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1566 if [ $busy -ne 0 ] ; then
1567 echo "$mnt is still busy, wait one second" && sleep 1
1568 do_node $client umount $force $mnt
1573 # nodes is comma list
1574 sanity_mount_check_nodes () {
1580 # FIXME: assume that all cluster nodes run the same os
1581 [ "$(uname)" = Linux ] || return 0
1584 for mnt in $mnts ; do
1585 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1586 mpts=\\\$(mount | grep -c $mnt' ');
1587 if [ \\\$running -ne \\\$mpts ]; then
1588 echo \\\$(hostname) env are INSANE!;
1591 [ $? -eq 0 ] || rc=1
1596 sanity_mount_check_servers () {
1597 [ "$CLIENTONLY" ] &&
1598 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1599 echo Checking servers environments
1601 # FIXME: modify get_facets to display all facets wo params
1602 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1606 for facet in ${facets//,/ }; do
1607 node=$(facet_host ${facet})
1608 mntpt=$(facet_mntpt $facet)
1609 sanity_mount_check_nodes $node $mntpt ||
1610 { error "server $node environments are insane!"; return 1; }
1614 sanity_mount_check_clients () {
1615 local clients=${1:-$CLIENTS}
1616 local mntpt=${2:-$MOUNT}
1617 local mntpt2=${3:-$MOUNT2}
1619 [ -z $clients ] && clients=$(hostname)
1620 echo Checking clients $clients environments
1622 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1623 error "clients environments are insane!"
1626 sanity_mount_check () {
1627 sanity_mount_check_servers || return 1
1628 sanity_mount_check_clients || return 2
1631 # mount clients if not mouted
1632 zconf_mount_clients() {
1635 local opts=${3:-$MOUNT_OPTS}
1636 opts=${opts:+-o $opts}
1637 local flags=${4:-$MOUNT_FLAGS}
1639 local device=$MGSNID:/$FSNAME
1640 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1641 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1645 echo "Starting client $clients: $flags $opts $device $mnt"
1648 running=\\\$(mount | grep -c $mnt' ');
1650 if [ \\\$running -eq 0 ] ; then
1652 $MOUNT_CMD $flags $opts $device $mnt;
1655 exit \\\$rc" || return ${PIPESTATUS[0]}
1657 echo "Started clients $clients: "
1658 do_nodes $clients "mount | grep $mnt' '"
1660 set_default_debug_nodes $clients
1665 zconf_umount_clients() {
1670 [ "$3" ] && force=-f
1672 echo "Stopping clients: $clients $mnt (opts:$force)"
1673 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1674 if [ \\\$running -ne 0 ] ; then
1675 echo Stopping client \\\$(hostname) $mnt opts:$force;
1676 lsof $mnt || need_kill=no;
1677 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1678 pids=\\\$(lsof -t $mnt | sort -u);
1679 if [ -n \\\"\\\$pids\\\" ]; then
1683 while umount $force $mnt 2>&1 | grep -q "busy"; do
1684 echo "$mnt is still busy, wait one second" && sleep 1;
1691 echo + $POWER_DOWN $node
1695 shutdown_node_hard () {
1697 local attempts=$SHUTDOWN_ATTEMPTS
1699 for i in $(seq $attempts) ; do
1702 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1703 echo "waiting for $host to fail attempts=$attempts"
1704 [ $i -lt $attempts ] || \
1705 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1711 local mnt=${2:-$MOUNT}
1714 if [ "$FAILURE_MODE" = HARD ]; then
1715 shutdown_node_hard $client
1717 zconf_umount_clients $client $mnt -f
1723 local facets="$(get_facets OST),$(get_facets MDS)"
1726 combined_mgs_mds || facets="$facets,mgs"
1728 for facet in ${facets//,/ }; do
1729 if [ $(facet_active_host $facet) == $host ]; then
1730 affected="$affected $facet"
1734 echo $(comma_list $affected)
1739 local host=${2:-$(facet_host $facet)}
1741 local label=$(convert_facet2label $facet)
1742 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1745 facets_up_on_host () {
1747 local facets=$(facets_on_host $host)
1750 for facet in ${facets//,/ }; do
1751 if $(facet_up $facet $host); then
1752 affected_up="$affected_up $facet"
1756 echo $(comma_list $affected_up)
1762 if [ "$FAILURE_MODE" = HARD ]; then
1763 shutdown_node_hard $(facet_active_host $facet)
1771 echo + $POWER_UP $node
1784 if [ "$FAILURE_MODE" = HARD ]; then
1785 reboot_node $(facet_active_host $facet)
1793 if [ "$FAILURE_MODE" = HARD ]; then
1803 for facet in ${facets//,/ }; do
1804 hosts=$(expand_list $hosts $(facet_host $facet) )
1810 _check_progs_installed () {
1814 for prog in $progs; do
1815 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1816 echo $prog missing on $(hostname)
1823 check_progs_installed () {
1827 do_rpc_nodes "$nodes" _check_progs_installed $@
1830 # recovery-scale functions
1832 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1835 start_client_load() {
1838 local var=$(node_var_name $client)_load
1839 eval export ${var}=$load
1841 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1842 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1843 END_RUN_FILE=$END_RUN_FILE \
1844 LOAD_PID_FILE=$LOAD_PID_FILE \
1845 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1846 TESTNAME=$TESTNAME \
1847 DBENCH_LIB=$DBENCH_LIB \
1848 DBENCH_SRC=$DBENCH_SRC \
1849 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1853 log "Started client load: ${load} on $client"
1855 # get the children process IDs
1856 local pids=$(ps --ppid $ppid -o pid= | xargs)
1857 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1861 start_client_loads () {
1862 local -a clients=(${1//,/ })
1863 local numloads=${#CLIENT_LOADS[@]}
1866 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1867 testnum=$((nodenum % numloads))
1868 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1870 # bug 22169: wait the background threads to start
1874 # only for remote client
1875 check_client_load () {
1877 local var=$(node_var_name $client)_load
1878 local TESTLOAD=run_${!var}.sh
1880 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1882 # bug 18914: try to connect several times not only when
1883 # check ps, but while check_catastrophe also
1886 while [ $RC = 254 -a $tries -gt 0 ]; do
1890 if ! check_catastrophe $client; then
1892 if [ $RC -eq 254 ]; then
1893 # FIXME: not sure how long we shuold sleep here
1897 echo "check catastrophe failed: RC=$RC "
1901 # We can continue try to connect if RC=254
1902 # Just print the warning about this
1903 if [ $RC = 254 ]; then
1904 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1907 # see if the load is still on the client
1910 while [ $RC = 254 -a $tries -gt 0 ]; do
1914 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1919 if [ $RC = 254 ]; then
1920 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1921 # see if we can diagnose a bit why this is
1926 check_client_loads () {
1927 local clients=${1//,/ }
1931 for client in $clients; do
1932 check_client_load $client
1934 if [ "$rc" != 0 ]; then
1935 log "Client load failed on node $client, rc=$rc"
1941 restart_client_loads () {
1942 local clients=${1//,/ }
1943 local expectedfail=${2:-""}
1947 for client in $clients; do
1948 check_client_load $client
1950 if [ "$rc" != 0 -a "$expectedfail" ]; then
1951 local var=$(node_var_name $client)_load
1952 start_client_load $client ${!var}
1953 echo "Restarted client load ${!var}: on $client. Checking ..."
1954 check_client_load $client
1956 if [ "$rc" != 0 ]; then
1957 log "Client load failed to restart on node $client, rc=$rc"
1958 # failure one client load means test fail
1959 # we do not need to check other
1968 # Start vmstat and save its process ID in a file.
1973 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1976 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1977 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1980 # Display the nodes on which client loads failed.
1981 print_end_run_file() {
1985 [ -s $file ] || return 0
1987 echo "Found the END_RUN_FILE file: $file"
1990 # A client load will stop if it finds the END_RUN_FILE file.
1991 # That does not mean the client load actually failed though.
1992 # The first node in END_RUN_FILE is the one we are interested in.
1995 if [ -n "$node" ]; then
1996 local var=$(node_var_name $node)_load
1998 local prefix=$TESTLOG_PREFIX
1999 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2000 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2001 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2003 echo "Client load ${!var} failed on node $node:"
2009 # Stop the process which had its PID saved in a file.
2014 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2016 do_nodes $nodes "test -f $pid_file &&
2017 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2020 # Stop all client loads.
2021 stop_client_loads() {
2022 local nodes=${1:-$CLIENTS}
2025 # stop the client loads
2026 stop_process $nodes $pid_file
2028 # clean up the processes that started them
2029 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2031 # End recovery-scale functions
2033 # verify that lustre actually cleaned up properly
2035 VAR=$(lctl get_param -n catastrophe 2>&1)
2036 if [ $? = 0 ] ; then
2037 if [ $VAR != 0 ]; then
2038 error "LBUG/LASSERT detected"
2041 BUSY=$(dmesg | grep -i destruct || true)
2042 if [ -n "$BUSY" ]; then
2044 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2048 check_mem_leak || exit 204
2050 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2051 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2054 if module_loaded lnet || module_loaded libcfs; then
2055 echo "$TESTSUITE: modules still loaded..." 1>&2
2064 if [[ "$1" == "--verbose" ]]; then
2079 PREV_RESULT=$(do_node $node "$TEST")
2081 RESULT=$(do_node $node "$TEST")
2082 if [[ "$RESULT" == "$FINAL" ]]; then
2083 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2084 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2088 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2089 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2093 [[ $WAIT -ge $MAX ]] && break
2094 [[ $((WAIT % print)) -eq 0 ]] &&
2095 echo "Waiting $((MAX - WAIT)) secs for update"
2096 WAIT=$((WAIT + sleep))
2099 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2103 wait_update_facet() {
2106 wait_update $(facet_active_host $facet) "$@"
2110 do_nodes $(comma_list $(mdts_nodes)) \
2111 "lctl set_param -n osd*.*MDT*.force_sync 1"
2112 do_nodes $(comma_list $(osts_nodes)) \
2113 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2114 grep -v 'Found no match'
2117 wait_delete_completed_mds() {
2118 local MAX_WAIT=${1:-20}
2119 # for ZFS, waiting more time for DMUs to be committed
2120 local ZFS_WAIT=${2:-5}
2122 local stime=$(date +%s)
2127 # find MDS with pending deletions
2128 for node in $(mdts_nodes); do
2129 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2130 2>/dev/null | calc_sum)
2131 if [[ $changes -eq 0 ]]; then
2134 mds2sync="$mds2sync $node"
2136 if [ -z "$mds2sync" ]; then
2139 mds2sync=$(comma_list $mds2sync)
2141 # sync MDS transactions
2142 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2144 # wait till all changes are sent and commmitted by OSTs
2145 # for ldiskfs space is released upon execution, but DMU
2146 # do this upon commit
2149 while [[ $WAIT -ne $MAX_WAIT ]]; do
2150 changes=$(do_nodes $mds2sync \
2151 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2152 #echo "$node: $changes changes on all"
2153 if [[ $changes -eq 0 ]]; then
2155 #echo "delete took $((etime - stime)) seconds"
2157 # the occupied disk space will be released
2158 # only after DMUs are committed
2159 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2160 echo "sleep $ZFS_WAIT for ZFS OSD"
2171 echo "Delete is not completed in $((etime - stime)) seconds"
2172 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2178 # we can use "for" here because we are waiting the slowest
2179 for host in ${hostlist//,/ }; do
2180 check_network "$host" 900
2182 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2189 for facet in ${facetlist//,/ }; do
2190 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2192 wait_for_host $hostlist
2195 _wait_recovery_complete () {
2198 # Use default policy if $2 is not passed by caller.
2199 local MAX=${2:-$(max_recovery_time)}
2204 while [ $WAIT -lt $MAX ]; do
2205 STATUS=$(lctl get_param -n $param | grep status)
2207 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2210 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2212 echo "$param recovery not done in $MAX sec. $STATUS"
2216 wait_recovery_complete () {
2219 # with an assumption that at_max is the same on all nodes
2220 local MAX=${2:-$(max_recovery_time)}
2223 if [ "$FAILURE_MODE" = HARD ]; then
2224 facets=$(facets_on_host $(facet_active_host $facet))
2226 echo affected facets: $facets
2228 # we can use "for" here because we are waiting the slowest
2229 for facet in ${facets//,/ }; do
2230 local var_svc=${facet}_svc
2231 local param="*.${!var_svc}.recovery_status"
2233 local host=$(facet_active_host $facet)
2234 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2238 wait_mds_ost_sync () {
2239 # just because recovery is done doesn't mean we've finished
2240 # orphan cleanup. Wait for llogs to get synchronized.
2241 echo "Waiting for orphan cleanup..."
2242 # MAX value includes time needed for MDS-OST reconnection
2243 local MAX=$(( TIMEOUT * 2 ))
2244 local WAIT_TIMEOUT=${1:-$MAX}
2247 local list=$(comma_list $(mdts_nodes))
2248 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2249 if ! do_facet $SINGLEMDS \
2250 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2252 # old way, use mds_sync
2254 list=$(comma_list $(osts_nodes))
2255 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2258 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2259 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2260 local -a sync=($(do_nodes $list "$cmd"))
2263 for ((i=0; i<${#sync[@]}; i++)); do
2265 [ ${sync[$i]} -eq 1 ] && continue
2267 [ ${sync[$i]} -eq 0 ] && continue
2269 # there is a not finished MDS-OST synchronization
2273 sleep 2 # increase waiting time and cover statfs cache
2274 [ ${con} -eq 1 ] && return 0
2275 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2279 # show which nodes are not finished.
2280 do_nodes $list "$cmd"
2281 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2285 wait_destroy_complete () {
2286 echo "Waiting for local destroys to complete"
2287 # MAX value shouldn't be big as this mean server responsiveness
2288 # never increase this just to make test pass but investigate
2289 # why it takes so long time
2292 while [ $WAIT -lt $MAX ]; do
2293 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2297 for ((i=0; i<${#RPCs[@]}; i++)); do
2298 [ ${RPCs[$i]} -eq 0 ] && continue
2299 # there are still some destroy RPCs in flight
2304 [ ${con} -eq 1 ] && return 0 # done waiting
2305 echo "Waiting ${WAIT}s for local destroys to complete"
2308 echo "Local destroys weren't done in $MAX sec."
2312 wait_delete_completed() {
2313 wait_delete_completed_mds $1 || return $?
2314 wait_destroy_complete
2323 # conf-sanity 31 takes a long time cleanup
2324 while [ $WAIT -lt 300 ]; do
2325 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2326 [ -z "${running}" ] && return 0
2327 echo "waited $WAIT for${running}"
2328 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2330 WAIT=$((WAIT + INTERVAL))
2332 echo "service didn't stop after $WAIT seconds. Still running:"
2337 wait_remote_prog () {
2343 [ "$PDSH" = "no_dsh" ] && return 0
2345 while [ $WAIT -lt $2 ]; do
2346 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2347 [ -z "${running}" ] && return 0 || true
2348 echo "waited $WAIT for: "
2350 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2352 WAIT=$((WAIT + INTERVAL))
2354 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2355 [ -z "$pids" ] && return 0
2356 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2357 # FIXME: not portable
2358 for pid in $pids; do
2359 cat /proc/${pid}/status || true
2360 cat /proc/${pid}/wchan || true
2362 kill -9 $pid || true
2371 # not every config has many clients
2373 if [ ! -z "$CLIENTS" ]; then
2374 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2376 stat -f $MOUNT > /dev/null
2382 # usually checked on particular client or locally
2384 if [ ! -z "$client" ]; then
2385 $PDSH $client "stat -f $MOUNT" > /dev/null
2387 stat -f $MOUNT > /dev/null
2395 client_reconnect_try() {
2396 uname -n >> $MOUNT/recon
2397 if [ -z "$CLIENTS" ]; then
2398 df $MOUNT; uname -n >> $MOUNT/recon
2400 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2402 echo Connected clients:
2404 ls -l $MOUNT/recon > /dev/null
2408 client_reconnect() {
2409 # one client_reconnect_try call does not always do the job...
2411 client_reconnect_try && break
2416 affected_facets () {
2419 local host=$(facet_active_host $facet)
2420 local affected=$facet
2422 if [ "$FAILURE_MODE" = HARD ]; then
2423 affected=$(facets_up_on_host $host)
2437 #Because it will only get up facets, we need get affected
2438 #facets before shutdown
2439 #For HARD Failure mode, it needs make sure facets on the same
2440 #HOST will only be shutdown and reboot once
2441 for facet in ${facets//,/ }; do
2442 local affected_facet
2444 #check whether facet has been included in other affected facets
2445 for ((index=0; index<$total; index++)); do
2446 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2449 if [ $skip -eq 0 ]; then
2450 affecteds[$total]=$(affected_facets $facet)
2455 for ((index=0; index<$total; index++)); do
2456 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2457 local host=$(facet_active_host $facet)
2458 echo "Failing ${affecteds[index]} on $host"
2459 shutdown_facet $facet
2462 for ((index=0; index<$total; index++)); do
2463 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2464 echo reboot facets: ${affecteds[index]}
2468 change_active ${affecteds[index]}
2470 wait_for_facet ${affecteds[index]}
2471 # start mgs first if it is affected
2472 if ! combined_mgs_mds &&
2473 list_member ${affecteds[index]} mgs; then
2474 mount_facet mgs || error "Restart of mgs failed"
2476 # FIXME; has to be changed to mount all facets concurrently
2477 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2478 echo mount facets: ${affecteds[index]}
2479 mount_facets ${affecteds[index]}
2489 do_facet $facet "sync; sync; sync"
2492 # make sure there will be no seq change
2493 local clients=${CLIENTS:-$HOSTNAME}
2494 local f=fsa-\\\$\(hostname\)
2495 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2496 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2498 local svc=${facet}_svc
2499 do_facet $facet $LCTL --device ${!svc} notransno
2501 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2502 # in-memory state has to be cleared by either rebooting the host or
2503 # exporting and reimporting the pool.
2505 # Although the uberblocks are not updated when a pool is freezed,
2506 # transactions are still written to the disks. Modified blocks may be
2507 # cached in memory when tests try reading them back. The
2508 # export-and-reimport process also evicts any cached pool data from
2509 # memory to provide the correct "data loss" semantics.
2511 # In the test framework, the exporting and importing operations are
2512 # handled by stop() and mount_facet() separately, which are used
2513 # inside fail() and fail_abort().
2515 do_facet $facet $LCTL --device ${!svc} readonly
2516 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2517 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2520 replay_barrier_nodf() {
2521 local facet=$1 echo running=${running}
2522 do_facet $facet "sync; sync; sync"
2523 local svc=${facet}_svc
2524 echo Replay barrier on ${!svc}
2525 do_facet $facet $LCTL --device ${!svc} notransno
2526 do_facet $facet $LCTL --device ${!svc} readonly
2527 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2528 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2531 replay_barrier_nosync() {
2532 local facet=$1 echo running=${running}
2533 local svc=${facet}_svc
2534 echo Replay barrier on ${!svc}
2535 do_facet $facet $LCTL --device ${!svc} notransno
2536 do_facet $facet $LCTL --device ${!svc} readonly
2537 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2538 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2542 # Get Lustre client uuid for a given Lustre mount point.
2545 local mntpnt=${1:-$MOUNT}
2547 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2548 local uuid=$($LCTL get_param -n llite.$name.uuid)
2553 mds_evict_client() {
2554 local mntpnt=${1:-$MOUNT}
2555 local uuid=$(get_client_uuid $mntpnt)
2557 do_facet $SINGLEMDS \
2558 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2561 ost_evict_client() {
2562 local mntpnt=${1:-$MOUNT}
2563 local uuid=$(get_client_uuid $mntpnt)
2566 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2571 local clients=${CLIENTS:-$HOSTNAME}
2573 facet_failover $* || error "failover: $?"
2574 wait_clients_import_state "$clients" "$facets" FULL
2575 clients_up || error "post-failover df: $?"
2580 facet_failover $facet
2586 change_active $facet
2587 wait_for_facet $facet
2588 mount_facet $facet -o abort_recovery
2589 clients_up || echo "first df failed: $?"
2590 clients_up || error "post-failover df: $?"
2594 echo There is no lmc. This is mountconf, baby.
2598 host_nids_address() {
2602 if [ -n "$kind" ]; then
2603 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2605 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2611 if [ "$1" = "'*'" ]; then echo \'*\'; else
2617 if [ "$1" = "'*'" ]; then echo \'*\'; else
2618 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2620 if [ -z "$ID" ]; then
2621 echo "Could not get a ptl id for $1..."
2630 h2name_or_ip "$1" "tcp"
2635 if [ "$1" = "'*'" ]; then echo \'*\'; else
2636 if type __h2elan >/dev/null 2>&1; then
2639 ID=`echo $1 | sed 's/[^0-9]*//g'`
2647 h2name_or_ip "$1" "o2ib"
2651 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2652 # expressions format. As a bonus we can then just pass in those variables
2653 # to pdsh. What this function does is take a HOSTLIST type string and
2654 # expand it into a space deliminated list for us.
2662 [ -z "$hostlist" ] && return
2664 # Translate the case of [..],..,[..] to [..] .. [..]
2665 list="${hostlist/],/] }"
2667 [[ "$front" == *,* ]] && {
2670 list=${list/${old}/${new}}
2673 for item in $list; do
2674 # Test if we have any []'s at all
2675 if [ "$item" != "${item/\[/}" ]; then {
2676 # Expand the [*] into list
2680 if [ "$name" != "$item" ]; then
2681 group=${item#$name[*}
2684 for range in ${group//,/ }; do
2688 # Number of leading zeros
2691 end=$(echo $end | sed 's/0*//')
2692 [[ -z "$end" ]] && end=0
2693 [[ $padlen2 -gt $padlen ]] && {
2694 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2697 begin=$(echo $begin | sed 's/0*//')
2698 [ -z $begin ] && begin=0
2700 for num in $(seq -f "%0${padlen}g" $begin $end); do
2701 value="${name#*,}${num}${back}"
2702 [ "$value" != "${value/\[/}" ] && {
2703 value=$(hostlist_expand "$value")
2705 myList="$myList $value"
2710 myList="$myList $item"
2713 myList=${myList//,/ }
2714 myList=${myList:1} # Remove first character which is a space
2716 # Filter any duplicates without sorting
2718 myList="${list%% *}"
2720 while [[ "$list" != ${myList##* } ]]; do
2721 list=${list//${list%% *} /}
2722 myList="$myList ${list%% *}"
2724 myList="${myList%* }";
2726 # We can select an object at an offset in the list
2729 for item in $myList; do
2731 [ $cnt -eq $offset ] && {
2735 [ $(get_node_count $myList) -ne 1 ] && myList=""
2744 [ "$facet" == client ] && echo -n $HOSTNAME && return
2745 varname=${facet}_HOST
2746 if [ -z "${!varname}" ]; then
2747 if [ "${facet:0:3}" == "ost" ]; then
2748 local fh=${facet%failover}_HOST
2749 eval export ${facet}_HOST=${!fh}
2750 if [ -z "${!varname}" ]; then
2751 eval export ${facet}_HOST=${ost_HOST}
2753 elif [ "${facet:0:3}" == "mdt" -o \
2754 "${facet:0:3}" == "mds" -o \
2755 "${facet:0:3}" == "mgs" ]; then
2756 eval export ${facet}_HOST=${mds_HOST}
2762 facet_failover_host() {
2766 var=${facet}failover_HOST
2767 if [ -n "${!var}" ]; then
2772 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2773 "${facet:0:3}" == "mgs" ]; then
2775 eval export ${facet}failover_host=${mds_HOST}
2780 if [[ $facet == ost* ]]; then
2781 eval export ${facet}failover_host=${ost_HOST}
2789 local activevar=${facet}active
2791 if [ -f $TMP/${facet}active ] ; then
2792 source $TMP/${facet}active
2795 active=${!activevar}
2796 if [ -z "$active" ] ; then
2803 facet_active_host() {
2804 facet_host $(facet_active $1)
2807 # Get the passive failover partner host of facet.
2808 facet_passive_host() {
2810 [[ $facet = client ]] && return
2812 local host=${facet}_HOST
2813 local failover_host=${facet}failover_HOST
2814 local active_host=$(facet_active_host $facet)
2816 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2818 if [[ $active_host = ${!host} ]]; then
2819 echo -n ${!failover_host}
2829 facetlist=$(exclude_items_from_list $facetlist mgs)
2831 for facet in ${facetlist//,/ }; do
2832 local failover=${facet}failover
2833 local host=`facet_host $failover`
2834 [ -z "$host" ] && return
2836 local curactive=`facet_active $facet`
2837 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2838 eval export ${facet}active=$facet
2840 eval export ${facet}active=$failover
2842 # save the active host for this facet
2843 local activevar=${facet}active
2844 echo "$activevar=${!activevar}" > $TMP/$activevar
2845 [[ $facet = mds1 ]] && combined_mgs_mds && \
2846 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2847 local TO=`facet_active_host $facet`
2848 echo "Failover $facet to $TO"
2854 # do not stripe off hostname if verbose, bug 19215
2855 if [ x$1 = x--verbose ]; then
2863 if [ "$HOST" = "$HOSTNAME" ]; then
2865 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2866 echo "cannot run remote command on $HOST with $myPDSH"
2870 echo "CMD: $HOST $@" >&2
2871 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2874 if [ "$myPDSH" = "rsh" ]; then
2875 # we need this because rsh does not return exit code of an executed command
2876 local command_status="$TMP/cs"
2877 rsh $HOST ":> $command_status"
2878 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2879 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2880 echo command failed >$command_status"
2881 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2886 # print HOSTNAME for myPDSH="no_dsh"
2887 if [[ $myPDSH = no_dsh ]]; then
2888 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2890 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2893 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2895 return ${PIPESTATUS[0]}
2899 do_node --verbose "$@"
2902 single_local_node () {
2903 [ "$1" = "$HOSTNAME" ]
2906 # Outputs environment variable assignments that should be passed to remote nodes
2910 local facets=$(get_facets)
2913 for var in ${!MODOPTS_*}; do
2914 value=${!var//\"/\\\"}
2915 echo -n " ${var}=\"$value\""
2918 for facet in ${facets//,/ }; do
2920 if [ -n "${!var}" ]; then
2921 echo -n " $var=${!var}"
2925 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2926 if [ -n "${!var}" ]; then
2927 echo -n " $var=${!var}"
2931 if [ -n "$FSTYPE" ]; then
2932 echo -n " FSTYPE=$FSTYPE"
2935 for var in LNETLND NETTYPE; do
2936 if [ -n "${!var}" ]; then
2937 echo -n " $var=${!var}"
2944 # do not stripe off hostname if verbose, bug 19215
2945 if [ x$1 = x--verbose ]; then
2953 if single_local_node $rnodes; then
2955 do_nodev $rnodes "$@"
2957 do_node $rnodes "$@"
2962 # This is part from do_node
2965 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2966 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2968 export FANOUT=$(get_node_count "${rnodes//,/ }")
2970 echo "CMD: $rnodes $@" >&2
2971 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2974 # do not replace anything from pdsh output if -N is used
2975 # -N Disable hostname: prefix on lines of output.
2976 if $verbose || [[ $myPDSH = *-N* ]]; then
2977 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2979 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2981 return ${PIPESTATUS[0]}
2987 local HOST=$(facet_active_host $facet)
2988 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
2992 # Function: do_facet_random_file $FACET $FILE $SIZE
2993 # Creates FILE with random content on the given FACET of given SIZE
2995 do_facet_random_file() {
2999 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3000 do_facet $facet "$cmd 2>/dev/null"
3003 do_facet_create_file() {
3007 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3008 do_facet $facet "$cmd 2>/dev/null"
3012 do_nodes --verbose "$@"
3018 # make sure its not already running
3020 rm -f $TMP/${facet}active
3021 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3022 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3024 if [[ $(facet_fstype $facet) == zfs ]]; then
3026 # After formatting a ZFS target, "cachefile=none" property will
3027 # be set on the ZFS storage pool so that the pool is not
3028 # automatically imported on system startup. And then the pool
3029 # will be exported so as to leave the importing and exporting
3030 # operations handled by mount_facet() and stop() separately.
3032 refresh_partition_table $facet $(facet_vdevice $facet)
3033 disable_zpool_cache $facet
3038 # Device formatted as ost
3041 local DEVNAME=OSTDEV$num
3043 local fstype=$(facet_fstype ost$num)
3047 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3048 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3050 #try $OSTZFSDEVn - independent of vdev
3051 DEVNAME=OSTZFSDEV$num
3052 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3054 error "unknown fstype!";;
3060 # Physical device location of data
3066 local fstype=$(facet_fstype ost$num)
3070 # vdevs are not supported by ldiskfs
3073 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3074 # Device formatted by zfs
3076 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3078 error "unknown fstype!";;
3084 # Logical device formatted for lustre
3087 local DEVNAME=MDSDEV$num
3089 local fstype=$(facet_fstype mds$num)
3093 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3094 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3096 # try $MDSZFSDEVn - independent of vdev
3097 DEVNAME=MDSZFSDEV$num
3098 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3100 error "unknown fstype!";;
3106 # Physical location of data
3110 local fstype=$(facet_fstype mds$num)
3114 # vdevs are not supported by ldiskfs
3117 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3118 # Device formatted by ZFS
3119 local DEVNAME=MDSDEV$num
3120 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3122 error "unknown fstype!";;
3130 local fstype=$(facet_fstype mgs)
3134 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3135 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3136 DEVPTR=$(mdsdevname 1)
3141 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3142 ( [ -z "$MGSZFSDEV" ] &&
3143 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3144 DEVPTR=$(mdsdevname 1)
3146 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3149 error "unknown fstype!";;
3158 local fstype=$(facet_fstype mgs)
3162 # vdevs are not supported by ldiskfs
3165 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3166 ( [ -z "$MGSDEV" ] &&
3167 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3168 VDEVPTR=$(mdsvdevname 1)
3169 elif [ -n "$MGSDEV" ]; then
3173 error "unknown fstype!";;
3181 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3183 local var=${facet}_MOUNT
3184 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3191 local dev=$(facet_device $facet)
3192 local mnt=$(facet_mntpt $facet)
3195 if ! do_facet $facet test -b $dev; then
3198 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3203 local dev=$(facet_device $facet)
3204 local mnt=$(facet_mntpt $facet)
3206 do_facet $facet umount -d $mnt
3210 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3215 local ds=$(facet_device $facet)
3216 local mnt=$(facet_mntpt $facet)
3221 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3222 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3223 do_facet $facet $ZFS set canmount=noauto $ds
3225 # The "legacy" mount method is used here because "zfs unmount $mnt"
3226 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3227 # targets are not available at the time, the stat(2) on $MOUNT will
3230 do_facet $facet $ZFS set mountpoint=legacy $ds
3231 do_facet $facet mount -t zfs $ds $mnt
3232 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3233 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3238 local ds=$(facet_device $facet)
3239 local mnt=$(facet_mntpt $facet)
3240 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3241 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3242 local mntpt=${!var_mntpt}
3243 local canmnt=${!var_canmnt}
3247 do_facet $facet umount $mnt
3248 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3249 do_facet $facet $ZFS set canmount=$canmnt $ds
3255 local fstype=$(facet_fstype $facet)
3257 mount_$fstype $facet
3262 local fstype=$(facet_fstype $facet)
3264 unmount_$fstype $facet
3271 # make sure we are using the primary server, so test-framework will
3272 # be able to clean up properly.
3273 activemds=`facet_active mds1`
3274 if [ $activemds != "mds1" ]; then
3278 local clients=$CLIENTS
3279 [ -z $clients ] && clients=$(hostname)
3281 zconf_umount_clients $clients $MOUNT "$*" || true
3282 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3284 [ "$CLIENTONLY" ] && return
3285 # The add fn does rm ${facet}active file, this would be enough
3286 # if we use do_facet <facet> only after the facet added, but
3287 # currently we use do_facet mds in local.sh
3288 for num in `seq $MDSCOUNT`; do
3290 rm -f ${TMP}/mds${num}active
3292 combined_mgs_mds && rm -f $TMP/mgsactive
3294 for num in `seq $OSTCOUNT`; do
3296 rm -f $TMP/ost${num}active
3299 if ! combined_mgs_mds ; then
3306 cleanup_echo_devs () {
3307 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3309 for dev in $devs; do
3310 $LCTL --device $dev cleanup
3311 $LCTL --device $dev detach
3316 nfs_client_mode && return
3325 combined_mgs_mds () {
3326 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3327 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3331 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3335 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3341 local fsname=${3:-"$FSNAME"}
3342 local type=$(facet_type $facet)
3343 local index=$(facet_index $facet)
3344 local fstype=$(facet_fstype $facet)
3345 local host=$(facet_host $facet)
3350 if [ $type == MGS ] || ( [ $type == MDS ] &&
3351 [ "$dev" == $(mgsdevname) ] &&
3352 [ "$host" == "$(facet_host mgs)" ] ); then
3355 opts="--mgsnode=$MGSNID"
3358 if [ $type != MGS ]; then
3359 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3363 var=${facet}failover_HOST
3364 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3365 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3368 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3369 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3371 if [ $type == MDS ]; then
3372 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3373 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3374 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3375 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3376 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3378 if [ $fstype == ldiskfs ]; then
3379 # Check for wide striping
3380 if [ $OSTCOUNT -gt 160 ]; then
3381 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3382 fs_mkfs_opts+="-O large_xattr"
3385 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3386 if [ ! -z $EJOURNAL ]; then
3387 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3389 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3393 if [ $type == OST ]; then
3394 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3395 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3397 if [ $fstype == ldiskfs ]; then
3398 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3402 opts+=" --backfstype=$fstype"
3405 if [ -n "${!var}" ]; then
3406 opts+=" --device-size=${!var}"
3409 var=$(upper $fstype)_MKFS_OPTS
3410 fs_mkfs_opts+=${!var:+" ${!var}"}
3412 var=${type}_FS_MKFS_OPTS
3413 fs_mkfs_opts+=${!var:+" ${!var}"}
3415 if [ -n "${fs_mkfs_opts## }" ]; then
3416 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3420 opts+=${!var:+" ${!var}"}
3425 check_ost_indices() {
3426 local index_count=${#OST_INDICES[@]}
3427 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3429 # OST count is greater than the index count in $OST_INDEX_LIST.
3430 # We need check whether there are duplicate indices.
3434 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3435 index=$(facet_index ost$i)
3436 for j in $(seq 0 $((index_count - 1))); do
3437 [[ $index -ne ${OST_INDICES[j]} ]] ||
3438 error "ost$i has the same index $index as ost$((j+1))"
3451 # We need ldiskfs here, may as well load them all
3453 [ "$CLIENTONLY" ] && return
3454 echo Formatting mgs, mds, osts
3455 if ! combined_mgs_mds ; then
3456 echo "Format mgs: $(mgsdevname)"
3457 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3458 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3462 for num in $(seq $MDSCOUNT); do
3463 echo "Format mds$num: $(mdsdevname $num)"
3464 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3465 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3466 ${quiet:+>/dev/null} || exit 10
3469 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3471 for num in $(seq $OSTCOUNT); do
3472 echo "Format ost$num: $(ostdevname $num)"
3473 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3474 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3475 ${quiet:+>/dev/null} || exit 10
3480 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3484 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3488 # 0: success, the old identity set already.
3489 # 1: success, the old identity does not set.
3494 local j=`expr $num - 1`
3495 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3497 if [ -z "$MDT" ]; then
3501 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3504 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3506 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3509 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3511 if [ $old = "NONE" ]; then
3520 zconf_umount `hostname` $1 || error "umount failed"
3521 zconf_mount `hostname` $1 || error "mount failed"
3529 rm -f $TMP/${facet}active
3530 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3535 local mdt_count=${1:-$MDSCOUNT}
3536 local ost_count=${2:-$OSTCOUNT}
3539 for num in $(seq $mdt_count); do
3540 DEVNAME=$(mdsdevname $num)
3541 writeconf_facet mds$num $DEVNAME || rc=$?
3544 for num in $(seq $ost_count); do
3545 DEVNAME=$(ostdevname $num)
3546 writeconf_facet ost$num $DEVNAME || rc=$?
3552 nfs_client_mode && return
3554 sanity_mount_check ||
3555 error "environments are insane!"
3559 if [ -z "$CLIENTONLY" ]; then
3560 echo Setup mgs, mdt, osts
3561 echo $WRITECONF | grep -q "writeconf" && \
3563 if ! combined_mgs_mds ; then
3564 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3567 for num in `seq $MDSCOUNT`; do
3568 DEVNAME=$(mdsdevname $num)
3569 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3571 # We started mds, now we should set failover variables properly.
3572 # Set mds${num}failover_HOST if it is not set (the default failnode).
3573 local varname=mds${num}failover_HOST
3574 if [ -z "${!varname}" ]; then
3575 eval mds${num}failover_HOST=$(facet_host mds$num)
3578 if [ $IDENTITY_UPCALL != "default" ]; then
3579 switch_identity $num $IDENTITY_UPCALL
3582 for num in `seq $OSTCOUNT`; do
3583 DEVNAME=$(ostdevname $num)
3584 start ost$num $DEVNAME $OST_MOUNT_OPTS
3586 # We started ost$num, now we should set ost${num}failover variable properly.
3587 # Set ost${num}failover_HOST if it is not set (the default failnode).
3588 varname=ost${num}failover_HOST
3589 if [ -z "${!varname}" ]; then
3590 eval ost${num}failover_HOST=$(facet_host ost${num})
3598 # wait a while to allow sptlrpc configuration be propogated to targets,
3599 # only needed when mounting new target devices.
3604 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3606 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3609 if [ "$MOUNT_2" ]; then
3610 mount_client $MOUNT2
3611 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3616 # by remounting mdt before ost, initial connect from mdt to ost might
3617 # timeout because ost is not ready yet. wait some time to its fully
3618 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3619 # by a context negotiation rpc with $TIMEOUT.
3620 # FIXME better by monitoring import status.
3623 sleep $((TIMEOUT + 5))
3629 mounted_lustre_filesystems() {
3630 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3633 init_facet_vars () {
3634 [ "$CLIENTONLY" ] && return 0
3641 eval export ${facet}_dev=${device}
3642 eval export ${facet}_opt=\"$@\"
3644 local dev=${facet}_dev
3646 # We need to loop for the label
3647 # in case its not initialized yet.
3648 for wait_time in {0,1,3,5,10}; do
3650 if [ $wait_time -gt 0 ]; then
3651 echo "${!dev} not yet initialized,"\
3652 "waiting ${wait_time} seconds."
3656 local label=$(devicelabel ${facet} ${!dev})
3658 # Check to make sure the label does
3659 # not include ffff at the end of the label.
3660 # This indicates it has not been initialized yet.
3662 if [[ $label =~ [f|F]{4}$ ]]; then
3663 # label is not initialized, unset the result
3664 # and either try again or fail
3671 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3673 eval export ${facet}_svc=${label}
3675 local varname=${facet}failover_HOST
3676 if [ -z "${!varname}" ]; then
3677 eval export $varname=$(facet_host $facet)
3680 varname=${facet}_HOST
3681 if [ -z "${!varname}" ]; then
3682 eval export $varname=$(facet_host $facet)
3685 # ${facet}failover_dev is set in cfg file
3686 varname=${facet}failover_dev
3687 if [ -n "${!varname}" ] ; then
3688 eval export ${facet}failover_dev=${!varname}
3690 eval export ${facet}failover_dev=$device
3693 # get mount point of already mounted device
3694 # is facet_dev is already mounted then use the real
3695 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3696 # i.e. ${facet}_MOUNT if specified by user or default
3697 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3698 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3699 if [ -z $mntpt ]; then
3700 mntpt=$(facet_mntpt $facet)
3702 eval export ${facet}_MOUNT=$mntpt
3705 init_facets_vars () {
3708 if ! remote_mds_nodsh; then
3709 for num in $(seq $MDSCOUNT); do
3710 DEVNAME=`mdsdevname $num`
3711 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3715 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3717 if ! remote_ost_nodsh; then
3718 for num in $(seq $OSTCOUNT); do
3719 DEVNAME=$(ostdevname $num)
3720 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3725 osc_ensure_active () {
3730 while [ $period -lt $timeout ]; do
3731 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3732 if [ $count -eq 0 ]; then
3736 echo "There are $count OST are inactive, wait $period seconds, and try again"
3738 period=$((period+3))
3741 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3744 set_conf_param_and_check() {
3748 local ORIG=$(do_facet $myfacet "$TEST")
3749 if [ $# -gt 3 ]; then
3755 echo "Setting $PARAM from $ORIG to $FINAL"
3756 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3757 error "conf_param $PARAM failed"
3759 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3760 error "check $PARAM failed!"
3763 init_param_vars () {
3765 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3767 log "Using TIMEOUT=$TIMEOUT"
3769 osc_ensure_active $SINGLEMDS $TIMEOUT
3770 osc_ensure_active client $TIMEOUT
3772 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3773 local current_jobid_var=$($LCTL get_param -n jobid_var)
3775 if [ $JOBID_VAR = "existing" ]; then
3776 echo "keeping jobstats as $current_jobid_var"
3777 elif [ $current_jobid_var != $JOBID_VAR ]; then
3778 echo "seting jobstats to $JOBID_VAR"
3780 set_conf_param_and_check client \
3781 "$LCTL get_param -n jobid_var" \
3782 "$FSNAME.sys.jobid_var" $JOBID_VAR
3785 echo "jobstats not supported by server"
3788 if [ $QUOTA_AUTO -ne 0 ]; then
3789 if [ "$ENABLE_QUOTA" ]; then
3790 echo "enable quota as required"
3791 setup_quota $MOUNT || return 2
3793 echo "disable quota as required"
3794 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3800 nfs_client_mode () {
3801 if [ "$NFSCLIENT" ]; then
3802 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3803 local clients=$CLIENTS
3804 [ -z $clients ] && clients=$(hostname)
3806 # FIXME: remove hostname when 19215 fixed
3807 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3808 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3809 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3810 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3812 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3818 check_config_client () {
3821 local mounted=$(mount | grep " $mntpt ")
3822 if [ "$CLIENTONLY" ]; then
3824 # CLIENTONLY should not depend on *_HOST settings
3825 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3826 # in theory someone could create a new,
3827 # client-only config file that assumed lustre was already
3828 # configured and didn't set the MGSNID. If MGSNID is not set,
3829 # then we should use the mgs nid currently being used
3830 # as the default value. bug 18021
3831 [[ x$MGSNID = x ]] &&
3834 if [[ x$mgc != xMGC$MGSNID ]]; then
3835 if [ "$mgs_HOST" ]; then
3836 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3837 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3838 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3844 local myMGS_host=$mgs_HOST
3845 if [ "$NETTYPE" = "ptl" ]; then
3846 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3849 echo Checking config lustre mounted on $mntpt
3850 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3851 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3853 # if [ "$mgshost" != "$myMGS_host" ]; then
3854 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3855 # Please use correct config or set mds_HOST correctly!"
3860 check_config_clients () {
3861 local clients=${CLIENTS:-$HOSTNAME}
3864 nfs_client_mode && return
3866 do_rpc_nodes "$clients" check_config_client $mntpt
3868 sanity_mount_check || error "environments are insane!"
3872 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3873 local cltimeout=$(lctl get_param -n timeout)
3874 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3875 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3882 [ -z $mntpt ] && return 1
3883 local mounted=$(mounted_lustre_filesystems)
3885 echo $mounted' ' | grep -w -q $mntpt' '
3889 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3893 # empty lustre filesystem may have empty directories lost+found and .lustre
3895 # exclude .lustre & lost+found
3896 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3897 -print | wc -l) = 1 ] || return 1
3898 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3899 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3900 # exclude .lustre/fid (LU-2780)
3901 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3902 -print | wc -l) = 1 ] || return 1
3904 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3909 check_and_setup_lustre() {
3910 nfs_client_mode && return
3912 local MOUNTED=$(mounted_lustre_filesystems)
3916 # both MOUNT and MOUNT2 are not mounted
3917 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3918 [ "$REFORMAT" ] && formatall
3919 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3921 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3922 export I_MOUNTED=yes
3926 elif is_mounted $MOUNT2; then
3928 # MOUNT2 is mounted, while MOUNT_2 is not set
3929 if ! [ "$MOUNT_2" ]; then
3930 cleanup_mount $MOUNT2
3931 export I_UMOUNTED2=yes
3934 # MOUNT2 is mounted, MOUNT_2 is set
3936 # FIXME: what to do if check_config failed?
3938 # 1) remote client has mounted other Lustre fs ?
3939 # 2) it has insane env ?
3940 # let's try umount MOUNT2 on all clients and mount it again:
3941 if ! check_config_clients $MOUNT2; then
3942 cleanup_mount $MOUNT2
3943 restore_mount $MOUNT2
3944 export I_MOUNTED2=yes
3949 # MOUNT is mounted MOUNT2 is not mounted
3950 elif [ "$MOUNT_2" ]; then
3951 restore_mount $MOUNT2
3952 export I_MOUNTED2=yes
3956 # FIXME: what to do if check_config failed?
3958 # 1) remote client has mounted other Lustre fs?
3959 # 2) lustre is mounted on remote_clients atall ?
3960 check_config_clients $MOUNT
3964 set_default_debug_nodes $(comma_list $(nodes_list))
3967 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3969 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3970 facets="$(get_facets OST)"
3971 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3972 facets="$facets,$(get_facets MDS)"
3973 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3974 facets="$facets,mgs"
3975 local nodes="$(facets_hosts ${facets})"
3976 if [ -n "$nodes" ] ; then
3977 do_nodes $nodes "$LCTL set_param \
3978 osd-ldiskfs.track_declares_assert=1 || true"
3987 #Enable remote MDT create for testing
3988 for num in $(seq $MDSCOUNT); do
3990 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
3994 if [ "$ONLY" == "setup" ]; then
4000 local clients=${CLIENTS:-$HOSTNAME}
4003 zconf_mount_clients $clients $mntpt
4007 local clients=${CLIENTS:-$HOSTNAME}
4010 zconf_umount_clients $clients $mntpt
4013 cleanup_and_setup_lustre() {
4014 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4015 lctl set_param debug=0 || true
4017 if [ "$ONLY" == "cleanup" ]; then
4021 check_and_setup_lustre
4024 # Get all of the server target devices from a given server node and type.
4031 if [ "$type" == ost ]; then
4032 devs=$(get_osd_param $node "" mntdev)
4034 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4036 for dev in $devs; do
4038 *loop*) do_node $node "losetup $dev" | \
4039 sed -e "s/.*(//" -e "s/).*//" ;;
4045 # Get all of the server target devices.
4050 # Master MDS parameters used by lfsck
4051 MDTNODE=$(facet_active_host $SINGLEMDS)
4052 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4056 for node in $(mdts_nodes); do
4057 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4063 for node in $(osts_nodes); do
4064 OSTDEVS[i]=$(get_mnt_devs $node ost)
4069 # Run e2fsck on MDT or OST device.
4074 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4075 local log=$TMP/e2fsck.log
4079 do_node $node $cmd 2>&1 | tee $log
4081 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4083 if [ $MDSCOUNT -gt 1 ]; then
4084 skip "DNE mode isn't supported!"
4088 error "It's not DNE mode."
4093 [ $rc -le $FSCK_MAX_ERR ] ||
4094 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4100 # Run resize2fs on MDT or OST device.
4109 do_facet $facet "$RESIZE2FS $opts $device $size"
4112 # verify a directory is shared among nodes.
4113 check_shared_dir() {
4115 local list=${2:-$(comma_list $(nodes_list))}
4117 [ -z "$dir" ] && return 1
4118 do_rpc_nodes "$list" check_logdir $dir
4119 check_write_access $dir "$list" || return 1
4123 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4130 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4131 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4133 check_shared_dir $SHARED_DIRECTORY ||
4134 error "$SHARED_DIRECTORY isn't a shared directory"
4136 export MDSDB=$SHARED_DIRECTORY/mdsdb
4137 export OSTDB=$SHARED_DIRECTORY/ostdb
4139 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4140 # we only pass master MDS parameters.
4141 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4146 for node in $(osts_nodes); do
4147 for dev in ${OSTDEVS[i]}; do
4148 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4149 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4150 ostidx=$((ostidx + 1))
4156 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4157 run_lfsck_remote() {
4158 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4163 #Check if lustre is already mounted
4164 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4166 zconf_mount $client $MOUNT ||
4167 error "failed to mount Lustre on $client"
4171 do_node $client $cmd || rc=$?
4172 #Umount if necessary
4174 zconf_umount $client $MOUNT ||
4175 error "failed to unmount Lustre on $client"
4178 [ $rc -le $FSCK_MAX_ERR ] ||
4179 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4180 echo "lfsck finished with rc=$rc"
4186 local facets="client $SINGLEMDS"
4192 for facet in $facets; do
4193 node=$(facet_active_host $facet)
4194 if check_progs_installed $node $LFSCK_BIN; then
4199 ! $found && error "None of \"$facets\" supports lfsck"
4201 run_lfsck_remote $node || rc=$?
4203 rm -rvf $MDSDB* $OSTDB* || true
4207 dump_file_contents() {
4213 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4214 error_noexit false \
4215 "Invalid parameters for dump_file_contents()"
4218 for node in ${nodes}; do
4219 do_node $node "for i in \\\$(find $dir -type f); do
4220 echo ====\\\${i}=======================;
4222 done" >> ${logname}.${node}.log
4226 dump_command_output() {
4232 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4233 error_noexit false \
4234 "Invalid parameters for dump_command_output()"
4238 for node in ${nodes}; do
4239 do_node $node "echo ====${cmd}=======================;
4240 $cmd" >> ${logname}.${node}.log
4247 # dump file contents from /proc/spl in case of zfs test
4248 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4249 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4250 dump_command_output \
4251 "$(osts_nodes)" "zpool events -v" "${logname}"
4254 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4255 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4256 dump_command_output \
4257 "$(mdts_nodes)" "zpool events -v" "${logname}"
4261 check_and_cleanup_lustre() {
4262 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4268 if is_mounted $MOUNT; then
4269 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4270 error "remove sub-test dirs failed"
4271 [ "$ENABLE_QUOTA" ] && restore_quota || true
4274 if [ "$I_UMOUNTED2" = "yes" ]; then
4275 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4278 if [ "$I_MOUNTED2" = "yes" ]; then
4279 cleanup_mount $MOUNT2
4282 if [ "$I_MOUNTED" = "yes" ]; then
4283 cleanupall -f || error "cleanup failed"
4291 wait_for_function () {
4294 # suppress fn both stderr and stdout
4295 if [ "$1" = "--quiet" ]; then
4297 quiet=" > /dev/null 2>&1"
4309 eval $fn $quiet && return 0
4311 wait=$((wait + sleep))
4312 [ $wait -lt $max ] || return 1
4313 echo waiting $fn, $((max - wait)) secs left ...
4323 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4324 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4325 echo "Network not available!"
4329 echo `date +"%H:%M:%S (%s)"` network interface is UP
4337 # Convert a space-delimited list to a comma-delimited list. If the input is
4338 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4340 # echo is used to convert newlines to spaces, since it doesn't
4341 # introduce a trailing space as using "tr '\n' ' '" does
4342 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4348 echo $list | grep -qw $item
4351 # list, excluded are the comma separated lists
4352 exclude_items_from_list () {
4358 for item in ${excluded//,/ }; do
4359 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4361 echo $(comma_list $list)
4364 # list, expand are the comma separated lists
4366 local list=${1//,/ }
4367 local expand=${2//,/ }
4370 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4371 echo $(comma_list $expanded)
4374 testslist_filter () {
4375 local script=$LUSTRE/tests/${TESTSUITE}.sh
4377 [ -f $script ] || return 0
4379 local start_at=$START_AT
4380 local stop_at=$STOP_AT
4382 local var=${TESTSUITE//-/_}_START_AT
4383 [ x"${!var}" != x ] && start_at=${!var}
4384 var=${TESTSUITE//-/_}_STOP_AT
4385 [ x"${!var}" != x ] && stop_at=${!var}
4387 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4388 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4389 /^'${start_at}'$/ {flag = 0}
4390 {if (flag == 1) print $0}
4391 /^'${stop_at}'$/ { flag = 1 }'
4395 (cd `dirname $1`; echo $PWD/`basename $1`)
4399 local types=${1:-"OST MDS MGS"}
4403 for entry in $types; do
4404 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4405 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4408 MGS ) list="$list $name";;
4409 MDS|OST|AGT ) local count=${type}COUNT
4410 for ((i=1; i<=${!count}; i++)) do
4411 list="$list ${name}$i"
4413 * ) error "Invalid facet type"
4417 echo $(comma_list $list)
4420 ##################################
4421 # Adaptive Timeouts funcs
4424 # only check mds, we assume at_max is the same on all nodes
4425 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4426 if [ $at_max -eq 0 ]; then
4437 # suppose that all ost-s have the same $at value set
4438 [ $facet != "ost" ] || facet=ost1
4440 do_facet $facet "lctl get_param -n $at"
4458 if [ $facet == "ost" ]; then
4459 facet=$(get_facets OST)
4460 elif [ $facet == "mds" ]; then
4461 facet=$(get_facets MDS)
4463 hosts=$(expand_list $hosts $(facets_hosts $facet))
4466 do_nodes $hosts lctl set_param at_max=$at_max
4469 ##################################
4473 # OBD_FAIL_MDS_ALL_REQUEST_NET
4475 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4476 do_facet client "$1" || RC=$?
4477 do_facet $SINGLEMDS lctl set_param fail_loc=0
4482 # OBD_FAIL_MDS_ALL_REPLY_NET
4484 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4486 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4490 drop_reint_reply() {
4491 # OBD_FAIL_MDS_REINT_NET_REP
4493 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4495 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4499 drop_update_reply() {
4500 # OBD_FAIL_OUT_UPDATE_NET_REP
4504 do_facet mds${index} lctl set_param fail_loc=0x1701
4505 do_facet client "$@" || RC=$?
4506 do_facet mds${index} lctl set_param fail_loc=0
4511 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4514 local timeout=${2:-0}
4515 # default is (obd_timeout / 4) if unspecified
4516 echo "timeout is $timeout/$2"
4517 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4518 do_facet client "$1" || RC=$?
4519 do_facet client "sync"
4520 do_facet ost1 lctl set_param fail_loc=0
4524 drop_ldlm_cancel() {
4525 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4527 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4528 do_nodes $list lctl set_param fail_loc=0x304
4530 do_facet client "$@" || RC=$?
4532 do_nodes $list lctl set_param fail_loc=0
4536 drop_bl_callback_once() {
4538 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4539 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4540 do_facet client lctl set_param fail_loc=0x80000305
4541 do_facet client "$@" || rc=$?
4542 do_facet client lctl set_param fail_loc=0
4543 do_facet client lctl set_param fail_val=0
4544 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4548 drop_bl_callback() {
4550 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4551 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4552 do_facet client lctl set_param fail_loc=0x305
4553 do_facet client "$@" || rc=$?
4554 do_facet client lctl set_param fail_loc=0
4555 do_facet client lctl set_param fail_val=0
4556 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4561 #define OBD_FAIL_LDLM_REPLY 0x30c
4563 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4564 do_nodes $list lctl set_param fail_loc=0x30c
4566 do_facet client "$@" || RC=$?
4568 do_nodes $list lctl set_param fail_loc=0
4572 drop_ldlm_reply_once() {
4573 #define OBD_FAIL_LDLM_REPLY 0x30c
4575 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4576 do_nodes $list lctl set_param fail_loc=0x8000030c
4578 do_facet client "$@" || RC=$?
4580 do_nodes $list lctl set_param fail_loc=0
4588 echo "clearing fail_loc on $facet"
4589 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4592 set_nodes_failloc () {
4593 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4596 cancel_lru_locks() {
4597 $LCTL mark "cancel_lru_locks $1 start"
4599 if [ $1 != "MGC" ]; then
4600 for d in $(lctl get_param -N ldlm.namespaces.*.lru_size |
4602 $LCTL set_param -n $d=clear
4604 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 |
4608 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lru_size \
4614 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lock_unused_count \
4616 if [ $(cat $d) != 0 ]; then
4617 echo "ldlm.namespaces.$(echo "$d" |
4618 cut -f 7 -d'/').lock_unused_count=$(cat $d)"
4623 $LCTL mark "cancel_lru_locks $1 stop"
4628 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4629 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4630 echo "$DEFAULT_LRU_SIZE"
4635 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4638 lru_resize_disable()
4640 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4646 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4652 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4653 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4654 echo there is still data in page cache $FILE ?
4655 lctl get_param -n $FILE
4663 DEBUGSAVE="$(lctl get_param -n debug)"
4667 [ -n "$DEBUGSAVE" ] && \
4668 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4673 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4676 debug_size_restore() {
4677 [ -n "$DEBUG_SIZE_SAVED" ] && \
4678 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4682 start_full_debug_logging() {
4687 local DEBUG_SIZE=150
4689 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4690 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4693 stop_full_debug_logging() {
4698 # prints bash call stack
4699 print_stack_trace() {
4701 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4702 local s=${BASH_SOURCE[$i]}
4703 local l=${BASH_LINENO[$i-1]}
4704 local f=${FUNCNAME[$i]}
4705 echo " = $s:$l:$f()"
4709 ##################################
4711 ##################################
4714 local TYPE=${TYPE:-"FAIL"}
4717 # do not dump logs if $1=false
4718 if [ "x$1" = "xfalse" ]; then
4724 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4725 print_stack_trace >&2
4728 # We need to dump the logs on all nodes
4730 gather_logs $(comma_list $(nodes_list))
4734 [ "$TESTSUITELOG" ] &&
4735 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4736 if [ -z "$*" ]; then
4737 echo "error() without useful message, please fix" > $LOGDIR/err
4739 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4740 echo "$@" > $LOGDIR/ignore
4742 echo "$@" > $LOGDIR/err
4749 local log=$TESTSUITELOG
4751 [ -f "$log" ] && grep -q FAIL $log && status=1
4764 # use only if we are ignoring failures for this test, bugno required.
4765 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4766 # e.g. error_ignore bz5494 "your message" or
4767 # error_ignore LU-5494 "your message"
4769 local TYPE="IGNORE ($1)"
4774 error_and_remount() {
4776 remount_client $MOUNT
4781 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4786 log " SKIP: $TESTSUITE $TESTNAME $@"
4788 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4789 skip_logged $TESTNAME "$@"
4792 echo "$@" > $LOGDIR/skip
4795 [[ -n "$TESTSUITELOG" ]] &&
4796 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4799 build_test_filter() {
4800 EXCEPT="$EXCEPT $(testslist_filter)"
4803 if [[ $O = [0-9]*-[0-9]* ]]; then
4804 for num in $(seq $(echo $O | tr '-' ' ')); do
4812 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4813 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4814 [ "$EXCEPT_SLOW" ] && \
4815 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4816 for E in $EXCEPT; do
4817 eval EXCEPT_${E}=true
4819 for E in $ALWAYS_EXCEPT; do
4820 eval EXCEPT_ALWAYS_${E}=true
4822 for E in $EXCEPT_SLOW; do
4823 eval EXCEPT_SLOW_${E}=true
4825 for G in $GRANT_CHECK_LIST; do
4826 eval GCHECK_ONLY_${G}=true
4831 if [[ $1 = [a-z]* ]]; then
4838 # print a newline if the last test was skipped
4839 export LAST_SKIPPED=
4840 export ALWAYS_SKIPPED=
4842 # Main entry into test-framework. This is called with the name and
4843 # description of a test. The name is used to find the function to run
4844 # the test using "test_$name".
4846 # This supports a variety of methods of specifying specific test to
4847 # run or not run. These need to be documented...
4852 export base=$(basetest $1)
4853 if [ -n "$ONLY" ]; then
4855 if [ ${!testname}x != x ]; then
4856 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4857 run_one_logged $1 "$2"
4861 if [ ${!testname}x != x ]; then
4862 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4863 run_one_logged $1 "$2"
4873 if [ ${!testname}x != x ]; then
4874 TESTNAME=test_$1 skip "skipping excluded test $1"
4877 testname=EXCEPT_$base
4878 if [ ${!testname}x != x ]; then
4879 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4882 testname=EXCEPT_ALWAYS_$1
4883 if [ ${!testname}x != x ]; then
4884 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4887 testname=EXCEPT_ALWAYS_$base
4888 if [ ${!testname}x != x ]; then
4889 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4892 testname=EXCEPT_SLOW_$1
4893 if [ ${!testname}x != x ]; then
4894 TESTNAME=test_$1 skip "skipping SLOW test $1"
4897 testname=EXCEPT_SLOW_$base
4898 if [ ${!testname}x != x ]; then
4899 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4905 run_one_logged $1 "$2"
4912 load_module ../libcfs/libcfs/libcfs
4924 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4929 strace -o $TMP/$1.strace -ttt $*
4931 log "FINISHED: $*: rc $RC"
4938 banner test complete, duration $duration sec
4939 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4940 echo duration $duration >>$TESTSUITELOG
4944 # Set TEST_STATUS here. It will be used for logging the result.
4947 if [[ -f $LOGDIR/err ]]; then
4949 elif [[ -f $LOGDIR/skip ]]; then
4952 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4956 local FFREE=$(do_node $SINGLEMDS \
4957 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4958 local FTOTAL=$(do_node $SINGLEMDS \
4959 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4961 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4965 echo -n "Resetting fail_loc on all nodes..."
4966 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
4967 fail_val=0 2>/dev/null || true"
4973 # Log a message (on all nodes) padded with "=" before and after.
4974 # Also appends a timestamp and prepends the testsuite name.
4977 EQUALS="===================================================================================================="
4979 msg="== ${TESTSUITE} $*"
4981 [[ $last != "=" && $last != " " ]] && msg="$msg "
4982 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4983 # always include at least == after the message
4984 log "$msg== $(date +"%H:%M:%S (%s)")"
4988 # Run a single test function and cleanup after it.
4990 # This function should be run in a subshell so the test func can
4991 # exit() without stopping the whole script.
4996 export tfile=f${testnum}.${TESTSUITE}
4997 export tdir=d${testnum}.${TESTSUITE}
4998 export TESTNAME=test_$testnum
4999 local SAVE_UMASK=`umask`
5002 banner "test $testnum: $message"
5003 test_${testnum} || error "test_$testnum failed with $?"
5006 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5007 check_catastrophe || error "LBUG/LASSERT detected"
5008 if [ "$PARALLEL" != "yes" ]; then
5009 ps auxww | grep -v grep | grep -q multiop &&
5010 error "multiop still running"
5020 # Wrapper around run_one to ensure:
5021 # - test runs in subshell
5022 # - output of test is saved to separate log file for error reporting
5023 # - test result is saved to data file
5026 local BEFORE=$(date +%s)
5028 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5029 local test_log=$LOGDIR/$name
5030 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5031 local zfs_debug_log=$LOGDIR/$zfs_log_name
5033 rm -rf $LOGDIR/ignore
5035 local SAVE_UMASK=$(umask)
5039 log_sub_test_begin test_${1}
5040 (run_one $1 "$2") 2>&1 | tee -i $test_log
5041 local RC=${PIPESTATUS[0]}
5043 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5044 echo "test_$1 returned $RC" | tee $LOGDIR/err
5046 duration=$(($(date +%s) - $BEFORE))
5047 pass "$1" "(${duration}s)"
5049 if [[ -f $LOGDIR/err ]]; then
5050 TEST_ERROR=$(cat $LOGDIR/err)
5051 elif [[ -f $LOGDIR/ignore ]]; then
5052 TEST_ERROR=$(cat $LOGDIR/ignore)
5053 elif [[ -f $LOGDIR/skip ]]; then
5054 TEST_ERROR=$(cat $LOGDIR/skip)
5056 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5058 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5062 if [ -f $LOGDIR/err ]; then
5063 log_zfs_info "$zfs_debug_log"
5064 $FAIL_ON_ERROR && exit $RC
5073 # Print information of skipped tests to result.yml
5076 log_sub_test_begin $1
5078 log_sub_test_end "SKIP" "0" "0" "$@"
5082 (cd $(dirname $1); echo $PWD/$(basename $1))
5087 export base=$(basetest $1)
5088 [ "$CHECK_GRANT" == "no" ] && return 0
5090 testname=GCHECK_ONLY_${base}
5091 [ ${!testname}x == x ] && return 0
5093 echo -n "checking grant......"
5095 local clients=$CLIENTS
5096 [ -z "$clients" ] && clients=$(hostname)
5098 # sync all the data and make sure no pending data on server
5099 do_nodes $clients sync
5102 client_grant=$(do_nodes $clients \
5103 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5104 awk '{ total += $1 } END { printf("%0.0f", total) }')
5107 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5108 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5109 awk '{ total += $1 } END { printf("%0.0f", total) }')
5111 # check whether client grant == server grant
5112 if [[ $client_grant -ne $server_grant ]]; then
5113 echo "failed: client:${client_grant} server: ${server_grant}."
5114 do_nodes $(comma_list $(osts_nodes)) \
5115 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5116 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5119 echo "pass: client:${client_grant} server: ${server_grant}"
5123 ########################
5129 ost=`echo $1 | awk -F_ '{print $3}'`
5130 if [ -z $ost ]; then
5131 ost=`echo $1 | sed 's/-osc.*//'`
5136 ostuuid_from_index()
5138 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5141 ostname_from_index() {
5142 local uuid=$(ostuuid_from_index $1)
5146 index_from_ostuuid()
5148 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5151 mdtuuid_from_index()
5153 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5157 # Return unique identifier for given hostname
5160 echo $host_name | md5sum | cut -d' ' -f1
5164 # Returns list of ip addresses for each interface
5166 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5171 # Cache address list to avoid mutiple execution of local_addr_list
5172 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5174 for i in $LOCAL_ADDR_LIST ; do
5175 [[ "$i" == "$addr" ]] && return 0
5182 local is_local="IS_LOCAL_$(host_id $host_name)"
5183 if [ -z "${!is_local-}" ] ; then
5185 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5186 is_local_addr "$host_ip" && eval $is_local=1
5188 [[ "${!is_local}" == "1" ]]
5193 local_node $node && return 1
5200 for node in $(mdts_nodes); do
5201 remote_node $node && return 0
5208 [ "$CLIENTONLY" ] && return 0 || true
5209 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5214 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5215 MSKIPPED=1 && return 1
5222 for node in $(osts_nodes) ; do
5223 remote_node $node && return 0
5230 [ "$CLIENTONLY" ] && return 0 || true
5231 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5236 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5237 OSKIPPED=1 && return 1
5244 MGS=$(facet_host mgs)
5245 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5250 remote_mds_nodsh || remote_ost_nodsh || \
5251 $(single_local_node $(comma_list $(nodes_list)))
5255 remote_ost && remote_mds
5258 # Get the active nodes for facets.
5266 for facet in ${facets//,/ }; do
5267 nodes="$nodes $(facet_active_host $facet)"
5270 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5274 # Get all of the active MDS nodes.
5276 echo -n $(facets_nodes $(get_facets MDS))
5279 # Get all of the active OSS nodes.
5281 echo -n $(facets_nodes $(get_facets OST))
5284 # Get all of the active AGT (HSM agent) nodes.
5286 echo -n $(facets_nodes $(get_facets AGT))
5289 # Get all of the client nodes and active server nodes.
5291 local nodes=$HOSTNAME
5295 # CLIENTS (if specified) contains the local client
5296 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5298 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5299 nodes="$nodes $(facets_nodes $(get_facets))"
5302 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5306 # Get all of the remote client nodes and remote active server nodes.
5307 remote_nodes_list () {
5308 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5311 # Get all of the MDS nodes, including active and passive nodes.
5319 for i in $(seq $MDSCOUNT); do
5321 failover_host=mds${i}failover_HOST
5322 nodes="$nodes ${!host} ${!failover_host}"
5325 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5329 # Get all of the OSS nodes, including active and passive nodes.
5337 for i in $(seq $OSTCOUNT); do
5339 failover_host=ost${i}failover_HOST
5340 nodes="$nodes ${!host} ${!failover_host}"
5343 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5347 # Get all of the server nodes, including active and passive nodes.
5348 all_server_nodes () {
5353 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5355 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5359 # Get all of the client and server nodes, including active and passive nodes.
5361 local nodes=$HOSTNAME
5365 # CLIENTS (if specified) contains the local client
5366 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5368 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5369 nodes="$nodes $(all_server_nodes)"
5372 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5376 init_clients_lists () {
5377 # Sanity check: exclude the local client from RCLIENTS
5378 local clients=$(hostlist_expand "$RCLIENTS")
5379 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5381 # Sanity check: exclude the dup entries
5382 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5384 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5386 # Sanity check: exclude the dup entries from CLIENTS
5387 # for those configs which has SINGLCLIENT set to local client
5388 clients=$(for i in $clients; do echo $i; done | sort -u)
5390 CLIENTS=$(comma_list $clients)
5391 local -a remoteclients=($RCLIENTS)
5392 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5393 varname=CLIENT$((i + 2))
5394 eval $varname=${remoteclients[i]}
5397 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5400 get_random_entry () {
5403 rnodes=${rnodes//,/ }
5405 local -a nodes=($rnodes)
5406 local num=${#nodes[@]}
5407 local i=$((RANDOM * num * 2 / 65536))
5413 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5418 lctl get_param version | grep -q patchless
5422 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5423 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5428 echo $nodes | wc -w || true
5432 local nodes=$(osts_nodes)
5433 local osscount=$(get_node_count "$nodes")
5434 [ ! "$OSTCOUNT" = "$osscount" ]
5438 local nodes=$(mdts_nodes)
5439 local mdtcount=$(get_node_count "$nodes")
5440 [ ! "$MDSCOUNT" = "$mdtcount" ]
5443 generate_machine_file() {
5444 local nodes=${1//,/ }
5445 local machinefile=$2
5447 for node in $nodes; do
5448 echo $node >>$machinefile || \
5449 { echo "can not generate machinefile $machinefile" && return 1; }
5454 local file=$1/stripe
5457 $LFS getstripe -v $file || error "getstripe $file failed"
5461 setstripe_nfsserver () {
5464 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5465 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5467 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5469 do_nodev $nfsserver lfs setstripe "$@"
5472 # Check and add a test group.
5478 local gid=$(getent group $group_name | cut -d: -f3)
5479 if [[ -n "$gid" ]]; then
5480 [[ "$gid" -eq "$group_id" ]] || {
5481 error_noexit "inconsistent group ID:" \
5482 "new: $group_id, old: $gid"
5486 groupadd -g $group_id $group_name
5493 # Check and add a test user.
5506 local uid=$(getent passwd $user_name | cut -d: -f3)
5507 if [[ -n "$uid" ]]; then
5508 if [[ "$uid" -eq "$user_id" ]]; then
5509 local dir=$(getent passwd $user_name | cut -d: -f6)
5510 if [[ "$dir" != "$home" ]]; then
5512 usermod -d $home $user_name
5516 error_noexit "inconsistent user ID:" \
5517 "new: $user_id, old: $uid"
5522 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5529 check_runas_id_ret() {
5531 local myRUNAS_UID=$1
5532 local myRUNAS_GID=$2
5535 if [ -z "$myRUNAS" ]; then
5536 error_exit "myRUNAS command must be specified for check_runas_id"
5539 $myRUNAS krb5_login.sh || \
5540 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5542 mkdir $DIR/d0_runas_test
5544 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5545 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5546 rm -rf $DIR/d0_runas_test
5551 local myRUNAS_UID=$1
5552 local myRUNAS_GID=$2
5555 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5556 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5557 Please set RUNAS_ID to some UID which exists on MDS and client or
5558 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5561 # obtain the UID/GID for MPI_USER
5565 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5566 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5568 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5569 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5572 # obtain and cache Kerberos ticket-granting ticket
5573 refresh_krb5_tgt() {
5574 local myRUNAS_UID=$1
5575 local myRUNAS_GID=$2
5578 if [ -z "$myRUNAS" ]; then
5579 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5582 CLIENTS=${CLIENTS:-$HOSTNAME}
5583 do_nodes $CLIENTS "set -x
5584 if ! $myRUNAS krb5_login.sh; then
5585 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5590 # Run multiop in the background, but wait for it to print
5591 # "PAUSING" to its stdout before returning from this function.
5592 multiop_bg_pause() {
5593 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5597 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5600 echo "$MULTIOP_PROG $FILE v$ARGS"
5601 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5603 echo "TMPPIPE=${TMPPIPE}"
5604 read -t 60 multiop_output < $TMPPIPE
5605 if [ $? -ne 0 ]; then
5610 if [ "$multiop_output" != "PAUSING" ]; then
5611 echo "Incorrect multiop output: $multiop_output"
5626 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5632 inodes_available () {
5633 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5634 sort -un | head -n1) || return 1
5638 mdsrate_inodes_available () {
5639 local min_inodes=$(inodes_available)
5640 echo $((min_inodes * 99 / 100))
5643 # reset llite stat counters
5644 clear_llite_stats(){
5645 lctl set_param -n llite.*.stats 0
5648 # sum llite stat items
5649 calc_llite_stats() {
5650 local res=$(lctl get_param -n llite.*.stats |
5651 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5655 # reset osc stat counters
5657 lctl set_param -n osc.*.osc_stats 0
5660 # sum osc stat items
5662 local res=$(lctl get_param -n osc.*.osc_stats |
5663 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5668 awk '{sum += $1} END { printf("%0.0f", sum) }'
5671 calc_osc_kbytes () {
5672 df $MOUNT > /dev/null
5673 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5676 # save_lustre_params(comma separated facet list, parameter_mask)
5677 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5678 save_lustre_params() {
5684 for facet in ${facets//,/ }; do
5685 node=$(facet_active_host $facet)
5686 [[ *\ $node\ * = " $nodes " ]] && continue
5687 nodes="$nodes $node"
5689 do_node $node "$LCTL get_param $2 |
5690 while read s; do echo $facet \\\$s; done"
5694 # restore lustre parameters from input stream, produces by save_lustre_params
5695 restore_lustre_params() {
5700 while IFS=" =" read facet name val; do
5701 do_facet $facet "$LCTL set_param -n $name $val"
5705 check_catastrophe() {
5706 local nodes=${1:-$(comma_list $(nodes_list))}
5708 do_nodes $nodes "rc=0;
5709 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5710 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5711 echo \\\$(hostname -s): \\\$val;
5717 mdsrate_cleanup () {
5719 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5720 --nfiles $3 --dir $4 --filefmt $5 $6
5725 delayed_recovery_enabled () {
5726 local var=${SINGLEMDS}_svc
5727 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5730 ########################
5732 convert_facet2label() {
5735 if [ x$facet = xost ]; then
5739 local varsvc=${facet}_svc
5741 if [ -n ${!varsvc} ]; then
5744 error "No lablel for $facet!"
5748 get_clientosc_proc_path() {
5752 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5753 # used by MDT would not be changed.
5754 # mdt lov: fsname-mdtlov
5755 # mdt osc: fsname-OSTXXXX-osc
5756 mds_on_old_device() {
5757 local mds=${1:-"$SINGLEMDS"}
5759 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5760 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5761 > /dev/null 2>&1" && return 0
5766 get_mdtosc_proc_path() {
5768 local ost_label=${2:-"*OST*"}
5770 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5771 local mdt_label=$(convert_facet2label $mds_facet)
5772 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5774 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5775 mds_on_old_device $mds_facet; then
5776 echo "${ost_label}-osc"
5778 echo "${ost_label}-osc-${mdt_index}"
5782 get_osc_import_name() {
5785 local label=$(convert_facet2label $ost)
5787 if [ "${facet:0:3}" = "mds" ]; then
5788 get_mdtosc_proc_path $facet $label
5792 get_clientosc_proc_path $label
5796 _wait_import_state () {
5799 local maxtime=${3:-$(max_recovery_time)}
5803 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5804 while [ "${CONN_STATE}" != "${expected}" ]; do
5805 if [ "${expected}" == "DISCONN" ]; then
5806 # for disconn we can check after proc entry is removed
5807 [ "x${CONN_STATE}" == "x" ] && return 0
5808 # with AT enabled, we can have connect request timeout near of
5809 # reconnect timeout and test can't see real disconnect
5810 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5812 [ $i -ge $maxtime ] && \
5813 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5816 # Add uniq for multi-mount case
5817 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5821 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5825 wait_import_state() {
5828 local maxtime=${3:-$(max_recovery_time)}
5831 for param in ${params//,/ }; do
5832 _wait_import_state $state $param $maxtime || return
5836 wait_import_state_mount() {
5837 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5841 wait_import_state $*
5844 # One client request could be timed out because server was not ready
5845 # when request was sent by client.
5846 # The request timeout calculation details :
5848 # /* We give the server rq_timeout secs to process the req, and
5849 # add the network latency for our local timeout. */
5850 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5851 # ptlrpc_at_get_net_latency(request) ;
5853 # ptlrpc_connect_import ()
5854 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5857 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5858 # ptlrpc_at_get_net_latency(request) ->
5859 # at_get (max (iat_net_latency=0, at_min)) = at_min
5862 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5863 # INITIAL_CONNECT_TIMEOUT + at_min
5865 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5866 # because we can not get this value in runtime,
5867 # the value depends on configure options, and it is not stored in /proc.
5869 # #define CONNECTION_SWITCH_MIN 5U
5870 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5872 request_timeout () {
5875 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5876 local init_connect_timeout=$TIMEOUT
5877 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5879 local at_min=$(at_get $facet at_min)
5881 echo $(( init_connect_timeout + at_min ))
5884 _wait_osc_import_state() {
5888 local ost=$(get_osc_import_name $facet $ost_facet)
5889 local param="osc.${ost}.ost_server_uuid"
5893 # 1. wait the deadline of client 1st request (it could be skipped)
5894 # 2. wait the deadline of client 2nd request
5895 local maxtime=$(( 2 * $(request_timeout $facet)))
5897 if [[ $facet == client* ]]; then
5898 # During setup time, the osc might not be setup, it need wait
5899 # until list_param can return valid value. And also if there
5900 # are mulitple osc entries we should list all of them before
5902 params=$($LCTL list_param $param 2>/dev/null || true)
5903 while [ -z "$params" ]; do
5904 if [ $i -ge $maxtime ]; then
5905 echo "can't get $param in $maxtime secs"
5910 params=$($LCTL list_param $param 2>/dev/null || true)
5913 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5914 wait_import_state $expected "$params" $maxtime; then
5915 error "import is not in ${expected} state"
5922 wait_osc_import_state() {
5928 if [[ $facet = mds ]]; then
5929 for num in $(seq $MDSCOUNT); do
5930 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5933 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5937 get_clientmdc_proc_path() {
5941 get_clientmgc_proc_path() {
5949 [ -z "$list" ] && return 0
5951 # Add paths to lustre tests for 32 and 64 bit systems.
5952 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5953 local TESTPATH="$RLUSTRE/tests:"
5954 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5955 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5958 wait_clients_import_state () {
5965 if [ "$FAILURE_MODE" = HARD ]; then
5966 facets=$(facets_on_host $(facet_active_host $facet))
5969 for facet in ${facets//,/ }; do
5970 local label=$(convert_facet2label $facet)
5973 ost* ) proc_path="osc.$(get_clientosc_proc_path \
5974 $label).ost_server_uuid" ;;
5975 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
5976 $label).mds_server_uuid" ;;
5977 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
5978 $label).mgs_server_uuid" ;;
5979 *) error "unknown facet!" ;;
5982 local params=$(expand_list $params $proc_path)
5985 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
5987 error "import is not in ${expected} state"
5997 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5998 $LCTL get_param obdfilter.*.kbytesavail))
5999 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6000 $LCTL get_param -n obdfilter.*.tot_granted))
6001 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6002 $LCTL get_param -n obdfilter.*.kbytestotal))
6003 for ((i=0; i<${#AVAILA[@]}; i++)); do
6004 local -a AVAIL1=(${AVAILA[$i]//=/ })
6005 local -a TOTAL=(${TOTALA[$i]//=/ })
6006 GRANT=$((${GRANTA[$i]}/1024))
6007 # allow 1% of total space in bavail because of delayed
6008 # allocation with ZFS which might release some free space after
6009 # txg commit. For small devices, we set a mininum of 8MB
6010 local LIMIT=$((${TOTAL} / 100 + 8000))
6011 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6012 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6013 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6014 echo " FULL" || echo
6020 do_facet mgs lctl pool_list $1
6024 local fsname=${1%%.*}
6025 local poolname=${1##$fsname.}
6027 do_facet mgs lctl pool_new $1
6029 # get param should return err unless pool is created
6030 [[ $RC -ne 0 ]] && return $RC
6032 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6033 2>/dev/null || echo foo" "" || RC=1
6034 if [[ $RC -eq 0 ]]; then
6037 error "pool_new failed $1"
6042 add_pool_to_list () {
6043 local fsname=${1%%.*}
6044 local poolname=${1##$fsname.}
6046 local listvar=${fsname}_CREATED_POOLS
6047 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
6050 remove_pool_from_list () {
6051 local fsname=${1%%.*}
6052 local poolname=${1##$fsname.}
6054 local listvar=${fsname}_CREATED_POOLS
6055 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6058 destroy_pool_int() {
6060 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6061 awk '$1 !~ /^Pool:/ {print $1}')
6062 for ost in $OSTS; do
6063 do_facet mgs lctl pool_remove $1 $ost
6065 do_facet mgs lctl pool_destroy $1
6068 # <fsname>.<poolname> or <poolname>
6070 local fsname=${1%%.*}
6071 local poolname=${1##$fsname.}
6073 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6077 pool_list $fsname.$poolname || return $?
6079 destroy_pool_int $fsname.$poolname
6081 [[ $RC -ne 0 ]] && return $RC
6083 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6084 2>/dev/null || echo foo" "foo" || RC=1
6086 if [[ $RC -eq 0 ]]; then
6087 remove_pool_from_list $fsname.$poolname
6089 error "destroy pool failed $1"
6095 local fsname=${1:-$FSNAME}
6097 local listvar=${fsname}_CREATED_POOLS
6101 [ x${!listvar} = x ] && return 0
6103 echo destroy the created pools: ${!listvar}
6104 for poolname in ${!listvar//,/ }; do
6105 destroy_pool $fsname.$poolname
6110 local fsname=${1:-$FSNAME}
6112 destroy_pools $fsname
6118 local ts=$(date +%s)
6121 if [[ ! -f "$YAML_LOG" ]]; then
6122 # init_logging is not performed before gather_logs,
6123 # so the $LOGDIR needs to be checked here
6124 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6127 [ -f $LOGDIR/shared ] && docp=false
6129 # dump lustre logs, dmesg
6131 prefix="$TESTLOG_PREFIX.$TESTNAME"
6133 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6135 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6136 echo "Dumping logs only on local client."
6137 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6138 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6143 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6144 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6145 if [ ! -f $LOGDIR/shared ]; then
6146 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6159 for i in $(seq 0 $num_mntpts); do
6160 cmd="ls -laf ${mntpt_root}$i/$dir"
6166 for pid in $pids; do
6173 # check_and_start_recovery_timer()
6174 # service_time = at_est2timeout(service_time);
6175 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6176 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6178 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6179 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6180 #define CONNECTION_SWITCH_MIN 5
6181 #define CONNECTION_SWITCH_INC 5
6182 max_recovery_time() {
6183 local init_connect_timeout=$((TIMEOUT / 20))
6184 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6186 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6187 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6189 echo -n $service_time
6192 get_clients_mount_count () {
6193 local clients=${CLIENTS:-`hostname`}
6195 # we need to take into account the clients mounts and
6196 # exclude mds/ost mounts if any;
6197 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6201 PROC_CLI="srpc_info"
6209 if [ $M -lt $N ]; then
6213 while [ $N -lt $M ]; do
6223 calc_connection_cnt() {
6226 # MDT->MDT = 2 * C(M, 2)
6230 comb_m2=$(combination $MDSCOUNT 2)
6232 local num_clients=$(get_clients_mount_count)
6234 local cnt_mdt2mdt=$((comb_m2 * 2))
6235 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6236 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6237 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6238 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6239 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6240 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6254 local cmd="$tgt.srpc.flavor"
6256 if [ $net == "any" ]; then
6261 if [ $dir != "any" ]; then
6266 log "Setting sptlrpc rule: $cmd"
6267 do_facet mgs "$LCTL conf_param $cmd"
6276 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6277 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6279 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6281 if [ "x$bulkspec" != "x" ]; then
6282 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6284 if [ "x$algs" != "x" ]; then
6285 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6287 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6288 if [ $bulk == "bulkn" ]; then
6289 bulk_count=`echo "$output" | grep "bulk flavor" \
6290 | grep "null/null" | wc -l`
6291 elif [ $bulk == "bulki" ]; then
6292 bulk_count=`echo "$output" | grep "bulk flavor" \
6293 | grep "/null" | grep -v "null/" | wc -l`
6295 bulk_count=`echo "$output" | grep "bulk flavor" \
6296 | grep -v "/null" | grep -v "null/" | wc -l`
6300 [ $bulk_count -lt $count ] && count=$bulk_count
6311 local clients=${CLIENTS:-`hostname`}
6313 for c in ${clients//,/ }; do
6314 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6315 tmpcnt=`count_flvr "$output" $flavor`
6316 cnt=$((cnt + tmpcnt))
6326 local clients=${CLIENTS:-`hostname`}
6328 for c in ${clients//,/ }; do
6329 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6330 tmpcnt=`count_flvr "$output" $flavor`
6331 cnt=$((cnt + tmpcnt))
6341 if [ $MDSCOUNT -le 1 ]; then
6346 for num in `seq $MDSCOUNT`; do
6347 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6348 tmpcnt=`count_flvr "$output" $flavor`
6349 cnt=$((cnt + tmpcnt))
6360 for num in `seq $MDSCOUNT`; do
6361 mdtosc=$(get_mdtosc_proc_path mds$num)
6362 mdtosc=${mdtosc/-MDT*/-MDT\*}
6363 output=$(do_facet mds$num lctl get_param -n \
6364 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6365 tmpcnt=`count_flvr "$output" $flavor`
6366 cnt=$((cnt + tmpcnt))
6375 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6376 count_flvr "$output" $flavor
6381 local dir=$1 # from to
6382 local flavor=$2 # flavor expected
6385 if [ $dir == "cli2mdt" ]; then
6386 res=`flvr_cnt_cli2mdt $flavor`
6387 elif [ $dir == "cli2ost" ]; then
6388 res=`flvr_cnt_cli2ost $flavor`
6389 elif [ $dir == "mdt2mdt" ]; then
6390 res=`flvr_cnt_mdt2mdt $flavor`
6391 elif [ $dir == "mdt2ost" ]; then
6392 res=`flvr_cnt_mdt2ost $flavor`
6393 elif [ $dir == "all2ost" ]; then
6394 res1=`flvr_cnt_mdt2ost $flavor`
6395 res2=`flvr_cnt_cli2ost $flavor`
6396 res=$((res1 + res2))
6397 elif [ $dir == "all2mdt" ]; then
6398 res1=`flvr_cnt_mdt2mdt $flavor`
6399 res2=`flvr_cnt_cli2mdt $flavor`
6400 res=$((res1 + res2))
6401 elif [ $dir == "all2all" ]; then
6402 res1=`flvr_cnt_mdt2ost $flavor`
6403 res2=`flvr_cnt_cli2ost $flavor`
6404 res3=`flvr_cnt_mdt2mdt $flavor`
6405 res4=`flvr_cnt_cli2mdt $flavor`
6406 res=$((res1 + res2 + res3 + res4))
6414 local dir=$1 # from to
6415 local flavor=$2 # flavor expected
6416 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6420 for ((i=0;i<20;i++)); do
6421 echo -n "checking $dir..."
6422 res=$(do_check_flavor $dir $flavor)
6423 echo "found $res/$expect $flavor connections"
6424 [ $res -ge $expect ] && return 0
6428 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6432 restore_to_default_flavor()
6434 local proc="mgs.MGS.live.$FSNAME"
6436 echo "restoring to default flavor..."
6438 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6440 # remove all existing rules if any
6441 if [ $nrule -ne 0 ]; then
6442 echo "$nrule existing rules"
6443 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6444 echo "remove rule: $rule"
6445 spec=`echo $rule | awk -F = '{print $1}'`
6446 do_facet mgs "$LCTL conf_param -d $spec"
6450 # verify no rules left
6451 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6452 [ $nrule -ne 0 ] && error "still $nrule rules left"
6454 # wait for default flavor to be applied
6455 # currently default flavor for all connections are 'null'
6456 wait_flavor all2all null
6457 echo "now at default flavor settings"
6462 local flavor=${1:-null}
6464 echo "setting all flavor to $flavor"
6466 # FIXME need parameter to this fn
6467 # and remove global vars
6468 local cnt_all2all=$(calc_connection_cnt all2all)
6470 local res=$(do_check_flavor all2all $flavor)
6471 if [ $res -eq $cnt_all2all ]; then
6472 echo "already have total $res $flavor connections"
6476 echo "found $res $flavor out of total $cnt_all2all connections"
6477 restore_to_default_flavor
6479 [[ $flavor = null ]] && return 0
6481 set_rule $FSNAME any any $flavor
6482 wait_flavor all2all $flavor
6488 # Checking for shared logdir
6489 if [ ! -d $dir ]; then
6490 # Not found. Create local logdir
6493 touch $dir/check_file.$(hostname -s)
6498 check_write_access() {
6500 local list=${2:-$(comma_list $(nodes_list))}
6504 for node in ${list//,/ }; do
6505 file=$dir/check_file.$(short_nodename $node)
6506 if [[ ! -f "$file" ]]; then
6507 # Logdir not accessible/writable from this node.
6510 rm -f $file || return 1
6516 if [[ -n $YAML_LOG ]]; then
6519 local SAVE_UMASK=`umask`
6522 export YAML_LOG=${LOGDIR}/results.yml
6526 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6527 if check_shared_dir $LOGDIR; then
6528 touch $LOGDIR/shared
6529 echo "Logging to shared log directory: $LOGDIR"
6531 echo "Logging to local directory: $LOGDIR"
6534 yml_nodes_file $LOGDIR >> $YAML_LOG
6535 yml_results_file >> $YAML_LOG
6542 yml_log_test $1 >> $YAML_LOG
6546 yml_log_test_status $@ >> $YAML_LOG
6549 log_sub_test_begin() {
6550 yml_log_sub_test_begin "$@" >> $YAML_LOG
6553 log_sub_test_end() {
6554 yml_log_sub_test_end "$@" >> $YAML_LOG
6560 local llverdev_opts=$2
6561 local devname=$(basename $1)
6562 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6563 # loop devices aren't in /proc/partitions
6564 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6566 size=$(($size / 1024 / 1024)) # Gb
6568 local partial_arg=""
6569 # Run in partial (fast) mode if the size
6570 # of a partition > 1 GB
6571 [ $size -gt 1 ] && partial_arg="-p"
6573 llverdev --force $partial_arg $llverdev_opts $dev
6579 local llverfs_opts=$2
6580 local use_partial_arg=$3
6581 local partial_arg=""
6582 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6584 # Run in partial (fast) mode if the size
6585 # of a partition > 1 GB
6586 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6588 llverfs $partial_arg $llverfs_opts $dir
6591 #Remove objects from OST
6592 remove_ost_objects() {
6598 local mntpt=$(facet_mntpt $facet)
6599 local opts=$OST_MOUNT_OPTS
6603 echo "removing objects from $ostdev on $facet: $objids"
6604 if ! test -b $ostdev; then
6605 opts=$(csa_add "$opts" -o loop)
6607 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6610 for i in $objids; do
6611 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6613 umount -f $mntpt || return $?
6617 #Remove files from MDT
6618 remove_mdt_files() {
6623 local mntpt=$(facet_mntpt $facet)
6624 local opts=$MDS_MOUNT_OPTS
6626 echo "removing files from $mdtdev on $facet: $files"
6627 if [ $(facet_fstype $facet) == ldiskfs ] &&
6628 ! do_facet $facet test -b $mdtdev; then
6629 opts=$(csa_add "$opts" -o loop)
6631 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6635 rm $mntpt/ROOT/$f || { rc=$?; break; }
6637 umount -f $mntpt || return $?
6641 duplicate_mdt_files() {
6646 local mntpt=$(facet_mntpt $facet)
6647 local opts=$MDS_MOUNT_OPTS
6649 echo "duplicating files on $mdtdev on $facet: $files"
6650 mkdir -p $mntpt || return $?
6651 if [ $(facet_fstype $facet) == ldiskfs ] &&
6652 ! do_facet $facet test -b $mdtdev; then
6653 opts=$(csa_add "$opts" -o loop)
6655 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6666 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6667 pushd $mntpt/ROOT > /dev/null || return $?
6670 touch $f.bad || return $?
6671 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6673 [ $rc -eq 0 ] || return $rc
6674 setfattr --restore $tmp || return $?
6680 local devs=${1//,/ }
6683 local rslt=$TMP/sgpdd_survey
6685 # sgpdd-survey cleanups ${rslt}.* files
6687 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6693 # returns the canonical name for an ldiskfs device
6698 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6699 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6700 echo dm-\\\${foo##*:};
6702 echo \\\$(basename \\\$dv);
6706 is_sanity_benchmark() {
6707 local benchmarks="dbench bonnie iozone fsx"
6709 for b in $benchmarks; do
6710 if [ "$b" == "$suite" ]; then
6718 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6722 # Get the available size (KB) of a given obd target.
6729 [[ $facet != client ]] || return 0
6731 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6736 # Get the page size (bytes) on a given facet node.
6742 size=$(do_facet $facet getconf PAGE_SIZE)
6743 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6748 # Get the block count of the filesystem.
6755 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6756 awk '/^Block count:/ {print $3}')
6760 # Get the block size of the filesystem.
6766 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6767 awk '/^Block size:/ {print $3}')
6771 # Check whether the "large_xattr" feature is enabled or not.
6772 large_xattr_enabled() {
6773 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6775 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6777 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6778 grep -E -q '(ea_inode|large_xattr)'"
6779 return ${PIPESTATUS[0]}
6782 # Get the maximum xattr size supported by the filesystem.
6786 if large_xattr_enabled; then
6787 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6790 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6791 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6793 # maximum xattr size = size of block - size of header -
6794 # size of 1 entry - 4 null bytes
6795 size=$((block_size - 32 - 32 - 4))
6801 # Dump the value of the named xattr from a file.
6806 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6809 # Generate a string with size of $size bytes.
6811 local size=${1:-1024} # in bytes
6813 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6816 reformat_external_journal() {
6819 if [ ! -z ${EJOURNAL} ]; then
6820 local rcmd="do_facet $facet"
6822 echo "reformat external journal on $facet:${EJOURNAL}"
6823 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6827 # MDT file-level backup/restore
6828 mds_backup_restore() {
6831 local devname=$(mdsdevname $(facet_number $facet))
6832 local mntpt=$(facet_mntpt brpt)
6833 local rcmd="do_facet $facet"
6834 local metaea=${TMP}/backup_restore.ea
6835 local metadata=${TMP}/backup_restore.tgz
6836 local opts=${MDS_MOUNT_OPTS}
6837 local svc=${facet}_svc
6839 if ! ${rcmd} test -b ${devname}; then
6840 opts=$(csa_add "$opts" -o loop)
6843 echo "file-level backup/restore on $facet:${devname}"
6845 # step 1: build mount point
6846 ${rcmd} mkdir -p $mntpt
6847 # step 2: cleanup old backup
6848 ${rcmd} rm -f $metaea $metadata
6850 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6851 if [ ! -z $igif ]; then
6852 # step 3.5: rm .lustre
6853 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6855 # step 4: backup metaea
6857 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6859 # step 5: backup metadata
6861 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6863 ${rcmd} umount -d $mntpt || return 4
6864 # step 7: reformat external journal if needed
6865 reformat_external_journal $facet || return 5
6866 # step 8: reformat dev
6867 echo "reformat new device"
6868 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6869 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6870 > /dev/null || exit 6
6872 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6873 # step 10: restore metadata
6875 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6876 # step 11: restore metaea
6878 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6879 # step 12: remove recovery logs
6880 echo "remove recovery logs"
6881 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6882 # step 13: umount dev
6883 ${rcmd} umount -d $mntpt || return 10
6884 # step 14: cleanup tmp backup
6885 ${rcmd} rm -f $metaea $metadata
6886 # step 15: reset device label - it's not virgin on
6887 ${rcmd} e2label $devname ${!svc}
6894 local devname=$(mdsdevname $(facet_number $facet))
6895 local mntpt=$(facet_mntpt brpt)
6896 local rcmd="do_facet $facet"
6897 local opts=${MDS_MOUNT_OPTS}
6899 if ! ${rcmd} test -b ${devname}; then
6900 opts=$(csa_add "$opts" -o loop)
6903 echo "removing OI files on $facet: idx=${idx}"
6905 # step 1: build mount point
6906 ${rcmd} mkdir -p $mntpt
6908 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6909 if [ -z $idx ]; then
6910 # step 3: remove all OI files
6911 ${rcmd} rm -fv $mntpt/oi.16*
6912 elif [ $idx -lt 2 ]; then
6913 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6917 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6918 for ((i=${idx}; i<64; i=$((i * idx)))); do
6919 ${rcmd} rm -fv $mntpt/oi.16.${i}
6923 ${rcmd} umount -d $mntpt || return 2
6924 # OI files will be recreated when mounted as lustre next time.
6927 # generate maloo upload-able log file name
6928 # \param logname specify unique part of file name
6929 generate_logname() {
6930 local logname=${1:-"default_logname"}
6932 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6935 # make directory on different MDTs
6939 local stripe_count=2
6940 local stripe_index=-1
6943 while getopts "c:i:p" opt; do
6945 c) stripe_count=$OPTARG;;
6946 i) stripe_index=$OPTARG;;
6948 \?) error "only support -i -c -p";;
6952 shift $((OPTIND - 1))
6953 [ $# -eq 1 ] || error "Only creating single directory is supported"
6956 if [ "$p_option" == "-p" ]; then
6957 local parent=$(dirname $path)
6959 [ -d $path ] && return 0
6960 [ ! -d ${parent} ] && mkdir -p ${parent}
6963 if [ $MDSCOUNT -le 1 ]; then
6966 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6969 if [ $stripe_index -eq -1 ]; then
6970 mdt_index=$((test_num % MDSCOUNT))
6972 mdt_index=$stripe_index
6974 echo "striped dir -i$mdt_index -c$stripe_count $path"
6975 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
6979 # find the smallest and not in use file descriptor
6982 local max_fd=$(ulimit -n)
6984 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6987 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
6991 check_mount_and_prep()
6993 is_mounted $MOUNT || setupall
6995 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
6996 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
6997 for idx in $(seq $MDSCOUNT); do
6998 local name="MDT$(printf '%04x' $((idx - 1)))"
6999 rm -rf $MOUNT/.lustre/lost+found/$name/*
7003 # calcule how many ost-objects to be created.
7004 precreated_ost_obj_count()
7008 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7009 local ost_name="OST$(printf '%04x' $ost_idx)"
7010 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7011 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7012 osp.$proc_path.prealloc_last_id)
7013 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7014 osp.$proc_path.prealloc_next_id)
7015 echo $((last_id - next_id + 1))
7018 check_file_in_pool()
7023 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7026 for t in $tlist ; do
7027 [ "$i" -eq "$t" ] && continue 2
7030 echo "pool list: $tlist"
7031 echo "striping: $res"
7032 error_noexit "$file not allocated in $pool"
7039 echo "Creating new pool"
7042 create_pool $FSNAME.$pool ||
7043 { error_noexit "No pool created, result code $?"; return 1; }
7044 [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
7045 { error_noexit "$pool not in lfs pool_list"; return 2; }
7048 pool_add_targets() {
7049 echo "Adding targets to pool"
7055 local list=$(seq $first $step $last)
7057 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7058 do_facet mgs $LCTL pool_add \
7059 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7060 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7061 | sort -u | tr '\n' ' ' " "$t" || {
7062 error_noexit "Add to pool failed"
7065 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7066 local addcount=$(((last - first) / step + 1))
7067 [ $lfscount -eq $addcount ] || {
7068 error_noexit "lfs pool_list bad ost count" \
7069 "$lfscount != $addcount"
7077 echo "Setting pool on directory $tdir"
7079 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7081 error_noexit "Cannot set pool $pool to $tdir"
7088 echo "Checking pool on directory $tdir"
7090 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7091 [ "$res" = "$pool" ] && return 0
7093 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7097 pool_dir_rel_path() {
7098 echo "Testing relative path works well"
7103 mkdir -p $root/$tdir/$tdir
7105 pool_set_dir $pool $tdir || return 1
7106 pool_set_dir $pool ./$tdir || return 2
7107 pool_set_dir $pool ../$tdir || return 3
7108 pool_set_dir $pool ../$tdir/$tdir || return 4
7109 rm -rf $tdir; cd - > /dev/null
7112 pool_alloc_files() {
7113 echo "Checking files allocation from directory pool"
7120 for i in $(seq -w 1 $count)
7122 local file=$tdir/file-$i
7124 check_file_in_pool $file $pool "$tlist" || \
7125 failed=$((failed + 1))
7127 [ "$failed" = 0 ] && return 0
7129 error_noexit "$failed files not allocated in $pool"
7133 pool_create_files() {
7134 echo "Creating files in pool"
7142 for i in $(seq -w 1 $count)
7144 local file=$tdir/spoo-$i
7145 $SETSTRIPE -p $pool $file
7146 check_file_in_pool $file $pool "$tlist" || \
7147 failed=$((failed + 1))
7149 [ "$failed" = 0 ] && return 0
7151 error_noexit "$failed files not allocated in $pool"
7156 echo "Checking 'lfs df' output"
7159 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7161 local res=$($LFS df --pool $FSNAME.$pool |
7163 grep "$FSNAME-OST" |
7165 [ "$res" = "$t" ] && return 0
7167 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7171 pool_file_rel_path() {
7172 echo "Creating files in a pool with relative pathname"
7177 { error_noexit "unable to create $tdir"; return 1 ; }
7178 local file="/..$tdir/$tfile-1"
7179 $SETSTRIPE -p $pool $file ||
7180 { error_noexit "unable to create $file" ; return 2 ; }
7183 $SETSTRIPE -p $pool $tfile-2 || {
7184 error_noexit "unable to create $tfile-2 in $tdir"
7189 pool_remove_first_target() {
7190 echo "Removing first target from a pool"
7193 local pname="lov.$FSNAME-*.pools.$pool"
7194 local t=$($LCTL get_param -n $pname | head -1)
7195 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7196 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7197 error_noexit "$t not removed from $FSNAME.$pool"
7202 pool_remove_all_targets() {
7203 echo "Removing all targets from pool"
7206 local pname="lov.$FSNAME-*.pools.$pool"
7207 for t in $($LCTL get_param -n $pname | sort -u)
7209 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7211 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7212 error_noexit "Pool $FSNAME.$pool cannot be drained"
7215 # striping on an empty/nonexistant pool should fall back
7216 # to "pool of everything"
7218 error_noexit "failed to use fallback striping for empty pool"
7221 # setstripe on an empty pool should fail
7222 $SETSTRIPE -p $pool $file 2>/dev/null && {
7223 error_noexit "expected failure when creating file" \
7231 echo "Destroying pool"
7235 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7238 # striping on an empty/nonexistant pool should fall back
7239 # to "pool of everything"
7241 error_noexit "failed to use fallback striping for missing pool"
7244 # setstripe on an empty pool should fail
7245 $SETSTRIPE -p $pool $file 2>/dev/null && {
7246 error_noexit "expected failure when creating file" \
7251 # get param should return err once pool is gone
7252 if wait_update $HOSTNAME "lctl get_param -n \
7253 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7255 remove_pool_from_list $FSNAME.$pool
7258 error_noexit "Pool $FSNAME.$pool is not destroyed"
7262 # Get and check the actual stripe count of one file.
7263 # Usage: check_stripe_count <file> <expected_stripe_count>
7264 check_stripe_count() {
7269 [[ -z "$file" || -z "$expected" ]] &&
7270 error "check_stripe_count: invalid argument"
7272 local cmd="$GETSTRIPE -c $file"
7273 actual=$($cmd) || error "$cmd failed"
7274 actual=${actual%% *}
7276 if [[ $actual -ne $expected ]]; then
7277 [[ $expected -eq -1 ]] ||
7278 error "$cmd wrong: found $actual, expected $expected"
7279 [[ $actual -eq $OSTCOUNT ]] ||
7280 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7284 # Get and check the actual list of OST indices on one file.
7285 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7291 [[ -z "$file" || -z "$expected" ]] &&
7292 error "check_obdidx: invalid argument!"
7294 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7295 grep -v obdidx | awk '{print $1}' | xargs))
7297 [[ $obdidx = $expected ]] ||
7298 error "list of OST indices on $file is $obdidx," \
7299 "should be $expected"
7302 # Get and check the actual OST index of the first stripe on one file.
7303 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7304 check_start_ost_idx() {
7309 [[ -z "$file" || -z "$expected" ]] &&
7310 error "check_start_ost_idx: invalid argument!"
7312 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7315 [[ $start_ost_idx = $expected ]] ||
7316 error "OST index of the first stripe on $file is" \
7317 "$start_ost_idx, should be $expected"