3 trap 'print_summary && touch $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
14 export GSS_PIPEFS=false
15 export IDENTITY_UPCALL=default
17 # specify environment variable containing batch job name for server statistics
18 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
20 #export PDSH="pdsh -S -Rssh -w"
21 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
22 export UMOUNT=${UMOUNT:-"umount -d"}
24 export LSNAPSHOT_CONF="/etc/ldev.conf"
25 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
27 # sles12 umount has a issue with -d option
28 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
29 export UMOUNT="umount"
32 # function used by scripts run on remote nodes
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/functions.sh
35 . $LUSTRE/tests/yaml.sh
37 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
39 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
41 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
43 if [ -f "$EXCEPT_LIST_FILE" ]; then
44 echo "Reading test skip list from $EXCEPT_LIST_FILE"
49 # check config files for options in decreasing order of preference
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
51 MODPROBECONF=/etc/modprobe.d/lustre.conf
52 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
53 MODPROBECONF=/etc/modprobe.d/Lustre
54 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
55 MODPROBECONF=/etc/modprobe.conf
57 sanitize_parameters() {
58 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
61 if [ -d "$path" ]; then
62 eval export $i=$(echo $path | sed -r 's/\/+$//g')
68 [[ $DIR/ = $MOUNT/* ]] ||
69 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
70 [[ $DIR1/ = $MOUNT1/* ]] ||
71 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
72 [[ $DIR2/ = $MOUNT2/* ]] ||
73 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
75 [ -n "$failed" ] && exit 99 || true
79 echo "usage: $0 [-r] [-f cfgfile]"
87 [ -z "$DEFAULT_SUITES"] && return 0
88 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
90 local form="%-13s %-17s %-9s %s %s\n"
91 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
92 echo "------------------------------------------------------------------------------------"
93 for O in $DEFAULT_SUITES; do
94 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
95 [ "${!O}" = "no" ] && continue || true
96 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
97 local log=${TMP}/${o}.log
98 if is_sanity_benchmark $o; then
99 log=${TMP}/sanity-benchmark.log
104 local status=Unfinished
106 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
108 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
109 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
110 total=$(grep duration $log | awk '{ print $2 }')
111 if [ "${!O}" = "done" ]; then
115 local durations=$(egrep "^PASS|^FAIL" $log |
116 tr -d "("| sed s/s\)$//g |
117 awk '{ print $2":"$3"|" }')
118 details=$(printf "%s\n%s %s %s\n" "$details" \
119 "DDETAILS" "$O" "$(echo $durations)")
122 printf "$form" $status "$O" "${total}" "E=$skipped"
123 printf "$form" "-" "-" "-" "S=$(echo $slow)"
126 for O in $DEFAULT_SUITES; do
127 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
128 if [ "${!O}" = "no" ]; then
129 printf "$form" "Skipped" "$O" ""
133 # print the detailed tests durations if DDETAILS=true
140 export LUSTRE=$(absolute_path $LUSTRE)
141 export TESTSUITE=$(basename $0 .sh)
142 export TEST_FAILED=false
143 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
144 export RPC_MODE=${RPC_MODE:-false}
145 export DO_CLEANUP=${DO_CLEANUP:-true}
146 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
148 export MKE2FS=$MKE2FS
149 if [ -z "$MKE2FS" ]; then
150 if which mkfs.ldiskfs >/dev/null 2>&1; then
151 export MKE2FS=mkfs.ldiskfs
157 export DEBUGFS=$DEBUGFS
158 if [ -z "$DEBUGFS" ]; then
159 if which debugfs.ldiskfs >/dev/null 2>&1; then
160 export DEBUGFS=debugfs.ldiskfs
162 export DEBUGFS=debugfs
166 export TUNE2FS=$TUNE2FS
167 if [ -z "$TUNE2FS" ]; then
168 if which tunefs.ldiskfs >/dev/null 2>&1; then
169 export TUNE2FS=tunefs.ldiskfs
171 export TUNE2FS=tune2fs
175 export E2LABEL=$E2LABEL
176 if [ -z "$E2LABEL" ]; then
177 if which label.ldiskfs >/dev/null 2>&1; then
178 export E2LABEL=label.ldiskfs
180 export E2LABEL=e2label
184 export DUMPE2FS=$DUMPE2FS
185 if [ -z "$DUMPE2FS" ]; then
186 if which dumpfs.ldiskfs >/dev/null 2>&1; then
187 export DUMPE2FS=dumpfs.ldiskfs
189 export DUMPE2FS=dumpe2fs
193 export E2FSCK=$E2FSCK
194 if [ -z "$E2FSCK" ]; then
195 if which fsck.ldiskfs >/dev/null 2>&1; then
196 export E2FSCK=fsck.ldiskfs
202 export RESIZE2FS=$RESIZE2FS
203 if [ -z "$RESIZE2FS" ]; then
204 if which resizefs.ldiskfs >/dev/null 2>&1; then
205 export RESIZE2FS=resizefs.ldiskfs
207 export RESIZE2FS=resize2fs
211 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
212 export FSCK_MAX_ERR=4 # File system errors left uncorrected
214 export ZFS=${ZFS:-zfs}
215 export ZPOOL=${ZPOOL:-zpool}
216 export ZDB=${ZDB:-zdb}
217 export PARTPROBE=${PARTPROBE:-partprobe}
219 #[ -d /r ] && export ROOT=${ROOT:-/r}
220 export TMP=${TMP:-$ROOT/tmp}
221 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
222 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
223 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
225 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
226 if ! echo $PATH | grep -q $LUSTRE/utils; then
227 export PATH=$LUSTRE/utils:$PATH
229 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
230 export PATH=$LUSTRE/utils/gss:$PATH
232 if ! echo $PATH | grep -q $LUSTRE/tests; then
233 export PATH=$LUSTRE/tests:$PATH
235 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
236 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
238 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
239 [ ! -f "$LST" ] && export LST=$(which lst)
240 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
241 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
242 export MCREATE=${MCREATE:-mcreate}
243 # Ubuntu, at least, has a truncate command in /usr/bin
244 # so fully path our truncate command.
245 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
246 export FSX=${FSX:-$LUSTRE/tests/fsx}
247 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
248 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
249 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
250 export PATH=$LUSTRE/tests/racer:$PATH:
252 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
253 export PATH=$LUSTRE/tests/mpi:$PATH
255 export RSYNC_RSH=${RSYNC_RSH:-rsh}
257 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
258 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
259 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
260 [ ! -f "$LFS" ] && export LFS=$(which lfs)
261 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
262 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
264 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
265 if [ ! -f "$L_GETIDENTITY" ]; then
266 if `which l_getidentity > /dev/null 2>&1`; then
267 export L_GETIDENTITY=$(which l_getidentity)
269 export L_GETIDENTITY=NONE
272 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
273 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
274 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
275 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
276 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
277 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
278 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
279 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
280 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
281 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
282 [ ! -f "$LUSTRE_RMMOD" ] &&
283 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
284 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
285 [ ! -f "$LFS_MIGRATE" ] &&
286 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
287 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
288 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
289 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
290 export NAME=${NAME:-local}
291 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
292 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
293 export LGSSD=$(which lgssd)
294 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
295 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
296 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
298 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
300 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
301 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
303 if [ "$ACCEPTOR_PORT" ]; then
304 export PORT_OPT="--port $ACCEPTOR_PORT"
309 echo "Using GSS/krb5 ptlrpc security flavor"
310 which lgss_keyring > /dev/null 2>&1 || \
311 error_exit "built with gss disabled! SEC=$SEC"
322 IDENTITY_UPCALL=false
326 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
328 # Paths on remote nodes, if different
329 export RLUSTRE=${RLUSTRE:-$LUSTRE}
330 export RPWD=${RPWD:-$PWD}
331 export I_MOUNTED=${I_MOUNTED:-"no"}
332 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
333 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
334 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
335 ! -f $LUSTRE/mdt/mdt.ko ]; then
336 export CLIENTMODSONLY=yes
339 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
340 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
344 while getopts "rvwf:" opt $*; do
349 w) WRITECONF=writeconf;;
354 shift $((OPTIND - 1))
357 # print the durations of each test if "true"
358 DDETAILS=${DDETAILS:-false}
359 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
364 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
371 ncpts=$(do_facet $facet "lctl get_param -n " \
372 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
374 if [ $ncpts -eq 0 ]; then
381 # Return a numeric version code based on a version string. The version
382 # code is useful for comparison two version strings to see which is newer.
384 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
385 eval set -- $(tr "[:punct:]" " " <<< $*)
387 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
390 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
391 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
393 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
395 # usage: lustre_build_version
397 # All Lustre versions support "lctl get_param" to report the version of the
398 # code running in the kernel (what our tests are interested in), but it
399 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
400 # the "version" parameter doesn't include "lustre: " at the beginning.
401 # If that fails, call "lctl lustre_build_version" which prints either (or both)
402 # the userspace and kernel build versions, but until 2.8.55 required root
403 # access to get the Lustre kernel version. If that also fails, fall back to
404 # using "lctl --version", which is easy to parse and works without the kernel
405 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
406 # not the module version, though they are usually the same.
408 # Various commands and their output format for different Lustre versions:
409 # lctl get_param version: 2.9.55
410 # lctl get_param version: lustre: 2.8.53
411 # lctl get_param version: lustre: 2.6.52
412 # kernel: patchless_client
413 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
414 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
415 # lctl lustre_build_version: error: lustre_build_version: Permission denied
416 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
417 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
418 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
419 # lctl --version: lctl 2.6.50
421 # output: prints version string to stdout in (up to 4) dotted-decimal values
422 lustre_build_version() {
423 local facet=${1:-client}
426 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null ||
427 $LCTL lustre_build_version 2>/dev/null ||
428 $LCTL --version 2>/dev/null | cut -d' ' -f2")
429 local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
430 [ -n "$lver" ] && ver="$lver"
432 sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
436 # Report the Lustre numeric build version code for the supplied facet.
437 lustre_version_code() {
438 version_code $(lustre_build_version $1)
442 /sbin/lsmod | grep -q "^\<$1\>"
445 # Load a module on the system where this is running.
447 # usage: load_module module_name [module arguments for insmod/modprobe]
449 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
450 # will be used as the arguments. Otherwise arguments will be obtained from
451 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
458 BASE=$(basename $module $EXT)
460 module_loaded ${BASE} && return
462 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
463 # else from modprobe.conf
464 if [ $# -eq 0 ]; then
465 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
466 # Bash until 4.x, so we resort to eval.
467 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
468 eval set -- \$$optvar
469 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
470 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
472 opt=$(awk -v var="^options $BASE" '$0 ~ var \
473 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
474 set -- $(echo -n $opt)
476 # Ensure we have accept=all for lnet
477 if [ $(basename $module) = lnet ]; then
478 # OK, this is a bit wordy...
479 local arg accept_all_present=false
482 [ "$arg" = accept=all ] && \
483 accept_all_present=true
485 $accept_all_present || set -- "$@" accept=all
491 [ $# -gt 0 ] && echo "${module} options: '$*'"
493 # Note that insmod will ignore anything in modprobe.conf, which is why
494 # we're passing options on the command-line.
495 if [[ "$BASE" == "lnet_selftest" ]] &&
496 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
497 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
498 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
499 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
500 insmod ${LUSTRE}/${module}${EXT} "$@"
502 # must be testing a "make install" or "rpm" installation
503 # note failed to load ptlrpc_gss is considered not fatal
504 if [[ "$BASE" == "ptlrpc_gss" ]]; then
505 modprobe $BASE "$@" 2>/dev/null ||
506 echo "gss/krb5 is not supported"
513 load_modules_local() {
514 if [ -n "$MODPROBE" ]; then
516 echo "Using modprobe to load modules"
520 echo Loading modules from $LUSTRE
524 if [ -f /sys/devices/system/cpu/online ]; then
525 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
526 echo "detected $ncpus online CPUs by sysfs"
528 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
530 if [ $rc -eq 0 ]; then
531 echo "detected $ncpus online CPUs by getconf"
533 echo "Can't detect number of CPUs"
538 # if there is only one CPU core, libcfs can only create one partition
539 # if there is more than 4 CPU cores, libcfs should create multiple CPU
540 # partitions. So we just force libcfs to create 2 partitions for
541 # system with 2 or 4 cores
542 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
543 # force to enable multiple CPU partitions
544 echo "Force libcfs to create 2 CPU partitions"
545 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
547 echo "libcfs will create CPU partition based on online CPUs"
550 load_module ../libcfs/libcfs/libcfs
551 # Prevent local MODOPTS_LIBCFS being passed as part of environment
552 # variable to remote nodes
556 load_module ../lnet/lnet/lnet
559 LNETLND="o2iblnd/ko2iblnd"
564 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
565 load_module ../lnet/klnds/$LNETLND
566 load_module obdclass/obdclass
567 load_module ptlrpc/ptlrpc
568 load_module ptlrpc/gss/ptlrpc_gss
576 load_module obdecho/obdecho
577 if ! client_only; then
578 SYMLIST=/proc/kallsyms
579 grep -q crc16 $SYMLIST ||
580 { modprobe crc16 2>/dev/null || true; }
581 grep -q -w jbd2 $SYMLIST ||
582 { modprobe jbd2 2>/dev/null || true; }
583 load_module lfsck/lfsck
584 [ "$LQUOTA" != "no" ] &&
585 load_module quota/lquota $LQUOTAOPTS
586 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
588 load_module osd-zfs/osd_zfs
590 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
591 grep -q exportfs_decode_fh $SYMLIST ||
592 { modprobe exportfs 2> /dev/null || true; }
593 grep -q -w mbcache $SYMLIST ||
594 { modprobe mbcache 2>/dev/null || true; }
595 load_module ../ldiskfs/ldiskfs
596 load_module osd-ldiskfs/osd_ldiskfs
608 load_module llite/lustre
609 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
611 rm -f $OGDB/ogdb-$HOSTNAME
612 $LCTL modules > $OGDB/ogdb-$HOSTNAME
614 # 'mount' doesn't look in $PATH, just sbin
615 local mount_lustre=$LUSTRE/utils/mount.lustre
616 if [ -f $mount_lustre ]; then
617 local sbin_mount=$(readlink -f /sbin)/mount.lustre
618 if grep -qw "$sbin_mount" /proc/mounts; then
619 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
621 if ! grep -qw "$sbin_mount" /proc/mounts; then
622 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
623 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
624 cat <<- EOF > "$sbin_mount"
627 echo "This $sbin_mount just a mountpoint." 1>&2
628 echo "It is never supposed to be run." 1>&2
629 logger -p emerg -- "using stub $sbin_mount $@"
632 chmod a+x $sbin_mount
634 mount --bind $mount_lustre $sbin_mount ||
635 error "can't bind $mount_lustre to $sbin_mount"
643 # load modules on remote nodes optionally
644 # lustre-tests have to be installed on these nodes
645 if $LOAD_MODULES_REMOTE; then
646 local list=$(comma_list $(remote_nodes_list))
647 if [ -n "$list" ]; then
648 echo "loading modules on: '$list'"
649 do_rpc_nodes "$list" load_modules_local
655 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
656 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
657 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
658 echo "$LEAK_LUSTRE" 1>&2
659 echo "$LEAK_PORTALS" 1>&2
660 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
661 echo "Memory leaks detected"
662 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
668 wait_exit_ST client # bug 12845
670 $LUSTRE_RMMOD ldiskfs || return 2
672 if $LOAD_MODULES_REMOTE; then
673 local list=$(comma_list $(remote_nodes_list))
674 if [ -n "$list" ]; then
675 echo "unloading modules on: '$list'"
676 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
677 do_rpc_nodes "$list" check_mem_leak
681 local sbin_mount=$(readlink -f /sbin)/mount.lustre
682 if grep -qe "$sbin_mount " /proc/mounts; then
683 umount $sbin_mount || true
684 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
688 check_mem_leak || return 254
690 echo "modules unloaded."
695 local facet=${1:-$SINGLEMDS}
696 local fstype=$(facet_fstype $facet)
699 ldiskfs) size=50;; # largest seen is 44, leave some headroom
700 zfs) size=400;; # largest seen is 384
707 local facet=${1:-$SINGLEMDS}
708 local fstype=$(facet_fstype $facet)
711 ldiskfs) size=4;; # ~4KB per inode
712 zfs) size=11;; # 10 to 11KB per inode
718 check_gss_daemon_nodes() {
722 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
723 if [ \\\"\\\$num\\\" -ne 1 ]; then
724 echo \\\$num instance of $dname;
729 check_gss_daemon_facet() {
733 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
734 if [ $num -ne 1 ]; then
735 echo "$num instance of $dname on $facet"
744 echo Stopping $@ on $list
745 do_nodes $list "killall -2 $@ 2>/dev/null || true"
748 # start gss daemons on all nodes, or
749 # "daemon" on "list" if set
750 start_gss_daemons() {
754 if [ "$list" ] && [ "$daemon" ] ; then
755 echo "Starting gss daemon on nodes: $list"
756 do_nodes $list "$daemon" || return 8
760 local list=$(comma_list $(mdts_nodes))
761 echo "Starting gss daemon on mds: $list"
762 do_nodes $list "$LSVCGSSD -v" || return 1
764 do_nodes $list "$LGSSD -v" || return 2
767 list=$(comma_list $(osts_nodes))
768 echo "Starting gss daemon on ost: $list"
769 do_nodes $list "$LSVCGSSD -v" || return 3
770 # starting on clients
772 local clients=${CLIENTS:-`hostname`}
774 echo "Starting $LGSSD on clients $clients "
775 do_nodes $clients "$LGSSD -v" || return 4
778 # wait daemons entering "stable" status
782 # check daemons are running
784 list=$(comma_list $(mdts_nodes) $(osts_nodes))
785 check_gss_daemon_nodes $list lsvcgssd || return 5
787 list=$(comma_list $(mdts_nodes))
788 check_gss_daemon_nodes $list lgssd || return 6
791 check_gss_daemon_nodes $clients lgssd || return 7
796 local list=$(comma_list $(mdts_nodes))
798 send_sigint $list lsvcgssd lgssd
800 list=$(comma_list $(osts_nodes))
801 send_sigint $list lsvcgssd
803 list=${CLIENTS:-`hostname`}
804 send_sigint $list lgssd
809 if ! module_loaded ptlrpc_gss; then
810 load_module ptlrpc/gss/ptlrpc_gss
811 module_loaded ptlrpc_gss ||
812 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
815 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
818 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
820 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
828 # maybe cleanup credential cache?
834 local var=${facet}_svc
842 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
843 tr '[:lower:]' '[:upper:]'
849 if [ $facet == mgs ] || [ $facet == client ]; then
853 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
861 if [ -n "${!var}" ]; then
866 var=$(facet_type $facet)FSTYPE
867 if [ -n "${!var}" ]; then
872 if [ -n "$FSTYPE" ]; then
877 if [[ $facet == mgs ]] && combined_mgs_mds; then
889 local facets=$(get_facets)
892 for facet in ${facets//,/ }; do
893 if [ $node == $(facet_host $facet) ] ||
894 [ $node == "$(facet_failover_host $facet)" ]; then
895 fstype=$(facet_fstype $facet)
896 if [[ $fstypes != *$fstype* ]]; then
897 fstypes+="${fstypes:+,}$fstype"
906 local num=$(facet_number $facet)
909 if [[ $(facet_type $facet) = OST ]]; then
911 if [[ -n "${!index}" ]]; then
916 index=${OST_INDICES[num - 1]}
919 [[ -n "$index" ]] || index=$((num - 1))
927 local fstype=$(facet_fstype $facet)
931 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
933 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
934 ${dev} 2>/dev/null");;
936 error "unknown fstype!";;
944 local device=$(mdsdevname $num)
945 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
951 local device=$(ostdevname $num)
952 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
957 # Get the device of a facet.
964 mgs) device=$(mgsdevname) ;;
965 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
966 ost*) device=$(ostdevname $(facet_number $facet)) ;;
967 fs2mds) device=$(mdsdevname 1_2) ;;
968 fs2ost) device=$(ostdevname 1_2) ;;
969 fs3ost) device=$(ostdevname 2_2) ;;
977 # Get the virtual device of a facet.
984 mgs) device=$(mgsvdevname) ;;
985 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
986 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
987 fs2mds) device=$(mdsvdevname 1_2) ;;
988 fs2ost) device=$(ostvdevname 1_2) ;;
989 fs3ost) device=$(ostvdevname 2_2) ;;
997 local virt=$(virt-what 2> /dev/null)
999 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1001 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1004 VMware|KVM|VirtualBox|Parallels)
1005 echo $virt | tr '[A-Z]' '[a-z]' ;;
1011 # Re-read the partition table on failover partner host.
1012 # After a ZFS storage pool is created on a shared device, the partition table
1013 # on the device may change. However, the operating system on the failover
1014 # host may not notice the change automatically. Without the up-to-date partition
1015 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1016 # relative to partition rather than disk beginnings.
1018 # This function performs partprobe on the failover host to make it re-read the
1021 refresh_partition_table() {
1026 host=$(facet_passive_host $facet)
1027 if [[ -n "$host" ]]; then
1028 do_node $host "$PARTPROBE $device"
1033 # Get ZFS storage pool name.
1040 device=$(facet_device $facet)
1041 # poolname is string before "/"
1042 poolname="${device%%/*}"
1049 # Get ZFS local fsname.
1051 zfs_local_fsname() {
1053 local lfsname=$(basename $(facet_device $facet))
1059 # Create ZFS storage pool.
1066 local opts=${@:-"-o cachefile=none"}
1068 do_facet $facet "modprobe zfs;
1069 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1070 $ZPOOL create -f $opts $poolname $vdev"
1074 # Create ZFS file system.
1080 local opts=${@:-"-o mountpoint=legacy"}
1082 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1083 $ZFS create $opts $dataset"
1087 # Export ZFS storage pool.
1088 # Before exporting the pool, all datasets within the pool should be unmounted.
1096 poolname=$(zpool_name $facet)
1098 if [[ -n "$poolname" ]]; then
1099 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1100 grep -q ^$poolname/ /proc/mounts ||
1101 $ZPOOL export $opts $poolname"
1106 # Destroy ZFS storage pool.
1107 # Destroy the given pool and free up any devices for other use. This command
1108 # tries to unmount any active datasets before destroying the pool.
1109 # -f Force any active datasets contained within the pool to be unmounted.
1113 local poolname=${2:-$(zpool_name $facet)}
1115 if [[ -n "$poolname" ]]; then
1116 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1117 $ZPOOL destroy -f $poolname"
1122 # Import ZFS storage pool.
1123 # Force importing, even if the pool appears to be potentially active.
1128 local opts=${@:-"-o cachefile=none"}
1131 poolname=$(zpool_name $facet)
1133 if [[ -n "$poolname" ]]; then
1134 opts+=" -d $(dirname $(facet_vdevice $facet))"
1135 do_facet $facet "modprobe zfs;
1136 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1137 $ZPOOL import -f $opts $poolname"
1142 # Reimport ZFS storage pool with new name
1147 local opts="-o cachefile=none"
1148 local poolname=$(zpool_name $facet)
1150 opts+=" -d $(dirname $(facet_vdevice $facet))"
1151 do_facet $facet "$ZPOOL export $poolname;
1152 $ZPOOL import $opts $poolname $newpool"
1156 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1157 # is not automatically imported on system startup.
1159 # In a failover environment, this will provide resource level fencing which
1160 # will ensure that the same ZFS storage pool will not be imported concurrently
1161 # on different nodes.
1163 disable_zpool_cache() {
1167 poolname=$(zpool_name $facet)
1169 if [[ -n "$poolname" ]]; then
1170 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1175 # This and set_osd_param() shall be used to access OSD parameters
1176 # once existed under "obdfilter":
1181 # writethrough_cache_enable
1185 local device=${2:-$FSNAME-OST*}
1188 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1189 osd-*.$device.$name 2>&1" | grep -v 'error:'
1194 local device=${2:-$FSNAME-OST*}
1198 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1199 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1203 local dz=${1:-$DEBUG_SIZE}
1205 if [ -f /sys/devices/system/cpu/possible ]; then
1206 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1208 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1211 # bug 19944, adjust size to be -gt num_possible_cpus()
1212 # promise 2MB for every cpu at least
1213 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1216 lctl set_param debug_mb=$dz
1219 set_default_debug () {
1220 local debug=${1:-"$PTLDEBUG"}
1221 local subsys=${2:-"$SUBSYSTEM"}
1222 local debug_size=${3:-$DEBUG_SIZE}
1224 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1225 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1227 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1230 set_default_debug_nodes () {
1233 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1234 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1238 do_rpc_nodes "$nodes" set_default_debug \
1239 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1242 set_default_debug_facet () {
1244 local node=$(facet_active_host $facet)
1245 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1247 set_default_debug_nodes $node
1251 local hostid=${1:-$(hostid)}
1253 if [ ! -s /etc/hostid ]; then
1254 printf $(echo -n $hostid |
1255 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1261 local facets=${1:-$(get_facets)}
1264 for facet in ${facets//,/ }; do
1267 [ $RC -eq 0 ] && continue
1269 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1270 skip "Restart of $facet failed!." && touch $LU482_FAILED
1272 error "Restart of $facet failed!"
1279 # Add argument "arg" (e.g., "loop") to the comma-separated list
1280 # of arguments for option "opt" (e.g., "-o") on command
1281 # line "opts" (e.g., "-o flock").
1287 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1289 if echo "$opts" | grep -q $opt_pattern; then
1290 opts=$(echo "$opts" | sed -e \
1291 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1293 opts+="${opts:+ }$opt $arg"
1301 local dev=$(facet_active $facet)_dev
1302 local opt=${facet}_opt
1303 local mntpt=$(facet_mntpt $facet)
1304 local opts="${!opt} $@"
1305 local fstype=$(facet_fstype $facet)
1308 module_loaded lustre || load_modules
1310 if [ $(facet_fstype $facet) == ldiskfs ] &&
1311 ! do_facet $facet test -b ${!dev}; then
1312 opts=$(csa_add "$opts" -o loop)
1315 if [[ $(facet_fstype $facet) == zfs ]]; then
1316 # import ZFS storage pool
1317 import_zpool $facet || return ${PIPESTATUS[0]}
1322 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1324 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1325 lustre:svname ${!dev}");;
1327 error "unknown fstype!";;
1330 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1331 # for testing LU-482 error handling in mount_facets() and test_0a()
1332 if [ -f $TMP/test-lu482-trigger ]; then
1335 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1340 if [ $RC -ne 0 ]; then
1341 echo "Start of ${!dev} on ${facet} failed ${RC}"
1345 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1346 if [[ "$health" != "healthy" ]]; then
1347 error "$facet is in a unhealthy state"
1350 set_default_debug_facet $facet
1352 if [[ $facet == mds* ]]; then
1354 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1357 if [[ $opts =~ .*nosvc.* ]]; then
1358 echo "Start ${!dev} without service"
1363 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1364 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1365 "" || error "${!dev} failed to initialize!";;
1367 wait_update_facet ${facet} "$ZFS get -H -o value \
1368 lustre:svname ${!dev} 2>/dev/null | \
1369 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1370 error "${!dev} failed to initialize!";;
1373 error "unknown fstype!";;
1377 # commit the device label change to disk
1378 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1379 echo "Commit the device label on ${!dev}"
1380 do_facet $facet "sync; sync; sync"
1385 label=$(devicelabel ${facet} ${!dev})
1386 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1387 eval export ${facet}_svc=${label}
1388 echo Started ${label}
1393 # start facet device options
1399 eval export ${facet}_dev=${device}
1400 eval export ${facet}_opt=\"$@\"
1402 local varname=${facet}failover_dev
1403 if [ -n "${!varname}" ] ; then
1404 eval export ${facet}failover_dev=${!varname}
1406 eval export ${facet}failover_dev=$device
1409 local mntpt=$(facet_mntpt $facet)
1410 do_facet ${facet} mkdir -p $mntpt
1411 eval export ${facet}_MOUNT=$mntpt
1412 mount_facet ${facet}
1415 if [[ $facet == mds* ]]; then
1417 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1428 local HOST=`facet_active_host $facet`
1429 [ -z $HOST ] && echo stop: no host for $facet && return 0
1431 local mntpt=$(facet_mntpt $facet)
1432 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1433 if [ ${running} -ne 0 ]; then
1434 echo "Stopping $mntpt (opts:$@) on $HOST"
1435 do_facet ${facet} $UMOUNT $@ $mntpt
1438 # umount should block, but we should wait for unrelated obd's
1439 # like the MGS or MGC to also stop.
1440 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1442 if [[ $(facet_fstype $facet) == zfs ]]; then
1443 # export ZFS storage pool
1444 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1448 # save quota version (both administrative and operational quotas)
1449 # add an additional parameter if mountpoint is ever different from $MOUNT
1451 # XXX This function is kept for interoperability with old server (< 2.3.50),
1452 # it should be removed whenever we drop the interoperability for such
1454 quota_save_version() {
1455 local fsname=${2:-$FSNAME}
1457 local ver=$(tr -c -d "123" <<< $spec)
1458 local type=$(tr -c -d "ug" <<< $spec)
1460 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1462 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1464 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1466 local osts=$(get_facets OST)
1467 for ost in ${osts//,/ }; do
1469 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1473 # client could mount several lustre
1475 # XXX This function is kept for interoperability with old server (< 2.3.50),
1476 # it should be removed whenever we drop the interoperability for such
1479 local fsname=${1:-$FSNAME}
1481 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1483 do_nodes $(comma_list $(osts_nodes)) \
1484 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1488 # get mdt quota type
1490 local varsvc=${SINGLEMDS}_svc
1491 do_facet $SINGLEMDS $LCTL get_param -n \
1492 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1495 # get ost quota type
1497 # All OSTs should have same quota type
1498 local varsvc=ost1_svc
1499 do_facet ost1 $LCTL get_param -n \
1500 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1503 # restore old quota type settings
1505 if [ "$old_MDT_QUOTA_TYPE" ]; then
1506 do_facet mgs $LCTL conf_param \
1507 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1509 if [ "$old_OST_QUOTA_TYPE" ]; then
1510 do_facet mgs $LCTL conf_param \
1511 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1515 # Handle the case when there is a space in the lfs df
1516 # "filesystem summary" line the same as when there is no space.
1517 # This will allow fixing the "lfs df" summary line in the future.
1519 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1522 # Get free inodes on the MDT specified by mdt index, free indoes on
1523 # the whole filesystem will be returned when index == -1.
1529 if [ $index -eq -1 ]; then
1532 mdt_uuid=$(mdtuuid_from_index $index)
1535 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1540 # Get the OST device status from 'lfs df' with a given OST index.
1544 local mnt_pnt=${2:-$MOUNT}
1547 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1548 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1554 # save old quota type & set new quota type
1555 local mdt_qtype=$(mdt_quota_type)
1556 local ost_qtype=$(ost_quota_type)
1558 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1559 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1561 export old_MDT_QUOTA_TYPE=$mdt_qtype
1562 export old_OST_QUOTA_TYPE=$ost_qtype
1564 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1565 error "set mdt quota type failed"
1566 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1567 error "set ost quota type failed"
1569 local quota_usrs=$QUOTA_USERS
1571 # get_filesystem_size
1572 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1573 local blk_soft=$((disksz + 1024))
1574 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1576 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1577 local i_soft=$inodes
1578 local i_hard=$((i_soft + i_soft / 20))
1580 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1581 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1582 "inode-hardlimit: $i_hard"
1585 for usr in $quota_usrs; do
1586 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1588 cmd="$LFS setquota -$type $usr -b $blk_soft"
1589 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1591 eval $cmd || error "$cmd FAILED!"
1593 # display the quota status
1594 echo "Quota settings for $usr : "
1595 $LFS quota -v -u $usr $mntpt || true
1602 local opts=${3:-$MOUNT_OPTS}
1603 opts=${opts:+-o $opts}
1604 local flags=${4:-$MOUNT_FLAGS}
1606 local device=$MGSNID:/$FSNAME$FILESET
1607 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1608 echo "Bad mount command: opt=$flags $opts dev=$device " \
1613 echo "Starting client: $client: $flags $opts $device $mnt"
1614 do_node $client mkdir -p $mnt
1615 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1616 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1618 #disable FILESET if not supported
1619 do_nodes $client lctl get_param -n \
1620 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1621 device=$MGSNID:/$FSNAME
1622 do_node $client mkdir -p $mnt/$FILESET
1623 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1626 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1628 set_default_debug_nodes $client
1640 [ "$3" ] && force=-f
1641 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1642 if [ $running -ne 0 ]; then
1643 echo "Stopping client $client $mnt (opts:$force)"
1644 do_node $client lsof -t $mnt || need_kill=no
1645 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1646 pids=$(do_node $client lsof -t $mnt | sort -u);
1647 if [ -n $pids ]; then
1648 do_node $client kill -9 $pids || true
1652 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1653 if [ $busy -ne 0 ] ; then
1654 echo "$mnt is still busy, wait one second" && sleep 1
1655 do_node $client umount $force $mnt
1660 # nodes is comma list
1661 sanity_mount_check_nodes () {
1667 # FIXME: assume that all cluster nodes run the same os
1668 [ "$(uname)" = Linux ] || return 0
1671 for mnt in $mnts ; do
1672 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1673 mpts=\\\$(mount | grep -c $mnt' ');
1674 if [ \\\$running -ne \\\$mpts ]; then
1675 echo \\\$(hostname) env are INSANE!;
1678 [ $? -eq 0 ] || rc=1
1683 sanity_mount_check_servers () {
1684 [ -n "$CLIENTONLY" ] &&
1685 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1686 echo Checking servers environments
1688 # FIXME: modify get_facets to display all facets wo params
1689 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1693 for facet in ${facets//,/ }; do
1694 node=$(facet_host ${facet})
1695 mntpt=$(facet_mntpt $facet)
1696 sanity_mount_check_nodes $node $mntpt ||
1697 { error "server $node environments are insane!"; return 1; }
1701 sanity_mount_check_clients () {
1702 local clients=${1:-$CLIENTS}
1703 local mntpt=${2:-$MOUNT}
1704 local mntpt2=${3:-$MOUNT2}
1706 [ -z $clients ] && clients=$(hostname)
1707 echo Checking clients $clients environments
1709 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1710 error "clients environments are insane!"
1713 sanity_mount_check () {
1714 sanity_mount_check_servers || return 1
1715 sanity_mount_check_clients || return 2
1718 # mount clients if not mouted
1719 zconf_mount_clients() {
1722 local opts=${3:-$MOUNT_OPTS}
1723 opts=${opts:+-o $opts}
1724 local flags=${4:-$MOUNT_FLAGS}
1726 local device=$MGSNID:/$FSNAME$FILESET
1727 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1728 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1733 echo "Starting client $clients: $flags $opts $device $mnt"
1734 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1735 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1737 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1739 #disable FILESET if not supported
1740 do_nodes $clients lctl get_param -n \
1741 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1742 device=$MGSNID:/$FSNAME
1743 do_nodes $clients mkdir -p $mnt/$FILESET
1744 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1749 running=\\\$(mount | grep -c $mnt' ');
1751 if [ \\\$running -eq 0 ] ; then
1753 $MOUNT_CMD $flags $opts $device $mnt;
1756 exit \\\$rc" || return ${PIPESTATUS[0]}
1758 echo "Started clients $clients: "
1759 do_nodes $clients "mount | grep $mnt' '"
1761 set_default_debug_nodes $clients
1766 zconf_umount_clients() {
1771 [ "$3" ] && force=-f
1773 echo "Stopping clients: $clients $mnt (opts:$force)"
1774 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1775 if [ \\\$running -ne 0 ] ; then
1776 echo Stopping client \\\$(hostname) $mnt opts:$force;
1777 lsof $mnt || need_kill=no;
1778 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1779 pids=\\\$(lsof -t $mnt | sort -u);
1780 if [ -n \\\"\\\$pids\\\" ]; then
1784 while umount $force $mnt 2>&1 | grep -q "busy"; do
1785 echo "$mnt is still busy, wait one second" && sleep 1;
1792 echo + $POWER_DOWN $node
1796 shutdown_node_hard () {
1798 local attempts=$SHUTDOWN_ATTEMPTS
1800 for i in $(seq $attempts) ; do
1803 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1804 echo "waiting for $host to fail attempts=$attempts"
1805 [ $i -lt $attempts ] || \
1806 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1812 local mnt=${2:-$MOUNT}
1815 if [ "$FAILURE_MODE" = HARD ]; then
1816 shutdown_node_hard $client
1818 zconf_umount_clients $client $mnt -f
1824 local facets="$(get_facets OST),$(get_facets MDS)"
1827 combined_mgs_mds || facets="$facets,mgs"
1829 for facet in ${facets//,/ }; do
1830 if [ $(facet_active_host $facet) == $host ]; then
1831 affected="$affected $facet"
1835 echo $(comma_list $affected)
1840 local host=${2:-$(facet_host $facet)}
1842 local label=$(convert_facet2label $facet)
1843 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1846 facets_up_on_host () {
1848 local facets=$(facets_on_host $host)
1851 for facet in ${facets//,/ }; do
1852 if $(facet_up $facet $host); then
1853 affected_up="$affected_up $facet"
1857 echo $(comma_list $affected_up)
1863 if [ "$FAILURE_MODE" = HARD ]; then
1864 shutdown_node_hard $(facet_active_host $facet)
1872 echo + $POWER_UP $node
1885 if [ "$FAILURE_MODE" = HARD ]; then
1886 reboot_node $(facet_active_host $facet)
1894 if [ "$FAILURE_MODE" = HARD ]; then
1904 for facet in ${facets//,/ }; do
1905 hosts=$(expand_list $hosts $(facet_host $facet) )
1911 _check_progs_installed () {
1915 for prog in $progs; do
1916 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1917 echo $prog missing on $(hostname)
1924 check_progs_installed () {
1928 do_rpc_nodes "$nodes" _check_progs_installed $@
1931 # recovery-scale functions
1933 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1936 start_client_load() {
1939 local var=$(node_var_name $client)_load
1940 eval export ${var}=$load
1942 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1943 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1944 END_RUN_FILE=$END_RUN_FILE \
1945 LOAD_PID_FILE=$LOAD_PID_FILE \
1946 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1947 TESTNAME=$TESTNAME \
1948 DBENCH_LIB=$DBENCH_LIB \
1949 DBENCH_SRC=$DBENCH_SRC \
1950 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1954 log "Started client load: ${load} on $client"
1956 # get the children process IDs
1957 local pids=$(ps --ppid $ppid -o pid= | xargs)
1958 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1962 start_client_loads () {
1963 local -a clients=(${1//,/ })
1964 local numloads=${#CLIENT_LOADS[@]}
1967 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1968 testnum=$((nodenum % numloads))
1969 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1971 # bug 22169: wait the background threads to start
1975 # only for remote client
1976 check_client_load () {
1978 local var=$(node_var_name $client)_load
1979 local testload=run_${!var}.sh
1981 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
1983 # bug 18914: try to connect several times not only when
1984 # check ps, but while check_node_health also
1988 while [ $RC = 254 -a $tries -gt 0 ]; do
1992 if ! check_node_health $client; then
1994 if [ $RC -eq 254 ]; then
1995 # FIXME: not sure how long we shuold sleep here
1999 echo "check node health failed: RC=$RC "
2003 # We can continue try to connect if RC=254
2004 # Just print the warning about this
2005 if [ $RC = 254 ]; then
2006 echo "got a return status of $RC from do_node while checking " \
2007 "node health on $client"
2010 # see if the load is still on the client
2013 while [ $RC = 254 -a $tries -gt 0 ]; do
2017 if ! do_node $client \
2018 "ps auxwww | grep -v grep | grep -q $testload"; then
2023 if [ $RC = 254 ]; then
2024 echo "got a return status of $RC from do_node while checking " \
2025 "(node health and 'ps') the client load on $client"
2026 # see if we can diagnose a bit why this is
2031 check_client_loads () {
2032 local clients=${1//,/ }
2036 for client in $clients; do
2037 check_client_load $client
2039 if [ "$rc" != 0 ]; then
2040 log "Client load failed on node $client, rc=$rc"
2046 restart_client_loads () {
2047 local clients=${1//,/ }
2048 local expectedfail=${2:-""}
2052 for client in $clients; do
2053 check_client_load $client
2055 if [ "$rc" != 0 -a "$expectedfail" ]; then
2056 local var=$(node_var_name $client)_load
2057 start_client_load $client ${!var}
2058 echo "Restarted client load ${!var}: on $client. Checking ..."
2059 check_client_load $client
2061 if [ "$rc" != 0 ]; then
2062 log "Client load failed to restart on node $client, rc=$rc"
2063 # failure one client load means test fail
2064 # we do not need to check other
2073 # Start vmstat and save its process ID in a file.
2078 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2081 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2082 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2085 # Display the nodes on which client loads failed.
2086 print_end_run_file() {
2090 [ -s $file ] || return 0
2092 echo "Found the END_RUN_FILE file: $file"
2095 # A client load will stop if it finds the END_RUN_FILE file.
2096 # That does not mean the client load actually failed though.
2097 # The first node in END_RUN_FILE is the one we are interested in.
2100 if [ -n "$node" ]; then
2101 local var=$(node_var_name $node)_load
2103 local prefix=$TESTLOG_PREFIX
2104 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2105 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2106 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2108 echo "Client load ${!var} failed on node $node:"
2114 # Stop the process which had its PID saved in a file.
2119 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2121 do_nodes $nodes "test -f $pid_file &&
2122 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2125 # Stop all client loads.
2126 stop_client_loads() {
2127 local nodes=${1:-$CLIENTS}
2130 # stop the client loads
2131 stop_process $nodes $pid_file
2133 # clean up the processes that started them
2134 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2136 # End recovery-scale functions
2138 # verify that lustre actually cleaned up properly
2140 VAR=$(lctl get_param -n catastrophe 2>&1)
2141 if [ $? = 0 ] ; then
2142 if [ $VAR != 0 ]; then
2143 error "LBUG/LASSERT detected"
2146 BUSY=$(dmesg | grep -i destruct || true)
2147 if [ -n "$BUSY" ]; then
2149 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2153 check_mem_leak || exit 204
2155 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2156 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2159 if module_loaded lnet || module_loaded libcfs; then
2160 echo "$TESTSUITE: modules still loaded..." 1>&2
2169 if [[ "$1" == "--verbose" ]]; then
2184 PREV_RESULT=$(do_node $node "$TEST")
2186 RESULT=$(do_node $node "$TEST")
2187 if [[ "$RESULT" == "$FINAL" ]]; then
2188 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2189 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2193 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2194 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2198 [[ $WAIT -ge $MAX ]] && break
2199 [[ $((WAIT % print)) -eq 0 ]] &&
2200 echo "Waiting $((MAX - WAIT)) secs for update"
2201 WAIT=$((WAIT + sleep))
2204 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2208 wait_update_facet() {
2210 [ "$1" = "--verbose" ] && verbose="$1" && shift
2214 wait_update $verbose $(facet_active_host $facet) "$@"
2218 do_nodes $(comma_list $(mdts_nodes)) \
2219 "lctl set_param -n osd*.*MDT*.force_sync=1"
2220 do_nodes $(comma_list $(osts_nodes)) \
2221 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2222 grep -v 'Found no match'
2226 # the occupied disk space will be released
2227 # only after DMUs are committed
2228 if [[ $(facet_fstype $1) == zfs ]]; then
2229 echo "sleep $2 for ZFS OSD"
2234 wait_delete_completed_mds() {
2235 local MAX_WAIT=${1:-20}
2236 # for ZFS, waiting more time for DMUs to be committed
2237 local ZFS_WAIT=${2:-5}
2239 local stime=$(date +%s)
2244 # find MDS with pending deletions
2245 for node in $(mdts_nodes); do
2246 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2247 2>/dev/null | calc_sum)
2248 if [[ $changes -eq 0 ]]; then
2251 mds2sync="$mds2sync $node"
2253 if [ -z "$mds2sync" ]; then
2254 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2257 mds2sync=$(comma_list $mds2sync)
2259 # sync MDS transactions
2260 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2262 # wait till all changes are sent and commmitted by OSTs
2263 # for ldiskfs space is released upon execution, but DMU
2264 # do this upon commit
2267 while [[ $WAIT -ne $MAX_WAIT ]]; do
2268 changes=$(do_nodes $mds2sync \
2269 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2270 #echo "$node: $changes changes on all"
2271 if [[ $changes -eq 0 ]]; then
2272 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2280 echo "Delete is not completed in $((etime - stime)) seconds"
2281 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2287 # we can use "for" here because we are waiting the slowest
2288 for host in ${hostlist//,/ }; do
2289 check_network "$host" 900
2291 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2298 for facet in ${facetlist//,/ }; do
2299 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2301 wait_for_host $hostlist
2304 _wait_recovery_complete () {
2307 # Use default policy if $2 is not passed by caller.
2308 local MAX=${2:-$(max_recovery_time)}
2313 while [ $WAIT -lt $MAX ]; do
2314 STATUS=$(lctl get_param -n $param | grep status)
2316 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2319 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2321 echo "$param recovery not done in $MAX sec. $STATUS"
2325 wait_recovery_complete () {
2328 # with an assumption that at_max is the same on all nodes
2329 local MAX=${2:-$(max_recovery_time)}
2332 if [ "$FAILURE_MODE" = HARD ]; then
2333 facets=$(facets_on_host $(facet_active_host $facet))
2335 echo affected facets: $facets
2337 # we can use "for" here because we are waiting the slowest
2338 for facet in ${facets//,/ }; do
2339 local var_svc=${facet}_svc
2340 local param="*.${!var_svc}.recovery_status"
2342 local host=$(facet_active_host $facet)
2343 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2347 wait_mds_ost_sync () {
2348 # just because recovery is done doesn't mean we've finished
2349 # orphan cleanup. Wait for llogs to get synchronized.
2350 echo "Waiting for orphan cleanup..."
2351 # MAX value includes time needed for MDS-OST reconnection
2352 local MAX=$(( TIMEOUT * 2 ))
2353 local WAIT_TIMEOUT=${1:-$MAX}
2356 local list=$(comma_list $(mdts_nodes))
2357 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2358 if ! do_facet $SINGLEMDS \
2359 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2361 # old way, use mds_sync
2363 list=$(comma_list $(osts_nodes))
2364 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2367 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2368 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2369 local -a sync=($(do_nodes $list "$cmd"))
2372 for ((i=0; i<${#sync[@]}; i++)); do
2374 [ ${sync[$i]} -eq 1 ] && continue
2376 [ ${sync[$i]} -eq 0 ] && continue
2378 # there is a not finished MDS-OST synchronization
2382 sleep 2 # increase waiting time and cover statfs cache
2383 [ ${con} -eq 1 ] && return 0
2384 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2388 # show which nodes are not finished.
2389 do_nodes $list "$cmd"
2390 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2394 # Wait OSTs to be active on both client and MDT side.
2396 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2397 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2398 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2399 error "wait_update OSTs up on client failed"
2401 cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
2402 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2403 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2404 error "wait_update OSTs up on MDT failed"
2407 wait_destroy_complete () {
2408 echo "Waiting for local destroys to complete"
2409 # MAX value shouldn't be big as this mean server responsiveness
2410 # never increase this just to make test pass but investigate
2411 # why it takes so long time
2414 while [ $WAIT -lt $MAX ]; do
2415 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2419 for ((i=0; i<${#RPCs[@]}; i++)); do
2420 [ ${RPCs[$i]} -eq 0 ] && continue
2421 # there are still some destroy RPCs in flight
2426 [ ${con} -eq 1 ] && return 0 # done waiting
2427 echo "Waiting ${WAIT}s for local destroys to complete"
2430 echo "Local destroys weren't done in $MAX sec."
2434 wait_delete_completed() {
2435 wait_delete_completed_mds $1 || return $?
2436 wait_destroy_complete
2445 # conf-sanity 31 takes a long time cleanup
2446 while [ $WAIT -lt 300 ]; do
2447 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2448 [ -z "${running}" ] && return 0
2449 echo "waited $WAIT for${running}"
2450 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2452 WAIT=$((WAIT + INTERVAL))
2454 echo "service didn't stop after $WAIT seconds. Still running:"
2459 wait_remote_prog () {
2465 [ "$PDSH" = "no_dsh" ] && return 0
2467 while [ $WAIT -lt $2 ]; do
2468 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2469 [ -z "${running}" ] && return 0 || true
2470 echo "waited $WAIT for: "
2472 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2474 WAIT=$((WAIT + INTERVAL))
2476 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2477 [ -z "$pids" ] && return 0
2478 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2479 # FIXME: not portable
2480 for pid in $pids; do
2481 cat /proc/${pid}/status || true
2482 cat /proc/${pid}/wchan || true
2484 kill -9 $pid || true
2493 local clients=${1:-$CLIENTS}
2495 if [ -z "$clients" ]; then
2498 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2504 # not every config has many clients
2510 # usually checked on particular client or locally
2519 client_reconnect_try() {
2520 local f=$MOUNT/recon
2523 if [ -z "$CLIENTS" ]; then
2524 $LFS df $MOUNT; uname -n >> $f
2526 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2528 echo "Connected clients: $(cat $f)"
2529 ls -l $f > /dev/null
2533 client_reconnect() {
2534 # one client_reconnect_try call does not always do the job...
2536 client_reconnect_try && break
2541 affected_facets () {
2544 local host=$(facet_active_host $facet)
2545 local affected=$facet
2547 if [ "$FAILURE_MODE" = HARD ]; then
2548 affected=$(facets_up_on_host $host)
2554 local E2FSCK_ON_MDT0=false
2555 if [ "$1" == "--fsck" ]; then
2557 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2569 #Because it will only get up facets, we need get affected
2570 #facets before shutdown
2571 #For HARD Failure mode, it needs make sure facets on the same
2572 #HOST will only be shutdown and reboot once
2573 for facet in ${facets//,/ }; do
2574 local affected_facet
2576 #check whether facet has been included in other affected facets
2577 for ((index=0; index<$total; index++)); do
2578 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2581 if [ $skip -eq 0 ]; then
2582 affecteds[$total]=$(affected_facets $facet)
2587 for ((index=0; index<$total; index++)); do
2588 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2589 local host=$(facet_active_host $facet)
2590 echo "Failing ${affecteds[index]} on $host"
2591 shutdown_facet $facet
2594 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2595 $(mdsdevname 1) "-n" || error "Running e2fsck")
2597 for ((index=0; index<$total; index++)); do
2598 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2599 echo reboot facets: ${affecteds[index]}
2603 change_active ${affecteds[index]}
2605 wait_for_facet ${affecteds[index]}
2606 # start mgs first if it is affected
2607 if ! combined_mgs_mds &&
2608 list_member ${affecteds[index]} mgs; then
2609 mount_facet mgs || error "Restart of mgs failed"
2611 # FIXME; has to be changed to mount all facets concurrently
2612 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2613 echo mount facets: ${affecteds[index]}
2614 mount_facets ${affecteds[index]}
2624 do_facet $facet "sync; sync; sync"
2627 # make sure there will be no seq change
2628 local clients=${CLIENTS:-$HOSTNAME}
2629 local f=fsa-\\\$\(hostname\)
2630 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2631 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2633 local svc=${facet}_svc
2634 do_facet $facet $LCTL --device ${!svc} notransno
2636 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2637 # in-memory state has to be cleared by either rebooting the host or
2638 # exporting and reimporting the pool.
2640 # Although the uberblocks are not updated when a pool is freezed,
2641 # transactions are still written to the disks. Modified blocks may be
2642 # cached in memory when tests try reading them back. The
2643 # export-and-reimport process also evicts any cached pool data from
2644 # memory to provide the correct "data loss" semantics.
2646 # In the test framework, the exporting and importing operations are
2647 # handled by stop() and mount_facet() separately, which are used
2648 # inside fail() and fail_abort().
2650 do_facet $facet $LCTL --device ${!svc} readonly
2651 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2652 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2655 replay_barrier_nodf() {
2656 local facet=$1 echo running=${running}
2657 do_facet $facet "sync; sync; sync"
2658 local svc=${facet}_svc
2659 echo Replay barrier on ${!svc}
2660 do_facet $facet $LCTL --device ${!svc} notransno
2661 do_facet $facet $LCTL --device ${!svc} readonly
2662 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2663 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2666 replay_barrier_nosync() {
2667 local facet=$1 echo running=${running}
2668 local svc=${facet}_svc
2669 echo Replay barrier on ${!svc}
2670 do_facet $facet $LCTL --device ${!svc} notransno
2671 do_facet $facet $LCTL --device ${!svc} readonly
2672 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2673 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2677 # Get Lustre client uuid for a given Lustre mount point.
2680 local mntpnt=${1:-$MOUNT}
2682 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2683 local uuid=$($LCTL get_param -n llite.$name.uuid)
2688 mds_evict_client() {
2689 local mntpnt=${1:-$MOUNT}
2690 local uuid=$(get_client_uuid $mntpnt)
2692 do_facet $SINGLEMDS \
2693 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2696 ost_evict_client() {
2697 local mntpnt=${1:-$MOUNT}
2698 local uuid=$(get_client_uuid $mntpnt)
2701 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2706 local clients=${CLIENTS:-$HOSTNAME}
2708 facet_failover $* || error "failover: $?"
2709 wait_clients_import_state "$clients" "$facets" FULL
2710 clients_up || error "post-failover stat: $?"
2715 facet_failover $facet
2721 change_active $facet
2722 wait_for_facet $facet
2723 mount_facet $facet -o abort_recovery
2724 clients_up || echo "first stat failed: $?"
2725 clients_up || error "post-failover stat: $?"
2729 echo There is no lmc. This is mountconf, baby.
2733 host_nids_address() {
2737 if [ -n "$kind" ]; then
2738 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2740 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2746 if [ "$1" = "'*'" ]; then echo \'*\'; else
2752 if [ "$1" = "'*'" ]; then echo \'*\'; else
2753 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2755 if [ -z "$ID" ]; then
2756 echo "Could not get a ptl id for $1..."
2765 h2name_or_ip "$1" "tcp"
2770 if [ "$1" = "'*'" ]; then echo \'*\'; else
2771 if type __h2elan >/dev/null 2>&1; then
2774 ID=`echo $1 | sed 's/[^0-9]*//g'`
2782 h2name_or_ip "$1" "o2ib"
2786 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2787 # expressions format. As a bonus we can then just pass in those variables
2788 # to pdsh. What this function does is take a HOSTLIST type string and
2789 # expand it into a space deliminated list for us.
2797 [ -z "$hostlist" ] && return
2799 # Translate the case of [..],..,[..] to [..] .. [..]
2800 list="${hostlist/],/] }"
2802 [[ "$front" == *,* ]] && {
2805 list=${list/${old}/${new}}
2808 for item in $list; do
2809 # Test if we have any []'s at all
2810 if [ "$item" != "${item/\[/}" ]; then {
2811 # Expand the [*] into list
2815 if [ "$name" != "$item" ]; then
2816 group=${item#$name[*}
2819 for range in ${group//,/ }; do
2823 # Number of leading zeros
2826 end=$(echo $end | sed 's/0*//')
2827 [[ -z "$end" ]] && end=0
2828 [[ $padlen2 -gt $padlen ]] && {
2829 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2832 begin=$(echo $begin | sed 's/0*//')
2833 [ -z $begin ] && begin=0
2835 for num in $(seq -f "%0${padlen}g" $begin $end); do
2836 value="${name#*,}${num}${back}"
2837 [ "$value" != "${value/\[/}" ] && {
2838 value=$(hostlist_expand "$value")
2840 myList="$myList $value"
2845 myList="$myList $item"
2848 myList=${myList//,/ }
2849 myList=${myList:1} # Remove first character which is a space
2851 # Filter any duplicates without sorting
2853 myList="${list%% *}"
2855 while [[ "$list" != ${myList##* } ]]; do
2856 local tlist=" $list"
2857 list=${tlist// ${list%% *} / }
2859 myList="$myList ${list%% *}"
2861 myList="${myList%* }";
2863 # We can select an object at an offset in the list
2866 for item in $myList; do
2868 [ $cnt -eq $offset ] && {
2872 [ $(get_node_count $myList) -ne 1 ] && myList=""
2881 [ "$facet" == client ] && echo -n $HOSTNAME && return
2882 varname=${facet}_HOST
2883 if [ -z "${!varname}" ]; then
2884 if [ "${facet:0:3}" == "ost" ]; then
2885 local fh=${facet%failover}_HOST
2886 eval export ${facet}_HOST=${!fh}
2887 if [ -z "${!varname}" ]; then
2888 eval export ${facet}_HOST=${ost_HOST}
2890 elif [ "${facet:0:3}" == "mdt" -o \
2891 "${facet:0:3}" == "mds" -o \
2892 "${facet:0:3}" == "mgs" ]; then
2893 eval export ${facet}_HOST=${mds_HOST}
2899 facet_failover_host() {
2903 var=${facet}failover_HOST
2904 if [ -n "${!var}" ]; then
2909 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2910 "${facet:0:3}" == "mgs" ]; then
2912 eval export ${facet}failover_host=${mds_HOST}
2917 if [[ $facet == ost* ]]; then
2918 eval export ${facet}failover_host=${ost_HOST}
2926 local activevar=${facet}active
2928 if [ -f $TMP/${facet}active ] ; then
2929 source $TMP/${facet}active
2932 active=${!activevar}
2933 if [ -z "$active" ] ; then
2940 facet_active_host() {
2941 facet_host $(facet_active $1)
2944 # Get the passive failover partner host of facet.
2945 facet_passive_host() {
2947 [[ $facet = client ]] && return
2949 local host=${facet}_HOST
2950 local failover_host=${facet}failover_HOST
2951 local active_host=$(facet_active_host $facet)
2953 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2955 if [[ $active_host = ${!host} ]]; then
2956 echo -n ${!failover_host}
2966 facetlist=$(exclude_items_from_list $facetlist mgs)
2968 for facet in ${facetlist//,/ }; do
2969 local failover=${facet}failover
2970 local host=`facet_host $failover`
2971 [ -z "$host" ] && return
2973 local curactive=`facet_active $facet`
2974 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2975 eval export ${facet}active=$facet
2977 eval export ${facet}active=$failover
2979 # save the active host for this facet
2980 local activevar=${facet}active
2981 echo "$activevar=${!activevar}" > $TMP/$activevar
2982 [[ $facet = mds1 ]] && combined_mgs_mds && \
2983 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2984 local TO=`facet_active_host $facet`
2985 echo "Failover $facet to $TO"
2991 # do not stripe off hostname if verbose, bug 19215
2992 if [ x$1 = x--verbose ]; then
3000 if [ "$HOST" = "$HOSTNAME" ]; then
3002 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3003 echo "cannot run remote command on $HOST with $myPDSH"
3007 echo "CMD: $HOST $@" >&2
3008 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3011 if [ "$myPDSH" = "rsh" ]; then
3012 # we need this because rsh does not return exit code of an executed command
3013 local command_status="$TMP/cs"
3014 rsh $HOST ":> $command_status"
3015 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3016 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3017 echo command failed >$command_status"
3018 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3023 # print HOSTNAME for myPDSH="no_dsh"
3024 if [[ $myPDSH = no_dsh ]]; then
3025 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3027 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3030 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3032 return ${PIPESTATUS[0]}
3036 do_node --verbose "$@"
3039 single_local_node () {
3040 [ "$1" = "$HOSTNAME" ]
3043 # Outputs environment variable assignments that should be passed to remote nodes
3047 local facets=$(get_facets)
3050 for var in ${!MODOPTS_*}; do
3051 value=${!var//\"/\\\"}
3052 echo -n " ${var}=\"$value\""
3055 for facet in ${facets//,/ }; do
3057 if [ -n "${!var}" ]; then
3058 echo -n " $var=${!var}"
3062 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3063 if [ -n "${!var}" ]; then
3064 echo -n " $var=${!var}"
3068 for var in VERBOSE; do
3069 if [ -n "${!var}" ]; then
3070 echo -n " $var=${!var}"
3074 if [ -n "$FSTYPE" ]; then
3075 echo -n " FSTYPE=$FSTYPE"
3078 for var in LNETLND NETTYPE; do
3079 if [ -n "${!var}" ]; then
3080 echo -n " $var=${!var}"
3087 # do not stripe off hostname if verbose, bug 19215
3088 if [ x$1 = x--verbose ]; then
3096 if single_local_node $rnodes; then
3098 do_nodev $rnodes "$@"
3100 do_node $rnodes "$@"
3105 # This is part from do_node
3108 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3109 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3111 export FANOUT=$(get_node_count "${rnodes//,/ }")
3113 echo "CMD: $rnodes $@" >&2
3114 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3117 # do not replace anything from pdsh output if -N is used
3118 # -N Disable hostname: prefix on lines of output.
3119 if $verbose || [[ $myPDSH = *-N* ]]; then
3120 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3122 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3124 return ${PIPESTATUS[0]}
3128 # Execute commands on a single service's host
3130 # The \a facet (service) may be on a local or remote node, which is
3131 # determined at the time the command is run.
3133 # usage: do_facet $facet command [arg ...]
3137 local HOST=$(facet_active_host $facet)
3138 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3142 # Function: do_facet_random_file $FACET $FILE $SIZE
3143 # Creates FILE with random content on the given FACET of given SIZE
3145 do_facet_random_file() {
3149 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3150 do_facet $facet "$cmd 2>/dev/null"
3153 do_facet_create_file() {
3157 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3158 do_facet $facet "$cmd 2>/dev/null"
3162 do_nodes --verbose "$@"
3168 # make sure its not already running
3170 rm -f $TMP/${facet}active
3171 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3172 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3174 if [[ $(facet_fstype $facet) == zfs ]]; then
3176 # After formatting a ZFS target, "cachefile=none" property will
3177 # be set on the ZFS storage pool so that the pool is not
3178 # automatically imported on system startup. And then the pool
3179 # will be exported so as to leave the importing and exporting
3180 # operations handled by mount_facet() and stop() separately.
3182 refresh_partition_table $facet $(facet_vdevice $facet)
3183 disable_zpool_cache $facet
3188 # Device formatted as ost
3191 local DEVNAME=OSTDEV$num
3193 local fstype=$(facet_fstype ost$num)
3197 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3198 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3200 #try $OSTZFSDEVn - independent of vdev
3201 DEVNAME=OSTZFSDEV$num
3202 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3204 error "unknown fstype!";;
3210 # Physical device location of data
3216 local fstype=$(facet_fstype ost$num)
3220 # vdevs are not supported by ldiskfs
3223 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3224 # Device formatted by zfs
3226 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3228 error "unknown fstype!";;
3234 # Logical device formatted for lustre
3237 local DEVNAME=MDSDEV$num
3239 local fstype=$(facet_fstype mds$num)
3243 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3244 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3246 # try $MDSZFSDEVn - independent of vdev
3247 DEVNAME=MDSZFSDEV$num
3248 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3250 error "unknown fstype!";;
3256 # Physical location of data
3260 local fstype=$(facet_fstype mds$num)
3264 # vdevs are not supported by ldiskfs
3267 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3268 # Device formatted by ZFS
3269 local DEVNAME=MDSDEV$num
3270 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3272 error "unknown fstype!";;
3280 local fstype=$(facet_fstype mgs)
3284 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3285 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3286 DEVPTR=$(mdsdevname 1)
3291 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3292 ( [ -z "$MGSZFSDEV" ] &&
3293 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3294 DEVPTR=$(mdsdevname 1)
3296 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3299 error "unknown fstype!";;
3308 local fstype=$(facet_fstype mgs)
3312 # vdevs are not supported by ldiskfs
3315 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3316 ( [ -z "$MGSDEV" ] &&
3317 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3318 VDEVPTR=$(mdsvdevname 1)
3319 elif [ -n "$MGSDEV" ]; then
3323 error "unknown fstype!";;
3331 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3333 local var=${facet}_MOUNT
3334 eval mntpt=${!var:-${MOUNT}-$facet}
3341 local dev=$(facet_device $facet)
3342 local mnt=${2:-$(facet_mntpt $facet)}
3345 if ! do_facet $facet test -b $dev; then
3348 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3353 local dev=$(facet_device $facet)
3354 local mnt=${2:-$(facet_mntpt $facet)}
3356 do_facet $facet $UMOUNT $mnt
3360 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3365 local ds=$(facet_device $facet)
3366 local mnt=${2:-$(facet_mntpt $facet)}
3371 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3372 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3373 do_facet $facet $ZFS set canmount=noauto $ds
3375 # The "legacy" mount method is used here because "zfs unmount $mnt"
3376 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3377 # targets are not available at the time, the stat(2) on $MOUNT will
3380 do_facet $facet $ZFS set mountpoint=legacy $ds
3381 do_facet $facet mount -t zfs $ds $mnt
3382 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3383 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3388 local ds=$(facet_device $facet)
3389 local mnt=${2:-$(facet_mntpt $facet)}
3390 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3391 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3392 local mntpt=${!var_mntpt}
3393 local canmnt=${!var_canmnt}
3397 do_facet $facet umount $mnt
3398 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3399 do_facet $facet $ZFS set canmount=$canmnt $ds
3406 local fstype=$(facet_fstype $facet)
3408 mount_$fstype $facet $mnt
3414 local fstype=$(facet_fstype $facet)
3416 unmount_$fstype $facet $mnt
3423 # make sure we are using the primary server, so test-framework will
3424 # be able to clean up properly.
3425 activemds=`facet_active mds1`
3426 if [ $activemds != "mds1" ]; then
3430 local clients=$CLIENTS
3431 [ -z $clients ] && clients=$(hostname)
3433 zconf_umount_clients $clients $MOUNT "$*" || true
3434 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3436 [ -n "$CLIENTONLY" ] && return
3438 # The add fn does rm ${facet}active file, this would be enough
3439 # if we use do_facet <facet> only after the facet added, but
3440 # currently we use do_facet mds in local.sh
3441 for num in `seq $MDSCOUNT`; do
3443 rm -f ${TMP}/mds${num}active
3445 combined_mgs_mds && rm -f $TMP/mgsactive
3447 for num in `seq $OSTCOUNT`; do
3449 rm -f $TMP/ost${num}active
3452 if ! combined_mgs_mds ; then
3459 cleanup_echo_devs () {
3462 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3464 for dev in $devs; do
3465 $LCTL --device $dev cleanup
3466 $LCTL --device $dev detach
3471 nfs_client_mode && return
3472 cifs_client_mode && return
3481 combined_mgs_mds () {
3482 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3483 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3487 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3491 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3497 local fsname=${3:-"$FSNAME"}
3498 local type=$(facet_type $facet)
3499 local index=$(facet_index $facet)
3500 local fstype=$(facet_fstype $facet)
3501 local host=$(facet_host $facet)
3506 if [ $type == MGS ] || ( [ $type == MDS ] &&
3507 [ "$dev" == $(mgsdevname) ] &&
3508 [ "$host" == "$(facet_host mgs)" ] ); then
3511 opts="--mgsnode=$MGSNID"
3514 if [ $type != MGS ]; then
3515 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3519 var=${facet}failover_HOST
3520 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3521 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3524 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3525 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3527 if [ $type == MDS ]; then
3528 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3529 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3530 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3531 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3533 if [ $fstype == ldiskfs ]; then
3534 # Check for wide striping
3535 if [ $OSTCOUNT -gt 160 ]; then
3536 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3537 fs_mkfs_opts+="-O large_xattr"
3541 if [ -n "${!var}" ]; then
3542 fs_mkfs_opts+=" -J device=${!var}"
3544 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3546 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3550 if [ $type == OST ]; then
3551 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3553 if [ $fstype == ldiskfs ]; then
3555 if [ -n "${!var}" ]; then
3556 fs_mkfs_opts+=" -J device=${!var}"
3558 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3563 opts+=" --backfstype=$fstype"
3566 if [ -n "${!var}" ]; then
3567 opts+=" --device-size=${!var}"
3570 var=$(upper $fstype)_MKFS_OPTS
3571 fs_mkfs_opts+=${!var:+" ${!var}"}
3573 var=${type}_FS_MKFS_OPTS
3574 fs_mkfs_opts+=${!var:+" ${!var}"}
3576 if [ -n "${fs_mkfs_opts## }" ]; then
3577 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3581 opts+=${!var:+" ${!var}"}
3586 check_ost_indices() {
3587 local index_count=${#OST_INDICES[@]}
3588 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3590 # OST count is greater than the index count in $OST_INDEX_LIST.
3591 # We need check whether there are duplicate indices.
3595 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3596 index=$(facet_index ost$i)
3597 for j in $(seq 0 $((index_count - 1))); do
3598 [[ $index -ne ${OST_INDICES[j]} ]] ||
3599 error "ost$i has the same index $index as ost$((j+1))"
3610 echo "Format mgs: $(mgsdevname)"
3611 reformat_external_journal mgs
3612 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3613 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3623 echo "Format mds$num: $(mdsdevname $num)"
3624 reformat_external_journal mds$num
3625 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3626 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3627 ${quiet:+>/dev/null} || exit 10
3636 echo "Format ost$num: $(ostdevname $num)"
3637 reformat_external_journal ost$num
3638 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3639 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3640 ${quiet:+>/dev/null} || exit 10
3645 # Set hostid for ZFS/SPL zpool import protection
3646 # (Assumes MDS version is also OSS version)
3647 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3649 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3652 # We need ldiskfs here, may as well load them all
3654 [ -n "$CLIENTONLY" ] && return
3655 echo Formatting mgs, mds, osts
3656 if ! combined_mgs_mds ; then
3660 for num in $(seq $MDSCOUNT); do
3664 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3666 for num in $(seq $OSTCOUNT); do
3672 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3676 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3680 # 0: success, the old identity set already.
3681 # 1: success, the old identity does not set.
3686 local j=`expr $num - 1`
3687 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3689 if [ -z "$MDT" ]; then
3693 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3696 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3698 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3701 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3703 if [ $old = "NONE" ]; then
3712 zconf_umount `hostname` $1 || error "umount failed"
3713 zconf_mount `hostname` $1 || error "mount failed"
3721 rm -f $TMP/${facet}active
3722 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3727 local mdt_count=${1:-$MDSCOUNT}
3728 local ost_count=${2:-$OSTCOUNT}
3731 for num in $(seq $mdt_count); do
3732 DEVNAME=$(mdsdevname $num)
3733 writeconf_facet mds$num $DEVNAME || rc=$?
3736 for num in $(seq $ost_count); do
3737 DEVNAME=$(ostdevname $num)
3738 writeconf_facet ost$num $DEVNAME || rc=$?
3746 nfs_client_mode && return
3747 cifs_client_mode && return
3749 sanity_mount_check || error "environments are insane!"
3753 if [ -z "$CLIENTONLY" ]; then
3754 echo Setup mgs, mdt, osts
3755 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3756 if ! combined_mgs_mds ; then
3757 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3760 for num in `seq $MDSCOUNT`; do
3761 DEVNAME=$(mdsdevname $num)
3762 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3764 # We started mds, now we should set failover variables properly.
3765 # Set mds${num}failover_HOST if it is not set (the default failnode).
3766 local varname=mds${num}failover_HOST
3767 if [ -z "${!varname}" ]; then
3768 eval mds${num}failover_HOST=$(facet_host mds$num)
3771 if [ $IDENTITY_UPCALL != "default" ]; then
3772 switch_identity $num $IDENTITY_UPCALL
3775 for num in `seq $OSTCOUNT`; do
3776 DEVNAME=$(ostdevname $num)
3777 start ost$num $DEVNAME $OST_MOUNT_OPTS
3779 # We started ost$num, now we should set ost${num}failover variable properly.
3780 # Set ost${num}failover_HOST if it is not set (the default failnode).
3781 varname=ost${num}failover_HOST
3782 if [ -z "${!varname}" ]; then
3783 eval ost${num}failover_HOST=$(facet_host ost${num})
3791 # wait a while to allow sptlrpc configuration be propogated to targets,
3792 # only needed when mounting new target devices.
3797 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3799 if [ ! -z $arg1 ]; then
3800 [ "$arg1" = "server_only" ] && return
3804 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3807 if [ "$MOUNT_2" ]; then
3808 mount_client $MOUNT2
3809 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3814 # by remounting mdt before ost, initial connect from mdt to ost might
3815 # timeout because ost is not ready yet. wait some time to its fully
3816 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3817 # by a context negotiation rpc with $TIMEOUT.
3818 # FIXME better by monitoring import status.
3821 sleep $((TIMEOUT + 5))
3827 mounted_lustre_filesystems() {
3828 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3831 init_facet_vars () {
3832 [ -n "$CLIENTONLY" ] && return 0
3839 eval export ${facet}_dev=${device}
3840 eval export ${facet}_opt=\"$@\"
3842 local dev=${facet}_dev
3844 # We need to loop for the label
3845 # in case its not initialized yet.
3846 for wait_time in {0,1,3,5,10}; do
3848 if [ $wait_time -gt 0 ]; then
3849 echo "${!dev} not yet initialized,"\
3850 "waiting ${wait_time} seconds."
3854 local label=$(devicelabel ${facet} ${!dev})
3856 # Check to make sure the label does
3857 # not include ffff at the end of the label.
3858 # This indicates it has not been initialized yet.
3860 if [[ $label =~ [f|F]{4}$ ]]; then
3861 # label is not initialized, unset the result
3862 # and either try again or fail
3869 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3871 eval export ${facet}_svc=${label}
3873 local varname=${facet}failover_HOST
3874 if [ -z "${!varname}" ]; then
3875 eval export $varname=$(facet_host $facet)
3878 varname=${facet}_HOST
3879 if [ -z "${!varname}" ]; then
3880 eval export $varname=$(facet_host $facet)
3883 # ${facet}failover_dev is set in cfg file
3884 varname=${facet}failover_dev
3885 if [ -n "${!varname}" ] ; then
3886 eval export ${facet}failover_dev=${!varname}
3888 eval export ${facet}failover_dev=$device
3891 # get mount point of already mounted device
3892 # is facet_dev is already mounted then use the real
3893 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3894 # i.e. ${facet}_MOUNT if specified by user or default
3895 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3896 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3897 if [ -z $mntpt ]; then
3898 mntpt=$(facet_mntpt $facet)
3900 eval export ${facet}_MOUNT=$mntpt
3903 init_facets_vars () {
3906 if ! remote_mds_nodsh; then
3907 for num in $(seq $MDSCOUNT); do
3908 DEVNAME=`mdsdevname $num`
3909 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3913 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3915 if ! remote_ost_nodsh; then
3916 for num in $(seq $OSTCOUNT); do
3917 DEVNAME=$(ostdevname $num)
3918 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3923 osc_ensure_active () {
3928 while [ $period -lt $timeout ]; do
3929 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3930 if [ $count -eq 0 ]; then
3934 echo "There are $count OST are inactive, wait $period seconds, and try again"
3936 period=$((period+3))
3939 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3942 set_conf_param_and_check() {
3946 local ORIG=$(do_facet $myfacet "$TEST")
3947 if [ $# -gt 3 ]; then
3953 echo "Setting $PARAM from $ORIG to $FINAL"
3954 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3955 error "conf_param $PARAM failed"
3957 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3958 error "check $PARAM failed!"
3961 init_param_vars () {
3962 TIMEOUT=$(lctl get_param -n timeout)
3963 TIMEOUT=${TIMEOUT:-20}
3965 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3967 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3968 log "Using TIMEOUT=$TIMEOUT"
3970 osc_ensure_active $SINGLEMDS $TIMEOUT
3971 osc_ensure_active client $TIMEOUT
3973 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3974 local current_jobid_var=$($LCTL get_param -n jobid_var)
3976 if [ $JOBID_VAR = "existing" ]; then
3977 echo "keeping jobstats as $current_jobid_var"
3978 elif [ $current_jobid_var != $JOBID_VAR ]; then
3979 echo "seting jobstats to $JOBID_VAR"
3981 set_conf_param_and_check client \
3982 "$LCTL get_param -n jobid_var" \
3983 "$FSNAME.sys.jobid_var" $JOBID_VAR
3986 echo "jobstats not supported by server"
3989 if [ $QUOTA_AUTO -ne 0 ]; then
3990 if [ "$ENABLE_QUOTA" ]; then
3991 echo "enable quota as required"
3992 setup_quota $MOUNT || return 2
3994 echo "disable quota as required"
3995 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4001 nfs_client_mode () {
4002 if [ "$NFSCLIENT" ]; then
4003 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4004 local clients=$CLIENTS
4005 [ -z $clients ] && clients=$(hostname)
4007 # FIXME: remove hostname when 19215 fixed
4008 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4009 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4010 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4011 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4013 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4019 cifs_client_mode () {
4020 [ x$CIFSCLIENT = xyes ] &&
4021 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4024 check_config_client () {
4027 local mounted=$(mount | grep " $mntpt ")
4028 if [ -n "$CLIENTONLY" ]; then
4030 # CLIENTONLY should not depend on *_HOST settings
4031 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4032 # in theory someone could create a new,
4033 # client-only config file that assumed lustre was already
4034 # configured and didn't set the MGSNID. If MGSNID is not set,
4035 # then we should use the mgs nid currently being used
4036 # as the default value. bug 18021
4037 [[ x$MGSNID = x ]] &&
4040 if [[ x$mgc != xMGC$MGSNID ]]; then
4041 if [ "$mgs_HOST" ]; then
4042 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4043 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4044 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4050 local myMGS_host=$mgs_HOST
4051 if [ "$NETTYPE" = "ptl" ]; then
4052 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
4055 echo Checking config lustre mounted on $mntpt
4056 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4057 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4059 # if [ "$mgshost" != "$myMGS_host" ]; then
4060 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
4061 # Please use correct config or set mds_HOST correctly!"
4066 check_config_clients () {
4067 local clients=${CLIENTS:-$HOSTNAME}
4070 nfs_client_mode && return
4071 cifs_client_mode && return
4073 do_rpc_nodes "$clients" check_config_client $mntpt
4075 sanity_mount_check || error "environments are insane!"
4079 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4080 local cltimeout=$(lctl get_param -n timeout)
4081 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4082 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4089 [ -z $mntpt ] && return 1
4090 local mounted=$(mounted_lustre_filesystems)
4092 echo $mounted' ' | grep -w -q $mntpt' '
4096 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4100 # empty lustre filesystem may have empty directories lost+found and .lustre
4102 # exclude .lustre & lost+found
4103 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4104 -print | wc -l) = 1 ] || return 1
4105 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4106 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4107 # exclude .lustre/fid (LU-2780)
4108 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4109 -print | wc -l) = 1 ] || return 1
4111 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4116 check_and_setup_lustre() {
4118 nfs_client_mode && return
4119 cifs_client_mode && return
4121 local MOUNTED=$(mounted_lustre_filesystems)
4125 # both MOUNT and MOUNT2 are not mounted
4126 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4127 [ "$REFORMAT" = "yes" ] && formatall
4128 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4130 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4131 export I_MOUNTED=yes
4135 elif is_mounted $MOUNT2; then
4137 # MOUNT2 is mounted, while MOUNT_2 is not set
4138 if ! [ "$MOUNT_2" ]; then
4139 cleanup_mount $MOUNT2
4140 export I_UMOUNTED2=yes
4143 # MOUNT2 is mounted, MOUNT_2 is set
4145 # FIXME: what to do if check_config failed?
4147 # 1) remote client has mounted other Lustre fs ?
4148 # 2) it has insane env ?
4149 # let's try umount MOUNT2 on all clients and mount it again:
4150 if ! check_config_clients $MOUNT2; then
4151 cleanup_mount $MOUNT2
4152 restore_mount $MOUNT2
4153 export I_MOUNTED2=yes
4158 # MOUNT is mounted MOUNT2 is not mounted
4159 elif [ "$MOUNT_2" ]; then
4160 restore_mount $MOUNT2
4161 export I_MOUNTED2=yes
4165 # FIXME: what to do if check_config failed?
4167 # 1) remote client has mounted other Lustre fs?
4168 # 2) lustre is mounted on remote_clients atall ?
4169 check_config_clients $MOUNT
4173 set_default_debug_nodes $(comma_list $(nodes_list))
4176 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4178 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4179 facets="$(get_facets OST)"
4180 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4181 facets="$facets,$(get_facets MDS)"
4182 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4183 facets="$facets,mgs"
4184 local nodes="$(facets_hosts ${facets})"
4185 if [ -n "$nodes" ] ; then
4186 do_nodes $nodes "$LCTL set_param \
4187 osd-ldiskfs.track_declares_assert=1 || true"
4196 if [ -z "$CLIENTONLY" ]; then
4197 # Enable remote MDT create for testing
4198 for num in $(seq $MDSCOUNT); do
4200 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4205 if [ "$ONLY" == "setup" ]; then
4211 local clients=${CLIENTS:-$HOSTNAME}
4214 zconf_mount_clients $clients $mntpt
4218 local clients=${CLIENTS:-$HOSTNAME}
4221 zconf_umount_clients $clients $mntpt
4224 cleanup_and_setup_lustre() {
4225 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4226 lctl set_param debug=0 || true
4228 if [ "$ONLY" == "cleanup" ]; then
4232 check_and_setup_lustre
4235 # Get all of the server target devices from a given server node and type.
4242 if [ "$type" == ost ]; then
4243 devs=$(get_osd_param $node "" mntdev)
4245 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4247 for dev in $devs; do
4249 *loop*) do_node $node "losetup $dev" | \
4250 sed -e "s/.*(//" -e "s/).*//" ;;
4256 # Get all of the server target devices.
4261 # Master MDS parameters used by lfsck
4262 MDTNODE=$(facet_active_host $SINGLEMDS)
4263 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4267 for node in $(mdts_nodes); do
4268 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4274 for node in $(osts_nodes); do
4275 OSTDEVS[i]=$(get_mnt_devs $node ost)
4280 # Run e2fsck on MDT or OST device.
4285 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4286 local log=$TMP/e2fsck.log
4290 do_node $node $cmd 2>&1 | tee $log
4292 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4294 if [ $MDSCOUNT -gt 1 ]; then
4295 skip "DNE mode isn't supported!"
4299 error "It's not DNE mode."
4304 [ $rc -le $FSCK_MAX_ERR ] ||
4305 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4311 # Run resize2fs on MDT or OST device.
4320 do_facet $facet "$RESIZE2FS $opts $device $size"
4323 # verify a directory is shared among nodes.
4324 check_shared_dir() {
4326 local list=${2:-$(comma_list $(nodes_list))}
4328 [ -z "$dir" ] && return 1
4329 do_rpc_nodes "$list" check_logdir $dir
4330 check_write_access $dir "$list" || return 1
4335 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4336 $LCTL set_param printk=+lfsck
4337 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4339 for k in $(seq $MDSCOUNT); do
4340 # wait up to 10+1 minutes for LFSCK to complete
4341 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4342 mdd.$(facet_svc mds${k}).lfsck_layout |
4343 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4344 error "MDS${k} layout isn't the expected 'completed'"
4345 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4346 mdd.$(facet_svc mds${k}).lfsck_namespace |
4347 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4348 error "MDS${k} namespace isn't the expected 'completed'"
4350 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4351 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4352 awk '/repaired/ { print $2 }' | calc_sum)
4353 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4354 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4355 awk '/repaired/ { print $2 }' | calc_sum)
4356 local repaired=$((rep_mdt + rep_ost))
4357 [ $repaired -eq 0 ] ||
4358 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4361 dump_file_contents() {
4367 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4368 error_noexit false \
4369 "Invalid parameters for dump_file_contents()"
4372 for node in ${nodes}; do
4373 do_node $node "for i in \\\$(find $dir -type f); do
4374 echo ====\\\${i}=======================;
4376 done" >> ${logname}.${node}.log
4380 dump_command_output() {
4386 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4387 error_noexit false \
4388 "Invalid parameters for dump_command_output()"
4392 for node in ${nodes}; do
4393 do_node $node "echo ====${cmd}=======================;
4394 $cmd" >> ${logname}.${node}.log
4401 # dump file contents from /proc/spl in case of zfs test
4402 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4403 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4404 dump_command_output \
4405 "$(osts_nodes)" "zpool events -v" "${logname}"
4408 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4409 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4410 dump_command_output \
4411 "$(mdts_nodes)" "zpool events -v" "${logname}"
4415 check_and_cleanup_lustre() {
4416 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4417 "$TESTSUITE" != "sanity-scrub" ]; then
4421 if is_mounted $MOUNT; then
4422 if $DO_CLEANUP; then
4423 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4424 error "remove sub-test dirs failed"
4428 [ "$ENABLE_QUOTA" ] && restore_quota || true
4431 if [ "$I_UMOUNTED2" = "yes" ]; then
4432 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4435 if [ "$I_MOUNTED2" = "yes" ]; then
4436 cleanup_mount $MOUNT2
4439 if [ "$I_MOUNTED" = "yes" ]; then
4440 cleanupall -f || error "cleanup failed"
4448 wait_for_function () {
4451 # suppress fn both stderr and stdout
4452 if [ "$1" = "--quiet" ]; then
4454 quiet=" > /dev/null 2>&1"
4466 eval $fn $quiet && return 0
4468 wait=$((wait + sleep))
4469 [ $wait -lt $max ] || return 1
4470 echo waiting $fn, $((max - wait)) secs left ...
4480 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4481 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4482 echo "Network not available!"
4486 echo `date +"%H:%M:%S (%s)"` network interface is UP
4494 # Convert a space-delimited list to a comma-delimited list. If the input is
4495 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4497 # echo is used to convert newlines to spaces, since it doesn't
4498 # introduce a trailing space as using "tr '\n' ' '" does
4499 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4505 echo $list | grep -qw $item
4508 # list, excluded are the comma separated lists
4509 exclude_items_from_list () {
4515 for item in ${excluded//,/ }; do
4516 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4518 echo $(comma_list $list)
4521 # list, expand are the comma separated lists
4523 local list=${1//,/ }
4524 local expand=${2//,/ }
4527 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4528 echo $(comma_list $expanded)
4531 testslist_filter () {
4532 local script=$LUSTRE/tests/${TESTSUITE}.sh
4534 [ -f $script ] || return 0
4536 local start_at=$START_AT
4537 local stop_at=$STOP_AT
4539 local var=${TESTSUITE//-/_}_START_AT
4540 [ x"${!var}" != x ] && start_at=${!var}
4541 var=${TESTSUITE//-/_}_STOP_AT
4542 [ x"${!var}" != x ] && stop_at=${!var}
4544 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4545 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4546 /^'${start_at}'$/ {flag = 0}
4547 {if (flag == 1) print $0}
4548 /^'${stop_at}'$/ { flag = 1 }'
4552 (cd `dirname $1`; echo $PWD/`basename $1`)
4556 local types=${1:-"OST MDS MGS"}
4560 for entry in $types; do
4561 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4562 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4565 MGS ) list="$list $name";;
4566 MDS|OST|AGT ) local count=${type}COUNT
4567 for ((i=1; i<=${!count}; i++)) do
4568 list="$list ${name}$i"
4570 * ) error "Invalid facet type"
4574 echo $(comma_list $list)
4577 ##################################
4578 # Adaptive Timeouts funcs
4581 # only check mds, we assume at_max is the same on all nodes
4582 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4583 if [ $at_max -eq 0 ]; then
4594 # suppose that all ost-s have the same $at value set
4595 [ $facet != "ost" ] || facet=ost1
4597 do_facet $facet "lctl get_param -n $at"
4615 if [ $facet == "ost" ]; then
4616 facet=$(get_facets OST)
4617 elif [ $facet == "mds" ]; then
4618 facet=$(get_facets MDS)
4620 hosts=$(expand_list $hosts $(facets_hosts $facet))
4623 do_nodes $hosts lctl set_param at_max=$at_max
4626 ##################################
4630 # OBD_FAIL_MDS_ALL_REQUEST_NET
4632 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4633 do_facet client "$1" || RC=$?
4634 do_facet $SINGLEMDS lctl set_param fail_loc=0
4639 # OBD_FAIL_MDS_ALL_REPLY_NET
4641 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4643 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4647 drop_reint_reply() {
4648 # OBD_FAIL_MDS_REINT_NET_REP
4650 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4652 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4656 drop_update_reply() {
4657 # OBD_FAIL_OUT_UPDATE_NET_REP
4661 do_facet mds${index} lctl set_param fail_loc=0x1701
4662 do_facet client "$@" || RC=$?
4663 do_facet mds${index} lctl set_param fail_loc=0
4668 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4671 local timeout=${2:-0}
4672 # default is (obd_timeout / 4) if unspecified
4673 echo "timeout is $timeout/$2"
4674 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4675 do_facet client "$1" || RC=$?
4676 do_facet client "sync"
4677 do_facet ost1 lctl set_param fail_loc=0
4681 drop_ldlm_cancel() {
4682 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4684 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4685 do_nodes $list lctl set_param fail_loc=0x304
4687 do_facet client "$@" || RC=$?
4689 do_nodes $list lctl set_param fail_loc=0
4693 drop_bl_callback_once() {
4695 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4696 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4697 do_facet client lctl set_param fail_loc=0x80000305
4698 do_facet client "$@" || rc=$?
4699 do_facet client lctl set_param fail_loc=0
4700 do_facet client lctl set_param fail_val=0
4701 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4705 drop_bl_callback() {
4707 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4708 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4709 do_facet client lctl set_param fail_loc=0x305
4710 do_facet client "$@" || rc=$?
4711 do_facet client lctl set_param fail_loc=0
4712 do_facet client lctl set_param fail_val=0
4713 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4718 #define OBD_FAIL_LDLM_REPLY 0x30c
4720 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4721 do_nodes $list lctl set_param fail_loc=0x30c
4723 do_facet client "$@" || RC=$?
4725 do_nodes $list lctl set_param fail_loc=0
4729 drop_ldlm_reply_once() {
4730 #define OBD_FAIL_LDLM_REPLY 0x30c
4732 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4733 do_nodes $list lctl set_param fail_loc=0x8000030c
4735 do_facet client "$@" || RC=$?
4737 do_nodes $list lctl set_param fail_loc=0
4745 echo "clearing fail_loc on $facet"
4746 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4749 set_nodes_failloc () {
4751 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4754 cancel_lru_locks() {
4755 #$LCTL mark "cancel_lru_locks $1 start"
4756 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4757 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4758 #$LCTL mark "cancel_lru_locks $1 stop"
4763 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4764 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4765 echo "$DEFAULT_LRU_SIZE"
4770 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4773 lru_resize_disable()
4775 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4781 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4787 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4788 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4789 echo there is still data in page cache $FILE ?
4790 lctl get_param -n $FILE
4798 DEBUGSAVE="$(lctl get_param -n debug)"
4799 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4803 [ -n "$DEBUGSAVE" ] &&
4804 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4808 [ -n "$DEBUGSAVE_SERVER" ] &&
4809 do_nodes $(comma_list $(all_server_nodes)) \
4810 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4816 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4819 debug_size_restore() {
4820 [ -n "$DEBUG_SIZE_SAVED" ] && \
4821 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4825 start_full_debug_logging() {
4830 local DEBUG_SIZE=150
4832 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4833 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4836 stop_full_debug_logging() {
4841 # prints bash call stack
4842 print_stack_trace() {
4845 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4846 local src=${BASH_SOURCE[$i]}
4847 local lineno=${BASH_LINENO[$i-1]}
4848 local funcname=${FUNCNAME[$i]}
4849 echo " = $src:$lineno:$funcname()"
4854 local TYPE=${TYPE:-"FAIL"}
4857 # do not dump logs if $1=false
4858 if [ "x$1" = "xfalse" ]; then
4863 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4864 (print_stack_trace 2) >&2
4866 # We need to dump the logs on all nodes
4868 gather_logs $(comma_list $(nodes_list))
4872 [ "$TESTSUITELOG" ] &&
4873 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4874 if [ -z "$*" ]; then
4875 echo "error() without useful message, please fix" > $LOGDIR/err
4877 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4878 echo "$@" > $LOGDIR/ignore
4880 echo "$@" > $LOGDIR/err
4884 # cleanup the env for failed tests
4888 ##################################
4890 ##################################
4898 local log=$TESTSUITELOG
4900 [ -f "$log" ] && grep -q FAIL $log && status=1
4914 # use only if we are ignoring failures for this test, bugno required.
4915 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4916 # e.g. error_ignore bz5494 "your message" or
4917 # error_ignore LU-5494 "your message"
4919 local TYPE="IGNORE ($1)"
4924 error_and_remount() {
4926 remount_client $MOUNT
4930 # Throw an error if it's not running in vm - usually for performance
4933 local virt=$(running_in_vm)
4934 if [[ -n "$virt" ]]; then
4935 echo "running in VM '$virt', ignore error"
4936 error_ignore env=$virt "$@"
4943 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4948 log " SKIP: $TESTSUITE $TESTNAME $@"
4950 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4951 skip_logged $TESTNAME "$@"
4954 echo "$@" > $LOGDIR/skip
4957 [[ -n "$TESTSUITELOG" ]] &&
4958 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4961 build_test_filter() {
4962 EXCEPT="$EXCEPT $(testslist_filter)"
4965 if [[ $O = [0-9]*-[0-9]* ]]; then
4966 for num in $(seq $(echo $O | tr '-' ' ')); do
4974 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4975 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4976 [ "$EXCEPT_SLOW" ] && \
4977 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4978 for E in $EXCEPT; do
4979 eval EXCEPT_${E}=true
4981 for E in $ALWAYS_EXCEPT; do
4982 eval EXCEPT_ALWAYS_${E}=true
4984 for E in $EXCEPT_SLOW; do
4985 eval EXCEPT_SLOW_${E}=true
4987 for G in $GRANT_CHECK_LIST; do
4988 eval GCHECK_ONLY_${G}=true
4993 if [[ $1 = [a-z]* ]]; then
5000 # print a newline if the last test was skipped
5001 export LAST_SKIPPED=
5002 export ALWAYS_SKIPPED=
5004 # Main entry into test-framework. This is called with the name and
5005 # description of a test. The name is used to find the function to run
5006 # the test using "test_$name".
5008 # This supports a variety of methods of specifying specific test to
5009 # run or not run. These need to be documented...
5014 export base=$(basetest $1)
5015 if [ -n "$ONLY" ]; then
5017 if [ ${!testname}x != x ]; then
5018 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5019 run_one_logged $1 "$2"
5023 if [ ${!testname}x != x ]; then
5024 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5025 run_one_logged $1 "$2"
5035 if [ ${!testname}x != x ]; then
5036 TESTNAME=test_$1 skip "skipping excluded test $1"
5039 testname=EXCEPT_$base
5040 if [ ${!testname}x != x ]; then
5041 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5044 testname=EXCEPT_ALWAYS_$1
5045 if [ ${!testname}x != x ]; then
5046 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5049 testname=EXCEPT_ALWAYS_$base
5050 if [ ${!testname}x != x ]; then
5051 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5054 testname=EXCEPT_SLOW_$1
5055 if [ ${!testname}x != x ]; then
5056 TESTNAME=test_$1 skip "skipping SLOW test $1"
5059 testname=EXCEPT_SLOW_$base
5060 if [ ${!testname}x != x ]; then
5061 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5067 run_one_logged $1 "$2"
5074 load_module ../libcfs/libcfs/libcfs
5086 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5091 strace -o $TMP/$1.strace -ttt $*
5093 log "FINISHED: $*: rc $RC"
5100 banner test complete, duration $duration sec
5101 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5102 echo duration $duration >>$TESTSUITELOG
5106 # Set TEST_STATUS here. It will be used for logging the result.
5109 if [[ -f $LOGDIR/err ]]; then
5111 elif [[ -f $LOGDIR/skip ]]; then
5114 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5118 local FFREE=$(do_node $SINGLEMDS \
5119 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5120 local FTOTAL=$(do_node $SINGLEMDS \
5121 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5123 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5127 echo -n "Resetting fail_loc on all nodes..."
5128 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5129 fail_val=0 2>/dev/null" || true
5135 # Log a message (on all nodes) padded with "=" before and after.
5136 # Also appends a timestamp and prepends the testsuite name.
5139 EQUALS="===================================================================================================="
5141 msg="== ${TESTSUITE} $*"
5143 [[ $last != "=" && $last != " " ]] && msg="$msg "
5144 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5145 # always include at least == after the message
5146 log "$msg== $(date +"%H:%M:%S (%s)")"
5149 check_dmesg_for_errors() {
5151 local errors="VFS: Busy inodes after unmount of\|\
5152 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5153 group descriptors corrupted"
5155 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5156 [ -z "$res" ] && return 0
5157 echo "Kernel error detected: $res"
5162 # Run a single test function and cleanup after it.
5164 # This function should be run in a subshell so the test func can
5165 # exit() without stopping the whole script.
5170 export tfile=f${testnum}.${TESTSUITE}
5171 export tdir=d${testnum}.${TESTSUITE}
5172 export TESTNAME=test_$testnum
5173 local SAVE_UMASK=`umask`
5176 if ! grep -q $DIR /proc/mounts; then
5180 banner "test $testnum: $message"
5181 test_${testnum} || error "test_$testnum failed with $?"
5184 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5186 check_dmesg_for_errors || error "Error in dmesg detected"
5187 if [ "$PARALLEL" != "yes" ]; then
5188 ps auxww | grep -v grep | grep -q multiop &&
5189 error "multiop still running"
5200 # Wrapper around run_one to ensure:
5201 # - test runs in subshell
5202 # - output of test is saved to separate log file for error reporting
5203 # - test result is saved to data file
5206 local BEFORE=$(date +%s)
5208 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5209 local test_log=$LOGDIR/$name
5210 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5211 local zfs_debug_log=$LOGDIR/$zfs_log_name
5213 rm -rf $LOGDIR/ignore
5215 local SAVE_UMASK=$(umask)
5219 log_sub_test_begin test_${1}
5220 (run_one $1 "$2") 2>&1 | tee -i $test_log
5221 local RC=${PIPESTATUS[0]}
5223 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5224 echo "test_$1 returned $RC" | tee $LOGDIR/err
5226 duration=$(($(date +%s) - $BEFORE))
5227 pass "$1" "(${duration}s)"
5229 if [[ -f $LOGDIR/err ]]; then
5230 TEST_ERROR=$(cat $LOGDIR/err)
5231 elif [[ -f $LOGDIR/ignore ]]; then
5232 TEST_ERROR=$(cat $LOGDIR/ignore)
5233 elif [[ -f $LOGDIR/skip ]]; then
5234 TEST_ERROR=$(cat $LOGDIR/skip)
5236 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5238 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5242 if [ -f $LOGDIR/err ]; then
5243 log_zfs_info "$zfs_debug_log"
5244 $FAIL_ON_ERROR && exit $RC
5253 # Print information of skipped tests to result.yml
5256 log_sub_test_begin $1
5258 log_sub_test_end "SKIP" "0" "0" "$@"
5262 (cd $(dirname $1); echo $PWD/$(basename $1))
5267 export base=$(basetest $1)
5268 [ "$CHECK_GRANT" == "no" ] && return 0
5270 testname=GCHECK_ONLY_${base}
5271 [ ${!testname}x == x ] && return 0
5273 echo -n "checking grant......"
5275 local clients=$CLIENTS
5276 [ -z "$clients" ] && clients=$(hostname)
5278 # sync all the data and make sure no pending data on server
5279 do_nodes $clients sync
5282 client_grant=$(do_nodes $clients \
5283 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5284 awk '{ total += $1 } END { printf("%0.0f", total) }')
5287 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5288 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5289 awk '{ total += $1 } END { printf("%0.0f", total) }')
5291 # check whether client grant == server grant
5292 if [[ $client_grant -ne $server_grant ]]; then
5293 echo "failed: client:${client_grant} server: ${server_grant}."
5294 do_nodes $(comma_list $(osts_nodes)) \
5295 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5296 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5299 echo "pass: client:${client_grant} server: ${server_grant}"
5303 ########################
5309 ost=`echo $1 | awk -F_ '{print $3}'`
5310 if [ -z $ost ]; then
5311 ost=`echo $1 | sed 's/-osc.*//'`
5316 ostuuid_from_index()
5318 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5321 ostname_from_index() {
5322 local uuid=$(ostuuid_from_index $1)
5326 index_from_ostuuid()
5328 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5331 mdtuuid_from_index()
5333 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5337 # Return unique identifier for given hostname
5340 echo $host_name | md5sum | cut -d' ' -f1
5344 # Returns list of ip addresses for each interface
5346 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5351 # Cache address list to avoid mutiple execution of local_addr_list
5352 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5354 for i in $LOCAL_ADDR_LIST ; do
5355 [[ "$i" == "$addr" ]] && return 0
5362 local is_local="IS_LOCAL_$(host_id $host_name)"
5363 if [ -z "${!is_local-}" ] ; then
5365 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5366 is_local_addr "$host_ip" && eval $is_local=1
5368 [[ "${!is_local}" == "1" ]]
5373 local_node $node && return 1
5380 for node in $(mdts_nodes); do
5381 remote_node $node && return 0
5388 [ -n "$CLIENTONLY" ] && return 0 || true
5389 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5394 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5395 MSKIPPED=1 && return 1
5402 for node in $(osts_nodes) ; do
5403 remote_node $node && return 0
5410 [ -n "$CLIENTONLY" ] && return 0 || true
5411 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5416 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5417 OSKIPPED=1 && return 1
5423 [ -n "$CLIENTONLY" ] && return 0 || true
5425 MGS=$(facet_host mgs)
5426 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5431 remote_mds_nodsh || remote_ost_nodsh || \
5432 $(single_local_node $(comma_list $(nodes_list)))
5436 remote_ost && remote_mds
5439 # Get the active nodes for facets.
5447 for facet in ${facets//,/ }; do
5448 nodes="$nodes $(facet_active_host $facet)"
5451 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5455 # Get all of the active MDS nodes.
5457 echo -n $(facets_nodes $(get_facets MDS))
5460 # Get all of the active OSS nodes.
5462 echo -n $(facets_nodes $(get_facets OST))
5465 # Get all of the active AGT (HSM agent) nodes.
5467 echo -n $(facets_nodes $(get_facets AGT))
5470 # Get all of the client nodes and active server nodes.
5472 local nodes=$HOSTNAME
5476 # CLIENTS (if specified) contains the local client
5477 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5479 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5480 nodes="$nodes $(facets_nodes $(get_facets))"
5483 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5487 # Get all of the remote client nodes and remote active server nodes.
5488 remote_nodes_list () {
5489 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5492 # Get all of the MDS nodes, including active and passive nodes.
5500 for i in $(seq $MDSCOUNT); do
5502 failover_host=mds${i}failover_HOST
5503 nodes="$nodes ${!host} ${!failover_host}"
5506 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5510 # Get all of the OSS nodes, including active and passive nodes.
5518 for i in $(seq $OSTCOUNT); do
5520 failover_host=ost${i}failover_HOST
5521 nodes="$nodes ${!host} ${!failover_host}"
5524 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5528 # Get all of the server nodes, including active and passive nodes.
5529 all_server_nodes () {
5534 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5536 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5540 # Get all of the client and server nodes, including active and passive nodes.
5542 local nodes=$HOSTNAME
5546 # CLIENTS (if specified) contains the local client
5547 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5549 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5550 nodes="$nodes $(all_server_nodes)"
5553 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5557 init_clients_lists () {
5558 # Sanity check: exclude the local client from RCLIENTS
5559 local clients=$(hostlist_expand "$RCLIENTS")
5560 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5562 # Sanity check: exclude the dup entries
5563 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5565 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5567 # Sanity check: exclude the dup entries from CLIENTS
5568 # for those configs which has SINGLCLIENT set to local client
5569 clients=$(for i in $clients; do echo $i; done | sort -u)
5571 CLIENTS=$(comma_list $clients)
5572 local -a remoteclients=($RCLIENTS)
5573 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5574 varname=CLIENT$((i + 2))
5575 eval $varname=${remoteclients[i]}
5578 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5581 get_random_entry () {
5584 rnodes=${rnodes//,/ }
5586 local -a nodes=($rnodes)
5587 local num=${#nodes[@]}
5588 local i=$((RANDOM * num * 2 / 65536))
5594 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5598 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5599 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5604 echo $nodes | wc -w || true
5608 local nodes=$(osts_nodes)
5609 local osscount=$(get_node_count "$nodes")
5610 [ ! "$OSTCOUNT" = "$osscount" ]
5614 local nodes=$(mdts_nodes)
5615 local mdtcount=$(get_node_count "$nodes")
5616 [ ! "$MDSCOUNT" = "$mdtcount" ]
5619 generate_machine_file() {
5620 local nodes=${1//,/ }
5621 local machinefile=$2
5623 for node in $nodes; do
5624 echo $node >>$machinefile || \
5625 { echo "can not generate machinefile $machinefile" && return 1; }
5630 local file=$1/stripe
5633 $LFS getstripe -v $file || error "getstripe $file failed"
5637 setstripe_nfsserver () {
5640 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5641 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5643 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5645 do_nodev $nfsserver lfs setstripe "$@"
5648 # Check and add a test group.
5654 local gid=$(getent group $group_name | cut -d: -f3)
5655 if [[ -n "$gid" ]]; then
5656 [[ "$gid" -eq "$group_id" ]] || {
5657 error_noexit "inconsistent group ID:" \
5658 "new: $group_id, old: $gid"
5662 groupadd -g $group_id $group_name
5669 # Check and add a test user.
5682 local uid=$(getent passwd $user_name | cut -d: -f3)
5683 if [[ -n "$uid" ]]; then
5684 if [[ "$uid" -eq "$user_id" ]]; then
5685 local dir=$(getent passwd $user_name | cut -d: -f6)
5686 if [[ "$dir" != "$home" ]]; then
5688 usermod -d $home $user_name
5692 error_noexit "inconsistent user ID:" \
5693 "new: $user_id, old: $uid"
5698 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5705 check_runas_id_ret() {
5707 local myRUNAS_UID=$1
5708 local myRUNAS_GID=$2
5711 if [ -z "$myRUNAS" ]; then
5712 error_exit "myRUNAS command must be specified for check_runas_id"
5715 $myRUNAS krb5_login.sh || \
5716 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5718 mkdir $DIR/d0_runas_test
5720 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5721 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5722 rm -rf $DIR/d0_runas_test
5727 local myRUNAS_UID=$1
5728 local myRUNAS_GID=$2
5731 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5732 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5733 Please set RUNAS_ID to some UID which exists on MDS and client or
5734 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5737 # obtain the UID/GID for MPI_USER
5741 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5742 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5744 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5745 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5748 # obtain and cache Kerberos ticket-granting ticket
5749 refresh_krb5_tgt() {
5750 local myRUNAS_UID=$1
5751 local myRUNAS_GID=$2
5754 if [ -z "$myRUNAS" ]; then
5755 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5758 CLIENTS=${CLIENTS:-$HOSTNAME}
5759 do_nodes $CLIENTS "set -x
5760 if ! $myRUNAS krb5_login.sh; then
5761 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5766 # Run multiop in the background, but wait for it to print
5767 # "PAUSING" to its stdout before returning from this function.
5768 multiop_bg_pause() {
5769 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5773 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5776 echo "$MULTIOP_PROG $FILE v$ARGS"
5777 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5779 echo "TMPPIPE=${TMPPIPE}"
5780 read -t 60 multiop_output < $TMPPIPE
5781 if [ $? -ne 0 ]; then
5786 if [ "$multiop_output" != "PAUSING" ]; then
5787 echo "Incorrect multiop output: $multiop_output"
5802 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5808 inodes_available () {
5809 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5810 sort -un | head -n1) || return 1
5814 mdsrate_inodes_available () {
5815 local min_inodes=$(inodes_available)
5816 echo $((min_inodes * 99 / 100))
5819 # reset llite stat counters
5820 clear_llite_stats(){
5821 lctl set_param -n llite.*.stats 0
5824 # sum llite stat items
5825 calc_llite_stats() {
5826 local res=$(lctl get_param -n llite.*.stats |
5827 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5831 # reset osc stat counters
5833 lctl set_param -n osc.*.osc_stats 0
5836 # sum osc stat items
5838 local res=$(lctl get_param -n osc.*.osc_stats |
5839 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5844 awk '{sum += $1} END { printf("%0.0f", sum) }'
5847 calc_osc_kbytes () {
5848 df $MOUNT > /dev/null
5849 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5852 # save_lustre_params(comma separated facet list, parameter_mask)
5853 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5854 save_lustre_params() {
5860 for facet in ${facets//,/ }; do
5861 node=$(facet_active_host $facet)
5862 [[ *\ $node\ * = " $nodes " ]] && continue
5863 nodes="$nodes $node"
5865 do_node $node "$LCTL get_param $2 |
5866 while read s; do echo $facet \\\$s; done"
5870 # restore lustre parameters from input stream, produces by save_lustre_params
5871 restore_lustre_params() {
5876 while IFS=" =" read facet name val; do
5877 do_facet $facet "$LCTL set_param -n $name $val"
5881 check_node_health() {
5882 local nodes=${1:-$(comma_list $(nodes_list))}
5884 for node in ${nodes//,/ }; do
5885 check_network "$node" 5
5886 if [ $? -eq 0 ]; then
5887 do_node $node "rc=0;
5888 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5889 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5890 echo \\\$(hostname -s): \\\$val;
5893 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5898 mdsrate_cleanup () {
5900 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5901 --nfiles $3 --dir $4 --filefmt $5 $6
5906 delayed_recovery_enabled () {
5907 local var=${SINGLEMDS}_svc
5908 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5911 ########################
5913 convert_facet2label() {
5916 if [ x$facet = xost ]; then
5920 local varsvc=${facet}_svc
5922 if [ -n ${!varsvc} ]; then
5925 error "No lablel for $facet!"
5929 get_clientosc_proc_path() {
5933 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5934 # used by MDT would not be changed.
5935 # mdt lov: fsname-mdtlov
5936 # mdt osc: fsname-OSTXXXX-osc
5937 mds_on_old_device() {
5938 local mds=${1:-"$SINGLEMDS"}
5940 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5941 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5942 > /dev/null 2>&1" && return 0
5947 get_mdtosc_proc_path() {
5949 local ost_label=${2:-"*OST*"}
5951 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5952 local mdt_label=$(convert_facet2label $mds_facet)
5953 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5955 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5956 mds_on_old_device $mds_facet; then
5957 echo "${ost_label}-osc"
5958 elif [[ $ost_label = *OST* ]]; then
5959 echo "${ost_label}-osc-${mdt_index}"
5961 echo "${ost_label}-osp-${mdt_index}"
5965 get_osc_import_name() {
5968 local label=$(convert_facet2label $ost)
5970 if [ "${facet:0:3}" = "mds" ]; then
5971 get_mdtosc_proc_path $facet $label
5975 get_clientosc_proc_path $label
5979 _wait_import_state () {
5982 local maxtime=${3:-$(max_recovery_time)}
5983 local error_on_failure=${4:-1}
5987 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5988 while [ "${CONN_STATE}" != "${expected}" ]; do
5989 if [ "${expected}" == "DISCONN" ]; then
5990 # for disconn we can check after proc entry is removed
5991 [ "x${CONN_STATE}" == "x" ] && return 0
5992 # with AT enabled, we can have connect request timeout near of
5993 # reconnect timeout and test can't see real disconnect
5994 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5996 if [ $i -ge $maxtime ]; then
5997 [ $error_on_failure -ne 0 ] && \
5998 error "can't put import for $CONN_PROC into ${expected}" \
5999 "state after $i sec, have ${CONN_STATE}"
6003 # Add uniq for multi-mount case
6004 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6008 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6012 wait_import_state() {
6015 local maxtime=${3:-$(max_recovery_time)}
6016 local error_on_failure=${4:-1}
6019 for param in ${params//,/ }; do
6020 _wait_import_state $state $param $maxtime $error_on_failure || return
6024 wait_import_state_mount() {
6025 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6029 wait_import_state $*
6032 # One client request could be timed out because server was not ready
6033 # when request was sent by client.
6034 # The request timeout calculation details :
6036 # /* We give the server rq_timeout secs to process the req, and
6037 # add the network latency for our local timeout. */
6038 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6039 # ptlrpc_at_get_net_latency(request) ;
6041 # ptlrpc_connect_import ()
6042 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6045 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6046 # ptlrpc_at_get_net_latency(request) ->
6047 # at_get (max (iat_net_latency=0, at_min)) = at_min
6050 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6051 # INITIAL_CONNECT_TIMEOUT + at_min
6053 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6054 # because we can not get this value in runtime,
6055 # the value depends on configure options, and it is not stored in /proc.
6057 # #define CONNECTION_SWITCH_MIN 5U
6058 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6060 request_timeout () {
6063 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6064 local init_connect_timeout=$TIMEOUT
6065 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6067 local at_min=$(at_get $facet at_min)
6069 echo $(( init_connect_timeout + at_min ))
6072 _wait_osc_import_state() {
6076 local target=$(get_osc_import_name $facet $ost_facet)
6077 local param="osc.${target}.ost_server_uuid"
6081 # 1. wait the deadline of client 1st request (it could be skipped)
6082 # 2. wait the deadline of client 2nd request
6083 local maxtime=$(( 2 * $(request_timeout $facet)))
6085 if [[ $facet == client* ]]; then
6086 # During setup time, the osc might not be setup, it need wait
6087 # until list_param can return valid value.
6088 param="osc.${ost%?}[^mM]*.ost_server_uuid"
6089 params=$($LCTL list_param $param 2>/dev/null || true)
6090 while [ -z "$params" ]; do
6091 if [ $i -ge $maxtime ]; then
6092 echo "can't get $param in $maxtime secs"
6097 params=$($LCTL list_param $param 2>/dev/null || true)
6101 if [[ $ost_facet = mds* ]]; then
6102 # no OSP connection to itself
6103 if [[ $facet = $ost_facet ]]; then
6106 param="osp.${target}.mdt_server_uuid"
6110 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6111 wait_import_state $expected "$params" $maxtime; then
6112 error "$facet: import is not in $expected state after $maxtime"
6119 wait_osc_import_state() {
6125 if [[ $facet = mds ]]; then
6126 for num in $(seq $MDSCOUNT); do
6127 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6130 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6134 _wait_mgc_import_state() {
6137 local error_on_failure=${3:-1}
6138 local param="mgc.*.mgs_server_uuid"
6142 # 1. wait the deadline of client 1st request (it could be skipped)
6143 # 2. wait the deadline of client 2nd request
6144 local maxtime=$(( 2 * $(request_timeout $facet)))
6146 if [[ $facet == client* ]]; then
6147 # During setup time, the osc might not be setup, it need wait
6148 # until list_param can return valid value. And also if there
6149 # are mulitple osc entries we should list all of them before
6151 params=$($LCTL list_param $param 2>/dev/null || true)
6152 while [ -z "$params" ]; do
6153 if [ $i -ge $maxtime ]; then
6154 echo "can't get $param in $maxtime secs"
6159 params=$($LCTL list_param $param 2>/dev/null || true)
6162 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6163 wait_import_state $expected "$params" $maxtime \
6164 $error_on_failure; then
6165 if [ $error_on_failure -ne 0 ]; then
6166 error "import is not in ${expected} state"
6174 wait_mgc_import_state() {
6177 local error_on_failure=${3:-1}
6180 if [[ $facet = mds ]]; then
6181 for num in $(seq $MDSCOUNT); do
6182 _wait_mgc_import_state mds$num "$expected" \
6183 $error_on_failure || return
6186 _wait_mgc_import_state "$facet" "$expected"
6187 $error_on_failure || return
6191 wait_dne_interconnect() {
6194 if [ $MDSCOUNT -gt 1 ]; then
6195 for num in $(seq $MDSCOUNT); do
6196 wait_osc_import_state mds mds$num FULL
6201 get_clientmdc_proc_path() {
6205 get_clientmgc_proc_path() {
6213 [ -z "$list" ] && return 0
6215 # Add paths to lustre tests for 32 and 64 bit systems.
6216 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6217 local TESTPATH="$RLUSTRE/tests:"
6218 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6219 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6222 wait_clients_import_state () {
6229 if [ "$FAILURE_MODE" = HARD ]; then
6230 facets=$(facets_on_host $(facet_active_host $facet))
6233 for facet in ${facets//,/ }; do
6234 local label=$(convert_facet2label $facet)
6237 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6238 $label).ost_server_uuid" ;;
6239 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6240 $label).mds_server_uuid" ;;
6241 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6242 $label).mgs_server_uuid" ;;
6243 *) error "unknown facet!" ;;
6246 local params=$(expand_list $params $proc_path)
6249 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6251 error "import is not in ${expected} state"
6261 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6262 $LCTL get_param obdfilter.*.kbytesavail))
6263 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6264 $LCTL get_param -n obdfilter.*.tot_granted))
6265 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6266 $LCTL get_param -n obdfilter.*.kbytestotal))
6267 for ((i=0; i<${#AVAILA[@]}; i++)); do
6268 local -a AVAIL1=(${AVAILA[$i]//=/ })
6269 local -a TOTAL=(${TOTALA[$i]//=/ })
6270 GRANT=$((${GRANTA[$i]}/1024))
6271 # allow 1% of total space in bavail because of delayed
6272 # allocation with ZFS which might release some free space after
6273 # txg commit. For small devices, we set a mininum of 8MB
6274 local LIMIT=$((${TOTAL} / 100 + 8000))
6275 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6276 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6277 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6278 echo " FULL" || echo
6284 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6287 check_pool_not_exist() {
6288 local fsname=${1%%.*}
6289 local poolname=${1##$fsname.}
6290 [[ $# -ne 1 ]] && return 0
6291 [[ x$poolname = x ]] && return 0
6292 list_pool $fsname | grep -w $1 && return 1
6297 local fsname=${1%%.*}
6298 local poolname=${1##$fsname.}
6300 trap "destroy_test_pools $fsname" EXIT
6301 do_facet mgs lctl pool_new $1
6303 # get param should return err unless pool is created
6304 [[ $RC -ne 0 ]] && return $RC
6306 for mds_id in $(seq $MDSCOUNT); do
6307 local mdt_id=$((mds_id-1))
6308 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6309 wait_update_facet mds$mds_id \
6310 "lctl get_param -n lod.$lodname.pools.$poolname \
6311 2>/dev/null || echo foo" "" ||
6312 error "mds$mds_id: pool_new failed $1"
6314 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6315 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6321 add_pool_to_list () {
6322 local fsname=${1%%.*}
6323 local poolname=${1##$fsname.}
6325 local listvar=${fsname}_CREATED_POOLS
6326 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6330 remove_pool_from_list () {
6331 local fsname=${1%%.*}
6332 local poolname=${1##$fsname.}
6334 local listvar=${fsname}_CREATED_POOLS
6335 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6339 destroy_pool_int() {
6341 local OSTS=$(list_pool $1)
6342 for ost in $OSTS; do
6343 do_facet mgs lctl pool_remove $1 $ost
6345 do_facet mgs lctl pool_destroy $1
6348 # <fsname>.<poolname> or <poolname>
6350 local fsname=${1%%.*}
6351 local poolname=${1##$fsname.}
6353 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6357 check_pool_not_exist $fsname.$poolname
6358 [[ $? -eq 0 ]] && return 0
6360 destroy_pool_int $fsname.$poolname
6362 [[ $RC -ne 0 ]] && return $RC
6363 for mds_id in $(seq $MDSCOUNT); do
6364 local mdt_id=$((mds_id-1))
6365 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6366 wait_update_facet mds$mds_id \
6367 "lctl get_param -n lod.$lodname.pools.$poolname \
6368 2>/dev/null || echo foo" "foo" ||
6369 error "mds$mds_id: destroy pool failed $1"
6371 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6372 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6374 remove_pool_from_list $fsname.$poolname
6380 local fsname=${1:-$FSNAME}
6382 local listvar=${fsname}_CREATED_POOLS
6384 [ x${!listvar} = x ] && return 0
6386 echo "Destroy the created pools: ${!listvar}"
6387 for poolname in ${!listvar//,/ }; do
6388 destroy_pool $fsname.$poolname
6392 destroy_test_pools () {
6394 local fsname=${1:-$FSNAME}
6395 destroy_pools $fsname || true
6401 local ts=$(date +%s)
6404 if [[ ! -f "$YAML_LOG" ]]; then
6405 # init_logging is not performed before gather_logs,
6406 # so the $LOGDIR needs to be checked here
6407 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6410 [ -f $LOGDIR/shared ] && docp=false
6412 # dump lustre logs, dmesg
6414 prefix="$TESTLOG_PREFIX.$TESTNAME"
6416 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6418 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6419 echo "Dumping logs only on local client."
6420 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6421 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6426 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6427 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6428 if [ ! -f $LOGDIR/shared ]; then
6429 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6442 for i in $(seq 0 $num_mntpts); do
6443 cmd="ls -laf ${mntpt_root}$i/$dir"
6449 for pid in $pids; do
6456 # check_and_start_recovery_timer()
6457 # service_time = at_est2timeout(service_time);
6458 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6459 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6461 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6462 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6463 #define CONNECTION_SWITCH_MIN 5
6464 #define CONNECTION_SWITCH_INC 5
6465 max_recovery_time() {
6466 local init_connect_timeout=$((TIMEOUT / 20))
6467 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6469 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6470 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6472 echo -n $service_time
6475 recovery_time_min() {
6476 local connection_switch_min=5
6477 local connection_switch_inc=5
6478 local connection_switch_max
6479 local reconnect_delay_max
6480 local initial_connect_timeout
6484 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6485 (($connection_switch_min > $TIMEOUT)) &&
6486 max=$connection_switch_min || max=$TIMEOUT
6487 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6489 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6490 timeout_20=$((TIMEOUT/20))
6491 (($connection_switch_min > $timeout_20)) &&
6492 initial_connect_timeout=$connection_switch_min ||
6493 initial_connect_timeout=$timeout_20
6495 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6496 initial_connect_timeout))
6497 echo $((2 * reconnect_delay_max))
6500 get_clients_mount_count () {
6501 local clients=${CLIENTS:-`hostname`}
6503 # we need to take into account the clients mounts and
6504 # exclude mds/ost mounts if any;
6505 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6509 PROC_CLI="srpc_info"
6517 if [ $M -lt $N ]; then
6521 while [ $N -lt $M ]; do
6531 calc_connection_cnt() {
6534 # MDT->MDT = 2 * C(M, 2)
6538 comb_m2=$(combination $MDSCOUNT 2)
6540 local num_clients=$(get_clients_mount_count)
6542 local cnt_mdt2mdt=$((comb_m2 * 2))
6543 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6544 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6545 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6546 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6547 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6548 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6562 local cmd="$tgt.srpc.flavor"
6564 if [ $net == "any" ]; then
6569 if [ $dir != "any" ]; then
6574 log "Setting sptlrpc rule: $cmd"
6575 do_facet mgs "$LCTL conf_param $cmd"
6584 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6585 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6587 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6589 if [ "x$bulkspec" != "x" ]; then
6590 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6592 if [ "x$algs" != "x" ]; then
6593 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6595 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6596 if [ $bulk == "bulkn" ]; then
6597 bulk_count=`echo "$output" | grep "bulk flavor" \
6598 | grep "null/null" | wc -l`
6599 elif [ $bulk == "bulki" ]; then
6600 bulk_count=`echo "$output" | grep "bulk flavor" \
6601 | grep "/null" | grep -v "null/" | wc -l`
6603 bulk_count=`echo "$output" | grep "bulk flavor" \
6604 | grep -v "/null" | grep -v "null/" | wc -l`
6608 [ $bulk_count -lt $count ] && count=$bulk_count
6619 local clients=${CLIENTS:-`hostname`}
6621 for c in ${clients//,/ }; do
6622 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6623 tmpcnt=`count_flvr "$output" $flavor`
6624 cnt=$((cnt + tmpcnt))
6634 local clients=${CLIENTS:-`hostname`}
6636 for c in ${clients//,/ }; do
6637 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6638 tmpcnt=`count_flvr "$output" $flavor`
6639 cnt=$((cnt + tmpcnt))
6649 if [ $MDSCOUNT -le 1 ]; then
6654 for num in `seq $MDSCOUNT`; do
6655 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6656 tmpcnt=`count_flvr "$output" $flavor`
6657 cnt=$((cnt + tmpcnt))
6668 for num in `seq $MDSCOUNT`; do
6669 mdtosc=$(get_mdtosc_proc_path mds$num)
6670 mdtosc=${mdtosc/-MDT*/-MDT\*}
6671 output=$(do_facet mds$num lctl get_param -n \
6672 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6673 tmpcnt=`count_flvr "$output" $flavor`
6674 cnt=$((cnt + tmpcnt))
6683 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6684 count_flvr "$output" $flavor
6689 local dir=$1 # from to
6690 local flavor=$2 # flavor expected
6693 if [ $dir == "cli2mdt" ]; then
6694 res=`flvr_cnt_cli2mdt $flavor`
6695 elif [ $dir == "cli2ost" ]; then
6696 res=`flvr_cnt_cli2ost $flavor`
6697 elif [ $dir == "mdt2mdt" ]; then
6698 res=`flvr_cnt_mdt2mdt $flavor`
6699 elif [ $dir == "mdt2ost" ]; then
6700 res=`flvr_cnt_mdt2ost $flavor`
6701 elif [ $dir == "all2ost" ]; then
6702 res1=`flvr_cnt_mdt2ost $flavor`
6703 res2=`flvr_cnt_cli2ost $flavor`
6704 res=$((res1 + res2))
6705 elif [ $dir == "all2mdt" ]; then
6706 res1=`flvr_cnt_mdt2mdt $flavor`
6707 res2=`flvr_cnt_cli2mdt $flavor`
6708 res=$((res1 + res2))
6709 elif [ $dir == "all2all" ]; then
6710 res1=`flvr_cnt_mdt2ost $flavor`
6711 res2=`flvr_cnt_cli2ost $flavor`
6712 res3=`flvr_cnt_mdt2mdt $flavor`
6713 res4=`flvr_cnt_cli2mdt $flavor`
6714 res=$((res1 + res2 + res3 + res4))
6722 local dir=$1 # from to
6723 local flavor=$2 # flavor expected
6724 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6728 for ((i=0;i<20;i++)); do
6729 echo -n "checking $dir..."
6730 res=$(do_check_flavor $dir $flavor)
6731 echo "found $res/$expect $flavor connections"
6732 [ $res -ge $expect ] && return 0
6736 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6740 restore_to_default_flavor()
6742 local proc="mgs.MGS.live.$FSNAME"
6744 echo "restoring to default flavor..."
6746 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6748 # remove all existing rules if any
6749 if [ $nrule -ne 0 ]; then
6750 echo "$nrule existing rules"
6751 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6752 echo "remove rule: $rule"
6753 spec=`echo $rule | awk -F = '{print $1}'`
6754 do_facet mgs "$LCTL conf_param -d $spec"
6758 # verify no rules left
6759 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6760 [ $nrule -ne 0 ] && error "still $nrule rules left"
6762 # wait for default flavor to be applied
6763 # currently default flavor for all connections are 'null'
6764 wait_flavor all2all null
6765 echo "now at default flavor settings"
6770 local flavor=${1:-null}
6772 echo "setting all flavor to $flavor"
6774 # FIXME need parameter to this fn
6775 # and remove global vars
6776 local cnt_all2all=$(calc_connection_cnt all2all)
6778 local res=$(do_check_flavor all2all $flavor)
6779 if [ $res -eq $cnt_all2all ]; then
6780 echo "already have total $res $flavor connections"
6784 echo "found $res $flavor out of total $cnt_all2all connections"
6785 restore_to_default_flavor
6787 [[ $flavor = null ]] && return 0
6789 set_rule $FSNAME any any $flavor
6790 wait_flavor all2all $flavor
6796 # Checking for shared logdir
6797 if [ ! -d $dir ]; then
6798 # Not found. Create local logdir
6801 touch $dir/check_file.$(hostname -s)
6806 check_write_access() {
6808 local list=${2:-$(comma_list $(nodes_list))}
6812 for node in ${list//,/ }; do
6813 file=$dir/check_file.$(short_nodename $node)
6814 if [[ ! -f "$file" ]]; then
6815 # Logdir not accessible/writable from this node.
6818 rm -f $file || return 1
6824 [[ -n $YAML_LOG ]] && return
6825 local save_umask=$(umask)
6828 export YAML_LOG=${LOGDIR}/results.yml
6832 # If the yaml log already exists then we will just append to it
6833 if [ ! -f $YAML_LOG ]; then
6834 if check_shared_dir $LOGDIR; then
6835 touch $LOGDIR/shared
6836 echo "Logging to shared log directory: $LOGDIR"
6838 echo "Logging to local directory: $LOGDIR"
6841 yml_nodes_file $LOGDIR >> $YAML_LOG
6842 yml_results_file >> $YAML_LOG
6847 # If modules are not yet loaded then older "lctl lustre_build_version"
6848 # will fail. Use lctl build version instead.
6849 log "Client: $($LCTL lustre_build_version)"
6850 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6851 do_facet $SINGLEMDS $LCTL --version)"
6852 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6853 do_facet ost1 $LCTL --version)"
6857 yml_log_test $1 >> $YAML_LOG
6861 yml_log_test_status $@ >> $YAML_LOG
6864 log_sub_test_begin() {
6865 yml_log_sub_test_begin "$@" >> $YAML_LOG
6868 log_sub_test_end() {
6869 yml_log_sub_test_end "$@" >> $YAML_LOG
6875 local llverdev_opts=$2
6876 local devname=$(basename $1)
6877 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6878 # loop devices aren't in /proc/partitions
6879 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6881 size=$(($size / 1024 / 1024)) # Gb
6883 local partial_arg=""
6884 # Run in partial (fast) mode if the size
6885 # of a partition > 1 GB
6886 [ $size -gt 1 ] && partial_arg="-p"
6888 llverdev --force $partial_arg $llverdev_opts $dev
6894 local llverfs_opts=$2
6895 local use_partial_arg=$3
6896 local partial_arg=""
6897 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6899 # Run in partial (fast) mode if the size
6900 # of a partition > 1 GB
6901 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6903 llverfs $partial_arg $llverfs_opts $dir
6906 #Remove objects from OST
6907 remove_ost_objects() {
6913 local mntpt=$(facet_mntpt $facet)
6914 local opts=$OST_MOUNT_OPTS
6918 echo "removing objects from $ostdev on $facet: $objids"
6919 if ! test -b $ostdev; then
6920 opts=$(csa_add "$opts" -o loop)
6922 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6925 for i in $objids; do
6926 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6928 umount -f $mntpt || return $?
6932 #Remove files from MDT
6933 remove_mdt_files() {
6938 local mntpt=$(facet_mntpt $facet)
6939 local opts=$MDS_MOUNT_OPTS
6941 echo "removing files from $mdtdev on $facet: $files"
6942 if [ $(facet_fstype $facet) == ldiskfs ] &&
6943 ! do_facet $facet test -b $mdtdev; then
6944 opts=$(csa_add "$opts" -o loop)
6946 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6950 rm $mntpt/ROOT/$f || { rc=$?; break; }
6952 umount -f $mntpt || return $?
6956 duplicate_mdt_files() {
6961 local mntpt=$(facet_mntpt $facet)
6962 local opts=$MDS_MOUNT_OPTS
6964 echo "duplicating files on $mdtdev on $facet: $files"
6965 mkdir -p $mntpt || return $?
6966 if [ $(facet_fstype $facet) == ldiskfs ] &&
6967 ! do_facet $facet test -b $mdtdev; then
6968 opts=$(csa_add "$opts" -o loop)
6970 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6981 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6982 pushd $mntpt/ROOT > /dev/null || return $?
6985 touch $f.bad || return $?
6986 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6988 [ $rc -eq 0 ] || return $rc
6989 setfattr --restore $tmp || return $?
6995 local devs=${1//,/ }
6998 local rslt=$TMP/sgpdd_survey
7000 # sgpdd-survey cleanups ${rslt}.* files
7002 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7008 # returns the canonical name for an ldiskfs device
7013 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7014 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7015 echo dm-\\\${foo##*:};
7017 echo \\\$(basename \\\$dv);
7021 is_sanity_benchmark() {
7022 local benchmarks="dbench bonnie iozone fsx"
7024 for b in $benchmarks; do
7025 if [ "$b" == "$suite" ]; then
7033 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
7037 # Get the available size (KB) of a given obd target.
7044 [[ $facet != client ]] || return 0
7046 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7051 # Get the page size (bytes) on a given facet node.
7055 local size=$(getconf PAGE_SIZE 2>/dev/null)
7057 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7058 echo -n ${size:-4096}
7062 # Get the block count of the filesystem.
7069 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7070 awk '/^Block count:/ {print $3}')
7074 # Get the block size of the filesystem.
7080 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7081 awk '/^Block size:/ {print $3}')
7085 # Check whether the "large_xattr" feature is enabled or not.
7086 large_xattr_enabled() {
7087 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7089 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7091 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7092 grep -E -q '(ea_inode|large_xattr)'"
7093 return ${PIPESTATUS[0]}
7096 # Get the maximum xattr size supported by the filesystem.
7100 if large_xattr_enabled; then
7101 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7104 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7105 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7107 # maximum xattr size = size of block - size of header -
7108 # size of 1 entry - 4 null bytes
7109 size=$((block_size - 32 - 32 - 4))
7115 # Dump the value of the named xattr from a file.
7120 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7123 # Generate a string with size of $size bytes.
7125 local size=${1:-1024} # in bytes
7127 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7130 reformat_external_journal() {
7135 if [ -n "${!var}" ]; then
7136 local rcmd="do_facet $facet"
7138 echo "reformat external journal on $facet:${!var}"
7139 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7143 # MDT file-level backup/restore
7144 mds_backup_restore() {
7147 local devname=$(mdsdevname $(facet_number $facet))
7148 local mntpt=$(facet_mntpt brpt)
7149 local rcmd="do_facet $facet"
7150 local metaea=${TMP}/backup_restore.ea
7151 local metadata=${TMP}/backup_restore.tgz
7152 local opts=${MDS_MOUNT_OPTS}
7153 local svc=${facet}_svc
7155 if ! ${rcmd} test -b ${devname}; then
7156 opts=$(csa_add "$opts" -o loop)
7159 echo "file-level backup/restore on $facet:${devname}"
7161 # step 1: build mount point
7162 ${rcmd} mkdir -p $mntpt
7163 # step 2: cleanup old backup
7164 ${rcmd} rm -f $metaea $metadata
7166 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7167 if [ ! -z $igif ]; then
7168 # step 3.5: rm .lustre
7169 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7171 # step 4: backup metaea
7173 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7175 # step 5: backup metadata
7177 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7179 ${rcmd} $UMOUNT $mntpt || return 4
7180 # step 8: reformat dev
7181 echo "reformat new device"
7182 format_mdt $(facet_number $facet)
7184 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7185 # step 10: restore metadata
7187 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7188 # step 11: restore metaea
7190 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7191 # step 12: remove recovery logs
7192 echo "remove recovery logs"
7193 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7194 # step 13: umount dev
7195 ${rcmd} $UMOUNT $mntpt || return 10
7196 # step 14: cleanup tmp backup
7197 ${rcmd} rm -f $metaea $metadata
7198 # step 15: reset device label - it's not virgin on
7199 ${rcmd} e2label $devname ${!svc}
7206 local devname=$(mdsdevname $(facet_number $facet))
7207 local mntpt=$(facet_mntpt brpt)
7208 local rcmd="do_facet $facet"
7209 local opts=${MDS_MOUNT_OPTS}
7211 if ! ${rcmd} test -b ${devname}; then
7212 opts=$(csa_add "$opts" -o loop)
7215 echo "removing OI files on $facet: idx=${idx}"
7217 # step 1: build mount point
7218 ${rcmd} mkdir -p $mntpt
7220 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7221 if [ -z $idx ]; then
7222 # step 3: remove all OI files
7223 ${rcmd} rm -fv $mntpt/oi.16*
7224 elif [ $idx -lt 2 ]; then
7225 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7229 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7230 for ((i=${idx}; i<64; i=$((i * idx)))); do
7231 ${rcmd} rm -fv $mntpt/oi.16.${i}
7235 ${rcmd} $UMOUNT $mntpt || return 2
7236 # OI files will be recreated when mounted as lustre next time.
7239 # generate maloo upload-able log file name
7240 # \param logname specify unique part of file name
7241 generate_logname() {
7242 local logname=${1:-"default_logname"}
7244 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7247 # make directory on different MDTs
7251 local stripe_count=2
7252 local stripe_index=-1
7255 while getopts "c:i:p" opt; do
7257 c) stripe_count=$OPTARG;;
7258 i) stripe_index=$OPTARG;;
7260 \?) error "only support -i -c -p";;
7264 shift $((OPTIND - 1))
7265 [ $# -eq 1 ] || error "Only creating single directory is supported"
7268 if [ "$p_option" == "-p" ]; then
7269 local parent=$(dirname $path)
7271 [ -d $path ] && return 0
7272 [ ! -d ${parent} ] && mkdir -p ${parent}
7275 if [ $MDSCOUNT -le 1 ]; then
7278 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7281 if [ $stripe_index -eq -1 ]; then
7282 mdt_index=$((test_num % MDSCOUNT))
7284 mdt_index=$stripe_index
7286 echo "striped dir -i$mdt_index -c$stripe_count $path"
7287 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7291 # find the smallest and not in use file descriptor
7294 local max_fd=$(ulimit -n)
7296 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7299 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7303 check_mount_and_prep()
7305 is_mounted $MOUNT || setupall
7307 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7308 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7309 for idx in $(seq $MDSCOUNT); do
7310 local name="MDT$(printf '%04x' $((idx - 1)))"
7311 rm -rf $MOUNT/.lustre/lost+found/$name/*
7315 # calcule how many ost-objects to be created.
7316 precreated_ost_obj_count()
7320 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7321 local ost_name="OST$(printf '%04x' $ost_idx)"
7322 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7323 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7324 osp.$proc_path.prealloc_last_id)
7325 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7326 osp.$proc_path.prealloc_next_id)
7327 echo $((last_id - next_id + 1))
7330 check_file_in_pool()
7335 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7338 for t in $tlist ; do
7339 [ "$i" -eq "$t" ] && continue 2
7342 echo "pool list: $tlist"
7343 echo "striping: $res"
7344 error_noexit "$file not allocated in $pool"
7351 echo "Creating new pool"
7354 create_pool $FSNAME.$pool ||
7355 { error_noexit "No pool created, result code $?"; return 1; }
7356 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7357 { error_noexit "$pool not in lfs pool_list"; return 2; }
7360 pool_add_targets() {
7361 echo "Adding targets to pool"
7367 local list=$(seq $first $step $last)
7369 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7370 do_facet mgs $LCTL pool_add \
7371 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7373 # wait for OSTs to be added to the pool
7374 for mds_id in $(seq $MDSCOUNT); do
7375 local mdt_id=$((mds_id-1))
7376 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7377 wait_update_facet mds$mds_id \
7378 "lctl get_param -n lod.$lodname.pools.$pool |
7379 sort -u | tr '\n' ' ' " "$t" || {
7380 error_noexit "mds$mds_id: Add to pool failed"
7384 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7385 | sort -u | tr '\n' ' ' " "$t" || {
7386 error_noexit "Add to pool failed"
7389 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7390 local addcount=$(((last - first) / step + 1))
7391 [ $lfscount -eq $addcount ] || {
7392 error_noexit "lfs pool_list bad ost count" \
7393 "$lfscount != $addcount"
7401 echo "Setting pool on directory $tdir"
7403 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7405 error_noexit "Cannot set pool $pool to $tdir"
7412 echo "Checking pool on directory $tdir"
7414 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7415 [ "$res" = "$pool" ] && return 0
7417 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7421 pool_dir_rel_path() {
7422 echo "Testing relative path works well"
7427 mkdir -p $root/$tdir/$tdir
7429 pool_set_dir $pool $tdir || return 1
7430 pool_set_dir $pool ./$tdir || return 2
7431 pool_set_dir $pool ../$tdir || return 3
7432 pool_set_dir $pool ../$tdir/$tdir || return 4
7433 rm -rf $tdir; cd - > /dev/null
7436 pool_alloc_files() {
7437 echo "Checking files allocation from directory pool"
7444 for i in $(seq -w 1 $count)
7446 local file=$tdir/file-$i
7448 check_file_in_pool $file $pool "$tlist" || \
7449 failed=$((failed + 1))
7451 [ "$failed" = 0 ] && return 0
7453 error_noexit "$failed files not allocated in $pool"
7457 pool_create_files() {
7458 echo "Creating files in pool"
7466 for i in $(seq -w 1 $count)
7468 local file=$tdir/spoo-$i
7469 $SETSTRIPE -p $pool $file
7470 check_file_in_pool $file $pool "$tlist" || \
7471 failed=$((failed + 1))
7473 [ "$failed" = 0 ] && return 0
7475 error_noexit "$failed files not allocated in $pool"
7480 echo "Checking 'lfs df' output"
7483 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7485 local res=$($LFS df --pool $FSNAME.$pool |
7487 grep "$FSNAME-OST" |
7489 [ "$res" = "$t" ] && return 0
7491 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7495 pool_file_rel_path() {
7496 echo "Creating files in a pool with relative pathname"
7501 { error_noexit "unable to create $tdir"; return 1 ; }
7502 local file="/..$tdir/$tfile-1"
7503 $SETSTRIPE -p $pool $file ||
7504 { error_noexit "unable to create $file" ; return 2 ; }
7507 $SETSTRIPE -p $pool $tfile-2 || {
7508 error_noexit "unable to create $tfile-2 in $tdir"
7513 pool_remove_first_target() {
7514 echo "Removing first target from a pool"
7517 local pname="lov.$FSNAME-*.pools.$pool"
7518 local t=$($LCTL get_param -n $pname | head -1)
7519 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7520 for mds_id in $(seq $MDSCOUNT); do
7521 local mdt_id=$((mds_id-1))
7522 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7523 wait_update_facet mds$mds_id \
7524 "lctl get_param -n lod.$lodname.pools.$pool |
7526 error_noexit "mds$mds_id: $t not removed from" \
7531 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7532 error_noexit "$t not removed from $FSNAME.$pool"
7537 pool_remove_all_targets() {
7538 echo "Removing all targets from pool"
7541 local pname="lov.$FSNAME-*.pools.$pool"
7542 for t in $($LCTL get_param -n $pname | sort -u)
7544 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7546 for mds_id in $(seq $MDSCOUNT); do
7547 local mdt_id=$((mds_id-1))
7548 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7549 wait_update_facet mds$mds_id "lctl get_param -n \
7550 lod.$lodname.pools.$pool" "" || {
7551 error_noexit "mds$mds_id: Pool $pool not drained"
7555 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7556 error_noexit "Pool $FSNAME.$pool cannot be drained"
7559 # striping on an empty/nonexistant pool should fall back
7560 # to "pool of everything"
7562 error_noexit "failed to use fallback striping for empty pool"
7565 # setstripe on an empty pool should fail
7566 $SETSTRIPE -p $pool $file 2>/dev/null && {
7567 error_noexit "expected failure when creating file" \
7575 echo "Destroying pool"
7579 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7582 # striping on an empty/nonexistant pool should fall back
7583 # to "pool of everything"
7585 error_noexit "failed to use fallback striping for missing pool"
7588 # setstripe on an empty pool should fail
7589 $SETSTRIPE -p $pool $file 2>/dev/null && {
7590 error_noexit "expected failure when creating file" \
7595 # get param should return err once pool is gone
7596 if wait_update $HOSTNAME "lctl get_param -n \
7597 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7599 remove_pool_from_list $FSNAME.$pool
7602 error_noexit "Pool $FSNAME.$pool is not destroyed"
7606 # Get and check the actual stripe count of one file.
7607 # Usage: check_stripe_count <file> <expected_stripe_count>
7608 check_stripe_count() {
7613 [[ -z "$file" || -z "$expected" ]] &&
7614 error "check_stripe_count: invalid argument"
7616 local cmd="$GETSTRIPE -c $file"
7617 actual=$($cmd) || error "$cmd failed"
7618 actual=${actual%% *}
7620 if [[ $actual -ne $expected ]]; then
7621 [[ $expected -eq -1 ]] ||
7622 error "$cmd wrong: found $actual, expected $expected"
7623 [[ $actual -eq $OSTCOUNT ]] ||
7624 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7628 # Get and check the actual list of OST indices on one file.
7629 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7635 [[ -z "$file" || -z "$expected" ]] &&
7636 error "check_obdidx: invalid argument!"
7638 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7639 grep -v obdidx | awk '{print $1}' | xargs))
7641 [[ $obdidx = $expected ]] ||
7642 error "list of OST indices on $file is $obdidx," \
7643 "should be $expected"
7646 # Get and check the actual OST index of the first stripe on one file.
7647 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7648 check_start_ost_idx() {
7653 [[ -z "$file" || -z "$expected" ]] &&
7654 error "check_start_ost_idx: invalid argument!"
7656 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7659 [[ $start_ost_idx = $expected ]] ||
7660 error "OST index of the first stripe on $file is" \
7661 "$start_ost_idx, should be $expected"
7664 killall_process () {
7665 local clients=${1:-$(hostname)}
7670 do_nodes $clients "killall $signal $name"
7675 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
7680 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
7685 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
7690 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
7695 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
7700 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
7707 do_facet mgs "cat $LSNAPSHOT_LOG"
7713 echo "Cleaning test environment ..."
7715 # Every lsnapshot command takes exclusive lock with others,
7716 # so can NOT destroy the snapshot during list with 'xargs'.
7718 local ssname=$(lsnapshot_list | grep snapshot_name |
7719 grep lss_ | awk '{ print $2 }' | head -n 1)
7720 [ -z "$ssname" ] && break
7722 lsnapshot_destroy -n $ssname -f ||
7723 lss_err "Fail to destroy $ssname by force"
7733 local host=$(facet_active_host $facet)
7734 local dir=$(dirname $(facet_vdevice $facet))
7735 local pool=$(zpool_name $facet)
7736 local lfsname=$(zfs_local_fsname $facet)
7737 local label=${FSNAME}-${role}$(printf '%04x' $idx)
7740 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
7746 do_facet mgs "rm -f $LSNAPSHOT_CONF"
7747 echo "Generating $LSNAPSHOT_CONF on MGS ..."
7749 if ! combined_mgs_mds ; then
7750 [ $(facet_fstype mgs) != zfs ] &&
7751 skip "Lustre snapshot 1 only works for ZFS backend" &&
7754 local host=$(facet_active_host mgs)
7755 local dir=$(dirname $(facet_vdevice mgs))
7756 local pool=$(zpool_name mgs)
7757 local lfsname=$(zfs_local_fsname mgs)
7760 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
7761 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
7764 for num in `seq $MDSCOUNT`; do
7765 [ $(facet_fstype mds$num) != zfs ] &&
7766 skip "Lustre snapshot 1 only works for ZFS backend" &&
7769 lss_gen_conf_one mds$num MDT $((num - 1)) ||
7770 lss_err "generate lss conf (mds$num)"
7773 for num in `seq $OSTCOUNT`; do
7774 [ $(facet_fstype ost$num) != zfs ] &&
7775 skip "Lustre snapshot 1 only works for ZFS backend" &&
7778 lss_gen_conf_one ost$num OST $((num - 1)) ||
7779 lss_err "generate lss conf (ost$num)"
7782 do_facet mgs "cat $LSNAPSHOT_CONF"