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}
444 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
445 $LCTL lustre_build_version 2>/dev/null ||
446 $LCTL --version 2>/dev/null | cut -d' ' -f2")
447 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
448 [ -n "$lver" ] && ver="$lver"
450 sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' -e 's/_/./g' <<<$ver |
454 # Report the Lustre numeric build version code for the supplied facet.
455 lustre_version_code() {
456 version_code $(lustre_build_version $1)
460 /sbin/lsmod | grep -q "^\<$1\>"
472 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
475 # parallels can't load modules directly from prlfs, use /tmp instead
476 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
477 local target="$(mktemp)"
479 cp "$module" "$target"
482 [[ $rc == 0 ]] && PRLFS=true
490 # Load a module on the system where this is running.
492 # usage: load_module module_name [module arguments for insmod/modprobe]
494 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
495 # will be used as the arguments. Otherwise arguments will be obtained from
496 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
503 BASE=$(basename $module $EXT)
505 module_loaded ${BASE} && return
507 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
508 # else from modprobe.conf
509 if [ $# -eq 0 ]; then
510 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
511 # Bash until 4.x, so we resort to eval.
512 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
513 eval set -- \$$optvar
514 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
515 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
517 opt=$(awk -v var="^options $BASE" '$0 ~ var \
518 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
519 set -- $(echo -n $opt)
521 # Ensure we have accept=all for lnet
522 if [ $(basename $module) = lnet ]; then
523 # OK, this is a bit wordy...
524 local arg accept_all_present=false
527 [ "$arg" = accept=all ] && \
528 accept_all_present=true
530 $accept_all_present || set -- "$@" accept=all
536 [ $# -gt 0 ] && echo "${module} options: '$*'"
538 # Note that insmod will ignore anything in modprobe.conf, which is why
539 # we're passing options on the command-line.
540 if [[ "$BASE" == "lnet_selftest" ]] &&
541 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
542 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
543 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
544 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
545 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
547 # must be testing a "make install" or "rpm" installation
548 # note failed to load ptlrpc_gss is considered not fatal
549 if [[ "$BASE" == "ptlrpc_gss" ]]; then
550 modprobe $BASE "$@" 2>/dev/null ||
551 echo "gss/krb5 is not supported"
558 load_modules_local() {
559 if [ -n "$MODPROBE" ]; then
561 echo "Using modprobe to load modules"
565 echo Loading modules from $LUSTRE
569 if [ -f /sys/devices/system/cpu/online ]; then
570 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
571 echo "detected $ncpus online CPUs by sysfs"
573 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
575 if [ $rc -eq 0 ]; then
576 echo "detected $ncpus online CPUs by getconf"
578 echo "Can't detect number of CPUs"
583 # if there is only one CPU core, libcfs can only create one partition
584 # if there is more than 4 CPU cores, libcfs should create multiple CPU
585 # partitions. So we just force libcfs to create 2 partitions for
586 # system with 2 or 4 cores
587 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
588 # force to enable multiple CPU partitions
589 echo "Force libcfs to create 2 CPU partitions"
590 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
592 echo "libcfs will create CPU partition based on online CPUs"
595 load_module ../libcfs/libcfs/libcfs
596 # Prevent local MODOPTS_LIBCFS being passed as part of environment
597 # variable to remote nodes
601 load_module ../lnet/lnet/lnet
603 LNDPATH=${LNDPATH:-"../lnet/klnds"}
604 if [ -z "$LNETLND" ]; then
606 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
607 tcp*) LNETLND="socklnd/ksocklnd" ;;
608 *) local lnd="${NETTYPE%%[0-9]}lnd"
609 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
610 LNETLND="$lnd/k$lnd" ||
611 LNETLND="socklnd/ksocklnd"
614 load_module ../lnet/klnds/$LNETLND
615 load_module obdclass/obdclass
616 load_module ptlrpc/ptlrpc
617 load_module ptlrpc/gss/ptlrpc_gss
625 load_module obdecho/obdecho
626 if ! client_only; then
627 SYMLIST=/proc/kallsyms
628 grep -q crc16 $SYMLIST ||
629 { modprobe crc16 2>/dev/null || true; }
630 grep -q -w jbd2 $SYMLIST ||
631 { modprobe jbd2 2>/dev/null || true; }
632 load_module lfsck/lfsck
633 [ "$LQUOTA" != "no" ] &&
634 load_module quota/lquota $LQUOTAOPTS
635 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
636 lsmod | grep zfs >&/dev/null || modprobe zfs
637 load_module osd-zfs/osd_zfs
639 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
640 grep -q exportfs_decode_fh $SYMLIST ||
641 { modprobe exportfs 2> /dev/null || true; }
642 grep -q -w mbcache $SYMLIST ||
643 { modprobe mbcache 2>/dev/null || true; }
644 load_module ../ldiskfs/ldiskfs
645 load_module osd-ldiskfs/osd_ldiskfs
657 load_module llite/lustre
658 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
660 rm -f $OGDB/ogdb-$HOSTNAME
661 $LCTL modules > $OGDB/ogdb-$HOSTNAME
663 # 'mount' doesn't look in $PATH, just sbin
664 local mount_lustre=$LUSTRE/utils/mount.lustre
665 if [ -f $mount_lustre ]; then
666 local sbin_mount=$(readlink -f /sbin)/mount.lustre
667 if grep -qw "$sbin_mount" /proc/mounts; then
668 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
670 if ! grep -qw "$sbin_mount" /proc/mounts; then
671 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
672 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
673 cat <<- EOF > "$sbin_mount"
676 echo "This $sbin_mount just a mountpoint." 1>&2
677 echo "It is never supposed to be run." 1>&2
678 logger -p emerg -- "using stub $sbin_mount $@"
681 chmod a+x $sbin_mount
683 mount --bind $mount_lustre $sbin_mount ||
684 error "can't bind $mount_lustre to $sbin_mount"
692 # load modules on remote nodes optionally
693 # lustre-tests have to be installed on these nodes
694 if $LOAD_MODULES_REMOTE; then
695 local list=$(comma_list $(remote_nodes_list))
696 if [ -n "$list" ]; then
697 echo "loading modules on: '$list'"
698 do_rpc_nodes "$list" load_modules_local
704 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
705 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
706 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
707 echo "$LEAK_LUSTRE" 1>&2
708 echo "$LEAK_PORTALS" 1>&2
709 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
710 echo "Memory leaks detected"
711 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
717 wait_exit_ST client # bug 12845
719 $LUSTRE_RMMOD ldiskfs || return 2
721 if $LOAD_MODULES_REMOTE; then
722 local list=$(comma_list $(remote_nodes_list))
723 if [ -n "$list" ]; then
724 echo "unloading modules on: '$list'"
725 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
726 do_rpc_nodes "$list" check_mem_leak
730 local sbin_mount=$(readlink -f /sbin)/mount.lustre
731 if grep -qe "$sbin_mount " /proc/mounts; then
732 umount $sbin_mount || true
733 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
737 check_mem_leak || return 254
739 echo "modules unloaded."
744 local facet=${1:-$SINGLEMDS}
745 local fstype=$(facet_fstype $facet)
748 ldiskfs) size=50;; # largest seen is 44, leave some headroom
749 zfs) size=512;; # largest seen is 512
756 local facet=${1:-$SINGLEMDS}
757 local fstype=$(facet_fstype $facet)
760 ldiskfs) size=4;; # ~4KB per inode
761 zfs) size=11;; # 10 to 11KB per inode
767 check_gss_daemon_nodes() {
771 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
772 if [ \\\"\\\$num\\\" -ne 1 ]; then
773 echo \\\$num instance of $dname;
778 check_gss_daemon_facet() {
782 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
783 if [ $num -ne 1 ]; then
784 echo "$num instance of $dname on $facet"
793 echo Stopping $@ on $list
794 do_nodes $list "killall -2 $@ 2>/dev/null || true"
797 # start gss daemons on all nodes, or "daemon" on "nodes" if set
798 start_gss_daemons() {
802 if [ "$nodes" ] && [ "$daemon" ] ; then
803 echo "Starting gss daemon on nodes: $nodes"
804 do_nodes $nodes "$daemon" || return 8
808 nodes=$(comma_list $(mdts_nodes))
809 echo "Starting gss daemon on mds: $nodes"
811 # Start all versions, in case of switching
812 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
814 do_nodes $nodes "$LSVCGSSD -v" || return 1
817 do_nodes $nodes "$LGSSD -v" || return 2
820 nodes=$(comma_list $(osts_nodes))
821 echo "Starting gss daemon on ost: $nodes"
823 # Start all versions, in case of switching
824 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
826 do_nodes $nodes "$LSVCGSSD -v" || return 3
828 # starting on clients
830 local clients=${CLIENTS:-$HOSTNAME}
832 echo "Starting $LGSSD on clients $clients "
833 do_nodes $clients "$LGSSD -v" || return 4
836 # wait daemons entering "stable" status
840 # check daemons are running
842 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
843 check_gss_daemon_nodes $nodes lsvcgssd || return 5
845 nodes=$(comma_list $(mdts_nodes))
846 check_gss_daemon_nodes $nodes lgssd || return 6
849 check_gss_daemon_nodes $clients lgssd || return 7
854 local nodes=$(comma_list $(mdts_nodes))
856 send_sigint $nodes lsvcgssd lgssd
858 nodes=$(comma_list $(osts_nodes))
859 send_sigint $nodes lsvcgssd
861 nodes=${CLIENTS:-$HOSTNAME}
862 send_sigint $nodes lgssd
866 # Add mount flags for shared key
868 if grep -q skpath <<< "$mt_opts" ; then
869 mt_opts=$(echo $mt_opts |
870 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
872 if [ -z "$mt_opts" ]; then
873 mt_opts="-o skpath=$SK_PATH"
875 mt_opts="$mt_opts,skpath=$SK_PATH"
891 if ! module_loaded ptlrpc_gss; then
892 load_module ptlrpc/gss/ptlrpc_gss
893 module_loaded ptlrpc_gss ||
894 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
897 if $GSS_KRB5 || $GSS_SK; then
898 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
901 if $GSS_SK && $SK_NO_KEY; then
902 local numclients=${1:-$CLIENTCOUNT}
903 local clients=${CLIENTS:-$HOSTNAME}
905 # security ctx config for keyring
908 mount -o bind $SK_OM_PATH /etc/request-key.d/
909 local lgssc_conf_line='create lgssc * * '
910 lgssc_conf_line+=$(which lgss_keyring)
911 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
913 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
914 echo "$lgssc_conf_line" > $lgssc_conf_file
915 [ -e $lgssc_conf_file ] ||
916 error_exit "Could not find key options in $lgssc_conf_file"
918 if ! local_mode; then
919 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
921 do_nodes $(comma_list $(all_nodes)) "mount \
922 -o bind $SK_OM_PATH \
924 do_nodes $(comma_list $(all_nodes)) "rsync -aqv \
925 $HOSTNAME:$lgssc_conf_file \
926 $lgssc_conf_file >/dev/null 2>&1"
929 # create shared key on all nodes
930 mkdir -p $SK_PATH/nodemap
931 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
932 $SK_PATH/$FSNAME-*.key
933 # for nodemap testing each client may need own key,
934 # and S2S now requires keys as well, both for "client"
937 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
938 -w $SK_PATH/$FSNAME-nmclient.key \
939 -d /dev/urandom >/dev/null 2>&1
940 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
941 -w $SK_PATH/$FSNAME-s2s-server.key \
942 -d /dev/urandom >/dev/null 2>&1
945 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
946 -d /dev/urandom >/dev/null 2>&1
948 for i in $(seq 0 $((numclients - 1))); do
949 lgss_sk -t server -f$FSNAME -n c$i \
950 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
954 if ! local_mode; then
955 do_nodes $(comma_list $(all_nodes)) "rsync -av \
956 $HOSTNAME:$SK_PATH/ $SK_PATH >/dev/null 2>&1"
958 # Set client keys to client type to generate prime P
960 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
961 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
963 do_nodes $clients "lgss_sk -t client -m \
964 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
965 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
966 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
968 # This is required for servers as well, if S2S in use
970 do_nodes $(comma_list $(mdts_nodes)) \
971 "cp $SK_PATH/$FSNAME-s2s-server.key \
972 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
973 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
975 do_nodes $(comma_list $(osts_nodes)) \
976 "cp $SK_PATH/$FSNAME-s2s-server.key \
977 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
978 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
980 do_nodes $clients "lgss_sk -t client \
981 -m $SK_PATH/$FSNAME-nmclient.key \
984 # mount options for servers and clients
985 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
986 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
987 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
988 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
992 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
994 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1001 # maybe cleanup credential cache?
1008 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1009 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1010 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1014 $RPC_MODE || echo "Cleaning up Shared Key.."
1015 do_nodes $(comma_list $(all_nodes)) "rm -f \
1016 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1017 # Remove the mount and clean up the files we added to SK_PATH
1018 do_nodes $(comma_list $(all_nodes)) "umount \
1019 /etc/request-key.d/"
1020 do_nodes $(comma_list $(all_nodes)) "rm -f \
1021 $SK_OM_PATH/lgssc.conf"
1022 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1029 local var=${facet}_svc
1037 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1038 tr '[:lower:]' '[:upper:]'
1044 if [ $facet == mgs ] || [ $facet == client ]; then
1048 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1056 if [ -n "${!var}" ]; then
1061 var=$(facet_type $facet)FSTYPE
1062 if [ -n "${!var}" ]; then
1067 if [ -n "$FSTYPE" ]; then
1072 if [[ $facet == mgs ]] && combined_mgs_mds; then
1084 local facets=$(get_facets)
1087 for facet in ${facets//,/ }; do
1088 if [ $node == $(facet_host $facet) ] ||
1089 [ $node == "$(facet_failover_host $facet)" ]; then
1090 fstype=$(facet_fstype $facet)
1091 if [[ $fstypes != *$fstype* ]]; then
1092 fstypes+="${fstypes:+,}$fstype"
1101 local num=$(facet_number $facet)
1104 if [[ $(facet_type $facet) = OST ]]; then
1105 index=OSTINDEX${num}
1106 if [[ -n "${!index}" ]]; then
1111 index=${OST_INDICES[num - 1]}
1114 [[ -n "$index" ]] || index=$((num - 1))
1122 local fstype=$(facet_fstype $facet)
1126 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1128 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1129 ${dev} 2>/dev/null");;
1131 error "unknown fstype!";;
1139 local device=$(mdsdevname $num)
1140 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
1146 local device=$(ostdevname $num)
1147 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
1152 # Get the device of a facet.
1159 mgs) device=$(mgsdevname) ;;
1160 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1161 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1162 fs2mds) device=$(mdsdevname 1_2) ;;
1163 fs2ost) device=$(ostdevname 1_2) ;;
1164 fs3ost) device=$(ostdevname 2_2) ;;
1172 # Get the virtual device of a facet.
1179 mgs) device=$(mgsvdevname) ;;
1180 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1181 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1182 fs2mds) device=$(mdsvdevname 1_2) ;;
1183 fs2ost) device=$(ostvdevname 1_2) ;;
1184 fs3ost) device=$(ostvdevname 2_2) ;;
1192 local virt=$(virt-what 2> /dev/null)
1194 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1196 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1199 VMware|KVM|VirtualBox|Parallels)
1200 echo $virt | tr '[A-Z]' '[a-z]' ;;
1206 # Re-read the partition table on failover partner host.
1207 # After a ZFS storage pool is created on a shared device, the partition table
1208 # on the device may change. However, the operating system on the failover
1209 # host may not notice the change automatically. Without the up-to-date partition
1210 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1211 # relative to partition rather than disk beginnings.
1213 # This function performs partprobe on the failover host to make it re-read the
1216 refresh_partition_table() {
1221 host=$(facet_passive_host $facet)
1222 if [[ -n "$host" ]]; then
1223 do_node $host "$PARTPROBE $device"
1228 # Get ZFS storage pool name.
1235 device=$(facet_device $facet)
1236 # poolname is string before "/"
1237 poolname="${device%%/*}"
1244 # Get ZFS local fsname.
1246 zfs_local_fsname() {
1248 local lfsname=$(basename $(facet_device $facet))
1254 # Create ZFS storage pool.
1261 local opts=${@:-"-o cachefile=none"}
1263 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1264 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1265 $ZPOOL create -f $opts $poolname $vdev"
1269 # Create ZFS file system.
1275 local opts=${@:-"-o mountpoint=legacy"}
1277 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1278 $ZFS create $opts $dataset"
1282 # Export ZFS storage pool.
1283 # Before exporting the pool, all datasets within the pool should be unmounted.
1291 poolname=$(zpool_name $facet)
1293 if [[ -n "$poolname" ]]; then
1294 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1295 grep -q ^$poolname/ /proc/mounts ||
1296 $ZPOOL export $opts $poolname"
1301 # Destroy ZFS storage pool.
1302 # Destroy the given pool and free up any devices for other use. This command
1303 # tries to unmount any active datasets before destroying the pool.
1304 # -f Force any active datasets contained within the pool to be unmounted.
1308 local poolname=${2:-$(zpool_name $facet)}
1310 if [[ -n "$poolname" ]]; then
1311 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1312 $ZPOOL destroy -f $poolname"
1317 # Import ZFS storage pool.
1318 # Force importing, even if the pool appears to be potentially active.
1323 local opts=${@:-"-o cachefile=none"}
1326 poolname=$(zpool_name $facet)
1328 if [[ -n "$poolname" ]]; then
1329 opts+=" -d $(dirname $(facet_vdevice $facet))"
1330 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1331 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1332 $ZPOOL import -f $opts $poolname"
1337 # Reimport ZFS storage pool with new name
1342 local opts="-o cachefile=none"
1343 local poolname=$(zpool_name $facet)
1345 opts+=" -d $(dirname $(facet_vdevice $facet))"
1346 do_facet $facet "$ZPOOL export $poolname;
1347 $ZPOOL import $opts $poolname $newpool"
1351 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1352 # is not automatically imported on system startup.
1354 # In a failover environment, this will provide resource level fencing which
1355 # will ensure that the same ZFS storage pool will not be imported concurrently
1356 # on different nodes.
1358 disable_zpool_cache() {
1362 poolname=$(zpool_name $facet)
1364 if [[ -n "$poolname" ]]; then
1365 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1370 # This and set_osd_param() shall be used to access OSD parameters
1371 # once existed under "obdfilter":
1376 # writethrough_cache_enable
1380 local device=${2:-$FSNAME-OST*}
1383 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1384 osd-*.$device.$name 2>&1" | grep -v 'error:'
1389 local device=${2:-$FSNAME-OST*}
1393 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1394 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1398 local dz=${1:-$DEBUG_SIZE}
1400 if [ -f /sys/devices/system/cpu/possible ]; then
1401 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1403 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1406 # bug 19944, adjust size to be -gt num_possible_cpus()
1407 # promise 2MB for every cpu at least
1408 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1411 lctl set_param debug_mb=$dz
1414 set_default_debug () {
1415 local debug=${1:-"$PTLDEBUG"}
1416 local subsys=${2:-"$SUBSYSTEM"}
1417 local debug_size=${3:-$DEBUG_SIZE}
1419 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1420 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1422 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1425 set_default_debug_nodes () {
1428 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1429 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1433 do_rpc_nodes "$nodes" set_default_debug \
1434 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1437 set_default_debug_facet () {
1439 local node=$(facet_active_host $facet)
1440 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1442 set_default_debug_nodes $node
1446 local hostid=${1:-$(hostid)}
1448 if [ ! -s /etc/hostid ]; then
1449 printf $(echo -n $hostid |
1450 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1456 local facets=${1:-$(get_facets)}
1459 for facet in ${facets//,/ }; do
1462 [ $RC -eq 0 ] && continue
1464 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1465 skip "Restart of $facet failed!." && touch $LU482_FAILED
1467 error "Restart of $facet failed!"
1474 # Add argument "arg" (e.g., "loop") to the comma-separated list
1475 # of arguments for option "opt" (e.g., "-o") on command
1476 # line "opts" (e.g., "-o flock").
1482 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1484 if echo "$opts" | grep -q $opt_pattern; then
1485 opts=$(echo "$opts" | sed -e \
1486 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1488 opts+="${opts:+ }$opt $arg"
1496 local dev=$(facet_active $facet)_dev
1497 local opt=${facet}_opt
1498 local mntpt=$(facet_mntpt $facet)
1499 local opts="${!opt} $@"
1500 local fstype=$(facet_fstype $facet)
1503 module_loaded lustre || load_modules
1505 if [ $(facet_fstype $facet) == ldiskfs ] &&
1506 ! do_facet $facet test -b ${!dev}; then
1507 opts=$(csa_add "$opts" -o loop)
1510 if [[ $(facet_fstype $facet) == zfs ]]; then
1511 # import ZFS storage pool
1512 import_zpool $facet || return ${PIPESTATUS[0]}
1517 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1519 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1520 lustre:svname ${!dev}");;
1522 error "unknown fstype!";;
1525 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1526 # for testing LU-482 error handling in mount_facets() and test_0a()
1527 if [ -f $TMP/test-lu482-trigger ]; then
1530 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1535 if [ $RC -ne 0 ]; then
1536 echo "Start of ${!dev} on ${facet} failed ${RC}"
1540 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1541 if [[ "$health" != "healthy" ]]; then
1542 error "$facet is in a unhealthy state"
1545 set_default_debug_facet $facet
1547 if [[ $facet == mds* ]]; then
1549 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1552 if [[ $opts =~ .*nosvc.* ]]; then
1553 echo "Start ${!dev} without service"
1558 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1559 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1560 "" || error "${!dev} failed to initialize!";;
1562 wait_update_facet ${facet} "$ZFS get -H -o value \
1563 lustre:svname ${!dev} 2>/dev/null | \
1564 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1565 error "${!dev} failed to initialize!";;
1568 error "unknown fstype!";;
1572 # commit the device label change to disk
1573 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1574 echo "Commit the device label on ${!dev}"
1575 do_facet $facet "sync; sleep 1; sync"
1579 label=$(devicelabel ${facet} ${!dev})
1580 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1581 eval export ${facet}_svc=${label}
1582 echo Started ${label}
1587 # start facet device options
1593 eval export ${facet}_dev=${device}
1594 eval export ${facet}_opt=\"$@\"
1596 local varname=${facet}failover_dev
1597 if [ -n "${!varname}" ] ; then
1598 eval export ${facet}failover_dev=${!varname}
1600 eval export ${facet}failover_dev=$device
1603 local mntpt=$(facet_mntpt $facet)
1604 do_facet ${facet} mkdir -p $mntpt
1605 eval export ${facet}_MOUNT=$mntpt
1606 mount_facet ${facet}
1609 if [[ $facet == mds* ]]; then
1611 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1622 local HOST=`facet_active_host $facet`
1623 [ -z $HOST ] && echo stop: no host for $facet && return 0
1625 local mntpt=$(facet_mntpt $facet)
1626 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1627 if [ ${running} -ne 0 ]; then
1628 echo "Stopping $mntpt (opts:$@) on $HOST"
1629 do_facet ${facet} $UMOUNT $@ $mntpt
1632 # umount should block, but we should wait for unrelated obd's
1633 # like the MGS or MGC to also stop.
1634 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1636 if [[ $(facet_fstype $facet) == zfs ]]; then
1637 # export ZFS storage pool
1638 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1642 # save quota version (both administrative and operational quotas)
1643 # add an additional parameter if mountpoint is ever different from $MOUNT
1645 # XXX This function is kept for interoperability with old server (< 2.3.50),
1646 # it should be removed whenever we drop the interoperability for such
1648 quota_save_version() {
1649 local fsname=${2:-$FSNAME}
1651 local ver=$(tr -c -d "123" <<< $spec)
1652 local type=$(tr -c -d "ug" <<< $spec)
1654 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1656 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1658 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1660 local osts=$(get_facets OST)
1661 for ost in ${osts//,/ }; do
1663 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1667 # client could mount several lustre
1669 # XXX This function is kept for interoperability with old server (< 2.3.50),
1670 # it should be removed whenever we drop the interoperability for such
1673 local fsname=${1:-$FSNAME}
1675 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1677 do_nodes $(comma_list $(osts_nodes)) \
1678 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1682 # get mdt quota type
1684 local varsvc=${SINGLEMDS}_svc
1685 do_facet $SINGLEMDS $LCTL get_param -n \
1686 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1689 # get ost quota type
1691 # All OSTs should have same quota type
1692 local varsvc=ost1_svc
1693 do_facet ost1 $LCTL get_param -n \
1694 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1697 # restore old quota type settings
1699 if [ "$old_MDT_QUOTA_TYPE" ]; then
1700 do_facet mgs $LCTL conf_param \
1701 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1703 if [ "$old_OST_QUOTA_TYPE" ]; then
1704 do_facet mgs $LCTL conf_param \
1705 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1709 # Handle the case when there is a space in the lfs df
1710 # "filesystem summary" line the same as when there is no space.
1711 # This will allow fixing the "lfs df" summary line in the future.
1713 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1716 # Get free inodes on the MDT specified by mdt index, free indoes on
1717 # the whole filesystem will be returned when index == -1.
1723 if [ $index -eq -1 ]; then
1726 mdt_uuid=$(mdtuuid_from_index $index)
1729 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1734 # Get the OST device status from 'lfs df' with a given OST index.
1738 local mnt_pnt=${2:-$MOUNT}
1741 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1742 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1748 # save old quota type & set new quota type
1749 local mdt_qtype=$(mdt_quota_type)
1750 local ost_qtype=$(ost_quota_type)
1752 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1753 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1755 export old_MDT_QUOTA_TYPE=$mdt_qtype
1756 export old_OST_QUOTA_TYPE=$ost_qtype
1758 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1759 error "set mdt quota type failed"
1760 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1761 error "set ost quota type failed"
1763 local quota_usrs=$QUOTA_USERS
1765 # get_filesystem_size
1766 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1767 local blk_soft=$((disksz + 1024))
1768 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1770 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1771 local i_soft=$inodes
1772 local i_hard=$((i_soft + i_soft / 20))
1774 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1775 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1776 "inode-hardlimit: $i_hard"
1779 for usr in $quota_usrs; do
1780 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1782 cmd="$LFS setquota -$type $usr -b $blk_soft"
1783 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1785 eval $cmd || error "$cmd FAILED!"
1787 # display the quota status
1788 echo "Quota settings for $usr : "
1789 $LFS quota -v -u $usr $mntpt || true
1796 local opts=${3:-$MOUNT_OPTS}
1797 opts=${opts:+-o $opts}
1798 local flags=${4:-$MOUNT_FLAGS}
1800 local device=$MGSNID:/$FSNAME$FILESET
1801 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1802 echo "Bad mount command: opt=$flags $opts dev=$device " \
1807 echo "Starting client: $client: $flags $opts $device $mnt"
1808 do_node $client mkdir -p $mnt
1809 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1810 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1812 #disable FILESET if not supported
1813 do_nodes $client lctl get_param -n \
1814 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1815 device=$MGSNID:/$FSNAME
1816 do_node $client mkdir -p $mnt/$FILESET
1817 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1820 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1821 # Mount using nodemap key
1822 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1823 if $SK_UNIQUE_NM; then
1824 mountkey=$SK_PATH/nodemap/c0.key
1826 local prunedopts=$(echo $opts |
1827 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
1828 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
1831 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
1835 set_default_debug_nodes $client
1847 [ "$3" ] && force=-f
1848 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1849 if [ $running -ne 0 ]; then
1850 echo "Stopping client $client $mnt (opts:$force)"
1851 do_node $client lsof -t $mnt || need_kill=no
1852 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1853 pids=$(do_node $client lsof -t $mnt | sort -u);
1854 if [ -n $pids ]; then
1855 do_node $client kill -9 $pids || true
1859 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1860 if [ $busy -ne 0 ] ; then
1861 echo "$mnt is still busy, wait one second" && sleep 1
1862 do_node $client umount $force $mnt
1867 # nodes is comma list
1868 sanity_mount_check_nodes () {
1874 # FIXME: assume that all cluster nodes run the same os
1875 [ "$(uname)" = Linux ] || return 0
1878 for mnt in $mnts ; do
1879 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1880 mpts=\\\$(mount | grep -c $mnt' ');
1881 if [ \\\$running -ne \\\$mpts ]; then
1882 echo \\\$(hostname) env are INSANE!;
1885 [ $? -eq 0 ] || rc=1
1890 sanity_mount_check_servers () {
1891 [ -n "$CLIENTONLY" ] &&
1892 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1893 echo Checking servers environments
1895 # FIXME: modify get_facets to display all facets wo params
1896 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1900 for facet in ${facets//,/ }; do
1901 node=$(facet_host ${facet})
1902 mntpt=$(facet_mntpt $facet)
1903 sanity_mount_check_nodes $node $mntpt ||
1904 { error "server $node environments are insane!"; return 1; }
1908 sanity_mount_check_clients () {
1909 local clients=${1:-$CLIENTS}
1910 local mntpt=${2:-$MOUNT}
1911 local mntpt2=${3:-$MOUNT2}
1913 [ -z $clients ] && clients=$(hostname)
1914 echo Checking clients $clients environments
1916 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1917 error "clients environments are insane!"
1920 sanity_mount_check () {
1921 sanity_mount_check_servers || return 1
1922 sanity_mount_check_clients || return 2
1925 # mount clients if not mouted
1926 zconf_mount_clients() {
1929 local opts=${3:-$MOUNT_OPTS}
1930 opts=${opts:+-o $opts}
1931 local flags=${4:-$MOUNT_FLAGS}
1932 local device=$MGSNID:/$FSNAME$FILESET
1933 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1934 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1939 echo "Starting client $clients: $flags $opts $device $mnt"
1940 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1941 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1942 # Mount with own nodemap key
1944 # Mount all server nodes first with per-NM keys
1945 for nmclient in ${clients//,/ }; do
1946 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
1947 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
1950 # set perms for per-nodemap keys else permission denied
1951 do_nodes $(comma_list $(all_nodes)) \
1952 "keyctl show | grep lustre | cut -c1-11 |
1954 xargs -IX keyctl setperm X 0x3f3f3f3f"
1955 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1957 for nmclient in ${clients//,/ }; do
1958 if $SK_UNIQUE_NM; then
1959 mountkey=$SK_PATH/nodemap/c$i.key
1961 do_node $nmclient "! grep -q $mnt' ' \
1962 /proc/mounts || umount $mnt"
1963 local prunedopts=$(add_sk_mntflag $prunedopts);
1964 prunedopts=$(echo $prunedopts | sed -e \
1965 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
1967 do_nodes $(comma_list $(all_server_nodes)) \
1970 do_node $nmclient $MOUNT_CMD $flags \
1971 $prunedopts $MGSNID:/$FSNAME $mnt ||
1976 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1978 do_nodes $clients $MOUNT_CMD $flags $opts \
1979 $MGSNID:/$FSNAME $mnt || return 1
1981 #disable FILESET if not supported
1982 do_nodes $clients lctl get_param -n \
1983 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1984 device=$MGSNID:/$FSNAME
1985 do_nodes $clients mkdir -p $mnt/$FILESET
1986 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1990 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
1991 # Mount with nodemap key
1993 local mountkey=$SK_PATH/$FSNAME-nmclient.key
1994 for nmclient in ${clients//,/ }; do
1995 if $SK_UNIQUE_NM; then
1996 mountkey=$SK_PATH/nodemap/c$i.key
1998 local prunedopts=$(echo $opts | sed -e \
1999 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2000 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2003 running=\\\$(mount | grep -c $mnt' ');
2005 if [ \\\$running -eq 0 ] ; then
2007 $MOUNT_CMD $flags $prunedopts $device $mnt;
2010 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2011 grep 'type lustre' | wc -l);
2012 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2013 echo zconf_mount_clients FAILED: \
2014 mount count \\\$running, not matching \
2015 with mount count of 'type lustre' \
2016 \\\$lustre_mnt_count;
2020 exit \\\$rc" || return ${PIPESTATUS[0]}
2027 if $SHARED_KEY; then
2028 tmpopts=$(add_sk_mntflag $opts)
2031 running=\\\$(mount | grep -c $mnt' ');
2033 if [ \\\$running -eq 0 ] ; then
2035 $MOUNT_CMD $flags $tmpopts $device $mnt;
2038 exit \\\$rc" || return ${PIPESTATUS[0]}
2041 echo "Started clients $clients: "
2042 do_nodes $clients "mount | grep $mnt' '"
2044 set_default_debug_nodes $clients
2049 zconf_umount_clients() {
2054 [ "$3" ] && force=-f
2056 echo "Stopping clients: $clients $mnt (opts:$force)"
2057 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2058 if [ \\\$running -ne 0 ] ; then
2059 echo Stopping client \\\$(hostname) $mnt opts:$force;
2060 lsof $mnt || need_kill=no;
2061 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2062 pids=\\\$(lsof -t $mnt | sort -u);
2063 if [ -n \\\"\\\$pids\\\" ]; then
2067 while umount $force $mnt 2>&1 | grep -q "busy"; do
2068 echo "$mnt is still busy, wait one second" && sleep 1;
2075 echo + $POWER_DOWN $node
2079 shutdown_node_hard () {
2081 local attempts=$SHUTDOWN_ATTEMPTS
2083 for i in $(seq $attempts) ; do
2086 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2087 echo "waiting for $host to fail attempts=$attempts"
2088 [ $i -lt $attempts ] || \
2089 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2095 local mnt=${2:-$MOUNT}
2098 if [ "$FAILURE_MODE" = HARD ]; then
2099 shutdown_node_hard $client
2101 zconf_umount_clients $client $mnt -f
2107 local facets="$(get_facets OST),$(get_facets MDS)"
2110 combined_mgs_mds || facets="$facets,mgs"
2112 for facet in ${facets//,/ }; do
2113 if [ $(facet_active_host $facet) == $host ]; then
2114 affected="$affected $facet"
2118 echo $(comma_list $affected)
2123 local host=${2:-$(facet_host $facet)}
2125 local label=$(convert_facet2label $facet)
2126 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2129 facets_up_on_host () {
2131 local facets=$(facets_on_host $host)
2134 for facet in ${facets//,/ }; do
2135 if $(facet_up $facet $host); then
2136 affected_up="$affected_up $facet"
2140 echo $(comma_list $affected_up)
2146 if [ "$FAILURE_MODE" = HARD ]; then
2147 shutdown_node_hard $(facet_active_host $facet)
2155 echo + $POWER_UP $node
2168 if [ "$FAILURE_MODE" = HARD ]; then
2169 reboot_node $(facet_active_host $facet)
2177 if [ "$FAILURE_MODE" = HARD ]; then
2187 for facet in ${facets//,/ }; do
2188 hosts=$(expand_list $hosts $(facet_host $facet) )
2194 _check_progs_installed () {
2198 for prog in $progs; do
2199 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2200 echo $prog missing on $(hostname)
2207 check_progs_installed () {
2211 do_rpc_nodes "$nodes" _check_progs_installed $@
2214 # recovery-scale functions
2216 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2219 start_client_load() {
2222 local var=$(node_var_name $client)_load
2223 eval export ${var}=$load
2225 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2226 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2227 END_RUN_FILE=$END_RUN_FILE \
2228 LOAD_PID_FILE=$LOAD_PID_FILE \
2229 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2230 TESTNAME=$TESTNAME \
2231 DBENCH_LIB=$DBENCH_LIB \
2232 DBENCH_SRC=$DBENCH_SRC \
2233 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2239 log "Started client load: ${load} on $client"
2241 # get the children process IDs
2242 local pids=$(ps --ppid $ppid -o pid= | xargs)
2243 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2247 start_client_loads () {
2248 local -a clients=(${1//,/ })
2249 local numloads=${#CLIENT_LOADS[@]}
2252 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2253 testnum=$((nodenum % numloads))
2254 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2256 # bug 22169: wait the background threads to start
2260 # only for remote client
2261 check_client_load () {
2263 local var=$(node_var_name $client)_load
2264 local testload=run_${!var}.sh
2266 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2268 # bug 18914: try to connect several times not only when
2269 # check ps, but while check_node_health also
2273 while [ $RC = 254 -a $tries -gt 0 ]; do
2277 if ! check_node_health $client; then
2279 if [ $RC -eq 254 ]; then
2280 # FIXME: not sure how long we shuold sleep here
2284 echo "check node health failed: RC=$RC "
2288 # We can continue try to connect if RC=254
2289 # Just print the warning about this
2290 if [ $RC = 254 ]; then
2291 echo "got a return status of $RC from do_node while checking " \
2292 "node health on $client"
2295 # see if the load is still on the client
2298 while [ $RC = 254 -a $tries -gt 0 ]; do
2302 if ! do_node $client \
2303 "ps auxwww | grep -v grep | grep -q $testload"; then
2308 if [ $RC = 254 ]; then
2309 echo "got a return status of $RC from do_node while checking " \
2310 "(node health and 'ps') the client load on $client"
2311 # see if we can diagnose a bit why this is
2316 check_client_loads () {
2317 local clients=${1//,/ }
2321 for client in $clients; do
2322 check_client_load $client
2324 if [ "$rc" != 0 ]; then
2325 log "Client load failed on node $client, rc=$rc"
2331 restart_client_loads () {
2332 local clients=${1//,/ }
2333 local expectedfail=${2:-""}
2337 for client in $clients; do
2338 check_client_load $client
2340 if [ "$rc" != 0 -a "$expectedfail" ]; then
2341 local var=$(node_var_name $client)_load
2342 start_client_load $client ${!var}
2343 echo "Restarted client load ${!var}: on $client. Checking ..."
2344 check_client_load $client
2346 if [ "$rc" != 0 ]; then
2347 log "Client load failed to restart on node $client, rc=$rc"
2348 # failure one client load means test fail
2349 # we do not need to check other
2358 # Start vmstat and save its process ID in a file.
2363 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2366 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2367 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2370 # Display the nodes on which client loads failed.
2371 print_end_run_file() {
2375 [ -s $file ] || return 0
2377 echo "Found the END_RUN_FILE file: $file"
2380 # A client load will stop if it finds the END_RUN_FILE file.
2381 # That does not mean the client load actually failed though.
2382 # The first node in END_RUN_FILE is the one we are interested in.
2385 if [ -n "$node" ]; then
2386 local var=$(node_var_name $node)_load
2388 local prefix=$TESTLOG_PREFIX
2389 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2390 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2391 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2393 echo "Client load ${!var} failed on node $node:"
2399 # Stop the process which had its PID saved in a file.
2404 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2406 do_nodes $nodes "test -f $pid_file &&
2407 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2410 # Stop all client loads.
2411 stop_client_loads() {
2412 local nodes=${1:-$CLIENTS}
2415 # stop the client loads
2416 stop_process $nodes $pid_file
2418 # clean up the processes that started them
2419 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2421 # End recovery-scale functions
2423 # verify that lustre actually cleaned up properly
2425 VAR=$(lctl get_param -n catastrophe 2>&1)
2426 if [ $? = 0 ] ; then
2427 if [ $VAR != 0 ]; then
2428 error "LBUG/LASSERT detected"
2431 BUSY=$(dmesg | grep -i destruct || true)
2432 if [ -n "$BUSY" ]; then
2434 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2438 check_mem_leak || exit 204
2440 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2441 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2444 if module_loaded lnet || module_loaded libcfs; then
2445 echo "$TESTSUITE: modules still loaded..." 1>&2
2454 if [[ "$1" == "--verbose" ]]; then
2469 PREV_RESULT=$(do_node $node "$TEST")
2471 RESULT=$(do_node $node "$TEST")
2472 if [[ "$RESULT" == "$FINAL" ]]; then
2473 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2474 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2478 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2479 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2483 [[ $WAIT -ge $MAX ]] && break
2484 [[ $((WAIT % print)) -eq 0 ]] &&
2485 echo "Waiting $((MAX - WAIT)) secs for update"
2486 WAIT=$((WAIT + sleep))
2489 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2493 wait_update_facet() {
2495 [ "$1" = "--verbose" ] && verbose="$1" && shift
2499 wait_update $verbose $(facet_active_host $facet) "$@"
2503 do_nodes $(comma_list $(mdts_nodes)) \
2504 "lctl set_param -n osd*.*MDT*.force_sync=1"
2505 do_nodes $(comma_list $(osts_nodes)) \
2506 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2507 grep -v 'Found no match'
2511 # the occupied disk space will be released
2512 # only after DMUs are committed
2513 if [[ $(facet_fstype $1) == zfs ]]; then
2514 echo "sleep $2 for ZFS OSD"
2519 wait_delete_completed_mds() {
2520 local MAX_WAIT=${1:-20}
2521 # for ZFS, waiting more time for DMUs to be committed
2522 local ZFS_WAIT=${2:-5}
2524 local stime=$(date +%s)
2529 # find MDS with pending deletions
2530 for node in $(mdts_nodes); do
2531 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2532 2>/dev/null | calc_sum)
2533 if [[ $changes -eq 0 ]]; then
2536 mds2sync="$mds2sync $node"
2538 if [ -z "$mds2sync" ]; then
2539 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2542 mds2sync=$(comma_list $mds2sync)
2544 # sync MDS transactions
2545 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2547 # wait till all changes are sent and commmitted by OSTs
2548 # for ldiskfs space is released upon execution, but DMU
2549 # do this upon commit
2552 while [[ $WAIT -ne $MAX_WAIT ]]; do
2553 changes=$(do_nodes $mds2sync \
2554 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2555 #echo "$node: $changes changes on all"
2556 if [[ $changes -eq 0 ]]; then
2557 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2565 echo "Delete is not completed in $((etime - stime)) seconds"
2566 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2572 # we can use "for" here because we are waiting the slowest
2573 for host in ${hostlist//,/ }; do
2574 check_network "$host" 900
2576 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2583 for facet in ${facetlist//,/ }; do
2584 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2586 wait_for_host $hostlist
2589 _wait_recovery_complete () {
2592 # Use default policy if $2 is not passed by caller.
2593 local MAX=${2:-$(max_recovery_time)}
2598 while [ $WAIT -lt $MAX ]; do
2599 STATUS=$(lctl get_param -n $param | grep status)
2601 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2604 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2606 echo "$param recovery not done in $MAX sec. $STATUS"
2610 wait_recovery_complete () {
2613 # with an assumption that at_max is the same on all nodes
2614 local MAX=${2:-$(max_recovery_time)}
2617 if [ "$FAILURE_MODE" = HARD ]; then
2618 facets=$(facets_on_host $(facet_active_host $facet))
2620 echo affected facets: $facets
2622 # we can use "for" here because we are waiting the slowest
2623 for facet in ${facets//,/ }; do
2624 local var_svc=${facet}_svc
2625 local param="*.${!var_svc}.recovery_status"
2627 local host=$(facet_active_host $facet)
2628 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2632 wait_mds_ost_sync () {
2633 # just because recovery is done doesn't mean we've finished
2634 # orphan cleanup. Wait for llogs to get synchronized.
2635 echo "Waiting for orphan cleanup..."
2636 # MAX value includes time needed for MDS-OST reconnection
2637 local MAX=$(( TIMEOUT * 2 ))
2638 local WAIT_TIMEOUT=${1:-$MAX}
2641 local list=$(comma_list $(mdts_nodes))
2642 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2643 if ! do_facet $SINGLEMDS \
2644 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2646 # old way, use mds_sync
2648 list=$(comma_list $(osts_nodes))
2649 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2652 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2653 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2654 local -a sync=($(do_nodes $list "$cmd"))
2657 for ((i=0; i<${#sync[@]}; i++)); do
2659 [ ${sync[$i]} -eq 1 ] && continue
2661 [ ${sync[$i]} -eq 0 ] && continue
2663 # there is a not finished MDS-OST synchronization
2667 sleep 2 # increase waiting time and cover statfs cache
2668 [ ${con} -eq 1 ] && return 0
2669 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2673 # show which nodes are not finished.
2674 do_nodes $list "$cmd"
2675 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2679 # Wait OSTs to be active on both client and MDT side.
2681 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2682 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2683 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2684 error "wait_update OSTs up on client failed"
2686 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
2687 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
2688 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2689 error "wait_update OSTs up on MDT0000 failed"
2692 wait_destroy_complete () {
2693 echo "Waiting for local destroys to complete"
2694 # MAX value shouldn't be big as this mean server responsiveness
2695 # never increase this just to make test pass but investigate
2696 # why it takes so long time
2699 while [ $WAIT -lt $MAX ]; do
2700 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2704 for ((i=0; i<${#RPCs[@]}; i++)); do
2705 [ ${RPCs[$i]} -eq 0 ] && continue
2706 # there are still some destroy RPCs in flight
2711 [ ${con} -eq 1 ] && return 0 # done waiting
2712 echo "Waiting ${WAIT}s for local destroys to complete"
2715 echo "Local destroys weren't done in $MAX sec."
2719 wait_delete_completed() {
2720 wait_delete_completed_mds $1 || return $?
2721 wait_destroy_complete
2730 # conf-sanity 31 takes a long time cleanup
2731 while [ $WAIT -lt 300 ]; do
2732 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2733 [ -z "${running}" ] && return 0
2734 echo "waited $WAIT for${running}"
2735 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2737 WAIT=$((WAIT + INTERVAL))
2739 echo "service didn't stop after $WAIT seconds. Still running:"
2744 wait_remote_prog () {
2750 [ "$PDSH" = "no_dsh" ] && return 0
2752 while [ $WAIT -lt $2 ]; do
2753 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2754 [ -z "${running}" ] && return 0 || true
2755 echo "waited $WAIT for: "
2757 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2759 WAIT=$((WAIT + INTERVAL))
2761 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2762 [ -z "$pids" ] && return 0
2763 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2764 # FIXME: not portable
2765 for pid in $pids; do
2766 cat /proc/${pid}/status || true
2767 cat /proc/${pid}/wchan || true
2769 kill -9 $pid || true
2778 local clients=${1:-$CLIENTS}
2780 if [ -z "$clients" ]; then
2783 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2788 # not every config has many clients
2794 # usually checked on particular client or locally
2803 client_reconnect_try() {
2804 local f=$MOUNT/recon
2807 if [ -z "$CLIENTS" ]; then
2808 $LFS df $MOUNT; uname -n >> $f
2810 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2812 echo "Connected clients: $(cat $f)"
2813 ls -l $f > /dev/null
2817 client_reconnect() {
2818 # one client_reconnect_try call does not always do the job...
2820 client_reconnect_try && break
2825 affected_facets () {
2828 local host=$(facet_active_host $facet)
2829 local affected=$facet
2831 if [ "$FAILURE_MODE" = HARD ]; then
2832 affected=$(facets_up_on_host $host)
2838 local E2FSCK_ON_MDT0=false
2839 if [ "$1" == "--fsck" ]; then
2841 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2853 #Because it will only get up facets, we need get affected
2854 #facets before shutdown
2855 #For HARD Failure mode, it needs make sure facets on the same
2856 #HOST will only be shutdown and reboot once
2857 for facet in ${facets//,/ }; do
2858 local affected_facet
2860 #check whether facet has been included in other affected facets
2861 for ((index=0; index<$total; index++)); do
2862 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2865 if [ $skip -eq 0 ]; then
2866 affecteds[$total]=$(affected_facets $facet)
2871 for ((index=0; index<$total; index++)); do
2872 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2873 local host=$(facet_active_host $facet)
2874 echo "Failing ${affecteds[index]} on $host"
2875 shutdown_facet $facet
2878 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2879 $(mdsdevname 1) "-n" || error "Running e2fsck")
2881 for ((index=0; index<$total; index++)); do
2882 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2883 echo reboot facets: ${affecteds[index]}
2887 change_active ${affecteds[index]}
2889 wait_for_facet ${affecteds[index]}
2890 # start mgs first if it is affected
2891 if ! combined_mgs_mds &&
2892 list_member ${affecteds[index]} mgs; then
2893 mount_facet mgs || error "Restart of mgs failed"
2895 # FIXME; has to be changed to mount all facets concurrently
2896 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2897 echo mount facets: ${affecteds[index]}
2898 mount_facets ${affecteds[index]}
2908 do_facet $facet "sync; sync; sync"
2911 # make sure there will be no seq change
2912 local clients=${CLIENTS:-$HOSTNAME}
2913 local f=fsa-\\\$\(hostname\)
2914 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2915 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2917 local svc=${facet}_svc
2918 do_facet $facet $LCTL --device ${!svc} notransno
2920 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2921 # in-memory state has to be cleared by either rebooting the host or
2922 # exporting and reimporting the pool.
2924 # Although the uberblocks are not updated when a pool is freezed,
2925 # transactions are still written to the disks. Modified blocks may be
2926 # cached in memory when tests try reading them back. The
2927 # export-and-reimport process also evicts any cached pool data from
2928 # memory to provide the correct "data loss" semantics.
2930 # In the test framework, the exporting and importing operations are
2931 # handled by stop() and mount_facet() separately, which are used
2932 # inside fail() and fail_abort().
2934 do_facet $facet $LCTL --device ${!svc} readonly
2935 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2936 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2939 replay_barrier_nodf() {
2940 local facet=$1 echo running=${running}
2941 do_facet $facet "sync; sync; sync"
2942 local svc=${facet}_svc
2943 echo Replay barrier on ${!svc}
2944 do_facet $facet $LCTL --device ${!svc} notransno
2945 do_facet $facet $LCTL --device ${!svc} readonly
2946 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2947 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2950 replay_barrier_nosync() {
2951 local facet=$1 echo running=${running}
2952 local svc=${facet}_svc
2953 echo Replay barrier on ${!svc}
2954 do_facet $facet $LCTL --device ${!svc} notransno
2955 do_facet $facet $LCTL --device ${!svc} readonly
2956 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2957 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2961 # Get Lustre client uuid for a given Lustre mount point.
2964 local mntpnt=${1:-$MOUNT}
2966 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2967 local uuid=$($LCTL get_param -n llite.$name.uuid)
2972 mds_evict_client() {
2973 local mntpnt=${1:-$MOUNT}
2974 local uuid=$(get_client_uuid $mntpnt)
2976 do_facet $SINGLEMDS \
2977 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2980 ost_evict_client() {
2981 local mntpnt=${1:-$MOUNT}
2982 local uuid=$(get_client_uuid $mntpnt)
2985 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2990 local clients=${CLIENTS:-$HOSTNAME}
2992 facet_failover $* || error "failover: $?"
2993 wait_clients_import_state "$clients" "$facets" FULL
2994 clients_up || error "post-failover stat: $?"
2999 facet_failover $facet
3005 change_active $facet
3006 wait_for_facet $facet
3007 mount_facet $facet -o abort_recovery
3008 clients_up || echo "first stat failed: $?"
3009 clients_up || error "post-failover stat: $?"
3012 host_nids_address() {
3016 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
3020 if [ "$1" = "'*'" ]; then echo \'*\'; else
3026 if [[ -n "$NETTYPE" ]]; then
3027 h2name_or_ip "$1" "$NETTYPE"
3029 h2name_or_ip "$1" "$2"
3032 declare -fx h2nettype
3034 # Wrapper function to print the deprecation warning
3036 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3037 if [[ -n "$NETTYPE" ]]; then
3040 h2nettype "$1" "tcp"
3044 # Wrapper function to print the deprecation warning
3046 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3047 if [[ -n "$NETTYPE" ]]; then
3050 h2nettype "$1" "o2ib"
3054 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3055 # expressions format. As a bonus we can then just pass in those variables
3056 # to pdsh. What this function does is take a HOSTLIST type string and
3057 # expand it into a space deliminated list for us.
3065 [ -z "$hostlist" ] && return
3067 # Translate the case of [..],..,[..] to [..] .. [..]
3068 list="${hostlist/],/] }"
3070 [[ "$front" == *,* ]] && {
3073 list=${list/${old}/${new}}
3076 for item in $list; do
3077 # Test if we have any []'s at all
3078 if [ "$item" != "${item/\[/}" ]; then {
3079 # Expand the [*] into list
3083 if [ "$name" != "$item" ]; then
3084 group=${item#$name[*}
3087 for range in ${group//,/ }; do
3093 # Number of leading zeros
3096 end=$(echo $end | sed 's/0*//')
3097 [[ -z "$end" ]] && end=0
3098 [[ $padlen2 -gt $padlen ]] && {
3099 [[ $padlen2 -eq ${#end} ]] && padlen2=0
3102 begin=$(echo $begin | sed 's/0*//')
3103 [ -z $begin ] && begin=0
3105 if [ ! -z "${begin##[!0-9]*}" ]; then
3106 order=$(seq -f "%0${padlen}g" $begin $end)
3108 order=$(eval echo {$begin..$end});
3111 for num in $order; do
3112 value="${name#*,}${num}${back}"
3113 [ "$value" != "${value/\[/}" ] && {
3114 value=$(hostlist_expand "$value")
3116 myList="$myList $value"
3121 myList="$myList $item"
3124 myList=${myList//,/ }
3125 myList=${myList:1} # Remove first character which is a space
3127 # Filter any duplicates without sorting
3129 myList="${list%% *}"
3131 while [[ "$list" != ${myList##* } ]]; do
3132 local tlist=" $list"
3133 list=${tlist// ${list%% *} / }
3135 myList="$myList ${list%% *}"
3137 myList="${myList%* }";
3139 # We can select an object at an offset in the list
3142 for item in $myList; do
3144 [ $cnt -eq $offset ] && {
3148 [ $(get_node_count $myList) -ne 1 ] && myList=""
3157 [ "$facet" == client ] && echo -n $HOSTNAME && return
3158 varname=${facet}_HOST
3159 if [ -z "${!varname}" ]; then
3160 if [ "${facet:0:3}" == "ost" ]; then
3161 local fh=${facet%failover}_HOST
3162 eval export ${facet}_HOST=${!fh}
3163 if [ -z "${!varname}" ]; then
3164 eval export ${facet}_HOST=${ost_HOST}
3166 elif [ "${facet:0:3}" == "mdt" -o \
3167 "${facet:0:3}" == "mds" -o \
3168 "${facet:0:3}" == "mgs" ]; then
3169 eval export ${facet}_HOST=${mds_HOST}
3175 facet_failover_host() {
3179 var=${facet}failover_HOST
3180 if [ -n "${!var}" ]; then
3185 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
3186 "${facet:0:3}" == "mgs" ]; then
3188 eval export ${facet}failover_host=${mds_HOST}
3193 if [[ $facet == ost* ]]; then
3194 eval export ${facet}failover_host=${ost_HOST}
3202 local activevar=${facet}active
3204 if [ -f $TMP/${facet}active ] ; then
3205 source $TMP/${facet}active
3208 active=${!activevar}
3209 if [ -z "$active" ] ; then
3216 facet_active_host() {
3217 facet_host $(facet_active $1)
3220 # Get the passive failover partner host of facet.
3221 facet_passive_host() {
3223 [[ $facet = client ]] && return
3225 local host=${facet}_HOST
3226 local failover_host=${facet}failover_HOST
3227 local active_host=$(facet_active_host $facet)
3229 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
3231 if [[ $active_host = ${!host} ]]; then
3232 echo -n ${!failover_host}
3242 facetlist=$(exclude_items_from_list $facetlist mgs)
3244 for facet in ${facetlist//,/ }; do
3245 local failover=${facet}failover
3246 local host=`facet_host $failover`
3247 [ -z "$host" ] && return
3249 local curactive=`facet_active $facet`
3250 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3251 eval export ${facet}active=$facet
3253 eval export ${facet}active=$failover
3255 # save the active host for this facet
3256 local activevar=${facet}active
3257 echo "$activevar=${!activevar}" > $TMP/$activevar
3258 [[ $facet = mds1 ]] && combined_mgs_mds && \
3259 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3260 local TO=`facet_active_host $facet`
3261 echo "Failover $facet to $TO"
3267 # do not stripe off hostname if verbose, bug 19215
3268 if [ x$1 = x--verbose ]; then
3276 if [ "$HOST" = "$HOSTNAME" ]; then
3278 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3279 echo "cannot run remote command on $HOST with $myPDSH"
3283 echo "CMD: $HOST $@" >&2
3284 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3287 if [ "$myPDSH" = "rsh" ]; then
3288 # we need this because rsh does not return exit code of an executed command
3289 local command_status="$TMP/cs"
3290 rsh $HOST ":> $command_status"
3291 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3292 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3293 echo command failed >$command_status"
3294 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3299 # print HOSTNAME for myPDSH="no_dsh"
3300 if [[ $myPDSH = no_dsh ]]; then
3301 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3303 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3306 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3308 return ${PIPESTATUS[0]}
3312 do_node --verbose "$@"
3315 single_local_node () {
3316 [ "$1" = "$HOSTNAME" ]
3319 # Outputs environment variable assignments that should be passed to remote nodes
3323 local facets=$(get_facets)
3326 for var in ${!MODOPTS_*}; do
3327 value=${!var//\"/\\\"}
3328 echo -n " ${var}=\"$value\""
3331 for facet in ${facets//,/ }; do
3333 if [ -n "${!var}" ]; then
3334 echo -n " $var=${!var}"
3338 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3339 if [ -n "${!var}" ]; then
3340 echo -n " $var=${!var}"
3344 for var in VERBOSE; do
3345 if [ -n "${!var}" ]; then
3346 echo -n " $var=${!var}"
3350 if [ -n "$FSTYPE" ]; then
3351 echo -n " FSTYPE=$FSTYPE"
3354 for var in LNETLND NETTYPE; do
3355 if [ -n "${!var}" ]; then
3356 echo -n " $var=${!var}"
3363 # do not stripe off hostname if verbose, bug 19215
3364 if [ x$1 = x--verbose ]; then
3372 if single_local_node $rnodes; then
3374 do_nodev $rnodes "$@"
3376 do_node $rnodes "$@"
3381 # This is part from do_node
3384 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3385 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3387 export FANOUT=$(get_node_count "${rnodes//,/ }")
3389 echo "CMD: $rnodes $@" >&2
3390 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3393 # do not replace anything from pdsh output if -N is used
3394 # -N Disable hostname: prefix on lines of output.
3395 if $verbose || [[ $myPDSH = *-N* ]]; then
3396 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3398 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3400 return ${PIPESTATUS[0]}
3404 # Execute commands on a single service's host
3406 # The \a facet (service) may be on a local or remote node, which is
3407 # determined at the time the command is run.
3409 # usage: do_facet $facet command [arg ...]
3413 local HOST=$(facet_active_host $facet)
3414 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3418 # Function: do_facet_random_file $FACET $FILE $SIZE
3419 # Creates FILE with random content on the given FACET of given SIZE
3421 do_facet_random_file() {
3425 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3426 do_facet $facet "$cmd 2>/dev/null"
3429 do_facet_create_file() {
3433 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3434 do_facet $facet "$cmd 2>/dev/null"
3438 do_nodes --verbose "$@"
3444 # make sure its not already running
3446 rm -f $TMP/${facet}active
3447 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3448 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3450 if [[ $(facet_fstype $facet) == zfs ]]; then
3452 # After formatting a ZFS target, "cachefile=none" property will
3453 # be set on the ZFS storage pool so that the pool is not
3454 # automatically imported on system startup. And then the pool
3455 # will be exported so as to leave the importing and exporting
3456 # operations handled by mount_facet() and stop() separately.
3458 refresh_partition_table $facet $(facet_vdevice $facet)
3459 disable_zpool_cache $facet
3464 # Device formatted as ost
3467 local DEVNAME=OSTDEV$num
3469 local fstype=$(facet_fstype ost$num)
3473 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3474 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3476 #try $OSTZFSDEVn - independent of vdev
3477 DEVNAME=OSTZFSDEV$num
3478 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3480 error "unknown fstype!";;
3486 # Physical device location of data
3492 local fstype=$(facet_fstype ost$num)
3496 # vdevs are not supported by ldiskfs
3499 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3500 # Device formatted by zfs
3502 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3504 error "unknown fstype!";;
3510 # Logical device formatted for lustre
3513 local DEVNAME=MDSDEV$num
3515 local fstype=$(facet_fstype mds$num)
3519 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3520 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3522 # try $MDSZFSDEVn - independent of vdev
3523 DEVNAME=MDSZFSDEV$num
3524 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3526 error "unknown fstype!";;
3532 # Physical location of data
3536 local fstype=$(facet_fstype mds$num)
3540 # vdevs are not supported by ldiskfs
3543 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3544 # Device formatted by ZFS
3545 local DEVNAME=MDSDEV$num
3546 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3548 error "unknown fstype!";;
3556 local fstype=$(facet_fstype mgs)
3560 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3561 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3562 DEVPTR=$(mdsdevname 1)
3567 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3568 ( [ -z "$MGSZFSDEV" ] &&
3569 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3570 DEVPTR=$(mdsdevname 1)
3572 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3575 error "unknown fstype!";;
3584 local fstype=$(facet_fstype mgs)
3588 # vdevs are not supported by ldiskfs
3591 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3592 ( [ -z "$MGSDEV" ] &&
3593 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3594 VDEVPTR=$(mdsvdevname 1)
3595 elif [ -n "$MGSDEV" ]; then
3599 error "unknown fstype!";;
3607 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3609 local var=${facet}_MOUNT
3610 eval mntpt=${!var:-${MOUNT}-$facet}
3617 local dev=$(facet_device $facet)
3618 local mnt=${2:-$(facet_mntpt $facet)}
3621 if ! do_facet $facet test -b $dev; then
3624 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3629 local dev=$(facet_device $facet)
3630 local mnt=${2:-$(facet_mntpt $facet)}
3632 do_facet $facet $UMOUNT $mnt
3636 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3641 local ds=$(facet_device $facet)
3642 local mnt=${2:-$(facet_mntpt $facet)}
3647 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3648 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3649 do_facet $facet $ZFS set canmount=noauto $ds
3651 # The "legacy" mount method is used here because "zfs unmount $mnt"
3652 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3653 # targets are not available at the time, the stat(2) on $MOUNT will
3656 do_facet $facet $ZFS set mountpoint=legacy $ds
3657 do_facet $facet mount -t zfs $ds $mnt
3658 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3659 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3664 local ds=$(facet_device $facet)
3665 local mnt=${2:-$(facet_mntpt $facet)}
3666 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3667 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3668 local mntpt=${!var_mntpt}
3669 local canmnt=${!var_canmnt}
3673 do_facet $facet umount $mnt
3674 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3675 do_facet $facet $ZFS set canmount=$canmnt $ds
3682 local fstype=$(facet_fstype $facet)
3684 mount_$fstype $facet $mnt
3690 local fstype=$(facet_fstype $facet)
3692 unmount_$fstype $facet $mnt
3699 # make sure we are using the primary server, so test-framework will
3700 # be able to clean up properly.
3701 activemds=`facet_active mds1`
3702 if [ $activemds != "mds1" ]; then
3706 local clients=$CLIENTS
3707 [ -z $clients ] && clients=$(hostname)
3709 zconf_umount_clients $clients $MOUNT "$*" || true
3710 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3712 [ -n "$CLIENTONLY" ] && return
3714 # The add fn does rm ${facet}active file, this would be enough
3715 # if we use do_facet <facet> only after the facet added, but
3716 # currently we use do_facet mds in local.sh
3717 for num in `seq $MDSCOUNT`; do
3719 rm -f ${TMP}/mds${num}active
3721 combined_mgs_mds && rm -f $TMP/mgsactive
3723 for num in `seq $OSTCOUNT`; do
3725 rm -f $TMP/ost${num}active
3728 if ! combined_mgs_mds ; then
3735 cleanup_echo_devs () {
3738 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3740 for dev in $devs; do
3741 $LCTL --device $dev cleanup
3742 $LCTL --device $dev detach
3747 nfs_client_mode && return
3748 cifs_client_mode && return
3758 combined_mgs_mds () {
3759 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3760 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3764 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3768 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3774 local fsname=${3:-"$FSNAME"}
3775 local type=$(facet_type $facet)
3776 local index=$(facet_index $facet)
3777 local fstype=$(facet_fstype $facet)
3778 local host=$(facet_host $facet)
3783 if [ $type == MGS ] || ( [ $type == MDS ] &&
3784 [ "$dev" == $(mgsdevname) ] &&
3785 [ "$host" == "$(facet_host mgs)" ] ); then
3788 opts="--mgsnode=$MGSNID"
3791 if [ $type != MGS ]; then
3792 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3796 var=${facet}failover_HOST
3797 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3798 opts+=" --failnode=$(h2nettype ${!var})"
3801 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3802 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3804 if [ $type == MDS ]; then
3805 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3806 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3807 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3808 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3810 if [ $fstype == ldiskfs ]; then
3811 # Check for wide striping
3812 if [ $OSTCOUNT -gt 160 ]; then
3813 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3814 fs_mkfs_opts+="-O large_xattr"
3818 if [ -n "${!var}" ]; then
3819 fs_mkfs_opts+=" -J device=${!var}"
3821 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3823 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3827 if [ $type == OST ]; then
3828 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3830 if [ $fstype == ldiskfs ]; then
3832 if [ -n "${!var}" ]; then
3833 fs_mkfs_opts+=" -J device=${!var}"
3835 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3840 opts+=" --backfstype=$fstype"
3843 if [ -n "${!var}" ]; then
3844 opts+=" --device-size=${!var}"
3847 var=$(upper $fstype)_MKFS_OPTS
3848 fs_mkfs_opts+=${!var:+" ${!var}"}
3850 var=${type}_FS_MKFS_OPTS
3851 fs_mkfs_opts+=${!var:+" ${!var}"}
3853 if [ -n "${fs_mkfs_opts## }" ]; then
3854 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3858 opts+=${!var:+" ${!var}"}
3865 local type=$(facet_type $facet)
3866 local var=${type}_MOUNT_FS_OPTS
3868 if [ -n "${!var}" ]; then
3869 opts+=" --mountfsoptions=${!var}"
3874 check_ost_indices() {
3875 local index_count=${#OST_INDICES[@]}
3876 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3878 # OST count is greater than the index count in $OST_INDEX_LIST.
3879 # We need check whether there are duplicate indices.
3883 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3884 index=$(facet_index ost$i)
3885 for j in $(seq 0 $((index_count - 1))); do
3886 [[ $index -ne ${OST_INDICES[j]} ]] ||
3887 error "ost$i has the same index $index as ost$((j+1))"
3894 local facet_type=$1 # mgs || mds || ost
3896 local facet=${1}${2}
3899 case "$(facet_fstype $facet)" in
3901 device=$(${facet_type}devname $facet_num)
3904 device=$(${facet_type}vdevname $facet_num)
3907 error "Unhandled filesystem type"
3911 do_facet $facet "[ -e \"$device\" ]" && return
3913 # Note: the following check only works with absolute paths
3914 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
3915 error "$facet: device '$device' does not exist"
3917 do_facet $facet "touch \"${device}\""
3926 echo "Format mgs: $(mgsdevname)"
3927 reformat_external_journal mgs
3929 # touch "device" in case it is a loopback file for testing and needs to
3930 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
3931 # to non-existent files in /dev if the admin made a typo during setup
3934 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
3935 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3945 echo "Format mds$num: $(mdsdevname $num)"
3946 reformat_external_journal mds$num
3948 __touch_device mds $num
3950 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3951 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
3952 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
3961 echo "Format ost$num: $(ostdevname $num)"
3962 reformat_external_journal ost$num
3964 __touch_device ost $num
3966 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3967 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
3968 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
3973 # Set hostid for ZFS/SPL zpool import protection
3974 # (Assumes MDS version is also OSS version)
3975 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3977 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3980 # We need ldiskfs here, may as well load them all
3982 [ -n "$CLIENTONLY" ] && return
3983 echo Formatting mgs, mds, osts
3984 if ! combined_mgs_mds ; then
3988 for num in $(seq $MDSCOUNT); do
3992 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3994 for num in $(seq $OSTCOUNT); do
4000 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
4004 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
4008 # 0: success, the old identity set already.
4009 # 1: success, the old identity does not set.
4014 local j=`expr $num - 1`
4015 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
4017 if [ -z "$MDT" ]; then
4021 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
4024 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
4026 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
4029 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
4031 if [ $old = "NONE" ]; then
4040 zconf_umount $HOSTNAME $1 || error "umount failed"
4041 zconf_mount $HOSTNAME $1 || error "mount failed"
4049 rm -f $TMP/${facet}active
4050 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
4055 local mdt_count=${1:-$MDSCOUNT}
4056 local ost_count=${2:-$OSTCOUNT}
4059 for num in $(seq $mdt_count); do
4060 DEVNAME=$(mdsdevname $num)
4061 writeconf_facet mds$num $DEVNAME || rc=$?
4064 for num in $(seq $ost_count); do
4065 DEVNAME=$(ostdevname $num)
4066 writeconf_facet ost$num $DEVNAME || rc=$?
4072 if ! combined_mgs_mds ; then
4073 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
4078 for num in $(seq $MDSCOUNT); do
4079 DEVNAME=$(mdsdevname $num)
4080 start mds$num $DEVNAME $MDS_MOUNT_OPTS
4082 # We started mds, now we should set failover variables properly.
4083 # Set mds${num}failover_HOST if unset (the default
4085 local varname=mds${num}failover_HOST
4086 if [ -z "${!varname}" ]; then
4087 eval mds${num}failover_HOST=$(facet_host mds$num)
4090 if [ $IDENTITY_UPCALL != "default" ]; then
4091 switch_identity $num $IDENTITY_UPCALL
4097 for num in $(seq $OSTCOUNT); do
4098 DEVNAME=$(ostdevname $num)
4099 start ost$num $DEVNAME $OST_MOUNT_OPTS
4101 # We started ost$num, now we should set ost${num}failover
4102 # variable properly. Set ost${num}failover_HOST if it is not
4103 # set (the default failnode).
4104 varname=ost${num}failover_HOST
4105 if [ -z "${!varname}" ]; then
4106 eval ost${num}failover_HOST=$(facet_host ost${num})
4113 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
4114 if [ ! -z $arg1 ]; then
4115 [ "$arg1" = "server_only" ] && return
4118 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
4121 if [ "$MOUNT_2" ]; then
4122 mount_client $MOUNT2
4123 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
4127 sk_nodemap_setup() {
4128 local sk_map_name=${1:-$SK_S2SNM}
4129 local sk_map_nodes=${2:-$HOSTNAME}
4130 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
4131 for servernode in $sk_map_nodes; do
4132 local nids=$(do_nodes $servernode "$LCTL list_nids")
4133 for nid in $nids; do
4134 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
4135 $sk_map_name --range $nid"
4143 nfs_client_mode && return
4144 cifs_client_mode && return
4146 sanity_mount_check || error "environments are insane!"
4152 if [ -z "$CLIENTONLY" ]; then
4153 echo Setup mgs, mdt, osts
4154 echo $WRITECONF | grep -q "writeconf" && writeconf_all
4156 if $SK_MOUNTED; then
4157 echo "Shared Key file system already mounted"
4162 if $SHARED_KEY; then
4163 export SK_MOUNTED=true
4167 echo "GSS_SK: setting kernel keyring perms"
4168 do_nodes $(comma_list $(all_nodes)) \
4169 "keyctl show | grep lustre | cut -c1-11 |
4171 xargs -IX keyctl setperm X 0x3f3f3f3f"
4174 # Need to start one nodemap for servers,
4175 # and one for clients.
4176 sk_nodemap_setup $SK_S2SNM \
4177 $(comma_list $(all_server_nodes))
4179 sk_nodemap_setup $SK_S2SNMCLI \
4180 ${CLIENTS:-$HOSTNAME}
4181 echo "Nodemap set up for SK S2S, remounting."
4190 # wait a while to allow sptlrpc configuration be propogated to targets,
4191 # only needed when mounting new target devices.
4199 # by remounting mdt before ost, initial connect from mdt to ost might
4200 # timeout because ost is not ready yet. wait some time to its fully
4201 # recovery. initial obd_connect timeout is 5s; in GSS case it's
4202 # preceeded by a context negotiation rpc with $TIMEOUT.
4203 # FIXME better by monitoring import status.
4206 set_rule $FSNAME any cli2mdt $SK_FLAVOR
4207 set_rule $FSNAME any cli2ost $SK_FLAVOR
4208 wait_flavor cli2mdt $SK_FLAVOR
4209 wait_flavor cli2ost $SK_FLAVOR
4213 sleep $((TIMEOUT + 5))
4219 mounted_lustre_filesystems() {
4220 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
4223 init_facet_vars () {
4224 [ -n "$CLIENTONLY" ] && return 0
4231 eval export ${facet}_dev=${device}
4232 eval export ${facet}_opt=\"$@\"
4234 local dev=${facet}_dev
4236 # We need to loop for the label
4237 # in case its not initialized yet.
4238 for wait_time in {0,1,3,5,10}; do
4240 if [ $wait_time -gt 0 ]; then
4241 echo "${!dev} not yet initialized,"\
4242 "waiting ${wait_time} seconds."
4246 local label=$(devicelabel ${facet} ${!dev})
4248 # Check to make sure the label does
4249 # not include ffff at the end of the label.
4250 # This indicates it has not been initialized yet.
4252 if [[ $label =~ [f|F]{4}$ ]]; then
4253 # label is not initialized, unset the result
4254 # and either try again or fail
4261 [ -z "$label" ] && echo no label for ${!dev} && exit 1
4263 eval export ${facet}_svc=${label}
4265 local varname=${facet}failover_HOST
4266 if [ -z "${!varname}" ]; then
4267 eval export $varname=$(facet_host $facet)
4270 varname=${facet}_HOST
4271 if [ -z "${!varname}" ]; then
4272 eval export $varname=$(facet_host $facet)
4275 # ${facet}failover_dev is set in cfg file
4276 varname=${facet}failover_dev
4277 if [ -n "${!varname}" ] ; then
4278 eval export ${facet}failover_dev=${!varname}
4280 eval export ${facet}failover_dev=$device
4283 # get mount point of already mounted device
4284 # is facet_dev is already mounted then use the real
4285 # mount point of this facet; otherwise use $(facet_mntpt $facet)
4286 # i.e. ${facet}_MOUNT if specified by user or default
4287 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
4288 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
4289 if [ -z $mntpt ]; then
4290 mntpt=$(facet_mntpt $facet)
4292 eval export ${facet}_MOUNT=$mntpt
4295 init_facets_vars () {
4298 if ! remote_mds_nodsh; then
4299 for num in $(seq $MDSCOUNT); do
4300 DEVNAME=`mdsdevname $num`
4301 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
4305 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
4307 if ! remote_ost_nodsh; then
4308 for num in $(seq $OSTCOUNT); do
4309 DEVNAME=$(ostdevname $num)
4310 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
4315 osc_ensure_active () {
4320 while [ $period -lt $timeout ]; do
4321 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
4322 if [ $count -eq 0 ]; then
4326 echo "There are $count OST are inactive, wait $period seconds, and try again"
4328 period=$((period+3))
4331 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
4334 set_conf_param_and_check() {
4338 local ORIG=$(do_facet $myfacet "$TEST")
4339 if [ $# -gt 3 ]; then
4345 echo "Setting $PARAM from $ORIG to $FINAL"
4346 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
4347 error "conf_param $PARAM failed"
4349 wait_update_facet $myfacet "$TEST" "$FINAL" ||
4350 error "check $PARAM failed!"
4353 init_param_vars () {
4354 TIMEOUT=$(lctl get_param -n timeout)
4355 TIMEOUT=${TIMEOUT:-20}
4357 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
4359 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4360 log "Using TIMEOUT=$TIMEOUT"
4362 osc_ensure_active $SINGLEMDS $TIMEOUT
4363 osc_ensure_active client $TIMEOUT
4365 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
4366 local current_jobid_var=$($LCTL get_param -n jobid_var)
4368 if [ $JOBID_VAR = "existing" ]; then
4369 echo "keeping jobstats as $current_jobid_var"
4370 elif [ $current_jobid_var != $JOBID_VAR ]; then
4371 echo "seting jobstats to $JOBID_VAR"
4373 set_conf_param_and_check client \
4374 "$LCTL get_param -n jobid_var" \
4375 "$FSNAME.sys.jobid_var" $JOBID_VAR
4378 echo "jobstats not supported by server"
4381 if [ $QUOTA_AUTO -ne 0 ]; then
4382 if [ "$ENABLE_QUOTA" ]; then
4383 echo "enable quota as required"
4384 setup_quota $MOUNT || return 2
4386 echo "disable quota as required"
4387 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4393 nfs_client_mode () {
4394 if [ "$NFSCLIENT" ]; then
4395 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4396 local clients=$CLIENTS
4397 [ -z $clients ] && clients=$(hostname)
4399 # FIXME: remove hostname when 19215 fixed
4400 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4401 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4402 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4403 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4405 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4411 cifs_client_mode () {
4412 [ x$CIFSCLIENT = xyes ] &&
4413 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4416 check_config_client () {
4419 local mounted=$(mount | grep " $mntpt ")
4420 if [ -n "$CLIENTONLY" ]; then
4422 # CLIENTONLY should not depend on *_HOST settings
4423 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4424 # in theory someone could create a new,
4425 # client-only config file that assumed lustre was already
4426 # configured and didn't set the MGSNID. If MGSNID is not set,
4427 # then we should use the mgs nid currently being used
4428 # as the default value. bug 18021
4429 [[ x$MGSNID = x ]] &&
4432 if [[ x$mgc != xMGC$MGSNID ]]; then
4433 if [ "$mgs_HOST" ]; then
4434 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4435 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4436 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4442 echo Checking config lustre mounted on $mntpt
4443 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4444 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4448 check_config_clients () {
4449 local clients=${CLIENTS:-$HOSTNAME}
4452 nfs_client_mode && return
4453 cifs_client_mode && return
4455 do_rpc_nodes "$clients" check_config_client $mntpt
4457 sanity_mount_check || error "environments are insane!"
4461 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4462 local cltimeout=$(lctl get_param -n timeout)
4463 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4464 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4471 [ -z $mntpt ] && return 1
4472 local mounted=$(mounted_lustre_filesystems)
4474 echo $mounted' ' | grep -w -q $mntpt' '
4478 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4482 # empty lustre filesystem may have empty directories lost+found and .lustre
4484 # exclude .lustre & lost+found
4485 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4486 -print | wc -l) = 1 ] || return 1
4487 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4488 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4489 # exclude .lustre/fid (LU-2780)
4490 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4491 -print | wc -l) = 1 ] || return 1
4493 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4498 check_and_setup_lustre() {
4500 nfs_client_mode && return
4501 cifs_client_mode && return
4503 local MOUNTED=$(mounted_lustre_filesystems)
4507 # both MOUNT and MOUNT2 are not mounted
4508 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4509 [ "$REFORMAT" = "yes" ] && formatall
4510 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4512 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4513 export I_MOUNTED=yes
4517 elif is_mounted $MOUNT2; then
4519 # MOUNT2 is mounted, while MOUNT_2 is not set
4520 if ! [ "$MOUNT_2" ]; then
4521 cleanup_mount $MOUNT2
4522 export I_UMOUNTED2=yes
4525 # MOUNT2 is mounted, MOUNT_2 is set
4527 # FIXME: what to do if check_config failed?
4529 # 1) remote client has mounted other Lustre fs ?
4530 # 2) it has insane env ?
4531 # let's try umount MOUNT2 on all clients and mount it again:
4532 if ! check_config_clients $MOUNT2; then
4533 cleanup_mount $MOUNT2
4534 restore_mount $MOUNT2
4535 export I_MOUNTED2=yes
4540 # MOUNT is mounted MOUNT2 is not mounted
4541 elif [ "$MOUNT_2" ]; then
4542 restore_mount $MOUNT2
4543 export I_MOUNTED2=yes
4547 # FIXME: what to do if check_config failed?
4549 # 1) remote client has mounted other Lustre fs?
4550 # 2) lustre is mounted on remote_clients atall ?
4551 check_config_clients $MOUNT
4555 set_default_debug_nodes $(comma_list $(nodes_list))
4558 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4560 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4561 facets="$(get_facets OST)"
4562 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4563 facets="$facets,$(get_facets MDS)"
4564 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4565 facets="$facets,mgs"
4566 local nodes="$(facets_hosts ${facets})"
4567 if [ -n "$nodes" ] ; then
4568 do_nodes $nodes "$LCTL set_param \
4569 osd-ldiskfs.track_declares_assert=1 || true"
4580 if [ -z "$CLIENTONLY" ]; then
4581 # Enable remote MDT create for testing
4582 for num in $(seq $MDSCOUNT); do
4584 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4589 if [ "$ONLY" == "setup" ]; then
4595 local clients=${CLIENTS:-$HOSTNAME}
4598 zconf_mount_clients $clients $mntpt
4602 local clients=${CLIENTS:-$HOSTNAME}
4605 zconf_umount_clients $clients $mntpt
4608 cleanup_and_setup_lustre() {
4609 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4610 lctl set_param debug=0 || true
4612 if [ "$ONLY" == "cleanup" ]; then
4616 check_and_setup_lustre
4619 # Get all of the server target devices from a given server node and type.
4626 if [ "$type" == ost ]; then
4627 devs=$(get_osd_param $node "" mntdev)
4629 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4631 for dev in $devs; do
4633 *loop*) do_node $node "losetup $dev" | \
4634 sed -e "s/.*(//" -e "s/).*//" ;;
4640 # Get all of the server target devices.
4645 # Master MDS parameters used by lfsck
4646 MDTNODE=$(facet_active_host $SINGLEMDS)
4647 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4651 for node in $(mdts_nodes); do
4652 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4658 for node in $(osts_nodes); do
4659 OSTDEVS[i]=$(get_mnt_devs $node ost)
4664 # Run e2fsck on MDT or OST device.
4669 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4670 local log=$TMP/e2fsck.log
4674 do_node $node $cmd 2>&1 | tee $log
4676 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4678 if [ $MDSCOUNT -gt 1 ]; then
4679 skip "DNE mode isn't supported!"
4683 error "It's not DNE mode."
4688 [ $rc -le $FSCK_MAX_ERR ] ||
4689 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4695 # Run resize2fs on MDT or OST device.
4704 do_facet $facet "$RESIZE2FS $opts $device $size"
4707 # verify a directory is shared among nodes.
4708 check_shared_dir() {
4710 local list=${2:-$(comma_list $(nodes_list))}
4712 [ -z "$dir" ] && return 1
4713 do_rpc_nodes "$list" check_logdir $dir
4714 check_write_access $dir "$list" || return 1
4719 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4720 $LCTL set_param printk=+lfsck
4721 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4723 for k in $(seq $MDSCOUNT); do
4724 # wait up to 10+1 minutes for LFSCK to complete
4725 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4726 mdd.$(facet_svc mds${k}).lfsck_layout |
4727 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4728 error "MDS${k} layout isn't the expected 'completed'"
4729 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4730 mdd.$(facet_svc mds${k}).lfsck_namespace |
4731 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4732 error "MDS${k} namespace isn't the expected 'completed'"
4734 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4735 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4736 awk '/repaired/ { print $2 }' | calc_sum)
4737 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4738 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4739 awk '/repaired/ { print $2 }' | calc_sum)
4740 local repaired=$((rep_mdt + rep_ost))
4741 [ $repaired -eq 0 ] ||
4742 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4745 dump_file_contents() {
4751 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4752 error_noexit false \
4753 "Invalid parameters for dump_file_contents()"
4756 for node in ${nodes}; do
4757 do_node $node "for i in \\\$(find $dir -type f); do
4758 echo ====\\\${i}=======================;
4760 done" >> ${logname}.${node}.log
4764 dump_command_output() {
4770 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4771 error_noexit false \
4772 "Invalid parameters for dump_command_output()"
4776 for node in ${nodes}; do
4777 do_node $node "echo ====${cmd}=======================;
4778 $cmd" >> ${logname}.${node}.log
4785 # dump file contents from /proc/spl in case of zfs test
4786 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4787 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4788 dump_command_output \
4789 "$(osts_nodes)" "zpool events -v" "${logname}"
4792 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4793 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4794 dump_command_output \
4795 "$(mdts_nodes)" "zpool events -v" "${logname}"
4799 check_and_cleanup_lustre() {
4800 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4801 "$TESTSUITE" != "sanity-scrub" ]; then
4805 if is_mounted $MOUNT; then
4806 if $DO_CLEANUP; then
4807 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4808 error "remove sub-test dirs failed"
4812 [ "$ENABLE_QUOTA" ] && restore_quota || true
4815 if [ "$I_UMOUNTED2" = "yes" ]; then
4816 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4819 if [ "$I_MOUNTED2" = "yes" ]; then
4820 cleanup_mount $MOUNT2
4823 if [ "$I_MOUNTED" = "yes" ]; then
4824 cleanupall -f || error "cleanup failed"
4832 wait_for_function () {
4835 # suppress fn both stderr and stdout
4836 if [ "$1" = "--quiet" ]; then
4838 quiet=" > /dev/null 2>&1"
4850 eval $fn $quiet && return 0
4852 wait=$((wait + sleep))
4853 [ $wait -lt $max ] || return 1
4854 echo waiting $fn, $((max - wait)) secs left ...
4864 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4865 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4866 echo "Network not available!"
4870 echo `date +"%H:%M:%S (%s)"` network interface is UP
4878 # Convert a space-delimited list to a comma-delimited list. If the input is
4879 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4881 # echo is used to convert newlines to spaces, since it doesn't
4882 # introduce a trailing space as using "tr '\n' ' '" does
4883 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4889 echo $list | grep -qw $item
4892 # list, excluded are the comma separated lists
4893 exclude_items_from_list () {
4899 for item in ${excluded//,/ }; do
4900 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4902 echo $(comma_list $list)
4905 # list, expand are the comma separated lists
4907 local list=${1//,/ }
4908 local expand=${2//,/ }
4911 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4912 echo $(comma_list $expanded)
4915 testslist_filter () {
4916 local script=$LUSTRE/tests/${TESTSUITE}.sh
4918 [ -f $script ] || return 0
4920 local start_at=$START_AT
4921 local stop_at=$STOP_AT
4923 local var=${TESTSUITE//-/_}_START_AT
4924 [ x"${!var}" != x ] && start_at=${!var}
4925 var=${TESTSUITE//-/_}_STOP_AT
4926 [ x"${!var}" != x ] && stop_at=${!var}
4928 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4929 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4930 /^'${start_at}'$/ {flag = 0}
4931 {if (flag == 1) print $0}
4932 /^'${stop_at}'$/ { flag = 1 }'
4936 (cd `dirname $1`; echo $PWD/`basename $1`)
4940 local types=${1:-"OST MDS MGS"}
4944 for entry in $types; do
4945 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4946 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4949 MGS ) list="$list $name";;
4950 MDS|OST|AGT ) local count=${type}COUNT
4951 for ((i=1; i<=${!count}; i++)) do
4952 list="$list ${name}$i"
4954 * ) error "Invalid facet type"
4958 echo $(comma_list $list)
4961 ##################################
4962 # Adaptive Timeouts funcs
4965 # only check mds, we assume at_max is the same on all nodes
4966 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4967 if [ $at_max -eq 0 ]; then
4978 # suppose that all ost-s have the same $at value set
4979 [ $facet != "ost" ] || facet=ost1
4981 do_facet $facet "lctl get_param -n $at"
4999 if [ $facet == "ost" ]; then
5000 facet=$(get_facets OST)
5001 elif [ $facet == "mds" ]; then
5002 facet=$(get_facets MDS)
5004 hosts=$(expand_list $hosts $(facets_hosts $facet))
5007 do_nodes $hosts lctl set_param at_max=$at_max
5010 ##################################
5014 # OBD_FAIL_MDS_ALL_REQUEST_NET
5016 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
5017 do_facet client "$1" || RC=$?
5018 do_facet $SINGLEMDS lctl set_param fail_loc=0
5023 # OBD_FAIL_MDS_ALL_REPLY_NET
5025 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
5027 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5031 drop_reint_reply() {
5032 # OBD_FAIL_MDS_REINT_NET_REP
5034 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
5036 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
5040 drop_update_reply() {
5041 # OBD_FAIL_OUT_UPDATE_NET_REP
5045 do_facet mds${index} lctl set_param fail_loc=0x1701
5046 do_facet client "$@" || RC=$?
5047 do_facet mds${index} lctl set_param fail_loc=0
5052 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
5055 local timeout=${2:-0}
5056 # default is (obd_timeout / 4) if unspecified
5057 echo "timeout is $timeout/$2"
5058 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
5059 do_facet client "$1" || RC=$?
5060 do_facet client "sync"
5061 do_facet ost1 lctl set_param fail_loc=0
5065 drop_ldlm_cancel() {
5066 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
5068 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5069 do_nodes $list lctl set_param fail_loc=0x304
5071 do_facet client "$@" || RC=$?
5073 do_nodes $list lctl set_param fail_loc=0
5077 drop_bl_callback_once() {
5079 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5080 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5081 do_facet client lctl set_param fail_loc=0x80000305
5082 do_facet client "$@" || rc=$?
5083 do_facet client lctl set_param fail_loc=0
5084 do_facet client lctl set_param fail_val=0
5085 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5089 drop_bl_callback() {
5091 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
5092 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
5093 do_facet client lctl set_param fail_loc=0x305
5094 do_facet client "$@" || rc=$?
5095 do_facet client lctl set_param fail_loc=0
5096 do_facet client lctl set_param fail_val=0
5097 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
5102 #define OBD_FAIL_LDLM_REPLY 0x30c
5104 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5105 do_nodes $list lctl set_param fail_loc=0x30c
5107 do_facet client "$@" || RC=$?
5109 do_nodes $list lctl set_param fail_loc=0
5113 drop_ldlm_reply_once() {
5114 #define OBD_FAIL_LDLM_REPLY 0x30c
5116 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
5117 do_nodes $list lctl set_param fail_loc=0x8000030c
5119 do_facet client "$@" || RC=$?
5121 do_nodes $list lctl set_param fail_loc=0
5129 echo "clearing fail_loc on $facet"
5130 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
5133 set_nodes_failloc () {
5135 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
5138 cancel_lru_locks() {
5139 #$LCTL mark "cancel_lru_locks $1 start"
5140 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
5141 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
5142 #$LCTL mark "cancel_lru_locks $1 stop"
5147 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
5148 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
5149 echo "$DEFAULT_LRU_SIZE"
5154 lctl set_param ldlm.namespaces.*$1*.lru_size=0
5157 lru_resize_disable()
5159 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
5165 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
5171 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
5172 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
5173 echo there is still data in page cache $FILE ?
5174 lctl get_param -n $FILE
5182 DEBUGSAVE="$(lctl get_param -n debug)"
5183 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
5187 [ -n "$DEBUGSAVE" ] &&
5188 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
5192 [ -n "$DEBUGSAVE_SERVER" ] &&
5193 do_nodes $(comma_list $(all_server_nodes)) \
5194 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
5200 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
5203 debug_size_restore() {
5204 [ -n "$DEBUG_SIZE_SAVED" ] && \
5205 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
5209 start_full_debug_logging() {
5214 local DEBUG_SIZE=150
5216 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
5217 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
5220 stop_full_debug_logging() {
5225 # prints bash call stack
5226 print_stack_trace() {
5229 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
5230 local src=${BASH_SOURCE[$i]}
5231 local lineno=${BASH_LINENO[$i-1]}
5232 local funcname=${FUNCNAME[$i]}
5233 echo " = $src:$lineno:$funcname()"
5238 local TYPE=${TYPE:-"FAIL"}
5241 # do not dump logs if $1=false
5242 if [ "x$1" = "xfalse" ]; then
5247 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
5248 (print_stack_trace 2) >&2
5250 # We need to dump the logs on all nodes
5252 gather_logs $(comma_list $(nodes_list))
5256 [ "$TESTSUITELOG" ] &&
5257 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
5258 if [ -z "$*" ]; then
5259 echo "error() without useful message, please fix" > $LOGDIR/err
5261 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
5262 echo "$@" > $LOGDIR/ignore
5264 echo "$@" > $LOGDIR/err
5268 # cleanup the env for failed tests
5272 ##################################
5274 ##################################
5282 local log=$TESTSUITELOG
5284 [ -f "$log" ] && grep -q FAIL $log && status=1
5298 # use only if we are ignoring failures for this test, bugno required.
5299 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
5300 # e.g. error_ignore bz5494 "your message" or
5301 # error_ignore LU-5494 "your message"
5303 local TYPE="IGNORE ($1)"
5308 error_and_remount() {
5310 remount_client $MOUNT
5314 # Throw an error if it's not running in vm - usually for performance
5317 local virt=$(running_in_vm)
5318 if [[ -n "$virt" ]]; then
5319 echo "running in VM '$virt', ignore error"
5320 error_ignore env=$virt "$@"
5327 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
5332 log " SKIP: $TESTSUITE $TESTNAME $@"
5334 if [[ -n "$ALWAYS_SKIPPED" ]]; then
5335 skip_logged $TESTNAME "$@"
5338 echo "$@" > $LOGDIR/skip
5341 [[ -n "$TESTSUITELOG" ]] &&
5342 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
5345 build_test_filter() {
5346 EXCEPT="$EXCEPT $(testslist_filter)"
5349 if [[ $O = [0-9]*-[0-9]* ]]; then
5350 for num in $(seq $(echo $O | tr '-' ' ')); do
5358 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
5359 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
5360 [ "$EXCEPT_SLOW" ] && \
5361 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
5362 for E in $EXCEPT; do
5363 eval EXCEPT_${E}=true
5365 for E in $ALWAYS_EXCEPT; do
5366 eval EXCEPT_ALWAYS_${E}=true
5368 for E in $EXCEPT_SLOW; do
5369 eval EXCEPT_SLOW_${E}=true
5371 for G in $GRANT_CHECK_LIST; do
5372 eval GCHECK_ONLY_${G}=true
5377 if [[ $1 = [a-z]* ]]; then
5384 # print a newline if the last test was skipped
5385 export LAST_SKIPPED=
5386 export ALWAYS_SKIPPED=
5388 # Main entry into test-framework. This is called with the name and
5389 # description of a test. The name is used to find the function to run
5390 # the test using "test_$name".
5392 # This supports a variety of methods of specifying specific test to
5393 # run or not run. These need to be documented...
5398 export base=$(basetest $1)
5399 if [ -n "$ONLY" ]; then
5401 if [ ${!testname}x != x ]; then
5402 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5403 run_one_logged $1 "$2"
5407 if [ ${!testname}x != x ]; then
5408 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5409 run_one_logged $1 "$2"
5419 if [ ${!testname}x != x ]; then
5420 TESTNAME=test_$1 skip "skipping excluded test $1"
5423 testname=EXCEPT_$base
5424 if [ ${!testname}x != x ]; then
5425 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5428 testname=EXCEPT_ALWAYS_$1
5429 if [ ${!testname}x != x ]; then
5430 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5433 testname=EXCEPT_ALWAYS_$base
5434 if [ ${!testname}x != x ]; then
5435 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5438 testname=EXCEPT_SLOW_$1
5439 if [ ${!testname}x != x ]; then
5440 TESTNAME=test_$1 skip "skipping SLOW test $1"
5443 testname=EXCEPT_SLOW_$base
5444 if [ ${!testname}x != x ]; then
5445 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5451 run_one_logged $1 "$2"
5458 load_module ../libcfs/libcfs/libcfs
5470 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5475 strace -o $TMP/$1.strace -ttt $*
5477 log "FINISHED: $*: rc $RC"
5484 banner test complete, duration $duration sec
5485 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5486 echo duration $duration >>$TESTSUITELOG
5490 # Set TEST_STATUS here. It will be used for logging the result.
5493 if [[ -f $LOGDIR/err ]]; then
5495 elif [[ -f $LOGDIR/skip ]]; then
5498 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5502 local FFREE=$(do_node $SINGLEMDS \
5503 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5504 local FTOTAL=$(do_node $SINGLEMDS \
5505 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5507 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5511 echo -n "Resetting fail_loc on all nodes..."
5512 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5513 fail_val=0 2>/dev/null" || true
5519 # Log a message (on all nodes) padded with "=" before and after.
5520 # Also appends a timestamp and prepends the testsuite name.
5523 EQUALS="===================================================================================================="
5525 msg="== ${TESTSUITE} $*"
5527 [[ $last != "=" && $last != " " ]] && msg="$msg "
5528 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5529 # always include at least == after the message
5530 log "$msg== $(date +"%H:%M:%S (%s)")"
5533 check_dmesg_for_errors() {
5535 local errors="VFS: Busy inodes after unmount of\|\
5536 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5537 group descriptors corrupted"
5539 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5540 [ -z "$res" ] && return 0
5541 echo "Kernel error detected: $res"
5546 # Run a single test function and cleanup after it.
5548 # This function should be run in a subshell so the test func can
5549 # exit() without stopping the whole script.
5554 export tfile=f${testnum}.${TESTSUITE}
5555 export tdir=d${testnum}.${TESTSUITE}
5556 export TESTNAME=test_$testnum
5557 local SAVE_UMASK=`umask`
5560 if ! grep -q $DIR /proc/mounts; then
5564 banner "test $testnum: $message"
5565 test_${testnum} || error "test_$testnum failed with $?"
5568 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5570 check_dmesg_for_errors || error "Error in dmesg detected"
5571 if [ "$PARALLEL" != "yes" ]; then
5572 ps auxww | grep -v grep | grep -q multiop &&
5573 error "multiop still running"
5584 # Wrapper around run_one to ensure:
5585 # - test runs in subshell
5586 # - output of test is saved to separate log file for error reporting
5587 # - test result is saved to data file
5590 local BEFORE=$(date +%s)
5592 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5593 local test_log=$LOGDIR/$name
5594 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5595 local zfs_debug_log=$LOGDIR/$zfs_log_name
5597 rm -rf $LOGDIR/ignore
5599 local SAVE_UMASK=$(umask)
5603 log_sub_test_begin test_${1}
5604 (run_one $1 "$2") 2>&1 | tee -i $test_log
5605 local RC=${PIPESTATUS[0]}
5607 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5608 echo "test_$1 returned $RC" | tee $LOGDIR/err
5610 duration=$(($(date +%s) - $BEFORE))
5611 pass "$1" "(${duration}s)"
5613 if [[ -f $LOGDIR/err ]]; then
5614 TEST_ERROR=$(cat $LOGDIR/err)
5615 elif [[ -f $LOGDIR/ignore ]]; then
5616 TEST_ERROR=$(cat $LOGDIR/ignore)
5617 elif [[ -f $LOGDIR/skip ]]; then
5618 TEST_ERROR=$(cat $LOGDIR/skip)
5620 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5622 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5626 if [ -f $LOGDIR/err ]; then
5627 log_zfs_info "$zfs_debug_log"
5628 $FAIL_ON_ERROR && exit $RC
5637 # Print information of skipped tests to result.yml
5640 log_sub_test_begin $1
5642 log_sub_test_end "SKIP" "0" "0" "$@"
5646 (cd $(dirname $1); echo $PWD/$(basename $1))
5651 export base=$(basetest $1)
5652 [ "$CHECK_GRANT" == "no" ] && return 0
5654 testnamebase=GCHECK_ONLY_${base}
5655 testname=GCHECK_ONLY_$1
5656 [ ${!testnamebase}x == x -a ${!testname}x == x ] && return 0
5658 echo -n "checking grant......"
5660 local clients=$CLIENTS
5661 [ -z "$clients" ] && clients=$(hostname)
5663 # sync all the data and make sure no pending data on server
5664 do_nodes $clients sync
5667 client_grant=$(do_nodes $clients \
5668 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5669 awk '{ total += $1 } END { printf("%0.0f", total) }')
5672 # which is tot_granted less grant_precreate
5673 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5675 "obdfilter.${FSNAME}-OST*.{tot_granted,tot_pending,grant_precreate}" |
5676 sed 's/=/ /'| awk '/tot_granted/{ total += $2 };
5677 /tot_pending/{ total -= $2 };
5678 /grant_precreate/{ total -= $2 };
5679 END { printf("%0.0f", total) }')
5681 # check whether client grant == server grant
5682 if [[ $client_grant -ne $server_grant ]]; then
5683 do_nodes $(comma_list $(osts_nodes)) \
5684 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
5685 "obdfilter.${FSNAME}-OST*.grant_*"
5686 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5687 error "failed: client:${client_grant} server: ${server_grant}."
5689 echo "pass: client:${client_grant} server: ${server_grant}"
5693 ########################
5699 ost=`echo $1 | awk -F_ '{print $3}'`
5700 if [ -z $ost ]; then
5701 ost=`echo $1 | sed 's/-osc.*//'`
5706 ostuuid_from_index()
5708 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5711 ostname_from_index() {
5712 local uuid=$(ostuuid_from_index $1)
5716 index_from_ostuuid()
5718 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5721 mdtuuid_from_index()
5723 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5727 # Return unique identifier for given hostname
5730 echo $host_name | md5sum | cut -d' ' -f1
5734 # Returns list of ip addresses for each interface
5736 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5741 # Cache address list to avoid mutiple execution of local_addr_list
5742 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5744 for i in $LOCAL_ADDR_LIST ; do
5745 [[ "$i" == "$addr" ]] && return 0
5752 local is_local="IS_LOCAL_$(host_id $host_name)"
5753 if [ -z "${!is_local-}" ] ; then
5755 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5756 is_local_addr "$host_ip" && eval $is_local=1
5758 [[ "${!is_local}" == "1" ]]
5763 local_node $node && return 1
5770 for node in $(mdts_nodes); do
5771 remote_node $node && return 0
5778 [ -n "$CLIENTONLY" ] && return 0 || true
5779 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5784 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5785 MSKIPPED=1 && return 1
5792 for node in $(osts_nodes) ; do
5793 remote_node $node && return 0
5800 [ -n "$CLIENTONLY" ] && return 0 || true
5801 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5806 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5807 OSKIPPED=1 && return 1
5813 [ -n "$CLIENTONLY" ] && return 0 || true
5815 MGS=$(facet_host mgs)
5816 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5821 remote_mds_nodsh || remote_ost_nodsh || \
5822 $(single_local_node $(comma_list $(nodes_list)))
5826 remote_ost && remote_mds
5829 # Get the active nodes for facets.
5837 for facet in ${facets//,/ }; do
5838 nodes="$nodes $(facet_active_host $facet)"
5841 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5845 # Get name of the active MGS node.
5847 echo -n $(facets_nodes $(get_facets MGS))
5850 # Get all of the active MDS nodes.
5852 echo -n $(facets_nodes $(get_facets MDS))
5855 # Get all of the active OSS nodes.
5857 echo -n $(facets_nodes $(get_facets OST))
5860 # Get all of the active AGT (HSM agent) nodes.
5862 echo -n $(facets_nodes $(get_facets AGT))
5865 # Get all of the client nodes and active server nodes.
5867 local nodes=$HOSTNAME
5871 # CLIENTS (if specified) contains the local client
5872 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5874 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5875 nodes="$nodes $(facets_nodes $(get_facets))"
5878 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5882 # Get all of the remote client nodes and remote active server nodes.
5883 remote_nodes_list () {
5884 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5887 # Get all of the MDS nodes, including active and passive nodes.
5891 local nodes="${mds_HOST} ${mdsfailover_HOST}"
5895 for i in $(seq $MDSCOUNT); do
5897 failover_host=mds${i}failover_HOST
5898 nodes="$nodes ${!host} ${!failover_host}"
5901 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5905 # Get all of the OSS nodes, including active and passive nodes.
5909 local nodes="${ost_HOST} ${ostfailover_HOST}"
5913 for i in $(seq $OSTCOUNT); do
5915 failover_host=ost${i}failover_HOST
5916 nodes="$nodes ${!host} ${!failover_host}"
5919 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5923 # Get all of the server nodes, including active and passive nodes.
5924 all_server_nodes () {
5929 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5931 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5935 # Get all of the client and server nodes, including active and passive nodes.
5937 local nodes=$HOSTNAME
5941 # CLIENTS (if specified) contains the local client
5942 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5944 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5945 nodes="$nodes $(all_server_nodes)"
5948 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5952 init_clients_lists () {
5953 # Sanity check: exclude the local client from RCLIENTS
5954 local clients=$(hostlist_expand "$RCLIENTS")
5955 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5957 # Sanity check: exclude the dup entries
5958 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5960 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5962 # Sanity check: exclude the dup entries from CLIENTS
5963 # for those configs which has SINGLCLIENT set to local client
5964 clients=$(for i in $clients; do echo $i; done | sort -u)
5966 CLIENTS=$(comma_list $clients)
5967 local -a remoteclients=($RCLIENTS)
5968 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5969 varname=CLIENT$((i + 2))
5970 eval $varname=${remoteclients[i]}
5973 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5976 get_random_entry () {
5979 rnodes=${rnodes//,/ }
5981 local -a nodes=($rnodes)
5982 local num=${#nodes[@]}
5983 local i=$((RANDOM * num * 2 / 65536))
5989 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5993 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5994 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5999 echo $nodes | wc -w || true
6003 local nodes=$(osts_nodes)
6004 local osscount=$(get_node_count "$nodes")
6005 [ ! "$OSTCOUNT" = "$osscount" ]
6009 local nodes=$(mdts_nodes)
6010 local mdtcount=$(get_node_count "$nodes")
6011 [ ! "$MDSCOUNT" = "$mdtcount" ]
6014 generate_machine_file() {
6015 local nodes=${1//,/ }
6016 local machinefile=$2
6018 for node in $nodes; do
6019 echo $node >>$machinefile || \
6020 { echo "can not generate machinefile $machinefile" && return 1; }
6025 local file=$1/stripe
6028 $LFS getstripe -v $file || error "getstripe $file failed"
6032 setstripe_nfsserver () {
6034 local nfsexportdir=$2
6038 local -a nfsexport=($(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
6039 { print $1 }' /proc/mounts | cut -f 1 -d :))
6041 # check that only one nfs mounted
6042 [[ -z $nfsexport ]] && echo "$dir is not nfs mounted" && return 1
6043 (( ${#nfsexport[@]} == 1 )) ||
6044 error "several nfs mounts found for $dir: ${nfsexport[@]} !"
6046 do_nodev ${nfsexport[0]} lfs setstripe $nfsexportdir "$@"
6049 # Check and add a test group.
6055 local gid=$(getent group $group_name | cut -d: -f3)
6056 if [[ -n "$gid" ]]; then
6057 [[ "$gid" -eq "$group_id" ]] || {
6058 error_noexit "inconsistent group ID:" \
6059 "new: $group_id, old: $gid"
6063 groupadd -g $group_id $group_name
6070 # Check and add a test user.
6083 local uid=$(getent passwd $user_name | cut -d: -f3)
6084 if [[ -n "$uid" ]]; then
6085 if [[ "$uid" -eq "$user_id" ]]; then
6086 local dir=$(getent passwd $user_name | cut -d: -f6)
6087 if [[ "$dir" != "$home" ]]; then
6089 usermod -d $home $user_name
6093 error_noexit "inconsistent user ID:" \
6094 "new: $user_id, old: $uid"
6099 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
6106 check_runas_id_ret() {
6108 local myRUNAS_UID=$1
6109 local myRUNAS_GID=$2
6112 if [ -z "$myRUNAS" ]; then
6113 error_exit "myRUNAS command must be specified for check_runas_id"
6116 $myRUNAS krb5_login.sh || \
6117 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
6119 mkdir $DIR/d0_runas_test
6121 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
6122 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
6123 rm -rf $DIR/d0_runas_test
6128 local myRUNAS_UID=$1
6129 local myRUNAS_GID=$2
6132 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
6133 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
6134 Please set RUNAS_ID to some UID which exists on MDS and client or
6135 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
6138 # obtain the UID/GID for MPI_USER
6142 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
6143 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
6145 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
6146 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
6149 # obtain and cache Kerberos ticket-granting ticket
6150 refresh_krb5_tgt() {
6151 local myRUNAS_UID=$1
6152 local myRUNAS_GID=$2
6155 if [ -z "$myRUNAS" ]; then
6156 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
6159 CLIENTS=${CLIENTS:-$HOSTNAME}
6160 do_nodes $CLIENTS "set -x
6161 if ! $myRUNAS krb5_login.sh; then
6162 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
6167 # Run multiop in the background, but wait for it to print
6168 # "PAUSING" to its stdout before returning from this function.
6169 multiop_bg_pause() {
6170 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
6174 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
6177 echo "$MULTIOP_PROG $FILE v$ARGS"
6178 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
6180 echo "TMPPIPE=${TMPPIPE}"
6181 read -t 60 multiop_output < $TMPPIPE
6182 if [ $? -ne 0 ]; then
6187 if [ "$multiop_output" != "PAUSING" ]; then
6188 echo "Incorrect multiop output: $multiop_output"
6203 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
6209 inodes_available () {
6210 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
6211 sort -un | head -n1) || return 1
6215 mdsrate_inodes_available () {
6216 local min_inodes=$(inodes_available)
6217 echo $((min_inodes * 99 / 100))
6220 # reset stat counters
6222 local paramfile="$1"
6223 lctl set_param -n $paramfile=0
6228 local paramfile="$1"
6230 lctl get_param -n $paramfile |
6231 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
6235 awk '{sum += $1} END { printf("%0.0f", sum) }'
6238 calc_osc_kbytes () {
6239 df $MOUNT > /dev/null
6240 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
6243 # save_lustre_params(comma separated facet list, parameter_mask)
6244 # generate a stream of formatted strings (<facet> <param name>=<param value>)
6245 save_lustre_params() {
6250 for facet in ${facets//,/ }; do
6251 facet_svc=$(facet_svc $facet)
6253 "params=\\\$($LCTL get_param $2);
6254 [[ -z \\\"$facet_svc\\\" ]] && param= ||
6255 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
6256 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
6257 while read s; do echo $facet \\\$s;
6258 done <<< \\\"\\\$param\\\""
6262 # restore lustre parameters from input stream, produces by save_lustre_params
6263 restore_lustre_params() {
6268 while IFS=" =" read facet name val; do
6269 do_facet $facet "$LCTL set_param -n $name $val"
6273 check_node_health() {
6274 local nodes=${1:-$(comma_list $(nodes_list))}
6276 for node in ${nodes//,/ }; do
6277 check_network "$node" 5
6278 if [ $? -eq 0 ]; then
6279 do_node $node "rc=0;
6280 val=\\\$($LCTL get_param -n catastrophe 2>&1);
6281 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
6282 echo \\\$(hostname -s): \\\$val;
6285 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
6290 mdsrate_cleanup () {
6292 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
6293 --nfiles $3 --dir $4 --filefmt $5 $6
6298 delayed_recovery_enabled () {
6299 local var=${SINGLEMDS}_svc
6300 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
6303 ########################
6305 convert_facet2label() {
6308 if [ x$facet = xost ]; then
6312 local varsvc=${facet}_svc
6314 if [ -n ${!varsvc} ]; then
6317 error "No lablel for $facet!"
6321 get_clientosc_proc_path() {
6325 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
6326 # used by MDT would not be changed.
6327 # mdt lov: fsname-mdtlov
6328 # mdt osc: fsname-OSTXXXX-osc
6329 mds_on_old_device() {
6330 local mds=${1:-"$SINGLEMDS"}
6332 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
6333 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
6334 > /dev/null 2>&1" && return 0
6339 get_mdtosc_proc_path() {
6341 local ost_label=${2:-"*OST*"}
6343 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
6344 local mdt_label=$(convert_facet2label $mds_facet)
6345 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
6347 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
6348 mds_on_old_device $mds_facet; then
6349 echo "${ost_label}-osc"
6350 elif [[ $ost_label = *OST* ]]; then
6351 echo "${ost_label}-osc-${mdt_index}"
6353 echo "${ost_label}-osp-${mdt_index}"
6357 get_osc_import_name() {
6360 local label=$(convert_facet2label $ost)
6362 if [ "${facet:0:3}" = "mds" ]; then
6363 get_mdtosc_proc_path $facet $label
6367 get_clientosc_proc_path $label
6371 _wait_import_state () {
6374 local maxtime=${3:-$(max_recovery_time)}
6375 local error_on_failure=${4:-1}
6379 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6380 while [ "${CONN_STATE}" != "${expected}" ]; do
6381 if [ "${expected}" == "DISCONN" ]; then
6382 # for disconn we can check after proc entry is removed
6383 [ "x${CONN_STATE}" == "x" ] && return 0
6384 # with AT enabled, we can have connect request timeout near of
6385 # reconnect timeout and test can't see real disconnect
6386 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
6388 if [ $i -ge $maxtime ]; then
6389 [ $error_on_failure -ne 0 ] && \
6390 error "can't put import for $CONN_PROC into ${expected}" \
6391 "state after $i sec, have ${CONN_STATE}"
6395 # Add uniq for multi-mount case
6396 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6400 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6404 wait_import_state() {
6407 local maxtime=${3:-$(max_recovery_time)}
6408 local error_on_failure=${4:-1}
6411 for param in ${params//,/ }; do
6412 _wait_import_state $state $param $maxtime $error_on_failure || return
6416 wait_import_state_mount() {
6417 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6421 wait_import_state $*
6424 # One client request could be timed out because server was not ready
6425 # when request was sent by client.
6426 # The request timeout calculation details :
6428 # /* We give the server rq_timeout secs to process the req, and
6429 # add the network latency for our local timeout. */
6430 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6431 # ptlrpc_at_get_net_latency(request) ;
6433 # ptlrpc_connect_import ()
6434 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6437 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6438 # ptlrpc_at_get_net_latency(request) ->
6439 # at_get (max (iat_net_latency=0, at_min)) = at_min
6442 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6443 # INITIAL_CONNECT_TIMEOUT + at_min
6445 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6446 # because we can not get this value in runtime,
6447 # the value depends on configure options, and it is not stored in /proc.
6449 # #define CONNECTION_SWITCH_MIN 5U
6450 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6452 request_timeout () {
6455 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6456 local init_connect_timeout=$TIMEOUT
6457 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6459 local at_min=$(at_get $facet at_min)
6461 echo $(( init_connect_timeout + at_min ))
6464 _wait_osc_import_state() {
6468 local target=$(get_osc_import_name $facet $ost_facet)
6469 local param="osc.${target}.ost_server_uuid"
6473 # 1. wait the deadline of client 1st request (it could be skipped)
6474 # 2. wait the deadline of client 2nd request
6475 local maxtime=$(( 2 * $(request_timeout $facet)))
6477 if [[ $facet == client* ]]; then
6478 # During setup time, the osc might not be setup, it need wait
6479 # until list_param can return valid value.
6480 params=$($LCTL list_param $param 2>/dev/null || true)
6481 while [ -z "$params" ]; do
6482 if [ $i -ge $maxtime ]; then
6483 echo "can't get $param in $maxtime secs"
6488 params=$($LCTL list_param $param 2>/dev/null || true)
6492 if [[ $ost_facet = mds* ]]; then
6493 # no OSP connection to itself
6494 if [[ $facet = $ost_facet ]]; then
6497 param="osp.${target}.mdt_server_uuid"
6501 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6502 wait_import_state $expected "$params" $maxtime; then
6503 error "$facet: import is not in $expected state after $maxtime"
6510 wait_osc_import_state() {
6516 if [[ $facet = mds ]]; then
6517 for num in $(seq $MDSCOUNT); do
6518 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6521 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6525 _wait_mgc_import_state() {
6528 local error_on_failure=${3:-1}
6529 local param="mgc.*.mgs_server_uuid"
6533 # 1. wait the deadline of client 1st request (it could be skipped)
6534 # 2. wait the deadline of client 2nd request
6535 local maxtime=$(( 2 * $(request_timeout $facet)))
6537 if [[ $facet == client* ]]; then
6538 # During setup time, the osc might not be setup, it need wait
6539 # until list_param can return valid value. And also if there
6540 # are mulitple osc entries we should list all of them before
6542 params=$($LCTL list_param $param 2>/dev/null || true)
6543 while [ -z "$params" ]; do
6544 if [ $i -ge $maxtime ]; then
6545 echo "can't get $param in $maxtime secs"
6550 params=$($LCTL list_param $param 2>/dev/null || true)
6553 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6554 wait_import_state $expected "$params" $maxtime \
6555 $error_on_failure; then
6556 if [ $error_on_failure -ne 0 ]; then
6557 error "import is not in ${expected} state"
6565 wait_mgc_import_state() {
6568 local error_on_failure=${3:-1}
6571 if [[ $facet = mds ]]; then
6572 for num in $(seq $MDSCOUNT); do
6573 _wait_mgc_import_state mds$num "$expected" \
6574 $error_on_failure || return
6577 _wait_mgc_import_state "$facet" "$expected"
6578 $error_on_failure || return
6582 wait_dne_interconnect() {
6585 if [ $MDSCOUNT -gt 1 ]; then
6586 for num in $(seq $MDSCOUNT); do
6587 wait_osc_import_state mds mds$num FULL
6592 get_clientmdc_proc_path() {
6596 get_clientmgc_proc_path() {
6604 [ -z "$list" ] && return 0
6606 # Add paths to lustre tests for 32 and 64 bit systems.
6607 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6608 local TESTPATH="$RLUSTRE/tests:"
6609 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6610 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6613 wait_clients_import_state () {
6620 if [ "$FAILURE_MODE" = HARD ]; then
6621 facets=$(facets_on_host $(facet_active_host $facet))
6624 for facet in ${facets//,/ }; do
6625 local label=$(convert_facet2label $facet)
6628 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6629 $label).ost_server_uuid" ;;
6630 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6631 $label).mds_server_uuid" ;;
6632 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6633 $label).mgs_server_uuid" ;;
6634 *) error "unknown facet!" ;;
6637 local params=$(expand_list $params $proc_path)
6640 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6642 error "import is not in ${expected} state"
6654 # wait until all MDTs are in the expected state
6655 for ((num = 1; num <= $MDSCOUNT; num++)); do
6656 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
6659 if [ $facet = "mds" ]; then
6660 mproc="osp.$mdtosp.active"
6661 [ $num -eq $((tgt_idx + 1)) ] && continue
6663 mproc="osc.$mdtosp.active"
6669 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
6673 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
6674 if [ $result -eq $expected ]; then
6675 echo -n "target updated after"
6676 echo "$wait sec (got $result)"
6680 if [ $wait -eq $max ]; then
6681 error "$tgt_name: wanted $expected got $result"
6683 echo "Waiting $((max - wait)) secs for $tgt_name"
6693 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6694 $LCTL get_param obdfilter.*.kbytesavail))
6695 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6696 $LCTL get_param -n obdfilter.*.tot_granted))
6697 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6698 $LCTL get_param -n obdfilter.*.kbytestotal))
6699 for ((i=0; i<${#AVAILA[@]}; i++)); do
6700 local -a AVAIL1=(${AVAILA[$i]//=/ })
6701 local -a TOTAL=(${TOTALA[$i]//=/ })
6702 GRANT=$((${GRANTA[$i]}/1024))
6703 # allow 1% of total space in bavail because of delayed
6704 # allocation with ZFS which might release some free space after
6705 # txg commit. For small devices, we set a mininum of 8MB
6706 local LIMIT=$((${TOTAL} / 100 + 8000))
6707 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6708 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6709 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6710 echo " FULL" || echo
6716 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6719 check_pool_not_exist() {
6720 local fsname=${1%%.*}
6721 local poolname=${1##$fsname.}
6722 [[ $# -ne 1 ]] && return 0
6723 [[ x$poolname = x ]] && return 0
6724 list_pool $fsname | grep -w $1 && return 1
6729 local fsname=${1%%.*}
6730 local poolname=${1##$fsname.}
6732 trap "destroy_test_pools $fsname" EXIT
6733 do_facet mgs lctl pool_new $1
6735 # get param should return err unless pool is created
6736 [[ $RC -ne 0 ]] && return $RC
6738 for mds_id in $(seq $MDSCOUNT); do
6739 local mdt_id=$((mds_id-1))
6740 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6741 wait_update_facet mds$mds_id \
6742 "lctl get_param -n lod.$lodname.pools.$poolname \
6743 2>/dev/null || echo foo" "" ||
6744 error "mds$mds_id: pool_new failed $1"
6746 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6747 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6753 add_pool_to_list () {
6754 local fsname=${1%%.*}
6755 local poolname=${1##$fsname.}
6757 local listvar=${fsname}_CREATED_POOLS
6758 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6762 remove_pool_from_list () {
6763 local fsname=${1%%.*}
6764 local poolname=${1##$fsname.}
6766 local listvar=${fsname}_CREATED_POOLS
6767 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6771 destroy_pool_int() {
6773 local OSTS=$(list_pool $1)
6774 for ost in $OSTS; do
6775 do_facet mgs lctl pool_remove $1 $ost
6777 do_facet mgs lctl pool_destroy $1
6780 # <fsname>.<poolname> or <poolname>
6782 local fsname=${1%%.*}
6783 local poolname=${1##$fsname.}
6785 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6789 check_pool_not_exist $fsname.$poolname
6790 [[ $? -eq 0 ]] && return 0
6792 destroy_pool_int $fsname.$poolname
6794 [[ $RC -ne 0 ]] && return $RC
6795 for mds_id in $(seq $MDSCOUNT); do
6796 local mdt_id=$((mds_id-1))
6797 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6798 wait_update_facet mds$mds_id \
6799 "lctl get_param -n lod.$lodname.pools.$poolname \
6800 2>/dev/null || echo foo" "foo" ||
6801 error "mds$mds_id: destroy pool failed $1"
6803 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6804 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6806 remove_pool_from_list $fsname.$poolname
6812 local fsname=${1:-$FSNAME}
6814 local listvar=${fsname}_CREATED_POOLS
6816 [ x${!listvar} = x ] && return 0
6818 echo "Destroy the created pools: ${!listvar}"
6819 for poolname in ${!listvar//,/ }; do
6820 destroy_pool $fsname.$poolname
6824 destroy_test_pools () {
6826 local fsname=${1:-$FSNAME}
6827 destroy_pools $fsname || true
6833 local ts=$(date +%s)
6836 if [[ ! -f "$YAML_LOG" ]]; then
6837 # init_logging is not performed before gather_logs,
6838 # so the $LOGDIR needs to be checked here
6839 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6842 [ -f $LOGDIR/shared ] && docp=false
6844 # dump lustre logs, dmesg
6846 prefix="$TESTLOG_PREFIX.$TESTNAME"
6848 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6850 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6851 echo "Dumping logs only on local client."
6852 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6853 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6858 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6859 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6861 if [ ! -f $LOGDIR/shared ]; then
6862 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6875 for i in $(seq 0 $num_mntpts); do
6876 cmd="ls -laf ${mntpt_root}$i/$dir"
6882 for pid in $pids; do
6889 # check_and_start_recovery_timer()
6890 # service_time = at_est2timeout(service_time);
6891 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6892 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6894 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6895 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6896 #define CONNECTION_SWITCH_MIN 5
6897 #define CONNECTION_SWITCH_INC 5
6898 max_recovery_time() {
6899 local init_connect_timeout=$((TIMEOUT / 20))
6900 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6902 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6903 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6905 echo -n $service_time
6908 recovery_time_min() {
6909 local connection_switch_min=5
6910 local connection_switch_inc=5
6911 local connection_switch_max
6912 local reconnect_delay_max
6913 local initial_connect_timeout
6917 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6918 (($connection_switch_min > $TIMEOUT)) &&
6919 max=$connection_switch_min || max=$TIMEOUT
6920 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6922 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6923 timeout_20=$((TIMEOUT/20))
6924 (($connection_switch_min > $timeout_20)) &&
6925 initial_connect_timeout=$connection_switch_min ||
6926 initial_connect_timeout=$timeout_20
6928 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6929 initial_connect_timeout))
6930 echo $((2 * reconnect_delay_max))
6933 get_clients_mount_count () {
6934 local clients=${CLIENTS:-$HOSTNAME}
6936 # we need to take into account the clients mounts and
6937 # exclude mds/ost mounts if any;
6938 do_nodes $clients cat /proc/mounts | grep lustre |
6939 grep -w $MOUNT | wc -l
6943 PROC_CLI="srpc_info"
6944 PROC_CON="srpc_contexts"
6952 if [ $M -lt $N ]; then
6956 while [ $N -lt $M ]; do
6966 calc_connection_cnt() {
6969 # MDT->MDT = 2 * C(M, 2)
6973 comb_m2=$(combination $MDSCOUNT 2)
6975 local num_clients=$(get_clients_mount_count)
6977 local cnt_mdt2mdt=$((comb_m2 * 2))
6978 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6979 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6980 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6981 if is_mounted $MOUNT2; then
6982 cnt_cli2mdt=$((cnt_cli2mdt * 2))
6983 cnt_cli2ost=$((cnt_cli2ost * 2))
6991 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6992 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6993 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
6994 + cnt_cli2ost + cnt_cli2mdt))
7008 local cmd="$tgt.srpc.flavor"
7010 if [ $net == "any" ]; then
7015 if [ $dir != "any" ]; then
7020 log "Setting sptlrpc rule: $cmd"
7021 do_facet mgs "$LCTL conf_param $cmd"
7027 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
7037 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
7038 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
7040 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
7042 if [ "x$bulkspec" != "x" ]; then
7043 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
7045 if [ "x$algs" != "x" ]; then
7046 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
7048 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
7049 if [ $bulk == "bulkn" ]; then
7050 bulk_count=`echo "$output" | grep "bulk flavor" \
7051 | grep "null/null" | wc -l`
7052 elif [ $bulk == "bulki" ]; then
7053 bulk_count=`echo "$output" | grep "bulk flavor" \
7054 | grep "/null" | grep -v "null/" | wc -l`
7056 bulk_count=`echo "$output" | grep "bulk flavor" \
7057 | grep -v "/null" | grep -v "null/" | wc -l`
7061 [ $bulk_count -lt $count ] && count=$bulk_count
7072 local clients=${CLIENTS:-$HOSTNAME}
7074 for c in ${clients//,/ }; do
7075 local output=$(do_node $c lctl get_param -n \
7076 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
7077 local tmpcnt=$(count_flvr "$output" $flavor)
7078 if $GSS_SK && [ $flavor != "null" ]; then
7079 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7080 output=$(do_node $c lctl get_param -n \
7081 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
7082 local outcon=$(count_contexts "$output")
7083 if [ "$outcon" -lt "$tmpcnt" ]; then
7087 cnt=$((cnt + tmpcnt))
7097 local clients=${CLIENTS:-$HOSTNAME}
7099 for c in ${clients//,/ }; do
7100 local output=$(do_node $c lctl get_param -n \
7101 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
7102 local tmpcnt=$(count_flvr "$output" $flavor)
7103 if $GSS_SK && [ $flavor != "null" ]; then
7104 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7105 output=$(do_node $c lctl get_param -n \
7106 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
7107 local outcon=$(count_contexts "$output")
7108 if [ "$outcon" -lt "$tmpcnt" ]; then
7112 cnt=$((cnt + tmpcnt))
7122 if [ $MDSCOUNT -le 1 ]; then
7127 for num in `seq $MDSCOUNT`; do
7128 local output=$(do_facet mds$num lctl get_param -n \
7129 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
7130 local tmpcnt=$(count_flvr "$output" $flavor)
7131 if $GSS_SK && [ $flavor != "null" ]; then
7132 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7133 output=$(do_facet mds$num lctl get_param -n \
7134 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
7135 local outcon=$(count_contexts "$output")
7136 if [ "$outcon" -lt "$tmpcnt" ]; then
7140 cnt=$((cnt + tmpcnt))
7151 for num in `seq $MDSCOUNT`; do
7152 mdtosc=$(get_mdtosc_proc_path mds$num)
7153 mdtosc=${mdtosc/-MDT*/-MDT\*}
7154 local output=$(do_facet mds$num lctl get_param -n \
7155 osc.$mdtosc.$PROC_CLI 2>/dev/null)
7156 local tmpcnt=$(count_flvr "$output" $flavor)
7157 if $GSS_SK && [ $flavor != "null" ]; then
7158 # tmpcnt=min(contexts,flavors) to ensure SK context is on
7159 output=$(do_facet mds$num lctl get_param -n \
7160 osc.$mdtosc.$PROC_CON 2>/dev/null)
7161 local outcon=$(count_contexts "$output")
7162 if [ "$outcon" -lt "$tmpcnt" ]; then
7166 cnt=$((cnt + tmpcnt))
7175 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
7177 count_flvr "$output" $flavor
7182 local dir=$1 # from to
7183 local flavor=$2 # flavor expected
7186 if [ $dir == "cli2mdt" ]; then
7187 res=`flvr_cnt_cli2mdt $flavor`
7188 elif [ $dir == "cli2ost" ]; then
7189 res=`flvr_cnt_cli2ost $flavor`
7190 elif [ $dir == "mdt2mdt" ]; then
7191 res=`flvr_cnt_mdt2mdt $flavor`
7192 elif [ $dir == "mdt2ost" ]; then
7193 res=`flvr_cnt_mdt2ost $flavor`
7194 elif [ $dir == "all2ost" ]; then
7195 res1=`flvr_cnt_mdt2ost $flavor`
7196 res2=`flvr_cnt_cli2ost $flavor`
7197 res=$((res1 + res2))
7198 elif [ $dir == "all2mdt" ]; then
7199 res1=`flvr_cnt_mdt2mdt $flavor`
7200 res2=`flvr_cnt_cli2mdt $flavor`
7201 res=$((res1 + res2))
7202 elif [ $dir == "all2all" ]; then
7203 res1=`flvr_cnt_mdt2ost $flavor`
7204 res2=`flvr_cnt_cli2ost $flavor`
7205 res3=`flvr_cnt_mdt2mdt $flavor`
7206 res4=`flvr_cnt_cli2mdt $flavor`
7207 res=$((res1 + res2 + res3 + res4))
7215 local dir=$1 # from to
7216 local flavor=$2 # flavor expected
7217 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
7218 local WAITFLAVOR_MAX=20 # how many retries before abort?
7221 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
7222 echo -n "checking $dir..."
7223 res=$(do_check_flavor $dir $flavor)
7224 echo "found $res/$expect $flavor connections"
7225 [ $res -ge $expect ] && return 0
7229 echo "Error checking $flavor of $dir: expect $expect, actual $res"
7230 # echo "Dumping additional logs for SK debug.."
7231 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
7233 gather_logs $(comma_list $(nodes_list))
7238 restore_to_default_flavor()
7240 local proc="mgs.MGS.live.$FSNAME"
7242 echo "restoring to default flavor..."
7244 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7245 grep ".srpc.flavor" | wc -l)
7247 # remove all existing rules if any
7248 if [ $nrule -ne 0 ]; then
7249 echo "$nrule existing rules"
7250 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7251 grep ".srpc.flavor."); do
7252 echo "remove rule: $rule"
7253 spec=`echo $rule | awk -F = '{print $1}'`
7254 do_facet mgs "$LCTL conf_param -d $spec"
7258 # verify no rules left
7259 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
7260 grep ".srpc.flavor." | wc -l)
7261 [ $nrule -ne 0 ] && error "still $nrule rules left"
7263 # wait for default flavor to be applied
7266 set_rule $FSNAME any any $SK_FLAVOR
7267 wait_flavor all2all $SK_FLAVOR
7269 set_rule $FSNAME any cli2mdt $SK_FLAVOR
7270 set_rule $FSNAME any cli2ost $SK_FLAVOR
7271 wait_flavor cli2mdt $SK_FLAVOR
7272 wait_flavor cli2ost $SK_FLAVOR
7274 echo "GSS_SK now at default flavor: $SK_FLAVOR"
7276 wait_flavor all2all null
7282 local flavor=${1:-null}
7284 echo "setting all flavor to $flavor"
7286 # FIXME need parameter to this fn
7287 # and remove global vars
7288 local cnt_all2all=$(calc_connection_cnt all2all)
7290 local res=$(do_check_flavor all2all $flavor)
7291 if [ $res -eq $cnt_all2all ]; then
7292 echo "already have total $res $flavor connections"
7296 echo "found $res $flavor out of total $cnt_all2all connections"
7297 restore_to_default_flavor
7299 [[ $flavor = null ]] && return 0
7301 if $GSS_SK && [ $flavor != "null" ]; then
7303 set_rule $FSNAME any any $flavor
7304 wait_flavor all2all $flavor
7306 set_rule $FSNAME any cli2mdt $flavor
7307 set_rule $FSNAME any cli2ost $flavor
7308 set_rule $FSNAME any mdt2ost null
7309 set_rule $FSNAME any mdt2mdt null
7310 wait_flavor cli2mdt $flavor
7311 wait_flavor cli2ost $flavor
7313 echo "GSS_SK now at flavor: $flavor"
7315 set_rule $FSNAME any any $flavor
7316 wait_flavor all2all $flavor
7323 # Checking for shared logdir
7324 if [ ! -d $dir ]; then
7325 # Not found. Create local logdir
7328 touch $dir/check_file.$(hostname -s)
7333 check_write_access() {
7335 local list=${2:-$(comma_list $(nodes_list))}
7339 for node in ${list//,/ }; do
7340 file=$dir/check_file.$(short_nodename $node)
7341 if [[ ! -f "$file" ]]; then
7342 # Logdir not accessible/writable from this node.
7345 rm -f $file || return 1
7351 [[ -n $YAML_LOG ]] && return
7352 local save_umask=$(umask)
7355 export YAML_LOG=${LOGDIR}/results.yml
7359 # If the yaml log already exists then we will just append to it
7360 if [ ! -f $YAML_LOG ]; then
7361 if check_shared_dir $LOGDIR; then
7362 touch $LOGDIR/shared
7363 echo "Logging to shared log directory: $LOGDIR"
7365 echo "Logging to local directory: $LOGDIR"
7368 yml_nodes_file $LOGDIR >> $YAML_LOG
7369 yml_results_file >> $YAML_LOG
7374 # If modules are not yet loaded then older "lctl lustre_build_version"
7375 # will fail. Use lctl build version instead.
7376 log "Client: $($LCTL lustre_build_version)"
7377 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
7378 do_facet $SINGLEMDS $LCTL --version)"
7379 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
7380 do_facet ost1 $LCTL --version)"
7384 yml_log_test $1 >> $YAML_LOG
7388 yml_log_test_status $@ >> $YAML_LOG
7391 log_sub_test_begin() {
7392 yml_log_sub_test_begin "$@" >> $YAML_LOG
7395 log_sub_test_end() {
7396 yml_log_sub_test_end "$@" >> $YAML_LOG
7402 local llverdev_opts=$2
7403 local devname=$(basename $1)
7404 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
7405 # loop devices aren't in /proc/partitions
7406 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
7408 size=$(($size / 1024 / 1024)) # Gb
7410 local partial_arg=""
7411 # Run in partial (fast) mode if the size
7412 # of a partition > 1 GB
7413 [ $size -gt 1 ] && partial_arg="-p"
7415 llverdev --force $partial_arg $llverdev_opts $dev
7421 local llverfs_opts=$2
7422 local use_partial_arg=$3
7423 local partial_arg=""
7424 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
7426 # Run in partial (fast) mode if the size
7427 # of a partition > 1 GB
7428 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
7430 llverfs $partial_arg $llverfs_opts $dir
7433 #Remove objects from OST
7434 remove_ost_objects() {
7440 local mntpt=$(facet_mntpt $facet)
7441 local opts=$OST_MOUNT_OPTS
7445 echo "removing objects from $ostdev on $facet: $objids"
7446 if ! test -b $ostdev; then
7447 opts=$(csa_add "$opts" -o loop)
7449 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
7452 for i in $objids; do
7453 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
7455 umount -f $mntpt || return $?
7459 #Remove files from MDT
7460 remove_mdt_files() {
7465 local mntpt=$(facet_mntpt $facet)
7466 local opts=$MDS_MOUNT_OPTS
7468 echo "removing files from $mdtdev on $facet: $files"
7469 if [ $(facet_fstype $facet) == ldiskfs ] &&
7470 ! do_facet $facet test -b $mdtdev; then
7471 opts=$(csa_add "$opts" -o loop)
7473 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7477 rm $mntpt/ROOT/$f || { rc=$?; break; }
7479 umount -f $mntpt || return $?
7483 duplicate_mdt_files() {
7488 local mntpt=$(facet_mntpt $facet)
7489 local opts=$MDS_MOUNT_OPTS
7491 echo "duplicating files on $mdtdev on $facet: $files"
7492 mkdir -p $mntpt || return $?
7493 if [ $(facet_fstype $facet) == ldiskfs ] &&
7494 ! do_facet $facet test -b $mdtdev; then
7495 opts=$(csa_add "$opts" -o loop)
7497 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7508 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
7509 pushd $mntpt/ROOT > /dev/null || return $?
7512 touch $f.bad || return $?
7513 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
7515 [ $rc -eq 0 ] || return $rc
7516 setfattr --restore $tmp || return $?
7522 local devs=${1//,/ }
7525 local rslt=$TMP/sgpdd_survey
7527 # sgpdd-survey cleanups ${rslt}.* files
7529 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7535 # returns the canonical name for an ldiskfs device
7540 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7541 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7542 echo dm-\\\${foo##*:};
7544 echo \\\$(basename \\\$dv);
7548 is_sanity_benchmark() {
7549 local benchmarks="dbench bonnie iozone fsx"
7551 for b in $benchmarks; do
7552 if [ "$b" == "$suite" ]; then
7560 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
7564 # Get the available size (KB) of a given obd target.
7571 [[ $facet != client ]] || return 0
7573 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7578 # Get the page size (bytes) on a given facet node.
7582 local size=$(getconf PAGE_SIZE 2>/dev/null)
7584 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7585 echo -n ${size:-4096}
7589 # Get the block count of the filesystem.
7596 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7597 awk '/^Block count:/ {print $3}')
7601 # Get the block size of the filesystem.
7607 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7608 awk '/^Block size:/ {print $3}')
7612 # Check whether the "large_xattr" feature is enabled or not.
7613 large_xattr_enabled() {
7614 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7616 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7618 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7619 grep -E -q '(ea_inode|large_xattr)'"
7620 return ${PIPESTATUS[0]}
7623 # Get the maximum xattr size supported by the filesystem.
7627 if large_xattr_enabled; then
7628 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7631 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7632 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7634 # maximum xattr size = size of block - size of header -
7635 # size of 1 entry - 4 null bytes
7636 size=$((block_size - 32 - 32 - 4))
7642 # Dump the value of the named xattr from a file.
7647 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7650 # Generate a string with size of $size bytes.
7652 local size=${1:-1024} # in bytes
7654 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7657 reformat_external_journal() {
7662 if [ -n "${!var}" ]; then
7663 local rcmd="do_facet $facet"
7665 echo "reformat external journal on $facet:${!var}"
7666 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7670 # MDT file-level backup/restore
7671 mds_backup_restore() {
7674 local devname=$(mdsdevname $(facet_number $facet))
7675 local mntpt=$(facet_mntpt brpt)
7676 local rcmd="do_facet $facet"
7677 local metaea=${TMP}/backup_restore.ea
7678 local metadata=${TMP}/backup_restore.tgz
7679 local opts=${MDS_MOUNT_OPTS}
7680 local svc=${facet}_svc
7682 if ! ${rcmd} test -b ${devname}; then
7683 opts=$(csa_add "$opts" -o loop)
7686 echo "file-level backup/restore on $facet:${devname}"
7688 # step 1: build mount point
7689 ${rcmd} mkdir -p $mntpt
7690 # step 2: cleanup old backup
7691 ${rcmd} rm -f $metaea $metadata
7693 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7694 if [ ! -z $igif ]; then
7695 # step 3.5: rm .lustre
7696 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7698 # step 4: backup metaea
7700 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7702 # step 5: backup metadata
7704 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7706 ${rcmd} $UMOUNT $mntpt || return 4
7707 # step 8: reformat dev
7708 echo "reformat new device"
7709 format_mdt $(facet_number $facet)
7711 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7712 # step 10: restore metadata
7714 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7715 # step 11: restore metaea
7717 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7718 # step 12: remove recovery logs
7719 echo "remove recovery logs"
7720 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7721 # step 13: umount dev
7722 ${rcmd} $UMOUNT $mntpt || return 10
7723 # step 14: cleanup tmp backup
7724 ${rcmd} rm -f $metaea $metadata
7725 # step 15: reset device label - it's not virgin on
7726 ${rcmd} e2label $devname ${!svc}
7733 local devname=$(mdsdevname $(facet_number $facet))
7734 local mntpt=$(facet_mntpt brpt)
7735 local rcmd="do_facet $facet"
7736 local opts=${MDS_MOUNT_OPTS}
7738 if ! ${rcmd} test -b ${devname}; then
7739 opts=$(csa_add "$opts" -o loop)
7742 echo "removing OI files on $facet: idx=${idx}"
7744 # step 1: build mount point
7745 ${rcmd} mkdir -p $mntpt
7747 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7748 if [ -z $idx ]; then
7749 # step 3: remove all OI files
7750 ${rcmd} rm -fv $mntpt/oi.16*
7751 elif [ $idx -lt 2 ]; then
7752 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7756 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7757 for ((i=${idx}; i<64; i=$((i * idx)))); do
7758 ${rcmd} rm -fv $mntpt/oi.16.${i}
7762 ${rcmd} $UMOUNT $mntpt || return 2
7763 # OI files will be recreated when mounted as lustre next time.
7766 # generate maloo upload-able log file name
7767 # \param logname specify unique part of file name
7768 generate_logname() {
7769 local logname=${1:-"default_logname"}
7771 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7774 # make directory on different MDTs
7778 local stripe_count=2
7779 local stripe_index=-1
7782 while getopts "c:i:p" opt; do
7784 c) stripe_count=$OPTARG;;
7785 i) stripe_index=$OPTARG;;
7787 \?) error "only support -i -c -p";;
7791 shift $((OPTIND - 1))
7792 [ $# -eq 1 ] || error "Only creating single directory is supported"
7795 if [ "$p_option" == "-p" ]; then
7796 local parent=$(dirname $path)
7798 [ -d $path ] && return 0
7799 if [ ! -d ${parent} ]; then
7800 mkdir -p ${parent} ||
7801 error "mkdir parent '$parent' failed"
7805 if [ $MDSCOUNT -le 1 ]; then
7806 mkdir $path || error "mkdir '$path' failed"
7808 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7811 if [ $stripe_index -eq -1 ]; then
7812 mdt_index=$((test_num % MDSCOUNT))
7814 mdt_index=$stripe_index
7816 echo "striped dir -i$mdt_index -c$stripe_count $path"
7817 $LFS mkdir -i$mdt_index -c$stripe_count $path ||
7818 error "mkdir -i $mdt_index -c$stripe_count $path failed"
7822 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
7824 # If called many times, passing @last_fd will avoid repeated searching
7825 # already-open FDs repeatedly if we know they are still in use.
7827 # usage: free_fd [last_fd]
7830 local max_fd=$(ulimit -n)
7831 local fd=$((${1:-2} + 1))
7833 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7836 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7840 check_mount_and_prep()
7842 is_mounted $MOUNT || setupall
7844 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7845 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7846 for idx in $(seq $MDSCOUNT); do
7847 local name="MDT$(printf '%04x' $((idx - 1)))"
7848 rm -rf $MOUNT/.lustre/lost+found/$name/*
7852 # calcule how many ost-objects to be created.
7853 precreated_ost_obj_count()
7857 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7858 local ost_name="OST$(printf '%04x' $ost_idx)"
7859 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7860 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7861 osp.$proc_path.prealloc_last_id)
7862 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7863 osp.$proc_path.prealloc_next_id)
7864 echo $((last_id - next_id + 1))
7867 check_file_in_pool()
7872 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7875 for t in $tlist ; do
7876 [ "$i" -eq "$t" ] && continue 2
7879 echo "pool list: $tlist"
7880 echo "striping: $res"
7881 error_noexit "$file not allocated in $pool"
7888 echo "Creating new pool"
7891 create_pool $FSNAME.$pool ||
7892 { error_noexit "No pool created, result code $?"; return 1; }
7893 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7894 { error_noexit "$pool not in lfs pool_list"; return 2; }
7897 pool_add_targets() {
7898 echo "Adding targets to pool"
7904 local list=$(seq $first $step $last)
7906 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7907 do_facet mgs $LCTL pool_add \
7908 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7910 # wait for OSTs to be added to the pool
7911 for mds_id in $(seq $MDSCOUNT); do
7912 local mdt_id=$((mds_id-1))
7913 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7914 wait_update_facet mds$mds_id \
7915 "lctl get_param -n lod.$lodname.pools.$pool |
7916 sort -u | tr '\n' ' ' " "$t" || {
7917 error_noexit "mds$mds_id: Add to pool failed"
7921 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7922 | sort -u | tr '\n' ' ' " "$t" || {
7923 error_noexit "Add to pool failed"
7926 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7927 local addcount=$(((last - first) / step + 1))
7928 [ $lfscount -eq $addcount ] || {
7929 error_noexit "lfs pool_list bad ost count" \
7930 "$lfscount != $addcount"
7938 echo "Setting pool on directory $tdir"
7940 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7942 error_noexit "Cannot set pool $pool to $tdir"
7949 echo "Checking pool on directory $tdir"
7951 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7952 [ "$res" = "$pool" ] && return 0
7954 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7958 pool_dir_rel_path() {
7959 echo "Testing relative path works well"
7964 mkdir -p $root/$tdir/$tdir
7966 pool_set_dir $pool $tdir || return 1
7967 pool_set_dir $pool ./$tdir || return 2
7968 pool_set_dir $pool ../$tdir || return 3
7969 pool_set_dir $pool ../$tdir/$tdir || return 4
7970 rm -rf $tdir; cd - > /dev/null
7973 pool_alloc_files() {
7974 echo "Checking files allocation from directory pool"
7981 for i in $(seq -w 1 $count)
7983 local file=$tdir/file-$i
7985 check_file_in_pool $file $pool "$tlist" || \
7986 failed=$((failed + 1))
7988 [ "$failed" = 0 ] && return 0
7990 error_noexit "$failed files not allocated in $pool"
7994 pool_create_files() {
7995 echo "Creating files in pool"
8003 for i in $(seq -w 1 $count)
8005 local file=$tdir/spoo-$i
8006 $SETSTRIPE -p $pool $file
8007 check_file_in_pool $file $pool "$tlist" || \
8008 failed=$((failed + 1))
8010 [ "$failed" = 0 ] && return 0
8012 error_noexit "$failed files not allocated in $pool"
8017 echo "Checking 'lfs df' output"
8020 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
8022 local res=$($LFS df --pool $FSNAME.$pool |
8024 grep "$FSNAME-OST" |
8026 [ "$res" = "$t" ] && return 0
8028 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
8032 pool_file_rel_path() {
8033 echo "Creating files in a pool with relative pathname"
8038 { error_noexit "unable to create $tdir"; return 1 ; }
8039 local file="/..$tdir/$tfile-1"
8040 $SETSTRIPE -p $pool $file ||
8041 { error_noexit "unable to create $file" ; return 2 ; }
8044 $SETSTRIPE -p $pool $tfile-2 || {
8045 error_noexit "unable to create $tfile-2 in $tdir"
8050 pool_remove_first_target() {
8051 echo "Removing first target from a pool"
8054 local pname="lov.$FSNAME-*.pools.$pool"
8055 local t=$($LCTL get_param -n $pname | head -1)
8056 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8057 for mds_id in $(seq $MDSCOUNT); do
8058 local mdt_id=$((mds_id-1))
8059 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8060 wait_update_facet mds$mds_id \
8061 "lctl get_param -n lod.$lodname.pools.$pool |
8063 error_noexit "mds$mds_id: $t not removed from" \
8068 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
8069 error_noexit "$t not removed from $FSNAME.$pool"
8074 pool_remove_all_targets() {
8075 echo "Removing all targets from pool"
8078 local pname="lov.$FSNAME-*.pools.$pool"
8079 for t in $($LCTL get_param -n $pname | sort -u)
8081 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
8083 for mds_id in $(seq $MDSCOUNT); do
8084 local mdt_id=$((mds_id-1))
8085 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
8086 wait_update_facet mds$mds_id "lctl get_param -n \
8087 lod.$lodname.pools.$pool" "" || {
8088 error_noexit "mds$mds_id: Pool $pool not drained"
8092 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
8093 error_noexit "Pool $FSNAME.$pool cannot be drained"
8096 # striping on an empty/nonexistant pool should fall back
8097 # to "pool of everything"
8099 error_noexit "failed to use fallback striping for empty pool"
8102 # setstripe on an empty pool should fail
8103 $SETSTRIPE -p $pool $file 2>/dev/null && {
8104 error_noexit "expected failure when creating file" \
8112 echo "Destroying pool"
8116 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
8119 # striping on an empty/nonexistant pool should fall back
8120 # to "pool of everything"
8122 error_noexit "failed to use fallback striping for missing pool"
8125 # setstripe on an empty pool should fail
8126 $SETSTRIPE -p $pool $file 2>/dev/null && {
8127 error_noexit "expected failure when creating file" \
8132 # get param should return err once pool is gone
8133 if wait_update $HOSTNAME "lctl get_param -n \
8134 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
8136 remove_pool_from_list $FSNAME.$pool
8139 error_noexit "Pool $FSNAME.$pool is not destroyed"
8143 # Get and check the actual stripe count of one file.
8144 # Usage: check_stripe_count <file> <expected_stripe_count>
8145 check_stripe_count() {
8150 [[ -z "$file" || -z "$expected" ]] &&
8151 error "check_stripe_count: invalid argument"
8153 local cmd="$GETSTRIPE -c $file"
8154 actual=$($cmd) || error "$cmd failed"
8155 actual=${actual%% *}
8157 if [[ $actual -ne $expected ]]; then
8158 [[ $expected -eq -1 ]] ||
8159 error "$cmd wrong: found $actual, expected $expected"
8160 [[ $actual -eq $OSTCOUNT ]] ||
8161 error "$cmd wrong: found $actual, expected $OSTCOUNT"
8165 # Get and check the actual list of OST indices on one file.
8166 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
8172 [[ -z "$file" || -z "$expected" ]] &&
8173 error "check_obdidx: invalid argument!"
8175 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
8176 grep -v obdidx | awk '{print $1}' | xargs))
8178 [[ $obdidx = $expected ]] ||
8179 error "list of OST indices on $file is $obdidx," \
8180 "should be $expected"
8183 # Get and check the actual OST index of the first stripe on one file.
8184 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
8185 check_start_ost_idx() {
8190 [[ -z "$file" || -z "$expected" ]] &&
8191 error "check_start_ost_idx: invalid argument!"
8193 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
8196 [[ $start_ost_idx = $expected ]] ||
8197 error "OST index of the first stripe on $file is" \
8198 "$start_ost_idx, should be $expected"
8201 killall_process () {
8202 local clients=${1:-$(hostname)}
8207 do_nodes $clients "killall $signal $name"
8212 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
8217 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
8222 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
8227 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
8232 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
8237 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
8244 do_facet mgs "cat $LSNAPSHOT_LOG"
8250 echo "Cleaning test environment ..."
8252 # Every lsnapshot command takes exclusive lock with others,
8253 # so can NOT destroy the snapshot during list with 'xargs'.
8255 local ssname=$(lsnapshot_list | grep snapshot_name |
8256 grep lss_ | awk '{ print $2 }' | head -n 1)
8257 [ -z "$ssname" ] && break
8259 lsnapshot_destroy -n $ssname -f ||
8260 lss_err "Fail to destroy $ssname by force"
8270 local host=$(facet_active_host $facet)
8271 local dir=$(dirname $(facet_vdevice $facet))
8272 local pool=$(zpool_name $facet)
8273 local lfsname=$(zfs_local_fsname $facet)
8274 local label=${FSNAME}-${role}$(printf '%04x' $idx)
8277 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
8283 do_facet mgs "rm -f $LSNAPSHOT_CONF"
8284 echo "Generating $LSNAPSHOT_CONF on MGS ..."
8286 if ! combined_mgs_mds ; then
8287 [ $(facet_fstype mgs) != zfs ] &&
8288 skip "Lustre snapshot 1 only works for ZFS backend" &&
8291 local host=$(facet_active_host mgs)
8292 local dir=$(dirname $(facet_vdevice mgs))
8293 local pool=$(zpool_name mgs)
8294 local lfsname=$(zfs_local_fsname mgs)
8297 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
8298 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
8301 for num in `seq $MDSCOUNT`; do
8302 [ $(facet_fstype mds$num) != zfs ] &&
8303 skip "Lustre snapshot 1 only works for ZFS backend" &&
8306 lss_gen_conf_one mds$num MDT $((num - 1)) ||
8307 lss_err "generate lss conf (mds$num)"
8310 for num in `seq $OSTCOUNT`; do
8311 [ $(facet_fstype ost$num) != zfs ] &&
8312 skip "Lustre snapshot 1 only works for ZFS backend" &&
8315 lss_gen_conf_one ost$num OST $((num - 1)) ||
8316 lss_err "generate lss conf (ost$num)"
8319 do_facet mgs "cat $LSNAPSHOT_CONF"
8325 local val=$(awk '{print $2}' <<< $line)
8327 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
8329 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
8331 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
8336 parse_layout_param()
8343 if [[ -z $mode ]]; then
8344 if [[ $line =~ ^"stripe_count:" ]]; then
8346 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
8348 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
8353 if [[ $mode = "plain_dir" ]]; then
8354 param=$(echo $line |
8355 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
8356 elif [[ $mode = "plain_file" ]]; then
8357 val=$(parse_plain_param "$line")
8358 [[ ! -z $val ]] && param="$param $val"
8359 elif [[ $mode = "pfl" ]]; then
8360 val=$(echo $line | awk '{print $2}')
8361 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
8362 if [[ $val = "EOF" ]]; then
8363 param="$param -E -1"
8365 param="$param -E $val"
8367 elif [[ $line =~ ^"stripe_count:" ]]; then
8370 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
8374 val=$(parse_plain_param "$line")
8375 [[ ! -z $val ]] && param="$param $val"
8384 local param=$($LFS getstripe -d $1 | parse_layout_param)