3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
14 export GSS_PIPEFS=false
15 export IDENTITY_UPCALL=default
17 # specify environment variable containing batch job name for server statistics
18 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
20 #export PDSH="pdsh -S -Rssh -w"
21 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
22 export UMOUNT=${UMOUNT:-"umount -d"}
23 # sles12 umount has a issue with -d option
24 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
25 export UMOUNT="umount"
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
53 sanitize_parameters() {
54 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
57 if [ -d "$path" ]; then
58 eval export $i=$(echo $path | sed -r 's/\/+$//g')
64 [[ $DIR/ = $MOUNT/* ]] ||
65 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
66 [[ $DIR1/ = $MOUNT1/* ]] ||
67 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
68 [[ $DIR2/ = $MOUNT2/* ]] ||
69 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
71 [ -n "$failed" ] && exit 99 || true
75 echo "usage: $0 [-r] [-f cfgfile]"
83 [ -z "$DEFAULT_SUITES"] && return 0
84 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
86 local form="%-13s %-17s %-9s %s %s\n"
87 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
88 echo "------------------------------------------------------------------------------------"
89 for O in $DEFAULT_SUITES; do
90 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
91 [ "${!O}" = "no" ] && continue || true
92 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
93 local log=${TMP}/${o}.log
94 if is_sanity_benchmark $o; then
95 log=${TMP}/sanity-benchmark.log
100 local status=Unfinished
102 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
104 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
105 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
106 total=$(grep duration $log | awk '{ print $2 }')
107 if [ "${!O}" = "done" ]; then
111 local durations=$(egrep "^PASS|^FAIL" $log |
112 tr -d "("| sed s/s\)$//g |
113 awk '{ print $2":"$3"|" }')
114 details=$(printf "%s\n%s %s %s\n" "$details" \
115 "DDETAILS" "$O" "$(echo $durations)")
118 printf "$form" $status "$O" "${total}" "E=$skipped"
119 printf "$form" "-" "-" "-" "S=$(echo $slow)"
122 for O in $DEFAULT_SUITES; do
123 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
124 if [ "${!O}" = "no" ]; then
125 printf "$form" "Skipped" "$O" ""
129 # print the detailed tests durations if DDETAILS=true
136 export LUSTRE=$(absolute_path $LUSTRE)
137 export TESTSUITE=$(basename $0 .sh)
138 export TEST_FAILED=false
139 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
140 export RPC_MODE=${RPC_MODE:-false}
141 export DO_CLEANUP=${DO_CLEANUP:-true}
142 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
144 export MKE2FS=$MKE2FS
145 if [ -z "$MKE2FS" ]; then
146 if which mkfs.ldiskfs >/dev/null 2>&1; then
147 export MKE2FS=mkfs.ldiskfs
153 export DEBUGFS=$DEBUGFS
154 if [ -z "$DEBUGFS" ]; then
155 if which debugfs.ldiskfs >/dev/null 2>&1; then
156 export DEBUGFS=debugfs.ldiskfs
158 export DEBUGFS=debugfs
162 export TUNE2FS=$TUNE2FS
163 if [ -z "$TUNE2FS" ]; then
164 if which tunefs.ldiskfs >/dev/null 2>&1; then
165 export TUNE2FS=tunefs.ldiskfs
167 export TUNE2FS=tune2fs
171 export E2LABEL=$E2LABEL
172 if [ -z "$E2LABEL" ]; then
173 if which label.ldiskfs >/dev/null 2>&1; then
174 export E2LABEL=label.ldiskfs
176 export E2LABEL=e2label
180 export DUMPE2FS=$DUMPE2FS
181 if [ -z "$DUMPE2FS" ]; then
182 if which dumpfs.ldiskfs >/dev/null 2>&1; then
183 export DUMPE2FS=dumpfs.ldiskfs
185 export DUMPE2FS=dumpe2fs
189 export E2FSCK=$E2FSCK
190 if [ -z "$E2FSCK" ]; then
191 if which fsck.ldiskfs >/dev/null 2>&1; then
192 export E2FSCK=fsck.ldiskfs
198 export RESIZE2FS=$RESIZE2FS
199 if [ -z "$RESIZE2FS" ]; then
200 if which resizefs.ldiskfs >/dev/null 2>&1; then
201 export RESIZE2FS=resizefs.ldiskfs
203 export RESIZE2FS=resize2fs
207 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
208 export FSCK_MAX_ERR=4 # File system errors left uncorrected
210 export ZFS=${ZFS:-zfs}
211 export ZPOOL=${ZPOOL:-zpool}
212 export ZDB=${ZDB:-zdb}
213 export PARTPROBE=${PARTPROBE:-partprobe}
215 #[ -d /r ] && export ROOT=${ROOT:-/r}
216 export TMP=${TMP:-$ROOT/tmp}
217 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
218 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
219 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
221 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
222 if ! echo $PATH | grep -q $LUSTRE/utils; then
223 export PATH=$LUSTRE/utils:$PATH
225 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
226 export PATH=$LUSTRE/utils/gss:$PATH
228 if ! echo $PATH | grep -q $LUSTRE/tests; then
229 export PATH=$LUSTRE/tests:$PATH
231 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
232 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
234 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
235 [ ! -f "$LST" ] && export LST=$(which lst)
236 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
237 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
238 export MCREATE=${MCREATE:-mcreate}
239 # Ubuntu, at least, has a truncate command in /usr/bin
240 # so fully path our truncate command.
241 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
242 export FSX=${FSX:-$LUSTRE/tests/fsx}
243 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
244 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
245 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
246 export PATH=$LUSTRE/tests/racer:$PATH:
248 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
249 export PATH=$LUSTRE/tests/mpi:$PATH
251 export RSYNC_RSH=${RSYNC_RSH:-rsh}
253 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
254 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
255 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
256 [ ! -f "$LFS" ] && export LFS=$(which lfs)
257 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
258 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
260 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
261 if [ ! -f "$L_GETIDENTITY" ]; then
262 if `which l_getidentity > /dev/null 2>&1`; then
263 export L_GETIDENTITY=$(which l_getidentity)
265 export L_GETIDENTITY=NONE
268 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
269 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
270 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
271 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
272 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
273 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
274 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
275 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
276 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
277 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
278 [ ! -f "$LUSTRE_RMMOD" ] &&
279 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
280 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
281 [ ! -f "$LFS_MIGRATE" ] &&
282 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
283 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
284 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
285 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
286 export NAME=${NAME:-local}
287 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
288 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
289 export LGSSD=$(which lgssd)
290 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
291 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
292 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
294 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
296 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
297 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
299 if [ "$ACCEPTOR_PORT" ]; then
300 export PORT_OPT="--port $ACCEPTOR_PORT"
305 echo "Using GSS/krb5 ptlrpc security flavor"
306 which lgss_keyring > /dev/null 2>&1 || \
307 error_exit "built with gss disabled! SEC=$SEC"
318 IDENTITY_UPCALL=false
322 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
324 # Paths on remote nodes, if different
325 export RLUSTRE=${RLUSTRE:-$LUSTRE}
326 export RPWD=${RPWD:-$PWD}
327 export I_MOUNTED=${I_MOUNTED:-"no"}
328 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
329 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
330 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
331 ! -f $LUSTRE/mdt/mdt.ko ]; then
332 export CLIENTMODSONLY=yes
335 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
336 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
340 while getopts "rvwf:" opt $*; do
345 w) WRITECONF=writeconf;;
350 shift $((OPTIND - 1))
353 # print the durations of each test if "true"
354 DDETAILS=${DDETAILS:-false}
355 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
360 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
367 ncpts=$(do_facet $facet "lctl get_param -n " \
368 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
370 if [ $ncpts -eq 0 ]; then
377 # Return a numeric version code based on a version string. The version
378 # code is useful for comparison two version strings to see which is newer.
380 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
381 eval set -- $(tr "[:punct:]" " " <<< $*)
383 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
386 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
387 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
389 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
391 # usage: lustre_build_version
393 # All Lustre versions support "lctl get_param" to report the version of the
394 # code running in the kernel (what our tests are interested in), but it
395 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
396 # the "version" parameter doesn't include "lustre: " at the beginning.
397 # If that fails, call "lctl lustre_build_version" which prints either (or both)
398 # the userspace and kernel build versions, but until 2.8.55 required root
399 # access to get the Lustre kernel version. If that also fails, fall back to
400 # using "lctl --version", which is easy to parse and works without the kernel
401 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
402 # not the module version, though they are usually the same.
404 # Various commands and their output format for different Lustre versions:
405 # lctl get_param version: 2.9.55
406 # lctl get_param version: lustre: 2.8.53
407 # lctl get_param version: lustre: 2.6.52
408 # kernel: patchless_client
409 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
410 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
411 # lctl lustre_build_version: error: lustre_build_version: Permission denied
412 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
413 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
414 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
415 # lctl --version: lctl 2.6.50
417 # output: prints version string to stdout in (up to 4) dotted-decimal values
418 lustre_build_version() {
419 local facet=${1:-client}
422 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
423 $LCTL lustre_build_version 2>/dev/null ||
424 $LCTL --version 2>/dev/null | cut -d' ' -f2")
425 local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
426 [ -n "$lver" ] && ver="$lver"
428 sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
432 # Report the Lustre numeric build version code for the supplied facet.
433 lustre_version_code() {
434 version_code $(lustre_build_version $1)
438 /sbin/lsmod | grep -q "^\<$1\>"
441 # Load a module on the system where this is running.
443 # usage: load_module module_name [module arguments for insmod/modprobe]
445 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
446 # will be used as the arguments. Otherwise arguments will be obtained from
447 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
454 BASE=$(basename $module $EXT)
456 module_loaded ${BASE} && return
458 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
459 # else from modprobe.conf
460 if [ $# -eq 0 ]; then
461 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
462 # Bash until 4.x, so we resort to eval.
463 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
464 eval set -- \$$optvar
465 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
466 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
468 opt=$(awk -v var="^options $BASE" '$0 ~ var \
469 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
470 set -- $(echo -n $opt)
472 # Ensure we have accept=all for lnet
473 if [ $(basename $module) = lnet ]; then
474 # OK, this is a bit wordy...
475 local arg accept_all_present=false
478 [ "$arg" = accept=all ] && \
479 accept_all_present=true
481 $accept_all_present || set -- "$@" accept=all
487 [ $# -gt 0 ] && echo "${module} options: '$*'"
489 # Note that insmod will ignore anything in modprobe.conf, which is why
490 # we're passing options on the command-line.
491 if [[ "$BASE" == "lnet_selftest" ]] &&
492 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
493 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
494 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
495 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
496 insmod ${LUSTRE}/${module}${EXT} "$@"
498 # must be testing a "make install" or "rpm" installation
499 # note failed to load ptlrpc_gss is considered not fatal
500 if [[ "$BASE" == "ptlrpc_gss" ]]; then
501 modprobe $BASE "$@" 2>/dev/null ||
502 echo "gss/krb5 is not supported"
509 load_modules_local() {
510 if [ -n "$MODPROBE" ]; then
512 echo "Using modprobe to load modules"
516 echo Loading modules from $LUSTRE
520 if [ -f /sys/devices/system/cpu/online ]; then
521 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
522 echo "detected $ncpus online CPUs by sysfs"
524 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
526 if [ $rc -eq 0 ]; then
527 echo "detected $ncpus online CPUs by getconf"
529 echo "Can't detect number of CPUs"
534 # if there is only one CPU core, libcfs can only create one partition
535 # if there is more than 4 CPU cores, libcfs should create multiple CPU
536 # partitions. So we just force libcfs to create 2 partitions for
537 # system with 2 or 4 cores
538 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
539 # force to enable multiple CPU partitions
540 echo "Force libcfs to create 2 CPU partitions"
541 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
543 echo "libcfs will create CPU partition based on online CPUs"
546 load_module ../libcfs/libcfs/libcfs
547 # Prevent local MODOPTS_LIBCFS being passed as part of environment
548 # variable to remote nodes
552 load_module ../lnet/lnet/lnet
555 LNETLND="o2iblnd/ko2iblnd"
560 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
561 load_module ../lnet/klnds/$LNETLND
562 load_module obdclass/obdclass
563 load_module ptlrpc/ptlrpc
564 load_module ptlrpc/gss/ptlrpc_gss
572 load_module obdecho/obdecho
573 if ! client_only; then
574 SYMLIST=/proc/kallsyms
575 grep -q crc16 $SYMLIST ||
576 { modprobe crc16 2>/dev/null || true; }
577 grep -q -w jbd2 $SYMLIST ||
578 { modprobe jbd2 2>/dev/null || true; }
579 load_module lfsck/lfsck
580 [ "$LQUOTA" != "no" ] &&
581 load_module quota/lquota $LQUOTAOPTS
582 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
584 load_module osd-zfs/osd_zfs
586 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
587 grep -q exportfs_decode_fh $SYMLIST ||
588 { modprobe exportfs 2> /dev/null || true; }
589 grep -q -w mbcache $SYMLIST ||
590 { modprobe mbcache 2>/dev/null || true; }
591 load_module ../ldiskfs/ldiskfs
592 load_module osd-ldiskfs/osd_ldiskfs
604 load_module llite/lustre
605 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
607 rm -f $OGDB/ogdb-$HOSTNAME
608 $LCTL modules > $OGDB/ogdb-$HOSTNAME
610 # 'mount' doesn't look in $PATH, just sbin
611 local mount_lustre=$LUSTRE/utils/mount.lustre
612 if [ -f $mount_lustre ]; then
613 local sbin_mount=$(readlink -f /sbin)/mount.lustre
614 if grep -qw "$sbin_mount" /proc/mounts; then
615 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
617 if ! grep -qw "$sbin_mount" /proc/mounts; then
618 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
619 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
620 cat <<- EOF > "$sbin_mount"
623 echo "This $sbin_mount just a mountpoint." 1>&2
624 echo "It is never supposed to be run." 1>&2
625 logger -p emerg -- "using stub $sbin_mount $@"
628 chmod a+x $sbin_mount
630 mount --bind $mount_lustre $sbin_mount ||
631 error "can't bind $mount_lustre to $sbin_mount"
639 # load modules on remote nodes optionally
640 # lustre-tests have to be installed on these nodes
641 if $LOAD_MODULES_REMOTE; then
642 local list=$(comma_list $(remote_nodes_list))
643 if [ -n "$list" ]; then
644 echo "loading modules on: '$list'"
645 do_rpc_nodes "$list" load_modules_local
651 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
652 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
653 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
654 echo "$LEAK_LUSTRE" 1>&2
655 echo "$LEAK_PORTALS" 1>&2
656 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
657 echo "Memory leaks detected"
658 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
664 wait_exit_ST client # bug 12845
666 $LUSTRE_RMMOD ldiskfs || return 2
668 if $LOAD_MODULES_REMOTE; then
669 local list=$(comma_list $(remote_nodes_list))
670 if [ -n "$list" ]; then
671 echo "unloading modules on: '$list'"
672 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
673 do_rpc_nodes "$list" check_mem_leak
677 local sbin_mount=$(readlink -f /sbin)/mount.lustre
678 if grep -qe "$sbin_mount " /proc/mounts; then
679 umount $sbin_mount || true
680 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
684 check_mem_leak || return 254
686 echo "modules unloaded."
691 local facet=${1:-$SINGLEMDS}
692 local fstype=$(facet_fstype $facet)
695 ldiskfs) size=50;; # largest seen is 44, leave some headroom
696 zfs) size=400;; # largest seen is 384
703 local facet=${1:-$SINGLEMDS}
704 local fstype=$(facet_fstype $facet)
707 ldiskfs) size=4;; # ~4KB per inode
708 zfs) size=11;; # 10 to 11KB per inode
714 check_gss_daemon_nodes() {
718 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
719 if [ \\\"\\\$num\\\" -ne 1 ]; then
720 echo \\\$num instance of $dname;
725 check_gss_daemon_facet() {
729 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
730 if [ $num -ne 1 ]; then
731 echo "$num instance of $dname on $facet"
740 echo Stopping $@ on $list
741 do_nodes $list "killall -2 $@ 2>/dev/null || true"
744 # start gss daemons on all nodes, or
745 # "daemon" on "list" if set
746 start_gss_daemons() {
750 if [ "$list" ] && [ "$daemon" ] ; then
751 echo "Starting gss daemon on nodes: $list"
752 do_nodes $list "$daemon" || return 8
756 local list=$(comma_list $(mdts_nodes))
757 echo "Starting gss daemon on mds: $list"
758 do_nodes $list "$LSVCGSSD -v" || return 1
760 do_nodes $list "$LGSSD -v" || return 2
763 list=$(comma_list $(osts_nodes))
764 echo "Starting gss daemon on ost: $list"
765 do_nodes $list "$LSVCGSSD -v" || return 3
766 # starting on clients
768 local clients=${CLIENTS:-`hostname`}
770 echo "Starting $LGSSD on clients $clients "
771 do_nodes $clients "$LGSSD -v" || return 4
774 # wait daemons entering "stable" status
778 # check daemons are running
780 list=$(comma_list $(mdts_nodes) $(osts_nodes))
781 check_gss_daemon_nodes $list lsvcgssd || return 5
783 list=$(comma_list $(mdts_nodes))
784 check_gss_daemon_nodes $list lgssd || return 6
787 check_gss_daemon_nodes $clients lgssd || return 7
792 local list=$(comma_list $(mdts_nodes))
794 send_sigint $list lsvcgssd lgssd
796 list=$(comma_list $(osts_nodes))
797 send_sigint $list lsvcgssd
799 list=${CLIENTS:-`hostname`}
800 send_sigint $list lgssd
805 if ! module_loaded ptlrpc_gss; then
806 load_module ptlrpc/gss/ptlrpc_gss
807 module_loaded ptlrpc_gss ||
808 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
811 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
814 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
816 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
824 # maybe cleanup credential cache?
830 local var=${facet}_svc
838 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
839 tr '[:lower:]' '[:upper:]'
845 if [ $facet == mgs ] || [ $facet == client ]; then
849 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
857 if [ -n "${!var}" ]; then
862 var=$(facet_type $facet)FSTYPE
863 if [ -n "${!var}" ]; then
868 if [ -n "$FSTYPE" ]; then
873 if [[ $facet == mgs ]] && combined_mgs_mds; then
885 local facets=$(get_facets)
888 for facet in ${facets//,/ }; do
889 if [ $node == $(facet_host $facet) ] ||
890 [ $node == "$(facet_failover_host $facet)" ]; then
891 fstype=$(facet_fstype $facet)
892 if [[ $fstypes != *$fstype* ]]; then
893 fstypes+="${fstypes:+,}$fstype"
902 local num=$(facet_number $facet)
905 if [[ $(facet_type $facet) = OST ]]; then
907 if [[ -n "${!index}" ]]; then
912 index=${OST_INDICES[num - 1]}
915 [[ -n "$index" ]] || index=$((num - 1))
923 local fstype=$(facet_fstype $facet)
927 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
929 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
930 ${dev} 2>/dev/null");;
932 error "unknown fstype!";;
940 local device=$(mdsdevname $num)
941 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
947 local device=$(ostdevname $num)
948 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
953 # Get the device of a facet.
960 mgs) device=$(mgsdevname) ;;
961 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
962 ost*) device=$(ostdevname $(facet_number $facet)) ;;
963 fs2mds) device=$(mdsdevname 1_2) ;;
964 fs2ost) device=$(ostdevname 1_2) ;;
965 fs3ost) device=$(ostdevname 2_2) ;;
973 # Get the virtual device of a facet.
980 mgs) device=$(mgsvdevname) ;;
981 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
982 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
983 fs2mds) device=$(mdsvdevname 1_2) ;;
984 fs2ost) device=$(ostvdevname 1_2) ;;
985 fs3ost) device=$(ostvdevname 2_2) ;;
993 local virt=$(virt-what 2> /dev/null)
995 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
997 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1000 VMware|KVM|VirtualBox|Parallels)
1001 echo $virt | tr '[A-Z]' '[a-z]' ;;
1007 # Re-read the partition table on failover partner host.
1008 # After a ZFS storage pool is created on a shared device, the partition table
1009 # on the device may change. However, the operating system on the failover
1010 # host may not notice the change automatically. Without the up-to-date partition
1011 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1012 # relative to partition rather than disk beginnings.
1014 # This function performs partprobe on the failover host to make it re-read the
1017 refresh_partition_table() {
1022 host=$(facet_passive_host $facet)
1023 if [[ -n "$host" ]]; then
1024 do_node $host "$PARTPROBE $device"
1029 # Get ZFS storage pool name.
1036 device=$(facet_device $facet)
1037 # poolname is string before "/"
1038 poolname="${device%%/*}"
1044 # Create ZFS storage pool.
1051 local opts=${@:-"-o cachefile=none"}
1053 do_facet $facet "modprobe zfs;
1054 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1055 $ZPOOL create -f $opts $poolname $vdev"
1059 # Create ZFS file system.
1065 local opts=${@:-"-o mountpoint=legacy"}
1067 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1068 $ZFS create $opts $dataset"
1072 # Export ZFS storage pool.
1073 # Before exporting the pool, all datasets within the pool should be unmounted.
1081 poolname=$(zpool_name $facet)
1083 if [[ -n "$poolname" ]]; then
1084 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1085 grep -q ^$poolname/ /proc/mounts ||
1086 $ZPOOL export $opts $poolname"
1091 # Destroy ZFS storage pool.
1092 # Destroy the given pool and free up any devices for other use. This command
1093 # tries to unmount any active datasets before destroying the pool.
1094 # -f Force any active datasets contained within the pool to be unmounted.
1098 local poolname=${2:-$(zpool_name $facet)}
1100 if [[ -n "$poolname" ]]; then
1101 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1102 $ZPOOL destroy -f $poolname"
1107 # Import ZFS storage pool.
1108 # Force importing, even if the pool appears to be potentially active.
1113 local opts=${@:-"-o cachefile=none"}
1116 poolname=$(zpool_name $facet)
1118 if [[ -n "$poolname" ]]; then
1119 opts+=" -d $(dirname $(facet_vdevice $facet))"
1120 do_facet $facet "modprobe zfs;
1121 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1122 $ZPOOL import -f $opts $poolname"
1127 # Reimport ZFS storage pool with new name
1132 local opts="-o cachefile=none"
1133 local poolname=$(zpool_name $facet)
1135 opts+=" -d $(dirname $(facet_vdevice $facet))"
1136 do_facet $facet "$ZPOOL export $poolname;
1137 $ZPOOL import $opts $poolname $newpool"
1141 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1142 # is not automatically imported on system startup.
1144 # In a failover environment, this will provide resource level fencing which
1145 # will ensure that the same ZFS storage pool will not be imported concurrently
1146 # on different nodes.
1148 disable_zpool_cache() {
1152 poolname=$(zpool_name $facet)
1154 if [[ -n "$poolname" ]]; then
1155 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1160 # This and set_osd_param() shall be used to access OSD parameters
1161 # once existed under "obdfilter":
1166 # writethrough_cache_enable
1170 local device=${2:-$FSNAME-OST*}
1173 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1174 osd-*.$device.$name 2>&1" | grep -v 'error:'
1179 local device=${2:-$FSNAME-OST*}
1183 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1184 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1188 local dz=${1:-$DEBUG_SIZE}
1190 if [ -f /sys/devices/system/cpu/possible ]; then
1191 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1193 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1196 # bug 19944, adjust size to be -gt num_possible_cpus()
1197 # promise 2MB for every cpu at least
1198 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1201 lctl set_param debug_mb=$dz
1204 set_default_debug () {
1205 local debug=${1:-"$PTLDEBUG"}
1206 local subsys=${2:-"$SUBSYSTEM"}
1207 local debug_size=${3:-$DEBUG_SIZE}
1209 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1210 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1212 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1215 set_default_debug_nodes () {
1218 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1219 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1223 do_rpc_nodes "$nodes" set_default_debug \
1224 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1227 set_default_debug_facet () {
1229 local node=$(facet_active_host $facet)
1230 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1232 set_default_debug_nodes $node
1236 local hostid=${1:-$(hostid)}
1238 if [ ! -s /etc/hostid ]; then
1239 printf $(echo -n $hostid |
1240 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1246 local facets=${1:-$(get_facets)}
1249 for facet in ${facets//,/ }; do
1252 [ $RC -eq 0 ] && continue
1254 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1255 skip "Restart of $facet failed!." && touch $LU482_FAILED
1257 error "Restart of $facet failed!"
1264 # Add argument "arg" (e.g., "loop") to the comma-separated list
1265 # of arguments for option "opt" (e.g., "-o") on command
1266 # line "opts" (e.g., "-o flock").
1272 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1274 if echo "$opts" | grep -q $opt_pattern; then
1275 opts=$(echo "$opts" | sed -e \
1276 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1278 opts+="${opts:+ }$opt $arg"
1286 local dev=$(facet_active $facet)_dev
1287 local opt=${facet}_opt
1288 local mntpt=$(facet_mntpt $facet)
1289 local opts="${!opt} $@"
1290 local fstype=$(facet_fstype $facet)
1293 module_loaded lustre || load_modules
1295 if [ $(facet_fstype $facet) == ldiskfs ] &&
1296 ! do_facet $facet test -b ${!dev}; then
1297 opts=$(csa_add "$opts" -o loop)
1300 if [[ $(facet_fstype $facet) == zfs ]]; then
1301 # import ZFS storage pool
1302 import_zpool $facet || return ${PIPESTATUS[0]}
1307 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1309 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1310 lustre:svname ${!dev}");;
1312 error "unknown fstype!";;
1315 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1316 # for testing LU-482 error handling in mount_facets() and test_0a()
1317 if [ -f $TMP/test-lu482-trigger ]; then
1320 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1325 if [ $RC -ne 0 ]; then
1326 echo "Start of ${!dev} on ${facet} failed ${RC}"
1330 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1331 if [[ "$health" != "healthy" ]]; then
1332 error "$facet is in a unhealthy state"
1335 set_default_debug_facet $facet
1337 if [[ $facet == mds* ]]; then
1339 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1342 if [[ $opts =~ .*nosvc.* ]]; then
1343 echo "Start ${!dev} without service"
1348 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1349 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1350 "" || error "${!dev} failed to initialize!";;
1352 wait_update_facet ${facet} "$ZFS get -H -o value \
1353 lustre:svname ${!dev} 2>/dev/null | \
1354 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1355 error "${!dev} failed to initialize!";;
1358 error "unknown fstype!";;
1362 # commit the device label change to disk
1363 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1364 echo "Commit the device label on ${!dev}"
1365 do_facet $facet "sync; sync; sync"
1370 label=$(devicelabel ${facet} ${!dev})
1371 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1372 eval export ${facet}_svc=${label}
1373 echo Started ${label}
1378 # start facet device options
1384 eval export ${facet}_dev=${device}
1385 eval export ${facet}_opt=\"$@\"
1387 local varname=${facet}failover_dev
1388 if [ -n "${!varname}" ] ; then
1389 eval export ${facet}failover_dev=${!varname}
1391 eval export ${facet}failover_dev=$device
1394 local mntpt=$(facet_mntpt $facet)
1395 do_facet ${facet} mkdir -p $mntpt
1396 eval export ${facet}_MOUNT=$mntpt
1397 mount_facet ${facet}
1400 if [[ $facet == mds* ]]; then
1402 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1413 local HOST=`facet_active_host $facet`
1414 [ -z $HOST ] && echo stop: no host for $facet && return 0
1416 local mntpt=$(facet_mntpt $facet)
1417 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1418 if [ ${running} -ne 0 ]; then
1419 echo "Stopping $mntpt (opts:$@) on $HOST"
1420 do_facet ${facet} $UMOUNT $@ $mntpt
1423 # umount should block, but we should wait for unrelated obd's
1424 # like the MGS or MGC to also stop.
1425 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1427 if [[ $(facet_fstype $facet) == zfs ]]; then
1428 # export ZFS storage pool
1429 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1433 # save quota version (both administrative and operational quotas)
1434 # add an additional parameter if mountpoint is ever different from $MOUNT
1436 # XXX This function is kept for interoperability with old server (< 2.3.50),
1437 # it should be removed whenever we drop the interoperability for such
1439 quota_save_version() {
1440 local fsname=${2:-$FSNAME}
1442 local ver=$(tr -c -d "123" <<< $spec)
1443 local type=$(tr -c -d "ug" <<< $spec)
1445 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1447 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1449 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1451 local osts=$(get_facets OST)
1452 for ost in ${osts//,/ }; do
1454 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1458 # client could mount several lustre
1460 # XXX This function is kept for interoperability with old server (< 2.3.50),
1461 # it should be removed whenever we drop the interoperability for such
1464 local fsname=${1:-$FSNAME}
1466 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1468 do_nodes $(comma_list $(osts_nodes)) \
1469 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1473 # get mdt quota type
1475 local varsvc=${SINGLEMDS}_svc
1476 do_facet $SINGLEMDS $LCTL get_param -n \
1477 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1480 # get ost quota type
1482 # All OSTs should have same quota type
1483 local varsvc=ost1_svc
1484 do_facet ost1 $LCTL get_param -n \
1485 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1488 # restore old quota type settings
1490 if [ "$old_MDT_QUOTA_TYPE" ]; then
1491 do_facet mgs $LCTL conf_param \
1492 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1494 if [ "$old_OST_QUOTA_TYPE" ]; then
1495 do_facet mgs $LCTL conf_param \
1496 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1500 # Handle the case when there is a space in the lfs df
1501 # "filesystem summary" line the same as when there is no space.
1502 # This will allow fixing the "lfs df" summary line in the future.
1504 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1507 # Get free inodes on the MDT specified by mdt index, free indoes on
1508 # the whole filesystem will be returned when index == -1.
1514 if [ $index -eq -1 ]; then
1517 mdt_uuid=$(mdtuuid_from_index $index)
1520 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1527 # save old quota type & set new quota type
1528 local mdt_qtype=$(mdt_quota_type)
1529 local ost_qtype=$(ost_quota_type)
1531 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1532 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1534 export old_MDT_QUOTA_TYPE=$mdt_qtype
1535 export old_OST_QUOTA_TYPE=$ost_qtype
1537 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1538 error "set mdt quota type failed"
1539 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1540 error "set ost quota type failed"
1542 local quota_usrs=$QUOTA_USERS
1544 # get_filesystem_size
1545 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1546 local blk_soft=$((disksz + 1024))
1547 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1549 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1550 local i_soft=$inodes
1551 local i_hard=$((i_soft + i_soft / 20))
1553 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1554 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1555 "inode-hardlimit: $i_hard"
1558 for usr in $quota_usrs; do
1559 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1561 cmd="$LFS setquota -$type $usr -b $blk_soft"
1562 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1564 eval $cmd || error "$cmd FAILED!"
1566 # display the quota status
1567 echo "Quota settings for $usr : "
1568 $LFS quota -v -u $usr $mntpt || true
1575 local opts=${3:-$MOUNT_OPTS}
1576 opts=${opts:+-o $opts}
1577 local flags=${4:-$MOUNT_FLAGS}
1579 local device=$MGSNID:/$FSNAME$FILESET
1580 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1581 echo "Bad mount command: opt=$flags $opts dev=$device " \
1586 echo "Starting client: $client: $flags $opts $device $mnt"
1587 do_node $client mkdir -p $mnt
1588 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1589 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1591 #disable FILESET if not supported
1592 do_nodes $client lctl get_param -n \
1593 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1594 device=$MGSNID:/$FSNAME
1595 do_node $client mkdir -p $mnt/$FILESET
1596 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1599 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1601 set_default_debug_nodes $client
1613 [ "$3" ] && force=-f
1614 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1615 if [ $running -ne 0 ]; then
1616 echo "Stopping client $client $mnt (opts:$force)"
1617 do_node $client lsof -t $mnt || need_kill=no
1618 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1619 pids=$(do_node $client lsof -t $mnt | sort -u);
1620 if [ -n $pids ]; then
1621 do_node $client kill -9 $pids || true
1625 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1626 if [ $busy -ne 0 ] ; then
1627 echo "$mnt is still busy, wait one second" && sleep 1
1628 do_node $client umount $force $mnt
1633 # nodes is comma list
1634 sanity_mount_check_nodes () {
1640 # FIXME: assume that all cluster nodes run the same os
1641 [ "$(uname)" = Linux ] || return 0
1644 for mnt in $mnts ; do
1645 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1646 mpts=\\\$(mount | grep -c $mnt' ');
1647 if [ \\\$running -ne \\\$mpts ]; then
1648 echo \\\$(hostname) env are INSANE!;
1651 [ $? -eq 0 ] || rc=1
1656 sanity_mount_check_servers () {
1657 [ -n "$CLIENTONLY" ] &&
1658 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1659 echo Checking servers environments
1661 # FIXME: modify get_facets to display all facets wo params
1662 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1666 for facet in ${facets//,/ }; do
1667 node=$(facet_host ${facet})
1668 mntpt=$(facet_mntpt $facet)
1669 sanity_mount_check_nodes $node $mntpt ||
1670 { error "server $node environments are insane!"; return 1; }
1674 sanity_mount_check_clients () {
1675 local clients=${1:-$CLIENTS}
1676 local mntpt=${2:-$MOUNT}
1677 local mntpt2=${3:-$MOUNT2}
1679 [ -z $clients ] && clients=$(hostname)
1680 echo Checking clients $clients environments
1682 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1683 error "clients environments are insane!"
1686 sanity_mount_check () {
1687 sanity_mount_check_servers || return 1
1688 sanity_mount_check_clients || return 2
1691 # mount clients if not mouted
1692 zconf_mount_clients() {
1695 local opts=${3:-$MOUNT_OPTS}
1696 opts=${opts:+-o $opts}
1697 local flags=${4:-$MOUNT_FLAGS}
1699 local device=$MGSNID:/$FSNAME$FILESET
1700 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1701 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1706 echo "Starting client $clients: $flags $opts $device $mnt"
1707 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1708 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1710 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1712 #disable FILESET if not supported
1713 do_nodes $clients lctl get_param -n \
1714 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1715 device=$MGSNID:/$FSNAME
1716 do_nodes $clients mkdir -p $mnt/$FILESET
1717 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1722 running=\\\$(mount | grep -c $mnt' ');
1724 if [ \\\$running -eq 0 ] ; then
1726 $MOUNT_CMD $flags $opts $device $mnt;
1729 exit \\\$rc" || return ${PIPESTATUS[0]}
1731 echo "Started clients $clients: "
1732 do_nodes $clients "mount | grep $mnt' '"
1734 set_default_debug_nodes $clients
1739 zconf_umount_clients() {
1744 [ "$3" ] && force=-f
1746 echo "Stopping clients: $clients $mnt (opts:$force)"
1747 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1748 if [ \\\$running -ne 0 ] ; then
1749 echo Stopping client \\\$(hostname) $mnt opts:$force;
1750 lsof $mnt || need_kill=no;
1751 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1752 pids=\\\$(lsof -t $mnt | sort -u);
1753 if [ -n \\\"\\\$pids\\\" ]; then
1757 while umount $force $mnt 2>&1 | grep -q "busy"; do
1758 echo "$mnt is still busy, wait one second" && sleep 1;
1765 echo + $POWER_DOWN $node
1769 shutdown_node_hard () {
1771 local attempts=$SHUTDOWN_ATTEMPTS
1773 for i in $(seq $attempts) ; do
1776 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1777 echo "waiting for $host to fail attempts=$attempts"
1778 [ $i -lt $attempts ] || \
1779 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1785 local mnt=${2:-$MOUNT}
1788 if [ "$FAILURE_MODE" = HARD ]; then
1789 shutdown_node_hard $client
1791 zconf_umount_clients $client $mnt -f
1797 local facets="$(get_facets OST),$(get_facets MDS)"
1800 combined_mgs_mds || facets="$facets,mgs"
1802 for facet in ${facets//,/ }; do
1803 if [ $(facet_active_host $facet) == $host ]; then
1804 affected="$affected $facet"
1808 echo $(comma_list $affected)
1813 local host=${2:-$(facet_host $facet)}
1815 local label=$(convert_facet2label $facet)
1816 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1819 facets_up_on_host () {
1821 local facets=$(facets_on_host $host)
1824 for facet in ${facets//,/ }; do
1825 if $(facet_up $facet $host); then
1826 affected_up="$affected_up $facet"
1830 echo $(comma_list $affected_up)
1836 if [ "$FAILURE_MODE" = HARD ]; then
1837 shutdown_node_hard $(facet_active_host $facet)
1845 echo + $POWER_UP $node
1858 if [ "$FAILURE_MODE" = HARD ]; then
1859 reboot_node $(facet_active_host $facet)
1867 if [ "$FAILURE_MODE" = HARD ]; then
1877 for facet in ${facets//,/ }; do
1878 hosts=$(expand_list $hosts $(facet_host $facet) )
1884 _check_progs_installed () {
1888 for prog in $progs; do
1889 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1890 echo $prog missing on $(hostname)
1897 check_progs_installed () {
1901 do_rpc_nodes "$nodes" _check_progs_installed $@
1904 # recovery-scale functions
1906 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1909 start_client_load() {
1912 local var=$(node_var_name $client)_load
1913 eval export ${var}=$load
1915 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1916 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1917 END_RUN_FILE=$END_RUN_FILE \
1918 LOAD_PID_FILE=$LOAD_PID_FILE \
1919 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1920 TESTNAME=$TESTNAME \
1921 DBENCH_LIB=$DBENCH_LIB \
1922 DBENCH_SRC=$DBENCH_SRC \
1923 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1927 log "Started client load: ${load} on $client"
1929 # get the children process IDs
1930 local pids=$(ps --ppid $ppid -o pid= | xargs)
1931 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1935 start_client_loads () {
1936 local -a clients=(${1//,/ })
1937 local numloads=${#CLIENT_LOADS[@]}
1940 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1941 testnum=$((nodenum % numloads))
1942 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1944 # bug 22169: wait the background threads to start
1948 # only for remote client
1949 check_client_load () {
1951 local var=$(node_var_name $client)_load
1952 local testload=run_${!var}.sh
1954 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
1956 # bug 18914: try to connect several times not only when
1957 # check ps, but while check_node_health also
1961 while [ $RC = 254 -a $tries -gt 0 ]; do
1965 if ! check_node_health $client; then
1967 if [ $RC -eq 254 ]; then
1968 # FIXME: not sure how long we shuold sleep here
1972 echo "check node health failed: RC=$RC "
1976 # We can continue try to connect if RC=254
1977 # Just print the warning about this
1978 if [ $RC = 254 ]; then
1979 echo "got a return status of $RC from do_node while checking " \
1980 "node health on $client"
1983 # see if the load is still on the client
1986 while [ $RC = 254 -a $tries -gt 0 ]; do
1990 if ! do_node $client \
1991 "ps auxwww | grep -v grep | grep -q $testload"; then
1996 if [ $RC = 254 ]; then
1997 echo "got a return status of $RC from do_node while checking " \
1998 "(node health and 'ps') the client load on $client"
1999 # see if we can diagnose a bit why this is
2004 check_client_loads () {
2005 local clients=${1//,/ }
2009 for client in $clients; do
2010 check_client_load $client
2012 if [ "$rc" != 0 ]; then
2013 log "Client load failed on node $client, rc=$rc"
2019 restart_client_loads () {
2020 local clients=${1//,/ }
2021 local expectedfail=${2:-""}
2025 for client in $clients; do
2026 check_client_load $client
2028 if [ "$rc" != 0 -a "$expectedfail" ]; then
2029 local var=$(node_var_name $client)_load
2030 start_client_load $client ${!var}
2031 echo "Restarted client load ${!var}: on $client. Checking ..."
2032 check_client_load $client
2034 if [ "$rc" != 0 ]; then
2035 log "Client load failed to restart on node $client, rc=$rc"
2036 # failure one client load means test fail
2037 # we do not need to check other
2046 # Start vmstat and save its process ID in a file.
2051 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2054 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2055 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2058 # Display the nodes on which client loads failed.
2059 print_end_run_file() {
2063 [ -s $file ] || return 0
2065 echo "Found the END_RUN_FILE file: $file"
2068 # A client load will stop if it finds the END_RUN_FILE file.
2069 # That does not mean the client load actually failed though.
2070 # The first node in END_RUN_FILE is the one we are interested in.
2073 if [ -n "$node" ]; then
2074 local var=$(node_var_name $node)_load
2076 local prefix=$TESTLOG_PREFIX
2077 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2078 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2079 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2081 echo "Client load ${!var} failed on node $node:"
2087 # Stop the process which had its PID saved in a file.
2092 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2094 do_nodes $nodes "test -f $pid_file &&
2095 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2098 # Stop all client loads.
2099 stop_client_loads() {
2100 local nodes=${1:-$CLIENTS}
2103 # stop the client loads
2104 stop_process $nodes $pid_file
2106 # clean up the processes that started them
2107 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2109 # End recovery-scale functions
2111 # verify that lustre actually cleaned up properly
2113 VAR=$(lctl get_param -n catastrophe 2>&1)
2114 if [ $? = 0 ] ; then
2115 if [ $VAR != 0 ]; then
2116 error "LBUG/LASSERT detected"
2119 BUSY=$(dmesg | grep -i destruct || true)
2120 if [ -n "$BUSY" ]; then
2122 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2126 check_mem_leak || exit 204
2128 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2129 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2132 if module_loaded lnet || module_loaded libcfs; then
2133 echo "$TESTSUITE: modules still loaded..." 1>&2
2142 if [[ "$1" == "--verbose" ]]; then
2157 PREV_RESULT=$(do_node $node "$TEST")
2159 RESULT=$(do_node $node "$TEST")
2160 if [[ "$RESULT" == "$FINAL" ]]; then
2161 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2162 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2166 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2167 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2171 [[ $WAIT -ge $MAX ]] && break
2172 [[ $((WAIT % print)) -eq 0 ]] &&
2173 echo "Waiting $((MAX - WAIT)) secs for update"
2174 WAIT=$((WAIT + sleep))
2177 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2181 wait_update_facet() {
2183 [ "$1" = "--verbose" ] && verbose="$1" && shift
2187 wait_update $verbose $(facet_active_host $facet) "$@"
2191 do_nodes $(comma_list $(mdts_nodes)) \
2192 "lctl set_param -n osd*.*MDT*.force_sync=1"
2193 do_nodes $(comma_list $(osts_nodes)) \
2194 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2195 grep -v 'Found no match'
2199 # the occupied disk space will be released
2200 # only after DMUs are committed
2201 if [[ $(facet_fstype $1) == zfs ]]; then
2202 echo "sleep $2 for ZFS OSD"
2207 wait_delete_completed_mds() {
2208 local MAX_WAIT=${1:-20}
2209 # for ZFS, waiting more time for DMUs to be committed
2210 local ZFS_WAIT=${2:-5}
2212 local stime=$(date +%s)
2217 # find MDS with pending deletions
2218 for node in $(mdts_nodes); do
2219 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2220 2>/dev/null | calc_sum)
2221 if [[ $changes -eq 0 ]]; then
2224 mds2sync="$mds2sync $node"
2226 if [ -z "$mds2sync" ]; then
2227 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2230 mds2sync=$(comma_list $mds2sync)
2232 # sync MDS transactions
2233 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2235 # wait till all changes are sent and commmitted by OSTs
2236 # for ldiskfs space is released upon execution, but DMU
2237 # do this upon commit
2240 while [[ $WAIT -ne $MAX_WAIT ]]; do
2241 changes=$(do_nodes $mds2sync \
2242 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2243 #echo "$node: $changes changes on all"
2244 if [[ $changes -eq 0 ]]; then
2245 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2253 echo "Delete is not completed in $((etime - stime)) seconds"
2254 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2260 # we can use "for" here because we are waiting the slowest
2261 for host in ${hostlist//,/ }; do
2262 check_network "$host" 900
2264 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2271 for facet in ${facetlist//,/ }; do
2272 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2274 wait_for_host $hostlist
2277 _wait_recovery_complete () {
2280 # Use default policy if $2 is not passed by caller.
2281 local MAX=${2:-$(max_recovery_time)}
2286 while [ $WAIT -lt $MAX ]; do
2287 STATUS=$(lctl get_param -n $param | grep status)
2289 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2292 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2294 echo "$param recovery not done in $MAX sec. $STATUS"
2298 wait_recovery_complete () {
2301 # with an assumption that at_max is the same on all nodes
2302 local MAX=${2:-$(max_recovery_time)}
2305 if [ "$FAILURE_MODE" = HARD ]; then
2306 facets=$(facets_on_host $(facet_active_host $facet))
2308 echo affected facets: $facets
2310 # we can use "for" here because we are waiting the slowest
2311 for facet in ${facets//,/ }; do
2312 local var_svc=${facet}_svc
2313 local param="*.${!var_svc}.recovery_status"
2315 local host=$(facet_active_host $facet)
2316 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2320 wait_mds_ost_sync () {
2321 # just because recovery is done doesn't mean we've finished
2322 # orphan cleanup. Wait for llogs to get synchronized.
2323 echo "Waiting for orphan cleanup..."
2324 # MAX value includes time needed for MDS-OST reconnection
2325 local MAX=$(( TIMEOUT * 2 ))
2326 local WAIT_TIMEOUT=${1:-$MAX}
2329 local list=$(comma_list $(mdts_nodes))
2330 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2331 if ! do_facet $SINGLEMDS \
2332 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2334 # old way, use mds_sync
2336 list=$(comma_list $(osts_nodes))
2337 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2340 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2341 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2342 local -a sync=($(do_nodes $list "$cmd"))
2345 for ((i=0; i<${#sync[@]}; i++)); do
2347 [ ${sync[$i]} -eq 1 ] && continue
2349 [ ${sync[$i]} -eq 0 ] && continue
2351 # there is a not finished MDS-OST synchronization
2355 sleep 2 # increase waiting time and cover statfs cache
2356 [ ${con} -eq 1 ] && return 0
2357 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2361 # show which nodes are not finished.
2362 do_nodes $list "$cmd"
2363 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2367 # Wait OSTs to be active on both client and MDT side.
2369 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2370 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2371 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2372 error "wait_update OSTs up on client failed"
2374 cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
2375 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2376 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2377 error "wait_update OSTs up on MDT failed"
2380 wait_destroy_complete () {
2381 echo "Waiting for local destroys to complete"
2382 # MAX value shouldn't be big as this mean server responsiveness
2383 # never increase this just to make test pass but investigate
2384 # why it takes so long time
2387 while [ $WAIT -lt $MAX ]; do
2388 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2392 for ((i=0; i<${#RPCs[@]}; i++)); do
2393 [ ${RPCs[$i]} -eq 0 ] && continue
2394 # there are still some destroy RPCs in flight
2399 [ ${con} -eq 1 ] && return 0 # done waiting
2400 echo "Waiting ${WAIT}s for local destroys to complete"
2403 echo "Local destroys weren't done in $MAX sec."
2407 wait_delete_completed() {
2408 wait_delete_completed_mds $1 || return $?
2409 wait_destroy_complete
2418 # conf-sanity 31 takes a long time cleanup
2419 while [ $WAIT -lt 300 ]; do
2420 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2421 [ -z "${running}" ] && return 0
2422 echo "waited $WAIT for${running}"
2423 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2425 WAIT=$((WAIT + INTERVAL))
2427 echo "service didn't stop after $WAIT seconds. Still running:"
2432 wait_remote_prog () {
2438 [ "$PDSH" = "no_dsh" ] && return 0
2440 while [ $WAIT -lt $2 ]; do
2441 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2442 [ -z "${running}" ] && return 0 || true
2443 echo "waited $WAIT for: "
2445 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2447 WAIT=$((WAIT + INTERVAL))
2449 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2450 [ -z "$pids" ] && return 0
2451 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2452 # FIXME: not portable
2453 for pid in $pids; do
2454 cat /proc/${pid}/status || true
2455 cat /proc/${pid}/wchan || true
2457 kill -9 $pid || true
2466 local clients=${1:-$CLIENTS}
2468 if [ -z "$clients" ]; then
2471 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2477 # not every config has many clients
2483 # usually checked on particular client or locally
2492 client_reconnect_try() {
2493 local f=$MOUNT/recon
2496 if [ -z "$CLIENTS" ]; then
2497 $LFS df $MOUNT; uname -n >> $f
2499 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2501 echo "Connected clients: $(cat $f)"
2502 ls -l $f > /dev/null
2506 client_reconnect() {
2507 # one client_reconnect_try call does not always do the job...
2509 client_reconnect_try && break
2514 affected_facets () {
2517 local host=$(facet_active_host $facet)
2518 local affected=$facet
2520 if [ "$FAILURE_MODE" = HARD ]; then
2521 affected=$(facets_up_on_host $host)
2527 local E2FSCK_ON_MDT0=false
2528 if [ "$1" == "--fsck" ]; then
2530 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2542 #Because it will only get up facets, we need get affected
2543 #facets before shutdown
2544 #For HARD Failure mode, it needs make sure facets on the same
2545 #HOST will only be shutdown and reboot once
2546 for facet in ${facets//,/ }; do
2547 local affected_facet
2549 #check whether facet has been included in other affected facets
2550 for ((index=0; index<$total; index++)); do
2551 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2554 if [ $skip -eq 0 ]; then
2555 affecteds[$total]=$(affected_facets $facet)
2560 for ((index=0; index<$total; index++)); do
2561 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2562 local host=$(facet_active_host $facet)
2563 echo "Failing ${affecteds[index]} on $host"
2564 shutdown_facet $facet
2567 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2568 $(mdsdevname 1) "-n" || error "Running e2fsck")
2570 for ((index=0; index<$total; index++)); do
2571 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2572 echo reboot facets: ${affecteds[index]}
2576 change_active ${affecteds[index]}
2578 wait_for_facet ${affecteds[index]}
2579 # start mgs first if it is affected
2580 if ! combined_mgs_mds &&
2581 list_member ${affecteds[index]} mgs; then
2582 mount_facet mgs || error "Restart of mgs failed"
2584 # FIXME; has to be changed to mount all facets concurrently
2585 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2586 echo mount facets: ${affecteds[index]}
2587 mount_facets ${affecteds[index]}
2597 do_facet $facet "sync; sync; sync"
2600 # make sure there will be no seq change
2601 local clients=${CLIENTS:-$HOSTNAME}
2602 local f=fsa-\\\$\(hostname\)
2603 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2604 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2606 local svc=${facet}_svc
2607 do_facet $facet $LCTL --device ${!svc} notransno
2609 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2610 # in-memory state has to be cleared by either rebooting the host or
2611 # exporting and reimporting the pool.
2613 # Although the uberblocks are not updated when a pool is freezed,
2614 # transactions are still written to the disks. Modified blocks may be
2615 # cached in memory when tests try reading them back. The
2616 # export-and-reimport process also evicts any cached pool data from
2617 # memory to provide the correct "data loss" semantics.
2619 # In the test framework, the exporting and importing operations are
2620 # handled by stop() and mount_facet() separately, which are used
2621 # inside fail() and fail_abort().
2623 do_facet $facet $LCTL --device ${!svc} readonly
2624 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2625 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2628 replay_barrier_nodf() {
2629 local facet=$1 echo running=${running}
2630 do_facet $facet "sync; sync; sync"
2631 local svc=${facet}_svc
2632 echo Replay barrier on ${!svc}
2633 do_facet $facet $LCTL --device ${!svc} notransno
2634 do_facet $facet $LCTL --device ${!svc} readonly
2635 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2636 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2639 replay_barrier_nosync() {
2640 local facet=$1 echo running=${running}
2641 local svc=${facet}_svc
2642 echo Replay barrier on ${!svc}
2643 do_facet $facet $LCTL --device ${!svc} notransno
2644 do_facet $facet $LCTL --device ${!svc} readonly
2645 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2646 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2650 # Get Lustre client uuid for a given Lustre mount point.
2653 local mntpnt=${1:-$MOUNT}
2655 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2656 local uuid=$($LCTL get_param -n llite.$name.uuid)
2661 mds_evict_client() {
2662 local mntpnt=${1:-$MOUNT}
2663 local uuid=$(get_client_uuid $mntpnt)
2665 do_facet $SINGLEMDS \
2666 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2669 ost_evict_client() {
2670 local mntpnt=${1:-$MOUNT}
2671 local uuid=$(get_client_uuid $mntpnt)
2674 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2679 local clients=${CLIENTS:-$HOSTNAME}
2681 facet_failover $* || error "failover: $?"
2682 wait_clients_import_state "$clients" "$facets" FULL
2683 clients_up || error "post-failover stat: $?"
2688 facet_failover $facet
2694 change_active $facet
2695 wait_for_facet $facet
2696 mount_facet $facet -o abort_recovery
2697 clients_up || echo "first stat failed: $?"
2698 clients_up || error "post-failover stat: $?"
2702 echo There is no lmc. This is mountconf, baby.
2706 host_nids_address() {
2710 if [ -n "$kind" ]; then
2711 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2713 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2719 if [ "$1" = "'*'" ]; then echo \'*\'; else
2725 if [ "$1" = "'*'" ]; then echo \'*\'; else
2726 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2728 if [ -z "$ID" ]; then
2729 echo "Could not get a ptl id for $1..."
2738 h2name_or_ip "$1" "tcp"
2743 if [ "$1" = "'*'" ]; then echo \'*\'; else
2744 if type __h2elan >/dev/null 2>&1; then
2747 ID=`echo $1 | sed 's/[^0-9]*//g'`
2755 h2name_or_ip "$1" "o2ib"
2759 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2760 # expressions format. As a bonus we can then just pass in those variables
2761 # to pdsh. What this function does is take a HOSTLIST type string and
2762 # expand it into a space deliminated list for us.
2770 [ -z "$hostlist" ] && return
2772 # Translate the case of [..],..,[..] to [..] .. [..]
2773 list="${hostlist/],/] }"
2775 [[ "$front" == *,* ]] && {
2778 list=${list/${old}/${new}}
2781 for item in $list; do
2782 # Test if we have any []'s at all
2783 if [ "$item" != "${item/\[/}" ]; then {
2784 # Expand the [*] into list
2788 if [ "$name" != "$item" ]; then
2789 group=${item#$name[*}
2792 for range in ${group//,/ }; do
2796 # Number of leading zeros
2799 end=$(echo $end | sed 's/0*//')
2800 [[ -z "$end" ]] && end=0
2801 [[ $padlen2 -gt $padlen ]] && {
2802 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2805 begin=$(echo $begin | sed 's/0*//')
2806 [ -z $begin ] && begin=0
2808 for num in $(seq -f "%0${padlen}g" $begin $end); do
2809 value="${name#*,}${num}${back}"
2810 [ "$value" != "${value/\[/}" ] && {
2811 value=$(hostlist_expand "$value")
2813 myList="$myList $value"
2818 myList="$myList $item"
2821 myList=${myList//,/ }
2822 myList=${myList:1} # Remove first character which is a space
2824 # Filter any duplicates without sorting
2826 myList="${list%% *}"
2828 while [[ "$list" != ${myList##* } ]]; do
2829 local tlist=" $list"
2830 list=${tlist// ${list%% *} / }
2832 myList="$myList ${list%% *}"
2834 myList="${myList%* }";
2836 # We can select an object at an offset in the list
2839 for item in $myList; do
2841 [ $cnt -eq $offset ] && {
2845 [ $(get_node_count $myList) -ne 1 ] && myList=""
2854 [ "$facet" == client ] && echo -n $HOSTNAME && return
2855 varname=${facet}_HOST
2856 if [ -z "${!varname}" ]; then
2857 if [ "${facet:0:3}" == "ost" ]; then
2858 local fh=${facet%failover}_HOST
2859 eval export ${facet}_HOST=${!fh}
2860 if [ -z "${!varname}" ]; then
2861 eval export ${facet}_HOST=${ost_HOST}
2863 elif [ "${facet:0:3}" == "mdt" -o \
2864 "${facet:0:3}" == "mds" -o \
2865 "${facet:0:3}" == "mgs" ]; then
2866 eval export ${facet}_HOST=${mds_HOST}
2872 facet_failover_host() {
2876 var=${facet}failover_HOST
2877 if [ -n "${!var}" ]; then
2882 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2883 "${facet:0:3}" == "mgs" ]; then
2885 eval export ${facet}failover_host=${mds_HOST}
2890 if [[ $facet == ost* ]]; then
2891 eval export ${facet}failover_host=${ost_HOST}
2899 local activevar=${facet}active
2901 if [ -f $TMP/${facet}active ] ; then
2902 source $TMP/${facet}active
2905 active=${!activevar}
2906 if [ -z "$active" ] ; then
2913 facet_active_host() {
2914 facet_host $(facet_active $1)
2917 # Get the passive failover partner host of facet.
2918 facet_passive_host() {
2920 [[ $facet = client ]] && return
2922 local host=${facet}_HOST
2923 local failover_host=${facet}failover_HOST
2924 local active_host=$(facet_active_host $facet)
2926 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2928 if [[ $active_host = ${!host} ]]; then
2929 echo -n ${!failover_host}
2939 facetlist=$(exclude_items_from_list $facetlist mgs)
2941 for facet in ${facetlist//,/ }; do
2942 local failover=${facet}failover
2943 local host=`facet_host $failover`
2944 [ -z "$host" ] && return
2946 local curactive=`facet_active $facet`
2947 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2948 eval export ${facet}active=$facet
2950 eval export ${facet}active=$failover
2952 # save the active host for this facet
2953 local activevar=${facet}active
2954 echo "$activevar=${!activevar}" > $TMP/$activevar
2955 [[ $facet = mds1 ]] && combined_mgs_mds && \
2956 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2957 local TO=`facet_active_host $facet`
2958 echo "Failover $facet to $TO"
2964 # do not stripe off hostname if verbose, bug 19215
2965 if [ x$1 = x--verbose ]; then
2973 if [ "$HOST" = "$HOSTNAME" ]; then
2975 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2976 echo "cannot run remote command on $HOST with $myPDSH"
2980 echo "CMD: $HOST $@" >&2
2981 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2984 if [ "$myPDSH" = "rsh" ]; then
2985 # we need this because rsh does not return exit code of an executed command
2986 local command_status="$TMP/cs"
2987 rsh $HOST ":> $command_status"
2988 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2989 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2990 echo command failed >$command_status"
2991 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2996 # print HOSTNAME for myPDSH="no_dsh"
2997 if [[ $myPDSH = no_dsh ]]; then
2998 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3000 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3003 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3005 return ${PIPESTATUS[0]}
3009 do_node --verbose "$@"
3012 single_local_node () {
3013 [ "$1" = "$HOSTNAME" ]
3016 # Outputs environment variable assignments that should be passed to remote nodes
3020 local facets=$(get_facets)
3023 for var in ${!MODOPTS_*}; do
3024 value=${!var//\"/\\\"}
3025 echo -n " ${var}=\"$value\""
3028 for facet in ${facets//,/ }; do
3030 if [ -n "${!var}" ]; then
3031 echo -n " $var=${!var}"
3035 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3036 if [ -n "${!var}" ]; then
3037 echo -n " $var=${!var}"
3041 for var in VERBOSE; do
3042 if [ -n "${!var}" ]; then
3043 echo -n " $var=${!var}"
3047 if [ -n "$FSTYPE" ]; then
3048 echo -n " FSTYPE=$FSTYPE"
3051 for var in LNETLND NETTYPE; do
3052 if [ -n "${!var}" ]; then
3053 echo -n " $var=${!var}"
3060 # do not stripe off hostname if verbose, bug 19215
3061 if [ x$1 = x--verbose ]; then
3069 if single_local_node $rnodes; then
3071 do_nodev $rnodes "$@"
3073 do_node $rnodes "$@"
3078 # This is part from do_node
3081 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3082 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3084 export FANOUT=$(get_node_count "${rnodes//,/ }")
3086 echo "CMD: $rnodes $@" >&2
3087 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3090 # do not replace anything from pdsh output if -N is used
3091 # -N Disable hostname: prefix on lines of output.
3092 if $verbose || [[ $myPDSH = *-N* ]]; then
3093 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3095 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3097 return ${PIPESTATUS[0]}
3101 # Execute commands on a single service's host
3103 # The \a facet (service) may be on a local or remote node, which is
3104 # determined at the time the command is run.
3106 # usage: do_facet $facet command [arg ...]
3110 local HOST=$(facet_active_host $facet)
3111 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3115 # Function: do_facet_random_file $FACET $FILE $SIZE
3116 # Creates FILE with random content on the given FACET of given SIZE
3118 do_facet_random_file() {
3122 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3123 do_facet $facet "$cmd 2>/dev/null"
3126 do_facet_create_file() {
3130 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3131 do_facet $facet "$cmd 2>/dev/null"
3135 do_nodes --verbose "$@"
3141 # make sure its not already running
3143 rm -f $TMP/${facet}active
3144 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3145 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3147 if [[ $(facet_fstype $facet) == zfs ]]; then
3149 # After formatting a ZFS target, "cachefile=none" property will
3150 # be set on the ZFS storage pool so that the pool is not
3151 # automatically imported on system startup. And then the pool
3152 # will be exported so as to leave the importing and exporting
3153 # operations handled by mount_facet() and stop() separately.
3155 refresh_partition_table $facet $(facet_vdevice $facet)
3156 disable_zpool_cache $facet
3161 # Device formatted as ost
3164 local DEVNAME=OSTDEV$num
3166 local fstype=$(facet_fstype ost$num)
3170 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3171 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3173 #try $OSTZFSDEVn - independent of vdev
3174 DEVNAME=OSTZFSDEV$num
3175 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3177 error "unknown fstype!";;
3183 # Physical device location of data
3189 local fstype=$(facet_fstype ost$num)
3193 # vdevs are not supported by ldiskfs
3196 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3197 # Device formatted by zfs
3199 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3201 error "unknown fstype!";;
3207 # Logical device formatted for lustre
3210 local DEVNAME=MDSDEV$num
3212 local fstype=$(facet_fstype mds$num)
3216 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3217 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3219 # try $MDSZFSDEVn - independent of vdev
3220 DEVNAME=MDSZFSDEV$num
3221 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3223 error "unknown fstype!";;
3229 # Physical location of data
3233 local fstype=$(facet_fstype mds$num)
3237 # vdevs are not supported by ldiskfs
3240 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3241 # Device formatted by ZFS
3242 local DEVNAME=MDSDEV$num
3243 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3245 error "unknown fstype!";;
3253 local fstype=$(facet_fstype mgs)
3257 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3258 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3259 DEVPTR=$(mdsdevname 1)
3264 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3265 ( [ -z "$MGSZFSDEV" ] &&
3266 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3267 DEVPTR=$(mdsdevname 1)
3269 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3272 error "unknown fstype!";;
3281 local fstype=$(facet_fstype mgs)
3285 # vdevs are not supported by ldiskfs
3288 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3289 ( [ -z "$MGSDEV" ] &&
3290 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3291 VDEVPTR=$(mdsvdevname 1)
3292 elif [ -n "$MGSDEV" ]; then
3296 error "unknown fstype!";;
3304 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3306 local var=${facet}_MOUNT
3307 eval mntpt=${!var:-${MOUNT}-$facet}
3314 local dev=$(facet_device $facet)
3315 local mnt=${2:-$(facet_mntpt $facet)}
3318 if ! do_facet $facet test -b $dev; then
3321 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3326 local dev=$(facet_device $facet)
3327 local mnt=${2:-$(facet_mntpt $facet)}
3329 do_facet $facet $UMOUNT $mnt
3333 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3338 local ds=$(facet_device $facet)
3339 local mnt=${2:-$(facet_mntpt $facet)}
3344 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3345 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3346 do_facet $facet $ZFS set canmount=noauto $ds
3348 # The "legacy" mount method is used here because "zfs unmount $mnt"
3349 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3350 # targets are not available at the time, the stat(2) on $MOUNT will
3353 do_facet $facet $ZFS set mountpoint=legacy $ds
3354 do_facet $facet mount -t zfs $ds $mnt
3355 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3356 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3361 local ds=$(facet_device $facet)
3362 local mnt=${2:-$(facet_mntpt $facet)}
3363 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3364 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3365 local mntpt=${!var_mntpt}
3366 local canmnt=${!var_canmnt}
3370 do_facet $facet umount $mnt
3371 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3372 do_facet $facet $ZFS set canmount=$canmnt $ds
3379 local fstype=$(facet_fstype $facet)
3381 mount_$fstype $facet $mnt
3387 local fstype=$(facet_fstype $facet)
3389 unmount_$fstype $facet $mnt
3396 # make sure we are using the primary server, so test-framework will
3397 # be able to clean up properly.
3398 activemds=`facet_active mds1`
3399 if [ $activemds != "mds1" ]; then
3403 local clients=$CLIENTS
3404 [ -z $clients ] && clients=$(hostname)
3406 zconf_umount_clients $clients $MOUNT "$*" || true
3407 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3409 [ -n "$CLIENTONLY" ] && return
3411 # The add fn does rm ${facet}active file, this would be enough
3412 # if we use do_facet <facet> only after the facet added, but
3413 # currently we use do_facet mds in local.sh
3414 for num in `seq $MDSCOUNT`; do
3416 rm -f ${TMP}/mds${num}active
3418 combined_mgs_mds && rm -f $TMP/mgsactive
3420 for num in `seq $OSTCOUNT`; do
3422 rm -f $TMP/ost${num}active
3425 if ! combined_mgs_mds ; then
3432 cleanup_echo_devs () {
3435 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3437 for dev in $devs; do
3438 $LCTL --device $dev cleanup
3439 $LCTL --device $dev detach
3444 nfs_client_mode && return
3445 cifs_client_mode && return
3454 combined_mgs_mds () {
3455 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3456 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3460 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3464 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3470 local fsname=${3:-"$FSNAME"}
3471 local type=$(facet_type $facet)
3472 local index=$(facet_index $facet)
3473 local fstype=$(facet_fstype $facet)
3474 local host=$(facet_host $facet)
3479 if [ $type == MGS ] || ( [ $type == MDS ] &&
3480 [ "$dev" == $(mgsdevname) ] &&
3481 [ "$host" == "$(facet_host mgs)" ] ); then
3484 opts="--mgsnode=$MGSNID"
3487 if [ $type != MGS ]; then
3488 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3492 var=${facet}failover_HOST
3493 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3494 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3497 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3498 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3500 if [ $type == MDS ]; then
3501 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3502 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3503 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3504 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3506 if [ $fstype == ldiskfs ]; then
3507 # Check for wide striping
3508 if [ $OSTCOUNT -gt 160 ]; then
3509 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3510 fs_mkfs_opts+="-O large_xattr"
3514 if [ -n "${!var}" ]; then
3515 fs_mkfs_opts+=" -J device=${!var}"
3517 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3519 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3523 if [ $type == OST ]; then
3524 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3526 if [ $fstype == ldiskfs ]; then
3528 if [ -n "${!var}" ]; then
3529 fs_mkfs_opts+=" -J device=${!var}"
3531 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3536 opts+=" --backfstype=$fstype"
3539 if [ -n "${!var}" ]; then
3540 opts+=" --device-size=${!var}"
3543 var=$(upper $fstype)_MKFS_OPTS
3544 fs_mkfs_opts+=${!var:+" ${!var}"}
3546 var=${type}_FS_MKFS_OPTS
3547 fs_mkfs_opts+=${!var:+" ${!var}"}
3549 if [ -n "${fs_mkfs_opts## }" ]; then
3550 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3554 opts+=${!var:+" ${!var}"}
3559 check_ost_indices() {
3560 local index_count=${#OST_INDICES[@]}
3561 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3563 # OST count is greater than the index count in $OST_INDEX_LIST.
3564 # We need check whether there are duplicate indices.
3568 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3569 index=$(facet_index ost$i)
3570 for j in $(seq 0 $((index_count - 1))); do
3571 [[ $index -ne ${OST_INDICES[j]} ]] ||
3572 error "ost$i has the same index $index as ost$((j+1))"
3583 echo "Format mgs: $(mgsdevname)"
3584 reformat_external_journal mgs
3585 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3586 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3596 echo "Format mds$num: $(mdsdevname $num)"
3597 reformat_external_journal mds$num
3598 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3599 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3600 ${quiet:+>/dev/null} || exit 10
3609 echo "Format ost$num: $(ostdevname $num)"
3610 reformat_external_journal ost$num
3611 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3612 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3613 ${quiet:+>/dev/null} || exit 10
3618 # Set hostid for ZFS/SPL zpool import protection
3619 # (Assumes MDS version is also OSS version)
3620 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3622 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3625 # We need ldiskfs here, may as well load them all
3627 [ -n "$CLIENTONLY" ] && return
3628 echo Formatting mgs, mds, osts
3629 if ! combined_mgs_mds ; then
3633 for num in $(seq $MDSCOUNT); do
3637 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3639 for num in $(seq $OSTCOUNT); do
3645 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3649 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3653 # 0: success, the old identity set already.
3654 # 1: success, the old identity does not set.
3659 local j=`expr $num - 1`
3660 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3662 if [ -z "$MDT" ]; then
3666 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3669 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3671 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3674 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3676 if [ $old = "NONE" ]; then
3685 zconf_umount `hostname` $1 || error "umount failed"
3686 zconf_mount `hostname` $1 || error "mount failed"
3694 rm -f $TMP/${facet}active
3695 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3700 local mdt_count=${1:-$MDSCOUNT}
3701 local ost_count=${2:-$OSTCOUNT}
3704 for num in $(seq $mdt_count); do
3705 DEVNAME=$(mdsdevname $num)
3706 writeconf_facet mds$num $DEVNAME || rc=$?
3709 for num in $(seq $ost_count); do
3710 DEVNAME=$(ostdevname $num)
3711 writeconf_facet ost$num $DEVNAME || rc=$?
3719 nfs_client_mode && return
3720 cifs_client_mode && return
3722 sanity_mount_check || error "environments are insane!"
3726 if [ -z "$CLIENTONLY" ]; then
3727 echo Setup mgs, mdt, osts
3728 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3729 if ! combined_mgs_mds ; then
3730 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3733 for num in `seq $MDSCOUNT`; do
3734 DEVNAME=$(mdsdevname $num)
3735 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3737 # We started mds, now we should set failover variables properly.
3738 # Set mds${num}failover_HOST if it is not set (the default failnode).
3739 local varname=mds${num}failover_HOST
3740 if [ -z "${!varname}" ]; then
3741 eval mds${num}failover_HOST=$(facet_host mds$num)
3744 if [ $IDENTITY_UPCALL != "default" ]; then
3745 switch_identity $num $IDENTITY_UPCALL
3748 for num in `seq $OSTCOUNT`; do
3749 DEVNAME=$(ostdevname $num)
3750 start ost$num $DEVNAME $OST_MOUNT_OPTS
3752 # We started ost$num, now we should set ost${num}failover variable properly.
3753 # Set ost${num}failover_HOST if it is not set (the default failnode).
3754 varname=ost${num}failover_HOST
3755 if [ -z "${!varname}" ]; then
3756 eval ost${num}failover_HOST=$(facet_host ost${num})
3764 # wait a while to allow sptlrpc configuration be propogated to targets,
3765 # only needed when mounting new target devices.
3770 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3772 if [ ! -z $arg1 ]; then
3773 [ "$arg1" = "server_only" ] && return
3777 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3780 if [ "$MOUNT_2" ]; then
3781 mount_client $MOUNT2
3782 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3787 # by remounting mdt before ost, initial connect from mdt to ost might
3788 # timeout because ost is not ready yet. wait some time to its fully
3789 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3790 # by a context negotiation rpc with $TIMEOUT.
3791 # FIXME better by monitoring import status.
3794 sleep $((TIMEOUT + 5))
3800 mounted_lustre_filesystems() {
3801 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3804 init_facet_vars () {
3805 [ -n "$CLIENTONLY" ] && return 0
3812 eval export ${facet}_dev=${device}
3813 eval export ${facet}_opt=\"$@\"
3815 local dev=${facet}_dev
3817 # We need to loop for the label
3818 # in case its not initialized yet.
3819 for wait_time in {0,1,3,5,10}; do
3821 if [ $wait_time -gt 0 ]; then
3822 echo "${!dev} not yet initialized,"\
3823 "waiting ${wait_time} seconds."
3827 local label=$(devicelabel ${facet} ${!dev})
3829 # Check to make sure the label does
3830 # not include ffff at the end of the label.
3831 # This indicates it has not been initialized yet.
3833 if [[ $label =~ [f|F]{4}$ ]]; then
3834 # label is not initialized, unset the result
3835 # and either try again or fail
3842 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3844 eval export ${facet}_svc=${label}
3846 local varname=${facet}failover_HOST
3847 if [ -z "${!varname}" ]; then
3848 eval export $varname=$(facet_host $facet)
3851 varname=${facet}_HOST
3852 if [ -z "${!varname}" ]; then
3853 eval export $varname=$(facet_host $facet)
3856 # ${facet}failover_dev is set in cfg file
3857 varname=${facet}failover_dev
3858 if [ -n "${!varname}" ] ; then
3859 eval export ${facet}failover_dev=${!varname}
3861 eval export ${facet}failover_dev=$device
3864 # get mount point of already mounted device
3865 # is facet_dev is already mounted then use the real
3866 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3867 # i.e. ${facet}_MOUNT if specified by user or default
3868 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3869 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3870 if [ -z $mntpt ]; then
3871 mntpt=$(facet_mntpt $facet)
3873 eval export ${facet}_MOUNT=$mntpt
3876 init_facets_vars () {
3879 if ! remote_mds_nodsh; then
3880 for num in $(seq $MDSCOUNT); do
3881 DEVNAME=`mdsdevname $num`
3882 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3886 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3888 if ! remote_ost_nodsh; then
3889 for num in $(seq $OSTCOUNT); do
3890 DEVNAME=$(ostdevname $num)
3891 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3896 osc_ensure_active () {
3901 while [ $period -lt $timeout ]; do
3902 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3903 if [ $count -eq 0 ]; then
3907 echo "There are $count OST are inactive, wait $period seconds, and try again"
3909 period=$((period+3))
3912 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3915 set_conf_param_and_check() {
3919 local ORIG=$(do_facet $myfacet "$TEST")
3920 if [ $# -gt 3 ]; then
3926 echo "Setting $PARAM from $ORIG to $FINAL"
3927 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3928 error "conf_param $PARAM failed"
3930 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3931 error "check $PARAM failed!"
3934 init_param_vars () {
3935 TIMEOUT=$(lctl get_param -n timeout)
3936 TIMEOUT=${TIMEOUT:-20}
3938 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3940 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3941 log "Using TIMEOUT=$TIMEOUT"
3943 osc_ensure_active $SINGLEMDS $TIMEOUT
3944 osc_ensure_active client $TIMEOUT
3946 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3947 local current_jobid_var=$($LCTL get_param -n jobid_var)
3949 if [ $JOBID_VAR = "existing" ]; then
3950 echo "keeping jobstats as $current_jobid_var"
3951 elif [ $current_jobid_var != $JOBID_VAR ]; then
3952 echo "seting jobstats to $JOBID_VAR"
3954 set_conf_param_and_check client \
3955 "$LCTL get_param -n jobid_var" \
3956 "$FSNAME.sys.jobid_var" $JOBID_VAR
3959 echo "jobstats not supported by server"
3962 if [ $QUOTA_AUTO -ne 0 ]; then
3963 if [ "$ENABLE_QUOTA" ]; then
3964 echo "enable quota as required"
3965 setup_quota $MOUNT || return 2
3967 echo "disable quota as required"
3968 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3974 nfs_client_mode () {
3975 if [ "$NFSCLIENT" ]; then
3976 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3977 local clients=$CLIENTS
3978 [ -z $clients ] && clients=$(hostname)
3980 # FIXME: remove hostname when 19215 fixed
3981 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3982 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3983 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3984 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3986 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3992 cifs_client_mode () {
3993 [ x$CIFSCLIENT = xyes ] &&
3994 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3997 check_config_client () {
4000 local mounted=$(mount | grep " $mntpt ")
4001 if [ -n "$CLIENTONLY" ]; then
4003 # CLIENTONLY should not depend on *_HOST settings
4004 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4005 # in theory someone could create a new,
4006 # client-only config file that assumed lustre was already
4007 # configured and didn't set the MGSNID. If MGSNID is not set,
4008 # then we should use the mgs nid currently being used
4009 # as the default value. bug 18021
4010 [[ x$MGSNID = x ]] &&
4013 if [[ x$mgc != xMGC$MGSNID ]]; then
4014 if [ "$mgs_HOST" ]; then
4015 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4016 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4017 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4023 local myMGS_host=$mgs_HOST
4024 if [ "$NETTYPE" = "ptl" ]; then
4025 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
4028 echo Checking config lustre mounted on $mntpt
4029 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4030 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4032 # if [ "$mgshost" != "$myMGS_host" ]; then
4033 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
4034 # Please use correct config or set mds_HOST correctly!"
4039 check_config_clients () {
4040 local clients=${CLIENTS:-$HOSTNAME}
4043 nfs_client_mode && return
4044 cifs_client_mode && return
4046 do_rpc_nodes "$clients" check_config_client $mntpt
4048 sanity_mount_check || error "environments are insane!"
4052 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4053 local cltimeout=$(lctl get_param -n timeout)
4054 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4055 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4062 [ -z $mntpt ] && return 1
4063 local mounted=$(mounted_lustre_filesystems)
4065 echo $mounted' ' | grep -w -q $mntpt' '
4069 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4073 # empty lustre filesystem may have empty directories lost+found and .lustre
4075 # exclude .lustre & lost+found
4076 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4077 -print | wc -l) = 1 ] || return 1
4078 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4079 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4080 # exclude .lustre/fid (LU-2780)
4081 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4082 -print | wc -l) = 1 ] || return 1
4084 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4089 check_and_setup_lustre() {
4091 nfs_client_mode && return
4092 cifs_client_mode && return
4094 local MOUNTED=$(mounted_lustre_filesystems)
4098 # both MOUNT and MOUNT2 are not mounted
4099 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4100 [ "$REFORMAT" = "yes" ] && formatall
4101 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4103 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4104 export I_MOUNTED=yes
4108 elif is_mounted $MOUNT2; then
4110 # MOUNT2 is mounted, while MOUNT_2 is not set
4111 if ! [ "$MOUNT_2" ]; then
4112 cleanup_mount $MOUNT2
4113 export I_UMOUNTED2=yes
4116 # MOUNT2 is mounted, MOUNT_2 is set
4118 # FIXME: what to do if check_config failed?
4120 # 1) remote client has mounted other Lustre fs ?
4121 # 2) it has insane env ?
4122 # let's try umount MOUNT2 on all clients and mount it again:
4123 if ! check_config_clients $MOUNT2; then
4124 cleanup_mount $MOUNT2
4125 restore_mount $MOUNT2
4126 export I_MOUNTED2=yes
4131 # MOUNT is mounted MOUNT2 is not mounted
4132 elif [ "$MOUNT_2" ]; then
4133 restore_mount $MOUNT2
4134 export I_MOUNTED2=yes
4138 # FIXME: what to do if check_config failed?
4140 # 1) remote client has mounted other Lustre fs?
4141 # 2) lustre is mounted on remote_clients atall ?
4142 check_config_clients $MOUNT
4146 set_default_debug_nodes $(comma_list $(nodes_list))
4149 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4151 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4152 facets="$(get_facets OST)"
4153 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4154 facets="$facets,$(get_facets MDS)"
4155 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4156 facets="$facets,mgs"
4157 local nodes="$(facets_hosts ${facets})"
4158 if [ -n "$nodes" ] ; then
4159 do_nodes $nodes "$LCTL set_param \
4160 osd-ldiskfs.track_declares_assert=1 || true"
4169 if [ -z "$CLIENTONLY" ]; then
4170 # Enable remote MDT create for testing
4171 for num in $(seq $MDSCOUNT); do
4173 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4178 if [ "$ONLY" == "setup" ]; then
4184 local clients=${CLIENTS:-$HOSTNAME}
4187 zconf_mount_clients $clients $mntpt
4191 local clients=${CLIENTS:-$HOSTNAME}
4194 zconf_umount_clients $clients $mntpt
4197 cleanup_and_setup_lustre() {
4198 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4199 lctl set_param debug=0 || true
4201 if [ "$ONLY" == "cleanup" ]; then
4205 check_and_setup_lustre
4208 # Get all of the server target devices from a given server node and type.
4215 if [ "$type" == ost ]; then
4216 devs=$(get_osd_param $node "" mntdev)
4218 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4220 for dev in $devs; do
4222 *loop*) do_node $node "losetup $dev" | \
4223 sed -e "s/.*(//" -e "s/).*//" ;;
4229 # Get all of the server target devices.
4234 # Master MDS parameters used by lfsck
4235 MDTNODE=$(facet_active_host $SINGLEMDS)
4236 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4240 for node in $(mdts_nodes); do
4241 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4247 for node in $(osts_nodes); do
4248 OSTDEVS[i]=$(get_mnt_devs $node ost)
4253 # Run e2fsck on MDT or OST device.
4258 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4259 local log=$TMP/e2fsck.log
4263 do_node $node $cmd 2>&1 | tee $log
4265 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4267 if [ $MDSCOUNT -gt 1 ]; then
4268 skip "DNE mode isn't supported!"
4272 error "It's not DNE mode."
4277 [ $rc -le $FSCK_MAX_ERR ] ||
4278 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4284 # Run resize2fs on MDT or OST device.
4293 do_facet $facet "$RESIZE2FS $opts $device $size"
4296 # verify a directory is shared among nodes.
4297 check_shared_dir() {
4299 local list=${2:-$(comma_list $(nodes_list))}
4301 [ -z "$dir" ] && return 1
4302 do_rpc_nodes "$list" check_logdir $dir
4303 check_write_access $dir "$list" || return 1
4308 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4309 $LCTL set_param printk=+lfsck
4310 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4312 for k in $(seq $MDSCOUNT); do
4313 # wait up to 10+1 minutes for LFSCK to complete
4314 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4315 mdd.$(facet_svc mds${k}).lfsck_layout |
4316 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4317 error "MDS${k} layout isn't the expected 'completed'"
4318 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4319 mdd.$(facet_svc mds${k}).lfsck_namespace |
4320 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4321 error "MDS${k} namespace isn't the expected 'completed'"
4323 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4324 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4325 awk '/repaired/ { print $2 }' | calc_sum)
4326 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4327 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4328 awk '/repaired/ { print $2 }' | calc_sum)
4329 local repaired=$((rep_mdt + rep_ost))
4330 [ $repaired -eq 0 ] ||
4331 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4334 dump_file_contents() {
4340 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4341 error_noexit false \
4342 "Invalid parameters for dump_file_contents()"
4345 for node in ${nodes}; do
4346 do_node $node "for i in \\\$(find $dir -type f); do
4347 echo ====\\\${i}=======================;
4349 done" >> ${logname}.${node}.log
4353 dump_command_output() {
4359 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4360 error_noexit false \
4361 "Invalid parameters for dump_command_output()"
4365 for node in ${nodes}; do
4366 do_node $node "echo ====${cmd}=======================;
4367 $cmd" >> ${logname}.${node}.log
4374 # dump file contents from /proc/spl in case of zfs test
4375 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4376 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4377 dump_command_output \
4378 "$(osts_nodes)" "zpool events -v" "${logname}"
4381 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4382 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4383 dump_command_output \
4384 "$(mdts_nodes)" "zpool events -v" "${logname}"
4388 check_and_cleanup_lustre() {
4389 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4390 "$TESTSUITE" != "sanity-scrub" ]; then
4394 if is_mounted $MOUNT; then
4395 if $DO_CLEANUP; then
4396 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4397 error "remove sub-test dirs failed"
4401 [ "$ENABLE_QUOTA" ] && restore_quota || true
4404 if [ "$I_UMOUNTED2" = "yes" ]; then
4405 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4408 if [ "$I_MOUNTED2" = "yes" ]; then
4409 cleanup_mount $MOUNT2
4412 if [ "$I_MOUNTED" = "yes" ]; then
4413 cleanupall -f || error "cleanup failed"
4421 wait_for_function () {
4424 # suppress fn both stderr and stdout
4425 if [ "$1" = "--quiet" ]; then
4427 quiet=" > /dev/null 2>&1"
4439 eval $fn $quiet && return 0
4441 wait=$((wait + sleep))
4442 [ $wait -lt $max ] || return 1
4443 echo waiting $fn, $((max - wait)) secs left ...
4453 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4454 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4455 echo "Network not available!"
4459 echo `date +"%H:%M:%S (%s)"` network interface is UP
4467 # Convert a space-delimited list to a comma-delimited list. If the input is
4468 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4470 # echo is used to convert newlines to spaces, since it doesn't
4471 # introduce a trailing space as using "tr '\n' ' '" does
4472 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4478 echo $list | grep -qw $item
4481 # list, excluded are the comma separated lists
4482 exclude_items_from_list () {
4488 for item in ${excluded//,/ }; do
4489 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4491 echo $(comma_list $list)
4494 # list, expand are the comma separated lists
4496 local list=${1//,/ }
4497 local expand=${2//,/ }
4500 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4501 echo $(comma_list $expanded)
4504 testslist_filter () {
4505 local script=$LUSTRE/tests/${TESTSUITE}.sh
4507 [ -f $script ] || return 0
4509 local start_at=$START_AT
4510 local stop_at=$STOP_AT
4512 local var=${TESTSUITE//-/_}_START_AT
4513 [ x"${!var}" != x ] && start_at=${!var}
4514 var=${TESTSUITE//-/_}_STOP_AT
4515 [ x"${!var}" != x ] && stop_at=${!var}
4517 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4518 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4519 /^'${start_at}'$/ {flag = 0}
4520 {if (flag == 1) print $0}
4521 /^'${stop_at}'$/ { flag = 1 }'
4525 (cd `dirname $1`; echo $PWD/`basename $1`)
4529 local types=${1:-"OST MDS MGS"}
4533 for entry in $types; do
4534 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4535 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4538 MGS ) list="$list $name";;
4539 MDS|OST|AGT ) local count=${type}COUNT
4540 for ((i=1; i<=${!count}; i++)) do
4541 list="$list ${name}$i"
4543 * ) error "Invalid facet type"
4547 echo $(comma_list $list)
4550 ##################################
4551 # Adaptive Timeouts funcs
4554 # only check mds, we assume at_max is the same on all nodes
4555 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4556 if [ $at_max -eq 0 ]; then
4567 # suppose that all ost-s have the same $at value set
4568 [ $facet != "ost" ] || facet=ost1
4570 do_facet $facet "lctl get_param -n $at"
4588 if [ $facet == "ost" ]; then
4589 facet=$(get_facets OST)
4590 elif [ $facet == "mds" ]; then
4591 facet=$(get_facets MDS)
4593 hosts=$(expand_list $hosts $(facets_hosts $facet))
4596 do_nodes $hosts lctl set_param at_max=$at_max
4599 ##################################
4603 # OBD_FAIL_MDS_ALL_REQUEST_NET
4605 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4606 do_facet client "$1" || RC=$?
4607 do_facet $SINGLEMDS lctl set_param fail_loc=0
4612 # OBD_FAIL_MDS_ALL_REPLY_NET
4614 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4616 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4620 drop_reint_reply() {
4621 # OBD_FAIL_MDS_REINT_NET_REP
4623 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4625 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4629 drop_update_reply() {
4630 # OBD_FAIL_OUT_UPDATE_NET_REP
4634 do_facet mds${index} lctl set_param fail_loc=0x1701
4635 do_facet client "$@" || RC=$?
4636 do_facet mds${index} lctl set_param fail_loc=0
4641 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4644 local timeout=${2:-0}
4645 # default is (obd_timeout / 4) if unspecified
4646 echo "timeout is $timeout/$2"
4647 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4648 do_facet client "$1" || RC=$?
4649 do_facet client "sync"
4650 do_facet ost1 lctl set_param fail_loc=0
4654 drop_ldlm_cancel() {
4655 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4657 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4658 do_nodes $list lctl set_param fail_loc=0x304
4660 do_facet client "$@" || RC=$?
4662 do_nodes $list lctl set_param fail_loc=0
4666 drop_bl_callback_once() {
4668 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4669 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4670 do_facet client lctl set_param fail_loc=0x80000305
4671 do_facet client "$@" || rc=$?
4672 do_facet client lctl set_param fail_loc=0
4673 do_facet client lctl set_param fail_val=0
4674 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4678 drop_bl_callback() {
4680 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4681 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4682 do_facet client lctl set_param fail_loc=0x305
4683 do_facet client "$@" || rc=$?
4684 do_facet client lctl set_param fail_loc=0
4685 do_facet client lctl set_param fail_val=0
4686 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4691 #define OBD_FAIL_LDLM_REPLY 0x30c
4693 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4694 do_nodes $list lctl set_param fail_loc=0x30c
4696 do_facet client "$@" || RC=$?
4698 do_nodes $list lctl set_param fail_loc=0
4702 drop_ldlm_reply_once() {
4703 #define OBD_FAIL_LDLM_REPLY 0x30c
4705 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4706 do_nodes $list lctl set_param fail_loc=0x8000030c
4708 do_facet client "$@" || RC=$?
4710 do_nodes $list lctl set_param fail_loc=0
4718 echo "clearing fail_loc on $facet"
4719 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4722 set_nodes_failloc () {
4724 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4727 cancel_lru_locks() {
4728 #$LCTL mark "cancel_lru_locks $1 start"
4729 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4730 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4731 #$LCTL mark "cancel_lru_locks $1 stop"
4736 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4737 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4738 echo "$DEFAULT_LRU_SIZE"
4743 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4746 lru_resize_disable()
4748 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4754 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4760 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4761 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4762 echo there is still data in page cache $FILE ?
4763 lctl get_param -n $FILE
4771 DEBUGSAVE="$(lctl get_param -n debug)"
4772 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4776 [ -n "$DEBUGSAVE" ] &&
4777 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4781 [ -n "$DEBUGSAVE_SERVER" ] &&
4782 do_nodes $(comma_list $(all_server_nodes)) \
4783 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4789 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4792 debug_size_restore() {
4793 [ -n "$DEBUG_SIZE_SAVED" ] && \
4794 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4798 start_full_debug_logging() {
4803 local DEBUG_SIZE=150
4805 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4806 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4809 stop_full_debug_logging() {
4814 # prints bash call stack
4815 print_stack_trace() {
4818 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4819 local src=${BASH_SOURCE[$i]}
4820 local lineno=${BASH_LINENO[$i-1]}
4821 local funcname=${FUNCNAME[$i]}
4822 echo " = $src:$lineno:$funcname()"
4827 local TYPE=${TYPE:-"FAIL"}
4830 # do not dump logs if $1=false
4831 if [ "x$1" = "xfalse" ]; then
4836 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4837 (print_stack_trace 2) >&2
4839 # We need to dump the logs on all nodes
4841 gather_logs $(comma_list $(nodes_list))
4845 [ "$TESTSUITELOG" ] &&
4846 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4847 if [ -z "$*" ]; then
4848 echo "error() without useful message, please fix" > $LOGDIR/err
4850 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4851 echo "$@" > $LOGDIR/ignore
4853 echo "$@" > $LOGDIR/err
4857 # cleanup the env for failed tests
4861 ##################################
4863 ##################################
4871 local log=$TESTSUITELOG
4873 [ -f "$log" ] && grep -q FAIL $log && status=1
4887 # use only if we are ignoring failures for this test, bugno required.
4888 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4889 # e.g. error_ignore bz5494 "your message" or
4890 # error_ignore LU-5494 "your message"
4892 local TYPE="IGNORE ($1)"
4897 error_and_remount() {
4899 remount_client $MOUNT
4903 # Throw an error if it's not running in vm - usually for performance
4906 local virt=$(running_in_vm)
4907 if [[ -n "$virt" ]]; then
4908 echo "running in VM '$virt', ignore error"
4909 error_ignore env=$virt "$@"
4916 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4921 log " SKIP: $TESTSUITE $TESTNAME $@"
4923 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4924 skip_logged $TESTNAME "$@"
4927 echo "$@" > $LOGDIR/skip
4930 [[ -n "$TESTSUITELOG" ]] &&
4931 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4934 build_test_filter() {
4935 EXCEPT="$EXCEPT $(testslist_filter)"
4938 if [[ $O = [0-9]*-[0-9]* ]]; then
4939 for num in $(seq $(echo $O | tr '-' ' ')); do
4947 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4948 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4949 [ "$EXCEPT_SLOW" ] && \
4950 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4951 for E in $EXCEPT; do
4952 eval EXCEPT_${E}=true
4954 for E in $ALWAYS_EXCEPT; do
4955 eval EXCEPT_ALWAYS_${E}=true
4957 for E in $EXCEPT_SLOW; do
4958 eval EXCEPT_SLOW_${E}=true
4960 for G in $GRANT_CHECK_LIST; do
4961 eval GCHECK_ONLY_${G}=true
4966 if [[ $1 = [a-z]* ]]; then
4973 # print a newline if the last test was skipped
4974 export LAST_SKIPPED=
4975 export ALWAYS_SKIPPED=
4977 # Main entry into test-framework. This is called with the name and
4978 # description of a test. The name is used to find the function to run
4979 # the test using "test_$name".
4981 # This supports a variety of methods of specifying specific test to
4982 # run or not run. These need to be documented...
4987 export base=$(basetest $1)
4988 if [ -n "$ONLY" ]; then
4990 if [ ${!testname}x != x ]; then
4991 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4992 run_one_logged $1 "$2"
4996 if [ ${!testname}x != x ]; then
4997 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4998 run_one_logged $1 "$2"
5008 if [ ${!testname}x != x ]; then
5009 TESTNAME=test_$1 skip "skipping excluded test $1"
5012 testname=EXCEPT_$base
5013 if [ ${!testname}x != x ]; then
5014 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5017 testname=EXCEPT_ALWAYS_$1
5018 if [ ${!testname}x != x ]; then
5019 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5022 testname=EXCEPT_ALWAYS_$base
5023 if [ ${!testname}x != x ]; then
5024 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5027 testname=EXCEPT_SLOW_$1
5028 if [ ${!testname}x != x ]; then
5029 TESTNAME=test_$1 skip "skipping SLOW test $1"
5032 testname=EXCEPT_SLOW_$base
5033 if [ ${!testname}x != x ]; then
5034 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5040 run_one_logged $1 "$2"
5047 load_module ../libcfs/libcfs/libcfs
5059 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5064 strace -o $TMP/$1.strace -ttt $*
5066 log "FINISHED: $*: rc $RC"
5073 banner test complete, duration $duration sec
5074 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5075 echo duration $duration >>$TESTSUITELOG
5079 # Set TEST_STATUS here. It will be used for logging the result.
5082 if [[ -f $LOGDIR/err ]]; then
5084 elif [[ -f $LOGDIR/skip ]]; then
5087 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5091 local FFREE=$(do_node $SINGLEMDS \
5092 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5093 local FTOTAL=$(do_node $SINGLEMDS \
5094 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5096 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5100 echo -n "Resetting fail_loc on all nodes..."
5101 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5102 fail_val=0 2>/dev/null" || true
5108 # Log a message (on all nodes) padded with "=" before and after.
5109 # Also appends a timestamp and prepends the testsuite name.
5112 EQUALS="===================================================================================================="
5114 msg="== ${TESTSUITE} $*"
5116 [[ $last != "=" && $last != " " ]] && msg="$msg "
5117 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5118 # always include at least == after the message
5119 log "$msg== $(date +"%H:%M:%S (%s)")"
5122 check_dmesg_for_errors() {
5124 local errors="VFS: Busy inodes after unmount of\|\
5125 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5126 group descriptors corrupted"
5128 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5129 [ -z "$res" ] && return 0
5130 echo "Kernel error detected: $res"
5135 # Run a single test function and cleanup after it.
5137 # This function should be run in a subshell so the test func can
5138 # exit() without stopping the whole script.
5143 export tfile=f${testnum}.${TESTSUITE}
5144 export tdir=d${testnum}.${TESTSUITE}
5145 export TESTNAME=test_$testnum
5146 local SAVE_UMASK=`umask`
5149 if ! grep -q $DIR /proc/mounts; then
5153 banner "test $testnum: $message"
5154 test_${testnum} || error "test_$testnum failed with $?"
5157 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5159 check_dmesg_for_errors || error "Error in dmesg detected"
5160 if [ "$PARALLEL" != "yes" ]; then
5161 ps auxww | grep -v grep | grep -q multiop &&
5162 error "multiop still running"
5173 # Wrapper around run_one to ensure:
5174 # - test runs in subshell
5175 # - output of test is saved to separate log file for error reporting
5176 # - test result is saved to data file
5179 local BEFORE=$(date +%s)
5181 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5182 local test_log=$LOGDIR/$name
5183 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5184 local zfs_debug_log=$LOGDIR/$zfs_log_name
5186 rm -rf $LOGDIR/ignore
5188 local SAVE_UMASK=$(umask)
5192 log_sub_test_begin test_${1}
5193 (run_one $1 "$2") 2>&1 | tee -i $test_log
5194 local RC=${PIPESTATUS[0]}
5196 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5197 echo "test_$1 returned $RC" | tee $LOGDIR/err
5199 duration=$(($(date +%s) - $BEFORE))
5200 pass "$1" "(${duration}s)"
5202 if [[ -f $LOGDIR/err ]]; then
5203 TEST_ERROR=$(cat $LOGDIR/err)
5204 elif [[ -f $LOGDIR/ignore ]]; then
5205 TEST_ERROR=$(cat $LOGDIR/ignore)
5206 elif [[ -f $LOGDIR/skip ]]; then
5207 TEST_ERROR=$(cat $LOGDIR/skip)
5209 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5211 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5215 if [ -f $LOGDIR/err ]; then
5216 log_zfs_info "$zfs_debug_log"
5217 $FAIL_ON_ERROR && exit $RC
5226 # Print information of skipped tests to result.yml
5229 log_sub_test_begin $1
5231 log_sub_test_end "SKIP" "0" "0" "$@"
5235 (cd $(dirname $1); echo $PWD/$(basename $1))
5240 export base=$(basetest $1)
5241 [ "$CHECK_GRANT" == "no" ] && return 0
5243 testname=GCHECK_ONLY_${base}
5244 [ ${!testname}x == x ] && return 0
5246 echo -n "checking grant......"
5248 local clients=$CLIENTS
5249 [ -z "$clients" ] && clients=$(hostname)
5251 # sync all the data and make sure no pending data on server
5252 do_nodes $clients sync
5255 client_grant=$(do_nodes $clients \
5256 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5257 awk '{ total += $1 } END { printf("%0.0f", total) }')
5260 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5261 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5262 awk '{ total += $1 } END { printf("%0.0f", total) }')
5264 # check whether client grant == server grant
5265 if [[ $client_grant -ne $server_grant ]]; then
5266 echo "failed: client:${client_grant} server: ${server_grant}."
5267 do_nodes $(comma_list $(osts_nodes)) \
5268 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5269 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5272 echo "pass: client:${client_grant} server: ${server_grant}"
5276 ########################
5282 ost=`echo $1 | awk -F_ '{print $3}'`
5283 if [ -z $ost ]; then
5284 ost=`echo $1 | sed 's/-osc.*//'`
5289 ostuuid_from_index()
5291 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5294 ostname_from_index() {
5295 local uuid=$(ostuuid_from_index $1)
5299 index_from_ostuuid()
5301 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5304 mdtuuid_from_index()
5306 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5310 # Return unique identifier for given hostname
5313 echo $host_name | md5sum | cut -d' ' -f1
5317 # Returns list of ip addresses for each interface
5319 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5324 # Cache address list to avoid mutiple execution of local_addr_list
5325 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5327 for i in $LOCAL_ADDR_LIST ; do
5328 [[ "$i" == "$addr" ]] && return 0
5335 local is_local="IS_LOCAL_$(host_id $host_name)"
5336 if [ -z "${!is_local-}" ] ; then
5338 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5339 is_local_addr "$host_ip" && eval $is_local=1
5341 [[ "${!is_local}" == "1" ]]
5346 local_node $node && return 1
5353 for node in $(mdts_nodes); do
5354 remote_node $node && return 0
5361 [ -n "$CLIENTONLY" ] && return 0 || true
5362 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5367 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5368 MSKIPPED=1 && return 1
5375 for node in $(osts_nodes) ; do
5376 remote_node $node && return 0
5383 [ -n "$CLIENTONLY" ] && return 0 || true
5384 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5389 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5390 OSKIPPED=1 && return 1
5396 [ -n "$CLIENTONLY" ] && return 0 || true
5398 MGS=$(facet_host mgs)
5399 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5404 remote_mds_nodsh || remote_ost_nodsh || \
5405 $(single_local_node $(comma_list $(nodes_list)))
5409 remote_ost && remote_mds
5412 # Get the active nodes for facets.
5420 for facet in ${facets//,/ }; do
5421 nodes="$nodes $(facet_active_host $facet)"
5424 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5428 # Get all of the active MDS nodes.
5430 echo -n $(facets_nodes $(get_facets MDS))
5433 # Get all of the active OSS nodes.
5435 echo -n $(facets_nodes $(get_facets OST))
5438 # Get all of the active AGT (HSM agent) nodes.
5440 echo -n $(facets_nodes $(get_facets AGT))
5443 # Get all of the client nodes and active server nodes.
5445 local nodes=$HOSTNAME
5449 # CLIENTS (if specified) contains the local client
5450 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5452 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5453 nodes="$nodes $(facets_nodes $(get_facets))"
5456 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5460 # Get all of the remote client nodes and remote active server nodes.
5461 remote_nodes_list () {
5462 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5465 # Get all of the MDS nodes, including active and passive nodes.
5473 for i in $(seq $MDSCOUNT); do
5475 failover_host=mds${i}failover_HOST
5476 nodes="$nodes ${!host} ${!failover_host}"
5479 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5483 # Get all of the OSS nodes, including active and passive nodes.
5491 for i in $(seq $OSTCOUNT); do
5493 failover_host=ost${i}failover_HOST
5494 nodes="$nodes ${!host} ${!failover_host}"
5497 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5501 # Get all of the server nodes, including active and passive nodes.
5502 all_server_nodes () {
5507 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5509 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5513 # Get all of the client and server nodes, including active and passive nodes.
5515 local nodes=$HOSTNAME
5519 # CLIENTS (if specified) contains the local client
5520 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5522 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5523 nodes="$nodes $(all_server_nodes)"
5526 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5530 init_clients_lists () {
5531 # Sanity check: exclude the local client from RCLIENTS
5532 local clients=$(hostlist_expand "$RCLIENTS")
5533 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5535 # Sanity check: exclude the dup entries
5536 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5538 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5540 # Sanity check: exclude the dup entries from CLIENTS
5541 # for those configs which has SINGLCLIENT set to local client
5542 clients=$(for i in $clients; do echo $i; done | sort -u)
5544 CLIENTS=$(comma_list $clients)
5545 local -a remoteclients=($RCLIENTS)
5546 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5547 varname=CLIENT$((i + 2))
5548 eval $varname=${remoteclients[i]}
5551 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5554 get_random_entry () {
5557 rnodes=${rnodes//,/ }
5559 local -a nodes=($rnodes)
5560 local num=${#nodes[@]}
5561 local i=$((RANDOM * num * 2 / 65536))
5567 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5571 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5572 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5577 echo $nodes | wc -w || true
5581 local nodes=$(osts_nodes)
5582 local osscount=$(get_node_count "$nodes")
5583 [ ! "$OSTCOUNT" = "$osscount" ]
5587 local nodes=$(mdts_nodes)
5588 local mdtcount=$(get_node_count "$nodes")
5589 [ ! "$MDSCOUNT" = "$mdtcount" ]
5592 generate_machine_file() {
5593 local nodes=${1//,/ }
5594 local machinefile=$2
5596 for node in $nodes; do
5597 echo $node >>$machinefile || \
5598 { echo "can not generate machinefile $machinefile" && return 1; }
5603 local file=$1/stripe
5606 $LFS getstripe -v $file || error "getstripe $file failed"
5610 setstripe_nfsserver () {
5613 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5614 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5616 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5618 do_nodev $nfsserver lfs setstripe "$@"
5621 # Check and add a test group.
5627 local gid=$(getent group $group_name | cut -d: -f3)
5628 if [[ -n "$gid" ]]; then
5629 [[ "$gid" -eq "$group_id" ]] || {
5630 error_noexit "inconsistent group ID:" \
5631 "new: $group_id, old: $gid"
5635 groupadd -g $group_id $group_name
5642 # Check and add a test user.
5655 local uid=$(getent passwd $user_name | cut -d: -f3)
5656 if [[ -n "$uid" ]]; then
5657 if [[ "$uid" -eq "$user_id" ]]; then
5658 local dir=$(getent passwd $user_name | cut -d: -f6)
5659 if [[ "$dir" != "$home" ]]; then
5661 usermod -d $home $user_name
5665 error_noexit "inconsistent user ID:" \
5666 "new: $user_id, old: $uid"
5671 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5678 check_runas_id_ret() {
5680 local myRUNAS_UID=$1
5681 local myRUNAS_GID=$2
5684 if [ -z "$myRUNAS" ]; then
5685 error_exit "myRUNAS command must be specified for check_runas_id"
5688 $myRUNAS krb5_login.sh || \
5689 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5691 mkdir $DIR/d0_runas_test
5693 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5694 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5695 rm -rf $DIR/d0_runas_test
5700 local myRUNAS_UID=$1
5701 local myRUNAS_GID=$2
5704 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5705 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5706 Please set RUNAS_ID to some UID which exists on MDS and client or
5707 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5710 # obtain the UID/GID for MPI_USER
5714 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5715 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5717 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5718 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5721 # obtain and cache Kerberos ticket-granting ticket
5722 refresh_krb5_tgt() {
5723 local myRUNAS_UID=$1
5724 local myRUNAS_GID=$2
5727 if [ -z "$myRUNAS" ]; then
5728 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5731 CLIENTS=${CLIENTS:-$HOSTNAME}
5732 do_nodes $CLIENTS "set -x
5733 if ! $myRUNAS krb5_login.sh; then
5734 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5739 # Run multiop in the background, but wait for it to print
5740 # "PAUSING" to its stdout before returning from this function.
5741 multiop_bg_pause() {
5742 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5746 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5749 echo "$MULTIOP_PROG $FILE v$ARGS"
5750 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5752 echo "TMPPIPE=${TMPPIPE}"
5753 read -t 60 multiop_output < $TMPPIPE
5754 if [ $? -ne 0 ]; then
5759 if [ "$multiop_output" != "PAUSING" ]; then
5760 echo "Incorrect multiop output: $multiop_output"
5775 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5781 inodes_available () {
5782 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5783 sort -un | head -n1) || return 1
5787 mdsrate_inodes_available () {
5788 local min_inodes=$(inodes_available)
5789 echo $((min_inodes * 99 / 100))
5792 # reset llite stat counters
5793 clear_llite_stats(){
5794 lctl set_param -n llite.*.stats 0
5797 # sum llite stat items
5798 calc_llite_stats() {
5799 local res=$(lctl get_param -n llite.*.stats |
5800 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5804 # reset osc stat counters
5806 lctl set_param -n osc.*.osc_stats 0
5809 # sum osc stat items
5811 local res=$(lctl get_param -n osc.*.osc_stats |
5812 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5817 awk '{sum += $1} END { printf("%0.0f", sum) }'
5820 calc_osc_kbytes () {
5821 df $MOUNT > /dev/null
5822 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5825 # save_lustre_params(comma separated facet list, parameter_mask)
5826 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5827 save_lustre_params() {
5833 for facet in ${facets//,/ }; do
5834 node=$(facet_active_host $facet)
5835 [[ *\ $node\ * = " $nodes " ]] && continue
5836 nodes="$nodes $node"
5838 do_node $node "$LCTL get_param $2 |
5839 while read s; do echo $facet \\\$s; done"
5843 # restore lustre parameters from input stream, produces by save_lustre_params
5844 restore_lustre_params() {
5849 while IFS=" =" read facet name val; do
5850 do_facet $facet "$LCTL set_param -n $name $val"
5854 check_node_health() {
5855 local nodes=${1:-$(comma_list $(nodes_list))}
5857 for node in ${nodes//,/ }; do
5858 check_network "$node" 5
5859 if [ $? -eq 0 ]; then
5860 do_node $node "rc=0;
5861 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5862 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5863 echo \\\$(hostname -s): \\\$val;
5866 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5871 mdsrate_cleanup () {
5873 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5874 --nfiles $3 --dir $4 --filefmt $5 $6
5879 delayed_recovery_enabled () {
5880 local var=${SINGLEMDS}_svc
5881 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5884 ########################
5886 convert_facet2label() {
5889 if [ x$facet = xost ]; then
5893 local varsvc=${facet}_svc
5895 if [ -n ${!varsvc} ]; then
5898 error "No lablel for $facet!"
5902 get_clientosc_proc_path() {
5906 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5907 # used by MDT would not be changed.
5908 # mdt lov: fsname-mdtlov
5909 # mdt osc: fsname-OSTXXXX-osc
5910 mds_on_old_device() {
5911 local mds=${1:-"$SINGLEMDS"}
5913 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5914 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5915 > /dev/null 2>&1" && return 0
5920 get_mdtosc_proc_path() {
5922 local ost_label=${2:-"*OST*"}
5924 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5925 local mdt_label=$(convert_facet2label $mds_facet)
5926 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5928 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5929 mds_on_old_device $mds_facet; then
5930 echo "${ost_label}-osc"
5931 elif [[ $ost_label = *OST* ]]; then
5932 echo "${ost_label}-osc-${mdt_index}"
5934 echo "${ost_label}-osp-${mdt_index}"
5938 get_osc_import_name() {
5941 local label=$(convert_facet2label $ost)
5943 if [ "${facet:0:3}" = "mds" ]; then
5944 get_mdtosc_proc_path $facet $label
5948 get_clientosc_proc_path $label
5952 _wait_import_state () {
5955 local maxtime=${3:-$(max_recovery_time)}
5956 local error_on_failure=${4:-1}
5960 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5961 while [ "${CONN_STATE}" != "${expected}" ]; do
5962 if [ "${expected}" == "DISCONN" ]; then
5963 # for disconn we can check after proc entry is removed
5964 [ "x${CONN_STATE}" == "x" ] && return 0
5965 # with AT enabled, we can have connect request timeout near of
5966 # reconnect timeout and test can't see real disconnect
5967 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5969 if [ $i -ge $maxtime ]; then
5970 [ $error_on_failure -ne 0 ] && \
5971 error "can't put import for $CONN_PROC into ${expected}" \
5972 "state after $i sec, have ${CONN_STATE}"
5976 # Add uniq for multi-mount case
5977 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5981 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5985 wait_import_state() {
5988 local maxtime=${3:-$(max_recovery_time)}
5989 local error_on_failure=${4:-1}
5992 for param in ${params//,/ }; do
5993 _wait_import_state $state $param $maxtime $error_on_failure || return
5997 wait_import_state_mount() {
5998 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6002 wait_import_state $*
6005 # One client request could be timed out because server was not ready
6006 # when request was sent by client.
6007 # The request timeout calculation details :
6009 # /* We give the server rq_timeout secs to process the req, and
6010 # add the network latency for our local timeout. */
6011 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6012 # ptlrpc_at_get_net_latency(request) ;
6014 # ptlrpc_connect_import ()
6015 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6018 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6019 # ptlrpc_at_get_net_latency(request) ->
6020 # at_get (max (iat_net_latency=0, at_min)) = at_min
6023 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6024 # INITIAL_CONNECT_TIMEOUT + at_min
6026 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6027 # because we can not get this value in runtime,
6028 # the value depends on configure options, and it is not stored in /proc.
6030 # #define CONNECTION_SWITCH_MIN 5U
6031 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6033 request_timeout () {
6036 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6037 local init_connect_timeout=$TIMEOUT
6038 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6040 local at_min=$(at_get $facet at_min)
6042 echo $(( init_connect_timeout + at_min ))
6045 _wait_osc_import_state() {
6049 local target=$(get_osc_import_name $facet $ost_facet)
6050 local param="osc.${target}.ost_server_uuid"
6054 # 1. wait the deadline of client 1st request (it could be skipped)
6055 # 2. wait the deadline of client 2nd request
6056 local maxtime=$(( 2 * $(request_timeout $facet)))
6058 if [[ $facet == client* ]]; then
6059 # During setup time, the osc might not be setup, it need wait
6060 # until list_param can return valid value.
6061 param="osc.${ost%?}[^mM]*.ost_server_uuid"
6062 params=$($LCTL list_param $param 2>/dev/null || true)
6063 while [ -z "$params" ]; do
6064 if [ $i -ge $maxtime ]; then
6065 echo "can't get $param in $maxtime secs"
6070 params=$($LCTL list_param $param 2>/dev/null || true)
6074 if [[ $ost_facet = mds* ]]; then
6075 # no OSP connection to itself
6076 if [[ $facet = $ost_facet ]]; then
6079 param="osp.${target}.mdt_server_uuid"
6083 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6084 wait_import_state $expected "$params" $maxtime; then
6085 error "$facet: import is not in $expected state after $maxtime"
6092 wait_osc_import_state() {
6098 if [[ $facet = mds ]]; then
6099 for num in $(seq $MDSCOUNT); do
6100 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6103 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6107 _wait_mgc_import_state() {
6110 local error_on_failure=${3:-1}
6111 local param="mgc.*.mgs_server_uuid"
6115 # 1. wait the deadline of client 1st request (it could be skipped)
6116 # 2. wait the deadline of client 2nd request
6117 local maxtime=$(( 2 * $(request_timeout $facet)))
6119 if [[ $facet == client* ]]; then
6120 # During setup time, the osc might not be setup, it need wait
6121 # until list_param can return valid value. And also if there
6122 # are mulitple osc entries we should list all of them before
6124 params=$($LCTL list_param $param 2>/dev/null || true)
6125 while [ -z "$params" ]; do
6126 if [ $i -ge $maxtime ]; then
6127 echo "can't get $param in $maxtime secs"
6132 params=$($LCTL list_param $param 2>/dev/null || true)
6135 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6136 wait_import_state $expected "$params" $maxtime \
6137 $error_on_failure; then
6138 if [ $error_on_failure -ne 0 ]; then
6139 error "import is not in ${expected} state"
6147 wait_mgc_import_state() {
6150 local error_on_failure=${3:-1}
6153 if [[ $facet = mds ]]; then
6154 for num in $(seq $MDSCOUNT); do
6155 _wait_mgc_import_state mds$num "$expected" \
6156 $error_on_failure || return
6159 _wait_mgc_import_state "$facet" "$expected"
6160 $error_on_failure || return
6164 wait_dne_interconnect() {
6167 if [ $MDSCOUNT -gt 1 ]; then
6168 for num in $(seq $MDSCOUNT); do
6169 wait_osc_import_state mds mds$num FULL
6174 get_clientmdc_proc_path() {
6178 get_clientmgc_proc_path() {
6186 [ -z "$list" ] && return 0
6188 # Add paths to lustre tests for 32 and 64 bit systems.
6189 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6190 local TESTPATH="$RLUSTRE/tests:"
6191 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6192 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6195 wait_clients_import_state () {
6202 if [ "$FAILURE_MODE" = HARD ]; then
6203 facets=$(facets_on_host $(facet_active_host $facet))
6206 for facet in ${facets//,/ }; do
6207 local label=$(convert_facet2label $facet)
6210 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6211 $label).ost_server_uuid" ;;
6212 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6213 $label).mds_server_uuid" ;;
6214 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6215 $label).mgs_server_uuid" ;;
6216 *) error "unknown facet!" ;;
6219 local params=$(expand_list $params $proc_path)
6222 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6224 error "import is not in ${expected} state"
6234 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6235 $LCTL get_param obdfilter.*.kbytesavail))
6236 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6237 $LCTL get_param -n obdfilter.*.tot_granted))
6238 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6239 $LCTL get_param -n obdfilter.*.kbytestotal))
6240 for ((i=0; i<${#AVAILA[@]}; i++)); do
6241 local -a AVAIL1=(${AVAILA[$i]//=/ })
6242 local -a TOTAL=(${TOTALA[$i]//=/ })
6243 GRANT=$((${GRANTA[$i]}/1024))
6244 # allow 1% of total space in bavail because of delayed
6245 # allocation with ZFS which might release some free space after
6246 # txg commit. For small devices, we set a mininum of 8MB
6247 local LIMIT=$((${TOTAL} / 100 + 8000))
6248 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6249 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6250 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6251 echo " FULL" || echo
6257 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6260 check_pool_not_exist() {
6261 local fsname=${1%%.*}
6262 local poolname=${1##$fsname.}
6263 [[ $# -ne 1 ]] && return 0
6264 [[ x$poolname = x ]] && return 0
6265 list_pool $fsname | grep -w $1 && return 1
6270 local fsname=${1%%.*}
6271 local poolname=${1##$fsname.}
6273 trap "destroy_test_pools $fsname" EXIT
6274 do_facet mgs lctl pool_new $1
6276 # get param should return err unless pool is created
6277 [[ $RC -ne 0 ]] && return $RC
6279 for mds_id in $(seq $MDSCOUNT); do
6280 local mdt_id=$((mds_id-1))
6281 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6282 wait_update_facet mds$mds_id \
6283 "lctl get_param -n lod.$lodname.pools.$poolname \
6284 2>/dev/null || echo foo" "" ||
6285 error "mds$mds_id: pool_new failed $1"
6287 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6288 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6294 add_pool_to_list () {
6295 local fsname=${1%%.*}
6296 local poolname=${1##$fsname.}
6298 local listvar=${fsname}_CREATED_POOLS
6299 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6303 remove_pool_from_list () {
6304 local fsname=${1%%.*}
6305 local poolname=${1##$fsname.}
6307 local listvar=${fsname}_CREATED_POOLS
6308 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6312 destroy_pool_int() {
6314 local OSTS=$(list_pool $1)
6315 for ost in $OSTS; do
6316 do_facet mgs lctl pool_remove $1 $ost
6318 do_facet mgs lctl pool_destroy $1
6321 # <fsname>.<poolname> or <poolname>
6323 local fsname=${1%%.*}
6324 local poolname=${1##$fsname.}
6326 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6330 check_pool_not_exist $fsname.$poolname
6331 [[ $? -eq 0 ]] && return 0
6333 destroy_pool_int $fsname.$poolname
6335 [[ $RC -ne 0 ]] && return $RC
6336 for mds_id in $(seq $MDSCOUNT); do
6337 local mdt_id=$((mds_id-1))
6338 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6339 wait_update_facet mds$mds_id \
6340 "lctl get_param -n lod.$lodname.pools.$poolname \
6341 2>/dev/null || echo foo" "foo" ||
6342 error "mds$mds_id: destroy pool failed $1"
6344 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6345 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6347 remove_pool_from_list $fsname.$poolname
6353 local fsname=${1:-$FSNAME}
6355 local listvar=${fsname}_CREATED_POOLS
6357 [ x${!listvar} = x ] && return 0
6359 echo "Destroy the created pools: ${!listvar}"
6360 for poolname in ${!listvar//,/ }; do
6361 destroy_pool $fsname.$poolname
6365 destroy_test_pools () {
6367 local fsname=${1:-$FSNAME}
6368 destroy_pools $fsname || true
6374 local ts=$(date +%s)
6377 if [[ ! -f "$YAML_LOG" ]]; then
6378 # init_logging is not performed before gather_logs,
6379 # so the $LOGDIR needs to be checked here
6380 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6383 [ -f $LOGDIR/shared ] && docp=false
6385 # dump lustre logs, dmesg
6387 prefix="$TESTLOG_PREFIX.$TESTNAME"
6389 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6391 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6392 echo "Dumping logs only on local client."
6393 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6394 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6399 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6400 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6401 if [ ! -f $LOGDIR/shared ]; then
6402 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6415 for i in $(seq 0 $num_mntpts); do
6416 cmd="ls -laf ${mntpt_root}$i/$dir"
6422 for pid in $pids; do
6429 # check_and_start_recovery_timer()
6430 # service_time = at_est2timeout(service_time);
6431 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6432 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6434 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6435 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6436 #define CONNECTION_SWITCH_MIN 5
6437 #define CONNECTION_SWITCH_INC 5
6438 max_recovery_time() {
6439 local init_connect_timeout=$((TIMEOUT / 20))
6440 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6442 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6443 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6445 echo -n $service_time
6448 recovery_time_min() {
6449 local connection_switch_min=5
6450 local connection_switch_inc=5
6451 local connection_switch_max
6452 local reconnect_delay_max
6453 local initial_connect_timeout
6457 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6458 (($connection_switch_min > $TIMEOUT)) &&
6459 max=$connection_switch_min || max=$TIMEOUT
6460 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6462 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6463 timeout_20=$((TIMEOUT/20))
6464 (($connection_switch_min > $timeout_20)) &&
6465 initial_connect_timeout=$connection_switch_min ||
6466 initial_connect_timeout=$timeout_20
6468 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6469 initial_connect_timeout))
6470 echo $((2 * reconnect_delay_max))
6473 get_clients_mount_count () {
6474 local clients=${CLIENTS:-`hostname`}
6476 # we need to take into account the clients mounts and
6477 # exclude mds/ost mounts if any;
6478 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6482 PROC_CLI="srpc_info"
6490 if [ $M -lt $N ]; then
6494 while [ $N -lt $M ]; do
6504 calc_connection_cnt() {
6507 # MDT->MDT = 2 * C(M, 2)
6511 comb_m2=$(combination $MDSCOUNT 2)
6513 local num_clients=$(get_clients_mount_count)
6515 local cnt_mdt2mdt=$((comb_m2 * 2))
6516 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6517 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6518 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6519 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6520 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6521 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6535 local cmd="$tgt.srpc.flavor"
6537 if [ $net == "any" ]; then
6542 if [ $dir != "any" ]; then
6547 log "Setting sptlrpc rule: $cmd"
6548 do_facet mgs "$LCTL conf_param $cmd"
6557 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6558 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6560 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6562 if [ "x$bulkspec" != "x" ]; then
6563 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6565 if [ "x$algs" != "x" ]; then
6566 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6568 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6569 if [ $bulk == "bulkn" ]; then
6570 bulk_count=`echo "$output" | grep "bulk flavor" \
6571 | grep "null/null" | wc -l`
6572 elif [ $bulk == "bulki" ]; then
6573 bulk_count=`echo "$output" | grep "bulk flavor" \
6574 | grep "/null" | grep -v "null/" | wc -l`
6576 bulk_count=`echo "$output" | grep "bulk flavor" \
6577 | grep -v "/null" | grep -v "null/" | wc -l`
6581 [ $bulk_count -lt $count ] && count=$bulk_count
6592 local clients=${CLIENTS:-`hostname`}
6594 for c in ${clients//,/ }; do
6595 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6596 tmpcnt=`count_flvr "$output" $flavor`
6597 cnt=$((cnt + tmpcnt))
6607 local clients=${CLIENTS:-`hostname`}
6609 for c in ${clients//,/ }; do
6610 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6611 tmpcnt=`count_flvr "$output" $flavor`
6612 cnt=$((cnt + tmpcnt))
6622 if [ $MDSCOUNT -le 1 ]; then
6627 for num in `seq $MDSCOUNT`; do
6628 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6629 tmpcnt=`count_flvr "$output" $flavor`
6630 cnt=$((cnt + tmpcnt))
6641 for num in `seq $MDSCOUNT`; do
6642 mdtosc=$(get_mdtosc_proc_path mds$num)
6643 mdtosc=${mdtosc/-MDT*/-MDT\*}
6644 output=$(do_facet mds$num lctl get_param -n \
6645 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6646 tmpcnt=`count_flvr "$output" $flavor`
6647 cnt=$((cnt + tmpcnt))
6656 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6657 count_flvr "$output" $flavor
6662 local dir=$1 # from to
6663 local flavor=$2 # flavor expected
6666 if [ $dir == "cli2mdt" ]; then
6667 res=`flvr_cnt_cli2mdt $flavor`
6668 elif [ $dir == "cli2ost" ]; then
6669 res=`flvr_cnt_cli2ost $flavor`
6670 elif [ $dir == "mdt2mdt" ]; then
6671 res=`flvr_cnt_mdt2mdt $flavor`
6672 elif [ $dir == "mdt2ost" ]; then
6673 res=`flvr_cnt_mdt2ost $flavor`
6674 elif [ $dir == "all2ost" ]; then
6675 res1=`flvr_cnt_mdt2ost $flavor`
6676 res2=`flvr_cnt_cli2ost $flavor`
6677 res=$((res1 + res2))
6678 elif [ $dir == "all2mdt" ]; then
6679 res1=`flvr_cnt_mdt2mdt $flavor`
6680 res2=`flvr_cnt_cli2mdt $flavor`
6681 res=$((res1 + res2))
6682 elif [ $dir == "all2all" ]; then
6683 res1=`flvr_cnt_mdt2ost $flavor`
6684 res2=`flvr_cnt_cli2ost $flavor`
6685 res3=`flvr_cnt_mdt2mdt $flavor`
6686 res4=`flvr_cnt_cli2mdt $flavor`
6687 res=$((res1 + res2 + res3 + res4))
6695 local dir=$1 # from to
6696 local flavor=$2 # flavor expected
6697 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6701 for ((i=0;i<20;i++)); do
6702 echo -n "checking $dir..."
6703 res=$(do_check_flavor $dir $flavor)
6704 echo "found $res/$expect $flavor connections"
6705 [ $res -ge $expect ] && return 0
6709 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6713 restore_to_default_flavor()
6715 local proc="mgs.MGS.live.$FSNAME"
6717 echo "restoring to default flavor..."
6719 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6721 # remove all existing rules if any
6722 if [ $nrule -ne 0 ]; then
6723 echo "$nrule existing rules"
6724 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6725 echo "remove rule: $rule"
6726 spec=`echo $rule | awk -F = '{print $1}'`
6727 do_facet mgs "$LCTL conf_param -d $spec"
6731 # verify no rules left
6732 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6733 [ $nrule -ne 0 ] && error "still $nrule rules left"
6735 # wait for default flavor to be applied
6736 # currently default flavor for all connections are 'null'
6737 wait_flavor all2all null
6738 echo "now at default flavor settings"
6743 local flavor=${1:-null}
6745 echo "setting all flavor to $flavor"
6747 # FIXME need parameter to this fn
6748 # and remove global vars
6749 local cnt_all2all=$(calc_connection_cnt all2all)
6751 local res=$(do_check_flavor all2all $flavor)
6752 if [ $res -eq $cnt_all2all ]; then
6753 echo "already have total $res $flavor connections"
6757 echo "found $res $flavor out of total $cnt_all2all connections"
6758 restore_to_default_flavor
6760 [[ $flavor = null ]] && return 0
6762 set_rule $FSNAME any any $flavor
6763 wait_flavor all2all $flavor
6769 # Checking for shared logdir
6770 if [ ! -d $dir ]; then
6771 # Not found. Create local logdir
6774 touch $dir/check_file.$(hostname -s)
6779 check_write_access() {
6781 local list=${2:-$(comma_list $(nodes_list))}
6785 for node in ${list//,/ }; do
6786 file=$dir/check_file.$(short_nodename $node)
6787 if [[ ! -f "$file" ]]; then
6788 # Logdir not accessible/writable from this node.
6791 rm -f $file || return 1
6797 [[ -n $YAML_LOG ]] && return
6798 local save_umask=$(umask)
6801 export YAML_LOG=${LOGDIR}/results.yml
6805 # If the yaml log already exists then we will just append to it
6806 if [ ! -f $YAML_LOG ]; then
6807 if check_shared_dir $LOGDIR; then
6808 touch $LOGDIR/shared
6809 echo "Logging to shared log directory: $LOGDIR"
6811 echo "Logging to local directory: $LOGDIR"
6814 yml_nodes_file $LOGDIR >> $YAML_LOG
6815 yml_results_file >> $YAML_LOG
6820 # If modules are not yet loaded then older "lctl lustre_build_version"
6821 # will fail. Use lctl build version instead.
6822 log "Client: $($LCTL lustre_build_version)"
6823 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6824 do_facet $SINGLEMDS $LCTL --version)"
6825 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6826 do_facet ost1 $LCTL --version)"
6830 yml_log_test $1 >> $YAML_LOG
6834 yml_log_test_status $@ >> $YAML_LOG
6837 log_sub_test_begin() {
6838 yml_log_sub_test_begin "$@" >> $YAML_LOG
6841 log_sub_test_end() {
6842 yml_log_sub_test_end "$@" >> $YAML_LOG
6848 local llverdev_opts=$2
6849 local devname=$(basename $1)
6850 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6851 # loop devices aren't in /proc/partitions
6852 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6854 size=$(($size / 1024 / 1024)) # Gb
6856 local partial_arg=""
6857 # Run in partial (fast) mode if the size
6858 # of a partition > 1 GB
6859 [ $size -gt 1 ] && partial_arg="-p"
6861 llverdev --force $partial_arg $llverdev_opts $dev
6867 local llverfs_opts=$2
6868 local use_partial_arg=$3
6869 local partial_arg=""
6870 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6872 # Run in partial (fast) mode if the size
6873 # of a partition > 1 GB
6874 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6876 llverfs $partial_arg $llverfs_opts $dir
6879 #Remove objects from OST
6880 remove_ost_objects() {
6886 local mntpt=$(facet_mntpt $facet)
6887 local opts=$OST_MOUNT_OPTS
6891 echo "removing objects from $ostdev on $facet: $objids"
6892 if ! test -b $ostdev; then
6893 opts=$(csa_add "$opts" -o loop)
6895 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6898 for i in $objids; do
6899 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6901 umount -f $mntpt || return $?
6905 #Remove files from MDT
6906 remove_mdt_files() {
6911 local mntpt=$(facet_mntpt $facet)
6912 local opts=$MDS_MOUNT_OPTS
6914 echo "removing files from $mdtdev on $facet: $files"
6915 if [ $(facet_fstype $facet) == ldiskfs ] &&
6916 ! do_facet $facet test -b $mdtdev; then
6917 opts=$(csa_add "$opts" -o loop)
6919 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6923 rm $mntpt/ROOT/$f || { rc=$?; break; }
6925 umount -f $mntpt || return $?
6929 duplicate_mdt_files() {
6934 local mntpt=$(facet_mntpt $facet)
6935 local opts=$MDS_MOUNT_OPTS
6937 echo "duplicating files on $mdtdev on $facet: $files"
6938 mkdir -p $mntpt || return $?
6939 if [ $(facet_fstype $facet) == ldiskfs ] &&
6940 ! do_facet $facet test -b $mdtdev; then
6941 opts=$(csa_add "$opts" -o loop)
6943 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6954 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6955 pushd $mntpt/ROOT > /dev/null || return $?
6958 touch $f.bad || return $?
6959 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6961 [ $rc -eq 0 ] || return $rc
6962 setfattr --restore $tmp || return $?
6968 local devs=${1//,/ }
6971 local rslt=$TMP/sgpdd_survey
6973 # sgpdd-survey cleanups ${rslt}.* files
6975 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6981 # returns the canonical name for an ldiskfs device
6986 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6987 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6988 echo dm-\\\${foo##*:};
6990 echo \\\$(basename \\\$dv);
6994 is_sanity_benchmark() {
6995 local benchmarks="dbench bonnie iozone fsx"
6997 for b in $benchmarks; do
6998 if [ "$b" == "$suite" ]; then
7006 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
7010 # Get the available size (KB) of a given obd target.
7017 [[ $facet != client ]] || return 0
7019 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7024 # Get the page size (bytes) on a given facet node.
7028 local size=$(getconf PAGE_SIZE 2>/dev/null)
7030 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7031 echo -n ${size:-4096}
7035 # Get the block count of the filesystem.
7042 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7043 awk '/^Block count:/ {print $3}')
7047 # Get the block size of the filesystem.
7053 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7054 awk '/^Block size:/ {print $3}')
7058 # Check whether the "large_xattr" feature is enabled or not.
7059 large_xattr_enabled() {
7060 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7062 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7064 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7065 grep -E -q '(ea_inode|large_xattr)'"
7066 return ${PIPESTATUS[0]}
7069 # Get the maximum xattr size supported by the filesystem.
7073 if large_xattr_enabled; then
7074 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7077 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7078 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7080 # maximum xattr size = size of block - size of header -
7081 # size of 1 entry - 4 null bytes
7082 size=$((block_size - 32 - 32 - 4))
7088 # Dump the value of the named xattr from a file.
7093 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7096 # Generate a string with size of $size bytes.
7098 local size=${1:-1024} # in bytes
7100 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7103 reformat_external_journal() {
7108 if [ -n "${!var}" ]; then
7109 local rcmd="do_facet $facet"
7111 echo "reformat external journal on $facet:${!var}"
7112 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7116 # MDT file-level backup/restore
7117 mds_backup_restore() {
7120 local devname=$(mdsdevname $(facet_number $facet))
7121 local mntpt=$(facet_mntpt brpt)
7122 local rcmd="do_facet $facet"
7123 local metaea=${TMP}/backup_restore.ea
7124 local metadata=${TMP}/backup_restore.tgz
7125 local opts=${MDS_MOUNT_OPTS}
7126 local svc=${facet}_svc
7128 if ! ${rcmd} test -b ${devname}; then
7129 opts=$(csa_add "$opts" -o loop)
7132 echo "file-level backup/restore on $facet:${devname}"
7134 # step 1: build mount point
7135 ${rcmd} mkdir -p $mntpt
7136 # step 2: cleanup old backup
7137 ${rcmd} rm -f $metaea $metadata
7139 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7140 if [ ! -z $igif ]; then
7141 # step 3.5: rm .lustre
7142 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7144 # step 4: backup metaea
7146 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7148 # step 5: backup metadata
7150 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7152 ${rcmd} $UMOUNT $mntpt || return 4
7153 # step 8: reformat dev
7154 echo "reformat new device"
7155 format_mdt $(facet_number $facet)
7157 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7158 # step 10: restore metadata
7160 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7161 # step 11: restore metaea
7163 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7164 # step 12: remove recovery logs
7165 echo "remove recovery logs"
7166 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7167 # step 13: umount dev
7168 ${rcmd} $UMOUNT $mntpt || return 10
7169 # step 14: cleanup tmp backup
7170 ${rcmd} rm -f $metaea $metadata
7171 # step 15: reset device label - it's not virgin on
7172 ${rcmd} e2label $devname ${!svc}
7179 local devname=$(mdsdevname $(facet_number $facet))
7180 local mntpt=$(facet_mntpt brpt)
7181 local rcmd="do_facet $facet"
7182 local opts=${MDS_MOUNT_OPTS}
7184 if ! ${rcmd} test -b ${devname}; then
7185 opts=$(csa_add "$opts" -o loop)
7188 echo "removing OI files on $facet: idx=${idx}"
7190 # step 1: build mount point
7191 ${rcmd} mkdir -p $mntpt
7193 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7194 if [ -z $idx ]; then
7195 # step 3: remove all OI files
7196 ${rcmd} rm -fv $mntpt/oi.16*
7197 elif [ $idx -lt 2 ]; then
7198 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7202 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7203 for ((i=${idx}; i<64; i=$((i * idx)))); do
7204 ${rcmd} rm -fv $mntpt/oi.16.${i}
7208 ${rcmd} $UMOUNT $mntpt || return 2
7209 # OI files will be recreated when mounted as lustre next time.
7212 # generate maloo upload-able log file name
7213 # \param logname specify unique part of file name
7214 generate_logname() {
7215 local logname=${1:-"default_logname"}
7217 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7220 # make directory on different MDTs
7224 local stripe_count=2
7225 local stripe_index=-1
7228 while getopts "c:i:p" opt; do
7230 c) stripe_count=$OPTARG;;
7231 i) stripe_index=$OPTARG;;
7233 \?) error "only support -i -c -p";;
7237 shift $((OPTIND - 1))
7238 [ $# -eq 1 ] || error "Only creating single directory is supported"
7241 if [ "$p_option" == "-p" ]; then
7242 local parent=$(dirname $path)
7244 [ -d $path ] && return 0
7245 [ ! -d ${parent} ] && mkdir -p ${parent}
7248 if [ $MDSCOUNT -le 1 ]; then
7251 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7254 if [ $stripe_index -eq -1 ]; then
7255 mdt_index=$((test_num % MDSCOUNT))
7257 mdt_index=$stripe_index
7259 echo "striped dir -i$mdt_index -c$stripe_count $path"
7260 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7264 # find the smallest and not in use file descriptor
7267 local max_fd=$(ulimit -n)
7269 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7272 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7276 check_mount_and_prep()
7278 is_mounted $MOUNT || setupall
7280 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7281 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7282 for idx in $(seq $MDSCOUNT); do
7283 local name="MDT$(printf '%04x' $((idx - 1)))"
7284 rm -rf $MOUNT/.lustre/lost+found/$name/*
7288 # calcule how many ost-objects to be created.
7289 precreated_ost_obj_count()
7293 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7294 local ost_name="OST$(printf '%04x' $ost_idx)"
7295 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7296 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7297 osp.$proc_path.prealloc_last_id)
7298 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7299 osp.$proc_path.prealloc_next_id)
7300 echo $((last_id - next_id + 1))
7303 check_file_in_pool()
7308 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7311 for t in $tlist ; do
7312 [ "$i" -eq "$t" ] && continue 2
7315 echo "pool list: $tlist"
7316 echo "striping: $res"
7317 error_noexit "$file not allocated in $pool"
7324 echo "Creating new pool"
7327 create_pool $FSNAME.$pool ||
7328 { error_noexit "No pool created, result code $?"; return 1; }
7329 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7330 { error_noexit "$pool not in lfs pool_list"; return 2; }
7333 pool_add_targets() {
7334 echo "Adding targets to pool"
7340 local list=$(seq $first $step $last)
7342 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7343 do_facet mgs $LCTL pool_add \
7344 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7346 # wait for OSTs to be added to the pool
7347 for mds_id in $(seq $MDSCOUNT); do
7348 local mdt_id=$((mds_id-1))
7349 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7350 wait_update_facet mds$mds_id \
7351 "lctl get_param -n lod.$lodname.pools.$pool |
7352 sort -u | tr '\n' ' ' " "$t" || {
7353 error_noexit "mds$mds_id: Add to pool failed"
7357 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7358 | sort -u | tr '\n' ' ' " "$t" || {
7359 error_noexit "Add to pool failed"
7362 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7363 local addcount=$(((last - first) / step + 1))
7364 [ $lfscount -eq $addcount ] || {
7365 error_noexit "lfs pool_list bad ost count" \
7366 "$lfscount != $addcount"
7374 echo "Setting pool on directory $tdir"
7376 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7378 error_noexit "Cannot set pool $pool to $tdir"
7385 echo "Checking pool on directory $tdir"
7387 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7388 [ "$res" = "$pool" ] && return 0
7390 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7394 pool_dir_rel_path() {
7395 echo "Testing relative path works well"
7400 mkdir -p $root/$tdir/$tdir
7402 pool_set_dir $pool $tdir || return 1
7403 pool_set_dir $pool ./$tdir || return 2
7404 pool_set_dir $pool ../$tdir || return 3
7405 pool_set_dir $pool ../$tdir/$tdir || return 4
7406 rm -rf $tdir; cd - > /dev/null
7409 pool_alloc_files() {
7410 echo "Checking files allocation from directory pool"
7417 for i in $(seq -w 1 $count)
7419 local file=$tdir/file-$i
7421 check_file_in_pool $file $pool "$tlist" || \
7422 failed=$((failed + 1))
7424 [ "$failed" = 0 ] && return 0
7426 error_noexit "$failed files not allocated in $pool"
7430 pool_create_files() {
7431 echo "Creating files in pool"
7439 for i in $(seq -w 1 $count)
7441 local file=$tdir/spoo-$i
7442 $SETSTRIPE -p $pool $file
7443 check_file_in_pool $file $pool "$tlist" || \
7444 failed=$((failed + 1))
7446 [ "$failed" = 0 ] && return 0
7448 error_noexit "$failed files not allocated in $pool"
7453 echo "Checking 'lfs df' output"
7456 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7458 local res=$($LFS df --pool $FSNAME.$pool |
7460 grep "$FSNAME-OST" |
7462 [ "$res" = "$t" ] && return 0
7464 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7468 pool_file_rel_path() {
7469 echo "Creating files in a pool with relative pathname"
7474 { error_noexit "unable to create $tdir"; return 1 ; }
7475 local file="/..$tdir/$tfile-1"
7476 $SETSTRIPE -p $pool $file ||
7477 { error_noexit "unable to create $file" ; return 2 ; }
7480 $SETSTRIPE -p $pool $tfile-2 || {
7481 error_noexit "unable to create $tfile-2 in $tdir"
7486 pool_remove_first_target() {
7487 echo "Removing first target from a pool"
7490 local pname="lov.$FSNAME-*.pools.$pool"
7491 local t=$($LCTL get_param -n $pname | head -1)
7492 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7493 for mds_id in $(seq $MDSCOUNT); do
7494 local mdt_id=$((mds_id-1))
7495 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7496 wait_update_facet mds$mds_id \
7497 "lctl get_param -n lod.$lodname.pools.$pool |
7499 error_noexit "mds$mds_id: $t not removed from" \
7504 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7505 error_noexit "$t not removed from $FSNAME.$pool"
7510 pool_remove_all_targets() {
7511 echo "Removing all targets from pool"
7514 local pname="lov.$FSNAME-*.pools.$pool"
7515 for t in $($LCTL get_param -n $pname | sort -u)
7517 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7519 for mds_id in $(seq $MDSCOUNT); do
7520 local mdt_id=$((mds_id-1))
7521 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7522 wait_update_facet mds$mds_id "lctl get_param -n \
7523 lod.$lodname.pools.$pool" "" || {
7524 error_noexit "mds$mds_id: Pool $pool not drained"
7528 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7529 error_noexit "Pool $FSNAME.$pool cannot be drained"
7532 # striping on an empty/nonexistant pool should fall back
7533 # to "pool of everything"
7535 error_noexit "failed to use fallback striping for empty pool"
7538 # setstripe on an empty pool should fail
7539 $SETSTRIPE -p $pool $file 2>/dev/null && {
7540 error_noexit "expected failure when creating file" \
7548 echo "Destroying pool"
7552 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7555 # striping on an empty/nonexistant pool should fall back
7556 # to "pool of everything"
7558 error_noexit "failed to use fallback striping for missing pool"
7561 # setstripe on an empty pool should fail
7562 $SETSTRIPE -p $pool $file 2>/dev/null && {
7563 error_noexit "expected failure when creating file" \
7568 # get param should return err once pool is gone
7569 if wait_update $HOSTNAME "lctl get_param -n \
7570 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7572 remove_pool_from_list $FSNAME.$pool
7575 error_noexit "Pool $FSNAME.$pool is not destroyed"
7579 # Get and check the actual stripe count of one file.
7580 # Usage: check_stripe_count <file> <expected_stripe_count>
7581 check_stripe_count() {
7586 [[ -z "$file" || -z "$expected" ]] &&
7587 error "check_stripe_count: invalid argument"
7589 local cmd="$GETSTRIPE -c $file"
7590 actual=$($cmd) || error "$cmd failed"
7591 actual=${actual%% *}
7593 if [[ $actual -ne $expected ]]; then
7594 [[ $expected -eq -1 ]] ||
7595 error "$cmd wrong: found $actual, expected $expected"
7596 [[ $actual -eq $OSTCOUNT ]] ||
7597 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7601 # Get and check the actual list of OST indices on one file.
7602 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7608 [[ -z "$file" || -z "$expected" ]] &&
7609 error "check_obdidx: invalid argument!"
7611 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7612 grep -v obdidx | awk '{print $1}' | xargs))
7614 [[ $obdidx = $expected ]] ||
7615 error "list of OST indices on $file is $obdidx," \
7616 "should be $expected"
7619 # Get and check the actual OST index of the first stripe on one file.
7620 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7621 check_start_ost_idx() {
7626 [[ -z "$file" || -z "$expected" ]] &&
7627 error "check_start_ost_idx: invalid argument!"
7629 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7632 [[ $start_ost_idx = $expected ]] ||
7633 error "OST index of the first stripe on $file is" \
7634 "$start_ost_idx, should be $expected"
7637 killall_process () {
7638 local clients=${1:-$(hostname)}
7643 do_nodes $clients "killall $signal $name"