3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export GSS_PIPEFS=false
15 export SHARED_KEY=${SHARED_KEY:-false}
16 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
17 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
18 export SK_MOUNTED=${SK_MOUNTED:-false}
19 export SK_FLAVOR=${SK_FLAVOR:-ski}
20 export SK_NO_KEY=${SK_NO_KEY:-true}
21 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
22 export SK_S2S=${SK_S2S:-false}
23 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
24 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
25 export IDENTITY_UPCALL=default
27 # specify environment variable containing batch job name for server statistics
28 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
30 #export PDSH="pdsh -S -Rssh -w"
31 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
32 export UMOUNT=${UMOUNT:-"umount -d"}
34 export LSNAPSHOT_CONF="/etc/ldev.conf"
35 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
37 # sles12 umount has a issue with -d option
38 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
39 export UMOUNT="umount"
42 # function used by scripts run on remote nodes
43 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
44 . $LUSTRE/tests/functions.sh
45 . $LUSTRE/tests/yaml.sh
47 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
49 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
51 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
53 if [ -f "$EXCEPT_LIST_FILE" ]; then
54 echo "Reading test skip list from $EXCEPT_LIST_FILE"
59 # check config files for options in decreasing order of preference
60 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
61 MODPROBECONF=/etc/modprobe.d/lustre.conf
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
63 MODPROBECONF=/etc/modprobe.d/Lustre
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
65 MODPROBECONF=/etc/modprobe.conf
67 sanitize_parameters() {
68 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
71 if [ -d "$path" ]; then
72 eval export $i=$(echo $path | sed -r 's/\/+$//g')
78 [[ $DIR/ = $MOUNT/* ]] ||
79 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
80 [[ $DIR1/ = $MOUNT1/* ]] ||
81 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
82 [[ $DIR2/ = $MOUNT2/* ]] ||
83 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
85 [ -n "$failed" ] && exit 99 || true
89 echo "usage: $0 [-r] [-f cfgfile]"
97 [ -z "$DEFAULT_SUITES"] && return 0
98 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
100 local form="%-13s %-17s %-9s %s %s\n"
101 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
102 echo "------------------------------------------------------------------------------------"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 [ "${!O}" = "no" ] && continue || true
106 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
107 local log=${TMP}/${o}.log
108 if is_sanity_benchmark $o; then
109 log=${TMP}/sanity-benchmark.log
114 local status=Unfinished
116 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
118 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
119 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
120 total=$(grep duration $log | awk '{ print $2 }')
121 if [ "${!O}" = "done" ]; then
125 local durations=$(egrep "^PASS|^FAIL" $log |
126 tr -d "("| sed s/s\)$//g |
127 awk '{ print $2":"$3"|" }')
128 details=$(printf "%s\n%s %s %s\n" "$details" \
129 "DDETAILS" "$O" "$(echo $durations)")
132 printf "$form" $status "$O" "${total}" "E=$skipped"
133 printf "$form" "-" "-" "-" "S=$(echo $slow)"
136 for O in $DEFAULT_SUITES; do
137 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
138 if [ "${!O}" = "no" ]; then
139 printf "$form" "Skipped" "$O" ""
143 # print the detailed tests durations if DDETAILS=true
150 export LUSTRE=$(absolute_path $LUSTRE)
151 export TESTSUITE=$(basename $0 .sh)
152 export TEST_FAILED=false
153 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
154 export RPC_MODE=${RPC_MODE:-false}
155 export DO_CLEANUP=${DO_CLEANUP:-true}
156 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
158 export MKE2FS=$MKE2FS
159 if [ -z "$MKE2FS" ]; then
160 if which mkfs.ldiskfs >/dev/null 2>&1; then
161 export MKE2FS=mkfs.ldiskfs
167 export DEBUGFS=$DEBUGFS
168 if [ -z "$DEBUGFS" ]; then
169 if which debugfs.ldiskfs >/dev/null 2>&1; then
170 export DEBUGFS=debugfs.ldiskfs
172 export DEBUGFS=debugfs
176 export TUNE2FS=$TUNE2FS
177 if [ -z "$TUNE2FS" ]; then
178 if which tunefs.ldiskfs >/dev/null 2>&1; then
179 export TUNE2FS=tunefs.ldiskfs
181 export TUNE2FS=tune2fs
185 export E2LABEL=$E2LABEL
186 if [ -z "$E2LABEL" ]; then
187 if which label.ldiskfs >/dev/null 2>&1; then
188 export E2LABEL=label.ldiskfs
190 export E2LABEL=e2label
194 export DUMPE2FS=$DUMPE2FS
195 if [ -z "$DUMPE2FS" ]; then
196 if which dumpfs.ldiskfs >/dev/null 2>&1; then
197 export DUMPE2FS=dumpfs.ldiskfs
199 export DUMPE2FS=dumpe2fs
203 export E2FSCK=$E2FSCK
204 if [ -z "$E2FSCK" ]; then
205 if which fsck.ldiskfs >/dev/null 2>&1; then
206 export E2FSCK=fsck.ldiskfs
212 export RESIZE2FS=$RESIZE2FS
213 if [ -z "$RESIZE2FS" ]; then
214 if which resizefs.ldiskfs >/dev/null 2>&1; then
215 export RESIZE2FS=resizefs.ldiskfs
217 export RESIZE2FS=resize2fs
221 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
222 export FSCK_MAX_ERR=4 # File system errors left uncorrected
224 export ZFS=${ZFS:-zfs}
225 export ZPOOL=${ZPOOL:-zpool}
226 export ZDB=${ZDB:-zdb}
227 export PARTPROBE=${PARTPROBE:-partprobe}
229 #[ -d /r ] && export ROOT=${ROOT:-/r}
230 export TMP=${TMP:-$ROOT/tmp}
231 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
232 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
233 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
235 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
236 if ! echo $PATH | grep -q $LUSTRE/utils; then
237 export PATH=$LUSTRE/utils:$PATH
239 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
240 export PATH=$LUSTRE/utils/gss:$PATH
242 if ! echo $PATH | grep -q $LUSTRE/tests; then
243 export PATH=$LUSTRE/tests:$PATH
245 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
246 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
248 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
249 [ ! -f "$LST" ] && export LST=$(which lst)
250 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
251 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
252 export MCREATE=${MCREATE:-mcreate}
253 # Ubuntu, at least, has a truncate command in /usr/bin
254 # so fully path our truncate command.
255 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
256 export FSX=${FSX:-$LUSTRE/tests/fsx}
257 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
258 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
259 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
260 export PATH=$LUSTRE/tests/racer:$PATH:
262 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
263 export PATH=$LUSTRE/tests/mpi:$PATH
265 export RSYNC_RSH=${RSYNC_RSH:-rsh}
267 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
268 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
269 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
270 [ ! -f "$LFS" ] && export LFS=$(which lfs)
271 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
272 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
274 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
275 if [ ! -f "$L_GETIDENTITY" ]; then
276 if `which l_getidentity > /dev/null 2>&1`; then
277 export L_GETIDENTITY=$(which l_getidentity)
279 export L_GETIDENTITY=NONE
282 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
283 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
284 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
285 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
286 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
287 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
288 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
289 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
290 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
291 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
292 [ ! -f "$LUSTRE_RMMOD" ] &&
293 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
294 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
295 [ ! -f "$LFS_MIGRATE" ] &&
296 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
297 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
298 [ ! -f "$LR_READER" ] &&
299 export LR_READER=$(which lr_reader 2> /dev/null)
300 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
301 export NAME=${NAME:-local}
302 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
303 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
304 export LGSSD=$(which lgssd)
305 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
306 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
307 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
309 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
311 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
312 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
314 if [ "$ACCEPTOR_PORT" ]; then
315 export PORT_OPT="--port $ACCEPTOR_PORT"
319 $RPC_MODE || echo "Using GSS shared-key feature"
320 which lgss_sk > /dev/null 2>&1 ||
321 error_exit "built with lgss_sk disabled! SEC=$SEC"
329 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
330 which lgss_keyring > /dev/null 2>&1 ||
331 error_exit "built with gss disabled! SEC=$SEC"
342 IDENTITY_UPCALL=false
346 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
348 # Paths on remote nodes, if different
349 export RLUSTRE=${RLUSTRE:-$LUSTRE}
350 export RPWD=${RPWD:-$PWD}
351 export I_MOUNTED=${I_MOUNTED:-"no"}
352 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
353 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
354 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
355 ! -f $LUSTRE/mdt/mdt.ko ]; then
356 export CLIENTMODSONLY=yes
359 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
360 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
364 while getopts "rvwf:" opt $*; do
369 w) WRITECONF=writeconf;;
374 shift $((OPTIND - 1))
377 # print the durations of each test if "true"
378 DDETAILS=${DDETAILS:-false}
379 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
384 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
391 ncpts=$(do_facet $facet "lctl get_param -n " \
392 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
394 if [ $ncpts -eq 0 ]; then
401 # Return a numeric version code based on a version string. The version
402 # code is useful for comparison two version strings to see which is newer.
404 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
405 eval set -- $(tr "[:punct:]" " " <<< $*)
407 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
410 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
411 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
413 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
415 # usage: lustre_build_version
417 # All Lustre versions support "lctl get_param" to report the version of the
418 # code running in the kernel (what our tests are interested in), but it
419 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
420 # the "version" parameter doesn't include "lustre: " at the beginning.
421 # If that fails, call "lctl lustre_build_version" which prints either (or both)
422 # the userspace and kernel build versions, but until 2.8.55 required root
423 # access to get the Lustre kernel version. If that also fails, fall back to
424 # using "lctl --version", which is easy to parse and works without the kernel
425 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
426 # not the module version, though they are usually the same.
428 # Various commands and their output format for different Lustre versions:
429 # lctl get_param version: 2.9.55
430 # lctl get_param version: lustre: 2.8.53
431 # lctl get_param version: lustre: 2.6.52
432 # kernel: patchless_client
433 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
434 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
435 # lctl lustre_build_version: error: lustre_build_version: Permission denied
436 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
437 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
438 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
439 # lctl --version: lctl 2.6.50
441 # output: prints version string to stdout in (up to 4) dotted-decimal values
442 lustre_build_version() {
443 local facet=${1:-client}
446 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
447 $LCTL lustre_build_version 2>/dev/null ||
448 $LCTL --version 2>/dev/null | cut -d' ' -f2")
449 local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
450 [ -n "$lver" ] && ver="$lver"
452 sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
456 # Report the Lustre numeric build version code for the supplied facet.
457 lustre_version_code() {
458 version_code $(lustre_build_version $1)
462 /sbin/lsmod | grep -q "^\<$1\>"
474 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
477 # parallels can't load modules directly from prlfs, use /tmp instead
478 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
479 local target="$(mktemp)"
481 cp "$module" "$target"
484 [[ $rc == 0 ]] && PRLFS=true
492 # Load a module on the system where this is running.
494 # usage: load_module module_name [module arguments for insmod/modprobe]
496 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
497 # will be used as the arguments. Otherwise arguments will be obtained from
498 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
505 BASE=$(basename $module $EXT)
507 module_loaded ${BASE} && return
509 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
510 # else from modprobe.conf
511 if [ $# -eq 0 ]; then
512 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
513 # Bash until 4.x, so we resort to eval.
514 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
515 eval set -- \$$optvar
516 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
517 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
519 opt=$(awk -v var="^options $BASE" '$0 ~ var \
520 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
521 set -- $(echo -n $opt)
523 # Ensure we have accept=all for lnet
524 if [ $(basename $module) = lnet ]; then
525 # OK, this is a bit wordy...
526 local arg accept_all_present=false
529 [ "$arg" = accept=all ] && \
530 accept_all_present=true
532 $accept_all_present || set -- "$@" accept=all
538 [ $# -gt 0 ] && echo "${module} options: '$*'"
540 # Note that insmod will ignore anything in modprobe.conf, which is why
541 # we're passing options on the command-line.
542 if [[ "$BASE" == "lnet_selftest" ]] &&
543 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
544 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
545 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
546 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
547 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
549 # must be testing a "make install" or "rpm" installation
550 # note failed to load ptlrpc_gss is considered not fatal
551 if [[ "$BASE" == "ptlrpc_gss" ]]; then
552 modprobe $BASE "$@" 2>/dev/null ||
553 echo "gss/krb5 is not supported"
560 load_modules_local() {
561 if [ -n "$MODPROBE" ]; then
563 echo "Using modprobe to load modules"
567 echo Loading modules from $LUSTRE
571 if [ -f /sys/devices/system/cpu/online ]; then
572 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
573 echo "detected $ncpus online CPUs by sysfs"
575 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
577 if [ $rc -eq 0 ]; then
578 echo "detected $ncpus online CPUs by getconf"
580 echo "Can't detect number of CPUs"
585 # if there is only one CPU core, libcfs can only create one partition
586 # if there is more than 4 CPU cores, libcfs should create multiple CPU
587 # partitions. So we just force libcfs to create 2 partitions for
588 # system with 2 or 4 cores
589 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
590 # force to enable multiple CPU partitions
591 echo "Force libcfs to create 2 CPU partitions"
592 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
594 echo "libcfs will create CPU partition based on online CPUs"
597 load_module ../libcfs/libcfs/libcfs
598 # Prevent local MODOPTS_LIBCFS being passed as part of environment
599 # variable to remote nodes
603 load_module ../lnet/lnet/lnet
605 LNDPATH=${LNDPATH:-"../lnet/klnds"}
606 if [ -z "$LNETLND" ]; then
608 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
609 tcp*) LNETLND="socklnd/ksocklnd" ;;
610 *) local lnd="${NETTYPE%%[0-9]}lnd"
611 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
612 LNETLND="$lnd/k$lnd" ||
613 LNETLND="socklnd/ksocklnd"
616 load_module ../lnet/klnds/$LNETLND
617 load_module obdclass/obdclass
618 load_module ptlrpc/ptlrpc
619 load_module ptlrpc/gss/ptlrpc_gss
627 load_module obdecho/obdecho
628 if ! client_only; then
629 SYMLIST=/proc/kallsyms
630 grep -q crc16 $SYMLIST ||
631 { modprobe crc16 2>/dev/null || true; }
632 grep -q -w jbd2 $SYMLIST ||
633 { modprobe jbd2 2>/dev/null || true; }
634 load_module lfsck/lfsck
635 [ "$LQUOTA" != "no" ] &&
636 load_module quota/lquota $LQUOTAOPTS
637 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
638 lsmod | grep zfs >&/dev/null || modprobe zfs
639 load_module osd-zfs/osd_zfs
641 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
642 grep -q exportfs_decode_fh $SYMLIST ||
643 { modprobe exportfs 2> /dev/null || true; }
644 grep -q -w mbcache $SYMLIST ||
645 { modprobe mbcache 2>/dev/null || true; }
646 load_module ../ldiskfs/ldiskfs
647 load_module osd-ldiskfs/osd_ldiskfs
659 load_module llite/lustre
660 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
662 rm -f $OGDB/ogdb-$HOSTNAME
663 $LCTL modules > $OGDB/ogdb-$HOSTNAME
665 # 'mount' doesn't look in $PATH, just sbin
666 local mount_lustre=$LUSTRE/utils/mount.lustre
667 if [ -f $mount_lustre ]; then
668 local sbin_mount=$(readlink -f /sbin)/mount.lustre
669 if grep -qw "$sbin_mount" /proc/mounts; then
670 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
672 if ! grep -qw "$sbin_mount" /proc/mounts; then
673 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
674 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
675 cat <<- EOF > "$sbin_mount"
678 echo "This $sbin_mount just a mountpoint." 1>&2
679 echo "It is never supposed to be run." 1>&2
680 logger -p emerg -- "using stub $sbin_mount $@"
683 chmod a+x $sbin_mount
685 mount --bind $mount_lustre $sbin_mount ||
686 error "can't bind $mount_lustre to $sbin_mount"
694 # load modules on remote nodes optionally
695 # lustre-tests have to be installed on these nodes
696 if $LOAD_MODULES_REMOTE; then
697 local list=$(comma_list $(remote_nodes_list))
698 if [ -n "$list" ]; then
699 echo "loading modules on: '$list'"
700 do_rpc_nodes "$list" load_modules_local
706 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
707 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
708 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
709 echo "$LEAK_LUSTRE" 1>&2
710 echo "$LEAK_PORTALS" 1>&2
711 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
712 echo "Memory leaks detected"
713 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
719 wait_exit_ST client # bug 12845
721 $LUSTRE_RMMOD ldiskfs || return 2
723 if $LOAD_MODULES_REMOTE; then
724 local list=$(comma_list $(remote_nodes_list))
725 if [ -n "$list" ]; then
726 echo "unloading modules on: '$list'"
727 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
728 do_rpc_nodes "$list" check_mem_leak
732 local sbin_mount=$(readlink -f /sbin)/mount.lustre
733 if grep -qe "$sbin_mount " /proc/mounts; then
734 umount $sbin_mount || true
735 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
739 check_mem_leak || return 254
741 echo "modules unloaded."
746 local facet=${1:-$SINGLEMDS}
747 local fstype=$(facet_fstype $facet)
750 ldiskfs) size=50;; # largest seen is 44, leave some headroom
751 zfs) size=400;; # largest seen is 384
758 local facet=${1:-$SINGLEMDS}
759 local fstype=$(facet_fstype $facet)
762 ldiskfs) size=4;; # ~4KB per inode
763 zfs) size=11;; # 10 to 11KB per inode
769 check_gss_daemon_nodes() {
773 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
774 if [ \\\"\\\$num\\\" -ne 1 ]; then
775 echo \\\$num instance of $dname;
780 check_gss_daemon_facet() {
784 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
785 if [ $num -ne 1 ]; then
786 echo "$num instance of $dname on $facet"
795 echo Stopping $@ on $list
796 do_nodes $list "killall -2 $@ 2>/dev/null || true"
799 # start gss daemons on all nodes, or "daemon" on "nodes" if set
800 start_gss_daemons() {
804 if [ "$nodes" ] && [ "$daemon" ] ; then
805 echo "Starting gss daemon on nodes: $nodes"
806 do_nodes $nodes "$daemon" || return 8
810 nodes=$(comma_list $(mdts_nodes))
811 echo "Starting gss daemon on mds: $nodes"
813 # Start all versions, in case of switching
814 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
816 do_nodes $nodes "$LSVCGSSD -v" || return 1
819 do_nodes $nodes "$LGSSD -v" || return 2
822 nodes=$(comma_list $(osts_nodes))
823 echo "Starting gss daemon on ost: $nodes"
825 # Start all versions, in case of switching
826 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
828 do_nodes $nodes "$LSVCGSSD -v" || return 3
830 # starting on clients
832 local clients=${CLIENTS:-$HOSTNAME}
834 echo "Starting $LGSSD on clients $clients "
835 do_nodes $clients "$LGSSD -v" || return 4
838 # wait daemons entering "stable" status
842 # check daemons are running
844 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
845 check_gss_daemon_nodes $nodes lsvcgssd || return 5
847 nodes=$(comma_list $(mdts_nodes))
848 check_gss_daemon_nodes $nodes lgssd || return 6
851 check_gss_daemon_nodes $clients lgssd || return 7
856 local nodes=$(comma_list $(mdts_nodes))
858 send_sigint $nodes lsvcgssd lgssd
860 nodes=$(comma_list $(osts_nodes))
861 send_sigint $nodes lsvcgssd
863 nodes=${CLIENTS:-$HOSTNAME}
864 send_sigint $nodes lgssd
868 # Add mount flags for shared key
870 if grep -q skpath <<< "$mt_opts" ; then
871 mt_opts=$(echo $mt_opts |
872 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
874 if [ -z "$mt_opts" ]; then
875 mt_opts="-o skpath=$SK_PATH"
877 mt_opts="$mt_opts,skpath=$SK_PATH"
893 if ! module_loaded ptlrpc_gss; then
894 load_module ptlrpc/gss/ptlrpc_gss
895 module_loaded ptlrpc_gss ||
896 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
899 if $GSS_KRB5 || $GSS_SK; then
900 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
903 if $GSS_SK && $SK_NO_KEY; then
904 local numclients=${1:-$CLIENTCOUNT}
905 local clients=${CLIENTS:-$HOSTNAME}
907 # security ctx config for keyring
910 mount -o bind $SK_OM_PATH /etc/request-key.d/
911 local lgssc_conf_line='create lgssc * * '
912 lgssc_conf_line+=$(which lgss_keyring)
913 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
915 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
916 echo "$lgssc_conf_line" > $lgssc_conf_file
917 [ -e $lgssc_conf_file ] ||
918 error_exit "Could not find key options in $lgssc_conf_file"
920 if ! local_mode; then
921 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
923 do_nodes $(comma_list $(all_nodes)) "mount \
924 -o bind $SK_OM_PATH \
926 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
927 $HOSTNAME:$lgssc_conf_file \
928 $lgssc_conf_file >/dev/null 2>&1"
931 # create shared key on all nodes
932 mkdir -p $SK_PATH/nodemap
933 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
934 $SK_PATH/$FSNAME-*.key
935 # for nodemap testing each client may need own key,
936 # and S2S now requires keys as well, both for "client"
939 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
940 -w $SK_PATH/$FSNAME-nmclient.key \
941 -d /dev/urandom >/dev/null 2>&1
942 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
943 -w $SK_PATH/$FSNAME-s2s-server.key \
944 -d /dev/urandom >/dev/null 2>&1
947 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
948 -d /dev/urandom >/dev/null 2>&1
950 for i in $(seq 0 $((numclients - 1))); do
951 lgss_sk -t server -f$FSNAME -n c$i \
952 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
956 if ! local_mode; then
957 do_nodes $(comma_list $(all_nodes)) "rsync -av \
958 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
960 # Set client keys to client type to generate prime P
962 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
963 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
965 do_nodes $clients "lgss_sk -t client -m \
966 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
967 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
968 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
970 # This is required for servers as well, if S2S in use
972 do_nodes $(comma_list $(mdts_nodes)) \
973 "cp $SK_PATH/$FSNAME-s2s-server.key \
974 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
975 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
977 do_nodes $(comma_list $(osts_nodes)) \
978 "cp $SK_PATH/$FSNAME-s2s-server.key \
979 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
980 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
982 do_nodes $clients "lgss_sk -t client \
983 -m $SK_PATH/$FSNAME-nmclient.key \
986 # mount options for servers and clients
987 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
988 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
989 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
990 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
994 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
996 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1003 # maybe cleanup credential cache?
1010 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1011 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1012 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1016 $RPC_MODE || echo "Cleaning up Shared Key.."
1017 do_nodes $(comma_list $(all_nodes)) "rm -f \
1018 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1019 # Remove the mount and clean up the files we added to SK_PATH
1020 do_nodes $(comma_list $(all_nodes)) "umount \
1021 /etc/request-key.d/"
1022 do_nodes $(comma_list $(all_nodes)) "rm -f \
1023 $SK_OM_PATH/lgssc.conf"
1024 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1031 local var=${facet}_svc
1039 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1040 tr '[:lower:]' '[:upper:]'
1046 if [ $facet == mgs ] || [ $facet == client ]; then
1050 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1058 if [ -n "${!var}" ]; then
1063 var=$(facet_type $facet)FSTYPE
1064 if [ -n "${!var}" ]; then
1069 if [ -n "$FSTYPE" ]; then
1074 if [[ $facet == mgs ]] && combined_mgs_mds; then
1086 local facets=$(get_facets)
1089 for facet in ${facets//,/ }; do
1090 if [ $node == $(facet_host $facet) ] ||
1091 [ $node == "$(facet_failover_host $facet)" ]; then
1092 fstype=$(facet_fstype $facet)
1093 if [[ $fstypes != *$fstype* ]]; then
1094 fstypes+="${fstypes:+,}$fstype"
1103 local num=$(facet_number $facet)
1106 if [[ $(facet_type $facet) = OST ]]; then
1107 index=OSTINDEX${num}
1108 if [[ -n "${!index}" ]]; then
1113 index=${OST_INDICES[num - 1]}
1116 [[ -n "$index" ]] || index=$((num - 1))
1124 local fstype=$(facet_fstype $facet)
1128 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1130 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1131 ${dev} 2>/dev/null");;
1133 error "unknown fstype!";;
1141 local device=$(mdsdevname $num)
1142 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1148 local device=$(ostdevname $num)
1149 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1154 # Get the device of a facet.
1161 mgs) device=$(mgsdevname) ;;
1162 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1163 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1164 fs2mds) device=$(mdsdevname 1_2) ;;
1165 fs2ost) device=$(ostdevname 1_2) ;;
1166 fs3ost) device=$(ostdevname 2_2) ;;
1174 # Get the virtual device of a facet.
1181 mgs) device=$(mgsvdevname) ;;
1182 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1183 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1184 fs2mds) device=$(mdsvdevname 1_2) ;;
1185 fs2ost) device=$(ostvdevname 1_2) ;;
1186 fs3ost) device=$(ostvdevname 2_2) ;;
1194 local virt=$(virt-what 2> /dev/null)
1196 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1198 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1201 VMware|KVM|VirtualBox|Parallels)
1202 echo $virt | tr '[A-Z]' '[a-z]' ;;
1208 # Re-read the partition table on failover partner host.
1209 # After a ZFS storage pool is created on a shared device, the partition table
1210 # on the device may change. However, the operating system on the failover
1211 # host may not notice the change automatically. Without the up-to-date partition
1212 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1213 # relative to partition rather than disk beginnings.
1215 # This function performs partprobe on the failover host to make it re-read the
1218 refresh_partition_table() {
1223 host=$(facet_passive_host $facet)
1224 if [[ -n "$host" ]]; then
1225 do_node $host "$PARTPROBE $device"
1230 # Get ZFS storage pool name.
1237 device=$(facet_device $facet)
1238 # poolname is string before "/"
1239 poolname="${device%%/*}"
1246 # Get ZFS local fsname.
1248 zfs_local_fsname() {
1250 local lfsname=$(basename $(facet_device $facet))
1256 # Create ZFS storage pool.
1263 local opts=${@:-"-o cachefile=none"}
1265 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1266 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1267 $ZPOOL create -f $opts $poolname $vdev"
1271 # Create ZFS file system.
1277 local opts=${@:-"-o mountpoint=legacy"}
1279 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1280 $ZFS create $opts $dataset"
1284 # Export ZFS storage pool.
1285 # Before exporting the pool, all datasets within the pool should be unmounted.
1293 poolname=$(zpool_name $facet)
1295 if [[ -n "$poolname" ]]; then
1296 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1297 grep -q ^$poolname/ /proc/mounts ||
1298 $ZPOOL export $opts $poolname"
1303 # Destroy ZFS storage pool.
1304 # Destroy the given pool and free up any devices for other use. This command
1305 # tries to unmount any active datasets before destroying the pool.
1306 # -f Force any active datasets contained within the pool to be unmounted.
1310 local poolname=${2:-$(zpool_name $facet)}
1312 if [[ -n "$poolname" ]]; then
1313 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1314 $ZPOOL destroy -f $poolname"
1319 # Import ZFS storage pool.
1320 # Force importing, even if the pool appears to be potentially active.
1325 local opts=${@:-"-o cachefile=none"}
1328 poolname=$(zpool_name $facet)
1330 if [[ -n "$poolname" ]]; then
1331 opts+=" -d $(dirname $(facet_vdevice $facet))"
1332 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1333 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1334 $ZPOOL import -f $opts $poolname"
1339 # Reimport ZFS storage pool with new name
1344 local opts="-o cachefile=none"
1345 local poolname=$(zpool_name $facet)
1347 opts+=" -d $(dirname $(facet_vdevice $facet))"
1348 do_facet $facet "$ZPOOL export $poolname;
1349 $ZPOOL import $opts $poolname $newpool"
1353 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1354 # is not automatically imported on system startup.
1356 # In a failover environment, this will provide resource level fencing which
1357 # will ensure that the same ZFS storage pool will not be imported concurrently
1358 # on different nodes.
1360 disable_zpool_cache() {
1364 poolname=$(zpool_name $facet)
1366 if [[ -n "$poolname" ]]; then
1367 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1372 # This and set_osd_param() shall be used to access OSD parameters
1373 # once existed under "obdfilter":
1378 # writethrough_cache_enable
1382 local device=${2:-$FSNAME-OST*}
1385 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1386 osd-*.$device.$name 2>&1" | grep -v 'error:'
1391 local device=${2:-$FSNAME-OST*}
1395 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1396 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1400 local dz=${1:-$DEBUG_SIZE}
1402 if [ -f /sys/devices/system/cpu/possible ]; then
1403 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1405 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1408 # bug 19944, adjust size to be -gt num_possible_cpus()
1409 # promise 2MB for every cpu at least
1410 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1413 lctl set_param debug_mb=$dz
1416 set_default_debug () {
1417 local debug=${1:-"$PTLDEBUG"}
1418 local subsys=${2:-"$SUBSYSTEM"}
1419 local debug_size=${3:-$DEBUG_SIZE}
1421 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1422 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1424 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1427 set_default_debug_nodes () {
1430 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1431 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1435 do_rpc_nodes "$nodes" set_default_debug \
1436 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1439 set_default_debug_facet () {
1441 local node=$(facet_active_host $facet)
1442 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1444 set_default_debug_nodes $node
1448 local hostid=${1:-$(hostid)}
1450 if [ ! -s /etc/hostid ]; then
1451 printf $(echo -n $hostid |
1452 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1458 local facets=${1:-$(get_facets)}
1461 for facet in ${facets//,/ }; do
1464 [ $RC -eq 0 ] && continue
1466 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1467 skip "Restart of $facet failed!." && touch $LU482_FAILED
1469 error "Restart of $facet failed!"
1476 # Add argument "arg" (e.g., "loop") to the comma-separated list
1477 # of arguments for option "opt" (e.g., "-o") on command
1478 # line "opts" (e.g., "-o flock").
1484 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1486 if echo "$opts" | grep -q $opt_pattern; then
1487 opts=$(echo "$opts" | sed -e \
1488 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1490 opts+="${opts:+ }$opt $arg"
1498 local dev=$(facet_active $facet)_dev
1499 local opt=${facet}_opt
1500 local mntpt=$(facet_mntpt $facet)
1501 local opts="${!opt} $@"
1502 local fstype=$(facet_fstype $facet)
1505 module_loaded lustre || load_modules
1507 if [ $(facet_fstype $facet) == ldiskfs ] &&
1508 ! do_facet $facet test -b ${!dev}; then
1509 opts=$(csa_add "$opts" -o loop)
1512 if [[ $(facet_fstype $facet) == zfs ]]; then
1513 # import ZFS storage pool
1514 import_zpool $facet || return ${PIPESTATUS[0]}
1519 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1521 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1522 lustre:svname ${!dev}");;
1524 error "unknown fstype!";;
1527 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1528 # for testing LU-482 error handling in mount_facets() and test_0a()
1529 if [ -f $TMP/test-lu482-trigger ]; then
1532 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1537 if [ $RC -ne 0 ]; then
1538 echo "Start of ${!dev} on ${facet} failed ${RC}"
1542 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1543 if [[ "$health" != "healthy" ]]; then
1544 error "$facet is in a unhealthy state"
1547 set_default_debug_facet $facet
1549 if [[ $facet == mds* ]]; then
1551 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1554 if [[ $opts =~ .*nosvc.* ]]; then
1555 echo "Start ${!dev} without service"
1560 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1561 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1562 "" || error "${!dev} failed to initialize!";;
1564 wait_update_facet ${facet} "$ZFS get -H -o value \
1565 lustre:svname ${!dev} 2>/dev/null | \
1566 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1567 error "${!dev} failed to initialize!";;
1570 error "unknown fstype!";;
1574 # commit the device label change to disk
1575 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1576 echo "Commit the device label on ${!dev}"
1577 do_facet $facet "sync; sleep 1; sync"
1581 label=$(devicelabel ${facet} ${!dev})
1582 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1583 eval export ${facet}_svc=${label}
1584 echo Started ${label}
1589 # start facet device options
1595 eval export ${facet}_dev=${device}
1596 eval export ${facet}_opt=\"$@\"
1598 local varname=${facet}failover_dev
1599 if [ -n "${!varname}" ] ; then
1600 eval export ${facet}failover_dev=${!varname}
1602 eval export ${facet}failover_dev=$device
1605 local mntpt=$(facet_mntpt $facet)
1606 do_facet ${facet} mkdir -p $mntpt
1607 eval export ${facet}_MOUNT=$mntpt
1608 mount_facet ${facet}
1611 if [[ $facet == mds* ]]; then
1613 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1624 local HOST=`facet_active_host $facet`
1625 [ -z $HOST ] && echo stop: no host for $facet && return 0
1627 local mntpt=$(facet_mntpt $facet)
1628 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1629 if [ ${running} -ne 0 ]; then
1630 echo "Stopping $mntpt (opts:$@) on $HOST"
1631 do_facet ${facet} $UMOUNT $@ $mntpt
1634 # umount should block, but we should wait for unrelated obd's
1635 # like the MGS or MGC to also stop.
1636 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1638 if [[ $(facet_fstype $facet) == zfs ]]; then
1639 # export ZFS storage pool
1640 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1644 # save quota version (both administrative and operational quotas)
1645 # add an additional parameter if mountpoint is ever different from $MOUNT
1647 # XXX This function is kept for interoperability with old server (< 2.3.50),
1648 # it should be removed whenever we drop the interoperability for such
1650 quota_save_version() {
1651 local fsname=${2:-$FSNAME}
1653 local ver=$(tr -c -d "123" <<< $spec)
1654 local type=$(tr -c -d "ug" <<< $spec)
1656 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1658 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1660 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1662 local osts=$(get_facets OST)
1663 for ost in ${osts//,/ }; do
1665 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1669 # client could mount several lustre
1671 # XXX This function is kept for interoperability with old server (< 2.3.50),
1672 # it should be removed whenever we drop the interoperability for such
1675 local fsname=${1:-$FSNAME}
1677 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1679 do_nodes $(comma_list $(osts_nodes)) \
1680 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1684 # get mdt quota type
1686 local varsvc=${SINGLEMDS}_svc
1687 do_facet $SINGLEMDS $LCTL get_param -n \
1688 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1691 # get ost quota type
1693 # All OSTs should have same quota type
1694 local varsvc=ost1_svc
1695 do_facet ost1 $LCTL get_param -n \
1696 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1699 # restore old quota type settings
1701 if [ "$old_MDT_QUOTA_TYPE" ]; then
1702 do_facet mgs $LCTL conf_param \
1703 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1705 if [ "$old_OST_QUOTA_TYPE" ]; then
1706 do_facet mgs $LCTL conf_param \
1707 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1711 # Handle the case when there is a space in the lfs df
1712 # "filesystem summary" line the same as when there is no space.
1713 # This will allow fixing the "lfs df" summary line in the future.
1715 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1718 # Get free inodes on the MDT specified by mdt index, free indoes on
1719 # the whole filesystem will be returned when index == -1.
1725 if [ $index -eq -1 ]; then
1728 mdt_uuid=$(mdtuuid_from_index $index)
1731 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1736 # Get the OST device status from 'lfs df' with a given OST index.
1740 local mnt_pnt=${2:-$MOUNT}
1743 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1744 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1750 # save old quota type & set new quota type
1751 local mdt_qtype=$(mdt_quota_type)
1752 local ost_qtype=$(ost_quota_type)
1754 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1755 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1757 export old_MDT_QUOTA_TYPE=$mdt_qtype
1758 export old_OST_QUOTA_TYPE=$ost_qtype
1760 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1761 error "set mdt quota type failed"
1762 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1763 error "set ost quota type failed"
1765 local quota_usrs=$QUOTA_USERS
1767 # get_filesystem_size
1768 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1769 local blk_soft=$((disksz + 1024))
1770 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1772 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1773 local i_soft=$inodes
1774 local i_hard=$((i_soft + i_soft / 20))
1776 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1777 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1778 "inode-hardlimit: $i_hard"
1781 for usr in $quota_usrs; do
1782 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1784 cmd="$LFS setquota -$type $usr -b $blk_soft"
1785 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1787 eval $cmd || error "$cmd FAILED!"
1789 # display the quota status
1790 echo "Quota settings for $usr : "
1791 $LFS quota -v -u $usr $mntpt || true
1798 local opts=${3:-$MOUNT_OPTS}
1799 opts=${opts:+-o $opts}
1800 local flags=${4:-$MOUNT_FLAGS}
1802 local device=$MGSNID:/$FSNAME$FILESET
1803 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1804 echo "Bad mount command: opt=$flags $opts dev=$device " \
1809 echo "Starting client: $client: $flags $opts $device $mnt"
1810 do_node $client mkdir -p $mnt
1811 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1812 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1814 #disable FILESET if not supported
1815 do_nodes $client lctl get_param -n \
1816 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1817 device=$MGSNID:/$FSNAME
1818 do_node $client mkdir -p $mnt/$FILESET
1819 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1822 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1823 # Mount using nodemap key
1824 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1825 if $SK_UNIQUE_NM; then
1826 mountkey=$SK_PATH/nodemap/c0.key
1828 local prunedopts=$(echo $opts |
1829 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
1830 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
1833 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
1837 set_default_debug_nodes $client
1849 [ "$3" ] && force=-f
1850 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1851 if [ $running -ne 0 ]; then
1852 echo "Stopping client $client $mnt (opts:$force)"
1853 do_node $client lsof -t $mnt || need_kill=no
1854 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1855 pids=$(do_node $client lsof -t $mnt | sort -u);
1856 if [ -n $pids ]; then
1857 do_node $client kill -9 $pids || true
1861 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1862 if [ $busy -ne 0 ] ; then
1863 echo "$mnt is still busy, wait one second" && sleep 1
1864 do_node $client umount $force $mnt
1869 # nodes is comma list
1870 sanity_mount_check_nodes () {
1876 # FIXME: assume that all cluster nodes run the same os
1877 [ "$(uname)" = Linux ] || return 0
1880 for mnt in $mnts ; do
1881 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1882 mpts=\\\$(mount | grep -c $mnt' ');
1883 if [ \\\$running -ne \\\$mpts ]; then
1884 echo \\\$(hostname) env are INSANE!;
1887 [ $? -eq 0 ] || rc=1
1892 sanity_mount_check_servers () {
1893 [ -n "$CLIENTONLY" ] &&
1894 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1895 echo Checking servers environments
1897 # FIXME: modify get_facets to display all facets wo params
1898 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1902 for facet in ${facets//,/ }; do
1903 node=$(facet_host ${facet})
1904 mntpt=$(facet_mntpt $facet)
1905 sanity_mount_check_nodes $node $mntpt ||
1906 { error "server $node environments are insane!"; return 1; }
1910 sanity_mount_check_clients () {
1911 local clients=${1:-$CLIENTS}
1912 local mntpt=${2:-$MOUNT}
1913 local mntpt2=${3:-$MOUNT2}
1915 [ -z $clients ] && clients=$(hostname)
1916 echo Checking clients $clients environments
1918 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1919 error "clients environments are insane!"
1922 sanity_mount_check () {
1923 sanity_mount_check_servers || return 1
1924 sanity_mount_check_clients || return 2
1927 # mount clients if not mouted
1928 zconf_mount_clients() {
1931 local opts=${3:-$MOUNT_OPTS}
1932 opts=${opts:+-o $opts}
1933 local flags=${4:-$MOUNT_FLAGS}
1934 local device=$MGSNID:/$FSNAME$FILESET
1935 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1936 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1941 echo "Starting client $clients: $flags $opts $device $mnt"
1942 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1943 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1944 # Mount with own nodemap key
1946 # Mount all server nodes first with per-NM keys
1947 for nmclient in ${clients//,/ }; do
1948 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
1949 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
1952 # set perms for per-nodemap keys else permission denied
1953 do_nodes $(comma_list $(all_nodes)) \
1954 "keyctl show | grep lustre | cut -c1-11 |
1956 xargs -IX keyctl setperm X 0x3f3f3f3f"
1957 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1959 for nmclient in ${clients//,/ }; do
1960 if $SK_UNIQUE_NM; then
1961 mountkey=$SK_PATH/nodemap/c$i.key
1963 do_node $nmclient "! grep -q $mnt' ' \
1964 /proc/mounts || umount $mnt"
1965 local prunedopts=$(add_sk_mntflag $prunedopts);
1966 prunedopts=$(echo $prunedopts | sed -e \
1967 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
1969 do_nodes $(comma_list $(all_server_nodes)) \
1972 do_node $nmclient $MOUNT_CMD $flags \
1973 $prunedopts $MGSNID:/$FSNAME $mnt ||
1978 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1980 do_nodes $clients $MOUNT_CMD $flags $opts \
1981 $MGSNID:/$FSNAME $mnt || return 1
1983 #disable FILESET if not supported
1984 do_nodes $clients lctl get_param -n \
1985 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1986 device=$MGSNID:/$FSNAME
1987 do_nodes $clients mkdir -p $mnt/$FILESET
1988 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1992 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1993 # Mount with nodemap key
1995 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1996 for nmclient in ${clients//,/ }; do
1997 if $SK_UNIQUE_NM; then
1998 mountkey=$SK_PATH/nodemap/c$i.key
2000 local prunedopts=$(echo $opts | sed -e \
2001 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2002 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2005 running=\\\$(mount | grep -c $mnt' ');
2007 if [ \\\$running -eq 0 ] ; then
2009 $MOUNT_CMD $flags $prunedopts $device $mnt;
2012 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2013 grep 'type lustre' | wc -l);
2014 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2015 echo zconf_mount_clients FAILED: \
2016 mount count \\\$running, not matching \
2017 with mount count of 'type lustre' \
2018 \\\$lustre_mnt_count;
2022 exit \\\$rc" || return ${PIPESTATUS[0]}
2029 if $SHARED_KEY; then
2030 tmpopts=$(add_sk_mntflag $opts)
2033 running=\\\$(mount | grep -c $mnt' ');
2035 if [ \\\$running -eq 0 ] ; then
2037 $MOUNT_CMD $flags $tmpopts $device $mnt;
2040 exit \\\$rc" || return ${PIPESTATUS[0]}
2043 echo "Started clients $clients: "
2044 do_nodes $clients "mount | grep $mnt' '"
2046 set_default_debug_nodes $clients
2051 zconf_umount_clients() {
2056 [ "$3" ] && force=-f
2058 echo "Stopping clients: $clients $mnt (opts:$force)"
2059 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2060 if [ \\\$running -ne 0 ] ; then
2061 echo Stopping client \\\$(hostname) $mnt opts:$force;
2062 lsof $mnt || need_kill=no;
2063 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2064 pids=\\\$(lsof -t $mnt | sort -u);
2065 if [ -n \\\"\\\$pids\\\" ]; then
2069 while umount $force $mnt 2>&1 | grep -q "busy"; do
2070 echo "$mnt is still busy, wait one second" && sleep 1;
2077 echo + $POWER_DOWN $node
2081 shutdown_node_hard () {
2083 local attempts=$SHUTDOWN_ATTEMPTS
2085 for i in $(seq $attempts) ; do
2088 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2089 echo "waiting for $host to fail attempts=$attempts"
2090 [ $i -lt $attempts ] || \
2091 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2097 local mnt=${2:-$MOUNT}
2100 if [ "$FAILURE_MODE" = HARD ]; then
2101 shutdown_node_hard $client
2103 zconf_umount_clients $client $mnt -f
2109 local facets="$(get_facets OST),$(get_facets MDS)"
2112 combined_mgs_mds || facets="$facets,mgs"
2114 for facet in ${facets//,/ }; do
2115 if [ $(facet_active_host $facet) == $host ]; then
2116 affected="$affected $facet"
2120 echo $(comma_list $affected)
2125 local host=${2:-$(facet_host $facet)}
2127 local label=$(convert_facet2label $facet)
2128 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2131 facets_up_on_host () {
2133 local facets=$(facets_on_host $host)
2136 for facet in ${facets//,/ }; do
2137 if $(facet_up $facet $host); then
2138 affected_up="$affected_up $facet"
2142 echo $(comma_list $affected_up)
2148 if [ "$FAILURE_MODE" = HARD ]; then
2149 shutdown_node_hard $(facet_active_host $facet)
2157 echo + $POWER_UP $node
2170 if [ "$FAILURE_MODE" = HARD ]; then
2171 reboot_node $(facet_active_host $facet)
2179 if [ "$FAILURE_MODE" = HARD ]; then
2189 for facet in ${facets//,/ }; do
2190 hosts=$(expand_list $hosts $(facet_host $facet) )
2196 _check_progs_installed () {
2200 for prog in $progs; do
2201 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2202 echo $prog missing on $(hostname)
2209 check_progs_installed () {
2213 do_rpc_nodes "$nodes" _check_progs_installed $@
2216 # recovery-scale functions
2218 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2221 start_client_load() {
2224 local var=$(node_var_name $client)_load
2225 eval export ${var}=$load
2227 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2228 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2229 END_RUN_FILE=$END_RUN_FILE \
2230 LOAD_PID_FILE=$LOAD_PID_FILE \
2231 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2232 TESTNAME=$TESTNAME \
2233 DBENCH_LIB=$DBENCH_LIB \
2234 DBENCH_SRC=$DBENCH_SRC \
2235 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2241 log "Started client load: ${load} on $client"
2243 # get the children process IDs
2244 local pids=$(ps --ppid $ppid -o pid= | xargs)
2245 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2249 start_client_loads () {
2250 local -a clients=(${1//,/ })
2251 local numloads=${#CLIENT_LOADS[@]}
2254 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2255 testnum=$((nodenum % numloads))
2256 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2258 # bug 22169: wait the background threads to start
2262 # only for remote client
2263 check_client_load () {
2265 local var=$(node_var_name $client)_load
2266 local testload=run_${!var}.sh
2268 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2270 # bug 18914: try to connect several times not only when
2271 # check ps, but while check_node_health also
2275 while [ $RC = 254 -a $tries -gt 0 ]; do
2279 if ! check_node_health $client; then
2281 if [ $RC -eq 254 ]; then
2282 # FIXME: not sure how long we shuold sleep here
2286 echo "check node health failed: RC=$RC "
2290 # We can continue try to connect if RC=254
2291 # Just print the warning about this
2292 if [ $RC = 254 ]; then
2293 echo "got a return status of $RC from do_node while checking " \
2294 "node health on $client"
2297 # see if the load is still on the client
2300 while [ $RC = 254 -a $tries -gt 0 ]; do
2304 if ! do_node $client \
2305 "ps auxwww | grep -v grep | grep -q $testload"; then
2310 if [ $RC = 254 ]; then
2311 echo "got a return status of $RC from do_node while checking " \
2312 "(node health and 'ps') the client load on $client"
2313 # see if we can diagnose a bit why this is
2318 check_client_loads () {
2319 local clients=${1//,/ }
2323 for client in $clients; do
2324 check_client_load $client
2326 if [ "$rc" != 0 ]; then
2327 log "Client load failed on node $client, rc=$rc"
2333 restart_client_loads () {
2334 local clients=${1//,/ }
2335 local expectedfail=${2:-""}
2339 for client in $clients; do
2340 check_client_load $client
2342 if [ "$rc" != 0 -a "$expectedfail" ]; then
2343 local var=$(node_var_name $client)_load
2344 start_client_load $client ${!var}
2345 echo "Restarted client load ${!var}: on $client. Checking ..."
2346 check_client_load $client
2348 if [ "$rc" != 0 ]; then
2349 log "Client load failed to restart on node $client, rc=$rc"
2350 # failure one client load means test fail
2351 # we do not need to check other
2360 # Start vmstat and save its process ID in a file.
2365 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2368 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2369 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2372 # Display the nodes on which client loads failed.
2373 print_end_run_file() {
2377 [ -s $file ] || return 0
2379 echo "Found the END_RUN_FILE file: $file"
2382 # A client load will stop if it finds the END_RUN_FILE file.
2383 # That does not mean the client load actually failed though.
2384 # The first node in END_RUN_FILE is the one we are interested in.
2387 if [ -n "$node" ]; then
2388 local var=$(node_var_name $node)_load
2390 local prefix=$TESTLOG_PREFIX
2391 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2392 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2393 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2395 echo "Client load ${!var} failed on node $node:"
2401 # Stop the process which had its PID saved in a file.
2406 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2408 do_nodes $nodes "test -f $pid_file &&
2409 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2412 # Stop all client loads.
2413 stop_client_loads() {
2414 local nodes=${1:-$CLIENTS}
2417 # stop the client loads
2418 stop_process $nodes $pid_file
2420 # clean up the processes that started them
2421 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2423 # End recovery-scale functions
2425 # verify that lustre actually cleaned up properly
2427 VAR=$(lctl get_param -n catastrophe 2>&1)
2428 if [ $? = 0 ] ; then
2429 if [ $VAR != 0 ]; then
2430 error "LBUG/LASSERT detected"
2433 BUSY=$(dmesg | grep -i destruct || true)
2434 if [ -n "$BUSY" ]; then
2436 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2440 check_mem_leak || exit 204
2442 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2443 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2446 if module_loaded lnet || module_loaded libcfs; then
2447 echo "$TESTSUITE: modules still loaded..." 1>&2
2456 if [[ "$1" == "--verbose" ]]; then
2471 PREV_RESULT=$(do_node $node "$TEST")
2473 RESULT=$(do_node $node "$TEST")
2474 if [[ "$RESULT" == "$FINAL" ]]; then
2475 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2476 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2480 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2481 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2485 [[ $WAIT -ge $MAX ]] && break
2486 [[ $((WAIT % print)) -eq 0 ]] &&
2487 echo "Waiting $((MAX - WAIT)) secs for update"
2488 WAIT=$((WAIT + sleep))
2491 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2495 wait_update_facet() {
2497 [ "$1" = "--verbose" ] && verbose="$1" && shift
2501 wait_update $verbose $(facet_active_host $facet) "$@"
2505 do_nodes $(comma_list $(mdts_nodes)) \
2506 "lctl set_param -n osd*.*MDT*.force_sync=1"
2507 do_nodes $(comma_list $(osts_nodes)) \
2508 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2509 grep -v 'Found no match'
2513 # the occupied disk space will be released
2514 # only after DMUs are committed
2515 if [[ $(facet_fstype $1) == zfs ]]; then
2516 echo "sleep $2 for ZFS OSD"
2521 wait_delete_completed_mds() {
2522 local MAX_WAIT=${1:-20}
2523 # for ZFS, waiting more time for DMUs to be committed
2524 local ZFS_WAIT=${2:-5}
2526 local stime=$(date +%s)
2531 # find MDS with pending deletions
2532 for node in $(mdts_nodes); do
2533 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2534 2>/dev/null | calc_sum)
2535 if [[ $changes -eq 0 ]]; then
2538 mds2sync="$mds2sync $node"
2540 if [ -z "$mds2sync" ]; then
2541 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2544 mds2sync=$(comma_list $mds2sync)
2546 # sync MDS transactions
2547 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2549 # wait till all changes are sent and commmitted by OSTs
2550 # for ldiskfs space is released upon execution, but DMU
2551 # do this upon commit
2554 while [[ $WAIT -ne $MAX_WAIT ]]; do
2555 changes=$(do_nodes $mds2sync \
2556 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2557 #echo "$node: $changes changes on all"
2558 if [[ $changes -eq 0 ]]; then
2559 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2567 echo "Delete is not completed in $((etime - stime)) seconds"
2568 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2574 # we can use "for" here because we are waiting the slowest
2575 for host in ${hostlist//,/ }; do
2576 check_network "$host" 900
2578 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2585 for facet in ${facetlist//,/ }; do
2586 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2588 wait_for_host $hostlist
2591 _wait_recovery_complete () {
2594 # Use default policy if $2 is not passed by caller.
2595 local MAX=${2:-$(max_recovery_time)}
2600 while [ $WAIT -lt $MAX ]; do
2601 STATUS=$(lctl get_param -n $param | grep status)
2603 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2606 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2608 echo "$param recovery not done in $MAX sec. $STATUS"
2612 wait_recovery_complete () {
2615 # with an assumption that at_max is the same on all nodes
2616 local MAX=${2:-$(max_recovery_time)}
2619 if [ "$FAILURE_MODE" = HARD ]; then
2620 facets=$(facets_on_host $(facet_active_host $facet))
2622 echo affected facets: $facets
2624 # we can use "for" here because we are waiting the slowest
2625 for facet in ${facets//,/ }; do
2626 local var_svc=${facet}_svc
2627 local param="*.${!var_svc}.recovery_status"
2629 local host=$(facet_active_host $facet)
2630 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2634 wait_mds_ost_sync () {
2635 # just because recovery is done doesn't mean we've finished
2636 # orphan cleanup. Wait for llogs to get synchronized.
2637 echo "Waiting for orphan cleanup..."
2638 # MAX value includes time needed for MDS-OST reconnection
2639 local MAX=$(( TIMEOUT * 2 ))
2640 local WAIT_TIMEOUT=${1:-$MAX}
2643 local list=$(comma_list $(mdts_nodes))
2644 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2645 if ! do_facet $SINGLEMDS \
2646 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2648 # old way, use mds_sync
2650 list=$(comma_list $(osts_nodes))
2651 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2654 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2655 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2656 local -a sync=($(do_nodes $list "$cmd"))
2659 for ((i=0; i<${#sync[@]}; i++)); do
2661 [ ${sync[$i]} -eq 1 ] && continue
2663 [ ${sync[$i]} -eq 0 ] && continue
2665 # there is a not finished MDS-OST synchronization
2669 sleep 2 # increase waiting time and cover statfs cache
2670 [ ${con} -eq 1 ] && return 0
2671 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2675 # show which nodes are not finished.
2676 do_nodes $list "$cmd"
2677 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2681 # Wait OSTs to be active on both client and MDT side.
2683 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2684 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2685 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2686 error "wait_update OSTs up on client failed"
2688 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
2689 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
2690 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2691 error "wait_update OSTs up on MDT0000 failed"
2694 wait_destroy_complete () {
2695 echo "Waiting for local destroys to complete"
2696 # MAX value shouldn't be big as this mean server responsiveness
2697 # never increase this just to make test pass but investigate
2698 # why it takes so long time
2701 while [ $WAIT -lt $MAX ]; do
2702 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2706 for ((i=0; i<${#RPCs[@]}; i++)); do
2707 [ ${RPCs[$i]} -eq 0 ] && continue
2708 # there are still some destroy RPCs in flight
2713 [ ${con} -eq 1 ] && return 0 # done waiting
2714 echo "Waiting ${WAIT}s for local destroys to complete"
2717 echo "Local destroys weren't done in $MAX sec."
2721 wait_delete_completed() {
2722 wait_delete_completed_mds $1 || return $?
2723 wait_destroy_complete
2732 # conf-sanity 31 takes a long time cleanup
2733 while [ $WAIT -lt 300 ]; do
2734 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2735 [ -z "${running}" ] && return 0
2736 echo "waited $WAIT for${running}"
2737 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2739 WAIT=$((WAIT + INTERVAL))
2741 echo "service didn't stop after $WAIT seconds. Still running:"
2746 wait_remote_prog () {
2752 [ "$PDSH" = "no_dsh" ] && return 0
2754 while [ $WAIT -lt $2 ]; do
2755 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2756 [ -z "${running}" ] && return 0 || true
2757 echo "waited $WAIT for: "
2759 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2761 WAIT=$((WAIT + INTERVAL))
2763 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2764 [ -z "$pids" ] && return 0
2765 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2766 # FIXME: not portable
2767 for pid in $pids; do
2768 cat /proc/${pid}/status || true
2769 cat /proc/${pid}/wchan || true
2771 kill -9 $pid || true
2780 local clients=${1:-$CLIENTS}
2782 if [ -z "$clients" ]; then
2785 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2790 # not every config has many clients
2796 # usually checked on particular client or locally
2805 client_reconnect_try() {
2806 local f=$MOUNT/recon
2809 if [ -z "$CLIENTS" ]; then
2810 $LFS df $MOUNT; uname -n >> $f
2812 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2814 echo "Connected clients: $(cat $f)"
2815 ls -l $f > /dev/null
2819 client_reconnect() {
2820 # one client_reconnect_try call does not always do the job...
2822 client_reconnect_try && break
2827 affected_facets () {
2830 local host=$(facet_active_host $facet)
2831 local affected=$facet
2833 if [ "$FAILURE_MODE" = HARD ]; then
2834 affected=$(facets_up_on_host $host)
2840 local E2FSCK_ON_MDT0=false
2841 if [ "$1" == "--fsck" ]; then
2843 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2855 #Because it will only get up facets, we need get affected
2856 #facets before shutdown
2857 #For HARD Failure mode, it needs make sure facets on the same
2858 #HOST will only be shutdown and reboot once
2859 for facet in ${facets//,/ }; do
2860 local affected_facet
2862 #check whether facet has been included in other affected facets
2863 for ((index=0; index<$total; index++)); do
2864 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2867 if [ $skip -eq 0 ]; then
2868 affecteds[$total]=$(affected_facets $facet)
2873 for ((index=0; index<$total; index++)); do
2874 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2875 local host=$(facet_active_host $facet)
2876 echo "Failing ${affecteds[index]} on $host"
2877 shutdown_facet $facet
2880 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2881 $(mdsdevname 1) "-n" || error "Running e2fsck")
2883 for ((index=0; index<$total; index++)); do
2884 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2885 echo reboot facets: ${affecteds[index]}
2889 change_active ${affecteds[index]}
2891 wait_for_facet ${affecteds[index]}
2892 # start mgs first if it is affected
2893 if ! combined_mgs_mds &&
2894 list_member ${affecteds[index]} mgs; then
2895 mount_facet mgs || error "Restart of mgs failed"
2897 # FIXME; has to be changed to mount all facets concurrently
2898 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2899 echo mount facets: ${affecteds[index]}
2900 mount_facets ${affecteds[index]}
2910 do_facet $facet "sync; sync; sync"
2913 # make sure there will be no seq change
2914 local clients=${CLIENTS:-$HOSTNAME}
2915 local f=fsa-\\\$\(hostname\)
2916 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2917 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2919 local svc=${facet}_svc
2920 do_facet $facet $LCTL --device ${!svc} notransno
2922 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2923 # in-memory state has to be cleared by either rebooting the host or
2924 # exporting and reimporting the pool.
2926 # Although the uberblocks are not updated when a pool is freezed,
2927 # transactions are still written to the disks. Modified blocks may be
2928 # cached in memory when tests try reading them back. The
2929 # export-and-reimport process also evicts any cached pool data from
2930 # memory to provide the correct "data loss" semantics.
2932 # In the test framework, the exporting and importing operations are
2933 # handled by stop() and mount_facet() separately, which are used
2934 # inside fail() and fail_abort().
2936 do_facet $facet $LCTL --device ${!svc} readonly
2937 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2938 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2941 replay_barrier_nodf() {
2942 local facet=$1 echo running=${running}
2943 do_facet $facet "sync; sync; sync"
2944 local svc=${facet}_svc
2945 echo Replay barrier on ${!svc}
2946 do_facet $facet $LCTL --device ${!svc} notransno
2947 do_facet $facet $LCTL --device ${!svc} readonly
2948 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2949 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2952 replay_barrier_nosync() {
2953 local facet=$1 echo running=${running}
2954 local svc=${facet}_svc
2955 echo Replay barrier on ${!svc}
2956 do_facet $facet $LCTL --device ${!svc} notransno
2957 do_facet $facet $LCTL --device ${!svc} readonly
2958 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2959 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2963 # Get Lustre client uuid for a given Lustre mount point.
2966 local mntpnt=${1:-$MOUNT}
2968 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2969 local uuid=$($LCTL get_param -n llite.$name.uuid)
2974 mds_evict_client() {
2975 local mntpnt=${1:-$MOUNT}
2976 local uuid=$(get_client_uuid $mntpnt)
2978 do_facet $SINGLEMDS \
2979 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2982 ost_evict_client() {
2983 local mntpnt=${1:-$MOUNT}
2984 local uuid=$(get_client_uuid $mntpnt)
2987 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2992 local clients=${CLIENTS:-$HOSTNAME}
2994 facet_failover $* || error "failover: $?"
2995 wait_clients_import_state "$clients" "$facets" FULL
2996 clients_up || error "post-failover stat: $?"
3001 facet_failover $facet
3007 change_active $facet
3008 wait_for_facet $facet
3009 mount_facet $facet -o abort_recovery
3010 clients_up || echo "first stat failed: $?"
3011 clients_up || error "post-failover stat: $?"
3014 host_nids_address() {
3018 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
3022 if [ "$1" = "'*'" ]; then echo \'*\'; else
3028 if [[ -n "$NETTYPE" ]]; then
3029 h2name_or_ip "$1" "$NETTYPE"
3031 h2name_or_ip "$1" "$2"
3034 declare -fx h2nettype
3036 # Wrapper function to print the deprecation warning
3038 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3039 if [[ -n "$NETTYPE" ]]; then
3042 h2nettype "$1" "tcp"
3046 # Wrapper function to print the deprecation warning
3048 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3049 if [[ -n "$NETTYPE" ]]; then
3052 h2nettype "$1" "o2ib"
3056 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3057 # expressions format. As a bonus we can then just pass in those variables
3058 # to pdsh. What this function does is take a HOSTLIST type string and
3059 # expand it into a space deliminated list for us.
3067 [ -z "$hostlist" ] && return
3069 # Translate the case of [..],..,[..] to [..] .. [..]
3070 list="${hostlist/],/] }"
3072 [[ "$front" == *,* ]] && {
3075 list=${list/${old}/${new}}
3078 for item in $list; do
3079 # Test if we have any []'s at all
3080 if [ "$item" != "${item/\[/}" ]; then {
3081 # Expand the [*] into list
3085 if [ "$name" != "$item" ]; then
3086 group=${item#$name[*}
3089 for range in ${group//,/ }; do
3095 # Number of leading zeros
3098 end=$(echo $end | sed 's/0*//')
3099 [[ -z "$end" ]] && end=0
3100 [[ $padlen2 -gt $padlen ]] && {
3101 [[ $padlen2 -eq ${#end} ]] && padlen2=0
3104 begin=$(echo $begin | sed 's/0*//')
3105 [ -z $begin ] && begin=0
3107 if [ ! -z "${begin##[!0-9]*}" ]; then
3108 order=$(seq -f "%0${padlen}g" $begin $end)
3110 order=$(eval echo {$begin..$end});
3113 for num in $order; do
3114 value="${name#*,}${num}${back}"
3115 [ "$value" != "${value/\[/}" ] && {
3116 value=$(hostlist_expand "$value")
3118 myList="$myList $value"
3123 myList="$myList $item"
3126 myList=${myList//,/ }
3127 myList=${myList:1} # Remove first character which is a space
3129 # Filter any duplicates without sorting
3131 myList="${list%% *}"
3133 while [[ "$list" != ${myList##* } ]]; do
3134 local tlist=" $list"
3135 list=${tlist// ${list%% *} / }
3137 myList="$myList ${list%% *}"
3139 myList="${myList%* }";
3141 # We can select an object at an offset in the list
3144 for item in $myList; do
3146 [ $cnt -eq $offset ] && {
3150 [ $(get_node_count $myList) -ne 1 ] && myList=""
3159 [ "$facet" == client ] && echo -n $HOSTNAME && return
3160 varname=${facet}_HOST
3161 if [ -z "${!varname}" ]; then
3162 if [ "${facet:0:3}" == "ost" ]; then
3163 local fh=${facet%failover}_HOST
3164 eval export ${facet}_HOST=${!fh}
3165 if [ -z "${!varname}" ]; then
3166 eval export ${facet}_HOST=${ost_HOST}
3168 elif [ "${facet:0:3}" == "mdt" -o \
3169 "${facet:0:3}" == "mds" -o \
3170 "${facet:0:3}" == "mgs" ]; then
3171 eval export ${facet}_HOST=${mds_HOST}
3177 facet_failover_host() {
3181 var=${facet}failover_HOST
3182 if [ -n "${!var}" ]; then
3187 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
3188 "${facet:0:3}" == "mgs" ]; then
3190 eval export ${facet}failover_host=${mds_HOST}
3195 if [[ $facet == ost* ]]; then
3196 eval export ${facet}failover_host=${ost_HOST}
3204 local activevar=${facet}active
3206 if [ -f $TMP/${facet}active ] ; then
3207 source $TMP/${facet}active
3210 active=${!activevar}
3211 if [ -z "$active" ] ; then
3218 facet_active_host() {
3219 facet_host $(facet_active $1)
3222 # Get the passive failover partner host of facet.
3223 facet_passive_host() {
3225 [[ $facet = client ]] && return
3227 local host=${facet}_HOST
3228 local failover_host=${facet}failover_HOST
3229 local active_host=$(facet_active_host $facet)
3231 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
3233 if [[ $active_host = ${!host} ]]; then
3234 echo -n ${!failover_host}
3244 facetlist=$(exclude_items_from_list $facetlist mgs)
3246 for facet in ${facetlist//,/ }; do
3247 local failover=${facet}failover
3248 local host=`facet_host $failover`
3249 [ -z "$host" ] && return
3251 local curactive=`facet_active $facet`
3252 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3253 eval export ${facet}active=$facet
3255 eval export ${facet}active=$failover
3257 # save the active host for this facet
3258 local activevar=${facet}active
3259 echo "$activevar=${!activevar}" > $TMP/$activevar
3260 [[ $facet = mds1 ]] && combined_mgs_mds && \
3261 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3262 local TO=`facet_active_host $facet`
3263 echo "Failover $facet to $TO"
3269 # do not stripe off hostname if verbose, bug 19215
3270 if [ x$1 = x--verbose ]; then
3278 if [ "$HOST" = "$HOSTNAME" ]; then
3280 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3281 echo "cannot run remote command on $HOST with $myPDSH"
3285 echo "CMD: $HOST $@" >&2
3286 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3289 if [ "$myPDSH" = "rsh" ]; then
3290 # we need this because rsh does not return exit code of an executed command
3291 local command_status="$TMP/cs"
3292 rsh $HOST ":> $command_status"
3293 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3294 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3295 echo command failed >$command_status"
3296 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3301 # print HOSTNAME for myPDSH="no_dsh"
3302 if [[ $myPDSH = no_dsh ]]; then
3303 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3305 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3308 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3310 return ${PIPESTATUS[0]}
3314 do_node --verbose "$@"
3317 single_local_node () {
3318 [ "$1" = "$HOSTNAME" ]
3321 # Outputs environment variable assignments that should be passed to remote nodes
3325 local facets=$(get_facets)
3328 for var in ${!MODOPTS_*}; do
3329 value=${!var//\"/\\\"}
3330 echo -n " ${var}=\"$value\""
3333 for facet in ${facets//,/ }; do
3335 if [ -n "${!var}" ]; then
3336 echo -n " $var=${!var}"
3340 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3341 if [ -n "${!var}" ]; then
3342 echo -n " $var=${!var}"
3346 for var in VERBOSE; do
3347 if [ -n "${!var}" ]; then
3348 echo -n " $var=${!var}"
3352 if [ -n "$FSTYPE" ]; then
3353 echo -n " FSTYPE=$FSTYPE"
3356 for var in LNETLND NETTYPE; do
3357 if [ -n "${!var}" ]; then
3358 echo -n " $var=${!var}"
3365 # do not stripe off hostname if verbose, bug 19215
3366 if [ x$1 = x--verbose ]; then
3374 if single_local_node $rnodes; then
3376 do_nodev $rnodes "$@"
3378 do_node $rnodes "$@"
3383 # This is part from do_node
3386 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3387 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3389 export FANOUT=$(get_node_count "${rnodes//,/ }")
3391 echo "CMD: $rnodes $@" >&2
3392 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3395 # do not replace anything from pdsh output if -N is used
3396 # -N Disable hostname: prefix on lines of output.
3397 if $verbose || [[ $myPDSH = *-N* ]]; then
3398 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3400 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3402 return ${PIPESTATUS[0]}
3406 # Execute commands on a single service's host
3408 # The \a facet (service) may be on a local or remote node, which is
3409 # determined at the time the command is run.
3411 # usage: do_facet $facet command [arg ...]
3415 local HOST=$(facet_active_host $facet)
3416 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3420 # Function: do_facet_random_file $FACET $FILE $SIZE
3421 # Creates FILE with random content on the given FACET of given SIZE
3423 do_facet_random_file() {
3427 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3428 do_facet $facet "$cmd 2>/dev/null"
3431 do_facet_create_file() {
3435 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3436 do_facet $facet "$cmd 2>/dev/null"
3440 do_nodes --verbose "$@"
3446 # make sure its not already running
3448 rm -f $TMP/${facet}active
3449 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3450 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3452 if [[ $(facet_fstype $facet) == zfs ]]; then
3454 # After formatting a ZFS target, "cachefile=none" property will
3455 # be set on the ZFS storage pool so that the pool is not
3456 # automatically imported on system startup. And then the pool
3457 # will be exported so as to leave the importing and exporting
3458 # operations handled by mount_facet() and stop() separately.
3460 refresh_partition_table $facet $(facet_vdevice $facet)
3461 disable_zpool_cache $facet
3466 # Device formatted as ost
3469 local DEVNAME=OSTDEV$num
3471 local fstype=$(facet_fstype ost$num)
3475 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3476 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3478 #try $OSTZFSDEVn - independent of vdev
3479 DEVNAME=OSTZFSDEV$num
3480 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3482 error "unknown fstype!";;
3488 # Physical device location of data
3494 local fstype=$(facet_fstype ost$num)
3498 # vdevs are not supported by ldiskfs
3501 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3502 # Device formatted by zfs
3504 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3506 error "unknown fstype!";;
3512 # Logical device formatted for lustre
3515 local DEVNAME=MDSDEV$num
3517 local fstype=$(facet_fstype mds$num)
3521 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3522 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3524 # try $MDSZFSDEVn - independent of vdev
3525 DEVNAME=MDSZFSDEV$num
3526 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3528 error "unknown fstype!";;
3534 # Physical location of data
3538 local fstype=$(facet_fstype mds$num)
3542 # vdevs are not supported by ldiskfs
3545 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3546 # Device formatted by ZFS
3547 local DEVNAME=MDSDEV$num
3548 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3550 error "unknown fstype!";;
3558 local fstype=$(facet_fstype mgs)
3562 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3563 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3564 DEVPTR=$(mdsdevname 1)
3569 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3570 ( [ -z "$MGSZFSDEV" ] &&
3571 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3572 DEVPTR=$(mdsdevname 1)
3574 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3577 error "unknown fstype!";;
3586 local fstype=$(facet_fstype mgs)
3590 # vdevs are not supported by ldiskfs
3593 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3594 ( [ -z "$MGSDEV" ] &&
3595 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3596 VDEVPTR=$(mdsvdevname 1)
3597 elif [ -n "$MGSDEV" ]; then
3601 error "unknown fstype!";;
3609 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3611 local var=${facet}_MOUNT
3612 eval mntpt=${!var:-${MOUNT}-$facet}
3619 local dev=$(facet_device $facet)
3620 local mnt=${2:-$(facet_mntpt $facet)}
3623 if ! do_facet $facet test -b $dev; then
3626 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3631 local dev=$(facet_device $facet)
3632 local mnt=${2:-$(facet_mntpt $facet)}
3634 do_facet $facet $UMOUNT $mnt
3638 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3643 local ds=$(facet_device $facet)
3644 local mnt=${2:-$(facet_mntpt $facet)}
3649 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3650 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3651 do_facet $facet $ZFS set canmount=noauto $ds
3653 # The "legacy" mount method is used here because "zfs unmount $mnt"
3654 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3655 # targets are not available at the time, the stat(2) on $MOUNT will
3658 do_facet $facet $ZFS set mountpoint=legacy $ds
3659 do_facet $facet mount -t zfs $ds $mnt
3660 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3661 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3666 local ds=$(facet_device $facet)
3667 local mnt=${2:-$(facet_mntpt $facet)}
3668 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3669 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3670 local mntpt=${!var_mntpt}
3671 local canmnt=${!var_canmnt}
3675 do_facet $facet umount $mnt
3676 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3677 do_facet $facet $ZFS set canmount=$canmnt $ds
3684 local fstype=$(facet_fstype $facet)
3686 mount_$fstype $facet $mnt
3692 local fstype=$(facet_fstype $facet)
3694 unmount_$fstype $facet $mnt
3701 # make sure we are using the primary server, so test-framework will
3702 # be able to clean up properly.
3703 activemds=`facet_active mds1`
3704 if [ $activemds != "mds1" ]; then
3708 local clients=$CLIENTS
3709 [ -z $clients ] && clients=$(hostname)
3711 zconf_umount_clients $clients $MOUNT "$*" || true
3712 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3714 [ -n "$CLIENTONLY" ] && return
3716 # The add fn does rm ${facet}active file, this would be enough
3717 # if we use do_facet <facet> only after the facet added, but
3718 # currently we use do_facet mds in local.sh
3719 for num in `seq $MDSCOUNT`; do
3721 rm -f ${TMP}/mds${num}active
3723 combined_mgs_mds && rm -f $TMP/mgsactive
3725 for num in `seq $OSTCOUNT`; do
3727 rm -f $TMP/ost${num}active
3730 if ! combined_mgs_mds ; then
3737 cleanup_echo_devs () {
3740 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3742 for dev in $devs; do
3743 $LCTL --device $dev cleanup
3744 $LCTL --device $dev detach
3749 nfs_client_mode && return
3750 cifs_client_mode && return
3760 combined_mgs_mds () {
3761 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3762 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3766 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3770 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3776 local fsname=${3:-"$FSNAME"}
3777 local type=$(facet_type $facet)
3778 local index=$(facet_index $facet)
3779 local fstype=$(facet_fstype $facet)
3780 local host=$(facet_host $facet)
3785 if [ $type == MGS ] || ( [ $type == MDS ] &&
3786 [ "$dev" == $(mgsdevname) ] &&
3787 [ "$host" == "$(facet_host mgs)" ] ); then
3790 opts="--mgsnode=$MGSNID"
3793 if [ $type != MGS ]; then
3794 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3798 var=${facet}failover_HOST
3799 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3800 opts+=" --failnode=$(h2nettype ${!var})"
3803 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3804 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3806 if [ $type == MDS ]; then
3807 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3808 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3809 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3810 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3812 if [ $fstype == ldiskfs ]; then
3813 # Check for wide striping
3814 if [ $OSTCOUNT -gt 160 ]; then
3815 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3816 fs_mkfs_opts+="-O large_xattr"
3820 if [ -n "${!var}" ]; then
3821 fs_mkfs_opts+=" -J device=${!var}"
3823 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3825 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3829 if [ $type == OST ]; then
3830 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3832 if [ $fstype == ldiskfs ]; then
3834 if [ -n "${!var}" ]; then
3835 fs_mkfs_opts+=" -J device=${!var}"
3837 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3842 opts+=" --backfstype=$fstype"
3845 if [ -n "${!var}" ]; then
3846 opts+=" --device-size=${!var}"
3849 var=$(upper $fstype)_MKFS_OPTS
3850 fs_mkfs_opts+=${!var:+" ${!var}"}
3852 var=${type}_FS_MKFS_OPTS
3853 fs_mkfs_opts+=${!var:+" ${!var}"}
3855 if [ -n "${fs_mkfs_opts## }" ]; then
3856 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3860 opts+=${!var:+" ${!var}"}
3867 local type=$(facet_type $facet)
3868 local var=${type}_MOUNT_FS_OPTS
3870 if [ -n "${!var}" ]; then
3871 opts+=" --mountfsoptions=${!var}"
3876 check_ost_indices() {
3877 local index_count=${#OST_INDICES[@]}
3878 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3880 # OST count is greater than the index count in $OST_INDEX_LIST.
3881 # We need check whether there are duplicate indices.
3885 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3886 index=$(facet_index ost$i)
3887 for j in $(seq 0 $((index_count - 1))); do
3888 [[ $index -ne ${OST_INDICES[j]} ]] ||
3889 error "ost$i has the same index $index as ost$((j+1))"
3896 local facet_type=$1 # mgs || mds || ost
3898 local facet=${1}${2}
3901 case "$(facet_fstype $facet)" in
3903 device=$(${facet_type}devname $facet_num)
3906 device=$(${facet_type}vdevname $facet_num)
3909 error "Unhandled filesystem type"
3913 do_facet $facet "[ -e \"$device\" ]" && return
3915 # Note: the following check only works with absolute paths
3916 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
3917 error "$facet: device '$device' does not exist"
3919 do_facet $facet "touch \"${device}\""
3928 echo "Format mgs: $(mgsdevname)"
3929 reformat_external_journal mgs
3931 # touch "device" in case it is a loopback file for testing and needs to
3932 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
3933 # to non-existent files in /dev if the admin made a typo during setup
3936 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
3937 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3947 echo "Format mds$num: $(mdsdevname $num)"
3948 reformat_external_journal mds$num
3950 __touch_device mds $num
3952 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3953 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
3954 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
3963 echo "Format ost$num: $(ostdevname $num)"
3964 reformat_external_journal ost$num
3966 __touch_device ost $num
3968 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3969 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
3970 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
3975 # Set hostid for ZFS/SPL zpool import protection
3976 # (Assumes MDS version is also OSS version)
3977 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3979 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3982 # We need ldiskfs here, may as well load them all
3984 [ -n "$CLIENTONLY" ] && return
3985 echo Formatting mgs, mds, osts
3986 if ! combined_mgs_mds ; then
3990 for num in $(seq $MDSCOUNT); do
3994 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3996 for num in $(seq $OSTCOUNT); do
4002 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
4006 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
4010 # 0: success, the old identity set already.
4011 # 1: success, the old identity does not set.
4016 local j=`expr $num - 1`
4017 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
4019 if [ -z "$MDT" ]; then
4023 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
4026 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
4028 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
4031 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
4033 if [ $old = "NONE" ]; then
4042 zconf_umount $HOSTNAME $1 || error "umount failed"
4043 zconf_mount $HOSTNAME $1 || error "mount failed"
4051 rm -f $TMP/${facet}active
4052 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
4057 local mdt_count=${1:-$MDSCOUNT}
4058 local ost_count=${2:-$OSTCOUNT}
4061 for num in $(seq $mdt_count); do
4062 DEVNAME=$(mdsdevname $num)
4063 writeconf_facet mds$num $DEVNAME || rc=$?
4066 for num in $(seq $ost_count); do
4067 DEVNAME=$(ostdevname $num)
4068 writeconf_facet ost$num $DEVNAME || rc=$?
4074 if ! combined_mgs_mds ; then
4075 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
4080 for num in $(seq $MDSCOUNT); do
4081 DEVNAME=$(mdsdevname $num)
4082 start mds$num $DEVNAME $MDS_MOUNT_OPTS
4084 # We started mds, now we should set failover variables properly.
4085 # Set mds${num}failover_HOST if unset (the default
4087 local varname=mds${num}failover_HOST
4088 if [ -z "${!varname}" ]; then
4089 eval mds${num}failover_HOST=$(facet_host mds$num)
4092 if [ $IDENTITY_UPCALL != "default" ]; then
4093 switch_identity $num $IDENTITY_UPCALL
4099 for num in $(seq $OSTCOUNT); do
4100 DEVNAME=$(ostdevname $num)
4101 start ost$num $DEVNAME $OST_MOUNT_OPTS
4103 # We started ost$num, now we should set ost${num}failover
4104 # variable properly. Set ost${num}failover_HOST if it is not
4105 # set (the default failnode).
4106 varname=ost${num}failover_HOST
4107 if [ -z "${!varname}" ]; then
4108 eval ost${num}failover_HOST=$(facet_host ost${num})
4115 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
4116 if [ ! -z $arg1 ]; then
4117 [ "$arg1" = "server_only" ] && return
4120 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
4123 if [ "$MOUNT_2" ]; then
4124 mount_client $MOUNT2
4125 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
4129 sk_nodemap_setup() {
4130 local sk_map_name=${1:-$SK_S2SNM}
4131 local sk_map_nodes=${2:-$HOSTNAME}
4132 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
4133 for servernode in $sk_map_nodes; do
4134 local nids=$(do_nodes $servernode "$LCTL list_nids")
4135 for nid in $nids; do
4136 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
4137 $sk_map_name --range $nid"
4145 nfs_client_mode && return
4146 cifs_client_mode && return
4148 sanity_mount_check || error "environments are insane!"
4154 if [ -z "$CLIENTONLY" ]; then
4155 echo Setup mgs, mdt, osts
4156 echo $WRITECONF | grep -q "writeconf" && writeconf_all
4158 if $SK_MOUNTED; then
4159 echo "Shared Key file system already mounted"
4164 if $SHARED_KEY; then
4165 export SK_MOUNTED=true
4169 echo "GSS_SK: setting kernel keyring perms"
4170 do_nodes $(comma_list $(all_nodes)) \
4171 "keyctl show | grep lustre | cut -c1-11 |
4173 xargs -IX keyctl setperm X 0x3f3f3f3f"
4176 # Need to start one nodemap for servers,
4177 # and one for clients.
4178 sk_nodemap_setup $SK_S2SNM \
4179 $(comma_list $(all_server_nodes))
4181 sk_nodemap_setup $SK_S2SNMCLI \
4182 ${CLIENTS:-$HOSTNAME}
4183 echo "Nodemap set up for SK S2S, remounting."
4192 # wait a while to allow sptlrpc configuration be propogated to targets,
4193 # only needed when mounting new target devices.
4201 # by remounting mdt before ost, initial connect from mdt to ost might
4202 # timeout because ost is not ready yet. wait some time to its fully
4203 # recovery. initial obd_connect timeout is 5s; in GSS case it's
4204 # preceeded by a context negotiation rpc with $TIMEOUT.
4205 # FIXME better by monitoring import status.
4208 set_rule $FSNAME any cli2mdt $SK_FLAVOR
4209 set_rule $FSNAME any cli2ost $SK_FLAVOR
4210 wait_flavor cli2mdt $SK_FLAVOR
4211 wait_flavor cli2ost $SK_FLAVOR
4215 sleep $((TIMEOUT + 5))
4221 mounted_lustre_filesystems() {
4222 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
4225 init_facet_vars () {
4226 [ -n "$CLIENTONLY" ] && return 0
4233 eval export ${facet}_dev=${device}
4234 eval export ${facet}_opt=\"$@\"
4236 local dev=${facet}_dev
4238 # We need to loop for the label
4239 # in case its not initialized yet.
4240 for wait_time in {0,1,3,5,10}; do
4242 if [ $wait_time -gt 0 ]; then
4243 echo "${!dev} not yet initialized,"\
4244 "waiting ${wait_time} seconds."
4248 local label=$(devicelabel ${facet} ${!dev})
4250 # Check to make sure the label does
4251 # not include ffff at the end of the label.
4252 # This indicates it has not been initialized yet.
4254 if [[ $label =~ [f|F]{4}$ ]]; then
4255 # label is not initialized, unset the result
4256 # and either try again or fail
4263 [ -z "$label" ] && echo no label for ${!dev} && exit 1
4265 eval export ${facet}_svc=${label}
4267 local varname=${facet}failover_HOST
4268 if [ -z "${!varname}" ]; then
4269 eval export $varname=$(facet_host $facet)
4272 varname=${facet}_HOST
4273 if [ -z "${!varname}" ]; then
4274 eval export $varname=$(facet_host $facet)
4277 # ${facet}failover_dev is set in cfg file
4278 varname=${facet}failover_dev
4279 if [ -n "${!varname}" ] ; then
4280 eval export ${facet}failover_dev=${!varname}
4282 eval export ${facet}failover_dev=$device
4285 # get mount point of already mounted device
4286 # is facet_dev is already mounted then use the real
4287 # mount point of this facet; otherwise use $(facet_mntpt $facet)
4288 # i.e. ${facet}_MOUNT if specified by user or default
4289 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
4290 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
4291 if [ -z $mntpt ]; then
4292 mntpt=$(facet_mntpt $facet)
4294 eval export ${facet}_MOUNT=$mntpt
4297 init_facets_vars () {
4300 if ! remote_mds_nodsh; then
4301 for num in $(seq $MDSCOUNT); do
4302 DEVNAME=`mdsdevname $num`
4303 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
4307 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
4309 if ! remote_ost_nodsh; then
4310 for num in $(seq $OSTCOUNT); do
4311 DEVNAME=$(ostdevname $num)
4312 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
4317 osc_ensure_active () {
4322 while [ $period -lt $timeout ]; do
4323 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
4324 if [ $count -eq 0 ]; then
4328 echo "There are $count OST are inactive, wait $period seconds, and try again"
4330 period=$((period+3))
4333 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
4336 set_conf_param_and_check() {
4340 local ORIG=$(do_facet $myfacet "$TEST")
4341 if [ $# -gt 3 ]; then
4347 echo "Setting $PARAM from $ORIG to $FINAL"
4348 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
4349 error "conf_param $PARAM failed"
4351 wait_update_facet $myfacet "$TEST" "$FINAL" ||
4352 error "check $PARAM failed!"
4355 init_param_vars () {
4356 TIMEOUT=$(lctl get_param -n timeout)
4357 TIMEOUT=${TIMEOUT:-20}
4359 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
4361 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4362 log "Using TIMEOUT=$TIMEOUT"
4364 osc_ensure_active $SINGLEMDS $TIMEOUT
4365 osc_ensure_active client $TIMEOUT
4367 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
4368 local current_jobid_var=$($LCTL get_param -n jobid_var)
4370 if [ $JOBID_VAR = "existing" ]; then
4371 echo "keeping jobstats as $current_jobid_var"
4372 elif [ $current_jobid_var != $JOBID_VAR ]; then
4373 echo "seting jobstats to $JOBID_VAR"
4375 set_conf_param_and_check client \
4376 "$LCTL get_param -n jobid_var" \
4377 "$FSNAME.sys.jobid_var" $JOBID_VAR
4380 echo "jobstats not supported by server"
4383 if [ $QUOTA_AUTO -ne 0 ]; then
4384 if [ "$ENABLE_QUOTA" ]; then
4385 echo "enable quota as required"
4386 setup_quota $MOUNT || return 2
4388 echo "disable quota as required"
4389 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4395 nfs_client_mode () {
4396 if [ "$NFSCLIENT" ]; then
4397 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4398 local clients=$CLIENTS
4399 [ -z $clients ] && clients=$(hostname)
4401 # FIXME: remove hostname when 19215 fixed
4402 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4403 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4404 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4405 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4407 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4413 cifs_client_mode () {
4414 [ x$CIFSCLIENT = xyes ] &&
4415 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4418 check_config_client () {
4421 local mounted=$(mount | grep " $mntpt ")
4422 if [ -n "$CLIENTONLY" ]; then
4424 # CLIENTONLY should not depend on *_HOST settings
4425 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4426 # in theory someone could create a new,
4427 # client-only config file that assumed lustre was already
4428 # configured and didn't set the MGSNID. If MGSNID is not set,
4429 # then we should use the mgs nid currently being used
4430 # as the default value. bug 18021
4431 [[ x$MGSNID = x ]] &&
4434 if [[ x$mgc != xMGC$MGSNID ]]; then
4435 if [ "$mgs_HOST" ]; then
4436 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4437 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4438 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4444 echo Checking config lustre mounted on $mntpt
4445 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4446 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4450 check_config_clients () {
4451 local clients=${CLIENTS:-$HOSTNAME}
4454 nfs_client_mode && return
4455 cifs_client_mode && return
4457 do_rpc_nodes "$clients" check_config_client $mntpt
4459 sanity_mount_check || error "environments are insane!"
4463 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4464 local cltimeout=$(lctl get_param -n timeout)
4465 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4466 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4473 [ -z $mntpt ] && return 1
4474 local mounted=$(mounted_lustre_filesystems)
4476 echo $mounted' ' | grep -w -q $mntpt' '
4480 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4484 # empty lustre filesystem may have empty directories lost+found and .lustre
4486 # exclude .lustre & lost+found
4487 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4488 -print | wc -l) = 1 ] || return 1
4489 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4490 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4491 # exclude .lustre/fid (LU-2780)
4492 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4493 -print | wc -l) = 1 ] || return 1
4495 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4500 check_and_setup_lustre() {
4502 nfs_client_mode && return
4503 cifs_client_mode && return
4505 local MOUNTED=$(mounted_lustre_filesystems)
4509 # both MOUNT and MOUNT2 are not mounted
4510 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4511 [ "$REFORMAT" = "yes" ] && formatall
4512 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4514 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4515 export I_MOUNTED=yes
4519 elif is_mounted $MOUNT2; then
4521 # MOUNT2 is mounted, while MOUNT_2 is not set
4522 if ! [ "$MOUNT_2" ]; then
4523 cleanup_mount $MOUNT2
4524 export I_UMOUNTED2=yes
4527 # MOUNT2 is mounted, MOUNT_2 is set
4529 # FIXME: what to do if check_config failed?
4531 # 1) remote client has mounted other Lustre fs ?
4532 # 2) it has insane env ?
4533 # let's try umount MOUNT2 on all clients and mount it again:
4534 if ! check_config_clients $MOUNT2; then
4535 cleanup_mount $MOUNT2
4536 restore_mount $MOUNT2
4537 export I_MOUNTED2=yes
4542 # MOUNT is mounted MOUNT2 is not mounted
4543 elif [ "$MOUNT_2" ]; then
4544 restore_mount $MOUNT2
4545 export I_MOUNTED2=yes
4549 # FIXME: what to do if check_config failed?
4551 # 1) remote client has mounted other Lustre fs?
4552 # 2) lustre is mounted on remote_clients atall ?
4553 check_config_clients $MOUNT
4557 set_default_debug_nodes $(comma_list $(nodes_list))
4560 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4562 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4563 facets="$(get_facets OST)"
4564 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4565 facets="$facets,$(get_facets MDS)"
4566 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4567 facets="$facets,mgs"
4568 local nodes="$(facets_hosts ${facets})"
4569 if [ -n "$nodes" ] ; then
4570 do_nodes $nodes "$LCTL set_param \
4571 osd-ldiskfs.track_declares_assert=1 || true"
4582 if [ -z "$CLIENTONLY" ]; then
4583 # Enable remote MDT create for testing
4584 for num in $(seq $MDSCOUNT); do
4586 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4591 if [ "$ONLY" == "setup" ]; then
4597 local clients=${CLIENTS:-$HOSTNAME}
4600 zconf_mount_clients $clients $mntpt
4604 local clients=${CLIENTS:-$HOSTNAME}
4607 zconf_umount_clients $clients $mntpt
4610 cleanup_and_setup_lustre() {
4611 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4612 lctl set_param debug=0 || true
4614 if [ "$ONLY" == "cleanup" ]; then
4618 check_and_setup_lustre
4621 # Get all of the server target devices from a given server node and type.
4628 if [ "$type" == ost ]; then
4629 devs=$(get_osd_param $node "" mntdev)
4631 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4633 for dev in $devs; do
4635 *loop*) do_node $node "losetup $dev" | \
4636 sed -e "s/.*(//" -e "s/).*//" ;;
4642 # Get all of the server target devices.
4647 # Master MDS parameters used by lfsck
4648 MDTNODE=$(facet_active_host $SINGLEMDS)
4649 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4653 for node in $(mdts_nodes); do
4654 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4660 for node in $(osts_nodes); do
4661 OSTDEVS[i]=$(get_mnt_devs $node ost)
4666 # Run e2fsck on MDT or OST device.
4671 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4672 local log=$TMP/e2fsck.log
4676 do_node $node $cmd 2>&1 | tee $log
4678 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4680 if [ $MDSCOUNT -gt 1 ]; then
4681 skip "DNE mode isn't supported!"
4685 error "It's not DNE mode."
4690 [ $rc -le $FSCK_MAX_ERR ] ||
4691 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4697 # Run resize2fs on MDT or OST device.
4706 do_facet $facet "$RESIZE2FS $opts $device $size"
4709 # verify a directory is shared among nodes.
4710 check_shared_dir() {
4712 local list=${2:-$(comma_list $(nodes_list))}
4714 [ -z "$dir" ] && return 1
4715 do_rpc_nodes "$list" check_logdir $dir
4716 check_write_access $dir "$list" || return 1
4721 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4722 $LCTL set_param printk=+lfsck
4723 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4725 for k in $(seq $MDSCOUNT); do
4726 # wait up to 10+1 minutes for LFSCK to complete
4727 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4728 mdd.$(facet_svc mds${k}).lfsck_layout |
4729 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4730 error "MDS${k} layout isn't the expected 'completed'"
4731 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4732 mdd.$(facet_svc mds${k}).lfsck_namespace |
4733 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4734 error "MDS${k} namespace isn't the expected 'completed'"
4736 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4737 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4738 awk '/repaired/ { print $2 }' | calc_sum)
4739 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4740 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4741 awk '/repaired/ { print $2 }' | calc_sum)
4742 local repaired=$((rep_mdt + rep_ost))
4743 [ $repaired -eq 0 ] ||
4744 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4747 dump_file_contents() {
4753 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4754 error_noexit false \
4755 "Invalid parameters for dump_file_contents()"
4758 for node in ${nodes}; do
4759 do_node $node "for i in \\\$(find $dir -type f); do
4760 echo ====\\\${i}=======================;
4762 done" >> ${logname}.${node}.log
4766 dump_command_output() {
4772 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4773 error_noexit false \
4774 "Invalid parameters for dump_command_output()"
4778 for node in ${nodes}; do
4779 do_node $node "echo ====${cmd}=======================;
4780 $cmd" >> ${logname}.${node}.log
4787 # dump file contents from /proc/spl in case of zfs test
4788 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4789 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4790 dump_command_output \
4791 "$(osts_nodes)" "zpool events -v" "${logname}"
4794 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4795 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4796 dump_command_output \
4797 "$(mdts_nodes)" "zpool events -v" "${logname}"
4801 check_and_cleanup_lustre() {
4802 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4803 "$TESTSUITE" != "sanity-scrub" ]; then
4807 if is_mounted $MOUNT; then
4808 if $DO_CLEANUP; then
4809 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4810 error "remove sub-test dirs failed"
4814 [ "$ENABLE_QUOTA" ] && restore_quota || true
4817 if [ "$I_UMOUNTED2" = "yes" ]; then
4818 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4821 if [ "$I_MOUNTED2" = "yes" ]; then
4822 cleanup_mount $MOUNT2
4825 if [ "$I_MOUNTED" = "yes" ]; then
4826 cleanupall -f || error "cleanup failed"
4834 wait_for_function () {
4837 # suppress fn both stderr and stdout
4838 if [ "$1" = "--quiet" ]; then
4840 quiet=" > /dev/null 2>&1"
4852 eval $fn $quiet && return 0
4854 wait=$((wait + sleep))
4855 [ $wait -lt $max ] || return 1
4856 echo waiting $fn, $((max - wait)) secs left ...
4866 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4867 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4868 echo "Network not available!"
4872 echo `date +"%H:%M:%S (%s)"` network interface is UP
4880 # Convert a space-delimited list to a comma-delimited list. If the input is
4881 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4883 # echo is used to convert newlines to spaces, since it doesn't
4884 # introduce a trailing space as using "tr '\n' ' '" does
4885 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4891 echo $list | grep -qw $item
4894 # list, excluded are the comma separated lists
4895 exclude_items_from_list () {
4901 for item in ${excluded//,/ }; do
4902 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4904 echo $(comma_list $list)
4907 # list, expand are the comma separated lists
4909 local list=${1//,/ }
4910 local expand=${2//,/ }
4913 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4914 echo $(comma_list $expanded)
4917 testslist_filter () {
4918 local script=$LUSTRE/tests/${TESTSUITE}.sh
4920 [ -f $script ] || return 0
4922 local start_at=$START_AT
4923 local stop_at=$STOP_AT
4925 local var=${TESTSUITE//-/_}_START_AT
4926 [ x"${!var}" != x ] && start_at=${!var}
4927 var=${TESTSUITE//-/_}_STOP_AT
4928 [ x"${!var}" != x ] && stop_at=${!var}
4930 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4931 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4932 /^'${start_at}'$/ {flag = 0}
4933 {if (flag == 1) print $0}
4934 /^'${stop_at}'$/ { flag = 1 }'
4938 (cd `dirname $1`; echo $PWD/`basename $1`)
4942 local types=${1:-"OST MDS MGS"}
4946 for entry in $types; do
4947 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4948 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4951 MGS ) list="$list $name";;
4952 MDS|OST|AGT ) local count=${type}COUNT
4953 for ((i=1; i<=${!count}; i++)) do
4954 list="$list ${name}$i"
4956 * ) error "Invalid facet type"
4960 echo $(comma_list $list)
4963 ##################################
4964 # Adaptive Timeouts funcs
4967 # only check mds, we assume at_max is the same on all nodes
4968 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4969 if [ $at_max -eq 0 ]; then
4980 # suppose that all ost-s have the same $at value set
4981 [ $facet != "ost" ] || facet=ost1
4983 do_facet $facet "lctl get_param -n $at"
5001 if [ $facet == "ost" ]; then
5002 facet=$(get_facets OST)
5003 elif [ $facet == "mds" ]; then
5004 facet=$(get_facets MDS)
5006 hosts=$(expand_list $hosts $(facets_hosts $facet))
5009 do_nodes $hosts lctl set_param at_max=$at_max
5012 ##################################
5016 # OBD_FAIL_MDS_ALL_REQUEST_NET
5018 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
5019 do_facet client "$1" || RC=$?
5020 do_facet $SINGLEMDS lctl set_param fail_loc=0
5025 # OBD_FAIL_MDS_ALL_REPLY_NET
5027 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
5029 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5033 drop_reint_reply() {
5034 # OBD_FAIL_MDS_REINT_NET_REP
5036 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
5038 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5042 drop_update_reply() {
5043 # OBD_FAIL_OUT_UPDATE_NET_REP
5047 do_facet mds${index} lctl set_param fail_loc=0x1701
5048 do_facet client "$@" || RC=$?
5049 do_facet mds${index} lctl set_param fail_loc=0
5054 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
5057 local timeout=${2:-0}
5058 # default is (obd_timeout / 4) if unspecified
5059 echo "timeout is $timeout/$2"
5060 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
5061 do_facet client "$1" || RC=$?
5062 do_facet client "sync"
5063 do_facet ost1 lctl set_param fail_loc=0
5067 drop_ldlm_cancel() {
5068 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
5070 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5071 do_nodes $list lctl set_param fail_loc=0x304
5073 do_facet client "$@" || RC=$?
5075 do_nodes $list lctl set_param fail_loc=0
5079 drop_bl_callback_once() {
5081 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5082 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5083 do_facet client lctl set_param fail_loc=0x80000305
5084 do_facet client "$@" || rc=$?
5085 do_facet client lctl set_param fail_loc=0
5086 do_facet client lctl set_param fail_val=0
5087 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5091 drop_bl_callback() {
5093 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5094 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5095 do_facet client lctl set_param fail_loc=0x305
5096 do_facet client "$@" || rc=$?
5097 do_facet client lctl set_param fail_loc=0
5098 do_facet client lctl set_param fail_val=0
5099 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5104 #define OBD_FAIL_LDLM_REPLY 0x30c
5106 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5107 do_nodes $list lctl set_param fail_loc=0x30c
5109 do_facet client "$@" || RC=$?
5111 do_nodes $list lctl set_param fail_loc=0
5115 drop_ldlm_reply_once() {
5116 #define OBD_FAIL_LDLM_REPLY 0x30c
5118 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5119 do_nodes $list lctl set_param fail_loc=0x8000030c
5121 do_facet client "$@" || RC=$?
5123 do_nodes $list lctl set_param fail_loc=0
5131 echo "clearing fail_loc on $facet"
5132 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
5135 set_nodes_failloc () {
5137 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
5140 cancel_lru_locks() {
5141 #$LCTL mark "cancel_lru_locks $1 start"
5142 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
5143 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
5144 #$LCTL mark "cancel_lru_locks $1 stop"
5149 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
5150 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
5151 echo "$DEFAULT_LRU_SIZE"
5156 lctl set_param ldlm.namespaces.*$1*.lru_size=0
5159 lru_resize_disable()
5161 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
5167 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
5173 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
5174 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
5175 echo there is still data in page cache $FILE ?
5176 lctl get_param -n $FILE
5184 DEBUGSAVE="$(lctl get_param -n debug)"
5185 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
5189 [ -n "$DEBUGSAVE" ] &&
5190 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
5194 [ -n "$DEBUGSAVE_SERVER" ] &&
5195 do_nodes $(comma_list $(all_server_nodes)) \
5196 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
5202 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
5205 debug_size_restore() {
5206 [ -n "$DEBUG_SIZE_SAVED" ] && \
5207 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
5211 start_full_debug_logging() {
5216 local DEBUG_SIZE=150
5218 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
5219 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
5222 stop_full_debug_logging() {
5227 # prints bash call stack
5228 print_stack_trace() {
5231 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
5232 local src=${BASH_SOURCE[$i]}
5233 local lineno=${BASH_LINENO[$i-1]}
5234 local funcname=${FUNCNAME[$i]}
5235 echo " = $src:$lineno:$funcname()"
5240 local TYPE=${TYPE:-"FAIL"}
5243 # do not dump logs if $1=false
5244 if [ "x$1" = "xfalse" ]; then
5249 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
5250 (print_stack_trace 2) >&2
5252 # We need to dump the logs on all nodes
5254 gather_logs $(comma_list $(nodes_list))
5258 [ "$TESTSUITELOG" ] &&
5259 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
5260 if [ -z "$*" ]; then
5261 echo "error() without useful message, please fix" > $LOGDIR/err
5263 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
5264 echo "$@" > $LOGDIR/ignore
5266 echo "$@" > $LOGDIR/err
5270 # cleanup the env for failed tests
5274 ##################################
5276 ##################################
5284 local log=$TESTSUITELOG
5286 [ -f "$log" ] && grep -q FAIL $log && status=1
5300 # use only if we are ignoring failures for this test, bugno required.
5301 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
5302 # e.g. error_ignore bz5494 "your message" or
5303 # error_ignore LU-5494 "your message"
5305 local TYPE="IGNORE ($1)"
5310 error_and_remount() {
5312 remount_client $MOUNT
5316 # Throw an error if it's not running in vm - usually for performance
5319 local virt=$(running_in_vm)
5320 if [[ -n "$virt" ]]; then
5321 echo "running in VM '$virt', ignore error"
5322 error_ignore env=$virt "$@"
5329 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
5334 log " SKIP: $TESTSUITE $TESTNAME $@"
5336 if [[ -n "$ALWAYS_SKIPPED" ]]; then
5337 skip_logged $TESTNAME "$@"
5340 echo "$@" > $LOGDIR/skip
5343 [[ -n "$TESTSUITELOG" ]] &&
5344 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
5347 build_test_filter() {
5348 EXCEPT="$EXCEPT $(testslist_filter)"
5351 if [[ $O = [0-9]*-[0-9]* ]]; then
5352 for num in $(seq $(echo $O | tr '-' ' ')); do
5360 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
5361 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
5362 [ "$EXCEPT_SLOW" ] && \
5363 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
5364 for E in $EXCEPT; do
5365 eval EXCEPT_${E}=true
5367 for E in $ALWAYS_EXCEPT; do
5368 eval EXCEPT_ALWAYS_${E}=true
5370 for E in $EXCEPT_SLOW; do
5371 eval EXCEPT_SLOW_${E}=true
5373 for G in $GRANT_CHECK_LIST; do
5374 eval GCHECK_ONLY_${G}=true
5379 if [[ $1 = [a-z]* ]]; then
5386 # print a newline if the last test was skipped
5387 export LAST_SKIPPED=
5388 export ALWAYS_SKIPPED=
5390 # Main entry into test-framework. This is called with the name and
5391 # description of a test. The name is used to find the function to run
5392 # the test using "test_$name".
5394 # This supports a variety of methods of specifying specific test to
5395 # run or not run. These need to be documented...
5400 export base=$(basetest $1)
5401 if [ -n "$ONLY" ]; then
5403 if [ ${!testname}x != x ]; then
5404 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5405 run_one_logged $1 "$2"
5409 if [ ${!testname}x != x ]; then
5410 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5411 run_one_logged $1 "$2"
5421 if [ ${!testname}x != x ]; then
5422 TESTNAME=test_$1 skip "skipping excluded test $1"
5425 testname=EXCEPT_$base
5426 if [ ${!testname}x != x ]; then
5427 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5430 testname=EXCEPT_ALWAYS_$1
5431 if [ ${!testname}x != x ]; then
5432 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5435 testname=EXCEPT_ALWAYS_$base
5436 if [ ${!testname}x != x ]; then
5437 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5440 testname=EXCEPT_SLOW_$1
5441 if [ ${!testname}x != x ]; then
5442 TESTNAME=test_$1 skip "skipping SLOW test $1"
5445 testname=EXCEPT_SLOW_$base
5446 if [ ${!testname}x != x ]; then
5447 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5453 run_one_logged $1 "$2"
5460 load_module ../libcfs/libcfs/libcfs
5472 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5477 strace -o $TMP/$1.strace -ttt $*
5479 log "FINISHED: $*: rc $RC"
5486 banner test complete, duration $duration sec
5487 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5488 echo duration $duration >>$TESTSUITELOG
5492 # Set TEST_STATUS here. It will be used for logging the result.
5495 if [[ -f $LOGDIR/err ]]; then
5497 elif [[ -f $LOGDIR/skip ]]; then
5500 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5504 local FFREE=$(do_node $SINGLEMDS \
5505 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5506 local FTOTAL=$(do_node $SINGLEMDS \
5507 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5509 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5513 echo -n "Resetting fail_loc on all nodes..."
5514 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5515 fail_val=0 2>/dev/null" || true
5521 # Log a message (on all nodes) padded with "=" before and after.
5522 # Also appends a timestamp and prepends the testsuite name.
5525 EQUALS="===================================================================================================="
5527 msg="== ${TESTSUITE} $*"
5529 [[ $last != "=" && $last != " " ]] && msg="$msg "
5530 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5531 # always include at least == after the message
5532 log "$msg== $(date +"%H:%M:%S (%s)")"
5535 check_dmesg_for_errors() {
5537 local errors="VFS: Busy inodes after unmount of\|\
5538 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5539 group descriptors corrupted"
5541 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5542 [ -z "$res" ] && return 0
5543 echo "Kernel error detected: $res"
5548 # Run a single test function and cleanup after it.
5550 # This function should be run in a subshell so the test func can
5551 # exit() without stopping the whole script.
5556 export tfile=f${testnum}.${TESTSUITE}
5557 export tdir=d${testnum}.${TESTSUITE}
5558 export TESTNAME=test_$testnum
5559 local SAVE_UMASK=`umask`
5562 if ! grep -q $DIR /proc/mounts; then
5566 banner "test $testnum: $message"
5567 test_${testnum} || error "test_$testnum failed with $?"
5570 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5572 check_dmesg_for_errors || error "Error in dmesg detected"
5573 if [ "$PARALLEL" != "yes" ]; then
5574 ps auxww | grep -v grep | grep -q multiop &&
5575 error "multiop still running"
5586 # Wrapper around run_one to ensure:
5587 # - test runs in subshell
5588 # - output of test is saved to separate log file for error reporting
5589 # - test result is saved to data file
5592 local BEFORE=$(date +%s)
5594 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5595 local test_log=$LOGDIR/$name
5596 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5597 local zfs_debug_log=$LOGDIR/$zfs_log_name
5599 rm -rf $LOGDIR/ignore
5601 local SAVE_UMASK=$(umask)
5605 log_sub_test_begin test_${1}
5606 (run_one $1 "$2") 2>&1 | tee -i $test_log
5607 local RC=${PIPESTATUS[0]}
5609 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5610 echo "test_$1 returned $RC" | tee $LOGDIR/err
5612 duration=$(($(date +%s) - $BEFORE))
5613 pass "$1" "(${duration}s)"
5615 if [[ -f $LOGDIR/err ]]; then
5616 TEST_ERROR=$(cat $LOGDIR/err)
5617 elif [[ -f $LOGDIR/ignore ]]; then
5618 TEST_ERROR=$(cat $LOGDIR/ignore)
5619 elif [[ -f $LOGDIR/skip ]]; then
5620 TEST_ERROR=$(cat $LOGDIR/skip)
5622 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5624 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5628 if [ -f $LOGDIR/err ]; then
5629 log_zfs_info "$zfs_debug_log"
5630 $FAIL_ON_ERROR && exit $RC
5639 # Print information of skipped tests to result.yml
5642 log_sub_test_begin $1
5644 log_sub_test_end "SKIP" "0" "0" "$@"
5648 (cd $(dirname $1); echo $PWD/$(basename $1))
5653 export base=$(basetest $1)
5654 [ "$CHECK_GRANT" == "no" ] && return 0
5656 testnamebase=GCHECK_ONLY_${base}
5657 testname=GCHECK_ONLY_$1
5658 [ ${!testnamebase}x == x -a ${!testname}x == x ] && return 0
5660 echo -n "checking grant......"
5662 local clients=$CLIENTS
5663 [ -z "$clients" ] && clients=$(hostname)
5665 # sync all the data and make sure no pending data on server
5666 do_nodes $clients sync
5669 client_grant=$(do_nodes $clients \
5670 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5671 awk '{ total += $1 } END { printf("%0.0f", total) }')
5674 # which is tot_granted less grant_precreate
5675 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5677 "obdfilter.${FSNAME}-OST*.{tot_granted,tot_pending,grant_precreate}" |
5678 sed 's/=/ /'| awk '/tot_granted/{ total += $2 };
5679 /tot_pending/{ total -= $2 };
5680 /grant_precreate/{ total -= $2 };
5681 END { printf("%0.0f", total) }')
5683 # check whether client grant == server grant
5684 if [[ $client_grant -ne $server_grant ]]; then
5685 do_nodes $(comma_list $(osts_nodes)) \
5686 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
5687 "obdfilter.${FSNAME}-OST*.grant_*"
5688 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5689 error "failed: client:${client_grant} server: ${server_grant}."
5691 echo "pass: client:${client_grant} server: ${server_grant}"
5695 ########################
5701 ost=`echo $1 | awk -F_ '{print $3}'`
5702 if [ -z $ost ]; then
5703 ost=`echo $1 | sed 's/-osc.*//'`
5708 ostuuid_from_index()
5710 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5713 ostname_from_index() {
5714 local uuid=$(ostuuid_from_index $1)
5718 index_from_ostuuid()
5720 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5723 mdtuuid_from_index()
5725 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5729 # Return unique identifier for given hostname
5732 echo $host_name | md5sum | cut -d' ' -f1
5736 # Returns list of ip addresses for each interface
5738 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5743 # Cache address list to avoid mutiple execution of local_addr_list
5744 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5746 for i in $LOCAL_ADDR_LIST ; do
5747 [[ "$i" == "$addr" ]] && return 0
5754 local is_local="IS_LOCAL_$(host_id $host_name)"
5755 if [ -z "${!is_local-}" ] ; then
5757 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5758 is_local_addr "$host_ip" && eval $is_local=1
5760 [[ "${!is_local}" == "1" ]]
5765 local_node $node && return 1
5772 for node in $(mdts_nodes); do
5773 remote_node $node && return 0
5780 [ -n "$CLIENTONLY" ] && return 0 || true
5781 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5786 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5787 MSKIPPED=1 && return 1
5794 for node in $(osts_nodes) ; do
5795 remote_node $node && return 0
5802 [ -n "$CLIENTONLY" ] && return 0 || true
5803 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5808 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5809 OSKIPPED=1 && return 1
5815 [ -n "$CLIENTONLY" ] && return 0 || true
5817 MGS=$(facet_host mgs)
5818 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5823 remote_mds_nodsh || remote_ost_nodsh || \
5824 $(single_local_node $(comma_list $(nodes_list)))
5828 remote_ost && remote_mds
5831 # Get the active nodes for facets.
5839 for facet in ${facets//,/ }; do
5840 nodes="$nodes $(facet_active_host $facet)"
5843 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5847 # Get name of the active MGS node.
5849 echo -n $(facets_nodes $(get_facets MGS))
5852 # Get all of the active MDS nodes.
5854 echo -n $(facets_nodes $(get_facets MDS))
5857 # Get all of the active OSS nodes.
5859 echo -n $(facets_nodes $(get_facets OST))
5862 # Get all of the active AGT (HSM agent) nodes.
5864 echo -n $(facets_nodes $(get_facets AGT))
5867 # Get all of the client nodes and active server nodes.
5869 local nodes=$HOSTNAME
5873 # CLIENTS (if specified) contains the local client
5874 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5876 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5877 nodes="$nodes $(facets_nodes $(get_facets))"
5880 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5884 # Get all of the remote client nodes and remote active server nodes.
5885 remote_nodes_list () {
5886 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5889 # Get all of the MDS nodes, including active and passive nodes.
5893 local nodes="${mds_HOST} ${mdsfailover_HOST}"
5897 for i in $(seq $MDSCOUNT); do
5899 failover_host=mds${i}failover_HOST
5900 nodes="$nodes ${!host} ${!failover_host}"
5903 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5907 # Get all of the OSS nodes, including active and passive nodes.
5911 local nodes="${ost_HOST} ${ostfailover_HOST}"
5915 for i in $(seq $OSTCOUNT); do
5917 failover_host=ost${i}failover_HOST
5918 nodes="$nodes ${!host} ${!failover_host}"
5921 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5925 # Get all of the server nodes, including active and passive nodes.
5926 all_server_nodes () {
5931 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5933 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5937 # Get all of the client and server nodes, including active and passive nodes.
5939 local nodes=$HOSTNAME
5943 # CLIENTS (if specified) contains the local client
5944 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5946 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5947 nodes="$nodes $(all_server_nodes)"
5950 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5954 init_clients_lists () {
5955 # Sanity check: exclude the local client from RCLIENTS
5956 local clients=$(hostlist_expand "$RCLIENTS")
5957 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5959 # Sanity check: exclude the dup entries
5960 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5962 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5964 # Sanity check: exclude the dup entries from CLIENTS
5965 # for those configs which has SINGLCLIENT set to local client
5966 clients=$(for i in $clients; do echo $i; done | sort -u)
5968 CLIENTS=$(comma_list $clients)
5969 local -a remoteclients=($RCLIENTS)
5970 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5971 varname=CLIENT$((i + 2))
5972 eval $varname=${remoteclients[i]}
5975 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5978 get_random_entry () {
5981 rnodes=${rnodes//,/ }
5983 local -a nodes=($rnodes)
5984 local num=${#nodes[@]}
5985 local i=$((RANDOM * num * 2 / 65536))
5991 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5995 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5996 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
6001 echo $nodes | wc -w || true
6005 local nodes=$(osts_nodes)
6006 local osscount=$(get_node_count "$nodes")
6007 [ ! "$OSTCOUNT" = "$osscount" ]
6011 local nodes=$(mdts_nodes)
6012 local mdtcount=$(get_node_count "$nodes")
6013 [ ! "$MDSCOUNT" = "$mdtcount" ]
6016 generate_machine_file() {
6017 local nodes=${1//,/ }
6018 local machinefile=$2
6020 for node in $nodes; do
6021 echo $node >>$machinefile || \
6022 { echo "can not generate machinefile $machinefile" && return 1; }
6027 local file=$1/stripe
6030 $LFS getstripe -v $file || error "getstripe $file failed"
6034 setstripe_nfsserver () {
6036 local nfsexportdir=$2
6040 local -a nfsexport=($(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
6041 { print $1 }' /proc/mounts | cut -f 1 -d :))
6043 # check that only one nfs mounted
6044 [[ -z $nfsexport ]] && echo "$dir is not nfs mounted" && return 1
6045 (( ${#nfsexport[@]} == 1 )) ||
6046 error "several nfs mounts found for $dir: ${nfsexport[@]} !"
6048 do_nodev ${nfsexport[0]} lfs setstripe $nfsexportdir "$@"
6051 # Check and add a test group.
6057 local gid=$(getent group $group_name | cut -d: -f3)
6058 if [[ -n "$gid" ]]; then
6059 [[ "$gid" -eq "$group_id" ]] || {
6060 error_noexit "inconsistent group ID:" \
6061 "new: $group_id, old: $gid"
6065 groupadd -g $group_id $group_name
6072 # Check and add a test user.
6085 local uid=$(getent passwd $user_name | cut -d: -f3)
6086 if [[ -n "$uid" ]]; then
6087 if [[ "$uid" -eq "$user_id" ]]; then
6088 local dir=$(getent passwd $user_name | cut -d: -f6)
6089 if [[ "$dir" != "$home" ]]; then
6091 usermod -d $home $user_name
6095 error_noexit "inconsistent user ID:" \
6096 "new: $user_id, old: $uid"
6101 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
6108 check_runas_id_ret() {
6110 local myRUNAS_UID=$1
6111 local myRUNAS_GID=$2
6114 if [ -z "$myRUNAS" ]; then
6115 error_exit "myRUNAS command must be specified for check_runas_id"
6118 $myRUNAS krb5_login.sh || \
6119 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
6121 mkdir $DIR/d0_runas_test
6123 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
6124 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
6125 rm -rf $DIR/d0_runas_test
6130 local myRUNAS_UID=$1
6131 local myRUNAS_GID=$2
6134 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
6135 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
6136 Please set RUNAS_ID to some UID which exists on MDS and client or
6137 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
6140 # obtain the UID/GID for MPI_USER
6144 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
6145 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
6147 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
6148 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
6151 # obtain and cache Kerberos ticket-granting ticket
6152 refresh_krb5_tgt() {
6153 local myRUNAS_UID=$1
6154 local myRUNAS_GID=$2
6157 if [ -z "$myRUNAS" ]; then
6158 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
6161 CLIENTS=${CLIENTS:-$HOSTNAME}
6162 do_nodes $CLIENTS "set -x
6163 if ! $myRUNAS krb5_login.sh; then
6164 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
6169 # Run multiop in the background, but wait for it to print
6170 # "PAUSING" to its stdout before returning from this function.
6171 multiop_bg_pause() {
6172 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
6176 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
6179 echo "$MULTIOP_PROG $FILE v$ARGS"
6180 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
6182 echo "TMPPIPE=${TMPPIPE}"
6183 read -t 60 multiop_output < $TMPPIPE
6184 if [ $? -ne 0 ]; then
6189 if [ "$multiop_output" != "PAUSING" ]; then
6190 echo "Incorrect multiop output: $multiop_output"
6205 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
6211 inodes_available () {
6212 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
6213 sort -un | head -n1) || return 1
6217 mdsrate_inodes_available () {
6218 local min_inodes=$(inodes_available)
6219 echo $((min_inodes * 99 / 100))
6222 # reset stat counters
6224 local paramfile="$1"
6225 lctl set_param -n $paramfile=0
6230 local paramfile="$1"
6232 lctl get_param -n $paramfile |
6233 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
6237 awk '{sum += $1} END { printf("%0.0f", sum) }'
6240 calc_osc_kbytes () {
6241 df $MOUNT > /dev/null
6242 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
6245 # save_lustre_params(comma separated facet list, parameter_mask)
6246 # generate a stream of formatted strings (<facet> <param name>=<param value>)
6247 save_lustre_params() {
6253 for facet in ${facets//,/ }; do
6254 node=$(facet_active_host $facet)
6255 [[ *\ $node\ * = " $nodes " ]] && continue
6256 nodes="$nodes $node"
6258 do_node $node "$LCTL get_param $2 |
6259 while read s; do echo $facet \\\$s; done"
6263 # restore lustre parameters from input stream, produces by save_lustre_params
6264 restore_lustre_params() {
6269 while IFS=" =" read facet name val; do
6270 do_facet $facet "$LCTL set_param -n $name $val"
6274 check_node_health() {
6275 local nodes=${1:-$(comma_list $(nodes_list))}
6277 for node in ${nodes//,/ }; do
6278 check_network "$node" 5
6279 if [ $? -eq 0 ]; then
6280 do_node $node "rc=0;
6281 val=\\\$($LCTL get_param -n catastrophe 2>&1);
6282 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
6283 echo \\\$(hostname -s): \\\$val;
6286 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
6291 mdsrate_cleanup () {
6293 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
6294 --nfiles $3 --dir $4 --filefmt $5 $6
6299 delayed_recovery_enabled () {
6300 local var=${SINGLEMDS}_svc
6301 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
6304 ########################
6306 convert_facet2label() {
6309 if [ x$facet = xost ]; then
6313 local varsvc=${facet}_svc
6315 if [ -n ${!varsvc} ]; then
6318 error "No lablel for $facet!"
6322 get_clientosc_proc_path() {
6326 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
6327 # used by MDT would not be changed.
6328 # mdt lov: fsname-mdtlov
6329 # mdt osc: fsname-OSTXXXX-osc
6330 mds_on_old_device() {
6331 local mds=${1:-"$SINGLEMDS"}
6333 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
6334 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
6335 > /dev/null 2>&1" && return 0
6340 get_mdtosc_proc_path() {
6342 local ost_label=${2:-"*OST*"}
6344 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
6345 local mdt_label=$(convert_facet2label $mds_facet)
6346 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
6348 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
6349 mds_on_old_device $mds_facet; then
6350 echo "${ost_label}-osc"
6351 elif [[ $ost_label = *OST* ]]; then
6352 echo "${ost_label}-osc-${mdt_index}"
6354 echo "${ost_label}-osp-${mdt_index}"
6358 get_osc_import_name() {
6361 local label=$(convert_facet2label $ost)
6363 if [ "${facet:0:3}" = "mds" ]; then
6364 get_mdtosc_proc_path $facet $label
6368 get_clientosc_proc_path $label
6372 _wait_import_state () {
6375 local maxtime=${3:-$(max_recovery_time)}
6376 local error_on_failure=${4:-1}
6380 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6381 while [ "${CONN_STATE}" != "${expected}" ]; do
6382 if [ "${expected}" == "DISCONN" ]; then
6383 # for disconn we can check after proc entry is removed
6384 [ "x${CONN_STATE}" == "x" ] && return 0
6385 # with AT enabled, we can have connect request timeout near of
6386 # reconnect timeout and test can't see real disconnect
6387 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
6389 if [ $i -ge $maxtime ]; then
6390 [ $error_on_failure -ne 0 ] && \
6391 error "can't put import for $CONN_PROC into ${expected}" \
6392 "state after $i sec, have ${CONN_STATE}"
6396 # Add uniq for multi-mount case
6397 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6401 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6405 wait_import_state() {
6408 local maxtime=${3:-$(max_recovery_time)}
6409 local error_on_failure=${4:-1}
6412 for param in ${params//,/ }; do
6413 _wait_import_state $state $param $maxtime $error_on_failure || return
6417 wait_import_state_mount() {
6418 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6422 wait_import_state $*
6425 # One client request could be timed out because server was not ready
6426 # when request was sent by client.
6427 # The request timeout calculation details :
6429 # /* We give the server rq_timeout secs to process the req, and
6430 # add the network latency for our local timeout. */
6431 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6432 # ptlrpc_at_get_net_latency(request) ;
6434 # ptlrpc_connect_import ()
6435 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6438 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6439 # ptlrpc_at_get_net_latency(request) ->
6440 # at_get (max (iat_net_latency=0, at_min)) = at_min
6443 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6444 # INITIAL_CONNECT_TIMEOUT + at_min
6446 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6447 # because we can not get this value in runtime,
6448 # the value depends on configure options, and it is not stored in /proc.
6450 # #define CONNECTION_SWITCH_MIN 5U
6451 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6453 request_timeout () {
6456 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6457 local init_connect_timeout=$TIMEOUT
6458 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6460 local at_min=$(at_get $facet at_min)
6462 echo $(( init_connect_timeout + at_min ))
6465 _wait_osc_import_state() {
6469 local target=$(get_osc_import_name $facet $ost_facet)
6470 local param="osc.${target}.ost_server_uuid"
6474 # 1. wait the deadline of client 1st request (it could be skipped)
6475 # 2. wait the deadline of client 2nd request
6476 local maxtime=$(( 2 * $(request_timeout $facet)))
6478 if [[ $facet == client* ]]; then
6479 # During setup time, the osc might not be setup, it need wait
6480 # until list_param can return valid value.
6481 params=$($LCTL list_param $param 2>/dev/null || true)
6482 while [ -z "$params" ]; do
6483 if [ $i -ge $maxtime ]; then
6484 echo "can't get $param in $maxtime secs"
6489 params=$($LCTL list_param $param 2>/dev/null || true)
6493 if [[ $ost_facet = mds* ]]; then
6494 # no OSP connection to itself
6495 if [[ $facet = $ost_facet ]]; then
6498 param="osp.${target}.mdt_server_uuid"
6502 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6503 wait_import_state $expected "$params" $maxtime; then
6504 error "$facet: import is not in $expected state after $maxtime"
6511 wait_osc_import_state() {
6517 if [[ $facet = mds ]]; then
6518 for num in $(seq $MDSCOUNT); do
6519 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6522 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6526 _wait_mgc_import_state() {
6529 local error_on_failure=${3:-1}
6530 local param="mgc.*.mgs_server_uuid"
6534 # 1. wait the deadline of client 1st request (it could be skipped)
6535 # 2. wait the deadline of client 2nd request
6536 local maxtime=$(( 2 * $(request_timeout $facet)))
6538 if [[ $facet == client* ]]; then
6539 # During setup time, the osc might not be setup, it need wait
6540 # until list_param can return valid value. And also if there
6541 # are mulitple osc entries we should list all of them before
6543 params=$($LCTL list_param $param 2>/dev/null || true)
6544 while [ -z "$params" ]; do
6545 if [ $i -ge $maxtime ]; then
6546 echo "can't get $param in $maxtime secs"
6551 params=$($LCTL list_param $param 2>/dev/null || true)
6554 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6555 wait_import_state $expected "$params" $maxtime \
6556 $error_on_failure; then
6557 if [ $error_on_failure -ne 0 ]; then
6558 error "import is not in ${expected} state"
6566 wait_mgc_import_state() {
6569 local error_on_failure=${3:-1}
6572 if [[ $facet = mds ]]; then
6573 for num in $(seq $MDSCOUNT); do
6574 _wait_mgc_import_state mds$num "$expected" \
6575 $error_on_failure || return
6578 _wait_mgc_import_state "$facet" "$expected"
6579 $error_on_failure || return
6583 wait_dne_interconnect() {
6586 if [ $MDSCOUNT -gt 1 ]; then
6587 for num in $(seq $MDSCOUNT); do
6588 wait_osc_import_state mds mds$num FULL
6593 get_clientmdc_proc_path() {
6597 get_clientmgc_proc_path() {
6605 [ -z "$list" ] && return 0
6607 # Add paths to lustre tests for 32 and 64 bit systems.
6608 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6609 local TESTPATH="$RLUSTRE/tests:"
6610 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6611 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6614 wait_clients_import_state () {
6621 if [ "$FAILURE_MODE" = HARD ]; then
6622 facets=$(facets_on_host $(facet_active_host $facet))
6625 for facet in ${facets//,/ }; do
6626 local label=$(convert_facet2label $facet)
6629 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6630 $label).ost_server_uuid" ;;
6631 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6632 $label).mds_server_uuid" ;;
6633 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6634 $label).mgs_server_uuid" ;;
6635 *) error "unknown facet!" ;;
6638 local params=$(expand_list $params $proc_path)
6641 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6643 error "import is not in ${expected} state"
6655 # wait until all MDTs are in the expected state
6656 for ((num = 1; num <= $MDSCOUNT; num++)); do
6657 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
6660 if [ $facet = "mds" ]; then
6661 mproc="osp.$mdtosp.active"
6662 [ $num -eq $((tgt_idx + 1)) ] && continue
6664 mproc="osc.$mdtosp.active"
6670 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
6674 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
6675 if [ $result -eq $expected ]; then
6676 echo -n "target updated after"
6677 echo "$wait sec (got $result)"
6681 if [ $wait -eq $max ]; then
6682 error "$tgt_name: wanted $expected got $result"
6684 echo "Waiting $((max - wait)) secs for $tgt_name"
6694 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6695 $LCTL get_param obdfilter.*.kbytesavail))
6696 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6697 $LCTL get_param -n obdfilter.*.tot_granted))
6698 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6699 $LCTL get_param -n obdfilter.*.kbytestotal))
6700 for ((i=0; i<${#AVAILA[@]}; i++)); do
6701 local -a AVAIL1=(${AVAILA[$i]//=/ })
6702 local -a TOTAL=(${TOTALA[$i]//=/ })
6703 GRANT=$((${GRANTA[$i]}/1024))
6704 # allow 1% of total space in bavail because of delayed
6705 # allocation with ZFS which might release some free space after
6706 # txg commit. For small devices, we set a mininum of 8MB
6707 local LIMIT=$((${TOTAL} / 100 + 8000))
6708 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6709 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6710 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6711 echo " FULL" || echo
6717 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6720 check_pool_not_exist() {
6721 local fsname=${1%%.*}
6722 local poolname=${1##$fsname.}
6723 [[ $# -ne 1 ]] && return 0
6724 [[ x$poolname = x ]] && return 0
6725 list_pool $fsname | grep -w $1 && return 1
6730 local fsname=${1%%.*}
6731 local poolname=${1##$fsname.}
6733 trap "destroy_test_pools $fsname" EXIT
6734 do_facet mgs lctl pool_new $1
6736 # get param should return err unless pool is created
6737 [[ $RC -ne 0 ]] && return $RC
6739 for mds_id in $(seq $MDSCOUNT); do
6740 local mdt_id=$((mds_id-1))
6741 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6742 wait_update_facet mds$mds_id \
6743 "lctl get_param -n lod.$lodname.pools.$poolname \
6744 2>/dev/null || echo foo" "" ||
6745 error "mds$mds_id: pool_new failed $1"
6747 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6748 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6754 add_pool_to_list () {
6755 local fsname=${1%%.*}
6756 local poolname=${1##$fsname.}
6758 local listvar=${fsname}_CREATED_POOLS
6759 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6763 remove_pool_from_list () {
6764 local fsname=${1%%.*}
6765 local poolname=${1##$fsname.}
6767 local listvar=${fsname}_CREATED_POOLS
6768 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6772 destroy_pool_int() {
6774 local OSTS=$(list_pool $1)
6775 for ost in $OSTS; do
6776 do_facet mgs lctl pool_remove $1 $ost
6778 do_facet mgs lctl pool_destroy $1
6781 # <fsname>.<poolname> or <poolname>
6783 local fsname=${1%%.*}
6784 local poolname=${1##$fsname.}
6786 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6790 check_pool_not_exist $fsname.$poolname
6791 [[ $? -eq 0 ]] && return 0
6793 destroy_pool_int $fsname.$poolname
6795 [[ $RC -ne 0 ]] && return $RC
6796 for mds_id in $(seq $MDSCOUNT); do
6797 local mdt_id=$((mds_id-1))
6798 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6799 wait_update_facet mds$mds_id \
6800 "lctl get_param -n lod.$lodname.pools.$poolname \
6801 2>/dev/null || echo foo" "foo" ||
6802 error "mds$mds_id: destroy pool failed $1"
6804 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6805 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6807 remove_pool_from_list $fsname.$poolname
6813 local fsname=${1:-$FSNAME}
6815 local listvar=${fsname}_CREATED_POOLS
6817 [ x${!listvar} = x ] && return 0
6819 echo "Destroy the created pools: ${!listvar}"
6820 for poolname in ${!listvar//,/ }; do
6821 destroy_pool $fsname.$poolname
6825 destroy_test_pools () {
6827 local fsname=${1:-$FSNAME}
6828 destroy_pools $fsname || true
6834 local ts=$(date +%s)
6837 if [[ ! -f "$YAML_LOG" ]]; then
6838 # init_logging is not performed before gather_logs,
6839 # so the $LOGDIR needs to be checked here
6840 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6843 [ -f $LOGDIR/shared ] && docp=false
6845 # dump lustre logs, dmesg
6847 prefix="$TESTLOG_PREFIX.$TESTNAME"
6849 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6851 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6852 echo "Dumping logs only on local client."
6853 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6854 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6859 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6860 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6862 if [ ! -f $LOGDIR/shared ]; then
6863 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6876 for i in $(seq 0 $num_mntpts); do
6877 cmd="ls -laf ${mntpt_root}$i/$dir"
6883 for pid in $pids; do
6890 # check_and_start_recovery_timer()
6891 # service_time = at_est2timeout(service_time);
6892 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6893 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6895 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6896 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6897 #define CONNECTION_SWITCH_MIN 5
6898 #define CONNECTION_SWITCH_INC 5
6899 max_recovery_time() {
6900 local init_connect_timeout=$((TIMEOUT / 20))
6901 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6903 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6904 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6906 echo -n $service_time
6909 recovery_time_min() {
6910 local connection_switch_min=5
6911 local connection_switch_inc=5
6912 local connection_switch_max
6913 local reconnect_delay_max
6914 local initial_connect_timeout
6918 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6919 (($connection_switch_min > $TIMEOUT)) &&
6920 max=$connection_switch_min || max=$TIMEOUT
6921 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6923 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6924 timeout_20=$((TIMEOUT/20))
6925 (($connection_switch_min > $timeout_20)) &&
6926 initial_connect_timeout=$connection_switch_min ||
6927 initial_connect_timeout=$timeout_20
6929 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6930 initial_connect_timeout))
6931 echo $((2 * reconnect_delay_max))
6934 get_clients_mount_count () {
6935 local clients=${CLIENTS:-$HOSTNAME}
6937 # we need to take into account the clients mounts and
6938 # exclude mds/ost mounts if any;
6939 do_nodes $clients cat /proc/mounts | grep lustre |
6940 grep -w $MOUNT | wc -l
6944 PROC_CLI="srpc_info"
6945 PROC_CON="srpc_contexts"
6953 if [ $M -lt $N ]; then
6957 while [ $N -lt $M ]; do
6967 calc_connection_cnt() {
6970 # MDT->MDT = 2 * C(M, 2)
6974 comb_m2=$(combination $MDSCOUNT 2)
6976 local num_clients=$(get_clients_mount_count)
6978 local cnt_mdt2mdt=$((comb_m2 * 2))
6979 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6980 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6981 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6982 if is_mounted $MOUNT2; then
6983 cnt_cli2mdt=$((cnt_cli2mdt * 2))
6984 cnt_cli2ost=$((cnt_cli2ost * 2))
6992 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6993 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6994 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
6995 + cnt_cli2ost + cnt_cli2mdt))
7009 local cmd="$tgt.srpc.flavor"
7011 if [ $net == "any" ]; then
7016 if [ $dir != "any" ]; then
7021 log "Setting sptlrpc rule: $cmd"
7022 do_facet mgs "$LCTL conf_param $cmd"
7028 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
7038 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
7039 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
7041 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
7043 if [ "x$bulkspec" != "x" ]; then
7044 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
7046 if [ "x$algs" != "x" ]; then
7047 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
7049 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
7050 if [ $bulk == "bulkn" ]; then
7051 bulk_count=`echo "$output" | grep "bulk flavor" \
7052 | grep "null/null" | wc -l`
7053 elif [ $bulk == "bulki" ]; then
7054 bulk_count=`echo "$output" | grep "bulk flavor" \
7055 | grep "/null" | grep -v "null/" | wc -l`
7057 bulk_count=`echo "$output" | grep "bulk flavor" \
7058 | grep -v "/null" | grep -v "null/" | wc -l`
7062 [ $bulk_count -lt $count ] && count=$bulk_count
7073 local clients=${CLIENTS:-$HOSTNAME}
7075 for c in ${clients//,/ }; do
7076 local output=$(do_node $c lctl get_param -n \
7077 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
7078 local tmpcnt=$(count_flvr "$output" $flavor)
7079 if $GSS_SK && [ $flavor != "null" ]; then
7080 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7081 output=$(do_node $c lctl get_param -n \
7082 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
7083 local outcon=$(count_contexts "$output")
7084 if [ "$outcon" -lt "$tmpcnt" ]; then
7088 cnt=$((cnt + tmpcnt))
7098 local clients=${CLIENTS:-$HOSTNAME}
7100 for c in ${clients//,/ }; do
7101 local output=$(do_node $c lctl get_param -n \
7102 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
7103 local tmpcnt=$(count_flvr "$output" $flavor)
7104 if $GSS_SK && [ $flavor != "null" ]; then
7105 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7106 output=$(do_node $c lctl get_param -n \
7107 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
7108 local outcon=$(count_contexts "$output")
7109 if [ "$outcon" -lt "$tmpcnt" ]; then
7113 cnt=$((cnt + tmpcnt))
7123 if [ $MDSCOUNT -le 1 ]; then
7128 for num in `seq $MDSCOUNT`; do
7129 local output=$(do_facet mds$num lctl get_param -n \
7130 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
7131 local tmpcnt=$(count_flvr "$output" $flavor)
7132 if $GSS_SK && [ $flavor != "null" ]; then
7133 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7134 output=$(do_facet mds$num lctl get_param -n \
7135 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
7136 local outcon=$(count_contexts "$output")
7137 if [ "$outcon" -lt "$tmpcnt" ]; then
7141 cnt=$((cnt + tmpcnt))
7152 for num in `seq $MDSCOUNT`; do
7153 mdtosc=$(get_mdtosc_proc_path mds$num)
7154 mdtosc=${mdtosc/-MDT*/-MDT\*}
7155 local output=$(do_facet mds$num lctl get_param -n \
7156 osc.$mdtosc.$PROC_CLI 2>/dev/null)
7157 local tmpcnt=$(count_flvr "$output" $flavor)
7158 if $GSS_SK && [ $flavor != "null" ]; then
7159 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7160 output=$(do_facet mds$num lctl get_param -n \
7161 osc.$mdtosc.$PROC_CON 2>/dev/null)
7162 local outcon=$(count_contexts "$output")
7163 if [ "$outcon" -lt "$tmpcnt" ]; then
7167 cnt=$((cnt + tmpcnt))
7176 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
7178 count_flvr "$output" $flavor
7183 local dir=$1 # from to
7184 local flavor=$2 # flavor expected
7187 if [ $dir == "cli2mdt" ]; then
7188 res=`flvr_cnt_cli2mdt $flavor`
7189 elif [ $dir == "cli2ost" ]; then
7190 res=`flvr_cnt_cli2ost $flavor`
7191 elif [ $dir == "mdt2mdt" ]; then
7192 res=`flvr_cnt_mdt2mdt $flavor`
7193 elif [ $dir == "mdt2ost" ]; then
7194 res=`flvr_cnt_mdt2ost $flavor`
7195 elif [ $dir == "all2ost" ]; then
7196 res1=`flvr_cnt_mdt2ost $flavor`
7197 res2=`flvr_cnt_cli2ost $flavor`
7198 res=$((res1 + res2))
7199 elif [ $dir == "all2mdt" ]; then
7200 res1=`flvr_cnt_mdt2mdt $flavor`
7201 res2=`flvr_cnt_cli2mdt $flavor`
7202 res=$((res1 + res2))
7203 elif [ $dir == "all2all" ]; then
7204 res1=`flvr_cnt_mdt2ost $flavor`
7205 res2=`flvr_cnt_cli2ost $flavor`
7206 res3=`flvr_cnt_mdt2mdt $flavor`
7207 res4=`flvr_cnt_cli2mdt $flavor`
7208 res=$((res1 + res2 + res3 + res4))
7216 local dir=$1 # from to
7217 local flavor=$2 # flavor expected
7218 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
7219 local WAITFLAVOR_MAX=20 # how many retries before abort?
7222 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
7223 echo -n "checking $dir..."
7224 res=$(do_check_flavor $dir $flavor)
7225 echo "found $res/$expect $flavor connections"
7226 [ $res -ge $expect ] && return 0
7230 echo "Error checking $flavor of $dir: expect $expect, actual $res"
7231 # echo "Dumping additional logs for SK debug.."
7232 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
7234 gather_logs $(comma_list $(nodes_list))
7239 restore_to_default_flavor()
7241 local proc="mgs.MGS.live.$FSNAME"
7243 echo "restoring to default flavor..."
7245 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7246 grep ".srpc.flavor" | wc -l)
7248 # remove all existing rules if any
7249 if [ $nrule -ne 0 ]; then
7250 echo "$nrule existing rules"
7251 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7252 grep ".srpc.flavor."); do
7253 echo "remove rule: $rule"
7254 spec=`echo $rule | awk -F = '{print $1}'`
7255 do_facet mgs "$LCTL conf_param -d $spec"
7259 # verify no rules left
7260 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7261 grep ".srpc.flavor." | wc -l)
7262 [ $nrule -ne 0 ] && error "still $nrule rules left"
7264 # wait for default flavor to be applied
7267 set_rule $FSNAME any any $SK_FLAVOR
7268 wait_flavor all2all $SK_FLAVOR
7270 set_rule $FSNAME any cli2mdt $SK_FLAVOR
7271 set_rule $FSNAME any cli2ost $SK_FLAVOR
7272 wait_flavor cli2mdt $SK_FLAVOR
7273 wait_flavor cli2ost $SK_FLAVOR
7275 echo "GSS_SK now at default flavor: $SK_FLAVOR"
7277 wait_flavor all2all null
7283 local flavor=${1:-null}
7285 echo "setting all flavor to $flavor"
7287 # FIXME need parameter to this fn
7288 # and remove global vars
7289 local cnt_all2all=$(calc_connection_cnt all2all)
7291 local res=$(do_check_flavor all2all $flavor)
7292 if [ $res -eq $cnt_all2all ]; then
7293 echo "already have total $res $flavor connections"
7297 echo "found $res $flavor out of total $cnt_all2all connections"
7298 restore_to_default_flavor
7300 [[ $flavor = null ]] && return 0
7302 if $GSS_SK && [ $flavor != "null" ]; then
7304 set_rule $FSNAME any any $flavor
7305 wait_flavor all2all $flavor
7307 set_rule $FSNAME any cli2mdt $flavor
7308 set_rule $FSNAME any cli2ost $flavor
7309 set_rule $FSNAME any mdt2ost null
7310 set_rule $FSNAME any mdt2mdt null
7311 wait_flavor cli2mdt $flavor
7312 wait_flavor cli2ost $flavor
7314 echo "GSS_SK now at flavor: $flavor"
7316 set_rule $FSNAME any any $flavor
7317 wait_flavor all2all $flavor
7324 # Checking for shared logdir
7325 if [ ! -d $dir ]; then
7326 # Not found. Create local logdir
7329 touch $dir/check_file.$(hostname -s)
7334 check_write_access() {
7336 local list=${2:-$(comma_list $(nodes_list))}
7340 for node in ${list//,/ }; do
7341 file=$dir/check_file.$(short_nodename $node)
7342 if [[ ! -f "$file" ]]; then
7343 # Logdir not accessible/writable from this node.
7346 rm -f $file || return 1
7352 [[ -n $YAML_LOG ]] && return
7353 local save_umask=$(umask)
7356 export YAML_LOG=${LOGDIR}/results.yml
7360 # If the yaml log already exists then we will just append to it
7361 if [ ! -f $YAML_LOG ]; then
7362 if check_shared_dir $LOGDIR; then
7363 touch $LOGDIR/shared
7364 echo "Logging to shared log directory: $LOGDIR"
7366 echo "Logging to local directory: $LOGDIR"
7369 yml_nodes_file $LOGDIR >> $YAML_LOG
7370 yml_results_file >> $YAML_LOG
7375 # If modules are not yet loaded then older "lctl lustre_build_version"
7376 # will fail. Use lctl build version instead.
7377 log "Client: $($LCTL lustre_build_version)"
7378 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
7379 do_facet $SINGLEMDS $LCTL --version)"
7380 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
7381 do_facet ost1 $LCTL --version)"
7385 yml_log_test $1 >> $YAML_LOG
7389 yml_log_test_status $@ >> $YAML_LOG
7392 log_sub_test_begin() {
7393 yml_log_sub_test_begin "$@" >> $YAML_LOG
7396 log_sub_test_end() {
7397 yml_log_sub_test_end "$@" >> $YAML_LOG
7403 local llverdev_opts=$2
7404 local devname=$(basename $1)
7405 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
7406 # loop devices aren't in /proc/partitions
7407 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
7409 size=$(($size / 1024 / 1024)) # Gb
7411 local partial_arg=""
7412 # Run in partial (fast) mode if the size
7413 # of a partition > 1 GB
7414 [ $size -gt 1 ] && partial_arg="-p"
7416 llverdev --force $partial_arg $llverdev_opts $dev
7422 local llverfs_opts=$2
7423 local use_partial_arg=$3
7424 local partial_arg=""
7425 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
7427 # Run in partial (fast) mode if the size
7428 # of a partition > 1 GB
7429 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
7431 llverfs $partial_arg $llverfs_opts $dir
7434 #Remove objects from OST
7435 remove_ost_objects() {
7441 local mntpt=$(facet_mntpt $facet)
7442 local opts=$OST_MOUNT_OPTS
7446 echo "removing objects from $ostdev on $facet: $objids"
7447 if ! test -b $ostdev; then
7448 opts=$(csa_add "$opts" -o loop)
7450 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
7453 for i in $objids; do
7454 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
7456 umount -f $mntpt || return $?
7460 #Remove files from MDT
7461 remove_mdt_files() {
7466 local mntpt=$(facet_mntpt $facet)
7467 local opts=$MDS_MOUNT_OPTS
7469 echo "removing files from $mdtdev on $facet: $files"
7470 if [ $(facet_fstype $facet) == ldiskfs ] &&
7471 ! do_facet $facet test -b $mdtdev; then
7472 opts=$(csa_add "$opts" -o loop)
7474 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7478 rm $mntpt/ROOT/$f || { rc=$?; break; }
7480 umount -f $mntpt || return $?
7484 duplicate_mdt_files() {
7489 local mntpt=$(facet_mntpt $facet)
7490 local opts=$MDS_MOUNT_OPTS
7492 echo "duplicating files on $mdtdev on $facet: $files"
7493 mkdir -p $mntpt || return $?
7494 if [ $(facet_fstype $facet) == ldiskfs ] &&
7495 ! do_facet $facet test -b $mdtdev; then
7496 opts=$(csa_add "$opts" -o loop)
7498 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7509 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
7510 pushd $mntpt/ROOT > /dev/null || return $?
7513 touch $f.bad || return $?
7514 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
7516 [ $rc -eq 0 ] || return $rc
7517 setfattr --restore $tmp || return $?
7523 local devs=${1//,/ }
7526 local rslt=$TMP/sgpdd_survey
7528 # sgpdd-survey cleanups ${rslt}.* files
7530 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7536 # returns the canonical name for an ldiskfs device
7541 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7542 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7543 echo dm-\\\${foo##*:};
7545 echo \\\$(basename \\\$dv);
7549 is_sanity_benchmark() {
7550 local benchmarks="dbench bonnie iozone fsx"
7552 for b in $benchmarks; do
7553 if [ "$b" == "$suite" ]; then
7561 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
7565 # Get the available size (KB) of a given obd target.
7572 [[ $facet != client ]] || return 0
7574 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7579 # Get the page size (bytes) on a given facet node.
7583 local size=$(getconf PAGE_SIZE 2>/dev/null)
7585 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7586 echo -n ${size:-4096}
7590 # Get the block count of the filesystem.
7597 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7598 awk '/^Block count:/ {print $3}')
7602 # Get the block size of the filesystem.
7608 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7609 awk '/^Block size:/ {print $3}')
7613 # Check whether the "large_xattr" feature is enabled or not.
7614 large_xattr_enabled() {
7615 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7617 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7619 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7620 grep -E -q '(ea_inode|large_xattr)'"
7621 return ${PIPESTATUS[0]}
7624 # Get the maximum xattr size supported by the filesystem.
7628 if large_xattr_enabled; then
7629 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7632 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7633 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7635 # maximum xattr size = size of block - size of header -
7636 # size of 1 entry - 4 null bytes
7637 size=$((block_size - 32 - 32 - 4))
7643 # Dump the value of the named xattr from a file.
7648 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7651 # Generate a string with size of $size bytes.
7653 local size=${1:-1024} # in bytes
7655 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7658 reformat_external_journal() {
7663 if [ -n "${!var}" ]; then
7664 local rcmd="do_facet $facet"
7666 echo "reformat external journal on $facet:${!var}"
7667 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7671 # MDT file-level backup/restore
7672 mds_backup_restore() {
7675 local devname=$(mdsdevname $(facet_number $facet))
7676 local mntpt=$(facet_mntpt brpt)
7677 local rcmd="do_facet $facet"
7678 local metaea=${TMP}/backup_restore.ea
7679 local metadata=${TMP}/backup_restore.tgz
7680 local opts=${MDS_MOUNT_OPTS}
7681 local svc=${facet}_svc
7683 if ! ${rcmd} test -b ${devname}; then
7684 opts=$(csa_add "$opts" -o loop)
7687 echo "file-level backup/restore on $facet:${devname}"
7689 # step 1: build mount point
7690 ${rcmd} mkdir -p $mntpt
7691 # step 2: cleanup old backup
7692 ${rcmd} rm -f $metaea $metadata
7694 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7695 if [ ! -z $igif ]; then
7696 # step 3.5: rm .lustre
7697 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7699 # step 4: backup metaea
7701 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7703 # step 5: backup metadata
7705 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7707 ${rcmd} $UMOUNT $mntpt || return 4
7708 # step 8: reformat dev
7709 echo "reformat new device"
7710 format_mdt $(facet_number $facet)
7712 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7713 # step 10: restore metadata
7715 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7716 # step 11: restore metaea
7718 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7719 # step 12: remove recovery logs
7720 echo "remove recovery logs"
7721 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7722 # step 13: umount dev
7723 ${rcmd} $UMOUNT $mntpt || return 10
7724 # step 14: cleanup tmp backup
7725 ${rcmd} rm -f $metaea $metadata
7726 # step 15: reset device label - it's not virgin on
7727 ${rcmd} e2label $devname ${!svc}
7734 local devname=$(mdsdevname $(facet_number $facet))
7735 local mntpt=$(facet_mntpt brpt)
7736 local rcmd="do_facet $facet"
7737 local opts=${MDS_MOUNT_OPTS}
7739 if ! ${rcmd} test -b ${devname}; then
7740 opts=$(csa_add "$opts" -o loop)
7743 echo "removing OI files on $facet: idx=${idx}"
7745 # step 1: build mount point
7746 ${rcmd} mkdir -p $mntpt
7748 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7749 if [ -z $idx ]; then
7750 # step 3: remove all OI files
7751 ${rcmd} rm -fv $mntpt/oi.16*
7752 elif [ $idx -lt 2 ]; then
7753 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7757 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7758 for ((i=${idx}; i<64; i=$((i * idx)))); do
7759 ${rcmd} rm -fv $mntpt/oi.16.${i}
7763 ${rcmd} $UMOUNT $mntpt || return 2
7764 # OI files will be recreated when mounted as lustre next time.
7767 # generate maloo upload-able log file name
7768 # \param logname specify unique part of file name
7769 generate_logname() {
7770 local logname=${1:-"default_logname"}
7772 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7775 # make directory on different MDTs
7779 local stripe_count=2
7780 local stripe_index=-1
7783 while getopts "c:i:p" opt; do
7785 c) stripe_count=$OPTARG;;
7786 i) stripe_index=$OPTARG;;
7788 \?) error "only support -i -c -p";;
7792 shift $((OPTIND - 1))
7793 [ $# -eq 1 ] || error "Only creating single directory is supported"
7796 if [ "$p_option" == "-p" ]; then
7797 local parent=$(dirname $path)
7799 [ -d $path ] && return 0
7800 [ ! -d ${parent} ] && mkdir -p ${parent}
7803 if [ $MDSCOUNT -le 1 ]; then
7806 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7809 if [ $stripe_index -eq -1 ]; then
7810 mdt_index=$((test_num % MDSCOUNT))
7812 mdt_index=$stripe_index
7814 echo "striped dir -i$mdt_index -c$stripe_count $path"
7815 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7819 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
7821 # If called many times, passing @last_fd will avoid repeated searching
7822 # already-open FDs repeatedly if we know they are still in use.
7824 # usage: free_fd [last_fd]
7827 local max_fd=$(ulimit -n)
7828 local fd=$((${1:-2} + 1))
7830 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7833 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7837 check_mount_and_prep()
7839 is_mounted $MOUNT || setupall
7841 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7842 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7843 for idx in $(seq $MDSCOUNT); do
7844 local name="MDT$(printf '%04x' $((idx - 1)))"
7845 rm -rf $MOUNT/.lustre/lost+found/$name/*
7849 # calcule how many ost-objects to be created.
7850 precreated_ost_obj_count()
7854 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7855 local ost_name="OST$(printf '%04x' $ost_idx)"
7856 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7857 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7858 osp.$proc_path.prealloc_last_id)
7859 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7860 osp.$proc_path.prealloc_next_id)
7861 echo $((last_id - next_id + 1))
7864 check_file_in_pool()
7869 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7872 for t in $tlist ; do
7873 [ "$i" -eq "$t" ] && continue 2
7876 echo "pool list: $tlist"
7877 echo "striping: $res"
7878 error_noexit "$file not allocated in $pool"
7885 echo "Creating new pool"
7888 create_pool $FSNAME.$pool ||
7889 { error_noexit "No pool created, result code $?"; return 1; }
7890 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7891 { error_noexit "$pool not in lfs pool_list"; return 2; }
7894 pool_add_targets() {
7895 echo "Adding targets to pool"
7901 local list=$(seq $first $step $last)
7903 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7904 do_facet mgs $LCTL pool_add \
7905 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7907 # wait for OSTs to be added to the pool
7908 for mds_id in $(seq $MDSCOUNT); do
7909 local mdt_id=$((mds_id-1))
7910 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7911 wait_update_facet mds$mds_id \
7912 "lctl get_param -n lod.$lodname.pools.$pool |
7913 sort -u | tr '\n' ' ' " "$t" || {
7914 error_noexit "mds$mds_id: Add to pool failed"
7918 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7919 | sort -u | tr '\n' ' ' " "$t" || {
7920 error_noexit "Add to pool failed"
7923 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7924 local addcount=$(((last - first) / step + 1))
7925 [ $lfscount -eq $addcount ] || {
7926 error_noexit "lfs pool_list bad ost count" \
7927 "$lfscount != $addcount"
7935 echo "Setting pool on directory $tdir"
7937 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7939 error_noexit "Cannot set pool $pool to $tdir"
7946 echo "Checking pool on directory $tdir"
7948 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7949 [ "$res" = "$pool" ] && return 0
7951 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7955 pool_dir_rel_path() {
7956 echo "Testing relative path works well"
7961 mkdir -p $root/$tdir/$tdir
7963 pool_set_dir $pool $tdir || return 1
7964 pool_set_dir $pool ./$tdir || return 2
7965 pool_set_dir $pool ../$tdir || return 3
7966 pool_set_dir $pool ../$tdir/$tdir || return 4
7967 rm -rf $tdir; cd - > /dev/null
7970 pool_alloc_files() {
7971 echo "Checking files allocation from directory pool"
7978 for i in $(seq -w 1 $count)
7980 local file=$tdir/file-$i
7982 check_file_in_pool $file $pool "$tlist" || \
7983 failed=$((failed + 1))
7985 [ "$failed" = 0 ] && return 0
7987 error_noexit "$failed files not allocated in $pool"
7991 pool_create_files() {
7992 echo "Creating files in pool"
8000 for i in $(seq -w 1 $count)
8002 local file=$tdir/spoo-$i
8003 $SETSTRIPE -p $pool $file
8004 check_file_in_pool $file $pool "$tlist" || \
8005 failed=$((failed + 1))
8007 [ "$failed" = 0 ] && return 0
8009 error_noexit "$failed files not allocated in $pool"
8014 echo "Checking 'lfs df' output"
8017 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
8019 local res=$($LFS df --pool $FSNAME.$pool |
8021 grep "$FSNAME-OST" |
8023 [ "$res" = "$t" ] && return 0
8025 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
8029 pool_file_rel_path() {
8030 echo "Creating files in a pool with relative pathname"
8035 { error_noexit "unable to create $tdir"; return 1 ; }
8036 local file="/..$tdir/$tfile-1"
8037 $SETSTRIPE -p $pool $file ||
8038 { error_noexit "unable to create $file" ; return 2 ; }
8041 $SETSTRIPE -p $pool $tfile-2 || {
8042 error_noexit "unable to create $tfile-2 in $tdir"
8047 pool_remove_first_target() {
8048 echo "Removing first target from a pool"
8051 local pname="lov.$FSNAME-*.pools.$pool"
8052 local t=$($LCTL get_param -n $pname | head -1)
8053 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8054 for mds_id in $(seq $MDSCOUNT); do
8055 local mdt_id=$((mds_id-1))
8056 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8057 wait_update_facet mds$mds_id \
8058 "lctl get_param -n lod.$lodname.pools.$pool |
8060 error_noexit "mds$mds_id: $t not removed from" \
8065 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
8066 error_noexit "$t not removed from $FSNAME.$pool"
8071 pool_remove_all_targets() {
8072 echo "Removing all targets from pool"
8075 local pname="lov.$FSNAME-*.pools.$pool"
8076 for t in $($LCTL get_param -n $pname | sort -u)
8078 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8080 for mds_id in $(seq $MDSCOUNT); do
8081 local mdt_id=$((mds_id-1))
8082 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8083 wait_update_facet mds$mds_id "lctl get_param -n \
8084 lod.$lodname.pools.$pool" "" || {
8085 error_noexit "mds$mds_id: Pool $pool not drained"
8089 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
8090 error_noexit "Pool $FSNAME.$pool cannot be drained"
8093 # striping on an empty/nonexistant pool should fall back
8094 # to "pool of everything"
8096 error_noexit "failed to use fallback striping for empty pool"
8099 # setstripe on an empty pool should fail
8100 $SETSTRIPE -p $pool $file 2>/dev/null && {
8101 error_noexit "expected failure when creating file" \
8109 echo "Destroying pool"
8113 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
8116 # striping on an empty/nonexistant pool should fall back
8117 # to "pool of everything"
8119 error_noexit "failed to use fallback striping for missing pool"
8122 # setstripe on an empty pool should fail
8123 $SETSTRIPE -p $pool $file 2>/dev/null && {
8124 error_noexit "expected failure when creating file" \
8129 # get param should return err once pool is gone
8130 if wait_update $HOSTNAME "lctl get_param -n \
8131 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
8133 remove_pool_from_list $FSNAME.$pool
8136 error_noexit "Pool $FSNAME.$pool is not destroyed"
8140 # Get and check the actual stripe count of one file.
8141 # Usage: check_stripe_count <file> <expected_stripe_count>
8142 check_stripe_count() {
8147 [[ -z "$file" || -z "$expected" ]] &&
8148 error "check_stripe_count: invalid argument"
8150 local cmd="$GETSTRIPE -c $file"
8151 actual=$($cmd) || error "$cmd failed"
8152 actual=${actual%% *}
8154 if [[ $actual -ne $expected ]]; then
8155 [[ $expected -eq -1 ]] ||
8156 error "$cmd wrong: found $actual, expected $expected"
8157 [[ $actual -eq $OSTCOUNT ]] ||
8158 error "$cmd wrong: found $actual, expected $OSTCOUNT"
8162 # Get and check the actual list of OST indices on one file.
8163 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
8169 [[ -z "$file" || -z "$expected" ]] &&
8170 error "check_obdidx: invalid argument!"
8172 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
8173 grep -v obdidx | awk '{print $1}' | xargs))
8175 [[ $obdidx = $expected ]] ||
8176 error "list of OST indices on $file is $obdidx," \
8177 "should be $expected"
8180 # Get and check the actual OST index of the first stripe on one file.
8181 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
8182 check_start_ost_idx() {
8187 [[ -z "$file" || -z "$expected" ]] &&
8188 error "check_start_ost_idx: invalid argument!"
8190 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
8193 [[ $start_ost_idx = $expected ]] ||
8194 error "OST index of the first stripe on $file is" \
8195 "$start_ost_idx, should be $expected"
8198 killall_process () {
8199 local clients=${1:-$(hostname)}
8204 do_nodes $clients "killall $signal $name"
8209 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
8214 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
8219 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
8224 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
8229 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
8234 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
8241 do_facet mgs "cat $LSNAPSHOT_LOG"
8247 echo "Cleaning test environment ..."
8249 # Every lsnapshot command takes exclusive lock with others,
8250 # so can NOT destroy the snapshot during list with 'xargs'.
8252 local ssname=$(lsnapshot_list | grep snapshot_name |
8253 grep lss_ | awk '{ print $2 }' | head -n 1)
8254 [ -z "$ssname" ] && break
8256 lsnapshot_destroy -n $ssname -f ||
8257 lss_err "Fail to destroy $ssname by force"
8267 local host=$(facet_active_host $facet)
8268 local dir=$(dirname $(facet_vdevice $facet))
8269 local pool=$(zpool_name $facet)
8270 local lfsname=$(zfs_local_fsname $facet)
8271 local label=${FSNAME}-${role}$(printf '%04x' $idx)
8274 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
8280 do_facet mgs "rm -f $LSNAPSHOT_CONF"
8281 echo "Generating $LSNAPSHOT_CONF on MGS ..."
8283 if ! combined_mgs_mds ; then
8284 [ $(facet_fstype mgs) != zfs ] &&
8285 skip "Lustre snapshot 1 only works for ZFS backend" &&
8288 local host=$(facet_active_host mgs)
8289 local dir=$(dirname $(facet_vdevice mgs))
8290 local pool=$(zpool_name mgs)
8291 local lfsname=$(zfs_local_fsname mgs)
8294 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
8295 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
8298 for num in `seq $MDSCOUNT`; do
8299 [ $(facet_fstype mds$num) != zfs ] &&
8300 skip "Lustre snapshot 1 only works for ZFS backend" &&
8303 lss_gen_conf_one mds$num MDT $((num - 1)) ||
8304 lss_err "generate lss conf (mds$num)"
8307 for num in `seq $OSTCOUNT`; do
8308 [ $(facet_fstype ost$num) != zfs ] &&
8309 skip "Lustre snapshot 1 only works for ZFS backend" &&
8312 lss_gen_conf_one ost$num OST $((num - 1)) ||
8313 lss_err "generate lss conf (ost$num)"
8316 do_facet mgs "cat $LSNAPSHOT_CONF"
8322 local val=$(awk '{print $2}' <<< $line)
8324 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
8326 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
8328 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
8333 parse_layout_param()
8340 if [[ -z $mode ]]; then
8341 if [[ $line =~ ^"stripe_count:" ]]; then
8343 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
8345 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
8350 if [[ $mode = "plain_dir" ]]; then
8351 param=$(echo $line |
8352 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
8353 elif [[ $mode = "plain_file" ]]; then
8354 val=$(parse_plain_param "$line")
8355 [[ ! -z $val ]] && param="$param $val"
8356 elif [[ $mode = "pfl" ]]; then
8357 val=$(echo $line | awk '{print $2}')
8358 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
8359 if [[ $val = "EOF" ]]; then
8360 param="$param -E -1"
8362 param="$param -E $val"
8364 elif [[ $line =~ ^"stripe_count:" ]]; then
8367 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
8371 val=$(parse_plain_param "$line")
8372 [[ ! -z $val ]] && param="$param $val"
8381 local param=$($LFS getstripe -d $1 | parse_layout_param)